2020-09-21 19:41:28 +02:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
|
|
|
|
function(add_compile_options_safe FLAG)
|
|
|
|
check_cxx_compiler_flag(${FLAG} _has_flag)
|
|
|
|
if (_has_flag)
|
|
|
|
add_compile_options(${FLAG})
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2020-04-22 11:04:19 +02:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2020-05-27 05:15:46 +02:00
|
|
|
if(CMAKE_BUILD_TYPE MATCHES "Release")
|
|
|
|
# "Release" uses -O3 by default
|
|
|
|
add_compile_options(-O2)
|
2020-04-22 11:04:19 +02:00
|
|
|
endif()
|
|
|
|
if (WARNINGS_ARE_ERRORS)
|
|
|
|
add_compile_options(-Werror)
|
|
|
|
endif()
|
2020-09-21 19:41:28 +02:00
|
|
|
add_compile_options(-pedantic)
|
|
|
|
add_compile_options(-Wall)
|
|
|
|
add_compile_options(-Wextra)
|
2020-04-22 11:04:19 +02:00
|
|
|
add_compile_options(-Wcast-qual) # Cast for removing type qualifiers
|
|
|
|
add_compile_options(-Wno-deprecated-declarations)
|
|
|
|
add_compile_options(-Wfloat-equal) # Floating values used in equality comparisons
|
|
|
|
add_compile_options(-Wmissing-declarations) # If a global function is defined without a previous declaration
|
|
|
|
add_compile_options(-Wmissing-format-attribute) #
|
|
|
|
add_compile_options(-Wno-long-long)
|
|
|
|
add_compile_options(-Wpacked) #
|
|
|
|
add_compile_options(-Wredundant-decls) # if anything is declared more than once in the same scope
|
|
|
|
add_compile_options(-Wundef)
|
|
|
|
add_compile_options(-Wno-shadow) # whenever a local variable or type declaration shadows another one
|
|
|
|
add_compile_options(-Wno-missing-field-initializers)
|
|
|
|
add_compile_options(-Wno-missing-braces)
|
|
|
|
add_compile_options(-Wno-sign-compare)
|
|
|
|
add_compile_options(-Wno-multichar)
|
2020-09-21 19:41:28 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
|
|
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6)
|
|
|
|
message(FATAL_ERROR "${PROJECT_NAME} c++11 support requires g++ 4.6 or greater, but it is ${CMAKE_CXX_COMPILER_VERSION}")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
add_compile_options(-Woverloaded-virtual) # when a function declaration hides virtual functions from a base class
|
2020-08-21 17:17:49 +02:00
|
|
|
add_compile_options(-Wno-maybe-uninitialized) # there are some false positives
|
2020-04-22 11:04:19 +02:00
|
|
|
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
|
|
|
|
add_compile_options(-Wno-four-char-constants)
|
|
|
|
add_compile_options(-Wno-missing-braces)
|
|
|
|
add_compile_options(-Wno-unused-function)
|
2020-09-21 19:41:28 +02:00
|
|
|
add_compile_options_safe(-Wextra-semi-stmt)
|
2020-12-26 13:46:28 +01:00
|
|
|
add_compile_options_safe(-Wcomma)
|
2015-02-13 19:00:14 +01:00
|
|
|
|
|
|
|
if(ENABLE_COVERAGE OR ENABLE_COVERAGE_XML)
|
2020-09-21 19:41:28 +02:00
|
|
|
message(FATAL_ERROR "Do not use clang for generate code coverage. Use gcc.")
|
2015-02-13 19:00:14 +01:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2020-05-23 17:42:56 +02:00
|
|
|
if (MSVC)
|
|
|
|
add_compile_options(/W4)
|
|
|
|
add_compile_options(/wd4018) # warning C4018: '>': signed/unsigned mismatch
|
|
|
|
add_compile_options(/wd4127) # warning C4127: conditional expression is constant
|
|
|
|
add_compile_options(/wd4244) # warning C4244: 'initializing': conversion from 'int' to 'char', possible loss of data
|
|
|
|
add_compile_options(/wd4251)
|
|
|
|
# Clang: -Wshorten-64-to-32 -Wimplicit-int-conversion
|
|
|
|
add_compile_options(/wd4267) # warning C4267: 'return': conversion from 'size_t' to 'int', possible loss of data
|
|
|
|
add_compile_options(/wd4389) # warning C4389: '==': signed/unsigned mismatch
|
|
|
|
add_compile_options(/wd4482)
|
|
|
|
add_compile_options(/wd4512)
|
|
|
|
add_compile_options(/wd4701) # warning C4701: potentially uninitialized local variable 'err' used
|
|
|
|
add_compile_options(/wd4706) # warning C4706: assignment within conditional expression
|
|
|
|
add_compile_options(/wd4800) # warning C4800: 'const SymbolDatabase *' : forcing value to bool 'true' or 'false' (performance warning)
|
|
|
|
|
|
|
|
if (WARNINGS_ARE_ERRORS)
|
|
|
|
add_compile_options(/WX)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2020-04-22 11:04:19 +02:00
|
|
|
# TODO: check if this can be enabled again - also done in Makefile
|
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES "Linux" AND
|
|
|
|
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2015-11-26 21:13:04 +01:00
|
|
|
|
2020-04-22 11:04:19 +02:00
|
|
|
add_compile_options(-U_GLIBCXX_DEBUG)
|
2015-11-26 21:13:04 +01:00
|
|
|
endif()
|
|
|
|
|
2019-07-15 12:39:58 +02:00
|
|
|
if (MSVC)
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:8000000")
|
|
|
|
endif()
|
|
|
|
|
2020-03-03 18:37:49 +01:00
|
|
|
if (CYGWIN)
|
2020-04-22 11:04:19 +02:00
|
|
|
# TODO: this is a linker flag - not a compiler flag
|
|
|
|
add_compile_options(-Wl,--stack,8388608)
|
2020-03-03 18:37:49 +01:00
|
|
|
endif()
|
|
|
|
|
2020-04-22 11:04:19 +02:00
|
|
|
include(cmake/dynamic_analyzer_options.cmake)
|