Browse Source

chore(build): Migrate existing warning handling to new warnings project

reviewable/pr6551/r21
Anthony Bilinski 3 years ago
parent
commit
0afc11fafc
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 22
      CMakeLists.txt
  2. 17
      cmake/warnings/CMakeLists.txt

22
CMakeLists.txt

@ -31,7 +31,7 @@ option(SVGZ_ICON "Compress the SVG icon of qTox" ON) @@ -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") @@ -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() @@ -123,7 +104,6 @@ endif()
include(CheckAtomic)
# Use ccache when available to speed up builds.
if (USE_CCACHE)
find_program(CCACHE_FOUND ccache)

17
cmake/warnings/CMakeLists.txt

@ -11,6 +11,10 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") @@ -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
$<$<OR:$<BOOL:${CLANG}>,$<CXX_COMPILER_ID:GNU>>:
-fno-common;
@ -20,7 +24,6 @@ target_compile_options(${PROJECT_NAME} INTERFACE @@ -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 @@ -72,4 +75,16 @@ target_compile_options(${PROJECT_NAME} INTERFACE
# loss of data # This one is sort of required for gtest.
/WX;
>
$<$<BOOL:${STRICT_OPTIONS}>:
-Werror;
>
$<$<BOOL:${COMPILER_SUPPORTS_WARNING_WEAK_VTABLES}>:
-Wweak-vtables; # https://llvm.org/docs/CodingStandards.html#provide-a-virtual-method-anchor-for-classes-in-headers
>
$<$<BOOL:${COMPILER_SUPPORTS_WDATE_TIME}>:
-Wdate-time; # avoid timestamps in binary for reproducible builds, not added until GCC 4.9
>
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<NOT:$<BOOL:${HAIKU}>>>:
-Wstack-protector;
>
)

Loading…
Cancel
Save