Conditional xmlsec support
[shibboleth/cpp-xmltooling.git] / configure.ac
1 AC_PREREQ([2.50])
2 AC_INIT([xmltooling], [1.0], [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.0])
6
7 sinclude(acx_pthread.m4)
8
9 AC_ARG_ENABLE(debug,
10     AC_HELP_STRING(--enable-debug, [Have GCC compile with symbols (Default = no)]),
11     enable_debug=$enableval, enable_debug=no)
12
13 if test "$enable_debug" = "yes" ; then
14     GCC_CFLAGS="$CFLAGS -g -D_DEBUG"
15     GCC_CXXFLAGS="$CXXFLAGS -g -D_DEBUG"
16 else
17     GCC_CFLAGS="$CFLAGS -O2 -DNDEBUG"
18     GCC_CXXFLAGS="$CXXFLAGS -O2 -DNDEBUG"
19 fi
20
21 AC_PROG_CC([gcc gcc3 cc])
22 AC_PROG_CXX([g++ g++3 c++ CC])
23
24 if test "$GCC" = "yes" ; then
25     CFLAGS="$GCC_CFLAGS"
26     CXXFLAGS="$GCC_CXXFLAGS"
27 fi
28
29 AC_DISABLE_STATIC
30 AC_PROG_LIBTOOL
31
32 AC_LANG(C++)
33
34 # C++ requirements
35 AC_CXX_REQUIRE_STL
36 AC_CXX_NAMESPACES
37
38 AC_LANG(C)
39
40 # checks for pthreads
41 ACX_PTHREAD([enable_threads="pthread"],[enable_threads="no"])
42 if test $enable_threads != "pthread"; then
43     AC_MSG_ERROR([unable to find pthreads, currently this is required])
44 else
45     AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])
46     LIBS="$PTHREAD_LIBS $LIBS"
47     CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
48     CXXFLAGS="$PTHREAD_CFLAGS $CXXFLAGS"
49 fi
50
51 # Checks for typedefs, structures, and compiler characteristics.
52 AC_C_CONST
53 AC_TYPE_SIZE_T
54 AC_STRUCT_TM
55 AC_STRUCT_TIMEZONE
56
57 # Checks for library functions.
58 AC_FUNC_STRFTIME
59 AC_CHECK_FUNCS([strchr strdup strstr gmtime_r timegm])
60 AC_CHECK_HEADERS([dlfcn.h])
61
62 # OpenSSL settings
63 AC_PATH_PROG(PKG_CONFIG, pkg-config)
64 if test "x$PKG_CONFIG" = x || test "x$PKG_CONFIG" = "xno" ; then
65     AC_ARG_WITH(openssl, 
66             AC_HELP_STRING([--with-openssl=PATH], [where openssl is installed]),
67             [if test x_$with_openssl != x_/usr; then
68                 SSLLIBS="-L${with_openssl}/lib"
69                 SSLFLAGS="-I${with_openssl}/include"
70             fi])
71     SSLLIBS="$SSLLIBS -lssl -lcrypto"
72 else
73     SSLLIBS="`$PKG_CONFIG --libs openssl`"
74     SSLFLAGS="`$PKG_CONFIG --cflags openssl`"
75 fi
76 AC_MSG_CHECKING(for OpenSSL libraries)
77 AC_MSG_RESULT($SSLLIBS)
78 LIBS="$LIBS $SSLLIBS"
79 AC_MSG_CHECKING(for OpenSSL cflags)
80 AC_MSG_RESULT($SSLFLAGS)
81 CPPFLAGS="$SSLFLAGS $CPPFLAGS"
82
83 AC_CHECK_HEADER([openssl/ssl.h],,
84                 AC_MSG_ERROR([unable to find openssl header files]))
85 AC_MSG_CHECKING(for ERR_load_CRYPTO_string)
86 AC_TRY_LINK_FUNC([ERR_load_CRYPTO_strings],,
87              AC_MSG_ERROR([unable to link with openssl libraries]))
88 AC_MSG_RESULT(yes)
89 AC_MSG_CHECKING(for SSL_library_init)
90 AC_TRY_LINK_FUNC([SSL_library_init],, 
91              AC_MSG_ERROR([unable to link with openssl libraries]))
92 AC_MSG_RESULT(yes)
93
94 # libcurl settings
95 AC_PATH_PROG(CURL_CONFIG,curl-config)
96 AC_ARG_WITH(curl,
97             AC_HELP_STRING([--with-curl=PATH], [where libcurl is installed]),
98             [CURL_CONFIG="${with_curl}/bin/curl-config"])
99 if test -f "${CURL_CONFIG}"; then
100     LDFLAGS="`${CURL_CONFIG} --libs` $LDFLAGS"
101     CPPFLAGS="`${CURL_CONFIG} --cflags` $CPPFLAGS"
102 else
103     AC_MSG_WARN([curl-config not found, guessing at libcurl build settings])
104 fi
105 AC_CHECK_HEADER([curl/curl.h],,AC_MSG_ERROR([unable to find libcurl header files]))
106 AC_CHECK_LIB([curl],[curl_global_init],,AC_MSG_ERROR([unable to link with libcurl]))
107 AC_MSG_CHECKING([for CURLOPT_SSL_CTX_FUNCTION in curl.h])
108 AC_EGREP_HEADER([CURLOPT_SSL_CTX_FUNCTION], [curl/curl.h],
109                 [AC_MSG_RESULT(yes)],
110                 [AC_MSG_ERROR([need libcurl that supports CURLOPT_SSL_CTX_FUNCTION])])
111
112 AC_LANG(C++)
113
114 # log4cpp settings
115 AC_PATH_PROG(LOG4CPP_CONFIG,log4cpp-config)
116 AC_ARG_WITH(log4cpp,
117             AC_HELP_STRING([--with-log4cpp=PATH], [where log4cpp is installed]),
118             [LOG4CPP_CONFIG="${with_log4cpp}/bin/log4cpp-config"])
119 if test -f "${LOG4CPP_CONFIG}"; then
120     LDFLAGS="`${LOG4CPP_CONFIG} --libs` $LDFLAGS"
121     CPPFLAGS="`${LOG4CPP_CONFIG} --cflags` $CPPFLAGS"
122 else
123     AC_MSG_WARN([log4cpp-config not found, guessing at log4cpp build settings])
124     LIBS="-llog4cpp $LIBS"
125 fi
126 AC_CHECK_HEADER([log4cpp/Category.hh],,AC_MSG_ERROR([unable to find log4cpp header files]))
127 AC_CHECK_HEADER([log4cpp/PropertyConfigurator.hh],,AC_MSG_ERROR([you need at least log4cpp 0.3.x]))
128 AC_TRY_LINK(
129         [#include <log4cpp/Category.hh>],
130         [log4cpp::Category::getInstance("foo")],
131         [AC_DEFINE(HAVE_LIBLOG4CPP,1,[Define if log4cpp library was found])],
132         [AC_MSG_ERROR([unable to link with log4cpp])])
133
134 # Xerces settings
135 AC_ARG_WITH(xerces, 
136             AC_HELP_STRING([--with-xerces=PATH], [where xerces-c is installed]),
137             [if test x_$with_xerces != x_/usr; then
138                 LDFLAGS="-L${with_xerces}/lib $LDFLAGS"
139                 CPPFLAGS="-I${with_xerces}/include $CPPFLAGS"
140             fi])
141 LIBS="-lxerces-c $LIBS"
142 AC_CHECK_HEADER([xercesc/dom/DOM.hpp],,AC_MSG_ERROR([unable to find xerces header files]))
143 AC_MSG_CHECKING([Xerces version])
144 AC_PREPROC_IFELSE(
145     [AC_LANG_PROGRAM([#include <xercesc/util/XercesVersion.hpp>],
146 [#if  _XERCES_VERSION != 20600
147 int i = 0;
148 #else
149 #error cannot use version 2.6.0
150 #endif])],
151     [AC_MSG_RESULT(OK)],
152     [AC_MSG_FAILURE([Xerces-C v2.6.0 has bugs that inhibit use with signed XML, please use special 2.6.1 tarball provided by Shibboleth Project])])
153 AC_TRY_LINK(
154         [#include <xercesc/util/PlatformUtils.hpp>],
155         [xercesc::XMLPlatformUtils::Initialize()],
156         [AC_DEFINE(HAVE_LIBXERCESC,1,[Define if Xerces-C library was found])],
157         [AC_MSG_ERROR([unable to link with Xerces])])
158
159
160 # XML-Security settings
161 AC_ARG_WITH(xmlsec,
162             AC_HELP_STRING([--with-xmlsec=PATH], [where xmlsec is installed]),
163             [if test x_$with_xmlsec != x_/usr; then
164                 LDFLAGS="-L${with_xmlsec}/lib $LDFLAGS"
165                 CPPFLAGS="-I${with_xmlsec}/include $CPPFLAGS"
166             fi])
167
168 if test x_$with_xmlsec != x_no; then
169     if test x_$with_xmlsec != x_/usr; then
170         LDFLAGS="-L${with_xmlsec}/lib $LDFLAGS"
171         CPPFLAGS="-I${with_xmlsec}/include $CPPFLAGS"
172     fi        
173     LIBS="-lxml-security-c $LIBS"
174     AC_CHECK_HEADER([xsec/utils/XSECPlatformUtils.hpp],,AC_MSG_ERROR([unable to find XML-Security header files]))
175     AC_MSG_CHECKING([XML-Security version])
176     AC_PREPROC_IFELSE(
177             [AC_LANG_PROGRAM([#include <xsec/utils/XSECPlatformUtils.hpp>],
178         [#if XSEC_VERSION_MAJOR > 1 || XSEC_VERSION_MEDIUM >2 
179 int i = 0;
180 #else
181 #error need version 1.3 or later
182 #endif])],
183         [AC_MSG_RESULT(OK)],
184         [AC_MSG_FAILURE([XML-Security version 1.3 or greater is required.])])
185     AC_TRY_LINK(
186             [#include <xsec/utils/XSECPlatformUtils.hpp>],
187             [XSECPlatformUtils::Initialise()],,
188             [AC_MSG_ERROR([unable to link with XML-Sec])])
189 else
190     AC_MSG_WARN([xmlsec disabled, building without signature/encryption support])
191     [AC_DEFINE(XMLTOOLING_NO_XMLSEC,1,
192         [Define if you wish to disable XML-Security-dependent features.])]
193 fi
194 AM_CONDITIONAL(BUILD_XMLSEC,test x_$with_xmlsec != x_no)
195
196 # Does the STL in use help or screw us?
197 AC_TRY_LINK(
198         [#include <string>],
199         [std::basic_string<unsigned short> foo; foo=foo+(unsigned short)65],
200         [AC_DEFINE(HAVE_GOOD_STL,1,
201             [Define if you have an STL implementation that supports useful string specialization.])],
202         )
203
204 # Check for unit test support
205 CXXTEST="/usr/bin/cxxtestgen.pl"
206 CXXTESTFLAGS=""
207 AC_ARG_WITH(cxxtest,
208             AC_HELP_STRING([--with-cxxtest=PATH], [where cxxtest is installed]),
209             [if test x_$with_cxxtest != x_/usr; then
210                 CXXTEST="${with_cxxtest}/cxxtestgen.pl"
211                 CXXTESTFLAGS="-I${with_cxxtest}"
212             fi])
213 if ! test -f "${CXXTEST}"; then
214     AC_MSG_WARN([cxxtestgen not found, won't build unit tests])
215 fi
216
217 AC_SUBST(CXXTEST)
218 AC_SUBST(CXXTESTFLAGS)
219 AM_CONDITIONAL(BUILD_UNITTEST,test -f ${CXXTEST})
220
221 # output makefiles
222 AC_OUTPUT(Makefile xmltooling/Makefile xmltoolingtest/Makefile schemas/Makefile)