@@ -312,29 +312,41 @@ macro(swift_common_cxx_warnings)
312
312
# Make unhandled switch cases be an error in assert builds
313
313
if (DEFINED LLVM_ENABLE_ASSERTIONS )
314
314
check_cxx_compiler_flag ("-Werror=switch" CXX_SUPPORTS_WERROR_SWITCH_FLAG )
315
- append_if (CXX_SUPPORTS_WERROR_SWITCH_FLAG "-Werror=switch" CMAKE_CXX_FLAGS )
315
+ if (CXX_SUPPORTS_WERROR_SWITCH_FLAG )
316
+ add_compile_options ($< $< COMPILE_LANGUAGE:CXX> :-Werror=switch> )
317
+ endif ()
316
318
317
- check_cxx_compiler_flag ("/we4062" CXX_SUPPORTS_WE4062 )
318
- append_if (CXX_SUPPORTS_WE4062 "/we4062" CMAKE_CXX_FLAGS )
319
+ if (MSVC )
320
+ check_cxx_compiler_flag ("/we4062" CXX_SUPPORTS_WE4062 )
321
+ add_compile_options ($< $< COMPILE_LANGUAGE:CXX> :/we4062> )
322
+ endif ()
319
323
endif ()
320
324
321
325
check_cxx_compiler_flag ("-Werror -Wdocumentation" CXX_SUPPORTS_DOCUMENTATION_FLAG )
322
- append_if (CXX_SUPPORTS_DOCUMENTATION_FLAG "-Wdocumentation" CMAKE_CXX_FLAGS )
326
+ if (CXX_SUPPORTS_DOCUMENTATION_FLAG )
327
+ add_compile_options ($< $< COMPILE_LANGUAGE:CXX> :-Wdocumentation> )
328
+ endif ()
323
329
324
330
check_cxx_compiler_flag ("-Werror -Wimplicit-fallthrough" CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG )
325
- append_if (CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG "-Wimplicit-fallthrough" CMAKE_CXX_FLAGS )
331
+ if (CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG )
332
+ add_compile_options ($< $< COMPILE_LANGUAGE:CXX> :-Wimplicit-fallthrough> )
333
+ endif ()
326
334
327
335
# Check for -Wunreachable-code-aggressive instead of -Wunreachable-code, as that indicates
328
336
# that we have the newer -Wunreachable-code implementation.
329
337
check_cxx_compiler_flag ("-Werror -Wunreachable-code-aggressive" CXX_SUPPORTS_UNREACHABLE_CODE_FLAG )
330
- append_if (CXX_SUPPORTS_UNREACHABLE_CODE_FLAG "-Wunreachable-code" CMAKE_CXX_FLAGS )
338
+ if (CXX_SUPPORTS_UNREACHABLE_CODE_FLAG )
339
+ add_compile_options ($< $< COMPILE_LANGUAGE:CXX> :-Wunreachable-code> )
340
+ endif ()
331
341
332
342
check_cxx_compiler_flag ("-Werror -Woverloaded-virtual" CXX_SUPPORTS_OVERLOADED_VIRTUAL )
333
- append_if (CXX_SUPPORTS_OVERLOADED_VIRTUAL "-Woverloaded-virtual" CMAKE_CXX_FLAGS )
343
+ if (CXX_SUPPORTS_OVERLOADED_VIRTUAL )
344
+ add_compile_options ($< $< COMPILE_LANGUAGE:CXX> :-Woverloaded-virtual> )
345
+ endif ()
334
346
335
347
check_cxx_compiler_flag ("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG )
336
348
if (CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG )
337
- set ( CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -Wno-nested- anon-types" )
349
+ add_compile_options ( $< $< COMPILE_LANGUAGE:CXX > :-Wnested- anon-types> )
338
350
endif ()
339
351
340
352
# Check for '-fapplication-extension'. On OS X/iOS we wish to link all
@@ -344,16 +356,19 @@ macro(swift_common_cxx_warnings)
344
356
# Disable C4068: unknown pragma. This means that MSVC doesn't report hundreds of warnings across
345
357
# the repository for IDE features such as #pragma mark "Title".
346
358
if ("${CMAKE_C_COMPILER_ID} " STREQUAL "MSVC" )
347
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4068" )
359
+ add_compile_options ($< $< COMPILE_LANGUAGE:CXX> :/wd4068> )
360
+
348
361
check_cxx_compiler_flag ("/permissive-" CXX_SUPPORTS_PERMISSIVE_FLAG )
349
- append_if (CXX_SUPPORTS_PERMISSIVE_FLAG "/permissive-" CMAKE_CXX_FLAGS )
362
+ if (CXX_SUPPORTS_PERMISSIVE_FLAG )
363
+ add_compile_options ($< $< COMPILE_LANGUAGE:CXX> :/permissive-> )
364
+ endif ()
350
365
endif ()
351
366
352
367
# Disallow calls to objc_msgSend() with no function pointer cast.
353
- set ( CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -DOBJC_OLD_DISPATCH_PROTOTYPES=0" )
368
+ add_compile_definitions ( $< $< COMPILE_LANGUAGE:CXX > :OBJC_OLD_DISPATCH_PROTOTYPES=0 > )
354
369
355
370
if (BRIDGING_MODE STREQUAL "PURE" )
356
- set ( CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -DPURE_BRIDGING_MODE" )
371
+ add_compile_definitions ( $< $< COMPILE_LANGUAGE:CXX > :PURE_BRIDGING_MODE > )
357
372
endif ()
358
373
endmacro ()
359
374
0 commit comments