This commit is contained in:
Erik Fröjdh 2021-10-12 11:42:02 +02:00 committed by GitHub
parent e84f5bec0b
commit 7426110e8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 35 deletions

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.12)
project(slsDetectorPackage) project(slsDetectorPackage)
set(PROJECT_VERSION 5.1.0) set(PROJECT_VERSION 6.0.0)
include(CheckIPOSupported)
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
cmake_policy(SET CMP0074 NEW) 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_DEVEL_HEADERS "install headers for devel" OFF)
option(SLS_USE_MOENCH "compile zmq and post processing for Moench" OFF) option(SLS_USE_MOENCH "compile zmq and post processing for Moench" OFF)
# set(ClangFormat_BIN_NAME clang-format)
set(ClangFormat_EXCLUDE_PATTERNS "build/" set(ClangFormat_EXCLUDE_PATTERNS "build/"
"libs/" "libs/"
"slsDetectorCalibration/" "slsDetectorCalibration/"
@ -66,6 +66,7 @@ set(ClangFormat_EXCLUDE_PATTERNS "build/"
find_package(ClangFormat) find_package(ClangFormat)
#Enable LTO if available #Enable LTO if available
include(CheckIPOSupported)
check_ipo_supported(RESULT SLS_LTO_AVAILABLE) check_ipo_supported(RESULT SLS_LTO_AVAILABLE)
message(STATUS "SLS_LTO_AVAILABLE:" ${SLS_LTO_AVAILABLE}) message(STATUS "SLS_LTO_AVAILABLE:" ${SLS_LTO_AVAILABLE})
@ -81,11 +82,11 @@ endif()
#Add two fake libraries to manage options #Add two fake libraries to manage options
add_library(slsProjectOptions INTERFACE) add_library(slsProjectOptions INTERFACE)
add_library(slsProjectWarnings 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 target_compile_options(slsProjectWarnings INTERFACE
-Wall -Wall
-Wextra -Wextra
-Wno-unused-parameter #Needs to be slowly mitigated -Wno-unused-parameter
# -Wold-style-cast # -Wold-style-cast
-Wnon-virtual-dtor -Wnon-virtual-dtor
-Woverloaded-virtual -Woverloaded-virtual
@ -96,13 +97,12 @@ target_compile_options(slsProjectWarnings INTERFACE
-Wvla -Wvla
-Wdouble-promotion -Wdouble-promotion
-Werror=return-type -Werror=return-type
) )
#Settings for C code #Settings for C code
add_library(slsProjectCSettings INTERFACE) add_library(slsProjectCSettings INTERFACE)
target_compile_features(slsProjectCSettings INTERFACE c_std_99)
target_compile_options(slsProjectCSettings INTERFACE target_compile_options(slsProjectCSettings INTERFACE
-std=gnu99 #fixed
-Wall -Wall
-Wextra -Wextra
-Wno-unused-parameter -Wno-unused-parameter
@ -119,35 +119,24 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.2) if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.2)
message(FATAL_ERROR "Clang version must be at least 3.2!") message(FATAL_ERROR "Clang version must be at least 3.2!")
endif() endif()
target_compile_options(slsProjectWarnings INTERFACE -Wshadow) #Clag does not warn on constructor
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
message(FATAL_ERROR "GCC version must be at least 4.8!") message(FATAL_ERROR "GCC version must be at least 4.8!")
endif() endif()
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5) if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
target_compile_options(slsProjectWarnings INTERFACE target_compile_options(slsProjectWarnings INTERFACE
-Wno-missing-field-initializers) -Wno-missing-field-initializers)
endif() 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() 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) if(SLS_USE_SANITIZER)
target_compile_options(slsProjectOptions INTERFACE -fsanitize=address,undefined -fno-omit-frame-pointer) target_compile_options(slsProjectOptions INTERFACE -fsanitize=address,undefined -fno-omit-frame-pointer)
target_link_libraries(slsProjectOptions INTERFACE -fsanitize=address,undefined) target_link_libraries(slsProjectOptions INTERFACE -fsanitize=address,undefined)
@ -193,8 +182,6 @@ if (NOT TARGET libzmq)
find_package(ZeroMQ 4 QUIET) find_package(ZeroMQ 4 QUIET)
endif() endif()
# libzmq autotools install: fallback to pkg-config # libzmq autotools install: fallback to pkg-config
if(NOT ZeroMQ_FOUND) if(NOT ZeroMQ_FOUND)
message(STATUS "CMake libzmq package not found, trying again with pkg-config (normal install of zeromq)") 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) endif(SLS_USE_TESTS)
# Common functionallity to detector and receiver # Common functionallity to detector and receiver
add_subdirectory(slsSupportLib) add_subdirectory(slsSupportLib)
@ -265,16 +250,12 @@ if(SLS_BUILD_DOCS)
add_subdirectory(docs) add_subdirectory(docs)
endif(SLS_BUILD_DOCS) endif(SLS_BUILD_DOCS)
if(SLS_USE_MOENCH) if(SLS_USE_MOENCH)
add_subdirectory(slsDetectorCalibration/moenchExecutables) add_subdirectory(slsDetectorCalibration/moenchExecutables)
endif(SLS_USE_MOENCH) endif(SLS_USE_MOENCH)
if(SLS_MASTER_PROJECT) if(SLS_MASTER_PROJECT)
# Set install dir CMake packages
set(CMAKE_INSTALL_DIR "share/cmake/${PROJECT_NAME}") set(CMAKE_INSTALL_DIR "share/cmake/${PROJECT_NAME}")
# Set the list of exported targets
set(PROJECT_LIBRARIES slsSupportShared slsDetectorShared slsReceiverShared) set(PROJECT_LIBRARIES slsSupportShared slsDetectorShared slsReceiverShared)
# Generate and install package config file and version
include(cmake/package_config.cmake) include(cmake/package_config.cmake)
endif() endif()

View File

@ -1,10 +1,64 @@
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
function(sls_add_flag_if_available flag target) include(CheckCCompilerFlag)
check_cxx_compiler_flag(${flag} flag_supported)
if(flag_supported)
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}) target_compile_options(${target} INTERFACE ${flag})
message("Adding: ${flag} to ${target}") message("Adding: ${flag} to ${target}")
else() else()
message("Flag: ${flag} not supported") message("Flag: ${flag} not supported")
endif() endif()
endfunction() 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()