[CMake] IMPORTED_LINK_DEPENDENT_LIBRARIES not working anymore?

James Bigler jamesbigler at gmail.com
Thu Mar 14 00:43:06 EDT 2013


I made a reproducer and discovered a couple of interesting things.  If the
dependent library is static then IMPORATED_LINK_DEPENDENT_LIBRARIES doesn't
work for 2.8.4+.  If I instead change it to
IMPORTED_LINK_INTERFACE_LIBRARIES then it works correctly regardless of if
the dependent library is static or shared and works for 2.8.4+.

I'm not sure what the expected behavior is supposed to be, but I attached
my simple reproducer.




On Wed, Mar 13, 2013 at 5:08 PM, James Bigler <jamesbigler at gmail.com> wrote:

> I determined that this failed starting in 2.8.7 (2.8.6 has the cudart
> library on the link line, and 2.8.7 didn't).  I didn't see anything
> particular about changes to the IMPORT libraries to suggest why this might
> have happened.  I'll try and rig up a reproducer.
>
> I did notice that there wasn't a test for IMPORTED_LINK_DEPENDENT_
> LIBRARIES aside from trying to create a circular dependency between a
> single library.
>
>
> On Wed, Mar 13, 2013 at 4:35 PM, James Bigler <jamesbigler at gmail.com>wrote:
>
>> I used the following code in 2.8.4, but in 2.8.9 and 2.8.10 it doesn't
>> add the CUDA_CUDART_LIBRARY library to the eventual link line.  I see my
>> target linking against the parallelprim library but not the cudart library.
>>  Did something change in the interface between 2.8.4 and now?
>>
>> I'll continue to try and narrow down the version of CMake where this
>> stopped working.
>>
>>     # Create an imported static target
>>     add_library(parallelprim STATIC IMPORTED)
>>     # This library pertains to all configurations
>>     set_property(TARGET parallelprim APPEND PROPERTY
>> IMPORTED_CONFIGURATIONS NOCONFIG)
>>     # Set the location
>>     set_target_properties(parallelprim PROPERTIES
>>       IMPORTED_LOCATION_NOCONFIG "${PARALLELPRIM_LIBRARY}")
>>     # Set list of dependent libraries (parallelprim needs cudart)
>>     set_target_properties(parallelprim PROPERTIES
>>       IMPORTED_LINK_DEPENDENT_LIBRARIES ${CUDA_CUDART_LIBRARY})
>>
>> I also tried this and it didn't work:
>>
>>     # Create an imported static target
>>     add_library(parallelprim STATIC IMPORTED)
>>     # Set the location
>>     set_target_properties(parallelprim PROPERTIES
>>       IMPORTED_LOCATION "${PARALLELPRIM_LIBRARY}")
>>     # Set list of dependent libraries (parallelprim needs cudart)
>>     set_target_properties(parallelprim PROPERTIES
>>       IMPORTED_LINK_DEPENDENT_LIBRARIES ${CUDA_CUDART_LIBRARY})
>>
>> Thanks,
>> James
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130313/b83b6f3f/attachment-0001.htm>
-------------- next part --------------
cmake_minimum_required(VERSION 2.8)

# Create a library with a symbol lib2 uses.
add_library(lib1 SHARED lib1.cpp)
get_target_property(lib1_path lib1 LOCATION)
message("lib1_path    = ${lib1_path}")

# Create a library with a symbol main uses.
add_library(lib2 STATIC lib2.cpp)

# Create a custom command to copy lib2 to another file
get_target_property(lib2_path lib2 LOCATION)
message("lib2_path    = ${lib2_path}")

set(lib2gen_path "${CMAKE_CURRENT_BINARY_DIR}/lib2gen.a")
message("lib2gen_path = ${lib2gen_path}")

add_custom_command(
  OUTPUT ${lib2gen_path}
  COMMAND ${CMAKE_COMMAND} -E copy "${lib2_path}" "${lib2gen_path}"
  DEPENDS lib2
  WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  COMMENT "Copying ${lib2_path} to ${lib2gen_path}"
  )
add_custom_target(build_lib2gen
  DEPENDS "${lib2gen_path}"
  )

# Create an imported static target
add_library(lib2gen STATIC IMPORTED)

# If you use IMPORTED_LINK_DEPENDENT_LIBRARIES then this works in 2.8.6, but not in
# 2.8.7+.  If lib1 is STATIC then IMPORTED_LINK_DEPENDENT_LIBRARIES doesn't work ever.  If
# you use IMPORTED_LINK_INTERFACE_LIBRARIES, then this works for 2.8.6 and 2.8.7+, and
# when lib1 is STATIC or SHARED.
set_target_properties(lib2gen PROPERTIES
  IMPORTED_LOCATION
  "${lib2gen_path}"
  IMPORTED_LINK_DEPENDENT_LIBRARIES "${lib1_path}"
#  IMPORTED_LINK_INTERFACE_LIBRARIES "${lib1_path}"
  )

# Make parallelprim target dependent on it being built.
add_dependencies(lib2gen build_lib2gen)

add_executable(main main.cpp)
target_link_libraries(main lib2gen)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: lib1.cpp
Type: text/x-c++src
Size: 31 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130313/b83b6f3f/attachment-0003.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lib2.cpp
Type: text/x-c++src
Size: 70 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130313/b83b6f3f/attachment-0004.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 116 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130313/b83b6f3f/attachment-0005.cpp>


More information about the CMake mailing list