aboutsummaryrefslogtreecommitdiff
path: root/cmake/module/FindUSDT.cmake
blob: 0ba9a58fc10ac9c786814b7063e2f6b2a272eafd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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}"
  )
  set(ENABLE_TRACING TRUE)
endif()