Skip to content

Commit c6261b9

Browse files
committed
Merge #162: cmake: Switch from tri-state options to boolean. Stage TWO
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
2 parents 3c26fec + 598eda8 commit c6261b9

9 files changed

+77
-56
lines changed

CMakeLists.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ if(WITH_ZMQ)
108108
endif()
109109
endif()
110110

111-
tristate_option(WITH_USDT
112-
"Enable tracepoints for Userspace, Statically Defined Tracing."
113-
"if sys/sdt.h is found."
114-
AUTO
115-
)
111+
option(WITH_USDT "Enable tracepoints for Userspace, Statically Defined Tracing." OFF)
112+
if(WITH_USDT)
113+
find_package(USDT MODULE REQUIRED)
114+
endif()
115+
116116
cmake_dependent_option(WITH_EXTERNAL_SIGNER "Enable external signer support." ON "NOT WIN32" OFF)
117117
set(ENABLE_EXTERNAL_SIGNER ${WITH_EXTERNAL_SIGNER})
118118

cmake/bitcoin-config.h.in

-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@
3030
/* Copyright year */
3131
#define COPYRIGHT_YEAR @COPYRIGHT_YEAR@
3232

33-
/* Define to 1 to enable tracepoints for Userspace, Statically Defined Tracing
34-
*/
35-
#cmakedefine ENABLE_TRACING 1
36-
3733
/* Define to 1 if you have the declaration of `fork', and to 0 if you don't.
3834
*/
3935
#cmakedefine01 HAVE_DECL_FORK

cmake/module/FindUSDT.cmake

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright (c) 2024-present The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or https://opensource.org/license/mit/.
4+
5+
#[=======================================================================[
6+
FindUSDT
7+
--------
8+
9+
Finds the Userspace, Statically Defined Tracing header(s).
10+
11+
Imported Targets
12+
^^^^^^^^^^^^^^^^
13+
14+
This module provides imported target ``USDT::headers``, if
15+
USDT has been found.
16+
17+
Result Variables
18+
^^^^^^^^^^^^^^^^
19+
20+
This module defines the following variables:
21+
22+
``USDT_FOUND``
23+
"True" if USDT found.
24+
25+
#]=======================================================================]
26+
27+
find_path(USDT_INCLUDE_DIR
28+
NAMES sys/sdt.h
29+
)
30+
mark_as_advanced(USDT_INCLUDE_DIR)
31+
32+
if(USDT_INCLUDE_DIR)
33+
include(CMakePushCheckState)
34+
cmake_push_check_state(RESET)
35+
36+
include(CheckCXXSourceCompiles)
37+
set(CMAKE_REQUIRED_INCLUDES ${USDT_INCLUDE_DIR})
38+
check_cxx_source_compiles("
39+
#include <sys/sdt.h>
40+
41+
int main()
42+
{
43+
DTRACE_PROBE(context, event);
44+
int a, b, c, d, e, f, g;
45+
DTRACE_PROBE7(context, event, a, b, c, d, e, f, g);
46+
}
47+
" HAVE_USDT_H
48+
)
49+
50+
cmake_pop_check_state()
51+
endif()
52+
53+
include(FindPackageHandleStandardArgs)
54+
find_package_handle_standard_args(USDT
55+
REQUIRED_VARS USDT_INCLUDE_DIR HAVE_USDT_H
56+
)
57+
58+
if(USDT_FOUND AND NOT TARGET USDT::headers)
59+
add_library(USDT::headers INTERFACE IMPORTED)
60+
set_target_properties(USDT::headers PROPERTIES
61+
INTERFACE_INCLUDE_DIRECTORIES "${USDT_INCLUDE_DIR}"
62+
INTERFACE_COMPILE_DEFINITIONS ENABLE_TRACING
63+
)
64+
endif()

cmake/optional.cmake

-40
Original file line numberDiff line numberDiff line change
@@ -50,46 +50,6 @@ if(CCACHE)
5050
mark_as_advanced(CCACHE_COMMAND)
5151
endif()
5252

53-
if(WITH_USDT)
54-
find_path(SystemTap_INCLUDE_DIR
55-
NAMES sys/sdt.h
56-
)
57-
mark_as_advanced(SystemTap_INCLUDE_DIR)
58-
59-
if(SystemTap_INCLUDE_DIR)
60-
include(CMakePushCheckState)
61-
cmake_push_check_state(RESET)
62-
63-
include(CheckCXXSourceCompiles)
64-
set(CMAKE_REQUIRED_INCLUDES ${SystemTap_INCLUDE_DIR})
65-
check_cxx_source_compiles("
66-
#include <sys/sdt.h>
67-
68-
int main()
69-
{
70-
DTRACE_PROBE(context, event);
71-
int a, b, c, d, e, f, g;
72-
DTRACE_PROBE7(context, event, a, b, c, d, e, f, g);
73-
}
74-
" HAVE_USDT_H
75-
)
76-
77-
cmake_pop_check_state()
78-
endif()
79-
80-
if(HAVE_USDT_H)
81-
target_include_directories(core_interface INTERFACE
82-
${SystemTap_INCLUDE_DIR}
83-
)
84-
set(ENABLE_TRACING TRUE)
85-
set(WITH_USDT ON)
86-
elseif(WITH_USDT STREQUAL "AUTO")
87-
set(WITH_USDT OFF)
88-
else()
89-
message(FATAL_ERROR "sys/sdt.h requested, but not found.")
90-
endif()
91-
endif()
92-
9353
if(ENABLE_WALLET)
9454
if(WITH_SQLITE)
9555
if(VCPKG_TARGET_TRIPLET)

depends/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ $(host_prefix)/toolchain.cmake : toolchain.cmake.in $(host_prefix)/.stamp_$(fina
291291
-e 's|@no_sqlite@|$(NO_SQLITE)|' \
292292
-e 's|@no_upnp@|$(NO_UPNP)|' \
293293
-e 's|@no_natpmp@|$(NO_NATPMP)|' \
294-
-e 's|@no_usdt@|$(NO_USDT)|' \
294+
-e 's|@usdt_packages@|$(usdt_packages_)|' \
295295
-e 's|@no_harden@|$(NO_HARDEN)|' \
296296
-e 's|@multiprocess@|$(MULTIPROCESS)|' \
297297
$< > $@

depends/toolchain.cmake.in

+4-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ else()
158158
set(WITH_NATPMP ON CACHE BOOL "")
159159
endif()
160160

161-
if(NOT WITH_USDT AND "@no_usdt@" STREQUAL "1")
162-
set(WITH_USDT OFF CACHE STRING "Enable tracepoints for Userspace, Statically Defined Tracing.")
161+
if("@usdt_packages@" STREQUAL "")
162+
set(WITH_USDT OFF CACHE BOOL "")
163+
else()
164+
set(WITH_USDT ON CACHE BOOL "")
163165
endif()
164166

165167
if("@no_harden@")

src/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ target_link_libraries(bitcoin_common
123123
secp256k1
124124
Boost::headers
125125
$<TARGET_NAME_IF_EXISTS:libevent::libevent>
126+
$<TARGET_NAME_IF_EXISTS:USDT::headers>
126127
)
127128

128129

@@ -258,6 +259,7 @@ target_link_libraries(bitcoin_node
258259
$<TARGET_NAME_IF_EXISTS:NATPMP::NATPMP>
259260
$<TARGET_NAME_IF_EXISTS:MiniUPnPc::MiniUPnPc>
260261
$<TARGET_NAME_IF_EXISTS:bitcoin_zmq>
262+
$<TARGET_NAME_IF_EXISTS:USDT::headers>
261263
)
262264

263265

src/util/trace.h

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
#ifndef BITCOIN_UTIL_TRACE_H
66
#define BITCOIN_UTIL_TRACE_H
77

8-
#if defined(HAVE_CONFIG_H)
9-
#include <config/bitcoin-config.h>
10-
#endif
11-
128
#ifdef ENABLE_TRACING
139

1410
#include <sys/sdt.h>

src/wallet/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ target_link_libraries(bitcoin_wallet
3838
bitcoin_common
3939
univalue
4040
Boost::headers
41+
$<TARGET_NAME_IF_EXISTS:USDT::headers>
4142
)
4243

4344
if(NOT USE_SQLITE AND NOT USE_BDB)

0 commit comments

Comments
 (0)