]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
update Snort FindSnort module
authorJosh <jrosenba@cisco.com>
Tue, 9 Dec 2014 20:49:05 +0000 (14:49 -0600)
committerJosh <jrosenba@cisco.com>
Tue, 9 Dec 2014 20:49:05 +0000 (14:49 -0600)
extra/CMakeLists.txt
extra/FindSnort.cmake
src/CMakeLists.txt

index 120bcd8a55207461dc58d5ced412d692d4993a39..7af99696ae5024ca2d2d65142814fec55df1bf52 100644 (file)
@@ -29,14 +29,15 @@ else (BUILD_EXTRA_PLUGINS)
     find_package(LuaJIT REQUIRED)
 
 
-    if ((NOT SNORT_FOUND) AND (NOT SNORT_PKG_MODULE_FOUND))
-        find_package(SNORT REQUIRED) # to print the helpful Snort message
-        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}")
+    #  add Snort++ properties to the current build
+    string (REPLACE "-DHAVE_CONFIG_H" " " tmp_cmp_flags  "${SNORT_INTERFACE_COMPILE_OPTIONS}")
+    string (STRIP "${CMAKE_CXX_FLAGS} ${tmp_cmp_flags}" tmp_cmp_flags)
+    set (CMAKE_CXX_FLAGS "${tmp_cmp_flags}" CACHE STRING
+        "Flags used by the compiler during all build types." FORCE)
+    include_directories(${SNORT_INTERFACE_INCLUDE_DIRECTORIES})
+    string (STRIP "${CMAKE_EXE_LINKER_FLAGS} ${SNORT_INTERFACE_LINK_FLAGS}" tmp_link_flags)
+    set (CMAKE_EXE_LINKER_FLAGS "${tmp_link_flags}" CACHE STRING
+        "Flags used by the linker. " FORCE)
 
 
     include(CheckCXXCompilerFlag)
@@ -71,8 +72,8 @@ else (BUILD_EXTRA_PLUGINS)
     endif ()
     unset(CMAKE_REQUIRED_FLAGS)
 
-    add_subdirectory(src)
 
+    add_subdirectory(src)
 
 
     # adding make unisntall
index 6afbc504e8b3ed59590536a29e9501a91b5a8c2f..026346e5755dad0e9b523e302a4881d7f7e0d584 100644 (file)
 #  SNORT_EXECUTABLE - The Snort++ executable
 #  SNORT_INCLUDE_DIR - Snort include directory
 #
+#
+#  SNORT_INTERFACE_COMPILE_OPTIONS -  Snort++'s compile options.  If snort.cmake found,
+#                                       use those compile flags.  Else, use
+#                                       `pkg-config snort` compile flags
+#  SNORT_INTERFACE_INCLUDE_DIRECTORIES - The directories that Snort++ includes
+#                                       when building. retrieved from snort.cmake
+#  SNORT_INTERFACE_LINK_FLAGS  -  Snort++ link flags.  retrived from `pkg-config`
+#
 
 set(ERROR_MESSAGE
     "
@@ -65,10 +73,15 @@ if (SNORT_IMPORT_FILE)
         set(SNORT_EXECUTABLE "${tmp_exe}" CACHE FILEPATH "Snort executable" FORCE)
     endif()
 
-    if (NOT SNORT_INCLUDE_DIR)
-        get_target_property(tmp_exe snort  INTERFACE_INCLUDE_DIRECTORIES)
-        set(SNORT_INCLUDE_DIR "${tmp_exe}" CACHE FILEPATH "Snort executable" FORCE)
-    endif()
+    get_target_property(tmp_cflags snort  INTERFACE_COMPILE_OPTIONS)
+        set (SNORT_INTERFACE_COMPILE_OPTIONS "${tmp_cflags}" CACHE STRING
+            "The compile options with which Snort was linked" FORCE)
+
+    get_target_property(tmp_int_dir snort  INTERFACE_INCLUDE_DIRECTORIES)
+    set(SNORT_INTERFACE_INCLUDE_DIRECTORIES "${tmp_int_dir}" CACHE FILEPATH
+        "The directories that Snort include's when building" FORCE)
+
+
 endif(SNORT_IMPORT_FILE)
 
 
@@ -80,29 +93,32 @@ if (PKG_CONFIG_FOUND)
 
     if (SNORT_PKG_FOUND)
 
-        #  add Snort link flags
-        string(REPLACE ";" " " tmp_cflags "${SNORT_PKG_CFLAGS}")
-        set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${tmp_cflags}" CACHE STRING
-            "Flags used by the compiler during all build types." FORCE)
+        #  CMake file takes precedence over pkg-config file
+        if (NOT SNORT_INTERFACE_COMPILE_OPTIONS)
+            string(REPLACE ";" " " tmp_cflags "${SNORT_PKG_CFLAGS}")
+            set (SNORT_INTERFACE_COMPILE_OPTIONS "${tmp_cflags}" CACHE STRING
+                "The compile options with which Snort was linked" FORCE)
+        endif()
+
 
         #  add Snort link flags
         string(REPLACE ";" " " tmp_lflags "${SNORT_PKG_LDFLAGS}")
-        set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${tmp_lflags}"
-            CACHE STRING "Flags used by the linker." FORCE)
+        set (SNORT_INTERFACE_LINK_FLAGS "${tmp_lflags}"
+            CACHE STRING "The link flags with which the Snort++ binary was linked" FORCE)
+
 
         if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
             set (CMAKE_INSTALL_PREFIX "${SNORT_PKG_PREFIX}" CACHE PATH
                 "Install path prefix, prepended onto install directories." FORCE)
         endif (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
 
-
     endif (SNORT_PKG_FOUND)
 endif (PKG_CONFIG_FOUND)
 
 
 find_path (SNORT_INCLUDE_DIR
     NAMES main/snort_types.h
-    HINTS ${SNORT_PKG_INCLUDE_DIRS} ENV SNORT_DIR
+    HINTS ${SNORT_INTERFACE_INCLUDE_DIRECTORIES} ENV SNORT_DIR
     PATH_SUFFIXES snort include/snort
 )
 
@@ -113,9 +129,8 @@ find_program (SNORT_EXECUTABLE
 )
 
 
-
 include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(SNORT
+find_package_handle_standard_args( Snort
     REQUIRED_VARS SNORT_INCLUDE_DIR SNORT_EXECUTABLE
     FAIL_MESSAGE "${ERROR_MESSAGE}"
 )
@@ -125,6 +140,9 @@ mark_as_advanced(
     SNORT_INCLUDE_DIR
     SNORT_EXECUTABLE
     SNORT_IMPORT_FILE
+    SNORT_INTERFACE_COMPILE_OPTIONS
+    SNORT_INTERFACE_INCLUDE_DIRECTORIES
+    SNORT_INTERFACE_LINK_FLAGS
 )
 
 
index 69e623290baa0fa256739ef86b263ee46f3f80a0..2a9621631eebc36f032227351cd903b258c02f8e 100644 (file)
@@ -157,6 +157,16 @@ add_subdirectory(network_inspectors)
 add_subdirectory(search_engines)
 
 
+#  setting export properties
+set_property(TARGET snort APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES
+    ${LUAJIT_INCLUDE_DIR}
+    ${EXTERNAL_INCLUDES}
+    # The installed path '${INCLUDE_INSTALL_PATH}'' is added below with 'install (... snort ...)'
+)
+
+set_property(TARGET snort APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "${CMAKE_CXX_FLAGS}")
+
+
 install (TARGETS snort
     EXPORT snortexe
     RUNTIME DESTINATION bin