Cleaned up source for dual build
[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(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 -Wall -g -D_DEBUG"
27     GCC_CXXFLAGS="$CXXFLAGS -Wall -g -D_DEBUG"
28 else
29     GCC_CFLAGS="$CFLAGS -Wall -O2 -DNDEBUG"
30     GCC_CXXFLAGS="$CXXFLAGS -Wall -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="$GCC_CFLAGS"
46     CXXFLAGS="$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
65 # Checks for library functions.
66 AC_CHECK_FUNCS([strchr strdup strstr timegm strcasecmp])
67 AC_CHECK_HEADERS([dlfcn.h])
68 AC_CHECK_FUNC(dlclose, , [ AC_CHECK_LIB(dl, dlopen) ])
69
70 # checks for pthreads
71 ACX_PTHREAD([enable_threads="pthread"],[enable_threads="no"])
72 if test $enable_threads != "pthread"; then
73     AC_MSG_ERROR([unable to find pthreads, currently this is required])
74 else
75     AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])
76         AM_CONDITIONAL(BUILD_PTHREAD,test "$enable_threads" = "pthread")
77     LIBS="$PTHREAD_LIBS $LIBS"
78     CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
79     CXXFLAGS="$PTHREAD_CFLAGS $CXXFLAGS"
80 fi
81
82 AC_CHECK_FUNCS([pthread_rwlock_init])
83
84 # libcurl settings
85 AC_PATH_PROG(CURL_CONFIG,curl-config)
86 AC_ARG_WITH(curl,
87     AC_HELP_STRING([--with-curl=PATH], [where curl-config is installed]),
88     [
89     CURL_CONFIG="${with_curl}"
90     if ! test -f "${CURL_CONFIG}" ; then
91         CURL_CONFIG="${with_curl}/bin/curl-config"
92     fi
93     ])
94 if test -f "${CURL_CONFIG}" ; then
95     LDFLAGS="`${CURL_CONFIG} --libs` $LDFLAGS"
96     CPPFLAGS="`${CURL_CONFIG} --cflags` $CPPFLAGS"
97 else
98     AC_MSG_ERROR([curl-config not found, may need to use --with-curl option])
99 fi
100 AC_CHECK_HEADER([curl/curl.h],,AC_MSG_ERROR([unable to find libcurl header files]))
101 AC_CHECK_LIB([curl],[curl_global_init],,AC_MSG_ERROR([unable to link with libcurl]))
102 AC_MSG_CHECKING([for CURLOPT_SSL_CTX_FUNCTION in curl.h])
103 AC_EGREP_HEADER([CURLOPT_SSL_CTX_FUNCTION], [curl/curl.h],
104                 [AC_MSG_RESULT(yes)],
105                 [AC_MSG_ERROR([need libcurl that supports CURLOPT_SSL_CTX_FUNCTION])])
106
107
108 AC_LANG(C++)
109
110 # C++ requirements
111 AC_CXX_REQUIRE_STL
112 AC_CXX_NAMESPACES
113
114 # are covariant methods allowed?
115 AC_TRY_LINK(
116      [ class base { public: virtual base *GetPtr( void ) { return this; } }; ],
117      [ class derived: virtual public base { public: virtual derived *GetPtr( void ) { return this; } }; ],
118      [AC_DEFINE(HAVE_COVARIANT_RETURNS,1,[Define if C++ compiler supports covariant virtual methods.])])
119
120 # log4cpp settings
121 AC_PATH_PROG(LOG4CPP_CONFIG,log4cpp-config)
122 AC_ARG_WITH(log4cpp,
123     AC_HELP_STRING([--with-log4cpp=PATH], [where log4cpp-config is installed]),
124     [
125     LOG4CPP_CONFIG="${with_log4cpp}"
126     if ! test -f "${LOG4CPP_CONFIG}" ; then
127         LOG4CPP_CONFIG="${with_log4cpp}/bin/log4cpp-config"
128     fi
129     ])
130 if test -f "${LOG4CPP_CONFIG}"; then
131     LDFLAGS="`${LOG4CPP_CONFIG} --libs` $LDFLAGS"
132     CPPFLAGS="`${LOG4CPP_CONFIG} --cflags` $CPPFLAGS"
133 else
134     AC_MSG_ERROR([log4cpp-config not found, may need to use --with-log4cpp option])
135     LIBS="-llog4cpp $LIBS"
136 fi
137 AC_CHECK_HEADER([log4cpp/Category.hh],,AC_MSG_ERROR([unable to find log4cpp header files]))
138 AC_CHECK_HEADER([log4cpp/PropertyConfigurator.hh],,AC_MSG_ERROR([you need at least log4cpp 0.3.x]))
139 AC_TRY_LINK(
140         [#include <log4cpp/Category.hh>],
141         [log4cpp::Category::getInstance("foo")],
142         [AC_DEFINE(HAVE_LIBLOG4CPP,1,[Define if log4cpp library was found])],
143         [AC_MSG_ERROR([unable to link with log4cpp])])
144
145 # Xerces settings
146 AC_ARG_WITH(xerces, 
147             AC_HELP_STRING([--with-xerces=PATH], [where xerces-c is installed]),
148             [if test x_$with_xerces != x_/usr; then
149                 LDFLAGS="-L${with_xerces}/lib $LDFLAGS"
150                 CPPFLAGS="-I${with_xerces}/include $CPPFLAGS"
151             fi])
152 LIBS="-lxerces-c $LIBS"
153 AC_CHECK_HEADER([xercesc/dom/DOM.hpp],,AC_MSG_ERROR([unable to find xerces header files]))
154 AC_MSG_CHECKING([Xerces version])
155 AC_PREPROC_IFELSE(
156     [AC_LANG_PROGRAM([#include <xercesc/util/XercesVersion.hpp>],
157 [#if  _XERCES_VERSION != 20600
158 int i = 0;
159 #else
160 #error cannot use version 2.6.0
161 #endif])],
162     [AC_MSG_RESULT(OK)],
163     [AC_MSG_FAILURE([Xerces-C v2.6.0 has bugs that inhibit use with signed XML, please use a newer version])])
164 AC_TRY_LINK(
165         [#include <xercesc/util/PlatformUtils.hpp>],
166         [xercesc::XMLPlatformUtils::Initialize()],
167         [AC_DEFINE(HAVE_LIBXERCESC,1,[Define if Xerces-C library was found])],
168         [AC_MSG_ERROR([unable to link with Xerces])])
169
170
171 # XML-Security settings
172 AC_ARG_WITH(xmlsec,
173             AC_HELP_STRING([--with-xmlsec=PATH], [where xmlsec is installed]),,
174             [with_xmlsec=/usr])
175
176 if test x_$with_xmlsec != x_no; then
177     if test x_$with_xmlsec != x_/usr; then
178         CPPFLAGS="-I${with_xmlsec}/include $CPPFLAGS"
179         LDFLAGS="-L${with_xmlsec}/lib $LDFLAGS"
180     fi        
181     XMLSEC_LIBS="-lxml-security-c"
182     
183     # save and append master libs
184     save_LIBS="$LIBS"
185     LIBS="$XMLSEC_LIBS $LIBS"
186     
187     AC_CHECK_HEADER([xsec/utils/XSECPlatformUtils.hpp],,AC_MSG_ERROR([unable to find XML-Security header files]))
188     AC_MSG_CHECKING([XML-Security version])
189     AC_PREPROC_IFELSE(
190             [AC_LANG_PROGRAM([#include <xsec/utils/XSECPlatformUtils.hpp>],
191         [#if XSEC_VERSION_MAJOR > 1 || (XSEC_VERSION_MAJOR == 1 && XSEC_VERSION_MEDIUM > 3) || (XSEC_VERSION_MAJOR == 1 && XSEC_VERSION_MEDIUM == 3 && XSEC_VERSION_MINOR > 0)
192 int i = 0;
193 #else
194 #error need version 1.3.1 or later
195 #endif])],
196         [AC_MSG_RESULT(OK)],
197         [AC_MSG_FAILURE([XML-Security version 1.3.1 or greater is required.])])
198     AC_TRY_LINK(
199             [#include <xsec/utils/XSECPlatformUtils.hpp>],
200             [XSECPlatformUtils::Initialise()],,
201             [AC_MSG_ERROR([unable to link with XML-Sec])])
202
203         # restore master libs
204         LIBS="$save_LIBS"
205
206         AC_LANG(C)
207
208         # OpenSSL settings
209         AC_ARG_WITH(openssl,
210             AC_HELP_STRING([--with-openssl=PATH], [where openssl is installed]),
211             [if test x_$with_openssl != x_/usr; then
212                 SSLFLAGS="-I${with_openssl}/include"
213                 SSLLIBS="-L${with_openssl}/lib -lcrypto -lssl"
214             fi])
215         
216         if test "x$SSLLIBS" = "x" ; then
217             AC_PATH_PROG(PKG_CONFIG, pkg-config)
218             if test "x$PKG_CONFIG" != x && test "x$PKG_CONFIG" != "xno" ; then
219                 if pkg-config openssl ; then
220                     SSLLIBS="`$PKG_CONFIG --libs openssl`"
221                     SSLFLAGS="`$PKG_CONFIG --cflags openssl`"
222                 else
223                     AC_MSG_ERROR([OpenSSL not supported by pkg-config, try --with-openssl instead])
224                 fi
225             fi
226         fi
227         
228         if test "x$SSLLIBS" = "x" ; then
229             SSLLIBS="-lcrypto -lssl"
230         fi
231         
232         AC_MSG_CHECKING(for OpenSSL cflags)
233         AC_MSG_RESULT($SSLFLAGS)
234         CPPFLAGS="$CPPFLAGS $SSLFLAGS"
235         AC_MSG_CHECKING(for OpenSSL libraries)
236         AC_MSG_RESULT($SSLLIBS)
237         XMLSEC_LIBS="$XMLSEC_LIBS $SSLLIBS"
238
239         # save and append master libs
240         save_LIBS="$LIBS"
241         LIBS="$XMLSEC_LIBS $LIBS"
242         
243         AC_CHECK_HEADER([openssl/pem.h],,
244                         AC_MSG_ERROR([unable to find openssl header files]))
245         AC_MSG_CHECKING(for ERR_load_CRYPTO_string)
246         AC_TRY_LINK_FUNC([ERR_load_CRYPTO_strings],,
247                      AC_MSG_ERROR([unable to link with openssl libraries]))
248         AC_MSG_RESULT(yes)
249
250         # restore master libs
251         LIBS="$save_LIBS"
252
253         AC_SUBST(XMLSEC_LIBS)
254         
255         AC_LANG(C++)
256 else
257     AC_MSG_WARN([xmlsec disabled, building without signature/encryption support])
258     AC_DEFINE(XMLTOOLING_NO_XMLSEC,1,
259         [Define if you wish to disable XML-Security-dependent features.])
260 fi
261 AM_CONDITIONAL(BUILD_XMLSEC,test x_$with_xmlsec != x_no)
262
263 # Does the STL in use help or screw us?
264 AC_TRY_LINK(
265         [#include <string>],
266         [std::basic_string<unsigned short> foo; foo=foo+(unsigned short)65],
267         [AC_DEFINE(HAVE_GOOD_STL,1,
268             [Define if you have an STL implementation that supports useful string specialization.])],
269         )
270
271 # Check for unit test support
272 CXXTEST="/usr/bin/cxxtestgen.pl"
273 CXXTESTFLAGS=""
274 AC_ARG_WITH(cxxtest,
275             AC_HELP_STRING([--with-cxxtest=PATH], [where cxxtest is installed]),
276             [if test x_$with_cxxtest != x_/usr; then
277                 CXXTEST="${with_cxxtest}/cxxtestgen.pl"
278                 CXXTESTFLAGS="-I${with_cxxtest}"
279             fi])
280 if ! test -f "${CXXTEST}"; then
281     AC_MSG_WARN([cxxtestgen not found, won't build unit tests])
282 fi
283
284 AC_SUBST(CXXTEST)
285 AC_SUBST(CXXTESTFLAGS)
286 AM_CONDITIONAL(BUILD_UNITTEST,test -f ${CXXTEST})
287
288 LIBTOOL="$LIBTOOL --silent"
289
290 # output makefiles
291 AC_OUTPUT(Makefile xmltooling/Makefile xmltoolingtest/Makefile schemas/Makefile doc/Makefile)