-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_default_options.cmake
199 lines (171 loc) · 8.37 KB
/
setup_default_options.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
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
191
192
193
194
195
196
197
198
199
include(platform)
include(list_to_string)
include(convert_default_options)
# Defines the default compiler options for each platform:
# FLAGS_CXX Compiler flags for all platforms, for langurage C++
# FLAGS_CXX_DEBUG Compiler flags for debug build, for langurage C++
# FLAGS_CXX_RELEASE Compiler flags for release build, for langurage C++
# FLAGS_CXX_MINSIZEREL Compiler flags for release min size build, for langurage C++
# FLAGS_CXX_RELWITHDEBINFO Compiler flags for release with debug info build, for langurage C++
# FLAGS_C Compiler flags for all platforms, for langurage C
# FLAGS_C_DEBUG Compiler flags for debug build, for langurage C
# FLAGS_C_RELEASE Compiler flags for release build, for langurage C
# FLAGS_C_MINSIZEREL Compiler flags for release min size build, for langurage C
# FLAGS_C_RELWITHDEBINFO Compiler flags for release with debug info build, for langurage C
# DEFINES Compiler definitions for all platforms, for langurage C and C++
# DEFINES_DEBUG Compiler definitions for debug build, for langurage C and C++
# DEFINES_RELEASE Compiler definitions for release build, for langurage C and C++
# DEFINES_MINSIZEREL Compiler definitions for release min size build, for langurage C and C++
# DEFINES_RELWITHDEBINFO Compiler definitions for release with debug info build, for langurage C and C++
# LINK_FLAGS Linker specific options
# LINK_LIBRARIES Generic libraries to be linked
macro(setup_default_options)
if(WIN_MSVC)
# Important! do not keep warning 4251 4275 ignored!
# Possibly switch warning 4505 back on
set(FLAGS_CXX
/Wall /wd4061 /wd4251 /wd4275 /wd4435 /wd4505 /wd4514 /wd4548 /wd4571 /wd4592 /wd4625 /wd4626 /wd4628 /wd4710 /wd4774
/wd4820 /wd5026 /wd5027 /WX- /EHsc /Gd /GR /sdl- /Zc:wchar_t /Zc:inline /fp:precise)
set(FLAGS_CXX_DEBUG /Od /Gm- /ZI /RTC1 /MDd)
set(FLAGS_CXX_RELEASE /Ox /GL /GS /Gy /Oi /MD)
set(FLAGS_CXX_MINSIZEREL /O1 /GL /GS /Gy /Oi /MD)
set(FLAGS_CXX_RELWITHDEBINFO /O2 /GL /GS /Gy /Oi /Zi /MD)
set(FLAGS_C
/Wall /wd4061 /wd4251 /wd4275 /wd4505 /wd4514 /wd4548 /wd4571 /wd4625 /wd4626 /wd4710 /wd4774
/wd4820 /wd5026 /wd5027 /WX- /EHsc /Gd /GR /sdl- /Zc:wchar_t /Zc:inline /fp:precise)
set(FLAGS_C_DEBUG /Od /Gm- /ZI /RTC1 /MDd)
set(FLAGS_C_RELEASE /Ox /GL /GS /Gy /Oi /MD)
set(FLAGS_C_MINSIZEREL /O1 /GL /GS /Gy /Oi /MD)
set(FLAGS_C_RELWITHDEBINFO /O2 /GL /GS /Gy /Oi /Zi /MD)
set(DEFINES _UNICODE UNICODE _CRT_SECURE_NO_WARNINGS _SCL_SECURE_NO_WARNINGS _WINSOCK_DEPRECATED_NO_WARNINGS _WIN32_WINNT=0x0700)
set(DEFINES_DEBUG _DEBUG)
set(DEFINES_RELEASE NDEBUG)
set(DEFINES_MINSIZEREL NDEBUG)
set(DEFINES_RELWITHDEBINFO NDEBUG)
set(PLATFORM_LIBRARIES_STATIC )
set(LINK_FLAGS /ignore:4217)
set(LINK_LIBRARIES )
# Hack to force linker to target X64 machine when needed.
if (${CMAKE_SIZEOF_VOID_P} EQUAL "8")
set(DEFINES ${DEFINES} _AMD64_)
else ()
set(DEFINES ${DEFINES} _X86_)
endif ()
if (MEASURE_COVERAGE)
message(STATUS "Adding options for coverage")
endif()
elseif(MINGW)
set(FLAGS_CXX -std=c++11 -Wall -Wextra -fPIC -fexceptions -fmessage-length=0)
set(FLAGS_CXX_DEBUG -O0 -g)
set(FLAGS_CXX_RELEASE -O3)
set(FLAGS_CXX_MINSIZEREL -O3)
set(FLAGS_CXX_RELWITHDEBINFO -O2 -g)
set(FLAGS_C -Wall -Wextra -fPIC -fmessage-length=0)
set(FLAGS_C_DEBUG -O0 -g)
set(FLAGS_C_RELEASE -O3)
set(FLAGS_C_MINSIZEREL -O3)
set(FLAGS_C_RELWITHDEBINFO -O2 -g)
set(DEFINES _UNICODE UNICODE _CRT_SECURE_NO_WARNINGS _SCL_SECURE_NO_WARNINGS _WINSOCK_DEPRECATED_NO_WARNINGS _WIN32_WINNT=0x0700)
set(DEFINES_DEBUG _DEBUG)
set(DEFINES_RELEASE NDEBUG)
set(DEFINES_MINSIZEREL NDEBUG)
set(DEFINES_RELWITHDEBINFO NDEBUG)
set(PLATFORM_LIBRARIES_STATIC )
set(LINK_FLAGS )
set(LINK_LIBRARIES )
if (MEASURE_COVERAGE)
message(STATUS "Adding options for coverage")
endif()
elseif(LINUX)
set(FLAGS_CXX -std=c++11 -Wall -Wextra -fPIC -fexceptions -fmessage-length=0)
set(FLAGS_CXX_DEBUG -O0 -g)
set(FLAGS_CXX_RELEASE -O3)
set(FLAGS_CXX_MINSIZEREL -O3)
set(FLAGS_CXX_RELWITHDEBINFO -O2 -g)
set(FLAGS_C -Wall -Wextra -fPIC -fmessage-length=0)
set(FLAGS_C_DEBUG -O0 -g)
set(FLAGS_C_RELEASE -O3)
set(FLAGS_C_MINSIZEREL -O3)
set(FLAGS_C_RELWITHDEBINFO -O2 -g)
set(DEFINES )
set(DEFINES_DEBUG _DEBUG)
set(DEFINES_RELEASE NDEBUG)
set(DEFINES_MINSIZEREL NDEBUG)
set(DEFINES_RELWITHDEBINFO NDEBUG)
set(PLATFORM_LIBRARIES_STATIC
-static-libgcc
-static-libstdc++)
set(LINK_FLAGS )
set(LINK_LIBRARIES )
if (MEASURE_COVERAGE)
message(STATUS "Adding options for coverage")
list(APPEND FLAGS_C -fprofile-arcs -ftest-coverage)
list(APPEND FLAGS_CXX -fprofile-arcs -ftest-coverage)
list(APPEND LINK_FLAGS --coverage)
list(APPEND LINK_LIBRARIES gcov)
endif()
elseif(APPLE)
set(FLAGS_CXX -std=c++11 -Wall -Wextra -fPIC -fexceptions -fmessage-length=0)
set(FLAGS_CXX_DEBUG -O0 -g)
set(FLAGS_CXX_RELEASE -O3)
set(FLAGS_CXX_MINSIZEREL -O3)
set(FLAGS_CXX_RELWITHDEBINFO -O2 -g)
set(FLAGS_C -Wall -Wextra -fPIC -fmessage-length=0)
set(FLAGS_C_DEBUG -O0 -g)
set(FLAGS_C_RELEASE -O3)
set(FLAGS_C_MINSIZEREL -O3)
set(FLAGS_C_RELWITHDEBINFO -O2 -g)
set(DEFINES )
set(DEFINES_DEBUG _DEBUG)
set(DEFINES_RELEASE NDEBUG)
set(DEFINES_MINSIZEREL NDEBUG)
set(DEFINES_RELWITHDEBINFO NDEBUG)
set(PLATFORM_LIBRARIES_STATIC )
set(LINK_FLAGS )
set(LINK_LIBRARIES )
if (MEASURE_COVERAGE)
message(STATUS "Adding options for coverage")
list(APPEND FLAGS_C -fprofile-arcs -ftest-coverage)
list(APPEND FLAGS_CXX -fprofile-arcs -ftest-coverage)
list(APPEND LINK_FLAGS --coverage)
list(APPEND LINK_LIBRARIES gcov)
endif()
else()
display_list("Unsupported platform " ${CMAKE_HOST_SYSTEM})
return()
endif()
set(CMAKE_COMPILER_IS_CLANG OFF)
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
display_list("Using Clang")
set(CMAKE_COMPILER_IS_CLANG ON)
elseif(${CMAKE_COMPILER_IS_GNUCXX})
display_list("Using Gcc")
else()
display_list("Compiler " ${CMAKE_CXX_COMPILER_ID})
endif()
if(CMAKE_USE_PTHREADS_INIT)
display_list("Adding pthread flags")
list(APPEND FLAGS_CXX -pthread)
list(APPEND FLAGS_C -pthread)
endif()
if(CMAKE_VERBOSE_MAKEFILE)
display_list("Defines: " ${DEFINES})
display_list("Defines - debug: " ${DEFINES_DEBUG})
display_list("Defines - release: " ${DEFINES_RELEASE})
display_list("Defines - release min size: " ${DEFINES_MINSIZEREL})
display_list("Defines - release debug info: " ${DEFINES_RELWITHDEBINFO})
display_list("C++ Flags: " ${FLAGS_CXX})
display_list("C++ Flags - debug: " ${FLAGS_CXX_DEBUG})
display_list("C++ Flags - release: " ${FLAGS_CXX_RELEASE})
display_list("C++ Flags - release min size: " ${FLAGS_CXX_MINSIZEREL})
display_list("C++ Flags - release debug info: " ${FLAGS_CXX_RELWITHDEBINFO})
display_list("C Flags: " ${FLAGS_C})
display_list("C Flags - debug: " ${FLAGS_C_DEBUG})
display_list("C Flags - release: " ${FLAGS_C_RELEASE})
display_list("C Flags - release min size: " ${FLAGS_C_MINSIZEREL})
display_list("C Flags - release debug info: " ${FLAGS_C_RELWITHDEBINFO})
display_list("Link Flags: " ${LINK_FLAGS})
display_list("Link Libraries: " ${LINK_LIBRARIES})
endif()
convert_default_options()
endmacro()