Skip to content

Commit 0124d44

Browse files
committed
DOC: Documentation for updated build system
1 parent de4b094 commit 0124d44

File tree

2 files changed

+90
-10
lines changed

2 files changed

+90
-10
lines changed

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,33 @@ For details on Pybind11 and Armadillo refer to their respective documentation [1
3030

3131
## Installation
3232
CARMA is a header only library that relies on two other header only libraries, Armadillo and Pybind11.
33+
It can be integrated in a CMake build using `ADD_SUBDIRECTORY(<path_to_carma>)` or installation which provides an interface library target `carma::carma` that has been linked with Python, Numpy, Pybind11 and Armadillo. See [build configuration](https://carma.readthedocs.io/en/stable/building.html) for details.
34+
35+
It can be installed using:
36+
```bash
37+
mkdir build
38+
cd build
39+
# optionally with -DCMAKE_INSTALL_PREFIX:PATH=<path/to/desired/location>
40+
cmake -DCARMA_INSTALL_LIB=ON ..
41+
cmake --build . --config Release --target install
42+
```
43+
44+
You can than include it in a project using:
3345

34-
CARMA can be integrated in a CMake build using `ADD_SUBDIRECTORY(<path_to_carma>)` which provides an interface library target `carma`
35-
that has been linked with Python, Numpy, Pybind11 and Armadillo. For Pybind11 and or Armadillo we create target(s) based on user settable version, see [build configuration](https://carma.readthedocs.io/en/stable/building.html), when they are not defined.
46+
```cmake
47+
FIND_PACKAGE(carma CONFIG REQUIRED)
48+
TARGET_LINK_LIBRARIES(<your_target> PRIVATE carma::carma)
49+
```
50+
51+
### CMake subdirectory
52+
53+
Alternatively you can forgo installing CARMA and directly use it as CMake subdirectory.
54+
For Pybind11 and or Armadillo we create target(s) based on user settable version, see [build configuration](https://carma.readthedocs.io/en/stable/building.html), when they are not defined.
3655

3756
To link with CARMA:
3857
```cmake
3958
ADD_SUBDIRECTORY(extern/carma)
40-
TARGET_LINK_LIBRARIES(<your_target> PRIVATE carma)
59+
TARGET_LINK_LIBRARIES(<your_target> PRIVATE carma::carma)
4160
```
4261
CARMA and Armadillo can then be included using:
4362
```C++
@@ -89,6 +108,8 @@ creating the tuple for the way out.
89108
#include <pybind11/numpy.h>
90109
#include <pybind11/pytypes.h>
91110

111+
namespace py = pybind11;
112+
92113
py::tuple ols(arma::mat& X, arma::colvec& y) {
93114
// We borrow the data underlying the numpy arrays
94115
int n = X.n_rows, k = X.n_cols;

docs/source/building.rst

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,88 @@ CARMA v0.5 requires a compiler with support for C++14 and supports:
1414
* Pybind11 v2.6.0 -- v2.6.2
1515
* Armadillo >= 10.5.2
1616

17-
CARMA target
18-
------------
17+
CMake build
18+
-----------
1919

2020
CARMA provides a CMake configuration that can be used to integrate into existing builds.
21-
It is advised to use :bash:`ADD_SUBDIRECTORY`, this provides an interface target, ``carma``, that can be linked to your target.
21+
You can either use it directly or install it first. To edit the configuration please see
22+
23+
It is advised to use the ``carma::carma`` interface target that can be linked to your target.
2224
This target pre-compiles the ``cnalloc.h`` header containing wrappers around Numpy's (de)allocator that are then picked up by Armadillo.
2325
By pre-compiling the header we can ensure that the ``ARMA_ALIEN_MEM_ALLOC`` and ``ARMA_ALIEN_MEM_FREE`` definitions exist when including Armadillo
2426
regardless of the include order.
2527

2628
.. warning:: if you are not using CARMA's cmake target you have to ensure that you include CARMA before Armadillo. Not doing so results in a compile error.
2729

30+
Installation
31+
************
32+
33+
Make sure to change the configuration if desired before installing CARMA.
34+
35+
CARMA can be installed using:
36+
37+
.. code-block:: bash
38+
39+
mkdir build
40+
cd build
41+
# optionally with -DCMAKE_INSTALL_PREFIX:PATH=
42+
cmake -DCARMA_INSTALL_LIB=ON ..
43+
cmake --build . --config Release --target install
44+
45+
You can than include it in a project using:
46+
47+
.. code-block:: cmake
48+
49+
FIND_PACKAGE(carma CONFIG REQUIRED)
50+
TARGET_LINK_LIBRARIES(<your_target> PRIVATE carma::carma)
51+
52+
The ``REQUIRED`` state is propagated to the dependencies of CARMA.
53+
54+
Variables
55+
^^^^^^^^^
56+
57+
The :bash:`FIND_PACKAGE` call sets the following variables
58+
59+
- ``carma_FOUND`` -- true if CARMA was found
60+
- ``carma_INCLUDE_DIR`` -- the path to CARMA's include directory
61+
- ``carma_INCLUDE_DIRS`` -- the paths to CARMA's include directory and the paths to the include directories of the dependencies.
62+
63+
Components
64+
^^^^^^^^^^
65+
66+
When including carma using :bash:`FIND_PACKAGE` two targets are created:
67+
68+
- ``carma::carma``
69+
70+
``carma::carma`` has been linked with Python, Numpy, Pybind11 and Armadillo and pre-compiles the ``cnalloc.h`` header which means that there is no required order to includes or carma and armadillo. If you only want this component you can use :bash:`FIND_PACKAGE(carma CONFIG REQUIRED COMPONENTS carma)`
71+
72+
- ``carma::headers``
73+
74+
If you want to have a header-only target that is not linked with the dependencies and does not pre-compile ``cnalloc.h``. You must than make sure to link it to it's dependencies and make sure to always include carma before armadillo.
75+
If you only want this component you can use :bash:`FIND_PACKAGE(carma CONFIG REQUIRED COMPONENTS headers)`
76+
77+
Subdirectory
78+
************
79+
80+
Alternatively, you can use CARMA without installing it by using:
81+
82+
.. code-block:: cmake
83+
84+
ADD_SUBDIRECTORY(extern/carma)
85+
TARGET_LINK_LIBRARIES(<your_target> PRIVATE carma::carma)
86+
87+
The same targets and conditions as for the installation hold, however, this build will obtain Armadillo and Pybind11 if they have not been provided.
88+
2889
Armadillo
2990
---------
3091

3192
Users can provide a specific Armadillo version by making sure the target ``armadillo`` is set before including CARMA or by setting:
3293

33-
The Armadillo version can be set using:
34-
3594
.. code-block:: bash
3695
3796
-DARMADILLO_ROOT_DIR=/path/to/armadillo/root/directory
3897
39-
If neither is set, CARMA will provide the ``armadillo`` target at build time and store a clone of armadillo in ``carma/extern/armadillo-code``. The Armadillo version, by default ``10.5.2``, can be set using:
98+
When using the subdirectory build, if neither is set, CARMA will provide the ``armadillo`` target at build time and store a clone of armadillo in ``carma/extern/armadillo-code``. The Armadillo version, by default ``10.5.2``, can be set using:
4099

41100
.. code-block:: bash
42101
@@ -52,7 +111,7 @@ Users can provide a specific Pybind11 version by making sure the target ``pybind
52111
-DPYBIND11_ROOT_DIR=/path/to/pybind11/root/directory
53112
54113
55-
If neither is set, CARMA will provide the ``pybind11`` target at build time and store a clone in ``carma/extern/pybind11``. The Pybind11 version, by default ``v2.6.2`` can be set using:
114+
When using the subdirectory build, if neither is set, CARMA will provide the ``pybind11`` target at build time and store a clone in ``carma/extern/pybind11``. The Pybind11 version, by default ``v2.6.2`` can be set using:
56115

57116
.. code-block:: bash
58117

0 commit comments

Comments
 (0)