🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
6.8 KiB

  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. # - POSTPROC
  16. # - SWSCALE
  17. # - SWRESAMPLE
  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. include(FindPackageHandleStandardArgs)
  31. if(NOT FFmpeg_FIND_COMPONENTS)
  32. set(FFmpeg_FIND_COMPONENTS AVFORMAT AVCODEC AVUTIL)
  33. endif()
  34. #
  35. ### Macro: set_component_found
  36. #
  37. # Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present.
  38. #
  39. macro(set_component_found _component)
  40. if(${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS)
  41. # message(STATUS " - ${_component} found.")
  42. set(${_component}_FOUND TRUE)
  43. else()
  44. # message(STATUS " - ${_component} not found.")
  45. endif()
  46. endmacro()
  47. #
  48. ### Macro: find_component
  49. #
  50. # Checks for the given component by invoking pkgconfig and then looking up the libraries and
  51. # include directories.
  52. #
  53. macro(find_component _component _pkgconfig _library _header)
  54. if(NOT WIN32)
  55. # use pkg-config to get the directories and then use these values
  56. # in the FIND_PATH() and FIND_LIBRARY() calls
  57. find_package(PkgConfig)
  58. if(PKG_CONFIG_FOUND)
  59. pkg_check_modules(PC_${_component} ${_pkgconfig})
  60. endif()
  61. endif()
  62. find_path(${_component}_INCLUDE_DIRS ${_header}
  63. HINTS
  64. ${FFMPEGSDK_INC}
  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. ${FFMPEGSDK_LIB}
  73. ${PC_LIB${_component}_LIBDIR}
  74. ${PC_LIB${_component}_LIBRARY_DIRS}
  75. )
  76. STRING(REGEX REPLACE "/.*" "/version.h" _ver_header ${_header})
  77. if(EXISTS "${${_component}_INCLUDE_DIRS}/${_ver_header}")
  78. file(STRINGS "${${_component}_INCLUDE_DIRS}/${_ver_header}" version_str REGEX "^#define[\t ]+LIB${_component}_VERSION_M.*")
  79. foreach(_str "${version_str}")
  80. if(NOT version_maj)
  81. string(REGEX REPLACE "^.*LIB${_component}_VERSION_MAJOR[\t ]+([0-9]*).*$" "\\1" version_maj "${_str}")
  82. endif()
  83. if(NOT version_min)
  84. string(REGEX REPLACE "^.*LIB${_component}_VERSION_MINOR[\t ]+([0-9]*).*$" "\\1" version_min "${_str}")
  85. endif()
  86. if(NOT version_mic)
  87. string(REGEX REPLACE "^.*LIB${_component}_VERSION_MICRO[\t ]+([0-9]*).*$" "\\1" version_mic "${_str}")
  88. endif()
  89. endforeach()
  90. unset(version_str)
  91. set(${_component}_VERSION "${version_maj}.${version_min}.${version_mic}" CACHE STRING "The ${_component} version number.")
  92. unset(version_maj)
  93. unset(version_min)
  94. unset(version_mic)
  95. endif(EXISTS "${${_component}_INCLUDE_DIRS}/${_ver_header}")
  96. set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number.")
  97. set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.")
  98. set_component_found(${_component})
  99. mark_as_advanced(
  100. ${_component}_INCLUDE_DIRS
  101. ${_component}_LIBRARIES
  102. ${_component}_DEFINITIONS
  103. ${_component}_VERSION)
  104. endmacro()
  105. set(FFMPEGSDK $ENV{FFMPEG_HOME})
  106. if(FFMPEGSDK)
  107. set(FFMPEGSDK_INC "${FFMPEGSDK}/include")
  108. set(FFMPEGSDK_LIB "${FFMPEGSDK}/lib")
  109. endif()
  110. # Check for all possible components.
  111. find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
  112. find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
  113. find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
  114. find_component(AVUTIL libavutil avutil libavutil/avutil.h)
  115. find_component(SWSCALE libswscale swscale libswscale/swscale.h)
  116. find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h)
  117. find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
  118. # Check if the required components were found and add their stuff to the FFMPEG_* vars.
  119. foreach(_component ${FFmpeg_FIND_COMPONENTS})
  120. if(${_component}_FOUND)
  121. # message(STATUS "Required component ${_component} present.")
  122. set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES})
  123. set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS})
  124. list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS})
  125. else()
  126. # message(STATUS "Required component ${_component} missing.")
  127. endif()
  128. endforeach()
  129. # Add libz if it exists (needed for static ffmpeg builds)
  130. find_library(_FFmpeg_HAVE_LIBZ NAMES z)
  131. if(_FFmpeg_HAVE_LIBZ)
  132. set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${_FFmpeg_HAVE_LIBZ})
  133. endif()
  134. # Build the include path and library list with duplicates removed.
  135. if(FFMPEG_INCLUDE_DIRS)
  136. list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
  137. endif()
  138. if(FFMPEG_LIBRARIES)
  139. list(REMOVE_DUPLICATES FFMPEG_LIBRARIES)
  140. endif()
  141. # cache the vars.
  142. set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE)
  143. set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE)
  144. set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE)
  145. mark_as_advanced(FFMPEG_INCLUDE_DIRS FFMPEG_LIBRARIES FFMPEG_DEFINITIONS)
  146. # Now set the noncached _FOUND vars for the components.
  147. foreach(_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWRESAMPLE SWSCALE)
  148. set_component_found(${_component})
  149. endforeach ()
  150. # Compile the list of required vars
  151. set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS)
  152. foreach(_component ${FFmpeg_FIND_COMPONENTS})
  153. list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS)
  154. endforeach()
  155. # Give a nice error message if some of the required vars are missing.
  156. find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS})