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

Rolf Eike Beer eike at sf-mail.de
Thu Mar 31 09:14:10 EDT 2011


Michael Hertling wrote:
> On 03/30/2011 03:14 PM, Rolf Eike Beer wrote:

>> [...] Only adding
>>
>> INSTALL(TARGETS privstatic EXPORT myexport DESTINATION trash)
>>
>> made CMake complete successfully, resulting in the static stuff showing
>> up
>> in the export, too.
>
> Could you provide a minimal but complete example with that issue?

See below. Looks like the only way to prevent this is to set
LINK_INTERFACE_LIBRARIES to empty for every lib that uses the static lib.
Which may be a good idea anyway as that transitive linking is harmful.

Eike


PROJECT(cmexport C CXX)

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/stlib.c "#include \"stlib.h\"

int stlib_func(void)
{
	return 42;
}
")
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/stlib.h "#pragma once

extern int stlib_func(void);
")
ADD_LIBRARY(stlib STATIC
		${CMAKE_CURRENT_BINARY_DIR}/stlib.c
		${CMAKE_CURRENT_BINARY_DIR}/stlib.h
)

FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/privlib.c "#include \"privlib.h\"
#include \"stlib.h\"

int privlib_func(void)
{
	return stlib_func();
}
")
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/privlib.h "#pragma once

#ifdef __cplusplus
extern \"C\" {
#endif

extern int privlib_func();

#ifdef __cplusplus
}
#endif
")
ADD_LIBRARY(privlib SHARED
		${CMAKE_CURRENT_BINARY_DIR}/privlib.c
		${CMAKE_CURRENT_BINARY_DIR}/privlib.h
)
TARGET_LINK_LIBRARIES(privlib stlib)

# comment out the next line to get the error
# SET_TARGET_PROPERTIES(privlib PROPERTIES LINK_INTERFACE_LIBRARIES "")

FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/publib.cpp "#include \"privlib.h\"

int pubfunc(void)
{
	return privlib_func();
}
")

ADD_LIBRARY(publib SHARED ${CMAKE_CURRENT_BINARY_DIR}/publib.cpp)
TARGET_LINK_LIBRARIES(publib privlib)
SET_TARGET_PROPERTIES(publib PROPERTIES LINK_INTERFACE_LIBRARIES "")

INSTALL(TARGETS publib privlib
	EXPORT cmexp
	DESTINATION lib)

INSTALL(EXPORT cmexp DESTINATION share)



More information about the CMake mailing list