Install "contaminated" headers directory

Hello there,

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

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

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.

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.

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.

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:

And installed simply like this:

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

├── 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…

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

And managed to do the same for the api.h file :slight_smile: