@@ -17,20 +17,83 @@ add_library(codspeed src/codspeed.cpp src/walltime.cpp src/uri.cpp)
1717# Version
1818add_compile_definitions (CODSPEED_VERSION="${CODSPEED_VERSION} " )
1919
20+ # Specify the include directories for users of the library
21+ target_include_directories (
22+ codspeed
23+ PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include >
24+ )
25+
2026# Disable valgrind compilation errors
2127if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" )
2228 # Disable the old-style-cast warning for the specific target
2329 target_compile_options (codspeed PRIVATE -Wno-old-style-cast)
2430endif ()
2531
26- # Specify the include directories for users of the library
27- target_include_directories (
32+ execute_process (
33+ COMMAND git rev-parse --show-toplevel
34+ OUTPUT_VARIABLE GIT_ROOT_DIR
35+ OUTPUT_STRIP_TRAILING_WHITESPACE
36+ RESULT_VARIABLE GIT_COMMAND_RESULT
37+ )
38+
39+ if (NOT GIT_COMMAND_RESULT EQUAL 0)
40+ message (
41+ WARNING
42+ "Failed to determine the git root directory.\
43+ Check that git is in your PATH, and that you are in a git repository.\
44+ Continuing, but codspeed features will not be useable"
45+ )
46+ # Default to user's cmake source directory
47+ set (GIT_ROOT_DIR ${CMAKE_SOURCE_DIR} )
48+ endif ()
49+
50+ target_compile_definitions (
2851 codspeed
29- PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include >
52+ INTERFACE -DCODSPEED_GIT_ROOT_DIR="${GIT_ROOT_DIR} "
53+ )
54+
55+ set (CODSPEED_MODE_ALLOWED_VALUES "OFF" "instrumentation" "walltime" )
56+ set (CODSPEED_MODE "OFF" CACHE STRING "Build mode for Codspeed" )
57+ set_property (
58+ CACHE CODSPEED_MODE
59+ PROPERTY STRINGS ${CODSPEED_MODE_ALLOWED_VALUES}
3060)
3161
62+ if (NOT CODSPEED_MODE STREQUAL "OFF" )
63+ target_compile_definitions (codspeed INTERFACE -DCODSPEED_ENABLED)
64+
65+ if (NOT CMAKE_BUILD_TYPE )
66+ message (
67+ WARNING
68+ "CMAKE_BUILD_TYPE is not set. Consider setting it to 'RelWithDebInfo'."
69+ )
70+ elseif (NOT CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
71+ message (
72+ WARNING
73+ "CMAKE_BUILD_TYPE is set to '${CMAKE_BUILD_TYPE} ', but 'RelWithDebInfo' is recommended."
74+ )
75+ endif ()
76+
77+ # Define a preprocessor macro based on the build mode
78+ if (CODSPEED_MODE STREQUAL "instrumentation" )
79+ target_compile_definitions (
80+ codspeed
81+ INTERFACE -DCODSPEED_INSTRUMENTATION
82+ )
83+ elseif (CODSPEED_MODE STREQUAL "walltime" )
84+ target_compile_definitions (codspeed INTERFACE -DCODSPEED_WALLTIME)
85+ else ()
86+ message (
87+ FATAL_ERROR
88+ "Invalid build mode: ${CODSPEED_MODE} . Use one of ${CODSPEED_MODE_ALLOWED_VALUES} ."
89+ )
90+ endif ()
91+ endif ()
92+
93+ message (STATUS "Codspeed mode: ${CODSPEED_MODE} " )
94+
3295option (ENABLE_TESTS "Enable building the unit tests which depend on gtest" OFF )
3396if (ENABLE_TESTS)
34- enable_testing ()
97+ enable_testing ()
3598 add_subdirectory (test )
3699endif ()
0 commit comments