Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add C++ modules support #350

Merged
merged 33 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7cb2099
feat: add module `mp_units`
JohelEGP Jan 6, 2024
52b0c03
docs: document `MP_UNITS_BUILD_CXX_MODULES`
JohelEGP Jan 6, 2024
ceb1522
docs: update example source lines
JohelEGP Jan 6, 2024
7aa0690
refactor: move `compare.h` and `random.h` to `mp_units.core`
JohelEGP Jan 6, 2024
b5a7b81
style: fix grammar of comment
JohelEGP Jan 6, 2024
47a5226
style: formatting and whitespaces fixed to make pre-commit happy
mpusz Jan 6, 2024
4069481
refactor: `math_core.h` moved back to the `utility` directory
mpusz Jan 6, 2024
c0f264c
fix: `mp-units-core-module` now links with `mp-units::utility`
mpusz Jan 6, 2024
50c8f0a
build: `projectPrefix` applied to preprocessor define
mpusz Jan 6, 2024
ea8450d
build: `_LIBCPP_NO_ABI_TAG` define set for clang-17 modules build
mpusz Jan 6, 2024
b582e20
fix: clang-17 with modules build on ignores disabling conversion warn…
mpusz Jan 6, 2024
0eaf6e2
refactor: modules support redesigned
mpusz Jan 6, 2024
271a811
fix: glide-computer compilation with headers fixed
mpusz Jan 6, 2024
3095b28
build: triggering C++ modules build added to Conan
mpusz Jan 6, 2024
4c75d46
ci: building C++ modules enabled for clang-17 and apple-clang-15
mpusz Jan 6, 2024
4223f81
style: CMake file formatting fixed
mpusz Jan 6, 2024
614d82d
ci: building C++ modules disabled for apple-clang-15
mpusz Jan 6, 2024
fb8552b
refactor: `core-fmt` and `core-ostream` modules merged with `core`
mpusz Jan 6, 2024
a7cb512
fix: modules build fixed
mpusz Jan 6, 2024
44c557f
refactor: `add_units_module` renamed to `add_mp_units_module` and `ta…
mpusz Jan 6, 2024
4960011
fix: `cxx_std_20` set for `mp-units::core`
mpusz Jan 6, 2024
e23be9a
fix: `MP_UNITS_USE_LIBFMT` was lost during refactoring
mpusz Jan 6, 2024
edb7de4
docs: documentation updated for C++ modules
mpusz Jan 6, 2024
aaa60e0
docs: example apllications documentation updated for modules
mpusz Jan 6, 2024
e8e3226
docs: "Installation and Usage" refactored
mpusz Jan 6, 2024
98cc53e
docs: "Wide Compatibility" chapter added
mpusz Jan 6, 2024
5847942
style: cmake-format.yaml updated
mpusz Jan 6, 2024
9611a64
docs: a note about C++ modules availability added to "Installation an…
mpusz Jan 6, 2024
39a66d2
docs: "C++ modules" tabs added to all the code examples
mpusz Jan 6, 2024
047b8a1
build: `add_mp_units_module` now use `HEADER_SET`
mpusz Jan 6, 2024
78dedb1
style: whitespaces fixed in "Wide Compatibility" to make pre-commit h…
mpusz Jan 6, 2024
53e2558
fix: `target_sources` with `FILE_SET HEADERS` called only when header…
mpusz Jan 6, 2024
6914142
fix: `compat_macros` included to fix the compilation after rebase
mpusz Jan 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions .cmake-format.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
parse:
additional_commands:
add_documentation:
add_mp_units_module:
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
nargs: 2
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
2 changes: 1 addition & 1 deletion .github/workflows/ci-conan.yml
JohelEGP marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
cxx: "clang++-17",
},
lib: "libc++",
conan-config: "",
conan-config: "-o cxx_modules=True",
}
- {
name: "Apple Clang 15",
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 @@ -98,7 +98,7 @@ jobs:
cxx: "clang++-17",
},
lib: "libc++",
conan-config: "",
conan-config: "-o cxx_modules=True",
}
- {
name: "Apple Clang 15",
Expand Down
2 changes: 1 addition & 1 deletion cmake/TestPublicHeaders.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function(get_target_sources target paths_out)
list(APPEND targets ${target})

foreach(t ${targets})
get_target_property(sources ${t} SOURCES)
get_target_property(sources ${t} HEADER_SET)
if(sources)
get_target_property(source_dir ${t} SOURCE_DIR)
foreach(f ${sources})
Expand Down
12 changes: 11 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class MPUnitsConan(ConanFile):
license = "MIT"
url = "https://github.com/mpusz/mp-units"
settings = "os", "arch", "compiler", "build_type"
options = {
"cxx_modules": [True, False],
}
default_options = {
"cxx_modules": False,
}

exports = ["LICENSE.md"]
exports_sources = [
"docs/*",
Expand Down Expand Up @@ -104,7 +111,7 @@ def set_version(self):
def requirements(self):
self.requires("gsl-lite/0.40.0")
if self._use_libfmt:
self.requires("fmt/10.1.0")
self.requires("fmt/10.1.1")

def build_requirements(self):
if self._build_all:
Expand Down Expand Up @@ -133,6 +140,9 @@ def layout(self):

def generate(self):
tc = CMakeToolchain(self)
if self.options.cxx_modules:
tc.variables["CMAKE_CXX_SCAN_FOR_MODULES"] = True
tc.variables["MP_UNITS_BUILD_CXX_MODULES"] = True
tc.variables["MP_UNITS_BUILD_LA"] = self._build_all and not self._skip_la
tc.variables["MP_UNITS_USE_LIBFMT"] = self._use_libfmt
tc.generate()
Expand Down
103 changes: 82 additions & 21 deletions docs/getting_started/installation_and_usage.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Installation And Usage

This chapter provides all the necessary information to obtain and build the code using **mp-units**.
It also describes how to build or distribute the library and generate its documentation.

## C++ compiler support { #cpp-compiler-support }

!!! info

**mp-units** library tries to provide the best user experience possible with the C++ language.
Expand All @@ -12,14 +17,42 @@
a [preprocessor macro](../users_guide/framework_basics/systems_of_quantities.md#defining-quantities)
providing a backward-compatible way to use it.

As of today, the library compiles fine on the following compilers (or newer):
The below table provides the minimum compiler version required to compile the code using the
specific feature:

| Feature | gcc | clang | apple-clang | MSVC |
|----------------------|:----:|:-----:|:-----------:|:----:|
| **Minimum support** | 12 | 16 | 15 | None |
| **`std::format`** | None | None | None | None |
| **C++ modules** | None | 17 | None | None |
| **C++23 extensions** | None | None | None | None |

More requirements for C++ modules support can be found in the
[CMake's documentation](https://cmake.org/cmake/help/latest/manual/cmake-cxxmodules.7.html).


## Modules

The **mp-units** library provides the following C++ modules.

```mermaid
flowchart TD
mp_units --- mp_units.systems --- mp_units.core
```

| C++ Module | CMake Target | Contents |
|--------------------|----------------------|-----------------------------------------|
| `mp_units.core` | `mp-units::core` | Core library framework |
| `mp_units.systems` | `mp-units::systems` | All the systems of quantities and units |
| `mp_units` | `mp-units::mp-units` | Core + Systems |

!!! note

- gcc-12
- clang-16
- apple-clang-15
C++ modules are provided within the package only when [`cxx_modules`](#cxx_modules) Conan
option is set to `True`.


## Repository Structure and Dependencies
## Repository structure and dependencies

This repository contains three independent CMake-based projects:

Expand Down Expand Up @@ -60,16 +93,18 @@ This repository contains three independent CMake-based projects:

This is why our projects have two entry points:

- _./CMakeLists.txt_ is to be used by projects developers to build **ALL** the project code with really
restrictive compilation flags,
- _./src/CMakeLists.txt_ contains only a pure library definition and should be used by the customers
that prefer to use CMake's `add_subdirectory()` to handle the dependencies.
- _./CMakeLists.txt_ is **to be used by projects developers** to build **ALL** the project code
with really restrictive compilation flags,
- _./src/CMakeLists.txt_ contains only a pure library definition and **should be used by the
customers** that prefer to use CMake's
[`add_subdirectory()`](https://cmake.org/cmake/help/latest/command/add_subdirectory.html) to
handle the dependencies.

To learn more about the rationale, please check our
[FAQ](faq.md#why-dont-we-have-cmake-options-to-disable-building-of-tests-and-examples).


## Obtaining Dependencies
## Obtaining dependencies

This library assumes that most of the dependencies will be provided by the
[Conan Package Manager](https://conan.io/). If you want to obtain required
Expand All @@ -78,7 +113,7 @@ The rest of the dependencies responsible for documentation generation are provid
`python3-pip`.


### Conan Quick Intro
### Conan quick intro

In case you are not familiar with Conan, to install it (or upgrade) just do:

Expand Down Expand Up @@ -136,17 +171,28 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"}
(e.g. `conan-gcc-13-23` and `conan-gcc-13-23-release`)


## Build Options
## Build options

### Conan Configuration Properties
### Conan options

[cxx_modules](#cxx_modules){ #cxx_modules }

: [:octicons-tag-24: 2.2.0][cxx modules support] · :octicons-milestone-24: `True`/`False` (Default: `False`)

Configures CMake to add C++ modules to the list of default targets.

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

### Conan configuration properties

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

: [:octicons-tag-24: 0.8.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`
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
Expand All @@ -164,7 +210,16 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"}
[skip la support]: https://github.com/mpusz/mp-units/releases/tag/v0.8.0


### CMake Options
### CMake options

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

: [:octicons-tag-24: 2.2.0][build_cxx_modules support] · :octicons-milestone-24: `ON`/`OFF` (Default: `OFF`)

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_AS_SYSTEM_HEADERS`](#MP_UNITS_AS_SYSTEM_HEADERS){ #MP_UNITS_AS_SYSTEM_HEADERS }

Expand Down Expand Up @@ -199,12 +254,12 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"}
: [:octicons-tag-24: 2.0.0][use libfmt support] · :octicons-milestone-24: `ON`/`OFF` (Default: `ON`)

Forces usage of [{fmt}](https://github.com/fmtlib/fmt) library instead of the C++20 Standard
Library feature.
Library features.

[use libfmt support]: https://github.com/mpusz/mp-units/releases/tag/v2.0.0


## CMake with Presets Support
## CMake with presets support

It is recommended to use at least CMake 3.23 to build this project as this version introduced support
for CMake Presets schema version 4, used now by Conan to generate presets files. All build instructions
Expand All @@ -224,7 +279,7 @@ cmake --build . --config Release
which will force Conan to use an older version of the CMake Presets schema.


## Installation and Reuse
## Installation and reuse

There are many different ways of installing/reusing **mp-units** in your project. Below we mention
only a few of many options possible.
Expand Down Expand Up @@ -284,6 +339,9 @@ The following steps may be performed to obtain an official library release:
[requires]
mp-units/2.1.0

[options]
mp-units:cxx_modules=True

[layout]
cmake_layout

Expand Down Expand Up @@ -341,6 +399,9 @@ with the following differences:
[requires]
mp-units/2.2.0@mpusz/testing

[options]
mp-units:cxx_modules=True

[layout]
cmake_layout

Expand Down Expand Up @@ -387,7 +448,7 @@ you should:

```shell
git clone https://github.com/mpusz/mp-units.git && cd units
conan build . -pr <your_conan_profile> -s compiler.cppstd=20 -c user.build:all=True -b missing
conan build . -pr <your_conan_profile> -s compiler.cppstd=23 -o cxx_modules=True -c user.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 @@ -433,13 +494,13 @@ 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 -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.build:all=True -b missing
```

The above will create a Conan package and run tests provided in _./test_package_ directory.


## Uploading **mp-units** Package to the Conan Server
## Uploading **mp-units** package to the Conan server

```shell
conan upload -r <remote-name> --all mp-units/2.1.0@<user>/<channel>
Expand Down
Loading