View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0008843CMakeCMakepublic2009-04-06 07:372009-04-06 11:14
ReporterTobias Rudolph 
Assigned ToBrad King 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product VersionCMake-2-6 
Target VersionFixed in Version 
Summary0008843: Imported targets that are linked transitively to parent projects are not resolved correctly
DescriptionI am trying to build a project containing several subprojects that are included via add_subdirectory. Now, here is an example demonstrating the problem:

The test project contains the following CMakeLists.txt:
----
project( CMakeTest )
cmake_minimum_required( VERSION 2.6 )

add_subdirectory( foo )
include_directories( foo )

add_executable( TestApp main.cpp )
target_link_libraries( TestApp foo )
----

The CMakeLists.txt of the subdirectory libFoo:
----
add_library( ImportedTarget SHARED IMPORTED )
set_target_properties( ImportedTarget PROPERTIES IMPORTED_LOCATION "/opt/local/lib/libz.dylib" )

add_library( foo SHARED foo.cpp )
target_link_libraries( foo ImportedTarget )
----

According to the documentation, the imported target ("ImportedTarget") is only known within "foo" and its subdirectories. So, when I try to link 'TestApp', it fails because the linker is looking for 'ImportedTarget' rather than '/opt/local/lib/libz.dylib' due to transitive linking (I suspect).

Additional Informationexample attached
TagsNo tags attached.
Attached Filesgz file icon CMake_transitive_linking.tar.gz [^] (634 bytes) 2009-04-06 07:37

 Relationships

  Notes
(0015920)
Alexandre Feblot (reporter)
2009-04-06 10:10

I second that. Why would imported target not behave as any other target regarding scopes? They should be global too.
(0015925)
Brad King (manager)
2009-04-06 10:22

Imported targets cannot be globally unique. Multiple subdirectories may do find_package(foo) and each import their own 'foo' with different options. Imported targets need to be scoped like variables and the link_directories command.

The reporter's analysis is correct. The proper fix is to make the transitive dependency analysis look in the right place for the imported target.
(0015930)
Brad King (manager)
2009-04-06 11:12

I've committed a fix and a test.

BUG: Lookup transitive link deps in depender scope
/cvsroot/CMake/CMake/Source/cmComputeLinkDepends.cxx,v <-- Source/cmComputeLinkDepends.cxx
new revision: 1.30; previous revision: 1.29
/cvsroot/CMake/CMake/Source/cmComputeLinkDepends.h,v <-- Source/cmComputeLinkDepends.h
new revision: 1.16; previous revision: 1.15

ENH: Test transitive link to subdir-imported lib
/cvsroot/CMake/CMake/Tests/ExportImport/Import/A/CMakeLists.txt,v <-- Tests/ExportImport/Import/A/CMakeLists.txt
initial revision: 1.1
/cvsroot/CMake/CMake/Tests/ExportImport/Import/A/imp_lib1.c,v <-- Tests/ExportImport/Import/A/imp_lib1.c
initial revision: 1.1
/cvsroot/CMake/CMake/Tests/ExportImport/Import/A/imp_mod1.c,v <-- Tests/ExportImport/Import/A/imp_mod1.c
initial revision: 1.1
/cvsroot/CMake/CMake/Tests/ExportImport/Import/A/imp_testExe1.c,v <-- Tests/ExportImport/Import/A/imp_testExe1.c
initial revision: 1.1
/cvsroot/CMake/CMake/Tests/ExportImport/Import/CMakeLists.txt,v <-- Tests/ExportImport/Import/CMakeLists.txt
new revision: 1.7; previous revision: 1.6
/cvsroot/CMake/CMake/Tests/ExportImport/Import/imp_mod1.c,v <-- Tests/ExportImport/Import/imp_mod1.c
new revision: delete; previous revision: 1.2
/cvsroot/CMake/CMake/Tests/ExportImport/Import/imp_testExe1.c,v <-- Tests/ExportImport/Import/imp_testExe1.c
new revision: delete; previous revision: 1.4
/cvsroot/CMake/CMake/Tests/ExportImport/Import/imp_testTransExe1.c,v <-- Tests/ExportImport/Import/imp_testTransExe1.c
initial revision: 1.1
(0015931)
Brad King (manager)
2009-04-06 11:14

Transitive link dependencies are now looked up in the scope of their immediate depender.

I've scheduled this for inclusion in 2.6.4.

 Issue History
Date Modified Username Field Change
2009-04-06 07:37 Tobias Rudolph New Issue
2009-04-06 07:37 Tobias Rudolph File Added: CMake_transitive_linking.tar.gz
2009-04-06 10:06 Bill Hoffman Status new => assigned
2009-04-06 10:06 Bill Hoffman Assigned To => Brad King
2009-04-06 10:10 Alexandre Feblot Note Added: 0015920
2009-04-06 10:22 Brad King Note Added: 0015925
2009-04-06 11:12 Brad King Note Added: 0015930
2009-04-06 11:14 Brad King Note Added: 0015931
2009-04-06 11:14 Brad King Status assigned => closed
2009-04-06 11:14 Brad King Resolution open => fixed


Copyright © 2000 - 2018 MantisBT Team