FindFFmpeg.cmake 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # vim: ts=2 sw=2
  2. # - Try to find the required ffmpeg components(default: AVFORMAT, AVUTIL, AVCODEC)
  3. #
  4. # Once done this will define
  5. # FFMPEG_FOUND - System has the all required components.
  6. # FFMPEG_INCLUDE_DIRS - Include directory necessary for using the required components headers.
  7. # FFMPEG_LIBRARIES - Link these to use the required ffmpeg components.
  8. # FFMPEG_DEFINITIONS - Compiler switches required for using the required ffmpeg components.
  9. #
  10. # For each of the components it will additionally set.
  11. # - AVCODEC
  12. # - AVDEVICE
  13. # - AVFORMAT
  14. # - AVFILTER
  15. # - AVUTIL
  16. # - POSTPROC
  17. # - SWSCALE
  18. # the following variables will be defined
  19. # <component>_FOUND - System has <component>
  20. # <component>_INCLUDE_DIRS - Include directory necessary for using the <component> headers
  21. # <component>_LIBRARIES - Link these to use <component>
  22. # <component>_DEFINITIONS - Compiler switches required for using <component>
  23. # <component>_VERSION - The components version
  24. #
  25. # Copyright (c) 2006, Matthias Kretz, <kretz@kde.org>
  26. # Copyright (c) 2008, Alexander Neundorf, <neundorf@kde.org>
  27. # Copyright (c) 2011, Michael Jansen, <kde@michael-jansen.biz>
  28. #
  29. # Redistribution and use is allowed according to the terms of the BSD license.
  30. # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
  31. include(FindPackageHandleStandardArgs)
  32. # The default components were taken from a survey over other FindFFMPEG.cmake files
  33. if (NOT FFmpeg_FIND_COMPONENTS)
  34. set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL)
  35. endif ()
  36. #
  37. ### Macro: set_component_found
  38. #
  39. # Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present.
  40. #
  41. macro(set_component_found _component )
  42. if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS)
  43. # message(STATUS " - ${_component} found.")
  44. set(${_component}_FOUND TRUE)
  45. else ()
  46. # message(STATUS " - ${_component} not found.")
  47. endif ()
  48. endmacro()
  49. #
  50. ### Macro: find_component
  51. #
  52. # Checks for the given component by invoking pkgconfig and then looking up the libraries and
  53. # include directories.
  54. #
  55. macro(find_component _component _pkgconfig _library _header)
  56. if (NOT WIN32)
  57. # use pkg-config to get the directories and then use these values
  58. # in the FIND_PATH() and FIND_LIBRARY() calls
  59. find_package(PkgConfig)
  60. if (PKG_CONFIG_FOUND)
  61. pkg_check_modules(PC_${_component} ${_pkgconfig})
  62. endif ()
  63. endif (NOT WIN32)
  64. find_path(${_component}_INCLUDE_DIRS ${_header}
  65. HINTS
  66. ${PC_${_component}_INCLUDEDIR}
  67. ${PC_${_component}_INCLUDE_DIRS}
  68. PATH_SUFFIXES
  69. ffmpeg
  70. )
  71. find_library(${_component}_LIBRARIES NAMES ${_library}
  72. HINTS
  73. ${PC_${_component}_LIBDIR}
  74. ${PC_${_component}_LIBRARY_DIRS}
  75. )
  76. set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.")
  77. set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number.")
  78. set_component_found(${_component})
  79. mark_as_advanced(
  80. ${_component}_INCLUDE_DIRS
  81. ${_component}_LIBRARIES
  82. ${_component}_DEFINITIONS
  83. ${_component}_VERSION)
  84. endmacro()
  85. # Check for cached results. If there are skip the costly part.
  86. if (NOT FFMPEG_LIBRARIES)
  87. # Check for all possible component.
  88. find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
  89. find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
  90. find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
  91. find_component(AVUTIL libavutil avutil libavutil/avutil.h)
  92. find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
  93. find_component(SWSCALE libswscale swscale libswscale/swscale.h)
  94. find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
  95. find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h)
  96. # Check if the required components were found and add their stuff to the FFMPEG_* vars.
  97. foreach (_component ${FFmpeg_FIND_COMPONENTS})
  98. if (${_component}_FOUND)
  99. # message(STATUS "Required component ${_component} present.")
  100. set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES})
  101. set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS})
  102. list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS})
  103. else ()
  104. # message(STATUS "Required component ${_component} missing.")
  105. endif ()
  106. endforeach ()
  107. # Build the include path with duplicates removed.
  108. if (FFMPEG_INCLUDE_DIRS)
  109. list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
  110. endif ()
  111. # cache the vars.
  112. set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE)
  113. set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE)
  114. set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE)
  115. mark_as_advanced(FFMPEG_INCLUDE_DIRS
  116. FFMPEG_LIBRARIES
  117. FFMPEG_DEFINITIONS)
  118. endif ()
  119. # Now set the noncached _FOUND vars for the components.
  120. foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE)
  121. set_component_found(${_component})
  122. endforeach ()
  123. # Compile the list of required vars
  124. set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS)
  125. foreach (_component ${FFmpeg_FIND_COMPONENTS})
  126. list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS)
  127. endforeach ()
  128. # Give a nice error message if some of the required vars are missing.
  129. find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS})