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.

Buildung 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

Build a single project of the framework

Pass the name of the project to the make command in the terminal after the cmake command completed. Dependencies are also built. To build the hello_yasmine project for example, we run:

make hello_yasmine

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 and build options

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.

SX_RAPIDJSON

Sets the path to the rapidJSON headers. If it is not defined, the default value '/usr/include/rapidjson' for Linux and 'C:\Program Files\rapidjson' for Windows is used. RapidJSON is used for the model and for libygen.

SX_GCC_EXPAND_TEMPLATE_PARAM_PACK_BUG

Activates a workaround for a bug in GCC where an error occurs during the expansion of template parameter packs that appear in lambda-expressions (problem was reported for GCC 4.8.4)

SX_BOOST_LIB_INCLUDE=[PATH]

Sets the path to the include directory for boost.

SX_BOOST_LIB_PATH=[PATH]

Sets the path to the boost libraries.

SX_STATIC=[ON]/[OFF]

Toggle library generation between static and shared. Default value is OFF.

SX_PEDANTIC=[ON]/[OFF]

Flag to turn off the pedantic flag for gcc/clang compilers. Default value is ON.

Deprecated definitions and build options

Definition

Replaced with

Changed in version

Y_BOOST_LIB_INCLUDE

SX_BOOST_LIB_INCLUDE

1.4.1

Y_BOOST_LIB_PATH

SX_BOOST_LIB_PATH

1.4.1

Usage example

# 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.

Starting with version 1.4.1, the boost libraries and paths are searched automatically if the user don't provide the path to the boost include directory.

The path to boost includes can be passed using SX_BOOST_LIB_INCLUDE and the path to the libraries can be passed using SX_BOOST_LIB_PATH.