@@ -295,11 +295,6 @@ macro(swift_common_unified_build_config product)
295295 endif ()
296296
297297 include (AddSwiftTableGen) # This imports TableGen from LLVM.
298-
299- check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
300- if (CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
301- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" )
302- endif ()
303298endmacro ()
304299
305300# Common cmake project config for additional warnings.
@@ -308,25 +303,42 @@ macro(swift_common_cxx_warnings)
308303 # Make unhandled switch cases be an error in assert builds
309304 if (DEFINED LLVM_ENABLE_ASSERTIONS)
310305 check_cxx_compiler_flag("-Werror=switch" CXX_SUPPORTS_WERROR_SWITCH_FLAG)
311- append_if(CXX_SUPPORTS_WERROR_SWITCH_FLAG "-Werror=switch" CMAKE_CXX_FLAGS )
306+ if (CXX_SUPPORTS_WERROR_SWITCH_FLAG)
307+ add_compile_options ($<$<COMPILE_LANGUAGE:CXX>:-Werror=switch>)
308+ endif ()
312309
313- check_cxx_compiler_flag("/we4062" CXX_SUPPORTS_WE4062)
314- append_if(CXX_SUPPORTS_WE4062 "/we4062" CMAKE_CXX_FLAGS )
310+ if (MSVC )
311+ check_cxx_compiler_flag("/we4062" CXX_SUPPORTS_WE4062)
312+ add_compile_options ($<$<COMPILE_LANGUAGE:CXX>:/we4062>)
313+ endif ()
315314 endif ()
316315
317316 check_cxx_compiler_flag("-Werror -Wdocumentation" CXX_SUPPORTS_DOCUMENTATION_FLAG)
318- append_if(CXX_SUPPORTS_DOCUMENTATION_FLAG "-Wdocumentation" CMAKE_CXX_FLAGS )
317+ if (CXX_SUPPORTS_DOCUMENTATION_FLAG)
318+ add_compile_options ($<$<COMPILE_LANGUAGE:CXX>:-Wdocumentation>)
319+ endif ()
319320
320321 check_cxx_compiler_flag("-Werror -Wimplicit-fallthrough" CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG)
321- append_if(CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG "-Wimplicit-fallthrough" CMAKE_CXX_FLAGS )
322+ if (CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG)
323+ add_compile_options ($<$<COMPILE_LANGUAGE:CXX>:-Wimplicit-fallthrough>)
324+ endif ()
322325
323326 # Check for -Wunreachable-code-aggressive instead of -Wunreachable-code, as that indicates
324327 # that we have the newer -Wunreachable-code implementation.
325328 check_cxx_compiler_flag("-Werror -Wunreachable-code-aggressive" CXX_SUPPORTS_UNREACHABLE_CODE_FLAG)
326- append_if(CXX_SUPPORTS_UNREACHABLE_CODE_FLAG "-Wunreachable-code" CMAKE_CXX_FLAGS )
329+ if (CXX_SUPPORTS_UNREACHABLE_CODE_FLAG)
330+ add_compile_options ($<$<COMPILE_LANGUAGE:CXX>:-Wunreachable-code>)
331+ endif ()
327332
328333 check_cxx_compiler_flag("-Werror -Woverloaded-virtual" CXX_SUPPORTS_OVERLOADED_VIRTUAL)
329- append_if(CXX_SUPPORTS_OVERLOADED_VIRTUAL "-Woverloaded-virtual" CMAKE_CXX_FLAGS )
334+ if (CXX_SUPPORTS_OVERLOADED_VIRTUAL)
335+ add_compile_options ($<$<COMPILE_LANGUAGE:CXX>:-Woverloaded-virtual>)
336+ endif ()
337+
338+ check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
339+ if (CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
340+ add_compile_options ($<$<COMPILE_LANGUAGE:CXX>:-Wnested-anon-types>)
341+ endif ()
330342
331343 # Check for '-fapplication-extension'. On OS X/iOS we wish to link all
332344 # dynamic libraries with this flag.
@@ -335,16 +347,19 @@ macro(swift_common_cxx_warnings)
335347 # Disable C4068: unknown pragma. This means that MSVC doesn't report hundreds of warnings across
336348 # the repository for IDE features such as #pragma mark "Title".
337349 if ("${CMAKE_C_COMPILER_ID} " STREQUAL "MSVC" )
338- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4068" )
350+ add_compile_options ($<$<COMPILE_LANGUAGE:CXX>:/wd4068>)
351+
339352 check_cxx_compiler_flag("/permissive-" CXX_SUPPORTS_PERMISSIVE_FLAG)
340- append_if(CXX_SUPPORTS_PERMISSIVE_FLAG "/permissive-" CMAKE_CXX_FLAGS )
353+ if (CXX_SUPPORTS_PERMISSIVE_FLAG)
354+ add_compile_options ($<$<COMPILE_LANGUAGE:CXX>:/permissive->)
355+ endif ()
341356 endif ()
342357
343358 # Disallow calls to objc_msgSend() with no function pointer cast.
344- set ( CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -DOBJC_OLD_DISPATCH_PROTOTYPES=0" )
359+ add_compile_definitions ($<$<COMPILE_LANGUAGE:CXX>:OBJC_OLD_DISPATCH_PROTOTYPES=0> )
345360
346361 if (BRIDGING_MODE STREQUAL "PURE" )
347- set ( CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -DPURE_BRIDGING_MODE" )
362+ add_compile_definitions ($<$<COMPILE_LANGUAGE:CXX>:PURE_BRIDGING_MODE> )
348363 endif ()
349364endmacro ()
350365
0 commit comments