feat: add module mp_units

This commit is contained in:
Johel Ernesto Guerrero Peña authored and Mateusz Pusz committed 2024-01-06 08:51:00 +01:00
1 parent f3ad392123
commit 7cb2099af5
92 files changed
+754 -141

No files matched your search

+58
View File
@@ -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)
+45
View File
@@ -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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
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)
@@ -27,6 +27,8 @@
//
// For the license information refer to format.h.
#pragma once
#include <mp-units/bits/external/hacks.h>
#ifndef MP_UNITS_USE_LIBFMT
+1
View File
@@ -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=$<BOOL:${${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)
+40
View File
@@ -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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
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)
@@ -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 <gsl/gsl-lite.hpp>
#include <mp-units/bits/external/hacks.h>
#include <array>
#include <compare>
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <initializer_list>
#include <iterator>
#include <limits>
#include <numbers>
#include <numeric>
#include <optional>
#include <ranges>
#include <string>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <utility>
// utility
#include <chrono>
#include <cmath>
#include <random>
@@ -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, __VA_ARGS__> { \
} name
#endif
+2 -3
View File
@@ -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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
+1
View File
@@ -22,6 +22,7 @@
#pragma once
#include <mp-units/bits/math_core.h>
#include <mp-units/concepts.h>
#include <mp-units/customization_points.h>
#include <mp-units/dimension.h>
+1 -14
View File
@@ -32,6 +32,7 @@
#include <mp-units/bits/reference_concepts.h>
#include <mp-units/bits/representation_concepts.h>
#include <mp-units/dimension.h>
#include <mp-units/quantity_spec_macro.h>
#include <tuple>
namespace mp_units {
@@ -364,20 +365,6 @@ struct quantity_spec<Self, QS, Eq, Args...> : quantity_spec<Self, QS, Args...> {
static constexpr quantity_character character = detail::quantity_character_init<Args...>(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, __VA_ARGS__> { \
} name
#endif
/**
* @brief A specification of a derived quantity
+13
View File
@@ -0,0 +1,13 @@
module;
#include <mp-units/bits/core-gmf.h>
#include <mp-units/bits/fmt_hacks.h>
export module mp_units.core_fmt;
export import mp_units.core;
export
{
#include <mp-units/format.h>
}
+13
View File
@@ -0,0 +1,13 @@
module;
#include <mp-units/bits/core-gmf.h>
#include <sstream>
export module mp_units.core_io;
export import mp_units.core;
export
{
#include <mp-units/ostream.h>
}
+11
View File
@@ -0,0 +1,11 @@
module;
#include <mp-units/bits/core-gmf.h>
export module mp_units.core;
export
{
// core
#include <mp-units/core.h>
}
+32
View File
@@ -0,0 +1,32 @@
module;
#include <mp-units/bits/core-gmf.h>
#include <mp-units/quantity_spec_macro.h>
export module mp_units.systems;
export import mp_units.core;
export
{
// systems
#include <mp-units/systems/angular/angular.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/iec80000.h>
#include <mp-units/systems/imperial/imperial.h>
#include <mp-units/systems/international/international.h>
#include <mp-units/systems/isq/isq.h>
#include <mp-units/systems/isq_angle/isq_angle.h>
#include <mp-units/systems/natural/natural.h>
#include <mp-units/systems/si/si.h>
#include <mp-units/systems/typographic/typographic.h>
#include <mp-units/systems/usc/usc.h>
// utility
#include <mp-units/chrono.h>
#include <mp-units/compare.h>
#include <mp-units/math.h>
#include <mp-units/random.h>
}
+8
View File
@@ -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;
+2 -2
View File
@@ -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