This repository has been archived by the owner on Jun 27, 2018. It is now read-only.
/
CMakeLists.txt
342 lines (311 loc) · 14.2 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
cmake_minimum_required(VERSION 2.8.5)
project (toolchain)
# Main version information.
set(VERSION_STAGE "beta")
execute_process(COMMAND git rev-parse HEAD OUTPUT_VARIABLE git_hash)
if("${git_hash}" STREQUAL "")
add_definitions(-DVERSION_STAGE=${VERSION_STAGE})
else("${git_hash}" STREQUAL "")
string(STRIP ${git_hash} git_hash)
string(SUBSTRING ${git_hash} 0 9 git_hash)
set(VERSION_GIT ${git_hash})
add_definitions(-DVERSION_STAGE=${VERSION_STAGE} -DVERSION_GIT=${VERSION_GIT})
endif("${git_hash}" STREQUAL "")
# Set up some basics.
set(IS_ROOT 1)
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR})
if(MSVC)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ROOT_DIR})
else(MSVC)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${ROOT_DIR}/Debug")
endif(MSVC)
set(OUTPUT_DIR "${ROOT_DIR}/Debug")
set(FLEX_UNISTD_INCLUDE "")
set(CMAKE_BUILD_TYPE Debug)
if(MSVC)
# Windows does not have unistd.h, but GnuWin32's Flex program
# provides it for us, so we need to add that as an include
# directory in this case.
set(FLEX_UNISTD_INCLUDE "${ROOT_DIR}/third-party/flex")
endif(MSVC)
if(NOT DEFINED BUILD_EMULATOR)
set(BUILD_EMULATOR true)
endif(NOT DEFINED BUILD_EMULATOR)
if(NOT DEFINED FLEX_EXECUTABLE)
find_program(FLEX_EXECUTABLE NAMES flex.exe flex)
endif(NOT DEFINED FLEX_EXECUTABLE)
if(NOT DEFINED BISON_EXECUTABLE)
find_program(BISON_EXECUTABLE NAMES bison.exe bison)
endif(NOT DEFINED BISON_EXECUTABLE)
if(NOT DEFINED M4_EXECUTABLE)
find_program(M4_EXECUTABLE NAMES m4.exe m4)
endif(NOT DEFINED M4_EXECUTABLE)
if(DEFINED ENV{SHELL})
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if(NOT MSVC)
set(TOOLCHAIN_ON_CYGWIN true)
endif(NOT MSVC)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
endif(DEFINED ENV{SHELL})
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "cmake")
# Set compiler options.
if(MSVC)
# TODO: Set warnings as errors on MSVC.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /W3 /wd4273 /wd4065 /wd4996 /wd4005 /D_CRT_SECURE_NO_WARNINGS /DSIMCLIST_NO_DUMPRESTORE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX /W3 /wd4273 /wd4065 /wd4996 /wd4005 /D_CRT_SECURE_NO_WARNINGS /DSIMCLIST_NO_DUMPRESTORE")
elseif(APPLE)
# TODO: Set warnings as errors under Mac / XCode.
else(MSVC)
# Assume GNU since there doesn't appear to be
# a better way of detecting this.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wdeclaration-after-statement -Wno-int-to-pointer-cast")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # TODO: Fix code to allow -Werror here.
endif(MSVC)
# Show configuration.
message("-- Showing configuration")
if(DEFINED VERSION_GIT)
message(" >> version is: '${VERSION_STAGE}; #${VERSION_GIT}'")
else(DEFINED VERSION_GIT)
message(" >> version is: '${VERSION_STAGE}'")
endif(DEFINED VERSION_GIT)
message(" >> m4 is at: ${M4_EXECUTABLE}")
message(" >> flex is at: ${FLEX_EXECUTABLE}")
message(" >> flex unistd is at: ${FLEX_UNISTD_INCLUDE}")
message(" >> bison is at: ${BISON_EXECUTABLE}")
message(" (must be Cygwin versions on Windows)")
if(NOT "${EXPERIMENTAL}" STREQUAL "")
message(" >> experimental features are enabled!")
set(EXPERIMENTAL true)
endif(NOT "${EXPERIMENTAL}" STREQUAL "")
if(DEFINED TOOLCHAIN_ON_CYGWIN)
message(" >> detected cygwin!")
endif(DEFINED TOOLCHAIN_ON_CYGWIN)
# Define a function that automatically includes
# all of the .h and .c files in the project folder.
function(dt_project type)
# Initialize.
set(${PROJECT_NAME}_all "")
# Add all source and header files first.
file(GLOB ${PROJECT_NAME}_source_c *.c)
file(GLOB ${PROJECT_NAME}_source_cpp *.cpp)
file(GLOB ${PROJECT_NAME}_header_c *.h)
file(GLOB ${PROJECT_NAME}_header_cpp *.hpp)
file(GLOB ${PROJECT_NAME}_parser_y parser.y)
file(GLOB ${PROJECT_NAME}_parser_l lexer.l)
# Check to see if we need to handle parsers.
if("${${PROJECT_NAME}_parser_y}" MATCHES "^(.*)/parser.y$")
string(LENGTH "${${PROJECT_NAME}_source_cpp}" has_cxx)
if(${has_cxx} EQUAL 0)
dt_has_parser(false)
else(${has_cxx} EQUAL 0)
dt_has_parser(true)
endif(${has_cxx} EQUAL 0)
endif("${${PROJECT_NAME}_parser_y}" MATCHES "^(.*)/parser.y$")
# Output messages.
if("${type}" MATCHES "^executable$")
message(" >> ${PROJECT_NAME}: executable")
elseif("${type}" MATCHES "^library$")
message(" >> ${PROJECT_NAME}: library")
else("${type}" MATCHES "^executable$")
message(FATAL_ERROR "Unknown project type definition for ${PROJECT_NAME}")
endif("${type}" MATCHES "^executable$")
# Add any additional directories.
if(NOT 1 EQUAL ${ARGC})
math(EXPR ARGC_OFFSET "${ARGC} - 1")
foreach(v RANGE 1 ${ARGC_OFFSET})
set(i ${ARGV${v}})
message(" .. including '${i}'")
# Search for all C / C++ files in the directory.
file(GLOB ${PROJECT_NAME}_${i}_source_c ${i}/*.c)
file(GLOB ${PROJECT_NAME}_${i}_source_cpp ${i}/*.cpp)
file(GLOB ${PROJECT_NAME}_${i}_header_c ${i}/*.h)
file(GLOB ${PROJECT_NAME}_${i}_header_cpp ${i}/*.hpp)
# Set groupings for IDEs.
source_group("Source Files\\\\${i}" FILES ${${PROJECT_NAME}_${i}_source_c} ${${PROJECT_NAME}_${i}_source_cpp})
source_group("Header Files\\\\${i}" FILES ${${PROJECT_NAME}_${i}_header_c} ${${PROJECT_NAME}_${i}_header_cpp})
source_group("Lexer / Parser Files\\\\${i}" FILES ${${PROJECT_NAME}_${i}_parser_y} ${${PROJECT_NAME}_${i}_parser_l})
# Append to source code list.
set(${PROJECT_NAME}_all ${${PROJECT_NAME}_all} ${${PROJECT_NAME}_${i}_source_c} ${${PROJECT_NAME}_${i}_source_cpp} ${${PROJECT_NAME}_${i}_header_c} ${${PROJECT_NAME}_${i}_header_cpp})
endforeach(v RANGE 1 ${ARGC})
endif(NOT 1 EQUAL ${ARGC})
# Join it all together.
set(${PROJECT_NAME}_all ${${PROJECT_NAME}_all} ${${PROJECT_NAME}_source_c} ${${PROJECT_NAME}_source_cpp} ${${PROJECT_NAME}_header_c} ${${PROJECT_NAME}_header_cpp} ${${PROJECT_NAME}_parser_y} ${${PROJECT_NAME}_parser_l})
# Set groupings for IDEs.
source_group("Source Files" FILES ${${PROJECT_NAME}_source_c} ${${PROJECT_NAME}_source_cpp})
source_group("Header Files" FILES ${${PROJECT_NAME}_header_c} ${${PROJECT_NAME}_header_cpp})
source_group("Lexer / Parser Files" FILES ${${PROJECT_NAME}_parser_y} ${${PROJECT_NAME}_parser_l})
# Add the flex unistd directory.
include_directories(${FLEX_UNISTD_INCLUDE})
# Create either an executable or library.
if("${type}" MATCHES "^executable$")
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_all})
elseif("${type}" MATCHES "^library$")
add_library(${PROJECT_NAME} ${${PROJECT_NAME}_all})
else("${type}" MATCHES "^executable$")
message(FATAL_ERROR "Unknown project type definition for ${PROJECT_NAME}")
endif("${type}" MATCHES "^executable$")
set_target_properties(${PROJECT_NAME} PROPERTIES include_path "${CMAKE_CURRENT_SOURCE_DIR}")
endfunction(dt_project type)
# Define a function which will place the current project
# in a specified folder.
function(dt_folder foldername)
message(" .. placing in folder ${foldername}")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER ${foldername})
endfunction(dt_folder foldername)
# Define a function which specifies a dependency on
# the project.
function(dt_needs dependency)
get_target_property(${dependency}_include_path ${dependency} include_path)
if("${${dependency}_include_path}" MATCHES "NOTFOUND")
# This is potentially a prebuilt library (like libtcod
# which varies).
dt_needs_prebuilt(${dependency})
else("${${dependency}_include_path}" MATCHES "NOTFOUND")
# We've found this as an internal dependency.
string(LENGTH ${ROOT_DIR} root_dir_length)
math(EXPR root_dir_length "${root_dir_length} + 1")
string(SUBSTRING "${${dependency}_include_path}" "${root_dir_length}" -1 pretty_include_path)
message(" .. adding '${dependency}' include at ${pretty_include_path}")
add_dependencies(${PROJECT_NAME} ${dependency})
include_directories("${${dependency}_include_path}")
target_link_libraries(${PROJECT_NAME} ${dependency})
endif("${${dependency}_include_path}" MATCHES "NOTFOUND")
endfunction(dt_needs)
# Define a function which specifies a framework/library to be linked with the project for Mac
function(dt_needs_osx_dependency dependency)
if(APPLE)
message(" .. adding '${dependency}' for Mac")
find_library(${dependency}_LIBRARY ${dependency})
# Fix for Mac libraries appending ;-framework X at the end specifically for SDL
# if this proves to be an issue for other libraries, this case statement can be removed/expanded
# STREQUAL is used to match SDL and not SDLmain
if("${dependency}" STREQUAL "SDL")
foreach(lib ${SDL_LIBRARY})
mark_as_advanced(${lib})
target_link_libraries(${PROJECT_NAME} "${lib}")
endforeach(lib)
find_path(SDL_INCLUDE_DIR SDL/SDL.h)
else()
mark_as_advanced(${dependency}_LIBRARY)
target_link_libraries(${PROJECT_NAME} "${${dependency}_LIBRARY}")
endif()
endif(APPLE)
endfunction(dt_needs_osx_dependency dependency)
# Define a function which specifies a **pre-built**
# dependency on the project.
function(dt_needs_prebuilt dependency)
set(should_include_headers true)
# Check to see if we should exclude distributed headers on this platform.
if(UNIX)
if(DEFINED ${dependency}_UnixNoInclude)
if(${${dependency}_UnixNoInclude})
set(should_include_headers false)
endif(${${dependency}_UnixNoInclude})
endif(DEFINED ${dependency}_UnixNoInclude)
endif(UNIX)
if(TOOLCHAIN_ON_CYGWIN)
if(DEFINED ${dependency}_CygwinNoInclude)
if(${${dependency}_CygwinNoInclude})
set(should_include_headers false)
endif(${${dependency}_CygwinNoInclude})
endif(DEFINED ${dependency}_CygwinNoInclude)
endif(TOOLCHAIN_ON_CYGWIN)
if(${should_include_headers})
message(" .. adding '${dependency}' include at third-party/${dependency}/include")
include_directories("${ROOT_DIR}/third-party/${dependency}/include")
else(${should_include_headers})
message(" .. skipping inclusion of distributed '${dependency}' headers on this platform.")
endif(${should_include_headers})
# Add include and library dependencies.
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if(DEFINED ${dependency}_Windows)
message(" .. adding '${dependency}' library at third-party/${dependency}/lib/${${dependency}_Windows}.lib")
target_link_libraries(${PROJECT_NAME} "${ROOT_DIR}/third-party/${dependency}/lib/${${dependency}_Windows}.lib")
else(DEFINED ${dependency}_Windows)
message(FATAL_ERROR " .. dependency '${dependency}' could not be satisified on your platform")
endif(DEFINED ${dependency}_Windows)
else(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if(DEFINED ${dependency}_Unix)
message(" .. adding '${dependency}' library")
find_library(${${dependency}_Unix} ${${dependency}_Unix})
target_link_libraries(${PROJECT_NAME} ${${dependency}_Unix})
else(DEFINED ${dependency}_Unix)
message(FATAL_ERROR " .. dependency '${dependency}' could not be satisified on your platform")
endif(DEFINED ${dependency}_Unix)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
endfunction(dt_needs_prebuilt dependency)
# Define a dependency on an executable project.
function(dt_needs_exe dependency)
add_dependencies(${PROJECT_NAME} ${dependency})
endfunction(dt_needs_exe dependency)
# Define a function which compiles Flex and Bison files.
function(dt_has_parser cxx)
if("${cxx}" MATCHES true)
add_custom_command(
SOURCE ${${PROJECT_NAME}_SOURCE_DIR}/lexer.l
COMMAND ${FLEX_EXECUTABLE} -o${${PROJECT_NAME}_SOURCE_DIR}/lexer.cpp --header-file=${${PROJECT_NAME}_SOURCE_DIR}/lexer.hpp ${${PROJECT_NAME}_SOURCE_DIR}/lexer.l
TARGET ${PROJECT_NAME}
OUTPUTS ${${PROJECT_NAME}_SOURCE_DIR}/lexer.cpp ${${PROJECT_NAME}_SOURCE_DIR}/lexer.hpp)
add_custom_command(
SOURCE ${${PROJECT_NAME}_SOURCE_DIR}/parser.y
COMMAND ${BISON_EXECUTABLE} -d -y -o${${PROJECT_NAME}_SOURCE_DIR}/parser.cpp ${${PROJECT_NAME}_SOURCE_DIR}/parser.y
TARGET ${PROJECT_NAME}
OUTPUTS ${${PROJECT_NAME}_SOURCE_DIR}/parser.cpp ${${PROJECT_NAME}_SOURCE_DIR}/parser.hpp)
set(${PROJECT_NAME}_all ${${PROJECT_NAME}_all} ${${PROJECT_NAME}_SOURCE_DIR}/parser.cpp ${${PROJECT_NAME}_SOURCE_DIR}/lexer.cpp PARENT_SCOPE)
set_source_files_properties(${${PROJECT_NAME}_SOURCE_DIR}/parser.cpp GENERATED)
else("${cxx}" MATCHES true)
add_custom_command(
SOURCE ${${PROJECT_NAME}_SOURCE_DIR}/lexer.l
COMMAND ${FLEX_EXECUTABLE} -o${${PROJECT_NAME}_SOURCE_DIR}/lexer.c --header-file=${${PROJECT_NAME}_SOURCE_DIR}/lexer.h ${${PROJECT_NAME}_SOURCE_DIR}/lexer.l
TARGET ${PROJECT_NAME}
OUTPUTS ${${PROJECT_NAME}_SOURCE_DIR}/lexer.c ${${PROJECT_NAME}_SOURCE_DIR}/lexer.h)
add_custom_command(
SOURCE ${${PROJECT_NAME}_SOURCE_DIR}/parser.y
COMMAND ${BISON_EXECUTABLE} -d -y -o${${PROJECT_NAME}_SOURCE_DIR}/parser.c ${${PROJECT_NAME}_SOURCE_DIR}/parser.y
TARGET ${PROJECT_NAME}
OUTPUTS ${${PROJECT_NAME}_SOURCE_DIR}/parser.c ${${PROJECT_NAME}_SOURCE_DIR}/parser.h)
set(${PROJECT_NAME}_all ${${PROJECT_NAME}_all} ${${PROJECT_NAME}_SOURCE_DIR}/parser.c ${${PROJECT_NAME}_SOURCE_DIR}/lexer.c PARENT_SCOPE)
set_source_files_properties(${${PROJECT_NAME}_SOURCE_DIR}/parser.c GENERATED)
endif("${cxx}" MATCHES true)
endfunction(dt_has_parser)
message("-- Defining projects")
# Add library folders.
if(NOT MSVC AND NOT TOOLCHAIN_ON_CYGWIN)
add_subdirectory(third-party/opengl)
add_subdirectory(third-party/zlib)
add_subdirectory(third-party/libpng)
add_subdirectory(third-party/sdl)
endif(NOT MSVC AND NOT TOOLCHAIN_ON_CYGWIN)
add_subdirectory(third-party/libtcod)
add_subdirectory(third-party/pthread)
add_subdirectory(third-party/readline)
add_subdirectory(third-party/argtable2)
add_subdirectory(third-party/bstring)
add_subdirectory(third-party/simclist)
add_subdirectory(libdcpu)
add_subdirectory(libdcpu-vm)
add_subdirectory(libdcpu-ci-dbgfmt)
add_subdirectory(libdcpu-vm-dbg)
add_subdirectory(libdcpu-pp)
add_subdirectory(libdcpu-pp-expr)
add_subdirectory(libdcpu-ci-objfmt)
add_subdirectory(libdcpu-ci-lang)
add_subdirectory(libdcpu-ci-lang-c)
# Add executable folders.
add_subdirectory(dtpp)
add_subdirectory(dtcc)
add_subdirectory(dtasm)
add_subdirectory(dtld)
add_subdirectory(dtdb)
if("${BUILD_EMULATOR}" MATCHES true)
add_subdirectory(dtemu)
endif("${BUILD_EMULATOR}" MATCHES true)
# Add kernel, using the multi-threading version if available.
if(EXISTS "kernel.mt" AND IS_DIRECTORY "kernel.mt")
# add_subdirectory(kernel.mt)
else(EXISTS "kernel.mt" AND IS_DIRECTORY "kernel.mt")
# add_subdirectory(kernel)
endif(EXISTS "kernel.mt" AND IS_DIRECTORY "kernel.mt")
add_subdirectory(dbg-test)