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