diff --git a/CMakeLists.txt b/CMakeLists.txt index e98e93f5..364e06d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ 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() @@ -53,6 +54,7 @@ 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 @@ -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) @@ -141,8 +148,6 @@ if(NOT DEFINED SPDLOG_ACTIVE_LEVEL) endif() endif() - - set(SPDLOG_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/spdlog/include) # argparse @@ -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}) @@ -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$<$: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() diff --git a/attach/frida_uprobe_attach_impl/CMakeLists.txt b/attach/frida_uprobe_attach_impl/CMakeLists.txt index 2d9dba8e..dba219c1 100644 --- a/attach/frida_uprobe_attach_impl/CMakeLists.txt +++ b/attach/frida_uprobe_attach_impl/CMakeLists.txt @@ -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 diff --git a/attach/syscall_trace_attach_impl/CMakeLists.txt b/attach/syscall_trace_attach_impl/CMakeLists.txt index 9c11d4bb..e94da71e 100644 --- a/attach/syscall_trace_attach_impl/CMakeLists.txt +++ b/attach/syscall_trace_attach_impl/CMakeLists.txt @@ -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 diff --git a/bpftime-verifier/CMakeLists.txt b/bpftime-verifier/CMakeLists.txt index 6e5e0c7a..2b93d5d4 100644 --- a/bpftime-verifier/CMakeLists.txt +++ b/bpftime-verifier/CMakeLists.txt @@ -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) diff --git a/daemon/test/CMakeLists.txt b/daemon/test/CMakeLists.txt index 8989e4fd..cf6bfcea 100644 --- a/daemon/test/CMakeLists.txt +++ b/daemon/test/CMakeLists.txt @@ -1,4 +1,5 @@ -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 @@ -6,6 +7,7 @@ if(${ENABLE_EBPF_VERIFIER}) GIT_TAG v3.4.0 ) FetchContent_MakeAvailable(Catch2) + # if not enable verifier, we will use the catch2 from submodule endif() diff --git a/runtime/unit-test/CMakeLists.txt b/runtime/unit-test/CMakeLists.txt index 2e0d47d6..95560844 100644 --- a/runtime/unit-test/CMakeLists.txt +++ b/runtime/unit-test/CMakeLists.txt @@ -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 diff --git a/vm/llvm-jit b/vm/llvm-jit index 374c2fd5..1acd8e52 160000 --- a/vm/llvm-jit +++ b/vm/llvm-jit @@ -1 +1 @@ -Subproject commit 374c2fd5d2083c0ffdc6987ad45d6750e7eba20c +Subproject commit 1acd8e52a47cfd6532ac7bed5361d6cd795f9846