| 1 |
include_guard() |
| 2 |
|
| 3 |
if(STRICT_FIND) |
| 4 |
set(dsda_strict_keyword REQUIRED) |
| 5 |
endif() |
| 6 |
|
| 7 |
add_library(dsda_dependencies INTERFACE IMPORTED) |
| 8 |
add_library(dsda::dependencies ALIAS dsda_dependencies) |
| 9 |
|
| 10 |
# Make sure OpenGL.framework is found, XQuartz may show up first and only supports GL 1.4 |
| 11 |
if(APPLE) |
| 12 |
set(find_framework_backup ${CMAKE_FIND_FRAMEWORK}) |
| 13 |
set(CMAKE_FIND_FRAMEWORK ONLY) |
| 14 |
endif() |
| 15 |
|
| 16 |
set(OpenGL_GL_PREFERENCE LEGACY) |
| 17 |
find_package(OpenGL 2.0 REQUIRED) |
| 18 |
|
| 19 |
if(APPLE) |
| 20 |
set(CMAKE_FIND_FRAMEWORK ${find_framework_backup}) |
| 21 |
endif() |
| 22 |
|
| 23 |
find_package(SDL2 2.0.12 CONFIG REQUIRED) |
| 24 |
find_package(SDL2_mixer REQUIRED) |
| 25 |
find_package(SndFile 1.0.29 REQUIRED) |
| 26 |
find_package(ZLIB REQUIRED) |
| 27 |
find_package(libzip REQUIRED) |
| 28 |
|
| 29 |
if(SndFile_VERSION VERSION_GREATER_EQUAL "1.1.0") |
| 30 |
set(HAVE_SNDFILE_MPEG TRUE) |
| 31 |
endif() |
| 32 |
|
| 33 |
if(WITH_IMAGE) |
| 34 |
find_package(SDL2_image ${dsda_strict_keyword}) |
| 35 |
if(SDL2_image_FOUND) |
| 36 |
set(HAVE_LIBSDL2_IMAGE TRUE) |
| 37 |
endif() |
| 38 |
endif() |
| 39 |
|
| 40 |
if(WITH_MAD) |
| 41 |
find_package(mad ${dsda_strict_keyword}) |
| 42 |
if(mad_FOUND) |
| 43 |
set(HAVE_LIBMAD TRUE) |
| 44 |
endif() |
| 45 |
endif() |
| 46 |
|
| 47 |
if(WITH_FLUIDSYNTH) |
| 48 |
find_package(FluidSynth ${dsda_strict_keyword}) |
| 49 |
if(FluidSynth_FOUND) |
| 50 |
set(HAVE_LIBFLUIDSYNTH TRUE) |
| 51 |
endif() |
| 52 |
endif() |
| 53 |
|
| 54 |
if(WITH_XMP) |
| 55 |
find_package(libxmp ${dsda_strict_keyword}) |
| 56 |
if(libxmp_FOUND) |
| 57 |
set(HAVE_LIBXMP TRUE) |
| 58 |
endif() |
| 59 |
endif() |
| 60 |
|
| 61 |
if(WITH_VORBISFILE) |
| 62 |
find_package(Vorbis ${dsda_strict_keyword}) |
| 63 |
if(Vorbis_File_FOUND) |
| 64 |
set(HAVE_LIBVORBISFILE TRUE) |
| 65 |
endif() |
| 66 |
endif() |
| 67 |
|
| 68 |
if(WITH_PORTMIDI) |
| 69 |
find_package(PortMidi ${dsda_strict_keyword}) |
| 70 |
if(PortMidi_FOUND) |
| 71 |
set(HAVE_LIBPORTMIDI TRUE) |
| 72 |
endif() |
| 73 |
endif() |
| 74 |
|
| 75 |
# Before SDL 2.24.x, all SDL2::* targets were created in autotools builds, even if the underlying library wasn't built. |
| 76 |
# So wrap all this in our interface library |
| 77 |
add_library(dsda_SDL2 INTERFACE IMPORTED) |
| 78 |
add_library(dsda::SDL2 ALIAS dsda_SDL2) |
| 79 |
|
| 80 |
if(TARGET SDL2::SDL2main) |
| 81 |
get_target_property(sdl2_main_library SDL2::SDL2main LOCATION) |
| 82 |
if(EXISTS ${sdl2_main_library}) |
| 83 |
target_link_libraries(dsda_SDL2 INTERFACE SDL2::SDL2main) |
| 84 |
endif() |
| 85 |
endif() |
| 86 |
|
| 87 |
if(TARGET SDL2::SDL2) |
| 88 |
get_target_property(sdl2_library SDL2::SDL2 LOCATION) |
| 89 |
endif() |
| 90 |
if(TARGET SDL2::SDL2-static) |
| 91 |
get_target_property(sdl2_static_library SDL2::SDL2-static LOCATION) |
| 92 |
endif() |
| 93 |
|
| 94 |
if(EXISTS ${sdl2_library}) |
| 95 |
target_link_libraries(dsda_SDL2 INTERFACE SDL2::SDL2) |
| 96 |
elseif(EXISTS ${sdl2_static_library}) |
| 97 |
target_link_libraries(dsda_SDL2 INTERFACE SDL2::SDL2-static) |
| 98 |
else() |
| 99 |
message(FATAL_ERROR "Neither '${sdl2_library}' or '${sdl2_static_library}' exist, your SDL installation may be broken.") |
| 100 |
endif() |
| 101 |
|
| 102 |
# TODO: Rework libxmp's find module to avoid this workaround |
| 103 |
add_library(dsda_xmp INTERFACE IMPORTED) |
| 104 |
add_library(dsda::xmp ALIAS dsda_xmp) |
| 105 |
|
| 106 |
if(HAVE_LIBXMP) |
| 107 |
if(TARGET libxmp::xmp) |
| 108 |
target_link_libraries(dsda_xmp INTERFACE libxmp::xmp) |
| 109 |
else() |
| 110 |
target_link_libraries(dsda_xmp |
| 111 |
INTERFACE |
| 112 |
$<IF:$<TARGET_EXISTS:libxmp::xmp_shared>,libxmp::xmp_shared,libxmp::xmp_static> |
| 113 |
) |
| 114 |
endif() |
| 115 |
endif() |
| 116 |
|
| 117 |
target_link_libraries(dsda_dependencies |
| 118 |
INTERFACE |
| 119 |
OpenGL::GL |
| 120 |
OpenGL::GLU |
| 121 |
SndFile::sndfile |
| 122 |
libzip::zip |
| 123 |
ZLIB::ZLIB |
| 124 |
|
| 125 |
dsda::xmp |
| 126 |
$<$<BOOL:${HAVE_LIBMAD}>:mad::mad> |
| 127 |
$<$<BOOL:${HAVE_LIBFLUIDSYNTH}>:FluidSynth::libfluidsynth> |
| 128 |
$<$<BOOL:${HAVE_LIBVORBISFILE}>:Vorbis::vorbisfile> |
| 129 |
$<$<BOOL:${HAVE_LIBPORTMIDI}>:PortMidi::portmidi> |
| 130 |
|
| 131 |
$<$<BOOL:${HAVE_LIBSDL2_IMAGE}>:$<IF:$<TARGET_EXISTS:SDL2_image::SDL2_image>,SDL2_image::SDL2_image,SDL2_image::SDL2_image-static>> |
| 132 |
$<IF:$<TARGET_EXISTS:SDL2_mixer::SDL2_mixer>,SDL2_mixer::SDL2_mixer,SDL2_mixer::SDL2_mixer-static> |
| 133 |
|
| 134 |
dsda::SDL2 |
| 135 |
) |
| 136 |
|
| 137 |
if(WIN32) |
| 138 |
target_link_libraries(dsda_dependencies |
| 139 |
INTERFACE |
| 140 |
winmm |
| 141 |
comctl32 |
| 142 |
) |
| 143 |
endif() |