<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 29, 2019 at 6:38 AM Stefan Seefeld <<a href="mailto:stefan@seefeld.name">stefan@seefeld.name</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
  

    
  
  <div bgcolor="#FFFFFF">
    <p>Hello,</p>
    <p>I'm working on a library project that will be packaged in
      multiple components. A "runtime" component will contain the
      (shared) library, an a "dev" component the associated headers (and
      perhaps other development-only artefacts).</p>
    <p>I have successfully used the `install()` command to install these
      two sets of artefacts, i.e. calling `install(... COMPONENT
      runtime)`, as well as `install(... COMPONENT dev)`.</p>
    <p>However, I'm now looking into calling `install(TARGETS ... EXPORT
      ...)`. The documentation explains how the list of installed
      headerfiles can actually be inferred from the target itself (if
      the target_include_directories have been appropriately set).
      However, I can't call that function more than once on the same
      target, and thus I seem to have no way to split the installation
      into multiple components.</p>
    <p>Does anyone know what I'm missing ? What is the suggested way to
      package a project into the usual "runtime" and "dev" components ?</p></div></blockquote></div><div><br></div><div>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 <font face="monospace">install(TARGETS ...)</font> command. For example:</div><div><br></div><div><font face="monospace">include(GNUInstallDirs)</font></div><div><font face="monospace">install(TARGETS myLib</font></div><div><font face="monospace">    EXPORT SomeProj_Targets</font></div><div><font face="monospace">    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}</font></div><div><font face="monospace">            COMPONENT SomeProj_Runtime</font></div><div><div><font face="monospace">    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}</font></div></div><div><div><font face="monospace">            COMPONENT          SomeProj_Runtime</font></div><div></div><div><font face="monospace">            NAMELINK_COMPONENT SomeProj_Development   # Requires CMake 3.12</font></div><div></div><div><font face="monospace">    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}</font></div></div><div><font face="monospace">            COMPONENT SomeProj_Development</font></div><div></div><div><font face="monospace">    PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}</font></div><div><font face="monospace">            COMPONENT SomeProj_Development</font></div><div></div><div><font face="monospace">    INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}</font></div><div><font face="monospace">)</font></div><div><br></div><div>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 <font face="monospace">install(FILES ...)</font> to install the headers directly for such cases. Also, the <font face="monospace">target_include_directories()</font> command has nothing to do with what header files get installed. Rather, it only controls the header search paths attached to a target.</div><div><br></div><div>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 <a href="https://crascit.com">https://crascit.com</a> (hopefully sometime this week, but depends how quickly the production people get the video done).</div><div><br></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="https://crascit.com" target="_blank">https://crascit.com</a><br></div><div><br></div><div>Get the hand-book for every CMake user: <a href="https://crascit.com/professional-cmake/" target="_blank">Professional CMake: A Practical Guide</a><br></div><div>Consulting services (CMake, C++, build/release processes): <a href="https://crascit.com/services" target="_blank">https://crascit.com/services</a></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>