[CMake] Dependency paths in CMake package config files

Alexander Lamaison awl03 at doc.ic.ac.uk
Thu Oct 2 12:56:12 EDT 2014


How do you manage the paths to the libraries that your static library
package depends on in the XXXConfig.cmake that gets installed with
package XXX?

I'm exporting my static library package from both the build tree and
from the installation location like

  add_library(foo STATIC ...)
  target_link_libraries(foo PRIVATE ...)
  install(TARGETS foo EXPORT FooConfig ...)

  ## During package installation, install FooConfig.cmake
  install(EXPORT FooConfig NAMESPACE Foo:: DESTINATION lib)

  ## During build, register directly from build tree
  export(TARGETS foo NAMESPACE Foo:: FILE FooConfig.cmake)
  export(PACKAGE Foo)

This does a great job of generating a FooConfig.cmake that can be used
by other projects on the local machine.  But target foo is linked with
other dependencies, for example, OpenSSH so the installed config file
includes the following:

  set_property(TARGET Foo::foo APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
  set_target_properties(Foo::foo PROPERTIES
    IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
    IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG "C:/OpenSSL-Win64/lib/VC/ssleay32MDd.lib;C:/OpenSSL-Win64/lib/VC/libeay32MDd.lib;ws2_32"
    IMPORTED_LOCATION_DEBUG "${_IMPORT_PREFIX}/lib/libfoo.lib")

So my question is, in general, how can I make installabled static
libraries with a package config file?  Or is the trying to redistribute
static libraries a bad idea in the first place?

Thanks,

Alex

--
Swish - Easy SFTP for Windows Explorer (http://www.swish-sftp.org)



More information about the CMake mailing list