Commit 71fc3d5c authored by Brenden Blanco's avatar Brenden Blanco

move api and create dependent option

Move the C++ api files under a new subdirectory.
Use CMAKE_DEPENDENT_OPTION to enforce sdt->cpp_api relationship.

Since linking .a into a .so can cause global symbols to be dropped, add
a helper file to force exported symbols to be retained (link_all.cc).
This problem doesn't exist for building the static cpp examples.
Signed-off-by: default avatarBrenden Blanco <bblanco@gmail.com>
parent 1614ce77
......@@ -11,6 +11,7 @@ enable_testing()
include(cmake/GetGitRevisionDescription.cmake)
include(cmake/version.cmake)
include(CMakeDependentOption)
include(GNUInstallDirs)
include(CheckCXXCompilerFlag)
include(cmake/FindCompilerFlag.cmake)
......
......@@ -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)
......
......@@ -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
......
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)
// 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
}
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment