2023-02-17 21:38:53 +08:00
|
|
|
# Require CMake 3.10. If available, use the policies up to CMake 3.22.
|
2024-10-24 16:46:02 +08:00
|
|
|
cmake_minimum_required (VERSION 3.13...3.22)
|
2016-02-09 06:48:19 +08:00
|
|
|
|
2024-11-29 00:51:38 +08:00
|
|
|
project (benchmark VERSION 1.9.1 LANGUAGES CXX)
|
2018-12-31 01:46:07 +08:00
|
|
|
|
2015-03-07 01:35:00 +08:00
|
|
|
option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON)
|
2016-12-06 01:24:09 +08:00
|
|
|
option(BENCHMARK_ENABLE_EXCEPTIONS "Enable the use of exceptions in the benchmark library." ON)
|
2015-04-30 21:10:52 +08:00
|
|
|
option(BENCHMARK_ENABLE_LTO "Enable link time optimisation of the benchmark library." OFF)
|
2016-08-30 02:43:30 +08:00
|
|
|
option(BENCHMARK_USE_LIBCXX "Build and test using libc++ as the standard library." OFF)
|
2021-10-18 16:41:25 +08:00
|
|
|
option(BENCHMARK_ENABLE_WERROR "Build Release candidates with -Werror." ON)
|
|
|
|
option(BENCHMARK_FORCE_WERROR "Build Release candidates with -Werror regardless of compiler issues." OFF)
|
|
|
|
|
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "PGI")
|
|
|
|
# PGC++ maybe reporting false positives.
|
|
|
|
set(BENCHMARK_ENABLE_WERROR OFF)
|
|
|
|
endif()
|
2023-03-08 17:50:30 +08:00
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "NVHPC")
|
|
|
|
set(BENCHMARK_ENABLE_WERROR OFF)
|
|
|
|
endif()
|
2021-10-18 16:41:25 +08:00
|
|
|
if(BENCHMARK_FORCE_WERROR)
|
|
|
|
set(BENCHMARK_ENABLE_WERROR ON)
|
|
|
|
endif(BENCHMARK_FORCE_WERROR)
|
|
|
|
|
2023-09-26 19:31:24 +08:00
|
|
|
if(NOT (MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC"))
|
2018-08-29 19:51:20 +08:00
|
|
|
option(BENCHMARK_BUILD_32_BITS "Build a 32 bit version of the library." OFF)
|
|
|
|
else()
|
|
|
|
set(BENCHMARK_BUILD_32_BITS OFF CACHE BOOL "Build a 32 bit version of the library - unsupported when using MSVC)" FORCE)
|
|
|
|
endif()
|
2017-10-21 04:49:37 +08:00
|
|
|
option(BENCHMARK_ENABLE_INSTALL "Enable installation of benchmark. (Projects embedding benchmark may want to turn this OFF.)" ON)
|
2021-10-25 19:32:33 +08:00
|
|
|
option(BENCHMARK_ENABLE_DOXYGEN "Build documentation with Doxygen." OFF)
|
2021-09-09 01:40:25 +08:00
|
|
|
option(BENCHMARK_INSTALL_DOCS "Enable installation of documentation." ON)
|
2017-03-28 15:43:42 +08:00
|
|
|
|
2017-12-14 07:26:47 +08:00
|
|
|
# Allow unmet dependencies to be met using CMake's ExternalProject mechanics, which
|
|
|
|
# may require downloading the source code.
|
|
|
|
option(BENCHMARK_DOWNLOAD_DEPENDENCIES "Allow the downloading and in-tree building of unmet dependencies" OFF)
|
|
|
|
|
|
|
|
# This option can be used to disable building and running unit tests which depend on gtest
|
|
|
|
# in cases where it is not possible to build or find a valid version of gtest.
|
|
|
|
option(BENCHMARK_ENABLE_GTEST_TESTS "Enable building the unit tests which depend on gtest" ON)
|
2021-09-12 23:57:57 +08:00
|
|
|
option(BENCHMARK_USE_BUNDLED_GTEST "Use bundled GoogleTest. If disabled, the find_package(GTest) will be used." ON)
|
2017-12-14 07:26:47 +08:00
|
|
|
|
2021-05-06 20:48:48 +08:00
|
|
|
option(BENCHMARK_ENABLE_LIBPFM "Enable performance counters provided by libpfm" OFF)
|
|
|
|
|
2022-02-14 18:48:53 +08:00
|
|
|
# Export only public symbols
|
|
|
|
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
|
|
|
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
|
|
|
|
|
2023-09-26 19:31:24 +08:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
2021-05-07 21:08:24 +08:00
|
|
|
# As of CMake 3.18, CMAKE_SYSTEM_PROCESSOR is not set properly for MSVC and
|
|
|
|
# cross-compilation (e.g. Host=x86_64, target=aarch64) requires using the
|
|
|
|
# undocumented, but working variable.
|
|
|
|
# See https://gitlab.kitware.com/cmake/cmake/-/issues/15170
|
|
|
|
set(CMAKE_SYSTEM_PROCESSOR ${MSVC_CXX_ARCHITECTURE_ID})
|
|
|
|
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "ARM")
|
|
|
|
set(CMAKE_CROSSCOMPILING TRUE)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
Add tests to verify assembler output -- Fix DoNotOptimize. (#530)
* Add tests to verify assembler output -- Fix DoNotOptimize.
For things like `DoNotOptimize`, `ClobberMemory`, and even `KeepRunning()`,
it is important exactly what assembly they generate. However, we currently
have no way to test this. Instead it must be manually validated every
time a change occurs -- including a change in compiler version.
This patch attempts to introduce a way to test the assembled output automatically.
It's mirrors how LLVM verifies compiler output, and it uses LLVM FileCheck to run
the tests in a similar way.
The tests function by generating the assembly for a test in CMake, and then
using FileCheck to verify the // CHECK lines in the source file are found
in the generated assembly.
Currently, the tests only run on 64-bit x86 systems under GCC and Clang,
and when FileCheck is found on the system.
Additionally, this patch tries to improve the code gen from DoNotOptimize.
This should probably be a separate change, but I needed something to test.
* Disable assembly tests on Bazel for now
* Link FIXME to github issue
* Fix Tests on OS X
* fix strip_asm.py to work on both Linux and OS X like targets
2018-03-24 06:10:47 +08:00
|
|
|
set(ENABLE_ASSEMBLY_TESTS_DEFAULT OFF)
|
|
|
|
function(should_enable_assembly_tests)
|
|
|
|
if(CMAKE_BUILD_TYPE)
|
|
|
|
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
|
|
|
|
if (${CMAKE_BUILD_TYPE_LOWER} MATCHES "coverage")
|
|
|
|
# FIXME: The --coverage flag needs to be removed when building assembly
|
|
|
|
# tests for this to work.
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
endif()
|
2023-09-26 19:31:24 +08:00
|
|
|
if (MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
|
Add tests to verify assembler output -- Fix DoNotOptimize. (#530)
* Add tests to verify assembler output -- Fix DoNotOptimize.
For things like `DoNotOptimize`, `ClobberMemory`, and even `KeepRunning()`,
it is important exactly what assembly they generate. However, we currently
have no way to test this. Instead it must be manually validated every
time a change occurs -- including a change in compiler version.
This patch attempts to introduce a way to test the assembled output automatically.
It's mirrors how LLVM verifies compiler output, and it uses LLVM FileCheck to run
the tests in a similar way.
The tests function by generating the assembly for a test in CMake, and then
using FileCheck to verify the // CHECK lines in the source file are found
in the generated assembly.
Currently, the tests only run on 64-bit x86 systems under GCC and Clang,
and when FileCheck is found on the system.
Additionally, this patch tries to improve the code gen from DoNotOptimize.
This should probably be a separate change, but I needed something to test.
* Disable assembly tests on Bazel for now
* Link FIXME to github issue
* Fix Tests on OS X
* fix strip_asm.py to work on both Linux and OS X like targets
2018-03-24 06:10:47 +08:00
|
|
|
return()
|
|
|
|
elseif(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
|
|
|
|
return()
|
|
|
|
elseif(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
|
|
|
|
# FIXME: Make these work on 32 bit builds
|
|
|
|
return()
|
|
|
|
elseif(BENCHMARK_BUILD_32_BITS)
|
|
|
|
# FIXME: Make these work on 32 bit builds
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
find_program(LLVM_FILECHECK_EXE FileCheck)
|
|
|
|
if (LLVM_FILECHECK_EXE)
|
|
|
|
set(LLVM_FILECHECK_EXE "${LLVM_FILECHECK_EXE}" CACHE PATH "llvm filecheck" FORCE)
|
|
|
|
message(STATUS "LLVM FileCheck Found: ${LLVM_FILECHECK_EXE}")
|
|
|
|
else()
|
|
|
|
message(STATUS "Failed to find LLVM FileCheck")
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
set(ENABLE_ASSEMBLY_TESTS_DEFAULT ON PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
should_enable_assembly_tests()
|
|
|
|
|
|
|
|
# This option disables the building and running of the assembly verification tests
|
|
|
|
option(BENCHMARK_ENABLE_ASSEMBLY_TESTS "Enable building and running the assembly tests"
|
|
|
|
${ENABLE_ASSEMBLY_TESTS_DEFAULT})
|
|
|
|
|
2014-08-01 22:00:43 +08:00
|
|
|
# Make sure we can import out CMake functions
|
2017-11-30 04:48:43 +08:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
|
2014-08-01 22:00:43 +08:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|
|
|
|
Add tests to verify assembler output -- Fix DoNotOptimize. (#530)
* Add tests to verify assembler output -- Fix DoNotOptimize.
For things like `DoNotOptimize`, `ClobberMemory`, and even `KeepRunning()`,
it is important exactly what assembly they generate. However, we currently
have no way to test this. Instead it must be manually validated every
time a change occurs -- including a change in compiler version.
This patch attempts to introduce a way to test the assembled output automatically.
It's mirrors how LLVM verifies compiler output, and it uses LLVM FileCheck to run
the tests in a similar way.
The tests function by generating the assembly for a test in CMake, and then
using FileCheck to verify the // CHECK lines in the source file are found
in the generated assembly.
Currently, the tests only run on 64-bit x86 systems under GCC and Clang,
and when FileCheck is found on the system.
Additionally, this patch tries to improve the code gen from DoNotOptimize.
This should probably be a separate change, but I needed something to test.
* Disable assembly tests on Bazel for now
* Link FIXME to github issue
* Fix Tests on OS X
* fix strip_asm.py to work on both Linux and OS X like targets
2018-03-24 06:10:47 +08:00
|
|
|
|
2015-03-07 01:35:00 +08:00
|
|
|
# Read the git tags to determine the project version
|
|
|
|
include(GetGitVersion)
|
|
|
|
get_git_version(GIT_VERSION)
|
|
|
|
|
2021-05-21 00:59:29 +08:00
|
|
|
# If no git version can be determined, use the version
|
|
|
|
# from the project() command
|
2024-05-28 18:24:21 +08:00
|
|
|
if ("${GIT_VERSION}" STREQUAL "v0.0.0")
|
2024-01-29 21:15:43 +08:00
|
|
|
set(VERSION "v${benchmark_VERSION}")
|
2021-05-21 00:59:29 +08:00
|
|
|
else()
|
|
|
|
set(VERSION "${GIT_VERSION}")
|
|
|
|
endif()
|
2024-01-29 21:15:43 +08:00
|
|
|
|
|
|
|
# Normalize version: drop "v" prefix, replace first "-" with ".",
|
|
|
|
# drop everything after second "-" (including said "-").
|
|
|
|
string(STRIP ${VERSION} VERSION)
|
|
|
|
if(VERSION MATCHES v[^-]*-)
|
|
|
|
string(REGEX REPLACE "v([^-]*)-([0-9]+)-.*" "\\1.\\2" NORMALIZED_VERSION ${VERSION})
|
|
|
|
else()
|
|
|
|
string(REGEX REPLACE "v(.*)" "\\1" NORMALIZED_VERSION ${VERSION})
|
|
|
|
endif()
|
|
|
|
|
2015-03-07 01:35:00 +08:00
|
|
|
# Tell the user what versions we are using
|
2024-01-29 21:15:43 +08:00
|
|
|
message(STATUS "Google Benchmark version: ${VERSION}, normalized to ${NORMALIZED_VERSION}")
|
2015-03-07 01:35:00 +08:00
|
|
|
|
|
|
|
# The version of the libraries
|
2024-01-29 21:15:43 +08:00
|
|
|
set(GENERIC_LIB_VERSION ${NORMALIZED_VERSION})
|
|
|
|
string(SUBSTRING ${NORMALIZED_VERSION} 0 1 GENERIC_LIB_SOVERSION)
|
2014-04-23 15:48:52 +08:00
|
|
|
|
2015-04-30 21:40:37 +08:00
|
|
|
# Import our CMake modules
|
2015-03-07 01:35:00 +08:00
|
|
|
include(AddCXXCompilerFlag)
|
2022-02-14 18:48:53 +08:00
|
|
|
include(CheckCXXCompilerFlag)
|
2021-10-14 23:06:36 +08:00
|
|
|
include(CheckLibraryExists)
|
2022-02-14 18:48:53 +08:00
|
|
|
include(CXXFeatureCheck)
|
2021-10-14 23:06:36 +08:00
|
|
|
|
|
|
|
check_library_exists(rt shm_open "" HAVE_LIB_RT)
|
2015-03-07 01:35:00 +08:00
|
|
|
|
2017-03-28 15:43:42 +08:00
|
|
|
if (BENCHMARK_BUILD_32_BITS)
|
|
|
|
add_required_cxx_compiler_flag(-m32)
|
|
|
|
endif()
|
|
|
|
|
2024-11-13 21:06:48 +08:00
|
|
|
set(BENCHMARK_CXX_STANDARD 17)
|
2022-09-14 22:11:37 +08:00
|
|
|
|
|
|
|
set(CMAKE_CXX_STANDARD ${BENCHMARK_CXX_STANDARD})
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED YES)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
2018-09-11 04:30:40 +08:00
|
|
|
if (MSVC)
|
2016-02-09 06:48:19 +08:00
|
|
|
# Turn compiler warnings up to 11
|
2016-04-28 09:44:39 +08:00
|
|
|
string(REGEX REPLACE "[-/]W[1-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
2024-09-06 05:28:43 +08:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /MP")
|
2016-02-09 06:48:19 +08:00
|
|
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
2015-04-30 21:10:52 +08:00
|
|
|
|
2024-08-19 11:39:37 +08:00
|
|
|
if(BENCHMARK_ENABLE_WERROR)
|
|
|
|
add_cxx_compiler_flag(-WX)
|
|
|
|
endif()
|
|
|
|
|
2016-12-06 01:24:09 +08:00
|
|
|
if (NOT BENCHMARK_ENABLE_EXCEPTIONS)
|
|
|
|
add_cxx_compiler_flag(-EHs-)
|
|
|
|
add_cxx_compiler_flag(-EHa-)
|
2018-11-03 00:03:49 +08:00
|
|
|
add_definitions(-D_HAS_EXCEPTIONS=0)
|
2016-12-06 01:24:09 +08:00
|
|
|
endif()
|
2016-02-09 06:48:19 +08:00
|
|
|
# Link time optimisation
|
|
|
|
if (BENCHMARK_ENABLE_LTO)
|
2016-04-28 09:47:03 +08:00
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL")
|
|
|
|
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /LTCG")
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG")
|
2016-04-28 09:48:43 +08:00
|
|
|
|
|
|
|
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /GL")
|
|
|
|
string(REGEX REPLACE "[-/]INCREMENTAL" "/INCREMENTAL:NO" CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO}")
|
|
|
|
set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
|
|
|
|
string(REGEX REPLACE "[-/]INCREMENTAL" "/INCREMENTAL:NO" CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}")
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
|
|
|
|
string(REGEX REPLACE "[-/]INCREMENTAL" "/INCREMENTAL:NO" CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
|
|
|
|
|
|
|
|
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /GL")
|
|
|
|
set(CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL "${CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL} /LTCG")
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL} /LTCG")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} /LTCG")
|
2016-02-09 06:48:19 +08:00
|
|
|
endif()
|
|
|
|
else()
|
2024-01-04 18:50:33 +08:00
|
|
|
# Turn on Large-file Support
|
|
|
|
add_definitions(-D_FILE_OFFSET_BITS=64)
|
|
|
|
add_definitions(-D_LARGEFILE64_SOURCE)
|
|
|
|
add_definitions(-D_LARGEFILE_SOURCE)
|
2016-02-09 06:48:19 +08:00
|
|
|
# Turn compiler warnings up to 11
|
|
|
|
add_cxx_compiler_flag(-Wall)
|
|
|
|
add_cxx_compiler_flag(-Wextra)
|
|
|
|
add_cxx_compiler_flag(-Wshadow)
|
2022-03-13 00:05:23 +08:00
|
|
|
add_cxx_compiler_flag(-Wfloat-equal)
|
2023-06-22 06:35:44 +08:00
|
|
|
add_cxx_compiler_flag(-Wold-style-cast)
|
2024-03-07 20:19:56 +08:00
|
|
|
add_cxx_compiler_flag(-Wconversion)
|
2021-10-18 16:41:25 +08:00
|
|
|
if(BENCHMARK_ENABLE_WERROR)
|
2023-02-17 02:54:09 +08:00
|
|
|
add_cxx_compiler_flag(-Werror)
|
2021-10-18 16:41:25 +08:00
|
|
|
endif()
|
2021-05-11 19:56:00 +08:00
|
|
|
if (NOT BENCHMARK_ENABLE_TESTING)
|
|
|
|
# Disable warning when compiling tests as gtest does not use 'override'.
|
|
|
|
add_cxx_compiler_flag(-Wsuggest-override)
|
|
|
|
endif()
|
2021-05-21 16:48:20 +08:00
|
|
|
add_cxx_compiler_flag(-pedantic)
|
|
|
|
add_cxx_compiler_flag(-pedantic-errors)
|
2016-02-09 06:48:19 +08:00
|
|
|
add_cxx_compiler_flag(-Wshorten-64-to-32)
|
|
|
|
add_cxx_compiler_flag(-fstrict-aliasing)
|
2018-05-29 20:25:32 +08:00
|
|
|
# Disable warnings regarding deprecated parts of the library while building
|
|
|
|
# and testing those parts of the library.
|
|
|
|
add_cxx_compiler_flag(-Wno-deprecated-declarations)
|
2023-08-10 17:33:10 +08:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
|
2018-07-09 18:45:10 +08:00
|
|
|
# Intel silently ignores '-Wno-deprecated-declarations',
|
|
|
|
# warning no. 1786 must be explicitly disabled.
|
|
|
|
# See #631 for rationale.
|
|
|
|
add_cxx_compiler_flag(-wd1786)
|
2023-08-10 17:33:10 +08:00
|
|
|
add_cxx_compiler_flag(-fno-finite-math-only)
|
2018-07-09 18:45:10 +08:00
|
|
|
endif()
|
2018-06-07 19:54:14 +08:00
|
|
|
# Disable deprecation warnings for release builds (when -Werror is enabled).
|
2021-10-18 16:41:25 +08:00
|
|
|
if(BENCHMARK_ENABLE_WERROR)
|
2023-02-17 02:54:09 +08:00
|
|
|
add_cxx_compiler_flag(-Wno-deprecated)
|
2021-10-18 16:41:25 +08:00
|
|
|
endif()
|
2016-12-06 01:24:09 +08:00
|
|
|
if (NOT BENCHMARK_ENABLE_EXCEPTIONS)
|
|
|
|
add_cxx_compiler_flag(-fno-exceptions)
|
|
|
|
endif()
|
2017-12-14 07:26:47 +08:00
|
|
|
|
2016-02-09 06:48:19 +08:00
|
|
|
if (HAVE_CXX_FLAG_FSTRICT_ALIASING)
|
2023-08-10 17:33:10 +08:00
|
|
|
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM") #ICC17u2: Many false positives for Wstrict-aliasing
|
2017-03-28 08:30:54 +08:00
|
|
|
add_cxx_compiler_flag(-Wstrict-aliasing)
|
|
|
|
endif()
|
2016-02-09 06:48:19 +08:00
|
|
|
endif()
|
2017-03-28 08:30:54 +08:00
|
|
|
# ICC17u2: overloaded virtual function "benchmark::Fixture::SetUp" is only partially overridden
|
|
|
|
# (because of deprecated overload)
|
2018-11-03 00:03:49 +08:00
|
|
|
add_cxx_compiler_flag(-wd654)
|
2016-02-09 06:48:19 +08:00
|
|
|
add_cxx_compiler_flag(-Wthread-safety)
|
2016-09-03 11:34:34 +08:00
|
|
|
if (HAVE_CXX_FLAG_WTHREAD_SAFETY)
|
2022-08-04 22:33:35 +08:00
|
|
|
cxx_feature_check(THREAD_SAFETY_ATTRIBUTES "-DINCLUDE_DIRECTORIES=${PROJECT_SOURCE_DIR}/include")
|
2016-02-09 06:48:19 +08:00
|
|
|
endif()
|
|
|
|
|
2016-10-08 15:03:23 +08:00
|
|
|
# On most UNIX like platforms g++ and clang++ define _GNU_SOURCE as a
|
|
|
|
# predefined macro, which turns on all of the wonderful libc extensions.
|
2023-01-10 20:25:32 +08:00
|
|
|
# However g++ doesn't do this in Cygwin so we have to define it ourselves
|
2016-10-08 15:03:23 +08:00
|
|
|
# since we depend on GNU/POSIX/BSD extensions.
|
|
|
|
if (CYGWIN)
|
|
|
|
add_definitions(-D_GNU_SOURCE=1)
|
|
|
|
endif()
|
|
|
|
|
2019-02-19 21:05:55 +08:00
|
|
|
if (QNXNTO)
|
|
|
|
add_definitions(-D_QNX_SOURCE)
|
|
|
|
endif()
|
|
|
|
|
2016-02-09 06:48:19 +08:00
|
|
|
# Link time optimisation
|
|
|
|
if (BENCHMARK_ENABLE_LTO)
|
|
|
|
add_cxx_compiler_flag(-flto)
|
2020-11-23 18:02:33 +08:00
|
|
|
add_cxx_compiler_flag(-Wno-lto-type-mismatch)
|
2019-05-11 23:56:57 +08:00
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
2016-02-09 06:48:19 +08:00
|
|
|
find_program(GCC_AR gcc-ar)
|
|
|
|
if (GCC_AR)
|
|
|
|
set(CMAKE_AR ${GCC_AR})
|
|
|
|
endif()
|
|
|
|
find_program(GCC_RANLIB gcc-ranlib)
|
|
|
|
if (GCC_RANLIB)
|
|
|
|
set(CMAKE_RANLIB ${GCC_RANLIB})
|
|
|
|
endif()
|
2019-05-11 23:56:57 +08:00
|
|
|
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
2017-11-30 04:48:43 +08:00
|
|
|
include(llvm-toolchain)
|
2015-04-30 21:10:52 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2016-02-09 06:48:19 +08:00
|
|
|
# Coverage build type
|
2017-08-29 07:10:19 +08:00
|
|
|
set(BENCHMARK_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG}"
|
|
|
|
CACHE STRING "Flags used by the C++ compiler during coverage builds."
|
2016-02-09 06:48:19 +08:00
|
|
|
FORCE)
|
2017-08-29 07:10:19 +08:00
|
|
|
set(BENCHMARK_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_DEBUG}"
|
|
|
|
CACHE STRING "Flags used for linking binaries during coverage builds."
|
2016-02-09 06:48:19 +08:00
|
|
|
FORCE)
|
2017-08-29 07:10:19 +08:00
|
|
|
set(BENCHMARK_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}"
|
|
|
|
CACHE STRING "Flags used by the shared libraries linker during coverage builds."
|
2016-02-09 06:48:19 +08:00
|
|
|
FORCE)
|
|
|
|
mark_as_advanced(
|
2017-08-29 07:10:19 +08:00
|
|
|
BENCHMARK_CXX_FLAGS_COVERAGE
|
|
|
|
BENCHMARK_EXE_LINKER_FLAGS_COVERAGE
|
|
|
|
BENCHMARK_SHARED_LINKER_FLAGS_COVERAGE)
|
2016-02-09 06:48:19 +08:00
|
|
|
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
|
2017-08-29 07:10:19 +08:00
|
|
|
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage.")
|
2016-02-09 06:48:19 +08:00
|
|
|
add_cxx_compiler_flag(--coverage COVERAGE)
|
|
|
|
endif()
|
2015-04-30 21:28:04 +08:00
|
|
|
|
2016-08-30 02:43:30 +08:00
|
|
|
if (BENCHMARK_USE_LIBCXX)
|
2018-10-05 23:44:02 +08:00
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
2016-08-30 02:43:30 +08:00
|
|
|
add_cxx_compiler_flag(-stdlib=libc++)
|
|
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
|
2023-08-10 17:33:10 +08:00
|
|
|
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel" OR
|
|
|
|
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "IntelLLVM")
|
2016-08-30 02:43:30 +08:00
|
|
|
add_cxx_compiler_flag(-nostdinc++)
|
2018-11-13 17:56:22 +08:00
|
|
|
message(WARNING "libc++ header path must be manually specified using CMAKE_CXX_FLAGS")
|
2016-08-30 02:43:30 +08:00
|
|
|
# Adding -nodefaultlibs directly to CMAKE_<TYPE>_LINKER_FLAGS will break
|
|
|
|
# configuration checks such as 'find_package(Threads)'
|
|
|
|
list(APPEND BENCHMARK_CXX_LINKER_FLAGS -nodefaultlibs)
|
|
|
|
# -lc++ cannot be added directly to CMAKE_<TYPE>_LINKER_FLAGS because
|
|
|
|
# linker flags appear before all linker inputs and -lc++ must appear after.
|
|
|
|
list(APPEND BENCHMARK_CXX_LIBRARIES c++)
|
|
|
|
else()
|
2018-05-08 18:33:37 +08:00
|
|
|
message(FATAL_ERROR "-DBENCHMARK_USE_LIBCXX:BOOL=ON is not supported for compiler")
|
2016-08-30 02:43:30 +08:00
|
|
|
endif()
|
|
|
|
endif(BENCHMARK_USE_LIBCXX)
|
|
|
|
|
2020-08-27 18:17:19 +08:00
|
|
|
set(EXTRA_CXX_FLAGS "")
|
|
|
|
if (WIN32 AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
|
|
|
# Clang on Windows fails to compile the regex feature check under C++11
|
|
|
|
set(EXTRA_CXX_FLAGS "-DCMAKE_CXX_STANDARD=14")
|
|
|
|
endif()
|
|
|
|
|
2014-07-31 22:20:20 +08:00
|
|
|
# C++ feature checks
|
2016-09-06 05:48:40 +08:00
|
|
|
# Determine the correct regular expression engine to use
|
2020-08-27 18:17:19 +08:00
|
|
|
cxx_feature_check(STD_REGEX ${EXTRA_CXX_FLAGS})
|
|
|
|
cxx_feature_check(GNU_POSIX_REGEX ${EXTRA_CXX_FLAGS})
|
|
|
|
cxx_feature_check(POSIX_REGEX ${EXTRA_CXX_FLAGS})
|
2016-09-06 05:48:40 +08:00
|
|
|
if(NOT HAVE_STD_REGEX AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX)
|
|
|
|
message(FATAL_ERROR "Failed to determine the source files for the regular expression backend")
|
|
|
|
endif()
|
2016-12-06 01:24:09 +08:00
|
|
|
if (NOT BENCHMARK_ENABLE_EXCEPTIONS AND HAVE_STD_REGEX
|
|
|
|
AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX)
|
|
|
|
message(WARNING "Using std::regex with exceptions disabled is not fully supported")
|
|
|
|
endif()
|
2020-08-27 18:17:19 +08:00
|
|
|
|
2015-03-27 05:52:28 +08:00
|
|
|
cxx_feature_check(STEADY_CLOCK)
|
2015-04-04 04:33:54 +08:00
|
|
|
# Ensure we have pthreads
|
2019-02-19 20:32:11 +08:00
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
2015-04-04 04:33:54 +08:00
|
|
|
find_package(Threads REQUIRED)
|
2023-02-21 19:30:28 +08:00
|
|
|
cxx_feature_check(PTHREAD_AFFINITY)
|
2015-04-04 04:33:54 +08:00
|
|
|
|
2021-04-28 16:25:29 +08:00
|
|
|
if (BENCHMARK_ENABLE_LIBPFM)
|
2024-01-09 23:34:42 +08:00
|
|
|
find_package(PFM REQUIRED)
|
2021-04-28 16:25:29 +08:00
|
|
|
endif()
|
|
|
|
|
2013-12-19 08:55:45 +08:00
|
|
|
# Set up directories
|
|
|
|
include_directories(${PROJECT_SOURCE_DIR}/include)
|
|
|
|
|
|
|
|
# Build the targets
|
2014-04-23 15:47:07 +08:00
|
|
|
add_subdirectory(src)
|
2015-03-07 01:35:00 +08:00
|
|
|
|
|
|
|
if (BENCHMARK_ENABLE_TESTING)
|
|
|
|
enable_testing()
|
2019-05-02 04:00:10 +08:00
|
|
|
if (BENCHMARK_ENABLE_GTEST_TESTS AND
|
|
|
|
NOT (TARGET gtest AND TARGET gtest_main AND
|
|
|
|
TARGET gmock AND TARGET gmock_main))
|
2021-09-12 23:57:57 +08:00
|
|
|
if (BENCHMARK_USE_BUNDLED_GTEST)
|
|
|
|
include(GoogleTest)
|
|
|
|
else()
|
|
|
|
find_package(GTest CONFIG REQUIRED)
|
|
|
|
add_library(gtest ALIAS GTest::gtest)
|
|
|
|
add_library(gtest_main ALIAS GTest::gtest_main)
|
|
|
|
add_library(gmock ALIAS GTest::gmock)
|
|
|
|
add_library(gmock_main ALIAS GTest::gmock_main)
|
|
|
|
endif()
|
2017-12-14 07:26:47 +08:00
|
|
|
endif()
|
2015-03-07 01:35:00 +08:00
|
|
|
add_subdirectory(test)
|
|
|
|
endif()
|