Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Officeyutong committed Aug 28, 2024
1 parent a9598f8 commit 2b26ee4
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 56 deletions.
92 changes: 50 additions & 42 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ function(bpftime_add_static_lib_component_command target)
)
set(BPFTIME_STATIC_LIB_AR_CMDS ${BPFTIME_STATIC_LIB_AR_CMDS} ${CMDS} PARENT_SCOPE)
endif()

set(BPFTIME_STATIC_LIB_DEPS ${BPFTIME_STATIC_LIB_DEPS} ${target} PARENT_SCOPE)
endfunction()

function(bpftime_add_libs_component_command target_path)
get_filename_component(target_name ${target_path} NAME)
string(REGEX REPLACE "^lib" "" target_name ${target_name})
string(REGEX REPLACE "\.a$" "" target_name ${target_name})

if(APPLE)
if(CMAKE_AR_NAME STREQUAL "ar")
list(APPEND CMDS
Expand Down Expand Up @@ -117,22 +119,27 @@ endif()
if(${BPFTIME_BUILD_WITH_LIBBPF})
include(cmake/libbpf.cmake)
endif()

# install frida
include(cmake/frida.cmake)


set(CMAKE_POSITION_INDEPENDENT_CODE YES)

if(${ENABLE_EBPF_VERIFIER})
add_subdirectory(bpftime-verifier)
else()
message(STATUS "Skipping ebpf verifier")

# Catch2
add_subdirectory(third_party/Catch2)
if(NOT DEFINED Catch2_INCLUDE)
message(STATUS "Adding Catch2 by subdirectory")
add_subdirectory(third_party/Catch2)
endif()
endif()

# spdlog
add_subdirectory(third_party/spdlog)

if(NOT DEFINED SPDLOG_ACTIVE_LEVEL)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_definitions(SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE)
Expand All @@ -141,8 +148,6 @@ if(NOT DEFINED SPDLOG_ACTIVE_LEVEL)
endif()
endif()



set(SPDLOG_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/spdlog/include)

# argparse
Expand All @@ -155,52 +160,55 @@ add_subdirectory(attach)

add_subdirectory(runtime)


# add to single archive if option is enabled
if (${BPFTIME_BUILD_STATIC_LIB})
set(UBPF_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/vm/ubpf-vm/ubpf)
message(STATUS " Adding libraries to single static archive file")
bpftime_add_static_lib_component_command(bpftime_vm)
if(${BPFTIME_LLVM_JIT})
bpftime_add_static_lib_component_command(bpftime_llvm_vm)
else()
bpftime_add_static_lib_component_command(bpftime_ubpf_vm)
bpftime_add_libs_component_command(${UBPF_BUILD_DIR}/lib/libubpf.a)
endif()
bpftime_add_libs_component_command(${FRIDA_GUM_INSTALL_DIR}/libfrida-gum.a)
bpftime_add_static_lib_component_command(bpftime_frida_uprobe_attach_impl)
if(${BPFTIME_BUILD_WITH_LIBBPF})
bpftime_add_libs_component_command(${CMAKE_CURRENT_BUILD_DIR}/libbpf/libbpf/libbpf.a)
bpftime_add_static_lib_component_command(bpftime_syscall_trace_attach_impl)
endif()
bpftime_add_static_lib_component_command(runtime)
bpftime_add_static_lib_component_command(spdlog)
add_custom_command(OUTPUT "libbpftime.a"
if(${BPFTIME_BUILD_STATIC_LIB})
set(UBPF_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/vm/ubpf-vm/ubpf)
message(STATUS " Adding libraries to single static archive file")
bpftime_add_static_lib_component_command(bpftime_vm)

if(${BPFTIME_LLVM_JIT})
bpftime_add_static_lib_component_command(bpftime_llvm_vm)
else()
bpftime_add_static_lib_component_command(bpftime_ubpf_vm)
bpftime_add_libs_component_command(${UBPF_BUILD_DIR}/lib/libubpf.a)
endif()

bpftime_add_libs_component_command(${FRIDA_GUM_INSTALL_DIR}/libfrida-gum.a)
bpftime_add_static_lib_component_command(bpftime_frida_uprobe_attach_impl)

if(${BPFTIME_BUILD_WITH_LIBBPF})
bpftime_add_libs_component_command(${CMAKE_CURRENT_BUILD_DIR}/libbpf/libbpf/libbpf.a)
bpftime_add_static_lib_component_command(bpftime_syscall_trace_attach_impl)
endif()

bpftime_add_static_lib_component_command(runtime)
bpftime_add_static_lib_component_command(spdlog)
add_custom_command(OUTPUT "libbpftime.a"
${BPFTIME_STATIC_LIB_AR_CMDS}
${BPFTIME_STATIC_LLVM_LIB_AR_CMDS}
COMMAND ${CMAKE_AR} -qcs libbpftime.a objs/*/*.o
COMMAND ${CMAKE_COMMAND} -E remove_directory objs
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${BPFTIME_STATIC_LIB_DEPS}
)
add_custom_target(bpftime_static_target ALL DEPENDS "libbpftime.a")
add_library(bpftime_static STATIC IMPORTED GLOBAL)
add_dependencies(bpftime_static bpftime_static_target)

set_target_properties(bpftime_static
PROPERTIES
IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/libbpftime.a"
)
)
add_custom_target(bpftime_static_target ALL DEPENDS "libbpftime.a")
add_library(bpftime_static STATIC IMPORTED GLOBAL)
add_dependencies(bpftime_static bpftime_static_target)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbpftime.a
DESTINATION ~/.bpftime
)
set_target_properties(bpftime_static
PROPERTIES
IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/libbpftime.a"
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbpftime.a
DESTINATION ~/.bpftime
)
endif()

if (${BUILD_BPFTIME_DAEMON} AND ${BPFTIME_BUILD_WITH_LIBBPF})
if(${BUILD_BPFTIME_DAEMON} AND ${BPFTIME_BUILD_WITH_LIBBPF})
add_subdirectory(daemon)
endif()

add_subdirectory(tools)

if(${BUILD_ATTACH_IMPL_EXAMPLE})
Expand All @@ -209,16 +217,16 @@ endif()

# benchmark that requires bpftime libraries
if(${BPFTIME_BUILD_WITH_LIBBPF})
# Currently benchmark is using libbpf
add_subdirectory(benchmark)
# Currently benchmark is using libbpf
add_subdirectory(benchmark)
endif()


set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")

set(DEST_DIR "$ENV{HOME}/.bpftime")

if(${BPFTIME_BUILD_WITH_LIBBPF})
install(TARGETS bpftime-agent bpftime_text_segment_transformer bpftime-syscall-server CONFIGURATIONS Release Debug RelWithDebInfo DESTINATION ${DEST_DIR})
install(TARGETS bpftime-agent bpftime_text_segment_transformer bpftime-syscall-server CONFIGURATIONS Release Debug RelWithDebInfo DESTINATION ${DEST_DIR})
else()
install(TARGETS bpftime-agent bpftime-syscall-server CONFIGURATIONS Release Debug RelWithDebInfo DESTINATION ${DEST_DIR})
install(TARGETS bpftime-agent bpftime-syscall-server CONFIGURATIONS Release Debug RelWithDebInfo DESTINATION ${DEST_DIR})
endif()
3 changes: 2 additions & 1 deletion attach/frida_uprobe_attach_impl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ set(TEST_SOURCES
)
add_executable(bpftime_frida_uprobe_attach_tests ${TEST_SOURCES})

if(${ENABLE_EBPF_VERIFIER})
if(${ENABLE_EBPF_VERIFIER} AND NOT TARGET Catch2)
message(STATUS "Adding Catch2 by FetchContent for frida_uprobe_attach_impl")
Include(FetchContent)
FetchContent_Declare(
Catch2
Expand Down
3 changes: 2 additions & 1 deletion attach/syscall_trace_attach_impl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ set(TEST_SOURCES
)
add_executable(bpftime_syscall_trace_attach_tests ${TEST_SOURCES})

if(${ENABLE_EBPF_VERIFIER})
if(${ENABLE_EBPF_VERIFIER} AND NOT TARGET Catch2)
message(STATUS "Adding Catch2 by FetchContent at syscall_trace_attach_impl")
Include(FetchContent)
FetchContent_Declare(
Catch2
Expand Down
21 changes: 12 additions & 9 deletions bpftime-verifier/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ set(TEST_SOURCES
test/non_kernel_helper.cpp
)

Include(FetchContent)

FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.0.1
)

FetchContent_MakeAvailable(Catch2)
if(NOT TARGET Catch2)
message(STATUS "Adding Catch2 by FetchContent at bpftime-verifier")
Include(FetchContent)

FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.0.1
)

FetchContent_MakeAvailable(Catch2)
endif()

add_executable(bpftime_verifier_tests ${TEST_SOURCES})
add_dependencies(bpftime_verifier_tests bpftime-verifier)
Expand Down
4 changes: 3 additions & 1 deletion daemon/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
if(${ENABLE_EBPF_VERIFIER})
if(${ENABLE_EBPF_VERIFIER} AND NOT TARGET Catch2)
message(STATUS "Adding Catch2 by FetchContent at bpftime-daemon")
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0
)
FetchContent_MakeAvailable(Catch2)

# if not enable verifier, we will use the catch2 from submodule
endif()

Expand Down
3 changes: 2 additions & 1 deletion runtime/unit-test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if(${ENABLE_EBPF_VERIFIER})
if(${ENABLE_EBPF_VERIFIER} AND NOT TARGET Catch2)
message(STATUS "Adding Catch2 by FetchContent from runtime/unit-test")
Include(FetchContent)
FetchContent_Declare(
Catch2
Expand Down
2 changes: 1 addition & 1 deletion vm/llvm-jit

0 comments on commit 2b26ee4

Please sign in to comment.