Skip to content

Commit

Permalink
Add c-library only option
Browse files Browse the repository at this point in the history
Allow building of JUST the libbpf library and related headers. No clang,
llvm, python, lua, etc. Not even tests :(

Signed-off-by: Brenden Blanco <[email protected]>
  • Loading branch information
drzaeus77 committed Aug 25, 2017
1 parent 71fc3d5 commit 7fef695
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
19 changes: 12 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ include(GNUInstallDirs)
include(CheckCXXCompilerFlag)
include(cmake/FindCompilerFlag.cmake)

option(ENABLE_CLANG_JIT "Enable Loading BPF through Clang Frontend" ON)
option(ENABLE_USDT "Enable User-level Statically Defined Tracing" ON)
CMAKE_DEPENDENT_OPTION(ENABLE_CPP_API "Enable C++ API" ON "ENABLE_USDT" OFF)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

if(NOT PYTHON_ONLY)
if(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
find_package(BISON)
find_package(FLEX)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS}")
find_package(LibElf REQUIRED)

# clang is linked as a library, but the library path searching is
# primitively supported, unlike libLLVM
Expand Down Expand Up @@ -52,10 +57,6 @@ if(NOT DEFINED BCC_KERNEL_MODULES_DIR)
set(BCC_KERNEL_MODULES_DIR "/lib/modules")
endif()

find_package(LibElf REQUIRED)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")

# As reported in issue #735, GCC 6 has some behavioral problems when
# dealing with -isystem. Hence, skip the warning optimization
# altogether on that compiler.
Expand All @@ -76,11 +77,15 @@ else()
message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
endif()

endif(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
endif()

add_subdirectory(src)
if(ENABLE_CLANG_JIT)
add_subdirectory(examples)
add_subdirectory(man)
add_subdirectory(src)
add_subdirectory(tests)
add_subdirectory(tools)
endif(ENABLE_CLANG_JIT)
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
set(EXAMPLE_PROGRAMS hello_world.py)
install(PROGRAMS ${EXAMPLE_PROGRAMS} DESTINATION share/bcc/examples)

if(ENABLE_CLANG_JIT)
add_subdirectory(cpp)
add_subdirectory(lua)
add_subdirectory(networking)
add_subdirectory(tracing)
endif()
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
if(NOT PYTHON_ONLY)
add_subdirectory(cc)
endif()
if(ENABLE_CLANG_JIT)
add_subdirectory(python)
add_subdirectory(lua)
endif()
33 changes: 15 additions & 18 deletions src/cc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ set(bcc_common_sources bpf_common.cc bpf_module.cc exported_files.cc)
set(bcc_table_sources table_storage.cc shared_table.cc bpffs_table.cc json_map_decl_visitor.cc)
set(bcc_util_sources ns_guard.cc common.cc)
set(bcc_sym_sources bcc_syms.cc bcc_elf.c bcc_perf_map.c bcc_proc.c)
set(bcc_common_headers libbpf.h perf_reader.h)
set(bcc_table_headers file_desc.h table_desc.h table_storage.h)
set(bcc_api_headers bpf_common.h bpf_module.h bcc_exception.h bcc_syms.h)

if(ENABLE_CLANG_JIT)
add_library(bcc-shared SHARED
link_all.cc
${bcc_common_sources} ${bcc_table_sources} ${bcc_sym_sources}
link_all.cc ${bcc_common_sources} ${bcc_table_sources} ${bcc_sym_sources}
${bcc_util_sources})
set_target_properties(bcc-shared PROPERTIES VERSION ${REVISION_LAST} SOVERSION 0)
set_target_properties(bcc-shared PROPERTIES OUTPUT_NAME bcc)
Expand All @@ -48,9 +51,6 @@ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${llvm_lib_exclude_f
set(bcc_common_libs b_frontend clang_frontend bpf-static
${clang_libs} ${llvm_libs} ${LIBELF_LIBRARIES})

option(ENABLE_USDT "Enable User-level Statically Defined Tracing" ON)
CMAKE_DEPENDENT_OPTION(ENABLE_CPP_API "Enable C++ API" ON "ENABLE_USDT" OFF)

if(ENABLE_CPP_API)
add_subdirectory(api)
list(APPEND bcc_common_libs api-static)
Expand All @@ -61,20 +61,17 @@ if(ENABLE_USDT)
list(APPEND bcc_common_libs usdt-static)
endif()

add_subdirectory(frontends)

# Link against LLVM libraries
target_link_libraries(bcc-shared ${bcc_common_libs})
target_link_libraries(bcc-static ${bcc_common_libs} bcc-loader-static)

install(TARGETS bcc-shared LIBRARY COMPONENT libbcc
DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES bpf_common.h bpf_module.h bcc_syms.h bcc_exception.h file_desc.h
libbpf.h perf_reader.h
table_desc.h table_storage.h COMPONENT libbcc
DESTINATION include/bcc)
install(DIRECTORY compat/linux/ COMPONENT libbcc
DESTINATION include/bcc/compat/linux
FILES_MATCHING PATTERN "*.h")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbcc.pc COMPONENT libbcc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

add_subdirectory(frontends)
install(TARGETS bcc-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${bcc_table_headers} DESTINATION include/bcc)
install(FILES ${bcc_api_headers} DESTINATION include/bcc)
install(DIRECTORY compat/linux/ DESTINATION include/bcc/compat/linux FILES_MATCHING PATTERN "*.h")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbcc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif(ENABLE_CLANG_JIT)
install(FILES ${bcc_common_headers} DESTINATION include/bcc)
install(TARGETS bpf-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ set(TEST_WRAPPER ${CMAKE_CURRENT_BINARY_DIR}/wrapper.sh)
add_test(NAME style-check COMMAND ${CMAKE_SOURCE_DIR}/scripts/style-check.sh)
set_tests_properties(style-check PROPERTIES PASS_REGULAR_EXPRESSION ".*")

if(ENABLE_CLANG_JIT)
add_subdirectory(cc)
add_subdirectory(python)
add_subdirectory(lua)
endif()

0 comments on commit 7fef695

Please sign in to comment.