1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2004-2009 Kitware, Inc.
Copyright 2004 Alexander Neundorf (neundorf@kde.org)
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
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.
============================================================================*/
#include "cmExtraKateGenerator.h"
#include "cmGlobalUnixMakefileGenerator3.h"
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmMakefile.h"
#include "cmake.h"
#include "cmSourceFile.h"
#include "cmGeneratedFileStream.h"
#include "cmTarget.h"
#include "cmSystemTools.h"
#include "cmXMLSafe.h"
#include <cmsys/SystemTools.hxx>
//----------------------------------------------------------------------------
void cmExtraKateGenerator
::GetDocumentation(cmDocumentationEntry& entry, const char*) const
{
entry.Name = this->GetName();
entry.Brief = "Generates Kate project files.";
}
cmExtraKateGenerator::cmExtraKateGenerator()
:cmExternalMakefileProjectGenerator()
{
#if defined(_WIN32)
this->SupportedGlobalGenerators.push_back("MinGW Makefiles");
this->SupportedGlobalGenerators.push_back("NMake Makefiles");
// disable until somebody actually tests it:
// this->SupportedGlobalGenerators.push_back("MSYS Makefiles");
#endif
this->SupportedGlobalGenerators.push_back("Ninja");
this->SupportedGlobalGenerators.push_back("Unix Makefiles");
}
void cmExtraKateGenerator::Generate()
{
const cmMakefile* mf
= this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
this->ProjectName = this->GenerateProjectName(mf->GetProjectName(),
mf->GetSafeDefinition("CMAKE_BUILD_TYPE"),
this->GetPathBasename(mf->GetHomeOutputDirectory()));
this->CreateKateProjectFile(mf);
this->CreateDummyKateProjectFile(mf);
}
void cmExtraKateGenerator::CreateKateProjectFile(const cmMakefile* mf) const
{
std::string filename = mf->GetHomeOutputDirectory();
filename += "/.kateproject";
cmGeneratedFileStream fout(filename.c_str());
if (!fout)
{
return;
}
std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
std::string args = mf->GetRequiredDefinition("CMAKE_KATE_MAKE_ARGUMENTS");
fout <<
"{\n"
"\t\"name\": \"" << this->ProjectName << "\",\n"
"\t\"directory\": \"" << mf->GetHomeDirectory() << "\",\n"
"\t\"files\": [ { " << this->GenerateFilesString(mf) << "} ],\n"
"\t\"build\": {\n"
"\t\t\"directory\": \"" << mf->GetHomeOutputDirectory() << "\",\n"
"\t\t\"build\": \"" << make << " " << args <<" all\",\n"
"\t\t\"clean\": \"" << make << " clean\",\n"
"\t\t\"quick\": \"" << make << " help\"\n"
"\t}\n"
"}\n";
}
void
cmExtraKateGenerator::CreateDummyKateProjectFile(const cmMakefile* mf) const
{
std::string filename = mf->GetHomeOutputDirectory();
filename += "/";
filename += this->ProjectName;
filename += ".kateproject";
cmGeneratedFileStream fout(filename.c_str());
if (!fout)
{
return;
}
fout << "#Generated by cmake, do not edit.\n";
}
std::string
cmExtraKateGenerator::GenerateFilesString(const cmMakefile* mf) const
{
std::string s = mf->GetHomeDirectory();
s += "/.git";
if(cmSystemTools::FileExists(s.c_str()))
{
return std::string("\"git\": 1 ");
}
s = mf->GetHomeDirectory();
s += "/.svn";
if(cmSystemTools::FileExists(s.c_str()))
{
return std::string("\"svn\": 1 ");
}
s = mf->GetHomeDirectory();
s += "/";
std::set<std::string> files;
std::string tmp;
const std::vector<cmLocalGenerator *>& lgs =
this->GlobalGenerator->GetLocalGenerators();
for (std::vector<cmLocalGenerator*>::const_iterator it=lgs.begin();
it!=lgs.end(); it++)
{
cmMakefile* makefile=(*it)->GetMakefile();
const std::vector<std::string>& listFiles=makefile->GetListFiles();
for (std::vector<std::string>::const_iterator lt=listFiles.begin();
lt!=listFiles.end(); lt++)
{
tmp=*lt;
{
files.insert(tmp);
}
}
const std::vector<cmSourceFile*>& sources = makefile->GetSourceFiles();
for (std::vector<cmSourceFile*>::const_iterator sfIt = sources.begin();
sfIt != sources.end(); sfIt++)
{
cmSourceFile* sf = *sfIt;
if (sf->GetPropertyAsBool("GENERATED"))
{
continue;
}
tmp = sf->GetFullPath();
files.insert(tmp);
}
}
const char* sep = "";
tmp = "\"list\": [";
for(std::set<std::string>::const_iterator it = files.begin();
it != files.end(); ++it)
{
tmp += sep;
tmp += " \"";
tmp += *it;
tmp += "\"";
sep = ",";
}
tmp += "] ";
return tmp;
}
std::string cmExtraKateGenerator::GenerateProjectName(const std::string& name,
const std::string& type,
const std::string& path) const
{
return name + (type.empty() ? "" : "-") + type + "@" + path;
}
std::string cmExtraKateGenerator::GetPathBasename(const std::string& path)const
{
std::string outputBasename = path;
while (outputBasename.size() > 0 &&
(outputBasename[outputBasename.size() - 1] == '/' ||
outputBasename[outputBasename.size() - 1] == '\\'))
{
outputBasename.resize(outputBasename.size() - 1);
}
std::string::size_type loc = outputBasename.find_last_of("/\\");
if (loc != std::string::npos)
{
outputBasename = outputBasename.substr(loc + 1);
}
return outputBasename;
}
// Create the command line for building the given target using the selected
// make
std::string cmExtraKateGenerator::BuildMakeCommand(const std::string& make,
const char* makefile, const char* target) const
{
std::string command = make;
if (strcmp(this->GlobalGenerator->GetName(), "NMake Makefiles")==0)
{
std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
command += " /NOLOGO /f "";
command += makefileName;
command += "" ";
command += " VERBOSE=1 ";
command += target;
}
else if (strcmp(this->GlobalGenerator->GetName(), "MinGW Makefiles")==0)
{
// no escaping of spaces in this case, see
// http://public.kitware.com/Bug/view.php?id=10014
std::string makefileName = makefile;
command += " -f "";
command += makefileName;
command += "" ";
command += " VERBOSE=1 ";
command += target;
}
else if (strcmp(this->GlobalGenerator->GetName(), "Ninja")==0)
{
command += " -v ";
command += target;
}
else
{
std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
command += " -f "";
command += makefileName;
command += "" ";
command += " VERBOSE=1 ";
command += target;
}
return command;
}
|