<br><br><div class="gmail_quote">On Fri, Sep 17, 2010 at 7:43 AM, Brad King <span dir="ltr"><<a href="mailto:brad.king@kitware.com">brad.king@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On 09/17/2010 07:19 AM, Pere Mato Vila wrote:<br>
> I am using the nice feature of exporting targets from one CMake<br>
> project to another. This works really nicely since it avoids<br>
> explicitly linking my executables and shared libraries with the<br>
> dependent libraries of the imported library target. The problem<br>
> is that imported library is linked with its full installation<br>
> path using the value of property IMPORTED_LOCATION, which is<br>
> generated when installing the exports. This implies that I<br>
> cannot relocate the installation of the project that is<br>
> exporting the targets. Is there a way to tell CMake to use only<br>
> the library name for the imported library targets?<br>
><br>
> In other words and with a little example<br>
><br>
> add_library(bar SHARED IMPORTED)<br>
> set_property(TARGET bar APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG)<br>
> set_target_properties( bar PROPERTIES<br>
> IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG "A;B;C"<br>
> IMPORTED_LOCATION_NOCONFIG "/tmp/absolute/path/to/libbar.so"<br>
<br>
</div>The export() command produces target import properties with full path<br>
because it is meant for exporting from a build tree. The install(EXPORT)<br>
command is meant for install trees, and it does support relocation. It<br>
sets the properties based on a path relative to the export file:<br>
<br>
install(TARGETS mylib DESTINATION lib EXPORT mytargets)<br>
install(EXPORT mytargets DESTINATION lib/myproj)<br>
<br>
The "lib/myproj/mytargets-<config>.cmake" that gets installed does this:<br>
<br>
# Compute the installation prefix relative to this file.<br>
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)<br>
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)<br>
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)<br>
...<br>
SET_TARGET_PROPERTIES(mylib PROPERTIES<br>
...<br>
IMPORTED_LOCATION_NOCONFIG "${_IMPORT_PREFIX}/lib/libmylib.a"<br>
)<br>
<br>
The whole install tree can be relocated to a new prefix and will still work.<br>
<font color="#888888"><br>
-Brad</font><br></blockquote></div><br>Yes, however, transitive link dependencies are stored/set in the installed targets file with full paths to the location on the original build machine. If I install the export target for a static libfoo, which links to /home/rpavlik/libbar.a, the targets file includes that full path. I'm not sure what the "right" solution is - in my case, I was bundling all the dependencies so it would have been reasonable OK to just link to the name of the library. However, I can envision possibly wanting to run a find_package script in there, etc.<br>
<br>Ryan<br clear="all"><br>-- <br>Ryan Pavlik<br>HCI Graduate Student<br>Virtual Reality Applications Center<br>Iowa State University<br><br><a href="mailto:rpavlik@iastate.edu">rpavlik@iastate.edu</a><br><a href="http://academic.cleardefinition.com">http://academic.cleardefinition.com</a><br>
Internal VRAC/HCI Site: <a href="http://tinyurl.com/rpavlik">http://tinyurl.com/rpavlik</a><br>