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