cmExtraEclipseCDT4Generator.cxx 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  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. // Append additional cproject contents without applying any XML formatting
  885. if (const char* extraCProjectContents =
  886. mf->GetState()->GetGlobalProperty("ECLIPSE_EXTRA_CPROJECT_CONTENTS")) {
  887. fout << extraCProjectContents;
  888. }
  889. xml.EndElement(); // cproject
  890. }
  891. std::string cmExtraEclipseCDT4Generator::GetEclipsePath(
  892. const std::string& path)
  893. {
  894. #if defined(__CYGWIN__)
  895. std::string cmd = "cygpath -m " + path;
  896. std::string out;
  897. if (!cmSystemTools::RunSingleCommand(cmd.c_str(), &out, &out)) {
  898. return path;
  899. } else {
  900. out.erase(out.find_last_of('\n'));
  901. return out;
  902. }
  903. #else
  904. return path;
  905. #endif
  906. }
  907. std::string cmExtraEclipseCDT4Generator::GetPathBasename(
  908. const std::string& path)
  909. {
  910. std::string outputBasename = path;
  911. while (!outputBasename.empty() &&
  912. (outputBasename[outputBasename.size() - 1] == '/' ||
  913. outputBasename[outputBasename.size() - 1] == '\\')) {
  914. outputBasename.resize(outputBasename.size() - 1);
  915. }
  916. std::string::size_type loc = outputBasename.find_last_of("/\\");
  917. if (loc != std::string::npos) {
  918. outputBasename = outputBasename.substr(loc + 1);
  919. }
  920. return outputBasename;
  921. }
  922. std::string cmExtraEclipseCDT4Generator::GenerateProjectName(
  923. const std::string& name, const std::string& type, const std::string& path)
  924. {
  925. return name + (type.empty() ? "" : "-") + type + "@" + path;
  926. }
  927. // Helper functions
  928. void cmExtraEclipseCDT4Generator::AppendStorageScanners(
  929. cmXMLWriter& xml, const cmMakefile& makefile)
  930. {
  931. // we need the "make" and the C (or C++) compiler which are used, Alex
  932. std::string make = makefile.GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  933. std::string compiler = makefile.GetSafeDefinition("CMAKE_C_COMPILER");
  934. std::string arg1 = makefile.GetSafeDefinition("CMAKE_C_COMPILER_ARG1");
  935. if (compiler.empty()) {
  936. compiler = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER");
  937. arg1 = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER_ARG1");
  938. }
  939. if (compiler.empty()) // Hmm, what to do now ?
  940. {
  941. compiler = "gcc";
  942. }
  943. // the following right now hardcodes gcc behaviour :-/
  944. std::string compilerArgs =
  945. "-E -P -v -dD ${plugin_state_location}/${specs_file}";
  946. if (!arg1.empty()) {
  947. arg1 += " ";
  948. compilerArgs = arg1 + compilerArgs;
  949. }
  950. xml.StartElement("storageModule");
  951. xml.Attribute("moduleId", "scannerConfiguration");
  952. xml.StartElement("autodiscovery");
  953. xml.Attribute("enabled", "true");
  954. xml.Attribute("problemReportingEnabled", "true");
  955. xml.Attribute("selectedProfileId",
  956. "org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile");
  957. xml.EndElement(); // autodiscovery
  958. cmExtraEclipseCDT4Generator::AppendScannerProfile(
  959. xml, "org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile", true,
  960. "", true, "specsFile", compilerArgs, compiler, true, true);
  961. cmExtraEclipseCDT4Generator::AppendScannerProfile(
  962. xml, "org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile", true, "",
  963. true, "makefileGenerator", "-f ${project_name}_scd.mk", make, true, true);
  964. xml.EndElement(); // storageModule
  965. }
  966. // The prefix is prepended before the actual name of the target. The purpose
  967. // of that is to sort the targets in the view of Eclipse, so that at first
  968. // the global/utility/all/clean targets appear ": ", then the executable
  969. // targets "[exe] ", then the libraries "[lib]", then the rules for the
  970. // object files "[obj]", then for preprocessing only "[pre] " and
  971. // finally the assembly files "[to asm] ". Note the "to" in "to asm",
  972. // without it, "asm" would be the first targets in the list, with the "to"
  973. // they are the last targets, which makes more sense.
  974. void cmExtraEclipseCDT4Generator::AppendTarget(
  975. cmXMLWriter& xml, const std::string& target, const std::string& make,
  976. const std::string& makeArgs, const std::string& path, const char* prefix,
  977. const char* makeTarget)
  978. {
  979. xml.StartElement("target");
  980. xml.Attribute("name", prefix + target);
  981. xml.Attribute("path", path);
  982. xml.Attribute("targetID", "org.eclipse.cdt.make.MakeTargetBuilder");
  983. xml.Element("buildCommand",
  984. cmExtraEclipseCDT4Generator::GetEclipsePath(make));
  985. xml.Element("buildArguments", makeArgs);
  986. xml.Element("buildTarget", makeTarget ? makeTarget : target.c_str());
  987. xml.Element("stopOnError", "true");
  988. xml.Element("useDefaultCommand", "false");
  989. xml.EndElement();
  990. }
  991. void cmExtraEclipseCDT4Generator::AppendScannerProfile(
  992. cmXMLWriter& xml, const std::string& profileID, bool openActionEnabled,
  993. const std::string& openActionFilePath, bool pParserEnabled,
  994. const std::string& scannerInfoProviderID,
  995. const std::string& runActionArguments, const std::string& runActionCommand,
  996. bool runActionUseDefault, bool sipParserEnabled)
  997. {
  998. xml.StartElement("profile");
  999. xml.Attribute("id", profileID);
  1000. xml.StartElement("buildOutputProvider");
  1001. xml.StartElement("openAction");
  1002. xml.Attribute("enabled", openActionEnabled ? "true" : "false");
  1003. xml.Attribute("filePath", openActionFilePath);
  1004. xml.EndElement(); // openAction
  1005. xml.StartElement("parser");
  1006. xml.Attribute("enabled", pParserEnabled ? "true" : "false");
  1007. xml.EndElement(); // parser
  1008. xml.EndElement(); // buildOutputProvider
  1009. xml.StartElement("scannerInfoProvider");
  1010. xml.Attribute("id", scannerInfoProviderID);
  1011. xml.StartElement("runAction");
  1012. xml.Attribute("arguments", runActionArguments);
  1013. xml.Attribute("command", runActionCommand);
  1014. xml.Attribute("useDefault", runActionUseDefault ? "true" : "false");
  1015. xml.EndElement(); // runAction
  1016. xml.StartElement("parser");
  1017. xml.Attribute("enabled", sipParserEnabled ? "true" : "false");
  1018. xml.EndElement(); // parser
  1019. xml.EndElement(); // scannerInfoProvider
  1020. xml.EndElement(); // profile
  1021. }
  1022. void cmExtraEclipseCDT4Generator::AppendLinkedResource(cmXMLWriter& xml,
  1023. const std::string& name,
  1024. const std::string& path,
  1025. LinkType linkType)
  1026. {
  1027. const char* locationTag = "location";
  1028. int typeTag = 2;
  1029. if (linkType == VirtualFolder) // ... and not a linked folder
  1030. {
  1031. locationTag = "locationURI";
  1032. }
  1033. if (linkType == LinkToFile) {
  1034. typeTag = 1;
  1035. }
  1036. xml.StartElement("link");
  1037. xml.Element("name", name);
  1038. xml.Element("type", typeTag);
  1039. xml.Element(locationTag, path);
  1040. xml.EndElement();
  1041. }