Search code examples
c++boostmakefileconfigure

How to ignore a build directory if Boost is not present


The top directory for my project has a configure.ac file for which I have included the following lines in order to include the Boost Test library:

BOOST_REQUIRE([1.48])
BOOST_TEST

I am using the boost.m4 macro.

The configure.ac file also contains the following code:

AC_OUTPUT([
Makefile 
include/Makefile
extra/Makefile
comm/Makefile
log/Makefile
strings/Makefile
app1/Makefile
app2/Makefile
app3/Makefile
http/Makefile
locks/Makefile
lib/Makefile
test/Makefile
boost_test/Makefile
])

My top directory has a Makefile.am file that has the following content:

ACLOCAL_AMFLAGS = -I m4
SUBDIRS = include extra comm log strings app1 app2 app3 http locks lib test boost_test
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = metrutil.pc

I have a subdirectory boost_test that contains a Makefile.am with the following content:

AM_CXXFLAGS = @CXXFLAGS@ -I$(top_srcdir)/include $(BOOST_CPPFLAGS) -g -Wall
AM_CFLAGS = @CFLAGS@ -I$(top_srcdir)/include -g -Wall
AM_LDFLAGS = -static $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS)
LDADD = ../lib/libmetrutil.la $(BOOST_UNIT_TEST_FRAMEWORK_LIBS)

bin_PROGRAMS = \
    tests

tests_SOURCES = \
    main.cpp \
    test1.cpp \
    test2.cpp \
    test3.cpp

My problem is that a lot of engineers in our project are not aware of Boost and so they do not have Boost installed in their systems. How should I modify configure.ac and the Makefile.am files so that if Boost is present in the system, then the boost_test Makefile is generated and executed? If the system does not have Boost installed, then the boost_test directory should simply be ignored.


Solution

  • You can use AM_CONDITIONAL to check the existence of boost library. Then in Makefile.am you can use if endif. Here is an example

    In configure.ac, I assume you have done boost check macro and store the result in the variable $enable_boost

    AM_CONDITIONAL([BOOST_ENABLED], test "$enable_boost" = yes)
    

    In Makefile.am

    if BOOST_ENABLED
    SUBDIRS += boost_test
    endif