tcprtt: fix compatibility for python3
[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 project(bcc)
6 if(NOT CMAKE_BUILD_TYPE)
7   set(CMAKE_BUILD_TYPE Release)
8 endif()
9
10 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
11   set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "path to install" FORCE)
12 endif()
13
14 enable_testing()
15
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})
21    else()
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})
27         else()
28                 message(WARNING "submodule libbpf dirty, so no sync")
29         endif()
30    endif()
31 endif()
32
33 # It's possible to use other kernel headers with
34 # KERNEL_INCLUDE_DIRS build variable, like:
35 #  $ cd <kernel-dir>
36 #  $ make INSTALL_HDR_PATH=/tmp/headers headers_install
37 #  $ cd <bcc-dir>
38 #  $ cmake -DKERNEL_INCLUDE_DIRS=/tmp/headers/include/ ...
39 include_directories(${KERNEL_INCLUDE_DIRS})
40
41 option(ENABLE_NO_PIE "Build bcc-lua without PIE" ON)
42
43 include(cmake/GetGitRevisionDescription.cmake)
44 include(cmake/version.cmake)
45 include(CMakeDependentOption)
46 include(GNUInstallDirs)
47 include(CheckCXXCompilerFlag)
48 include(cmake/FindCompilerFlag.cmake)
49
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)
59
60 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
61
62 if (CMAKE_USE_LIBBPF_PACKAGE)
63   find_package(LibBpf)
64 endif()
65
66 if(NOT PYTHON_ONLY)
67 find_package(LLVM REQUIRED CONFIG)
68 message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS} ${LLVM_PACKAGE_VERSION}")
69
70 if(ENABLE_CLANG_JIT)
71 find_package(BISON)
72 find_package(FLEX)
73 find_package(LibElf REQUIRED)
74 find_package(LibDebuginfod)
75 if(CLANG_DIR)
76   set(CMAKE_FIND_ROOT_PATH "${CLANG_DIR}")
77   include_directories("${CLANG_DIR}/include")
78 endif()
79
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")
99 endif()
100 FOREACH(DIR ${LLVM_INCLUDE_DIRS})
101   include_directories("${DIR}/../tools/clang/include")
102 ENDFOREACH()
103 endif(ENABLE_CLANG_JIT)
104
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")
109 endif()
110
111 if(NOT DEFINED BCC_PROG_TAG_DIR)
112   set(BCC_PROG_TAG_DIR "/var/tmp/bcc")
113 endif()
114
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}")
125   endforeach()
126 endif()
127
128 set(CMAKE_CXX_STANDARD_REQUIRED ON)
129 set(CMAKE_CXX_STANDARD 14)
130
131 endif(NOT PYTHON_ONLY)
132
133 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
134 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
135
136 add_subdirectory(src)
137 add_subdirectory(introspection)
138 if(ENABLE_CLANG_JIT)
139 if(ENABLE_EXAMPLES)
140 add_subdirectory(examples)
141 endif(ENABLE_EXAMPLES)
142 if(ENABLE_MAN)
143 add_subdirectory(man)
144 endif(ENABLE_MAN)
145 if(ENABLE_TESTS)
146 add_subdirectory(tests)
147 endif(ENABLE_TESTS)
148 add_subdirectory(tools)
149 endif(ENABLE_CLANG_JIT)