From e3106d807ce3a5c0d8cdaca2def22dda5a6f024a Mon Sep 17 00:00:00 2001 From: Aleksandr Vodyanov Date: Thu, 21 Nov 2024 17:23:08 +0300 Subject: [PATCH] [DO-987] catch recipe (!3) Co-authored-by: aleksandr.vodyanov Reviewed-on: https://git.avroid.tech/Conan/conan_build/pulls/3 Reviewed-by: Denis Patrakeev Co-authored-by: Aleksandr Vodyanov Co-committed-by: Aleksandr Vodyanov --- recipes/catch2/2.x.x/conandata.yml | 19 ++ recipes/catch2/2.x.x/conanfile.py | 133 ++++++++++++ .../2.x.x/test_package/000-CatchMain.cpp | 3 + .../2.x.x/test_package/100-standalone.cpp | 5 + .../2.x.x/test_package/200-benchmark.cpp | 11 + .../300-standalone-with-prefix.cpp | 5 + .../400-benchmark-with-prefix.cpp | 11 + .../catch2/2.x.x/test_package/CMakeLists.txt | 31 +++ .../catch2/2.x.x/test_package/conanfile.py | 33 +++ .../2.x.x/test_v1_package/CMakeLists.txt | 10 + .../catch2/2.x.x/test_v1_package/conanfile.py | 18 ++ recipes/catch2/3.x.x/conandata.yml | 68 ++++++ recipes/catch2/3.x.x/conanfile.py | 194 ++++++++++++++++++ .../patches/3.0.1-0001-allow-shared.patch | 64 ++++++ ...1-0002-dllimport-global-symbols-msvc.patch | 77 +++++++ .../patches/3.1.0-0001-fix-dll-install.patch | 16 ++ ...0-0002-dllimport-global-symbols-msvc.patch | 77 +++++++ .../3.x.x/test_package/100-standalone.cpp | 5 + .../3.x.x/test_package/200-benchmark.cpp | 12 ++ .../300-standalone-with-prefix.cpp | 5 + .../400-benchmark-with-prefix.cpp | 12 ++ .../catch2/3.x.x/test_package/CMakeLists.txt | 16 ++ .../catch2/3.x.x/test_package/conanfile.py | 31 +++ .../3.x.x/test_v1_package/CMakeLists.txt | 8 + .../catch2/3.x.x/test_v1_package/conanfile.py | 18 ++ recipes/catch2/all | 1 + recipes/catch2/config.yml | 45 ++++ 27 files changed, 928 insertions(+) create mode 100644 recipes/catch2/2.x.x/conandata.yml create mode 100644 recipes/catch2/2.x.x/conanfile.py create mode 100644 recipes/catch2/2.x.x/test_package/000-CatchMain.cpp create mode 100644 recipes/catch2/2.x.x/test_package/100-standalone.cpp create mode 100644 recipes/catch2/2.x.x/test_package/200-benchmark.cpp create mode 100644 recipes/catch2/2.x.x/test_package/300-standalone-with-prefix.cpp create mode 100644 recipes/catch2/2.x.x/test_package/400-benchmark-with-prefix.cpp create mode 100644 recipes/catch2/2.x.x/test_package/CMakeLists.txt create mode 100644 recipes/catch2/2.x.x/test_package/conanfile.py 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 create mode 100644 recipes/catch2/3.x.x/conandata.yml create mode 100644 recipes/catch2/3.x.x/conanfile.py create mode 100644 recipes/catch2/3.x.x/patches/3.0.1-0001-allow-shared.patch create mode 100644 recipes/catch2/3.x.x/patches/3.0.1-0002-dllimport-global-symbols-msvc.patch create mode 100644 recipes/catch2/3.x.x/patches/3.1.0-0001-fix-dll-install.patch create mode 100644 recipes/catch2/3.x.x/patches/3.1.0-0002-dllimport-global-symbols-msvc.patch create mode 100644 recipes/catch2/3.x.x/test_package/100-standalone.cpp create mode 100644 recipes/catch2/3.x.x/test_package/200-benchmark.cpp create mode 100644 recipes/catch2/3.x.x/test_package/300-standalone-with-prefix.cpp create mode 100644 recipes/catch2/3.x.x/test_package/400-benchmark-with-prefix.cpp create mode 100644 recipes/catch2/3.x.x/test_package/CMakeLists.txt create mode 100644 recipes/catch2/3.x.x/test_package/conanfile.py 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 create mode 120000 recipes/catch2/all create mode 100644 recipes/catch2/config.yml diff --git a/recipes/catch2/2.x.x/conandata.yml b/recipes/catch2/2.x.x/conandata.yml new file mode 100644 index 0000000..9e23bc0 --- /dev/null +++ b/recipes/catch2/2.x.x/conandata.yml @@ -0,0 +1,19 @@ +sources: + "2.13.10": + url: "https://github.com/catchorg/Catch2/archive/v2.13.10.tar.gz" + sha256: "d54a712b7b1d7708bc7a819a8e6e47b2fde9536f487b89ccbca295072a7d9943" + "2.13.9": + url: "https://github.com/catchorg/Catch2/archive/v2.13.9.tar.gz" + sha256: "06dbc7620e3b96c2b69d57bf337028bf245a211b3cddb843835bfe258f427a52" + "2.13.8": + url: "https://github.com/catchorg/Catch2/archive/v2.13.8.tar.gz" + sha256: "b9b592bd743c09f13ee4bf35fc30eeee2748963184f6bea836b146e6cc2a585a" + "2.13.7": + url: "https://github.com/catchorg/Catch2/archive/v2.13.7.tar.gz" + sha256: "3cdb4138a072e4c0290034fe22d9f0a80d3bcfb8d7a8a5c49ad75d3a5da24fae" + "2.12.4": + url: "https://github.com/catchorg/Catch2/archive/v2.12.4.tar.gz" + sha256: "5436725bbc6ee131a0bc9545bef31f0adabbb21fbc39fb6f1b2a42c12e4f8107" + "2.11.3": + url: "https://github.com/catchorg/Catch2/archive/v2.11.3.tar.gz" + sha256: "9a6967138062688f04374698fce4ce65908f907d8c0fe5dfe8dc33126bd46543" diff --git a/recipes/catch2/2.x.x/conanfile.py b/recipes/catch2/2.x.x/conanfile.py new file mode 100644 index 0000000..15b0185 --- /dev/null +++ b/recipes/catch2/2.x.x/conanfile.py @@ -0,0 +1,133 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import copy, get, rmdir +from conan.tools.scm import Version +import os + +required_conan_version = ">=1.53.0" + + +class Catch2Conan(ConanFile): + name = "catch2" + description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD" + topics = ("header-only", "unit-test", "tdd", "bdd") + homepage = "https://github.com/catchorg/Catch2" + url = "https://github.com/conan-io/conan-center-index" + license = "BSL-1.0" + + settings = "os", "arch", "compiler", "build_type" + options = { + "fPIC": [True, False], + "with_main": [True, False], + "with_benchmark": [True, False], + "with_prefix": [True, False], + "default_reporter": [None, "ANY"], + } + default_options = { + "fPIC": True, + "with_main": False, + "with_benchmark": False, + "with_prefix": False, + "default_reporter": None, + } + + @property + def _default_reporter_str(self): + return str(self.options.default_reporter).strip('"') + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if not self.options.with_main: + self.options.rm_safe("fPIC") + self.options.rm_safe("with_benchmark") + + def layout(self): + cmake_layout(self, src_folder="src") + + def package_id(self): + if not self.info.options.with_main: + self.info.clear() + + def validate(self): + if Version(self.version) < "2.13.1" and self.settings.arch == "armv8": + raise ConanInvalidConfiguration("ARMv8 is not supported by versions < 2.13.1+") + if self.options.get_safe("with_main") and Version(self.version) < "2.13.4": + raise ConanInvalidConfiguration("Option with_main not supported by versions < 2.13.4") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["BUILD_TESTING"] = False + tc.cache_variables["CATCH_INSTALL_DOCS"] = False # these are cmake options, so use cache_variables + tc.cache_variables["CATCH_INSTALL_HELPERS"] = "ON" # these are cmake options, so use cache_variables + tc.cache_variables["CATCH_BUILD_STATIC_LIBRARY"] = str(self.options.with_main) # these are cmake options, so use cache_variables (str() is required for conan 1.52) + if self.options.with_prefix: + tc.preprocessor_definitions["CATCH_CONFIG_PREFIX_ALL"] = 1 + if self.options.get_safe("with_benchmark", False): + tc.preprocessor_definitions["CATCH_CONFIG_ENABLE_BENCHMARKING"] = 1 + if self.options.default_reporter: + tc.variables["CATCH_CONFIG_DEFAULT_REPORTER"] = self._default_reporter_str + tc.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + if self.options.with_main: + cmake.build() + + def package(self): + copy(self, pattern="LICENSE.txt", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + cmake = CMake(self) + cmake.install() + 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"]: + copy(self, + cmake_file, + src=os.path.join(self.source_folder, "contrib"), + dst=os.path.join(self.package_folder, "lib", "cmake", "Catch2"), + ) + + def package_info(self): + self.cpp_info.set_property("cmake_file_name", "Catch2") + self.cpp_info.set_property("cmake_target_name", "Catch2::Catch2{}".format("WithMain" if self.options.with_main else "")) + self.cpp_info.set_property("pkg_config_name", "catch2{}".format("-with-main" if self.options.with_main else "")) + + defines = [] + if self.options.get_safe("with_benchmark", False): + defines.append("CATCH_CONFIG_ENABLE_BENCHMARKING") + if self.options.with_prefix: + defines.append("CATCH_CONFIG_PREFIX_ALL") + if self.options.default_reporter: + defines.append(f"CATCH_CONFIG_DEFAULT_REPORTER={self._default_reporter_str}") + + if self.options.with_main: + self.cpp_info.components["_catch2"].set_property("cmake_target_name", "Catch2::Catch2") + self.cpp_info.components["_catch2"].set_property("pkg_config_name", "catch2") + self.cpp_info.components["_catch2"].defines = defines + + self.cpp_info.components["catch2_with_main"].builddirs.append(os.path.join("lib", "cmake", "Catch2")) + self.cpp_info.components["catch2_with_main"].libs = ["Catch2WithMain"] + self.cpp_info.components["catch2_with_main"].system_libs = ["log"] if self.settings.os == "Android" else [] + self.cpp_info.components["catch2_with_main"].set_property("cmake_target_name", "Catch2::Catch2WithMain") + self.cpp_info.components["catch2_with_main"].set_property("pkg_config_name", "catch2-with-main") + self.cpp_info.components["catch2_with_main"].defines = defines + else: + self.cpp_info.builddirs = [os.path.join("lib", "cmake", "Catch2")] + self.cpp_info.system_libs = ["log"] if self.settings.os == "Android" else [] + self.cpp_info.defines = defines + + # TODO: to remove in conan v2 once legacy generators removed + self.cpp_info.names["cmake_find_package"] = "Catch2" + self.cpp_info.names["cmake_find_package_multi"] = "Catch2" + if self.options.with_main: + self.cpp_info.components["_catch2"].names["cmake_find_package"] = "Catch2" + self.cpp_info.components["_catch2"].names["cmake_find_package_multi"] = "Catch2" + self.cpp_info.components["catch2_with_main"].names["cmake_find_package"] = "Catch2WithMain" + self.cpp_info.components["catch2_with_main"].names["cmake_find_package_multi"] = "Catch2WithMain" diff --git a/recipes/catch2/2.x.x/test_package/000-CatchMain.cpp b/recipes/catch2/2.x.x/test_package/000-CatchMain.cpp new file mode 100644 index 0000000..f481b16 --- /dev/null +++ b/recipes/catch2/2.x.x/test_package/000-CatchMain.cpp @@ -0,0 +1,3 @@ +#define CATCH_CONFIG_MAIN + +#include diff --git a/recipes/catch2/2.x.x/test_package/100-standalone.cpp b/recipes/catch2/2.x.x/test_package/100-standalone.cpp new file mode 100644 index 0000000..d330a97 --- /dev/null +++ b/recipes/catch2/2.x.x/test_package/100-standalone.cpp @@ -0,0 +1,5 @@ +#include + +TEST_CASE( "compiles and runs" ) { + REQUIRE( true == !false ); +} diff --git a/recipes/catch2/2.x.x/test_package/200-benchmark.cpp b/recipes/catch2/2.x.x/test_package/200-benchmark.cpp new file mode 100644 index 0000000..147c743 --- /dev/null +++ b/recipes/catch2/2.x.x/test_package/200-benchmark.cpp @@ -0,0 +1,11 @@ +#include + +unsigned int Factorial( unsigned int number ) { + return number > 1 ? Factorial(number-1)*number : 1; +} + +TEST_CASE( "compiles and runs" ) { + BENCHMARK("factorial 25"){ + return Factorial(25); + }; +} diff --git a/recipes/catch2/2.x.x/test_package/300-standalone-with-prefix.cpp b/recipes/catch2/2.x.x/test_package/300-standalone-with-prefix.cpp new file mode 100644 index 0000000..6340e09 --- /dev/null +++ b/recipes/catch2/2.x.x/test_package/300-standalone-with-prefix.cpp @@ -0,0 +1,5 @@ +#include + +CATCH_TEST_CASE( "compiles and runs" ) { + CATCH_REQUIRE( true == !false ); +} diff --git a/recipes/catch2/2.x.x/test_package/400-benchmark-with-prefix.cpp b/recipes/catch2/2.x.x/test_package/400-benchmark-with-prefix.cpp new file mode 100644 index 0000000..147c743 --- /dev/null +++ b/recipes/catch2/2.x.x/test_package/400-benchmark-with-prefix.cpp @@ -0,0 +1,11 @@ +#include + +unsigned int Factorial( unsigned int number ) { + return number > 1 ? Factorial(number-1)*number : 1; +} + +TEST_CASE( "compiles and runs" ) { + BENCHMARK("factorial 25"){ + return Factorial(25); + }; +} diff --git a/recipes/catch2/2.x.x/test_package/CMakeLists.txt b/recipes/catch2/2.x.x/test_package/CMakeLists.txt new file mode 100644 index 0000000..7cf7254 --- /dev/null +++ b/recipes/catch2/2.x.x/test_package/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES CXX) + +enable_testing() + +find_package(Catch2 REQUIRED CONFIG) + +if(WITH_PREFIX) + set(SRC_STANDALONE 300-standalone-with-prefix.cpp) + set(SRC_BENCHMARK 400-benchmark-with-prefix.cpp) +else() + set(SRC_STANDALONE 100-standalone.cpp) + set(SRC_BENCHMARK 200-benchmark.cpp) +endif() + +add_executable(standalone 000-CatchMain.cpp ${SRC_STANDALONE}) +target_link_libraries(standalone PRIVATE Catch2::Catch2) +target_compile_features(standalone PRIVATE cxx_std_11) +add_test(NAME standalone COMMAND standalone) +if(WITH_MAIN) + add_executable(standalone_with_main ${SRC_STANDALONE}) + target_link_libraries(standalone_with_main PRIVATE Catch2::Catch2WithMain) + target_compile_features(standalone_with_main PRIVATE cxx_std_11) + add_test(NAME standalone_with_main COMMAND standalone_with_main) +endif() +if(WITH_BENCHMARK) + add_executable(benchmark ${SRC_BENCHMARK}) + target_link_libraries(benchmark PRIVATE Catch2::Catch2WithMain) + target_compile_features(benchmark PRIVATE cxx_std_11) + add_test(NAME benchmark COMMAND benchmark) +endif() diff --git a/recipes/catch2/2.x.x/test_package/conanfile.py b/recipes/catch2/2.x.x/test_package/conanfile.py new file mode 100644 index 0000000..cab6586 --- /dev/null +++ b/recipes/catch2/2.x.x/test_package/conanfile.py @@ -0,0 +1,33 @@ +from conan import ConanFile +from conan.tools.build import build_jobs, can_run +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import chdir + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["WITH_MAIN"] = self.dependencies["catch2"].options.with_main + tc.variables["WITH_BENCHMARK"] = self.dependencies["catch2"].options.get_safe("with_benchmark", False) + tc.variables["WITH_PREFIX"] = self.dependencies["catch2"].options.with_prefix + tc.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + with chdir(self, self.build_folder): + self.run(f"ctest --output-on-failure -C {self.settings.build_type} -j {build_jobs(self)}", env="conanrun") 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 0000000..c23ed5c --- /dev/null +++ b/recipes/catch2/2.x.x/test_v1_package/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.1) +project(test_v1_package) + +enable_testing() + +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/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 0000000..2ee4780 --- /dev/null +++ b/recipes/catch2/2.x.x/test_v1_package/conanfile.py @@ -0,0 +1,18 @@ +from conans import ConanFile, CMake, tools + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package_multi" + + 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(f"ctest --output-on-failure -C {self.settings.build_type} -j {tools.cpu_count()}", run_environment=True) diff --git a/recipes/catch2/3.x.x/conandata.yml b/recipes/catch2/3.x.x/conandata.yml new file mode 100644 index 0000000..fd7c1c8 --- /dev/null +++ b/recipes/catch2/3.x.x/conandata.yml @@ -0,0 +1,68 @@ +sources: + "3.7.1": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.7.1" + "3.7.0": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.7.0" + "3.6.0": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.6.0" + "3.5.4": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.5.4" + "3.5.3": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.5.3" + "3.5.2": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.5.2" + "3.5.1": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.5.1" + "3.5.0": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.5.0" + "3.4.0": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.4.0" + "3.3.2": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.3.2" + "3.3.1": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.3.1" + "3.3.0": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.3.0" + "3.2.1": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.2.1" + "3.2.0": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.2.0" + "3.1.0": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.1.0" + "3.0.1": + url: "ssh://git@git.avroid.tech:2222/Mirrors/Catch2" + branch: "v3.0.1" +patches: + "3.1.0": + - patch_file: "patches/3.1.0-0001-fix-dll-install.patch" + patch_description: "Install dll in bin folder" + patch_type: "portability" + patch_source: "https://github.com/catchorg/Catch2/pull/2485" + - patch_file: "patches/3.1.0-0002-dllimport-global-symbols-msvc.patch" + patch_description: "Fix import of global symbols for msvc shared" + patch_type: "portability" + patch_source: "https://github.com/catchorg/Catch2/pull/2527" + "3.0.1": + - patch_file: "patches/3.0.1-0001-allow-shared.patch" + patch_description: "Allow to build catch2 as a shared library" + patch_type: "portability" + patch_source: "https://github.com/catchorg/Catch2/commit/bea58bf8bbfca887f871c3aa2d720ba62c01f855" + - patch_file: "patches/3.0.1-0002-dllimport-global-symbols-msvc.patch" + patch_description: "Fix import of global symbols for msvc shared" + patch_type: "portability" + patch_source: "https://github.com/catchorg/Catch2/pull/2527" diff --git a/recipes/catch2/3.x.x/conanfile.py b/recipes/catch2/3.x.x/conanfile.py new file mode 100644 index 0000000..7479963 --- /dev/null +++ b/recipes/catch2/3.x.x/conanfile.py @@ -0,0 +1,194 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir, save +from conan.tools.scm import Version, Git +import os +import textwrap + +required_conan_version = ">=1.54.0" + + +class Catch2Conan(ConanFile): + name = "catch2" + description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD" + license = "BSL-1.0" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/catchorg/Catch2" + topics = ("catch2", "unit-test", "tdd", "bdd") + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + "with_prefix": [True, False], + "default_reporter": [None, "ANY"], + "console_width": [None, "ANY"], + "no_posix_signals": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + "with_prefix": False, + "default_reporter": None, + "console_width": "80", + "no_posix_signals": False, + } + # disallow cppstd compatibility, as it affects the ABI in this library + # see https://github.com/conan-io/conan-center-index/issues/19008 + extension_properties = {"compatibility_cppstd": False} + + @property + def _min_cppstd(self): + return "14" + + @property + def _min_console_width(self): + # Catch2 doesn't build if less than this value + return 46 + + @property + def _compilers_minimum_version(self): + return { + "gcc": "7", + "Visual Studio": "15", + "msvc": "191", + "clang": "5", + "apple-clang": "10", + } + + @property + def _default_reporter_str(self): + return str(self.options.default_reporter).strip('"') + + def export_sources(self): + export_conandata_patches(self) + + 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, src_folder="src") + + def validate(self): + if self.settings.compiler.get_safe("cppstd"): + check_min_cppstd(self, self._min_cppstd) + 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", + ) + + try: + if int(self.options.console_width) < self._min_console_width: + raise ConanInvalidConfiguration( + f"option 'console_width' must be >= {self._min_console_width}, " + f"got {self.options.console_width}. Contributions welcome if this should work!") + except ValueError as e: + raise ConanInvalidConfiguration(f"option 'console_width' must be an integer, " + f"got '{self.options.console_width}'") from e + + def source(self): + #get(self, **self.conan_data["sources"][self.version], strip_root=True) + git = Git(self) + sources = self.conan_data["sources"][self.version] + clone_args = ['--depth', '1', '--branch', sources["branch"]] + git.clone(url=sources["url"], target=self.source_folder, args=clone_args) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["BUILD_TESTING"] = False + tc.cache_variables["CATCH_INSTALL_DOCS"] = False + tc.cache_variables["CATCH_INSTALL_EXTRAS"] = True + tc.cache_variables["CATCH_DEVELOPMENT_BUILD"] = False + tc.variables["CATCH_CONFIG_PREFIX_ALL"] = self.options.with_prefix + tc.variables["CATCH_CONFIG_CONSOLE_WIDTH"] = self.options.console_width + if self.options.default_reporter: + tc.variables["CATCH_CONFIG_DEFAULT_REPORTER"] = self._default_reporter_str + tc.variables["CATCH_CONFIG_NO_POSIX_SIGNALS"] = self.options.no_posix_signals + tc.generate() + + def build(self): + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + copy(self, "LICENSE.txt", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) + cmake.install() + 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"]: + copy( + self, + cmake_file, + src=os.path.join(self.source_folder, "extras"), + dst=os.path.join(self.package_folder, "lib", "cmake", "Catch2"), + ) + + # TODO: to remove in conan v2 once legacy generators removed + self._create_cmake_module_alias_targets( + os.path.join(self.package_folder, self._module_file_rel_path), + { + "Catch2::Catch2": "catch2::_catch2", + "Catch2::Catch2WithMain": "catch2::catch2_with_main", + } + ) + + def _create_cmake_module_alias_targets(self, module_file, targets): + content = "" + for alias, aliased in targets.items(): + content += textwrap.dedent(f"""\ + if(TARGET {aliased} AND NOT TARGET {alias}) + add_library({alias} INTERFACE IMPORTED) + set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased}) + endif() + """) + save(self, module_file, content) + + @property + def _module_file_rel_path(self): + return os.path.join("lib", "cmake", f"conan-official-{self.name}-targets.cmake") + + def package_info(self): + self.cpp_info.set_property("cmake_file_name", "Catch2") + self.cpp_info.set_property("cmake_target_name", "Catch2::Catch2WithMain") + self.cpp_info.set_property("pkg_config_name", "catch2-with-main") + + lib_suffix = "d" if self.settings.build_type == "Debug" else "" + self.cpp_info.components["_catch2"].set_property("cmake_target_name", "Catch2::Catch2") + self.cpp_info.components["_catch2"].set_property("pkg_config_name", "catch2") + self.cpp_info.components["_catch2"].libs = ["Catch2" + lib_suffix] + + self.cpp_info.components["catch2_with_main"].builddirs.append(os.path.join("lib", "cmake", "Catch2")) + self.cpp_info.components["catch2_with_main"].libs = ["Catch2Main" + lib_suffix] + self.cpp_info.components["catch2_with_main"].requires = ["_catch2"] + self.cpp_info.components["catch2_with_main"].system_libs = ["log"] if self.settings.os == "Android" else [] + self.cpp_info.components["catch2_with_main"].set_property("cmake_target_name", "Catch2::Catch2WithMain") + self.cpp_info.components["catch2_with_main"].set_property("pkg_config_name", "catch2-with-main") + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.components["catch2_with_main"].system_libs.append("m") + defines = [] + if self.options.with_prefix: + defines.append("CATCH_CONFIG_PREFIX_ALL") + if self.options.default_reporter: + defines.append(f"CATCH_CONFIG_DEFAULT_REPORTER={self._default_reporter_str}") + self.cpp_info.components["catch2_with_main"].defines = defines + + # TODO: to remove in conan v2 once legacy generators removed + self.cpp_info.filenames["cmake_find_package"] = "Catch2" + self.cpp_info.filenames["cmake_find_package_multi"] = "Catch2" + self.cpp_info.names["cmake_find_package"] = "catch2" + self.cpp_info.names["cmake_find_package_multi"] = "catch2" + self.cpp_info.components["_catch2"].build_modules["cmake_find_package"] = [self._module_file_rel_path] + self.cpp_info.components["_catch2"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path] + self.cpp_info.components["catch2_with_main"].build_modules["cmake_find_package"] = [self._module_file_rel_path] + self.cpp_info.components["catch2_with_main"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path] diff --git a/recipes/catch2/3.x.x/patches/3.0.1-0001-allow-shared.patch b/recipes/catch2/3.x.x/patches/3.0.1-0001-allow-shared.patch new file mode 100644 index 0000000..38c31d2 --- /dev/null +++ b/recipes/catch2/3.x.x/patches/3.0.1-0001-allow-shared.patch @@ -0,0 +1,64 @@ +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -263,9 +263,7 @@ set(REPORTER_SOURCES + ) + set(REPORTER_FILES ${REPORTER_HEADERS} ${REPORTER_SOURCES}) + +-# Fixme: STATIC because for dynamic, we would need to handle visibility +-# and I don't want to do the annotations right now +-add_library(Catch2 STATIC ++add_library(Catch2 + ${REPORTER_FILES} + ${INTERNAL_FILES} + ${BENCHMARK_HEADERS} +@@ -318,7 +316,7 @@ target_include_directories(Catch2 + ) + + +-add_library(Catch2WithMain STATIC ++add_library(Catch2WithMain + ${SOURCES_DIR}/internal/catch_main.cpp + ) + add_build_reproducibility_settings(Catch2WithMain) +@@ -338,8 +336,12 @@ if (NOT_SUBPROJECT) + Catch2WithMain + EXPORT + Catch2Targets +- DESTINATION ++ LIBRARY DESTINATION ++ ${CMAKE_INSTALL_LIBDIR} ++ ARCHIVE DESTINATION + ${CMAKE_INSTALL_LIBDIR} ++ RUNTIME DESTINATION ++ ${CMAKE_INSTALL_BINDIR} + ) + + +@@ -409,3 +411,27 @@ endif() + + list(APPEND CATCH_WARNING_TARGETS Catch2 Catch2WithMain) + set(CATCH_WARNING_TARGETS ${CATCH_WARNING_TARGETS} PARENT_SCOPE) ++ ++ ++# We still do not support building dynamic library with hidden visibility ++# so we want to check & warn users if they do this. However, we won't abort ++# the configuration step so that we don't have to also provide an override. ++if (BUILD_SHARED_LIBS) ++ if (MSVC) ++ set_target_properties(Catch2 Catch2WithMain ++ PROPERTIES ++ WINDOWS_EXPORT_ALL_SYMBOLS ON ++ ) ++ endif() ++ ++ get_target_property(_VisPreset Catch2 CXX_VISIBILITY_PRESET) ++ if (NOT MSVC AND _VisPreset STREQUAL "hidden") ++ set_target_properties(Catch2 Catch2WithMain ++ PROPERTIES ++ CXX_VISIBILITY_PRESET "default" ++ VISIBILITY_INLINES_HIDDEN OFF ++ ) ++ message(WARNING "Setting Catch2's visibility to default." ++ " Hidden visibility is not supported.") ++ endif() ++endif() diff --git a/recipes/catch2/3.x.x/patches/3.0.1-0002-dllimport-global-symbols-msvc.patch b/recipes/catch2/3.x.x/patches/3.0.1-0002-dllimport-global-symbols-msvc.patch new file mode 100644 index 0000000..c797f9d --- /dev/null +++ b/recipes/catch2/3.x.x/patches/3.0.1-0002-dllimport-global-symbols-msvc.patch @@ -0,0 +1,77 @@ +--- a/CMake/CatchConfigOptions.cmake ++++ b/CMake/CatchConfigOptions.cmake +@@ -45,6 +45,7 @@ set(_OverridableOptions + foreach(OptionName ${_OverridableOptions}) + AddOverridableConfigOption(${OptionName}) + endforeach() ++set(CATCH_CONFIG_SHARED_LIBRARY ${BUILD_SHARED_LIBS}) + + set(_OtherConfigOptions + "DISABLE_EXCEPTIONS" +--- a/src/catch2/catch_tostring.hpp ++++ b/src/catch2/catch_tostring.hpp +@@ -296,13 +296,13 @@ namespace Catch { + template<> + struct StringMaker { + static std::string convert(float value); +- static int precision; ++ CATCH_EXPORT static int precision; + }; + + template<> + struct StringMaker { + static std::string convert(double value); +- static int precision; ++ CATCH_EXPORT static int precision; + }; + + template +--- a/src/catch2/catch_user_config.hpp.in ++++ b/src/catch2/catch_user_config.hpp.in +@@ -181,6 +181,8 @@ + #cmakedefine CATCH_CONFIG_PREFIX_ALL + #cmakedefine CATCH_CONFIG_WINDOWS_CRTDBG + ++#cmakedefine CATCH_CONFIG_SHARED_LIBRARY ++ + + // ------ + // "Variable" defines, these have actual values +--- a/src/catch2/internal/catch_compiler_capabilities.hpp ++++ b/src/catch2/internal/catch_compiler_capabilities.hpp +@@ -364,5 +364,15 @@ + # define CATCH_CONFIG_COLOUR_WIN32 + #endif + ++#if defined( CATCH_CONFIG_SHARED_LIBRARY ) && defined( _MSC_VER ) && \ ++ !defined( CATCH_CONFIG_STATIC ) ++# ifdef Catch2_EXPORTS ++# define CATCH_EXPORT //__declspec( dllexport ) // not needed ++# else ++# define CATCH_EXPORT __declspec( dllimport ) ++# endif ++#else ++# define CATCH_EXPORT ++#endif + + #endif // CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED +--- a/src/catch2/internal/catch_context.hpp ++++ b/src/catch2/internal/catch_context.hpp +@@ -8,6 +8,8 @@ + #ifndef CATCH_CONTEXT_HPP_INCLUDED + #define CATCH_CONTEXT_HPP_INCLUDED + ++#include ++ + namespace Catch { + + class IResultCapture; +@@ -28,7 +30,7 @@ namespace Catch { + virtual void setConfig( IConfig const* config ) = 0; + + private: +- static IMutableContext *currentContext; ++ CATCH_EXPORT static IMutableContext *currentContext; + friend IMutableContext& getCurrentMutableContext(); + friend void cleanUpContext(); + static void createContext(); diff --git a/recipes/catch2/3.x.x/patches/3.1.0-0001-fix-dll-install.patch b/recipes/catch2/3.x.x/patches/3.1.0-0001-fix-dll-install.patch new file mode 100644 index 0000000..c702794 --- /dev/null +++ b/recipes/catch2/3.x.x/patches/3.1.0-0001-fix-dll-install.patch @@ -0,0 +1,16 @@ +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -359,8 +359,12 @@ if (NOT_SUBPROJECT) + Catch2WithMain + EXPORT + Catch2Targets +- DESTINATION ++ LIBRARY DESTINATION ++ ${CMAKE_INSTALL_LIBDIR} ++ ARCHIVE DESTINATION + ${CMAKE_INSTALL_LIBDIR} ++ RUNTIME DESTINATION ++ ${CMAKE_INSTALL_BINDIR} + ) + + diff --git a/recipes/catch2/3.x.x/patches/3.1.0-0002-dllimport-global-symbols-msvc.patch b/recipes/catch2/3.x.x/patches/3.1.0-0002-dllimport-global-symbols-msvc.patch new file mode 100644 index 0000000..63e221c --- /dev/null +++ b/recipes/catch2/3.x.x/patches/3.1.0-0002-dllimport-global-symbols-msvc.patch @@ -0,0 +1,77 @@ +--- a/CMake/CatchConfigOptions.cmake ++++ b/CMake/CatchConfigOptions.cmake +@@ -45,6 +45,7 @@ set(_OverridableOptions + foreach(OptionName ${_OverridableOptions}) + AddOverridableConfigOption(${OptionName}) + endforeach() ++set(CATCH_CONFIG_SHARED_LIBRARY ${BUILD_SHARED_LIBS}) + + set(_OtherConfigOptions + "DISABLE_EXCEPTIONS" +--- a/src/catch2/catch_tostring.hpp ++++ b/src/catch2/catch_tostring.hpp +@@ -296,13 +296,13 @@ namespace Catch { + template<> + struct StringMaker { + static std::string convert(float value); +- static int precision; ++ CATCH_EXPORT static int precision; + }; + + template<> + struct StringMaker { + static std::string convert(double value); +- static int precision; ++ CATCH_EXPORT static int precision; + }; + + template +--- a/src/catch2/catch_user_config.hpp.in ++++ b/src/catch2/catch_user_config.hpp.in +@@ -181,6 +181,8 @@ + #cmakedefine CATCH_CONFIG_PREFIX_ALL + #cmakedefine CATCH_CONFIG_WINDOWS_CRTDBG + ++#cmakedefine CATCH_CONFIG_SHARED_LIBRARY ++ + + // ------ + // "Variable" defines, these have actual values +--- a/src/catch2/internal/catch_compiler_capabilities.hpp ++++ b/src/catch2/internal/catch_compiler_capabilities.hpp +@@ -376,5 +376,15 @@ + # define CATCH_CONFIG_COLOUR_WIN32 + #endif + ++#if defined( CATCH_CONFIG_SHARED_LIBRARY ) && defined( _MSC_VER ) && \ ++ !defined( CATCH_CONFIG_STATIC ) ++# ifdef Catch2_EXPORTS ++# define CATCH_EXPORT //__declspec( dllexport ) // not needed ++# else ++# define CATCH_EXPORT __declspec( dllimport ) ++# endif ++#else ++# define CATCH_EXPORT ++#endif + + #endif // CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED +--- a/src/catch2/internal/catch_context.hpp ++++ b/src/catch2/internal/catch_context.hpp +@@ -8,6 +8,8 @@ + #ifndef CATCH_CONTEXT_HPP_INCLUDED + #define CATCH_CONTEXT_HPP_INCLUDED + ++#include ++ + namespace Catch { + + class IResultCapture; +@@ -28,7 +30,7 @@ namespace Catch { + virtual void setConfig( IConfig const* config ) = 0; + + private: +- static IMutableContext *currentContext; ++ CATCH_EXPORT static IMutableContext *currentContext; + friend IMutableContext& getCurrentMutableContext(); + friend void cleanUpContext(); + static void createContext(); diff --git a/recipes/catch2/3.x.x/test_package/100-standalone.cpp b/recipes/catch2/3.x.x/test_package/100-standalone.cpp new file mode 100644 index 0000000..4930209 --- /dev/null +++ b/recipes/catch2/3.x.x/test_package/100-standalone.cpp @@ -0,0 +1,5 @@ +#include + +TEST_CASE( "compiles and runs" ) { + REQUIRE( true == !false ); +} diff --git a/recipes/catch2/3.x.x/test_package/200-benchmark.cpp b/recipes/catch2/3.x.x/test_package/200-benchmark.cpp new file mode 100644 index 0000000..a109712 --- /dev/null +++ b/recipes/catch2/3.x.x/test_package/200-benchmark.cpp @@ -0,0 +1,12 @@ +#include +#include + +unsigned int Factorial( unsigned int number ) { + return number > 1 ? Factorial(number-1)*number : 1; +} + +TEST_CASE( "compiles and runs" ) { + BENCHMARK("factorial 25"){ + return Factorial(25); + }; +} diff --git a/recipes/catch2/3.x.x/test_package/300-standalone-with-prefix.cpp b/recipes/catch2/3.x.x/test_package/300-standalone-with-prefix.cpp new file mode 100644 index 0000000..1f26b18 --- /dev/null +++ b/recipes/catch2/3.x.x/test_package/300-standalone-with-prefix.cpp @@ -0,0 +1,5 @@ +#include + +CATCH_TEST_CASE( "compiles and runs" ) { + CATCH_REQUIRE( true == !false ); +} diff --git a/recipes/catch2/3.x.x/test_package/400-benchmark-with-prefix.cpp b/recipes/catch2/3.x.x/test_package/400-benchmark-with-prefix.cpp new file mode 100644 index 0000000..a496560 --- /dev/null +++ b/recipes/catch2/3.x.x/test_package/400-benchmark-with-prefix.cpp @@ -0,0 +1,12 @@ +#include +#include + +unsigned int Factorial( unsigned int number ) { + return number > 1 ? Factorial(number-1)*number : 1; +} + +CATCH_TEST_CASE( "compiles and runs" ) { + CATCH_BENCHMARK("factorial 25"){ + return Factorial(25); + }; +} diff --git a/recipes/catch2/3.x.x/test_package/CMakeLists.txt b/recipes/catch2/3.x.x/test_package/CMakeLists.txt new file mode 100644 index 0000000..1e2b066 --- /dev/null +++ b/recipes/catch2/3.x.x/test_package/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES CXX) + +find_package(Catch2 REQUIRED CONFIG) + +if(WITH_PREFIX) + add_executable(standalone 300-standalone-with-prefix.cpp) + add_executable(benchmark 400-benchmark-with-prefix.cpp) +else() + add_executable(standalone 100-standalone.cpp) + add_executable(benchmark 200-benchmark.cpp) +endif() +target_link_libraries(standalone PRIVATE Catch2::Catch2WithMain) +target_compile_features(standalone PRIVATE cxx_std_14) +target_link_libraries(benchmark PRIVATE Catch2::Catch2WithMain) +target_compile_features(benchmark PRIVATE cxx_std_14) diff --git a/recipes/catch2/3.x.x/test_package/conanfile.py b/recipes/catch2/3.x.x/test_package/conanfile.py new file mode 100644 index 0000000..259cc35 --- /dev/null +++ b/recipes/catch2/3.x.x/test_package/conanfile.py @@ -0,0 +1,31 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + 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 build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + 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 0000000..0d20897 --- /dev/null +++ b/recipes/catch2/3.x.x/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.1) +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/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 0000000..b62a348 --- /dev/null +++ b/recipes/catch2/3.x.x/test_v1_package/conanfile.py @@ -0,0 +1,18 @@ +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.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) diff --git a/recipes/catch2/all b/recipes/catch2/all new file mode 120000 index 0000000..85d0b59 --- /dev/null +++ b/recipes/catch2/all @@ -0,0 +1 @@ +3.x.x \ No newline at end of file diff --git a/recipes/catch2/config.yml b/recipes/catch2/config.yml new file mode 100644 index 0000000..0c81c16 --- /dev/null +++ b/recipes/catch2/config.yml @@ -0,0 +1,45 @@ +versions: + "3.7.1": + folder: 3.x.x + "3.7.0": + folder: 3.x.x + "3.6.0": + folder: 3.x.x + "3.5.4": + folder: 3.x.x + "3.5.3": + folder: 3.x.x + "3.5.2": + folder: 3.x.x + "3.5.1": + folder: 3.x.x + "3.5.0": + folder: 3.x.x + "3.4.0": + folder: 3.x.x + "3.3.2": + folder: 3.x.x + "3.3.1": + folder: 3.x.x + "3.3.0": + folder: 3.x.x + "3.2.1": + folder: 3.x.x + "3.2.0": + folder: 3.x.x + "3.1.0": + folder: 3.x.x + "3.0.1": + folder: 3.x.x + "2.13.10": + folder: 2.x.x + "2.13.9": + folder: 2.x.x + "2.13.8": + folder: 2.x.x + "2.13.7": + folder: 2.x.x + "2.12.4": + folder: 2.x.x + "2.11.3": + folder: 2.x.x