How to Install shared library from add_subdirectory, but not header includes?

I have an application which depends on a library, which uses add_subdirectory() to include in our CMakeLists. This subdirectory is 3rd party code, and placed there as a git submodule, so I can’t easily modify CMakeLists.txt of the library itself, only the top level.

I am attempting to fix up cmake install settings for the application, and get CPack to work with it. The problem I have is that the installing the library (DLL files) also installs “includes”/header files which I don’t want to package with my application.

Is there any way to selectively choose what gets installed, from outside the library subdirectory?
Or failing that, can I specify some post-install, pre-packaging command through cmake to delete the unwanted includes?

What I tend to do in such situations is to use component install in my project and install just the binary I’m interested in as a part of my own component. Works like a charm.

I don’t understand how that would work. Could you give a small example? The library itself does not specify components by the way.

It’s quite simple. For example (simplified):

set(CPACK_GENERATOR "ZIP")
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_ALL "my_component;my_dependencies")

add_subdirectory(some_3rd_party_library)
install(TARGET some_3rd_party_library_target_name COMPONENT my_dependencies)

add_executable(my_exe main.c)
target_link_libraries(my_exe PRIVATE some_3rd_party_library_target_name)
install(TARGET my_exe COMPONENT my_component)

include(CPack)

There may be typos as I did it from the top of my head but hopefully you should get the general idea.