[CMake] Can I build targets during all but NOT during install?

Paul Smith paul at mad-scientist.net
Sat Aug 25 20:19:31 EDT 2018


On Mon, 2018-01-01 at 18:12 -0500, Paul Smith wrote:
> What I hoped is for the default build with no targets specified to
> build everything ("all"), but if I invoke the build with the
> "install" target it builds only the things that are to be installed,
> not my test programs.
> 
> Unfortunately it doesn't seem like this is possible; at least when I
> examine the Makefiles generated by the CMake Unix Makefiles
> generator, the install target depends on the preinstall target which
> depends on all.  Is this true in general or is there something in my
> CMake setup that causes it?

FYI I'm using CMake 3.11.3 on GNU/Linux, MacOS, and Windows with Visual
Studio.

Thanks to Oleksii Vilchanskyi <oleksii.vilchanskyi at gmail.com> for
pointing me to CMAKE_SKIP_INSTALL_ALL_DEPENDENCY.

This appears (not tested completely yet) to do half of what I'd like,
by keeping the "install" target from depending on "all".


The other half is that I want to have the "all" target depend on
"install", instead: all should build all the installation targets AND
also build all the extra testing stuff that is not needed during
install.

I can't seem to figure out how to do that; add_dependencies()
explicitly says that I can't use it with "install" and I don't see any
other way to add dependencies to a target.

Is this possible?  Or do I need to go around to all my "all"
dependencies and explicitly add them to "install" as well?


Then the next step after that is I'd like my "install" target to have
dependencies which are built during installation but don't actually
copy any files anywhere: they are just built and left as-is when I run
the "install" rule (e.g., "make install" or whatever).

I can't come up with a way to modify the dependencies of the "install"
target without using the install() rule.

The manual says that the DESTINATION option in install() is optional,
but if I leave it out I get errors.

Is that possible?


More information about the CMake mailing list