Install libraries defined in INTERFACE targets

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Install libraries defined in INTERFACE targets

I build a project which consists of several "modules" with various mutual dependencies. Each module defines its OBJECT target as:
    # Module 1:
    add_library(Module1 OBJECT ....)
    target_include_directories(Module1 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
    add_library(Module1_LIBRARIES INTERFACE)
    target_link_libraries(Module1_LIBRARIES INTERFACE $<BUILD_INTERFACE:....>)
    # Module 2:
    add_library(Module2 OBJECT ....)
    target_include_directories(Module2 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
    add_library(Module2_LIBRARIES INTERFACE)
    target_link_libraries(Module2_LIBRARIES INTERFACE $<BUILD_INTERFACE:....> $<BUILD_INTERFACE:Module1_LIBRARIES>)
    add_library(Module2_INCLUDES  INTERFACE)
    target_include_directories(Module2_INCLUDES  INTERFACE $<TARGET_PROPERTY:Module2,INCLUDE_DIRECTORIES>)
    target_sources(Module2_INCLUDES  INTERFACE ....)
    add_library(Module_CONFFILE  INTERFACE)
    target_sources(Module2_CONFFILE  INTERFACE Module.config)
And when building a final product (or one of the final products), I use the individual targets:
    add_library(Product1 STATIC $<TARGET_OBJECTS:Module1> $<TARGET_OBJECTS:Module2> ...)
It works perfectly, the library is built using all the sources. Even when defining INSTALL, all the properties of the targets (include files, config files, etc.) can be accessed and are installed correctly
    install(TARGETS Product1  DESTINATION "./" EXPORT "libProduct1")
The problem starts when I want to export a CMake file listing all the libraries which were defined by the individual modules (and are accessed by $<BUILD_INTERFACE:Module2_LIBRARIES>) since they know what they need (how they were configured).
When building a static library (which is shown here), I need to export a list of additional libraries necessary to link the Product1 correctly. But using $<BUILD_INTERFACE:Module[]_LIBRARIES> in the INSTALL() command does not work, neither works something like:
So the question is: how to export the libraries defined by the individual modules to an CMake file which would be installed together with the Product1 library and header files?
Thank you very much,
P.S. I use CMake 3.6.2.

Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: