FindX11.cmake 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #
  2. # try to find X11 on UNIX systems.
  3. #
  4. # The following values are defined
  5. # X11_FOUND - True if X11 is available
  6. # X11_INCLUDE_DIR - include directories to use X11
  7. # X11_LIBRARIES - link against these to use X11
  8. IF (UNIX)
  9. SET(X11_FOUND 0)
  10. SET(X11_INC_SEARCH_PATH
  11. /usr/X11R6/include
  12. /usr/local/include
  13. /usr/include/X11
  14. /usr/openwin/include
  15. /usr/openwin/share/include
  16. /opt/graphics/OpenGL/include
  17. /usr/include
  18. )
  19. SET(X11_LIB_SEARCH_PATH
  20. /usr/X11R6/lib
  21. /usr/local/lib
  22. /usr/openwin/lib
  23. /usr/lib
  24. )
  25. FIND_PATH(X11_X11_INCLUDE_PATH X11/X.h ${X11_INC_SEARCH_PATH})
  26. FIND_PATH(X11_Xlib_INCLUDE_PATH X11/Xlib.h ${X11_INC_SEARCH_PATH})
  27. FIND_PATH(X11_Xutil_INCLUDE_PATH X11/Xutil.h ${X11_INC_SEARCH_PATH})
  28. FIND_LIBRARY(X11_X11_LIB X11 ${X11_LIB_SEARCH_PATH})
  29. FIND_LIBRARY(X11_Xext_LIB Xext ${X11_LIB_SEARCH_PATH})
  30. IF(X11_X11_INCLUDE_PATH)
  31. SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_X11_INCLUDE_PATH})
  32. ENDIF(X11_X11_INCLUDE_PATH)
  33. IF(X11_Xlib_INCLUDE_PATH)
  34. SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xlib_INCLUDE_PATH})
  35. ENDIF(X11_Xlib_INCLUDE_PATH)
  36. IF(X11_Xutil_INCLUDE_PATH)
  37. SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xutil_INCLUDE_PATH})
  38. ENDIF(X11_Xutil_INCLUDE_PATH)
  39. IF(X11_X11_LIB)
  40. SET(X11_LIBRARIES ${X11_LIBRARIES} ${X11_X11_LIB})
  41. ENDIF(X11_X11_LIB)
  42. IF(X11_Xext_LIB)
  43. SET(X11_LIBRARIES ${X11_LIBRARIES} ${X11_Xext_LIB})
  44. ENDIF(X11_Xext_LIB)
  45. # Deprecated variable for backwards compatibility with CMake 1.4
  46. IF(X11_X11_INCLUDE_PATH)
  47. IF(X11_LIBRARIES)
  48. SET(X11_FOUND 1)
  49. ENDIF(X11_LIBRARIES)
  50. ENDIF(X11_X11_INCLUDE_PATH)
  51. IF(X11_FOUND)
  52. INCLUDE(${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
  53. INCLUDE(${CMAKE_ROOT}/Modules/CheckLibraryExists.cmake)
  54. # Translated from an autoconf-generated configure script.
  55. # See libs.m4 in autoconf's m4 directory.
  56. IF($ENV{ISC} MATCHES "^yes$")
  57. SET(X11_X_EXTRA_LIBS -lnsl_s -linet)
  58. ELSE($ENV{ISC} MATCHES "^yes$")
  59. SET(X11_X_EXTRA_LIBS "")
  60. # See if XOpenDisplay in X11 works by itself.
  61. CHECK_LIBRARY_EXISTS("${X11_LIBRARIES}" "XOpenDisplay" "" X11_LIB_X11_SOLO)
  62. IF(NOT X11_LIB_X11_SOLO)
  63. # Find library needed for dnet_ntoa.
  64. CHECK_LIBRARY_EXISTS("dnet" "dnet_ntoa" "" X11_LIB_DNET_HAS_DNET_NTOA)
  65. IF (X11_LIB_DNET_HAS_DNET_NTOA)
  66. SET (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -ldnet)
  67. ELSE (X11_LIB_DNET_HAS_DNET_NTOA)
  68. CHECK_LIBRARY_EXISTS("dnet_stub" "dnet_ntoa" "" X11_LIB_DNET_STUB_HAS_DNET_NTOA)
  69. IF (X11_LIB_DNET_STUB_HAS_DNET_NTOA)
  70. SET (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -ldnet_stub)
  71. ENDIF (X11_LIB_DNET_STUB_HAS_DNET_NTOA)
  72. ENDIF (X11_LIB_DNET_HAS_DNET_NTOA)
  73. ENDIF(NOT X11_LIB_X11_SOLO)
  74. # Find library needed for gethostbyname.
  75. CHECK_FUNCTION_EXISTS("gethostbyname" CMAKE_HAVE_GETHOSTBYNAME)
  76. IF(NOT CMAKE_HAVE_GETHOSTBYNAME)
  77. CHECK_LIBRARY_EXISTS("nsl" "gethostbyname" "" CMAKE_LIB_NSL_HAS_GETHOSTBYNAME)
  78. IF (CMAKE_LIB_NSL_HAS_GETHOSTBYNAME)
  79. SET (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -lnsl)
  80. ELSE (CMAKE_LIB_NSL_HAS_GETHOSTBYNAME)
  81. CHECK_LIBRARY_EXISTS("bsd" "gethostbyname" "" CMAKE_LIB_BSD_HAS_GETHOSTBYNAME)
  82. IF (CMAKE_LIB_BSD_HAS_GETHOSTBYNAME)
  83. SET (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -lbsd)
  84. ENDIF (CMAKE_LIB_BSD_HAS_GETHOSTBYNAME)
  85. ENDIF (CMAKE_LIB_NSL_HAS_GETHOSTBYNAME)
  86. ENDIF(NOT CMAKE_HAVE_GETHOSTBYNAME)
  87. # Find library needed for connect.
  88. CHECK_FUNCTION_EXISTS("connect" CMAKE_HAVE_CONNECT)
  89. IF(NOT CMAKE_HAVE_CONNECT)
  90. CHECK_LIBRARY_EXISTS("socket" "connect" "" CMAKE_LIB_SOCKET_HAS_CONNECT)
  91. IF (CMAKE_LIB_SOCKET_HAS_CONNECT)
  92. SET (X11_X_EXTRA_LIBS -lsocket ${X11_X_EXTRA_LIBS})
  93. ENDIF (CMAKE_LIB_SOCKET_HAS_CONNECT)
  94. ENDIF(NOT CMAKE_HAVE_CONNECT)
  95. # Find library needed for remove.
  96. CHECK_FUNCTION_EXISTS("remove" CMAKE_HAVE_REMOVE)
  97. IF(NOT CMAKE_HAVE_REMOVE)
  98. CHECK_LIBRARY_EXISTS("posix" "remove" "" CMAKE_LIB_POSIX_HAS_REMOVE)
  99. IF (CMAKE_LIB_POSIX_HAS_REMOVE)
  100. SET (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -lposix)
  101. ENDIF (CMAKE_LIB_POSIX_HAS_REMOVE)
  102. ENDIF(NOT CMAKE_HAVE_REMOVE)
  103. # Find library needed for shmat.
  104. CHECK_FUNCTION_EXISTS("shmat" CMAKE_HAVE_SHMAT)
  105. IF(NOT CMAKE_HAVE_SHMAT)
  106. CHECK_LIBRARY_EXISTS("ipc" "shmat" "" CMAKE_LIB_IPS_HAS_SHMAT)
  107. IF (CMAKE_LIB_IPS_HAS_SHMAT)
  108. SET (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -lipc)
  109. ENDIF (CMAKE_LIB_IPS_HAS_SHMAT)
  110. ENDIF(NOT CMAKE_HAVE_SHMAT)
  111. ENDIF($ENV{ISC} MATCHES "^yes$")
  112. CHECK_LIBRARY_EXISTS("ICE" "IceConnectionNumber" ""
  113. CMAKE_LIB_ICE_HAS_ICECONNECTIONNUMBER)
  114. IF(CMAKE_LIB_ICE_HAS_ICECONNECTIONNUMBER)
  115. SET (X11_X_PRE_LIBS -lSM -lICE)
  116. ENDIF(CMAKE_LIB_ICE_HAS_ICECONNECTIONNUMBER)
  117. # Build the final list of libraries.
  118. SET (X11_LIBRARIES ${X11_X_PRE_LIBS} ${X11_LIBRARIES} ${X11_X_EXTRA_LIBS})
  119. ENDIF(X11_FOUND)
  120. MARK_AS_ADVANCED(
  121. X11_X11_INCLUDE_PATH
  122. X11_X11_LIB
  123. X11_Xext_LIB
  124. X11_Xlib_INCLUDE_PATH
  125. X11_Xutil_INCLUDE_PATH
  126. X11_LIBRARIES
  127. )
  128. ENDIF (UNIX)