Skip to content

Commit 3a50086

Browse files
authored
Merge branch 'master' into feature/faster-CI
2 parents bc440cc + a1d8c4d commit 3a50086

File tree

9 files changed

+137
-53
lines changed

9 files changed

+137
-53
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: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,27 @@
33
👍🎉 First off, thanks for taking the time to contribute! 🎉👍
44

55

6+
## **mp-units** documentation
7+
8+
Before contributing, it is highly recommended to familiarize yourself with our
9+
[official documentation](https://mpusz.github.io/mp-units).
10+
11+
This file is also a part of it, and this is why it has non-standard Markdown formatting (which can
12+
be seen when reading in a regular Markdown renderer). To benefit from full mkdocs rendering, please
13+
switch to the [Contributing](https://mpusz.github.io/mp-units/latest/getting_started/contributing)
14+
chapter of our documentation.
15+
16+
617
## Where to start?
718

819
If you are looking for a good issue to start with, please check the following:
920

1021
- [good first issue](https://github.com/mpusz/mp-units/labels/good%20first%20issue) - issues that
11-
should be pretty simple to implement,
22+
should be pretty simple to implement,
1223
- [help wanted](https://github.com/mpusz/mp-units/labels/help%20wanted) - issues that typically are
13-
a bit more involved than beginner issues,
24+
a bit more involved than beginner issues,
1425
- [high priority](https://github.com/mpusz/mp-units/labels/high%20priority) - things to fix ASAP
15-
but often of higher complexity.
26+
but often of higher complexity.
1627

1728

1829
## Gitpod
@@ -46,28 +57,28 @@ if you want to set up a development environment on your local machine.
4657

4758
[`user.mp-units.build:all`](#user.mp-units.build-all){ #user.mp-units.build-all }
4859

49-
Enables compilation of all the source code, including tests and examples. To support this, it requires some additional Conan build dependencies described in
50-
[Repository directory tree and dependencies](https://mpusz.github.io/mp-units/latest/getting_started/project_structure#cmake-projects-and-dependencies).
51-
It also runs unit tests during the Conan build (unless
52-
[`tools.build:skip_test`](https://docs.conan.io/2/reference/commands/config.html?highlight=tools.build:skip_test#conan-config-list)
53-
configuration property is set to `True`).
60+
: Enables compilation of all the source code, including tests and examples. To support this, it requires some additional Conan build dependencies described in
61+
[Repository directory tree and dependencies](https://mpusz.github.io/mp-units/latest/getting_started/project_structure#cmake-projects-and-dependencies).
62+
It also runs unit tests during the Conan build (unless
63+
[`tools.build:skip_test`](https://docs.conan.io/2/reference/commands/config.html?highlight=tools.build:skip_test#conan-config-list)
64+
configuration property is set to `True`).
5465

55-
[conan build all support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0
66+
[conan build all support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0
5667

5768
[`user.mp-units.build:skip_la`](#user-skip-la){ #user-skip-la }
5869

59-
If `user.mp-units.build:all` is enabled, among others, Conan installs the external
60-
[wg21-linear_algebra](https://conan.io/center/recipes/wg21-linear_algebra)
61-
dependency and enables the compilation of linear algebra-based tests and usage examples.
62-
Such behavior can be disabled with this option.
70+
: If `user.mp-units.build:all` is enabled, among others, Conan installs the external
71+
[wg21-linear_algebra](https://conan.io/center/recipes/wg21-linear_algebra)
72+
dependency and enables the compilation of linear algebra-based tests and usage examples.
73+
Such behavior can be disabled with this option.
6374

64-
[conan skip la support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0
75+
[conan skip la support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0
6576

6677
[`user.mp-units.analyze:clang-tidy`](#user.mp-units.analyze-clang-tidy){ #user.mp-units.analyze-clang-tidy }
6778

68-
Enables clang-tidy analysis.
79+
: Enables clang-tidy analysis.
6980

70-
[conan clang-tidy support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0
81+
[conan clang-tidy support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0
7182

7283

7384
### CMake options for mp-units project developers
@@ -76,25 +87,39 @@ if you want to set up a development environment on your local machine.
7687

7788
:   [:octicons-tag-24: 2.2.0][cmake build la support] · :octicons-milestone-24: `ON`/`OFF` (Default: `ON`)
7889

79-
Enables building code depending on the linear algebra library.
90+
Enables building code depending on the linear algebra library.
8091

81-
[cmake build la support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0
92+
[cmake build la support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0
8293

8394
[`MP_UNITS_DEV_IWYU`](#MP_UNITS_DEV_IWYU){ #MP_UNITS_DEV_IWYU }
8495

8596
:   [:octicons-tag-24: 2.2.0][cmake iwyu support] · :octicons-milestone-24: `ON`/`OFF` (Default: `OFF`)
8697

87-
Enables include-what-you-use analysis.
98+
Enables include-what-you-use analysis.
8899

89-
[cmake iwyu support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0
100+
[cmake iwyu support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0
90101

91102
[`MP_UNITS_DEV_CLANG_TIDY`](#MP_UNITS_DEV_CLANG_TIDY){ #MP_UNITS_DEV_CLANG_TIDY }
92103

93104
:   [:octicons-tag-24: 2.2.0][cmake clang-tidy support] · :octicons-milestone-24: `ON`/`OFF` (Default: `OFF`)
94105

95-
Enables clang-tidy analysis.
106+
Enables clang-tidy analysis.
107+
108+
[cmake clang-tidy support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0
109+
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.
96115

97-
[cmake clang-tidy support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0
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
98123

99124

100125
### Building the entire repository
@@ -105,7 +130,7 @@ To build all the **mp-units** source code (with unit tests and examples), you sh
105130
2. Run Conan with [`user.mp-units.build:all`](#user.mp-units.build-all) = `True`.
106131

107132
```shell
108-
git clone https://github.com/mpusz/mp-units.git && cd units
133+
git clone https://github.com/mpusz/mp-units.git && cd mp-units
109134
conan build . -pr <your_conan_profile> -s compiler.cppstd=23 -c user.mp-units.build:all=True -b missing
110135
```
111136

@@ -167,15 +192,15 @@ After that, you can either:
167192

168193
- easily [start a live server to preview the documentation as you write](https://squidfunk.github.io/mkdocs-material/creating-your-site/#previewing-as-you-write)
169194

170-
```shell
171-
mkdocs serve
172-
```
195+
```shell
196+
mkdocs serve
197+
```
173198

174199
- [build the documentation](https://squidfunk.github.io/mkdocs-material/creating-your-site/#building-your-site)
175200

176-
```shell
177-
mkdocs build
178-
```
201+
```shell
202+
mkdocs build
203+
```
179204

180205
### Generating API reference
181206

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/CMakeLists.txt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ set(projectPrefix MP_UNITS_)
2727

2828
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
2929

30-
include(CheckCXXFeatureSupported)
3130
include(AddMPUnitsModule)
31+
include(CheckCacheVarValues)
32+
include(CheckCXXFeatureSupported)
3233
include(GNUInstallDirs)
3334

3435
# check if libc++ is being used
@@ -77,21 +78,12 @@ option(${projectPrefix}API_NO_CRTP "Enable class definitions without CRTP idiom"
7778
)
7879
option(${projectPrefix}API_FREESTANDING "Builds only freestanding part of the library" OFF)
7980
set(${projectPrefix}API_CONTRACTS GSL-LITE CACHE STRING "Enable contract checking")
81+
check_cache_var_values(API_CONTRACTS NONE GSL-LITE MS-GSL)
8082

8183
message(STATUS "${projectPrefix}API_STD_FORMAT: ${${projectPrefix}API_STD_FORMAT}")
8284
message(STATUS "${projectPrefix}API_NO_CRTP: ${${projectPrefix}API_NO_CRTP}")
8385
message(STATUS "${projectPrefix}API_FREESTANDING: ${${projectPrefix}API_FREESTANDING}")
84-
85-
function(cache_var_values name)
86-
set_property(CACHE ${projectPrefix}${name} PROPERTY STRINGS ${ARGN})
87-
if(NOT ${projectPrefix}${name} IN_LIST ARGN)
88-
message(FATAL_ERROR
89-
"Invalid value '${${projectPrefix}${name}}' provided for a cache variable ${projectPrefix}${name} (${ARGN} allowed)"
90-
)
91-
endif()
92-
message(STATUS "${projectPrefix}${name}: ${${projectPrefix}${name}}")
93-
endfunction()
94-
cache_var_values(API_CONTRACTS NONE GSL-LITE MS-GSL)
86+
message(STATUS "${projectPrefix}API_CONTRACTS: ${${projectPrefix}API_CONTRACTS}")
9587

9688
# validate options
9789
if(${projectPrefix}API_FREESTANDING AND NOT ${projectPrefix}API_CONTRACTS STREQUAL "NONE")

src/cmake/CheckCacheVarValues.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2018 Mateusz Pusz
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
cmake_minimum_required(VERSION 3.25)
24+
25+
function(check_cache_var_values name)
26+
set_property(CACHE ${projectPrefix}${name} PROPERTY STRINGS ${ARGN})
27+
if(NOT ${projectPrefix}${name} IN_LIST ARGN)
28+
message(FATAL_ERROR
29+
"Invalid value '${${projectPrefix}${name}}' provided for a cache variable ${projectPrefix}${name} (${ARGN} allowed)"
30+
)
31+
endif()
32+
endfunction()

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/core/include/mp-units/framework/unit.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,23 @@ struct get_canonical_unit_result {
120120
inline static constexpr auto value = get_canonical_unit_impl(U{}, U{});
121121
};
122122

123-
template<Unit Lhs, Unit Rhs>
124-
struct unit_less : std::bool_constant<type_name<Lhs>() < type_name<Rhs>()> {};
123+
} // namespace detail
125124

126-
template<typename T1, typename T2>
127-
using type_list_of_unit_less = expr_less<T1, T2, unit_less>;
125+
// TODO this should really be in the `details` namespace but is used in `chrono.h` (a part of mp_units.systems)
126+
// Even though it is not exported, it is visible to the other module via ADL
127+
[[nodiscard]] consteval auto get_canonical_unit(Unit auto u)
128+
{
129+
return detail::get_canonical_unit_result<decltype(u)>::value;
130+
}
131+
132+
namespace detail {
128133

129134
template<typename From, typename To>
130135
concept PotentiallyConvertibleTo = Unit<From> && Unit<To> &&
131136
((AssociatedUnit<From> && AssociatedUnit<To> &&
132137
implicitly_convertible(get_quantity_spec(From{}), get_quantity_spec(To{}))) ||
133138
(!AssociatedUnit<From> && !AssociatedUnit<To>));
134139

135-
} // namespace detail
136-
137-
// TODO this should really be in the `details` namespace but is used in `chrono.h` (a part of mp_units.systems)
138-
// Even though it is not exported, it is visible to the other module via ADL
139-
[[nodiscard]] consteval auto get_canonical_unit(Unit auto u)
140-
{
141-
return detail::get_canonical_unit_result<decltype(u)>::value;
142140
}
143141

144142
// convertible
@@ -159,6 +157,12 @@ struct derived_unit;
159157

160158
namespace detail {
161159

160+
template<Unit Lhs, Unit Rhs>
161+
struct unit_less : std::bool_constant<type_name<Lhs>() < type_name<Rhs>()> {};
162+
163+
template<typename T1, typename T2>
164+
using type_list_of_unit_less = expr_less<T1, T2, unit_less>;
165+
162166
struct unit_interface {
163167
/**
164168
* Multiplication by `1` returns the same unit, otherwise `scaled_unit` is being returned.

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)