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