Fix: cmake example with configure based oot build
[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 # Must also check for the path of generated header files since out-of-tree
49 # build is a possibility (Yocto).
50 find_path(LTTNGUST_INCLUDE_DIRS_GENERATED NAMES lttng/ust-config.h)
51 find_library(LTTNGUST_LIBRARIES NAMES lttng-ust)
52
53 if(LTTNGUST_INCLUDE_DIRS AND LTTNGUST_INCLUDE_DIRS_GENERATED AND LTTNGUST_LIBRARIES)
54 # find tracef() and tracelog() support
55 set(LTTNGUST_HAS_TRACEF 0)
56 set(LTTNGUST_HAS_TRACELOG 0)
57
58 if(EXISTS "${LTTNGUST_INCLUDE_DIRS}/lttng/tracef.h")
59 set(LTTNGUST_HAS_TRACEF TRUE)
60 endif()
61
62 if(EXISTS "${LTTNGUST_INCLUDE_DIRS}/lttng/tracelog.h")
63 set(LTTNGUST_HAS_TRACELOG TRUE)
64 endif()
65
66 # get version
67 set(lttngust_version_file "${LTTNGUST_INCLUDE_DIRS_GENERATED}/lttng/ust-version.h")
68
69 if(EXISTS "${lttngust_version_file}")
70 file(STRINGS "${lttngust_version_file}" lttngust_version_major_string
71 REGEX "^[\t ]*#define[\t ]+LTTNG_UST_MAJOR_VERSION[\t ]+[0-9]+[\t ]*$")
72 file(STRINGS "${lttngust_version_file}" lttngust_version_minor_string
73 REGEX "^[\t ]*#define[\t ]+LTTNG_UST_MINOR_VERSION[\t ]+[0-9]+[\t ]*$")
74 file(STRINGS "${lttngust_version_file}" lttngust_version_patch_string
75 REGEX "^[\t ]*#define[\t ]+LTTNG_UST_PATCHLEVEL_VERSION[\t ]+[0-9]+[\t ]*$")
76 string(REGEX REPLACE ".*([0-9]+).*" "\\1"
77 lttngust_v_major "${lttngust_version_major_string}")
78 string(REGEX REPLACE ".*([0-9]+).*" "\\1"
79 lttngust_v_minor "${lttngust_version_minor_string}")
80 string(REGEX REPLACE ".*([0-9]+).*" "\\1"
81 lttngust_v_patch "${lttngust_version_patch_string}")
82 set(LTTNGUST_VERSION_STRING
83 "${lttngust_v_major}.${lttngust_v_minor}.${lttngust_v_patch}")
84 unset(lttngust_version_major_string)
85 unset(lttngust_version_minor_string)
86 unset(lttngust_version_patch_string)
87 unset(lttngust_v_major)
88 unset(lttngust_v_minor)
89 unset(lttngust_v_patch)
90 else()
91 message(FATAL_ERROR "Missing version header")
92 endif()
93
94 unset(lttngust_version_file)
95
96 if(NOT TARGET LTTng::UST)
97 add_library(LTTng::UST UNKNOWN IMPORTED)
98 set_target_properties(LTTng::UST PROPERTIES
99 INTERFACE_INCLUDE_DIRECTORIES "${LTTNGUST_INCLUDE_DIRS};${LTTNGUST_INCLUDE_DIRS_GENERATED}"
100 INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS}
101 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
102 IMPORTED_LOCATION "${LTTNGUST_LIBRARIES}")
103 endif()
104
105 # add libdl to required libraries
106 set(LTTNGUST_LIBRARIES ${LTTNGUST_LIBRARIES} ${CMAKE_DL_LIBS})
107 endif()
108
109 # handle the QUIETLY and REQUIRED arguments and set LTTNGUST_FOUND to
110 # TRUE if all listed variables are TRUE
111 include(FindPackageHandleStandardArgs)
112 find_package_handle_standard_args(LTTngUST FOUND_VAR LTTNGUST_FOUND
113 REQUIRED_VARS LTTNGUST_LIBRARIES
114 LTTNGUST_INCLUDE_DIRS
115 VERSION_VAR LTTNGUST_VERSION_STRING)
116 mark_as_advanced(LTTNGUST_LIBRARIES LTTNGUST_INCLUDE_DIRS)
This page took 0.03715 seconds and 4 git commands to generate.