FindFFMpeg.cmake 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #
  2. # This module defines the following variables:
  3. #
  4. # FFMPEG_FOUND - All required components and the core library were found
  5. # FFMPEG_INCLUDE_DIRS - Combined list of all components include dirs
  6. # FFMPEG_LIBRARIES - Combined list of all componenets libraries
  7. # FFMPEG_VERSION_STRING - Version of the first component requested
  8. #
  9. # For each requested component the following variables are defined:
  10. #
  11. # FFMPEG_<component>_FOUND - The component was found
  12. # FFMPEG_<component>_INCLUDE_DIRS - The components include dirs
  13. # FFMPEG_<component>_LIBRARIES - The components libraries
  14. # FFMPEG_<component>_VERSION_STRING - The components version string
  15. # FFMPEG_<component>_VERSION_MAJOR - The components major version
  16. # FFMPEG_<component>_VERSION_MINOR - The components minor version
  17. # FFMPEG_<component>_VERSION_MICRO - The components micro version
  18. #
  19. # <component> is the uppercase name of the component
  20. find_package(PkgConfig QUIET)
  21. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  22. set(_lib_suffix 64)
  23. else()
  24. set(_lib_suffix 32)
  25. endif()
  26. function(find_ffmpeg_library component header)
  27. string(TOUPPER "${component}" component_u)
  28. set(FFMPEG_${component_u}_FOUND FALSE PARENT_SCOPE)
  29. set(FFMpeg_${component}_FOUND FALSE PARENT_SCOPE)
  30. if(PKG_CONFIG_FOUND)
  31. pkg_check_modules(PC_FFMPEG_${component} QUIET lib${component})
  32. endif()
  33. find_path(FFMPEG_${component}_INCLUDE_DIR
  34. NAMES
  35. "lib${component}/${header}" "lib${component}/version.h"
  36. HINTS
  37. ENV FFmpegPath${_lib_suffix}
  38. ENV FFmpegPath
  39. ${PC_FFMPEG_${component}_INCLUDE_DIRS}
  40. PATH_SUFFIXES ffmpeg libav)
  41. find_library(FFMPEG_${component}_LIBRARY
  42. NAMES
  43. "${component}" "lib${component}"
  44. HINTS
  45. ENV FFmpegPath${_lib_suffix}
  46. ENV FFmpegPath
  47. ${PC_FFMPEG_${component}_LIBRARY_DIRS}
  48. PATH_SUFFIXES
  49. lib${_lib_suffix} lib
  50. libs${_lib_suffix} libs
  51. bin${_lib_suffix} bin
  52. ../lib${_lib_suffix} ../lib
  53. ../libs${_lib_suffix} ../libs
  54. ../bin${_lib_suffix} ../bin)
  55. set(FFMPEG_${component_u}_INCLUDE_DIRS ${FFMPEG_${component}_INCLUDE_DIR} PARENT_SCOPE)
  56. set(FFMPEG_${component_u}_LIBRARIES ${FFMPEG_${component}_LIBRARY} PARENT_SCOPE)
  57. mark_as_advanced(FFMPEG_${component}_INCLUDE_DIR FFMPEG_${component}_LIBRARY)
  58. if(FFMPEG_${component}_INCLUDE_DIR AND FFMPEG_${component}_LIBRARY)
  59. set(FFMPEG_${component_u}_FOUND TRUE PARENT_SCOPE)
  60. set(FFMpeg_${component}_FOUND TRUE PARENT_SCOPE)
  61. list(APPEND FFMPEG_INCLUDE_DIRS ${FFMPEG_${component}_INCLUDE_DIR})
  62. list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
  63. set(FFMPEG_INCLUDE_DIRS "${FFMPEG_INCLUDE_DIRS}" PARENT_SCOPE)
  64. list(APPEND FFMPEG_LIBRARIES ${FFMPEG_${component}_LIBRARY})
  65. list(REMOVE_DUPLICATES FFMPEG_LIBRARIES)
  66. set(FFMPEG_LIBRARIES "${FFMPEG_LIBRARIES}" PARENT_SCOPE)
  67. set(FFMPEG_${component_u}_VERSION_STRING "unknown" PARENT_SCOPE)
  68. set(_vfile "${FFMPEG_${component}_INCLUDE_DIR}/lib${component}/version.h")
  69. if(EXISTS "${_vfile}")
  70. file(STRINGS "${_vfile}" _version_parse REGEX "^.*VERSION_(MAJOR|MINOR|MICRO)[ \t]+[0-9]+[ \t]*$")
  71. string(REGEX REPLACE ".*VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" _major "${_version_parse}")
  72. string(REGEX REPLACE ".*VERSION_MINOR[ \t]+([0-9]+).*" "\\1" _minor "${_version_parse}")
  73. string(REGEX REPLACE ".*VERSION_MICRO[ \t]+([0-9]+).*" "\\1" _micro "${_version_parse}")
  74. set(FFMPEG_${component_u}_VERSION_MAJOR "${_major}" PARENT_SCOPE)
  75. set(FFMPEG_${component_u}_VERSION_MINOR "${_minor}" PARENT_SCOPE)
  76. set(FFMPEG_${component_u}_VERSION_MICRO "${_micro}" PARENT_SCOPE)
  77. set(FFMPEG_${component_u}_VERSION_STRING "${_major}.${_minor}.${_micro}" PARENT_SCOPE)
  78. else()
  79. message(STATUS "Failed parsing FFMpeg ${component} version")
  80. endif()
  81. endif()
  82. endfunction()
  83. set(FFMPEG_INCLUDE_DIRS)
  84. set(FFMPEG_LIBRARIES)
  85. if(NOT FFMpeg_FIND_COMPONENTS)
  86. message(FATAL_ERROR "No FFMpeg components requested")
  87. endif()
  88. list(GET FFMpeg_FIND_COMPONENTS 0 _first_comp)
  89. string(TOUPPER "${_first_comp}" _first_comp)
  90. foreach(component ${FFMpeg_FIND_COMPONENTS})
  91. if(component STREQUAL "avcodec")
  92. find_ffmpeg_library("${component}" "avcodec.h")
  93. elseif(component STREQUAL "avdevice")
  94. find_ffmpeg_library("${component}" "avdevice.h")
  95. elseif(component STREQUAL "avfilter")
  96. find_ffmpeg_library("${component}" "avfilter.h")
  97. elseif(component STREQUAL "avformat")
  98. find_ffmpeg_library("${component}" "avformat.h")
  99. elseif(component STREQUAL "avresample")
  100. find_ffmpeg_library("${component}" "avresample.h")
  101. elseif(component STREQUAL "avutil")
  102. find_ffmpeg_library("${component}" "avutil.h")
  103. elseif(component STREQUAL "postproc")
  104. find_ffmpeg_library("${component}" "postprocess.h")
  105. elseif(component STREQUAL "swresample")
  106. find_ffmpeg_library("${component}" "swresample.h")
  107. elseif(component STREQUAL "swscale")
  108. find_ffmpeg_library("${component}" "swscale.h")
  109. else()
  110. message(FATAL_ERROR "Unknown FFMpeg component requested: ${component}")
  111. endif()
  112. endforeach()
  113. include(FindPackageHandleStandardArgs)
  114. find_package_handle_standard_args(FFMpeg
  115. FOUND_VAR FFMPEG_FOUND
  116. REQUIRED_VARS FFMPEG_${_first_comp}_LIBRARIES FFMPEG_${_first_comp}_INCLUDE_DIRS
  117. VERSION_VAR FFMPEG_${_first_comp}_VERSION_STRING
  118. HANDLE_COMPONENTS)