Adding Boost as a Dependency with CMake

Published:

In this short post, I demonstrate how-to add Boost as a dependency to a C++ project using the mighty CMake.

I use MinGW Distro in this example, which ships with Boost v1.55.0. In my opinion, MinGW Distro is the best Minimum GNU for Windows distribution at this moment (at least if you are using a x64 architecture).

CMake encourages out-of-source builds, and so do I:

CMake supports out-of-source builds, therefore it is recommended to create a subdirectory build which can be ignored by version control.

A MSYS Makefile can be generated by executing the following command from the build directory of your project.

cmake -G"MSYS Makefiles" ..

If you are using *-nix, simply comment out the line containing BOOST_ROOT or modify its value. After that run the following command from the build directory of your project.

cmake ..