Reputation: 137
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.
Upvotes: 0
Views: 6043
Reputation: 42842
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
Upvotes: 1
Reputation: 137
The following seems to work. Thanks to Kamil Cuk which leads me to one solution.
if(not defined VAR)
set(VAR VAL)
endif()
Upvotes: 2