Skip to content

Commit a245479

Browse files
committed
clang: Work around toolchain file use of internal CMake variables
Since commit d44c0db (clang: setup correct configuration in gnu mode, 2019-02-20, v3.15.0-rc1~41^2~5) our Clang compiler information modules need the `CMAKE_<LANG>_COMPILER_FRONTEND_VARIANT` variable that we compute during compiler detection. However, some existing toolchain files set our internal `CMAKE_<LANG>_COMPILER_ID_RUN` variables and block that detection, but do not set the new frontend variant variable. Help them out by setting `CMAKE_<LANG>_COMPILER_FRONTEND_VARIANT` anyway. Fixes: #19515, #19539
1 parent 863f7eb commit a245479

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Modules/CMakeDetermineCCompiler.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,22 @@ if(NOT CMAKE_C_COMPILER_ID_RUN)
124124
elseif(CMAKE_C_PLATFORM_ID MATCHES "Cygwin")
125125
set(CMAKE_COMPILER_IS_CYGWIN 1)
126126
endif()
127+
else()
128+
if(NOT DEFINED CMAKE_C_COMPILER_FRONTEND_VARIANT)
129+
# Some toolchain files set our internal CMAKE_C_COMPILER_ID_RUN
130+
# variable but are not aware of CMAKE_C_COMPILER_FRONTEND_VARIANT.
131+
# They pre-date our support for the GNU-like variant targeting the
132+
# MSVC ABI so we do not consider that here.
133+
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
134+
if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC")
135+
set(CMAKE_C_COMPILER_FRONTEND_VARIANT "MSVC")
136+
else()
137+
set(CMAKE_C_COMPILER_FRONTEND_VARIANT "GNU")
138+
endif()
139+
else()
140+
set(CMAKE_C_COMPILER_FRONTEND_VARIANT "")
141+
endif()
142+
endif()
127143
endif()
128144

129145
if (NOT _CMAKE_TOOLCHAIN_LOCATION)

Modules/CMakeDetermineCXXCompiler.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,22 @@ if(NOT CMAKE_CXX_COMPILER_ID_RUN)
119119
elseif(CMAKE_CXX_PLATFORM_ID MATCHES "Cygwin")
120120
set(CMAKE_COMPILER_IS_CYGWIN 1)
121121
endif()
122+
else()
123+
if(NOT DEFINED CMAKE_CXX_COMPILER_FRONTEND_VARIANT)
124+
# Some toolchain files set our internal CMAKE_CXX_COMPILER_ID_RUN
125+
# variable but are not aware of CMAKE_CXX_COMPILER_FRONTEND_VARIANT.
126+
# They pre-date our support for the GNU-like variant targeting the
127+
# MSVC ABI so we do not consider that here.
128+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
129+
if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
130+
set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "MSVC")
131+
else()
132+
set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "GNU")
133+
endif()
134+
else()
135+
set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "")
136+
endif()
137+
endif()
122138
endif()
123139

124140
if (NOT _CMAKE_TOOLCHAIN_LOCATION)

0 commit comments

Comments
 (0)