Feature request: Provide a way to control installation of EXCLUDE_FROM_ALL targets
I'm using CMake 3.12.0-rc1 on Windows 10/Ubuntu 18.04.
My project consists of a lot of (almost 100) "module" style targets (static libraries, more or less), but only a few top-level targets that a user would actually want to build. The all
target is empty, that is, every target has EXCLUDE_FROM_ALL
set. The user will, at compile time, decide to build whichever target they need. A single target may depend on a couple of others, so the end result of a single target being built might be eg. an exe file plus a dll plus a couple of other things. Making everything EXCLUDE_FROM_ALL
is partly an optimisation (no single person ever wants to build all targets, so this shortens configure/generate time) and partly semantic (there's no use case that involves all built targets, so why have an all
?).
But I also want to provide installation capabilities, so users don't have to hunt down exes and libs scattered throughout CMake's build tree. I'll want to create installers using CPack at some point too.
Currently there's no easy way to do this if all of my targets are EXCLUDE_FROM_ALL
. According to the documentation, even if I use the OPTIONAL
flag in install()
, the behaviour is undefined, and being a C programmer, I take that to mean "don't do it upon pain of death."
The only other option I see is to create custom commands (POST_BUILD
style) for every target that copies it to some designated output directory. But then I can't take advantage of CMake's other installation capabilities, and I think that would be invisible to CPack. Plus this seems like I'm just reinventing a wheel that's right there already.
I don't know what the implications are of just making install(... OPTIONAL)
on an EXCLUDE_FROM_ALL
target defined, but it seems like that would be the easiest thing from the point of view of a user of CMake, since then all the documentation would apply, features would be consistent, etc. But if that's not possible, could we have some way to do this please?