FindCurses.cmake 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #.rst:
  2. # FindCurses
  3. # ----------
  4. #
  5. # Find the curses or ncurses include file and library.
  6. #
  7. # Result Variables
  8. # ^^^^^^^^^^^^^^^^
  9. #
  10. # This module defines the following variables:
  11. #
  12. # ``CURSES_FOUND``
  13. # True if Curses is found.
  14. # ``CURSES_INCLUDE_DIRS``
  15. # The include directories needed to use Curses.
  16. # ``CURSES_LIBRARIES``
  17. # The libraries needed to use Curses.
  18. # ``CURSES_HAVE_CURSES_H``
  19. # True if curses.h is available.
  20. # ``CURSES_HAVE_NCURSES_H``
  21. # True if ncurses.h is available.
  22. # ``CURSES_HAVE_NCURSES_NCURSES_H``
  23. # True if ``ncurses/ncurses.h`` is available.
  24. # ``CURSES_HAVE_NCURSES_CURSES_H``
  25. # True if ``ncurses/curses.h`` is available.
  26. #
  27. # Set ``CURSES_NEED_NCURSES`` to ``TRUE`` before the
  28. # ``find_package(Curses)`` call if NCurses functionality is required.
  29. #
  30. # Backward Compatibility
  31. # ^^^^^^^^^^^^^^^^^^^^^^
  32. #
  33. # The following variable are provided for backward compatibility:
  34. #
  35. # ``CURSES_INCLUDE_DIR``
  36. # Path to Curses include. Use ``CURSES_INCLUDE_DIRS`` instead.
  37. # ``CURSES_LIBRARY``
  38. # Path to Curses library. Use ``CURSES_LIBRARIES`` instead.
  39. #=============================================================================
  40. # Copyright 2001-2014 Kitware, Inc.
  41. #
  42. # Distributed under the OSI-approved BSD License (the "License");
  43. # see accompanying file Copyright.txt for details.
  44. #
  45. # This software is distributed WITHOUT ANY WARRANTY; without even the
  46. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  47. # See the License for more information.
  48. #=============================================================================
  49. # (To distribute this file outside of CMake, substitute the full
  50. # License text for the above reference.)
  51. include(${CMAKE_CURRENT_LIST_DIR}/CheckLibraryExists.cmake)
  52. find_library(CURSES_CURSES_LIBRARY NAMES curses )
  53. find_library(CURSES_NCURSES_LIBRARY NAMES ncurses )
  54. set(CURSES_USE_NCURSES FALSE)
  55. if(CURSES_NCURSES_LIBRARY AND ((NOT CURSES_CURSES_LIBRARY) OR CURSES_NEED_NCURSES))
  56. set(CURSES_USE_NCURSES TRUE)
  57. endif()
  58. # http://cygwin.com/ml/cygwin-announce/2010-01/msg00002.html
  59. # cygwin ncurses stopped providing curses.h symlinks see above
  60. # message. Cygwin is an ncurses package, so force ncurses on
  61. # cygwin if the curses.h is missing
  62. if(CYGWIN)
  63. if(NOT EXISTS /usr/include/curses.h)
  64. set(CURSES_USE_NCURSES TRUE)
  65. endif()
  66. endif()
  67. # Not sure the logic is correct here.
  68. # If NCurses is required, use the function wsyncup() to check if the library
  69. # has NCurses functionality (at least this is where it breaks on NetBSD).
  70. # If wsyncup is in curses, use this one.
  71. # If not, try to find ncurses and check if this has the symbol.
  72. # Once the ncurses library is found, search the ncurses.h header first, but
  73. # some web pages also say that even with ncurses there is not always a ncurses.h:
  74. # http://osdir.com/ml/gnome.apps.mc.devel/2002-06/msg00029.html
  75. # So at first try ncurses.h, if not found, try to find curses.h under the same
  76. # prefix as the library was found, if still not found, try curses.h with the
  77. # default search paths.
  78. if(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES)
  79. include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
  80. cmake_push_check_state()
  81. set(CMAKE_REQUIRED_QUIET ${Curses_FIND_QUIETLY})
  82. CHECK_LIBRARY_EXISTS("${CURSES_CURSES_LIBRARY}"
  83. wsyncup "" CURSES_CURSES_HAS_WSYNCUP)
  84. if(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP)
  85. CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}"
  86. wsyncup "" CURSES_NCURSES_HAS_WSYNCUP)
  87. if( CURSES_NCURSES_HAS_WSYNCUP)
  88. set(CURSES_USE_NCURSES TRUE)
  89. endif()
  90. endif()
  91. cmake_pop_check_state()
  92. endif()
  93. if(CURSES_USE_NCURSES)
  94. get_filename_component(_cursesLibDir "${CURSES_NCURSES_LIBRARY}" PATH)
  95. get_filename_component(_cursesParentDir "${_cursesLibDir}" PATH)
  96. # Use CURSES_NCURSES_INCLUDE_PATH if set, for compatibility.
  97. if(CURSES_NCURSES_INCLUDE_PATH)
  98. find_path(CURSES_INCLUDE_PATH
  99. NAMES ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h
  100. PATHS ${CURSES_NCURSES_INCLUDE_PATH}
  101. NO_DEFAULT_PATH
  102. )
  103. endif()
  104. find_path(CURSES_INCLUDE_PATH
  105. NAMES ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h
  106. HINTS "${_cursesParentDir}/include"
  107. )
  108. # Previous versions of FindCurses provided these values.
  109. if(NOT DEFINED CURSES_LIBRARY)
  110. set(CURSES_LIBRARY "${CURSES_NCURSES_LIBRARY}")
  111. endif()
  112. CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}"
  113. cbreak "" CURSES_NCURSES_HAS_CBREAK)
  114. if(NOT CURSES_NCURSES_HAS_CBREAK)
  115. find_library(CURSES_EXTRA_LIBRARY tinfo HINTS "${_cursesLibDir}")
  116. find_library(CURSES_EXTRA_LIBRARY tinfo )
  117. endif()
  118. else()
  119. get_filename_component(_cursesLibDir "${CURSES_CURSES_LIBRARY}" PATH)
  120. get_filename_component(_cursesParentDir "${_cursesLibDir}" PATH)
  121. find_path(CURSES_INCLUDE_PATH
  122. NAMES curses.h
  123. HINTS "${_cursesParentDir}/include"
  124. )
  125. # Previous versions of FindCurses provided these values.
  126. if(NOT DEFINED CURSES_CURSES_H_PATH)
  127. set(CURSES_CURSES_H_PATH "${CURSES_INCLUDE_PATH}")
  128. endif()
  129. if(NOT DEFINED CURSES_LIBRARY)
  130. set(CURSES_LIBRARY "${CURSES_CURSES_LIBRARY}")
  131. endif()
  132. endif()
  133. # Report whether each possible header name exists in the include directory.
  134. if(NOT DEFINED CURSES_HAVE_NCURSES_NCURSES_H)
  135. if(EXISTS "${CURSES_INCLUDE_PATH}/ncurses/ncurses.h")
  136. set(CURSES_HAVE_NCURSES_NCURSES_H "${CURSES_INCLUDE_PATH}/ncurses/ncurses.h")
  137. else()
  138. set(CURSES_HAVE_NCURSES_NCURSES_H "CURSES_HAVE_NCURSES_NCURSES_H-NOTFOUND")
  139. endif()
  140. endif()
  141. if(NOT DEFINED CURSES_HAVE_NCURSES_CURSES_H)
  142. if(EXISTS "${CURSES_INCLUDE_PATH}/ncurses/curses.h")
  143. set(CURSES_HAVE_NCURSES_CURSES_H "${CURSES_INCLUDE_PATH}/ncurses/curses.h")
  144. else()
  145. set(CURSES_HAVE_NCURSES_CURSES_H "CURSES_HAVE_NCURSES_CURSES_H-NOTFOUND")
  146. endif()
  147. endif()
  148. if(NOT DEFINED CURSES_HAVE_NCURSES_H)
  149. if(EXISTS "${CURSES_INCLUDE_PATH}/ncurses.h")
  150. set(CURSES_HAVE_NCURSES_H "${CURSES_INCLUDE_PATH}/ncurses.h")
  151. else()
  152. set(CURSES_HAVE_NCURSES_H "CURSES_HAVE_NCURSES_H-NOTFOUND")
  153. endif()
  154. endif()
  155. if(NOT DEFINED CURSES_HAVE_CURSES_H)
  156. if(EXISTS "${CURSES_INCLUDE_PATH}/curses.h")
  157. set(CURSES_HAVE_CURSES_H "${CURSES_INCLUDE_PATH}/curses.h")
  158. else()
  159. set(CURSES_HAVE_CURSES_H "CURSES_HAVE_CURSES_H-NOTFOUND")
  160. endif()
  161. endif()
  162. find_library(CURSES_FORM_LIBRARY form HINTS "${_cursesLibDir}")
  163. find_library(CURSES_FORM_LIBRARY form )
  164. # Previous versions of FindCurses provided these values.
  165. if(NOT DEFINED FORM_LIBRARY)
  166. set(FORM_LIBRARY "${CURSES_FORM_LIBRARY}")
  167. endif()
  168. # Need to provide the *_LIBRARIES
  169. set(CURSES_LIBRARIES ${CURSES_LIBRARY})
  170. if(CURSES_EXTRA_LIBRARY)
  171. set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY})
  172. endif()
  173. if(CURSES_FORM_LIBRARY)
  174. set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY})
  175. endif()
  176. # Provide the *_INCLUDE_DIRS result.
  177. set(CURSES_INCLUDE_DIRS ${CURSES_INCLUDE_PATH})
  178. set(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH}) # compatibility
  179. # handle the QUIETLY and REQUIRED arguments and set CURSES_FOUND to TRUE if
  180. # all listed variables are TRUE
  181. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  182. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Curses DEFAULT_MSG
  183. CURSES_LIBRARY CURSES_INCLUDE_PATH)
  184. mark_as_advanced(
  185. CURSES_INCLUDE_PATH
  186. CURSES_CURSES_LIBRARY
  187. CURSES_NCURSES_LIBRARY
  188. CURSES_EXTRA_LIBRARY
  189. )