cmGlobalKdevelopGenerator.cxx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmGlobalKdevelopGenerator.h"
  4. #include "cmGeneratedFileStream.h"
  5. #include "cmGeneratorTarget.h"
  6. #include "cmGlobalGenerator.h"
  7. #include "cmLocalGenerator.h"
  8. #include "cmMakefile.h"
  9. #include "cmSourceFile.h"
  10. #include "cmStateTypes.h"
  11. #include "cmSystemTools.h"
  12. #include "cmTarget.h"
  13. #include "cmXMLWriter.h"
  14. #include "cmake.h"
  15. #include "cmsys/Directory.hxx"
  16. #include "cmsys/FStream.hxx"
  17. #include <map>
  18. #include <set>
  19. #include <string.h>
  20. #include <utility>
  21. cmGlobalKdevelopGenerator::cmGlobalKdevelopGenerator()
  22. : cmExternalMakefileProjectGenerator()
  23. {
  24. }
  25. cmExternalMakefileProjectGeneratorFactory*
  26. cmGlobalKdevelopGenerator::GetFactory()
  27. {
  28. static cmExternalMakefileProjectGeneratorSimpleFactory<
  29. cmGlobalKdevelopGenerator>
  30. factory("KDevelop3", "Generates KDevelop 3 project files.");
  31. if (factory.GetSupportedGlobalGenerators().empty()) {
  32. factory.AddSupportedGlobalGenerator("Unix Makefiles");
  33. #ifdef CMAKE_USE_NINJA
  34. factory.AddSupportedGlobalGenerator("Ninja");
  35. #endif
  36. factory.Aliases.push_back("KDevelop3");
  37. }
  38. return &factory;
  39. }
  40. void cmGlobalKdevelopGenerator::Generate()
  41. {
  42. // for each sub project in the project create
  43. // a kdevelop project
  44. for (std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator
  45. it = this->GlobalGenerator->GetProjectMap().begin();
  46. it != this->GlobalGenerator->GetProjectMap().end(); ++it) {
  47. std::string outputDir = it->second[0]->GetCurrentBinaryDirectory();
  48. std::string projectDir = it->second[0]->GetSourceDirectory();
  49. std::string projectName = it->second[0]->GetProjectName();
  50. std::string cmakeFilePattern("CMakeLists.txt;*.cmake;");
  51. std::string fileToOpen;
  52. const std::vector<cmLocalGenerator*>& lgs = it->second;
  53. // create the project.kdevelop.filelist file
  54. if (!this->CreateFilelistFile(lgs, outputDir, projectDir, projectName,
  55. cmakeFilePattern, fileToOpen)) {
  56. cmSystemTools::Error("Can not create filelist file");
  57. return;
  58. }
  59. // try to find the name of an executable so we have something to
  60. // run from kdevelop for now just pick the first executable found
  61. std::string executable;
  62. for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin();
  63. lg != lgs.end(); lg++) {
  64. std::vector<cmGeneratorTarget*> const& targets =
  65. (*lg)->GetGeneratorTargets();
  66. for (std::vector<cmGeneratorTarget*>::const_iterator ti =
  67. targets.begin();
  68. ti != targets.end(); ti++) {
  69. if ((*ti)->GetType() == cmStateEnums::EXECUTABLE) {
  70. executable = (*ti)->GetLocation("");
  71. break;
  72. }
  73. }
  74. if (!executable.empty()) {
  75. break;
  76. }
  77. }
  78. // now create a project file
  79. this->CreateProjectFile(outputDir, projectDir, projectName, executable,
  80. cmakeFilePattern, fileToOpen);
  81. }
  82. }
  83. bool cmGlobalKdevelopGenerator::CreateFilelistFile(
  84. const std::vector<cmLocalGenerator*>& lgs, const std::string& outputDir,
  85. const std::string& projectDirIn, const std::string& projectname,
  86. std::string& cmakeFilePattern, std::string& fileToOpen)
  87. {
  88. std::string projectDir = projectDirIn + "/";
  89. std::string filename = outputDir + "/" + projectname + ".kdevelop.filelist";
  90. std::set<std::string> files;
  91. std::string tmp;
  92. std::vector<std::string> const& hdrExts =
  93. this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions();
  94. for (std::vector<cmLocalGenerator*>::const_iterator it = lgs.begin();
  95. it != lgs.end(); it++) {
  96. cmMakefile* makefile = (*it)->GetMakefile();
  97. const std::vector<std::string>& listFiles = makefile->GetListFiles();
  98. for (std::vector<std::string>::const_iterator lt = listFiles.begin();
  99. lt != listFiles.end(); lt++) {
  100. tmp = *lt;
  101. cmSystemTools::ReplaceString(tmp, projectDir.c_str(), "");
  102. // make sure the file is part of this source tree
  103. if ((tmp[0] != '/') &&
  104. (strstr(tmp.c_str(), cmake::GetCMakeFilesDirectoryPostSlash()) ==
  105. CM_NULLPTR)) {
  106. files.insert(tmp);
  107. tmp = cmSystemTools::GetFilenameName(tmp);
  108. // add all files which dont match the default
  109. // */CMakeLists.txt;*cmake; to the file pattern
  110. if ((tmp != "CMakeLists.txt") &&
  111. (strstr(tmp.c_str(), ".cmake") == CM_NULLPTR)) {
  112. cmakeFilePattern += tmp + ";";
  113. }
  114. }
  115. }
  116. // get all sources
  117. std::vector<cmGeneratorTarget*> targets = (*it)->GetGeneratorTargets();
  118. for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
  119. ti != targets.end(); ti++) {
  120. std::vector<cmSourceFile*> sources;
  121. cmGeneratorTarget* gt = *ti;
  122. gt->GetSourceFiles(sources, gt->Target->GetMakefile()->GetSafeDefinition(
  123. "CMAKE_BUILD_TYPE"));
  124. for (std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  125. si != sources.end(); si++) {
  126. tmp = (*si)->GetFullPath();
  127. std::string headerBasename = cmSystemTools::GetFilenamePath(tmp);
  128. headerBasename += "/";
  129. headerBasename += cmSystemTools::GetFilenameWithoutExtension(tmp);
  130. cmSystemTools::ReplaceString(tmp, projectDir.c_str(), "");
  131. if ((tmp[0] != '/') &&
  132. (strstr(tmp.c_str(), cmake::GetCMakeFilesDirectoryPostSlash()) ==
  133. CM_NULLPTR) &&
  134. (cmSystemTools::GetFilenameExtension(tmp) != ".moc")) {
  135. files.insert(tmp);
  136. // check if there's a matching header around
  137. for (std::vector<std::string>::const_iterator ext = hdrExts.begin();
  138. ext != hdrExts.end(); ++ext) {
  139. std::string hname = headerBasename;
  140. hname += ".";
  141. hname += *ext;
  142. if (cmSystemTools::FileExists(hname.c_str())) {
  143. cmSystemTools::ReplaceString(hname, projectDir.c_str(), "");
  144. files.insert(hname);
  145. break;
  146. }
  147. }
  148. }
  149. }
  150. for (std::vector<std::string>::const_iterator lt = listFiles.begin();
  151. lt != listFiles.end(); lt++) {
  152. tmp = *lt;
  153. cmSystemTools::ReplaceString(tmp, projectDir.c_str(), "");
  154. if ((tmp[0] != '/') &&
  155. (strstr(tmp.c_str(), cmake::GetCMakeFilesDirectoryPostSlash()) ==
  156. CM_NULLPTR)) {
  157. files.insert(tmp);
  158. }
  159. }
  160. }
  161. }
  162. // check if the output file already exists and read it
  163. // insert all files which exist into the set of files
  164. cmsys::ifstream oldFilelist(filename.c_str());
  165. if (oldFilelist) {
  166. while (cmSystemTools::GetLineFromStream(oldFilelist, tmp)) {
  167. if (tmp[0] == '/') {
  168. continue;
  169. }
  170. std::string completePath = projectDir + tmp;
  171. if (cmSystemTools::FileExists(completePath.c_str())) {
  172. files.insert(tmp);
  173. }
  174. }
  175. oldFilelist.close();
  176. }
  177. // now write the new filename
  178. cmGeneratedFileStream fout(filename.c_str());
  179. if (!fout) {
  180. return false;
  181. }
  182. fileToOpen = "";
  183. for (std::set<std::string>::const_iterator it = files.begin();
  184. it != files.end(); it++) {
  185. // get the full path to the file
  186. tmp = cmSystemTools::CollapseFullPath(*it, projectDir.c_str());
  187. // just select the first source file
  188. if (fileToOpen.empty()) {
  189. std::string ext = cmSystemTools::GetFilenameExtension(tmp);
  190. if ((ext == ".c") || (ext == ".cc") || (ext == ".cpp") ||
  191. (ext == ".cxx") || (ext == ".C") || (ext == ".h") ||
  192. (ext == ".hpp")) {
  193. fileToOpen = tmp;
  194. }
  195. }
  196. // make it relative to the project dir
  197. cmSystemTools::ReplaceString(tmp, projectDir.c_str(), "");
  198. // only put relative paths
  199. if (!tmp.empty() && tmp[0] != '/') {
  200. fout << tmp << "\n";
  201. }
  202. }
  203. return true;
  204. }
  205. /* create the project file, if it already exists, merge it with the
  206. existing one, otherwise create a new one */
  207. void cmGlobalKdevelopGenerator::CreateProjectFile(
  208. const std::string& outputDir, const std::string& projectDir,
  209. const std::string& projectname, const std::string& executable,
  210. const std::string& cmakeFilePattern, const std::string& fileToOpen)
  211. {
  212. this->Blacklist.clear();
  213. std::string filename = outputDir + "/";
  214. filename += projectname + ".kdevelop";
  215. std::string sessionFilename = outputDir + "/";
  216. sessionFilename += projectname + ".kdevses";
  217. if (cmSystemTools::FileExists(filename.c_str())) {
  218. this->MergeProjectFiles(outputDir, projectDir, filename, executable,
  219. cmakeFilePattern, fileToOpen, sessionFilename);
  220. } else {
  221. // add all subdirectories which are cmake build directories to the
  222. // kdevelop blacklist so they are not monitored for added or removed files
  223. // since this is handled by adding files to the cmake files
  224. cmsys::Directory d;
  225. if (d.Load(projectDir)) {
  226. size_t numf = d.GetNumberOfFiles();
  227. for (unsigned int i = 0; i < numf; i++) {
  228. std::string nextFile = d.GetFile(i);
  229. if ((nextFile != ".") && (nextFile != "..")) {
  230. std::string tmp = projectDir;
  231. tmp += "/";
  232. tmp += nextFile;
  233. if (cmSystemTools::FileIsDirectory(tmp)) {
  234. tmp += "/CMakeCache.txt";
  235. if ((nextFile == "CMakeFiles") ||
  236. (cmSystemTools::FileExists(tmp.c_str()))) {
  237. this->Blacklist.push_back(nextFile);
  238. }
  239. }
  240. }
  241. }
  242. }
  243. this->CreateNewProjectFile(outputDir, projectDir, filename, executable,
  244. cmakeFilePattern, fileToOpen, sessionFilename);
  245. }
  246. }
  247. void cmGlobalKdevelopGenerator::MergeProjectFiles(
  248. const std::string& outputDir, const std::string& projectDir,
  249. const std::string& filename, const std::string& executable,
  250. const std::string& cmakeFilePattern, const std::string& fileToOpen,
  251. const std::string& sessionFilename)
  252. {
  253. cmsys::ifstream oldProjectFile(filename.c_str());
  254. if (!oldProjectFile) {
  255. this->CreateNewProjectFile(outputDir, projectDir, filename, executable,
  256. cmakeFilePattern, fileToOpen, sessionFilename);
  257. return;
  258. }
  259. /* Read the existing project file (line by line), copy all lines
  260. into the new project file, except the ones which can be reliably
  261. set from contents of the CMakeLists.txt */
  262. std::string tmp;
  263. std::vector<std::string> lines;
  264. while (cmSystemTools::GetLineFromStream(oldProjectFile, tmp)) {
  265. lines.push_back(tmp);
  266. }
  267. oldProjectFile.close();
  268. cmGeneratedFileStream fout(filename.c_str());
  269. if (!fout) {
  270. return;
  271. }
  272. for (std::vector<std::string>::const_iterator it = lines.begin();
  273. it != lines.end(); it++) {
  274. const char* line = (*it).c_str();
  275. // skip these tags as they are always replaced
  276. if ((strstr(line, "<projectdirectory>") != CM_NULLPTR) ||
  277. (strstr(line, "<projectmanagement>") != CM_NULLPTR) ||
  278. (strstr(line, "<absoluteprojectpath>") != CM_NULLPTR) ||
  279. (strstr(line, "<filelistdirectory>") != CM_NULLPTR) ||
  280. (strstr(line, "<buildtool>") != CM_NULLPTR) ||
  281. (strstr(line, "<builddir>") != CM_NULLPTR)) {
  282. continue;
  283. }
  284. // output the line from the file if it is not one of the above tags
  285. fout << *it << "\n";
  286. // if this is the <general> tag output the stuff that goes in the
  287. // general tag
  288. if (strstr(line, "<general>")) {
  289. fout << " <projectmanagement>KDevCustomProject</projectmanagement>\n";
  290. fout << " <projectdirectory>" << projectDir
  291. << "</projectdirectory>\n"; // this one is important
  292. fout << " <absoluteprojectpath>true</absoluteprojectpath>\n";
  293. // and this one
  294. }
  295. // inside kdevcustomproject the <filelistdirectory> must be put
  296. if (strstr(line, "<kdevcustomproject>")) {
  297. fout << " <filelistdirectory>" << outputDir
  298. << "</filelistdirectory>\n";
  299. }
  300. // buildtool and builddir go inside <build>
  301. if (strstr(line, "<build>")) {
  302. fout << " <buildtool>make</buildtool>\n";
  303. fout << " <builddir>" << outputDir << "</builddir>\n";
  304. }
  305. }
  306. }
  307. void cmGlobalKdevelopGenerator::CreateNewProjectFile(
  308. const std::string& outputDir, const std::string& projectDir,
  309. const std::string& filename, const std::string& executable,
  310. const std::string& cmakeFilePattern, const std::string& fileToOpen,
  311. const std::string& sessionFilename)
  312. {
  313. cmGeneratedFileStream fout(filename.c_str());
  314. if (!fout) {
  315. return;
  316. }
  317. cmXMLWriter xml(fout);
  318. // check for a version control system
  319. bool hasSvn = cmSystemTools::FileExists((projectDir + "/.svn").c_str());
  320. bool hasCvs = cmSystemTools::FileExists((projectDir + "/CVS").c_str());
  321. bool enableCxx = (this->GlobalGenerator->GetLanguageEnabled("C") ||
  322. this->GlobalGenerator->GetLanguageEnabled("CXX"));
  323. bool enableFortran = this->GlobalGenerator->GetLanguageEnabled("Fortran");
  324. std::string primaryLanguage = "C++";
  325. if (enableFortran && !enableCxx) {
  326. primaryLanguage = "Fortran77";
  327. }
  328. xml.StartDocument();
  329. xml.StartElement("kdevelop");
  330. xml.StartElement("general");
  331. xml.Element("author", "");
  332. xml.Element("email", "");
  333. xml.Element("version", "$VERSION$");
  334. xml.Element("projectmanagement", "KDevCustomProject");
  335. xml.Element("primarylanguage", primaryLanguage);
  336. xml.Element("ignoreparts");
  337. xml.Element("projectdirectory", projectDir); // this one is important
  338. xml.Element("absoluteprojectpath", "true"); // and this one
  339. // setup additional languages
  340. xml.StartElement("secondaryLanguages");
  341. if (enableFortran && enableCxx) {
  342. xml.Element("language", "Fortran");
  343. }
  344. if (enableCxx) {
  345. xml.Element("language", "C");
  346. }
  347. xml.EndElement();
  348. if (hasSvn) {
  349. xml.Element("versioncontrol", "kdevsubversion");
  350. } else if (hasCvs) {
  351. xml.Element("versioncontrol", "kdevcvsservice");
  352. }
  353. xml.EndElement(); // general
  354. xml.StartElement("kdevcustomproject");
  355. xml.Element("filelistdirectory", outputDir);
  356. xml.StartElement("run");
  357. xml.Element("mainprogram", executable);
  358. xml.Element("directoryradio", "custom");
  359. xml.Element("customdirectory", outputDir);
  360. xml.Element("programargs", "");
  361. xml.Element("terminal", "false");
  362. xml.Element("autocompile", "true");
  363. xml.Element("envvars");
  364. xml.EndElement();
  365. xml.StartElement("build");
  366. xml.Element("buildtool", "make"); // this one is important
  367. xml.Element("builddir", outputDir); // and this one
  368. xml.EndElement();
  369. xml.StartElement("make");
  370. xml.Element("abortonerror", "false");
  371. xml.Element("numberofjobs", 1);
  372. xml.Element("dontact", "false");
  373. xml.Element("makebin", this->GlobalGenerator->GetLocalGenerators()[0]
  374. ->GetMakefile()
  375. ->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"));
  376. xml.Element("selectedenvironment", "default");
  377. xml.StartElement("environments");
  378. xml.StartElement("default");
  379. xml.StartElement("envvar");
  380. xml.Attribute("value", 1);
  381. xml.Attribute("name", "VERBOSE");
  382. xml.EndElement();
  383. xml.StartElement("envvar");
  384. xml.Attribute("value", 1);
  385. xml.Attribute("name", "CMAKE_NO_VERBOSE");
  386. xml.EndElement();
  387. xml.EndElement(); // default
  388. xml.EndElement(); // environments
  389. xml.EndElement(); // make
  390. xml.StartElement("blacklist");
  391. for (std::vector<std::string>::const_iterator dirIt =
  392. this->Blacklist.begin();
  393. dirIt != this->Blacklist.end(); ++dirIt) {
  394. xml.Element("path", *dirIt);
  395. }
  396. xml.EndElement();
  397. xml.EndElement(); // kdevcustomproject
  398. xml.StartElement("kdevfilecreate");
  399. xml.Element("filetypes");
  400. xml.StartElement("useglobaltypes");
  401. xml.StartElement("type");
  402. xml.Attribute("ext", "ui");
  403. xml.EndElement();
  404. xml.StartElement("type");
  405. xml.Attribute("ext", "cpp");
  406. xml.EndElement();
  407. xml.StartElement("type");
  408. xml.Attribute("ext", "h");
  409. xml.EndElement();
  410. xml.EndElement(); // useglobaltypes
  411. xml.EndElement(); // kdevfilecreate
  412. xml.StartElement("kdevdoctreeview");
  413. xml.StartElement("projectdoc");
  414. xml.Element("userdocDir", "html/");
  415. xml.Element("apidocDir", "html/");
  416. xml.EndElement(); // projectdoc
  417. xml.Element("ignoreqt_xml");
  418. xml.Element("ignoredoxygen");
  419. xml.Element("ignorekdocs");
  420. xml.Element("ignoretocs");
  421. xml.Element("ignoredevhelp");
  422. xml.EndElement(); // kdevdoctreeview;
  423. if (enableCxx) {
  424. xml.StartElement("cppsupportpart");
  425. xml.StartElement("filetemplates");
  426. xml.Element("interfacesuffix", ".h");
  427. xml.Element("implementationsuffix", ".cpp");
  428. xml.EndElement(); // filetemplates
  429. xml.EndElement(); // cppsupportpart
  430. xml.StartElement("kdevcppsupport");
  431. xml.StartElement("codecompletion");
  432. xml.Element("includeGlobalFunctions", "true");
  433. xml.Element("includeTypes", "true");
  434. xml.Element("includeEnums", "true");
  435. xml.Element("includeTypedefs", "false");
  436. xml.Element("automaticCodeCompletion", "true");
  437. xml.Element("automaticArgumentsHint", "true");
  438. xml.Element("automaticHeaderCompletion", "true");
  439. xml.Element("codeCompletionDelay", 250);
  440. xml.Element("argumentsHintDelay", 400);
  441. xml.Element("headerCompletionDelay", 250);
  442. xml.EndElement(); // codecompletion
  443. xml.Element("references");
  444. xml.EndElement(); // kdevcppsupport;
  445. }
  446. if (enableFortran) {
  447. xml.StartElement("kdevfortransupport");
  448. xml.StartElement("ftnchek");
  449. xml.Element("division", "false");
  450. xml.Element("extern", "false");
  451. xml.Element("declare", "false");
  452. xml.Element("pure", "false");
  453. xml.Element("argumentsall", "false");
  454. xml.Element("commonall", "false");
  455. xml.Element("truncationall", "false");
  456. xml.Element("usageall", "false");
  457. xml.Element("f77all", "false");
  458. xml.Element("portabilityall", "false");
  459. xml.Element("argumentsonly");
  460. xml.Element("commononly");
  461. xml.Element("truncationonly");
  462. xml.Element("usageonly");
  463. xml.Element("f77only");
  464. xml.Element("portabilityonly");
  465. xml.EndElement(); // ftnchek
  466. xml.EndElement(); // kdevfortransupport;
  467. }
  468. // set up file groups. maybe this can be used with the CMake SOURCE_GROUP()
  469. // command
  470. xml.StartElement("kdevfileview");
  471. xml.StartElement("groups");
  472. xml.StartElement("group");
  473. xml.Attribute("pattern", cmakeFilePattern);
  474. xml.Attribute("name", "CMake");
  475. xml.EndElement();
  476. if (enableCxx) {
  477. xml.StartElement("group");
  478. xml.Attribute("pattern", "*.h;*.hxx;*.hpp");
  479. xml.Attribute("name", "Header");
  480. xml.EndElement();
  481. xml.StartElement("group");
  482. xml.Attribute("pattern", "*.c");
  483. xml.Attribute("name", "C Sources");
  484. xml.EndElement();
  485. xml.StartElement("group");
  486. xml.Attribute("pattern", "*.cpp;*.C;*.cxx;*.cc");
  487. xml.Attribute("name", "C++ Sources");
  488. xml.EndElement();
  489. }
  490. if (enableFortran) {
  491. xml.StartElement("group");
  492. xml.Attribute("pattern",
  493. "*.f;*.F;*.f77;*.F77;*.f90;*.F90;*.for;*.f95;*.F95");
  494. xml.Attribute("name", "Fortran Sources");
  495. xml.EndElement();
  496. }
  497. xml.StartElement("group");
  498. xml.Attribute("pattern", "*.ui");
  499. xml.Attribute("name", "Qt Designer files");
  500. xml.EndElement();
  501. xml.Element("hidenonprojectfiles", "true");
  502. xml.EndElement(); // groups
  503. xml.StartElement("tree");
  504. xml.Element("hidepatterns", "*.o,*.lo,CVS,*~,cmake*");
  505. xml.Element("hidenonprojectfiles", "true");
  506. xml.EndElement(); // tree
  507. xml.EndElement(); // kdevfileview
  508. xml.EndElement(); // kdevelop;
  509. xml.EndDocument();
  510. if (sessionFilename.empty()) {
  511. return;
  512. }
  513. // and a session file, so that kdevelop opens a file if it opens the
  514. // project the first time
  515. cmGeneratedFileStream devses(sessionFilename.c_str());
  516. if (!devses) {
  517. return;
  518. }
  519. cmXMLWriter sesxml(devses);
  520. sesxml.StartDocument("UTF-8");
  521. sesxml.Doctype("KDevPrjSession");
  522. sesxml.StartElement("KDevPrjSession");
  523. sesxml.StartElement("DocsAndViews");
  524. sesxml.Attribute("NumberOfDocuments", 1);
  525. sesxml.StartElement("Doc0");
  526. sesxml.Attribute("NumberOfViews", 1);
  527. sesxml.Attribute("URL", "file://" + fileToOpen);
  528. sesxml.StartElement("View0");
  529. sesxml.Attribute("line", 0);
  530. sesxml.Attribute("Type", "Source");
  531. sesxml.EndElement(); // View0
  532. sesxml.EndElement(); // Doc0
  533. sesxml.EndElement(); // DocsAndViews
  534. sesxml.EndElement(); // KDevPrjSession;
  535. }