Preprocessor Configuration: Header
Explore how to use CMake to configure header files dynamically by substituting variables within template headers. Learn to apply configure_file for generating headers, manage compile-time definitions, and include configured headers in your C++ source files. Gain practical experience running CMake commands to build and execute your project with configured headers.
We'll cover the following...
In this lesson, we'll cover how we can use CMake to configure included headers.
Configuring the headers
Passing definitions through target_compile_definitions() can be a bit of an overhead if we have multiple variables. Can't we just provide a header file with placeholders referencing various variables and get CMake to fill them in?
Sure we can! With the configure_file() command, we can generate new files from templates like this one: