FindLTTngUST.cmake 3.5 KB

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