1
- # Require CMake 3.10. If available, use the policies up to CMake 3.22.
2
- cmake_minimum_required (VERSION 3.10...3.22 )
1
+ cmake_minimum_required (VERSION 3.5.1 )
2
+
3
+ foreach (p
4
+ CMP0048 # OK to clear PROJECT_VERSION on project()
5
+ CMP0054 # CMake 3.1
6
+ CMP0056 # export EXE_LINKER_FLAGS to try_run
7
+ CMP0057 # Support no if() IN_LIST operator
8
+ CMP0063 # Honor visibility properties for all targets
9
+ CMP0077 # Allow option() overrides in importing projects
10
+ )
11
+ if (POLICY ${p} )
12
+ cmake_policy (SET ${p} NEW )
13
+ endif ()
14
+ endforeach ()
3
15
4
- project (benchmark VERSION 1.8.3 LANGUAGES CXX )
16
+ project (benchmark VERSION 1.6.0 LANGUAGES CXX )
5
17
6
18
option (BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON )
7
19
option (BENCHMARK_ENABLE_EXCEPTIONS "Enable the use of exceptions in the benchmark library." ON )
@@ -14,14 +26,11 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "PGI")
14
26
# PGC++ maybe reporting false positives.
15
27
set (BENCHMARK_ENABLE_WERROR OFF )
16
28
endif ()
17
- if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "NVHPC" )
18
- set (BENCHMARK_ENABLE_WERROR OFF )
19
- endif ()
20
29
if (BENCHMARK_FORCE_WERROR )
21
30
set (BENCHMARK_ENABLE_WERROR ON )
22
31
endif (BENCHMARK_FORCE_WERROR )
23
32
24
- if (NOT ( MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC" ) )
33
+ if (NOT MSVC )
25
34
option (BENCHMARK_BUILD_32_BITS "Build a 32 bit version of the library." OFF )
26
35
else ()
27
36
set (BENCHMARK_BUILD_32_BITS OFF CACHE BOOL "Build a 32 bit version of the library - unsupported when using MSVC)" FORCE )
@@ -41,11 +50,8 @@ option(BENCHMARK_USE_BUNDLED_GTEST "Use bundled GoogleTest. If disabled, the fin
41
50
42
51
option (BENCHMARK_ENABLE_LIBPFM "Enable performance counters provided by libpfm" OFF )
43
52
44
- # Export only public symbols
45
- set (CMAKE_CXX_VISIBILITY_PRESET hidden )
46
- set (CMAKE_VISIBILITY_INLINES_HIDDEN ON )
47
-
48
- if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
53
+ set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON )
54
+ if (MSVC )
49
55
# As of CMake 3.18, CMAKE_SYSTEM_PROCESSOR is not set properly for MSVC and
50
56
# cross-compilation (e.g. Host=x86_64, target=aarch64) requires using the
51
57
# undocumented, but working variable.
@@ -66,7 +72,7 @@ function(should_enable_assembly_tests)
66
72
return ()
67
73
endif ()
68
74
endif ()
69
- if (MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC" )
75
+ if (MSVC )
70
76
return ()
71
77
elseif (NOT CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" )
72
78
return ()
@@ -105,49 +111,29 @@ get_git_version(GIT_VERSION)
105
111
# If no git version can be determined, use the version
106
112
# from the project() command
107
113
if ("${GIT_VERSION} " STREQUAL "0.0.0" )
108
- set (VERSION "v ${benchmark_VERSION} " )
114
+ set (VERSION "${benchmark_VERSION} " )
109
115
else ()
110
116
set (VERSION "${GIT_VERSION} " )
111
117
endif ()
112
-
113
- # Normalize version: drop "v" prefix, replace first "-" with ".",
114
- # drop everything after second "-" (including said "-").
115
- string (STRIP ${VERSION} VERSION )
116
- if (VERSION MATCHES v[^-]*- )
117
- string (REGEX REPLACE "v([^-]*)-([0-9]+)-.*" "\\ 1.\\ 2" NORMALIZED_VERSION ${VERSION} )
118
- else ()
119
- string (REGEX REPLACE "v(.*)" "\\ 1" NORMALIZED_VERSION ${VERSION} )
120
- endif ()
121
-
122
118
# Tell the user what versions we are using
123
- message (STATUS "Google Benchmark version : ${VERSION} , normalized to ${NORMALIZED_VERSION } " )
119
+ message (STATUS "Version : ${VERSION} " )
124
120
125
121
# The version of the libraries
126
- set (GENERIC_LIB_VERSION ${NORMALIZED_VERSION } )
127
- string (SUBSTRING ${NORMALIZED_VERSION } 0 1 GENERIC_LIB_SOVERSION )
122
+ set (GENERIC_LIB_VERSION ${VERSION } )
123
+ string (SUBSTRING ${VERSION } 0 1 GENERIC_LIB_SOVERSION )
128
124
129
125
# Import our CMake modules
130
- include (AddCXXCompilerFlag )
131
126
include (CheckCXXCompilerFlag )
132
- include (CheckLibraryExists )
127
+ include (AddCXXCompilerFlag )
133
128
include (CXXFeatureCheck )
129
+ include (CheckLibraryExists )
134
130
135
131
check_library_exists (rt shm_open "" HAVE_LIB_RT )
136
132
137
133
if (BENCHMARK_BUILD_32_BITS )
138
134
add_required_cxx_compiler_flag (-m32 )
139
135
endif ()
140
136
141
- if (MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC" )
142
- set (BENCHMARK_CXX_STANDARD 14 )
143
- else ()
144
- set (BENCHMARK_CXX_STANDARD 11 )
145
- endif ()
146
-
147
- set (CMAKE_CXX_STANDARD ${BENCHMARK_CXX_STANDARD} )
148
- set (CMAKE_CXX_STANDARD_REQUIRED YES )
149
- set (CMAKE_CXX_EXTENSIONS OFF )
150
-
151
137
if (MSVC )
152
138
# Turn compiler warnings up to 11
153
139
string (REGEX REPLACE "[-/]W[1-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} " )
@@ -180,18 +166,21 @@ if (MSVC)
180
166
set (CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} /LTCG" )
181
167
endif ()
182
168
else ()
183
- # Turn on Large-file Support
184
- add_definitions (-D_FILE_OFFSET_BITS=64 )
185
- add_definitions (-D_LARGEFILE64_SOURCE )
186
- add_definitions (-D_LARGEFILE_SOURCE )
169
+ # Try and enable C++11. Don't use C++14 because it doesn't work in some
170
+ # configurations.
171
+ add_cxx_compiler_flag (-std=c++11 )
172
+ if (NOT HAVE_CXX_FLAG_STD_CXX11 )
173
+ add_cxx_compiler_flag (-std=c++0x )
174
+ endif ()
175
+
187
176
# Turn compiler warnings up to 11
188
177
add_cxx_compiler_flag (-Wall )
189
178
add_cxx_compiler_flag (-Wextra )
190
179
add_cxx_compiler_flag (-Wshadow )
191
- add_cxx_compiler_flag (-Wfloat-equal )
192
- add_cxx_compiler_flag (-Wold-style-cast )
193
180
if (BENCHMARK_ENABLE_WERROR )
194
- add_cxx_compiler_flag (-Werror )
181
+ add_cxx_compiler_flag (-Werror RELEASE )
182
+ add_cxx_compiler_flag (-Werror RELWITHDEBINFO )
183
+ add_cxx_compiler_flag (-Werror MINSIZEREL )
195
184
endif ()
196
185
if (NOT BENCHMARK_ENABLE_TESTING )
197
186
# Disable warning when compiling tests as gtest does not use 'override'.
@@ -204,23 +193,24 @@ else()
204
193
# Disable warnings regarding deprecated parts of the library while building
205
194
# and testing those parts of the library.
206
195
add_cxx_compiler_flag (-Wno-deprecated-declarations )
207
- if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" )
196
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" )
208
197
# Intel silently ignores '-Wno-deprecated-declarations',
209
198
# warning no. 1786 must be explicitly disabled.
210
199
# See #631 for rationale.
211
200
add_cxx_compiler_flag (-wd1786 )
212
- add_cxx_compiler_flag (-fno-finite-math-only )
213
201
endif ()
214
202
# Disable deprecation warnings for release builds (when -Werror is enabled).
215
203
if (BENCHMARK_ENABLE_WERROR )
216
- add_cxx_compiler_flag (-Wno-deprecated )
204
+ add_cxx_compiler_flag (-Wno-deprecated RELEASE )
205
+ add_cxx_compiler_flag (-Wno-deprecated RELWITHDEBINFO )
206
+ add_cxx_compiler_flag (-Wno-deprecated MINSIZEREL )
217
207
endif ()
218
208
if (NOT BENCHMARK_ENABLE_EXCEPTIONS )
219
209
add_cxx_compiler_flag (-fno-exceptions )
220
210
endif ()
221
211
222
212
if (HAVE_CXX_FLAG_FSTRICT_ALIASING )
223
- if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" ) #ICC17u2: Many false positives for Wstrict-aliasing
213
+ if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel" ) #ICC17u2: Many false positives for Wstrict-aliasing
224
214
add_cxx_compiler_flag (-Wstrict-aliasing )
225
215
endif ()
226
216
endif ()
@@ -229,12 +219,12 @@ else()
229
219
add_cxx_compiler_flag (-wd654 )
230
220
add_cxx_compiler_flag (-Wthread-safety )
231
221
if (HAVE_CXX_FLAG_WTHREAD_SAFETY )
232
- cxx_feature_check (THREAD_SAFETY_ATTRIBUTES "-DINCLUDE_DIRECTORIES= ${PROJECT_SOURCE_DIR} /include" )
222
+ cxx_feature_check (THREAD_SAFETY_ATTRIBUTES )
233
223
endif ()
234
224
235
225
# On most UNIX like platforms g++ and clang++ define _GNU_SOURCE as a
236
226
# predefined macro, which turns on all of the wonderful libc extensions.
237
- # However g++ doesn't do this in Cygwin so we have to define it ourselves
227
+ # However g++ doesn't do this in Cygwin so we have to define it ourselfs
238
228
# since we depend on GNU/POSIX/BSD extensions.
239
229
if (CYGWIN )
240
230
add_definitions (-D_GNU_SOURCE=1 )
@@ -285,8 +275,7 @@ if (BENCHMARK_USE_LIBCXX)
285
275
if ("${CMAKE_CXX_COMPILER_ID} " MATCHES "Clang" )
286
276
add_cxx_compiler_flag (-stdlib=libc++ )
287
277
elseif ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "GNU" OR
288
- "${CMAKE_CXX_COMPILER_ID} " STREQUAL "Intel" OR
289
- "${CMAKE_CXX_COMPILER_ID} " STREQUAL "IntelLLVM" )
278
+ "${CMAKE_CXX_COMPILER_ID} " STREQUAL "Intel" )
290
279
add_cxx_compiler_flag (-nostdinc++ )
291
280
message (WARNING "libc++ header path must be manually specified using CMAKE_CXX_FLAGS" )
292
281
# Adding -nodefaultlibs directly to CMAKE_<TYPE>_LINKER_FLAGS will break
@@ -323,10 +312,9 @@ cxx_feature_check(STEADY_CLOCK)
323
312
# Ensure we have pthreads
324
313
set (THREADS_PREFER_PTHREAD_FLAG ON )
325
314
find_package (Threads REQUIRED )
326
- cxx_feature_check (PTHREAD_AFFINITY )
327
315
328
316
if (BENCHMARK_ENABLE_LIBPFM )
329
- find_package (PFM REQUIRED )
317
+ find_package (PFM )
330
318
endif ()
331
319
332
320
# Set up directories
0 commit comments