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 | |
Brenden Blanco | f275d3d | 2015-07-06 23:41:23 -0700 | [diff] [blame] | 5 | project(bcc) |
Gabor Buella | 31d4a59 | 2017-05-19 15:33:08 +0200 | [diff] [blame] | 6 | if(NOT CMAKE_BUILD_TYPE) |
| 7 | set(CMAKE_BUILD_TYPE Release) |
| 8 | endif() |
Brenden Blanco | cd5cb41 | 2015-04-26 09:41:58 -0700 | [diff] [blame] | 9 | |
| 10 | enable_testing() |
Brenden Blanco | a94bd93 | 2015-04-26 00:56:42 -0700 | [diff] [blame] | 11 | |
Brenden Blanco | 974e891 | 2015-09-04 09:36:37 -0700 | [diff] [blame] | 12 | include(cmake/GetGitRevisionDescription.cmake) |
| 13 | include(cmake/version.cmake) |
Brenden Blanco | 71fc3d5 | 2017-06-28 17:37:06 -0700 | [diff] [blame] | 14 | include(CMakeDependentOption) |
Brenden Blanco | 6470bbe | 2015-09-23 07:23:35 -0700 | [diff] [blame] | 15 | include(GNUInstallDirs) |
Simon Liu | 2d82c8e | 2017-04-17 09:53:58 -0500 | [diff] [blame] | 16 | include(CheckCXXCompilerFlag) |
Yonghong Song | 75e2f37 | 2017-08-23 13:40:47 -0700 | [diff] [blame] | 17 | include(cmake/FindCompilerFlag.cmake) |
Brenden Blanco | d8acf6f | 2015-06-07 22:32:33 -0700 | [diff] [blame] | 18 | |
Brenden Blanco | 7fef695 | 2017-08-22 15:47:12 -0700 | [diff] [blame] | 19 | option(ENABLE_CLANG_JIT "Enable Loading BPF through Clang Frontend" ON) |
| 20 | option(ENABLE_USDT "Enable User-level Statically Defined Tracing" ON) |
| 21 | CMAKE_DEPENDENT_OPTION(ENABLE_CPP_API "Enable C++ API" ON "ENABLE_USDT" OFF) |
| 22 | |
Vicent Marti | ff9ff5d | 2016-04-20 13:24:54 +0200 | [diff] [blame] | 23 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) |
| 24 | |
Brenden Blanco | 7fef695 | 2017-08-22 15:47:12 -0700 | [diff] [blame] | 25 | if(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT) |
Brenden Blanco | a94bd93 | 2015-04-26 00:56:42 -0700 | [diff] [blame] | 26 | find_package(BISON) |
| 27 | find_package(FLEX) |
| 28 | find_package(LLVM REQUIRED CONFIG) |
Yonghong Song | 91837ca | 2017-09-28 09:40:13 -0700 | [diff] [blame] | 29 | message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS} ${LLVM_PACKAGE_VERSION}") |
Brenden Blanco | 7fef695 | 2017-08-22 15:47:12 -0700 | [diff] [blame] | 30 | find_package(LibElf REQUIRED) |
Brenden Blanco | 25245bf | 2015-05-10 12:15:06 -0700 | [diff] [blame] | 31 | |
| 32 | # clang is linked as a library, but the library path searching is |
| 33 | # primitively supported, unlike libLLVM |
Brenden Blanco | f275d3d | 2015-07-06 23:41:23 -0700 | [diff] [blame] | 34 | set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}") |
Brenden Blanco | 25245bf | 2015-05-10 12:15:06 -0700 | [diff] [blame] | 35 | find_library(libclangAnalysis NAMES clangAnalysis HINTS ${CLANG_SEARCH}) |
| 36 | find_library(libclangAST NAMES clangAST HINTS ${CLANG_SEARCH}) |
| 37 | find_library(libclangBasic NAMES clangBasic HINTS ${CLANG_SEARCH}) |
| 38 | find_library(libclangCodeGen NAMES clangCodeGen HINTS ${CLANG_SEARCH}) |
| 39 | find_library(libclangDriver NAMES clangDriver HINTS ${CLANG_SEARCH}) |
| 40 | find_library(libclangEdit NAMES clangEdit HINTS ${CLANG_SEARCH}) |
| 41 | find_library(libclangFrontend NAMES clangFrontend HINTS ${CLANG_SEARCH}) |
| 42 | find_library(libclangLex NAMES clangLex HINTS ${CLANG_SEARCH}) |
| 43 | find_library(libclangParse NAMES clangParse HINTS ${CLANG_SEARCH}) |
Brenden Blanco | 7009b55 | 2015-05-26 11:48:17 -0700 | [diff] [blame] | 44 | find_library(libclangRewrite NAMES clangRewrite HINTS ${CLANG_SEARCH}) |
Brenden Blanco | 25245bf | 2015-05-10 12:15:06 -0700 | [diff] [blame] | 45 | find_library(libclangSema NAMES clangSema HINTS ${CLANG_SEARCH}) |
| 46 | find_library(libclangSerialization NAMES clangSerialization HINTS ${CLANG_SEARCH}) |
Brenden Blanco | 8310291 | 2015-06-09 17:43:27 -0700 | [diff] [blame] | 47 | if(libclangBasic STREQUAL "libclangBasic-NOTFOUND") |
| 48 | message(FATAL_ERROR "Unable to find clang libraries") |
| 49 | endif() |
Alexei Starovoitov | 955f3b6 | 2015-06-09 19:37:38 -0700 | [diff] [blame] | 50 | FOREACH(DIR ${LLVM_INCLUDE_DIRS}) |
| 51 | include_directories("${DIR}/../tools/clang/include") |
| 52 | ENDFOREACH() |
Brenden Blanco | a94bd93 | 2015-04-26 00:56:42 -0700 | [diff] [blame] | 53 | |
Ragnar Dahlén | dbc21ea | 2016-04-05 23:32:02 +0100 | [diff] [blame] | 54 | # Set to a string path if system places kernel lib directory in |
| 55 | # non-default location. |
| 56 | if(NOT DEFINED BCC_KERNEL_MODULES_DIR) |
| 57 | set(BCC_KERNEL_MODULES_DIR "/lib/modules") |
| 58 | endif() |
| 59 | |
Alexei Starovoitov | 4f47e3b | 2017-09-06 19:57:21 -0700 | [diff] [blame] | 60 | if(NOT DEFINED BCC_PROG_TAG_DIR) |
| 61 | set(BCC_PROG_TAG_DIR "/var/tmp/bcc") |
| 62 | endif() |
| 63 | |
Marco Leogrande | 0c461c9 | 2016-10-06 12:28:40 -0700 | [diff] [blame] | 64 | # As reported in issue #735, GCC 6 has some behavioral problems when |
| 65 | # dealing with -isystem. Hence, skip the warning optimization |
| 66 | # altogether on that compiler. |
Simon Liu | 1b38b9a | 2017-04-14 12:50:57 -0500 | [diff] [blame] | 67 | option(USINGISYSTEM "using -isystem" ON) |
Marco Leogrande | 0c461c9 | 2016-10-06 12:28:40 -0700 | [diff] [blame] | 68 | execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) |
Simon Liu | 1b38b9a | 2017-04-14 12:50:57 -0500 | [diff] [blame] | 69 | if (USINGISYSTEM AND GCC_VERSION VERSION_LESS 6.0) |
Marco Leogrande | 0c461c9 | 2016-10-06 12:28:40 -0700 | [diff] [blame] | 70 | # iterate over all available directories in LLVM_INCLUDE_DIRS to |
| 71 | # generate a correctly tokenized list of parameters |
| 72 | foreach(ONE_LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIRS}) |
| 73 | set(CXX_ISYSTEM_DIRS "${CXX_ISYSTEM_DIRS} -isystem ${ONE_LLVM_INCLUDE_DIR}") |
| 74 | endforeach() |
| 75 | endif() |
| 76 | |
Teng Qin | 84757ce | 2017-08-25 15:56:23 -0700 | [diff] [blame] | 77 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 78 | set(CMAKE_CXX_STANDARD 11) |
Simon Liu | 2d82c8e | 2017-04-17 09:53:58 -0500 | [diff] [blame] | 79 | |
Brenden Blanco | 7fef695 | 2017-08-22 15:47:12 -0700 | [diff] [blame] | 80 | endif(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT) |
Brenden Blanco | a94bd93 | 2015-04-26 00:56:42 -0700 | [diff] [blame] | 81 | |
Brenden Blanco | 7fef695 | 2017-08-22 15:47:12 -0700 | [diff] [blame] | 82 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") |
| 83 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}") |
| 84 | |
| 85 | add_subdirectory(src) |
Martin KaFai Lau | f89cb40 | 2017-10-19 23:52:54 -0700 | [diff] [blame] | 86 | add_subdirectory(introspection) |
Brenden Blanco | 7fef695 | 2017-08-22 15:47:12 -0700 | [diff] [blame] | 87 | if(ENABLE_CLANG_JIT) |
Brenden Blanco | 46176a1 | 2015-07-07 13:05:22 -0700 | [diff] [blame] | 88 | add_subdirectory(examples) |
Brenden Blanco | c175cf8 | 2015-11-25 18:22:42 -0800 | [diff] [blame] | 89 | add_subdirectory(man) |
Brenden Blanco | cd5cb41 | 2015-04-26 09:41:58 -0700 | [diff] [blame] | 90 | add_subdirectory(tests) |
Brenden Blanco | c175cf8 | 2015-11-25 18:22:42 -0800 | [diff] [blame] | 91 | add_subdirectory(tools) |
Brenden Blanco | 7fef695 | 2017-08-22 15:47:12 -0700 | [diff] [blame] | 92 | endif(ENABLE_CLANG_JIT) |