FindWayland.cmake 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #[=======================================================================[.rst
  2. FindWayland
  3. -----------
  4. FindModule for Wayland and and associated components
  5. .. versionchanged:: 3.0
  6. Updated FindModule to CMake standards
  7. Components
  8. ^^^^^^^^^^
  9. .. versionadded:: 1.0
  10. This module contains provides several components:
  11. ``Client``
  12. ``Server``
  13. ``EGL``
  14. ``Cursor``
  15. Import targets exist for each component.
  16. Imported Targets
  17. ^^^^^^^^^^^^^^^^
  18. .. versionadded:: 2.0
  19. This module defines the :prop_tgt:`IMPORTED` targets:
  20. ``Wayland::Client``
  21. Wayland client component
  22. ``Wayland::Server``
  23. Wayland server component
  24. ``Wayland::EGL``
  25. Wayland EGL component
  26. ``Wayland::Cursor``
  27. Wayland cursor component
  28. Result Variables
  29. ^^^^^^^^^^^^^^^^
  30. This module sets the following variables:
  31. ``Wayland_<COMPONENT>_FOUND``
  32. True, if required component was found.
  33. ``Wayland_<COMPONENT>_VERSION``
  34. Detected version of Wayland component.
  35. ``Wayland_<COMPONENT>_INCLUDE_DIRS``
  36. Include directories needed for Wayland component.
  37. ``Wayland_<COMPONENT>_LIBRARIES``
  38. Libraries needed to link to Wayland component.
  39. Cache variables
  40. ^^^^^^^^^^^^^^^
  41. The following cache variables may also be set:
  42. ``Wayland_<COMPONENT>_LIBRARY``
  43. Path to the component of Wayland.
  44. ``Wayland_<COMPONENT>_INCLUDE_DIR``
  45. Directory containing ``<COMPONENT>.h``.
  46. #]=======================================================================]
  47. include(FindPackageHandleStandardArgs)
  48. find_package(PkgConfig QUIET)
  49. list(APPEND _Wayland_DEFAULT_COMPONENTS Client Server EGL Cursor)
  50. list(APPEND _Wayland_LIBRARIES wayland-client wayland-server wayland-egl wayland-cursor)
  51. if(NOT Wayland_FIND_COMPONENTS)
  52. set(Wayland_FIND_COMPONENTS ${_Wayland_DEFAULT_COMPONENTS})
  53. endif()
  54. # Wayland_find_component: Macro to setup targets for specified Wayland component
  55. macro(Wayland_find_component component)
  56. list(GET _Wayland_DEFAULT_COMPONENTS ${component} COMPONENT_NAME)
  57. list(GET _Wayland_LIBRARIES ${component} COMPONENT_LIBRARY)
  58. if(NOT TARGET Wayland::${COMPONENT_NAME})
  59. if(PKG_CONFIG_FOUND)
  60. pkg_search_module(PC_Wayland_${COMPONENT_NAME} QUIET ${COMPONENT_LIBRARY})
  61. endif()
  62. find_path(
  63. Wayland_${COMPONENT_NAME}_INCLUDE_DIR
  64. NAMES ${COMPONENT_LIBRARY}.h
  65. HINTS ${PC_Wayland_${COMPONENT_NAME}_INCLUDE_DIRS}
  66. PATHS /usr/include /usr/local/include
  67. DOC "Wayland ${COMPONENT_NAME} include directory"
  68. )
  69. find_library(
  70. Wayland_${COMPONENT_NAME}_LIBRARY
  71. NAMES ${COMPONENT_LIBRARY}
  72. HINTS ${PC_Wayland_${COMPONENT_NAME}_LIBRARY_DIRS}
  73. PATHS /usr/lib /usr/local/lib
  74. DOC "Wayland ${COMPONENT_NAME} location"
  75. )
  76. if(PC_Wayland_${COMPONENT_NAME}_VERSION VERSION_GREATER 0)
  77. set(Wayland_${COMPONENT_NAME}_VERSION ${PC_Wayland_${COMPONENT_NAME}_VERSION})
  78. else()
  79. if(NOT Wayland_FIND_QUIETLY)
  80. message(AUTHOR_WARNING "Failed to find Wayland ${COMPONENT_NAME} version.")
  81. endif()
  82. set(Wayland_${COMPONENT_NAME}_VERSION 0.0.0)
  83. endif()
  84. if(Wayland_${COMPONENT_NAME}_LIBRARY AND Wayland_${COMPONENT_NAME}_INCLUDE_DIR)
  85. set(Wayland_${COMPONENT_NAME}_FOUND TRUE)
  86. set(Wayland_${COMPONENT_NAME}_LIBRARIES ${Wayland_${COMPONENT_NAME}_LIBRARY})
  87. set(Wayland_${COMPONENT_NAME}_INCLUDE_DIRS ${Wayland_${COMPONENT_NAME}_INCLUDE_DIR})
  88. set(Wayland_${COMPONENT_NAME}_DEFINITIONS ${PC_Wayland_${COMPONENT_NAME}_CFLAGS_OTHER})
  89. mark_as_advanced(Wayland_${COMPONENT_NAME}_LIBRARY Wayland_${COMPONENT_NAME}_INCLUDE_DIR)
  90. if(IS_ABSOLUTE "${Wayland_${COMPONENT_NAME}_LIBRARY}")
  91. add_library(Wayland::${COMPONENT_NAME} UNKNOWN IMPORTED)
  92. set_property(
  93. TARGET Wayland::${COMPONENT_NAME}
  94. PROPERTY IMPORTED_LOCATION "${Wayland_${COMPONENT_NAME}_LIBRARY}"
  95. )
  96. else()
  97. add_library(Wayland::${COMPONENT_NAME} INTERFACE IMPORTED)
  98. set_property(TARGET Wayland::${COMPONENT_NAME} PROPERTY IMPORTED_LIBNAME "${Wayland_${COMPONENT_NAME}_LIBRARY}")
  99. endif()
  100. set_target_properties(
  101. Wayland::${COMPONENT_NAME}
  102. PROPERTIES
  103. INTERFACE_COMPILE_OPTIONS "${PC_Wayland_${COMPONENT_NAME}_CFLAGS_OTHER}"
  104. INTERFACE_INCLUDE_DIRECTORIES "${Wayland_${COMPONENT_NAME}_INCLUDE_DIR}"
  105. VERSION ${Wayland_${COMPONENT_NAME}_VERSION}
  106. )
  107. list(APPEND Wayland_COMPONENTS Wayland::${COMPONENT_NAME})
  108. list(APPEND Wayland_INCLUDE_DIRS ${Wayland_${COMPONENT_NAME}_INCLUDE_DIR})
  109. list(APPEND Wayland_LIBRARIES ${Wayland_${COMPONENT_NAME}_LIBRARY})
  110. if(NOT Wayland_VERSION)
  111. set(Wayland_VERSION ${Wayland_${COMPONENT_NAME}_VERSION})
  112. endif()
  113. endif()
  114. else()
  115. list(APPEND Wayland_COMPONENTS Wayland::${COMPONENT_NAME})
  116. endif()
  117. endmacro()
  118. foreach(component IN LISTS Wayland_FIND_COMPONENTS)
  119. list(FIND _Wayland_DEFAULT_COMPONENTS "${component}" valid_component)
  120. if(valid_component GREATER_EQUAL 0)
  121. wayland_find_component(${valid_component})
  122. else()
  123. message(FATAL_ERROR "Unknown Wayland component required: ${component}.")
  124. endif()
  125. endforeach()
  126. find_package_handle_standard_args(
  127. Wayland
  128. REQUIRED_VARS Wayland_LIBRARIES Wayland_INCLUDE_DIRS
  129. VERSION_VAR Wayland_VERSION
  130. HANDLE_COMPONENTS
  131. REASON_FAILURE_MESSAGE "Ensure that Wayland is installed on the system."
  132. )
  133. unset(_Wayland_DEFAULT_COMPONENTS)
  134. unset(_Wayland_LIBRARIES)
  135. include(FeatureSummary)
  136. set_package_properties(
  137. Wayland
  138. PROPERTIES
  139. URL "https://wayland.freedesktop.org"
  140. DESCRIPTION
  141. "A replacement for the X11 window system protocol and architecture with the aim to be easier to develop, extend, and maintain."
  142. )