My project compiles using GNU autotools (aclocal && autoconf && ./configure && make
). I'd like to use Boost, and I'd like for other people to be able to compile it as well.
/usr/share/aclocal
dir, but that doesn't help someone else who wants to compile the project using ./configure && make
.The Archive has AX_BOOST_*
.
I switched to boost.m4 for some time, but it is so painfully slow I could edit a Makefile with the full Boost path by hand in vim before boost.m4 finished testing for the second library.
I went back to the Archive and was happy to learn the boost macros are being actively maintained again; then I proceeded to purge boost.m4 from every one of my projects.
Relevant excerpts from a use case (assuming the ax_boost_*.m4 files are in subdir m4):
aclocal -I m4 --install
...
...
AC_CONFIG_MACRO_DIR([m4])
...
AX_BOOST_BASE([1.48],, [AC_MSG_ERROR([libfoo needs Boost, but it was not found in your system])])
AX_BOOST_SYSTEM
AX_BOOST_FILESYSTEM
...
ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = bootstrap ...
SUBDIRS = ... src ...
...
AM_CPPFLAGS = \
... \
$(BOOST_CPPFLAGS) \
...
...
AM_LDFLAGS = ... \
$(BOOST_LDFLAGS)
...
lib_LTLIBRARIES = libFoo.la
...
libFoo_la_LIBADD = \
... \
$(BOOST_FILESYSTEM_LIB) \
$(BOOST_SYSTEM_LIB) \
...
There's an excellent boost.m4 macro that you can include in your project in the m4
subdirectory. These macros are located with AC_CONFIG_MACRO_DIR([m4])
in configure.ac
.
Add ACLOCAL_AMFLAGS = -I m4 --install
to the top-level Makefile.am
, used by automake
.
Here's why it's such a good macro:
BOOST_REQUIRE([1.54],[ACTION-IF-NOT-FOUND])
This will define BOOST_CPPFLAGS
which you can add to CPPFLAGS
, use in an AC_SUBST
, etc.
For individual Boost components, it's possible to specify debug builds, static builds, etc. But the (typically) multi-threaded, dynamic libraries are best, e.g.,
BOOST_FILESYSTEM([mt])
will define BOOST_FILESYSTEM_LIBS
and BOOST_FILESYSTEM_LDFLAGS
. As another bonus, if the library relies on, say, Boost.System, then these library dependencies are automatically added to the LIBS
, LDFLAGS
, etc.
You should just specify that a Boost installation is required rather than trying to distribute it. It's easily built and installed from source, or from precompiled packages. The former takes a long time, but it's best to have an 'optimized' build on the system. There's a lot of software that can make use of a (robust and optimized) Boost implementation.
Then use the BOOST_REQUIRE
error message if there's no acceptable version available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With