1 # Copyright (c) PLUMgrid, Inc.
2 # Licensed under the Apache License, Version 2.0 (the "License")
3 cmake_minimum_required(VERSION 2.8.7)
6 if(NOT CMAKE_BUILD_TYPE)
7 set(CMAKE_BUILD_TYPE Release)
10 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
11 set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "path to install" FORCE)
16 # populate submodules (libbpf)
17 if(NOT CMAKE_USE_LIBBPF_PACKAGE)
18 if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/cc/libbpf/src)
19 execute_process(COMMAND git submodule update --init --recursive
20 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
22 execute_process(COMMAND git diff --shortstat ${CMAKE_CURRENT_SOURCE_DIR}/src/cc/libbpf/
23 OUTPUT_VARIABLE DIFF_STATUS)
24 if("${DIFF_STATUS}" STREQUAL "")
25 execute_process(COMMAND git submodule update --init --recursive
26 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
28 message(WARNING "submodule libbpf dirty, so no sync")
33 # It's possible to use other kernel headers with
34 # KERNEL_INCLUDE_DIRS build variable, like:
36 # $ make INSTALL_HDR_PATH=/tmp/headers headers_install
38 # $ cmake -DKERNEL_INCLUDE_DIRS=/tmp/headers/include/ ...
39 include_directories(${KERNEL_INCLUDE_DIRS})
41 option(ENABLE_NO_PIE "Build bcc-lua without PIE" ON)
43 include(cmake/GetGitRevisionDescription.cmake)
44 include(cmake/version.cmake)
45 include(CMakeDependentOption)
46 include(GNUInstallDirs)
47 include(CheckCXXCompilerFlag)
48 include(cmake/FindCompilerFlag.cmake)
50 option(ENABLE_LLVM_NATIVECODEGEN "Enable use of llvm nativecodegen module (needed by rw-engine)" ON)
51 option(ENABLE_RTTI "Enable compiling with real time type information" OFF)
52 option(ENABLE_LLVM_SHARED "Enable linking LLVM as a shared library" OFF)
53 option(ENABLE_CLANG_JIT "Enable Loading BPF through Clang Frontend" ON)
54 option(ENABLE_USDT "Enable User-level Statically Defined Tracing" ON)
55 option(ENABLE_EXAMPLES "Build examples" ON)
56 option(ENABLE_MAN "Build man pages" ON)
57 option(ENABLE_TESTS "Build tests" ON)
58 CMAKE_DEPENDENT_OPTION(ENABLE_CPP_API "Enable C++ API" ON "ENABLE_USDT" OFF)
60 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
62 if (CMAKE_USE_LIBBPF_PACKAGE)
67 find_package(LLVM REQUIRED CONFIG)
68 message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS} ${LLVM_PACKAGE_VERSION}")
73 find_package(LibElf REQUIRED)
74 find_package(LibDebuginfod)
76 set(CMAKE_FIND_ROOT_PATH "${CLANG_DIR}")
77 include_directories("${CLANG_DIR}/include")
80 # clang is linked as a library, but the library path searching is
81 # primitively supported, unlike libLLVM
82 set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}")
83 find_library(libclangAnalysis NAMES clangAnalysis clang-cpp HINTS ${CLANG_SEARCH})
84 find_library(libclangAST NAMES clangAST clang-cpp HINTS ${CLANG_SEARCH})
85 find_library(libclangBasic NAMES clangBasic clang-cpp HINTS ${CLANG_SEARCH})
86 find_library(libclangCodeGen NAMES clangCodeGen clang-cpp HINTS ${CLANG_SEARCH})
87 find_library(libclangDriver NAMES clangDriver clang-cpp HINTS ${CLANG_SEARCH})
88 find_library(libclangEdit NAMES clangEdit clang-cpp HINTS ${CLANG_SEARCH})
89 find_library(libclangFrontend NAMES clangFrontend clang-cpp HINTS ${CLANG_SEARCH})
90 find_library(libclangLex NAMES clangLex clang-cpp HINTS ${CLANG_SEARCH})
91 find_library(libclangParse NAMES clangParse clang-cpp HINTS ${CLANG_SEARCH})
92 find_library(libclangRewrite NAMES clangRewrite clang-cpp HINTS ${CLANG_SEARCH})
93 find_library(libclangSema NAMES clangSema clang-cpp HINTS ${CLANG_SEARCH})
94 find_library(libclangSerialization NAMES clangSerialization clang-cpp HINTS ${CLANG_SEARCH})
95 find_library(libclangASTMatchers NAMES clangASTMatchers clang-cpp HINTS ${CLANG_SEARCH})
96 find_library(libclang-shared libclang-cpp.so HINTS ${CLANG_SEARCH})
97 if(libclangBasic STREQUAL "libclangBasic-NOTFOUND")
98 message(FATAL_ERROR "Unable to find clang libraries")
100 FOREACH(DIR ${LLVM_INCLUDE_DIRS})
101 include_directories("${DIR}/../tools/clang/include")
103 endif(ENABLE_CLANG_JIT)
105 # Set to a string path if system places kernel lib directory in
106 # non-default location.
107 if(NOT DEFINED BCC_KERNEL_MODULES_DIR)
108 set(BCC_KERNEL_MODULES_DIR "/lib/modules")
111 if(NOT DEFINED BCC_PROG_TAG_DIR)
112 set(BCC_PROG_TAG_DIR "/var/tmp/bcc")
115 # As reported in issue #735, GCC 6 has some behavioral problems when
116 # dealing with -isystem. Hence, skip the warning optimization
117 # altogether on that compiler.
118 option(USINGISYSTEM "using -isystem" ON)
119 execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
120 if (USINGISYSTEM AND GCC_VERSION VERSION_LESS 6.0)
121 # iterate over all available directories in LLVM_INCLUDE_DIRS to
122 # generate a correctly tokenized list of parameters
123 foreach(ONE_LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
124 set(CXX_ISYSTEM_DIRS "${CXX_ISYSTEM_DIRS} -isystem ${ONE_LLVM_INCLUDE_DIR}")
128 set(CMAKE_CXX_STANDARD_REQUIRED ON)
129 set(CMAKE_CXX_STANDARD 14)
131 endif(NOT PYTHON_ONLY)
133 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
134 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
136 add_subdirectory(src)
137 add_subdirectory(introspection)
140 add_subdirectory(examples)
141 endif(ENABLE_EXAMPLES)
143 add_subdirectory(man)
146 add_subdirectory(tests)
148 add_subdirectory(tools)
149 endif(ENABLE_CLANG_JIT)