[CMake] Enforce variable is defined

Alexander Neundorf a.neundorf-work at gmx.net
Sat Jan 14 14:45:34 EST 2012


On Saturday 14 January 2012, Thorsten Wagner wrote:
> Hello,
> how can i enforce that a variable will be defined?

what exactly do you mean ?
Do you want to force the user to set some variable explicitely ?

if(NOT DEFINED SOME_VARIABLE)
  message(FATAL_ERROR "...")
endif()


or put it with some default value in the cache, and then check that it has 
been changed:

set(SOME_VARIABLE "NOTFOUND" CACHE STRING "must be set by the user")

if ("${SOME_VARIABLE}" STREQUAL "NOTFOUND")
  message(FATAL_ERROR "...")
endif()

Is that what you want to do ?

Alex


More information about the CMake mailing list