-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
sources: | ||
"cci.20230615": | ||
url: "https://github.com/marcomagdy/ulid/archive/a14ff0987bc327cca60333ac3bfda37e42a71f2d.zip" | ||
sha256: "e7884fee1a6973a7a83ab07bf229d3e86d6e59afabc7418be318aa3f42af5872" | ||
patches: | ||
"cci.20230615": | ||
- patch_file: "patches/cci.20230615-msvc-fix.patch" | ||
patch_description: "MSVC compile fix patch" | ||
patch_type: "portability" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.microsoft import check_min_vs, is_msvc_static_runtime, is_msvc | ||
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, replace_in_file | ||
from conan.tools.build import check_min_cppstd | ||
from conan.tools.scm import Version | ||
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout | ||
from conan.tools.env import VirtualBuildEnv | ||
import os | ||
|
||
|
||
required_conan_version = ">=1.53.0" | ||
|
||
class UlidConan(ConanFile): | ||
name = "ulid" | ||
description = "Lightweight ulid implementation in C++ suitable for embedded environments" | ||
license = "The Unlicense" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/marcomagdy/ulid" | ||
topics = ("ulid", "id", "embedded") | ||
package_type = "library" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": True, | ||
} | ||
|
||
@property | ||
def _min_cppstd(self): | ||
return 17 | ||
|
||
@property | ||
def _compilers_minimum_version(self): | ||
return { | ||
"gcc": "7", | ||
"clang": "7", | ||
"apple-clang": "10", | ||
} | ||
|
||
def export_sources(self): | ||
export_conandata_patches(self) | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
self.options.rm_safe("fPIC") | ||
|
||
def layout(self): | ||
cmake_layout(self, src_folder="src") | ||
|
||
def validate(self): | ||
if self.settings.compiler.cppstd: | ||
check_min_cppstd(self, self._min_cppstd) | ||
check_min_vs(self, 191) | ||
if not is_msvc(self): | ||
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) | ||
if minimum_version and Version(self.settings.compiler.version) < minimum_version: | ||
raise ConanInvalidConfiguration( | ||
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." | ||
) | ||
if is_msvc(self) and self.options.shared: | ||
raise ConanInvalidConfiguration(f"{self.ref} can not be built as shared on Visual Studio and msvc.") | ||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
tc.variables["ENABLE_SANITIZERS"] = False | ||
tc.variables["BUILD_TESTING"] = False | ||
tc.generate() | ||
|
||
def _patch_sources(self): | ||
apply_conandata_patches(self) | ||
|
||
def build(self): | ||
self._patch_sources() | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def package(self): | ||
copy(self, pattern="LICENSE", dst=os.path.join( | ||
self.package_folder, "licenses"), src=self.source_folder) | ||
cmake = CMake(self) | ||
cmake.install() | ||
|
||
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) | ||
rmdir(self, os.path.join(self.package_folder, "share")) | ||
rm(self, "*.la", os.path.join(self.package_folder, "lib")) | ||
rm(self, "*.pdb", os.path.join(self.package_folder, "lib")) | ||
rm(self, "*.pdb", os.path.join(self.package_folder, "bin")) | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = ["ulid"] | ||
self.cpp_info.filenames["cmake_find_package"] = "ULID" | ||
self.cpp_info.filenames["cmake_find_package_multi"] = "ulid" | ||
self.cpp_info.names["cmake_find_package"] = "ULID" | ||
self.cpp_info.names["cmake_find_package_multi"] = "ulid" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt | ||
index 12ba41b..e0f59b1 100644 | ||
--- a/source/CMakeLists.txt | ||
+++ b/source/CMakeLists.txt | ||
@@ -1,7 +1,11 @@ | ||
add_library(${PROJECT_NAME} ulid.cpp) | ||
target_compile_options(${PROJECT_NAME} PRIVATE | ||
-fno-exceptions | ||
- -fno-rtti | ||
- -Wall | ||
- -Wextra | ||
- -Werror) | ||
+ -fno-rtti) | ||
+ | ||
+if(NOT MSVC) | ||
+ target_compile_options(${PROJECT_NAME} PRIVATE | ||
+ -Wall | ||
+ -Werror | ||
+ -Wextra) | ||
+endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
|
||
project(test_package CXX) | ||
|
||
find_package(ulid REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE ulid::ulid) | ||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout, CMake | ||
import os | ||
|
||
|
||
# It will become the standard on Conan 2.x | ||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindir, "test_package") | ||
self.run(bin_path, env="conanrun") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <cstdlib> | ||
#include <iostream> | ||
|
||
#include "ulid/ulid.h" | ||
|
||
int main(void) | ||
{ | ||
std::cout << ulid::generate().str(); | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package LANGUAGES CXX) | ||
|
||
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") | ||
conan_basic_setup(TARGETS) | ||
|
||
find_package(ulid REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} ../test_package/test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE ulid::ulid) | ||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from conans import ConanFile, CMake, tools | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "cmake", "cmake_find_package_multi" | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not tools.cross_building(self): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run(bin_path, run_environment=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"cci.20230615": | ||
folder: all |