Boost logo

Boost :

From: Alexander Grund (alexander.grund_at_[hidden])
Date: 2024-06-12 08:29:53



> A mistake in my view.  CMake for boost should support "modularization".
It does. As long as your library doesn't (transitively) depend on a
specific boost library you don't need to have it present.
Or what do you refer to as "modularization"?
> The CMakeLists.txt in each (sub?)directory would contain the
> "target_link_libraries" if required.  It's possible that some library
> might might be dependent on something besides another library - e.g. a
> test data generator executable.  So using add_subdirectory would be
> more general.
The top-level CML uses `add_subdirectory` for each Boost library
required. Individual Library can use `add_subdirectory` for each of its
own subfolders such as tests and examples.
This call alone does not declare a dependency of any kind. It only
brings the contents/targets of the subdirectory "into view".
You still need to `target_link_libraries(your_lib PRIVATE|PUBLIC
your_dependency)` to declare the dependency relationship.
`add_subdirectory` does not do that so it is not "more general"
If you provide a specific example we can help you there.
E.g. if you need some generated input data for a test you do in CMake:

- Add the generator as an (executable) target
- Declare a rule how to transform input to output data using the target
- Declare a dependency of your test onto the output data
(`add_dependencies`)

Note that this is the same for Boost or any other CMake project.

> Right. and it's only required because we're presuming that the
> invocation is from boost rather than from within the library directory
> itself.  Again - use this project to support the "modularization" of
> Boost.

Again what is "modularization" in this context?

Coming back to your question of how to invoke CMake with your library
directory as the source:

`if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)` can be used to
detect this case

You are then responsible for `add_subdirectory` all your dependencies
(even transitive ones) manually. If they change you need to update your
code.

A nifty variant used by other libraries to add all dependencies using
the existing logic in Boost.CMake is:
 Â Â Â  set(BOOST_INCLUDE_LIBRARIES serialization)
 Â Â Â  set(BOOST_EXCLUDE_LIBRARIES serialization)
 Â Â Â  add_subdirectory(../.. _deps/boost EXCLUDE_FROM_ALL)

or
 Â Â Â  if(NOT BOOST_SUPERPROJECT_VERSION)
 Â        set(BOOST_INCLUDE_LIBRARIES serialization)
 Â Â Â Â Â Â Â  add_subdirectory(../.. _deps/boost EXCLUDE_FROM_ALL)
 Â Â Â Â Â Â Â  return()
 Â Â Â  endif()

Or similar to basically redirect to the Boost super-project

This basically calls the root CML.
Untested though





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