Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / CursesDialog / ccmake.cxx
blobf19c3d2dc7efe9b40817fc5e370cae6a7fe1c67d
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: ccmake.cxx,v $
5 Language: C++
6 Date: $Date: 2007/12/13 22:56:50 $
7 Version: $Revision: 1.37 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "../cmCacheManager.h"
18 #include "../cmSystemTools.h"
19 #include "../cmake.h"
20 #include "../cmDocumentation.h"
22 #include <signal.h>
23 #include <sys/ioctl.h>
25 #include "cmCursesMainForm.h"
26 #include "cmCursesStandardIncludes.h"
28 #include <form.h>
30 //----------------------------------------------------------------------------
31 static const char * cmDocumentationName[][3] =
33 {0,
34 " ccmake - Curses Interface for CMake.", 0},
35 {0,0,0}
38 //----------------------------------------------------------------------------
39 static const char * cmDocumentationUsage[][3] =
41 {0,
42 " ccmake <path-to-source>\n"
43 " ccmake <path-to-existing-build>", 0},
44 {0,0,0}
47 //----------------------------------------------------------------------------
48 static const char * cmDocumentationDescription[][3] =
50 {0,
51 "The \"ccmake\" executable is the CMake curses interface. Project "
52 "configuration settings may be specified interactively through "
53 "this GUI. Brief instructions are provided at the bottom of the "
54 "terminal when the program is running.", 0},
55 CMAKE_STANDARD_INTRODUCTION,
56 {0,0,0}
59 //----------------------------------------------------------------------------
60 static const char * cmDocumentationOptions[][3] =
62 CMAKE_STANDARD_OPTIONS_TABLE,
63 {0,0,0}
66 //----------------------------------------------------------------------------
67 static const char * cmDocumentationSeeAlso[][3] =
69 {0, "cmake", 0},
70 {0, "ctest", 0},
71 {0, 0, 0}
74 cmCursesForm* cmCursesForm::CurrentForm=0;
76 extern "C"
79 void onsig(int)
81 if (cmCursesForm::CurrentForm)
83 endwin();
84 initscr(); /* Initialization */
85 noecho(); /* Echo off */
86 cbreak(); /* nl- or cr not needed */
87 keypad(stdscr,TRUE); /* Use key symbols as
88 KEY_DOWN*/
89 refresh();
90 int x,y;
91 getmaxyx(stdscr, y, x);
92 cmCursesForm::CurrentForm->Render(1,1,x,y);
93 cmCursesForm::CurrentForm->UpdateStatusBar();
95 signal(SIGWINCH, onsig);
100 void CMakeErrorHandler(const char* message, const char* title, bool&, void* clientData)
102 cmCursesForm* self = static_cast<cmCursesForm*>( clientData );
103 self->AddError(message, title);
106 int main(int argc, char** argv)
108 cmSystemTools::FindExecutableDirectory(argv[0]);
109 cmDocumentation doc;
110 if(doc.CheckOptions(argc, argv))
112 cmake hcm;
113 std::vector<cmDocumentationEntry> commands;
114 std::vector<cmDocumentationEntry> compatCommands;
115 std::vector<cmDocumentationEntry> generators;
116 hcm.GetCommandDocumentation(commands, true, false);
117 hcm.GetCommandDocumentation(compatCommands, false, true);
118 hcm.GetGeneratorDocumentation(generators);
119 doc.SetName("ccmake");
120 doc.SetSection("Name",cmDocumentationName);
121 doc.SetSection("Usage",cmDocumentationUsage);
122 doc.SetSection("Description",cmDocumentationDescription);
123 doc.SetSection("Generators",generators);
124 doc.SetSection("Options",cmDocumentationOptions);
125 doc.SetSection("Command",commands);
126 doc.SetSection("Compatibility Commands",compatCommands);
127 doc.SetSeeAlsoList(cmDocumentationSeeAlso);
128 return doc.PrintRequestedDocumentation(std::cout)? 0:1;
131 bool debug = false;
132 unsigned int i;
133 int j;
134 std::vector<std::string> args;
135 for(j =0; j < argc; ++j)
137 if(strcmp(argv[j], "-debug") == 0)
139 debug = true;
141 else
143 args.push_back(argv[j]);
147 std::string cacheDir = cmSystemTools::GetCurrentWorkingDirectory();
148 for(i=1; i < args.size(); ++i)
150 std::string arg = args[i];
151 if(arg.find("-B",0) == 0)
153 cacheDir = arg.substr(2);
157 cmSystemTools::DisableRunCommandOutput();
159 if (debug)
161 cmCursesForm::DebugStart();
164 initscr(); /* Initialization */
165 noecho(); /* Echo off */
166 cbreak(); /* nl- or cr not needed */
167 keypad(stdscr,TRUE); /* Use key symbols as
168 KEY_DOWN*/
170 signal(SIGWINCH, onsig);
172 int x,y;
173 getmaxyx(stdscr, y, x);
174 if ( x < cmCursesMainForm::MIN_WIDTH ||
175 y < cmCursesMainForm::MIN_HEIGHT )
177 endwin();
178 std::cerr << "Window is too small. A size of at least "
179 << cmCursesMainForm::MIN_WIDTH << " x "
180 << cmCursesMainForm::MIN_HEIGHT
181 << " is required to run ccmake." << std::endl;
182 return 1;
186 cmCursesMainForm* myform;
188 myform = new cmCursesMainForm(args, x);
189 if(myform->LoadCache(cacheDir.c_str()))
191 curses_clear();
192 touchwin(stdscr);
193 endwin();
194 delete myform;
195 std::cerr << "Error running cmake::LoadCache(). Aborting.\n";
196 return 1;
199 cmSystemTools::SetErrorCallback(CMakeErrorHandler, myform);
201 cmCursesForm::CurrentForm = myform;
203 myform->InitializeUI();
204 if ( myform->Configure(1) == 0 )
206 myform->Render(1, 1, x, y);
207 myform->HandleInput();
210 // Need to clean-up better
211 curses_clear();
212 touchwin(stdscr);
213 endwin();
214 delete cmCursesForm::CurrentForm;
215 cmCursesForm::CurrentForm = 0;
217 std::cout << std::endl << std::endl;
219 return 0;