From f0cf99457424dd7b3cc1bf6007bff42b97b3421b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johel=20Ernesto=20Guerrero=20Pe=C3=B1a?= Date: Wed, 30 Aug 2023 10:28:30 -0400 Subject: [PATCH] feat: add module `mp_units` --- src/CMakeLists.txt | 14 +++++ .../include/mp-units/bits/fmt_hacks.h | 2 +- .../mp-units/bits/external/type_list.h | 1 + src/core/include/mp-units/quantity_spec.h | 15 +---- .../include/mp-units/quantity_spec_macro.h | 13 +++++ src/mp-units.cpp | 58 +++++++++++++++++++ src/utility/include/mp-units/random.h | 8 +-- test/unit_test/static/CMakeLists.txt | 10 +++- test/unit_test/static/quantity_test.cpp | 9 ++- 9 files changed, 106 insertions(+), 24 deletions(-) create mode 100644 src/core/include/mp-units/quantity_spec_macro.h create mode 100644 src/mp-units.cpp 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-fmt/include/mp-units/bits/fmt_hacks.h b/src/core-fmt/include/mp-units/bits/fmt_hacks.h index 008c3159ef..340e014758 100644 --- a/src/core-fmt/include/mp-units/bits/fmt_hacks.h +++ b/src/core-fmt/include/mp-units/bits/fmt_hacks.h @@ -62,7 +62,7 @@ MP_UNITS_DIAGNOSTIC_POP #else -#ifndef __cpp_lib_format +#if !defined(__cpp_lib_format) && !defined(__cpp_lib_format_ranges) #error "std::formatting facility not supported" #endif 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..e95c8989a2 --- /dev/null +++ b/src/core/include/mp-units/quantity_spec_macro.h @@ -0,0 +1,13 @@ +#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..15a949475b --- /dev/null +++ b/src/mp-units.cpp @@ -0,0 +1,58 @@ +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 + +// 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/static/CMakeLists.txt b/test/unit_test/static/CMakeLists.txt index d8a6cb04ff..0fe085a8ed 100644 --- a/test/unit_test/static/CMakeLists.txt +++ b/test/unit_test/static/CMakeLists.txt @@ -23,7 +23,6 @@ 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> ) @@ -63,5 +62,10 @@ 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_compile_definitions("${target}" PRIVATE $<$:MP_UNITS_MODULES>) +endforeach() diff --git a/test/unit_test/static/quantity_test.cpp b/test/unit_test/static/quantity_test.cpp index c8fd713bd2..e12a59e166 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;