Skip to content

Commit

Permalink
build: MP_UNITS_DEV_TIME_TRACE CMake option added
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Nov 17, 2024
1 parent dc847ca commit 51f2539
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,25 @@ cmake_minimum_required(VERSION 3.25)
project(mp-units-dev LANGUAGES CXX)

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/src/cmake")
include(CheckCacheVarValues)

set(projectPrefix MP_UNITS_)

option(${projectPrefix}DEV_BUILD_LA "Build code depending on the linear algebra library" OFF)
option(${projectPrefix}DEV_IWYU "Enables include-what-you-use" OFF)
option(${projectPrefix}DEV_CLANG_TIDY "Enables clang-tidy" OFF)
set(${projectPrefix}DEV_TIME_TRACE
NONE
CACHE STRING
"Enables `-ftime-trace` for a selected scope: NONE, ALL, MODULES, HEADERS. MODULES and HEADERS do not affect unit tests."
)
check_cache_var_values(DEV_TIME_TRACE NONE ALL MODULES HEADERS)

message(STATUS "${projectPrefix}DEV_BUILD_LA: ${${projectPrefix}DEV_BUILD_LA}")
message(STATUS "${projectPrefix}DEV_IWYU: ${${projectPrefix}DEV_IWYU}")
message(STATUS "${projectPrefix}DEV_CLANG_TIDY: ${${projectPrefix}DEV_CLANG_TIDY}")
message(STATUS "${projectPrefix}DEV_TIME_TRACE: ${${projectPrefix}DEV_TIME_TRACE}")

# make sure that the file is being used as an entry point
include(modern_project_structure)
Expand Down Expand Up @@ -74,5 +83,4 @@ endif()

# add unit tests
enable_testing()

add_subdirectory(test)
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ if you want to set up a development environment on your local machine.

[cmake clang-tidy support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0

[`MP_UNITS_DEV_TIME_TRACE`](#MP_UNITS_DEV_TIME_TRACE){ #MP_UNITS_DEV_TIME_TRACE }

:   [:octicons-tag-24: 2.5.0][cmake time-trace support] · :octicons-milestone-24: `NONE`/`ALL`/`MODULES`/`HEADERS` (Default: `NONE`)

Enables compilation performance data collection with `-ftime-trace` for clang compilers.

All our unit tests compile only for headers and never for modules. To allow fair
comparison, `MODULES` and `HEADERS` do not enable the data collection for unit tests.
This means that they affect only the core, systems, and examples.

Please use `ALL` to profile unit tests as well.

[cmake time-trace support]: https://github.com/mpusz/mp-units/releases/tag/v2.5.0


### Building the entire repository

Expand Down
6 changes: 6 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ function(add_example target)
target_compile_features(${target} PRIVATE cxx_std_20)
target_compile_definitions(${target} PRIVATE ${projectPrefix}MODULES)
target_link_libraries(${target} PRIVATE mp-units::mp-units ${ARGN})
if(${projectPrefix}DEV_TIME_TRACE STREQUAL "MODULES")
target_compile_options(${target} PRIVATE "-ftime-trace")
endif()
endif()

add_executable(${target}-headers ${target}.cpp)
list(TRANSFORM ARGN APPEND "-headers")
target_link_libraries(${target}-headers PRIVATE mp-units::mp-units ${ARGN})
if(${projectPrefix}DEV_TIME_TRACE STREQUAL "HEADERS")
target_compile_options(${target}-headers PRIVATE "-ftime-trace")
endif()
endfunction()

add_example(avg_speed)
Expand Down
7 changes: 7 additions & 0 deletions example/glide_computer_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ add_library(glide_computer_lib-headers STATIC glide_computer_lib.cpp include/gli
target_compile_features(glide_computer_lib-headers PUBLIC cxx_std_20)
target_link_libraries(glide_computer_lib-headers PUBLIC mp-units::mp-units example_utils-headers)
target_include_directories(glide_computer_lib-headers PUBLIC include)
if(${projectPrefix}DEV_TIME_TRACE STREQUAL "HEADERS")
target_compile_options(glide_computer_lib-headers PRIVATE "-ftime-trace")
endif()

if(${projectPrefix}BUILD_CXX_MODULES)
add_library(glide_computer_lib STATIC glide_computer_lib.cpp include/glide_computer_lib.h)
target_compile_features(glide_computer_lib PUBLIC cxx_std_20)
target_compile_definitions(glide_computer_lib PUBLIC ${projectPrefix}MODULES)
target_link_libraries(glide_computer_lib PUBLIC mp-units::mp-units example_utils)
target_include_directories(glide_computer_lib PUBLIC include)

if(${projectPrefix}DEV_TIME_TRACE STREQUAL "MODULES")
target_compile_options(glide_computer_lib PRIVATE "-ftime-trace")
endif()
endif()
6 changes: 6 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,9 @@ target_compile_definitions(
mp-units-core ${${projectPrefix}TARGET_SCOPE}
${projectPrefix}HOSTED=$<NOT:$<BOOL:${${projectPrefix}API_FREESTANDING}>>
)

if(${projectPrefix}DEV_TIME_TRACE STREQUAL "ALL")
target_compile_options(mp-units-core ${${projectPrefix}TARGET_SCOPE} "-ftime-trace")
elseif(${projectPrefix}DEV_TIME_TRACE STREQUAL "MODULES")
target_compile_options(mp-units-core PRIVATE "-ftime-trace")
endif()
4 changes: 4 additions & 0 deletions src/systems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ if(NOT ${projectPrefix}API_FREESTANDING)
include/mp-units/systems/si/chrono.h
)
endif()

if(${projectPrefix}DEV_TIME_TRACE STREQUAL "MODULES")
target_compile_options(mp-units-systems PRIVATE "-ftime-trace")
endif()

0 comments on commit 51f2539

Please sign in to comment.