[CMake] configuration packages, IMPORTED targets, and global scope

Deniz Bahadir dbahadir at benocs.com
Thu Sep 7 05:02:21 EDT 2017


Am 06.09.2017 um 20:24 schrieb Robert Dailey:
> So it took me a while to figure out why find_package() calls I was
> making (with CONFIG) option were not accessible outside of the
> directory in which it was invoked. I realized that all targets seem to
> be global by default except IMPORTED targets (according to
> add_library() docs). I find this counterintuitive, since I expect
> imported targets to behave the same as normal ones WRT scope.
> 
> Is there a reason that imported targets need to be explicitly made GLOBAL?
> 
> Barring that, I'd like to find some way to make find_package() convert
> those imported targets to global. I don't see a target property I can
> set or a command I can call to make an existing imported target a
> global one. Any thoughts on workarounds? If there are none, are there
> some changes we could make to CMake to support this behavior?

Just a two days ago I created an issue for this: 
https://gitlab.kitware.com/cmake/cmake/issues/17256

It would probably help if you participate in that discussion.

> My use case is that I have a subdirectory I step into, which builds
> various third party libraries and then follows up with a
> find_package() call. I do this in a isolated but central place because
> I have to set up various variables like CMAKE_PREFIX_PATH and many
> others to isolate searches to a controlled location. Beyond this, if a
> target needs one of these third party libs, the expectation is that
> they only have to do target_link_libraries() with the import target
> names to use those libs. However, because they are out of scope, they
> can't use them.
> 

HTH,
Deniz


More information about the CMake mailing list