Skip to content

Commit

Permalink
Merge pull request #774 in SNORT/snort3 from dynamic_plugins to master
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 429abf88893a45cdb4d2c4a8a5b41c18284cb166
Author: Michael Altizer <mialtize@cisco.com>
Date:   Thu Jan 12 18:28:03 2017 -0500

    pkg-config: Remove unnecessary optional cppflags from the default

    Nothing in the exported headers requires PCAP, DNET, or OpenSSL headers.

commit 482b74a103a5d6d88c1391e5c4219687cfeef875
Author: Michael Altizer <mialtize@cisco.com>
Date:   Thu Jan 12 18:24:06 2017 -0500

    cmake: Fix exporting Hyperscan cppflags in snort.pc

commit ab4ba847964e2d5e255e07663be9ab9fa35b5203
Author: Michael Altizer <mialtize@cisco.com>
Date:   Thu Jan 12 17:57:03 2017 -0500

    cmake: Add configure_cmake.sh convenience wrapper for extras

commit 1df401e0cc1ba3b60a10a74c041ae133407de7f7
Author: Michael Altizer <mialtize@cisco.com>
Date:   Thu Jan 12 17:49:11 2017 -0500

    build: Synchronize installed files between autotools and cmake

commit ebaf6fb2a8e05d50619dea337eb504996a3f7df6
Author: Michael Altizer <mialtize@cisco.com>
Date:   Wed Jan 11 02:33:18 2017 -0500

    build: Build dynamic plugins as modules rather than shared libraries

    This removes the 'lib' prefix from dynamic plugins, leaving them with
    their normal bare names and a .so file extension.  No SONAME nor other,
    OS-level dynamic library versioning method is applied.

    The cmake macro for adding dynamic plugins has been renamed from
    add_shared_library to add_dynamic_module.

    On OSX, this means that plugins will no longer have the dynamic library
    suffix (.dylib) and only plugins with the .so extension will be loaded,
    just like on other platforms.

    The cmake and automake templates for extras have been updated
    accordingly and used to regenerate the respective files in extras.

commit 65cc51c527d07a3d1dfbc89c3ac9885f1c352984
Author: Michael Altizer <mialtize@cisco.com>
Date:   Thu Jan 12 14:00:55 2017 -0500

    cmake: Fix setting CMAKE_C[XX]_FLAGS for subdirectories

    Don't clobber the existing CMAKE_C_FLAGS and CMAKE_CXX_FLAGS.
    Additionally, add subdirectories after flags have been pulled from
    pkg-config so that they are properly propagated.

commit 8a1f748c6ab8836e6236c7b6922c42162138dd18
Author: Michael Altizer <mialtize@cisco.com>
Date:   Wed Jan 11 01:33:50 2017 -0500

    build: Remove unnecessary check for pcap_lib_version()

    The function has been present since libpcap 0.8 and we require higher
    than that, so don't bother.
  • Loading branch information
Xiche committed Jan 13, 2017
1 parent 729ef37 commit 04625ee
Show file tree
Hide file tree
Showing 120 changed files with 1,225 additions and 979 deletions.
32 changes: 16 additions & 16 deletions cmake/create_pkg_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ set(datadir "\${datarootdir}")
set(mandir "\${datarootdir}/man")
set(infodir "\${datarootdir}/info")

if(PCAP_INCLUDE_DIR)
set(PCAP_CPPFLAGS "-I${PCAP_INCLUDE_DIR}")
if(DAQ_INCLUDE_DIR)
set(DAQ_CPPFLAGS "-I${DAQ_INCLUDE_DIR}")
endif()

if(HWLOC_INCLUDE_DIR)
set(HWLOC_CPPFLAGS "-I${HWLOC_INCLUDE_DIR}")
if(DNET_INCLUDE_DIR)
set(DNET_CPPFLAGS "-I${DNET_INCLUDE_DIR}")
endif()

if(LUAJIT_INCLUDE_DIR)
set(LUAJIT_CPPFLAGS "-I${LUAJIT_INCLUDE_DIR}")
if(HS_INCLUDE_DIR)
set(HYPERSCAN_CPPFLAGS "-I${HS_INCLUDE_DIR}")
endif()

if(PCRE_INCLUDE_DIR)
set(PCRE_CPPFLAGS "-I${PCRE_INCLUDE_DIR}")
if(HWLOC_INCLUDE_DIR)
set(HWLOC_CPPFLAGS "-I${HWLOC_INCLUDE_DIR}")
endif()

if(DNET_INCLUDE_DIR)
set(DNET_CPPFLAGS "-I${DNET_INCLUDE_DIR}")
if(INTEL_SOFT_CPM_INCLUDE_DIR)
set(INTEL_SOFT_CPM_CPPFLAGS "-I${INTEL_SOFT_CPM_INCLUDE_DIR}")
endif()

if(DAQ_INCLUDE_DIR)
set(DAQ_CPPFLAGS "-I${DAQ_INCLUDE_DIR}")
if(LUAJIT_INCLUDE_DIR)
set(LUAJIT_CPPFLAGS "-I${LUAJIT_INCLUDE_DIR}")
endif()

if(LZMA_INCLUDE_DIR)
Expand All @@ -44,12 +44,12 @@ if(OPENSSL_INCLUDE_DIR)
set(OPENSSL_CPPFLAGS "-I${OPENSSL_INCLUDE_DIR}")
endif()

if(INTEL_SOFT_CPM_INCLUDE_DIR)
set(INTEL_SOFT_CPM_CPPFLAGS "-I${INTEL_SOFT_CPM_INCLUDE_DIR}")
if(PCAP_INCLUDE_DIR)
set(PCAP_CPPFLAGS "-I${PCAP_INCLUDE_DIR}")
endif()

if(HYPERSCAN_INCLUDE_DIR)
set(HYPERSCAN_CPPFLAGS "-I${HYPERSCAN_INCLUDE_DIR}")
if(PCRE_INCLUDE_DIR)
set(PCRE_CPPFLAGS "-I${PCRE_INCLUDE_DIR}")
endif()

# create & install pkgconfig file
Expand Down
19 changes: 14 additions & 5 deletions cmake/macros.cmake
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
# TO CALL THIS MACRO...
# PARAMS:
# libname : The library's libname
# additional args : the library's sources. Must have at least one source
macro (add_shared_library libname install_path)
# libname : The module's name
# additional args : the module's sources. Must have at least one source
macro (add_dynamic_module libname install_path)
set (sources ${ARGN})

add_library ( ${libname} SHARED ${sources} )
add_library ( ${libname} MODULE ${sources} )
set_target_properties (
${libname}
PROPERTIES
COMPILE_FLAGS "-DBUILDING_SO"
PREFIX ""
)

if (APPLE)
set_target_properties (
${libname}
PROPERTIES
LINK_FLAGS "-undefined dynamic_lookup"
)
endif()

install (
TARGETS ${libname}
LIBRARY
DESTINATION "lib/${CMAKE_PROJECT_NAME}/${install_path}"
)
endmacro (add_shared_library)
endmacro (add_dynamic_module)


#anything following testname is assumed to be a link dependency
Expand Down
26 changes: 2 additions & 24 deletions cmake/platforms.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
endif()
endif()


# the Clang compiler on MacOS X may need the c++ library explicityly specified
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
Expand All @@ -29,31 +30,8 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
endif()
endif()

include(CheckCXXCompilerFlag)

# More MacOS X fun
set(CMAKE_REQUIRED_FLAGS "-Wl,-undefined,dynamic_lookup")
check_cxx_compiler_flag(${CMAKE_REQUIRED_FLAGS} HAVE_DYNAMIC_LOOKUP)
if(HAVE_DYNAMIC_LOOKUP)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
endif()
unset (CMAKE_REQUIRED_FLAGS)


#set (CMAKE_REQUIRED_FLAGS "-Wl,-export-dynamic")
#check_cxx_compiler_flag (${CMAKE_REQUIRED_FLAGS} HAVE_EXPORT_DYNAMIC)
#if (HAVE_EXPORT_DYNAMIC)
# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
#endif ()
#unset(CMAKE_REQUIRED_FLAGS)


#set (CMAKE_REQUIRED_FLAGS "-Wl,-shared")
#check_cxx_compiler_flag (${CMAKE_REQUIRED_FLAGS} HAVE_SHARED)
#if (HAVE_SHARED)
# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
#endif ()
#unset(CMAKE_REQUIRED_FLAGS)
include(CheckCXXCompilerFlag)

set (CMAKE_REQUIRED_FLAGS "-fvisibility=hidden")
check_cxx_compiler_flag (${CMAKE_REQUIRED_FLAGS} HAVE_VISIBILITY)
Expand Down
2 changes: 0 additions & 2 deletions cmake/sanity_checks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,3 @@ endif()
if (DEFINED LIBLZMA_LIBRARIES)
check_library_exists (${LIBLZMA_LIBRARIES} lzma_code "" HAVE_LZMA)
endif()

check_library_exists (pcap pcap_lib_version "${PCAP_LIBRARIES}" HAVE_PCAP_LIB_VERSION)
3 changes: 0 additions & 3 deletions config.cmake.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,6 @@

/* Library specific functions */

/* Can output the library version. */
#cmakedefine HAVE_PCAP_LIB_VERSION 1


/* Available compiler options */

Expand Down
16 changes: 0 additions & 16 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -606,22 +606,6 @@ if test "x$LPCAP" = "xno"; then
exit 1
fi

AC_MSG_CHECKING([for pcap_lib_version])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[#include <pcap.h>]],
[[pcap_lib_version();]]
)],
[have_pcap_lib_version="yes"],
[have_pcap_lib_version="no"]
)
AC_MSG_RESULT($have_pcap_lib_version)

if test "x$have_pcap_lib_version" = "xyes"; then
AC_DEFINE([HAVE_PCAP_LIB_VERSION],[1],
[Can output the library version.])
fi

#--------------------------------------------------------------------------
# hwloc
#--------------------------------------------------------------------------
Expand Down
10 changes: 1 addition & 9 deletions daqs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
macro ( add_daq_module libname )
set ( sources ${ARGN} )
add_library ( ${libname} MODULE ${sources} )
add_dynamic_module ( ${libname} daqs ${ARGN} )
set_target_properties (
${libname}
PROPERTIES
COMPILE_FLAGS "-DBUILDING_SO"
C_STANDARD 99
)

install (
TARGETS ${libname}
LIBRARY
DESTINATION "lib/${CMAKE_PROJECT_NAME}/daqs"
)
endmacro ( add_daq_module )

set ( DAQS_INCLUDES daq_user.h )
Expand Down
8 changes: 4 additions & 4 deletions extra/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
cmake_minimum_required ( VERSION 2.8.11 )
project( snort_extra CXX C )

add_subdirectory ( src )

set (EXTRA_VERSION_MAJOR 1)
set (EXTRA_VERSION_MINOR 0)
set (EXTRA_VERSION_BUILD 0-a4)
Expand All @@ -28,8 +26,8 @@ include(CPack)
set ( C_FLAGS "" CACHE STRING "" )
set ( CXX_FLAGS "" CACHE STRING "" )

set ( CMAKE_C_FLAGS "${C_FLAGS}" CACHE STRING "" FORCE )
set ( CMAKE_CXX_FLAGS "${CXX_FLAGS}" CACHE STRING "" FORCE )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_FLAGS}" CACHE STRING "" FORCE )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS}" CACHE STRING "" FORCE )

execute_process (
COMMAND pkg-config --variable=cpp_opts snort
Expand Down Expand Up @@ -67,3 +65,5 @@ foreach ( OPT ${CPP_OPTS_OTHER} )
string ( REGEX REPLACE "[\r\n]" " " CPPFLAGS "${CPPFLAGS}" )
set ( ${OPT}_CPPFLAGS "${CPPFLAGS}" CACHE STRING "" )
endforeach ( OPT )

add_subdirectory ( src )
100 changes: 100 additions & 0 deletions extra/configure_cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/sh
# Convenience wrapper for easily viewing/setting options that
# the project's CMake scripts will recognize

set -e
command="$0 $*"

# check for `cmake` command
type cmake > /dev/null 2>&1 || {
echo "\
This package requires CMake, please install it first, then you may
use this configure script to access CMake equivalent functionality.\
" >&2;
exit 1;
}

usage="\
Usage: $0 [OPTION]... [VAR=VALUE]...
--builddir= The build directory
--generator= run cmake --help for a list of generators
--prefix= Snort++ installation prefix
"

sourcedir="$( cd "$( dirname "$0" )" && pwd )"

# Function to append a CMake cache entry definition to the
# CMakeCacheEntries variable
# $1 is the cache entry variable name
# $2 is the cache entry variable type
# $3 is the cache entry variable value
append_cache_entry () {
CMakeCacheEntries="$CMakeCacheEntries -D $1:$2=$3"
}

# set defaults
builddir=build
prefix=/usr/local/snort
CMakeCacheEntries=""
append_cache_entry CMAKE_INSTALL_PREFIX PATH $prefix


# parse arguments
while [ $# -ne 0 ]; do
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac

case "$1" in
--help|-h)
echo "${usage}" 1>&2
exit 1
;;
--builddir=*)
builddir=$optarg
;;
--generator=*)
CMakeGenerator="$optarg"
;;
--prefix=*)
prefix=$optarg
append_cache_entry CMAKE_INSTALL_PREFIX PATH $optarg
;;
*)
echo "Invalid option '$1'. Try $0 --help to see available options."
exit 1
;;
esac
shift
done

if [ -d $builddir ]; then
# If build directory exists, check if it has a CMake cache
if [ -f $builddir/CMakeCache.txt ]; then
# If the CMake cache exists, delete it so that this configuration
# is not tainted by a previous one
rm -f $builddir/CMakeCache.txt
fi
else
# Create build directory
mkdir -p $builddir
fi

echo "Build Directory : $builddir"
echo "Source Directory: $sourcedir"
cd $builddir

gen=""
[ "$CMakeGenerator" ] && gen+=" -G $CMakeGenerator"

cmake $gen \
-DCMAKE_CXX_FLAGS:STRING="$CXXFLAGS $CPPFLAGS" \
-DCMAKE_C_FLAGS:STRING="$CFLAGS $CPPFLAGS" \
$CMakeCacheEntries $sourcedir

echo "# This is the command used to configure this build" > config.status
echo $command >> config.status
chmod u+x config.status

2 changes: 1 addition & 1 deletion extra/generate_boilerplate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ boilerplate=(

[[ -n $DRY_RUN ]] && ECHO=echo || ECHO=

for project_dir in $(find $RECURSE -type d -mindepth 3); do
for project_dir in $(find $RECURSE -mindepth 3 -type d); do
project_base=${project_dir##*/}

for template in "${boilerplate[@]}"; do
Expand Down
23 changes: 17 additions & 6 deletions extra/src/codecs/cd_eapol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,30 @@ project ( cd_eapol CXX )

if ( APPLE )
set ( CMAKE_MACOSX_RPATH OFF )
set (
CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup"
)
endif ( APPLE )

include ( FindPkgConfig )
pkg_search_module ( SNORT3 REQUIRED snort>=3 )

add_library (
cd_eapol SHARED
cd_eapol MODULE
cd_eapol.cc
)

if ( APPLE )
set_target_properties (
cd_eapol
PROPERTIES
LINK_FLAGS "-undefined dynamic_lookup"
)
endif ( APPLE )

set_target_properties (
cd_eapol
PROPERTIES
PREFIX ""
)

set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )

target_include_directories (
Expand All @@ -26,5 +36,6 @@ target_include_directories (

install (
TARGETS cd_eapol
LIBRARY DESTINATION "lib/${CMAKE_PROJECT_NAME}/codecs"
LIBRARY
DESTINATION "lib/${CMAKE_PROJECT_NAME}/codecs"
)
8 changes: 4 additions & 4 deletions extra/src/codecs/cd_eapol/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cd_eapollibdir = $(pkglibdir)/codecs

AM_CXXFLAGS = @SNORT3_CFLAGS@ -std=c++11

cd_eapollib_LTLIBRARIES = libcd_eapol.la
libcd_eapol_la_CXXFLAGS = $(AM_CXXFLAGS)
libcd_eapol_la_LDFLAGS = -export-dynamic -shared -avoid-version
libcd_eapol_la_SOURCES = cd_eapol.cc
cd_eapollib_LTLIBRARIES = cd_eapol.la
cd_eapol_la_CXXFLAGS = $(AM_CXXFLAGS)
cd_eapol_la_LDFLAGS = -module -export-dynamic -avoid-version -shared
cd_eapol_la_SOURCES = cd_eapol.cc
Loading

0 comments on commit 04625ee

Please sign in to comment.