forked from DavidPH/GDCC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
349 lines (282 loc) · 8.15 KB
/
CMakeLists.txt
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
##-----------------------------------------------------------------------------
##
## Copyright (C) 2013-2019 David Hill
##
## See COPYING for license information.
##
##-----------------------------------------------------------------------------
##
## Root CMake file.
##
##-----------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.6)
project(gdcc)
include(CheckCXXCompilerFlag)
include(CheckTypeSize)
##----------------------------------------------------------------------------|
## CMake Configuration |
##
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "release")
endif()
set(CMAKE_CXX_STANDARD 17)
##----------------------------------------------------------------------------|
## Functions |
##
##
## GDCC_INSTALL_PART
##
function(GDCC_INSTALL_PART name nameAPI pathAPI wantExe wantLib)
if(wantLib AND GDCC_INSTALL_API)
install(FILES ${GDCC_${nameAPI}_H}
DESTINATION include/GDCC/${pathAPI})
endif()
if(wantExe AND GDCC_INSTALL_EXE)
install(TARGETS gdcc-${name}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
endif()
if(wantLib AND GDCC_INSTALL_LIB)
if(GDCC_INSTALL_API)
install(TARGETS gdcc-${name}-lib
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
elseif(GDCC_SHARED)
install(TARGETS gdcc-${name}-lib
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
)
endif()
endif()
endfunction()
##
## GDCC_TRY_CXX_FLAG
##
function(GDCC_TRY_CXX_FLAG flag name)
CHECK_CXX_COMPILER_FLAG(${flag} GDCC_FLAG_CXX_${name})
if(GDCC_FLAG_CXX_${name})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
endif()
endfunction()
##----------------------------------------------------------------------------|
## Environment Detection |
##
set(GDCC_SHARED_DEFAULT ON)
if(NOT GDCC_NOFLAGS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
GDCC_TRY_CXX_FLAG(-Wall Wall)
GDCC_TRY_CXX_FLAG(-Wextra Wextra)
GDCC_TRY_CXX_FLAG(-Wshadow Wshadow)
GDCC_TRY_CXX_FLAG(-Wno-misleading-indentation Wno_misleading_indentation)
GDCC_TRY_CXX_FLAG(-Wno-implicit-fallthrough Wno_implicit_fallthrough)
endif()
if(MSVC)
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
add_definitions(/wd4146) # Unary minus applied to unsigned.
add_definitions(/wd4244) # Possible loss of data by conversion.
add_definitions(/wd4800) # Forcing value to boolean. (All my hate.)
add_definitions(/wd4996) # Deprecated declaration.
endif()
endif()
if(MSVC)
# Disable shared by default, as the source does not contain the needed
# declaration annotations to make that work under MSVC.
set(GDCC_SHARED_DEFAULT OFF)
endif()
find_package(GMP)
CHECK_TYPE_SIZE("long" GDCC_Core_SizeLong)
CHECK_TYPE_SIZE("long long" GDCC_Core_SizeLongLong)
##----------------------------------------------------------------------------|
## Variables |
##
##
## GDCC_Option
##
if(NOT DEFINED GDCC_Option)
if(EXISTS "${CMAKE_SOURCE_DIR}/Option")
set(GDCC_Option ON CACHE BOOL "Enable Option module.")
else()
set(GDCC_Option OFF CACHE BOOL "Enable Option module.")
endif()
endif()
##
## GDCC_Core
##
if(NOT DEFINED GDCC_Core)
if(GDCC_Option AND EXISTS "${CMAKE_SOURCE_DIR}/Core")
set(GDCC_Core ON CACHE BOOL "Enable core module.")
else()
set(GDCC_Core OFF CACHE BOOL "Enable core module.")
endif()
endif()
##
## GDCC_Core_BigNum
##
if(NOT DEFINED GDCC_Core_BigNum)
set(GDCC_Core_BigNum ${GMP_FOUND} CACHE BOOL
"Enable extended precision types and functions.")
endif()
##
## GDCC_Target
##
if(NOT DEFINED GDCC_Target)
if(GDCC_Core AND EXISTS "${CMAKE_SOURCE_DIR}/Target")
set(GDCC_Target ON CACHE BOOL "Enable Target module.")
else()
set(GDCC_Target OFF CACHE BOOL "Enable Target module.")
endif()
endif()
##
## GDCC_IR
##
if(NOT DEFINED GDCC_IR)
if(GDCC_Target AND GDCC_Core_BigNum AND EXISTS "${CMAKE_SOURCE_DIR}/IR")
set(GDCC_IR ON CACHE BOOL "Enable IR module.")
else()
set(GDCC_IR OFF CACHE BOOL "Enable IR module.")
endif()
endif()
##
## GDCC_BC_DGE
##
if(NOT DEFINED GDCC_BC_DGE)
if(GDCC_IR AND EXISTS "${CMAKE_SOURCE_DIR}/BC/DGE")
set(GDCC_BC_DGE ON CACHE BOOL "Enable BC::DGE module.")
else()
set(GDCC_BC_DGE OFF CACHE BOOL "Enable BC::DGE module.")
endif()
endif()
##
## GDCC_BC_ZDACS
##
if(NOT DEFINED GDCC_BC_ZDACS)
if(GDCC_IR AND EXISTS "${CMAKE_SOURCE_DIR}/BC/ZDACS")
set(GDCC_BC_ZDACS ON CACHE BOOL "Enable BC::ZDACS module.")
else()
set(GDCC_BC_ZDACS OFF CACHE BOOL "Enable BC::ZDACS module.")
endif()
endif()
##
## GDCC_INSTALL_API
##
if(NOT DEFINED GDCC_INSTALL_API)
set(GDCC_INSTALL_API ON CACHE BOOL "Install headers.")
endif()
##
## GDCC_INSTALL_DOC
##
if(NOT DEFINED GDCC_INSTALL_DOC)
set(GDCC_INSTALL_DOC ON CACHE BOOL "Install documentation.")
endif()
##
## GDCC_INSTALL_EXE
##
if(NOT DEFINED GDCC_INSTALL_EXE)
set(GDCC_INSTALL_EXE ON CACHE BOOL "Install executables.")
endif()
##
## GDCC_INSTALL_LIB
##
if(NOT DEFINED GDCC_INSTALL_LIB)
set(GDCC_INSTALL_LIB ON CACHE BOOL "Install libraries.")
endif()
##
## GDCC_SHARED
##
## If true (or equivalent), libraries will be built as SHARED. Otherwise,
## they are built as STATIC.
##
if(NOT DEFINED GDCC_SHARED)
set(GDCC_SHARED ${GDCC_SHARED_DEFAULT} CACHE BOOL
"Build libraries as shared objects.")
endif()
##
## GDCC_SHARED_DECL
##
## Used internally for convenience in add_library commands.
##
if(GDCC_SHARED)
set(GDCC_SHARED_DECL SHARED)
else()
set(GDCC_SHARED_DECL STATIC)
endif()
##----------------------------------------------------------------------------|
## Environment Configuration |
##
configure_file(Config.hpp inc/GDCC/Config.hpp)
include_directories(${CMAKE_BINARY_DIR}/inc .)
if(GMP_FOUND)
include_directories(${GMP_INCLUDE_DIRS})
endif()
##----------------------------------------------------------------------------|
## Targets |
##
if(GDCC_IR AND EXISTS "${CMAKE_SOURCE_DIR}/ACC")
add_subdirectory(ACC)
endif()
if(GDCC_IR AND EXISTS "${CMAKE_SOURCE_DIR}/AR")
add_subdirectory(AR)
endif()
if(GDCC_IR AND EXISTS "${CMAKE_SOURCE_DIR}/AS")
add_subdirectory(AS)
endif()
if(GDCC_IR AND EXISTS "${CMAKE_SOURCE_DIR}/BC")
add_subdirectory(BC)
endif()
if(GDCC_IR AND EXISTS "${CMAKE_SOURCE_DIR}/CC")
add_subdirectory(CC)
endif()
if(GDCC_IR AND EXISTS "${CMAKE_SOURCE_DIR}/CPP")
add_subdirectory(CPP)
endif()
if(GDCC_Core)
add_subdirectory(Core)
endif()
if(GDCC_IR)
add_subdirectory(IR)
endif()
if(GDCC_IR AND EXISTS "${CMAKE_SOURCE_DIR}/IRDump")
add_subdirectory(IRDump)
endif()
if(GDCC_IR AND EXISTS "${CMAKE_SOURCE_DIR}/LD")
add_subdirectory(LD)
endif()
if(GDCC_IR AND EXISTS "${CMAKE_SOURCE_DIR}/MakeLib")
add_subdirectory(MakeLib)
endif()
if(GDCC_IR AND EXISTS "${CMAKE_SOURCE_DIR}/NTSC")
add_subdirectory(NTSC)
endif()
if(GDCC_Option)
add_subdirectory(Option)
endif()
if(GDCC_IR AND EXISTS "${CMAKE_SOURCE_DIR}/SR")
add_subdirectory(SR)
endif()
if(GDCC_Target)
add_subdirectory(Target)
endif()
if(GDCC_INSTALL_API)
install(FILES ${CMAKE_BINARY_DIR}/inc/GDCC/Config.hpp DESTINATION include/GDCC)
endif()
if(WIN32)
if(GDCC_INSTALL_DOC)
install(DIRECTORY doc/ DESTINATION doc)
install(FILES COPYING DESTINATION doc)
install(FILES COPYLIB DESTINATION doc)
endif()
install(DIRECTORY lib/ DESTINATION bin/lib)
else()
if(GDCC_INSTALL_DOC)
install(DIRECTORY doc/ DESTINATION share/gdcc/doc)
install(FILES COPYING DESTINATION share/gdcc/doc)
install(FILES COPYLIB DESTINATION share/gdcc/doc)
endif()
install(DIRECTORY lib/ DESTINATION share/gdcc/lib)
endif()
## EOF