Skip to content

Commit

Permalink
Add some more options to the BCC build
Browse files Browse the repository at this point in the history
Signed-off-by: Zain Asgar <[email protected]>
  • Loading branch information
zasgar authored and JamesMBartlett committed Oct 19, 2022
1 parent 341d921 commit b9cc317
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 39 deletions.
34 changes: 23 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ include(GNUInstallDirs)
include(CheckCXXCompilerFlag)
include(cmake/FindCompilerFlag.cmake)


option(ENABLE_INTROSPECTIONS "Enable introspection tool" OFF)
option(ENABLE_LUA "Enable lua bindings" OFF)
option(ENABLE_PYTHON "Enable python binding" OFF)
option(ENABLE_SHARED "Enable shared libraries" OFF)
option(ENABLE_LLVM_NATIVECODEGEN "Enable use of llvm nativecodegen module (needed by rw-engine)" ON)
option(ENABLE_RTTI "Enable compiling with real time type information" OFF)
option(ENABLE_LLVM_SHARED "Enable linking LLVM as a shared library" OFF)
Expand Down Expand Up @@ -179,16 +184,23 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")

add_subdirectory(src)
add_subdirectory(introspection)

if(ENABLE_INTROSPECTIONS)
add_subdirectory(introspection)
endif(ENABLE_INTROSPECTIONS)

if(ENABLE_CLANG_JIT)
if(ENABLE_EXAMPLES)
add_subdirectory(examples)
endif(ENABLE_EXAMPLES)
if(ENABLE_MAN)
add_subdirectory(man)
endif(ENABLE_MAN)
if(ENABLE_TESTS)
add_subdirectory(tests)
endif(ENABLE_TESTS)
add_subdirectory(tools)
if(ENABLE_EXAMPLES)
add_subdirectory(examples)
endif(ENABLE_EXAMPLES)

if(ENABLE_MAN)
add_subdirectory(man)
endif(ENABLE_MAN)

if(ENABLE_TESTS)
add_subdirectory(tests)
endif(ENABLE_TESTS)

add_subdirectory(tools)
endif(ENABLE_CLANG_JIT)
16 changes: 11 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

if (ENABLE_RTTI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})

if(NOT PYTHON_ONLY)
add_subdirectory(cc)
add_subdirectory(cc)
endif()

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

if(ENABLE_LUA)
add_subdirectory(lua)
endif(ENABLE_LUA)
endif()
59 changes: 36 additions & 23 deletions src/cc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
# to be removed
include_directories(${CMAKE_CURRENT_BINARY_DIR}/frontends/b)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/frontends/b)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/frontends/clang)
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${LIBELF_INCLUDE_DIRS})

if (LIBDEBUGINFOD_FOUND)
include_directories(${LIBDEBUGINFOD_INCLUDE_DIRS})
endif (LIBDEBUGINFOD_FOUND)

# todo: if check for kernel version
if (CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
include_directories(${LIBBPF_INCLUDE_DIRS})
Expand All @@ -38,8 +38,6 @@ endif()
string(REGEX MATCH "^([0-9]+).*" _ ${LLVM_PACKAGE_VERSION})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_MAJOR_VERSION=${CMAKE_MATCH_1}")

include(static_libstdc++)

if(LIBBPF_INCLUDE_DIR)
# Add user libbpf include and notify compilation
# that we are using external libbpf. It's checked
Expand Down Expand Up @@ -82,11 +80,13 @@ if(LIBBPF_FOUND)
endif()

if(ENABLE_CLANG_JIT)
add_library(bcc-shared SHARED
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)
if(ENABLE_SHARED)
add_library(bcc-shared SHARED
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)
endif(ENABLE_SHARED)

if(ENABLE_USDT)
add_definitions(-DEXPORT_USDT)
Expand All @@ -106,16 +106,19 @@ set(bpf_sources libbpf.c perf_reader.c ${libbpf_sources} ${bcc_sym_sources} ${bc
add_library(bpf-static STATIC ${bpf_sources})
set_target_properties(bpf-static PROPERTIES OUTPUT_NAME bcc_bpf)
target_link_libraries(bpf-static elf z)
add_library(bpf-shared SHARED ${bpf_sources})
set_target_properties(bpf-shared PROPERTIES VERSION ${REVISION_LAST} SOVERSION 0)
set_target_properties(bpf-shared PROPERTIES OUTPUT_NAME bcc_bpf)
target_link_libraries(bpf-shared elf z)
if(LIBDEBUGINFOD_FOUND)
target_link_libraries(bpf-shared ${LIBDEBUGINFOD_LIBRARIES})
endif(LIBDEBUGINFOD_FOUND)
if(CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
target_link_libraries(bpf-shared ${LIBBPF_LIBRARIES})
endif()

if(ENABLE_SHARED)
add_library(bpf-shared SHARED ${bpf_sources})
set_target_properties(bpf-shared PROPERTIES VERSION ${REVISION_LAST} SOVERSION 0)
set_target_properties(bpf-shared PROPERTIES OUTPUT_NAME bcc_bpf)
target_link_libraries(bpf-shared elf z)
if(LIBDEBUGINFOD_FOUND)
target_link_libraries(bpf-shared ${LIBDEBUGINFOD_LIBRARIES})
endif(LIBDEBUGINFOD_FOUND)
if(CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
target_link_libraries(bpf-shared ${LIBBPF_LIBRARIES})
endif()
endif(ENABLE_SHARED)

include(clang_libs)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${clang_lib_exclude_flags}")
Expand Down Expand Up @@ -161,15 +164,25 @@ endif()
add_subdirectory(frontends)

# Link against LLVM libraries
target_link_libraries(bcc-shared ${bcc_common_libs_for_s})
if(ENABLE_SHARED)
target_link_libraries(bcc-shared ${bcc_common_libs_for_s})
endif(ENABLE_SHARED)

target_link_libraries(bcc-static ${bcc_common_libs_for_a} bcc-loader-static)
set(bcc-lua-static ${bcc-lua-static} ${bcc_common_libs_for_lua})

install(TARGETS bcc-shared bcc-static bcc-loader-static bpf-static LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS bcc-static bcc-loader-static bpf-static LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${bcc_table_headers} DESTINATION include/bcc)
install(FILES ${bcc_api_headers} DESTINATION include/bcc)
install(DIRECTORY ${libbpf_uapi} DESTINATION include/bcc/compat/linux FILES_MATCHING PATTERN "*.h")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbcc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
if(ENABLE_SHARED)
install(TARGETS bcc-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif(ENABLE_SHARED)

endif(ENABLE_CLANG_JIT)
install(FILES ${bcc_common_headers} DESTINATION include/bcc)
install(TARGETS bpf-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

if(ENABLE_SHARED)
install(TARGETS bpf-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif(ENABLE_SHARED)

0 comments on commit b9cc317

Please sign in to comment.