How to incorporate Boost into the GNU Autotools project?

My project compiles using GNU autotools ( aclocal && autoconf && ./configure && make ). I would like to use Boost, and I would like other people to be able to compile it too.

  • Should I put Boost in my project, or rely on the Boost system?
  • How do I tell autotools to use boost? I googled and found many m4 files that claim to be needed, but where should I put these m4 files? I can write it to the /usr/share/aclocal , but this does not help someone who wants to compile the project using ./configure && make .
+6
source share
3 answers

The archive has AX_BOOST_* .

I switched to boost.m4 for some time, but it hurt so slowly. I can edit the Makefile with the full Boost way manually in vim before boost. m4 finished testing for the second library.

I returned to the Archive and was glad to know that enhancement macros are actively supported again; then I started cleaning boost.m4 from each of my projects.

Relevant excerpts from the use case (assuming the ax_boost _ *. M4 files are in subdir m4):

./ self-loading

 aclocal -I m4 --install ... 

./configure.ac

 ... 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 ... 

./Makefile.am

 ACLOCAL_AMFLAGS = -I m4 EXTRA_DIST = bootstrap ... SUBDIRS = ... src ... ... 

./SRc/ makeake file

 AM_CPPFLAGS = \ ... \ $(BOOST_CPPFLAGS) \ ... ... AM_LDFLAGS = ... \ $(BOOST_LDFLAGS) ... lib_LTLIBRARIES = libFoo.la ... libFoo_la_LIBADD = \ ... \ $(BOOST_FILESYSTEM_LIB) \ $(BOOST_SYSTEM_LIB) \ ... 
+15
source

There is an excellent boost.m4 macro, which 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 .

This is why it is 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 AC_SUBST , etc.

For individual Boost components, you can specify debug assemblies, static assemblies, etc. But the most typical (usually) multithreaded dynamic libraries, for example,

 BOOST_FILESYSTEM([mt]) 

will define BOOST_FILESYSTEM_LIBS and BOOST_FILESYSTEM_LDFLAGS . As another bonus, if a library uses, say, Boost.System, then these library dependencies are automatically added to LIBS , LDFLAGS , etc.


You should simply indicate that a Boost installation is required, rather than trying to distribute it. It is easy to build and install from the source or from precompiled packages. The first one takes a lot of time, but it is best to have an โ€œoptimizedโ€ build in the system. There is a lot of software that can use the (robust and optimized) Boost implementation.

Then use the BOOST_REQUIRE error message if no version is available.

+1
source
  • I definitely rely on installing the Boost system. IIRC, the last time I built Boost, custom tools were needed to create Boost (for the portable tools needed for autoconf). It also took a lot of time.
  • AC_CONFIG_MACRO_DIR is where these .m4 files go

     AC_CONFIG_MACRO_DIR([m4]) 

where the macros are in the "m4" directory. I expected that various Boost.m4 macros would have a way to tell configure which Boost package to look for (for several Boost installations) and where it is (non-standard installations).

0
source

Source: https://habr.com/ru/post/951912/


All Articles