CPack: Exclude INSTALL commands from subdirectory (googletest directory)

So there is the macro option @Tsyvarev mentioned that was originally suggested here:

# overwrite install() command with a dummy macro that is a nop
macro (install)
endmacro ()

# configure build system for external libraries
add_subdirectory(external)

# replace install macro by one which simply invokes the CMake
install() function with the given arguments
macro (install)
  _install(${ARGV})
endmacro(install)

Note ${ARGV} and ${ARGN} are the same but the docs currently suggest using ${ARGN}. Also the fact that macro-overwriting prepends _ to the original macro name is not documented, but it is still the behaviour. See the code here.

However, I never got the above code to work properly. It does really weird things and often calls install() twice.

An alternative – also undocumented – is to use EXCLUDE_FROM_ALL:

add_subdirectory(external EXCLUDE_FROM_ALL)

According to some comment I found somewhere this disables install() for that subdirectory. I think what it actually does is set EXCLUDE_FROM_ALL by default for all the install() commands which also probably does what you want. I haven’t really tested it, worth a shot though.

Leave a Comment