blob: 7feca07c3eb34a9a31e5283ef8e78b8ed40c1703 [file] [log] [blame]
Brenden Blanco246b9422015-06-05 11:15:27 -07001# Copyright (c) PLUMgrid, Inc.
2# Licensed under the Apache License, Version 2.0 (the "License")
Brenden Blancoa94bd932015-04-26 00:56:42 -07003cmake_minimum_required(VERSION 2.8.7)
4
Brenden Blancof275d3d2015-07-06 23:41:23 -07005project(bcc)
6set(CMAKE_BUILD_TYPE Release)
Brenden Blancocd5cb412015-04-26 09:41:58 -07007
8enable_testing()
Brenden Blancoa94bd932015-04-26 00:56:42 -07009
Brenden Blanco974e8912015-09-04 09:36:37 -070010include(cmake/GetGitRevisionDescription.cmake)
11include(cmake/version.cmake)
Brenden Blanco6470bbe2015-09-23 07:23:35 -070012include(GNUInstallDirs)
Brenden Blancod8acf6f2015-06-07 22:32:33 -070013
Vicent Martiff9ff5d2016-04-20 13:24:54 +020014set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
15
Brenden Blanco439a9f32015-07-03 16:10:29 -070016if(NOT PYTHON_ONLY)
Brenden Blancoa94bd932015-04-26 00:56:42 -070017find_package(BISON)
18find_package(FLEX)
19find_package(LLVM REQUIRED CONFIG)
Brenden Blancocd5cb412015-04-26 09:41:58 -070020message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS}")
Brenden Blanco25245bf2015-05-10 12:15:06 -070021
22# clang is linked as a library, but the library path searching is
23# primitively supported, unlike libLLVM
Brenden Blancof275d3d2015-07-06 23:41:23 -070024set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}")
Brenden Blanco25245bf2015-05-10 12:15:06 -070025find_library(libclangAnalysis NAMES clangAnalysis HINTS ${CLANG_SEARCH})
26find_library(libclangAST NAMES clangAST HINTS ${CLANG_SEARCH})
27find_library(libclangBasic NAMES clangBasic HINTS ${CLANG_SEARCH})
28find_library(libclangCodeGen NAMES clangCodeGen HINTS ${CLANG_SEARCH})
29find_library(libclangDriver NAMES clangDriver HINTS ${CLANG_SEARCH})
30find_library(libclangEdit NAMES clangEdit HINTS ${CLANG_SEARCH})
31find_library(libclangFrontend NAMES clangFrontend HINTS ${CLANG_SEARCH})
32find_library(libclangLex NAMES clangLex HINTS ${CLANG_SEARCH})
33find_library(libclangParse NAMES clangParse HINTS ${CLANG_SEARCH})
Brenden Blanco7009b552015-05-26 11:48:17 -070034find_library(libclangRewrite NAMES clangRewrite HINTS ${CLANG_SEARCH})
Brenden Blanco25245bf2015-05-10 12:15:06 -070035find_library(libclangSema NAMES clangSema HINTS ${CLANG_SEARCH})
36find_library(libclangSerialization NAMES clangSerialization HINTS ${CLANG_SEARCH})
Brenden Blanco83102912015-06-09 17:43:27 -070037if(libclangBasic STREQUAL "libclangBasic-NOTFOUND")
38 message(FATAL_ERROR "Unable to find clang libraries")
39endif()
Alexei Starovoitov955f3b62015-06-09 19:37:38 -070040FOREACH(DIR ${LLVM_INCLUDE_DIRS})
41 include_directories("${DIR}/../tools/clang/include")
42ENDFOREACH()
Brenden Blancoa94bd932015-04-26 00:56:42 -070043
Ragnar Dahléndbc21ea2016-04-05 23:32:02 +010044# Set to a string path if system places kernel lib directory in
45# non-default location.
46if(NOT DEFINED BCC_KERNEL_MODULES_DIR)
47 set(BCC_KERNEL_MODULES_DIR "/lib/modules")
48endif()
49
Vicent Marti0612db52016-04-20 13:24:54 +020050find_package(LibElf REQUIRED)
51
Gary Lin6366a092015-11-17 10:48:39 +080052set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
Marco Leogrande0c461c92016-10-06 12:28:40 -070053
54# As reported in issue #735, GCC 6 has some behavioral problems when
55# dealing with -isystem. Hence, skip the warning optimization
56# altogether on that compiler.
57execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
58if (GCC_VERSION VERSION_LESS 6.0)
59 # iterate over all available directories in LLVM_INCLUDE_DIRS to
60 # generate a correctly tokenized list of parameters
61 foreach(ONE_LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
62 set(CXX_ISYSTEM_DIRS "${CXX_ISYSTEM_DIRS} -isystem ${ONE_LLVM_INCLUDE_DIR}")
63 endforeach()
64endif()
65
Marco Leogrande396ecd72016-09-27 19:17:02 -070066set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall ${CXX_ISYSTEM_DIRS}")
Brenden Blanco439a9f32015-07-03 16:10:29 -070067endif()
Brenden Blancoa94bd932015-04-26 00:56:42 -070068
Brenden Blanco46176a12015-07-07 13:05:22 -070069add_subdirectory(examples)
Brenden Blancoc175cf82015-11-25 18:22:42 -080070add_subdirectory(man)
Brenden Blancocd5cb412015-04-26 09:41:58 -070071add_subdirectory(src)
72add_subdirectory(tests)
Brenden Blancoc175cf82015-11-25 18:22:42 -080073add_subdirectory(tools)