Re: Can I use a *Targets-someName.cmake file to get access to _IMPORT_PREFIX ?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Re: Can I use a *Targets-someName.cmake file to get access to _IMPORT_PREFIX ?

Daniel Oertwig

 - For a project thing I get thingTargets.cmake when I install EXPORT it
 - thingTargets.cmake sets _IMPORT_PREFIX
 - thingTargets.cmake loads files thingTargets-*.cmake

Can I create and install thingTargets-someName.cmake which uses _IMPORT_PREFIX to "hook" into above mechanism? Or is this likely to break / change in the future?

Longer version:

I really like that you can use the exported targets of cmake even when still in a staging directory and not installed. Example:

# in thing project
mkdir thing-build; cd thing-build
# creates /path/to/staging/lib/cmake/thing/lib{Config,Targets}.cmake and friends
make install DESTDIR=/path/to/staging

# in user project
mkdir user-build
cmake .. -Dthing_DIR=/path/to/staging/lib/cmake/thing
make # correctly uses libraries and headers from /path/to/staging/

Looking at /path/to/staging/lib/cmake/thing/libTargets.cmake I can see that it calculates an _IMPORT_PREFIX variable (in this case to /path/to/staging/ while not yet installed). Also it loads files named libTargets-*.cmake (of which there's only one for me, namely libTargets-noconfig.cmake).

Can I install a file libTargets-someName.cmake? In this file I'd have access to the _IMPORT_PREFIX variable to e.g. set paths:

  -T ${_IMPORT_PREFIX}/share/link.ld)

Larger example at



Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: