1
0

portfile.cmake 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
  2. set(LIBVPX_VERSION 1.12.0)
  3. vcpkg_from_github(
  4. OUT_SOURCE_PATH SOURCE_PATH
  5. REPO webmproject/libvpx
  6. REF v${LIBVPX_VERSION}
  7. SHA512 dc059bc3102b75524ae29989372334b3e0f2acf1520e5a4daa4073831bb55949d82897c498fb9d2d38b59f1a66bb0ad24407d0d086b1e3a8394a4933f04f2ed0
  8. HEAD_REF master
  9. PATCHES
  10. 0002-Fix-nasm-debug-format-flag.patch
  11. 0003-add-uwp-v142-and-v143-support.patch
  12. 0004-remove-library-suffixes.patch
  13. )
  14. vcpkg_find_acquire_program(PERL)
  15. get_filename_component(PERL_EXE_PATH ${PERL} DIRECTORY)
  16. if(CMAKE_HOST_WIN32)
  17. vcpkg_acquire_msys(MSYS_ROOT PACKAGES make)
  18. set(BASH ${MSYS_ROOT}/usr/bin/bash.exe)
  19. set(ENV{PATH} "${MSYS_ROOT}/usr/bin;$ENV{PATH};${PERL_EXE_PATH}")
  20. else()
  21. set(BASH /bin/bash)
  22. set(ENV{PATH} "${MSYS_ROOT}/usr/bin:$ENV{PATH}:${PERL_EXE_PATH}")
  23. endif()
  24. vcpkg_find_acquire_program(NASM)
  25. get_filename_component(NASM_EXE_PATH ${NASM} DIRECTORY)
  26. vcpkg_add_to_path(${NASM_EXE_PATH})
  27. if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
  28. file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}")
  29. if(VCPKG_CRT_LINKAGE STREQUAL static)
  30. set(LIBVPX_CRT_LINKAGE --enable-static-msvcrt)
  31. set(LIBVPX_CRT_SUFFIX mt)
  32. else()
  33. set(LIBVPX_CRT_SUFFIX md)
  34. endif()
  35. if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL WindowsStore AND (VCPKG_PLATFORM_TOOLSET STREQUAL v142 OR VCPKG_PLATFORM_TOOLSET STREQUAL v143))
  36. set(LIBVPX_TARGET_OS "uwp")
  37. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL x86 OR VCPKG_TARGET_ARCHITECTURE STREQUAL arm)
  38. set(LIBVPX_TARGET_OS "win32")
  39. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL x64 OR VCPKG_TARGET_ARCHITECTURE STREQUAL arm64)
  40. set(LIBVPX_TARGET_OS "win64")
  41. endif()
  42. if(VCPKG_TARGET_ARCHITECTURE STREQUAL x86)
  43. set(LIBVPX_TARGET_ARCH "x86-${LIBVPX_TARGET_OS}")
  44. set(LIBVPX_ARCH_DIR "Win32")
  45. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL x64)
  46. set(LIBVPX_TARGET_ARCH "x86_64-${LIBVPX_TARGET_OS}")
  47. set(LIBVPX_ARCH_DIR "x64")
  48. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL arm64)
  49. set(LIBVPX_TARGET_ARCH "arm64-${LIBVPX_TARGET_OS}")
  50. set(LIBVPX_ARCH_DIR "ARM64")
  51. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL arm)
  52. set(LIBVPX_TARGET_ARCH "armv7-${LIBVPX_TARGET_OS}")
  53. set(LIBVPX_ARCH_DIR "ARM")
  54. endif()
  55. if(VCPKG_PLATFORM_TOOLSET STREQUAL v143)
  56. set(LIBVPX_TARGET_VS "vs17")
  57. elseif(VCPKG_PLATFORM_TOOLSET STREQUAL v142)
  58. set(LIBVPX_TARGET_VS "vs16")
  59. else()
  60. set(LIBVPX_TARGET_VS "vs15")
  61. endif()
  62. set(OPTIONS "--disable-examples --disable-tools --disable-docs --enable-pic")
  63. if("realtime" IN_LIST FEATURES)
  64. set(OPTIONS "${OPTIONS} --enable-realtime-only")
  65. endif()
  66. if("highbitdepth" IN_LIST FEATURES)
  67. set(OPTIONS "${OPTIONS} --enable-vp9-highbitdepth")
  68. endif()
  69. message(STATUS "Generating makefile")
  70. file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}")
  71. vcpkg_execute_required_process(
  72. COMMAND
  73. ${BASH} --noprofile --norc
  74. "${SOURCE_PATH}/configure"
  75. --target=${LIBVPX_TARGET_ARCH}-${LIBVPX_TARGET_VS}
  76. ${LIBVPX_CRT_LINKAGE}
  77. ${OPTIONS}
  78. --as=nasm
  79. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}"
  80. LOGNAME configure-${TARGET_TRIPLET})
  81. message(STATUS "Generating MSBuild projects")
  82. vcpkg_execute_required_process(
  83. COMMAND
  84. ${BASH} --noprofile --norc -c "make dist"
  85. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}"
  86. LOGNAME generate-${TARGET_TRIPLET})
  87. vcpkg_build_msbuild(
  88. PROJECT_PATH "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/vpx.vcxproj"
  89. OPTIONS /p:UseEnv=True
  90. )
  91. # note: pdb file names are hardcoded in the lib file, cannot rename
  92. set(LIBVPX_OUTPUT_PREFIX "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/${LIBVPX_ARCH_DIR}")
  93. if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
  94. file(INSTALL "${LIBVPX_OUTPUT_PREFIX}/Release/vpx.lib" DESTINATION "${CURRENT_PACKAGES_DIR}/lib")
  95. if (EXISTS "${LIBVPX_OUTPUT_PREFIX}/Release/vpx.pdb")
  96. file(INSTALL "${LIBVPX_OUTPUT_PREFIX}/Release/vpx.pdb" DESTINATION "${CURRENT_PACKAGES_DIR}/lib")
  97. else()
  98. file(INSTALL "${LIBVPX_OUTPUT_PREFIX}/Release/vpx/vpx.pdb" DESTINATION "${CURRENT_PACKAGES_DIR}/lib")
  99. endif()
  100. endif()
  101. if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
  102. file(INSTALL "${LIBVPX_OUTPUT_PREFIX}/Debug/vpx.lib" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib")
  103. if (EXISTS "${LIBVPX_OUTPUT_PREFIX}/Debug/vpx.pdb")
  104. file(INSTALL "${LIBVPX_OUTPUT_PREFIX}/Debug/vpx.pdb" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib")
  105. else()
  106. file(INSTALL "${LIBVPX_OUTPUT_PREFIX}/Debug/vpx/vpx.pdb" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib")
  107. endif()
  108. endif()
  109. if (VCPKG_TARGET_ARCHITECTURE STREQUAL arm64)
  110. set(LIBVPX_INCLUDE_DIR "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/vpx-vp8-vp9-nopost-nodocs-${LIBVPX_TARGET_ARCH}${LIBVPX_CRT_SUFFIX}-${LIBVPX_TARGET_VS}-v${LIBVPX_VERSION}/include/vpx")
  111. elseif (VCPKG_TARGET_ARCHITECTURE STREQUAL arm)
  112. set(LIBVPX_INCLUDE_DIR "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/vpx-vp8-vp9-nopost-nomt-nodocs-${LIBVPX_TARGET_ARCH}${LIBVPX_CRT_SUFFIX}-${LIBVPX_TARGET_VS}-v${LIBVPX_VERSION}/include/vpx")
  113. else()
  114. set(LIBVPX_INCLUDE_DIR "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/vpx-vp8-vp9-nodocs-${LIBVPX_TARGET_ARCH}${LIBVPX_CRT_SUFFIX}-${LIBVPX_TARGET_VS}-v${LIBVPX_VERSION}/include/vpx")
  115. endif()
  116. file(
  117. INSTALL
  118. "${LIBVPX_INCLUDE_DIR}"
  119. DESTINATION
  120. "${CURRENT_PACKAGES_DIR}/include"
  121. RENAME
  122. "vpx")
  123. if (NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
  124. set(LIBVPX_PREFIX "${CURRENT_INSTALLED_DIR}")
  125. configure_file("${CMAKE_CURRENT_LIST_DIR}/vpx.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/vpx.pc" @ONLY)
  126. endif()
  127. if (NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
  128. set(LIBVPX_PREFIX "${CURRENT_INSTALLED_DIR}/debug")
  129. configure_file("${CMAKE_CURRENT_LIST_DIR}/vpx.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/vpx.pc" @ONLY)
  130. endif()
  131. else()
  132. set(OPTIONS "--disable-examples --disable-tools --disable-docs --disable-unit-tests --enable-pic")
  133. set(OPTIONS_DEBUG "--enable-debug-libs --enable-debug --prefix=${CURRENT_PACKAGES_DIR}/debug")
  134. set(OPTIONS_RELEASE "--prefix=${CURRENT_PACKAGES_DIR}")
  135. if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
  136. set(OPTIONS "${OPTIONS} --disable-static --enable-shared")
  137. else()
  138. set(OPTIONS "${OPTIONS} --enable-static --disable-shared")
  139. endif()
  140. if("realtime" IN_LIST FEATURES)
  141. set(OPTIONS "${OPTIONS} --enable-realtime-only")
  142. endif()
  143. if("highbitdepth" IN_LIST FEATURES)
  144. set(OPTIONS "${OPTIONS} --enable-vp9-highbitdepth")
  145. endif()
  146. if(VCPKG_TARGET_ARCHITECTURE STREQUAL x86)
  147. set(LIBVPX_TARGET_ARCH "x86")
  148. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL x64)
  149. set(LIBVPX_TARGET_ARCH "x86_64")
  150. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL arm64)
  151. set(LIBVPX_TARGET_ARCH "arm64")
  152. else()
  153. message(FATAL_ERROR "libvpx does not support architecture ${VCPKG_TARGET_ARCHITECTURE}")
  154. endif()
  155. if(VCPKG_TARGET_IS_MINGW)
  156. if(LIBVPX_TARGET_ARCH STREQUAL "x86")
  157. set(LIBVPX_TARGET "x86-win32-gcc")
  158. else()
  159. set(LIBVPX_TARGET "x86_64-win64-gcc")
  160. endif()
  161. elseif(VCPKG_TARGET_IS_LINUX)
  162. set(LIBVPX_TARGET "${LIBVPX_TARGET_ARCH}-linux-gcc")
  163. elseif(VCPKG_TARGET_IS_OSX)
  164. if(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
  165. set(LIBVPX_TARGET "arm64-darwin20-gcc")
  166. else()
  167. set(LIBVPX_TARGET "${LIBVPX_TARGET_ARCH}-darwin17-gcc") # enable latest CPU instructions for best performance and less CPU usage on MacOS
  168. endif()
  169. else()
  170. set(LIBVPX_TARGET "generic-gnu") # use default target
  171. endif()
  172. message(STATUS "Build info. Target: ${LIBVPX_TARGET}; Options: ${OPTIONS}")
  173. if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
  174. message(STATUS "Configuring libvpx for Release")
  175. file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
  176. vcpkg_execute_required_process(
  177. COMMAND
  178. ${BASH} --noprofile --norc
  179. "${SOURCE_PATH}/configure"
  180. --target=${LIBVPX_TARGET}
  181. ${OPTIONS}
  182. ${OPTIONS_RELEASE}
  183. --as=nasm
  184. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel"
  185. LOGNAME configure-${TARGET_TRIPLET}-rel)
  186. message(STATUS "Building libvpx for Release")
  187. vcpkg_execute_required_process(
  188. COMMAND
  189. ${BASH} --noprofile --norc -c "make -j8"
  190. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel"
  191. LOGNAME build-${TARGET_TRIPLET}-rel
  192. )
  193. message(STATUS "Installing libvpx for Release")
  194. vcpkg_execute_required_process(
  195. COMMAND
  196. ${BASH} --noprofile --norc -c "make install"
  197. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel"
  198. LOGNAME install-${TARGET_TRIPLET}-rel
  199. )
  200. endif()
  201. # --- --- ---
  202. if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
  203. message(STATUS "Configuring libvpx for Debug")
  204. file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
  205. vcpkg_execute_required_process(
  206. COMMAND
  207. ${BASH} --noprofile --norc
  208. "${SOURCE_PATH}/configure"
  209. --target=${LIBVPX_TARGET}
  210. ${OPTIONS}
  211. ${OPTIONS_DEBUG}
  212. --as=nasm
  213. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg"
  214. LOGNAME configure-${TARGET_TRIPLET}-dbg)
  215. message(STATUS "Building libvpx for Debug")
  216. vcpkg_execute_required_process(
  217. COMMAND
  218. ${BASH} --noprofile --norc -c "make -j8"
  219. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg"
  220. LOGNAME build-${TARGET_TRIPLET}-dbg
  221. )
  222. message(STATUS "Installing libvpx for Debug")
  223. vcpkg_execute_required_process(
  224. COMMAND
  225. ${BASH} --noprofile --norc -c "make install"
  226. WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg"
  227. LOGNAME install-${TARGET_TRIPLET}-dbg
  228. )
  229. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
  230. file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/lib/libvpx_g.a")
  231. endif()
  232. endif()
  233. vcpkg_fixup_pkgconfig()
  234. if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
  235. set(LIBVPX_CONFIG_DEBUG ON)
  236. else()
  237. set(LIBVPX_CONFIG_DEBUG OFF)
  238. endif()
  239. configure_file("${CMAKE_CURRENT_LIST_DIR}/unofficial-libvpx-config.cmake.in" "${CURRENT_PACKAGES_DIR}/share/unofficial-libvpx/unofficial-libvpx-config.cmake" @ONLY)
  240. file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)