Skip to content

Allow user to force codspeed root dir value and to install google_benchmark as a system lib #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 40 additions & 13 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,38 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(codspeed INTERFACE -Wno-old-style-cast)
endif()

execute_process(
COMMAND git rev-parse --show-toplevel
OUTPUT_VARIABLE CODSPEED_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE GIT_COMMAND_RESULT
)
# Allow the user to override CODSPEED_ROOT_DIR from the command line
set(CODSPEED_ROOT_DIR "" CACHE PATH "Root directory for Codspeed")

if(NOT CODSPEED_ROOT_DIR)
execute_process(
COMMAND git rev-parse --show-toplevel
OUTPUT_VARIABLE CODSPEED_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE GIT_COMMAND_RESULT
)

if(NOT GIT_COMMAND_RESULT EQUAL 0)
if(GIT_COMMAND_RESULT EQUAL 0)
message(STATUS "Detected Codspeed root directory: ${CODSPEED_ROOT_DIR}")
else()
message(
WARNING
"CODSPEED_ROOT_DIR will default to PWD at runtime as git detection failed."
)
endif()
else()
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"
STATUS
"Using user-specified Codspeed root directory: ${CODSPEED_ROOT_DIR}"
)
# Default to user's cmake source directory
set(CODSPEED_ROOT_DIR ${CMAKE_SOURCE_DIR})
endif()

# Define the CODSPEED_ROOT_DIR macro for the target
target_compile_definitions(
codspeed
PRIVATE -DCODSPEED_ROOT_DIR="${CODSPEED_ROOT_DIR}"
)

message(STATUS "Using codspeed root directory: ${CODSPEED_ROOT_DIR}")

set(CODSPEED_MODE_ALLOWED_VALUES "off" "instrumentation" "walltime")
Expand Down Expand Up @@ -97,6 +107,23 @@ if(NOT CODSPEED_MODE STREQUAL "off")
endif()
endif()

install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include"
DESTINATION /usr/local
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
)

install(
TARGETS codspeed
EXPORT codspeed-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

message(STATUS "Codspeed mode: ${CODSPEED_MODE}")

option(ENABLE_TESTS "Enable building the unit tests which depend on gtest" OFF)
Expand Down
Loading