diff --git a/recipes/marcomagdy-ulid/all/conandata.yml b/recipes/marcomagdy-ulid/all/conandata.yml new file mode 100644 index 0000000000000..a0167db018416 --- /dev/null +++ b/recipes/marcomagdy-ulid/all/conandata.yml @@ -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" diff --git a/recipes/marcomagdy-ulid/all/conanfile.py b/recipes/marcomagdy-ulid/all/conanfile.py new file mode 100644 index 0000000000000..4b5cdf3882104 --- /dev/null +++ b/recipes/marcomagdy-ulid/all/conanfile.py @@ -0,0 +1,104 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.microsoft import check_min_vs, is_msvc +from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir +from conan.tools.build import check_min_cppstd +from conan.tools.scm import Version +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +import os + + +required_conan_version = ">=1.53.0" + + +class UlidConan(ConanFile): + name = "marcomagdy-ulid" + description = "Lightweight ulid implementation in C++ suitable for embedded environments" + license = "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 + del self.options.shared + self.package_type = "static-library" + + def configure(self): + if self.options.get_safe("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." + ) + + 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.set_property("cmake_file_name", "ulid") + self.cpp_info.set_property("cmake_target_name", "ULID::ulid") diff --git a/recipes/marcomagdy-ulid/all/patches/cci.20230615-msvc-fix.patch b/recipes/marcomagdy-ulid/all/patches/cci.20230615-msvc-fix.patch new file mode 100644 index 0000000000000..5fe470a00052d --- /dev/null +++ b/recipes/marcomagdy-ulid/all/patches/cci.20230615-msvc-fix.patch @@ -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() diff --git a/recipes/marcomagdy-ulid/all/test_package/CMakeLists.txt b/recipes/marcomagdy-ulid/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..47158858e7590 --- /dev/null +++ b/recipes/marcomagdy-ulid/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/marcomagdy-ulid/all/test_package/conanfile.py b/recipes/marcomagdy-ulid/all/test_package/conanfile.py new file mode 100644 index 0000000000000..02eb5ce439fb4 --- /dev/null +++ b/recipes/marcomagdy-ulid/all/test_package/conanfile.py @@ -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") diff --git a/recipes/marcomagdy-ulid/all/test_package/test_package.cpp b/recipes/marcomagdy-ulid/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..0f5cd48bc9c1a --- /dev/null +++ b/recipes/marcomagdy-ulid/all/test_package/test_package.cpp @@ -0,0 +1,11 @@ +#include +#include + +#include "ulid/ulid.h" + +int main(void) +{ + std::cout << ulid::generate().str(); + + return EXIT_SUCCESS; +} diff --git a/recipes/marcomagdy-ulid/config.yml b/recipes/marcomagdy-ulid/config.yml new file mode 100644 index 0000000000000..99e34846cfd31 --- /dev/null +++ b/recipes/marcomagdy-ulid/config.yml @@ -0,0 +1,3 @@ +versions: + "cci.20230615": + folder: all