0

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.

captain_flammy
  • 117
  • 3
  • 9

2 Answers2

2

The following seems to work. Thanks to Kamil Cuk which leads me to one solution.

if(not defined VAR)
                set(VAR VAL)
 endif()
captain_flammy
  • 117
  • 3
  • 9
1

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 or .

Or if you have boolean values take the option() definitions command.

References

Florian
  • 39,996
  • 9
  • 133
  • 149