Updated xerces m4 file.
[asdcplib.git] / m4 / ax_lib_xerces.m4
1 # ===========================================================================
2 #             http://autoconf-archive.cryp.to/ax_lib_xerces.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 #   AX_LIB_XERCES([MINIMUM-VERSION])
8 #
9 # DESCRIPTION
10 #
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
14 #
15 #   Macro supports following options and their values:
16 #
17 #   1) Single-option usage:
18 #
19 #     --with-xerces - yes, no or path to Xerces installation prefix
20 #
21 #   2) Three-options usage (all options are required):
22 #
23 #     --with-xerces=yes
24 #     --with-xerces-inc - path to base directory with Xerces headers
25 #     --with-xerces-lib - linker flags for Xerces
26 #
27 #   This macro calls:
28 #
29 #     AC_SUBST(XERCES_CFLAGS)
30 #     AC_SUBST(XERCES_LDFLAGS)
31 #     AC_SUBST(XERCES_VERSION) - only if version requirement is used
32 #
33 #   And sets:
34 #
35 #     HAVE_XERCES
36 #
37 # LAST MODIFICATION
38 #
39 #   2008-04-12
40 #
41 # COPYLEFT
42 #
43 #   Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net>
44 #
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.
48
49 AC_DEFUN([AX_LIB_XERCES],
50 [
51 #    AC_REQUIRE([ACX_PTHREAD])
52
53     AC_ARG_WITH([xerces],
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)]
56         ),
57         [
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
62                 xerces_prefix=/usr
63             else
64                 xerces_prefix=""
65             fi
66             xerces_requested="yes"
67         elif test -d "$withval"; then
68             xerces_prefix="$withval"
69             xerces_requested="yes"
70         else
71             xerces_prefix=""
72             xerces_requested="no"
73         fi
74         ],
75         [
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
80             xerces_prefix=/usr
81         else
82             xerces_prefix=""
83         fi
84         ]
85     )
86
87     AC_ARG_WITH([xerces-inc],
88         AC_HELP_STRING([--with-xerces-inc=@<:@DIR@:>@],
89             [path to Xerces C++ Parser headers]
90         ),
91         [xerces_include_dir="$withval"],
92         [xerces_include_dir=""]
93     )
94     AC_ARG_WITH([xerces-lib],
95         AC_HELP_STRING([--with-xerces-lib=@<:@ARG@:>@],
96             [link options for Xerces C++ Parser libraries]
97         ),
98         [xerces_ldflags="$withval"],
99         [xerces_ldflags=""]
100     )
101
102     XERCES_CPPFLAGS=""
103     XERCES_LDFLAGS=""
104     XERCES_VERSION=""
105
106     dnl
107     dnl Collect include/lib paths and flags
108     dnl
109     run_xerces_test="no"
110
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"
120         fi
121     else
122         run_xerces_test="no"
123     fi
124
125     xerces_libs="-lxerces-c"
126
127     dnl
128     dnl Check Xerces C++ Parser files
129     dnl
130     if test "$run_xerces_test" = "yes"; then
131
132         saved_CPPFLAGS="$CPPFLAGS"
133         CPPFLAGS="$CPPFLAGS -I$xerces_include_dir -I$xerces_include_dir2"
134
135         saved_LDFLAGS="$LDFLAGS"
136         LDFLAGS="$LDFLAGS $xerces_ldflags $PTHREAD_LDFLAGS"
137
138         saved_LIBS="$LIBS"
139         LIBS="$xerces_libs $PTHREAD_LIBS $LIBS"
140
141         dnl
142         dnl Check Xerces headers
143         dnl
144         AC_MSG_CHECKING([for Xerces C++ Parser headers in $xerces_include_dir and $xerces_include_dir2])
145
146         AC_LANG_PUSH([C++])
147         AC_COMPILE_IFELSE([
148             AC_LANG_PROGRAM(
149                 [[
150 @%:@include <xercesc/util/XercesDefs.hpp>
151 @%:@include <xercesc/util/PlatformUtils.hpp>
152                 ]],
153                 [[]]
154             )],
155             [
156             XERCES_CPPFLAGS="-I$xerces_include_dir -I$xerces_include_dir2"
157             xerces_header_found="yes"
158             AC_MSG_RESULT([found])
159             ],
160             [
161             xerces_header_found="no"
162             AC_MSG_RESULT([not found])
163             ]
164         )
165         AC_LANG_POP([C++])
166
167         dnl
168         dnl Check Xerces libraries
169         dnl
170         if test "$xerces_header_found" = "yes"; then
171
172             AC_MSG_CHECKING([for Xerces C++ Parser libraries])
173
174             AC_LANG_PUSH([C++])
175             AC_LINK_IFELSE([
176                 AC_LANG_PROGRAM(
177                     [[
178 @%:@include <xercesc/util/XercesDefs.hpp>
179 @%:@include <xercesc/util/PlatformUtils.hpp>
180 #if (_XERCES_VERSION >= 20200)
181 XERCES_CPP_NAMESPACE_USE
182 #endif
183                     ]],
184                     [[
185 XMLPlatformUtils::Initialize();
186                     ]]
187                 )],
188                 [
189                 XERCES_LDFLAGS="$xerces_ldflags $PTHREAD_LDFLAGS"
190                 XERCES_LIBS="$xerces_libs $PTHREAD_LIBS"
191                 xerces_lib_found="yes"
192                 AC_MSG_RESULT([found])
193                 ],
194                 [
195                 xerces_lib_found="no"
196                 AC_MSG_RESULT([not found])
197                 ]
198             )
199             AC_LANG_POP([C++])
200         fi
201
202         CPPFLAGS="$saved_CPPFLAGS"
203         LDFLAGS="$saved_LDFLAGS"
204         LIBS="$saved_LIBS"
205     fi
206
207     AC_MSG_CHECKING([for Xerces C++ Parser])
208
209     if test "$run_xerces_test" = "yes"; then
210         if test "$xerces_header_found" = "yes" -a "$xerces_lib_found" = "yes"; then
211
212             AC_SUBST([XERCES_CPPFLAGS])
213             AC_SUBST([XERCES_LDFLAGS])
214             AC_SUBST([XERCES_LIBS])
215
216             HAVE_XERCES="yes"
217         else
218             HAVE_XERCES="no"
219         fi
220
221         AC_MSG_RESULT([$HAVE_XERCES])
222
223         dnl
224         dnl Check Xerces version
225         dnl
226         if test "$HAVE_XERCES" = "yes"; then
227
228             xerces_version_req=ifelse([$1], [], [], [$1])
229
230             if test  -n "$xerces_version_req"; then
231
232                 AC_MSG_CHECKING([if Xerces C++ Parser version is >= $xerces_version_req])
233
234                 if test -f "$xerces_include_dir2/util/XercesVersion.hpp"; then
235
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.//'`
239
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.//'`
243
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.//'`
247
248                     XERCES_VERSION="$xerces_major.$xerces_minor.$xerces_revision"
249                     AC_SUBST([XERCES_VERSION])
250
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"
257                     fi
258
259                     xerces_version_req_number=`expr $xerces_version_req_major \* 10000 \
260                                                \+ $xerces_version_req_minor \* 100 \
261                                                \+ $xerces_version_req_revision`
262
263                     dnl Calculate numerical representation of detected version
264                     xerces_version_number=`expr $xerces_major \* 10000 \
265                                           \+ $xerces_minor \* 100 \
266                                            \+ $xerces_revision`
267
268                     xerces_version_check=`expr $xerces_version_number \>\= $xerces_version_req_number`
269                     if test "$xerces_version_check" = "1"; then
270                         AC_MSG_RESULT([yes])
271                     else
272                         AC_MSG_RESULT([no])
273                         AC_MSG_WARN([Found Xerces C++ Parser $XERCES_VERSION, which is older than required. Possible compilation failure.])
274                     fi
275                 else
276                     AC_MSG_RESULT([no])
277                     AC_MSG_WARN([Missing header XercesVersion.hpp. Unable to determine Xerces version.])
278                 fi
279             fi
280         fi
281
282     else
283         HAVE_XERCES="no"
284         AC_MSG_RESULT([$HAVE_XERCES])
285
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])
288         fi
289     fi
290     if test "$HAVE_XERCES" = "yes"; then
291         CPPFLAGS="$CPPFLAGS -DHAVE_XERCES_C=1"
292     fi
293 ])