FindLTTngUST.cmake 3.6 KB

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