Add code paths for new xmlsec APIs, and allow for undetermined signature algorithm.
[shibboleth/cpp-xmltooling.git] / configure.ac
1 AC_PREREQ([2.50])
2 AC_INIT([xmltooling], [1.4], [mace-opensaml-users@internet2.edu], [xmltooling])
3 AM_CONFIG_HEADER(config.h)
4 AM_CONFIG_HEADER(xmltooling/config_pub.h)
5 AM_INIT_AUTOMAKE([xmltooling], [1.4])
6
7 sinclude(doxygen.m4)
8 sinclude(acx_pthread.m4)
9 sinclude(ax_create_pkgconfig_info.m4)
10
11 # Docygen features
12 DX_HTML_FEATURE(ON)
13 DX_CHM_FEATURE(OFF)
14 DX_CHI_FEATURE(OFF)
15 DX_MAN_FEATURE(OFF)
16 DX_RTF_FEATURE(OFF)
17 DX_XML_FEATURE(OFF)
18 DX_PDF_FEATURE(OFF)
19 DX_PS_FEATURE(OFF)
20 DX_INIT_DOXYGEN(xmltooling, doxygen.cfg, doc/api)
21
22 AC_ARG_ENABLE(debug,
23     AC_HELP_STRING(--enable-debug, [Have GCC compile with symbols (Default = no)]),
24     enable_debug=$enableval, enable_debug=no)
25
26 if test "$enable_debug" = "yes" ; then
27     GCC_CFLAGS="$CFLAGS -g -D_DEBUG"
28     GCC_CXXFLAGS="$CXXFLAGS -g -D_DEBUG"
29 else
30     GCC_CFLAGS="$CFLAGS -O2 -DNDEBUG"
31     GCC_CXXFLAGS="$CXXFLAGS -O2 -DNDEBUG"
32 fi
33
34 AC_PROG_CC([gcc gcc3 cc])
35 AC_PROG_CXX([g++ g++3 c++ CC])
36 AC_CANONICAL_HOST
37
38 if test "$GCC" = "yes" ; then
39 #    AC_HAVE_GCC_VERSION(4,0,0,0,
40 #        [
41 #        AC_DEFINE(GCC_HASCLASSVISIBILITY,1,
42 #            [Define to enable class visibility control in gcc.])
43 #        GCC_CFLAGS="$GCC_CFLAGS -fvisibility=hidden -fvisibility-inlines-hidden"
44 #        GCC_CXXFLAGS="$GCC_CXXFLAGS -fvisibility=hidden -fvisibility-inlines-hidden"
45 #        ])
46     CFLAGS="-Wall $GCC_CFLAGS"
47     CXXFLAGS="-Wall $GCC_CXXFLAGS"
48 else
49 # Fix for Sun Workshop compiler in debug mode, may be Sun case #6360993
50         case "${host_cpu}-${host_os}" in
51                 *solaris*)
52                         if test "$CXX" = "CC" ; then
53                                 CXXFLAGS="$CXXFLAGS -Qoption ccfe -stabs=no%dfltlit+no%dflthlp"
54                         fi
55                 ;;
56         esac
57 fi
58
59 AC_DISABLE_STATIC
60 AC_PROG_LIBTOOL
61
62 # Checks for typedefs, structures, and compiler characteristics.
63 AC_C_CONST
64 AC_TYPE_SIZE_T
65 AC_CHECK_SIZEOF([long])
66
67 # Checks for library functions.
68 AC_CHECK_FUNCS([strchr strdup strstr timegm strcasecmp])
69 AC_CHECK_HEADERS([dlfcn.h])
70 AC_CHECK_FUNC(dlclose, , [ AC_CHECK_LIB(dl, dlopen) ])
71
72 # checks for pthreads
73 ACX_PTHREAD([enable_threads="pthread"],[enable_threads="no"])
74 if test $enable_threads != "pthread"; then
75     AC_MSG_ERROR([unable to find pthreads, currently this is required])
76 else
77     AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])
78         AM_CONDITIONAL(BUILD_PTHREAD,test "$enable_threads" = "pthread")
79     LIBS="$PTHREAD_LIBS $LIBS"
80     CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
81     CXXFLAGS="$PTHREAD_CFLAGS $CXXFLAGS"
82 fi
83
84 AC_CHECK_FUNCS([pthread_rwlock_init])
85
86 AC_LANG(C++)
87
88 # C++ requirements
89 AC_CXX_REQUIRE_STL
90 AC_CXX_NAMESPACES
91
92 # are covariant methods allowed?
93 AC_TRY_LINK(
94      [ class base { public: virtual base *GetPtr( void ) { return this; } }; ],
95      [ class derived: virtual public base { public: virtual derived *GetPtr( void ) { return this; } }; ],
96      [AC_DEFINE([HAVE_COVARIANT_RETURNS], [1], [Define to 1 if C++ compiler supports covariant virtual methods.])])
97
98 # log4shib settings (favor this version over the log4cpp code)
99 AC_PATH_PROG(LOG4SHIB_CONFIG,log4shib-config)
100 AC_ARG_WITH(log4shib,
101     AC_HELP_STRING([--with-log4shib=PATH], [where log4shib-config is installed]),
102     [
103     LOG4SHIB_CONFIG="${with_log4shib}"
104     if ! test -f "${LOG4SHIB_CONFIG}" ; then
105         LOG4SHIB_CONFIG="${with_log4shib}/bin/log4shib-config"
106     fi
107     ])
108 if test -f "${LOG4SHIB_CONFIG}"; then
109     LDFLAGS="`${LOG4SHIB_CONFIG} --libs` $LDFLAGS"
110     CPPFLAGS="`${LOG4SHIB_CONFIG} --cflags` $CPPFLAGS"
111         AC_CHECK_HEADER([log4shib/CategoryStream.hh],,AC_MSG_ERROR([unable to find log4shib header files]))
112         AC_TRY_LINK(
113                 [#include <log4shib/Category.hh>
114 #include <log4shib/CategoryStream.hh>],
115                 [log4shib::Category::getInstance("foo").errorStream() << log4shib::eol],
116                 [AC_DEFINE([XMLTOOLING_LOG4SHIB], [1], [Define to 1 if log4shib library is used.])],
117                 [AC_MSG_ERROR([unable to link with log4shib])])
118 else
119     AC_MSG_WARN([log4shib-config not found, may need to use --with-log4shib option])
120     AC_MSG_WARN([will look for original log4cpp library])
121     
122         # log4cpp settings
123         AC_PATH_PROG(LOG4CPP_CONFIG,log4cpp-config)
124         AC_ARG_WITH(log4cpp,
125             AC_HELP_STRING([--with-log4cpp=PATH], [where log4cpp-config is installed]),
126             [
127             LOG4CPP_CONFIG="${with_log4cpp}"
128             if ! test -f "${LOG4CPP_CONFIG}" ; then
129                 LOG4CPP_CONFIG="${with_log4cpp}/bin/log4cpp-config"
130             fi
131             ])
132         if test -f "${LOG4CPP_CONFIG}"; then
133                 AC_MSG_WARN([will try to use log4cpp, note that most non-Internet2 supplied versions are not thread-safe])
134             LDFLAGS="`${LOG4CPP_CONFIG} --libs` $LDFLAGS"
135             CPPFLAGS="`${LOG4CPP_CONFIG} --cflags` $CPPFLAGS"
136                 AC_CHECK_HEADER([log4cpp/CategoryStream.hh],,AC_MSG_ERROR([unable to find log4cpp header files]))
137                 AC_TRY_LINK(
138                         [#include <log4cpp/Category.hh>
139 #include <log4cpp/CategoryStream.hh>],
140                         [log4cpp::Category::getInstance("foo").errorStream() << log4cpp::eol],
141                         [AC_DEFINE([XMLTOOLING_LOG4CPP], [1], [Define to 1 if log4cpp library is used.])],
142                         [AC_MSG_ERROR([unable to link with log4cpp, need version 1.0 or later])])
143         else
144             AC_MSG_ERROR([log4cpp-config not found, may need to use --with-log4cpp option])
145         fi
146 fi
147
148 # Xerces settings
149 AC_ARG_WITH(xerces, 
150             AC_HELP_STRING([--with-xerces=PATH], [where xerces-c is installed]),
151             [if test x_$with_xerces != x_/usr; then
152                 LDFLAGS="-L${with_xerces}/lib $LDFLAGS"
153                 CPPFLAGS="-I${with_xerces}/include $CPPFLAGS"
154             fi])
155 LIBS="-lxerces-c $LIBS"
156 AC_CHECK_HEADER([xercesc/dom/DOM.hpp],,AC_MSG_ERROR([unable to find xerces header files]))
157 AC_MSG_CHECKING([Xerces version])
158 AC_PREPROC_IFELSE(
159     [AC_LANG_PROGRAM([#include <xercesc/util/XercesVersion.hpp>],
160 [#if  _XERCES_VERSION != 20600
161 int i = 0;
162 #else
163 #error cannot use version 2.6.0
164 #endif])],
165     [AC_MSG_RESULT(OK)],
166     [AC_MSG_FAILURE([Xerces-C v2.6.0 has bugs that inhibit use with signed XML, please use a newer version])])
167 AC_TRY_LINK(
168         [#include <xercesc/util/PlatformUtils.hpp>],
169         [xercesc::XMLPlatformUtils::Initialize()],
170         [AC_DEFINE([HAVE_LIBXERCESC], [1], [Define to 1 if Xerces-C library was found])],
171         [AC_MSG_ERROR([unable to link with Xerces])])
172
173 AC_MSG_CHECKING([whether Xerces is 64-bit clean])
174 AC_TRY_COMPILE([#include <xercesc/framework/MemBufInputSource.hpp>],
175     [using namespace XERCES_CPP_NAMESPACE;
176       XMLFilePos testvar;
177     ],
178     [AC_MSG_RESULT([yes])]
179     [AC_DEFINE([XMLTOOLING_XERCESC_64BITSAFE], [1], [Define to 1 if Xerces has a 64-bit-safe API.])],
180     [AC_MSG_RESULT([no])])
181
182 AC_MSG_CHECKING([whether Xerces BinInputStream requires getContentType])
183 AC_TRY_COMPILE([#include <xercesc/util/BinMemInputStream.hpp>],
184     [using namespace XERCES_CPP_NAMESPACE;
185       XMLByte buf[1024];
186       BinMemInputStream in(buf,1024);
187       in.getContentType();
188     ],
189     [AC_MSG_RESULT([yes])]
190     [AC_DEFINE([XMLTOOLING_XERCESC_INPUTSTREAM_HAS_CONTENTTYPE], [1], [Define to 1 if Xerces InputStream class requires getContentType.])],
191     [AC_MSG_RESULT([no])])
192
193 AC_MSG_CHECKING([whether Xerces DOMLS API is compliant])
194 AC_TRY_COMPILE([#include <xercesc/dom/DOM.hpp>],
195     [using namespace XERCES_CPP_NAMESPACE;
196         DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(NULL);
197         DOMLSSerializer *ls = ((DOMImplementationLS*)impl)->createLSSerializer();
198     ],
199     [AC_MSG_RESULT([yes])]
200     [AC_DEFINE([XMLTOOLING_XERCESC_COMPLIANT_DOMLS], [1], [Define to 1 if Xerces supports a compliant DOMLS API.])],
201     [AC_MSG_RESULT([no])])
202
203 AC_MSG_CHECKING([whether Xerces has setIdAttribute(XMLCh*, bool)])
204 AC_TRY_COMPILE([#include <xercesc/dom/DOM.hpp>],
205       [using namespace XERCES_CPP_NAMESPACE;
206           DOMElement * elt;
207           elt->setIdAttribute(NULL, false);
208       ],
209       [AC_MSG_RESULT([yes])]
210       [AC_DEFINE([XMLTOOLING_XERCESC_BOOLSETIDATTRIBUTE], [1], [Define to 1 if Xerces DOM ID methods take extra parameter.])],
211       [AC_MSG_RESULT([no])])
212
213 # XML-Security settings
214 AC_ARG_WITH(xmlsec,
215             AC_HELP_STRING([--with-xmlsec=PATH], [where xmlsec is installed]),,
216             [with_xmlsec=/usr])
217
218 if test x_$with_xmlsec != x_no; then
219
220     # OpenSSL settings (need to do this first in case it's in a different spot from xmlsec)
221     AC_ARG_WITH(openssl,
222         AC_HELP_STRING([--with-openssl=PATH], [where openssl is installed]),
223         [if test x_$with_openssl != x_/usr; then
224             SSLFLAGS="-I${with_openssl}/include"
225             SSLLIBS="-L${with_openssl}/lib -lcrypto -lssl"
226         else
227             SSLLIBS="-lcrypto -lssl"
228         fi])
229     
230     if test "x$SSLLIBS" = "x" ; then
231         AC_PATH_PROG(PKG_CONFIG, pkg-config)
232         if test "x$PKG_CONFIG" != x && test "x$PKG_CONFIG" != "xno" ; then
233             if pkg-config openssl ; then
234                 SSLLIBS="`$PKG_CONFIG --libs openssl`"
235                 SSLFLAGS="`$PKG_CONFIG --cflags openssl`"
236             else
237                 AC_MSG_WARN([OpenSSL not supported by pkg-config, try --with-openssl instead])
238             fi
239         fi
240     fi
241     
242     if test "x$SSLLIBS" = "x" ; then
243         SSLLIBS="-lcrypto -lssl"
244     fi
245     
246     AC_MSG_CHECKING(for OpenSSL cflags)
247     AC_MSG_RESULT($SSLFLAGS)
248     CPPFLAGS="$CPPFLAGS $SSLFLAGS"
249     AC_MSG_CHECKING(for OpenSSL libraries)
250     AC_MSG_RESULT($SSLLIBS)
251     XMLSEC_LIBS="$XMLSEC_LIBS $SSLLIBS"
252
253     # save and append master libs
254     save_LIBS="$LIBS"
255     LIBS="$XMLSEC_LIBS $LIBS"
256     
257     AC_CHECK_HEADER([openssl/pem.h],,
258                     AC_MSG_ERROR([unable to find openssl header files]))
259     AC_MSG_CHECKING(for ERR_load_CRYPTO_string)
260     AC_TRY_LINK_FUNC([ERR_load_CRYPTO_strings],,
261                  AC_MSG_ERROR([unable to link with openssl libraries]))
262     AC_MSG_RESULT(yes)
263
264     # restore master libs
265     LIBS="$save_LIBS"
266
267     if test x_$with_xmlsec != x_/usr; then
268         CPPFLAGS="-I${with_xmlsec}/include $CPPFLAGS"
269         LDFLAGS="-L${with_xmlsec}/lib $LDFLAGS"
270     fi        
271     XMLSEC_LIBS="$XMLSEC_LIBS -lxml-security-c"
272     
273     # save and append master libs
274     save_LIBS="$LIBS"
275     LIBS="$XMLSEC_LIBS $LIBS"
276     
277     AC_CHECK_HEADER([xsec/utils/XSECPlatformUtils.hpp],,AC_MSG_ERROR([unable to find XML-Security header files]))
278     AC_MSG_CHECKING([XML-Security version])
279     AC_PREPROC_IFELSE(
280             [AC_LANG_PROGRAM([#include <xsec/utils/XSECPlatformUtils.hpp>],
281         [#if XSEC_VERSION_MAJOR > 1 || (XSEC_VERSION_MAJOR == 1 && XSEC_VERSION_MEDIUM > 3)
282 int i = 0;
283 #else
284 #error need version 1.4.0 or later
285 #endif])],
286         [AC_MSG_RESULT(OK)],
287         [AC_MSG_FAILURE([XML-Security version 1.4.0 or greater is required.])])
288     AC_TRY_LINK(
289             [#include <xsec/utils/XSECPlatformUtils.hpp>],
290             [XSECPlatformUtils::Initialise()],,
291             [AC_MSG_ERROR([unable to link with XML-Security])])
292     AC_CHECK_TYPE([xsecsize_t],[AC_DEFINE([HAVE_XSECSIZE_T], [1], [Define to 1 if you have the 'xsecsize_t' type.])])
293
294     AC_MSG_CHECKING([whether XML-Security-C has multiple CRL support])
295     AC_TRY_COMPILE([#include <xsec/dsig/DSIGKeyInfoList.hpp>],
296           [DSIGKeyInfoList* klist; klist->getX509CRLListSize();],
297           [AC_MSG_RESULT([yes])]
298           [AC_DEFINE([XMLTOOLING_XMLSEC_MULTIPLECRL], [1], [Define to 1 if XML-Security-C handles multiple CRLs.])],
299           [AC_MSG_RESULT([no])])
300
301     AC_MSG_CHECKING([whether XML-Security-C exposes the signature algorithm URI])
302     AC_TRY_COMPILE([#include <xsec/dsig/DSIGSignature.hpp>],
303           [DSIGSignature* sig; sig->getAlgorithmURI();],
304           [AC_MSG_RESULT([yes])]
305           [AC_DEFINE([XMLTOOLING_XMLSEC_SIGALGORITHM], [1], [Define to 1 if XML-Security-C exposes the signature algorithm URI.])],
306           [AC_MSG_RESULT([no])])
307
308         # restore master libs
309         LIBS="$save_LIBS"
310
311         # libcurl settings
312         AC_PATH_PROG(CURL_CONFIG,curl-config)
313         AC_ARG_WITH(curl,
314             AC_HELP_STRING([--with-curl=PATH], [where curl-config is installed]),
315             [
316             CURL_CONFIG="${with_curl}"
317             if ! test -f "${CURL_CONFIG}" ; then
318                 CURL_CONFIG="${with_curl}/bin/curl-config"
319             fi
320             ])
321         if test -f "${CURL_CONFIG}" ; then
322             CPPFLAGS="`${CURL_CONFIG} --cflags` $CPPFLAGS"
323             XMLSEC_LIBS="`${CURL_CONFIG} --libs` $XMLSEC_LIBS"
324         else
325             AC_MSG_ERROR([curl-config not found, may need to use --with-curl option])
326         fi
327
328         # save and append master libs
329         save_LIBS="$LIBS"
330         LIBS="$XMLSEC_LIBS $LIBS"
331         
332         AC_CHECK_HEADER([curl/curl.h],,AC_MSG_ERROR([unable to find libcurl header files]))
333         AC_CHECK_LIB([curl],[curl_global_init],,AC_MSG_ERROR([unable to link with libcurl]))
334         AC_MSG_CHECKING([for CURLOPT_SSL_CTX_FUNCTION in curl.h])
335         AC_EGREP_HEADER([CURLOPT_SSL_CTX_FUNCTION], [curl/curl.h],
336                         [AC_MSG_RESULT(yes)],
337                         [AC_MSG_ERROR([need libcurl that supports CURLOPT_SSL_CTX_FUNCTION])])
338     AC_CHECK_TYPE([curl_off_t],[AC_DEFINE([HAVE_CURL_OFF_T], [1], [Define to 1 if you have the 'curl_off_t' type.])])
339
340         # restore master libs
341         LIBS="$save_LIBS"
342
343         AC_SUBST(XMLSEC_LIBS)
344 else
345     AC_MSG_WARN([xmlsec disabled, building without signature/encryption support])
346     AC_DEFINE([XMLTOOLING_NO_XMLSEC], [1], [Define to 1 if you wish to disable XML-Security-dependent features.])
347 fi
348 AM_CONDITIONAL(BUILD_XMLSEC,test x_$with_xmlsec != x_no)
349
350 # Does the STL in use help or screw us?
351 AC_TRY_LINK(
352         [#include <string>],
353         [std::basic_string<unsigned short> foo; foo=foo+(unsigned short)65],
354         [AC_DEFINE([HAVE_GOOD_STL], [1],
355             [Define to 1 if you have an STL implementation that supports useful string specialization.])],
356         )
357 AC_TRY_LINK(
358         [#include <vector>],
359         [std::iterator_traits<std::vector<int>::iterator>::value_type foo=0],
360         [AC_DEFINE([HAVE_ITERATOR_TRAITS], [1],
361             [Define to 1 if you have an STL implementation that supports std::iterator_traits.])],
362         )
363
364 # Check for unit test support
365 CXXTEST="/usr/bin/cxxtestgen.pl"
366 CXXTESTFLAGS=""
367 AC_ARG_WITH(cxxtest,
368             AC_HELP_STRING([--with-cxxtest=PATH], [where cxxtest is installed]),
369             [if test x_$with_cxxtest != x_/usr; then
370                 CXXTEST="${with_cxxtest}/cxxtestgen.pl"
371                 CXXTESTFLAGS="-I${with_cxxtest}"
372             fi])
373 if ! test -f "${CXXTEST}"; then
374     AC_MSG_WARN([cxxtestgen not found, won't build unit tests])
375 fi
376
377 AC_SUBST(CXXTEST)
378 AC_SUBST(CXXTESTFLAGS)
379 AM_CONDITIONAL(BUILD_UNITTEST,test -f ${CXXTEST})
380
381 AX_CREATE_PKGCONFIG_INFO(,,[$XMLSEC_LIBS -lxmltooling],[OpenSAML XMLTooling-C library])
382
383 LIBTOOL="$LIBTOOL --silent"
384
385 # output packaging and makefiles
386 AC_CONFIG_FILES([xmltooling.spec pkginfo Portfile])
387 AC_CONFIG_FILES([Makefile xmltooling/Makefile xmltoolingtest/Makefile schemas/Makefile doc/Makefile])
388 AC_OUTPUT