1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

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

This commit is contained in:
Anthony Bilinski 2022-03-10 18:08:50 -08:00
parent df58c35998
commit 0afc11fafc
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
2 changed files with 17 additions and 22 deletions

View File

@ -31,7 +31,7 @@ option(SVGZ_ICON "Compress the SVG icon of qTox" ON)
option(ASAN "Compile with AddressSanitizer" OFF) option(ASAN "Compile with AddressSanitizer" OFF)
option(TSAN "Compile with ThreadSanitizer" OFF) option(TSAN "Compile with ThreadSanitizer" OFF)
option(DESKTOP_NOTIFICATIONS "Use snorenotify for desktop notifications" 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 # process generated files if cmake >= 3.10
if(POLICY CMP0071) if(POLICY CMP0071)
@ -93,27 +93,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
# Hardening flags (ASLR, warnings, etc) # Hardening flags (ASLR, warnings, etc)
set(POSITION_INDEPENDENT_CODE True) 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) if (NOT WIN32 AND NOT HAIKU)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wstack-protector")
endif() endif()
if (UNIX AND NOT APPLE) if (UNIX AND NOT APPLE)
@ -123,7 +104,6 @@ endif()
include(CheckAtomic) include(CheckAtomic)
# Use ccache when available to speed up builds. # Use ccache when available to speed up builds.
if (USE_CCACHE) if (USE_CCACHE)
find_program(CCACHE_FOUND ccache) find_program(CCACHE_FOUND ccache)

View File

@ -11,6 +11,10 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
endif() endif()
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 target_compile_options(${PROJECT_NAME} INTERFACE
$<$<OR:$<BOOL:${CLANG}>,$<CXX_COMPILER_ID:GNU>>: $<$<OR:$<BOOL:${CLANG}>,$<CXX_COMPILER_ID:GNU>>:
-fno-common; -fno-common;
@ -20,7 +24,6 @@ target_compile_options(${PROJECT_NAME} INTERFACE
-Wall; -Wall;
-Wcast-align; -Wcast-align;
-Wdouble-promotion; -Wdouble-promotion;
-Werror;
-Wextra; -Wextra;
-Wformat=2; -Wformat=2;
-Wmissing-declarations; -Wmissing-declarations;
@ -72,4 +75,16 @@ target_compile_options(${PROJECT_NAME} INTERFACE
# loss of data # This one is sort of required for gtest. # loss of data # This one is sort of required for gtest.
/WX; /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;
>
) )