blob: f9e38f7754b536002380b25ce0ad8666e829658b [file] [log] [blame]
Brenden Blanco246b9422015-06-05 11:15:27 -07001# Copyright (c) PLUMgrid, Inc.
2# Licensed under the Apache License, Version 2.0 (the "License")
Brenden Blancoa94bd932015-04-26 00:56:42 -07003cmake_minimum_required(VERSION 2.8.7)
4
Brenden Blancof275d3d2015-07-06 23:41:23 -07005project(bcc)
Gabor Buella31d4a592017-05-19 15:33:08 +02006if(NOT CMAKE_BUILD_TYPE)
7 set(CMAKE_BUILD_TYPE Release)
8endif()
Brenden Blancocd5cb412015-04-26 09:41:58 -07009
10enable_testing()
Brenden Blancoa94bd932015-04-26 00:56:42 -070011
Brenden Blanco974e8912015-09-04 09:36:37 -070012include(cmake/GetGitRevisionDescription.cmake)
13include(cmake/version.cmake)
Brenden Blanco71fc3d52017-06-28 17:37:06 -070014include(CMakeDependentOption)
Brenden Blanco6470bbe2015-09-23 07:23:35 -070015include(GNUInstallDirs)
Simon Liu2d82c8e2017-04-17 09:53:58 -050016include(CheckCXXCompilerFlag)
Yonghong Song75e2f372017-08-23 13:40:47 -070017include(cmake/FindCompilerFlag.cmake)
Brenden Blancod8acf6f2015-06-07 22:32:33 -070018
Brenden Blancoe8001c32018-07-23 08:15:56 -070019option(ENABLE_LLVM_SHARED "Enable linking LLVM as a shared library" OFF)
Brenden Blanco7fef6952017-08-22 15:47:12 -070020option(ENABLE_CLANG_JIT "Enable Loading BPF through Clang Frontend" ON)
21option(ENABLE_USDT "Enable User-level Statically Defined Tracing" ON)
22CMAKE_DEPENDENT_OPTION(ENABLE_CPP_API "Enable C++ API" ON "ENABLE_USDT" OFF)
23
Vicent Martiff9ff5d2016-04-20 13:24:54 +020024set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
25
Brenden Blanco7fef6952017-08-22 15:47:12 -070026if(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
Brenden Blancoa94bd932015-04-26 00:56:42 -070027find_package(BISON)
28find_package(FLEX)
29find_package(LLVM REQUIRED CONFIG)
Yonghong Song91837ca2017-09-28 09:40:13 -070030message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS} ${LLVM_PACKAGE_VERSION}")
Brenden Blanco7fef6952017-08-22 15:47:12 -070031find_package(LibElf REQUIRED)
Brenden Blanco25245bf2015-05-10 12:15:06 -070032
33# clang is linked as a library, but the library path searching is
34# primitively supported, unlike libLLVM
Brenden Blancof275d3d2015-07-06 23:41:23 -070035set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}")
Brenden Blanco25245bf2015-05-10 12:15:06 -070036find_library(libclangAnalysis NAMES clangAnalysis HINTS ${CLANG_SEARCH})
37find_library(libclangAST NAMES clangAST HINTS ${CLANG_SEARCH})
38find_library(libclangBasic NAMES clangBasic HINTS ${CLANG_SEARCH})
39find_library(libclangCodeGen NAMES clangCodeGen HINTS ${CLANG_SEARCH})
40find_library(libclangDriver NAMES clangDriver HINTS ${CLANG_SEARCH})
41find_library(libclangEdit NAMES clangEdit HINTS ${CLANG_SEARCH})
42find_library(libclangFrontend NAMES clangFrontend HINTS ${CLANG_SEARCH})
43find_library(libclangLex NAMES clangLex HINTS ${CLANG_SEARCH})
44find_library(libclangParse NAMES clangParse HINTS ${CLANG_SEARCH})
Brenden Blanco7009b552015-05-26 11:48:17 -070045find_library(libclangRewrite NAMES clangRewrite HINTS ${CLANG_SEARCH})
Brenden Blanco25245bf2015-05-10 12:15:06 -070046find_library(libclangSema NAMES clangSema HINTS ${CLANG_SEARCH})
47find_library(libclangSerialization NAMES clangSerialization HINTS ${CLANG_SEARCH})
Brenden Blanco83102912015-06-09 17:43:27 -070048if(libclangBasic STREQUAL "libclangBasic-NOTFOUND")
49 message(FATAL_ERROR "Unable to find clang libraries")
50endif()
Alexei Starovoitov955f3b62015-06-09 19:37:38 -070051FOREACH(DIR ${LLVM_INCLUDE_DIRS})
52 include_directories("${DIR}/../tools/clang/include")
53ENDFOREACH()
Brenden Blancoa94bd932015-04-26 00:56:42 -070054
Ragnar Dahléndbc21ea2016-04-05 23:32:02 +010055# Set to a string path if system places kernel lib directory in
56# non-default location.
57if(NOT DEFINED BCC_KERNEL_MODULES_DIR)
58 set(BCC_KERNEL_MODULES_DIR "/lib/modules")
59endif()
60
Alexei Starovoitov4f47e3b2017-09-06 19:57:21 -070061if(NOT DEFINED BCC_PROG_TAG_DIR)
62 set(BCC_PROG_TAG_DIR "/var/tmp/bcc")
63endif()
64
Marco Leogrande0c461c92016-10-06 12:28:40 -070065# As reported in issue #735, GCC 6 has some behavioral problems when
66# dealing with -isystem. Hence, skip the warning optimization
67# altogether on that compiler.
Simon Liu1b38b9a2017-04-14 12:50:57 -050068option(USINGISYSTEM "using -isystem" ON)
Marco Leogrande0c461c92016-10-06 12:28:40 -070069execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
Simon Liu1b38b9a2017-04-14 12:50:57 -050070if (USINGISYSTEM AND GCC_VERSION VERSION_LESS 6.0)
Marco Leogrande0c461c92016-10-06 12:28:40 -070071 # iterate over all available directories in LLVM_INCLUDE_DIRS to
72 # generate a correctly tokenized list of parameters
73 foreach(ONE_LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
74 set(CXX_ISYSTEM_DIRS "${CXX_ISYSTEM_DIRS} -isystem ${ONE_LLVM_INCLUDE_DIR}")
75 endforeach()
76endif()
77
Teng Qin84757ce2017-08-25 15:56:23 -070078set(CMAKE_CXX_STANDARD_REQUIRED ON)
79set(CMAKE_CXX_STANDARD 11)
Simon Liu2d82c8e2017-04-17 09:53:58 -050080
Brenden Blanco7fef6952017-08-22 15:47:12 -070081endif(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
Brenden Blancoa94bd932015-04-26 00:56:42 -070082
Brenden Blanco7fef6952017-08-22 15:47:12 -070083set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
84set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
85
86add_subdirectory(src)
Martin KaFai Lauf89cb402017-10-19 23:52:54 -070087add_subdirectory(introspection)
Brenden Blanco7fef6952017-08-22 15:47:12 -070088if(ENABLE_CLANG_JIT)
Brenden Blanco46176a12015-07-07 13:05:22 -070089add_subdirectory(examples)
Brenden Blancoc175cf82015-11-25 18:22:42 -080090add_subdirectory(man)
Brenden Blancocd5cb412015-04-26 09:41:58 -070091add_subdirectory(tests)
Brenden Blancoc175cf82015-11-25 18:22:42 -080092add_subdirectory(tools)
Brenden Blanco7fef6952017-08-22 15:47:12 -070093endif(ENABLE_CLANG_JIT)