🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

429 lines
19 KiB

  1. # - Locates the SDL_sound library
  2. #
  3. # This module depends on SDL being found and
  4. # must be called AFTER FindSDL.cmake or FindSDL2.cmake is called.
  5. #
  6. # This module defines
  7. # SDL_SOUND_INCLUDE_DIR, where to find SDL_sound.h
  8. # SDL_SOUND_FOUND, if false, do not try to link to SDL_sound
  9. # SDL_SOUND_LIBRARIES, this contains the list of libraries that you need
  10. # to link against. This is a read-only variable and is marked INTERNAL.
  11. # SDL_SOUND_EXTRAS, this is an optional variable for you to add your own
  12. # flags to SDL_SOUND_LIBRARIES. This is prepended to SDL_SOUND_LIBRARIES.
  13. # This is available mostly for cases this module failed to anticipate for
  14. # and you must add additional flags. This is marked as ADVANCED.
  15. # SDL_SOUND_VERSION_STRING, human-readable string containing the version of SDL_sound
  16. #
  17. # This module also defines (but you shouldn't need to use directly)
  18. # SDL_SOUND_LIBRARY, the name of just the SDL_sound library you would link
  19. # against. Use SDL_SOUND_LIBRARIES for you link instructions and not this one.
  20. # And might define the following as needed
  21. # MIKMOD_LIBRARY
  22. # MODPLUG_LIBRARY
  23. # OGG_LIBRARY
  24. # VORBIS_LIBRARY
  25. # SMPEG_LIBRARY
  26. # FLAC_LIBRARY
  27. # SPEEX_LIBRARY
  28. #
  29. # Typically, you should not use these variables directly, and you should use
  30. # SDL_SOUND_LIBRARIES which contains SDL_SOUND_LIBRARY and the other audio libraries
  31. # (if needed) to successfully compile on your system.
  32. #
  33. # Created by Eric Wing.
  34. # This module is a bit more complicated than the other FindSDL* family modules.
  35. # The reason is that SDL_sound can be compiled in a large variety of different ways
  36. # which are independent of platform. SDL_sound may dynamically link against other 3rd
  37. # party libraries to get additional codec support, such as Ogg Vorbis, SMPEG, ModPlug,
  38. # MikMod, FLAC, Speex, and potentially others.
  39. # Under some circumstances which I don't fully understand,
  40. # there seems to be a requirement
  41. # that dependent libraries of libraries you use must also be explicitly
  42. # linked against in order to successfully compile. SDL_sound does not currently
  43. # have any system in place to know how it was compiled.
  44. # So this CMake module does the hard work in trying to discover which 3rd party
  45. # libraries are required for building (if any).
  46. # This module uses a brute force approach to create a test program that uses SDL_sound,
  47. # and then tries to build it. If the build fails, it parses the error output for
  48. # known symbol names to figure out which libraries are needed.
  49. #
  50. # Responds to the $SDLDIR and $SDLSOUNDDIR environmental variable that would
  51. # correspond to the ./configure --prefix=$SDLDIR used in building SDL.
  52. #
  53. # On OSX, this will prefer the Framework version (if found) over others.
  54. # People will have to manually change the cache values of
  55. # SDL_LIBRARY or SDL2_LIBRARY to override this selection or set the CMake
  56. # environment CMAKE_INCLUDE_PATH to modify the search paths.
  57. #=============================================================================
  58. # Copyright 2005-2009 Kitware, Inc.
  59. # Copyright 2012 Benjamin Eikel
  60. #
  61. # Distributed under the OSI-approved BSD License (the "License");
  62. # see accompanying file Copyright.txt for details.
  63. #
  64. # This software is distributed WITHOUT ANY WARRANTY; without even the
  65. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  66. # See the License for more information.
  67. #=============================================================================
  68. # (To distribute this file outside of CMake, substitute the full
  69. # License text for the above reference.)
  70. set(SDL_SOUND_EXTRAS "" CACHE STRING "SDL_sound extra flags")
  71. mark_as_advanced(SDL_SOUND_EXTRAS)
  72. # Find SDL_sound.h
  73. find_path(SDL_SOUND_INCLUDE_DIR SDL_sound.h
  74. HINTS
  75. ENV SDLSOUNDDIR
  76. ENV SDLDIR
  77. PATH_SUFFIXES SDL SDL12 SDL11
  78. )
  79. find_library(SDL_SOUND_LIBRARY
  80. NAMES SDL_sound
  81. HINTS
  82. ENV SDLSOUNDDIR
  83. ENV SDLDIR
  84. )
  85. if(SDL2_FOUND OR SDL_FOUND)
  86. if(SDL_SOUND_INCLUDE_DIR AND SDL_SOUND_LIBRARY)
  87. # CMake is giving me problems using TRY_COMPILE with the CMAKE_FLAGS
  88. # for the :STRING syntax if I have multiple values contained in a
  89. # single variable. This is a problem for the SDL2_LIBRARY variable
  90. # because it does just that. When I feed this variable to the command,
  91. # only the first value gets the appropriate modifier (e.g. -I) and
  92. # the rest get dropped.
  93. # To get multiple single variables to work, I must separate them with a "\;"
  94. # I could go back and modify the FindSDL2.cmake module, but that's kind of painful.
  95. # The solution would be to try something like:
  96. # set(SDL2_TRY_COMPILE_LIBRARY_LIST "${SDL2_TRY_COMPILE_LIBRARY_LIST}\;${CMAKE_THREAD_LIBS_INIT}")
  97. # Instead, it was suggested on the mailing list to write a temporary CMakeLists.txt
  98. # with a temporary test project and invoke that with TRY_COMPILE.
  99. # See message thread "Figuring out dependencies for a library in order to build"
  100. # 2005-07-16
  101. # try_compile(
  102. # MY_RESULT
  103. # ${CMAKE_BINARY_DIR}
  104. # ${PROJECT_SOURCE_DIR}/DetermineSoundLibs.c
  105. # CMAKE_FLAGS
  106. # -DINCLUDE_DIRECTORIES:STRING=${SDL2_INCLUDE_DIR}\;${SDL_SOUND_INCLUDE_DIR}
  107. # -DLINK_LIBRARIES:STRING=${SDL_SOUND_LIBRARY}\;${SDL2_LIBRARY}
  108. # OUTPUT_VARIABLE MY_OUTPUT
  109. # )
  110. # To minimize external dependencies, create a sdlsound test program
  111. # which will be used to figure out if additional link dependencies are
  112. # required for the link phase.
  113. file(WRITE ${PROJECT_BINARY_DIR}/CMakeTmp/DetermineSoundLibs.c
  114. "#include \"SDL_sound.h\"
  115. #include \"SDL.h\"
  116. int main(int argc, char* argv[])
  117. {
  118. Sound_AudioInfo desired;
  119. Sound_Sample* sample;
  120. SDL_Init(0);
  121. Sound_Init();
  122. /* This doesn't actually have to work, but Init() is a no-op
  123. * for some of the decoders, so this should force more symbols
  124. * to be pulled in.
  125. */
  126. sample = Sound_NewSampleFromFile(argv[1], &desired, 4096);
  127. Sound_Quit();
  128. SDL_Quit();
  129. return 0;
  130. }"
  131. )
  132. # Calling
  133. # target_link_libraries(DetermineSoundLibs "${SDL_SOUND_LIBRARY} ${SDL2_LIBRARY})
  134. # causes problems when SDL2_LIBRARY looks like
  135. # /Library/Frameworks/SDL2.framework;-framework Cocoa
  136. # The ;-framework Cocoa seems to be confusing CMake once the OS X
  137. # framework support was added. I was told that breaking up the list
  138. # would fix the problem.
  139. set(TMP_LIBS "")
  140. if(SDL2_FOUND)
  141. set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARY} ${SDL2_LIBRARY})
  142. foreach(lib ${SDL_SOUND_LIBRARY} ${SDL2_LIBRARY})
  143. set(TMP_LIBS "${TMP_LIBS} \"${lib}\"")
  144. endforeach()
  145. set(TMP_INCLUDE_DIRS ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
  146. else()
  147. set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARY} ${SDL_LIBRARY})
  148. foreach(lib ${SDL_SOUND_LIBRARY} ${SDL_LIBRARY})
  149. set(TMP_LIBS "${TMP_LIBS} \"${lib}\"")
  150. endforeach()
  151. set(TMP_INCLUDE_DIRS ${SDL_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
  152. endif()
  153. # Keep trying to build a temp project until we find all missing libs.
  154. set(TRY_AGAIN TRUE)
  155. WHILE(TRY_AGAIN)
  156. set(TRY_AGAIN FALSE)
  157. # message("TMP_TRY_LIBS ${TMP_TRY_LIBS}")
  158. # Write the CMakeLists.txt and test project
  159. # Weird, this is still sketchy. If I don't quote the variables
  160. # in the TARGET_LINK_LIBRARIES, I seem to loose everything
  161. # in the SDL2_LIBRARY string after the "-framework".
  162. # But if I quote the stuff in INCLUDE_DIRECTORIES, it doesn't work.
  163. file(WRITE ${PROJECT_BINARY_DIR}/CMakeTmp/CMakeLists.txt
  164. "cmake_minimum_required(VERSION 2.8)
  165. project(DetermineSoundLibs C)
  166. include_directories(${TMP_INCLUDE_DIRS})
  167. add_executable(DetermineSoundLibs DetermineSoundLibs.c)
  168. target_link_libraries(DetermineSoundLibs ${TMP_LIBS})"
  169. )
  170. try_compile(
  171. MY_RESULT
  172. ${PROJECT_BINARY_DIR}/CMakeTmp
  173. ${PROJECT_BINARY_DIR}/CMakeTmp
  174. DetermineSoundLibs
  175. OUTPUT_VARIABLE MY_OUTPUT
  176. )
  177. # message("${MY_RESULT}")
  178. # message(${MY_OUTPUT})
  179. if(NOT MY_RESULT)
  180. # I expect that MPGLIB, VOC, WAV, AIFF, and SHN are compiled in statically.
  181. # I think Timidity is also compiled in statically.
  182. # I've never had to explcitly link against Quicktime, so I'll skip that for now.
  183. # Find libmath
  184. if("${MY_OUTPUT}" MATCHES "cos@@GLIBC")
  185. find_library(MATH_LIBRARY NAMES m)
  186. if(MATH_LIBRARY)
  187. set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${MATH_LIBRARY})
  188. set(TMP_LIBS "${SDL_SOUND_LIBRARIES_TMP} \"${MATH_LIBRARY}\"")
  189. set(TRY_AGAIN TRUE)
  190. endif(MATH_LIBRARY)
  191. endif("${MY_OUTPUT}" MATCHES "cos@@GLIBC")
  192. # Find MikMod
  193. if("${MY_OUTPUT}" MATCHES "MikMod_")
  194. find_library(MIKMOD_LIBRARY
  195. NAMES libmikmod-coreaudio mikmod
  196. PATHS
  197. ENV MIKMODDIR
  198. ENV SDLSOUNDDIR
  199. ENV SDLDIR
  200. /sw
  201. /opt/local
  202. /opt/csw
  203. /opt
  204. PATH_SUFFIXES lib
  205. )
  206. if(MIKMOD_LIBRARY)
  207. set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${MIKMOD_LIBRARY})
  208. set(TMP_LIBS "${SDL_SOUND_LIBRARIES_TMP} \"${MIKMOD_LIBRARY}\"")
  209. set(TRY_AGAIN TRUE)
  210. endif(MIKMOD_LIBRARY)
  211. endif("${MY_OUTPUT}" MATCHES "MikMod_")
  212. # Find ModPlug
  213. if("${MY_OUTPUT}" MATCHES "MODPLUG_")
  214. find_library(MODPLUG_LIBRARY
  215. NAMES modplug
  216. PATHS
  217. ENV MODPLUGDIR
  218. ENV SDLSOUNDDIR
  219. ENV SDLDIR
  220. /sw
  221. /opt/local
  222. /opt/csw
  223. /opt
  224. PATH_SUFFIXES lib
  225. )
  226. if(MODPLUG_LIBRARY)
  227. set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${MODPLUG_LIBRARY})
  228. set(TMP_LIBS "${SDL_SOUND_LIBRARIES_TMP} \"${MODPLUG_LIBRARY}\"")
  229. set(TRY_AGAIN TRUE)
  230. endif()
  231. endif()
  232. # Find Ogg and Vorbis
  233. if("${MY_OUTPUT}" MATCHES "ov_")
  234. find_library(VORBISFILE_LIBRARY
  235. NAMES vorbisfile VorbisFile VORBISFILE
  236. PATHS
  237. ENV VORBISDIR
  238. ENV OGGDIR
  239. ENV SDLSOUNDDIR
  240. ENV SDLDIR
  241. /sw
  242. /opt/local
  243. /opt/csw
  244. /opt
  245. PATH_SUFFIXES lib
  246. )
  247. if(VORBISFILE_LIBRARY)
  248. set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${VORBISFILE_LIBRARY})
  249. set(TMP_LIBS "${SDL_SOUND_LIBRARIES_TMP} \"${VORBISFILE_LIBRARY}\"")
  250. set(TRY_AGAIN TRUE)
  251. endif()
  252. find_library(VORBIS_LIBRARY
  253. NAMES vorbis Vorbis VORBIS
  254. PATHS
  255. ENV OGGDIR
  256. ENV VORBISDIR
  257. ENV SDLSOUNDDIR
  258. ENV SDLDIR
  259. /sw
  260. /opt/local
  261. /opt/csw
  262. /opt
  263. PATH_SUFFIXES lib
  264. )
  265. if(VORBIS_LIBRARY)
  266. set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${VORBIS_LIBRARY})
  267. set(TMP_LIBS "${SDL_SOUND_LIBRARIES_TMP} \"${VORBIS_LIBRARY}\"")
  268. set(TRY_AGAIN TRUE)
  269. endif()
  270. find_library(OGG_LIBRARY
  271. NAMES ogg Ogg OGG
  272. PATHS
  273. ENV OGGDIR
  274. ENV VORBISDIR
  275. ENV SDLSOUNDDIR
  276. ENV SDLDIR
  277. /sw
  278. /opt/local
  279. /opt/csw
  280. /opt
  281. PATH_SUFFIXES lib
  282. )
  283. if(OGG_LIBRARY)
  284. set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${OGG_LIBRARY})
  285. set(TMP_LIBS "${SDL_SOUND_LIBRARIES_TMP} \"${OGG_LIBRARY}\"")
  286. set(TRY_AGAIN TRUE)
  287. endif()
  288. endif()
  289. # Find SMPEG
  290. if("${MY_OUTPUT}" MATCHES "SMPEG_")
  291. find_library(SMPEG_LIBRARY
  292. NAMES smpeg SMPEG Smpeg SMpeg
  293. PATHS
  294. ENV SMPEGDIR
  295. ENV SDLSOUNDDIR
  296. ENV SDLDIR
  297. /sw
  298. /opt/local
  299. /opt/csw
  300. /opt
  301. PATH_SUFFIXES lib
  302. )
  303. if(SMPEG_LIBRARY)
  304. set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${SMPEG_LIBRARY})
  305. set(TMP_LIBS "${SDL_SOUND_LIBRARIES_TMP} \"${SMPEG_LIBRARY}\"")
  306. set(TRY_AGAIN TRUE)
  307. endif()
  308. endif()
  309. # Find FLAC
  310. if("${MY_OUTPUT}" MATCHES "FLAC_")
  311. find_library(FLAC_LIBRARY
  312. NAMES flac FLAC
  313. PATHS
  314. ENV FLACDIR
  315. ENV SDLSOUNDDIR
  316. ENV SDLDIR
  317. /sw
  318. /opt/local
  319. /opt/csw
  320. /opt
  321. PATH_SUFFIXES lib
  322. )
  323. if(FLAC_LIBRARY)
  324. set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${FLAC_LIBRARY})
  325. set(TMP_LIBS "${SDL_SOUND_LIBRARIES_TMP} \"${FLAC_LIBRARY}\"")
  326. set(TRY_AGAIN TRUE)
  327. endif()
  328. endif()
  329. # Hmmm...Speex seems to depend on Ogg. This might be a problem if
  330. # the TRY_COMPILE attempt gets blocked at SPEEX before it can pull
  331. # in the Ogg symbols. I'm not sure if I should duplicate the ogg stuff
  332. # above for here or if two ogg entries will screw up things.
  333. if("${MY_OUTPUT}" MATCHES "speex_")
  334. find_library(SPEEX_LIBRARY
  335. NAMES speex SPEEX
  336. PATHS
  337. ENV SPEEXDIR
  338. ENV SDLSOUNDDIR
  339. ENV SDLDIR
  340. /sw
  341. /opt/local
  342. /opt/csw
  343. /opt
  344. PATH_SUFFIXES lib
  345. )
  346. if(SPEEX_LIBRARY)
  347. set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${SPEEX_LIBRARY})
  348. set(TMP_LIBS "${SDL_SOUND_LIBRARIES_TMP} \"${SPEEX_LIBRARY}\"")
  349. set(TRY_AGAIN TRUE)
  350. endif()
  351. # Find OGG (needed for Speex)
  352. # We might have already found Ogg for Vorbis, so skip it if so.
  353. if(NOT OGG_LIBRARY)
  354. find_library(OGG_LIBRARY
  355. NAMES ogg Ogg OGG
  356. PATHS
  357. ENV OGGDIR
  358. ENV VORBISDIR
  359. ENV SPEEXDIR
  360. ENV SDLSOUNDDIR
  361. ENV SDLDIR
  362. /sw
  363. /opt/local
  364. /opt/csw
  365. /opt
  366. PATH_SUFFIXES lib
  367. )
  368. if(OGG_LIBRARY)
  369. set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${OGG_LIBRARY})
  370. set(TMP_LIBS "${SDL_SOUND_LIBRARIES_TMP} \"${OGG_LIBRARY}\"")
  371. set(TRY_AGAIN TRUE)
  372. endif()
  373. endif()
  374. endif()
  375. endif()
  376. ENDWHILE()
  377. unset(TMP_INCLUDE_DIRS)
  378. unset(TMP_LIBS)
  379. set(SDL_SOUND_LIBRARIES ${SDL_SOUND_EXTRAS} ${SDL_SOUND_LIBRARIES_TMP} CACHE INTERNAL "SDL_sound and dependent libraries")
  380. endif()
  381. endif()
  382. if(SDL_SOUND_INCLUDE_DIR AND EXISTS "${SDL_SOUND_INCLUDE_DIR}/SDL_sound.h")
  383. file(STRINGS "${SDL_SOUND_INCLUDE_DIR}/SDL_sound.h" SDL_SOUND_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SOUND_VER_MAJOR[ \t]+[0-9]+$")
  384. file(STRINGS "${SDL_SOUND_INCLUDE_DIR}/SDL_sound.h" SDL_SOUND_VERSION_MINOR_LINE REGEX "^#define[ \t]+SOUND_VER_MINOR[ \t]+[0-9]+$")
  385. file(STRINGS "${SDL_SOUND_INCLUDE_DIR}/SDL_sound.h" SDL_SOUND_VERSION_PATCH_LINE REGEX "^#define[ \t]+SOUND_VER_PATCH[ \t]+[0-9]+$")
  386. string(REGEX REPLACE "^#define[ \t]+SOUND_VER_MAJOR[ \t]+([0-9]+)$" "\\1" SDL_SOUND_VERSION_MAJOR "${SDL_SOUND_VERSION_MAJOR_LINE}")
  387. string(REGEX REPLACE "^#define[ \t]+SOUND_VER_MINOR[ \t]+([0-9]+)$" "\\1" SDL_SOUND_VERSION_MINOR "${SDL_SOUND_VERSION_MINOR_LINE}")
  388. string(REGEX REPLACE "^#define[ \t]+SOUND_VER_PATCH[ \t]+([0-9]+)$" "\\1" SDL_SOUND_VERSION_PATCH "${SDL_SOUND_VERSION_PATCH_LINE}")
  389. set(SDL_SOUND_VERSION_STRING ${SDL_SOUND_VERSION_MAJOR}.${SDL_SOUND_VERSION_MINOR}.${SDL_SOUND_VERSION_PATCH})
  390. unset(SDL_SOUND_VERSION_MAJOR_LINE)
  391. unset(SDL_SOUND_VERSION_MINOR_LINE)
  392. unset(SDL_SOUND_VERSION_PATCH_LINE)
  393. unset(SDL_SOUND_VERSION_MAJOR)
  394. unset(SDL_SOUND_VERSION_MINOR)
  395. unset(SDL_SOUND_VERSION_PATCH)
  396. endif()
  397. include(FindPackageHandleStandardArgs)
  398. FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_sound
  399. REQUIRED_VARS SDL_SOUND_LIBRARIES SDL_SOUND_INCLUDE_DIR
  400. VERSION_VAR SDL_SOUND_VERSION_STRING)