install(FILE ...) with custom_target

Dear all,

TL ; DR: Is there a way to let “install(FILES output )” add a dependency of the target “install” to the file “output” ?

I am building additional files, which will be used only at install time. Parts of that is the documentation. There is a quite similar old and similar question on stackoverflow (number 9163176). Similar topics here are:

  1. 1 which tries to install a program
  2. 2 which tries to install a directory

The common solution was always to add the custom target to the common target “ALL”. But that has the drawback, that the targets will we generated everytime, not only when installing. Furthermore the target is always out of date, even if it creates an output.

Is there any other way despite adding a dependency to the ALL-target? Are there any plans to extend the install(FILES …) commands in that direction?

There is currently no way to add dependencies to CMake’s built-in targets. See this issue.

Nice to see how old that feature request is. My impression is, that the main problem stems from the “local folder” requirement.

What makes me wondering is, that cmake automaticly determines the dependencies on custom files for executable and library targets. Is it possible to do the same with the install(FILES …) command? I think that would also resolve the issue.

That approach can be folder-specific, such that only custom files in sub-folders are considered.

That sounds more in line with this issue.

It looks quite similar, but from the viewpoint of the target “test” instead of “install”.

Should I open a new issue as feature request? What is the best way?

I would just add it as a comment there. If we don’t tackle it as well in the same solution, it can be migrated to its own issue.