FindLTTngUST.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. # Copyright 2016 Kitware, Inc.
  34. # Copyright 2016 Philippe Proulx <pproulx@efficios.com>
  35. #
  36. # Distributed under the OSI-approved BSD License (the "License");
  37. # see accompanying file Copyright.txt for details.
  38. #
  39. # This software is distributed WITHOUT ANY WARRANTY; without even the
  40. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  41. # See the License for more information.
  42. #=============================================================================
  43. # (To distribute this file outside of CMake, substitute the full
  44. # License text for the above reference.)
  45. find_path(LTTNGUST_INCLUDE_DIRS NAMES lttng/tracepoint.h)
  46. find_library(LTTNGUST_LIBRARIES NAMES lttng-ust)
  47. if(LTTNGUST_INCLUDE_DIRS AND LTTNGUST_LIBRARIES)
  48. # find tracef() and tracelog() support
  49. set(LTTNGUST_HAS_TRACEF 0)
  50. set(LTTNGUST_HAS_TRACELOG 0)
  51. if(EXISTS "${LTTNGUST_INCLUDE_DIRS}/lttng/tracef.h")
  52. set(LTTNGUST_HAS_TRACEF TRUE)
  53. endif()
  54. if(EXISTS "${LTTNGUST_INCLUDE_DIRS}/lttng/tracelog.h")
  55. set(LTTNGUST_HAS_TRACELOG TRUE)
  56. endif()
  57. # get version
  58. set(lttngust_version_file "${LTTNGUST_INCLUDE_DIRS}/lttng/ust-version.h")
  59. if(EXISTS "${lttngust_version_file}")
  60. file(STRINGS "${lttngust_version_file}" lttngust_version_major_string
  61. REGEX "^[\t ]*#define[\t ]+LTTNG_UST_MAJOR_VERSION[\t ]+[0-9]+[\t ]*$")
  62. file(STRINGS "${lttngust_version_file}" lttngust_version_minor_string
  63. REGEX "^[\t ]*#define[\t ]+LTTNG_UST_MINOR_VERSION[\t ]+[0-9]+[\t ]*$")
  64. file(STRINGS "${lttngust_version_file}" lttngust_version_patch_string
  65. REGEX "^[\t ]*#define[\t ]+LTTNG_UST_PATCHLEVEL_VERSION[\t ]+[0-9]+[\t ]*$")
  66. string(REGEX REPLACE ".*([0-9]+).*" "\\1"
  67. lttngust_v_major "${lttngust_version_major_string}")
  68. string(REGEX REPLACE ".*([0-9]+).*" "\\1"
  69. lttngust_v_minor "${lttngust_version_minor_string}")
  70. string(REGEX REPLACE ".*([0-9]+).*" "\\1"
  71. lttngust_v_patch "${lttngust_version_patch_string}")
  72. set(LTTNGUST_VERSION_STRING
  73. "${lttngust_v_major}.${lttngust_v_minor}.${lttngust_v_patch}")
  74. unset(lttngust_version_major_string)
  75. unset(lttngust_version_minor_string)
  76. unset(lttngust_version_patch_string)
  77. unset(lttngust_v_major)
  78. unset(lttngust_v_minor)
  79. unset(lttngust_v_patch)
  80. endif()
  81. unset(lttngust_version_file)
  82. if(NOT TARGET LTTng::UST)
  83. add_library(LTTng::UST UNKNOWN IMPORTED)
  84. set_target_properties(LTTng::UST PROPERTIES
  85. INTERFACE_INCLUDE_DIRECTORIES "${LTTNGUST_INCLUDE_DIRS}"
  86. INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS}
  87. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  88. IMPORTED_LOCATION "${LTTNGUST_LIBRARIES}")
  89. endif()
  90. # add libdl to required libraries
  91. set(LTTNGUST_LIBRARIES ${LTTNGUST_LIBRARIES} ${CMAKE_DL_LIBS})
  92. endif()
  93. # handle the QUIETLY and REQUIRED arguments and set LTTNGUST_FOUND to
  94. # TRUE if all listed variables are TRUE
  95. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  96. find_package_handle_standard_args(LTTngUST FOUND_VAR LTTNGUST_FOUND
  97. REQUIRED_VARS LTTNGUST_LIBRARIES
  98. LTTNGUST_INCLUDE_DIRS
  99. VERSION_VAR LTTNGUST_VERSION_STRING)
  100. mark_as_advanced(LTTNGUST_LIBRARIES LTTNGUST_INCLUDE_DIRS)