FindCurses.cmake 6.57 KB
Newer Older
1
# - Find the curses include file and library
Berk Geveci's avatar
Berk Geveci committed
2
#
3 4 5
#  CURSES_FOUND - system has Curses
#  CURSES_INCLUDE_DIR - the Curses include directory
#  CURSES_LIBRARIES - The libraries needed to use Curses
6 7 8 9
#  CURSES_HAVE_CURSES_H - true if curses.h is available
#  CURSES_HAVE_NCURSES_H - true if ncurses.h is available
#  CURSES_HAVE_NCURSES_NCURSES_H - true if ncurses/ncurses.h is available
#  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 14
# functionality is required.

15 16 17 18 19 20 21 22 23 24
#=============================================================================
# Copyright 2001-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
25
# (To distribute this file outside of CMake, substitute the full
26 27
#  License text for the above reference.)

28
find_library(CURSES_CURSES_LIBRARY NAMES curses )
29

30 31
find_library(CURSES_NCURSES_LIBRARY NAMES ncurses )
set(CURSES_USE_NCURSES FALSE)
32

33 34
if(CURSES_NCURSES_LIBRARY  AND NOT  CURSES_CURSES_LIBRARY)
  set(CURSES_USE_NCURSES TRUE)
35
endif()
36 37 38 39
# http://cygwin.com/ml/cygwin-announce/2010-01/msg00002.html
# cygwin ncurses stopped providing curses.h symlinks see above
# message.  Cygwin is an ncurses package, so force ncurses on
# cygwin if the curses.h is missing
40 41 42 43 44
if(CYGWIN)
  if(NOT EXISTS /usr/include/curses.h)
    set(CURSES_USE_NCURSES TRUE)
  endif()
endif()
45 46 47 48 49 50 51 52 53 54 55


# Not sure the logic is correct here.
# If NCurses is required, use the function wsyncup() to check if the library
# has NCurses functionality (at least this is where it breaks on NetBSD).
# If wsyncup is in curses, use this one.
# If not, try to find ncurses and check if this has the symbol.
# Once the ncurses library is found, search the ncurses.h header first, but
# some web pages also say that even with ncurses there is not always a ncurses.h:
# http://osdir.com/ml/gnome.apps.mc.devel/2002-06/msg00029.html
# 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(${CMAKE_CURRENT_LIST_DIR}/CheckLibraryExists.cmake)
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 67
    if( CURSES_NCURSES_HAS_WSYNCUP)
      set(CURSES_USE_NCURSES TRUE)
68 69
    endif()
  endif()
70

71
endif()
72 73


74 75 76 77 78
if(NOT CURSES_USE_NCURSES)
  find_file(CURSES_HAVE_CURSES_H curses.h )
  find_path(CURSES_CURSES_H_PATH curses.h )
  get_filename_component(_cursesLibDir "${CURSES_CURSES_LIBRARY}" PATH)
  get_filename_component(_cursesParentDir "${_cursesLibDir}" PATH)
Alexander Neundorf's avatar
Alexander Neundorf committed
79 80 81

  # for compatibility with older FindCurses.cmake this has to be in the cache
  # 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 89
  get_filename_component(_cursesLibDir "${CURSES_NCURSES_LIBRARY}" PATH)
  get_filename_component(_cursesParentDir "${_cursesLibDir}" PATH)
90

91 92 93 94
  find_file(CURSES_HAVE_NCURSES_H         ncurses.h)
  find_file(CURSES_HAVE_NCURSES_NCURSES_H ncurses/ncurses.h)
  find_file(CURSES_HAVE_NCURSES_CURSES_H  ncurses/curses.h)
  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")
Berk Geveci's avatar
Berk Geveci committed
101

Alexander Neundorf's avatar
Alexander Neundorf committed
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
Bill Hoffman's avatar
Bill Hoffman committed
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 110
  if(NOT CURSES_NCURSES_INCLUDE_PATH AND CURSES_HAVE_NCURSES_NCURSES_H)
    get_filename_component(CURSES_NCURSES_INCLUDE_PATH
Bill Hoffman's avatar
Bill Hoffman committed
111
      "${CURSES_HAVE_NCURSES_NCURSES_H}" PATH)
112
  endif()
113 114 115 116
  if(CURSES_NCURSES_INCLUDE_PATH AND CURSES_NCURSES_LIBRARY)
    set( FORCE_IT )
    if(CURSES_INCLUDE_PATH MATCHES NOTFOUND)
      set(FORCE_IT FORCE)
117
    endif()
118
    set(CURSES_INCLUDE_PATH "${CURSES_NCURSES_INCLUDE_PATH}"
Bill Hoffman's avatar
Bill Hoffman committed
119
      CACHE FILEPATH "The curses include path" ${FORCE_IT})
120 121 122
    set( FORCE_IT)
    if(CURSES_LIBRARY MATCHES NOTFOUND)
      set(FORCE_IT FORCE)
123
    endif()
124
    set(CURSES_LIBRARY "${CURSES_NCURSES_LIBRARY}"
Bill Hoffman's avatar
Bill Hoffman committed
125
      CACHE FILEPATH "The curses library" ${FORCE_IT})
126
  endif()
127

128
endif()
129

130 131
find_library(CURSES_EXTRA_LIBRARY cur_colr HINTS "${_cursesLibDir}")
find_library(CURSES_EXTRA_LIBRARY cur_colr )
132

133 134
find_library(CURSES_FORM_LIBRARY form HINTS "${_cursesLibDir}")
find_library(CURSES_FORM_LIBRARY form )
Berk Geveci's avatar
Berk Geveci committed
135

Alexander Neundorf's avatar
Alexander Neundorf committed
136
# for compatibility with older FindCurses.cmake this has to be in the cache
137 138
# FORCE must not be used since this would break builds which preload a cache
# qith these variables set
139
set(FORM_LIBRARY "${CURSES_FORM_LIBRARY}"
140
  CACHE FILEPATH "The curses form library")
Alexander Neundorf's avatar
Alexander Neundorf committed
141

Bill Hoffman's avatar
Bill Hoffman committed
142
# Need to provide the *_LIBRARIES
143
set(CURSES_LIBRARIES ${CURSES_LIBRARY})
Bill Hoffman's avatar
Bill Hoffman committed
144

145 146
if(CURSES_EXTRA_LIBRARY)
  set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY})
147
endif()
Bill Hoffman's avatar
Bill Hoffman committed
148

149 150
if(CURSES_FORM_LIBRARY)
  set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY})
151
endif()
Bill Hoffman's avatar
Bill Hoffman committed
152 153

# Proper name is *_INCLUDE_DIR
154
set(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH})
Bill Hoffman's avatar
Bill Hoffman committed
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 160
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Curses DEFAULT_MSG
  CURSES_LIBRARY CURSES_INCLUDE_PATH)
161

162
mark_as_advanced(
Bill Hoffman's avatar
Bill Hoffman committed
163 164
  CURSES_INCLUDE_PATH
  CURSES_LIBRARY
165
  CURSES_CURSES_INCLUDE_PATH
Alexander Neundorf's avatar
Alexander Neundorf committed
166
  CURSES_CURSES_LIBRARY
167 168
  CURSES_NCURSES_INCLUDE_PATH
  CURSES_NCURSES_LIBRARY
Bill Hoffman's avatar
Bill Hoffman committed
169 170 171 172
  CURSES_EXTRA_LIBRARY
  FORM_LIBRARY
  CURSES_LIBRARIES
  CURSES_INCLUDE_DIR
173 174
  CURSES_CURSES_HAS_WSYNCUP
  CURSES_NCURSES_HAS_WSYNCUP
Bill Hoffman's avatar
Bill Hoffman committed
175 176
  )