Skip to content

Commit 38056d1

Browse files
authored
Merge pull request #1651 from enetheru/clang-cl
CMake: Enable using clang-cl on windows
2 parents ce66e6b + ef9778a commit 38056d1

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ project( godot-cpp
5050
HOMEPAGE_URL "https://github.com/godotengine/godot-cpp"
5151
LANGUAGES CXX)
5252

53+
compiler_detection()
5354
godotcpp_generate()
5455

5556
# Test Example

cmake/common_compiler_flags.cmake

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
Common Compiler Flags
33
---------------------
44
5-
This file contains a single function to configure platform agnostic compiler
6-
flags like optimization levels, warnings, and features. For platform specific
7-
flags look to each of the ``cmake/<platform>.cmake`` files.
5+
This file contains host platform toolchain and target platform agnostic
6+
configuration. It includes flags like optimization levels, warnings, and
7+
features. For target platform specific flags look to each of the
8+
``cmake/<platform>.cmake`` files.
89
910
]=======================================================================]
1011

@@ -24,6 +25,25 @@ set( GNU_GT_V11 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,11>" )
2425
set( GNU_LT_V11 "$<VERSION_LESS:$<CXX_COMPILER_VERSION>,11>" )
2526
set( GNU_GE_V12 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,12>" )
2627

28+
#[[ Check for clang-cl with MSVC frontend
29+
The compiler is tested and set when the project command is called.
30+
The variable CXX_COMPILER_FRONTEND_VARIANT was introduced in 3.14
31+
The generator expression $<CXX_COMPILER_FRONTEND_VARIANT> wasn't introduced
32+
until CMake 3.30 so we can't use it yet.
33+
34+
So to support clang downloaded from llvm.org which uses the MSVC frontend
35+
by default, we need to test for it. ]]
36+
function( compiler_detection )
37+
if( ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang )
38+
if( ${CMAKE_CXX_COMPILER_FRONTEND_VARIANT} STREQUAL MSVC )
39+
message( "Using clang-cl" )
40+
set( IS_CLANG "0" PARENT_SCOPE )
41+
set( IS_MSVC "1" PARENT_SCOPE )
42+
set( NOT_MSVC "0" PARENT_SCOPE )
43+
endif ()
44+
endif ()
45+
endfunction( )
46+
2747
function( common_compiler_flags TARGET_NAME )
2848

2949
target_compile_features(${TARGET_NAME}
@@ -60,7 +80,8 @@ function( common_compiler_flags TARGET_NAME )
6080

6181
# MSVC only
6282
$<${IS_MSVC}:
63-
"/MP ${PROC_N}"
83+
# /MP isn't valid for clang-cl with msvc frontend
84+
$<$<CXX_COMPILER_ID:MSVC>:/MP${PROC_N}>
6485
/W4
6586

6687
# Disable warnings which we don't plan to fix.

0 commit comments

Comments
 (0)