FIX: Write .build.cmake to correct directory
[freefoam.git] / CMake / Modules / FindReadline.cmake
blob8bb231d0aa123f0aad3cce3ea9ea110683400427
1 #-------------------------------------------------------------------------------
2 #               ______                _     ____          __  __
3 #              |  ____|             _| |_  / __ \   /\   |  \/  |
4 #              | |__ _ __ ___  ___ /     \| |  | | /  \  | \  / |
5 #              |  __| '__/ _ \/ _ ( (| |) ) |  | |/ /\ \ | |\/| |
6 #              | |  | | |  __/  __/\_   _/| |__| / ____ \| |  | |
7 #              |_|  |_|  \___|\___|  |_|   \____/_/    \_\_|  |_|
9 #                   FreeFOAM: The Cross-Platform CFD Toolkit
11 # Copyright (C) 2008-2011 Michael Wild <themiwi@users.sf.net>
12 #                         Gerber van der Graaf <gerber_graaf@users.sf.net>
13 #-------------------------------------------------------------------------------
14 # License
15 #   This file is part of FreeFOAM.
17 #   FreeFOAM is free software; you can redistribute it and/or modify it
18 #   under the terms of the GNU General Public License as published by the
19 #   Free Software Foundation; either version 2 of the License, or (at your
20 #   option) any later version.
22 #   FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
23 #   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 #   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25 #   for more details.
27 #   You should have received a copy of the GNU General Public License
28 #   along with FreeFOAM; if not, write to the Free Software Foundation,
29 #   Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #-------------------------------------------------------------------------------
32 # - Find Readline
34 # This module looks for readline support and defines the following values
35 #  READLINE_FOUND          TRUE if readline has been found
36 #  READLINE_INCLUDE_DIRS   include path for readline
37 #  READLINE_LIBRARIES      libraries to link against
39 # This module also checks whether linking against the readline library needs
40 # (n)curses or termcap and offers the user the choice between them with the
41 # variable READLINE_USE_CURSES. The default is OFF (use termcap).
43 include(CheckCSourceCompiles)
45 find_path(READLINE_INCLUDE_DIR readline/readline.h)
46 find_library(READLINE_LIBRARY readline)
48 mark_as_advanced(
49   READLINE_INCLUDE_DIR
50   READLINE_LIBRARY
51   )
53 set(_READLINE_VARS READLINE_LIBRARY READLINE_INCLUDE_DIR READLINE_WORKS)
55 if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
56   set(READLINE_INCLUDE_DIRS "${READLINE_INCLUDE_DIR}")
57   set(READLINE_LIBRARIES "${READLINE_LIBRARY}")
59   # check whether it needs to be linked against curses or termcap
60   set(_fr_CMAKE_REQUIRED_FLAGS_bak "${CMAKE_REQUIRED_FLAGS}")
61   set(_fr_CMAKE_REQUIRED_DEFINITIONS_bak "${CMAKE_REQUIRED_DEFINITIONS}")
62   set(_fr_CMAKE_REQUIRED_INCLUDES_bak "${CMAKE_REQUIRED_INCLUDES}")
63   set(_fr_CMAKE_REQUIRED_LIBRARIES_bak "${CMAKE_REQUIRED_LIBRARIES}")
65   set(CMAKE_REQUIRED_FLAGS)
66   set(CMAKE_REQUIRED_DEFINITIONS)
67   set(CMAKE_REQUIRED_INCLUDES "${READLINE_INCLUDE_DIR}")
68   set(CMAKE_REQUIRED_LIBRARIES "${READLINE_LIBRARY}")
69   set(READLINE_WORKS TRUE)
70   check_c_source_compiles("int main(){return 0;}" _READLINE_WORKS_STANDALONE)
72   if(NOT _READLINE_WORKS_STANDALONE)
73     set(READLINE_WORKS FALSE)
74     option(READLINE_USE_CURSES
75       "Use the curses library instead of the termcap library" OFF)
76     mark_as_advanced(READLINE_USE_CURSES)
77     if(READLINE_USE_CURSES)
78       find_package(Curses REQUIRED)
79       list(APPEND _READLINE_VARS CURSES_FOUND)
80       # check whether it works with curses
81       if(CURSES_FOUND)
82         set(CMAKE_REQUIRED_LIBRARIES "${READLINE_LIBRARY};${CURSES_LIBRARIES}")
83         check_c_source_compiles("int main(){return 0;}" _READLINE_WORKS_WITH_CURSES)
84         if(_READLINE_WORKS_WITH_CURSES)
85           set(READLINE_WORKS TRUE)
86           list(APPEND READLINE_LIBRARIES "${CURSES_LIBRARIES}")
87         endif()
88       endif()
89     else()
90       find_library(TERMCAP_LIBRARY termcap)
91       mark_as_advanced(TERMCAP_LIBRARY)
92       list(APPEND _READLINE_VARS TERMCAP_LIBRARY)
93       # check whether it works with termcap
94       if(TERMCAP_LIBRARY)
95         set(CMAKE_REQUIRED_LIBRARIES "${READLINE_LIBRARY};${TERMCAP_LIBRARY}")
96         check_c_source_compiles("int main(){return 0;}" _READLINE_WORKS_WITH_TERMCAP)
97         if(_READLINE_WORKS_WITH_TERMCAP)
98           set(READLINE_WORKS TRUE)
99           list(APPEND READLINE_LIBRARIES "${TERMCAP_LIBRARY}")
100         endif()
101       endif()
102     endif()
103   endif()
104   set(CMAKE_REQUIRED_FLAGS "${_fr_CMAKE_REQUIRED_FLAGS_bak}")
105   set(CMAKE_REQUIRED_DEFINITIONS "${_fr_CMAKE_REQUIRED_DEFINITIONS_bak}")
106   set(CMAKE_REQUIRED_INCLUDES "${_fr_CMAKE_REQUIRED_INCLUDES_bak}")
107   set(CMAKE_REQUIRED_LIBRARIES "${_fr_CMAKE_REQUIRED_LIBRARIES_bak}")
108 endif()
110 include(FindPackageHandleStandardArgs)
111 find_package_handle_standard_args(Readline DEFAULT_MSG ${_READLINE_VARS})
113 # ------------------------- vim: set sw=2 sts=2 et: --------------- end-of-file