MantisBT - CMake
View Issue Details
0015101CMakeCMakepublic2014-08-22 08:292015-03-02 08:57
Björn Piltz 
 
normalminoralways
closedfixed 
Apple MacOS X10.4.10
CMake 3.0.1 
CMake 3.1CMake 3.1 
0015101: Imported libraries go out of scope after call to target_link_libraries().
I have a project where module lib - a library - depends on Qt, so it calls find_package(Qt5 ...) and target_link_libraries(lib Qt5::Core). Later I call target_link_libraries(app lib).
The cmake configure step runs through without problems, but the generate step halts with the message:

    Target "app" links to target "Qt5::Core" but the target was not found.
    Perhaps a find_package() call is missing for an IMPORTED target, or an
    ALIAS target is missing?

According to the documentation the target Qt5::Core is out of scope for 'app' since app is not in a subdirectory of the directory where add_library(... IMPORTED) was made, but I would argue that this is a bug since the target was in scope when the call add_library(lib Qt5::Core) was made.

This issue is not specific to Qt and I'm aware that it could be fixed on their side by calling add_library(... IMPORTED GLOBAL). I'm hoping it could be fixed on the cmake side, though.
git clone https://github.com/bjornpiltz/cmake_bug.git [^] cmake_bug
mkdir work
cd work
cmake -DCMAKE_PREFIX_PATH=<Qt5>/lib/cmake/ ../cmake_bug/
This issue is platform independent.
No tags attached.
Issue History
2014-08-22 08:29Björn PiltzNew Issue
2014-08-22 08:47Brad KingNote Added: 0036661
2014-08-22 08:50Brad KingNote Added: 0036662
2014-08-22 10:45Brad KingTarget Version => CMake 3.1
2014-09-02 11:07Brad KingStatusnew => resolved
2014-09-02 11:07Brad KingResolutionopen => fixed
2014-09-02 11:07Brad KingFixed in Version => CMake 3.1
2015-03-02 08:57Robert MaynardNote Added: 0038111
2015-03-02 08:57Robert MaynardStatusresolved => closed

Notes
(0036661)
Brad King   
2014-08-22 08:47   
Historically the dependency lookups were supposed to occur in the scope of the target making the direct reference, not the final target getting the dependency transitively. This may have been broken during the usage requirements implementation. Since 3.0 I've refactored some of that implementation and fixed at least one case involving this kind of lookup. Please try a nightly binary:

 http://www.cmake.org/files/dev/?C=M;O=D [^]

or build from our Git 'master' branch.
(0036662)
Brad King   
2014-08-22 08:50   
Re 0015101:0036661: Local testing of the 'master' branch as of commit 16afccac confirms that the example you provided is fixed.
(0038111)
Robert Maynard   
2015-03-02 08:57   
Closing resolved issues that have not been updated in more than 4 months.