Curses support across platforms!

develop
Petr Mrázek 2011-05-21 20:32:53 +02:00
parent 909cd8b60b
commit bb99924b24
11 changed files with 1511 additions and 206 deletions

@ -1,177 +1,23 @@
# - Find the curses include file and library
#
# CURSES_FOUND - system has Curses
# CURSES_INCLUDE_DIR - the Curses include directory
# CURSES_LIBRARIES - The libraries needed to use Curses
# CURSES_HAVE_CURSES_H - true if curses.h is available
# CURSES_HAVE_NCURSES_H - true if ncurses.h is available
# CURSES_HAVE_NCURSES_NCURSES_H - true if ncurses/ncurses.h is available
# CURSES_HAVE_NCURSES_CURSES_H - true if ncurses/curses.h is available
# CURSES_LIBRARY - set for backwards compatibility with 2.4 CMake
#
# Set CURSES_NEED_NCURSES to TRUE before the FIND_PACKAGE() command if NCurses
# functionality is required.
IF(Curses_FOUND)
SET(Curses_FIND_QUIETLY TRUE)
ENDIF()
# Set CURSES_NEED_WIDE to TRUE before the FIND_PACKAGE() command if unicode
# functionality is required
FIND_PATH(Curses_INCLUDE_PATH
NAMES ncurses.h curses.h
PATH_SUFFIXES ncurses
PATHS /usr/include /usr/local/include /usr/pkg/include
)
SET(CURSES_LIBRARY_NAME "curses")
SET(NCURSES_LIBRARY_NAME "ncurses")
IF(CURSES_NEED_WIDE)
SET(CURSES_LIBRARY_NAME "cursesw")
SET(NCURSES_LIBRARY_NAME "ncursesw")
ENDIF(CURSES_NEED_WIDE)
FIND_LIBRARY(Curses_LIBRARY
NAMES ncursesw
PATHS /lib /usr/lib /usr/local/lib /usr/pkg/lib
)
FIND_LIBRARY(CURSES_CURSES_LIBRARY "${CURSES_LIBRARY_NAME}")
#MESSAGE(STATUS "CURSES! " ${CURSES_CURSES_LIBRARY})
FIND_LIBRARY(CURSES_NCURSES_LIBRARY "${NCURSES_LIBRARY_NAME}")
#MESSAGE(STATUS "NCURSES! " ${CURSES_NCURSES_LIBRARY})
SET(CURSES_USE_NCURSES FALSE)
IF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_LIBRARY)
SET(CURSES_USE_NCURSES TRUE)
ENDIF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_LIBRARY)
# Not sure the logic is correct here.
# If NCurses is required, use the function wsyncup() to check if the library
# has NCurses functionality (at least this is where it breaks on NetBSD).
# If wsyncup is in curses, use this one.
# If not, try to find ncurses and check if this has the symbol.
# Once the ncurses library is found, search the ncurses.h header first, but
# some web pages also say that even with ncurses there is not always a ncurses.h:
# http://osdir.com/ml/gnome.apps.mc.devel/2002-06/msg00029.html
# So at first try ncurses.h, if not found, try to find curses.h under the same
# prefix as the library was found, if still not found, try curses.h with the
# default search paths.
IF(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES)
INCLUDE(CheckLibraryExists)
CHECK_LIBRARY_EXISTS("${CURSES_CURSES_LIBRARY}"
wsyncup "" CURSES_CURSES_HAS_WSYNCUP)
IF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP)
CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}"
wsyncup "" CURSES_NCURSES_HAS_WSYNCUP)
IF( CURSES_NCURSES_HAS_WSYNCUP)
SET(CURSES_USE_NCURSES TRUE)
ENDIF( CURSES_NCURSES_HAS_WSYNCUP)
ENDIF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP)
ENDIF(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES)
IF(NOT CURSES_USE_NCURSES)
FIND_FILE(CURSES_HAVE_CURSES_H curses.h )
FIND_FILE(CURSES_HAVE_CURSESW_H cursesw.h )
FIND_PATH(CURSES_CURSES_H_PATH curses.h )
FIND_PATH(CURSES_CURSESW_H_PATH cursesw.h )
GET_FILENAME_COMPONENT(_cursesLibDir "${CURSES_CURSES_LIBRARY}" PATH)
GET_FILENAME_COMPONENT(_cursesParentDir "${_cursesLibDir}" PATH)
# for compatibility with older FindCurses.cmake this has to be in the cache
# FORCE must not be used since this would break builds which preload a cache wqith these variables set
SET(CURSES_INCLUDE_PATH "${CURSES_CURSES_H_PATH} ${CURSES_CURSESW_H_PATH}"
CACHE FILEPATH "The curses include path")
SET(CURSES_LIBRARY "${CURSES_CURSES_LIBRARY}"
CACHE FILEPATH "The curses library")
ELSE(NOT CURSES_USE_NCURSES)
# we need to find ncurses
GET_FILENAME_COMPONENT(_cursesLibDir "${CURSES_NCURSES_LIBRARY}" PATH)
GET_FILENAME_COMPONENT(_cursesParentDir "${_cursesLibDir}" PATH)
FIND_FILE(CURSES_HAVE_NCURSES_H ncurses.h)
FIND_FILE(CURSES_HAVE_NCURSES_NCURSES_H ncurses/ncurses.h)
FIND_FILE(CURSES_HAVE_NCURSES_CURSES_H ncurses/curses.h)
FIND_FILE(CURSES_HAVE_CURSES_H curses.h
HINTS "${_cursesParentDir}/include")
FIND_FILE(CURSES_HAVE_NCURSESW_H ncursesw.h)
FIND_FILE(CURSES_HAVE_NCURSESW_NCURSES_H ncursesw/ncurses.h)
FIND_FILE(CURSES_HAVE_NCURSESW_CURSES_H ncursesw/curses.h)
FIND_FILE(CURSES_HAVE_CURSESW_H cursesw.h
HINTS "${_cursesParentDir}/include")
FIND_PATH(CURSES_NCURSES_INCLUDE_PATH ncurses.h ncurses/ncurses.h
ncurses/curses.h ncursesw.h ncursesw/ncurses.h ncursesw/curses.h cursesw.h)
FIND_PATH(CURSES_NCURSES_INCLUDE_PATH curses.h
HINTS "${_cursesParentDir}/include")
# for compatibility with older FindCurses.cmake this has to be in the cache
# FORCE must not be used since this would break builds which preload
# a cache wqith these variables set
# only put ncurses include and library into
# variables if they are found
IF(CURSES_NCURSES_INCLUDE_PATH AND CURSES_NCURSES_LIBRARY)
SET(CURSES_INCLUDE_PATH "${CURSES_NCURSES_INCLUDE_PATH} ${CURSES_NCURSESW_INCLUDE_PATH}"
CACHE FILEPATH "The curses include path")
SET(CURSES_LIBRARY "${CURSES_NCURSES_LIBRARY}"
CACHE FILEPATH "The curses library")
ENDIF(CURSES_NCURSES_INCLUDE_PATH AND CURSES_NCURSES_LIBRARY)
ENDIF(NOT CURSES_USE_NCURSES)
FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr HINTS "${_cursesLibDir}")
FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr )
SET(CURSES_FORM_LIBRARY_NAME "form")
IF(CURSES_NEED_WIDE)
SET(CURSES_FORM_LIBRARY_NAME "formw")
ENDIF(CURSES_NEED_WIDE)
FIND_LIBRARY(CURSES_CURSES_LIBRARY "${CURSES_LIBRARY_NAME}")
FIND_LIBRARY(CURSES_FORM_LIBRARY "${CURSES_FORM_LIBRARY_NAME}" HINTS "${_cursesLibDir}")
FIND_LIBRARY(CURSES_FORM_LIBRARY "${CURSES_FORM_LIBRARY_NAME}" )
# for compatibility with older FindCurses.cmake this has to be in the cache
# FORCE must not be used since this would break builds which preload a cache
# qith these variables set
SET(FORM_LIBRARY "${CURSES_FORM_LIBRARY}"
CACHE FILEPATH "The curses form library")
# Need to provide the *_LIBRARIES
SET(CURSES_LIBRARIES ${CURSES_LIBRARY})
IF(CURSES_EXTRA_LIBRARY)
SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY})
ENDIF(CURSES_EXTRA_LIBRARY)
IF(CURSES_FORM_LIBRARY)
SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY})
ENDIF(CURSES_FORM_LIBRARY)
# Proper name is *_INCLUDE_DIR
SET(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH})
# handle the QUIETLY and REQUIRED arguments and set CURSES_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Curses DEFAULT_MSG
CURSES_LIBRARY CURSES_INCLUDE_PATH)
IF (Curses_INCLUDE_PATH AND Curses_LIBRARY)
SET(Curses_FOUND TRUE)
ENDIF()
MARK_AS_ADVANCED(
CURSES_INCLUDE_PATH
CURSES_LIBRARY
CURSES_CURSES_INCLUDE_PATH
CURSES_CURSES_LIBRARY
CURSES_NCURSES_INCLUDE_PATH
CURSES_NCURSES_LIBRARY
CURSES_EXTRA_LIBRARY
FORM_LIBRARY
CURSES_FORM_LIBRARY
CURSES_LIBRARIES
CURSES_INCLUDE_DIR
CURSES_CURSES_HAS_WSYNCUP
CURSES_NCURSES_HAS_WSYNCUP
CURSES_HAVE_CURSESW_H
CURSES_HAVE_CURSES_H
CURSES_HAVE_NCURSESW_CURSES_H
CURSES_HAVE_NCURSESW_H
CURSES_HAVE_NCURSESW_NCURSES_H
CURSES_HAVE_NCURSES_CURSES_H
CURSES_HAVE_NCURSES_H
CURSES_HAVE_NCURSES_NCURSES_H
)
Curses_INCLUDE_PATH
Curses_LIBRARY
)

@ -51,6 +51,7 @@ IF(WIN32)
ELSE()
set (DFHACK_INST_DEFAULT "linux")
ENDIF()
SET( DFHACK_INSTALL ${DFHACK_INST_DEFAULT} CACHE STRING
"Choose the install type:
'portable' for a portable zip or tar.gz package (windows default)
@ -150,6 +151,26 @@ include_directories (${dfhack_SOURCE_DIR}/library/shm/)
include_directories (${dfhack_SOURCE_DIR}/library/depends/argstream/)
include_directories (${dfhack_SOURCE_DIR}/library/depends/xgetopt/)
# handle curses library bull**** on multiple platforms.
IF(UNIX)
find_package(Curses QUIET)
if(Curses_FOUND)
add_library(curses SHARED IMPORTED)
set_property(TARGET curses PROPERTY IMPORTED_LOCATION ${Curses_LIBRARY})
include_directories (${Curses_INCLUDE_PATH})
endif()
ELSE()
add_library(curses SHARED IMPORTED)
set_property(TARGET curses PROPERTY IMPORTED_LOCATION ${dfhack_SOURCE_DIR}/pdcurses/pdcurses.dll)
set_property(TARGET curses PROPERTY IMPORTED_IMPLIB ${dfhack_SOURCE_DIR}/pdcurses/pdcurses.lib)
include_directories (${dfhack_SOURCE_DIR}/pdcurses)
add_custom_target( curses-copy
COMMAND "${CMAKE_COMMAND}" -E copy "${dfhack_SOURCE_DIR}/pdcurses/pdcurses.dll" ${dfhack_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/
DEPENDS "${dfhack_SOURCE_DIR}/pdcurses/pdcurses.dll")
SET(Curses_FOUND TRUE)
INSTALL(FILES "${dfhack_SOURCE_DIR}/pdcurses/pdcurses.dll" DESTINATION ${DFHACK_BINARY_DESTINATION})
ENDIF()
# macro to save on typing in the tool subdirs
# builds a tool, links it to the dfhack lib and makes sure the dependency
# LOCAL_DEPNAME is built first, in case there is one
@ -164,6 +185,26 @@ MACRO(DFHACK_TOOL TOOL_NAME TOOL_SOURCES)
RUNTIME DESTINATION ${DFHACK_BINARY_DESTINATION})
ENDMACRO()
# same as above builds a curses tool instead of plain terminal one.
MACRO(DFHACK_CURSES_TOOL TOOL_NAME TOOL_SOURCES)
IF(Curses_FOUND)
ADD_EXECUTABLE(${TOOL_NAME} ${TOOL_SOURCES})
TARGET_LINK_LIBRARIES(${TOOL_NAME} dfhack curses)
if(DEFINED LOCAL_DEPNAME)
ADD_DEPENDENCIES(${TOOL_NAME} ${LOCAL_DEPNAME})
endif()
if(WIN32)
ADD_DEPENDENCIES(${TOOL_NAME} curses-copy)
ENDIF()
install(TARGETS
${TOOL_NAME}
RUNTIME DESTINATION ${DFHACK_BINARY_DESTINATION})
ELSE()
MESSAGE(STATUS "Wide-character ncurses library not found - " ${TOOL_NAME} "can't be built")
ENDIF()
ENDMACRO()
IF(BUILD_DFHACK_LIBRARY)
add_subdirectory (library)

@ -38,6 +38,7 @@ include/dfhack/DFVector.h
include/dfhack/VersionInfoFactory.h
include/dfhack/VersionInfo.h
include/dfhack/extra/MapExtras.h
include/dfhack/extra/termutil.h
include/dfhack/modules/Buildings.h
include/dfhack/modules/Constructions.h
include/dfhack/modules/Creatures.h

@ -2,7 +2,7 @@
#define TERMUTIL_H
#ifdef LINUX_BUILD
// FIXME: is this ever false?
// FIXME: is this ever true?
bool TemporaryTerminal ()
{
return false;

File diff suppressed because it is too large Load Diff

@ -0,0 +1,58 @@
/* Public Domain Curses */
/* $Id: panel.h,v 1.19 2008/07/13 16:08:16 wmcbrine Exp $ */
/*----------------------------------------------------------------------*
* Panels for PDCurses *
*----------------------------------------------------------------------*/
#ifndef __PDCURSES_PANEL_H__
#define __PDCURSES_PANEL_H__ 1
#include <curses.h>
#if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS)
extern "C"
{
#endif
typedef struct panelobs
{
struct panelobs *above;
struct panel *pan;
} PANELOBS;
typedef struct panel
{
WINDOW *win;
int wstarty;
int wendy;
int wstartx;
int wendx;
struct panel *below;
struct panel *above;
const void *user;
struct panelobs *obscure;
} PANEL;
int bottom_panel(PANEL *pan);
int del_panel(PANEL *pan);
int hide_panel(PANEL *pan);
int move_panel(PANEL *pan, int starty, int startx);
PANEL *new_panel(WINDOW *win);
PANEL *panel_above(const PANEL *pan);
PANEL *panel_below(const PANEL *pan);
int panel_hidden(const PANEL *pan);
const void *panel_userptr(const PANEL *pan);
WINDOW *panel_window(const PANEL *pan);
int replace_panel(PANEL *pan, WINDOW *win);
int set_panel_userptr(PANEL *pan, const void *uptr);
int show_panel(PANEL *pan);
int top_panel(PANEL *pan);
void update_panels(void);
#if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS)
}
#endif
#endif /* __PDCURSES_PANEL_H__ */

Binary file not shown.

Binary file not shown.

@ -28,6 +28,10 @@ DFHACK_TOOL(dfmoodump moodump.cpp)
# Author: mizipzor
DFHACK_TOOL(dfdigger digger.cpp)
# dfstatus - watches DF and prints stuff in a window
DFHACK_CURSES_TOOL(dfstatus dfstatus.cpp)
find_package(Curses QUIET)
# digger2 - designate for digging from a text file
# Author: rOut
DFHACK_TOOL(dfdigger2 digger2.cpp)

@ -116,33 +116,5 @@ ENDIF()
# tile types. tile shape, material, and special information manipulation tool
DFHACK_TOOL(dftiletypes tiletypes.cpp)
# veinlook - look at the map... sort of
IF(UNIX)
SET(VEINLOOK_BUILT "NO")
SET(CURSES_NEED_WIDE "YES")
SET(CURSES_NEED_NCURSES "NO")
find_package(Curses QUIET)
IF(CURSES_FOUND)
if(CURSES_HAVE_NCURSESW_NCURSES_H)
SET(NCURSES_H "ncursesw/ncurses.h")
elseif(CURSES_HAVE_NCURSESW_CURSES_H)
SET(NCURSES_H "ncursesw/curses.h")
elseif(CURSES_HAVE_NCURSESW_H)
SET(NCURSES_H "ncursesw.h")
elseif(CURSES_HAVE_CURSESW_H)
SET(NCURSES_H "cursesw.h")
endif(CURSES_HAVE_NCURSESW_NCURSES_H)
IF(NCURSES_H)
ADD_EXECUTABLE(dfveinlook veinlook.cpp)
set_property( TARGET dfveinlook PROPERTY COMPILE_DEFINITIONS NCURSES_H=${NCURSES_H} )
INCLUDE_DIRECTORIES(${CURSES_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(dfveinlook dfhack ${CURSES_LIBRARIES})
install(TARGETS
dfveinlook
RUNTIME DESTINATION ${DFHACK_BINARY_DESTINATION}
)
ENDIF(NCURSES_H)
ELSE(CURSES_FOUND)
MESSAGE(STATUS "Wide-character ncurses library not found - veinlook can't be built")
ENDIF(CURSES_FOUND)
ENDIF(UNIX)
# veinlook - look at the map... sort of, kind of
DFHACK_CURSES_TOOL(dfveinlook veinlook.cpp)

@ -10,8 +10,7 @@ using namespace std;
#include <sstream>
// the header name comes from the build system.
#define INCLUDE_NAME() <NCURSES_H>
#include INCLUDE_NAME()
#include <curses.h>
#include <stdlib.h>
#include <signal.h>
#include <locale.h>
@ -807,7 +806,7 @@ int main(int argc, char *argv[])
Maps->ReadTemperatures(cursorX+i,cursorY+j,cursorZ,&b_temp1, &b_temp2 );
if(dotwiddle)
{
bitset<32> bs = Block->designation[0][0].whole;
bitset<32> bs ((int)Block->designation[0][0].whole);
bs.flip(twiddle);
Block->designation[0][0].whole = bs.to_ulong();
Maps->WriteDesignations(cursorX+i,cursorY+j,cursorZ, &(Block->designation));