How to install a custom target ?

I am creating a target to generate a script using add_custom_target(). Now I want to install it, but:

  • install(TARGETS) fails with “install TARGETS given target “script” which is not an executable, library, or module.” and I can’t find a way to tell cmake that this target has TYPE EXECUTABLE
  • install(PROGRAMS) would allow me to specify “TYPE EXECUTABLE”, but does not appear to let me specify a file from build tree, only source tree

What did I miss ?

Moreover, the “correct way” to use add_custom_target() seems to be together with add_custom_command() if we want proper dependency handling. But then it seems I have to give different names to the “command” (which takes the output file name) and to the target. And then I’m at a loss as to how install(TARGETS) can be used at all: specifying the file name does not work as it is not a target name, and specifying the target name naturally does not work as it’s not the file name. So what ?

What’s make you think so? The doc:
File names given as relative paths are interpreted with respect to the current source directory

I bet that if you provide absolute path you can install any file in the build tree.
Did you try something like?

I’m pretty sure you cannot use install(TARGETS) for custom target.

Right, this works, thanks. It would be useful to get this example in the doc, I’d say.
Also, if we go with install(PROGRAMS), then better use “TYPE BIN” than “DESTINATION bin”

That seems pretty counter-intuitive, to say the list. If this is so, it should surely be mentionned in the doc too.

Using install(PROGRAMS) still feels like a hack, and anyway it looks like we can’t use the “proper” add_custom_cammand() idiom.