1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

Warn if CMAKE_CROSSCOMPILING is true without CMAKE_SYSTEM_NAME set

Also clarify the `CMAKE_CROSSCOMPILING` documentation to state that
CMake sets the variable automatically.
This commit is contained in:
Martin Storsjö
2023-03-24 10:59:23 +02:00
committed by Brad King
parent c4c4ca0e87
commit 4d23636694
6 changed files with 22 additions and 5 deletions

View File

@@ -1,15 +1,15 @@
CMAKE_CROSSCOMPILING
--------------------
Intended to indicate whether CMake is cross compiling, but note limitations
discussed below.
This variable is set by CMake to indicate whether it is cross compiling,
but note limitations discussed below.
This variable will be set to true by CMake if the :variable:`CMAKE_SYSTEM_NAME`
variable has been set manually (i.e. in a toolchain file or as a cache entry
from the :manual:`cmake <cmake(1)>` command line). In most cases, manually
setting :variable:`CMAKE_SYSTEM_NAME` will only be done when cross compiling,
since it will otherwise be given the same value as
:variable:`CMAKE_HOST_SYSTEM_NAME` if not manually set, which is correct for
setting :variable:`CMAKE_SYSTEM_NAME` will only be done when cross compiling
since, if not manually set, it will be given the same value as
:variable:`CMAKE_HOST_SYSTEM_NAME`, which is correct for
the non-cross-compiling case. In the event that :variable:`CMAKE_SYSTEM_NAME`
is manually set to the same value as :variable:`CMAKE_HOST_SYSTEM_NAME`, then
``CMAKE_CROSSCOMPILING`` will still be set to true.

View File

@@ -176,6 +176,13 @@ else()
set(CMAKE_SYSTEM_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
endif()
set(CMAKE_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
if(CMAKE_CROSSCOMPILING)
message(AUTHOR_WARNING
"CMAKE_CROSSCOMPILING has been set by the project, toolchain file, or user. "
"CMake is resetting it to false because CMAKE_SYSTEM_NAME was not set. "
"To indicate cross compilation, only CMAKE_SYSTEM_NAME needs to be set."
)
endif()
set(CMAKE_CROSSCOMPILING FALSE)
set(PRESET_CMAKE_SYSTEM_NAME FALSE)
endif()

View File

@@ -14,6 +14,7 @@ run_cmake_toolchain(LinkFlagsInit)
run_cmake_toolchain(CMP0126-NEW)
run_cmake_toolchain(CMP0126-OLD)
run_cmake_toolchain(CMP0126-WARN)
run_cmake_toolchain(SetCrossCompiling)
function(run_IncludeDirectories)
run_cmake_toolchain(IncludeDirectories)

View File

@@ -0,0 +1,8 @@
^CMake Warning \(dev\) at [^
]*/Modules/CMakeDetermineSystem.cmake:[0-9]+ \(message\):
CMAKE_CROSSCOMPILING has been set by the project, toolchain file, or user\.
CMake is resetting it to false because CMAKE_SYSTEM_NAME was not set\. To
indicate cross compilation, only CMAKE_SYSTEM_NAME needs to be set\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(project\)
This warning is for project developers\. Use -Wno-dev to suppress it\.$

View File

@@ -0,0 +1 @@
set(CMAKE_CROSSCOMPILING TRUE)