portfile.cmake 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. vcpkg_from_github(
  2. OUT_SOURCE_PATH SOURCE_PATH
  3. REPO ffmpeg/ffmpeg
  4. REF "n${VERSION}"
  5. SHA512 3ba02e8b979c80bf61d55f414bdac2c756578bb36498ed7486151755c6ccf8bd8ff2b8c7afa3c5d1acd862ce48314886a86a105613c05e36601984c334f8f6bf
  6. HEAD_REF master
  7. PATCHES
  8. 0002-fix-msvc-link.patch # upstreamed in future version
  9. 0003-fix-windowsinclude.patch
  10. 0005-fix-nasm.patch # upstreamed in future version
  11. 0012-Fix-ssl-110-detection.patch
  12. 0013-define-WINVER.patch
  13. patch/0001-avcodec-amfenc-add-query_timeout-option-for-h264-hev.patch
  14. patch/0002-libavcodec-amfenc-reconfig-when-bitrate-change.patch
  15. patch/0003-amf-colorspace.patch
  16. )
  17. if(SOURCE_PATH MATCHES " ")
  18. message(FATAL_ERROR "Error: ffmpeg will not build with spaces in the path. Please use a directory with no spaces")
  19. endif()
  20. if(NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "wasm32")
  21. vcpkg_find_acquire_program(NASM)
  22. get_filename_component(NASM_EXE_PATH "${NASM}" DIRECTORY)
  23. vcpkg_add_to_path("${NASM_EXE_PATH}")
  24. endif()
  25. set(OPTIONS "\
  26. --disable-shared \
  27. --enable-static \
  28. --enable-pic \
  29. --disable-everything \
  30. --disable-programs \
  31. --disable-doc \
  32. --disable-htmlpages \
  33. --disable-manpages \
  34. --disable-podpages \
  35. --disable-txtpages \
  36. --disable-network \
  37. --disable-appkit \
  38. --disable-coreimage \
  39. --disable-metal \
  40. --disable-sdl2 \
  41. --disable-securetransport \
  42. --disable-vulkan \
  43. --disable-audiotoolbox \
  44. --disable-v4l2-m2m \
  45. --disable-debug \
  46. --disable-valgrind-backtrace \
  47. --disable-large-tests \
  48. --disable-avdevice \
  49. --enable-avcodec \
  50. --enable-avformat \
  51. --disable-avfilter \
  52. --disable-swresample \
  53. --disable-swscale \
  54. --disable-postproc \
  55. --enable-decoder=h264 \
  56. --enable-decoder=hevc \
  57. --enable-parser=h264 \
  58. --enable-parser=hevc \
  59. --enable-bsf=h264_mp4toannexb \
  60. --enable-bsf=hevc_mp4toannexb \
  61. --enable-bsf=h264_metadata \
  62. --enable-bsf=hevc_metadata \
  63. --enable-muxer=mp4 \
  64. --enable-protocol=file \
  65. ")
  66. if(VCPKG_HOST_IS_WINDOWS)
  67. vcpkg_acquire_msys(MSYS_ROOT PACKAGES automake1.16)
  68. set(SHELL "${MSYS_ROOT}/usr/bin/bash.exe")
  69. vcpkg_add_to_path("${MSYS_ROOT}/usr/share/automake-1.16")
  70. string(APPEND OPTIONS " --pkg-config=${CURRENT_HOST_INSTALLED_DIR}/tools/pkgconf/pkgconf${VCPKG_HOST_EXECUTABLE_SUFFIX}")
  71. else()
  72. find_program(SHELL bash)
  73. endif()
  74. if(VCPKG_TARGET_IS_LINUX)
  75. string(APPEND OPTIONS "\
  76. --target-os=linux \
  77. --enable-pthreads \
  78. ")
  79. if(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm")
  80. else()
  81. string(APPEND OPTIONS "\
  82. --enable-cuda \
  83. --enable-ffnvcodec \
  84. --enable-encoder=h264_nvenc \
  85. --enable-encoder=hevc_nvenc \
  86. --enable-hwaccel=h264_nvdec \
  87. --enable-hwaccel=hevc_nvdec \
  88. --enable-amf \
  89. --enable-encoder=h264_amf \
  90. --enable-encoder=hevc_amf \
  91. --enable-hwaccel=h264_vaapi \
  92. --enable-hwaccel=hevc_vaapi \
  93. --enable-encoder=h264_vaapi \
  94. --enable-encoder=hevc_vaapi \
  95. ")
  96. if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
  97. string(APPEND OPTIONS "\
  98. --enable-cuda_llvm \
  99. ")
  100. endif()
  101. endif()
  102. elseif(VCPKG_TARGET_IS_WINDOWS)
  103. string(APPEND OPTIONS "\
  104. --target-os=win32 \
  105. --toolchain=msvc \
  106. --cc=cl \
  107. --enable-gpl \
  108. --enable-d3d11va \
  109. --enable-cuda \
  110. --enable-ffnvcodec \
  111. --enable-hwaccel=h264_nvdec \
  112. --enable-hwaccel=hevc_nvdec \
  113. --enable-hwaccel=h264_d3d11va \
  114. --enable-hwaccel=hevc_d3d11va \
  115. --enable-hwaccel=h264_d3d11va2 \
  116. --enable-hwaccel=hevc_d3d11va2 \
  117. --enable-amf \
  118. --enable-encoder=h264_amf \
  119. --enable-encoder=hevc_amf \
  120. --enable-encoder=h264_nvenc \
  121. --enable-encoder=hevc_nvenc \
  122. --enable-libmfx \
  123. --enable-encoder=h264_qsv \
  124. --enable-encoder=hevc_qsv \
  125. ")
  126. if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
  127. set(LIB_MACHINE_ARG /machine:x86)
  128. string(APPEND OPTIONS " --arch=i686 --enable-cross-compile")
  129. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
  130. set(LIB_MACHINE_ARG /machine:x64)
  131. string(APPEND OPTIONS " --arch=x86_64")
  132. else()
  133. message(FATAL_ERROR "Unsupported target architecture")
  134. endif()
  135. elseif(VCPKG_TARGET_IS_OSX)
  136. string(APPEND OPTIONS "\
  137. --disable-autodetect \
  138. --enable-videotoolbox \
  139. --enable-encoder=h264_videotoolbox,hevc_videotoolbox \
  140. --enable-hwaccel=h264_videotoolbox,hevc_videotoolbox \
  141. ")
  142. elseif(VCPKG_TARGET_IS_IOS)
  143. string(APPEND OPTIONS "\
  144. --arch=arm64 \
  145. --disable-autodetect \
  146. --disable-hwaccels \
  147. --disable-encoders \
  148. --disable-videotoolbox \
  149. --extra-cflags=\"-arch arm64 -mios-version-min=8.0 -fembed-bitcode\" \
  150. --extra-ldflags=\"-arch arm64 -mios-version-min=8.0 -fembed-bitcode\" \
  151. ")
  152. elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "Android")
  153. string(APPEND OPTIONS "\
  154. --target-os=android \
  155. --disable-asm \
  156. --enable-jni \
  157. --enable-mediacodec \
  158. --disable-hwaccels \
  159. --enable-encoder=h264_mediacodec \
  160. --enable-encoder=hevc_mediacodec \
  161. --enable-decoder=h264_mediacodec \
  162. --enable-decoder=hevc_mediacodec \
  163. ")
  164. endif()
  165. if(VCPKG_TARGET_IS_OSX)
  166. list(JOIN VCPKG_OSX_ARCHITECTURES " " OSX_ARCHS)
  167. list(LENGTH VCPKG_OSX_ARCHITECTURES OSX_ARCH_COUNT)
  168. endif()
  169. vcpkg_cmake_get_vars(cmake_vars_file)
  170. include("${cmake_vars_file}")
  171. if(VCPKG_DETECTED_MSVC)
  172. string(APPEND OPTIONS " --disable-inline-asm") # clang-cl has inline assembly but this leads to undefined symbols.
  173. set(OPTIONS "--toolchain=msvc ${OPTIONS}")
  174. # This is required because ffmpeg depends upon optimizations to link correctly
  175. string(APPEND VCPKG_COMBINED_C_FLAGS_DEBUG " -O2")
  176. string(REGEX REPLACE "(^| )-RTC1( |$)" " " VCPKG_COMBINED_C_FLAGS_DEBUG "${VCPKG_COMBINED_C_FLAGS_DEBUG}")
  177. string(REGEX REPLACE "(^| )-Od( |$)" " " VCPKG_COMBINED_C_FLAGS_DEBUG "${VCPKG_COMBINED_C_FLAGS_DEBUG}")
  178. string(REGEX REPLACE "(^| )-Ob0( |$)" " " VCPKG_COMBINED_C_FLAGS_DEBUG "${VCPKG_COMBINED_C_FLAGS_DEBUG}")
  179. endif()
  180. string(APPEND VCPKG_COMBINED_C_FLAGS_DEBUG " -I \"${CURRENT_INSTALLED_DIR}/include\"")
  181. string(APPEND VCPKG_COMBINED_C_FLAGS_RELEASE " -I \"${CURRENT_INSTALLED_DIR}/include\"")
  182. if(VCPKG_TARGET_IS_WINDOWS)
  183. string(APPEND VCPKG_COMBINED_C_FLAGS_DEBUG " -I \"${CURRENT_INSTALLED_DIR}/include/mfx\"")
  184. string(APPEND VCPKG_COMBINED_C_FLAGS_RELEASE " -I \"${CURRENT_INSTALLED_DIR}/include/mfx\"")
  185. endif()
  186. # # Setup vcpkg toolchain
  187. set(prog_env "")
  188. if(VCPKG_DETECTED_CMAKE_C_COMPILER)
  189. get_filename_component(CC_path "${VCPKG_DETECTED_CMAKE_C_COMPILER}" DIRECTORY)
  190. get_filename_component(CC_filename "${VCPKG_DETECTED_CMAKE_C_COMPILER}" NAME)
  191. set(ENV{CC} "${CC_filename}")
  192. string(APPEND OPTIONS " --cc=${CC_filename}")
  193. if(VCPKG_HOST_IS_WINDOWS)
  194. string(APPEND OPTIONS " --host_cc=${CC_filename}")
  195. endif()
  196. list(APPEND prog_env "${CC_path}")
  197. endif()
  198. if(VCPKG_DETECTED_CMAKE_CXX_COMPILER)
  199. get_filename_component(CXX_path "${VCPKG_DETECTED_CMAKE_CXX_COMPILER}" DIRECTORY)
  200. get_filename_component(CXX_filename "${VCPKG_DETECTED_CMAKE_CXX_COMPILER}" NAME)
  201. set(ENV{CXX} "${CXX_filename}")
  202. string(APPEND OPTIONS " --cxx=${CXX_filename}")
  203. # string(APPEND OPTIONS " --host_cxx=${CC_filename}")
  204. list(APPEND prog_env "${CXX_path}")
  205. endif()
  206. if(VCPKG_DETECTED_CMAKE_RC_COMPILER)
  207. get_filename_component(RC_path "${VCPKG_DETECTED_CMAKE_RC_COMPILER}" DIRECTORY)
  208. get_filename_component(RC_filename "${VCPKG_DETECTED_CMAKE_RC_COMPILER}" NAME)
  209. set(ENV{WINDRES} "${RC_filename}")
  210. string(APPEND OPTIONS " --windres=${RC_filename}")
  211. list(APPEND prog_env "${RC_path}")
  212. endif()
  213. if(VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
  214. get_filename_component(LD_path "${VCPKG_DETECTED_CMAKE_LINKER}" DIRECTORY)
  215. get_filename_component(LD_filename "${VCPKG_DETECTED_CMAKE_LINKER}" NAME)
  216. set(ENV{LD} "${LD_filename}")
  217. string(APPEND OPTIONS " --ld=${LD_filename}")
  218. # string(APPEND OPTIONS " --host_ld=${LD_filename}")
  219. list(APPEND prog_env "${LD_path}")
  220. endif()
  221. if(VCPKG_DETECTED_CMAKE_NM)
  222. get_filename_component(NM_path "${VCPKG_DETECTED_CMAKE_NM}" DIRECTORY)
  223. get_filename_component(NM_filename "${VCPKG_DETECTED_CMAKE_NM}" NAME)
  224. set(ENV{NM} "${NM_filename}")
  225. string(APPEND OPTIONS " --nm=${NM_filename}")
  226. list(APPEND prog_env "${NM_path}")
  227. endif()
  228. if(VCPKG_DETECTED_CMAKE_AR)
  229. get_filename_component(AR_path "${VCPKG_DETECTED_CMAKE_AR}" DIRECTORY)
  230. get_filename_component(AR_filename "${VCPKG_DETECTED_CMAKE_AR}" NAME)
  231. if(AR_filename MATCHES [[^(llvm-)?lib\.exe$]])
  232. set(ENV{AR} "ar-lib ${AR_filename}")
  233. string(APPEND OPTIONS " --ar='ar-lib ${AR_filename}'")
  234. else()
  235. set(ENV{AR} "${AR_filename}")
  236. string(APPEND OPTIONS " --ar='${AR_filename}'")
  237. endif()
  238. list(APPEND prog_env "${AR_path}")
  239. endif()
  240. if(VCPKG_DETECTED_CMAKE_RANLIB)
  241. get_filename_component(RANLIB_path "${VCPKG_DETECTED_CMAKE_RANLIB}" DIRECTORY)
  242. get_filename_component(RANLIB_filename "${VCPKG_DETECTED_CMAKE_RANLIB}" NAME)
  243. set(ENV{RANLIB} "${RANLIB_filename}")
  244. string(APPEND OPTIONS " --ranlib=${RANLIB_filename}")
  245. list(APPEND prog_env "${RANLIB_path}")
  246. endif()
  247. if(VCPKG_DETECTED_CMAKE_STRIP)
  248. get_filename_component(STRIP_path "${VCPKG_DETECTED_CMAKE_STRIP}" DIRECTORY)
  249. get_filename_component(STRIP_filename "${VCPKG_DETECTED_CMAKE_STRIP}" NAME)
  250. set(ENV{STRIP} "${STRIP_filename}")
  251. string(APPEND OPTIONS " --strip=${STRIP_filename}")
  252. list(APPEND prog_env "${STRIP_path}")
  253. endif()
  254. if(VCPKG_HOST_IS_WINDOWS)
  255. vcpkg_acquire_msys(MSYS_ROOT PACKAGES automake1.16)
  256. set(SHELL "${MSYS_ROOT}/usr/bin/bash.exe")
  257. list(APPEND prog_env "${MSYS_ROOT}/usr/bin" "${MSYS_ROOT}/usr/share/automake-1.16")
  258. else()
  259. # find_program(SHELL bash)
  260. endif()
  261. list(REMOVE_DUPLICATES prog_env)
  262. vcpkg_add_to_path(PREPEND ${prog_env})
  263. # More? OBJCC BIN2C
  264. file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg" "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
  265. set(FFMPEG_PKGCONFIG_MODULES libavutil)
  266. set(OPTIONS_CROSS "--enable-cross-compile")
  267. # ffmpeg needs --cross-prefix option to use appropriate tools for cross-compiling.
  268. if(VCPKG_DETECTED_CMAKE_C_COMPILER MATCHES "([^\/]*-)gcc$")
  269. string(APPEND OPTIONS_CROSS " --cross-prefix=${CMAKE_MATCH_1}")
  270. endif()
  271. if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
  272. set(BUILD_ARCH "x86_64")
  273. else()
  274. set(BUILD_ARCH ${VCPKG_TARGET_ARCHITECTURE})
  275. endif()
  276. if(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm" OR VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
  277. if(VCPKG_TARGET_IS_WINDOWS)
  278. vcpkg_find_acquire_program(GASPREPROCESSOR)
  279. foreach(GAS_PATH ${GASPREPROCESSOR})
  280. get_filename_component(GAS_ITEM_PATH ${GAS_PATH} DIRECTORY)
  281. vcpkg_add_to_path("${GAS_ITEM_PATH}")
  282. endforeach(GAS_PATH)
  283. endif()
  284. endif()
  285. set(OPTIONS_DEBUG "--disable-optimizations")
  286. set(OPTIONS_RELEASE "--enable-optimizations")
  287. set(OPTIONS "${OPTIONS} ${OPTIONS_CROSS}")
  288. if(VCPKG_TARGET_IS_MINGW)
  289. set(OPTIONS "${OPTIONS} --extra_cflags=-D_WIN32_WINNT=0x0601")
  290. elseif(VCPKG_TARGET_IS_WINDOWS)
  291. set(OPTIONS "${OPTIONS} --extra-cflags=-DHAVE_UNISTD_H=0")
  292. endif()
  293. vcpkg_find_acquire_program(PKGCONFIG)
  294. set(OPTIONS "${OPTIONS} --pkg-config=${PKGCONFIG}")
  295. if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
  296. set(OPTIONS "${OPTIONS} --pkg-config-flags=--static")
  297. endif()
  298. message(STATUS "Building Options: ${OPTIONS}")
  299. # Release build
  300. if(NOT VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
  301. if(VCPKG_DETECTED_MSVC)
  302. set(OPTIONS_RELEASE "${OPTIONS_RELEASE} --extra-ldflags=-libpath:\"${CURRENT_INSTALLED_DIR}/lib\"")
  303. else()
  304. set(OPTIONS_RELEASE "${OPTIONS_RELEASE} --extra-ldflags=-L\"${CURRENT_INSTALLED_DIR}/lib\"")
  305. endif()
  306. message(STATUS "Building Release Options: ${OPTIONS_RELEASE}")
  307. set(ENV{PKG_CONFIG_PATH} "${CURRENT_INSTALLED_DIR}/lib/pkgconfig")
  308. message(STATUS "Building ${PORT} for Release")
  309. file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
  310. # We use response files here as the only known way to handle spaces in paths
  311. set(crsp "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/cflags.rsp")
  312. string(REGEX REPLACE "-arch [A-Za-z0-9_]+" "" VCPKG_COMBINED_C_FLAGS_RELEASE_SANITIZED "${VCPKG_COMBINED_C_FLAGS_RELEASE}")
  313. file(WRITE "${crsp}" "${VCPKG_COMBINED_C_FLAGS_RELEASE_SANITIZED}")
  314. set(ldrsp "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/ldflags.rsp")
  315. string(REGEX REPLACE "-arch [A-Za-z0-9_]+" "" VCPKG_COMBINED_SHARED_LINKER_FLAGS_RELEASE_SANITIZED "${VCPKG_COMBINED_SHARED_LINKER_FLAGS_RELEASE}")
  316. file(WRITE "${ldrsp}" "${VCPKG_COMBINED_SHARED_LINKER_FLAGS_RELEASE_SANITIZED}")
  317. set(ENV{CFLAGS} "@${crsp}")
  318. # All tools except the msvc arm{,64} assembler accept @... as response file syntax.
  319. # For that assembler, there is no known way to pass in flags. We must hope that not passing flags will work acceptably.
  320. if(NOT VCPKG_DETECTED_MSVC OR NOT VCPKG_TARGET_ARCHITECTURE MATCHES "^arm")
  321. set(ENV{ASFLAGS} "@${crsp}")
  322. endif()
  323. set(ENV{LDFLAGS} "@${ldrsp}")
  324. set(ENV{ARFLAGS} "${VCPKG_COMBINED_STATIC_LINKER_FLAGS_RELEASE}")
  325. set(BUILD_DIR "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
  326. set(CONFIGURE_OPTIONS "${OPTIONS} ${OPTIONS_RELEASE}")
  327. set(INST_PREFIX "${CURRENT_PACKAGES_DIR}")
  328. configure_file("${CMAKE_CURRENT_LIST_DIR}/build.sh.in" "${BUILD_DIR}/build.sh" @ONLY)
  329. z_vcpkg_setup_pkgconfig_path(CONFIG RELEASE)
  330. vcpkg_execute_required_process(
  331. COMMAND "${SHELL}" ./build.sh
  332. WORKING_DIRECTORY "${BUILD_DIR}"
  333. LOGNAME "build-${TARGET_TRIPLET}-rel"
  334. SAVE_LOG_FILES ffbuild/config.log
  335. )
  336. z_vcpkg_restore_pkgconfig_path()
  337. endif()
  338. # Debug build
  339. if(NOT VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
  340. if(VCPKG_DETECTED_MSVC)
  341. set(OPTIONS_DEBUG "${OPTIONS_DEBUG} --extra-ldflags=-libpath:\"${CURRENT_INSTALLED_DIR}/debug/lib\"")
  342. else()
  343. set(OPTIONS_DEBUG "${OPTIONS_DEBUG} --extra-ldflags=-L\"${CURRENT_INSTALLED_DIR}/debug/lib\"")
  344. endif()
  345. message(STATUS "Building Debug Options: ${OPTIONS_DEBUG}")
  346. set(ENV{LDFLAGS} "${VCPKG_COMBINED_SHARED_LINKER_FLAGS_DEBUG}")
  347. set(ENV{PKG_CONFIG_PATH} "${CURRENT_INSTALLED_DIR}/debug/lib/pkgconfig")
  348. message(STATUS "Building ${PORT} for Debug")
  349. file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
  350. set(crsp "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/cflags.rsp")
  351. string(REGEX REPLACE "-arch [A-Za-z0-9_]+" "" VCPKG_COMBINED_C_FLAGS_DEBUG_SANITIZED "${VCPKG_COMBINED_C_FLAGS_DEBUG}")
  352. file(WRITE "${crsp}" "${VCPKG_COMBINED_C_FLAGS_DEBUG_SANITIZED}")
  353. set(ldrsp "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/ldflags.rsp")
  354. string(REGEX REPLACE "-arch [A-Za-z0-9_]+" "" VCPKG_COMBINED_SHARED_LINKER_FLAGS_DEBUG_SANITIZED "${VCPKG_COMBINED_SHARED_LINKER_FLAGS_DEBUG}")
  355. file(WRITE "${ldrsp}" "${VCPKG_COMBINED_SHARED_LINKER_FLAGS_DEBUG_SANITIZED}")
  356. set(ENV{CFLAGS} "@${crsp}")
  357. if(NOT VCPKG_DETECTED_MSVC OR NOT VCPKG_TARGET_ARCHITECTURE MATCHES "^arm")
  358. set(ENV{ASFLAGS} "@${crsp}")
  359. endif()
  360. set(ENV{LDFLAGS} "@${ldrsp}")
  361. set(ENV{ARFLAGS} "${VCPKG_COMBINED_STATIC_LINKER_FLAGS_DEBUG}")
  362. set(BUILD_DIR "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
  363. set(CONFIGURE_OPTIONS "${OPTIONS} ${OPTIONS_DEBUG}")
  364. set(INST_PREFIX "${CURRENT_PACKAGES_DIR}/debug")
  365. configure_file("${CMAKE_CURRENT_LIST_DIR}/build.sh.in" "${BUILD_DIR}/build.sh" @ONLY)
  366. z_vcpkg_setup_pkgconfig_path(CONFIG DEBUG)
  367. vcpkg_execute_required_process(
  368. COMMAND "${SHELL}" ./build.sh
  369. WORKING_DIRECTORY "${BUILD_DIR}"
  370. LOGNAME "build-${TARGET_TRIPLET}-dbg"
  371. SAVE_LOG_FILES ffbuild/config.log
  372. )
  373. z_vcpkg_restore_pkgconfig_path()
  374. endif()
  375. if(VCPKG_TARGET_IS_WINDOWS)
  376. file(GLOB DEF_FILES "${CURRENT_PACKAGES_DIR}/lib/*.def" "${CURRENT_PACKAGES_DIR}/debug/lib/*.def")
  377. if(NOT VCPKG_TARGET_IS_MINGW)
  378. if(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm")
  379. set(LIB_MACHINE_ARG /machine:ARM)
  380. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
  381. set(LIB_MACHINE_ARG /machine:ARM64)
  382. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
  383. set(LIB_MACHINE_ARG /machine:x86)
  384. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
  385. set(LIB_MACHINE_ARG /machine:x64)
  386. else()
  387. message(FATAL_ERROR "Unsupported target architecture")
  388. endif()
  389. foreach(DEF_FILE ${DEF_FILES})
  390. get_filename_component(DEF_FILE_DIR "${DEF_FILE}" DIRECTORY)
  391. get_filename_component(DEF_FILE_NAME "${DEF_FILE}" NAME)
  392. string(REGEX REPLACE "-[0-9]*\\.def" "${VCPKG_TARGET_STATIC_LIBRARY_SUFFIX}" OUT_FILE_NAME "${DEF_FILE_NAME}")
  393. file(TO_NATIVE_PATH "${DEF_FILE}" DEF_FILE_NATIVE)
  394. file(TO_NATIVE_PATH "${DEF_FILE_DIR}/${OUT_FILE_NAME}" OUT_FILE_NATIVE)
  395. message(STATUS "Generating ${OUT_FILE_NATIVE}")
  396. vcpkg_execute_required_process(
  397. COMMAND lib.exe "/def:${DEF_FILE_NATIVE}" "/out:${OUT_FILE_NATIVE}" ${LIB_MACHINE_ARG}
  398. WORKING_DIRECTORY "${CURRENT_PACKAGES_DIR}"
  399. LOGNAME "libconvert-${TARGET_TRIPLET}"
  400. )
  401. endforeach()
  402. endif()
  403. file(GLOB EXP_FILES "${CURRENT_PACKAGES_DIR}/lib/*.exp" "${CURRENT_PACKAGES_DIR}/debug/lib/*.exp")
  404. file(GLOB LIB_FILES "${CURRENT_PACKAGES_DIR}/bin/*${VCPKG_TARGET_STATIC_LIBRARY_SUFFIX}" "${CURRENT_PACKAGES_DIR}/debug/bin/*${VCPKG_TARGET_STATIC_LIBRARY_SUFFIX}")
  405. if(VCPKG_TARGET_IS_MINGW)
  406. file(GLOB LIB_FILES_2 "${CURRENT_PACKAGES_DIR}/bin/*.lib" "${CURRENT_PACKAGES_DIR}/debug/bin/*.lib")
  407. endif()
  408. set(files_to_remove ${EXP_FILES} ${LIB_FILES} ${LIB_FILES_2} ${DEF_FILES})
  409. if(files_to_remove)
  410. file(REMOVE ${files_to_remove})
  411. endif()
  412. endif()
  413. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" "${CURRENT_PACKAGES_DIR}/debug/share")
  414. if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
  415. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin")
  416. endif()
  417. vcpkg_copy_pdbs()
  418. if(VCPKG_TARGET_IS_WINDOWS)
  419. set(_dirs "/")
  420. if(NOT VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
  421. list(APPEND _dirs "/debug/")
  422. endif()
  423. foreach(_debug IN LISTS _dirs)
  424. foreach(PKGCONFIG_MODULE IN LISTS FFMPEG_PKGCONFIG_MODULES)
  425. set(PKGCONFIG_FILE "${CURRENT_PACKAGES_DIR}${_debug}lib/pkgconfig/${PKGCONFIG_MODULE}.pc")
  426. # remove redundant cygwin style -libpath entries
  427. execute_process(
  428. COMMAND "${MSYS_ROOT}/usr/bin/cygpath.exe" -u "${CURRENT_INSTALLED_DIR}"
  429. OUTPUT_VARIABLE CYG_INSTALLED_DIR
  430. OUTPUT_STRIP_TRAILING_WHITESPACE
  431. )
  432. vcpkg_replace_string("${PKGCONFIG_FILE}" "-libpath:${CYG_INSTALLED_DIR}${_debug}lib/pkgconfig/../../lib " "")
  433. # transform libdir, includedir, and prefix paths from cygwin style to windows style
  434. file(READ "${PKGCONFIG_FILE}" PKGCONFIG_CONTENT)
  435. foreach(PATH_NAME prefix libdir includedir)
  436. string(REGEX MATCH "${PATH_NAME}=[^\n]*" PATH_VALUE "${PKGCONFIG_CONTENT}")
  437. string(REPLACE "${PATH_NAME}=" "" PATH_VALUE "${PATH_VALUE}")
  438. if(NOT PATH_VALUE)
  439. message(FATAL_ERROR "failed to find pkgconfig variable ${PATH_NAME}")
  440. endif()
  441. execute_process(
  442. COMMAND "${MSYS_ROOT}/usr/bin/cygpath.exe" -w "${PATH_VALUE}"
  443. OUTPUT_VARIABLE FIXED_PATH
  444. OUTPUT_STRIP_TRAILING_WHITESPACE
  445. )
  446. file(TO_CMAKE_PATH "${FIXED_PATH}" FIXED_PATH)
  447. vcpkg_replace_string("${PKGCONFIG_FILE}" "${PATH_NAME}=${PATH_VALUE}" "${PATH_NAME}=${FIXED_PATH}")
  448. endforeach()
  449. # list libraries with -l flag (so pkgconf knows they are libraries and not just linker flags)
  450. foreach(LIBS_ENTRY Libs Libs.private)
  451. string(REGEX MATCH "${LIBS_ENTRY}: [^\n]*" LIBS_VALUE "${PKGCONFIG_CONTENT}")
  452. if(NOT LIBS_VALUE)
  453. message(FATAL_ERROR "failed to find pkgconfig entry ${LIBS_ENTRY}")
  454. endif()
  455. string(REPLACE "${LIBS_ENTRY}: " "" LIBS_VALUE "${LIBS_VALUE}")
  456. if(LIBS_VALUE)
  457. set(LIBS_VALUE_OLD "${LIBS_VALUE}")
  458. string(REGEX REPLACE "([^ ]+)[.]lib" "-l\\1" LIBS_VALUE "${LIBS_VALUE}")
  459. set(LIBS_VALUE_NEW "${LIBS_VALUE}")
  460. vcpkg_replace_string("${PKGCONFIG_FILE}" "${LIBS_ENTRY}: ${LIBS_VALUE_OLD}" "${LIBS_ENTRY}: ${LIBS_VALUE_NEW}")
  461. endif()
  462. endforeach()
  463. endforeach()
  464. endforeach()
  465. endif()
  466. vcpkg_fixup_pkgconfig()
  467. # Handle dependencies
  468. x_vcpkg_pkgconfig_get_modules(PREFIX FFMPEG_PKGCONFIG MODULES ${FFMPEG_PKGCONFIG_MODULES} LIBS)
  469. function(append_dependencies_from_libs out)
  470. cmake_parse_arguments(PARSE_ARGV 1 "arg" "" "LIBS" "")
  471. string(REGEX REPLACE "[ ]+" ";" contents "${arg_LIBS}")
  472. list(FILTER contents EXCLUDE REGEX "^-F.+")
  473. list(FILTER contents EXCLUDE REGEX "^-framework$")
  474. list(FILTER contents EXCLUDE REGEX "^-L.+")
  475. list(FILTER contents EXCLUDE REGEX "^-libpath:.+")
  476. list(TRANSFORM contents REPLACE "^-Wl,-framework," "-l")
  477. list(FILTER contents EXCLUDE REGEX "^-Wl,.+")
  478. list(TRANSFORM contents REPLACE "^-l" "")
  479. list(FILTER contents EXCLUDE REGEX "^avutil$")
  480. list(FILTER contents EXCLUDE REGEX "^avcodec$")
  481. list(FILTER contents EXCLUDE REGEX "^avdevice$")
  482. list(FILTER contents EXCLUDE REGEX "^avfilter$")
  483. list(FILTER contents EXCLUDE REGEX "^avformat$")
  484. list(FILTER contents EXCLUDE REGEX "^postproc$")
  485. list(FILTER contents EXCLUDE REGEX "^swresample$")
  486. list(FILTER contents EXCLUDE REGEX "^swscale$")
  487. if(VCPKG_TARGET_IS_WINDOWS)
  488. list(TRANSFORM contents TOLOWER)
  489. endif()
  490. if(contents)
  491. list(APPEND "${out}" "${contents}")
  492. set("${out}" "${${out}}" PARENT_SCOPE)
  493. endif()
  494. endfunction()
  495. append_dependencies_from_libs(FFMPEG_DEPENDENCIES_RELEASE LIBS "${FFMPEG_PKGCONFIG_LIBS_RELEASE}")
  496. append_dependencies_from_libs(FFMPEG_DEPENDENCIES_DEBUG LIBS "${FFMPEG_PKGCONFIG_LIBS_DEBUG}")
  497. # must remove duplicates from the front to respect link order so reverse first
  498. list(REVERSE FFMPEG_DEPENDENCIES_RELEASE)
  499. list(REVERSE FFMPEG_DEPENDENCIES_DEBUG)
  500. list(REMOVE_DUPLICATES FFMPEG_DEPENDENCIES_RELEASE)
  501. list(REMOVE_DUPLICATES FFMPEG_DEPENDENCIES_DEBUG)
  502. list(REVERSE FFMPEG_DEPENDENCIES_RELEASE)
  503. list(REVERSE FFMPEG_DEPENDENCIES_DEBUG)
  504. message(STATUS "Dependencies (release): ${FFMPEG_DEPENDENCIES_RELEASE}")
  505. message(STATUS "Dependencies (debug): ${FFMPEG_DEPENDENCIES_DEBUG}")
  506. # Handle version strings
  507. function(extract_regex_from_file out)
  508. cmake_parse_arguments(PARSE_ARGV 1 "arg" "MAJOR" "FILE_WITHOUT_EXTENSION;REGEX" "")
  509. file(READ "${arg_FILE_WITHOUT_EXTENSION}.h" contents)
  510. if(contents MATCHES "${arg_REGEX}")
  511. if(NOT CMAKE_MATCH_COUNT EQUAL 1)
  512. message(FATAL_ERROR "Could not identify match group in regular expression \"${arg_REGEX}\"")
  513. endif()
  514. else()
  515. if(arg_MAJOR)
  516. file(READ "${arg_FILE_WITHOUT_EXTENSION}_major.h" contents)
  517. if(contents MATCHES "${arg_REGEX}")
  518. if(NOT CMAKE_MATCH_COUNT EQUAL 1)
  519. message(FATAL_ERROR "Could not identify match group in regular expression \"${arg_REGEX}\"")
  520. endif()
  521. else()
  522. message(WARNING "Could not find line matching \"${arg_REGEX}\" in file \"${arg_FILE_WITHOUT_EXTENSION}_major.h\"")
  523. endif()
  524. else()
  525. message(WARNING "Could not find line matching \"${arg_REGEX}\" in file \"${arg_FILE_WITHOUT_EXTENSION}.h\"")
  526. endif()
  527. endif()
  528. set("${out}" "${CMAKE_MATCH_1}" PARENT_SCOPE)
  529. endfunction()
  530. function(extract_version_from_component out)
  531. cmake_parse_arguments(PARSE_ARGV 1 "arg" "" "COMPONENT" "")
  532. string(TOLOWER "${arg_COMPONENT}" component_lower)
  533. string(TOUPPER "${arg_COMPONENT}" component_upper)
  534. extract_regex_from_file(major_version
  535. FILE_WITHOUT_EXTENSION "${SOURCE_PATH}/${component_lower}/version"
  536. MAJOR
  537. REGEX "#define ${component_upper}_VERSION_MAJOR[ ]+([0-9]+)"
  538. )
  539. extract_regex_from_file(minor_version
  540. FILE_WITHOUT_EXTENSION "${SOURCE_PATH}/${component_lower}/version"
  541. REGEX "#define ${component_upper}_VERSION_MINOR[ ]+([0-9]+)"
  542. )
  543. extract_regex_from_file(micro_version
  544. FILE_WITHOUT_EXTENSION "${SOURCE_PATH}/${component_lower}/version"
  545. REGEX "#define ${component_upper}_VERSION_MICRO[ ]+([0-9]+)"
  546. )
  547. set("${out}" "${major_version}.${minor_version}.${micro_version}" PARENT_SCOPE)
  548. endfunction()
  549. extract_regex_from_file(FFMPEG_VERSION
  550. FILE_WITHOUT_EXTENSION "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/libavutil/ffversion"
  551. REGEX "#define FFMPEG_VERSION[ ]+\"(.+)\""
  552. )
  553. extract_version_from_component(LIBAVUTIL_VERSION
  554. COMPONENT libavutil)
  555. extract_version_from_component(LIBAVCODEC_VERSION
  556. COMPONENT libavcodec)
  557. extract_version_from_component(LIBAVDEVICE_VERSION
  558. COMPONENT libavdevice)
  559. extract_version_from_component(LIBAVFILTER_VERSION
  560. COMPONENT libavfilter)
  561. extract_version_from_component(LIBAVFORMAT_VERSION
  562. COMPONENT libavformat)
  563. extract_version_from_component(LIBSWRESAMPLE_VERSION
  564. COMPONENT libswresample)
  565. extract_version_from_component(LIBSWSCALE_VERSION
  566. COMPONENT libswscale)
  567. # Handle copyright
  568. file(STRINGS "${CURRENT_BUILDTREES_DIR}/build-${TARGET_TRIPLET}-rel-out.log" LICENSE_STRING REGEX "License: .*" LIMIT_COUNT 1)
  569. if(LICENSE_STRING STREQUAL "License: LGPL version 2.1 or later")
  570. set(LICENSE_FILE "COPYING.LGPLv2.1")
  571. elseif(LICENSE_STRING STREQUAL "License: LGPL version 3 or later")
  572. set(LICENSE_FILE "COPYING.LGPLv3")
  573. elseif(LICENSE_STRING STREQUAL "License: GPL version 2 or later")
  574. set(LICENSE_FILE "COPYING.GPLv2")
  575. elseif(LICENSE_STRING STREQUAL "License: GPL version 3 or later")
  576. set(LICENSE_FILE "COPYING.GPLv3")
  577. elseif(LICENSE_STRING STREQUAL "License: nonfree and unredistributable")
  578. set(LICENSE_FILE "COPYING.NONFREE")
  579. file(WRITE "${SOURCE_PATH}/${LICENSE_FILE}" "${LICENSE_STRING}")
  580. else()
  581. message(FATAL_ERROR "Failed to identify license (${LICENSE_STRING})")
  582. endif()
  583. configure_file("${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake" "${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-cmake-wrapper.cmake" @ONLY)
  584. vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/${LICENSE_FILE}")