From e5428de101b1a846316b8c438f316366a8a0284f Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Sat, 15 Oct 2022 19:55:36 +0200 Subject: [PATCH] conan v2 support --- recipes/xerces-c/all/CMakeLists.txt | 7 -- recipes/xerces-c/all/conandata.yml | 4 - recipes/xerces-c/all/conanfile.py | 96 +++++++++---------- .../xerces-c/all/test_package/CMakeLists.txt | 13 +-- .../xerces-c/all/test_package/conanfile.py | 19 +++- .../all/test_v1_package/CMakeLists.txt | 11 +++ .../xerces-c/all/test_v1_package/conanfile.py | 17 ++++ 7 files changed, 93 insertions(+), 74 deletions(-) delete mode 100644 recipes/xerces-c/all/CMakeLists.txt create mode 100644 recipes/xerces-c/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/xerces-c/all/test_v1_package/conanfile.py diff --git a/recipes/xerces-c/all/CMakeLists.txt b/recipes/xerces-c/all/CMakeLists.txt deleted file mode 100644 index 9d48e327cd88a..0000000000000 --- a/recipes/xerces-c/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/xerces-c/all/conandata.yml b/recipes/xerces-c/all/conandata.yml index 1fe9340e9c368..689ea35941ef9 100644 --- a/recipes/xerces-c/all/conandata.yml +++ b/recipes/xerces-c/all/conandata.yml @@ -8,11 +8,7 @@ sources: patches: "3.2.3": - patch_file: "patches/0001-remove-test-samples.patch" - base_path: "source_subfolder" - patch_file: "patches/0002-find-icu-programs.patch" - base_path: "source_subfolder" "3.2.2": - patch_file: "patches/0001-remove-test-samples.patch" - base_path: "source_subfolder" - patch_file: "patches/0002-find-icu-programs.patch" - base_path: "source_subfolder" diff --git a/recipes/xerces-c/all/conanfile.py b/recipes/xerces-c/all/conanfile.py index 06b8a858e9d3e..de59d70169466 100644 --- a/recipes/xerces-c/all/conanfile.py +++ b/recipes/xerces-c/all/conanfile.py @@ -1,8 +1,11 @@ -from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.env import VirtualBuildEnv +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.files import apply_conandata_patches, collect_libs, copy, export_conandata_patches, get, rmdir import os -required_conan_version = ">=1.43.0" +required_conan_version = ">=1.52.0" class XercesCConan(ConanFile): @@ -36,21 +39,8 @@ class XercesCConan(ConanFile): "mutex_manager": "standard", } - generators = "cmake", "cmake_find_package" - _cmake = None - - @property - def _source_subfolder(self): - return "source_subfolder" - - @property - def _build_subfolder(self): - return "build_subfolder" - 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": @@ -67,13 +57,19 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC + try: + del self.options.fPIC + except Exception: + pass + + def layout(self): + cmake_layout(self, src_folder="src") def requirements(self): if "icu" in (self.options.transcoder, self.options.message_loader): - self.requires("icu/70.1") + self.requires("icu/71.1") if self.options.network_accessor == "curl": - self.requires("libcurl/7.80.0") + self.requires("libcurl/7.85.0") def _validate(self, option, value, os): """ @@ -85,7 +81,7 @@ def _validate(self, option, value, os): :param os: either a single string or a tuple of strings containing the OS(es) that `value` is valid on """ - if self.settings.os not in os and getattr(self.options, option) == value: + if self.info.settings.os not in os and getattr(self.info.options, option) == value: raise ConanInvalidConfiguration( "Option '{option}={value}' is only supported on {os}".format( option=option, value=value, os=os @@ -93,7 +89,7 @@ def _validate(self, option, value, os): ) def validate(self): - if self.settings.os not in ("Windows", "Macos", "Linux"): + if self.info.settings.os not in ("Windows", "Macos", "Linux"): raise ConanInvalidConfiguration("OS is not supported") self._validate("char_type", "wchar_t", ("Windows", )) self._validate("network_accessor", "winsock", ("Windows", )) @@ -107,51 +103,51 @@ def validate(self): def build_requirements(self): if hasattr(self, "settings_build") and self.options.message_loader == "icu": - self.build_requires("icu/70.1") + self.tool_requires("icu/71.1") def source(self): - tools.get(**self.conan_data["sources"][self.version], - destination=self._source_subfolder, strip_root=True) + get(self, **self.conan_data["sources"][self.version], + destination=self.source_folder, strip_root=True) - def _configure_cmake(self): - if self._cmake: - return self._cmake - self._cmake = CMake(self) + def generate(self): + env = VirtualBuildEnv(self) + env.generate() + tc = CMakeToolchain(self) # https://xerces.apache.org/xerces-c/build-3.html - self._cmake.definitions["network-accessor"] = self.options.network_accessor - self._cmake.definitions["transcoder"] = self.options.transcoder - self._cmake.definitions["message-loader"] = self.options.message_loader - self._cmake.definitions["xmlch-type"] = self.options.char_type - self._cmake.definitions["mutex-manager"] = self.options.mutex_manager + tc.variables["network-accessor"] = self.options.network_accessor + tc.variables["transcoder"] = self.options.transcoder + tc.variables["message-loader"] = self.options.message_loader + tc.variables["xmlch-type"] = self.options.char_type + tc.variables["mutex-manager"] = self.options.mutex_manager # avoid picking up system dependency - self._cmake.definitions["CMAKE_DISABLE_FIND_PACKAGE_CURL"] = self.options.network_accessor != "curl" - self._cmake.definitions["CMAKE_DISABLE_FIND_PACKAGE_ICU"] = "icu" not in (self.options.transcoder, self.options.message_loader) - self._cmake.configure(build_folder=self._build_subfolder) - return self._cmake + tc.variables["CMAKE_DISABLE_FIND_PACKAGE_CURL"] = self.options.network_accessor != "curl" + tc.variables["CMAKE_DISABLE_FIND_PACKAGE_ICU"] = "icu" not in (self.options.transcoder, self.options.message_loader) + 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(pattern="LICENSE", dst="licenses", src=self._source_subfolder) - self.copy(pattern="NOTICE", dst="licenses", src=self._source_subfolder) - cmake = self._configure_cmake() + for license in ("LICENSE", "NOTICE"): + copy(self, license, src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) cmake.install() - # remove unneeded directories - tools.rmdir(os.path.join(self.package_folder, "share")) - tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) - tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) - tools.rmdir(os.path.join(self.package_folder, "cmake")) + rmdir(self, os.path.join(self.package_folder, "share")) + 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, "cmake")) def package_info(self): self.cpp_info.set_property("cmake_find_mode", "both") self.cpp_info.set_property("cmake_file_name", "XercesC") self.cpp_info.set_property("cmake_target_name", "XercesC::XercesC") self.cpp_info.set_property("pkg_config_name", "xerces-c") - self.cpp_info.libs = tools.collect_libs(self) + self.cpp_info.libs = collect_libs(self) if self.settings.os == "Macos": self.cpp_info.frameworks = ["CoreFoundation", "CoreServices"] elif self.settings.os in ["Linux", "FreeBSD"]: diff --git a/recipes/xerces-c/all/test_package/CMakeLists.txt b/recipes/xerces-c/all/test_package/CMakeLists.txt index 71e1760854d13..3f03b5b9ef2cd 100644 --- a/recipes/xerces-c/all/test_package/CMakeLists.txt +++ b/recipes/xerces-c/all/test_package/CMakeLists.txt @@ -1,11 +1,8 @@ -cmake_minimum_required(VERSION 3.1) -project(test_package) +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES CXX) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - -find_package(XercesC REQUIRED CONFIG) +find_package(XercesC REQUIRED) add_executable(${PROJECT_NAME} test_package.cpp) -target_link_libraries(${PROJECT_NAME} XercesC::XercesC) -set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) +target_link_libraries(${PROJECT_NAME} PRIVATE XercesC::XercesC) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) diff --git a/recipes/xerces-c/all/test_package/conanfile.py b/recipes/xerces-c/all/test_package/conanfile.py index 38f4483872d47..0a6bc68712d90 100644 --- a/recipes/xerces-c/all/test_package/conanfile.py +++ b/recipes/xerces-c/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, cmake_layout import os class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "cmake", "cmake_find_package_multi" + 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,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.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/xerces-c/all/test_v1_package/CMakeLists.txt b/recipes/xerces-c/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..7c3c78b82bae7 --- /dev/null +++ b/recipes/xerces-c/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(XercesC REQUIRED) + +add_executable(${PROJECT_NAME} ../test_package/test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE XercesC::XercesC) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) diff --git a/recipes/xerces-c/all/test_v1_package/conanfile.py b/recipes/xerces-c/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..19e6a0c06e3d8 --- /dev/null +++ b/recipes/xerces-c/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" + + 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)