@@ -295,11 +295,6 @@ macro(swift_common_unified_build_config product)
295
295
endif ()
296
296
297
297
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 ()
303
298
endmacro ()
304
299
305
300
# Common cmake project config for additional warnings.
@@ -308,25 +303,42 @@ macro(swift_common_cxx_warnings)
308
303
# Make unhandled switch cases be an error in assert builds
309
304
if (DEFINED LLVM_ENABLE_ASSERTIONS )
310
305
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 ()
312
309
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 ()
315
314
endif ()
316
315
317
316
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 ()
319
320
320
321
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 ()
322
325
323
326
# Check for -Wunreachable-code-aggressive instead of -Wunreachable-code, as that indicates
324
327
# that we have the newer -Wunreachable-code implementation.
325
328
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 ()
327
332
328
333
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 ()
330
342
331
343
# Check for '-fapplication-extension'. On OS X/iOS we wish to link all
332
344
# dynamic libraries with this flag.
@@ -335,16 +347,19 @@ macro(swift_common_cxx_warnings)
335
347
# Disable C4068: unknown pragma. This means that MSVC doesn't report hundreds of warnings across
336
348
# the repository for IDE features such as #pragma mark "Title".
337
349
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
+
339
352
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 ()
341
356
endif ()
342
357
343
358
# 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 > )
345
360
346
361
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 > )
348
363
endif ()
349
364
endmacro ()
350
365
0 commit comments