Repository: Unidata/netcdf-c
Pull request #2923 (2024-05-11 22:24:53)

Convert the ENABLE_XXX options to NETCDF_ENABLE_XXX options for NCZarr
# Primary Change
In order to conform to the cmake overhaul, occurrences of ENABLE_XXX options in the nczarr code have been changed to NETCDF_ENABLE_XXX.

# Misc. Other changes
* Fix use of rand_s in libdispatch/ncrandom.c
* Fix some bugs in the mingw gitub action.
* Fix signature bug in libncpoco/cp_win32.c
* Make some NCZarr fixes to config.h.cmake.in


Patch:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 81a7345a1..6ded68d07 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -382,13 +382,13 @@ if(MSVC)
 endif()
 
 # Option to build netCDF Version 2
-OPTION (ENABLE_V2_API "Build netCDF Version 2." ON)
-set(BUILD_V2 ${ENABLE_V2_API})
-if(NOT ENABLE_V2_API)
+OPTION (NETCDF_ENABLE_V2_API "Build netCDF Version 2." ON)
+set(BUILD_V2 ${NETCDF_ENABLE_V2_API})
+if(NOT NETCDF_ENABLE_V2_API)
   set(NO_NETCDF_2 ON)
-else(NOT ENABLE_V2_API)
+else(NOT NETCDF_ENABLE_V2_API)
   set(USE_NETCDF_2 TRUE)
-endif(NOT ENABLE_V2_API)
+endif(NOT NETCDF_ENABLE_V2_API)
 
 # Option to build utilities
 option(NETCDF_BUILD_UTILITIES "Build ncgen, ncgen3, ncdump." ON)
@@ -1446,7 +1446,7 @@ endif()
 
 # Enable tests
 if(NETCDF_ENABLE_TESTS)
-  if(ENABLE_V2_API)
+  if(NETCDF_ENABLE_V2_API)
     add_subdirectory(nctest)
   endif()
   add_subdirectory(nc_test)
@@ -1622,7 +1622,7 @@ set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_${CMAKE_BU
 is_disabled(BUILD_SHARED_LIBS enable_static)
 is_enabled(BUILD_SHARED_LIBS enable_shared)
 
-is_enabled(ENABLE_V2_API HAS_NC2)
+is_enabled(NETCDF_ENABLE_V2_API HAS_NC2)
 is_enabled(NETCDF_ENABLE_NETCDF_4 HAS_NC4)
 is_enabled(NETCDF_ENABLE_HDF4 HAS_HDF4)
 is_enabled(USE_HDF5 HAS_HDF5)
@@ -1637,7 +1637,7 @@ is_enabled(NETCDF_ENABLE_BYTERANGE HAS_BYTERANGE)
 is_enabled(NETCDF_ENABLE_DISKLESS HAS_DISKLESS)
 is_enabled(USE_MMAP HAS_MMAP)
 is_enabled(JNA HAS_JNA)
-is_enabled(ENABLE_ZERO_LENGTH_COORD_BOUND RELAX_COORD_BOUND)
+is_enabled(NETCDF_ENABLE_ZERO_LENGTH_COORD_BOUND RELAX_COORD_BOUND)
 is_enabled(USE_CDF5 HAS_CDF5)
 is_enabled(NETCDF_ENABLE_ERANGE_FILL HAS_ERANGE_FILL)
 is_enabled(HDF5_HAS_PAR_FILTERS HAS_PAR_FILTERS)
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index bfa8c58c8..52c0db7b2 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -7,6 +7,7 @@ This file contains a high-level description of this package's evolution. Release
 
 ## 4.9.3 - TBD
 
+* Convert the Zarr-related ENABLE_XXX options to NETCDF_ENABLE_XXX options (part of the cmake overhaul). See [Github #2923](https://github.com/Unidata/netcdf-c/issues/2923) for more information.
 * Refactor macro `_FillValue` to `NC_FillValue` to avoid conflict with libc++ headers. See [Github #2858](https://github.com/Unidata/netcdf-c/issues/2858) for more information.
 * Changed `cmake` build options to be prefaced with `NETCDF`, to bring things in to line with best practices.  This will permit a number of overall quality of life improvements to netCDF, in terms of allowing it to be more easily integrated with upstream projects via `FetchContent()`, `subdirectory()`, etc. Currently, the naming convention in use thus far will still work, but will result in warning messages about deprecation, and instructions on how to update your workflow. See [Github #2895](https://github.com/Unidata/netcdf-c/pull/2895) for more information.
 * Fix some problems in handling S3 urls with missing regions. See [Github #2819](https://github.com/Unidata/netcdf-c/pull/2819).
diff --git a/config.h.cmake.in b/config.h.cmake.in
index 4a404781c..0cf62a757 100644
--- a/config.h.cmake.in
+++ b/config.h.cmake.in
@@ -133,6 +133,9 @@ are set when opening a binary file on Windows. */
 /* if true, enable client side filters */
 #cmakedefine ENABLE_CLIENT_FILTERS 1
 
+/* if true, enable filter testing */
+#cmakedefine NETCDF_ENABLE_FILTER_TESTING 1
+
 /* if true, enable strict null byte header padding. */
 #cmakedefine USE_STRICT_NULL_BYTE_HEADER_PADDING 1
 
@@ -167,7 +170,7 @@ are set when opening a binary file on Windows. */
 #cmakedefine NETCDF_ENABLE_S3_INTERNAL 1
 
 /* if true, enable S3 testing*/
-#cmakedefine WITH_S3_TESTING "PUBLIC"
+#cmakedefine WITH_S3_TESTING "${WITH_S3_TESTING}"
 
 /* S3 Test Bucket */
 #define S3TESTBUCKET "${S3TESTBUCKET}"
@@ -199,6 +202,9 @@ are set when opening a binary file on Windows. */
 /* Define to 1 if blosc library available. */
 #cmakedefine HAVE_BLOSC 1
 
+/* if true enable tests that access external servers */
+#cmakedefine NETCDF_ENABLE_EXTERNAL_SERVER_TESTS 1
+
 /* Define to 1 if you have hdf5_coll_metadata_ops */
 #cmakedefine HDF5_HAS_COLL_METADATA_OPS 1
 
@@ -397,6 +403,9 @@ are set when opening a binary file on Windows. */
 /* Define to 1 if you have the `strlcpy' function. */
 #cmakedefine HAVE_STRLCPY 1
 
+/* Define to 1 if you have the `strlen' function. */
+#cmakedefine HAVE_STRLEN 1
+
 /* Define to 1 if you have the `strtoll' function. */
 #cmakedefine HAVE_STRTOLL 1
 
@@ -487,7 +496,7 @@ with zip */
 #cmakedefine NETCDF_ENABLE_DOXYGEN 1
 #cmakedefine NETCDF_ENABLE_INTERNAL_DOCS 1
 #cmakedefine VALGRIND_TESTS 1
-#cmakedefine ENABLE_CDMREMOTE 1
+#cmakedefine NETCDF_ENABLE_CDMREMOTE 1
 #cmakedefine USE_HDF5 1
 #cmakedefine ENABLE_FILEINFO 1
 #cmakedefine TEST_PARALLEL ${TEST_PARALLEL}
@@ -570,6 +579,9 @@ with zip */
 /* The size of `size_t', as computed by sizeof. */
 #cmakedefine SIZEOF_SIZE_T ${SIZEOF_SIZE_T}
 
+/* The size of `ssize_t', as computed by sizeof. */
+#cmakedefine SIZEOF_SSIZE_T ${SIZEOF_SSIZE_T}
+
 /* The size of `uint', as computed by sizeof. */
 #cmakedefine SIZEOF_UINT ${SIZEOF_UINT}
 
@@ -635,10 +647,10 @@ with zip */
 #cmakedefine USE_STDIO 1
 
 /* if true, multi-filters enabled*/
-#cmakedefine ENABLE_MULTIFILTERS 1
+#cmakedefine NETCDF_ENABLE_MULTIFILTERS 1
 
 /* if true, enable nczarr blosc support */
-#cmakedefine ENABLE_BLOSC 1
+#cmakedefine NETCDF_ENABLE_BLOSC 1
 
 /* Version number of package */
 #cmakedefine VERSION "${netCDF_VERSION}"
diff --git a/configure.ac b/configure.ac
index da3b33626..b8b544e87 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1765,7 +1765,7 @@ if test "x$enable_pnetcdf" = xyes -o "x$enable_parallel4" = xyes; then
 else
   enable_parallel=no
 fi
-AM_CONDITIONAL(ENABLE_PARALLEL, [test x$enable_parallel = xyes ])
+AM_CONDITIONAL(NETCDF_ENABLE_PARALLEL, [test x$enable_parallel = xyes ])
 
 if test "x$hdf5_parallel" = xyes; then
   # Provide more precise parallel control
diff --git a/libdispatch/ncrandom.c b/libdispatch/ncrandom.c
index 7575aa72a..bd6e7746b 100644
--- a/libdispatch/ncrandom.c
+++ b/libdispatch/ncrandom.c
@@ -13,13 +13,16 @@
 #include <stdio.h>
 #endif
 
+#if defined(_WIN32) || defined(_MSC_VER)
+extern errno_t rand_s(unsigned int *randomValue);
+#endif
 
 /* Support platform independent generation of 32-bit unsigned int random numbers */
 
 int
 main() {
     unsigned int urnd = 0; /* range 0..2147483647 */
-#if defined(WIN32) || defined(_MSC_VER)
+#if defined(_WIN32) || defined(_MSC_VER)
     (void)rand_s(&urnd);
 #else
     long rnd;
diff --git a/libhdf5/hdf5filter.c b/libhdf5/hdf5filter.c
index 2cd840aac..a6e392cb5 100644
--- a/libhdf5/hdf5filter.c
+++ b/libhdf5/hdf5filter.c
@@ -20,7 +20,7 @@
 #include "netcdf.h"
 #include "netcdf_filter.h"
 
-#ifdef ENABLE_BLOSC
+#ifdef NETCDF_ENABLE_BLOSC
 #include <blosc.h>
 #endif
 
diff --git a/libhdf5/hdf5open.c b/libhdf5/hdf5open.c
index 085d0d768..63a127300 100644
--- a/libhdf5/hdf5open.c
+++ b/libhdf5/hdf5open.c
@@ -930,7 +930,7 @@ nc4_open_file(const char *path, int mode, void* parameters, int ncid)
                 if(H5Pset_fapl_ros3(fapl_id, &fa) < 0)
                     BAIL(NC_EHDFERR);
 	    } else
-#endif /*ENABLE_ROS3*/
+#endif /*NETCDF_ENABLE_ROS3*/
 	    {/* Configure FAPL to use our byte-range file driver */
                 if (H5Pset_fapl_http(fapl_id) < 0)
                     BAIL(NC_EHDFERR);
diff --git a/liblib/nc_initialize.c b/liblib/nc_initialize.c
index b7756041d..ed7fea893 100644
--- a/liblib/nc_initialize.c
+++ b/liblib/nc_initialize.c
@@ -42,7 +42,7 @@ extern int NC_HDF4_initialize(void);
 extern int NC_HDF4_finalize(void);
 #endif
 
-#ifdef ENABLE_S3
+#ifdef NETCDF_ENABLE_S3
 EXTERNL int NC_s3sdkinitialize(void);
 EXTERNL int NC_s3sdkfinalize(void);
 #endif
@@ -105,7 +105,7 @@ nc_initialize()
 #ifdef USE_HDF4
     if((stat = NC_HDF4_initialize())) goto done;
 #endif
-#ifdef ENABLE_S3
+#ifdef NETCDF_ENABLE_S3
     if((stat = NC_s3sdkinitialize())) goto done;
 #endif
 #ifdef NETCDF_ENABLE_NCZARR
@@ -170,7 +170,7 @@ nc_finalize(void)
     if((stat = NCZ_finalize())) failed = stat;
 #endif
 
-#ifdef ENABLE_S3
+#ifdef NETCDF_ENABLE_S3
     if((stat = NC_s3sdkfinalize())) failed = stat;
 #endif
 
diff --git a/libncpoco/cp_win32.c b/libncpoco/cp_win32.c
index 896344f63..a768b8242 100644
--- a/libncpoco/cp_win32.c
+++ b/libncpoco/cp_win32.c
@@ -104,7 +104,7 @@ load(NCPSharedLib* lib , const char* path0, int flags)
 	int errcode = GetLastError();
 	char* msg = NULL;
         FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
-                          NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &msg, 0, NULL);
+                          NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (char*)&msg, 0, NULL);
 	memset(lib->err.msg,0,sizeof(lib->err.msg));
 	if(msg)
 	    strncpy(lib->err.msg,msg,sizeof(lib->err.msg));
diff --git a/libsrc/CMakeLists.txt b/libsrc/CMakeLists.txt
index 29a4d2b73..b0016249f 100644
--- a/libsrc/CMakeLists.txt
+++ b/libsrc/CMakeLists.txt
@@ -100,4 +100,4 @@ if(HAVE_M4)
     install(FILES "${CMAKE_CURRENT_BINARY_DIR}/netcdf.3" DESTINATION "${CMAKE_INSTALL_MANDIR}/man3" COMPONENT documentation)
   endif(NOT MSVC)
 
-endif()
\ No newline at end of file
+endif()
diff --git a/libsrc4/nc4internal.c b/libsrc4/nc4internal.c
index 5508e8612..3dea91e7c 100644
--- a/libsrc4/nc4internal.c
+++ b/libsrc4/nc4internal.c
@@ -1803,7 +1803,7 @@ nc_set_log_level(int new_level)
 #endif /* NC_HAS_PARALLEL4 */
     
     LOG((1, "log_level changed to %d", nc_log_level));
-#endif /*NC_HAS_LOGGING */
+#endif /* LOGGING */
     
     return NC_NOERR;
 }
diff --git a/ncgen/CMakeLists.txt b/ncgen/CMakeLists.txt
index ab7fad349..b247d5223 100644
--- a/ncgen/CMakeLists.txt
+++ b/ncgen/CMakeLists.txt
@@ -70,7 +70,7 @@ FILE(GLOB COPY_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.l ${CMAKE_CURRENT_SOURCE_DIR}
 FILE(COPY ${COPY_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
 
 # Stuff to build if tests are enabled.
-IF(ENABLE_TESTS)
+IF(NETCDF_ENABLE_TESTS)
   FILE(GLOB COPY_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cdl ${CMAKE_CURRENT_SOURCE_DIR}/*.sh)
   FILE(COPY ${COPY_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)
 
diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt
index 6d0b20a41..ec24023b9 100644
--- a/plugins/CMakeLists.txt
+++ b/plugins/CMakeLists.txt
@@ -89,12 +89,12 @@ buildplugin(nczmisc "zmisc")
 buildplugin(nczhdf5filters "zhdf5filters" netcdf)
 buildplugin(nczstdfilters "zstdfilters" netcdf)
 
-if(ENABLE_BLOSC)
+if(NETCDF_ENABLE_BLOSC)
   set(h5blosc_SOURCES H5Zblosc.c)
   buildplugin(h5blosc "h5blosc" netcdf;${Blosc_LIBRARIES})
 endif()
 
-if(ENABLE_ZSTD)
+if(NETCDF_ENABLE_ZSTD)
   set(h5zstd_SOURCES H5Zzstd.c H5Zzstd.h)
   buildplugin(h5zstd "h5zstd" netcdf;${Zstd_LIBRARIES})
 endif()


Test patch:
diff --git a/nc_test/Makefile.am b/nc_test/Makefile.am
index 903e74351..6654119ac 100644
--- a/nc_test/Makefile.am
+++ b/nc_test/Makefile.am
@@ -87,7 +87,7 @@ endif
 
 TESTS += run_diskless.sh run_diskless5.sh run_inmemory.sh
 if LARGE_FILE_TESTS
-if ! ENABLE_PARALLEL
+if ! NETCDF_ENABLE_PARALLEL
 TESTS += run_diskless2.sh
 endif
 endif
diff --git a/nc_test4/Makefile.am b/nc_test4/Makefile.am
index 22ac5f394..7937ca131 100644
--- a/nc_test4/Makefile.am
+++ b/nc_test4/Makefile.am
@@ -79,6 +79,7 @@ endif
 
 # Filter Tests (requires ncdump and ncgen and HDF5)
 if USE_HDF5
+if NETCDF_ENABLE_PLUGINS
 if NETCDF_ENABLE_FILTER_TESTING
 extradir =
 check_PROGRAMS += test_filter test_filter_misc test_filter_order test_filter_repeat
@@ -108,6 +109,7 @@ TESTS += tst_filterinstall.sh
 endif
 
 endif # NETCDF_ENABLE_FILTER_TESTING
+endif # NETCDF_ENABLE_PLUGINS
 endif # USE_HDF5
 endif # NETCDF_BUILD_UTILITIES
 
diff --git a/ncdap_test/CMakeLists.txt b/ncdap_test/CMakeLists.txt
index d1178ff9f..e919708d6 100644
--- a/ncdap_test/CMakeLists.txt
+++ b/ncdap_test/CMakeLists.txt
@@ -39,6 +39,7 @@ IF(NETCDF_ENABLE_TESTS)
     add_bin_env_test(ncdap test_vara)
   ENDIF()
 
+  IF(NETCDF_ENABLE_EXTERNAL_SERVER_TESTS)
   IF(NETCDF_ENABLE_DAP_REMOTE_TESTS)
 
     IF(NETCDF_BUILD_UTILITIES)
@@ -64,6 +65,7 @@ IF(NETCDF_ENABLE_TESTS)
           add_bin_test(ncdap test_manyurls)
           SET_TESTS_PROPERTIES(ncdap_test_manyurls PROPERTIES RUN_SERIAL TRUE)
     ENDIF()
+    ENDIF()
 
     IF(NETCDF_ENABLE_DAP_AUTH_TESTS)
 ##obsolete      add_bin_test(ncdap t_auth)
diff --git a/ncdap_test/Makefile.am b/ncdap_test/Makefile.am
index d7576677a..1e121db17 100644
--- a/ncdap_test/Makefile.am
+++ b/ncdap_test/Makefile.am
@@ -47,6 +47,10 @@ if NETCDF_BUILD_UTILITIES
 TESTS += tst_ber.sh tst_remote3.sh tst_formatx.sh testurl.sh tst_fillmismatch.sh tst_zero_len_var.sh
 endif
 
+if NETCDF_ENABLE_EXTERNAL_SERVER_TESTS
+if NETCDF_ENABLE_DAP_REMOTE_TESTS
+
+if NETCDF_BUILD_UTILITIES
 # Remote servers
 # iridl.ldeo.columbia.edu
 TESTS += tst_encode.sh
@@ -55,16 +59,17 @@ TESTS += tst_hyrax.sh
 
 TESTS += test_partvar
 
-if NETCDF_ENABLE_DAP_LONG_TESTS
+# Various
  TESTS += tst_longremote3.sh
  tst_longremote3.log: tst_remote3.log
-if NETCDF_ENABLE_EXTERNAL_SERVER_TESTS
+endif
+
+if NETCDF_ENABLE_DAP_LONG_TESTS
  test_manyurls_SOURCES = test_manyurls.c manyurls.h
  check_PROGRAMS += test_manyurls
  test_manyurls.log: tst_longremote3.log
  TESTS += test_manyurls
 endif
-endif
 
 test_partvar_SOURCES = test_partvar.c
 
@@ -84,6 +89,9 @@ check_PROGRAMS += test_partvar
 check_PROGRAMS += t_misc
 check_PROGRAMS += t_ncf330
 
+endif
+endif
+
 if NETCDF_ENABLE_DAP_AUTH_TESTS
 TESTS += testauth.sh
 endif
diff --git a/nczarr_test/Makefile.am b/nczarr_test/Makefile.am
index 166516c2e..541526780 100644
--- a/nczarr_test/Makefile.am
+++ b/nczarr_test/Makefile.am
@@ -21,7 +21,7 @@ TEST_EXTENSIONS = .sh
 
 AM_CPPFLAGS += -I${top_srcdir} -I${top_srcdir}/libnczarr
 AM_LDFLAGS += ${top_builddir}/liblib/libnetcdf.la
-LDADD = ${top_builddir}/liblib/libnetcdf.la
+LDADD += ${top_builddir}/liblib/libnetcdf.la
 AM_CXXFLAGS = 
 # Set up the tests; do the .sh first, then .c
 check_PROGRAMS =