Home | History | Annotate | Download | only in bcc
      1 # Copyright (c) PLUMgrid, Inc.
      2 # Licensed under the Apache License, Version 2.0 (the "License")
      3 cmake_minimum_required(VERSION 2.8.7)
      4 
      5 project(bcc)
      6 if(NOT CMAKE_BUILD_TYPE)
      7   set(CMAKE_BUILD_TYPE Release)
      8 endif()
      9 
     10 enable_testing()
     11 
     12 include(cmake/GetGitRevisionDescription.cmake)
     13 include(cmake/version.cmake)
     14 include(CMakeDependentOption)
     15 include(GNUInstallDirs)
     16 include(CheckCXXCompilerFlag)
     17 include(cmake/FindCompilerFlag.cmake)
     18 
     19 option(ENABLE_LLVM_SHARED "Enable linking LLVM as a shared library" OFF)
     20 option(ENABLE_CLANG_JIT "Enable Loading BPF through Clang Frontend" ON)
     21 option(ENABLE_USDT "Enable User-level Statically Defined Tracing" ON)
     22 CMAKE_DEPENDENT_OPTION(ENABLE_CPP_API "Enable C++ API" ON "ENABLE_USDT" OFF)
     23 
     24 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
     25 
     26 if(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
     27 find_package(BISON)
     28 find_package(FLEX)
     29 find_package(LLVM REQUIRED CONFIG)
     30 message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS} ${LLVM_PACKAGE_VERSION}")
     31 find_package(LibElf REQUIRED)
     32 
     33 # clang is linked as a library, but the library path searching is
     34 # primitively supported, unlike libLLVM
     35 set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}")
     36 find_library(libclangAnalysis NAMES clangAnalysis HINTS ${CLANG_SEARCH})
     37 find_library(libclangAST NAMES clangAST HINTS ${CLANG_SEARCH})
     38 find_library(libclangBasic NAMES clangBasic HINTS ${CLANG_SEARCH})
     39 find_library(libclangCodeGen NAMES clangCodeGen HINTS ${CLANG_SEARCH})
     40 find_library(libclangDriver NAMES clangDriver HINTS ${CLANG_SEARCH})
     41 find_library(libclangEdit NAMES clangEdit HINTS ${CLANG_SEARCH})
     42 find_library(libclangFrontend NAMES clangFrontend HINTS ${CLANG_SEARCH})
     43 find_library(libclangLex NAMES clangLex HINTS ${CLANG_SEARCH})
     44 find_library(libclangParse NAMES clangParse HINTS ${CLANG_SEARCH})
     45 find_library(libclangRewrite NAMES clangRewrite HINTS ${CLANG_SEARCH})
     46 find_library(libclangSema NAMES clangSema HINTS ${CLANG_SEARCH})
     47 find_library(libclangSerialization NAMES clangSerialization HINTS ${CLANG_SEARCH})
     48 find_library(libclangASTMatchers NAMES clangASTMatchers HINTS ${CLANG_SEARCH})
     49 if(libclangBasic STREQUAL "libclangBasic-NOTFOUND")
     50   message(FATAL_ERROR "Unable to find clang libraries")
     51 endif()
     52 FOREACH(DIR ${LLVM_INCLUDE_DIRS})
     53   include_directories("${DIR}/../tools/clang/include")
     54 ENDFOREACH()
     55 
     56 # Set to a string path if system places kernel lib directory in
     57 # non-default location.
     58 if(NOT DEFINED BCC_KERNEL_MODULES_DIR)
     59   set(BCC_KERNEL_MODULES_DIR "/lib/modules")
     60 endif()
     61 
     62 if(NOT DEFINED BCC_PROG_TAG_DIR)
     63   set(BCC_PROG_TAG_DIR "/var/tmp/bcc")
     64 endif()
     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.
     69 option(USINGISYSTEM "using -isystem" ON)
     70 execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
     71 if (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()
     77 endif()
     78 
     79 set(CMAKE_CXX_STANDARD_REQUIRED ON)
     80 set(CMAKE_CXX_STANDARD 11)
     81 
     82 endif(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
     83 
     84 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
     85 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
     86 
     87 add_subdirectory(src)
     88 add_subdirectory(introspection)
     89 if(ENABLE_CLANG_JIT)
     90 add_subdirectory(examples)
     91 add_subdirectory(man)
     92 add_subdirectory(tests)
     93 add_subdirectory(tools)
     94 endif(ENABLE_CLANG_JIT)
     95