Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
161 lines (88 sloc) 4.56 KB

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:

  1. Include the submodule using git submodule add https://github.com/tdegeus/cppmat.git.

  2. 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 :ref:`compile_automatic`. 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)

  1. Proceed to a (temporary) build directory. For example

    $ cd /path/to/temp/build
  2. '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)

  1. Proceed to a (temporary) build directory. For example

    $ cd /path/to/temp/build
  2. '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
  3. 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:

  1. Copy the file src/cppmat.pc.in to cppmat.pc to some location that can be found by pkg_config (for example by adding export PKG_CONFIG_PATH=/path/to/cppmat.pc:$PKG_CONFIG_PATH to the .bashrc).
  2. Modify the line prefix=@CMAKE_INSTALL_PREFIX@ to prefix=/path/to/cppmat.
  3. Modify the line Cflags: -I${prefix}/@CPPMAT_INCLUDE_DIR@ to Cflags: -I${prefix}/src.
  4. 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
You can’t perform that action at this time.