Skip to content

Commit

Permalink
fixup! cmake: Add systemtap-sdt optional package support
Browse files Browse the repository at this point in the history
Rework in a target-focused way.
  • Loading branch information
hebasto committed Apr 30, 2024
1 parent 6640654 commit f3c2fea
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 39 deletions.
4 changes: 0 additions & 4 deletions cmake/bitcoin-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
/* Copyright year */
#define COPYRIGHT_YEAR @COPYRIGHT_YEAR@

/* Define to 1 to enable tracepoints for Userspace, Statically Defined Tracing
*/
#cmakedefine ENABLE_TRACING 1

/* Define to 1 if you have the declaration of `fork', and to 0 if you don't.
*/
#cmakedefine01 HAVE_DECL_FORK
Expand Down
64 changes: 64 additions & 0 deletions cmake/module/FindUSDT.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright (c) 2024-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

#[=======================================================================[
FindUSDT
--------
Finds the Userspace, Statically Defined Tracing header(s).
Imported Targets
^^^^^^^^^^^^^^^^
This module provides imported target ``USDT::headers``, if
USDT has been found.
Result Variables
^^^^^^^^^^^^^^^^
This module defines the following variables:
``USDT_FOUND``
"True" if USDT found.
#]=======================================================================]

find_path(USDT_INCLUDE_DIR
NAMES sys/sdt.h
)
mark_as_advanced(USDT_INCLUDE_DIR)

if(USDT_INCLUDE_DIR)
include(CMakePushCheckState)
cmake_push_check_state(RESET)

include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${USDT_INCLUDE_DIR})
check_cxx_source_compiles("
#include <sys/sdt.h>
int main()
{
DTRACE_PROBE(context, event);
int a, b, c, d, e, f, g;
DTRACE_PROBE7(context, event, a, b, c, d, e, f, g);
}
" HAVE_USDT_H
)

cmake_pop_check_state()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(USDT
REQUIRED_VARS USDT_INCLUDE_DIR HAVE_USDT_H
)

if(USDT_FOUND AND NOT TARGET USDT::headers)
add_library(USDT::headers INTERFACE IMPORTED)
set_target_properties(USDT::headers PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${USDT_INCLUDE_DIR}"
INTERFACE_COMPILE_DEFINITIONS ENABLE_TRACING
)
endif()
33 changes: 2 additions & 31 deletions cmake/optional.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,8 @@ if(CCACHE)
endif()

if(WITH_USDT)
find_path(SystemTap_INCLUDE_DIR
NAMES sys/sdt.h
)
mark_as_advanced(SystemTap_INCLUDE_DIR)

if(SystemTap_INCLUDE_DIR)
include(CMakePushCheckState)
cmake_push_check_state(RESET)

include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${SystemTap_INCLUDE_DIR})
check_cxx_source_compiles("
#include <sys/sdt.h>
int main()
{
DTRACE_PROBE(context, event);
int a, b, c, d, e, f, g;
DTRACE_PROBE7(context, event, a, b, c, d, e, f, g);
}
" HAVE_USDT_H
)

cmake_pop_check_state()
endif()

if(HAVE_USDT_H)
target_include_directories(core_interface INTERFACE
${SystemTap_INCLUDE_DIR}
)
set(ENABLE_TRACING TRUE)
find_package(USDT MODULE)
if(USDT_FOUND)
set(WITH_USDT ON)
elseif(WITH_USDT STREQUAL "AUTO")
set(WITH_USDT OFF)
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ target_link_libraries(bitcoin_common
secp256k1
Boost::headers
$<TARGET_NAME_IF_EXISTS:libevent::libevent>
$<TARGET_NAME_IF_EXISTS:USDT::headers>
)


Expand Down Expand Up @@ -263,6 +264,7 @@ target_link_libraries(bitcoin_node
$<TARGET_NAME_IF_EXISTS:NATPMP::NATPMP>
$<TARGET_NAME_IF_EXISTS:MiniUPnPc::MiniUPnPc>
$<TARGET_NAME_IF_EXISTS:bitcoin_zmq>
$<TARGET_NAME_IF_EXISTS:USDT::headers>
)


Expand Down
4 changes: 0 additions & 4 deletions src/util/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
#ifndef BITCOIN_UTIL_TRACE_H
#define BITCOIN_UTIL_TRACE_H

#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h>
#endif

#ifdef ENABLE_TRACING

#include <sys/sdt.h>
Expand Down
1 change: 1 addition & 0 deletions src/wallet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ target_link_libraries(bitcoin_wallet
bitcoin_common
univalue
Boost::headers
$<TARGET_NAME_IF_EXISTS:USDT::headers>
)

if(NOT USE_SQLITE AND NOT USE_BDB)
Expand Down

0 comments on commit f3c2fea

Please sign in to comment.