From: Josh Date: Wed, 20 Aug 2014 19:34:08 +0000 (-0400) Subject: tweaks to Cmakefiles (for building) X-Git-Tag: 3.0.0-233~1419^2~32^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bb3e3940492487d4ecb50991fba677821b9aef68;p=thirdparty%2Fsnort3.git tweaks to Cmakefiles (for building) --- bb3e3940492487d4ecb50991fba677821b9aef68 diff --cc CMakeLists.txt index de4c1dc24,ffe55775f..bb9291bef --- a/CMakeLists.txt +++ b/CMakeLists.txt @@@ -52,10 -52,3 +52,10 @@@ configure_file add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) + +# Test Plugins!! +if (BUILD_EXTRA_PLUGINS) + if (${CMAKE_GENERATOR} MATCHES "Make") + add_subdirectory(extra) + endif() - endif (BUILD_UNIT_TESTS) ++endif (BUILD_EXTRA_PLUGINS) diff --cc cmake/macros.cmake index 9309b11fe,fde550982..10f501a62 --- a/cmake/macros.cmake +++ b/cmake/macros.cmake @@@ -53,10 -53,10 +53,9 @@@ macro (add_shared_library libname insta set_target_properties ( ${libname} PROPERTIES COMPILE_FLAGS "-DBUILDING_SO" - LINK_FLAGS "-export-dynamic -shared" +# LINK_FLAGS "-export-dynamic -shared" - LINK_FLAGS "-shared" ) - #install into given library install (TARGETS ${libname} LIBRARY DESTINATION "lib/${CMAKE_PROJECT_NAME}/${install_path}" ) diff --cc cmake/platforms.cmake index afc197e5c,a5fdf9d18..51c877c64 --- a/cmake/platforms.cmake +++ b/cmake/platforms.cmake @@@ -79,21 -74,3 +79,27 @@@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin ) endif() endif() + +# More MacOS X fun - set(CMAKE_REQUIRED_FLAGS "-Wl,-undefined -Wl,dynamic_lookup") ++set(CMAKE_REQUIRED_FLAGS "-Wl,-undefined,dynamic_lookup") +check_cxx_compiler_flag("" HAVE_DYNAMIC_LOOKUP) +if(HAVE_DYNAMIC_LOOKUP) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup") ++ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,dynamic_lookup") +endif() - set (CMAKE_REQUIRED_FLAGS "") ++unset (CMAKE_REQUIRED_FLAGS) + + +set (CMAKE_REQUIRED_FLAGS "-Wl,-export-dynamic") +check_cxx_compiler_flag ("" HAVE_EXPORT_DYNAMIC) +if (HAVE_EXPORT_DYNAMIC) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -export-dynamic") ++ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-export-dynamic") +endif () ++unset(CMAKE_REQUIRED_FLAGS) + + ++set (CMAKE_REQUIRED_FLAGS "-Wl,-shared") ++check_cxx_compiler_flag ("" HAVE_SHARED) ++if (HAVE_SHARED) ++ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-shared") ++endif () +unset(CMAKE_REQUIRED_FLAGS) diff --cc config.cmake.h.in index 8e14bf8b2,8e14bf8b2..a99305ff3 --- a/config.cmake.h.in +++ b/config.cmake.h.in @@@ -31,6 -31,6 +31,9 @@@ /* include internal loggers in binary */ #cmakedefine STATIC_LOGGERS 1 ++/* include internal ips actions in binary */ ++#define STATIC_IPS_ACTIONS 1 ++ /* include internal ips options in binary */ #cmakedefine STATIC_IPS_OPTIONS 1 diff --cc doc/config_changes.txt index 1256ddf5a,1256ddf5a..0e4f5b0de --- a/doc/config_changes.txt +++ b/doc/config_changes.txt @@@ -134,9 -134,9 +134,6 @@@ change: policy bsd-right ==> policy = change: policy_mode ==> mode change: ports ==> bindings change: ports ==> gtp_ports --change: ports both ==> both_ports --change: ports client ==> client_ports --change: ports server ==> server_ports change: post_depth [-1:65495] ==> post_depth [-1:65535] change: preprocessor normalize_icmp4 ==> icmp4 == change: preprocessor normalize_icmp6 ==> icmp6 == @@@ -161,6 -161,6 +158,12 @@@ change: snortfile ==> file = tru change: sort avg_ticks_per_nomatch ==> sort = avg_ticks_per_no_match change: split-any-any ==> split_any_any change: srcport ==> src_port ++change: stream_tcp: ports ==> binder.when.ports; binder.when.role = any ++change: stream_tcp: ports ==> binder.when.ports; binder.when.role = client ++change: stream_tcp: ports ==> binder.when.ports; binder.when.role = server ++change: stream_tcp: protocol ==> binder.when.proto; binder.when.role = any ++change: stream_tcp: protocol ==> binder.when.proto; binder.when.role = client ++change: stream_tcp: protocol ==> binder.when.proto; binder.when.role = server change: suspend-expensive-rules ==> suspend_expensive_rules change: suspend-timeout ==> suspend_timeout change: tcp_cache_nominal_timeout ==> pruning_timeout diff --cc extra/CMakeLists.txt index ca713cc0e,2e3fd484f..1271063ec --- a/extra/CMakeLists.txt +++ b/extra/CMakeLists.txt @@@ -1,47 -1,40 +1,72 @@@ -cmake_minimum_required(VERSION 2.8.8) -project(snort_extra CXX C) +if (BUILD_EXTRA_PLUGINS) + add_subdirectory(src) +else (BUILD_EXTRA_PLUGINS) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") -set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}") + cmake_minimum_required(VERSION 2.8.8) + project(snort_extra CXX C) -# Look for Snort using pkg-config and our own find-snort module -find_package(PkgConfig REQUIRED) -pkg_check_modules(SNORT_PKG_MODULE snort) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}") -if (SNORT_PKG_MODULE_FOUND) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SNORT_PKG_MODULE_CFLAGS}") - find_package(SNORT QUIET) -else() - find_package(SNORT REQUIRED) -endif() + # Look for Snort using pkg-config and our own find-snort module + find_package(PkgConfig REQUIRED) + pkg_check_modules(SNORT_PKG_MODULE snort) -if ((NOT SNORT_FOUND) AND (NOT SNORT_PKG_MODULE_FOUND)) - message(FATAL_ERROR "Unable to find Snort includes!!") -endif() -string (REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -string (REPLACE "-DHAVE_CONFIG_H" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -message(STATUS "${CMAKE_CXX_FLAGS}") + if (SNORT_PKG_MODULE_FOUND) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SNORT_PKG_MODULE_CFLAGS}") + find_package(SNORT QUIET) + else() + find_package(SNORT REQUIRED) + endif() -add_subdirectory(src) + if ((NOT SNORT_FOUND) AND (NOT SNORT_PKG_MODULE_FOUND)) + message(FATAL_ERROR "Unable to find Snort includes!!") + endif() + string (REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string (REPLACE "-DHAVE_CONFIG_H" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + message(STATUS "${CMAKE_CXX_FLAGS}") + -# adding make unisntall -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" - IMMEDIATE @ONLY) ++ # Some shared library flags for the two platforms which I am using ++ set(CMAKE_REQUIRED_FLAGS "-Wl,-undefined,dynamic_lookup") ++ check_cxx_compiler_flag("" HAVE_DYNAMIC_LOOKUP) ++ if(HAVE_DYNAMIC_LOOKUP) ++ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,dynamic_lookup") ++ endif() ++ unset (CMAKE_REQUIRED_FLAGS) + -add_custom_target(uninstall - COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) ++ ++ set (CMAKE_REQUIRED_FLAGS "-Wl,-export-dynamic") ++ check_cxx_compiler_flag ("" HAVE_EXPORT_DYNAMIC) ++ if (HAVE_EXPORT_DYNAMIC) ++ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-export-dynamic") ++ endif () ++ unset(CMAKE_REQUIRED_FLAGS) ++ ++ ++ set (CMAKE_REQUIRED_FLAGS "-Wl,-shared") ++ check_cxx_compiler_flag ("" HAVE_SHARED) ++ if (HAVE_SHARED) ++ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-shared") ++ endif () ++ unset(CMAKE_REQUIRED_FLAGS) ++ + add_subdirectory(src) + + + + # adding make unisntall + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + + add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) + +endif (BUILD_EXTRA_PLUGINS) diff --cc extra/src/CMakeLists.txt index 270a01ab6,3a3cba68c..4ec4ff0e9 --- a/extra/src/CMakeLists.txt +++ b/extra/src/CMakeLists.txt @@@ -1,150 -1,11 +1,150 @@@ -include_directories(${SNORT_INCLUDE_DIR}) +################################################ +# MACRO FOR ADDING EXAMPLE LIBRARIES +# +# Look in subdirecties for examples. This macro +# will take care of all the logic, especially adding +# this to the test configuration +# +# PARAMS: +# library ==> library name to be installed +# install_path ==> install into folder lib/[snort/snort_ex]/install_path +# SOURCES ==> all arguments after install path are library sources +# +################################################ -set(EX_INSTALL_PATH "lib/snort_examples") +macro (add_example_library libname install_path) + set (sources ${ARGN}) -add_subdirectory(codecs) -add_subdirectory(inspectors) -add_subdirectory(ips_options) -add_subdirectory(loggers) -add_subdirectory(search_engines) -add_subdirectory(so_rules) + # Did we get any sources? + list(LENGTH sources num_extra_args) + if (${num_extra_args} GREATER 0) + + add_library (${libname} SHARED ${sources} ) + set_target_properties ( ${libname} + PROPERTIES + COMPILE_FLAGS "-DBUILDING_SO" - LINK_FLAGS "-export-dynamic -shared" + ) + + # If we're testing plugins, set a variable for later use. + if (BUILD_EXTRA_PLUGINS) + set (TMP_PLUGINS "${BUILT_PLUGINS}") + list (APPEND TMP_PLUGINS ${libname}) + + # Force implied, but making this explicit + set (BUILT_PLUGINS "${TMP_PLUGINS}" CACHE INTERNAL "example plugin libraries" FORCE) + endif (BUILD_EXTRA_PLUGINS) + + + install (TARGETS ${libname} + LIBRARY DESTINATION "${EX_INSTALL_PATH}/${install_path}" + ) + + else (${num_extra_args} GREATER 0) + + message (STATUS "add_static_library requires at least one source file!") + message (FATAL "usage: add_static_library lib_name source_1 source_2 source_3 ...") + + endif (${num_extra_args} GREATER 0) +endmacro (add_example_library) + + + +################################################ +#### SETTING CORRECT VARIABLES FOR BULIDING #### +################################################ + +if (BUILD_EXTRA_PLUGINS) + set (TEST_INSTALL_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test_install") + set (EX_INSTALL_PATH "lib/snort") + include_directories ("${TEST_INSTALL_DIRECTORY}/include/snort") ++ include_directories (${DAQ_INCLUDE_DIR}) + + # reset this variable in case Cmake is reconfigured. i.e., + # we will keep appending the same libraries multiple times otherwise + unset (BUILT_PLUGINS CACHE) + + +else (BUILD_EXTRA_PLUGINS) + include_directories (${SNORT_INCLUDE_DIR}) + set (EX_INSTALL_PATH "lib/snort_examples") + +endif (BUILD_EXTRA_PLUGINS) + + +################################################ +####### FINALLY, ADDING SUBDIRECTORIES ####### +################################################ + + +add_subdirectory (codecs) +add_subdirectory (inspectors) +add_subdirectory (ips_options) +add_subdirectory (loggers) +add_subdirectory (search_engines) +add_subdirectory (so_rules) + + +############################################################################## +# When Testing plugins, I want to build snort, install it, and then include +# the installed directory. This makes sure we install all correct files. +# The result is below. +############################################################################## + +if (BUILD_EXTRA_PLUGINS) + + ################################################ + # This variable, DBUILD_EXTRA_PLUGINS, is toggled because + # when Snort++ builds unit test, this directory will + # get recursively called from 'make install'. Infinite loops + # seem like a poor life choice. + ################################################ + + ################################################ + # Breaking this down by command + # 1) Remove the previously installed directory (if it exists) + # While this may strictly not necessary, this is a + # safegaurd to ensure only current files are included. + # 2) Clean this directory and all subdirectories. This command + # works in tandem with WORKING_DIRECTORY to ensure it + # only cleans extra plugins. Also, we check in the top + # level cmake file to ensure that Makefiles have been + # generated. So, the command is definitely valid. + # 3) Ensure we don't recursively build this directly. Also, + # make sure we install into a temporary directory + # 4) build snort. Can technically be combined with 'make install' + # but lets keep them seperate for clarity. + # 5) install snort into the temp install directory. + # 6) reset cmake options + # 7) Another make is required to ensure the all the configured files + # revert to their original form. I chose u2spewfoo because + # it only has one source file + # 8) possible cmake bug? timestamp on installed binary not updating. + # Manually touch file to ensure we don't needlesly rebuild + ################################################ + + set (TMP_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) + + # install Snort into temporary directory + add_custom_command( + OUTPUT "${TEST_INSTALL_DIRECTORY}/bin/snort" + COMMAND ${CMAKE_COMMAND} -E remove_directory ${TEST_INSTALL_DIRECTORY} + COMMAND make clean + COMMAND ${CMAKE_COMMAND} ${CMAKE_BINARY_DIR} -DCMAKE_INSTALL_PREFIX=${TEST_INSTALL_DIRECTORY} -DBUILD_EXTRA_PLUGINS=OFF + COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target snort + COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target install + COMMAND ${CMAKE_COMMAND} ${CMAKE_BINARY_DIR} -DCMAKE_INSTALL_PREFIX=${TMP_INSTALL_PREFIX} -DBUILD_EXTRA_PLUGINS=ON + COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target u2spewfoo + COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${TEST_INSTALL_DIRECTORY}/bin/snort + DEPENDS snort + COMMENT "Building extra plugins using installed Snort" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + add_custom_target(install_snort DEPENDS "${TEST_INSTALL_DIRECTORY}/bin/snort") + + + # set in Macro above + foreach (lib ${BUILT_PLUGINS}) + add_dependencies(${lib} install_snort) + endforeach(lib) +endif (BUILD_EXTRA_PLUGINS) diff --cc src/ips_options/CMakeLists.txt index 4ef3652a8,2806466b9..1ef5e35cb --- a/src/ips_options/CMakeLists.txt +++ b/src/ips_options/CMakeLists.txt @@@ -120,3 -118,3 +118,6 @@@ else (STATIC_IPS_OPTIONS endif (STATIC_IPS_OPTIONS) ++target_link_libraries(ips_options ++ helpers ++)