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

[szip, hdf5] Fix mingw import lib names, control linkage #17941

Merged
merged 20 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 16 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
30 changes: 30 additions & 0 deletions ports/hdf5/mingw-import-libs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff -urw a/config/cmake_ext_mod/HDFMacros.cmake b/config/cmake_ext_mod/HDFMacros.cmake
--- a/config/cmake_ext_mod/HDFMacros.cmake 2020-03-03 00:03:12.000000000 +0100
+++ b/config/cmake_ext_mod/HDFMacros.cmake 2021-05-12 07:56:13.703041807 +0200
@@ -144,7 +144,7 @@
endif ()

#----- Use MSVC Naming conventions for Shared Libraries
- if (MINGW AND ${libtype} MATCHES "SHARED")
+ if (FALSE AND MINGW AND ${libtype} MATCHES "SHARED")
set_target_properties (${libtarget} PROPERTIES
IMPORT_SUFFIX ".lib"
IMPORT_PREFIX ""
@@ -168,7 +168,7 @@

if (${libtype} MATCHES "SHARED")
if (WIN32)
- if (MINGW)
+ if (FALSE AND MINGW)
set_target_properties (${libtarget} PROPERTIES
IMPORTED_IMPLIB "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${IMPORT_LIB_NAME}.lib"
IMPORTED_LOCATION "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${IMPORT_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}"
@@ -180,7 +180,7 @@
)
endif ()
else ()
- if (MINGW)
+ if (FALSE AND MINGW)
set_target_properties (${libtarget} PROPERTIES
IMPORTED_IMPLIB "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${IMPORT_LIB_NAME}.lib"
IMPORTED_LOCATION "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${IMPORT_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}"
48 changes: 48 additions & 0 deletions ports/hdf5/pkgconfig-requires.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
diff -urN a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt 2020-03-03 00:03:12.000000000 +0100
+++ b/CMakeLists.txt 2021-05-15 15:02:03.496210691 +0200
@@ -682,6 +682,9 @@
if (MPI_C_LINK_FLAGS)
set (CMAKE_EXE_LINKER_FLAGS "${MPI_C_LINK_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
endif ()
+ if(UNIX)
+ set(ompi-c_PC_LIBS_PRIVATE ${MPI_C_LIBRARIES})
+ endif()
endif ()

#option (DEFAULT_API_VERSION "Enable v1.12 API (v16, v18, v110, v112)" "v112")
diff -urN a/CMakeFilters.cmake b/CMakeFilters.cmake
--- a/CMakeFilters.cmake 2020-03-03 00:03:12.000000000 +0100
+++ b/CMakeFilters.cmake 2021-05-15 12:35:58.453641554 +0200
@@ -55,6 +55,7 @@
if (ZLIB_FOUND)
set (LINK_COMP_LIBS ${LINK_COMP_LIBS} ${ZLIB_LIBRARIES})
set (LINK_COMP_SHARED_LIBS ${LINK_COMP_SHARED_LIBS} ${ZLIB_LIBRARIES})
+ set (zlib_PC_LIBS_PRIVATE "${ZLIB_LIBRARIES}")
endif ()
endif ()
endif ()
@@ -130,6 +131,7 @@
set (LINK_COMP_SHARED_LIBS ${LINK_COMP_SHARED_LIBS} ${SZIP_SHARED_LIBRARY})
endif ()
set (LINK_COMP_LIBS ${LINK_COMP_LIBS} ${SZIP_STATIC_LIBRARY})
+ set (szip_PC_LIBS_PRIVATE "${SZIP_STATIC_LIBRARY}")
INCLUDE_DIRECTORIES (${SZIP_INCLUDE_DIRS})
message (STATUS "Filter SZIP is ON")
if (H5_HAVE_FILTER_SZIP)
diff -urN a/src/CMakeLists.txt b/src/CMakeLists.txt
--- a/src/CMakeLists.txt 2020-03-03 00:03:12.000000000 +0100
+++ b/src/CMakeLists.txt 2021-05-15 12:41:34.762354040 +0200
@@ -1259,6 +1259,12 @@

set (_PKG_CONFIG_REQUIRES)
set (_PKG_CONFIG_REQUIRES_PRIVATE)
+foreach(_module IN ITEMS ompi-c szip zlib)
+ if(${_module}_PC_LIBS_PRIVATE)
+ string(REPLACE " -l${${_module}_PC_LIBS_PRIVATE}" "" _PKG_CONFIG_LIBS_PRIVATE "${_PKG_CONFIG_LIBS_PRIVATE}")
+ string(APPEND _PKG_CONFIG_REQUIRES_PRIVATE " ${_module}")
+ endif()
+endforeach()

configure_file (
${HDF_RESOURCES_DIR}/libhdf5.pc.in
52 changes: 19 additions & 33 deletions ports/hdf5/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ vcpkg_from_github(
SHA512 d84df1ea72dc6fa038440a370e1b1ff523364474e7f214b967edc26d3191b2ef4fe1d9273c4a086a5945f1ad1ab6aa8dbcda495898e7967b2b73fd93dd5071e0
HEAD_REF develop
PATCHES
hdf5_config.patch
szip.patch
hdf5_config.patch
szip.patch
mingw-import-libs.patch
pkgconfig-requires.patch
)

if ("parallel" IN_LIST FEATURES AND "cpp" IN_LIST FEATURES)
Expand All @@ -22,15 +24,15 @@ if ("fortran" IN_LIST FEATURE)
endif()

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES # <- Keyword FEATURES is required because INVERTED_FEATURES are being used
parallel HDF5_ENABLE_PARALLEL
tools HDF5_BUILD_TOOLS
cpp HDF5_BUILD_CPP_LIB
szip HDF5_ENABLE_SZIP_SUPPORT
szip HDF5_ENABLE_SZIP_ENCODING
zlib HDF5_ENABLE_Z_LIB_SUPPORT
fortran HDF5_BUILD_FORTRAN
threadsafe HDF5_ENABLE_THREADSAFE
FEATURES
parallel HDF5_ENABLE_PARALLEL
tools HDF5_BUILD_TOOLS
cpp HDF5_BUILD_CPP_LIB
szip HDF5_ENABLE_SZIP_SUPPORT
szip HDF5_ENABLE_SZIP_ENCODING
zlib HDF5_ENABLE_Z_LIB_SUPPORT
fortran HDF5_BUILD_FORTRAN
threadsafe HDF5_ENABLE_THREADSAFE
)

file(REMOVE "${SOURCE_PATH}/config/cmake_ext_mod/FindSZIP.cmake")#Outdated; does not find debug szip
Expand All @@ -45,11 +47,9 @@ if(NOT VCPKG_LIBRARY_LINKAGE STREQUAL "static")
-DONLY_SHARED_LIBS=ON)
endif()

find_library(SZIP_RELEASE NAMES libsz libszip szip sz PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH)
find_library(SZIP_DEBUG NAMES libsz libszip szip sz libsz_D libszip_D szip_D sz_D szip_debug PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH)

vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
DISABLE_PARALLEL_CONFIGURE
PREFER_NINJA
OPTIONS
Expand All @@ -61,10 +61,10 @@ vcpkg_configure_cmake(
-DHDF_PACKAGE_NAMESPACE:STRING=hdf5::
)

vcpkg_install_cmake()

vcpkg_cmake_install()
vcpkg_copy_pdbs()
vcpkg_fixup_cmake_targets()
vcpkg_cmake_config_fixup()

set(debug_suffix debug)
if(VCPKG_TARGET_IS_WINDOWS)
set(debug_suffix D)
Expand Down Expand Up @@ -119,20 +119,6 @@ foreach(PC_FILE IN LISTS PKG_FILES)
endforeach()
endforeach()
vcpkg_fixup_pkgconfig()
if(EXISTS "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/hdf5.pc")
vcpkg_replace_string(
"${CURRENT_PACKAGES_DIR}/lib/pkgconfig/hdf5.pc"
"-loptimized -l\"\${prefix}/lib/zlib.lib\" -ldebug -l\"\${prefix}/debug/lib/zlibd.lib\""
"-lzlib"
)
endif()
if(EXISTS "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/hdf5.pc")
vcpkg_replace_string(
"${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/hdf5.pc"
"-loptimized -l\"\${prefix}/lib/zlib.lib\" -ldebug -l\"\${prefix}/lib/zlibd.lib\""
"-lzlibd"
)
endif()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")

Expand All @@ -155,7 +141,7 @@ if(FEATURES MATCHES "tools")
endif()
if(EXISTS "${CURRENT_PACKAGES_DIR}/bin/${tool}${suffix}")
file(INSTALL "${CURRENT_PACKAGES_DIR}/bin/${tool}${suffix}"
DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}")
DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}")
file(REMOVE "${CURRENT_PACKAGES_DIR}/bin/${tool}${suffix}")
endif()
endforeach()
Expand Down
25 changes: 14 additions & 11 deletions ports/hdf5/szip.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
diff --git a/CMakeFilters.cmake b/CMakeFilters.cmake
index 5a8956456..997bb8e81 100644
--- a/CMakeFilters.cmake
+++ b/CMakeFilters.cmake
@@ -100,7 +100,7 @@ option (HDF5_ENABLE_SZIP_SUPPORT "Use SZip Filter" OFF)
if (HDF5_ENABLE_SZIP_SUPPORT)
option (HDF5_ENABLE_SZIP_ENCODING "Use SZip Encoding" OFF)
if (NOT SZIP_USE_EXTERNAL)
- find_package (SZIP NAMES ${SZIP_PACKAGE_NAME}${HDF_PACKAGE_EXT} COMPONENTS static shared)
+ find_package (SZIP NAMES ${SZIP_PACKAGE_NAME}${HDF_PACKAGE_EXT})
diff -urN a/CMakeFilters.cmake b/CMakeFilters.cmake
--- a/CMakeFilters.cmake 2021-05-15 19:07:48.160044927 +0200
+++ b/CMakeFilters.cmake 2021-05-15 19:22:56.993970332 +0200
@@ -104,7 +104,11 @@
find_package (SZIP NAMES ${SZIP_PACKAGE_NAME}${HDF_PACKAGE_EXT} COMPONENTS static shared)
if (NOT SZIP_FOUND)
find_package (SZIP) # Legacy find
if (SZIP_FOUND)
- if (SZIP_FOUND)
+ if (DEFINED SZIP_SHARED_LIBRARY AND NOT DEFINED SZIP_STATIC_LIBRARY)
+ set (SZIP_STATIC_LIBRARY "${SZIP_SHARED_LIBRARY}")
+ elseif (DEFINED SZIP_STATIC_LIBRARY AND NOT DEFINED SZIP_SHARED_LIBRARY)
+ set (SZIP_SHARED_LIBRARY "${SZIP_STATIC_LIBRARY}")
+ elseif (SZIP_FOUND)
set (LINK_COMP_LIBS ${LINK_COMP_LIBS} ${SZIP_LIBRARIES})
set (LINK_COMP_SHARED_LIBS ${LINK_COMP_SHARED_LIBS} ${SZIP_LIBRARIES})
endif ()
12 changes: 11 additions & 1 deletion ports/hdf5/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
{
"name": "hdf5",
"version": "1.12.0",
"port-version": 2,
"port-version": 3,
"description": "HDF5 is a data model, library, and file format for storing and managing data",
"homepage": "https://www.hdfgroup.org/downloads/hdf5/",
"supports": "!uwp",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
],
"default-features": [
"szip",
"zlib"
Expand Down
4 changes: 0 additions & 4 deletions ports/szip/CONTROL

This file was deleted.

47 changes: 47 additions & 0 deletions ports/szip/fix-linkage-config.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
diff -urN a/config/cmake/szip-config.cmake.in b/config/cmake/szip-config.cmake.in
--- a/config/cmake/szip-config.cmake.in 2017-01-09 16:14:35.000000000 +0100
+++ b/config/cmake/szip-config.cmake.in 2021-05-14 21:26:09.490134839 +0200
@@ -39,8 +39,13 @@

# Handle default component(static) :
if (NOT ${SZIP_PACKAGE_NAME}_FIND_COMPONENTS)
+ if(@BUILD_SHARED_LIBS@)
+ set (${SZIP_PACKAGE_NAME}_FIND_COMPONENTS shared)
+ set (${SZIP_PACKAGE_NAME}_FIND_REQUIRED_shared true)
+ else()
set (${SZIP_PACKAGE_NAME}_FIND_COMPONENTS static)
set (${SZIP_PACKAGE_NAME}_FIND_REQUIRED_static true)
+ endif()
endif ()

# Handle requested components:
diff -urN a/src/CMakeLists.txt b/src/CMakeLists.txt
--- a/src/CMakeLists.txt 2017-02-03 20:42:43.000000000 +0100
+++ b/src/CMakeLists.txt 2021-05-14 22:20:28.237632925 +0200
@@ -22,6 +22,7 @@
${SZIP_SRC_SOURCE_DIR}/szlib.h
)

+if(NOT BUILD_SHARED_LIBS)
add_library (${SZIP_LIB_TARGET} STATIC ${SZIP_SRCS} ${SZIP_PUBLIC_HEADERS})
#set_target_properties (${SZIP_LIB_TARGET}
# PROPERTIES
@@ -36,6 +37,7 @@
set_global_variable (SZIP_LIBRARIES_TO_EXPORT ${SZIP_LIB_TARGET})
SZIP_SET_LIB_OPTIONS (${SZIP_LIB_TARGET} ${SZIP_LIB_NAME} STATIC)
set (install_targets ${SZIP_LIB_TARGET})
+endif(NOT BUILD_SHARED_LIBS)

if (BUILD_SHARED_LIBS)
add_library (${SZIP_LIBSH_TARGET} SHARED ${SZIP_SRCS} ${SZIP_PUBLIC_HEADERS})
@@ -62,8 +64,9 @@
if (SZIP_EXPORTED_TARGETS)
if (BUILD_SHARED_LIBS)
INSTALL_TARGET_PDB (${SZIP_LIBSH_TARGET} ${SZIP_INSTALL_BIN_DIR} libraries)
- endif (BUILD_SHARED_LIBS)
+ else()
INSTALL_TARGET_PDB (${SZIP_LIB_TARGET} ${SZIP_INSTALL_BIN_DIR} libraries)
+ endif()

install (
TARGETS
11 changes: 0 additions & 11 deletions ports/szip/fix-szip-config-to-set-szip-found.patch

This file was deleted.

30 changes: 30 additions & 0 deletions ports/szip/mingw-lib-names.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff -urN a/config/cmake/SZIPMacros.cmake b/config/cmake/SZIPMacros.cmake
--- a/config/cmake/SZIPMacros.cmake 2021-05-15 09:06:50.546455249 +0200
+++ b/config/cmake/SZIPMacros.cmake 2021-05-15 09:01:24.933765423 +0200
@@ -126,7 +126,7 @@
macro (SZIP_SET_BASE_OPTIONS libtarget libname libtype)
# message (STATUS "${libname} libtype: ${libtype}")
if (${libtype} MATCHES "SHARED")
- if (WIN32)
+ if (WIN32 AND NOT MINGW)
set (LIB_RELEASE_NAME "${libname}")
set (LIB_DEBUG_NAME "${libname}_D")
else ()
@@ -134,7 +134,7 @@
set (LIB_DEBUG_NAME "${libname}_debug")
endif ()
else ()
- if (WIN32)
+ if (WIN32 AND NOT MINGW)
set (LIB_RELEASE_NAME "lib${libname}")
set (LIB_DEBUG_NAME "lib${libname}_D")
else ()
@@ -164,7 +164,7 @@
endif ()

#----- Use MSVC Naming conventions for Shared Libraries
- if (MINGW AND ${libtype} MATCHES "SHARED")
+ if (FALSE AND MINGW AND ${libtype} MATCHES "SHARED")
set_target_properties (${libtarget}
PROPERTIES
IMPORT_SUFFIX ".lib"
57 changes: 45 additions & 12 deletions ports/szip/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,30 +1,63 @@
set(SZIP_VERSION "2.1.1")
vcpkg_download_distfile(ARCHIVE
URLS "https://support.hdfgroup.org/ftp/lib-external/szip/2.1.1/src/szip-2.1.1.tar.gz"
FILENAME "szip-2.1.1.tar.gz"
URLS "https://support.hdfgroup.org/ftp/lib-external/szip/${SZIP_VERSION}/src/szip-${SZIP_VERSION}.tar.gz"
FILENAME "szip-${SZIP_VERSION}.tar.gz"
SHA512 ada6406efb096cd8a2daf8f9217fe9111a96dcae87e29d1c31f58ddd2ad2aa7bac03f23c7205dc9360f3b62d259461759330c7189ef0c2fe559704b1ea9d40dd
)

vcpkg_extract_source_archive_ex(
OUT_SOURCE_PATH SOURCE_PATH
ARCHIVE ${ARCHIVE}
REF szip-2.1.1
ARCHIVE "${ARCHIVE}"
REF szip-${SZIP_VERSION}
PATCHES
fix-szip-config-to-set-szip-found.patch # This patch is required for linux on osx; It does not matter for windows
fix-linkage-config.patch
mingw-lib-names.patch
)

vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
PREFER_NINJA
OPTIONS
-DSZIP_INSTALL_DATA_DIR=share/szip/data
-DSZIP_INSTALL_CMAKE_DIR=share/szip
)

vcpkg_install_cmake()
vcpkg_cmake_install()
vcpkg_copy_pdbs()
vcpkg_fixup_cmake_targets()
vcpkg_cmake_config_fixup()

file(RENAME ${CURRENT_PACKAGES_DIR}/share/szip/data/COPYING ${CURRENT_PACKAGES_DIR}/share/szip/copyright)
if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/szip_adpt.h"
"\n#ifdef SZ_BUILT_AS_DYNAMIC_LIB"
"\n#ifndef SZ_BUILT_AS_DYNAMIC_LIB\n#define SZ_BUILT_AS_DYNAMIC_LIB 1\n#endif\n#ifdef SZ_BUILT_AS_DYNAMIC_LIB")
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
endif()

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
if(NOT VCPKG_TARGET_IS_WINDOWS)
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
set(SZIP_LIB_RELEASE "-lszip")
set(SZIP_LIB_DEBUG "-lszip_debug")
set(SZIP_LIBS_PRIVATE "-lm")
elseif(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
set(SZIP_LIB_RELEASE "-llibszip")
set(SZIP_LIB_DEBUG "-llibszip_D")
set(SZIP_LIBS_PRIVATE )
else()
set(SZIP_LIB_RELEASE "-lszip")
set(SZIP_LIB_DEBUG "-lszip_D")
set(SZIP_LIBS_PRIVATE )
endif()
if(EXISTS "${CURRENT_PACKAGES_DIR}/lib")
set(SZIP_LIB "${SZIP_LIB_RELEASE}")
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/lib/pkgconfig")
configure_file("${CMAKE_CURRENT_LIST_DIR}/szip.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/szip.pc" @ONLY)
endif()
if(EXISTS "${CURRENT_PACKAGES_DIR}/debug/lib")
set(SZIP_LIB "${SZIP_LIB_DEBUG}")
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig")
configure_file("${CMAKE_CURRENT_LIST_DIR}/szip.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/szip.pc" @ONLY)
endif()
vcpkg_fixup_pkgconfig()

file(RENAME "${CURRENT_PACKAGES_DIR}/share/szip/data/COPYING" "${CURRENT_PACKAGES_DIR}/share/szip/copyright")

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