forked from ZQuestClassic/ZQuestClassic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
253 lines (198 loc) · 10.5 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
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CONFIGURATION_TYPES Debug Release CACHE TYPE INTERNAL FORCE)
project (ZeldaClassic)
set(USE_PCH FALSE CACHE BOOL "Use precompiled headers")
set(UNITY_BUILD FALSE CACHE BOOL "Unity build")
set(CMAKE_CXX_STANDARD 98)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()
function(enable_unity_build UB_SUFFIX SOURCE_VARIABLE_NAME)
set(files ${${SOURCE_VARIABLE_NAME}})
# Generate a unique filename for the unity build translation unit
set(unit_build_file ${CMAKE_CURRENT_BINARY_DIR}/UB_${UB_SUFFIX}.cpp)
# Exclude all translation units from compilation
set_source_files_properties(${files} PROPERTIES HEADER_FILE_ONLY true)
# Open the ub file
FILE(WRITE ${unit_build_file} "// Unity Build generated by CMake\n")
FILE(APPEND ${unit_build_file} "#include \"${CMAKE_SOURCE_DIR}/src/precompiled.h\"\n")
# Add include statement for each translation unit
foreach(source_file ${files} )
FILE( APPEND ${unit_build_file} "#include <${CMAKE_CURRENT_SOURCE_DIR}/${source_file}>\n")
endforeach(source_file)
# Complement list of translation units with the name of ub
set(${SOURCE_VARIABLE_NAME} ${${SOURCE_VARIABLE_NAME}} ${unit_build_file} PARENT_SCOPE)
endfunction(enable_unity_build)
#############################################################
# Header and source file lists
#############################################################
include_directories(./allegro/include)
include_directories(./include/lpng1212)
include_directories(./include/zlib123)
include_directories(./include/loadpng)
include_directories(./include/jpgalleg-2.5)
include_directories(./include/dumb)
include_directories(./include/alogg)
include_directories(./include/almp3)
include_directories(./include/gme)
set(ZCSOUNDSOURCES
src/zcmusic.cpp
src/zcmusicd.cpp
src/alleg_compat.cpp
)
set(ROMVIEW_MODULES
${CMAKE_SOURCE_DIR}/modules/romview/RomviewCore.txt
${CMAKE_SOURCE_DIR}/modules/romview/RomviewGUI.txt
)
set(ZELDA_MODULES
${CMAKE_SOURCE_DIR}/modules/zelda/ZeldaCore.txt
${CMAKE_SOURCE_DIR}/modules/zelda/ZeldaGUI.txt
${CMAKE_SOURCE_DIR}/modules/zelda/ZeldaSprite.txt
${CMAKE_SOURCE_DIR}/modules/zelda/ZeldaSubscreen.txt
)
set(ZQUEST_MODULES
${CMAKE_SOURCE_DIR}/modules/zquest/ZQuestCore.txt
${CMAKE_SOURCE_DIR}/modules/zquest/ZQuestGUI.txt
${CMAKE_SOURCE_DIR}/modules/zquest/ZQuestMisc.txt
${CMAKE_SOURCE_DIR}/modules/zquest/ZQuestZScript.txt
${CMAKE_SOURCE_DIR}/modules/zquest/ZQuestZScriptNP.txt
)
foreach(module ${ROMVIEW_MODULES} ${ZELDA_MODULES} ${ZQUEST_MODULES})
include(${module})
set_source_files_properties(${module} PROPERTIES HEADER_FILE_ONLY true)
endforeach()
#############################################################
# Build the ZScript parser
#############################################################
find_package(BISON QUIET)
find_package(FLEX QUIET)
if(${BISON_FOUND} AND ${FLEX_FOUND})
if(MSVC)
set(FLEXFLAGS "--wincompat")
endif()
FLEX_TARGET(ZScriptLexer ${CMAKE_SOURCE_DIR}/src/parser/ffscript.lpp ${CMAKE_SOURCE_DIR}/src/parser/lex.yy.cpp COMPILE_FLAGS ${FLEXFLAGS})
BISON_TARGET(ZScriptParser ${CMAKE_SOURCE_DIR}/src/parser/ffscript.ypp ${CMAKE_SOURCE_DIR}/src/parser/y.tab.cpp)
add_flex_bison_dependency(ZScriptLexer ZScriptParser)
else()
message(WARNING "Flex and Bison not found. ZQuest will be compiled without the ZScript parser.")
set(ZQUEST_ZSCRIPT_SOURCES ${ZQUEST_ZSCRIPT_SOURCES_NOPARSER})
endif()
#############################################################
# Global settings for the different platforms
#############################################################
# Windows
if(MSVC)
set(ALLEGROLIB "$<$<CONFIG:DEBUG>:${CMAKE_SOURCE_DIR}/libs/win32dbg/alleg44-debug.lib>"
"$<$<CONFIG:RELEASE>:${CMAKE_SOURCE_DIR}/libs/win32/alleg44.lib>")
add_definitions(-DALLEGRO_MSVC)
set(IMAGELIBS "$<$<CONFIG:DEBUG>:${CMAKE_SOURCE_DIR}/libs/win32dbg/al_gif.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/libpng.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/zlibd.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/loadpng.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/libjpgal.lib>"
"$<$<CONFIG:RELEASE>:${CMAKE_SOURCE_DIR}/libs/win32/al_gif.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/libpng.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/zlib.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/loadpng.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/libjpgal.lib>")
set(SOUNDLIBS "$<$<CONFIG:DEBUG>:${CMAKE_SOURCE_DIR}/libs/win32dbg/aldmd.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/almp3.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/alogg.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/dumbd.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32dbg/gme.lib>"
"$<$<CONFIG:RELEASE>:${CMAKE_SOURCE_DIR}/libs/win32/aldmb.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/almp3.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/alogg.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/dumb.lib$<SEMICOLON>${CMAKE_SOURCE_DIR}/libs/win32/gme.lib>")
if(MSVC_VERSION GREATER 1500)
add_definitions(-DALLEGRO_HAVE_STDINT_H)
endif()
add_compile_options("$<$<CONFIG:DEBUG>:/MTd>")
add_compile_options("$<$<CONFIG:RELEASE>:/MT>")
# REQUIRED or else MSVC throws internal compiler error(!)
add_compile_options("$<$<CONFIG:RELEASE>:/fp:fast>")
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:LIBCD /SUBSYSTEM:WINDOWS /DEBUG")
if(USE_PCH)
set(ZCPrecompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/zcprecompiled.pch")
set(ZQPrecompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/zqprecompiled.pch")
set_source_files_properties(src/precompiledzc.cpp PROPERTIES COMPILE_FLAGS "/Ycprecompiled.h /Fp\"${ZCPrecompiledBinary}\"" OBJECT_OUTPUTS "${ZCPrecompiledBinary}")
set_source_files_properties(src/precompiledzq.cpp PROPERTIES COMPILE_FLAGS "/Ycprecompiled.h /Fp\"${ZQPrecompiledBinary}\"" OBJECT_OUTPUTS "${ZQPrecompiledBinary}")
list(APPEND ZELDAEXTRASOURCES src/precompiledzc.cpp)
list(APPEND ZQUESTEXTRASOURCES src/precompiledzq.cpp)
endif()
# Linux
elseif(LINUX)
link_directories(/usr/lib/i386-linux-gnu)
link_directories(./libs/linux)
set(ALLEGROLIB alleg)
add_definitions(-DALLEGRO_UNIX)
add_definitions(-DALLEGRO_LINUX) # Mistakenly used in the source.
execute_process(COMMAND "${CMAKE_SOURCE_DIR}/allegro/configure --enable-static=yes --enable-shared=no --enable-ossdigi=no --enable-ossmidi=no --enable-esddigi=no --enable-artsdigi=no --enable-sgialdigi=no --enable-jackdigi=no --enable-xwin-dga2=no --enable-vga=no --enable-svgalib=no" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/allegro")
set(IMAGELIBS algif ldpng jpgal png z)
set(SOUNDLIBS aldmb almp3 alogg dumb gme asound)
set(X11_LIBRARIES X11 Xext Xcursor Xxf86vm pthread Xpm dl)
add_compile_options("-m32")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32 -static-libgcc -export-dynamic")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32 -static-libgcc")
endif()
#############################################################
# Sound Library
#############################################################
if(MSVC AND (MSVC_VERSION GREATER 1600))
set(ZCSOUNDLIBSEXTRA legacy_stdio_definitions)
endif()
add_library(zcsound SHARED ${ZCSOUNDSOURCES})
target_link_libraries(zcsound ${ALLEGROLIB} ${SOUNDLIBS} ${ZCSOUNDLIBSEXTRA})
#############################################################
# Romview
#############################################################
if(MSVC)
list(APPEND ROMVIEWEXTRASOURCES rv_icon.rc)
elseif(LINUX)
list(APPEND ROMVIEWEXTRASOURCES rv_icon.c)
set(ROMVIEWLIBSEXTRA ${X11_LIBRARIES})
endif()
if(UNITY_BUILD)
enable_unity_build(RomviewCore ROMVIEW_CORE_SOURCES)
enable_unity_build(RomviewGUI ROMVIEW_GUI_SOURCES)
endif()
add_executable(romview ${ROMVIEW_CORE_SOURCES} ${ROMVIEW_GUI_SOURCES} ${ROMVIEWEXTRASOURCES} ${ROMVIEW_MODULES})
target_link_libraries(romview ${IMAGELIBS} ${ALLEGROLIB} ${SOUNDLIBS} ${ROMVIEWLIBSEXTRA})
#############################################################
# Zelda
#############################################################
if(MSVC)
list(APPEND ZELDAEXTRASOURCES zc_icon.rc)
elseif(LINUX)
list(APPEND ZELDAEXTRASOURCES zc_icon.c src/single_instance_unix.cpp)
set(ZELDALIBSEXTRA ${X11_LIBRARIES})
endif()
if(UNITY_BUILD)
enable_unity_build(ZeldaCore ZELDA_CORE_SOURCES)
enable_unity_build(ZeldaGUI ZELDA_GUI_SOURCES)
enable_unity_build(ZeldaSprite ZELDA_SPRITE_SOURCES)
enable_unity_build(ZeldaSubscreen ZELDA_SUBSCREEN_SOURCES)
endif()
add_executable(zelda ${ZELDA_CORE_SOURCES} ${ZELDA_GUI_SOURCES} ${ZELDA_SPRITE_SOURCES} ${ZELDA_SUBSCREEN_SOURCES} ${ZELDA_SCRIPTING_SOURCES} ${ZELDAEXTRASOURCES} ${ZELDA_MODULES})
if(WIN32)
target_link_libraries(zelda zcsound winmm ${IMAGELIBS} ${ALLEGROLIB} ${ZELDALIBSEXTRA})
elseif(LINUX)
target_link_libraries(zelda zcsound ${IMAGELIBS} ${ALLEGROLIB} ${ZELDALIBSEXTRA})
endif()
if(MSVC AND USE_PCH)
set_target_properties(zelda PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h /Fp\"${ZCPrecompiledBinary}\"" OBJECT_DEPENDS "${ZCPrecompiledBinary}")
target_compile_definitions(zelda PRIVATE ZC_PCH)
endif()
#############################################################
# ZQuest
#############################################################
if(MSVC)
list(APPEND ZQUESTEXTRASOURCES zq_icon.rc)
elseif(LINUX)
list(APPEND ZQUESTEXTRASOURCES zq_icon.c src/single_instance_unix.cpp)
set(ZQUESTLIBSEXTRA ${X11_LIBRARIES})
endif()
if(UNITY_BUILD)
enable_unity_build(ZQuestCore ZQUEST_CORE_SOURCES)
enable_unity_build(ZQuestGUI ZQUEST_GUI_SOURCES)
enable_unity_build(ZQuestMisc ZQUEST_MISC_SOURCES)
enable_unity_build(ZQuestZScript ZQUEST_ZSCRIPT_SOURCES)
endif()
add_executable(zquest ${ZQUEST_CORE_SOURCES} ${ZQUEST_GUI_SOURCES} ${ZQUEST_MISC_SOURCES} ${ZQUEST_ZSCRIPT_SOURCES} ${ZQUESTEXTRASOURCES} ${BISON_ZScriptParser_OUTPUTS} ${FLEX_ZScriptLexer_OUTPUTS} ${ZQUEST_MODULES})
target_link_libraries(zquest zcsound ${IMAGELIBS} ${ALLEGROLIB} ${ZQUESTLIBSEXTRA})
if(MSVC AND USE_PCH)
set_target_properties(zquest PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h /Fp\"${ZQPrecompiledBinary}\"" OBJECT_DEPENDS "${ZQPrecompiledBinary}")
target_compile_definitions(zquest PRIVATE ZC_PCH)
endif()
if(MSVC)
target_compile_definitions(zcsound PRIVATE ZCM_DLL)
target_compile_definitions(zelda PRIVATE ZCM_DLL_IMPORT)
target_compile_definitions(zquest PRIVATE ZCM_DLL_IMPORT)
endif()