mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-22 11:50:03 +02:00
Warnings (#313)
This commit is contained in:
parent
e84f5bec0b
commit
7426110e8a
@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(slsDetectorPackage)
|
||||
set(PROJECT_VERSION 5.1.0)
|
||||
include(CheckIPOSupported)
|
||||
set(PROJECT_VERSION 6.0.0)
|
||||
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
|
||||
|
||||
cmake_policy(SET CMP0074 NEW)
|
||||
@ -54,7 +54,7 @@ option(SLS_TUNE_LOCAL "tune to local machine" OFF)
|
||||
option(SLS_DEVEL_HEADERS "install headers for devel" OFF)
|
||||
option(SLS_USE_MOENCH "compile zmq and post processing for Moench" OFF)
|
||||
|
||||
# set(ClangFormat_BIN_NAME clang-format)
|
||||
|
||||
set(ClangFormat_EXCLUDE_PATTERNS "build/"
|
||||
"libs/"
|
||||
"slsDetectorCalibration/"
|
||||
@ -66,6 +66,7 @@ set(ClangFormat_EXCLUDE_PATTERNS "build/"
|
||||
find_package(ClangFormat)
|
||||
|
||||
#Enable LTO if available
|
||||
include(CheckIPOSupported)
|
||||
check_ipo_supported(RESULT SLS_LTO_AVAILABLE)
|
||||
message(STATUS "SLS_LTO_AVAILABLE:" ${SLS_LTO_AVAILABLE})
|
||||
|
||||
@ -81,11 +82,11 @@ endif()
|
||||
#Add two fake libraries to manage options
|
||||
add_library(slsProjectOptions INTERFACE)
|
||||
add_library(slsProjectWarnings INTERFACE)
|
||||
target_compile_features(slsProjectOptions INTERFACE cxx_std_11)
|
||||
target_compile_options(slsProjectOptions INTERFACE -std=gnu++11)
|
||||
target_compile_options(slsProjectWarnings INTERFACE
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wno-unused-parameter #Needs to be slowly mitigated
|
||||
-Wno-unused-parameter
|
||||
# -Wold-style-cast
|
||||
-Wnon-virtual-dtor
|
||||
-Woverloaded-virtual
|
||||
@ -96,13 +97,12 @@ target_compile_options(slsProjectWarnings INTERFACE
|
||||
-Wvla
|
||||
-Wdouble-promotion
|
||||
-Werror=return-type
|
||||
|
||||
)
|
||||
|
||||
#Settings for C code
|
||||
add_library(slsProjectCSettings INTERFACE)
|
||||
target_compile_features(slsProjectCSettings INTERFACE c_std_99)
|
||||
target_compile_options(slsProjectCSettings INTERFACE
|
||||
-std=gnu99 #fixed
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wno-unused-parameter
|
||||
@ -119,35 +119,24 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.2)
|
||||
message(FATAL_ERROR "Clang version must be at least 3.2!")
|
||||
endif()
|
||||
target_compile_options(slsProjectWarnings INTERFACE -Wshadow) #Clag does not warn on constructor
|
||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
|
||||
message(FATAL_ERROR "GCC version must be at least 4.8!")
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
|
||||
target_compile_options(slsProjectWarnings INTERFACE
|
||||
-Wno-missing-field-initializers)
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0)
|
||||
target_compile_options(slsProjectWarnings INTERFACE
|
||||
-Wno-misleading-indentation # mostly in rapidjson remove using clang format
|
||||
-Wduplicated-cond
|
||||
-Wnull-dereference )
|
||||
|
||||
endif()
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0)
|
||||
target_compile_options(slsProjectWarnings INTERFACE
|
||||
-Wno-class-memaccess )
|
||||
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Add or disable warnings depending on if the compiler supports them
|
||||
# The function checks internally and sets HAS_warning-name
|
||||
sls_enable_cxx_warning("-Wnull-dereference")
|
||||
sls_enable_cxx_warning("-Wduplicated-cond")
|
||||
sls_disable_cxx_warning("-Wclass-memaccess")
|
||||
sls_disable_c_warning("-Wstringop-truncation")
|
||||
|
||||
|
||||
sls_add_flag_if_available("-Wno-stringop-truncation" slsProjectCSettings)
|
||||
|
||||
if(SLS_USE_SANITIZER)
|
||||
target_compile_options(slsProjectOptions INTERFACE -fsanitize=address,undefined -fno-omit-frame-pointer)
|
||||
target_link_libraries(slsProjectOptions INTERFACE -fsanitize=address,undefined)
|
||||
@ -193,8 +182,6 @@ if (NOT TARGET libzmq)
|
||||
find_package(ZeroMQ 4 QUIET)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
# libzmq autotools install: fallback to pkg-config
|
||||
if(NOT ZeroMQ_FOUND)
|
||||
message(STATUS "CMake libzmq package not found, trying again with pkg-config (normal install of zeromq)")
|
||||
@ -218,8 +205,6 @@ if (SLS_USE_TESTS)
|
||||
endif(SLS_USE_TESTS)
|
||||
|
||||
|
||||
|
||||
|
||||
# Common functionallity to detector and receiver
|
||||
add_subdirectory(slsSupportLib)
|
||||
|
||||
@ -265,16 +250,12 @@ if(SLS_BUILD_DOCS)
|
||||
add_subdirectory(docs)
|
||||
endif(SLS_BUILD_DOCS)
|
||||
|
||||
|
||||
if(SLS_USE_MOENCH)
|
||||
add_subdirectory(slsDetectorCalibration/moenchExecutables)
|
||||
endif(SLS_USE_MOENCH)
|
||||
|
||||
if(SLS_MASTER_PROJECT)
|
||||
# Set install dir CMake packages
|
||||
set(CMAKE_INSTALL_DIR "share/cmake/${PROJECT_NAME}")
|
||||
# Set the list of exported targets
|
||||
set(PROJECT_LIBRARIES slsSupportShared slsDetectorShared slsReceiverShared)
|
||||
# Generate and install package config file and version
|
||||
include(cmake/package_config.cmake)
|
||||
endif()
|
||||
|
@ -1,10 +1,64 @@
|
||||
include(CheckCXXCompilerFlag)
|
||||
function(sls_add_flag_if_available flag target)
|
||||
check_cxx_compiler_flag(${flag} flag_supported)
|
||||
if(flag_supported)
|
||||
include(CheckCCompilerFlag)
|
||||
|
||||
|
||||
function(enable_cxx_warning flag target)
|
||||
string(REPLACE "-W" "HAS_" flag_name ${flag})
|
||||
check_cxx_compiler_flag(${flag} ${flag_name})
|
||||
if(${flag_name})
|
||||
target_compile_options(${target} INTERFACE ${flag})
|
||||
message("Adding: ${flag} to ${target}")
|
||||
else()
|
||||
message("Flag: ${flag} not supported")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(enable_c_warning flag target)
|
||||
string(REPLACE "-W" "HAS_" flag_name ${flag})
|
||||
check_c_compiler_flag(${flag} ${flag_name})
|
||||
if(${flag_name})
|
||||
target_compile_options(${target} INTERFACE ${flag})
|
||||
message("Adding: ${flag} to ${target}")
|
||||
else()
|
||||
message("Flag: ${flag} not supported")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
||||
function(disable_cxx_warning flag target)
|
||||
string(REPLACE "-W" "HAS_" flag_name ${flag})
|
||||
check_cxx_compiler_flag(${flag} ${flag_name})
|
||||
|
||||
if(${flag_name})
|
||||
string(REPLACE "-W" "-Wno-" neg_flag ${flag})
|
||||
message("Adding: ${neg_flag} to ${target}")
|
||||
target_compile_options(${target} INTERFACE ${neg_flag})
|
||||
else()
|
||||
message("Warning: ${flag} not supported no need to disable")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(disable_c_warning flag target)
|
||||
string(REPLACE "-W" "HAS_" flag_name ${flag})
|
||||
check_c_compiler_flag(${flag} ${flag_name})
|
||||
if(${flag_name})
|
||||
string(REPLACE "-W" "-Wno-" neg_flag ${flag})
|
||||
message("Adding: ${neg_flag} to ${target}")
|
||||
target_compile_options(${target} INTERFACE ${neg_flag})
|
||||
else()
|
||||
message("Warning: ${flag} not supported no need to disable")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
||||
function(sls_disable_c_warning flag)
|
||||
disable_c_warning(${flag} slsProjectCSettings)
|
||||
endfunction()
|
||||
|
||||
function(sls_enable_cxx_warning flag)
|
||||
enable_cxx_warning(${flag} slsProjectWarnings)
|
||||
endfunction()
|
||||
|
||||
function(sls_disable_cxx_warning flag)
|
||||
disable_cxx_warning(${flag} slsProjectWarnings)
|
||||
endfunction()
|
Loading…
x
Reference in New Issue
Block a user