Brenden Blanco | 246b942 | 2015-06-05 11:15:27 -0700 | [diff] [blame] | 1 | # Copyright (c) PLUMgrid, Inc. |
| 2 | # Licensed under the Apache License, Version 2.0 (the "License") |
Brenden Blanco | a94bd93 | 2015-04-26 00:56:42 -0700 | [diff] [blame] | 3 | cmake_minimum_required(VERSION 2.8.7) |
| 4 | |
FUJI Goro | 9fc0493 | 2021-11-19 13:40:01 +0900 | [diff] [blame] | 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 | |
Brenden Blanco | f275d3d | 2015-07-06 23:41:23 -0700 | [diff] [blame] | 9 | project(bcc) |
Gabor Buella | 31d4a59 | 2017-05-19 15:33:08 +0200 | [diff] [blame] | 10 | if(NOT CMAKE_BUILD_TYPE) |
| 11 | set(CMAKE_BUILD_TYPE Release) |
| 12 | endif() |
Brenden Blanco | cd5cb41 | 2015-04-26 09:41:58 -0700 | [diff] [blame] | 13 | |
FUJI Goro | 4c1136e | 2020-03-18 14:26:43 +0900 | [diff] [blame] | 14 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| 15 | set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "path to install" FORCE) |
| 16 | endif() |
| 17 | |
Brenden Blanco | cd5cb41 | 2015-04-26 09:41:58 -0700 | [diff] [blame] | 18 | enable_testing() |
Brenden Blanco | a94bd93 | 2015-04-26 00:56:42 -0700 | [diff] [blame] | 19 | |
Yonghong Song | fbe94dd | 2019-01-16 15:47:24 -0800 | [diff] [blame] | 20 | # populate submodules (libbpf) |
Jianpeng Ma | 3df26a5 | 2021-02-04 11:33:30 +0800 | [diff] [blame] | 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 |
Jacky_Yin | 2ddafc2 | 2021-09-10 18:54:27 +0800 | [diff] [blame] | 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() |
Jianpeng Ma | 3df26a5 | 2021-02-04 11:33:30 +0800 | [diff] [blame] | 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 |
Jacky_Yin | 2ddafc2 | 2021-09-10 18:54:27 +0800 | [diff] [blame] | 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() |
Jianpeng Ma | 3df26a5 | 2021-02-04 11:33:30 +0800 | [diff] [blame] | 39 | else() |
| 40 | message(WARNING "submodule libbpf dirty, so no sync") |
| 41 | endif() |
| 42 | endif() |
Yonghong Song | fbe94dd | 2019-01-16 15:47:24 -0800 | [diff] [blame] | 43 | endif() |
| 44 | |
Jiri Olsa | 82abd2f | 2020-05-21 16:51:30 +0200 | [diff] [blame] | 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 | |
Gary Lin | 24eeae2 | 2021-03-12 11:32:19 +0800 | [diff] [blame] | 53 | option(ENABLE_NO_PIE "Build bcc-lua without PIE" ON) |
| 54 | |
Brenden Blanco | 974e891 | 2015-09-04 09:36:37 -0700 | [diff] [blame] | 55 | include(cmake/GetGitRevisionDescription.cmake) |
| 56 | include(cmake/version.cmake) |
Brenden Blanco | 71fc3d5 | 2017-06-28 17:37:06 -0700 | [diff] [blame] | 57 | include(CMakeDependentOption) |
Brenden Blanco | 6470bbe | 2015-09-23 07:23:35 -0700 | [diff] [blame] | 58 | include(GNUInstallDirs) |
Simon Liu | 2d82c8e | 2017-04-17 09:53:58 -0500 | [diff] [blame] | 59 | include(CheckCXXCompilerFlag) |
Yonghong Song | 75e2f37 | 2017-08-23 13:40:47 -0700 | [diff] [blame] | 60 | include(cmake/FindCompilerFlag.cmake) |
Brenden Blanco | d8acf6f | 2015-06-07 22:32:33 -0700 | [diff] [blame] | 61 | |
torgil | 61c063a | 2018-12-23 08:20:21 +0100 | [diff] [blame] | 62 | option(ENABLE_LLVM_NATIVECODEGEN "Enable use of llvm nativecodegen module (needed by rw-engine)" ON) |
torgil | 4a7717d | 2018-12-12 08:12:42 +0100 | [diff] [blame] | 63 | option(ENABLE_RTTI "Enable compiling with real time type information" OFF) |
Brenden Blanco | e8001c3 | 2018-07-23 08:15:56 -0700 | [diff] [blame] | 64 | option(ENABLE_LLVM_SHARED "Enable linking LLVM as a shared library" OFF) |
Brenden Blanco | 7fef695 | 2017-08-22 15:47:12 -0700 | [diff] [blame] | 65 | option(ENABLE_CLANG_JIT "Enable Loading BPF through Clang Frontend" ON) |
| 66 | option(ENABLE_USDT "Enable User-level Statically Defined Tracing" ON) |
Marcelo Juchem | 8fac710 | 2020-12-23 17:18:41 -0800 | [diff] [blame] | 67 | option(ENABLE_EXAMPLES "Build examples" ON) |
Romain Naour | 910ddaf | 2018-12-07 22:36:21 +0100 | [diff] [blame] | 68 | option(ENABLE_MAN "Build man pages" ON) |
Marcelo Juchem | 8fac710 | 2020-12-23 17:18:41 -0800 | [diff] [blame] | 69 | option(ENABLE_TESTS "Build tests" ON) |
Dave Marchevsky | ddfedaa | 2021-12-28 22:45:22 -0500 | [diff] [blame] | 70 | option(RUN_LUA_TESTS "Run lua tests" ON) |
Brenden Blanco | 7fef695 | 2017-08-22 15:47:12 -0700 | [diff] [blame] | 71 | CMAKE_DEPENDENT_OPTION(ENABLE_CPP_API "Enable C++ API" ON "ENABLE_USDT" OFF) |
| 72 | |
Vicent Marti | ff9ff5d | 2016-04-20 13:24:54 +0200 | [diff] [blame] | 73 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) |
| 74 | |
Jiri Olsa | d4b3bf0 | 2019-10-22 21:01:00 +0200 | [diff] [blame] | 75 | if (CMAKE_USE_LIBBPF_PACKAGE) |
| 76 | find_package(LibBpf) |
| 77 | endif() |
| 78 | |
Marcelo Juchem | c06208f | 2020-12-29 11:25:35 -0800 | [diff] [blame] | 79 | if(NOT PYTHON_ONLY) |
Brenden Blanco | a94bd93 | 2015-04-26 00:56:42 -0700 | [diff] [blame] | 80 | find_package(LLVM REQUIRED CONFIG) |
FUJI Goro | 9fc0493 | 2021-11-19 13:40:01 +0900 | [diff] [blame] | 81 | message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS} ${LLVM_PACKAGE_VERSION} (Use LLVM_ROOT envronment variable for another version of LLVM)") |
Brenden Blanco | 25245bf | 2015-05-10 12:15:06 -0700 | [diff] [blame] | 82 | |
Marcelo Juchem | c06208f | 2020-12-29 11:25:35 -0800 | [diff] [blame] | 83 | if(ENABLE_CLANG_JIT) |
| 84 | find_package(BISON) |
| 85 | find_package(FLEX) |
| 86 | find_package(LibElf REQUIRED) |
Andreas Ziegler | 8ddbf3b | 2021-04-29 12:18:40 +0200 | [diff] [blame] | 87 | find_package(LibDebuginfod) |
Dale Hamel | 2d099cd | 2020-02-11 21:10:52 -0500 | [diff] [blame] | 88 | if(CLANG_DIR) |
| 89 | set(CMAKE_FIND_ROOT_PATH "${CLANG_DIR}") |
| 90 | include_directories("${CLANG_DIR}/include") |
| 91 | endif() |
| 92 | |
Brenden Blanco | 25245bf | 2015-05-10 12:15:06 -0700 | [diff] [blame] | 93 | # clang is linked as a library, but the library path searching is |
| 94 | # primitively supported, unlike libLLVM |
Brenden Blanco | f275d3d | 2015-07-06 23:41:23 -0700 | [diff] [blame] | 95 | set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}") |
Dominique Martinet | 1599c2e | 2020-04-17 21:16:03 +0200 | [diff] [blame] | 96 | find_library(libclangAnalysis NAMES clangAnalysis clang-cpp HINTS ${CLANG_SEARCH}) |
| 97 | find_library(libclangAST NAMES clangAST clang-cpp HINTS ${CLANG_SEARCH}) |
| 98 | find_library(libclangBasic NAMES clangBasic clang-cpp HINTS ${CLANG_SEARCH}) |
| 99 | find_library(libclangCodeGen NAMES clangCodeGen clang-cpp HINTS ${CLANG_SEARCH}) |
| 100 | find_library(libclangDriver NAMES clangDriver clang-cpp HINTS ${CLANG_SEARCH}) |
| 101 | find_library(libclangEdit NAMES clangEdit clang-cpp HINTS ${CLANG_SEARCH}) |
| 102 | find_library(libclangFrontend NAMES clangFrontend clang-cpp HINTS ${CLANG_SEARCH}) |
| 103 | find_library(libclangLex NAMES clangLex clang-cpp HINTS ${CLANG_SEARCH}) |
| 104 | find_library(libclangParse NAMES clangParse clang-cpp HINTS ${CLANG_SEARCH}) |
| 105 | find_library(libclangRewrite NAMES clangRewrite clang-cpp HINTS ${CLANG_SEARCH}) |
| 106 | find_library(libclangSema NAMES clangSema clang-cpp HINTS ${CLANG_SEARCH}) |
| 107 | find_library(libclangSerialization NAMES clangSerialization clang-cpp HINTS ${CLANG_SEARCH}) |
| 108 | find_library(libclangASTMatchers NAMES clangASTMatchers clang-cpp HINTS ${CLANG_SEARCH}) |
Luca Boccassi | e46997e | 2021-01-01 19:04:37 +0000 | [diff] [blame] | 109 | find_library(libclang-shared libclang-cpp.so HINTS ${CLANG_SEARCH}) |
Brenden Blanco | 8310291 | 2015-06-09 17:43:27 -0700 | [diff] [blame] | 110 | if(libclangBasic STREQUAL "libclangBasic-NOTFOUND") |
| 111 | message(FATAL_ERROR "Unable to find clang libraries") |
| 112 | endif() |
Alexei Starovoitov | 955f3b6 | 2015-06-09 19:37:38 -0700 | [diff] [blame] | 113 | FOREACH(DIR ${LLVM_INCLUDE_DIRS}) |
| 114 | include_directories("${DIR}/../tools/clang/include") |
| 115 | ENDFOREACH() |
Marcelo Juchem | c06208f | 2020-12-29 11:25:35 -0800 | [diff] [blame] | 116 | endif(ENABLE_CLANG_JIT) |
Brenden Blanco | a94bd93 | 2015-04-26 00:56:42 -0700 | [diff] [blame] | 117 | |
Ragnar Dahlén | dbc21ea | 2016-04-05 23:32:02 +0100 | [diff] [blame] | 118 | # Set to a string path if system places kernel lib directory in |
| 119 | # non-default location. |
| 120 | if(NOT DEFINED BCC_KERNEL_MODULES_DIR) |
| 121 | set(BCC_KERNEL_MODULES_DIR "/lib/modules") |
| 122 | endif() |
| 123 | |
Alexei Starovoitov | 4f47e3b | 2017-09-06 19:57:21 -0700 | [diff] [blame] | 124 | if(NOT DEFINED BCC_PROG_TAG_DIR) |
| 125 | set(BCC_PROG_TAG_DIR "/var/tmp/bcc") |
| 126 | endif() |
| 127 | |
Marco Leogrande | 0c461c9 | 2016-10-06 12:28:40 -0700 | [diff] [blame] | 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. |
Simon Liu | 1b38b9a | 2017-04-14 12:50:57 -0500 | [diff] [blame] | 131 | option(USINGISYSTEM "using -isystem" ON) |
Marco Leogrande | 0c461c9 | 2016-10-06 12:28:40 -0700 | [diff] [blame] | 132 | execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) |
Simon Liu | 1b38b9a | 2017-04-14 12:50:57 -0500 | [diff] [blame] | 133 | if (USINGISYSTEM AND GCC_VERSION VERSION_LESS 6.0) |
Marco Leogrande | 0c461c9 | 2016-10-06 12:28:40 -0700 | [diff] [blame] | 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() |
| 139 | endif() |
| 140 | |
Teng Qin | 84757ce | 2017-08-25 15:56:23 -0700 | [diff] [blame] | 141 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
yonghong-song | 903513e | 2019-09-24 20:08:31 -0700 | [diff] [blame] | 142 | set(CMAKE_CXX_STANDARD 14) |
Simon Liu | 2d82c8e | 2017-04-17 09:53:58 -0500 | [diff] [blame] | 143 | |
Marcelo Juchem | c06208f | 2020-12-29 11:25:35 -0800 | [diff] [blame] | 144 | endif(NOT PYTHON_ONLY) |
Brenden Blanco | a94bd93 | 2015-04-26 00:56:42 -0700 | [diff] [blame] | 145 | |
Brenden Blanco | 7fef695 | 2017-08-22 15:47:12 -0700 | [diff] [blame] | 146 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") |
| 147 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}") |
| 148 | |
| 149 | add_subdirectory(src) |
Martin KaFai Lau | f89cb40 | 2017-10-19 23:52:54 -0700 | [diff] [blame] | 150 | add_subdirectory(introspection) |
Brenden Blanco | 7fef695 | 2017-08-22 15:47:12 -0700 | [diff] [blame] | 151 | if(ENABLE_CLANG_JIT) |
Marcelo Juchem | 8fac710 | 2020-12-23 17:18:41 -0800 | [diff] [blame] | 152 | if(ENABLE_EXAMPLES) |
Brenden Blanco | 46176a1 | 2015-07-07 13:05:22 -0700 | [diff] [blame] | 153 | add_subdirectory(examples) |
Marcelo Juchem | 8fac710 | 2020-12-23 17:18:41 -0800 | [diff] [blame] | 154 | endif(ENABLE_EXAMPLES) |
Romain Naour | 910ddaf | 2018-12-07 22:36:21 +0100 | [diff] [blame] | 155 | if(ENABLE_MAN) |
Brenden Blanco | c175cf8 | 2015-11-25 18:22:42 -0800 | [diff] [blame] | 156 | add_subdirectory(man) |
Romain Naour | 910ddaf | 2018-12-07 22:36:21 +0100 | [diff] [blame] | 157 | endif(ENABLE_MAN) |
Marcelo Juchem | 8fac710 | 2020-12-23 17:18:41 -0800 | [diff] [blame] | 158 | if(ENABLE_TESTS) |
Brenden Blanco | cd5cb41 | 2015-04-26 09:41:58 -0700 | [diff] [blame] | 159 | add_subdirectory(tests) |
Marcelo Juchem | 8fac710 | 2020-12-23 17:18:41 -0800 | [diff] [blame] | 160 | endif(ENABLE_TESTS) |
Brenden Blanco | c175cf8 | 2015-11-25 18:22:42 -0800 | [diff] [blame] | 161 | add_subdirectory(tools) |
Brenden Blanco | 7fef695 | 2017-08-22 15:47:12 -0700 | [diff] [blame] | 162 | endif(ENABLE_CLANG_JIT) |