FindNcursesw.cmake 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #.rst:
  2. # FindNcursesw
  3. # ------------
  4. #
  5. # Find the ncursesw (wide ncurses) include file and library.
  6. #
  7. # Based on FindCurses.cmake which comes with CMake.
  8. #
  9. # Checks for ncursesw first. If not found, it then executes the
  10. # regular old FindCurses.cmake to look for for ncurses (or curses).
  11. #
  12. #
  13. # Result Variables
  14. # ^^^^^^^^^^^^^^^^
  15. #
  16. # This module defines the following variables:
  17. #
  18. # ``CURSES_FOUND``
  19. # True if curses is found.
  20. # ``NCURSESW_FOUND``
  21. # True if ncursesw is found.
  22. # ``CURSES_INCLUDE_DIRS``
  23. # The include directories needed to use Curses.
  24. # ``CURSES_LIBRARIES``
  25. # The libraries needed to use Curses.
  26. # ``CURSES_HAVE_CURSES_H``
  27. # True if curses.h is available.
  28. # ``CURSES_HAVE_NCURSES_H``
  29. # True if ncurses.h is available.
  30. # ``CURSES_HAVE_NCURSES_NCURSES_H``
  31. # True if ``ncurses/ncurses.h`` is available.
  32. # ``CURSES_HAVE_NCURSES_CURSES_H``
  33. # True if ``ncurses/curses.h`` is available.
  34. # ``CURSES_HAVE_NCURSESW_NCURSES_H``
  35. # True if ``ncursesw/ncurses.h`` is available.
  36. # ``CURSES_HAVE_NCURSESW_CURSES_H``
  37. # True if ``ncursesw/curses.h`` is available.
  38. #
  39. # Set ``CURSES_NEED_NCURSES`` to ``TRUE`` before the
  40. # ``find_package(Ncursesw)`` call if NCurses functionality is required.
  41. #
  42. #=============================================================================
  43. # Copyright 2001-2014 Kitware, Inc.
  44. # modifications: Copyright 2015 kahrl <kahrl@gmx.net>
  45. #
  46. # Redistribution and use in source and binary forms, with or without
  47. # modification, are permitted provided that the following conditions
  48. # are met:
  49. #
  50. # * Redistributions of source code must retain the above copyright
  51. # notice, this list of conditions and the following disclaimer.
  52. #
  53. # * Redistributions in binary form must reproduce the above copyright
  54. # notice, this list of conditions and the following disclaimer in the
  55. # documentation and/or other materials provided with the distribution.
  56. #
  57. # * Neither the names of Kitware, Inc., the Insight Software Consortium,
  58. # nor the names of their contributors may be used to endorse or promote
  59. # products derived from this software without specific prior written
  60. # permission.
  61. #
  62. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  63. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  64. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  65. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  66. # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  67. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  68. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  69. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  70. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  71. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  72. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  73. #
  74. # ------------------------------------------------------------------------------
  75. #
  76. # The above copyright and license notice applies to distributions of
  77. # CMake in source and binary form. Some source files contain additional
  78. # notices of original copyright by their contributors; see each source
  79. # for details. Third-party software packages supplied with CMake under
  80. # compatible licenses provide their own copyright notices documented in
  81. # corresponding subdirectories.
  82. #
  83. # ------------------------------------------------------------------------------
  84. #
  85. # CMake was initially developed by Kitware with the following sponsorship:
  86. #
  87. # * National Library of Medicine at the National Institutes of Health
  88. # as part of the Insight Segmentation and Registration Toolkit (ITK).
  89. #
  90. # * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel
  91. # Visualization Initiative.
  92. #
  93. # * National Alliance for Medical Image Computing (NAMIC) is funded by the
  94. # National Institutes of Health through the NIH Roadmap for Medical Research,
  95. # Grant U54 EB005149.
  96. #
  97. # * Kitware, Inc.
  98. #=============================================================================
  99. include(CheckLibraryExists)
  100. find_library(CURSES_NCURSESW_LIBRARY NAMES ncursesw
  101. DOC "Path to libncursesw.so or .lib or .a")
  102. set(CURSES_USE_NCURSES FALSE)
  103. set(CURSES_USE_NCURSESW FALSE)
  104. if(CURSES_NCURSESW_LIBRARY)
  105. set(CURSES_USE_NCURSES TRUE)
  106. set(CURSES_USE_NCURSESW TRUE)
  107. endif()
  108. if(CURSES_USE_NCURSESW)
  109. get_filename_component(_cursesLibDir "${CURSES_NCURSESW_LIBRARY}" PATH)
  110. get_filename_component(_cursesParentDir "${_cursesLibDir}" PATH)
  111. find_path(CURSES_INCLUDE_PATH
  112. NAMES ncursesw/ncurses.h ncursesw/curses.h ncurses.h curses.h
  113. HINTS "${_cursesParentDir}/include"
  114. )
  115. # Previous versions of FindCurses provided these values.
  116. if(NOT DEFINED CURSES_LIBRARY)
  117. set(CURSES_LIBRARY "${CURSES_NCURSESW_LIBRARY}")
  118. endif()
  119. CHECK_LIBRARY_EXISTS("${CURSES_NCURSESW_LIBRARY}"
  120. cbreak "" CURSES_NCURSESW_HAS_CBREAK)
  121. if(NOT CURSES_NCURSESW_HAS_CBREAK)
  122. find_library(CURSES_EXTRA_LIBRARY tinfo HINTS "${_cursesLibDir}"
  123. DOC "Path to libtinfo.so or .lib or .a")
  124. find_library(CURSES_EXTRA_LIBRARY tinfo )
  125. endif()
  126. # Report whether each possible header name exists in the include directory.
  127. if(NOT DEFINED CURSES_HAVE_NCURSESW_NCURSES_H)
  128. if(EXISTS "${CURSES_INCLUDE_PATH}/ncursesw/ncurses.h")
  129. set(CURSES_HAVE_NCURSESW_NCURSES_H "${CURSES_INCLUDE_PATH}/ncursesw/ncurses.h")
  130. else()
  131. set(CURSES_HAVE_NCURSESW_NCURSES_H "CURSES_HAVE_NCURSESW_NCURSES_H-NOTFOUND")
  132. endif()
  133. endif()
  134. if(NOT DEFINED CURSES_HAVE_NCURSESW_CURSES_H)
  135. if(EXISTS "${CURSES_INCLUDE_PATH}/ncursesw/curses.h")
  136. set(CURSES_HAVE_NCURSESW_CURSES_H "${CURSES_INCLUDE_PATH}/ncursesw/curses.h")
  137. else()
  138. set(CURSES_HAVE_NCURSESW_CURSES_H "CURSES_HAVE_NCURSESW_CURSES_H-NOTFOUND")
  139. endif()
  140. endif()
  141. if(NOT DEFINED CURSES_HAVE_NCURSES_H)
  142. if(EXISTS "${CURSES_INCLUDE_PATH}/ncurses.h")
  143. set(CURSES_HAVE_NCURSES_H "${CURSES_INCLUDE_PATH}/ncurses.h")
  144. else()
  145. set(CURSES_HAVE_NCURSES_H "CURSES_HAVE_NCURSES_H-NOTFOUND")
  146. endif()
  147. endif()
  148. if(NOT DEFINED CURSES_HAVE_CURSES_H)
  149. if(EXISTS "${CURSES_INCLUDE_PATH}/curses.h")
  150. set(CURSES_HAVE_CURSES_H "${CURSES_INCLUDE_PATH}/curses.h")
  151. else()
  152. set(CURSES_HAVE_CURSES_H "CURSES_HAVE_CURSES_H-NOTFOUND")
  153. endif()
  154. endif()
  155. find_library(CURSES_FORM_LIBRARY form HINTS "${_cursesLibDir}"
  156. DOC "Path to libform.so or .lib or .a")
  157. find_library(CURSES_FORM_LIBRARY form )
  158. # Need to provide the *_LIBRARIES
  159. set(CURSES_LIBRARIES ${CURSES_LIBRARY})
  160. if(CURSES_EXTRA_LIBRARY)
  161. set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY})
  162. endif()
  163. if(CURSES_FORM_LIBRARY)
  164. set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY})
  165. endif()
  166. # Provide the *_INCLUDE_DIRS result.
  167. set(CURSES_INCLUDE_DIRS ${CURSES_INCLUDE_PATH})
  168. set(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH}) # compatibility
  169. # handle the QUIETLY and REQUIRED arguments and set CURSES_FOUND to TRUE if
  170. # all listed variables are TRUE
  171. include(FindPackageHandleStandardArgs)
  172. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ncursesw DEFAULT_MSG
  173. CURSES_LIBRARY CURSES_INCLUDE_PATH)
  174. set(CURSES_FOUND ${NCURSESW_FOUND})
  175. else()
  176. find_package(Curses)
  177. set(NCURSESW_FOUND FALSE)
  178. endif()
  179. mark_as_advanced(
  180. CURSES_INCLUDE_PATH
  181. CURSES_CURSES_LIBRARY
  182. CURSES_NCURSES_LIBRARY
  183. CURSES_NCURSESW_LIBRARY
  184. CURSES_EXTRA_LIBRARY
  185. CURSES_FORM_LIBRARY
  186. )