FindUSDT.cmake raw
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 #if defined(__arm__)
40 # define STAP_SDT_ARG_CONSTRAINT g
41 #endif
42
43 // Setting SDT_USE_VARIADIC lets systemtap (sys/sdt.h) know that we want to use
44 // the optional variadic macros to define tracepoints.
45 #define SDT_USE_VARIADIC 1
46 #include <sys/sdt.h>
47
48 int main()
49 {
50 STAP_PROBEV(context, event);
51 int a, b, c, d, e, f, g;
52 STAP_PROBEV(context, event, a, b, c, d, e, f, g);
53 }
54 " HAVE_USDT_H
55 )
56
57 cmake_pop_check_state()
58 endif()
59
60 include(FindPackageHandleStandardArgs)
61 find_package_handle_standard_args(USDT
62 REQUIRED_VARS USDT_INCLUDE_DIR HAVE_USDT_H
63 )
64
65 if(USDT_FOUND AND NOT TARGET USDT::headers)
66 add_library(USDT::headers INTERFACE IMPORTED)
67 set_target_properties(USDT::headers PROPERTIES
68 INTERFACE_INCLUDE_DIRECTORIES "${USDT_INCLUDE_DIR}"
69 )
70 set(ENABLE_TRACING TRUE)
71 endif()
72