[cmake-developers] [ANNOUNCE] CMake 3.12.0-rc2 is ready for testing

Patrick Stotko stotko at informatik.uni-bonn.de
Sun Jul 1 10:58:27 EDT 2018


I've reproduced the error. A possible fix would be to extend 
pkg_check_module and pkg_search_module to allow globally imported 
targets, i.e. to add an IMPORTED_GLOBAL_TARGET or GLOBAL keyword (where 
the latter is only usable together with IMPORTED_TARGET) to allow 
similar control as add_library.

Essentially, adding GLOBAL here

https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/FindPkgConfig.cmake#L232

immediately solves the problem, so it's indeed related to target 
visibility. Therefore, I think this is intended behavior and the logic 
for the RHS target is correct.

Maybe we should open an issue and discuss the design of the fix there 
together with Brad King and the others.

Best regards,
Patrick Stotko

On 30.06.2018 23:03, Patrick Stotko wrote:
> It seems that CMake does not find PkgConfig::GooCanvas because it is 
> imported but not globally imported, i.e. it is maybe a visibility problem.
> For reference, the relaxation of this limitation 
> (https://gitlab.kitware.com/cmake/cmake/merge_requests/2040) is 
> covered by this additional check for the LHS target:
>
> https://gitlab.kitware.com/cmake/cmake/blob/c9349cc1b94a08b4f5ed86a397e72ceed50847dd/Source/cmTargetLinkLibrariesCommand.cxx#L383
>
> Maybe a corresponding check for locally imported RHS targets is 
> missing here:
>
> https://gitlab.kitware.com/cmake/cmake/blob/c9349cc1b94a08b4f5ed86a397e72ceed50847dd/Source/cmTargetLinkLibrariesCommand.cxx#L396
>
> Best regards,
> Patrick Stotko
>
>
> Am 30.06.2018 um 21:15 schrieb Rolf Eike Beer:
>>> * The "target_link_libraries()" command may now be called to modify
>>>    targets created outside the current directory.
>> I played a bit around with that as I hope it would simplify some things in
>> OSM2go, but it looks there are still some limitations:
>>
>> in main:
>>
>> add_library(osm2go_lib ...)
>>
>> add_subdirectory(sub)
>>
>> in sub:
>>
>> pkg_search_module(GooCanvas REQUIRED IMPORTED_TARGET goocanvas)
>> target_sources(osm2go_lib PRIVATE
>> 	src/platforms/gtk/canvas_goocanvas.cpp
>> )
>> target_link_libraries(osm2go_lib PRIVATE PkgConfig::GooCanvas)
>>
>> Breaks:
>>
>> CMake Error at CMakeLists.txt:43 (add_library):
>>    Target "osm2go_lib" links to target "PkgConfig::GooCanvas" but the target
>>    was not found.  Perhaps a find_package() call is missing for an IMPORTED
>>    target, or an ALIAS target is missing?
>>
>> Is this intended to work?
>>
>> There is an easy workaround, but it feels nasty:
>>
>> add_library(osm2go_x_lib INTERFACE)
>> target_link_libraries(osm2go_x_lib INTERFACE PkgConfig::GooCanvas)
>> target_link_libraries(osm2go_lib PRIVATE osm2go_x_lib)
>>
>>
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake-developers/attachments/20180701/500814fb/attachment.html>


More information about the cmake-developers mailing list