From 691a8974e4da741e95617819f383c0369e91233f Mon Sep 17 00:00:00 2001 From: Ali Abdulkadir Date: Wed, 22 Nov 2017 05:24:22 +0300 Subject: Avoid using the library's full path on the linker command-line (Try to) avoid cmake's sloppy practice of using the library's full path on the linker command-line. "e.g. -lC:\User\projects\WpdPack\Lib\Packet.lib" This line also ends up in pcap-config, giving other build systems/compiler a very hard time. --- cmake/Modules/FindPacket.cmake | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'cmake') diff --git a/cmake/Modules/FindPacket.cmake b/cmake/Modules/FindPacket.cmake index a5968b4a..a84e4cd3 100644 --- a/cmake/Modules/FindPacket.cmake +++ b/cmake/Modules/FindPacket.cmake @@ -49,7 +49,28 @@ # if(NOT PACKET_DLL_DIR) - set(PACKET_DLL_DIR $ENV{PACKET_DLL_DIR}) +# Compile a source file to see if the library and include files are +# already reachable. + include(CheckCSourceCompiles) + include(CMakePushCheckState) + + cmake_push_check_state() + set(CMAKE_REQUIRED_QUIET true) + set(CMAKE_REQUIRED_LIBRARIES packet) + check_c_source_compiles( +"#include + +int main() +{ + return 0; +}" PACKET_SYSTEM_LIBRARY) + cmake_pop_check_state() + + if(PACKET_SYSTEM_LIBRARY) + set(PACKET_LIBRARY packet) + else() + set(PACKET_DLL_DIR $ENV{PACKET_DLL_DIR}) + endif() endif() # The 64-bit Packet.lib is located under /x64 @@ -64,12 +85,14 @@ find_path(PACKET_INCLUDE_DIR Packet32.h PATH_SUFFIXES include Include ) +if(PACKET_SYSTEM_LIBRARY) # Find the library -find_library(PACKET_LIBRARY - NAMES Packet packet - HINTS "${PACKET_DLL_DIR}" - PATH_SUFFIXES Lib${64BIT_SUBDIR} lib${64BIT_SUBDIR} -) + find_library(PACKET_LIBRARY + NAMES Packet packet + HINTS "${PACKET_DLL_DIR}" + PATH_SUFFIXES Lib${64BIT_SUBDIR} lib${64BIT_SUBDIR} + ) +endif() # Set PACKET_FOUND to TRUE if PACKET_INCLUDE_DIR and PACKET_LIBRARY are TRUE. include(FindPackageHandleStandardArgs) -- cgit v1.2.1