Adding a Boost Library with CMake
This page describes how to introduce a new Boost library into the CMake-based build system. Any Boost library that provides a library binary (e.g., boost_signals.dll
) or has regression tests (hopefully, every Boost library!) will need to be part of the build system.
To introduce a new library, which resides in the subdirectory libs/libname
, follow these steps:
- Create a new file
libs/libname/CMakeLists.txt
with your favorite text editor. This file will contain an invocation of the boost_library_project macro, which identifies each Boost library to the build system. The invocation of theboost_library_project
will look like this:boost_library_project( Libname SRCDIRS src TESTDIRS test )
where
Libname
is the properly-capitalization library name, e.g.,Signals
orSmart_ptr
. TheSRCDIRS src
line should only be present if your Boost library actually needs to compile a library binary; header-only libraries can skip this step. TheTESTDIRS test
line indicates that the subdirectorytest
contains regression tests for your library. Every Boost library should have these.
- Re-run CMake to reconfigure the source tree, causing CMake to find the new Boost library. CMake can be re-run either from the command line (by invoking
cmake /path/to/boost
orccmake /path/to/boost
) or, on Windows, using the CMake GUI. Once you have reconfigured and generated new makefiles or project files, CMake knows about your library.
- If your library has compiled sources (i.e., it is not a header-only library), follow the instructions on adding a compiled library to get CMake building and installing your library.
- If your library has regression tests (it
does
have regression tests, right?), follow the instructions on adding regression tests to get CMake to build and run regression tests for your library.