forked from zeek/zeek-agent-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
158 lines (126 loc) · 4.72 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# Copyright (c) 2021 by the Zeek Project. See LICENSE for details.
cmake_minimum_required(VERSION 3.15.1)
project(ZeekAgent)
if ( CMAKE_SYSTEM_NAME STREQUAL "Darwin" )
set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0 CACHE STRING "Minimum macOS version" FORCE) # Big Sur
# Hack to avoid CMake telling us that it doesn't support universal binaries for Swift.
# We later enable universal binaries explicitly ourselves for Swift code.
set(old_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}")
set(CMAKE_OSX_ARCHITECTURES "")
enable_language(Swift)
set(CMAKE_OSX_ARCHITECTURES "${old_CMAKE_OSX_ARCHITECTURES}")
endif ()
enable_language(C)
enable_language(CXX)
### Initialize defaults & global options
# Defaults here should match 'configure'.
option(USE_CCACHE "" "no")
option(USE_SANITIZERS "" "")
option(USE_WERROR "" "no")
option(USE_DOCTEST "" "yes")
option(USE_STATIC_LINKING "" "no")
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
if ( NOT CMAKE_BUILD_TYPE )
# CMake doesn't set build type by default.
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif ()
include(Util)
include(GNUInstallDirs)
if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
endif ()
if( NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY )
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
endif ()
if ( NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY )
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
endif ()
if ( USE_CCACHE )
find_program(CCACHE_PROGRAM ccache)
if( CCACHE_PROGRAM )
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
else ()
set(USE_CCACHE "no (error: could not find ccache)")
endif()
endif ()
if ( USE_STATIC_LINKING )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
endif()
enable_testing()
### Determine version information
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/VERSION ZEEK_AGENT_VERSION LIMIT_COUNT 1)
set(CMAKE_PROJECT_VERSION ${ZEEK_AGENT_VERSION})
string(REGEX MATCHALL "[0-9]+" AGENT_PARTS "${ZEEK_AGENT_VERSION}")
list(GET AGENT_PARTS 0 ZEEK_AGENT_VERSION_MAJOR)
list(GET AGENT_PARTS 1 ZEEK_AGENT_VERSION_MINOR)
list(GET AGENT_PARTS 2 ZEEK_AGENT_VERSION_PATCH)
list(LENGTH AGENT_PARTS PARTS_LEN)
if ( PARTS_LEN GREATER 3 )
list(GET AGENT_PARTS 3 ZEEK_AGENT_VERSION_COMMITNUM)
else ()
set(ZEEK_AGENT_VERSION_COMMITNUM 0)
endif ()
# Get current git commit. If we cannot get the current commit (e.g., no .git
# directory present for release tarballs), this will leave ZEEK_AGENT_COMMIT unset.
execute_process(
COMMAND ${CMAKE_COMMAND} -E env GIT_DIR=${CMAKE_CURRENT_SOURCE_DIR}/.git git rev-parse --short HEAD
OUTPUT_VARIABLE ZEEK_AGENT_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE ignored)
if ( NOT "${SPICY_COMMIT}" STREQUAL "" )
set(ZEEK_AGENT_VERSION_LONG "${ZEEK_AGENT_VERSION} (${ZEEK_AGENT_COMMIT})")
else ()
set(ZEEK_AGENT_VERSION_LONG "${ZEEK_AGENT_VERSION}")
endif ()
### Platform-specific code.
if (UNIX)
set(HAVE_POSIX true)
else()
set(HAVE_POSIX false)
endif()
if ( CMAKE_SYSTEM_NAME STREQUAL "Darwin" )
set(HAVE_DARWIN true)
elseif ( CMAKE_SYSTEM_NAME STREQUAL "Linux" )
set(HAVE_LINUX true)
elseif ( CMAKE_SYSTEM_NAME STREQUAL "Windows" )
set(HAVE_WINDOWS true)
else ()
message(FATAL_ERROR "unknown platform, supporting only Linux and macOS currently")
endif()
### Additional targets.
include(ProcessorCount)
ProcessorCount(NUM_CPUS)
if(NUM_CPUS EQUAL 0)
set(NUM_CPUS 1)
endif()
# Create a target for running clang-tidy through our helper script.
add_custom_target(tidy COMMAND ${CMAKE_SOURCE_DIR}/auxil/run-clang-tidy -j ${NUM_CPUS} ${CMAKE_BINARY_DIR})
### Add subdirectories.
add_subdirectory(3rdparty)
add_subdirectory(src)
add_subdirectory(packaging)
### Emit configuration summary.
if ( NOT "${USE_SANITIZERS}" )
set(USE_SANITIZERS_DISPLAY "no")
endif ()
message(
"\n====================| Zeek Agent Build Summary |===================="
"\n"
"\nVersion: ${ZEEK_AGENT_VERSION_LONG}"
"\n"
"\nBuild type: ${CMAKE_BUILD_TYPE}"
"\nBuild directory: ${PROJECT_BINARY_DIR}"
"\nInstall prefix: ${CMAKE_INSTALL_PREFIX}"
"\n"
"\nHost system: ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION} (${CMAKE_SYSTEM_PROCESSOR})"
"\n"
"\nBuild with tests: ${USE_DOCTEST}"
"\nUse ccache: ${USE_CCACHE}"
"\nUse sanitizers: ${USE_SANITIZERS_DISPLAY}"
"\nLink statically: ${USE_STATIC_LINKING}"
"\n"
"\nWarnings are errors: ${USE_WERROR}"
"\n"
"\n================================================================\n"
)