FindSDL_mixer.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindSDL_mixer
  5. -------------
  6. Locate SDL_mixer library
  7. This module defines:
  8. ::
  9. SDL_MIXER_LIBRARIES, the name of the library to link against
  10. SDL_MIXER_INCLUDE_DIRS, where to find the headers
  11. SDL_MIXER_FOUND, if false, do not try to link against
  12. SDL_MIXER_VERSION_STRING - human-readable string containing the
  13. version of SDL_mixer
  14. For backward compatibility the following variables are also set:
  15. ::
  16. SDLMIXER_LIBRARY (same value as SDL_MIXER_LIBRARIES)
  17. SDLMIXER_INCLUDE_DIR (same value as SDL_MIXER_INCLUDE_DIRS)
  18. SDLMIXER_FOUND (same value as SDL_MIXER_FOUND)
  19. $SDLDIR is an environment variable that would correspond to the
  20. ./configure --prefix=$SDLDIR used in building SDL.
  21. Created by Eric Wing. This was influenced by the FindSDL.cmake
  22. module, but with modifications to recognize OS X frameworks and
  23. additional Unix paths (FreeBSD, etc).
  24. #]=======================================================================]
  25. if(NOT SDL_MIXER_INCLUDE_DIR AND SDLMIXER_INCLUDE_DIR)
  26. set(SDL_MIXER_INCLUDE_DIR ${SDLMIXER_INCLUDE_DIR} CACHE PATH "directory cache
  27. entry initialized from old variable name")
  28. endif()
  29. find_path(SDL_MIXER_INCLUDE_DIR SDL_mixer.h
  30. HINTS
  31. ENV SDLMIXERDIR
  32. ENV SDLDIR
  33. PATH_SUFFIXES SDL
  34. # path suffixes to search inside ENV{SDLDIR}
  35. include/SDL include/SDL12 include/SDL11 include
  36. )
  37. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  38. set(VC_LIB_PATH_SUFFIX lib/x64)
  39. else()
  40. set(VC_LIB_PATH_SUFFIX lib/x86)
  41. endif()
  42. if(NOT SDL_MIXER_LIBRARY AND SDLMIXER_LIBRARY)
  43. set(SDL_MIXER_LIBRARY ${SDLMIXER_LIBRARY} CACHE FILEPATH "file cache entry
  44. initialized from old variable name")
  45. endif()
  46. find_library(SDL_MIXER_LIBRARY
  47. NAMES SDL_mixer
  48. HINTS
  49. ENV SDLMIXERDIR
  50. ENV SDLDIR
  51. PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
  52. )
  53. if(SDL_MIXER_INCLUDE_DIR AND EXISTS "${SDL_MIXER_INCLUDE_DIR}/SDL_mixer.h")
  54. file(STRINGS "${SDL_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$")
  55. file(STRINGS "${SDL_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$")
  56. file(STRINGS "${SDL_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$")
  57. string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_MIXER_VERSION_MAJOR "${SDL_MIXER_VERSION_MAJOR_LINE}")
  58. string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_MIXER_VERSION_MINOR "${SDL_MIXER_VERSION_MINOR_LINE}")
  59. string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_MIXER_VERSION_PATCH "${SDL_MIXER_VERSION_PATCH_LINE}")
  60. set(SDL_MIXER_VERSION_STRING ${SDL_MIXER_VERSION_MAJOR}.${SDL_MIXER_VERSION_MINOR}.${SDL_MIXER_VERSION_PATCH})
  61. unset(SDL_MIXER_VERSION_MAJOR_LINE)
  62. unset(SDL_MIXER_VERSION_MINOR_LINE)
  63. unset(SDL_MIXER_VERSION_PATCH_LINE)
  64. unset(SDL_MIXER_VERSION_MAJOR)
  65. unset(SDL_MIXER_VERSION_MINOR)
  66. unset(SDL_MIXER_VERSION_PATCH)
  67. endif()
  68. set(SDL_MIXER_LIBRARIES ${SDL_MIXER_LIBRARY})
  69. set(SDL_MIXER_INCLUDE_DIRS ${SDL_MIXER_INCLUDE_DIR})
  70. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  71. FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_mixer
  72. REQUIRED_VARS SDL_MIXER_LIBRARIES SDL_MIXER_INCLUDE_DIRS
  73. VERSION_VAR SDL_MIXER_VERSION_STRING)
  74. # for backward compatibility
  75. set(SDLMIXER_LIBRARY ${SDL_MIXER_LIBRARIES})
  76. set(SDLMIXER_INCLUDE_DIR ${SDL_MIXER_INCLUDE_DIRS})
  77. set(SDLMIXER_FOUND ${SDL_MIXER_FOUND})
  78. mark_as_advanced(SDL_MIXER_LIBRARY SDL_MIXER_INCLUDE_DIR)