Elements  6.2
A C++ base framework for the Euclid Software.
How to build and use the Elements project with CMake

Requirements

The CMake configuration of Elements is based on the version 2.8.5 or later of CMake.

Quick Start

To quickly get started, you can use the top Makefile, which will take care of the main details (except the value of BINARY_TAG). It is located at the root of your project:

    $ make configure
    $ make -j 8
    $ make test
    $ make install

Please note that the make install instruction is not installing the built objects in the system. It creates a special InstallArea directory that exposes these ojects to the client projects

The main targets are:

Target Action
configure just run C Make to generate the build directory (or reconfigure)
all build everything (implies configure). This is the default target
test run the tests, note that it does not imply the build and does not require installation
tests same as above but implies all
install populate the InstallArea directory, `required for runtime`
clean clean-up of the built objects
purge total removal of the built directory
doc generation of the documentation.

Build

The regular build is done as described above. This is the prefered way of building for development purposes. The call to CMake will be done by

    $ make configure

This will create a build.${BINARY_TAG} directory and run cmake ../ in there. All the other calls to make targets (except for purge and tests) will be forwarded to the generated Makefile of that directory. The complete call to CMake during the configuration looks like:

    $ cd build.${BINARY_TAG}
    $ cmake -DCMAKE_TOOLCHAIN_FILE=/usr/share/EuclidEnv/cmake/ElementsToolChain.cmake -DUSE_LOCAL_INSTALLAREA=ON ../
    $ cd ..

The toolchain file is looked for (by the Makefile wrapper) in the local cmake sub-directory or in every location of the CMAKE_PREFIX_PATH.

The build will then be done with

    $ make
    $ make test

The USE_LOCAL_INSTALLAREA will perform a local installation in the InstallArea sub-directory of the source tree.

    $ make install



There is another way to build Elements by using the standard CMake off-source build, which means that the files required by the build and the build products are created in a different directory than the source one. In this example $MY_WORK/Elements/source will contain the source checkout and $MY_WORK/Elements/build will contain the built items.

To prepare the build directory, you have to:

    $ src=$MY_WORK/Elements/source
    $ dest=$MY_WORK/Elements/build
    $ mkdir $dest
    $ cd $dest
    $ cmake -DCMAKE_TOOLCHAIN_FILE=/usr/share/EuclidEnv/cmake/ElementsToolChain.cmake \
    -G "Eclipse CDT4 - Unix Makefiles" $src

This will create the required Unix makefiles and the Eclipse project configuration to build Elements.

Other options are available on the command line when you prepare the build directory the first time or afterwards via the CMake configuration tool ccmake.

Now you can build the project with a simple (from $MY_WORK/Elements/build):

    $ cd $dest
    $ make
    $ make test

or from Eclipse after you imported the project.

For the installation, the usual command:

    $ make install

will do the installation. And since we didn't use the -DUSE_LOCAL_INSTALLAREA=on option at configure time, the installation directory will be /opt/euclid/Elements/5.9/InstallArea.

Please note that the build can also be performed by pure CMake commands:

    $ cd $dest
    $ cmake --build .
    $ cmake --build . --target test # or ctest
    $ cmake --build . --target install

This render the build agnostic about the used build subsystem (gmake, ninja, etc) and gives more options. For example the installation can be done in a different directory chosen on the fly:

    $ cmake -DCMAKE_INSTALL_PREFIX=/tmp/install_Elements -P cmake_install.cmake

Run from the build directory

For testing and debugging (as already mentioned) there is no need to install.

To run an application using the build directory, you can use the script run located in the build directory, for example like this:

    $ cd $dest
    $ ./run somescript.py --help
    $ ./run bash

Resources