portfile.cmake 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
  2. vcpkg_from_github(
  3. OUT_SOURCE_PATH SOURCE_PATH
  4. REPO webmproject/libvpx
  5. REF "v${VERSION}"
  6. SHA512 3e3bfad3d035c0bc3db7cb5a194d56d3c90f5963fb1ad527ae5252054e7c48ce2973de1346c97d94b59f7a95d4801bec44214cce10faf123f92b36fca79a8d1e
  7. HEAD_REF master
  8. PATCHES
  9. 0002-Fix-nasm-debug-format-flag.patch
  10. 0003-add-uwp-v142-and-v143-support.patch
  11. 0004-remove-library-suffixes.patch
  12. )
  13. if(CMAKE_HOST_WIN32)
  14. vcpkg_acquire_msys(MSYS_ROOT PACKAGES make perl)
  15. set(ENV{PATH} "${MSYS_ROOT}/usr/bin;$ENV{PATH}")
  16. else()
  17. vcpkg_find_acquire_program(PERL)
  18. get_filename_component(PERL_EXE_PATH ${PERL} DIRECTORY)
  19. set(ENV{PATH} "${MSYS_ROOT}/usr/bin:$ENV{PATH}:${PERL_EXE_PATH}")
  20. endif()
  21. find_program(BASH NAME bash HINTS ${MSYS_ROOT}/usr/bin REQUIRED NO_CACHE)
  22. vcpkg_find_acquire_program(NASM)
  23. get_filename_component(NASM_EXE_PATH ${NASM} DIRECTORY)
  24. vcpkg_add_to_path(${NASM_EXE_PATH})
  25. if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
  26. file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-tmp")
  27. if(VCPKG_CRT_LINKAGE STREQUAL static)
  28. set(LIBVPX_CRT_LINKAGE --enable-static-msvcrt)
  29. set(LIBVPX_CRT_SUFFIX mt)
  30. else()
  31. set(LIBVPX_CRT_SUFFIX md)
  32. endif()
  33. if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL WindowsStore AND (VCPKG_PLATFORM_TOOLSET STREQUAL v142 OR VCPKG_PLATFORM_TOOLSET STREQUAL v143))
  34. set(LIBVPX_TARGET_OS "uwp")
  35. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL x86 OR VCPKG_TARGET_ARCHITECTURE STREQUAL arm)
  36. set(LIBVPX_TARGET_OS "win32")
  37. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL x64 OR VCPKG_TARGET_ARCHITECTURE STREQUAL arm64)
  38. set(LIBVPX_TARGET_OS "win64")
  39. endif()
  40. if(VCPKG_TARGET_ARCHITECTURE STREQUAL x86)
  41. set(LIBVPX_TARGET_ARCH "x86-${LIBVPX_TARGET_OS}")
  42. set(LIBVPX_ARCH_DIR "Win32")
  43. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL x64)
  44. set(LIBVPX_TARGET_ARCH "x86_64-${LIBVPX_TARGET_OS}")
  45. set(LIBVPX_ARCH_DIR "x64")
  46. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL arm64)
  47. set(LIBVPX_TARGET_ARCH "arm64-${LIBVPX_TARGET_OS}")
  48. set(LIBVPX_ARCH_DIR "ARM64")
  49. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL arm)
  50. set(LIBVPX_TARGET_ARCH "armv7-${LIBVPX_TARGET_OS}")
  51. set(LIBVPX_ARCH_DIR "ARM")
  52. endif()
  53. if(VCPKG_PLATFORM_TOOLSET STREQUAL v143)
  54. set(LIBVPX_TARGET_VS "vs17")
  55. elseif(VCPKG_PLATFORM_TOOLSET STREQUAL v142)
  56. set(LIBVPX_TARGET_VS "vs16")
  57. else()
  58. set(LIBVPX_TARGET_VS "vs15")
  59. endif()
  60. set(OPTIONS "--disable-examples --disable-tools --disable-docs --enable-pic")
  61. if("realtime" IN_LIST FEATURES)
  62. set(OPTIONS "${OPTIONS} --enable-realtime-only")
  63. endif()
  64. if("highbitdepth" IN_LIST FEATURES)
  65. set(OPTIONS "${OPTIONS} --enable-vp9-highbitdepth")
  66. endif()
  67. message(STATUS "Generating makefile")
  68. file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-tmp")
  69. vcpkg_execute_required_process(
  70. COMMAND
  71. ${BASH} --noprofile --norc
  72. "${SOURCE_PATH}/configure"
  73. --target=${LIBVPX_TARGET_ARCH}-${LIBVPX_TARGET_VS}
  74. ${LIBVPX_CRT_LINKAGE}
  75. ${OPTIONS}
  76. --as=nasm
  77. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-tmp"
  78. LOGNAME configure-${TARGET_TRIPLET})
  79. message(STATUS "Generating MSBuild projects")
  80. vcpkg_execute_required_process(
  81. COMMAND
  82. ${BASH} --noprofile --norc -c "make dist"
  83. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-tmp"
  84. LOGNAME generate-${TARGET_TRIPLET})
  85. vcpkg_msbuild_install(
  86. SOURCE_PATH "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-tmp"
  87. PROJECT_SUBPATH vpx.vcxproj
  88. )
  89. if (VCPKG_TARGET_ARCHITECTURE STREQUAL arm64)
  90. set(LIBVPX_INCLUDE_DIR "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/vpx-vp8-vp9-nopost-nodocs-${LIBVPX_TARGET_ARCH}${LIBVPX_CRT_SUFFIX}-${LIBVPX_TARGET_VS}-v${VERSION}/include/vpx")
  91. elseif (VCPKG_TARGET_ARCHITECTURE STREQUAL arm)
  92. set(LIBVPX_INCLUDE_DIR "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/vpx-vp8-vp9-nopost-nomt-nodocs-${LIBVPX_TARGET_ARCH}${LIBVPX_CRT_SUFFIX}-${LIBVPX_TARGET_VS}-v${VERSION}/include/vpx")
  93. else()
  94. set(LIBVPX_INCLUDE_DIR "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/vpx-vp8-vp9-nodocs-${LIBVPX_TARGET_ARCH}${LIBVPX_CRT_SUFFIX}-${LIBVPX_TARGET_VS}-v${VERSION}/include/vpx")
  95. endif()
  96. file(
  97. INSTALL
  98. "${LIBVPX_INCLUDE_DIR}"
  99. DESTINATION
  100. "${CURRENT_PACKAGES_DIR}/include"
  101. RENAME
  102. "vpx")
  103. if (NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
  104. set(LIBVPX_PREFIX "${CURRENT_INSTALLED_DIR}")
  105. configure_file("${CMAKE_CURRENT_LIST_DIR}/vpx.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/vpx.pc" @ONLY)
  106. endif()
  107. if (NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
  108. set(LIBVPX_PREFIX "${CURRENT_INSTALLED_DIR}/debug")
  109. configure_file("${CMAKE_CURRENT_LIST_DIR}/vpx.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/vpx.pc" @ONLY)
  110. endif()
  111. else()
  112. set(OPTIONS "--disable-examples --disable-tools --disable-docs --disable-unit-tests --enable-pic")
  113. set(OPTIONS_DEBUG "--enable-debug-libs --enable-debug --prefix=${CURRENT_PACKAGES_DIR}/debug")
  114. set(OPTIONS_RELEASE "--prefix=${CURRENT_PACKAGES_DIR}")
  115. set(AS_NASM "--as=nasm")
  116. if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
  117. set(OPTIONS "${OPTIONS} --disable-static --enable-shared")
  118. else()
  119. set(OPTIONS "${OPTIONS} --enable-static --disable-shared")
  120. endif()
  121. if("realtime" IN_LIST FEATURES)
  122. set(OPTIONS "${OPTIONS} --enable-realtime-only")
  123. endif()
  124. if("highbitdepth" IN_LIST FEATURES)
  125. set(OPTIONS "${OPTIONS} --enable-vp9-highbitdepth")
  126. endif()
  127. if(VCPKG_TARGET_ARCHITECTURE STREQUAL x86)
  128. set(LIBVPX_TARGET_ARCH "x86")
  129. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL x64)
  130. set(LIBVPX_TARGET_ARCH "x86_64")
  131. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL arm)
  132. set(LIBVPX_TARGET_ARCH "armv7")
  133. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL arm64)
  134. set(LIBVPX_TARGET_ARCH "arm64")
  135. else()
  136. message(FATAL_ERROR "libvpx does not support architecture ${VCPKG_TARGET_ARCHITECTURE}")
  137. endif()
  138. vcpkg_cmake_get_vars(cmake_vars_file)
  139. include("${cmake_vars_file}")
  140. # Set environment variables for configure
  141. if(VCPKG_DETECTED_CMAKE_C_COMPILER MATCHES "([^\/]*-)gcc$")
  142. message(STATUS "Cross-building for ${TARGET_TRIPLET} with ${CMAKE_MATCH_1}")
  143. set(ENV{CROSS} ${CMAKE_MATCH_1})
  144. unset(AS_NASM)
  145. else()
  146. set(ENV{CC} ${VCPKG_DETECTED_CMAKE_C_COMPILER})
  147. set(ENV{CXX} ${VCPKG_DETECTED_CMAKE_CXX_COMPILER})
  148. set(ENV{AR} ${VCPKG_DETECTED_CMAKE_AR})
  149. set(ENV{LD} ${VCPKG_DETECTED_CMAKE_LINKER})
  150. set(ENV{RANLIB} ${VCPKG_DETECTED_CMAKE_RANLIB})
  151. set(ENV{STRIP} ${VCPKG_DETECTED_CMAKE_STRIP})
  152. endif()
  153. if(VCPKG_TARGET_IS_MINGW)
  154. if(LIBVPX_TARGET_ARCH STREQUAL "x86")
  155. set(LIBVPX_TARGET "x86-win32-gcc")
  156. else()
  157. set(LIBVPX_TARGET "x86_64-win64-gcc")
  158. endif()
  159. elseif(VCPKG_TARGET_IS_LINUX)
  160. set(LIBVPX_TARGET "${LIBVPX_TARGET_ARCH}-linux-gcc")
  161. elseif(VCPKG_TARGET_IS_ANDROID)
  162. set(LIBVPX_TARGET "generic-gnu")
  163. # Settings
  164. if(VCPKG_TARGET_ARCHITECTURE STREQUAL x86)
  165. set(OPTIONS "${OPTIONS} --disable-sse4_1 --disable-avx --disable-avx2 --disable-avx512")
  166. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL x64)
  167. set(OPTIONS "${OPTIONS} --disable-avx --disable-avx2 --disable-avx512")
  168. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL arm)
  169. set(OPTIONS "${OPTIONS} --enable-thumb --disable-neon")
  170. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL arm64)
  171. set(OPTIONS "${OPTIONS} --enable-thumb")
  172. endif()
  173. # Set environment variables for configure
  174. set(ENV{AS} ${VCPKG_DETECTED_CMAKE_C_COMPILER})
  175. set(ENV{LDFLAGS} "${LDFLAGS} --target=${VCPKG_DETECTED_CMAKE_C_COMPILER_TARGET}")
  176. # Set clang target
  177. set(OPTIONS "${OPTIONS} --extra-cflags=--target=${VCPKG_DETECTED_CMAKE_C_COMPILER_TARGET} --extra-cxxflags=--target=${VCPKG_DETECTED_CMAKE_CXX_COMPILER_TARGET}")
  178. # Unset nasm and let AS do its job
  179. unset(AS_NASM)
  180. elseif(VCPKG_TARGET_IS_OSX)
  181. if(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
  182. set(LIBVPX_TARGET "arm64-darwin20-gcc")
  183. if(DEFINED VCPKG_OSX_DEPLOYMENT_TARGET)
  184. set(MAC_OSX_MIN_VERSION_CFLAGS --extra-cflags=-mmacosx-version-min=${VCPKG_OSX_DEPLOYMENT_TARGET} --extra-cxxflags=-mmacosx-version-min=${VCPKG_OSX_DEPLOYMENT_TARGET})
  185. endif()
  186. else()
  187. set(LIBVPX_TARGET "${LIBVPX_TARGET_ARCH}-darwin17-gcc") # enable latest CPU instructions for best performance and less CPU usage on MacOS
  188. endif()
  189. elseif(VCPKG_TARGET_IS_IOS)
  190. if(VCPKG_TARGET_ARCHITECTURE STREQUAL arm)
  191. set(LIBVPX_TARGET "armv7-darwin-gcc")
  192. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL arm64)
  193. set(LIBVPX_TARGET "arm64-darwin-gcc")
  194. else()
  195. message(FATAL_ERROR "libvpx does not support architecture ${VCPKG_TARGET_ARCHITECTURE} on iOS")
  196. endif()
  197. else()
  198. set(LIBVPX_TARGET "generic-gnu") # use default target
  199. endif()
  200. message(STATUS "Build info. Target: ${LIBVPX_TARGET}; Options: ${OPTIONS}")
  201. if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
  202. message(STATUS "Configuring libvpx for Release")
  203. file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
  204. vcpkg_execute_required_process(
  205. COMMAND
  206. ${BASH} --noprofile --norc
  207. "${SOURCE_PATH}/configure"
  208. --target=${LIBVPX_TARGET}
  209. ${OPTIONS}
  210. ${OPTIONS_RELEASE}
  211. ${MAC_OSX_MIN_VERSION_CFLAGS}
  212. ${AS_NASM}
  213. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel"
  214. LOGNAME configure-${TARGET_TRIPLET}-rel)
  215. message(STATUS "Building libvpx for Release")
  216. vcpkg_execute_required_process(
  217. COMMAND
  218. ${BASH} --noprofile --norc -c "make -j${VCPKG_CONCURRENCY}"
  219. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel"
  220. LOGNAME build-${TARGET_TRIPLET}-rel
  221. )
  222. message(STATUS "Installing libvpx for Release")
  223. vcpkg_execute_required_process(
  224. COMMAND
  225. ${BASH} --noprofile --norc -c "make install"
  226. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel"
  227. LOGNAME install-${TARGET_TRIPLET}-rel
  228. )
  229. endif()
  230. # --- --- ---
  231. if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
  232. message(STATUS "Configuring libvpx for Debug")
  233. file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
  234. vcpkg_execute_required_process(
  235. COMMAND
  236. ${BASH} --noprofile --norc
  237. "${SOURCE_PATH}/configure"
  238. --target=${LIBVPX_TARGET}
  239. ${OPTIONS}
  240. ${OPTIONS_DEBUG}
  241. ${MAC_OSX_MIN_VERSION_CFLAGS}
  242. ${AS_NASM}
  243. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg"
  244. LOGNAME configure-${TARGET_TRIPLET}-dbg)
  245. message(STATUS "Building libvpx for Debug")
  246. vcpkg_execute_required_process(
  247. COMMAND
  248. ${BASH} --noprofile --norc -c "make -j${VCPKG_CONCURRENCY}"
  249. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg"
  250. LOGNAME build-${TARGET_TRIPLET}-dbg
  251. )
  252. message(STATUS "Installing libvpx for Debug")
  253. vcpkg_execute_required_process(
  254. COMMAND
  255. ${BASH} --noprofile --norc -c "make install"
  256. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg"
  257. LOGNAME install-${TARGET_TRIPLET}-dbg
  258. )
  259. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
  260. file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/lib/libvpx_g.a")
  261. endif()
  262. endif()
  263. vcpkg_fixup_pkgconfig()
  264. if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
  265. set(LIBVPX_CONFIG_DEBUG ON)
  266. else()
  267. set(LIBVPX_CONFIG_DEBUG OFF)
  268. endif()
  269. configure_file("${CMAKE_CURRENT_LIST_DIR}/unofficial-libvpx-config.cmake.in" "${CURRENT_PACKAGES_DIR}/share/unofficial-libvpx/unofficial-libvpx-config.cmake" @ONLY)
  270. vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")