summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Dionne <ldionne@apple.com>2019-10-02 19:31:30 +0000
committerLouis Dionne <ldionne@apple.com>2019-10-02 19:31:30 +0000
commitc78c0e08be2192b3bc33f449f26480a58e89032b (patch)
tree90ad872f31ad1258b2ef357d4b7b39274b5b94da
parent3c1084373d320947d5dae5478e62fa262fd42e3f (diff)
downloadbcm5719-llvm-c78c0e08be2192b3bc33f449f26480a58e89032b.tar.gz
bcm5719-llvm-c78c0e08be2192b3bc33f449f26480a58e89032b.zip
[libc++] Use a function to set warning flags per target
This is part of a larger shift to move to per-target settings and eradicate global variables from the CMake build. I'm starting small with warnings only because those are easy to transition over and I want to see how it pans out, but we can handle all flags like exceptions and RTTI in the future. llvm-svn: 373511
-rw-r--r--libcxx/CMakeLists.txt65
-rw-r--r--libcxx/src/CMakeLists.txt2
2 files changed, 35 insertions, 32 deletions
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 37a1e3fc082..51ef0492551 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -568,19 +568,19 @@ if (LIBCXX_HAS_COMMENT_LIB_PRAGMA)
endif()
# Warning flags ===============================================================
-add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-add_compile_flags_if_supported(
- -Wall -Wextra -W -Wwrite-strings
- -Wno-unused-parameter -Wno-long-long
- -Werror=return-type -Wextra-semi)
-if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
- add_compile_flags_if_supported(
- -Wno-user-defined-literals
- -Wno-covered-switch-default
- -Wno-ignored-attributes # FIXME: Caused by _LIBCPP_NODEBUG_TYPE not being supported on older clangs
- )
+function(cxx_add_warning_flags target)
+ target_compile_definitions(${target} PUBLIC -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+ target_add_compile_flags_if_supported(${target} PRIVATE -Wall -Wextra -W -Wwrite-strings
+ -Wno-unused-parameter -Wno-long-long
+ -Werror=return-type -Wextra-semi)
+ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
+ target_add_compile_flags_if_supported(${target} PRIVATE
+ -Wno-user-defined-literals
+ -Wno-covered-switch-default
+ -Wno-ignored-attributes # FIXME: Caused by _LIBCPP_NODEBUG_TYPE not being supported on older clangs
+ )
if (LIBCXX_TARGETING_CLANG_CL)
- add_compile_flags_if_supported(
+ target_add_compile_flags_if_supported(${target} PRIVATE
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-c++11-compat
@@ -597,26 +597,27 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
-Wno-double-promotion # FIXME: remove me
)
endif()
-elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
- add_compile_flags_if_supported(
- -Wno-literal-suffix
- -Wno-c++14-compat
- -Wno-noexcept-type)
-endif()
-if (LIBCXX_ENABLE_WERROR)
- add_compile_flags_if_supported(-Werror)
- add_compile_flags_if_supported(-WX)
-else()
- # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is
- # added elsewhere.
- add_compile_flags_if_supported(-Wno-error)
-endif()
-if (LIBCXX_ENABLE_PEDANTIC)
- add_compile_flags_if_supported(-pedantic)
-endif()
-if (LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS)
- add_definitions(-D_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
-endif()
+ elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
+ target_add_compile_flags_if_supported(${target} PRIVATE
+ -Wno-literal-suffix
+ -Wno-c++14-compat
+ -Wno-noexcept-type)
+ endif()
+ if (LIBCXX_ENABLE_WERROR)
+ target_add_compile_flags_if_supported(${target} PRIVATE -Werror)
+ target_add_compile_flags_if_supported(${target} PRIVATE -WX)
+ else()
+ # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is
+ # added elsewhere.
+ target_add_compile_flags_if_supported(${target} PRIVATE -Wno-error)
+ endif()
+ if (LIBCXX_ENABLE_PEDANTIC)
+ target_add_compile_flags_if_supported(${target} PRIVATE -pedantic)
+ endif()
+ if (LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS)
+ target_compile_definitions(${target} PRIVATE -D_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
+ endif()
+endfunction()
# Exception flags =============================================================
if (LIBCXX_ENABLE_EXCEPTIONS)
diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index 93be30b597e..b85243fc751 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -260,6 +260,7 @@ if (LIBCXX_ENABLE_SHARED)
DEFINE_SYMBOL ""
)
cxx_set_common_defines(cxx_shared)
+ cxx_add_warning_flags(cxx_shared)
# Link against LLVM libunwind
if (LIBCXXABI_USE_LLVM_UNWINDER)
@@ -360,6 +361,7 @@ if (LIBCXX_ENABLE_STATIC)
OUTPUT_NAME "c++"
)
cxx_set_common_defines(cxx_static)
+ cxx_add_warning_flags(cxx_static)
if (LIBCXX_HERMETIC_STATIC_LIBRARY)
# If the hermetic library doesn't define the operator new/delete functions
OpenPOWER on IntegriCloud