diff --git a/recipes/unleash-client-cpp/all/CMakeLists.txt b/recipes/unleash-client-cpp/all/CMakeLists.txt deleted file mode 100644 index b71c882d9d33f..0000000000000 --- a/recipes/unleash-client-cpp/all/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.1) -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup(KEEP_RPATHS) - -add_subdirectory(source_subfolder) diff --git a/recipes/unleash-client-cpp/all/conandata.yml b/recipes/unleash-client-cpp/all/conandata.yml index 76a5bca8da701..ac4d0efb2aa81 100644 --- a/recipes/unleash-client-cpp/all/conandata.yml +++ b/recipes/unleash-client-cpp/all/conandata.yml @@ -1,8 +1,16 @@ sources: + "1.3.0": + url: "https://github.com/aruizs/unleash-client-cpp/archive/refs/tags/v1.3.0.tar.gz" + sha256: "fa0b8d6101c6dbd08db23a3d353f386c17e9436a63d658f88c7d0b8619b8d501" "1.1.1": url: "https://github.com/aruizs/unleash-client-cpp/archive/refs/tags/v1.1.1.tar.gz" sha256: "2750dc231bf608910d4270ac39d83d46d25b88cc547a9d4d31f7ce4950effa7c" patches: "1.1.1": - patch_file: "patches/0001-no-conan-cmake.patch" - base_path: "source_subfolder" + patch_type: "conan" + patch_description: "Do not load Conan in CMakeLists.txt" + - patch_file: "patches/0002-fix-includes.patch" + patch_type: "portability" + patch_description: "Fix missing includes when building with Clang" + patch_source: "https://github.com/aruizs/unleash-client-cpp/pull/19" diff --git a/recipes/unleash-client-cpp/all/conanfile.py b/recipes/unleash-client-cpp/all/conanfile.py index 08a60bfc378de..09b2fc5266b6b 100644 --- a/recipes/unleash-client-cpp/all/conanfile.py +++ b/recipes/unleash-client-cpp/all/conanfile.py @@ -1,18 +1,24 @@ -from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration import os -required_conan_version = ">=1.43.0" +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir +from conan.tools.scm import Version + +required_conan_version = ">=1.53.0" class UnleashConan(ConanFile): name = "unleash-client-cpp" - homepage = "https://github.com/aruizs/unleash-client-cpp/" + description = "C++ client SDK for Unleash, an open-source feature flag management service." license = "MIT" url = "https://github.com/conan-io/conan-center-index" - description = "Unleash Client SDK for C++ projects." - topics = ("unleash", "feature", "flag", "toggle") + homepage = "https://github.com/aruizs/unleash-client-cpp/" + topics = ("unleash", "feature-flag") + package_type = "library" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], @@ -23,35 +29,23 @@ class UnleashConan(ConanFile): "fPIC": True, } - generators = "cmake", "cmake_find_package" - _cmake = None - - @property - def _source_subfolder(self): - return "source_subfolder" - - @property - def _build_subfolder(self): - return "build_subfolder" - @property def _min_cppstd(self): - return "17" + return 17 @property - def _compilers_min_version(self): + def _compilers_minimum_version(self): return { "Visual Studio": "15", # Should we check toolset? + "msvc": "191", "gcc": "7", "clang": "4.0", "apple-clang": "3.8", - "intel": "17", + "intel-cc": "17", } def export_sources(self): - self.copy("CMakeLists.txt") - for patch in self.conan_data.get("patches", {}).get(self.version, []): - self.copy(patch["patch_file"]) + export_conandata_patches(self) def config_options(self): if self.settings.os == "Windows": @@ -59,52 +53,48 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC + self.options.rm_safe("fPIC") + + def layout(self): + cmake_layout(self, src_folder="src") def requirements(self): - self.requires("cpr/1.7.2") - self.requires("nlohmann_json/3.10.5") + self.requires("cpr/1.10.5") + self.requires("nlohmann_json/3.11.3") def validate(self): - if self.settings.compiler.get_safe("cppstd"): - tools.check_min_cppstd(self, self._min_cppstd) - - def loose_lt_semver(v1, v2): - lv1 = [int(v) for v in v1.split(".")] - lv2 = [int(v) for v in v2.split(".")] - min_length = min(len(lv1), len(lv2)) - return lv1[:min_length] < lv2[:min_length] - - min_version = self._compilers_min_version.get(str(self.settings.compiler), False) - if min_version and loose_lt_semver(str(self.settings.compiler.version), min_version): + if self.settings.compiler.cppstd: + check_min_cppstd(self, self._min_cppstd) + 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( - "{} requires C++{}, which your compiler does not support.".format(self.name, self._min_cppstd) + f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." ) + if self.version == "1.1.1" and self.settings.arch == "armv8": + raise ConanInvalidConfiguration("armv8 is not supported by unleash-client-cpp 1.1.1") def source(self): - tools.get(**self.conan_data["sources"][self.version], - strip_root=True, destination=self._source_subfolder) - - def _configure_cmake(self): - if self._cmake: - return self._cmake - self._cmake = CMake(self) - self._cmake.definitions["ENABLE_TESTING"] = False - self._cmake.definitions["ENABLE_TEST_COVERAGE"] = False - self._cmake.configure(build_folder=self._build_subfolder) - return self._cmake + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["ENABLE_TESTING"] = False + tc.variables["ENABLE_TEST_COVERAGE"] = False + tc.generate() + deps = CMakeDeps(self) + deps.generate() def build(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) - cmake = self._configure_cmake() + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure() cmake.build() def package(self): - self.copy("LICENSE", dst="licenses", src=self._source_subfolder) - cmake = self._configure_cmake() + copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + cmake = CMake(self) cmake.install() - tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) def package_info(self): self.cpp_info.set_property("cmake_file_name", "unleash") @@ -113,4 +103,3 @@ def package_info(self): self.cpp_info.names["cmake_find_package"] = "unleash" self.cpp_info.names["cmake_find_package_multi"] = "unleash" - diff --git a/recipes/unleash-client-cpp/all/patches/0002-fix-includes.patch b/recipes/unleash-client-cpp/all/patches/0002-fix-includes.patch new file mode 100644 index 0000000000000..5d7e861ae2b0f --- /dev/null +++ b/recipes/unleash-client-cpp/all/patches/0002-fix-includes.patch @@ -0,0 +1,32 @@ +--- src/strategies/applicationhostname.cpp ++++ src/strategies/applicationhostname.cpp +@@ -6,7 +6,7 @@ + #else + #include + #endif +-#include ++#include + + + namespace unleash { + +--- src/strategies/remoteaddress.cpp ++++ src/strategies/remoteaddress.cpp +@@ -1,5 +1,6 @@ + #include "unleash/strategies/remoteaddress.h" + #include ++#include + + namespace unleash { + RemoteAddress::RemoteAddress(std::string_view parameters, std::string_view constraints) : Strategy("remoteAddress", constraints) { + +--- src/strategies/userwithid.cpp ++++ src/strategies/userwithid.cpp +@@ -1,6 +1,6 @@ + #include "unleash/strategies/userwithid.h" +-#include + #include ++#include + + namespace unleash { + UserWithId::UserWithId(std::string_view parameters, std::string_view constraints) : Strategy("userWithId", constraints) { diff --git a/recipes/unleash-client-cpp/all/test_package/CMakeLists.txt b/recipes/unleash-client-cpp/all/test_package/CMakeLists.txt index 5dfa06d3b7057..abb11a6fea8c2 100644 --- a/recipes/unleash-client-cpp/all/test_package/CMakeLists.txt +++ b/recipes/unleash-client-cpp/all/test_package/CMakeLists.txt @@ -1,10 +1,7 @@ -cmake_minimum_required(VERSION 3.8) -project(test_package) +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - -find_package(unleash CONFIG REQUIRED) +find_package(unleash REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) target_link_libraries(${PROJECT_NAME} unleash::unleash) diff --git a/recipes/unleash-client-cpp/all/test_package/conanfile.py b/recipes/unleash-client-cpp/all/test_package/conanfile.py index 38f4483872d47..ef5d7042163ec 100644 --- a/recipes/unleash-client-cpp/all/test_package/conanfile.py +++ b/recipes/unleash-client-cpp/all/test_package/conanfile.py @@ -1,10 +1,19 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake import os class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "cmake", "cmake_find_package_multi" + 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) @@ -12,6 +21,6 @@ def build(self): 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) + 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/unleash-client-cpp/all/test_package/test_package.cpp b/recipes/unleash-client-cpp/all/test_package/test_package.cpp index 9af855c3e03d7..536cabbc9204f 100644 --- a/recipes/unleash-client-cpp/all/test_package/test_package.cpp +++ b/recipes/unleash-client-cpp/all/test_package/test_package.cpp @@ -1,10 +1,11 @@ -#include - #include +#include + int main() { - unleash::UnleashClient unleashClient = unleash::UnleashClient::create("production", "https://www.apple.com/%"); + unleash::UnleashClient unleashClient = unleash::UnleashClient::create("production", "urlMock"); + std::cout << unleashClient << std::endl; unleashClient.initializeClient(); - return unleashClient.isEnabled("feature.toogle"); - + unleashClient.isEnabled("feature.toogle"); + return 0; } diff --git a/recipes/unleash-client-cpp/all/test_v1_package/CMakeLists.txt b/recipes/unleash-client-cpp/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..91630d79f4abb --- /dev/null +++ b/recipes/unleash-client-cpp/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/unleash-client-cpp/all/test_v1_package/conanfile.py b/recipes/unleash-client-cpp/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..38f4483872d47 --- /dev/null +++ b/recipes/unleash-client-cpp/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/unleash-client-cpp/config.yml b/recipes/unleash-client-cpp/config.yml index 60d31991f5141..4d32e3eeef7e4 100644 --- a/recipes/unleash-client-cpp/config.yml +++ b/recipes/unleash-client-cpp/config.yml @@ -1,3 +1,5 @@ versions: + "1.3.0": + folder: all "1.1.1": folder: all