| 1 | #.rst: |
| 2 | # FindLTTngUST |
| 3 | # ------------ |
| 4 | # |
| 5 | # This module finds the `LTTng-UST <http://lttng.org/>`__ library. |
| 6 | # |
| 7 | # Imported target |
| 8 | # ^^^^^^^^^^^^^^^ |
| 9 | # |
| 10 | # This module defines the following :prop_tgt:`IMPORTED` target: |
| 11 | # |
| 12 | # ``LTTng::UST`` |
| 13 | # The LTTng-UST library, if found |
| 14 | # |
| 15 | # Result variables |
| 16 | # ^^^^^^^^^^^^^^^^ |
| 17 | # |
| 18 | # This module sets the following |
| 19 | # |
| 20 | # ``LTTNGUST_FOUND`` |
| 21 | # ``TRUE`` if system has LTTng-UST |
| 22 | # ``LTTNGUST_INCLUDE_DIRS`` |
| 23 | # The LTTng-UST include directories |
| 24 | # ``LTTNGUST_LIBRARIES`` |
| 25 | # The libraries needed to use LTTng-UST |
| 26 | # ``LTTNGUST_VERSION_STRING`` |
| 27 | # The LTTng-UST version |
| 28 | # ``LTTNGUST_HAS_TRACEF`` |
| 29 | # ``TRUE`` if the ``tracef()`` API is available in the system's LTTng-UST |
| 30 | # ``LTTNGUST_HAS_TRACELOG`` |
| 31 | # ``TRUE`` if the ``tracelog()`` API is available in the system's LTTng-UST |
| 32 | # |
| 33 | # SPDX-FileCopyrightText: 2016 Kitware, Inc. |
| 34 | # SPDX-FileCopyrightText: 2016 Philippe Proulx <pproulx@efficios.com> |
| 35 | # |
| 36 | # SPDX-License-Identifier: BSD-3-Clause |
| 37 | |
| 38 | find_path(LTTNGUST_INCLUDE_DIRS NAMES lttng/tracepoint.h) |
| 39 | # Must also check for the path of generated header files since out-of-tree |
| 40 | # build is a possibility (Yocto). |
| 41 | find_path(LTTNGUST_INCLUDE_DIRS_GENERATED NAMES lttng/ust-config.h) |
| 42 | find_library(LTTNGUST_LIBRARIES NAMES lttng-ust) |
| 43 | |
| 44 | if(LTTNGUST_INCLUDE_DIRS AND LTTNGUST_INCLUDE_DIRS_GENERATED AND LTTNGUST_LIBRARIES) |
| 45 | # find tracef() and tracelog() support |
| 46 | set(LTTNGUST_HAS_TRACEF 0) |
| 47 | set(LTTNGUST_HAS_TRACELOG 0) |
| 48 | |
| 49 | if(EXISTS "${LTTNGUST_INCLUDE_DIRS}/lttng/tracef.h") |
| 50 | set(LTTNGUST_HAS_TRACEF TRUE) |
| 51 | endif() |
| 52 | |
| 53 | if(EXISTS "${LTTNGUST_INCLUDE_DIRS}/lttng/tracelog.h") |
| 54 | set(LTTNGUST_HAS_TRACELOG TRUE) |
| 55 | endif() |
| 56 | |
| 57 | # get version |
| 58 | set(lttngust_version_file "${LTTNGUST_INCLUDE_DIRS_GENERATED}/lttng/ust-version.h") |
| 59 | |
| 60 | if(EXISTS "${lttngust_version_file}") |
| 61 | file(STRINGS "${lttngust_version_file}" lttngust_version_major_string |
| 62 | REGEX "^[\t ]*#define[\t ]+LTTNG_UST_MAJOR_VERSION[\t ]+[0-9]+[\t ]*$") |
| 63 | file(STRINGS "${lttngust_version_file}" lttngust_version_minor_string |
| 64 | REGEX "^[\t ]*#define[\t ]+LTTNG_UST_MINOR_VERSION[\t ]+[0-9]+[\t ]*$") |
| 65 | file(STRINGS "${lttngust_version_file}" lttngust_version_patch_string |
| 66 | REGEX "^[\t ]*#define[\t ]+LTTNG_UST_PATCHLEVEL_VERSION[\t ]+[0-9]+[\t ]*$") |
| 67 | string(REGEX REPLACE ".*([0-9]+).*" "\\1" |
| 68 | lttngust_v_major "${lttngust_version_major_string}") |
| 69 | string(REGEX REPLACE ".*([0-9]+).*" "\\1" |
| 70 | lttngust_v_minor "${lttngust_version_minor_string}") |
| 71 | string(REGEX REPLACE ".*([0-9]+).*" "\\1" |
| 72 | lttngust_v_patch "${lttngust_version_patch_string}") |
| 73 | set(LTTNGUST_VERSION_STRING |
| 74 | "${lttngust_v_major}.${lttngust_v_minor}.${lttngust_v_patch}") |
| 75 | unset(lttngust_version_major_string) |
| 76 | unset(lttngust_version_minor_string) |
| 77 | unset(lttngust_version_patch_string) |
| 78 | unset(lttngust_v_major) |
| 79 | unset(lttngust_v_minor) |
| 80 | unset(lttngust_v_patch) |
| 81 | else() |
| 82 | message(FATAL_ERROR "Missing version header") |
| 83 | endif() |
| 84 | |
| 85 | unset(lttngust_version_file) |
| 86 | |
| 87 | if(NOT TARGET LTTng::UST) |
| 88 | add_library(LTTng::UST UNKNOWN IMPORTED) |
| 89 | set_target_properties(LTTng::UST PROPERTIES |
| 90 | INTERFACE_INCLUDE_DIRECTORIES "${LTTNGUST_INCLUDE_DIRS};${LTTNGUST_INCLUDE_DIRS_GENERATED}" |
| 91 | INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS} |
| 92 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" |
| 93 | IMPORTED_LOCATION "${LTTNGUST_LIBRARIES}") |
| 94 | endif() |
| 95 | |
| 96 | # add libdl to required libraries |
| 97 | set(LTTNGUST_LIBRARIES ${LTTNGUST_LIBRARIES} ${CMAKE_DL_LIBS}) |
| 98 | endif() |
| 99 | |
| 100 | # handle the QUIETLY and REQUIRED arguments and set LTTNGUST_FOUND to |
| 101 | # TRUE if all listed variables are TRUE |
| 102 | include(FindPackageHandleStandardArgs) |
| 103 | find_package_handle_standard_args(LTTngUST FOUND_VAR LTTNGUST_FOUND |
| 104 | REQUIRED_VARS LTTNGUST_LIBRARIES |
| 105 | LTTNGUST_INCLUDE_DIRS |
| 106 | VERSION_VAR LTTNGUST_VERSION_STRING) |
| 107 | mark_as_advanced(LTTNGUST_LIBRARIES LTTNGUST_INCLUDE_DIRS) |