Browse Source

clang: introduce CMAKE_<lang>_COMPILER_FRONTEND_VARIANT

This variable is set to GNU on Windows when clang.exe ar clang++.exe is
used, and set to MSVC for clang-cl.exe.

CMAKE_<lang>_SIMULATE_ID is set to MSVC in both cases, as clang defaults
to -fms-compatibility for all command lines on windows.
Zsolt Parragi 6 years ago
parent
commit
53fbe23f3f

+ 1 - 0
Modules/CMakeCCompiler.cmake.in

@@ -12,6 +12,7 @@ set(CMAKE_C11_COMPILE_FEATURES "@CMAKE_C11_COMPILE_FEATURES@")
 
 set(CMAKE_C_PLATFORM_ID "@CMAKE_C_PLATFORM_ID@")
 set(CMAKE_C_SIMULATE_ID "@CMAKE_C_SIMULATE_ID@")
+set(CMAKE_C_COMPILER_FRONTEND_VARIANT "@CMAKE_C_COMPILER_FRONTEND_VARIANT@")
 set(CMAKE_C_SIMULATE_VERSION "@CMAKE_C_SIMULATE_VERSION@")
 @_SET_CMAKE_C_COMPILER_ARCHITECTURE_ID@
 @SET_MSVC_C_ARCHITECTURE_ID@

+ 1 - 0
Modules/CMakeCXXCompiler.cmake.in

@@ -14,6 +14,7 @@ set(CMAKE_CXX20_COMPILE_FEATURES "@CMAKE_CXX20_COMPILE_FEATURES@")
 
 set(CMAKE_CXX_PLATFORM_ID "@CMAKE_CXX_PLATFORM_ID@")
 set(CMAKE_CXX_SIMULATE_ID "@CMAKE_CXX_SIMULATE_ID@")
+set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "@CMAKE_CXX_COMPILER_FRONTEND_VARIANT@")
 set(CMAKE_CXX_SIMULATE_VERSION "@CMAKE_CXX_SIMULATE_VERSION@")
 @_SET_CMAKE_CXX_COMPILER_ARCHITECTURE_ID@
 @SET_MSVC_CXX_ARCHITECTURE_ID@

+ 0 - 1
Modules/CMakeDetermineCCompiler.cmake

@@ -111,7 +111,6 @@ if(NOT CMAKE_C_COMPILER_ID_RUN)
 
   include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
   CMAKE_DETERMINE_COMPILER_ID(C CFLAGS CMakeCCompilerId.c)
-  CMAKE_DIAGNOSE_UNSUPPORTED_CLANG(C CC)
 
   # Set old compiler and platform id variables.
   if(CMAKE_C_COMPILER_ID STREQUAL "GNU")

+ 0 - 1
Modules/CMakeDetermineCXXCompiler.cmake

@@ -106,7 +106,6 @@ if(NOT CMAKE_CXX_COMPILER_ID_RUN)
 
   include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
   CMAKE_DETERMINE_COMPILER_ID(CXX CXXFLAGS CMakeCXXCompilerId.cpp)
-  CMAKE_DIAGNOSE_UNSUPPORTED_CLANG(CXX CXX)
 
   # Set old compiler and platform id variables.
   if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")

+ 28 - 36
Modules/CMakeDetermineCompilerId.cmake

@@ -103,6 +103,31 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
     set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "")
   endif()
 
+  set(_variant "")
+  if("x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xClang")
+    if(CMAKE_HOST_WIN32 AND "x${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "xMSVC")
+      if(CMAKE_GENERATOR MATCHES "Visual Studio")
+        set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "MSVC")
+      else()
+        # Test whether an MSVC-like command-line option works.
+        execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" -?
+          RESULT_VARIABLE _clang_result
+          OUTPUT_VARIABLE _clang_stdout
+          ERROR_VARIABLE _clang_stderr)
+        if(_clang_result EQUAL 0)
+          set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "MSVC")
+        else()
+          set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "GNU")
+        endif()
+      endif()
+      set(_variant " with ${CMAKE_${lang}_COMPILER_FRONTEND_VARIANT}-like command-line")
+    else()
+      set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "GNU")
+    endif()
+  else()
+    set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "")
+  endif()
+
   # Display the final identification result.
   if(CMAKE_${lang}_COMPILER_ID)
     if(CMAKE_${lang}_COMPILER_VERSION)
@@ -116,9 +141,10 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
       set(_archid "")
     endif()
     message(STATUS "The ${lang} compiler identification is "
-      "${CMAKE_${lang}_COMPILER_ID}${_archid}${_version}")
+      "${CMAKE_${lang}_COMPILER_ID}${_archid}${_version}${_variant}")
     unset(_archid)
     unset(_version)
+    unset(_variant)
   else()
     message(STATUS "The ${lang} compiler identification is unknown")
   endif()
@@ -137,6 +163,7 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
     PARENT_SCOPE)
   set(CMAKE_${lang}_XCODE_ARCHS "${CMAKE_${lang}_XCODE_ARCHS}" PARENT_SCOPE)
   set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "${CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX}" PARENT_SCOPE)
+  set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "${CMAKE_${lang}_COMPILER_FRONTEND_VARIANT}" PARENT_SCOPE)
   set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE)
   set(CMAKE_${lang}_COMPILER_VERSION_INTERNAL "${CMAKE_${lang}_COMPILER_VERSION_INTERNAL}" PARENT_SCOPE)
   set(CMAKE_${lang}_COMPILER_WRAPPER "${CMAKE_${lang}_COMPILER_WRAPPER}" PARENT_SCOPE)
@@ -838,38 +865,3 @@ 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 an MSVC-like command-line option works.
-  execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" -?
-    RESULT_VARIABLE _clang_result
-    OUTPUT_VARIABLE _clang_stdout
-    ERROR_VARIABLE _clang_stderr)
-  if(_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()