I would love to see some progression in CMake syntaxt such that it gets more safe and better to use.
Such as to disable set(A ${var}) which accidentially unsets variable A if var is empty.
Instead the the set should always resolve into setting an empty string, and not unsetting a variable.
That would greatly improve errors, e.g.
set(var ${SOME_GLOBAL}) # global might be unset
if(var STREQUAL "")
# this if is never reached if `SOME_GLOBAL` is empty...
endif()
Also it would be nice if any command evaluating a var-name argument would FATAL_ERROR when this variable is not defined. e.g.
if(missingVar STREQUAL "asd") # Direct error here: Variable `missingVar` is undefined.
endif()
You should use “${SOME_GLOBAL}” instead of ${SOME_GLOBAL}. So the value is set to the empty string instead of unsettling the value. In general it is good practice (and even sometimes necessary) to enclose variable access with “” (avoid splitting at white spaces resp. complete elimination if there are only white spaces)
You can check with if ( DEFINED ) if a variable is set.
Just check out:
Hm. Jeah it would be nice to close these mud holes such that devs do not get more frustrated about such basic things… Bit I habe no idea given the cirrcumstances about backward compat and policies. It needs a bold step to get rid of these akward scenarios…