Skip to content

Commit

Permalink
refactor: modules support redesigned
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Dec 29, 2023
1 parent 334a4d1 commit 9065780
Show file tree
Hide file tree
Showing 129 changed files with 271 additions and 838 deletions.
23 changes: 3 additions & 20 deletions .cmake-format.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
68 changes: 31 additions & 37 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mp-units-depependencies>...)
# add_example(target <depependencies>...)
#
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)
2 changes: 1 addition & 1 deletion example/clcpp_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
along with this program. If not, see http://www.gnu.org/licenses./
*/

#include <mp-units/bits/fmt_hacks.h>
#include <mp-units/compat_fmt_macros.h>
#include <iostream>
#ifdef MP_UNITS_MODULES
import mp_units;
Expand Down
2 changes: 1 addition & 1 deletion example/conversion_factor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
along with this program. If not, see http://www.gnu.org/licenses./
*/

#include <mp-units/bits/fmt_hacks.h>
#include <mp-units/compat_fmt_macros.h>
#include <iostream>
#include <type_traits>
#ifdef MP_UNITS_MODULES
Expand Down
2 changes: 1 addition & 1 deletion example/currency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <mp-units/quantity_spec_macro.h>
#include <mp-units/compat_macros.h>
#include <iostream>
#include <map>
#ifdef MP_UNITS_MODULES
Expand Down
2 changes: 1 addition & 1 deletion example/foot_pound_second.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <mp-units/bits/fmt_hacks.h>
#include <mp-units/compat_fmt_macros.h>
#include <iostream>
#include <string_view>
#ifdef MP_UNITS_MODULES
Expand Down
5 changes: 2 additions & 3 deletions example/glide_computer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// SOFTWARE.

#include "glide_computer_lib.h"
#include <mp-units/bits/fmt_hacks.h>
#include <mp-units/compat_fmt_macros.h>
#include <array>
#include <exception>
#include <iostream>
Expand All @@ -32,10 +32,9 @@
#ifdef MP_UNITS_MODULES
import mp_units;
#else
#include <mp-units/chrono.h>
#include <mp-units/math.h>
#include <mp-units/systems/international/international.h>
#include <mp-units/systems/si/unit_symbols.h>
#include <mp-units/systems/si/si.h>
#endif

namespace {
Expand Down
16 changes: 9 additions & 7 deletions example/glide_computer_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions example/glide_computer_lib/include/glide_computer_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#pragma once

#include <mp-units/quantity_spec_macro.h>
#include <mp-units/compat_macros.h>
//
#include "geographic.h"
#include <algorithm>
Expand All @@ -36,10 +36,10 @@
#ifdef MP_UNITS_MODULES
import mp_units;
#else
#include <mp-units/chrono.h>
#include <mp-units/math.h> // IWYU pragma: keep
#include <mp-units/quantity_point.h>
#include <mp-units/systems/isq/space_and_time.h>
#include <mp-units/systems/si/chrono.h>
#endif

// An example of a really simplified tactical glide computer
Expand Down
2 changes: 1 addition & 1 deletion example/hello_units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// !!! renders correctly in the documentation "Examples" section. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#include <mp-units/bits/fmt_hacks.h>
#include <mp-units/compat_fmt_macros.h>
#include <iostream>
#ifdef MP_UNITS_MODULES
import mp_units;
Expand Down
5 changes: 2 additions & 3 deletions example/include/geographic.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#pragma once

#include "ranged_representation.h"
#include <mp-units/bits/fmt_hacks.h>
#include <mp-units/compat_fmt_macros.h>
#include <compare>
#include <limits>
#include <numbers>
Expand All @@ -33,11 +33,10 @@ import mp_units;
#else
#include <mp-units/compare.h>
#include <mp-units/format.h>
#include <mp-units/math.h>
#include <mp-units/quantity.h>
#include <mp-units/quantity_point.h>
#include <mp-units/systems/isq/space_and_time.h>
#include <mp-units/systems/si/units.h>
#include <mp-units/systems/si/si.h>
#endif

namespace geographic {
Expand Down
2 changes: 1 addition & 1 deletion example/include/validated_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#pragma once

#include <gsl/gsl-lite.hpp>
#include <mp-units/bits/fmt_hacks.h>
#include <mp-units/compat_fmt_macros.h>
#include <ostream>
#include <utility>
#ifdef MP_UNITS_MODULES
Expand Down
28 changes: 8 additions & 20 deletions example/kalman_filter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,11 @@

cmake_minimum_required(VERSION 3.5)

#
# add_example(target <depependencies>...)
#
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)
2 changes: 1 addition & 1 deletion example/kalman_filter/kalman.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#pragma once

#include <mp-units/bits/fmt_hacks.h>
#include <mp-units/compat_fmt_macros.h>
#include <tuple>
#ifdef MP_UNITS_MODULES
import mp_units;
Expand Down
2 changes: 1 addition & 1 deletion example/si_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// !!! renders correctly in the documentation "Examples" section. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#include <mp-units/bits/fmt_hacks.h>
#include <mp-units/compat_fmt_macros.h>
#include <iostream>
#ifdef MP_UNITS_MODULES
import mp_units;
Expand Down
2 changes: 1 addition & 1 deletion example/spectroscopy_units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <mp-units/bits/fmt_hacks.h>
#include <mp-units/compat_fmt_macros.h>
#include <iostream>
#include <tuple>
#ifdef MP_UNITS_MODULES
Expand Down
9 changes: 3 additions & 6 deletions example/storage_tank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <mp-units/bits/fmt_hacks.h>
#include <mp-units/quantity_spec_macro.h>
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <cassert>
#include <chrono>
#include <iostream>
Expand All @@ -30,14 +30,11 @@
#ifdef MP_UNITS_MODULES
import mp_units;
#else
#include <mp-units/chrono.h>
#include <mp-units/format.h>
#include <mp-units/math.h>
#include <mp-units/systems/isq/mechanics.h>
#include <mp-units/systems/isq/space_and_time.h>
#include <mp-units/systems/si/constants.h>
#include <mp-units/systems/si/unit_symbols.h>
#include <mp-units/systems/si/units.h>
#include <mp-units/systems/si/si.h>
#endif

// allows standard gravity (acceleration) and weight (force) to be expressed with scalar representation
Expand Down
2 changes: 1 addition & 1 deletion example/unmanned_aerial_vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// SOFTWARE.

#include "geographic.h"
#include <mp-units/bits/fmt_hacks.h>
#include <mp-units/compat_fmt_macros.h>
#include <cassert>
#include <iostream>
#ifdef MP_UNITS_MODULES
Expand Down
Loading

0 comments on commit 9065780

Please sign in to comment.