diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index dae84e825d..ac1f6ae895 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -31,6 +31,10 @@ target_include_directories(example_utils INTERFACE include) 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) + target_compile_definitions(${target} PRIVATE MP_UNITS_MODULES) + endif() endfunction() add_example(avg_speed mp-units::core-io mp-units::si mp-units::cgs mp-units::usc) diff --git a/example/avg_speed.cpp b/example/avg_speed.cpp index 3c2ce2dc75..ba8e968bc6 100644 --- a/example/avg_speed.cpp +++ b/example/avg_speed.cpp @@ -20,13 +20,17 @@ // 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 +#endif namespace { diff --git a/example/capacitor_time_curve.cpp b/example/capacitor_time_curve.cpp index d1fb12ce18..02bbc2719f 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 fb9f93e3ab..58cdd912ef 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 a3b810512e..f75d4bf7b6 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 587f1f7dac..aa1d11acfe 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; +#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 092f0d236a..be88f3b432 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_lib/CMakeLists.txt b/example/glide_computer_lib/CMakeLists.txt index cd6cbcaec7..0a689b11e4 100644 --- a/example/glide_computer_lib/CMakeLists.txt +++ b/example/glide_computer_lib/CMakeLists.txt @@ -25,3 +25,7 @@ cmake_minimum_required(VERSION 3.2) 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) target_include_directories(glide_computer_lib PUBLIC include) +if(TARGET mp-units::modules) + target_link_libraries(glide_computer_lib PRIVATE mp-units::modules) + target_compile_definitions(glide_computer_lib PRIVATE MP_UNITS_MODULES) +endif() diff --git a/example/glide_computer_lib/glide_computer_lib.cpp b/example/glide_computer_lib/glide_computer_lib.cpp index c0fa44d7bf..46d2c9ce89 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; +#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 8503cc3b0c..9adfae1821 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 041bbf8488..2a6e8700c2 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 574b086566..08148d50fd 100644 --- a/example/include/geographic.h +++ b/example/include/geographic.h @@ -24,16 +24,20 @@ #include "ranged_representation.h" #include +#include +#include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include #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 60bab6fe91..aaeaca0a85 100644 --- a/example/include/ranged_representation.h +++ b/example/include/ranged_representation.h @@ -24,10 +24,14 @@ #include "validated_type.h" #include -#include #include #include #include +#ifdef MP_UNITS_MODULES +import mp_units; +#else +#include +#endif template) auto Min, MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(std::convertible_to) auto Max> diff --git a/example/kalman_filter/CMakeLists.txt b/example/kalman_filter/CMakeLists.txt index f137001899..8be30a0afd 100644 --- a/example/kalman_filter/CMakeLists.txt +++ b/example/kalman_filter/CMakeLists.txt @@ -28,6 +28,10 @@ cmake_minimum_required(VERSION 3.2) 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) + target_compile_definitions(${target} PRIVATE MP_UNITS_MODULES) + 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 0d38ebaa78..de888bcd2a 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 bee7176107..c038f253eb 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 b7b4171462..076492af35 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 30e11f4354..6aa59dca21 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 f0c4a2b26f..6036420028 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 e50114ebcf..b4be7e3c1e 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 ec2954088f..ad00787ada 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 613a6da7cc..aecf79857d 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 081b8507b8..a5ecbdff36 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 b11492af0d..89f693c6f4 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 99355a611a..26ebf2d82d 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 6cf9e953fd..6a4673e5a3 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 4ec3f725f3..8719320b92 100644 --- a/example/storage_tank.cpp +++ b/example/storage_tank.cpp @@ -20,6 +20,15 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#include +#include +#include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include @@ -27,10 +36,7 @@ #include #include #include -#include -#include -#include -#include +#endif template requires mp_units::is_scalar diff --git a/example/strong_angular_quantities.cpp b/example/strong_angular_quantities.cpp index 7d375e3cd2..298a097e78 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 9d6a9f8b6d..86d4217e14 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 diff --git a/example/unmanned_aerial_vehicle.cpp b/example/unmanned_aerial_vehicle.cpp index 56ecd8285c..ef1a8b1c40 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 c0249ea936..fe1653a888 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,6 +51,20 @@ target_link_libraries( add_library(mp-units::mp-units ALIAS mp-units) install(TARGETS mp-units EXPORT mp-unitsTargets) +# C++ module +if(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API) + add_library(mp-units-modules STATIC) + 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 PRIVATE mp-units::mp-units) + target_include_directories( + mp-units-modules ${unitsAsSystem} INTERFACE $ + $ + ) +endif() + # local build export(EXPORT mp-unitsTargets NAMESPACE mp-units::) configure_file("mp-unitsConfig.cmake" "." COPYONLY) diff --git a/src/core/include/mp-units/bits/external/type_list.h b/src/core/include/mp-units/bits/external/type_list.h index 5369ce18db..80b66e060f 100644 --- a/src/core/include/mp-units/bits/external/type_list.h +++ b/src/core/include/mp-units/bits/external/type_list.h @@ -24,6 +24,7 @@ #include // IWYU pragma: keep #include +#include #include MP_UNITS_DIAGNOSTIC_PUSH diff --git a/src/core/include/mp-units/quantity_spec.h b/src/core/include/mp-units/quantity_spec.h index 0bd2fe95e3..805182f971 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 { @@ -359,20 +360,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/core/include/mp-units/quantity_spec_macro.h b/src/core/include/mp-units/quantity_spec_macro.h new file mode 100644 index 0000000000..9e45b833df --- /dev/null +++ b/src/core/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/mp-units.cpp b/src/mp-units.cpp new file mode 100644 index 0000000000..aff96a3988 --- /dev/null +++ b/src/mp-units.cpp @@ -0,0 +1,67 @@ +module; + +// core +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// core-io +#include + +// core-fmt +#include + +// utility +#include +#include +#include + +export module mp_units; + +export +{ +// core +#include + +// core-io +#include + +// core-fmt +#include + +// systems +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// utility +#include +#include +#include +} diff --git a/src/utility/include/mp-units/random.h b/src/utility/include/mp-units/random.h index 2c26b97a97..811494875d 100644 --- a/src/utility/include/mp-units/random.h +++ b/src/utility/include/mp-units/random.h @@ -30,7 +30,7 @@ namespace mp_units { namespace detail { template -static std::vector i_qty_to_rep(InputIt first, InputIt last) +std::vector i_qty_to_rep(InputIt first, InputIt last) { std::vector intervals_rep; intervals_rep.reserve(static_cast(std::distance(first, last))); @@ -41,7 +41,7 @@ static std::vector i_qty_to_rep(InputIt first, InputIt last) } template -static std::vector bl_qty_to_rep(std::initializer_list& bl) +std::vector bl_qty_to_rep(std::initializer_list& bl) { std::vector bl_rep; bl_rep.reserve(bl.size()); @@ -52,7 +52,7 @@ static std::vector bl_qty_to_rep(std::initializer_list& bl) } template -inline static std::vector fw_bl_pwc(std::initializer_list& bl, UnaryOperation fw) +std::vector fw_bl_pwc(std::initializer_list& bl, UnaryOperation fw) { using rep = MP_UNITS_TYPENAME Q::rep; std::vector w_bl; @@ -70,7 +70,7 @@ inline static std::vector fw_bl_pwc(std::initializer_list& b } template -static std::vector fw_bl_pwl(std::initializer_list& bl, UnaryOperation fw) +std::vector fw_bl_pwl(std::initializer_list& bl, UnaryOperation fw) { std::vector weights; weights.reserve(bl.size()); diff --git a/test/unit_test/runtime/almost_equals.h b/test/unit_test/runtime/almost_equals.h index 69b972c1ec..adff079d91 100644 --- a/test/unit_test/runtime/almost_equals.h +++ b/test/unit_test/runtime/almost_equals.h @@ -21,8 +21,12 @@ // SOFTWARE. #include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #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 b7f459713e..c33654289a 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 9bdce188b4..8edefbac08 100644 --- a/test/unit_test/runtime/fmt_test.cpp +++ b/test/unit_test/runtime/fmt_test.cpp @@ -22,6 +22,12 @@ #include #include +#include +#include +#include +#ifdef MP_UNITS_MODULES +import mp_units; +#else #include #include #include @@ -29,9 +35,7 @@ #include #include #include -#include -#include -#include +#endif template requires mp_units::is_scalar diff --git a/test/unit_test/runtime/math_test.cpp b/test/unit_test/runtime/math_test.cpp index 4e838273ea..e513deec31 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 d8a6cb04ff..54217b55f4 100644 --- a/test/unit_test/static/CMakeLists.txt +++ b/test/unit_test/static/CMakeLists.txt @@ -23,10 +23,16 @@ cmake_minimum_required(VERSION 3.2) add_library(unit_tests_static_truncating quantity_test.cpp) -target_link_libraries(unit_tests_static_truncating PRIVATE mp-units::mp-units) -target_compile_options( - unit_tests_static_truncating PRIVATE $,/wd4242 /wd4244,-Wno-conversion> -) + +set(no_truncation_warning_targets unit_tests_static_truncating) +if(TARGET mp-units::modules) + list(APPEND no_truncation_warning_targets mp-units-modules) + set(mp_units_modules_target mp-units::modules) + set(mp_units_modules_macro MP_UNITS_MODULES) +endif() +foreach(target IN LISTS no_truncation_warning_targets) + target_compile_options("${target}" PRIVATE $,/wd4242 /wd4244,-Wno-conversion>) +endforeach() add_library( unit_tests_static @@ -63,5 +69,8 @@ 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) +target_link_libraries(unit_tests_static PRIVATE unit_tests_static_truncating) +foreach(target unit_tests_static_truncating unit_tests_static) + target_link_libraries(${target} PRIVATE mp-units::mp-units ${mp_units_modules_target}) + target_compile_definitions(${target} PRIVATE ${mp_units_modules_macro}) +endforeach() diff --git a/test/unit_test/static/angular_test.cpp b/test/unit_test/static/angular_test.cpp index c3010dfe86..c0c5a23b6b 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 e0b36fffb2..79d86129a3 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 75d87128ef..25a69920ef 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/concepts_test.cpp b/test/unit_test/static/concepts_test.cpp index 21c6cbcc55..e4409295cb 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 689c9666d0..9288679d3e 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 7d18effd77..2ebc01a695 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 d5091f54c9..425b712a2e 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 4835fbdfeb..c4a56aeddc 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 d8a1b51376..6014b34ebb 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 f58e110efe..8be44a11e2 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 33ddec6808..7c94c60159 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 4732185385..0780cebe13 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 7b3b3a741d..13d1ed2600 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 a5a312194b..910c9e2605 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 ef59707664..fdb324963f 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 151e5ad7b5..7f7fe4ed55 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 eaf2cc17c6..f0eb031b8e 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 a8b23053a0..ed380b5ac4 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 #if __cpp_lib_constexpr_cmath || MP_UNITS_COMP_GCC diff --git a/test/unit_test/static/natural_test.cpp b/test/unit_test/static/natural_test.cpp index 5666991fac..5dbc32b50b 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 c75f04afd0..ebbb7d515b 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 71e0457b86..4e8ddf9885 100644 --- a/test/unit_test/static/quantity_point_test.cpp +++ b/test/unit_test/static/quantity_point_test.cpp @@ -21,13 +21,19 @@ // SOFTWARE. #include "test_tools.h" +#include +#include +#include +#include +#ifdef MP_UNITS_MODULES +#include +import mp_units; +#else #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 2183fb5ffa..eb64235306 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 c8fd713bd2..c59ccea11f 100644 --- a/test/unit_test/static/quantity_test.cpp +++ b/test/unit_test/static/quantity_test.cpp @@ -21,12 +21,18 @@ // SOFTWARE. #include "test_tools.h" +#include +#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 5bf9bec08d..fd2113bc00 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 010b77f58b..35bf959fa0 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 69d83096c7..8ce659358d 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 0cfa2b4e89..292bbb9eee 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/type_list_test.cpp b/test/unit_test/static/type_list_test.cpp index 6720ebbbd2..c3d61d5215 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 9a47469ca4..71c713d17b 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 a642caaf86..cc129ae950 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 ff5ab4ef83..3c49d3dd9e 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 b55d02fad8..1c0c5bdf60 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 {