Skip to content

Commit

Permalink
feat: import std; support added
Browse files Browse the repository at this point in the history
Resolves #595
  • Loading branch information
mpusz committed Jul 16, 2024
1 parent a469182 commit b870b85
Show file tree
Hide file tree
Showing 93 changed files with 425 additions and 9 deletions.
25 changes: 24 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class MPUnitsConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
options = {
"cxx_modules": [True, False],
"import_std": [True, False],
"std_format": [True, False],
"string_view_ret": [True, False],
"no_crtp": [True, False],
Expand All @@ -64,6 +65,7 @@ class MPUnitsConan(ConanFile):
}
default_options = {
# "cxx_modules" default set in config_options()
# "import_std" default set in config_options()
# "std_format" default set in config_options()
# "string_view_ret" default set in config_options()
# "no_crtp" default set in config_options()
Expand Down Expand Up @@ -108,6 +110,10 @@ def _feature_compatibility(self):
"min_cppstd": "20",
"compiler": {"gcc": "", "clang": "17", "apple-clang": "", "msvc": ""},
},
"import_std": {
"min_cppstd": "23",
"compiler": {"gcc": "", "clang": "18", "apple-clang": "", "msvc": ""},
},
"static_constexpr_vars_in_constexpr_func": {
"min_cppstd": "23",
"compiler": {"gcc": "13", "clang": "17", "apple-clang": "", "msvc": ""},
Expand All @@ -128,6 +134,7 @@ def _option_feature_map(self):
return {
"std_format": "std_format",
"cxx_modules": "cxx_modules",
"import_std": "import_std",
"string_view_ret": "static_constexpr_vars_in_constexpr_func",
"no_crtp": "explicit_this",
}
Expand Down Expand Up @@ -210,7 +217,7 @@ def requirements(self):
self.requires("fmt/11.0.1")

def build_requirements(self):
self.tool_requires("cmake/[>=3.29 <4]")
self.tool_requires("cmake/[>=3.30 <4]")
if self._build_all:
if not self.options.freestanding:
self.test_requires("catch2/3.6.0")
Expand All @@ -226,6 +233,16 @@ def validate(self):
raise ConanInvalidConfiguration(
"'contracts' should be set to 'none' for a freestanding build"
)
# mixing of `import std;` and regular header files includes does not work for now
if self.options.import_std:
if self.options.contracts != "none":
raise ConanInvalidConfiguration(
"'contracts' should be set to 'none' to use `import std;`"
)
if not self.options.std_format:
raise ConanInvalidConfiguration(
"'std_format' should be enabled to use `import std;`"
)

def layout(self):
cmake_layout(self)
Expand All @@ -242,6 +259,12 @@ def generate(self):
if self.options.cxx_modules:
tc.cache_variables["CMAKE_CXX_SCAN_FOR_MODULES"] = True
tc.cache_variables["MP_UNITS_BUILD_CXX_MODULES"] = True
if self.options.import_std:
tc.cache_variables["CMAKE_CXX_MODULE_STD"] = True
# Current experimental support according to `Help/dev/experimental.rst`
tc.cache_variables[
"CMAKE_EXPERIMENTAL_CXX_IMPORT_STD"
] = "0e5b6991-d74f-4b3d-a41c-cf096e0b2508"
if self.options.freestanding:
tc.cache_variables["MP_UNITS_API_FREESTANDING"] = True
else:
Expand Down
17 changes: 16 additions & 1 deletion docs/getting_started/installation_and_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"}

[conan C++ modules support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0

[`import_std`](#import_std){ #import_std }

: [:octicons-tag-24: 2.3.0][conan import std support] · :octicons-milestone-24: `True`/`False` (Default: automatically determined from settings)

Enables `import std;` usage.

[conan import std support]: https://github.com/mpusz/mp-units/releases/tag/v2.3.0

[`std_format`](#std_format){ #std_format }

: [:octicons-tag-24: 2.2.0][conan std::format support] · :octicons-milestone-24: `True`/`False` (Default: automatically determined from settings)
Expand Down Expand Up @@ -338,7 +346,14 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"}

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_BUILD_IMPORT_STD`](#MP_UNITS_BUILD_IMPORT_STD){ #MP_UNITS_BUILD_IMPORT_STD }

: [:octicons-tag-24: 2.3.0][cmake import std support] · :octicons-milestone-24: `ON`/`OFF` (Default: `OFF`)

Enables `import std;` usage.

[cmake import std support]: https://github.com/mpusz/mp-units/releases/tag/v2.3.0

[`MP_UNITS_API_STD_FORMAT`](#MP_UNITS_API_STD_FORMAT){ #MP_UNITS_API_STD_FORMAT }

Expand Down
4 changes: 4 additions & 0 deletions example/avg_speed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
// !!! renders correctly in the documentation "Examples" section. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <exception>
#include <iostream>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/capacitor_time_curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
physical_quantities
*/

#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <iostream>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/clcpp_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

#include <mp-units/compat_macros.h>
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <iostream>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/conversion_factor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@

#include <mp-units/compat_macros.h>
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <concepts>
#include <iostream>
#include <string>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/currency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
// SOFTWARE.

#include <mp-units/compat_macros.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <concepts>
#include <iostream>
#include <map>
#include <string_view>
#include <utility>
#endif
#ifdef MP_UNITS_MODULES
import mp_units.core;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/foot_pound_second.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@

#include <mp-units/compat_macros.h>
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <iostream>
#include <string>
#include <string_view>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/glide_computer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include <mp-units/bits/hacks.h>
#include <mp-units/compat_macros.h>
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <array>
#include <chrono>
#include <concepts>
Expand All @@ -33,6 +36,7 @@
#include <ranges>
#include <string>
#include <utility>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/glide_computer_lib/glide_computer_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@

#include "glide_computer_lib.h"
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <functional>
#include <iostream>
#include <numeric>
#include <string_view>
#endif
#ifdef MP_UNITS_MODULES
import mp_units.core;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/glide_computer_lib/include/glide_computer_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include <mp-units/compat_macros.h>
//
#include "geographic.h"
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <algorithm>
#include <array>
#include <chrono>
Expand All @@ -35,6 +38,7 @@
#include <ranges>
#include <string> // IWYU pragma: keep
#include <vector>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/hello_units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@

#include <mp-units/compat_macros.h>
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <iomanip>
#include <iostream>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/include/geographic.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
#include "ranged_representation.h"
#include <mp-units/compat_macros.h>
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <compare>
#include <limits>
#include <numbers>
#include <ostream>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/include/ranged_representation.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@
#include <mp-units/bits/hacks.h>
#include <mp-units/compat_macros.h>
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <algorithm>
#include <concepts>
#include <type_traits>
#endif
#ifdef MP_UNITS_MODULES
import mp_units.core;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/include/validated_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@
#include <mp-units/compat_macros.h>
#include <mp-units/ext/contracts.h>
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <compare> // IWYU pragma: export
#include <ostream>
#include <utility>
#endif
#ifdef MP_UNITS_MODULES
import mp_units.core;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/kalman_filter/kalman.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@

#include <mp-units/compat_macros.h>
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <algorithm>
#include <locale>
#include <tuple>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/kalman_filter/kalman_filter-example_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@

#include "kalman.h"
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <array>
#include <iostream>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/kalman_filter/kalman_filter-example_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@

#include "kalman.h"
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <array>
#include <iostream>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/kalman_filter/kalman_filter-example_3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@

#include "kalman.h"
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <array>
#include <iostream>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/kalman_filter/kalman_filter-example_4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@

#include "kalman.h"
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <array>
#include <iostream>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/kalman_filter/kalman_filter-example_5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@

#include "kalman.h"
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <array>
#include <iostream>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/kalman_filter/kalman_filter-example_6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@

#include "kalman.h"
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <array>
#include <iostream>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
4 changes: 4 additions & 0 deletions example/kalman_filter/kalman_filter-example_7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@

#include "kalman.h"
#include <mp-units/ext/format.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
#include <array>
#include <iostream>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
Expand Down
Loading

0 comments on commit b870b85

Please sign in to comment.