diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a41e5182..bf7e8d36f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ option(SVGZ_ICON "Compress the SVG icon of qTox" ON) option(ASAN "Compile with AddressSanitizer" OFF) option(TSAN "Compile with ThreadSanitizer" OFF) option(DESKTOP_NOTIFICATIONS "Use snorenotify for desktop notifications" OFF) -option(STRICT_OPTIONS "Enable strict compile options, used by CI" OFF) +option(STRICT_OPTIONS "Error on compile warning, used by CI" OFF) # process generated files if cmake >= 3.10 if(POLICY CMP0071) @@ -93,27 +93,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") # Hardening flags (ASLR, warnings, etc) set(POSITION_INDEPENDENT_CODE True) -include(CheckCXXCompilerFlag) -CHECK_CXX_COMPILER_FLAG(-Wweak-vtables COMPILER_SUPPORTS_WARNING_WEAK_VTABLES) -if(COMPILER_SUPPORTS_WARNING_WEAK_VTABLES) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wweak-vtables") -endif() - -# Extra-strict compile options that we don't want to subject all users to by default -if (STRICT_OPTIONS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") -endif() - -# avoid timestamps in binary for reproducible builds, not added until GCC 4.9 -include(CheckCXXCompilerFlag) -CHECK_CXX_COMPILER_FLAG(-Wdate-time COMPILER_SUPPORTS_WDATE_TIME) -if (COMPILER_SUPPORTS_WDATE_TIME) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdate-time") -endif() - if (NOT WIN32 AND NOT HAIKU) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wstack-protector") endif() if (UNIX AND NOT APPLE) @@ -123,7 +104,6 @@ endif() include(CheckAtomic) - # Use ccache when available to speed up builds. if (USE_CCACHE) find_program(CCACHE_FOUND ccache) diff --git a/cmake/warnings/CMakeLists.txt b/cmake/warnings/CMakeLists.txt index dccf95fda..ed1d5f1e8 100644 --- a/cmake/warnings/CMakeLists.txt +++ b/cmake/warnings/CMakeLists.txt @@ -11,6 +11,10 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") endif() endif() +include(CheckCXXCompilerFlag) +CHECK_CXX_COMPILER_FLAG(-Wweak-vtables COMPILER_SUPPORTS_WARNING_WEAK_VTABLES) +CHECK_CXX_COMPILER_FLAG(-Wdate-time COMPILER_SUPPORTS_WDATE_TIME) + target_compile_options(${PROJECT_NAME} INTERFACE $<$,$>: -fno-common; @@ -20,7 +24,6 @@ target_compile_options(${PROJECT_NAME} INTERFACE -Wall; -Wcast-align; -Wdouble-promotion; - -Werror; -Wextra; -Wformat=2; -Wmissing-declarations; @@ -72,4 +75,16 @@ target_compile_options(${PROJECT_NAME} INTERFACE # loss of data # This one is sort of required for gtest. /WX; > + $<$: + -Werror; + > + $<$: + -Wweak-vtables; # https://llvm.org/docs/CodingStandards.html#provide-a-virtual-method-anchor-for-classes-in-headers + > + $<$: + -Wdate-time; # avoid timestamps in binary for reproducible builds, not added until GCC 4.9 + > + $<$>,$>>: + -Wstack-protector; + > )