22Common 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>" )
2425set ( GNU_LT_V11 "$<VERSION_LESS:$<CXX_COMPILER_VERSION>,11>" )
2526set ( 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+
2747function ( 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