[CMake] using `install()` with EXPORT and COMPONENT

Stefan Seefeld stefan at seefeld.name
Sun Sep 29 14:09:20 EDT 2019


Hi Craig,

thanks for the detailed explanation !

On 2019-09-29 5:13 a.m., Craig Scott wrote:
>
> If all of your headers should be installed to a single directory, then 
> you can list the headers in the target's PUBLIC_HEADER or 
> PRIVATE_HEADER target property, then make sure you add those 
> destinations in the install(TARGETS ...) command. For example:
>
> include(GNUInstallDirs)
> install(TARGETS myLib
>     EXPORT SomeProj_Targets
>     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
>             COMPONENT SomeProj_Runtime
>     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
>             COMPONENT          SomeProj_Runtime
> NAMELINK_COMPONENT SomeProj_Development   # Requires CMake 3.12
>     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
>             COMPONENT SomeProj_Development
>     PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
>             COMPONENT SomeProj_Development
>     INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
> )

I hadn't noticed one can have multiple 'COMPONENT' sections in a single 
`install` call. The CMake documentation could be a bit more clear about 
that.

>
> If you need to install headers into more than one directory (i.e. your 
> headers have some sort of directory hierarchy), then the above doesn't 
> work because it flattens all of the headers into a single location. 
> Instead, you have to use install(FILES ...) to install the headers 
> directly for such cases. Also, the 
> target_include_directories() command has nothing to do with what 
> header files get installed. Rather, it only controls the header search 
> paths attached to a target.

Right, true.

> FYI, part of my CppCon talk "Deep CMake For Library Authors" from a 
> couple of weeks ago has a fair amount of overlap with this topic 
> (specifically install components and destinations). I'm waiting for 
> the YouTube clip to be made available and then I'll be posting a blog 
> article on my website with links and the slides. When it goes up, 
> you'll be able to find it at https://crascit.com (hopefully sometime 
> this week, but depends how quickly the production people get the video 
> done).

Great, looking forward to reading the slides.

Many thanks !

Stefan
-- 

       ...ich hab' noch einen Koffer in Berlin...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190929/299b9bb8/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .signature.png
Type: image/png
Size: 2754 bytes
Desc: not available
URL: <https://cmake.org/pipermail/cmake/attachments/20190929/299b9bb8/attachment.png>


More information about the CMake mailing list