1# Copyright (c) PLUMgrid, Inc. 2# Licensed under the Apache License, Version 2.0 (the "License") 3 4include_directories(${CMAKE_CURRENT_BINARY_DIR}) 5include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 6# to be removed 7include_directories(${CMAKE_CURRENT_BINARY_DIR}/frontends/b) 8include_directories(${CMAKE_CURRENT_SOURCE_DIR}/frontends/b) 9include_directories(${CMAKE_CURRENT_SOURCE_DIR}/frontends/clang) 10include_directories(${LLVM_INCLUDE_DIRS}) 11include_directories(${LIBELF_INCLUDE_DIRS}) 12# todo: if check for kernel version 13include_directories(${CMAKE_CURRENT_SOURCE_DIR}/compat) 14add_definitions(${LLVM_DEFINITIONS}) 15configure_file(libbcc.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libbcc.pc @ONLY) 16 17set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -DBCC_PROG_TAG_DIR='\"${BCC_PROG_TAG_DIR}\"'") 18set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-result") 19set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wno-unused-result") 20 21string(REGEX MATCH "^([0-9]+).*" _ ${LLVM_PACKAGE_VERSION}) 22set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_MAJOR_VERSION=${CMAKE_MATCH_1}") 23 24include(static_libstdc++) 25 26add_library(bpf-static STATIC libbpf.c perf_reader.c) 27set_target_properties(bpf-static PROPERTIES OUTPUT_NAME bpf) 28add_library(bpf-shared SHARED libbpf.c perf_reader.c) 29set_target_properties(bpf-shared PROPERTIES VERSION ${REVISION_LAST} SOVERSION 0) 30set_target_properties(bpf-shared PROPERTIES OUTPUT_NAME bpf) 31 32set(bcc_common_sources bpf_common.cc bpf_module.cc exported_files.cc) 33if (${LLVM_PACKAGE_VERSION} VERSION_EQUAL 6 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 6) 34 set(bcc_common_sources ${bcc_common_sources} bcc_debug.cc) 35endif() 36 37if(ENABLE_LLVM_NATIVECODEGEN) 38set(bcc_common_sources ${bcc_common_sources} bpf_module_rw_engine.cc) 39else() 40set(bcc_common_sources ${bcc_common_sources} bpf_module_rw_engine_disabled.cc) 41endif() 42 43set(bcc_table_sources table_storage.cc shared_table.cc bpffs_table.cc json_map_decl_visitor.cc) 44set(bcc_util_sources ns_guard.cc common.cc) 45set(bcc_sym_sources bcc_syms.cc bcc_elf.c bcc_perf_map.c bcc_proc.c) 46set(bcc_common_headers libbpf.h perf_reader.h) 47set(bcc_table_headers file_desc.h table_desc.h table_storage.h) 48set(bcc_api_headers bpf_common.h bpf_module.h bcc_exception.h bcc_syms.h bcc_elf.h) 49 50if(ENABLE_CLANG_JIT) 51add_library(bcc-shared SHARED 52 link_all.cc ${bcc_common_sources} ${bcc_table_sources} ${bcc_sym_sources} 53 ${bcc_util_sources}) 54set_target_properties(bcc-shared PROPERTIES VERSION ${REVISION_LAST} SOVERSION 0) 55set_target_properties(bcc-shared PROPERTIES OUTPUT_NAME bcc) 56 57if(ENABLE_USDT) 58 set(bcc_usdt_sources usdt/usdt.cc usdt/usdt_args.cc) 59 # else undefined 60endif() 61 62add_library(bcc-loader-static STATIC ${bcc_sym_sources} ${bcc_util_sources}) 63target_link_libraries(bcc-loader-static elf) 64add_library(bcc-static STATIC 65 ${bcc_common_sources} ${bcc_table_sources} ${bcc_util_sources} ${bcc_usdt_sources}) 66set_target_properties(bcc-static PROPERTIES OUTPUT_NAME bcc) 67set(bcc-lua-static 68 ${bcc_common_sources} ${bcc_table_sources} ${bcc_sym_sources} ${bcc_util_sources}) 69 70include(clang_libs) 71set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${clang_lib_exclude_flags}") 72set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${llvm_lib_exclude_flags}") 73 74# bcc_common_libs_for_a for archive libraries 75# bcc_common_libs_for_s for shared libraries 76set(bcc_common_libs_for_a b_frontend clang_frontend bpf-static 77 -Wl,--whole-archive ${clang_libs} ${llvm_libs} -Wl,--no-whole-archive 78 ${LIBELF_LIBRARIES}) 79set(bcc_common_libs_for_s ${bcc_common_libs_for_a}) 80set(bcc_common_libs_for_lua b_frontend clang_frontend bpf-static 81 ${clang_libs} ${llvm_libs} ${LIBELF_LIBRARIES}) 82 83if(ENABLE_CPP_API) 84 add_subdirectory(api) 85 list(APPEND bcc_common_libs_for_a api-static) 86 # Keep all API functions 87 list(APPEND bcc_common_libs_for_s -Wl,--whole-archive api-static -Wl,--no-whole-archive) 88endif() 89 90if(ENABLE_USDT) 91 list(APPEND bcc_api_headers bcc_usdt.h) 92 add_subdirectory(usdt) 93 list(APPEND bcc_common_libs_for_a usdt-static) 94 list(APPEND bcc_common_libs_for_s usdt-static) 95 list(APPEND bcc_common_libs_for_lua usdt-static) 96endif() 97 98add_subdirectory(frontends) 99 100# Link against LLVM libraries 101target_link_libraries(bcc-shared ${bcc_common_libs_for_s}) 102target_link_libraries(bcc-static ${bcc_common_libs_for_a} bcc-loader-static) 103set(bcc-lua-static ${bcc-lua-static} ${bcc_common_libs_for_lua}) 104 105install(TARGETS bcc-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) 106install(FILES ${bcc_table_headers} DESTINATION include/bcc) 107install(FILES ${bcc_api_headers} DESTINATION include/bcc) 108install(DIRECTORY compat/linux/ DESTINATION include/bcc/compat/linux FILES_MATCHING PATTERN "*.h") 109install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbcc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) 110endif(ENABLE_CLANG_JIT) 111install(FILES ${bcc_common_headers} DESTINATION include/bcc) 112install(TARGETS bpf-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) 113