From 7cb2099af5c180c473de3a1d2a8b87fa43d70dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johel=20Ernesto=20Guerrero=20Pe=C3=B1a?= Date: Sat, 6 Jan 2024 08:51:00 +0100 Subject: [PATCH 01/33] feat: add module `mp_units` --- conanfile.py | 2 +- example/CMakeLists.txt | 26 +++++---- example/avg_speed.cpp | 12 ++-- example/capacitor_time_curve.cpp | 6 +- example/clcpp_response.cpp | 7 ++- example/conversion_factor.cpp | 9 ++- example/currency.cpp | 9 ++- example/foot_pound_second.cpp | 9 ++- example/glide_computer.cpp | 12 ++-- example/glide_computer_lib/CMakeLists.txt | 7 ++- .../glide_computer_lib/glide_computer_lib.cpp | 6 +- .../include/glide_computer_lib.h | 14 +++-- example/hello_units.cpp | 7 ++- example/include/geographic.h | 12 ++-- example/include/ranged_representation.h | 8 ++- example/include/validated_type.h | 9 ++- example/kalman_filter/CMakeLists.txt | 6 +- example/kalman_filter/kalman.h | 6 +- .../kalman_filter/kalman_filter-example_1.cpp | 8 ++- .../kalman_filter/kalman_filter-example_2.cpp | 8 ++- .../kalman_filter/kalman_filter-example_3.cpp | 8 ++- .../kalman_filter/kalman_filter-example_4.cpp | 8 ++- .../kalman_filter/kalman_filter-example_5.cpp | 8 ++- .../kalman_filter/kalman_filter-example_6.cpp | 8 ++- .../kalman_filter/kalman_filter-example_7.cpp | 8 ++- .../kalman_filter/kalman_filter-example_8.cpp | 8 ++- example/measurement.cpp | 10 +++- example/si_constants.cpp | 7 ++- example/spectroscopy_units.cpp | 9 ++- example/storage_tank.cpp | 16 +++-- example/strong_angular_quantities.cpp | 6 +- example/total_energy.cpp | 26 ++++----- example/unmanned_aerial_vehicle.cpp | 9 ++- src/CMakeLists.txt | 58 +++++++++++++++++++ src/core-fmt-macros/CMakeLists.txt | 45 ++++++++++++++ .../include/mp-units/bits/fmt_hacks.h | 2 + src/core-fmt/CMakeLists.txt | 1 + src/core-macros/CMakeLists.txt | 40 +++++++++++++ .../include/mp-units/bits/core-gmf.h | 50 ++++++++++++++++ .../include/mp-units/bits/external/hacks.h | 0 .../include/mp-units/quantity_spec_macro.h | 37 ++++++++++++ src/core/CMakeLists.txt | 5 +- .../include/mp-units/bits/math_core.h | 0 src/core/include/mp-units/core.h | 1 + src/core/include/mp-units/quantity_spec.h | 15 +---- src/mp-units-core-fmt.cpp | 13 +++++ src/mp-units-core-io.cpp | 13 +++++ src/mp-units-core.cpp | 11 ++++ src/mp-units-systems.cpp | 32 ++++++++++ src/mp-units.cpp | 8 +++ src/utility/include/mp-units/math.h | 4 +- test/unit_test/runtime/CMakeLists.txt | 7 ++- test/unit_test/runtime/almost_equals.h | 7 ++- test/unit_test/runtime/distribution_test.cpp | 12 ++-- test/unit_test/runtime/fmt_test.cpp | 11 +++- .../unit_test/runtime/linear_algebra_test.cpp | 9 ++- test/unit_test/runtime/math_test.cpp | 6 +- test/unit_test/static/CMakeLists.txt | 14 ++++- test/unit_test/static/angular_test.cpp | 6 +- test/unit_test/static/cgs_test.cpp | 4 ++ test/unit_test/static/chrono_test.cpp | 7 ++- test/unit_test/static/compare_test.cpp | 4 ++ test/unit_test/static/concepts_test.cpp | 12 ++-- .../static/custom_rep_test_min_expl.cpp | 8 ++- .../static/custom_rep_test_min_impl.cpp | 8 ++- test/unit_test/static/dimension_test.cpp | 4 ++ test/unit_test/static/fixed_string_test.cpp | 4 ++ .../static/fractional_exponent_quantity.cpp | 5 ++ test/unit_test/static/hep_test.cpp | 4 ++ test/unit_test/static/iau_test.cpp | 4 ++ test/unit_test/static/iec80000_test.cpp | 4 ++ test/unit_test/static/imperial_test.cpp | 4 ++ test/unit_test/static/international_test.cpp | 4 ++ test/unit_test/static/isq_angle_test.cpp | 4 ++ test/unit_test/static/isq_test.cpp | 4 ++ test/unit_test/static/magnitude_test.cpp | 4 ++ test/unit_test/static/math_test.cpp | 6 +- test/unit_test/static/natural_test.cpp | 4 ++ test/unit_test/static/prime_test.cpp | 6 +- test/unit_test/static/quantity_point_test.cpp | 11 +++- test/unit_test/static/quantity_spec_test.cpp | 4 ++ test/unit_test/static/quantity_test.cpp | 9 ++- test/unit_test/static/ratio_test.cpp | 4 ++ test/unit_test/static/reference_test.cpp | 4 ++ test/unit_test/static/si_test.cpp | 5 ++ test/unit_test/static/symbol_text_test.cpp | 4 ++ test/unit_test/static/test_tools.h | 7 ++- test/unit_test/static/type_list_test.cpp | 5 ++ test/unit_test/static/typographic_test.cpp | 4 ++ test/unit_test/static/unit_symbol_test.cpp | 4 ++ test/unit_test/static/unit_test.cpp | 4 ++ test/unit_test/static/usc_test.cpp | 5 ++ 92 files changed, 754 insertions(+), 141 deletions(-) create mode 100644 src/core-fmt-macros/CMakeLists.txt rename src/{core-fmt => core-fmt-macros}/include/mp-units/bits/fmt_hacks.h (99%) create mode 100644 src/core-macros/CMakeLists.txt create mode 100644 src/core-macros/include/mp-units/bits/core-gmf.h rename src/{core => core-macros}/include/mp-units/bits/external/hacks.h (100%) create mode 100644 src/core-macros/include/mp-units/quantity_spec_macro.h rename src/{utility => core}/include/mp-units/bits/math_core.h (100%) create mode 100644 src/mp-units-core-fmt.cpp create mode 100644 src/mp-units-core-io.cpp create mode 100644 src/mp-units-core.cpp create mode 100644 src/mp-units-systems.cpp create mode 100644 src/mp-units.cpp diff --git a/conanfile.py b/conanfile.py index ff27e6cc..d8d8e141 100644 --- a/conanfile.py +++ b/conanfile.py @@ -104,7 +104,7 @@ class MPUnitsConan(ConanFile): def requirements(self): self.requires("gsl-lite/0.40.0") if self._use_libfmt: - self.requires("fmt/10.1.0") + self.requires("fmt/10.1.1") def build_requirements(self): if self._build_all: diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 5c4bc3c4..33d09727 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -22,15 +22,25 @@ cmake_minimum_required(VERSION 3.5) +# find dependencies +if(NOT TARGET gsl::gsl-lite) + find_package(gsl-lite CONFIG REQUIRED) +endif() + add_library(example_utils INTERFACE) target_include_directories(example_utils INTERFACE include) +target_link_libraries(example_utils INTERFACE gsl::gsl-lite) # -# add_example(target ...) +# add_example(target ...) # function(add_example target) add_executable(${target} ${target}.cpp) - target_link_libraries(${target} PRIVATE ${ARGN}) + if(TARGET mp-units::modules) + target_link_libraries(${target} PRIVATE mp-units::modules) + else() + target_link_libraries(${target} PRIVATE ${ARGN}) + endif() endfunction() add_example(avg_speed mp-units::core-io mp-units::si mp-units::cgs mp-units::usc) @@ -49,7 +59,8 @@ add_example( add_example(conversion_factor mp-units::core-fmt mp-units::core-io mp-units::si) add_example(currency mp-units::core-io) add_example(foot_pound_second mp-units::core-fmt mp-units::international mp-units::imperial) -add_example(glide_computer mp-units::core-fmt mp-units::international mp-units::utility glide_computer_lib) +add_example(glide_computer mp-units::core-fmt mp-units::international mp-units::utility) +target_link_libraries(glide_computer PRIVATE glide_computer_lib) add_example(hello_units mp-units::core-fmt mp-units::core-io mp-units::si mp-units::usc) add_example(measurement mp-units::core-io mp-units::si) add_example(si_constants mp-units::core-fmt mp-units::si) @@ -60,14 +71,9 @@ add_example( ) add_example(total_energy mp-units::core-io mp-units::si mp-units::natural mp-units::utility) add_example( - unmanned_aerial_vehicle - mp-units::core-fmt - mp-units::core-io - mp-units::si - mp-units::international - mp-units::utility - example_utils + unmanned_aerial_vehicle mp-units::core-fmt mp-units::core-io mp-units::si mp-units::international mp-units::utility ) +target_link_libraries(unmanned_aerial_vehicle PRIVATE example_utils) add_subdirectory(glide_computer_lib) add_subdirectory(kalman_filter) diff --git a/example/avg_speed.cpp b/example/avg_speed.cpp index 6744ede1..4443fb6d 100644 --- a/example/avg_speed.cpp +++ b/example/avg_speed.cpp @@ -25,13 +25,17 @@ // !!! renders correctly in the documentation "Examples" section. !!! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include -#include -#include -#include -#include +#include +#include +#endif namespace { diff --git a/example/capacitor_time_curve.cpp b/example/capacitor_time_curve.cpp index d1fb12ce..02bbc271 100644 --- a/example/capacitor_time_curve.cpp +++ b/example/capacitor_time_curve.cpp @@ -20,11 +20,15 @@ physical_quantities */ +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include // IWYU pragma: keep #include #include #include -#include +#endif int main() { diff --git a/example/clcpp_response.cpp b/example/clcpp_response.cpp index fb9f93e3..58cdd912 100644 --- a/example/clcpp_response.cpp +++ b/example/clcpp_response.cpp @@ -15,6 +15,11 @@ along with this program. If not, see http://www.gnu.org/licenses./ */ +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include @@ -24,7 +29,7 @@ #include #include #include -#include +#endif namespace { diff --git a/example/conversion_factor.cpp b/example/conversion_factor.cpp index 5a4eaa97..2b666b9c 100644 --- a/example/conversion_factor.cpp +++ b/example/conversion_factor.cpp @@ -15,12 +15,17 @@ along with this program. If not, see http://www.gnu.org/licenses./ */ +#include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include -#include -#include +#endif /* get conversion factor from one dimensionally equivalent diff --git a/example/currency.cpp b/example/currency.cpp index 28af832e..57cf5a57 100644 --- a/example/currency.cpp +++ b/example/currency.cpp @@ -20,11 +20,16 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units.core_io; +#else #include #include #include -#include -#include +#endif using namespace mp_units; diff --git a/example/foot_pound_second.cpp b/example/foot_pound_second.cpp index 9177cd0c..bfb5719d 100644 --- a/example/foot_pound_second.cpp +++ b/example/foot_pound_second.cpp @@ -20,14 +20,19 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include #include #include -#include -#include +#endif using namespace mp_units; using namespace mp_units::international::unit_symbols; diff --git a/example/glide_computer.cpp b/example/glide_computer.cpp index 09531727..cefe692e 100644 --- a/example/glide_computer.cpp +++ b/example/glide_computer.cpp @@ -22,10 +22,6 @@ #include "glide_computer_lib.h" #include -#include -#include -#include -#include #include #include #include @@ -33,6 +29,14 @@ #include #include #include +#ifdef MP_UNITS_MODULES +import mp_units; +#else +#include +#include +#include +#include +#endif namespace { diff --git a/example/glide_computer_lib/CMakeLists.txt b/example/glide_computer_lib/CMakeLists.txt index 9534977d..65d11b35 100644 --- a/example/glide_computer_lib/CMakeLists.txt +++ b/example/glide_computer_lib/CMakeLists.txt @@ -23,5 +23,10 @@ cmake_minimum_required(VERSION 3.5) add_library(glide_computer_lib STATIC glide_computer_lib.cpp include/glide_computer_lib.h) -target_link_libraries(glide_computer_lib PRIVATE mp-units::core-fmt PUBLIC mp-units::si mp-units::utility example_utils) +if(TARGET mp-units::modules) + target_link_libraries(glide_computer_lib PUBLIC gsl::gsl-lite mp-units::modules) +else() + target_link_libraries(glide_computer_lib PRIVATE mp-units::core-fmt PUBLIC mp-units::si mp-units::utility) +endif() +target_link_libraries(glide_computer_lib PUBLIC example_utils) target_include_directories(glide_computer_lib PUBLIC include) diff --git a/example/glide_computer_lib/glide_computer_lib.cpp b/example/glide_computer_lib/glide_computer_lib.cpp index c0fa44d7..70d26edf 100644 --- a/example/glide_computer_lib/glide_computer_lib.cpp +++ b/example/glide_computer_lib/glide_computer_lib.cpp @@ -21,10 +21,14 @@ // SOFTWARE. #include "glide_computer_lib.h" -#include #include #include #include +#ifdef MP_UNITS_MODULES +import mp_units.core_fmt; +#else +#include +#endif namespace glide_computer { diff --git a/example/glide_computer_lib/include/glide_computer_lib.h b/example/glide_computer_lib/include/glide_computer_lib.h index daa3fcf5..50229a9b 100644 --- a/example/glide_computer_lib/include/glide_computer_lib.h +++ b/example/glide_computer_lib/include/glide_computer_lib.h @@ -22,11 +22,9 @@ #pragma once +#include +// #include "geographic.h" -#include -#include // IWYU pragma: keep -#include -#include #include #include #include @@ -35,6 +33,14 @@ #include #include // IWYU pragma: keep #include +#ifdef MP_UNITS_MODULES +import mp_units; +#else +#include +#include // IWYU pragma: keep +#include +#include +#endif // An example of a really simplified tactical glide computer // Simplifications: diff --git a/example/hello_units.cpp b/example/hello_units.cpp index e537a7a6..6bc12235 100644 --- a/example/hello_units.cpp +++ b/example/hello_units.cpp @@ -25,12 +25,17 @@ // !!! renders correctly in the documentation "Examples" section. !!! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include #include -#include +#endif using namespace mp_units; diff --git a/example/include/geographic.h b/example/include/geographic.h index f66fd1cf..ade0f6e0 100644 --- a/example/include/geographic.h +++ b/example/include/geographic.h @@ -24,6 +24,13 @@ #include "ranged_representation.h" #include +#include +#include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include @@ -31,10 +38,7 @@ #include #include #include -#include -#include -#include -#include +#endif namespace geographic { diff --git a/example/include/ranged_representation.h b/example/include/ranged_representation.h index 82f51846..2b7fff52 100644 --- a/example/include/ranged_representation.h +++ b/example/include/ranged_representation.h @@ -24,11 +24,15 @@ #include "validated_type.h" #include -#include -#include #include #include #include +#ifdef MP_UNITS_MODULES +import mp_units.core; +#else +#include +#include +#endif template) auto Min, MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(std::convertible_to) auto Max> diff --git a/example/include/validated_type.h b/example/include/validated_type.h index 15d540bc..77422ccc 100644 --- a/example/include/validated_type.h +++ b/example/include/validated_type.h @@ -23,11 +23,16 @@ #pragma once #include +#include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units.core_fmt; +#else #include #include #include -#include -#include +#endif inline constexpr struct validated_tag { } validated; diff --git a/example/kalman_filter/CMakeLists.txt b/example/kalman_filter/CMakeLists.txt index ef91cdcb..4c7954d9 100644 --- a/example/kalman_filter/CMakeLists.txt +++ b/example/kalman_filter/CMakeLists.txt @@ -27,7 +27,11 @@ cmake_minimum_required(VERSION 3.5) # function(add_example target) add_executable(${target} ${target}.cpp) - target_link_libraries(${target} PRIVATE ${ARGN}) + if(TARGET mp-units::modules) + target_link_libraries(${target} PRIVATE mp-units::modules) + else() + target_link_libraries(${target} PRIVATE ${ARGN}) + endif() endfunction() add_example(kalman_filter-example_1 mp-units::core-fmt mp-units::si mp-units::utility) diff --git a/example/kalman_filter/kalman.h b/example/kalman_filter/kalman.h index dd925f55..310d9941 100644 --- a/example/kalman_filter/kalman.h +++ b/example/kalman_filter/kalman.h @@ -23,12 +23,16 @@ #pragma once #include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include #include -#include +#endif namespace kalman { diff --git a/example/kalman_filter/kalman_filter-example_1.cpp b/example/kalman_filter/kalman_filter-example_1.cpp index bee71761..c038f253 100644 --- a/example/kalman_filter/kalman_filter-example_1.cpp +++ b/example/kalman_filter/kalman_filter-example_1.cpp @@ -21,11 +21,15 @@ // SOFTWARE. #include "kalman.h" +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include -#include -#include +#endif // Based on: https://www.kalmanfilter.net/alphabeta.html#ex1 diff --git a/example/kalman_filter/kalman_filter-example_2.cpp b/example/kalman_filter/kalman_filter-example_2.cpp index ac748ca3..0260d2de 100644 --- a/example/kalman_filter/kalman_filter-example_2.cpp +++ b/example/kalman_filter/kalman_filter-example_2.cpp @@ -21,11 +21,15 @@ // SOFTWARE. #include "kalman.h" +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include -#include -#include +#endif // Based on: https://www.kalmanfilter.net/alphabeta.html#ex2 diff --git a/example/kalman_filter/kalman_filter-example_3.cpp b/example/kalman_filter/kalman_filter-example_3.cpp index 1fb2e32f..5d453d48 100644 --- a/example/kalman_filter/kalman_filter-example_3.cpp +++ b/example/kalman_filter/kalman_filter-example_3.cpp @@ -21,11 +21,15 @@ // SOFTWARE. #include "kalman.h" +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include -#include -#include +#endif // Based on: https://www.kalmanfilter.net/alphabeta.html#ex3 diff --git a/example/kalman_filter/kalman_filter-example_4.cpp b/example/kalman_filter/kalman_filter-example_4.cpp index cc5044ea..00696c02 100644 --- a/example/kalman_filter/kalman_filter-example_4.cpp +++ b/example/kalman_filter/kalman_filter-example_4.cpp @@ -21,11 +21,15 @@ // SOFTWARE. #include "kalman.h" +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include -#include -#include +#endif // Based on: https://www.kalmanfilter.net/alphabeta.html#ex4 diff --git a/example/kalman_filter/kalman_filter-example_5.cpp b/example/kalman_filter/kalman_filter-example_5.cpp index e50114eb..b4be7e3c 100644 --- a/example/kalman_filter/kalman_filter-example_5.cpp +++ b/example/kalman_filter/kalman_filter-example_5.cpp @@ -21,12 +21,16 @@ // SOFTWARE. #include "kalman.h" +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include -#include -#include +#endif // Based on: https://www.kalmanfilter.net/kalman1d.html#ex5 diff --git a/example/kalman_filter/kalman_filter-example_6.cpp b/example/kalman_filter/kalman_filter-example_6.cpp index 23660370..a6ab2131 100644 --- a/example/kalman_filter/kalman_filter-example_6.cpp +++ b/example/kalman_filter/kalman_filter-example_6.cpp @@ -21,13 +21,17 @@ // SOFTWARE. #include "kalman.h" +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include #include -#include -#include +#endif // Based on: https://www.kalmanfilter.net/kalman1d.html#ex6 diff --git a/example/kalman_filter/kalman_filter-example_7.cpp b/example/kalman_filter/kalman_filter-example_7.cpp index d82d7323..49c832fe 100644 --- a/example/kalman_filter/kalman_filter-example_7.cpp +++ b/example/kalman_filter/kalman_filter-example_7.cpp @@ -21,13 +21,17 @@ // SOFTWARE. #include "kalman.h" +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include #include -#include -#include +#endif // Based on: https://www.kalmanfilter.net/kalman1d.html#ex7 diff --git a/example/kalman_filter/kalman_filter-example_8.cpp b/example/kalman_filter/kalman_filter-example_8.cpp index ca02b7bd..474ecff7 100644 --- a/example/kalman_filter/kalman_filter-example_8.cpp +++ b/example/kalman_filter/kalman_filter-example_8.cpp @@ -21,13 +21,17 @@ // SOFTWARE. #include "kalman.h" +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include #include -#include -#include +#endif // Based on: https://www.kalmanfilter.net/kalman1d.html#ex8 diff --git a/example/measurement.cpp b/example/measurement.cpp index cd36aa92..0f3813e7 100644 --- a/example/measurement.cpp +++ b/example/measurement.cpp @@ -20,13 +20,17 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include -#include -#include -#include +#endif namespace { diff --git a/example/si_constants.cpp b/example/si_constants.cpp index 255f8054..35d855d5 100644 --- a/example/si_constants.cpp +++ b/example/si_constants.cpp @@ -25,9 +25,14 @@ // !!! renders correctly in the documentation "Examples" section. !!! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include -#include +#endif template requires mp_units::is_scalar diff --git a/example/spectroscopy_units.cpp b/example/spectroscopy_units.cpp index 363605a1..7a6270d6 100644 --- a/example/spectroscopy_units.cpp +++ b/example/spectroscopy_units.cpp @@ -20,11 +20,16 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include -#include -#include +#endif // This example implements a table of units provided in the following article // http://cds.cern.ch/record/1481609/files/978-3-642-18018-7_BookBackMatter.pdf diff --git a/example/storage_tank.cpp b/example/storage_tank.cpp index d975e9e0..84d1c42c 100644 --- a/example/storage_tank.cpp +++ b/example/storage_tank.cpp @@ -20,6 +20,16 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#include +#include +#include +#include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include @@ -28,11 +38,7 @@ #include #include #include -#include -#include -#include -#include -#include +#endif // allows standard gravity (acceleration) and weight (force) to be expressed with scalar representation // types instead of requiring the usage of Linear Algebra library for this simple example diff --git a/example/strong_angular_quantities.cpp b/example/strong_angular_quantities.cpp index 7d375e3c..298a097e 100644 --- a/example/strong_angular_quantities.cpp +++ b/example/strong_angular_quantities.cpp @@ -20,11 +20,15 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include -#include +#endif template requires mp_units::is_scalar diff --git a/example/total_energy.cpp b/example/total_energy.cpp index fa83a6cd..116ac4ad 100644 --- a/example/total_energy.cpp +++ b/example/total_energy.cpp @@ -20,14 +20,18 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include #include #include -#include -#include +#endif template requires mp_units::is_scalar @@ -56,31 +60,21 @@ void si_example() std::cout << "\n*** SI units (c = " << c << " = " << c.in(si::metre / s) << ") ***\n"; - std::cout << "\n[in `GeV` and `c`]\n" - << "p = " << p1 << "\n" - << "m = " << m1 << "\n" - << "E = " << E << "\n"; + std::cout << "\n[in `GeV` and `c`]\n" << "p = " << p1 << "\n" << "m = " << m1 << "\n" << "E = " << E << "\n"; const auto p2 = p1.in(GeV / (m / s)); const auto m2 = m1.in(GeV / pow<2>(m / s)); const auto E2 = total_energy(p2, m2, c).in(GeV); - std::cout << "\n[in `GeV`]\n" - << "p = " << p2 << "\n" - << "m = " << m2 << "\n" - << "E = " << E2 << "\n"; + std::cout << "\n[in `GeV`]\n" << "p = " << p2 << "\n" << "m = " << m2 << "\n" << "E = " << E2 << "\n"; const auto p3 = p1.in(kg * m / s); const auto m3 = m1.in(kg); const auto E3 = total_energy(p3, m3, c).in(J); - std::cout << "\n[in SI base units]\n" - << "p = " << p3 << "\n" - << "m = " << m3 << "\n" - << "E = " << E3 << "\n"; + std::cout << "\n[in SI base units]\n" << "p = " << p3 << "\n" << "m = " << m3 << "\n" << "E = " << E3 << "\n"; - std::cout << "\n[converted from SI units back to GeV]\n" - << "E = " << E3.force_in(GeV) << "\n"; + std::cout << "\n[converted from SI units back to GeV]\n" << "E = " << E3.force_in(GeV) << "\n"; } void natural_example() diff --git a/example/unmanned_aerial_vehicle.cpp b/example/unmanned_aerial_vehicle.cpp index fe465f68..6e089939 100644 --- a/example/unmanned_aerial_vehicle.cpp +++ b/example/unmanned_aerial_vehicle.cpp @@ -21,13 +21,18 @@ // SOFTWARE. #include "geographic.h" +#include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include #include -#include -#include +#endif using namespace mp_units; using namespace geographic; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 739e553e..0c5a3fe7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,6 +28,9 @@ set(projectPrefix MP_UNITS_) option(${projectPrefix}AS_SYSTEM_HEADERS "Exports library as system headers" OFF) message(STATUS "${projectPrefix}AS_SYSTEM_HEADERS: ${${projectPrefix}AS_SYSTEM_HEADERS}") +option(${projectPrefix}BUILD_CXX_MODULES "Add C++ modules to the list of default targets" OFF) +message(STATUS "${projectPrefix}BUILD_CXX_MODULES: ${${projectPrefix}BUILD_CXX_MODULES}") + list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") include(AddUnitsModule) @@ -37,7 +40,9 @@ if(${projectPrefix}AS_SYSTEM_HEADERS) set(unitsAsSystem SYSTEM) endif() +add_subdirectory(core-macros) add_subdirectory(core) +add_subdirectory(core-fmt-macros) add_subdirectory(core-fmt) add_subdirectory(core-io) add_subdirectory(systems) @@ -51,6 +56,59 @@ target_link_libraries( add_library(mp-units::mp-units ALIAS mp-units) install(TARGETS mp-units EXPORT mp-unitsTargets) +# C++ modules +if(${projectPrefix}BUILD_CXX_MODULES) + add_library(mp-units-core-module) + add_library(mp-units::core-module ALIAS mp-units-core-module) + target_sources( + mp-units-core-module PUBLIC FILE_SET CXX_MODULES BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES + "mp-units-core.cpp" + ) + target_compile_definitions(mp-units-core-module INTERFACE MP_UNITS_MODULES) + target_link_libraries(mp-units-core-module PRIVATE mp-units::core PUBLIC mp-units::core-macros) + if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18) + target_compile_options(mp-units-core-module PUBLIC "-Wno-include-angled-in-module-purview") + endif() + + add_library(mp-units-core-fmt-module) + add_library(mp-units::core-fmt-module ALIAS mp-units-core-fmt-module) + target_sources( + mp-units-core-fmt-module PUBLIC FILE_SET CXX_MODULES BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES + "mp-units-core-fmt.cpp" + ) + target_link_libraries( + mp-units-core-fmt-module PRIVATE mp-units::core-fmt PUBLIC mp-units::core-fmt-macros mp-units::core-module + ) + + add_library(mp-units-core-io-module) + add_library(mp-units::core-io-module ALIAS mp-units-core-io-module) + target_sources( + mp-units-core-io-module PUBLIC FILE_SET CXX_MODULES BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES + "mp-units-core-io.cpp" + ) + target_link_libraries(mp-units-core-io-module PRIVATE mp-units::core-io PUBLIC mp-units::core-module) + + add_library(mp-units-systems-module) + add_library(mp-units::systems-module ALIAS mp-units-systems-module) + target_sources( + mp-units-systems-module PUBLIC FILE_SET CXX_MODULES BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES + "mp-units-systems.cpp" + ) + target_link_libraries( + mp-units-systems-module PRIVATE mp-units::systems mp-units::utility PUBLIC mp-units::core-module + ) + + add_library(mp-units-modules) + add_library(mp-units::modules ALIAS mp-units-modules) + target_sources( + mp-units-modules PUBLIC FILE_SET CXX_MODULES BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES "mp-units.cpp" + ) + target_link_libraries( + mp-units-modules PUBLIC mp-units::core-module mp-units::core-fmt-module mp-units::core-io-module + mp-units::systems-module + ) +endif() + # local build export(EXPORT mp-unitsTargets NAMESPACE mp-units::) configure_file("mp-unitsConfig.cmake" "." COPYONLY) diff --git a/src/core-fmt-macros/CMakeLists.txt b/src/core-fmt-macros/CMakeLists.txt new file mode 100644 index 00000000..8f6bc13c --- /dev/null +++ b/src/core-fmt-macros/CMakeLists.txt @@ -0,0 +1,45 @@ +# The MIT License (MIT) +# +# Copyright (c) 2018 Mateusz Pusz +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +cmake_minimum_required(VERSION 3.19) + +# core-fmt-macros library definition +add_library(mp-units-core-fmt-macros INTERFACE include/mp-units/bits/fmt_hacks.h) +target_include_directories( + mp-units-core-fmt-macros ${unitsAsSystem} INTERFACE $ + $ +) +target_link_libraries(mp-units-core-fmt-macros INTERFACE mp-units::core-macros) + +if(${projectPrefix}USE_LIBFMT) + if(NOT TARGET fmt::fmt) + find_package(fmt CONFIG REQUIRED) + endif() + target_link_libraries(mp-units-core-fmt-macros INTERFACE fmt::fmt) +endif() + +set_target_properties(mp-units-core-fmt-macros PROPERTIES EXPORT_NAME core-fmt-macros) +add_library(mp-units::core-fmt-macros ALIAS mp-units-core-fmt-macros) + +# installation +install(TARGETS mp-units-core-fmt-macros EXPORT mp-unitsTargets) +install(DIRECTORY include/mp-units TYPE INCLUDE) diff --git a/src/core-fmt/include/mp-units/bits/fmt_hacks.h b/src/core-fmt-macros/include/mp-units/bits/fmt_hacks.h similarity index 99% rename from src/core-fmt/include/mp-units/bits/fmt_hacks.h rename to src/core-fmt-macros/include/mp-units/bits/fmt_hacks.h index 008c3159..3ac40aad 100644 --- a/src/core-fmt/include/mp-units/bits/fmt_hacks.h +++ b/src/core-fmt-macros/include/mp-units/bits/fmt_hacks.h @@ -27,6 +27,8 @@ // // For the license information refer to format.h. +#pragma once + #include #ifndef MP_UNITS_USE_LIBFMT diff --git a/src/core-fmt/CMakeLists.txt b/src/core-fmt/CMakeLists.txt index 99f2ce04..35a59370 100644 --- a/src/core-fmt/CMakeLists.txt +++ b/src/core-fmt/CMakeLists.txt @@ -27,6 +27,7 @@ message(STATUS "${projectPrefix}USE_LIBFMT: ${${projectPrefix}USE_LIBFMT}") add_units_module(core-fmt DEPENDENCIES mp-units::core HEADERS include/mp-units/format.h) target_compile_definitions(mp-units-core-fmt INTERFACE ${projectPrefix}USE_LIBFMT=$) +target_link_libraries(mp-units-core-fmt INTERFACE mp-units::core-fmt-macros) if(${projectPrefix}USE_LIBFMT) if(NOT TARGET fmt::fmt) diff --git a/src/core-macros/CMakeLists.txt b/src/core-macros/CMakeLists.txt new file mode 100644 index 00000000..38bfe974 --- /dev/null +++ b/src/core-macros/CMakeLists.txt @@ -0,0 +1,40 @@ +# The MIT License (MIT) +# +# Copyright (c) 2018 Mateusz Pusz +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +cmake_minimum_required(VERSION 3.19) + +# core-macros library definition +add_library( + mp-units-core-macros INTERFACE include/mp-units/bits/external/hacks.h include/mp-units/quantity_spec_macro.h +) +target_compile_features(mp-units-core-macros INTERFACE cxx_std_20) +target_include_directories( + mp-units-core-macros ${unitsAsSystem} INTERFACE $ + $ +) + +set_target_properties(mp-units-core-macros PROPERTIES EXPORT_NAME core-macros) +add_library(mp-units::core-macros ALIAS mp-units-core-macros) + +# installation +install(TARGETS mp-units-core-macros EXPORT mp-unitsTargets) +install(DIRECTORY include/mp-units TYPE INCLUDE) diff --git a/src/core-macros/include/mp-units/bits/core-gmf.h b/src/core-macros/include/mp-units/bits/core-gmf.h new file mode 100644 index 00000000..fdcd10ad --- /dev/null +++ b/src/core-macros/include/mp-units/bits/core-gmf.h @@ -0,0 +1,50 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +// core +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// utility +#include +#include +#include diff --git a/src/core/include/mp-units/bits/external/hacks.h b/src/core-macros/include/mp-units/bits/external/hacks.h similarity index 100% rename from src/core/include/mp-units/bits/external/hacks.h rename to src/core-macros/include/mp-units/bits/external/hacks.h diff --git a/src/core-macros/include/mp-units/quantity_spec_macro.h b/src/core-macros/include/mp-units/quantity_spec_macro.h new file mode 100644 index 00000000..9e45b833 --- /dev/null +++ b/src/core-macros/include/mp-units/quantity_spec_macro.h @@ -0,0 +1,37 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#ifdef __cpp_explicit_this_parameter + +#define QUANTITY_SPEC(name, ...) \ + inline constexpr struct name : ::mp_units::quantity_spec<__VA_ARGS__> { \ + } name + +#else + +#define QUANTITY_SPEC(name, ...) \ + inline constexpr struct name : ::mp_units::quantity_spec { \ + } name + +#endif diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 7159996e..0abde4e6 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -33,7 +33,6 @@ add_library( INTERFACE include/mp-units/bits/external/algorithm.h include/mp-units/bits/external/fixed_string.h - include/mp-units/bits/external/hacks.h include/mp-units/bits/external/math_concepts.h include/mp-units/bits/external/prime.h include/mp-units/bits/external/type_list.h @@ -44,6 +43,7 @@ add_library( include/mp-units/bits/get_associated_quantity.h include/mp-units/bits/get_common_base.h include/mp-units/bits/magnitude.h + include/mp-units/bits/math_core.h include/mp-units/bits/quantity_cast.h include/mp-units/bits/quantity_concepts.h include/mp-units/bits/quantity_point_concepts.h @@ -67,8 +67,7 @@ add_library( include/mp-units/system_reference.h include/mp-units/unit.h ) -target_compile_features(mp-units-core INTERFACE cxx_std_20) -target_link_libraries(mp-units-core INTERFACE gsl::gsl-lite) +target_link_libraries(mp-units-core INTERFACE gsl::gsl-lite mp-units::core-macros) target_include_directories( mp-units-core ${unitsAsSystem} INTERFACE $ $ diff --git a/src/utility/include/mp-units/bits/math_core.h b/src/core/include/mp-units/bits/math_core.h similarity index 100% rename from src/utility/include/mp-units/bits/math_core.h rename to src/core/include/mp-units/bits/math_core.h diff --git a/src/core/include/mp-units/core.h b/src/core/include/mp-units/core.h index b6c3682d..209076f0 100644 --- a/src/core/include/mp-units/core.h +++ b/src/core/include/mp-units/core.h @@ -22,6 +22,7 @@ #pragma once +#include #include #include #include diff --git a/src/core/include/mp-units/quantity_spec.h b/src/core/include/mp-units/quantity_spec.h index c9b242d4..4550c1e7 100644 --- a/src/core/include/mp-units/quantity_spec.h +++ b/src/core/include/mp-units/quantity_spec.h @@ -32,6 +32,7 @@ #include #include #include +#include #include namespace mp_units { @@ -364,20 +365,6 @@ struct quantity_spec : quantity_spec { static constexpr quantity_character character = detail::quantity_character_init(Eq.character); }; -#ifdef __cpp_explicit_this_parameter - -#define QUANTITY_SPEC(name, ...) \ - inline constexpr struct name : ::mp_units::quantity_spec<__VA_ARGS__> { \ - } name - -#else - -#define QUANTITY_SPEC(name, ...) \ - inline constexpr struct name : ::mp_units::quantity_spec { \ - } name - -#endif - /** * @brief A specification of a derived quantity diff --git a/src/mp-units-core-fmt.cpp b/src/mp-units-core-fmt.cpp new file mode 100644 index 00000000..8576e7bb --- /dev/null +++ b/src/mp-units-core-fmt.cpp @@ -0,0 +1,13 @@ +module; + +#include +#include + +export module mp_units.core_fmt; + +export import mp_units.core; + +export +{ +#include +} diff --git a/src/mp-units-core-io.cpp b/src/mp-units-core-io.cpp new file mode 100644 index 00000000..db16a2df --- /dev/null +++ b/src/mp-units-core-io.cpp @@ -0,0 +1,13 @@ +module; + +#include +#include + +export module mp_units.core_io; + +export import mp_units.core; + +export +{ +#include +} diff --git a/src/mp-units-core.cpp b/src/mp-units-core.cpp new file mode 100644 index 00000000..b0ddbb81 --- /dev/null +++ b/src/mp-units-core.cpp @@ -0,0 +1,11 @@ +module; + +#include + +export module mp_units.core; + +export +{ +// core +#include +} diff --git a/src/mp-units-systems.cpp b/src/mp-units-systems.cpp new file mode 100644 index 00000000..250bd9eb --- /dev/null +++ b/src/mp-units-systems.cpp @@ -0,0 +1,32 @@ +module; + +#include +#include + +export module mp_units.systems; + +export import mp_units.core; + +export +{ +// systems +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// utility +#include +#include +#include +#include +} diff --git a/src/mp-units.cpp b/src/mp-units.cpp new file mode 100644 index 00000000..30218060 --- /dev/null +++ b/src/mp-units.cpp @@ -0,0 +1,8 @@ +module; + +export module mp_units; + +export import mp_units.core; +export import mp_units.core_fmt; +export import mp_units.core_io; +export import mp_units.systems; diff --git a/src/utility/include/mp-units/math.h b/src/utility/include/mp-units/math.h index 0a37935d..c8d9dce2 100644 --- a/src/utility/include/mp-units/math.h +++ b/src/utility/include/mp-units/math.h @@ -29,5 +29,5 @@ // This header is intentionally empty and just include other headers // `math.h` is just a convenience wrapper for not modular code // With C++20 modules: -// - math_core will be a part of the mp_units.core module -// - math_si and math_angular will be provided with the mp_units.systems module +// - math_core is be a part of the mp_units.core module +// - math_si and math_angular is provided with the mp_units.systems module diff --git a/test/unit_test/runtime/CMakeLists.txt b/test/unit_test/runtime/CMakeLists.txt index 29846ad2..21686ab5 100644 --- a/test/unit_test/runtime/CMakeLists.txt +++ b/test/unit_test/runtime/CMakeLists.txt @@ -25,7 +25,12 @@ cmake_minimum_required(VERSION 3.5) find_package(Catch2 3 CONFIG REQUIRED) add_executable(unit_tests_runtime distribution_test.cpp fmt_test.cpp math_test.cpp) -target_link_libraries(unit_tests_runtime PRIVATE mp-units::mp-units Catch2::Catch2WithMain) +if(TARGET mp-units::modules) + target_link_libraries(unit_tests_runtime PRIVATE mp-units::modules) +else() + target_link_libraries(unit_tests_runtime PRIVATE mp-units::mp-units) +endif() +target_link_libraries(unit_tests_runtime PRIVATE Catch2::Catch2WithMain) if(${projectPrefix}BUILD_LA) find_package(wg21_linear_algebra CONFIG REQUIRED) diff --git a/test/unit_test/runtime/almost_equals.h b/test/unit_test/runtime/almost_equals.h index 264182f3..8a871fe9 100644 --- a/test/unit_test/runtime/almost_equals.h +++ b/test/unit_test/runtime/almost_equals.h @@ -21,9 +21,14 @@ // SOFTWARE. #include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include -#include +#endif namespace mp_units { diff --git a/test/unit_test/runtime/distribution_test.cpp b/test/unit_test/runtime/distribution_test.cpp index 5b14ae7f..d3786989 100644 --- a/test/unit_test/runtime/distribution_test.cpp +++ b/test/unit_test/runtime/distribution_test.cpp @@ -21,14 +21,18 @@ // SOFTWARE. #include -#include -#include -#include -#include #include #include #include #include +#ifdef MP_UNITS_MODULES +import mp_units; +#else +#include +#include +#include +#include +#endif using namespace mp_units; diff --git a/test/unit_test/runtime/fmt_test.cpp b/test/unit_test/runtime/fmt_test.cpp index bda7b936..482838b4 100644 --- a/test/unit_test/runtime/fmt_test.cpp +++ b/test/unit_test/runtime/fmt_test.cpp @@ -22,6 +22,13 @@ #include #include +#include +#include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include @@ -29,9 +36,7 @@ #include #include #include -#include -#include -#include +#endif template requires mp_units::is_scalar diff --git a/test/unit_test/runtime/linear_algebra_test.cpp b/test/unit_test/runtime/linear_algebra_test.cpp index 492e3bf8..4e227728 100644 --- a/test/unit_test/runtime/linear_algebra_test.cpp +++ b/test/unit_test/runtime/linear_algebra_test.cpp @@ -21,6 +21,12 @@ // SOFTWARE. #include +#include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include @@ -28,8 +34,7 @@ #include #include #include -#include -#include +#endif template using vector = STD_LA::fixed_size_column_vector; diff --git a/test/unit_test/runtime/math_test.cpp b/test/unit_test/runtime/math_test.cpp index 47e78d74..c6dcc589 100644 --- a/test/unit_test/runtime/math_test.cpp +++ b/test/unit_test/runtime/math_test.cpp @@ -22,13 +22,17 @@ #include "almost_equals.h" #include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include #include #include -#include +#endif using namespace mp_units; using namespace mp_units::si::unit_symbols; diff --git a/test/unit_test/static/CMakeLists.txt b/test/unit_test/static/CMakeLists.txt index 09e09ffd..37cb00c7 100644 --- a/test/unit_test/static/CMakeLists.txt +++ b/test/unit_test/static/CMakeLists.txt @@ -23,7 +23,11 @@ cmake_minimum_required(VERSION 3.5) add_library(unit_tests_static_truncating quantity_test.cpp) -target_link_libraries(unit_tests_static_truncating PRIVATE mp-units::mp-units) +if(TARGET mp-units::modules) + target_link_libraries(unit_tests_static_truncating PRIVATE mp-units::modules) +else() + target_link_libraries(unit_tests_static_truncating PRIVATE mp-units::mp-units) +endif() target_compile_options( unit_tests_static_truncating PRIVATE $,/wd4242 /wd4244,-Wno-conversion> ) @@ -64,5 +68,9 @@ add_library( usc_test.cpp ) -target_link_libraries(unit_tests_static PRIVATE mp-units::mp-units) -target_link_libraries(unit_tests_static PRIVATE unit_tests_static_truncating mp-units::mp-units) +if(TARGET mp-units::modules) + target_link_libraries(unit_tests_static PRIVATE mp-units::modules) +else() + target_link_libraries(unit_tests_static PRIVATE mp-units::mp-units) +endif() +target_link_libraries(unit_tests_static PRIVATE unit_tests_static_truncating) diff --git a/test/unit_test/static/angular_test.cpp b/test/unit_test/static/angular_test.cpp index c3010dfe..c0c5a23b 100644 --- a/test/unit_test/static/angular_test.cpp +++ b/test/unit_test/static/angular_test.cpp @@ -20,8 +20,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include #include +#ifdef MP_UNITS_MODULES +import mp_units; +#else +#include +#endif namespace { diff --git a/test/unit_test/static/cgs_test.cpp b/test/unit_test/static/cgs_test.cpp index c58c5885..2d2bbf0c 100644 --- a/test/unit_test/static/cgs_test.cpp +++ b/test/unit_test/static/cgs_test.cpp @@ -21,10 +21,14 @@ // SOFTWARE. #include "test_tools.h" +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include +#endif template requires mp_units::is_scalar diff --git a/test/unit_test/static/chrono_test.cpp b/test/unit_test/static/chrono_test.cpp index b8c61fa5..df5fa356 100644 --- a/test/unit_test/static/chrono_test.cpp +++ b/test/unit_test/static/chrono_test.cpp @@ -21,11 +21,16 @@ // SOFTWARE. #include "test_tools.h" +#include +#ifdef MP_UNITS_MODULES +#include +import mp_units; +#else #include #include #include #include -#include +#endif namespace { diff --git a/test/unit_test/static/compare_test.cpp b/test/unit_test/static/compare_test.cpp index 5de812d9..6c966f19 100644 --- a/test/unit_test/static/compare_test.cpp +++ b/test/unit_test/static/compare_test.cpp @@ -20,8 +20,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include +#endif namespace { diff --git a/test/unit_test/static/concepts_test.cpp b/test/unit_test/static/concepts_test.cpp index 4312e638..2c050f8b 100644 --- a/test/unit_test/static/concepts_test.cpp +++ b/test/unit_test/static/concepts_test.cpp @@ -20,16 +20,20 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include #include #include -#include -#include -#include -#include +#endif template inline constexpr bool mp_units::is_scalar> = true; diff --git a/test/unit_test/static/custom_rep_test_min_expl.cpp b/test/unit_test/static/custom_rep_test_min_expl.cpp index 689c9666..9288679d 100644 --- a/test/unit_test/static/custom_rep_test_min_expl.cpp +++ b/test/unit_test/static/custom_rep_test_min_expl.cpp @@ -20,11 +20,15 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include -#include -#include +#endif namespace { diff --git a/test/unit_test/static/custom_rep_test_min_impl.cpp b/test/unit_test/static/custom_rep_test_min_impl.cpp index 7d18effd..2ebc01a6 100644 --- a/test/unit_test/static/custom_rep_test_min_impl.cpp +++ b/test/unit_test/static/custom_rep_test_min_impl.cpp @@ -20,8 +20,14 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include +#include +#include #include +#ifdef MP_UNITS_MODULES +import mp_units; +#else +#include +#endif namespace { diff --git a/test/unit_test/static/dimension_test.cpp b/test/unit_test/static/dimension_test.cpp index 808620d7..04a95357 100644 --- a/test/unit_test/static/dimension_test.cpp +++ b/test/unit_test/static/dimension_test.cpp @@ -21,11 +21,15 @@ // SOFTWARE. #include "test_tools.h" +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include #include +#endif namespace { diff --git a/test/unit_test/static/fixed_string_test.cpp b/test/unit_test/static/fixed_string_test.cpp index 4835fbdf..c4a56aed 100644 --- a/test/unit_test/static/fixed_string_test.cpp +++ b/test/unit_test/static/fixed_string_test.cpp @@ -20,7 +20,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include +#endif using namespace mp_units; diff --git a/test/unit_test/static/fractional_exponent_quantity.cpp b/test/unit_test/static/fractional_exponent_quantity.cpp index d8a1b513..6014b34e 100644 --- a/test/unit_test/static/fractional_exponent_quantity.cpp +++ b/test/unit_test/static/fractional_exponent_quantity.cpp @@ -20,9 +20,14 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include +#endif namespace { diff --git a/test/unit_test/static/hep_test.cpp b/test/unit_test/static/hep_test.cpp index 93a95321..d5e2384a 100644 --- a/test/unit_test/static/hep_test.cpp +++ b/test/unit_test/static/hep_test.cpp @@ -20,10 +20,14 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include +#endif template requires mp_units::is_scalar diff --git a/test/unit_test/static/iau_test.cpp b/test/unit_test/static/iau_test.cpp index 6e414b0b..54738538 100644 --- a/test/unit_test/static/iau_test.cpp +++ b/test/unit_test/static/iau_test.cpp @@ -20,9 +20,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include +#endif /* ************** DERIVED DIMENSIONS THAT INCLUDE UNITS WITH SPECIAL NAMES **************** */ diff --git a/test/unit_test/static/iec80000_test.cpp b/test/unit_test/static/iec80000_test.cpp index 2718758f..1021a6cc 100644 --- a/test/unit_test/static/iec80000_test.cpp +++ b/test/unit_test/static/iec80000_test.cpp @@ -20,10 +20,14 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include +#endif /* ************** DERIVED DIMENSIONS THAT INCLUDE UNITS WITH SPECIAL NAMES **************** */ diff --git a/test/unit_test/static/imperial_test.cpp b/test/unit_test/static/imperial_test.cpp index 7b3b3a74..13d1ed26 100644 --- a/test/unit_test/static/imperial_test.cpp +++ b/test/unit_test/static/imperial_test.cpp @@ -20,9 +20,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include +#endif namespace { diff --git a/test/unit_test/static/international_test.cpp b/test/unit_test/static/international_test.cpp index a5a31219..910c9e26 100644 --- a/test/unit_test/static/international_test.cpp +++ b/test/unit_test/static/international_test.cpp @@ -20,12 +20,16 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include #include #include +#endif template requires mp_units::is_scalar diff --git a/test/unit_test/static/isq_angle_test.cpp b/test/unit_test/static/isq_angle_test.cpp index ef597076..fdb32496 100644 --- a/test/unit_test/static/isq_angle_test.cpp +++ b/test/unit_test/static/isq_angle_test.cpp @@ -20,8 +20,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include +#endif namespace { diff --git a/test/unit_test/static/isq_test.cpp b/test/unit_test/static/isq_test.cpp index 4d7333f2..9a67d44e 100644 --- a/test/unit_test/static/isq_test.cpp +++ b/test/unit_test/static/isq_test.cpp @@ -20,9 +20,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include +#endif namespace { diff --git a/test/unit_test/static/magnitude_test.cpp b/test/unit_test/static/magnitude_test.cpp index eaf2cc17..f0eb031b 100644 --- a/test/unit_test/static/magnitude_test.cpp +++ b/test/unit_test/static/magnitude_test.cpp @@ -20,9 +20,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include +#endif using namespace units; using namespace units::detail; diff --git a/test/unit_test/static/math_test.cpp b/test/unit_test/static/math_test.cpp index 528ea206..d4f52037 100644 --- a/test/unit_test/static/math_test.cpp +++ b/test/unit_test/static/math_test.cpp @@ -20,11 +20,15 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include // IWYU pragma: keep #include #include #include -#include +#endif namespace { diff --git a/test/unit_test/static/natural_test.cpp b/test/unit_test/static/natural_test.cpp index 7880642b..f24f31e1 100644 --- a/test/unit_test/static/natural_test.cpp +++ b/test/unit_test/static/natural_test.cpp @@ -20,8 +20,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include +#endif template requires mp_units::is_scalar diff --git a/test/unit_test/static/prime_test.cpp b/test/unit_test/static/prime_test.cpp index 0fd724bd..d6647a10 100644 --- a/test/unit_test/static/prime_test.cpp +++ b/test/unit_test/static/prime_test.cpp @@ -20,9 +20,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include #include #include +#ifdef MP_UNITS_MODULES +import mp_units; +#else +#include +#endif using namespace mp_units::detail; diff --git a/test/unit_test/static/quantity_point_test.cpp b/test/unit_test/static/quantity_point_test.cpp index 4ebfb5ad..b44da9f0 100644 --- a/test/unit_test/static/quantity_point_test.cpp +++ b/test/unit_test/static/quantity_point_test.cpp @@ -21,14 +21,19 @@ // SOFTWARE. #include "test_tools.h" +#include +#include +#include +#ifdef MP_UNITS_MODULES +#include +import mp_units; +#else #include #include #include #include #include -#include -#include -#include +#endif namespace { diff --git a/test/unit_test/static/quantity_spec_test.cpp b/test/unit_test/static/quantity_spec_test.cpp index ab7694c1..d9713686 100644 --- a/test/unit_test/static/quantity_spec_test.cpp +++ b/test/unit_test/static/quantity_spec_test.cpp @@ -21,10 +21,14 @@ // SOFTWARE. #include "test_tools.h" +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include +#endif namespace { diff --git a/test/unit_test/static/quantity_test.cpp b/test/unit_test/static/quantity_test.cpp index 47ed833c..11721955 100644 --- a/test/unit_test/static/quantity_test.cpp +++ b/test/unit_test/static/quantity_test.cpp @@ -21,12 +21,17 @@ // SOFTWARE. #include "test_tools.h" +#include +#include +#ifdef MP_UNITS_MODULES +#include +import mp_units; +#else #include #include #include #include -#include -#include +#endif template<> inline constexpr bool mp_units::is_vector = true; diff --git a/test/unit_test/static/ratio_test.cpp b/test/unit_test/static/ratio_test.cpp index 5bf9bec0..fd2113bc 100644 --- a/test/unit_test/static/ratio_test.cpp +++ b/test/unit_test/static/ratio_test.cpp @@ -20,7 +20,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include +#endif namespace { diff --git a/test/unit_test/static/reference_test.cpp b/test/unit_test/static/reference_test.cpp index 3aac7e59..8da7fa48 100644 --- a/test/unit_test/static/reference_test.cpp +++ b/test/unit_test/static/reference_test.cpp @@ -21,6 +21,9 @@ // SOFTWARE. #include "test_tools.h" +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include @@ -28,6 +31,7 @@ #include #include #include +#endif namespace { diff --git a/test/unit_test/static/si_test.cpp b/test/unit_test/static/si_test.cpp index 69d83096..8ce65935 100644 --- a/test/unit_test/static/si_test.cpp +++ b/test/unit_test/static/si_test.cpp @@ -20,8 +20,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include +#endif namespace { diff --git a/test/unit_test/static/symbol_text_test.cpp b/test/unit_test/static/symbol_text_test.cpp index 1eb4700b..950c39e6 100644 --- a/test/unit_test/static/symbol_text_test.cpp +++ b/test/unit_test/static/symbol_text_test.cpp @@ -20,7 +20,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include +#endif using namespace mp_units; diff --git a/test/unit_test/static/test_tools.h b/test/unit_test/static/test_tools.h index 42cbc61e..bf6f77a5 100644 --- a/test/unit_test/static/test_tools.h +++ b/test/unit_test/static/test_tools.h @@ -22,8 +22,13 @@ #pragma once -#include #include +#ifdef MP_UNITS_MODULES +#include +import mp_units; +#else +#include +#endif template inline constexpr bool is_of_type = std::is_same_v, T>; diff --git a/test/unit_test/static/type_list_test.cpp b/test/unit_test/static/type_list_test.cpp index 6720ebbb..c3d61d52 100644 --- a/test/unit_test/static/type_list_test.cpp +++ b/test/unit_test/static/type_list_test.cpp @@ -20,8 +20,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include +#endif namespace { diff --git a/test/unit_test/static/typographic_test.cpp b/test/unit_test/static/typographic_test.cpp index 9a47469c..71c713d1 100644 --- a/test/unit_test/static/typographic_test.cpp +++ b/test/unit_test/static/typographic_test.cpp @@ -20,9 +20,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include +#endif namespace { diff --git a/test/unit_test/static/unit_symbol_test.cpp b/test/unit_test/static/unit_symbol_test.cpp index d5a41358..24fe56fa 100644 --- a/test/unit_test/static/unit_symbol_test.cpp +++ b/test/unit_test/static/unit_symbol_test.cpp @@ -20,9 +20,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include +#endif namespace { diff --git a/test/unit_test/static/unit_test.cpp b/test/unit_test/static/unit_test.cpp index ca4ae1cc..d187467a 100644 --- a/test/unit_test/static/unit_test.cpp +++ b/test/unit_test/static/unit_test.cpp @@ -21,11 +21,15 @@ // SOFTWARE. #include "test_tools.h" +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include #include +#endif namespace { diff --git a/test/unit_test/static/usc_test.cpp b/test/unit_test/static/usc_test.cpp index c4e35e9e..42c29389 100644 --- a/test/unit_test/static/usc_test.cpp +++ b/test/unit_test/static/usc_test.cpp @@ -20,10 +20,15 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #include +#endif namespace { From 52b0c033467801ee050ddfe2ca769f3479c64113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johel=20Ernesto=20Guerrero=20Pe=C3=B1a?= Date: Sat, 6 Jan 2024 08:51:00 +0100 Subject: [PATCH 02/33] docs: document `MP_UNITS_BUILD_CXX_MODULES` --- docs/getting_started/installation_and_usage.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/getting_started/installation_and_usage.md b/docs/getting_started/installation_and_usage.md index 80f31108..5ed8ce5c 100644 --- a/docs/getting_started/installation_and_usage.md +++ b/docs/getting_started/installation_and_usage.md @@ -175,6 +175,15 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"} [as system headers support]: https://github.com/mpusz/mp-units/releases/tag/v2.0.0 +[`MP_UNITS_BUILD_CXX_MODULES`](#MP_UNITS_BUILD_CXX_MODULES){ #MP_UNITS_BUILD_CXX_MODULES } + +: [:octicons-tag-24: 2.2.0][build_cxx_modules support] · :octicons-milestone-24: `ON`/`OFF` (Default: `OFF`) + + Add C++ modules to the list of default targets. + + [build_cxx_modules support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0 + + [`MP_UNITS_BUILD_LA`](#MP_UNITS_BUILD_LA){ #MP_UNITS_BUILD_LA } : [:octicons-tag-24: 2.0.0][build la support] · :octicons-milestone-24: `ON`/`OFF` (Default: `ON`) From ceb1522a1e222b40c73f466b723f2fa8e5dce0e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johel=20Ernesto=20Guerrero=20Pe=C3=B1a?= Date: Sat, 6 Jan 2024 08:51:00 +0100 Subject: [PATCH 03/33] docs: update example source lines --- docs/users_guide/examples/avg_speed.md | 30 +++++++++++------------ docs/users_guide/examples/hello_units.md | 22 ++++++++--------- docs/users_guide/examples/si_constants.md | 6 ++--- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/docs/users_guide/examples/avg_speed.md b/docs/users_guide/examples/avg_speed.md index c2aade6c..dc8ebc43 100644 --- a/docs/users_guide/examples/avg_speed.md +++ b/docs/users_guide/examples/avg_speed.md @@ -18,28 +18,28 @@ First, we include all the necessary header files and import all the identifiers `mp_units` namespace: ```cpp title="avg_speed.cpp" linenums="1" ---8<-- "example/avg_speed.cpp:28:38" +--8<-- "example/avg_speed.cpp:28:42" ``` Next, we define two functions calculating average speed based on quantities of fixed units and integral and floating-point representation types, respectively, and a third function that we introduced in the [previous example](hello_units.md): -```cpp title="avg_speed.cpp" linenums="12" ---8<-- "example/avg_speed.cpp:40:54" +```cpp title="avg_speed.cpp" linenums="16" +--8<-- "example/avg_speed.cpp:44:58" ``` We also added a simple utility to print our results: -```cpp title="avg_speed.cpp" linenums="27" ---8<-- "example/avg_speed.cpp:56:62" +```cpp title="avg_speed.cpp" linenums="31" +--8<-- "example/avg_speed.cpp:60:66" ``` Now, let's analyze how those three utility functions behave with different sets of arguments. First, we are going to use quantities of SI units and integral representation: -```cpp title="avg_speed.cpp" linenums="27" ---8<-- "example/avg_speed.cpp:64:78" +```cpp title="avg_speed.cpp" linenums="38" +--8<-- "example/avg_speed.cpp:68:82" ``` The above provides the following output: @@ -61,8 +61,8 @@ can be easily observed in the first case where we deal with integral representat The second scenario is really similar to the previous one, but this time, function arguments have floating-point representation types: -```cpp title="avg_speed.cpp" linenums="42" ---8<-- "example/avg_speed.cpp:80:91" +```cpp title="avg_speed.cpp" linenums="53" +--8<-- "example/avg_speed.cpp:84:95" ``` Conversion from floating-point to integral representation types is @@ -82,8 +82,8 @@ Average speed of a car that makes 220 km in 2 h is 110 km/h. Next, let's do the same for integral and floating-point representations, but this time using US Customary units: -```cpp title="avg_speed.cpp" linenums="54" ---8<-- "example/avg_speed.cpp:93:124" +```cpp title="avg_speed.cpp" linenums="65" +--8<-- "example/avg_speed.cpp:97:129" ``` One important difference here is the fact that as it is not possible to make a lossless conversion @@ -108,8 +108,8 @@ Please note how the first and third results get truncated using integral represe In the end, we repeat the scenario for CGS units: -```cpp title="avg_speed.cpp" linenums="86" ---8<-- "example/avg_speed.cpp:126:155" +```cpp title="avg_speed.cpp" linenums="98" +--8<-- "example/avg_speed.cpp:131:161" ``` Again, we observe `value_cast` being used in the same places and consistent truncation errors @@ -129,6 +129,6 @@ Average speed of a car that makes 2.2e+07 cm in 7200 s is 110 km/h. The example file ends with a simple `main()` function: -```cpp title="avg_speed.cpp" linenums="116" ---8<-- "example/avg_speed.cpp:157:" +```cpp title="avg_speed.cpp" linenums="129" +--8<-- "example/avg_speed.cpp:163:" ``` diff --git a/docs/users_guide/examples/hello_units.md b/docs/users_guide/examples/hello_units.md index c0f99bbb..bc5c5a50 100644 --- a/docs/users_guide/examples/hello_units.md +++ b/docs/users_guide/examples/hello_units.md @@ -18,20 +18,20 @@ First, we include the headers for: - text and stream output support ```cpp title="hello_units.cpp" linenums="1" ---8<-- "example/hello_units.cpp:28:33" +--8<-- "example/hello_units.cpp:28:39" ``` Also, to shorten the definitions, we "import" `mp_units` namespace. -```cpp title="hello_units.cpp" linenums="7" ---8<-- "example/hello_units.cpp:35:36" +```cpp title="hello_units.cpp" linenums="12" +--8<-- "example/hello_units.cpp:40:41" ``` Next we define a simple function that calculates average speed based on the provided arguments of length and time: -```cpp title="hello_units.cpp" linenums="8" ---8<-- "example/hello_units.cpp:37:40" +```cpp title="hello_units.cpp" linenums="13" +--8<-- "example/hello_units.cpp:42:45" ``` The above function template takes any quantities implicitly convertible to `isq::length` @@ -45,16 +45,16 @@ that its quantity type is implicitly convertible to `isq::speed`. type is really useful for users of such a function as it provides more information of what to expect from a function than just using `auto`. -```cpp title="hello_units.cpp" linenums="12" ---8<-- "example/hello_units.cpp:42:45" +```cpp title="hello_units.cpp" linenums="17" +--8<-- "example/hello_units.cpp:47:50" ``` The above lines explicitly opt-in to use unit symbols from two systems of units. As this introduces a lot of short identifiers into the current scope, it is not done implicitly while including a header file. -```cpp title="hello_units.cpp" linenums="16" ---8<-- "example/hello_units.cpp:47:53" +```cpp title="hello_units.cpp" linenums="21" +--8<-- "example/hello_units.cpp:52:58" ``` - Lines `16` & `17` create a quantity of kind `isq::length / isq::time` with the numbers @@ -74,8 +74,8 @@ implicitly while including a header file. - Line `22` does a [value-truncating conversion](../framework_basics/value_conversions.md#value-truncating-conversions) of changing the underlying representation type from `double` to `int`. -```cpp title="hello_units.cpp" linenums="23" ---8<-- "example/hello_units.cpp:55" +```cpp title="hello_units.cpp" linenums="28" +--8<-- "example/hello_units.cpp:60" ``` The above presents [various ways to print a quantity](../framework_basics/text_output.md). diff --git a/docs/users_guide/examples/si_constants.md b/docs/users_guide/examples/si_constants.md index 87b67ad4..8e46816e 100644 --- a/docs/users_guide/examples/si_constants.md +++ b/docs/users_guide/examples/si_constants.md @@ -13,7 +13,7 @@ how [Faster-than-lightspeed Constants](../framework_basics/faster_than_lightspee work in practice. ```cpp title="si_constants.cpp" linenums="1" ---8<-- "example/si_constants.cpp:28:34" +--8<-- "example/si_constants.cpp:28:39" ``` As always, we start with the inclusion of all the needed header files. After that, for @@ -21,8 +21,8 @@ the simplicity of this example, we [hack the character of quantities](../framework_basics/character_of_a_quantity.md#hacking-the-character) to be able to express vector quantities with simple scalar types. -```cpp title="si_constants.cpp" linenums="1" ---8<-- "example/si_constants.cpp:36:" +```cpp title="si_constants.cpp" linenums="13" +--8<-- "example/si_constants.cpp:41:" ``` The main part of the example prints all of the SI-defining constants. While analyzing the output of From 7aa0690246eaf1474bbbc4e9ee456007238b65da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johel=20Ernesto=20Guerrero=20Pe=C3=B1a?= Date: Sat, 6 Jan 2024 08:51:00 +0100 Subject: [PATCH 04/33] refactor: move `compare.h` and `random.h` to `mp_units.core` --- src/mp-units-core.cpp | 4 ++++ src/mp-units-systems.cpp | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mp-units-core.cpp b/src/mp-units-core.cpp index b0ddbb81..2826e6fe 100644 --- a/src/mp-units-core.cpp +++ b/src/mp-units-core.cpp @@ -8,4 +8,8 @@ export { // core #include + +// utility +#include +#include } diff --git a/src/mp-units-systems.cpp b/src/mp-units-systems.cpp index 250bd9eb..eaa63218 100644 --- a/src/mp-units-systems.cpp +++ b/src/mp-units-systems.cpp @@ -26,7 +26,5 @@ export // utility #include -#include #include -#include } From b5a7b815bafa4ad4dd6f51b42db5b4823232853e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johel=20Ernesto=20Guerrero=20Pe=C3=B1a?= Date: Sat, 6 Jan 2024 08:51:00 +0100 Subject: [PATCH 05/33] style: fix grammar of comment Co-authored-by: Mateusz Pusz --- src/utility/include/mp-units/math.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/include/mp-units/math.h b/src/utility/include/mp-units/math.h index c8d9dce2..53743dee 100644 --- a/src/utility/include/mp-units/math.h +++ b/src/utility/include/mp-units/math.h @@ -29,5 +29,5 @@ // This header is intentionally empty and just include other headers // `math.h` is just a convenience wrapper for not modular code // With C++20 modules: -// - math_core is be a part of the mp_units.core module +// - math_core is a part of the mp_units.core module // - math_si and math_angular is provided with the mp_units.systems module From 47a522688816ead5215387697e3a1d6dbbf42f1b Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 06/33] style: formatting and whitespaces fixed to make pre-commit happy --- example/total_energy.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/example/total_energy.cpp b/example/total_energy.cpp index 116ac4ad..f183169b 100644 --- a/example/total_energy.cpp +++ b/example/total_energy.cpp @@ -60,21 +60,31 @@ void si_example() std::cout << "\n*** SI units (c = " << c << " = " << c.in(si::metre / s) << ") ***\n"; - std::cout << "\n[in `GeV` and `c`]\n" << "p = " << p1 << "\n" << "m = " << m1 << "\n" << "E = " << E << "\n"; + std::cout << "\n[in `GeV` and `c`]\n" + << "p = " << p1 << "\n" + << "m = " << m1 << "\n" + << "E = " << E << "\n"; const auto p2 = p1.in(GeV / (m / s)); const auto m2 = m1.in(GeV / pow<2>(m / s)); const auto E2 = total_energy(p2, m2, c).in(GeV); - std::cout << "\n[in `GeV`]\n" << "p = " << p2 << "\n" << "m = " << m2 << "\n" << "E = " << E2 << "\n"; + std::cout << "\n[in `GeV`]\n" + << "p = " << p2 << "\n" + << "m = " << m2 << "\n" + << "E = " << E2 << "\n"; const auto p3 = p1.in(kg * m / s); const auto m3 = m1.in(kg); const auto E3 = total_energy(p3, m3, c).in(J); - std::cout << "\n[in SI base units]\n" << "p = " << p3 << "\n" << "m = " << m3 << "\n" << "E = " << E3 << "\n"; + std::cout << "\n[in SI base units]\n" + << "p = " << p3 << "\n" + << "m = " << m3 << "\n" + << "E = " << E3 << "\n"; - std::cout << "\n[converted from SI units back to GeV]\n" << "E = " << E3.force_in(GeV) << "\n"; + std::cout << "\n[converted from SI units back to GeV]\n" + << "E = " << E3.force_in(GeV) << "\n"; } void natural_example() From 4069481331214834c22303ebfff249a7cf7e7eea Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 07/33] refactor: `math_core.h` moved back to the `utility` directory --- src/core/CMakeLists.txt | 1 - src/utility/CMakeLists.txt | 3 ++- src/{core => utility}/include/mp-units/bits/math_core.h | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/{core => utility}/include/mp-units/bits/math_core.h (100%) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 0abde4e6..ed0270cd 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -43,7 +43,6 @@ add_library( include/mp-units/bits/get_associated_quantity.h include/mp-units/bits/get_common_base.h include/mp-units/bits/magnitude.h - include/mp-units/bits/math_core.h include/mp-units/bits/quantity_cast.h include/mp-units/bits/quantity_concepts.h include/mp-units/bits/quantity_point_concepts.h diff --git a/src/utility/CMakeLists.txt b/src/utility/CMakeLists.txt index 7b51d34c..a9642ef0 100644 --- a/src/utility/CMakeLists.txt +++ b/src/utility/CMakeLists.txt @@ -24,5 +24,6 @@ cmake_minimum_required(VERSION 3.19) add_units_module( utility DEPENDENCIES mp-units::core mp-units::isq mp-units::si mp-units::angular - HEADERS include/mp-units/chrono.h include/mp-units/math.h include/mp-units/random.h + HEADERS include/mp-units/bits/math_angular.h include/mp-units/bits/math_core.h include/mp-units/bits/math_si.h + include/mp-units/chrono.h include/mp-units/math.h include/mp-units/random.h ) diff --git a/src/core/include/mp-units/bits/math_core.h b/src/utility/include/mp-units/bits/math_core.h similarity index 100% rename from src/core/include/mp-units/bits/math_core.h rename to src/utility/include/mp-units/bits/math_core.h From c0f264cae92acd828dc6dd6cb7facaf7c4abafde Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 08/33] fix: `mp-units-core-module` now links with `mp-units::utility` --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0c5a3fe7..6fe4377c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -65,7 +65,7 @@ if(${projectPrefix}BUILD_CXX_MODULES) "mp-units-core.cpp" ) target_compile_definitions(mp-units-core-module INTERFACE MP_UNITS_MODULES) - target_link_libraries(mp-units-core-module PRIVATE mp-units::core PUBLIC mp-units::core-macros) + target_link_libraries(mp-units-core-module PRIVATE mp-units::core mp-units::utility PUBLIC mp-units::core-macros) if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18) target_compile_options(mp-units-core-module PUBLIC "-Wno-include-angled-in-module-purview") endif() From 50c8f0a20da6d127edf06a071562273d4147961a Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 09/33] build: `projectPrefix` applied to preprocessor define --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6fe4377c..34ba13c6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,7 +64,7 @@ if(${projectPrefix}BUILD_CXX_MODULES) mp-units-core-module PUBLIC FILE_SET CXX_MODULES BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES "mp-units-core.cpp" ) - target_compile_definitions(mp-units-core-module INTERFACE MP_UNITS_MODULES) + target_compile_definitions(mp-units-core-module PUBLIC ${projectPrefix}MODULES) target_link_libraries(mp-units-core-module PRIVATE mp-units::core mp-units::utility PUBLIC mp-units::core-macros) if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18) target_compile_options(mp-units-core-module PUBLIC "-Wno-include-angled-in-module-purview") From ea8450df9d03b02be4f84dd92b38cab5675a3884 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 10/33] build: `_LIBCPP_NO_ABI_TAG` define set for clang-17 modules build --- src/CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 34ba13c6..c8a43497 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -66,8 +66,14 @@ if(${projectPrefix}BUILD_CXX_MODULES) ) target_compile_definitions(mp-units-core-module PUBLIC ${projectPrefix}MODULES) target_link_libraries(mp-units-core-module PRIVATE mp-units::core mp-units::utility PUBLIC mp-units::core-macros) - if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18) - target_compile_options(mp-units-core-module PUBLIC "-Wno-include-angled-in-module-purview") + if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18) + target_compile_definitions(mp-units-core-module PUBLIC _LIBCPP_NO_ABI_TAG) + endif() + + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18) + target_compile_options(mp-units-core-module PUBLIC "-Wno-include-angled-in-module-purview") + endif() endif() add_library(mp-units-core-fmt-module) From b582e200a035521516e3a71503254442d8116cdf Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 11/33] fix: clang-17 with modules build on ignores disabling conversion warnings --- test/unit_test/static/quantity_test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/unit_test/static/quantity_test.cpp b/test/unit_test/static/quantity_test.cpp index 11721955..ed038077 100644 --- a/test/unit_test/static/quantity_test.cpp +++ b/test/unit_test/static/quantity_test.cpp @@ -20,6 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +// #include "test_tools.h" #include #include @@ -402,6 +404,8 @@ static_assert((std::uint8_t(255) * m %= 257 * m).numerical_value_in(m) != [] { // TODO ICE // (https://developercommunity2.visualstudio.com/t/ICE-on-a-constexpr-operator-in-mp-unit/1302907) #ifndef MP_UNITS_COMP_MSVC +// clang-17 with modules build on ignores disabling conversion warnings +#if !(defined MP_UNITS_COMP_CLANG && MP_UNITS_COMP_CLANG < 18 && defined MP_UNITS_MODULES) // next two lines trigger conversions warnings // (warning disabled in CMake for this file) static_assert((22 * m *= 33.33).numerical_value_in(m) == 733); @@ -409,6 +413,7 @@ static_assert((22 * m /= 3.33).numerical_value_in(m) == 6); static_assert((22 * m *= 33.33 * one).numerical_value_in(m) == 733); static_assert((22 * m /= 3.33 * one).numerical_value_in(m) == 6); #endif +#endif template typename Q> concept invalid_compound_assignments = requires() { From 0eaf6e2e56ab90eb240fc215a2357e1b5d33add9 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 12/33] refactor: modules support redesigned --- .cmake-format.yaml | 23 +--- example/CMakeLists.txt | 68 +++++------ example/clcpp_response.cpp | 2 +- example/conversion_factor.cpp | 2 +- example/currency.cpp | 2 +- example/foot_pound_second.cpp | 2 +- example/glide_computer.cpp | 5 +- example/glide_computer_lib/CMakeLists.txt | 16 +-- .../include/glide_computer_lib.h | 4 +- example/hello_units.cpp | 2 +- example/include/geographic.h | 5 +- example/include/validated_type.h | 2 +- example/kalman_filter/CMakeLists.txt | 28 ++--- example/kalman_filter/kalman.h | 2 +- example/si_constants.cpp | 2 +- example/spectroscopy_units.cpp | 2 +- example/storage_tank.cpp | 9 +- example/unmanned_aerial_vehicle.cpp | 2 +- src/CMakeLists.txt | 76 ++---------- src/cmake/AddUnitsModule.cmake | 41 +++++-- src/core-fmt-macros/CMakeLists.txt | 45 -------- src/core-fmt/CMakeLists.txt | 14 ++- src/core-fmt/include/mp-units/bits/fmt.h | 2 +- .../include/mp-units/compat_fmt_macros.h} | 0 src/{ => core-fmt}/mp-units-core-fmt.cpp | 4 +- src/core-io/CMakeLists.txt | 7 +- src/{ => core-io}/mp-units-core-io.cpp | 2 +- src/core-macros/CMakeLists.txt | 40 ------- src/core/CMakeLists.txt | 109 ++++++++++-------- .../include/mp-units/bits/core_gmf.h} | 6 +- .../include/mp-units/bits/external/hacks.h | 7 +- .../include/mp-units/compare.h | 0 .../include/mp-units/compat_macros.h} | 2 + src/core/include/mp-units/core.h | 5 +- .../include/mp-units/math.h} | 0 src/core/include/mp-units/quantity_point.h | 22 +--- src/core/include/mp-units/quantity_spec.h | 2 +- .../include/mp-units/random.h | 0 src/core/mp-units-core.cpp | 10 ++ src/mp-units-core.cpp | 15 --- src/systems/CMakeLists.txt | 71 ++++++------ src/systems/angular/CMakeLists.txt | 25 ---- src/systems/cgs/CMakeLists.txt | 25 ---- src/systems/hep/CMakeLists.txt | 25 ---- src/systems/iau/CMakeLists.txt | 25 ---- src/systems/iec80000/CMakeLists.txt | 31 ----- src/systems/imperial/CMakeLists.txt | 27 ----- .../mp-units/systems/angular/angular.h} | 11 +- .../include/mp-units/systems/angular/math.h} | 2 +- .../mp-units/systems/angular/units.h} | 0 .../include/mp-units/systems/cgs/cgs.h | 0 .../include/mp-units/systems/hep/hep.h | 0 .../include/mp-units/systems/iau/iau.h | 0 .../systems/iec80000/binary_prefixes.h | 0 .../mp-units/systems/iec80000/iec80000.h | 0 .../mp-units/systems/iec80000/quantities.h | 0 .../mp-units/systems/iec80000/unit_symbols.h | 0 .../include/mp-units/systems/iec80000/units.h | 0 .../mp-units/systems/imperial/imperial.h | 0 .../systems/international/international.h | 0 .../systems/isq/atomic_and_nuclear_physics.h | 0 .../mp-units/systems/isq/base_quantities.h | 0 .../mp-units/systems/isq/electromagnetism.h | 0 .../include/mp-units/systems/isq/isq.h | 0 .../include/mp-units/systems/isq/mechanics.h | 0 .../mp-units/systems/isq/space_and_time.h | 0 .../mp-units/systems/isq/thermodynamics.h | 0 .../mp-units/systems/isq_angle/isq_angle.h | 0 .../mp-units/systems/natural/natural.h | 0 .../include/mp-units/systems/si}/chrono.h | 0 .../include/mp-units/systems/si/constants.h | 0 .../include/mp-units/systems/si/math.h} | 0 .../include/mp-units/systems/si/prefixes.h | 0 .../{si => }/include/mp-units/systems/si/si.h | 2 + .../mp-units/systems/si/unit_symbols.h | 0 .../include/mp-units/systems/si/units.h | 0 .../systems/typographic/typographic.h | 0 .../include/mp-units/systems/usc/usc.h | 0 src/systems/international/CMakeLists.txt | 25 ---- src/systems/isq/CMakeLists.txt | 35 ------ src/systems/isq_angle/CMakeLists.txt | 27 ----- src/{ => systems}/mp-units-systems.cpp | 9 +- src/systems/natural/CMakeLists.txt | 25 ---- src/systems/si/CMakeLists.txt | 31 ----- src/systems/typographic/CMakeLists.txt | 25 ---- src/systems/usc/CMakeLists.txt | 25 ---- src/utility/CMakeLists.txt | 29 ----- test/CMakeLists.txt | 6 +- test/{unit_test => }/runtime/CMakeLists.txt | 8 +- test/{unit_test => }/runtime/almost_equals.h | 2 +- .../runtime/distribution_test.cpp | 0 test/{unit_test => }/runtime/fmt_test.cpp | 2 +- .../runtime/linear_algebra_test.cpp | 2 +- test/{unit_test => }/runtime/math_test.cpp | 3 +- test/{unit_test => }/static/CMakeLists.txt | 14 +-- test/{unit_test => }/static/angular_test.cpp | 0 test/{unit_test => }/static/cgs_test.cpp | 0 test/{unit_test => }/static/chrono_test.cpp | 3 +- test/{unit_test => }/static/compare_test.cpp | 0 test/{unit_test => }/static/concepts_test.cpp | 1 - .../static/custom_rep_test_min_expl.cpp | 0 .../static/custom_rep_test_min_impl.cpp | 0 .../{unit_test => }/static/dimension_test.cpp | 0 .../static/fixed_string_test.cpp | 0 .../static/fractional_exponent_quantity.cpp | 2 +- test/{unit_test => }/static/hep_test.cpp | 0 test/{unit_test => }/static/iau_test.cpp | 0 test/{unit_test => }/static/iec80000_test.cpp | 0 test/{unit_test => }/static/imperial_test.cpp | 0 .../static/international_test.cpp | 0 .../{unit_test => }/static/isq_angle_test.cpp | 0 test/{unit_test => }/static/isq_test.cpp | 0 .../{unit_test => }/static/magnitude_test.cpp | 0 test/{unit_test => }/static/math_test.cpp | 0 test/{unit_test => }/static/natural_test.cpp | 0 test/{unit_test => }/static/prime_test.cpp | 0 .../static/quantity_point_test.cpp | 1 - .../static/quantity_spec_test.cpp | 0 test/{unit_test => }/static/quantity_test.cpp | 1 - test/{unit_test => }/static/ratio_test.cpp | 0 .../{unit_test => }/static/reference_test.cpp | 0 test/{unit_test => }/static/si_test.cpp | 0 .../static/symbol_text_test.cpp | 0 test/{unit_test => }/static/test_tools.h | 2 +- .../{unit_test => }/static/type_list_test.cpp | 0 .../static/typographic_test.cpp | 0 .../static/unit_symbol_test.cpp | 0 test/{unit_test => }/static/unit_test.cpp | 0 test/{unit_test => }/static/usc_test.cpp | 0 129 files changed, 271 insertions(+), 838 deletions(-) delete mode 100644 src/core-fmt-macros/CMakeLists.txt rename src/{core-fmt-macros/include/mp-units/bits/fmt_hacks.h => core-fmt/include/mp-units/compat_fmt_macros.h} (100%) rename src/{ => core-fmt}/mp-units-core-fmt.cpp (60%) rename src/{ => core-io}/mp-units-core-io.cpp (78%) delete mode 100644 src/core-macros/CMakeLists.txt rename src/{core-macros/include/mp-units/bits/core-gmf.h => core/include/mp-units/bits/core_gmf.h} (99%) rename src/{core-macros => core}/include/mp-units/bits/external/hacks.h (95%) rename src/{utility => core}/include/mp-units/compare.h (100%) rename src/{core-macros/include/mp-units/quantity_spec_macro.h => core/include/mp-units/compat_macros.h} (97%) rename src/{utility/include/mp-units/bits/math_core.h => core/include/mp-units/math.h} (100%) rename src/{utility => core}/include/mp-units/random.h (100%) create mode 100644 src/core/mp-units-core.cpp delete mode 100644 src/mp-units-core.cpp delete mode 100644 src/systems/angular/CMakeLists.txt delete mode 100644 src/systems/cgs/CMakeLists.txt delete mode 100644 src/systems/hep/CMakeLists.txt delete mode 100644 src/systems/iau/CMakeLists.txt delete mode 100644 src/systems/iec80000/CMakeLists.txt delete mode 100644 src/systems/imperial/CMakeLists.txt rename src/{utility/include/mp-units/math.h => systems/include/mp-units/systems/angular/angular.h} (74%) rename src/{utility/include/mp-units/bits/math_angular.h => systems/include/mp-units/systems/angular/math.h} (99%) rename src/systems/{angular/include/mp-units/systems/angular/angular.h => include/mp-units/systems/angular/units.h} (100%) rename src/systems/{cgs => }/include/mp-units/systems/cgs/cgs.h (100%) rename src/systems/{hep => }/include/mp-units/systems/hep/hep.h (100%) rename src/systems/{iau => }/include/mp-units/systems/iau/iau.h (100%) rename src/systems/{iec80000 => }/include/mp-units/systems/iec80000/binary_prefixes.h (100%) rename src/systems/{iec80000 => }/include/mp-units/systems/iec80000/iec80000.h (100%) rename src/systems/{iec80000 => }/include/mp-units/systems/iec80000/quantities.h (100%) rename src/systems/{iec80000 => }/include/mp-units/systems/iec80000/unit_symbols.h (100%) rename src/systems/{iec80000 => }/include/mp-units/systems/iec80000/units.h (100%) rename src/systems/{imperial => }/include/mp-units/systems/imperial/imperial.h (100%) rename src/systems/{international => }/include/mp-units/systems/international/international.h (100%) rename src/systems/{isq => }/include/mp-units/systems/isq/atomic_and_nuclear_physics.h (100%) rename src/systems/{isq => }/include/mp-units/systems/isq/base_quantities.h (100%) rename src/systems/{isq => }/include/mp-units/systems/isq/electromagnetism.h (100%) rename src/systems/{isq => }/include/mp-units/systems/isq/isq.h (100%) rename src/systems/{isq => }/include/mp-units/systems/isq/mechanics.h (100%) rename src/systems/{isq => }/include/mp-units/systems/isq/space_and_time.h (100%) rename src/systems/{isq => }/include/mp-units/systems/isq/thermodynamics.h (100%) rename src/systems/{isq_angle => }/include/mp-units/systems/isq_angle/isq_angle.h (100%) rename src/systems/{natural => }/include/mp-units/systems/natural/natural.h (100%) rename src/{utility/include/mp-units => systems/include/mp-units/systems/si}/chrono.h (100%) rename src/systems/{si => }/include/mp-units/systems/si/constants.h (100%) rename src/{utility/include/mp-units/bits/math_si.h => systems/include/mp-units/systems/si/math.h} (100%) rename src/systems/{si => }/include/mp-units/systems/si/prefixes.h (100%) rename src/systems/{si => }/include/mp-units/systems/si/si.h (94%) rename src/systems/{si => }/include/mp-units/systems/si/unit_symbols.h (100%) rename src/systems/{si => }/include/mp-units/systems/si/units.h (100%) rename src/systems/{typographic => }/include/mp-units/systems/typographic/typographic.h (100%) rename src/systems/{usc => }/include/mp-units/systems/usc/usc.h (100%) delete mode 100644 src/systems/international/CMakeLists.txt delete mode 100644 src/systems/isq/CMakeLists.txt delete mode 100644 src/systems/isq_angle/CMakeLists.txt rename src/{ => systems}/mp-units-systems.cpp (80%) delete mode 100644 src/systems/natural/CMakeLists.txt delete mode 100644 src/systems/si/CMakeLists.txt delete mode 100644 src/systems/typographic/CMakeLists.txt delete mode 100644 src/systems/usc/CMakeLists.txt delete mode 100644 src/utility/CMakeLists.txt rename test/{unit_test => }/runtime/CMakeLists.txt (87%) rename test/{unit_test => }/runtime/almost_equals.h (98%) rename test/{unit_test => }/runtime/distribution_test.cpp (100%) rename test/{unit_test => }/runtime/fmt_test.cpp (99%) rename test/{unit_test => }/runtime/linear_algebra_test.cpp (99%) rename test/{unit_test => }/runtime/math_test.cpp (99%) rename test/{unit_test => }/static/CMakeLists.txt (84%) rename test/{unit_test => }/static/angular_test.cpp (100%) rename test/{unit_test => }/static/cgs_test.cpp (100%) rename test/{unit_test => }/static/chrono_test.cpp (99%) rename test/{unit_test => }/static/compare_test.cpp (100%) rename test/{unit_test => }/static/concepts_test.cpp (99%) rename test/{unit_test => }/static/custom_rep_test_min_expl.cpp (100%) rename test/{unit_test => }/static/custom_rep_test_min_impl.cpp (100%) rename test/{unit_test => }/static/dimension_test.cpp (100%) rename test/{unit_test => }/static/fixed_string_test.cpp (100%) rename test/{unit_test => }/static/fractional_exponent_quantity.cpp (98%) rename test/{unit_test => }/static/hep_test.cpp (100%) rename test/{unit_test => }/static/iau_test.cpp (100%) rename test/{unit_test => }/static/iec80000_test.cpp (100%) rename test/{unit_test => }/static/imperial_test.cpp (100%) rename test/{unit_test => }/static/international_test.cpp (100%) rename test/{unit_test => }/static/isq_angle_test.cpp (100%) rename test/{unit_test => }/static/isq_test.cpp (100%) rename test/{unit_test => }/static/magnitude_test.cpp (100%) rename test/{unit_test => }/static/math_test.cpp (100%) rename test/{unit_test => }/static/natural_test.cpp (100%) rename test/{unit_test => }/static/prime_test.cpp (100%) rename test/{unit_test => }/static/quantity_point_test.cpp (99%) rename test/{unit_test => }/static/quantity_spec_test.cpp (100%) rename test/{unit_test => }/static/quantity_test.cpp (99%) rename test/{unit_test => }/static/ratio_test.cpp (100%) rename test/{unit_test => }/static/reference_test.cpp (100%) rename test/{unit_test => }/static/si_test.cpp (100%) rename test/{unit_test => }/static/symbol_text_test.cpp (100%) rename test/{unit_test => }/static/test_tools.h (97%) rename test/{unit_test => }/static/type_list_test.cpp (100%) rename test/{unit_test => }/static/typographic_test.cpp (100%) rename test/{unit_test => }/static/unit_symbol_test.cpp (100%) rename test/{unit_test => }/static/unit_test.cpp (100%) rename test/{unit_test => }/static/usc_test.cpp (100%) diff --git a/.cmake-format.yaml b/.cmake-format.yaml index 2956b76e..537bcefb 100644 --- a/.cmake-format.yaml +++ b/.cmake-format.yaml @@ -1,22 +1,12 @@ parse: additional_commands: - add_documentation: - pargs: - nargs: 1 - flags: - - ALL - kwargs: - BREATHE_PROJECT: 1 - CODE_SOURCE_DIR: 1 - INSTALL_DIR: 1 - CODE_DEPENDS: 1 - DOCS_DEPENDS: 1 add_units_module: pargs: nargs: 1 kwargs: - DEPENDENCIES: + - HEADERS: + + DEPENDENCIES: "+" + HEADERS: "*" + MODULE_INTERFACE_UNIT: "?" enable_iwyu: pargs: flags: @@ -26,13 +16,6 @@ parse: kwargs: MAPPING_FILE: 1 MAX_LINE_LENGTH: 1 - metabench_add_chart: - pargs: - nargs: 1 - kwargs: - TITLE: 1 - SUBTITLE: 1 - DATASETS: + format: line_width: 120 tab_size: 4 diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 33d09727..4a268ce4 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -27,53 +27,47 @@ if(NOT TARGET gsl::gsl-lite) find_package(gsl-lite CONFIG REQUIRED) endif() +if(${projectPrefix}BUILD_CXX_MODULES) add_library(example_utils INTERFACE) +target_compile_definitions(example_utils INTERFACE ${projectPrefix}MODULES) target_include_directories(example_utils INTERFACE include) target_link_libraries(example_utils INTERFACE gsl::gsl-lite) +endif() + +add_library(example_utils-headers INTERFACE) +target_include_directories(example_utils-headers INTERFACE include) +target_link_libraries(example_utils-headers INTERFACE gsl::gsl-lite) # -# add_example(target ...) +# add_example(target ...) # function(add_example target) - add_executable(${target} ${target}.cpp) - if(TARGET mp-units::modules) - target_link_libraries(${target} PRIVATE mp-units::modules) - else() - target_link_libraries(${target} PRIVATE ${ARGN}) + if(${projectPrefix}BUILD_CXX_MODULES) + add_executable(${target} ${target}.cpp) + target_compile_definitions(${target} PUBLIC ${projectPrefix}MODULES) + target_link_libraries(${target} PRIVATE mp-units::mp-units ${ARGN}) endif() + + add_executable(${target}-headers ${target}.cpp) + list(TRANSFORM ARGN APPEND "-headers") + target_link_libraries(${target}-headers PRIVATE mp-units::mp-units ${ARGN}) endfunction() -add_example(avg_speed mp-units::core-io mp-units::si mp-units::cgs mp-units::usc) -add_example(capacitor_time_curve mp-units::core-io mp-units::si mp-units::utility) -add_example( - clcpp_response - mp-units::core-fmt - mp-units::core-io - mp-units::si - mp-units::iau - mp-units::imperial - mp-units::international - mp-units::typographic - mp-units::usc -) -add_example(conversion_factor mp-units::core-fmt mp-units::core-io mp-units::si) -add_example(currency mp-units::core-io) -add_example(foot_pound_second mp-units::core-fmt mp-units::international mp-units::imperial) -add_example(glide_computer mp-units::core-fmt mp-units::international mp-units::utility) -target_link_libraries(glide_computer PRIVATE glide_computer_lib) -add_example(hello_units mp-units::core-fmt mp-units::core-io mp-units::si mp-units::usc) -add_example(measurement mp-units::core-io mp-units::si) -add_example(si_constants mp-units::core-fmt mp-units::si) -add_example(spectroscopy_units mp-units::core-fmt mp-units::si) -add_example(storage_tank mp-units::core-fmt mp-units::si mp-units::utility) -add_example( - strong_angular_quantities mp-units::core-fmt mp-units::core-io mp-units::si mp-units::isq_angle mp-units::utility -) -add_example(total_energy mp-units::core-io mp-units::si mp-units::natural mp-units::utility) -add_example( - unmanned_aerial_vehicle mp-units::core-fmt mp-units::core-io mp-units::si mp-units::international mp-units::utility -) -target_link_libraries(unmanned_aerial_vehicle PRIVATE example_utils) +add_example(avg_speed) +add_example(capacitor_time_curve) +add_example(clcpp_response) +add_example(conversion_factor) +add_example(currency) +add_example(foot_pound_second) +add_example(glide_computer glide_computer_lib) +add_example(hello_units) +add_example(measurement) +add_example(si_constants) +add_example(spectroscopy_units) +add_example(storage_tank) +add_example(strong_angular_quantities) +add_example(total_energy) +add_example(unmanned_aerial_vehicle example_utils) add_subdirectory(glide_computer_lib) add_subdirectory(kalman_filter) diff --git a/example/clcpp_response.cpp b/example/clcpp_response.cpp index 58cdd912..1bf0bbb5 100644 --- a/example/clcpp_response.cpp +++ b/example/clcpp_response.cpp @@ -15,7 +15,7 @@ along with this program. If not, see http://www.gnu.org/licenses./ */ -#include +#include #include #ifdef MP_UNITS_MODULES import mp_units; diff --git a/example/conversion_factor.cpp b/example/conversion_factor.cpp index 2b666b9c..d6846f4d 100644 --- a/example/conversion_factor.cpp +++ b/example/conversion_factor.cpp @@ -15,7 +15,7 @@ along with this program. If not, see http://www.gnu.org/licenses./ */ -#include +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/currency.cpp b/example/currency.cpp index 57cf5a57..65527711 100644 --- a/example/currency.cpp +++ b/example/currency.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/foot_pound_second.cpp b/example/foot_pound_second.cpp index bfb5719d..63a303fc 100644 --- a/example/foot_pound_second.cpp +++ b/example/foot_pound_second.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/glide_computer.cpp b/example/glide_computer.cpp index cefe692e..c691d12d 100644 --- a/example/glide_computer.cpp +++ b/example/glide_computer.cpp @@ -21,7 +21,7 @@ // SOFTWARE. #include "glide_computer_lib.h" -#include +#include #include #include #include @@ -32,10 +32,9 @@ #ifdef MP_UNITS_MODULES import mp_units; #else -#include #include #include -#include +#include #endif namespace { diff --git a/example/glide_computer_lib/CMakeLists.txt b/example/glide_computer_lib/CMakeLists.txt index 65d11b35..810a666c 100644 --- a/example/glide_computer_lib/CMakeLists.txt +++ b/example/glide_computer_lib/CMakeLists.txt @@ -22,11 +22,13 @@ cmake_minimum_required(VERSION 3.5) -add_library(glide_computer_lib STATIC glide_computer_lib.cpp include/glide_computer_lib.h) -if(TARGET mp-units::modules) - target_link_libraries(glide_computer_lib PUBLIC gsl::gsl-lite mp-units::modules) -else() - target_link_libraries(glide_computer_lib PRIVATE mp-units::core-fmt PUBLIC mp-units::si mp-units::utility) +add_library(glide_computer_lib-headers STATIC glide_computer_lib.cpp include/glide_computer_lib.h) +target_link_libraries(glide_computer_lib-headers PUBLIC mp-units::mp-units example_utils) +target_include_directories(glide_computer_lib-headers PUBLIC include) + +if(${projectPrefix}BUILD_CXX_MODULES) + add_library(glide_computer_lib STATIC glide_computer_lib.cpp include/glide_computer_lib.h) + 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) endif() -target_link_libraries(glide_computer_lib PUBLIC example_utils) -target_include_directories(glide_computer_lib PUBLIC include) diff --git a/example/glide_computer_lib/include/glide_computer_lib.h b/example/glide_computer_lib/include/glide_computer_lib.h index 50229a9b..b198dabf 100644 --- a/example/glide_computer_lib/include/glide_computer_lib.h +++ b/example/glide_computer_lib/include/glide_computer_lib.h @@ -22,7 +22,7 @@ #pragma once -#include +#include // #include "geographic.h" #include @@ -36,10 +36,10 @@ #ifdef MP_UNITS_MODULES import mp_units; #else -#include #include // IWYU pragma: keep #include #include +#include #endif // An example of a really simplified tactical glide computer diff --git a/example/hello_units.cpp b/example/hello_units.cpp index 6bc12235..e707cd99 100644 --- a/example/hello_units.cpp +++ b/example/hello_units.cpp @@ -25,7 +25,7 @@ // !!! renders correctly in the documentation "Examples" section. !!! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -#include +#include #include #ifdef MP_UNITS_MODULES import mp_units; diff --git a/example/include/geographic.h b/example/include/geographic.h index ade0f6e0..3d285bd8 100644 --- a/example/include/geographic.h +++ b/example/include/geographic.h @@ -23,7 +23,7 @@ #pragma once #include "ranged_representation.h" -#include +#include #include #include #include @@ -33,11 +33,10 @@ import mp_units; #else #include #include -#include #include #include #include -#include +#include #endif namespace geographic { diff --git a/example/include/validated_type.h b/example/include/validated_type.h index 77422ccc..9924fc4a 100644 --- a/example/include/validated_type.h +++ b/example/include/validated_type.h @@ -23,7 +23,7 @@ #pragma once #include -#include +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/kalman_filter/CMakeLists.txt b/example/kalman_filter/CMakeLists.txt index 4c7954d9..d1d1a6c8 100644 --- a/example/kalman_filter/CMakeLists.txt +++ b/example/kalman_filter/CMakeLists.txt @@ -22,23 +22,11 @@ cmake_minimum_required(VERSION 3.5) -# -# add_example(target ...) -# -function(add_example target) - add_executable(${target} ${target}.cpp) - if(TARGET mp-units::modules) - target_link_libraries(${target} PRIVATE mp-units::modules) - else() - target_link_libraries(${target} PRIVATE ${ARGN}) - endif() -endfunction() - -add_example(kalman_filter-example_1 mp-units::core-fmt mp-units::si mp-units::utility) -add_example(kalman_filter-example_2 mp-units::core-fmt mp-units::si mp-units::utility) -add_example(kalman_filter-example_3 mp-units::core-fmt mp-units::si mp-units::utility) -add_example(kalman_filter-example_4 mp-units::core-fmt mp-units::si mp-units::utility) -add_example(kalman_filter-example_5 mp-units::core-fmt mp-units::si mp-units::utility) -add_example(kalman_filter-example_6 mp-units::core-fmt mp-units::si mp-units::utility) -add_example(kalman_filter-example_7 mp-units::core-fmt mp-units::si mp-units::utility) -add_example(kalman_filter-example_8 mp-units::core-fmt mp-units::si mp-units::utility) +add_example(kalman_filter-example_1) +add_example(kalman_filter-example_2) +add_example(kalman_filter-example_3) +add_example(kalman_filter-example_4) +add_example(kalman_filter-example_5) +add_example(kalman_filter-example_6) +add_example(kalman_filter-example_7) +add_example(kalman_filter-example_8) diff --git a/example/kalman_filter/kalman.h b/example/kalman_filter/kalman.h index 310d9941..9115aae3 100644 --- a/example/kalman_filter/kalman.h +++ b/example/kalman_filter/kalman.h @@ -22,7 +22,7 @@ #pragma once -#include +#include #include #ifdef MP_UNITS_MODULES import mp_units; diff --git a/example/si_constants.cpp b/example/si_constants.cpp index 35d855d5..e3d02d6e 100644 --- a/example/si_constants.cpp +++ b/example/si_constants.cpp @@ -25,7 +25,7 @@ // !!! renders correctly in the documentation "Examples" section. !!! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -#include +#include #include #ifdef MP_UNITS_MODULES import mp_units; diff --git a/example/spectroscopy_units.cpp b/example/spectroscopy_units.cpp index 7a6270d6..71da66d5 100644 --- a/example/spectroscopy_units.cpp +++ b/example/spectroscopy_units.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/storage_tank.cpp b/example/storage_tank.cpp index 84d1c42c..a2317384 100644 --- a/example/storage_tank.cpp +++ b/example/storage_tank.cpp @@ -20,8 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include -#include +#include +#include #include #include #include @@ -30,14 +30,11 @@ #ifdef MP_UNITS_MODULES import mp_units; #else -#include #include #include #include #include -#include -#include -#include +#include #endif // allows standard gravity (acceleration) and weight (force) to be expressed with scalar representation diff --git a/example/unmanned_aerial_vehicle.cpp b/example/unmanned_aerial_vehicle.cpp index 6e089939..35978aab 100644 --- a/example/unmanned_aerial_vehicle.cpp +++ b/example/unmanned_aerial_vehicle.cpp @@ -21,7 +21,7 @@ // SOFTWARE. #include "geographic.h" -#include +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c8a43497..b3f87735 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,84 +36,26 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") include(AddUnitsModule) include(GNUInstallDirs) +if(${projectPrefix}BUILD_CXX_MODULES) + set(${projectPrefix}TARGET_SCOPE "PUBLIC") +else() + set(${projectPrefix}TARGET_SCOPE "INTERFACE") +endif() + if(${projectPrefix}AS_SYSTEM_HEADERS) set(unitsAsSystem SYSTEM) endif() -add_subdirectory(core-macros) add_subdirectory(core) -add_subdirectory(core-fmt-macros) add_subdirectory(core-fmt) add_subdirectory(core-io) add_subdirectory(systems) -add_subdirectory(utility) # project-wide wrapper -add_library(mp-units INTERFACE) -target_link_libraries( - mp-units INTERFACE mp-units::core mp-units::core-io mp-units::core-fmt mp-units::systems mp-units::utility +add_units_module( + mp-units DEPENDENCIES mp-units::core mp-units::core-io mp-units::core-fmt mp-units::systems + MODULE_INTERFACE_UNIT mp-units.cpp ) -add_library(mp-units::mp-units ALIAS mp-units) -install(TARGETS mp-units EXPORT mp-unitsTargets) - -# C++ modules -if(${projectPrefix}BUILD_CXX_MODULES) - add_library(mp-units-core-module) - add_library(mp-units::core-module ALIAS mp-units-core-module) - target_sources( - mp-units-core-module PUBLIC FILE_SET CXX_MODULES BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES - "mp-units-core.cpp" - ) - target_compile_definitions(mp-units-core-module PUBLIC ${projectPrefix}MODULES) - target_link_libraries(mp-units-core-module PRIVATE mp-units::core mp-units::utility PUBLIC mp-units::core-macros) - if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18) - target_compile_definitions(mp-units-core-module PUBLIC _LIBCPP_NO_ABI_TAG) - endif() - - if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18) - target_compile_options(mp-units-core-module PUBLIC "-Wno-include-angled-in-module-purview") - endif() - endif() - - add_library(mp-units-core-fmt-module) - add_library(mp-units::core-fmt-module ALIAS mp-units-core-fmt-module) - target_sources( - mp-units-core-fmt-module PUBLIC FILE_SET CXX_MODULES BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES - "mp-units-core-fmt.cpp" - ) - target_link_libraries( - mp-units-core-fmt-module PRIVATE mp-units::core-fmt PUBLIC mp-units::core-fmt-macros mp-units::core-module - ) - - add_library(mp-units-core-io-module) - add_library(mp-units::core-io-module ALIAS mp-units-core-io-module) - target_sources( - mp-units-core-io-module PUBLIC FILE_SET CXX_MODULES BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES - "mp-units-core-io.cpp" - ) - target_link_libraries(mp-units-core-io-module PRIVATE mp-units::core-io PUBLIC mp-units::core-module) - - add_library(mp-units-systems-module) - add_library(mp-units::systems-module ALIAS mp-units-systems-module) - target_sources( - mp-units-systems-module PUBLIC FILE_SET CXX_MODULES BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES - "mp-units-systems.cpp" - ) - target_link_libraries( - mp-units-systems-module PRIVATE mp-units::systems mp-units::utility PUBLIC mp-units::core-module - ) - - add_library(mp-units-modules) - add_library(mp-units::modules ALIAS mp-units-modules) - target_sources( - mp-units-modules PUBLIC FILE_SET CXX_MODULES BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES "mp-units.cpp" - ) - target_link_libraries( - mp-units-modules PUBLIC mp-units::core-module mp-units::core-fmt-module mp-units::core-io-module - mp-units::systems-module - ) -endif() # local build export(EXPORT mp-unitsTargets NAMESPACE mp-units::) diff --git a/src/cmake/AddUnitsModule.cmake b/src/cmake/AddUnitsModule.cmake index de89f1af..4e0ac2a4 100644 --- a/src/cmake/AddUnitsModule.cmake +++ b/src/cmake/AddUnitsModule.cmake @@ -43,27 +43,46 @@ endfunction() # # add_units_module(ModuleName # DEPENDENCIES ... -# HEADERS ...) +# [HEADERS ...] +# MODULE_INTERFACE_UNIT ) # function(add_units_module name) # parse arguments + set(oneValue MODULE_INTERFACE_UNIT) set(multiValues DEPENDENCIES HEADERS) - cmake_parse_arguments(PARSE_ARGV 1 ARG "" "" "${multiValues}") + cmake_parse_arguments(PARSE_ARGV 1 ARG "" "${oneValue}" "${multiValues}") # validate and process arguments validate_unparsed(${name} ARG) - validate_arguments_exists(${name} ARG DEPENDENCIES HEADERS) + validate_arguments_exists(${name} ARG DEPENDENCIES MODULE_INTERFACE_UNIT) + + if(${projectPrefix}TARGET_SCOPE STREQUAL INTERFACE) + set(SCOPE "INTERFACE") + endif() # define the target for a module - add_library(mp-units-${name} INTERFACE ${ARG_HEADERS}) - target_link_libraries(mp-units-${name} INTERFACE ${ARG_DEPENDENCIES}) - target_include_directories( - mp-units-${name} ${unitsAsSystem} INTERFACE $ - $ - ) + add_library(mp-units-${name} ${SCOPE} ${ARG_HEADERS}) + target_link_libraries(mp-units-${name} ${${projectPrefix}TARGET_SCOPE} ${ARG_DEPENDENCIES}) + if(ARG_HEADERS) + target_include_directories( + mp-units-${name} ${unitsAsSystem} ${${projectPrefix}TARGET_SCOPE} + $ $ + ) + endif() set_target_properties(mp-units-${name} PROPERTIES EXPORT_NAME ${name}) add_library(mp-units::${name} ALIAS mp-units-${name}) - install(TARGETS mp-units-${name} EXPORT mp-unitsTargets) - install(DIRECTORY include/mp-units TYPE INCLUDE) + if(${projectPrefix}BUILD_CXX_MODULES) + target_sources(mp-units-${name} PUBLIC FILE_SET CXX_MODULES FILES ${ARG_MODULE_INTERFACE_UNIT}) + install(TARGETS mp-units-${name} + EXPORT mp-unitsTargets + FILE_SET CXX_MODULES + DESTINATION ${CMAKE_INSTALL_LIBDIR}/miu + ) + else() + install(TARGETS mp-units-${name} EXPORT mp-unitsTargets) + endif() + if(ARG_HEADERS) + install(DIRECTORY include/mp-units TYPE INCLUDE) + endif() endfunction() diff --git a/src/core-fmt-macros/CMakeLists.txt b/src/core-fmt-macros/CMakeLists.txt deleted file mode 100644 index 8f6bc13c..00000000 --- a/src/core-fmt-macros/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -# core-fmt-macros library definition -add_library(mp-units-core-fmt-macros INTERFACE include/mp-units/bits/fmt_hacks.h) -target_include_directories( - mp-units-core-fmt-macros ${unitsAsSystem} INTERFACE $ - $ -) -target_link_libraries(mp-units-core-fmt-macros INTERFACE mp-units::core-macros) - -if(${projectPrefix}USE_LIBFMT) - if(NOT TARGET fmt::fmt) - find_package(fmt CONFIG REQUIRED) - endif() - target_link_libraries(mp-units-core-fmt-macros INTERFACE fmt::fmt) -endif() - -set_target_properties(mp-units-core-fmt-macros PROPERTIES EXPORT_NAME core-fmt-macros) -add_library(mp-units::core-fmt-macros ALIAS mp-units-core-fmt-macros) - -# installation -install(TARGETS mp-units-core-fmt-macros EXPORT mp-unitsTargets) -install(DIRECTORY include/mp-units TYPE INCLUDE) diff --git a/src/core-fmt/CMakeLists.txt b/src/core-fmt/CMakeLists.txt index 35a59370..71a643da 100644 --- a/src/core-fmt/CMakeLists.txt +++ b/src/core-fmt/CMakeLists.txt @@ -25,13 +25,19 @@ cmake_minimum_required(VERSION 3.19) option(${projectPrefix}USE_LIBFMT "Enables usage of libfmt instead of the one from 'std'" ON) message(STATUS "${projectPrefix}USE_LIBFMT: ${${projectPrefix}USE_LIBFMT}") -add_units_module(core-fmt DEPENDENCIES mp-units::core HEADERS include/mp-units/format.h) -target_compile_definitions(mp-units-core-fmt INTERFACE ${projectPrefix}USE_LIBFMT=$) -target_link_libraries(mp-units-core-fmt INTERFACE mp-units::core-fmt-macros) +add_units_module( + core-fmt + DEPENDENCIES mp-units::core + HEADERS include/mp-units/bits/fmt.h include/mp-units/compat_fmt_macros.h include/mp-units/format.h + MODULE_INTERFACE_UNIT mp-units-core-fmt.cpp +) +target_compile_definitions( + mp-units-core-fmt ${${projectPrefix}TARGET_SCOPE} ${projectPrefix}USE_LIBFMT=$ +) if(${projectPrefix}USE_LIBFMT) if(NOT TARGET fmt::fmt) find_package(fmt CONFIG REQUIRED) endif() - target_link_libraries(mp-units-core-fmt INTERFACE fmt::fmt) + target_link_libraries(mp-units-core-fmt ${${projectPrefix}TARGET_SCOPE} fmt::fmt) endif() diff --git a/src/core-fmt/include/mp-units/bits/fmt.h b/src/core-fmt/include/mp-units/bits/fmt.h index 973f01ad..28fa08ea 100644 --- a/src/core-fmt/include/mp-units/bits/fmt.h +++ b/src/core-fmt/include/mp-units/bits/fmt.h @@ -30,7 +30,7 @@ #pragma once #include -#include +#include #include #include #include diff --git a/src/core-fmt-macros/include/mp-units/bits/fmt_hacks.h b/src/core-fmt/include/mp-units/compat_fmt_macros.h similarity index 100% rename from src/core-fmt-macros/include/mp-units/bits/fmt_hacks.h rename to src/core-fmt/include/mp-units/compat_fmt_macros.h diff --git a/src/mp-units-core-fmt.cpp b/src/core-fmt/mp-units-core-fmt.cpp similarity index 60% rename from src/mp-units-core-fmt.cpp rename to src/core-fmt/mp-units-core-fmt.cpp index 8576e7bb..da3e62e8 100644 --- a/src/mp-units-core-fmt.cpp +++ b/src/core-fmt/mp-units-core-fmt.cpp @@ -1,7 +1,7 @@ module; -#include -#include +#include +#include export module mp_units.core_fmt; diff --git a/src/core-io/CMakeLists.txt b/src/core-io/CMakeLists.txt index d4ae7a20..6f991530 100644 --- a/src/core-io/CMakeLists.txt +++ b/src/core-io/CMakeLists.txt @@ -22,4 +22,9 @@ cmake_minimum_required(VERSION 3.19) -add_units_module(core-io DEPENDENCIES mp-units::core HEADERS include/mp-units/ostream.h) +add_units_module( + core-io + DEPENDENCIES mp-units::core + HEADERS include/mp-units/ostream.h + MODULE_INTERFACE_UNIT mp-units-core-io.cpp +) diff --git a/src/mp-units-core-io.cpp b/src/core-io/mp-units-core-io.cpp similarity index 78% rename from src/mp-units-core-io.cpp rename to src/core-io/mp-units-core-io.cpp index db16a2df..b31e7803 100644 --- a/src/mp-units-core-io.cpp +++ b/src/core-io/mp-units-core-io.cpp @@ -1,6 +1,6 @@ module; -#include +#include #include export module mp_units.core_io; diff --git a/src/core-macros/CMakeLists.txt b/src/core-macros/CMakeLists.txt deleted file mode 100644 index 38bfe974..00000000 --- a/src/core-macros/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -# core-macros library definition -add_library( - mp-units-core-macros INTERFACE include/mp-units/bits/external/hacks.h include/mp-units/quantity_spec_macro.h -) -target_compile_features(mp-units-core-macros INTERFACE cxx_std_20) -target_include_directories( - mp-units-core-macros ${unitsAsSystem} INTERFACE $ - $ -) - -set_target_properties(mp-units-core-macros PROPERTIES EXPORT_NAME core-macros) -add_library(mp-units::core-macros ALIAS mp-units-core-macros) - -# installation -install(TARGETS mp-units-core-macros EXPORT mp-unitsTargets) -install(DIRECTORY include/mp-units TYPE INCLUDE) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index ed0270cd..46143809 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -28,60 +28,67 @@ if(NOT TARGET gsl::gsl-lite) endif() # core library definition -add_library( - mp-units-core - INTERFACE - include/mp-units/bits/external/algorithm.h - include/mp-units/bits/external/fixed_string.h - include/mp-units/bits/external/math_concepts.h - include/mp-units/bits/external/prime.h - include/mp-units/bits/external/type_list.h - include/mp-units/bits/external/type_name.h - include/mp-units/bits/external/type_traits.h - include/mp-units/bits/dimension_concepts.h - include/mp-units/bits/expression_template.h - include/mp-units/bits/get_associated_quantity.h - include/mp-units/bits/get_common_base.h - include/mp-units/bits/magnitude.h - include/mp-units/bits/quantity_cast.h - include/mp-units/bits/quantity_concepts.h - include/mp-units/bits/quantity_point_concepts.h - include/mp-units/bits/quantity_spec_concepts.h - include/mp-units/bits/ratio.h - include/mp-units/bits/reference_concepts.h - include/mp-units/bits/representation_concepts.h - include/mp-units/bits/sudo_cast.h - include/mp-units/bits/symbol_text.h - include/mp-units/bits/text_tools.h - include/mp-units/bits/unit_concepts.h - include/mp-units/bits/value_cast.h - include/mp-units/concepts.h - include/mp-units/core.h - include/mp-units/customization_points.h - include/mp-units/dimension.h - include/mp-units/quantity.h - include/mp-units/quantity_point.h - include/mp-units/quantity_spec.h - include/mp-units/reference.h - include/mp-units/system_reference.h - include/mp-units/unit.h -) -target_link_libraries(mp-units-core INTERFACE gsl::gsl-lite mp-units::core-macros) -target_include_directories( - mp-units-core ${unitsAsSystem} INTERFACE $ - $ +add_units_module( + core + DEPENDENCIES gsl::gsl-lite + HEADERS include/mp-units/bits/external/algorithm.h + include/mp-units/bits/external/fixed_string.h + include/mp-units/bits/external/hacks.h + include/mp-units/bits/external/math_concepts.h + include/mp-units/bits/external/prime.h + include/mp-units/bits/external/type_list.h + include/mp-units/bits/external/type_name.h + include/mp-units/bits/external/type_traits.h + include/mp-units/bits/core_gmf.h + include/mp-units/bits/dimension_concepts.h + include/mp-units/bits/expression_template.h + include/mp-units/bits/get_associated_quantity.h + include/mp-units/bits/get_common_base.h + include/mp-units/bits/magnitude.h + include/mp-units/bits/quantity_cast.h + include/mp-units/bits/quantity_concepts.h + include/mp-units/bits/quantity_point_concepts.h + include/mp-units/bits/quantity_spec_concepts.h + include/mp-units/bits/ratio.h + include/mp-units/bits/reference_concepts.h + include/mp-units/bits/representation_concepts.h + include/mp-units/bits/sudo_cast.h + include/mp-units/bits/symbol_text.h + include/mp-units/bits/text_tools.h + include/mp-units/bits/unit_concepts.h + include/mp-units/bits/value_cast.h + include/mp-units/compare.h + include/mp-units/compat_macros.h + include/mp-units/concepts.h + include/mp-units/core.h + include/mp-units/customization_points.h + include/mp-units/dimension.h + include/mp-units/math.h + include/mp-units/quantity.h + include/mp-units/quantity_point.h + include/mp-units/quantity_spec.h + include/mp-units/random.h + include/mp-units/reference.h + include/mp-units/system_reference.h + include/mp-units/unit.h + MODULE_INTERFACE_UNIT mp-units-core.cpp ) +if(${projectPrefix}BUILD_CXX_MODULES) + if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18) + target_compile_definitions(mp-units-core PUBLIC _LIBCPP_NO_ABI_TAG) + endif() + + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18) + target_compile_options(mp-units-core PUBLIC "-Wno-include-angled-in-module-purview") + endif() + endif() +endif() + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options( - mp-units-core - INTERFACE /utf-8 # Specifies both the source character set and the execution character set as UTF-8 + mp-units-core ${${projectPrefix}TARGET_SCOPE} + /utf-8 # Specifies both the source character set and the execution character set as UTF-8 ) endif() - -set_target_properties(mp-units-core PROPERTIES EXPORT_NAME core) -add_library(mp-units::core ALIAS mp-units-core) - -# installation -install(TARGETS mp-units-core EXPORT mp-unitsTargets) -install(DIRECTORY include/mp-units TYPE INCLUDE) diff --git a/src/core-macros/include/mp-units/bits/core-gmf.h b/src/core/include/mp-units/bits/core_gmf.h similarity index 99% rename from src/core-macros/include/mp-units/bits/core-gmf.h rename to src/core/include/mp-units/bits/core_gmf.h index fdcd10ad..8c21e6ec 100644 --- a/src/core-macros/include/mp-units/bits/core-gmf.h +++ b/src/core/include/mp-units/bits/core_gmf.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -44,7 +46,5 @@ #include #include -// utility +// si #include -#include -#include diff --git a/src/core-macros/include/mp-units/bits/external/hacks.h b/src/core/include/mp-units/bits/external/hacks.h similarity index 95% rename from src/core-macros/include/mp-units/bits/external/hacks.h rename to src/core/include/mp-units/bits/external/hacks.h index f943dc25..6bf6f45d 100644 --- a/src/core-macros/include/mp-units/bits/external/hacks.h +++ b/src/core/include/mp-units/bits/external/hacks.h @@ -22,8 +22,6 @@ #pragma once -#include - #if __clang__ #define MP_UNITS_COMP_CLANG __clang_major__ #elif __GNUC__ @@ -70,9 +68,6 @@ #define MP_UNITS_DIAGNOSTIC_IGNORE_DEPRECATED #endif -#include -#include - #if MP_UNITS_COMP_MSVC #define MP_UNITS_TYPENAME typename @@ -83,7 +78,7 @@ #endif -#if (defined MP_UNITS_COMP_CLANG && MP_UNITS_COMP_CLANG < 17) || (defined MP_UNITS_COMP_GCC && MP_UNITS_COMP_GCC < 12) +#if (defined MP_UNITS_COMP_CLANG && MP_UNITS_COMP_CLANG < 17) #define MP_UNITS_CONSTEVAL constexpr diff --git a/src/utility/include/mp-units/compare.h b/src/core/include/mp-units/compare.h similarity index 100% rename from src/utility/include/mp-units/compare.h rename to src/core/include/mp-units/compare.h diff --git a/src/core-macros/include/mp-units/quantity_spec_macro.h b/src/core/include/mp-units/compat_macros.h similarity index 97% rename from src/core-macros/include/mp-units/quantity_spec_macro.h rename to src/core/include/mp-units/compat_macros.h index 9e45b833..4ab02761 100644 --- a/src/core-macros/include/mp-units/quantity_spec_macro.h +++ b/src/core/include/mp-units/compat_macros.h @@ -22,6 +22,8 @@ #pragma once +#include + #ifdef __cpp_explicit_this_parameter #define QUANTITY_SPEC(name, ...) \ diff --git a/src/core/include/mp-units/core.h b/src/core/include/mp-units/core.h index 209076f0..e92ceb28 100644 --- a/src/core/include/mp-units/core.h +++ b/src/core/include/mp-units/core.h @@ -22,13 +22,16 @@ #pragma once -#include +#include +#include #include #include #include +#include #include #include #include +#include #include #include #include diff --git a/src/utility/include/mp-units/bits/math_core.h b/src/core/include/mp-units/math.h similarity index 100% rename from src/utility/include/mp-units/bits/math_core.h rename to src/core/include/mp-units/math.h diff --git a/src/core/include/mp-units/quantity_point.h b/src/core/include/mp-units/quantity_point.h index 73d1f66c..c42994c0 100644 --- a/src/core/include/mp-units/quantity_point.h +++ b/src/core/include/mp-units/quantity_point.h @@ -23,27 +23,13 @@ #pragma once #include +#include #include #include #include namespace mp_units { -namespace detail { - -template - requires requires { - { - T::zero() - } -> std::equality_comparable_with; - } -[[nodiscard]] constexpr bool is_eq_zero(T v) -{ - return v == T::zero(); -} - -} // namespace detail - template struct absolute_point_origin { static constexpr QuantitySpec auto quantity_spec = QS; @@ -95,11 +81,9 @@ template else if constexpr (detail::RelativePointOrigin && detail::RelativePointOrigin) return PO1::quantity_point == PO2::quantity_point; else if constexpr (detail::RelativePointOrigin) - return detail::same_absolute_point_origins(po1, po2) && - detail::is_eq_zero(PO1::quantity_point.quantity_from_zero()); + return detail::same_absolute_point_origins(po1, po2) && is_eq_zero(PO1::quantity_point.quantity_from_zero()); else if constexpr (detail::RelativePointOrigin) - return detail::same_absolute_point_origins(po1, po2) && - detail::is_eq_zero(PO2::quantity_point.quantity_from_zero()); + return detail::same_absolute_point_origins(po1, po2) && is_eq_zero(PO2::quantity_point.quantity_from_zero()); } template diff --git a/src/core/include/mp-units/quantity_spec.h b/src/core/include/mp-units/quantity_spec.h index 4550c1e7..556b8cd2 100644 --- a/src/core/include/mp-units/quantity_spec.h +++ b/src/core/include/mp-units/quantity_spec.h @@ -31,8 +31,8 @@ #include #include #include +#include #include -#include #include namespace mp_units { diff --git a/src/utility/include/mp-units/random.h b/src/core/include/mp-units/random.h similarity index 100% rename from src/utility/include/mp-units/random.h rename to src/core/include/mp-units/random.h diff --git a/src/core/mp-units-core.cpp b/src/core/mp-units-core.cpp new file mode 100644 index 00000000..17a3d87c --- /dev/null +++ b/src/core/mp-units-core.cpp @@ -0,0 +1,10 @@ +module; + +#include + +export module mp_units.core; + +export +{ +#include +} diff --git a/src/mp-units-core.cpp b/src/mp-units-core.cpp deleted file mode 100644 index 2826e6fe..00000000 --- a/src/mp-units-core.cpp +++ /dev/null @@ -1,15 +0,0 @@ -module; - -#include - -export module mp_units.core; - -export -{ -// core -#include - -// utility -#include -#include -} diff --git a/src/systems/CMakeLists.txt b/src/systems/CMakeLists.txt index b21c786b..95e20497 100644 --- a/src/systems/CMakeLists.txt +++ b/src/systems/CMakeLists.txt @@ -22,40 +22,39 @@ cmake_minimum_required(VERSION 3.19) -# systems -add_subdirectory(angular) -add_subdirectory(iec80000) -add_subdirectory(isq) -add_subdirectory(isq_angle) -add_subdirectory(natural) -add_subdirectory(si) -add_subdirectory(cgs) -add_subdirectory(hep) -add_subdirectory(iau) -add_subdirectory(imperial) -add_subdirectory(international) -add_subdirectory(typographic) -add_subdirectory(usc) - -# wrapper for all the systems -add_library(mp-units-systems INTERFACE) -target_link_libraries( - mp-units-systems - INTERFACE - mp-units::angular - mp-units::iec80000 - mp-units::isq - mp-units::isq_angle - mp-units::natural - mp-units::si - mp-units::cgs - mp-units::hep - mp-units::iau - mp-units::imperial - mp-units::international - mp-units::typographic - mp-units::usc +add_units_module( + systems + DEPENDENCIES mp-units::core + HEADERS include/mp-units/systems/angular/angular.h + include/mp-units/systems/angular/math.h + include/mp-units/systems/angular/units.h + include/mp-units/systems/cgs/cgs.h + include/mp-units/systems/hep/hep.h + include/mp-units/systems/iau/iau.h + include/mp-units/systems/iec80000/binary_prefixes.h + include/mp-units/systems/iec80000/iec80000.h + include/mp-units/systems/iec80000/quantities.h + include/mp-units/systems/iec80000/unit_symbols.h + include/mp-units/systems/iec80000/units.h + include/mp-units/systems/imperial/imperial.h + include/mp-units/systems/international/international.h + include/mp-units/systems/isq/atomic_and_nuclear_physics.h + include/mp-units/systems/isq/base_quantities.h + include/mp-units/systems/isq/electromagnetism.h + include/mp-units/systems/isq/isq.h + include/mp-units/systems/isq/mechanics.h + include/mp-units/systems/isq/space_and_time.h + include/mp-units/systems/isq/thermodynamics.h + include/mp-units/systems/isq_angle/isq_angle.h + include/mp-units/systems/natural/natural.h + include/mp-units/systems/si/chrono.h + include/mp-units/systems/si/constants.h + include/mp-units/systems/si/math.h + include/mp-units/systems/si/prefixes.h + include/mp-units/systems/si/si.h + include/mp-units/systems/si/unit_symbols.h + include/mp-units/systems/si/units.h + include/mp-units/systems/typographic/typographic.h + include/mp-units/systems/usc/usc.h + MODULE_INTERFACE_UNIT mp-units-systems.cpp ) -add_library(mp-units::systems ALIAS mp-units-systems) -set_target_properties(mp-units-systems PROPERTIES EXPORT_NAME systems) -install(TARGETS mp-units-systems EXPORT mp-unitsTargets) diff --git a/src/systems/angular/CMakeLists.txt b/src/systems/angular/CMakeLists.txt deleted file mode 100644 index 2c7886b2..00000000 --- a/src/systems/angular/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -add_units_module(angular DEPENDENCIES mp-units::isq HEADERS include/mp-units/systems/angular/angular.h) diff --git a/src/systems/cgs/CMakeLists.txt b/src/systems/cgs/CMakeLists.txt deleted file mode 100644 index 604b5937..00000000 --- a/src/systems/cgs/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -add_units_module(cgs DEPENDENCIES mp-units::si HEADERS include/mp-units/systems/cgs/cgs.h) diff --git a/src/systems/hep/CMakeLists.txt b/src/systems/hep/CMakeLists.txt deleted file mode 100644 index b09581b4..00000000 --- a/src/systems/hep/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2021 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -add_units_module(hep DEPENDENCIES mp-units::si HEADERS include/mp-units/systems/hep/hep.h) diff --git a/src/systems/iau/CMakeLists.txt b/src/systems/iau/CMakeLists.txt deleted file mode 100644 index 6f1cbd6d..00000000 --- a/src/systems/iau/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -add_units_module(iau DEPENDENCIES mp-units::si HEADERS include/mp-units/systems/iau/iau.h) diff --git a/src/systems/iec80000/CMakeLists.txt b/src/systems/iec80000/CMakeLists.txt deleted file mode 100644 index f1bd31ca..00000000 --- a/src/systems/iec80000/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -add_units_module( - iec80000 - DEPENDENCIES mp-units::isq mp-units::si - HEADERS include/mp-units/systems/iec80000/binary_prefixes.h include/mp-units/systems/iec80000/quantities.h - include/mp-units/systems/iec80000/iec80000.h include/mp-units/systems/iec80000/unit_symbols.h - include/mp-units/systems/iec80000/units.h -) diff --git a/src/systems/imperial/CMakeLists.txt b/src/systems/imperial/CMakeLists.txt deleted file mode 100644 index cdde9f2f..00000000 --- a/src/systems/imperial/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -add_units_module( - imperial DEPENDENCIES mp-units::si mp-units::international HEADERS include/mp-units/systems/imperial/imperial.h -) diff --git a/src/utility/include/mp-units/math.h b/src/systems/include/mp-units/systems/angular/angular.h similarity index 74% rename from src/utility/include/mp-units/math.h rename to src/systems/include/mp-units/systems/angular/angular.h index 53743dee..e9461440 100644 --- a/src/utility/include/mp-units/math.h +++ b/src/systems/include/mp-units/systems/angular/angular.h @@ -22,12 +22,5 @@ #pragma once -#include -#include -#include - -// This header is intentionally empty and just include other headers -// `math.h` is just a convenience wrapper for not modular code -// With C++20 modules: -// - math_core is a part of the mp_units.core module -// - math_si and math_angular is provided with the mp_units.systems module +#include +#include diff --git a/src/utility/include/mp-units/bits/math_angular.h b/src/systems/include/mp-units/systems/angular/math.h similarity index 99% rename from src/utility/include/mp-units/bits/math_angular.h rename to src/systems/include/mp-units/systems/angular/math.h index aa49afb5..f2954f05 100644 --- a/src/utility/include/mp-units/bits/math_angular.h +++ b/src/systems/include/mp-units/systems/angular/math.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include // IWYU pragma: begin_exports diff --git a/src/systems/angular/include/mp-units/systems/angular/angular.h b/src/systems/include/mp-units/systems/angular/units.h similarity index 100% rename from src/systems/angular/include/mp-units/systems/angular/angular.h rename to src/systems/include/mp-units/systems/angular/units.h diff --git a/src/systems/cgs/include/mp-units/systems/cgs/cgs.h b/src/systems/include/mp-units/systems/cgs/cgs.h similarity index 100% rename from src/systems/cgs/include/mp-units/systems/cgs/cgs.h rename to src/systems/include/mp-units/systems/cgs/cgs.h diff --git a/src/systems/hep/include/mp-units/systems/hep/hep.h b/src/systems/include/mp-units/systems/hep/hep.h similarity index 100% rename from src/systems/hep/include/mp-units/systems/hep/hep.h rename to src/systems/include/mp-units/systems/hep/hep.h diff --git a/src/systems/iau/include/mp-units/systems/iau/iau.h b/src/systems/include/mp-units/systems/iau/iau.h similarity index 100% rename from src/systems/iau/include/mp-units/systems/iau/iau.h rename to src/systems/include/mp-units/systems/iau/iau.h diff --git a/src/systems/iec80000/include/mp-units/systems/iec80000/binary_prefixes.h b/src/systems/include/mp-units/systems/iec80000/binary_prefixes.h similarity index 100% rename from src/systems/iec80000/include/mp-units/systems/iec80000/binary_prefixes.h rename to src/systems/include/mp-units/systems/iec80000/binary_prefixes.h diff --git a/src/systems/iec80000/include/mp-units/systems/iec80000/iec80000.h b/src/systems/include/mp-units/systems/iec80000/iec80000.h similarity index 100% rename from src/systems/iec80000/include/mp-units/systems/iec80000/iec80000.h rename to src/systems/include/mp-units/systems/iec80000/iec80000.h diff --git a/src/systems/iec80000/include/mp-units/systems/iec80000/quantities.h b/src/systems/include/mp-units/systems/iec80000/quantities.h similarity index 100% rename from src/systems/iec80000/include/mp-units/systems/iec80000/quantities.h rename to src/systems/include/mp-units/systems/iec80000/quantities.h diff --git a/src/systems/iec80000/include/mp-units/systems/iec80000/unit_symbols.h b/src/systems/include/mp-units/systems/iec80000/unit_symbols.h similarity index 100% rename from src/systems/iec80000/include/mp-units/systems/iec80000/unit_symbols.h rename to src/systems/include/mp-units/systems/iec80000/unit_symbols.h diff --git a/src/systems/iec80000/include/mp-units/systems/iec80000/units.h b/src/systems/include/mp-units/systems/iec80000/units.h similarity index 100% rename from src/systems/iec80000/include/mp-units/systems/iec80000/units.h rename to src/systems/include/mp-units/systems/iec80000/units.h diff --git a/src/systems/imperial/include/mp-units/systems/imperial/imperial.h b/src/systems/include/mp-units/systems/imperial/imperial.h similarity index 100% rename from src/systems/imperial/include/mp-units/systems/imperial/imperial.h rename to src/systems/include/mp-units/systems/imperial/imperial.h diff --git a/src/systems/international/include/mp-units/systems/international/international.h b/src/systems/include/mp-units/systems/international/international.h similarity index 100% rename from src/systems/international/include/mp-units/systems/international/international.h rename to src/systems/include/mp-units/systems/international/international.h diff --git a/src/systems/isq/include/mp-units/systems/isq/atomic_and_nuclear_physics.h b/src/systems/include/mp-units/systems/isq/atomic_and_nuclear_physics.h similarity index 100% rename from src/systems/isq/include/mp-units/systems/isq/atomic_and_nuclear_physics.h rename to src/systems/include/mp-units/systems/isq/atomic_and_nuclear_physics.h diff --git a/src/systems/isq/include/mp-units/systems/isq/base_quantities.h b/src/systems/include/mp-units/systems/isq/base_quantities.h similarity index 100% rename from src/systems/isq/include/mp-units/systems/isq/base_quantities.h rename to src/systems/include/mp-units/systems/isq/base_quantities.h diff --git a/src/systems/isq/include/mp-units/systems/isq/electromagnetism.h b/src/systems/include/mp-units/systems/isq/electromagnetism.h similarity index 100% rename from src/systems/isq/include/mp-units/systems/isq/electromagnetism.h rename to src/systems/include/mp-units/systems/isq/electromagnetism.h diff --git a/src/systems/isq/include/mp-units/systems/isq/isq.h b/src/systems/include/mp-units/systems/isq/isq.h similarity index 100% rename from src/systems/isq/include/mp-units/systems/isq/isq.h rename to src/systems/include/mp-units/systems/isq/isq.h diff --git a/src/systems/isq/include/mp-units/systems/isq/mechanics.h b/src/systems/include/mp-units/systems/isq/mechanics.h similarity index 100% rename from src/systems/isq/include/mp-units/systems/isq/mechanics.h rename to src/systems/include/mp-units/systems/isq/mechanics.h diff --git a/src/systems/isq/include/mp-units/systems/isq/space_and_time.h b/src/systems/include/mp-units/systems/isq/space_and_time.h similarity index 100% rename from src/systems/isq/include/mp-units/systems/isq/space_and_time.h rename to src/systems/include/mp-units/systems/isq/space_and_time.h diff --git a/src/systems/isq/include/mp-units/systems/isq/thermodynamics.h b/src/systems/include/mp-units/systems/isq/thermodynamics.h similarity index 100% rename from src/systems/isq/include/mp-units/systems/isq/thermodynamics.h rename to src/systems/include/mp-units/systems/isq/thermodynamics.h diff --git a/src/systems/isq_angle/include/mp-units/systems/isq_angle/isq_angle.h b/src/systems/include/mp-units/systems/isq_angle/isq_angle.h similarity index 100% rename from src/systems/isq_angle/include/mp-units/systems/isq_angle/isq_angle.h rename to src/systems/include/mp-units/systems/isq_angle/isq_angle.h diff --git a/src/systems/natural/include/mp-units/systems/natural/natural.h b/src/systems/include/mp-units/systems/natural/natural.h similarity index 100% rename from src/systems/natural/include/mp-units/systems/natural/natural.h rename to src/systems/include/mp-units/systems/natural/natural.h diff --git a/src/utility/include/mp-units/chrono.h b/src/systems/include/mp-units/systems/si/chrono.h similarity index 100% rename from src/utility/include/mp-units/chrono.h rename to src/systems/include/mp-units/systems/si/chrono.h diff --git a/src/systems/si/include/mp-units/systems/si/constants.h b/src/systems/include/mp-units/systems/si/constants.h similarity index 100% rename from src/systems/si/include/mp-units/systems/si/constants.h rename to src/systems/include/mp-units/systems/si/constants.h diff --git a/src/utility/include/mp-units/bits/math_si.h b/src/systems/include/mp-units/systems/si/math.h similarity index 100% rename from src/utility/include/mp-units/bits/math_si.h rename to src/systems/include/mp-units/systems/si/math.h diff --git a/src/systems/si/include/mp-units/systems/si/prefixes.h b/src/systems/include/mp-units/systems/si/prefixes.h similarity index 100% rename from src/systems/si/include/mp-units/systems/si/prefixes.h rename to src/systems/include/mp-units/systems/si/prefixes.h diff --git a/src/systems/si/include/mp-units/systems/si/si.h b/src/systems/include/mp-units/systems/si/si.h similarity index 94% rename from src/systems/si/include/mp-units/systems/si/si.h rename to src/systems/include/mp-units/systems/si/si.h index 9efad6f3..b2668de5 100644 --- a/src/systems/si/include/mp-units/systems/si/si.h +++ b/src/systems/include/mp-units/systems/si/si.h @@ -22,7 +22,9 @@ #pragma once +#include #include +#include #include #include #include diff --git a/src/systems/si/include/mp-units/systems/si/unit_symbols.h b/src/systems/include/mp-units/systems/si/unit_symbols.h similarity index 100% rename from src/systems/si/include/mp-units/systems/si/unit_symbols.h rename to src/systems/include/mp-units/systems/si/unit_symbols.h diff --git a/src/systems/si/include/mp-units/systems/si/units.h b/src/systems/include/mp-units/systems/si/units.h similarity index 100% rename from src/systems/si/include/mp-units/systems/si/units.h rename to src/systems/include/mp-units/systems/si/units.h diff --git a/src/systems/typographic/include/mp-units/systems/typographic/typographic.h b/src/systems/include/mp-units/systems/typographic/typographic.h similarity index 100% rename from src/systems/typographic/include/mp-units/systems/typographic/typographic.h rename to src/systems/include/mp-units/systems/typographic/typographic.h diff --git a/src/systems/usc/include/mp-units/systems/usc/usc.h b/src/systems/include/mp-units/systems/usc/usc.h similarity index 100% rename from src/systems/usc/include/mp-units/systems/usc/usc.h rename to src/systems/include/mp-units/systems/usc/usc.h diff --git a/src/systems/international/CMakeLists.txt b/src/systems/international/CMakeLists.txt deleted file mode 100644 index 36844f97..00000000 --- a/src/systems/international/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -add_units_module(international DEPENDENCIES mp-units::si HEADERS include/mp-units/systems/international/international.h) diff --git a/src/systems/isq/CMakeLists.txt b/src/systems/isq/CMakeLists.txt deleted file mode 100644 index c0276bf1..00000000 --- a/src/systems/isq/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -add_units_module( - isq - DEPENDENCIES mp-units::core - HEADERS include/mp-units/systems/isq/atomic_and_nuclear_physics.h - include/mp-units/systems/isq/base_quantities.h - include/mp-units/systems/isq/electromagnetism.h - include/mp-units/systems/isq/isq.h - include/mp-units/systems/isq/mechanics.h - include/mp-units/systems/isq/space_and_time.h - include/mp-units/systems/isq/thermodynamics.h -) diff --git a/src/systems/isq_angle/CMakeLists.txt b/src/systems/isq_angle/CMakeLists.txt deleted file mode 100644 index be5b3b9f..00000000 --- a/src/systems/isq_angle/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -add_units_module( - isq_angle DEPENDENCIES mp-units::angular mp-units::isq HEADERS include/mp-units/systems/isq_angle/isq_angle.h -) diff --git a/src/mp-units-systems.cpp b/src/systems/mp-units-systems.cpp similarity index 80% rename from src/mp-units-systems.cpp rename to src/systems/mp-units-systems.cpp index eaa63218..f9494203 100644 --- a/src/mp-units-systems.cpp +++ b/src/systems/mp-units-systems.cpp @@ -1,7 +1,7 @@ module; -#include -#include +#include +#include export module mp_units.systems; @@ -9,7 +9,6 @@ export import mp_units.core; export { -// systems #include #include #include @@ -23,8 +22,4 @@ export #include #include #include - -// utility -#include -#include } diff --git a/src/systems/natural/CMakeLists.txt b/src/systems/natural/CMakeLists.txt deleted file mode 100644 index 1489b2e8..00000000 --- a/src/systems/natural/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -add_units_module(natural DEPENDENCIES mp-units::isq HEADERS include/mp-units/systems/natural/natural.h) diff --git a/src/systems/si/CMakeLists.txt b/src/systems/si/CMakeLists.txt deleted file mode 100644 index 7f9de7a8..00000000 --- a/src/systems/si/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -add_units_module( - si - DEPENDENCIES mp-units::isq - HEADERS include/mp-units/systems/si/constants.h include/mp-units/systems/si/prefixes.h - include/mp-units/systems/si/si.h include/mp-units/systems/si/unit_symbols.h - include/mp-units/systems/si/units.h -) diff --git a/src/systems/typographic/CMakeLists.txt b/src/systems/typographic/CMakeLists.txt deleted file mode 100644 index f9bd1a7c..00000000 --- a/src/systems/typographic/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -add_units_module(typographic DEPENDENCIES mp-units::usc HEADERS include/mp-units/systems/typographic/typographic.h) diff --git a/src/systems/usc/CMakeLists.txt b/src/systems/usc/CMakeLists.txt deleted file mode 100644 index d5041e29..00000000 --- a/src/systems/usc/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -add_units_module(usc DEPENDENCIES mp-units::si mp-units::international HEADERS include/mp-units/systems/usc/usc.h) diff --git a/src/utility/CMakeLists.txt b/src/utility/CMakeLists.txt deleted file mode 100644 index a9642ef0..00000000 --- a/src/utility/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -add_units_module( - utility DEPENDENCIES mp-units::core mp-units::isq mp-units::si mp-units::angular - HEADERS include/mp-units/bits/math_angular.h include/mp-units/bits/math_core.h include/mp-units/bits/math_si.h - include/mp-units/chrono.h include/mp-units/math.h include/mp-units/random.h -) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0b8c706a..8430bfa4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -22,7 +22,5 @@ cmake_minimum_required(VERSION 3.5) -add_subdirectory(unit_test/runtime) -add_subdirectory(unit_test/static) - -# add_subdirectory(metabench) +add_subdirectory(runtime) +add_subdirectory(static) diff --git a/test/unit_test/runtime/CMakeLists.txt b/test/runtime/CMakeLists.txt similarity index 87% rename from test/unit_test/runtime/CMakeLists.txt rename to test/runtime/CMakeLists.txt index 21686ab5..29fa0036 100644 --- a/test/unit_test/runtime/CMakeLists.txt +++ b/test/runtime/CMakeLists.txt @@ -25,12 +25,10 @@ cmake_minimum_required(VERSION 3.5) find_package(Catch2 3 CONFIG REQUIRED) add_executable(unit_tests_runtime distribution_test.cpp fmt_test.cpp math_test.cpp) -if(TARGET mp-units::modules) - target_link_libraries(unit_tests_runtime PRIVATE mp-units::modules) -else() - target_link_libraries(unit_tests_runtime PRIVATE mp-units::mp-units) +if(${projectPrefix}BUILD_CXX_MODULES) + target_compile_definitions(unit_tests_runtime PUBLIC ${projectPrefix}MODULES) endif() -target_link_libraries(unit_tests_runtime PRIVATE Catch2::Catch2WithMain) +target_link_libraries(unit_tests_runtime PRIVATE mp-units::mp-units Catch2::Catch2WithMain) if(${projectPrefix}BUILD_LA) find_package(wg21_linear_algebra CONFIG REQUIRED) diff --git a/test/unit_test/runtime/almost_equals.h b/test/runtime/almost_equals.h similarity index 98% rename from test/unit_test/runtime/almost_equals.h rename to test/runtime/almost_equals.h index 8a871fe9..5913c990 100644 --- a/test/unit_test/runtime/almost_equals.h +++ b/test/runtime/almost_equals.h @@ -21,7 +21,7 @@ // SOFTWARE. #include -#include +#include #include #ifdef MP_UNITS_MODULES import mp_units; diff --git a/test/unit_test/runtime/distribution_test.cpp b/test/runtime/distribution_test.cpp similarity index 100% rename from test/unit_test/runtime/distribution_test.cpp rename to test/runtime/distribution_test.cpp diff --git a/test/unit_test/runtime/fmt_test.cpp b/test/runtime/fmt_test.cpp similarity index 99% rename from test/unit_test/runtime/fmt_test.cpp rename to test/runtime/fmt_test.cpp index 482838b4..ef914a1f 100644 --- a/test/unit_test/runtime/fmt_test.cpp +++ b/test/runtime/fmt_test.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include diff --git a/test/unit_test/runtime/linear_algebra_test.cpp b/test/runtime/linear_algebra_test.cpp similarity index 99% rename from test/unit_test/runtime/linear_algebra_test.cpp rename to test/runtime/linear_algebra_test.cpp index 4e227728..cbdb9c6c 100644 --- a/test/unit_test/runtime/linear_algebra_test.cpp +++ b/test/runtime/linear_algebra_test.cpp @@ -21,7 +21,7 @@ // SOFTWARE. #include -#include +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/test/unit_test/runtime/math_test.cpp b/test/runtime/math_test.cpp similarity index 99% rename from test/unit_test/runtime/math_test.cpp rename to test/runtime/math_test.cpp index c6dcc589..c4e6b759 100644 --- a/test/unit_test/runtime/math_test.cpp +++ b/test/runtime/math_test.cpp @@ -30,8 +30,7 @@ import mp_units; #include #include #include -#include -#include +#include #endif using namespace mp_units; diff --git a/test/unit_test/static/CMakeLists.txt b/test/static/CMakeLists.txt similarity index 84% rename from test/unit_test/static/CMakeLists.txt rename to test/static/CMakeLists.txt index 37cb00c7..2f660568 100644 --- a/test/unit_test/static/CMakeLists.txt +++ b/test/static/CMakeLists.txt @@ -23,11 +23,10 @@ cmake_minimum_required(VERSION 3.5) add_library(unit_tests_static_truncating quantity_test.cpp) -if(TARGET mp-units::modules) - target_link_libraries(unit_tests_static_truncating PRIVATE mp-units::modules) -else() - target_link_libraries(unit_tests_static_truncating PRIVATE mp-units::mp-units) +if(${projectPrefix}BUILD_CXX_MODULES) + target_compile_definitions(unit_tests_static_truncating PUBLIC ${projectPrefix}MODULES) endif() +target_link_libraries(unit_tests_static_truncating PRIVATE mp-units::mp-units) target_compile_options( unit_tests_static_truncating PRIVATE $,/wd4242 /wd4244,-Wno-conversion> ) @@ -68,9 +67,8 @@ add_library( usc_test.cpp ) -if(TARGET mp-units::modules) - target_link_libraries(unit_tests_static PRIVATE mp-units::modules) -else() - target_link_libraries(unit_tests_static PRIVATE mp-units::mp-units) +target_link_libraries(unit_tests_static PRIVATE mp-units::mp-units) +if(${projectPrefix}BUILD_CXX_MODULES) + target_compile_definitions(unit_tests_static PUBLIC ${projectPrefix}MODULES) endif() target_link_libraries(unit_tests_static PRIVATE unit_tests_static_truncating) diff --git a/test/unit_test/static/angular_test.cpp b/test/static/angular_test.cpp similarity index 100% rename from test/unit_test/static/angular_test.cpp rename to test/static/angular_test.cpp diff --git a/test/unit_test/static/cgs_test.cpp b/test/static/cgs_test.cpp similarity index 100% rename from test/unit_test/static/cgs_test.cpp rename to test/static/cgs_test.cpp diff --git a/test/unit_test/static/chrono_test.cpp b/test/static/chrono_test.cpp similarity index 99% rename from test/unit_test/static/chrono_test.cpp rename to test/static/chrono_test.cpp index df5fa356..dc807697 100644 --- a/test/unit_test/static/chrono_test.cpp +++ b/test/static/chrono_test.cpp @@ -27,9 +27,8 @@ import mp_units; #else #include -#include #include -#include +#include #endif namespace { diff --git a/test/unit_test/static/compare_test.cpp b/test/static/compare_test.cpp similarity index 100% rename from test/unit_test/static/compare_test.cpp rename to test/static/compare_test.cpp diff --git a/test/unit_test/static/concepts_test.cpp b/test/static/concepts_test.cpp similarity index 99% rename from test/unit_test/static/concepts_test.cpp rename to test/static/concepts_test.cpp index 2c050f8b..3bfd265d 100644 --- a/test/unit_test/static/concepts_test.cpp +++ b/test/static/concepts_test.cpp @@ -27,7 +27,6 @@ #ifdef MP_UNITS_MODULES import mp_units; #else -#include #include #include #include diff --git a/test/unit_test/static/custom_rep_test_min_expl.cpp b/test/static/custom_rep_test_min_expl.cpp similarity index 100% rename from test/unit_test/static/custom_rep_test_min_expl.cpp rename to test/static/custom_rep_test_min_expl.cpp diff --git a/test/unit_test/static/custom_rep_test_min_impl.cpp b/test/static/custom_rep_test_min_impl.cpp similarity index 100% rename from test/unit_test/static/custom_rep_test_min_impl.cpp rename to test/static/custom_rep_test_min_impl.cpp diff --git a/test/unit_test/static/dimension_test.cpp b/test/static/dimension_test.cpp similarity index 100% rename from test/unit_test/static/dimension_test.cpp rename to test/static/dimension_test.cpp diff --git a/test/unit_test/static/fixed_string_test.cpp b/test/static/fixed_string_test.cpp similarity index 100% rename from test/unit_test/static/fixed_string_test.cpp rename to test/static/fixed_string_test.cpp diff --git a/test/unit_test/static/fractional_exponent_quantity.cpp b/test/static/fractional_exponent_quantity.cpp similarity index 98% rename from test/unit_test/static/fractional_exponent_quantity.cpp rename to test/static/fractional_exponent_quantity.cpp index 6014b34e..3e3c79ca 100644 --- a/test/unit_test/static/fractional_exponent_quantity.cpp +++ b/test/static/fractional_exponent_quantity.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include +#include #ifdef MP_UNITS_MODULES import mp_units; #else diff --git a/test/unit_test/static/hep_test.cpp b/test/static/hep_test.cpp similarity index 100% rename from test/unit_test/static/hep_test.cpp rename to test/static/hep_test.cpp diff --git a/test/unit_test/static/iau_test.cpp b/test/static/iau_test.cpp similarity index 100% rename from test/unit_test/static/iau_test.cpp rename to test/static/iau_test.cpp diff --git a/test/unit_test/static/iec80000_test.cpp b/test/static/iec80000_test.cpp similarity index 100% rename from test/unit_test/static/iec80000_test.cpp rename to test/static/iec80000_test.cpp diff --git a/test/unit_test/static/imperial_test.cpp b/test/static/imperial_test.cpp similarity index 100% rename from test/unit_test/static/imperial_test.cpp rename to test/static/imperial_test.cpp diff --git a/test/unit_test/static/international_test.cpp b/test/static/international_test.cpp similarity index 100% rename from test/unit_test/static/international_test.cpp rename to test/static/international_test.cpp diff --git a/test/unit_test/static/isq_angle_test.cpp b/test/static/isq_angle_test.cpp similarity index 100% rename from test/unit_test/static/isq_angle_test.cpp rename to test/static/isq_angle_test.cpp diff --git a/test/unit_test/static/isq_test.cpp b/test/static/isq_test.cpp similarity index 100% rename from test/unit_test/static/isq_test.cpp rename to test/static/isq_test.cpp diff --git a/test/unit_test/static/magnitude_test.cpp b/test/static/magnitude_test.cpp similarity index 100% rename from test/unit_test/static/magnitude_test.cpp rename to test/static/magnitude_test.cpp diff --git a/test/unit_test/static/math_test.cpp b/test/static/math_test.cpp similarity index 100% rename from test/unit_test/static/math_test.cpp rename to test/static/math_test.cpp diff --git a/test/unit_test/static/natural_test.cpp b/test/static/natural_test.cpp similarity index 100% rename from test/unit_test/static/natural_test.cpp rename to test/static/natural_test.cpp diff --git a/test/unit_test/static/prime_test.cpp b/test/static/prime_test.cpp similarity index 100% rename from test/unit_test/static/prime_test.cpp rename to test/static/prime_test.cpp diff --git a/test/unit_test/static/quantity_point_test.cpp b/test/static/quantity_point_test.cpp similarity index 99% rename from test/unit_test/static/quantity_point_test.cpp rename to test/static/quantity_point_test.cpp index b44da9f0..3ffe3615 100644 --- a/test/unit_test/static/quantity_point_test.cpp +++ b/test/static/quantity_point_test.cpp @@ -28,7 +28,6 @@ #include import mp_units; #else -#include #include #include #include diff --git a/test/unit_test/static/quantity_spec_test.cpp b/test/static/quantity_spec_test.cpp similarity index 100% rename from test/unit_test/static/quantity_spec_test.cpp rename to test/static/quantity_spec_test.cpp diff --git a/test/unit_test/static/quantity_test.cpp b/test/static/quantity_test.cpp similarity index 99% rename from test/unit_test/static/quantity_test.cpp rename to test/static/quantity_test.cpp index ed038077..891cf21d 100644 --- a/test/unit_test/static/quantity_test.cpp +++ b/test/static/quantity_test.cpp @@ -29,7 +29,6 @@ #include import mp_units; #else -#include #include #include #include diff --git a/test/unit_test/static/ratio_test.cpp b/test/static/ratio_test.cpp similarity index 100% rename from test/unit_test/static/ratio_test.cpp rename to test/static/ratio_test.cpp diff --git a/test/unit_test/static/reference_test.cpp b/test/static/reference_test.cpp similarity index 100% rename from test/unit_test/static/reference_test.cpp rename to test/static/reference_test.cpp diff --git a/test/unit_test/static/si_test.cpp b/test/static/si_test.cpp similarity index 100% rename from test/unit_test/static/si_test.cpp rename to test/static/si_test.cpp diff --git a/test/unit_test/static/symbol_text_test.cpp b/test/static/symbol_text_test.cpp similarity index 100% rename from test/unit_test/static/symbol_text_test.cpp rename to test/static/symbol_text_test.cpp diff --git a/test/unit_test/static/test_tools.h b/test/static/test_tools.h similarity index 97% rename from test/unit_test/static/test_tools.h rename to test/static/test_tools.h index bf6f77a5..27587442 100644 --- a/test/unit_test/static/test_tools.h +++ b/test/static/test_tools.h @@ -24,7 +24,7 @@ #include #ifdef MP_UNITS_MODULES -#include +#include import mp_units; #else #include diff --git a/test/unit_test/static/type_list_test.cpp b/test/static/type_list_test.cpp similarity index 100% rename from test/unit_test/static/type_list_test.cpp rename to test/static/type_list_test.cpp diff --git a/test/unit_test/static/typographic_test.cpp b/test/static/typographic_test.cpp similarity index 100% rename from test/unit_test/static/typographic_test.cpp rename to test/static/typographic_test.cpp diff --git a/test/unit_test/static/unit_symbol_test.cpp b/test/static/unit_symbol_test.cpp similarity index 100% rename from test/unit_test/static/unit_symbol_test.cpp rename to test/static/unit_symbol_test.cpp diff --git a/test/unit_test/static/unit_test.cpp b/test/static/unit_test.cpp similarity index 100% rename from test/unit_test/static/unit_test.cpp rename to test/static/unit_test.cpp diff --git a/test/unit_test/static/usc_test.cpp b/test/static/usc_test.cpp similarity index 100% rename from test/unit_test/static/usc_test.cpp rename to test/static/usc_test.cpp From 271a8117eeaf4cf5f6cdbb751a3af1a9b7e30287 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 13/33] fix: glide-computer compilation with headers fixed --- example/glide_computer_lib/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/glide_computer_lib/CMakeLists.txt b/example/glide_computer_lib/CMakeLists.txt index 810a666c..56dce4a2 100644 --- a/example/glide_computer_lib/CMakeLists.txt +++ b/example/glide_computer_lib/CMakeLists.txt @@ -23,7 +23,7 @@ cmake_minimum_required(VERSION 3.5) add_library(glide_computer_lib-headers STATIC glide_computer_lib.cpp include/glide_computer_lib.h) -target_link_libraries(glide_computer_lib-headers PUBLIC mp-units::mp-units example_utils) +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}BUILD_CXX_MODULES) From 3095b28bd65a95aed842cf8d6b45fb8d868a412f Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 14/33] build: triggering C++ modules build added to Conan --- conanfile.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/conanfile.py b/conanfile.py index d8d8e141..3d1d667e 100644 --- a/conanfile.py +++ b/conanfile.py @@ -54,6 +54,13 @@ class MPUnitsConan(ConanFile): license = "MIT" url = "https://github.com/mpusz/mp-units" settings = "os", "arch", "compiler", "build_type" + options = { + "cxx_modules": [True, False], + } + default_options = { + "cxx_modules": False, + } + exports = ["LICENSE.md"] exports_sources = [ "docs/*", @@ -133,6 +140,9 @@ class MPUnitsConan(ConanFile): def generate(self): tc = CMakeToolchain(self) + if self.options.cxx_modules: + tc.variables["CMAKE_CXX_SCAN_FOR_MODULES"] = True + tc.variables["MP_UNITS_BUILD_CXX_MODULES"] = True tc.variables["MP_UNITS_BUILD_LA"] = self._build_all and not self._skip_la tc.variables["MP_UNITS_USE_LIBFMT"] = self._use_libfmt tc.generate() From 4c75d467eddd1b638312524c534ad63715bc7648 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 15/33] ci: building C++ modules enabled for clang-17 and apple-clang-15 --- .github/workflows/ci-conan.yml | 4 ++-- .github/workflows/ci-test-package-cmake.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index b6f6254c..58597a85 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -102,7 +102,7 @@ jobs: cxx: "clang++-17", }, lib: "libc++", - conan-config: "", + conan-config: "-o cxx_modules=True", } - { name: "Apple Clang 15", @@ -114,7 +114,7 @@ jobs: cc: "clang", cxx: "clang++", }, - conan-config: "", + conan-config: "-o cxx_modules=True", } build_type: ["Release", "Debug"] diff --git a/.github/workflows/ci-test-package-cmake.yml b/.github/workflows/ci-test-package-cmake.yml index ea9afa96..5670b0e1 100644 --- a/.github/workflows/ci-test-package-cmake.yml +++ b/.github/workflows/ci-test-package-cmake.yml @@ -98,7 +98,7 @@ jobs: cxx: "clang++-17", }, lib: "libc++", - conan-config: "", + conan-config: "-o cxx_modules=True", } - { name: "Apple Clang 15", @@ -110,7 +110,7 @@ jobs: cc: "clang", cxx: "clang++", }, - conan-config: "", + conan-config: "-o cxx_modules=True", } build_type: ["Release", "Debug"] From 4223f813cd560ae4c829725ee1f329f941634dfa Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 16/33] style: CMake file formatting fixed --- example/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 4a268ce4..2ccc3b99 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -28,10 +28,10 @@ if(NOT TARGET gsl::gsl-lite) endif() if(${projectPrefix}BUILD_CXX_MODULES) -add_library(example_utils INTERFACE) -target_compile_definitions(example_utils INTERFACE ${projectPrefix}MODULES) -target_include_directories(example_utils INTERFACE include) -target_link_libraries(example_utils INTERFACE gsl::gsl-lite) + add_library(example_utils INTERFACE) + target_compile_definitions(example_utils INTERFACE ${projectPrefix}MODULES) + target_include_directories(example_utils INTERFACE include) + target_link_libraries(example_utils INTERFACE gsl::gsl-lite) endif() add_library(example_utils-headers INTERFACE) From 614d82dece34be440afb84f86e8a2005b93cdf5c Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 17/33] ci: building C++ modules disabled for apple-clang-15 --- .github/workflows/ci-conan.yml | 2 +- .github/workflows/ci-test-package-cmake.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index 58597a85..4250509b 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -114,7 +114,7 @@ jobs: cc: "clang", cxx: "clang++", }, - conan-config: "-o cxx_modules=True", + conan-config: "", } build_type: ["Release", "Debug"] diff --git a/.github/workflows/ci-test-package-cmake.yml b/.github/workflows/ci-test-package-cmake.yml index 5670b0e1..65696cc9 100644 --- a/.github/workflows/ci-test-package-cmake.yml +++ b/.github/workflows/ci-test-package-cmake.yml @@ -110,7 +110,7 @@ jobs: cc: "clang", cxx: "clang++", }, - conan-config: "-o cxx_modules=True", + conan-config: "", } build_type: ["Release", "Debug"] From fb8552b1d953ef609f4bcc3e5b3175ebdd2967a4 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 18/33] refactor: `core-fmt` and `core-ostream` modules merged with `core` --- example/clcpp_response.cpp | 2 +- example/conversion_factor.cpp | 2 +- example/currency.cpp | 2 +- example/foot_pound_second.cpp | 2 +- example/glide_computer.cpp | 2 +- example/hello_units.cpp | 2 +- example/include/geographic.h | 2 +- example/include/validated_type.h | 2 +- example/kalman_filter/kalman.h | 2 +- example/si_constants.cpp | 2 +- example/spectroscopy_units.cpp | 2 +- example/storage_tank.cpp | 1 - example/unmanned_aerial_vehicle.cpp | 2 +- src/CMakeLists.txt | 4 +- src/core-fmt/CMakeLists.txt | 43 ---------- .../include/mp-units/compat_fmt_macros.h | 79 ------------------- src/core-fmt/mp-units-core-fmt.cpp | 13 --- src/core-io/CMakeLists.txt | 30 ------- src/core-io/mp-units-core-io.cpp | 13 --- src/core/CMakeLists.txt | 14 ++++ .../include/mp-units/bits/external/hacks.h | 47 +++++++++++ .../include/mp-units/bits/fmt.h | 2 +- src/core/include/mp-units/core.h | 2 + .../include/mp-units/format.h | 0 .../include/mp-units/ostream.h | 0 test/runtime/almost_equals.h | 2 +- test/runtime/fmt_test.cpp | 2 +- test/runtime/linear_algebra_test.cpp | 2 +- 28 files changed, 80 insertions(+), 198 deletions(-) delete mode 100644 src/core-fmt/CMakeLists.txt delete mode 100644 src/core-fmt/include/mp-units/compat_fmt_macros.h delete mode 100644 src/core-fmt/mp-units-core-fmt.cpp delete mode 100644 src/core-io/CMakeLists.txt delete mode 100644 src/core-io/mp-units-core-io.cpp rename src/{core-fmt => core}/include/mp-units/bits/fmt.h (99%) rename src/{core-fmt => core}/include/mp-units/format.h (100%) rename src/{core-io => core}/include/mp-units/ostream.h (100%) diff --git a/example/clcpp_response.cpp b/example/clcpp_response.cpp index 1bf0bbb5..98664b85 100644 --- a/example/clcpp_response.cpp +++ b/example/clcpp_response.cpp @@ -15,7 +15,7 @@ along with this program. If not, see http://www.gnu.org/licenses./ */ -#include +#include #include #ifdef MP_UNITS_MODULES import mp_units; diff --git a/example/conversion_factor.cpp b/example/conversion_factor.cpp index d6846f4d..e98dd694 100644 --- a/example/conversion_factor.cpp +++ b/example/conversion_factor.cpp @@ -15,7 +15,7 @@ along with this program. If not, see http://www.gnu.org/licenses./ */ -#include +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/currency.cpp b/example/currency.cpp index 65527711..cc935c5e 100644 --- a/example/currency.cpp +++ b/example/currency.cpp @@ -24,7 +24,7 @@ #include #include #ifdef MP_UNITS_MODULES -import mp_units.core_io; +import mp_units.core; #else #include #include diff --git a/example/foot_pound_second.cpp b/example/foot_pound_second.cpp index 63a303fc..b14576b4 100644 --- a/example/foot_pound_second.cpp +++ b/example/foot_pound_second.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/glide_computer.cpp b/example/glide_computer.cpp index c691d12d..b834e917 100644 --- a/example/glide_computer.cpp +++ b/example/glide_computer.cpp @@ -21,7 +21,7 @@ // SOFTWARE. #include "glide_computer_lib.h" -#include +#include #include #include #include diff --git a/example/hello_units.cpp b/example/hello_units.cpp index e707cd99..9725926a 100644 --- a/example/hello_units.cpp +++ b/example/hello_units.cpp @@ -25,7 +25,7 @@ // !!! renders correctly in the documentation "Examples" section. !!! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -#include +#include #include #ifdef MP_UNITS_MODULES import mp_units; diff --git a/example/include/geographic.h b/example/include/geographic.h index 3d285bd8..9ee94919 100644 --- a/example/include/geographic.h +++ b/example/include/geographic.h @@ -23,7 +23,7 @@ #pragma once #include "ranged_representation.h" -#include +#include #include #include #include diff --git a/example/include/validated_type.h b/example/include/validated_type.h index 9924fc4a..019867df 100644 --- a/example/include/validated_type.h +++ b/example/include/validated_type.h @@ -23,7 +23,7 @@ #pragma once #include -#include +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/kalman_filter/kalman.h b/example/kalman_filter/kalman.h index 9115aae3..9ae5b462 100644 --- a/example/kalman_filter/kalman.h +++ b/example/kalman_filter/kalman.h @@ -22,7 +22,7 @@ #pragma once -#include +#include #include #ifdef MP_UNITS_MODULES import mp_units; diff --git a/example/si_constants.cpp b/example/si_constants.cpp index e3d02d6e..2567210a 100644 --- a/example/si_constants.cpp +++ b/example/si_constants.cpp @@ -25,7 +25,7 @@ // !!! renders correctly in the documentation "Examples" section. !!! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -#include +#include #include #ifdef MP_UNITS_MODULES import mp_units; diff --git a/example/spectroscopy_units.cpp b/example/spectroscopy_units.cpp index 71da66d5..0badec0b 100644 --- a/example/spectroscopy_units.cpp +++ b/example/spectroscopy_units.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/storage_tank.cpp b/example/storage_tank.cpp index a2317384..e1e457ce 100644 --- a/example/storage_tank.cpp +++ b/example/storage_tank.cpp @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include #include #include #include diff --git a/example/unmanned_aerial_vehicle.cpp b/example/unmanned_aerial_vehicle.cpp index 35978aab..05bf9309 100644 --- a/example/unmanned_aerial_vehicle.cpp +++ b/example/unmanned_aerial_vehicle.cpp @@ -21,7 +21,7 @@ // SOFTWARE. #include "geographic.h" -#include +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b3f87735..51e484c9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,13 +47,11 @@ if(${projectPrefix}AS_SYSTEM_HEADERS) endif() add_subdirectory(core) -add_subdirectory(core-fmt) -add_subdirectory(core-io) add_subdirectory(systems) # project-wide wrapper add_units_module( - mp-units DEPENDENCIES mp-units::core mp-units::core-io mp-units::core-fmt mp-units::systems + mp-units DEPENDENCIES mp-units::core mp-units::systems MODULE_INTERFACE_UNIT mp-units.cpp ) diff --git a/src/core-fmt/CMakeLists.txt b/src/core-fmt/CMakeLists.txt deleted file mode 100644 index 71a643da..00000000 --- a/src/core-fmt/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -option(${projectPrefix}USE_LIBFMT "Enables usage of libfmt instead of the one from 'std'" ON) -message(STATUS "${projectPrefix}USE_LIBFMT: ${${projectPrefix}USE_LIBFMT}") - -add_units_module( - core-fmt - DEPENDENCIES mp-units::core - HEADERS include/mp-units/bits/fmt.h include/mp-units/compat_fmt_macros.h include/mp-units/format.h - MODULE_INTERFACE_UNIT mp-units-core-fmt.cpp -) -target_compile_definitions( - mp-units-core-fmt ${${projectPrefix}TARGET_SCOPE} ${projectPrefix}USE_LIBFMT=$ -) - -if(${projectPrefix}USE_LIBFMT) - if(NOT TARGET fmt::fmt) - find_package(fmt CONFIG REQUIRED) - endif() - target_link_libraries(mp-units-core-fmt ${${projectPrefix}TARGET_SCOPE} fmt::fmt) -endif() diff --git a/src/core-fmt/include/mp-units/compat_fmt_macros.h b/src/core-fmt/include/mp-units/compat_fmt_macros.h deleted file mode 100644 index 3ac40aad..00000000 --- a/src/core-fmt/include/mp-units/compat_fmt_macros.h +++ /dev/null @@ -1,79 +0,0 @@ -// The MIT License (MIT) -// -// Copyright (c) 2018 Mateusz Pusz -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -// Formatting library for C++ - the core API for char/UTF-8 -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#pragma once - -#include - -#ifndef MP_UNITS_USE_LIBFMT -#define MP_UNITS_USE_LIBFMT 1 -#endif - -#if MP_UNITS_USE_LIBFMT - -MP_UNITS_DIAGNOSTIC_PUSH -MP_UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE -MP_UNITS_DIAGNOSTIC_IGNORE_SHADOW -#include -MP_UNITS_DIAGNOSTIC_POP - -#define MP_UNITS_STD_FMT fmt -#define MP_UNITS_FMT_LOCALE(loc) (loc).template get() -#define MP_UNITS_FMT_TO_ARG_ID(arg) static_cast(arg) -#define MP_UNITS_FMT_FROM_ARG_ID(arg) static_cast(arg) - -// This re-uses code from fmt; -#if FMT_EXCEPTIONS -#if FMT_MSC_VERSION || defined(__NVCC__) -#define MP_UNITS_THROW(x) ::fmt::detail::do_throw(x) -#else -#define MP_UNITS_THROW(x) throw x -#endif -#else -#define MP_UNITS_THROW(x) \ - do { \ - FMT_ASSERT(false, (x).what()); \ - } while (false) -#endif - -#else - -#ifndef __cpp_lib_format -#error "std::formatting facility not supported" -#endif - -#include - -#define MP_UNITS_STD_FMT std -#define MP_UNITS_FMT_LOCALE(loc) loc -#define MP_UNITS_FMT_TO_ARG_ID(arg) arg -#define MP_UNITS_FMT_FROM_ARG_ID(arg) arg -#define MP_UNITS_THROW(arg) throw arg - -#endif diff --git a/src/core-fmt/mp-units-core-fmt.cpp b/src/core-fmt/mp-units-core-fmt.cpp deleted file mode 100644 index da3e62e8..00000000 --- a/src/core-fmt/mp-units-core-fmt.cpp +++ /dev/null @@ -1,13 +0,0 @@ -module; - -#include -#include - -export module mp_units.core_fmt; - -export import mp_units.core; - -export -{ -#include -} diff --git a/src/core-io/CMakeLists.txt b/src/core-io/CMakeLists.txt deleted file mode 100644 index 6f991530..00000000 --- a/src/core-io/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Mateusz Pusz -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.19) - -add_units_module( - core-io - DEPENDENCIES mp-units::core - HEADERS include/mp-units/ostream.h - MODULE_INTERFACE_UNIT mp-units-core-io.cpp -) diff --git a/src/core-io/mp-units-core-io.cpp b/src/core-io/mp-units-core-io.cpp deleted file mode 100644 index b31e7803..00000000 --- a/src/core-io/mp-units-core-io.cpp +++ /dev/null @@ -1,13 +0,0 @@ -module; - -#include -#include - -export module mp_units.core_io; - -export import mp_units.core; - -export -{ -#include -} diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 46143809..023bb245 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -42,6 +42,7 @@ add_units_module( include/mp-units/bits/core_gmf.h include/mp-units/bits/dimension_concepts.h include/mp-units/bits/expression_template.h + include/mp-units/bits/fmt.h include/mp-units/bits/get_associated_quantity.h include/mp-units/bits/get_common_base.h include/mp-units/bits/magnitude.h @@ -63,7 +64,9 @@ add_units_module( include/mp-units/core.h include/mp-units/customization_points.h include/mp-units/dimension.h + include/mp-units/format.h include/mp-units/math.h + include/mp-units/ostream.h include/mp-units/quantity.h include/mp-units/quantity_point.h include/mp-units/quantity_spec.h @@ -74,6 +77,17 @@ add_units_module( MODULE_INTERFACE_UNIT mp-units-core.cpp ) +target_compile_definitions( + mp-units-core ${${projectPrefix}TARGET_SCOPE} ${projectPrefix}USE_LIBFMT=$ +) + +if(${projectPrefix}USE_LIBFMT) + if(NOT TARGET fmt::fmt) + find_package(fmt CONFIG REQUIRED) + endif() + target_link_libraries(mp-units-core ${${projectPrefix}TARGET_SCOPE} fmt::fmt) +endif() + if(${projectPrefix}BUILD_CXX_MODULES) if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18) diff --git a/src/core/include/mp-units/bits/external/hacks.h b/src/core/include/mp-units/bits/external/hacks.h index 6bf6f45d..542ebcc6 100644 --- a/src/core/include/mp-units/bits/external/hacks.h +++ b/src/core/include/mp-units/bits/external/hacks.h @@ -99,3 +99,50 @@ #define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) X #endif + +#ifndef MP_UNITS_USE_LIBFMT +#define MP_UNITS_USE_LIBFMT 1 +#endif + +#if MP_UNITS_USE_LIBFMT + +MP_UNITS_DIAGNOSTIC_PUSH +MP_UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE +MP_UNITS_DIAGNOSTIC_IGNORE_SHADOW +#include +MP_UNITS_DIAGNOSTIC_POP + +#define MP_UNITS_STD_FMT fmt +#define MP_UNITS_FMT_LOCALE(loc) (loc).template get() +#define MP_UNITS_FMT_TO_ARG_ID(arg) static_cast(arg) +#define MP_UNITS_FMT_FROM_ARG_ID(arg) static_cast(arg) + +// This re-uses code from fmt; +#if FMT_EXCEPTIONS +#if FMT_MSC_VERSION || defined(__NVCC__) +#define MP_UNITS_THROW(x) ::fmt::detail::do_throw(x) +#else +#define MP_UNITS_THROW(x) throw x +#endif +#else +#define MP_UNITS_THROW(x) \ + do { \ + FMT_ASSERT(false, (x).what()); \ + } while (false) +#endif + +#else + +#ifndef __cpp_lib_format +#error "std::formatting facility not supported" +#endif + +#include + +#define MP_UNITS_STD_FMT std +#define MP_UNITS_FMT_LOCALE(loc) loc +#define MP_UNITS_FMT_TO_ARG_ID(arg) arg +#define MP_UNITS_FMT_FROM_ARG_ID(arg) arg +#define MP_UNITS_THROW(arg) throw arg + +#endif diff --git a/src/core-fmt/include/mp-units/bits/fmt.h b/src/core/include/mp-units/bits/fmt.h similarity index 99% rename from src/core-fmt/include/mp-units/bits/fmt.h rename to src/core/include/mp-units/bits/fmt.h index 28fa08ea..1b56e7ef 100644 --- a/src/core-fmt/include/mp-units/bits/fmt.h +++ b/src/core/include/mp-units/bits/fmt.h @@ -30,7 +30,7 @@ #pragma once #include -#include +#include #include #include #include diff --git a/src/core/include/mp-units/core.h b/src/core/include/mp-units/core.h index e92ceb28..d2d49551 100644 --- a/src/core/include/mp-units/core.h +++ b/src/core/include/mp-units/core.h @@ -27,7 +27,9 @@ #include #include #include +#include #include +#include #include #include #include diff --git a/src/core-fmt/include/mp-units/format.h b/src/core/include/mp-units/format.h similarity index 100% rename from src/core-fmt/include/mp-units/format.h rename to src/core/include/mp-units/format.h diff --git a/src/core-io/include/mp-units/ostream.h b/src/core/include/mp-units/ostream.h similarity index 100% rename from src/core-io/include/mp-units/ostream.h rename to src/core/include/mp-units/ostream.h diff --git a/test/runtime/almost_equals.h b/test/runtime/almost_equals.h index 5913c990..471f2b79 100644 --- a/test/runtime/almost_equals.h +++ b/test/runtime/almost_equals.h @@ -21,7 +21,7 @@ // SOFTWARE. #include -#include +#include #include #ifdef MP_UNITS_MODULES import mp_units; diff --git a/test/runtime/fmt_test.cpp b/test/runtime/fmt_test.cpp index ef914a1f..71ea8588 100644 --- a/test/runtime/fmt_test.cpp +++ b/test/runtime/fmt_test.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include diff --git a/test/runtime/linear_algebra_test.cpp b/test/runtime/linear_algebra_test.cpp index cbdb9c6c..5779fbb9 100644 --- a/test/runtime/linear_algebra_test.cpp +++ b/test/runtime/linear_algebra_test.cpp @@ -21,7 +21,7 @@ // SOFTWARE. #include -#include +#include #include #include #ifdef MP_UNITS_MODULES From a7cb512f877082667d95e9dbab39030fbaaf896e Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 19/33] fix: modules build fixed --- example/glide_computer_lib/glide_computer_lib.cpp | 2 +- example/include/validated_type.h | 2 +- src/mp-units.cpp | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/example/glide_computer_lib/glide_computer_lib.cpp b/example/glide_computer_lib/glide_computer_lib.cpp index 70d26edf..8c3af99f 100644 --- a/example/glide_computer_lib/glide_computer_lib.cpp +++ b/example/glide_computer_lib/glide_computer_lib.cpp @@ -25,7 +25,7 @@ #include #include #ifdef MP_UNITS_MODULES -import mp_units.core_fmt; +import mp_units.core; #else #include #endif diff --git a/example/include/validated_type.h b/example/include/validated_type.h index 019867df..814cefd7 100644 --- a/example/include/validated_type.h +++ b/example/include/validated_type.h @@ -27,7 +27,7 @@ #include #include #ifdef MP_UNITS_MODULES -import mp_units.core_fmt; +import mp_units.core; #else #include #include diff --git a/src/mp-units.cpp b/src/mp-units.cpp index 30218060..5dd2ff9d 100644 --- a/src/mp-units.cpp +++ b/src/mp-units.cpp @@ -3,6 +3,4 @@ module; export module mp_units; export import mp_units.core; -export import mp_units.core_fmt; -export import mp_units.core_io; export import mp_units.systems; From 44c557ff4b0daa0cf6dd0514a389b63426015551 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 20/33] refactor: `add_units_module` renamed to `add_mp_units_module` and `target_name` parameter added --- src/CMakeLists.txt | 7 ++--- ...itsModule.cmake => AddMPUnitsModule.cmake} | 28 +++++++++---------- src/core/CMakeLists.txt | 4 +-- src/systems/CMakeLists.txt | 4 +-- 4 files changed, 20 insertions(+), 23 deletions(-) rename src/cmake/{AddUnitsModule.cmake => AddMPUnitsModule.cmake} (75%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 51e484c9..fe4560c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,7 +33,7 @@ message(STATUS "${projectPrefix}BUILD_CXX_MODULES: ${${projectPrefix}BUILD_CXX_M list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") -include(AddUnitsModule) +include(AddMPUnitsModule) include(GNUInstallDirs) if(${projectPrefix}BUILD_CXX_MODULES) @@ -50,10 +50,7 @@ add_subdirectory(core) add_subdirectory(systems) # project-wide wrapper -add_units_module( - mp-units DEPENDENCIES mp-units::core mp-units::systems - MODULE_INTERFACE_UNIT mp-units.cpp -) +add_mp_units_module(mp-units mp-units DEPENDENCIES mp-units::core mp-units::systems MODULE_INTERFACE_UNIT mp-units.cpp) # local build export(EXPORT mp-unitsTargets NAMESPACE mp-units::) diff --git a/src/cmake/AddUnitsModule.cmake b/src/cmake/AddMPUnitsModule.cmake similarity index 75% rename from src/cmake/AddUnitsModule.cmake rename to src/cmake/AddMPUnitsModule.cmake index 4e0ac2a4..642d2255 100644 --- a/src/cmake/AddUnitsModule.cmake +++ b/src/cmake/AddMPUnitsModule.cmake @@ -41,16 +41,16 @@ function(validate_arguments_exists module prefix) endfunction() # -# add_units_module(ModuleName -# DEPENDENCIES ... -# [HEADERS ...] -# MODULE_INTERFACE_UNIT ) +# add_mp_units_module(Name TargetName +# DEPENDENCIES ... +# [HEADERS ...] +# MODULE_INTERFACE_UNIT ) # -function(add_units_module name) +function(add_mp_units_module name target_name) # parse arguments set(oneValue MODULE_INTERFACE_UNIT) set(multiValues DEPENDENCIES HEADERS) - cmake_parse_arguments(PARSE_ARGV 1 ARG "" "${oneValue}" "${multiValues}") + cmake_parse_arguments(PARSE_ARGV 2 ARG "" "${oneValue}" "${multiValues}") # validate and process arguments validate_unparsed(${name} ARG) @@ -61,26 +61,26 @@ function(add_units_module name) endif() # define the target for a module - add_library(mp-units-${name} ${SCOPE} ${ARG_HEADERS}) - target_link_libraries(mp-units-${name} ${${projectPrefix}TARGET_SCOPE} ${ARG_DEPENDENCIES}) + add_library(${target_name} ${SCOPE} ${ARG_HEADERS}) + target_link_libraries(${target_name} ${${projectPrefix}TARGET_SCOPE} ${ARG_DEPENDENCIES}) if(ARG_HEADERS) target_include_directories( - mp-units-${name} ${unitsAsSystem} ${${projectPrefix}TARGET_SCOPE} + ${target_name} ${unitsAsSystem} ${${projectPrefix}TARGET_SCOPE} $ $ ) endif() - set_target_properties(mp-units-${name} PROPERTIES EXPORT_NAME ${name}) - add_library(mp-units::${name} ALIAS mp-units-${name}) + set_target_properties(${target_name} PROPERTIES EXPORT_NAME ${name}) + add_library(mp-units::${name} ALIAS ${target_name}) if(${projectPrefix}BUILD_CXX_MODULES) - target_sources(mp-units-${name} PUBLIC FILE_SET CXX_MODULES FILES ${ARG_MODULE_INTERFACE_UNIT}) - install(TARGETS mp-units-${name} + target_sources(${target_name} PUBLIC FILE_SET CXX_MODULES FILES ${ARG_MODULE_INTERFACE_UNIT}) + install(TARGETS ${target_name} EXPORT mp-unitsTargets FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_LIBDIR}/miu ) else() - install(TARGETS mp-units-${name} EXPORT mp-unitsTargets) + install(TARGETS ${target_name} EXPORT mp-unitsTargets) endif() if(ARG_HEADERS) install(DIRECTORY include/mp-units TYPE INCLUDE) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 023bb245..1ed2cfec 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -28,8 +28,8 @@ if(NOT TARGET gsl::gsl-lite) endif() # core library definition -add_units_module( - core +add_mp_units_module( + core mp-units-core DEPENDENCIES gsl::gsl-lite HEADERS include/mp-units/bits/external/algorithm.h include/mp-units/bits/external/fixed_string.h diff --git a/src/systems/CMakeLists.txt b/src/systems/CMakeLists.txt index 95e20497..e061e4a0 100644 --- a/src/systems/CMakeLists.txt +++ b/src/systems/CMakeLists.txt @@ -22,8 +22,8 @@ cmake_minimum_required(VERSION 3.19) -add_units_module( - systems +add_mp_units_module( + systems mp-units-systems DEPENDENCIES mp-units::core HEADERS include/mp-units/systems/angular/angular.h include/mp-units/systems/angular/math.h From 4960011ca5579a0779c980c69073506afc303d63 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 21/33] fix: `cxx_std_20` set for `mp-units::core` --- src/core/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 1ed2cfec..cec5811b 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -77,6 +77,7 @@ add_mp_units_module( MODULE_INTERFACE_UNIT mp-units-core.cpp ) +target_compile_features(mp-units-core INTERFACE cxx_std_20) target_compile_definitions( mp-units-core ${${projectPrefix}TARGET_SCOPE} ${projectPrefix}USE_LIBFMT=$ ) From e23be9aab5862817be6aee011144db2e8ffb01bf Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 22/33] fix: `MP_UNITS_USE_LIBFMT` was lost during refactoring --- src/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fe4560c2..589cc9d5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,11 +25,14 @@ project(mp-units VERSION 2.2.0 LANGUAGES CXX) set(projectPrefix MP_UNITS_) +option(${projectPrefix}BUILD_CXX_MODULES "Add C++ modules to the list of default targets" OFF) +message(STATUS "${projectPrefix}BUILD_CXX_MODULES: ${${projectPrefix}BUILD_CXX_MODULES}") + option(${projectPrefix}AS_SYSTEM_HEADERS "Exports library as system headers" OFF) message(STATUS "${projectPrefix}AS_SYSTEM_HEADERS: ${${projectPrefix}AS_SYSTEM_HEADERS}") -option(${projectPrefix}BUILD_CXX_MODULES "Add C++ modules to the list of default targets" OFF) -message(STATUS "${projectPrefix}BUILD_CXX_MODULES: ${${projectPrefix}BUILD_CXX_MODULES}") +option(${projectPrefix}USE_LIBFMT "Enables usage of libfmt instead of the one from 'std'" ON) +message(STATUS "${projectPrefix}USE_LIBFMT: ${${projectPrefix}USE_LIBFMT}") list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") From edb7de4b116cd97a3e364da1795cbd6e5b6410d1 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 23/33] docs: documentation updated for C++ modules --- .../getting_started/installation_and_usage.md | 84 ++++++++++++++----- docs/index.md | 16 +++- 2 files changed, 75 insertions(+), 25 deletions(-) diff --git a/docs/getting_started/installation_and_usage.md b/docs/getting_started/installation_and_usage.md index 5ed8ce5c..6e361609 100644 --- a/docs/getting_started/installation_and_usage.md +++ b/docs/getting_started/installation_and_usage.md @@ -12,11 +12,34 @@ a [preprocessor macro](../users_guide/framework_basics/systems_of_quantities.md#defining-quantities) providing a backward-compatible way to use it. - As of today, the library compiles fine on the following compilers (or newer): + The below table provides the minimum compiler version required to compile the code using the + specific feature: - - gcc-12 - - clang-16 - - apple-clang-15 + | Feature | gcc | clang | apple-clang | MSVC | + |----------------------|:----:|:-----:|:-----------:|:----:| + | **Minimum support** | 12 | 16 | 15 | None | + | **`std::format`** | None | None | None | None | + | **C++ modules** | None | 17 | None | None | + | **C++23 extensions** | None | None | None | None | + + More requirements for C++ modules support can be found in the + [CMake's documentation](https://cmake.org/cmake/help/latest/manual/cmake-cxxmodules.7.html). + + +## Modules + +The **mp-units** library provides the following C++ modules. + +```mermaid +flowchart TD + mp_units --- mp_units.systems --- mp_units.core +``` + +| C++ Module | CMake Target | Contents | +|--------------------|----------------------|-----------------------------------------| +| `mp_units.core` | `mp-units::core` | Core library framework | +| `mp_units.systems` | `mp-units::systems` | All the systems of quantities and units | +| `mp_units` | `mp-units::mp-units` | Core + Systems | ## Repository Structure and Dependencies @@ -60,10 +83,12 @@ This repository contains three independent CMake-based projects: This is why our projects have two entry points: - - _./CMakeLists.txt_ is to be used by projects developers to build **ALL** the project code with really - restrictive compilation flags, - - _./src/CMakeLists.txt_ contains only a pure library definition and should be used by the customers - that prefer to use CMake's `add_subdirectory()` to handle the dependencies. + - _./CMakeLists.txt_ is **to be used by projects developers** to build **ALL** the project code + with really restrictive compilation flags, + - _./src/CMakeLists.txt_ contains only a pure library definition and **should be used by the + customers** that prefer to use CMake's + [`add_subdirectory()`](https://cmake.org/cmake/help/latest/command/add_subdirectory.html) to + handle the dependencies. To learn more about the rationale, please check our [FAQ](faq.md#why-dont-we-have-cmake-options-to-disable-building-of-tests-and-examples). @@ -138,6 +163,16 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"} ## Build Options +### Conan Options + +[cxx_modules](#cxx_modules){ #cxx_modules } + +: [:octicons-tag-24: 2.2.0][cxx modules support] · :octicons-milestone-24: `True`/`False` (Default: `False`) + + Configures CMake to add C++ modules to the list of default targets. + +[cxx modules support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0 + ### Conan Configuration Properties [`user.build:all`](#user-build-all){ #user-build-all } @@ -146,7 +181,8 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"} Enables compilation of all the source code, including tests and examples. To support this, it requires some additional Conan build dependencies described in [Repository Structure and Dependencies](#repository-structure-and-dependencies). - It also runs unit tests during Conan build (unless `tools.build:skip_test` + It also runs unit tests during Conan build (unless + [`tools.build:skip_test`](https://docs.conan.io/2/reference/commands/config.html?highlight=tools.build:skip_test#conan-config-list) configuration property is set to `True`). [build all support]: https://github.com/mpusz/mp-units/releases/tag/v0.8.0 @@ -166,6 +202,15 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"} ### CMake Options +[`MP_UNITS_BUILD_CXX_MODULES`](#MP_UNITS_BUILD_CXX_MODULES){ #MP_UNITS_BUILD_CXX_MODULES } + +: [:octicons-tag-24: 2.2.0][build_cxx_modules support] · :octicons-milestone-24: `ON`/`OFF` (Default: `OFF`) + + Adds C++ modules to the list of default targets. + + [build_cxx_modules support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0 + + [`MP_UNITS_AS_SYSTEM_HEADERS`](#MP_UNITS_AS_SYSTEM_HEADERS){ #MP_UNITS_AS_SYSTEM_HEADERS } : [:octicons-tag-24: 2.0.0][as system headers support] · :octicons-milestone-24: `ON`/`OFF` (Default: `OFF`) @@ -175,15 +220,6 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"} [as system headers support]: https://github.com/mpusz/mp-units/releases/tag/v2.0.0 -[`MP_UNITS_BUILD_CXX_MODULES`](#MP_UNITS_BUILD_CXX_MODULES){ #MP_UNITS_BUILD_CXX_MODULES } - -: [:octicons-tag-24: 2.2.0][build_cxx_modules support] · :octicons-milestone-24: `ON`/`OFF` (Default: `OFF`) - - Add C++ modules to the list of default targets. - - [build_cxx_modules support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0 - - [`MP_UNITS_BUILD_LA`](#MP_UNITS_BUILD_LA){ #MP_UNITS_BUILD_LA } : [:octicons-tag-24: 2.0.0][build la support] · :octicons-milestone-24: `ON`/`OFF` (Default: `ON`) @@ -208,7 +244,7 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"} : [:octicons-tag-24: 2.0.0][use libfmt support] · :octicons-milestone-24: `ON`/`OFF` (Default: `ON`) Forces usage of [{fmt}](https://github.com/fmtlib/fmt) library instead of the C++20 Standard - Library feature. + Library features. [use libfmt support]: https://github.com/mpusz/mp-units/releases/tag/v2.0.0 @@ -293,6 +329,9 @@ The following steps may be performed to obtain an official library release: [requires] mp-units/2.1.0 + [options] + mp-units:cxx_modules=True + [layout] cmake_layout @@ -350,6 +389,9 @@ with the following differences: [requires] mp-units/2.2.0@mpusz/testing + [options] + mp-units:cxx_modules=True + [layout] cmake_layout @@ -396,7 +438,7 @@ you should: ```shell git clone https://github.com/mpusz/mp-units.git && cd units -conan build . -pr -s compiler.cppstd=20 -c user.build:all=True -b missing +conan build . -pr -s compiler.cppstd=23 -o cxx_modules=True -c user.build:all=True -b missing ``` The above will download and install all of the dependencies needed for the development of the library, @@ -442,7 +484,7 @@ After that, you can either: To test CMake installation and Conan packaging or create a Conan package run: ```shell -conan create . --user --channel -pr -s compiler.cppstd=20 -c user.build:all=True -b missing +conan create . --user --channel -pr -s compiler.cppstd=20 -o cxx_modules=True -c user.build:all=True -b missing ``` The above will create a Conan package and run tests provided in _./test_package_ directory. diff --git a/docs/index.md b/docs/index.md index e814e40a..0150746e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -25,11 +25,19 @@ The library source code is hosted on [GitHub](https://github.com/mpusz/mp-units) a [preprocessor macro](users_guide/framework_basics/systems_of_quantities.md#defining-quantities) providing a backward-compatible way to use it. - As of today, the library compiles fine on the following compilers (or newer): + The below table provides the minimum compiler version required to compile the code using the + specific feature: + + | Feature | gcc | clang | apple-clang | MSVC | + |----------------------|:----:|:-----:|:-----------:|:----:| + | **Minimum support** | 12 | 16 | 15 | None | + | **`std::format`** | None | None | None | None | + | **C++ modules** | None | 17 | None | None | + | **C++23 extensions** | None | None | None | None | + + More requirements for C++ modules support can be found in the + [CMake's documentation](https://cmake.org/cmake/help/latest/manual/cmake-cxxmodules.7.html). - - gcc-12 - - clang-16 - - apple-clang-15 ```cpp #include From aaa60e0573db06c27cddb3a7b763adb8e92625c3 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 24/33] docs: example apllications documentation updated for modules --- docs/users_guide/examples/avg_speed.md | 26 +++++++------- docs/users_guide/examples/hello_units.md | 46 ++++++++++++------------ example/avg_speed.cpp | 8 ++--- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/docs/users_guide/examples/avg_speed.md b/docs/users_guide/examples/avg_speed.md index dc8ebc43..704730f9 100644 --- a/docs/users_guide/examples/avg_speed.md +++ b/docs/users_guide/examples/avg_speed.md @@ -14,8 +14,8 @@ library features as possible, but we will scope on different interfaces one can with the **mp-units**. We will also describe some advantages and disadvantages of presented solutions. -First, we include all the necessary header files and import all the identifiers from the -`mp_units` namespace: +First, we either import a module or include all the necessary header files and import all +the identifiers from the `mp_units` namespace: ```cpp title="avg_speed.cpp" linenums="1" --8<-- "example/avg_speed.cpp:28:42" @@ -52,11 +52,11 @@ Average speed of a car that makes 220 km in 2 h is 110 km/h. ``` Please note that in the first two cases, we must convert length from `km` to `m` and -time from `h` to `s`. The converted values are used to calculate speed in `m / s` which -is then again converted to the one in `km / h`. Those conversions not only impact the -application's runtime performance but may also affect the final result. Such truncation -can be easily observed in the first case where we deal with integral representation types -(the resulting speed is `108 km / h`). +time from `h` to `s`. The converted values are used to calculate speed in `m/s` which +is then again converted to the one in `km/h`. Those conversions not only impact the +application's runtime performance but may also affect the precision of the final result. +Such truncation can be easily observed in the first case where we deal with integral +representation types (the resulting speed is `108 km/h`). The second scenario is really similar to the previous one, but this time, function arguments have floating-point representation types: @@ -80,7 +80,7 @@ Average speed of a car that makes 220 km in 2 h is 110 km/h. ``` Next, let's do the same for integral and floating-point representations, but this time -using US Customary units: +using international mile: ```cpp title="avg_speed.cpp" linenums="65" --8<-- "example/avg_speed.cpp:97:129" @@ -88,17 +88,17 @@ using US Customary units: One important difference here is the fact that as it is not possible to make a lossless conversion of miles to meters on a quantity using an integral representation type, so this time, we need a -`value_cast` to force it. +`value_cast` to force it. If we check the text output of the above, we will see the following: ```text -US Customary Units with 'int' as representation +International mile with 'int' as representation Average speed of a car that makes 140 mi in 2 h is 111 km/h. Average speed of a car that makes 140 mi in 2 h is 112.654 km/h. Average speed of a car that makes 140 mi in 2 h is 112 km/h. -US Customary Units with 'double' as representation +International mile with 'double' as representation Average speed of a car that makes 140 mi in 2 h is 111 km/h. Average speed of a car that makes 140 mi in 2 h is 112.654 km/h. Average speed of a car that makes 140 mi in 2 h is 112.654 km/h. @@ -108,7 +108,7 @@ Please note how the first and third results get truncated using integral represe In the end, we repeat the scenario for CGS units: -```cpp title="avg_speed.cpp" linenums="98" +```cpp title="avg_speed.cpp" linenums="97" --8<-- "example/avg_speed.cpp:131:161" ``` @@ -129,6 +129,6 @@ Average speed of a car that makes 2.2e+07 cm in 7200 s is 110 km/h. The example file ends with a simple `main()` function: -```cpp title="avg_speed.cpp" linenums="129" +```cpp title="avg_speed.cpp" linenums="128" --8<-- "example/avg_speed.cpp:163:" ``` diff --git a/docs/users_guide/examples/hello_units.md b/docs/users_guide/examples/hello_units.md index bc5c5a50..8e2935a9 100644 --- a/docs/users_guide/examples/hello_units.md +++ b/docs/users_guide/examples/hello_units.md @@ -10,24 +10,24 @@ tags: This is a really simple example showcasing the features of the **mp-units** library. -First, we include the headers for: +First, we either import the `mp_units` module or include the headers for: -- a system of quantities (ISQ) -- symbols of SI units -- symbols of international units -- text and stream output support +- an International System of Quantities (ISQ) +- an International System of units (SI) +- units derived from the International Yard and Pound +- text formatting and stream output support ```cpp title="hello_units.cpp" linenums="1" --8<-- "example/hello_units.cpp:28:39" ``` -Also, to shorten the definitions, we "import" `mp_units` namespace. +Also, to shorten the definitions, we "import" all the symbols from the `mp_units` namespace. ```cpp title="hello_units.cpp" linenums="12" --8<-- "example/hello_units.cpp:40:41" ``` -Next we define a simple function that calculates average speed based on the provided +Next, we define a simple function that calculates the average speed based on the provided arguments of length and time: ```cpp title="hello_units.cpp" linenums="13" @@ -35,21 +35,21 @@ arguments of length and time: ``` The above function template takes any quantities implicitly convertible to `isq::length` -and `isq::time` respectively. Those quantities can use any compatible unit and a -representation type. The function returns a result of a really simple equation and ensures +and `isq::time`, respectively. Those quantities can use any compatible unit and a +representation type. The function returns a result of a straightforward equation and ensures that its quantity type is implicitly convertible to `isq::speed`. !!! tip Besides verifying the type returned from the function, constraining a generic return - type is really useful for users of such a function as it provides more information + type is beneficial for users of such a function as it provides more information of what to expect from a function than just using `auto`. ```cpp title="hello_units.cpp" linenums="17" --8<-- "example/hello_units.cpp:47:50" ``` -The above lines explicitly opt-in to use unit symbols from two systems of units. +The above lines explicitly opt into using unit symbols from two systems of units. As this introduces a lot of short identifiers into the current scope, it is not done implicitly while including a header file. @@ -57,21 +57,21 @@ implicitly while including a header file. --8<-- "example/hello_units.cpp:52:58" ``` -- Lines `16` & `17` create a quantity of kind `isq::length / isq::time` with the numbers +- Lines `21` & `22` create a quantity of kind `isq::length / isq::time` with the numbers and units provided. Such quantities can be converted or assigned to any other quantity with a matching kind. -- Line `18` calls our function template with quantities of kind `isq::length` and +- Line `23` calls our function template with quantities of kind `isq::length` and `isq::time` and number and units provided. -- Line `19` explicitly provides quantity types of the quantities passed to a function template. - This time those will not be quantity kinds anymore and will have +- Line `24` explicitly provides quantity types of the quantities passed to a function template. + This time, those will not be quantity kinds anymore and will have [more restrictive conversion rules](../framework_basics/simple_and_typed_quantities.md#quantity_cast-to-force-unsafe-conversions). -- Line `20` changes the unit of a quantity `v3` to `m / s` in a +- Line `25` changes the unit of a quantity `v3` to `m / s` in a [value-preserving way](../framework_basics/value_conversions.md#value-preserving-conversions) (floating-point representations are considered to be value-preserving). -- Line `21` does a similar operation but this time it would succeed also for +- Line `26` does a similar operation, but this time, it would also succeed for [value-truncating cases](../framework_basics/value_conversions.md#value-truncating-conversions) - (if it was the case). -- Line `22` does a [value-truncating conversion](../framework_basics/value_conversions.md#value-truncating-conversions) + (if that was the case). +- Line `27` does a [value-truncating conversion](../framework_basics/value_conversions.md#value-truncating-conversions) of changing the underlying representation type from `double` to `int`. ```cpp title="hello_units.cpp" linenums="28" @@ -79,10 +79,10 @@ implicitly while including a header file. ``` The above presents [various ways to print a quantity](../framework_basics/text_output.md). -Both stream insertion operations and `std::format` are supported. +Both stream insertion operations and `std::format` facilities are supported. !!! tip - `MP_UNITS_STD_FMT` is used for compatibility reasons. In case a specific compiler - does not support `std::format` or a user prefers to use `{fmt}` library, this macro - will resolve to `fmt` namespace. Otherwise, `std` namespace will be used. + `MP_UNITS_STD_FMT` is used for compatibility reasons. If a specific compiler + does not support `std::format` or a user prefers to use the `{fmt}` library, this macro + will resolve to `fmt` namespace. Otherwise, the `std` namespace will be used. diff --git a/example/avg_speed.cpp b/example/avg_speed.cpp index 4443fb6d..a31f6a1b 100644 --- a/example/avg_speed.cpp +++ b/example/avg_speed.cpp @@ -94,14 +94,14 @@ void example() print_result(distance, duration, avg_speed(distance, duration)); } - // Customary Units (int) + // International mile (int) { using namespace mp_units::international::unit_symbols; constexpr auto distance = 140 * mi; constexpr auto duration = 2 * h; - std::cout << "\nUS Customary Units with 'int' as representation\n"; + std::cout << "\nInternational mile with 'int' as representation\n"; // it is not possible to make a lossless conversion of miles to meters on an integral type // (explicit cast needed) @@ -110,14 +110,14 @@ void example() print_result(distance, duration, avg_speed(distance, duration)); } - // Customary Units (double) + // International mile (double) { using namespace mp_units::international::unit_symbols; constexpr auto distance = 140. * mi; constexpr auto duration = 2. * h; - std::cout << "\nUS Customary Units with 'double' as representation\n"; + std::cout << "\nInternational mile with 'double' as representation\n"; // conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed // also it is not possible to make a lossless conversion of miles to meters on an integral type From e8e3226698f72a0e5038dc265bf7d741be75faef Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 25/33] docs: "Installation and Usage" refactored --- .../getting_started/installation_and_usage.md | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/docs/getting_started/installation_and_usage.md b/docs/getting_started/installation_and_usage.md index 6e361609..2b12541b 100644 --- a/docs/getting_started/installation_and_usage.md +++ b/docs/getting_started/installation_and_usage.md @@ -1,5 +1,10 @@ # Installation And Usage +This chapter provides all the necessary information to obtain and build the code using **mp-units**. +It also describes how to build or distribute the library and generate its documentation. + +## C++ compiler support { #cpp-compiler-support } + !!! info **mp-units** library tries to provide the best user experience possible with the C++ language. @@ -12,18 +17,18 @@ a [preprocessor macro](../users_guide/framework_basics/systems_of_quantities.md#defining-quantities) providing a backward-compatible way to use it. - The below table provides the minimum compiler version required to compile the code using the - specific feature: +The below table provides the minimum compiler version required to compile the code using the +specific feature: - | Feature | gcc | clang | apple-clang | MSVC | - |----------------------|:----:|:-----:|:-----------:|:----:| - | **Minimum support** | 12 | 16 | 15 | None | - | **`std::format`** | None | None | None | None | - | **C++ modules** | None | 17 | None | None | - | **C++23 extensions** | None | None | None | None | +| Feature | gcc | clang | apple-clang | MSVC | +|----------------------|:----:|:-----:|:-----------:|:----:| +| **Minimum support** | 12 | 16 | 15 | None | +| **`std::format`** | None | None | None | None | +| **C++ modules** | None | 17 | None | None | +| **C++23 extensions** | None | None | None | None | - More requirements for C++ modules support can be found in the - [CMake's documentation](https://cmake.org/cmake/help/latest/manual/cmake-cxxmodules.7.html). +More requirements for C++ modules support can be found in the +[CMake's documentation](https://cmake.org/cmake/help/latest/manual/cmake-cxxmodules.7.html). ## Modules @@ -42,7 +47,7 @@ flowchart TD | `mp_units` | `mp-units::mp-units` | Core + Systems | -## Repository Structure and Dependencies +## Repository structure and dependencies This repository contains three independent CMake-based projects: @@ -94,7 +99,7 @@ This repository contains three independent CMake-based projects: [FAQ](faq.md#why-dont-we-have-cmake-options-to-disable-building-of-tests-and-examples). -## Obtaining Dependencies +## Obtaining dependencies This library assumes that most of the dependencies will be provided by the [Conan Package Manager](https://conan.io/). If you want to obtain required @@ -103,7 +108,7 @@ The rest of the dependencies responsible for documentation generation are provid `python3-pip`. -### Conan Quick Intro +### Conan quick intro In case you are not familiar with Conan, to install it (or upgrade) just do: @@ -161,9 +166,9 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"} (e.g. `conan-gcc-13-23` and `conan-gcc-13-23-release`) -## Build Options +## Build options -### Conan Options +### Conan options [cxx_modules](#cxx_modules){ #cxx_modules } @@ -173,7 +178,7 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"} [cxx modules support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0 -### Conan Configuration Properties +### Conan configuration properties [`user.build:all`](#user-build-all){ #user-build-all } @@ -200,7 +205,7 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"} [skip la support]: https://github.com/mpusz/mp-units/releases/tag/v0.8.0 -### CMake Options +### CMake options [`MP_UNITS_BUILD_CXX_MODULES`](#MP_UNITS_BUILD_CXX_MODULES){ #MP_UNITS_BUILD_CXX_MODULES } @@ -249,7 +254,7 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"} [use libfmt support]: https://github.com/mpusz/mp-units/releases/tag/v2.0.0 -## CMake with Presets Support +## CMake with presets support It is recommended to use at least CMake 3.23 to build this project as this version introduced support for CMake Presets schema version 4, used now by Conan to generate presets files. All build instructions @@ -269,7 +274,7 @@ cmake --build . --config Release which will force Conan to use an older version of the CMake Presets schema. -## Installation and Reuse +## Installation and reuse There are many different ways of installing/reusing **mp-units** in your project. Below we mention only a few of many options possible. @@ -490,7 +495,7 @@ conan create . --user --channel -pr -s The above will create a Conan package and run tests provided in _./test_package_ directory. -## Uploading **mp-units** Package to the Conan Server +## Uploading **mp-units** package to the Conan server ```shell conan upload -r --all mp-units/2.1.0@/ From 98cc53ef866b54a0256c1f929f1ef4c479c137ca Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 26/33] docs: "Wide Compatibility" chapter added --- docs/users_guide/examples/tags_index.md | 6 + .../use_cases/wide_compatibility.md | 159 ++++++++++++++++++ mkdocs.yml | 1 + 3 files changed, 166 insertions(+) create mode 100644 docs/users_guide/use_cases/wide_compatibility.md diff --git a/docs/users_guide/examples/tags_index.md b/docs/users_guide/examples/tags_index.md index f8e60316..0f1d4da8 100644 --- a/docs/users_guide/examples/tags_index.md +++ b/docs/users_guide/examples/tags_index.md @@ -1,5 +1,11 @@ # Tags Index +!!! note + + **mp-units** usage example applications are meant to be built on all of + [the supported compilers](../../getting_started/installation_and_usage.md#cpp-compiler-support). + This is why they benefit from the [Wide Compatibility](../use_cases/wide_compatibility.md) mode. + !!! tip All usage examples in this chapter are categorized with appropriate tags to simplify navigation and diff --git a/docs/users_guide/use_cases/wide_compatibility.md b/docs/users_guide/use_cases/wide_compatibility.md new file mode 100644 index 00000000..5b9f75f2 --- /dev/null +++ b/docs/users_guide/use_cases/wide_compatibility.md @@ -0,0 +1,159 @@ +# Wide Compatibility + +The **mp-units** allows us to implement nice and terse code targeting a specific C++ version and +configuration. Such code is easy to write and understand but might not be portable to some older +environments. + +However, sometimes, we want to develop code that can be compiled on a wide range of various +compilers and configurations. This is why the library also exposes and uses special preprocessor +macros that can be used to ensure the wide compatibility of our code. + +!!! note + + Those macros are used in our short [example applications](../examples/tags_index.md) as those are meant + to be built on all of [the supported compilers](../../getting_started/installation_and_usage.md#cpp-compiler-support). + Some still do not support `std::format`, C++ modules, or C++ versions newer than C++20. + + +## Various compatibility options + +Depending on your compiler's conformance, you can choose to use any of the below styles to write +your code using **mp-units**: + +=== "C++23" + + ```cpp + #include + #include + import mp_units; + + // ... + + inline constexpr struct horizontal_length : quantity_spec {} horizontal_length; + + // ... + + std::cout << std::format(...) << "\n"; + ``` + +=== "C++20" + + ```cpp + #include + #include + import mp_units; + + // ... + + inline constexpr struct horizontal_length : quantity_spec {} horizontal_length; + + // ... + + std::cout << std::format(...) << "\n"; + ``` + +=== "C++20 with header files" + + ```cpp + #include + #include + #include + #include + #include + #include + #include + + // ... + + inline constexpr struct horizontal_length : quantity_spec {} horizontal_length; + + // ... + + std::cout << std::format(...) << "\n"; + ``` + +=== "C++20 with header files + libfmt" + + ```cpp + #include + #include + #include + #include + #include + #include + #include + + // ... + + inline constexpr struct horizontal_length : quantity_spec {} horizontal_length; + + // ... + + std::cout << fmt::format(...) << "\n"; + ``` + +=== "Wide Compatibility" + + ```cpp + #include + #ifdef MP_UNITS_MODULES + #include + import mp_units; + #else + #include + #include + #include + #include + #include + #endif + + // ... + + QUANTITY_SPEC(horizontal_length, isq::length); + + // ... + + std::cout << MP_UNITS_STD_FMT::format(...) << "\n"; + ``` + +!!! tip + + Depending on your preferences, you can either write: + + - terse code directly targeting your specific compiler's abilities, + - verbose code using preprocessor branches and macros that provide the widest compatibility + across various compilers. + + +## Compatibility macros + +This chapter describes only the most essential tools the **mp-units** users need. +All the compatibility macros can be found in the _mp-units/compat_macros.h_ header file. + +!!! tip + + The _mp-units/compat_macros.h_ header file is implicitly included when we use "legacy" headers + in our translation units. However, it has to be explicitly included when we use C++20 modules, + as those do not propagate preprocessor macros. + +### `QUANTITY_SPEC(name, ...)` { #QUANTITY_SPEC } + +Quantity specification definitions benefit from an +[explicit object parameter](https://en.cppreference.com/w/cpp/language/member_functions#Explicit_object_parameter) +added in C++23 to remove the need for CRTP idiom, which significantly simplifies the code. + +This macro benefits from the new C++23 feature if available. Otherwise, it uses the CRTP idiom under +the hood. + +*[CRTP]: Curiously Recurring Template Pattern + +### `MP_UNITS_STD_FMT` + +Some of the supported compilers do not support [std::format](https://en.cppreference.com/w/cpp/utility/format/format) +and related tools. Also, despite using a conformant compiler, some projects still choose to +use [fmtlib](https://github.com/fmtlib/fmt) as their primary formatting facility (e.g., to benefit +from additional features provided with the library). + +This macro resolves to either the `std` or `fmt` namespace, depending on the value of +[MP_UNITS_USE_LIBFMT](../../getting_started/installation_and_usage.md#MP_UNITS_USE_LIBFMT) +CMake option. diff --git a/mkdocs.yml b/mkdocs.yml index 7f5fd92b..e43ba05e 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -162,6 +162,7 @@ nav: - Using Custom Representation Types: users_guide/use_cases/using_custom_representation_types.md - Interoperability with Other Libraries: users_guide/use_cases/interoperability_with_other_libraries.md - Extending the Library: users_guide/use_cases/extending_the_library.md + - Wide Compatibility: users_guide/use_cases/wide_compatibility.md - Examples: - Tags Index: users_guide/examples/tags_index.md - All Examples: From 58479427d1573d4ed7f9fc59d1d438586205b832 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 27/33] style: cmake-format.yaml updated --- .cmake-format.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.cmake-format.yaml b/.cmake-format.yaml index 537bcefb..c80494f1 100644 --- a/.cmake-format.yaml +++ b/.cmake-format.yaml @@ -1,8 +1,8 @@ parse: additional_commands: - add_units_module: + add_mp_units_module: pargs: - nargs: 1 + nargs: 2 kwargs: DEPENDENCIES: "+" HEADERS: "*" From 9611a64ad55bb297228af110b357aa3a5a64fed3 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 28/33] docs: a note about C++ modules availability added to "Installation and Usage" chapter --- docs/getting_started/installation_and_usage.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/getting_started/installation_and_usage.md b/docs/getting_started/installation_and_usage.md index 2b12541b..fb7c15b4 100644 --- a/docs/getting_started/installation_and_usage.md +++ b/docs/getting_started/installation_and_usage.md @@ -46,6 +46,11 @@ flowchart TD | `mp_units.systems` | `mp-units::systems` | All the systems of quantities and units | | `mp_units` | `mp-units::mp-units` | Core + Systems | +!!! note + + C++ modules are provided within the package only when [`cxx_modules`](#cxx_modules) Conan + option is set to `True`. + ## Repository structure and dependencies From 39a66d2c6b611c16755e75fd57be39c3a254f8a3 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 29/33] docs: "C++ modules" tabs added to all the code examples --- docs/getting_started/look_and_feel.md | 168 +++++-- docs/getting_started/quick_start.md | 147 ++++-- docs/index.md | 44 +- .../simple_and_typed_quantities.md | 445 ++++++++++++------ 4 files changed, 566 insertions(+), 238 deletions(-) diff --git a/docs/getting_started/look_and_feel.md b/docs/getting_started/look_and_feel.md index 21e2cee6..581fd1ba 100644 --- a/docs/getting_started/look_and_feel.md +++ b/docs/getting_started/look_and_feel.md @@ -2,30 +2,59 @@ Here is a small example of operations possible on scalar quantities: -```cpp -#include +=== "C++ modules" -using namespace mp_units; -using namespace mp_units::si::unit_symbols; + ```cpp + import mp_units; -// simple numeric operations -static_assert(10 * km / 2 == 5 * km); + using namespace mp_units; + using namespace mp_units::si::unit_symbols; -// unit conversions -static_assert(1 * h == 3600 * s); -static_assert(1 * km + 1 * m == 1001 * m); + // simple numeric operations + static_assert(10 * km / 2 == 5 * km); -// derived quantities -static_assert(1 * km / (1 * s) == 1000 * m / s); -static_assert(2 * km / h * (2 * h) == 4 * km); -static_assert(2 * km / (2 * km / h) == 1 * h); + // unit conversions + static_assert(1 * h == 3600 * s); + static_assert(1 * km + 1 * m == 1001 * m); -static_assert(2 * m * (3 * m) == 6 * m2); + // derived quantities + static_assert(1 * km / (1 * s) == 1000 * m / s); + static_assert(2 * km / h * (2 * h) == 4 * km); + static_assert(2 * km / (2 * km / h) == 1 * h); -static_assert(10 * km / (5 * km) == 2 * one); + static_assert(2 * m * (3 * m) == 6 * m2); -static_assert(1000 / (1 * s) == 1 * kHz); -``` + static_assert(10 * km / (5 * km) == 2 * one); + + static_assert(1000 / (1 * s) == 1 * kHz); + ``` + +=== "Header files" + + ```cpp + #include + + using namespace mp_units; + using namespace mp_units::si::unit_symbols; + + // simple numeric operations + static_assert(10 * km / 2 == 5 * km); + + // unit conversions + static_assert(1 * h == 3600 * s); + static_assert(1 * km + 1 * m == 1001 * m); + + // derived quantities + static_assert(1 * km / (1 * s) == 1000 * m / s); + static_assert(2 * km / h * (2 * h) == 4 * km); + static_assert(2 * km / (2 * km / h) == 1 * h); + + static_assert(2 * m * (3 * m) == 6 * m2); + + static_assert(10 * km / (5 * km) == 2 * one); + + static_assert(1000 / (1 * s) == 1 * kHz); + ``` !!! example "[Try it on Compiler Explorer](https://godbolt.org/z/81Ev7qhTd)" @@ -37,44 +66,83 @@ performed without sacrificing accuracy. Please see the below example for a quick *[NTTP]: Non-Type Template Parameter -```cpp -#include -#include -#include -#include -#include -#include +=== "C++ modules" -using namespace mp_units; + ```cpp + #include + import mp_units; -constexpr QuantityOf auto avg_speed(QuantityOf auto d, - QuantityOf auto t) -{ - return d / t; -} + using namespace mp_units; -int main() -{ - using namespace mp_units::si::unit_symbols; - using namespace mp_units::international::unit_symbols; + constexpr QuantityOf auto avg_speed(QuantityOf auto d, + QuantityOf auto t) + { + return d / t; + } - constexpr quantity v1 = 110 * km / h; - constexpr quantity v2 = 70 * mph; - constexpr quantity v3 = avg_speed(220. * isq::distance[km], 2 * h); - constexpr quantity v4 = avg_speed(isq::distance(140. * mi), 2 * h); - constexpr quantity v5 = v3.in(m / s); - constexpr quantity v6 = value_cast(v4); - constexpr quantity v7 = value_cast(v6); + int main() + { + using namespace mp_units::si::unit_symbols; + using namespace mp_units::international::unit_symbols; - std::cout << v1 << '\n'; // 110 km/h - std::cout << v2 << '\n'; // 70 mi/h - std::cout << std::format("{}", v3) << '\n'; // 110 km/h - std::cout << std::format("{:*^14}", v4) << '\n'; // ***70 mi/h**** - std::cout << std::format("{:%Q in %q}", v5) << '\n'; // 30.5556 in m/s - std::cout << std::format("{0:%Q} in {0:%q}", v6) << '\n'; // 31.2928 in m/s - std::cout << std::format("{:%Q}", v7) << '\n'; // 31 -} -``` + constexpr quantity v1 = 110 * km / h; + constexpr quantity v2 = 70 * mph; + constexpr quantity v3 = avg_speed(220. * isq::distance[km], 2 * h); + constexpr quantity v4 = avg_speed(isq::distance(140. * mi), 2 * h); + constexpr quantity v5 = v3.in(m / s); + constexpr quantity v6 = value_cast(v4); + constexpr quantity v7 = value_cast(v6); + + std::cout << v1 << '\n'; // 110 km/h + std::cout << v2 << '\n'; // 70 mi/h + std::cout << std::format("{}", v3) << '\n'; // 110 km/h + std::cout << std::format("{:*^14}", v4) << '\n'; // ***70 mi/h**** + std::cout << std::format("{:%Q in %q}", v5) << '\n'; // 30.5556 in m/s + std::cout << std::format("{0:%Q} in {0:%q}", v6) << '\n'; // 31.2928 in m/s + std::cout << std::format("{:%Q}", v7) << '\n'; // 31 + } + ``` + +=== "Header files" + + ```cpp + #include + #include + #include + #include + #include + #include + + using namespace mp_units; + + constexpr QuantityOf auto avg_speed(QuantityOf auto d, + QuantityOf auto t) + { + return d / t; + } + + int main() + { + using namespace mp_units::si::unit_symbols; + using namespace mp_units::international::unit_symbols; + + constexpr quantity v1 = 110 * km / h; + constexpr quantity v2 = 70 * mph; + constexpr quantity v3 = avg_speed(220. * isq::distance[km], 2 * h); + constexpr quantity v4 = avg_speed(isq::distance(140. * mi), 2 * h); + constexpr quantity v5 = v3.in(m / s); + constexpr quantity v6 = value_cast(v4); + constexpr quantity v7 = value_cast(v6); + + std::cout << v1 << '\n'; // 110 km/h + std::cout << v2 << '\n'; // 70 mi/h + std::cout << std::format("{}", v3) << '\n'; // 110 km/h + std::cout << std::format("{:*^14}", v4) << '\n'; // ***70 mi/h**** + std::cout << std::format("{:%Q in %q}", v5) << '\n'; // 30.5556 in m/s + std::cout << std::format("{0:%Q} in {0:%q}", v6) << '\n'; // 31.2928 in m/s + std::cout << std::format("{:%Q}", v7) << '\n'; // 31 + } + ``` !!! example "[Try it on Compiler Explorer](https://godbolt.org/z/Tsesa1Pvq)" diff --git a/docs/getting_started/quick_start.md b/docs/getting_started/quick_start.md index 3cb39189..12b9245e 100644 --- a/docs/getting_started/quick_start.md +++ b/docs/getting_started/quick_start.md @@ -20,13 +20,25 @@ The [SI Brochure](../appendix/references.md#SIBrochure) says: Following the above, the value of a quantity in the **mp-units** library is created by multiplying a number with a predefined unit: -```cpp -#include +=== "C++ modules" -using namespace mp_units; + ```cpp + import mp_units; -quantity q = 42 * si::metre / si::second; -``` + using namespace mp_units; + + quantity q = 42 * si::metre / si::second; + ``` + +=== "Header files" + + ```cpp + #include + + using namespace mp_units; + + quantity q = 42 * si::metre / si::second; + ``` !!! info @@ -34,25 +46,50 @@ quantity q = 42 * si::metre / si::second; provided by this and other libraries, a quantity can also be created with a two-parameter constructor: - ```cpp - #include + === "C++ modules" - using namespace mp_units; + ```cpp + import mp_units; - quantity q{42, si::metre / si::second}; - ``` + using namespace mp_units; + + quantity q{42, si::metre / si::second}; + ``` + + === "Header files" + + ```cpp + #include + + using namespace mp_units; + + quantity q{42, si::metre / si::second}; + ``` The above creates an instance of `quantity>{}, int>`. The same can be obtained using optional unit symbols: -```cpp -#include +=== "C++ modules" -using namespace mp_units; -using namespace mp_units::si::unit_symbols; + ```cpp + import mp_units; -quantity q = 42 * m / s; -``` + using namespace mp_units; + using namespace mp_units::si::unit_symbols; + + quantity q = 42 * m / s; + ``` + +=== "Header files" + + ```cpp + #include + + using namespace mp_units; + using namespace mp_units::si::unit_symbols; + + quantity q = 42 * m / s; + ``` !!! tip @@ -62,14 +99,27 @@ quantity q = 42 * m / s; Quantities of the same kind can be added, subtracted, and compared to each other: -```cpp -#include +=== "C++ modules" -using namespace mp_units; -using namespace mp_units::si::unit_symbols; + ```cpp + import mp_units; -static_assert(1 * km + 50 * m == 1050 * m); -``` + using namespace mp_units; + using namespace mp_units::si::unit_symbols; + + static_assert(1 * km + 50 * m == 1050 * m); + ``` + +=== "Header files" + + ```cpp + #include + + using namespace mp_units; + using namespace mp_units::si::unit_symbols; + + static_assert(1 * km + 50 * m == 1050 * m); + ``` Various quantities can be multiplied or divided by each other: @@ -96,24 +146,45 @@ Quantity points should be used in all places where adding two values is meaningl The set of operations that can be done on quantity points is limited compared to quantities. This introduces an additional type-safety. -```cpp -#include -#include -#include -#include +=== "C++ modules" -int main() -{ - using namespace mp_units; - using namespace mp_units::si::unit_symbols; - using namespace mp_units::usc::unit_symbols; + ```cpp + #include + import mp_units; - quantity_point temp{20. * deg_C}; - std::cout << "Temperature: " - << temp.quantity_from_zero() << " (" - << temp.in(deg_F).quantity_from_zero() << ")\n"; -} -``` + int main() + { + using namespace mp_units; + using namespace mp_units::si::unit_symbols; + using namespace mp_units::usc::unit_symbols; + + quantity_point temp{20. * deg_C}; + std::cout << "Temperature: " + << temp.quantity_from_zero() << " (" + << temp.in(deg_F).quantity_from_zero() << ")\n"; + } + ``` + +=== "Header files" + + ```cpp + #include + #include + #include + #include + + int main() + { + using namespace mp_units; + using namespace mp_units::si::unit_symbols; + using namespace mp_units::usc::unit_symbols; + + quantity_point temp{20. * deg_C}; + std::cout << "Temperature: " + << temp.quantity_from_zero() << " (" + << temp.in(deg_F).quantity_from_zero() << ")\n"; + } + ``` The above outputs: diff --git a/docs/index.md b/docs/index.md index 0150746e..cdb5ae99 100644 --- a/docs/index.md +++ b/docs/index.md @@ -38,23 +38,41 @@ The library source code is hosted on [GitHub](https://github.com/mpusz/mp-units) More requirements for C++ modules support can be found in the [CMake's documentation](https://cmake.org/cmake/help/latest/manual/cmake-cxxmodules.7.html). +=== "C++ modules" -```cpp -#include -#include -#include -#include + ```cpp + #include + import mp_units; -using namespace mp_units; + using namespace mp_units; -inline constexpr struct smoot : named_unit<"smoot", mag<67> * usc::inch> {} smoot; + inline constexpr struct smoot : named_unit<"smoot", mag<67> * usc::inch> {} smoot; -int main() -{ - constexpr quantity dist = 364.4 * smoot; - std::cout << "Harvard Bridge length = " << dist << "(" << dist.in(usc::foot) << ", " << dist.in(si::metre) << ") ± 1 εar\n"; -} -``` + int main() + { + constexpr quantity dist = 364.4 * smoot; + std::cout << "Harvard Bridge length = " << dist << "(" << dist.in(usc::foot) << ", " << dist.in(si::metre) << ") ± 1 εar\n"; + } + ``` + +=== "Header files" + + ```cpp + #include + #include + #include + #include + + using namespace mp_units; + + inline constexpr struct smoot : named_unit<"smoot", mag<67> * usc::inch> {} smoot; + + int main() + { + constexpr quantity dist = 364.4 * smoot; + std::cout << "Harvard Bridge length = " << dist << "(" << dist.in(usc::foot) << ", " << dist.in(si::metre) << ") ± 1 εar\n"; + } + ``` Output: diff --git a/docs/users_guide/framework_basics/simple_and_typed_quantities.md b/docs/users_guide/framework_basics/simple_and_typed_quantities.md index 0de6c48a..6c5d01a0 100644 --- a/docs/users_guide/framework_basics/simple_and_typed_quantities.md +++ b/docs/users_guide/framework_basics/simple_and_typed_quantities.md @@ -53,32 +53,62 @@ have shorter type identifiers, resulting in easier-to-understand error messages Here is a simple example showing how to deal with such quantities: -```cpp -#include -#include -#include +=== "C++ modules" -using namespace mp_units; + ```cpp + #include + import mp_units; -constexpr quantity avg_speed(quantity d, - quantity t) -{ - return d / t; -} + using namespace mp_units; -int main() -{ - using namespace mp_units::si::unit_symbols; + constexpr quantity avg_speed(quantity d, + quantity t) + { + return d / t; + } - const quantity distance = 110 * km; - const quantity duration = 2 * h; - const quantity speed = avg_speed(distance, duration); + int main() + { + using namespace mp_units::si::unit_symbols; - std::cout << "A car driving " << distance << " in " << duration - << " has an average speed of " << speed - << " (" << speed.in(km / h) << ")\n"; -} -``` + const quantity distance = 110 * km; + const quantity duration = 2 * h; + const quantity speed = avg_speed(distance, duration); + + std::cout << "A car driving " << distance << " in " << duration + << " has an average speed of " << speed + << " (" << speed.in(km / h) << ")\n"; + } + ``` + +=== "Header files" + + ```cpp + #include + #include + #include + + using namespace mp_units; + + constexpr quantity avg_speed(quantity d, + quantity t) + { + return d / t; + } + + int main() + { + using namespace mp_units::si::unit_symbols; + + const quantity distance = 110 * km; + const quantity duration = 2 * h; + const quantity speed = avg_speed(distance, duration); + + std::cout << "A car driving " << distance << " in " << duration + << " has an average speed of " << speed + << " (" << speed.in(km / h) << ")\n"; + } + ``` The code above prints: @@ -144,38 +174,67 @@ accident. The previous example can be re-typed using typed quantities in the following way: -```cpp -#include -#include -#include -#include +=== "C++ modules" -using namespace mp_units; -using namespace mp_units::si::unit_symbols; + ```cpp + #include + import mp_units; -constexpr quantity avg_speed(quantity d, - quantity t) -{ - return d / t; -} + using namespace mp_units; + using namespace mp_units::si::unit_symbols; -int main() -{ - const quantity distance = isq::distance(110 * km); - const quantity duration = isq::time(2 * h); - const quantity speed = avg_speed(distance, duration); + constexpr quantity avg_speed(quantity d, + quantity t) + { + return d / t; + } - std::cout << "A car driving " << distance << " in " << duration - << " has an average speed of " << speed - << " (" << speed.in(km / h) << ")\n"; -} -``` + int main() + { + const quantity distance = isq::distance(110 * km); + const quantity duration = isq::time(2 * h); + const quantity speed = avg_speed(distance, duration); + + std::cout << "A car driving " << distance << " in " << duration + << " has an average speed of " << speed + << " (" << speed.in(km / h) << ")\n"; + } + ``` + +=== "Header files" + + ```cpp + #include + #include + #include + #include + + using namespace mp_units; + using namespace mp_units::si::unit_symbols; + + constexpr quantity avg_speed(quantity d, + quantity t) + { + return d / t; + } + + int main() + { + const quantity distance = isq::distance(110 * km); + const quantity duration = isq::time(2 * h); + const quantity speed = avg_speed(distance, duration); + + std::cout << "A car driving " << distance << " in " << duration + << " has an average speed of " << speed + << " (" << speed.in(km / h) << ")\n"; + } + ``` ```text A car driving 110 km in 2 h has an average speed of 15.2778 m/s (55 km/h) ``` -!!! example "[Try it on Compiler Explorer](https://godbolt.org/z/q3PzMzqsh)" +!!! example "[Try it on Compiler Explorer](https://godbolt.org/z/MWxG1j4Pc)" In case we will accidentally make the same calculation error as before, this time, we will get a bit longer error message, this time also containing information about the quantity type: @@ -200,116 +259,228 @@ but there are scenarios where they offer additional level of safety. Let's see another example: -=== "Simple" +=== "C++ modules" - ```cpp hl_lines="42" - #include - #include - #include + === "Simple" - using namespace mp_units; + ```cpp hl_lines="41" + #include + import mp_units; - class StorageTank { - quantity base_; - quantity height_; - public: - constexpr StorageTank(const quantity& base, - const quantity& height) : - base_(base), height_(height) - { - } + using namespace mp_units; - // ... - }; + class StorageTank { + quantity base_; + quantity height_; + public: + constexpr StorageTank(const quantity& base, + const quantity& height) : + base_(base), height_(height) + { + } - class CylindricalStorageTank : public StorageTank { - public: - constexpr CylindricalStorageTank(const quantity& radius, - const quantity& height) : - StorageTank(std::numbers::pi * pow<2>(radius), height) - { - } - }; + // ... + }; - class RectangularStorageTank : public StorageTank { - public: - constexpr RectangularStorageTank(const quantity& length, - const quantity& width, - const quantity& height) : - StorageTank(length * width, height) - { - } - }; + class CylindricalStorageTank : public StorageTank { + public: + constexpr CylindricalStorageTank(const quantity& radius, + const quantity& height) : + StorageTank(std::numbers::pi * pow<2>(radius), height) + { + } + }; - int main() - { - using namespace mp_units::si::unit_symbols; - auto tank = RectangularStorageTank(1'000 * mm, 500 * mm, 200 * mm); - // ... - } - ``` + class RectangularStorageTank : public StorageTank { + public: + constexpr RectangularStorageTank(const quantity& length, + const quantity& width, + const quantity& height) : + StorageTank(length * width, height) + { + } + }; -=== "Typed" + int main() + { + using namespace mp_units::si::unit_symbols; + auto tank = RectangularStorageTank(1'000 * mm, 500 * mm, 200 * mm); + // ... + } + ``` - ```cpp hl_lines="53 54 55" - #include - #include - #include - #include + === "Typed" - using namespace mp_units; - using namespace mp_units::si::unit_symbols; + ```cpp hl_lines="51 52 53" + #include + import mp_units; - // add a custom quantity type of kind isq::length - inline constexpr struct horizontal_length - : quantity_spec {} horizontal_length; + using namespace mp_units; + using namespace mp_units::si::unit_symbols; - // add a custom derived quantity type of kind isq::area - // with a constrained quantity equation - inline constexpr struct horizontal_area - : quantity_spec {} horizontal_area; + // add a custom quantity type of kind isq::length + inline constexpr struct horizontal_length + : quantity_spec {} horizontal_length; - class StorageTank { - quantity base_; - quantity height_; - public: - constexpr StorageTank(const quantity& base, - const quantity& height) : - base_(base), height_(height) - { - } + // add a custom derived quantity type of kind isq::area + // with a constrained quantity equation + inline constexpr struct horizontal_area + : quantity_spec {} horizontal_area; - // ... - }; + class StorageTank { + quantity base_; + quantity height_; + public: + constexpr StorageTank(const quantity& base, + const quantity& height) : + base_(base), height_(height) + { + } - class CylindricalStorageTank : public StorageTank { - public: - constexpr CylindricalStorageTank(const quantity& radius, - const quantity& height) : - StorageTank(quantity_cast(std::numbers::pi * pow<2>(radius)), - height) - { - } - }; + // ... + }; - class RectangularStorageTank : public StorageTank { - public: - constexpr RectangularStorageTank(const quantity& length, - const quantity& width, - const quantity& height) : - StorageTank(length * width, height) - { - } - }; + class CylindricalStorageTank : public StorageTank { + public: + constexpr CylindricalStorageTank(const quantity& radius, + const quantity& height) : + StorageTank(quantity_cast(std::numbers::pi * pow<2>(radius)), + height) + { + } + }; - int main() - { - auto tank = RectangularStorageTank(horizontal_length(1'000 * mm), - isq::width(500 * mm), - isq::height(200 * mm)); - // ... - } - ``` + class RectangularStorageTank : public StorageTank { + public: + constexpr RectangularStorageTank(const quantity& length, + const quantity& width, + const quantity& height) : + StorageTank(length * width, height) + { + } + }; + + int main() + { + auto tank = RectangularStorageTank(horizontal_length(1'000 * mm), + isq::width(500 * mm), + isq::height(200 * mm)); + // ... + } + ``` + +=== "Header files" + + === "Simple" + + ```cpp hl_lines="42" + #include + #include + #include + + using namespace mp_units; + + class StorageTank { + quantity base_; + quantity height_; + public: + constexpr StorageTank(const quantity& base, + const quantity& height) : + base_(base), height_(height) + { + } + + // ... + }; + + class CylindricalStorageTank : public StorageTank { + public: + constexpr CylindricalStorageTank(const quantity& radius, + const quantity& height) : + StorageTank(std::numbers::pi * pow<2>(radius), height) + { + } + }; + + class RectangularStorageTank : public StorageTank { + public: + constexpr RectangularStorageTank(const quantity& length, + const quantity& width, + const quantity& height) : + StorageTank(length * width, height) + { + } + }; + + int main() + { + using namespace mp_units::si::unit_symbols; + auto tank = RectangularStorageTank(1'000 * mm, 500 * mm, 200 * mm); + // ... + } + ``` + + === "Typed" + + ```cpp hl_lines="53 54 55" + #include + #include + #include + #include + + using namespace mp_units; + using namespace mp_units::si::unit_symbols; + + // add a custom quantity type of kind isq::length + inline constexpr struct horizontal_length + : quantity_spec {} horizontal_length; + + // add a custom derived quantity type of kind isq::area + // with a constrained quantity equation + inline constexpr struct horizontal_area + : quantity_spec {} horizontal_area; + + class StorageTank { + quantity base_; + quantity height_; + public: + constexpr StorageTank(const quantity& base, + const quantity& height) : + base_(base), height_(height) + { + } + + // ... + }; + + class CylindricalStorageTank : public StorageTank { + public: + constexpr CylindricalStorageTank(const quantity& radius, + const quantity& height) : + StorageTank(quantity_cast(std::numbers::pi * pow<2>(radius)), + height) + { + } + }; + + class RectangularStorageTank : public StorageTank { + public: + constexpr RectangularStorageTank(const quantity& length, + const quantity& width, + const quantity& height) : + StorageTank(length * width, height) + { + } + }; + + int main() + { + auto tank = RectangularStorageTank(horizontal_length(1'000 * mm), + isq::width(500 * mm), + isq::height(200 * mm)); + // ... + } + ``` In the above example, the highlighted call doesn't look that safe anymore in the case of simple quantities, right? Suppose someone, either by mistake or due to some refactoring, From 047b8a140a59d7ef67983d280a81af95468e80ff Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 30/33] build: `add_mp_units_module` now use `HEADER_SET` --- cmake/TestPublicHeaders.cmake | 2 +- src/cmake/AddMPUnitsModule.cmake | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cmake/TestPublicHeaders.cmake b/cmake/TestPublicHeaders.cmake index e1756af5..38a50770 100644 --- a/cmake/TestPublicHeaders.cmake +++ b/cmake/TestPublicHeaders.cmake @@ -43,7 +43,7 @@ function(get_target_sources target paths_out) list(APPEND targets ${target}) foreach(t ${targets}) - get_target_property(sources ${t} SOURCES) + get_target_property(sources ${t} HEADER_SET) if(sources) get_target_property(source_dir ${t} SOURCE_DIR) foreach(f ${sources}) diff --git a/src/cmake/AddMPUnitsModule.cmake b/src/cmake/AddMPUnitsModule.cmake index 642d2255..e8d12c6f 100644 --- a/src/cmake/AddMPUnitsModule.cmake +++ b/src/cmake/AddMPUnitsModule.cmake @@ -61,7 +61,17 @@ function(add_mp_units_module name target_name) endif() # define the target for a module - add_library(${target_name} ${SCOPE} ${ARG_HEADERS}) + add_library(${target_name} ${SCOPE}) + target_sources( + ${target_name} + ${${projectPrefix}TARGET_SCOPE} + FILE_SET + HEADERS + BASE_DIRS + ${CMAKE_CURRENT_SOURCE_DIR}/include + FILES + ${ARG_HEADERS} + ) target_link_libraries(${target_name} ${${projectPrefix}TARGET_SCOPE} ${ARG_DEPENDENCIES}) if(ARG_HEADERS) target_include_directories( @@ -76,13 +86,10 @@ function(add_mp_units_module name target_name) target_sources(${target_name} PUBLIC FILE_SET CXX_MODULES FILES ${ARG_MODULE_INTERFACE_UNIT}) install(TARGETS ${target_name} EXPORT mp-unitsTargets - FILE_SET CXX_MODULES + FILE_SET HEADERS FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_LIBDIR}/miu ) else() - install(TARGETS ${target_name} EXPORT mp-unitsTargets) - endif() - if(ARG_HEADERS) - install(DIRECTORY include/mp-units TYPE INCLUDE) + install(TARGETS ${target_name} EXPORT mp-unitsTargets FILE_SET HEADERS) endif() endfunction() From 78dedb1d1c13c115070e2a55535f810ea539e7be Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 08:51:01 +0100 Subject: [PATCH 31/33] style: whitespaces fixed in "Wide Compatibility" to make pre-commit happy --- docs/users_guide/use_cases/wide_compatibility.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/users_guide/use_cases/wide_compatibility.md b/docs/users_guide/use_cases/wide_compatibility.md index 5b9f75f2..95cc054a 100644 --- a/docs/users_guide/use_cases/wide_compatibility.md +++ b/docs/users_guide/use_cases/wide_compatibility.md @@ -119,7 +119,7 @@ your code using **mp-units**: !!! tip Depending on your preferences, you can either write: - + - terse code directly targeting your specific compiler's abilities, - verbose code using preprocessor branches and macros that provide the widest compatibility across various compilers. From 53e25582e627666831b44330e80b48be330c9e29 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 09:14:42 +0100 Subject: [PATCH 32/33] fix: `target_sources` with `FILE_SET HEADERS` called only when headers are present --- src/cmake/AddMPUnitsModule.cmake | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/cmake/AddMPUnitsModule.cmake b/src/cmake/AddMPUnitsModule.cmake index e8d12c6f..da42cd1b 100644 --- a/src/cmake/AddMPUnitsModule.cmake +++ b/src/cmake/AddMPUnitsModule.cmake @@ -62,25 +62,26 @@ function(add_mp_units_module name target_name) # define the target for a module add_library(${target_name} ${SCOPE}) - target_sources( - ${target_name} - ${${projectPrefix}TARGET_SCOPE} - FILE_SET - HEADERS - BASE_DIRS - ${CMAKE_CURRENT_SOURCE_DIR}/include - FILES - ${ARG_HEADERS} - ) target_link_libraries(${target_name} ${${projectPrefix}TARGET_SCOPE} ${ARG_DEPENDENCIES}) + set_target_properties(${target_name} PROPERTIES EXPORT_NAME ${name}) + add_library(mp-units::${name} ALIAS ${target_name}) + if(ARG_HEADERS) + target_sources( + ${target_name} + ${${projectPrefix}TARGET_SCOPE} + FILE_SET + HEADERS + BASE_DIRS + ${CMAKE_CURRENT_SOURCE_DIR}/include + FILES + ${ARG_HEADERS} + ) target_include_directories( ${target_name} ${unitsAsSystem} ${${projectPrefix}TARGET_SCOPE} $ $ ) endif() - set_target_properties(${target_name} PROPERTIES EXPORT_NAME ${name}) - add_library(mp-units::${name} ALIAS ${target_name}) if(${projectPrefix}BUILD_CXX_MODULES) target_sources(${target_name} PUBLIC FILE_SET CXX_MODULES FILES ${ARG_MODULE_INTERFACE_UNIT}) From 691414227584675e718fe96d3fd100234458b634 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 6 Jan 2024 09:25:17 +0100 Subject: [PATCH 33/33] fix: `compat_macros` included to fix the compilation after rebase --- example/measurement.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/example/measurement.cpp b/example/measurement.cpp index 0f3813e7..8a6a5948 100644 --- a/example/measurement.cpp +++ b/example/measurement.cpp @@ -20,6 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include #include #include #include