2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2004-2009 Kitware, Inc.
|
|
|
|
Copyright 2004 Alexander Neundorf (neundorf@kde.org)
|
2004-10-11 19:32:14 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2004-10-11 19:32:14 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
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.
|
|
|
|
============================================================================*/
|
2004-10-11 19:32:14 +04:00
|
|
|
#include "cmGlobalKdevelopGenerator.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2007-06-08 19:57:16 +04:00
|
|
|
#include "cmGlobalUnixMakefileGenerator3.h"
|
2007-01-25 23:44:52 +03:00
|
|
|
#include "cmLocalUnixMakefileGenerator3.h"
|
2004-10-11 19:32:14 +04:00
|
|
|
#include "cmMakefile.h"
|
2005-02-10 07:22:06 +03:00
|
|
|
#include "cmSourceFile.h"
|
2007-08-27 03:27:33 +04:00
|
|
|
#include "cmSystemTools.h"
|
2015-07-17 00:07:15 +03:00
|
|
|
#include "cmXMLWriter.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmake.h"
|
2004-10-11 19:32:14 +04:00
|
|
|
|
2007-08-27 03:27:33 +04:00
|
|
|
#include <cmsys/Directory.hxx>
|
2014-01-04 09:47:13 +04:00
|
|
|
#include <cmsys/FStream.hxx>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmsys/SystemTools.hxx>
|
2006-10-02 18:49:55 +04:00
|
|
|
|
2016-07-20 19:28:39 +03:00
|
|
|
cmGlobalKdevelopGenerator::cmGlobalKdevelopGenerator()
|
|
|
|
: cmExternalMakefileProjectGenerator()
|
2004-10-11 19:32:14 +04:00
|
|
|
{
|
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
|
2016-07-20 19:28:39 +03:00
|
|
|
cmExternalMakefileProjectGeneratorFactory*
|
|
|
|
cmGlobalKdevelopGenerator::GetFactory()
|
2007-06-08 19:57:16 +04:00
|
|
|
{
|
2016-07-20 19:28:39 +03:00
|
|
|
static cmExternalMakefileProjectGeneratorSimpleFactory<
|
|
|
|
cmGlobalKdevelopGenerator>
|
|
|
|
factory("KDevelop3", "Generates KDevelop 3 project files.");
|
|
|
|
|
|
|
|
if (factory.GetSupportedGlobalGenerators().empty()) {
|
|
|
|
factory.AddSupportedGlobalGenerator("Unix Makefiles");
|
2012-06-15 14:14:13 +04:00
|
|
|
#ifdef CMAKE_USE_NINJA
|
2016-07-20 19:28:39 +03:00
|
|
|
factory.AddSupportedGlobalGenerator("Ninja");
|
2012-06-15 14:14:13 +04:00
|
|
|
#endif
|
2016-07-20 19:28:39 +03:00
|
|
|
|
|
|
|
factory.Aliases.push_back("KDevelop3");
|
|
|
|
}
|
|
|
|
|
|
|
|
return &factory;
|
2007-06-08 19:57:16 +04:00
|
|
|
}
|
|
|
|
|
2005-02-10 07:22:06 +03:00
|
|
|
void cmGlobalKdevelopGenerator::Generate()
|
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
// for each sub project in the project create
|
2005-02-10 07:22:06 +03:00
|
|
|
// a kdevelop project
|
2014-02-10 09:21:34 +04:00
|
|
|
for (std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator
|
2016-05-16 17:34:04 +03:00
|
|
|
it = this->GlobalGenerator->GetProjectMap().begin();
|
|
|
|
it != this->GlobalGenerator->GetProjectMap().end(); ++it) {
|
|
|
|
std::string outputDir = it->second[0]->GetCurrentBinaryDirectory();
|
|
|
|
std::string projectDir = it->second[0]->GetSourceDirectory();
|
|
|
|
std::string projectName = it->second[0]->GetProjectName();
|
2005-02-10 07:22:06 +03:00
|
|
|
std::string cmakeFilePattern("CMakeLists.txt;*.cmake;");
|
2006-02-18 19:03:36 +03:00
|
|
|
std::string fileToOpen;
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::vector<cmLocalGenerator*>& lgs = it->second;
|
2005-02-10 07:22:06 +03:00
|
|
|
// create the project.kdevelop.filelist file
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->CreateFilelistFile(lgs, outputDir, projectDir, projectName,
|
|
|
|
cmakeFilePattern, fileToOpen)) {
|
2005-02-10 07:22:06 +03:00
|
|
|
cmSystemTools::Error("Can not create filelist file");
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
// try to find the name of an executable so we have something to
|
|
|
|
// run from kdevelop for now just pick the first executable found
|
2005-02-10 07:22:06 +03:00
|
|
|
std::string executable;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin();
|
|
|
|
lg != lgs.end(); lg++) {
|
2015-10-18 17:53:00 +03:00
|
|
|
std::vector<cmGeneratorTarget*> const& targets =
|
2016-05-16 17:34:04 +03:00
|
|
|
(*lg)->GetGeneratorTargets();
|
2015-10-18 17:53:00 +03:00
|
|
|
for (std::vector<cmGeneratorTarget*>::const_iterator ti =
|
2016-05-16 17:34:04 +03:00
|
|
|
targets.begin();
|
|
|
|
ti != targets.end(); ti++) {
|
|
|
|
if ((*ti)->GetType() == cmState::EXECUTABLE) {
|
2015-10-18 17:53:00 +03:00
|
|
|
executable = (*ti)->GetLocation("");
|
2006-04-24 17:39:50 +04:00
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!executable.empty()) {
|
2005-02-10 07:22:06 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2005-02-10 07:22:06 +03:00
|
|
|
// now create a project file
|
2016-05-16 17:34:04 +03:00
|
|
|
this->CreateProjectFile(outputDir, projectDir, projectName, executable,
|
|
|
|
cmakeFilePattern, fileToOpen);
|
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmGlobalKdevelopGenerator::CreateFilelistFile(
|
|
|
|
const std::vector<cmLocalGenerator*>& lgs, const std::string& outputDir,
|
|
|
|
const std::string& projectDirIn, const std::string& projectname,
|
|
|
|
std::string& cmakeFilePattern, std::string& fileToOpen)
|
2005-02-10 07:22:06 +03:00
|
|
|
{
|
|
|
|
std::string projectDir = projectDirIn + "/";
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string filename = outputDir + "/" + projectname + ".kdevelop.filelist";
|
2005-02-10 07:22:06 +03:00
|
|
|
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> files;
|
2005-02-10 07:22:06 +03:00
|
|
|
std::string tmp;
|
|
|
|
|
2015-10-24 15:58:23 +03:00
|
|
|
std::vector<std::string> hdrExts =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions();
|
|
|
|
|
|
|
|
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;
|
2005-02-10 07:22:06 +03:00
|
|
|
cmSystemTools::ReplaceString(tmp, projectDir.c_str(), "");
|
|
|
|
// make sure the file is part of this source tree
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((tmp[0] != '/') &&
|
|
|
|
(strstr(tmp.c_str(), cmake::GetCMakeFilesDirectoryPostSlash()) ==
|
2016-06-27 23:44:16 +03:00
|
|
|
CM_NULLPTR)) {
|
2005-02-10 07:22:06 +03:00
|
|
|
files.insert(tmp);
|
2016-05-16 17:34:04 +03:00
|
|
|
tmp = cmSystemTools::GetFilenameName(tmp);
|
|
|
|
// add all files which dont match the default
|
2005-02-10 07:22:06 +03:00
|
|
|
// */CMakeLists.txt;*cmake; to the file pattern
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((tmp != "CMakeLists.txt") &&
|
2016-06-27 23:44:16 +03:00
|
|
|
(strstr(tmp.c_str(), ".cmake") == CM_NULLPTR)) {
|
2016-05-16 17:34:04 +03:00
|
|
|
cmakeFilePattern += tmp + ";";
|
2005-02-10 07:22:06 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// get all sources
|
|
|
|
std::vector<cmGeneratorTarget*> targets = (*it)->GetGeneratorTargets();
|
2015-10-18 18:06:14 +03:00
|
|
|
for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
ti != targets.end(); ti++) {
|
2013-07-14 20:22:57 +04:00
|
|
|
std::vector<cmSourceFile*> sources;
|
2015-10-18 18:06:14 +03:00
|
|
|
cmGeneratorTarget* gt = *ti;
|
2016-05-16 17:34:04 +03:00
|
|
|
gt->GetSourceFiles(sources, gt->Target->GetMakefile()->GetSafeDefinition(
|
|
|
|
"CMAKE_BUILD_TYPE"));
|
|
|
|
for (std::vector<cmSourceFile*>::const_iterator si = sources.begin();
|
|
|
|
si != sources.end(); si++) {
|
|
|
|
tmp = (*si)->GetFullPath();
|
|
|
|
std::string headerBasename = cmSystemTools::GetFilenamePath(tmp);
|
|
|
|
headerBasename += "/";
|
|
|
|
headerBasename += cmSystemTools::GetFilenameWithoutExtension(tmp);
|
2006-10-02 18:49:55 +04:00
|
|
|
|
2005-02-10 07:22:06 +03:00
|
|
|
cmSystemTools::ReplaceString(tmp, projectDir.c_str(), "");
|
2006-10-02 18:49:55 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((tmp[0] != '/') &&
|
|
|
|
(strstr(tmp.c_str(), cmake::GetCMakeFilesDirectoryPostSlash()) ==
|
2016-06-27 23:44:16 +03:00
|
|
|
CM_NULLPTR) &&
|
2016-05-16 17:34:04 +03:00
|
|
|
(cmSystemTools::GetFilenameExtension(tmp) != ".moc")) {
|
2005-02-10 07:22:06 +03:00
|
|
|
files.insert(tmp);
|
2006-10-02 18:49:55 +04:00
|
|
|
|
|
|
|
// check if there's a matching header around
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator ext = hdrExts.begin();
|
|
|
|
ext != hdrExts.end(); ++ext) {
|
|
|
|
std::string hname = headerBasename;
|
2006-10-02 18:49:55 +04:00
|
|
|
hname += ".";
|
|
|
|
hname += *ext;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileExists(hname.c_str())) {
|
2007-01-25 23:44:52 +03:00
|
|
|
cmSystemTools::ReplaceString(hname, projectDir.c_str(), "");
|
2006-10-02 18:49:55 +04:00
|
|
|
files.insert(hname);
|
|
|
|
break;
|
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
for (std::vector<std::string>::const_iterator lt = listFiles.begin();
|
|
|
|
lt != listFiles.end(); lt++) {
|
|
|
|
tmp = *lt;
|
2005-02-10 07:22:06 +03:00
|
|
|
cmSystemTools::ReplaceString(tmp, projectDir.c_str(), "");
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((tmp[0] != '/') &&
|
|
|
|
(strstr(tmp.c_str(), cmake::GetCMakeFilesDirectoryPostSlash()) ==
|
2016-06-27 23:44:16 +03:00
|
|
|
CM_NULLPTR)) {
|
2014-03-11 03:04:11 +04:00
|
|
|
files.insert(tmp);
|
2005-02-10 07:22:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// check if the output file already exists and read it
|
|
|
|
// insert all files which exist into the set of files
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream oldFilelist(filename.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (oldFilelist) {
|
|
|
|
while (cmSystemTools::GetLineFromStream(oldFilelist, tmp)) {
|
|
|
|
if (tmp[0] == '/') {
|
2005-02-10 07:22:06 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
std::string completePath = projectDir + tmp;
|
|
|
|
if (cmSystemTools::FileExists(completePath.c_str())) {
|
2005-02-10 07:22:06 +03:00
|
|
|
files.insert(tmp);
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
oldFilelist.close();
|
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// now write the new filename
|
2005-02-10 07:22:06 +03:00
|
|
|
cmGeneratedFileStream fout(filename.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!fout) {
|
2005-02-10 07:22:06 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
fileToOpen = "";
|
|
|
|
for (std::set<std::string>::const_iterator it = files.begin();
|
|
|
|
it != files.end(); it++) {
|
2005-02-10 07:22:06 +03:00
|
|
|
// get the full path to the file
|
2016-05-16 17:34:04 +03:00
|
|
|
tmp = cmSystemTools::CollapseFullPath(*it, projectDir.c_str());
|
2006-02-18 19:03:36 +03:00
|
|
|
// just select the first source file
|
2016-05-16 17:34:04 +03:00
|
|
|
if (fileToOpen.empty()) {
|
|
|
|
std::string ext = cmSystemTools::GetFilenameExtension(tmp);
|
|
|
|
if ((ext == ".c") || (ext == ".cc") || (ext == ".cpp") ||
|
|
|
|
(ext == ".cxx") || (ext == ".C") || (ext == ".h") ||
|
|
|
|
(ext == ".hpp")) {
|
|
|
|
fileToOpen = tmp;
|
|
|
|
}
|
2006-02-18 19:03:36 +03:00
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
// make it relative to the project dir
|
|
|
|
cmSystemTools::ReplaceString(tmp, projectDir.c_str(), "");
|
|
|
|
// only put relative paths
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!tmp.empty() && tmp[0] != '/') {
|
2016-06-07 00:53:32 +03:00
|
|
|
fout << tmp << "\n";
|
2005-02-10 07:22:06 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
return true;
|
2007-06-08 19:57:16 +04:00
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
|
|
|
|
/* create the project file, if it already exists, merge it with the
|
|
|
|
existing one, otherwise create a new one */
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGlobalKdevelopGenerator::CreateProjectFile(
|
|
|
|
const std::string& outputDir, const std::string& projectDir,
|
|
|
|
const std::string& projectname, const std::string& executable,
|
|
|
|
const std::string& cmakeFilePattern, const std::string& fileToOpen)
|
2005-02-10 07:22:06 +03:00
|
|
|
{
|
2007-08-27 03:27:33 +04:00
|
|
|
this->Blacklist.clear();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string filename = outputDir + "/";
|
|
|
|
filename += projectname + ".kdevelop";
|
|
|
|
std::string sessionFilename = outputDir + "/";
|
|
|
|
sessionFilename += projectname + ".kdevses";
|
2005-02-10 07:22:06 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileExists(filename.c_str())) {
|
|
|
|
this->MergeProjectFiles(outputDir, projectDir, filename, executable,
|
|
|
|
cmakeFilePattern, fileToOpen, sessionFilename);
|
|
|
|
} else {
|
2012-08-13 21:42:58 +04:00
|
|
|
// add all subdirectories which are cmake build directories to the
|
2008-08-17 00:33:47 +04:00
|
|
|
// kdevelop blacklist so they are not monitored for added or removed files
|
|
|
|
// since this is handled by adding files to the cmake files
|
2007-08-31 21:42:21 +04:00
|
|
|
cmsys::Directory d;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (d.Load(projectDir)) {
|
2007-08-31 21:42:21 +04:00
|
|
|
size_t numf = d.GetNumberOfFiles();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int i = 0; i < numf; i++) {
|
2007-08-31 21:42:21 +04:00
|
|
|
std::string nextFile = d.GetFile(i);
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((nextFile != ".") && (nextFile != "..")) {
|
2007-08-31 21:42:21 +04:00
|
|
|
std::string tmp = projectDir;
|
|
|
|
tmp += "/";
|
|
|
|
tmp += nextFile;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsDirectory(tmp)) {
|
2008-08-17 00:33:47 +04:00
|
|
|
tmp += "/CMakeCache.txt";
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((nextFile == "CMakeFiles") ||
|
|
|
|
(cmSystemTools::FileExists(tmp.c_str()))) {
|
2008-08-17 00:33:47 +04:00
|
|
|
this->Blacklist.push_back(nextFile);
|
2007-08-31 21:42:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->CreateNewProjectFile(outputDir, projectDir, filename, executable,
|
|
|
|
cmakeFilePattern, fileToOpen, sessionFilename);
|
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGlobalKdevelopGenerator::MergeProjectFiles(
|
|
|
|
const std::string& outputDir, const std::string& projectDir,
|
|
|
|
const std::string& filename, const std::string& executable,
|
|
|
|
const std::string& cmakeFilePattern, const std::string& fileToOpen,
|
|
|
|
const std::string& sessionFilename)
|
2005-02-10 07:22:06 +03:00
|
|
|
{
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream oldProjectFile(filename.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!oldProjectFile) {
|
|
|
|
this->CreateNewProjectFile(outputDir, projectDir, filename, executable,
|
|
|
|
cmakeFilePattern, fileToOpen, sessionFilename);
|
2005-02-10 07:22:06 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
|
|
|
|
/* Read the existing project file (line by line), copy all lines
|
|
|
|
into the new project file, except the ones which can be reliably
|
|
|
|
set from contents of the CMakeLists.txt */
|
|
|
|
std::string tmp;
|
|
|
|
std::vector<std::string> lines;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(oldProjectFile, tmp)) {
|
2005-02-10 07:22:06 +03:00
|
|
|
lines.push_back(tmp);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
oldProjectFile.close();
|
|
|
|
|
|
|
|
cmGeneratedFileStream fout(filename.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!fout) {
|
2005-02-10 07:22:06 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator it = lines.begin();
|
|
|
|
it != lines.end(); it++) {
|
|
|
|
const char* line = (*it).c_str();
|
2005-02-10 07:22:06 +03:00
|
|
|
// skip these tags as they are always replaced
|
2016-06-27 23:44:16 +03:00
|
|
|
if ((strstr(line, "<projectdirectory>") != CM_NULLPTR) ||
|
|
|
|
(strstr(line, "<projectmanagement>") != CM_NULLPTR) ||
|
|
|
|
(strstr(line, "<absoluteprojectpath>") != CM_NULLPTR) ||
|
|
|
|
(strstr(line, "<filelistdirectory>") != CM_NULLPTR) ||
|
|
|
|
(strstr(line, "<buildtool>") != CM_NULLPTR) ||
|
|
|
|
(strstr(line, "<builddir>") != CM_NULLPTR)) {
|
2005-02-10 07:22:06 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
|
|
|
|
// output the line from the file if it is not one of the above tags
|
2016-05-16 17:34:04 +03:00
|
|
|
fout << *it << "\n";
|
2006-05-11 18:40:28 +04:00
|
|
|
// if this is the <general> tag output the stuff that goes in the
|
|
|
|
// general tag
|
2016-05-16 17:34:04 +03:00
|
|
|
if (strstr(line, "<general>")) {
|
|
|
|
fout << " <projectmanagement>KDevCustomProject</projectmanagement>\n";
|
|
|
|
fout << " <projectdirectory>" << projectDir
|
|
|
|
<< "</projectdirectory>\n"; // this one is important
|
|
|
|
fout << " <absoluteprojectpath>true</absoluteprojectpath>\n";
|
|
|
|
// and this one
|
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
// inside kdevcustomproject the <filelistdirectory> must be put
|
2016-05-16 17:34:04 +03:00
|
|
|
if (strstr(line, "<kdevcustomproject>")) {
|
|
|
|
fout << " <filelistdirectory>" << outputDir
|
|
|
|
<< "</filelistdirectory>\n";
|
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
// buildtool and builddir go inside <build>
|
2016-05-16 17:34:04 +03:00
|
|
|
if (strstr(line, "<build>")) {
|
|
|
|
fout << " <buildtool>make</buildtool>\n";
|
|
|
|
fout << " <builddir>" << outputDir << "</builddir>\n";
|
2005-02-10 07:22:06 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-02-10 07:22:06 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGlobalKdevelopGenerator::CreateNewProjectFile(
|
|
|
|
const std::string& outputDir, const std::string& projectDir,
|
|
|
|
const std::string& filename, const std::string& executable,
|
|
|
|
const std::string& cmakeFilePattern, const std::string& fileToOpen,
|
|
|
|
const std::string& sessionFilename)
|
2005-02-10 07:22:06 +03:00
|
|
|
{
|
|
|
|
cmGeneratedFileStream fout(filename.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!fout) {
|
2005-02-10 07:22:06 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-07-17 00:07:15 +03:00
|
|
|
cmXMLWriter xml(fout);
|
2005-02-10 07:22:06 +03:00
|
|
|
|
2007-06-11 03:51:26 +04:00
|
|
|
// check for a version control system
|
|
|
|
bool hasSvn = cmSystemTools::FileExists((projectDir + "/.svn").c_str());
|
|
|
|
bool hasCvs = cmSystemTools::FileExists((projectDir + "/CVS").c_str());
|
2007-08-31 21:42:21 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool enableCxx = (this->GlobalGenerator->GetLanguageEnabled("C") ||
|
|
|
|
this->GlobalGenerator->GetLanguageEnabled("CXX"));
|
2007-08-31 21:42:21 +04:00
|
|
|
bool enableFortran = this->GlobalGenerator->GetLanguageEnabled("Fortran");
|
|
|
|
std::string primaryLanguage = "C++";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (enableFortran && !enableCxx) {
|
|
|
|
primaryLanguage = "Fortran77";
|
|
|
|
}
|
2007-08-31 21:42:21 +04:00
|
|
|
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.StartDocument();
|
|
|
|
xml.StartElement("kdevelop");
|
|
|
|
xml.StartElement("general");
|
|
|
|
|
|
|
|
xml.Element("author", "");
|
|
|
|
xml.Element("email", "");
|
|
|
|
xml.Element("version", "$VERSION$");
|
|
|
|
xml.Element("projectmanagement", "KDevCustomProject");
|
|
|
|
xml.Element("primarylanguage", primaryLanguage);
|
|
|
|
xml.Element("ignoreparts");
|
|
|
|
xml.Element("projectdirectory", projectDir); // this one is important
|
|
|
|
xml.Element("absoluteprojectpath", "true"); // and this one
|
2007-08-31 21:42:21 +04:00
|
|
|
|
|
|
|
// setup additional languages
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.StartElement("secondaryLanguages");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (enableFortran && enableCxx) {
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.Element("language", "Fortran");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (enableCxx) {
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.Element("language", "C");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.EndElement();
|
2007-06-11 03:51:26 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (hasSvn) {
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.Element("versioncontrol", "kdevsubversion");
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (hasCvs) {
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.Element("versioncontrol", "kdevcvsservice");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-11 03:51:26 +04:00
|
|
|
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.EndElement(); // general
|
|
|
|
xml.StartElement("kdevcustomproject");
|
|
|
|
|
|
|
|
xml.Element("filelistdirectory", outputDir);
|
|
|
|
|
|
|
|
xml.StartElement("run");
|
|
|
|
xml.Element("mainprogram", executable);
|
|
|
|
xml.Element("directoryradio", "custom");
|
|
|
|
xml.Element("customdirectory", outputDir);
|
|
|
|
xml.Element("programargs", "");
|
|
|
|
xml.Element("terminal", "false");
|
|
|
|
xml.Element("autocompile", "true");
|
|
|
|
xml.Element("envvars");
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("build");
|
|
|
|
xml.Element("buildtool", "make"); // this one is important
|
|
|
|
xml.Element("builddir", outputDir); // and this one
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("make");
|
|
|
|
xml.Element("abortonerror", "false");
|
|
|
|
xml.Element("numberofjobs", 1);
|
|
|
|
xml.Element("dontact", "false");
|
2016-05-16 17:34:04 +03:00
|
|
|
xml.Element("makebin", this->GlobalGenerator->GetLocalGenerators()[0]
|
|
|
|
->GetMakefile()
|
|
|
|
->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"));
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.Element("selectedenvironment", "default");
|
|
|
|
|
|
|
|
xml.StartElement("environments");
|
|
|
|
xml.StartElement("default");
|
|
|
|
|
|
|
|
xml.StartElement("envvar");
|
|
|
|
xml.Attribute("value", 1);
|
|
|
|
xml.Attribute("name", "VERBOSE");
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("envvar");
|
|
|
|
xml.Attribute("value", 1);
|
|
|
|
xml.Attribute("name", "CMAKE_NO_VERBOSE");
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.EndElement(); // default
|
|
|
|
xml.EndElement(); // environments
|
|
|
|
xml.EndElement(); // make
|
|
|
|
|
|
|
|
xml.StartElement("blacklist");
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator dirIt =
|
|
|
|
this->Blacklist.begin();
|
|
|
|
dirIt != this->Blacklist.end(); ++dirIt) {
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.Element("path", *dirIt);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.EndElement(); // kdevcustomproject
|
|
|
|
|
|
|
|
xml.StartElement("kdevfilecreate");
|
|
|
|
xml.Element("filetypes");
|
|
|
|
xml.StartElement("useglobaltypes");
|
|
|
|
|
|
|
|
xml.StartElement("type");
|
|
|
|
xml.Attribute("ext", "ui");
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("type");
|
|
|
|
xml.Attribute("ext", "cpp");
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("type");
|
|
|
|
xml.Attribute("ext", "h");
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.EndElement(); // useglobaltypes
|
|
|
|
xml.EndElement(); // kdevfilecreate
|
|
|
|
|
|
|
|
xml.StartElement("kdevdoctreeview");
|
|
|
|
xml.StartElement("projectdoc");
|
|
|
|
xml.Element("userdocDir", "html/");
|
|
|
|
xml.Element("apidocDir", "html/");
|
|
|
|
xml.EndElement(); // projectdoc
|
|
|
|
xml.Element("ignoreqt_xml");
|
|
|
|
xml.Element("ignoredoxygen");
|
|
|
|
xml.Element("ignorekdocs");
|
|
|
|
xml.Element("ignoretocs");
|
|
|
|
xml.Element("ignoredevhelp");
|
|
|
|
xml.EndElement(); // kdevdoctreeview;
|
2007-08-31 21:42:21 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (enableCxx) {
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.StartElement("cppsupportpart");
|
|
|
|
xml.StartElement("filetemplates");
|
|
|
|
xml.Element("interfacesuffix", ".h");
|
|
|
|
xml.Element("implementationsuffix", ".cpp");
|
|
|
|
xml.EndElement(); // filetemplates
|
|
|
|
xml.EndElement(); // cppsupportpart
|
|
|
|
|
|
|
|
xml.StartElement("kdevcppsupport");
|
|
|
|
xml.StartElement("codecompletion");
|
|
|
|
xml.Element("includeGlobalFunctions", "true");
|
|
|
|
xml.Element("includeTypes", "true");
|
|
|
|
xml.Element("includeEnums", "true");
|
|
|
|
xml.Element("includeTypedefs", "false");
|
|
|
|
xml.Element("automaticCodeCompletion", "true");
|
|
|
|
xml.Element("automaticArgumentsHint", "true");
|
|
|
|
xml.Element("automaticHeaderCompletion", "true");
|
|
|
|
xml.Element("codeCompletionDelay", 250);
|
|
|
|
xml.Element("argumentsHintDelay", 400);
|
|
|
|
xml.Element("headerCompletionDelay", 250);
|
|
|
|
xml.EndElement(); // codecompletion
|
|
|
|
xml.Element("references");
|
|
|
|
xml.EndElement(); // kdevcppsupport;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-08-31 21:42:21 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (enableFortran) {
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.StartElement("kdevfortransupport");
|
|
|
|
xml.StartElement("ftnchek");
|
|
|
|
xml.Element("division", "false");
|
|
|
|
xml.Element("extern", "false");
|
|
|
|
xml.Element("declare", "false");
|
|
|
|
xml.Element("pure", "false");
|
|
|
|
xml.Element("argumentsall", "false");
|
|
|
|
xml.Element("commonall", "false");
|
|
|
|
xml.Element("truncationall", "false");
|
|
|
|
xml.Element("usageall", "false");
|
|
|
|
xml.Element("f77all", "false");
|
|
|
|
xml.Element("portabilityall", "false");
|
|
|
|
xml.Element("argumentsonly");
|
|
|
|
xml.Element("commononly");
|
|
|
|
xml.Element("truncationonly");
|
|
|
|
xml.Element("usageonly");
|
|
|
|
xml.Element("f77only");
|
|
|
|
xml.Element("portabilityonly");
|
|
|
|
xml.EndElement(); // ftnchek
|
|
|
|
xml.EndElement(); // kdevfortransupport;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-08-31 21:42:21 +04:00
|
|
|
|
|
|
|
// set up file groups. maybe this can be used with the CMake SOURCE_GROUP()
|
|
|
|
// command
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.StartElement("kdevfileview");
|
|
|
|
xml.StartElement("groups");
|
|
|
|
|
|
|
|
xml.StartElement("group");
|
|
|
|
xml.Attribute("pattern", cmakeFilePattern);
|
|
|
|
xml.Attribute("name", "CMake");
|
|
|
|
xml.EndElement();
|
2007-08-31 21:42:21 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (enableCxx) {
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.StartElement("group");
|
|
|
|
xml.Attribute("pattern", "*.h;*.hxx;*.hpp");
|
|
|
|
xml.Attribute("name", "Header");
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("group");
|
|
|
|
xml.Attribute("pattern", "*.c");
|
|
|
|
xml.Attribute("name", "C Sources");
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.StartElement("group");
|
|
|
|
xml.Attribute("pattern", "*.cpp;*.C;*.cxx;*.cc");
|
|
|
|
xml.Attribute("name", "C++ Sources");
|
|
|
|
xml.EndElement();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-08-31 21:42:21 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (enableFortran) {
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.StartElement("group");
|
|
|
|
xml.Attribute("pattern",
|
2016-05-16 17:34:04 +03:00
|
|
|
"*.f;*.F;*.f77;*.F77;*.f90;*.F90;*.for;*.f95;*.F95");
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.Attribute("name", "Fortran Sources");
|
|
|
|
xml.EndElement();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-08-31 21:42:21 +04:00
|
|
|
|
2015-07-17 00:07:15 +03:00
|
|
|
xml.StartElement("group");
|
|
|
|
xml.Attribute("pattern", "*.ui");
|
|
|
|
xml.Attribute("name", "Qt Designer files");
|
|
|
|
xml.EndElement();
|
|
|
|
|
|
|
|
xml.Element("hidenonprojectfiles", "true");
|
|
|
|
xml.EndElement(); // groups
|
|
|
|
|
|
|
|
xml.StartElement("tree");
|
|
|
|
xml.Element("hidepatterns", "*.o,*.lo,CVS,*~,cmake*");
|
|
|
|
xml.Element("hidenonprojectfiles", "true");
|
|
|
|
xml.EndElement(); // tree
|
|
|
|
|
|
|
|
xml.EndElement(); // kdevfileview
|
|
|
|
xml.EndElement(); // kdevelop;
|
|
|
|
xml.EndDocument();
|
2007-08-31 21:42:21 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (sessionFilename.empty()) {
|
2007-05-18 00:50:53 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-18 19:03:36 +03:00
|
|
|
|
2006-05-11 18:40:28 +04:00
|
|
|
// and a session file, so that kdevelop opens a file if it opens the
|
|
|
|
// project the first time
|
2006-02-18 19:03:36 +03:00
|
|
|
cmGeneratedFileStream devses(sessionFilename.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!devses) {
|
2007-05-18 00:50:53 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-07-17 00:07:15 +03:00
|
|
|
cmXMLWriter sesxml(devses);
|
|
|
|
sesxml.StartDocument("UTF-8");
|
|
|
|
sesxml.Doctype("KDevPrjSession");
|
|
|
|
sesxml.StartElement("KDevPrjSession");
|
|
|
|
|
|
|
|
sesxml.StartElement("DocsAndViews");
|
|
|
|
sesxml.Attribute("NumberOfDocuments", 1);
|
|
|
|
|
|
|
|
sesxml.StartElement("Doc0");
|
|
|
|
sesxml.Attribute("NumberOfViews", 1);
|
|
|
|
sesxml.Attribute("URL", "file://" + fileToOpen);
|
|
|
|
|
|
|
|
sesxml.StartElement("View0");
|
|
|
|
sesxml.Attribute("line", 0);
|
|
|
|
sesxml.Attribute("Type", "Source");
|
|
|
|
sesxml.EndElement(); // View0
|
|
|
|
|
|
|
|
sesxml.EndElement(); // Doc0
|
|
|
|
sesxml.EndElement(); // DocsAndViews
|
|
|
|
sesxml.EndElement(); // KDevPrjSession;
|
2005-02-10 07:22:06 +03:00
|
|
|
}
|