Update obsolete file name bitesize -> bitehist
[platform/upstream/bcc.git] / CMakeLists.txt
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(GNUInstallDirs)
15 include(CheckCXXCompilerFlag)
16
17 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
18
19 if(NOT PYTHON_ONLY)
20 find_package(BISON)
21 find_package(FLEX)
22 find_package(LLVM REQUIRED CONFIG)
23 message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS}")
24
25 # clang is linked as a library, but the library path searching is
26 # primitively supported, unlike libLLVM
27 set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}")
28 find_library(libclangAnalysis NAMES clangAnalysis HINTS ${CLANG_SEARCH})
29 find_library(libclangAST NAMES clangAST HINTS ${CLANG_SEARCH})
30 find_library(libclangBasic NAMES clangBasic HINTS ${CLANG_SEARCH})
31 find_library(libclangCodeGen NAMES clangCodeGen HINTS ${CLANG_SEARCH})
32 find_library(libclangDriver NAMES clangDriver HINTS ${CLANG_SEARCH})
33 find_library(libclangEdit NAMES clangEdit HINTS ${CLANG_SEARCH})
34 find_library(libclangFrontend NAMES clangFrontend HINTS ${CLANG_SEARCH})
35 find_library(libclangLex NAMES clangLex HINTS ${CLANG_SEARCH})
36 find_library(libclangParse NAMES clangParse HINTS ${CLANG_SEARCH})
37 find_library(libclangRewrite NAMES clangRewrite HINTS ${CLANG_SEARCH})
38 find_library(libclangSema NAMES clangSema HINTS ${CLANG_SEARCH})
39 find_library(libclangSerialization NAMES clangSerialization HINTS ${CLANG_SEARCH})
40 if(libclangBasic STREQUAL "libclangBasic-NOTFOUND")
41   message(FATAL_ERROR "Unable to find clang libraries")
42 endif()
43 FOREACH(DIR ${LLVM_INCLUDE_DIRS})
44   include_directories("${DIR}/../tools/clang/include")
45 ENDFOREACH()
46
47 # Set to a string path if system places kernel lib directory in
48 # non-default location.
49 if(NOT DEFINED BCC_KERNEL_MODULES_DIR)
50   set(BCC_KERNEL_MODULES_DIR "/lib/modules")
51 endif()
52
53 find_package(LibElf REQUIRED)
54
55 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
56
57 # As reported in issue #735, GCC 6 has some behavioral problems when
58 # dealing with -isystem. Hence, skip the warning optimization
59 # altogether on that compiler.
60 option(USINGISYSTEM "using -isystem" ON)
61 execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
62 if (USINGISYSTEM AND GCC_VERSION VERSION_LESS 6.0)
63   # iterate over all available directories in LLVM_INCLUDE_DIRS to
64   # generate a correctly tokenized list of parameters
65   foreach(ONE_LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
66     set(CXX_ISYSTEM_DIRS "${CXX_ISYSTEM_DIRS} -isystem ${ONE_LLVM_INCLUDE_DIR}")
67   endforeach()
68 endif()
69
70 CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
71 if(COMPILER_SUPPORTS_CXX11)
72   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
73 else()
74   message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
75 endif()
76
77 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
78 endif()
79
80 add_subdirectory(examples)
81 add_subdirectory(man)
82 add_subdirectory(src)
83 add_subdirectory(tests)
84 add_subdirectory(tools)