From bdb7bf71a8ed1cef055cdc50a648ce7cd3e33db8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 17 Apr 2019 12:19:12 +0200 Subject: [PATCH] Reduce warnings from moc-generated code - The auto-generated code produces a lot of warnings from Clang 8; this obscures the more meaningful warnings from actual Calamares code, so tone the warnings down. - For Clang, set CALAMARES_MOC_OPTIONS. - Add convenience CMake function for automoccing. It applies the options as needed to a given target. --- CMakeLists.txt | 3 +++ CMakeModules/CalamaresAddLibrary.cmake | 7 +++-- CMakeModules/CalamaresAutomoc.cmake | 36 ++++++++++++++++++++++++++ src/libcalamares/CMakeLists.txt | 4 +-- src/libcalamares/utils/moc-warnings.h | 4 +++ 5 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 CMakeModules/CalamaresAutomoc.cmake create mode 100644 src/libcalamares/utils/moc-warnings.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c9dddb547..ce627fc9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,6 +208,8 @@ if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) set( CMAKE_TOOLCHAIN_PREFIX "llvm-" ) set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined" ) + + set( CALAMARES_AUTOMOC_OPTIONS "-butils/moc-warnings.h" ) else() set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--no-undefined" ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--fatal-warnings -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type" ) @@ -509,6 +511,7 @@ install( "CMakeModules/CalamaresAddLibrary.cmake" "CMakeModules/CalamaresAddBrandingSubdirectory.cmake" "CMakeModules/CalamaresAddTranslations.cmake" + "CMakeModules/CalamaresAutomoc.cmake" "CMakeModules/CMakeColors.cmake" DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" diff --git a/CMakeModules/CalamaresAddLibrary.cmake b/CMakeModules/CalamaresAddLibrary.cmake index d5d734989..e731e2b15 100644 --- a/CMakeModules/CalamaresAddLibrary.cmake +++ b/CMakeModules/CalamaresAddLibrary.cmake @@ -44,6 +44,7 @@ # flag (i.e. `-D`) so only state the name (optionally, also the value) # without a `-D` prefixed to it. Pass in a CMake list as needed. include( CMakeParseArguments ) +include( CalamaresAutomoc ) function(calamares_add_library) # parse arguments (name needs to be saved before passing ARGN into the macro) @@ -81,10 +82,8 @@ function(calamares_add_library) add_library(${target} SHARED ${LIBRARY_SOURCES}) endif() - # definitions - can this be moved into set_target_properties below? - add_definitions(${QT_DEFINITIONS}) - set_target_properties(${target} PROPERTIES AUTOMOC TRUE) - + calamares_automoc(${target}) + if(LIBRARY_EXPORT_MACRO) set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS ${LIBRARY_EXPORT_MACRO}) endif() diff --git a/CMakeModules/CalamaresAutomoc.cmake b/CMakeModules/CalamaresAutomoc.cmake new file mode 100644 index 000000000..0ca5cd89a --- /dev/null +++ b/CMakeModules/CalamaresAutomoc.cmake @@ -0,0 +1,36 @@ +# === This file is part of Calamares - === +# +# Calamares is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Calamares is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Calamares. If not, see . +# +# SPDX-License-Identifier: GPL-3.0+ +# License-Filename: LICENSE +# +### +# +# Helper function for doing automoc on a target. +# +# Sets AUTOMOC TRUE for a target. +# +# If the global variable CALAMARES_AUTOMOC_OPTIONS is set, uses that +# as well to set options passed to MOC. This can be used to add +# libcalamares/utils/moc-warnings.h file to the moc, which in turn +# reduces compiler warnings in generated MOC code. +# + +function(calamares_automoc TARGET) + set_target_properties( ${TARGET} PROPERTIES AUTOMOC TRUE ) + if ( CALAMARES_AUTOMOC_OPTIONS ) + set_target_properties( ${TARGET} PROPERTIES AUTOMOC_MOC_OPTIONS "${CALAMARES_AUTOMOC_OPTIONS}" ) + endif() +endfunction() diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index a7dd1c0fe..340f8fe3b 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -84,10 +84,10 @@ endif() add_library( calamares SHARED ${libSources} ${kdsagSources} ${utilsSources} ) set_target_properties( calamares PROPERTIES - AUTOMOC TRUE VERSION ${CALAMARES_VERSION_SHORT} SOVERSION ${CALAMARES_VERSION_SHORT} ) +calamares_automoc( calamares ) target_link_libraries( calamares LINK_PRIVATE @@ -114,7 +114,7 @@ if ( ECM_FOUND AND BUILD_TESTING ) Qt5::Core Qt5::Test ) - set_target_properties( libcalamarestest PROPERTIES AUTOMOC TRUE ) + calamares_automoc( libcalamarestest ) endif() # Make symlink lib/calamares/libcalamares.so to lib/libcalamares.so.VERSION so diff --git a/src/libcalamares/utils/moc-warnings.h b/src/libcalamares/utils/moc-warnings.h new file mode 100644 index 000000000..b773c176b --- /dev/null +++ b/src/libcalamares/utils/moc-warnings.h @@ -0,0 +1,4 @@ +#ifdef __clang__ +#pragma clang diagnostic ignored "-Wextra-semi-stmt" +#pragma clang diagnostic ignored "-Wredundant-parens" +#endif