CMake

Starting with version 0.5.0 yasmine support builds on different platforms using CMake.

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

The CMakeFileLists.txt files can be found in solution folder, in the yasmine project folder and in folders of examples.

Generating with CMake

Create a folder where the CMake output and the results of build are generated. For example, create the cmake_build folder.

Linux

In a terminal, go to directory which you extracted yasmine 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 the Linux OS, 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 yasmine.

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

There is no platform set as default. To choose bethween x64 and x86 platforms, we need to add value m64 for x64 platform or m32 for x86 platform to the CMAKE_CXX_FLAGS. It's looking like this:

# for x64 platform
cmake -G "Unix Makefiles" -DCMAKE_CXX_FLAGS=-m64 ..
 
# for x86 platform
cmake -G "Unix Makefiles" -DCMAKE_CXX_FLAGS=-m32 ..

Windows

In console, go to the location of the folder you've created (cmake_build) and run the command:

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, will be listed the generators that are available on the platform you use:

cmake --help

For example, using Visual Studio 2013 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 the 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 yasmine's preprocessor definitions with CMake is also possible by passing them as parameters in the console/terminal.

Definition

Description

SX_NO_LOGGING=[ON]/[OFF]

Use when you want to use no logging at all (no logging code is created).

SX_NO_STD_MAKE_UNIQUE=[ON]/[OFF]

When the standard make_unique is not available (e.g. no C++14 support), you have to define this preprocessor definition. A yasmine drop-in replacement template will be used instead then. It is used as standard when defining CPP_VERSION=03.

Y_LEAN_AND_MEAN=[ON]/[OFF]

If you compile the library with Y_LEAN_AND_MEAN being defined or if you define the macro locally before including yasmine.hpp, all the state pseudostates and the asynchronous simple state (with the asynchronous behavior) are excluded (i.e. those headers are not included). This can reduce compile time.

Y_PROFILER =[ON]/[OFF]

If this is defined, the state machine will count the number of events that were processed. The user can query the counter by calling the 'get_number_of_processed_events' method.

Y_OPTIMIZE=[SIZE]/[SPEED]

Sets the optimization type. Supported values: SPEED (optimizes the code for fast execution) and SIZE (optimizes the code for low memory consumption). Default value is SPEED.

CPP_VERSION=[VALUE]

Switchs the standard of the C++ compiler. Accepted values: 03 for C++03, 14 for C++14. When it is not used, the C++11 will be used.

Y_BOOST_LIB_INCLUDE=[PATH]

Sets the path to the include directory for boost.

Y_BOOST_LIB_PATH=[PATH]

Sets the path to the boost libraries.

How to use

# for Windows
cmake -G "Visual Studio 14 2015 x64" -DSX_NO_LOGGING=ON -DSX_NO_STD_MAKE_UNIQUE=ON -DY_LEAN_AND_MEAN=ON -DY_PROFILER=ON -DY_OPTIMIZE=SIZE ..
 
# for Linux
cmake -G "Unix Makefiles" -DSX_NO_LOGGING=ON -DSX_NO_STD_MAKE_UNIQUE=ON -DY_LEAN_AND_MEAN=ON -DY_PROFILER=ON -DY_OPTIMIZE=SIZE ..

C++03 compatibility

For compiling yasmine using the C++03 standard, the CPP_VERSION flag must be set to value '03'. This option is the same for Linux and Windows.

The path to boost library can be passed using Y_BOOST_LIB_INCLUDE and Y_BOOST_LIB_PATH.