-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
590 lines (516 loc) · 21.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
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
cmake_minimum_required (VERSION 3.2...3.5)
project(libOPNMIDI VERSION 1.5.1 LANGUAGES C CXX)
include(GNUInstallDirs)
include(CheckCXXCompilerFlag)
# Prefer C90 standard
set(CMAKE_C_STANDARD 90)
# Prefer C++98 standard
set(CMAKE_CXX_STANDARD 98)
if(MSVC)
check_cxx_compiler_flag("/std:c++14" COMPILER_SUPPORTS_CXX14)
if(COMPILER_SUPPORTS_CXX14)
set(FLAG_CPP14 "/std:c++14")
endif()
if(MSVC_VERSION LESS 1910)
unset(COMPILER_SUPPORTS_CXX14) # MSVC older than 2017 fails to build YMFM
endif()
else()
check_cxx_compiler_flag("-std=c++14" COMPILER_SUPPORTS_CXX14)
if(COMPILER_SUPPORTS_CXX14)
set(FLAG_CPP14 "-std=c++14")
endif()
endif()
if(COMPILER_SUPPORTS_CXX14)
message("== Your C++ compiler supports C++14, YMFM emulator will be ENABLED")
else()
message("== Your C++ compiler does NOT supports C++14, YMFM emulator will be DISABLED")
endif()
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
#===========================================================================================
# Strip garbage
if(APPLE)
set(LINK_FLAGS_RELEASE "${LINK_FLAGS_RELEASE} -dead_strip")
elseif(NOT MSVC AND NOT MSDOS AND NOT OPENBSD_LOCALBASE)
string(REGEX REPLACE "-O3" ""
CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REGEX REPLACE "-O3" ""
CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -fdata-sections -ffunction-sections")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fdata-sections -ffunction-sections")
if(ANDROID)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -funwind-tables")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -funwind-tables")
endif()
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s -Wl,--gc-sections -Wl,-s")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s -Wl,--gc-sections -Wl,-s")
set(LINK_FLAGS_RELEASE "${LINK_FLAGS_RELEASE} -Wl,--gc-sections -Wl,-s")
endif()
endif()
# Global optimization flags
if(NOT MSVC AND NOT MSDOS)
# Global optimization flags
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-omit-frame-pointer")
# Turn on all warnings
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
# Deny undefined symbols
if(NOT APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined" )
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" )
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined" )
endif()
# Supress the std::vector::insert() GCC change warning
if(VITA)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DVITA -DVITA=1 -fcompare-debug-second")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVITA -DVITA=1 -fcompare-debug-second")
endif()
if(NINTENDO_3DS OR NINTENDO_WII OR NINTENDO_WIIU OR NINTENDO_SWITCH)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcompare-debug-second")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcompare-debug-second")
endif()
endif()
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(NINTENDO_3DS OR NINTENDO_WII OR NINTENDO_WIIU OR NINTENDO_SWITCH)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu90")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98")
endif()
if(DEFINED CMAKE_BUILD_TYPE)
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
endif()
if(CMAKE_BUILD_TYPE_LOWER EQUAL "release")
add_definitions(-DNDEBUG)
ENDIF()
# Disable bogus MSVC warnings
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
ENDIF()
if(OPENBSD_LOCALBASE)
message("OpenBSD Detected!")
include_directories(/usr/local/include)
endif()
if(WIN32)
add_definitions(-DUNICODE -D_UNICODE)
endif()
function(set_legacy_standard destTarget)
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
# Turn on warnings and legacy C/C++ standards to support more compilers
target_compile_options(${destTarget} PRIVATE
$<$<COMPILE_LANGUAGE:C>:-Wall -pedantic -std=gnu90>
$<$<COMPILE_LANGUAGE:CXX>:-Wall -pedantic -std=gnu++98>
)
endif()
endfunction()
function(set_visibility_hidden destTarget)
if(CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang)$" AND NOT DJGPP)
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_GREATER 3.2)
target_compile_options(${destTarget} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-fvisibility-inlines-hidden> -fvisibility=hidden)
else()
target_compile_options(${destTarget} PRIVATE -fvisibility=hidden)
endif()
target_compile_definitions(${destTarget} PRIVATE -DLIBOPNMIDI_VISIBILITY)
endif()
endfunction()
#===========================================================================================
if(VITA OR NINTENDO_3DS OR NINTENDO_WII OR NINTENDO_WIIU)
set(DEFAULT_HEAVY_EMULATORS OFF)
else()
set(DEFAULT_HEAVY_EMULATORS ON)
endif()
if(NOT EMSCRIPTEN
AND NOT VITA
AND NOT NINTENDO_3DS
AND NOT NINTENDO_WII
AND NOT NINTENDO_WIIU
AND NOT NINTENDO_SWITCH
AND NOT MSDOS)
set(libOPNMIDI_STATIC_ENABLED_BY_DEFAULT ON)
set(libOPNMIDI_SHARED_ENABLED_BY_DEFAULT OFF)
# When defined, respect CMake's BUILD_SHARED_LIBS setting
if (BUILD_SHARED_LIBS)
set(libOPNMIDI_SHARED_ENABLED_BY_DEFAULT ON)
set(libOPNMIDI_STATIC_ENABLED_BY_DEFAULT OFF)
endif()
option(libOPNMIDI_STATIC "Build static library of libOPNMIDI" ${libOPNMIDI_STATIC_ENABLED_BY_DEFAULT})
option(libOPNMIDI_SHARED "Build shared library of libOPNMIDI" ${libOPNMIDI_SHARED_ENABLED_BY_DEFAULT})
else()
set(libOPNMIDI_STATIC ON)
set(libOPNMIDI_SHARED OFF)
endif()
option(WITH_MIDI_SEQUENCER "Build with embedded MIDI sequencer. Disable this if you want use library in real-time MIDI drivers or plugins.)" ON)
option(WITH_HQ_RESAMPLER "Build with support for high quality resampling" OFF)
option(WITH_MUS_SUPPORT "Build with support for DMX MUS files)" ON)
option(WITH_XMI_SUPPORT "Build with support for AIL XMI files)" ON)
option(USE_MAME_EMULATOR "Use MAME YM2612 emulator (for most of hardware)" ON)
option(USE_GENS_EMULATOR "Use GENS 2.10 emulator (fastest, very outdated, inaccurate)" ON)
option(USE_NUKED_EMULATOR "Use Nuked OPN2 emulator (most accurate, heavy)" ${DEFAULT_HEAVY_EMULATORS})
option(USE_GX_EMULATOR "Use Genesis Plus GX emulator (experimental)" OFF)
option(USE_NP2_EMULATOR "Use Neko Project II emulator" ON)
option(USE_MAME_2608_EMULATOR "Use MAME YM2608 emulator" ON)
option(USE_PMDWIN_EMULATOR "Use PMDWin emulator (experimental)" OFF)
option(USE_VGM_FILE_DUMPER "Use VGM File Dumper (required to build the MIDI2VGM tool)" ON)
if(COMPILER_SUPPORTS_CXX14)
option(USE_YMFM_EMULATOR "Use YMFM emulator (requires C++14 support)" ON)
endif()
# WIP FEATURES
# option(WITH_CPP_EXTRAS "Build with support for C++ extras (features are can be found in 'adlmidi.hpp' header)" OFF)
option(WITH_MIDIPLAY "Build also demo MIDI player" OFF)
option(WITH_MIDI2VGM "Build also MIDI to VGM converter tool" OFF)
option(WITH_WOPN2HPP "Build also the WOPN to C++ header source converter tool" OFF)
option(WITH_VLC_PLUGIN "Build also a plugin for VLC Media Player" OFF)
option(VLC_PLUGIN_NOINSTALL "Don't install VLC plugin into VLC directory" OFF)
option(WITH_DAC_UTIL "Build also OPN2 DAC testing utility" OFF)
option(WITH_EXTRA_BANKS "Install extra bank files" OFF)
if(WIN32)
option(WITH_WINMMDRV "Build a WinMM MIDI driver" OFF)
endif()
include_directories(${libOPNMIDI_SOURCE_DIR}/include)
include_directories(${libOPNMIDI_SOURCE_DIR}/src/)
link_directories(${libOPNMIDI_BINARY_DIR}/)
set(libOPNMIDI_SOURCES)
list(APPEND libOPNMIDI_SOURCES
${libOPNMIDI_SOURCE_DIR}/src/opnmidi.cpp
${libOPNMIDI_SOURCE_DIR}/src/opnmidi_load.cpp
${libOPNMIDI_SOURCE_DIR}/src/opnmidi_midiplay.cpp
${libOPNMIDI_SOURCE_DIR}/src/opnmidi_opn2.cpp
${libOPNMIDI_SOURCE_DIR}/src/opnmidi_private.cpp
${libOPNMIDI_SOURCE_DIR}/src/wopn/wopn_file.c
)
# Make headers being properly visible at IDEs
file(GLOB libOPNMIDI_HEADERS
${libOPNMIDI_SOURCE_DIR}/include/*.h
${libOPNMIDI_SOURCE_DIR}/src/*.h
${libOPNMIDI_SOURCE_DIR}/src/*.hpp
${libOPNMIDI_SOURCE_DIR}/src/wopn/*.h
${libOPNMIDI_SOURCE_DIR}/src/structures/*.hpp
${libOPNMIDI_SOURCE_DIR}/src/chips/*.h
${libOPNMIDI_SOURCE_DIR}/src/chips/gens/*.hpp
${libOPNMIDI_SOURCE_DIR}/src/chips/gx/*.h
${libOPNMIDI_SOURCE_DIR}/src/chips/mame/*.h
${libOPNMIDI_SOURCE_DIR}/src/chips/mamefm/*.h
${libOPNMIDI_SOURCE_DIR}/src/chips/np2/*.h
${libOPNMIDI_SOURCE_DIR}/src/chips/nuked/*.h
${libOPNMIDI_SOURCE_DIR}/src/chips/pmdwin/*.h
${libOPNMIDI_SOURCE_DIR}/src/chips/ymfm/*.h
${libOPNMIDI_SOURCE_DIR}/src/chips/ymfm/*.hpp
)
list(APPEND libOPNMIDI_SOURCES ${libOPNMIDI_HEADERS})
if(WITH_MIDI_SEQUENCER)
list(APPEND libOPNMIDI_SOURCES
${libOPNMIDI_SOURCE_DIR}/src/opnmidi_sequencer.cpp
)
add_definitions(-DENABLE_END_SILENCE_SKIPPING)
endif()
if(NOT WITH_MUS_SUPPORT OR NOT WITH_MIDI_SEQUENCER)
add_definitions(-DBWMIDI_DISABLE_MUS_SUPPORT)
endif()
if(NOT WITH_XMI_SUPPORT OR NOT WITH_MIDI_SEQUENCER)
add_definitions(-DBWMIDI_DISABLE_XMI_SUPPORT)
endif()
if(USE_GENS_EMULATOR)
list(APPEND libOPNMIDI_SOURCES
${libOPNMIDI_SOURCE_DIR}/src/chips/gens_opn2.cpp
${libOPNMIDI_SOURCE_DIR}/src/chips/gens/Ym2612.cpp
)
set(HAS_EMULATOR TRUE)
else()
add_definitions(-DOPNMIDI_DISABLE_GENS_EMULATOR)
endif()
if(USE_MAME_EMULATOR)
list(APPEND libOPNMIDI_SOURCES
${libOPNMIDI_SOURCE_DIR}/src/chips/mame_opn2.cpp
${libOPNMIDI_SOURCE_DIR}/src/chips/mame/mame_ym2612fm.c
)
set(HAS_EMULATOR TRUE)
else()
add_definitions(-DOPNMIDI_DISABLE_MAME_EMULATOR)
endif()
if(USE_NUKED_EMULATOR)
list(APPEND libOPNMIDI_SOURCES
${libOPNMIDI_SOURCE_DIR}/src/chips/nuked_opn2.cpp
${libOPNMIDI_SOURCE_DIR}/src/chips/nuked/ym3438.c
)
set(HAS_EMULATOR TRUE)
else()
add_definitions(-DOPNMIDI_DISABLE_NUKED_EMULATOR)
endif()
#if(USE_GX_EMULATOR)
# list(APPEND libOPNMIDI_SOURCES
# ${libOPNMIDI_SOURCE_DIR}/src/chips/gx_opn2.cpp
# ${libOPNMIDI_SOURCE_DIR}/src/chips/gx/gx_ym2612.c
# )
# set(HAS_EMULATOR TRUE)
#else()
# add_definitions(-DOPNMIDI_DISABLE_GX_EMULATOR)
#endif()
if(USE_NP2_EMULATOR)
list(APPEND libOPNMIDI_SOURCES
${libOPNMIDI_SOURCE_DIR}/src/chips/np2_opna.cpp
${libOPNMIDI_SOURCE_DIR}/src/chips/np2/fmgen_opna.cpp
${libOPNMIDI_SOURCE_DIR}/src/chips/np2/fmgen_file.cpp
${libOPNMIDI_SOURCE_DIR}/src/chips/np2/fmgen_fmgen.cpp
${libOPNMIDI_SOURCE_DIR}/src/chips/np2/fmgen_fmtimer.cpp
${libOPNMIDI_SOURCE_DIR}/src/chips/np2/fmgen_opna.cpp
${libOPNMIDI_SOURCE_DIR}/src/chips/np2/fmgen_psg.cpp)
set(HAS_EMULATOR TRUE)
else()
add_definitions(-DOPNMIDI_DISABLE_NP2_EMULATOR)
endif()
if(USE_MAME_2608_EMULATOR)
list(APPEND libOPNMIDI_SOURCES
${libOPNMIDI_SOURCE_DIR}/src/chips/mame_opna.cpp
${libOPNMIDI_SOURCE_DIR}/src/chips/mamefm/fm.cpp
${libOPNMIDI_SOURCE_DIR}/src/chips/mamefm/ymdeltat.cpp
${libOPNMIDI_SOURCE_DIR}/src/chips/mamefm/emu2149.c
${libOPNMIDI_SOURCE_DIR}/src/chips/mamefm/resampler.cpp)
set(HAS_EMULATOR TRUE)
else()
add_definitions(-DOPNMIDI_DISABLE_MAME_2608_EMULATOR)
endif()
#if(USE_PMDWIN_EMULATOR)
# list(APPEND libOPNMIDI_SOURCES
# ${libOPNMIDI_SOURCE_DIR}/src/chips/pmdwin_opna.cpp
# ${libOPNMIDI_SOURCE_DIR}/src/chips/pmdwin/opna.c
# ${libOPNMIDI_SOURCE_DIR}/src/chips/pmdwin/psg.c
# ${libOPNMIDI_SOURCE_DIR}/src/chips/pmdwin/rhythmdata.c)
# set(HAS_EMULATOR TRUE)
#else()
# add_definitions(-DOPNMIDI_DISABLE_PMDWIN_EMULATOR)
#endif()
if(USE_VGM_FILE_DUMPER)
list(APPEND libOPNMIDI_SOURCES
${libOPNMIDI_SOURCE_DIR}/src/chips/vgm_file_dumper.cpp)
set(HAS_EMULATOR TRUE)
add_definitions(-DOPNMIDI_MIDI2VGM)
endif()
if(USE_YMFM_EMULATOR)
set(YMFM_SOURCES
"${libOPNMIDI_SOURCE_DIR}/src/chips/ymfm_opn2.cpp"
"${libOPNMIDI_SOURCE_DIR}/src/chips/ymfm_opna.cpp"
"${libOPNMIDI_SOURCE_DIR}/src/chips/ymfm/ymfm_opn.cpp"
"${libOPNMIDI_SOURCE_DIR}/src/chips/ymfm/ymfm_misc.cpp"
"${libOPNMIDI_SOURCE_DIR}/src/chips/ymfm/ymfm_pcm.cpp"
"${libOPNMIDI_SOURCE_DIR}/src/chips/ymfm/ymfm_adpcm.cpp"
"${libOPNMIDI_SOURCE_DIR}/src/chips/ymfm/ymfm_ssg.cpp"
)
if(DEFINED FLAG_CPP14)
set_source_files_properties(${YMFM_SOURCES} COMPILE_FLAGS ${FLAG_CPP14})
endif()
list(APPEND libOPNMIDI_SOURCES ${YMFM_SOURCES})
set(HAS_EMULATOR TRUE)
else()
add_definitions(-DOPNMIDI_DISABLE_YMFM_EMULATOR)
endif()
if(NOT HAS_EMULATOR)
message(FATAL_ERROR "No emulators enabled! You should enable at least one emulator!")
endif()
if(NOT WITH_MIDI_SEQUENCER)
add_definitions(-DOPNMIDI_DISABLE_MIDI_SEQUENCER)
endif()
if(NOT WIN32
AND NOT VITA
AND NOT NINTENDO_3DS
AND NOT NINTENDO_WII
AND NOT NINTENDO_WIIU
AND NOT EMSCRIPTEN
AND NOT MSDOS)
option(ENABLE_FPIC "Build static libraries as position independent code" ON)
else()
set(ENABLE_FPIC OFF)
endif()
# === Static library ====
if(libOPNMIDI_STATIC OR WITH_VLC_PLUGIN)
add_library(OPNMIDI_static STATIC ${libOPNMIDI_SOURCES})
if(WIN32 AND libOPNMIDI_SHARED)
set_target_properties(OPNMIDI_static PROPERTIES OUTPUT_NAME OPNMIDI-static)
else()
set_target_properties(OPNMIDI_static PROPERTIES OUTPUT_NAME OPNMIDI)
endif()
target_include_directories(OPNMIDI_static PUBLIC $<BUILD_INTERFACE:${libOPNMIDI_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
set_legacy_standard(OPNMIDI_static)
set_visibility_hidden(OPNMIDI_static)
# -fPIC thing
if(ENABLE_FPIC)
set_target_properties(OPNMIDI_static PROPERTIES COMPILE_FLAGS "-fPIC")
endif()
if(NOT libOPNMIDI_STATIC)
set_target_properties(OPNMIDI_static PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()
endif()
# === Shared library ====
if(libOPNMIDI_SHARED)
add_library(OPNMIDI_shared SHARED ${libOPNMIDI_SOURCES})
set_target_properties(OPNMIDI_shared PROPERTIES OUTPUT_NAME OPNMIDI)
set_target_properties(OPNMIDI_shared PROPERTIES
VERSION ${libOPNMIDI_VERSION}
SOVERSION ${libOPNMIDI_VERSION_MAJOR}
)
target_include_directories(OPNMIDI_shared PUBLIC $<BUILD_INTERFACE:${libOPNMIDI_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
set_legacy_standard(OPNMIDI_shared)
set_visibility_hidden(OPNMIDI_shared)
if(WIN32)
target_compile_definitions(OPNMIDI_shared PRIVATE "-DOPNMIDI_BUILD_DLL")
if(CMAKE_COMPILER_IS_GNUCXX)
set_property(TARGET OPNMIDI_shared APPEND_STRING PROPERTY LINK_FLAGS " -static-libgcc -static-libstdc++")
set_property(TARGET OPNMIDI_shared APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-Bstatic,--whole-archive -lpthread -Wl,-Bdynamic,--no-whole-archive")
endif()
endif()
if(OPENBSD_LOCALBASE)
set_property(TARGET OPNMIDI_shared APPEND_STRING PROPERTY LINK_FLAGS " -lc")
endif()
set_target_properties(OPNMIDI_shared PROPERTIES SOVERSION "1")
endif()
if(NOT libOPNMIDI_STATIC AND NOT libOPNMIDI_SHARED)
message(FATAL_ERROR "Both static and shared libOPNMIDI builds are disabled!
You must enable at least one of them!")
endif()
add_library(OPNMIDI_IF INTERFACE)
if(libOPNMIDI_STATIC OR WITH_VLC_PLUGIN)
add_library(OPNMIDI_IF_STATIC INTERFACE)
target_link_libraries(OPNMIDI_IF_STATIC INTERFACE OPNMIDI_static)
endif()
if(libOPNMIDI_SHARED)
target_link_libraries(OPNMIDI_IF INTERFACE OPNMIDI_shared)
else()
target_link_libraries(OPNMIDI_IF INTERFACE OPNMIDI_static)
endif()
if(WITH_MIDIPLAY)
add_subdirectory(utils/midiplay)
endif()
if(WITH_MIDI2VGM)
if(NOT USE_VGM_FILE_DUMPER)
message(FATAL_ERROR "To build MIDI to VGM converter, you must enable -DUSE_VGM_FILE_DUMPER=ON flag!")
endif()
add_subdirectory(utils/midi2vgm)
endif()
if(WITH_WOPN2HPP)
add_subdirectory(utils/wopn2hpp)
endif()
if(WITH_VLC_PLUGIN)
add_subdirectory(utils/vlc_codec)
endif()
if(WITH_DAC_UTIL)
add_subdirectory(utils/dac_test)
endif()
if(WIN32 AND WITH_WINMMDRV)
add_subdirectory(utils/winmm_drv)
endif()
if(WITH_HQ_RESAMPLER)
find_library(ZITA_RESAMPLER_LIBRARY "zita-resampler" REQUIRED)
add_definitions(-DOPNMIDI_ENABLE_HQ_RESAMPLER)
if(libOPNMIDI_SHARED)
target_link_libraries(OPNMIDI_shared PUBLIC "${ZITA_RESAMPLER_LIBRARY}")
endif()
if(libOPNMIDI_STATIC OR WITH_VLC_PLUGIN)
target_link_libraries(OPNMIDI_static PUBLIC "${ZITA_RESAMPLER_LIBRARY}")
endif()
endif()
if(libOPNMIDI_STATIC)
install(TARGETS OPNMIDI_static
EXPORT libOPNMIDIStaticTargets
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
install(EXPORT libOPNMIDIStaticTargets
FILE libOPNMIDI-static-targets.cmake
NAMESPACE libOPNMIDI::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libOPNMIDI")
endif()
if(libOPNMIDI_SHARED)
install(TARGETS OPNMIDI_shared
EXPORT libOPNMIDISharedTargets
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
install(EXPORT libOPNMIDISharedTargets
FILE libOPNMIDI-shared-targets.cmake
NAMESPACE libOPNMIDI::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libOPNMIDI")
endif()
install(FILES
include/opnmidi.h
#include/opnmidi.hpp # WIP
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
include(CMakePackageConfigHelpers)
configure_package_config_file(libOPNMIDIConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/libOPNMIDIConfig.cmake"
PATH_VARS CMAKE_INSTALL_PREFIX CMAKE_INSTALL_FULL_BINDIR CMAKE_INSTALL_FULL_INCLUDEDIR CMAKE_INSTALL_FULL_LIBDIR
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libOPNMIDI"
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libOPNMIDIConfig.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libOPNMIDI")
if(WITH_EXTRA_BANKS AND NOT APPLE)
file(GLOB WOPN_FILES ${libOPNMIDI_SOURCE_DIR}/fm_banks/*.wopn)
install(FILES ${WOPN_FILES}
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/sounds/wopn")
file(GLOB WOPNTXT_FILES ${libOPNMIDI_SOURCE_DIR}/fm_banks/*.txt)
install(FILES ${WOPNTXT_FILES}
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/doc/libOPNMIDI/wopn")
endif()
file(GLOB DOCTXT_FILES
"${libOPNMIDI_SOURCE_DIR}/docs/*.txt"
"${libOPNMIDI_SOURCE_DIR}/LICENSE*.txt"
README.md AUTHORS
)
install(FILES ${DOCTXT_FILES}
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/doc/libOPNMIDI")
if(NOT ANDROID)
configure_file(libOPNMIDI.pc.in libOPNMIDI.pc @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libOPNMIDI.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()
option(WITH_UNIT_TESTS "Enable unit testing" OFF)
if(WITH_UNIT_TESTS)
enable_testing ()
add_subdirectory(test)
endif()
# === Version check ====
set(VERSION_CHECK_SOURCE "
#include \"opnmidi.h\"
#if !(OPNMIDI_VERSION_MAJOR == ${PROJECT_VERSION_MAJOR} && OPNMIDI_VERSION_MINOR == ${PROJECT_VERSION_MINOR} && OPNMIDI_VERSION_PATCHLEVEL == ${PROJECT_VERSION_PATCH})
#error Project and source code version do not match!
#endif")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/version_check.c" "${VERSION_CHECK_SOURCE}")
add_library(OPNMIDI_version_check OBJECT "${CMAKE_CURRENT_BINARY_DIR}/version_check.c")
target_include_directories(OPNMIDI_version_check PRIVATE "include")
message("==== libOPNMIDI options ====")
message("libOPNMIDI_STATIC = ${libOPNMIDI_STATIC}")
message("libOPNMIDI_SHARED = ${libOPNMIDI_SHARED}")
message("WITH_UNIT_TESTS = ${WITH_UNIT_TESTS}")
# message("WITH_CPP_EXTRAS = ${WITH_CPP_EXTRAS}")
message("WITH_MIDI_SEQUENCER = ${WITH_MIDI_SEQUENCER}")
message("WITH_HQ_RESAMPLER = ${WITH_HQ_RESAMPLER}")
message("WITH_MUS_SUPPORT = ${WITH_MUS_SUPPORT}")
message("WITH_XMI_SUPPORT = ${WITH_XMI_SUPPORT}")
message("USE_MAME_EMULATOR = ${USE_MAME_EMULATOR}")
message("USE_GENS_EMULATOR = ${USE_GENS_EMULATOR}")
message("USE_NUKED_EMULATOR = ${USE_NUKED_EMULATOR}")
#message("USE_GX_EMULATOR = ${USE_GX_EMULATOR}")
message("USE_NP2_EMULATOR = ${USE_NP2_EMULATOR}")
message("USE_MAME_2608_EMULATOR = ${USE_MAME_2608_EMULATOR}")
#message("USE_PMDWIN_EMULATOR = ${USE_PMDWIN_EMULATOR}")
message("USE_VGM_FILE_DUMPER = ${USE_VGM_FILE_DUMPER}")
message("USE_YMFM_EMULATOR = ${USE_YMFM_EMULATOR}")
message("===== Utils and extras =====")
message("WITH_MIDIPLAY = ${WITH_MIDIPLAY}")
message("WITH_WOPN2HPP = ${WITH_WOPN2HPP}")
message("WITH_VLC_PLUGIN = ${WITH_VLC_PLUGIN}")
message("WITH_DAC_UTIL = ${WITH_DAC_UTIL}")
if(WIN32)
message("WITH_WINMMDRV = ${WITH_WINMMDRV}")
endif()
if(NOT APPLE)
message("WITH_EXTRA_BANKS = ${WITH_EXTRA_BANKS}")
endif()