add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
- endif (BUILD_UNIT_TESTS)
+
+# Test Plugins!!
+if (BUILD_EXTRA_PLUGINS)
+ if (${CMAKE_GENERATOR} MATCHES "Make")
+ add_subdirectory(extra)
+ endif()
++endif (BUILD_EXTRA_PLUGINS)
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}"
)
)
endif()
endif()
- set(CMAKE_REQUIRED_FLAGS "-Wl,-undefined -Wl,dynamic_lookup")
+
+# More MacOS X fun
- set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
++set(CMAKE_REQUIRED_FLAGS "-Wl,-undefined,dynamic_lookup")
+check_cxx_compiler_flag("" HAVE_DYNAMIC_LOOKUP)
+if(HAVE_DYNAMIC_LOOKUP)
- set (CMAKE_REQUIRED_FLAGS "")
++ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,dynamic_lookup")
+endif()
- set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -export-dynamic")
++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} -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)
/* 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
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 == <bool>
change: preprocessor normalize_icmp6 ==> icmp6 == <bool>
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
-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)
+
-add_custom_target(uninstall
- COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
++ # 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)
+
++
++ 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)
-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)
endif (STATIC_IPS_OPTIONS)
++target_link_libraries(ips_options
++ helpers
++)