[CMake] Install header directory hierarchy

Daniel Pfeifer daniel at pfeifer-mail.de
Fri Oct 15 07:00:48 EDT 2010


Hi,

This question has been asked quite a few times, but never satisfactorily
answerded before: How do I install a bunch of headers preserving
directory structure? The following snippet

> set(HEADERS header1.h dir/header2.h)
> install(FILES ${HEADERS} DESTINATION include)

puts both files inside the same directory. The structure is not
preserved. The following workaround does the trick:

> foreach(HEADER HEADERS)
>   string(REGEX MATCH "(.*)[/\\]" DIR ${HEADER})
>   install(FILES ${HEADER} DESTINATION include/${DIR})
> endforeach(HEADER HEADERS)

However, I consider this as a workaround, not as a solution!

It gets more complicated as soon as I want to build frameworks on mac,

> set_target_properties(my_lib PROPERTIES PUBLIC_HEADER ${HEADERS})

again puts both files inside the same directory, ignoring structure.
Here the workaround is even less a solution, if this is really the only
way: <http://www.cmake.org/pipermail/cmake/2008-June/022378.html>

Hasn't this been considered before? The public wiki shows two use cases
of cmake frameworks, but neither of them puts headers into a directory
hierarchy. <http://www.cmake.org/Wiki/CMake:MacOSX_Frameworks>

cheers, Daniel




More information about the CMake mailing list