cmExtraEclipseCDT4Generator.cxx 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  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)) {
  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);
  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 std::string* 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);
  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",
  242. this->GenerateProjectName(
  243. lg->GetProjectName(),
  244. mf->GetSafeDefinition("CMAKE_BUILD_TYPE"),
  245. this->GetPathBasename(this->HomeOutputDirectory)));
  246. xml.Element("comment", "");
  247. xml.Element("projects", "");
  248. xml.StartElement("buildSpec");
  249. xml.StartElement("buildCommand");
  250. xml.Element("name", "org.eclipse.cdt.make.core.makeBuilder");
  251. xml.Element("triggers", "clean,full,incremental,");
  252. xml.StartElement("arguments");
  253. // use clean target
  254. AppendDictionary(xml, "org.eclipse.cdt.make.core.cleanBuildTarget", "clean");
  255. AppendDictionary(xml, "org.eclipse.cdt.make.core.enableCleanBuild", "true");
  256. AppendDictionary(xml, "org.eclipse.cdt.make.core.append_environment",
  257. "true");
  258. AppendDictionary(xml, "org.eclipse.cdt.make.core.stopOnError", "true");
  259. // set the make command
  260. AppendDictionary(xml, "org.eclipse.cdt.make.core.enabledIncrementalBuild",
  261. "true");
  262. AppendDictionary(
  263. xml, "org.eclipse.cdt.make.core.build.command",
  264. this->GetEclipsePath(mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM")));
  265. AppendDictionary(xml, "org.eclipse.cdt.make.core.contents",
  266. "org.eclipse.cdt.make.core.activeConfigSettings");
  267. AppendDictionary(xml, "org.eclipse.cdt.make.core.build.target.inc", "all");
  268. AppendDictionary(xml, "org.eclipse.cdt.make.core.build.arguments",
  269. mf->GetSafeDefinition("CMAKE_ECLIPSE_MAKE_ARGUMENTS"));
  270. AppendDictionary(xml, "org.eclipse.cdt.make.core.buildLocation",
  271. this->GetEclipsePath(this->HomeOutputDirectory));
  272. AppendDictionary(xml, "org.eclipse.cdt.make.core.useDefaultBuildCmd",
  273. "false");
  274. // set project specific environment
  275. std::ostringstream environment;
  276. environment << "VERBOSE=1|CMAKE_NO_VERBOSE=1|"; // verbose Makefile output
  277. // set vsvars32.bat environment available at CMake time,
  278. // but not necessarily when eclipse is open
  279. if (compilerId == "MSVC") {
  280. AddEnvVar(environment, "PATH", lg);
  281. AddEnvVar(environment, "INCLUDE", lg);
  282. AddEnvVar(environment, "LIB", lg);
  283. AddEnvVar(environment, "LIBPATH", lg);
  284. } else if (compilerId == "Intel") {
  285. // if the env.var is set, use this one and put it in the cache
  286. // if the env.var is not set, but the value is in the cache,
  287. // use it from the cache:
  288. AddEnvVar(environment, "INTEL_LICENSE_FILE", lg);
  289. }
  290. AppendDictionary(xml, "org.eclipse.cdt.make.core.environment",
  291. environment.str());
  292. AppendDictionary(xml, "org.eclipse.cdt.make.core.enableFullBuild", "true");
  293. AppendDictionary(xml, "org.eclipse.cdt.make.core.build.target.auto", "all");
  294. AppendDictionary(xml, "org.eclipse.cdt.make.core.enableAutoBuild", "false");
  295. AppendDictionary(xml, "org.eclipse.cdt.make.core.build.target.clean",
  296. "clean");
  297. AppendDictionary(xml, "org.eclipse.cdt.make.core.fullBuildTarget", "all");
  298. AppendDictionary(xml, "org.eclipse.cdt.make.core.buildArguments", "");
  299. AppendDictionary(xml, "org.eclipse.cdt.make.core.build.location",
  300. this->GetEclipsePath(this->HomeOutputDirectory));
  301. AppendDictionary(xml, "org.eclipse.cdt.make.core.autoBuildTarget", "all");
  302. // set error parsers
  303. std::ostringstream errorOutputParser;
  304. if (compilerId == "MSVC") {
  305. errorOutputParser << "org.eclipse.cdt.core.VCErrorParser;";
  306. } else if (compilerId == "Intel") {
  307. errorOutputParser << "org.eclipse.cdt.core.ICCErrorParser;";
  308. }
  309. if (this->SupportsGmakeErrorParser) {
  310. errorOutputParser << "org.eclipse.cdt.core.GmakeErrorParser;";
  311. } else {
  312. errorOutputParser << "org.eclipse.cdt.core.MakeErrorParser;";
  313. }
  314. errorOutputParser << "org.eclipse.cdt.core.GCCErrorParser;"
  315. "org.eclipse.cdt.core.GASErrorParser;"
  316. "org.eclipse.cdt.core.GLDErrorParser;";
  317. AppendDictionary(xml, "org.eclipse.cdt.core.errorOutputParser",
  318. errorOutputParser.str());
  319. xml.EndElement(); // arguments
  320. xml.EndElement(); // buildCommand
  321. xml.StartElement("buildCommand");
  322. xml.Element("name", "org.eclipse.cdt.make.core.ScannerConfigBuilder");
  323. xml.StartElement("arguments");
  324. xml.EndElement(); // arguments
  325. xml.EndElement(); // buildCommand
  326. xml.EndElement(); // buildSpec
  327. // set natures for c/c++ projects
  328. xml.StartElement("natures");
  329. xml.Element("nature", "org.eclipse.cdt.make.core.makeNature");
  330. xml.Element("nature", "org.eclipse.cdt.make.core.ScannerConfigNature");
  331. ;
  332. for (std::string const& n : this->Natures) {
  333. xml.Element("nature", n);
  334. }
  335. if (const char* extraNaturesProp =
  336. mf->GetState()->GetGlobalProperty("ECLIPSE_EXTRA_NATURES")) {
  337. std::vector<std::string> extraNatures;
  338. cmSystemTools::ExpandListArgument(extraNaturesProp, extraNatures);
  339. for (std::string const& n : extraNatures) {
  340. xml.Element("nature", n);
  341. }
  342. }
  343. xml.EndElement(); // natures
  344. xml.StartElement("linkedResources");
  345. // create linked resources
  346. if (this->IsOutOfSourceBuild) {
  347. // create a linked resource to CMAKE_SOURCE_DIR
  348. // (this is not done anymore for each project because of
  349. // https://gitlab.kitware.com/cmake/cmake/issues/9978 and because I found
  350. // it actually quite confusing in bigger projects with many directories and
  351. // projects, Alex
  352. std::string sourceLinkedResourceName = "[Source directory]";
  353. std::string linkSourceDirectory =
  354. this->GetEclipsePath(lg->GetCurrentSourceDirectory());
  355. // .project dir can't be subdir of a linked resource dir
  356. if (!cmSystemTools::IsSubDirectory(this->HomeOutputDirectory,
  357. linkSourceDirectory)) {
  358. this->AppendLinkedResource(xml, sourceLinkedResourceName,
  359. this->GetEclipsePath(linkSourceDirectory),
  360. LinkToFolder);
  361. this->SrcLinkedResources.push_back(std::move(sourceLinkedResourceName));
  362. }
  363. }
  364. if (this->SupportsVirtualFolders) {
  365. this->CreateLinksToSubprojects(xml, this->HomeOutputDirectory);
  366. this->CreateLinksForTargets(xml);
  367. }
  368. xml.EndElement(); // linkedResources
  369. xml.EndElement(); // projectDescription
  370. }
  371. void cmExtraEclipseCDT4Generator::WriteGroups(
  372. std::vector<cmSourceGroup> const& sourceGroups, std::string& linkName,
  373. cmXMLWriter& xml)
  374. {
  375. for (cmSourceGroup const& sg : sourceGroups) {
  376. std::string linkName3 = linkName;
  377. linkName3 += "/";
  378. linkName3 += sg.GetFullName();
  379. std::replace(linkName3.begin(), linkName3.end(), '\\', '/');
  380. this->AppendLinkedResource(xml, linkName3, "virtual:/virtual",
  381. VirtualFolder);
  382. std::vector<cmSourceGroup> const& children = sg.GetGroupChildren();
  383. if (!children.empty()) {
  384. this->WriteGroups(children, linkName, xml);
  385. }
  386. std::vector<const cmSourceFile*> sFiles = sg.GetSourceFiles();
  387. for (cmSourceFile const* file : sFiles) {
  388. std::string const& fullPath = file->GetFullPath();
  389. if (!cmSystemTools::FileIsDirectory(fullPath)) {
  390. std::string linkName4 = linkName3;
  391. linkName4 += "/";
  392. linkName4 += cmSystemTools::GetFilenameName(fullPath);
  393. this->AppendLinkedResource(xml, linkName4,
  394. this->GetEclipsePath(fullPath), LinkToFile);
  395. }
  396. }
  397. }
  398. }
  399. void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml)
  400. {
  401. std::string linkName = "[Targets]";
  402. this->AppendLinkedResource(xml, linkName, "virtual:/virtual", VirtualFolder);
  403. for (cmLocalGenerator* lg : this->GlobalGenerator->GetLocalGenerators()) {
  404. cmMakefile* makefile = lg->GetMakefile();
  405. const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
  406. for (cmGeneratorTarget* target : targets) {
  407. std::string linkName2 = linkName;
  408. linkName2 += "/";
  409. switch (target->GetType()) {
  410. case cmStateEnums::EXECUTABLE:
  411. case cmStateEnums::STATIC_LIBRARY:
  412. case cmStateEnums::SHARED_LIBRARY:
  413. case cmStateEnums::MODULE_LIBRARY:
  414. case cmStateEnums::OBJECT_LIBRARY: {
  415. const char* prefix =
  416. (target->GetType() == cmStateEnums::EXECUTABLE ? "[exe] "
  417. : "[lib] ");
  418. linkName2 += prefix;
  419. linkName2 += target->GetName();
  420. this->AppendLinkedResource(xml, linkName2, "virtual:/virtual",
  421. VirtualFolder);
  422. if (!this->GenerateLinkedResources) {
  423. break; // skip generating the linked resources to the source files
  424. }
  425. std::vector<cmSourceGroup> sourceGroups =
  426. makefile->GetSourceGroups();
  427. // get the files from the source lists then add them to the groups
  428. cmGeneratorTarget* gt = const_cast<cmGeneratorTarget*>(target);
  429. std::vector<cmSourceFile*> files;
  430. gt->GetSourceFiles(files,
  431. makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
  432. for (cmSourceFile* sf : files) {
  433. // Add the file to the list of sources.
  434. std::string const& source = sf->GetFullPath();
  435. cmSourceGroup* sourceGroup =
  436. makefile->FindSourceGroup(source, sourceGroups);
  437. sourceGroup->AssignSource(sf);
  438. }
  439. this->WriteGroups(sourceGroups, linkName2, xml);
  440. } break;
  441. // ignore all others:
  442. default:
  443. break;
  444. }
  445. }
  446. }
  447. }
  448. void cmExtraEclipseCDT4Generator::CreateLinksToSubprojects(
  449. cmXMLWriter& xml, const std::string& baseDir)
  450. {
  451. if (!this->GenerateLinkedResources) {
  452. return;
  453. }
  454. // for each sub project create a linked resource to the source dir
  455. // - only if it is an out-of-source build
  456. this->AppendLinkedResource(xml, "[Subprojects]", "virtual:/virtual",
  457. VirtualFolder);
  458. for (auto const& it : this->GlobalGenerator->GetProjectMap()) {
  459. std::string linkSourceDirectory =
  460. this->GetEclipsePath(it.second[0]->GetCurrentSourceDirectory());
  461. // a linked resource must not point to a parent directory of .project or
  462. // .project itself
  463. if ((baseDir != linkSourceDirectory) &&
  464. !cmSystemTools::IsSubDirectory(baseDir, linkSourceDirectory)) {
  465. std::string linkName = "[Subprojects]/";
  466. linkName += it.first;
  467. this->AppendLinkedResource(xml, linkName,
  468. this->GetEclipsePath(linkSourceDirectory),
  469. LinkToFolder);
  470. // Don't add it to the srcLinkedResources, because listing multiple
  471. // directories confuses the Eclipse indexer (#13596).
  472. }
  473. }
  474. }
  475. void cmExtraEclipseCDT4Generator::AppendIncludeDirectories(
  476. cmXMLWriter& xml, const std::vector<std::string>& includeDirs,
  477. std::set<std::string>& emittedDirs)
  478. {
  479. for (std::string const& inc : includeDirs) {
  480. if (!inc.empty()) {
  481. std::string dir = cmSystemTools::CollapseFullPath(inc);
  482. // handle framework include dirs on OSX, the remainder after the
  483. // Frameworks/ part has to be stripped
  484. // /System/Library/Frameworks/GLUT.framework/Headers
  485. cmsys::RegularExpression frameworkRx("(.+/Frameworks)/.+\\.framework/");
  486. if (frameworkRx.find(dir)) {
  487. dir = frameworkRx.match(1);
  488. }
  489. if (emittedDirs.find(dir) == emittedDirs.end()) {
  490. emittedDirs.insert(dir);
  491. xml.StartElement("pathentry");
  492. xml.Attribute("include",
  493. cmExtraEclipseCDT4Generator::GetEclipsePath(dir));
  494. xml.Attribute("kind", "inc");
  495. xml.Attribute("path", "");
  496. xml.Attribute("system", "true");
  497. xml.EndElement();
  498. }
  499. }
  500. }
  501. }
  502. void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
  503. {
  504. std::set<std::string> emmited;
  505. cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
  506. const cmMakefile* mf = lg->GetMakefile();
  507. const std::string filename = this->HomeOutputDirectory + "/.cproject";
  508. cmGeneratedFileStream fout(filename);
  509. if (!fout) {
  510. return;
  511. }
  512. cmXMLWriter xml(fout);
  513. // add header
  514. xml.StartDocument("UTF-8");
  515. xml.ProcessingInstruction("fileVersion", "4.0.0");
  516. xml.StartElement("cproject");
  517. xml.StartElement("storageModule");
  518. xml.Attribute("moduleId", "org.eclipse.cdt.core.settings");
  519. xml.StartElement("cconfiguration");
  520. xml.Attribute("id", "org.eclipse.cdt.core.default.config.1");
  521. // Configuration settings...
  522. xml.StartElement("storageModule");
  523. xml.Attribute("buildSystemId",
  524. "org.eclipse.cdt.core.defaultConfigDataProvider");
  525. xml.Attribute("id", "org.eclipse.cdt.core.default.config.1");
  526. xml.Attribute("moduleId", "org.eclipse.cdt.core.settings");
  527. xml.Attribute("name", "Configuration");
  528. xml.Element("externalSettings");
  529. xml.StartElement("extensions");
  530. // TODO: refactor this out...
  531. std::string executableFormat =
  532. mf->GetSafeDefinition("CMAKE_EXECUTABLE_FORMAT");
  533. if (executableFormat == "ELF") {
  534. xml.StartElement("extension");
  535. xml.Attribute("id", "org.eclipse.cdt.core.ELF");
  536. xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
  537. xml.EndElement(); // extension
  538. xml.StartElement("extension");
  539. xml.Attribute("id", "org.eclipse.cdt.core.GNU_ELF");
  540. xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
  541. AppendAttribute(xml, "addr2line");
  542. AppendAttribute(xml, "c++filt");
  543. xml.EndElement(); // extension
  544. } else {
  545. std::string systemName = mf->GetSafeDefinition("CMAKE_SYSTEM_NAME");
  546. if (systemName == "CYGWIN") {
  547. xml.StartElement("extension");
  548. xml.Attribute("id", "org.eclipse.cdt.core.Cygwin_PE");
  549. xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
  550. AppendAttribute(xml, "addr2line");
  551. AppendAttribute(xml, "c++filt");
  552. AppendAttribute(xml, "cygpath");
  553. AppendAttribute(xml, "nm");
  554. xml.EndElement(); // extension
  555. } else if (systemName == "Windows") {
  556. xml.StartElement("extension");
  557. xml.Attribute("id", "org.eclipse.cdt.core.PE");
  558. xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
  559. xml.EndElement(); // extension
  560. } else if (systemName == "Darwin") {
  561. xml.StartElement("extension");
  562. xml.Attribute("id",
  563. this->SupportsMachO64Parser
  564. ? "org.eclipse.cdt.core.MachO64"
  565. : "org.eclipse.cdt.core.MachO");
  566. xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
  567. AppendAttribute(xml, "c++filt");
  568. xml.EndElement(); // extension
  569. } else {
  570. // *** Should never get here ***
  571. xml.Element("error_toolchain_type");
  572. }
  573. }
  574. xml.EndElement(); // extensions
  575. xml.EndElement(); // storageModule
  576. // ???
  577. xml.StartElement("storageModule");
  578. xml.Attribute("moduleId", "org.eclipse.cdt.core.language.mapping");
  579. xml.Element("project-mappings");
  580. xml.EndElement(); // storageModule
  581. // ???
  582. xml.StartElement("storageModule");
  583. xml.Attribute("moduleId", "org.eclipse.cdt.core.externalSettings");
  584. xml.EndElement(); // storageModule
  585. // set the path entries (includes, libs, source dirs, etc.)
  586. xml.StartElement("storageModule");
  587. xml.Attribute("moduleId", "org.eclipse.cdt.core.pathentry");
  588. // for each sub project with a linked resource to the source dir:
  589. // - make it type 'src'
  590. // - and exclude it from type 'out'
  591. std::string excludeFromOut;
  592. /* I don't know what the pathentry kind="src" are good for, e.g.
  593. * autocompletion
  594. * works also without them. Done wrong, the indexer complains, see #12417
  595. * and #12213.
  596. * According to #13596, this entry at least limits the directories the
  597. * indexer is searching for files. So now the "src" entry contains only
  598. * the linked resource to CMAKE_SOURCE_DIR.
  599. * The CDT documentation is very terse on that:
  600. * "CDT_SOURCE: Entry kind constant describing a path entry identifying a
  601. * folder containing source code to be compiled."
  602. * Also on the cdt-dev list didn't bring any information:
  603. * http://web.archiveorange.com/archive/v/B4NlJDNIpYoOS1SbxFNy
  604. * Alex */
  605. // include subprojects directory to the src pathentry
  606. // eclipse cdt indexer uses this entries as reference to index source files
  607. if (this->GenerateLinkedResources) {
  608. xml.StartElement("pathentry");
  609. xml.Attribute("kind", "src");
  610. xml.Attribute("path", "[Subprojects]");
  611. xml.EndElement();
  612. }
  613. for (std::string const& p : this->SrcLinkedResources) {
  614. xml.StartElement("pathentry");
  615. xml.Attribute("kind", "src");
  616. xml.Attribute("path", p);
  617. xml.EndElement();
  618. // exlude source directory from output search path
  619. // - only if not named the same as an output directory
  620. if (!cmSystemTools::FileIsDirectory(
  621. std::string(this->HomeOutputDirectory + "/" + p))) {
  622. excludeFromOut += p + "/|";
  623. }
  624. }
  625. excludeFromOut += "**/CMakeFiles/";
  626. xml.StartElement("pathentry");
  627. xml.Attribute("excluding", excludeFromOut);
  628. xml.Attribute("kind", "out");
  629. xml.Attribute("path", "");
  630. xml.EndElement();
  631. // add pre-processor definitions to allow eclipse to gray out sections
  632. emmited.clear();
  633. for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
  634. if (const char* cdefs =
  635. lgen->GetMakefile()->GetProperty("COMPILE_DEFINITIONS")) {
  636. // Expand the list.
  637. std::vector<std::string> defs;
  638. cmGeneratorExpression::Split(cdefs, defs);
  639. for (std::string const& d : defs) {
  640. if (cmGeneratorExpression::Find(d) != std::string::npos) {
  641. continue;
  642. }
  643. std::string::size_type equals = d.find('=', 0);
  644. std::string::size_type enddef = d.length();
  645. std::string def;
  646. std::string val;
  647. if (equals != std::string::npos && equals < enddef) {
  648. // we have -DFOO=BAR
  649. def = d.substr(0, equals);
  650. val = d.substr(equals + 1, enddef - equals + 1);
  651. } else {
  652. // we have -DFOO
  653. def = d;
  654. }
  655. // insert the definition if not already added.
  656. if (emmited.find(def) == emmited.end()) {
  657. emmited.insert(def);
  658. xml.StartElement("pathentry");
  659. xml.Attribute("kind", "mac");
  660. xml.Attribute("name", def);
  661. xml.Attribute("path", "");
  662. xml.Attribute("value", val);
  663. xml.EndElement();
  664. }
  665. }
  666. }
  667. }
  668. // add system defined c macros
  669. const char* cDefs =
  670. mf->GetDefinition("CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS");
  671. if (this->CEnabled && cDefs) {
  672. // Expand the list.
  673. std::vector<std::string> defs;
  674. cmSystemTools::ExpandListArgument(cDefs, defs, true);
  675. // the list must contain only definition-value pairs:
  676. if ((defs.size() % 2) == 0) {
  677. std::vector<std::string>::const_iterator di = defs.begin();
  678. while (di != defs.end()) {
  679. std::string def = *di;
  680. ++di;
  681. std::string val;
  682. if (di != defs.end()) {
  683. val = *di;
  684. ++di;
  685. }
  686. // insert the definition if not already added.
  687. if (emmited.find(def) == emmited.end()) {
  688. emmited.insert(def);
  689. xml.StartElement("pathentry");
  690. xml.Attribute("kind", "mac");
  691. xml.Attribute("name", def);
  692. xml.Attribute("path", "");
  693. xml.Attribute("value", val);
  694. xml.EndElement();
  695. }
  696. }
  697. }
  698. }
  699. // add system defined c++ macros
  700. const char* cxxDefs =
  701. mf->GetDefinition("CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS");
  702. if (this->CXXEnabled && cxxDefs) {
  703. // Expand the list.
  704. std::vector<std::string> defs;
  705. cmSystemTools::ExpandListArgument(cxxDefs, defs, true);
  706. // the list must contain only definition-value pairs:
  707. if ((defs.size() % 2) == 0) {
  708. std::vector<std::string>::const_iterator di = defs.begin();
  709. while (di != defs.end()) {
  710. std::string def = *di;
  711. ++di;
  712. std::string val;
  713. if (di != defs.end()) {
  714. val = *di;
  715. ++di;
  716. }
  717. // insert the definition if not already added.
  718. if (emmited.find(def) == emmited.end()) {
  719. emmited.insert(def);
  720. xml.StartElement("pathentry");
  721. xml.Attribute("kind", "mac");
  722. xml.Attribute("name", def);
  723. xml.Attribute("path", "");
  724. xml.Attribute("value", val);
  725. xml.EndElement();
  726. }
  727. }
  728. }
  729. }
  730. // include dirs
  731. emmited.clear();
  732. for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
  733. const std::vector<cmGeneratorTarget*>& targets =
  734. lgen->GetGeneratorTargets();
  735. for (cmGeneratorTarget* target : targets) {
  736. std::vector<std::string> includeDirs;
  737. std::string config = mf->GetSafeDefinition("CMAKE_BUILD_TYPE");
  738. lgen->GetIncludeDirectories(includeDirs, target, "C", config);
  739. this->AppendIncludeDirectories(xml, includeDirs, emmited);
  740. }
  741. }
  742. // now also the system include directories, in case we found them in
  743. // CMakeSystemSpecificInformation.cmake. This makes Eclipse find the
  744. // standard headers.
  745. std::string compiler = mf->GetSafeDefinition("CMAKE_C_COMPILER");
  746. if (this->CEnabled && !compiler.empty()) {
  747. std::string systemIncludeDirs =
  748. mf->GetSafeDefinition("CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS");
  749. std::vector<std::string> dirs;
  750. cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
  751. this->AppendIncludeDirectories(xml, dirs, emmited);
  752. }
  753. compiler = mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
  754. if (this->CXXEnabled && !compiler.empty()) {
  755. std::string systemIncludeDirs =
  756. mf->GetSafeDefinition("CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS");
  757. std::vector<std::string> dirs;
  758. cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
  759. this->AppendIncludeDirectories(xml, dirs, emmited);
  760. }
  761. xml.EndElement(); // storageModule
  762. // add build targets
  763. xml.StartElement("storageModule");
  764. xml.Attribute("moduleId", "org.eclipse.cdt.make.core.buildtargets");
  765. xml.StartElement("buildTargets");
  766. emmited.clear();
  767. const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  768. const std::string makeArgs =
  769. mf->GetSafeDefinition("CMAKE_ECLIPSE_MAKE_ARGUMENTS");
  770. cmGlobalGenerator* generator =
  771. const_cast<cmGlobalGenerator*>(this->GlobalGenerator);
  772. std::string allTarget;
  773. std::string cleanTarget;
  774. if (generator->GetAllTargetName()) {
  775. allTarget = generator->GetAllTargetName();
  776. }
  777. if (generator->GetCleanTargetName()) {
  778. cleanTarget = generator->GetCleanTargetName();
  779. }
  780. // add all executable and library targets and some of the GLOBAL
  781. // and UTILITY targets
  782. for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
  783. const std::vector<cmGeneratorTarget*>& targets =
  784. lgen->GetGeneratorTargets();
  785. std::string subdir = lgen->ConvertToRelativePath(
  786. this->HomeOutputDirectory, lgen->GetCurrentBinaryDirectory());
  787. if (subdir == ".") {
  788. subdir.clear();
  789. }
  790. for (cmGeneratorTarget* target : targets) {
  791. std::string targetName = target->GetName();
  792. switch (target->GetType()) {
  793. case cmStateEnums::GLOBAL_TARGET: {
  794. // Only add the global targets from CMAKE_BINARY_DIR,
  795. // not from the subdirs
  796. if (subdir.empty()) {
  797. this->AppendTarget(xml, targetName, make, makeArgs, subdir, ": ");
  798. }
  799. } break;
  800. case cmStateEnums::UTILITY:
  801. // Add all utility targets, except the Nightly/Continuous/
  802. // Experimental-"sub"targets as e.g. NightlyStart
  803. if (((targetName.find("Nightly") == 0) &&
  804. (targetName != "Nightly")) ||
  805. ((targetName.find("Continuous") == 0) &&
  806. (targetName != "Continuous")) ||
  807. ((targetName.find("Experimental") == 0) &&
  808. (targetName != "Experimental"))) {
  809. break;
  810. }
  811. this->AppendTarget(xml, targetName, make, makeArgs, subdir, ": ");
  812. break;
  813. case cmStateEnums::EXECUTABLE:
  814. case cmStateEnums::STATIC_LIBRARY:
  815. case cmStateEnums::SHARED_LIBRARY:
  816. case cmStateEnums::MODULE_LIBRARY:
  817. case cmStateEnums::OBJECT_LIBRARY: {
  818. const char* prefix =
  819. (target->GetType() == cmStateEnums::EXECUTABLE ? "[exe] "
  820. : "[lib] ");
  821. this->AppendTarget(xml, targetName, make, makeArgs, subdir, prefix);
  822. std::string fastTarget = targetName;
  823. fastTarget += "/fast";
  824. this->AppendTarget(xml, fastTarget, make, makeArgs, subdir, prefix);
  825. // Add Build and Clean targets in the virtual folder of targets:
  826. if (this->SupportsVirtualFolders) {
  827. std::string virtDir = "[Targets]/";
  828. virtDir += prefix;
  829. virtDir += targetName;
  830. std::string buildArgs = "-C \"";
  831. buildArgs += lgen->GetBinaryDirectory();
  832. buildArgs += "\" ";
  833. buildArgs += makeArgs;
  834. this->AppendTarget(xml, "Build", make, buildArgs, virtDir, "",
  835. targetName.c_str());
  836. std::string cleanArgs = "-E chdir \"";
  837. cleanArgs += lgen->GetCurrentBinaryDirectory();
  838. cleanArgs += "\" \"";
  839. cleanArgs += cmSystemTools::GetCMakeCommand();
  840. cleanArgs += "\" -P \"";
  841. cmGeneratorTarget* gt = target;
  842. cleanArgs += lgen->GetTargetDirectory(gt);
  843. cleanArgs += "/cmake_clean.cmake\"";
  844. this->AppendTarget(xml, "Clean", cmSystemTools::GetCMakeCommand(),
  845. cleanArgs, virtDir, "", "");
  846. }
  847. } break;
  848. default:
  849. break;
  850. }
  851. }
  852. // insert the all and clean targets in every subdir
  853. if (!allTarget.empty()) {
  854. this->AppendTarget(xml, allTarget, make, makeArgs, subdir, ": ");
  855. }
  856. if (!cleanTarget.empty()) {
  857. this->AppendTarget(xml, cleanTarget, make, makeArgs, subdir, ": ");
  858. }
  859. // insert rules for compiling, preprocessing and assembling individual
  860. // files
  861. std::vector<std::string> objectFileTargets;
  862. lg->GetIndividualFileTargets(objectFileTargets);
  863. for (std::string const& f : objectFileTargets) {
  864. const char* prefix = "[obj] ";
  865. if (f.back() == 's') {
  866. prefix = "[to asm] ";
  867. } else if (f.back() == 'i') {
  868. prefix = "[pre] ";
  869. }
  870. this->AppendTarget(xml, f, make, makeArgs, subdir, prefix);
  871. }
  872. }
  873. xml.EndElement(); // buildTargets
  874. xml.EndElement(); // storageModule
  875. this->AppendStorageScanners(xml, *mf);
  876. xml.EndElement(); // cconfiguration
  877. xml.EndElement(); // storageModule
  878. xml.StartElement("storageModule");
  879. xml.Attribute("moduleId", "cdtBuildSystem");
  880. xml.Attribute("version", "4.0.0");
  881. xml.StartElement("project");
  882. xml.Attribute("id", std::string(lg->GetProjectName()) + ".null.1");
  883. xml.Attribute("name", lg->GetProjectName());
  884. xml.EndElement(); // project
  885. xml.EndElement(); // storageModule
  886. // Append additional cproject contents without applying any XML formatting
  887. if (const char* extraCProjectContents =
  888. mf->GetState()->GetGlobalProperty("ECLIPSE_EXTRA_CPROJECT_CONTENTS")) {
  889. fout << extraCProjectContents;
  890. }
  891. xml.EndElement(); // cproject
  892. }
  893. std::string cmExtraEclipseCDT4Generator::GetEclipsePath(
  894. const std::string& path)
  895. {
  896. #if defined(__CYGWIN__)
  897. std::string cmd = "cygpath -m " + path;
  898. std::string out;
  899. if (!cmSystemTools::RunSingleCommand(cmd.c_str(), &out, &out)) {
  900. return path;
  901. } else {
  902. out.erase(out.find_last_of('\n'));
  903. return out;
  904. }
  905. #else
  906. return path;
  907. #endif
  908. }
  909. std::string cmExtraEclipseCDT4Generator::GetPathBasename(
  910. const std::string& path)
  911. {
  912. std::string outputBasename = path;
  913. while (!outputBasename.empty() &&
  914. (outputBasename.back() == '/' || outputBasename.back() == '\\')) {
  915. outputBasename.resize(outputBasename.size() - 1);
  916. }
  917. std::string::size_type loc = outputBasename.find_last_of("/\\");
  918. if (loc != std::string::npos) {
  919. outputBasename = outputBasename.substr(loc + 1);
  920. }
  921. return outputBasename;
  922. }
  923. std::string cmExtraEclipseCDT4Generator::GenerateProjectName(
  924. const std::string& name, const std::string& type, const std::string& path)
  925. {
  926. return name + (type.empty() ? "" : "-") + type + "@" + path;
  927. }
  928. // Helper functions
  929. void cmExtraEclipseCDT4Generator::AppendStorageScanners(
  930. cmXMLWriter& xml, const cmMakefile& makefile)
  931. {
  932. // we need the "make" and the C (or C++) compiler which are used, Alex
  933. std::string make = makefile.GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  934. std::string compiler = makefile.GetSafeDefinition("CMAKE_C_COMPILER");
  935. std::string arg1 = makefile.GetSafeDefinition("CMAKE_C_COMPILER_ARG1");
  936. if (compiler.empty()) {
  937. compiler = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER");
  938. arg1 = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER_ARG1");
  939. }
  940. if (compiler.empty()) // Hmm, what to do now ?
  941. {
  942. compiler = "gcc";
  943. }
  944. // the following right now hardcodes gcc behaviour :-/
  945. std::string compilerArgs =
  946. "-E -P -v -dD ${plugin_state_location}/${specs_file}";
  947. if (!arg1.empty()) {
  948. arg1 += " ";
  949. compilerArgs = arg1 + compilerArgs;
  950. }
  951. xml.StartElement("storageModule");
  952. xml.Attribute("moduleId", "scannerConfiguration");
  953. xml.StartElement("autodiscovery");
  954. xml.Attribute("enabled", "true");
  955. xml.Attribute("problemReportingEnabled", "true");
  956. xml.Attribute("selectedProfileId",
  957. "org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile");
  958. xml.EndElement(); // autodiscovery
  959. cmExtraEclipseCDT4Generator::AppendScannerProfile(
  960. xml, "org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile", true,
  961. "", true, "specsFile", compilerArgs, compiler, true, true);
  962. cmExtraEclipseCDT4Generator::AppendScannerProfile(
  963. xml, "org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile", true, "",
  964. true, "makefileGenerator", "-f ${project_name}_scd.mk", make, true, true);
  965. xml.EndElement(); // storageModule
  966. }
  967. // The prefix is prepended before the actual name of the target. The purpose
  968. // of that is to sort the targets in the view of Eclipse, so that at first
  969. // the global/utility/all/clean targets appear ": ", then the executable
  970. // targets "[exe] ", then the libraries "[lib]", then the rules for the
  971. // object files "[obj]", then for preprocessing only "[pre] " and
  972. // finally the assembly files "[to asm] ". Note the "to" in "to asm",
  973. // without it, "asm" would be the first targets in the list, with the "to"
  974. // they are the last targets, which makes more sense.
  975. void cmExtraEclipseCDT4Generator::AppendTarget(
  976. cmXMLWriter& xml, const std::string& target, const std::string& make,
  977. const std::string& makeArgs, const std::string& path, const char* prefix,
  978. const char* makeTarget)
  979. {
  980. xml.StartElement("target");
  981. xml.Attribute("name", prefix + target);
  982. xml.Attribute("path", path);
  983. xml.Attribute("targetID", "org.eclipse.cdt.make.MakeTargetBuilder");
  984. xml.Element("buildCommand",
  985. cmExtraEclipseCDT4Generator::GetEclipsePath(make));
  986. xml.Element("buildArguments", makeArgs);
  987. xml.Element("buildTarget", makeTarget ? makeTarget : target.c_str());
  988. xml.Element("stopOnError", "true");
  989. xml.Element("useDefaultCommand", "false");
  990. xml.EndElement();
  991. }
  992. void cmExtraEclipseCDT4Generator::AppendScannerProfile(
  993. cmXMLWriter& xml, const std::string& profileID, bool openActionEnabled,
  994. const std::string& openActionFilePath, bool pParserEnabled,
  995. const std::string& scannerInfoProviderID,
  996. const std::string& runActionArguments, const std::string& runActionCommand,
  997. bool runActionUseDefault, bool sipParserEnabled)
  998. {
  999. xml.StartElement("profile");
  1000. xml.Attribute("id", profileID);
  1001. xml.StartElement("buildOutputProvider");
  1002. xml.StartElement("openAction");
  1003. xml.Attribute("enabled", openActionEnabled ? "true" : "false");
  1004. xml.Attribute("filePath", openActionFilePath);
  1005. xml.EndElement(); // openAction
  1006. xml.StartElement("parser");
  1007. xml.Attribute("enabled", pParserEnabled ? "true" : "false");
  1008. xml.EndElement(); // parser
  1009. xml.EndElement(); // buildOutputProvider
  1010. xml.StartElement("scannerInfoProvider");
  1011. xml.Attribute("id", scannerInfoProviderID);
  1012. xml.StartElement("runAction");
  1013. xml.Attribute("arguments", runActionArguments);
  1014. xml.Attribute("command", runActionCommand);
  1015. xml.Attribute("useDefault", runActionUseDefault ? "true" : "false");
  1016. xml.EndElement(); // runAction
  1017. xml.StartElement("parser");
  1018. xml.Attribute("enabled", sipParserEnabled ? "true" : "false");
  1019. xml.EndElement(); // parser
  1020. xml.EndElement(); // scannerInfoProvider
  1021. xml.EndElement(); // profile
  1022. }
  1023. void cmExtraEclipseCDT4Generator::AppendLinkedResource(cmXMLWriter& xml,
  1024. const std::string& name,
  1025. const std::string& path,
  1026. LinkType linkType)
  1027. {
  1028. const char* locationTag = "location";
  1029. int typeTag = 2;
  1030. if (linkType == VirtualFolder) // ... and not a linked folder
  1031. {
  1032. locationTag = "locationURI";
  1033. }
  1034. if (linkType == LinkToFile) {
  1035. typeTag = 1;
  1036. }
  1037. xml.StartElement("link");
  1038. xml.Element("name", name);
  1039. xml.Element("type", typeTag);
  1040. xml.Element(locationTag, path);
  1041. xml.EndElement();
  1042. }