CMake: installing headers and preserving the directory structure

CMake doesn’t provide a dedicated way to install header files (except for mac). What I wanted to do was to install all headers of my project using the same directory structure as in the source tree. This isn’t as easy as it sounds. Assume you have a list of header files: SET(HS folder/test.h folder/other/test2.h) A simple call to INSTALL doesn’t preserve the folder structure: INSTALL(FILES ${HS} DESTINATION include) This results in all files being directly under $prefix/include. ...

May 31, 2010 · updated April 30, 2021 · 1 min