diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -558,65 +558,6 @@ target_compile_options(${target} PUBLIC "${LIBCXX_ADDITIONAL_COMPILE_FLAGS}") endfunction() -# Warning flags =============================================================== -function(cxx_add_warning_flags target) - target_compile_definitions(${target} PUBLIC -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) - if (MSVC) - # -W4 is the cl.exe/clang-cl equivalent of -Wall. (In cl.exe and clang-cl, - # -Wall is equivalent to -Weverything in GCC style compiler drivers.) - target_add_compile_flags_if_supported(${target} PRIVATE -W4) - else() - target_add_compile_flags_if_supported(${target} PRIVATE -Wall) - endif() - target_add_compile_flags_if_supported(${target} PRIVATE -Wextra -W -Wwrite-strings - -Wno-unused-parameter -Wno-long-long - -Werror=return-type -Wextra-semi -Wundef - -Wformat-nonliteral) - if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - target_add_compile_flags_if_supported(${target} PRIVATE - -Wno-user-defined-literals - -Wno-covered-switch-default - -Wno-suggest-override - ) - if (LIBCXX_TARGETING_CLANG_CL) - target_add_compile_flags_if_supported(${target} PRIVATE - -Wno-c++98-compat - -Wno-c++98-compat-pedantic - -Wno-c++11-compat - -Wno-undef - -Wno-reserved-id-macro - -Wno-gnu-include-next - -Wno-gcc-compat # For ignoring "'diagnose_if' is a clang extension" warnings - -Wno-zero-as-null-pointer-constant # FIXME: Remove this and fix all occurrences. - -Wno-deprecated-dynamic-exception-spec # For auto_ptr - -Wno-sign-conversion - -Wno-old-style-cast - -Wno-deprecated # FIXME: Remove this and fix all occurrences. - -Wno-shift-sign-overflow # FIXME: Why do we need this with clang-cl but not clang? - -Wno-double-promotion # FIXME: remove me - ) - endif() - elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") - target_add_compile_flags_if_supported(${target} PRIVATE - -Wno-attributes - -Wno-literal-suffix - -Wno-c++14-compat - -Wno-noexcept-type - -Wno-suggest-override) - 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() -endfunction() - # Exception flags ============================================================= function(cxx_add_exception_flags target) if (LIBCXX_ENABLE_EXCEPTIONS) @@ -899,7 +840,7 @@ # Setup all common build flags ================================================= function(cxx_add_common_build_flags target) cxx_add_basic_build_flags(${target}) - cxx_add_warning_flags(${target}) + cxx_add_warning_flags(${target} ${LIBCXX_ENABLE_WERROR} ${LIBCXX_ENABLE_PEDANTIC}) cxx_add_windows_flags(${target}) cxx_add_exception_flags(${target}) cxx_add_rtti_flags(${target}) diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt --- a/libcxxabi/CMakeLists.txt +++ b/libcxxabi/CMakeLists.txt @@ -44,7 +44,7 @@ "Provide support for exceptions in the runtime. When disabled, libc++abi does not support stack unwinding and other exceptions-related features." ON) option(LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON) -option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) +option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF) option(LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF) @@ -283,41 +283,6 @@ # it is being built as part of libcxx. add_definitions(-D_LIBCPP_BUILDING_LIBRARY) -add_compile_flags_if_supported(-Werror=return-type) - -# Get warning flags -add_compile_flags_if_supported(-W) -add_compile_flags_if_supported(-Wall) -add_compile_flags_if_supported(-Wchar-subscripts) -add_compile_flags_if_supported(-Wconversion) -add_compile_flags_if_supported(-Wmismatched-tags) -add_compile_flags_if_supported(-Wmissing-braces) -add_compile_flags_if_supported(-Wnewline-eof) -add_compile_flags_if_supported(-Wunused-function) -add_compile_flags_if_supported(-Wshadow) -add_compile_flags_if_supported(-Wshorten-64-to-32) -add_compile_flags_if_supported(-Wsign-compare) -add_compile_flags_if_supported(-Wsign-conversion) -add_compile_flags_if_supported(-Wstrict-aliasing=2) -add_compile_flags_if_supported(-Wstrict-overflow=4) -add_compile_flags_if_supported(-Wunused-parameter) -add_compile_flags_if_supported(-Wunused-variable) -add_compile_flags_if_supported(-Wwrite-strings) -add_compile_flags_if_supported(-Wundef) - -add_compile_flags_if_supported(-Wno-suggest-override) - -if (LIBCXXABI_ENABLE_WERROR) - add_compile_flags_if_supported(-Werror) - add_compile_flags_if_supported(-WX) -else() - add_compile_flags_if_supported(-Wno-error) - add_compile_flags_if_supported(-WX-) -endif() -if (LIBCXXABI_ENABLE_PEDANTIC) - add_compile_flags_if_supported(-pedantic) -endif() - # Get feature flags. add_compile_flags_if_supported(-fstrict-aliasing) diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt --- a/libcxxabi/src/CMakeLists.txt +++ b/libcxxabi/src/CMakeLists.txt @@ -158,8 +158,11 @@ message(STATUS "Could not find ParallelSTL, libc++abi will not attempt to use it but the build may fail if the libc++ in use needs it to be available.") endif() +include(WarningFlags) + # Build the shared library. add_library(cxxabi_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS}) +cxx_add_warning_flags(cxxabi_shared_objects ${LIBCXXABI_ENABLE_WERROR} ${LIBCXXABI_ENABLE_PEDANTIC}) if (LIBCXXABI_USE_LLVM_UNWINDER) if (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY) target_link_libraries(cxxabi_shared_objects PUBLIC unwind_shared_objects) # propagate usage requirements @@ -246,6 +249,7 @@ # Build the static library. add_library(cxxabi_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS}) +cxx_add_warning_flags(cxxabi_static_objects ${LIBCXXABI_ENABLE_WERROR} ${LIBCXXABI_ENABLE_PEDANTIC}) if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY) target_link_libraries(cxxabi_static_objects PUBLIC unwind_static_objects) # propagate usage requirements target_sources(cxxabi_static_objects PUBLIC $) diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -169,28 +169,6 @@ endif() endif() -# Get warning flags -add_compile_flags_if_supported(-W) -add_compile_flags_if_supported(-Wall) -add_compile_flags_if_supported(-Wchar-subscripts) -add_compile_flags_if_supported(-Wconversion) -add_compile_flags_if_supported(-Wmismatched-tags) -add_compile_flags_if_supported(-Wmissing-braces) -add_compile_flags_if_supported(-Wnewline-eof) -add_compile_flags_if_supported(-Wno-unused-function) -add_compile_flags_if_supported(-Wshadow) -add_compile_flags_if_supported(-Wshorten-64-to-32) -add_compile_flags_if_supported(-Wsign-compare) -add_compile_flags_if_supported(-Wsign-conversion) -add_compile_flags_if_supported(-Wstrict-aliasing=2) -add_compile_flags_if_supported(-Wstrict-overflow=4) -add_compile_flags_if_supported(-Wunused-parameter) -add_compile_flags_if_supported(-Wunused-variable) -add_compile_flags_if_supported(-Wwrite-strings) -add_compile_flags_if_supported(-Wundef) - -add_compile_flags_if_supported(-Wno-suggest-override) - if (WIN32) # The headers lack matching dllexport attributes (_LIBUNWIND_EXPORT); # silence the warning instead of cluttering the headers (which aren't @@ -199,18 +177,6 @@ add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration) endif() -if (LIBUNWIND_ENABLE_WERROR) - add_compile_flags_if_supported(-Werror) - add_compile_flags_if_supported(-WX) -else() - add_compile_flags_if_supported(-Wno-error) - add_compile_flags_if_supported(-WX-) -endif() - -if (LIBUNWIND_ENABLE_PEDANTIC) - add_compile_flags_if_supported(-pedantic) -endif() - # Get feature flags. # Exceptions # Catches C++ exceptions only and tells the compiler to assume that extern C diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt --- a/libunwind/src/CMakeLists.txt +++ b/libunwind/src/CMakeLists.txt @@ -135,8 +135,11 @@ # ease, but does not rely on C++ at runtime. set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "") +include(WarningFlags) + # Build the shared library. add_library(unwind_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS}) +cxx_add_warning_flags(unwind_shared_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC}) if(CMAKE_C_COMPILER_ID STREQUAL MSVC) target_compile_options(unwind_shared_objects PRIVATE /GR-) else() @@ -174,6 +177,7 @@ # Build the static library. add_library(unwind_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS}) +cxx_add_warning_flags(unwind_static_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC}) if(CMAKE_C_COMPILER_ID STREQUAL MSVC) target_compile_options(unwind_static_objects PRIVATE /GR-) else() diff --git a/runtimes/cmake/Modules/WarningFlags.cmake b/runtimes/cmake/Modules/WarningFlags.cmake new file mode 100644 --- /dev/null +++ b/runtimes/cmake/Modules/WarningFlags.cmake @@ -0,0 +1,77 @@ +include(HandleFlags) + +# Warning flags =============================================================== +function(cxx_add_warning_flags target enable_werror enable_pedantic) + target_compile_definitions(${target} PUBLIC -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) + if (MSVC) + # -W4 is the cl.exe/clang-cl equivalent of -Wall. (In cl.exe and clang-cl, + # -Wall is equivalent to -Weverything in GCC style compiler drivers.) + target_add_compile_flags_if_supported(${target} PRIVATE -W4) + else() + target_add_compile_flags_if_supported(${target} PRIVATE -Wall) + endif() + # TODO: Should -Wconversion be enabled? + target_add_compile_flags_if_supported(${target} PRIVATE + -Wall + -Wextra + -Wnewline-eof + -Wshadow + -Wwrite-strings + -Wno-unused-parameter + -Wno-long-long + -Werror=return-type + -Wextra-semi + -Wundef + -Wformat-nonliteral + ) + + if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + target_add_compile_flags_if_supported(${target} PRIVATE + -Wno-user-defined-literals + -Wno-covered-switch-default + -Wno-suggest-override + ) + if (LIBCXX_TARGETING_CLANG_CL) + target_add_compile_flags_if_supported(${target} PRIVATE + -Wno-c++98-compat + -Wno-c++98-compat-pedantic + -Wno-c++11-compat + -Wno-undef + -Wno-reserved-id-macro + -Wno-gnu-include-next + -Wno-gcc-compat # For ignoring "'diagnose_if' is a clang extension" warnings + -Wno-zero-as-null-pointer-constant # FIXME: Remove this and fix all occurrences. + -Wno-deprecated-dynamic-exception-spec # For auto_ptr + -Wno-sign-conversion + -Wno-old-style-cast + -Wno-deprecated # FIXME: Remove this and fix all occurrences. + -Wno-shift-sign-overflow # FIXME: Why do we need this with clang-cl but not clang? + -Wno-double-promotion # FIXME: remove me + ) + endif() + + elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") + + target_add_compile_flags_if_supported(${target} PRIVATE + -Wstrict-aliasing=2 + -Wstrict-overflow=4 + -Wno-attributes + -Wno-literal-suffix + -Wno-c++14-compat + -Wno-noexcept-type + -Wno-suggest-override + ) + + endif() + if (${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 (${enable_pedantic}) + target_add_compile_flags_if_supported(${target} PRIVATE -pedantic) + endif() +endfunction()