I want to be able to set a bunch of boolean flags when calling CMake, that are later used in C++ code. Something like:
set(DEBUG_ENABLE false CACHE BOOL "enable debugging")
target_compile_definitions(target PRIVATE DEBUG_ENABLE=${DEBUG_ENABLE})
This actually works fine and produces something equivalent to:
#define DEBUG_ENABLE false
However, the the native CMake literals for BOOLs are ON/OFF and tools like the CMake GUI will use those values, resulting in a define that doesn't work well in C++:
#define DEBUG_ENABLE OFF
What is the best way to forward such a boolean variable from CMake to C++?
I can think of a few things:
- Conversion function in CMake, resulting in three lines per boolean value
- Use
STRINGinstead ofBOOL - Make it work in C++:
#define ON true
None of these options seem particularly great to me.