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

Allow optional use of libxml2 #2135

Merged
merged 2 commits into from
Nov 4, 2021
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
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,15 @@ IF(NOT FOUND_CURL)
ENDIF()
ENDIF(NOT FOUND_CURL)

# see if we have libxml2
find_package(LibXml2)
IF(LibXml2_FOUND)
SET(HAVE_LIBXML2 TRUE)
INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIRS})
ELSE()
SET(HAVE_LIBXML2 FALSE)
ENDIF()

IF(NOT ENABLE_BYTERANGE AND ENABLE_HDF5_ROS3)
MESSAGE(WARNING "ROS3 support requires ENABLE_BYTERANGE=TRUE; disabling ROS3 support")
SET(ENABLE_HDF5_ROS3 OFF CACHE BOOL "ROS3 support" FORCE)
Expand Down Expand Up @@ -2080,6 +2089,7 @@ ENDIF()

IF(ENABLE_DAP4)
ADD_SUBDIRECTORY(libdap4)
ADD_SUBDIRECTORY(libncxml)
ENDIF()

IF(ENABLE_PLUGINS)
Expand Down
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ endif

if ENABLE_DAP4
DAP4 = libdap4
XML = libncxml
NCDAP4TESTDIR = dap4_test
endif #DAP4

Expand Down Expand Up @@ -112,7 +113,7 @@ endif
# This is the list of subdirs for which Makefiles will be constructed
# and run. ncgen must come before ncdump, because their tests
# depend on it.
SUBDIRS = include $(H5_TEST_DIR) libdispatch libsrc $(LIBSRC4_DIR) \
SUBDIRS = include $(H5_TEST_DIR) ${XML} libdispatch libsrc $(LIBSRC4_DIR) \
$(LIBSRCP) $(LIBHDF4) $(LIBHDF5) $(OCLIB) $(DAP2) ${DAP4} \
${NCPOCO} ${ZARR} liblib \
$(NCGEN3) $(NCGEN) $(NCDUMP) ${PLUGIN_DIR} $(TESTDIRS) docs \
Expand Down
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This file contains a high-level description of this package's evolution. Release

## 4.8.2 - TBD

* [Enhancement] Support optional use of libxml2, otherwise default to ezxml. See [Github #2135](https://github.com/Unidata/netcdf-c/pull/2135) -- H/T to [Egbert Eich](https://github.com/e4t).
* [Enhancement] Support byte-range reading of netcdf-3 files stored in private buckets in S3. See [Github #2134](https://github.com/Unidata/netcdf-c/pull/2134)
* [Enhancement] Support Amazon S3 access for NCZarr. Also support use of the existing Amazon SDK credentials system. See [Github #2114](https://github.com/Unidata/netcdf-c/pull/2114)
* [Bug Fix] Fix string allocation error in H5FDhttp.c. See [Github #2127](https://github.com/Unidata/netcdf-c/pull/2127).
Expand Down
3 changes: 3 additions & 0 deletions config.h.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ are set when opening a binary file on Windows. */
/* Define to 1 if you have the `pnetcdf' library (-lpnetcdf). */
#cmakedefine HAVE_LIBPNETCDF 1

/* Define to 1 if you have the libxml2 library. */
#cmakedefine HAVE_LIBXML2 1

/* Define to 1 if you have the <locale.h> header file. */
#cmakedefine HAVE_LOCALE_H 1

Expand Down
14 changes: 14 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,19 @@ if test "x$enable_dap4" = xyes; then
AC_DEFINE([ENABLE_DAP4], [1], [if true, build DAP4 Client])
fi

# We can optionally use libxml2 for DAP4, if available
AC_CHECK_LIB([xml2],[xmlReadMemory],[have_libxml2=yes],[have_libxml2=no])
if test "x$have_libxml2" = "xyes" ; then
AC_SEARCH_LIBS([xmlReadMemory],[xml2 xml2.dll cygxml2.dll], [],[])
fi
if test "x$have_libxml2" = xyes; then
XML2FLAGS=`xml2-config --cflags`
AC_SUBST([XML2FLAGS],${XML2FLAGS})
AC_DEFINE([HAVE_LIBXML2], [1], [if true, use libxml2])
fi
# Need a condition for this
AM_CONDITIONAL(HAVE_LIBXML2, [test "x$have_libxml2" = xyes])

# check for useful, but not essential, memio support
AC_CHECK_FUNCS([memmove getpagesize sysconf])

Expand Down Expand Up @@ -1875,6 +1888,7 @@ AC_CONFIG_FILES([Makefile
libhdf4/Makefile
libnczarr/Makefile
libncpoco/Makefile
libncxml/Makefile
libdispatch/Makefile
liblib/Makefile
ncdump/cdl/Makefile
Expand Down
13 changes: 5 additions & 8 deletions include/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ nc4internal.h nctime.h nc3internal.h onstack.h ncrc.h ncauth.h \
ncoffsets.h nctestserver.h nc4dispatch.h nc3dispatch.h ncexternl.h \
ncpathmgr.h ncindex.h hdf4dispatch.h hdf5internal.h nc_provenance.h \
hdf5dispatch.h ncmodel.h isnan.h nccrc.h ncexhash.h ncxcache.h \
ncfilter.h ncjson.h ezxml.h ncs3sdk.h
ncfilter.h ncjson.h ncxml.h ncs3sdk.h

if USE_DAP
noinst_HEADERS += ncdap.h
Expand All @@ -32,10 +32,7 @@ endif

EXTRA_DIST = CMakeLists.txt XGetopt.h netcdf_meta.h.in netcdf_dispatch.h.in

# netcdf_json.h is part of the distribution.
# If either of the files ncjson.h ../libdispatch/ncjson.c is changed
# then netcdf_json.h should be reconstructed using this recipe.
build_netcdf_json.h::
sed -e 's/NCJSON_H/NETCDF_JSON_H/' -e '/ncjson.h/d' <${srcdir}/ncjson.h > $@
sed -e '/ncjson.h/d' < ${srcdir}/../libdispatch/ncjson.c >> $@

# Give the recipe for rebuilding netcdf_json.h
makencjson::
sed -e 's/NCJSON_H/NETCDF_JSON_H/' -e '/ncjson.h/d' <${srcdir}/ncjson.h > netcdf_json.h
sed -e '/ncjson.h/d' < ${srcdir}/../libdispatch/ncjson.c >> netcdf_json.h
44 changes: 44 additions & 0 deletions include/ncxml.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Copyright 2018-2018 University Corporation for Atmospheric
Research/Unidata. */

#ifndef NCXML_H
#define NCXML_H

#ifdef _WIN32
#ifdef DLL_EXPORT /* define when building the library */
#define DECLSPEC __declspec(dllexport)
#else
#define DECLSPEC __declspec(dllimport)
#endif
#else
#define DECLSPEC
#endif

typedef void* ncxml_t;
typedef void* ncxml_attr_t;
typedef void* ncxml_doc_t;

#if defined(__cplusplus)
extern "C" {
#endif

DECLSPEC void ncxml_initialize(void);
DECLSPEC void ncxml_finalize(void);
DECLSPEC ncxml_doc_t ncxml_parse(char* contents, size_t len);
DECLSPEC void ncxml_free(ncxml_doc_t doc0);
DECLSPEC ncxml_t ncxml_root(ncxml_doc_t doc);
DECLSPEC const char* ncxml_name(ncxml_t xml0);
DECLSPEC char* ncxml_attr(ncxml_t xml0, const char* key);
DECLSPEC ncxml_t ncxml_child(ncxml_t xml0, const char* name);
DECLSPEC ncxml_t ncxml_next(ncxml_t xml0, const char* name);
DECLSPEC char* ncxml_text(ncxml_t xml0);
DECLSPEC int ncxml_attr_pairs(ncxml_t xml0, char*** pairsp);
/* Nameless versions of child and next */
DECLSPEC ncxml_t ncxml_child_first(ncxml_t xml0);
DECLSPEC ncxml_t ncxml_child_next(ncxml_t xml0);

#if defined(__cplusplus)
}
#endif

#endif /*NCXML_H*/
4 changes: 3 additions & 1 deletion libdap4/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

# Put together AM_CPPFLAGS and AM_LDFLAGS.
include $(top_srcdir)/lib_flags.am
AM_CPPFLAGS += -I$(top_srcdir)/libncxml
libdap4_la_CPPFLAGS = ${AM_CPPFLAGS}

# We may have to add to these later.
DISTCLEANFILES =
Expand Down Expand Up @@ -59,7 +61,7 @@ endif
# Build convenience library
noinst_LTLIBRARIES = libdap4.la
libdap4_la_SOURCES = $(SRC) $(HDRS)
libdap4_la_CPPFLAGS = $(AM_CPPFLAGS)
libdap4_la_CPPFLAGS += $(AM_CPPFLAGS)
libdap4_la_LIBADD =

endif # ENABLE_DAP4
1 change: 0 additions & 1 deletion libdap4/d4data.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "d4includes.h"
#include <stdarg.h>
#include <assert.h>
#include "ezxml.h"
#include "d4includes.h"
#include "d4odom.h"
#include "nccrc.h"
Expand Down
1 change: 0 additions & 1 deletion libdap4/d4fix.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <assert.h>

#include "d4includes.h"
#include "ezxml.h"

/*
The primary purpose of this code is to provide node and data walkers
Expand Down
1 change: 0 additions & 1 deletion libdap4/d4meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <stdarg.h>
#include "nc4internal.h"
#include "ncoffsets.h"
#include "ezxml.h"

/**
* Build the netcdf-4 metadata from the NCD4node nodes.
Expand Down
Loading