Hallo Robert,
thank you for your answer.
 
While I generally understand your explanation, I do not know exactly what to 
do. I have tried to add
 
   target_link_libraries(Module2_LIBRARIES INTERFACE $<INSTALL_INTERFACE:...>)
 
into Modules 1 and 2 together with 
 
   install(EXPORT ...
 
in Module 3, but still there is no definition of the required libraries in the 
CMake file(s) generated (by the EXPORT).
 
Could you give me few more additional hints, please?
 
Thank you very much,
Dan
 


______________________________________________________________
Od: Robert Maynard <robert.mayn...@kitware.com>
Komu: roze...@volny.cz
Datum: 17.05.2018 00:12
Předmět: Re: [CMake] Install libraries defined in INTERFACE targets

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.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. 
On Wed, May 16, 2018 at 7:03 AM <roze...@volny.cz <roze...@volny.cz>> 
wrote:Hallo,
I have created a simple project simulating the issue. 
 
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).
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.
 
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?
 
Thank you very much.
Best regards,
 
Dan
 
 
______________________________________________________________
> Od: <roze...@volny.cz <roze...@volny.cz>>
> Komu: <cmake@cmake.org <cmake@cmake.org>>
> Datum: 04.05.2018 13:25
> Předmět: Install libraries defined in INTERFACE targets
>

 Hello,
 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> ...)
     target_link_libraries(Product1 LINK_INTERFACE_LIBRARIES 
$<BUILD_INTERFACE:Module1_LIBRARIES> $<BUILD_INTERFACE:Module2_LIBRARIES> ...)
  
  
  
 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")
     install(FILES $<TARGET_PROPERTY:Module2_CONFFILE,INTERFACE_SOURCES>          
DESTINATION "./config")
     install(FILES $<TARGET_PROPERTY:Module2_INCLUDES,INTERFACE_SOURCES>          
DESTINATION "./include")
  
     
 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:
  
     install(EXPORT "llibProduct1" DESTINATION "." 
EXPORT_LINK_INTERFACE_LIBRARIES)
  
  
 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,
 Dan
  
 P.S. I use CMake 3.6.2.
--

Powered by www.kitware.com <http://www.kitware.com>

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ <http://www.cmake.org/Wiki/CMake_FAQ>

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

CMake Support: http://cmake.org/cmake/help/support.html 
<http://cmake.org/cmake/help/support.html>
CMake Consulting: http://cmake.org/cmake/help/consulting.html 
<http://cmake.org/cmake/help/consulting.html>
CMake Training Courses: http://cmake.org/cmake/help/training.html 
<http://cmake.org/cmake/help/training.html>

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html 
<http://www.kitware.com/opensource/opensource.html>

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake 
<https://cmake.org/mailman/listinfo/cmake>
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

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

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to