Dominic Hamon | 13b8bdc | 2019-05-01 09:06:12 +0100 | [diff] [blame] | 1 | cmake_minimum_required (VERSION 3.5.1) |
Eric Fiselier | cb8a0cc | 2017-05-03 23:43:16 -0600 | [diff] [blame] | 2 | |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 3 | foreach(p |
Reid Kleckner | dc10645 | 2018-12-30 09:46:07 -0800 | [diff] [blame] | 4 | CMP0048 # OK to clear PROJECT_VERSION on project() |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 5 | CMP0054 # CMake 3.1 |
Steve Downey | 2149577 | 2016-07-06 15:36:56 -0400 | [diff] [blame] | 6 | CMP0056 # export EXE_LINKER_FLAGS to try_run |
Eric | 7db02be | 2017-12-13 16:26:47 -0700 | [diff] [blame] | 7 | CMP0057 # Support no if() IN_LIST operator |
Joseph Loser | 3bc802e | 2019-04-05 04:43:47 -0600 | [diff] [blame] | 8 | CMP0063 # Honor visibility properties for all targets |
Alex Reinking | e5ea03c | 2020-01-31 02:16:25 -0800 | [diff] [blame] | 9 | CMP0077 # Allow option() overrides in importing projects |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 10 | ) |
| 11 | if(POLICY ${p}) |
| 12 | cmake_policy(SET ${p} NEW) |
| 13 | endif() |
| 14 | endforeach() |
| 15 | |
MichaĆ Janiszewski | 12c978c | 2019-05-10 18:56:08 +0200 | [diff] [blame] | 16 | project (benchmark CXX) |
Reid Kleckner | dc10645 | 2018-12-30 09:46:07 -0800 | [diff] [blame] | 17 | |
Eric Fiselier | 5b41e12 | 2015-03-06 12:35:00 -0500 | [diff] [blame] | 18 | option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON) |
Eric | efd4e99 | 2016-12-05 10:24:09 -0700 | [diff] [blame] | 19 | option(BENCHMARK_ENABLE_EXCEPTIONS "Enable the use of exceptions in the benchmark library." ON) |
Matt Clarkson | bb23a9b | 2015-04-30 14:10:52 +0100 | [diff] [blame] | 20 | option(BENCHMARK_ENABLE_LTO "Enable link time optimisation of the benchmark library." OFF) |
Eric | 6e25917 | 2016-08-29 12:43:30 -0600 | [diff] [blame] | 21 | option(BENCHMARK_USE_LIBCXX "Build and test using libc++ as the standard library." OFF) |
Michael "Croydon" Keck | a0018c3 | 2018-08-29 13:51:20 +0200 | [diff] [blame] | 22 | if(NOT MSVC) |
| 23 | option(BENCHMARK_BUILD_32_BITS "Build a 32 bit version of the library." OFF) |
| 24 | else() |
| 25 | set(BENCHMARK_BUILD_32_BITS OFF CACHE BOOL "Build a 32 bit version of the library - unsupported when using MSVC)" FORCE) |
| 26 | endif() |
Yangqing Jia | 491360b | 2017-10-20 13:49:37 -0700 | [diff] [blame] | 27 | option(BENCHMARK_ENABLE_INSTALL "Enable installation of benchmark. (Projects embedding benchmark may want to turn this OFF.)" ON) |
Eric | 0dbcdf5 | 2017-03-28 01:43:42 -0600 | [diff] [blame] | 28 | |
Eric | 7db02be | 2017-12-13 16:26:47 -0700 | [diff] [blame] | 29 | # Allow unmet dependencies to be met using CMake's ExternalProject mechanics, which |
| 30 | # may require downloading the source code. |
| 31 | option(BENCHMARK_DOWNLOAD_DEPENDENCIES "Allow the downloading and in-tree building of unmet dependencies" OFF) |
| 32 | |
| 33 | # This option can be used to disable building and running unit tests which depend on gtest |
| 34 | # in cases where it is not possible to build or find a valid version of gtest. |
| 35 | option(BENCHMARK_ENABLE_GTEST_TESTS "Enable building the unit tests which depend on gtest" ON) |
| 36 | |
Kyle Edwards | d16ae64 | 2019-10-23 04:13:40 -0400 | [diff] [blame] | 37 | set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) |
Eric | 7b03df7 | 2018-03-23 16:10:47 -0600 | [diff] [blame] | 38 | set(ENABLE_ASSEMBLY_TESTS_DEFAULT OFF) |
| 39 | function(should_enable_assembly_tests) |
| 40 | if(CMAKE_BUILD_TYPE) |
| 41 | string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER) |
| 42 | if (${CMAKE_BUILD_TYPE_LOWER} MATCHES "coverage") |
| 43 | # FIXME: The --coverage flag needs to be removed when building assembly |
| 44 | # tests for this to work. |
| 45 | return() |
| 46 | endif() |
| 47 | endif() |
| 48 | if (MSVC) |
| 49 | return() |
| 50 | elseif(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") |
| 51 | return() |
| 52 | elseif(NOT CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 53 | # FIXME: Make these work on 32 bit builds |
| 54 | return() |
| 55 | elseif(BENCHMARK_BUILD_32_BITS) |
| 56 | # FIXME: Make these work on 32 bit builds |
| 57 | return() |
| 58 | endif() |
| 59 | find_program(LLVM_FILECHECK_EXE FileCheck) |
| 60 | if (LLVM_FILECHECK_EXE) |
| 61 | set(LLVM_FILECHECK_EXE "${LLVM_FILECHECK_EXE}" CACHE PATH "llvm filecheck" FORCE) |
| 62 | message(STATUS "LLVM FileCheck Found: ${LLVM_FILECHECK_EXE}") |
| 63 | else() |
| 64 | message(STATUS "Failed to find LLVM FileCheck") |
| 65 | return() |
| 66 | endif() |
| 67 | set(ENABLE_ASSEMBLY_TESTS_DEFAULT ON PARENT_SCOPE) |
| 68 | endfunction() |
| 69 | should_enable_assembly_tests() |
| 70 | |
| 71 | # This option disables the building and running of the assembly verification tests |
| 72 | option(BENCHMARK_ENABLE_ASSEMBLY_TESTS "Enable building and running the assembly tests" |
| 73 | ${ENABLE_ASSEMBLY_TESTS_DEFAULT}) |
| 74 | |
Matt Clarkson | c927845 | 2014-08-01 15:00:43 +0100 | [diff] [blame] | 75 | # Make sure we can import out CMake functions |
Roman Lebedev | c45f018 | 2017-11-29 23:48:43 +0300 | [diff] [blame] | 76 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules") |
Matt Clarkson | c927845 | 2014-08-01 15:00:43 +0100 | [diff] [blame] | 77 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 78 | |
Eric | 7b03df7 | 2018-03-23 16:10:47 -0600 | [diff] [blame] | 79 | |
Matt Clarkson | d591edf | 2014-07-30 20:12:04 +0100 | [diff] [blame] | 80 | # Read the git tags to determine the project version |
Matt Clarkson | c927845 | 2014-08-01 15:00:43 +0100 | [diff] [blame] | 81 | include(GetGitVersion) |
| 82 | get_git_version(GIT_VERSION) |
Matt Clarkson | d591edf | 2014-07-30 20:12:04 +0100 | [diff] [blame] | 83 | |
| 84 | # Tell the user what versions we are using |
Matt Clarkson | d591edf | 2014-07-30 20:12:04 +0100 | [diff] [blame] | 85 | string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" VERSION ${GIT_VERSION}) |
Dominic Hamon | bb15a4e | 2018-11-13 09:56:22 +0000 | [diff] [blame] | 86 | message(STATUS "Version: ${VERSION}") |
Matt Clarkson | d591edf | 2014-07-30 20:12:04 +0100 | [diff] [blame] | 87 | |
Matt Clarkson | 57fdf38 | 2014-07-30 16:59:14 +0100 | [diff] [blame] | 88 | # The version of the libraries |
Matt Clarkson | d591edf | 2014-07-30 20:12:04 +0100 | [diff] [blame] | 89 | set(GENERIC_LIB_VERSION ${VERSION}) |
| 90 | string(SUBSTRING ${VERSION} 0 1 GENERIC_LIB_SOVERSION) |
Matt Clarkson | 57fdf38 | 2014-07-30 16:59:14 +0100 | [diff] [blame] | 91 | |
Matt Clarkson | 3314aa4 | 2015-04-30 14:40:37 +0100 | [diff] [blame] | 92 | # Import our CMake modules |
Eric Fiselier | 5b41e12 | 2015-03-06 12:35:00 -0500 | [diff] [blame] | 93 | include(CheckCXXCompilerFlag) |
| 94 | include(AddCXXCompilerFlag) |
Matt Clarkson | edfa60a | 2014-07-31 15:20:20 +0100 | [diff] [blame] | 95 | include(CXXFeatureCheck) |
Eric Fiselier | 5b41e12 | 2015-03-06 12:35:00 -0500 | [diff] [blame] | 96 | |
Eric | 0dbcdf5 | 2017-03-28 01:43:42 -0600 | [diff] [blame] | 97 | if (BENCHMARK_BUILD_32_BITS) |
| 98 | add_required_cxx_compiler_flag(-m32) |
| 99 | endif() |
| 100 | |
Roman Lebedev | f274c50 | 2018-09-10 23:30:40 +0300 | [diff] [blame] | 101 | if (MSVC) |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 102 | # Turn compiler warnings up to 11 |
Billy Robert O'Neal III | 60b5921 | 2016-04-27 18:44:39 -0700 | [diff] [blame] | 103 | string(REGEX REPLACE "[-/]W[1-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 104 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 105 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
Matt Clarkson | bb23a9b | 2015-04-30 14:10:52 +0100 | [diff] [blame] | 106 | |
Eric | efd4e99 | 2016-12-05 10:24:09 -0700 | [diff] [blame] | 107 | if (NOT BENCHMARK_ENABLE_EXCEPTIONS) |
| 108 | add_cxx_compiler_flag(-EHs-) |
| 109 | add_cxx_compiler_flag(-EHa-) |
Kirill Bobyrev | a9b31c5 | 2018-11-02 19:03:49 +0300 | [diff] [blame] | 110 | add_definitions(-D_HAS_EXCEPTIONS=0) |
Eric | efd4e99 | 2016-12-05 10:24:09 -0700 | [diff] [blame] | 111 | endif() |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 112 | # Link time optimisation |
| 113 | if (BENCHMARK_ENABLE_LTO) |
Billy Robert O'Neal III | 9bb1ba6 | 2016-04-27 18:47:03 -0700 | [diff] [blame] | 114 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL") |
| 115 | set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /LTCG") |
| 116 | set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG") |
| 117 | set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") |
Billy Robert O'Neal III | d89ab07 | 2016-04-27 18:48:43 -0700 | [diff] [blame] | 118 | |
| 119 | set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /GL") |
| 120 | string(REGEX REPLACE "[-/]INCREMENTAL" "/INCREMENTAL:NO" CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO}") |
| 121 | set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO} /LTCG") |
| 122 | string(REGEX REPLACE "[-/]INCREMENTAL" "/INCREMENTAL:NO" CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}") |
| 123 | set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /LTCG") |
| 124 | string(REGEX REPLACE "[-/]INCREMENTAL" "/INCREMENTAL:NO" CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}") |
| 125 | set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG") |
| 126 | |
| 127 | set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /GL") |
| 128 | set(CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL "${CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL} /LTCG") |
| 129 | set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL} /LTCG") |
| 130 | set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} /LTCG") |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 131 | endif() |
| 132 | else() |
| 133 | # Try and enable C++11. Don't use C++14 because it doesn't work in some |
| 134 | # configurations. |
| 135 | add_cxx_compiler_flag(-std=c++11) |
| 136 | if (NOT HAVE_CXX_FLAG_STD_CXX11) |
| 137 | add_cxx_compiler_flag(-std=c++0x) |
| 138 | endif() |
| 139 | |
| 140 | # Turn compiler warnings up to 11 |
| 141 | add_cxx_compiler_flag(-Wall) |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 142 | add_cxx_compiler_flag(-Wextra) |
| 143 | add_cxx_compiler_flag(-Wshadow) |
| 144 | add_cxx_compiler_flag(-Werror RELEASE) |
Billy Robert O'Neal III | 09edc48 | 2016-04-27 18:49:17 -0700 | [diff] [blame] | 145 | add_cxx_compiler_flag(-Werror RELWITHDEBINFO) |
| 146 | add_cxx_compiler_flag(-Werror MINSIZEREL) |
Dominic Hamon | 5ac80de | 2020-01-30 13:29:17 +0000 | [diff] [blame] | 147 | # Disabled until googletest (gmock) stops emitting variadic macro warnings |
| 148 | #add_cxx_compiler_flag(-pedantic) |
| 149 | #add_cxx_compiler_flag(-pedantic-errors) |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 150 | add_cxx_compiler_flag(-Wshorten-64-to-32) |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 151 | add_cxx_compiler_flag(-fstrict-aliasing) |
Eric | 7b8d024 | 2018-05-29 06:25:32 -0600 | [diff] [blame] | 152 | # Disable warnings regarding deprecated parts of the library while building |
| 153 | # and testing those parts of the library. |
| 154 | add_cxx_compiler_flag(-Wno-deprecated-declarations) |
Federico Ficarelli | 0c21bc3 | 2018-07-09 12:45:10 +0200 | [diff] [blame] | 155 | if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") |
| 156 | # Intel silently ignores '-Wno-deprecated-declarations', |
| 157 | # warning no. 1786 must be explicitly disabled. |
| 158 | # See #631 for rationale. |
| 159 | add_cxx_compiler_flag(-wd1786) |
| 160 | endif() |
Dominic Hamon | 151ead6 | 2018-06-07 12:54:14 +0100 | [diff] [blame] | 161 | # Disable deprecation warnings for release builds (when -Werror is enabled). |
| 162 | add_cxx_compiler_flag(-Wno-deprecated RELEASE) |
| 163 | add_cxx_compiler_flag(-Wno-deprecated RELWITHDEBINFO) |
| 164 | add_cxx_compiler_flag(-Wno-deprecated MINSIZEREL) |
Eric | efd4e99 | 2016-12-05 10:24:09 -0700 | [diff] [blame] | 165 | if (NOT BENCHMARK_ENABLE_EXCEPTIONS) |
| 166 | add_cxx_compiler_flag(-fno-exceptions) |
| 167 | endif() |
Eric | 7db02be | 2017-12-13 16:26:47 -0700 | [diff] [blame] | 168 | |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 169 | if (HAVE_CXX_FLAG_FSTRICT_ALIASING) |
rolandschulz | 9b92ed7 | 2017-03-27 17:30:54 -0700 | [diff] [blame] | 170 | if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel") #ICC17u2: Many false positives for Wstrict-aliasing |
| 171 | add_cxx_compiler_flag(-Wstrict-aliasing) |
| 172 | endif() |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 173 | endif() |
rolandschulz | 9b92ed7 | 2017-03-27 17:30:54 -0700 | [diff] [blame] | 174 | # ICC17u2: overloaded virtual function "benchmark::Fixture::SetUp" is only partially overridden |
| 175 | # (because of deprecated overload) |
Kirill Bobyrev | a9b31c5 | 2018-11-02 19:03:49 +0300 | [diff] [blame] | 176 | add_cxx_compiler_flag(-wd654) |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 177 | add_cxx_compiler_flag(-Wthread-safety) |
Eric | cba945e | 2016-09-02 21:34:34 -0600 | [diff] [blame] | 178 | if (HAVE_CXX_FLAG_WTHREAD_SAFETY) |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 179 | cxx_feature_check(THREAD_SAFETY_ATTRIBUTES) |
| 180 | endif() |
| 181 | |
Eric Fiselier | f67ee4a | 2016-10-08 01:03:23 -0600 | [diff] [blame] | 182 | # On most UNIX like platforms g++ and clang++ define _GNU_SOURCE as a |
| 183 | # predefined macro, which turns on all of the wonderful libc extensions. |
| 184 | # However g++ doesn't do this in Cygwin so we have to define it ourselfs |
| 185 | # since we depend on GNU/POSIX/BSD extensions. |
| 186 | if (CYGWIN) |
| 187 | add_definitions(-D_GNU_SOURCE=1) |
| 188 | endif() |
| 189 | |
Jilin Zhou | 0ae233a | 2019-02-19 08:05:55 -0500 | [diff] [blame] | 190 | if (QNXNTO) |
| 191 | add_definitions(-D_QNX_SOURCE) |
| 192 | endif() |
| 193 | |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 194 | # Link time optimisation |
| 195 | if (BENCHMARK_ENABLE_LTO) |
| 196 | add_cxx_compiler_flag(-flto) |
Dominic Hamon | 7fa6f1f | 2020-11-23 10:02:33 +0000 | [diff] [blame] | 197 | add_cxx_compiler_flag(-Wno-lto-type-mismatch) |
Roman Lebedev | 2e7203a | 2019-05-11 18:56:57 +0300 | [diff] [blame] | 198 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 199 | find_program(GCC_AR gcc-ar) |
| 200 | if (GCC_AR) |
| 201 | set(CMAKE_AR ${GCC_AR}) |
| 202 | endif() |
| 203 | find_program(GCC_RANLIB gcc-ranlib) |
| 204 | if (GCC_RANLIB) |
| 205 | set(CMAKE_RANLIB ${GCC_RANLIB}) |
| 206 | endif() |
Roman Lebedev | 2e7203a | 2019-05-11 18:56:57 +0300 | [diff] [blame] | 207 | elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |
Roman Lebedev | c45f018 | 2017-11-29 23:48:43 +0300 | [diff] [blame] | 208 | include(llvm-toolchain) |
Matt Clarkson | bb23a9b | 2015-04-30 14:10:52 +0100 | [diff] [blame] | 209 | endif() |
| 210 | endif() |
Matt Clarkson | bb23a9b | 2015-04-30 14:10:52 +0100 | [diff] [blame] | 211 | |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 212 | # Coverage build type |
Roman Lebedev | 6e06648 | 2017-08-29 02:10:19 +0300 | [diff] [blame] | 213 | set(BENCHMARK_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG}" |
| 214 | CACHE STRING "Flags used by the C++ compiler during coverage builds." |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 215 | FORCE) |
Roman Lebedev | 6e06648 | 2017-08-29 02:10:19 +0300 | [diff] [blame] | 216 | set(BENCHMARK_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" |
| 217 | CACHE STRING "Flags used for linking binaries during coverage builds." |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 218 | FORCE) |
Roman Lebedev | 6e06648 | 2017-08-29 02:10:19 +0300 | [diff] [blame] | 219 | set(BENCHMARK_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" |
| 220 | CACHE STRING "Flags used by the shared libraries linker during coverage builds." |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 221 | FORCE) |
| 222 | mark_as_advanced( |
Roman Lebedev | 6e06648 | 2017-08-29 02:10:19 +0300 | [diff] [blame] | 223 | BENCHMARK_CXX_FLAGS_COVERAGE |
| 224 | BENCHMARK_EXE_LINKER_FLAGS_COVERAGE |
| 225 | BENCHMARK_SHARED_LINKER_FLAGS_COVERAGE) |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 226 | set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING |
Roman Lebedev | 6e06648 | 2017-08-29 02:10:19 +0300 | [diff] [blame] | 227 | "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage.") |
Arkadiy Shapkin | 9e37d69 | 2016-02-09 01:48:19 +0300 | [diff] [blame] | 228 | add_cxx_compiler_flag(--coverage COVERAGE) |
| 229 | endif() |
Matt Clarkson | 36c1eb6 | 2015-04-30 14:28:04 +0100 | [diff] [blame] | 230 | |
Eric | 6e25917 | 2016-08-29 12:43:30 -0600 | [diff] [blame] | 231 | if (BENCHMARK_USE_LIBCXX) |
Gregorio Litenstein | 9ffb8df | 2018-10-05 12:44:02 -0300 | [diff] [blame] | 232 | if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |
Eric | 6e25917 | 2016-08-29 12:43:30 -0600 | [diff] [blame] | 233 | add_cxx_compiler_flag(-stdlib=libc++) |
| 234 | elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR |
| 235 | "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") |
| 236 | add_cxx_compiler_flag(-nostdinc++) |
Dominic Hamon | bb15a4e | 2018-11-13 09:56:22 +0000 | [diff] [blame] | 237 | message(WARNING "libc++ header path must be manually specified using CMAKE_CXX_FLAGS") |
Eric | 6e25917 | 2016-08-29 12:43:30 -0600 | [diff] [blame] | 238 | # Adding -nodefaultlibs directly to CMAKE_<TYPE>_LINKER_FLAGS will break |
| 239 | # configuration checks such as 'find_package(Threads)' |
| 240 | list(APPEND BENCHMARK_CXX_LINKER_FLAGS -nodefaultlibs) |
| 241 | # -lc++ cannot be added directly to CMAKE_<TYPE>_LINKER_FLAGS because |
| 242 | # linker flags appear before all linker inputs and -lc++ must appear after. |
| 243 | list(APPEND BENCHMARK_CXX_LIBRARIES c++) |
| 244 | else() |
Roman Lebedev | e8ddd90 | 2018-05-08 13:33:37 +0300 | [diff] [blame] | 245 | message(FATAL_ERROR "-DBENCHMARK_USE_LIBCXX:BOOL=ON is not supported for compiler") |
Eric | 6e25917 | 2016-08-29 12:43:30 -0600 | [diff] [blame] | 246 | endif() |
| 247 | endif(BENCHMARK_USE_LIBCXX) |
| 248 | |
Jeremy Ong | 01c0ab7 | 2020-08-27 04:17:19 -0600 | [diff] [blame] | 249 | set(EXTRA_CXX_FLAGS "") |
| 250 | if (WIN32 AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |
| 251 | # Clang on Windows fails to compile the regex feature check under C++11 |
| 252 | set(EXTRA_CXX_FLAGS "-DCMAKE_CXX_STANDARD=14") |
| 253 | endif() |
| 254 | |
Eric Fiselier | 5b41e12 | 2015-03-06 12:35:00 -0500 | [diff] [blame] | 255 | # C++ feature checks |
Eric | d038472 | 2016-09-05 15:48:40 -0600 | [diff] [blame] | 256 | # Determine the correct regular expression engine to use |
Jeremy Ong | 01c0ab7 | 2020-08-27 04:17:19 -0600 | [diff] [blame] | 257 | cxx_feature_check(STD_REGEX ${EXTRA_CXX_FLAGS}) |
| 258 | cxx_feature_check(GNU_POSIX_REGEX ${EXTRA_CXX_FLAGS}) |
| 259 | cxx_feature_check(POSIX_REGEX ${EXTRA_CXX_FLAGS}) |
Eric | d038472 | 2016-09-05 15:48:40 -0600 | [diff] [blame] | 260 | if(NOT HAVE_STD_REGEX AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX) |
| 261 | message(FATAL_ERROR "Failed to determine the source files for the regular expression backend") |
| 262 | endif() |
Eric | efd4e99 | 2016-12-05 10:24:09 -0700 | [diff] [blame] | 263 | if (NOT BENCHMARK_ENABLE_EXCEPTIONS AND HAVE_STD_REGEX |
| 264 | AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX) |
| 265 | message(WARNING "Using std::regex with exceptions disabled is not fully supported") |
| 266 | endif() |
Jeremy Ong | 01c0ab7 | 2020-08-27 04:17:19 -0600 | [diff] [blame] | 267 | |
Eric Fiselier | d3e0671 | 2015-03-26 17:52:28 -0400 | [diff] [blame] | 268 | cxx_feature_check(STEADY_CLOCK) |
Dominic Hamon | 1e0ed3a | 2015-04-03 13:33:54 -0700 | [diff] [blame] | 269 | # Ensure we have pthreads |
Wes McKinney | 7c57133 | 2019-02-19 06:32:11 -0600 | [diff] [blame] | 270 | set(THREADS_PREFER_PTHREAD_FLAG ON) |
Dominic Hamon | 1e0ed3a | 2015-04-03 13:33:54 -0700 | [diff] [blame] | 271 | find_package(Threads REQUIRED) |
| 272 | |
Dominic Hamon | 403f354 | 2013-12-18 16:55:45 -0800 | [diff] [blame] | 273 | # Set up directories |
| 274 | include_directories(${PROJECT_SOURCE_DIR}/include) |
Dominic Hamon | 403f354 | 2013-12-18 16:55:45 -0800 | [diff] [blame] | 275 | |
| 276 | # Build the targets |
Chris Kennelly | e38fde6 | 2014-04-23 00:47:07 -0700 | [diff] [blame] | 277 | add_subdirectory(src) |
Eric Fiselier | 5b41e12 | 2015-03-06 12:35:00 -0500 | [diff] [blame] | 278 | |
| 279 | if (BENCHMARK_ENABLE_TESTING) |
| 280 | enable_testing() |
Shuo Chen | 7d856b0 | 2019-05-01 13:00:10 -0700 | [diff] [blame] | 281 | if (BENCHMARK_ENABLE_GTEST_TESTS AND |
| 282 | NOT (TARGET gtest AND TARGET gtest_main AND |
| 283 | TARGET gmock AND TARGET gmock_main)) |
Roman Lebedev | 4b77194 | 2019-04-30 13:36:29 +0300 | [diff] [blame] | 284 | include(GoogleTest) |
Eric | 7db02be | 2017-12-13 16:26:47 -0700 | [diff] [blame] | 285 | endif() |
Eric Fiselier | 5b41e12 | 2015-03-06 12:35:00 -0500 | [diff] [blame] | 286 | add_subdirectory(test) |
| 287 | endif() |