ccmake.cxx 4.51 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
13
#include "../cmCacheManager.h"
#include "../cmSystemTools.h"
14
#include "../cmake.h"
15
#include "../cmDocumentation.h"
Berk Geveci's avatar
Berk Geveci committed
16
17
18
19

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

20
#include "cmCursesMainForm.h"
Alexander Neundorf's avatar
 
Alexander Neundorf committed
21
#include "cmCursesStandardIncludes.h"
22
23
24

#include <form.h>

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

//----------------------------------------------------------------------------
34
static const char * cmDocumentationUsage[][3] =
35
36
{
  {0,
37
38
   "  ccmake <path-to-source>\n"
   "  ccmake <path-to-existing-build>", 0},
39
40
41
  {0,0,0}
};

42
//----------------------------------------------------------------------------
43
static const char * cmDocumentationOptions[][3] =
44
45
46
47
48
{
  CMAKE_STANDARD_OPTIONS_TABLE,
  {0,0,0}
};

49
cmCursesForm* cmCursesForm::CurrentForm=0;
Berk Geveci's avatar
Berk Geveci committed
50

Bill Hoffman's avatar
Bill Hoffman committed
51
52
53
extern "C"
{

54
void onsig(int)
Berk Geveci's avatar
Berk Geveci committed
55
{
56
  if (cmCursesForm::CurrentForm)
Berk Geveci's avatar
Berk Geveci committed
57
58
    {
    endwin();
59
60
61
62
63
    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
64
65
    refresh();
    int x,y;
66
67
68
    getmaxyx(stdscr, y, x);
    cmCursesForm::CurrentForm->Render(1,1,x,y);
    cmCursesForm::CurrentForm->UpdateStatusBar();
Berk Geveci's avatar
Berk Geveci committed
69
70
71
    }
  signal(SIGWINCH, onsig);
}
72

Bill Hoffman's avatar
Bill Hoffman committed
73
}
Berk Geveci's avatar
Berk Geveci committed
74

75
void CMakeErrorHandler(const char* message, const char* title, bool&, void* clientData)
76
{
77
78
  cmCursesForm* self = static_cast<cmCursesForm*>( clientData );
  self->AddError(message, title);
79
80
}

Berk Geveci's avatar
Berk Geveci committed
81
82
int main(int argc, char** argv)
{
83
  cmSystemTools::FindExecutableDirectory(argv[0]);
84
  cmDocumentation doc;
85
  doc.addCMakeStandardDocSections();
86
  if(doc.CheckOptions(argc, argv))
87
    {
88
    cmake hcm;
89
90
    std::vector<cmDocumentationEntry> generators;
    hcm.GetGeneratorDocumentation(generators);
91
    doc.SetName("ccmake");
92
93
94
    doc.SetSection("Name",cmDocumentationName);
    doc.SetSection("Usage",cmDocumentationUsage);
    doc.SetSection("Generators",generators);
95
    doc.PrependSection("Options",cmDocumentationOptions);
96
    return doc.PrintRequestedDocumentation(std::cout)? 0:1;
97
98
    }

Berk Geveci's avatar
Berk Geveci committed
99
  bool debug = false;
100
  unsigned int i;
Berk Geveci's avatar
Berk Geveci committed
101
  int j;
102
  std::vector<std::string> args;
Berk Geveci's avatar
Berk Geveci committed
103
  for(j =0; j < argc; ++j)
104
    {
Berk Geveci's avatar
Berk Geveci committed
105
106
107
108
109
110
111
112
    if(strcmp(argv[j], "-debug") == 0)
      {
      debug = true;
      }
    else
      {
      args.push_back(argv[j]);
      }
113
    }
Berk Geveci's avatar
Berk Geveci committed
114

115
  std::string cacheDir = cmSystemTools::GetCurrentWorkingDirectory();
116
  for(i=1; i < args.size(); ++i)
Berk Geveci's avatar
Berk Geveci committed
117
    {
118
    std::string arg = args[i];
119
120
121
122
    if(arg.find("-B",0) == 0)
      {
      cacheDir = arg.substr(2);
      }
Berk Geveci's avatar
Berk Geveci committed
123
124
    }

125
  cmSystemTools::DisableRunCommandOutput();
Berk Geveci's avatar
Berk Geveci committed
126

Berk Geveci's avatar
Berk Geveci committed
127
128
129
130
131
  if (debug)
    {
    cmCursesForm::DebugStart();
    }

132
133
134
135
136
  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
137
138
139
140

  signal(SIGWINCH, onsig);

  int x,y;
141
  getmaxyx(stdscr, y, x);
142
  if ( x < cmCursesMainForm::MIN_WIDTH  ||
143
       y < cmCursesMainForm::MIN_HEIGHT )
Berk Geveci's avatar
Berk Geveci committed
144
    {
145
146
    endwin();
    std::cerr << "Window is too small. A size of at least "
147
              << cmCursesMainForm::MIN_WIDTH << " x "
148
149
              <<  cmCursesMainForm::MIN_HEIGHT
              << " is required to run ccmake." <<  std::endl;
150
    return 1;
Berk Geveci's avatar
Berk Geveci committed
151
    }
152
153
154
155


  cmCursesMainForm* myform;

156
  myform = new cmCursesMainForm(args, x);
157
158
159
160
161
162
  if(myform->LoadCache(cacheDir.c_str()))
    {
    curses_clear();
    touchwin(stdscr);
    endwin();
    delete myform;
Ken Martin's avatar
Ken Martin committed
163
    std::cerr << "Error running cmake::LoadCache().  Aborting.\n";
164
165
    return 1;
    }
166

167
  cmSystemTools::SetErrorCallback(CMakeErrorHandler, myform);
168
169
170
171

  cmCursesForm::CurrentForm = myform;

  myform->InitializeUI();
172
173
174
175
176
  if ( myform->Configure(1) == 0 )
    {
    myform->Render(1, 1, x, y);
    myform->HandleInput();
    }
177

Berk Geveci's avatar
Berk Geveci committed
178
  // Need to clean-up better
179
  curses_clear();
180
  touchwin(stdscr);
Berk Geveci's avatar
Berk Geveci committed
181
  endwin();
182
183
184
  delete cmCursesForm::CurrentForm;
  cmCursesForm::CurrentForm = 0;

Ken Martin's avatar
Ken Martin committed
185
  std::cout << std::endl << std::endl;
186

Berk Geveci's avatar
Berk Geveci committed
187
188
189
  return 0;

}