FindCurses.cmake 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. FIND_LIBRARY(CURSES_CURSES_LIBRARY NAMES curses )
  15. FIND_LIBRARY(CURSES_NCURSES_LIBRARY NAMES ncurses )
  16. SET(CURSES_USE_NCURSES FALSE)
  17. IF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_LIBRARY)
  18. SET(CURSES_USE_NCURSES TRUE)
  19. ENDIF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_LIBRARY)
  20. # Not sure the logic is correct here.
  21. # If NCurses is required, use the function wsyncup() to check if the library
  22. # has NCurses functionality (at least this is where it breaks on NetBSD).
  23. # If wsyncup is in curses, use this one.
  24. # If not, try to find ncurses and check if this has the symbol.
  25. # Once the ncurses library is found, search the ncurses.h header first, but
  26. # some web pages also say that even with ncurses there is not always a ncurses.h:
  27. # http://osdir.com/ml/gnome.apps.mc.devel/2002-06/msg00029.html
  28. # So at first try ncurses.h, if not found, try to find curses.h under the same
  29. # prefix as the library was found, if still not found, try curses.h with the
  30. # default search paths.
  31. IF(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES)
  32. INCLUDE(CheckLibraryExists)
  33. CHECK_LIBRARY_EXISTS("${CURSES_CURSES_LIBRARY}" wsyncup "" CURSES_CURSES_HAS_WSYNCUP)
  34. IF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP)
  35. CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}" wsyncup "" CURSES_NCURSES_HAS_WSYNCUP)
  36. IF( CURSES_NCURSES_HAS_WSYNCUP)
  37. SET(CURSES_USE_NCURSES TRUE)
  38. ENDIF( CURSES_NCURSES_HAS_WSYNCUP)
  39. ENDIF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP)
  40. ENDIF(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES)
  41. IF(NOT CURSES_USE_NCURSES)
  42. FIND_FILE(CURSES_HAVE_CURSES_H curses.h )
  43. FIND_PATH(CURSES_CURSES_H_PATH curses.h )
  44. GET_FILENAME_COMPONENT(_cursesLibDir "${CURSES_CURSES_LIBRARY}" PATH)
  45. GET_FILENAME_COMPONENT(_cursesParentDir "${_cursesLibDir}" PATH)
  46. # for compatibility with older FindCurses.cmake this has to be in the cache
  47. # FORCE must not be used since this would break builds which preload a cache wqith these variables set
  48. SET(CURSES_INCLUDE_PATH "${CURSES_CURSES_H_PATH}" CACHE FILEPATH "The curses include path")
  49. SET(CURSES_LIBRARY "${CURSES_CURSES_LIBRARY}" CACHE FILEPATH "The curses library")
  50. ELSE(NOT CURSES_USE_NCURSES)
  51. # we need to find ncurses
  52. GET_FILENAME_COMPONENT(_cursesLibDir "${CURSES_NCURSES_LIBRARY}" PATH)
  53. GET_FILENAME_COMPONENT(_cursesParentDir "${_cursesLibDir}" PATH)
  54. FIND_FILE(CURSES_HAVE_NCURSES_H ncurses.h)
  55. FIND_FILE(CURSES_HAVE_NCURSES_NCURSES_H ncurses/ncurses.h)
  56. FIND_FILE(CURSES_HAVE_NCURSES_CURSES_H ncurses/curses.h)
  57. FIND_FILE(CURSES_HAVE_CURSES_H curses.h HINTS "${_cursesParentDir}/include")
  58. FIND_PATH(CURSES_NCURSES_INCLUDE_PATH ncurses.h ncurses/ncurses.h ncurses/curses.h)
  59. FIND_PATH(CURSES_NCURSES_INCLUDE_PATH curses.h HINTS "${_cursesParentDir}/include")
  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_NCURSES_INCLUDE_PATH}" CACHE FILEPATH "The curses include path")
  63. SET(CURSES_LIBRARY "${CURSES_NCURSES_LIBRARY}" CACHE FILEPATH "The curses library")
  64. ENDIF(NOT CURSES_USE_NCURSES)
  65. FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr HINTS "${_cursesLibDir}")
  66. FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr )
  67. FIND_LIBRARY(CURSES_FORM_LIBRARY form HINTS "${_cursesLibDir}")
  68. FIND_LIBRARY(CURSES_FORM_LIBRARY form )
  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(FORM_LIBRARY "${CURSES_FORM_LIBRARY}" CACHE FILEPATH "The curses form library")
  72. # Need to provide the *_LIBRARIES
  73. SET(CURSES_LIBRARIES ${CURSES_LIBRARY})
  74. IF(CURSES_EXTRA_LIBRARY)
  75. SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY})
  76. ENDIF(CURSES_EXTRA_LIBRARY)
  77. IF(CURSES_FORM_LIBRARY)
  78. SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY})
  79. ENDIF(CURSES_FORM_LIBRARY)
  80. # Proper name is *_INCLUDE_DIR
  81. SET(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH})
  82. # handle the QUIETLY and REQUIRED arguments and set CURSES_FOUND to TRUE if
  83. # all listed variables are TRUE
  84. INCLUDE(FindPackageHandleStandardArgs)
  85. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Curses DEFAULT_MSG CURSES_LIBRARY CURSES_INCLUDE_PATH)
  86. MARK_AS_ADVANCED(
  87. CURSES_INCLUDE_PATH
  88. CURSES_LIBRARY
  89. CURSES_CURSES_INCLUDE_PATH
  90. CURSES_CURSES_LIBRARY
  91. CURSES_NCURSES_INCLUDE_PATH
  92. CURSES_NCURSES_LIBRARY
  93. CURSES_EXTRA_LIBRARY
  94. FORM_LIBRARY
  95. CURSES_LIBRARIES
  96. CURSES_INCLUDE_DIR
  97. CURSES_CURSES_HAS_WSYNCUP
  98. CURSES_NCURSES_HAS_WSYNCUP
  99. )