From 8e5cdea5b53b8dc7c24ffd62a70381a28f3d4a3f Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Mon, 4 Mar 2024 13:33:42 +0100 Subject: [PATCH 1/7] Improve Conan recipe support Signed-off-by: Uilian Ries --- conanfile.py | 55 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/conanfile.py b/conanfile.py index f8892ad6de..9d1b000817 100755 --- a/conanfile.py +++ b/conanfile.py @@ -1,9 +1,9 @@ #!/usr/bin/env python -from conan import ConanFile, tools, __version__ as conan_version +from conan import ConanFile from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout -from conan.tools import files, scm +from conan.tools.files import copy, rmdir +from conan.tools.build import check_min_cppstd import os -import shutil import re required_conan_version = ">=1.53.0" @@ -22,6 +22,15 @@ class CatchConan(ConanFile): settings = "os", "compiler", "build_type", "arch" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } + def set_version(self): pattern = re.compile(r"\w*VERSION (\d+\.\d+\.\d+) # CML version placeholder, don't delete") with open("CMakeLists.txt") as file: @@ -35,36 +44,38 @@ def set_version(self): def layout(self): cmake_layout(self) + def validate(self): + if self.settings.compiler.get_safe("cppstd"): + check_min_cppstd(self, 17) + def generate(self): tc = CMakeToolchain(self) + tc.cache_variables["BUILD_TESTING"] = False + tc.cache_variables["CATCH_INSTALL_DOCS"] = False + tc.cache_variables["CATCH_INSTALL_EXTRAS"] = True tc.generate() deps = CMakeDeps(self) deps.generate() - def _configure_cmake(self): - cmake = CMake(self) - - # These are option variables. The toolchain in conan 2 doesn't appear to - # set these correctly so you have to do it in the configure variables. - cmake.configure(variables= { - "BUILD_TESTING": "OFF", - "CATCH_INSTALL_DOCS": "OFF", - "CATCH_INSTALL_EXTRAS": "ON", - } - ) - return cmake - def build(self): - cmake = self._configure_cmake() + cmake = CMake(self) + cmake.configure() cmake.build() def package(self): - cmake = self._configure_cmake() + copy(self, "LICENSE.txt", src=str(self.recipe_folder), dst=os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) cmake.install() - - os.mkdir(f'{self.package_folder}/licenses/') - shutil.copy2(f'{self.recipe_folder}/LICENSE.txt', f'{self.package_folder}/licenses/') + rmdir(self, os.path.join(self.package_folder, "share")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + for cmake_file in ["ParseAndAddCatchTests.cmake", "Catch.cmake", "CatchAddTests.cmake"]: + copy( + self, + cmake_file, + src=os.path.join(self.export_sources_folder, "extras"), + dst=os.path.join(self.package_folder, "lib", "cmake", "Catch2"), + ) def package_info(self): lib_suffix = "d" if self.settings.build_type == "Debug" else "" @@ -84,4 +95,4 @@ def package_info(self): self.cpp_info.components["catch2main"].set_property("cmake_target_name", "Catch2::Catch2WithMain") self.cpp_info.components["catch2main"].set_property("pkg_config_name", "catch2-with-main") self.cpp_info.components["catch2main"].libs = ["Catch2Main" + lib_suffix] - self.cpp_info.components["catch2main"].requires = ["catch2base"] \ No newline at end of file + self.cpp_info.components["catch2main"].requires = ["catch2base"] From 0d4754a186d108bb85aefadfe42cdc71ce35dc04 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Mon, 4 Mar 2024 13:39:48 +0100 Subject: [PATCH 2/7] export files Signed-off-by: Uilian Ries --- conanfile.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/conanfile.py b/conanfile.py index 9d1b000817..8cc591a6db 100755 --- a/conanfile.py +++ b/conanfile.py @@ -16,10 +16,6 @@ class CatchConan(ConanFile): homepage = url license = "BSL-1.0" version = "latest" - - exports = "LICENSE.txt" - exports_sources = ("src/*", "CMakeLists.txt", "CMake/*", "extras/*") - settings = "os", "compiler", "build_type", "arch" options = { @@ -41,6 +37,15 @@ def set_version(self): self.output.info(f'Using version: {self.version}') + def export(self): + copy(self, "LICENSE.txt", src=self.recipe_folder, dst=self.export_folder) + + def export_sources(self): + copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder) + copy(self, "src/*", src=self.recipe_folder, dst=self.export_sources_folder) + copy(self, "extras/*", src=self.recipe_folder, dst=self.export_sources_folder) + copy(self, "CMake/*", src=self.recipe_folder, dst=self.export_sources_folder) + def layout(self): cmake_layout(self) From c6d8d98f7bfad285e118689d78af1efe685a2b84 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Mon, 4 Mar 2024 13:50:03 +0100 Subject: [PATCH 3/7] supports c++14 Signed-off-by: Uilian Ries --- conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index 8cc591a6db..ff992c427b 100755 --- a/conanfile.py +++ b/conanfile.py @@ -51,7 +51,7 @@ def layout(self): def validate(self): if self.settings.compiler.get_safe("cppstd"): - check_min_cppstd(self, 17) + check_min_cppstd(self, 14) def generate(self): tc = CMakeToolchain(self) From bc28864fb9fe3c56693bc74ce83d7a1023a998fc Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Mon, 4 Mar 2024 14:08:31 +0100 Subject: [PATCH 4/7] update Conan client in the CI Signed-off-by: Uilian Ries --- .github/workflows/package-manager-builds.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/package-manager-builds.yaml b/.github/workflows/package-manager-builds.yaml index cb55b753ee..6d90d14054 100644 --- a/.github/workflows/package-manager-builds.yaml +++ b/.github/workflows/package-manager-builds.yaml @@ -9,12 +9,12 @@ jobs: strategy: matrix: conan_version: - - '1.62' - - '2.0' + - '1.63' + - '2.1' include: # Conan 1 has default profiles installed - - conan_version: '1.62' + - conan_version: '1.63' profile_generate: 'false' steps: From 6156f2c5ed115de15189090430e07f3957214923 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Mon, 4 Mar 2024 14:08:50 +0100 Subject: [PATCH 5/7] Better compatibility with Conan 1.x Signed-off-by: Uilian Ries --- .conan/test_package/CMakeLists.txt | 3 ++- .conan/test_package/conanfile.py | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.conan/test_package/CMakeLists.txt b/.conan/test_package/CMakeLists.txt index ff9496adb4..00a6af23df 100644 --- a/.conan/test_package/CMakeLists.txt +++ b/.conan/test_package/CMakeLists.txt @@ -4,4 +4,5 @@ project(PackageTest CXX) find_package(Catch2 CONFIG REQUIRED) add_executable(test_package test_package.cpp) -target_link_libraries(test_package Catch2::Catch2WithMain) \ No newline at end of file +target_link_libraries(test_package Catch2::Catch2WithMain) +target_compile_features(test_package PRIVATE cxx_std_14) diff --git a/.conan/test_package/conanfile.py b/.conan/test_package/conanfile.py index 88f3d137fa..dc03876433 100644 --- a/.conan/test_package/conanfile.py +++ b/.conan/test_package/conanfile.py @@ -3,12 +3,14 @@ from conan import ConanFile from conan.tools.cmake import CMake, cmake_layout from conan.tools.build import can_run +from conan.tools.files import save, load import os class TestPackageConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "CMakeToolchain", "CMakeDeps" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" def requirements(self): self.requires(self.tested_reference_str) @@ -16,6 +18,12 @@ def requirements(self): def layout(self): cmake_layout(self) + def generate(self): + save(self, os.path.join(self.build_folder, "package_folder"), + self.dependencies[self.tested_reference_str].package_folder) + save(self, os.path.join(self.build_folder, "license"), + self.dependencies[self.tested_reference_str].license) + def build(self): cmake = CMake(self) cmake.configure() @@ -26,8 +34,7 @@ def test(self): cmd = os.path.join(self.cpp.build.bindir, "test_package") self.run(cmd, env="conanrun") - # If we are on conan 2 we can check the license info is populated - if hasattr(self, 'dependencies'): - catch2 = self.dependencies["catch2"] - assert os.path.exists(f'{catch2.package_folder}/licenses/LICENSE.txt') - assert catch2.license == 'BSL-1.0' + package_folder = load(self, os.path.join(self.build_folder, "package_folder")) + license = load(self, os.path.join(self.build_folder, "license")) + assert os.path.isfile(os.path.join(package_folder, "licenses", "LICENSE.txt")) + assert license == 'BSL-1.0' From 3a135ff8e49112377c7267463cf2f435f84f8960 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Mon, 4 Mar 2024 14:09:11 +0100 Subject: [PATCH 6/7] Manage options and cppstd for Conan 1.x Signed-off-by: Uilian Ries --- conanfile.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index ff992c427b..aca8a766ad 100755 --- a/conanfile.py +++ b/conanfile.py @@ -3,6 +3,8 @@ from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout from conan.tools.files import copy, rmdir from conan.tools.build import check_min_cppstd +from conan.tools.scm import Version +from conan.errors import ConanInvalidConfiguration import os import re @@ -27,6 +29,21 @@ class CatchConan(ConanFile): "fPIC": True, } + @property + def _min_cppstd(self): + return "14" + + @property + def _compilers_minimum_version(self): + return { + "gcc": "7", + "Visual Studio": "15", + "msvc": "191", + "clang": "5", + "apple-clang": "10", + } + + def set_version(self): pattern = re.compile(r"\w*VERSION (\d+\.\d+\.\d+) # CML version placeholder, don't delete") with open("CMakeLists.txt") as file: @@ -46,12 +63,24 @@ def export_sources(self): copy(self, "extras/*", src=self.recipe_folder, dst=self.export_sources_folder) copy(self, "CMake/*", src=self.recipe_folder, dst=self.export_sources_folder) + 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) def validate(self): if self.settings.compiler.get_safe("cppstd"): - check_min_cppstd(self, 14) + check_min_cppstd(self, self._min_cppstd) + # INFO: Conan 1.x does not specify cppstd by default, so we need to check the compiler version instead. + 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 doesn't support") def generate(self): tc = CMakeToolchain(self) From 85b039cb3b33814b096959280ca70d9a3f36978b Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Tue, 12 Mar 2024 17:49:41 +0100 Subject: [PATCH 7/7] copy eveything from extra Signed-off-by: Uilian Ries --- conanfile.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/conanfile.py b/conanfile.py index aca8a766ad..8f45b8a975 100755 --- a/conanfile.py +++ b/conanfile.py @@ -103,13 +103,8 @@ def package(self): cmake.install() rmdir(self, os.path.join(self.package_folder, "share")) rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) - for cmake_file in ["ParseAndAddCatchTests.cmake", "Catch.cmake", "CatchAddTests.cmake"]: - copy( - self, - cmake_file, - src=os.path.join(self.export_sources_folder, "extras"), - dst=os.path.join(self.package_folder, "lib", "cmake", "Catch2"), - ) + copy(self, "*.cmake", src=os.path.join(self.export_sources_folder, "extras"), + dst=os.path.join(self.package_folder, "lib", "cmake", "Catch2")) def package_info(self): lib_suffix = "d" if self.settings.build_type == "Debug" else ""