1# Copyright (c) PLUMgrid, Inc. 2# Licensed under the Apache License, Version 2.0 (the "License") 3cmake_minimum_required(VERSION 2.8.7) 4 5project(bcc) 6if(NOT CMAKE_BUILD_TYPE) 7 set(CMAKE_BUILD_TYPE Release) 8endif() 9 10enable_testing() 11 12include(cmake/GetGitRevisionDescription.cmake) 13include(cmake/version.cmake) 14include(CMakeDependentOption) 15include(GNUInstallDirs) 16include(CheckCXXCompilerFlag) 17include(cmake/FindCompilerFlag.cmake) 18 19option(ENABLE_LLVM_SHARED "Enable linking LLVM as a shared library" OFF) 20option(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 24set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) 25 26if(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT) 27find_package(BISON) 28find_package(FLEX) 29find_package(LLVM REQUIRED CONFIG) 30message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS} ${LLVM_PACKAGE_VERSION}") 31find_package(LibElf REQUIRED) 32 33# clang is linked as a library, but the library path searching is 34# primitively supported, unlike libLLVM 35set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}") 36find_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}) 45find_library(libclangRewrite NAMES clangRewrite HINTS ${CLANG_SEARCH}) 46find_library(libclangSema NAMES clangSema HINTS ${CLANG_SEARCH}) 47find_library(libclangSerialization NAMES clangSerialization HINTS ${CLANG_SEARCH}) 48find_library(libclangASTMatchers NAMES clangASTMatchers HINTS ${CLANG_SEARCH}) 49if(libclangBasic STREQUAL "libclangBasic-NOTFOUND") 50 message(FATAL_ERROR "Unable to find clang libraries") 51endif() 52FOREACH(DIR ${LLVM_INCLUDE_DIRS}) 53 include_directories("${DIR}/../tools/clang/include") 54ENDFOREACH() 55 56# 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 62if(NOT DEFINED BCC_PROG_TAG_DIR) 63 set(BCC_PROG_TAG_DIR "/var/tmp/bcc") 64endif() 65 66# 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. 69option(USINGISYSTEM "using -isystem" ON) 70execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) 71if (USINGISYSTEM AND GCC_VERSION VERSION_LESS 6.0) 72 # 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 79set(CMAKE_CXX_STANDARD_REQUIRED ON) 80set(CMAKE_CXX_STANDARD 11) 81 82endif(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT) 83 84set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") 85set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}") 86 87add_subdirectory(src) 88add_subdirectory(introspection) 89if(ENABLE_CLANG_JIT) 90add_subdirectory(examples) 91add_subdirectory(man) 92add_subdirectory(tests) 93add_subdirectory(tools) 94endif(ENABLE_CLANG_JIT) 95