Boost logo

Boost Interest :

Subject: Re: [Boost-cmake] find_package and Boost.Cmake
From: Denis Arnaud (denis.arnaud_boost_at_[hidden])
Date: 2011-02-16 09:25:50

>From one of my colleagues...

---------- Forwarded message ----------
From: Daniel Perez
Date: 2011/2/16
Subject: Re: Fwd: [Boost-cmake] find_package and Boost.Cmake

I've been using an *ugly* trick for that purpose but I guess there might be
a more beautiful way to do so by tweaking PATHS or other CMake variables.

I disable /usr/include when I include Boost headers since it seems that
/usr/include always get first in find_package (I insist: there might be a
nicer way to tell CMake which paths to use, but I didn't find). I do as

*1)* Unzip a Boost distribution somewhere in your project's sources and
enable it with include_directories(). I put Boost in the root of my sources
so that I don't have to enable it with include_directories() since the root
of the sources is always included by default in my projects.

*2)* In your CMakeLists.txt you add:

  find_package( Boost 1.43.0 )
   set (*USE_IN_SOURCE_TREE_BOOST* true)

so USE_IN_SOURCE_TREE_BOOST is defined in the case Boost is not found in the
system. If you always want to use the in-source Boost, define that variable
unconditionally. Take into consideration that I'm assuming that if you ship
your own Boost version it means that you don't care about the version checks
and the include paths checks. To note that this assumption only holds for
header-only distributions of Boost.

*3)* You disable /usr/include for the desired set of headers by clearing


// BOOST Gregorian
#include <boost/date_time/gregorian/gregorian.hpp>
// BOOST Spirit
#include <boost/spirit/include/qi.hpp>
#include <boost/typeof/typeof.hpp>
// This is needed to use Fusion & maps
#include <boost/fusion/include/std_pair.hpp>
// Phoenix Bind, << operator for val() and some others,
// construct<> and at_c
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/spirit/home/phoenix/bind/bind_function.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>

I clear this variable in a .cpp file so it's not dangerous.

I hope it helps. And please, let me know if you find a better way of doing
this (by supplying PATHS or the like).


Boost-cmake list run by bdawes at, david.abrahams at, gregod at, cpdaniel at, john at