The CMake Configuration

Write the Top-Level CMake File

Start by creating the project-wide CMakeLists.txt in the root directory. This file defines the overall project and registers the subdirectories that contain the library and the application.

  1. Create and open the file:

    $ nano CMakeLists.txt
    
  2. Add the following content:

    <project>/CMakeLists.txt
      cmake_minimum_required(VERSION 3.28)
      project(SignalBoardProject LANGUAGES CXX)
    
      add_subdirectory(erbsland-cpp-color-term)
      add_subdirectory(signal-board)
    

The library directory is added first so its targets are available when the application is configured.

Write the Application CMake File

Next, create the CMake configuration for the tutorial application itself.

  1. Create and open the file:

    $ nano signal-board/CMakeLists.txt
    
  2. Add the following content:

    <project>/signal-board/CMakeLists.txt
      cmake_minimum_required(VERSION 3.28)
      project(SignalBoard LANGUAGES CXX)
    
      add_executable(signal-board
          src/main.cpp
      )
    
      target_compile_features(signal-board PRIVATE cxx_std_20)
      target_link_libraries(signal-board PRIVATE erbsland-color-term)
    

This configuration creates the executable and links it against the erbsland-color-term library that was registered in the top-level build.

Important Details

A few important lines in this configuration are worth highlighting:

  • add_subdirectory(erbsland-cpp-color-term) registers the library and makes its targets available to the rest of the build.

  • target_compile_features(... cxx_std_20) enables the required C++20 language features for the application.

  • target_link_libraries(... erbsland-color-term) links the executable with the terminal rendering library.

The Current Project State

Your directory should now look like this:

signal-board-project
    ├── erbsland-cpp-color-term
    ├── signal-board
    │   ├── src
    │   └── CMakeLists.txt         # [new] Application build file
    └── CMakeLists.txt             # [new] Top-level build file

Write a Minimal Main Function →