diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | examples/cpp/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/cc/CMakeLists.txt | 16 | ||||
-rw-r--r-- | src/cc/api/BPF.cc (renamed from src/cc/BPF.cc) | 0 | ||||
-rw-r--r-- | src/cc/api/BPF.h (renamed from src/cc/BPF.h) | 0 | ||||
-rw-r--r-- | src/cc/api/BPFTable.cc (renamed from src/cc/BPFTable.cc) | 0 | ||||
-rw-r--r-- | src/cc/api/BPFTable.h (renamed from src/cc/BPFTable.h) | 0 | ||||
-rw-r--r-- | src/cc/api/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/cc/link_all.cc | 21 | ||||
-rw-r--r-- | tests/cc/CMakeLists.txt | 1 |
10 files changed, 38 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b23261cc..f2bdd554 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ enable_testing() include(cmake/GetGitRevisionDescription.cmake) include(cmake/version.cmake) +include(CMakeDependentOption) include(GNUInstallDirs) include(CheckCXXCompilerFlag) include(cmake/FindCompilerFlag.cmake) diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index 49da8296..7d6ccee2 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -2,6 +2,7 @@ # Licensed under the Apache License, Version 2.0 (the "License") include_directories(${CMAKE_SOURCE_DIR}/src/cc) +include_directories(${CMAKE_SOURCE_DIR}/src/cc/api) option(INSTALL_CPP_EXAMPLES "Install C++ examples. Those binaries are statically linked and can take plenty of disk space" OFF) diff --git a/src/cc/CMakeLists.txt b/src/cc/CMakeLists.txt index 799f5481..8d4b7dc2 100644 --- a/src/cc/CMakeLists.txt +++ b/src/cc/CMakeLists.txt @@ -28,18 +28,17 @@ 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_api_sources BPF.cc BPFTable.cc) add_library(bcc-shared SHARED + link_all.cc ${bcc_common_sources} ${bcc_table_sources} ${bcc_sym_sources} - ${bcc_util_sources} ${bcc_api_sources}) + ${bcc_util_sources}) set_target_properties(bcc-shared PROPERTIES VERSION ${REVISION_LAST} SOVERSION 0) set_target_properties(bcc-shared PROPERTIES OUTPUT_NAME bcc) add_library(bcc-loader-static STATIC ${bcc_sym_sources} ${bcc_util_sources}) add_library(bcc-static STATIC - ${bcc_common_sources} ${bcc_table_sources} - ${bcc_util_sources} ${bcc_api_sources}) + ${bcc_common_sources} ${bcc_table_sources} ${bcc_util_sources}) set_target_properties(bcc-static PROPERTIES OUTPUT_NAME bcc) include(clang_libs) @@ -50,6 +49,13 @@ 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) +endif() + if(ENABLE_USDT) add_subdirectory(usdt) list(APPEND bcc_common_libs usdt-static) @@ -62,7 +68,7 @@ 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 BPF.h BPFTable.h + libbpf.h perf_reader.h table_desc.h table_storage.h COMPONENT libbcc DESTINATION include/bcc) install(DIRECTORY compat/linux/ COMPONENT libbcc diff --git a/src/cc/BPF.cc b/src/cc/api/BPF.cc index 0a6cb728..0a6cb728 100644 --- a/src/cc/BPF.cc +++ b/src/cc/api/BPF.cc diff --git a/src/cc/BPF.h b/src/cc/api/BPF.h index 4a4c46c2..4a4c46c2 100644 --- a/src/cc/BPF.h +++ b/src/cc/api/BPF.h diff --git a/src/cc/BPFTable.cc b/src/cc/api/BPFTable.cc index 559af4a6..559af4a6 100644 --- a/src/cc/BPFTable.cc +++ b/src/cc/api/BPFTable.cc diff --git a/src/cc/BPFTable.h b/src/cc/api/BPFTable.h index 23336804..23336804 100644 --- a/src/cc/BPFTable.h +++ b/src/cc/api/BPFTable.h diff --git a/src/cc/api/CMakeLists.txt b/src/cc/api/CMakeLists.txt new file mode 100644 index 00000000..4234e20c --- /dev/null +++ b/src/cc/api/CMakeLists.txt @@ -0,0 +1,3 @@ +set(bcc_api_sources BPF.cc BPFTable.cc) +add_library(api-static STATIC ${bcc_api_sources}) +install(FILES BPF.h BPFTable.h COMPONENT libbcc DESTINATION include/bcc) diff --git a/src/cc/link_all.cc b/src/cc/link_all.cc new file mode 100644 index 00000000..11057766 --- /dev/null +++ b/src/cc/link_all.cc @@ -0,0 +1,21 @@ +// Copyright (c) 2017 VMware, Inc. +// Licensed under the Apache License, Version 2.0 (the "License") +#include <cstdlib> + +#include "bcc_usdt.h" + +namespace { + // Take this trick from llvm for forcing exported functions in helper + // libraries to be included in the final .so + struct LinkAll { + LinkAll() { + // getenv never returns -1, but compiler doesn't know! + if (::getenv("bar") != (char *)-1) + return; + + (void)bcc_usdt_new_frompid(-1); + (void)bcc_usdt_new_frompath(nullptr); + (void)bcc_usdt_close(nullptr); + } + } LinkAll; // declare one instance to invoke the constructor +} diff --git a/tests/cc/CMakeLists.txt b/tests/cc/CMakeLists.txt index be986bfa..373bfcb7 100644 --- a/tests/cc/CMakeLists.txt +++ b/tests/cc/CMakeLists.txt @@ -2,6 +2,7 @@ # Licensed under the Apache License, Version 2.0 (the "License") include_directories(${CMAKE_SOURCE_DIR}/src/cc) +include_directories(${CMAKE_SOURCE_DIR}/src/cc/api) add_executable(test_static test_static.c) target_link_libraries(test_static bcc-static) |