Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[freetype] Fix INTERFACE_LINK_LIBRARIES in exported cmake file #14499

Merged
merged 4 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ports/freetype/CONTROL
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Source: freetype
Version: 2.10.2
Port-Version: 4
Port-Version: 5
Build-Depends: zlib, brotli
Homepage: https://www.freetype.org/
Description: A library to render fonts.
Expand Down
30 changes: 30 additions & 0 deletions ports/freetype/fix-exports.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 04ce73a..ee3cc05 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -454,7 +454,7 @@ endif ()
set(PKG_CONFIG_REQUIRED_PRIVATE "")

if (ZLIB_FOUND)
- target_link_libraries(freetype PRIVATE ${ZLIB_LIBRARIES})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${ZLIB_LIBRARIES} is correct, but it's value is not optimized;...;debug;..., so different values are generated in INTERFACE_LINK_LIBRARIES in freetype-config.cmake, and vcpkg_fixup_cmake_targets deletes the debug freetype-config.cmake, which causes this problem.
We should avoid using the macros provided by cmake's module.

That means ZLIB requires a wrapper to correctly set that value on Linux. You are just dropping a droplet of water on a hot stone with that patch. You might have fixed freetype but all other ports using ZLIB_LIBRARIES still have the same problem. The root cause ist that ZLIB_LIBRARIES is not correctly set with debug/optimized keywords and needs fixing on Linux/OSX.

Copy link
Contributor Author

@JackBoosY JackBoosY Nov 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${ZLIB_LIBRARIES} is correct, but it's value is not optimized;...;debug;..., so different values are generated in INTERFACE_LINK_LIBRARIES in freetype-config.cmake, and vcpkg_fixup_cmake_targets deletes the debug freetype-config.cmake, which causes this problem.
We should avoid using the macros provided by cmake's module.

That means ZLIB requires a wrapper to correctly set that value on Linux. You are just dropping a droplet of water on a hot stone with that patch. You might have fixed freetype but all other ports using ZLIB_LIBRARIES still have the same problem. The root cause ist that ZLIB_LIBRARIES is not correctly set with debug/optimized keywords and needs fixing on Linux/OSX.

This means that all module modes(Find*.cmake) that call cmake by default have a high probability of this problem. So I think we should deal with it uniformly (by vcpkg, not by port).

+ target_link_libraries(freetype PRIVATE ZLIB::ZLIB)
target_include_directories(freetype PRIVATE ${ZLIB_INCLUDE_DIRS})
list(APPEND PKG_CONFIG_REQUIRED_PRIVATE "zlib")
endif ()
@@ -562,8 +562,15 @@ if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
install(
EXPORT freetype-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/freetype
- FILE freetype-config.cmake
COMPONENT headers)
+
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/freetype-config.cmake"
+[[include(CMakeFindDependencyMacro)
+find_dependency(ZLIB)
+include("${CMAKE_CURRENT_LIST_DIR}/freetype-targets.cmake")
+]])
+
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freetype-config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/freetype)
endif ()


34 changes: 16 additions & 18 deletions ports/freetype/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
set(FT_VERSION 2.10.2)
vcpkg_download_distfile(ARCHIVE
URLS "https://download-mirror.savannah.gnu.org/releases/freetype/freetype-${FT_VERSION}.tar.xz" "https://downloads.sourceforge.net/project/freetype/freetype2/${FT_VERSION}/freetype-${FT_VERSION}.tar.xz"
FILENAME "freetype-${FT_VERSION}.tar.xz"
SHA512 cf45089bd8893d7de2cdcb59d91bbb300e13dd0f0a9ef80ed697464ba7aeaf46a5a81b82b59638e6b21691754d8f300f23e1f0d11683604541d77f0f581affaa
)

vcpkg_extract_source_archive_ex(
vcpkg_from_sourceforge(
OUT_SOURCE_PATH SOURCE_PATH
ARCHIVE ${ARCHIVE}
REPO freetype/freetype2
REF ${FT_VERSION}
FILENAME freetype-${FT_VERSION}.tar.xz
SHA512 cf45089bd8893d7de2cdcb59d91bbb300e13dd0f0a9ef80ed697464ba7aeaf46a5a81b82b59638e6b21691754d8f300f23e1f0d11683604541d77f0f581affaa
PATCHES
0001-Fix-install-command.patch
0003-Fix-UWP.patch
pkgconfig.patch
brotli-static.patch
fix-exports.patch
)

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
Expand All @@ -36,6 +34,7 @@ vcpkg_configure_cmake(
)

vcpkg_install_cmake()
vcpkg_copy_pdbs()
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake/freetype)

# Rename for easy usage (VS integration; CMake and autotools will not care)
Expand All @@ -45,13 +44,13 @@ file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/include/freetype2)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)

# Fix the include dir [freetype2 -> freetype]
file(READ ${CURRENT_PACKAGES_DIR}/share/freetype/freetype-config.cmake CONFIG_MODULE)
file(READ ${CURRENT_PACKAGES_DIR}/share/freetype/freetype-targets.cmake CONFIG_MODULE)
string(REPLACE "\${_IMPORT_PREFIX}/include/freetype2" "\${_IMPORT_PREFIX}/include" CONFIG_MODULE "${CONFIG_MODULE}")
string(REPLACE "\${_IMPORT_PREFIX}/lib/brotlicommon-static.lib" [[\$<\$<NOT:\$<CONFIG:DEBUG>>:${_IMPORT_PREFIX}/lib/brotlicommon-static.lib>;\$<\$<CONFIG:DEBUG>:${_IMPORT_PREFIX}/debug/lib/brotlicommon-static.lib>]] CONFIG_MODULE "${CONFIG_MODULE}")
string(REPLACE "\${_IMPORT_PREFIX}/lib/brotlidec-static.lib" [[\$<\$<NOT:\$<CONFIG:DEBUG>>:${_IMPORT_PREFIX}/lib/brotlidec-static.lib>;\$<\$<CONFIG:DEBUG>:${_IMPORT_PREFIX}/debug/lib/brotlidec-static.lib>]] CONFIG_MODULE "${CONFIG_MODULE}")
string(REPLACE "\${_IMPORT_PREFIX}/lib/brotlidec.lib" [[\$<\$<NOT:\$<CONFIG:DEBUG>>:${_IMPORT_PREFIX}/lib/brotlidec.lib>;\$<\$<CONFIG:DEBUG>:${_IMPORT_PREFIX}/debug/lib/brotlidec.lib>]] CONFIG_MODULE "${CONFIG_MODULE}")
string(REPLACE "\${_IMPORT_PREFIX}/lib/brotlidec.lib" [[\$<\$<NOT:\$<CONFIG:DEBUG>>:${_IMPORT_PREFIX}/lib/brotlidec.lib>;\$<\$<CONFIG:DEBUG>:${_IMPORT_PREFIX}/debug/lib/brotlidec.lib>]] CONFIG_MODULE "${CONFIG_MODULE}")
file(WRITE ${CURRENT_PACKAGES_DIR}/share/freetype/freetype-config.cmake "${CONFIG_MODULE}")
file(WRITE ${CURRENT_PACKAGES_DIR}/share/freetype/freetype-targets.cmake "${CONFIG_MODULE}")

find_library(FREETYPE_DEBUG NAMES freetyped PATHS "${CURRENT_PACKAGES_DIR}/debug/lib/" NO_DEFAULT_PATH)
if(EXISTS "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/freetype2.pc")
Expand All @@ -67,20 +66,12 @@ if(EXISTS "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/freetype2.pc")
string(REPLACE "-I\${includedir}/freetype2" "-I\${includedir}" _contents "${_contents}")
file(WRITE "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/freetype2.pc" "${_contents}")
endif()

vcpkg_fixup_pkgconfig(SYSTEM_LIBRARIES m)

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

file(COPY
${SOURCE_PATH}/docs/FTL.TXT
${SOURCE_PATH}/docs/GPLv2.TXT
DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}
)
file(INSTALL ${SOURCE_PATH}/docs/LICENSE.TXT DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)

vcpkg_copy_pdbs()

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
if("bzip2" IN_LIST FEATURES)
set(USE_BZIP2 ON)
Expand All @@ -93,3 +84,10 @@ if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
configure_file(${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake
${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-cmake-wrapper.cmake @ONLY)
endif()

file(COPY
${SOURCE_PATH}/docs/FTL.TXT
${SOURCE_PATH}/docs/GPLv2.TXT
DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}
)
file(INSTALL ${SOURCE_PATH}/docs/LICENSE.TXT DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
2 changes: 1 addition & 1 deletion ports/libpng/CONTROL
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Source: libpng
Version: 1.6.37
Port-Version: 12
Port-Version: 13
Build-Depends: zlib
Homepage: https://github.com/glennrp/libpng
Description: libpng is a library implementing an interface for reading and writing PNG (Portable Network Graphics) format files.
Expand Down
65 changes: 65 additions & 0 deletions ports/libpng/fix-export-targets.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b45e878..19f8692 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -536,7 +536,7 @@ if(PNG_SHARED)
set_target_properties(png PROPERTIES PREFIX "lib")
set_target_properties(png PROPERTIES IMPORT_PREFIX "lib")
endif()
- target_link_libraries(png ${ZLIB_LIBRARY} ${M_LIBRARY})
+ target_link_libraries(png ZLIB::ZLIB ${M_LIBRARY})

if(UNIX AND AWK)
if(HAVE_LD_VERSION_SCRIPT)
@@ -564,7 +564,7 @@ if(PNG_STATIC)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(png_static PROPERTIES PREFIX "lib")
endif()
- target_link_libraries(png_static ${ZLIB_LIBRARY} ${M_LIBRARY})
+ target_link_libraries(png_static ZLIB::ZLIB ${M_LIBRARY})
endif()

if(PNG_FRAMEWORK)
@@ -581,7 +581,7 @@ if(PNG_FRAMEWORK)
XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
PUBLIC_HEADER "${libpng_public_hdrs}"
OUTPUT_NAME png)
- target_link_libraries(png_framework ${ZLIB_LIBRARY} ${M_LIBRARY})
+ target_link_libraries(png_framework ZLIB::ZLIB ${M_LIBRARY})
endif()

if(NOT PNG_LIB_TARGETS)
@@ -746,7 +746,7 @@ if(PNG_SHARED)
set(PNG_BIN_TARGETS pngfix)

add_executable(png-fix-itxt ${png_fix_itxt_sources})
- target_link_libraries(png-fix-itxt ${ZLIB_LIBRARY} ${M_LIBRARY})
+ target_link_libraries(png-fix-itxt ZLIB::ZLIB ${M_LIBRARY})
list(APPEND PNG_BIN_TARGETS png-fix-itxt)
endif()

@@ -851,7 +851,7 @@ endif()
# INSTALL
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
install(TARGETS ${PNG_LIB_TARGETS}
- EXPORT libpng
+ EXPORT libpng-targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
@@ -919,7 +919,14 @@ endif()

# Create an export file that CMake users can include() to import our targets.
if(NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL)
- install(EXPORT libpng DESTINATION lib/libpng FILE libpngConfig.cmake)
+ install(EXPORT libpng-targets DESTINATION lib/libpng)
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/libpng-config.cmake"
+ [[include(CMakeFindDependencyMacro)
+find_dependency(ZLIB)
+include("${CMAKE_CURRENT_LIST_DIR}/libpng-targets.cmake")
+ ]])
+
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng-config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpng)
endif()

# what's with libpng-manual.txt and all the extra files?
1 change: 1 addition & 0 deletions ports/libpng/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ vcpkg_from_github(
pkgconfig.patch
pkgconfig.2.patch
${APNG_EXTRA_PATCH}
fix-export-targets.patch
)

if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
Expand Down