cmExtraEclipseCDT4Generator.cxx 43 KB

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