summaryrefslogtreecommitdiffstats
path: root/Modules/FindX11.cmake
blob: 05e4d5937e1fc53ab3cdd7c8f3514750536b5f5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#
# try to find X11 on UNIX systems.
#
# The following values are defined
# CMAKE_X11_INCLUDE_PATH  - where to find X11.h
# CMAKE_X_LIBS            - link against these to use X11
# CMAKE_HAS_X             - True if X11 is available
# CMAKE_X11_LIBDIR        - Directory with X11 library
# CMAKE_Xext_LIBDIR       - Directory with Xext library

IF (UNIX)
  SET(CMAKE_X_PRE_LIBS "")
  SET(CMAKE_X_REAL_LIBS "")
  SET(CMAKE_X_EXTRA_LIBS "")
  SET(CMAKE_X_EXTRA_LIBS "")
  SET(CMAKE_HAS_X 0)
  
  FIND_PATH(CMAKE_X11_INCLUDE_PATH X11/X.h
    /usr/include 
    /usr/local/include 
    /usr/openwin/include 
    /usr/openwin/share/include 
    /usr/X11R6/include 
    /usr/include/X11
    /opt/graphics/OpenGL/include
  )

  FIND_PATH(CMAKE_Xlib_INCLUDE_PATH X11/Xlib.h
    /usr/include 
    /usr/local/include 
    /usr/openwin/include 
    /usr/openwin/share/include 
    /usr/X11R6/include 
    /usr/include/X11
    /opt/graphics/OpenGL/include
  )

  FIND_PATH(CMAKE_Xutil_INCLUDE_PATH X11/Xutil.h
    /usr/include 
    /usr/local/include 
    /usr/openwin/include 
    /usr/openwin/share/include 
    /usr/X11R6/include 
    /usr/include/X11
    /opt/graphics/OpenGL/include
  )

  IF(CMAKE_X11_INCLUDE_PATH)
    SET(CMAKE_X11_INCLUDES "${CMAKE_X11_INCLUDES};${CMAKE_X11_INCLUDE_PATH}")
  ENDIF(CMAKE_X11_INCLUDE_PATH)
  IF(CMAKE_Xlib_INCLUDE_PATH)
    SET(CMAKE_X11_INCLUDES "${CMAKE_X11_INCLUDES};${CMAKE_Xlib_INCLUDE_PATH}")
  ENDIF(CMAKE_Xlib_INCLUDE_PATH)
  IF(CMAKE_Xutil_INCLUDE_PATH)
    SET(CMAKE_X11_INCLUDES "${CMAKE_X11_INCLUDES};${CMAKE_Xutil_INCLUDE_PATH}")
  ENDIF(CMAKE_Xutil_INCLUDE_PATH)

  FIND_LIBRARY(CMAKE_X11_LIBDIR X11
    /usr/lib 
    /usr/local/lib 
    /usr/openwin/lib 
    /usr/X11R6/lib
  )

  FIND_LIBRARY(CMAKE_Xext_LIBDIR Xext
    /usr/lib 
    /usr/local/lib 
    /usr/openwin/lib 
    /usr/X11R6/lib
  )

  IF(CMAKE_X11_INCLUDE_PATH)

    IF(CMAKE_X11_LIBDIR)
      SET( CMAKE_X_LIBS "${CMAKE_X_LIBS};${CMAKE_X11_LIBDIR}" )
    ENDIF(CMAKE_X11_LIBDIR)

    IF(CMAKE_Xext_LIBDIR)
      SET( CMAKE_X_LIBS "${CMAKE_X_LIBS};${CMAKE_Xext_LIBDIR}" )
    ENDIF(CMAKE_Xext_LIBDIR)

  ENDIF(CMAKE_X11_INCLUDE_PATH)

  # Deprecated variable fro backwards compatibility with CMake 1.4
  IF(CMAKE_X11_INCLUDE_PATH)
    IF(CMAKE_X_LIBS)
      SET(CMAKE_HAS_X 1)
    ENDIF(CMAKE_X_LIBS)
  ENDIF(CMAKE_X11_INCLUDE_PATH)
  IF(CMAKE_HAS_X)
    INCLUDE (${CMAKE_ROOT}/Modules/CheckLibraryExists.cmake)
    CHECK_LIBRARY_EXISTS("nsl" "gethostbyname" "" CMAKE_HAVE_GETHOSTBYNAME) 
    IF (CMAKE_HAVE_GETHOSTBYNAME)
      SET (CMAKE_X_EXTRA_LIBS "${CMAKE_X_EXTRA_LIBS};-lnsl")
    ENDIF (CMAKE_HAVE_GETHOSTBYNAME)
    CHECK_LIBRARY_EXISTS("socket" "connect" "" CMAKE_HAVE_SOCKET_LIBRARY)
    IF (CMAKE_HAVE_SOCKET_LIBRARY)
      SET (CMAKE_X_EXTRA_LIBS "${CMAKE_X_EXTRA_LIBS};-lsocket")
    ENDIF (CMAKE_HAVE_SOCKET_LIBRARY)
    SET (CMAKE_X_LIBS "${CMAKE_X_PRE_LIBS};${CMAKE_X_LIBS};${CMAKE_X_EXTRA_LIBS}" 
         CACHE STRING 
         "Libraries and options used in X11 programs.")

    SET (CMAKE_X_CFLAGS           "${CMAKE_X_CFLAGS}" CACHE STRING 
         "X11 extra flags.")
  ENDIF(CMAKE_HAS_X)
  SET (CMAKE_HAS_X ${CMAKE_HAS_X} CACHE INTERNAL "Is X11 around.")
  MARK_AS_ADVANCED(
    CMAKE_X11_INCLUDE_PATH
    CMAKE_X11_LIBDIR
    CMAKE_Xext_LIBDIR
    CMAKE_Xlib_INCLUDE_PATH
    CMAKE_Xutil_INCLUDE_PATH
    )

ENDIF (UNIX)