1.1. Using the CENA binary libraries in a separate project

1.1.1. Prerequisites

In order to build your custom application using the CENA libraries, you need

  • CMake 3.16 or higher

  • A C Compiler supporting C99 or newer

  • A C++ Compiler supporting C++17 or newer

1.1.1.1. GNU/Linux

On Linux hosts, everything should work out of the box, if you have installed a recent version of GCC and CMake via your system’s package manager.

1.1.1.2. Microsoft Windows

For Windows builds, only the Cygwin based toolchain is currently tested and evaluated.

Please make sure you have set up a working Cygwin environment before continuing.

You will require at least the following packages installed via the cygwin installer:

  • gdb, gcc, g++

  • cmake

  • make

Warning

Execute all commands from within the Cygwin terminal.

1.1.2. Quickstart

Inside the CENA binary distribution, you should have received a src folder that contains some example implementations that make use of the CENA libraries. Along with the actual implementation (the .cpp files) there is a CMake project file - CMakeLists.txt

Perform the following commands to build the examples:

cd ${PATH_TO_THE_CENA_DISTRIBUTION}/usr/local/src/example_usage/
mkdir build && cd build
cmake ..
make

You now have built your first applications with the CENA as a library! The generated programs are placed in the build folder: example_mtp_controlengine and example_logging.

1.1.3. Usage

The CENA itself is written in C++17 compatible code. Included dependencies however may be written in older C++ versions or C.

The build system of the CENA itself is CMake. For integration in other projects, we highly suggest the usage of the supplied CMake config files. The config files define custom CMake targets for the CENA libraries. A CMake target in this case is a library that other projects can link to. For each defined target, the config files will automatically add linker flags and compiler flags that are required upon compilation. You can find the config files in the CENA binary distribution in usr/local/lib/cmake.

1.1.3.1. Writing your own CMakeLists.txt CMake project definition

To setup a new project using the CENA, certain tasks are required in the CMake project. We will discuss them in detail now.

Tip

All following necessities are included in the example CMake project used in the Quickstart section.

In its current configuration, the CENA will require information about the environment it is compiled for:

string(TOUPPER TARGET_${CMAKE_CXX_PLATFORM_ID} SEMODIA_CXX_PLATFORM)
string(TOUPPER TARGET_${CMAKE_CXX_PLATFORM_ID} SEMODIA_C_PLATFORM)
add_definitions(-D${SEMODIA_CXX_PLATFORM} -D${SEMODIA_C_PLATFORM})

When using the CENA in your project, you will need to inform CMake about the location of the config files:

set(CMAKE_PREFIX_PATH ${PATH_TO_THE_CENA_DISTRIBUTION}/usr/local/lib/cmake/)

Afterwards, instruct CMake to include the CENA via the configuration contained in the folder:

find_package(semodia_controlengine)

Now you need to define your own targets. These might either be libraries or executable targets. Let’s assume you want to create a new application, i.e. a CMake executable target. All you have to do is to define a new target and instruct CMake, which source files are included:

add_executable(your_application_name your_source_1.cpp your_source_2.cpp)

And that’s it. Now you can link directly to CENA’s libraries:

target_link_libraries(your_application_name PUBLIC semodia_controlengine::controlengine_packed_static)

As the CENA includes C++17 features in its headers, you will need to enable C++17 support for your compiler.

set_target_properties(your_application_name PROPERTIES CXX_STANDARD 17 CMAKE_CXX_STANDARD_REQUIRED ON)

1.1.3.2. Using the CENA without CMake

For now, there is not support for other build systems beside CMake. If you wish, you can always link to the library files directly and add include directories by hand.

1.1.3.3. IDE Support

The usage of a CMake capable IDE is highly advised. For example, Jetbrains Clion can import CMake projects natively.