forked from Ableton/link
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigureCompileFlags.cmake
160 lines (143 loc) · 6.01 KB
/
ConfigureCompileFlags.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
cmake_minimum_required(VERSION 3.0)
set(build_flags_COMMON_LIST)
set(build_flags_DEBUG_LIST)
set(build_flags_RELEASE_LIST)
# _ _ _
# | | | |_ __ (_)_ __
# | | | | '_ \| \ \/ /
# | |_| | | | | |> <
# \___/|_| |_|_/_/\_\
#
if(UNIX)
# Common flags for all Unix compilers
set(build_flags_DEBUG_LIST
"-DDEBUG=1"
)
set(build_flags_RELEASE_LIST
"-DNDEBUG=1"
)
# Clang-specific flags
if(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
set(build_flags_COMMON_LIST
${build_flags_COMMON_LIST}
"-Weverything"
"-Werror"
"-Wno-c++98-compat"
"-Wno-c++98-compat-pedantic"
"-Wno-deprecated"
"-Wno-disabled-macro-expansion"
"-Wno-exit-time-destructors"
"-Wno-padded"
"-Wno-reserved-id-macro"
"-Wno-unknown-warning-option"
"-Wno-unused-member-function"
)
# GCC-specific flags
# Unfortunately, we can't use -Werror on GCC, since there is no way to suppress the
# warnings generated by -fpermissive.
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
set(build_flags_COMMON_LIST
${build_flags_COMMON_LIST}
"-Werror"
"-Wno-multichar"
)
endif()
# ASan support
if(LINK_ENABLE_ASAN)
set(build_flags_COMMON_LIST
${build_flags_COMMON_LIST}
"-fsanitize=address"
"-fno-omit-frame-pointer"
)
endif()
# __ ___ _
# \ \ / (_)_ __ __| | _____ _____
# \ \ /\ / /| | '_ \ / _` |/ _ \ \ /\ / / __|
# \ V V / | | | | | (_| | (_) \ V V /\__ \
# \_/\_/ |_|_| |_|\__,_|\___/ \_/\_/ |___/
#
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
add_definitions("/D_SCL_SECURE_NO_WARNINGS")
if(LINK_BUILD_VLD)
add_definitions("/DLINK_BUILD_VLD=1")
else()
add_definitions("/DLINK_BUILD_VLD=0")
endif()
set(build_flags_DEBUG_LIST
"/DDEBUG=1"
)
set(build_flags_RELEASE_LIST
"/DNDEBUG=1"
)
set(build_flags_COMMON_LIST
${build_flags_COMMON_LIST}
"/MP"
"/Wall"
"/WX"
"/EHsc"
#############################
# Ignored compiler warnings #
#############################
"/wd4061" # Enumerator 'identifier' in switch of enum 'enumeration' is not explicitly handled by a case label
"/wd4265" # 'Class' : class has virtual functions, but destructor is not virtual
"/wd4350" # Behavior change: 'member1' called instead of 'member2'
"/wd4355" # 'This' : used in base member initializer list
"/wd4365" # 'Action': conversion from 'type_1' to 'type_2', signed/unsigned mismatch
"/wd4371" # Layout of class may have changed from a previous version of the compiler due to better packing of member 'member'
"/wd4503" # 'Identifier': decorated name length exceeded, name was truncated
"/wd4510" # 'Class': default constructor could not be generated
"/wd4512" # 'Class': assignment operator could not be generated
"/wd4514" # 'Function' : unreferenced inline function has been removed
"/wd4571" # Informational: catch(...) semantics changed since Visual C++ 7.1; structured exceptions (SEH) are no longer caught
"/wd4610" # 'Class': can never be instantiated - user defined constructor required
"/wd4625" # 'Derived class' : copy constructor was implicitly defined as deleted because a base class copy constructor is inaccessible or deleted
"/wd4626" # 'Derived class' : assignment operator was implicitly defined as deleted because a base class assignment operator is inaccessible or deleted
"/wd4628" # digraphs not supported with -Ze. Character sequence 'digraph' not interpreted as alternate token for 'char'
"/wd4640" # 'Instance': construction of local static object is not thread-safe
"/wd4710" # 'Function': function not inlined
"/wd4711" # Function 'function' selected for inline expansion
"/wd4738" # Storing 32-bit float result in memory, possible loss of performance
"/wd4820" # 'Bytes': bytes padding added after construct 'member_name'
)
if(MSVC_VERSION VERSION_GREATER 1800)
set(build_flags_COMMON_LIST
${build_flags_COMMON_LIST}
"/wd4464" # Relative include path contains '..'
"/wd4548" # Expression before comma has no effect; expected expression with side-effect
"/wd4623" # 'Derived class': default constructor could not be generated because a base class default constructor is inaccessible
"/wd4868" # Compiler may not enforce left-to-right evaluation order in braced initializer list
"/wd5026" # Move constructor was implicitly defined as deleted
"/wd5027" # Move assignment operator was implicitly defined as deleted
)
endif()
if(MSVC_VERSION VERSION_GREATER 1900)
set(build_flags_COMMON_LIST
${build_flags_COMMON_LIST}
"/wd4987" # nonstandard extension used: 'throw (...)'
"/wd4774" # 'printf_s' : format string expected in argument 1 is not a string literal
"/wd5039" # "pointer or reference to potentially throwing function passed to extern C function under -EHc. Undefined behavior may occur if this function throws an exception."
)
endif()
if(NOT LINK_BUILD_ASIO)
set(build_flags_COMMON_LIST
${build_flags_COMMON_LIST}
"/wd4917" # 'Symbol': a GUID can only be associated with a class, interface or namespace
# This compiler warning is generated by Microsoft's own ocidl.h, which is
# used when building the WASAPI driver.
)
endif()
endif()
# ____ _ __ _
# / ___| ___| |_ / _| | __ _ __ _ ___
# \___ \ / _ \ __| | |_| |/ _` |/ _` / __|
# ___) | __/ |_ | _| | (_| | (_| \__ \
# |____/ \___|\__| |_| |_|\__,_|\__, |___/
# |___/
# Translate lists to strings
string(REPLACE ";" " " build_flags_COMMON "${build_flags_COMMON_LIST}")
string(REPLACE ";" " " build_flags_DEBUG "${build_flags_DEBUG_LIST}")
string(REPLACE ";" " " build_flags_RELEASE "${build_flags_RELEASE_LIST}")
# Set flags for different build types
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${build_flags_COMMON}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${build_flags_DEBUG}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${build_flags_RELEASE}")