Update upstream source from tag 'upstream/1.2+really+1.1'
Update to upstream version '1.2+really+1.1'
with Debian dir 44ad8acbc0cc6fa2bfa62bcf6965ac83e8a21e39
Hilko Bengen
4 years ago
0 | ||
1 | 1.2 | 2019-06-12 15:01:17 -0700 | |
2 | ||
3 | * Release 1.2. | |
4 | ||
5 | 1.1-19 | 2019-06-12 15:01:04 -0700 | |
6 | ||
7 | * Rename directories from bro to zeek (Daniel Thayer) | |
8 | ||
9 | 1.1-16 | 2019-05-20 19:38:17 -0700 | |
10 | ||
11 | * Rename Bro to Zeek (Daniel Thayer) | |
12 | ||
13 | * Update codegen to use faster val_list and event queue API (Jon Siwek, Corelight) | |
14 | ||
15 | 1.1-10 | 2019-04-16 11:48:09 -0700 | |
16 | ||
17 | * Change file extension of auto-generated script files to .zeek (Daniel Thayer) | |
18 | ||
19 | * Use ValManager for creating Vals (Jon Siwek, Corelight) | |
20 | ||
21 | * Update submodules to use github.com/zeek (Jon Siwek, Corelight) | |
22 | 0 | |
23 | 1 | 1.1 | 2018-08-31 15:23:21 -0500 |
24 | 2 |
0 | .. _Zeek: https://www.zeek.org | |
0 | .. _Bro: https://bro.org | |
1 | 1 | |
2 | ================= | |
3 | Zeek BIF Compiler | |
4 | ================= | |
2 | ================ | |
3 | Bro BIF Compiler | |
4 | ================ | |
5 | 5 | |
6 | 6 | The ``bifcl`` program simply takes a ``.bif`` file as input and |
7 | generates C++ header/source files along with a ``.zeek`` script | |
8 | that all-together provide the declaration and implementation of Zeek_ | |
7 | generates C++ header/source files along with a ``.bro`` script | |
8 | that all-together provide the declaration and implementation of Bro_ | |
9 | 9 | Built-In-Functions (BIFs), which can then be compiled and shipped |
10 | as part of a Zeek plugin. | |
10 | as part of a Bro plugin. | |
11 | 11 | |
12 | 12 | A BIF allows one to write arbitrary C++ code and access it via a |
13 | function call inside a Zeek script. In this way, they can also be | |
14 | used to access parts of Zeek's internal C++ API that aren't already | |
13 | function call inside a Bro script. In this way, they can also be | |
14 | used to access parts of Bro's internal C++ API that aren't already | |
15 | 15 | exposed via their own BIFs. |
16 | 16 | |
17 | 17 | At the moment, learning the format of a ``.bif`` file is likely easiest |
18 | by just taking a look at the ``.bif`` files inside the Zeek source-tree. | |
18 | by just taking a look at the ``.bif`` files inside the Bro source-tree. |
1 | 1 | |
2 | 2 | DEFINE_BIF_TYPE(TYPE_ADDR, "addr", "addr", "AddrVal*", "%s->AsAddrVal()", "%s") |
3 | 3 | DEFINE_BIF_TYPE(TYPE_ANY, "any", "any", "Val*", "%s", "%s") |
4 | DEFINE_BIF_TYPE(TYPE_BOOL, "bool", "bool", "int", "%s->AsBool()", "val_mgr->GetBool(%s)") | |
4 | DEFINE_BIF_TYPE(TYPE_BOOL, "bool", "bool", "int", "%s->AsBool()", "new Val(%s, TYPE_BOOL)") | |
5 | 5 | DEFINE_BIF_TYPE(TYPE_CONN_ID, "conn_id", "conn_id", "Val*", "%s", "%s") |
6 | 6 | DEFINE_BIF_TYPE(TYPE_CONNECTION, "connection", "connection", "Connection*", "%s->AsRecordVal()->GetOrigin()", "%s->BuildConnVal()") |
7 | DEFINE_BIF_TYPE(TYPE_COUNT, "count", "count", "bro_uint_t", "%s->AsCount()", "val_mgr->GetCount(%s)") | |
7 | DEFINE_BIF_TYPE(TYPE_COUNT, "count", "count", "bro_uint_t", "%s->AsCount()", "new Val(%s, TYPE_COUNT)") | |
8 | 8 | DEFINE_BIF_TYPE(TYPE_DOUBLE, "double", "double", "double", "%s->AsDouble()", "new Val(%s, TYPE_DOUBLE)") |
9 | 9 | DEFINE_BIF_TYPE(TYPE_FILE, "file", "file", "BroFile*", "%s->AsFile()", "new Val(%s)") |
10 | DEFINE_BIF_TYPE(TYPE_INT, "int", "int", "bro_int_t", "%s->AsInt()", "val_mgr->GetInt(%s)") | |
10 | DEFINE_BIF_TYPE(TYPE_INT, "int", "int", "bro_int_t", "%s->AsInt()", "new Val(%s, TYPE_INT)") | |
11 | 11 | DEFINE_BIF_TYPE(TYPE_INTERVAL, "interval", "interval", "double", "%s->AsInterval()", "new IntervalVal(%s, Seconds)") |
12 | 12 | DEFINE_BIF_TYPE(TYPE_PACKET, "packet", "packet", "TCP_TracePacket*", "%s->AsRecordVal()->GetOrigin()", "%s->PacketVal()") |
13 | 13 | DEFINE_BIF_TYPE(TYPE_PATTERN, "pattern", "pattern", "RE_Matcher*", "%s->AsPattern()", "new PatternVal(%s)") |
104 | 104 | |
105 | 105 | /* |
106 | 106 | Hacky way to pass along arbitrary attribute expressions since the BIF parser |
107 | has little understanding of valid Zeek expressions. With this pattern, the | |
107 | has little understanding of valid Bro expressions. With this pattern, the | |
108 | 108 | attribute expression should stop when it reaches another attribute, another |
109 | 109 | function argument, or the end of the function declaration. |
110 | 110 | */ |
187 | 187 | |
188 | 188 | void init_alternative_mode() |
189 | 189 | { |
190 | fp_bro_init = open_output_file("zeek"); | |
190 | fp_bro_init = open_output_file("bro"); | |
191 | 191 | fp_func_h = open_output_file("h"); |
192 | 192 | fp_func_def = open_output_file("cc"); |
193 | 193 | fp_func_init = open_output_file("init.cc"); |
334 | 334 | |
335 | 335 | if ( ! alternative_mode ) |
336 | 336 | { |
337 | fp_bro_init = open_output_file("zeek"); | |
337 | fp_bro_init = open_output_file("bro"); | |
338 | 338 | fp_func_h = open_output_file("func_h"); |
339 | 339 | fp_func_def = open_output_file("func_def"); |
340 | 340 | fp_func_init = open_output_file("func_init"); |
408 | 408 | { |
409 | 409 | close_all_output_files(); |
410 | 410 | /* clean up. remove all output files we've generated so far */ |
411 | remove_file("zeek"); | |
411 | remove_file("bro"); | |
412 | 412 | remove_file("func_h"); |
413 | 413 | remove_file("func_def"); |
414 | 414 | remove_file("func_init"); |
49 | 49 | string c_namespace_end; // closing "}" for all the above namespaces |
50 | 50 | string c_fullname; // fully qualified name (namespace::....) for use in netvar_init |
51 | 51 | string bro_fullname; // fully qualified bro name, for netvar (and lookup_ID()) |
52 | string bro_name; // the name as we read it from input. What we write into the .zeek file | |
52 | string bro_name; // the name as we read it from input. What we write into the .bro file | |
53 | 53 | |
54 | 54 | // special cases for events. Events have an EventHandlerPtr |
55 | 55 | // and a generate_* function. This name is for the generate_* function |
229 | 229 | fprintf(fp, "\t// allocation.\n"); |
230 | 230 | fprintf(fp, "\n"); |
231 | 231 | |
232 | BuiltinFuncArg* connection_arg = 0; | |
233 | ||
234 | fprintf(fp, "\tmgr.QueueEventFast(%s, val_list{\n", decl.c_fullname.c_str()); | |
232 | fprintf(fp, "\tval_list* vl = new val_list;\n\n"); | |
233 | BuiltinFuncArg *connection_arg = 0; | |
235 | 234 | |
236 | 235 | for ( int i = 0; i < (int) args.size(); ++i ) |
237 | 236 | { |
238 | fprintf(fp, "\t "); | |
237 | fprintf(fp, "\t"); | |
238 | fprintf(fp, "vl->append("); | |
239 | 239 | args[i]->PrintBroValConstructor(fp); |
240 | fprintf(fp, ",\n"); | |
240 | fprintf(fp, ");\n"); | |
241 | 241 | |
242 | 242 | if ( args[i]->Type() == TYPE_CONNECTION ) |
243 | 243 | { |
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
256 | fprintf(fp, "\t },\n\t SOURCE_LOCAL, analyzer->GetID(), timer_mgr"); | |
256 | fprintf(fp, "\n"); | |
257 | fprintf(fp, "\tmgr.QueueEvent(%s, vl, SOURCE_LOCAL, analyzer->GetID(), timer_mgr", | |
258 | decl.c_fullname.c_str()); | |
257 | 259 | |
258 | 260 | if ( connection_arg ) |
259 | 261 | // Pass the connection to the EventMgr as the "cookie" |
335 | 337 | // XXX: Add the netvar glue so that the event engine knows about |
336 | 338 | // the type. One still has to define the type in bro.init. |
337 | 339 | // Would be nice, if we could just define the record type here |
338 | // and then copy to the .bif.zeek file, but type declarations in | |
339 | // Zeek can be quite powerful. Don't know whether it's worth it | |
340 | // and then copy to the .bif.bro file, but type declarations in | |
341 | // Bro can be quite powerful. Don't know whether it's worth it | |
340 | 342 | // extend the bif-language to be able to handle that all.... |
341 | 343 | // Or we just support a simple form of record type definitions |
342 | 344 | // TODO: add other types (tables, sets) |
595 | 597 | ; |
596 | 598 | |
597 | 599 | // TODO: Migrate all other compound types to this rule. Once the BiF language |
598 | // can parse all regular Zeek types, we can throw out the unnecessary | |
600 | // can parse all regular Bro types, we can throw out the unnecessary | |
599 | 601 | // boilerplate typedefs for addr_set, string_set, etc. |
600 | 602 | type: |
601 | 603 | TOK_OPAQUE opt_ws TOK_OF opt_ws TOK_ID |
0 | 0 | |
1 | 1 | # A macro to define a command that uses the BIF compiler to produce C++ |
2 | # segments and Zeek language declarations from a .bif file. The outputs | |
2 | # segments and Bro language declarations from a .bif file. The outputs | |
3 | 3 | # are returned in BIF_OUTPUT_{CC,H,BRO}. By default, it runs bifcl in |
4 | 4 | # alternative mode (-a; suitable for standalone compilation). If |
5 | 5 | # an additional parameter "standard" is given, it runs it in standard mode |
31 | 31 | ${bifInputBasename}.netvar_init) |
32 | 32 | set(BIF_OUTPUT_H ${bifInputBasename}.func_h |
33 | 33 | ${bifInputBasename}.netvar_h) |
34 | set(BIF_OUTPUT_BRO ${CMAKE_BINARY_DIR}/scripts/base/bif/${bifInputBasename}.zeek) | |
35 | set(bro_BASE_BIF_SCRIPTS ${bro_BASE_BIF_SCRIPTS} ${BIF_OUTPUT_BRO} CACHE INTERNAL "Zeek script stubs for BIFs in base distribution of Zeek" FORCE) # Propogate to top-level | |
34 | set(BIF_OUTPUT_BRO ${CMAKE_BINARY_DIR}/scripts/base/bif/${bifInputBasename}.bro) | |
35 | set(bro_BASE_BIF_SCRIPTS ${bro_BASE_BIF_SCRIPTS} ${BIF_OUTPUT_BRO} CACHE INTERNAL "Bro script stubs for BIFs in base distribution of Bro" FORCE) # Propogate to top-level | |
36 | 36 | |
37 | 37 | elseif ( "${ARGV1}" STREQUAL "plugin" ) |
38 | 38 | set(plugin_name ${ARGV2}) |
58 | 58 | |
59 | 59 | set(BIF_OUTPUT_H ${bifInputBasename}.h) |
60 | 60 | |
61 | if ( NOT ZEEK_PLUGIN_BUILD_DYNAMIC ) | |
62 | set(BIF_OUTPUT_BRO ${CMAKE_BINARY_DIR}/scripts/base/bif/plugins/${plugin_name_canon}.${bifInputBasename}.zeek) | |
63 | else () | |
64 | set(BIF_OUTPUT_BRO ${BRO_PLUGIN_BIF}/${bifInputBasename}.zeek) | |
61 | if ( NOT BRO_PLUGIN_BUILD_DYNAMIC ) | |
62 | set(BIF_OUTPUT_BRO ${CMAKE_BINARY_DIR}/scripts/base/bif/plugins/${plugin_name_canon}.${bifInputBasename}.bro) | |
63 | else () | |
64 | set(BIF_OUTPUT_BRO ${BRO_PLUGIN_BIF}/${bifInputBasename}.bro) | |
65 | 65 | endif() |
66 | 66 | |
67 | set(bro_PLUGIN_BIF_SCRIPTS ${bro_PLUGIN_BIF_SCRIPTS} ${BIF_OUTPUT_BRO} CACHE INTERNAL "Zeek script stubs for BIFs in Zeek plugins" FORCE) # Propogate to top-level | |
67 | set(bro_PLUGIN_BIF_SCRIPTS ${bro_PLUGIN_BIF_SCRIPTS} ${BIF_OUTPUT_BRO} CACHE INTERNAL "Bro script stubs for BIFs in Bro plugins" FORCE) # Propogate to top-level | |
68 | 68 | |
69 | 69 | else () |
70 | 70 | # Alternative mode. These will get compiled in automatically. |
77 | 77 | set(BIF_OUTPUT_CC ${bifInputBasename}.cc) |
78 | 78 | set(BIF_OUTPUT_H ${bifInputBasename}.h) |
79 | 79 | |
80 | # In order be able to run Zeek from the build directory, the | |
81 | # generated Zeek script needs to be inside a directory tree | |
80 | # In order be able to run bro from the build directory, the | |
81 | # generated bro script needs to be inside a directory tree | |
82 | 82 | # named the same way it will be referenced from an @load. |
83 | set(BIF_OUTPUT_BRO ${CMAKE_BINARY_DIR}/scripts/base/bif/${bifInputBasename}.zeek) | |
83 | set(BIF_OUTPUT_BRO ${CMAKE_BINARY_DIR}/scripts/base/bif/${bifInputBasename}.bro) | |
84 | 84 | |
85 | 85 | set(bro_AUTO_BIFS ${bro_AUTO_BIFS} ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename} CACHE INTERNAL "BIFs for automatic inclusion" FORCE) # Propagate to top-level. |
86 | set(bro_BASE_BIF_SCRIPTS ${bro_BASE_BIF_SCRIPTS} ${BIF_OUTPUT_BRO} CACHE INTERNAL "Zeek script stubs for BIFs in base distribution of Zeek" FORCE) # Propogate to top-level | |
86 | set(bro_BASE_BIF_SCRIPTS ${bro_BASE_BIF_SCRIPTS} ${BIF_OUTPUT_BRO} CACHE INTERNAL "Bro script stubs for BIFs in base distribution of Bro" FORCE) # Propogate to top-level | |
87 | 87 | |
88 | 88 | endif () |
89 | 89 | |
90 | if ( ZEEK_PLUGIN_INTERNAL_BUILD ) | |
90 | if ( BRO_PLUGIN_INTERNAL_BUILD ) | |
91 | 91 | if ( BIFCL_EXE_PATH ) |
92 | 92 | set(BifCl_EXE ${BIFCL_EXE_PATH}) |
93 | 93 | else () |
113 | 113 | COMMAND ${BifCl_EXE} |
114 | 114 | ARGS ${bifcl_args} ${CMAKE_CURRENT_SOURCE_DIR}/${bifInput} || (rm -f ${bifOutputs} && exit 1) |
115 | 115 | COMMAND "${CMAKE_COMMAND}" |
116 | ARGS -E copy ${bifInputBasename}.zeek ${BIF_OUTPUT_BRO} | |
116 | ARGS -E copy ${bifInputBasename}.bro ${BIF_OUTPUT_BRO} | |
117 | 117 | COMMAND "${CMAKE_COMMAND}" |
118 | ARGS -E remove -f ${bifInputBasename}.zeek | |
118 | ARGS -E remove -f ${bifInputBasename}.bro | |
119 | 119 | DEPENDS ${bifInput} |
120 | 120 | DEPENDS ${bifclDep} |
121 | 121 | COMMENT "[BIFCL] Processing ${bifInput}" |
130 | 130 | set(bro_ALL_GENERATED_OUTPUTS ${bro_ALL_GENERATED_OUTPUTS} ${target} CACHE INTERNAL "automatically generated files" FORCE) # Propagate to top-level. |
131 | 131 | endmacro(bif_target) |
132 | 132 | |
133 | # A macro to create a __load__.zeek file for all *.bif.zeek files in | |
133 | # A macro to create a __load__.bro file for all *.bif.bro files in | |
134 | 134 | # a given collection (which should all be in the same directory). |
135 | 135 | # It creates a corresponding target to trigger the generation. |
136 | 136 | function(bro_bif_create_loader target bifinputs) |
142 | 142 | |
143 | 143 | if ( _bif_loader_dir ) |
144 | 144 | if ( NOT _bif_loader_dir_tmp STREQUAL _bif_loader_dir ) |
145 | message(FATAL_ERROR "Directory of Zeek script BIF stub ${_bro_file} differs from expected: ${_bif_loader_dir}") | |
145 | message(FATAL_ERROR "Directory of Bro script BIF stub ${_bro_file} differs from expected: ${_bif_loader_dir}") | |
146 | 146 | endif () |
147 | 147 | else () |
148 | 148 | set(_bif_loader_dir ${_bif_loader_dir_tmp}) |
157 | 157 | |
158 | 158 | file(MAKE_DIRECTORY ${_bif_loader_dir}) |
159 | 159 | |
160 | set(_bif_loader_file ${_bif_loader_dir}/__load__.zeek) | |
160 | set(_bif_loader_file ${_bif_loader_dir}/__load__.bro) | |
161 | 161 | add_custom_target(${target} |
162 | 162 | COMMAND "sh" "-c" "rm -f ${_bif_loader_file}" |
163 | 163 | COMMAND "sh" "-c" "for i in ${_bif_loader_content}; do echo @load ./$i >> ${_bif_loader_file}; done" |
8 | 8 | # the input pac to make it unique. The target is added automatically to |
9 | 9 | # bro_ALL_GENERATED_OUTPUTS. |
10 | 10 | macro(BINPAC_TARGET pacFile) |
11 | if ( ZEEK_PLUGIN_INTERNAL_BUILD ) | |
11 | if ( BRO_PLUGIN_INTERNAL_BUILD ) | |
12 | 12 | if ( BINPAC_EXE_PATH ) |
13 | 13 | set(BinPAC_EXE ${BINPAC_EXE_PATH}) |
14 | 14 | endif () |
0 | ||
1 | # Wrapper include file that loads the macros for building a Bro | |
2 | # plugin either statically or dynamically, depending on whether | |
3 | # we're building as part of the main Bro source tree, or externally. | |
4 | ||
5 | if ( BRO_PLUGIN_INTERNAL_BUILD ) | |
6 | if ( "${BRO_PLUGIN_BUILD_DYNAMIC}" STREQUAL "" ) | |
7 | set(BRO_PLUGIN_BUILD_DYNAMIC FALSE) | |
8 | endif() | |
9 | else () | |
10 | set(BRO_PLUGIN_BUILD_DYNAMIC TRUE) | |
11 | endif () | |
12 | ||
13 | include(BroPluginCommon) | |
14 | include(BroPluginStatic) | |
15 | include(BroPluginDynamic) | |
16 |
0 | ## A set of functions for defining Bro plugins. | |
1 | ## | |
2 | ## This set is used by both static and dynamic plugins via | |
3 | ## BroPluginsStatic and BroPluginsDynamic, respectively. | |
4 | ||
5 | include(RequireCXX11) | |
6 | ||
7 | include(BifCl) | |
8 | include(BinPAC) | |
9 | ||
10 | # Begins a plugin definition, giving its namespace and name as the arguments. | |
11 | function(bro_plugin_begin ns name) | |
12 | _plugin_target_name(target "${ns}" "${name}") | |
13 | set(_plugin_lib "${target}" PARENT_SCOPE) | |
14 | set(_plugin_name "${ns}::${name}" PARENT_SCOPE) | |
15 | set(_plugin_name_canon "${ns}_${name}" PARENT_SCOPE) | |
16 | set(_plugin_ns "${ns}" PARENT_SCOPE) | |
17 | set(_plugin_objs "" PARENT_SCOPE) | |
18 | set(_plugin_deps "" PARENT_SCOPE) | |
19 | set(_plugin_dist "" PARENT_SCOPE) | |
20 | endfunction() | |
21 | ||
22 | # Adds *.cc files to a plugin. | |
23 | function(bro_plugin_cc) | |
24 | list(APPEND _plugin_objs ${ARGV}) | |
25 | set(_plugin_objs "${_plugin_objs}" PARENT_SCOPE) | |
26 | endfunction() | |
27 | ||
28 | # Adds a *.pac file to a plugin. Further *.pac files may given that | |
29 | # it depends on. | |
30 | function(bro_plugin_pac) | |
31 | binpac_target(${ARGV}) | |
32 | list(APPEND _plugin_objs ${BINPAC_OUTPUT_CC}) | |
33 | list(APPEND _plugin_deps ${BINPAC_BUILD_TARGET}) | |
34 | set(_plugin_objs "${_plugin_objs}" PARENT_SCOPE) | |
35 | set(_plugin_deps "${_plugin_deps}" PARENT_SCOPE) | |
36 | endfunction() | |
37 | ||
38 | # Add an additional object file to the plugin's library. | |
39 | function(bro_plugin_obj) | |
40 | foreach ( bif ${ARGV} ) | |
41 | list(APPEND _plugin_objs ${bif}) | |
42 | set(_plugin_objs "${_plugin_objs}" PARENT_SCOPE) | |
43 | endforeach () | |
44 | endfunction() | |
45 | ||
46 | # Add additional files that should be included into the binary plugin distribution. | |
47 | # Ignored for static plugins. | |
48 | macro(bro_plugin_dist_files) | |
49 | foreach ( file ${ARGV} ) | |
50 | list(APPEND _plugin_dist ${file}) | |
51 | # Don't need this here, and generates an error that | |
52 | # there is not parent scope. Not sure why it does that | |
53 | # here but not for other macros doing something similar. | |
54 | # set(_plugin_dist "${_plugin_dist}" PARENT_SCOPE) | |
55 | endforeach () | |
56 | endmacro() | |
57 | ||
58 | # Link an additional library to the plugin's library. | |
59 | function(bro_plugin_link_library) | |
60 | if ( BRO_PLUGIN_BUILD_DYNAMIC ) | |
61 | bro_plugin_link_library_dynamic(${ARGV}) | |
62 | else () | |
63 | bro_plugin_link_library_static(${ARGV}) | |
64 | endif () | |
65 | endfunction() | |
66 | ||
67 | # Adds *.bif files to a plugin. | |
68 | macro(bro_plugin_bif) | |
69 | if ( BRO_PLUGIN_BUILD_DYNAMIC ) | |
70 | bro_plugin_bif_dynamic(${ARGV}) | |
71 | else () | |
72 | bro_plugin_bif_static(${ARGV}) | |
73 | endif () | |
74 | endmacro() | |
75 | ||
76 | # Ends a plugin definition. | |
77 | macro(bro_plugin_end) | |
78 | if ( BRO_PLUGIN_BUILD_DYNAMIC ) | |
79 | bro_plugin_end_dynamic(${ARGV}) | |
80 | else () | |
81 | bro_plugin_end_static(${ARGV}) | |
82 | endif () | |
83 | endmacro() | |
84 | ||
85 | # Internal macro to create a unique target name for a plugin. | |
86 | macro(_plugin_target_name target ns name) | |
87 | if ( BRO_PLUGIN_BUILD_DYNAMIC ) | |
88 | _plugin_target_name_dynamic(${ARGV}) | |
89 | else () | |
90 | _plugin_target_name_static(${ARGV}) | |
91 | endif () | |
92 | endmacro() | |
93 |
0 | ## A set of functions for defining Bro plugins. | |
1 | ## | |
2 | ## This set is for plugins compiled dynamically for loading at run-time. | |
3 | ## See BroPluginsStatic.cmake for the static version. | |
4 | ## | |
5 | ## Note: This is meant to run as a standalone CMakeLists.txt. It sets | |
6 | ## up all the basic infrastructure to compile a dynamic Bro plugin when | |
7 | ## included from its top-level CMake file. | |
8 | ||
9 | if ( NOT BRO_PLUGIN_INTERNAL_BUILD ) | |
10 | set(BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH "${BRO_PLUGIN_INSTALL_ROOT}" | |
11 | CACHE INTERNAL "" FORCE) | |
12 | ||
13 | if ( BRO_DIST ) | |
14 | include(${BRO_DIST}/cmake/CommonCMakeConfig.cmake) | |
15 | ||
16 | if ( NOT EXISTS "${BRO_DIST}/build/CMakeCache.txt" ) | |
17 | message(FATAL_ERROR | |
18 | "${BRO_DIST}/build/CMakeCache.txt; has Bro been built?") | |
19 | endif () | |
20 | ||
21 | load_cache("${BRO_DIST}/build" READ_WITH_PREFIX bro_cache_ | |
22 | CMAKE_INSTALL_PREFIX | |
23 | Bro_BINARY_DIR | |
24 | Bro_SOURCE_DIR | |
25 | ENABLE_DEBUG | |
26 | BRO_PLUGIN_INSTALL_PATH | |
27 | BRO_EXE_PATH | |
28 | CMAKE_CXX_FLAGS | |
29 | CMAKE_C_FLAGS | |
30 | CAF_INCLUDE_DIR_CORE | |
31 | CAF_INCLUDE_DIR_IO | |
32 | CAF_INCLUDE_DIR_OPENSSL) | |
33 | ||
34 | if ( NOT BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH ) | |
35 | set(BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH | |
36 | "${bro_cache_BRO_PLUGIN_INSTALL_PATH}" CACHE INTERNAL "" FORCE) | |
37 | endif () | |
38 | ||
39 | set(BRO_PLUGIN_BRO_INSTALL_PREFIX "${bro_cache_CMAKE_INSTALL_PREFIX}" | |
40 | CACHE INTERNAL "" FORCE) | |
41 | set(BRO_PLUGIN_ENABLE_DEBUG "${bro_cache_ENABLE_DEBUG}" | |
42 | CACHE INTERNAL "" FORCE) | |
43 | set(BRO_PLUGIN_BRO_SRC "${bro_cache_Bro_SOURCE_DIR}" | |
44 | CACHE INTERNAL "" FORCE) | |
45 | set(BRO_PLUGIN_BRO_BUILD "${bro_cache_Bro_BINARY_DIR}" | |
46 | CACHE INTERNAL "" FORCE) | |
47 | set(BRO_PLUGIN_BRO_EXE_PATH "${bro_cache_BRO_EXE_PATH}" | |
48 | CACHE INTERNAL "" FORCE) | |
49 | ||
50 | set(BRO_PLUGIN_BRO_CMAKE ${BRO_PLUGIN_BRO_SRC}/cmake) | |
51 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) | |
52 | set(CMAKE_MODULE_PATH ${BRO_PLUGIN_BRO_CMAKE} ${CMAKE_MODULE_PATH}) | |
53 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${bro_cache_CMAKE_C_FLAGS}") | |
54 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${bro_cache_CMAKE_CXX_FLAGS}") | |
55 | ||
56 | include_directories(BEFORE | |
57 | ${BRO_PLUGIN_BRO_SRC}/src | |
58 | ${BRO_PLUGIN_BRO_SRC}/aux/binpac/lib | |
59 | ${BRO_PLUGIN_BRO_SRC}/aux/broker | |
60 | ${BRO_PLUGIN_BRO_BUILD} | |
61 | ${BRO_PLUGIN_BRO_BUILD}/src | |
62 | ${BRO_PLUGIN_BRO_BUILD}/aux/binpac/lib | |
63 | ${BRO_PLUGIN_BRO_BUILD}/aux/broker | |
64 | ${bro_cache_CAF_INCLUDE_DIR_CORE} | |
65 | ${bro_cache_CAF_INCLUDE_DIR_IO} | |
66 | ${bro_cache_CAF_INCLUDE_DIR_OPENSSL} | |
67 | ${CMAKE_CURRENT_BINARY_DIR} | |
68 | ${CMAKE_CURRENT_BINARY_DIR}/src | |
69 | ${CMAKE_CURRENT_SOURCE_DIR} | |
70 | ${CMAKE_CURRENT_SOURCE_DIR}/src | |
71 | ) | |
72 | ||
73 | set(ENV{PATH} "${BRO_PLUGIN_BRO_BUILD}/build/src:$ENV{PATH}") | |
74 | ||
75 | else () | |
76 | # Independent from BRO_DIST source tree | |
77 | ||
78 | if ( NOT BRO_CONFIG_CMAKE_DIR ) | |
79 | message(FATAL_ERROR "CMake var. BRO_CONFIG_CMAKE_DIR must be set" | |
80 | " to the path where Bro installed its cmake modules") | |
81 | endif () | |
82 | ||
83 | include(${BRO_CONFIG_CMAKE_DIR}/CommonCMakeConfig.cmake) | |
84 | ||
85 | if ( NOT BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH ) | |
86 | if ( NOT BRO_CONFIG_PLUGIN_DIR ) | |
87 | message(FATAL_ERROR "CMake var. BRO_CONFIG_PLUGIN_DIR must be" | |
88 | " set to the path where Bro installs its plugins") | |
89 | endif () | |
90 | ||
91 | set(BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH | |
92 | "${BRO_CONFIG_PLUGIN_DIR}" CACHE INTERNAL "" FORCE) | |
93 | endif () | |
94 | ||
95 | if ( NOT BRO_CONFIG_PREFIX ) | |
96 | message(FATAL_ERROR "CMake var. BRO_CONFIG_PREFIX must be set" | |
97 | " to the root installation path of Bro") | |
98 | endif () | |
99 | ||
100 | if ( NOT BRO_CONFIG_INCLUDE_DIR ) | |
101 | message(FATAL_ERROR "CMake var. BRO_CONFIG_INCLUDE_DIR must be set" | |
102 | " to the installation path of Bro headers") | |
103 | endif () | |
104 | ||
105 | set(BRO_PLUGIN_BRO_CONFIG_INCLUDE_DIR "${BRO_CONFIG_INCLUDE_DIR}" | |
106 | CACHE INTERNAL "" FORCE) | |
107 | set(BRO_PLUGIN_BRO_INSTALL_PREFIX "${BRO_CONFIG_PREFIX}" | |
108 | CACHE INTERNAL "" FORCE) | |
109 | set(BRO_PLUGIN_BRO_EXE_PATH "${BRO_CONFIG_PREFIX}/bin/bro" | |
110 | CACHE INTERNAL "" FORCE) | |
111 | ||
112 | set(BRO_PLUGIN_BRO_CMAKE ${BRO_CONFIG_CMAKE_DIR}) | |
113 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) | |
114 | set(CMAKE_MODULE_PATH ${BRO_PLUGIN_BRO_CMAKE} ${CMAKE_MODULE_PATH}) | |
115 | ||
116 | find_package(BinPAC REQUIRED) | |
117 | find_package(CAF COMPONENTS core io openssl REQUIRED) | |
118 | find_package(Broker REQUIRED) | |
119 | ||
120 | include_directories(BEFORE | |
121 | ${BRO_CONFIG_INCLUDE_DIR} | |
122 | ${BinPAC_INCLUDE_DIR} | |
123 | ${BROKER_INCLUDE_DIR} | |
124 | ${CAF_INCLUDE_DIR_CORE} | |
125 | ${CAF_INCLUDE_DIR_IO} | |
126 | ${CAF_INCLUDE_DIR_OPENSSL} | |
127 | ${CMAKE_CURRENT_BINARY_DIR} | |
128 | ${CMAKE_CURRENT_BINARY_DIR}/src | |
129 | ${CMAKE_CURRENT_SOURCE_DIR} | |
130 | ${CMAKE_CURRENT_SOURCE_DIR}/src | |
131 | ) | |
132 | endif () | |
133 | ||
134 | if ( NOT BRO_PLUGIN_BASE ) | |
135 | set(BRO_PLUGIN_BASE "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "" FORCE) | |
136 | endif () | |
137 | ||
138 | set(BRO_PLUGIN_SCRIPTS "${CMAKE_CURRENT_BINARY_DIR}/scripts" CACHE INTERNAL "" FORCE) | |
139 | set(BRO_PLUGIN_SCRIPTS_SRC "${BRO_PLUGIN_BASE}/scripts" CACHE INTERNAL "" FORCE) | |
140 | set(BRO_PLUGIN_BUILD "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "" FORCE) | |
141 | set(BRO_PLUGIN_LIB "${BRO_PLUGIN_BUILD}/lib" CACHE INTERNAL "" FORCE) | |
142 | set(BRO_PLUGIN_BIF "${BRO_PLUGIN_LIB}/bif" CACHE INTERNAL "" FORCE) | |
143 | set(BRO_PLUGIN_MAGIC "${BRO_PLUGIN_BUILD}/__bro_plugin__" CACHE INTERNAL "" FORCE) | |
144 | set(BRO_PLUGIN_README "${BRO_PLUGIN_BASE}/README" CACHE INTERNAL "" FORCE) | |
145 | ||
146 | set(BRO_PLUGIN_INTERNAL_BUILD false CACHE INTERNAL "" FORCE) | |
147 | set(BRO_PLUGIN_BUILD_DYNAMIC true CACHE INTERNAL "" FORCE) | |
148 | ||
149 | message(STATUS "Bro executable : ${BRO_PLUGIN_BRO_EXE_PATH}") | |
150 | message(STATUS "Bro source : ${BRO_PLUGIN_BRO_SRC}") | |
151 | message(STATUS "Bro build : ${BRO_PLUGIN_BRO_BUILD}") | |
152 | message(STATUS "Bro install prefix : ${BRO_PLUGIN_BRO_INSTALL_PREFIX}") | |
153 | message(STATUS "Bro plugin directory: ${BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH}") | |
154 | message(STATUS "Bro debug mode : ${BRO_PLUGIN_ENABLE_DEBUG}") | |
155 | ||
156 | if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") | |
157 | # By default Darwin's linker requires all symbols to be present at link time. | |
158 | set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -undefined dynamic_lookup -Wl,-bind_at_load") | |
159 | endif () | |
160 | ||
161 | set(bro_PLUGIN_LIBS CACHE INTERNAL "plugin libraries" FORCE) | |
162 | set(bro_PLUGIN_BIF_SCRIPTS CACHE INTERNAL "Bro script stubs for BIFs in Bro plugins" FORCE) | |
163 | ||
164 | add_definitions(-DBRO_PLUGIN_INTERNAL_BUILD=false) | |
165 | ||
166 | add_custom_target(generate_outputs) | |
167 | ||
168 | if ( BRO_PLUGIN_ENABLE_DEBUG ) | |
169 | set(ENABLE_DEBUG true) | |
170 | set(CMAKE_BUILD_TYPE Debug) | |
171 | endif () | |
172 | ||
173 | include(SetDefaultCompileFlags) | |
174 | ||
175 | else () | |
176 | set(BRO_PLUGIN_BASE "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "" FORCE) | |
177 | set(BRO_PLUGIN_LIB "${CMAKE_CURRENT_BINARY_DIR}/lib" CACHE INTERNAL "" FORCE) | |
178 | set(BRO_PLUGIN_BIF "${BRO_PLUGIN_LIB}/bif" CACHE INTERNAL "" FORCE) | |
179 | set(BRO_PLUGIN_MAGIC "${BRO_PLUGIN_BASE}/__bro_plugin__" CACHE INTERNAL "" FORCE) | |
180 | set(BRO_PLUGIN_README "${BRO_PLUGIN_BASE}/README" CACHE INTERNAL "" FORCE) | |
181 | set(BRO_PLUGIN_SCRIPTS "${BRO_PLUGIN_BASE}/scripts" CACHE INTERNAL "" FORCE) | |
182 | set(BRO_PLUGIN_SCRIPTS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/scripts" CACHE INTERNAL "" FORCE) | |
183 | endif () | |
184 | ||
185 | include(GetArchitecture) | |
186 | ||
187 | function(bro_plugin_bif_dynamic) | |
188 | foreach ( bif ${ARGV} ) | |
189 | bif_target(${bif} "plugin" ${_plugin_name} ${_plugin_name_canon} FALSE) | |
190 | list(APPEND _plugin_objs ${BIF_OUTPUT_CC}) | |
191 | list(APPEND _plugin_deps ${BIF_BUILD_TARGET}) | |
192 | set(_plugin_objs "${_plugin_objs}" PARENT_SCOPE) | |
193 | set(_plugin_deps "${_plugin_deps}" PARENT_SCOPE) | |
194 | endforeach () | |
195 | endfunction() | |
196 | ||
197 | function(bro_plugin_link_library_dynamic) | |
198 | foreach ( lib ${ARGV} ) | |
199 | set(_plugin_libs ${_plugin_libs} ${lib} CACHE INTERNAL "dynamic plugin libraries") | |
200 | endforeach () | |
201 | endfunction() | |
202 | ||
203 | function(bro_plugin_end_dynamic) | |
204 | # Create the dynamic library/bundle. | |
205 | add_library(${_plugin_lib} MODULE ${_plugin_objs}) | |
206 | set_target_properties(${_plugin_lib} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${BRO_PLUGIN_LIB}") | |
207 | set_target_properties(${_plugin_lib} PROPERTIES PREFIX "") | |
208 | # set_target_properties(${_plugin_lib} PROPERTIES ENABLE_EXPORTS TRUE) | |
209 | ||
210 | add_dependencies(${_plugin_lib} generate_outputs) | |
211 | ||
212 | if ( _plugin_deps ) | |
213 | add_dependencies(${_plugin_lib} ${_plugin_deps}) | |
214 | endif() | |
215 | ||
216 | target_link_libraries(${_plugin_lib} ${_plugin_libs}) | |
217 | ||
218 | # Create bif/__init__.bro. | |
219 | bro_bif_create_loader(bif-init-${_plugin_name_canon} "${bro_PLUGIN_BIF_SCRIPTS}") | |
220 | ||
221 | # Copy scripts/ if it's not already at the right place inside the | |
222 | # plugin directory. (Actually, we create a symbolic link rather | |
223 | # than copy so that edits to the scripts show up immediately.) | |
224 | if ( NOT "${BRO_PLUGIN_SCRIPTS_SRC}" STREQUAL "${BRO_PLUGIN_SCRIPTS}" ) | |
225 | add_custom_target(copy-scripts-${_plugin_name_canon} | |
226 | # COMMAND "${CMAKE_COMMAND}" -E remove_directory ${BRO_PLUGIN_SCRIPTS} | |
227 | # COMMAND "${CMAKE_COMMAND}" -E copy_directory ${BRO_PLUGIN_SCRIPTS_SRC} ${BRO_PLUGIN_SCRIPTS}) | |
228 | COMMAND test -d ${BRO_PLUGIN_SCRIPTS_SRC} && rm -f ${BRO_PLUGIN_SCRIPTS} && ln -s ${BRO_PLUGIN_SCRIPTS_SRC} ${BRO_PLUGIN_SCRIPTS} || true) | |
229 | add_dependencies(${_plugin_lib} copy-scripts-${_plugin_name_canon}) | |
230 | endif() | |
231 | ||
232 | if ( _plugin_deps ) | |
233 | add_dependencies(bif-init-${_plugin_name_canon} ${_plugin_deps}) | |
234 | add_dependencies(${_plugin_lib} bif-init-${_plugin_name_canon}) | |
235 | endif() | |
236 | ||
237 | # Create __bro_plugin__ | |
238 | # string(REPLACE "${BRO_PLUGIN_BASE}/" "" msg "Creating ${BRO_PLUGIN_MAGIC} for ${_plugin_name}") | |
239 | get_filename_component(_magic_basename ${BRO_PLUGIN_MAGIC} NAME) | |
240 | ||
241 | add_custom_target(bro-plugin-${_plugin_name_canon} | |
242 | COMMAND echo "${_plugin_name}" ">${BRO_PLUGIN_MAGIC}" | |
243 | COMMENT "Creating ${_magic_basename} for ${_plugin_name}") | |
244 | ||
245 | if ( _plugin_deps ) | |
246 | add_dependencies(bro-plugin-${_plugin_name_canon} ${_plugin_deps}) | |
247 | endif() | |
248 | ||
249 | add_dependencies(${_plugin_lib} bro-plugin-${_plugin_name_canon}) | |
250 | ||
251 | set(_dist_tarball_name ${_plugin_name_canon}.tar.gz) | |
252 | set(_dist_output ${CMAKE_CURRENT_BINARY_DIR}/${_dist_tarball_name}) | |
253 | ||
254 | # Create binary install package. | |
255 | add_custom_command(OUTPUT ${_dist_output} | |
256 | COMMAND ${BRO_PLUGIN_BRO_CMAKE}/bro-plugin-create-package.sh ${_plugin_name_canon} ${_plugin_dist} | |
257 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | |
258 | DEPENDS ${_plugin_lib} | |
259 | COMMENT "Building binary plugin package: ${_dist_tarball_name}") | |
260 | ||
261 | add_custom_target(dist ALL DEPENDS ${_dist_output}) | |
262 | ||
263 | set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${BRO_PLUGIN_BIF}) | |
264 | set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${BRO_PLUGIN_LIB}) | |
265 | set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${BRO_PLUGIN_MAGIC}) | |
266 | ||
267 | ### Plugin installation. | |
268 | ||
269 | set(plugin_install "${BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH}/${_plugin_name_canon}") | |
270 | ||
271 | INSTALL(CODE "execute_process( | |
272 | COMMAND ${BRO_PLUGIN_BRO_CMAKE}/bro-plugin-install-package.sh ${_plugin_name_canon} \$ENV{DESTDIR}/${BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH} | |
273 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | |
274 | )") | |
275 | ||
276 | ||
277 | endfunction() | |
278 | ||
279 | macro(_plugin_target_name_dynamic target ns name) | |
280 | set(${target} "${ns}-${name}.${HOST_ARCHITECTURE}") | |
281 | endmacro() | |
282 |
0 | ## A set of functions for defining Bro plugins. | |
1 | ## | |
2 | ## This set is for plugins compiled in statically. | |
3 | ## See BroPluginsDynamic.cmake for the dynamic version. | |
4 | ||
5 | function(bro_plugin_bif_static) | |
6 | foreach ( bif ${ARGV} ) | |
7 | bif_target(${bif} "plugin" ${_plugin_name} ${_plugin_name_canon} TRUE) | |
8 | list(APPEND _plugin_objs ${BIF_OUTPUT_CC}) | |
9 | list(APPEND _plugin_deps ${BIF_BUILD_TARGET}) | |
10 | set(_plugin_objs "${_plugin_objs}" PARENT_SCOPE) | |
11 | set(_plugin_deps "${_plugin_deps}" PARENT_SCOPE) | |
12 | endforeach () | |
13 | endfunction() | |
14 | ||
15 | function(bro_plugin_link_library_static) | |
16 | foreach ( lib ${ARGV} ) | |
17 | set(bro_SUBDIR_LIBS ${bro_SUBDIR_LIBS} "${lib}" CACHE INTERNAL "plugin libraries") | |
18 | endforeach () | |
19 | endfunction() | |
20 | ||
21 | function(bro_plugin_end_static) | |
22 | if ( bro_HAVE_OBJECT_LIBRARIES ) | |
23 | add_library(${_plugin_lib} OBJECT ${_plugin_objs}) | |
24 | set(_target "$<TARGET_OBJECTS:${_plugin_lib}>") | |
25 | else () | |
26 | add_library(${_plugin_lib} STATIC ${_plugin_objs}) | |
27 | set(_target "${_plugin_lib}") | |
28 | endif () | |
29 | ||
30 | if ( NOT "${_plugin_deps}" STREQUAL "" ) | |
31 | add_dependencies(${_plugin_lib} ${_plugin_deps}) | |
32 | endif () | |
33 | ||
34 | add_dependencies(${_plugin_lib} generate_outputs) | |
35 | ||
36 | set(bro_PLUGIN_LIBS ${bro_PLUGIN_LIBS} "${_target}" CACHE INTERNAL "plugin libraries") | |
37 | endfunction() | |
38 | ||
39 | macro(_plugin_target_name_static target ns name) | |
40 | set(${target} "plugin-${ns}-${name}") | |
41 | endmacro() | |
42 |
0 | ||
1 | # Creates a target for a library of objects file in a subdirectory, | |
2 | # and adds to the global bro_SUBDIR_LIBS. | |
3 | function(bro_add_subdir_library name) | |
4 | if ( bro_HAVE_OBJECT_LIBRARIES ) | |
5 | add_library("bro_${name}" OBJECT ${ARGN}) | |
6 | set(_target "$<TARGET_OBJECTS:bro_${name}>") | |
7 | else () | |
8 | add_library("bro_${name}" STATIC ${ARGN}) | |
9 | set(_target "bro_${name}") | |
10 | endif () | |
11 | ||
12 | set(bro_SUBDIR_LIBS "${_target}" ${bro_SUBDIR_LIBS} CACHE INTERNAL "subdir libraries") | |
13 | endfunction() |
5 | 5 | check_function_exists(strerror HAVE_STRERROR) |
6 | 6 | check_function_exists(strsep HAVE_STRSEP) |
7 | 7 | check_function_exists(sigset HAVE_SIGSET) |
8 | check_function_exists(sigaction HAVE_SIGACTION) | |
8 | ||
9 | if (HAVE_SIGSET) | |
10 | set(SIG_FUNC sigset) | |
11 | else () | |
12 | set(SIG_FUNC signal) | |
13 | check_function_exists(sigaction HAVE_SIGACTION) | |
14 | endif () |
122 | 122 | endif () |
123 | 123 | |
124 | 124 | if ( NOT CPACK_PACKAGE_CONTACT ) |
125 | set(CPACK_PACKAGE_CONTACT "info@zeek.org") | |
125 | set(CPACK_PACKAGE_CONTACT "info@bro.org") | |
126 | 126 | endif () |
127 | 127 | |
128 | 128 | if ( NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY ) |
129 | 129 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY |
130 | "The Zeek Network Security Monitor") | |
130 | "The Bro Network Intrusion Detection System") | |
131 | 131 | endif () |
132 | 132 | |
133 | 133 | # CPack may enforce file name extensions for certain package generators |
140 | 140 | ${CMAKE_CURRENT_BINARY_DIR}/COPYING.txt |
141 | 141 | COPYONLY) |
142 | 142 | elseif ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/COPYING.edit-me ) |
143 | # Zeek plugin skeletons have a placeholder file. Just use | |
143 | # Bro plugin skeletons have a placeholder file. Just use | |
144 | 144 | # it even if it hasn't actually been changed. |
145 | 145 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/COPYING.edit-me |
146 | 146 | ${CMAKE_CURRENT_BINARY_DIR}/COPYING.txt |
87 | 87 | IF(NOT ${BISON_version_result} EQUAL 0) |
88 | 88 | MESSAGE(SEND_ERROR "Command \"${BISON_EXECUTABLE} --version\" failed with output:\n${BISON_version_error}") |
89 | 89 | ELSE() |
90 | STRING(REGEX REPLACE "^bison \\(GNU [bB]ison\\) ([^\n]+)\n.*" "\\1" | |
90 | STRING(REGEX REPLACE "^bison \\(GNU Bison\\) ([^\n]+)\n.*" "\\1" | |
91 | 91 | BISON_VERSION "${BISON_version_output}") |
92 | 92 | ENDIF() |
93 | 93 |
28 | 28 | ) |
29 | 29 | |
30 | 30 | find_library(BinPAC_LIBRARY |
31 | NAMES binpac libbinpac.a | |
31 | NAMES libbinpac.a | |
32 | 32 | HINTS ${BinPAC_ROOT_DIR}/lib |
33 | 33 | ) |
34 | 34 |
0 | # - Try to find Bro installation | |
1 | # | |
2 | # Usage of this module as follows: | |
3 | # | |
4 | # find_package(Bro) | |
5 | # | |
6 | # Variables used by this module, they can change the default behaviour and need | |
7 | # to be set before calling find_package: | |
8 | # | |
9 | # BRO_ROOT_DIR Set this variable to the root installation of | |
10 | # Bro if the module has problems finding the | |
11 | # proper installation path. | |
12 | # | |
13 | # Variables defined by this module: | |
14 | # | |
15 | # BRO_FOUND Bro NIDS is installed | |
16 | # BRO_EXE path to the 'bro' binary | |
17 | ||
18 | if (BRO_EXE AND BRO_ROOT_DIR) | |
19 | # this implies that we're building from the Bro source tree | |
20 | set(BRO_FOUND true) | |
21 | return() | |
22 | endif () | |
23 | ||
24 | find_program(BRO_EXE bro | |
25 | HINTS ${BRO_ROOT_DIR}/bin /usr/local/bro/bin) | |
26 | ||
27 | if (BRO_EXE) | |
28 | get_filename_component(BRO_ROOT_DIR ${BRO_EXE} PATH) | |
29 | get_filename_component(BRO_ROOT_DIR ${BRO_ROOT_DIR} PATH) | |
30 | endif () | |
31 | ||
32 | include(FindPackageHandleStandardArgs) | |
33 | find_package_handle_standard_args(Bro DEFAULT_MSG BRO_EXE) | |
34 | ||
35 | mark_as_advanced(BRO_ROOT_DIR) |
0 | # - Try to find FTS library and headers | |
1 | # | |
2 | # Usage of this module as follows: | |
3 | # | |
4 | # find_package(FTS) | |
5 | # | |
6 | # Variables used by this module, they can change the default behaviour and need | |
7 | # to be set before calling find_package: | |
8 | # | |
9 | # FTS_ROOT_DIR Set this variable to the root installation of | |
10 | # FTS if the module has problems finding the | |
11 | # proper installation path. | |
12 | # | |
13 | # Variables defined by this module: | |
14 | # | |
15 | # FTS_FOUND System has FTS library | |
16 | # FTS_LIBRARY The FTS library | |
17 | # FTS_INCLUDE_DIR The FTS headers | |
18 | ||
19 | find_path(FTS_ROOT_DIR | |
20 | NAMES include/fts.h | |
21 | ) | |
22 | ||
23 | find_library(FTS_LIBRARY | |
24 | NAMES fts | |
25 | HINTS ${FTS_ROOT_DIR}/lib | |
26 | ) | |
27 | ||
28 | find_path(FTS_INCLUDE_DIR | |
29 | NAMES fts.h | |
30 | HINTS ${FTS_ROOT_DIR}/include | |
31 | ) | |
32 | ||
33 | include(FindPackageHandleStandardArgs) | |
34 | find_package_handle_standard_args(FTS DEFAULT_MSG | |
35 | FTS_LIBRARY | |
36 | FTS_INCLUDE_DIR | |
37 | ) | |
38 | ||
39 | mark_as_advanced( | |
40 | FTS_ROOT_DIR | |
41 | FTS_LIBRARY | |
42 | FTS_INCLUDE_DIR | |
43 | ) |
39 | 39 | # (e.g. some systems may have a "python" symlink, but not a "python-config" |
40 | 40 | # symlink). |
41 | 41 | get_filename_component(PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE}" REALPATH) |
42 | get_filename_component(PYTHON_EXECUTABLE_DIR "${PYTHON_EXECUTABLE}" DIRECTORY) | |
42 | endif () | |
43 | 43 | |
44 | if ( EXISTS ${PYTHON_EXECUTABLE}-config ) | |
45 | set(PYTHON_CONFIG ${PYTHON_EXECUTABLE}-config CACHE PATH "" FORCE) | |
46 | elseif ( EXISTS ${PYTHON_EXECUTABLE_DIR}/python-config ) | |
47 | set(PYTHON_CONFIG ${PYTHON_EXECUTABLE_DIR}/python-config CACHE PATH "" FORCE) | |
48 | endif () | |
44 | if (PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE}-config) | |
45 | set(PYTHON_CONFIG ${PYTHON_EXECUTABLE}-config CACHE PATH "" FORCE) | |
49 | 46 | else () |
50 | 47 | find_program(PYTHON_CONFIG |
51 | NAMES python-config python3.7-config python3.6-config python3.5-config | |
52 | python3.4-config python-config2.7 python-config2.6 python-config2.6 | |
48 | NAMES python-config python-config2.7 python-config2.6 python-config2.6 | |
53 | 49 | python-config2.4 python-config2.3) |
54 | 50 | endif () |
55 | 51 |
0 | # - Try to find Zeek installation | |
1 | # | |
2 | # Usage of this module as follows: | |
3 | # | |
4 | # find_package(Zeek) | |
5 | # | |
6 | # Variables used by this module, they can change the default behaviour and need | |
7 | # to be set before calling find_package: | |
8 | # | |
9 | # ZEEK_ROOT_DIR Set this variable to the root installation of | |
10 | # Zeek if the module has problems finding the | |
11 | # proper installation path. | |
12 | # | |
13 | # Variables defined by this module: | |
14 | # | |
15 | # BRO_FOUND Zeek is installed | |
16 | # ZEEK_EXE path to the 'zeek' binary | |
17 | ||
18 | if (ZEEK_EXE AND ZEEK_ROOT_DIR) | |
19 | # this implies that we're building from the Zeek source tree | |
20 | set(BRO_FOUND true) | |
21 | return() | |
22 | endif () | |
23 | ||
24 | find_program(ZEEK_EXE zeek | |
25 | HINTS ${ZEEK_ROOT_DIR}/bin /usr/local/zeek/bin /usr/local/bro/bin) | |
26 | ||
27 | if (ZEEK_EXE) | |
28 | get_filename_component(ZEEK_ROOT_DIR ${ZEEK_EXE} PATH) | |
29 | get_filename_component(ZEEK_ROOT_DIR ${ZEEK_ROOT_DIR} PATH) | |
30 | endif () | |
31 | ||
32 | include(FindPackageHandleStandardArgs) | |
33 | find_package_handle_standard_args(Zeek DEFAULT_MSG ZEEK_EXE) | |
34 | ||
35 | mark_as_advanced(ZEEK_ROOT_DIR) |
0 | 0 | This is a collection of CMake scripts intended to be included as a |
1 | git submodule in other repositories related to Zeek (www.zeek.org). | |
1 | git submodule in other repositories related to Bro (www.bro.org). |
3 | 3 | if (NOT BINARY_PACKAGING_MODE) |
4 | 4 | SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) |
5 | 5 | SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") |
6 | ||
7 | include(GNUInstallDirs) | |
8 | ||
9 | if ( NOT CMAKE_INSTALL_LIBDIR STREQUAL "lib" ) | |
10 | # Ideally, we'd consistently use just one lib dir (e.g. lib/ or lib64/), | |
11 | # which requires every sub-project and external/embedded dependency | |
12 | # agrees and/or offers ability to install at that canonical location. | |
13 | set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") | |
14 | endif () | |
15 | 6 | endif () |
0 | ||
1 | # Wrapper include file that loads the macros for building a Zeek | |
2 | # plugin either statically or dynamically, depending on whether | |
3 | # we're building as part of the main Zeek source tree, or externally. | |
4 | ||
5 | if ( ZEEK_PLUGIN_INTERNAL_BUILD ) | |
6 | if ( "${ZEEK_PLUGIN_BUILD_DYNAMIC}" STREQUAL "" ) | |
7 | set(ZEEK_PLUGIN_BUILD_DYNAMIC FALSE) | |
8 | endif() | |
9 | else () | |
10 | set(ZEEK_PLUGIN_BUILD_DYNAMIC TRUE) | |
11 | endif () | |
12 | ||
13 | include(ZeekPluginCommon) | |
14 | include(ZeekPluginStatic) | |
15 | include(ZeekPluginDynamic) | |
16 |
0 | ## A set of functions for defining Zeek plugins. | |
1 | ## | |
2 | ## This set is used by both static and dynamic plugins via | |
3 | ## ZeekPluginStatic and ZeekPluginDynamic, respectively. | |
4 | ||
5 | include(RequireCXX11) | |
6 | ||
7 | include(BifCl) | |
8 | include(BinPAC) | |
9 | ||
10 | # Begins a plugin definition, giving its namespace and name as the arguments. | |
11 | function(zeek_plugin_begin ns name) | |
12 | _plugin_target_name(target "${ns}" "${name}") | |
13 | set(_plugin_lib "${target}" PARENT_SCOPE) | |
14 | set(_plugin_name "${ns}::${name}" PARENT_SCOPE) | |
15 | set(_plugin_name_canon "${ns}_${name}" PARENT_SCOPE) | |
16 | set(_plugin_ns "${ns}" PARENT_SCOPE) | |
17 | set(_plugin_objs "" PARENT_SCOPE) | |
18 | set(_plugin_deps "" PARENT_SCOPE) | |
19 | set(_plugin_dist "" PARENT_SCOPE) | |
20 | endfunction() | |
21 | ||
22 | # This is needed to support legacy Bro plugins. | |
23 | macro(bro_plugin_begin) | |
24 | zeek_plugin_begin(${ARGV}) | |
25 | endmacro() | |
26 | ||
27 | # Adds *.cc files to a plugin. | |
28 | function(zeek_plugin_cc) | |
29 | list(APPEND _plugin_objs ${ARGV}) | |
30 | set(_plugin_objs "${_plugin_objs}" PARENT_SCOPE) | |
31 | endfunction() | |
32 | ||
33 | # This is needed to support legacy Bro plugins. | |
34 | macro(bro_plugin_cc) | |
35 | zeek_plugin_cc(${ARGV}) | |
36 | endmacro() | |
37 | ||
38 | # Adds a *.pac file to a plugin. Further *.pac files may given that | |
39 | # it depends on. | |
40 | function(zeek_plugin_pac) | |
41 | binpac_target(${ARGV}) | |
42 | list(APPEND _plugin_objs ${BINPAC_OUTPUT_CC}) | |
43 | list(APPEND _plugin_deps ${BINPAC_BUILD_TARGET}) | |
44 | set(_plugin_objs "${_plugin_objs}" PARENT_SCOPE) | |
45 | set(_plugin_deps "${_plugin_deps}" PARENT_SCOPE) | |
46 | endfunction() | |
47 | ||
48 | # This is needed to support legacy Bro plugins. | |
49 | macro(bro_plugin_pac) | |
50 | zeek_plugin_pac(${ARGV}) | |
51 | endmacro() | |
52 | ||
53 | # Add an additional object file to the plugin's library. | |
54 | function(zeek_plugin_obj) | |
55 | foreach ( bif ${ARGV} ) | |
56 | list(APPEND _plugin_objs ${bif}) | |
57 | set(_plugin_objs "${_plugin_objs}" PARENT_SCOPE) | |
58 | endforeach () | |
59 | endfunction() | |
60 | ||
61 | # This is needed to support legacy Bro plugins. | |
62 | macro(bro_plugin_obj) | |
63 | zeek_plugin_obj(${ARGV}) | |
64 | endmacro() | |
65 | ||
66 | # Add additional files that should be included into the binary plugin distribution. | |
67 | # Ignored for static plugins. | |
68 | macro(zeek_plugin_dist_files) | |
69 | foreach ( file ${ARGV} ) | |
70 | list(APPEND _plugin_dist ${file}) | |
71 | # Don't need this here, and generates an error that | |
72 | # there is not parent scope. Not sure why it does that | |
73 | # here but not for other macros doing something similar. | |
74 | # set(_plugin_dist "${_plugin_dist}" PARENT_SCOPE) | |
75 | endforeach () | |
76 | endmacro() | |
77 | ||
78 | # This is needed to support legacy Bro plugins. | |
79 | macro(bro_plugin_dist_files) | |
80 | zeek_plugin_dist_files(${ARGV}) | |
81 | endmacro() | |
82 | ||
83 | # Link an additional library to the plugin's library. | |
84 | function(zeek_plugin_link_library) | |
85 | if ( ZEEK_PLUGIN_BUILD_DYNAMIC ) | |
86 | bro_plugin_link_library_dynamic(${ARGV}) | |
87 | else () | |
88 | bro_plugin_link_library_static(${ARGV}) | |
89 | endif () | |
90 | endfunction() | |
91 | ||
92 | # This is needed to support legacy Bro plugins. | |
93 | macro(bro_plugin_link_library) | |
94 | zeek_plugin_link_library(${ARGV}) | |
95 | endmacro() | |
96 | ||
97 | # Adds *.bif files to a plugin. | |
98 | macro(zeek_plugin_bif) | |
99 | if ( ZEEK_PLUGIN_BUILD_DYNAMIC ) | |
100 | bro_plugin_bif_dynamic(${ARGV}) | |
101 | else () | |
102 | bro_plugin_bif_static(${ARGV}) | |
103 | endif () | |
104 | endmacro() | |
105 | ||
106 | # This is needed to support legacy Bro plugins. | |
107 | macro(bro_plugin_bif) | |
108 | zeek_plugin_bif(${ARGV}) | |
109 | endmacro() | |
110 | ||
111 | # Ends a plugin definition. | |
112 | macro(zeek_plugin_end) | |
113 | if ( ZEEK_PLUGIN_BUILD_DYNAMIC ) | |
114 | bro_plugin_end_dynamic(${ARGV}) | |
115 | else () | |
116 | bro_plugin_end_static(${ARGV}) | |
117 | endif () | |
118 | endmacro() | |
119 | ||
120 | # This is needed to support legacy Bro plugins. | |
121 | macro(bro_plugin_end) | |
122 | zeek_plugin_end(${ARGV}) | |
123 | endmacro() | |
124 | ||
125 | # Internal macro to create a unique target name for a plugin. | |
126 | macro(_plugin_target_name target ns name) | |
127 | if ( ZEEK_PLUGIN_BUILD_DYNAMIC ) | |
128 | _plugin_target_name_dynamic(${ARGV}) | |
129 | else () | |
130 | _plugin_target_name_static(${ARGV}) | |
131 | endif () | |
132 | endmacro() | |
133 |
0 | ## A set of functions for defining Zeek plugins. | |
1 | ## | |
2 | ## This set is for plugins compiled dynamically for loading at run-time. | |
3 | ## See ZeekPluginStatic.cmake for the static version. | |
4 | ## | |
5 | ## Note: This is meant to run as a standalone CMakeLists.txt. It sets | |
6 | ## up all the basic infrastructure to compile a dynamic Zeek plugin when | |
7 | ## included from its top-level CMake file. | |
8 | ||
9 | if ( NOT ZEEK_PLUGIN_INTERNAL_BUILD ) | |
10 | set(BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH "${BRO_PLUGIN_INSTALL_ROOT}" | |
11 | CACHE INTERNAL "" FORCE) | |
12 | ||
13 | if ( BRO_DIST ) | |
14 | include(${BRO_DIST}/cmake/CommonCMakeConfig.cmake) | |
15 | ||
16 | if ( NOT EXISTS "${BRO_DIST}/build/CMakeCache.txt" ) | |
17 | message(FATAL_ERROR | |
18 | "${BRO_DIST}/build/CMakeCache.txt; has Zeek been built?") | |
19 | endif () | |
20 | ||
21 | load_cache("${BRO_DIST}/build" READ_WITH_PREFIX bro_cache_ | |
22 | CMAKE_INSTALL_PREFIX | |
23 | Zeek_BINARY_DIR | |
24 | Zeek_SOURCE_DIR | |
25 | ENABLE_DEBUG | |
26 | BRO_PLUGIN_INSTALL_PATH | |
27 | ZEEK_EXE_PATH | |
28 | CMAKE_CXX_FLAGS | |
29 | CMAKE_C_FLAGS | |
30 | CAF_INCLUDE_DIR_CORE | |
31 | CAF_INCLUDE_DIR_IO | |
32 | CAF_INCLUDE_DIR_OPENSSL) | |
33 | ||
34 | if ( NOT BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH ) | |
35 | set(BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH | |
36 | "${bro_cache_BRO_PLUGIN_INSTALL_PATH}" CACHE INTERNAL "" FORCE) | |
37 | endif () | |
38 | ||
39 | set(BRO_PLUGIN_BRO_INSTALL_PREFIX "${bro_cache_CMAKE_INSTALL_PREFIX}" | |
40 | CACHE INTERNAL "" FORCE) | |
41 | set(BRO_PLUGIN_ENABLE_DEBUG "${bro_cache_ENABLE_DEBUG}" | |
42 | CACHE INTERNAL "" FORCE) | |
43 | set(BRO_PLUGIN_BRO_SRC "${bro_cache_Zeek_SOURCE_DIR}" | |
44 | CACHE INTERNAL "" FORCE) | |
45 | set(BRO_PLUGIN_BRO_BUILD "${bro_cache_Zeek_BINARY_DIR}" | |
46 | CACHE INTERNAL "" FORCE) | |
47 | set(BRO_PLUGIN_BRO_EXE_PATH "${bro_cache_ZEEK_EXE_PATH}" | |
48 | CACHE INTERNAL "" FORCE) | |
49 | ||
50 | set(BRO_PLUGIN_BRO_CMAKE ${BRO_PLUGIN_BRO_SRC}/cmake) | |
51 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) | |
52 | set(CMAKE_MODULE_PATH ${BRO_PLUGIN_BRO_CMAKE} ${CMAKE_MODULE_PATH}) | |
53 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${bro_cache_CMAKE_C_FLAGS}") | |
54 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${bro_cache_CMAKE_CXX_FLAGS}") | |
55 | ||
56 | include_directories(BEFORE | |
57 | ${BRO_PLUGIN_BRO_SRC}/src | |
58 | ${BRO_PLUGIN_BRO_SRC}/aux/binpac/lib | |
59 | ${BRO_PLUGIN_BRO_SRC}/aux/broker | |
60 | ${BRO_PLUGIN_BRO_BUILD} | |
61 | ${BRO_PLUGIN_BRO_BUILD}/src | |
62 | ${BRO_PLUGIN_BRO_BUILD}/aux/binpac/lib | |
63 | ${BRO_PLUGIN_BRO_BUILD}/aux/broker | |
64 | ${bro_cache_CAF_INCLUDE_DIR_CORE} | |
65 | ${bro_cache_CAF_INCLUDE_DIR_IO} | |
66 | ${bro_cache_CAF_INCLUDE_DIR_OPENSSL} | |
67 | ${CMAKE_CURRENT_BINARY_DIR} | |
68 | ${CMAKE_CURRENT_BINARY_DIR}/src | |
69 | ${CMAKE_CURRENT_SOURCE_DIR} | |
70 | ${CMAKE_CURRENT_SOURCE_DIR}/src | |
71 | ) | |
72 | ||
73 | set(ENV{PATH} "${BRO_PLUGIN_BRO_BUILD}/build/src:$ENV{PATH}") | |
74 | ||
75 | else () | |
76 | # Independent from BRO_DIST source tree | |
77 | ||
78 | if ( NOT BRO_CONFIG_CMAKE_DIR ) | |
79 | message(FATAL_ERROR "CMake var. BRO_CONFIG_CMAKE_DIR must be set" | |
80 | " to the path where Zeek installed its cmake modules") | |
81 | endif () | |
82 | ||
83 | include(${BRO_CONFIG_CMAKE_DIR}/CommonCMakeConfig.cmake) | |
84 | ||
85 | if ( NOT BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH ) | |
86 | if ( NOT BRO_CONFIG_PLUGIN_DIR ) | |
87 | message(FATAL_ERROR "CMake var. BRO_CONFIG_PLUGIN_DIR must be" | |
88 | " set to the path where Zeek installs its plugins") | |
89 | endif () | |
90 | ||
91 | set(BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH | |
92 | "${BRO_CONFIG_PLUGIN_DIR}" CACHE INTERNAL "" FORCE) | |
93 | endif () | |
94 | ||
95 | if ( NOT BRO_CONFIG_PREFIX ) | |
96 | message(FATAL_ERROR "CMake var. BRO_CONFIG_PREFIX must be set" | |
97 | " to the root installation path of Zeek") | |
98 | endif () | |
99 | ||
100 | if ( NOT BRO_CONFIG_INCLUDE_DIR ) | |
101 | message(FATAL_ERROR "CMake var. BRO_CONFIG_INCLUDE_DIR must be set" | |
102 | " to the installation path of Zeek headers") | |
103 | endif () | |
104 | ||
105 | set(BRO_PLUGIN_BRO_CONFIG_INCLUDE_DIR "${BRO_CONFIG_INCLUDE_DIR}" | |
106 | CACHE INTERNAL "" FORCE) | |
107 | set(BRO_PLUGIN_BRO_INSTALL_PREFIX "${BRO_CONFIG_PREFIX}" | |
108 | CACHE INTERNAL "" FORCE) | |
109 | set(BRO_PLUGIN_BRO_EXE_PATH "${BRO_CONFIG_PREFIX}/bin/zeek" | |
110 | CACHE INTERNAL "" FORCE) | |
111 | ||
112 | set(BRO_PLUGIN_BRO_CMAKE ${BRO_CONFIG_CMAKE_DIR}) | |
113 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) | |
114 | set(CMAKE_MODULE_PATH ${BRO_PLUGIN_BRO_CMAKE} ${CMAKE_MODULE_PATH}) | |
115 | ||
116 | find_package(BinPAC REQUIRED) | |
117 | find_package(CAF COMPONENTS core io openssl REQUIRED) | |
118 | find_package(Broker REQUIRED) | |
119 | ||
120 | include_directories(BEFORE | |
121 | ${BRO_CONFIG_INCLUDE_DIR} | |
122 | ${BinPAC_INCLUDE_DIR} | |
123 | ${BROKER_INCLUDE_DIR} | |
124 | ${CAF_INCLUDE_DIR_CORE} | |
125 | ${CAF_INCLUDE_DIR_IO} | |
126 | ${CAF_INCLUDE_DIR_OPENSSL} | |
127 | ${CMAKE_CURRENT_BINARY_DIR} | |
128 | ${CMAKE_CURRENT_BINARY_DIR}/src | |
129 | ${CMAKE_CURRENT_SOURCE_DIR} | |
130 | ${CMAKE_CURRENT_SOURCE_DIR}/src | |
131 | ) | |
132 | endif () | |
133 | ||
134 | if ( NOT BRO_PLUGIN_BASE ) | |
135 | set(BRO_PLUGIN_BASE "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "" FORCE) | |
136 | endif () | |
137 | ||
138 | set(BRO_PLUGIN_SCRIPTS "${CMAKE_CURRENT_BINARY_DIR}/scripts" CACHE INTERNAL "" FORCE) | |
139 | set(BRO_PLUGIN_SCRIPTS_SRC "${BRO_PLUGIN_BASE}/scripts" CACHE INTERNAL "" FORCE) | |
140 | set(BRO_PLUGIN_BUILD "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "" FORCE) | |
141 | set(BRO_PLUGIN_LIB "${BRO_PLUGIN_BUILD}/lib" CACHE INTERNAL "" FORCE) | |
142 | set(BRO_PLUGIN_BIF "${BRO_PLUGIN_LIB}/bif" CACHE INTERNAL "" FORCE) | |
143 | set(BRO_PLUGIN_MAGIC "${BRO_PLUGIN_BUILD}/__bro_plugin__" CACHE INTERNAL "" FORCE) | |
144 | set(BRO_PLUGIN_README "${BRO_PLUGIN_BASE}/README" CACHE INTERNAL "" FORCE) | |
145 | ||
146 | set(ZEEK_PLUGIN_INTERNAL_BUILD false CACHE INTERNAL "" FORCE) | |
147 | set(ZEEK_PLUGIN_BUILD_DYNAMIC true CACHE INTERNAL "" FORCE) | |
148 | ||
149 | message(STATUS "Zeek executable : ${BRO_PLUGIN_BRO_EXE_PATH}") | |
150 | message(STATUS "Zeek source : ${BRO_PLUGIN_BRO_SRC}") | |
151 | message(STATUS "Zeek build : ${BRO_PLUGIN_BRO_BUILD}") | |
152 | message(STATUS "Zeek install prefix : ${BRO_PLUGIN_BRO_INSTALL_PREFIX}") | |
153 | message(STATUS "Zeek plugin directory: ${BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH}") | |
154 | message(STATUS "Zeek debug mode : ${BRO_PLUGIN_ENABLE_DEBUG}") | |
155 | ||
156 | if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") | |
157 | # By default Darwin's linker requires all symbols to be present at link time. | |
158 | set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -undefined dynamic_lookup -Wl,-bind_at_load") | |
159 | endif () | |
160 | ||
161 | set(bro_PLUGIN_LIBS CACHE INTERNAL "plugin libraries" FORCE) | |
162 | set(bro_PLUGIN_BIF_SCRIPTS CACHE INTERNAL "Zeek script stubs for BIFs in Zeek plugins" FORCE) | |
163 | ||
164 | add_definitions(-DZEEK_PLUGIN_INTERNAL_BUILD=false) | |
165 | ||
166 | add_custom_target(generate_outputs) | |
167 | ||
168 | if ( BRO_PLUGIN_ENABLE_DEBUG ) | |
169 | set(ENABLE_DEBUG true) | |
170 | set(CMAKE_BUILD_TYPE Debug) | |
171 | endif () | |
172 | ||
173 | include(SetDefaultCompileFlags) | |
174 | ||
175 | else () | |
176 | set(BRO_PLUGIN_BASE "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "" FORCE) | |
177 | set(BRO_PLUGIN_LIB "${CMAKE_CURRENT_BINARY_DIR}/lib" CACHE INTERNAL "" FORCE) | |
178 | set(BRO_PLUGIN_BIF "${BRO_PLUGIN_LIB}/bif" CACHE INTERNAL "" FORCE) | |
179 | set(BRO_PLUGIN_MAGIC "${BRO_PLUGIN_BASE}/__bro_plugin__" CACHE INTERNAL "" FORCE) | |
180 | set(BRO_PLUGIN_README "${BRO_PLUGIN_BASE}/README" CACHE INTERNAL "" FORCE) | |
181 | set(BRO_PLUGIN_SCRIPTS "${BRO_PLUGIN_BASE}/scripts" CACHE INTERNAL "" FORCE) | |
182 | set(BRO_PLUGIN_SCRIPTS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/scripts" CACHE INTERNAL "" FORCE) | |
183 | endif () | |
184 | ||
185 | include(GetArchitecture) | |
186 | ||
187 | function(bro_plugin_bif_dynamic) | |
188 | foreach ( bif ${ARGV} ) | |
189 | bif_target(${bif} "plugin" ${_plugin_name} ${_plugin_name_canon} FALSE) | |
190 | list(APPEND _plugin_objs ${BIF_OUTPUT_CC}) | |
191 | list(APPEND _plugin_deps ${BIF_BUILD_TARGET}) | |
192 | set(_plugin_objs "${_plugin_objs}" PARENT_SCOPE) | |
193 | set(_plugin_deps "${_plugin_deps}" PARENT_SCOPE) | |
194 | endforeach () | |
195 | endfunction() | |
196 | ||
197 | function(bro_plugin_link_library_dynamic) | |
198 | foreach ( lib ${ARGV} ) | |
199 | set(_plugin_libs ${_plugin_libs} ${lib} CACHE INTERNAL "dynamic plugin libraries") | |
200 | endforeach () | |
201 | endfunction() | |
202 | ||
203 | function(bro_plugin_end_dynamic) | |
204 | # Create the dynamic library/bundle. | |
205 | add_library(${_plugin_lib} MODULE ${_plugin_objs}) | |
206 | set_target_properties(${_plugin_lib} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${BRO_PLUGIN_LIB}") | |
207 | set_target_properties(${_plugin_lib} PROPERTIES PREFIX "") | |
208 | # set_target_properties(${_plugin_lib} PROPERTIES ENABLE_EXPORTS TRUE) | |
209 | ||
210 | add_dependencies(${_plugin_lib} generate_outputs) | |
211 | ||
212 | if ( _plugin_deps ) | |
213 | add_dependencies(${_plugin_lib} ${_plugin_deps}) | |
214 | endif() | |
215 | ||
216 | target_link_libraries(${_plugin_lib} ${_plugin_libs}) | |
217 | ||
218 | # Create bif/__load__.zeek. | |
219 | bro_bif_create_loader(bif-init-${_plugin_name_canon} "${bro_PLUGIN_BIF_SCRIPTS}") | |
220 | ||
221 | # Copy scripts/ if it's not already at the right place inside the | |
222 | # plugin directory. (Actually, we create a symbolic link rather | |
223 | # than copy so that edits to the scripts show up immediately.) | |
224 | if ( NOT "${BRO_PLUGIN_SCRIPTS_SRC}" STREQUAL "${BRO_PLUGIN_SCRIPTS}" ) | |
225 | add_custom_target(copy-scripts-${_plugin_name_canon} | |
226 | # COMMAND "${CMAKE_COMMAND}" -E remove_directory ${BRO_PLUGIN_SCRIPTS} | |
227 | # COMMAND "${CMAKE_COMMAND}" -E copy_directory ${BRO_PLUGIN_SCRIPTS_SRC} ${BRO_PLUGIN_SCRIPTS}) | |
228 | COMMAND test -d ${BRO_PLUGIN_SCRIPTS_SRC} && rm -f ${BRO_PLUGIN_SCRIPTS} && ln -s ${BRO_PLUGIN_SCRIPTS_SRC} ${BRO_PLUGIN_SCRIPTS} || true) | |
229 | add_dependencies(${_plugin_lib} copy-scripts-${_plugin_name_canon}) | |
230 | endif() | |
231 | ||
232 | if ( _plugin_deps ) | |
233 | add_dependencies(bif-init-${_plugin_name_canon} ${_plugin_deps}) | |
234 | add_dependencies(${_plugin_lib} bif-init-${_plugin_name_canon}) | |
235 | endif() | |
236 | ||
237 | # Create __bro_plugin__ | |
238 | # string(REPLACE "${BRO_PLUGIN_BASE}/" "" msg "Creating ${BRO_PLUGIN_MAGIC} for ${_plugin_name}") | |
239 | get_filename_component(_magic_basename ${BRO_PLUGIN_MAGIC} NAME) | |
240 | ||
241 | add_custom_target(bro-plugin-${_plugin_name_canon} | |
242 | COMMAND echo "${_plugin_name}" ">${BRO_PLUGIN_MAGIC}" | |
243 | COMMENT "Creating ${_magic_basename} for ${_plugin_name}") | |
244 | ||
245 | if ( _plugin_deps ) | |
246 | add_dependencies(bro-plugin-${_plugin_name_canon} ${_plugin_deps}) | |
247 | endif() | |
248 | ||
249 | add_dependencies(${_plugin_lib} bro-plugin-${_plugin_name_canon}) | |
250 | ||
251 | set(_dist_tarball_name ${_plugin_name_canon}.tar.gz) | |
252 | set(_dist_output ${CMAKE_CURRENT_BINARY_DIR}/${_dist_tarball_name}) | |
253 | ||
254 | # Create binary install package. | |
255 | add_custom_command(OUTPUT ${_dist_output} | |
256 | COMMAND ${BRO_PLUGIN_BRO_CMAKE}/zeek-plugin-create-package.sh ${_plugin_name_canon} ${_plugin_dist} | |
257 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | |
258 | DEPENDS ${_plugin_lib} | |
259 | COMMENT "Building binary plugin package: ${_dist_tarball_name}") | |
260 | ||
261 | add_custom_target(dist ALL DEPENDS ${_dist_output}) | |
262 | ||
263 | set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${BRO_PLUGIN_BIF}) | |
264 | set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${BRO_PLUGIN_LIB}) | |
265 | set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${BRO_PLUGIN_MAGIC}) | |
266 | ||
267 | ### Plugin installation. | |
268 | ||
269 | set(plugin_install "${BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH}/${_plugin_name_canon}") | |
270 | ||
271 | INSTALL(CODE "execute_process( | |
272 | COMMAND ${BRO_PLUGIN_BRO_CMAKE}/zeek-plugin-install-package.sh ${_plugin_name_canon} \$ENV{DESTDIR}/${BRO_PLUGIN_BRO_PLUGIN_INSTALL_PATH} | |
273 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | |
274 | )") | |
275 | ||
276 | ||
277 | endfunction() | |
278 | ||
279 | macro(_plugin_target_name_dynamic target ns name) | |
280 | set(${target} "${ns}-${name}.${HOST_ARCHITECTURE}") | |
281 | endmacro() | |
282 |
0 | ## A set of functions for defining Zeek plugins. | |
1 | ## | |
2 | ## This set is for plugins compiled in statically. | |
3 | ## See ZeekPluginDynamic.cmake for the dynamic version. | |
4 | ||
5 | function(bro_plugin_bif_static) | |
6 | foreach ( bif ${ARGV} ) | |
7 | bif_target(${bif} "plugin" ${_plugin_name} ${_plugin_name_canon} TRUE) | |
8 | list(APPEND _plugin_objs ${BIF_OUTPUT_CC}) | |
9 | list(APPEND _plugin_deps ${BIF_BUILD_TARGET}) | |
10 | set(_plugin_objs "${_plugin_objs}" PARENT_SCOPE) | |
11 | set(_plugin_deps "${_plugin_deps}" PARENT_SCOPE) | |
12 | endforeach () | |
13 | endfunction() | |
14 | ||
15 | function(bro_plugin_link_library_static) | |
16 | foreach ( lib ${ARGV} ) | |
17 | set(bro_SUBDIR_LIBS ${bro_SUBDIR_LIBS} "${lib}" CACHE INTERNAL "plugin libraries") | |
18 | endforeach () | |
19 | endfunction() | |
20 | ||
21 | function(bro_plugin_end_static) | |
22 | if ( bro_HAVE_OBJECT_LIBRARIES ) | |
23 | add_library(${_plugin_lib} OBJECT ${_plugin_objs}) | |
24 | set(_target "$<TARGET_OBJECTS:${_plugin_lib}>") | |
25 | else () | |
26 | add_library(${_plugin_lib} STATIC ${_plugin_objs}) | |
27 | set(_target "${_plugin_lib}") | |
28 | endif () | |
29 | ||
30 | if ( NOT "${_plugin_deps}" STREQUAL "" ) | |
31 | add_dependencies(${_plugin_lib} ${_plugin_deps}) | |
32 | endif () | |
33 | ||
34 | add_dependencies(${_plugin_lib} generate_outputs) | |
35 | ||
36 | set(bro_PLUGIN_LIBS ${bro_PLUGIN_LIBS} "${_target}" CACHE INTERNAL "plugin libraries") | |
37 | endfunction() | |
38 | ||
39 | macro(_plugin_target_name_static target ns name) | |
40 | set(${target} "plugin-${ns}-${name}") | |
41 | endmacro() | |
42 |
0 | ||
1 | # Creates a target for a library of objects file in a subdirectory, | |
2 | # and adds to the global bro_SUBDIR_LIBS. | |
3 | function(bro_add_subdir_library name) | |
4 | if ( bro_HAVE_OBJECT_LIBRARIES ) | |
5 | add_library("bro_${name}" OBJECT ${ARGN}) | |
6 | set(_target "$<TARGET_OBJECTS:bro_${name}>") | |
7 | else () | |
8 | add_library("bro_${name}" STATIC ${ARGN}) | |
9 | set(_target "bro_${name}") | |
10 | endif () | |
11 | ||
12 | set(bro_SUBDIR_LIBS "${_target}" ${bro_SUBDIR_LIBS} CACHE INTERNAL "subdir libraries") | |
13 | endfunction() |
0 | #! /bin/sh | |
1 | # | |
2 | # Helper script creating a tarball with a plugin's binary distribution. We'll | |
3 | # also leave a MANIFEST in place with all files part of the tar ball. | |
4 | # | |
5 | # Called from BroPluginDynamic.cmake. Current directory is the plugin | |
6 | # build directory. | |
7 | ||
8 | if [ $# = 0 ]; then | |
9 | echo "usage: `basename $0` <canonical plugin name> [<additional files to include into binary distribution>]" | |
10 | exit 1 | |
11 | fi | |
12 | ||
13 | name=$1 | |
14 | shift | |
15 | addl=$@ | |
16 | ||
17 | # Copy additional distribution files into build directory. | |
18 | for i in ${addl}; do | |
19 | if [ -e ../$i ]; then | |
20 | dir=`dirname $i` | |
21 | mkdir -p ${dir} | |
22 | cp -p ../$i ${dir} | |
23 | fi | |
24 | done | |
25 | ||
26 | tgz=${name}-`(test -e ../VERSION && cat ../VERSION | head -1) || echo 0.0`.tar.gz | |
27 | ||
28 | rm -f MANIFEST ${name} ${name}.tgz ${tgz} | |
29 | ||
30 | for i in __bro_plugin__ lib scripts ${addl}; do | |
31 | test -e $i && find -L $i -type f | sed "s%^%${name}/%g" >>MANIFEST | |
32 | done | |
33 | ||
34 | ln -s . ${name} | |
35 | mkdir -p dist | |
36 | ||
37 | flag="-T" | |
38 | test `uname` = "OpenBSD" && flag="-I" | |
39 | tar czf dist/${tgz} ${flag} MANIFEST | |
40 | ||
41 | ln -s dist/${tgz} ${name}.tgz | |
42 | rm -f ${name} |
0 | #! /bin/sh | |
1 | # | |
2 | # Helper script to install the tarball with a plugin's binary distribution. | |
3 | # | |
4 | # Called from BroPluginDynamic.cmake. Current directory is the plugin | |
5 | # build directory. | |
6 | ||
7 | if [ $# != 2 ]; then | |
8 | echo "usage: `basename $0` <canonical plugin name> <destination directory>" | |
9 | exit 1 | |
10 | fi | |
11 | ||
12 | dst=$2 | |
13 | ||
14 | if [ ! -d "${dst}" ]; then | |
15 | echo "Warning: ${dst} does not exist; has Bro been installed?" | |
16 | mkdir -p ${dst} | |
17 | fi | |
18 | ||
19 | name=$1 | |
20 | tgz=`pwd`/$name.tgz | |
21 | ||
22 | ( cd ${dst} && rm -rf "${name}" && tar xzf ${tgz} ) |
2 | 2 | # This script is meant to be used by binary packages post-installation. |
3 | 3 | # Variables between @ symbols are replaced by CMake at configure time. |
4 | 4 | |
5 | backupNamesFile=/tmp/zeek_install_backups | |
5 | backupNamesFile=/tmp/bro_install_backups | |
6 | 6 | version=@VERSION@ |
7 | 7 | sampleFiles="" |
8 | 8 | |
48 | 48 | EOF |
49 | 49 | fi |
50 | 50 | |
51 | # Set up world writeable spool and logs directory for zeekctl, making sure | |
51 | # Set up world writeable spool and logs directory for broctl, making sure | |
52 | 52 | # to set the sticky bit so that unprivileged users can't rename/remove files. |
53 | 53 | # (CMake/CPack is supposed to install them, but has problems with empty dirs) |
54 | 54 | if [ -n "@EMPTY_WORLD_DIRS@" ]; then |
3 | 3 | # Variables between @ symbols are replaced by CMake at configure time. |
4 | 4 | |
5 | 5 | configFiles="@INSTALLED_CONFIG_FILES@" |
6 | backupNamesFile=/tmp/zeek_install_backups | |
6 | backupNamesFile=/tmp/bro_install_backups | |
7 | 7 | |
8 | 8 | # Checks if a config file exists in a default location and makes a backup |
9 | 9 | # so that a modified version is not clobbered |
0 | #! /bin/sh | |
1 | # | |
2 | # Helper script creating a tarball with a plugin's binary distribution. We'll | |
3 | # also leave a MANIFEST in place with all files part of the tar ball. | |
4 | # | |
5 | # Called from ZeekPluginDynamic.cmake. Current directory is the plugin | |
6 | # build directory. | |
7 | ||
8 | if [ $# = 0 ]; then | |
9 | echo "usage: `basename $0` <canonical plugin name> [<additional files to include into binary distribution>]" | |
10 | exit 1 | |
11 | fi | |
12 | ||
13 | name=$1 | |
14 | shift | |
15 | addl=$@ | |
16 | ||
17 | # Copy additional distribution files into build directory. | |
18 | for i in ${addl}; do | |
19 | if [ -e ../$i ]; then | |
20 | dir=`dirname $i` | |
21 | mkdir -p ${dir} | |
22 | cp -p ../$i ${dir} | |
23 | fi | |
24 | done | |
25 | ||
26 | tgz=${name}-`(test -e ../VERSION && cat ../VERSION | head -1) || echo 0.0`.tar.gz | |
27 | ||
28 | rm -f MANIFEST ${name} ${name}.tgz ${tgz} | |
29 | ||
30 | for i in __bro_plugin__ lib scripts ${addl}; do | |
31 | test -e $i && find -L $i -type f | sed "s%^%${name}/%g" >>MANIFEST | |
32 | done | |
33 | ||
34 | ln -s . ${name} | |
35 | mkdir -p dist | |
36 | ||
37 | flag="-T" | |
38 | test `uname` = "OpenBSD" && flag="-I" | |
39 | tar czf dist/${tgz} ${flag} MANIFEST | |
40 | ||
41 | ln -s dist/${tgz} ${name}.tgz | |
42 | rm -f ${name} |
0 | #! /bin/sh | |
1 | # | |
2 | # Helper script to install the tarball with a plugin's binary distribution. | |
3 | # | |
4 | # Called from ZeekPluginDynamic.cmake. Current directory is the plugin | |
5 | # build directory. | |
6 | ||
7 | if [ $# != 2 ]; then | |
8 | echo "usage: `basename $0` <canonical plugin name> <destination directory>" | |
9 | exit 1 | |
10 | fi | |
11 | ||
12 | dst=$2 | |
13 | ||
14 | if [ ! -d "${dst}" ]; then | |
15 | echo "Warning: ${dst} does not exist; has Zeek been installed?" | |
16 | mkdir -p ${dst} | |
17 | fi | |
18 | ||
19 | name=$1 | |
20 | tgz=`pwd`/$name.tgz | |
21 | ||
22 | ( cd ${dst} && rm -rf "${name}" && tar xzf ${tgz} ) |
26 | 26 | --generator=GENERATOR CMake generator to use (see cmake --help) |
27 | 27 | |
28 | 28 | Installation Directories: |
29 | --prefix=PREFIX installation directory [/usr/local/zeek] | |
29 | --prefix=PREFIX installation directory [/usr/local/bro] | |
30 | 30 | |
31 | 31 | Optional Features: |
32 | 32 | --enable-debug compile in debugging mode (like --build-type=Debug) |
67 | 67 | |
68 | 68 | # set defaults |
69 | 69 | builddir=build |
70 | prefix=/usr/local/zeek | |
70 | prefix=/usr/local/bro | |
71 | 71 | CMakeCacheEntries="" |
72 | 72 | append_cache_entry CMAKE_INSTALL_PREFIX PATH $prefix |
73 | 73 | append_cache_entry ENABLE_DEBUG BOOL false |