a70a418f49ba868229f4c2465dcb5ab7e4232f75
[platform/upstream/cmake.git] / Modules / FindLTTngUST.cmake
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
3
4 #[=======================================================================[.rst:
5 FindLTTngUST
6 ------------
7
8 .. versionadded:: 3.6
9
10 Find
11 `Linux Trace Toolkit Next Generation (LTTng-UST) <http://lttng.org/>`__ library.
12
13 Imported target
14 ^^^^^^^^^^^^^^^
15
16 This module defines the following :prop_tgt:`IMPORTED` target:
17
18 ``LTTng::UST``
19   The LTTng-UST library, if found
20
21 Result variables
22 ^^^^^^^^^^^^^^^^
23
24 This module sets the following
25
26 ``LTTNGUST_FOUND``
27   ``TRUE`` if system has LTTng-UST
28 ``LTTNGUST_INCLUDE_DIRS``
29   The LTTng-UST include directories
30 ``LTTNGUST_LIBRARIES``
31   The libraries needed to use LTTng-UST
32 ``LTTNGUST_VERSION_STRING``
33   The LTTng-UST version
34 ``LTTNGUST_HAS_TRACEF``
35   ``TRUE`` if the ``tracef()`` API is available in the system's LTTng-UST
36 ``LTTNGUST_HAS_TRACELOG``
37   ``TRUE`` if the ``tracelog()`` API is available in the system's LTTng-UST
38 #]=======================================================================]
39
40 find_path(LTTNGUST_INCLUDE_DIRS NAMES lttng/tracepoint.h)
41 find_library(LTTNGUST_LIBRARIES NAMES lttng-ust)
42
43 if(LTTNGUST_INCLUDE_DIRS AND LTTNGUST_LIBRARIES)
44   # find tracef() and tracelog() support
45   set(LTTNGUST_HAS_TRACEF 0)
46   set(LTTNGUST_HAS_TRACELOG 0)
47
48   if(EXISTS "${LTTNGUST_INCLUDE_DIRS}/lttng/tracef.h")
49     set(LTTNGUST_HAS_TRACEF TRUE)
50   endif()
51
52   if(EXISTS "${LTTNGUST_INCLUDE_DIRS}/lttng/tracelog.h")
53     set(LTTNGUST_HAS_TRACELOG TRUE)
54   endif()
55
56   # get version
57   set(lttngust_version_file "${LTTNGUST_INCLUDE_DIRS}/lttng/ust-version.h")
58
59   if(EXISTS "${lttngust_version_file}")
60     file(STRINGS "${lttngust_version_file}" lttngust_version_major_string
61          REGEX "^[\t ]*#define[\t ]+LTTNG_UST_MAJOR_VERSION[\t ]+[0-9]+[\t ]*$")
62     file(STRINGS "${lttngust_version_file}" lttngust_version_minor_string
63          REGEX "^[\t ]*#define[\t ]+LTTNG_UST_MINOR_VERSION[\t ]+[0-9]+[\t ]*$")
64     file(STRINGS "${lttngust_version_file}" lttngust_version_patch_string
65          REGEX "^[\t ]*#define[\t ]+LTTNG_UST_PATCHLEVEL_VERSION[\t ]+[0-9]+[\t ]*$")
66     string(REGEX REPLACE ".*[\t ]+([0-9]+).*" "\\1"
67            lttngust_v_major "${lttngust_version_major_string}")
68     string(REGEX REPLACE ".*[\t ]+([0-9]+).*" "\\1"
69            lttngust_v_minor "${lttngust_version_minor_string}")
70     string(REGEX REPLACE ".*[\t ]+([0-9]+).*" "\\1"
71            lttngust_v_patch "${lttngust_version_patch_string}")
72     set(LTTNGUST_VERSION_STRING
73         "${lttngust_v_major}.${lttngust_v_minor}.${lttngust_v_patch}")
74     unset(lttngust_version_major_string)
75     unset(lttngust_version_minor_string)
76     unset(lttngust_version_patch_string)
77     unset(lttngust_v_major)
78     unset(lttngust_v_minor)
79     unset(lttngust_v_patch)
80   endif()
81
82   unset(lttngust_version_file)
83
84   if(NOT TARGET LTTng::UST)
85     add_library(LTTng::UST UNKNOWN IMPORTED)
86     set_target_properties(LTTng::UST PROPERTIES
87       INTERFACE_INCLUDE_DIRECTORIES "${LTTNGUST_INCLUDE_DIRS}"
88       INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS}
89       IMPORTED_LINK_INTERFACE_LANGUAGES "C"
90       IMPORTED_LOCATION "${LTTNGUST_LIBRARIES}")
91   endif()
92
93   # add libdl to required libraries
94   set(LTTNGUST_LIBRARIES ${LTTNGUST_LIBRARIES} ${CMAKE_DL_LIBS})
95 endif()
96
97 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
98 find_package_handle_standard_args(LTTngUST FOUND_VAR LTTNGUST_FOUND
99                                   REQUIRED_VARS LTTNGUST_LIBRARIES
100                                                 LTTNGUST_INCLUDE_DIRS
101                                   VERSION_VAR LTTNGUST_VERSION_STRING)
102 mark_as_advanced(LTTNGUST_LIBRARIES LTTNGUST_INCLUDE_DIRS)