Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / FindCurses.cmake
1 # - Find the curses include file and library
2 #
3 #  CURSES_FOUND - system has Curses
4 #  CURSES_INCLUDE_DIR - the Curses include directory
5 #  CURSES_LIBRARIES - The libraries needed to use Curses
6 #  CURSES_HAVE_CURSES_H - true if curses.h is available
7 #  CURSES_HAVE_NCURSES_H - true if ncurses.h is available
8 #  CURSES_HAVE_NCURSES_NCURSES_H - true if ncurses/ncurses.h is available
9 #  CURSES_HAVE_NCURSES_CURSES_H - true if ncurses/curses.h is available
10 #  CURSES_LIBRARY - set for backwards compatibility with 2.4 CMake
11 #
12 # Set CURSES_NEED_NCURSES to TRUE before the find_package() command if NCurses
13 # functionality is required.
14
15 #=============================================================================
16 # Copyright 2001-2009 Kitware, Inc.
17 #
18 # Distributed under the OSI-approved BSD License (the "License");
19 # see accompanying file Copyright.txt for details.
20 #
21 # This software is distributed WITHOUT ANY WARRANTY; without even the
22 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 # See the License for more information.
24 #=============================================================================
25 # (To distribute this file outside of CMake, substitute the full
26 #  License text for the above reference.)
27
28 find_library(CURSES_CURSES_LIBRARY NAMES curses )
29
30 find_library(CURSES_NCURSES_LIBRARY NAMES ncurses )
31 set(CURSES_USE_NCURSES FALSE)
32
33 if(CURSES_NCURSES_LIBRARY  AND NOT  CURSES_CURSES_LIBRARY)
34   set(CURSES_USE_NCURSES TRUE)
35 endif()
36 # http://cygwin.com/ml/cygwin-announce/2010-01/msg00002.html
37 # cygwin ncurses stopped providing curses.h symlinks see above
38 # message.  Cygwin is an ncurses package, so force ncurses on
39 # cygwin if the curses.h is missing
40 if(CYGWIN)
41   if(NOT EXISTS /usr/include/curses.h)
42     set(CURSES_USE_NCURSES TRUE)
43   endif()
44 endif()
45
46
47 # Not sure the logic is correct here.
48 # If NCurses is required, use the function wsyncup() to check if the library
49 # has NCurses functionality (at least this is where it breaks on NetBSD).
50 # If wsyncup is in curses, use this one.
51 # If not, try to find ncurses and check if this has the symbol.
52 # Once the ncurses library is found, search the ncurses.h header first, but
53 # some web pages also say that even with ncurses there is not always a ncurses.h:
54 # http://osdir.com/ml/gnome.apps.mc.devel/2002-06/msg00029.html
55 # So at first try ncurses.h, if not found, try to find curses.h under the same
56 # prefix as the library was found, if still not found, try curses.h with the
57 # default search paths.
58 if(CURSES_CURSES_LIBRARY  AND  CURSES_NEED_NCURSES)
59   include(CheckLibraryExists)
60   CHECK_LIBRARY_EXISTS("${CURSES_CURSES_LIBRARY}"
61     wsyncup "" CURSES_CURSES_HAS_WSYNCUP)
62
63   if(CURSES_NCURSES_LIBRARY  AND NOT  CURSES_CURSES_HAS_WSYNCUP)
64     CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}"
65       wsyncup "" CURSES_NCURSES_HAS_WSYNCUP)
66     if( CURSES_NCURSES_HAS_WSYNCUP)
67       set(CURSES_USE_NCURSES TRUE)
68     endif()
69   endif()
70
71 endif()
72
73
74 if(NOT CURSES_USE_NCURSES)
75   find_file(CURSES_HAVE_CURSES_H curses.h )
76   find_path(CURSES_CURSES_H_PATH curses.h )
77   get_filename_component(_cursesLibDir "${CURSES_CURSES_LIBRARY}" PATH)
78   get_filename_component(_cursesParentDir "${_cursesLibDir}" PATH)
79
80   # for compatibility with older FindCurses.cmake this has to be in the cache
81   # FORCE must not be used since this would break builds which preload a cache wqith these variables set
82   set(CURSES_INCLUDE_PATH "${CURSES_CURSES_H_PATH}"
83     CACHE FILEPATH "The curses include path")
84   set(CURSES_LIBRARY "${CURSES_CURSES_LIBRARY}"
85     CACHE FILEPATH "The curses library")
86 else()
87 # we need to find ncurses
88   get_filename_component(_cursesLibDir "${CURSES_NCURSES_LIBRARY}" PATH)
89   get_filename_component(_cursesParentDir "${_cursesLibDir}" PATH)
90
91   find_file(CURSES_HAVE_NCURSES_H         ncurses.h)
92   find_file(CURSES_HAVE_NCURSES_NCURSES_H ncurses/ncurses.h)
93   find_file(CURSES_HAVE_NCURSES_CURSES_H  ncurses/curses.h)
94   find_file(CURSES_HAVE_CURSES_H          curses.h
95     HINTS "${_cursesParentDir}/include")
96
97   find_path(CURSES_NCURSES_INCLUDE_PATH ncurses.h ncurses/ncurses.h
98     ncurses/curses.h)
99   find_path(CURSES_NCURSES_INCLUDE_PATH curses.h
100     HINTS "${_cursesParentDir}/include")
101
102   # for compatibility with older FindCurses.cmake this has to be in the cache
103   # FORCE must not be used since this would break builds which preload
104   # however if the value of the variable has NOTFOUND in it, then
105   # it is OK to force, and we need to force in order to have it work.
106   # a cache wqith these variables set
107   # only put ncurses include and library into
108   # variables if they are found
109   if(NOT CURSES_NCURSES_INCLUDE_PATH AND CURSES_HAVE_NCURSES_NCURSES_H)
110     get_filename_component(CURSES_NCURSES_INCLUDE_PATH
111       "${CURSES_HAVE_NCURSES_NCURSES_H}" PATH)
112   endif()
113   if(CURSES_NCURSES_INCLUDE_PATH AND CURSES_NCURSES_LIBRARY)
114     set( FORCE_IT )
115     if(CURSES_INCLUDE_PATH MATCHES NOTFOUND)
116       set(FORCE_IT FORCE)
117     endif()
118     set(CURSES_INCLUDE_PATH "${CURSES_NCURSES_INCLUDE_PATH}"
119       CACHE FILEPATH "The curses include path" ${FORCE_IT})
120     set( FORCE_IT)
121     if(CURSES_LIBRARY MATCHES NOTFOUND)
122       set(FORCE_IT FORCE)
123     endif()
124     set(CURSES_LIBRARY "${CURSES_NCURSES_LIBRARY}"
125       CACHE FILEPATH "The curses library" ${FORCE_IT})
126   endif()
127
128 endif()
129
130 find_library(CURSES_EXTRA_LIBRARY cur_colr HINTS "${_cursesLibDir}")
131 find_library(CURSES_EXTRA_LIBRARY cur_colr )
132
133 find_library(CURSES_FORM_LIBRARY form HINTS "${_cursesLibDir}")
134 find_library(CURSES_FORM_LIBRARY form )
135
136 # for compatibility with older FindCurses.cmake this has to be in the cache
137 # FORCE must not be used since this would break builds which preload a cache
138 # qith these variables set
139 set(FORM_LIBRARY "${CURSES_FORM_LIBRARY}"
140   CACHE FILEPATH "The curses form library")
141
142 # Need to provide the *_LIBRARIES
143 set(CURSES_LIBRARIES ${CURSES_LIBRARY})
144
145 if(CURSES_EXTRA_LIBRARY)
146   set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY})
147 endif()
148
149 if(CURSES_FORM_LIBRARY)
150   set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY})
151 endif()
152
153 # Proper name is *_INCLUDE_DIR
154 set(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH})
155
156 # handle the QUIETLY and REQUIRED arguments and set CURSES_FOUND to TRUE if
157 # all listed variables are TRUE
158 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
159 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Curses DEFAULT_MSG
160   CURSES_LIBRARY CURSES_INCLUDE_PATH)
161
162 mark_as_advanced(
163   CURSES_INCLUDE_PATH
164   CURSES_LIBRARY
165   CURSES_CURSES_INCLUDE_PATH
166   CURSES_CURSES_LIBRARY
167   CURSES_NCURSES_INCLUDE_PATH
168   CURSES_NCURSES_LIBRARY
169   CURSES_EXTRA_LIBRARY
170   FORM_LIBRARY
171   CURSES_LIBRARIES
172   CURSES_INCLUDE_DIR
173   CURSES_CURSES_HAS_WSYNCUP
174   CURSES_NCURSES_HAS_WSYNCUP
175   )
176