How can I install a custom target?

You don’t want to use a custom target for this. Targets are a build time thing, installs are completely separate. Don’t be fooled into thinking an install is still part of the build just because there’s an install build target. That isn’t really a proper build target in that it acts mostly just as a convenience wrapper for running the install. I normally recommend if people want to do an install, the more canonical way is to run cmake --install /path/to/build/dir --prefix /where/you/want/to/install/to. The install details are all contained in dedicated files in the build directory, completely separate from the build description in your build.ninja, Makefile, or whatever build system you’ve used.

For logic you want to run as part of an install, you should indeed be using install(CODE) or install(SCRIPT).

1 Like