Install without building tests


I would like to achieve the following:

  1. The default target builds all artifacts.
  2. The “install” target only builds the artifacts that it installs.

My use case that I want to improve “install” times by not building tests, which we do not install, while still having the default target build everything, which is what our devs have come to expect. We could change the expectations on the latter, but that would not be my preference.

I have tried two approaches. Both of them are close but none do exactly what I’d like:

  1. Use EXCLUDE_FROM_ALL for all test executables. This prevents install from building the tests, but the default target now doesn’t build tests.
  2. Set CMAKE_SKIP_INSTALL_ALL_DEPENDENCY, and then add a custom “custom-install” target that depends on the installable artifacts, and runs a COMMAND that does ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR}. This keeps the default target building everything, build my install target is now named “custom-install” instead of “install”.

To me, the fundamental issue appears that install depends on targets that are not installed, which seems wrong? If that’s by design, is there another way to achieve what I want?

It’s a long-standing issue that install is not hooked up to what is installed. I have ideas on how it can be fixed based on other in-progress developments, but there’s no roadmap for anything handling this specifically at the moment.