Posts for: #Cmake

CMake on SMT32 | Episode 8: building with Docker

CMake on SMT32 | Episode 8: building with Docker

In this episode, we will use Docker to set up and manage our build environment.

The embedded world doesn’t always embrace the latest software development techniques. I acknowledged this in the previous episode about unit tests. Four years ago, when I started this series, I was totally unaware of Docker for instance. Since then, I have used it for non-embedded projects and I think it could have solved some issues I encountered in the past. I would like to share my experience and demonstrate that it can perfectly fit in an MCU project.

[Read more...]

CMake on SMT32 | Episode 7: unit tests

CMake on SMT32 | Episode 7: unit tests

It’s been almost four years, and it’s about time to revive this series on CMake and STM32 (or MCUs in general, STM32 just serves as a tangible example).

Funny enough, I’m not working with microcontrollers anymore…. This is a very recent change in my professional career, even if I think I will probably work again with MCUs sooner or later. However, I still use CMake to build C++ projects! The real reason to resume this series is my desire to write an article Docker for builds. In 2020, I had never used Docker at all. Today, I use it very often, and I’m convinced it could have solved some build and environment issues back then.

[Read more...]

Please meet the SYSTEM property from CMake 3.25

CMake 3.25 introduced a new variable called SYSTEM. It will help us handle warnings from 3rd party libraries. Let’s see how!

The issue (with a minimal example project)

Here is a minimal example project to reproduce the issue. It simply prints something with the great fmt library:

#include <fmt/core.h>

int main()
{
    fmt::print("The answer is {}", 42);
}

The library is fetched from GitHub thanks to CMake’s FetchContent module:

cmake_minimum_required(VERSION 3.25)
project(CMake_SYSTEM)

# Set C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Fetch fmt from GitHub
include(FetchContent)

FetchContent_Declare(
        fmt
        GIT_REPOSITORY https://github.com/fmtlib/fmt.git
        GIT_TAG 9.1.0
)

FetchContent_MakeAvailable(fmt)

# Create executable
add_executable(${PROJECT_NAME} main.cpp)

target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic -Wswitch-enum)

target_link_libraries(${PROJECT_NAME} PRIVATE fmt)

The project can be built with:

[Read more...]