blob: ff3a9cd8cc5db20a4f7401e75f996da12dc6c9ab [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
Brenden Blanco3e2f9d92016-03-07 23:27:59 -080052# Set to non-zero if system installs kernel headers with split source and build
53# directories in /lib/modules/`uname -r`/. This is the case for debian and
54# suse, to the best of my knowledge.
55if(BCC_KERNEL_HAS_SOURCE_DIR)
56 set(BCC_KERNEL_HAS_SOURCE_DIR 1)
57 set(BCC_KERNEL_MODULES_SUFFIX "source")
58else()
59 set(BCC_KERNEL_HAS_SOURCE_DIR 0)
60endif()
61
62# Similar to above, set to custom value if kernel headers in
63# /lib/modules/`uname -r` sit in a different location than build/.
64if(NOT DEFINED BCC_KERNEL_MODULES_SUFFIX)
65 set(BCC_KERNEL_MODULES_SUFFIX "build")
66endif()
67
Gary Lin6366a092015-11-17 10:48:39 +080068set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
Marco Leogrande396ecd72016-09-27 19:17:02 -070069# iterate over all available directories in LLVM_INCLUDE_DIRS to
70# generate a correctly tokenized list of parameters
71foreach(ONE_LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
72 set(CXX_ISYSTEM_DIRS "${CXX_ISYSTEM_DIRS} -isystem ${ONE_LLVM_INCLUDE_DIR}")
73endforeach()
74set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall ${CXX_ISYSTEM_DIRS}")
Brenden Blanco439a9f32015-07-03 16:10:29 -070075endif()
Brenden Blancoa94bd932015-04-26 00:56:42 -070076
Brenden Blanco46176a12015-07-07 13:05:22 -070077add_subdirectory(examples)
Brenden Blancoc175cf82015-11-25 18:22:42 -080078add_subdirectory(man)
Brenden Blancocd5cb412015-04-26 09:41:58 -070079add_subdirectory(src)
80add_subdirectory(tests)
Brenden Blancoc175cf82015-11-25 18:22:42 -080081add_subdirectory(tools)