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)
153
16- project (benchmark VERSION 1.6.0 LANGUAGES CXX)
4+ project (benchmark VERSION 1.8.3 LANGUAGES CXX)
175
186option (BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON )
197option (BENCHMARK_ENABLE_EXCEPTIONS "Enable the use of exceptions in the benchmark library." ON )
@@ -26,11 +14,14 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "PGI")
2614 # PGC++ maybe reporting false positives.
2715 set (BENCHMARK_ENABLE_WERROR OFF )
2816endif ()
17+ if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "NVHPC" )
18+ set (BENCHMARK_ENABLE_WERROR OFF )
19+ endif ()
2920if (BENCHMARK_FORCE_WERROR)
3021 set (BENCHMARK_ENABLE_WERROR ON )
3122endif (BENCHMARK_FORCE_WERROR)
3223
33- if (NOT MSVC )
24+ if (NOT ( MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC" ) )
3425 option (BENCHMARK_BUILD_32_BITS "Build a 32 bit version of the library." OFF )
3526else ()
3627 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
5041
5142option (BENCHMARK_ENABLE_LIBPFM "Enable performance counters provided by libpfm" OFF )
5243
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" )
5549 # As of CMake 3.18, CMAKE_SYSTEM_PROCESSOR is not set properly for MSVC and
5650 # cross-compilation (e.g. Host=x86_64, target=aarch64) requires using the
5751 # undocumented, but working variable.
@@ -72,7 +66,7 @@ function(should_enable_assembly_tests)
7266 return ()
7367 endif ()
7468 endif ()
75- if (MSVC )
69+ if (MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC" )
7670 return ()
7771 elseif (NOT CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" )
7872 return ()
@@ -111,29 +105,49 @@ get_git_version(GIT_VERSION)
111105# If no git version can be determined, use the version
112106# from the project() command
113107if ("${GIT_VERSION} " STREQUAL "0.0.0" )
114- set (VERSION "${benchmark_VERSION} " )
108+ set (VERSION "v ${benchmark_VERSION} " )
115109else ()
116110 set (VERSION "${GIT_VERSION} " )
117111endif ()
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+
118122# Tell the user what versions we are using
119- message (STATUS "Version : ${VERSION} " )
123+ message (STATUS "Google Benchmark version : ${VERSION} , normalized to ${NORMALIZED_VERSION } " )
120124
121125# 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)
124128
125129# Import our CMake modules
126- include (CheckCXXCompilerFlag)
127130include (AddCXXCompilerFlag)
128- include (CXXFeatureCheck )
131+ include (CheckCXXCompilerFlag )
129132include (CheckLibraryExists)
133+ include (CXXFeatureCheck)
130134
131135check_library_exists(rt shm_open "" HAVE_LIB_RT)
132136
133137if (BENCHMARK_BUILD_32_BITS)
134138 add_required_cxx_compiler_flag(-m32)
135139endif ()
136140
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+
137151if (MSVC )
138152 # Turn compiler warnings up to 11
139153 string (REGEX REPLACE "[-/]W[1-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} " )
@@ -166,21 +180,18 @@ if (MSVC)
166180 set (CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} /LTCG" )
167181 endif ()
168182else ()
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)
176187 # Turn compiler warnings up to 11
177188 add_cxx_compiler_flag(-Wall)
178189 add_cxx_compiler_flag(-Wextra)
179190 add_cxx_compiler_flag(-Wshadow)
191+ add_cxx_compiler_flag(-Wfloat-equal )
192+ add_cxx_compiler_flag(-Wold-style-cast)
180193 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)
184195 endif ()
185196 if (NOT BENCHMARK_ENABLE_TESTING)
186197 # Disable warning when compiling tests as gtest does not use 'override'.
@@ -193,24 +204,23 @@ else()
193204 # Disable warnings regarding deprecated parts of the library while building
194205 # and testing those parts of the library.
195206 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" )
197208 # Intel silently ignores '-Wno-deprecated-declarations',
198209 # warning no. 1786 must be explicitly disabled.
199210 # See #631 for rationale.
200211 add_cxx_compiler_flag(-wd1786)
212+ add_cxx_compiler_flag(-fno-finite-math-only)
201213 endif ()
202214 # Disable deprecation warnings for release builds (when -Werror is enabled).
203215 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)
207217 endif ()
208218 if (NOT BENCHMARK_ENABLE_EXCEPTIONS)
209219 add_cxx_compiler_flag(-fno-exceptions)
210220 endif ()
211221
212222 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
214224 add_cxx_compiler_flag(-Wstrict-aliasing)
215225 endif ()
216226 endif ()
@@ -219,12 +229,12 @@ else()
219229 add_cxx_compiler_flag(-wd654)
220230 add_cxx_compiler_flag(-Wthread-safety)
221231 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" )
223233 endif ()
224234
225235 # On most UNIX like platforms g++ and clang++ define _GNU_SOURCE as a
226236 # 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
228238 # since we depend on GNU/POSIX/BSD extensions.
229239 if (CYGWIN )
230240 add_definitions (-D_GNU_SOURCE=1)
@@ -275,7 +285,8 @@ if (BENCHMARK_USE_LIBCXX)
275285 if ("${CMAKE_CXX_COMPILER_ID} " MATCHES "Clang" )
276286 add_cxx_compiler_flag(-stdlib=libc++)
277287 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" )
279290 add_cxx_compiler_flag(-nostdinc++)
280291 message (WARNING "libc++ header path must be manually specified using CMAKE_CXX_FLAGS" )
281292 # Adding -nodefaultlibs directly to CMAKE_<TYPE>_LINKER_FLAGS will break
@@ -312,9 +323,10 @@ cxx_feature_check(STEADY_CLOCK)
312323# Ensure we have pthreads
313324set (THREADS_PREFER_PTHREAD_FLAG ON )
314325find_package (Threads REQUIRED)
326+ cxx_feature_check(PTHREAD_AFFINITY)
315327
316328if (BENCHMARK_ENABLE_LIBPFM)
317- find_package (PFM)
329+ find_package (PFM REQUIRED )
318330endif ()
319331
320332# Set up directories
0 commit comments