Boost logo

Boost :

From: Alexander Grund (alexander.grund_at_[hidden])
Date: 2024-06-11 08:20:52



> mkdir __build
> cd __build
> cmake ..
> cmake --build .
>
> Does this presume that one starts from the library directory?
This assumes to start from inside the top-level boost folder.
> Does this syntax work for out of source tree builds?  That is, would
> the following work?
>
> mkdir /temp/__build
> cd /temp/__build
> cmake ..
> cmake --build .
Almost. The first CMake invocation needs the path to the Boost root,
then this works.
> (very confusing usage of leading __)
The name "build" is already taken for the library folder as it contains
e.g. the Jamfiles. Using a (very likely) new folder allows to do `rm -r
__build` to start clean
> ahhhh - I see a problem.  I'm thinking of starting from within the
> directory of a particular library.  I'm presuming "modular boost".  Is
> this supported?
This does not work out of the box but needs a CMakeLists.txt especially
tailored for that which is a bit more involved. "Modular boost" refers
to B2 IIRC so this is orthogonal.

> 2) BOOST_INCLUDE_LIBRARY
>
> I would like my CMakeLists.txt file to explicitly list the direct
> antecedent libraries (dependencies - bad word usage).  So I'd expect
> to see something like
No, in CMake you specify your direct dependencies with
`target_link_libraries`. The top-level Boost build (the CMake machinery
added by Peter) has logic to add the required subdirectories.
You only need to list each `Boost::foo` target on a separate line. See
e.g.:
https://github.com/boostorg/variant2/blob/develop/CMakeLists.txt#L15C1-L20

> add_directory(../filesystem)
> add_directory(../regex)

This can and needs to be done to test whether you can use your library
itself with `add_subdirecory` which is an extra test, see e.g.
https://github.com/boostorg/variant2/blob/develop/test/cmake_subdir_test/CMakeLists.txt


> So I could just
> cd to .../libs/serialization
> cmake --build
>
> and have it build the antecedent if and only if required.
A bit different:
- cd to new build folder
- cmake <boost-root> -DBOOST_INCLUDE_LIBRARY=serialization
- cmake --build

BOOST_INCLUDE_LIBRARY is basically the/our CMake way of "b2 --with-foo"

> 3) CMAKE_INSTALL_INCLUDEDIR
>
> I would prefer not to "install" (copy) the include files but just use
> the ones from their original locations.
That variable is only used for installation. Nothing is copied for the build
>
> 4) BUILD_TESTING
>
> I would prefer to have my library source to look like:
>
> ... libs/serialization
>   CMakeLists.txt
>     // includes add_directory for subdirectorys build, test, example,
> profile and ...
>     // includes add_directory for antecedent libraries like
> add_directory(../libs/filesystem)
>   include // directory with include files for users of serialization
> library
>   build(or src) // source files for library build
>     CMakeLists.txt // to build library
>   test
>     CMakeLists.txt
>   example
>     CMakeLists.txt
>   profile
>     CMakeLists.txt
>
> Maybe the add_directory would be conditioned on a CMAKE variable.
You can:
See
https://github.com/boostorg/variant2/blob/f9bdafd3ca0f5025012f60a405b559888513a9be/CMakeLists.txt#L33-L37
Also already done for your root CML
> So if I invoke
>
> CMake --build test_polymorphic_binary_archive
>
> It would recursively (re)build everything necessary and nothing not
> necessary
This requires `-DBUILD_TESTING=ON` but otherwise it will work. However
your targets should be prefixed like
"boost_serialization_test_polymorphic_binary_archive"
>
> If I didn't specify a list of targets, it would recursively (re)build
> everything that needs (re)building.
Yes
> in particular recursive inclusion of header files and likely some
> other stuff.
Yes this is done
> I've also experimented with CMake enough to have a feeling that what I
> want to do is not possible.  And this is the short version of what I'd
> like to do.
See above: With a bit care it is possible. Take some of Peters libraries
as a starting point.
 From what I can only the CMLt in your test folder is missing.
boost_test_jamfile can convert most tests in the jamfile to CMake.
It requires some restrictions though like plain "run foo.cpp ;" and
"compile bar.cpp ;" lines.



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