From d27ace98baa233675460f6989929909c531311f5 Mon Sep 17 00:00:00 2001 From: peerkoel Date: Sun, 16 Oct 2005 19:13:54 +0000 Subject: [PATCH] The examples/client_test program depends on Boost::Regex and Boost::ProgramOptions. The configure script detects these and builds the client_test if the necessary libs are found. --- configure.in | 19 ++++++++++++++++ examples/Makefile.am | 7 +++--- m4/ax_boost_program_options.m4 | 41 ++++++++++++++++++++++++++++++++++ m4/ax_boost_regex.m4 | 41 ++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 m4/ax_boost_program_options.m4 create mode 100644 m4/ax_boost_regex.m4 diff --git a/configure.in b/configure.in index 50b6e82d0..bef46cf63 100644 --- a/configure.in +++ b/configure.in @@ -37,6 +37,25 @@ if test -z "$BOOST_THREAD_LIB"; then AC_MSG_ERROR([unable to find Boost.Thread library, currently this is required.]) fi +AX_BOOST_REGEX +dnl check that Boost.Regex was found: +if test -z "$BOOST_REGEX_LIB"; then + AC_MSG_RESULT([unable to find Boost.Regex library, example test_client will not be build.]) + BUILD_TESTCLIENT=no; +fi + +AX_BOOST_PROGRAM_OPTIONS +dnl check that Boost.Program_options was found: +if test -z "$BOOST_PROGRAM_OPTIONS_LIB"; then + AC_MSG_RESULT([unable to find Boost.Program_options library, example test_client will not be build.]) + BUILD_TESTCLIENT=no; +fi + +if [[ "x$BUILD_TESTCLIENT" != "xno" ]]; then + CLIENT_TEST_BIN=client_test; + AC_SUBST(CLIENT_TEST_BIN) +fi + dnl try different ways of resolving gethostbyname AC_CHECK_FUNC(gethostbyname, , AC_CHECK_LIB(resolv, gethostbyname, , diff --git a/examples/Makefile.am b/examples/Makefile.am index da9c8d30c..373075341 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,8 +1,9 @@ -bin_PROGRAMS = client_test dump_torrent make_torrent simple_client +bin_PROGRAMS = @CLIENT_TEST_BIN@ dump_torrent make_torrent simple_client +EXTRA_PROGRAMS = client_test EXTRA_DIST = Jamfile client_test_SOURCES = client_test.cpp -client_test_LDADD = $(top_builddir)/src/libtorrent.la +client_test_LDADD = $(top_builddir)/src/libtorrent.la -l@BOOST_REGEX_LIB@ -l@BOOST_PROGRAM_OPTIONS_LIB@ dump_torrent_SOURCES = dump_torrent.cpp dump_torrent_LDADD = $(top_builddir)/src/libtorrent.la @@ -14,4 +15,4 @@ simple_client_SOURCES = simple_client.cpp simple_client_LDADD = $(top_builddir)/src/libtorrent.la AM_CXXFLAGS=-ftemplate-depth-50 -I$(top_srcdir)/include @DEBUGFLAGS@ @PTHREAD_CFLAGS@ -AM_LDFLAGS= ${LDLAGS} -L./ -l@BOOST_DATE_TIME_LIB@ -l@BOOST_FILESYSTEM_LIB@ -l@BOOST_THREAD_LIB@ @PTHREAD_LIBS@ +AM_LDFLAGS= ${LDLAGS} -L./ -l@BOOST_DATE_TIME_LIB@ -l@BOOST_FILESYSTEM_LIB@ -l@BOOST_THREAD_LIB@ @PTHREAD_LIBS@ diff --git a/m4/ax_boost_program_options.m4 b/m4/ax_boost_program_options.m4 new file mode 100644 index 000000000..7e88f6df0 --- /dev/null +++ b/m4/ax_boost_program_options.m4 @@ -0,0 +1,41 @@ +dnl @synopsis AX_BOOST_PROGRAM_OPTIONS +dnl +dnl This macro checks to see if the Boost.ProgramOptions library is installed. +dnl It also attempts to guess the currect library name using several +dnl attempts. It tries to build the library name using a user supplied +dnl name or suffix and then just the raw library. +dnl +dnl If the library is found, HAVE_BOOST_PROGRAM_OPTIONS is defined and +dnl BOOST_THREAD_LIB is set to the name of the library. +dnl +dnl This macro calls AC_SUBST(BOOST_PROGRAM_OPTIONS_LIB). +dnl + + + +AC_DEFUN([AX_BOOST_PROGRAM_OPTIONS], +[AC_REQUIRE([AC_CXX_NAMESPACES])dnl +AC_CACHE_CHECK(whether the Boost::ProgramOptions library is available, +ax_cv_boost_program_options, +[AC_LANG_SAVE + AC_LANG_CPLUSPLUS + AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[#include ]], + [[boost::program_options::options_description desc("test"); return 0;]]), + ax_cv_boost_program_options=yes, ax_cv_boost_program_options=no) + AC_LANG_RESTORE +]) +if test "$ax_cv_boost_program_options" = yes; then + AC_DEFINE(HAVE_BOOST_PROGRAM_OPTIONS,,[define if the Boost::ProgramOptions library is available]) + dnl Now determine the appropriate file names + AC_ARG_WITH([boost-program_options],AS_HELP_STRING([--with-boost-program_options], + [specify the boost program_options library or suffix to use]), + [if test "x$with_boost_thread" != "xno"; then + ax_program_options_lib=$with_boost_program_options + ax_boost_program_options_lib=boost_program_options-$with_boost_program_options + fi]) + for ax_lib in $ax_program_options_lib $ax_boost_program_options_lib boost_program_options; do + AC_CHECK_LIB($ax_lib, main, [BOOST_PROGRAM_OPTIONS_LIB=$ax_lib break]) + done + AC_SUBST(BOOST_PROGRAM_OPTIONS_LIB) +fi +])dnl diff --git a/m4/ax_boost_regex.m4 b/m4/ax_boost_regex.m4 new file mode 100644 index 000000000..f16f27648 --- /dev/null +++ b/m4/ax_boost_regex.m4 @@ -0,0 +1,41 @@ +dnl @synopsis AX_BOOST_REGEX +dnl +dnl This macro checks to see if the Boost.Regex library is installed. +dnl It also attempts to guess the currect library name using several +dnl attempts. It tries to build the library name using a user supplied +dnl name or suffix and then just the raw library. +dnl +dnl If the library is found, HAVE_BOOST_REGEX is defined and +dnl BOOST_REGEX_LIB is set to the name of the library. +dnl +dnl This macro calls AC_SUBST(BOOST_REGEX_LIB). +dnl +dnl @version $Id$ +dnl @author Michael Tindal +dnl +AC_DEFUN([AX_BOOST_REGEX], +[AC_REQUIRE([AC_CXX_NAMESPACES])dnl +AC_CACHE_CHECK(whether the Boost::Regex library is available, +ax_cv_boost_regex, +[AC_LANG_SAVE + AC_LANG_CPLUSPLUS + AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[#include ]], + [[boost::regex r(); return 0;]]), + ax_cv_boost_regex=yes, ax_cv_boost_regex=no) + AC_LANG_RESTORE +]) +if test "$ax_cv_boost_regex" = yes; then + AC_DEFINE(HAVE_BOOST_REGEX,,[define if the Boost::Regex library is available]) + dnl Now determine the appropriate file names + AC_ARG_WITH([boost-regex],AS_HELP_STRING([--with-boost-regex], + [specify the boost regex library or suffix to use]), + [if test "x$with_boost_regex" != "xno"; then + ax_regex_lib=$with_boost_regex + ax_boost_regex_lib=boost_regex-$with_boost_regex + fi]) + for ax_lib in $ax_regex_lib $ax_boost_regex_lib boost_regex; do + AC_CHECK_LIB($ax_lib, main, [BOOST_REGEX_LIB=$ax_lib break]) + done + AC_SUBST(BOOST_REGEX_LIB) +fi +])dnl