cmExtraEclipseCDT4Generator.cxx 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. Copyright (c) 2004 Alexander Neundorf [email protected], All rights reserved.
  9. Copyright (c) 2007 Miguel A. Figueroa-Villanueva. All rights reserved.
  10. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  11. This software is distributed WITHOUT ANY WARRANTY; without even
  12. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. PURPOSE. See the above copyright notices for more information.
  14. =========================================================================*/
  15. #include "cmExtraEclipseCDT4Generator.h"
  16. #include "cmGlobalUnixMakefileGenerator3.h"
  17. #include "cmLocalUnixMakefileGenerator3.h"
  18. #include "cmMakefile.h"
  19. #include "cmGeneratedFileStream.h"
  20. #include "cmTarget.h"
  21. #include "cmSystemTools.h"
  22. #include <stdlib.h>
  23. #include <assert.h>
  24. //----------------------------------------------------------------------------
  25. cmExtraEclipseCDT4Generator
  26. ::cmExtraEclipseCDT4Generator() : cmExternalMakefileProjectGenerator()
  27. {
  28. // TODO: Verify if __CYGWIN__ should be checked.
  29. //#if defined(_WIN32) && !defined(__CYGWIN__)
  30. #if defined(_WIN32)
  31. this->SupportedGlobalGenerators.push_back("NMake Makefiles");
  32. this->SupportedGlobalGenerators.push_back("MinGW Makefiles");
  33. // this->SupportedGlobalGenerators.push_back("MSYS Makefiles");
  34. #endif
  35. this->SupportedGlobalGenerators.push_back("Unix Makefiles");
  36. }
  37. //----------------------------------------------------------------------------
  38. void cmExtraEclipseCDT4Generator
  39. ::GetDocumentation(cmDocumentationEntry& entry, const char*) const
  40. {
  41. entry.Name = this->GetName();
  42. entry.Brief = "Generates Eclipse CDT 4.0 project files.";
  43. entry.Full =
  44. "Project files for Eclipse will be created in the top directory "
  45. "and will have a linked resource to every subdirectory which "
  46. "features a CMakeLists.txt file containing a PROJECT() call."
  47. "Additionally a hierarchy of makefiles is generated into the "
  48. "build tree. The appropriate make program can build the project through "
  49. "the default make target. A \"make install\" target is also provided.";
  50. }
  51. //----------------------------------------------------------------------------
  52. void cmExtraEclipseCDT4Generator
  53. ::SetGlobalGenerator(cmGlobalGenerator* generator)
  54. {
  55. cmExternalMakefileProjectGenerator::SetGlobalGenerator(generator);
  56. cmGlobalUnixMakefileGenerator3* mf
  57. = static_cast<cmGlobalUnixMakefileGenerator3*>(generator);
  58. mf->SetToolSupportsColor(true);
  59. mf->SetForceVerboseMakefiles(true);
  60. }
  61. //----------------------------------------------------------------------------
  62. void cmExtraEclipseCDT4Generator::Generate()
  63. {
  64. const cmMakefile* mf
  65. = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  66. // TODO: Decide if these are local or member variables
  67. this->HomeDirectory = mf->GetHomeDirectory();
  68. this->HomeOutputDirectory = mf->GetHomeOutputDirectory();
  69. this->IsOutOfSourceBuild = (this->HomeDirectory!=this->HomeOutputDirectory);
  70. this->GenerateSourceProject = (this->IsOutOfSourceBuild &&
  71. mf->IsOn("ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT"));
  72. // NOTE: This is not good, since it pollutes the source tree. However,
  73. // Eclipse doesn't allow CVS/SVN to work when the .project is not in
  74. // the cvs/svn root directory. Hence, this is provided as an option.
  75. if (this->GenerateSourceProject)
  76. {
  77. // create .project file in the source tree
  78. this->CreateSourceProjectFile();
  79. }
  80. // create a .project file
  81. this->CreateProjectFile();
  82. // create a .cproject file
  83. this->CreateCProjectFile();
  84. }
  85. void cmExtraEclipseCDT4Generator::CreateSourceProjectFile() const
  86. {
  87. assert(this->HomeDirectory != this->HomeOutputDirectory);
  88. // set up the project name: <project>-Source@<baseSourcePathName>
  89. const cmMakefile* mf
  90. = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  91. std::string name = this->GenerateProjectName(mf->GetProjectName(), "Source",
  92. this->GetPathBasename(this->HomeDirectory));
  93. const std::string filename = this->HomeDirectory + "/.project";
  94. cmGeneratedFileStream fout(filename.c_str());
  95. if (!fout)
  96. {
  97. return;
  98. }
  99. fout <<
  100. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  101. "<projectDescription>\n"
  102. "\t<name>" << name << "</name>\n"
  103. "\t<comment></comment>\n"
  104. "\t<projects>\n"
  105. "\t</projects>\n"
  106. "\t<buildSpec>\n"
  107. "\t</buildSpec>\n"
  108. "\t<natures>\n"
  109. "\t</natures>\n"
  110. "</projectDescription>\n"
  111. ;
  112. }
  113. //----------------------------------------------------------------------------
  114. void cmExtraEclipseCDT4Generator::CreateProjectFile()
  115. {
  116. const cmMakefile* mf
  117. = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  118. const std::string filename = this->HomeOutputDirectory + "/.project";
  119. cmGeneratedFileStream fout(filename.c_str());
  120. if (!fout)
  121. {
  122. return;
  123. }
  124. fout <<
  125. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  126. "<projectDescription>\n"
  127. "\t<name>" <<
  128. this->GenerateProjectName(mf->GetProjectName(),
  129. mf->GetDefinition("CMAKE_BUILD_TYPE"),
  130. this->GetPathBasename(this->HomeOutputDirectory))
  131. << "</name>\n"
  132. "\t<comment></comment>\n"
  133. "\t<projects>\n"
  134. "\t</projects>\n"
  135. "\t<buildSpec>\n"
  136. "\t\t<buildCommand>\n"
  137. "\t\t\t<name>org.eclipse.cdt.make.core.makeBuilder</name>\n"
  138. "\t\t\t<triggers>clean,full,incremental,</triggers>\n"
  139. "\t\t\t<arguments>\n"
  140. ;
  141. // use clean target
  142. fout <<
  143. "\t\t\t\t<dictionary>\n"
  144. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>\n"
  145. "\t\t\t\t\t<value>clean</value>\n"
  146. "\t\t\t\t</dictionary>\n"
  147. "\t\t\t\t<dictionary>\n"
  148. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enableCleanBuild</key>\n"
  149. "\t\t\t\t\t<value>true</value>\n"
  150. "\t\t\t\t</dictionary>\n"
  151. "\t\t\t\t<dictionary>\n"
  152. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.append_environment</key>\n"
  153. "\t\t\t\t\t<value>true</value>\n"
  154. "\t\t\t\t</dictionary>\n"
  155. "\t\t\t\t<dictionary>\n"
  156. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.stopOnError</key>\n"
  157. "\t\t\t\t\t<value>true</value>\n"
  158. "\t\t\t\t</dictionary>\n"
  159. ;
  160. // set the make command
  161. std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  162. fout <<
  163. "\t\t\t\t<dictionary>\n"
  164. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enabledIncrementalBuild</key>\n"
  165. "\t\t\t\t\t<value>true</value>\n"
  166. "\t\t\t\t</dictionary>\n"
  167. "\t\t\t\t<dictionary>\n"
  168. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.command</key>\n"
  169. "\t\t\t\t\t<value>" + this->GetEclipsePath(make) + "</value>\n"
  170. "\t\t\t\t</dictionary>\n"
  171. "\t\t\t\t<dictionary>\n"
  172. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.contents</key>\n"
  173. "\t\t\t\t\t<value>org.eclipse.cdt.make.core.activeConfigSettings</value>\n"
  174. "\t\t\t\t</dictionary>\n"
  175. "\t\t\t\t<dictionary>\n"
  176. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.target.inc</key>\n"
  177. "\t\t\t\t\t<value>all</value>\n"
  178. "\t\t\t\t</dictionary>\n"
  179. "\t\t\t\t<dictionary>\n"
  180. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.arguments</key>\n"
  181. "\t\t\t\t\t<value></value>\n"
  182. "\t\t\t\t</dictionary>\n"
  183. "\t\t\t\t<dictionary>\n"
  184. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.buildLocation</key>\n"
  185. "\t\t\t\t\t<value>"
  186. << this->GetEclipsePath(this->HomeOutputDirectory) << "</value>\n"
  187. "\t\t\t\t</dictionary>\n"
  188. "\t\t\t\t<dictionary>\n"
  189. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>\n"
  190. "\t\t\t\t\t<value>false</value>\n"
  191. "\t\t\t\t</dictionary>\n"
  192. ;
  193. // set project specific environment
  194. fout <<
  195. "\t\t\t\t<dictionary>\n"
  196. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.environment</key>\n"
  197. "\t\t\t\t\t<value>"
  198. ;
  199. // set vsvars32.bat environment available at CMake time,
  200. // but not necessarily when eclipse is open
  201. if (make.find("nmake") != std::string::npos)
  202. {
  203. if (getenv("PATH"))
  204. {
  205. fout << "PATH=" << getenv("PATH") << "|";
  206. }
  207. if (getenv("INCLUDE"))
  208. {
  209. fout << "INCLUDE=" << getenv("INCLUDE") << "|";
  210. }
  211. if (getenv("LIB"))
  212. {
  213. fout << "LIB=" << getenv("LIB") << "|";
  214. }
  215. if (getenv("LIBPATH"))
  216. {
  217. fout << "LIBPATH=" << getenv("LIBPATH") << "|";
  218. }
  219. }
  220. fout <<
  221. "</value>\n"
  222. "\t\t\t\t</dictionary>\n"
  223. ;
  224. fout <<
  225. "\t\t\t\t<dictionary>\n"
  226. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enableFullBuild</key>\n"
  227. "\t\t\t\t\t<value>true</value>\n"
  228. "\t\t\t\t</dictionary>\n"
  229. "\t\t\t\t<dictionary>\n"
  230. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.target.auto</key>\n"
  231. "\t\t\t\t\t<value>all</value>\n"
  232. "\t\t\t\t</dictionary>\n"
  233. "\t\t\t\t<dictionary>\n"
  234. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enableAutoBuild</key>\n"
  235. "\t\t\t\t\t<value>false</value>\n"
  236. "\t\t\t\t</dictionary>\n"
  237. "\t\t\t\t<dictionary>\n"
  238. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.target.clean</key>\n"
  239. "\t\t\t\t\t<value>clean</value>\n"
  240. "\t\t\t\t</dictionary>\n"
  241. "\t\t\t\t<dictionary>\n"
  242. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.fullBuildTarget</key>\n"
  243. "\t\t\t\t\t<value>all</value>\n"
  244. "\t\t\t\t</dictionary>\n"
  245. "\t\t\t\t<dictionary>\n"
  246. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.buildArguments</key>\n"
  247. "\t\t\t\t\t<value></value>\n"
  248. "\t\t\t\t</dictionary>\n"
  249. "\t\t\t\t<dictionary>\n"
  250. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.location</key>\n"
  251. "\t\t\t\t\t<value>"
  252. << this->GetEclipsePath(this->HomeOutputDirectory) << "</value>\n"
  253. "\t\t\t\t</dictionary>\n"
  254. "\t\t\t\t<dictionary>\n"
  255. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.autoBuildTarget</key>\n"
  256. "\t\t\t\t\t<value>all</value>\n"
  257. "\t\t\t\t</dictionary>\n"
  258. ;
  259. // set error parsers
  260. fout <<
  261. "\t\t\t\t<dictionary>\n"
  262. "\t\t\t\t\t<key>org.eclipse.cdt.core.errorOutputParser</key>\n"
  263. "\t\t\t\t\t<value>"
  264. ;
  265. if (this->GetToolChainType(*mf) == EclipseToolchainOther)
  266. {
  267. fout << "org.eclipse.cdt.core.VCErrorParser;";
  268. }
  269. fout <<
  270. "org.eclipse.cdt.core.MakeErrorParser;"
  271. "org.eclipse.cdt.core.GCCErrorParser;"
  272. "org.eclipse.cdt.core.GASErrorParser;"
  273. "org.eclipse.cdt.core.GLDErrorParser;"
  274. "</value>\n"
  275. "\t\t\t\t</dictionary>\n"
  276. ;
  277. fout <<
  278. "\t\t\t</arguments>\n"
  279. "\t\t</buildCommand>\n"
  280. "\t\t<buildCommand>\n"
  281. "\t\t\t<name>org.eclipse.cdt.make.core.ScannerConfigBuilder</name>\n"
  282. "\t\t\t<arguments>\n"
  283. "\t\t\t</arguments>\n"
  284. "\t\t</buildCommand>\n"
  285. "\t</buildSpec>\n"
  286. ;
  287. // set natures for c/c++ projects
  288. fout <<
  289. "\t<natures>\n"
  290. // TODO: ccnature only if it is c++ ???
  291. "\t\t<nature>org.eclipse.cdt.core.ccnature</nature>\n"
  292. "\t\t<nature>org.eclipse.cdt.make.core.makeNature</nature>\n"
  293. "\t\t<nature>org.eclipse.cdt.make.core.ScannerConfigNature</nature>\n"
  294. "\t\t<nature>org.eclipse.cdt.core.cnature</nature>\n"
  295. "\t</natures>\n"
  296. ;
  297. // TODO: refactor this
  298. // create linked resources
  299. if (this->IsOutOfSourceBuild)
  300. {
  301. fout << "\t<linkedResources>\n";
  302. // for each sub project create a linked resource to the source dir
  303. // - only if it is an out-of-source build
  304. for (std::map<cmStdString, std::vector<cmLocalGenerator*> >::const_iterator
  305. it = this->GlobalGenerator->GetProjectMap().begin();
  306. it != this->GlobalGenerator->GetProjectMap().end();
  307. ++it)
  308. {
  309. std::string linkSourceDirectory = this->GetEclipsePath(
  310. it->second[0]->GetMakefile()->GetStartDirectory());
  311. // .project dir can't be subdir of a linked resource dir
  312. if (!cmSystemTools::IsSubDirectory(this->HomeOutputDirectory.c_str(),
  313. linkSourceDirectory.c_str()))
  314. {
  315. this->AppendLinkedResource(fout, it->first,
  316. this->GetEclipsePath(linkSourceDirectory));
  317. this->SrcLinkedResources.push_back(it->first);
  318. }
  319. }
  320. // for EXECUTABLE_OUTPUT_PATH when not in binary dir
  321. std::string outputPath = mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  322. if (!outputPath.empty() && !cmSystemTools::IsSubDirectory(
  323. outputPath.c_str(), this->HomeOutputDirectory.c_str()))
  324. {
  325. std::string name = this->GetPathBasename(outputPath);
  326. // make sure linked resource name is unique
  327. while (this->GlobalGenerator->GetProjectMap().find(name)
  328. != this->GlobalGenerator->GetProjectMap().end())
  329. {
  330. name += "_";
  331. }
  332. this->AppendLinkedResource(fout, name,
  333. this->GetEclipsePath(outputPath));
  334. this->OutLinkedResources.push_back(name);
  335. }
  336. // for LIBRARY_OUTPUT_PATH when not in binary dir
  337. if (outputPath != mf->GetSafeDefinition("LIBRARY_OUTPUT_PATH"))
  338. {
  339. outputPath = mf->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  340. if (!outputPath.empty() && !cmSystemTools::IsSubDirectory(
  341. outputPath.c_str(), this->HomeOutputDirectory.c_str()))
  342. {
  343. std::string name = this->GetPathBasename(outputPath);
  344. // make sure linked resource name is unique
  345. while (this->GlobalGenerator->GetProjectMap().find(name)
  346. != this->GlobalGenerator->GetProjectMap().end())
  347. {
  348. name += "_";
  349. }
  350. this->AppendLinkedResource(fout, name,
  351. this->GetEclipsePath(outputPath));
  352. this->OutLinkedResources.push_back(name);
  353. }
  354. }
  355. fout << "\t</linkedResources>\n";
  356. }
  357. fout << "</projectDescription>\n";
  358. }
  359. //----------------------------------------------------------------------------
  360. void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
  361. {
  362. std::set<std::string> emmited;
  363. const cmMakefile* mf
  364. = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  365. const std::string filename = this->HomeOutputDirectory + "/.cproject";
  366. cmGeneratedFileStream fout(filename.c_str());
  367. if (!fout)
  368. {
  369. return;
  370. }
  371. // add header
  372. fout <<
  373. "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
  374. "<?fileVersion 4.0.0?>\n\n"
  375. "<cproject>\n"
  376. "<storageModule moduleId=\"org.eclipse.cdt.core.settings\">\n"
  377. ;
  378. fout << "<cconfiguration id=\"org.eclipse.cdt.core.default.config.1\">\n";
  379. // Configuration settings...
  380. fout <<
  381. "<storageModule"
  382. " buildSystemId=\"org.eclipse.cdt.core.defaultConfigDataProvider\""
  383. " id=\"org.eclipse.cdt.core.default.config.1\""
  384. " moduleId=\"org.eclipse.cdt.core.settings\" name=\"Configuration\">\n"
  385. "<externalSettings/>\n"
  386. "<extensions>\n"
  387. ;
  388. // TODO: refactor this out...
  389. switch (this->GetToolChainType(*mf))
  390. {
  391. case EclipseToolchainLinux :
  392. fout << "<extension id=\"org.eclipse.cdt.core.ELF\""
  393. " point=\"org.eclipse.cdt.core.BinaryParser\"/>\n"
  394. ;
  395. fout << "<extension id=\"org.eclipse.cdt.core.GNU_ELF\""
  396. " point=\"org.eclipse.cdt.core.BinaryParser\">\n"
  397. "<attribute key=\"addr2line\" value=\"addr2line\"/>\n"
  398. "<attribute key=\"c++filt\" value=\"c++filt\"/>\n"
  399. "</extension>\n"
  400. ;
  401. break;
  402. case EclipseToolchainCygwin :
  403. fout << "<extension id=\"org.eclipse.cdt.core.Cygwin_PE\""
  404. " point=\"org.eclipse.cdt.core.BinaryParser\">\n"
  405. "<attribute key=\"addr2line\" value=\"addr2line\"/>\n"
  406. "<attribute key=\"c++filt\" value=\"c++filt\"/>\n"
  407. "<attribute key=\"cygpath\" value=\"cygpath\"/>\n"
  408. "<attribute key=\"nm\" value=\"nm\"/>\n"
  409. "</extension>\n"
  410. ;
  411. break;
  412. case EclipseToolchainMinGW :
  413. fout << "<extension id=\"org.eclipse.cdt.core.PE\""
  414. " point=\"org.eclipse.cdt.core.BinaryParser\"/>\n"
  415. ;
  416. break;
  417. case EclipseToolchainSolaris :
  418. fout << "<extension id=\"org.eclipse.cdt.core.ELF\""
  419. " point=\"org.eclipse.cdt.core.BinaryParser\"/>\n"
  420. ;
  421. break;
  422. case EclipseToolchainMacOSX :
  423. fout << "<extension id=\"org.eclipse.cdt.core.MachO\""
  424. " point=\"org.eclipse.cdt.core.BinaryParser\">\n"
  425. "<attribute key=\"c++filt\" value=\"c++filt\"/>\n"
  426. "</extension>\n"
  427. ;
  428. break;
  429. case EclipseToolchainOther :
  430. fout << "<extension id=\"org.eclipse.cdt.core.PE\""
  431. " point=\"org.eclipse.cdt.core.BinaryParser\"/>\n"
  432. ;
  433. fout << "<extension id=\"org.eclipse.cdt.core.ELF\""
  434. " point=\"org.eclipse.cdt.core.BinaryParser\"/>\n"
  435. ;
  436. break;
  437. default :
  438. // *** Should never get here ***
  439. fout << "<error_toolchain_type/>\n";
  440. }
  441. fout << "</extensions>\n"
  442. "</storageModule>\n"
  443. ;
  444. // ???
  445. fout <<
  446. "<storageModule moduleId=\"org.eclipse.cdt.core.language.mapping\">\n"
  447. "<project-mappings/>\n"
  448. "</storageModule>\n"
  449. ;
  450. // ???
  451. fout<<"<storageModule moduleId=\"org.eclipse.cdt.core.externalSettings\"/>\n"
  452. ;
  453. // set the path entries (includes, libs, source dirs, etc.)
  454. fout << "<storageModule moduleId=\"org.eclipse.cdt.core.pathentry\">\n"
  455. ;
  456. // for each sub project with a linked resource to the source dir:
  457. // - make it type 'src'
  458. // - and exclude it from type 'out'
  459. std::string excludeFromOut;
  460. for (std::vector<std::string>::const_iterator
  461. it = this->SrcLinkedResources.begin();
  462. it != this->SrcLinkedResources.end();
  463. ++it)
  464. {
  465. fout << "<pathentry kind=\"src\" path=\"" << *it << "\"/>\n";
  466. // exlude source directory from output search path
  467. // - only if not named the same as an output directory
  468. if (!cmSystemTools::FileIsDirectory(
  469. std::string(this->HomeOutputDirectory + "/" + *it).c_str()))
  470. {
  471. excludeFromOut += *it + "/|";
  472. }
  473. }
  474. excludeFromOut += "**/CMakeFiles/";
  475. fout << "<pathentry excluding=\"" << excludeFromOut
  476. << "\" kind=\"out\" path=\"\"/>\n";
  477. // add output entry for EXECUTABLE_OUTPUT_PATH and LIBRARY_OUTPUT_PATH
  478. // - if it is a subdir of homeOutputDirectory, there is no need to add it
  479. // - if it is not then create a linked resource and add the linked name
  480. // but check it doesn't conflict with other linked resources names
  481. for (std::vector<std::string>::const_iterator
  482. it = this->OutLinkedResources.begin();
  483. it != this->OutLinkedResources.end();
  484. ++it)
  485. {
  486. fout << "<pathentry kind=\"out\" path=\"" << *it << "\"/>\n";
  487. }
  488. // add pre-processor definitions to allow eclipse to gray out sections
  489. emmited.clear();
  490. for (std::vector<cmLocalGenerator*>::const_iterator
  491. it = this->GlobalGenerator->GetLocalGenerators().begin();
  492. it != this->GlobalGenerator->GetLocalGenerators().end();
  493. ++it)
  494. {
  495. if(const char* cdefs = (*it)->GetMakefile()->GetProperty(
  496. "COMPILE_DEFINITIONS"))
  497. {
  498. // Expand the list.
  499. std::vector<std::string> defs;
  500. cmSystemTools::ExpandListArgument(cdefs, defs);
  501. for(std::vector<std::string>::const_iterator di = defs.begin();
  502. di != defs.end(); ++di)
  503. {
  504. std::string::size_type equals = di->find('=', 0);
  505. std::string::size_type enddef = di->length();
  506. std::string def;
  507. std::string val;
  508. if (equals != std::string::npos && equals < enddef)
  509. {
  510. // we have -DFOO=BAR
  511. def = di->substr(0, equals);
  512. val = di->substr(equals + 1, enddef - equals + 1);
  513. }
  514. else
  515. {
  516. // we have -DFOO
  517. def = *di;
  518. }
  519. // insert the definition if not already added.
  520. if(emmited.find(def) == emmited.end())
  521. {
  522. emmited.insert(def);
  523. fout << "<pathentry kind=\"mac\" name=\"" << def
  524. << "\" path=\"\" value=\"" << this->EscapeForXML(val)
  525. << "\"/>\n";
  526. }
  527. }
  528. }
  529. }
  530. // include dirs
  531. emmited.clear();
  532. for (std::vector<cmLocalGenerator*>::const_iterator
  533. it = this->GlobalGenerator->GetLocalGenerators().begin();
  534. it != this->GlobalGenerator->GetLocalGenerators().end();
  535. ++it)
  536. {
  537. const std::vector<std::string>& includeDirs
  538. = (*it)->GetMakefile()->GetIncludeDirectories();
  539. for(std::vector<std::string>::const_iterator inc = includeDirs.begin();
  540. inc != includeDirs.end();
  541. ++inc)
  542. {
  543. std::string dir = cmSystemTools::CollapseFullPath(inc->c_str());
  544. if(emmited.find(dir) == emmited.end())
  545. {
  546. emmited.insert(dir);
  547. fout << "<pathentry include=\"" << this->GetEclipsePath(dir)
  548. << "\" kind=\"inc\" path=\"\" system=\"true\"/>\n";
  549. }
  550. }
  551. }
  552. fout << "</storageModule>\n";
  553. // add build targets
  554. fout <<
  555. "<storageModule moduleId=\"org.eclipse.cdt.make.core.buildtargets\">\n"
  556. "<buildTargets>\n"
  557. ;
  558. emmited.clear();
  559. const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  560. cmGlobalGenerator* generator
  561. = const_cast<cmGlobalGenerator*>(this->GlobalGenerator);
  562. if (generator->GetAllTargetName())
  563. {
  564. emmited.insert(generator->GetAllTargetName());
  565. cmExtraEclipseCDT4Generator::AppendTarget(fout,
  566. generator->GetAllTargetName(),
  567. make);
  568. }
  569. if (generator->GetPreinstallTargetName())
  570. {
  571. emmited.insert(generator->GetPreinstallTargetName());
  572. cmExtraEclipseCDT4Generator
  573. ::AppendTarget(fout, generator->GetPreinstallTargetName(), make);
  574. }
  575. if (generator->GetCleanTargetName())
  576. {
  577. emmited.insert(generator->GetCleanTargetName());
  578. cmExtraEclipseCDT4Generator
  579. ::AppendTarget(fout, generator->GetCleanTargetName(), make);
  580. }
  581. // add all executable and library targets and some of the GLOBAL
  582. // and UTILITY targets
  583. for (std::vector<cmLocalGenerator*>::const_iterator
  584. it = this->GlobalGenerator->GetLocalGenerators().begin();
  585. it != this->GlobalGenerator->GetLocalGenerators().end();
  586. ++it)
  587. {
  588. const cmTargets& targets = (*it)->GetMakefile()->GetTargets();
  589. for(cmTargets::const_iterator t = targets.begin(); t != targets.end(); ++t)
  590. {
  591. switch(t->second.GetType())
  592. {
  593. case cmTarget::UTILITY:
  594. case cmTarget::GLOBAL_TARGET:
  595. {
  596. // only add these global targets
  597. if (!( (t->first=="install")
  598. || (t->first=="install/strip")
  599. || (t->first=="test")
  600. || (t->first=="Experimental")
  601. || (t->first=="Nightly")
  602. || (t->first=="edit_cache")
  603. || (t->first=="package")
  604. || (t->first=="package_source")
  605. || (t->first=="rebuild_cache") ))
  606. {
  607. break;
  608. }
  609. // add the edit_cache target only if it's not ccmake
  610. // otherwise ccmake will be executed in the log view of Eclipse,
  611. // which is no terminal, so curses don't work there, Alex
  612. if (t->first=="edit_cache")
  613. {
  614. if (strstr(mf->GetRequiredDefinition("CMAKE_EDIT_COMMAND"),
  615. "ccmake")!=NULL)
  616. {
  617. break;
  618. }
  619. }
  620. }
  621. case cmTarget::EXECUTABLE:
  622. case cmTarget::STATIC_LIBRARY:
  623. case cmTarget::SHARED_LIBRARY:
  624. case cmTarget::MODULE_LIBRARY:
  625. {
  626. if(emmited.find(t->first) == emmited.end())
  627. {
  628. emmited.insert(t->first);
  629. cmExtraEclipseCDT4Generator::AppendTarget(fout, t->first, make);
  630. }
  631. break;
  632. }
  633. // ignore these:
  634. case cmTarget::INSTALL_FILES:
  635. case cmTarget::INSTALL_PROGRAMS:
  636. case cmTarget::INSTALL_DIRECTORY:
  637. default:
  638. break;
  639. }
  640. }
  641. }
  642. fout << "</buildTargets>\n"
  643. "</storageModule>\n"
  644. ;
  645. this->AppendStorageScanners(fout, *mf);
  646. fout << "</cconfiguration>\n"
  647. "</storageModule>\n"
  648. "<storageModule moduleId=\"cdtBuildSystem\" version=\"4.0.0\">\n"
  649. "<project id=\"" << mf->GetProjectName() << ".null.1\""
  650. " name=\"" << mf->GetProjectName() << "\"/>\n"
  651. "</storageModule>\n"
  652. "</cproject>\n"
  653. ;
  654. }
  655. //----------------------------------------------------------------------------
  656. cmExtraEclipseCDT4Generator::EclipseToolchainType
  657. cmExtraEclipseCDT4Generator::GetToolChainType(const cmMakefile& makefile)
  658. {
  659. if (makefile.IsSet("UNIX"))
  660. {
  661. if (makefile.IsSet("CYGWIN"))
  662. {
  663. return EclipseToolchainCygwin;
  664. }
  665. if (makefile.IsSet("APPLE" ))
  666. {
  667. return EclipseToolchainMacOSX;
  668. }
  669. // *** how do I determine if it is Solaris ???
  670. return EclipseToolchainLinux;
  671. }
  672. else if (makefile.IsSet("WIN32"))
  673. {
  674. if (makefile.IsSet("MINGW"))
  675. {
  676. return EclipseToolchainMinGW;
  677. }
  678. if (makefile.IsSet("MSYS" ))
  679. {
  680. return EclipseToolchainMinGW;
  681. }
  682. return EclipseToolchainOther;
  683. }
  684. else
  685. {
  686. return EclipseToolchainOther;
  687. }
  688. }
  689. std::string
  690. cmExtraEclipseCDT4Generator::GetEclipsePath(const std::string& path)
  691. {
  692. #if defined(__CYGWIN__)
  693. std::string cmd = "cygpath -m " + path;
  694. std::string out;
  695. if (!cmSystemTools::RunCommand(cmd.c_str(), out, 0, false))
  696. {
  697. return path;
  698. }
  699. else
  700. {
  701. out.erase(out.find_last_of('\n'));
  702. return out;
  703. }
  704. #else
  705. return path;
  706. #endif
  707. }
  708. std::string
  709. cmExtraEclipseCDT4Generator::GetPathBasename(const std::string& path)
  710. {
  711. std::string outputBasename = path;
  712. while (outputBasename.size() > 0 &&
  713. (outputBasename[outputBasename.size() - 1] == '/' ||
  714. outputBasename[outputBasename.size() - 1] == '\\'))
  715. {
  716. outputBasename.resize(outputBasename.size() - 1);
  717. }
  718. std::string::size_type loc = outputBasename.find_last_of("/\\");
  719. if (loc != std::string::npos)
  720. {
  721. outputBasename = outputBasename.substr(loc + 1);
  722. }
  723. return outputBasename;
  724. }
  725. std::string
  726. cmExtraEclipseCDT4Generator::GenerateProjectName(const std::string& name,
  727. const std::string& type,
  728. const std::string& path)
  729. {
  730. return name + (type.empty() ? "" : "-") + type + "@" + path;
  731. }
  732. std::string cmExtraEclipseCDT4Generator::EscapeForXML(const std::string& value)
  733. {
  734. std::string str = value;
  735. cmSystemTools::ReplaceString(str, "&", "&amp;");
  736. cmSystemTools::ReplaceString(str, "<", "&lt;");
  737. cmSystemTools::ReplaceString(str, ">", "&gt;");
  738. cmSystemTools::ReplaceString(str, "\"", "&quot;");
  739. // NOTE: This one is not necessary, since as of Eclipse CDT4 it will
  740. // automatically change this to the original value (').
  741. //cmSystemTools::ReplaceString(str, "'", "&apos;");
  742. return str;
  743. }
  744. //----------------------------------------------------------------------------
  745. // Helper functions
  746. //----------------------------------------------------------------------------
  747. void cmExtraEclipseCDT4Generator
  748. ::AppendStorageScanners(cmGeneratedFileStream& fout,
  749. const cmMakefile& makefile)
  750. {
  751. // we need the "make" and the C (or C++) compiler which are used, Alex
  752. std::string make = makefile.GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  753. std::string compiler = makefile.GetSafeDefinition("CMAKE_C_COMPILER");
  754. if (compiler.empty())
  755. {
  756. compiler = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER");
  757. }
  758. if (compiler.empty()) //Hmm, what to do now ?
  759. {
  760. compiler = "gcc";
  761. }
  762. // the following right now hardcodes gcc behaviour :-/
  763. fout <<
  764. "<storageModule moduleId=\"scannerConfiguration\">\n"
  765. "<autodiscovery enabled=\"true\" problemReportingEnabled=\"true\""
  766. " selectedProfileId="
  767. "\"org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile\"/>\n"
  768. ;
  769. cmExtraEclipseCDT4Generator::AppendScannerProfile(fout,
  770. "org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile",
  771. true, "", true, "specsFile",
  772. "-E -P -v -dD ${plugin_state_location}/${specs_file}",
  773. compiler, true, true);
  774. cmExtraEclipseCDT4Generator::AppendScannerProfile(fout,
  775. "org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile",
  776. true, "", true, "makefileGenerator",
  777. "-f ${project_name}_scd.mk",
  778. make, true, true);
  779. fout << "</storageModule>\n";
  780. }
  781. void cmExtraEclipseCDT4Generator::AppendTarget(cmGeneratedFileStream& fout,
  782. const std::string& target,
  783. const std::string& make)
  784. {
  785. fout <<
  786. "<target name=\"" << target << "\""
  787. " path=\"\""
  788. " targetID=\"org.eclipse.cdt.make.MakeTargetBuilder\">\n"
  789. "<buildCommand>"
  790. << cmExtraEclipseCDT4Generator::GetEclipsePath(make)
  791. << "</buildCommand>\n"
  792. "<buildArguments/>\n"
  793. "<buildTarget>" << target << "</buildTarget>\n"
  794. "<stopOnError>true</stopOnError>\n"
  795. "<useDefaultCommand>false</useDefaultCommand>\n"
  796. "</target>\n"
  797. ;
  798. }
  799. void cmExtraEclipseCDT4Generator
  800. ::AppendScannerProfile(cmGeneratedFileStream& fout,
  801. const std::string& profileID,
  802. bool openActionEnabled,
  803. const std::string& openActionFilePath,
  804. bool pParserEnabled,
  805. const std::string& scannerInfoProviderID,
  806. const std::string& runActionArguments,
  807. const std::string& runActionCommand,
  808. bool runActionUseDefault,
  809. bool sipParserEnabled)
  810. {
  811. fout <<
  812. "<profile id=\"" << profileID << "\">\n"
  813. "<buildOutputProvider>\n"
  814. "<openAction enabled=\"" << (openActionEnabled ? "true" : "false")
  815. << "\" filePath=\"" << openActionFilePath << "\"/>\n"
  816. "<parser enabled=\"" << (pParserEnabled ? "true" : "false") << "\"/>\n"
  817. "</buildOutputProvider>\n"
  818. "<scannerInfoProvider id=\"" << scannerInfoProviderID << "\">\n"
  819. "<runAction arguments=\"" << runActionArguments << "\""
  820. " command=\"" << runActionCommand
  821. << "\" useDefault=\"" << (runActionUseDefault ? "true":"false") << "\"/>\n"
  822. "<parser enabled=\"" << (sipParserEnabled ? "true" : "false") << "\"/>\n"
  823. "</scannerInfoProvider>\n"
  824. "</profile>\n"
  825. ;
  826. }
  827. void cmExtraEclipseCDT4Generator
  828. ::AppendLinkedResource (cmGeneratedFileStream& fout,
  829. const std::string& name,
  830. const std::string& path)
  831. {
  832. fout <<
  833. "\t\t<link>\n"
  834. "\t\t\t<name>" << name << "</name>\n"
  835. "\t\t\t<type>2</type>\n"
  836. "\t\t\t<location>"
  837. << path
  838. << "</location>\n"
  839. "\t\t</link>\n"
  840. ;
  841. }