2020-03-09 18:55:41 +01:00
|
|
|
Usage
|
|
|
|
=====
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
2021-03-15 22:08:12 +01:00
|
|
|
This library targets C++23/26 and extensively uses C++20 features. This is why it requires the latest C++
|
|
|
|
compilers. The following compilers (or newer) are supported:
|
|
|
|
|
|
|
|
- gcc-10
|
|
|
|
- clang-12
|
|
|
|
- Visual Studio 16.9
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-03-26 17:09:26 +01:00
|
|
|
Repository Structure and Dependencies
|
2020-03-09 18:55:41 +01:00
|
|
|
-------------------------------------
|
|
|
|
|
|
|
|
This repository contains three independent CMake-based projects:
|
|
|
|
|
|
|
|
- *./src*
|
|
|
|
|
|
|
|
- header-only project containing whole **mp-units** library
|
2020-09-06 23:53:42 +02:00
|
|
|
- when this library will become part of the C++ standard it will have no external dependencies
|
|
|
|
but until then it depends on:
|
|
|
|
|
|
|
|
- `{fmt} <https://github.com/fmtlib/fmt>`_ to provide text formatting of quantities.
|
2021-01-04 18:36:26 -04:00
|
|
|
- `gsl-lite <https://github.com/gsl-lite/gsl-lite>`_ to verify runtime contracts with the ``gsl_Expects`` macro.
|
2021-03-16 10:27:59 +01:00
|
|
|
- [only for clang-12 with libc++] `range-v3 <https://github.com/ericniebler/range-v3>`_ to provide needed C++20 concepts and utilities.
|
2020-03-09 18:55:41 +01:00
|
|
|
|
|
|
|
- *.*
|
|
|
|
|
|
|
|
- project used as an entry point for library development and CI/CD
|
|
|
|
- it wraps *./src* project together with usage examples and tests
|
|
|
|
- additionally to the dependencies of *./src* project, it uses:
|
|
|
|
|
|
|
|
- `Catch2 <https://github.com/catchorg/Catch2>`_ library as a unit tests framework.
|
|
|
|
- `linear algebra <https://github.com/BobSteagall/wg21/tree/master/linear_algebra/code>`_
|
|
|
|
library based on proposal `P1385 <https://wg21.link/P1385>`_ used in some examples
|
|
|
|
and tests.
|
|
|
|
- `Doxygen <http://www.doxygen.nl>`_ to extract C++ entities information from the source
|
|
|
|
code.
|
|
|
|
- `Sphinx <https://www.sphinx-doc.org>`_ to build the documentation.
|
|
|
|
- `Sphinx recommonmark <https://recommonmark.readthedocs.io>`_.
|
|
|
|
- `Breathe <https://breathe.readthedocs.io/>`_ as a bridge between the Sphinx and Doxygen
|
|
|
|
documentation systems.
|
|
|
|
|
|
|
|
- *./test_package*
|
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
- library installation and Conan package verification.
|
2020-03-09 18:55:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
Obtaining Dependencies
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
This library assumes that most of the dependencies will be provided by the
|
2020-09-06 23:53:42 +02:00
|
|
|
`Conan Package Manager <https://conan.io/>`_. In case you would like to obtain required
|
|
|
|
dependencies by other means some modifications to library's CMake files might be needed.
|
|
|
|
The rest of the dependencies responsible for documentation generation are provided by
|
|
|
|
:command:`python3-pip`.
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-03-13 19:14:01 +01:00
|
|
|
.. seealso::
|
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
A full list of dependencies can be found in `Repository Structure and Dependencies`_.
|
2020-03-13 19:14:01 +01:00
|
|
|
|
2020-03-26 17:09:26 +01:00
|
|
|
Conan Quick Intro
|
2020-03-09 18:55:41 +01:00
|
|
|
^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
In case you are not familiar with Conan, to install it (or upgrade) just do:
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
|
|
pip3 install -U conan
|
|
|
|
|
|
|
|
After that you might need to add a custom profile file for your development environment
|
2020-09-06 23:53:42 +02:00
|
|
|
in *~/.conan/profiles* directory. An example profile can look as follows:
|
2020-03-09 18:55:41 +01:00
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
:emphasize-lines: 8
|
|
|
|
|
|
|
|
[settings]
|
|
|
|
os=Linux
|
|
|
|
os_build=Linux
|
|
|
|
arch=x86_64
|
|
|
|
arch_build=x86_64
|
|
|
|
compiler=gcc
|
2020-09-06 10:23:31 +02:00
|
|
|
compiler.version=10
|
2020-03-09 18:55:41 +01:00
|
|
|
compiler.cppstd=20
|
|
|
|
compiler.libcxx=libstdc++11
|
|
|
|
build_type=Release
|
|
|
|
|
|
|
|
[options]
|
|
|
|
[build_requires]
|
|
|
|
|
|
|
|
[env]
|
2020-09-06 10:23:31 +02:00
|
|
|
CC=/usr/bin/gcc-10
|
|
|
|
CXX=/usr/bin/g++-10
|
2020-09-06 23:53:42 +02:00
|
|
|
CONAN_CMAKE_GENERATOR=Ninja
|
2020-03-09 18:55:41 +01:00
|
|
|
|
|
|
|
.. tip::
|
|
|
|
|
|
|
|
Please note that **mp-units** library requires C++20 to be set either in a Conan profile or forced
|
|
|
|
via Conan command line. If you do the former, you will not need to provide ``-s compiler.cppstd=20``
|
2020-09-06 23:53:42 +02:00
|
|
|
every time your run a Conan command line (as it is suggested below).
|
2020-03-09 18:55:41 +01:00
|
|
|
|
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
Build Options
|
|
|
|
-------------
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
Environment Variables
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
CONAN_RUN_TESTS
|
|
|
|
+++++++++++++++
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
**Values**: ``True``/``False``
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
**Defaulted to**: ``False``
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
Enables compilation of all the source code (tests and examples) and building the documentation.
|
|
|
|
To support this it requires some additional Conan build dependencies described in
|
|
|
|
`Repository Structure and Dependencies`_.
|
|
|
|
It also runs unit tests during Conan build.
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-09 20:56:08 +02:00
|
|
|
|
|
|
|
Conan Options
|
|
|
|
^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
downcast_mode
|
|
|
|
+++++++++++++
|
|
|
|
|
|
|
|
**Values**: ``off``/``on``/``auto``
|
|
|
|
|
|
|
|
**Defaulted to**: ``on``
|
|
|
|
|
2021-02-16 16:19:57 +01:00
|
|
|
Specifies how :ref:`design/downcasting:The Downcasting Facility` works:
|
2020-09-09 20:56:08 +02:00
|
|
|
|
|
|
|
- ``off`` - no downcasting at all
|
|
|
|
- ``on`` - downcasting always forced -> compile-time errors in case of duplicated definitions
|
|
|
|
- ``automatic`` - downcasting automatically enabled if no collisions are present
|
|
|
|
|
2020-12-21 23:46:04 +01:00
|
|
|
build_docs
|
|
|
|
++++++++++
|
|
|
|
|
|
|
|
**Values**: ``True``/``False``
|
|
|
|
|
|
|
|
**Defaulted to**: ``True``
|
|
|
|
|
|
|
|
If enabled, Conan installs the documentation generation dependencies (i.e. doxygen).
|
|
|
|
Additionally, enables project documentation generation when the project is being built by Conan.
|
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
CMake Options
|
|
|
|
^^^^^^^^^^^^^
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-13 18:45:46 +02:00
|
|
|
UNITS_DOWNCAST_MODE
|
|
|
|
+++++++++++++++++++
|
2020-09-09 20:56:08 +02:00
|
|
|
|
|
|
|
**Values**: ``OFF``/``ON``/``AUTO``
|
|
|
|
|
|
|
|
**Defaulted to**: ``ON``
|
|
|
|
|
2020-09-13 18:45:46 +02:00
|
|
|
Equivalent to `downcast_mode`_.
|
2020-09-09 20:56:08 +02:00
|
|
|
|
|
|
|
|
2020-12-21 23:46:04 +01:00
|
|
|
UNITS_BUILD_DOCS
|
|
|
|
++++++++++++++++
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
**Values**: ``ON``/``OFF``
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
**Defaulted to**: ``ON``
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
Enables project documentation generation.
|
2020-03-09 18:55:41 +01:00
|
|
|
|
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
Installation and Reuse
|
|
|
|
----------------------
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
There are many different ways of installing/reusing **mp-units** in your project. Below we mention
|
|
|
|
only a few of many options possible.
|
2020-03-09 18:55:41 +01:00
|
|
|
|
|
|
|
Copy
|
|
|
|
^^^^
|
|
|
|
|
|
|
|
As **mp-units** is a C++ header-only library you can simply copy *src/include* directory to
|
|
|
|
your source tree and use it as regular header files.
|
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
.. important::
|
|
|
|
|
|
|
|
In such a case you are on your own to make sure all the dependencies are installed and their header
|
|
|
|
files can be located during the build. Please also note that some compiler-specific flags are needed
|
|
|
|
to make the code compile without issues.
|
2020-03-09 18:55:41 +01:00
|
|
|
|
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
Copy + CMake
|
|
|
|
^^^^^^^^^^^^
|
|
|
|
|
|
|
|
In case you copy the whole **mp-units** repository to your project's file tree you can reuse CMake targets
|
|
|
|
defined by the library. To do so you should use *CMakeLists.txt* file from the *./src* directory:
|
|
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
add_subdirectory(<path_to_units_folder>/src)
|
2020-09-08 20:05:30 +02:00
|
|
|
# ...
|
2021-03-18 20:50:38 +01:00
|
|
|
target_link_libraries(<your_target> <PUBLIC|PRIVATE|INTERFACE> mp-units::mp-units)
|
2020-09-06 23:53:42 +02:00
|
|
|
|
|
|
|
.. important::
|
|
|
|
|
2020-12-21 23:46:04 +01:00
|
|
|
You are still on your own to make sure all the dependencies are installed and their header and CMake
|
|
|
|
configuration files can be located during the build.
|
2020-09-06 23:53:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
Conan + CMake (release)
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
.. tip::
|
|
|
|
|
|
|
|
If you are new to Conan package manager it is highly recommended to read `Obtaining Dependencies`_
|
|
|
|
and refer to `Getting Started <https://docs.conan.io/en/latest/getting_started.html>`_ and
|
|
|
|
`Using packages <https://docs.conan.io/en/latest/using_packages.html>`_ chapters
|
|
|
|
of the official Conan documentation for more information.
|
|
|
|
|
|
|
|
**mp-units** releases are hosted on `Conan-Center <https://conan.io/center/>`_. To obtain official
|
|
|
|
library release the following steps may be performed:
|
|
|
|
|
|
|
|
1. Create Conan configuration file (either *conanfile.txt* or *conanfile.py*) in your
|
|
|
|
project's top-level directory and add **mp-units** as a dependency of your project.
|
|
|
|
For example the simplest file may look as follows:
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
:caption: conanfile.txt
|
|
|
|
|
|
|
|
[requires]
|
|
|
|
mp-units/0.6.0
|
|
|
|
|
|
|
|
[generators]
|
2021-03-18 08:17:45 +01:00
|
|
|
CMakeToolchain
|
|
|
|
CMakeDeps
|
2020-09-06 23:53:42 +02:00
|
|
|
|
|
|
|
2. Import **mp-units** and its dependencies definitions to your project's build procedure
|
|
|
|
with ``find_package``:
|
|
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
2021-03-18 08:17:45 +01:00
|
|
|
find_package(mp-units CONFIG REQUIRED)
|
2020-09-06 23:53:42 +02:00
|
|
|
|
|
|
|
3. Link your CMake targets with **mp-units**:
|
|
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
2021-03-18 20:50:38 +01:00
|
|
|
target_link_libraries(<your_target> <PUBLIC|PRIVATE|INTERFACE> mp-units::mp-units)
|
|
|
|
target_compile_features(<your_target> <PUBLIC|PRIVATE|INTERFACE> cxx_std_20)
|
2020-09-06 23:53:42 +02:00
|
|
|
|
|
|
|
.. important::
|
|
|
|
|
|
|
|
Unfortunately, packages distributed via Conan-Center cannot force the minimum version
|
|
|
|
of the C++ language used for your build process. This is why it is important to specify
|
|
|
|
it in `Conan profile file <Conan Quick Intro>`_ and with ``target_compile_features`` command
|
2021-03-18 08:17:45 +01:00
|
|
|
for each CMake target directly linking with `mp-units::mp-units` in your project.
|
2020-09-06 23:53:42 +02:00
|
|
|
|
|
|
|
4. Download, build, and install Conan dependencies before running CMake configuration step:
|
2020-03-09 18:55:41 +01:00
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
mkdir build && cd build
|
|
|
|
conan install .. -pr <your_conan_profile> -s compiler.cppstd=20 -b=missing
|
2021-03-18 08:17:45 +01:00
|
|
|
cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake
|
2020-09-06 23:53:42 +02:00
|
|
|
cmake --build .
|
|
|
|
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
Conan + CMake (Live At Head)
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
This chapter describes the procedure to Live At Head which means to use the latest version
|
|
|
|
of **mp-units** all the time.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
Please note that even though the Conan packages that you will be using are generated **ONLY**
|
|
|
|
for builds that are considered stable (passed our CI tests) some minor regressions may happen
|
|
|
|
(our CI and C++20 build environment is not perfect yet). Also, please expect that the library
|
|
|
|
interface might, and probably will, change from time to time. Even though we do our best, such
|
|
|
|
changes might not be reflected in the project's documentation right away.
|
|
|
|
|
|
|
|
The procedure is similar to the one described in `Conan + CMake (release)`_ with the following
|
|
|
|
differences:
|
|
|
|
|
|
|
|
1. Before starting the previous procedure add **mp-units** remote to your Conan configuration:
|
2020-03-09 18:55:41 +01:00
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
conan remote add conan-mpusz https://api.bintray.com/conan/mpusz/conan-mpusz
|
|
|
|
|
|
|
|
2. In your Conan configuration file provide package identifier of the ``mpusz/testing`` stream:
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
.. code-block:: ini
|
|
|
|
:caption: conanfile.txt
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
[requires]
|
|
|
|
mp-units/0.7.0@mpusz/testing
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
[generators]
|
2021-03-17 15:57:11 +01:00
|
|
|
CMakeToolchain
|
|
|
|
CMakeDeps
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
.. tip::
|
|
|
|
|
|
|
|
The identifiers of the latest packages can always be found in
|
|
|
|
`the project's README file <https://github.com/mpusz/units/blob/master/README.md>`_ or on
|
|
|
|
`the project's Bintray <https://bintray.com/mpusz/conan-mpusz/mp-units%3Ampusz>`_.
|
|
|
|
|
2020-09-07 13:17:06 +02:00
|
|
|
3. Force Conan to check for updated recipes ``-u`` and to build outdated packages ``-b outdated``:
|
2020-09-06 23:53:42 +02:00
|
|
|
|
|
|
|
.. code-block:: shell
|
2020-03-09 18:55:41 +01:00
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
mkdir build && cd build
|
|
|
|
conan install .. -pr <your_conan_profile> -s compiler.cppstd=20 -b=outdated -u
|
2021-03-14 16:50:24 +01:00
|
|
|
cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake
|
|
|
|
cmake --build .
|
2020-03-09 18:55:41 +01:00
|
|
|
|
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
Contributing (or just building all the tests, examples, and documentation)
|
|
|
|
--------------------------------------------------------------------------
|
2020-03-09 18:55:41 +01:00
|
|
|
|
|
|
|
In case you would like to build all the source code (with unit tests and examples) and documentation
|
2020-09-06 23:53:42 +02:00
|
|
|
in **mp-units** repository, you should:
|
|
|
|
|
|
|
|
1. Add remotes of additional Conan dependencies.
|
|
|
|
2. Use the *CMakeLists.txt* from the top-level directory.
|
|
|
|
3. Obtain Python dependencies.
|
2020-09-07 13:17:06 +02:00
|
|
|
4. Run Conan with `CONAN_RUN_TESTS`_ = ``True``.
|
2020-03-09 18:55:41 +01:00
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
conan remote add linear-algebra https://api.bintray.com/conan/twonington/public-conan
|
|
|
|
git clone https://github.com/mpusz/units.git && cd units
|
2020-03-09 18:55:41 +01:00
|
|
|
pip3 install -r docs/requirements.txt
|
|
|
|
mkdir build && cd build
|
2020-09-06 23:53:42 +02:00
|
|
|
conan install .. -pr <your_conan_profile> -s compiler.cppstd=20 -e mp-units:CONAN_RUN_TESTS=True -b outdated -u
|
2020-11-05 17:51:04 +01:00
|
|
|
conan build ..
|
|
|
|
|
|
|
|
The above will download and install all of the dependencies needed for the development of the library,
|
2020-12-21 23:46:04 +01:00
|
|
|
build all of the source code and documentation, and run unit tests.
|
|
|
|
|
2021-01-27 17:48:53 +01:00
|
|
|
If you prefer to build the project via CMake rather then Conan, then you should replace the last ``conan build ..``
|
|
|
|
step with the CMake build:
|
2020-11-05 17:51:04 +01:00
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
2020-12-21 23:46:04 +01:00
|
|
|
# ...
|
2021-03-14 16:50:24 +01:00
|
|
|
cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake
|
|
|
|
cmake --build .
|
2020-03-09 18:55:41 +01:00
|
|
|
ctest
|
|
|
|
|
|
|
|
|
|
|
|
Packaging
|
|
|
|
---------
|
|
|
|
|
|
|
|
To test CMake installation and Conan packaging or create a Conan package run:
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
conan create . <username>/<channel> -pr <your_conan_profile> -s compiler.cppstd=20 -e mp-units:CONAN_RUN_TESTS=True -b outdated -u
|
2020-03-09 18:55:41 +01:00
|
|
|
|
|
|
|
The above will create a Conan package and run tests provided in *./test_package* directory.
|
|
|
|
|
|
|
|
|
2020-03-26 17:09:26 +01:00
|
|
|
Uploading **mp-units** Package to the Conan Server
|
2020-03-09 18:55:41 +01:00
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
2020-09-06 23:53:42 +02:00
|
|
|
conan upload -r <remote-name> --all mp-units/0.7.0@<user>/<channel>
|