diff options
Diffstat (limited to 'cmake/modules/FindFFMPEG.cmake')
| -rw-r--r-- | cmake/modules/FindFFMPEG.cmake | 293 |
1 files changed, 293 insertions, 0 deletions
diff --git a/cmake/modules/FindFFMPEG.cmake b/cmake/modules/FindFFMPEG.cmake new file mode 100644 index 0000000..63505a5 --- /dev/null +++ b/cmake/modules/FindFFMPEG.cmake | |||
| @@ -0,0 +1,293 @@ | |||
| 1 | # FindFFMPEG | ||
| 2 | # -------- | ||
| 3 | # Finds FFmpeg libraries | ||
| 4 | # | ||
| 5 | # This module will first look for the required library versions on the system. | ||
| 6 | # If they are not found, it will fall back to downloading and building kodi's own version | ||
| 7 | # | ||
| 8 | # -------- | ||
| 9 | # the following variables influence behaviour: | ||
| 10 | # ENABLE_INTERNAL_FFMPEG - if enabled, kodi's own version will always be built | ||
| 11 | # | ||
| 12 | # FFMPEG_PATH - use external ffmpeg not found in system paths | ||
| 13 | # usage: -DFFMPEG_PATH=/path/to/ffmpeg_install_prefix | ||
| 14 | # | ||
| 15 | # WITH_FFMPEG - use external ffmpeg not found in system paths | ||
| 16 | # WARNING: this option is for developers as it will _disable ffmpeg version checks_! | ||
| 17 | # Consider using FFMPEG_PATH instead, which _does_ check library versions | ||
| 18 | # usage: -DWITH_FFMPEG=/path/to/ffmpeg_install_prefix | ||
| 19 | # | ||
| 20 | # -------- | ||
| 21 | # This module will will define the following variables: | ||
| 22 | # | ||
| 23 | # FFMPEG_FOUND - system has FFmpeg | ||
| 24 | # FFMPEG_INCLUDE_DIRS - FFmpeg include directory | ||
| 25 | # FFMPEG_LIBRARIES - FFmpeg libraries | ||
| 26 | # FFMPEG_DEFINITIONS - pre-processor definitions | ||
| 27 | # FFMPEG_LDFLAGS - linker flags | ||
| 28 | # | ||
| 29 | # and the following imported targets:: | ||
| 30 | # | ||
| 31 | # ffmpeg - The FFmpeg libraries | ||
| 32 | # -------- | ||
| 33 | # | ||
| 34 | |||
| 35 | # required ffmpeg library versions | ||
| 36 | set(REQUIRED_FFMPEG_VERSION 3.3) | ||
| 37 | set(_avcodec_ver ">=57.89.100") | ||
| 38 | set(_avfilter_ver ">=6.82.100") | ||
| 39 | set(_avformat_ver ">=57.71.100") | ||
| 40 | set(_avutil_ver ">=55.58.100") | ||
| 41 | set(_swscale_ver ">=4.6.100") | ||
| 42 | set(_swresample_ver ">=2.7.100") | ||
| 43 | set(_postproc_ver ">=54.5.100") | ||
| 44 | |||
| 45 | |||
| 46 | # Allows building with external ffmpeg not found in system paths, | ||
| 47 | # without library version checks | ||
| 48 | if(WITH_FFMPEG) | ||
| 49 | set(FFMPEG_PATH ${WITH_FFMPEG}) | ||
| 50 | message(STATUS "Warning: FFmpeg version checking disabled") | ||
| 51 | set(REQUIRED_FFMPEG_VERSION undef) | ||
| 52 | unset(_avcodec_ver) | ||
| 53 | unset(_avfilter_ver) | ||
| 54 | unset(_avformat_ver) | ||
| 55 | unset(_avutil_ver) | ||
| 56 | unset(_swscale_ver) | ||
| 57 | unset(_swresample_ver) | ||
| 58 | unset(_postproc_ver) | ||
| 59 | endif() | ||
| 60 | |||
| 61 | # Allows building with external ffmpeg not found in system paths, | ||
| 62 | # with library version checks | ||
| 63 | if(FFMPEG_PATH) | ||
| 64 | set(ENABLE_INTERNAL_FFMPEG OFF) | ||
| 65 | endif() | ||
| 66 | |||
| 67 | # external FFMPEG | ||
| 68 | if(NOT ENABLE_INTERNAL_FFMPEG OR KODI_DEPENDSBUILD) | ||
| 69 | if(FFMPEG_PATH) | ||
| 70 | set(ENV{PKG_CONFIG_PATH} "${FFMPEG_PATH}/lib/pkgconfig") | ||
| 71 | list(APPEND CMAKE_PREFIX_PATH ${FFMPEG_PATH}) | ||
| 72 | endif() | ||
| 73 | |||
| 74 | set(FFMPEG_PKGS libavcodec${_avcodec_ver} | ||
| 75 | libavfilter${_avfilter_ver} | ||
| 76 | libavformat${_avformat_ver} | ||
| 77 | libavutil${_avutil_ver} | ||
| 78 | libswscale${_swscale_ver} | ||
| 79 | libswresample${_swresample_ver} | ||
| 80 | libpostproc${_postproc_ver}) | ||
| 81 | |||
| 82 | if(PKG_CONFIG_FOUND) | ||
| 83 | pkg_check_modules(PC_FFMPEG ${FFMPEG_PKGS} QUIET) | ||
| 84 | string(REGEX REPLACE "framework;" "framework " PC_FFMPEG_LDFLAGS "${PC_FFMPEG_LDFLAGS}") | ||
| 85 | endif() | ||
| 86 | |||
| 87 | find_path(FFMPEG_INCLUDE_DIRS libavcodec/avcodec.h libavfilter/avfilter.h libavformat/avformat.h | ||
| 88 | libavutil/avutil.h libswscale/swscale.h libpostproc/postprocess.h | ||
| 89 | PATH_SUFFIXES ffmpeg | ||
| 90 | PATHS ${PC_FFMPEG_INCLUDE_DIRS} | ||
| 91 | NO_DEFAULT_PATH) | ||
| 92 | find_path(FFMPEG_INCLUDE_DIRS libavcodec/avcodec.h libavfilter/avfilter.h libavformat/avformat.h | ||
| 93 | libavutil/avutil.h libswscale/swscale.h libpostproc/postprocess.h) | ||
| 94 | |||
| 95 | find_library(FFMPEG_LIBAVCODEC | ||
| 96 | NAMES avcodec libavcodec | ||
| 97 | PATH_SUFFIXES ffmpeg/libavcodec | ||
| 98 | PATHS ${PC_FFMPEG_libavcodec_LIBDIR} | ||
| 99 | NO_DEFAULT_PATH) | ||
| 100 | find_library(FFMPEG_LIBAVCODEC NAMES avcodec libavcodec PATH_SUFFIXES ffmpeg/libavcodec) | ||
| 101 | |||
| 102 | find_library(FFMPEG_LIBAVFILTER | ||
| 103 | NAMES avfilter libavfilter | ||
| 104 | PATH_SUFFIXES ffmpeg/libavfilter | ||
| 105 | PATHS ${PC_FFMPEG_libavfilter_LIBDIR} | ||
| 106 | NO_DEFAULT_PATH) | ||
| 107 | find_library(FFMPEG_LIBAVFILTER NAMES avfilter libavfilter PATH_SUFFIXES ffmpeg/libavfilter) | ||
| 108 | |||
| 109 | find_library(FFMPEG_LIBAVFORMAT | ||
| 110 | NAMES avformat libavformat | ||
| 111 | PATH_SUFFIXES ffmpeg/libavformat | ||
| 112 | PATHS ${PC_FFMPEG_libavformat_LIBDIR} | ||
| 113 | NO_DEFAULT_PATH) | ||
| 114 | find_library(FFMPEG_LIBAVFORMAT NAMES avformat libavformat PATH_SUFFIXES ffmpeg/libavformat) | ||
| 115 | |||
| 116 | find_library(FFMPEG_LIBAVUTIL | ||
| 117 | NAMES avutil libavutil | ||
| 118 | PATH_SUFFIXES ffmpeg/libavutil | ||
| 119 | PATHS ${PC_FFMPEG_libavutil_LIBDIR} | ||
| 120 | NO_DEFAULT_PATH) | ||
| 121 | find_library(FFMPEG_LIBAVUTIL NAMES avutil libavutil PATH_SUFFIXES ffmpeg/libavutil) | ||
| 122 | |||
| 123 | find_library(FFMPEG_LIBSWSCALE | ||
| 124 | NAMES swscale libswscale | ||
| 125 | PATH_SUFFIXES ffmpeg/libswscale | ||
| 126 | PATHS ${PC_FFMPEG_libswscale_LIBDIR} | ||
| 127 | NO_DEFAULT_PATH) | ||
| 128 | find_library(FFMPEG_LIBSWSCALE NAMES swscale libswscale PATH_SUFFIXES ffmpeg/libswscale) | ||
| 129 | |||
| 130 | find_library(FFMPEG_LIBSWRESAMPLE | ||
| 131 | NAMES swresample libswresample | ||
| 132 | PATH_SUFFIXES ffmpeg/libswresample | ||
| 133 | PATHS ${PC_FFMPEG_libswresample_LIBDIR} | ||
| 134 | NO_DEFAULT_PATH) | ||
| 135 | find_library(FFMPEG_LIBSWRESAMPLE NAMES NAMES swresample libswresample PATH_SUFFIXES ffmpeg/libswresample) | ||
| 136 | |||
| 137 | find_library(FFMPEG_LIBPOSTPROC | ||
| 138 | NAMES postproc libpostproc | ||
| 139 | PATH_SUFFIXES ffmpeg/libpostproc | ||
| 140 | PATHS ${PC_FFMPEG_libpostproc_LIBDIR} | ||
| 141 | NO_DEFAULT_PATH) | ||
| 142 | find_library(FFMPEG_LIBPOSTPROC NAMES postproc libpostproc PATH_SUFFIXES ffmpeg/libpostproc) | ||
| 143 | |||
| 144 | if((PC_FFMPEG_FOUND | ||
| 145 | AND PC_FFMPEG_libavcodec_VERSION | ||
| 146 | AND PC_FFMPEG_libavfilter_VERSION | ||
| 147 | AND PC_FFMPEG_libavformat_VERSION | ||
| 148 | AND PC_FFMPEG_libavutil_VERSION | ||
| 149 | AND PC_FFMPEG_libswscale_VERSION | ||
| 150 | AND PC_FFMPEG_libswresample_VERSION | ||
| 151 | AND PC_FFMPEG_libpostproc_VERSION) | ||
| 152 | OR WIN32) | ||
| 153 | set(FFMPEG_VERSION ${REQUIRED_FFMPEG_VERSION}) | ||
| 154 | |||
| 155 | |||
| 156 | include(FindPackageHandleStandardArgs) | ||
| 157 | find_package_handle_standard_args(FFMPEG | ||
| 158 | VERSION_VAR FFMPEG_VERSION | ||
| 159 | REQUIRED_VARS FFMPEG_INCLUDE_DIRS | ||
| 160 | FFMPEG_LIBAVCODEC | ||
| 161 | FFMPEG_LIBAVFILTER | ||
| 162 | FFMPEG_LIBAVFORMAT | ||
| 163 | FFMPEG_LIBAVUTIL | ||
| 164 | FFMPEG_LIBSWSCALE | ||
| 165 | FFMPEG_LIBSWRESAMPLE | ||
| 166 | FFMPEG_LIBPOSTPROC | ||
| 167 | FFMPEG_VERSION | ||
| 168 | FAIL_MESSAGE "FFmpeg ${REQUIRED_FFMPEG_VERSION} not found, please consider using -DENABLE_INTERNAL_FFMPEG=ON") | ||
| 169 | |||
| 170 | else() | ||
| 171 | message(STATUS "FFmpeg ${REQUIRED_FFMPEG_VERSION} not found, falling back to internal build") | ||
| 172 | unset(FFMPEG_INCLUDE_DIRS) | ||
| 173 | unset(FFMPEG_INCLUDE_DIRS CACHE) | ||
| 174 | unset(FFMPEG_LIBRARIES) | ||
| 175 | unset(FFMPEG_LIBRARIES CACHE) | ||
| 176 | unset(FFMPEG_DEFINITIONS) | ||
| 177 | unset(FFMPEG_DEFINITIONS CACHE) | ||
| 178 | endif() | ||
| 179 | |||
| 180 | if(FFMPEG_FOUND) | ||
| 181 | set(FFMPEG_LDFLAGS ${PC_FFMPEG_LDFLAGS} CACHE STRING "ffmpeg linker flags") | ||
| 182 | |||
| 183 | # check if ffmpeg libs are statically linked | ||
| 184 | set(FFMPEG_LIB_TYPE SHARED) | ||
| 185 | foreach(_fflib IN LISTS FFMPEG_LIBRARIES) | ||
| 186 | if(${_fflib} MATCHES ".+\.a$" AND PC_FFMPEG_STATIC_LDFLAGS) | ||
| 187 | set(FFMPEG_LDFLAGS ${PC_FFMPEG_STATIC_LDFLAGS} CACHE STRING "ffmpeg linker flags" FORCE) | ||
| 188 | set(FFMPEG_LIB_TYPE STATIC) | ||
| 189 | break() | ||
| 190 | endif() | ||
| 191 | endforeach() | ||
| 192 | |||
| 193 | set(FFMPEG_LIBRARIES ${FFMPEG_LIBAVCODEC} ${FFMPEG_LIBAVFILTER} | ||
| 194 | ${FFMPEG_LIBAVFORMAT} ${FFMPEG_LIBAVUTIL} | ||
| 195 | ${FFMPEG_LIBSWSCALE} ${FFMPEG_LIBSWRESAMPLE} | ||
| 196 | ${FFMPEG_LIBPOSTPROC} ${FFMPEG_LDFLAGS}) | ||
| 197 | list(APPEND FFMPEG_DEFINITIONS -DFFMPEG_VER_SHA=\"${FFMPEG_VERSION}\") | ||
| 198 | |||
| 199 | if(NOT TARGET ffmpeg) | ||
| 200 | add_library(ffmpeg ${FFMPEG_LIB_TYPE} IMPORTED) | ||
| 201 | set_target_properties(ffmpeg PROPERTIES | ||
| 202 | FOLDER "External Projects" | ||
| 203 | IMPORTED_LOCATION "${FFMPEG_LIBRARIES}" | ||
| 204 | INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}" | ||
| 205 | INTERFACE_LINK_LIBRARIES "${FFMPEG_LDFLAGS}" | ||
| 206 | INTERFACE_COMPILE_DEFINITIONS "${FFMPEG_DEFINITIONS}") | ||
| 207 | endif() | ||
| 208 | endif() | ||
| 209 | endif() | ||
| 210 | |||
| 211 | # Internal FFMPEG | ||
| 212 | if(NOT FFMPEG_FOUND) | ||
| 213 | include(ExternalProject) | ||
| 214 | file(STRINGS ${CMAKE_SOURCE_DIR}/tools/depends/target/ffmpeg/FFMPEG-VERSION VER) | ||
| 215 | string(REGEX MATCH "VERSION=[^ ]*$.*" FFMPEG_VER "${VER}") | ||
| 216 | list(GET FFMPEG_VER 0 FFMPEG_VER) | ||
| 217 | string(SUBSTRING "${FFMPEG_VER}" 8 -1 FFMPEG_VER) | ||
| 218 | string(REGEX MATCH "BASE_URL=([^ ]*)" FFMPEG_BASE_URL "${VER}") | ||
| 219 | list(GET FFMPEG_BASE_URL 0 FFMPEG_BASE_URL) | ||
| 220 | string(SUBSTRING "${FFMPEG_BASE_URL}" 9 -1 FFMPEG_BASE_URL) | ||
| 221 | |||
| 222 | # allow user to override the download URL with a local tarball | ||
| 223 | # needed for offline build envs | ||
| 224 | if(FFMPEG_URL) | ||
| 225 | get_filename_component(FFMPEG_URL "${FFMPEG_URL}" ABSOLUTE) | ||
| 226 | else() | ||
| 227 | set(FFMPEG_URL ${FFMPEG_BASE_URL}/${FFMPEG_VER}.tar.gz) | ||
| 228 | endif() | ||
| 229 | if(VERBOSE) | ||
| 230 | message(STATUS "FFMPEG_URL: ${FFMPEG_URL}") | ||
| 231 | endif() | ||
| 232 | |||
| 233 | if(KODI_DEPENDSBUILD) | ||
| 234 | set(CROSS_ARGS -DDEPENDS_PATH=${DEPENDS_PATH} | ||
| 235 | -DPKG_CONFIG_EXECUTABLE=${PKG_CONFIG_EXECUTABLE} | ||
| 236 | -DCROSSCOMPILING=${CMAKE_CROSSCOMPILING} | ||
| 237 | -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} | ||
| 238 | -DOS=${OS} | ||
| 239 | -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} | ||
| 240 | -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} | ||
| 241 | -DCMAKE_AR=${CMAKE_AR}) | ||
| 242 | endif() | ||
| 243 | |||
| 244 | externalproject_add(ffmpeg | ||
| 245 | URL ${FFMPEG_URL} | ||
| 246 | DOWNLOAD_NAME ffmpeg-${FFMPEG_VER}.tar.gz | ||
| 247 | DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/download | ||
| 248 | PREFIX ${CORE_BUILD_DIR}/ffmpeg | ||
| 249 | CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR} | ||
| 250 | -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} | ||
| 251 | -DFFMPEG_VER=${FFMPEG_VER} | ||
| 252 | -DCORE_SYSTEM_NAME=${CORE_SYSTEM_NAME} | ||
| 253 | -DCPU=${CPU} | ||
| 254 | -DENABLE_NEON=${ENABLE_NEON} | ||
| 255 | -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} | ||
| 256 | -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} | ||
| 257 | -DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS} | ||
| 258 | ${CROSS_ARGS} | ||
| 259 | PATCH_COMMAND ${CMAKE_COMMAND} -E copy | ||
| 260 | ${CMAKE_SOURCE_DIR}/tools/depends/target/ffmpeg/CMakeLists.txt | ||
| 261 | <SOURCE_DIR> && | ||
| 262 | ${CMAKE_COMMAND} -E copy | ||
| 263 | ${CMAKE_SOURCE_DIR}/tools/depends/target/ffmpeg/FindGnuTls.cmake | ||
| 264 | <SOURCE_DIR>) | ||
| 265 | |||
| 266 | file(WRITE ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ffmpeg/ffmpeg-link-wrapper | ||
| 267 | "#!/bin/bash | ||
| 268 | if [[ $@ == *${APP_NAME_LC}.bin* || $@ == *${APP_NAME_LC}.so* || $@ == *${APP_NAME_LC}-test* ]] | ||
| 269 | then | ||
| 270 | avformat=`PKG_CONFIG_PATH=${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/lib/pkgconfig ${PKG_CONFIG_EXECUTABLE} --libs --static libavcodec` | ||
| 271 | avcodec=`PKG_CONFIG_PATH=${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/lib/pkgconfig ${PKG_CONFIG_EXECUTABLE} --libs --static libavformat` | ||
| 272 | avfilter=`PKG_CONFIG_PATH=${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/lib/pkgconfig ${PKG_CONFIG_EXECUTABLE} --libs --static libavfilter` | ||
| 273 | avutil=`PKG_CONFIG_PATH=${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/lib/pkgconfig ${PKG_CONFIG_EXECUTABLE} --libs --static libavutil` | ||
| 274 | swscale=`PKG_CONFIG_PATH=${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/lib/pkgconfig ${PKG_CONFIG_EXECUTABLE} --libs --static libswscale` | ||
| 275 | swresample=`PKG_CONFIG_PATH=${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/lib/pkgconfig ${PKG_CONFIG_EXECUTABLE} --libs --static libswresample` | ||
| 276 | gnutls=`PKG_CONFIG_PATH=${DEPENDS_PATH}/lib/pkgconfig/ ${PKG_CONFIG_EXECUTABLE} --libs-only-l --static --silence-errors gnutls` | ||
| 277 | $@ $avcodec $avformat $avcodec $avfilter $swscale $swresample -lpostproc $gnutls | ||
| 278 | else | ||
| 279 | $@ | ||
| 280 | fi") | ||
| 281 | file(COPY ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ffmpeg/ffmpeg-link-wrapper | ||
| 282 | DESTINATION ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR} | ||
| 283 | FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE) | ||
| 284 | set(FFMPEG_LINK_EXECUTABLE "${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ffmpeg-link-wrapper <CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" PARENT_SCOPE) | ||
| 285 | set(FFMPEG_CREATE_SHARED_LIBRARY "${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ffmpeg-link-wrapper <CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" PARENT_SCOPE) | ||
| 286 | set(FFMPEG_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/include) | ||
| 287 | list(APPEND FFMPEG_DEFINITIONS -DFFMPEG_VER_SHA=\"${FFMPEG_VER}\" | ||
| 288 | -DUSE_STATIC_FFMPEG=1) | ||
| 289 | set(FFMPEG_FOUND 1) | ||
| 290 | set_target_properties(ffmpeg PROPERTIES FOLDER "External Projects") | ||
| 291 | endif() | ||
| 292 | |||
| 293 | mark_as_advanced(FFMPEG_INCLUDE_DIRS FFMPEG_LIBRARIES FFMPEG_LDFLAGS FFMPEG_DEFINITIONS FFMPEG_FOUND) | ||
