Search code examples
cmakecpack

SET(CPACK_COMPONENTS_ALL ...) with ExternalProject Installing Additional Components


I use the ExtrenalProject cmake module to add 3rd party or internal dependencies to my build. I then use the CPack module with components to install only components from the current code base in the following manner.

set(CPACK_COMPONENTS_ALL
  common-lib
  common-include
  common-depends
)

An example of one of these components declared in CMake is:

install(TARGETS common
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib
  COMPONENT common-lib
)

However, other projects added using add_subdirectory such as google test or other internal libraries also declare install targets. When I run

make package

and then list the contents of the .deb or .tar generated, I see the contents of other components not set in the CPACK_COMPONENTS_ALL variable.

What is the proper way to get CMake and CPack to only install the components requested?


Solution

  • You can just add the argument EXCLUDE_FROM_ALL to the end of the add_subdirectory() call. This will essentially disable all of the include() calls made in the added subdirectories.