build: Add check for required Crypto++ library
Change-Id: I3e4db0e3b3d2c00f0a66dda0c69c4325b836b75e
diff --git a/Makefile.am b/Makefile.am
index 4533a01..850d034 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -120,8 +120,8 @@
src/util/string-helper.hpp \
src/util/time.hpp
-libndn_cpp_la_LIBADD = @OPENSSL_LIBS@ @OSX_SECURITY_LIBS@
-libndn_cpp_la_LDFLAGS = @OPENSSL_LDFLAGS@ @SQLITE3_LDFLAGS@ @BOOST_LDFLAGS@
-libndn_cpp_la_CFLAGS = @OPENSSL_INCLUDES@ @SQLITE3_CFLAGS@ @BOOST_CPPFLAGS@
+libndn_cpp_la_LIBADD = @OPENSSL_LIBS@ @CRYPTOPP_LIBS@ @OSX_SECURITY_LIBS@
+libndn_cpp_la_LDFLAGS = @OPENSSL_LDFLAGS@ @CRYPTOPP_LDFLAGS@ @SQLITE3_LDFLAGS@ @BOOST_LDFLAGS@
+libndn_cpp_la_CFLAGS = @OPENSSL_INCLUDES@ @CRYPTOPP_INCLUDES@ @SQLITE3_CFLAGS@ @BOOST_CPPFLAGS@
dist_noinst_SCRIPTS = autogen.sh
diff --git a/configure.ac b/configure.ac
index 7e367d7..c668f29 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,6 +95,8 @@
# Require openssl (libcrypto).
AX_CHECK_OPENSSL([], [AC_MSG_FAILURE([can't find openssl crypto lib])])
+AX_LIB_CRYPTOPP([], [AC_MSG_FAILURE([can't find crypto++ library])])
+
# Conditionally use libsqlite3. AX_LIB_SQLITE3 defines HAVE_SQLITE3 in confdefs.h .
AX_LIB_SQLITE3()
if grep -q "#define HAVE_SQLITE3" confdefs.h ; then
diff --git a/m4/ax_lib_cryptopp.m4 b/m4/ax_lib_cryptopp.m4
new file mode 100644
index 0000000..f4f51fd
--- /dev/null
+++ b/m4/ax_lib_cryptopp.m4
@@ -0,0 +1,101 @@
+# SYNOPSIS
+#
+# AX_LIB_CRYPTOPP([ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
+#
+# DESCRIPTION
+#
+# Test for the Crypto++ library
+#
+# If no intallation prefix to the installed Crypto++ library is given the
+# macro searches under /usr, /usr/local, and /opt.
+#
+# This macro calls:
+#
+# AC_SUBST(CRYPTOPP_INCLUDES)
+# AC_SUBST(CRYPTOPP_LDFLAGS)
+# AC_SUBST(CRYPTOPP_LIBS)
+#
+# And sets:
+#
+# HAVE_CRYPTOPP
+
+AC_DEFUN([AX_LIB_CRYPTOPP],
+[
+ AC_ARG_WITH([cryptopp],
+ AS_HELP_STRING(
+ [--with-cryptopp=@<:@ARG@:>@],
+ [use Crypto++ library @<:@default=yes@:>@, optionally specify the prefix for the library]
+ ),
+ [
+ if test "$withval" = "no"; then
+ WANT_CRYPTOPP="no"
+ elif test "$withval" = "yes"; then
+ WANT_CRYPTOPP="yes"
+ ac_cryptopp_path=""
+ else
+ WANT_CRYPTOPP="yes"
+ ac_cryptopp_path="$withval"
+ fi
+ ],
+ [WANT_CRYPTOPP="yes"]
+ )
+
+ CRYPTOPP_CFLAGS=""
+ CRYPTOPP_LDFLAGS=""
+ CRYPTOPP_LIBS=""
+
+ if test "x$WANT_CRYPTOPP" = "xyes"; then
+
+ AC_MSG_CHECKING([for Crypto++ library])
+
+ ac_cryptopp_header="cryptopp/cryptlib.h"
+ ac_cryptopp_libs="-lcryptopp"
+
+ if test "$ac_cryptopp_path" != ""; then
+ ac_cryptopp_ldflags="-L$ac_cryptopp_path/lib"
+ ac_cryptopp_cppflags="-I$ac_cryptopp_path/include"
+ else
+ for ac_cryptopp_path_tmp in /usr /usr/local /opt ; do
+ if test -f "$ac_cryptopp_path_tmp/include/$ac_cryptopp_header" \
+ && test -r "$ac_cryptopp_path_tmp/include/$ac_cryptopp_header"; then
+ ac_cryptopp_path=$ac_cryptopp_path_tmp
+ ac_cryptopp_cppflags="-I$ac_cryptopp_path_tmp/include"
+ ac_cryptopp_ldflags="-L$ac_cryptopp_path_tmp/lib"
+ break;
+ fi
+ done
+ fi
+
+ CRYPTOPP_INCLUDES="$ac_cryptopp_cppflags"
+ CRYPTOPP_LDFLAGS="$ac_cryptopp_ldflags"
+ CRYPTOPP_LIBS="$ac_cryptopp_libs"
+
+ save_LIBS="$LIBS"
+ save_LDFLAGS="$LDFLAGS"
+ save_CPPFLAGS="$CPPFLAGS"
+
+ LDFLAGS="$LDFLAGS $CRYPTOPP_LDFLAGS"
+ LIBS="$CRYPTOPP_LIBS $LIBS"
+ CPPFLAGS="$CRYPTOPP_INCLUDES $CPPFLAGS"
+ AC_LANG_PUSH(C++)
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([#include <cryptopp/cryptlib.h>], [])],
+ [
+ AC_MSG_RESULT([yes])
+ $1
+ ], [
+ AC_MSG_RESULT([no])
+ $2
+ ])
+ AC_LANG_POP([C++])
+ CPPFLAGS="$save_CPPFLAGS"
+ LDFLAGS="$save_LDFLAGS"
+ LIBS="$save_LIBS"
+
+ AC_SUBST(CRYPTOPP_INCLUDES)
+ AC_SUBST(CRYPTOPP_LDFLAGS)
+ AC_SUBST(CRYPTOPP_LIBS)
+
+ AC_DEFINE([HAVE_CRYPTOPP], [], [Have the Crypto++ library])
+ fi
+])