cmExtraEclipseCDT4Generator.cxx 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  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", true);
  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(
  596. "CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS");
  597. if(cDefs)
  598. {
  599. // Expand the list.
  600. std::vector<std::string> defs;
  601. cmSystemTools::ExpandListArgument(cDefs, defs, true);
  602. // the list must contain only definition-value pairs:
  603. if ((defs.size() % 2) == 0)
  604. {
  605. std::vector<std::string>::const_iterator di = defs.begin();
  606. while (di != defs.end())
  607. {
  608. std::string def = *di;
  609. ++di;
  610. std::string val;
  611. if (di != defs.end())
  612. {
  613. val = *di;
  614. ++di;
  615. }
  616. // insert the definition if not already added.
  617. if(emmited.find(def) == emmited.end())
  618. {
  619. emmited.insert(def);
  620. fout << "<pathentry kind=\"mac\" name=\"" << def
  621. << "\" path=\"\" value=\"" << this->EscapeForXML(val)
  622. << "\"/>\n";
  623. }
  624. }
  625. }
  626. }
  627. // add system defined c++ macros
  628. const char* cxxDefs = mf->GetDefinition(
  629. "CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS");
  630. if(cxxDefs)
  631. {
  632. // Expand the list.
  633. std::vector<std::string> defs;
  634. cmSystemTools::ExpandListArgument(cxxDefs, defs, true);
  635. // the list must contain only definition-value pairs:
  636. if ((defs.size() % 2) == 0)
  637. {
  638. std::vector<std::string>::const_iterator di = defs.begin();
  639. while (di != defs.end())
  640. {
  641. std::string def = *di;
  642. ++di;
  643. std::string val;
  644. if (di != defs.end())
  645. {
  646. val = *di;
  647. ++di;
  648. }
  649. // insert the definition if not already added.
  650. if(emmited.find(def) == emmited.end())
  651. {
  652. emmited.insert(def);
  653. fout << "<pathentry kind=\"mac\" name=\"" << def
  654. << "\" path=\"\" value=\"" << this->EscapeForXML(val)
  655. << "\"/>\n";
  656. }
  657. }
  658. }
  659. }
  660. // include dirs
  661. emmited.clear();
  662. for (std::vector<cmLocalGenerator*>::const_iterator
  663. it = this->GlobalGenerator->GetLocalGenerators().begin();
  664. it != this->GlobalGenerator->GetLocalGenerators().end();
  665. ++it)
  666. {
  667. const std::vector<std::string>& includeDirs
  668. = (*it)->GetMakefile()->GetIncludeDirectories();
  669. this->AppendIncludeDirectories(fout, includeDirs, emmited);
  670. }
  671. // now also the system include directories, in case we found them in
  672. // CMakeSystemSpecificInformation.cmake. This makes Eclipse find the
  673. // standard headers.
  674. std::string compiler = mf->GetSafeDefinition("CMAKE_C_COMPILER");
  675. if (!compiler.empty())
  676. {
  677. std::string systemIncludeDirs = mf->GetSafeDefinition(
  678. "CMAKE_EXTRA_GENERATOR_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_EXTRA_GENERATOR_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. std::string arg1 = makefile.GetSafeDefinition("CMAKE_C_COMPILER_ARG1");
  907. if (compiler.empty())
  908. {
  909. compiler = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER");
  910. arg1 = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER_ARG1");
  911. }
  912. if (compiler.empty()) //Hmm, what to do now ?
  913. {
  914. compiler = "gcc";
  915. }
  916. // the following right now hardcodes gcc behaviour :-/
  917. std::string compilerArgs =
  918. "-E -P -v -dD ${plugin_state_location}/${specs_file}";
  919. if (!arg1.empty())
  920. {
  921. arg1 += " ";
  922. compilerArgs = arg1 + compilerArgs;
  923. }
  924. fout <<
  925. "<storageModule moduleId=\"scannerConfiguration\">\n"
  926. "<autodiscovery enabled=\"true\" problemReportingEnabled=\"true\""
  927. " selectedProfileId="
  928. "\"org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile\"/>\n"
  929. ;
  930. cmExtraEclipseCDT4Generator::AppendScannerProfile(fout,
  931. "org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile",
  932. true, "", true, "specsFile",
  933. compilerArgs,
  934. compiler, true, true);
  935. cmExtraEclipseCDT4Generator::AppendScannerProfile(fout,
  936. "org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile",
  937. true, "", true, "makefileGenerator",
  938. "-f ${project_name}_scd.mk",
  939. make, true, true);
  940. fout << "</storageModule>\n";
  941. }
  942. // The prefix is prepended before the actual name of the target. The purpose
  943. // of that is to sort the targets in the view of Eclipse, so that at first
  944. // the global/utility/all/clean targets appear ": ", then the executable
  945. // targets "[exe] ", then the libraries "[lib]", then the rules for the
  946. // object files "[obj]", then for preprocessing only "[pre] " and
  947. // finally the assembly files "[to asm] ". Note the "to" in "to asm",
  948. // without it, "asm" would be the first targets in the list, with the "to"
  949. // they are the last targets, which makes more sense.
  950. void cmExtraEclipseCDT4Generator::AppendTarget(cmGeneratedFileStream& fout,
  951. const std::string& target,
  952. const std::string& make,
  953. const std::string& makeArgs,
  954. const std::string& path,
  955. const char* prefix)
  956. {
  957. std::string targetXml = cmExtraEclipseCDT4Generator::EscapeForXML(target);
  958. std::string pathXml = cmExtraEclipseCDT4Generator::EscapeForXML(path);
  959. fout <<
  960. "<target name=\"" << prefix << targetXml << "\""
  961. " path=\"" << pathXml.c_str() << "\""
  962. " targetID=\"org.eclipse.cdt.make.MakeTargetBuilder\">\n"
  963. "<buildCommand>"
  964. << cmExtraEclipseCDT4Generator::GetEclipsePath(make)
  965. << "</buildCommand>\n"
  966. "<buildArguments>" << makeArgs << "</buildArguments>\n"
  967. "<buildTarget>" << targetXml << "</buildTarget>\n"
  968. "<stopOnError>true</stopOnError>\n"
  969. "<useDefaultCommand>false</useDefaultCommand>\n"
  970. "</target>\n"
  971. ;
  972. }
  973. void cmExtraEclipseCDT4Generator
  974. ::AppendScannerProfile(cmGeneratedFileStream& fout,
  975. const std::string& profileID,
  976. bool openActionEnabled,
  977. const std::string& openActionFilePath,
  978. bool pParserEnabled,
  979. const std::string& scannerInfoProviderID,
  980. const std::string& runActionArguments,
  981. const std::string& runActionCommand,
  982. bool runActionUseDefault,
  983. bool sipParserEnabled)
  984. {
  985. fout <<
  986. "<profile id=\"" << profileID << "\">\n"
  987. "<buildOutputProvider>\n"
  988. "<openAction enabled=\"" << (openActionEnabled ? "true" : "false")
  989. << "\" filePath=\"" << openActionFilePath << "\"/>\n"
  990. "<parser enabled=\"" << (pParserEnabled ? "true" : "false") << "\"/>\n"
  991. "</buildOutputProvider>\n"
  992. "<scannerInfoProvider id=\"" << scannerInfoProviderID << "\">\n"
  993. "<runAction arguments=\"" << runActionArguments << "\""
  994. " command=\"" << runActionCommand
  995. << "\" useDefault=\"" << (runActionUseDefault ? "true":"false") << "\"/>\n"
  996. "<parser enabled=\"" << (sipParserEnabled ? "true" : "false") << "\"/>\n"
  997. "</scannerInfoProvider>\n"
  998. "</profile>\n"
  999. ;
  1000. }
  1001. void cmExtraEclipseCDT4Generator
  1002. ::AppendLinkedResource (cmGeneratedFileStream& fout,
  1003. const std::string& name,
  1004. const std::string& path,
  1005. bool isVirtualFolder)
  1006. {
  1007. const char* locationTag = "location";
  1008. if (isVirtualFolder) // ... and not a linked folder
  1009. {
  1010. locationTag = "locationURI";
  1011. }
  1012. fout <<
  1013. "\t\t<link>\n"
  1014. "\t\t\t<name>"
  1015. << cmExtraEclipseCDT4Generator::EscapeForXML(name)
  1016. << "</name>\n"
  1017. "\t\t\t<type>2</type>\n"
  1018. "\t\t\t<" << locationTag << ">"
  1019. << cmExtraEclipseCDT4Generator::EscapeForXML(path)
  1020. << "</" << locationTag << ">\n"
  1021. "\t\t</link>\n"
  1022. ;
  1023. }
  1024. bool cmExtraEclipseCDT4Generator
  1025. ::AppendOutLinkedResource(cmGeneratedFileStream& fout,
  1026. const std::string& defname,
  1027. const std::string& altdefname)
  1028. {
  1029. if (defname.empty() && altdefname.empty())
  1030. {
  1031. return false;
  1032. }
  1033. std::string outputPath = (defname.empty() ? altdefname : defname);
  1034. if (!cmSystemTools::FileIsFullPath(outputPath.c_str()))
  1035. {
  1036. outputPath = this->HomeOutputDirectory + "/" + outputPath;
  1037. }
  1038. if (cmSystemTools::IsSubDirectory(outputPath.c_str(),
  1039. this->HomeOutputDirectory.c_str()))
  1040. {
  1041. return false;
  1042. }
  1043. std::string name = this->GetPathBasename(outputPath);
  1044. // make sure linked resource name is unique
  1045. while (this->GlobalGenerator->GetProjectMap().find(name)
  1046. != this->GlobalGenerator->GetProjectMap().end())
  1047. {
  1048. name += "_";
  1049. }
  1050. if (std::find(this->OutLinkedResources.begin(),
  1051. this->OutLinkedResources.end(),
  1052. name)
  1053. != this->OutLinkedResources.end())
  1054. {
  1055. return false;
  1056. }
  1057. else
  1058. {
  1059. this->AppendLinkedResource(fout, name,
  1060. this->GetEclipsePath(outputPath));
  1061. this->OutLinkedResources.push_back(name);
  1062. return true;
  1063. }
  1064. }