Skip to content

Commit 51f2539

Browse files
committed
build: MP_UNITS_DEV_TIME_TRACE CMake option added
1 parent dc847ca commit 51f2539

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,25 @@ cmake_minimum_required(VERSION 3.25)
2424
project(mp-units-dev LANGUAGES CXX)
2525

2626
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
27+
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/src/cmake")
28+
include(CheckCacheVarValues)
2729

2830
set(projectPrefix MP_UNITS_)
2931

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

3442
message(STATUS "${projectPrefix}DEV_BUILD_LA: ${${projectPrefix}DEV_BUILD_LA}")
3543
message(STATUS "${projectPrefix}DEV_IWYU: ${${projectPrefix}DEV_IWYU}")
3644
message(STATUS "${projectPrefix}DEV_CLANG_TIDY: ${${projectPrefix}DEV_CLANG_TIDY}")
45+
message(STATUS "${projectPrefix}DEV_TIME_TRACE: ${${projectPrefix}DEV_TIME_TRACE}")
3746

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

7584
# add unit tests
7685
enable_testing()
77-
7886
add_subdirectory(test)

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ if you want to set up a development environment on your local machine.
107107

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

110+
[`MP_UNITS_DEV_TIME_TRACE`](#MP_UNITS_DEV_TIME_TRACE){ #MP_UNITS_DEV_TIME_TRACE }
111+
112+
:   [:octicons-tag-24: 2.5.0][cmake time-trace support] · :octicons-milestone-24: `NONE`/`ALL`/`MODULES`/`HEADERS` (Default: `NONE`)
113+
114+
Enables compilation performance data collection with `-ftime-trace` for clang compilers.
115+
116+
All our unit tests compile only for headers and never for modules. To allow fair
117+
comparison, `MODULES` and `HEADERS` do not enable the data collection for unit tests.
118+
This means that they affect only the core, systems, and examples.
119+
120+
Please use `ALL` to profile unit tests as well.
121+
122+
[cmake time-trace support]: https://github.com/mpusz/mp-units/releases/tag/v2.5.0
123+
110124

111125
### Building the entire repository
112126

example/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@ function(add_example target)
4242
target_compile_features(${target} PRIVATE cxx_std_20)
4343
target_compile_definitions(${target} PRIVATE ${projectPrefix}MODULES)
4444
target_link_libraries(${target} PRIVATE mp-units::mp-units ${ARGN})
45+
if(${projectPrefix}DEV_TIME_TRACE STREQUAL "MODULES")
46+
target_compile_options(${target} PRIVATE "-ftime-trace")
47+
endif()
4548
endif()
4649

4750
add_executable(${target}-headers ${target}.cpp)
4851
list(TRANSFORM ARGN APPEND "-headers")
4952
target_link_libraries(${target}-headers PRIVATE mp-units::mp-units ${ARGN})
53+
if(${projectPrefix}DEV_TIME_TRACE STREQUAL "HEADERS")
54+
target_compile_options(${target}-headers PRIVATE "-ftime-trace")
55+
endif()
5056
endfunction()
5157

5258
add_example(avg_speed)

example/glide_computer_lib/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@ add_library(glide_computer_lib-headers STATIC glide_computer_lib.cpp include/gli
2424
target_compile_features(glide_computer_lib-headers PUBLIC cxx_std_20)
2525
target_link_libraries(glide_computer_lib-headers PUBLIC mp-units::mp-units example_utils-headers)
2626
target_include_directories(glide_computer_lib-headers PUBLIC include)
27+
if(${projectPrefix}DEV_TIME_TRACE STREQUAL "HEADERS")
28+
target_compile_options(glide_computer_lib-headers PRIVATE "-ftime-trace")
29+
endif()
2730

2831
if(${projectPrefix}BUILD_CXX_MODULES)
2932
add_library(glide_computer_lib STATIC glide_computer_lib.cpp include/glide_computer_lib.h)
3033
target_compile_features(glide_computer_lib PUBLIC cxx_std_20)
3134
target_compile_definitions(glide_computer_lib PUBLIC ${projectPrefix}MODULES)
3235
target_link_libraries(glide_computer_lib PUBLIC mp-units::mp-units example_utils)
3336
target_include_directories(glide_computer_lib PUBLIC include)
37+
38+
if(${projectPrefix}DEV_TIME_TRACE STREQUAL "MODULES")
39+
target_compile_options(glide_computer_lib PRIVATE "-ftime-trace")
40+
endif()
3441
endif()

src/core/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,9 @@ target_compile_definitions(
151151
mp-units-core ${${projectPrefix}TARGET_SCOPE}
152152
${projectPrefix}HOSTED=$<NOT:$<BOOL:${${projectPrefix}API_FREESTANDING}>>
153153
)
154+
155+
if(${projectPrefix}DEV_TIME_TRACE STREQUAL "ALL")
156+
target_compile_options(mp-units-core ${${projectPrefix}TARGET_SCOPE} "-ftime-trace")
157+
elseif(${projectPrefix}DEV_TIME_TRACE STREQUAL "MODULES")
158+
target_compile_options(mp-units-core PRIVATE "-ftime-trace")
159+
endif()

src/systems/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,7 @@ if(NOT ${projectPrefix}API_FREESTANDING)
7171
include/mp-units/systems/si/chrono.h
7272
)
7373
endif()
74+
75+
if(${projectPrefix}DEV_TIME_TRACE STREQUAL "MODULES")
76+
target_compile_options(mp-units-systems PRIVATE "-ftime-trace")
77+
endif()

0 commit comments

Comments
 (0)