1 # ===========================================================================
2 # http://autoconf-archive.cryp.to/ax_lib_xerces.html
3 # ===========================================================================
7 # AX_LIB_XERCES([MINIMUM-VERSION])
11 # This macro provides tests of availability of Apache Xerces C++ Parser of
12 # particular version or newer. This macros checks for Apache Xerces C++
13 # Parser headers and libraries and defines compilation flags
15 # Macro supports following options and their values:
17 # 1) Single-option usage:
19 # --with-xerces - yes, no or path to Xerces installation prefix
21 # 2) Three-options usage (all options are required):
24 # --with-xerces-inc - path to base directory with Xerces headers
25 # --with-xerces-lib - linker flags for Xerces
29 # AC_SUBST(XERCES_CFLAGS)
30 # AC_SUBST(XERCES_LDFLAGS)
31 # AC_SUBST(XERCES_VERSION) - only if version requirement is used
43 # Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net>
45 # Copying and distribution of this file, with or without modification, are
46 # permitted in any medium without royalty provided the copyright notice
47 # and this notice are preserved.
49 AC_DEFUN([AX_LIB_XERCES],
51 # AC_REQUIRE([ACX_PTHREAD])
54 AC_HELP_STRING([--with-xerces=@<:@ARG@:>@],
55 [use Xerces C++ Parser from given prefix (ARG=path); check standard prefixes (ARG=yes); disable (ARG=no)]
58 if test "$withval" = "yes"; then
59 if test -d /usr/local/include/xercesc ; then
60 xerces_prefix=/usr/local
61 elif test -d /usr/include/xercesc ; then
66 xerces_requested="yes"
67 elif test -d "$withval"; then
68 xerces_prefix="$withval"
69 xerces_requested="yes"
76 dnl Default behavior is implicit yes
77 if test -d /usr/local/include/xercesc ; then
78 xerces_prefix=/usr/local
79 elif test -d /usr/include/xercesc ; then
87 AC_ARG_WITH([xerces-inc],
88 AC_HELP_STRING([--with-xerces-inc=@<:@DIR@:>@],
89 [path to Xerces C++ Parser headers]
91 [xerces_include_dir="$withval"],
92 [xerces_include_dir=""]
94 AC_ARG_WITH([xerces-lib],
95 AC_HELP_STRING([--with-xerces-lib=@<:@ARG@:>@],
96 [link options for Xerces C++ Parser libraries]
98 [xerces_ldflags="$withval"],
107 dnl Collect include/lib paths and flags
111 if test -n "$xerces_prefix"; then
112 xerces_include_dir="$xerces_prefix/include"
113 xerces_include_dir2="$xerces_prefix/include/xercesc"
114 xerces_ldflags="-L$xerces_prefix/lib"
115 run_xerces_test="yes"
116 elif test "$xerces_requested" = "yes"; then
117 if test -n "$xerces_include_dir" -a -n "$xerces_lib_flags"; then
118 xerces_include_dir2="$xerces_include_dir/xercesc"
119 run_xerces_test="yes"
125 xerces_libs="-lxerces-c"
128 dnl Check Xerces C++ Parser files
130 if test "$run_xerces_test" = "yes"; then
132 saved_CPPFLAGS="$CPPFLAGS"
133 CPPFLAGS="$CPPFLAGS -I$xerces_include_dir -I$xerces_include_dir2"
135 saved_LDFLAGS="$LDFLAGS"
136 LDFLAGS="$LDFLAGS $xerces_ldflags $PTHREAD_LDFLAGS"
139 LIBS="$xerces_libs $PTHREAD_LIBS $LIBS"
142 dnl Check Xerces headers
144 AC_MSG_CHECKING([for Xerces C++ Parser headers in $xerces_include_dir and $xerces_include_dir2])
150 @%:@include <xercesc/util/XercesDefs.hpp>
151 @%:@include <xercesc/util/PlatformUtils.hpp>
156 XERCES_CPPFLAGS="-I$xerces_include_dir -I$xerces_include_dir2"
157 xerces_header_found="yes"
158 AC_MSG_RESULT([found])
161 xerces_header_found="no"
162 AC_MSG_RESULT([not found])
168 dnl Check Xerces libraries
170 if test "$xerces_header_found" = "yes"; then
172 AC_MSG_CHECKING([for Xerces C++ Parser libraries])
178 @%:@include <xercesc/util/XercesDefs.hpp>
179 @%:@include <xercesc/util/PlatformUtils.hpp>
180 #if (_XERCES_VERSION >= 20200)
181 XERCES_CPP_NAMESPACE_USE
185 XMLPlatformUtils::Initialize();
189 XERCES_LDFLAGS="$xerces_ldflags $PTHREAD_LDFLAGS"
190 XERCES_LIBS="$xerces_libs $PTHREAD_LIBS"
191 xerces_lib_found="yes"
192 AC_MSG_RESULT([found])
195 xerces_lib_found="no"
196 AC_MSG_RESULT([not found])
202 CPPFLAGS="$saved_CPPFLAGS"
203 LDFLAGS="$saved_LDFLAGS"
207 AC_MSG_CHECKING([for Xerces C++ Parser])
209 if test "$run_xerces_test" = "yes"; then
210 if test "$xerces_header_found" = "yes" -a "$xerces_lib_found" = "yes"; then
212 AC_SUBST([XERCES_CPPFLAGS])
213 AC_SUBST([XERCES_LDFLAGS])
214 AC_SUBST([XERCES_LIBS])
221 AC_MSG_RESULT([$HAVE_XERCES])
224 dnl Check Xerces version
226 if test "$HAVE_XERCES" = "yes"; then
228 xerces_version_req=ifelse([$1], [], [], [$1])
230 if test -n "$xerces_version_req"; then
232 AC_MSG_CHECKING([if Xerces C++ Parser version is >= $xerces_version_req])
234 if test -f "$xerces_include_dir2/util/XercesVersion.hpp"; then
236 xerces_major=`cat $xerces_include_dir2/util/XercesVersion.hpp | \
237 grep '^#define.*XERCES_VERSION_MAJOR.*[0-9]$' | \
238 sed -e 's/#define XERCES_VERSION_MAJOR.//'`
240 xerces_minor=`cat $xerces_include_dir2/util/XercesVersion.hpp | \
241 grep '^#define.*XERCES_VERSION_MINOR.*[0-9]$' | \
242 sed -e 's/#define XERCES_VERSION_MINOR.//'`
244 xerces_revision=`cat $xerces_include_dir2/util/XercesVersion.hpp | \
245 grep '^#define.*XERCES_VERSION_REVISION.*[0-9]$' | \
246 sed -e 's/#define XERCES_VERSION_REVISION.//'`
248 XERCES_VERSION="$xerces_major.$xerces_minor.$xerces_revision"
249 AC_SUBST([XERCES_VERSION])
251 dnl Decompose required version string and calculate numerical representation
252 xerces_version_req_major=`expr $xerces_version_req : '\([[0-9]]*\)'`
253 xerces_version_req_minor=`expr $xerces_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
254 xerces_version_req_revision=`expr $xerces_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
255 if test "x$xerces_version_req_revision" = "x"; then
256 xerces_version_req_revision="0"
259 xerces_version_req_number=`expr $xerces_version_req_major \* 10000 \
260 \+ $xerces_version_req_minor \* 100 \
261 \+ $xerces_version_req_revision`
263 dnl Calculate numerical representation of detected version
264 xerces_version_number=`expr $xerces_major \* 10000 \
265 \+ $xerces_minor \* 100 \
268 xerces_version_check=`expr $xerces_version_number \>\= $xerces_version_req_number`
269 if test "$xerces_version_check" = "1"; then
273 AC_MSG_WARN([Found Xerces C++ Parser $XERCES_VERSION, which is older than required. Possible compilation failure.])
277 AC_MSG_WARN([Missing header XercesVersion.hpp. Unable to determine Xerces version.])
284 AC_MSG_RESULT([$HAVE_XERCES])
286 if test "$xerces_requested" = "yes"; then
287 AC_MSG_WARN([Xerces C++ Parser support requested but headers or library not found. Specify valid prefix of Xerces C++ using --with-xerces=@<:@DIR@:>@ or provide include directory and linker flags using --with-xerces-inc and --with-xerces-lib])
290 if test "$HAVE_XERCES" = "yes"; then
291 CPPFLAGS="$CPPFLAGS -DHAVE_XERCES_C=1"