cmExtraEclipseCDT4Generator.cxx 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  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 "cmGlobalUnixMakefileGenerator3.h"
  14. #include "cmLocalUnixMakefileGenerator3.h"
  15. #include "cmMakefile.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include "cmTarget.h"
  18. #include "cmSystemTools.h"
  19. #include <stdlib.h>
  20. #include <assert.h>
  21. //----------------------------------------------------------------------------
  22. cmExtraEclipseCDT4Generator
  23. ::cmExtraEclipseCDT4Generator() : cmExternalMakefileProjectGenerator()
  24. {
  25. // TODO: Verify if __CYGWIN__ should be checked.
  26. //#if defined(_WIN32) && !defined(__CYGWIN__)
  27. #if defined(_WIN32)
  28. this->SupportedGlobalGenerators.push_back("NMake Makefiles");
  29. this->SupportedGlobalGenerators.push_back("MinGW Makefiles");
  30. // this->SupportedGlobalGenerators.push_back("MSYS Makefiles");
  31. #endif
  32. this->SupportedGlobalGenerators.push_back("Unix Makefiles");
  33. }
  34. //----------------------------------------------------------------------------
  35. void cmExtraEclipseCDT4Generator
  36. ::GetDocumentation(cmDocumentationEntry& entry, const char*) const
  37. {
  38. entry.Name = this->GetName();
  39. entry.Brief = "Generates Eclipse CDT 4.0 project files.";
  40. entry.Full =
  41. "Project files for Eclipse will be created in the top directory "
  42. "and will have a linked resource to every subdirectory which "
  43. "features a CMakeLists.txt file containing a PROJECT() call."
  44. "Additionally a hierarchy of makefiles is generated into the "
  45. "build tree. The appropriate make program can build the project through "
  46. "the default make target. A \"make install\" target is also provided.";
  47. }
  48. //----------------------------------------------------------------------------
  49. void cmExtraEclipseCDT4Generator
  50. ::SetGlobalGenerator(cmGlobalGenerator* generator)
  51. {
  52. cmExternalMakefileProjectGenerator::SetGlobalGenerator(generator);
  53. cmGlobalUnixMakefileGenerator3* mf
  54. = static_cast<cmGlobalUnixMakefileGenerator3*>(generator);
  55. mf->SetToolSupportsColor(true);
  56. }
  57. //----------------------------------------------------------------------------
  58. void cmExtraEclipseCDT4Generator::Generate()
  59. {
  60. const cmMakefile* mf
  61. = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  62. // TODO: Decide if these are local or member variables
  63. this->HomeDirectory = mf->GetHomeDirectory();
  64. this->HomeOutputDirectory = mf->GetHomeOutputDirectory();
  65. this->IsOutOfSourceBuild = (this->HomeDirectory!=this->HomeOutputDirectory);
  66. this->GenerateSourceProject = (this->IsOutOfSourceBuild &&
  67. mf->IsOn("ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT"));
  68. // NOTE: This is not good, since it pollutes the source tree. However,
  69. // Eclipse doesn't allow CVS/SVN to work when the .project is not in
  70. // the cvs/svn root directory. Hence, this is provided as an option.
  71. if (this->GenerateSourceProject)
  72. {
  73. // create .project file in the source tree
  74. this->CreateSourceProjectFile();
  75. }
  76. // create a .project file
  77. this->CreateProjectFile();
  78. // create a .cproject file
  79. this->CreateCProjectFile();
  80. }
  81. void cmExtraEclipseCDT4Generator::CreateSourceProjectFile() const
  82. {
  83. assert(this->HomeDirectory != this->HomeOutputDirectory);
  84. // set up the project name: <project>-Source@<baseSourcePathName>
  85. const cmMakefile* mf
  86. = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  87. std::string name = this->GenerateProjectName(mf->GetProjectName(), "Source",
  88. this->GetPathBasename(this->HomeDirectory));
  89. const std::string filename = this->HomeDirectory + "/.project";
  90. cmGeneratedFileStream fout(filename.c_str());
  91. if (!fout)
  92. {
  93. return;
  94. }
  95. fout <<
  96. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  97. "<projectDescription>\n"
  98. "\t<name>" << name << "</name>\n"
  99. "\t<comment></comment>\n"
  100. "\t<projects>\n"
  101. "\t</projects>\n"
  102. "\t<buildSpec>\n"
  103. "\t</buildSpec>\n"
  104. "\t<natures>\n"
  105. "\t</natures>\n"
  106. "</projectDescription>\n"
  107. ;
  108. }
  109. //----------------------------------------------------------------------------
  110. void cmExtraEclipseCDT4Generator::CreateProjectFile()
  111. {
  112. const cmMakefile* mf
  113. = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  114. const std::string filename = this->HomeOutputDirectory + "/.project";
  115. cmGeneratedFileStream fout(filename.c_str());
  116. if (!fout)
  117. {
  118. return;
  119. }
  120. fout <<
  121. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  122. "<projectDescription>\n"
  123. "\t<name>" <<
  124. this->GenerateProjectName(mf->GetProjectName(),
  125. mf->GetDefinition("CMAKE_BUILD_TYPE"),
  126. this->GetPathBasename(this->HomeOutputDirectory))
  127. << "</name>\n"
  128. "\t<comment></comment>\n"
  129. "\t<projects>\n"
  130. "\t</projects>\n"
  131. "\t<buildSpec>\n"
  132. "\t\t<buildCommand>\n"
  133. "\t\t\t<name>org.eclipse.cdt.make.core.makeBuilder</name>\n"
  134. "\t\t\t<triggers>clean,full,incremental,</triggers>\n"
  135. "\t\t\t<arguments>\n"
  136. ;
  137. // use clean target
  138. fout <<
  139. "\t\t\t\t<dictionary>\n"
  140. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>\n"
  141. "\t\t\t\t\t<value>clean</value>\n"
  142. "\t\t\t\t</dictionary>\n"
  143. "\t\t\t\t<dictionary>\n"
  144. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enableCleanBuild</key>\n"
  145. "\t\t\t\t\t<value>true</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.append_environment</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.stopOnError</key>\n"
  153. "\t\t\t\t\t<value>true</value>\n"
  154. "\t\t\t\t</dictionary>\n"
  155. ;
  156. // set the make command
  157. std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  158. fout <<
  159. "\t\t\t\t<dictionary>\n"
  160. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enabledIncrementalBuild</key>\n"
  161. "\t\t\t\t\t<value>true</value>\n"
  162. "\t\t\t\t</dictionary>\n"
  163. "\t\t\t\t<dictionary>\n"
  164. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.command</key>\n"
  165. "\t\t\t\t\t<value>" + this->GetEclipsePath(make) + "</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.contents</key>\n"
  169. "\t\t\t\t\t<value>org.eclipse.cdt.make.core.activeConfigSettings</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.build.target.inc</key>\n"
  173. "\t\t\t\t\t<value>all</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.arguments</key>\n"
  177. "\t\t\t\t\t<value></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.buildLocation</key>\n"
  181. "\t\t\t\t\t<value>"
  182. << this->GetEclipsePath(this->HomeOutputDirectory) << "</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.useDefaultBuildCmd</key>\n"
  186. "\t\t\t\t\t<value>false</value>\n"
  187. "\t\t\t\t</dictionary>\n"
  188. ;
  189. // set project specific environment
  190. fout <<
  191. "\t\t\t\t<dictionary>\n"
  192. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.environment</key>\n"
  193. "\t\t\t\t\t<value>VERBOSE=1|</value>\n" // enforce VERBOSE Makefile output
  194. "\t\t\t\t\t<value>"
  195. ;
  196. // set vsvars32.bat environment available at CMake time,
  197. // but not necessarily when eclipse is open
  198. if (make.find("nmake") != std::string::npos)
  199. {
  200. if (getenv("PATH"))
  201. {
  202. fout << "PATH=" << getenv("PATH") << "|";
  203. }
  204. if (getenv("INCLUDE"))
  205. {
  206. fout << "INCLUDE=" << getenv("INCLUDE") << "|";
  207. }
  208. if (getenv("LIB"))
  209. {
  210. fout << "LIB=" << getenv("LIB") << "|";
  211. }
  212. if (getenv("LIBPATH"))
  213. {
  214. fout << "LIBPATH=" << getenv("LIBPATH") << "|";
  215. }
  216. }
  217. fout <<
  218. "</value>\n"
  219. "\t\t\t\t</dictionary>\n"
  220. ;
  221. fout <<
  222. "\t\t\t\t<dictionary>\n"
  223. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enableFullBuild</key>\n"
  224. "\t\t\t\t\t<value>true</value>\n"
  225. "\t\t\t\t</dictionary>\n"
  226. "\t\t\t\t<dictionary>\n"
  227. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.target.auto</key>\n"
  228. "\t\t\t\t\t<value>all</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.enableAutoBuild</key>\n"
  232. "\t\t\t\t\t<value>false</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.build.target.clean</key>\n"
  236. "\t\t\t\t\t<value>clean</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.fullBuildTarget</key>\n"
  240. "\t\t\t\t\t<value>all</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.buildArguments</key>\n"
  244. "\t\t\t\t\t<value></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.build.location</key>\n"
  248. "\t\t\t\t\t<value>"
  249. << this->GetEclipsePath(this->HomeOutputDirectory) << "</value>\n"
  250. "\t\t\t\t</dictionary>\n"
  251. "\t\t\t\t<dictionary>\n"
  252. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.autoBuildTarget</key>\n"
  253. "\t\t\t\t\t<value>all</value>\n"
  254. "\t\t\t\t</dictionary>\n"
  255. ;
  256. // set error parsers
  257. fout <<
  258. "\t\t\t\t<dictionary>\n"
  259. "\t\t\t\t\t<key>org.eclipse.cdt.core.errorOutputParser</key>\n"
  260. "\t\t\t\t\t<value>"
  261. ;
  262. if (this->GetToolChainType(*mf) == EclipseToolchainOther)
  263. {
  264. fout << "org.eclipse.cdt.core.VCErrorParser;";
  265. }
  266. fout <<
  267. "org.eclipse.cdt.core.MakeErrorParser;"
  268. "org.eclipse.cdt.core.GCCErrorParser;"
  269. "org.eclipse.cdt.core.GASErrorParser;"
  270. "org.eclipse.cdt.core.GLDErrorParser;"
  271. "</value>\n"
  272. "\t\t\t\t</dictionary>\n"
  273. ;
  274. fout <<
  275. "\t\t\t</arguments>\n"
  276. "\t\t</buildCommand>\n"
  277. "\t\t<buildCommand>\n"
  278. "\t\t\t<name>org.eclipse.cdt.make.core.ScannerConfigBuilder</name>\n"
  279. "\t\t\t<arguments>\n"
  280. "\t\t\t</arguments>\n"
  281. "\t\t</buildCommand>\n"
  282. "\t</buildSpec>\n"
  283. ;
  284. // set natures for c/c++ projects
  285. fout <<
  286. "\t<natures>\n"
  287. // TODO: ccnature only if it is c++ ???
  288. "\t\t<nature>org.eclipse.cdt.core.ccnature</nature>\n"
  289. "\t\t<nature>org.eclipse.cdt.make.core.makeNature</nature>\n"
  290. "\t\t<nature>org.eclipse.cdt.make.core.ScannerConfigNature</nature>\n"
  291. "\t\t<nature>org.eclipse.cdt.core.cnature</nature>\n"
  292. "\t</natures>\n"
  293. ;
  294. // TODO: refactor this
  295. // create linked resources
  296. if (this->IsOutOfSourceBuild)
  297. {
  298. fout << "\t<linkedResources>\n";
  299. // for each sub project create a linked resource to the source dir
  300. // - only if it is an out-of-source build
  301. for (std::map<cmStdString, std::vector<cmLocalGenerator*> >::const_iterator
  302. it = this->GlobalGenerator->GetProjectMap().begin();
  303. it != this->GlobalGenerator->GetProjectMap().end();
  304. ++it)
  305. {
  306. std::string linkSourceDirectory = this->GetEclipsePath(
  307. it->second[0]->GetMakefile()->GetStartDirectory());
  308. // .project dir can't be subdir of a linked resource dir
  309. if (!cmSystemTools::IsSubDirectory(this->HomeOutputDirectory.c_str(),
  310. linkSourceDirectory.c_str()))
  311. {
  312. this->AppendLinkedResource(fout, it->first,
  313. this->GetEclipsePath(linkSourceDirectory));
  314. this->SrcLinkedResources.push_back(it->first);
  315. }
  316. }
  317. // for EXECUTABLE_OUTPUT_PATH when not in binary dir
  318. this->AppendOutLinkedResource(fout,
  319. mf->GetSafeDefinition("CMAKE_RUNTIME_OUTPUT_DIRECTORY"),
  320. mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH"));
  321. // for LIBRARY_OUTPUT_PATH when not in binary dir
  322. this->AppendOutLinkedResource(fout,
  323. mf->GetSafeDefinition("CMAKE_LIBRARY_OUTPUT_DIRECTORY"),
  324. mf->GetSafeDefinition("LIBRARY_OUTPUT_PATH"));
  325. fout << "\t</linkedResources>\n";
  326. }
  327. fout << "</projectDescription>\n";
  328. }
  329. //----------------------------------------------------------------------------
  330. void cmExtraEclipseCDT4Generator::AppendIncludeDirectories(
  331. cmGeneratedFileStream& fout,
  332. const std::vector<std::string>& includeDirs,
  333. std::set<std::string>& emittedDirs)
  334. {
  335. for(std::vector<std::string>::const_iterator inc = includeDirs.begin();
  336. inc != includeDirs.end();
  337. ++inc)
  338. {
  339. if (!inc->empty())
  340. {
  341. std::string dir = cmSystemTools::CollapseFullPath(inc->c_str());
  342. if(emittedDirs.find(dir) == emittedDirs.end())
  343. {
  344. emittedDirs.insert(dir);
  345. fout << "<pathentry include=\""
  346. << cmExtraEclipseCDT4Generator::GetEclipsePath(dir)
  347. << "\" kind=\"inc\" path=\"\" system=\"true\"/>\n";
  348. }
  349. }
  350. }
  351. }
  352. //----------------------------------------------------------------------------
  353. void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
  354. {
  355. std::set<std::string> emmited;
  356. const cmMakefile* mf
  357. = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  358. const std::string filename = this->HomeOutputDirectory + "/.cproject";
  359. cmGeneratedFileStream fout(filename.c_str());
  360. if (!fout)
  361. {
  362. return;
  363. }
  364. // add header
  365. fout <<
  366. "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
  367. "<?fileVersion 4.0.0?>\n\n"
  368. "<cproject>\n"
  369. "<storageModule moduleId=\"org.eclipse.cdt.core.settings\">\n"
  370. ;
  371. fout << "<cconfiguration id=\"org.eclipse.cdt.core.default.config.1\">\n";
  372. // Configuration settings...
  373. fout <<
  374. "<storageModule"
  375. " buildSystemId=\"org.eclipse.cdt.core.defaultConfigDataProvider\""
  376. " id=\"org.eclipse.cdt.core.default.config.1\""
  377. " moduleId=\"org.eclipse.cdt.core.settings\" name=\"Configuration\">\n"
  378. "<externalSettings/>\n"
  379. "<extensions>\n"
  380. ;
  381. // TODO: refactor this out...
  382. switch (this->GetToolChainType(*mf))
  383. {
  384. case EclipseToolchainLinux :
  385. fout << "<extension id=\"org.eclipse.cdt.core.ELF\""
  386. " point=\"org.eclipse.cdt.core.BinaryParser\"/>\n"
  387. ;
  388. fout << "<extension id=\"org.eclipse.cdt.core.GNU_ELF\""
  389. " point=\"org.eclipse.cdt.core.BinaryParser\">\n"
  390. "<attribute key=\"addr2line\" value=\"addr2line\"/>\n"
  391. "<attribute key=\"c++filt\" value=\"c++filt\"/>\n"
  392. "</extension>\n"
  393. ;
  394. break;
  395. case EclipseToolchainCygwin :
  396. fout << "<extension id=\"org.eclipse.cdt.core.Cygwin_PE\""
  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. "<attribute key=\"cygpath\" value=\"cygpath\"/>\n"
  401. "<attribute key=\"nm\" value=\"nm\"/>\n"
  402. "</extension>\n"
  403. ;
  404. break;
  405. case EclipseToolchainMinGW :
  406. fout << "<extension id=\"org.eclipse.cdt.core.PE\""
  407. " point=\"org.eclipse.cdt.core.BinaryParser\"/>\n"
  408. ;
  409. break;
  410. case EclipseToolchainSolaris :
  411. fout << "<extension id=\"org.eclipse.cdt.core.ELF\""
  412. " point=\"org.eclipse.cdt.core.BinaryParser\"/>\n"
  413. ;
  414. break;
  415. case EclipseToolchainMacOSX :
  416. fout << "<extension id=\"org.eclipse.cdt.core.MachO\""
  417. " point=\"org.eclipse.cdt.core.BinaryParser\">\n"
  418. "<attribute key=\"c++filt\" value=\"c++filt\"/>\n"
  419. "</extension>\n"
  420. ;
  421. break;
  422. case EclipseToolchainOther :
  423. fout << "<extension id=\"org.eclipse.cdt.core.PE\""
  424. " point=\"org.eclipse.cdt.core.BinaryParser\"/>\n"
  425. ;
  426. fout << "<extension id=\"org.eclipse.cdt.core.ELF\""
  427. " point=\"org.eclipse.cdt.core.BinaryParser\"/>\n"
  428. ;
  429. break;
  430. default :
  431. // *** Should never get here ***
  432. fout << "<error_toolchain_type/>\n";
  433. }
  434. fout << "</extensions>\n"
  435. "</storageModule>\n"
  436. ;
  437. // ???
  438. fout <<
  439. "<storageModule moduleId=\"org.eclipse.cdt.core.language.mapping\">\n"
  440. "<project-mappings/>\n"
  441. "</storageModule>\n"
  442. ;
  443. // ???
  444. fout<<"<storageModule moduleId=\"org.eclipse.cdt.core.externalSettings\"/>\n"
  445. ;
  446. // set the path entries (includes, libs, source dirs, etc.)
  447. fout << "<storageModule moduleId=\"org.eclipse.cdt.core.pathentry\">\n"
  448. ;
  449. // for each sub project with a linked resource to the source dir:
  450. // - make it type 'src'
  451. // - and exclude it from type 'out'
  452. std::string excludeFromOut;
  453. for (std::vector<std::string>::const_iterator
  454. it = this->SrcLinkedResources.begin();
  455. it != this->SrcLinkedResources.end();
  456. ++it)
  457. {
  458. fout << "<pathentry kind=\"src\" path=\"" << *it << "\"/>\n";
  459. // exlude source directory from output search path
  460. // - only if not named the same as an output directory
  461. if (!cmSystemTools::FileIsDirectory(
  462. std::string(this->HomeOutputDirectory + "/" + *it).c_str()))
  463. {
  464. excludeFromOut += *it + "/|";
  465. }
  466. }
  467. excludeFromOut += "**/CMakeFiles/";
  468. fout << "<pathentry excluding=\"" << excludeFromOut
  469. << "\" kind=\"out\" path=\"\"/>\n";
  470. // add output entry for EXECUTABLE_OUTPUT_PATH and LIBRARY_OUTPUT_PATH
  471. // - if it is a subdir of homeOutputDirectory, there is no need to add it
  472. // - if it is not then create a linked resource and add the linked name
  473. // but check it doesn't conflict with other linked resources names
  474. for (std::vector<std::string>::const_iterator
  475. it = this->OutLinkedResources.begin();
  476. it != this->OutLinkedResources.end();
  477. ++it)
  478. {
  479. fout << "<pathentry kind=\"out\" path=\"" << *it << "\"/>\n";
  480. }
  481. // add pre-processor definitions to allow eclipse to gray out sections
  482. emmited.clear();
  483. for (std::vector<cmLocalGenerator*>::const_iterator
  484. it = this->GlobalGenerator->GetLocalGenerators().begin();
  485. it != this->GlobalGenerator->GetLocalGenerators().end();
  486. ++it)
  487. {
  488. if(const char* cdefs = (*it)->GetMakefile()->GetProperty(
  489. "COMPILE_DEFINITIONS"))
  490. {
  491. // Expand the list.
  492. std::vector<std::string> defs;
  493. cmSystemTools::ExpandListArgument(cdefs, defs);
  494. for(std::vector<std::string>::const_iterator di = defs.begin();
  495. di != defs.end(); ++di)
  496. {
  497. std::string::size_type equals = di->find('=', 0);
  498. std::string::size_type enddef = di->length();
  499. std::string def;
  500. std::string val;
  501. if (equals != std::string::npos && equals < enddef)
  502. {
  503. // we have -DFOO=BAR
  504. def = di->substr(0, equals);
  505. val = di->substr(equals + 1, enddef - equals + 1);
  506. }
  507. else
  508. {
  509. // we have -DFOO
  510. def = *di;
  511. }
  512. // insert the definition if not already added.
  513. if(emmited.find(def) == emmited.end())
  514. {
  515. emmited.insert(def);
  516. fout << "<pathentry kind=\"mac\" name=\"" << def
  517. << "\" path=\"\" value=\"" << this->EscapeForXML(val)
  518. << "\"/>\n";
  519. }
  520. }
  521. }
  522. }
  523. // add system defined c macros
  524. const char* cDefs=mf->GetDefinition("CMAKE_ECLIPSE_C_SYSTEM_DEFINED_MACROS");
  525. if(cDefs)
  526. {
  527. // Expand the list.
  528. std::vector<std::string> defs;
  529. cmSystemTools::ExpandListArgument(cDefs, defs, true);
  530. // the list must contain only definition-value pairs:
  531. if ((defs.size() % 2) == 0)
  532. {
  533. std::vector<std::string>::const_iterator di = defs.begin();
  534. while (di != defs.end())
  535. {
  536. std::string def = *di;
  537. ++di;
  538. std::string val;
  539. if (di != defs.end())
  540. {
  541. val = *di;
  542. ++di;
  543. }
  544. // insert the definition if not already added.
  545. if(emmited.find(def) == emmited.end())
  546. {
  547. emmited.insert(def);
  548. fout << "<pathentry kind=\"mac\" name=\"" << def
  549. << "\" path=\"\" value=\"" << this->EscapeForXML(val)
  550. << "\"/>\n";
  551. }
  552. }
  553. }
  554. }
  555. // add system defined c++ macros
  556. const char* cxxDefs = mf->GetDefinition(
  557. "CMAKE_ECLIPSE_CXX_SYSTEM_DEFINED_MACROS");
  558. if(cxxDefs)
  559. {
  560. // Expand the list.
  561. std::vector<std::string> defs;
  562. cmSystemTools::ExpandListArgument(cxxDefs, defs, true);
  563. // the list must contain only definition-value pairs:
  564. if ((defs.size() % 2) == 0)
  565. {
  566. std::vector<std::string>::const_iterator di = defs.begin();
  567. while (di != defs.end())
  568. {
  569. std::string def = *di;
  570. ++di;
  571. std::string val;
  572. if (di != defs.end())
  573. {
  574. val = *di;
  575. ++di;
  576. }
  577. // insert the definition if not already added.
  578. if(emmited.find(def) == emmited.end())
  579. {
  580. emmited.insert(def);
  581. fout << "<pathentry kind=\"mac\" name=\"" << def
  582. << "\" path=\"\" value=\"" << this->EscapeForXML(val)
  583. << "\"/>\n";
  584. }
  585. }
  586. }
  587. }
  588. // include dirs
  589. emmited.clear();
  590. for (std::vector<cmLocalGenerator*>::const_iterator
  591. it = this->GlobalGenerator->GetLocalGenerators().begin();
  592. it != this->GlobalGenerator->GetLocalGenerators().end();
  593. ++it)
  594. {
  595. const std::vector<std::string>& includeDirs
  596. = (*it)->GetMakefile()->GetIncludeDirectories();
  597. this->AppendIncludeDirectories(fout, includeDirs, emmited);
  598. }
  599. // now also the system include directories, in case we found them in
  600. // CMakeSystemSpecificInformation.cmake. This makes Eclipse find the
  601. // standard headers.
  602. mf->GetDefinition("CMAKE_ECLIPSE_C_SYSTEM_INCLUDE_DIRS");
  603. std::string compiler = mf->GetSafeDefinition("CMAKE_C_COMPILER");
  604. if (!compiler.empty())
  605. {
  606. std::string systemIncludeDirs = mf->GetSafeDefinition(
  607. "CMAKE_ECLIPSE_C_SYSTEM_INCLUDE_DIRS");
  608. std::vector<std::string> dirs;
  609. cmSystemTools::ExpandListArgument(systemIncludeDirs.c_str(), dirs);
  610. this->AppendIncludeDirectories(fout, dirs, emmited);
  611. }
  612. compiler = mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
  613. if (!compiler.empty())
  614. {
  615. std::string systemIncludeDirs = mf->GetSafeDefinition(
  616. "CMAKE_ECLIPSE_CXX_SYSTEM_INCLUDE_DIRS");
  617. std::vector<std::string> dirs;
  618. cmSystemTools::ExpandListArgument(systemIncludeDirs.c_str(), dirs);
  619. this->AppendIncludeDirectories(fout, dirs, emmited);
  620. }
  621. fout << "</storageModule>\n";
  622. // add build targets
  623. fout <<
  624. "<storageModule moduleId=\"org.eclipse.cdt.make.core.buildtargets\">\n"
  625. "<buildTargets>\n"
  626. ;
  627. emmited.clear();
  628. const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  629. cmGlobalGenerator* generator
  630. = const_cast<cmGlobalGenerator*>(this->GlobalGenerator);
  631. std::string allTarget;
  632. std::string cleanTarget;
  633. if (generator->GetAllTargetName())
  634. {
  635. allTarget = generator->GetAllTargetName();
  636. }
  637. if (generator->GetCleanTargetName())
  638. {
  639. cleanTarget = generator->GetCleanTargetName();
  640. }
  641. // add all executable and library targets and some of the GLOBAL
  642. // and UTILITY targets
  643. for (std::vector<cmLocalGenerator*>::const_iterator
  644. it = this->GlobalGenerator->GetLocalGenerators().begin();
  645. it != this->GlobalGenerator->GetLocalGenerators().end();
  646. ++it)
  647. {
  648. const cmTargets& targets = (*it)->GetMakefile()->GetTargets();
  649. cmMakefile* makefile=(*it)->GetMakefile();
  650. std::string subdir = (*it)->Convert(makefile->GetCurrentOutputDirectory(),
  651. cmLocalGenerator::HOME_OUTPUT);
  652. if (subdir == ".")
  653. {
  654. subdir = "";
  655. }
  656. for(cmTargets::const_iterator ti=targets.begin(); ti!=targets.end(); ++ti)
  657. {
  658. switch(ti->second.GetType())
  659. {
  660. case cmTarget::GLOBAL_TARGET:
  661. {
  662. bool insertTarget = false;
  663. // Only add the global targets from CMAKE_BINARY_DIR,
  664. // not from the subdirs
  665. if (subdir.empty())
  666. {
  667. insertTarget = true;
  668. // only add the "edit_cache" target if it's not ccmake, because
  669. // this will not work within the IDE
  670. if (ti->first == "edit_cache")
  671. {
  672. if (strstr(makefile->GetRequiredDefinition
  673. ("CMAKE_EDIT_COMMAND"), "ccmake")!=NULL)
  674. {
  675. insertTarget = false;
  676. }
  677. }
  678. }
  679. if (insertTarget)
  680. {
  681. this->AppendTarget(fout, ti->first, make, subdir, ": ");
  682. }
  683. }
  684. break;
  685. case cmTarget::UTILITY:
  686. // Add all utility targets, except the Nightly/Continuous/
  687. // Experimental-"sub"targets as e.g. NightlyStart
  688. if (((ti->first.find("Nightly")==0) &&(ti->first!="Nightly"))
  689. || ((ti->first.find("Continuous")==0)&&(ti->first!="Continuous"))
  690. || ((ti->first.find("Experimental")==0)
  691. && (ti->first!="Experimental")))
  692. {
  693. break;
  694. }
  695. this->AppendTarget(fout, ti->first, make, subdir, ": ");
  696. break;
  697. case cmTarget::EXECUTABLE:
  698. case cmTarget::STATIC_LIBRARY:
  699. case cmTarget::SHARED_LIBRARY:
  700. case cmTarget::MODULE_LIBRARY:
  701. {
  702. const char* prefix = (ti->second.GetType()==cmTarget::EXECUTABLE ?
  703. "[exe] " : "[lib] ");
  704. this->AppendTarget(fout, ti->first, make, subdir, prefix);
  705. std::string fastTarget = ti->first;
  706. fastTarget += "/fast";
  707. this->AppendTarget(fout, fastTarget, make, subdir, prefix);
  708. }
  709. break;
  710. // ignore these:
  711. case cmTarget::INSTALL_FILES:
  712. case cmTarget::INSTALL_PROGRAMS:
  713. case cmTarget::INSTALL_DIRECTORY:
  714. default:
  715. break;
  716. }
  717. }
  718. // insert the all and clean targets in every subdir
  719. if (!allTarget.empty())
  720. {
  721. this->AppendTarget(fout, allTarget, make, subdir, ": ");
  722. }
  723. if (!cleanTarget.empty())
  724. {
  725. this->AppendTarget(fout, cleanTarget, make, subdir, ": ");
  726. }
  727. //insert rules for compiling, preprocessing and assembling individual files
  728. cmLocalUnixMakefileGenerator3* lumg=(cmLocalUnixMakefileGenerator3*)*it;
  729. std::vector<std::string> objectFileTargets;
  730. lumg->GetIndividualFileTargets(objectFileTargets);
  731. for(std::vector<std::string>::const_iterator fit=objectFileTargets.begin();
  732. fit != objectFileTargets.end();
  733. ++fit)
  734. {
  735. const char* prefix = "[obj] ";
  736. if ((*fit)[fit->length()-1] == 's')
  737. {
  738. prefix = "[to asm] ";
  739. }
  740. else if ((*fit)[fit->length()-1] == 'i')
  741. {
  742. prefix = "[pre] ";
  743. }
  744. this->AppendTarget(fout, *fit, make, subdir, prefix);
  745. }
  746. }
  747. fout << "</buildTargets>\n"
  748. "</storageModule>\n"
  749. ;
  750. this->AppendStorageScanners(fout, *mf);
  751. fout << "</cconfiguration>\n"
  752. "</storageModule>\n"
  753. "<storageModule moduleId=\"cdtBuildSystem\" version=\"4.0.0\">\n"
  754. "<project id=\"" << mf->GetProjectName() << ".null.1\""
  755. " name=\"" << mf->GetProjectName() << "\"/>\n"
  756. "</storageModule>\n"
  757. "</cproject>\n"
  758. ;
  759. }
  760. //----------------------------------------------------------------------------
  761. cmExtraEclipseCDT4Generator::EclipseToolchainType
  762. cmExtraEclipseCDT4Generator::GetToolChainType(const cmMakefile& makefile)
  763. {
  764. if (makefile.IsSet("UNIX"))
  765. {
  766. if (makefile.IsSet("CYGWIN"))
  767. {
  768. return EclipseToolchainCygwin;
  769. }
  770. if (makefile.IsSet("APPLE" ))
  771. {
  772. return EclipseToolchainMacOSX;
  773. }
  774. // *** how do I determine if it is Solaris ???
  775. return EclipseToolchainLinux;
  776. }
  777. else if (makefile.IsSet("WIN32"))
  778. {
  779. if (makefile.IsSet("MINGW"))
  780. {
  781. return EclipseToolchainMinGW;
  782. }
  783. if (makefile.IsSet("MSYS" ))
  784. {
  785. return EclipseToolchainMinGW;
  786. }
  787. return EclipseToolchainOther;
  788. }
  789. else
  790. {
  791. return EclipseToolchainOther;
  792. }
  793. }
  794. std::string
  795. cmExtraEclipseCDT4Generator::GetEclipsePath(const std::string& path)
  796. {
  797. #if defined(__CYGWIN__)
  798. std::string cmd = "cygpath -m " + path;
  799. std::string out;
  800. if (!cmSystemTools::RunCommand(cmd.c_str(), out, 0, false))
  801. {
  802. return path;
  803. }
  804. else
  805. {
  806. out.erase(out.find_last_of('\n'));
  807. return out;
  808. }
  809. #else
  810. return path;
  811. #endif
  812. }
  813. std::string
  814. cmExtraEclipseCDT4Generator::GetPathBasename(const std::string& path)
  815. {
  816. std::string outputBasename = path;
  817. while (outputBasename.size() > 0 &&
  818. (outputBasename[outputBasename.size() - 1] == '/' ||
  819. outputBasename[outputBasename.size() - 1] == '\\'))
  820. {
  821. outputBasename.resize(outputBasename.size() - 1);
  822. }
  823. std::string::size_type loc = outputBasename.find_last_of("/\\");
  824. if (loc != std::string::npos)
  825. {
  826. outputBasename = outputBasename.substr(loc + 1);
  827. }
  828. return outputBasename;
  829. }
  830. std::string
  831. cmExtraEclipseCDT4Generator::GenerateProjectName(const std::string& name,
  832. const std::string& type,
  833. const std::string& path)
  834. {
  835. return name + (type.empty() ? "" : "-") + type + "@" + path;
  836. }
  837. std::string cmExtraEclipseCDT4Generator::EscapeForXML(const std::string& value)
  838. {
  839. std::string str = value;
  840. cmSystemTools::ReplaceString(str, "&", "&amp;");
  841. cmSystemTools::ReplaceString(str, "<", "&lt;");
  842. cmSystemTools::ReplaceString(str, ">", "&gt;");
  843. cmSystemTools::ReplaceString(str, "\"", "&quot;");
  844. // NOTE: This one is not necessary, since as of Eclipse CDT4 it will
  845. // automatically change this to the original value (').
  846. //cmSystemTools::ReplaceString(str, "'", "&apos;");
  847. return str;
  848. }
  849. //----------------------------------------------------------------------------
  850. // Helper functions
  851. //----------------------------------------------------------------------------
  852. void cmExtraEclipseCDT4Generator
  853. ::AppendStorageScanners(cmGeneratedFileStream& fout,
  854. const cmMakefile& makefile)
  855. {
  856. // we need the "make" and the C (or C++) compiler which are used, Alex
  857. std::string make = makefile.GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  858. std::string compiler = makefile.GetSafeDefinition("CMAKE_C_COMPILER");
  859. if (compiler.empty())
  860. {
  861. compiler = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER");
  862. }
  863. if (compiler.empty()) //Hmm, what to do now ?
  864. {
  865. compiler = "gcc";
  866. }
  867. // the following right now hardcodes gcc behaviour :-/
  868. fout <<
  869. "<storageModule moduleId=\"scannerConfiguration\">\n"
  870. "<autodiscovery enabled=\"true\" problemReportingEnabled=\"true\""
  871. " selectedProfileId="
  872. "\"org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile\"/>\n"
  873. ;
  874. cmExtraEclipseCDT4Generator::AppendScannerProfile(fout,
  875. "org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile",
  876. true, "", true, "specsFile",
  877. "-E -P -v -dD ${plugin_state_location}/${specs_file}",
  878. compiler, true, true);
  879. cmExtraEclipseCDT4Generator::AppendScannerProfile(fout,
  880. "org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile",
  881. true, "", true, "makefileGenerator",
  882. "-f ${project_name}_scd.mk",
  883. make, true, true);
  884. fout << "</storageModule>\n";
  885. }
  886. // The prefix is prepended before the actual name of the target. The purpose
  887. // of that is to sort the targets in the view of Eclipse, so that at first
  888. // the global/utility/all/clean targets appear ": ", then the executable
  889. // targets "[exe] ", then the libraries "[lib]", then the rules for the
  890. // object files "[obj]", then for preprocessing only "[pre] " and
  891. // finally the assembly files "[to asm] ". Note the "to" in "to asm",
  892. // without it, "asm" would be the first targets in the list, with the "to"
  893. // they are the last targets, which makes more sense.
  894. void cmExtraEclipseCDT4Generator::AppendTarget(cmGeneratedFileStream& fout,
  895. const std::string& target,
  896. const std::string& make,
  897. const std::string& path,
  898. const char* prefix)
  899. {
  900. fout <<
  901. "<target name=\"" << prefix << target << "\""
  902. " path=\"" << path.c_str() << "\""
  903. " targetID=\"org.eclipse.cdt.make.MakeTargetBuilder\">\n"
  904. "<buildCommand>"
  905. << cmExtraEclipseCDT4Generator::GetEclipsePath(make)
  906. << "</buildCommand>\n"
  907. "<buildArguments/>\n"
  908. "<buildTarget>" << target << "</buildTarget>\n"
  909. "<stopOnError>true</stopOnError>\n"
  910. "<useDefaultCommand>false</useDefaultCommand>\n"
  911. "</target>\n"
  912. ;
  913. }
  914. void cmExtraEclipseCDT4Generator
  915. ::AppendScannerProfile(cmGeneratedFileStream& fout,
  916. const std::string& profileID,
  917. bool openActionEnabled,
  918. const std::string& openActionFilePath,
  919. bool pParserEnabled,
  920. const std::string& scannerInfoProviderID,
  921. const std::string& runActionArguments,
  922. const std::string& runActionCommand,
  923. bool runActionUseDefault,
  924. bool sipParserEnabled)
  925. {
  926. fout <<
  927. "<profile id=\"" << profileID << "\">\n"
  928. "<buildOutputProvider>\n"
  929. "<openAction enabled=\"" << (openActionEnabled ? "true" : "false")
  930. << "\" filePath=\"" << openActionFilePath << "\"/>\n"
  931. "<parser enabled=\"" << (pParserEnabled ? "true" : "false") << "\"/>\n"
  932. "</buildOutputProvider>\n"
  933. "<scannerInfoProvider id=\"" << scannerInfoProviderID << "\">\n"
  934. "<runAction arguments=\"" << runActionArguments << "\""
  935. " command=\"" << runActionCommand
  936. << "\" useDefault=\"" << (runActionUseDefault ? "true":"false") << "\"/>\n"
  937. "<parser enabled=\"" << (sipParserEnabled ? "true" : "false") << "\"/>\n"
  938. "</scannerInfoProvider>\n"
  939. "</profile>\n"
  940. ;
  941. }
  942. void cmExtraEclipseCDT4Generator
  943. ::AppendLinkedResource (cmGeneratedFileStream& fout,
  944. const std::string& name,
  945. const std::string& path)
  946. {
  947. fout <<
  948. "\t\t<link>\n"
  949. "\t\t\t<name>" << name << "</name>\n"
  950. "\t\t\t<type>2</type>\n"
  951. "\t\t\t<location>"
  952. << path
  953. << "</location>\n"
  954. "\t\t</link>\n"
  955. ;
  956. }
  957. bool cmExtraEclipseCDT4Generator
  958. ::AppendOutLinkedResource(cmGeneratedFileStream& fout,
  959. const std::string& defname,
  960. const std::string& altdefname)
  961. {
  962. if (defname.empty() && altdefname.empty())
  963. {
  964. return false;
  965. }
  966. std::string outputPath = (defname.empty() ? altdefname : defname);
  967. if (!cmSystemTools::FileIsFullPath(outputPath.c_str()))
  968. {
  969. outputPath = this->HomeOutputDirectory + "/" + outputPath;
  970. }
  971. if (cmSystemTools::IsSubDirectory(outputPath.c_str(),
  972. this->HomeOutputDirectory.c_str()))
  973. {
  974. return false;
  975. }
  976. std::string name = this->GetPathBasename(outputPath);
  977. // make sure linked resource name is unique
  978. while (this->GlobalGenerator->GetProjectMap().find(name)
  979. != this->GlobalGenerator->GetProjectMap().end())
  980. {
  981. name += "_";
  982. }
  983. if (std::find(this->OutLinkedResources.begin(),
  984. this->OutLinkedResources.end(),
  985. name)
  986. != this->OutLinkedResources.end())
  987. {
  988. return false;
  989. }
  990. else
  991. {
  992. this->AppendLinkedResource(fout, name,
  993. this->GetEclipsePath(outputPath));
  994. this->OutLinkedResources.push_back(name);
  995. return true;
  996. }
  997. }