Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mpusz/mp-units
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Feb 16, 2024
2 parents 0035015 + bde00c8 commit 8b9ca0e
Show file tree
Hide file tree
Showing 21 changed files with 254 additions and 188 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-conan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
# name: "MSVC 14.2",
# os: windows-2019,
# compiler: { type: VISUAL, version: 16, cc: "", cxx: "" },
# conan-config: "-c user.build:skip_la=True",
# conan-config: "-c user.mp-units.build:skip_la=True",
# }
# - {
# name: "MSVC 14.3",
Expand Down Expand Up @@ -212,7 +212,7 @@ jobs:
run: |
conan create . --user mpusz --channel ${CHANNEL} --lockfile-out=package.lock \
-b mp-units/* -b missing -c tools.cmake.cmaketoolchain:generator="Ninja Multi-Config" \
-c user.build:all=True -o cxx_modules=${{ matrix.config.cxx_modules }} -o use_fmtlib=${{ env.use_fmtlib }} ${{ matrix.config.conan-config }}
-c user.mp-units.build:all=True -o cxx_modules=${{ matrix.config.cxx_modules }} -o use_fmtlib=${{ env.use_fmtlib }} ${{ matrix.config.conan-config }}
- name: Obtain package reference
id: get-package-ref
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-test-package-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ jobs:
- name: Install Conan dependencies
shell: bash
run: |
conan install . -b missing -c tools.cmake.cmaketoolchain:generator="Ninja Multi-Config" -c user.build:all=False \
conan install . -b missing -c tools.cmake.cmaketoolchain:generator="Ninja Multi-Config" -c user.mp-units.build:all=False \
-o cxx_modules=${{ matrix.config.cxx_modules }} -o use_fmtlib=${{ env.use_fmtlib }}
mv CMakeUserPresets.json src
- name: Configure mp-units CMake
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
conan profile detect --force
conan remote add artifactory https://mpusz.jfrog.io/artifactory/api/conan/conan-oss
mkdir _lgtm_build_dir && cd _lgtm_build_dir
conan build .. -s compiler.cppstd=20 -c user.build:all=True -o use_fmtlib=True -b missing
conan build .. -s compiler.cppstd=20 -c user.mp-units.build:all=True -o use_fmtlib=True -b missing
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
Expand Down
32 changes: 16 additions & 16 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,47 +70,47 @@ tasks:
gp sync-await python-init
conan profile detect
conan config install $PWD/.gitpod/conan
conan install . -pr gcc12 -c user.build:all=True -o use_fmtlib=True -b missing
conan install . -pr gcc12 -c user.build:all=True -o use_fmtlib=True -b missing -s build_type=Debug
conan install . -pr gcc12 -o use_fmtlib=True -b missing
conan install . -pr gcc12 -o use_fmtlib=True -b missing -s build_type=Debug
gp sync-done conan-gcc12-20
conan install . -pr gcc13 -c user.build:all=True -b missing
conan install . -pr gcc13 -c user.build:all=True -b missing -s build_type=Debug
conan install . -pr gcc13 -b missing
conan install . -pr gcc13 -b missing -s build_type=Debug
gp sync-done conan-gcc13-20
conan install . -pr clang16 -c user.build:all=True -o use_fmtlib=True -b missing
conan install . -pr clang16 -c user.build:all=True -o use_fmtlib=True -b missing -s build_type=Debug
conan install . -pr clang16 -o use_fmtlib=True -b missing
conan install . -pr clang16 -o use_fmtlib=True -b missing -s build_type=Debug
gp sync-done conan-clang16-20
conan install . -pr clang17 -c user.build:all=True -o cxx_modules=True -b missing
conan install . -pr clang17 -c user.build:all=True -o cxx_modules=True -b missing -s build_type=Debug
conan install . -pr clang17 -o cxx_modules=True -b missing
conan install . -pr clang17 -o cxx_modules=True -b missing -s build_type=Debug
gp sync-done conan-clang17-20
conan remote login -p $ARTIFACTORY_TOKEN conan-gitpod-mp-units $ARTIFACTORY_USER
conan upload "*" -r conan-gitpod-mp-units -c
- name: gcc-12-20
init: |
gp sync-await conan-gcc12-20
source ${PYTHON_VENV}/bin/activate
conan build . -pr gcc12 -c user.build:all=True -o use_fmtlib=True
conan build . -pr gcc12 -c user.build:all=True -o use_fmtlib=True -s build_type=Debug
conan build . -pr gcc12 -o use_fmtlib=True
conan build . -pr gcc12 -o use_fmtlib=True -s build_type=Debug
echo "🛠️ gcc-12 pre-build done for C++20, header files, and libfmt! You can close this terminal and use 'Build' button in the VSCode status bar for incremental builds. 🛠️"
- name: gcc-13-20
init: |
gp sync-await conan-gcc13-20
source ${PYTHON_VENV}/bin/activate
conan build . -pr gcc13 -c user.build:all=True
conan build . -pr gcc13 -c user.build:all=True -s build_type=Debug
conan build . -pr gcc13
conan build . -pr gcc13 -s build_type=Debug
echo "🛠️ gcc-13 pre-build done for C++20 and header files! You can close this terminal and use 'Build' button in the VSCode status bar for incremental builds. 🛠️"
- name: clang-16-20
init: |
gp sync-await conan-clang16-20
source ${PYTHON_VENV}/bin/activate
conan build . -pr clang16 -c user.build:all=True -o use_fmtlib=True
conan build . -pr clang16 -c user.build:all=True -o use_fmtlib=True -s build_type=Debug
conan build . -pr clang16 -o use_fmtlib=True
conan build . -pr clang16 -o use_fmtlib=True -s build_type=Debug
echo "🛠️ clang-16 pre-build done for C++20, header files, and libfmt! You can close this terminal and use 'Build' button in the VSCode status bar for incremental builds. 🛠️"
- name: clang-17-20
init: |
gp sync-await conan-clang17-20
source ${PYTHON_VENV}/bin/activate
conan build . -pr clang17 -c user.build:all=True -o cxx_modules=True
conan build . -pr clang17 -c user.build:all=True -o cxx_modules=True -s build_type=Debug
conan build . -pr clang17 -o cxx_modules=True
conan build . -pr clang17 -o cxx_modules=True -s build_type=Debug
echo "🛠️ clang-17 pre-build done for C++20! You can close this terminal and use 'Build' button in the VSCode status bar for incremental builds. 🛠️"
- name: documentation
init: |
Expand Down
1 change: 1 addition & 0 deletions .gitpod/conan/global.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
tools.cmake.cmaketoolchain:generator=Ninja Multi-Config
tools.cmake.cmake_layout:build_folder_vars=["settings.compiler", "settings.compiler.version", "settings.compiler.cppstd"]
user.mp-units.build:all=True
10 changes: 9 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,21 @@ After the script is done please make sure to stage all those changes to git comm
The simplest way to verify if all targets build correctly and all unit tests pass is to run:

```bash
conan build . -pr <your_conan_profile> -s compiler.cppstd=23 -o cxx_modules=True -c user.build:all=True -b missing
conan build . -pr <your_conan_profile> -s compiler.cppstd=23 -o cxx_modules=True -c user.mp-units.build:all=True -b missing
```

as described in the
[Installation and Usage](https://mpusz.github.io/mp-units/latest/getting_started/installation_and_usage/#contributing-or-just-building-all-the-tests-and-examples)
chapter of our documentation.

_Hint:_ To ensure that that we always build all the targets and to save some typing of the Conan commands,
it is a good practice to set the following in the `~/.conan2/global.conf`:

```text
user.mp-units.build:all=True
```


### Backward Compatibility

Before submission, please remember to check if the code compiles fine on the supported compilers.
Expand Down
8 changes: 4 additions & 4 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,26 @@ def _minimum_compilers_version(self):
return {
"gcc": "12",
"clang": "16",
"apple-clang": "15"
"apple-clang": "15",
# , "msvc": "192"
}

@property
def _std_format_minimum_compilers_version(self):
return {
"gcc": "13",
"clang": "17"
"clang": "17",
# , "apple-clang": "15"
# , "msvc": "192"
}

@property
def _build_all(self):
return bool(self.conf.get("user.build:all", default=False))
return bool(self.conf.get("user.mp-units.build:all", default=False))

@property
def _skip_la(self):
return bool(self.conf.get("user.build:skip_la", default=False))
return bool(self.conf.get("user.mp-units.build:skip_la", default=False))

def set_version(self):
content = load(self, os.path.join(self.recipe_folder, "src/CMakeLists.txt"))
Expand Down
20 changes: 10 additions & 10 deletions docs/getting_started/installation_and_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,29 +194,29 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"}

### Conan configuration properties

[`user.build:all`](#user-build-all){ #user-build-all }
[`user.mp-units.build:all`](#user.mp-units.build-all){ #user.mp-units.build-all }

: [:octicons-tag-24: 0.8.0][build all support] · :octicons-milestone-24: `True`/`False` (Default: `False`)
: [:octicons-tag-24: 2.2.0][build all support] · :octicons-milestone-24: `True`/`False` (Default: `False`)

Enables compilation of all the source code, including tests and examples. To support this, it requires some additional Conan build dependencies described in
[Repository Structure and Dependencies](#repository-structure-and-dependencies).
It also runs unit tests during Conan build (unless
[`tools.build:skip_test`](https://docs.conan.io/2/reference/commands/config.html?highlight=tools.build:skip_test#conan-config-list)
configuration property is set to `True`).

[build all support]: https://github.com/mpusz/mp-units/releases/tag/v0.8.0
[build all support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0


[`user.build:skip_la`](#user-skip-la){ #user-skip-la }
[`user.mp-units.build:skip_la`](#user-skip-la){ #user-skip-la }

: [:octicons-tag-24: 0.8.0][skip la support] · :octicons-milestone-24: `True`/`False` (Default: `False`)
: [:octicons-tag-24: 2.2.0][skip la support] · :octicons-milestone-24: `True`/`False` (Default: `False`)

If `user.build:all` is enabled, among others, Conan installs the external
If `user.mp-units.build:all` is enabled, among others, Conan installs the external
[wg21-linear_algebra](https://conan.io/center/recipes/wg21-linear_algebra)
dependency and enables the compilation of linear algebra-based tests and usage examples.
Such behavior can be disabled with this option.

[skip la support]: https://github.com/mpusz/mp-units/releases/tag/v0.8.0
[skip la support]: https://github.com/mpusz/mp-units/releases/tag/v2.2.0


### CMake options
Expand Down Expand Up @@ -453,11 +453,11 @@ In case you would like to build all the **mp-units** source code (with unit test
you should:
1. Use the _CMakeLists.txt_ from the top-level directory.
2. Run Conan with [`user.build:all`](#user-build-all) = `True`.
2. Run Conan with [`user.mp-units.build:all`](#user.mp-units.build-all) = `True`.
```shell
git clone https://github.com/mpusz/mp-units.git && cd units
conan build . -pr <your_conan_profile> -s compiler.cppstd=23 -o cxx_modules=True -c user.build:all=True -b missing
conan build . -pr <your_conan_profile> -s compiler.cppstd=23 -o cxx_modules=True -c user.mp-units.build:all=True -b missing
```
The above will download and install all of the dependencies needed for the development of the library,
Expand Down Expand Up @@ -504,7 +504,7 @@ After that, you can either:
To test CMake installation and Conan packaging or create a Conan package run:
```shell
conan create . --user <username> --channel <channel> -pr <your_conan_profile> -s compiler.cppstd=20 -o cxx_modules=True -c user.build:all=True -b missing
conan create . --user <username> --channel <channel> -pr <your_conan_profile> -s compiler.cppstd=20 -o cxx_modules=True -c user.mp-units.build:all=True -b missing
```
The above will create a Conan package and run tests provided in _./test_package_ directory.
Expand Down
7 changes: 6 additions & 1 deletion docs/users_guide/framework_basics/systems_of_quantities.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,9 @@ static_assert(same_type<kind_of<isq::length> / isq::time, isq::length / isq::tim
Only a root quantity from the hierarchy tree or the one marked with `is_kind` specifier
in the `quantity_spec` definition can be put as a template parameter to the `kind_of`
specifier. For example, `kind_of<isq::width>` will fail to compile.
specifier. For example, `kind_of<isq::width>` will fail to compile. However, we can call
`get_kind(q)` to obtain a kind of any quantity:
```cpp
static_assert(get_kind(isq::width) == kind_of<isq::length>);
```
30 changes: 15 additions & 15 deletions example/total_energy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ QuantityOf<isq::mechanical_energy> auto total_energy(QuantityOf<isq::momentum> a
void si_example()
{
using namespace mp_units::si::unit_symbols;
constexpr auto GeV = si::giga<si::electronvolt>;
constexpr QuantityOf<isq::speed> auto c = 1. * si::si2019::speed_of_light_in_vacuum;
auto c2 = pow<2>(c);
constexpr Unit auto GeV = si::giga<si::electronvolt>;
constexpr quantity c = 1. * si::si2019::speed_of_light_in_vacuum;
quantity c2 = pow<2>(c);

const auto p1 = isq::momentum(4. * GeV / c);
const quantity p1 = isq::momentum(4. * GeV / c);
const QuantityOf<isq::mass> auto m1 = 3. * GeV / c2;
const auto E = total_energy(p1, m1, c);
const quantity E = total_energy(p1, m1, c);

std::cout << "\n*** SI units (c = " << c << " = " << c.in(si::metre / s) << ") ***\n";

Expand All @@ -65,18 +65,18 @@ void si_example()
<< "m = " << m1 << "\n"
<< "E = " << E << "\n";

const auto p2 = p1.in(GeV / (m / s));
const auto m2 = m1.in(GeV / pow<2>(m / s));
const auto E2 = total_energy(p2, m2, c).in(GeV);
const quantity p2 = p1.in(GeV / (m / s));
const quantity m2 = m1.in(GeV / pow<2>(m / s));
const quantity E2 = total_energy(p2, m2, c).in(GeV);

std::cout << "\n[in `GeV`]\n"
<< "p = " << p2 << "\n"
<< "m = " << m2 << "\n"
<< "E = " << E2 << "\n";

const auto p3 = p1.in(kg * m / s);
const auto m3 = m1.in(kg);
const auto E3 = total_energy(p3, m3, c).in(J);
const quantity p3 = p1.in(kg * m / s);
const quantity m3 = m1.in(kg);
const quantity E3 = total_energy(p3, m3, c).in(J);

std::cout << "\n[in SI base units]\n"
<< "p = " << p3 << "\n"
Expand All @@ -92,10 +92,10 @@ void natural_example()
using namespace mp_units::natural;
using namespace mp_units::natural::unit_symbols;

constexpr auto c = 1. * speed_of_light;
const auto p = 4. * momentum[GeV];
const auto m = 3. * mass[GeV];
const auto E = total_energy(p, m, c);
constexpr quantity c = 1. * speed_of_light;
const quantity p = 4. * momentum[GeV];
const quantity m = 3. * mass[GeV];
const quantity E = total_energy(p, m, c);

std::cout << "\n*** Natural units (c = " << c << ") ***\n"
<< "p = " << p << "\n"
Expand Down
2 changes: 1 addition & 1 deletion src/core/include/mp-units/bits/external/hacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
// TODO revise the below when clang-18 is released
#if MP_UNITS_COMP_CLANG >= 18 && !defined __cpp_explicit_this_parameter

#define __cpp_explicit_this_parameter
#define __cpp_explicit_this_parameter 202110L

#endif

Expand Down
4 changes: 2 additions & 2 deletions src/core/include/mp-units/bits/quantity_spec_concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ concept QuantitySpec =
detail::NamedQuantitySpec<T> || detail::IntermediateDerivedQuantitySpec<T> || detail::QuantityKindSpec<T>;

template<QuantitySpec Q>
[[nodiscard]] consteval QuantitySpec auto get_kind(Q q);
[[nodiscard]] consteval detail::QuantityKindSpec auto get_kind(Q q);

namespace detail {

template<auto To, auto From>
concept NestedQuantityKindSpecOf =
QuantitySpec<std::remove_const_t<decltype(From)>> && QuantitySpec<std::remove_const_t<decltype(To)>> &&
get_kind(From) != get_kind(To) &&
std::derived_from<std::remove_cvref_t<decltype(To)>, std::remove_cvref_t<decltype(get_kind(From))>>;
std::derived_from<std::remove_cvref_t<decltype(To)>, std::remove_cvref_t<decltype(get_kind(From)._quantity_spec_)>>;

}

Expand Down
Loading

0 comments on commit 8b9ca0e

Please sign in to comment.