[CMake] Install optional targets

Tim Gallagher tim.gallagher at gatech.edu
Sun Aug 28 19:20:56 EDT 2011


Hi,

I asked about this awhile back and haven't had any luck with it, so I'll try again.

What we are trying to do is have a project (called Utilities) that has a bunch of targets (the actual utility executables). Let's say there are 4 utils: pre, post, grid, and restart. We would like to do something like:

make pre
make post
make install

Where the "make install" step only installs the targets that have been built. If each target is created with the add_executable() and then has an install() (without OPTIONAL), then typing "make install" will build pre, post, grid and restart. 

If each target has EXCLUDE_FROM_ALL and an install() (without OPTIONAL), CMake warns that the behavior is undefined and "make install" does nothing. 

If each target has EXCLUDE FROM_ALL and OPTIONAL in the install(), the same as above.

If each target is in all and OPTIONAL is in the install(), then "make install" still builds all the targets, not just the ones already built. 

So it appears the "install" target depends on the "all" target. And since all the utilities are part of "all," they get built, even when OPTIONAL is specified. 

Is what we're trying to do possible? We have it working where we create custom targets for each utility, ie:

make pre
make post
make install_pre
make install_post

but it would be much nicer/easier if there was just a "install all targets that have been built" step. 

Any suggestions?

Tim


More information about the CMake mailing list