FindFFmpeg.cmake 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # - Try to find ffmpeg libraries (libavcodec, libavformat, libavutil and libswscale)
  2. # Once done this will define
  3. #
  4. # FFMPEG_FOUND - system has ffmpeg or libav
  5. # FFMPEG_INCLUDE_DIR - the ffmpeg include directory
  6. # FFMPEG_LIBRARIES - Link these to use ffmpeg
  7. # FFMPEG_LIBAVCODEC
  8. # FFMPEG_LIBAVFORMAT
  9. # FFMPEG_LIBAVUTIL
  10. # FFMPEG_LIBSWSCALE
  11. #
  12. # Copyright (c) 2008 Andreas Schneider <mail@cynapses.org>
  13. # Modified for other libraries by Lasse Kärkkäinen <tronic>
  14. # Modified for Hedgewars by Stepik777
  15. # Modified for FFmpeg-example Tuukka Pasanen 2018
  16. #
  17. # Redistribution and use is allowed according to the terms of the New
  18. # BSD license.
  19. #
  20. include(FindPackageHandleStandardArgs)
  21. find_package_handle_standard_args(FFMPEG
  22. FOUND_VAR FFMPEG_FOUND
  23. REQUIRED_VARS
  24. FFMPEG_LIBRARY
  25. FFMPEG_INCLUDE_DIR
  26. VERSION_VAR FFMPEG_VERSION
  27. )
  28. if(FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
  29. # in cache already
  30. set(FFMPEG_FOUND TRUE)
  31. else()
  32. # use pkg-config to get the directories and then use these values
  33. # in the FIND_PATH() and FIND_LIBRARY() calls
  34. find_package(PkgConfig)
  35. if(PKG_CONFIG_FOUND)
  36. pkg_check_modules(_FFMPEG_AVCODEC libavcodec)
  37. pkg_check_modules(_FFMPEG_AVFORMAT libavformat)
  38. pkg_check_modules(_FFMPEG_AVUTIL libavutil)
  39. pkg_check_modules(_FFMPEG_SWSCALE libswscale)
  40. endif()
  41. find_path(FFMPEG_AVCODEC_INCLUDE_DIR
  42. NAMES libavcodec/avcodec.h
  43. PATHS ${_FFMPEG_AVCODEC_INCLUDE_DIRS}
  44. /usr/include
  45. /usr/local/include
  46. /opt/local/include
  47. /sw/include
  48. PATH_SUFFIXES ffmpeg libav)
  49. find_library(FFMPEG_LIBAVCODEC
  50. NAMES avcodec
  51. PATHS ${_FFMPEG_AVCODEC_LIBRARY_DIRS}
  52. /usr/lib
  53. /usr/local/lib
  54. /opt/local/lib
  55. /sw/lib)
  56. find_library(FFMPEG_LIBAVFORMAT
  57. NAMES avformat
  58. PATHS ${_FFMPEG_AVFORMAT_LIBRARY_DIRS}
  59. /usr/lib
  60. /usr/local/lib
  61. /opt/local/lib
  62. /sw/lib)
  63. find_library(FFMPEG_LIBAVUTIL
  64. NAMES avutil
  65. PATHS ${_FFMPEG_AVUTIL_LIBRARY_DIRS}
  66. /usr/lib
  67. /usr/local/lib
  68. /opt/local/lib
  69. /sw/lib)
  70. find_library(FFMPEG_LIBSWSCALE
  71. NAMES swscale
  72. PATHS ${_FFMPEG_SWSCALE_LIBRARY_DIRS}
  73. /usr/lib
  74. /usr/local/lib
  75. /opt/local/lib
  76. /sw/lib)
  77. if(FFMPEG_LIBAVCODEC AND FFMPEG_LIBAVFORMAT)
  78. set(FFMPEG_FOUND TRUE)
  79. endif()
  80. if(FFMPEG_FOUND)
  81. set(FFMPEG_INCLUDE_DIR ${FFMPEG_AVCODEC_INCLUDE_DIR})
  82. set(FFMPEG_LIBRARIES
  83. ${FFMPEG_LIBAVCODEC}
  84. ${FFMPEG_LIBAVFORMAT}
  85. ${FFMPEG_LIBAVUTIL}
  86. ${FFMPEG_LIBSWSCALE})
  87. endif()
  88. if(FFMPEG_FOUND)
  89. if(NOT FFMPEG_FIND_QUIETLY)
  90. message(STATUS
  91. "Found FFMPEG or Libav: ${FFMPEG_LIBRARIES}, ${FFMPEG_INCLUDE_DIR}")
  92. endif()
  93. else()
  94. if(FFMPEG_FIND_REQUIRED)
  95. message(FATAL_ERROR
  96. "Could not find libavcodec or libavformat or libavutil or libswscale")
  97. endif()
  98. endif()
  99. endif()