1
- import glob
2
- import os
3
1
from conans import ConanFile , CMake , tools
4
2
from conans .errors import ConanInvalidConfiguration
3
+ import os
4
+
5
+ required_conan_version = ">=1.33.0"
5
6
6
7
7
8
class GTestConan (ConanFile ):
@@ -10,13 +11,35 @@ class GTestConan(ConanFile):
10
11
url = "https://github.com/conan-io/conan-center-index"
11
12
homepage = "https://github.com/google/googletest"
12
13
license = "BSD-3-Clause"
13
- topics = ("conan" , " gtest" , "testing" , "google-testing" , "unit-test" )
14
+ topics = ("gtest" , "testing" , "google-testing" , "unit-test" )
14
15
exports_sources = ["CMakeLists.txt" , "patches/*" ]
15
16
generators = "cmake"
16
17
settings = "os" , "arch" , "compiler" , "build_type"
17
- options = {"shared" : [True , False ], "build_gmock" : [True , False ], "fPIC" : [True , False ], "no_main" : [True , False ], "debug_postfix" : "ANY" , "hide_symbols" : [True , False ]}
18
- default_options = {"shared" : False , "build_gmock" : True , "fPIC" : True , "no_main" : False , "debug_postfix" : 'd' , "hide_symbols" : False }
19
- _source_subfolder = "source_subfolder"
18
+ options = {
19
+ "shared" : [True , False ],
20
+ "build_gmock" : [True , False ],
21
+ "fPIC" : [True , False ],
22
+ "no_main" : [True , False ],
23
+ "debug_postfix" : "ANY" ,
24
+ "hide_symbols" : [True , False ],
25
+ }
26
+ default_options = {
27
+ "shared" : False ,
28
+ "build_gmock" : True ,
29
+ "fPIC" : True ,
30
+ "no_main" : False ,
31
+ "debug_postfix" : "d" ,
32
+ "hide_symbols" : False ,
33
+ }
34
+ _cmake = None
35
+
36
+ @property
37
+ def _source_subfolder (self ):
38
+ return "source_subfolder"
39
+
40
+ @property
41
+ def _build_subfolder (self ):
42
+ return "build_subfolder"
20
43
21
44
@property
22
45
def _minimum_cpp_standard (self ):
@@ -45,7 +68,7 @@ def _minimum_compilers_version(self):
45
68
"clang" : "5" ,
46
69
"apple-clang" : "9.1"
47
70
}
48
-
71
+
49
72
@property
50
73
def _postfix (self ):
51
74
return self .options .debug_postfix if self .settings .build_type == "Debug" else ""
@@ -59,6 +82,8 @@ def config_options(self):
59
82
def configure (self ):
60
83
if self .options .shared :
61
84
del self .options .fPIC
85
+
86
+ def validate (self ):
62
87
if self .settings .get_safe ("compiler.cppstd" ):
63
88
tools .check_min_cppstd (self , self ._minimum_cpp_standard )
64
89
min_version = self ._minimum_compilers_version .get (
@@ -79,26 +104,27 @@ def lazy_lt_semver(v1, v2):
79
104
self .name , self .settings .compiler , min_version , self .settings .compiler .version ))
80
105
81
106
def source (self ):
82
- tools .get (** self .conan_data ["sources" ][self .version ], destination = self ._source_subfolder , strip_root = True )
107
+ tools .get (** self .conan_data ["sources" ][self .version ],
108
+ destination = self ._source_subfolder , strip_root = True )
83
109
84
110
def _configure_cmake (self ):
85
- cmake = CMake (self )
111
+ if self ._cmake :
112
+ return self ._cmake
113
+ self ._cmake = CMake (self )
86
114
if self .settings .build_type == "Debug" :
87
- cmake .definitions ["CUSTOM_DEBUG_POSTFIX" ] = self .options .debug_postfix
115
+ self . _cmake .definitions ["CUSTOM_DEBUG_POSTFIX" ] = self .options .debug_postfix
88
116
if self .settings .os == "Windows" and self .settings .get_safe ("compiler.runtime" ):
89
- cmake .definitions ["gtest_force_shared_crt" ] = "MD" in str (self .settings .compiler .runtime )
90
- cmake .definitions ["BUILD_GMOCK" ] = self .options .build_gmock
91
- cmake .definitions ["GTEST_NO_MAIN" ] = self .options .no_main
117
+ self ._cmake .definitions ["gtest_force_shared_crt" ] = "MD" in str (self .settings .compiler .runtime )
118
+ self ._cmake .definitions ["BUILD_GMOCK" ] = self .options .build_gmock
92
119
if self .settings .os == "Windows" and self .settings .compiler == "gcc" :
93
- cmake .definitions ["gtest_disable_pthreads" ] = True
94
- cmake .definitions ["gtest_hide_internal_symbols" ] = self .options .hide_symbols
95
- cmake . configure ()
96
- return cmake
120
+ self . _cmake .definitions ["gtest_disable_pthreads" ] = True
121
+ self . _cmake .definitions ["gtest_hide_internal_symbols" ] = self .options .hide_symbols
122
+ self . _cmake . configure (build_folder = self . _build_subfolder )
123
+ return self . _cmake
97
124
98
125
def build (self ):
99
- if "patches" in self .conan_data :
100
- for patch in self .conan_data ["patches" ][self .version ]:
101
- tools .patch (** patch )
126
+ for patch in self .conan_data .get ("patches" , {}).get (self .version , []):
127
+ tools .patch (** patch )
102
128
cmake = self ._configure_cmake ()
103
129
cmake .build ()
104
130
@@ -108,8 +134,7 @@ def package(self):
108
134
cmake .install ()
109
135
tools .rmdir (os .path .join (self .package_folder , "lib" , "pkgconfig" ))
110
136
tools .rmdir (os .path .join (self .package_folder , "lib" , "cmake" ))
111
- for pdb_file in glob .glob (os .path .join (self .package_folder , "lib" , "*.pdb" )):
112
- os .unlink (pdb_file )
137
+ tools .remove_files_by_mask (os .path .join (self .package_folder , "lib" ), "*.pdb" )
113
138
114
139
def package_id (self ):
115
140
del self .info .options .no_main
@@ -122,17 +147,18 @@ def package_info(self):
122
147
self .cpp_info .components ["libgtest" ].libs = ["gtest{}" .format (self ._postfix )]
123
148
if self .settings .os == "Linux" :
124
149
self .cpp_info .components ["libgtest" ].system_libs .append ("pthread" )
125
-
150
+
126
151
if self .settings .os == "Neutrino" and self .settings .os .version == "7.1" :
127
152
self .cpp_info .components ["libgtest" ].system_libs .append ("regex" )
128
153
129
154
if self .options .shared :
130
155
self .cpp_info .components ["libgtest" ].defines .append ("GTEST_LINKED_AS_SHARED_LIBRARY=1" )
131
156
132
- if self .settings .compiler == "Visual Studio" :
133
- if tools .Version (self .settings .compiler .version .value ) >= "15" :
134
- self .cpp_info .components ["libgtest" ].defines .append ("GTEST_LANG_CXX11=1" )
135
- self .cpp_info .components ["libgtest" ].defines .append ("GTEST_HAS_TR1_TUPLE=0" )
157
+ if self .version == "1.8.1" :
158
+ if self .settings .compiler == "Visual Studio" :
159
+ if tools .Version (self .settings .compiler .version ) >= "15" :
160
+ self .cpp_info .components ["libgtest" ].defines .append ("GTEST_LANG_CXX11=1" )
161
+ self .cpp_info .components ["libgtest" ].defines .append ("GTEST_HAS_TR1_TUPLE=0" )
136
162
137
163
if not self .options .no_main :
138
164
self .cpp_info .components ["gtest_main" ].libs = ["gtest_main{}" .format (self ._postfix )]
0 commit comments