-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
244 lines (204 loc) · 9.28 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
# Copyright (c) PLUMgrid, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
cmake_minimum_required(VERSION 2.8.12)
if(${CMAKE_VERSION} VERSION_EQUAL 3.12.0 OR ${CMAKE_VERSION} VERSION_GREATER 3.12.0)
cmake_policy(SET CMP0074 NEW)
endif()
if(${CMAKE_VERSION} VERSION_EQUAL 3.3.0 OR ${CMAKE_VERSION} VERSION_GREATER 3.3.0)
cmake_policy(SET CMP0057 NEW)
endif()
project(bcc)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
if(CMAKE_SANITIZE_TYPE)
add_compile_options(-fsanitize=${CMAKE_SANITIZE_TYPE})
add_link_options(-fsanitize=${CMAKE_SANITIZE_TYPE})
endif()
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "path to install" FORCE)
endif()
enable_testing()
execute_process(COMMAND git config --global --add safe.directory ${CMAKE_CURRENT_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE CONFIG_RESULT)
if(CONFIG_RESULT AND NOT CONFIG_RESULT EQUAL 0)
message(WARNING "Failed to add root source directory to safe.directory")
endif()
# populate submodule blazesym
if(NOT NO_BLAZESYM)
execute_process(COMMAND git config --global --add safe.directory ${CMAKE_CURRENT_SOURCE_DIR}/libbpf-tools/blazesym
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE CONFIG_RESULT)
if(CONFIG_RESULT AND NOT CONFIG_RESULT EQUAL 0)
message(WARNING "Failed to add blazesym source directory to safe.directory")
endif()
execute_process(COMMAND git submodule update --init --recursive -- libbpf-tools/blazesym
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE UPDATE_RESULT)
if(UPDATE_RESULT AND NOT UPDATE_RESULT EQUAL 0)
message(WARNING "Failed to update submodule blazesym")
endif()
endif()
# populate submodules (libbpf)
if(NOT CMAKE_USE_LIBBPF_PACKAGE)
execute_process(COMMAND git config --global --add safe.directory ${CMAKE_CURRENT_SOURCE_DIR}/src/cc/libbpf
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE CONFIG_RESULT)
if(CONFIG_RESULT AND NOT CONFIG_RESULT EQUAL 0)
message(WARNING "Failed to add libbpf source directory to safe.directory")
endif()
execute_process(COMMAND git config --global --add safe.directory ${CMAKE_CURRENT_SOURCE_DIR}/libbpf-tools/bpftool
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE CONFIG_RESULT)
if(CONFIG_RESULT AND NOT CONFIG_RESULT EQUAL 0)
message(WARNING "Failed to add bpftool source directory to safe.directory")
endif()
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/cc/libbpf/src)
execute_process(COMMAND git submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE UPDATE_RESULT)
if(UPDATE_RESULT AND NOT UPDATE_RESULT EQUAL 0)
message(WARNING "Failed to update submodule libbpf")
endif()
else()
execute_process(COMMAND git diff --shortstat ${CMAKE_CURRENT_SOURCE_DIR}/src/cc/libbpf/
OUTPUT_VARIABLE DIFF_STATUS)
if("${DIFF_STATUS}" STREQUAL "")
execute_process(COMMAND git submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE UPDATE_RESULT)
if(UPDATE_RESULT AND NOT UPDATE_RESULT EQUAL 0)
message(WARNING "Failed to update submodule libbpf")
endif()
else()
message(WARNING "submodule libbpf dirty, so no sync")
endif()
endif()
endif()
# It's possible to use other kernel headers with
# KERNEL_INCLUDE_DIRS build variable, like:
# $ cd <kernel-dir>
# $ make INSTALL_HDR_PATH=/tmp/headers headers_install
# $ cd <bcc-dir>
# $ cmake -DKERNEL_INCLUDE_DIRS=/tmp/headers/include/ ...
include_directories(${KERNEL_INCLUDE_DIRS})
option(ENABLE_NO_PIE "Build bcc-lua without PIE" ON)
include(cmake/GetGitRevisionDescription.cmake)
include(cmake/version.cmake)
include(CMakeDependentOption)
include(GNUInstallDirs)
include(CheckCXXCompilerFlag)
include(cmake/FindCompilerFlag.cmake)
option(ENABLE_LLVM_NATIVECODEGEN "Enable use of llvm nativecodegen module (needed by rw-engine)" ON)
option(ENABLE_RTTI "Enable compiling with real time type information" OFF)
option(ENABLE_LLVM_SHARED "Enable linking LLVM as a shared library" OFF)
option(ENABLE_CLANG_JIT "Enable Loading BPF through Clang Frontend" ON)
option(ENABLE_USDT "Enable User-level Statically Defined Tracing" ON)
option(ENABLE_EXAMPLES "Build examples" ON)
option(ENABLE_MAN "Build man pages" ON)
option(ENABLE_TESTS "Build tests" ON)
option(RUN_LUA_TESTS "Run lua tests" ON)
option(ENABLE_LIBDEBUGINFOD "Use libdebuginfod as a source of debug symbols" ON)
CMAKE_DEPENDENT_OPTION(ENABLE_CPP_API "Enable C++ API" ON "ENABLE_USDT" OFF)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if(ENABLE_TESTS)
find_package(KernelHeaders)
endif()
if(CMAKE_USE_LIBBPF_PACKAGE)
find_package(LibBpf)
endif()
if(NOT PYTHON_ONLY)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS} ${LLVM_PACKAGE_VERSION} (Use LLVM_ROOT envronment variable for another version of LLVM)")
if(ENABLE_CLANG_JIT)
find_package(BISON)
find_package(FLEX)
find_package(LibElf REQUIRED)
find_package(LibDebuginfod)
find_package(LibLzma)
if(CLANG_DIR)
set(CMAKE_FIND_ROOT_PATH "${CLANG_DIR}")
include_directories("${CLANG_DIR}/include")
endif()
# clang is linked as a library, but the library path searching is
# primitively supported, unlike libLLVM
set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}")
find_library(libclangAnalysis NAMES clangAnalysis clang-cpp HINTS ${CLANG_SEARCH})
find_library(libclangAST NAMES clangAST clang-cpp HINTS ${CLANG_SEARCH})
find_library(libclangBasic NAMES clangBasic clang-cpp HINTS ${CLANG_SEARCH})
find_library(libclangCodeGen NAMES clangCodeGen clang-cpp HINTS ${CLANG_SEARCH})
find_library(libclangDriver NAMES clangDriver clang-cpp HINTS ${CLANG_SEARCH})
find_library(libclangEdit NAMES clangEdit clang-cpp HINTS ${CLANG_SEARCH})
find_library(libclangFrontend NAMES clangFrontend clang-cpp HINTS ${CLANG_SEARCH})
find_library(libclangLex NAMES clangLex clang-cpp HINTS ${CLANG_SEARCH})
find_library(libclangParse NAMES clangParse clang-cpp HINTS ${CLANG_SEARCH})
find_library(libclangRewrite NAMES clangRewrite clang-cpp HINTS ${CLANG_SEARCH})
find_library(libclangSema NAMES clangSema clang-cpp HINTS ${CLANG_SEARCH})
find_library(libclangSerialization NAMES clangSerialization clang-cpp HINTS ${CLANG_SEARCH})
find_library(libclangASTMatchers NAMES clangASTMatchers clang-cpp HINTS ${CLANG_SEARCH})
if(${LLVM_PACKAGE_VERSION} VERSION_EQUAL 15 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 15)
find_library(libclangSupport NAMES clangSupport clang-cpp HINTS ${CLANG_SEARCH})
endif()
if(${LLVM_PACKAGE_VERSION} VERSION_EQUAL 18 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 18)
find_library(libclangAPINotes NAMES clangAPINotes clang-cpp HINTS ${CLANG_SEARCH})
endif()
find_library(libclang-shared libclang-cpp.so HINTS ${CLANG_SEARCH})
if(libclangBasic STREQUAL "libclangBasic-NOTFOUND")
message(FATAL_ERROR "Unable to find clang libraries")
endif()
FOREACH(DIR ${LLVM_INCLUDE_DIRS})
include_directories("${DIR}/../tools/clang/include")
ENDFOREACH()
endif(ENABLE_CLANG_JIT)
# Set to a string path if system places kernel lib directory in
# non-default location.
if(NOT DEFINED BCC_KERNEL_MODULES_DIR)
set(BCC_KERNEL_MODULES_DIR "/lib/modules")
endif()
if(NOT DEFINED BCC_PROG_TAG_DIR)
set(BCC_PROG_TAG_DIR "/var/tmp/bcc")
endif()
# As reported in issue #735, GCC 6 has some behavioral problems when
# dealing with -isystem. Hence, skip the warning optimization
# altogether on that compiler.
option(USINGISYSTEM "using -isystem" ON)
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if(USINGISYSTEM AND GCC_VERSION VERSION_LESS 6.0)
# iterate over all available directories in LLVM_INCLUDE_DIRS to
# generate a correctly tokenized list of parameters
foreach(ONE_LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
set(CXX_ISYSTEM_DIRS "${CXX_ISYSTEM_DIRS} -isystem ${ONE_LLVM_INCLUDE_DIR}")
endforeach()
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(${LLVM_PACKAGE_VERSION} VERSION_EQUAL 16 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 16)
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 14)
endif()
endif(NOT PYTHON_ONLY)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
add_subdirectory(src)
add_subdirectory(introspection)
if(ENABLE_CLANG_JIT)
if(ENABLE_EXAMPLES)
add_subdirectory(examples)
endif(ENABLE_EXAMPLES)
if(ENABLE_MAN)
add_subdirectory(man)
endif(ENABLE_MAN)
if(ENABLE_TESTS)
add_subdirectory(tests)
endif(ENABLE_TESTS)
add_subdirectory(tools)
endif(ENABLE_CLANG_JIT)
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CmakeUninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CmakeUninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/CmakeUninstall.cmake)
endif()