mfontanini / libtins

High-level, multiplatform C++ network packet sniffing and crafting library.
http://libtins.github.io/
BSD 2-Clause "Simplified" License
1.91k stars 379 forks source link

Installed package not relocatable #101

Open zmb3 opened 9 years ago

zmb3 commented 9 years ago

The installed package for libtins is not relocatable (it contains a bunch of absolute paths valid only on the machine in which is was built).

There are several sub-issues here:

  1. CONFIGURE_PACKAGE_CONFIG_FILE() should be used instead of CONFIGURE_FILE() (see https://github.com/mfontanini/libtins/pull/100)
  2. The libtinsTargets-xxx.cmake file(s) that get generated contain hard coded absolute paths to
    dependencies like libpcap.
  3. The libtins.pc pkg-config file contains absolute paths on the build machine instead of paths relative to the install prefix.

I'm working on a PR for 1 (not quite there yet). This will remove hard coded paths from libtinsConfig.cmake.

For 2, I believe libtins needs to IMPORT pcap instead of doing target_link_libraries. See http://www.cmake.org/cmake/help/v3.2/manual/cmake-packages.7.html#creating-packages.

Note that it is not advisable to populate any properties which may contain paths, such as INTERFACE_INCLUDE_DIRECTORIES and INTERFACE_LINK_LIBRARIES, with paths relevant to dependencies. That would hard-code into installed packages the include directory or library paths for dependencies as found on the machine the package was made on.

I can't quite figure out how to fix this. I believe instead of target_link_libraries(tgt PCAP) there should be a find_dependency(PCAP) in libtinsConfig.cmake.

I think 3 should be resolved with the same type of solution as 1.

mfontanini commented 9 years ago

I've never used the package file generated by CMake so I never came across this issues. But I guess it makes sense not to use hardcoded paths. If you find a way around that, I'll appreciate it :D.

BTW: I think you probably saw it, but it seems like travis.ci build for OSX failed when using CONFIGURE_PACKAGE_CONFIG_FILE on the PR you created yesterday.

zmb3 commented 9 years ago

Yes, I have a few fixes to make to the PR. I'm not sure exactly how to fix the hardcoded paths in the targets file. Was hoping you knew more CMake than I do :)

mfontanini commented 9 years ago

Oh no, I just know enough CMake to be able to do some simple stuff.