From d654e6b78a98685dfabea9a81cf81eea960d9e07 Mon Sep 17 00:00:00 2001 From: Gordon Smith Date: Fri, 5 Apr 2024 03:22:02 +0100 Subject: [PATCH] fix: Switch to forked xz repo Signed-off-by: Gordon Smith --- overlays/liblzma/add_support_ios.patch | 20 +++++ overlays/liblzma/build-tools.patch | 20 +++++ overlays/liblzma/fix_config_include.patch | 12 +++ overlays/liblzma/portfile.cmake | 86 ++++++++++++++++++++++ overlays/liblzma/usage | 9 +++ overlays/liblzma/vcpkg-cmake-wrapper.cmake | 64 ++++++++++++++++ overlays/liblzma/vcpkg.json | 24 ++++++ overlays/liblzma/win_output_name.patch | 17 +++++ 8 files changed, 252 insertions(+) create mode 100644 overlays/liblzma/add_support_ios.patch create mode 100644 overlays/liblzma/build-tools.patch create mode 100644 overlays/liblzma/fix_config_include.patch create mode 100644 overlays/liblzma/portfile.cmake create mode 100644 overlays/liblzma/usage create mode 100644 overlays/liblzma/vcpkg-cmake-wrapper.cmake create mode 100644 overlays/liblzma/vcpkg.json create mode 100644 overlays/liblzma/win_output_name.patch diff --git a/overlays/liblzma/add_support_ios.patch b/overlays/liblzma/add_support_ios.patch new file mode 100644 index 00000000000000..79741639b60a2b --- /dev/null +++ b/overlays/liblzma/add_support_ios.patch @@ -0,0 +1,20 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 52439b3..0b5e371 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -574,6 +574,7 @@ if(HAVE_GETOPT_LONG) + + install(TARGETS xzdec + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ++ BUNDLE DESTINATION "${CMAKE_INSTALL_BINDIR}" + COMPONENT xzdec) + + if(UNIX) +@@ -701,6 +702,7 @@ if(NOT MSVC AND HAVE_GETOPT_LONG) + + install(TARGETS xz + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ++ BUNDLE DESTINATION "${CMAKE_INSTALL_BINDIR}" + COMPONENT xz) + + if(UNIX) diff --git a/overlays/liblzma/build-tools.patch b/overlays/liblzma/build-tools.patch new file mode 100644 index 00000000000000..759345ef23afee --- /dev/null +++ b/overlays/liblzma/build-tools.patch @@ -0,0 +1,20 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 03b8301..820d08e 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -584,6 +584,7 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config.cmake" + COMPONENT liblzma_Development) + + ++if(BUILD_TOOLS) + ############################################################################# + # getopt_long + ############################################################################# +@@ -793,6 +794,7 @@ if(NOT MSVC AND HAVE_GETOPT_LONG) + endforeach() + endif() + endif() ++endif() + + + ############################################################################# diff --git a/overlays/liblzma/fix_config_include.patch b/overlays/liblzma/fix_config_include.patch new file mode 100644 index 00000000000000..91dc4c13ba5435 --- /dev/null +++ b/overlays/liblzma/fix_config_include.patch @@ -0,0 +1,12 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 34c6aca00..7b3708ab2 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -413,6 +413,7 @@ if(WIN32) + if(BUILD_SHARED_LIBS) + # Add the Windows resource file for liblzma.dll. + target_sources(liblzma PRIVATE src/liblzma/liblzma_w32res.rc) ++ target_include_directories(liblzma PRIVATE windows/vs2019) + + set_target_properties(liblzma PROPERTIES + LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc" diff --git a/overlays/liblzma/portfile.cmake b/overlays/liblzma/portfile.cmake new file mode 100644 index 00000000000000..0ce7c901363da6 --- /dev/null +++ b/overlays/liblzma/portfile.cmake @@ -0,0 +1,86 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO GordonSmith/xz + REF "v${VERSION}" + SHA512 67292be900a713035d2a3dab4c3b6697cf0db37a78faaa5e0d3f5a96909ef9645c15a6030af94fb7f4224c3ad8eacd1a653ba67dfdeb6372165c1c36e0cf16b7 + HEAD_REF master + PATCHES + fix_config_include.patch + win_output_name.patch # Fix output name on Windows. Autotool build does not generate lib prefixed libraries on windows. + add_support_ios.patch # add install bundle info for support ios + build-tools.patch +) + +vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS + FEATURES + tools BUILD_TOOLS +) + +if(VCPKG_TARGET_ARCHITECTURE STREQUAL "wasm32") + set(WASM_OPTIONS -DCMAKE_C_BYTE_ORDER=LITTLE_ENDIAN -DCMAKE_CXX_BYTE_ORDER=LITTLE_ENDIAN) +endif() + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + ${FEATURE_OPTIONS} + ${WASM_OPTIONS} + -DBUILD_TESTING=OFF + -DCREATE_XZ_SYMLINKS=OFF + -DCREATE_LZMA_SYMLINKS=OFF + -DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT= # using flags from (vcpkg) toolchain + MAYBE_UNUSED_VARIABLES + CMAKE_MSVC_DEBUG_INFORMATION_FORMAT + CREATE_XZ_SYMLINKS + CREATE_LZMA_SYMLINKS +) +vcpkg_cmake_install() +vcpkg_copy_pdbs() + +set(exec_prefix "\${prefix}") +set(libdir "\${prefix}/lib") +set(includedir "\${prefix}/include") +set(PACKAGE_URL https://tukaani.org/xz/) +set(PACKAGE_VERSION 5.4.3) +if(NOT VCPKG_TARGET_IS_WINDOWS) + set(PTHREAD_CFLAGS -pthread) +endif() +set(prefix "${CURRENT_INSTALLED_DIR}") +configure_file("${SOURCE_PATH}/src/liblzma/liblzma.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/liblzma.pc" @ONLY) +if (NOT VCPKG_BUILD_TYPE) + set(prefix "${CURRENT_INSTALLED_DIR}/debug") + configure_file("${SOURCE_PATH}/src/liblzma/liblzma.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/liblzma.pc" @ONLY) +endif() +vcpkg_fixup_pkgconfig() + +vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/liblzma) + +if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/lzma.h" "defined(LZMA_API_STATIC)" "1") +else() + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/lzma.h" "defined(LZMA_API_STATIC)" "0") +endif() + +file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/debug/include" + "${CURRENT_PACKAGES_DIR}/debug/share" + "${CURRENT_PACKAGES_DIR}/share/man" +) + +set(TOOLS xz xzdec) +foreach(_tool IN LISTS TOOLS) + if(NOT EXISTS "${CURRENT_PACKAGES_DIR}/bin/${_tool}${VCPKG_TARGET_EXECUTABLE_SUFFIX}") + list(REMOVE_ITEM TOOLS ${_tool}) + endif() +endforeach() +if(TOOLS) + vcpkg_copy_tools(TOOL_NAMES ${TOOLS} AUTO_CLEAN) +endif() + +if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin") +endif() + +file(COPY "${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") +file(COPY "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING") diff --git a/overlays/liblzma/usage b/overlays/liblzma/usage new file mode 100644 index 00000000000000..b1461c93fc0a9e --- /dev/null +++ b/overlays/liblzma/usage @@ -0,0 +1,9 @@ +liblzma is compatible with built-in CMake targets: + + find_package(LibLZMA REQUIRED) + target_link_libraries(main PRIVATE LibLZMA::LibLZMA) + +liblzma provides CMake targets: + + find_package(liblzma CONFIG REQUIRED) + target_link_libraries(main PRIVATE liblzma::liblzma) diff --git a/overlays/liblzma/vcpkg-cmake-wrapper.cmake b/overlays/liblzma/vcpkg-cmake-wrapper.cmake new file mode 100644 index 00000000000000..826cdba0650ba6 --- /dev/null +++ b/overlays/liblzma/vcpkg-cmake-wrapper.cmake @@ -0,0 +1,64 @@ +cmake_policy(PUSH) +cmake_policy(SET CMP0012 NEW) +cmake_policy(SET CMP0057 NEW) +set(z_vcpkg_liblzma_fixup_needed 0) +if(NOT "CONFIG" IN_LIST ARGS AND NOT "NO_MODULE" IN_LIST ARGS AND NOT CMAKE_DISABLE_FIND_PACKAGE_LibLZMA) + get_filename_component(z_vcpkg_liblzma_prefix "${CMAKE_CURRENT_LIST_DIR}" DIRECTORY) + get_filename_component(z_vcpkg_liblzma_prefix "${z_vcpkg_liblzma_prefix}" DIRECTORY) + find_path(LIBLZMA_INCLUDE_DIR NAMES lzma.h PATHS "${z_vcpkg_liblzma_prefix}/include" NO_DEFAULT_PATH) + # liblzma doesn't use a debug postfix, but FindLibLZMA.cmake expects it + find_library(LIBLZMA_LIBRARY_RELEASE NAMES lzma PATHS "${z_vcpkg_liblzma_prefix}/lib" NO_DEFAULT_PATH) + find_library(LIBLZMA_LIBRARY_DEBUG NAMES lzma PATHS "${z_vcpkg_liblzma_prefix}/debug/lib" NO_DEFAULT_PATH) + unset(z_vcpkg_liblzma_prefix) + if(CMAKE_VERSION VERSION_LESS 3.16) + # Older versions of FindLibLZMA.cmake need a single lib in LIBLZMA_LIBRARY. + set(z_vcpkg_liblzma_fixup_needed 1) + set(LIBLZMA_LIBRARY "${LIBLZMA_LIBRARY_RELEASE}" CACHE INTERNAL "") + elseif(NOT TARGET LibLZMA::LibLZMA) + set(z_vcpkg_liblzma_fixup_needed 1) + endif() + # Known values, and required. Skip expensive tests. + set(LIBLZMA_HAS_AUTO_DECODER 1 CACHE INTERNAL "") + set(LIBLZMA_HAS_EASY_ENCODER 1 CACHE INTERNAL "") + set(LIBLZMA_HAS_LZMA_PRESET 1 CACHE INTERNAL "") +endif() + +_find_package(${ARGS}) + +if(z_vcpkg_liblzma_fixup_needed) + include(SelectLibraryConfigurations) + select_library_configurations(LIBLZMA) + if(NOT TARGET LibLZMA::LibLZMA) + # Backfill LibLZMA::LibLZMA to versions of cmake before 3.14 + add_library(LibLZMA::LibLZMA UNKNOWN IMPORTED) + if(DEFINED LIBLZMA_INCLUDE_DIRS) + set_target_properties(LibLZMA::LibLZMA PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LIBLZMA_INCLUDE_DIRS}") + endif() + set_property(TARGET LibLZMA::LibLZMA APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(LibLZMA::LibLZMA PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" + IMPORTED_LOCATION_RELEASE "${LIBLZMA_LIBRARY_RELEASE}") + if(EXISTS "${LIBLZMA_LIBRARY}") + set_target_properties(LibLZMA::LibLZMA PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${LIBLZMA_LIBRARY}") + endif() + endif() + if(LIBLZMA_LIBRARY_DEBUG) + # Backfill debug variant to versions of cmake before 3.16 + set_property(TARGET LibLZMA::LibLZMA APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(LibLZMA::LibLZMA PROPERTIES IMPORTED_LOCATION_DEBUG "${LIBLZMA_LIBRARY_DEBUG}") + endif() +endif() +if(LIBLZMA_LIBRARIES AND NOT "Threads::Threads" IN_LIST LIBLZMA_LIBRARIES) + set(THREADS_PREFER_PTHREAD_FLAG TRUE) + find_package(Threads) + list(APPEND LIBLZMA_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + if(TARGET LibLZMA::LibLZMA) + set_property(TARGET LibLZMA::LibLZMA APPEND PROPERTY INTERFACE_LINK_LIBRARIES Threads::Threads) + endif() +endif() +unset(z_vcpkg_liblzma_fixup_needed) +cmake_policy(POP) diff --git a/overlays/liblzma/vcpkg.json b/overlays/liblzma/vcpkg.json new file mode 100644 index 00000000000000..6d4e5ca40cff6f --- /dev/null +++ b/overlays/liblzma/vcpkg.json @@ -0,0 +1,24 @@ +{ + "name": "liblzma", + "version": "5.4.3", + "port-version": 1, + "description": "Compression library with an API similar to that of zlib.", + "homepage": "https://github.com/GordonSmith/xz", + "license": null, + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ], + "features": { + "tools": { + "description": "Build tools", + "supports": "!windows, mingw" + } + } +} \ No newline at end of file diff --git a/overlays/liblzma/win_output_name.patch b/overlays/liblzma/win_output_name.patch new file mode 100644 index 00000000000000..9a845bdbaef1d2 --- /dev/null +++ b/overlays/liblzma/win_output_name.patch @@ -0,0 +1,17 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 0c6d4b7..62a824a 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -868,8 +868,11 @@ set_target_properties(liblzma PROPERTIES + + # It's liblzma.so or liblzma.dll, not libliblzma.so or lzma.dll. + # Avoid the name lzma.dll because it would conflict with LZMA SDK. +- PREFIX "" ++ OUTPUT_NAME lzma + ) ++if(WIN32 AND NOT MINGW) ++ set_target_properties(liblzma PROPERTIES RUNTIME_OUTPUT_NAME liblzma) ++endif() + + # Create liblzma-config-version.cmake. + #