diff options
Diffstat (limited to 'project/cmake/modules/FindFFMPEG.cmake')
| -rw-r--r-- | project/cmake/modules/FindFFMPEG.cmake | 258 |
1 files changed, 218 insertions, 40 deletions
diff --git a/project/cmake/modules/FindFFMPEG.cmake b/project/cmake/modules/FindFFMPEG.cmake index a9f88fb..2b3f47b 100644 --- a/project/cmake/modules/FindFFMPEG.cmake +++ b/project/cmake/modules/FindFFMPEG.cmake | |||
| @@ -1,18 +1,224 @@ | |||
| 1 | include(ExternalProject) | 1 | # FindFFMPEG |
| 2 | file(STRINGS ${CORE_SOURCE_DIR}/tools/depends/target/ffmpeg/FFMPEG-VERSION VER) | 2 | # -------- |
| 3 | string(REGEX MATCH "VERSION=[^ ]*$.*" FFMPEG_VER "${VER}") | 3 | # Finds FFmpeg libraries |
| 4 | list(GET FFMPEG_VER 0 FFMPEG_VER) | 4 | # |
| 5 | string(SUBSTRING "${FFMPEG_VER}" 8 -1 FFMPEG_VER) | 5 | # This module will first look for the required library versions on the system. |
| 6 | string(REGEX MATCH "BASE_URL=([^ ]*)" FFMPEG_BASE_URL "${VER}") | 6 | # If they are not found, it will fall back to downloading and building kodi's own version |
| 7 | list(GET FFMPEG_BASE_URL 0 FFMPEG_BASE_URL) | 7 | # |
| 8 | string(SUBSTRING "${FFMPEG_BASE_URL}" 9 -1 FFMPEG_BASE_URL) | 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 | # | ||
| 9 | 34 | ||
| 35 | # required ffmpeg library versions | ||
| 36 | set(REQUIRED_FFMPEG_VERSION 3.1) | ||
| 37 | set(_avcodec_ver ">=57.48.101") | ||
| 38 | set(_avfilter_ver ">=6.47.100") | ||
| 39 | set(_avformat_ver ">=57.41.100") | ||
| 40 | set(_avutil_ver ">=55.28.100") | ||
| 41 | set(_swscale_ver ">=4.1.100") | ||
| 42 | set(_swresample_ver ">=2.1.100") | ||
| 43 | set(_postproc_ver ">=54.0.100") | ||
| 10 | 44 | ||
| 11 | if(ENABLE_INTERNAL_FFMPEG) | 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 CMAKE_CROSSCOMPILING) | ||
| 12 | if(FFMPEG_PATH) | 69 | if(FFMPEG_PATH) |
| 13 | message(WARNING "Internal FFmpeg enabled, but FFMPEG_PATH given, ignoring") | 70 | set(ENV{PKG_CONFIG_PATH} "${FFMPEG_PATH}/lib/pkgconfig") |
| 71 | list(APPEND CMAKE_PREFIX_PATH ${FFMPEG_PATH}) | ||
| 14 | endif() | 72 | endif() |
| 15 | 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 ${CORE_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 | |||
| 16 | # allow user to override the download URL with a local tarball | 222 | # allow user to override the download URL with a local tarball |
| 17 | # needed for offline build envs | 223 | # needed for offline build envs |
| 18 | if(FFMPEG_URL) | 224 | if(FFMPEG_URL) |
| @@ -80,35 +286,7 @@ fi") | |||
| 80 | list(APPEND FFMPEG_DEFINITIONS -DFFMPEG_VER_SHA=\"${FFMPEG_VER}\" | 286 | list(APPEND FFMPEG_DEFINITIONS -DFFMPEG_VER_SHA=\"${FFMPEG_VER}\" |
| 81 | -DUSE_STATIC_FFMPEG=1) | 287 | -DUSE_STATIC_FFMPEG=1) |
| 82 | set(FFMPEG_FOUND 1) | 288 | set(FFMPEG_FOUND 1) |
| 83 | else() | 289 | set_target_properties(ffmpeg PROPERTIES FOLDER "External Projects") |
| 84 | if(FFMPEG_PATH) | ||
| 85 | set(ENV{PKG_CONFIG_PATH} "${FFMPEG_PATH}/lib/pkgconfig") | ||
| 86 | endif() | ||
| 87 | set(FFMPEG_PKGS libavcodec>=56.26.100 libavfilter>=5.11.100 libavformat>=56.25.101 | ||
| 88 | libavutil>=54.20.100 libswscale>=3.1.101 libswresample>=1.1.100 libpostproc>=53.3.100) | ||
| 89 | if(PKG_CONFIG_FOUND AND NOT WIN32) | ||
| 90 | pkg_check_modules (FFMPEG ${FFMPEG_PKGS}) | ||
| 91 | string(REGEX REPLACE "framework;" "framework " FFMPEG_LDFLAGS "${FFMPEG_LDFLAGS}") | ||
| 92 | set(FFMPEG_LIBRARIES ${FFMPEG_LDFLAGS}) | ||
| 93 | add_custom_target(ffmpeg) | ||
| 94 | else() | ||
| 95 | find_path(FFMPEG_INCLUDE_DIRS libavcodec/avcodec.h PATH_SUFFIXES ffmpeg) | ||
| 96 | find_library(FFMPEG_LIBAVCODEC NAMES avcodec libavcodec PATH_SUFFIXES ffmpeg/libavcodec) | ||
| 97 | find_library(FFMPEG_LIBAVFILTER NAMES avfilter libavfilter PATH_SUFFIXES ffmpeg/libavfilter) | ||
| 98 | find_library(FFMPEG_LIBAVFORMAT NAMES avformat libavformat PATH_SUFFIXES ffmpeg/libavformat) | ||
| 99 | find_library(FFMPEG_LIBAVUTIL NAMES avutil libavutil PATH_SUFFIXES ffmpeg/libavutil) | ||
| 100 | find_library(FFMPEG_LIBSWSCALE NAMES swscale libswscale PATH_SUFFIXES ffmpeg/libswscale) | ||
| 101 | find_library(FFMPEG_LIBPOSTPROC NAMES postproc libpostproc PATH_SUFFIXES ffmpeg/libpostproc) | ||
| 102 | set(FFMPEG_LIBRARIES ${FFMPEG_LIBAVCODEC} ${FFMPEG_LIBAVFILTER} ${FFMPEG_LIBAVFORMAT} | ||
| 103 | ${FFMPEG_LIBAVUTIL} ${FFMPEG_LIBSWSCALE} ${FFMPEG_LIBPOSTPROC}) | ||
| 104 | add_custom_target(ffmpeg DEPENDS ${FFMPEG_LIBRARIES}) | ||
| 105 | endif() | ||
| 106 | |||
| 107 | include(FindPackageHandleStandardArgs) | ||
| 108 | find_package_handle_standard_args(FFMPEG DEFAULT_MSG FFMPEG_INCLUDE_DIRS FFMPEG_LIBRARIES) | ||
| 109 | set(FFMPEG_FOUND 1) | ||
| 110 | list(APPEND FFMPEG_DEFINITIONS -DFFMPEG_VER_SHA=\"${FFMPEG_VER}\") | ||
| 111 | endif() | 290 | endif() |
| 112 | set_target_properties(ffmpeg PROPERTIES FOLDER "External Projects") | ||
| 113 | 291 | ||
| 114 | mark_as_advanced(FFMPEG_INCLUDE_DIRS FFMPEG_LIBRARIES FFMPEG_DEFINITIONS FFMPEG_FOUND) | 292 | mark_as_advanced(FFMPEG_INCLUDE_DIRS FFMPEG_LIBRARIES FFMPEG_LDFLAGS FFMPEG_DEFINITIONS FFMPEG_FOUND) |
