Skip to content

Commit

Permalink
Add bcc_version.h to access LIBBCC_VERSION from C/C++ (iovisor#2856)
Browse files Browse the repository at this point in the history
 add bcc/bcc_version.h to install
  • Loading branch information
gfx committed Apr 19, 2020
1 parent c1d3a65 commit 6d61622
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) Facebook, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")

include_directories(${CMAKE_BINARY_DIR}/src/cc)
include_directories(${CMAKE_SOURCE_DIR}/src/cc)
include_directories(${CMAKE_SOURCE_DIR}/src/cc/api)
include_directories(${CMAKE_SOURCE_DIR}/src/cc/libbpf/include/uapi)
Expand Down
3 changes: 3 additions & 0 deletions examples/cpp/HelloWorld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <iostream>
#include <string>

#include "bcc_version.h"
#include "BPF.h"

const std::string BPF_PROGRAM = R"(
Expand Down Expand Up @@ -35,6 +36,8 @@ int main() {
return 1;
}

std::cout << "Starting HelloWorld with BCC " << LIBBCC_VERSION << std::endl;

while (true) {
if (std::getline(pipe, line)) {
std::cout << line << std::endl;
Expand Down
5 changes: 3 additions & 2 deletions src/cc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ include_directories(${LIBELF_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include/uapi)
add_definitions(${LLVM_DEFINITIONS})
configure_file(libbcc.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libbcc.pc @ONLY)
configure_file(libbcc.pc.in libbcc.pc @ONLY)
configure_file(bcc_version.h.in bcc_version.h @ONLY)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -DBCC_PROG_TAG_DIR='\"${BCC_PROG_TAG_DIR}\"'")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-result")
Expand Down Expand Up @@ -66,7 +67,7 @@ endif()
set(bcc_table_sources table_storage.cc shared_table.cc bpffs_table.cc json_map_decl_visitor.cc)
set(bcc_util_sources common.cc)
set(bcc_sym_sources bcc_syms.cc bcc_elf.c bcc_perf_map.c bcc_proc.c)
set(bcc_common_headers libbpf.h perf_reader.h)
set(bcc_common_headers libbpf.h perf_reader.h "${CMAKE_CURRENT_BINARY_DIR}/bcc_version.h")
set(bcc_table_headers file_desc.h table_desc.h table_storage.h)
set(bcc_api_headers bcc_common.h bpf_module.h bcc_exception.h bcc_syms.h bcc_proc.h bcc_elf.h)

Expand Down
6 changes: 6 additions & 0 deletions src/cc/bcc_version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef LIBBCC_VERSION_H
#define LIBBCC_VERSION_H

#define LIBBCC_VERSION "@REVISION@"

#endif

0 comments on commit 6d61622

Please sign in to comment.