Check<LANG>SourceRuns: Failed cross-compilation case can return wrong result
In the various Check<LANG>SourceRuns
modules, the check_<lang>_source_runs()
implementations all have a code block like the following:
if("${${VAR}_EXITCODE}" EQUAL 0)
set(${VAR} 1 CACHE INTERNAL "Test ${VAR}")
# ... Other logic for successful attempt
else()
if(CMAKE_CROSSCOMPILING AND "${${VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN")
set(${VAR} "${${VAR}_EXITCODE}")
else()
set(${VAR} "" CACHE INTERNAL "Test ${VAR}")
endif()
# ... Other logic for failed attempt
endif()
In the above, ${VAR}
is the variable that is meant to hold the result of the check. The documentation of these modules all have wording like the following:
If the ``<code>`` could be built and run
successfully, the internal cache variable specified by ``<resultVar>`` will
be set to 1, otherwise it will be set to an value that evaluates to boolean
false (e.g. an empty string or an error message).
While the code and the documentation are consistent with each other, the documentation contradicts itself. An error message that matches FAILED_TO_RUN
will evaluate to boolean true, not false. I suspect the expected/intended behavior is that the result variable would hold a false value rather than an error message if the run attempt failed.
The implementations for all three supported languages (C, C++, Fortran) have this problem.
Edited by Craig Scott