Hi,
TL;DR; Is there a way of selecting specific targets (at build time) from the sub-projects that are built as part of a superbuild?
Consider the simple scenario where there is a superbuild that builds two sub-projects. The reason that those two sub-projects exist is because they are built very differently (e.g. different toolchains).
Each sub-project produces two executables, so let’s call them:
ProjectA: A_exe1, A_exe2
ProjectB: B_exe1, B_exe2
When we run cmake to configure the top-level superbuild, cmake gives us a superbuild configuration that has the two sub-project targets (along with the usual support targets). E.g. running in the “build” directory:
cmake --build . --target help
would list “ProjectA” and “ProjectB” (along with “clean”, etc.)
If we then build those sub-project targets they will (by default) build the “all” target of the sub-project. (E.g. cmake --build . --target ProjectA
)
However, we may want to build just a selection of the targets within a sub-project (e.g. some configuration options may be invalid for some of their targets, or we simply don’t want to waste time building them).
We could pass flags “down” to the sub-projects’ during the initial superbuild configuration to “switch stuff on/off”; however, that has drawbacks; e.g.
- It requires a re-run of the cmake configure, but we do not need reconfiguration; only target selection.
- It’s invasive on the cmake files of the sub-projects. If we were building these sub-projects stand-alone then we’d just build the specific targets (*).
- It’s not scalable; we may want a matrix of target combinations from each sub-project (suppose each sub-project can produce 100 targets).
It seems we’d like to do something like:
cmake --build . --target ProjectA:A_exe2 --target ProjectB:B_exe1
I did experiment with first running the cmake configure for the superbuild, and then trying to build the sub-projects from their generated sub-directories. However, the CMakeCache, etc, are not generated for the sub-projects - these are only created at build time, by which time the target is already “all”. E.g. following cmake ../source_root
the ProjectA and ProjectB sub-dirs are empty. Perhaps there is a way of forcing the sub-project configuration without the build?
The sub-projects are first-party components, so the source is all there; i.e. it does not appear that the FetchContent approach used for 3PP applies here (because AFAICT that copies the whole source sub-tree).
I’ve had a good search for anything superbuild related but haven’t found anything that appears to fit - apologies if this is made obvious somewhere.
(*) Perhaps the superbuild pattern isn’t suited, and this should just be scripted.