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