From 823476d4194835ece445d4fd54fab57135e288ec Mon Sep 17 00:00:00 2001 From: wolfee Date: Sun, 3 Sep 2023 23:20:46 +0200 Subject: [PATCH] ulid: add recipe --- recipes/ulid/all/conandata.yml | 9 ++ recipes/ulid/all/conanfile.py | 107 ++++++++++++++++++ .../all/patches/cci.20230615-msvc-fix.patch | 20 ++++ recipes/ulid/all/test_package/CMakeLists.txt | 9 ++ recipes/ulid/all/test_package/conanfile.py | 27 +++++ .../ulid/all/test_package/test_package.cpp | 11 ++ .../ulid/all/test_v1_package/CMakeLists.txt | 11 ++ recipes/ulid/all/test_v1_package/conanfile.py | 17 +++ recipes/ulid/config.yml | 3 + 9 files changed, 214 insertions(+) create mode 100644 recipes/ulid/all/conandata.yml create mode 100644 recipes/ulid/all/conanfile.py create mode 100644 recipes/ulid/all/patches/cci.20230615-msvc-fix.patch create mode 100644 recipes/ulid/all/test_package/CMakeLists.txt create mode 100644 recipes/ulid/all/test_package/conanfile.py create mode 100644 recipes/ulid/all/test_package/test_package.cpp create mode 100644 recipes/ulid/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/ulid/all/test_v1_package/conanfile.py create mode 100644 recipes/ulid/config.yml diff --git a/recipes/ulid/all/conandata.yml b/recipes/ulid/all/conandata.yml new file mode 100644 index 0000000000000..a0167db018416 --- /dev/null +++ b/recipes/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/ulid/all/conanfile.py b/recipes/ulid/all/conanfile.py new file mode 100644 index 0000000000000..1d06989a760c2 --- /dev/null +++ b/recipes/ulid/all/conanfile.py @@ -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" diff --git a/recipes/ulid/all/patches/cci.20230615-msvc-fix.patch b/recipes/ulid/all/patches/cci.20230615-msvc-fix.patch new file mode 100644 index 0000000000000..5fe470a00052d --- /dev/null +++ b/recipes/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/ulid/all/test_package/CMakeLists.txt b/recipes/ulid/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..db3c48389528e --- /dev/null +++ b/recipes/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/ulid/all/test_package/conanfile.py b/recipes/ulid/all/test_package/conanfile.py new file mode 100644 index 0000000000000..02eb5ce439fb4 --- /dev/null +++ b/recipes/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/ulid/all/test_package/test_package.cpp b/recipes/ulid/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..0f5cd48bc9c1a --- /dev/null +++ b/recipes/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/ulid/all/test_v1_package/CMakeLists.txt b/recipes/ulid/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..e7c495e34202a --- /dev/null +++ b/recipes/ulid/all/test_v1_package/CMakeLists.txt @@ -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) diff --git a/recipes/ulid/all/test_v1_package/conanfile.py b/recipes/ulid/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..38f4483872d47 --- /dev/null +++ b/recipes/ulid/all/test_v1_package/conanfile.py @@ -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) diff --git a/recipes/ulid/config.yml b/recipes/ulid/config.yml new file mode 100644 index 0000000000000..99e34846cfd31 --- /dev/null +++ b/recipes/ulid/config.yml @@ -0,0 +1,3 @@ +versions: + "cci.20230615": + folder: all