Skip to content

Commit

Permalink
Merge pull request godotengine#1651 from enetheru/clang-cl
Browse files Browse the repository at this point in the history
CMake: Enable using clang-cl on windows
  • Loading branch information
dsnopek authored Dec 9, 2024
2 parents ce66e6b + ef9778a commit 38056d1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ project( godot-cpp
HOMEPAGE_URL "https://github.com/godotengine/godot-cpp"
LANGUAGES CXX)

compiler_detection()
godotcpp_generate()

# Test Example
Expand Down
29 changes: 25 additions & 4 deletions cmake/common_compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
Common Compiler Flags
---------------------
This file contains a single function to configure platform agnostic compiler
flags like optimization levels, warnings, and features. For platform specific
flags look to each of the ``cmake/<platform>.cmake`` files.
This file contains host platform toolchain and target platform agnostic
configuration. It includes flags like optimization levels, warnings, and
features. For target platform specific flags look to each of the
``cmake/<platform>.cmake`` files.
]=======================================================================]

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

#[[ Check for clang-cl with MSVC frontend
The compiler is tested and set when the project command is called.
The variable CXX_COMPILER_FRONTEND_VARIANT was introduced in 3.14
The generator expression $<CXX_COMPILER_FRONTEND_VARIANT> wasn't introduced
until CMake 3.30 so we can't use it yet.
So to support clang downloaded from llvm.org which uses the MSVC frontend
by default, we need to test for it. ]]
function( compiler_detection )
if( ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang )
if( ${CMAKE_CXX_COMPILER_FRONTEND_VARIANT} STREQUAL MSVC )
message( "Using clang-cl" )
set( IS_CLANG "0" PARENT_SCOPE )
set( IS_MSVC "1" PARENT_SCOPE )
set( NOT_MSVC "0" PARENT_SCOPE )
endif ()
endif ()
endfunction( )

function( common_compiler_flags TARGET_NAME )

target_compile_features(${TARGET_NAME}
Expand Down Expand Up @@ -60,7 +80,8 @@ function( common_compiler_flags TARGET_NAME )

# MSVC only
$<${IS_MSVC}:
"/MP ${PROC_N}"
# /MP isn't valid for clang-cl with msvc frontend
$<$<CXX_COMPILER_ID:MSVC>:/MP${PROC_N}>
/W4

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

0 comments on commit 38056d1

Please sign in to comment.