<div dir="ltr">Yes, that was exactly what I needed.<div><br></div><div>Now my installed targets file has IMPORTED_LINK_INTERFACE_LIBRARIES "PCAP" instead of an absolute path, and the FindPCAP.cmake module kicks in and does what I would expect.</div><div><br></div><div>Thanks again for your time - much appreciated.</div><div><br></div><div>Zac</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 20, 2015 at 9:25 AM, Guillaume Dumont <span dir="ltr"><<a href="mailto:dumont.guillaume@gmail.com" target="_blank">dumont.guillaume@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div><div><div><div>Hi Zac,<br><br></div>target_link_libraries will work with either full library paths or target names including imported targets. <br><br></div>You need to use target_link_libraries in your CMakeLists.txt and find_dependency in your PackageConfig.cmake. Like so:<br><br></div>in CMakeLists.txt:<br><br></div>target_link_libraries(mylib ${PCAP_LIBRARIES})<br><br></div>in PackageConfig.cmake<br><br></div>include(CMakeFindDependencyMacro)<br></div>find_depdency(PCAP)<br><br></div>this way your exported targets will carry a link dependency to an imported target called PCAP and your PackageConfig.cmake will resolve that dependency for consuming projects. (Provided you install your FindPCAP.cmake and add the path to this file to CMAKE_MODULE_PATH)<br><br></div>Clearer now?<br><br></div><div><div><div><div><div><div><div><div><div><br><br></div></div></div></div></div></div></div></div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 20, 2015 at 8:24 AM, Zac Bergquist <span dir="ltr"><<a href="mailto:zbergquist99@gmail.com" target="_blank">zbergquist99@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I think I'm on the right track now.  I was definitely missing the add_library(PCAP IMPORTED) section.<div><br></div><div>Could you elaborate on the last part?  I thought target_link_libraries() is the reason I'm getting absolute paths.  Should I be using the FindDependency macro instead of target_link_libraries()?<div><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 19, 2015 at 9:54 PM, Guillaume Dumont <span dir="ltr"><<a href="mailto:dumont.guillaume@gmail.com" target="_blank">dumont.guillaume@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Zac,<div><br></div><div>Sorry I read your post very quickly the first time... If your library uses its own FindPCAP.cmake then you can define an imported target for the PCAP libraries like so:</div><div><br></div><div># FindPCAP.cmake</div><div><br></div><div>find_path(PCAP_INCLUDE_DIR pcap.h ... )<br></div><div>find_library(PCAP_LIBRARY pcap ... )</div><div><br></div><div>include(FindPackageHandleStandardArgs)</div><div>find_package_handle_standard_args(<span style="color:rgb(51,51,51);line-height:15.6px;background-color:rgb(238,255,204)">PCAP  DEFAULT_MSG </span>PCAP_LIBRARY PCAP_INCLUDE_DIR)</div><div><br></div><div>if(PCAP_FOUND AND NOT TARGET PCAP)</div><div>  add_library(PCAP IMPORTED) # you can(or should) also specify if it's a shared or static library</div><div>  set_target_properties(PCAP PROPERTIES IMPORTED_LOCATION ${PCAP_LIBRARY})</div><div>  # also add the interface include directories here via set_target_properties</div><div>  set(PCAP_LIBRARIES PCAP)</div><div>endif()</div><div><br></div><div>then in your CMakeLists.txt:</div><div><br></div><div>find_package(PCAP)</div><div><br></div><div>target_link_libraries(mylib ${PCAP_LIBRARIES})</div><div><br></div><div>Install your FindPCAP.cmake with your exported targets so that you can use the FindDependencyMacro to resolve the dependency when a consuming project finds your  library.</div><div><br></div><div>Would that work for you?</div><div><br></div><div>HTH</div><span><font color="#888888"><div><br></div><div>Guillaume</div><div><br></div><div><br></div></font></span></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 19, 2015 at 7:06 PM, Pau Garcia i Quiles <span dir="ltr"><<a href="mailto:pgquiles@elpauer.org" target="_blank">pgquiles@elpauer.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>In your case, what you need to do is to modify the config file generation in the library (i. e. you will need to patch the third-party library) so that the generated config file is relative.</div><div><br></div><div>As an alternative, if you do not want to patch the third-party library, try modifying the generated config file by replacing absolute prefixes with a variable (to the cross-compilation sysroot) or relative paths.</div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 20, 2015 at 1:02 AM, Zac Bergquist <span dir="ltr"><<a href="mailto:zbergquist99@gmail.com" target="_blank">zbergquist99@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Yes, Pau, this is exactly my problem. Or more specifically, as the author of a library that uses CMake and depends on libpcap, how can I best structure and distribute the library to make it easy to use (and cross compile)?  I would say using the system libpcap is strongly preferred over distributing a copy of it.</p>
<p dir="ltr">That tutorial is very interesting.  I'll have to take a closer look at it because the solution isn't jumping out at me.  The tutorial shows a project that contains both a library and a program that links to that library in the same list file.  In my case that would not be possible.  Also, the library in the example has no dependencies so it wouldn't suffer from the absolute path issue I'm encountering.</p><div><div>
<div class="gmail_quote">On Oct 19, 2015 5:36 PM, "Pau Garcia i Quiles" <<a href="mailto:pgquiles@elpauer.org" target="_blank">pgquiles@elpauer.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Dan,<div><br></div><div>On a second read, it seems Zac's problem was actually finding the dependency (libpcap) of a dependency. Or rather, making if findable, because the second depenency contains an absolute path which is broken due to cross-compilation.</div><div><br></div><div>I have never used it but this page contains information on how to fix the paths in the config file to be relative instead of absolute. That should fix the problem:</div><div><br></div><div><a href="https://cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file" target="_blank">https://cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file</a><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 19, 2015 at 11:15 PM, Dan Kegel <span dir="ltr"><<a href="mailto:dank@kegel.com" target="_blank">dank@kegel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Well, that's one answer.  But if you want to use system libpcap, it's not a very satisfying one.<div><br></div><div>It's odd that pcap doesn't ship with a .pc file.   </div><div>I guess the pcap folks are hostile to pkgconfig because it's LGPL; see</div><div><a href="https://github.com/the-tcpdump-group/libpcap/issues/374" target="_blank">https://github.com/the-tcpdump-group/libpcap/issues/374</a><span><font color="#888888"><br></font></span></div><span><font color="#888888"><div>- Dan<br></div><div><br></div><div><br></div></font></span></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 19, 2015 at 2:04 PM, Pau Garcia i Quiles <span dir="ltr"><<a href="mailto:pgquiles@elpauer.org" target="_blank">pgquiles@elpauer.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>Use ExternalProject to build libpcap as part of your project. Make sure you use $ORIGIN in rpath everywhere. Install your application (and your bundled libpcap) to /opt to avoid polluting the system.</div></div><div class="gmail_extra"><div><div><br><div class="gmail_quote">On Mon, Oct 19, 2015 at 10:37 PM, Zac Bergquist <span dir="ltr"><<a href="mailto:zbergquist99@gmail.com" target="_blank">zbergquist99@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thank you for your reply, Guillaume.<div><br></div><div>I understand that this is the expected behavior.  I even linked to the documentation that says this is the expected behavior.  What I don't understand is how to resolve it.  Are you saying it is not possible to create a relocatable package unless all dependencies are also using CMake?  That doesn't seem right.</div><div><br></div><div>Should I be trying to write a package config file for libpcap, or is there a better way to approach this?</div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Oct 17, 2015 at 8:19 AM, Guillaume Dumont <span dir="ltr"><<a href="mailto:dumont.guillaume@gmail.com" target="_blank">dumont.guillaume@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">What you are seeing is the expected behavior. You can get a relocatable package if all your dependencies (in your case libcap) have themselves relocatable package config files with exported targets. Then you package should make use of find_dependency macro.</div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Fri, Oct 16, 2015 at 4:56 PM, Zac Bergquist <span dir="ltr"><<a href="mailto:zbergquist99@gmail.com" target="_blank">zbergquist99@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">I've created a sample project to replicate my issue in hopes that it would make it easier to troubleshoot.<div><br></div><div>Thanks for any help,</div><div>Zac<br><div><br></div><div><a href="https://github.com/zmb3/cmaketest" target="_blank">https://github.com/zmb3/cmaketest</a><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 12, 2015 at 8:53 AM, Zac Bergquist <span dir="ltr"><<a href="mailto:zbergquist99@gmail.com" target="_blank">zbergquist99@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>I'm trying to fix a project so that its output is relocatable.  The project is a library that itself depends on libpcap.  My goal is to be able to import the library into my CMake application and have CMake automatically link libpcap with it.</div><div><br></div><div>I'm using a toolchain file that invokes an ARM cross compiler, sets CMAKE_INSTALL_PREFIX and appends it to CMAKE_FIND_ROOT_PATH.  This all seems to work well.</div><div><br></div><div>What I'm seeing is that the exported files that get installed to CMAKE_INSTALL_PREFIX contain absolute paths to libpcap on my machine, which make them useless to other team members.</div><div><br></div><div>The first thing I changed was to use CONFIGURE_PACKAGE_CONFIG_FILE instead of CONFIGURE_FILE.  This got rid of absolute paths in the generated CMake config file.</div><div><div><br></div><div>However, I still have absolute paths in the CMake target import file that gets generated.  The IMPORTED_LINK_INTERFACE_LIBRARIES target property has an absolute path instead of one relative to CMAKE_INSTALL_PREFIX.</div><div><br></div><div>I've read the "Creating Relocatable Packages" [1] section of the CMake packages documentation. I'm pretty sure this is what I'm running into, but I don't quite understand how to solve it.  The documentation says that I should be using imported targets, but I'm not sure how to do so.  The library is just using its own FindPCAP.cmake file to locate libpcap.</div></div><div><br></div><div>Does anyone know of an example of a CMake package that imports other libraries?  I could also try to create a minimal example project with this setup if it would be helpful.</div><div><br></div><div>Thanks,</div><div>Zac</div><div><br></div><div>[1]: <a href="https://cmake.org/cmake/help/v3.3/manual/cmake-packages.7.html#creating-relocatable-packages" target="_blank">https://cmake.org/cmake/help/v3.3/manual/cmake-packages.7.html#creating-relocatable-packages</a></div><div><br></div></div>
</blockquote></div><br></div>
<br></div></div>--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><span><font color="#888888"><br></font></span></blockquote></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div>Guillaume Dumont<br>=========================<br><a href="mailto:dumont.guillaume@gmail.com" target="_blank">dumont.guillaume@gmail.com</a></div>
</font></span></div>
</blockquote></div><br></div>
</div></div><br>--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br></div></div><span><font color="#888888"><div>Pau Garcia i Quiles<br><a href="http://www.elpauer.org" target="_blank">http://www.elpauer.org</a><br>(Due to my workload, I may need 10 days to answer)</div>
</font></span></div>
<br>--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br></blockquote></div><br></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Pau Garcia i Quiles<br><a href="http://www.elpauer.org" target="_blank">http://www.elpauer.org</a><br>(Due to my workload, I may need 10 days to answer)</div>
</div>
</blockquote></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Pau Garcia i Quiles<br><a href="http://www.elpauer.org" target="_blank">http://www.elpauer.org</a><br>(Due to my workload, I may need 10 days to answer)</div>
</div>
</div></div><br>--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Guillaume Dumont<br>=========================<br><a href="mailto:dumont.guillaume@gmail.com" target="_blank">dumont.guillaume@gmail.com</a></div>
</div>
</div></div></blockquote></div><br></div></div></div></div></div>
</blockquote></div><br><br clear="all"><br>-- <br><div>Guillaume Dumont<br>=========================<br><a href="mailto:dumont.guillaume@gmail.com" target="_blank">dumont.guillaume@gmail.com</a></div>
</div>
</div></div></blockquote></div><br></div>