@@ -13,18 +13,24 @@ class RapidcheckConan(ConanFile):
13
13
homepage = "https://github.com/emil-e/rapidcheck"
14
14
license = "BSD-2-Clause"
15
15
topics = "quickcheck" , "testing" , "property-testing"
16
- exports_sources = "CMakeLists.txt"
17
- generators = "cmake"
16
+ exports_sources = [ "CMakeLists.txt" , "patches/**" ]
17
+ generators = [ "cmake" , "cmake_find_package" ]
18
18
settings = "os" , "arch" , "compiler" , "build_type"
19
19
options = {
20
20
"shared" : [True , False ],
21
21
"fPIC" : [True , False ],
22
22
"enable_rtti" : [True , False ],
23
+ "enable_catch" : [True , False ],
24
+ "enable_gmock" : [True , False ],
25
+ "enable_gtest" : [True , False ]
23
26
}
24
27
default_options = {
25
28
"shared" : False ,
26
29
"fPIC" : True ,
27
30
"enable_rtti" : True ,
31
+ "enable_catch" : False ,
32
+ "enable_gmock" : False ,
33
+ "enable_gtest" : False
28
34
}
29
35
30
36
_cmake = None
@@ -51,6 +57,12 @@ def validate(self):
51
57
if self .settings .compiler == "Visual Studio" and self .options .shared :
52
58
raise ConanInvalidConfiguration ("shared is not supported using Visual Studio" )
53
59
60
+ def requirements (self ):
61
+ if self .options .enable_catch :
62
+ self .requires ("catch2/2.13.7" )
63
+ if self .options .enable_gmock or self .options .enable_gtest :
64
+ self .requires ("gtest/1.11.0" )
65
+
54
66
def source (self ):
55
67
tools .get (** self .conan_data ["sources" ][self .version ],
56
68
destination = self ._source_subfolder , strip_root = True )
@@ -62,10 +74,17 @@ def _configure_cmake(self):
62
74
self ._cmake .definitions ["RC_ENABLE_RTTI" ] = self .options .enable_rtti
63
75
self ._cmake .definitions ["RC_ENABLE_TESTS" ] = False
64
76
self ._cmake .definitions ["RC_ENABLE_EXAMPLES" ] = False
77
+ self ._cmake .definitions ["RC_ENABLE_CATCH" ] = self .options .enable_catch
78
+ self ._cmake .definitions ["RC_ENABLE_GMOCK" ] = self .options .enable_gmock
79
+ self ._cmake .definitions ["RC_ENABLE_GTEST" ] = self .options .enable_gtest
65
80
self ._cmake .configure (build_folder = self ._build_subfolder )
66
81
return self ._cmake
67
82
68
83
def build (self ):
84
+ if self .options .enable_gmock and not self .deps_cpp_info ["gtest" ].build_gmock :
85
+ raise ConanInvalidConfiguration ("The option `rapidcheck:enable_gmock` requires gtest:build_gmock=True`" )
86
+ for patch in self .conan_data ["patches" ][self .version ]:
87
+ tools .patch (** patch )
69
88
cmake = self ._configure_cmake ()
70
89
cmake .build ()
71
90
@@ -76,7 +95,10 @@ def package(self):
76
95
tools .rmdir (os .path .join (self .package_folder , "share" ))
77
96
self ._create_cmake_module_alias_targets (
78
97
os .path .join (self .package_folder , self ._module_file_rel_path ),
79
- {"rapidcheck" : "rapidcheck::rapidcheck" }
98
+ {"rapidcheck" : "rapidcheck::rapidcheck" ,
99
+ "rapidcheck_catch" :"rapidcheck::rapidcheck_catch" ,
100
+ "rapidcheck_gmock" : "rapidcheck::rapidcheck_gmock" ,
101
+ "rapidcheck_gtest" : "rapidcheck::rapidcheck_gtest" }
80
102
)
81
103
82
104
@staticmethod
@@ -103,15 +125,23 @@ def _module_file_rel_path(self):
103
125
def package_info (self ):
104
126
self .cpp_info .names ["cmake_find_package" ] = "rapidcheck"
105
127
self .cpp_info .names ["cmake_find_package_multi" ] = "rapidcheck"
106
- self .cpp_info .builddirs .append (self ._module_subfolder )
107
- self .cpp_info .build_modules ["cmake_find_package" ] = [self ._module_file_rel_path ]
108
- self .cpp_info .build_modules ["cmake_find_package_multi" ] = [self ._module_file_rel_path ]
109
- self .cpp_info .libs = ["rapidcheck" ]
110
128
129
+ self .cpp_info .components ["rapidcheck_rapidcheck" ].set_property ("cmake_target_name" , "rapidcheck" )
130
+ self .cpp_info .components ["rapidcheck_rapidcheck" ].builddirs .append (self ._module_subfolder )
131
+ self .cpp_info .components ["rapidcheck_rapidcheck" ].set_property ("cmake_build_modules" , [self ._module_file_rel_path ])
132
+ self .cpp_info .components ["rapidcheck_rapidcheck" ].libs = ["rapidcheck" ]
111
133
version = self .version [4 :]
112
134
if tools .Version (version ) < "20201218" :
113
135
if self .options .enable_rtti :
114
- self .cpp_info .defines .append ("RC_USE_RTTI" )
136
+ self .cpp_info .components [ "rapidcheck_rapidcheck" ]. defines .append ("RC_USE_RTTI" )
115
137
else :
116
138
if not self .options .enable_rtti :
117
- self .cpp_info .defines .append ("RC_DONT_USE_RTTI" )
139
+ self .cpp_info .components ["rapidcheck_rapidcheck" ].defines .append ("RC_DONT_USE_RTTI" )
140
+
141
+ if self .options .enable_catch :
142
+ self .cpp_info .components ["rapidcheck_catch" ].requires = ["rapidcheck_rapidcheck" , "catch2::catch2" ]
143
+ if self .options .enable_gmock :
144
+ self .cpp_info .components ["rapidcheck_gmock" ].requires = ["rapidcheck_rapidcheck" , "gtest::gtest" ]
145
+ if self .options .enable_gtest :
146
+ self .cpp_info .components ["rapidcheck_gtest" ].requires = ["rapidcheck_rapidcheck" , "gtest::gtest" ]
147
+
0 commit comments