CMAKE_CROSSCOMPILING: Actual behaviour different to documentation
The docs for the CMAKE_CROSSCOMPILING
variable say this:
This variable will be set to true by CMake if CMake is cross compiling. Specifically if the build platform is different from the target platform.
In Modules/CMakeDetermineSystem.cmake, however, the logic that sets it is this:
# if CMAKE_SYSTEM_NAME is here already set, either it comes from a toolchain file
# or it was set via -DCMAKE_SYSTEM_NAME=...
# if that's the case, assume we are crosscompiling
if(CMAKE_SYSTEM_NAME)
if(NOT DEFINED CMAKE_CROSSCOMPILING)
set(CMAKE_CROSSCOMPILING TRUE)
endif()
set(PRESET_CMAKE_SYSTEM_NAME TRUE)
elseif(CMAKE_VS_WINCE_VERSION)
set(CMAKE_SYSTEM_NAME "WindowsCE")
set(CMAKE_SYSTEM_VERSION "${CMAKE_VS_WINCE_VERSION}")
set(CMAKE_SYSTEM_PROCESSOR "${MSVC_C_ARCHITECTURE_ID}")
set(CMAKE_CROSSCOMPILING TRUE)
set(PRESET_CMAKE_SYSTEM_NAME TRUE)
else()
set(CMAKE_SYSTEM_NAME "${CMAKE_HOST_SYSTEM_NAME}")
if(NOT DEFINED CMAKE_SYSTEM_VERSION)
set(CMAKE_SYSTEM_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
endif()
set(CMAKE_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
set(CMAKE_CROSSCOMPILING FALSE)
set(PRESET_CMAKE_SYSTEM_NAME FALSE)
endif()
Therefore, if CMAKE_SYSTEM_NAME
is set either in a toolchain file or on the command line as a cache variable, CMAKE_CROSSCOMPILING
will be TRUE
regardless of the value of CMAKE_SYSTEM_NAME
, even if it matches CMAKE_HOST_SYSTEM_NAME
. Should the documentation be updated (which I'm happy to do) or is the implementation incorrect and should follow what the docs say?