# Install "contaminated" headers directory

**URL:** <https://discourse.cmake.org/t/install-contaminated-headers-directory/7083>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [December 16, 2022, 9:58am UTC](https://discourse.cmake.org/t/install-contaminated-headers-directory/7083 "2022-12-16T09:58:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruilvo](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ruilvo/32/1342_2.png) [@ruilvo](https://discourse.cmake.org/u/ruilvo)\
**Post date:** [December 16, 2022, 9:58am UTC](https://discourse.cmake.org/t/install-contaminated-headers-directory/7083/1 "2022-12-16T09:58:02Z")

</div>

Hello there,

So here’s the deal. I’m managing this C(++ eventually)+CMake project.  
This is the repo:

> **[GitHub - AetherRadio/X6100Control: A base control library and RPC server for...](https://github.com/AetherRadio/X6100Control)**
>
> A base control library and RPC server for the X6100. - GitHub - AetherRadio/X6100Control: A base control library and RPC server for the X6100.

Problem is that the installation results in the following tree (here shown via `cpack` for simplicity):

```nohighlight
lk@lk-vm:~/Development/AetherRadio/X6100Control_build/Debug/AetherX6100Control-0.1-Linux$ tree
.
├── include
│ └── aether_radio
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── CMakeLists.txt
│ └── x6100_control
│ ├── api.h
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── CMakeLists.txt
│ ├── control.h
│ ├── flow.h
│ └── gpio.h
└── lib
    ├── libaether_x6100_control.so -> libaether_x6100_control.so.0
    ├── libaether_x6100_control.so.0 -> libaether_x6100_control.so.0.1
    └── libaether_x6100_control.so.0.1

6 directories, 11 files

```

See all the `CMakeLists.txt` and `cmake_install.cmake` files, plus the `CMakeFiles` directories?  
How can I remove them from the installed directories? Or rather, exclude them from being installed.  
Preferably, without having to list the header files multiple times…

Any ideas?

Thanks.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [December 16, 2022, 1:47pm UTC](https://discourse.cmake.org/t/install-contaminated-headers-directory/7083/2 "2022-12-16T13:47:39Z")

</div>

> [@ruilvo](#):
>
> Preferably, without having to list the header files multiple times…

You can put the header files into a variable and use it for the source list and the `install(FILES)` call. Or, if you’re using CMake 3.23+, you can put the headers into a `FILE_SET` and install the `FILE_SET` directly.

> [@ruilvo](#):
>
> Or rather, exclude them from being installed.

You can pass `EXCLUDE` arguments to `install(FILES)`, but the set of files differs from generator to generator. I would encourage factoring out the list of headers in one of the ways described above.

---

<div class="post-metadata">

**Author:** ![ruilvo](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ruilvo/32/1342_2.png) [@ruilvo](https://discourse.cmake.org/u/ruilvo)\
**Post date:** [December 16, 2022, 2:11pm UTC](https://discourse.cmake.org/t/install-contaminated-headers-directory/7083/3 "2022-12-16T14:11:55Z")

</div>

Thank you for the answer.

I’ve been experimenting with the `FILE_SETS` feature.

But I have a question. I like having source filed being added on `CMakeLists.txt` files next to them.  
So, I did this:

> <https://github.com/AetherRadio/X6100Control/blob/feature-cmake-filesets/x6100_control/include/aether_radio/x6100_control/CMakeLists.txt>

And installed simply like this:

> <https://github.com/AetherRadio/X6100Control/blob/feature-cmake-filesets/x6100_control/cmake/install.cmake>

As I was already expecting, this results in the following tree:

```nohighlight
├── include
│ ├── control.h
│ ├── flow.h
│ └── gpio.h
└── lib
    ├── libaether_x6100_control.so -> libaether_x6100_control.so.0
    ├── libaether_x6100_control.so.0 -> libaether_x6100_control.so.0.1
    └── libaether_x6100_control.so.0.1

2 directories, 6 files

```

Which misses the sub-directories of the previous tree.

I understand I could add a `BASE_DIRS` agument, but then I’d have to specify `FILES` relative to that `BASE_DIRS`, right? Again re-writing stuff…

---

<div class="post-metadata">

**Author:** ![ruilvo](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ruilvo/32/1342_2.png) [@ruilvo](https://discourse.cmake.org/u/ruilvo)\
**Post date:** [December 16, 2022, 2:25pm UTC](https://discourse.cmake.org/t/install-contaminated-headers-directory/7083/4 "2022-12-16T14:25:32Z")

</div>

Well, I managed to find out you can do it, as this commit will reveal:

> <https://github.com/AetherRadio/X6100Control/commit/cc93a4bc8387cda1c7458980f91d2831ce4f7cbb>

---

<div class="post-metadata">

**Author:** ![ruilvo](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ruilvo/32/1342_2.png) [@ruilvo](https://discourse.cmake.org/u/ruilvo)\
**Post date:** [December 16, 2022, 2:32pm UTC](https://discourse.cmake.org/t/install-contaminated-headers-directory/7083/5 "2022-12-16T14:32:14Z")

</div>

And managed to do the same for the `api.h` file 🙂

> <https://github.com/AetherRadio/X6100Control/commit/58900ce5616be7e5844743d5d806d1f3e8616c2a>
