From 7fb6df0d098e07041005946e95682df954037c15 Mon Sep 17 00:00:00 2001 From: Fernando Pelliccioni Date: Fri, 23 Sep 2022 11:05:53 +0200 Subject: [PATCH] (#13037) [Catch2] adapt recipe for Conan v2 * [Catch2] adapt recipe for Conan v2 * fixes * fixes * fixes * fixes * fixes 4 * fixes 5 * fixes 6 * Update recipes/catch2/3.x.x/conanfile.py Co-authored-by: Uilian Ries * Update recipes/catch2/3.x.x/conanfile.py Co-authored-by: Uilian Ries * Update recipes/catch2/3.x.x/conanfile.py Co-authored-by: Uilian Ries * Update recipes/catch2/3.x.x/conanfile.py * fix patches * fix * fix * remove comments * Update recipes/catch2/3.x.x/conanfile.py Co-authored-by: Chris Mc * Update recipes/catch2/3.x.x/conanfile.py Co-authored-by: Chris Mc * test package changes * Move test package files (#2) * move gtest Signed-off-by: Uilian Ries * Delete test_all.sh * Use cmake targets * Do not use settings Signed-off-by: Uilian Ries Signed-off-by: Uilian Ries Co-authored-by: Uilian Ries Co-authored-by: Chris Mc --- .../2.x.x/test_v1_package/CMakeLists.txt | 32 ++++++++ .../catch2/2.x.x/test_v1_package/conanfile.py | 24 ++++++ recipes/catch2/3.x.x/CMakeLists.txt | 10 --- recipes/catch2/3.x.x/conandata.yml | 2 - recipes/catch2/3.x.x/conanfile.py | 75 +++++++++---------- .../catch2/3.x.x/test_package/CMakeLists.txt | 5 +- .../catch2/3.x.x/test_package/conanfile.py | 29 +++++-- .../3.x.x/test_v1_package/CMakeLists.txt | 22 ++++++ .../catch2/3.x.x/test_v1_package/conanfile.py | 18 +++++ 9 files changed, 152 insertions(+), 65 deletions(-) create mode 100644 recipes/catch2/2.x.x/test_v1_package/CMakeLists.txt create mode 100644 recipes/catch2/2.x.x/test_v1_package/conanfile.py delete mode 100644 recipes/catch2/3.x.x/CMakeLists.txt create mode 100644 recipes/catch2/3.x.x/test_v1_package/CMakeLists.txt create mode 100644 recipes/catch2/3.x.x/test_v1_package/conanfile.py diff --git a/recipes/catch2/2.x.x/test_v1_package/CMakeLists.txt b/recipes/catch2/2.x.x/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000000..ba50d23310806f --- /dev/null +++ b/recipes/catch2/2.x.x/test_v1_package/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.5) +project(test_package) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +find_package(Catch2 REQUIRED) + +if(NOT WITH_PREFIX) + add_executable(test_package ../test_package/000-CatchMain.cpp ../test_package/100-Fix-Section.cpp) + target_link_libraries(test_package PRIVATE Catch2::Catch2) + + if(WITH_MAIN) + add_executable(standalone ../test_package/200-standalone.cpp) + target_link_libraries(standalone PRIVATE Catch2::Catch2WithMain) + if(WITH_BENCHMARK) + add_executable(benchmark ../test_package/300-benchmark.cpp) + target_link_libraries(benchmark PRIVATE Catch2::Catch2WithMain) + endif() + endif() +else() + add_executable(test_package ../test_package/000-CatchMain.cpp ../test_package/400-with-prefix.cpp) + target_link_libraries(test_package PRIVATE Catch2::Catch2) + + if(WITH_MAIN) + add_executable(standalone ../test_package/400-with-prefix.cpp) + target_link_libraries(standalone PRIVATE Catch2::Catch2WithMain) + endif() +endif() diff --git a/recipes/catch2/2.x.x/test_v1_package/conanfile.py b/recipes/catch2/2.x.x/test_v1_package/conanfile.py new file mode 100644 index 00000000000000..26e54f7cba1f51 --- /dev/null +++ b/recipes/catch2/2.x.x/test_v1_package/conanfile.py @@ -0,0 +1,24 @@ +from conans import ConanFile, CMake, tools +from conans.tools import Version +import os + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake", "cmake_find_package" + + def build(self): + cmake = CMake(self) + cmake.definitions["WITH_MAIN"] = self.options["catch2"].with_main + cmake.definitions["WITH_BENCHMARK"] = self.options["catch2"].with_main and self.options["catch2"].with_benchmark + cmake.definitions["WITH_PREFIX"] = self.options["catch2"].with_prefix + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + self.run(os.path.join("bin", "test_package"), run_environment=True) + if self.options["catch2"].with_main: + self.run(os.path.join("bin", "standalone"), run_environment=True) + if self.options["catch2"].with_benchmark: + self.run(os.path.join("bin", "benchmark"), run_environment=True) diff --git a/recipes/catch2/3.x.x/CMakeLists.txt b/recipes/catch2/3.x.x/CMakeLists.txt deleted file mode 100644 index 8a6f93c2da7ef4..00000000000000 --- a/recipes/catch2/3.x.x/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -cmake_minimum_required(VERSION 3.8) -project(cmake_wrapper) - -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -include(conanbuildinfo.cmake) -conan_basic_setup() - -add_subdirectory(source_subfolder) diff --git a/recipes/catch2/3.x.x/conandata.yml b/recipes/catch2/3.x.x/conandata.yml index c9fa14ce205a3b..9b3616a81d44c3 100644 --- a/recipes/catch2/3.x.x/conandata.yml +++ b/recipes/catch2/3.x.x/conandata.yml @@ -8,7 +8,5 @@ sources: patches: "3.1.0": - patch_file: "patches/3.0.1-0001-force-not_usbproject-off.patch" - base_path: "source_subfolder" "3.0.1": - patch_file: "patches/3.0.1-0001-force-not_usbproject-off.patch" - base_path: "source_subfolder" diff --git a/recipes/catch2/3.x.x/conanfile.py b/recipes/catch2/3.x.x/conanfile.py index 88d4e49f205879..6b39f3af956626 100644 --- a/recipes/catch2/3.x.x/conanfile.py +++ b/recipes/catch2/3.x.x/conanfile.py @@ -1,9 +1,12 @@ import os -import functools -from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.build import check_min_cppstd +from conan.tools.scm import Version +from conan.tools.files import apply_conandata_patches, copy, get, rmdir -required_conan_version = ">=1.43.0" +required_conan_version = ">=1.52.0" class Catch2Conan(ConanFile): name = "catch2" @@ -23,24 +26,14 @@ class Catch2Conan(ConanFile): "with_prefix": False, "default_reporter": None, } - generators = "cmake" - - @property - def _source_subfolder(self): - return "source_subfolder" - - @property - def _build_subfolder(self): - return "build_subfolder" @property def _default_reporter_str(self): return '"{}"'.format(str(self.options.default_reporter).strip('"')) def export_sources(self): - self.copy("CMakeLists.txt") - for patch in self.conan_data.get("patches", {}).get(self.version, []): - self.copy(patch["patch_file"]) + for p in self.conan_data.get("patches", {}).get(self.version, []): + copy(self, p["patch_file"], self.recipe_folder, self.export_sources_folder) def config_options(self): if self.settings.os == "Windows": @@ -55,12 +48,15 @@ def _compilers_minimum_version(self): "apple-clang": "10", } + def layout(self): + cmake_layout(self, src_folder="src") + def validate(self): if self.settings.compiler.get_safe("cppstd"): - tools.check_min_cppstd(self, "14") + check_min_cppstd(self, "14") minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) if minimum_version: - if tools.Version(self.settings.compiler.version) < minimum_version: + if Version(self.settings.compiler.version) < minimum_version: raise ConanInvalidConfiguration("{}/{}: Unsupported compiler: {}-{} " "(https://github.com/p-ranav/structopt#compiler-compatibility)." .format(self.name, self.version, self.settings.compiler, self.settings.compiler.version)) @@ -68,39 +64,36 @@ def validate(self): self.output.warn("{}/{} requires C++14. Your compiler is unknown. Assuming it supports C++14.".format(self.name, self.version)) def source(self): - tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder) - - @functools.lru_cache(1) - def _configure_cmake(self): - cmake = CMake(self) - cmake.definitions["BUILD_TESTING"] = "OFF" - cmake.definitions["CATCH_INSTALL_DOCS"] = "OFF" - cmake.definitions["CATCH_INSTALL_HELPERS"] = "ON" - cmake.definitions["CATCH_CONFIG_PREFIX_ALL"] = self.options.with_prefix + get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["BUILD_TESTING"] = False + tc.variables["CATCH_INSTALL_DOCS"] = False + tc.variables["CATCH_INSTALL_HELPERS"] = True + tc.variables["CATCH_CONFIG_PREFIX_ALL"] = self.options.with_prefix if self.options.default_reporter: - cmake.definitions["CATCH_CONFIG_DEFAULT_REPORTER"] = self._default_reporter_str - cmake.configure(build_folder=self._build_subfolder) - return cmake - - def _patch_sources(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) + tc.variables["CATCH_CONFIG_DEFAULT_REPORTER"] = self._default_reporter_str + tc.generate() def build(self): - self._patch_sources() - cmake = self._configure_cmake() + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure() cmake.build() def package(self): - self.copy(pattern="LICENSE.txt", dst="licenses", src=self._source_subfolder) - cmake = self._configure_cmake() + copy(self, "LICENSE.txt", 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")) - tools.rmdir(os.path.join(self.package_folder, "share")) + + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "share")) for cmake_file in ["ParseAndAddCatchTests.cmake", "Catch.cmake", "CatchAddTests.cmake"]: self.copy( cmake_file, - src=os.path.join(self._source_subfolder, "extras"), + src=os.path.join(self.source_folder, "extras"), dst=os.path.join("lib", "cmake", "Catch2"), ) diff --git a/recipes/catch2/3.x.x/test_package/CMakeLists.txt b/recipes/catch2/3.x.x/test_package/CMakeLists.txt index 93500a54ca7133..5747d03f1f75fa 100644 --- a/recipes/catch2/3.x.x/test_package/CMakeLists.txt +++ b/recipes/catch2/3.x.x/test_package/CMakeLists.txt @@ -1,9 +1,6 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.15) project(test_package) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() - find_package(Catch2 REQUIRED CONFIG) set(CMAKE_CXX_STANDARD 14) diff --git a/recipes/catch2/3.x.x/test_package/conanfile.py b/recipes/catch2/3.x.x/test_package/conanfile.py index 752bdb4cf4490a..26998ae73cc28d 100644 --- a/recipes/catch2/3.x.x/test_package/conanfile.py +++ b/recipes/catch2/3.x.x/test_package/conanfile.py @@ -1,18 +1,31 @@ -from conans import ConanFile, CMake, tools -from conans.tools import Version +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeToolchain +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout import os class TestPackageConan(ConanFile): - settings = "os", "arch", "compiler", "build_type" - generators = "cmake", "cmake_find_package_multi" + settings = "os", "compiler", "build_type", "arch" + generators = "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["WITH_PREFIX"] = self.dependencies[self.tested_reference_str].options.with_prefix + tc.generate() + + def layout(self): + cmake_layout(self) def build(self): cmake = CMake(self) - cmake.definitions["WITH_PREFIX"] = self.options["catch2"].with_prefix cmake.configure() cmake.build() def test(self): - if not tools.cross_building(self): - self.run(os.path.join("bin", "standalone"), run_environment=True) - self.run(os.path.join("bin", "benchmark"), run_environment=True) + if can_run(self): + self.run(os.path.join(self.cpp.build.bindirs[0], "standalone"), env="conanrun") + self.run(os.path.join(self.cpp.build.bindirs[0], "benchmark"), env="conanrun") diff --git a/recipes/catch2/3.x.x/test_v1_package/CMakeLists.txt b/recipes/catch2/3.x.x/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000000..c64530cd7a4a6b --- /dev/null +++ b/recipes/catch2/3.x.x/test_v1_package/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.12) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +find_package(Catch2 REQUIRED CONFIG) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if(NOT WITH_PREFIX) + add_executable(standalone ../test_package/100-standalone.cpp) + target_link_libraries(standalone PRIVATE Catch2::Catch2WithMain) + add_executable(benchmark ../test_package/200-benchmark.cpp) + target_link_libraries(benchmark PRIVATE Catch2::Catch2WithMain) +else() + add_executable(standalone ../test_package/300-standalone-with-prefix.cpp) + target_link_libraries(standalone PRIVATE Catch2::Catch2WithMain) + add_executable(benchmark ../test_package/400-benchmark-with-prefix.cpp) + target_link_libraries(benchmark PRIVATE Catch2::Catch2WithMain) +endif() diff --git a/recipes/catch2/3.x.x/test_v1_package/conanfile.py b/recipes/catch2/3.x.x/test_v1_package/conanfile.py new file mode 100644 index 00000000000000..752bdb4cf4490a --- /dev/null +++ b/recipes/catch2/3.x.x/test_v1_package/conanfile.py @@ -0,0 +1,18 @@ +from conans import ConanFile, CMake, tools +from conans.tools import Version +import os + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.definitions["WITH_PREFIX"] = self.options["catch2"].with_prefix + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + self.run(os.path.join("bin", "standalone"), run_environment=True) + self.run(os.path.join("bin", "benchmark"), run_environment=True)