[CMake] OBJECT libraries and working around lake of target_link_libraries

David Hunter davidhunter22 at gmail.com
Tue Jul 11 13:35:07 EDT 2017


We recently converted some software, comprising about 300 projects, to use
OBJECT libraries from SHARED libraries so we could create "conveneince"
libraries that were cominations of some of the 300 projects. Not being
able to use target_link_libraries with thier transitive nature made this
very painful, many days of work. Supporting OBJECT libraries in
target_link_libraries calls was mentioned mentioned right back here
https://cmake.org/pipermail/cmake-developers/2012-March/015422.html but
sadly seems still to be on the back burner.

We are faced with a project hierarchy re-org and wanted to try to automate
generation of the dependencies. So we are thinking of doing the following.

1) Remove all the target_sources stuff from all CMakeLists.txt
2) Add add_dependencies calls to specify the project dependencies
3) run cmake with the --graphviz=graphviz.dot
4) Write a program that reads the resultant graphviz.dot and generate
   a file for each project that contain a target_sources call specifying
   all the dependencies for that project
5) In the CMakeLists.txt  for each project include the relevant generated
   target_sources file
6) Rerun cmake

Note the first time cmake gets run all the generated dependency files
are empty so the only dependencies are those specified by add_dependencies
calls.

Obviously the above is a bit convoluted, although we already have a
program to read and use the data in graphviz.dot file for other reason.
So my question is will the above approach work and is there a better one?


More information about the CMake mailing list