Revert reordering of libtool macros.
[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_LINK_IFELSE(
94         [AC_LANG_PROGRAM([[]],
95                 [[
96                 class base { public: virtual base *GetPtr( void ) { return this; } };
97                 class derived: virtual public base { public: virtual derived *GetPtr( void ) { return this; } };
98                 ]])],
99     [AC_DEFINE([HAVE_COVARIANT_RETURNS], [1], [Define to 1 if C++ compiler supports covariant virtual methods.])]
100         )
101
102 # is nullptr supported?
103 AC_COMPILE_IFELSE(
104         [AC_LANG_PROGRAM([[]],
105                 [[
106                 const char* ptr = nullptr;
107                 ]])],
108         [AC_DEFINE([HAVE_NULLPTR], [1], [Define to 1 if C++ compiler supports nullptr keyword.])]
109         )
110
111 # log4shib settings (favor this version over the log4cpp code)
112 AC_PATH_PROG(LOG4SHIB_CONFIG,log4shib-config)
113 AC_ARG_WITH(log4shib,
114     AC_HELP_STRING([--with-log4shib=PATH], [where log4shib-config is installed]),
115     [
116     LOG4SHIB_CONFIG="${with_log4shib}"
117     if ! test -f "${LOG4SHIB_CONFIG}" ; then
118         LOG4SHIB_CONFIG="${with_log4shib}/bin/log4shib-config"
119     fi
120     ])
121 if test -f "${LOG4SHIB_CONFIG}"; then
122     LIBS="`${LOG4SHIB_CONFIG} --libs` $LIBS"
123     CPPFLAGS="`${LOG4SHIB_CONFIG} --cflags` $CPPFLAGS"
124         AC_CHECK_HEADER([log4shib/CategoryStream.hh],,AC_MSG_ERROR([unable to find log4shib header files]))
125         AC_TRY_LINK(
126                 [#include <log4shib/Category.hh>
127 #include <log4shib/CategoryStream.hh>],
128                 [log4shib::Category::getInstance("foo").errorStream() << log4shib::eol],
129                 [AC_DEFINE([XMLTOOLING_LOG4SHIB], [1], [Define to 1 if log4shib library is used.])],
130                 [AC_MSG_ERROR([unable to link with log4shib])])
131 else
132     AC_MSG_WARN([log4shib-config not found, may need to use --with-log4shib option])
133     AC_MSG_WARN([will look for original log4cpp library])
134     
135         # log4cpp settings
136         AC_PATH_PROG(LOG4CPP_CONFIG,log4cpp-config)
137         AC_ARG_WITH(log4cpp,
138             AC_HELP_STRING([--with-log4cpp=PATH], [where log4cpp-config is installed]),
139             [
140             LOG4CPP_CONFIG="${with_log4cpp}"
141             if ! test -f "${LOG4CPP_CONFIG}" ; then
142                 LOG4CPP_CONFIG="${with_log4cpp}/bin/log4cpp-config"
143             fi
144             ])
145         if test -f "${LOG4CPP_CONFIG}"; then
146                 AC_MSG_WARN([will try to use log4cpp, note that most non-Internet2 supplied versions are not thread-safe])
147             LIBS="`${LOG4CPP_CONFIG} --libs` $LIBS"
148             CPPFLAGS="`${LOG4CPP_CONFIG} --cflags` $CPPFLAGS"
149                 AC_CHECK_HEADER([log4cpp/CategoryStream.hh],,AC_MSG_ERROR([unable to find log4cpp header files]))
150                 AC_TRY_LINK(
151                         [#include <log4cpp/Category.hh>
152 #include <log4cpp/CategoryStream.hh>],
153                         [log4cpp::Category::getInstance("foo").errorStream() << log4cpp::eol],
154                         [AC_DEFINE([XMLTOOLING_LOG4CPP], [1], [Define to 1 if log4cpp library is used.])],
155                         [AC_MSG_ERROR([unable to link with log4cpp, need version 1.0 or later])])
156         else
157             AC_MSG_ERROR([log4cpp-config not found, may need to use --with-log4cpp option])
158         fi
159 fi
160
161 # Xerces settings
162 AC_ARG_WITH(xerces, 
163             AC_HELP_STRING([--with-xerces=PATH], [where xerces-c is installed]),
164             [if test x_$with_xerces != x_/usr; then
165                 LDFLAGS="-L${with_xerces}/lib $LDFLAGS"
166                 CPPFLAGS="-I${with_xerces}/include $CPPFLAGS"
167             fi])
168 LIBS="-lxerces-c $LIBS"
169 AC_CHECK_HEADER([xercesc/dom/DOM.hpp],,AC_MSG_ERROR([unable to find xerces header files]))
170 AC_MSG_CHECKING([Xerces version])
171 AC_PREPROC_IFELSE(
172     [AC_LANG_PROGRAM([#include <xercesc/util/XercesVersion.hpp>],
173 [#if  _XERCES_VERSION != 20600
174 int i = 0;
175 #else
176 #error cannot use version 2.6.0
177 #endif])],
178     [AC_MSG_RESULT(OK)],
179     [AC_MSG_FAILURE([Xerces-C v2.6.0 has bugs that inhibit use with signed XML, please use a newer version])])
180 AC_TRY_LINK(
181         [#include <xercesc/util/PlatformUtils.hpp>],
182         [xercesc::XMLPlatformUtils::Initialize()],
183         [AC_DEFINE([HAVE_LIBXERCESC], [1], [Define to 1 if Xerces-C library was found])],
184         [AC_MSG_ERROR([unable to link with Xerces])])
185
186 AC_MSG_CHECKING([whether Xerces is 64-bit clean])
187 AC_TRY_COMPILE([#include <xercesc/framework/MemBufInputSource.hpp>],
188     [using namespace XERCES_CPP_NAMESPACE;
189       XMLFilePos testvar;
190     ],
191     [AC_MSG_RESULT([yes])]
192     [AC_DEFINE([XMLTOOLING_XERCESC_64BITSAFE], [1], [Define to 1 if Xerces has a 64-bit-safe API.])],
193     [AC_MSG_RESULT([no])])
194
195 AC_MSG_CHECKING([whether Xerces BinInputStream requires getContentType])
196 AC_TRY_COMPILE([#include <xercesc/util/BinMemInputStream.hpp>],
197     [using namespace XERCES_CPP_NAMESPACE;
198       XMLByte buf[1024];
199       BinMemInputStream in(buf,1024);
200       in.getContentType();
201     ],
202     [AC_MSG_RESULT([yes])]
203     [AC_DEFINE([XMLTOOLING_XERCESC_INPUTSTREAM_HAS_CONTENTTYPE], [1], [Define to 1 if Xerces InputStream class requires getContentType.])],
204     [AC_MSG_RESULT([no])])
205
206 AC_MSG_CHECKING([whether Xerces DOMLS API is compliant])
207 AC_TRY_COMPILE([#include <xercesc/dom/DOM.hpp>],
208     [using namespace XERCES_CPP_NAMESPACE;
209         DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(NULL);
210         DOMLSSerializer *ls = ((DOMImplementationLS*)impl)->createLSSerializer();
211     ],
212     [AC_MSG_RESULT([yes])]
213     [AC_DEFINE([XMLTOOLING_XERCESC_COMPLIANT_DOMLS], [1], [Define to 1 if Xerces supports a compliant DOMLS API.])],
214     [AC_MSG_RESULT([no])])
215
216 AC_MSG_CHECKING([whether Xerces has setIdAttribute(XMLCh*, bool)])
217 AC_TRY_COMPILE([#include <xercesc/dom/DOM.hpp>],
218       [using namespace XERCES_CPP_NAMESPACE;
219           DOMElement * elt;
220           elt->setIdAttribute(NULL, false);
221       ],
222       [AC_MSG_RESULT([yes])]
223       [AC_DEFINE([XMLTOOLING_XERCESC_BOOLSETIDATTRIBUTE], [1], [Define to 1 if Xerces DOM ID methods take extra parameter.])],
224       [AC_MSG_RESULT([no])])
225
226 AC_MSG_CHECKING([whether Xerces XMLString::release(XMLByte**) exists])
227 AC_TRY_COMPILE([#include <xercesc/util/XMLString.hpp>],
228     [using namespace XERCES_CPP_NAMESPACE;
229       XMLByte* buf=NULL;
230       XMLString::release(&buf);
231     ],
232     [AC_MSG_RESULT([yes])]
233     [AC_DEFINE([XMLTOOLING_XERCESC_HAS_XMLBYTE_RELEASE], [1], [Define to 1 if Xerces XMLString includes XMLByte release.])],
234     [AC_MSG_RESULT([no])])
235
236 # XML-Security settings
237 AC_ARG_WITH(xmlsec,
238             AC_HELP_STRING([--with-xmlsec=PATH], [where xmlsec is installed]),,
239             [with_xmlsec=/usr])
240
241 if test x_$with_xmlsec != x_no; then
242
243     # OpenSSL settings (need to do this first in case it's in a different spot from xmlsec)
244     AC_ARG_WITH(openssl,
245         AC_HELP_STRING([--with-openssl=PATH], [where openssl is installed]),
246         [if test x_$with_openssl != x_/usr; then
247             SSLFLAGS="-I${with_openssl}/include"
248             SSLLIBS="-L${with_openssl}/lib -lcrypto -lssl"
249         else
250             SSLLIBS="-lcrypto -lssl"
251         fi])
252     
253     if test "x$SSLLIBS" = "x" ; then
254         AC_PATH_PROG(PKG_CONFIG, pkg-config)
255         if test "x$PKG_CONFIG" != x && test "x$PKG_CONFIG" != "xno" ; then
256             if pkg-config openssl ; then
257                 SSLLIBS="`$PKG_CONFIG --libs openssl`"
258                 SSLFLAGS="`$PKG_CONFIG --cflags openssl`"
259             else
260                 AC_MSG_WARN([OpenSSL not supported by pkg-config, try --with-openssl instead])
261             fi
262         fi
263     fi
264     
265     if test "x$SSLLIBS" = "x" ; then
266         SSLLIBS="-lcrypto -lssl"
267     fi
268     
269     AC_MSG_CHECKING(for OpenSSL cflags)
270     AC_MSG_RESULT($SSLFLAGS)
271     CPPFLAGS="$CPPFLAGS $SSLFLAGS"
272     AC_MSG_CHECKING(for OpenSSL libraries)
273     AC_MSG_RESULT($SSLLIBS)
274     XMLSEC_LIBS="$XMLSEC_LIBS $SSLLIBS"
275
276     # save and append master libs
277     save_LIBS="$LIBS"
278     LIBS="$XMLSEC_LIBS $LIBS"
279     
280     AC_CHECK_HEADER([openssl/pem.h],,
281                     AC_MSG_ERROR([unable to find openssl header files]))
282     AC_MSG_CHECKING(for ERR_load_CRYPTO_string)
283     AC_TRY_LINK_FUNC([ERR_load_CRYPTO_strings],,
284                  AC_MSG_ERROR([unable to link with openssl libraries]))
285     AC_MSG_RESULT(yes)
286
287         AC_CHECK_DECL(EVP_sha512,
288                 [AC_DEFINE([XMLTOOLING_OPENSSL_HAVE_SHA2],[],[Define to 1 if OpenSSL supports the SHA-2 hash family.])],
289                 ,[#include <openssl/evp.h>])
290
291     # restore master libs
292     LIBS="$save_LIBS"
293
294     if test x_$with_xmlsec != x_/usr; then
295         CPPFLAGS="-I${with_xmlsec}/include $CPPFLAGS"
296         LDFLAGS="-L${with_xmlsec}/lib $LDFLAGS"
297     fi        
298     XMLSEC_LIBS="$XMLSEC_LIBS -lxml-security-c"
299     
300     # save and append master libs
301     save_LIBS="$LIBS"
302     LIBS="$XMLSEC_LIBS $LIBS"
303     
304     AC_CHECK_HEADER([xsec/utils/XSECPlatformUtils.hpp],,AC_MSG_ERROR([unable to find XML-Security header files]))
305     AC_MSG_CHECKING([XML-Security version])
306     AC_PREPROC_IFELSE(
307             [AC_LANG_PROGRAM([#include <xsec/utils/XSECPlatformUtils.hpp>],
308         [#if XSEC_VERSION_MAJOR > 1 || (XSEC_VERSION_MAJOR == 1 && XSEC_VERSION_MEDIUM > 3)
309 int i = 0;
310 #else
311 #error need version 1.4.0 or later
312 #endif])],
313         [AC_MSG_RESULT(OK)],
314         [AC_MSG_FAILURE([XML-Security version 1.4.0 or greater is required.])])
315     AC_TRY_LINK(
316             [#include <xsec/utils/XSECPlatformUtils.hpp>],
317             [XSECPlatformUtils::Initialise()],,
318             [AC_MSG_ERROR([unable to link with XML-Security])])
319     AC_CHECK_TYPE([xsecsize_t],[AC_DEFINE([HAVE_XSECSIZE_T], [1], [Define to 1 if you have the 'xsecsize_t' type.])])
320
321     AC_MSG_CHECKING([whether XML-Security-C has multiple CRL support])
322     AC_TRY_COMPILE([#include <xsec/dsig/DSIGKeyInfoList.hpp>],
323           [DSIGKeyInfoList* klist; klist->getX509CRLListSize();],
324           [AC_MSG_RESULT([yes])]
325           [AC_DEFINE([XMLTOOLING_XMLSEC_MULTIPLECRL], [1], [Define to 1 if XML-Security-C handles multiple CRLs.])],
326           [AC_MSG_RESULT([no])])
327
328     AC_MSG_CHECKING([whether XML-Security-C exposes the signature algorithm URI])
329     AC_TRY_COMPILE([#include <xsec/dsig/DSIGSignature.hpp>],
330           [DSIGSignature* sig; sig->getAlgorithmURI();],
331           [AC_MSG_RESULT([yes])]
332           [AC_DEFINE([XMLTOOLING_XMLSEC_SIGALGORITHM], [1], [Define to 1 if XML-Security-C exposes the signature algorithm URI.])],
333           [AC_MSG_RESULT([no])])
334
335     AC_MSG_CHECKING([whether XML-Security-C includes ECC support])
336     AC_TRY_COMPILE([#include <xsec/dsig/DSIGKeyInfoValue.hpp>],
337           [DSIGKeyInfoValue* info; info->getECNamedCurve();],
338           [AC_MSG_RESULT([yes])]
339           [AC_DEFINE([XMLTOOLING_XMLSEC_ECC], [1], [Define to 1 if XML-Security-C includes ECC support.])],
340           [AC_MSG_RESULT([no])])
341
342     AC_MSG_CHECKING([whether XML-Security-C includes debug logging support])
343     AC_TRY_COMPILE([#include <xsec/utils/XSECPlatformUtils.hpp>],
344           [XSECPlatformUtils::SetReferenceLoggingSink(NULL)],
345           [AC_MSG_RESULT([yes])]
346           [AC_DEFINE([XMLTOOLING_XMLSEC_DEBUGLOGGING], [1], [Define to 1 if XML-Security-C includes debug logging support.])],
347           [AC_MSG_RESULT([no])])
348
349         # restore master libs
350         LIBS="$save_LIBS"
351
352         # libcurl settings
353         AC_PATH_PROG(CURL_CONFIG,curl-config)
354         AC_ARG_WITH(curl,
355             AC_HELP_STRING([--with-curl=PATH], [where curl-config is installed]),
356             [
357             CURL_CONFIG="${with_curl}"
358             if ! test -f "${CURL_CONFIG}" ; then
359                 CURL_CONFIG="${with_curl}/bin/curl-config"
360             fi
361             ])
362         if test -f "${CURL_CONFIG}" ; then
363             CPPFLAGS="`${CURL_CONFIG} --cflags` $CPPFLAGS"
364             XMLSEC_LIBS="`${CURL_CONFIG} --libs` $XMLSEC_LIBS"
365         else
366             AC_MSG_ERROR([curl-config not found, may need to use --with-curl option])
367         fi
368
369         # save and append master libs
370         save_LIBS="$LIBS"
371         LIBS="$XMLSEC_LIBS $LIBS"
372         
373         AC_CHECK_HEADER([curl/curl.h],,AC_MSG_ERROR([unable to find libcurl header files]))
374         AC_CHECK_LIB([curl],[curl_global_init],,AC_MSG_ERROR([unable to link with libcurl]))
375         AC_MSG_CHECKING([for CURLOPT_SSL_CTX_FUNCTION in curl.h])
376         AC_EGREP_HEADER([CURLOPT_SSL_CTX_FUNCTION], [curl/curl.h],
377                         [AC_MSG_RESULT(yes)],
378                         [AC_MSG_ERROR([need libcurl that supports CURLOPT_SSL_CTX_FUNCTION])])
379     AC_CHECK_TYPE([curl_off_t],[AC_DEFINE([HAVE_CURL_OFF_T], [1], [Define to 1 if you have the 'curl_off_t' type.])])
380
381         # restore master libs
382         LIBS="$save_LIBS"
383
384         AC_SUBST(XMLSEC_LIBS)
385 else
386     AC_MSG_WARN([xmlsec disabled, building without signature/encryption support])
387     AC_DEFINE([XMLTOOLING_NO_XMLSEC], [1], [Define to 1 if you wish to disable XML-Security-dependent features.])
388 fi
389 AM_CONDITIONAL(BUILD_XMLSEC,test x_$with_xmlsec != x_no)
390
391 # Does the STL in use help or screw us?
392 AC_TRY_LINK(
393         [#include <string>],
394         [std::basic_string<unsigned short> foo; foo=foo+(unsigned short)65],
395         [AC_DEFINE([HAVE_GOOD_STL], [1],
396             [Define to 1 if you have an STL implementation that supports useful string specialization.])],
397         )
398 AC_TRY_LINK(
399         [#include <vector>],
400         [std::iterator_traits<std::vector<int>::iterator>::value_type foo=0],
401         [AC_DEFINE([HAVE_ITERATOR_TRAITS], [1],
402             [Define to 1 if you have an STL implementation that supports std::iterator_traits.])],
403         )
404
405 # Check for unit test support
406 CXXTEST="/usr/bin/cxxtestgen.pl"
407 CXXTESTFLAGS=""
408 AC_ARG_WITH(cxxtest,
409             AC_HELP_STRING([--with-cxxtest=PATH], [where cxxtest is installed]),
410             [if test x_$with_cxxtest != x_/usr; then
411                 CXXTEST="${with_cxxtest}/cxxtestgen.pl"
412                 CXXTESTFLAGS="-I${with_cxxtest}"
413             fi])
414 if ! test -f "${CXXTEST}"; then
415     AC_MSG_WARN([cxxtestgen not found, won't build unit tests])
416 fi
417
418 AC_SUBST(CXXTEST)
419 AC_SUBST(CXXTESTFLAGS)
420 AM_CONDITIONAL(BUILD_UNITTEST,test -f ${CXXTEST})
421
422 AX_CREATE_PKGCONFIG_INFO(,,[$XMLSEC_LIBS -lxmltooling],[OpenSAML XMLTooling-C library])
423
424 LIBTOOL="$LIBTOOL --silent"
425
426 # output packaging and makefiles
427 AC_CONFIG_FILES([xmltooling.spec pkginfo Portfile])
428 AC_CONFIG_FILES([Makefile xmltooling/Makefile xmltoolingtest/Makefile schemas/Makefile doc/Makefile])
429 AC_OUTPUT