[CMake] How do I use install() with targets that might not be built?

Jason Heeris jason.heeris at gmail.com
Wed Jul 25 02:09:20 EDT 2018


My project consists of a lot of "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.

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 might
want to create installers using CPack at some point too.

How do I 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. Better not do that.

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.

Is there some other way?

I'm using CMake 3.12 on Windows 10/Ubuntu 18.04, if that's relevant.

Cheers,
Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180725/ea6e5204/attachment.html>


More information about the CMake mailing list