Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds rapidcheck gtest/catch integrations #7394

Merged
merged 12 commits into from
Sep 28, 2021
Merged
10 changes: 10 additions & 0 deletions recipes/rapidcheck/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ sources:
"cci.20200131":
url: "https://github.com/emil-e/rapidcheck/archive/258d907da00a0855f92c963d8f76eef115531716.zip"
sha256: "87bfbdceaa09e7aaaf70b2efd0078e93323dd8abdad48c57e9f23bfd84174a75"
patches:
"cci.20210702":
- patch_file: "patches/0001-gtest-catch-integration.patch"
base_path: "source_subfolder"
"cci.20210107":
- patch_file: "patches/0001-gtest-catch-integration-20210107.patch"
base_path: "source_subfolder"
"cci.20200131":
- patch_file: "patches/0001-gtest-catch-integration-20200131.patch"
base_path: "source_subfolder"
49 changes: 40 additions & 9 deletions recipes/rapidcheck/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ class RapidcheckConan(ConanFile):
homepage = "https://github.com/emil-e/rapidcheck"
license = "BSD-2-Clause"
topics = "quickcheck", "testing", "property-testing"
exports_sources = "CMakeLists.txt"
generators = "cmake"
exports_sources = ["CMakeLists.txt", "patches/**"]
generators = ["cmake", "cmake_find_package"]
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"enable_rtti": [True, False],
"enable_catch": [True, False],
"enable_gmock": [True, False],
"enable_gtest": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"enable_rtti": True,
"enable_catch": False,
"enable_gmock": False,
"enable_gtest": False
}

_cmake = None
Expand All @@ -51,6 +57,12 @@ def validate(self):
if self.settings.compiler == "Visual Studio" and self.options.shared:
raise ConanInvalidConfiguration("shared is not supported using Visual Studio")

def requirements(self):
if self.options.enable_catch:
self.requires("catch2/2.13.7")
if self.options.enable_gmock or self.options.enable_gtest:
self.requires("gtest/1.11.0")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
Expand All @@ -62,10 +74,15 @@ def _configure_cmake(self):
self._cmake.definitions["RC_ENABLE_RTTI"] = self.options.enable_rtti
self._cmake.definitions["RC_ENABLE_TESTS"] = False
self._cmake.definitions["RC_ENABLE_EXAMPLES"] = False
self._cmake.definitions["RC_ENABLE_CATCH"] = self.options.enable_catch
self._cmake.definitions["RC_ENABLE_GMOCK"] = self.options.enable_gmock
self._cmake.definitions["RC_ENABLE_GTEST"] = self.options.enable_gtest
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def build(self):
mjvankampen marked this conversation as resolved.
Show resolved Hide resolved
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

Expand All @@ -76,7 +93,10 @@ def package(self):
tools.rmdir(os.path.join(self.package_folder, "share"))
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{"rapidcheck": "rapidcheck::rapidcheck"}
{"rapidcheck": "rapidcheck::rapidcheck",
"rapidcheck_catch":"rapidcheck::catch",
"rapidcheck_gmock": "rapidcheck::gmock",
"rapidcheck_gtest": "rapidcheck::gtest"}
)

@staticmethod
Expand All @@ -103,15 +123,26 @@ def _module_file_rel_path(self):
def package_info(self):
self.cpp_info.names["cmake_find_package"] = "rapidcheck"
self.cpp_info.names["cmake_find_package_multi"] = "rapidcheck"
self.cpp_info.builddirs.append(self._module_subfolder)
self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.libs = ["rapidcheck"]

self.cpp_info.components["core"].set_property("cmake_target_name", "rapidcheck")
self.cpp_info.components["core"].builddirs.append(self._module_subfolder)
self.cpp_info.components["core"].set_property("cmake_build_modules", [self._module_file_rel_path])
self.cpp_info.components["core"].libs = ["rapidcheck"]
version = self.version[4:]
if tools.Version(version) < "20201218":
if self.options.enable_rtti:
self.cpp_info.defines.append("RC_USE_RTTI")
self.cpp_info.components["core"].defines.append("RC_USE_RTTI")
else:
if not self.options.enable_rtti:
self.cpp_info.defines.append("RC_DONT_USE_RTTI")
self.cpp_info.components["core"].defines.append("RC_DONT_USE_RTTI")

if self.options.enable_catch:
self.cpp_info.components["core"].requires.append("catch2::catch2")
self.cpp_info.components["catch"].requires = ["core", "catch2::catch2"]
if self.options.enable_gmock:
self.cpp_info.components["core"].requires.append("gtest::gtest")
self.cpp_info.components["gmock"].requires = ["core"]
if self.options.enable_gtest:
self.cpp_info.components["core"].requires.append("gtest::gtest")
self.cpp_info.components["gtest"].requires = ["core"]

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 92bc63c7df2cb87b5e5672a7651dbb4eafa3aaa7..c57b700157360f4b5a2e280167e821f567bb31ea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -106,8 +106,6 @@ if(RC_ENABLE_RTTI)
target_compile_definitions(rapidcheck PUBLIC RC_USE_RTTI)
endif()

-add_subdirectory(ext)
-
if(RC_ENABLE_TESTS)
enable_testing()
add_subdirectory(test)
@@ -117,6 +115,16 @@ if(RC_ENABLE_EXAMPLES)
add_subdirectory(examples)
endif()

+if (RC_ENABLE_CATCH)
+ find_package(Catch2 REQUIRED)
+ target_link_libraries(rapidcheck PUBLIC Catch2::Catch2)
+endif()
+
+if (RC_ENABLE_GMOCK OR RC_ENABLE_GTEST)
+ find_package(GTest REQUIRED)
+ target_link_libraries(rapidcheck PUBLIC GTest::GTest)
+endif()
+
add_subdirectory(extras)

# Install the export file specifying all the targets for RapidCheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9f583afc171fab0a6894ffd64a0c787fd806bbaa..da2389500c99e4e4b59c772ee25285e2a9607de5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -106,8 +106,6 @@ if(NOT RC_ENABLE_RTTI)
target_compile_definitions(rapidcheck PUBLIC RC_DONT_USE_RTTI)
endif()

-add_subdirectory(ext)
-
if(RC_ENABLE_TESTS)
enable_testing()
add_subdirectory(test)
@@ -116,6 +114,15 @@ endif()
if(RC_ENABLE_EXAMPLES)
add_subdirectory(examples)
endif()
+if (RC_ENABLE_CATCH)
+ find_package(Catch2 REQUIRED)
+ target_link_libraries(rapidcheck PUBLIC Catch2::Catch2)
+endif()
+
+if (RC_ENABLE_GMOCK OR RC_ENABLE_GTEST)
+ find_package(GTest REQUIRED)
+ target_link_libraries(rapidcheck PUBLIC GTest::GTest)
+endif()

add_subdirectory(extras)

30 changes: 30 additions & 0 deletions recipes/rapidcheck/all/patches/0001-gtest-catch-integration.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 15c46d01288dce235179b791770187f5a38230ab..0c47308162af09841789ff9791b11839d524f852 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -111,8 +111,6 @@ if(NOT RC_ENABLE_RTTI)
target_compile_definitions(rapidcheck PUBLIC RC_DONT_USE_RTTI)
endif()

-add_subdirectory(ext)
-
if(RC_ENABLE_TESTS)
enable_testing()
add_subdirectory(test)
@@ -122,6 +120,16 @@ if(RC_ENABLE_EXAMPLES)
add_subdirectory(examples)
endif()

+if (RC_ENABLE_CATCH)
+ find_package(Catch2 REQUIRED)
+ target_link_libraries(rapidcheck PUBLIC Catch2::Catch2)
+endif()
+
+if (RC_ENABLE_GMOCK OR RC_ENABLE_GTEST)
+ find_package(GTest REQUIRED)
+ target_link_libraries(rapidcheck PUBLIC GTest::GTest)
+endif()
+
add_subdirectory(extras)

# Install the export file specifying all the targets for RapidCheck
2 changes: 1 addition & 1 deletion recipes/rapidcheck/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ def build(self):
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)