blob: 610e153ae604e1acd43b9a376dccd1c9247fb406 [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
torgil61c063a2018-12-23 08:20:21 +010019option(ENABLE_LLVM_NATIVECODEGEN "Enable use of llvm nativecodegen module (needed by rw-engine)" ON)
torgil4a7717d2018-12-12 08:12:42 +010020option(ENABLE_RTTI "Enable compiling with real time type information" OFF)
Brenden Blancoe8001c32018-07-23 08:15:56 -070021option(ENABLE_LLVM_SHARED "Enable linking LLVM as a shared library" OFF)
Brenden Blanco7fef6952017-08-22 15:47:12 -070022option(ENABLE_CLANG_JIT "Enable Loading BPF through Clang Frontend" ON)
23option(ENABLE_USDT "Enable User-level Statically Defined Tracing" ON)
24CMAKE_DEPENDENT_OPTION(ENABLE_CPP_API "Enable C++ API" ON "ENABLE_USDT" OFF)
25
Vicent Martiff9ff5d2016-04-20 13:24:54 +020026set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
27
Brenden Blanco7fef6952017-08-22 15:47:12 -070028if(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
Brenden Blancoa94bd932015-04-26 00:56:42 -070029find_package(BISON)
30find_package(FLEX)
31find_package(LLVM REQUIRED CONFIG)
Yonghong Song91837ca2017-09-28 09:40:13 -070032message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS} ${LLVM_PACKAGE_VERSION}")
Brenden Blanco7fef6952017-08-22 15:47:12 -070033find_package(LibElf REQUIRED)
Brenden Blanco25245bf2015-05-10 12:15:06 -070034
35# clang is linked as a library, but the library path searching is
36# primitively supported, unlike libLLVM
Brenden Blancof275d3d2015-07-06 23:41:23 -070037set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}")
Brenden Blanco25245bf2015-05-10 12:15:06 -070038find_library(libclangAnalysis NAMES clangAnalysis HINTS ${CLANG_SEARCH})
39find_library(libclangAST NAMES clangAST HINTS ${CLANG_SEARCH})
40find_library(libclangBasic NAMES clangBasic HINTS ${CLANG_SEARCH})
41find_library(libclangCodeGen NAMES clangCodeGen HINTS ${CLANG_SEARCH})
42find_library(libclangDriver NAMES clangDriver HINTS ${CLANG_SEARCH})
43find_library(libclangEdit NAMES clangEdit HINTS ${CLANG_SEARCH})
44find_library(libclangFrontend NAMES clangFrontend HINTS ${CLANG_SEARCH})
45find_library(libclangLex NAMES clangLex HINTS ${CLANG_SEARCH})
46find_library(libclangParse NAMES clangParse HINTS ${CLANG_SEARCH})
Brenden Blanco7009b552015-05-26 11:48:17 -070047find_library(libclangRewrite NAMES clangRewrite HINTS ${CLANG_SEARCH})
Brenden Blanco25245bf2015-05-10 12:15:06 -070048find_library(libclangSema NAMES clangSema HINTS ${CLANG_SEARCH})
49find_library(libclangSerialization NAMES clangSerialization HINTS ${CLANG_SEARCH})
yonghong-song72bb0d52018-09-18 23:31:34 -070050find_library(libclangASTMatchers NAMES clangASTMatchers HINTS ${CLANG_SEARCH})
Brenden Blanco83102912015-06-09 17:43:27 -070051if(libclangBasic STREQUAL "libclangBasic-NOTFOUND")
52 message(FATAL_ERROR "Unable to find clang libraries")
53endif()
Alexei Starovoitov955f3b62015-06-09 19:37:38 -070054FOREACH(DIR ${LLVM_INCLUDE_DIRS})
55 include_directories("${DIR}/../tools/clang/include")
56ENDFOREACH()
Brenden Blancoa94bd932015-04-26 00:56:42 -070057
Ragnar Dahléndbc21ea2016-04-05 23:32:02 +010058# Set to a string path if system places kernel lib directory in
59# non-default location.
60if(NOT DEFINED BCC_KERNEL_MODULES_DIR)
61 set(BCC_KERNEL_MODULES_DIR "/lib/modules")
62endif()
63
Alexei Starovoitov4f47e3b2017-09-06 19:57:21 -070064if(NOT DEFINED BCC_PROG_TAG_DIR)
65 set(BCC_PROG_TAG_DIR "/var/tmp/bcc")
66endif()
67
Marco Leogrande0c461c92016-10-06 12:28:40 -070068# As reported in issue #735, GCC 6 has some behavioral problems when
69# dealing with -isystem. Hence, skip the warning optimization
70# altogether on that compiler.
Simon Liu1b38b9a2017-04-14 12:50:57 -050071option(USINGISYSTEM "using -isystem" ON)
Marco Leogrande0c461c92016-10-06 12:28:40 -070072execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
Simon Liu1b38b9a2017-04-14 12:50:57 -050073if (USINGISYSTEM AND GCC_VERSION VERSION_LESS 6.0)
Marco Leogrande0c461c92016-10-06 12:28:40 -070074 # iterate over all available directories in LLVM_INCLUDE_DIRS to
75 # generate a correctly tokenized list of parameters
76 foreach(ONE_LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
77 set(CXX_ISYSTEM_DIRS "${CXX_ISYSTEM_DIRS} -isystem ${ONE_LLVM_INCLUDE_DIR}")
78 endforeach()
79endif()
80
Teng Qin84757ce2017-08-25 15:56:23 -070081set(CMAKE_CXX_STANDARD_REQUIRED ON)
82set(CMAKE_CXX_STANDARD 11)
Simon Liu2d82c8e2017-04-17 09:53:58 -050083
Brenden Blanco7fef6952017-08-22 15:47:12 -070084endif(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
Brenden Blancoa94bd932015-04-26 00:56:42 -070085
Brenden Blanco7fef6952017-08-22 15:47:12 -070086set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
87set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
88
89add_subdirectory(src)
Martin KaFai Lauf89cb402017-10-19 23:52:54 -070090add_subdirectory(introspection)
Brenden Blanco7fef6952017-08-22 15:47:12 -070091if(ENABLE_CLANG_JIT)
Brenden Blanco46176a12015-07-07 13:05:22 -070092add_subdirectory(examples)
Brenden Blancoc175cf82015-11-25 18:22:42 -080093add_subdirectory(man)
Brenden Blancocd5cb412015-04-26 09:41:58 -070094add_subdirectory(tests)
Brenden Blancoc175cf82015-11-25 18:22:42 -080095add_subdirectory(tools)
Brenden Blanco7fef6952017-08-22 15:47:12 -070096endif(ENABLE_CLANG_JIT)