|
1 | 1 | add_subdirectory(${PROJECT_SOURCE_DIR}/../core codspeed) |
2 | 2 |
|
3 | 3 | execute_process( |
4 | | - COMMAND git rev-parse --show-toplevel |
5 | | - OUTPUT_VARIABLE GIT_ROOT_DIR |
6 | | - OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 4 | + COMMAND git rev-parse --show-toplevel |
| 5 | + OUTPUT_VARIABLE GIT_ROOT_DIR |
| 6 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 7 | + RESULT_VARIABLE GIT_COMMAND_RESULT |
| 8 | +) |
7 | 9 |
|
8 | | -target_compile_definitions(codspeed |
9 | | - INTERFACE -DCODSPEED_GIT_ROOT_DIR="${GIT_ROOT_DIR}") |
| 10 | +if(NOT GIT_COMMAND_RESULT EQUAL 0) |
| 11 | + message( |
| 12 | + WARNING |
| 13 | + "Failed to determine the git root directory.\ |
| 14 | + Check that git is in your PATH, and that you are in a git repository.\ |
| 15 | + Continuing, but codspeed features will not be useable" |
| 16 | + ) |
| 17 | + # Default to user's cmake source directory |
| 18 | + set(GIT_ROOT_DIR ${CMAKE_SOURCE_DIR}) |
| 19 | +endif() |
10 | 20 |
|
11 | | -# Step 1: Check if CODSPEED_MODE is set via the command line |
| 21 | +target_compile_definitions( |
| 22 | + codspeed |
| 23 | + INTERFACE -DCODSPEED_GIT_ROOT_DIR="${GIT_ROOT_DIR}" |
| 24 | +) |
12 | 25 |
|
13 | | -# CMake cache kind of breaks this mechanism, keeping it for first time |
14 | | -# defaulting |
15 | | -if(NOT DEFINED CODSPEED_MODE) |
16 | | - # Step 2: Check the environment variable CODSPEED_MODE |
17 | | - if(DEFINED $ENV{CODSPEED_RUNNER_MODE}) |
18 | | - set(CODSPEED_MODE $ENV{CODSPEED_RUNNER_MODE} FORCE) |
| 26 | +if(DEFINED CODSPEED_MODE) |
| 27 | + # Define a preprocessor macro based on the build mode |
| 28 | + if(CODSPEED_MODE STREQUAL "instrumentation") |
| 29 | + target_compile_definitions( |
| 30 | + codspeed |
| 31 | + INTERFACE -DCODSPEED_INSTRUMENTATION |
| 32 | + ) |
| 33 | + elseif(CODSPEED_MODE STREQUAL "walltime") |
| 34 | + target_compile_definitions(codspeed INTERFACE -DCODSPEED_WALLTIME) |
19 | 35 | else() |
20 | | - # Step 3: Default to "instrumentation" if no value is provided |
21 | | - set(CODSPEED_MODE "instrumentation") |
| 36 | + message( |
| 37 | + FATAL_ERROR |
| 38 | + "Invalid build mode: ${CODSPEED_MODE}. Use 'instrumentation' or 'walltime'." |
| 39 | + ) |
22 | 40 | endif() |
23 | 41 | endif() |
24 | 42 |
|
25 | | -# Define a preprocessor macro based on the build mode |
26 | | -if(CODSPEED_MODE STREQUAL "instrumentation") |
27 | | - target_compile_definitions(codspeed INTERFACE -DCODSPEED_INSTRUMENTATION) |
28 | | -elseif(CODSPEED_MODE STREQUAL "walltime") |
29 | | - target_compile_definitions(codspeed INTERFACE -DCODSPEED_WALLTIME) |
30 | | -else() |
31 | | - message( |
32 | | - FATAL_ERROR |
33 | | - "Invalid build mode: ${CODSPEED_MODE}. Use 'instrumentation' or 'walltime'." |
34 | | - ) |
35 | | -endif() |
36 | | - |
37 | 43 | message(STATUS "Build mode set to: ${CODSPEED_MODE}") |
0 commit comments