[CMake] INSTALL(EXPORT) does not honor LINK_INTERFACE_LIBRARIES?

Michael Hertling mhertling at online.de
Tue Mar 29 03:08:50 EDT 2011


On 03/28/2011 02:51 PM, Rolf Eike Beer wrote:
> I try to do an INSTALL(EXPORT) to allow others to link against one of my
> libraries. That libraries is linked against some other internal libraries
> the target's don't need to link to as everything in them is purely
> internal.
> 
> I tried something like that:
> 
> ADD_LIBRARY(publiclib SHARED 	${publiclib_SOURCES})
> 
> TARGET_LINK_LIBRARIES(publiclib privatelib)
> 
> SET_TARGET_PROPERTIES(publiclib PROPERTIES LINK_INTERFACE_LIBRARIES "")
> 
> INSTALL(TARGETS publiclib
> 			EXPORT publiclib_export
> 			RUNTIME DESTINATION bin
> 			LIBRARY DESTINATION lib
> 			ARCHIVE DESTINATION lib)
> 
> INSTALL(EXPORT publiclib_export DESTINATION cmake/modules)
> 
> This results in:
> 
> Make Error: INSTALL(EXPORT "publiclib_export" ...) includes target
> "publiclib" which requires target "privatelib" that is not in the export
> set.
> 
> Ehm, no, it doesn't? Is this intentional (why?), is there a workaround or
> should I file a bug report?
> 
> Eike

That's got nothing to do with the LINK_INTERFACE_LIBRARIES property.
Your publiclib target is linked against the privatelib one, so you
can't place the former in an export set without the latter, and this
is what CMake tells you, cf. [1]. Remove the SET_TARGET_PROPERTIES()
command and you'll probably see that the error message persists, i.e.
LINK_INTERFACE_LIBRARIES can not be used to break any dependencies
established by TARGET_LINK_LIBRARIES(); it has other purposes [2].

Besides, INSTALL(EXPORT) *does* honor LINK_INTERFACE_LIBRARIES:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(LIL C)
SET(CMAKE_VERBOSE_MAKEFILE ON)
FILE(WRITE ${CMAKE_BINARY_DIR}/f0.c "void f0(void){}\n")
ADD_LIBRARY(f0 SHARED f0.c)
FILE(WRITE ${CMAKE_BINARY_DIR}/f.c "void f(void){}\n")
ADD_LIBRARY(f1 SHARED f.c)
TARGET_LINK_LIBRARIES(f1 f0)
ADD_LIBRARY(f2 SHARED f.c)
TARGET_LINK_LIBRARIES(f2 f0)
SET_TARGET_PROPERTIES(f2 PROPERTIES LINK_INTERFACE_LIBRARIES "")
INSTALL(TARGETS f2 f1 f0 EXPORT lil
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib)
INSTALL(EXPORT lil DESTINATION share)

Inspect the ${CMAKE_INSTALL_PREFIX}/share/lil-noconfig.cmake file after
the installation; you will see that the f1 shared library target has an
IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG property of "f0" whereas the
f2 target has the IMPORTED_LINK_DEPENDENT_LIBRARIES_NOCONFIG property.
                                ^^^^^^^^^
Regards,

Michael

[1] http://www.cmake.org/pipermail/cmake/2011-February/042851.html
[2] http://www.cmake.org/pipermail/cmake/2011-March/043560.html


More information about the CMake mailing list