blob: 9bc24418c9b293d08edd4e4a79fb88e661bf31eb [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 Blanco7fef6952017-08-22 15:47:12 -070019option(ENABLE_CLANG_JIT "Enable Loading BPF through Clang Frontend" ON)
20option(ENABLE_USDT "Enable User-level Statically Defined Tracing" ON)
21CMAKE_DEPENDENT_OPTION(ENABLE_CPP_API "Enable C++ API" ON "ENABLE_USDT" OFF)
22
Vicent Martiff9ff5d2016-04-20 13:24:54 +020023set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
24
Brenden Blanco7fef6952017-08-22 15:47:12 -070025if(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
Brenden Blancoa94bd932015-04-26 00:56:42 -070026find_package(BISON)
27find_package(FLEX)
28find_package(LLVM REQUIRED CONFIG)
Yonghong Song91837ca2017-09-28 09:40:13 -070029message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS} ${LLVM_PACKAGE_VERSION}")
Brenden Blanco7fef6952017-08-22 15:47:12 -070030find_package(LibElf REQUIRED)
Brenden Blanco25245bf2015-05-10 12:15:06 -070031
32# clang is linked as a library, but the library path searching is
33# primitively supported, unlike libLLVM
Brenden Blancof275d3d2015-07-06 23:41:23 -070034set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}")
Brenden Blanco25245bf2015-05-10 12:15:06 -070035find_library(libclangAnalysis NAMES clangAnalysis HINTS ${CLANG_SEARCH})
36find_library(libclangAST NAMES clangAST HINTS ${CLANG_SEARCH})
37find_library(libclangBasic NAMES clangBasic HINTS ${CLANG_SEARCH})
38find_library(libclangCodeGen NAMES clangCodeGen HINTS ${CLANG_SEARCH})
39find_library(libclangDriver NAMES clangDriver HINTS ${CLANG_SEARCH})
40find_library(libclangEdit NAMES clangEdit HINTS ${CLANG_SEARCH})
41find_library(libclangFrontend NAMES clangFrontend HINTS ${CLANG_SEARCH})
42find_library(libclangLex NAMES clangLex HINTS ${CLANG_SEARCH})
43find_library(libclangParse NAMES clangParse HINTS ${CLANG_SEARCH})
Brenden Blanco7009b552015-05-26 11:48:17 -070044find_library(libclangRewrite NAMES clangRewrite HINTS ${CLANG_SEARCH})
Brenden Blanco25245bf2015-05-10 12:15:06 -070045find_library(libclangSema NAMES clangSema HINTS ${CLANG_SEARCH})
46find_library(libclangSerialization NAMES clangSerialization HINTS ${CLANG_SEARCH})
Brenden Blanco83102912015-06-09 17:43:27 -070047if(libclangBasic STREQUAL "libclangBasic-NOTFOUND")
48 message(FATAL_ERROR "Unable to find clang libraries")
49endif()
Alexei Starovoitov955f3b62015-06-09 19:37:38 -070050FOREACH(DIR ${LLVM_INCLUDE_DIRS})
51 include_directories("${DIR}/../tools/clang/include")
52ENDFOREACH()
Brenden Blancoa94bd932015-04-26 00:56:42 -070053
Ragnar Dahléndbc21ea2016-04-05 23:32:02 +010054# Set to a string path if system places kernel lib directory in
55# non-default location.
56if(NOT DEFINED BCC_KERNEL_MODULES_DIR)
57 set(BCC_KERNEL_MODULES_DIR "/lib/modules")
58endif()
59
Alexei Starovoitov4f47e3b2017-09-06 19:57:21 -070060if(NOT DEFINED BCC_PROG_TAG_DIR)
61 set(BCC_PROG_TAG_DIR "/var/tmp/bcc")
62endif()
63
Marco Leogrande0c461c92016-10-06 12:28:40 -070064# 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 Liu1b38b9a2017-04-14 12:50:57 -050067option(USINGISYSTEM "using -isystem" ON)
Marco Leogrande0c461c92016-10-06 12:28:40 -070068execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
Simon Liu1b38b9a2017-04-14 12:50:57 -050069if (USINGISYSTEM AND GCC_VERSION VERSION_LESS 6.0)
Marco Leogrande0c461c92016-10-06 12:28:40 -070070 # 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()
75endif()
76
Teng Qin84757ce2017-08-25 15:56:23 -070077set(CMAKE_CXX_STANDARD_REQUIRED ON)
78set(CMAKE_CXX_STANDARD 11)
Simon Liu2d82c8e2017-04-17 09:53:58 -050079
Brenden Blanco7fef6952017-08-22 15:47:12 -070080endif(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
Brenden Blancoa94bd932015-04-26 00:56:42 -070081
Brenden Blanco7fef6952017-08-22 15:47:12 -070082set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
83set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
84
85add_subdirectory(src)
Martin KaFai Lauf89cb402017-10-19 23:52:54 -070086add_subdirectory(introspection)
Brenden Blanco7fef6952017-08-22 15:47:12 -070087if(ENABLE_CLANG_JIT)
Brenden Blanco46176a12015-07-07 13:05:22 -070088add_subdirectory(examples)
Brenden Blancoc175cf82015-11-25 18:22:42 -080089add_subdirectory(man)
Brenden Blancocd5cb412015-04-26 09:41:58 -070090add_subdirectory(tests)
Brenden Blancoc175cf82015-11-25 18:22:42 -080091add_subdirectory(tools)
Brenden Blanco7fef6952017-08-22 15:47:12 -070092endif(ENABLE_CLANG_JIT)