Fix ordering issues with LDFLAGS and LIBS.
[shibboleth/cpp-opensaml.git] / configure.ac
1 AC_PREREQ([2.50])
2 AC_INIT([opensaml],[2.5],[https://issues.shibboleth.net/],[opensaml])
3 AC_CONFIG_SRCDIR(saml)
4 AC_CONFIG_AUX_DIR(build-aux)
5 AC_CONFIG_MACRO_DIR(m4)
6 AM_INIT_AUTOMAKE
7 AC_DISABLE_STATIC
8 AC_PROG_LIBTOOL
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(opensaml, doxygen.cfg, doc/api)
20 DX_INCLUDE=
21
22 AC_ARG_ENABLE(debug,
23     AS_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 -Wall -g -D_DEBUG"
28     GCC_CXXFLAGS="$CXXFLAGS -Wall -g -D_DEBUG"
29 else
30     GCC_CFLAGS="$CFLAGS -Wall -O2 -DNDEBUG"
31     GCC_CXXFLAGS="$CXXFLAGS -Wall -O2 -DNDEBUG"
32 fi
33
34 AC_CONFIG_HEADERS([config.h])
35 AC_CONFIG_FILES([opensaml.spec])
36 AC_CONFIG_FILES([Makefile saml/Makefile samltest/Makefile samlsign/Makefile schemas/Makefile doc/Makefile])
37
38 AC_PROG_CC([gcc gcc3 cc])
39 AC_PROG_CXX([g++ g++3 c++ CC])
40 AC_CANONICAL_HOST
41
42 if test "$GCC" = "yes" ; then
43 #    AC_HAVE_GCC_VERSION(4,0,0,0,
44 #        [
45 #        AC_DEFINE(GCC_HASCLASSVISIBILITY,1,
46 #            [Define to enable class visibility control in gcc.])
47 #        GCC_CFLAGS="$GCC_CFLAGS -fvisibility=hidden -fvisibility-inlines-hidden"
48 #        GCC_CXXFLAGS="$GCC_CXXFLAGS -fvisibility=hidden -fvisibility-inlines-hidden"
49 #        ])
50     CFLAGS="$GCC_CFLAGS"
51     CXXFLAGS="$GCC_CXXFLAGS"
52 else
53 # Fix for Sun Workshop compiler in debug mode, may be Sun case #6360993
54         case "${host_cpu}-${host_os}" in
55                 *solaris*)
56                         if test "$CXX" = "CC" ; then
57                                 CXXFLAGS="$CXXFLAGS -Qoption ccfe -stabs=no%dfltlit+no%dflthlp"
58                         fi
59                 ;;
60         esac
61 fi
62
63 # Checks for typedefs, structures, and compiler characteristics.
64 AC_C_CONST
65 AC_TYPE_SIZE_T
66 AC_HEADER_DIRENT
67
68 # Checks for library functions.
69 AC_CHECK_FUNCS([strchr strdup strstr])
70 AC_CHECK_SIZEOF(time_t)
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     LIBS="$PTHREAD_LIBS $LIBS"
79     CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
80     CXXFLAGS="$PTHREAD_CFLAGS $CXXFLAGS"
81 fi
82
83 # zlib settings
84 AC_ARG_WITH(zlib,
85     AS_HELP_STRING([--with-zlib=PATH],[where zlib is installed]),
86     [
87         if test -d "$withval" ; then
88             CPPFLAGS="${CPPFLAGS} -I$withval/include"
89             LDFLAGS="${LDFLAGS} -L$withval/lib"
90         fi
91     ]
92 )
93
94 AC_ARG_WITH(zlib,
95     AS_HELP_STRING([--with-zlib=PATH],[where zlib is installed]),,
96     [with_zlib=/usr])
97 if test x_$with_zlib != x_/usr; then
98     CPPFLAGS="-I${with_zlib}/include $CPPFLAGS"
99     LIBS="-L${with_zlib}/lib -lz $LIBS"
100 else
101     LIBS="-lz $LIBS"
102 fi
103
104 AC_CHECK_HEADER([zlib.h],,AC_MSG_ERROR([unable to find zlib header files]))
105 AC_CHECK_LIB([z],[deflateInit2_],[],AC_MSG_ERROR([unable to link with zlib library]))
106
107 # OpenSSL settings
108 AC_ARG_WITH(openssl,
109     AS_HELP_STRING([--with-openssl=PATH],[where openssl is installed]),
110     [if test x_$with_openssl != x_/usr; then
111         SSLFLAGS="-I${with_openssl}/include"
112     fi])
113
114 if test "x$with_openssl" = "x" ; then
115     AC_PATH_PROG(PKG_CONFIG, pkg-config)
116     if test "x$PKG_CONFIG" != x && test "x$PKG_CONFIG" != "xno" ; then
117         if pkg-config openssl ; then
118             SSLFLAGS="`$PKG_CONFIG --cflags openssl`"
119         else
120             AC_MSG_WARN([OpenSSL not supported by pkg-config, try --with-openssl instead])
121         fi
122     fi
123 fi
124
125 AC_MSG_CHECKING(for OpenSSL cflags)
126 AC_MSG_RESULT($SSLFLAGS)
127 CPPFLAGS="$SSLFLAGS $CPPFLAGS"
128
129 AC_CHECK_HEADER([openssl/x509.h],,AC_MSG_ERROR([unable to find openssl header files]))
130
131 AC_LANG([C++])
132
133 # C++ requirements
134 AC_CXX_NAMESPACES
135 AC_CXX_REQUIRE_STL
136
137 # log4shib settings (favor this version over the log4cpp code)
138 AC_PATH_PROG(LOG4SHIB_CONFIG,log4shib-config)
139 AC_ARG_WITH(log4shib,
140     AS_HELP_STRING([--with-log4shib=PATH],[where log4shib-config is installed]),
141     [
142     LOG4SHIB_CONFIG="${with_log4shib}"
143     if ! test -f "${LOG4SHIB_CONFIG}"; then
144         LOG4SHIB_CONFIG="${with_log4shib}/bin/log4shib-config"
145     fi
146     ])
147 if test -f "${LOG4SHIB_CONFIG}" ; then
148     LIBS="`${LOG4SHIB_CONFIG} --libs` $LIBS"
149     CPPFLAGS="`${LOG4SHIB_CONFIG} --cflags` $CPPFLAGS"
150         AC_CHECK_HEADER([log4shib/CategoryStream.hh],,AC_MSG_ERROR([unable to find log4shib header files]))
151     AC_LINK_IFELSE(
152         [AC_LANG_PROGRAM([[#include <log4shib/Category.hh>
153 #include <log4shib/CategoryStream.hh>]],
154             [[log4shib::Category::getInstance("foo").errorStream() << log4shib::eol]])],
155         [AC_DEFINE([OPENSAML_LOG4SHIB],[1],[Define to 1 if log4shib library is used.])],
156         [AC_MSG_ERROR([unable to link with log4shib])])
157 else
158     AC_MSG_WARN([log4shib-config not found, may need to use --with-log4shib option])
159     AC_MSG_WARN([will look for original log4cpp library])
160     
161     # log4cpp settings
162     AC_PATH_PROG(LOG4CPP_CONFIG,log4cpp-config)
163     AC_ARG_WITH(log4cpp,
164         AS_HELP_STRING([--with-log4cpp=PATH],[where log4cpp-config is installed]),
165         [
166         LOG4CPP_CONFIG="${with_log4cpp}"
167         if ! test -f "${LOG4CPP_CONFIG}"; then
168                 LOG4CPP_CONFIG="${with_log4cpp}/bin/log4cpp-config"
169         fi
170         ])
171     if test -f "${LOG4CPP_CONFIG}"; then
172         AC_MSG_WARN([will try to use log4cpp, note that most non-Internet2 supplied versions are not thread-safe])
173         LIBS="`${LOG4CPP_CONFIG} --libs` $LIBS"
174         CPPFLAGS="`${LOG4CPP_CONFIG} --cflags` $CPPFLAGS"
175         AC_CHECK_HEADER([log4cpp/CategoryStream.hh],,AC_MSG_ERROR([unable to find log4cpp header files]))
176         AC_LINK_IFELSE(
177             [AC_LANG_PROGRAM([[#include <log4cpp/Category.hh>
178 #include <log4cpp/CategoryStream.hh>]],
179                 [[log4cpp::Category::getInstance("foo").errorStream() << log4cpp::eol]])],
180             [AC_DEFINE([OPENSAML_LOG4CPP],[1],[Define to 1 if log4cpp library is used.])],
181             [AC_MSG_ERROR([unable to link with log4cpp, need version 1.0 or later])])
182     else
183         AC_MSG_ERROR([log4cpp-config not found, may need to use --with-log4cpp option])
184     fi
185 fi
186
187 # Xerces settings
188 AC_ARG_WITH(xerces,
189     AS_HELP_STRING([--with-xerces=PATH],[where xerces-c is installed]),,
190     [with_xerces=/usr])
191 if test x_$with_xerces != x_/usr; then
192     CPPFLAGS="-I${with_xerces}/include $CPPFLAGS"
193     LIBS="-L${with_xerces}/lib -lxerces-c $LIBS"
194 else
195     LIBS="-lxerces-c $LIBS"
196 fi
197
198 AC_CHECK_HEADER([xercesc/dom/DOM.hpp],,AC_MSG_ERROR([unable to find xerces header files]))
199 AC_MSG_CHECKING([Xerces version])
200 AC_PREPROC_IFELSE(
201     [AC_LANG_PROGRAM([#include <xercesc/util/XercesVersion.hpp>],
202 [#if  _XERCES_VERSION != 20600
203 int i = 0;
204 #else
205 #error cannot use version 2.6.0
206 #endif])],
207     [AC_MSG_RESULT(OK)],
208     [AC_MSG_FAILURE([Xerces-C v2.6.0 has bugs that inhibit use with signed XML, please use a newer version])])
209 AC_LINK_IFELSE(
210     [AC_LANG_PROGRAM([[#include <xercesc/util/PlatformUtils.hpp>]],[[xercesc::XMLPlatformUtils::Initialize()]])],
211     ,[AC_MSG_ERROR([unable to link with Xerces])])
212
213 AC_MSG_CHECKING([whether Xerces XMLString::release(XMLByte**) exists])
214 AC_COMPILE_IFELSE(
215     [AC_LANG_PROGRAM([[#include <xercesc/util/XMLString.hpp>]],
216     [[using namespace XERCES_CPP_NAMESPACE; XMLByte* buf=NULL; XMLString::release(&buf);]])],
217     [AC_MSG_RESULT([yes])AC_DEFINE([OPENSAML_XERCESC_HAS_XMLBYTE_RELEASE],[1],[Define to 1 if Xerces XMLString includes XMLByte release.])],
218     [AC_MSG_RESULT([no])])
219
220 # XML-Security settings
221 AC_ARG_WITH(xmlsec,
222     AS_HELP_STRING([--with-xmlsec=PATH],[where xmlsec is installed]),,
223     [with_xmlsec=/usr])
224 if test x_$with_xmlsec != x_/usr; then
225     CPPFLAGS="-I${with_xmlsec}/include $CPPFLAGS"
226     LIBS="-L${with_xmlsec}/lib -lxml-security-c $LIBS"
227 else
228     LIBS="-lxml-security-c $LIBS"
229 fi
230 AC_CHECK_HEADER([xsec/utils/XSECPlatformUtils.hpp],,AC_MSG_ERROR([unable to find xmlsec header files]))
231 AC_MSG_CHECKING([XML-Security version])
232 AC_PREPROC_IFELSE(
233     [AC_LANG_PROGRAM([#include <xsec/utils/XSECPlatformUtils.hpp>],
234     [#if XSEC_VERSION_MAJOR > 1 || (XSEC_VERSION_MAJOR == 1 && XSEC_VERSION_MEDIUM > 3)
235 int i = 0;
236 #else
237 #error need version 1.4.0 or later
238 #endif])],
239     [AC_MSG_RESULT(OK)],
240     [AC_MSG_FAILURE([XML-Security version 1.4.0 or greater is required.])])
241     AC_LINK_IFELSE(
242         [AC_LANG_PROGRAM([[#include <xsec/utils/XSECPlatformUtils.hpp>]],
243             [[XSECPlatformUtils::Initialise()]])],,
244         [AC_MSG_ERROR([unable to link with XML-Security])])
245
246 # XML-Tooling settings
247 AC_ARG_WITH(xmltooling,
248     AS_HELP_STRING([--with-xmltooling=PATH],[where xmltooling is installed]),,
249     [with_xmltooling=/usr])
250 if test x_$with_xmltooling != x_/usr; then
251     CPPFLAGS="-I${with_xmltooling}/include $CPPFLAGS"
252     DX_INCLUDE="${with_xmltooling}/include"
253     LIBS="-L${with_xmltooling}/lib -lxmltooling $LIBS"
254 else
255     LIBS="-lxmltooling $LIBS"
256 fi
257
258 AC_CHECK_HEADER([xmltooling/XMLToolingConfig.h],,AC_MSG_ERROR([unable to find xmltooling header files]))
259
260 AC_LINK_IFELSE(
261     [AC_LANG_PROGRAM([[#include <xmltooling/XMLToolingConfig.h>
262 #include <xmltooling/version.h>]],
263         [[#if _XMLTOOLING_VERSION >= 10400
264 xmltooling::XMLToolingConfig::getConfig();
265 #else
266 #error Need XMLTooling version 1.4 or higher
267 #endif]])],
268     ,[AC_MSG_ERROR([unable to link with XMLTooling, or version was too old])])
269
270 # Check for unit test support
271 CXXTEST="/usr/bin/cxxtestgen.pl"
272 CXXTESTFLAGS=""
273 AC_ARG_WITH(cxxtest,
274     AS_HELP_STRING([--with-cxxtest=PATH], [where cxxtest is installed]),
275     [if test x_$with_cxxtest != x_/usr; then
276         CXXTEST="${with_cxxtest}/cxxtestgen.pl"
277         CXXTESTFLAGS="-I${with_cxxtest}"
278     fi])
279 if ! test -f "${CXXTEST}"; then
280     AC_MSG_WARN([cxxtestgen not found, won't build unit tests])
281 fi
282
283 AC_SUBST(CXXTEST)
284 AC_SUBST(CXXTESTFLAGS)
285 AM_CONDITIONAL(BUILD_UNITTEST,test -f ${CXXTEST})
286
287 AX_CREATE_PKGCONFIG_INFO(,,[$LIBS -lsaml],[OpenSAML library])
288
289 AC_SUBST(DX_INCLUDE)
290 LIBTOOL="$LIBTOOL --silent"
291
292 # output packaging and makefiles
293 AC_OUTPUT