Monday, June 22, 2009

Using boost svn with cmake

This post was created in the interest of saving someone else's sanity. If for some absolutely insane reason you decide to use boost's trunk from your shinny new cmakefile - and thus have a need to negotiate your way through FindBoost - all you need to do is:

  • Make sure you created a symlink for the include directory. By default boost puts its includes under boost-X.YY (e.g. boost-1.39). Just ln -s boost-1_39/boost boost and away you go. Not sure how things work on Win32, but if you need to symlink remember: junction.exe is your friend.
  • Set BOOST_ROOT and only BOOST_ROOT. When things fail to work you may be lured into thinking that artifacts such as Boost_LIBRARY_DIRS or Boost_INCLUDE_DIRS or others of such ilk (BOOST_LIBRARY_DIRS, BOST_LIBRARYDIRS, etc.) may actually help you. How wrong you are. All you need is to get BOOST_ROOT right. To do so, simply point it to the top level directory where you installed boost. For instance, I've placed boost under ~/local. Your BOOST_ROOT is set correctly when ${BOOST_ROOT}/include/boost and ${BOOST_ROOT}/lib exist.
So the final work of art looks like so (pray notice the capitalization!!):

set(BOOST_ROOT /home/marco/local)
find_package(Boost 1.36 REQUIRED COMPONENTS system thread serialization filesystem)
...
include_directories(${INCLUDE_DIR} ${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
...
target_link_libraries(${YOUR_BINARY} ${Boost_LIBRARIES})

That simple. Of course, one must not forget to change this before giving this to anyone else - you should be checking the regular directories where boost gets installed.

No comments: