cmGlobalKdevelopGenerator.cxx 20 KB

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