FindFLAC.cmake 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # - Find FLAC
  2. # Find the native FLAC includes and libraries
  3. #
  4. # FLAC_INCLUDE_DIRS - where to find FLAC headers.
  5. # FLAC_LIBRARIES - List of libraries when using libFLAC.
  6. # FLAC_FOUND - True if libFLAC found.
  7. # FLAC_DEFINITIONS - FLAC compile definitons
  8. if (FLAC_INCLUDE_DIR)
  9. # Already in cache, be silent
  10. set (FLAC_FIND_QUIETLY TRUE)
  11. endif ()
  12. find_package (Ogg QUIET)
  13. find_package (PkgConfig QUIET)
  14. pkg_check_modules(PC_FLAC QUIET flac)
  15. set(FLAC_VERSION ${PC_FLAC_VERSION})
  16. find_path (FLAC_INCLUDE_DIR FLAC/stream_decoder.h
  17. HINTS
  18. ${PC_FLAC_INCLUDEDIR}
  19. ${PC_FLAC_INCLUDE_DIRS}
  20. ${FLAC_ROOT}
  21. )
  22. # MSVC built libraries can name them *_static, which is good as it
  23. # distinguishes import libraries from static libraries with the same extension.
  24. find_library (FLAC_LIBRARY
  25. NAMES
  26. FLAC
  27. libFLAC
  28. libFLAC_dynamic
  29. libFLAC_static
  30. HINTS
  31. ${PC_FLAC_LIBDIR}
  32. ${PC_FLAC_LIBRARY_DIRS}
  33. ${FLAC_ROOT}
  34. )
  35. # Handle the QUIETLY and REQUIRED arguments and set FLAC_FOUND to TRUE if
  36. # all listed variables are TRUE.
  37. include (FindPackageHandleStandardArgs)
  38. find_package_handle_standard_args (FLAC
  39. REQUIRED_VARS
  40. FLAC_LIBRARY
  41. FLAC_INCLUDE_DIR
  42. Ogg_FOUND
  43. VERSION_VAR
  44. FLAC_VERSION
  45. )
  46. if (FLAC_FOUND)
  47. set (FLAC_INCLUDE_DIRS ${FLAC_INCLUDE_DIR})
  48. set (FLAC_LIBRARIES ${FLAC_LIBRARY} ${OGG_LIBRARIES})
  49. if (NOT TARGET FLAC::FLAC)
  50. add_library(FLAC::FLAC UNKNOWN IMPORTED)
  51. set_target_properties(FLAC::FLAC PROPERTIES
  52. INTERFACE_INCLUDE_DIRECTORIES "${FLAC_INCLUDE_DIR}"
  53. IMPORTED_LOCATION "${FLAC_LIBRARY}"
  54. INTERFACE_LINK_LIBRARIES Ogg::ogg
  55. )
  56. endif ()
  57. endif ()
  58. mark_as_advanced(FLAC_INCLUDE_DIR FLAC_LIBRARY)