Preprocessor Configuration: Header
Let's learn about how the preprocessor configures 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:
Press + to interact
#cmakedefine FOO_ENABLE#cmakedefine FOO_STRING1 "@FOO_STRING1@"#cmakedefine FOO_STRING2 "${FOO_STRING2}"#cmakedefine FOO_UNDEFINED "@FOO_UNDEFINED@"
...