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

Robert Dailey rcdailey.lists at gmail.com
Wed Sep 6 14:24:18 EDT 2017


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?

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.


More information about the CMake mailing list