How to install a specific target for multiple projects by `add_subdirectory`?

CMakeLists.txt

add_subdirectory(App1)
add_subdirectory(App2)

Can the user choose to install only App1 and how?

If the COMPONENTS argument is specified to the relevant install() commands, yes. Otherwise, the Makefile generator supports per-directory install targets, but no other generators do (AFAIK) by doing make -C App1 install. Note that per-directory installs may miss dependencies that need installed outside of that directory.

1 Like