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 ?
I completely agree with you. I have spent the last 15 mins trying to wrestle with install(TARGETS) to install a custom target and failed. What was frustrating was I cotinued to try using install(TARGETS) over install(PROGRAMS) because of the following line in the docs
This form is intended to install programs that are not targets, such as shell scripts. Use the TARGETS form to install targets built within the project.
That is until I found this thread and @erk mentioned he is pretty sure custom targets cannot be installed with install(TARGETS)