FindLTTngUST.cmake 3.7 KB

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