I would like to give a default value DEF to a variable VAR if I do not give the flag -DVAR=VAL. Have you any idea?
Thank you.
I would like to give a default value DEF to a variable VAR if I do not give the flag -DVAR=VAL. Have you any idea?
Thank you.
The following seems to work. Thanks to Kamil Cuk which leads me to one solution.
if(not defined VAR)
set(VAR VAL)
endif()
You can just use set(... CACHE ...)
command:
set(VAR "DEF" CACHE STRING "My VAR for doing xyz")
If the variable is already set in the cache - e.g. via command line switch -D
- it's not overwritten. And the user could change it with cmake-gui or ccmake.
Or if you have boolean values take the option()
definitions command.
References