CMake

The build with CMake is currently tested with Linux (Fedora, gcc and clang) and for Windows (Microsoft Visual Studio).

The following were used:

  • Fedora 25

  • Linux Kernel 4.04-301.fc22.i686

  • gcc 6.3.1 20161221

  • clang 3.8.0

The CMakeFileLists.txt files are located in the solution folder, in the essentials project folder and in the folder of the unit tests project.

Generating with CMake

Create a folder where the CMake output and the results of the build are supposed to be stored. For example, create the cmake_build folder.

Linux

In a terminal go to the directory to which you extracted essentials to and run the following commands:

cmake -G "Unix Makefiles" .
make VERBOSE=1

gcc and clang

Using clang is very similar to using gcc. If both compilers are installed on a Linux machine, you can switch between them and run the same CMake script. After you choose which compiler should be used, you can use the commands listed above to build essentials.

Switching from gcc to clang

The switch can be made running these commands in terminal:

export CC=/usr/bin/clang
export CXX=/usr/bin/clang++

Switching from clang to gcc

The switch can be made running these commands in terminal:

export CC=/usr/bin/gcc
export CXX=/usr/bin/g++

Choosing the architecture

The default build architecture is x86. To choose the x64 architecture for the Linux build, we need to add the value m64 to the CMAKE_CXX_FLAGS variable:

cmake -G "Unix Makefiles" -DCMAKE_CXX_FLAGS=-m64 ..

Windows

Open a console, switch into the folder you've created (e.g. cmake_build) and run the command (for a release build):

cmake -G "Visual Studio 14 Win32" -DCMAKE_BUILD_TYPE=Release ..

Under Windows, as default, CMake uses the newest Visual Studio installation. But a compiler can be used by explicitly specifying it on calling CMake.

By running the following command (among other informations) the available the generators that are available your platform will be listed:

cmake --help

For example using Visual Studio 2013 as generator, the command will look like this:

cmake -G "Visual Studio 12 2013" -DCMAKE_BUILD_TYPE=Release ..

Choosing the architecture

The architecture defaults to x86. To switch to x64 just specify the x64 platform after the generator, according to the following example:

cmake -G "Visual Studio 14 2015 x64" -DCMAKE_BUILD_TYPE=Release ..

Release/Debug

Choosing between release and debug builds is the same for both Windows and Linux. On invoking CMake, pass the parameter -DCMAKE_BUILD_TYPE as in the following examples:

# for Windows
cmake -G "Visual Studio 14 2015 x64" -DCMAKE_BUILD_TYPE=Release ..
cmake -G "Visual Studio 14 2015 x64" -DCMAKE_BUILD_TYPE=Debug ..
 
# for Linux
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ..

Preprocessor definitions

Using essentials's preprocessor definitions with CMake is also possible by passing them as parameters in the console/terminal.

Definition

Description

Y_NO_STD_MAKE_UNIQUE=[ON]/[OFF]

When the std::make_unique is not available (e.g. no C++14 support), you have to define this preprocessor definition. An essentials drop-in replacement template will be used then instead.

CPP_VERSION=[VALUE]

Sets the standard for the C++ compiler to C++03. Accepted value: 03. When it is not used, C++11 will be used.

Example

# for Windows
cmake -G "Visual Studio 14 2015 x64" -DY_NO_STD_MAKE_UNIQUE=ON ..
 
# for Linux
cmake -G "Unix Makefiles" -DY_NO_STD_MAKE_UNIQUE=ON ..