diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,8 @@ include(KDEInstallDirs) include(KDECMakeSettings) +include(KDevelopMacrosInternal) + if(POLICY CMP0071) # CMake 3.10 generates warnings when projects combine AUTOMOC with qt5_wrap_ui() or qt5_add_resources() # Avoid that by setting this policy (cf. https://bugreports.qt.io/browse/QTBUG-63442) @@ -112,17 +114,6 @@ -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT ) -function(add_compile_flag_if_supported _flag) - unset(_have_flag CACHE) - string(REGEX REPLACE "[-=]" "_" _varname ${_flag}) - string(TOUPPER ${_varname} _varname) - set(_varname "HAVE${_varname}") - check_cxx_compiler_flag("${_flag}" "${_varname}") - if (${${_varname}}) - add_compile_options(${_flag}) - endif() -endfunction() - # Turn off missing-field-initializers warning for GCC to avoid noise from false positives with empty {} # See discussion: http://mail.kde.org/pipermail/kdevelop-devel/2014-February/046910.html add_compile_flag_if_supported(-Wno-missing-field-initializers) @@ -135,8 +126,12 @@ # This warning is triggered by every call to qCDebug() add_compile_flag_if_supported(-Wno-gnu-zero-variadic-macro-arguments) endif() -if (CMAKE_COMPILER_CXX_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_flag_if_supported(-pedantic) + add_compile_flag_if_supported(-Wzero-as-null-pointer-constant CXX_ONLY) +endif() +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_compile_flag_if_supported(-Wsuggest-override CXX_ONLY) endif() include_directories(${KDevelop_SOURCE_DIR} ${KDevelop_BINARY_DIR}) diff --git a/cmake/modules/KDevelopMacrosInternal.cmake b/cmake/modules/KDevelopMacrosInternal.cmake new file mode 100644 --- /dev/null +++ b/cmake/modules/KDevelopMacrosInternal.cmake @@ -0,0 +1,59 @@ +# +# KDevelop Private Macros +# +# The following macros are defined here: +# +# add_compile_flag_if_supported( [CXX_ONLY]) +# add_target_compile_flag_if_supported( ) +# +#============================================================================= +# Copyright 2018 Friedrich W. H. Kossebau +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= + + +# helper method to ensure consistent cache var names +function(_varname_for_compile_flag_check_result _varname _flag ) + string(REGEX REPLACE "[-=]" "_" _varname ${_flag}) + string(TOUPPER ${_varname} _varname) + set(_varname "KDEV_HAVE${_varname}" PARENT_SCOPE) +endfunction() + + +# add_compile_flag_if_supported( [CXX_ONLY]) +# Optional argument CXX_ONLY to set the flag only for C++ code. +# +# Example: +# add_compile_flag_if_supported(-Wsuggest-override CXX_ONLY) +function(add_compile_flag_if_supported _flag) + _varname_for_compile_flag_check_result(_varname ${_flag}) + check_cxx_compiler_flag("${_flag}" "${_varname}") + + if (${${_varname}}) + if("${ARGV1}" STREQUAL "CXX_ONLY") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}" PARENT_SCOPE) + else() + add_compile_options(${_flag}) + endif() + endif() +endfunction() + + +# add_target_compile_flag_if_supported( ) +# +# Example: +# add_target_compile_flag_if_supported(kdevqtc-qmlsupport PRIVATE "-Wno-suggest-override") +function(add_target_compile_flag_if_supported _target _scope _flag) + _varname_for_compile_flag_check_result(_varname ${_flag}) + check_cxx_compiler_flag("${_flag}" "${_varname}") + + if (${${_varname}}) + target_compile_options(${_target} ${_scope} "${_flag}") + endif() +endfunction() diff --git a/plugins/astyle/3rdparty/libastyle/CMakeLists.txt b/plugins/astyle/3rdparty/libastyle/CMakeLists.txt --- a/plugins/astyle/3rdparty/libastyle/CMakeLists.txt +++ b/plugins/astyle/3rdparty/libastyle/CMakeLists.txt @@ -7,7 +7,16 @@ ) add_library(astylelib STATIC ${astylelib_SRCS}) set_property(TARGET astylelib PROPERTY POSITION_INDEPENDENT_CODE ON) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # astyle lib throws lots of warnings with -Wdocumentation - target_compile_options(astylelib PRIVATE "-Wno-documentation") + add_target_compile_flag_if_supported(astylelib PRIVATE "-Wno-documentation") endif() +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_target_compile_flag_if_supported(astylelib PRIVATE "-Wno-zero-as-null-pointer-constant") +endif() +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_target_compile_flag_if_supported(astylelib PRIVATE "-Wno-suggest-override") +endif() +# add as SYSTEM include dir so compiler does not emit warnings for the lib headers +target_include_directories(astylelib SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/plugins/qmljs/3rdparty/qtcreator-libs/CMakeLists.txt b/plugins/qmljs/3rdparty/qtcreator-libs/CMakeLists.txt --- a/plugins/qmljs/3rdparty/qtcreator-libs/CMakeLists.txt +++ b/plugins/qmljs/3rdparty/qtcreator-libs/CMakeLists.txt @@ -51,16 +51,19 @@ target_link_libraries(kdevqtc-qmlsupport LINK_PRIVATE "-framework Foundation" ) endif() -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0") - target_compile_options(kdevqtc-qmlsupport PRIVATE "-Wno-class-memaccess") - endif() -endif() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - target_compile_options(kdevqtc-qmlsupport PRIVATE "-Wno-documentation") + add_target_compile_flag_if_supported(kdevqtc-qmlsupport PRIVATE "-Wno-documentation") +endif() +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_target_compile_flag_if_supported(kdevqtc-qmlsupport PRIVATE "-Wno-zero-as-null-pointer-constant") +endif() +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_target_compile_flag_if_supported(kdevqtc-qmlsupport PRIVATE "-Wno-suggest-override") + add_target_compile_flag_if_supported(kdevqtc-qmlsupport PRIVATE "-Wno-class-memaccess") endif() target_compile_definitions(kdevqtc-qmlsupport PUBLIC -DLANGUAGEUTILS_BUILD_DIR -DQTCREATOR_UTILS_LIB -DQT_CREATOR -DQML_BUILD_STATIC_LIB) -target_include_directories(kdevqtc-qmlsupport PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +# add as SYSTEM include dir so compiler does not emit warnings for the lib headers +target_include_directories(kdevqtc-qmlsupport SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(kdevqtc-qmlsupport LINK_PRIVATE Qt5::Core Qt5::Gui diff --git a/plugins/subversion/3rdparty/CMakeLists.txt b/plugins/subversion/3rdparty/CMakeLists.txt --- a/plugins/subversion/3rdparty/CMakeLists.txt +++ b/plugins/subversion/3rdparty/CMakeLists.txt @@ -27,7 +27,7 @@ ) set_property(TARGET kdevsvncpp PROPERTY POSITION_INDEPENDENT_CODE ON) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - target_compile_options(kdevsvncpp PRIVATE "-Wno-documentation") + add_target_compile_flag_if_supported(kdevsvncpp PRIVATE "-Wno-documentation") endif() target_include_directories(kdevsvncpp PRIVATE kdevsvncpp