From: Michael Altizer (mialtize) Date: Tue, 16 May 2017 18:05:41 +0000 (-0400) Subject: Merge pull request #894 in SNORT/snort3 from poc_work to master X-Git-Tag: 3.0.0-239~81 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7a4fdd2d3b5b0bf98a1efdb1f45d538dfbc53511;p=thirdparty%2Fsnort3.git Merge pull request #894 in SNORT/snort3 from poc_work to master Squashed commit of the following: commit 8fc6c009d224fbbc9aef5528b181bd193bcc7772 Author: Michael Altizer Date: Mon May 8 16:35:02 2017 -0400 tools: Clean up per-target includes and libraries commit 8054717b7735294bc685210548b4779f38ee4547 Author: Michael Altizer Date: Mon May 8 16:34:18 2017 -0400 cmake: Fix erroneous space when checking for netdb.h commit dcf1750fd041b0a0b16dc7f62b6497fcffa3c8d3 Author: Michael Altizer Date: Mon May 8 16:33:21 2017 -0400 cmake: Check if libsfbpf is needed to link against libpcap Some implementations of libpcap have a dependency on libsfbpf and CMake has issues resolving library dependencies; help it along. --- diff --git a/cmake/FindPCAP.cmake b/cmake/FindPCAP.cmake index 86faccfce..da64c5603 100644 --- a/cmake/FindPCAP.cmake +++ b/cmake/FindPCAP.cmake @@ -54,16 +54,38 @@ check_c_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO) set(CMAKE_REQUIRED_LIBRARIES) -# check if linking against libpcap also needs to link against a thread library +# check if linking against libpcap also needs to link against a thread and/or SFBPF library if (NOT PCAP_LINKS_SOLO) find_package(Threads) if (THREADS_FOUND) set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) - check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS) + check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS_ONLY) + if (PCAP_NEEDS_THREADS_ONLY) + set(PCAP_EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT}) + endif () set(CMAKE_REQUIRED_LIBRARIES) endif () - if (THREADS_FOUND AND PCAP_NEEDS_THREADS) - set(_tmp ${PCAP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) + + find_package(SFBPF) + if (NOT PCAP_NEEDS_THREADS AND SFBPF_FOUND) + set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES} ${SFBPF_LIBRARIES}) + check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_SFBPF_ONLY) + if (PCAP_NEEDS_SFBPF_ONLY) + set(PCAP_EXTRA_LIBS ${SFBPF_LIBRARIES}) + endif () + set(CMAKE_REQUIRED_LIBRARIES) + endif () + + if (NOT (PCAP_NEEDS_THREADS_ONLY OR PCAP_NEEDS_SFBPF_ONLY) AND THREADS_FOUND AND SFBPF_FOUND) + set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES} ${SFBPF_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) + check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_SFBPF_AND_THREADS) + if (PCAP_NEEDS_SFBPF_AND_THREADS) + set(PCAP_EXTRA_LIBS ${SFBPF_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) + endif () + endif () + + if (PCAP_EXTRA_LIBS) + set(_tmp ${PCAP_LIBRARIES} ${PCAP_EXTRA_LIBS}) list(REMOVE_DUPLICATES _tmp) set(PCAP_LIBRARIES ${_tmp} CACHE STRING "Libraries needed to link against libpcap" FORCE) diff --git a/cmake/sanity_checks.cmake b/cmake/sanity_checks.cmake index b0567d1fb..ea93ce6ac 100644 --- a/cmake/sanity_checks.cmake +++ b/cmake/sanity_checks.cmake @@ -22,7 +22,7 @@ check_include_file_cxx("inttypes.h" HAVE_INTTYPES_H) check_include_file_cxx("libintl.h" HAVE_LIBINTL_H) check_include_file_cxx("limits.h" HAVE_LIMITS_H) check_include_file_cxx("malloc.h" HAVE_MALLOC_H) -check_include_file_cxx("netdb.h " HAVE_NETDB_H) +check_include_file_cxx("netdb.h" HAVE_NETDB_H) check_include_file_cxx("netinet/in.h" HAVE_NETINET_IN_H) check_include_file_cxx("stddef.h" HAVE_STDDEF_H) check_include_file_cxx("stdint.h" HAVE_STDINT_H) diff --git a/tools/flatbuffers/CMakeLists.txt b/tools/flatbuffers/CMakeLists.txt index e006e0fe5..6bfaa6678 100644 --- a/tools/flatbuffers/CMakeLists.txt +++ b/tools/flatbuffers/CMakeLists.txt @@ -1,11 +1,15 @@ if ( FLATBUFFERS_FOUND ) - include_directories(${PROJECT_SOURCE_DIR}/src ${FLATBUFFERS_INCLUDE_DIR}) - add_executable( fbstreamer fbstreamer.cc ) - target_link_libraries( fbstreamer ${FLATBUFFERS_LIBRARIES} ) + target_include_directories( fbstreamer + PRIVATE + ${FLATBUFFERS_INCLUDE_DIR} + ) + target_link_libraries( fbstreamer + ${FLATBUFFERS_LIBRARIES} + ) install (TARGETS fbstreamer RUNTIME DESTINATION bin diff --git a/tools/u2boat/CMakeLists.txt b/tools/u2boat/CMakeLists.txt index 5a23d19d2..206097e8c 100644 --- a/tools/u2boat/CMakeLists.txt +++ b/tools/u2boat/CMakeLists.txt @@ -1,15 +1,17 @@ -include_directories(${PROJECT_SOURCE_DIR}/src) - add_executable( u2boat u2boat.cc ) +target_include_directories( u2boat + PRIVATE + ${PROJECT_SOURCE_DIR}/src + ${PCAP_INCLUDE_DIR} +) target_link_libraries( u2boat ${PCAP_LIBRARIES} ) - install (TARGETS u2boat RUNTIME DESTINATION bin ) diff --git a/tools/u2spewfoo/CMakeLists.txt b/tools/u2spewfoo/CMakeLists.txt index 9e0d79371..2d47900d4 100644 --- a/tools/u2spewfoo/CMakeLists.txt +++ b/tools/u2spewfoo/CMakeLists.txt @@ -1,11 +1,14 @@ -include_directories(${PROJECT_SOURCE_DIR}/src) - add_executable( u2spewfoo u2spewfoo.cc u2_common.h ) +target_include_directories( u2spewfoo + PRIVATE + ${PROJECT_SOURCE_DIR}/src +) + install (TARGETS u2spewfoo RUNTIME DESTINATION bin )