1 # Copyright (c) PLUMgrid, Inc.
2 # Licensed under the Apache License, Version 2.0 (the "License")
3 cmake_minimum_required(VERSION 2.8.7)
6 if(NOT CMAKE_BUILD_TYPE)
7 set(CMAKE_BUILD_TYPE Release)
12 include(cmake/GetGitRevisionDescription.cmake)
13 include(cmake/version.cmake)
14 include(CMakeDependentOption)
15 include(GNUInstallDirs)
16 include(CheckCXXCompilerFlag)
17 include(cmake/FindCompilerFlag.cmake)
19 option(ENABLE_CLANG_JIT "Enable Loading BPF through Clang Frontend" ON)
20 option(ENABLE_USDT "Enable User-level Statically Defined Tracing" ON)
21 CMAKE_DEPENDENT_OPTION(ENABLE_CPP_API "Enable C++ API" ON "ENABLE_USDT" OFF)
23 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
25 if(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
28 find_package(LLVM REQUIRED CONFIG)
29 message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS}")
30 find_package(LibElf REQUIRED)
32 # clang is linked as a library, but the library path searching is
33 # primitively supported, unlike libLLVM
34 set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}")
35 find_library(libclangAnalysis NAMES clangAnalysis HINTS ${CLANG_SEARCH})
36 find_library(libclangAST NAMES clangAST HINTS ${CLANG_SEARCH})
37 find_library(libclangBasic NAMES clangBasic HINTS ${CLANG_SEARCH})
38 find_library(libclangCodeGen NAMES clangCodeGen HINTS ${CLANG_SEARCH})
39 find_library(libclangDriver NAMES clangDriver HINTS ${CLANG_SEARCH})
40 find_library(libclangEdit NAMES clangEdit HINTS ${CLANG_SEARCH})
41 find_library(libclangFrontend NAMES clangFrontend HINTS ${CLANG_SEARCH})
42 find_library(libclangLex NAMES clangLex HINTS ${CLANG_SEARCH})
43 find_library(libclangParse NAMES clangParse HINTS ${CLANG_SEARCH})
44 find_library(libclangRewrite NAMES clangRewrite HINTS ${CLANG_SEARCH})
45 find_library(libclangSema NAMES clangSema HINTS ${CLANG_SEARCH})
46 find_library(libclangSerialization NAMES clangSerialization HINTS ${CLANG_SEARCH})
47 if(libclangBasic STREQUAL "libclangBasic-NOTFOUND")
48 message(FATAL_ERROR "Unable to find clang libraries")
50 FOREACH(DIR ${LLVM_INCLUDE_DIRS})
51 include_directories("${DIR}/../tools/clang/include")
54 # Set to a string path if system places kernel lib directory in
55 # non-default location.
56 if(NOT DEFINED BCC_KERNEL_MODULES_DIR)
57 set(BCC_KERNEL_MODULES_DIR "/lib/modules")
60 # As reported in issue #735, GCC 6 has some behavioral problems when
61 # dealing with -isystem. Hence, skip the warning optimization
62 # altogether on that compiler.
63 option(USINGISYSTEM "using -isystem" ON)
64 execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
65 if (USINGISYSTEM AND GCC_VERSION VERSION_LESS 6.0)
66 # iterate over all available directories in LLVM_INCLUDE_DIRS to
67 # generate a correctly tokenized list of parameters
68 foreach(ONE_LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
69 set(CXX_ISYSTEM_DIRS "${CXX_ISYSTEM_DIRS} -isystem ${ONE_LLVM_INCLUDE_DIR}")
73 set(CMAKE_CXX_STANDARD_REQUIRED ON)
74 set(CMAKE_CXX_STANDARD 11)
76 endif(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
78 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
79 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
83 add_subdirectory(examples)
85 add_subdirectory(tests)
86 add_subdirectory(tools)
87 endif(ENABLE_CLANG_JIT)