Skip to content

Commit

Permalink
Merge #162: cmake: Switch from tri-state options to boolean. Stage TWO
Browse files Browse the repository at this point in the history
598eda8 cmake [KILL 3-STATE]: Switch `WITH_USDT` to boolean w/ default OFF (Hennadii Stepanov)
f3c2fea fixup! cmake: Add `systemtap-sdt` optional package support (Hennadii Stepanov)

Pull request description:

  Same as #161, but USDT-specific with refactoring of the USDT search logic into its own "FindUSDT" module.

  The first commit is a pure refactoring.

Top commit has no ACKs.

Tree-SHA512: 2d67c7e72509fc78eb906a8af93e7525b8125bdeb38a5f45ceda1c0c75f300c74501402c39d8d17de2585b2ed2939de0009a33231d1164438ce929236d4b742a
  • Loading branch information
hebasto committed May 1, 2024
2 parents 3c26fec + 598eda8 commit c6261b9
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 56 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ if(WITH_ZMQ)
endif()
endif()

tristate_option(WITH_USDT
"Enable tracepoints for Userspace, Statically Defined Tracing."
"if sys/sdt.h is found."
AUTO
)
option(WITH_USDT "Enable tracepoints for Userspace, Statically Defined Tracing." OFF)
if(WITH_USDT)
find_package(USDT MODULE REQUIRED)
endif()

cmake_dependent_option(WITH_EXTERNAL_SIGNER "Enable external signer support." ON "NOT WIN32" OFF)
set(ENABLE_EXTERNAL_SIGNER ${WITH_EXTERNAL_SIGNER})

Expand Down
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()
40 changes: 0 additions & 40 deletions cmake/optional.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,46 +50,6 @@ if(CCACHE)
mark_as_advanced(CCACHE_COMMAND)
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)
set(WITH_USDT ON)
elseif(WITH_USDT STREQUAL "AUTO")
set(WITH_USDT OFF)
else()
message(FATAL_ERROR "sys/sdt.h requested, but not found.")
endif()
endif()

if(ENABLE_WALLET)
if(WITH_SQLITE)
if(VCPKG_TARGET_TRIPLET)
Expand Down
2 changes: 1 addition & 1 deletion depends/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ $(host_prefix)/toolchain.cmake : toolchain.cmake.in $(host_prefix)/.stamp_$(fina
-e 's|@no_sqlite@|$(NO_SQLITE)|' \
-e 's|@no_upnp@|$(NO_UPNP)|' \
-e 's|@no_natpmp@|$(NO_NATPMP)|' \
-e 's|@no_usdt@|$(NO_USDT)|' \
-e 's|@usdt_packages@|$(usdt_packages_)|' \
-e 's|@no_harden@|$(NO_HARDEN)|' \
-e 's|@multiprocess@|$(MULTIPROCESS)|' \
$< > $@
Expand Down
6 changes: 4 additions & 2 deletions depends/toolchain.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ else()
set(WITH_NATPMP ON CACHE BOOL "")
endif()

if(NOT WITH_USDT AND "@no_usdt@" STREQUAL "1")
set(WITH_USDT OFF CACHE STRING "Enable tracepoints for Userspace, Statically Defined Tracing.")
if("@usdt_packages@" STREQUAL "")
set(WITH_USDT OFF CACHE BOOL "")
else()
set(WITH_USDT ON CACHE BOOL "")
endif()

if("@no_harden@")
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,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 @@ -258,6 +259,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 c6261b9

Please sign in to comment.