Skip to content

CMake Integration

Oleksandr Geronime edited this page Jun 27, 2026 · 1 revision

CMake Integration

After installing serp-dev, SERP exposes a standard CMake package that your project's CMakeLists.txt can consume with find_package.

Basic Usage

cmake_minimum_required(VERSION 3.16)
project(MyApp)

find_package(Serp REQUIRED)

add_executable(myapp main.cpp MyService.cpp)
target_link_libraries(myapp
    Serp::core
    Serp::command
    Serp::logger_console
    Serp::transport_dbus     # or Serp::transport_grpc
)

Available CMake Targets

Core Targets

Target Contents Notes
Serp::core EventLoop, Service, Call, Property, Notification, Timer, Watchdog, Promise Always required
Serp::command Command, CommandQueue, CommandProcessor, LambdaCommand Orchestration layer
Serp::serp Aggregate: core + command + logger + default transport Convenience target

Logging Targets

Target Contents Notes
Serp::logger LogManager, Logger, LogWriter, LogTag, Loggable Logging core
Serp::logger_console LogStrategyConsole Console log output
Serp::logger_file LogStrategyFile File log output with rotation

Transport Targets

Target Contents Notes
Serp::transport Transport base interface Included transitively by backend targets
Serp::transport_dbus DBus backend (sdbus-c++) Linux only
Serp::transport_grpc gRPC backend macOS and Linux

Runtime Targets (Engineering / Debug Only)

Target Contents Notes
Serp::runtime Runtime debug registry Do not include in production builds
Serp::runtime_console RuntimeConsole REPL Interactive runtime console
Serp::runtime_dbus RuntimeDbus adapter DBus-based runtime access
Serp::runtime_grpc RuntimeGrpc adapter gRPC-based runtime access

Test Target

Target Contents Notes
Serp::test_engine TestRunner, ReplyHolder For SERP-based integration tests

Build Options

These SERP_BUILD_* options control which optional components are compiled into the installed package. Set them before find_package (if building SERP from source) or in your project's CMake configuration:

set(SERP_BUILD_TRANSPORT_DBUS ON)
set(SERP_BUILD_TRANSPORT_GRPC ON)
set(SERP_BUILD_LOGGER_CONSOLE ON)
set(SERP_BUILD_LOGGER_FILE ON)

If you installed serp-dev via the package manager rather than building from source, all components are available and these options are not needed.

Transport Selection by Deployment

When writing a CMakeLists.txt for a service executable, link the transport that matches your deployment's transport: field:

Deployment transport CMake target
inprocess No transport target needed
dbus Serp::transport_dbus
grpc Serp::transport_grpc

Generated CMakeLists.txt

In a serpgen-managed project, you typically do not write deployment CMakeLists.txt files by hand. serpgen generate-workspace generates one per process:

gen/deployments/multiprocess_dbus/
  car_service_app/
    CMakeLists.txt      # Generated — includes find_package(Serp) and links correct targets
  climate_hal_app/
    CMakeLists.txt

The generated files call find_package(Serp REQUIRED), define an executable from the generated main.cpp and your src/ files, and link the appropriate Serp::* targets based on the deployment spec.

The top-level project CMakeLists.txt includes the generated deployment directories:

add_subdirectory(gen/deployments/multiprocess_dbus/car_service_app)
add_subdirectory(gen/deployments/multiprocess_dbus/climate_hal_app)

Do not hand-edit generated CMakeLists.txt files — they are regenerated on every serpgen run. If you need to customize the build, use variables or hooks in the top-level CMakeLists.txt that the generated files pick up.

Minimum CMake Version

SERP requires CMake 3.16 or later for target_link_libraries with modern imported targets and find_package config mode.

Related Pages

Clone this wiki locally