1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 22:37:30 +08:00

ccmake: Add Windows support using PDCurses

This commit is contained in:
Duncan Ogilvie
2022-01-14 17:31:28 +01:00
committed by Brad King
parent b97c12babb
commit 9278c6e01a
5 changed files with 34 additions and 4 deletions

View File

@@ -674,10 +674,10 @@ macro (CMAKE_BUILD_UTILITIES)
if (UNIX)
include(${CMake_SOURCE_DIR}/Source/Checks/Curses.cmake)
set(BUILD_CursesDialog_DEFAULT "${CMakeCheckCurses_COMPILED}")
option(BUILD_CursesDialog "Build the CMake Curses Dialog ccmake" "${BUILD_CursesDialog_DEFAULT}")
else()
set(BUILD_CursesDialog 0)
elseif(WIN32)
set(BUILD_CursesDialog_DEFAULT "OFF")
endif()
option(BUILD_CursesDialog "Build the CMake Curses Dialog ccmake" "${BUILD_CursesDialog_DEFAULT}")
endif ()
if(BUILD_CursesDialog)
if(UNIX)
@@ -690,6 +690,13 @@ macro (CMAKE_BUILD_UTILITIES)
)
set(BUILD_CursesDialog 0)
endif()
elseif(WIN32)
# FIXME: Add support for system-provided pdcurses.
add_subdirectory(Utilities/cmpdcurses)
set(CURSES_LIBRARY cmpdcurses)
set(CURSES_INCLUDE_PATH "") # cmpdcurses has usage requirements
set(CMAKE_USE_SYSTEM_FORM 0)
set(HAVE_CURSES_USE_DEFAULT_COLORS 1)
endif()
endif()
if(BUILD_CursesDialog)

View File

@@ -51,6 +51,7 @@ static const char* cmDocumentationOptions[][2] = {
cmCursesForm* cmCursesForm::CurrentForm = nullptr;
#ifndef _WIN32
extern "C" {
static void onsig(int /*unused*/)
@@ -61,6 +62,7 @@ static void onsig(int /*unused*/)
signal(SIGWINCH, onsig);
}
}
#endif // _WIN32
int main(int argc, char const* const* argv)
{
@@ -126,7 +128,9 @@ int main(int argc, char const* const* argv)
keypad(stdscr, true); /* Use key symbols as KEY_DOWN */
cmCursesColor::InitColors();
#ifndef _WIN32
signal(SIGWINCH, onsig);
#endif // _WIN32
int x;
int y;

View File

@@ -2,7 +2,10 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCursesForm.h"
#include <unistd.h>
#include <cstdlib>
#ifndef _WIN32
# include <unistd.h>
#endif // _WIN32
cmsys::ofstream cmCursesForm::DebugFile;
bool cmCursesForm::Debug = false;
@@ -51,8 +54,12 @@ void cmCursesForm::HandleResize()
endwin();
if (initscr() == nullptr) {
static const char errmsg[] = "Error: ncurses initialization failed\n";
#ifdef _WIN32
fprintf(stderr, "%s", errmsg);
#else
auto r = write(STDERR_FILENO, errmsg, sizeof(errmsg) - 1);
static_cast<void>(r);
#endif // _WIN32
exit(1);
}
noecho(); /* Echo off */

View File

@@ -177,6 +177,12 @@ void cmCursesLongMessageForm::HandleInput()
this->PrintKeys();
int key = getch();
#ifdef _WIN32
if (key == KEY_RESIZE) {
HandleResize();
}
#endif // _WIN32
snprintf(debugMessage, sizeof(debugMessage),
"Message widget handling input, key: %d", key);
cmCursesForm::LogMessage(debugMessage);

View File

@@ -686,6 +686,12 @@ void cmCursesMainForm::HandleInput()
}
int key = getch();
#ifdef _WIN32
if (key == KEY_RESIZE) {
HandleResize();
}
#endif // _WIN32
getmaxyx(stdscr, y, x);
// If window too small, handle 'q' only
if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) {