Skip to content

Commit 217a57d

Browse files
(#5898) gtest: remove obsolete defines and refactor recipe
* gtest: remove obsolete defines and refactor recipe Check conan version for tools.get Use remove_files_by_mask Refactor call to patching Move compiler checks to validate method Use shorter lines and other small style changes Remove GTEST_NO_MAIN which was doing nothing Do not use GREATER_EQUAL - it is not present in CMake 2.8 Remove "conan" from topics * Remove value Co-authored-by: Chris Mc <prince.chrismc@gmail.com> Co-authored-by: Chris Mc <prince.chrismc@gmail.com>
1 parent b926bc4 commit 217a57d

File tree

2 files changed

+56
-32
lines changed

2 files changed

+56
-32
lines changed

recipes/gtest/all/CMakeLists.txt

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
cmake_minimum_required(VERSION 2.8.11)
22
project(cmake_wrapper)
33

4-
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
4+
include("conanbuildinfo.cmake")
55
conan_basic_setup()
66

7-
option(GTEST_NO_MAIN "Generate google main libraries" OFF)
8-
97
if(MSVC)
10-
if(MSVC_VERSION AND MSVC_VERSION GREATER_EQUAL 1910)
8+
if(MSVC_VERSION AND (MSVC_VERSION EQUAL 1910 OR MSVC_VERSION GREATER 1910))
119
add_definitions(-DGTEST_LANG_CXX11=1 -DGTEST_HAS_TR1_TUPLE=0)
12-
endif(MSVC_VERSION AND MSVC_VERSION GREATER_EQUAL 1910)
10+
endif(MSVC_VERSION AND (MSVC_VERSION EQUAL 1910 OR MSVC_VERSION GREATER 1910))
1311
endif(MSVC)
1412

1513
add_subdirectory("source_subfolder")

recipes/gtest/all/conanfile.py

+53-27
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import glob
2-
import os
31
from conans import ConanFile, CMake, tools
42
from conans.errors import ConanInvalidConfiguration
3+
import os
4+
5+
required_conan_version = ">=1.33.0"
56

67

78
class GTestConan(ConanFile):
@@ -10,13 +11,35 @@ class GTestConan(ConanFile):
1011
url = "https://github.com/conan-io/conan-center-index"
1112
homepage = "https://github.com/google/googletest"
1213
license = "BSD-3-Clause"
13-
topics = ("conan", "gtest", "testing", "google-testing", "unit-test")
14+
topics = ("gtest", "testing", "google-testing", "unit-test")
1415
exports_sources = ["CMakeLists.txt", "patches/*"]
1516
generators = "cmake"
1617
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"
2043

2144
@property
2245
def _minimum_cpp_standard(self):
@@ -45,7 +68,7 @@ def _minimum_compilers_version(self):
4568
"clang": "5",
4669
"apple-clang": "9.1"
4770
}
48-
71+
4972
@property
5073
def _postfix(self):
5174
return self.options.debug_postfix if self.settings.build_type == "Debug" else ""
@@ -59,6 +82,8 @@ def config_options(self):
5982
def configure(self):
6083
if self.options.shared:
6184
del self.options.fPIC
85+
86+
def validate(self):
6287
if self.settings.get_safe("compiler.cppstd"):
6388
tools.check_min_cppstd(self, self._minimum_cpp_standard)
6489
min_version = self._minimum_compilers_version.get(
@@ -79,26 +104,27 @@ def lazy_lt_semver(v1, v2):
79104
self.name, self.settings.compiler, min_version, self.settings.compiler.version))
80105

81106
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)
83109

84110
def _configure_cmake(self):
85-
cmake = CMake(self)
111+
if self._cmake:
112+
return self._cmake
113+
self._cmake = CMake(self)
86114
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
88116
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
92119
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
97124

98125
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)
102128
cmake = self._configure_cmake()
103129
cmake.build()
104130

@@ -108,8 +134,7 @@ def package(self):
108134
cmake.install()
109135
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
110136
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")
113138

114139
def package_id(self):
115140
del self.info.options.no_main
@@ -122,17 +147,18 @@ def package_info(self):
122147
self.cpp_info.components["libgtest"].libs = ["gtest{}".format(self._postfix)]
123148
if self.settings.os == "Linux":
124149
self.cpp_info.components["libgtest"].system_libs.append("pthread")
125-
150+
126151
if self.settings.os == "Neutrino" and self.settings.os.version == "7.1":
127152
self.cpp_info.components["libgtest"].system_libs.append("regex")
128153

129154
if self.options.shared:
130155
self.cpp_info.components["libgtest"].defines.append("GTEST_LINKED_AS_SHARED_LIBRARY=1")
131156

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")
136162

137163
if not self.options.no_main:
138164
self.cpp_info.components["gtest_main"].libs = ["gtest_main{}".format(self._postfix)]

0 commit comments

Comments
 (0)