FindCurses.cmake 4.5 KB

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