# How to Install shared library from add\_subdirectory, but not header includes?

**URL:** <https://discourse.cmake.org/t/how-to-install-shared-library-from-add-subdirectory-but-not-header-includes/4919>\
**Category:** Code\
**Created:** [January 27, 2022, 5:26pm UTC](https://discourse.cmake.org/t/how-to-install-shared-library-from-add-subdirectory-but-not-header-includes/4919 "2022-01-27T17:26:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thehans](https://discourse.cmake.org/user_avatar/discourse.cmake.org/thehans/32/2134_2.png) [@thehans](https://discourse.cmake.org/u/thehans)\
**Post date:** [January 27, 2022, 5:26pm UTC](https://discourse.cmake.org/t/how-to-install-shared-library-from-add-subdirectory-but-not-header-includes/4919/1 "2022-01-27T17:26:40Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)\
**Post date:** [January 27, 2022, 5:43pm UTC](https://discourse.cmake.org/t/how-to-install-shared-library-from-add-subdirectory-but-not-header-includes/4919/2 "2022-01-27T17:43:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![thehans](https://discourse.cmake.org/user_avatar/discourse.cmake.org/thehans/32/2134_2.png) [@thehans](https://discourse.cmake.org/u/thehans)\
**Post date:** [January 27, 2022, 5:47pm UTC](https://discourse.cmake.org/t/how-to-install-shared-library-from-add-subdirectory-but-not-header-includes/4919/3 "2022-01-27T17:47:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)\
**Post date:** [January 27, 2022, 5:59pm UTC](https://discourse.cmake.org/t/how-to-install-shared-library-from-add-subdirectory-but-not-header-includes/4919/4 "2022-01-27T17:59:43Z")

</div>

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

```auto
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.
