-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathCompileOptions.cmake
More file actions
190 lines (147 loc) · 5.15 KB
/
CompileOptions.cmake
File metadata and controls
190 lines (147 loc) · 5.15 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#
# Platform and architecture setup
#
# Get upper case system name
string(TOUPPER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME_UPPER)
# Determine architecture (32/64 bit)
set(X64 OFF)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(X64 ON)
endif()
#
# Project options
#
set(DEFAULT_PROJECT_OPTIONS
DEBUG_POSTFIX "d"
CXX_STANDARD 11 # Not available before CMake 3.1; see below for manual command line argument addition
LINKER_LANGUAGE "CXX"
POSITION_INDEPENDENT_CODE ON
CXX_VISIBILITY_PRESET "hidden"
CXX_EXTENSIONS Off
)
#
# Include directories
#
set(DEFAULT_INCLUDE_DIRECTORIES)
if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
LIST(APPEND DEFAULT_INCLUDE_DIRECTORIES "/usr/local/include")
endif ()
#
# Libraries
#
set(DEFAULT_LIBRARIES)
#
# Compile definitions
#
set(DEFAULT_COMPILE_DEFINITIONS
SYSTEM_${SYSTEM_NAME_UPPER}
)
# MSVC compiler options
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC" OR
"${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND "x${CMAKE_CXX_SIMULATE_ID}" MATCHES "xMSVC")
set(DEFAULT_COMPILE_DEFINITIONS ${DEFAULT_COMPILE_DEFINITIONS}
_SCL_SECURE_NO_WARNINGS # Calling any one of the potentially unsafe methods in the Standard C++ Library
_CRT_SECURE_NO_WARNINGS # Calling any one of the potentially unsafe methods in the CRT Library
)
endif ()
#
# Compile options
#
set(DEFAULT_COMPILE_OPTIONS_PRIVATE)
set(DEFAULT_COMPILE_OPTIONS_PUBLIC)
# MSVC compiler options
if (MSVC)
set(DEFAULT_COMPILE_OPTIONS_PRIVATE ${DEFAULT_COMPILE_OPTIONS_PRIVATE}
$<$<CXX_COMPILER_ID:MSVC>:
/MP # -> build with multiple processes
>
/W4 # -> warning level 4
# /WX # -> treat warnings as errors
/wd4251 # -> disable warning: 'identifier': class 'type' needs to have dll-interface to be used by clients of class 'type2'
/wd4592 # -> disable warning: 'identifier': symbol will be dynamically initialized (implementation limitation)
# /wd4201 # -> disable warning: nonstandard extension used: nameless struct/union (caused by GLM)
/wd4127 # -> disable warning: conditional expression is constant (caused by Qt)
# /Zm114 # -> Memory size for precompiled headers (insufficient for msvc 2013)
/Zm200 # -> Memory size for precompiled headers
$<$<CXX_COMPILER_ID:Clang>:
-Wno-microsoft-cast
>
#$<$<CONFIG:Debug>:
#/RTCc # -> value is assigned to a smaller data type and results in a data loss
#>
$<$<CONFIG:Release>:
/Gw # -> whole program global optimization
/GS- # -> buffer security check: no
/GL # -> whole program optimization: enable link-time code generation (disables Zi)
/GF # -> enable string pooling
>
# No manual c++11 enable for MSVC as all supported MSVC versions for cmake-init have C++11 implicitly enabled (MSVC >=2013)
)
endif ()
# GCC, Clang and IntelLLVM compiler options
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR
"${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" MATCHES "IntelLLVM" AND NOT MSVC)
set(DEFAULT_COMPILE_OPTIONS_PRIVATE ${DEFAULT_COMPILE_OPTIONS_PRIVATE}
#-fno-exceptions # since we use stl and stl is intended to use exceptions, exceptions should not be disabled
-Wall
-Wextra
-Wunused
-Wreorder
-Wignored-qualifiers
-Wmissing-braces
-Wreturn-type
-Wswitch
-Wswitch-default
-Wuninitialized
-Wmissing-field-initializers
$<$<CXX_COMPILER_ID:GNU>:
-Wmaybe-uninitialized
-Wno-unknown-pragmas
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,4.8>:
-Wpedantic
-Wreturn-local-addr
>
>
$<$<CXX_COMPILER_ID:Clang>:
-Wpedantic
$<$<PLATFORM_ID:Windows>:
-Wno-language-extension-token
-Wno-microsoft-cast
>
# -Wreturn-stack-address # gives false positives
>
$<$<CXX_COMPILER_ID:IntelLLVM>:
-Wmaybe-uninitialized
-Wno-unknown-pragmas
-Wpedantic
-Wreturn-local-addr
>
)
set(DEFAULT_COMPILE_OPTIONS_PUBLIC ${DEFAULT_COMPILE_OPTIONS_PUBLIC}
$<$<PLATFORM_ID:Darwin>:
-pthread
>
# Required for CMake < 3.1; should be removed if minimum required CMake version is raised.
$<$<VERSION_LESS:${CMAKE_VERSION},3.1>:
-std=c++11
>
)
endif ()
#
# Linker options
#
set(DEFAULT_LINKER_OPTIONS)
# Use pthreads on mingw and linux
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
set(DEFAULT_LINKER_OPTIONS
PUBLIC
-pthread
)
endif()
if(NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
set(DEFAULT_LINKER_OPTIONS ${DEFAULT_LINKER_OPTIONS}
PUBLIC
${CMAKE_DL_LIBS}
)
endif()