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 <[email protected]> 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 <[email protected]>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
>>
>
>
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)
int lib1_call()
{
return 4;
}
extern int lib1_call();
int lib2_call()
{
return 3 * lib1_call();
}
#include <stdio.h>
extern int lib2_call();
int main()
{
printf("lib2_call() = %d\n", lib2_call());
return 0;
}
--
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake