Boost logo

Boost :

Subject: Re: [boost] Moving CMake forward
From: Nana Sakisaka (n.sakisaka_at_[hidden])
Date: 2017-07-22 11:34:14


2017-07-22 18:07 GMT+09:00 John Maddock via Boost <boost_at_[hidden]>:

> (snip)

As a minimal first step, what I would like to see come up for review (yes a
> review folks!) is a system that:
>
> (snip)
> * Is usable by end users to be able to easily reference Boost libraries
> from their own CMake projects (note, might be limited to libraries with
> source, since header only libraries are kind of trivial). An example, and
> how to documentation should be provided.
>

 You can create a virtual target called INTERFACE then users can reference
that target to get all the dependencies for the header files:

set(BOOST_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include")
> add_library(boost_all_headers INTERFACE)
> file(GLOB_RECURSE BOOST_ALL_HEADERS "${BOOST_INCLUDE_DIR}/include" "*.hpp")
> target_include_directories(boost_all_headers INTERFACE
> "${BOOST_INCLUDE_DIR}")
> target_sources(boost_all_headers INTERFACE ${BOOST_ALL_HEADERS})
> install(TARGETS boost_all_headers EXPORT boost_all_headers_export)
> export(
> EXPORT boost_all_headers_export
> FILE "Boost-config.cmake"
> )

Basically you put this kind of script to the root CMakeLists.txt (of Boost).
The steps for the user could be something like:
- Clone the boost library (or its components).
- Run the initial `cmake` for boost.
- Run `make install` - when you have provided some specific options to
CMake, this won't actually *install*; it does the EXPORTing and creates the
Boost-config.cmake on the Boost root.

So if you need only the header-only library, then you can just generate the
exported target without building the libs.

Referencing the exported target should also correctly add the Boost include
directory (pointing to your local installation) to your program.
Sometimes you need the BEFORE PUBLIC property to get it included before the
system-wide dirs.

The script above is a rough sketch, but I hope this helps..

Nana.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk