Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

FindPCAP.cmake 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # - Try to find libpcap include dirs and libraries
  2. #
  3. # Usage of this module as follows:
  4. #
  5. # find_package(PCAP)
  6. #
  7. # Variables used by this module, they can change the default behaviour and need
  8. # to be set before calling find_package:
  9. #
  10. # PCAP_ROOT_DIR Set this variable to the root installation of
  11. # libpcap if the module has problems finding the
  12. # proper installation path.
  13. #
  14. # Variables defined by this module:
  15. #
  16. # PCAP_FOUND System has libpcap, include and library dirs found
  17. # PCAP_INCLUDE_DIR The libpcap include directories.
  18. # PCAP_LIBRARY The libpcap library (possibly includes a thread
  19. # library e.g. required by pf_ring's libpcap)
  20. # HAVE_PF_RING If a found version of libpcap supports PF_RING
  21. find_path(PCAP_ROOT_DIR
  22. NAMES include/pcap.h
  23. )
  24. find_path(PCAP_INCLUDE_DIR
  25. NAMES pcap.h
  26. HINTS ${PCAP_ROOT_DIR}/include
  27. )
  28. find_library(PCAP_LIBRARY
  29. NAMES pcap
  30. HINTS ${PCAP_ROOT_DIR}/lib
  31. )
  32. include(FindPackageHandleStandardArgs)
  33. find_package_handle_standard_args(PCAP DEFAULT_MSG
  34. PCAP_LIBRARY
  35. PCAP_INCLUDE_DIR
  36. )
  37. include(CheckCSourceCompiles)
  38. set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
  39. check_c_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO)
  40. set(CMAKE_REQUIRED_LIBRARIES)
  41. # check if linking against libpcap also needs to link against a thread library
  42. if (NOT PCAP_LINKS_SOLO)
  43. find_package(Threads)
  44. if (THREADS_FOUND)
  45. set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
  46. check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS)
  47. set(CMAKE_REQUIRED_LIBRARIES)
  48. endif ()
  49. if (THREADS_FOUND AND PCAP_NEEDS_THREADS)
  50. set(_tmp ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
  51. list(REMOVE_DUPLICATES _tmp)
  52. set(PCAP_LIBRARY ${_tmp}
  53. CACHE STRING "Libraries needed to link against libpcap" FORCE)
  54. else ()
  55. message(FATAL_ERROR "Couldn't determine how to link against libpcap")
  56. endif ()
  57. endif ()
  58. include(CheckFunctionExists)
  59. set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
  60. check_function_exists(pcap_get_pfring_id HAVE_PF_RING)
  61. set(CMAKE_REQUIRED_LIBRARIES)
  62. mark_as_advanced(
  63. PCAP_ROOT_DIR
  64. PCAP_INCLUDE_DIR
  65. PCAP_LIBRARY
  66. )