MINGW variable is not defined when not using MinGW
There is this MINGW
variable described (v3.26.3) as
New in version 3.2.
True
when using MinGWSet to
true
when the compiler is some version of MinGW.
However, the value is not defined when the compiler is not some version of MinGW. And it appears to not only be a specification issue but also the actual state - the variable is not defined.
This in turn makes it harder to use with -Werror=dev
that reports using undefined variables.
While with "normal CMake code" I could do something like this:
if(DEFINED MINGW)
# ...
else()
# ...
endif()
it is somewhat verbose since within the true branch I will either have to assume that mere fact of variable existence means we are under MinGW (doesn't sound future proof and robust) or I need to again if
for the actual value.
While things get even worse with generator expressions since expression like $<BOOL:${MINGW}>
is not reliable - will trigger error with -Werror=dev
when the MINGW
variable is not defined. I don't see any way around this.
What I ended up doing is to introduce custom MINGW_SAFE
variable:
if(DEFINED MINGW)
set(MINGW_SAFE ${MINGW})
else()
set(MINGW_SAFE False)
endif()
and thereafter I use my own MINGW_SAFE
instead of MINGW
.
However, it would be nicer if MINGW
would always be defined.
Furthermore, note how the specification starts with True
but then says true
. While casing doesn't matter in the end, it would be nice if the documentation would be consistent, at least within a single page.
Finally, how is this supposed to work with configurations where for example CXX is configured to MinGW but C is configured to some other compiler? Shouldn't this variable be split for languages?