-
Notifications
You must be signed in to change notification settings - Fork 36
/
CMakeLists.txt
166 lines (131 loc) · 5.7 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
# Copyright (c) 2018 Trail of Bits, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.10)
project("trailofbits_extensions")
set(TOB_ROOT_TEST_TARGET "trailofbits_extensions_tests")
set(TOB_EXTENSIONS_ROOT "${CMAKE_CURRENT_SOURCE_DIR}" CACHE STRING "TOB extensions root directory")
set(OSQUERY_EXTENSION_GROUP_NAME "trailofbits_osquery_extensions" CACHE STRING "Overrides osquery extension group name" FORCE)
set(OSQUERY_EXTENSION_GROUP_VERSION "1.2" CACHE STRING "Overrides osquery extension group version" FORCE)
function(trailofbitsExtensionsMain)
message(STATUS "================================")
message(STATUS "Trail of Bits osquery extensions")
message(STATUS "Version: ${OSQUERY_EXTENSION_GROUP_VERSION}")
message(STATUS "================================")
if(NOT (${OSQUERY_VERSION_INTERNAL} VERSION_EQUAL "4.1.0" OR
${OSQUERY_VERSION_INTERNAL} VERSION_GREATER "4.1.0"))
message(WARNING "Detected osquery version ${OSQUERY_VERSION_INTERNAL}: This version is unsupported, please use version 4.1.0 or greater")
return()
endif()
add_custom_target("${TOB_ROOT_TEST_TARGET}")
ImportLibraries()
ImportExtensions()
message(STATUS "================================")
endfunction()
function(ImportLibraries)
message("Importing libraries from '${CMAKE_CURRENT_SOURCE_DIR}/libraries/${library}'")
file(GLOB library_list RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/libraries" "${CMAKE_CURRENT_SOURCE_DIR}/libraries/*")
foreach(library ${library_list})
set(full_library_path "${CMAKE_CURRENT_SOURCE_DIR}/libraries/${library}")
if(NOT IS_DIRECTORY "${full_library_path}")
continue()
endif()
IsFolderEnabled("libraries/${library}")
if(NOT "${IsFolderEnabled_OUTPUT}")
continue()
endif()
message(" > ${library}")
add_subdirectory("${full_library_path}" "libraries/${library}")
endforeach()
endfunction()
function(ImportDependency dependency_name)
set(dependency_path "${TOB_EXTENSIONS_ROOT}/opt_dependencies/${dependency_name}")
message("Importing dependency '${dependency_name}' from '${dependency_path}'")
add_subdirectory("${dependency_path}" "opt_dependencies/${dependency_name}")
endfunction()
function(ImportExtensions)
message("Importing extensions from '${CMAKE_CURRENT_SOURCE_DIR}'")
if (DEFINED ENV{TRAILOFBITS_EXTENSIONS_TO_BUILD})
set(extensions_to_build $ENV{TRAILOFBITS_EXTENSIONS_TO_BUILD})
string(REPLACE "," ";" extensions_to_build "${extensions_to_build}")
endif()
file(GLOB extension_list RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/*")
foreach(extension ${extension_list})
if("${extension}" STREQUAL ".vscode")
continue()
endif()
set(full_extension_path "${CMAKE_CURRENT_SOURCE_DIR}/${extension}")
if(NOT IS_DIRECTORY "${full_extension_path}")
continue()
endif()
if("${extension}" STREQUAL "libraries" OR "${extension}" STREQUAL ".git" OR "${extension}" STREQUAL "opt_dependencies")
continue()
endif()
if (DEFINED extensions_to_build AND NOT "${extension}" IN_LIST extensions_to_build)
continue()
endif()
IsFolderEnabled("${extension}")
if(NOT "${IsFolderEnabled_OUTPUT}")
continue()
endif()
message(" > ${extension}")
add_subdirectory("${extension}" "extensions/${extension}")
endforeach()
endfunction()
function(IsFolderEnabled relative_path)
set(platforms_file_path "${CMAKE_CURRENT_SOURCE_DIR}/${relative_path}/.platforms")
if(NOT EXISTS "${platforms_file_path}")
message(" ! Missing '.platforms` file: ${relative_path}. Skipping...")
set(IsFolderEnabled_OUTPUT false PARENT_SCOPE)
return()
endif()
file(READ "${platforms_file_path}" supported_platforms)
if(PLATFORM_WINDOWS AND "${supported_platforms}" MATCHES "WINDOWS")
set(IsFolderEnabled_OUTPUT true PARENT_SCOPE)
elseif(PLATFORM_MACOS AND "${supported_platforms}" MATCHES "APPLE")
set(IsFolderEnabled_OUTPUT true PARENT_SCOPE)
elseif(PLATFORM_LINUX AND "${supported_platforms}" MATCHES "LINUX")
set(IsFolderEnabled_OUTPUT true PARENT_SCOPE)
else()
set(IsFolderEnabled_OUTPUT false PARENT_SCOPE)
endif()
endfunction()
function(AddTest test_name out_executable_target_name)
set(target_name "tobExtTests_${test_name}")
add_executable("${target_name}" EXCLUDE_FROM_ALL ${ARGN})
if(UNIX)
if(APPLE)
target_compile_definitions("${target_name}" PRIVATE APPLE)
else()
target_compile_definitions("${target_name}" PRIVATE LINUX)
endif()
else()
target_compile_definitions("${target_name}" PRIVATE WINDOWS)
endif()
add_custom_target("${target_name}_runner"
COMMAND ${command_prefix} $<TARGET_FILE:${target_name}>
COMMENT "Running test: ${target_name}"
)
add_dependencies("${TOB_ROOT_TEST_TARGET}" "${target_name}_runner")
target_link_libraries("${target_name}" PRIVATE
osquery_sdk_pluginsdk
osquery_extensions_implthrift
thirdparty_googletest
)
# Return the executable target name to the caller
set("${out_executable_target_name}" "${target_name}" PARENT_SCOPE)
endfunction()
trailofbitsExtensionsMain()
# If the user has generated extensions using the new generate_osquery_extension_group
# function, then this call will generate the bundle
generateOsqueryExtensionGroup()