<br><br><div class="gmail_quote">On Fri, Sep 17, 2010 at 7:43 AM, Brad King <span dir="ltr">&lt;<a href="mailto:brad.king@kitware.com">brad.king@kitware.com</a>&gt;</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>
&gt; I am using the nice feature of exporting targets from one CMake<br>
&gt; project to another. This works really nicely since it avoids<br>
&gt; explicitly linking my executables and shared libraries with the<br>
&gt; dependent libraries of the imported library target. The problem<br>
&gt; is that imported library is linked with its full installation<br>
&gt; path using the value of property IMPORTED_LOCATION, which is<br>
&gt; generated when installing the exports. This implies that I<br>
&gt; cannot relocate the installation of the project that is<br>
&gt; exporting the targets. Is there a way to tell CMake to use only<br>
&gt; the library name for the imported library targets?<br>
&gt;<br>
&gt;   In other words and with a little example<br>
&gt;<br>
&gt; add_library(bar SHARED IMPORTED)<br>
&gt; set_property(TARGET bar APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG)<br>
&gt; set_target_properties( bar PROPERTIES<br>
&gt;   IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG &quot;A;B;C&quot;<br>
&gt;   IMPORTED_LOCATION_NOCONFIG &quot;/tmp/absolute/path/to/libbar.so&quot;<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 &quot;lib/myproj/mytargets-&lt;config&gt;.cmake&quot; that gets installed does this:<br>
<br>
# Compute the installation prefix relative to this file.<br>
GET_FILENAME_COMPONENT(_IMPORT_PREFIX &quot;${CMAKE_CURRENT_LIST_FILE}&quot; PATH)<br>
GET_FILENAME_COMPONENT(_IMPORT_PREFIX &quot;${_IMPORT_PREFIX}&quot; PATH)<br>
GET_FILENAME_COMPONENT(_IMPORT_PREFIX &quot;${_IMPORT_PREFIX}&quot; PATH)<br>
...<br>
SET_TARGET_PROPERTIES(mylib PROPERTIES<br>
  ...<br>
  IMPORTED_LOCATION_NOCONFIG &quot;${_IMPORT_PREFIX}/lib/libmylib.a&quot;<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&#39;m not sure what the &quot;right&quot; 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>