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"
48 changes: 39 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,17 @@ 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
if self.options.enable_gmock and not self.deps_cpp_info["gtest"].build_gmock:
raise ConanInvalidConfiguration("The option `rapidcheck:enable_gmock` requires gtest:build_gmock=True`")
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

Expand All @@ -76,7 +95,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::rapidcheck_catch",
"rapidcheck_gmock": "rapidcheck::rapidcheck_gmock",
"rapidcheck_gtest": "rapidcheck::rapidcheck_gtest"}
)

@staticmethod
Expand All @@ -103,15 +125,23 @@ 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["rapidcheck_rapidcheck"].set_property("cmake_target_name", "rapidcheck")
self.cpp_info.components["rapidcheck_rapidcheck"].builddirs.append(self._module_subfolder)
self.cpp_info.components["rapidcheck_rapidcheck"].set_property("cmake_build_modules", [self._module_file_rel_path])
self.cpp_info.components["rapidcheck_rapidcheck"].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["rapidcheck_rapidcheck"].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["rapidcheck_rapidcheck"].defines.append("RC_DONT_USE_RTTI")

if self.options.enable_catch:
self.cpp_info.components["rapidcheck_catch"].requires = ["rapidcheck_rapidcheck", "catch2::catch2"]
if self.options.enable_gmock:
self.cpp_info.components["rapidcheck_gmock"].requires = ["rapidcheck_rapidcheck", "gtest::gtest"]
if self.options.enable_gtest:
self.cpp_info.components["rapidcheck_gtest"].requires = ["rapidcheck_rapidcheck", "gtest::gtest"]

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 92bc63c7df2cb87b5e5672a7651dbb4eafa3aaa7..14000896cd4e6ebcde3f2154b85caf4f5cca056b 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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9f583afc171fab0a6894ffd64a0c787fd806bbaa..ea31145f55fe1010fe36739c17a655309db552f1 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)
13 changes: 13 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,13 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 15c46d01288dce235179b791770187f5a38230ab..1805354a744931086622c41fa5a640c283142adc 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)
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)