cmExtraEclipseCDT4Generator.cxx 43 KB

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