Skip to content

Commit 2607a21

Browse files
feat(core): allow user to manually set the root dir
1 parent 93629bb commit 2607a21

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

core/CMakeLists.txt

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,38 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
3535
target_compile_options(codspeed INTERFACE -Wno-old-style-cast)
3636
endif()
3737

38-
execute_process(
39-
COMMAND git rev-parse --show-toplevel
40-
OUTPUT_VARIABLE CODSPEED_ROOT_DIR
41-
OUTPUT_STRIP_TRAILING_WHITESPACE
42-
RESULT_VARIABLE GIT_COMMAND_RESULT
43-
)
38+
# Allow the user to override CODSPEED_ROOT_DIR from the command line
39+
set(CODSPEED_ROOT_DIR "" CACHE PATH "Root directory for Codspeed")
40+
41+
if(NOT CODSPEED_ROOT_DIR)
42+
execute_process(
43+
COMMAND git rev-parse --show-toplevel
44+
OUTPUT_VARIABLE CODSPEED_ROOT_DIR
45+
OUTPUT_STRIP_TRAILING_WHITESPACE
46+
RESULT_VARIABLE GIT_COMMAND_RESULT
47+
)
4448

45-
if(NOT GIT_COMMAND_RESULT EQUAL 0)
49+
if(GIT_COMMAND_RESULT EQUAL 0)
50+
message(STATUS "Detected Codspeed root directory: ${CODSPEED_ROOT_DIR}")
51+
else()
52+
message(
53+
WARNING
54+
"CODSPEED_ROOT_DIR will default to PWD at runtime as git detection failed."
55+
)
56+
endif()
57+
else()
4658
message(
47-
WARNING
48-
"Failed to determine the git root directory.\
49-
Check that git is in your PATH, and that you are in a git repository.\
50-
Continuing, but codspeed features will not be useable"
59+
STATUS
60+
"Using user-specified Codspeed root directory: ${CODSPEED_ROOT_DIR}"
5161
)
52-
# Default to user's cmake source directory
53-
set(CODSPEED_ROOT_DIR ${CMAKE_SOURCE_DIR})
5462
endif()
5563

64+
# Define the CODSPEED_ROOT_DIR macro for the target
5665
target_compile_definitions(
5766
codspeed
5867
PRIVATE -DCODSPEED_ROOT_DIR="${CODSPEED_ROOT_DIR}"
5968
)
69+
6070
message(STATUS "Using codspeed root directory: ${CODSPEED_ROOT_DIR}")
6171

6272
set(CODSPEED_MODE_ALLOWED_VALUES "off" "instrumentation" "walltime")
@@ -99,16 +109,17 @@ endif()
99109

100110
# Install the codspeed.h header
101111
install(
102-
FILES
103-
include/codspeed.h # or wherever codspeed.h is located in core/
104-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/benchmark
105-
# Or possibly: DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
112+
DIRECTORY "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include"
113+
DESTINATION /usr/local
114+
FILES_MATCHING
115+
PATTERN "*.h"
116+
PATTERN "*.hpp"
106117
)
107118

108119
# If there's also a library to install:
109120
install(
110121
TARGETS
111-
codspeed_core # whatever the target name is
122+
codspeed # whatever the target name is
112123
EXPORT codspeed-targets
113124
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
114125
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}

0 commit comments

Comments
 (0)