forked from asmaloney/GDExtensionTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompilerWarnings.cmake
115 lines (98 loc) · 3.78 KB
/
CompilerWarnings.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# SPDX-License-Identifier: Unlicense
# by Andy Maloney <[email protected]>
string( TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPERCASE )
if ( NOT MSVC )
option( ${PROJECT_NAME_UPPERCASE}_WARN_EVERYTHING "Turn on all warnings (not recommended - used for lib development)" OFF )
endif()
option( ${PROJECT_NAME_UPPERCASE}_WARNING_AS_ERROR "Treat warnings as errors" ON )
# Add warnings based on compiler
# Set some helper variables for readability
set( compiler_is_clang "$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:Clang>>" )
set( compiler_is_gnu "$<CXX_COMPILER_ID:GNU>" )
set( compiler_is_msvc "$<CXX_COMPILER_ID:MSVC>" )
target_compile_options( ${PROJECT_NAME}
PRIVATE
# MSVC only
$<${compiler_is_msvc}:
/W4
/w14263 # 'function': member function does not override any base class virtual member function
/w14296 # 'operator': expression is always 'boolean_value'
/w14311 # 'variable': pointer truncation from 'type1' to 'type2'
/w14545 # expression before comma evaluates to a function which is missing an argument list
/w14546 # function call before comma missing argument list
/w14547 # 'operator': operator before comma has no effect; expected operator with side-effect
/w14549 # 'operator': operator before comma has no effect; did you intend 'operator'?
/w14619 # pragma warning: there is no warning number 'number'
/w14640 # thread un-safe static member initialization
/w14905 # wide string literal cast to 'LPSTR'
/w14906 # string literal cast to 'LPWSTR'
# Disable warnings which bleed through from godot-cpp's macros.
/wd4100 # unreferenced formal parameter
>
# Clang and GNU
$<$<OR:${compiler_is_clang},${compiler_is_gnu}>:
-Wall
-Wcast-align
-Wctor-dtor-privacy
-Wextra
-Wformat=2
-Wnon-virtual-dtor
-Wnull-dereference
-Woverloaded-virtual
-Wpedantic
-Wshadow
-Wunused
-Wwrite-strings
# Disable warnings which bleed through from godot-cpp's macros.
-Wno-unused-parameter
>
# Clang only
$<${compiler_is_clang}:
-Wdocumentation
-Wimplicit-fallthrough
>
# GNU only
$<${compiler_is_gnu}:
-Walloc-zero
-Wduplicated-branches
-Wduplicated-cond
-Wlogical-op
>
)
# Turn on (almost) all warnings on Clang, Apple Clang, and GNU.
# Useful for internal development, but too noisy for general development.
function( set_warn_everything )
message( STATUS "[${PROJECT_NAME}] Turning on (almost) all warnings")
target_compile_options( ${PROJECT_NAME}
PRIVATE
# Clang and GNU
$<$<OR:${compiler_is_clang},${compiler_is_gnu}>:
-Weverything
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-padded
>
)
endfunction()
if ( NOT MSVC AND ${PROJECT_NAME_UPPERCASE}_WARN_EVERYTHING )
set_warn_everything()
endif()
# Treat warnings as errors
function( set_warning_as_error )
message( STATUS "[${PROJECT_NAME}] Treating warnings as errors")
if ( CMAKE_VERSION VERSION_GREATER_EQUAL "3.24" )
set_target_properties( ${PROJECT_NAME}
PROPERTIES
COMPILE_WARNING_AS_ERROR ON
)
else()
target_compile_options( ${PROJECT_NAME}
PRIVATE
$<${compiler_is_msvc}:/WX>
$<$<OR:${compiler_is_clang},${compiler_is_gnu}>:-Werror>
)
endif()
endfunction()
if ( ${PROJECT_NAME_UPPERCASE}_WARNING_AS_ERROR )
set_warning_as_error()
endif()