Last month, I embarked on a new project. I set up a new computer with the latest Debian version, installed my favorites tools, and was all set to code. My first task was to migrate all the repositories from C++14 to C++20. While it might seem as straightforward as updating all the CMakeLists.txt to replace set (CMAKE_CXX_STANDARD 14) with set (CMAKE_CXX_STANDARD 20) reality proved otherwise (and I knew it would).
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: