-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
99 lines (82 loc) · 2.84 KB
/
CMakeLists.txt
File metadata and controls
99 lines (82 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
cmake_minimum_required(VERSION 3.10)
set(CODSPEED_VERSION 1.0.0)
project(codspeed VERSION ${CODSPEED_VERSION} LANGUAGES CXX)
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Add the include directory
include_directories(include)
# Add the library
add_library(codspeed src/codspeed.cpp src/walltime.cpp src/uri.cpp)
# Version
add_compile_definitions(CODSPEED_VERSION="${CODSPEED_VERSION}")
# Specify the include directories for users of the library
target_include_directories(
codspeed
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
)
# Disable valgrind compilation errors
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Disable the old-style-cast warning for the specific target
target_compile_options(codspeed PRIVATE -Wno-old-style-cast)
endif()
execute_process(
COMMAND git rev-parse --show-toplevel
OUTPUT_VARIABLE GIT_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE GIT_COMMAND_RESULT
)
if(NOT GIT_COMMAND_RESULT EQUAL 0)
message(
WARNING
"Failed to determine the git root directory.\
Check that git is in your PATH, and that you are in a git repository.\
Continuing, but codspeed features will not be useable"
)
# Default to user's cmake source directory
set(GIT_ROOT_DIR ${CMAKE_SOURCE_DIR})
endif()
target_compile_definitions(
codspeed
INTERFACE -DCODSPEED_GIT_ROOT_DIR="${GIT_ROOT_DIR}"
)
set(CODSPEED_MODE_ALLOWED_VALUES "OFF" "instrumentation" "walltime")
set(CODSPEED_MODE "OFF" CACHE STRING "Build mode for Codspeed")
set_property(
CACHE CODSPEED_MODE
PROPERTY STRINGS ${CODSPEED_MODE_ALLOWED_VALUES}
)
if(NOT CODSPEED_MODE STREQUAL "OFF")
target_compile_definitions(codspeed INTERFACE -DCODSPEED_ENABLED)
if(NOT CMAKE_BUILD_TYPE)
message(
WARNING
"CMAKE_BUILD_TYPE is not set. Consider setting it to 'RelWithDebInfo'."
)
elseif(NOT CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
message(
WARNING
"CMAKE_BUILD_TYPE is set to '${CMAKE_BUILD_TYPE}', but 'RelWithDebInfo' is recommended."
)
endif()
# Define a preprocessor macro based on the build mode
if(CODSPEED_MODE STREQUAL "instrumentation")
target_compile_definitions(
codspeed
INTERFACE -DCODSPEED_INSTRUMENTATION
)
elseif(CODSPEED_MODE STREQUAL "walltime")
target_compile_definitions(codspeed INTERFACE -DCODSPEED_WALLTIME)
else()
message(
FATAL_ERROR
"Invalid build mode: ${CODSPEED_MODE}. Use one of ${CODSPEED_MODE_ALLOWED_VALUES}."
)
endif()
endif()
message(STATUS "Codspeed mode: ${CODSPEED_MODE}")
option(ENABLE_TESTS "Enable building the unit tests which depend on gtest" OFF)
if(ENABLE_TESTS)
enable_testing()
add_subdirectory(test)
endif()