Skip to content

Commit

Permalink
[brotli] Export libm usage requirement, cleanup, usage (microsoft#27971)
Browse files Browse the repository at this point in the history
* Simplify pkgconfig patch

* Export libm usage requirement

* Merge ios patch into install patch

* Revise portfile

* Refactor cmake wrapper into config

* Document usage

* Update versions
  • Loading branch information
dg0yt authored Dec 2, 2022
1 parent c4294ea commit 163fe7b
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 98 deletions.
12 changes: 0 additions & 12 deletions ports/brotli/fix-ios.patch

This file was deleted.

5 changes: 3 additions & 2 deletions ports/brotli/install.patch
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ index 4ff3401..46492d0 100644
endforeach()

if(NOT BROTLI_EMSCRIPTEN)
@@ -223,27 +222,35 @@ if(NOT BROTLI_EMSCRIPTEN)
@@ -223,27 +222,36 @@ if(NOT BROTLI_EMSCRIPTEN)
if(NOT BROTLI_BUNDLED_MODE)
install(
TARGETS brotli
- RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+ RUNTIME DESTINATION tools/brotli
+ BUNDLE DESTINATION tools/brotli
+ CONFIGURATIONS Release
)

Expand Down Expand Up @@ -52,7 +53,7 @@ index 4ff3401..46492d0 100644
+ CONFIGURATIONS Release
)
+
+ install(EXPORT brotli FILE unofficial-brotli-config.cmake NAMESPACE unofficial::brotli:: DESTINATION share/unofficial-brotli)
+ install(EXPORT brotli FILE unofficial-brotli-targets.cmake NAMESPACE unofficial::brotli:: DESTINATION share/unofficial-brotli)
endif() # BROTLI_BUNDLED_MODE
endif() # BROTLI_EMSCRIPTEN

74 changes: 9 additions & 65 deletions ports/brotli/pkgconfig.patch
Original file line number Diff line number Diff line change
@@ -1,74 +1,18 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b1c654b..fcd9024 100644
index 0cdb73b..33a80a7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -390,7 +390,7 @@ function(generate_pkg_config_path outvar path)
set("${outvar}" "${${outvar}}" PARENT_SCOPE)
endfunction(generate_pkg_config_path)

-function(transform_pc_file INPUT_FILE OUTPUT_FILE VERSION)
+function(transform_pc_file INPUT_FILE OUTPUT_FILE VERSION SHARED_TARGET STATIC_TARGET)
file(READ ${INPUT_FILE} TEXT)

set(PREFIX "${CMAKE_INSTALL_PREFIX}")
@@ -404,15 +404,22 @@ function(transform_pc_file INPUT_FILE OUTPUT_FILE VERSION)
string(REGEX REPLACE "@includedir@" "${INCLUDEDIR}" TEXT ${TEXT})
@@ -406,6 +406,13 @@ function(transform_pc_file INPUT_FILE OUTPUT_FILE VERSION)

string(REGEX REPLACE "@PACKAGE_VERSION@" "${VERSION}" TEXT ${TEXT})
+
+ if(BUILD_SHARED_LIBS)
+ set(LIB_NAME "${SHARED_TARGET}")
+ else()
+ set(LIB_NAME "${STATIC_TARGET}")
+ endif()
+ string(REGEX REPLACE "@lib_name@" "${LIB_NAME}" TEXT ${TEXT})

+ string(REPLACE [[ -R${libdir}]] "" TEXT ${TEXT})
+ if(NOT BUILD_SHARED_LIBS)
+ string(REGEX REPLACE [[( -lbrotli[a-z]*)]] [[\1-static]] TEXT ${TEXT})
+ if(LIBM_LIBRARY)
+ string(REPLACE " -lbrotlicommon-static" " -lbrotlicommon-static -l${LIBM_LIBRARY}" TEXT ${TEXT})
+ endif()
+ endif()
file(WRITE ${OUTPUT_FILE} ${TEXT})
endfunction()

-transform_pc_file("scripts/libbrotlicommon.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libbrotlicommon.pc" "${BROTLI_VERSION}")
+transform_pc_file("scripts/libbrotlicommon.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libbrotlicommon.pc" "${BROTLI_VERSION}" brotlicommon brotlicommon-static)

-transform_pc_file("scripts/libbrotlidec.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libbrotlidec.pc" "${BROTLI_VERSION}")
+transform_pc_file("scripts/libbrotlidec.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libbrotlidec.pc" "${BROTLI_VERSION}" brotlidec brotlidec-static)

-transform_pc_file("scripts/libbrotlienc.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libbrotlienc.pc" "${BROTLI_VERSION}")
+transform_pc_file("scripts/libbrotlienc.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libbrotlienc.pc" "${BROTLI_VERSION}" brotlienc brotlienc-static)

if(NOT BROTLI_EMSCRIPTEN)
if(NOT BROTLI_BUNDLED_MODE)
diff --git a/scripts/libbrotlicommon.pc.in b/scripts/libbrotlicommon.pc.in
index 10ca969..7736344 100644
--- a/scripts/libbrotlicommon.pc.in
+++ b/scripts/libbrotlicommon.pc.in
@@ -7,5 +7,5 @@ Name: libbrotlicommon
URL: https://github.com/google/brotli
Description: Brotli common dictionary library
Version: @PACKAGE_VERSION@
-Libs: -L${libdir} -R${libdir} -lbrotlicommon
+Libs: -L${libdir} -l@lib_name@
Cflags: -I${includedir}
diff --git a/scripts/libbrotlidec.pc.in b/scripts/libbrotlidec.pc.in
index e7c3124..a7dc8ce 100644
--- a/scripts/libbrotlidec.pc.in
+++ b/scripts/libbrotlidec.pc.in
@@ -7,6 +7,6 @@ Name: libbrotlidec
URL: https://github.com/google/brotli
Description: Brotli decoder library
Version: @PACKAGE_VERSION@
-Libs: -L${libdir} -R${libdir} -lbrotlidec
+Libs: -L${libdir} -l@lib_name@
Requires.private: libbrotlicommon >= 1.0.2
Cflags: -I${includedir}
diff --git a/scripts/libbrotlienc.pc.in b/scripts/libbrotlienc.pc.in
index 4dd0811..eb2712e 100644
--- a/scripts/libbrotlienc.pc.in
+++ b/scripts/libbrotlienc.pc.in
@@ -7,6 +7,6 @@ Name: libbrotlienc
URL: https://github.com/google/brotli
Description: Brotli encoder library
Version: @PACKAGE_VERSION@
-Libs: -L${libdir} -R${libdir} -lbrotlienc
+Libs: -L${libdir} -l@lib_name@
Requires.private: libbrotlicommon >= 1.0.2
Cflags: -I${includedir}
10 changes: 4 additions & 6 deletions ports/brotli/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@ vcpkg_from_github(
install.patch
fix-arm-uwp.patch
pkgconfig.patch
fix-ios.patch
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DBROTLI_DISABLE_TESTS=ON
)

vcpkg_cmake_install()

vcpkg_copy_pdbs()
vcpkg_fixup_pkgconfig()

vcpkg_copy_tool_dependencies("${CURRENT_PACKAGES_DIR}/tools/brotli")
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/unofficial-brotli-config.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/unofficial-brotli")
vcpkg_cmake_config_fixup(CONFIG_PATH share/unofficial-brotli PACKAGE_NAME unofficial-brotli)
vcpkg_fixup_pkgconfig()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/tools")
vcpkg_copy_tool_dependencies("${CURRENT_PACKAGES_DIR}/tools/brotli")

file(COPY "${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/unofficial-brotli")
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
11 changes: 11 additions & 0 deletions ports/brotli/unofficial-brotli-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include("${CMAKE_CURRENT_LIST_DIR}/unofficial-brotli-targets.cmake")
foreach(target IN ITEMS brotlicommon brotlidec brotlienc)
if(TARGET unofficial::brotli::${target} AND NOT TARGET unofficial::brotli::${target}-static)
_add_library(unofficial::brotli::${target}-static INTERFACE IMPORTED)
set_target_properties(unofficial::brotli::${target}-static PROPERTIES INTERFACE_LINK_LIBRARIES "unofficial::brotli::${target}")
endif()
if(NOT TARGET unofficial::brotli::${target} AND TARGET unofficial::brotli::${target}-static)
_add_library(unofficial::brotli::${target} INTERFACE IMPORTED)
set_target_properties(unofficial::brotli::${target} PROPERTIES INTERFACE_LINK_LIBRARIES "unofficial::brotli::${target}-static")
endif()
endforeach()
7 changes: 7 additions & 0 deletions ports/brotli/usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
brotli provides CMake targets:

find_package(unofficial-brotli CONFIG REQUIRED)
# Brotli decoder library
target_link_libraries(main PRIVATE unofficial::brotli::brotlidec)
# Brotli encoder library
target_link_libraries(main PRIVATE unofficial::brotli::brotlienc)
11 changes: 0 additions & 11 deletions ports/brotli/vcpkg-cmake-wrapper.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion ports/brotli/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "brotli",
"version": "1.0.9",
"port-version": 3,
"port-version": 4,
"description": "a generic-purpose lossless compression algorithm that compresses data using a combination of a modern variant of the LZ77 algorithm, Huffman coding and 2nd order context modeling.",
"homepage": "https://github.com/google/brotli",
"license": "MIT",
Expand Down
5 changes: 5 additions & 0 deletions versions/b-/brotli.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "e6838ab1a2b10d47924875dd1f71c47d45c01bb6",
"version": "1.0.9",
"port-version": 4
},
{
"git-tree": "7b182b3e0615d6f3538b5eeac680f7eb8af5abd0",
"version": "1.0.9",
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@
},
"brotli": {
"baseline": "1.0.9",
"port-version": 3
"port-version": 4
},
"brpc": {
"baseline": "1.2.0",
Expand Down

0 comments on commit 163fe7b

Please sign in to comment.