FindCurses.cmake 7.0 KB

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