From 126c82ea8eda5d5a274c64b9d95727a487783076 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Mon, 17 Oct 2022 16:45:38 +0200 Subject: [PATCH] (#13505) oatpp-openssl: conan v2 support --- recipes/oatpp-openssl/all/CMakeLists.txt | 7 - recipes/oatpp-openssl/all/conanfile.py | 120 ++++++++++-------- .../all/test_package/CMakeLists.txt | 13 +- .../all/test_package/conanfile.py | 20 ++- .../all/test_v1_package/CMakeLists.txt | 11 ++ .../all/test_v1_package/conanfile.py | 17 +++ 6 files changed, 115 insertions(+), 73 deletions(-) delete mode 100644 recipes/oatpp-openssl/all/CMakeLists.txt create mode 100644 recipes/oatpp-openssl/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/oatpp-openssl/all/test_v1_package/conanfile.py diff --git a/recipes/oatpp-openssl/all/CMakeLists.txt b/recipes/oatpp-openssl/all/CMakeLists.txt deleted file mode 100644 index 7b920d87ae627..0000000000000 --- a/recipes/oatpp-openssl/all/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.1) # Mininum as required oatpp -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup() - -add_subdirectory(source_subfolder) diff --git a/recipes/oatpp-openssl/all/conanfile.py b/recipes/oatpp-openssl/all/conanfile.py index b250393d708cc..d109d1b7545bb 100644 --- a/recipes/oatpp-openssl/all/conanfile.py +++ b/recipes/oatpp-openssl/all/conanfile.py @@ -1,8 +1,14 @@ -from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration +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 copy, get, rmdir +from conan.tools.microsoft import is_msvc +from conan.tools.scm import Version import os -required_conan_version = ">=1.43.0" +required_conan_version = ">=1.51.1" + class OatppOpenSSLConan(ConanFile): name = "oatpp-openssl" @@ -11,21 +17,16 @@ class OatppOpenSSLConan(ConanFile): url = "https://github.com/conan-io/conan-center-index" description = "Oat++ OpenSSL library" topics = ("oat++", "oatpp", "openssl") - settings = "os", "arch", "compiler", "build_type" - options = {"shared": [True, False], "fPIC": [True, False]} - default_options = {"shared": False, "fPIC": True} - generators = "cmake", "cmake_find_package" - exports_sources = "CMakeLists.txt" - - _cmake = None - - @property - def _source_subfolder(self): - return "source_subfolder" - @property - def _build_subfolder(self): - return "build_subfolder" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } def config_options(self): if self.settings.os == "Windows": @@ -33,60 +34,75 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC + try: + del self.options.fPIC + except Exception: + pass - def validate(self): - if self.settings.compiler.cppstd: - tools.check_min_cppstd(self, 11) - - if self.settings.os == "Windows" and self.options.shared: - raise ConanInvalidConfiguration("oatpp-openssl can not be built as shared library on Windows") - - if self.settings.compiler == "gcc" and tools.Version(self.settings.compiler.version) < "5": - raise ConanInvalidConfiguration("oatpp-openssl requires GCC >=5") + def layout(self): + cmake_layout(self, src_folder="src") def requirements(self): - self.requires("oatpp/" + self.version) - self.requires("openssl/3.0.1") + self.requires(f"oatpp/{self.version}") + self.requires("openssl/3.0.5") - def source(self): - tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) + def validate(self): + if self.info.settings.compiler.get_safe("cppstd"): + check_min_cppstd(self, 11) - def _configure_cmake(self): - if self._cmake: - return self._cmake + if is_msvc(self) and self.info.options.shared: + raise ConanInvalidConfiguration(f"{self.ref} can not be built as shared library with msvc") - self._cmake = CMake(self) - self._cmake.definitions["OATPP_BUILD_TESTS"] = False - self._cmake.definitions["OATPP_MODULES_LOCATION"] = "INSTALLED" - self._cmake.configure(build_folder=self._build_subfolder) - return self._cmake + if self.info.settings.compiler == "gcc" and Version(self.info.settings.compiler.version) < "5": + raise ConanInvalidConfiguration(f"{self.ref} requires GCC >=5") + + def source(self): + get(self, **self.conan_data["sources"][self.version], + destination=self.source_folder, strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["OATPP_BUILD_TESTS"] = False + tc.variables["OATPP_MODULES_LOCATION"] = "INSTALLED" + # Honor BUILD_SHARED_LIBS from conan_toolchain (see https://github.com/conan-io/conan/issues/11840) + tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW" + tc.generate() + deps = CMakeDeps(self) + deps.generate() def build(self): - cmake = self._configure_cmake() + cmake = CMake(self) + cmake.configure() cmake.build() def package(self): - self.copy("LICENSE", src=self._source_subfolder, dst="licenses") - cmake = self._configure_cmake() + copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + 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.filenames["cmake_find_package"] = "oatpp-openssl" - self.cpp_info.filenames["cmake_find_package_multi"] = "oatpp-openssl" self.cpp_info.set_property("cmake_file_name", "oatpp-openssl") - self.cpp_info.names["cmake_find_package"] = "oatpp" - self.cpp_info.names["cmake_find_package_multi"] = "oatpp" self.cpp_info.set_property("cmake_target_name", "oatpp::oatpp-openssl") - self.cpp_info.components["_oatpp-openssl"].names["cmake_find_package"] = "oatpp-openssl" - self.cpp_info.components["_oatpp-openssl"].names["cmake_find_package_multi"] = "oatpp-openssl" - self.cpp_info.components["_oatpp-openssl"].set_property("cmake_target_name", "oatpp::oatpp-openssl") + # TODO: back to global scope in conan v2 once legacy generators removed self.cpp_info.components["_oatpp-openssl"].includedirs = [ - os.path.join("include", "oatpp-{}".format(self.version), "oatpp-openssl") + os.path.join("include", f"oatpp-{self.version}", "oatpp-openssl") ] - self.cpp_info.components["_oatpp-openssl"].libdirs = [os.path.join("lib", "oatpp-{}".format(self.version))] + self.cpp_info.components["_oatpp-openssl"].libdirs = [os.path.join("lib", f"oatpp-{self.version}")] + if self.settings.os == "Windows" and self.options.shared: + self.cpp_info.components["_oatpp-openssl"].bindirs = [os.path.join("bin", f"oatpp-{self.version}")] + else: + self.cpp_info.components["_oatpp-openssl"].bindirs = [] self.cpp_info.components["_oatpp-openssl"].libs = ["oatpp-openssl"] if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.components["_oatpp-openssl"].system_libs = ["pthread"] + + # TODO: to remove in conan v2 once legacy generators removed + self.cpp_info.filenames["cmake_find_package"] = "oatpp-openssl" + self.cpp_info.filenames["cmake_find_package_multi"] = "oatpp-openssl" + self.cpp_info.names["cmake_find_package"] = "oatpp" + self.cpp_info.names["cmake_find_package_multi"] = "oatpp" + self.cpp_info.components["_oatpp-openssl"].names["cmake_find_package"] = "oatpp-openssl" + self.cpp_info.components["_oatpp-openssl"].names["cmake_find_package_multi"] = "oatpp-openssl" + self.cpp_info.components["_oatpp-openssl"].set_property("cmake_target_name", "oatpp::oatpp-openssl") self.cpp_info.components["_oatpp-openssl"].requires = ["oatpp::oatpp", "openssl::openssl"] diff --git a/recipes/oatpp-openssl/all/test_package/CMakeLists.txt b/recipes/oatpp-openssl/all/test_package/CMakeLists.txt index b28526769f48c..716aedd7390f1 100644 --- a/recipes/oatpp-openssl/all/test_package/CMakeLists.txt +++ b/recipes/oatpp-openssl/all/test_package/CMakeLists.txt @@ -1,13 +1,8 @@ -cmake_minimum_required(VERSION 3.1) -project(test_package CXX) +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES CXX) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - -find_package(oatpp-openssl REQUIRED) +find_package(oatpp-openssl REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) - -set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) - target_link_libraries(${PROJECT_NAME} PRIVATE oatpp::oatpp-openssl) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) diff --git a/recipes/oatpp-openssl/all/test_package/conanfile.py b/recipes/oatpp-openssl/all/test_package/conanfile.py index a77f6e7a20977..0a6bc68712d90 100644 --- a/recipes/oatpp-openssl/all/test_package/conanfile.py +++ b/recipes/oatpp-openssl/all/test_package/conanfile.py @@ -1,10 +1,19 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout import os -from conans import ConanFile, CMake, tools -class OatppOpenSSLTestConan(ConanFile): +class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "cmake", "cmake_find_package" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) def build(self): cmake = CMake(self) @@ -12,5 +21,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - self.run(os.path.join("bin", "test_package"), run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/oatpp-openssl/all/test_v1_package/CMakeLists.txt b/recipes/oatpp-openssl/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..07d783bdbcaec --- /dev/null +++ b/recipes/oatpp-openssl/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES CXX) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +find_package(oatpp-openssl REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} ../test_package/test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE oatpp::oatpp-openssl) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) diff --git a/recipes/oatpp-openssl/all/test_v1_package/conanfile.py b/recipes/oatpp-openssl/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..38f4483872d47 --- /dev/null +++ b/recipes/oatpp-openssl/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)