TL;DR:

 - 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
cmake .. -DCMAKE_INSTALL_PREFIX=""
make
# 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:

target_link_options(thing::lib
  INTERFACE
  -T ${_IMPORT_PREFIX}/share/link.ld)

Larger example at
https://github.com/musteresel/cmake-multiple-example-research

Best,
Daniel
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

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

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to