# CMake FILE\_SET for HEADER when using DESTINATION

**URL:** https://discourse.cmake.org/t/cmake-file-set-for-header-when-using-destination/5692
**Category:** Code
**Tags:** os:linux
**Created:** [May 19, 2022, 4:04am UTC](https://discourse.cmake.org/t/cmake-file-set-for-header-when-using-destination/5692 "2022-05-19T04:04:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![RFRIEDM-Trimble](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rfriedm-trimble/32/2428_2.png) [@RFRIEDM-Trimble](https://discourse.cmake.org/u/RFRIEDM-Trimble)
#### Post date: [May 19, 2022, 4:04am UTC](https://discourse.cmake.org/t/cmake-file-set-for-header-when-using-destination/5692/1 "2022-05-19T04:04:24Z")

</div>

Hello,

I’m trying to migrate a multi-target library from CMake3.14 to CMake v3.23.1 to take advantage of the new FILE\_SET feature. I’ve purchased a copy of the 14th edition of Professional CMake and followed along the new updates for file sets. This will replace my use of installing the entire include directory and using file matching, making it so I can build and install header files for each target respectively rather than all headers.

Directory structure:

> include  
> ----myProj  
> --------a.hpp  
> --------b.hpp  
> src  
> ----a.cpp  
> ----b.cpp

I have cmakelists in each of the folders, with targets A and B. Some parts removed for brevity.

**include/myProj/CMakeLists.txt**

> target\_sources(A  
> PUBLIC FILE\_SET HEADERS  
> FILES  
> a.hpp  
> )  
> target\_sources(B  
> PUBLIC FILE\_SET HEADERS  
> FILES  
> b.hpp  
> )

**CMakeLists.txt**

> add\_library(A)  
> add\_library(B)  
> …  
> add\_subdirectory(include/myProj)  
> include(GNUInstallDirs)  
> install(TARGETS A B  
> EXPORT ${PROJECT\_NAME}-export  
> DESTINATION ${CMAKE\_INSTALL\_LIBDIR}  
> FILE\_SET HEADERS  
> )

When installing the build directory, I expect the headers to be in install/include/a.hpp, however I see install/lib/a.hpp instead (The install prefix is “install”)

> cmake --install build --prefix install

As per the book, “Since no DESTINATION was specified after FILE\_SET, the default destination provided by CMAKE\_INSTALL\_INCLUDEDIR for HEADERS file sets will be used.”, which is said to be include, not lib.

I also tried supplying the INCLUDES DESTINATION X/Y/Z which has zero effect on the output structure. It seems that by supplying the generic DESTINATION keyword, that overrides the headers.

Am I missing something?

---

<div class="post-metadata">

### Author: ![RFRIEDM-Trimble](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rfriedm-trimble/32/2428_2.png) [@RFRIEDM-Trimble](https://discourse.cmake.org/u/RFRIEDM-Trimble)
#### Post date: [May 19, 2022, 5:39am UTC](https://discourse.cmake.org/t/cmake-file-set-for-header-when-using-destination/5692/2 "2022-05-19T05:39:46Z")

</div>

After reading additional documentation, and realizing that the DESTINATION keyword above was applying in ways I had not considered, here is the corrected install command. The below command is a combination of the examples for install in CMake documentation as well as the example in Professional CMake.

> install(TARGETS A B  
> EXPORT ${PROJECT\_NAME}-export  
> FILE\_SET HEADERS  
> DESTINATION ${CMAKE\_INSTALL\_INCLUDEDIR}/${PROJECT\_NAME}  
> INCLUDES DESTINATION ${CMAKE\_INSTALL\_INCLUDEDIR}  
> )

The only thing left is changing it so if I only build “A”, that it will install “A”, and not fail that B is not built.
