summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorRaul Tambre <raul@tambre.ee>2020-08-22 10:03:59 (GMT)
committerRaul Tambre <raul@tambre.ee>2020-08-29 10:06:44 (GMT)
commit9f81aa0f6908785791b4a9c16331986b1dee7319 (patch)
tree06854ff7a9d34318bbd0e40d2880328e9a4cb98f /Modules
parent670672f10e8b720d42b44fad80472805efa9ec00 (diff)
downloadCMake-9f81aa0f6908785791b4a9c16331986b1dee7319.zip
CMake-9f81aa0f6908785791b4a9c16331986b1dee7319.tar.gz
CMake-9f81aa0f6908785791b4a9c16331986b1dee7319.tar.bz2
CUDA: Fail if compiler detection using the host compiler fails
If an user specified a host compiler we should fail if we are unable to perform compiler detection with it. Previously we would try without and likely succeed and continue. Then we'd fail during ABI detection and compiler testing since we'd still try to use it. This is particularly problematic when crosscompiling since we extract the host linker from the compiler detection link line. This would result in the wrong host linker being used and a linking error due to architecture mismatch during ABI detection where other necessary flags may already be present to make the host compiler work. See #21076 for an example. Fix this by adding CMAKE_<LANG>_COMPILER_ID_REQUIRE_SUCCESS to CMakeDetermineCompilerId, which throws a fatal error if executing the compiler results in a non-zero exit code. Fixes #21120.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/CMakeDetermineCUDACompiler.cmake4
-rw-r--r--Modules/CMakeDetermineCompilerId.cmake9
2 files changed, 10 insertions, 3 deletions
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake
index daca382..85b6695 100644
--- a/Modules/CMakeDetermineCUDACompiler.cmake
+++ b/Modules/CMakeDetermineCUDACompiler.cmake
@@ -189,6 +189,10 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
set(nvcc_test_flags "--keep --keep-dir tmp")
if(CMAKE_CUDA_HOST_COMPILER)
string(APPEND nvcc_test_flags " -ccbin=\"${CMAKE_CUDA_HOST_COMPILER}\"")
+
+ # If the user has specified a host compiler we should fail instead of trying without.
+ # Succeeding detection without may result in confusing errors later on, see #21076.
+ set(CMAKE_CUDA_COMPILER_ID_REQUIRE_SUCCESS ON)
endif()
elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")
if(WIN32)
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake
index d7a35e1..f024061 100644
--- a/Modules/CMakeDetermineCompilerId.cmake
+++ b/Modules/CMakeDetermineCompilerId.cmake
@@ -606,9 +606,12 @@ ${CMAKE_${lang}_COMPILER_ID_OUTPUT}
")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "${MSG}")
- #if(NOT CMAKE_${lang}_COMPILER_ID_ALLOW_FAIL)
- # message(FATAL_ERROR "${MSG}")
- #endif()
+
+ # Some languages may know the correct/desired set of flags and want to fail right away if they don't work.
+ # This is currently only used by CUDA.
+ if(CMAKE_${lang}_COMPILER_ID_REQUIRE_SUCCESS)
+ message(FATAL_ERROR "${MSG}")
+ endif()
# No output files should be inspected.
set(COMPILER_${lang}_PRODUCED_FILES)