FindWayland.cmake 4.4 KB

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