3

Hello developper friends, I'm using CMake for a while now, but I could't figure how to install a target :

  • that is part of an export set
  • that link privately against interface library

The export set is created with the command

install(EXPORT MyExportSet DESTINATION MyExportDir
        NAMESPACE Project FILE ProjectTargets.cmake)

the link to the interface library is done like this

target_link_libraries(exportedTarget
    PRIVATE interfaceTargetLibrary
)

and finally i'm exporting the target like this :

install(TARGETS exportedTarget EXPORT MyExportSet
      ARCHIVE DESTINATION lib/static
      LIBRARY DESTINATION lib
      RUNTIME DESTINATION bin
      INCLUDES DESTINATION include
)

This look rights to me, and following the logic of the PRIVATE flag uppon linking, I shouldn't have to export the target interfaceTargetLibrary

But CMake throw me an error (This one)

CMake Error: install(EXPORT "ProjectTargets" ...) includes target"exportedTargets" which requires target "interfaceTargetLibrary" that is not in the export set.

So here my question, is that a bug ? or something I didn't understand ? And obviously did you achieve to make it work on way or another.

I'm using CMake version 3.7.

EDIT : Finded out, if someone interested. It's because, the library that is linked privately wont be packaged in the one I export. So, the comsummer of the library will need, to link against interfaceTargetLibary
too and so I need to export it as well.

Noki
  • 383
  • 1
  • 9

1 Answers1

0

Since it's linked privately, you can use the following trick: CMake won't try to install an IMPORTED library.

Also see "What is an INTERFACE IMPORTED library in CMake and what are its uses?".

I tried to find official documentation on this behaviour but I could not. I did find a related discussion ticket on kitware's repo though.

starball
  • 20,030
  • 7
  • 43
  • 238