configure.ac 67.7 KB
Newer Older
1 2
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
3

4
AC_PREREQ([2.69])
5 6 7 8 9

# For released versions, this is in x.y.z format.
# For GIT versions, this is x.y.z-git, where x.y.z denotes the software
# version that was used as a base + changes that were made later, but
# are not released yet.
10
AC_INIT(kea,1.4.0-git, kea-dev@lists.isc.org)
11
AC_CONFIG_SRCDIR(README)
12 13 14 15 16 17 18 19 20 21 22 23 24

# serial-tests is not available in automake version before 1.13, so
# we'll check that and conditionally use serial-tests. This check is
# adopted from code by Richard W.M. Jones:
# https://www.redhat.com/archives/libguestfs/2013-February/msg00102.html
m4_define([serial_tests], [
    m4_esyscmd([automake --version |
                head -1 |
                awk '{split ($NF,a,"."); if (a[1] == 1 && a[2] >= 12) { print "serial-tests" }}'
    ])
])
AM_INIT_AUTOMAKE(foreign serial_tests)

25
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])dnl be backward compatible
26
AC_CONFIG_HEADERS([config.h])
27
AC_CONFIG_MACRO_DIR([m4macros])
28

29
AC_CANONICAL_HOST
30
AC_CANONICAL_BUILD
31

32 33
# Checks for programs.
AC_PROG_CXX
34

35 36 37
# Check for exact Kea version.
AC_MSG_CHECKING(whether this is a tarball or git source)
if test -d "${srcdir}/.git"; then
38
        KEA_SRCID="git `(cd "${top_srcdir}";git rev-parse HEAD)`"
39 40 41 42 43 44 45
        AC_MSG_RESULT("git")
else
        KEA_SRCID="tarball"
        AC_MSG_RESULT("tarball")
fi
# Export EXTENDED_VERSION to config.h
# This will be either "tarball" or "git abcd".
46 47 48 49
# We do not want to put this in a config.h, because it messes up ccache
# horribly. When building different branches, the commit-id is different
# and since the config.h is included in most files *and* has a different
# content, ccache can't use cached content and thus has to do full compilation.
50 51
# Now it is in kea_version.h and config.status substitutes it.
AC_SUBST(KEA_SRCID)
52

53 54
# Find a separator for path_replacer
for sep in "+" "," ";" "&" "__NONE__"; do
55 56 57 58 59 60
        if `pwd | grep -q $sep`; then continue; fi
        if `echo ${prefix} | grep -q $sep`; then continue; fi
        if `echo ${sysconfdir} | grep -q $sep`; then continue; fi
        if `echo ${localstatedir} | grep -q $sep`; then continue; fi
        SEP=$sep
        break
61 62
done
if test "$sep" = "__NONE__"; then
63
        AC_MSG_ERROR([can't find a separator character in '+,;&' for the path_replacer shell script])
64 65 66
fi
AC_SUBST(SEP)

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
# If cross compiling assume the message compiler executable was
# magically already in place...
if test "$cross_compiling" = "yes"; then
        AC_MSG_CHECKING("build (vs. host) compiled message compiler")
	if test -x "${srcdir}/src/lib/log/compiler/message"; then
		AC_MSG_RESULT(yes)
	else
		AC_MSG_RESULT(no)
		AC_MSG_WARN("you must install a message compiler in:")
		AC_MSG_WARN("    ${srcdir}/src/lib/log/compiler/message")
		AC_MSG_WARN("compiled for build ($build).")
	fi
fi
AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = "yes"])

82 83 84
# pkg-config can be required.
AC_PATH_PROG([PKG_CONFIG], [pkg-config])

85 86 87
# Enable low-performing debugging facilities? This option optionally
# enables some debugging aids that perform slowly and hence aren't built
# by default.
88 89 90 91
AC_ARG_ENABLE([debug],
  AS_HELP_STRING([--enable-debug],
    [enable debugging (default is no)]),
  [case "${enableval}" in
92 93
    yes) debug_enabled=yes ;;
    no)  debug_enabled=no ;;
94
    *)   AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;
95 96
  esac],[debug_enabled=no])
AM_CONDITIONAL([DEBUG_ENABLED], [test x$debug_enabled = xyes])
97
AM_COND_IF([DEBUG_ENABLED], [AC_DEFINE([ENABLE_DEBUG], [1], [Enable low-performing debugging facilities?])])
98

99
# Include premium configuration
100 101
INCLUDED_HOOKS=

102
PREMIUM_DIR=
103
DISTCHECK_PREMIUM_CONFIGURE_FLAG=
Francis Dupont's avatar
Francis Dupont committed
104
AC_DEFUN([AX_PREMIUM],[])
105
# m4_sinclude includes the file if it exists at autoreconf time
106
m4_sinclude(premium/config.m4)
107
AC_SUBST(PREMIUM_DIR)
108
AC_SUBST(DISTCHECK_PREMIUM_CONFIGURE_FLAG)
Francis Dupont's avatar
Francis Dupont committed
109
AX_PREMIUM
110

111
# Include contrib configuration
112
# (currently only a provision copied from premium support)
113
CONTRIB_DIR=
114
DISTCHECK_CONTRIB_CONFIGURE_FLAG=
Francis Dupont's avatar
Francis Dupont committed
115
AC_DEFUN([AX_CONTRIB],[])
116
m4_sinclude(contrib/config.m4)
Francis Dupont's avatar
Francis Dupont committed
117
AC_SUBST(CONTRIB_DIR)
118
AC_SUBST(DISTCHECK_CONTRIB_CONFIGURE_FLAG)
Francis Dupont's avatar
Francis Dupont committed
119
AX_CONTRIB
120

121 122
# Libtool configuration
#
123 124 125

# libtool cannot handle spaces in paths, so exit early if there is one
if [ test `echo $PWD | grep -c ' '` != "0"  ]; then
126
    AC_MSG_ERROR([Kea cannot be built in a directory that contains spaces, because of libtool limitations. Please change the directory name, or use a symbolic link that does not contain spaces.])
127 128
fi

129 130
# On FreeBSD (and probably some others), clang++ does not meet an autoconf
# assumption in identifying libtool configuration regarding shared library:
131 132 133 134 135
# the configure script will execute "$CC -shared $CFLAGS/$CXXFLAGS -v" and
# expect the output contains -Lxxx or -Ryyy.  This is the case for g++, but
# not for clang++, and, as a result, it will cause various errors in linking
# programs or running them with a shared object (such as some of our python
# scripts).
136 137 138 139 140
# To work around this problem we define a temporary variable
# "CXX_LIBTOOL_LDFLAGS".  It's expected to be defined as, e.g, "-L/usr/lib"
# to temporarily fake the output so that it will be compatible with that of
# g++.
CFLAGS_SAVED=$CFLAGS
141
CXXFLAGS_SAVED=$CXXFLAGS
142
CFLAGS="$CFLAGS $CXX_LIBTOOL_LDFLAGS"
143
CXXFLAGS="$CXXFLAGS $CXX_LIBTOOL_LDFLAGS"
144
LT_INIT
145
CFLAGS=$CFLAGS_SAVED
146
CXXFLAGS=$CXXFLAGS_SAVED
147

148
# Use C++ language
149 150 151
AC_LANG([C++])

# Identify the compiler: this check must be after AC_PROG_CXX and AC_LANG.
152
AM_CONDITIONAL(USE_GXX, test "X${GXX}" = "Xyes")
153
AC_CHECK_DECL([__SUNPRO_CC], [SUNCXX="yes"], [SUNCXX="no"])
154
AC_CHECK_DECL([__clang__], [CLANGPP="yes"], [CLANGPP="no"])
Josh Soref's avatar
Josh Soref committed
155
# USE_CLANGPP is no longer used, keep it by symmetry with USE_GXX?
156
AM_CONDITIONAL(USE_CLANGPP, test "X${CLANGPP}" = "Xyes")
157

158
# Check for C++11 features support
159
AX_ISC_CPP11
160

161 162 163
# Check for std::is_base_of support
AC_MSG_CHECKING([for std::is_base_of])
AC_COMPILE_IFELSE(
164 165 166 167 168 169 170 171 172
    [AC_LANG_PROGRAM(
        [#include <type_traits>
        class A {};
        class B : A {};]
        [static_assert(std::is_base_of<A, B>::value, "");])],
    [AC_MSG_RESULT(yes)
    AC_DEFINE([HAVE_IS_BASE_OF], [1],
    [Define to 1 if std::is_base_of is available])],
    [AC_MSG_RESULT(no)])
173

174
dnl Determine if we are using GNU sed
175
GNU_SED=no
176
$SED --version 2> /dev/null | grep GNU > /dev/null 2>&1
177 178 179 180
if test $? -eq 0; then
  GNU_SED=yes
fi

181 182 183 184 185 186 187
# Display the C++ version
AC_MSG_CHECKING([C++ version])
cat > conftest.cpp << EOF
long v = __cplusplus;
EOF
CXX_STANDARD=`$CXX $CXXFLAGS -E -o - conftest.cpp | grep '^long v = ' | $SED -e 's/^long v = //' -e 's/[[^0-9]]*$//' 2> /dev/null`
if test -z "$CXX_STANDARD"; then
188
        CXX_STANDARD="unknown"
189 190 191
fi
AC_MSG_RESULT([$CXX_STANDARD])

192 193
# Linker options

194
# check -R, "-Wl,-R" or -rpath
195
AX_ISC_RPATH
196

197
# Compiler dependent settings: define some mandatory CXXFLAGS here.
198
# We also use a separate variable KEA_CXXFLAGS.  This will (and should) be
199
# used as the default value for each specific AM_CXXFLAGS:
200
# AM_CXXFLAGS = $(KEA_CXXFLAGS)
201 202 203 204 205 206 207 208
# AM_CXXFLAGS += ... # add module specific flags
# We need this so that we can disable some specific compiler warnings per
# module basis; since AM_CXXFLAGS are placed before CXXFLAGS, and since
# gcc's -Wno-XXX option must be specified after -Wall or -Wextra, we cannot
# specify the default warning flags in CXXFLAGS and let specific modules
# "override" the default.

# This may be used to try linker flags.
209
AC_DEFUN([KEA_CXX_TRY_FLAG], [
210 211
  AC_MSG_CHECKING([whether $CXX supports $1])

212
  kea_save_CXXFLAGS="$CXXFLAGS"
213
  CXXFLAGS="$CXXFLAGS -Werror $1"
214

215
  AC_LINK_IFELSE([AC_LANG_SOURCE([int main(){ return 0;}])],
216 217
                 [kea_cxx_flag=yes], [kea_cxx_flag=no])
  CXXFLAGS="$kea_save_CXXFLAGS"
218

219
  if test "x$kea_cxx_flag" = "xyes"; then
220 221 222 223 224
    ifelse([$2], , :, [$2])
  else
    ifelse([$3], , :, [$3])
  fi

225
  AC_MSG_RESULT([$kea_cxx_flag])
226 227
])

228 229
CXX_VERSION="unknown"

230 231 232
# SunStudio compiler requires special compiler options for boost
# (http://blogs.sun.com/sga/entry/boost_mini_howto)
if test "$SUNCXX" = "yes"; then
233
CXX_VERSION=`$CXX -V 2> /dev/null | head -1`
234
CXXFLAGS="$CXXFLAGS -library=stlport4 -features=tmplife -features=tmplrefstatic"
Francis Dupont's avatar
Francis Dupont committed
235
KEA_CXXFLAGS="$KEA_CXXFLAGS -mt"
236 237 238 239 240 241 242 243 244 245
MULTITHREADING_FLAG="-mt"
fi

# Newer versions of clang++ promotes "unused driver arguments" warnings to
# a fatal error with -Werror, causing build failure.  Since we use multiple
# compilers on multiple systems, this can easily happen due to settings for
# non clang++ environments that could be just ignored otherwise.  It can also
# happen if clang++ is used via ccache.  So, although probably suboptimal,
# we suppress this particular warning.  Note that it doesn't weaken checks
# on the source code.
246
if test "X$CLANGPP" = "Xyes"; then
247
CXX_VERSION=`$CXX --version 2> /dev/null | head -1`
248
KEA_CXXFLAGS="$KEA_CXXFLAGS -Qunused-arguments"
249 250
fi

251
# gcc/clang specific settings:
252
if test "X$GXX" = "Xyes"; then
253
CXX_VERSION=`$CXX --version 2> /dev/null | head -1`
254
KEA_CXXFLAGS="$KEA_CXXFLAGS -Wall -Wextra -Wnon-virtual-dtor -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare"
255 256 257
# gcc 4.4 would emit warnings about breaking strict aliasing rules.
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41874
CXX_DUMP_VERSION=`$CXX -dumpversion | cut -f1-2 -d.`
258
if expr "$CXX_DUMP_VERSION" \< "4.5" > /dev/null; then
259 260 261
       WARNING_GCC_44_STRICT_ALIASING_CFLAG="-fno-strict-aliasing"
fi
AC_SUBST(WARNING_GCC_44_STRICT_ALIASING_CFLAG)
Francis Dupont's avatar
Francis Dupont committed
262
CPPP="$CPP"
263
# gcc 5 preprocessor requires -P for checking its output
264
if expr "$CXX_DUMP_VERSION" \> "5" > /dev/null; then
265 266
       CPPP="$CPP -P"
fi
267

268 269
case "$host" in
*-solaris*)
270 271 272 273
        MULTITHREADING_FLAG=-pthreads
        # In Solaris, IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT need -Wno-missing-braces
        KEA_CXXFLAGS="$KEA_CXXFLAGS -Wno-missing-braces"
        ;;
274
*-apple-darwin*)
275 276
        MULTITHREADING_FLAG=
        ;;
277
*)
278 279
        MULTITHREADING_FLAG=-pthread
        ;;
280
esac
281
KEA_CXXFLAGS="$KEA_CXXFLAGS $MULTITHREADING_FLAG"
282

283 284 285
# Disable -Werror by default. Only use it if specifically enabled.
# The usage of this flag is:
#
286 287 288 289 290
# No flag:            -Werror is disabled
# --with-werror:      -Werror is enabled
# --with-werror=yes:  -Werror is enabled
# --with-werror=no:   -Werror is disabled
# --with-werror=value -Werror is enabled and "value" is included in the compiler flags
291 292 293 294
#
# In the last case, "value" may be one or more compiler flags, e.g.

# --with-werror=-Wundef
295
# --with-werror='-Wundef -Wconversion'
296

297
werror_extras=
298
AC_ARG_WITH(werror,
299
    AC_HELP_STRING([--with-werror], [Compile using -Werror (default=no)]),
300 301 302 303
    [
     case "${withval}" in
         yes) with_werror=1 ;;
         no)  with_werror=0 ;;
304
         -*)  with_werror=1; werror_extras=${withval} ;;
305
         *)   AC_MSG_ERROR(bad value ${withval} for --with-werror) ;;
306
     esac],
307
     [with_werror=0])
308 309 310 311 312 313 314 315

werror_ok=0

# Certain versions of gcc (g++) have a bug that incorrectly warns about
# the use of anonymous name spaces even if they're closed in a single
# translation unit.  For these versions we have to disable -Werror.
if test $with_werror = 1; then
   CXXFLAGS_SAVED="$CXXFLAGS"
316
   CXXFLAGS="$CXXFLAGS $KEA_CXXFLAGS -Werror"
317
   AC_MSG_CHECKING(for in-TU anonymous namespace breakage)
318 319 320 321
   # We use struct, not class, here, because some compilers complain about
   # "unused private members", causing a false positive.
   AC_TRY_COMPILE([namespace { struct Foo {}; }
   namespace isc {struct Bar {Foo foo_;};} ],,
322 323 324 325
        [AC_MSG_RESULT(no)
         werror_ok=1
         KEA_CXXFLAGS="$KEA_CXXFLAGS -Werror"],
        [AC_MSG_RESULT(yes)])
326 327 328
   CXXFLAGS="$CXXFLAGS_SAVED"
fi

329 330 331 332 333 334 335
# Added flags after -Werror

# Some versions of GCC warn about some versions of Boost regarding
# missing initializer for members in its posix_time.
# https://svn.boost.org/trac/boost/ticket/3477
# But older GCC compilers don't have the flag.
KEA_CXX_TRY_FLAG([-Wno-missing-field-initializers],
336
        [KEA_CXXFLAGS="$KEA_CXXFLAGS -Wno-missing-field-initializers"])
337 338

if test "X$CLANGPP" = "Xyes"; then
339 340 341 342
        # This is to workaround unused variables tcout and tcerr in
        # log4cplus's streams.h and unused parameters from some of the
        # Boost headers.
        KEA_CXXFLAGS="$KEA_CXXFLAGS -Wno-unused-variable -Wno-unused-parameter"
343 344 345 346 347
fi

# Add the extras at the very last
# Note it can be used to re-enable a (fatal) warning
for extra in $werror_extras; do
348 349 350
        KEA_CXX_TRY_FLAG([$extra],
                [KEA_CXXFLAGS="$KEA_CXXFLAGS $extra"],
                [AC_MSG_ERROR([$CXX does not support $extra"])])
351 352
done

353
fi                              dnl GXX = yes
354

355 356 357 358 359 360 361
# allow building programs with static link.  we need to make it selective
# because loadable modules cannot be statically linked.
AC_ARG_ENABLE([static-link],
AC_HELP_STRING([--enable-static-link],
  [build programs with static link [[default=no]]]),
  [enable_static_link=yes], [enable_static_link=no])
AM_CONDITIONAL(USE_STATIC_LINK, test $enable_static_link = yes)
362
AM_COND_IF([USE_STATIC_LINK], [AC_DEFINE([USE_STATIC_LINK], [1], [Was Kea statically linked?])])
363

364 365
# Check validity about some libtool options
if test $enable_static_link = yes -a $enable_static = no; then
366
        AC_MSG_ERROR([--enable-static-link requires --enable-static])
367
fi
368
if test $enable_static_link = no -a $enable_shared = no; then
369
        AC_MSG_ERROR([--disable-static-link requires --enable-shared])
370 371
fi

372
# OS dependent configuration
373
kea_undefined_pthread_behavior=no
374

375
case "$host" in
376
*-solaris*)
377 378 379 380 381 382 383 384 385 386
        # Solaris requires special definitions to get some standard libraries
        # (e.g. getopt(3)) available with common used header files.
        CPPFLAGS="$CPPFLAGS -D_XPG4_2 -D__EXTENSIONS__"
        # "now" binding is necessary to prevent deadlocks in C++ static initialization code
        LDFLAGS="$LDFLAGS -z now"
        # Destroying locked mutexes, condition variables being waited
        # on, etc. are undefined behavior on Solaris, so we set it as
        # such here.
        kea_undefined_pthread_behavior=yes
        ;;
387
*-apple-darwin*)
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
        # Starting with OSX 10.7 (Lion) we must choose which IPv6 API to use
        # (RFC2292 or RFC3542).
        CPPFLAGS="$CPPFLAGS -D__APPLE_USE_RFC_3542"

        # In OS X 10.9 (and possibly any future versions?) pthread_cond_destroy
        # doesn't work as documented, which makes some of unit tests fail.
        AC_MSG_CHECKING([OS X versions where destroying locked locks do not fail])
        AC_TRY_COMPILE(
        [#include <Availability.h>],
        [#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
         #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
         #error " OS X >= 10.9"
         #endif
         #endif
         return 1;],
        [AC_MSG_RESULT([OS X < 10.9])],
        [AC_MSG_RESULT([OS X >= 10.9])
         kea_undefined_pthread_behavior=yes])
        ;;
407
*-freebsd*)
408 409 410 411 412 413 414 415 416 417 418
        # On FreeBSD10.1 pthread_cond_destroy doesn't work as documented, which
        # causes the CondVarTest.destroyWhileWait test to fail. According to the
        # pthread_cond_destroy documentation for FreeBSD, this function should
        # return EBUSY error when there is a thread waiting for the conditional
        # variable, whereas this function returned success code. We treat it here
        # as an undefined behavior. Also note that this issue was only visible
        # when gtest 1.7 was in use, because the previous versions of gtest
        # didn't seem to have support for the death tests on FreeBSD. As a
        # result, the test was not executed and the error didn't occur.
        kea_undefined_pthread_behavior=yes
        ;;
419
esac
420
if [ test $kea_undefined_pthread_behavior = "yes" ]; then
421 422
   AC_DEFINE([HAS_UNDEFINED_PTHREAD_BEHAVIOR], [1], [Does this platform have some undefined pthreads behavior?])
fi
423

424 425 426 427 428 429 430 431 432 433
# Our experiments have shown Solaris 10 has broken support for the
# IPV6_USE_MIN_MTU socket option for getsockopt(); it doesn't return the value
# previously set via setsockopt().  We know it doesn't happen on one instance
# on Solaris 11, but we don't know whether it happens for any Solaris 10
# implementations or for earlier versions of Solaris.  In any case, at the
# moment this matters for only one unittest case, so we'll simply disable
# the affected test using the following definition with the specific hardcoding
# of that version of Solaris.
case "$host" in
*-solaris2.10)
434 435 436
        AC_DEFINE([HAVE_BROKEN_GET_IPV6_USE_MIN_MTU], [1],
        [Define to 1 if getsockopt(IPV6_USE_MIN_MTU) does not work])
        ;;
437 438
esac

439 440 441 442 443 444 445 446
# Kea-shell is written in python. It can work with python 2.7 or any 3.x.
# It may likely work with earlier versions, but 2.7 was the oldest one we tested
# it with. We require python only if kea-shell was enabled. It is disabled
# by default to not introduce hard dependency on python.
AC_ARG_ENABLE(shell, [AC_HELP_STRING([--enable-shell],
  [enable kea-shell, a text management client for Control Agent [default=no]])],
  enable_shell=$enableval, enable_shell=no)

447
DISTCHECK_KEA_SHELL_CONFIGURE_FLAG=
Francis Dupont's avatar
Francis Dupont committed
448
PKGPYTHONDIR=
449 450 451
m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
 [python3 python3.9 python3.8 python3.7 python3.6 python3.5 python3.4 dnl
  python3.3 python3.2 python3.1 python3.0 python python2 python2.7])
452 453
if test "x$enable_shell" != xno ; then
# If kea-shell is enabled, we really need python. 2.7 or anything newer will do.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
454
# We try to find 3.x first. If not found, we can do with 2.7.
455
  AM_PATH_PYTHON([2.7])
Francis Dupont's avatar
Francis Dupont committed
456
  # pkgpythondir needs to be expanded
457 458 459 460
  saved_prefix="$prefix"
  if test "$prefix" = "NONE"; then
    prefix=$ac_default_prefix
  fi
Francis Dupont's avatar
Francis Dupont committed
461 462 463 464 465 466
  PKGPYTHONDIR="$pkgpythondir"
  OLD=
  while test "x$OLD" != "x$PKGPYTHONDIR"; do
    OLD="$PKGPYTHONDIR"
    eval PKGPYTHONDIR="\"$OLD\""
  done
467
  prefix="$saved_prefix"
468
  DISTCHECK_KEA_SHELL_CONFIGURE_FLAG="--enable-shell"
469
else
470
  PYTHON=no
471
fi
472

473 474
# Export to makefiles the info whether we have shell enabled or not
AM_CONDITIONAL(KEA_SHELL, test x$enable_shell != xno)
475
AC_SUBST(DISTCHECK_KEA_SHELL_CONFIGURE_FLAG)
Francis Dupont's avatar
Francis Dupont committed
476
AC_SUBST(PKGPYTHONDIR)
477

478
# produce PIC unless we disable shared libraries. need this for python bindings.
479
if test $enable_shared != "no" -a "X$GXX" = "Xyes"; then
480
   KEA_CXXFLAGS="$KEA_CXXFLAGS -fPIC"
481 482
fi

483
# Look for glib static libs if they're trying to do static builds
484
if test $enable_static_link != "no"; then
485 486 487 488
   CXX_SAVED=$CXX
   CXX="$CXX -static"

   AC_LINK_IFELSE(
489
     [AC_LANG_PROGRAM([#include <math.h>],[(void)sqrt(-1.0);])],
490 491
     [AC_MSG_RESULT([checking for static glib libraries... yes])],
     [AC_MSG_RESULT([checking for static glib libraries... no])
492
      AC_MSG_ERROR([Building with --enable-static-link does not work. You appear to be missing glib static libraries. Check config.log for details.])])
493 494 495

   CXX=$CXX_SAVED
fi
496

497
AC_SUBST(KEA_CXXFLAGS)
498

499 500
# Checks for libraries.

501 502
AC_SEARCH_LIBS(inet_pton, [nsl])
AC_SEARCH_LIBS(recvfrom, [socket])
503
AC_SEARCH_LIBS(nanosleep, [rt])
504
AC_SEARCH_LIBS(dlsym, [dl])
505

506 507 508 509 510 511
# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_TYPE_SIZE_T

512

513 514
# Detect OS type (it may be used to do OS-specific things, e.g.
# interface detection in DHCP)
515
AC_MSG_CHECKING(OS type)
516
BSD_TYPE="notaBSD"
517 518 519
case $host in
    *-linux*)
      AC_DEFINE([OS_LINUX], [1], [Running on Linux?])
520
      OS_TYPE="Linux"
521 522
      CPPFLAGS="$CPPFLAGS -DOS_LINUX"
      ;;
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
    *-apple-darwin*)
      AC_DEFINE([OS_BSD], [1], [Running on BSD?])
      AC_DEFINE([OS_OSX], [1], [Running on OSX?])
      OS_TYPE="BSD"
      BSD_TYPE="OSX"
      CPPFLAGS="$CPPFLAGS -DOS_BSD"
      ;;
    *-freebsd*)
      AC_DEFINE([OS_BSD], [1], [Running on BSD?])
      AC_DEFINE([OS_FREEBSD], [1], [Running on FreeBSD?])
      OS_TYPE="BSD"
      BSD_TYPE="FreeBSD"
      CPPFLAGS="$CPPFLAGS -DOS_BSD"
      ;;
    *-netbsd*)
      AC_DEFINE([OS_BSD], [1], [Running on BSD?])
      AC_DEFINE([OS_NETBSD], [1], [Running on NetBSD?])
      OS_TYPE="BSD"
      BSD_TYPE="NetBSD"
      CPPFLAGS="$CPPFLAGS -DOS_BSD"
      ;;
    *-openbsd*)
      AC_DEFINE([OS_BSD], [1], [Running on BSD?])
      AC_DEFINE([OS_OPENBSD], [1], [Running on OpenBSD?])
547
      OS_TYPE="BSD"
548
      BSD_TYPE="OpenBSD"
549 550
      CPPFLAGS="$CPPFLAGS -DOS_BSD"
      ;;
551 552
    *-solaris*)
      AC_DEFINE([OS_SOLARIS], [1], [Running on Solaris?])
553
      OS_TYPE="Solaris"
554
      CPPFLAGS="$CPPFLAGS -DOS_SUN"
555 556 557
      ;;
    *)
      OS_TYPE="Unknown"
558 559
      # $host_os is more user friendly than full $host
      AC_MSG_WARN("Unsupported OS: $host_os")
560 561 562
      ;;
esac
AC_MSG_RESULT($OS_TYPE)
563 564

AM_CONDITIONAL(OS_LINUX, test $OS_TYPE = Linux)
565 566
AM_CONDITIONAL(OS_BSD, test $OS_TYPE = BSD)
AM_CONDITIONAL(OS_SOLARIS, test $OS_TYPE = Solaris)
567 568 569 570
AM_CONDITIONAL(OS_OSX, test $BSD_TYPE = OSX)
AM_CONDITIONAL(OS_FREEBSD, test $BSD_TYPE = FreeBSD)
AM_CONDITIONAL(OS_NETBSD, test $BSD_TYPE = NetBSD)
AM_CONDITIONAL(OS_OPENBSD, test $BSD_TYPE = OpenBSD)
571 572


573 574 575 576 577 578
AC_MSG_CHECKING(for sa_len in struct sockaddr)
AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/socket.h>],
[struct sockaddr sa; sa.sa_len = 0; return (0);],
        [AC_MSG_RESULT(yes)
579
        AC_DEFINE(HAVE_SA_LEN, 1, [Define to 1 if sockaddr has a sa_len member, and corresponding sin_len and sun_len])],
580 581
        AC_MSG_RESULT(no))

582 583 584 585 586 587 588 589 590 591 592 593 594 595
AC_MSG_CHECKING(for usuable C++11 regex)
AC_TRY_RUN([
#include <regex>
#include <iostream>
int main() {
  const std::regex regex(".*");
  const std::string string = "This should match!";
  const auto result = std::regex_search(string, regex);
  return result ? EXIT_SUCCESS : EXIT_FAILURE;
}],
        [AC_MSG_RESULT(yes)
        AC_DEFINE(USE_REGEX, 1, [Define to 1 if C++11 regex is usable])],
        AC_MSG_RESULT(no))

596
enable_gtest="no"
597
GTEST_INCLUDES=
598 599 600

AC_ARG_WITH([gtest-source],
            [AS_HELP_STRING([--with-gtest-source=PATH],
601 602
                            [location of the Googletest source])],
            [enable_gtest="yes" ; GTEST_SOURCE="$withval"])
603 604

AC_ARG_WITH([gtest],
605 606 607
            [AS_HELP_STRING([--with-gtest=PATH],
                            [specify a path to gtest header files (PATH/include) and library (PATH/lib)])],
        [gtest_path="$withval"; enable_gtest="yes"], [gtest_path="no"])
608

609
AC_ARG_WITH(lcov,
610
[  --with-lcov[=PROGRAM]         enable gtest and coverage target using the specified lcov], lcov="$withval", lcov="no")
611 612 613

USE_LCOV="no"
if test "$lcov" != "no"; then
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
        # force gtest if not set
        if test "$enable_gtest" = "no"; then
#               AC_MSG_ERROR("lcov needs gtest for test coverage report")
                AC_MSG_NOTICE([gtest support is now enabled, because used by coverage tests])
                enable_gtest="yes"
        fi
        if test "$lcov" != "yes"; then
                LCOV=$lcov
        else
                AC_PATH_PROG([LCOV], [lcov])
        fi
        if test -x "${LCOV}"; then
                USE_LCOV="yes"
        else
                AC_MSG_ERROR([Cannot find lcov.])
        fi
        # is genhtml always in the same directory?
        GENHTML=`echo "$LCOV" | ${SED} s/lcov$/genhtml/`
        if test ! -x $GENHTML; then
                AC_MSG_ERROR([genhtml not found, needed for lcov])
        fi
        # GCC specific?
        CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage"
        LIBS=" $LIBS -lgcov"
        AC_SUBST(CPPFLAGS)
        AC_SUBST(LIBS)
        AC_SUBST(LCOV)
        AC_SUBST(GENHTML)
642 643 644
fi
AC_SUBST(USE_LCOV)

Andrei Pavel's avatar
Andrei Pavel committed
645 646 647 648 649 650 651 652 653 654 655 656 657
enable_benchmark="no"
BENCHMARK_INCLUDES=

AC_ARG_WITH([benchmark-source],
            [AS_HELP_STRING([--with-benchmark-source=PATH],
                            [location of the benchmark source])],
            [enable_benchmark="yes" ; BENCHMARK_SOURCE="$withval"])

AC_ARG_WITH([benchmark],
            [AS_HELP_STRING([--with-benchmark=PATH],
                            [specify a path to benchmark header files (PATH/include) and library (PATH/lib)])],
        [benchmark_path="$withval"; enable_benchmark="yes"], [benchmark_path="no"])

658 659 660
# Sets up for use of botan unless openssl is specified
# sets variables CRYPTO_*
AX_CRYPTO
661

662 663 664 665
# List of directories, where tools like mysql_config or pgsql_config will be
# searched for
defaultdirs="/usr /usr/local /usr/pkg /opt /opt/local"

666
# Check for MySql.  The path to the mysql_config program is given with
667 668
# the --with-mysql-config (default to /usr/bin/mysql-config).  By default,
# the software is not built with MySQL support enabled.
669
mysql_config="no"
670 671
AC_ARG_WITH([mysql],
  AC_HELP_STRING([--with-mysql=PATH],
672
    [path to the MySQL 'mysql_config' script (MySQL is used for the DHCP database)]),
673 674
    [mysql_config="$withval"])

675 676 677 678 679 680 681 682
deprec_msg="no"
AC_ARG_WITH([dhcp-mysql],,
    [mysql_config="$withval";deprec_msg="yes"])

if test "${deprec_msg}" = "yes" ; then
    AC_MSG_WARN([--with-dhcp-mysql has been deprecated, please use --with-mysql])
fi

683
if test "${mysql_config}" = "yes" ; then
684 685 686 687 688 689 690
    for d in $defaultdirs
    do
        if test -f $d/bin/mysql_config; then
            MYSQL_CONFIG="$d/bin/mysql_config"
            break
        fi
    done
691 692 693 694 695
elif test "${mysql_config}" != "no" ; then
    MYSQL_CONFIG="${withval}"
fi

if test "$MYSQL_CONFIG" != "" ; then
696
    if test -d "$MYSQL_CONFIG" -o ! -x "$MYSQL_CONFIG" ; then
697
        AC_MSG_ERROR([--with-mysql should point to a mysql_config program])
698 699 700 701
    fi

    MYSQL_CPPFLAGS=`$MYSQL_CONFIG --cflags`
    MYSQL_LIBS=`$MYSQL_CONFIG --libs`
702
    MYSQL_VERSION=`$MYSQL_CONFIG --version`
703 704 705 706 707 708 709 710 711 712 713 714

    AC_SUBST(MYSQL_CPPFLAGS)
    AC_SUBST(MYSQL_LIBS)

    # Check that a simple program using MySQL functions can compile and link.
    CPPFLAGS_SAVED="$CPPFLAGS"
    LIBS_SAVED="$LIBS"

    CPPFLAGS="$MYSQL_CPPFLAGS $CPPFLAGS"
    LIBS="$MYSQL_LIBS $LIBS"

    AC_LINK_IFELSE(
715
            [AC_LANG_PROGRAM([#include <mysql.h>],
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
                             [MYSQL mysql_handle;
                              (void) mysql_init(&mysql_handle);
                             ])],
            [AC_MSG_RESULT([checking for MySQL headers and library... yes])],
            [AC_MSG_RESULT([checking for MySQL headers and library... no])
             AC_MSG_ERROR([Needs MySQL library])]
    )

    CPPFLAGS=$CPPFLAGS_SAVED
    LIBS=$LIBS_SAVED

    # Note that MYSQL is present in the config.h file
    AC_DEFINE([HAVE_MYSQL], [1], [MySQL is present])
fi

731
# Solaris puts FIONREAD in filio.h
732
AC_CHECK_HEADERS(sys/filio.h,,,)
733

734 735 736
# ... and at the shell level, so Makefile.am can take action depending on this.
AM_CONDITIONAL(HAVE_MYSQL, test "$MYSQL_CONFIG" != "")

737
pg_config="no"
738 739
AC_ARG_WITH([pgsql],
  AC_HELP_STRING([--with-pgsql=PATH],
740 741 742
    [path to the PostgreSQL 'pg_config' script]),
    [pg_config="$withval"])

743 744 745 746 747 748 749 750
deprec_msg="no"
AC_ARG_WITH([dhcp-pgsql],,
    [pg_config="$withval";deprec_msg="yes"])

if test "${deprec_msg}" = "yes" ; then
    AC_MSG_WARN([--with-dhcp-pgsql has been deprecated, please use --with-pgsql])
fi

751
if test "${pg_config}" = "yes" ; then
752 753 754 755 756 757 758
    for d in $defaultdirs
    do
        if test -f $d/bin/pg_config; then
            PG_CONFIG="$d/bin/pg_config"
            break
        fi
    done
759 760 761 762 763 764
elif test "${pg_config}" != "no" ; then
    PG_CONFIG="${withval}"
fi

if test "$PG_CONFIG" != "" ; then
    if test -d "$PG_CONFIG" -o ! -x "$PG_CONFIG" ; then
765
        AC_MSG_ERROR([--with-pgsql should point to a pg_config program])
766 767 768 769
    fi

    PGSQL_CPPFLAGS=`$PG_CONFIG --cppflags`
    PGSQL_INCLUDEDIR=`$PG_CONFIG --includedir`
770 771
    PGSQL_INCLUDEDIR_SERVER=`$PG_CONFIG --includedir-server`
    PGSQL_CPPFLAGS="$PGSQL_CPPFLAGS -I$PGSQL_INCLUDEDIR -I$PGSQL_INCLUDEDIR_SERVER"
772 773
    PGSQL_LIBS=`$PG_CONFIG --libdir`
    PGSQL_LIBS="-L$PGSQL_LIBS -lpq"
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794
    PGSQL_VERSION=`$PG_CONFIG --version`

    AC_SUBST(PGSQL_CPPFLAGS)
    AC_SUBST(PGSQL_LIBS)

    # Check that a simple program using PostgreSQL functions can compile and link.
    CPPFLAGS_SAVED="$CPPFLAGS"
    LIBS_SAVED="$LIBS"

    CPPFLAGS="$PGSQL_CPPFLAGS $CPPFLAGS"
    LIBS="$PGSQL_LIBS $LIBS"

    AC_LINK_IFELSE(
            [AC_LANG_PROGRAM([#include <libpq-fe.h>],
                             [PGconn * c = PQconnectdb("dbname = 'postgres'");
                              PQfinish(c);])],
            [AC_MSG_RESULT([checking for PostgreSQL headers and library... yes])],
            [AC_MSG_RESULT([checking for PostgreSQL headers and library... no])
             AC_MSG_ERROR([Needs PostgreSQL library])]
    )

795
    AC_CHECK_HEADERS([utils/errcodes.h],,
796
    AC_MSG_ERROR([Missing required header file (errcodes.h) from PostgreSQL server-development package]))
797

798 799 800 801 802 803 804 805 806
    CPPFLAGS=$CPPFLAGS_SAVED
    LIBS=$LIBS_SAVED

    # Note that PostgreSQL is present in the config.h file
    AC_DEFINE([HAVE_PGSQL], [1], [PostgreSQL is present])
fi

# ... and at the shell level, so Makefile.am can take action depending on this.
AM_CONDITIONAL(HAVE_PGSQL, test "$PG_CONFIG" != "")
807

808
# allow building kea programs with static link to cassandra cpp-driver.
809 810 811 812
AC_ARG_ENABLE([cql-static-lib],
AS_HELP_STRING([--enable-cql-static-lib],
    [build programs with cassandra cpp driver static library [[default=no]]]),
    [enable_cql_static_lib=yes], [enable_cql_static_lib=no])
813
AM_CONDITIONAL(USE_CQL_STATIC_LIB, test "$enable_cql_static_lib" = yes)
814 815 816 817 818 819 820
#AC_DEFINE USE_CQL_STATIC_LIB? (unused)

cql_lib="cassandra"
if test "${enable_cql_static_lib}" = "yes" ; then
    cql_lib="${cql_lib}_static"
fi

Tomek Mrugalski's avatar
Tomek Mrugalski committed
821 822 823
cql_config="no"
AC_ARG_WITH([cql],
  AC_HELP_STRING([--with-cql=PATH],
824
    [path to pkg-config or the Cassandra CQL 'cql_config' script]),
Tomek Mrugalski's avatar
Tomek Mrugalski committed
825 826 827
    [cql_config="$withval"])

if test "${cql_config}" = "yes" ; then
828
    CQL_CONFIG="$PKG_CONFIG"
Tomek Mrugalski's avatar
Tomek Mrugalski committed
829
elif test "${cql_config}" != "no" ; then
Francis Dupont's avatar
Francis Dupont committed
830
    CQL_CONFIG="${cql_config}"
831 832
fi

Tomek Mrugalski's avatar
Tomek Mrugalski committed
833 834
if test "$CQL_CONFIG" != "" ; then
    if test -d "$CQL_CONFIG" -o ! -x "$CQL_CONFIG" ; then
835
        AC_MSG_ERROR([--with-cql should point to a pkg-config or cql_config program])
836 837
    fi

838
    CQL_INCLUDEDIR=`$CQL_CONFIG --cflags-only-I $cql_lib`
Andrei Pavel's avatar
Andrei Pavel committed
839
    CQL_CPPFLAGS="$CQL_INCLUDEDIR `$CQL_CONFIG --cflags-only-other $cql_lib`"
Francis Dupont's avatar
Francis Dupont committed
840
    CQL_LIBS="`$CQL_CONFIG --libs $cql_lib`"
841
    CQL_VERSION=`$CQL_CONFIG --modversion $cql_lib`
842

Tomek Mrugalski's avatar
Tomek Mrugalski committed
843 844
    AC_SUBST(CQL_CPPFLAGS)
    AC_SUBST(CQL_LIBS)
845

Tomek Mrugalski's avatar
Tomek Mrugalski committed
846
    # Check that a simple program using CQL functions can compile and link.
847 848 849
    CPPFLAGS_SAVED="$CPPFLAGS"
    LIBS_SAVED="$LIBS"

Tomek Mrugalski's avatar
Tomek Mrugalski committed
850 851
    CPPFLAGS="$CQL_CPPFLAGS $CPPFLAGS"
    LIBS="$CQL_LIBS $LIBS"
852 853 854 855 856

    AC_LINK_IFELSE(
            [AC_LANG_PROGRAM([#include <cassandra.h>],
                             [CassCluster* cluster = cass_cluster_new();
                              cass_cluster_free(cluster);])],
Tomek Mrugalski's avatar
Tomek Mrugalski committed
857 858 859
            [AC_MSG_RESULT([checking for Cassandra CQL headers and library... yes])],
            [AC_MSG_RESULT([checking for Cassandra CQL headers and library... no])
             AC_MSG_ERROR([Needs Cassandra CQL library])]
860 861 862 863
    )
    CPPFLAGS=$CPPFLAGS_SAVED
    LIBS=$LIBS_SAVED

Tomek Mrugalski's avatar
Tomek Mrugalski committed
864 865
    # Note that CQL is present in the config.h file
    AC_DEFINE([HAVE_CQL], [1], [CQL is present])
866 867 868
fi

# ... and at the shell level, so Makefile.am can take action depending on this.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
869
AM_CONDITIONAL(HAVE_CQL, test "$CQL_CONFIG" != "")
870

871
DISTCHECK_SYSREPO_CONFIGURE_FLAG=
872 873 874 875 876 877 878 879
sysrepo_config="no"
AC_ARG_WITH([sysrepo],
  AC_HELP_STRING([--with-sysrepo=PATH],
    [path to the Sysrepo 'sysrepo_config' script]),
    [sysrepo_config="$withval"])

if test "${sysrepo_config}" = "yes" ; then
    SYSREPO_CONFIG="$PKG_CONFIG"
880
    DISTCHECK_SYSREPO_CONFIGURE_FLAG="-with-sysrepo=${sysrepo_config}"
881 882
elif test "${sysrepo_config}" != "no" ; then
    SYSREPO_CONFIG="${sysrepo_config}"
883
    DISTCHECK_SYSREPO_CONFIGURE_FLAG="-with-sysrepo=${sysrepo_config}"
884
fi
885
AC_SUBST(DISTCHECK_SYSREPO_CONFIGURE_FLAG)
886

887
if test "$SYSREPO_CONFIG" != "" ; then
888
    if test -d "$SYSREPO_CONFIG" -o ! -x "$SYSREPO_CONFIG" ; then
889
        AC_MSG_ERROR([--with-sysrepo should point to a pkg-config or sysrepo_config program])
890 891
    fi

892
    # Let's get the configuration environment for pure Sysrepo (written in C) first
Andrei Pavel's avatar
Andrei Pavel committed
893 894 895 896
    SYSREPO_INCLUDEDIR=`$SYSREPO_CONFIG --cflags-only-I libsysrepo`
    SYSREPO_CPPFLAGS="$SYSREPO_INCLUDEDIR `$SYSREPO_CONFIG --cflags-only-other libsysrepo`"
    SYSREPO_LIBS="`$SYSREPO_CONFIG --libs libsysrepo`"
    SYSREPO_VERSION=`$SYSREPO_CONFIG --modversion libsysrepo`
897
    SYSREPO_REPO=`$SYSREPO_CONFIG --variable=SR_REPOSITORY_LOC libsysrepo`
898

899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918
    # Now get the environment for C++ bindings for Sysrepo.
    SYSREPOCPP_INCLUDEDIR=`$SYSREPO_CONFIG --cflags-only-I libSysrepo-cpp`
    SYSREPOCPP_CPPFLAGS="$SYSREPO_INCLUDEDIR `$SYSREPO_CONFIG --cflags-only-other libSysrepo-cpp`"
    SYSREPOCPP_LIBS="`$SYSREPO_CONFIG --libs libSysrepo-cpp`"
    SYSREPOCPP_VERSION=`$SYSREPO_CONFIG --modversion libSysrepo-cpp`

    # If include paths are equal, there's no need to include both. But if they're different,
    # we need both.
    if test "${SYSREPO_INCLUDEDIR}" != "${SYSREPOCPP_INCLUDEDIR}"; then
       SYSREPO_INCLUDEDIR="${SYSREPO_INCLUDEDIR} ${SYSREPOCPP_INCLUDEDIR}"
    fi

    if test "${SYSREPO_CPPFLAGS}" != "${SYSREPOCPP_CPPFLAGS}"; then
       SYSREPO_CPPFLAGS="${SYSREPO_CPPFLAGS} ${SYSREPOCPP_CPPFLAGS}"
    fi

    if test "${SYSREPO_LIBS}" != "${SYSREPOCPP_LIBS}"; then
       SYSREPO_LIBS="${SYSREPO_LIBS} ${SYSREPOCPP_LIBS}"
    fi

919 920
    AC_SUBST(SYSREPO_CPPFLAGS)
    AC_SUBST(SYSREPO_LIBS)
921
    AC_SUBST(SYSREPO_REPO)
922

Andrei Pavel's avatar
Andrei Pavel committed
923
    # Check that a simple program using Sysrepo functions can compile and link.
924 925 926 927 928 929 930
    CPPFLAGS_SAVED="$CPPFLAGS"
    LIBS_SAVED="$LIBS"

    CPPFLAGS="$SYSREPO_CPPFLAGS $CPPFLAGS"
    LIBS="$SYSREPO_LIBS $LIBS"

    AC_LINK_IFELSE(
Andrei Pavel's avatar
Andrei Pavel committed
931 932 933
            [AC_LANG_PROGRAM([extern "C" {
                              #include <sysrepo.h>
                              }],
934 935 936 937 938 939 940 941
                              [sr_conn_ctx_t *connection = NULL;
                              sr_session_ctx_t *session = NULL;
                              sr_connect("configure_test", SR_CONN_DEFAULT, &connection);
                              sr_disconnect(connection);])],
            [AC_MSG_RESULT([checking for Sysrepo headers and library... yes])],
            [AC_MSG_RESULT([checking for Sysrepo headers and library... no])
             AC_MSG_ERROR([Needs Sysrepo library])]
    )
942 943 944 945 946 947 948 949 950

    AC_LINK_IFELSE(
            [AC_LANG_PROGRAM([#include <sysrepo-cpp/Session.h>],
                              [Connection("conn-name");])],
            [AC_MSG_RESULT([checking for Sysrepo C++ bindings headers and library... yes])],
            [AC_MSG_RESULT([checking for Sysrepo C++ bindings headers and library... no])
             AC_MSG_ERROR([Needs Sysrepo C++ bindings (unable to find Sysrepo-ccp library. To get it, you need to compile sysrepo with -DGEN_CPP_BINDINGS=ON.])]
    )

951 952 953
    CPPFLAGS=$CPPFLAGS_SAVED
    LIBS=$LIBS_SAVED

Andrei Pavel's avatar
Andrei Pavel committed
954
    # Note that Sysrepo is present in the config.h file
955 956 957 958 959 960
    AC_DEFINE([HAVE_SYSREPO], [1], [SYSREPO is present])
fi

# ... and at the shell level, so Makefile.am can take action depending on this.
AM_CONDITIONAL(HAVE_SYSREPO, test "$SYSREPO_CONFIG" != "")

961
# Check for log4cplus
962
DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG=
963 964 965 966 967
log4cplus_path="yes"
AC_ARG_WITH([log4cplus],
  AC_HELP_STRING([--with-log4cplus=PATH],
    [specify exact directory of log4cplus library and headers]),
    [log4cplus_path="$withval"])
968
if test "${log4cplus_path}" = "no" ; then
969 970
    AC_MSG_ERROR([Need log4cplus])
elif test "${log4cplus_path}" != "yes" ; then
971
  DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG="-with-log4cplus=${log4cplus_path}"
972
  LOG4CPLUS_INCLUDES="-I${log4cplus_path}/include"
973
  LOG4CPLUS_LIBS="-L${log4cplus_path}/lib"
974 975
else
# If not specified, try some common paths.
976
        for d in $defaultdirs
977 978 979 980 981 982 983
        do
                if test -f $d/include/log4cplus/logger.h; then
                        LOG4CPLUS_INCLUDES="-I$d/include"
                        LOG4CPLUS_LIBS="-L$d/lib -L$d/lib64"
                        break
                fi
        done
984
	DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG="-with-log4cplus"
985 986
fi

Francis Dupont's avatar
Francis Dupont committed
987
LOG4CPLUS_LIBS="$LOG4CPLUS_LIBS -llog4cplus"
988

989
AC_SUBST(DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG)
990
AC_SUBST(LOG4CPLUS_LIBS)
991 992 993 994
AC_SUBST(LOG4CPLUS_INCLUDES)

CPPFLAGS_SAVED=$CPPFLAGS
CPPFLAGS="$LOG4CPLUS_INCLUDES $CPPFLAGS"
995
LIBS_SAVED="$LIBS"
Francis Dupont's avatar
Francis Dupont committed
996
LIBS="$LOG4CPLUS_LIBS $MULTITHREADING_FLAG $LIBS"
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009

AC_CHECK_HEADERS([log4cplus/logger.h],,AC_MSG_ERROR([Missing required header files.]))
AC_LINK_IFELSE(
        [AC_LANG_PROGRAM([#include <log4cplus/logger.h>
                         ],
                         [using namespace log4cplus;
                          Logger logger = Logger::getInstance("main");
                         ])],
        [AC_MSG_RESULT([checking for log4cplus library... yes])],
        [AC_MSG_RESULT([checking for log4cplus library... no])
         AC_MSG_ERROR([Needs log4cplus library])]
)

1010 1011 1012
dnl Determine the log4cplus version, used mainly for config.report.
AC_MSG_CHECKING([log4cplus version])
cat > conftest.cpp << EOF
1013
#include <log4cplus/version.h>
1014 1015 1016
AUTOCONF_LOG4CPLUS_VERSION=LOG4CPLUS_VERSION_STR
EOF

1017
LOG4CPLUS_VERSION=`$CPPP $CPPFLAGS conftest.cpp | grep '^AUTOCONF_LOG4CPLUS_VERSION=' | $SED -e 's/^AUTOCONF_LOG4CPLUS_VERSION=//' -e 's/[[ 	]]//g' -e 's/"//g' 2> /dev/null`
1018 1019 1020 1021 1022 1023
if test -z "$LOG4CPLUS_VERSION"; then
  LOG4CPLUS_VERSION="unknown"
fi
$RM -f conftest.cpp
AC_MSG_RESULT([$LOG4CPLUS_VERSION])

1024
CPPFLAGS=$CPPFLAGS_SAVED
1025
LIBS=$LIBS_SAVED
1026

1027 1028 1029
#
# Configure Boost header path
#
1030
AX_BOOST_FOR_KEA
1031 1032
# Boost offset_ptr is required in one library and not optional right now, so
# we unconditionally fail here if it doesn't work.
1033
if test "$BOOST_OFFSET_PTR_WOULDFAIL" = "yes" -a X"$werror_ok" = X1; then
1034
    AC_MSG_ERROR([Failed to compile a required header file.  Try upgrading Boost to 1.44 or higher (when using clang++) or specifying --without-werror.  See the ChangeLog entry for Trac no. 2147 for more details.])
1035
fi
1036

1037 1038 1039 1040
if test "$BOOST_STATIC_ASSERT_WOULDFAIL" = "yes" -a X"$werror_ok" = X1; then
    AC_MSG_ERROR([Failed to use Boost static assertions. Try upgrading Boost to 1.54 or higher (when using GCC 4.8) or specifying --without-werror.  See trac ticket no. 3039 for more details.])
fi

1041
# There's a known bug in FreeBSD ports for Boost that would trigger a false
1042 1043
# warning in build with g++ and -Werror (we exclude clang++ explicitly to
# avoid unexpected false positives).
1044
if test "$BOOST_NUMERIC_CAST_WOULDFAIL" = "yes" -a X"$werror_ok" = X1 -a $CLANGPP = "no"; then
1045 1046 1047 1048
    AC_MSG_ERROR([Failed to compile a required header file.  If you are using FreeBSD and Boost installed via ports, retry with specifying --without-werror.  See the ChangeLog entry for Trac no. 1991 for more details.])
fi

# Add some default CPP flags needed for Boost, identified by the AX macro.
1049
CPPFLAGS="$CPPFLAGS $CPPFLAGS_BOOST_THREADCONF"
1050

1051
# Can be required by gtest, boost and perhaps still asio
Francis Dupont's avatar
Francis Dupont committed
1052
AC_CHECK_LIB(pthread, pthread_create,[ LDFLAGS="$LDFLAGS -lpthread" ], [])
1053

1054
#
1055
# Check availability of gtest, which will be used for unit tests.
1056
#
1057 1058 1059
GTEST_LDFLAGS=
GTEST_LDADD=
DISTCHECK_GTEST_CONFIGURE_FLAG=
1060
GTEST_VERSION="unknown"
1061

1062
if test "x$enable_gtest" = "xyes" ; then
1063

1064 1065
    DISTCHECK_GTEST_CONFIGURE_FLAG="--with-gtest=$gtest_path"

1066
    if test -n "$with_gtest_source" ; then
1067

1068
        if test "x$GTEST_SOURCE" = "xyes" ; then
1069

1070
            AC_MSG_CHECKING([for gtest source])
1071
            # If not specified, try some common paths.
1072
            GTEST_SOURCE=
1073 1074 1075 1076 1077 1078 1079
            for d in /usr/src/gtest /usr/local /usr/pkg /opt /opt/local ; do
                if test -f $d/src/gtest-all.cc -a $d/src/gtest_main.cc; then
                    GTEST_SOURCE=$d
                    AC_MSG_RESULT([$GTEST_SOURCE])
                    break
                fi
            done
1080
            if test -z $GTEST_SOURCE ; then
1081
                AC_MSG_ERROR([no gtest source but it was selected])
1082
            fi
1083
        else
1084 1085 1086
            if test ! -d $GTEST_SOURCE/src -a -d $GTEST_SOURCE/googletest; then
                GTEST_SOURCE=$GTEST_SOURCE/googletest
            fi
1087
            AC_CHECK_FILES([$GTEST_SOURCE/src/gtest-all.cc]
1088 1089 1090 1091 1092
                [$GTEST_SOURCE/src/gtest_main.cc],
                [have_gtest_source=yes],
                [AC_MSG_ERROR([no gtest source at $GTEST_SOURCE])])
        fi
        have_gtest_source=yes
Francis Dupont's avatar
Francis Dupont committed
1093
        GTEST_LDADD="\$(top_builddir)/ext/gtest/libgtest.a"
1094 1095
        DISTCHECK_GTEST_CONFIGURE_FLAG="--with-gtest-source=$GTEST_SOURCE"
        GTEST_INCLUDES="-I$GTEST_SOURCE -I$GTEST_SOURCE/include"
1096
        GTEST_VERSION="`basename $GTEST_SOURCE`"
1097
    fi
1098 1099 1100 1101 1102 1103 1104 1105 1106

    if test "$gtest_path" != "no" ; then
        if test "$gtest_path" != "yes"; then
            GTEST_PATHS=$gtest_path
            if test -x "${gtest_path}/bin/gtest-config" ; then
                GTEST_CONFIG="${gtest_path}/bin/gtest-config"
            fi
        else
            AC_PATH_PROG([GTEST_CONFIG], [gtest-config])
1107
        fi
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
        if test -x "${GTEST_CONFIG}" ; then :
            # using cppflags instead of cxxflags
            GTEST_INCLUDES=`${GTEST_CONFIG} --cppflags`
            GTEST_LDFLAGS=`${GTEST_CONFIG} --ldflags`
            GTEST_LDADD=`${GTEST_CONFIG} --libs`
            GTEST_VERSION=`${GTEST_CONFIG} --version`
            GTEST_FOUND="true"
        else
            AC_MSG_WARN([Unable to locate Google Test gtest-config.])
            if test -z "${GTEST_PATHS}" ; then
                GTEST_PATHS="/usr /usr/local"
1119
            fi
1120 1121 1122 1123 1124 1125
            GTEST_FOUND="false"
        fi
        if test "${GTEST_FOUND}" != "true"; then
            GTEST_FOUND="false"
            for dir in $GTEST_PATHS; do
                if test -f "$dir/include/gtest/gtest.h"; then
1126 1127 1128 1129
                    if ! test -f "$dir/lib/libgtests.a"; then
                        AC_MSG_WARN([Found Google Test include but not the library in $dir.])
                        continue
                    fi
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140
                    GTEST_INCLUDES="-I$dir/include"
                    GTEST_LDFLAGS="-L$dir/lib"
                    GTEST_LDADD="-lgtest"
                    GTEST_FOUND="true"
                    break
                fi
            done
        fi
        if test "${GTEST_FOUND}" != "true"; then
            AC_MSG_ERROR([Cannot find gtest in: $GTEST_PATHS])
        fi
1141

1142
    fi
1143
fi
1144 1145
AM_CONDITIONAL(HAVE_GTEST, test $enable_gtest != "no")
AM_CONDITIONAL(HAVE_GTEST_SOURCE, test "X$have_gtest_source" = "Xyes")
1146
AC_SUBST(DISTCHECK_GTEST_CONFIGURE_FLAG)
1147 1148 1149
AC_SUBST(GTEST_INCLUDES)
AC_SUBST(GTEST_LDFLAGS)
AC_SUBST(GTEST_LDADD)
1150
AC_SUBST(GTEST_SOURCE)
1151

Andrei Pavel's avatar
Andrei Pavel committed
1152 1153 1154
#
# Check availability of benchmark.
#
1155
BENCHMARK_CPPFLAGS=
Andrei Pavel's avatar
Andrei Pavel committed
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
BENCHMARK_LDFLAGS=
BENCHMARK_LDADD=
DISTCHECK_BENCHMARK_CONFIGURE_FLAG=
BENCHMARK_VERSION="unknown"

if test "x$enable_benchmark" = "xyes" ; then

    DISTCHECK_BENCHMARK_CONFIGURE_FLAG="--with-benchmark=$benchmark_path"

    if test -n "$with_benchmark_source" ; then

        if test "x$BENCHMARK_SOURCE" = "xyes" ; then

            AC_MSG_CHECKING([for benchmark source])
            # If not specified, try some common paths.
            BENCHMARK_SOURCE=
            for d in /usr/src/benchmark /usr/local /usr/pkg /opt /opt/local ; do
                if test -f $d/src/benchmark.cc; then
                    BENCHMARK_SOURCE=$d
                    AC_MSG_RESULT([$BENCHMARK_SOURCE])
                    break
                fi
            done
            if test -z $BENCHMARK_SOURCE ; then
                AC_MSG_ERROR([no benchmark source but it was selected])
            fi
        else
            if test ! -d $BENCHMARK_SOURCE/src; then
                BENCHMARK_SOURCE=$BENCHMARK_SOURCE/benchmark
            fi
            AC_CHECK_FILES([$BENCHMARK_SOURCE/src/benchmark.cc],
                [have_benchmark_source=yes],
                [AC_MSG_ERROR([no benchmark source at $BENCHMARK_SOURCE])])
        fi
        have_benchmark_source=yes
1191 1192
        BENCHMARK_CPPFLAGS=`cat \${BENCHMARK_SOURCE}/build/src/CMakeFiles/benchmark.dir/flags.make | grep CXX_DEFINES | cut -d "=" -f 2`
        BENCHMARK_LDADD="\$(BENCHMARK_SOURCE)/build/src/libbenchmark.a"
Andrei Pavel's avatar
Andrei Pavel committed
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
        DISTCHECK_BENCHMARK_CONFIGURE_FLAG="--with-benchmark-source=$BENCHMARK_SOURCE"
        BENCHMARK_INCLUDES="-I$BENCHMARK_SOURCE \
                            -I$BENCHMARK_SOURCE/src \
                            -I$BENCHMARK_SOURCE/include \
                            -I$BENCHMARK_SOURCE/include/benchmark"
        BENCHMARK_VERSION="$(basename $BENCHMARK_SOURCE)"
    fi

    if test "$benchmark_path" != "no" ; then
        if test "$benchmark_path" != "yes"; then
            BENCHMARK_PATHS=$benchmark_path
        fi
1205 1206
        if test -z "${BENCHMARK_PATHS}" ; then
            BENCHMARK_PATHS="/usr /usr/local"
Andrei Pavel's avatar
Andrei Pavel committed
1207
        fi
1208 1209 1210 1211 1212 1213
        BENCHMARK_FOUND="false"
        for dir in ${BENCHMARK_PATHS}; do
            if test -f "$dir/include/benchmark/benchmark.h"; then
                if ! test -f "$dir/lib/libbenchmark.a"; then
                    AC_MSG_WARN([Found Google Benchmark include but not the library in $dir.])
                    continue
Andrei Pavel's avatar
Andrei Pavel committed
1214
                fi
1215 1216 1217 1218 1219 1220 1221
                BENCHMARK_INCLUDES="-I$dir/include"
                BENCHMARK_LDFLAGS="-L$dir/lib"
                BENCHMARK_LDADD="$dir/lib/libbenchmark.a "
                BENCHMARK_FOUND="true"
                break
            fi
        done
Andrei Pavel's avatar
Andrei Pavel committed
1222 1223 1224 1225 1226 1227 1228 1229 1230
        if test "${BENCHMARK_FOUND}" != "true"; then
            AC_MSG_ERROR([Cannot find benchmark in: $BENCHMARK_PATHS])
        fi

    fi
fi
AM_CONDITIONAL(HAVE_BENCHMARK, test $enable_benchmark != "no")
AM_CONDITIONAL(HAVE_BENCHMARK_SOURCE, test "X$have_benchmark_source" = "Xyes")
AC_SUBST(DISTCHECK_BENCHMARK_CONFIGURE_FLAG)
1231
AC_SUBST(BENCHMARK_CPPFLAGS)
Andrei Pavel's avatar
Andrei Pavel committed
1232 1233 1234 1235 1236
AC_SUBST(BENCHMARK_INCLUDES)
AC_SUBST(BENCHMARK_LDFLAGS)
AC_SUBST(BENCHMARK_LDADD)
AC_SUBST(BENCHMARK_SOURCE)

1237 1238 1239 1240 1241 1242
#
# Some Googletest versions bug with C++11 compilers
#
if test $enable_gtest != "no"; then
   AC_MSG_CHECKING([if Google Test is compatible with the compiler])
   CPPFLAGS_SAVED=$CPPFLAGS
1243
   CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES $GTEST_INCLUDES"
1244 1245
   AC_COMPILE_IFELSE(
       [AC_LANG_PROGRAM(
1246 1247 1248 1249 1250
            [#include <boost/shared_ptr.hpp>
            #include <gtest/gtest.h>
            void foo() {
                boost::shared_ptr<int> bar;
                ASSERT_TRUE(bar);
1251
            }],
1252 1253 1254
            [return 0;])],
        [AC_MSG_RESULT(yes)],
        [AC_MSG_ERROR([XXX_TRUE() Google Test macros won't compile; the most likely reason is that a later version of Google Test is required])])
1255 1256
    CPPFLAGS=$CPPFLAGS_SAVED
fi
1257

1258 1259 1260 1261 1262 1263 1264
# Check for CreateUnifiedDiff from gtest >= 1.8.0
if test $enable_gtest != "no"; then
   AC_MSG_CHECKING([for CreateUnifiedDiff in $GTEST_INCLUDES/gtest.h])
   CPPFLAGS_SAVED=$CPPFLAGS
   CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES $GTEST_INCLUDES"
   AC_COMPILE_IFELSE(
       [AC_LANG_PROGRAM(
1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279
            [#include <boost/algorithm/string.hpp>
            #include <gtest/gtest.h>
            #include <string>
            #include <vector>
            std::string nodiff(std::string text) {
                std::vector<std::string> lines;
                boost::split(lines, text, boost::is_any_of("\n"));
                using namespace testing::internal;
                return (edit_distance::CreateUnifiedDiff(lines, lines));
            }],
            [return 0;])],
        [AC_MSG_RESULT(yes)
        AC_DEFINE([HAVE_CREATE_UNIFIED_DIFF], [1],
        [Define to 1 if gtest defines edit_distance::CreateUnifiedDiff])],
        [AC_MSG_RESULT(no)])
1280
    CPPFLAGS=$CPPFLAGS_SAVED
1281
fi
1282

1283 1284 1285
#
# ASIO: we extensively use it as the C++ event management module.
#
1286 1287
# Doesn't seem to be required?
CPPFLAGS="$CPPFLAGS -DBOOST_ASIO_HEADER_ONLY"
1288
#
Francis Dupont's avatar
Francis Dupont committed
1289
# Disable threads: they seems to break things on some systems
Francis Dupont's avatar