Getting boost test to work on windows and with cmake
This is not the only way to get boost test to work on windows ,most likely, but it is a way which works.
Boost version used
boost 1.48.0
Building boost
It’s best just to build what you need from boost. It’s not worth trying to build all of it, unless you have lots of time and disk-space.
To build just boost test, first run bootstrap, then run b2 using the following command-line:
b2 --with-test link=shared variant=debug threading=multi runtime-link=shared stage
Setting ‘link’ to ‘shared’ works very well. I couldn’t get boost test working on windows with ‘link’ set to ‘static’, plus cmake defaults to using link=shared.
That’s the hard bit done.
A gotcha: if you’re testing using the commandline, cl, you must enable exceptions, which are not enabled by default, otherwise you will see a link error for a method boost::throw_exception().
Running cmake
Now, cmake is quite easy. In the CMakeFiles.txt, you want some lines like:
find_package(Boost COMPONENTS unit_test_framework REQUIRED )
include_directories( ${Boost_INCLUDE_DIR} )
link_libraries( ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY_DEBUG} )
When you run cmake-gui on Windows, after running ‘configure’ the first time, it will give an error message asking to set BOOST_ROOT, so set BOOST_ROOT, by doing ‘add entry’, and then rerun configure, and it should work ok.