<div dir="ltr">BUILD_INTERFACE explicitly means that only consumers inside the same buildsystem should use these libraries. To specify the libraries that should be used when linking to an installed version of a library you need to use INSTALL_INTERFACE.<div><br></div><div>The reason for BUILD and INSTALL interface is to make sure you can build relocatable libraries and not embed absolute paths into a libraries specification. </div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, May 16, 2018 at 7:03 AM <<a href="mailto:rozelak@volny.cz">rozelak@volny.cz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hallo,<br>
I have created a simple project simulating the issue. <br>
<br>
There is 'run.sh' script which first builds an executable using 'add_subdirectory()' CMake command. It works without issues, as expected (the libraries required by Module1 and Module2 are passed to the Module4 builder).<br>
Then, it first builds a STATIC library (defined by Module3) which is then used by Module4. This fails, since I do not know how to export a list of libraries required by Module1 and Module2.<br>
<br>
Could someone, please, look at the project (which is really simple) and give me a hint how Module3 should export (when install iss called) a CMake script, which would containt the libraries to link with?<br>
<br>
Thank you very much.<br>
Best regards,<br>
<br>
Dan<br>
<br>
<br>
______________________________________________________________<br>
> Od: <<a href="mailto:rozelak@volny.cz" target="_blank">rozelak@volny.cz</a>><br>
> Komu: <<a href="mailto:cmake@cmake.org" target="_blank">cmake@cmake.org</a>><br>
> Datum: 04.05.2018 13:25<br>
> Předmět: Install libraries defined in INTERFACE targets<br>
><br>
<br>
Hello,<br>
I build a project which consists of several "modules" with various mutual dependencies. Each module defines its OBJECT target as:<br>
<br>
<br>
# Module 1:<br>
add_library(Module1 OBJECT ....)<br>
target_include_directories(Module1 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})<br>
<br>
add_library(Module1_LIBRARIES INTERFACE)<br>
target_link_libraries(Module1_LIBRARIES INTERFACE $<BUILD_INTERFACE:....>)<br>
<br>
<br>
# Module 2:<br>
add_library(Module2 OBJECT ....)<br>
target_include_directories(Module2 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)<br>
<br>
add_library(Module2_LIBRARIES INTERFACE)<br>
target_link_libraries(Module2_LIBRARIES INTERFACE $<BUILD_INTERFACE:....> $<BUILD_INTERFACE:Module1_LIBRARIES>)<br>
<br>
add_library(Module2_INCLUDES INTERFACE)<br>
target_include_directories(Module2_INCLUDES INTERFACE $<TARGET_PROPERTY:Module2,INCLUDE_DIRECTORIES>)<br>
target_sources(Module2_INCLUDES INTERFACE ....)<br>
<br>
add_library(Module_CONFFILE INTERFACE)<br>
target_sources(Module2_CONFFILE INTERFACE Module.config)<br>
<br>
<br>
And when building a final product (or one of the final products), I use the individual targets:<br>
<br>
add_library(Product1 STATIC $<TARGET_OBJECTS:Module1> $<TARGET_OBJECTS:Module2> ...)<br>
target_link_libraries(Product1 LINK_INTERFACE_LIBRARIES $<BUILD_INTERFACE:Module1_LIBRARIES> $<BUILD_INTERFACE:Module2_LIBRARIES> ...)<br>
<br>
<br>
<br>
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<br>
<br>
install(TARGETS Product1 DESTINATION "./" EXPORT "libProduct1")<br>
install(FILES $<TARGET_PROPERTY:Module2_CONFFILE,INTERFACE_SOURCES> DESTINATION "./config")<br>
install(FILES $<TARGET_PROPERTY:Module2_INCLUDES,INTERFACE_SOURCES> DESTINATION "./include")<br>
<br>
<br>
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).<br>
<br>
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:<br>
<br>
install(EXPORT "llibProduct1" DESTINATION "." EXPORT_LINK_INTERFACE_LIBRARIES)<br>
<br>
<br>
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?<br>
<br>
<br>
Thank you very much,<br>
Dan<br>
<br>
P.S. I use CMake 3.6.2.<br>
-- <br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div>