| Brenden Blanco | 246b942 | 2015-06-05 11:15:27 -0700 | [diff] [blame] | 1 | # Copyright (c) PLUMgrid, Inc. |
| 2 | # Licensed under the Apache License, Version 2.0 (the "License") |
| Brenden Blanco | a94bd93 | 2015-04-26 00:56:42 -0700 | [diff] [blame] | 3 | cmake_minimum_required(VERSION 2.8.7) |
| 4 | |
| Brenden Blanco | f275d3d | 2015-07-06 23:41:23 -0700 | [diff] [blame] | 5 | project(bcc) |
| 6 | set(CMAKE_BUILD_TYPE Release) |
| Brenden Blanco | cd5cb41 | 2015-04-26 09:41:58 -0700 | [diff] [blame] | 7 | |
| 8 | enable_testing() |
| Brenden Blanco | a94bd93 | 2015-04-26 00:56:42 -0700 | [diff] [blame] | 9 | |
| Brenden Blanco | 974e891 | 2015-09-04 09:36:37 -0700 | [diff] [blame] | 10 | include(cmake/GetGitRevisionDescription.cmake) |
| 11 | include(cmake/version.cmake) |
| Brenden Blanco | 6470bbe | 2015-09-23 07:23:35 -0700 | [diff] [blame] | 12 | include(GNUInstallDirs) |
| Brenden Blanco | d8acf6f | 2015-06-07 22:32:33 -0700 | [diff] [blame] | 13 | |
| Vicent Marti | ff9ff5d | 2016-04-20 13:24:54 +0200 | [diff] [blame] | 14 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) |
| 15 | |
| Brenden Blanco | 439a9f3 | 2015-07-03 16:10:29 -0700 | [diff] [blame] | 16 | if(NOT PYTHON_ONLY) |
| Brenden Blanco | a94bd93 | 2015-04-26 00:56:42 -0700 | [diff] [blame] | 17 | find_package(BISON) |
| 18 | find_package(FLEX) |
| 19 | find_package(LLVM REQUIRED CONFIG) |
| Brenden Blanco | cd5cb41 | 2015-04-26 09:41:58 -0700 | [diff] [blame] | 20 | message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS}") |
| Brenden Blanco | 25245bf | 2015-05-10 12:15:06 -0700 | [diff] [blame] | 21 | |
| 22 | # clang is linked as a library, but the library path searching is |
| 23 | # primitively supported, unlike libLLVM |
| Brenden Blanco | f275d3d | 2015-07-06 23:41:23 -0700 | [diff] [blame] | 24 | set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}") |
| Brenden Blanco | 25245bf | 2015-05-10 12:15:06 -0700 | [diff] [blame] | 25 | find_library(libclangAnalysis NAMES clangAnalysis HINTS ${CLANG_SEARCH}) |
| 26 | find_library(libclangAST NAMES clangAST HINTS ${CLANG_SEARCH}) |
| 27 | find_library(libclangBasic NAMES clangBasic HINTS ${CLANG_SEARCH}) |
| 28 | find_library(libclangCodeGen NAMES clangCodeGen HINTS ${CLANG_SEARCH}) |
| 29 | find_library(libclangDriver NAMES clangDriver HINTS ${CLANG_SEARCH}) |
| 30 | find_library(libclangEdit NAMES clangEdit HINTS ${CLANG_SEARCH}) |
| 31 | find_library(libclangFrontend NAMES clangFrontend HINTS ${CLANG_SEARCH}) |
| 32 | find_library(libclangLex NAMES clangLex HINTS ${CLANG_SEARCH}) |
| 33 | find_library(libclangParse NAMES clangParse HINTS ${CLANG_SEARCH}) |
| Brenden Blanco | 7009b55 | 2015-05-26 11:48:17 -0700 | [diff] [blame] | 34 | find_library(libclangRewrite NAMES clangRewrite HINTS ${CLANG_SEARCH}) |
| Brenden Blanco | 25245bf | 2015-05-10 12:15:06 -0700 | [diff] [blame] | 35 | find_library(libclangSema NAMES clangSema HINTS ${CLANG_SEARCH}) |
| 36 | find_library(libclangSerialization NAMES clangSerialization HINTS ${CLANG_SEARCH}) |
| Brenden Blanco | 8310291 | 2015-06-09 17:43:27 -0700 | [diff] [blame] | 37 | if(libclangBasic STREQUAL "libclangBasic-NOTFOUND") |
| 38 | message(FATAL_ERROR "Unable to find clang libraries") |
| 39 | endif() |
| Alexei Starovoitov | 955f3b6 | 2015-06-09 19:37:38 -0700 | [diff] [blame] | 40 | FOREACH(DIR ${LLVM_INCLUDE_DIRS}) |
| 41 | include_directories("${DIR}/../tools/clang/include") |
| 42 | ENDFOREACH() |
| Brenden Blanco | a94bd93 | 2015-04-26 00:56:42 -0700 | [diff] [blame] | 43 | |
| Ragnar Dahlén | dbc21ea | 2016-04-05 23:32:02 +0100 | [diff] [blame] | 44 | # Set to a string path if system places kernel lib directory in |
| 45 | # non-default location. |
| 46 | if(NOT DEFINED BCC_KERNEL_MODULES_DIR) |
| 47 | set(BCC_KERNEL_MODULES_DIR "/lib/modules") |
| 48 | endif() |
| 49 | |
| Vicent Marti | 0612db5 | 2016-04-20 13:24:54 +0200 | [diff] [blame] | 50 | find_package(LibElf REQUIRED) |
| 51 | |
| Brenden Blanco | 3e2f9d9 | 2016-03-07 23:27:59 -0800 | [diff] [blame] | 52 | # 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. |
| 55 | if(BCC_KERNEL_HAS_SOURCE_DIR) |
| 56 | set(BCC_KERNEL_HAS_SOURCE_DIR 1) |
| 57 | set(BCC_KERNEL_MODULES_SUFFIX "source") |
| 58 | else() |
| 59 | set(BCC_KERNEL_HAS_SOURCE_DIR 0) |
| 60 | endif() |
| 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/. |
| 64 | if(NOT DEFINED BCC_KERNEL_MODULES_SUFFIX) |
| 65 | set(BCC_KERNEL_MODULES_SUFFIX "build") |
| 66 | endif() |
| 67 | |
| Gary Lin | 6366a09 | 2015-11-17 10:48:39 +0800 | [diff] [blame] | 68 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") |
| Marco Leogrande | 396ecd7 | 2016-09-27 19:17:02 -0700 | [diff] [blame^] | 69 | # iterate over all available directories in LLVM_INCLUDE_DIRS to |
| 70 | # generate a correctly tokenized list of parameters |
| 71 | foreach(ONE_LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIRS}) |
| 72 | set(CXX_ISYSTEM_DIRS "${CXX_ISYSTEM_DIRS} -isystem ${ONE_LLVM_INCLUDE_DIR}") |
| 73 | endforeach() |
| 74 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall ${CXX_ISYSTEM_DIRS}") |
| Brenden Blanco | 439a9f3 | 2015-07-03 16:10:29 -0700 | [diff] [blame] | 75 | endif() |
| Brenden Blanco | a94bd93 | 2015-04-26 00:56:42 -0700 | [diff] [blame] | 76 | |
| Brenden Blanco | 46176a1 | 2015-07-07 13:05:22 -0700 | [diff] [blame] | 77 | add_subdirectory(examples) |
| Brenden Blanco | c175cf8 | 2015-11-25 18:22:42 -0800 | [diff] [blame] | 78 | add_subdirectory(man) |
| Brenden Blanco | cd5cb41 | 2015-04-26 09:41:58 -0700 | [diff] [blame] | 79 | add_subdirectory(src) |
| 80 | add_subdirectory(tests) |
| Brenden Blanco | c175cf8 | 2015-11-25 18:22:42 -0800 | [diff] [blame] | 81 | add_subdirectory(tools) |