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
84 dnl Default behavior is implicit no
90 AC_ARG_WITH([xerces-inc],
91 AC_HELP_STRING([--with-xerces-inc=@<:@DIR@:>@],
92 [path to Xerces C++ Parser headers]
94 [xerces_include_dir="$withval"],
95 [xerces_include_dir=""]
97 AC_ARG_WITH([xerces-lib],
98 AC_HELP_STRING([--with-xerces-lib=@<:@ARG@:>@],
99 [link options for Xerces C++ Parser libraries]
101 [xerces_ldflags="$withval"],
110 dnl Collect include/lib paths and flags
114 if test -n "$xerces_prefix"; then
115 xerces_include_dir="$xerces_prefix/include"
116 xerces_include_dir2="$xerces_prefix/include/xercesc"
117 xerces_ldflags="-L$xerces_prefix/lib"
118 run_xerces_test="yes"
119 elif test "$xerces_requested" = "yes"; then
120 if test -n "$xerces_include_dir" -a -n "$xerces_lib_flags"; then
121 xerces_include_dir2="$xerces_include_dir/xercesc"
122 run_xerces_test="yes"
128 xerces_libs="-lxerces-c"
131 dnl Check Xerces C++ Parser files
133 if test "$run_xerces_test" = "yes"; then
135 saved_CPPFLAGS="$CPPFLAGS"
136 CPPFLAGS="$CPPFLAGS -I$xerces_include_dir -I$xerces_include_dir2"
138 saved_LDFLAGS="$LDFLAGS"
139 LDFLAGS="$xerces_ldflags $PTHREAD_LDFLAGS $LDFLAGS"
142 LIBS="$xerces_libs $PTHREAD_LIBS $LIBS"
145 dnl Check Xerces headers
147 AC_MSG_CHECKING([for Xerces C++ Parser headers in $xerces_include_dir and $xerces_include_dir2])
153 @%:@include <xercesc/util/XercesDefs.hpp>
154 @%:@include <xercesc/util/PlatformUtils.hpp>
159 XERCES_CPPFLAGS="-I$xerces_include_dir -I$xerces_include_dir2"
160 xerces_header_found="yes"
161 AC_MSG_RESULT([found])
164 xerces_header_found="no"
165 AC_MSG_RESULT([not found])
171 dnl Check Xerces libraries
173 if test "$xerces_header_found" = "yes"; then
175 AC_MSG_CHECKING([for Xerces C++ Parser libraries])
181 @%:@include <xercesc/util/XercesDefs.hpp>
182 @%:@include <xercesc/util/PlatformUtils.hpp>
183 #if (_XERCES_VERSION >= 20200)
184 XERCES_CPP_NAMESPACE_USE
188 XMLPlatformUtils::Initialize();
192 XERCES_LDFLAGS="$xerces_ldflags $PTHREAD_LDFLAGS"
193 XERCES_LIBS="$xerces_libs $PTHREAD_LIBS"
194 xerces_lib_found="yes"
195 AC_MSG_RESULT([found])
198 xerces_lib_found="no"
199 AC_MSG_RESULT([not found])
205 CPPFLAGS="$saved_CPPFLAGS"
206 LDFLAGS="$saved_LDFLAGS"
210 AC_MSG_CHECKING([for Xerces C++ Parser])
212 if test "$run_xerces_test" = "yes"; then
213 if test "$xerces_header_found" = "yes" -a "$xerces_lib_found" = "yes"; then
215 AC_SUBST([XERCES_CPPFLAGS])
216 AC_SUBST([XERCES_LDFLAGS])
217 AC_SUBST([XERCES_LIBS])
224 AC_MSG_RESULT([$HAVE_XERCES])
227 dnl Check Xerces version
229 if test "$HAVE_XERCES" = "yes"; then
231 xerces_version_req=ifelse([$1], [], [], [$1])
233 if test -n "$xerces_version_req"; then
235 AC_MSG_CHECKING([if Xerces C++ Parser version is >= $xerces_version_req])
237 if test -f "$xerces_include_dir2/util/XercesVersion.hpp"; then
239 xerces_major=`cat $xerces_include_dir2/util/XercesVersion.hpp | \
240 grep '^#define.*XERCES_VERSION_MAJOR.*[0-9]$' | \
241 sed -e 's/#define XERCES_VERSION_MAJOR.//'`
243 xerces_minor=`cat $xerces_include_dir2/util/XercesVersion.hpp | \
244 grep '^#define.*XERCES_VERSION_MINOR.*[0-9]$' | \
245 sed -e 's/#define XERCES_VERSION_MINOR.//'`
247 xerces_revision=`cat $xerces_include_dir2/util/XercesVersion.hpp | \
248 grep '^#define.*XERCES_VERSION_REVISION.*[0-9]$' | \
249 sed -e 's/#define XERCES_VERSION_REVISION.//'`
251 XERCES_VERSION="$xerces_major.$xerces_minor.$xerces_revision"
252 AC_SUBST([XERCES_VERSION])
254 dnl Decompose required version string and calculate numerical representation
255 xerces_version_req_major=`expr $xerces_version_req : '\([[0-9]]*\)'`
256 xerces_version_req_minor=`expr $xerces_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
257 xerces_version_req_revision=`expr $xerces_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
258 if test "x$xerces_version_req_revision" = "x"; then
259 xerces_version_req_revision="0"
262 xerces_version_req_number=`expr $xerces_version_req_major \* 10000 \
263 \+ $xerces_version_req_minor \* 100 \
264 \+ $xerces_version_req_revision`
266 dnl Calculate numerical representation of detected version
267 xerces_version_number=`expr $xerces_major \* 10000 \
268 \+ $xerces_minor \* 100 \
271 xerces_version_check=`expr $xerces_version_number \>\= $xerces_version_req_number`
272 if test "$xerces_version_check" = "1"; then
276 AC_MSG_WARN([Found Xerces C++ Parser $XERCES_VERSION, which is older than required. Possible compilation failure.])
280 AC_MSG_WARN([Missing header XercesVersion.hpp. Unable to determine Xerces version.])
287 AC_MSG_RESULT([$HAVE_XERCES])
289 if test "$xerces_requested" = "yes"; then
290 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])
293 if test "$HAVE_XERCES" = "yes"; then
294 CPPFLAGS="$CPPFLAGS $XERCES_CPPFLAGS -DHAVE_XERCES_C=1"
295 LDFLAGS="$LDFLAGS $XERCES_LDFLAGS $XERCES_LIBS"