cmExtraEclipseCDT4Generator.cxx 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  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 "cmExtraEclipseCDT4Generator.h"
  4. #include "cmsys/RegularExpression.hxx"
  5. #include <algorithm>
  6. #include <assert.h>
  7. #include <sstream>
  8. #include <stdio.h>
  9. #include <utility>
  10. #include "cmGeneratedFileStream.h"
  11. #include "cmGeneratorExpression.h"
  12. #include "cmGeneratorTarget.h"
  13. #include "cmGlobalGenerator.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmMakefile.h"
  16. #include "cmSourceFile.h"
  17. #include "cmSourceGroup.h"
  18. #include "cmState.h"
  19. #include "cmStateTypes.h"
  20. #include "cmSystemTools.h"
  21. #include "cmXMLWriter.h"
  22. #include "cmake.h"
  23. static void AppendAttribute(cmXMLWriter& xml, const char* keyval)
  24. {
  25. xml.StartElement("attribute");
  26. xml.Attribute("key", keyval);
  27. xml.Attribute("value", keyval);
  28. xml.EndElement();
  29. }
  30. template <typename T>
  31. void AppendDictionary(cmXMLWriter& xml, const char* key, T const& value)
  32. {
  33. xml.StartElement("dictionary");
  34. xml.Element("key", key);
  35. xml.Element("value", value);
  36. xml.EndElement();
  37. }
  38. cmExtraEclipseCDT4Generator::cmExtraEclipseCDT4Generator()
  39. : cmExternalMakefileProjectGenerator()
  40. {
  41. this->SupportsVirtualFolders = true;
  42. this->GenerateLinkedResources = true;
  43. this->SupportsGmakeErrorParser = true;
  44. this->SupportsMachO64Parser = true;
  45. this->CEnabled = false;
  46. this->CXXEnabled = false;
  47. }
  48. cmExternalMakefileProjectGeneratorFactory*
  49. cmExtraEclipseCDT4Generator::GetFactory()
  50. {
  51. static cmExternalMakefileProjectGeneratorSimpleFactory<
  52. cmExtraEclipseCDT4Generator>
  53. factory("Eclipse CDT4", "Generates Eclipse CDT 4.0 project files.");
  54. if (factory.GetSupportedGlobalGenerators().empty()) {
  55. // TODO: Verify if __CYGWIN__ should be checked.
  56. //#if defined(_WIN32) && !defined(__CYGWIN__)
  57. #if defined(_WIN32)
  58. factory.AddSupportedGlobalGenerator("NMake Makefiles");
  59. factory.AddSupportedGlobalGenerator("MinGW Makefiles");
  60. // factory.AddSupportedGlobalGenerator("MSYS Makefiles");
  61. #endif
  62. factory.AddSupportedGlobalGenerator("Ninja");
  63. factory.AddSupportedGlobalGenerator("Unix Makefiles");
  64. }
  65. return &factory;
  66. }
  67. void cmExtraEclipseCDT4Generator::EnableLanguage(
  68. std::vector<std::string> const& languages, cmMakefile* /*unused*/,
  69. bool /*optional*/)
  70. {
  71. for (std::string const& l : languages) {
  72. if (l == "CXX") {
  73. this->Natures.insert("org.eclipse.cdt.core.ccnature");
  74. this->Natures.insert("org.eclipse.cdt.core.cnature");
  75. this->CXXEnabled = true;
  76. } else if (l == "C") {
  77. this->Natures.insert("org.eclipse.cdt.core.cnature");
  78. this->CEnabled = true;
  79. } else if (l == "Java") {
  80. this->Natures.insert("org.eclipse.jdt.core.javanature");
  81. }
  82. }
  83. }
  84. void cmExtraEclipseCDT4Generator::Generate()
  85. {
  86. cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
  87. const cmMakefile* mf = lg->GetMakefile();
  88. std::string eclipseVersion = mf->GetSafeDefinition("CMAKE_ECLIPSE_VERSION");
  89. cmsys::RegularExpression regex(".*([0-9]+\\.[0-9]+).*");
  90. if (regex.find(eclipseVersion.c_str())) {
  91. unsigned int majorVersion = 0;
  92. unsigned int minorVersion = 0;
  93. int res =
  94. sscanf(regex.match(1).c_str(), "%u.%u", &majorVersion, &minorVersion);
  95. if (res == 2) {
  96. int version = majorVersion * 1000 + minorVersion;
  97. if (version < 3006) // 3.6 is Helios
  98. {
  99. this->SupportsVirtualFolders = false;
  100. this->SupportsMachO64Parser = false;
  101. }
  102. if (version < 3007) // 3.7 is Indigo
  103. {
  104. this->SupportsGmakeErrorParser = false;
  105. }
  106. }
  107. }
  108. // TODO: Decide if these are local or member variables
  109. this->HomeDirectory = lg->GetSourceDirectory();
  110. this->HomeOutputDirectory = lg->GetBinaryDirectory();
  111. this->GenerateLinkedResources =
  112. mf->IsOn("CMAKE_ECLIPSE_GENERATE_LINKED_RESOURCES");
  113. this->IsOutOfSourceBuild =
  114. (this->HomeDirectory != this->HomeOutputDirectory);
  115. this->GenerateSourceProject =
  116. (this->IsOutOfSourceBuild &&
  117. mf->IsOn("CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT"));
  118. if (!this->GenerateSourceProject &&
  119. (mf->IsOn("ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT"))) {
  120. mf->IssueMessage(
  121. cmake::WARNING,
  122. "ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT is set to TRUE, "
  123. "but this variable is not supported anymore since CMake 2.8.7.\n"
  124. "Enable CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT instead.");
  125. }
  126. if (cmSystemTools::IsSubDirectory(this->HomeOutputDirectory,
  127. this->HomeDirectory)) {
  128. mf->IssueMessage(cmake::WARNING,
  129. "The build directory is a subdirectory "
  130. "of the source directory.\n"
  131. "This is not supported well by Eclipse. It is strongly "
  132. "recommended to use a build directory which is a "
  133. "sibling of the source directory.");
  134. }
  135. // NOTE: This is not good, since it pollutes the source tree. However,
  136. // Eclipse doesn't allow CVS/SVN to work when the .project is not in
  137. // the cvs/svn root directory. Hence, this is provided as an option.
  138. if (this->GenerateSourceProject) {
  139. // create .project file in the source tree
  140. this->CreateSourceProjectFile();
  141. }
  142. // create a .project file
  143. this->CreateProjectFile();
  144. // create a .cproject file
  145. this->CreateCProjectFile();
  146. }
  147. void cmExtraEclipseCDT4Generator::CreateSourceProjectFile()
  148. {
  149. assert(this->HomeDirectory != this->HomeOutputDirectory);
  150. // set up the project name: <project>-Source@<baseSourcePathName>
  151. cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
  152. std::string name =
  153. this->GenerateProjectName(lg->GetProjectName(), "Source",
  154. this->GetPathBasename(this->HomeDirectory));
  155. const std::string filename = this->HomeDirectory + "/.project";
  156. cmGeneratedFileStream fout(filename.c_str());
  157. if (!fout) {
  158. return;
  159. }
  160. cmXMLWriter xml(fout);
  161. xml.StartDocument("UTF-8");
  162. xml.StartElement("projectDescription");
  163. xml.Element("name", name);
  164. xml.Element("comment", "");
  165. xml.Element("projects", "");
  166. xml.Element("buildSpec", "");
  167. xml.Element("natures", "");
  168. xml.StartElement("linkedResources");
  169. if (this->SupportsVirtualFolders) {
  170. this->CreateLinksToSubprojects(xml, this->HomeDirectory);
  171. this->SrcLinkedResources.clear();
  172. }
  173. xml.EndElement(); // linkedResources
  174. xml.EndElement(); // projectDescription
  175. xml.EndDocument();
  176. }
  177. void cmExtraEclipseCDT4Generator::AddEnvVar(std::ostream& out,
  178. const char* envVar,
  179. cmLocalGenerator* lg)
  180. {
  181. cmMakefile* mf = lg->GetMakefile();
  182. // get the variables from the environment and from the cache and then
  183. // figure out which one to use:
  184. std::string envVarValue;
  185. const bool envVarSet = cmSystemTools::GetEnv(envVar, envVarValue);
  186. std::string cacheEntryName = "CMAKE_ECLIPSE_ENVVAR_";
  187. cacheEntryName += envVar;
  188. const char* cacheValue =
  189. lg->GetState()->GetInitializedCacheValue(cacheEntryName);
  190. // now we have both, decide which one to use
  191. std::string valueToUse;
  192. if (!envVarSet && cacheValue == nullptr) {
  193. // nothing known, do nothing
  194. valueToUse.clear();
  195. } else if (envVarSet && cacheValue == nullptr) {
  196. // The variable is in the env, but not in the cache. Use it and put it
  197. // in the cache
  198. valueToUse = envVarValue;
  199. mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(),
  200. cacheEntryName.c_str(), cmStateEnums::STRING, true);
  201. mf->GetCMakeInstance()->SaveCache(lg->GetBinaryDirectory());
  202. } else if (!envVarSet && cacheValue != nullptr) {
  203. // It is already in the cache, but not in the env, so use it from the cache
  204. valueToUse = cacheValue;
  205. } else {
  206. // It is both in the cache and in the env.
  207. // Use the version from the env. except if the value from the env is
  208. // completely contained in the value from the cache (for the case that we
  209. // now have a PATH without MSVC dirs in the env. but had the full PATH with
  210. // all MSVC dirs during the cmake run which stored the var in the cache:
  211. valueToUse = cacheValue;
  212. if (valueToUse.find(envVarValue) == std::string::npos) {
  213. valueToUse = envVarValue;
  214. mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(),
  215. cacheEntryName.c_str(), cmStateEnums::STRING,
  216. true);
  217. mf->GetCMakeInstance()->SaveCache(lg->GetBinaryDirectory());
  218. }
  219. }
  220. if (!valueToUse.empty()) {
  221. out << envVar << "=" << valueToUse << "|";
  222. }
  223. }
  224. void cmExtraEclipseCDT4Generator::CreateProjectFile()
  225. {
  226. cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
  227. cmMakefile* mf = lg->GetMakefile();
  228. const std::string filename = this->HomeOutputDirectory + "/.project";
  229. cmGeneratedFileStream fout(filename.c_str());
  230. if (!fout) {
  231. return;
  232. }
  233. std::string compilerId = mf->GetSafeDefinition("CMAKE_C_COMPILER_ID");
  234. if (compilerId.empty()) // no C compiler, try the C++ compiler:
  235. {
  236. compilerId = mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID");
  237. }
  238. cmXMLWriter xml(fout);
  239. xml.StartDocument("UTF-8");
  240. xml.StartElement("projectDescription");
  241. xml.Element("name", this->GenerateProjectName(
  242. lg->GetProjectName(),
  243. mf->GetSafeDefinition("CMAKE_BUILD_TYPE"),
  244. this->GetPathBasename(this->HomeOutputDirectory)));
  245. xml.Element("comment", "");
  246. xml.Element("projects", "");
  247. xml.StartElement("buildSpec");
  248. xml.StartElement("buildCommand");
  249. xml.Element("name", "org.eclipse.cdt.make.core.makeBuilder");
  250. xml.Element("triggers", "clean,full,incremental,");
  251. xml.StartElement("arguments");
  252. // use clean target
  253. AppendDictionary(xml, "org.eclipse.cdt.make.core.cleanBuildTarget", "clean");
  254. AppendDictionary(xml, "org.eclipse.cdt.make.core.enableCleanBuild", "true");
  255. AppendDictionary(xml, "org.eclipse.cdt.make.core.append_environment",
  256. "true");
  257. AppendDictionary(xml, "org.eclipse.cdt.make.core.stopOnError", "true");
  258. // set the make command
  259. AppendDictionary(xml, "org.eclipse.cdt.make.core.enabledIncrementalBuild",
  260. "true");
  261. AppendDictionary(
  262. xml, "org.eclipse.cdt.make.core.build.command",
  263. this->GetEclipsePath(mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM")));
  264. AppendDictionary(xml, "org.eclipse.cdt.make.core.contents",
  265. "org.eclipse.cdt.make.core.activeConfigSettings");
  266. AppendDictionary(xml, "org.eclipse.cdt.make.core.build.target.inc", "all");
  267. AppendDictionary(xml, "org.eclipse.cdt.make.core.build.arguments",
  268. mf->GetSafeDefinition("CMAKE_ECLIPSE_MAKE_ARGUMENTS"));
  269. AppendDictionary(xml, "org.eclipse.cdt.make.core.buildLocation",
  270. this->GetEclipsePath(this->HomeOutputDirectory));
  271. AppendDictionary(xml, "org.eclipse.cdt.make.core.useDefaultBuildCmd",
  272. "false");
  273. // set project specific environment
  274. std::ostringstream environment;
  275. environment << "VERBOSE=1|CMAKE_NO_VERBOSE=1|"; // verbose Makefile output
  276. // set vsvars32.bat environment available at CMake time,
  277. // but not necessarily when eclipse is open
  278. if (compilerId == "MSVC") {
  279. AddEnvVar(environment, "PATH", lg);
  280. AddEnvVar(environment, "INCLUDE", lg);
  281. AddEnvVar(environment, "LIB", lg);
  282. AddEnvVar(environment, "LIBPATH", lg);
  283. } else if (compilerId == "Intel") {
  284. // if the env.var is set, use this one and put it in the cache
  285. // if the env.var is not set, but the value is in the cache,
  286. // use it from the cache:
  287. AddEnvVar(environment, "INTEL_LICENSE_FILE", lg);
  288. }
  289. AppendDictionary(xml, "org.eclipse.cdt.make.core.environment",
  290. environment.str());
  291. AppendDictionary(xml, "org.eclipse.cdt.make.core.enableFullBuild", "true");
  292. AppendDictionary(xml, "org.eclipse.cdt.make.core.build.target.auto", "all");
  293. AppendDictionary(xml, "org.eclipse.cdt.make.core.enableAutoBuild", "false");
  294. AppendDictionary(xml, "org.eclipse.cdt.make.core.build.target.clean",
  295. "clean");
  296. AppendDictionary(xml, "org.eclipse.cdt.make.core.fullBuildTarget", "all");
  297. AppendDictionary(xml, "org.eclipse.cdt.make.core.buildArguments", "");
  298. AppendDictionary(xml, "org.eclipse.cdt.make.core.build.location",
  299. this->GetEclipsePath(this->HomeOutputDirectory));
  300. AppendDictionary(xml, "org.eclipse.cdt.make.core.autoBuildTarget", "all");
  301. // set error parsers
  302. std::ostringstream errorOutputParser;
  303. if (compilerId == "MSVC") {
  304. errorOutputParser << "org.eclipse.cdt.core.VCErrorParser;";
  305. } else if (compilerId == "Intel") {
  306. errorOutputParser << "org.eclipse.cdt.core.ICCErrorParser;";
  307. }
  308. if (this->SupportsGmakeErrorParser) {
  309. errorOutputParser << "org.eclipse.cdt.core.GmakeErrorParser;";
  310. } else {
  311. errorOutputParser << "org.eclipse.cdt.core.MakeErrorParser;";
  312. }
  313. errorOutputParser << "org.eclipse.cdt.core.GCCErrorParser;"
  314. "org.eclipse.cdt.core.GASErrorParser;"
  315. "org.eclipse.cdt.core.GLDErrorParser;";
  316. AppendDictionary(xml, "org.eclipse.cdt.core.errorOutputParser",
  317. errorOutputParser.str());
  318. xml.EndElement(); // arguments
  319. xml.EndElement(); // buildCommand
  320. xml.StartElement("buildCommand");
  321. xml.Element("name", "org.eclipse.cdt.make.core.ScannerConfigBuilder");
  322. xml.StartElement("arguments");
  323. xml.EndElement(); // arguments
  324. xml.EndElement(); // buildCommand
  325. xml.EndElement(); // buildSpec
  326. // set natures for c/c++ projects
  327. xml.StartElement("natures");
  328. xml.Element("nature", "org.eclipse.cdt.make.core.makeNature");
  329. xml.Element("nature", "org.eclipse.cdt.make.core.ScannerConfigNature");
  330. ;
  331. for (std::string const& n : this->Natures) {
  332. xml.Element("nature", n);
  333. }
  334. if (const char* extraNaturesProp =
  335. mf->GetState()->GetGlobalProperty("ECLIPSE_EXTRA_NATURES")) {
  336. std::vector<std::string> extraNatures;
  337. cmSystemTools::ExpandListArgument(extraNaturesProp, extraNatures);
  338. for (std::string const& n : extraNatures) {
  339. xml.Element("nature", n);
  340. }
  341. }
  342. xml.EndElement(); // natures
  343. xml.StartElement("linkedResources");
  344. // create linked resources
  345. if (this->IsOutOfSourceBuild) {
  346. // create a linked resource to CMAKE_SOURCE_DIR
  347. // (this is not done anymore for each project because of
  348. // https://gitlab.kitware.com/cmake/cmake/issues/9978 and because I found
  349. // it actually quite confusing in bigger projects with many directories and
  350. // projects, Alex
  351. std::string sourceLinkedResourceName = "[Source directory]";
  352. std::string linkSourceDirectory =
  353. this->GetEclipsePath(lg->GetCurrentSourceDirectory());
  354. // .project dir can't be subdir of a linked resource dir
  355. if (!cmSystemTools::IsSubDirectory(this->HomeOutputDirectory,
  356. linkSourceDirectory)) {
  357. this->AppendLinkedResource(xml, sourceLinkedResourceName,
  358. this->GetEclipsePath(linkSourceDirectory),
  359. LinkToFolder);
  360. this->SrcLinkedResources.push_back(std::move(sourceLinkedResourceName));
  361. }
  362. }
  363. if (this->SupportsVirtualFolders) {
  364. this->CreateLinksToSubprojects(xml, this->HomeOutputDirectory);
  365. this->CreateLinksForTargets(xml);
  366. }
  367. xml.EndElement(); // linkedResources
  368. xml.EndElement(); // projectDescription
  369. }
  370. void cmExtraEclipseCDT4Generator::WriteGroups(
  371. std::vector<cmSourceGroup> const& sourceGroups, std::string& linkName,
  372. cmXMLWriter& xml)
  373. {
  374. for (cmSourceGroup const& sg : sourceGroups) {
  375. std::string linkName3 = linkName;
  376. linkName3 += "/";
  377. linkName3 += sg.GetFullName();
  378. std::replace(linkName3.begin(), linkName3.end(), '\\', '/');
  379. this->AppendLinkedResource(xml, linkName3, "virtual:/virtual",
  380. VirtualFolder);
  381. std::vector<cmSourceGroup> const& children = sg.GetGroupChildren();
  382. if (!children.empty()) {
  383. this->WriteGroups(children, linkName, xml);
  384. }
  385. std::vector<const cmSourceFile*> sFiles = sg.GetSourceFiles();
  386. for (cmSourceFile const* file : sFiles) {
  387. std::string const& fullPath = file->GetFullPath();
  388. if (!cmSystemTools::FileIsDirectory(fullPath)) {
  389. std::string linkName4 = linkName3;
  390. linkName4 += "/";
  391. linkName4 += cmSystemTools::GetFilenameName(fullPath);
  392. this->AppendLinkedResource(xml, linkName4,
  393. this->GetEclipsePath(fullPath), LinkToFile);
  394. }
  395. }
  396. }
  397. }
  398. void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml)
  399. {
  400. std::string linkName = "[Targets]";
  401. this->AppendLinkedResource(xml, linkName, "virtual:/virtual", VirtualFolder);
  402. for (cmLocalGenerator* lg : this->GlobalGenerator->GetLocalGenerators()) {
  403. cmMakefile* makefile = lg->GetMakefile();
  404. const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
  405. for (cmGeneratorTarget* target : targets) {
  406. std::string linkName2 = linkName;
  407. linkName2 += "/";
  408. switch (target->GetType()) {
  409. case cmStateEnums::EXECUTABLE:
  410. case cmStateEnums::STATIC_LIBRARY:
  411. case cmStateEnums::SHARED_LIBRARY:
  412. case cmStateEnums::MODULE_LIBRARY:
  413. case cmStateEnums::OBJECT_LIBRARY: {
  414. const char* prefix =
  415. (target->GetType() == cmStateEnums::EXECUTABLE ? "[exe] "
  416. : "[lib] ");
  417. linkName2 += prefix;
  418. linkName2 += target->GetName();
  419. this->AppendLinkedResource(xml, linkName2, "virtual:/virtual",
  420. VirtualFolder);
  421. if (!this->GenerateLinkedResources) {
  422. break; // skip generating the linked resources to the source files
  423. }
  424. std::vector<cmSourceGroup> sourceGroups =
  425. makefile->GetSourceGroups();
  426. // get the files from the source lists then add them to the groups
  427. cmGeneratorTarget* gt = const_cast<cmGeneratorTarget*>(target);
  428. std::vector<cmSourceFile*> files;
  429. gt->GetSourceFiles(files,
  430. makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
  431. for (cmSourceFile* sf : files) {
  432. // Add the file to the list of sources.
  433. std::string const& source = sf->GetFullPath();
  434. cmSourceGroup* sourceGroup =
  435. makefile->FindSourceGroup(source, sourceGroups);
  436. sourceGroup->AssignSource(sf);
  437. }
  438. this->WriteGroups(sourceGroups, linkName2, xml);
  439. } break;
  440. // ignore all others:
  441. default:
  442. break;
  443. }
  444. }
  445. }
  446. }
  447. void cmExtraEclipseCDT4Generator::CreateLinksToSubprojects(
  448. cmXMLWriter& xml, const std::string& baseDir)
  449. {
  450. if (!this->GenerateLinkedResources) {
  451. return;
  452. }
  453. // for each sub project create a linked resource to the source dir
  454. // - only if it is an out-of-source build
  455. this->AppendLinkedResource(xml, "[Subprojects]", "virtual:/virtual",
  456. VirtualFolder);
  457. for (auto const& it : this->GlobalGenerator->GetProjectMap()) {
  458. std::string linkSourceDirectory =
  459. this->GetEclipsePath(it.second[0]->GetCurrentSourceDirectory());
  460. // a linked resource must not point to a parent directory of .project or
  461. // .project itself
  462. if ((baseDir != linkSourceDirectory) &&
  463. !cmSystemTools::IsSubDirectory(baseDir, linkSourceDirectory)) {
  464. std::string linkName = "[Subprojects]/";
  465. linkName += it.first;
  466. this->AppendLinkedResource(xml, linkName,
  467. this->GetEclipsePath(linkSourceDirectory),
  468. LinkToFolder);
  469. // Don't add it to the srcLinkedResources, because listing multiple
  470. // directories confuses the Eclipse indexer (#13596).
  471. }
  472. }
  473. }
  474. void cmExtraEclipseCDT4Generator::AppendIncludeDirectories(
  475. cmXMLWriter& xml, const std::vector<std::string>& includeDirs,
  476. std::set<std::string>& emittedDirs)
  477. {
  478. for (std::string const& inc : includeDirs) {
  479. if (!inc.empty()) {
  480. std::string dir = cmSystemTools::CollapseFullPath(inc);
  481. // handle framework include dirs on OSX, the remainder after the
  482. // Frameworks/ part has to be stripped
  483. // /System/Library/Frameworks/GLUT.framework/Headers
  484. cmsys::RegularExpression frameworkRx("(.+/Frameworks)/.+\\.framework/");
  485. if (frameworkRx.find(dir.c_str())) {
  486. dir = frameworkRx.match(1);
  487. }
  488. if (emittedDirs.find(dir) == emittedDirs.end()) {
  489. emittedDirs.insert(dir);
  490. xml.StartElement("pathentry");
  491. xml.Attribute("include",
  492. cmExtraEclipseCDT4Generator::GetEclipsePath(dir));
  493. xml.Attribute("kind", "inc");
  494. xml.Attribute("path", "");
  495. xml.Attribute("system", "true");
  496. xml.EndElement();
  497. }
  498. }
  499. }
  500. }
  501. void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
  502. {
  503. std::set<std::string> emmited;
  504. cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
  505. const cmMakefile* mf = lg->GetMakefile();
  506. const std::string filename = this->HomeOutputDirectory + "/.cproject";
  507. cmGeneratedFileStream fout(filename.c_str());
  508. if (!fout) {
  509. return;
  510. }
  511. cmXMLWriter xml(fout);
  512. // add header
  513. xml.StartDocument("UTF-8");
  514. xml.ProcessingInstruction("fileVersion", "4.0.0");
  515. xml.StartElement("cproject");
  516. xml.StartElement("storageModule");
  517. xml.Attribute("moduleId", "org.eclipse.cdt.core.settings");
  518. xml.StartElement("cconfiguration");
  519. xml.Attribute("id", "org.eclipse.cdt.core.default.config.1");
  520. // Configuration settings...
  521. xml.StartElement("storageModule");
  522. xml.Attribute("buildSystemId",
  523. "org.eclipse.cdt.core.defaultConfigDataProvider");
  524. xml.Attribute("id", "org.eclipse.cdt.core.default.config.1");
  525. xml.Attribute("moduleId", "org.eclipse.cdt.core.settings");
  526. xml.Attribute("name", "Configuration");
  527. xml.Element("externalSettings");
  528. xml.StartElement("extensions");
  529. // TODO: refactor this out...
  530. std::string executableFormat =
  531. mf->GetSafeDefinition("CMAKE_EXECUTABLE_FORMAT");
  532. if (executableFormat == "ELF") {
  533. xml.StartElement("extension");
  534. xml.Attribute("id", "org.eclipse.cdt.core.ELF");
  535. xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
  536. xml.EndElement(); // extension
  537. xml.StartElement("extension");
  538. xml.Attribute("id", "org.eclipse.cdt.core.GNU_ELF");
  539. xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
  540. AppendAttribute(xml, "addr2line");
  541. AppendAttribute(xml, "c++filt");
  542. xml.EndElement(); // extension
  543. } else {
  544. std::string systemName = mf->GetSafeDefinition("CMAKE_SYSTEM_NAME");
  545. if (systemName == "CYGWIN") {
  546. xml.StartElement("extension");
  547. xml.Attribute("id", "org.eclipse.cdt.core.Cygwin_PE");
  548. xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
  549. AppendAttribute(xml, "addr2line");
  550. AppendAttribute(xml, "c++filt");
  551. AppendAttribute(xml, "cygpath");
  552. AppendAttribute(xml, "nm");
  553. xml.EndElement(); // extension
  554. } else if (systemName == "Windows") {
  555. xml.StartElement("extension");
  556. xml.Attribute("id", "org.eclipse.cdt.core.PE");
  557. xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
  558. xml.EndElement(); // extension
  559. } else if (systemName == "Darwin") {
  560. xml.StartElement("extension");
  561. xml.Attribute("id", this->SupportsMachO64Parser
  562. ? "org.eclipse.cdt.core.MachO64"
  563. : "org.eclipse.cdt.core.MachO");
  564. xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
  565. AppendAttribute(xml, "c++filt");
  566. xml.EndElement(); // extension
  567. } else {
  568. // *** Should never get here ***
  569. xml.Element("error_toolchain_type");
  570. }
  571. }
  572. xml.EndElement(); // extensions
  573. xml.EndElement(); // storageModule
  574. // ???
  575. xml.StartElement("storageModule");
  576. xml.Attribute("moduleId", "org.eclipse.cdt.core.language.mapping");
  577. xml.Element("project-mappings");
  578. xml.EndElement(); // storageModule
  579. // ???
  580. xml.StartElement("storageModule");
  581. xml.Attribute("moduleId", "org.eclipse.cdt.core.externalSettings");
  582. xml.EndElement(); // storageModule
  583. // set the path entries (includes, libs, source dirs, etc.)
  584. xml.StartElement("storageModule");
  585. xml.Attribute("moduleId", "org.eclipse.cdt.core.pathentry");
  586. // for each sub project with a linked resource to the source dir:
  587. // - make it type 'src'
  588. // - and exclude it from type 'out'
  589. std::string excludeFromOut;
  590. /* I don't know what the pathentry kind="src" are good for, e.g.
  591. * autocompletion
  592. * works also without them. Done wrong, the indexer complains, see #12417
  593. * and #12213.
  594. * According to #13596, this entry at least limits the directories the
  595. * indexer is searching for files. So now the "src" entry contains only
  596. * the linked resource to CMAKE_SOURCE_DIR.
  597. * The CDT documentation is very terse on that:
  598. * "CDT_SOURCE: Entry kind constant describing a path entry identifying a
  599. * folder containing source code to be compiled."
  600. * Also on the cdt-dev list didn't bring any information:
  601. * http://web.archiveorange.com/archive/v/B4NlJDNIpYoOS1SbxFNy
  602. * Alex */
  603. // include subprojects directory to the src pathentry
  604. // eclipse cdt indexer uses this entries as reference to index source files
  605. if (this->GenerateLinkedResources) {
  606. xml.StartElement("pathentry");
  607. xml.Attribute("kind", "src");
  608. xml.Attribute("path", "[Subprojects]");
  609. xml.EndElement();
  610. }
  611. for (std::string const& p : this->SrcLinkedResources) {
  612. xml.StartElement("pathentry");
  613. xml.Attribute("kind", "src");
  614. xml.Attribute("path", p);
  615. xml.EndElement();
  616. // exlude source directory from output search path
  617. // - only if not named the same as an output directory
  618. if (!cmSystemTools::FileIsDirectory(
  619. std::string(this->HomeOutputDirectory + "/" + p))) {
  620. excludeFromOut += p + "/|";
  621. }
  622. }
  623. excludeFromOut += "**/CMakeFiles/";
  624. xml.StartElement("pathentry");
  625. xml.Attribute("excluding", excludeFromOut);
  626. xml.Attribute("kind", "out");
  627. xml.Attribute("path", "");
  628. xml.EndElement();
  629. // add pre-processor definitions to allow eclipse to gray out sections
  630. emmited.clear();
  631. for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
  632. if (const char* cdefs =
  633. lgen->GetMakefile()->GetProperty("COMPILE_DEFINITIONS")) {
  634. // Expand the list.
  635. std::vector<std::string> defs;
  636. cmGeneratorExpression::Split(cdefs, defs);
  637. for (std::string const& d : defs) {
  638. if (cmGeneratorExpression::Find(d) != std::string::npos) {
  639. continue;
  640. }
  641. std::string::size_type equals = d.find('=', 0);
  642. std::string::size_type enddef = d.length();
  643. std::string def;
  644. std::string val;
  645. if (equals != std::string::npos && equals < enddef) {
  646. // we have -DFOO=BAR
  647. def = d.substr(0, equals);
  648. val = d.substr(equals + 1, enddef - equals + 1);
  649. } else {
  650. // we have -DFOO
  651. def = d;
  652. }
  653. // insert the definition if not already added.
  654. if (emmited.find(def) == emmited.end()) {
  655. emmited.insert(def);
  656. xml.StartElement("pathentry");
  657. xml.Attribute("kind", "mac");
  658. xml.Attribute("name", def);
  659. xml.Attribute("path", "");
  660. xml.Attribute("value", val);
  661. xml.EndElement();
  662. }
  663. }
  664. }
  665. }
  666. // add system defined c macros
  667. const char* cDefs =
  668. mf->GetDefinition("CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS");
  669. if (this->CEnabled && cDefs) {
  670. // Expand the list.
  671. std::vector<std::string> defs;
  672. cmSystemTools::ExpandListArgument(cDefs, defs, true);
  673. // the list must contain only definition-value pairs:
  674. if ((defs.size() % 2) == 0) {
  675. std::vector<std::string>::const_iterator di = defs.begin();
  676. while (di != defs.end()) {
  677. std::string def = *di;
  678. ++di;
  679. std::string val;
  680. if (di != defs.end()) {
  681. val = *di;
  682. ++di;
  683. }
  684. // insert the definition if not already added.
  685. if (emmited.find(def) == emmited.end()) {
  686. emmited.insert(def);
  687. xml.StartElement("pathentry");
  688. xml.Attribute("kind", "mac");
  689. xml.Attribute("name", def);
  690. xml.Attribute("path", "");
  691. xml.Attribute("value", val);
  692. xml.EndElement();
  693. }
  694. }
  695. }
  696. }
  697. // add system defined c++ macros
  698. const char* cxxDefs =
  699. mf->GetDefinition("CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS");
  700. if (this->CXXEnabled && cxxDefs) {
  701. // Expand the list.
  702. std::vector<std::string> defs;
  703. cmSystemTools::ExpandListArgument(cxxDefs, defs, true);
  704. // the list must contain only definition-value pairs:
  705. if ((defs.size() % 2) == 0) {
  706. std::vector<std::string>::const_iterator di = defs.begin();
  707. while (di != defs.end()) {
  708. std::string def = *di;
  709. ++di;
  710. std::string val;
  711. if (di != defs.end()) {
  712. val = *di;
  713. ++di;
  714. }
  715. // insert the definition if not already added.
  716. if (emmited.find(def) == emmited.end()) {
  717. emmited.insert(def);
  718. xml.StartElement("pathentry");
  719. xml.Attribute("kind", "mac");
  720. xml.Attribute("name", def);
  721. xml.Attribute("path", "");
  722. xml.Attribute("value", val);
  723. xml.EndElement();
  724. }
  725. }
  726. }
  727. }
  728. // include dirs
  729. emmited.clear();
  730. for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
  731. const std::vector<cmGeneratorTarget*>& targets =
  732. lgen->GetGeneratorTargets();
  733. for (cmGeneratorTarget* target : targets) {
  734. std::vector<std::string> includeDirs;
  735. std::string config = mf->GetSafeDefinition("CMAKE_BUILD_TYPE");
  736. lgen->GetIncludeDirectories(includeDirs, target, "C", config);
  737. this->AppendIncludeDirectories(xml, includeDirs, emmited);
  738. }
  739. }
  740. // now also the system include directories, in case we found them in
  741. // CMakeSystemSpecificInformation.cmake. This makes Eclipse find the
  742. // standard headers.
  743. std::string compiler = mf->GetSafeDefinition("CMAKE_C_COMPILER");
  744. if (this->CEnabled && !compiler.empty()) {
  745. std::string systemIncludeDirs =
  746. mf->GetSafeDefinition("CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS");
  747. std::vector<std::string> dirs;
  748. cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
  749. this->AppendIncludeDirectories(xml, dirs, emmited);
  750. }
  751. compiler = mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
  752. if (this->CXXEnabled && !compiler.empty()) {
  753. std::string systemIncludeDirs =
  754. mf->GetSafeDefinition("CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS");
  755. std::vector<std::string> dirs;
  756. cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
  757. this->AppendIncludeDirectories(xml, dirs, emmited);
  758. }
  759. xml.EndElement(); // storageModule
  760. // add build targets
  761. xml.StartElement("storageModule");
  762. xml.Attribute("moduleId", "org.eclipse.cdt.make.core.buildtargets");
  763. xml.StartElement("buildTargets");
  764. emmited.clear();
  765. const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  766. const std::string makeArgs =
  767. mf->GetSafeDefinition("CMAKE_ECLIPSE_MAKE_ARGUMENTS");
  768. cmGlobalGenerator* generator =
  769. const_cast<cmGlobalGenerator*>(this->GlobalGenerator);
  770. std::string allTarget;
  771. std::string cleanTarget;
  772. if (generator->GetAllTargetName()) {
  773. allTarget = generator->GetAllTargetName();
  774. }
  775. if (generator->GetCleanTargetName()) {
  776. cleanTarget = generator->GetCleanTargetName();
  777. }
  778. // add all executable and library targets and some of the GLOBAL
  779. // and UTILITY targets
  780. for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
  781. const std::vector<cmGeneratorTarget*>& targets =
  782. lgen->GetGeneratorTargets();
  783. std::string subdir = lgen->ConvertToRelativePath(
  784. this->HomeOutputDirectory, lgen->GetCurrentBinaryDirectory());
  785. if (subdir == ".") {
  786. subdir.clear();
  787. }
  788. for (cmGeneratorTarget* target : targets) {
  789. std::string targetName = target->GetName();
  790. switch (target->GetType()) {
  791. case cmStateEnums::GLOBAL_TARGET: {
  792. // Only add the global targets from CMAKE_BINARY_DIR,
  793. // not from the subdirs
  794. if (subdir.empty()) {
  795. this->AppendTarget(xml, targetName, make, makeArgs, subdir, ": ");
  796. }
  797. } break;
  798. case cmStateEnums::UTILITY:
  799. // Add all utility targets, except the Nightly/Continuous/
  800. // Experimental-"sub"targets as e.g. NightlyStart
  801. if (((targetName.find("Nightly") == 0) &&
  802. (targetName != "Nightly")) ||
  803. ((targetName.find("Continuous") == 0) &&
  804. (targetName != "Continuous")) ||
  805. ((targetName.find("Experimental") == 0) &&
  806. (targetName != "Experimental"))) {
  807. break;
  808. }
  809. this->AppendTarget(xml, targetName, make, makeArgs, subdir, ": ");
  810. break;
  811. case cmStateEnums::EXECUTABLE:
  812. case cmStateEnums::STATIC_LIBRARY:
  813. case cmStateEnums::SHARED_LIBRARY:
  814. case cmStateEnums::MODULE_LIBRARY:
  815. case cmStateEnums::OBJECT_LIBRARY: {
  816. const char* prefix =
  817. (target->GetType() == cmStateEnums::EXECUTABLE ? "[exe] "
  818. : "[lib] ");
  819. this->AppendTarget(xml, targetName, make, makeArgs, subdir, prefix);
  820. std::string fastTarget = targetName;
  821. fastTarget += "/fast";
  822. this->AppendTarget(xml, fastTarget, make, makeArgs, subdir, prefix);
  823. // Add Build and Clean targets in the virtual folder of targets:
  824. if (this->SupportsVirtualFolders) {
  825. std::string virtDir = "[Targets]/";
  826. virtDir += prefix;
  827. virtDir += targetName;
  828. std::string buildArgs = "-C \"";
  829. buildArgs += lgen->GetBinaryDirectory();
  830. buildArgs += "\" ";
  831. buildArgs += makeArgs;
  832. this->AppendTarget(xml, "Build", make, buildArgs, virtDir, "",
  833. targetName.c_str());
  834. std::string cleanArgs = "-E chdir \"";
  835. cleanArgs += lgen->GetCurrentBinaryDirectory();
  836. cleanArgs += "\" \"";
  837. cleanArgs += cmSystemTools::GetCMakeCommand();
  838. cleanArgs += "\" -P \"";
  839. cmGeneratorTarget* gt = target;
  840. cleanArgs += lgen->GetTargetDirectory(gt);
  841. cleanArgs += "/cmake_clean.cmake\"";
  842. this->AppendTarget(xml, "Clean", cmSystemTools::GetCMakeCommand(),
  843. cleanArgs, virtDir, "", "");
  844. }
  845. } break;
  846. default:
  847. break;
  848. }
  849. }
  850. // insert the all and clean targets in every subdir
  851. if (!allTarget.empty()) {
  852. this->AppendTarget(xml, allTarget, make, makeArgs, subdir, ": ");
  853. }
  854. if (!cleanTarget.empty()) {
  855. this->AppendTarget(xml, cleanTarget, make, makeArgs, subdir, ": ");
  856. }
  857. // insert rules for compiling, preprocessing and assembling individual
  858. // files
  859. std::vector<std::string> objectFileTargets;
  860. lg->GetIndividualFileTargets(objectFileTargets);
  861. for (std::string const& f : objectFileTargets) {
  862. const char* prefix = "[obj] ";
  863. if (f[f.length() - 1] == 's') {
  864. prefix = "[to asm] ";
  865. } else if (f[f.length() - 1] == 'i') {
  866. prefix = "[pre] ";
  867. }
  868. this->AppendTarget(xml, f, make, makeArgs, subdir, prefix);
  869. }
  870. }
  871. xml.EndElement(); // buildTargets
  872. xml.EndElement(); // storageModule
  873. this->AppendStorageScanners(xml, *mf);
  874. xml.EndElement(); // cconfiguration
  875. xml.EndElement(); // storageModule
  876. xml.StartElement("storageModule");
  877. xml.Attribute("moduleId", "cdtBuildSystem");
  878. xml.Attribute("version", "4.0.0");
  879. xml.StartElement("project");
  880. xml.Attribute("id", std::string(lg->GetProjectName()) + ".null.1");
  881. xml.Attribute("name", lg->GetProjectName());
  882. xml.EndElement(); // project
  883. xml.EndElement(); // storageModule
  884. xml.EndElement(); // cproject
  885. }
  886. std::string cmExtraEclipseCDT4Generator::GetEclipsePath(
  887. const std::string& path)
  888. {
  889. #if defined(__CYGWIN__)
  890. std::string cmd = "cygpath -m " + path;
  891. std::string out;
  892. if (!cmSystemTools::RunSingleCommand(cmd.c_str(), &out, &out)) {
  893. return path;
  894. } else {
  895. out.erase(out.find_last_of('\n'));
  896. return out;
  897. }
  898. #else
  899. return path;
  900. #endif
  901. }
  902. std::string cmExtraEclipseCDT4Generator::GetPathBasename(
  903. const std::string& path)
  904. {
  905. std::string outputBasename = path;
  906. while (!outputBasename.empty() &&
  907. (outputBasename[outputBasename.size() - 1] == '/' ||
  908. outputBasename[outputBasename.size() - 1] == '\\')) {
  909. outputBasename.resize(outputBasename.size() - 1);
  910. }
  911. std::string::size_type loc = outputBasename.find_last_of("/\\");
  912. if (loc != std::string::npos) {
  913. outputBasename = outputBasename.substr(loc + 1);
  914. }
  915. return outputBasename;
  916. }
  917. std::string cmExtraEclipseCDT4Generator::GenerateProjectName(
  918. const std::string& name, const std::string& type, const std::string& path)
  919. {
  920. return name + (type.empty() ? "" : "-") + type + "@" + path;
  921. }
  922. // Helper functions
  923. void cmExtraEclipseCDT4Generator::AppendStorageScanners(
  924. cmXMLWriter& xml, const cmMakefile& makefile)
  925. {
  926. // we need the "make" and the C (or C++) compiler which are used, Alex
  927. std::string make = makefile.GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  928. std::string compiler = makefile.GetSafeDefinition("CMAKE_C_COMPILER");
  929. std::string arg1 = makefile.GetSafeDefinition("CMAKE_C_COMPILER_ARG1");
  930. if (compiler.empty()) {
  931. compiler = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER");
  932. arg1 = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER_ARG1");
  933. }
  934. if (compiler.empty()) // Hmm, what to do now ?
  935. {
  936. compiler = "gcc";
  937. }
  938. // the following right now hardcodes gcc behaviour :-/
  939. std::string compilerArgs =
  940. "-E -P -v -dD ${plugin_state_location}/${specs_file}";
  941. if (!arg1.empty()) {
  942. arg1 += " ";
  943. compilerArgs = arg1 + compilerArgs;
  944. }
  945. xml.StartElement("storageModule");
  946. xml.Attribute("moduleId", "scannerConfiguration");
  947. xml.StartElement("autodiscovery");
  948. xml.Attribute("enabled", "true");
  949. xml.Attribute("problemReportingEnabled", "true");
  950. xml.Attribute("selectedProfileId",
  951. "org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile");
  952. xml.EndElement(); // autodiscovery
  953. cmExtraEclipseCDT4Generator::AppendScannerProfile(
  954. xml, "org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile", true,
  955. "", true, "specsFile", compilerArgs, compiler, true, true);
  956. cmExtraEclipseCDT4Generator::AppendScannerProfile(
  957. xml, "org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile", true, "",
  958. true, "makefileGenerator", "-f ${project_name}_scd.mk", make, true, true);
  959. xml.EndElement(); // storageModule
  960. }
  961. // The prefix is prepended before the actual name of the target. The purpose
  962. // of that is to sort the targets in the view of Eclipse, so that at first
  963. // the global/utility/all/clean targets appear ": ", then the executable
  964. // targets "[exe] ", then the libraries "[lib]", then the rules for the
  965. // object files "[obj]", then for preprocessing only "[pre] " and
  966. // finally the assembly files "[to asm] ". Note the "to" in "to asm",
  967. // without it, "asm" would be the first targets in the list, with the "to"
  968. // they are the last targets, which makes more sense.
  969. void cmExtraEclipseCDT4Generator::AppendTarget(
  970. cmXMLWriter& xml, const std::string& target, const std::string& make,
  971. const std::string& makeArgs, const std::string& path, const char* prefix,
  972. const char* makeTarget)
  973. {
  974. xml.StartElement("target");
  975. xml.Attribute("name", prefix + target);
  976. xml.Attribute("path", path);
  977. xml.Attribute("targetID", "org.eclipse.cdt.make.MakeTargetBuilder");
  978. xml.Element("buildCommand",
  979. cmExtraEclipseCDT4Generator::GetEclipsePath(make));
  980. xml.Element("buildArguments", makeArgs);
  981. xml.Element("buildTarget", makeTarget ? makeTarget : target.c_str());
  982. xml.Element("stopOnError", "true");
  983. xml.Element("useDefaultCommand", "false");
  984. xml.EndElement();
  985. }
  986. void cmExtraEclipseCDT4Generator::AppendScannerProfile(
  987. cmXMLWriter& xml, const std::string& profileID, bool openActionEnabled,
  988. const std::string& openActionFilePath, bool pParserEnabled,
  989. const std::string& scannerInfoProviderID,
  990. const std::string& runActionArguments, const std::string& runActionCommand,
  991. bool runActionUseDefault, bool sipParserEnabled)
  992. {
  993. xml.StartElement("profile");
  994. xml.Attribute("id", profileID);
  995. xml.StartElement("buildOutputProvider");
  996. xml.StartElement("openAction");
  997. xml.Attribute("enabled", openActionEnabled ? "true" : "false");
  998. xml.Attribute("filePath", openActionFilePath);
  999. xml.EndElement(); // openAction
  1000. xml.StartElement("parser");
  1001. xml.Attribute("enabled", pParserEnabled ? "true" : "false");
  1002. xml.EndElement(); // parser
  1003. xml.EndElement(); // buildOutputProvider
  1004. xml.StartElement("scannerInfoProvider");
  1005. xml.Attribute("id", scannerInfoProviderID);
  1006. xml.StartElement("runAction");
  1007. xml.Attribute("arguments", runActionArguments);
  1008. xml.Attribute("command", runActionCommand);
  1009. xml.Attribute("useDefault", runActionUseDefault ? "true" : "false");
  1010. xml.EndElement(); // runAction
  1011. xml.StartElement("parser");
  1012. xml.Attribute("enabled", sipParserEnabled ? "true" : "false");
  1013. xml.EndElement(); // parser
  1014. xml.EndElement(); // scannerInfoProvider
  1015. xml.EndElement(); // profile
  1016. }
  1017. void cmExtraEclipseCDT4Generator::AppendLinkedResource(cmXMLWriter& xml,
  1018. const std::string& name,
  1019. const std::string& path,
  1020. LinkType linkType)
  1021. {
  1022. const char* locationTag = "location";
  1023. int typeTag = 2;
  1024. if (linkType == VirtualFolder) // ... and not a linked folder
  1025. {
  1026. locationTag = "locationURI";
  1027. }
  1028. if (linkType == LinkToFile) {
  1029. typeTag = 1;
  1030. }
  1031. xml.StartElement("link");
  1032. xml.Element("name", name);
  1033. xml.Element("type", typeTag);
  1034. xml.Element(locationTag, path);
  1035. xml.EndElement();
  1036. }