2015-04-02 22:24:48 +00:00
|
|
|
cmake_minimum_required (VERSION 2.8.11)
|
2013-12-19 00:55:45 +00:00
|
|
|
project (benchmark)
|
|
|
|
|
2016-02-08 22:48:19 +00:00
|
|
|
foreach(p
|
|
|
|
CMP0054 # CMake 3.1
|
|
|
|
)
|
|
|
|
if(POLICY ${p})
|
|
|
|
cmake_policy(SET ${p} NEW)
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2015-03-06 17:35:00 +00:00
|
|
|
option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON)
|
2015-04-30 13:10:52 +00:00
|
|
|
option(BENCHMARK_ENABLE_LTO "Enable link time optimisation of the benchmark library." OFF)
|
2014-08-01 14:00:43 +00:00
|
|
|
# Make sure we can import out CMake functions
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|
|
|
|
2015-03-06 17:35:00 +00:00
|
|
|
# Read the git tags to determine the project version
|
|
|
|
include(GetGitVersion)
|
|
|
|
get_git_version(GIT_VERSION)
|
|
|
|
|
|
|
|
# Tell the user what versions we are using
|
|
|
|
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" VERSION ${GIT_VERSION})
|
|
|
|
message("-- Version: ${VERSION}")
|
|
|
|
|
|
|
|
# The version of the libraries
|
|
|
|
set(GENERIC_LIB_VERSION ${VERSION})
|
|
|
|
string(SUBSTRING ${VERSION} 0 1 GENERIC_LIB_SOVERSION)
|
2014-04-23 07:48:52 +00:00
|
|
|
|
2015-04-30 13:40:37 +00:00
|
|
|
# Import our CMake modules
|
2014-08-01 13:24:56 +00:00
|
|
|
include(CheckCXXCompilerFlag)
|
2015-03-06 17:35:00 +00:00
|
|
|
include(AddCXXCompilerFlag)
|
|
|
|
include(CXXFeatureCheck)
|
|
|
|
|
2016-02-08 22:48:19 +00:00
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
|
|
|
# Turn compiler warnings up to 11
|
2016-04-28 01:44:39 +00:00
|
|
|
string(REGEX REPLACE "[-/]W[1-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
2016-02-08 22:48:19 +00:00
|
|
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
2015-04-30 13:10:52 +00:00
|
|
|
|
2016-02-08 22:48:19 +00:00
|
|
|
# Link time optimisation
|
|
|
|
if (BENCHMARK_ENABLE_LTO)
|
2016-04-28 01:47:03 +00: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 01:48:43 +00: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-08 22:48:19 +00:00
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
# Try and enable C++11. Don't use C++14 because it doesn't work in some
|
|
|
|
# configurations.
|
|
|
|
add_cxx_compiler_flag(-std=c++11)
|
|
|
|
if (NOT HAVE_CXX_FLAG_STD_CXX11)
|
|
|
|
add_cxx_compiler_flag(-std=c++0x)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Turn compiler warnings up to 11
|
|
|
|
add_cxx_compiler_flag(-Wall)
|
|
|
|
|
|
|
|
add_cxx_compiler_flag(-Wextra)
|
|
|
|
add_cxx_compiler_flag(-Wshadow)
|
|
|
|
add_cxx_compiler_flag(-Werror RELEASE)
|
2016-04-28 01:49:17 +00:00
|
|
|
add_cxx_compiler_flag(-Werror RELWITHDEBINFO)
|
|
|
|
add_cxx_compiler_flag(-Werror MINSIZEREL)
|
2016-02-08 22:48:19 +00:00
|
|
|
add_cxx_compiler_flag(-pedantic)
|
|
|
|
add_cxx_compiler_flag(-pedantic-errors)
|
|
|
|
add_cxx_compiler_flag(-Wshorten-64-to-32)
|
|
|
|
add_cxx_compiler_flag(-Wfloat-equal)
|
|
|
|
add_cxx_compiler_flag(-Wzero-as-null-pointer-constant)
|
|
|
|
add_cxx_compiler_flag(-fstrict-aliasing)
|
|
|
|
if (HAVE_CXX_FLAG_FSTRICT_ALIASING)
|
|
|
|
add_cxx_compiler_flag(-Wstrict-aliasing)
|
|
|
|
endif()
|
|
|
|
add_cxx_compiler_flag(-Wthread-safety)
|
|
|
|
if (HAVE_WTHREAD_SAFETY)
|
|
|
|
add_definitions(-DHAVE_WTHREAD_SAFETY)
|
|
|
|
cxx_feature_check(THREAD_SAFETY_ATTRIBUTES)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Link time optimisation
|
|
|
|
if (BENCHMARK_ENABLE_LTO)
|
|
|
|
add_cxx_compiler_flag(-flto)
|
|
|
|
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
|
|
|
|
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()
|
2015-04-30 13:10:52 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2016-02-08 22:48:19 +00:00
|
|
|
# Coverage build type
|
|
|
|
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
|
|
|
|
"Flags used by the C++ compiler during coverage builds."
|
|
|
|
FORCE)
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
|
|
|
|
"${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING
|
|
|
|
"Flags used for linking binaries during coverage builds."
|
|
|
|
FORCE)
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
|
|
|
|
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING
|
|
|
|
"Flags used by the shared libraries linker during coverage builds."
|
|
|
|
FORCE)
|
|
|
|
mark_as_advanced(
|
|
|
|
CMAKE_CXX_FLAGS_COVERAGE
|
|
|
|
CMAKE_EXE_LINKER_FLAGS_COVERAGE
|
|
|
|
CMAKE_SHARED_LINKER_FLAGS_COVERAGE)
|
|
|
|
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
|
|
|
|
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage."
|
|
|
|
FORCE)
|
|
|
|
add_cxx_compiler_flag(--coverage COVERAGE)
|
|
|
|
endif()
|
2015-04-30 13:28:04 +00:00
|
|
|
|
2014-07-31 14:20:20 +00:00
|
|
|
# C++ feature checks
|
|
|
|
cxx_feature_check(STD_REGEX)
|
|
|
|
cxx_feature_check(GNU_POSIX_REGEX)
|
|
|
|
cxx_feature_check(POSIX_REGEX)
|
2015-03-26 21:52:28 +00:00
|
|
|
cxx_feature_check(STEADY_CLOCK)
|
2014-07-31 14:20:20 +00:00
|
|
|
|
2015-04-03 20:33:54 +00:00
|
|
|
# Ensure we have pthreads
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
|
2013-12-19 00:55:45 +00:00
|
|
|
# Set up directories
|
|
|
|
include_directories(${PROJECT_SOURCE_DIR}/include)
|
|
|
|
|
|
|
|
# Build the targets
|
2014-04-23 07:47:07 +00:00
|
|
|
add_subdirectory(src)
|
2015-03-06 17:35:00 +00:00
|
|
|
|
|
|
|
if (BENCHMARK_ENABLE_TESTING)
|
|
|
|
enable_testing()
|
|
|
|
add_subdirectory(test)
|
|
|
|
endif()
|