FindFFmpeg.cmake 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # - Try to find ffmpeg libraries (libavcodec, libavformat and libavutil)
  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. #
  11. # Copyright (c) 2008 Andreas Schneider <mail@cynapses.org>
  12. # Modified for other libraries by Lasse Kärkkäinen <tronic>
  13. # Modified for Hedgewars by Stepik777
  14. # Modified for FFmpeg-example Tuukka Pasanen 2018
  15. # Modified for yuzu toastUnlimted 2020
  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_AVUTIL libavutil)
  38. pkg_check_modules(_FFMPEG_SWSCALE libswscale)
  39. endif()
  40. find_path(FFMPEG_AVCODEC_INCLUDE_DIR
  41. NAMES libavcodec/avcodec.h
  42. PATHS ${_FFMPEG_AVCODEC_INCLUDE_DIRS}
  43. /usr/include
  44. /usr/local/include
  45. /opt/local/include
  46. /sw/include
  47. PATH_SUFFIXES ffmpeg libav)
  48. find_library(FFMPEG_LIBAVCODEC
  49. NAMES avcodec
  50. PATHS ${_FFMPEG_AVCODEC_LIBRARY_DIRS}
  51. /usr/lib
  52. /usr/local/lib
  53. /opt/local/lib
  54. /sw/lib)
  55. find_library(FFMPEG_LIBAVUTIL
  56. NAMES avutil
  57. PATHS ${_FFMPEG_AVUTIL_LIBRARY_DIRS}
  58. /usr/lib
  59. /usr/local/lib
  60. /opt/local/lib
  61. /sw/lib)
  62. find_library(FFMPEG_LIBSWSCALE
  63. NAMES swscale
  64. PATHS ${_FFMPEG_SWSCALE_LIBRARY_DIRS}
  65. /usr/lib
  66. /usr/local/lib
  67. /opt/local/lib
  68. /sw/lib)
  69. if(FFMPEG_LIBAVCODEC AND FFMPEG_LIBAVUTIL AND FFMPEG_LIBSWSCALE)
  70. set(FFMPEG_FOUND TRUE)
  71. endif()
  72. if(FFMPEG_FOUND)
  73. set(FFMPEG_INCLUDE_DIR ${FFMPEG_AVCODEC_INCLUDE_DIR})
  74. set(FFMPEG_LIBRARIES
  75. ${FFMPEG_LIBAVCODEC}
  76. ${FFMPEG_LIBAVUTIL}
  77. ${FFMPEG_LIBSWSCALE})
  78. endif()
  79. if(FFMPEG_FOUND)
  80. if(NOT FFMPEG_FIND_QUIETLY)
  81. message(STATUS
  82. "Found FFMPEG or Libav: ${FFMPEG_LIBRARIES}, ${FFMPEG_INCLUDE_DIR}")
  83. endif()
  84. else()
  85. if(FFMPEG_FIND_REQUIRED)
  86. message(FATAL_ERROR
  87. "Could not find libavcodec or libavutil or libswscale")
  88. endif()
  89. endif()
  90. endif()