Commit 648c2080 authored by GILLES Sebastien's avatar GILLES Sebastien

#1217 Cmake: Add warnings depending on compiler family.

parent 5bed9cdb
# A minimum version for cmake command is required.
cmake_minimum_required(VERSION 3.8)
# IF(DEFINED CMAKE_BUILD_TYPE)
# SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of
# build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug
# Release RelWithDebInfo MinSizeRel.")
# ELSE()
# SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build,
# options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release
# RelWithDebInfo MinSizeRel.")
# ENDIF()
# TODO Add check whether the provided value is valid.
# From https://cmake.org/pipermail/cmake/2008-September/023808.html
if(DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of
build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug
Release RelWithDebInfo MinSizeRel.")
else()
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build,
options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release
RelWithDebInfo MinSizeRel.")
endif()
project( "MoReFEM_CMAKE")
......@@ -44,7 +46,13 @@ endif()
MESSAGE("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}")
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} --my-debug-flags")
include(compiler)
message("CMAKE_C_COMPILER " ${CMAKE_C_COMPILER})
message("CMAKE_C_COMPILER_ID" ${CMAKE_C_COMPILER_ID})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Sources /
${CMAKE_CURRENT_SOURCE_DIR}/Sources/ThirdParty/Source/Tclap/include /
......
message(STATUS "C compiler identifier found to be ${CMAKE_C_COMPILER_ID}; settings (warnings, STL, etc...) will be set accordingly.")
if(${CMAKE_C_COMPILER_ID} STREQUAL "AppleClang" OR ${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
add_cxx_compiler_flag("-Weverything")
add_cxx_compiler_flag("-Wno-c++98-compat")
add_cxx_compiler_flag("-Wno-c++98-compat-pedantic")
add_cxx_compiler_flag("-Wno-padded")
add_cxx_compiler_flag("-Wno-exit-time-destructors")
add_cxx_compiler_flag("-Wno-global-constructors")
add_cxx_compiler_flag("-Wno-documentation")
add_cxx_compiler_flag("-Wno-documentation-unknown-command")
add_cxx_compiler_flag("-Wno-undefined-func-template")
add_cxx_compiler_flag("-Wno-c++1z-extensions')")
add_cxx_compiler_flag("-stdlib=libc++")
elseif(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
add_cxx_compiler_flag("-Wall")
add_cxx_compiler_flag("-Wextra")
#add_cxx_compiler_flag("-Wpedantic") Can't be activated because of third-party error; pragma doesn't work to disable it only for third party.
add_cxx_compiler_flag("-Wcast-align")
add_cxx_compiler_flag("-Wcast-qual")
add_cxx_compiler_flag("-Wconversion")
add_cxx_compiler_flag("-Wdisabled-optimization")
add_cxx_compiler_flag("-Wfloat-equal")
add_cxx_compiler_flag("-Wformat=2")
add_cxx_compiler_flag("-Wformat-nonliteral")
add_cxx_compiler_flag("-Wformat-security")
add_cxx_compiler_flag("-Wformat-y2k")
add_cxx_compiler_flag("-Wimport")
add_cxx_compiler_flag("-Winit-self")
# add_cxx_compiler_flag("-Winline") Tag destructor defined with = default as inline...
add_cxx_compiler_flag("-Winvalid-pch")
add_cxx_compiler_flag("-Wmissing-field-initializers")
add_cxx_compiler_flag("-Wmissing-format-attribute")
add_cxx_compiler_flag("-Wmissing-include-dirs")
add_cxx_compiler_flag("-Wmissing-noreturn")
add_cxx_compiler_flag("-Wpacked")
add_cxx_compiler_flag("-Wpointer-arith")
add_cxx_compiler_flag("-Wredundant-decls")
# add_cxx_compiler_flag("-Wshadow") g++ shadow is too cumbersome: can't name function argument same as a method for instance...
add_cxx_compiler_flag("-Wstack-protector")
add_cxx_compiler_flag("-Wstrict-aliasing=2")
add_cxx_compiler_flag("-Wswitch-enum")
add_cxx_compiler_flag("-Wunreachable-code")
add_cxx_compiler_flag("-Wunused")
add_cxx_compiler_flag("-Wunused-parameter")
add_cxx_compiler_flag("-Wvariadic-macros")
add_cxx_compiler_flag("-Wwrite-strings")
else()
message(FATAL_ERROR "Sorry, your compiler family wasn't recognized. If CMake has updated its flag, please modify the cmake/Compiler.cmake file in MoReFEM accoerdingly. See CMAKE_LANG_COMPILER_ID in CMake tutorial to find out the valid options.")
endif()
include(TestCXXAcceptsFlag)
# add a compiler flag only if it is accepted
macro(add_cxx_compiler_flag _flag)
string(REPLACE "-" "_" _flag_var ${_flag})
......@@ -8,6 +11,15 @@ macro(add_cxx_compiler_flag _flag)
endmacro()
macro(add_c_compiler_flag _flag)
string(REPLACE "-" "_" _flag_var ${_flag})
check_c_accepts_flag("${_flag}" C_COMPILER_${_flag_var}_OK)
if(C_COMPILER_${_flag_var}_OK)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flag}")
endif()
endmacro()
##########################################################################################
#
# Find a library and store it in _macro; if not a message error is issued.
......@@ -21,8 +33,6 @@ endmacro()
##########################################################################################
function(morefem_find_library _macro _libnames _dir _name)
MESSAGE("ARGS: ${_macro} | ${_libnames} | ${_dir} | ${_name}")
find_library(${_macro} ${_libnames} PATHS ${_dir} NO_DEFAULT_PATH)
if (NOT ${_macro})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment