FindX11.cmake 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindX11
  5. -------
  6. Find X11 installation
  7. Try to find X11 on UNIX systems. The following values are defined
  8. ::
  9. X11_FOUND - True if X11 is available
  10. X11_INCLUDE_DIR - include directories to use X11
  11. X11_LIBRARIES - link against these to use X11
  12. and also the following more fine grained variables and targets:
  13. ::
  14. X11_ICE_INCLUDE_PATH, X11_ICE_LIB, X11_ICE_FOUND, X11::ICE
  15. X11_SM_INCLUDE_PATH, X11_SM_LIB, X11_SM_FOUND, X11::SM
  16. X11_X11_INCLUDE_PATH, X11_X11_LIB, X11::X11
  17. X11_Xaccessrules_INCLUDE_PATH,
  18. X11_Xaccessstr_INCLUDE_PATH, X11_Xaccess_FOUND
  19. X11_Xau_INCLUDE_PATH, X11_Xau_LIB, X11_Xau_FOUND, X11::Xau
  20. X11_Xcomposite_INCLUDE_PATH, X11_Xcomposite_LIB, X11_Xcomposite_FOUND, X11::Xcomposite
  21. X11_Xcursor_INCLUDE_PATH, X11_Xcursor_LIB, X11_Xcursor_FOUND, X11::Xcursor
  22. X11_Xdamage_INCLUDE_PATH, X11_Xdamage_LIB, X11_Xdamage_FOUND, X11::Xdamage
  23. X11_Xdmcp_INCLUDE_PATH, X11_Xdmcp_LIB, X11_Xdmcp_FOUND, X11::Xdmcp
  24. X11_Xext_INCLUDE_PATH, X11_Xext_LIB, X11_Xext_FOUND, X11::Xext
  25. X11_Xxf86misc_INCLUDE_PATH, X11_Xxf86misc_LIB, X11_Xxf86misc_FOUND, X11::Xxf86misc
  26. X11_Xxf86vm_INCLUDE_PATH, X11_Xxf86vm_LIB X11_Xxf86vm_FOUND, X11::Xxf86vm
  27. X11_Xfixes_INCLUDE_PATH, X11_Xfixes_LIB, X11_Xfixes_FOUND, X11::Xfixes
  28. X11_Xft_INCLUDE_PATH, X11_Xft_LIB, X11_Xft_FOUND, X11::Xft
  29. X11_Xi_INCLUDE_PATH, X11_Xi_LIB, X11_Xi_FOUND, X11::Xi
  30. X11_Xinerama_INCLUDE_PATH, X11_Xinerama_LIB, X11_Xinerama_FOUND, X11::Xinerama
  31. X11_Xkb_INCLUDE_PATH,
  32. X11_Xkblib_INCLUDE_PATH, X11_Xkb_FOUND, X11::Xkb
  33. X11_xkbfile_INCLUDE_PATH, X11_xkbfile_LIB, X11_xkbfile_FOUND, X11::xkbfile
  34. X11_Xmu_INCLUDE_PATH, X11_Xmu_LIB, X11_Xmu_FOUND, X11::Xmu
  35. X11_Xpm_INCLUDE_PATH, X11_Xpm_LIB, X11_Xpm_FOUND, X11::Xpm
  36. X11_Xtst_INCLUDE_PATH, X11_Xtst_LIB, X11_Xtst_FOUND, X11::Xtst
  37. X11_Xrandr_INCLUDE_PATH, X11_Xrandr_LIB, X11_Xrandr_FOUND, X11::Xrandr
  38. X11_Xrender_INCLUDE_PATH, X11_Xrender_LIB, X11_Xrender_FOUND, X11::Xrender
  39. X11_XRes_INCLUDE_PATH, X11_XRes_LIB, X11_XRes_FOUND, X11::XRes
  40. X11_Xss_INCLUDE_PATH, X11_Xss_LIB, X11_Xss_FOUND, X11::Xss
  41. X11_Xt_INCLUDE_PATH, X11_Xt_LIB, X11_Xt_FOUND, X11::Xt
  42. X11_Xutil_INCLUDE_PATH, X11_Xutil_FOUND, X11::Xutil
  43. X11_Xv_INCLUDE_PATH, X11_Xv_LIB, X11_Xv_FOUND, X11::Xv
  44. X11_dpms_INCLUDE_PATH, (in X11_Xext_LIB), X11_dpms_FOUND
  45. X11_XShm_INCLUDE_PATH, (in X11_Xext_LIB), X11_XShm_FOUND
  46. X11_Xshape_INCLUDE_PATH, (in X11_Xext_LIB), X11_Xshape_FOUND
  47. X11_XSync_INCLUDE_PATH, (in X11_Xext_LIB), X11_XSync_FOUND
  48. #]=======================================================================]
  49. if (UNIX)
  50. set(X11_FOUND 0)
  51. # X11 is never a framework and some header files may be
  52. # found in tcl on the mac
  53. set(CMAKE_FIND_FRAMEWORK_SAVE ${CMAKE_FIND_FRAMEWORK})
  54. set(CMAKE_FIND_FRAMEWORK NEVER)
  55. set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET})
  56. set(CMAKE_REQUIRED_QUIET ${X11_FIND_QUIETLY})
  57. set(X11_INC_SEARCH_PATH
  58. /usr/pkg/xorg/include
  59. /usr/X11R6/include
  60. /usr/X11R7/include
  61. /usr/include/X11
  62. /usr/openwin/include
  63. /usr/openwin/share/include
  64. /opt/graphics/OpenGL/include
  65. /opt/X11/include
  66. )
  67. set(X11_LIB_SEARCH_PATH
  68. /usr/pkg/xorg/lib
  69. /usr/X11R6/lib
  70. /usr/X11R7/lib
  71. /usr/openwin/lib
  72. /opt/X11/lib
  73. )
  74. find_path(X11_X11_INCLUDE_PATH X11/X.h ${X11_INC_SEARCH_PATH})
  75. find_path(X11_Xlib_INCLUDE_PATH X11/Xlib.h ${X11_INC_SEARCH_PATH})
  76. # Look for includes; keep the list sorted by name of the cmake *_INCLUDE_PATH
  77. # variable (which doesn't need to match the include file name).
  78. # Solaris lacks XKBrules.h, so we should skip kxkbd there.
  79. find_path(X11_ICE_INCLUDE_PATH X11/ICE/ICE.h ${X11_INC_SEARCH_PATH})
  80. find_path(X11_SM_INCLUDE_PATH X11/SM/SM.h ${X11_INC_SEARCH_PATH})
  81. find_path(X11_Xaccessrules_INCLUDE_PATH X11/extensions/XKBrules.h ${X11_INC_SEARCH_PATH})
  82. find_path(X11_Xaccessstr_INCLUDE_PATH X11/extensions/XKBstr.h ${X11_INC_SEARCH_PATH})
  83. find_path(X11_Xau_INCLUDE_PATH X11/Xauth.h ${X11_INC_SEARCH_PATH})
  84. find_path(X11_Xcomposite_INCLUDE_PATH X11/extensions/Xcomposite.h ${X11_INC_SEARCH_PATH})
  85. find_path(X11_Xcursor_INCLUDE_PATH X11/Xcursor/Xcursor.h ${X11_INC_SEARCH_PATH})
  86. find_path(X11_Xdamage_INCLUDE_PATH X11/extensions/Xdamage.h ${X11_INC_SEARCH_PATH})
  87. find_path(X11_Xdmcp_INCLUDE_PATH X11/Xdmcp.h ${X11_INC_SEARCH_PATH})
  88. find_path(X11_Xext_INCLUDE_PATH X11/extensions/Xext.h ${X11_INC_SEARCH_PATH})
  89. find_path(X11_dpms_INCLUDE_PATH X11/extensions/dpms.h ${X11_INC_SEARCH_PATH})
  90. find_path(X11_Xxf86misc_INCLUDE_PATH X11/extensions/xf86misc.h ${X11_INC_SEARCH_PATH})
  91. find_path(X11_Xxf86vm_INCLUDE_PATH X11/extensions/xf86vmode.h ${X11_INC_SEARCH_PATH})
  92. find_path(X11_Xfixes_INCLUDE_PATH X11/extensions/Xfixes.h ${X11_INC_SEARCH_PATH})
  93. find_path(X11_Xft_INCLUDE_PATH X11/Xft/Xft.h ${X11_INC_SEARCH_PATH})
  94. find_path(X11_Xi_INCLUDE_PATH X11/extensions/XInput.h ${X11_INC_SEARCH_PATH})
  95. find_path(X11_Xinerama_INCLUDE_PATH X11/extensions/Xinerama.h ${X11_INC_SEARCH_PATH})
  96. find_path(X11_Xkb_INCLUDE_PATH X11/extensions/XKB.h ${X11_INC_SEARCH_PATH})
  97. find_path(X11_Xkblib_INCLUDE_PATH X11/XKBlib.h ${X11_INC_SEARCH_PATH})
  98. find_path(X11_xkbfile_INCLUDE_PATH X11/extensions/XKBfile.h ${X11_INC_SEARCH_PATH})
  99. find_path(X11_Xmu_INCLUDE_PATH X11/Xmu/Xmu.h ${X11_INC_SEARCH_PATH})
  100. find_path(X11_Xpm_INCLUDE_PATH X11/xpm.h ${X11_INC_SEARCH_PATH})
  101. find_path(X11_Xtst_INCLUDE_PATH X11/extensions/XTest.h ${X11_INC_SEARCH_PATH})
  102. find_path(X11_XShm_INCLUDE_PATH X11/extensions/XShm.h ${X11_INC_SEARCH_PATH})
  103. find_path(X11_Xrandr_INCLUDE_PATH X11/extensions/Xrandr.h ${X11_INC_SEARCH_PATH})
  104. find_path(X11_Xrender_INCLUDE_PATH X11/extensions/Xrender.h ${X11_INC_SEARCH_PATH})
  105. find_path(X11_XRes_INCLUDE_PATH X11/extensions/XRes.h ${X11_INC_SEARCH_PATH})
  106. find_path(X11_Xss_INCLUDE_PATH X11/extensions/scrnsaver.h ${X11_INC_SEARCH_PATH})
  107. find_path(X11_Xshape_INCLUDE_PATH X11/extensions/shape.h ${X11_INC_SEARCH_PATH})
  108. find_path(X11_Xutil_INCLUDE_PATH X11/Xutil.h ${X11_INC_SEARCH_PATH})
  109. find_path(X11_Xt_INCLUDE_PATH X11/Intrinsic.h ${X11_INC_SEARCH_PATH})
  110. find_path(X11_Xv_INCLUDE_PATH X11/extensions/Xvlib.h ${X11_INC_SEARCH_PATH})
  111. find_path(X11_XSync_INCLUDE_PATH X11/extensions/sync.h ${X11_INC_SEARCH_PATH})
  112. # Backwards compatibility.
  113. set(X11_Xinput_INCLUDE_PATH "${X11_Xi_INCLUDE_PATH}")
  114. set(X11_xf86misc_INCLUDE_PATH "${X11_Xxf86misc_INCLUDE_PATH}")
  115. set(X11_xf86vmode_INCLUDE_PATH "${X11_Xxf8vm_INCLUDE_PATH}")
  116. set(X11_Xkbfile_INCLUDE_PATH "${X11_xkbfile_INCLUDE_PATH}")
  117. set(X11_XTest_INCLUDE_PATH "${X11_Xtst_INCLUDE_PATH}")
  118. set(X11_Xscreensaver_INCLUDE_PATH "${X11_Xss_INCLUDE_PATH}")
  119. find_library(X11_X11_LIB X11 ${X11_LIB_SEARCH_PATH})
  120. # Find additional X libraries. Keep list sorted by library name.
  121. find_library(X11_ICE_LIB ICE ${X11_LIB_SEARCH_PATH})
  122. find_library(X11_SM_LIB SM ${X11_LIB_SEARCH_PATH})
  123. find_library(X11_Xau_LIB Xau ${X11_LIB_SEARCH_PATH})
  124. find_library(X11_Xcomposite_LIB Xcomposite ${X11_LIB_SEARCH_PATH})
  125. find_library(X11_Xcursor_LIB Xcursor ${X11_LIB_SEARCH_PATH})
  126. find_library(X11_Xdamage_LIB Xdamage ${X11_LIB_SEARCH_PATH})
  127. find_library(X11_Xdmcp_LIB Xdmcp ${X11_LIB_SEARCH_PATH})
  128. find_library(X11_Xext_LIB Xext ${X11_LIB_SEARCH_PATH})
  129. find_library(X11_Xfixes_LIB Xfixes ${X11_LIB_SEARCH_PATH})
  130. find_library(X11_Xft_LIB Xft ${X11_LIB_SEARCH_PATH})
  131. find_library(X11_Xi_LIB Xi ${X11_LIB_SEARCH_PATH})
  132. find_library(X11_Xinerama_LIB Xinerama ${X11_LIB_SEARCH_PATH})
  133. find_library(X11_xkbfile_LIB xkbfile ${X11_LIB_SEARCH_PATH})
  134. find_library(X11_Xmu_LIB Xmu ${X11_LIB_SEARCH_PATH})
  135. find_library(X11_Xpm_LIB Xpm ${X11_LIB_SEARCH_PATH})
  136. find_library(X11_Xrandr_LIB Xrandr ${X11_LIB_SEARCH_PATH})
  137. find_library(X11_Xrender_LIB Xrender ${X11_LIB_SEARCH_PATH})
  138. find_library(X11_XRes_LIB XRes ${X11_LIB_SEARCH_PATH})
  139. find_library(X11_Xss_LIB Xss ${X11_LIB_SEARCH_PATH})
  140. find_library(X11_Xt_LIB Xt ${X11_LIB_SEARCH_PATH})
  141. find_library(X11_Xtst_LIB Xtst ${X11_LIB_SEARCH_PATH})
  142. find_library(X11_Xv_LIB Xv ${X11_LIB_SEARCH_PATH})
  143. find_library(X11_Xxf86misc_LIB Xxf86misc ${X11_LIB_SEARCH_PATH})
  144. find_library(X11_Xxf86vm_LIB Xxf86vm ${X11_LIB_SEARCH_PATH})
  145. # Backwards compatibility.
  146. set(X11_Xinput_LIB "${X11_Xi_LIB}")
  147. set(X11_Xkbfile_LIB "${X11_xkbfile_LIB}")
  148. set(X11_XTest_LIB "${X11_Xtst_LIB}")
  149. set(X11_Xscreensaver_LIB "${X11_Xss_LIB}")
  150. set(X11_LIBRARY_DIR "")
  151. if(X11_X11_LIB)
  152. get_filename_component(X11_LIBRARY_DIR ${X11_X11_LIB} PATH)
  153. endif()
  154. set(X11_INCLUDE_DIR) # start with empty list
  155. if(X11_X11_INCLUDE_PATH)
  156. list(APPEND X11_INCLUDE_DIR ${X11_X11_INCLUDE_PATH})
  157. endif()
  158. if(X11_Xlib_INCLUDE_PATH)
  159. list(APPEND X11_INCLUDE_DIR ${X11_Xlib_INCLUDE_PATH})
  160. endif()
  161. if(X11_Xutil_INCLUDE_PATH)
  162. set(X11_Xutil_FOUND TRUE)
  163. list(APPEND X11_INCLUDE_DIR ${X11_Xutil_INCLUDE_PATH})
  164. endif()
  165. if(X11_Xshape_INCLUDE_PATH)
  166. set(X11_Xshape_FOUND TRUE)
  167. list(APPEND X11_INCLUDE_DIR ${X11_Xshape_INCLUDE_PATH})
  168. endif()
  169. set(X11_LIBRARIES) # start with empty list
  170. if(X11_X11_LIB)
  171. list(APPEND X11_LIBRARIES ${X11_X11_LIB})
  172. endif()
  173. if(X11_Xext_LIB)
  174. set(X11_Xext_FOUND TRUE)
  175. list(APPEND X11_LIBRARIES ${X11_Xext_LIB})
  176. endif()
  177. if(X11_Xt_LIB AND X11_Xt_INCLUDE_PATH)
  178. set(X11_Xt_FOUND TRUE)
  179. endif()
  180. if(X11_Xft_LIB AND X11_Xft_INCLUDE_PATH)
  181. find_package(Freetype QUIET)
  182. find_package(Fontconfig QUIET)
  183. if (FREETYPE_FOUND AND Fontconfig_FOUND)
  184. set(X11_Xft_FOUND TRUE)
  185. endif ()
  186. list(APPEND X11_INCLUDE_DIR ${X11_Xft_INCLUDE_PATH})
  187. endif()
  188. if(X11_Xv_LIB AND X11_Xv_INCLUDE_PATH)
  189. set(X11_Xv_FOUND TRUE)
  190. list(APPEND X11_INCLUDE_DIR ${X11_Xv_INCLUDE_PATH})
  191. endif()
  192. if (X11_Xau_LIB AND X11_Xau_INCLUDE_PATH)
  193. set(X11_Xau_FOUND TRUE)
  194. endif ()
  195. if (X11_Xdmcp_INCLUDE_PATH AND X11_Xdmcp_LIB)
  196. set(X11_Xdmcp_FOUND TRUE)
  197. list(APPEND X11_INCLUDE_DIR ${X11_Xdmcp_INCLUDE_PATH})
  198. endif ()
  199. if (X11_Xaccessrules_INCLUDE_PATH AND X11_Xaccessstr_INCLUDE_PATH)
  200. set(X11_Xaccess_FOUND TRUE)
  201. set(X11_Xaccess_INCLUDE_PATH ${X11_Xaccessstr_INCLUDE_PATH})
  202. list(APPEND X11_INCLUDE_DIR ${X11_Xaccess_INCLUDE_PATH})
  203. endif ()
  204. if (X11_Xpm_INCLUDE_PATH AND X11_Xpm_LIB)
  205. set(X11_Xpm_FOUND TRUE)
  206. list(APPEND X11_INCLUDE_DIR ${X11_Xpm_INCLUDE_PATH})
  207. endif ()
  208. if (X11_Xcomposite_INCLUDE_PATH AND X11_Xcomposite_LIB)
  209. set(X11_Xcomposite_FOUND TRUE)
  210. list(APPEND X11_INCLUDE_DIR ${X11_Xcomposite_INCLUDE_PATH})
  211. endif ()
  212. if (X11_Xdamage_INCLUDE_PATH AND X11_Xdamage_LIB)
  213. set(X11_Xdamage_FOUND TRUE)
  214. list(APPEND X11_INCLUDE_DIR ${X11_Xdamage_INCLUDE_PATH})
  215. endif ()
  216. if (X11_XShm_INCLUDE_PATH)
  217. set(X11_XShm_FOUND TRUE)
  218. list(APPEND X11_INCLUDE_DIR ${X11_XShm_INCLUDE_PATH})
  219. endif ()
  220. if (X11_Xtst_INCLUDE_PATH AND X11_Xtst_LIB)
  221. set(X11_Xtst_FOUND TRUE)
  222. # Backwards compatibility.
  223. set(X11_XTest_FOUND TRUE)
  224. list(APPEND X11_INCLUDE_DIR ${X11_Xtst_INCLUDE_PATH})
  225. endif ()
  226. if (X11_Xi_INCLUDE_PATH AND X11_Xi_LIB)
  227. set(X11_Xi_FOUND TRUE)
  228. # Backwards compatibility.
  229. set(X11_Xinput_FOUND TRUE)
  230. list(APPEND X11_INCLUDE_DIR ${X11_Xi_INCLUDE_PATH})
  231. endif ()
  232. if (X11_Xinerama_INCLUDE_PATH AND X11_Xinerama_LIB)
  233. set(X11_Xinerama_FOUND TRUE)
  234. list(APPEND X11_INCLUDE_DIR ${X11_Xinerama_INCLUDE_PATH})
  235. endif ()
  236. if (X11_Xfixes_INCLUDE_PATH AND X11_Xfixes_LIB)
  237. set(X11_Xfixes_FOUND TRUE)
  238. list(APPEND X11_INCLUDE_DIR ${X11_Xfixes_INCLUDE_PATH})
  239. endif ()
  240. if (X11_Xrender_INCLUDE_PATH AND X11_Xrender_LIB)
  241. set(X11_Xrender_FOUND TRUE)
  242. list(APPEND X11_INCLUDE_DIR ${X11_Xrender_INCLUDE_PATH})
  243. endif ()
  244. if (X11_XRes_INCLUDE_PATH AND X11_XRes_LIB)
  245. set(X11_XRes_FOUND TRUE)
  246. list(APPEND X11_INCLUDE_DIR ${X11_XRes_INCLUDE_PATH})
  247. endif ()
  248. if (X11_Xrandr_INCLUDE_PATH AND X11_Xrandr_LIB)
  249. set(X11_Xrandr_FOUND TRUE)
  250. list(APPEND X11_INCLUDE_DIR ${X11_Xrandr_INCLUDE_PATH})
  251. endif ()
  252. if (X11_Xxf86misc_INCLUDE_PATH AND X11_Xxf86misc_LIB)
  253. set(X11_Xxf86misc_FOUND TRUE)
  254. # Backwards compatibility.
  255. set(X11_xf86misc_FOUND TRUE)
  256. list(APPEND X11_INCLUDE_DIR ${X11_Xxf86misc_INCLUDE_PATH})
  257. endif ()
  258. if (X11_Xxf86vm_INCLUDE_PATH AND X11_Xxf86vm_LIB)
  259. set(X11_Xxf86vm_FOUND TRUE)
  260. # Backwards compatibility.
  261. set(X11_xf86vmode_FOUND TRUE)
  262. list(APPEND X11_INCLUDE_DIR ${X11_Xxf86vm_INCLUDE_PATH})
  263. endif ()
  264. if (X11_Xcursor_INCLUDE_PATH AND X11_Xcursor_LIB)
  265. set(X11_Xcursor_FOUND TRUE)
  266. list(APPEND X11_INCLUDE_DIR ${X11_Xcursor_INCLUDE_PATH})
  267. endif ()
  268. if (X11_Xss_INCLUDE_PATH AND X11_Xss_LIB)
  269. set(X11_Xss_FOUND TRUE)
  270. set(X11_Xscreensaver_FOUND TRUE)
  271. list(APPEND X11_INCLUDE_DIR ${X11_Xss_INCLUDE_PATH})
  272. endif ()
  273. if (X11_dpms_INCLUDE_PATH)
  274. set(X11_dpms_FOUND TRUE)
  275. list(APPEND X11_INCLUDE_DIR ${X11_dpms_INCLUDE_PATH})
  276. endif ()
  277. if (X11_Xkb_INCLUDE_PATH AND X11_Xkblib_INCLUDE_PATH AND X11_Xlib_INCLUDE_PATH)
  278. set(X11_Xkb_FOUND TRUE)
  279. list(APPEND X11_INCLUDE_DIR ${X11_Xkb_INCLUDE_PATH} )
  280. endif ()
  281. if (X11_xkbfile_INCLUDE_PATH AND X11_xkbfile_LIB AND X11_Xlib_INCLUDE_PATH)
  282. set(X11_xkbfile_FOUND TRUE)
  283. # Backwards compatibility.
  284. set(X11_Xkbfile_FOUND TRUE)
  285. list(APPEND X11_INCLUDE_DIR ${X11_xkbfile_INCLUDE_PATH} )
  286. endif ()
  287. if (X11_Xmu_INCLUDE_PATH AND X11_Xmu_LIB)
  288. set(X11_Xmu_FOUND TRUE)
  289. list(APPEND X11_INCLUDE_DIR ${X11_Xmu_INCLUDE_PATH})
  290. endif ()
  291. if (X11_XSync_INCLUDE_PATH)
  292. set(X11_XSync_FOUND TRUE)
  293. list(APPEND X11_INCLUDE_DIR ${X11_XSync_INCLUDE_PATH})
  294. endif ()
  295. if(X11_ICE_LIB AND X11_ICE_INCLUDE_PATH)
  296. set(X11_ICE_FOUND TRUE)
  297. endif()
  298. if(X11_SM_LIB AND X11_SM_INCLUDE_PATH)
  299. set(X11_SM_FOUND TRUE)
  300. endif()
  301. # Most of the X11 headers will be in the same directories, avoid
  302. # creating a huge list of duplicates.
  303. if (X11_INCLUDE_DIR)
  304. list(REMOVE_DUPLICATES X11_INCLUDE_DIR)
  305. endif ()
  306. # Deprecated variable for backwards compatibility with CMake 1.4
  307. if (X11_X11_INCLUDE_PATH AND X11_LIBRARIES)
  308. set(X11_FOUND 1)
  309. endif ()
  310. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  311. find_package_handle_standard_args(X11
  312. REQUIRED_VARS X11_X11_INCLUDE_PATH X11_X11_LIB
  313. HANDLE_COMPONENTS)
  314. if(X11_FOUND)
  315. include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
  316. include(${CMAKE_CURRENT_LIST_DIR}/CheckLibraryExists.cmake)
  317. # Translated from an autoconf-generated configure script.
  318. # See libs.m4 in autoconf's m4 directory.
  319. if($ENV{ISC} MATCHES "^yes$")
  320. set(X11_X_EXTRA_LIBS -lnsl_s -linet)
  321. else()
  322. set(X11_X_EXTRA_LIBS "")
  323. # See if XOpenDisplay in X11 works by itself.
  324. check_library_exists("${X11_LIBRARIES}" "XOpenDisplay" "${X11_LIBRARY_DIR}" X11_LIB_X11_SOLO)
  325. if(NOT X11_LIB_X11_SOLO)
  326. # Find library needed for dnet_ntoa.
  327. check_library_exists("dnet" "dnet_ntoa" "" X11_LIB_DNET_HAS_DNET_NTOA)
  328. if (X11_LIB_DNET_HAS_DNET_NTOA)
  329. list(APPEND X11_X_EXTRA_LIBS -ldnet)
  330. else ()
  331. check_library_exists("dnet_stub" "dnet_ntoa" "" X11_LIB_DNET_STUB_HAS_DNET_NTOA)
  332. if (X11_LIB_DNET_STUB_HAS_DNET_NTOA)
  333. list(APPEND X11_X_EXTRA_LIBS -ldnet_stub)
  334. endif ()
  335. endif ()
  336. endif()
  337. # Find library needed for gethostbyname.
  338. check_function_exists("gethostbyname" CMAKE_HAVE_GETHOSTBYNAME)
  339. if(NOT CMAKE_HAVE_GETHOSTBYNAME)
  340. check_library_exists("nsl" "gethostbyname" "" CMAKE_LIB_NSL_HAS_GETHOSTBYNAME)
  341. if (CMAKE_LIB_NSL_HAS_GETHOSTBYNAME)
  342. list(APPEND X11_X_EXTRA_LIBS -lnsl)
  343. else ()
  344. check_library_exists("bsd" "gethostbyname" "" CMAKE_LIB_BSD_HAS_GETHOSTBYNAME)
  345. if (CMAKE_LIB_BSD_HAS_GETHOSTBYNAME)
  346. list(APPEND X11_X_EXTRA_LIBS -lbsd)
  347. endif ()
  348. endif ()
  349. endif()
  350. # Find library needed for connect.
  351. check_function_exists("connect" CMAKE_HAVE_CONNECT)
  352. if(NOT CMAKE_HAVE_CONNECT)
  353. check_library_exists("socket" "connect" "" CMAKE_LIB_SOCKET_HAS_CONNECT)
  354. if (CMAKE_LIB_SOCKET_HAS_CONNECT)
  355. list(INSERT X11_X_EXTRA_LIBS 0 -lsocket)
  356. endif ()
  357. endif()
  358. # Find library needed for remove.
  359. check_function_exists("remove" CMAKE_HAVE_REMOVE)
  360. if(NOT CMAKE_HAVE_REMOVE)
  361. check_library_exists("posix" "remove" "" CMAKE_LIB_POSIX_HAS_REMOVE)
  362. if (CMAKE_LIB_POSIX_HAS_REMOVE)
  363. list(APPEND X11_X_EXTRA_LIBS -lposix)
  364. endif ()
  365. endif()
  366. # Find library needed for shmat.
  367. check_function_exists("shmat" CMAKE_HAVE_SHMAT)
  368. if(NOT CMAKE_HAVE_SHMAT)
  369. check_library_exists("ipc" "shmat" "" CMAKE_LIB_IPS_HAS_SHMAT)
  370. if (CMAKE_LIB_IPS_HAS_SHMAT)
  371. list(APPEND X11_X_EXTRA_LIBS -lipc)
  372. endif ()
  373. endif()
  374. endif()
  375. if (X11_ICE_FOUND)
  376. check_library_exists("ICE" "IceConnectionNumber" "${X11_LIBRARY_DIR}"
  377. CMAKE_LIB_ICE_HAS_ICECONNECTIONNUMBER)
  378. if(CMAKE_LIB_ICE_HAS_ICECONNECTIONNUMBER)
  379. set (X11_X_PRE_LIBS ${X11_ICE_LIB})
  380. if(X11_SM_LIB)
  381. list(INSERT X11_X_PRE_LIBS 0 ${X11_SM_LIB})
  382. endif()
  383. endif()
  384. endif ()
  385. # Build the final list of libraries.
  386. set(X11_LIBRARIES ${X11_X_PRE_LIBS} ${X11_LIBRARIES} ${X11_X_EXTRA_LIBS})
  387. if (NOT TARGET X11::X11)
  388. add_library(X11::X11 UNKNOWN IMPORTED)
  389. set_target_properties(X11::X11 PROPERTIES
  390. IMPORTED_LOCATION "${X11_X11_LIB}"
  391. INTERFACE_INCLUDE_DIRECTORIES "${X11_X11_INCLUDE_PATH}")
  392. endif ()
  393. endif ()
  394. if (X11_ICE_FOUND AND NOT TARGET X11::ICE)
  395. add_library(X11::ICE UNKNOWN IMPORTED)
  396. set_target_properties(X11::ICE PROPERTIES
  397. IMPORTED_LOCATION "${X11_ICE_LIB}"
  398. INTERFACE_INCLUDE_DIRECTORIES "${X11_ICE_INCLUDE_PATH}")
  399. endif ()
  400. if (X11_SM_FOUND AND NOT TARGET X11::SM)
  401. add_library(X11::SM UNKNOWN IMPORTED)
  402. set_target_properties(X11::SM PROPERTIES
  403. IMPORTED_LOCATION "${X11_SM_LIB}"
  404. INTERFACE_INCLUDE_DIRECTORIES "${X11_SM_INCLUDE_PATH}")
  405. endif ()
  406. if (X11_Xau_FOUND AND NOT TARGET X11::Xau)
  407. add_library(X11::Xau UNKNOWN IMPORTED)
  408. set_target_properties(X11::Xau PROPERTIES
  409. IMPORTED_LOCATION "${X11_Xau_LIB}"
  410. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xau_INCLUDE_PATH}")
  411. endif ()
  412. if (X11_Xcomposite_FOUND AND NOT TARGET X11::Xcomposite)
  413. add_library(X11::Xcomposite UNKNOWN IMPORTED)
  414. set_target_properties(X11::Xcomposite PROPERTIES
  415. IMPORTED_LOCATION "${X11_Xcomposite_LIB}"
  416. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xcomposite_INCLUDE_PATH}"
  417. INTERFACE_LINK_LIBRARIES "X11::X11")
  418. endif ()
  419. if (X11_Xcursor_FOUND AND NOT TARGET X11::Xcursor)
  420. add_library(X11::Xcursor UNKNOWN IMPORTED)
  421. set_target_properties(X11::Xcursor PROPERTIES
  422. IMPORTED_LOCATION "${X11_Xcursor_LIB}"
  423. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xcursor_INCLUDE_PATH}"
  424. INTERFACE_LINK_LIBRARIES "X11::Xrender;X11::Xfixes;X11::X11")
  425. endif ()
  426. if (X11_Xdamage_FOUND AND NOT TARGET X11::Xdamage)
  427. add_library(X11::Xdamage UNKNOWN IMPORTED)
  428. set_target_properties(X11::Xdamage PROPERTIES
  429. IMPORTED_LOCATION "${X11_Xdamage_LIB}"
  430. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xdamage_INCLUDE_PATH}"
  431. INTERFACE_LINK_LIBRARIES "X11::Xfixes;X11::X11")
  432. endif ()
  433. if (X11_Xdmcp_FOUND AND NOT TARGET X11::Xdmcp)
  434. add_library(X11::Xdmcp UNKNOWN IMPORTED)
  435. set_target_properties(X11::Xdmcp PROPERTIES
  436. IMPORTED_LOCATION "${X11_Xdmcp_LIB}"
  437. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xdmcp_INCLUDE_PATH}")
  438. endif ()
  439. if (X11_Xext_FOUND AND NOT TARGET X11::Xext)
  440. add_library(X11::Xext UNKNOWN IMPORTED)
  441. set_target_properties(X11::Xext PROPERTIES
  442. IMPORTED_LOCATION "${X11_Xext_LIB}"
  443. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xext_INCLUDE_PATH}"
  444. INTERFACE_LINK_LIBRARIES "X11::X11")
  445. endif ()
  446. if (X11_Xxf86misc_FOUND AND NOT TARGET X11::Xxf86misc)
  447. add_library(X11::Xxf86misc UNKNOWN IMPORTED)
  448. set_target_properties(X11::Xxf86misc PROPERTIES
  449. IMPORTED_LOCATION "${X11_Xxf86misc_LIB}"
  450. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xxf86misc_INCLUDE_PATH}"
  451. INTERFACE_LINK_LIBRARIES "X11::X11;X11::Xext")
  452. endif ()
  453. if (X11_Xxf86vm_FOUND AND NOT TARGET X11::Xxf86vm)
  454. add_library(X11::Xxf86vm UNKNOWN IMPORTED)
  455. set_target_properties(X11::Xxf86vm PROPERTIES
  456. IMPORTED_LOCATION "${X11_Xxf86vm_LIB}"
  457. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xxf86vm_INCLUDE_PATH}"
  458. INTERFACE_LINK_LIBRARIES "X11::X11;X11::Xext")
  459. endif ()
  460. if (X11_Xfixes_FOUND AND NOT TARGET X11::Xfixes)
  461. add_library(X11::Xfixes UNKNOWN IMPORTED)
  462. set_target_properties(X11::Xfixes PROPERTIES
  463. IMPORTED_LOCATION "${X11_Xfixes_LIB}"
  464. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xfixes_INCLUDE_PATH}"
  465. INTERFACE_LINK_LIBRARIES "X11::X11")
  466. endif ()
  467. if (X11_Xft_FOUND AND NOT TARGET X11::Xft)
  468. add_library(X11::Xft UNKNOWN IMPORTED)
  469. set_target_properties(X11::Xft PROPERTIES
  470. IMPORTED_LOCATION "${X11_Xft_LIB}"
  471. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xft_INCLUDE_PATH}"
  472. INTERFACE_LINK_LIBRARIES "X11::Xrender;X11::X11;Fontconfig::Fontconfig;Freetype::Freetype")
  473. endif ()
  474. if (X11_Xi_FOUND AND NOT TARGET X11::Xi)
  475. add_library(X11::Xi UNKNOWN IMPORTED)
  476. set_target_properties(X11::Xi PROPERTIES
  477. IMPORTED_LOCATION "${X11_Xi_LIB}"
  478. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xi_INCLUDE_PATH}"
  479. INTERFACE_LINK_LIBRARIES "X11::Xext;X11::X11")
  480. endif ()
  481. if (X11_Xinerama_FOUND AND NOT TARGET X11::Xinerama)
  482. add_library(X11::Xinerama UNKNOWN IMPORTED)
  483. set_target_properties(X11::Xinerama PROPERTIES
  484. IMPORTED_LOCATION "${X11_Xinerama_LIB}"
  485. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xinerama_INCLUDE_PATH}"
  486. INTERFACE_LINK_LIBRARIES "X11::Xext;X11::X11")
  487. endif ()
  488. if (X11_Xkb_FOUND AND NOT TARGET X11::Xkb)
  489. add_library(X11::Xkb INTERFACE IMPORTED)
  490. set_target_properties(X11::Xkb PROPERTIES
  491. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xkb_INCLUDE_PATH}"
  492. INTERFACE_LINK_LIBRARIES "X11::X11")
  493. endif ()
  494. if (X11_xkbfile_FOUND AND NOT TARGET X11::xkbfile)
  495. add_library(X11::xkbfile UNKNOWN IMPORTED)
  496. set_target_properties(X11::xkbfile PROPERTIES
  497. IMPORTED_LOCATION "${X11_xkbfile_LIB}"
  498. INTERFACE_INCLUDE_DIRECTORIES "${X11_xkbfile_INCLUDE_PATH}"
  499. INTERFACE_LINK_LIBRARIES "X11::X11")
  500. endif ()
  501. if (X11_Xmu_FOUND AND NOT TARGET X11::Xmu)
  502. add_library(X11::Xmu UNKNOWN IMPORTED)
  503. set_target_properties(X11::Xmu PROPERTIES
  504. IMPORTED_LOCATION "${X11_Xmu_LIB}"
  505. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xmu_INCLUDE_PATH}"
  506. INTERFACE_LINK_LIBRARIES "X11::Xt;X11::Xext;X11::X11")
  507. endif ()
  508. if (X11_Xpm_FOUND AND NOT TARGET X11::Xpm)
  509. add_library(X11::Xpm UNKNOWN IMPORTED)
  510. set_target_properties(X11::Xpm PROPERTIES
  511. IMPORTED_LOCATION "${X11_Xpm_LIB}"
  512. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xpm_INCLUDE_PATH}"
  513. INTERFACE_LINK_LIBRARIES "X11::X11")
  514. endif ()
  515. if (X11_Xtst_FOUND AND NOT TARGET X11::Xtst)
  516. add_library(X11::Xtst UNKNOWN IMPORTED)
  517. set_target_properties(X11::Xtst PROPERTIES
  518. IMPORTED_LOCATION "${X11_Xtst_LIB}"
  519. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xtst_INCLUDE_PATH}"
  520. INTERFACE_LINK_LIBRARIES "X11::Xi;X11::Xext;X11::X11")
  521. endif ()
  522. if (X11_Xrandr_FOUND AND NOT TARGET X11::Xrandr)
  523. add_library(X11::Xrandr UNKNOWN IMPORTED)
  524. set_target_properties(X11::Xrandr PROPERTIES
  525. IMPORTED_LOCATION "${X11_Xrandr_LIB}"
  526. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xrandr_INCLUDE_PATH}"
  527. INTERFACE_LINK_LIBRARIES "X11::Xrender;X11::Xext;X11::X11")
  528. endif ()
  529. if (X11_Xrender_FOUND AND NOT TARGET X11::Xrender)
  530. add_library(X11::Xrender UNKNOWN IMPORTED)
  531. set_target_properties(X11::Xrender PROPERTIES
  532. IMPORTED_LOCATION "${X11_Xrender_LIB}"
  533. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xrender_INCLUDE_PATH}"
  534. INTERFACE_LINK_LIBRARIES "X11::X11")
  535. endif ()
  536. if (X11_XRes_FOUND AND NOT TARGET X11::XRes)
  537. add_library(X11::XRes UNKNOWN IMPORTED)
  538. set_target_properties(X11::XRes PROPERTIES
  539. IMPORTED_LOCATION "${X11_XRes_LIB}"
  540. INTERFACE_INCLUDE_DIRECTORIES "${X11_XRes_INCLUDE_PATH}"
  541. INTERFACE_LINK_LIBRARIES "X11::Xext;X11::X11")
  542. endif ()
  543. if (X11_Xss_FOUND AND NOT TARGET X11::Xss)
  544. add_library(X11::Xss UNKNOWN IMPORTED)
  545. set_target_properties(X11::Xss PROPERTIES
  546. IMPORTED_LOCATION "${X11_Xss_LIB}"
  547. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xss_INCLUDE_PATH}"
  548. INTERFACE_LINK_LIBRARIES "X11::Xext;X11::X11")
  549. endif ()
  550. if (X11_Xt_FOUND AND NOT TARGET X11::Xt)
  551. add_library(X11::Xt UNKNOWN IMPORTED)
  552. set_target_properties(X11::Xt PROPERTIES
  553. IMPORTED_LOCATION "${X11_Xt_LIB}"
  554. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xt_INCLUDE_PATH}"
  555. INTERFACE_LINK_LIBRARIES "X11::ICE;X11::SM;X11::X11")
  556. endif ()
  557. if (X11_Xutil_FOUND AND NOT TARGET X11::Xutil)
  558. add_library(X11::Xutil INTERFACE IMPORTED)
  559. set_target_properties(X11::Xutil PROPERTIES
  560. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xutil_INCLUDE_PATH}"
  561. # libX11 contains the implementations for functions in the Xutil.h
  562. # header.
  563. INTERFACE_LINK_LIBRARIES "X11::X11")
  564. endif ()
  565. if (X11_Xv_FOUND AND NOT TARGET X11::Xv)
  566. add_library(X11::Xv UNKNOWN IMPORTED)
  567. set_target_properties(X11::Xv PROPERTIES
  568. IMPORTED_LOCATION "${X11_Xv_LIB}"
  569. INTERFACE_INCLUDE_DIRECTORIES "${X11_Xv_INCLUDE_PATH}"
  570. INTERFACE_LINK_LIBRARIES "X11::Xext;X11::X11")
  571. endif ()
  572. mark_as_advanced(
  573. X11_X11_INCLUDE_PATH
  574. X11_X11_LIB
  575. X11_Xext_INCLUDE_PATH
  576. X11_Xext_LIB
  577. X11_Xau_LIB
  578. X11_Xau_INCLUDE_PATH
  579. X11_Xlib_INCLUDE_PATH
  580. X11_Xutil_INCLUDE_PATH
  581. X11_Xcomposite_INCLUDE_PATH
  582. X11_Xcomposite_LIB
  583. X11_Xfixes_LIB
  584. X11_Xfixes_INCLUDE_PATH
  585. X11_Xrandr_LIB
  586. X11_Xrandr_INCLUDE_PATH
  587. X11_Xdamage_LIB
  588. X11_Xdamage_INCLUDE_PATH
  589. X11_Xrender_LIB
  590. X11_Xrender_INCLUDE_PATH
  591. X11_XRes_LIB
  592. X11_XRes_INCLUDE_PATH
  593. X11_Xxf86misc_LIB
  594. X11_Xxf86misc_INCLUDE_PATH
  595. X11_Xxf86vm_LIB
  596. X11_Xxf86vm_INCLUDE_PATH
  597. X11_Xi_LIB
  598. X11_Xi_INCLUDE_PATH
  599. X11_Xinerama_LIB
  600. X11_Xinerama_INCLUDE_PATH
  601. X11_Xtst_LIB
  602. X11_Xtst_INCLUDE_PATH
  603. X11_Xcursor_LIB
  604. X11_Xcursor_INCLUDE_PATH
  605. X11_dpms_INCLUDE_PATH
  606. X11_Xt_LIB
  607. X11_Xt_INCLUDE_PATH
  608. X11_Xdmcp_LIB
  609. X11_LIBRARIES
  610. X11_Xaccessrules_INCLUDE_PATH
  611. X11_Xaccessstr_INCLUDE_PATH
  612. X11_Xdmcp_INCLUDE_PATH
  613. X11_Xkb_INCLUDE_PATH
  614. X11_Xkblib_INCLUDE_PATH
  615. X11_xkbfile_INCLUDE_PATH
  616. X11_xkbfile_LIB
  617. X11_Xmu_INCLUDE_PATH
  618. X11_Xmu_LIB
  619. X11_Xss_INCLUDE_PATH
  620. X11_Xss_LIB
  621. X11_Xpm_INCLUDE_PATH
  622. X11_Xpm_LIB
  623. X11_Xft_LIB
  624. X11_Xft_INCLUDE_PATH
  625. X11_Xshape_INCLUDE_PATH
  626. X11_Xv_LIB
  627. X11_Xv_INCLUDE_PATH
  628. X11_XShm_INCLUDE_PATH
  629. X11_ICE_LIB
  630. X11_ICE_INCLUDE_PATH
  631. X11_SM_LIB
  632. X11_SM_INCLUDE_PATH
  633. X11_XSync_INCLUDE_PATH
  634. )
  635. set(CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_SAVE})
  636. set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
  637. endif ()