diff --git a/recipes/enjincppsdk/all/CMakeLists.txt b/recipes/enjincppsdk/all/CMakeLists.txt deleted file mode 100644 index 9d48e327cd88a..0000000000000 --- a/recipes/enjincppsdk/all/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12) -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup(KEEP_RPATHS) - -add_subdirectory("source_subfolder") diff --git a/recipes/enjincppsdk/all/conanfile.py b/recipes/enjincppsdk/all/conanfile.py index 172ca8e02037d..8af63eb0a3f23 100644 --- a/recipes/enjincppsdk/all/conanfile.py +++ b/recipes/enjincppsdk/all/conanfile.py @@ -1,21 +1,26 @@ -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.apple import is_apple_os +from conan.tools.build import check_min_cppstd +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.files import copy, get, rmdir, save, replace_in_file +from conan.tools.scm import Version + +required_conan_version = ">=1.53.0" class EnjinCppSdk(ConanFile): name = "enjincppsdk" description = "A C++ SDK for development on the Enjin blockchain platform." license = "Apache-2.0" - topics = ("enjin", "sdk", "blockchain") - homepage = "https://github.com/enjin/enjin-cpp-sdk" url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/enjin/enjin-cpp-sdk" + topics = ("enjin", "sdk", "blockchain") - settings = "os", "compiler", "arch", "build_type" - generators = "cmake", "cmake_find_package", "cmake_find_package_multi" - + package_type = "library" + settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], @@ -29,108 +34,107 @@ class EnjinCppSdk(ConanFile): "with_default_ws_client": False, } - _cmake = None - short_paths = True - - @property - def _source_subfolder(self): - return "source_subfolder" - - @property - def _build_subfolder(self): - return "build_subfolder" - @property def _minimum_compilers_version(self): return { "Visual Studio": "16", + "msvc": "192", "gcc": "9", "clang": "10", + "apple-clang": "12", } - def export_sources(self): - self.copy("CMakeLists.txt") - def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.options.shared: - del self.options.fPIC + self.options.rm_safe("fPIC") if self.options.with_default_http_client: self.options["cpp-httplib"].with_openssl = True self.options["spdlog"].header_only = True + def layout(self): + cmake_layout(self, src_folder="src") + def requirements(self): if self.options.with_default_http_client: - self.requires("cpp-httplib/0.8.5") + self.requires("cpp-httplib/0.14.1") if self.options.with_default_ws_client: - self.requires("ixwebsocket/11.0.4") - - self.requires("rapidjson/1.1.0") - self.requires("spdlog/1.8.2") + self.requires("ixwebsocket/11.4.3") - def build_requirements(self): - self.build_requires("cmake/3.16.9") + self.requires("rapidjson/cci.20220822") + self.requires("spdlog/1.12.0") def validate(self): # Validations for OS - if self.settings.os == "Macos": - raise ConanInvalidConfiguration("macOS is not supported at this time. Contributions are welcomed.") + if is_apple_os(self): + raise ConanInvalidConfiguration(f"{self.settings.os} is not supported at this time. Contributions are welcomed.") # Validations for minimum required C++ standard compiler = self.settings.compiler - if compiler.get_safe("cppstd"): - tools.check_min_cppstd(self, 17) - + check_min_cppstd(self, 17) minimum_version = self._minimum_compilers_version.get(str(compiler), False) if not minimum_version: - self.output.warn("C++17 support is required. Your compiler is unknown. Assuming it supports C++17.") - elif tools.Version(compiler.version) < minimum_version: + self.output.warning("C++17 support is required. Your compiler is unknown. Assuming it supports C++17.") + elif Version(compiler.version) < minimum_version: raise ConanInvalidConfiguration("C++17 support is required, which your compiler does not support.") if compiler == "clang" and compiler.libcxx != "libstdc++11": raise ConanInvalidConfiguration("libstdc++11 is required for clang.") # Validations for dependencies - if not self.options["spdlog"].header_only: + if not self.dependencies["spdlog"].options.header_only: raise ConanInvalidConfiguration(f"{self.name} requires spdlog:header_only=True to be enabled.") - if self.options.with_default_http_client and not self.options["cpp-httplib"].with_openssl: - raise ConanInvalidConfiguration(f"{self.name} requires cpp-httplib:with_openssl=True when using " - f"with_default_http_client=True.") - - def source(self): - tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) + if self.options.with_default_http_client and not self.dependencies["cpp-httplib"].options.with_openssl: + raise ConanInvalidConfiguration( + f"{self.name} requires cpp-httplib:with_openssl=True when using with_default_http_client=True." + ) - def _configure_cmake(self): - if self._cmake: - return self._cmake + def build_requirements(self): + self.tool_requires("cmake/[>=3.16]") - self._cmake = CMake(self) - self._cmake.definitions["ENJINSDK_BUILD_SHARED"] = self.options.shared - self._cmake.definitions["ENJINSDK_BUILD_TESTS"] = False - self._cmake.configure(build_folder=self._build_subfolder) - return self._cmake + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["ENJINSDK_BUILD_SHARED"] = self.options.shared + tc.variables["ENJINSDK_BUILD_TESTS"] = False + tc.generate() + tc = CMakeDeps(self) + tc.generate() + + def _patch_sources(self): + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "RAPIDJSON", "RapidJSON") + # Remove version check for RapidJSON + save(self, os.path.join(self.source_folder, "cmake", "enjinsdk_find_rapidjson.cmake"), + "find_package(RapidJSON REQUIRED CONFIG)") def build(self): - cmake = self._configure_cmake() + self._patch_sources() + cmake = CMake(self) + cmake.configure() cmake.build() def package(self): - self.copy(pattern="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")) - tools.rmdir(os.path.join(self.package_folder, "lib", "enjinsdk")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "lib", "enjinsdk")) def package_info(self): + self.cpp_info.libs = ["enjinsdk"] + self.cpp_info.set_property("cmake_file_name", "enjinsdk") self.cpp_info.set_property("cmake_target_name", "enjinsdk::enjinsdk") + + # TODO: to remove in conan v2 once cmake_find_package_* generators removed self.cpp_info.names["cmake_find_package"] = "enjinsdk" self.cpp_info.names["cmake_find_package_multi"] = "enjinsdk" - self.cpp_info.libs = ["enjinsdk"] diff --git a/recipes/enjincppsdk/all/test_package/CMakeLists.txt b/recipes/enjincppsdk/all/test_package/CMakeLists.txt index 30e76e5090606..a986c4e5f3431 100644 --- a/recipes/enjincppsdk/all/test_package/CMakeLists.txt +++ b/recipes/enjincppsdk/all/test_package/CMakeLists.txt @@ -1,9 +1,6 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.15) project(test_package CXX) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - find_package(enjinsdk REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) diff --git a/recipes/enjincppsdk/all/test_package/conanfile.py b/recipes/enjincppsdk/all/test_package/conanfile.py index 4a5eb7410ea85..ef5d7042163ec 100644 --- a/recipes/enjincppsdk/all/test_package/conanfile.py +++ b/recipes/enjincppsdk/all/test_package/conanfile.py @@ -1,12 +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 -required_conan_version = ">=1.43.0" - class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "cmake_find_package_multi" + 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) @@ -14,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/enjincppsdk/all/test_v1_package/CMakeLists.txt b/recipes/enjincppsdk/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..91630d79f4abb --- /dev/null +++ b/recipes/enjincppsdk/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/enjincppsdk/all/test_v1_package/conanfile.py b/recipes/enjincppsdk/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..4a5eb7410ea85 --- /dev/null +++ b/recipes/enjincppsdk/all/test_v1_package/conanfile.py @@ -0,0 +1,19 @@ +from conans import ConanFile, CMake, tools +import os + +required_conan_version = ">=1.43.0" + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + 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)