2 # try to find X11 on UNIX systems.
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
12 SET(X11_INC_SEARCH_PATH
17 /usr/openwin/share/include
18 /opt/graphics/OpenGL/include
22 SET(X11_LIB_SEARCH_PATH
29 FIND_PATH(X11_X11_INCLUDE_PATH X11/X.h ${X11_INC_SEARCH_PATH})
30 FIND_PATH(X11_Xlib_INCLUDE_PATH X11/Xlib.h ${X11_INC_SEARCH_PATH})
31 FIND_PATH(X11_Xutil_INCLUDE_PATH X11/Xutil.h ${X11_INC_SEARCH_PATH})
32 FIND_LIBRARY(X11_X11_LIB X11 ${X11_LIB_SEARCH_PATH})
33 FIND_LIBRARY(X11_Xext_LIB Xext ${X11_LIB_SEARCH_PATH})
35 IF(X11_X11_INCLUDE_PATH)
36 SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_X11_INCLUDE_PATH})
37 ENDIF(X11_X11_INCLUDE_PATH)
39 IF(X11_Xlib_INCLUDE_PATH)
40 SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xlib_INCLUDE_PATH})
41 ENDIF(X11_Xlib_INCLUDE_PATH)
43 IF(X11_Xutil_INCLUDE_PATH)
44 SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xutil_INCLUDE_PATH})
45 ENDIF(X11_Xutil_INCLUDE_PATH)
48 SET(X11_LIBRARIES ${X11_LIBRARIES} ${X11_X11_LIB})
52 SET(X11_LIBRARIES ${X11_LIBRARIES} ${X11_Xext_LIB})
55 # Deprecated variable for backwards compatibility with CMake 1.4
56 IF(X11_X11_INCLUDE_PATH)
60 ENDIF(X11_X11_INCLUDE_PATH)
62 SET(X11_LIBRARY_DIR "")
64 GET_FILENAME_COMPONENT(X11_LIBRARY_DIR ${X11_X11_LIB} PATH)
68 INCLUDE(CheckFunctionExists)
69 INCLUDE(CheckLibraryExists)
71 # Translated from an autoconf-generated configure script.
72 # See libs.m4 in autoconf's m4 directory.
73 IF($ENV{ISC} MATCHES "^yes$")
74 SET(X11_X_EXTRA_LIBS -lnsl_s -linet)
75 ELSE($ENV{ISC} MATCHES "^yes$")
76 SET(X11_X_EXTRA_LIBS "")
78 # See if XOpenDisplay in X11 works by itself.
79 CHECK_LIBRARY_EXISTS("${X11_LIBRARIES}" "XOpenDisplay" "${X11_LIBRARY_DIR}" X11_LIB_X11_SOLO)
80 IF(NOT X11_LIB_X11_SOLO)
81 # Find library needed for dnet_ntoa.
82 CHECK_LIBRARY_EXISTS("dnet" "dnet_ntoa" "" X11_LIB_DNET_HAS_DNET_NTOA)
83 IF (X11_LIB_DNET_HAS_DNET_NTOA)
84 SET (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -ldnet)
85 ELSE (X11_LIB_DNET_HAS_DNET_NTOA)
86 CHECK_LIBRARY_EXISTS("dnet_stub" "dnet_ntoa" "" X11_LIB_DNET_STUB_HAS_DNET_NTOA)
87 IF (X11_LIB_DNET_STUB_HAS_DNET_NTOA)
88 SET (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -ldnet_stub)
89 ENDIF (X11_LIB_DNET_STUB_HAS_DNET_NTOA)
90 ENDIF (X11_LIB_DNET_HAS_DNET_NTOA)
91 ENDIF(NOT X11_LIB_X11_SOLO)
93 # Find library needed for gethostbyname.
94 CHECK_FUNCTION_EXISTS("gethostbyname" CMAKE_HAVE_GETHOSTBYNAME)
95 IF(NOT CMAKE_HAVE_GETHOSTBYNAME)
96 CHECK_LIBRARY_EXISTS("nsl" "gethostbyname" "" CMAKE_LIB_NSL_HAS_GETHOSTBYNAME)
97 IF (CMAKE_LIB_NSL_HAS_GETHOSTBYNAME)
98 SET (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -lnsl)
99 ELSE (CMAKE_LIB_NSL_HAS_GETHOSTBYNAME)
100 CHECK_LIBRARY_EXISTS("bsd" "gethostbyname" "" CMAKE_LIB_BSD_HAS_GETHOSTBYNAME)
101 IF (CMAKE_LIB_BSD_HAS_GETHOSTBYNAME)
102 SET (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -lbsd)
103 ENDIF (CMAKE_LIB_BSD_HAS_GETHOSTBYNAME)
104 ENDIF (CMAKE_LIB_NSL_HAS_GETHOSTBYNAME)
105 ENDIF(NOT CMAKE_HAVE_GETHOSTBYNAME)
107 # Find library needed for connect.
108 CHECK_FUNCTION_EXISTS("connect" CMAKE_HAVE_CONNECT)
109 IF(NOT CMAKE_HAVE_CONNECT)
110 CHECK_LIBRARY_EXISTS("socket" "connect" "" CMAKE_LIB_SOCKET_HAS_CONNECT)
111 IF (CMAKE_LIB_SOCKET_HAS_CONNECT)
112 SET (X11_X_EXTRA_LIBS -lsocket ${X11_X_EXTRA_LIBS})
113 ENDIF (CMAKE_LIB_SOCKET_HAS_CONNECT)
114 ENDIF(NOT CMAKE_HAVE_CONNECT)
116 # Find library needed for remove.
117 CHECK_FUNCTION_EXISTS("remove" CMAKE_HAVE_REMOVE)
118 IF(NOT CMAKE_HAVE_REMOVE)
119 CHECK_LIBRARY_EXISTS("posix" "remove" "" CMAKE_LIB_POSIX_HAS_REMOVE)
120 IF (CMAKE_LIB_POSIX_HAS_REMOVE)
121 SET (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -lposix)
122 ENDIF (CMAKE_LIB_POSIX_HAS_REMOVE)
123 ENDIF(NOT CMAKE_HAVE_REMOVE)
125 # Find library needed for shmat.
126 CHECK_FUNCTION_EXISTS("shmat" CMAKE_HAVE_SHMAT)
127 IF(NOT CMAKE_HAVE_SHMAT)
128 CHECK_LIBRARY_EXISTS("ipc" "shmat" "" CMAKE_LIB_IPS_HAS_SHMAT)
129 IF (CMAKE_LIB_IPS_HAS_SHMAT)
130 SET (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -lipc)
131 ENDIF (CMAKE_LIB_IPS_HAS_SHMAT)
132 ENDIF(NOT CMAKE_HAVE_SHMAT)
133 ENDIF($ENV{ISC} MATCHES "^yes$")
135 CHECK_LIBRARY_EXISTS("ICE" "IceConnectionNumber" "${X11_LIBRARY_DIR}"
136 CMAKE_LIB_ICE_HAS_ICECONNECTIONNUMBER)
137 IF(CMAKE_LIB_ICE_HAS_ICECONNECTIONNUMBER)
138 SET (X11_X_PRE_LIBS -lSM -lICE)
139 ENDIF(CMAKE_LIB_ICE_HAS_ICECONNECTIONNUMBER)
140 # Build the final list of libraries.
141 SET (X11_LIBRARIES ${X11_X_PRE_LIBS} ${X11_LIBRARIES} ${X11_X_EXTRA_LIBS})
148 X11_Xlib_INCLUDE_PATH
149 X11_Xutil_INCLUDE_PATH