Move build defaults from configure to CMake

Moving the defaults for build variables from the `configure` script to
`CMakeLists.txt` gives the same default behavior on platforms where the
`configure` script is not available (Windows) and also allows a pure
CMake-based work flow (e.g., the standard `cmake -S . -B build`) without
having to manually adjust the defaults.

The `configure` script also becomes much simpler as a result.
This commit is contained in:
Dominik Charousset 2023-04-29 10:31:50 +02:00
parent 3a172bde38
commit 7af3611807
2 changed files with 63 additions and 48 deletions

View file

@ -9,12 +9,62 @@ endif()
project(Zeek C CXX)
option(ZEEK_STANDALONE "Build Zeek as stand-alone binary?" ON)
# We want to set ENABLE_DEBUG to ON by default if the build type is Debug.
set(ENABLE_DEBUG_DEFAULT OFF)
if ( NOT GENERATOR_IS_MULTI_CONFIG )
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower)
if ( build_type_lower STREQUAL "debug" )
set(ENABLE_DEBUG_DEFAULT ON)
endif ()
unset(build_type_lower)
endif ()
# CMake options (Boolean flags).
option(BUILD_SHARED_LIBS "Build targets as shared libraries." ON)
option(ENABLE_DEBUG "Build Zeek with additional debugging support." ${ENABLE_DEBUG_DEFAULT})
option(ENABLE_JEMALLOC "Link against jemalloc." OFF)
option(ENABLE_PERFTOOLS "Build with support for Google perftools." OFF)
option(ENABLE_ZEEK_UNIT_TESTS "Build the C++ (doctest) unit tests?" ON)
option(ENABLE_ZEEK_UNIT_TESTS "Build the C++ unit tests." ON)
option(INSTALL_AUX_TOOLS "Install additional tools from auxil." ON)
option(INSTALL_BTEST "Install btest alongside Zeek." ON)
option(INSTALL_BTEST_PCAPS "Install pcap files for testing." ON)
option(INSTALL_ZEEKCTL "Install zeekctl." ON)
option(INSTALL_ZEEK_ARCHIVER "Install the zeek-archiver." ON)
option(INSTALL_ZEEK_CLIENT "Install the zeek-client." ON)
option(INSTALL_ZKG "Install zkg." ON)
option(PREALLOCATE_PORT_ARRAY "Pre-allocate all ports for zeek::Val." ON)
option(ZEEK_STANDALONE "Build Zeek as stand-alone binary?" ON)
# Non-boolean options.
if ( NOT WIN32 )
if ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
set(CMAKE_INSTALL_PREFIX "/usr/local/zeek"
CACHE PATH "Install directory used by install()." FORCE)
endif ()
# On windows, this defaults to "c:/Program Files/${PROJECT_NAME}":
# https://cmake.org/cmake/help/v3.15/variable/CMAKE_INSTALL_PREFIX.html.
endif ()
set(ZEEK_SCRIPT_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/share/zeek"
CACHE PATH "Install directory for Zeek scripts.")
set(ZEEK_ETC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/etc"
CACHE PATH "Install directory for Zeek configuration files.")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON
CACHE INTERNAL "Write JSON compile commands database")
CACHE INTERNAL "Whether to write a JSON compile commands database")
set(ZEEK_CXX_STD cxx_std_17 CACHE STRING "The C++ standard to use.")
set(ZEEK_SANITIZERS "" CACHE STRING "Sanitizers to use when building.")
set(CPACK_SOURCE_IGNORE_FILES "" CACHE STRING "CPack source ignore files.")
set(ZEEK_INCLUDE_PLUGINS "" CACHE STRING "Extra plugins to add to the build.")
# Look into the build tree for additional CMake modules.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})