Sign up for the KDAB Newsletter
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Find what you need - explore our website and developer resources
14 November 2024
To build parts of the code optionally, or to inject CMake variables into C++, you need pre-processor definitions like -DENABLE_FEATURE on the command-line or #define ENABLE_FEATURE 1 in code.
This video shows 3 different ways of setting such pre-processor definitions with CMake. add_compile_definitions() and target_compile_definitions() trigger too much recompilation when changing a define, while configure_file() is the best solution to this problem, and saves compilation time in your projects. In addition, the video explains how and why you should use #if rather than #ifdef for on/off defines.
Corresponding blog post: https://www.kdab.com/setting-defines-with-cmake/
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Learn Modern C++
Our hands-on Modern C++ training courses are designed to quickly familiarize newcomers with the language. They also update professional C++ developers on the latest changes in the language and standard library introduced in recent C++ editions.
Learn more