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

Rolf Eike Beer eike at sf-mail.de
Wed Mar 30 09:14:34 EDT 2011


> On 03/30/2011 02:02 PM, Rolf Eike Beer wrote:
>
>>> However, I still don't understand the relation of that transitive
>>> linking and its avoidance, respectively, to your initial complaint
>>> about CMake's error message due to the missing library in another
>>> library's export set. Unless I'm mistaken, you've a shared library
>>> target "publiclib" which is linked explicitly against another target
>>> "privatelib" via TARGET_LINK_LIBRARIES().
>>
>> Yes.
>>
>>> This means you can't place
>>> publiclib in an export set without privatelib since the former could
>>> not be set up properly w.r.t. its diverse IMPORTED properties if the
>>> latter is not installed, too, i.e. INSTALL(EXPORT) could not generate
>>> a valid export file.
>>
>> Yes, and that's basically the problem I have.
>>
>> Ok, I went and put every thing in the same export set. Which itself is a
>> bit weird as I now have to INSTALL static libraries that were linked by
>> the shared ones only to be able to specify that they are in the export
>> set. And at the end all those libraries of course show up in the export.
>> And I still see IMPORTED_LINK_DEPENDENT_LIBRARIES_DEBUG of the library
>> that this is all about set to it's dependencies.
>
> W.r.t. *static* libraries, that's not necessary: If a shared library is
> linked against a static one and the former prevents transitive linking
> for the latter by setting LINK_INTERRFACE_LIBRARIES appropriately, the
> static library does not need to be put in the shared one's export set:
>
> CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
> PROJECT(PRIVATE C)
> SET(CMAKE_VERBOSE_MAKEFILE ON)
> FILE(WRITE ${CMAKE_BINARY_DIR}/f.c "void f(void){}\n")
> ADD_LIBRARY(f STATIC f.c)
> FILE(WRITE ${CMAKE_BINARY_DIR}/g.c "void g(void){f();}\n")
> ADD_LIBRARY(g SHARED g.c)
> TARGET_LINK_LIBRARIES(g f)
> SET_TARGET_PROPERTIES(g PROPERTIES LINK_INTERFACE_LIBRARIES "")
> INSTALL(TARGETS g EXPORT public LIBRARY DESTINATION lib)
> INSTALL(EXPORT public DESTINATION share)
>
> In the export file, the static f isn't mentioned at all, and that's
> perfect. Without LINK_INTERFACE_LIBRARIES set or with a *shared* f,
> this does not work, of course.

What CMake version are you using? For me CMake is complaining that the
public library depends on some private libraries that are not exported and
they are static. Only adding

INSTALL(TARGETS privstatic EXPORT myexport DESTINATION trash)

made CMake complete successfully, resulting in the static stuff showing up
in the export, too.

Maybe I just write the export file by hand as what's happening here is
just plain wrong IMHO. At least for my case.

Eike


More information about the CMake mailing list