mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Compile Zeek with MSVC
Allow Zeek to be embedded in another project
This commit is contained in:
parent
2bd4af7477
commit
3a80b79497
53 changed files with 724 additions and 153 deletions
128
CMakeLists.txt
128
CMakeLists.txt
|
@ -2,9 +2,86 @@
|
|||
# auxil/zeek-aux/plugin-support/skeleton/CMakeLists.txt
|
||||
cmake_minimum_required(VERSION 3.15.0 FATAL_ERROR)
|
||||
|
||||
if ( WIN32 )
|
||||
# Enable usage of CMAKE_MSVC_RUNTIME_LIBRARY variable
|
||||
cmake_policy(SET CMP0091 NEW)
|
||||
endif()
|
||||
|
||||
project(Zeek C CXX)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
option(ZEEK_STANDALONE "Is Zeek compiled stand-alone or embedded in a parent project." ON)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
|
||||
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
|
||||
|
||||
# Windows: Configure runtime and dependencies
|
||||
if ( MSVC )
|
||||
cmake_policy(SET CMP0091 NEW)
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebug")
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY_FLAG "MTd")
|
||||
else ()
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY_FLAG "MT")
|
||||
endif ()
|
||||
set(OPENSSL_USE_STATIC_LIBS true)
|
||||
set(OPENSSL_MSVC_STATIC_RT true)
|
||||
|
||||
if ( ZEEK_STANDALONE )
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/conan.cmake)
|
||||
|
||||
conan_cmake_configure(REQUIRES
|
||||
zlib/1.2.11
|
||||
openssl/1.1.1i
|
||||
winflexbison/2.5.24
|
||||
npcap-wpcap/1.31
|
||||
GENERATORS cmake_find_package)
|
||||
|
||||
# Install packages from conanfile
|
||||
conan_cmake_install(PATH_OR_REFERENCE ${CMAKE_SOURCE_DIR}/ci/windows/conanfile_windows.txt
|
||||
BUILD missing
|
||||
SETTINGS ${settings})
|
||||
endif()
|
||||
|
||||
# Set LibPCAP to point to wpcap binaries.
|
||||
find_package(npcap-wpcap)
|
||||
set(PCAP_ROOT_DIR "${npcap-wpcap_LIB_DIRS}/../")
|
||||
set(PCAP_INCLUDE_DIR ${npcap-wpcap_INCLUDES})
|
||||
set(PCAP_LIBRARY ${npcap-wpcap_LIBS})
|
||||
set(LIBPCAP_PCAP_COMPILE_NOPCAP_HAS_ERROR_PARAMETER false)
|
||||
|
||||
# Set ZLib to point at the right variable.
|
||||
find_package(ZLIB)
|
||||
set(ZLIB_LIBRARY ${ZLIB_LIBRARIES})
|
||||
|
||||
add_subdirectory(auxil/libunistd)
|
||||
set(UNISTD_INCLUDES ${CMAKE_SOURCE_DIR}/auxil/libunistd/unistd ${CMAKE_SOURCE_DIR}/auxil/libunistd/regex)
|
||||
include_directories(BEFORE ${UNISTD_INCLUDES})
|
||||
# Required for `check_include_files` to operate correctly
|
||||
list(APPEND CMAKE_REQUIRED_INCLUDES ${UNISTD_INCLUDES})
|
||||
list(APPEND zeekdeps libunistd libregex)
|
||||
|
||||
# Set CMAKE flags for supported windows build.
|
||||
set(DISABLE_PYTHON_BINDINGS true)
|
||||
set(BROKER_DISABLE_TESTS true)
|
||||
set(BROKER_DISABLE_DOC_EXAMPLES true)
|
||||
else ()
|
||||
include(GNUInstallDirs)
|
||||
endif ()
|
||||
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
if ( CMAKE_SYSTEM_NAME STREQUAL Linux )
|
||||
set(CMAKE_DL_LIBS pthread ${CMAKE_DL_LIBS})
|
||||
endif ()
|
||||
|
||||
if ( NOT CMAKE_INSTALL_LIBDIR )
|
||||
# Currently, some sub-projects may use GNUInstallDirs.cmake to choose the
|
||||
# library install dir, while others just default to "lib". For sake of
|
||||
# consistency, this just overrides the former to always use "lib" in case
|
||||
# it would have chosen something else, like "lib64", but a thing for the
|
||||
# future may be to standardize all sub-projects to use GNUInstallDirs.
|
||||
set(CMAKE_INSTALL_LIBDIR lib)
|
||||
endif ()
|
||||
|
||||
include(cmake/CommonCMakeConfig.cmake)
|
||||
include(cmake/FindClangTidy.cmake)
|
||||
|
@ -63,6 +140,21 @@ if (ZEEK_PLUGIN_DIR)
|
|||
else ()
|
||||
set(BRO_PLUGIN_INSTALL_PATH ${ZEEK_LIBDIR_PATH}/plugins
|
||||
CACHE STRING "Installation path for plugins" FORCE)
|
||||
endif()
|
||||
|
||||
set(bro_plugin_install_path "${BRO_PLUGIN_INSTALL_PATH}")
|
||||
set(cmake_binary_dir "${CMAKE_BINARY_DIR}")
|
||||
set(cmake_current_binary_dir "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
set(cmake_install_prefix "${CMAKE_INSTALL_PREFIX}")
|
||||
set(cmake_source_dir "${CMAKE_SOURCE_DIR}")
|
||||
set(zeek_script_install_path "${ZEEK_SCRIPT_INSTALL_PATH}")
|
||||
if ( MSVC )
|
||||
string(REGEX REPLACE "^([A-Za-z]):/(.*)" "/\\1/\\2" bro_plugin_install_path "${bro_plugin_install_path}")
|
||||
string(REGEX REPLACE "^([A-Za-z]):/(.*)" "/\\1/\\2" cmake_binary_dir "${cmake_binary_dir}")
|
||||
string(REGEX REPLACE "^([A-Za-z]):/(.*)" "/\\1/\\2" cmake_current_binary_dir "${cmake_current_binary_dir}")
|
||||
string(REGEX REPLACE "^([A-Za-z]):/(.*)" "/\\1/\\2" cmake_install_prefix "${cmake_install_prefix}")
|
||||
string(REGEX REPLACE "^([A-Za-z]):/(.*)" "/\\1/\\2" cmake_source_dir "${cmake_source_dir}")
|
||||
string(REGEX REPLACE "^([A-Za-z]):/(.*)" "/\\1/\\2" zeek_script_install_path "${zeek_script_install_path}")
|
||||
endif ()
|
||||
|
||||
if ( NOT ZEEK_ETC_INSTALL_DIR )
|
||||
|
@ -300,7 +392,9 @@ FindRequiredPackage(FLEX)
|
|||
FindRequiredPackage(BISON)
|
||||
FindRequiredPackage(PCAP)
|
||||
FindRequiredPackage(OpenSSL)
|
||||
FindRequiredPackage(BIND)
|
||||
if ( NOT WIN32 )
|
||||
FindRequiredPackage(BIND)
|
||||
endif ()
|
||||
FindRequiredPackage(ZLIB)
|
||||
|
||||
# Installation directory for the distribution's Python modules. An
|
||||
|
@ -325,6 +419,9 @@ set(PY_MOD_INSTALL_DIR ${py_mod_install_dir}
|
|||
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/auxil/binpac/CMakeLists.txt)
|
||||
|
||||
set(ENABLE_STATIC_ONLY_SAVED ${ENABLE_STATIC_ONLY})
|
||||
if ( MSVC )
|
||||
set(BUILD_STATIC_BINPAC true)
|
||||
endif()
|
||||
|
||||
if ( BUILD_STATIC_BINPAC )
|
||||
set(ENABLE_STATIC_ONLY true)
|
||||
|
@ -381,6 +478,11 @@ if ( PYTHON_VERSION_STRING VERSION_LESS ${ZEEK_PYTHON_MIN} )
|
|||
endif ()
|
||||
|
||||
add_subdirectory(auxil/paraglob)
|
||||
if ( MSVC )
|
||||
cmake_policy(SET CMP0079 NEW)
|
||||
target_link_libraries(paraglob shlwapi)
|
||||
set(BROKER_DISABLE_TOOLS true)
|
||||
endif ()
|
||||
set(zeekdeps ${zeekdeps} paraglob)
|
||||
|
||||
if ( Broker_ROOT )
|
||||
|
@ -397,6 +499,9 @@ else ()
|
|||
endif ()
|
||||
|
||||
set(ENABLE_STATIC_ONLY_SAVED ${ENABLE_STATIC_ONLY})
|
||||
if ( MSVC )
|
||||
set(BUILD_STATIC_BROKER true)
|
||||
endif()
|
||||
|
||||
if ( BUILD_STATIC_BROKER )
|
||||
set(ENABLE_STATIC_ONLY true)
|
||||
|
@ -599,7 +704,12 @@ if ( ${CMAKE_SYSTEM_NAME} MATCHES Linux )
|
|||
endif ()
|
||||
endif ()
|
||||
|
||||
set(DEFAULT_ZEEKPATH .:${ZEEK_SCRIPT_INSTALL_PATH}:${ZEEK_SCRIPT_INSTALL_PATH}/policy:${ZEEK_SCRIPT_INSTALL_PATH}/site:${ZEEK_SCRIPT_INSTALL_PATH}/builtin-plugins)
|
||||
set(DEFAULT_ZEEKPATH_PATHS . ${ZEEK_SCRIPT_INSTALL_PATH} ${ZEEK_SCRIPT_INSTALL_PATH}/policy ${ZEEK_SCRIPT_INSTALL_PATH}/site ${ZEEK_SCRIPT_INSTALL_PATH}/builtin-plugins)
|
||||
if ( WIN32 )
|
||||
list(JOIN DEFAULT_ZEEKPATH_PATHS ";" DEFAULT_ZEEKPATH)
|
||||
else ()
|
||||
list(JOIN DEFAULT_ZEEKPATH_PATHS ":" DEFAULT_ZEEKPATH)
|
||||
endif ()
|
||||
|
||||
if ( NOT BINARY_PACKAGING_MODE )
|
||||
set(ZEEK_DIST ${PROJECT_SOURCE_DIR})
|
||||
|
@ -653,11 +763,13 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake DESTINATION share/zeek
|
|||
USE_SOURCE_PERMISSIONS
|
||||
PATTERN ".git" EXCLUDE)
|
||||
|
||||
# Install wrapper script for Bro-to-Zeek renaming.
|
||||
include(InstallShellScript)
|
||||
include(InstallSymlink)
|
||||
InstallShellScript("bin" "zeek-wrapper.in" "zeek-wrapper")
|
||||
InstallSymlink("${CMAKE_INSTALL_PREFIX}/bin/zeek-wrapper" "${CMAKE_INSTALL_PREFIX}/bin/bro-config")
|
||||
if ( NOT WIN32 )
|
||||
# Install wrapper script for Bro-to-Zeek renaming.
|
||||
include(InstallShellScript)
|
||||
include(InstallSymlink)
|
||||
InstallShellScript("bin" "zeek-wrapper.in" "zeek-wrapper")
|
||||
InstallSymlink("${CMAKE_INSTALL_PREFIX}/bin/zeek-wrapper" "${CMAKE_INSTALL_PREFIX}/bin/bro-config")
|
||||
endif ()
|
||||
|
||||
########################################################################
|
||||
## zkg configuration
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue