ccmake.cxx 5.21 KB
Newer Older
1
2
3
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
Will Schroeder's avatar
Will Schroeder committed
4

5
6
  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.
Will Schroeder's avatar
Will Schroeder committed
7

8
9
10
11
  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
12
#include "../cmSystemTools.h"
13
#include "../cmake.h"
14
#include "../cmDocumentation.h"
Berk Geveci's avatar
Berk Geveci committed
15
16
17
18

#include <signal.h>
#include <sys/ioctl.h>

19
#include "cmCursesMainForm.h"
Alexander Neundorf's avatar
   
Alexander Neundorf committed
20
#include "cmCursesStandardIncludes.h"
21
#include <cmsys/Encoding.hxx>
22
23
24

#include <form.h>

25
//----------------------------------------------------------------------------
26
static const char * cmDocumentationName[][2] =
27
{
28
  {0,
29
30
   "  ccmake - Curses Interface for CMake."},
  {0,0}
31
32
33
};

//----------------------------------------------------------------------------
34
static const char * cmDocumentationUsage[][2] =
35
36
{
  {0,
37
   "  ccmake <path-to-source>\n"
38
   "  ccmake <path-to-existing-build>"},
39
40
41
42
43
44
45
46
47
48
49
50
  {0,
   "Specify a source directory to (re-)generate a build system for "
   "it in the current working directory.  Specify an existing build "
   "directory to re-generate its build system."},
  {0,0}
};

//----------------------------------------------------------------------------
static const char * cmDocumentationUsageNote[][2] =
{
  {0,
   "Run 'ccmake --help' for more information."},
51
  {0,0}
52
53
};

54
//----------------------------------------------------------------------------
55
static const char * cmDocumentationOptions[][2] =
56
57
{
  CMAKE_STANDARD_OPTIONS_TABLE,
58
  {0,0}
59
60
};

61
cmCursesForm* cmCursesForm::CurrentForm=0;
Berk Geveci's avatar
Berk Geveci committed
62

Bill Hoffman's avatar
Bill Hoffman committed
63
64
65
extern "C"
{

66
void onsig(int)
Berk Geveci's avatar
Berk Geveci committed
67
{
68
  if (cmCursesForm::CurrentForm)
Berk Geveci's avatar
Berk Geveci committed
69
70
    {
    endwin();
71
72
73
74
75
    initscr(); /* Initialization */
    noecho(); /* Echo off */
    cbreak(); /* nl- or cr not needed */
    keypad(stdscr,TRUE); /* Use key symbols as
                            KEY_DOWN*/
Berk Geveci's avatar
Berk Geveci committed
76
77
    refresh();
    int x,y;
78
79
80
    getmaxyx(stdscr, y, x);
    cmCursesForm::CurrentForm->Render(1,1,x,y);
    cmCursesForm::CurrentForm->UpdateStatusBar();
Berk Geveci's avatar
Berk Geveci committed
81
82
83
    }
  signal(SIGWINCH, onsig);
}
84

Bill Hoffman's avatar
Bill Hoffman committed
85
}
Berk Geveci's avatar
Berk Geveci committed
86

87
88
void CMakeMessageHandler(const char* message, const char* title, bool&,
                         void* clientData)
89
{
90
91
  cmCursesForm* self = static_cast<cmCursesForm*>( clientData );
  self->AddError(message, title);
92
93
}

94
int main(int argc, char const* const* argv)
Berk Geveci's avatar
Berk Geveci committed
95
{
96
97
98
99
100
  cmsys::Encoding::CommandLineArguments encoding_args =
    cmsys::Encoding::CommandLineArguments::Main(argc, argv);
  argc = encoding_args.argc();
  argv = encoding_args.argv();

101
  cmSystemTools::FindCMakeResources(argv[0]);
102
  cmDocumentation doc;
103
  doc.addCMakeStandardDocSections();
104
  if(doc.CheckOptions(argc, argv))
105
    {
106
    cmake hcm;
107
    hcm.AddCMakePaths();
108
109
    std::vector<cmDocumentationEntry> generators;
    hcm.GetGeneratorDocumentation(generators);
110
    doc.SetName("ccmake");
111
112
    doc.SetSection("Name",cmDocumentationName);
    doc.SetSection("Usage",cmDocumentationUsage);
113
114
115
116
    if ( argc == 1 )
      {
      doc.AppendSection("Usage",cmDocumentationUsageNote);
      }
117
    doc.SetSection("Generators",generators);
118
    doc.PrependSection("Options",cmDocumentationOptions);
119
    return doc.PrintRequestedDocumentation(std::cout)? 0:1;
120
121
    }

Berk Geveci's avatar
Berk Geveci committed
122
  bool debug = false;
123
  unsigned int i;
Berk Geveci's avatar
Berk Geveci committed
124
  int j;
125
  std::vector<std::string> args;
Berk Geveci's avatar
Berk Geveci committed
126
  for(j =0; j < argc; ++j)
127
    {
Berk Geveci's avatar
Berk Geveci committed
128
129
130
131
132
133
134
135
    if(strcmp(argv[j], "-debug") == 0)
      {
      debug = true;
      }
    else
      {
      args.push_back(argv[j]);
      }
136
    }
Berk Geveci's avatar
Berk Geveci committed
137

138
  std::string cacheDir = cmSystemTools::GetCurrentWorkingDirectory();
139
  for(i=1; i < args.size(); ++i)
Berk Geveci's avatar
Berk Geveci committed
140
    {
141
    std::string arg = args[i];
142
143
144
145
    if(arg.find("-B",0) == 0)
      {
      cacheDir = arg.substr(2);
      }
Berk Geveci's avatar
Berk Geveci committed
146
147
    }

148
  cmSystemTools::DisableRunCommandOutput();
Berk Geveci's avatar
Berk Geveci committed
149

Berk Geveci's avatar
Berk Geveci committed
150
151
152
153
154
  if (debug)
    {
    cmCursesForm::DebugStart();
    }

155
156
157
158
159
  initscr(); /* Initialization */
  noecho(); /* Echo off */
  cbreak(); /* nl- or cr not needed */
  keypad(stdscr,TRUE); /* Use key symbols as
                          KEY_DOWN*/
Berk Geveci's avatar
Berk Geveci committed
160
161
162
163

  signal(SIGWINCH, onsig);

  int x,y;
164
  getmaxyx(stdscr, y, x);
165
  if ( x < cmCursesMainForm::MIN_WIDTH  ||
166
       y < cmCursesMainForm::MIN_HEIGHT )
Berk Geveci's avatar
Berk Geveci committed
167
    {
168
169
    endwin();
    std::cerr << "Window is too small. A size of at least "
170
              << cmCursesMainForm::MIN_WIDTH << " x "
171
172
              <<  cmCursesMainForm::MIN_HEIGHT
              << " is required to run ccmake." <<  std::endl;
173
    return 1;
Berk Geveci's avatar
Berk Geveci committed
174
    }
175
176
177
178


  cmCursesMainForm* myform;

179
  myform = new cmCursesMainForm(args, x);
180
181
182
183
184
185
  if(myform->LoadCache(cacheDir.c_str()))
    {
    curses_clear();
    touchwin(stdscr);
    endwin();
    delete myform;
Ken Martin's avatar
Ken Martin committed
186
    std::cerr << "Error running cmake::LoadCache().  Aborting.\n";
187
188
    return 1;
    }
189

190
  cmSystemTools::SetMessageCallback(CMakeMessageHandler, myform);
191
192
193
194

  cmCursesForm::CurrentForm = myform;

  myform->InitializeUI();
195
196
197
198
199
  if ( myform->Configure(1) == 0 )
    {
    myform->Render(1, 1, x, y);
    myform->HandleInput();
    }
200

Berk Geveci's avatar
Berk Geveci committed
201
  // Need to clean-up better
202
  curses_clear();
203
  touchwin(stdscr);
Berk Geveci's avatar
Berk Geveci committed
204
  endwin();
205
206
207
  delete cmCursesForm::CurrentForm;
  cmCursesForm::CurrentForm = 0;

Ken Martin's avatar
Ken Martin committed
208
  std::cout << std::endl << std::endl;
209

Berk Geveci's avatar
Berk Geveci committed
210
211
212
  return 0;

}