portfile.cmake 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
  2. vcpkg_from_git(
  3. OUT_SOURCE_PATH SOURCE_PATH
  4. URL https://chromium.googlesource.com/libyuv/libyuv
  5. REF 0faf8dd0e004520a61a603a4d2996d5ecc80dc3f
  6. # Check https://chromium.googlesource.com/libyuv/libyuv/+/refs/heads/main/include/libyuv/version.h for a version!
  7. PATCHES
  8. fix-cmakelists.patch
  9. )
  10. vcpkg_cmake_get_vars(cmake_vars_file)
  11. include("${cmake_vars_file}")
  12. if (VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND NOT VCPKG_TARGET_IS_UWP)
  13. # Most of libyuv accelerated features need to be compiled by clang/gcc, so force use clang-cl, otherwise the performance is too poor.
  14. # Manually build the port with clang-cl when using MSVC as compiler
  15. message(STATUS "Set compiler to clang-cl when using MSVC")
  16. # https://github.com/microsoft/vcpkg/pull/10398
  17. set(VCPKG_POLICY_SKIP_ARCHITECTURE_CHECK enabled)
  18. vcpkg_find_acquire_program(CLANG)
  19. if (CLANG MATCHES "-NOTFOUND")
  20. message(FATAL_ERROR "Clang is required.")
  21. endif ()
  22. get_filename_component(CLANG "${CLANG}" DIRECTORY)
  23. if(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm")
  24. set(CLANG_TARGET "arm")
  25. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
  26. set(CLANG_TARGET "aarch64")
  27. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
  28. set(CLANG_TARGET "i686")
  29. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
  30. set(CLANG_TARGET "x86_64")
  31. else()
  32. message(FATAL_ERROR "Unsupported target architecture")
  33. endif()
  34. set(CLANG_TARGET "${CLANG_TARGET}-pc-windows-msvc")
  35. message(STATUS "Using clang target ${CLANG_TARGET}")
  36. string(APPEND VCPKG_DETECTED_CMAKE_CXX_FLAGS --target=${CLANG_TARGET})
  37. string(APPEND VCPKG_DETECTED_CMAKE_C_FLAGS --target=${CLANG_TARGET})
  38. set(BUILD_OPTIONS
  39. -DCMAKE_CXX_COMPILER=${CLANG}/clang-cl.exe
  40. -DCMAKE_C_COMPILER=${CLANG}/clang-cl.exe
  41. -DCMAKE_CXX_FLAGS=${VCPKG_DETECTED_CMAKE_CXX_FLAGS}
  42. -DCMAKE_C_FLAGS=${VCPKG_DETECTED_CMAKE_C_FLAGS})
  43. endif ()
  44. vcpkg_cmake_configure(
  45. SOURCE_PATH ${SOURCE_PATH}
  46. DISABLE_PARALLEL_CONFIGURE
  47. OPTIONS
  48. ${BUILD_OPTIONS}
  49. OPTIONS_DEBUG
  50. -DCMAKE_DEBUG_POSTFIX=d
  51. )
  52. vcpkg_cmake_install()
  53. vcpkg_copy_pdbs()
  54. vcpkg_cmake_config_fixup(CONFIG_PATH share/cmake/libyuv)
  55. file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
  56. file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)
  57. configure_file(${CMAKE_CURRENT_LIST_DIR}/libyuv-config.cmake ${CURRENT_PACKAGES_DIR}/share/${PORT} COPYONLY)
  58. file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
  59. vcpkg_cmake_get_vars(cmake_vars_file)
  60. include("${cmake_vars_file}")
  61. if (VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
  62. message(WARNING "Use MSVC to compile libyuv results in a very slow library. (https://github.com/microsoft/vcpkg/issues/28446)")
  63. file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage-msvc" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME "usage")
  64. else ()
  65. file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
  66. endif ()