PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/strigi-0.7.7/libstreamanalyzer/cmake/FindFFmpeg.cmake

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