There is more

To make sure that the preprocessor variables are only defined if the CMake variable is considered a true constant, one can employ #cmakedefine instead of #define in the header files that are about to be configured, by using configure_file.

Depending on whether the CMake variable is defined and evaluates to a true constant, #cmakedefine YOUR_VARIABLE will then be replaced with either #define YOUR_VARIABLE ... or /* #undef YOUR_VARIABLE */. There is also #cmakedefine01, which will set a variable to either 0 or 1, depending on whether the variable is defined.

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.