Findmpg123.cmake 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #[=======================================================================[.rst:
  2. Findmpg123
  3. -------
  4. Finds the mpg123 library.
  5. Imported Targets
  6. ^^^^^^^^^^^^^^^^
  7. This module provides the following imported targets, if found:
  8. ``MPG123::libmpg123``
  9. The mpg123 library
  10. Result Variables
  11. ^^^^^^^^^^^^^^^^
  12. This will define the following variables:
  13. ``mpg123_FOUND``
  14. True if the system has the mpg123 package.
  15. ``mpg123_VERSION``
  16. The version of mpg123 that was found on the system.
  17. Cache Variables
  18. ^^^^^^^^^^^^^^^
  19. The following cache variables may also be set:
  20. ``mpg123_INCLUDE_DIR``
  21. The directory containing ``mpg123.h``.
  22. ``mpg123_LIBRARY``
  23. The path to the mpg123 library.
  24. #]=======================================================================]
  25. if (mpg123_INCLUDE_DIR)
  26. # Already in cache, be silent
  27. set(mpg123_FIND_QUIETLY TRUE)
  28. endif ()
  29. find_package (PkgConfig QUIET)
  30. pkg_check_modules(PC_MPG123 QUIET libmpg123>=1.25.10)
  31. find_path (mpg123_INCLUDE_DIR mpg123.h
  32. HINTS
  33. ${PC_MPG123_INCLUDEDIR}
  34. ${PC_MPG123_INCLUDE_DIRS}
  35. ${mpg123_ROOT}
  36. )
  37. # MSVC built mpg123 may be named mpg123_static.
  38. # The provided project files name the library with the lib prefix.
  39. find_library (mpg123_LIBRARY
  40. NAMES
  41. mpg123
  42. mpg123_static
  43. libmpg123
  44. libmpg123_static
  45. HINTS
  46. ${PC_MPG123_LIBDIR}
  47. ${PC_MPG123_LIBRARY_DIRS}
  48. ${mpg123_ROOT}
  49. )
  50. if (PC_MPG123_FOUND)
  51. set (mpg123_VERSION ${PC_MPG123_VERSION})
  52. elseif (mpg123_INCLUDE_DIR)
  53. file (READ "${mpg123_INCLUDE_DIR}/mpg123.h" _mpg123_h)
  54. string (REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" _mpg123_version_re "${_mpg123_h}")
  55. set (mpg123_VERSION "${_mpg123_version_re}")
  56. endif ()
  57. # Handle the QUIETLY and REQUIRED arguments and set mpg123_FOUND
  58. # to TRUE if all listed variables are TRUE.
  59. include(FindPackageHandleStandardArgs)
  60. find_package_handle_standard_args (mpg123
  61. REQUIRED_VARS
  62. mpg123_LIBRARY
  63. mpg123_INCLUDE_DIR
  64. VERSION_VAR
  65. mpg123_VERSION
  66. )
  67. if (mpg123_FOUND AND NOT TARGET MPG123::libmpg123)
  68. add_library (MPG123::libmpg123 UNKNOWN IMPORTED)
  69. set_target_properties (MPG123::libmpg123
  70. PROPERTIES
  71. IMPORTED_LOCATION "${mpg123_LIBRARY}"
  72. INTERFACE_INCLUDE_DIRECTORIES "${mpg123_INCLUDE_DIR}"
  73. )
  74. endif ()
  75. mark_as_advanced(mpg123_INCLUDE_DIR mpg123_LIBRARY)