blob: bb3f53b90b48e8e1953c89c728a5946c94d665db [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})
yonghong-song72bb0d52018-09-18 23:31:34 -070048find_library(libclangASTMatchers NAMES clangASTMatchers HINTS ${CLANG_SEARCH})
Brenden Blanco83102912015-06-09 17:43:27 -070049if(libclangBasic STREQUAL "libclangBasic-NOTFOUND")
50 message(FATAL_ERROR "Unable to find clang libraries")
51endif()
Alexei Starovoitov955f3b62015-06-09 19:37:38 -070052FOREACH(DIR ${LLVM_INCLUDE_DIRS})
53 include_directories("${DIR}/../tools/clang/include")
54ENDFOREACH()
Brenden Blancoa94bd932015-04-26 00:56:42 -070055
Ragnar Dahléndbc21ea2016-04-05 23:32:02 +010056# Set to a string path if system places kernel lib directory in
57# non-default location.
58if(NOT DEFINED BCC_KERNEL_MODULES_DIR)
59 set(BCC_KERNEL_MODULES_DIR "/lib/modules")
60endif()
61
Alexei Starovoitov4f47e3b2017-09-06 19:57:21 -070062if(NOT DEFINED BCC_PROG_TAG_DIR)
63 set(BCC_PROG_TAG_DIR "/var/tmp/bcc")
64endif()
65
Marco Leogrande0c461c92016-10-06 12:28:40 -070066# As reported in issue #735, GCC 6 has some behavioral problems when
67# dealing with -isystem. Hence, skip the warning optimization
68# altogether on that compiler.
Simon Liu1b38b9a2017-04-14 12:50:57 -050069option(USINGISYSTEM "using -isystem" ON)
Marco Leogrande0c461c92016-10-06 12:28:40 -070070execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
Simon Liu1b38b9a2017-04-14 12:50:57 -050071if (USINGISYSTEM AND GCC_VERSION VERSION_LESS 6.0)
Marco Leogrande0c461c92016-10-06 12:28:40 -070072 # iterate over all available directories in LLVM_INCLUDE_DIRS to
73 # generate a correctly tokenized list of parameters
74 foreach(ONE_LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
75 set(CXX_ISYSTEM_DIRS "${CXX_ISYSTEM_DIRS} -isystem ${ONE_LLVM_INCLUDE_DIR}")
76 endforeach()
77endif()
78
Teng Qin84757ce2017-08-25 15:56:23 -070079set(CMAKE_CXX_STANDARD_REQUIRED ON)
80set(CMAKE_CXX_STANDARD 11)
Simon Liu2d82c8e2017-04-17 09:53:58 -050081
Brenden Blanco7fef6952017-08-22 15:47:12 -070082endif(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
Brenden Blancoa94bd932015-04-26 00:56:42 -070083
Brenden Blanco7fef6952017-08-22 15:47:12 -070084set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
85set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
86
87add_subdirectory(src)
Martin KaFai Lauf89cb402017-10-19 23:52:54 -070088add_subdirectory(introspection)
Brenden Blanco7fef6952017-08-22 15:47:12 -070089if(ENABLE_CLANG_JIT)
Brenden Blanco46176a12015-07-07 13:05:22 -070090add_subdirectory(examples)
Brenden Blancoc175cf82015-11-25 18:22:42 -080091add_subdirectory(man)
Brenden Blancocd5cb412015-04-26 09:41:58 -070092add_subdirectory(tests)
Brenden Blancoc175cf82015-11-25 18:22:42 -080093add_subdirectory(tools)
Brenden Blanco7fef6952017-08-22 15:47:12 -070094endif(ENABLE_CLANG_JIT)