summaryrefslogtreecommitdiff
path: root/Modules/CMakeDetermineCompilerId.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-10-10 14:51:38 -0400
committerBrad King <brad.king@kitware.com>2017-10-10 14:56:43 -0400
commitb6d3a1c09a796ec0c29074c387953fb88ebfe874 (patch)
treed5290133c7d7e8bedbc05507666935ca7297fa36 /Modules/CMakeDetermineCompilerId.cmake
parenta91eb5e41f486628910f189bf40403568af013c7 (diff)
downloadcmake-b6d3a1c09a796ec0c29074c387953fb88ebfe874.tar.gz
Clang: Diagnose unsupported GNU-like clang targeting MSVC ABI
The LLVM/Clang installer on Windows provides a `LLVM/bin` directory containing `clang.exe` and `clang++.exe` command-line tools that have a GNU-like command-line but target the MSVC ABI (instead of MinGW). We do not support this combination, so diagnose and reject it explicitly. Tell users what to do to use the `clang-cl.exe` tool instead. Issue: #16439
Diffstat (limited to 'Modules/CMakeDetermineCompilerId.cmake')
-rw-r--r--Modules/CMakeDetermineCompilerId.cmake35
1 files changed, 35 insertions, 0 deletions
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake
index 7efe739a4d..347106e78b 100644
--- a/Modules/CMakeDetermineCompilerId.cmake
+++ b/Modules/CMakeDetermineCompilerId.cmake
@@ -735,3 +735,38 @@ function(CMAKE_DETERMINE_MSVC_SHOWINCLUDES_PREFIX lang userflags)
set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "" PARENT_SCOPE)
endif()
endfunction()
+
+function(CMAKE_DIAGNOSE_UNSUPPORTED_CLANG lang envvar)
+ if(NOT CMAKE_HOST_WIN32 OR CMAKE_GENERATOR MATCHES "Visual Studio" OR
+ NOT "${CMAKE_${lang}_COMPILER_ID};${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "Clang;MSVC")
+ return()
+ endif()
+
+ # Test whether a GNU-like command-line option works.
+ execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" --version
+ RESULT_VARIABLE _clang_result
+ OUTPUT_VARIABLE _clang_stdout
+ ERROR_VARIABLE _clang_stderr)
+ if(NOT _clang_result EQUAL 0)
+ return()
+ endif()
+
+ # Help the user configure the environment to use the MSVC-like Clang.
+ string(CONCAT _msg
+ "The Clang compiler tool\n"
+ " \"${CMAKE_${lang}_COMPILER}\"\n"
+ "targets the MSVC ABI but has a GNU-like command-line interface. "
+ "This is not supported. "
+ "Use 'clang-cl' instead, e.g. by setting '${envvar}=clang-cl' in the environment."
+ )
+ execute_process(COMMAND rc -help
+ RESULT_VARIABLE _rc_result
+ OUTPUT_VARIABLE _rc_stdout
+ ERROR_VARIABLE _rc_stderr)
+ if(NOT _rc_result EQUAL 0)
+ string(APPEND _msg " "
+ "Furthermore, use the MSVC command-line environment."
+ )
+ endif()
+ message(FATAL_ERROR "${_msg}")
+endfunction()