cmExtraEclipseCDT4Generator.cxx 31 KB

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