@@ -568,19 +568,19 @@ if (LIBCXX_HAS_COMMENT_LIB_PRAGMA)
568568endif ()
569569
570570# Warning flags ===============================================================
571- add_definitions (-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER )
572- add_compile_flags_if_supported(
573- -Wall -Wextra -W -Wwrite-strings
574- -Wno-unused-parameter -Wno-long-long
575- -Werror=return-type -Wextra-semi)
576- if ("${CMAKE_CXX_COMPILER_ID} " MATCHES "Clang" )
577- add_compile_flags_if_supported(
578- -Wno-user-defined -literals
579- -Wno-covered-switch-default
580- -Wno-ignored-attributes # FIXME: Caused by _LIBCPP_NODEBUG_TYPE not being supported on older clangs
581- )
571+ function (cxx_add_warning_flags target )
572+ target_compile_definitions ( ${target} PUBLIC -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
573+ target_add_compile_flags_if_supported( ${target} PRIVATE -Wall -Wextra -W -Wwrite-strings
574+ -Wno-unused-parameter -Wno-long-long
575+ -Werror=return-type -Wextra-semi)
576+ if ("${CMAKE_CXX_COMPILER_ID} " MATCHES "Clang" )
577+ target_add_compile_flags_if_supported( ${target} PRIVATE
578+ -Wno-user-defined -literals
579+ -Wno-covered-switch-default
580+ -Wno-ignored-attributes # FIXME: Caused by _LIBCPP_NODEBUG_TYPE not being supported on older clangs
581+ )
582582 if (LIBCXX_TARGETING_CLANG_CL)
583- add_compile_flags_if_supported(
583+ target_add_compile_flags_if_supported( ${target} PRIVATE
584584 -Wno-c++98-compat
585585 -Wno-c++98-compat-pedantic
586586 -Wno-c++11-compat
@@ -597,26 +597,27 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
597597 -Wno-double-promotion # FIXME: remove me
598598 )
599599 endif ()
600- elseif ("${CMAKE_CXX_COMPILER_ID} " MATCHES "GNU" )
601- add_compile_flags_if_supported(
602- -Wno-literal-suffix
603- -Wno-c++14-compat
604- -Wno-noexcept-type )
605- endif ()
606- if (LIBCXX_ENABLE_WERROR)
607- add_compile_flags_if_supported(-Werror)
608- add_compile_flags_if_supported(-WX)
609- else ()
610- # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is
611- # added elsewhere.
612- add_compile_flags_if_supported(-Wno-error)
613- endif ()
614- if (LIBCXX_ENABLE_PEDANTIC)
615- add_compile_flags_if_supported(-pedantic)
616- endif ()
617- if (LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS)
618- add_definitions (-D_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
619- endif ()
600+ elseif ("${CMAKE_CXX_COMPILER_ID} " MATCHES "GNU" )
601+ target_add_compile_flags_if_supported(${target} PRIVATE
602+ -Wno-literal-suffix
603+ -Wno-c++14-compat
604+ -Wno-noexcept-type )
605+ endif ()
606+ if (LIBCXX_ENABLE_WERROR)
607+ target_add_compile_flags_if_supported(${target} PRIVATE -Werror)
608+ target_add_compile_flags_if_supported(${target} PRIVATE -WX)
609+ else ()
610+ # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is
611+ # added elsewhere.
612+ target_add_compile_flags_if_supported(${target} PRIVATE -Wno-error)
613+ endif ()
614+ if (LIBCXX_ENABLE_PEDANTIC)
615+ target_add_compile_flags_if_supported(${target} PRIVATE -pedantic)
616+ endif ()
617+ if (LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS)
618+ target_compile_definitions (${target} PRIVATE -D_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
619+ endif ()
620+ endfunction ()
620621
621622# Exception flags =============================================================
622623if (LIBCXX_ENABLE_EXCEPTIONS)
0 commit comments