mirror of
https://github.com/mpusz/mp-units.git
synced 2025-06-25 01:01:33 +02:00
build: MP_UNITS_DEV_TIME_TRACE
CMake option added
This commit is contained in:
@ -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)
|
||||
@ -74,5 +83,4 @@ endif()
|
||||
|
||||
# add unit tests
|
||||
enable_testing()
|
||||
|
||||
add_subdirectory(test)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -24,6 +24,9 @@ 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)
|
||||
@ -31,4 +34,8 @@ if(${projectPrefix}BUILD_CXX_MODULES)
|
||||
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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user