Skip to content

Commit

Permalink
[netcdf-c] Fix pc files; use features (#18120)
Browse files Browse the repository at this point in the history
* Format manifest

* New port-version

* Quote filepath expressions

* Port to vcpkg-cmake ports

* Remove invalid nc-config file

* Fix pc files

* Use features

* Add feature 'tools'

* x-add-version

* Fix build with msys2 mingw

* Update git-tree
  • Loading branch information
dg0yt authored Jun 29, 2021
1 parent 6cdc26c commit e2d1022
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 36 deletions.
6 changes: 0 additions & 6 deletions ports/netcdf-c/CONTROL

This file was deleted.

15 changes: 0 additions & 15 deletions ports/netcdf-c/config-pkg-location.patch

This file was deleted.

13 changes: 13 additions & 0 deletions ports/netcdf-c/fix-dependency-zlib.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/liblib/CMakeLists.txt b/liblib/CMakeLists.txt
index 5b578f7..0731460 100644
--- a/liblib/CMakeLists.txt
+++ b/liblib/CMakeLists.txt
@@ -58,7 +58,7 @@ ENDIF()

SET(TLL_LIBS "")

-SET(TLL_LIBS ${TLL_LIBS} ${HAVE_LIBM} ZLIB::ZLIB)
+SET(TLL_LIBS ${TLL_LIBS} ${HAVE_LIBM})

# Add extra dependencies specified via NC_EXTRA_DEPS
SET(TLL_LIBS ${TLL_LIBS} ${EXTRA_DEPS})
13 changes: 13 additions & 0 deletions ports/netcdf-c/fix-manpage-msys.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/libsrc/CMakeLists.txt b/libsrc/CMakeLists.txt
index 65a3f87..30a008d 100644
--- a/libsrc/CMakeLists.txt
+++ b/libsrc/CMakeLists.txt
@@ -61,7 +61,7 @@ IF(HAVE_M4)
IF(NOT MSVC)
ADD_CUSTOM_TARGET(manpage ALL

- COMMAND ${NC_M4} ${ARGS_MANPAGE} '${CMAKE_CURRENT_BINARY_DIR}/netcdf.m4' > '${CMAKE_CURRENT_BINARY_DIR}/netcdf.3'
+ COMMAND ${NC_M4} ${ARGS_MANPAGE} "${CMAKE_CURRENT_BINARY_DIR}/netcdf.m4" > "${CMAKE_CURRENT_BINARY_DIR}/netcdf.3" VERBATIM
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

37 changes: 37 additions & 0 deletions ports/netcdf-c/fix-pkgconfig.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 57d2d4b..3de6f8c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1892,6 +1892,20 @@ LIST(REMOVE_DUPLICATES LINKFLAGS)
SET(LIBS ${NC_LIBS})
SET(NC_LIBS "-lnetcdf")

+set(NC_LIBS_PRIVATE " ${LIBS} ")
+set(NC_REQUIRES_PRIVATE "")
+macro(replace_pkgconfig_module PATTERN MODULE)
+ if(NC_LIBS_PRIVATE MATCHES " ${PATTERN} ")
+ string(REPLACE "${CMAKE_MATCH_0}" " " NC_LIBS_PRIVATE "${NC_LIBS_PRIVATE}")
+ string(APPEND NC_REQUIRES_PRIVATE " ${MODULE}")
+ endif()
+endmacro()
+replace_pkgconfig_module("-lhdf5_hl" "hdf5_hl")
+replace_pkgconfig_module("-lhdf5" "hdf5")
+replace_pkgconfig_module("-lmpi" "ompi-c")
+replace_pkgconfig_module("-lCURL[^ ]*" "libcurl")
+replace_pkgconfig_module("-lZLIB[^ ]*" "zlib")
+
configure_file(
${netCDF_SOURCE_DIR}/netcdf.pc.in
${netCDF_BINARY_DIR}/netcdf.pc @ONLY)
diff --git a/netcdf.pc.in b/netcdf.pc.in
index 22b5594..a48b7c2 100644
--- a/netcdf.pc.in
+++ b/netcdf.pc.in
@@ -9,5 +9,6 @@ Description: NetCDF Client Library for C
URL: http://www.unidata.ucar.edu/netcdf
Version: @PACKAGE_VERSION@
Libs: -L${libdir} @NC_LIBS@
-Libs.private: @LIBS@
+Libs.private: @NC_LIBS_PRIVATE@
Cflags: -I${includedir}
+Requires.private: @NC_REQUIRES_PRIVATE@
45 changes: 31 additions & 14 deletions ports/netcdf-c/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ vcpkg_from_github(
HEAD_REF master
PATCHES
no-install-deps.patch
config-pkg-location.patch
use_targets.patch
fix-dependency-libmath.patch
fix-linkage-error.patch
fix-pkgconfig.patch
fix-dependency-zlib.patch
fix-manpage-msys.patch
)

#Remove outdated find modules
Expand All @@ -23,31 +25,46 @@ else()
set(NC_USE_STATIC_CRT OFF)
endif()

vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
dap ENABLE_DAP
netcdf-4 ENABLE_NETCDF_4
netcdf-4 USE_HDF5
tools BUILD_UTILITIES
INVERTED_FEATURES
dap CMAKE_DISABLE_FIND_PACKAGE_CURL
netcdf-4 CMAKE_DISABLE_FIND_PACKAGE_HDF5
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
DISABLE_PARALLEL_CONFIGURE # netcdf-c configures in the source!
PREFER_NINJA
OPTIONS
-DBUILD_UTILITIES=OFF
-DBUILD_TESTING=OFF
-DENABLE_EXAMPLES=OFF
-DENABLE_TESTS=OFF
-DENABLE_FILTER_TESTING=OFF
-DUSE_HDF5=ON
-DENABLE_DAP_REMOTE_TESTS=OFF
-DDISABLE_INSTALL_DEPENDENCIES=ON
-DNC_USE_STATIC_CRT=${NC_USE_STATIC_CRT}
-DConfigPackageLocation=share/netcdf
${FEATURE_OPTIONS}
)

vcpkg_install_cmake()
vcpkg_fixup_cmake_targets(CONFIG_PATH share/netcdf TARGET_PATH share/netcdf)
vcpkg_cmake_install()
vcpkg_cmake_config_fixup(PACKAGE_NAME "netcdf" CONFIG_PATH "lib/cmake/netCDF")
vcpkg_fixup_pkgconfig()

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/bin ${CURRENT_PACKAGES_DIR}/bin)
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/bin/nc-config" "${CURRENT_PACKAGES_DIR}/bin/nc-config") # invalid
if("tools" IN_LIST FEATURES)
vcpkg_copy_tools(
TOOL_NAMES nccopy ncdump ncgen ncgen3
AUTO_CLEAN
)
elseif(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/bin" "${CURRENT_PACKAGES_DIR}/bin")
endif()

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

file(INSTALL ${SOURCE_PATH}/COPYRIGHT DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
file(INSTALL "${SOURCE_PATH}/COPYRIGHT" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
43 changes: 43 additions & 0 deletions ports/netcdf-c/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "netcdf-c",
"version-string": "4.7.4",
"port-version": 3,
"description": "A set of self-describing, machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data.",
"homepage": "https://github.com/Unidata/netcdf-c",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
],
"default-features": [
"dap",
"netcdf-4"
],
"features": {
"dap": {
"description": "Build with DAP remote access client support",
"dependencies": [
"curl"
]
},
"netcdf-4": {
"description": "Build with netCDF-4/HDF5 support",
"dependencies": [
{
"name": "hdf5",
"features": [
"zlib"
]
}
]
},
"tools": {
"description": "Build utilities"
}
}
}
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -4290,7 +4290,7 @@
},
"netcdf-c": {
"baseline": "4.7.4",
"port-version": 2
"port-version": 3
},
"netcdf-cxx4": {
"baseline": "4.3.1",
Expand Down
5 changes: 5 additions & 0 deletions versions/n-/netcdf-c.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "069ccb40f8ce75d6ec88b8fe31966c11fcf6906b",
"version-string": "4.7.4",
"port-version": 3
},
{
"git-tree": "aa42781f00db0c2de52798f0345801b667977c79",
"version-string": "4.7.4",
Expand Down

0 comments on commit e2d1022

Please sign in to comment.