[C++] Define preprocessor macro through cmake


Answers

To do this for a specific target, you can do the following:

target_compile_definitions(my_target PRIVATE FOO=1 BAR=1)

You should do this if you have more than one target that you're building and you don't want them all to use the same flags.

Question

How do I define a preprocessor variable through cmake?

The equivalent code would be #define foo.