diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f4fb2e2..711136c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5d7671ed..d3d5d960 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 7c329d4e..ed36e396 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -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) diff --git a/example/glide_computer_lib/CMakeLists.txt b/example/glide_computer_lib/CMakeLists.txt index 54124f1a..cb3f9984 100644 --- a/example/glide_computer_lib/CMakeLists.txt +++ b/example/glide_computer_lib/CMakeLists.txt @@ -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() diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 1f3dc449..31cf8ea7 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -151,3 +151,9 @@ target_compile_definitions( mp-units-core ${${projectPrefix}TARGET_SCOPE} ${projectPrefix}HOSTED=$> ) + +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() diff --git a/src/systems/CMakeLists.txt b/src/systems/CMakeLists.txt index 745c1788..b110b1d9 100644 --- a/src/systems/CMakeLists.txt +++ b/src/systems/CMakeLists.txt @@ -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()