• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) PLUMgrid, Inc.
2# Licensed under the Apache License, Version 2.0 (the "License")
3cmake_minimum_required(VERSION 2.8.7)
4
5if (${CMAKE_VERSION} VERSION_EQUAL 3.12.0 OR ${CMAKE_VERSION} VERSION_GREATER 3.12.0)
6  cmake_policy(SET CMP0074 NEW)
7endif()
8
9project(bcc)
10if(NOT CMAKE_BUILD_TYPE)
11  set(CMAKE_BUILD_TYPE Release)
12endif()
13
14if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
15  set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "path to install" FORCE)
16endif()
17
18enable_testing()
19
20# populate submodules (libbpf)
21if(NOT CMAKE_USE_LIBBPF_PACKAGE)
22   if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/cc/libbpf/src)
23	execute_process(COMMAND git submodule update --init --recursive
24                  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
25                  RESULT_VARIABLE UPDATE_RESULT)
26  if(UPDATE_RESULT AND NOT UPDATE_RESULT EQUAL 0)
27    message(WARNING "Failed to update submodule libbpf")
28  endif()
29   else()
30	execute_process(COMMAND git diff --shortstat ${CMAKE_CURRENT_SOURCE_DIR}/src/cc/libbpf/
31		OUTPUT_VARIABLE DIFF_STATUS)
32	if("${DIFF_STATUS}" STREQUAL "")
33		execute_process(COMMAND git submodule update --init --recursive
34                    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
35                    RESULT_VARIABLE UPDATE_RESULT)
36  if(UPDATE_RESULT AND NOT UPDATE_RESULT EQUAL 0)
37    message(WARNING "Failed to update submodule libbpf")
38  endif()
39	else()
40		message(WARNING "submodule libbpf dirty, so no sync")
41	endif()
42   endif()
43endif()
44
45# It's possible to use other kernel headers with
46# KERNEL_INCLUDE_DIRS build variable, like:
47#  $ cd <kernel-dir>
48#  $ make INSTALL_HDR_PATH=/tmp/headers headers_install
49#  $ cd <bcc-dir>
50#  $ cmake -DKERNEL_INCLUDE_DIRS=/tmp/headers/include/ ...
51include_directories(${KERNEL_INCLUDE_DIRS})
52
53option(ENABLE_NO_PIE "Build bcc-lua without PIE" ON)
54
55include(cmake/GetGitRevisionDescription.cmake)
56include(cmake/version.cmake)
57include(CMakeDependentOption)
58include(GNUInstallDirs)
59include(CheckCXXCompilerFlag)
60include(cmake/FindCompilerFlag.cmake)
61
62option(ENABLE_LLVM_NATIVECODEGEN "Enable use of llvm nativecodegen module (needed by rw-engine)" ON)
63option(ENABLE_RTTI "Enable compiling with real time type information" OFF)
64option(ENABLE_LLVM_SHARED "Enable linking LLVM as a shared library" OFF)
65option(ENABLE_CLANG_JIT "Enable Loading BPF through Clang Frontend" ON)
66option(ENABLE_USDT "Enable User-level Statically Defined Tracing" ON)
67option(ENABLE_EXAMPLES "Build examples" ON)
68option(ENABLE_MAN "Build man pages" ON)
69option(ENABLE_TESTS "Build tests" ON)
70option(RUN_LUA_TESTS "Run lua tests" ON)
71CMAKE_DEPENDENT_OPTION(ENABLE_CPP_API "Enable C++ API" ON "ENABLE_USDT" OFF)
72
73set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
74
75if (CMAKE_USE_LIBBPF_PACKAGE)
76  find_package(LibBpf)
77endif()
78
79if(NOT PYTHON_ONLY)
80find_package(LLVM REQUIRED CONFIG)
81message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS} ${LLVM_PACKAGE_VERSION} (Use LLVM_ROOT envronment variable for another version of LLVM)")
82
83if(ENABLE_CLANG_JIT)
84find_package(BISON)
85find_package(FLEX)
86find_package(LibElf REQUIRED)
87find_package(LibDebuginfod)
88if(CLANG_DIR)
89  set(CMAKE_FIND_ROOT_PATH "${CLANG_DIR}")
90  include_directories("${CLANG_DIR}/include")
91endif()
92
93# clang is linked as a library, but the library path searching is
94# primitively supported, unlike libLLVM
95set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}")
96find_library(libclangAnalysis NAMES clangAnalysis clang-cpp HINTS ${CLANG_SEARCH})
97find_library(libclangAST NAMES clangAST clang-cpp HINTS ${CLANG_SEARCH})
98find_library(libclangBasic NAMES clangBasic clang-cpp HINTS ${CLANG_SEARCH})
99find_library(libclangCodeGen NAMES clangCodeGen clang-cpp HINTS ${CLANG_SEARCH})
100find_library(libclangDriver NAMES clangDriver clang-cpp HINTS ${CLANG_SEARCH})
101find_library(libclangEdit NAMES clangEdit clang-cpp HINTS ${CLANG_SEARCH})
102find_library(libclangFrontend NAMES clangFrontend clang-cpp HINTS ${CLANG_SEARCH})
103find_library(libclangLex NAMES clangLex clang-cpp HINTS ${CLANG_SEARCH})
104find_library(libclangParse NAMES clangParse clang-cpp HINTS ${CLANG_SEARCH})
105find_library(libclangRewrite NAMES clangRewrite clang-cpp HINTS ${CLANG_SEARCH})
106find_library(libclangSema NAMES clangSema clang-cpp HINTS ${CLANG_SEARCH})
107find_library(libclangSerialization NAMES clangSerialization clang-cpp HINTS ${CLANG_SEARCH})
108find_library(libclangASTMatchers NAMES clangASTMatchers clang-cpp HINTS ${CLANG_SEARCH})
109find_library(libclang-shared libclang-cpp.so HINTS ${CLANG_SEARCH})
110if(libclangBasic STREQUAL "libclangBasic-NOTFOUND")
111  message(FATAL_ERROR "Unable to find clang libraries")
112endif()
113FOREACH(DIR ${LLVM_INCLUDE_DIRS})
114  include_directories("${DIR}/../tools/clang/include")
115ENDFOREACH()
116endif(ENABLE_CLANG_JIT)
117
118# Set to a string path if system places kernel lib directory in
119# non-default location.
120if(NOT DEFINED BCC_KERNEL_MODULES_DIR)
121  set(BCC_KERNEL_MODULES_DIR "/lib/modules")
122endif()
123
124if(NOT DEFINED BCC_PROG_TAG_DIR)
125  set(BCC_PROG_TAG_DIR "/var/tmp/bcc")
126endif()
127
128# As reported in issue #735, GCC 6 has some behavioral problems when
129# dealing with -isystem. Hence, skip the warning optimization
130# altogether on that compiler.
131option(USINGISYSTEM "using -isystem" ON)
132execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
133if (USINGISYSTEM AND GCC_VERSION VERSION_LESS 6.0)
134  # iterate over all available directories in LLVM_INCLUDE_DIRS to
135  # generate a correctly tokenized list of parameters
136  foreach(ONE_LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
137    set(CXX_ISYSTEM_DIRS "${CXX_ISYSTEM_DIRS} -isystem ${ONE_LLVM_INCLUDE_DIR}")
138  endforeach()
139endif()
140
141set(CMAKE_CXX_STANDARD_REQUIRED ON)
142set(CMAKE_CXX_STANDARD 14)
143
144endif(NOT PYTHON_ONLY)
145
146set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
147set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
148
149add_subdirectory(src)
150add_subdirectory(introspection)
151if(ENABLE_CLANG_JIT)
152if(ENABLE_EXAMPLES)
153add_subdirectory(examples)
154endif(ENABLE_EXAMPLES)
155if(ENABLE_MAN)
156add_subdirectory(man)
157endif(ENABLE_MAN)
158if(ENABLE_TESTS)
159add_subdirectory(tests)
160endif(ENABLE_TESTS)
161add_subdirectory(tools)
162endif(ENABLE_CLANG_JIT)
163