Template library

The template library provides an example CMake shared library project for service developers.

To acquire the template service source code the user needs to fetch the code from GitHub.

git clone https://github.com/Pelagicore/template-library.git

The library also uses the googletest and googlemock projects for unit testing.

Compilation and installation

cd template-library
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/path/to/install/dir .. && make -j4
make install


The example above presents how to compile and install the template library natively on your host machine.

Using googletest in your project

The template library can also serve as a good example on how to add googletest and googlemock to your own projects. It provides a couple of CMake modules which greatly simplify the deployment of those packages:

  • AddGMock: provides the add_gmock() macro which takes care of downloading googletest and adding it as a subproject of your project. Note that googlemock is part of googletest, so it will also be available when googletest is downloaded. Just add the following lines to your CMakeLists.txt:

  • AddGTestTest: provides the add_gtest_test() macro, which you can use to add a test binary to your build. The macro takes three parameters:

    1. Name of the test executable to be created;
    2. List of source files for the test (the macro takes care of adding the googletest and googlemock related files, so you don’t have to worry about them);
    3. Any additional libraries needed by your test. If none, use “”.

These modules need to be saved into the cmake_modules directory located at the root of your project (if it does not exist, create it).

A practical example of how googletest can be added to your existing project can be found in this commit.

Template service

The template service serves as an example CMake project for service developers that should be used as a starting point while creating platform services.

To acquire the template service source code the user needs to fetch the code from GitHub.

git clone https://github.com/Pelagicore/template-service.git


The template service depends on the template library. That is reflected in its CMakeLists.txt file. The build system will check if the required dependencies are installed on the system through pkg-config.

Compilation and installation

cd template-service
mkdir build && cd build
PKG_CONFIG_PATH=/path/to/install/dir/lib/pkgconfig \
cmake -DCMAKE_INSTALL_PREFIX=/path/to/install/dir .. && make -j4
make install

Running the template service

LD_LIBRARY_PATH=/path/to/install/dir/lib \


The example above presents how to compile, install and run the template service natively on your host machine.

Install directory structure

Once the template service and library are installed, the layout of the installation will be as shown below.

├── bin
│   └── template-service
├── include
│   └── template-library
│       └── templatepublicclass.h
└── lib
    ├── libtemplate-library.so
    └── pkgconfig
        └── template-library.pc