From e924c3e655e111b54ba64339d48f04dc6dc50f33 Mon Sep 17 00:00:00 2001 From: Florian Uhlig <f.uhlig@gsi.de> Date: Thu, 31 Mar 2022 14:39:07 +0200 Subject: [PATCH] Fix compiler warnings when using Clang The KF and L1 packages set special compiler flags. Some of the warnings are not present when using Clang such that a CMake check was implemented which test the existense of those. The check simply compiles some C++ code with the compiler flag added to the compile command. Unfortunately Clang only prints a warning when a warning flag doesn't exist but successfuly finishes the compilation such that the check suceeds. This results in many warnings during compilation of L1. --- reco/KF/KF.cmake | 10 +++++----- reco/KF/KFParticleInterface.cmake | 14 +++++++------- reco/KF/KFQA.cmake | 14 +++++++------- reco/L1/CMakeLists.txt | 12 ++++-------- reco/eventbuilder/CMakeLists.txt | 4 ++-- 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/reco/KF/KF.cmake b/reco/KF/KF.cmake index a9c0b7e63a..53477deb37 100644 --- a/reco/KF/KF.cmake +++ b/reco/KF/KF.cmake @@ -122,22 +122,22 @@ Interface/CbmGlobalTrackFitterKF.h #CbmKFParticleInterface.h ) -If (APPLE) +If(CMAKE_CXX_COMPILER_ID MATCHES "Clang") ADD_DEFINITIONS(-Wall -Wsign-promo -Wctor-dtor-privacy -Wreorder -Wno-deprecated -Wno-parentheses -DDO_TPCCATRACKER_EFF_PERFORMANCE -DNonhomogeneousField -DCBM -DUSE_TIMERS) # -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual -Wold-style-cast : wait for other parts of cbmroot\root. #---Check for compiler flags - CHECK_CXX_COMPILER_FLAG("-Wno-pmf-conversions" HAS_PMF) + CHECK_CXX_COMPILER_FLAG("-Werror -Wno-pmf-conversions" HAS_PMF) If(HAS_PMF) ADD_DEFINITIONS(-Wno-pmf-conversions) EndIf() - CHECK_CXX_COMPILER_FLAG("-Wstrict-null-sentinel" HAS_SENTINEL) + CHECK_CXX_COMPILER_FLAG("-Werror -Wstrict-null-sentinel" HAS_SENTINEL) If(HAS_SENTINEL) ADD_DEFINITIONS(-Wstrict-null-sentinel) EndIf() - CHECK_CXX_COMPILER_FLAG("-Wno-non-template-friend" HAS_TEMPLATE_FRIEND) + CHECK_CXX_COMPILER_FLAG("-Werror -Wno-non-template-friend" HAS_TEMPLATE_FRIEND) If(HAS_TEMPLATE_FRIEND) ADD_DEFINITIONS(-Wno-non-template-friend) EndIf() - CHECK_CXX_COMPILER_FLAG("-Wno-pragmas" HAS_PRAGMA) + CHECK_CXX_COMPILER_FLAG("-Werror -Wno-pragmas" HAS_PRAGMA) If(HAS_PRAGMA) ADD_DEFINITIONS(-Wno-pragmas) EndIf() diff --git a/reco/KF/KFParticleInterface.cmake b/reco/KF/KFParticleInterface.cmake index a8efb56852..7fb7e1d11a 100644 --- a/reco/KF/KFParticleInterface.cmake +++ b/reco/KF/KFParticleInterface.cmake @@ -65,22 +65,22 @@ CbmKFParticleFinderQa.h CbmKFParticleInterface.h ) -If (APPLE) +If(CMAKE_CXX_COMPILER_ID MATCHES "Clang") ADD_DEFINITIONS(-Wall -Wsign-promo -Wctor-dtor-privacy -Wreorder -Wno-deprecated -Wno-parentheses -DDO_TPCCATRACKER_EFF_PERFORMANCE -DNonhomogeneousField -DCBM -DUSE_TIMERS) # -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual -Wold-style-cast : wait for other parts of cbmroot\root. #---Check for compiler flags - CHECK_CXX_COMPILER_FLAG("-Wno-pmf-conversions" HAS_PMF) + CHECK_CXX_COMPILER_FLAG("-Werror -Wno-pmf-conversions" HAS_PMF) If(HAS_PMF) ADD_DEFINITIONS(-Wno-pmf-conversions) EndIf() - CHECK_CXX_COMPILER_FLAG("-Wstrict-null-sentinel" HAS_SENTINEL) + CHECK_CXX_COMPILER_FLAG("-Werror -Wstrict-null-sentinel" HAS_SENTINEL) If(HAS_SENTINEL) ADD_DEFINITIONS(-Wstrict-null-sentinel) EndIf() - CHECK_CXX_COMPILER_FLAG("-Wno-non-template-friend" HAS_TEMPLATE_FRIEND) + CHECK_CXX_COMPILER_FLAG("-Werror -Wno-non-template-friend" HAS_TEMPLATE_FRIEND) If(HAS_TEMPLATE_FRIEND) ADD_DEFINITIONS(-Wno-non-template-friend) EndIf() - CHECK_CXX_COMPILER_FLAG("-Wno-pragmas" HAS_PRAGMA) + CHECK_CXX_COMPILER_FLAG("-Werror -Wno-pragmas" HAS_PRAGMA) If(HAS_PRAGMA) ADD_DEFINITIONS(-Wno-pragmas) EndIf() @@ -89,12 +89,12 @@ Else() EndIf() IF (SSE_FOUND) - Message(STATUS "KF will be compiled with SSE support") + Message(STATUS "KFParticleInterface will be compiled with SSE support") ADD_DEFINITIONS(-DHAVE_SSE) SET_SOURCE_FILES_PROPERTIES(${SRCS} PROPERTIES COMPILE_FLAGS "-msse -O3") ELSE (SSE_FOUND) - MESSAGE(STATUS "KF will be compiled without SSE support") + MESSAGE(STATUS "KFParticleInterface will be compiled without SSE support") SET_SOURCE_FILES_PROPERTIES(${SRCS} PROPERTIES COMPILE_FLAGS "-O3") ENDIF (SSE_FOUND) diff --git a/reco/KF/KFQA.cmake b/reco/KF/KFQA.cmake index f94bbe426f..339202e24f 100644 --- a/reco/KF/KFQA.cmake +++ b/reco/KF/KFQA.cmake @@ -66,22 +66,22 @@ KFQA/CbmKFPartEfficiencies.h KFQA/KFParticleMatch.h ) -If (APPLE) +If(CMAKE_CXX_COMPILER_ID MATCHES "Clang") ADD_DEFINITIONS(-Wall -Wsign-promo -Wctor-dtor-privacy -Wreorder -Wno-deprecated -Wno-parentheses -DDO_TPCCATRACKER_EFF_PERFORMANCE -DNonhomogeneousField -DCBM -DUSE_TIMERS) # -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual -Wold-style-cast : wait for other parts of cbmroot\root. #---Check for compiler flags - CHECK_CXX_COMPILER_FLAG("-Wno-pmf-conversions" HAS_PMF) + CHECK_CXX_COMPILER_FLAG("-Werror -Wno-pmf-conversions" HAS_PMF) If(HAS_PMF) ADD_DEFINITIONS(-Wno-pmf-conversions) EndIf() - CHECK_CXX_COMPILER_FLAG("-Wstrict-null-sentinel" HAS_SENTINEL) + CHECK_CXX_COMPILER_FLAG("-Werror -Wstrict-null-sentinel" HAS_SENTINEL) If(HAS_SENTINEL) ADD_DEFINITIONS(-Wstrict-null-sentinel) EndIf() - CHECK_CXX_COMPILER_FLAG("-Wno-non-template-friend" HAS_TEMPLATE_FRIEND) + CHECK_CXX_COMPILER_FLAG("-Werror -Wno-non-template-friend" HAS_TEMPLATE_FRIEND) If(HAS_TEMPLATE_FRIEND) ADD_DEFINITIONS(-Wno-non-template-friend) EndIf() - CHECK_CXX_COMPILER_FLAG("-Wno-pragmas" HAS_PRAGMA) + CHECK_CXX_COMPILER_FLAG("-Werror -Wno-pragmas" HAS_PRAGMA) If(HAS_PRAGMA) ADD_DEFINITIONS(-Wno-pragmas) EndIf() @@ -90,12 +90,12 @@ Else() EndIf() IF (SSE_FOUND) - Message(STATUS "KF will be compiled with SSE support") + Message(STATUS "KFQA will be compiled with SSE support") ADD_DEFINITIONS(-DHAVE_SSE) SET_SOURCE_FILES_PROPERTIES(${SRCS} PROPERTIES COMPILE_FLAGS "-msse -O3") ELSE (SSE_FOUND) - MESSAGE(STATUS "KF will be compiled without SSE support") + MESSAGE(STATUS "KFQA will be compiled without SSE support") SET_SOURCE_FILES_PROPERTIES(${SRCS} PROPERTIES COMPILE_FLAGS "-O3") ENDIF (SSE_FOUND) diff --git a/reco/L1/CMakeLists.txt b/reco/L1/CMakeLists.txt index 291f5f7ce2..e3d4cc9299 100644 --- a/reco/L1/CMakeLists.txt +++ b/reco/L1/CMakeLists.txt @@ -190,27 +190,23 @@ qa/CbmTrackerInputQaTrd.h -If(APPLE) +If(CMAKE_CXX_COMPILER_ID MATCHES "Clang") ADD_DEFINITIONS(-Wall -Wsign-promo -Wctor-dtor-privacy -Wreorder -Wno-deprecated -Wno-parentheses) # -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual -Wold-style-cast : wait for other parts of cbmroot\root. #-- - Check for compiler flags - CHECK_CXX_COMPILER_FLAG("-Wno-pmf-conversions" HAS_PMF) + CHECK_CXX_COMPILER_FLAG("-Werror -Wno-pmf-conversions" HAS_PMF) If(HAS_PMF) ADD_DEFINITIONS(-Wno-pmf-conversions) EndIf() - CHECK_CXX_COMPILER_FLAG("-Wstrict-null-sentinel" HAS_SENTINEL) + CHECK_CXX_COMPILER_FLAG("-Werror -Wstrict-null-sentinel" HAS_SENTINEL) If(HAS_SENTINEL) ADD_DEFINITIONS(-Wstrict-null-sentinel) EndIf() - CHECK_CXX_COMPILER_FLAG("-Wno-non-template-friend" HAS_TEMPLATE_FRIEND) + CHECK_CXX_COMPILER_FLAG("-Werror -Wno-non-template-friend" HAS_TEMPLATE_FRIEND) If(HAS_TEMPLATE_FRIEND) ADD_DEFINITIONS(-Wno-non-template-friend) EndIf() - - Else() - ADD_DEFINITIONS(-Wall -Wsign-promo -Wno-pmf-conversions -Wctor-dtor-privacy -Wreorder -Wno-deprecated -Wstrict-null-sentinel -Wno-non-template-friend -Wno-parentheses) # -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual -Wold-style-cast : wait for other parts of cbmroot\root. - EndIf() diff --git a/reco/eventbuilder/CMakeLists.txt b/reco/eventbuilder/CMakeLists.txt index 1008551332..9c19042b0d 100644 --- a/reco/eventbuilder/CMakeLists.txt +++ b/reco/eventbuilder/CMakeLists.txt @@ -79,9 +79,9 @@ IF (SSE_FOUND) ADD_DEFINITIONS(-DHAVE_SSE) SET_SOURCE_FILES_PROPERTIES(${SRCS} PROPERTIES COMPILE_FLAGS "-msse -O3") - Message(STATUS "L1 will be compiled with SSE support") + Message(STATUS "eventbuilder will be compiled with SSE support") ELSE (SSE_FOUND) - Message(STATUS "L1 will be compiled without SSE support") + Message(STATUS "eventbuilder will be compiled without SSE support") SET_SOURCE_FILES_PROPERTIES(${SRCS} PROPERTIES COMPILE_FLAGS "-O3") ENDIF (SSE_FOUND) -- GitLab