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_NATIVECODEGEN "Enable use of llvm nativecodegen module (needed by rw-engine)" ON) 20option(ENABLE_RTTI "Enable compiling with real time type information" OFF) 21option(ENABLE_LLVM_SHARED "Enable linking LLVM as a shared library" OFF) 22option(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 26set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) 27 28if(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT) 29find_package(BISON) 30find_package(FLEX) 31find_package(LLVM REQUIRED CONFIG) 32message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS} ${LLVM_PACKAGE_VERSION}") 33find_package(LibElf REQUIRED) 34 35# clang is linked as a library, but the library path searching is 36# primitively supported, unlike libLLVM 37set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}") 38find_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}) 47find_library(libclangRewrite NAMES clangRewrite HINTS ${CLANG_SEARCH}) 48find_library(libclangSema NAMES clangSema HINTS ${CLANG_SEARCH}) 49find_library(libclangSerialization NAMES clangSerialization HINTS ${CLANG_SEARCH}) 50find_library(libclangASTMatchers NAMES clangASTMatchers HINTS ${CLANG_SEARCH}) 51if(libclangBasic STREQUAL "libclangBasic-NOTFOUND") 52 message(FATAL_ERROR "Unable to find clang libraries") 53endif() 54FOREACH(DIR ${LLVM_INCLUDE_DIRS}) 55 include_directories("${DIR}/../tools/clang/include") 56ENDFOREACH() 57 58# 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 64if(NOT DEFINED BCC_PROG_TAG_DIR) 65 set(BCC_PROG_TAG_DIR "/var/tmp/bcc") 66endif() 67 68# 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. 71option(USINGISYSTEM "using -isystem" ON) 72execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) 73if (USINGISYSTEM AND GCC_VERSION VERSION_LESS 6.0) 74 # 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 81set(CMAKE_CXX_STANDARD_REQUIRED ON) 82set(CMAKE_CXX_STANDARD 11) 83 84endif(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT) 85 86set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") 87set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}") 88 89add_subdirectory(src) 90add_subdirectory(introspection) 91if(ENABLE_CLANG_JIT) 92add_subdirectory(examples) 93add_subdirectory(man) 94add_subdirectory(tests) 95add_subdirectory(tools) 96endif(ENABLE_CLANG_JIT) 97