18d28bdebc6652074e6a5518e248b6f908a581b4
[lttng-ust.git] / doc / examples / cmake-multiple-shared-libraries / cmake / FindLTTngUST.cmake
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 #=============================================================================
34 # Copyright 2016 Kitware, Inc.
35 # Copyright 2016 Philippe Proulx <pproulx@efficios.com>
36 #
37 # Distributed under the OSI-approved BSD License (the "License");
38 # see accompanying file Copyright.txt for details.
39 #
40 # This software is distributed WITHOUT ANY WARRANTY; without even the
41 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
42 # See the License for more information.
43 #=============================================================================
44 # (To distribute this file outside of CMake, substitute the full
45 # License text for the above reference.)
46
47 find_path(LTTNGUST_INCLUDE_DIRS NAMES lttng/tracepoint.h)
48 find_library(LTTNGUST_LIBRARIES NAMES lttng-ust)
49
50 if(LTTNGUST_INCLUDE_DIRS AND LTTNGUST_LIBRARIES)
51 # find tracef() and tracelog() support
52 set(LTTNGUST_HAS_TRACEF 0)
53 set(LTTNGUST_HAS_TRACELOG 0)
54
55 if(EXISTS "${LTTNGUST_INCLUDE_DIRS}/lttng/tracef.h")
56 set(LTTNGUST_HAS_TRACEF TRUE)
57 endif()
58
59 if(EXISTS "${LTTNGUST_INCLUDE_DIRS}/lttng/tracelog.h")
60 set(LTTNGUST_HAS_TRACELOG TRUE)
61 endif()
62
63 # get version
64 set(lttngust_version_file "${LTTNGUST_INCLUDE_DIRS}/lttng/ust-version.h")
65
66 if(EXISTS "${lttngust_version_file}")
67 file(STRINGS "${lttngust_version_file}" lttngust_version_major_string
68 REGEX "^[\t ]*#define[\t ]+LTTNG_UST_MAJOR_VERSION[\t ]+[0-9]+[\t ]*$")
69 file(STRINGS "${lttngust_version_file}" lttngust_version_minor_string
70 REGEX "^[\t ]*#define[\t ]+LTTNG_UST_MINOR_VERSION[\t ]+[0-9]+[\t ]*$")
71 file(STRINGS "${lttngust_version_file}" lttngust_version_patch_string
72 REGEX "^[\t ]*#define[\t ]+LTTNG_UST_PATCHLEVEL_VERSION[\t ]+[0-9]+[\t ]*$")
73 string(REGEX REPLACE ".*([0-9]+).*" "\\1"
74 lttngust_v_major "${lttngust_version_major_string}")
75 string(REGEX REPLACE ".*([0-9]+).*" "\\1"
76 lttngust_v_minor "${lttngust_version_minor_string}")
77 string(REGEX REPLACE ".*([0-9]+).*" "\\1"
78 lttngust_v_patch "${lttngust_version_patch_string}")
79 set(LTTNGUST_VERSION_STRING
80 "${lttngust_v_major}.${lttngust_v_minor}.${lttngust_v_patch}")
81 unset(lttngust_version_major_string)
82 unset(lttngust_version_minor_string)
83 unset(lttngust_version_patch_string)
84 unset(lttngust_v_major)
85 unset(lttngust_v_minor)
86 unset(lttngust_v_patch)
87 endif()
88
89 unset(lttngust_version_file)
90
91 if(NOT TARGET LTTng::UST)
92 add_library(LTTng::UST UNKNOWN IMPORTED)
93 set_target_properties(LTTng::UST PROPERTIES
94 INTERFACE_INCLUDE_DIRECTORIES "${LTTNGUST_INCLUDE_DIRS}"
95 INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS}
96 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
97 IMPORTED_LOCATION "${LTTNGUST_LIBRARIES}")
98 endif()
99
100 # add libdl to required libraries
101 set(LTTNGUST_LIBRARIES ${LTTNGUST_LIBRARIES} ${CMAKE_DL_LIBS})
102 endif()
103
104 # handle the QUIETLY and REQUIRED arguments and set LTTNGUST_FOUND to
105 # TRUE if all listed variables are TRUE
106 include(FindPackageHandleStandardArgs)
107 find_package_handle_standard_args(LTTngUST FOUND_VAR LTTNGUST_FOUND
108 REQUIRED_VARS LTTNGUST_LIBRARIES
109 LTTNGUST_INCLUDE_DIRS
110 VERSION_VAR LTTNGUST_VERSION_STRING)
111 mark_as_advanced(LTTNGUST_LIBRARIES LTTNGUST_INCLUDE_DIRS)
This page took 0.032228 seconds and 3 git commands to generate.