[cmake-developers] Tools for handling cross project dependencies
Raffi Enficiaud
raffi.enficiaud at mines-paris.org
Wed Sep 27 08:50:05 EDT 2017
Hi CMake,
I am currently working on a toy cmake prototype for Boost. I am not sure
it will ever be released but I believe it might be useful beyond this
project.
The idea is to include several "packages" (one package ~ one project in
Boost) and make those available to the build, exactly as for a regular
CMakeLists.txt that adds several directories or subprojects through a
sequence of calls to "add_directories".
However, the difference here is that "packages" have inter-dependencies,
and the order of the "add_directories" should honor those dependencies.
I developed a rather small CMake script that
* encodes those dependencies in a very simple manner, just by stating
parent projects in the DAG of dependencies in an appropriate cmake variable,
* runs the ordered inclusion of those dependencies inside the master
project,
It works like this:
1/ a small "dependencies.cmake" declares the provided components and
dependencies:
* a variable that indicates the provided components (say "core",
"doc" and "test"). Each component defines a CMakeLists.txt
* a variable that indicates the dependencies to another module (with
or without components)
2/ a function parses a build tree (not necessarily flat) and detect all
those dependencies.cmake, loads the containing variables and extract the
module and components
3/ another function reads the variables set by step 2/ and adds the
components in the right order
Additional filtering can happen after 2 (already implemented in my
project) to remove all the packages/components that are not needed for
the current build, but 3/ will bring any necessary dependency to the build.
A possible example, that can of course be adapted, is given below.
My inquiry there is the following:
* would this be of any interest for the community? I know that some
projects are struggling with this or provide solutions that, as a
developer, dislike
* is there already any such mechanism in cmake? I failed to see any, and
the problem statement is a different than the cmake-package facility
provided by cmake.
I believe it would also be possible to enhance step 3/ by eg. having a
logic that checks out the package sources instead of doing an
"add_directory", and by the possible intermediate filter after step 2/,
then checking out only what is needed for the end-user/developer.
Thanks!
Raffi
------------------ Example for Boost.test ----
set(_current_package "TEST")
# this declares the components
set(BOOST_LIB_${_current_package}_COMPONENTS "build" "doc" "test")
# this declares the dependencies for the component "build"
set(BOOST_LIB_${_current_package}_COMPONENTS_BUILD_DEPENDENCY
"system:build"
"core:build"
"config:build"
"predef:build"
)
# same for the component "DOC"
set(BOOST_LIB_${_current_package}_COMPONENTS_DOC_DEPENDENCY )
# same for the component "TEST" (or the module TEST)
set(BOOST_LIB_${_current_package}_COMPONENTS_TEST_DEPENDENCY "test:build")
More information about the cmake-developers
mailing list