forked from tildearrow/furnace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
394 lines (355 loc) · 13.1 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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
cmake_minimum_required(VERSION 3.0)
if (APPLE)
set(MACOSX_DEPLOYMENT_TARGET 10.9)
endif()
project(furnace)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_PROJECT_VERSION_MAJOR 0)
set(CMAKE_PROJECT_VERSION_MINOR 5)
set(CMAKE_PROJECT_VERSION_PATCH 1)
if (ANDROID)
set(BUILD_GUI_DEFAULT OFF)
set(SYSTEM_SDL2_DEFAULT ON)
else()
set(BUILD_GUI_DEFAULT ON)
set(SYSTEM_SDL2_DEFAULT OFF)
endif()
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(JACK jack)
set(WITH_JACK_DEFAULT ${JACK_FOUND})
else()
set(WITH_JACK_DEFAULT OFF)
endif()
option(BUILD_GUI "Build the tracker (disable to build only a headless player)" ${BUILD_GUI_DEFAULT})
option(WITH_JACK "Whether to build with JACK support. Auto-detects if JACK is available" ${WITH_JACK_DEFAULT})
option(SYSTEM_FMT "Use a system-installed version of fmt instead of the vendored one" OFF)
option(SYSTEM_LIBSNDFILE "Use a system-installed version of libsndfile instead of the vendored one" OFF)
option(SYSTEM_ZLIB "Use a system-installed version of zlib instead of the vendored one" OFF)
option(SYSTEM_SDL2 "Use a system-installed version of SDL2 instead of the vendored one" ${SYSTEM_SDL2_DEFAULT})
option(WARNINGS_ARE_ERRORS "Whether warnings in furnace's C++ code should be treated as errors" OFF)
set(DEPENDENCIES_INCLUDE_DIRS "")
set(DEPENDENCIES_DEFINES "")
set(DEPENDENCIES_COMPILE_OPTIONS "")
set(DEPENDENCIES_LIBRARIES "")
set(DEPENDENCIES_LIBRARY_DIRS "")
set(DEPENDENCIES_LINK_OPTIONS "")
set(DEPENDENCIES_LEGACY_LDFLAGS "")
if (BUILD_GUI)
set(SYSTEM_SDL_MIN_VER 2.0.18)
else()
set(SYSTEM_SDL_MIN_VER 2.0.0)
endif()
find_package(Threads REQUIRED)
list(APPEND DEPENDENCIES_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
if (SYSTEM_FMT)
if (PKG_CONFIG_FOUND)
pkg_check_modules(FMT fmt)
if (FMT_FOUND)
list(APPEND DEPENDENCIES_INCLUDE_DIRS ${FMT_INCLUDE_DIRS})
list(APPEND DEPENDENCIES_COMPILE_OPTIONS ${FMT_CFLAGS_OTHER})
list(APPEND DEPENDENCIES_LIBRARIES ${FMT_LIBRARIES})
list(APPEND DEPENDENCIES_LIBRARY_DIRS ${FMT_LIBRARY_DIRS})
list(APPEND DEPENDENCIES_LINK_OPTIONS ${FMT_LDFLAGS_OTHER})
list(APPEND DEPENDENCIES_LEGACY_LDFLAGS ${FMT_LDFLAGS})
endif()
endif()
if (NOT FMT_FOUND)
find_package(fmt REQUIRED)
list(APPEND DEPENDENCIES_LIBRARIES fmt::fmt)
endif()
message(STATUS "Using system-installed fmt")
else()
add_subdirectory(extern/fmt EXCLUDE_FROM_ALL)
list(APPEND DEPENDENCIES_INCLUDE_DIRS extern/fmt/include)
list(APPEND DEPENDENCIES_LIBRARIES fmt)
message(STATUS "Using vendored fmt")
endif()
if (SYSTEM_LIBSNDFILE)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBSNDFILE REQUIRED sndfile)
list(APPEND DEPENDENCIES_INCLUDE_DIRS ${LIBSNDFILE_INCLUDE_DIRS})
list(APPEND DEPENDENCIES_COMPILE_OPTIONS ${LIBSNDFILE_CFLAGS_OTHER})
list(APPEND DEPENDENCIES_LIBRARIES ${LIBSNDFILE_LIBRARIES})
list(APPEND DEPENDENCIES_LIBRARY_DIRS ${LIBSNDFILE_LIBRARY_DIRS})
list(APPEND DEPENDENCIES_LINK_OPTIONS ${LIBSNDFILE_LDFLAGS_OTHER})
list(APPEND DEPENDENCIES_LEGACY_LDFLAGS ${LIBSNDFILE_LDFLAGS})
message(STATUS "Using system-installed libsndfile")
else()
set(BUILD_TESTING OFF CACHE BOOL "aaaaaa" FORCE)
set(BUILD_PROGRAMS OFF CACHE BOOL "aaa" FORCE)
set(BUILD_EXAMPLES OFF CACHE BOOL "a" FORCE)
set(ENABLE_EXTERNAL_LIBS OFF CACHE BOOL "come on" FORCE)
set(ENABLE_MPEG OFF CACHE BOOL "come on" FORCE)
add_subdirectory(extern/libsndfile EXCLUDE_FROM_ALL)
list(APPEND DEPENDENCIES_LIBRARIES sndfile)
message(STATUS "Using vendored libsndfile")
endif()
if (SYSTEM_ZLIB)
find_package(PkgConfig REQUIRED)
pkg_check_modules(ZLIB REQUIRED zlib)
list(APPEND DEPENDENCIES_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS})
list(APPEND DEPENDENCIES_COMPILE_OPTIONS ${ZLIB_CFLAGS_OTHER})
list(APPEND DEPENDENCIES_LIBRARIES ${ZLIB_LIBRARIES})
list(APPEND DEPENDENCIES_LIBRARY_DIRS ${ZLIB_LIBRARY_DIRS})
list(APPEND DEPENDENCIES_LINK_OPTIONS ${ZLIB_LDFLAGS_OTHER})
list(APPEND DEPENDENCIES_LEGACY_LDFLAGS ${ZLIB_LDFLAGS})
message(STATUS "Using system-installed zlib")
else()
set(BUILD_TESTING OFF CACHE BOOL "aaaaaa" FORCE)
set(BUILD_PROGRAMS OFF CACHE BOOL "aaa" FORCE)
set(BUILD_EXAMPLES OFF CACHE BOOL "a" FORCE)
set(ENABLE_EXTERNAL_LIBS OFF CACHE BOOL "come on" FORCE)
set(ENABLE_MPEG OFF CACHE BOOL "come on" FORCE)
add_subdirectory(extern/zlib EXCLUDE_FROM_ALL)
list(APPEND DEPENDENCIES_INCLUDE_DIRS extern/zlib ${CMAKE_CURRENT_BINARY_DIR}/extern/zlib)
list(APPEND DEPENDENCIES_LIBRARIES zlibstatic)
message(STATUS "Using vendored zlib")
endif()
if (SYSTEM_SDL2)
if (PKG_CONFIG_FOUND)
pkg_check_modules(SDL sdl>=${SYSTEM_SDL_MIN_VER})
if (SDL_FOUND)
list(APPEND DEPENDENCIES_INCLUDE_DIRS ${SDL_INCLUDE_DIRS})
list(APPEND DEPENDENCIES_COMPILE_OPTIONS ${SDL_CFLAGS_OTHER})
list(APPEND DEPENDENCIES_LIBRARIES ${SDL_LIBRARIES})
list(APPEND DEPENDENCIES_LIBRARY_DIRS ${SDL_LIBRARY_DIRS})
list(APPEND DEPENDENCIES_LINK_OPTIONS ${SDL_LDFLAGS_OTHER})
list(APPEND DEPENDENCIES_LEGACY_LDFLAGS ${SDL_LDFLAGS})
endif()
endif()
if (NOT SDL_FOUND)
find_package(SDL ${SYSTEM_SDL_MIN_VER})
if (SDL_FOUND)
list(APPEND DEPENDENCIES_INCLUDE_DIRS ${SDL_INCLUDE_DIR})
list(APPEND DEPENDENCIES_LIBRARIES ${SDL_LIBRARY})
else()
if (PKG_CONFIG_FOUND)
pkg_check_modules(SDL2 sdl2>=${SYSTEM_SDL_MIN_VER})
if (SDL2_FOUND)
list(APPEND DEPENDENCIES_INCLUDE_DIRS ${SDL2_INCLUDE_DIRS})
list(APPEND DEPENDENCIES_COMPILE_OPTIONS ${SDL2_CFLAGS_OTHER})
list(APPEND DEPENDENCIES_LIBRARIES ${SDL2_LIBRARIES})
list(APPEND DEPENDENCIES_LIBRARY_DIRS ${SDL2_LIBRARY_DIRS})
list(APPEND DEPENDENCIES_LINK_OPTIONS ${SDL2_LDFLAGS_OTHER})
list(APPEND DEPENDENCIES_LEGACY_LDFLAGS ${SDL2_LDFLAGS})
endif()
endif()
if (NOT SDL2_FOUND)
find_package(SDL2 ${SYSTEM_SDL_MIN_VER} REQUIRED)
list(APPEND DEPENDENCIES_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})
list(APPEND DEPENDENCIES_LIBRARIES ${SDL2_LIBRARY})
endif()
endif()
endif()
message(STATUS "Using system-installed SDL2")
else()
set(SDL_SHARED OFF)
set(SDL_STATIC ON)
add_subdirectory(extern/SDL EXCLUDE_FROM_ALL)
list(APPEND DEPENDENCIES_INCLUDE_DIRS extern/SDL/include)
list(APPEND DEPENDENCIES_LIBRARIES SDL2-static)
message(STATUS "Using vendored SDL2")
endif()
set(AUDIO_SOURCES
src/audio/abstract.cpp
src/audio/sdl.cpp
)
if(WITH_JACK)
find_package(PkgConfig REQUIRED)
pkg_check_modules(JACK REQUIRED jack)
list(APPEND AUDIO_SOURCES src/audio/jack.cpp)
list(APPEND DEPENDENCIES_INCLUDE_DIRS ${JACK_INCLUDE_DIRS})
list(APPEND DEPENDENCIES_DEFINES HAVE_JACK)
list(APPEND DEPENDENCIES_COMPILE_OPTIONS ${JACK_CFLAGS_OTHER})
list(APPEND DEPENDENCIES_LIBRARIES ${JACK_LIBRARIES})
list(APPEND DEPENDENCIES_LIBRARY_DIRS ${JACK_LIBRARY_DIRS})
list(APPEND DEPENDENCIES_LINK_OPTIONS ${JACK_LDFLAGS_OTHER})
list(APPEND DEPENDENCIES_LEGACY_LDFLAGS ${JACK_LDFLAGS})
message(STATUS "Building with JACK support")
else()
message(STATUS "Building without JACK support")
endif()
set(ENGINE_SOURCES
src/log.cpp
src/fileutils.cpp
src/utfutils.cpp
extern/Nuked-OPN2/ym3438.c
extern/opm/opm.c
src/engine/platform/sound/sn76496.cpp
src/engine/platform/sound/ay8910.cpp
src/engine/platform/sound/saa1099.cpp
src/engine/platform/sound/gb/apu.c
src/engine/platform/sound/gb/timing.c
src/engine/platform/sound/pce_psg.cpp
src/engine/platform/sound/nes/apu.c
src/engine/platform/sound/c64/sid.cc
src/engine/platform/sound/c64/voice.cc
src/engine/platform/sound/c64/wave.cc
src/engine/platform/sound/c64/envelope.cc
src/engine/platform/sound/c64/filter.cc
src/engine/platform/sound/c64/extfilt.cc
src/engine/platform/sound/c64/pot.cc
src/engine/platform/sound/c64/version.cc
src/engine/platform/sound/c64/wave6581_PS_.cc
src/engine/platform/sound/c64/wave6581_PST.cc
src/engine/platform/sound/c64/wave6581_P_T.cc
src/engine/platform/sound/c64/wave6581__ST.cc
src/engine/platform/sound/c64/wave8580_PS_.cc
src/engine/platform/sound/c64/wave8580_PST.cc
src/engine/platform/sound/c64/wave8580_P_T.cc
src/engine/platform/sound/c64/wave8580__ST.cc
src/engine/platform/sound/tia/TIASnd.cpp
src/engine/platform/sound/ymfm/ymfm_adpcm.cpp
src/engine/platform/sound/ymfm/ymfm_opm.cpp
src/engine/platform/sound/ymfm/ymfm_opn.cpp
src/engine/platform/sound/ymfm/ymfm_ssg.cpp
src/engine/platform/ym2610Interface.cpp
src/engine/blip_buf.c
src/engine/safeReader.cpp
src/engine/safeWriter.cpp
src/engine/dispatchContainer.cpp
src/engine/engine.cpp
src/engine/instrument.cpp
src/engine/macroInt.cpp
src/engine/pattern.cpp
src/engine/playback.cpp
src/engine/sample.cpp
src/engine/song.cpp
src/engine/wavetable.cpp
src/engine/platform/abstract.cpp
src/engine/platform/genesis.cpp
src/engine/platform/genesisext.cpp
src/engine/platform/sms.cpp
src/engine/platform/gb.cpp
src/engine/platform/pce.cpp
src/engine/platform/nes.cpp
src/engine/platform/c64.cpp
src/engine/platform/arcade.cpp
src/engine/platform/ym2610.cpp
src/engine/platform/ym2610ext.cpp
src/engine/platform/ay.cpp
src/engine/platform/ay8930.cpp
src/engine/platform/tia.cpp
src/engine/platform/saa.cpp
src/engine/platform/amiga.cpp
src/engine/platform/dummy.cpp
)
if (WIN32)
list(APPEND ENGINE_SOURCES src/utfutils.cpp)
list(APPEND ENGINE_SOURCES src/engine/winStuff.cpp)
list(APPEND ENGINE_SOURCES res/furnace.rc)
endif()
set(GUI_SOURCES
extern/imgui/imgui.cpp
extern/imgui/imgui_draw.cpp
extern/imgui/imgui_tables.cpp
extern/imgui/imgui_widgets.cpp
extern/imgui/backends/imgui_impl_sdlrenderer.cpp
extern/imgui/backends/imgui_impl_sdl.cpp
extern/imgui/misc/cpp/imgui_stdlib.cpp
extern/igfd/ImGuiFileDialog.cpp
src/gui/plot_nolerp.cpp
src/gui/font_exo.cpp
src/gui/font_liberationSans.cpp
src/gui/font_mononoki.cpp
src/gui/font_plexMono.cpp
src/gui/font_plexSans.cpp
src/gui/font_proggyClean.cpp
src/gui/font_ptMono.cpp
src/gui/font_unifont.cpp
src/gui/font_icon.cpp
src/gui/fonts.cpp
src/gui/debug.cpp
src/gui/gui.cpp
)
if (NOT WIN32 AND NOT APPLE)
list(APPEND GUI_SOURCES src/gui/icon.c)
endif()
set(USED_SOURCES ${ENGINE_SOURCES} ${AUDIO_SOURCES} src/main.cpp)
if (BUILD_GUI)
list(APPEND USED_SOURCES ${GUI_SOURCES})
list(APPEND DEPENDENCIES_INCLUDE_DIRS
extern/imgui
extern/imgui/backends
extern/IconFontCppHeaders
extern/igfd
)
list(APPEND DEPENDENCIES_DEFINES HAVE_GUI)
message(STATUS "Building GUI")
else()
message(STATUS "Building headless")
endif()
if (WIN32)
list(APPEND DEPENDENCIES_LIBRARIES shlwapi)
if (NOT MSVC)
list(APPEND DEPENDENCIES_LIBRARIES -static)
endif()
endif()
if (NOT MSVC)
set(WARNING_FLAGS -Wall -Wextra -Wno-unused-parameter)
if (WARNINGS_ARE_ERRORS)
list(APPEND WARNING_FLAGS -Werror)
endif()
else()
# /wd4100 == -Wno-unused-parameter
set(WARNING_FLAGS /W4 /wd4100 /D_CRT_SECURE_NO_WARNINGS)
if (WARNINGS_ARE_ERRORS)
list(APPEND WARNING_FLAGS /WX)
endif()
endif()
# Nicer but cannot be narrowed down to just C++
# target_compile_options(furnace PRIVATE ${WARNING_FLAGS})
string(REPLACE ";" " " WARNING_FLAGS_STRING "${WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS_STRING}")
if (WARNINGS_ARE_ERRORS)
message(WARNING
"Treating all warnings in furnace's C++ code as errors! "
"Please report any errors you encounter on the bug tracker."
)
endif()
if (MSVC)
add_executable(furnace WIN32 ${USED_SOURCES})
else()
add_executable(furnace ${USED_SOURCES})
endif()
target_include_directories(furnace SYSTEM PRIVATE ${DEPENDENCIES_INCLUDE_DIRS})
target_compile_definitions(furnace PRIVATE ${DEPENDENCIES_DEFINES})
target_compile_options(furnace PRIVATE ${DEPENDENCIES_COMPILE_OPTIONS})
target_link_libraries(furnace PRIVATE ${DEPENDENCIES_LIBRARIES})
if (PKG_CONFIG_FOUND AND (SYSTEM_FMT OR SYSTEM_LIBSNDFILE OR SYSTEM_ZLIB OR SYSTEM_SDL2 OR WITH_JACK))
if ("${CMAKE_VERSION}" VERSION_LESS "3.13")
message(WARNING
"CMake version is <3.13, using old pkg-config LDFLAGS. "
"You may encounter linking problems with these!"
)
target_link_libraries(furnace PRIVATE ${DEPENDENCIES_LEGACY_LDFLAGS})
else()
target_link_directories(furnace PRIVATE ${DEPENDENCIES_LIBRARY_DIRS})
target_link_options(furnace PRIVATE ${DEPENDENCIES_LINK_OPTIONS})
endif()
endif()
install(TARGETS furnace RUNTIME DESTINATION bin)
if (NOT WIN32 AND NOT APPLE)
include(GNUInstallDirs)
install(FILES res/furnace.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
install(FILES res/furnace.appdata.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo)
install(DIRECTORY papers DESTINATION ${CMAKE_INSTALL_DOCDIR})
install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DATADIR}/licenses)
install(DIRECTORY demos DESTINATION ${CMAKE_INSTALL_DATADIR}/furnace)
install(FILES res/logo.png RENAME furnace.png DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/1024x1024/apps)
endif()
set(CPACK_PACKAGE_NAME "Furnace")
set(CPACK_PACKAGE_VENDOR "tildearrow")
set(CPACK_PACKAGE_DESCRIPTION "free and open-source chiptune tracker")
if (APPLE)
set(CPACK_GENERATOR Bundle)
set(CPACK_DMG_SLA_DIR ${CMAKE_SOURCE_DIR}/res/macLicense)
set(CPACK_DMG_SLA_LANGUAGES en)
set(CPACK_BUNDLE_NAME "Furnace")
set(CPACK_DMG_VOLUME_NAME "Furnace")
set(CPACK_BUNDLE_PLIST ${CMAKE_SOURCE_DIR}/res/Info.plist)
set(CPACK_BUNDLE_ICON ${CMAKE_SOURCE_DIR}/res/icon.icns)
set(CPACK_BUNDLE_STARTUP_COMMAND "furnace")
endif()
include(CPack)