Skip to content

Commit

Permalink
Add plugin/CMakeLists.txt
Browse files Browse the repository at this point in the history
Support for BRO_PLUGIN_BASE has been removed, resulting in the
ZeekPluginDynamic.cmake code to pick-up ${CMAKE_CURRENT_SOURCE_DIR}/scripts
as the plugin's script. For the package-template's generated skeleton,
these are however the extra scripts usually installed via zkg.

Propose creation of another CMakeLists.txt within plugin/ to prevent
this.

The main wart here is that zeek-plugin-create-package.sh contains assumption
about the location of additional DIST_FILES (../ relative to the build directory),
so we copy these at configure time into build/ to fix this.

I'm liking this more than re-introducing support for BRO_PLUGIN_BASE,
but not sure it's overly great.

Closes #35
  • Loading branch information
awelzel committed Jun 26, 2024
1 parent 4d1638b commit e3116a7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 26 deletions.
28 changes: 2 additions & 26 deletions features/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.15.0 FATAL_ERROR)

project(ZeekPlugin@NAME@)

# Establish version numbers in config.h
# Establish version numbers
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" VERSION LIMIT_COUNT 1)

string(REGEX REPLACE "[.-]" " " version_numbers ${VERSION})
Expand All @@ -13,34 +13,10 @@ list(GET version_numbers 0 VERSION_MAJOR)
list(GET version_numbers 1 VERSION_MINOR)
list(GET version_numbers 2 VERSION_PATCH)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/plugin/src/config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/config.h" @ONLY)

# Process any package-specific customizations
include(plugin.cmake OPTIONAL)

# Our plugin source and scripts are in a subdirectory
set(BRO_PLUGIN_BASE "${CMAKE_CURRENT_SOURCE_DIR}/plugin")

# Workaround to make header files in plugin sources available to BiFs.
include_directories("${BRO_PLUGIN_BASE}/src")

include(ZeekPlugin)

zeek_plugin_begin(@NS@ @NAME@)

file(GLOB cc_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "plugin/src/*.cc")
foreach(file ${cc_files})
zeek_plugin_cc(${file})
endforeach ()

file(GLOB bif_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "plugin/src/*.bif")
foreach(file ${bif_files})
zeek_plugin_bif(${file})
endforeach ()

zeek_plugin_dist_files(README CHANGES COPYING VERSION)
zeek_plugin_end()
add_subdirectory(plugin)

if ("${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
# Allows building rpm/deb packages via "make package" in build dir.
Expand Down
30 changes: 30 additions & 0 deletions features/plugin/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/config.h" @ONLY)

include(ZeekPlugin)

zeek_plugin_begin(@NS@ @NAME@)

file(GLOB cc_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "src/*.cc")
foreach(file ${cc_files})
zeek_plugin_cc(${file})
endforeach ()

file(GLOB bif_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "src/*.bif")
foreach(file ${bif_files})
zeek_plugin_bif(${file})
endforeach ()

# Copy the dist files to package with the tarball into the top-level
# build directory to fulfill zeek-plugin-create-package.sh assumptions
# about them being located in the parent directory.
set(dist_files README CHANGES COPYING VERSION)
foreach(file ${dist_files})
if ( EXISTS ../${file} )
file(COPY ../${file} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../)
endif()
endforeach ()

zeek_plugin_dist_files(${dist_files})

zeek_plugin_end()
10 changes: 10 additions & 0 deletions tests/Baseline/features.plugin-init-preload/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
=== without test/scripts
plugin/scripts/__load__.zeek
plugin/scripts/__preload__.zeek
=== with test/scripts
plugin/scripts/__load__.zeek
plugin/scripts/__preload__.zeek
scripts/__load__.zeek
scripts/main.zeek
Hello world!
1 change: 1 addition & 0 deletions tests/Baseline/features.plugin-license-github_ci/output
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test/COPYING
test/plugin
test/plugin.cmake
test/plugin/.gitignore
test/plugin/CMakeLists.txt
test/plugin/scripts
test/plugin/scripts/types.zeek
test/plugin/scripts/__load__.zeek
Expand Down
24 changes: 24 additions & 0 deletions tests/features/plugin-init-preload
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# A test to verify that plugin/scripts/ is used as the plugin's script
# directory rather than the top-level scripts/ directory.
#
# Regression test for #35.
#
# @TEST-REQUIRES: make --version
# @TEST-REQUIRES: cmake --help | grep -q '^* Unix Makefiles'
#
# @TEST-EXEC: bash %INPUT
#
# @TEST-EXEC: cd test && ./configure 1>&2
# @TEST-EXEC: make -C test/build/ -j`nproc` 1>&2
# @TEST-EXEC: echo "=== without test/scripts" >>output
# @TEST-EXEC: ZEEK_PLUGIN_PATH=./test/build zeek </dev/null >>output
# @TEST-EXEC: echo "=== with test/scripts" >>output
# @TEST-EXEC: ZEEK_PLUGIN_PATH=./test/build zeek ./test/scripts >>output
# @TEST-EXEC: btest-diff output

${SCRIPTS}/zkg create --packagedir=test --features plugin --user-var name=Name --user-var namespace=Namespace

echo 'event zeek_init() &priority=40 { print "plugin/scripts/__load__.zeek"; }' >> test/plugin/scripts/__load__.zeek
echo 'event zeek_init() &priority=30 { print "plugin/scripts/__preload__.zeek"; }' >> test/plugin/scripts/__preload__.zeek
echo 'event zeek_init() &priority=20 { print "scripts/__load__.zeek"; }' >> test/scripts/__load__.zeek
echo 'event zeek_init() &priority=10 { print "scripts/main.zeek"; }' >> test/scripts/main.zeek

0 comments on commit e3116a7

Please sign in to comment.