From 25aadd82ef2db3ac909fc742efa9644fbf45bfe2 Mon Sep 17 00:00:00 2001 From: Dominik Charousset Date: Thu, 31 Oct 2019 10:58:51 +0100 Subject: [PATCH] Use object libraries for subdir libs and plugins --- src/CMakeLists.txt | 40 +++---------------- src/analyzer/CMakeLists.txt | 2 +- src/broker/CMakeLists.txt | 2 +- src/file_analysis/CMakeLists.txt | 2 +- .../analyzer/data_event/CMakeLists.txt | 2 +- .../analyzer/entropy/CMakeLists.txt | 2 +- .../analyzer/extract/CMakeLists.txt | 2 +- .../analyzer/hash/CMakeLists.txt | 2 +- .../analyzer/unified2/CMakeLists.txt | 2 +- src/input/CMakeLists.txt | 2 +- src/logging/CMakeLists.txt | 2 +- src/plugins.cc.in | 22 ---------- 12 files changed, 16 insertions(+), 66 deletions(-) delete mode 100644 src/plugins.cc.in diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 564fd7acb3..e32c739e9d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,10 +13,6 @@ set(bro_REGISTER_BIFS CACHE INTERNAL "BIFs for automatic registering" FORCE) set(bro_BASE_BIF_SCRIPTS CACHE INTERNAL "Zeek script stubs for BIFs in base distribution of Zeek" FORCE) set(bro_PLUGIN_BIF_SCRIPTS CACHE INTERNAL "Zeek script stubs for BIFs in Zeek plugins" FORCE) -# If TRUE, use CMake's object libraries for sub-directories instead of -# static libraries. This requires CMake >= 2.8.8. -set(bro_HAVE_OBJECT_LIBRARIES FALSE) - configure_file(version.c.in ${CMAKE_CURRENT_BINARY_DIR}/version.c) configure_file(util-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/util-config.h) @@ -139,7 +135,9 @@ list(APPEND BINPAC_OUTPUTS "${BINPAC_OUTPUT_CC}") ######################################################################## set(bro_SUBDIR_LIBS CACHE INTERNAL "subdir libraries" FORCE) +set(bro_SUBDIR_DEPS CACHE INTERNAL "subdir dependencies" FORCE) set(bro_PLUGIN_LIBS CACHE INTERNAL "plugin libraries" FORCE) +set(bro_PLUGIN_DEPS CACHE INTERNAL "plugin dependencies" FORCE) add_subdirectory(analyzer) add_subdirectory(broker) @@ -150,26 +148,6 @@ add_subdirectory(iosource) add_subdirectory(logging) add_subdirectory(probabilistic) -set(bro_SUBDIRS - # Order is important here. - ${bro_PLUGIN_LIBS} - ${bro_SUBDIR_LIBS} -) - -if ( NOT bro_HAVE_OBJECT_LIBRARIES ) - foreach (_plugin ${bro_PLUGIN_LIBS}) - string(REGEX REPLACE "plugin-" "" _plugin "${_plugin}") - string(REGEX REPLACE "-" "_" _plugin "${_plugin}") - set(_decl "namespace plugin { namespace ${_plugin} { class Plugin; extern Plugin plugin; } };") - set(_use "i += (size_t)(&(plugin::${_plugin}::plugin));") - set(__BRO_DECL_PLUGINS "${__BRO_DECL_PLUGINS}${_decl}\n") - set(__BRO_USE_PLUGINS "${__BRO_USE_PLUGINS}${_use}\n") - endforeach() - - configure_file(plugins.cc.in ${CMAKE_CURRENT_BINARY_DIR}/plugins.cc) - set(PLUGIN_INIT ${CMAKE_CURRENT_BINARY_DIR}/plugins.cc) -endif() - ######################################################################## ## bro target @@ -344,20 +322,14 @@ set(bro_SRCS ${FLEX_Scanner_INPUT} ${BISON_Parser_INPUT} ${CMAKE_CURRENT_BINARY_DIR}/DebugCmdConstants.h - ${PLUGIN_INIT} ${THIRD_PARTY_SRCS} ${MAIN_SRCS} ) collect_headers(bro_HEADERS ${bro_SRCS}) -if ( bro_HAVE_OBJECT_LIBRARIES ) - add_executable(zeek ${bro_SRCS} ${bro_HEADERS} ${bro_SUBDIRS}) - target_link_libraries(zeek ${zeekdeps} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) -else () - add_executable(zeek ${bro_SRCS} ${bro_HEADERS}) - target_link_libraries(zeek ${bro_SUBDIRS} ${zeekdeps} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) -endif () +add_executable(zeek ${bro_SRCS} ${bro_HEADERS} ${bro_SUBDIR_LIBS} ${bro_PLUGIN_LIBS}) +target_link_libraries(zeek ${zeekdeps} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) if ( NOT "${bro_LINKER_FLAGS}" STREQUAL "" ) set_target_properties(zeek PROPERTIES LINK_FLAGS "${bro_LINKER_FLAGS}") @@ -396,12 +368,12 @@ add_dependencies(generate_outputs generate_outputs_stage2a generate_outputs_stag # Build __load__.zeek files for standard *.bif.zeek. bro_bif_create_loader(bif_loader "${bro_BASE_BIF_SCRIPTS}") -add_dependencies(bif_loader ${bro_SUBDIRS}) +add_dependencies(bif_loader ${bro_PLUGIN_DEPS} ${bro_SUBDIR_DEPS}) add_dependencies(zeek bif_loader) # Build __load__.zeek files for plugins/*.bif.zeek. bro_bif_create_loader(bif_loader_plugins "${bro_PLUGIN_BIF_SCRIPTS}") -add_dependencies(bif_loader_plugins ${bro_SUBDIRS}) +add_dependencies(bif_loader_plugins ${bro_PLUGIN_DEPS} ${bro_SUBDIR_DEPS}) add_dependencies(zeek bif_loader_plugins) # Install *.bif.zeek. diff --git a/src/analyzer/CMakeLists.txt b/src/analyzer/CMakeLists.txt index 4dc2830737..e0d2351c93 100644 --- a/src/analyzer/CMakeLists.txt +++ b/src/analyzer/CMakeLists.txt @@ -17,6 +17,6 @@ set(analyzer_SRCS bif_target(analyzer.bif) -bro_add_subdir_library(analyzer ${analyzer_SRCS} ${BIF_OUTPUT_CC}) +bro_add_subdir_library(analyzer ${analyzer_SRCS}) add_dependencies(bro_analyzer generate_outputs) diff --git a/src/broker/CMakeLists.txt b/src/broker/CMakeLists.txt index 08e02597e7..da0d1ca819 100644 --- a/src/broker/CMakeLists.txt +++ b/src/broker/CMakeLists.txt @@ -21,5 +21,5 @@ bif_target(data.bif) bif_target(messaging.bif) bif_target(store.bif) -bro_add_subdir_library(brokercomm ${comm_SRCS} ${BIF_OUTPUT_CC}) +bro_add_subdir_library(brokercomm ${comm_SRCS}) add_dependencies(bro_brokercomm generate_outputs) diff --git a/src/file_analysis/CMakeLists.txt b/src/file_analysis/CMakeLists.txt index f9a2758920..8facf86c32 100644 --- a/src/file_analysis/CMakeLists.txt +++ b/src/file_analysis/CMakeLists.txt @@ -20,5 +20,5 @@ set(file_analysis_SRCS bif_target(file_analysis.bif) -bro_add_subdir_library(file_analysis ${file_analysis_SRCS} ${BIF_OUTPUT_CC}) +bro_add_subdir_library(file_analysis ${file_analysis_SRCS}) add_dependencies(bro_file_analysis generate_outputs) diff --git a/src/file_analysis/analyzer/data_event/CMakeLists.txt b/src/file_analysis/analyzer/data_event/CMakeLists.txt index 0a62b1d666..df8aada1f4 100644 --- a/src/file_analysis/analyzer/data_event/CMakeLists.txt +++ b/src/file_analysis/analyzer/data_event/CMakeLists.txt @@ -4,5 +4,5 @@ include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) zeek_plugin_begin(Zeek FileDataEvent) -zeek_plugin_cc(DataEvent.cc Plugin.cc ../../Analyzer.cc) +zeek_plugin_cc(DataEvent.cc Plugin.cc) zeek_plugin_end() diff --git a/src/file_analysis/analyzer/entropy/CMakeLists.txt b/src/file_analysis/analyzer/entropy/CMakeLists.txt index 7841f27f94..e6233a743b 100644 --- a/src/file_analysis/analyzer/entropy/CMakeLists.txt +++ b/src/file_analysis/analyzer/entropy/CMakeLists.txt @@ -4,6 +4,6 @@ include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) zeek_plugin_begin(Zeek FileEntropy) -zeek_plugin_cc(Entropy.cc Plugin.cc ../../Analyzer.cc) +zeek_plugin_cc(Entropy.cc Plugin.cc) zeek_plugin_bif(events.bif) zeek_plugin_end() diff --git a/src/file_analysis/analyzer/extract/CMakeLists.txt b/src/file_analysis/analyzer/extract/CMakeLists.txt index 7df895af38..f24691ddff 100644 --- a/src/file_analysis/analyzer/extract/CMakeLists.txt +++ b/src/file_analysis/analyzer/extract/CMakeLists.txt @@ -4,7 +4,7 @@ include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) zeek_plugin_begin(Zeek FileExtract) -zeek_plugin_cc(Extract.cc Plugin.cc ../../Analyzer.cc) +zeek_plugin_cc(Extract.cc Plugin.cc) zeek_plugin_bif(events.bif) zeek_plugin_bif(functions.bif) zeek_plugin_end() diff --git a/src/file_analysis/analyzer/hash/CMakeLists.txt b/src/file_analysis/analyzer/hash/CMakeLists.txt index 46d557fd4b..66d6d7e6e8 100644 --- a/src/file_analysis/analyzer/hash/CMakeLists.txt +++ b/src/file_analysis/analyzer/hash/CMakeLists.txt @@ -4,6 +4,6 @@ include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) zeek_plugin_begin(Zeek FileHash) -zeek_plugin_cc(Hash.cc Plugin.cc ../../Analyzer.cc) +zeek_plugin_cc(Hash.cc Plugin.cc) zeek_plugin_bif(events.bif) zeek_plugin_end() diff --git a/src/file_analysis/analyzer/unified2/CMakeLists.txt b/src/file_analysis/analyzer/unified2/CMakeLists.txt index bd1537c8ef..68c3d2712c 100644 --- a/src/file_analysis/analyzer/unified2/CMakeLists.txt +++ b/src/file_analysis/analyzer/unified2/CMakeLists.txt @@ -5,7 +5,7 @@ include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) zeek_plugin_begin(Zeek Unified2) -zeek_plugin_cc(Unified2.cc Plugin.cc ../../Analyzer.cc) +zeek_plugin_cc(Unified2.cc Plugin.cc) zeek_plugin_bif(events.bif types.bif) zeek_plugin_pac(unified2.pac unified2-file.pac unified2-analyzer.pac) zeek_plugin_end() diff --git a/src/input/CMakeLists.txt b/src/input/CMakeLists.txt index c928451cb3..2b41487021 100644 --- a/src/input/CMakeLists.txt +++ b/src/input/CMakeLists.txt @@ -18,6 +18,6 @@ set(input_SRCS bif_target(input.bif) -bro_add_subdir_library(input ${input_SRCS} ${BIF_OUTPUT_CC}) +bro_add_subdir_library(input ${input_SRCS}) add_dependencies(bro_input generate_outputs) diff --git a/src/logging/CMakeLists.txt b/src/logging/CMakeLists.txt index b37f6f95cb..849444b647 100644 --- a/src/logging/CMakeLists.txt +++ b/src/logging/CMakeLists.txt @@ -20,6 +20,6 @@ set(logging_SRCS bif_target(logging.bif) -bro_add_subdir_library(logging ${logging_SRCS} ${BIF_OUTPUT_CC}) +bro_add_subdir_library(logging ${logging_SRCS}) add_dependencies(bro_logging generate_outputs) diff --git a/src/plugins.cc.in b/src/plugins.cc.in deleted file mode 100644 index 4527d5d1a9..0000000000 --- a/src/plugins.cc.in +++ /dev/null @@ -1,22 +0,0 @@ - -// A work-around the problem that for static libraries unused globals -// aren't linked into the final binary. CMake automatically inserts -// code here to reference the globals that initializes each of the -// statically compiled plugins. -// -// Note: This won't be necessary anymore once we can assume CMake >2.8.8 -// as a required depencendy. If so, switch bro_HAVE_OBJECT_LIBRARIES -// in src/CMakeLists.txt to TRUE and remove this. - -#include - -${__BRO_DECL_PLUGINS} - -size_t __make_sure_to_use_plugin_globals() -{ - // This function is never actually called. - - size_t i = 0; - ${__BRO_USE_PLUGINS} - return i; -}