FindLTTngUST.cmake 3.6 KB

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