Compiling¶
Introduction¶
This module is header only. So one just has to #include <cppmat/cppmat.h>
somewhere in the source code, and to tell the compiler where the header files are. For the latter, several ways are described below.
Before proceeding, a word about optimization. Of course one should use optimization when compiling the release of the code (-O2
or -O3
). But it is also a good idea to switch off the assertions in the code (mostly checks on size) that facilitate easy debugging, but do cost time. Therefore, include the flag -DNDEBUG
. Note that this is all C++ standard. I.e. it should be no surprise, and it is always a good idea to do.
Manual compiler flags¶
GNU / Clang¶
Add the following compiler’s arguments:
-I${PATH_TO_CPPMAT}/src -std=c++14
Note
(Not recommended)
If you want to avoid separately including the header files using a compiler flag, git submodule
is a nice way to go:
Include the submodule using
git submodule add https://github.com/tdegeus/cppmat.git
.Include using
#include "cppmat/src/cppmat/cppmat.h"
.If you decide to manually copy the header file, you might need to modify this relative path to your liking.
Or see (Semi-)Automatic compiler flags. You can also combine the git submodule
with any of the below compiling strategies.
(Semi-)Automatic compiler flags¶
Install¶
To enable (semi-)automatic build, one should ‘install’ cppmat
somewhere.
Install systemwide (depends on your privileges)¶
Proceed to a (temporary) build directory. For example
$ cd /path/to/temp/build
‘Install’
cppmat
:$ cmake /path/to/cppmat $ make install
Note
One usually does not need any compiler arguments after following this protocol.
Install in custom location (user)¶
Proceed to a (temporary) build directory. For example
$ cd /path/to/temp/build
‘Install’
cppmat
, to install it in a custom location$ mkdir /custom/install/path $ cmake /path/to/cppmat -DCMAKE_INSTALL_PREFIX:PATH=/custom/install/path $ make install
Add the following path to your
~/.bashrc
(or~/.zshrc
):export PKG_CONFIG_PATH=/custom/install/path/share/pkgconfig:$PKG_CONFIG_PATH export CPLUS_INCLUDE_PATH=$HOME/custom/install/path/include:$CPLUS_INCLUDE_PATH
Note
One usually does not need any compiler arguments after following this protocol.
Note
(Not recommended)
If you do not wish to use CMake
for the installation, or you want to do something custom. You can, of course. Follow these steps:
- Copy the file
src/cppmat.pc.in
tocppmat.pc
to some location that can be found bypkg_config
(for example by addingexport PKG_CONFIG_PATH=/path/to/cppmat.pc:$PKG_CONFIG_PATH
to the.bashrc
). - Modify the line
prefix=@CMAKE_INSTALL_PREFIX@
toprefix=/path/to/cppmat
. - Modify the line
Cflags: -I${prefix}/@CPPMAT_INCLUDE_DIR@
toCflags: -I${prefix}/src
. - Modify the line
Version: @CPPMAT_VERSION_NUMBER@
to reflect the correct release version.
Compiler arguments from ‘pkg-config’¶
Should the compiler for some reason not be able to find the headers, instead of -I...
one can now use
`pkg-config --cflags cppmat` -std=c++14
as compiler argument.
Compiler arguments from ‘cmake’¶
Add the following to your CMakeLists.txt
:
set(CMAKE_CXX_STANDARD 14)
find_package(PkgConfig)
pkg_check_modules(CPPMAT REQUIRED cppmat)
include_directories(${CPPMAT_INCLUDE_DIRS})
Note
Except the C++ standard it should usually not be necessary to load cppmat explicitly, as it is installed in a location where the compiler can find it.
Compiling Python modules that use cppmat¶
To compile Python modules that use cppmat using for example
python setup.py build
python setup.py install
One can ‘install’ cppmat’s headers to the include directory that Python uses. One can obtain cppmat from PyPi:
pip install cppmat
Or install from a local copy:
pip install /path/to/cppmat