Ausnahme gefangen: SSL certificate problem: certificate is not yet valid ๐Ÿ“Œ The SYSTEM property from CMake 3.25

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š The SYSTEM property from CMake 3.25


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

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:

mkdir build
cd build
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=RELEASE
ninja

There is nothing very fancy here. However: when both C++20 and -Wswitch-enum are used, warnings like these are emitted:

C:/.../cmake_system/build/_deps/fmt-src/include/fmt/core.h:2796:3: warning: enumeration value 'dec' not handled in switch [-Wswitch-enum]
 2796 |   switch (specs.type) {
      |   ^~~~~~
C:/.../cmake_system/build/_deps/fmt-src/include/fmt/core.h:2796:3: warning: enumeration value 'oct' not handled in switch [-Wswitch-enum]
C:/.../cmake_system/build/_deps/fmt-src/include/fmt/core.h:2796:3: warning: enumeration value 'hex_lower' not handled in switch [-Wswitch-enum]

Either use C++17 or remove the compiler option, and the warnings will disappear. Both of these solutions are not satisfying, but it's worth mentioning them because you may not run into the issue if you compile the code without one of these parameters.

The satisfying solution would be to ask GCC to treat fmt's headers as system headers, so that no warning will be emitted.

Before CMake 3.25

To ask GCC to treat a directory as a system include directory, you have to the following in CMake:

target_include_directories(target_name SYSTEM path/to/the/directory).

Here, we don't have any explicit call to target_include_directories() as we directly call target_link_libraries(). There is a generic solution to get the path to any target's include directory, and we simply have to add these two magic lines at the end of our CMakeLists.txt:

get_target_property(fmt_include_dir fmt INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${fmt_include_dir})

That's it! Problem solved.

In case you wonder: here, the directory is build/_deps/fmt-src/include. Not something very easy to guess.

CMake 3.25 to the rescue

Obviously, the solution shown in the previous section isn't perfect. For instance, if fmt was used by several targets, we would have to call target_include_directories() several times.

This is why the SYSTEM target property was created in CMake 3.25:

Specifies that a target is a SYSTEM library. This has the following effects:

  • Entries of INTERFACE_INCLUDE_DIRECTORIES are treated as SYSTEM include directories when compiling consumers.
  • Entries of INTERFACE_SYSTEM_INCLUDE_DIRECTORIES are not affected, and will always be treated as SYSTEM include directories.

There is also a directory property with the same name:

This directory property is used to initialize the SYSTEM target property for targets created in that directory. It is set to true by add_subdirectory() and FetchContent_Declare() when the SYSTEM option is given as an argument to those commands.

How to use the SYSTEM property

With FetchContent_Declare()

To fix our example project, we can simply add a parameter to FetchContent_Declare():

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

The warnings are now gone!

NOTE = I got error with this, but I don't know why:

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

NOTE 2 = you must specify the value of SYSTEM with a BOOL.

Manually setting the property

Another solution would be to manually change the property of the target. Just after FetchContent_MakeAvailable(fmt), the target is available and can be modified with set_target_properties(fmt PROPERTIES SYSTEM TRUE).

You can do this with any particular target, and you can do the same with a particular directory thanks to set_directory_properties().

With add_subdirectory()

Let's imagine we had manually downloaded fmt's sources and placed them in our project. We would have called add_subdirectory(fmt_directory SYSTEM) and all the target created there would have been flagged as SYSTEM.

Conclusion

Even if we might feel FetchContent is solely used to get 3rd party libraries from GitHub, this is not the only use case. This is why the SYSTEM is FALSE by default. Personally, I will probably always set it to TRUE when I get libraries from GitHub to avoid warnings!

PS: once upon a time, I wrote an article on how to avoid warnings in specific source files.

...



๐Ÿ“Œ The SYSTEM property from CMake 3.25


๐Ÿ“ˆ 40.09 Punkte

๐Ÿ“Œ Medium CVE-2021-22856: Changjia property management system project Changjia property management system


๐Ÿ“ˆ 37.3 Punkte

๐Ÿ“Œ Medium CVE-2021-22857: Changjia property management system project Changjia property management system


๐Ÿ“ˆ 37.3 Punkte

๐Ÿ“Œ Medium CVE-2018-7319: Os property real estate project Os property real estate


๐Ÿ“ˆ 28.25 Punkte

๐Ÿ“Œ CMake 3.25.2 - Cross-platform, Open-Source build system.


๐Ÿ“ˆ 25.96 Punkte

๐Ÿ“Œ Qt Creator 4.1 Brings Editor Improvements, Better CMake Support, and New Themes


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ openSUSE Tumbleweed Gets Linux Kernel 4.8.9, CMake 3.7, Firefox 50 & Mesa 13.0.1


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ openSUSE Tumbleweed Gets Linux Kernel 4.8.9, CMake 3.7, Firefox 50 & Mesa 13.0.1


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ Clear, Functional C++ Documentation with Sphinx + Breathe + Doxygen + CMake


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ How to force cmake to use a particular version


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ CMake and ndk-build support in Android Studio 2.2


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ C++ Cross-Platform Development with Visual Studio 2019 version 16.3: vcpkg, CMake configuration, remote headers, and WSL


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ Debugging Linux CMake Projects with gdbserver


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ CMake, Linux targeting, and IntelliSense improvements in Visual Studio 2019 version 16.5 Preview 2


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ cmake on Node.js Download weak encryption


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ New templates for debugging CMake projects on remote systems and WSL in Visual Studio 2019


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ CMake template for creating IDA plugins


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ Qt Creator 4.2 Launches with New Qt SCXML Editor Module, Better CMake Support


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ Qt Creator 4.1 Brings Editor Improvements, Better CMake Support, and New Themes


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ Qt Creator 4.2 Launches with New Qt SCXML Editor Module, Better CMake Support


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ Qt Creator 4.4 Open-Source IDE Released with C++ and CMake Improvements, More


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ Qt Creator 4.5 Open-Source IDE Improves Android and CMake Support


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ Entwicklungsumgebung: Qt Creator 4.13 รผberarbeitet Unterstรผtzung fรผr CMake


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ Compiler LLVM 12.0 setzt auf CMake


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ More convergent apps. Strike is an IDE for CMake-based projects. Sol is a web browser.


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ CMake and ndk-build support in Android Studio 2.2


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ Build-Werkzeug: CMake fรผr Visual Studio Code in neuer Version


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ Build-Werkzeug: CMake 3.24 unterstรผtzt den Fortran-Compiler flang


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ 3 Ways to Install CMake on Raspberry Pi


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ How to Fix: cmake command not found Error


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ CMake 3.14 and Performance Improvements


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ Neues zur CMake-Entwicklung in Visual Studio


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ New Features for CMake Targets View in Visual Studio


๐Ÿ“ˆ 21.44 Punkte

๐Ÿ“Œ Usability Improvements for CMake in Visual Studio 2019 version 16.4: Launch Target Selection and Overview Pages


๐Ÿ“ˆ 21.44 Punkte











matomo