Skip to content

Commit fb75ad6

Browse files
authored
Merge pull request #3034 from DennisHeimbigner/minpluginx.dmh
Extend the netcdf API to support programmatic changes to the plugin search path
2 parents f67f25c + 818f56d commit fb75ad6

96 files changed

Lines changed: 4109 additions & 2658 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/main-cmake.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: NetCDF-C CMake CI - Windows
22

3-
on: [pull_request, workflow_dispatch]
3+
on: [ pull_request, workflow_dispatch]
44

55
env:
66
REMOTETESTDOWN: ${{ vars.REMOTETESTDOWN }}

CMakeLists.txt

Lines changed: 60 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ if (NOT DEFINED NETCDF_IS_TOP_LEVEL)
5454
endif ()
5555
endif ()
5656

57-
5857
################################
5958
# The target
6059
################################
@@ -72,8 +71,6 @@ endif()
7271
add_library(netcdf)
7372
add_library(netCDF::netcdf ALIAS netcdf)
7473

75-
76-
7774
# Version of the dispatch table. This must match the value in
7875
# configure.ac.
7976
set(NC_DISPATCH_VERSION 5)
@@ -363,12 +360,12 @@ endif()
363360
set(DEFAULT_CHUNK_SIZE 16777216 CACHE STRING "Default Chunk Cache Size.")
364361
set(DEFAULT_CHUNK_CACHE_SIZE 16777216U CACHE STRING "Default Chunk Cache Size.")
365362
set(DEFAULT_CHUNKS_IN_CACHE 1000 CACHE STRING "Default number of chunks in cache.")
366-
set(DEFAULT_CHUNK_CACHE_PREEMPTION 0.75 CACHE STRING "Default file chunk cache preemption policy (a number between 0 and 1, inclusive.")
363+
set(DEFAULT_CHUNK_CACHE_PREEMPTION 0.75 CACHE STRING "Default file chunk cache preemption policy (a number between 0 and 1, inclusive).")
367364

368365
# HDF5 default cache size values
369366
set(CHUNK_CACHE_SIZE ${DEFAULT_CHUNK_CACHE_SIZE} CACHE STRING "Default HDF5 Chunk Cache Size.")
370367
set(CHUNK_CACHE_NELEMS ${DEFAULT_CHUNKS_IN_CACHE} CACHE STRING "Default maximum number of elements in cache.")
371-
set(CHUNK_CACHE_PREEMPTION ${DEFAULT_CHUNK_CACHE_PREEMPTION} CACHE STRING "Default file chunk cache preemption policy for HDf5 files(a number between 0 and 1, inclusive.")
368+
set(CHUNK_CACHE_PREEMPTION ${DEFAULT_CHUNK_CACHE_PREEMPTION} CACHE STRING "Default file chunk cache preemption policy for HDf5 files(a number between 0 and 1, inclusive.)")
372369

373370
set(NETCDF_LIB_NAME "" CACHE STRING "Default name of the netcdf library.")
374371
set(TEMP_LARGE "." CACHE STRING "Where to put large temp files if large file tests are run.")
@@ -629,76 +626,66 @@ option(NETCDF_ENABLE_FILTER_BZ2 "Enable use of Bz2 compression library if it i
629626
option(NETCDF_ENABLE_FILTER_BLOSC "Enable use of blosc compression library if it is available." ON)
630627
option(NETCDF_ENABLE_FILTER_ZSTD "Enable use of Zstd compression library if it is available." ON)
631628

632-
# If user wants, then install selected plugins (default on)
633-
set(NETCDF_PLUGIN_INSTALL_DIR "YES" CACHE STRING "Whether and where we should install plugins; defaults to yes")
634-
if(NOT NETCDF_ENABLE_PLUGINS)
635-
unset(NETCDF_PLUGIN_INSTALL_DIR CACHE)
636-
endif()
629+
# If user wants, then install selected plugins (default off)
630+
option(NETCDF_PLUGIN_INSTALL "Enable plugin installation" NO)
637631

638-
# This is ugly, but seems necessary because of CMake's boolean structure
639-
set(boolval FALSE)
640-
if(DEFINED NETCDF_PLUGIN_INSTALL_DIR)
641-
booleanize(${NETCDF_PLUGIN_INSTALL_DIR} boolval)
642-
if(boolval)
643-
set(ENABLE_PLUGIN_INSTALL YES)
644-
# No actual value was specified
645-
unset(NETCDF_PLUGIN_INSTALL_DIR CACHE)
646-
else()
647-
if(boolval STREQUAL "NOTFOUND")
648-
# Must be an actual value
649-
set(ENABLE_PLUGIN_INSTALL YES)
650-
else()
651-
set(ENABLE_PLUGIN_INSTALL NO)
652-
endif()
653-
endif()
632+
# Note: the term PLATFORMDEFAULT stands for:
633+
# -- /usr/loca/hdf5/lib/plugin If on a *nix* machine
634+
# -- %ALLUSERSPROFILE%/hdf5/lib/plugins If on a windows or Mingw platform
635+
if(ISMSVC OR ISMINGW)
636+
set(PLATFORMDEFAULT "$ENV{ALLUSERSPROFILE}\\hdf5\\lib\\plugin")
637+
set(PLATFORMSEP ";")
654638
else()
655-
set(ENABLE_PLUGIN_INSTALL NO)
656-
endif()
657-
658-
# Ensure no defined plugin dir if not enabled
659-
if(NOT ENABLE_PLUGIN_INSTALL)
660-
unset(NETCDF_PLUGIN_INSTALL_DIR CACHE)
661-
endif()
662-
663-
if(ENABLE_PLUGIN_INSTALL)
664-
if(NOT DEFINED NETCDF_PLUGIN_INSTALL_DIR)
665-
# Default to HDF5_PLUGIN_PATH or its default directories
666-
if(DEFINED ENV{HDF5_PLUGIN_PATH})
667-
set(NETCDF_PLUGIN_INSTALL_DIR "$ENV{HDF5_PLUGIN_PATH}")
668-
else()
669-
if(ISMSVC OR ISMINGW)
670-
set(NETCDF_PLUGIN_INSTALL_DIR "$ENV{ALLUSERSPROFILE}\\hdf5\\lib\\plugin")
671-
else()
672-
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
673-
set(NETCDF_PLUGIN_INSTALL_DIR "/usr/local/hdf5/lib/plugin")
674-
else()
675-
set(NETCDF_PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/hdf5/lib/plugin")
676-
endif(NOT DEFINED CMAKE_INSTALL_PREFIX)
677-
endif(ISMSVC OR ISMINGW)
678-
endif(DEFINED ENV{HDF5_PLUGIN_PATH})
679-
message(STATUS "Defaulting to -DPLUGIN_INSTALL_DIR=${NETCDF_PLUGIN_INSTALL_DIR}")
680-
endif()
681-
endif(ENABLE_PLUGIN_INSTALL)
639+
set(PLATFORMDEFAULT "/usr/local/hdf5/lib/plugin")
640+
set(PLATFORMSEP ":")
641+
endif()
682642

683-
if(ENABLE_PLUGIN_INSTALL)
684-
# Use the lowest priority dir in the path
685-
if(NOT ISMSVC AND NOT ISMINGW)
686-
string(REPLACE ":" ";" PATH_LIST ${NETCDF_PLUGIN_INSTALL_DIR})
687-
else()
688-
set(PATH_LIST ${NETCDF_PLUGIN_INSTALL_DIR})
689-
endif()
643+
# Internally, the variable DEFAULT_PLUGIN_INSTALL_DIR is the default
644+
# directory into which plugins are installed; this may be undefined if
645+
# plugin installation is disabled (the usual case). It is exported as
646+
# NETCDF_DEFAULT_PLUGIN_INSTALL_DIR.
647+
#
648+
# Similarly the variable DEFAULT_PLUGIN_SEARCH_PATH is the default list
649+
# of directories to search to locate plugins.
650+
#
651+
# See configure.ac to see a table defining the rules for computing these two variables.
690652

691-
# Get last element
692-
list(GET PATH_LIST -1 NETCDF_PLUGIN_INSTALL_DIR)
693-
set(PLUGIN_INSTALL_DIR_SETTING "${NETCDF_PLUGIN_INSTALL_DIR}")
694-
message(STATUS "Final value of-DPLUGIN_INSTALL_DIR=${NETCDF_PLUGIN_INSTALL_DIR}")
695-
else() # No option specified
696-
unset(NETCDF_PLUGIN_INSTALL_DIR)
697-
unset(NETCDF_PLUGIN_INSTALL_DIR CACHE)
698-
set(PLUGIN_INSTALL_DIR_SETTING "N.A.")
653+
# Inferences about plugins
654+
655+
if(NETCDF_WITH_PLUGIN_DIR)
656+
set(NETCDF_ENABLE_PLUGINS yes)
699657
endif()
658+
# canonical form is all forward slashes
659+
string(REPLACE "\\" "/" DEFAULT_PLUGIN_INSTALL_DIR "${DEFAULT_PLUGIN_INSTALL_DIR}")
660+
string(REPLACE "\\" "/" DEFAULT_PLUGIN_SEARCH_PATH "${DEFAULT_PLUGIN_SEARCH_PATH}")
700661

701-
message(STATUS "ENABLE_PLUGIN_INSTALL=${ENABLE_PLUGIN_INSTALL} PLUGIN_INSTALL_DIR=${NETCDF_PLUGIN_INSTALL_DIR}")
662+
if(NOT NETCDF_ENABLE_PLUGINS)
663+
unset(NETCDF_PLUGIN_INSTALL)
664+
unset(NETCDF_WITH_PLUGIN_DIR)
665+
endif()
666+
667+
if (DEFINED NETCDF_WITH_PLUGIN_DIR) # Table row 3
668+
set(DEFAULT_PLUGIN_INSTALL_DIR "${NETCDF_WITH_PLUGIN_DIR}")
669+
set(DEFAULT_PLUGIN_SEARCH_PATH "${NETCDF_WITH_PLUGIN_DIR}${PLATFORMSEP}${PLATFORMDEFAULT}")
670+
elseif (DEFINED CMAKE_INSTALL_PREFIX) # Table row 2
671+
set(DEFAULT_PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/hdf5/lib/plugin")
672+
set(DEFAULT_PLUGIN_SEARCH_PATH "${DEFAULT_PLUGIN_INSTALL_DIR}${PLATFORMSEP}${PLATFORMDEFAULT}")
673+
else() # Table row 1
674+
unset(DEFAULT_PLUGIN_INSTALL_DIR)
675+
set(DEFAULT_PLUGIN_SEARCH_PATH "${PLATFORMDEFAULT}")
676+
endif()
677+
# canonical form is all forward slashes
678+
string(REPLACE "\\" "/" DEFAULT_PLUGIN_INSTALL_DIR "${DEFAULT_PLUGIN_INSTALL_DIR}")
679+
string(REPLACE "\\" "/" DEFAULT_PLUGIN_SEARCH_PATH "${DEFAULT_PLUGIN_SEARCH_PATH}")
680+
681+
# Inferences
682+
if (DEFINED DEFAULT_PLUGIN_INSTALL_DIR)
683+
set(ENABLE_PLUGIN_DIR yes)
684+
else()
685+
set(ENABLE_PLUGIN_DIR no)
686+
endif()
687+
set(NETCDF_PLUGIN_INSTALL_DIR "${DEFAULT_PLUGIN_INSTALL_DIR}")
688+
set(NETCDF_PLUGIN_SEARCH_PATH "${DEFAULT_PLUGIN_SEARCH_PATH}")
702689

703690
# Try to enable NCZarr zip support
704691
option(NETCDF_ENABLE_NCZARR_ZIP "Enable NCZarr ZIP support." ${NETCDF_ENABLE_NCZARR})
@@ -753,10 +740,10 @@ if(NOT WIN32)
753740
endif()
754741

755742
# Options for S3 Support
756-
#option(NETCDF_ENABLE_S3 "Enable S3 support." OFF)
757743
option(NETCDF_ENABLE_S3_AWS "Enable S3 support via AWS-CPP-SDK" OFF)
758744
option(NETCDF_ENABLE_S3_INTERNAL "Enable S3 Internal support." OFF)
759745

746+
#option(NETCDF_ENABLE_S3 "Enable S3 support." OFF)
760747
cmake_dependent_option(NETCDF_ENABLE_S3 "Enable S3 Support" ON "NETCDF_ENABLE_S3_AWS OR NETCDF_ENABLE_S3_INTERNAL" OFF)
761748

762749
option(NETCDF_ENABLE_NCZARR_S3 "Enable NCZarr S3 support; Deprecated in favor of NETCDF_ENABLE_S3" ${NETCDF_ENABLE_S3})
@@ -877,7 +864,7 @@ if(NETCDF_ENABLE_TESTS)
877864
# See https://github.com/Unidata/netcdf-c/issues/2627 for more information.
878865
###
879866
option(NETCDF_ENABLE_BENCHMARKS "Run benchmark Tests." OFF)
880-
867+
set(BUILD_BENCHMARKS ${NETCDF_ENABLE_BENCHMARKS} CACHE BOOL "alias for NETCDF_ENABLE_BENCHMARKS")
881868

882869
###
883870
# End known-failures.
@@ -1380,8 +1367,8 @@ endif(NETCDF_ENABLE_MMAP)
13801367
# Used in the `configure_file` calls below
13811368
set(ISCMAKE "yes")
13821369
if(MSVC)
1383-
set(ISMSVC ON CACHE BOOL "" FORCE)
1384-
set(REGEDIT ON CACHE BOOL "" FORCE)
1370+
set(ISMSVC yes CACHE BOOL "" FORCE)
1371+
set(REGEDIT yes CACHE BOOL "" FORCE)
13851372
# Get windows major version and build number
13861373
execute_process(COMMAND "systeminfo" OUTPUT_VARIABLE WININFO)
13871374
if(WININFO STREQUAL "")
@@ -1564,8 +1551,6 @@ endif()
15641551
# STATIC_DEFINE netcdf_BUILT_AS_STATIC
15651552
#)
15661553

1567-
1568-
15691554
##
15701555
# Brute force, grab all of the dlls from the dependency directory,
15711556
# install them in the binary dir. Grab all of the .libs, put them

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ This file contains a high-level description of this package's evolution. Release
77

88
## 4.9.3 - TBD
99

10+
* Extend the netcdf API to support programmatic changes to the plugin search path. See [Github #3034](https://github.com/Unidata/netcdf-c/pull/3034) for more information.
11+
1012
## Known Issue
1113

1214
> Parallel operation using `mpich 4.2.0` (the default on `Ubuntu 24.04`) results in 'unexpected results' when running `nc_test4/run_par_test.sh`. This can be fixed by removing `mpich` and associated libraries and development packages and installing `mpich 4.2.2` by hand, or by using `openmpi` provided via `apt`.

cmake/dependencies.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ if(USE_HDF5)
226226
endif(USE_HDF5)
227227

228228
################################
229-
# Curl Libraryies
229+
# Curl Libraries
230230
# Only needed for DAP (DAP2 or DAP4)
231-
# and NCZARR with S3 Support
231+
# and NCZARR S3 support
232+
# and byterange support
232233
################################
233234

234-
if( (NETCDF_ENABLE_DAP AND (NETCDF_ENABLE_DAP2 OR NETCDF_ENABLE_DAP4 OR NETCDF_ENABLE_BYTERANGE_SUPPORT)) OR (NETCDF_ENABLE_NCZARR AND NETCDF_ENABLENCZARR_S3))
235-
235+
if( NETCDF_ENABLE_DAP2 OR NETCDF_ENABLE_DAP4 OR NETCDF_ENABLE_BYTERANGE_SUPPORT OR NETCDF_ENABLE_NCZARR_S3)
236236
# See if we have libcurl
237237
find_package(CURL)
238238
#target_compile_options(netcdf

cmake/netcdf_functions_macros.cmake

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,16 @@ function(is_disabled feature ret_val)
324324
set(${ret_val} "yes" PARENT_SCOPE)
325325
set("NC_${ret_val}" 1 PARENT_SCOPE)
326326
endif(${feature})
327-
endfunction()
327+
endfunction()
328+
329+
# Extract the last element from a path string
330+
function(getlastdir s ret_val)
331+
if(NOT ISMSVC AND NOT ISMINGW)
332+
string(REPLACE ":" ";" list "${s}")
333+
else()
334+
set(list ${s})
335+
endif()
336+
list(GET list -1 last)
337+
set(${ret_val} "${last}" PARENT_SCOPE)
338+
endfunction()
339+

config.h.cmake.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ are set when opening a binary file on Windows. */
124124
#define ERANGE_FILL 1
125125
#endif
126126

127+
/* if true, use hdf5 S3 virtual file reader */
128+
#cmakedefine NETCDF_ENABLE_HDF5 1
129+
127130
/* if true, use hdf5 S3 virtual file reader */
128131
#cmakedefine NETCDF_ENABLE_HDF5_ROS3 1
129132

@@ -160,6 +163,12 @@ are set when opening a binary file on Windows. */
160163
/* if true, Allow dynamically loaded plugins */
161164
#cmakedefine NETCDF_ENABLE_PLUGINS 1
162165

166+
/* Define the plugin install dir */
167+
#cmakedefine NETCDF_PLUGIN_INSTALL_DIR "${NETCDF_PLUGIN_INSTALL_DIR}"
168+
169+
/* Define the plugin search path */
170+
#cmakedefine NETCDF_PLUGIN_SEARCH_PATH "${NETCDF_PLUGIN_SEARCH_PATH}"
171+
163172
/* if true, enable S3 support */
164173
#cmakedefine NETCDF_ENABLE_S3 1
165174

0 commit comments

Comments
 (0)