FindCurses.cmake 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 distributed 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. # Not sure the logic is correct here.
  33. # If NCurses is required, use the function wsyncup() to check if the library
  34. # has NCurses functionality (at least this is where it breaks on NetBSD).
  35. # If wsyncup is in curses, use this one.
  36. # If not, try to find ncurses and check if this has the symbol.
  37. # Once the ncurses library is found, search the ncurses.h header first, but
  38. # some web pages also say that even with ncurses there is not always a ncurses.h:
  39. # http://osdir.com/ml/gnome.apps.mc.devel/2002-06/msg00029.html
  40. # So at first try ncurses.h, if not found, try to find curses.h under the same
  41. # prefix as the library was found, if still not found, try curses.h with the
  42. # default search paths.
  43. IF(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES)
  44. INCLUDE(CheckLibraryExists)
  45. CHECK_LIBRARY_EXISTS("${CURSES_CURSES_LIBRARY}"
  46. wsyncup "" CURSES_CURSES_HAS_WSYNCUP)
  47. IF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP)
  48. CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}"
  49. wsyncup "" CURSES_NCURSES_HAS_WSYNCUP)
  50. IF( CURSES_NCURSES_HAS_WSYNCUP)
  51. SET(CURSES_USE_NCURSES TRUE)
  52. ENDIF( CURSES_NCURSES_HAS_WSYNCUP)
  53. ENDIF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP)
  54. ENDIF(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES)
  55. IF(NOT CURSES_USE_NCURSES)
  56. FIND_FILE(CURSES_HAVE_CURSES_H curses.h )
  57. FIND_PATH(CURSES_CURSES_H_PATH curses.h )
  58. GET_FILENAME_COMPONENT(_cursesLibDir "${CURSES_CURSES_LIBRARY}" PATH)
  59. GET_FILENAME_COMPONENT(_cursesParentDir "${_cursesLibDir}" PATH)
  60. # for compatibility with older FindCurses.cmake this has to be in the cache
  61. # FORCE must not be used since this would break builds which preload a cache wqith these variables set
  62. SET(CURSES_INCLUDE_PATH "${CURSES_CURSES_H_PATH}"
  63. CACHE FILEPATH "The curses include path")
  64. SET(CURSES_LIBRARY "${CURSES_CURSES_LIBRARY}"
  65. CACHE FILEPATH "The curses library")
  66. ELSE(NOT CURSES_USE_NCURSES)
  67. # we need to find ncurses
  68. GET_FILENAME_COMPONENT(_cursesLibDir "${CURSES_NCURSES_LIBRARY}" PATH)
  69. GET_FILENAME_COMPONENT(_cursesParentDir "${_cursesLibDir}" PATH)
  70. FIND_FILE(CURSES_HAVE_NCURSES_H ncurses.h)
  71. FIND_FILE(CURSES_HAVE_NCURSES_NCURSES_H ncurses/ncurses.h)
  72. FIND_FILE(CURSES_HAVE_NCURSES_CURSES_H ncurses/curses.h)
  73. FIND_FILE(CURSES_HAVE_CURSES_H curses.h
  74. HINTS "${_cursesParentDir}/include")
  75. FIND_PATH(CURSES_NCURSES_INCLUDE_PATH ncurses.h ncurses/ncurses.h
  76. ncurses/curses.h)
  77. FIND_PATH(CURSES_NCURSES_INCLUDE_PATH curses.h
  78. HINTS "${_cursesParentDir}/include")
  79. # for compatibility with older FindCurses.cmake this has to be in the cache
  80. # FORCE must not be used since this would break builds which preload
  81. # however if the value of the variable has NOTFOUND in it, then
  82. # it is OK to force, and we need to force in order to have it work.
  83. # a cache wqith these variables set
  84. # only put ncurses include and library into
  85. # variables if they are found
  86. IF(NOT CURSES_NCURSES_INCLUDE_PATH AND CURSES_HAVE_NCURSES_NCURSES_H)
  87. GET_FILENAME_COMPONENT(CURSES_NCURSES_INCLUDE_PATH
  88. "${CURSES_HAVE_NCURSES_NCURSES_H}" PATH)
  89. ENDIF(NOT CURSES_NCURSES_INCLUDE_PATH AND CURSES_HAVE_NCURSES_NCURSES_H)
  90. IF(CURSES_NCURSES_INCLUDE_PATH AND CURSES_NCURSES_LIBRARY)
  91. SET( FORCE_IT )
  92. IF(CURSES_INCLUDE_PATH MATCHES NOTFOUND)
  93. SET(FORCE_IT FORCE)
  94. ENDIF(CURSES_INCLUDE_PATH MATCHES NOTFOUND)
  95. SET(CURSES_INCLUDE_PATH "${CURSES_NCURSES_INCLUDE_PATH}"
  96. CACHE FILEPATH "The curses include path" ${FORCE_IT})
  97. SET( FORCE_IT)
  98. IF(CURSES_LIBRARY MATCHES NOTFOUND)
  99. SET(FORCE_IT FORCE)
  100. ENDIF(CURSES_LIBRARY MATCHES NOTFOUND)
  101. SET(CURSES_LIBRARY "${CURSES_NCURSES_LIBRARY}"
  102. CACHE FILEPATH "The curses library" ${FORCE_IT})
  103. ENDIF(CURSES_NCURSES_INCLUDE_PATH AND CURSES_NCURSES_LIBRARY)
  104. ENDIF(NOT CURSES_USE_NCURSES)
  105. FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr HINTS "${_cursesLibDir}")
  106. FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr )
  107. FIND_LIBRARY(CURSES_FORM_LIBRARY form HINTS "${_cursesLibDir}")
  108. FIND_LIBRARY(CURSES_FORM_LIBRARY form )
  109. # for compatibility with older FindCurses.cmake this has to be in the cache
  110. # FORCE must not be used since this would break builds which preload a cache
  111. # qith these variables set
  112. SET(FORM_LIBRARY "${CURSES_FORM_LIBRARY}"
  113. CACHE FILEPATH "The curses form library")
  114. # Need to provide the *_LIBRARIES
  115. SET(CURSES_LIBRARIES ${CURSES_LIBRARY})
  116. IF(CURSES_EXTRA_LIBRARY)
  117. SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY})
  118. ENDIF(CURSES_EXTRA_LIBRARY)
  119. IF(CURSES_FORM_LIBRARY)
  120. SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY})
  121. ENDIF(CURSES_FORM_LIBRARY)
  122. # Proper name is *_INCLUDE_DIR
  123. SET(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH})
  124. # handle the QUIETLY and REQUIRED arguments and set CURSES_FOUND to TRUE if
  125. # all listed variables are TRUE
  126. INCLUDE(FindPackageHandleStandardArgs)
  127. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Curses DEFAULT_MSG
  128. CURSES_LIBRARY CURSES_INCLUDE_PATH)
  129. MARK_AS_ADVANCED(
  130. CURSES_INCLUDE_PATH
  131. CURSES_LIBRARY
  132. CURSES_CURSES_INCLUDE_PATH
  133. CURSES_CURSES_LIBRARY
  134. CURSES_NCURSES_INCLUDE_PATH
  135. CURSES_NCURSES_LIBRARY
  136. CURSES_EXTRA_LIBRARY
  137. FORM_LIBRARY
  138. CURSES_LIBRARIES
  139. CURSES_INCLUDE_DIR
  140. CURSES_CURSES_HAS_WSYNCUP
  141. CURSES_NCURSES_HAS_WSYNCUP
  142. )