Skip to content

Commit

Permalink
[libyuv] Update, enable shared lib (#40549)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg0yt authored Aug 27, 2024
1 parent 1d86542 commit df3e0e1
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 134 deletions.
24 changes: 18 additions & 6 deletions ports/libavif/find-dependency.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 46c6059..c0c047a 100644
index aca5d6f..48a26c3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -660,7 +660,7 @@ endif()
@@ -156,7 +156,10 @@ if(AVIF_LOCAL_LIBYUV)
set(libyuv_FOUND TRUE)
message(STATUS "libavif: local libyuv found; libyuv-based fast paths enabled.")
else(AVIF_LOCAL_LIBYUV)
- find_package(libyuv QUIET) # not required
+ find_package(libyuv_config NAMES libyuv CONFIG REQUIRED)
+ set(LIBYUV_INCLUDE_DIR "${libyuv_INCLUDE_DIRS}")
+ set(LIBYUV_LIBRARY "yuv")
+ find_package(libyuv MODULE REQUIRED)
if(libyuv_FOUND)
# libyuv 1755 exposed all of the I*Matrix() functions, which libavif relies on.
# libyuv 1774 exposed ScalePlane_12 function, which libavif can use for some additional optimizations.
@@ -660,7 +663,7 @@ endif()
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
install(
TARGETS avif
Expand All @@ -11,7 +23,7 @@ index 46c6059..c0c047a 100644
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
@@ -668,7 +668,7 @@ if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
@@ -668,7 +671,7 @@ if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)

# Enable CMake configs in VCPKG mode
if(BUILD_SHARED_LIBS OR VCPKG_TARGET_TRIPLET)
Expand All @@ -20,15 +32,15 @@ index 46c6059..c0c047a 100644

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
@@ -677,6 +677,28 @@ if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
@@ -677,6 +680,28 @@ if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake.in "@PACKAGE_INIT@\n")
+ if(UNIX AND NOT BUILD_SHARED_LIBS)
+ if(NOT BUILD_SHARED_LIBS)
+ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake.in "
+ include(CMakeFindDependencyMacro)
+ set(CMAKE_THREAD_PREFER_PTHREADS ON)
+ find_dependency(libyuv CONFIG)
+ set(THREADS_PREFER_PTHREAD_FLAG ON)
+ find_dependency(Threads)
+ ")
Expand Down
2 changes: 1 addition & 1 deletion ports/libavif/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DAVIF_BUILD_APPS=OFF
-DCMAKE_REQUIRE_FIND_PACKAGE_libyuv=ON
-DCMAKE_DISABLE_FIND_PACKAGE_libsharpyuv=ON
${FEATURE_OPTIONS}
)

Expand Down
2 changes: 1 addition & 1 deletion ports/libavif/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "libavif",
"version-semver": "1.0.4",
"port-version": 1,
"port-version": 2,
"description": "Library for encoding and decoding AVIF files",
"homepage": "https://github.com/AOMediaCodec/libavif",
"license": "BSD-2-Clause AND Apache-2.0",
Expand Down
46 changes: 46 additions & 0 deletions ports/libyuv/cmake.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9a20941..945c5a4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,8 +4,8 @@

include(CheckCSourceCompiles)

+cmake_minimum_required(VERSION 3.12)
project ( YUV C CXX ) # "C" is required even for C++ projects
-cmake_minimum_required( VERSION 2.8.12 )
option( UNIT_TEST "Built unit tests" OFF )

set ( ly_base_dir ${PROJECT_SOURCE_DIR} )
@@ -164,7 +164,8 @@ target_link_libraries ( yuvconstants ${ly_lib_static} )
find_package ( JPEG )
if (JPEG_FOUND)
include_directories( ${JPEG_INCLUDE_DIR} )
- target_link_libraries( ${ly_lib_shared} ${JPEG_LIBRARY} )
+ target_link_libraries( ${ly_lib_static} PRIVATE JPEG::JPEG )
+ target_link_libraries( ${ly_lib_shared} PRIVATE JPEG::JPEG )
add_definitions( -DHAVE_JPEG )
endif()

@@ -211,9 +212,18 @@ endif()


# install the conversion tool, .so, .a, and all the header files
-install ( PROGRAMS ${CMAKE_BINARY_DIR}/yuvconvert DESTINATION bin )
-install ( TARGETS ${ly_lib_static} DESTINATION lib )
-install ( TARGETS ${ly_lib_shared} LIBRARY DESTINATION lib RUNTIME DESTINATION bin )
+install(TARGETS yuvconvert)
+if(BUILD_SHARED_LIBS)
+ target_include_directories(${ly_lib_shared} PUBLIC $<INSTALL_INTERFACE:include>)
+ install(TARGETS ${ly_lib_shared} EXPORT libyuv-targets)
+ set_target_properties(${ly_lib_shared} PROPERTIES EXPORT_NAME "${ly_lib_static}") # vcpkg legacy
+ add_definitions(-DLIBYUV_BUILDING_SHARED_LIBRARY)
+else()
+ target_include_directories(${ly_lib_static} PUBLIC $<INSTALL_INTERFACE:include>)
+ install(TARGETS ${ly_lib_static} EXPORT libyuv-targets)
+ set_target_properties(${ly_lib_shared} PROPERTIES EXCLUDE_FROM_ALL 1)
+endif()
+install(EXPORT libyuv-targets DESTINATION share/libyuv)
install ( DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include )

# create the .deb and .rpm packages using cpack
89 changes: 0 additions & 89 deletions ports/libyuv/fix-cmakelists.patch

This file was deleted.

44 changes: 23 additions & 21 deletions ports/libyuv/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)

vcpkg_from_git(
OUT_SOURCE_PATH SOURCE_PATH
URL https://chromium.googlesource.com/libyuv/libyuv
REF 0faf8dd0e004520a61a603a4d2996d5ecc80dc3f
REF c21dda06dd8d19b6e50168c28c324c1f32e94407 # 6 commits after switch to 1895, reason: CMake changes
# Check https://chromium.googlesource.com/libyuv/libyuv/+/refs/heads/main/include/libyuv/version.h for a version!
PATCHES
fix-cmakelists.patch
cmake.diff
)

vcpkg_cmake_configure(
SOURCE_PATH ${SOURCE_PATH}
OPTIONS
${BUILD_OPTIONS}
OPTIONS_DEBUG
-DCMAKE_DEBUG_POSTFIX=d
SOURCE_PATH "${SOURCE_PATH}"
)

vcpkg_cmake_install()
vcpkg_cmake_config_fixup()
vcpkg_copy_pdbs()

vcpkg_cmake_config_fixup(CONFIG_PATH share/cmake/libyuv)
vcpkg_copy_tools(TOOL_NAMES yuvconvert AUTO_CLEAN)

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)
if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/libyuv/basic_types.h" "defined(LIBYUV_USING_SHARED_LIBRARY)" "1")
endif()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")

configure_file(${CMAKE_CURRENT_LIST_DIR}/libyuv-config.cmake ${CURRENT_PACKAGES_DIR}/share/${PORT} COPYONLY)
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
file(COPY "${CMAKE_CURRENT_LIST_DIR}/libyuv-config.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
file(COPY "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")

vcpkg_cmake_get_vars(cmake_vars_file)
include("${cmake_vars_file}")
if (VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message(WARNING "Use MSVC to compile libyuv results in a very slow library. (https://github.com/microsoft/vcpkg/issues/28446)")
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage-msvc" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME "usage")
else ()
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
endif ()
if(VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
file(APPEND "${CURRENT_PACKAGES_DIR}/share/${PORT}/usage" [[

Attention:
You are using MSVC to compile libyuv. This build won't compile any
of the acceleration codes, which results in a very slow library.
See workarounds: https://github.com/microsoft/vcpkg/issues/28446
]])
endif()

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
5 changes: 3 additions & 2 deletions ports/libyuv/usage
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
libyuv provides CMake targets:

find_package(libyuv CONFIG REQUIRED)
target_link_libraries(main PRIVATE yuv)
# Unofficial config package and target from vcpkg
find_package(libyuv CONFIG REQUIRED)
target_link_libraries(main PRIVATE yuv)
9 changes: 0 additions & 9 deletions ports/libyuv/usage-msvc

This file was deleted.

3 changes: 1 addition & 2 deletions ports/libyuv/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "libyuv",
"version": "1857",
"port-version": 1,
"version": "1895",
"description": "libyuv is an open source project that includes YUV scaling and conversion functionality",
"homepage": "https://chromium.googlesource.com/libyuv/libyuv",
"license": null,
Expand Down
6 changes: 3 additions & 3 deletions versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -4266,7 +4266,7 @@
},
"libavif": {
"baseline": "1.0.4",
"port-version": 1
"port-version": 2
},
"libb2": {
"baseline": "0.98.1",
Expand Down Expand Up @@ -5397,8 +5397,8 @@
"port-version": 5
},
"libyuv": {
"baseline": "1857",
"port-version": 1
"baseline": "1895",
"port-version": 0
},
"libzen": {
"baseline": "0.4.41",
Expand Down
5 changes: 5 additions & 0 deletions versions/l-/libavif.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "30218a66d9e44d06cd55a1e7d29e501ceeba42da",
"version-semver": "1.0.4",
"port-version": 2
},
{
"git-tree": "5464a231b3a83e3d8a076b339d93c5247d04b36b",
"version-semver": "1.0.4",
Expand Down
5 changes: 5 additions & 0 deletions versions/l-/libyuv.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "8248e631c414a1497fe1c8100a658b6f9f180a4d",
"version": "1895",
"port-version": 0
},
{
"git-tree": "a814249d5f2638de96bece573dfddddadec7527c",
"version": "1857",
Expand Down

0 comments on commit df3e0e1

Please sign in to comment.