Commit ac16ae51 authored by Alastair Robertson's avatar Alastair Robertson

Link to libclang

parent b834cd3b
cmake_minimum_required(VERSION 2.8.12)
project(bpftrace)
set(STATIC_LINKING OFF CACHE BOOL "Build bpftrace as a statically linked executable")
add_compile_options("-std=c++14")
add_compile_options("-Wno-format-security")
#add_compile_options("-Wall")
......@@ -39,6 +41,13 @@ else()
)
endif()
if (STATIC_LINKING)
set(CMAKE_EXE_LINKER_FLAGS "-static")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(CMAKE_LINK_SEARCH_START_STATIC TRUE)
set(CMAKE_LINK_SEARCH_END_STATIC TRUE)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
find_package(LibElf REQUIRED)
include_directories(${LIBELF_INCLUDE_DIRS})
......@@ -51,11 +60,12 @@ add_flex_bison_dependency(flex_lexer bison_parser)
add_library(parser ${BISON_bison_parser_OUTPUTS} ${FLEX_flex_lexer_OUTPUTS})
target_include_directories(parser PUBLIC src src/ast ${CMAKE_BINARY_DIR})
find_package(LLVM REQUIRED CONFIG)
find_package(LLVM REQUIRED)
include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
set(STATIC_LINKING OFF CACHE BOOL "Build bpftrace as a statically linked executable")
find_package(Clang REQUIRED)
include_directories(${CLANG_INCLUDE_DIRS})
add_subdirectory(src/arch)
add_subdirectory(src/ast)
......
if (STATIC_LINKING)
set(CMAKE_EXE_LINKER_FLAGS "-static")
endif()
add_executable(bpftrace
attached_probe.cpp
bpftrace.cpp
......@@ -16,10 +12,6 @@ add_executable(bpftrace
target_link_libraries(bpftrace arch ast parser)
llvm_map_components_to_libnames(llvm_libs bpfcodegen ipo irreader mcjit orcjit)
target_link_libraries(bpftrace ${llvm_libs})
add_dependencies(bpftrace bcc-build)
ExternalProject_Get_Property(bcc source_dir binary_dir)
target_include_directories(bpftrace PUBLIC ${source_dir}/src/cc)
target_link_libraries(bpftrace ${binary_dir}/src/cc/libbpf.a)
......
......@@ -11,6 +11,30 @@ target_include_directories(ast PUBLIC ${CMAKE_SOURCE_DIR}/src/ast)
target_include_directories(ast PUBLIC ${CMAKE_BINARY_DIR})
target_link_libraries(ast arch)
add_dependencies(ast bcc-build)
add_dependencies(ast bcc-build parser)
ExternalProject_Get_Property(bcc source_dir)
target_include_directories(ast PUBLIC ${source_dir}/src/cc)
if (STATIC_LINKING)
set(clang_libs
libclang.a
clangAST
clangAnalysis
clangBasic
clangDriver
clangEdit
clangFormat
clangFrontend
clangIndex
clangLex
clangParse
clangRewrite
clangSema
clangSerialization
clangToolingCore)
llvm_map_components_to_libnames(llvm_libs bpfcodegen ipo irreader mcjit orcjit ${LLVM_TARGETS_TO_BUILD})
target_link_libraries(ast ${clang_libs})
target_link_libraries(ast ${llvm_libs})
else()
target_link_libraries(ast LLVM libclang)
endif()
if (STATIC_LINKING)
set(CMAKE_EXE_LINKER_FLAGS "-static")
endif()
add_compile_options("-Wno-undef")
add_compile_options("-Wno-switch-default")
add_compile_options("-Wno-switch-enum")
......@@ -21,19 +17,10 @@ add_executable(bpftrace_test
${CMAKE_SOURCE_DIR}/src/mapkey.cpp
${CMAKE_SOURCE_DIR}/src/printf.cpp
${CMAKE_SOURCE_DIR}/src/types.cpp
${CMAKE_SOURCE_DIR}/src/ast/ast.cpp
${CMAKE_SOURCE_DIR}/src/ast/codegen_llvm.cpp
${CMAKE_SOURCE_DIR}/src/ast/irbuilderbpf.cpp
${CMAKE_SOURCE_DIR}/src/ast/printer.cpp
${CMAKE_SOURCE_DIR}/src/ast/semantic_analyser.cpp
)
target_link_libraries(bpftrace_test arch parser)
llvm_map_components_to_libnames(llvm_libs bpfcodegen ipo irreader mcjit)
target_link_libraries(bpftrace_test ${llvm_libs})
target_link_libraries(bpftrace_test arch ast parser)
add_dependencies(bpftrace_test bcc-build)
ExternalProject_Get_Property(bcc source_dir binary_dir)
target_include_directories(bpftrace_test PUBLIC ${source_dir}/src/cc)
target_link_libraries(bpftrace_test ${binary_dir}/src/cc/libbpf.a)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment