Mercurial > hg > CbC > CbC_llvm
comparison libcxx/utils/google-benchmark/CMakeLists.txt @ 223:5f17cb93ff66 llvm-original
LLVM13 (2021/7/18)
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 18 Jul 2021 22:43:00 +0900 |
parents | 1d019706d866 |
children |
comparison
equal
deleted
inserted
replaced
222:81f6424ef0e3 | 223:5f17cb93ff66 |
---|---|
1 cmake_minimum_required (VERSION 2.8.12) | 1 cmake_minimum_required (VERSION 3.5.1) |
2 | |
3 project (benchmark) | |
4 | 2 |
5 foreach(p | 3 foreach(p |
4 CMP0048 # OK to clear PROJECT_VERSION on project() | |
6 CMP0054 # CMake 3.1 | 5 CMP0054 # CMake 3.1 |
7 CMP0056 # export EXE_LINKER_FLAGS to try_run | 6 CMP0056 # export EXE_LINKER_FLAGS to try_run |
8 CMP0057 # Support no if() IN_LIST operator | 7 CMP0057 # Support no if() IN_LIST operator |
8 CMP0063 # Honor visibility properties for all targets | |
9 CMP0077 # Allow option() overrides in importing projects | |
9 ) | 10 ) |
10 if(POLICY ${p}) | 11 if(POLICY ${p}) |
11 cmake_policy(SET ${p} NEW) | 12 cmake_policy(SET ${p} NEW) |
12 endif() | 13 endif() |
13 endforeach() | 14 endforeach() |
15 | |
16 project (benchmark VERSION 1.5.4 LANGUAGES CXX) | |
14 | 17 |
15 option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON) | 18 option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON) |
16 option(BENCHMARK_ENABLE_EXCEPTIONS "Enable the use of exceptions in the benchmark library." ON) | 19 option(BENCHMARK_ENABLE_EXCEPTIONS "Enable the use of exceptions in the benchmark library." ON) |
17 option(BENCHMARK_ENABLE_LTO "Enable link time optimisation of the benchmark library." OFF) | 20 option(BENCHMARK_ENABLE_LTO "Enable link time optimisation of the benchmark library." OFF) |
18 option(BENCHMARK_USE_LIBCXX "Build and test using libc++ as the standard library." OFF) | 21 option(BENCHMARK_USE_LIBCXX "Build and test using libc++ as the standard library." OFF) |
28 option(BENCHMARK_DOWNLOAD_DEPENDENCIES "Allow the downloading and in-tree building of unmet dependencies" OFF) | 31 option(BENCHMARK_DOWNLOAD_DEPENDENCIES "Allow the downloading and in-tree building of unmet dependencies" OFF) |
29 | 32 |
30 # This option can be used to disable building and running unit tests which depend on gtest | 33 # This option can be used to disable building and running unit tests which depend on gtest |
31 # in cases where it is not possible to build or find a valid version of gtest. | 34 # in cases where it is not possible to build or find a valid version of gtest. |
32 option(BENCHMARK_ENABLE_GTEST_TESTS "Enable building the unit tests which depend on gtest" ON) | 35 option(BENCHMARK_ENABLE_GTEST_TESTS "Enable building the unit tests which depend on gtest" ON) |
36 | |
37 option(BENCHMARK_ENABLE_LIBPFM "Enable performance counters provided by libpfm" OFF) | |
38 | |
39 set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) | |
40 if(MSVC) | |
41 # As of CMake 3.18, CMAKE_SYSTEM_PROCESSOR is not set properly for MSVC and | |
42 # cross-compilation (e.g. Host=x86_64, target=aarch64) requires using the | |
43 # undocumented, but working variable. | |
44 # See https://gitlab.kitware.com/cmake/cmake/-/issues/15170 | |
45 set(CMAKE_SYSTEM_PROCESSOR ${MSVC_CXX_ARCHITECTURE_ID}) | |
46 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "ARM") | |
47 set(CMAKE_CROSSCOMPILING TRUE) | |
48 endif() | |
49 endif() | |
33 | 50 |
34 set(ENABLE_ASSEMBLY_TESTS_DEFAULT OFF) | 51 set(ENABLE_ASSEMBLY_TESTS_DEFAULT OFF) |
35 function(should_enable_assembly_tests) | 52 function(should_enable_assembly_tests) |
36 if(CMAKE_BUILD_TYPE) | 53 if(CMAKE_BUILD_TYPE) |
37 string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER) | 54 string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER) |
75 | 92 |
76 # Read the git tags to determine the project version | 93 # Read the git tags to determine the project version |
77 include(GetGitVersion) | 94 include(GetGitVersion) |
78 get_git_version(GIT_VERSION) | 95 get_git_version(GIT_VERSION) |
79 | 96 |
97 # If no git version can be determined, use the version | |
98 # from the project() command | |
99 if ("${GIT_VERSION}" STREQUAL "0.0.0") | |
100 set(VERSION "${benchmark_VERSION}") | |
101 else() | |
102 set(VERSION "${GIT_VERSION}") | |
103 endif() | |
80 # Tell the user what versions we are using | 104 # Tell the user what versions we are using |
81 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" VERSION ${GIT_VERSION}) | |
82 message(STATUS "Version: ${VERSION}") | 105 message(STATUS "Version: ${VERSION}") |
83 | 106 |
84 # The version of the libraries | 107 # The version of the libraries |
85 set(GENERIC_LIB_VERSION ${VERSION}) | 108 set(GENERIC_LIB_VERSION ${VERSION}) |
86 string(SUBSTRING ${VERSION} 0 1 GENERIC_LIB_SOVERSION) | 109 string(SUBSTRING ${VERSION} 0 1 GENERIC_LIB_SOVERSION) |
138 add_cxx_compiler_flag(-Wextra) | 161 add_cxx_compiler_flag(-Wextra) |
139 add_cxx_compiler_flag(-Wshadow) | 162 add_cxx_compiler_flag(-Wshadow) |
140 add_cxx_compiler_flag(-Werror RELEASE) | 163 add_cxx_compiler_flag(-Werror RELEASE) |
141 add_cxx_compiler_flag(-Werror RELWITHDEBINFO) | 164 add_cxx_compiler_flag(-Werror RELWITHDEBINFO) |
142 add_cxx_compiler_flag(-Werror MINSIZEREL) | 165 add_cxx_compiler_flag(-Werror MINSIZEREL) |
166 if (NOT BENCHMARK_ENABLE_TESTING) | |
167 # Disable warning when compiling tests as gtest does not use 'override'. | |
168 add_cxx_compiler_flag(-Wsuggest-override) | |
169 endif() | |
143 add_cxx_compiler_flag(-pedantic) | 170 add_cxx_compiler_flag(-pedantic) |
144 add_cxx_compiler_flag(-pedantic-errors) | 171 add_cxx_compiler_flag(-pedantic-errors) |
145 add_cxx_compiler_flag(-Wshorten-64-to-32) | 172 add_cxx_compiler_flag(-Wshorten-64-to-32) |
146 add_cxx_compiler_flag(-fstrict-aliasing) | 173 add_cxx_compiler_flag(-fstrict-aliasing) |
147 # Disable warnings regarding deprecated parts of the library while building | 174 # Disable warnings regarding deprecated parts of the library while building |
180 # since we depend on GNU/POSIX/BSD extensions. | 207 # since we depend on GNU/POSIX/BSD extensions. |
181 if (CYGWIN) | 208 if (CYGWIN) |
182 add_definitions(-D_GNU_SOURCE=1) | 209 add_definitions(-D_GNU_SOURCE=1) |
183 endif() | 210 endif() |
184 | 211 |
212 if (QNXNTO) | |
213 add_definitions(-D_QNX_SOURCE) | |
214 endif() | |
215 | |
185 # Link time optimisation | 216 # Link time optimisation |
186 if (BENCHMARK_ENABLE_LTO) | 217 if (BENCHMARK_ENABLE_LTO) |
187 add_cxx_compiler_flag(-flto) | 218 add_cxx_compiler_flag(-flto) |
188 if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") | 219 add_cxx_compiler_flag(-Wno-lto-type-mismatch) |
220 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") | |
189 find_program(GCC_AR gcc-ar) | 221 find_program(GCC_AR gcc-ar) |
190 if (GCC_AR) | 222 if (GCC_AR) |
191 set(CMAKE_AR ${GCC_AR}) | 223 set(CMAKE_AR ${GCC_AR}) |
192 endif() | 224 endif() |
193 find_program(GCC_RANLIB gcc-ranlib) | 225 find_program(GCC_RANLIB gcc-ranlib) |
194 if (GCC_RANLIB) | 226 if (GCC_RANLIB) |
195 set(CMAKE_RANLIB ${GCC_RANLIB}) | 227 set(CMAKE_RANLIB ${GCC_RANLIB}) |
196 endif() | 228 endif() |
197 elseif("${CMAKE_C_COMPILER_ID}" MATCHES "Clang") | 229 elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |
198 include(llvm-toolchain) | 230 include(llvm-toolchain) |
199 endif() | 231 endif() |
200 endif() | 232 endif() |
201 | 233 |
202 # Coverage build type | 234 # Coverage build type |
234 else() | 266 else() |
235 message(FATAL_ERROR "-DBENCHMARK_USE_LIBCXX:BOOL=ON is not supported for compiler") | 267 message(FATAL_ERROR "-DBENCHMARK_USE_LIBCXX:BOOL=ON is not supported for compiler") |
236 endif() | 268 endif() |
237 endif(BENCHMARK_USE_LIBCXX) | 269 endif(BENCHMARK_USE_LIBCXX) |
238 | 270 |
271 set(EXTRA_CXX_FLAGS "") | |
272 if (WIN32 AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") | |
273 # Clang on Windows fails to compile the regex feature check under C++11 | |
274 set(EXTRA_CXX_FLAGS "-DCMAKE_CXX_STANDARD=14") | |
275 endif() | |
276 | |
239 # C++ feature checks | 277 # C++ feature checks |
240 # Determine the correct regular expression engine to use | 278 # Determine the correct regular expression engine to use |
241 cxx_feature_check(STD_REGEX) | 279 cxx_feature_check(STD_REGEX ${EXTRA_CXX_FLAGS}) |
242 cxx_feature_check(GNU_POSIX_REGEX) | 280 cxx_feature_check(GNU_POSIX_REGEX ${EXTRA_CXX_FLAGS}) |
243 cxx_feature_check(POSIX_REGEX) | 281 cxx_feature_check(POSIX_REGEX ${EXTRA_CXX_FLAGS}) |
244 if(NOT HAVE_STD_REGEX AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX) | 282 if(NOT HAVE_STD_REGEX AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX) |
245 message(FATAL_ERROR "Failed to determine the source files for the regular expression backend") | 283 message(FATAL_ERROR "Failed to determine the source files for the regular expression backend") |
246 endif() | 284 endif() |
247 if (NOT BENCHMARK_ENABLE_EXCEPTIONS AND HAVE_STD_REGEX | 285 if (NOT BENCHMARK_ENABLE_EXCEPTIONS AND HAVE_STD_REGEX |
248 AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX) | 286 AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX) |
249 message(WARNING "Using std::regex with exceptions disabled is not fully supported") | 287 message(WARNING "Using std::regex with exceptions disabled is not fully supported") |
250 endif() | 288 endif() |
289 | |
251 cxx_feature_check(STEADY_CLOCK) | 290 cxx_feature_check(STEADY_CLOCK) |
252 # Ensure we have pthreads | 291 # Ensure we have pthreads |
292 set(THREADS_PREFER_PTHREAD_FLAG ON) | |
253 find_package(Threads REQUIRED) | 293 find_package(Threads REQUIRED) |
294 | |
295 if (BENCHMARK_ENABLE_LIBPFM) | |
296 find_package(PFM) | |
297 endif() | |
254 | 298 |
255 # Set up directories | 299 # Set up directories |
256 include_directories(${PROJECT_SOURCE_DIR}/include) | 300 include_directories(${PROJECT_SOURCE_DIR}/include) |
257 | 301 |
258 # Build the targets | 302 # Build the targets |
259 add_subdirectory(src) | 303 add_subdirectory(src) |
260 | 304 |
261 if (BENCHMARK_ENABLE_TESTING) | 305 if (BENCHMARK_ENABLE_TESTING) |
262 enable_testing() | 306 enable_testing() |
263 if (BENCHMARK_ENABLE_GTEST_TESTS) | 307 if (BENCHMARK_ENABLE_GTEST_TESTS AND |
264 include(HandleGTest) | 308 NOT (TARGET gtest AND TARGET gtest_main AND |
309 TARGET gmock AND TARGET gmock_main)) | |
310 include(GoogleTest) | |
265 endif() | 311 endif() |
266 add_subdirectory(test) | 312 add_subdirectory(test) |
267 endif() | 313 endif() |