cmExtraEclipseCDT4Generator.cxx 39 KB

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