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