forked from osquery/osquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
525 lines (429 loc) · 13 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
# Copyright (c) 2014-present, The osquery authors
#
# This source code is licensed as defined by the LICENSE file found in the
# root directory of this source tree.
#
# SPDX-License-Identifier: (Apache-2.0 OR GPL-2.0-only)
cmake_minimum_required(VERSION 3.17.5 FATAL_ERROR)
cmake_policy(SET CMP0083 NEW)
# toolchain.cmake needs to be included before project() because the former sets the compiler path for the custom toolchain,
# if the user specify it and the latter does compiler detection.
# utilities.cmake is a dependency of toolchain.cmake.
include(cmake/utilities.cmake)
include(cmake/toolchain.cmake)
project(osquery)
if(OSQUERY_BUILD_TESTS)
enable_testing()
endif()
include(cmake/globals.cmake)
include(cmake/options.cmake)
include(cmake/flags.cmake)
if(OSQUERY_TOOLCHAIN_SYSROOT AND NOT DEFINED PLATFORM_LINUX)
message(FATAL_ERROR "The custom toolchain can only be used with Linux, undefine OSQUERY_TOOLCHAIN_SYSROOT and specify a compiler to use")
endif()
# clang-tidy needs to be initialized in global scope, before any
# target is created
if(OSQUERY_ENABLE_CLANG_TIDY)
find_package(clang-tidy)
if(TARGET clang-tidy::clang-tidy)
foreach(language C CXX)
set("CMAKE_${language}_CLANG_TIDY"
"${CLANG-TIDY_EXECUTABLE};${OSQUERY_CLANG_TIDY_CHECKS}"
)
endforeach()
else()
message(WARNING "clang-tidy: Disabled because it was not found")
endif()
endif()
function(main)
findClangFormat()
findPythonExecutablePath()
generateSpecialTargets()
if(OSQUERY_ENABLE_FORMAT_ONLY)
return()
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Shared libraries: ${BUILD_SHARED_LIBS}")
if(DEFINED PLATFORM_MACOS)
if((NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" AND NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang") OR
(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang"))
message(STATUS "Warning: the selected C or C++ compiler is not clang/clang++. Compilation may fail")
endif()
elseif(NOT DEFINED PLATFORM_WINDOWS)
if(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR
NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message(STATUS "Warning: the selected C or C++ compiler is not clang/clang++. Compilation may fail")
endif()
endif()
add_subdirectory("libraries")
importLibraries()
add_subdirectory("osquery")
add_subdirectory("plugins")
add_subdirectory("tools")
add_subdirectory("specs")
add_subdirectory("external")
add_subdirectory("tests")
if(DEFINED PLATFORM_WINDOWS)
enableOsqueryWEL()
endif()
generateInstallDirectives()
endfunction()
function(importLibraries)
set(library_descriptor_list
"Linux,Darwin:augeas"
"Linux,Darwin,Windows:boost"
"Linux,Darwin,Windows:bzip2"
"Linux,Darwin,Windows:gflags"
"Linux,Darwin,Windows:glog"
"Linux,Darwin,Windows:googletest"
"Linux,Darwin,Windows:libarchive"
"Linux:libaudit"
"Linux:libcryptsetup"
"Linux:libdevmapper"
"Linux:libelfin"
"Linux:libgcrypt"
"Linux:libgpg-error"
"Linux:libiptables"
"Linux,Darwin:libmagic"
"Linux,Darwin,Windows:librdkafka"
"Linux:librpm"
"Linux:libudev"
"Linux,Darwin,Windows:libxml2"
"Linux,Darwin,Windows:linenoise-ng"
"Linux,Darwin:lldpd"
"Linux,Darwin,Windows:lzma"
"Linux,Darwin:popt"
"Linux,Darwin,Windows:rapidjson"
"Linux,Darwin,Windows:rocksdb"
"Linux,Darwin,Windows:sleuthkit"
"Linux,Darwin:smartmontools"
"Linux,Darwin,Windows:sqlite"
"Linux,Darwin:ssdeep-cpp"
"Linux,Darwin,Windows:thrift"
"Linux:util-linux"
"Linux,Darwin,Windows:yara"
"Linux,Darwin,Windows:zlib"
"Linux,Darwin,Windows:zstd"
"Linux,Darwin,Windows:openssl"
"Linux,Darwin,Windows:icu"
"Linux:expat"
"Linux:dbus"
"Linux:libcap"
)
if(OSQUERY_BUILD_BPF)
list(APPEND library_descriptor_list
"Linux:ebpfpub"
)
endif()
if(OSQUERY_BUILD_AWS)
list(APPEND library_descriptor_list
"Linux,Darwin,Windows:aws-sdk-cpp"
)
endif()
if(OSQUERY_BUILD_DPKG)
list(APPEND library_descriptor_list
"Linux:libdpkg"
)
endif()
foreach(library_descriptor ${library_descriptor_list})
# Expand the library descriptor
string(REPLACE ":" ";" library_descriptor "${library_descriptor}")
list(GET library_descriptor 0 platform_list)
list(GET library_descriptor 1 library)
string(REPLACE "," ";" platform_list "${platform_list}")
list(FIND platform_list "${CMAKE_SYSTEM_NAME}" platform_index)
if(platform_index EQUAL -1)
continue()
endif()
find_package("${library}" REQUIRED)
# Skip libraries which already use our internal target name
if(TARGET "thirdparty_${library}")
continue()
# For generic libraries that import the library name, let's create
# an alias
elseif(TARGET "${library}")
add_library("thirdparty_${library}" ALIAS "${library}")
# Legacy libraries will just export variables; build a new INTERFACE
# target with them
elseif(DEFINED "${library}_LIBRARIES")
if(NOT DEFINED "${library}_INCLUDE_DIRS")
message(FATAL_ERROR "Variable ${library}_INCLUDE_DIRS was not found!")
endif()
add_library("thirdparty_${library}" INTERFACE)
target_link_libraries("thirdparty_${library}" INTERFACE
${library}_LIBRARIES
)
target_include_directories("thirdparty_${library}" INTERFACE
${library}_INCLUDE_DIRS
)
if(DEFINED "${library}_DEFINITIONS")
target_compile_definitions("thirdparty_${library}" INTERFACE
${library}_DEFINITIONS
)
endif()
else()
# In case we were trying to import ebpfpub, check whether the build option
# has been turned OFF automatically because the installed LLVM libraries
# were broken/not compatible
if(NOT OSQUERY_BUILD_BPF AND "${library}" STREQUAL "ebpfpub")
message(WARNING "ebpfpub could not correctly import the LLVM libraries. BPF support has been disabled")
else()
message(FATAL_ERROR "The '${library}' library was found but it couldn't be imported correctly")
endif()
endif()
endforeach()
endfunction()
function(generateInstallDirectives)
get_property(augeas_lenses_path
GLOBAL PROPERTY "AUGEAS_LENSES_FOLDER_PATH"
)
if(PLATFORM_LINUX)
install(
FILES "tools/deployment/linux_packaging/deb/conffiles"
DESTINATION "/control/deb"
)
install(
FILES "tools/deployment/linux_packaging/deb/osqueryd.service"
DESTINATION "/control/deb/lib/systemd/system"
)
install(
FILES "tools/deployment/linux_packaging/deb/copyright"
DESTINATION "/control/deb"
)
install(
FILES "tools/deployment/linux_packaging/deb/osquery.initd"
DESTINATION "/control/deb/etc/init.d"
RENAME "osqueryd"
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
install(
FILES "tools/deployment/linux_packaging/rpm/osquery.initd"
DESTINATION "/control/rpm/etc/init.d"
RENAME "osqueryd"
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
install(
FILES "tools/deployment/linux_packaging/rpm/osqueryd.service"
DESTINATION "/control/rpm/lib/systemd/system"
)
install(
FILES "tools/deployment/linux_packaging/postinst"
DESTINATION "/control"
)
install(
TARGETS osqueryd
DESTINATION "bin"
)
execute_process(
COMMAND "${CMAKE_COMMAND}" -E create_symlink osqueryd osqueryi
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/osqueryi"
DESTINATION "bin"
)
install(
FILES "tools/deployment/osqueryctl"
DESTINATION "bin"
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
install(
FILES "tools/deployment/osquery.example.conf"
DESTINATION "share/osquery"
)
install(
DIRECTORY "${augeas_lenses_path}/"
DESTINATION "share/osquery/lenses"
FILES_MATCHING PATTERN "*.aug"
PATTERN "tests" EXCLUDE
)
install(
FILES "${augeas_lenses_path}/../COPYING"
DESTINATION "share/osquery/lenses"
)
install(
DIRECTORY "packs"
DESTINATION "share/osquery"
)
install(
FILES "${CMAKE_SOURCE_DIR}/tools/deployment/certs.pem"
DESTINATION "share/osquery/certs"
)
install(
FILES "tools/deployment/linux_packaging/osqueryd.sysconfig"
DESTINATION "/control/deb/etc/default"
RENAME "osqueryd"
)
install(
FILES "tools/deployment/linux_packaging/osqueryd.sysconfig"
DESTINATION "/control/rpm/etc/sysconfig"
RENAME "osqueryd"
)
install(
FILES "LICENSE"
DESTINATION "/control"
RENAME "LICENSE.txt"
)
elseif(PLATFORM_WINDOWS)
# CMake doesn't prefer 'Program Files' on x64 platforms, more information
# here: https://gitlab.kitware.com/cmake/cmake/-/issues/18312
# This is a workaround, to ensure that we leverage 'Program Files' when
# on a 64 bit system.
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
set(CMAKE_INSTALL_PREFIX "/Program Files/${CMAKE_PROJECT_NAME}" CACHE PATH "" FORCE)
else()
set(CMAKE_INSTALL_PREFIX "/Program Files (x86)/${CMAKE_PROJECT_NAME}" CACHE PATH "" FORCE)
endif()
endif()
install(
TARGETS osqueryd
DESTINATION "osqueryd"
)
install(
PROGRAMS "$<TARGET_FILE:osqueryd>"
DESTINATION "."
RENAME "osqueryi.exe"
)
install(
DIRECTORY "tools/deployment/windows_packaging/chocolatey/tools"
DESTINATION "/control/nupkg"
)
install(
FILES "LICENSE"
DESTINATION "/control/nupkg/extras"
RENAME "LICENSE.txt"
)
install(
FILES "LICENSE"
DESTINATION "/control"
RENAME "LICENSE.txt"
)
install(
FILES "tools/deployment/windows_packaging/osquery.ico"
DESTINATION "/control"
)
install(
FILES "tools/deployment/windows_packaging/chocolatey/VERIFICATION.txt"
DESTINATION "/control/nupkg/extras"
)
install(
FILES "tools/deployment/osquery.example.conf"
DESTINATION "."
RENAME "osquery.conf"
)
install(
FILES "tools/wel/osquery.man"
DESTINATION "."
)
install(
FILES "tools/deployment/windows_packaging/manage-osqueryd.ps1"
DESTINATION "."
)
install(
FILES "tools/deployment/windows_packaging/osquery_utils.ps1"
DESTINATION "."
)
install(
FILES "tools/deployment/windows_packaging/osquery.flags"
DESTINATION "."
)
install(
FILES "tools/deployment/windows_packaging/manage-osqueryd.ps1"
DESTINATION "/control/nupkg/extras"
)
install(
FILES "tools/deployment/windows_packaging/osquery_utils.ps1"
DESTINATION "/control/nupkg/tools"
)
install(
FILES "tools/deployment/windows_packaging/msi/osquery_wix_patch.xml"
DESTINATION "/control/msi"
)
install(
FILES "tools/deployment/certs.pem"
DESTINATION "certs"
)
install(
DIRECTORY
DESTINATION "log"
)
elseif(PLATFORM_MACOS)
install(
FILES
"tools/deployment/macos_packaging/osquery.entitlements"
DESTINATION
"/control"
)
install(
FILES
"tools/deployment/macos_packaging/pkg/productbuild.sh"
DESTINATION
"/control/pkg"
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
install(
TARGETS osqueryd
DESTINATION "bin"
)
execute_process(
COMMAND "${CMAKE_COMMAND}" -E create_symlink osqueryd osqueryi
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/osqueryi"
DESTINATION "bin"
)
install(
FILES "tools/deployment/osqueryctl"
DESTINATION "bin"
)
install(
DIRECTORY "${augeas_lenses_path}"
DESTINATION "/private/var/osquery"
FILES_MATCHING PATTERN "*.aug"
PATTERN "tests" EXCLUDE
)
install(
DIRECTORY "packs"
DESTINATION "/private/var/osquery"
)
install(
FILES "tools/deployment/certs.pem"
DESTINATION "/private/var/osquery/certs"
)
install(
FILES
"tools/deployment/osquery.example.conf"
DESTINATION
"/private/var/osquery"
)
install(
FILES
"tools/deployment/macos_packaging/pkg/com.facebook.osqueryd.conf"
"tools/deployment/macos_packaging/pkg/com.facebook.osqueryd.plist"
DESTINATION
"/control/pkg"
)
install(
FILES "LICENSE"
DESTINATION "/control"
RENAME "LICENSE.txt"
)
else()
message(FATAL_ERROR "Unsupported platform")
endif()
endfunction()
main()