From 2cf1e05bd990da73ee7f7ca4782c06ddb802d14b Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Mon, 25 Nov 2024 21:35:02 +0100 Subject: [PATCH] [libavif] Fix usage requirements export (#42250) --- ports/libavif/dependencies.diff | 52 +++++++++++++++++++ ports/libavif/portfile.cmake | 30 +++++------ ports/libavif/vcpkg.json | 1 + .../vcpkg-ci-libavif/portfile.cmake | 10 ++++ .../vcpkg-ci-libavif/project/CMakeLists.txt | 17 ++++++ .../vcpkg-ci-libavif/project/main.c | 10 ++++ .../test_ports/vcpkg-ci-libavif/vcpkg.json | 34 ++++++++++++ versions/baseline.json | 2 +- versions/l-/libavif.json | 5 ++ 9 files changed, 143 insertions(+), 18 deletions(-) create mode 100644 ports/libavif/dependencies.diff create mode 100644 scripts/test_ports/vcpkg-ci-libavif/portfile.cmake create mode 100644 scripts/test_ports/vcpkg-ci-libavif/project/CMakeLists.txt create mode 100644 scripts/test_ports/vcpkg-ci-libavif/project/main.c create mode 100644 scripts/test_ports/vcpkg-ci-libavif/vcpkg.json diff --git a/ports/libavif/dependencies.diff b/ports/libavif/dependencies.diff new file mode 100644 index 0000000000..a543d14a5d --- /dev/null +++ b/ports/libavif/dependencies.diff @@ -0,0 +1,52 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index a28e6c3..aaeb5d2 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -248,6 +248,7 @@ if(AVIF_LIBYUV_ENABLED) + target_compile_definitions(avif_obj PRIVATE -DAVIF_LIBYUV_ENABLED=1) + avif_target_link_library(yuv::yuv) + set(AVIF_PKG_CONFIG_EXTRA_LIBS_PRIVATE "${AVIF_PKG_CONFIG_EXTRA_LIBS_PRIVATE} -lyuv") ++ set(AVIF_PKG_CONFIG_EXTRA_REQUIRES_PRIVATE "${AVIF_PKG_CONFIG_EXTRA_REQUIRES_PRIVATE} libjpeg") + set(AVIF_LIB_USE_CXX ON) + endif(AVIF_LIBYUV_ENABLED) + +@@ -849,13 +850,38 @@ if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) + + # Enable CMake configs in VCPKG mode + if(BUILD_SHARED_LIBS OR VCPKG_TARGET_TRIPLET) +- install(EXPORT ${PROJECT_NAME}-config DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) ++ install(EXPORT ${PROJECT_NAME}-config DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} FILE ${PROJECT_NAME}-targets.cmake) ++ if(NOT BUILD_SHARED_LIBS) ++ target_include_directories(avif_static PUBLIC $) ++ set(avif_static_link_libs yuv) ++ set(avif_find_dependencies "find_dependency(libyuv CONFIG)\n") ++ if(AVIF_CODEC_AOM_ENABLED) ++ find_package(aom CONFIG REQUIRED) ++ list(APPEND avif_static_link_libs unofficial::aom) ++ string(APPEND avif_find_dependencies "find_dependency(aom CONFIG)\n") ++ endif() ++ if(AVIF_CODEC_DAV1D_ENABLED) ++ list(APPEND avif_static_link_libs ${DAV1D_LIBRARIES} ${CMAKE_DL_LIBS}) ++ endif() ++ if(UNIX OR MINGW) ++ list(APPEND avif_static_link_libs Threads::Threads m) ++ string(APPEND avif_find_dependencies "set(THREADS_PREFER_PTHREAD_FLAG ON)\nfind_dependency(Threads)\n") ++ endif() ++ target_link_libraries(avif_static INTERFACE ${avif_static_link_libs}) ++ endif() ++ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" ++"# Generated by vcpkg ++include(CMakeFindDependencyMacro) ++${avif_find_dependencies} ++include(\"\${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}-targets.cmake\") ++") + + include(CMakePackageConfigHelpers) + write_basic_package_version_file( + ${PROJECT_NAME}-config-version.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion + ) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake ++ ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + ) + endif() diff --git a/ports/libavif/portfile.cmake b/ports/libavif/portfile.cmake index 1cfdc16ba2..58611565c0 100644 --- a/ports/libavif/portfile.cmake +++ b/ports/libavif/portfile.cmake @@ -5,37 +5,33 @@ vcpkg_from_github( SHA512 ba72b8d02b098f361643a073361fccafd22eaac14e46dd06378d5e7acd9853538c5d166473e1de0b020de62dac25be83e42bd57ba51f675d11e2ddf155fbfa21 HEAD_REF master PATCHES + dependencies.diff disable-source-utf8.patch ) +file(REMOVE_RECURSE "${SOURCE_PATH}/third_party") -vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS - FEATURES - aom AVIF_CODEC_AOM - dav1d AVIF_CODEC_DAV1D -) +set(FEATURE_OPTIONS "") +if("aom" IN_LIST FEATURES) + list(APPEND FEATURE_OPTIONS "-DAVIF_CODEC_AOM=SYSTEM") +endif() +if("dav1d" IN_LIST FEATURES) + list(APPEND FEATURE_OPTIONS "-DAVIF_CODEC_DAV1D=SYSTEM") +endif() + +vcpkg_find_acquire_program(PKGCONFIG) vcpkg_cmake_configure( SOURCE_PATH "${SOURCE_PATH}" OPTIONS - -DAVIF_BUILD_APPS=OFF - -DAVIF_BUILD_TESTS=OFF - -DCMAKE_DISABLE_FIND_PACKAGE_libsharpyuv=ON ${FEATURE_OPTIONS} + "-DPKG_CONFIG_EXECUTABLE=${PKGCONFIG}" ) - vcpkg_cmake_install() - vcpkg_copy_pdbs() - -# Move cmake configs +vcpkg_fixup_pkgconfig() vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/${PORT}) -# Fix pkg-config files -vcpkg_fixup_pkgconfig() - -# Remove duplicate files file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" "${CURRENT_PACKAGES_DIR}/debug/share") -# Handle copyright vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") diff --git a/ports/libavif/vcpkg.json b/ports/libavif/vcpkg.json index 78312d7ac2..e2212eeef1 100644 --- a/ports/libavif/vcpkg.json +++ b/ports/libavif/vcpkg.json @@ -1,6 +1,7 @@ { "name": "libavif", "version-semver": "1.1.1", + "port-version": 1, "description": "Library for encoding and decoding AVIF files", "homepage": "https://github.com/AOMediaCodec/libavif", "license": "BSD-2-Clause AND Apache-2.0", diff --git a/scripts/test_ports/vcpkg-ci-libavif/portfile.cmake b/scripts/test_ports/vcpkg-ci-libavif/portfile.cmake new file mode 100644 index 0000000000..dd25706120 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-libavif/portfile.cmake @@ -0,0 +1,10 @@ +set(VCPKG_POLICY_EMPTY_PACKAGE enabled) + +vcpkg_find_acquire_program(PKGCONFIG) + +vcpkg_cmake_configure( + SOURCE_PATH "${CURRENT_PORT_DIR}/project" + OPTIONS + "-DPKG_CONFIG_EXECUTABLE=${PKGCONFIG}" +) +vcpkg_cmake_build() diff --git a/scripts/test_ports/vcpkg-ci-libavif/project/CMakeLists.txt b/scripts/test_ports/vcpkg-ci-libavif/project/CMakeLists.txt new file mode 100644 index 0000000000..37e5786d9c --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-libavif/project/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.30) +project(libavif-test C) + +find_package(libavif CONFIG REQUIRED) + +add_executable(main main.c) +target_link_libraries(main PRIVATE + $ +) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(libavif_pc libavif REQUIRED IMPORTED_TARGET) + +add_executable(main-pkconfig main.c) +target_link_libraries(main-pkconfig PRIVATE + PkgConfig::libavif_pc +) diff --git a/scripts/test_ports/vcpkg-ci-libavif/project/main.c b/scripts/test_ports/vcpkg-ci-libavif/project/main.c new file mode 100644 index 0000000000..f305e9f1c6 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-libavif/project/main.c @@ -0,0 +1,10 @@ +#include +#include + +int main() +{ + char codecVersions[256]; + avifCodecVersions(codecVersions); + printf("Codec Versions: %s\n", codecVersions); + return 0; +} diff --git a/scripts/test_ports/vcpkg-ci-libavif/vcpkg.json b/scripts/test_ports/vcpkg-ci-libavif/vcpkg.json new file mode 100644 index 0000000000..7734f771ce --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-libavif/vcpkg.json @@ -0,0 +1,34 @@ +{ + "name": "vcpkg-ci-libavif", + "version-string": "ci", + "description": "Port to force features of libavif within CI", + "homepage": "https://github.com/microsoft/vcpkg", + "license": "MIT", + "dependencies": [ + { + "name": "libavif", + "default-features": false + }, + { + "name": "vcpkg-cmake", + "host": true + } + ], + "default-features": [ + "all" + ], + "features": { + "all": { + "description": "Test all features", + "dependencies": [ + { + "name": "libavif", + "features": [ + "aom", + "dav1d" + ] + } + ] + } + } +} diff --git a/versions/baseline.json b/versions/baseline.json index c7c1a36058..a91b58e707 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -4330,7 +4330,7 @@ }, "libavif": { "baseline": "1.1.1", - "port-version": 0 + "port-version": 1 }, "libb2": { "baseline": "0.98.1", diff --git a/versions/l-/libavif.json b/versions/l-/libavif.json index 975aa578ab..fc76b3f4d7 100644 --- a/versions/l-/libavif.json +++ b/versions/l-/libavif.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "6ce7e81979ac4f42aaafb11efbb35b171fe53791", + "version-semver": "1.1.1", + "port-version": 1 + }, { "git-tree": "ad9d36286110339f45b585a1bbb330273c04edad", "version-semver": "1.1.1",