FindLibdrm.cmake 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #[=======================================================================[.rst
  2. FindLibdrm
  3. ----------
  4. FindModule for Libdrm and associated libraries
  5. .. versionchanged:: 3.0
  6. Updated FindModule to CMake standards
  7. Imported Targets
  8. ^^^^^^^^^^^^^^^^
  9. .. versionadded:: 2.0
  10. This module defines the :prop_tgt:`IMPORTED` target ``Libdrm::Libdrm``.
  11. Result Variables
  12. ^^^^^^^^^^^^^^^^
  13. This module sets the following variables:
  14. ``Libdrm_FOUND``
  15. True, if all required components and the core library were found.
  16. ``Libdrm_VERSION``
  17. Detected version of found Libdrm libraries.
  18. Cache variables
  19. ^^^^^^^^^^^^^^^
  20. The following cache variables may also be set:
  21. ``Libdrm_LIBRARY``
  22. Path to the library component of Libdrm.
  23. ``Libdrm_INCLUDE_DIR``
  24. Directory containing ``drm_fourcc.h``.
  25. #]=======================================================================]
  26. include(FindPackageHandleStandardArgs)
  27. find_package(PkgConfig QUIET)
  28. if(PKG_CONFIG_FOUND)
  29. pkg_search_module(PC_Libdrm QUIET libdrm)
  30. endif()
  31. find_path(
  32. Libdrm_INCLUDE_DIR
  33. NAMES drm_fourcc.h
  34. HINTS ${PC_Libdrm_INCLUDE_DIRS}
  35. PATHS /usr/include /usr/local/include
  36. PATH_SUFFIXES libdrm
  37. DOC "Libdrm include directory"
  38. )
  39. find_library(
  40. Libdrm_LIBRARY
  41. NAMES drm libdrm
  42. HINTS ${PC_Libdrm_LIBRARY_DIRS}
  43. PATHS /usr/lib /usr/local/lib
  44. DOC "Libdrm location"
  45. )
  46. if(PC_Libdrm_VERSION VERSION_GREATER 0)
  47. set(Libdrm_VERSION ${PC_Libdrm_VERSION})
  48. else()
  49. if(NOT Libdrm_FIND_QUIETLY)
  50. message(AUTHOR_WARNING "Failed to find Libdrm version.")
  51. endif()
  52. set(Libdrm_VERSION 0.0.0)
  53. endif()
  54. find_package_handle_standard_args(
  55. Libdrm
  56. REQUIRED_VARS Libdrm_LIBRARY Libdrm_INCLUDE_DIR
  57. VERSION_VAR Libdrm_VERSION
  58. REASON_FAILURE_MESSAGE "Ensure that libdrm is installed on the system."
  59. )
  60. mark_as_advanced(Libdrm_INCLUDE_DIR Libdrm_LIBRARY)
  61. if(Libdrm_FOUND)
  62. if(NOT TARGET Libdrm::Libdrm)
  63. if(IS_ABSOLUTE "${Libdrm_LIBRARY}")
  64. add_library(Libdrm::Libdrm UNKNOWN IMPORTED)
  65. set_property(TARGET Libdrm::Libdrm PROPERTY IMPORTED_LOCATION "${Libdrm_LIBRARY}")
  66. else()
  67. add_library(Libdrm::Libdrm INTERFACE IMPORTED)
  68. set_property(TARGET Libdrm::Libdrm PROPERTY IMPORTED_LIBNAME "${Libdrm_LIBRARY}")
  69. endif()
  70. set_target_properties(
  71. Libdrm::Libdrm
  72. PROPERTIES
  73. INTERFACE_COMPILE_OPTIONS "${PC_Libdrm_CFLAGS_OTHER}"
  74. INTERFACE_INCLUDE_DIRECTORIES "${Libdrm_INCLUDE_DIR}"
  75. VERSION ${Libdrm_VERSION}
  76. )
  77. endif()
  78. endif()
  79. include(FeatureSummary)
  80. set_package_properties(
  81. Libdrm
  82. PROPERTIES
  83. URL "https://gitlab.freedesktop.org/mesa/drm"
  84. DESCRIPTION
  85. "A low-level library, typically used by graphics drivers such as the Mesa drivers, the X drivers, libva and similar projects."
  86. )