forked from leafo/goattracker2
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
263 lines (227 loc) · 6.77 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
cmake_minimum_required(VERSION 3.9)
project(goattracker2)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR
"${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
add_compile_options("$<$<CONFIG:DEBUG>:-Wall;-Wextra;-pedantic>")
endif()
option(INLINING "enable inlining of functions" ON)
option(BRANCH_HINTS "enable static branch prediction hints" ON)
option(NEW_FILTER "enable new 8580 filter implementation" ON)
if(NEW_FILTER)
set(FILTER_SRC src/resid/filter8580new.cc)
else()
set(FILTER_SRC src/resid/filter.cc)
endif()
set(GOATTRK2_SOURCES
${CMAKE_BINARY_DIR}/src/goatdata.c
src/goattrk2.c
src/gsong.c
src/gorder.c
src/gpattern.c
src/ginstr.c
src/gtable.c
src/gplay.c
src/gdisplay.c
src/gfile.c
src/greloc.c
src/ghelp.c
src/gsound.c
src/gconsole.c
src/gsid.cpp
src/resid/dac.cc
src/resid/envelope.cc
src/resid/extfilt.cc
${FILTER_SRC}
src/resid/pot.cc
src/resid/sid.cc
src/resid/wave.cc
src/resid/voice.cc
src/asm/asmtab.c
src/asm/chnkpool.c
src/asm/expr.c
src/asm/lexyy.c
src/asm/log.c
src/asm/membuf.c
src/asm/membufio.c
src/asm/namedbuf.c
src/asm/parse.c
src/asm/pc.c
src/asm/vec.c
src/bme/bme_gfx.c
src/bme/bme_snd.c
src/bme/bme_win.c
src/bme/bme_mou.c
src/bme/bme_kbd.c
src/bme/bme_io.c
src/bme/bme_end.c
src/bme/bme.c
src/rtmidi/rtmidi_c.h
src/rtmidi/rtmidi_c.cpp
src/rtmidi/RtMidi.h
src/rtmidi/RtMidi.cpp)
if(MINGW)
list(APPEND GOATTRK2_SOURCES
src/goattrk2.rc
)
endif(MINGW)
# it would be nice not having to link things like resid, however the source is
# not ready for that
set(GT2RELOC_SOURCES
${CMAKE_BINARY_DIR}/src/goatdata.c
src/gt2reloc.c
src/gsong.c
src/gorder.c
src/gpattern.c
src/ginstr.c
src/gtable.c
src/gplay.c
src/gdisplay.c
src/gfile.c
src/ghelp.c
src/gsound.c
src/gconsole.c
src/gsid.cpp
src/resid/dac.cc
src/resid/envelope.cc
src/resid/extfilt.cc
${FILTER_SRC}
src/resid/pot.cc
src/resid/sid.cc
src/resid/wave.cc
src/resid/voice.cc
src/asm/asmtab.c
src/asm/chnkpool.c
src/asm/expr.c
src/asm/lexyy.c
src/asm/log.c
src/asm/membuf.c
src/asm/membufio.c
src/asm/namedbuf.c
src/asm/parse.c
src/asm/pc.c
src/asm/vec.c
src/bme/bme_gfx.c
src/bme/bme_snd.c
src/bme/bme_win.c
src/bme/bme_mou.c
src/bme/bme_kbd.c
src/bme/bme_io.c
src/bme/bme_end.c
src/bme/bme.c)
set(MOD2SNG_SOURCES
src/mod2sng.c
src/bme/bme_end.c)
set(INS2SND2_SOURCES
src/ins2snd2.c
src/bme/bme_end.c)
set(SNGSPLI2_SOURCES
src/sngspli2.c
src/bme/bme_end.c)
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_SOURCE_DIR}/src/bme)
include_directories(${CMAKE_SOURCE_DIR}/src/asm)
include_directories(${CMAKE_BINARY_DIR}/src/resid)
find_package(SDL2 REQUIRED)
get_target_property(SDL2_INCLUDE_DIRS SDL2::SDL2 INTERFACE_INCLUDE_DIRECTORIES)
add_executable(datafile src/bme/datafile.c src/bme/bme_end.c)
add_executable(dat2inc src/bme/dat2inc.c)
target_include_directories(datafile PUBLIC ${SDL2_INCLUDE_DIRS})
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/src/goattrk2.dat
COMMAND datafile ${CMAKE_BINARY_DIR}/src/goattrk2.dat goattrk2.seq
DEPENDS datafile
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src
)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/src/goatdata.c
COMMAND dat2inc goattrk2.dat goatdata.c
DEPENDS dat2inc ${CMAKE_BINARY_DIR}/src/goattrk2.dat
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src
)
add_executable(goattrk2 ${GOATTRK2_SOURCES})
add_executable(gt2reloc ${GT2RELOC_SOURCES})
add_executable(mod2sng ${MOD2SNG_SOURCES})
add_executable(ins2snd2 ${INS2SND2_SOURCES})
add_executable(sngspli2 ${SNGSPLI2_SOURCES})
add_custom_target(goatdata DEPENDS ${CMAKE_BINARY_DIR}/src/goatdata.c)
add_dependencies(goattrk2 goatdata)
add_dependencies(gt2reloc goatdata)
target_include_directories(mod2sng PUBLIC ${SDL2_INCLUDE_DIRS})
target_include_directories(ins2snd2 PUBLIC ${SDL2_INCLUDE_DIRS})
target_include_directories(sngspli2 PUBLIC ${SDL2_INCLUDE_DIRS})
if(MINGW)
set(LIB_MINGW mingw32)
endif()
if(TARGET SDL2::SDL2main)
target_link_libraries(goattrk2 ${LIB_MINGW} SDL2::SDL2main)
target_link_libraries(gt2reloc ${LIB_MINGW} SDL2::SDL2main)
endif()
OPTION(STATIC "Static build" OFF)
IF(STATIC)
set(CMAKE_EXE_LINKER_FLAGS "-static")
target_link_libraries(goattrk2 SDL2::SDL2-static)
target_link_libraries(gt2reloc SDL2::SDL2-static)
ELSE(STATIC)
target_link_libraries(goattrk2 SDL2::SDL2)
target_link_libraries(gt2reloc SDL2::SDL2)
ENDIF(STATIC)
find_package(Jack)
IF(JACK_FOUND)
target_compile_definitions(goattrk2 PUBLIC USE_JACK __UNIX_JACK__)
include_directories(${JACK_INCLUDE_DIR})
target_link_libraries(goattrk2 ${JACK_LIBRARY})
set(use_midi ON)
ENDIF(JACK_FOUND)
find_package(ALSA)
if (ALSA_FOUND)
target_compile_definitions(goattrk2 PUBLIC __LINUX_ALSA__)
include_directories(${ALSA_INCLUDE_DIR})
target_link_libraries(goattrk2 ${ALSA_LIBRARY} pthread)
set(use_midi ON)
endif(ALSA_FOUND)
if(APPLE)
find_library(COREMIDI CoreMIDI)
find_library(COREAUDIO CoreAudio)
find_library(COREFOUNDATION CoreFoundation)
target_compile_definitions(goattrk2 PUBLIC __MACOSX_CORE__)
target_link_libraries(goattrk2 ${COREMIDI} ${COREAUDIO} ${COREFOUNDATION} pthread)
set(use_midi ON)
endif(APPLE)
if(WIN32 OR MINGW)
target_compile_definitions(goattrk2 PUBLIC __WINDOWS_MM__)
target_link_libraries(goattrk2 winmm)
set(use_midi ON)
endif()
if (use_midi)
target_compile_definitions(goattrk2 PUBLIC USE_MIDI_INPUT)
endif(use_midi)
find_package(ExSID)
if (EXSID_FOUND)
target_compile_definitions(goattrk2 PUBLIC USE_EXSID)
include_directories(${EXSID_INCLUDE_DIR})
target_link_libraries(goattrk2 ${EXSID_LIBRARY})
endif(EXSID_FOUND)
# create siddefs.h for resid
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("int main() { __builtin_expect(0, 0); }" HAVE_BUILTIN_EXPECT)
check_cxx_source_compiles("include <math.h>\nint main() { double x = log1p(1.0); }" HAVE_LOG1P)
macro(get_bool var)
if(${ARGN})
set(${var} 1)
else()
set(${var} 0)
endif()
endmacro()
get_bool(RESID_INLINING ${INLINING})
set(RESID_INLINE "inline")
get_bool(RESID_BRANCH_HINTS ${BRANCH_HINTS})
get_bool(NEW_8580_FILTER ${NEW_FILTER})
set(HAVE_BOOL "1")
get_bool(HAVE_BUILTIN_EXPECT ${HAVE_BUILTIN_EXPECT})
get_bool(HAVE_LOG1P ${HAVE_LOG1P})
configure_file(${CMAKE_SOURCE_DIR}/src/resid/siddefs.h.in ${CMAKE_BINARY_DIR}/src/resid/siddefs.h @ONLY)