FindWayland.cmake 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # Try to find Wayland on a Unix system
  2. #
  3. # This will define:
  4. #
  5. # WAYLAND_FOUND - True if Wayland is found WAYLAND_LIBRARIES - Link
  6. # these to use Wayland WAYLAND_INCLUDE_DIRS - Include directory for Wayland
  7. # WAYLAND_COMPILE_FLAGS - Compiler flags for using Wayland
  8. #
  9. # In addition the following more fine grained variables will be defined:
  10. #
  11. # Wayland_Client_FOUND WAYLAND_CLIENT_INCLUDE_DIRS WAYLAND_CLIENT_LIBRARIES
  12. # Wayland_Server_FOUND WAYLAND_SERVER_INCLUDE_DIRS WAYLAND_SERVER_LIBRARIES
  13. # Wayland_EGL_FOUND WAYLAND_EGL_INCLUDE_DIRS WAYLAND_EGL_LIBRARIES
  14. # Wayland_Cursor_FOUND WAYLAND_CURSOR_INCLUDE_DIRS WAYLAND_CURSOR_LIBRARIES
  15. #
  16. # Copyright (c) 2013 Martin Gräßlin <[email protected]> 2020 Georges Basile
  17. # Stavracas Neto <[email protected]>
  18. #
  19. # Redistribution and use is allowed according to the terms of the BSD license.
  20. # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
  21. # Use pkg-config to get the directories and then use these values in the
  22. # find_path() and find_library() calls
  23. find_package(PkgConfig)
  24. pkg_check_modules(PKG_WAYLAND QUIET wayland-client wayland-server wayland-egl
  25. wayland-cursor)
  26. set(WAYLAND_COMPILE_FLAGS ${PKG_WAYLAND_CFLAGS})
  27. find_path(
  28. WAYLAND_CLIENT_INCLUDE_DIRS
  29. NAMES wayland-client.h
  30. HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
  31. find_library(
  32. WAYLAND_CLIENT_LIBRARIES
  33. NAMES wayland-client
  34. HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
  35. if(WAYLAND_CLIENT_INCLUDE_DIRS AND WAYLAND_CLIENT_LIBRARIES)
  36. set(Wayland_Client_FOUND TRUE)
  37. else()
  38. set(Wayland_Client_FOUND FALSE)
  39. endif()
  40. mark_as_advanced(WAYLAND_CLIENT_INCLUDE_DIRS WAYLAND_CLIENT_LIBRARIES)
  41. find_path(
  42. WAYLAND_CURSOR_INCLUDE_DIRS
  43. NAMES wayland-cursor.h
  44. HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
  45. find_library(
  46. WAYLAND_CURSOR_LIBRARIES
  47. NAMES wayland-cursor
  48. HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
  49. if(WAYLAND_CURSOR_INCLUDE_DIRS AND WAYLAND_CURSOR_LIBRARIES)
  50. set(Wayland_Cursor_FOUND TRUE)
  51. else()
  52. set(Wayland_Cursor_FOUND FALSE)
  53. endif()
  54. mark_as_advanced(WAYLAND_CURSOR_INCLUDE_DIRS WAYLAND_CURSOR_LIBRARIES)
  55. find_path(
  56. WAYLAND_EGL_INCLUDE_DIRS
  57. NAMES wayland-egl.h
  58. HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
  59. find_library(
  60. WAYLAND_EGL_LIBRARIES
  61. NAMES wayland-egl
  62. HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
  63. if(WAYLAND_EGL_INCLUDE_DIRS AND WAYLAND_EGL_LIBRARIES)
  64. set(Wayland_EGL_FOUND TRUE)
  65. else()
  66. set(Wayland_EGL_FOUND FALSE)
  67. endif()
  68. mark_as_advanced(WAYLAND_EGL_INCLUDE_DIRS WAYLAND_EGL_LIBRARIES)
  69. find_path(
  70. WAYLAND_SERVER_INCLUDE_DIRS
  71. NAMES wayland-server.h
  72. HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
  73. find_library(
  74. WAYLAND_SERVER_LIBRARIES
  75. NAMES wayland-server
  76. HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
  77. if(WAYLAND_SERVER_INCLUDE_DIRS AND WAYLAND_SERVER_LIBRARIES)
  78. set(Wayland_Server_FOUND TRUE)
  79. else()
  80. set(Wayland_Server_FOUND FALSE)
  81. endif()
  82. mark_as_advanced(WAYLAND_SERVER_INCLUDE_DIRS WAYLAND_SERVER_LIBRARIES)
  83. set(WAYLAND_INCLUDE_DIRS
  84. ${WAYLAND_CLIENT_INCLUDE_DIRS} ${WAYLAND_SERVER_INCLUDE_DIRS}
  85. ${WAYLAND_EGL_INCLUDE_DIRS} ${WAYLAND_CURSOR_INCLUDE_DIRS})
  86. set(WAYLAND_LIBRARIES ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_SERVER_LIBRARIES}
  87. ${WAYLAND_EGL_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES})
  88. mark_as_advanced(WAYLAND_INCLUDE_DIRS WAYLAND_LIBRARIES)
  89. list(REMOVE_DUPLICATES WAYLAND_INCLUDE_DIRS)
  90. include(FindPackageHandleStandardArgs)
  91. find_package_handle_standard_args(
  92. Wayland
  93. REQUIRED_VARS WAYLAND_LIBRARIES WAYLAND_INCLUDE_DIRS
  94. HANDLE_COMPONENTS)
  95. foreach(component "Client" "Server" "EGL" "Cursor")
  96. if(NOT TARGET Wayland::${component})
  97. string(TOUPPER ${component} component_u)
  98. if(Wayland_${component}_FOUND)
  99. if(IS_ABSOLUTE "${WAYLAND_${component_u}_LIBRARIES}")
  100. add_library(Wayland::${component} UNKNOWN IMPORTED)
  101. set_target_properties(
  102. Wayland::${component}
  103. PROPERTIES IMPORTED_LOCATION "${WAYLAND_${component_u}_LIBRARIES}")
  104. else()
  105. add_library(Wayland::${component} INTERFACE IMPORTED)
  106. set_target_properties(
  107. Wayland::${component}
  108. PROPERTIES IMPORTED_LIBNAME "${WAYLAND_${component_u}_LIBRARIES}")
  109. endif()
  110. set_target_properties(
  111. Wayland::${component}
  112. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
  113. "${WAYLAND_${component_u}_INCLUDE_DIRS}")
  114. set_target_properties(
  115. Wayland::${component} PROPERTIES INTERFACE_COMPILE_OPTIONS
  116. "${WAYLAND_COMPILE_FLAGS}")
  117. endif()
  118. endif()
  119. endforeach()