summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-03-27 13:53:46 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-03-27 13:53:53 (GMT)
commit2deb22e160bafaad40c9bc5e27b14b2723dc1bfd (patch)
tree9292883d6c603978ae4a2b0c03e26578b02294d6
parentc0d50bf83f88c58d207b1973a84b9f88df7af3c3 (diff)
parent4d23636694f88c5a34926bae1f26d90a229d6773 (diff)
downloadCMake-2deb22e160bafaad40c9bc5e27b14b2723dc1bfd.zip
CMake-2deb22e160bafaad40c9bc5e27b14b2723dc1bfd.tar.gz
CMake-2deb22e160bafaad40c9bc5e27b14b2723dc1bfd.tar.bz2
Merge topic 'crosscompiling-warn-reset'
4d23636694 Warn if CMAKE_CROSSCOMPILING is true without CMAKE_SYSTEM_NAME set Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !8358
-rw-r--r--Help/variable/CMAKE_CROSSCOMPILING.rst10
-rw-r--r--Modules/CMakeDetermineSystem.cmake7
-rw-r--r--Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/ToolchainFile/SetCrossCompiling-stderr.txt8
-rw-r--r--Tests/RunCMake/ToolchainFile/SetCrossCompiling-toolchain.cmake1
-rw-r--r--Tests/RunCMake/ToolchainFile/SetCrossCompiling.cmake0
6 files changed, 22 insertions, 5 deletions
diff --git a/Help/variable/CMAKE_CROSSCOMPILING.rst b/Help/variable/CMAKE_CROSSCOMPILING.rst
index 7e6ec33..16dbfa5 100644
--- a/Help/variable/CMAKE_CROSSCOMPILING.rst
+++ b/Help/variable/CMAKE_CROSSCOMPILING.rst
@@ -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.
diff --git a/Modules/CMakeDetermineSystem.cmake b/Modules/CMakeDetermineSystem.cmake
index d4dcc62..386be73 100644
--- a/Modules/CMakeDetermineSystem.cmake
+++ b/Modules/CMakeDetermineSystem.cmake
@@ -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()
diff --git a/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake b/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake
index 7744ee8..b588ce0 100644
--- a/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake
+++ b/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake
@@ -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)
diff --git a/Tests/RunCMake/ToolchainFile/SetCrossCompiling-stderr.txt b/Tests/RunCMake/ToolchainFile/SetCrossCompiling-stderr.txt
new file mode 100644
index 0000000..6642cf6
--- /dev/null
+++ b/Tests/RunCMake/ToolchainFile/SetCrossCompiling-stderr.txt
@@ -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\.$
diff --git a/Tests/RunCMake/ToolchainFile/SetCrossCompiling-toolchain.cmake b/Tests/RunCMake/ToolchainFile/SetCrossCompiling-toolchain.cmake
new file mode 100644
index 0000000..170e26c
--- /dev/null
+++ b/Tests/RunCMake/ToolchainFile/SetCrossCompiling-toolchain.cmake
@@ -0,0 +1 @@
+set(CMAKE_CROSSCOMPILING TRUE)
diff --git a/Tests/RunCMake/ToolchainFile/SetCrossCompiling.cmake b/Tests/RunCMake/ToolchainFile/SetCrossCompiling.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/ToolchainFile/SetCrossCompiling.cmake