cmExtraEclipseCDT4Generator.cxx 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  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 "cmSourceFile.h"
  19. #include "cmSystemTools.h"
  20. #include <stdlib.h>
  21. #include <assert.h>
  22. //----------------------------------------------------------------------------
  23. cmExtraEclipseCDT4Generator
  24. ::cmExtraEclipseCDT4Generator() : cmExternalMakefileProjectGenerator()
  25. {
  26. // TODO: Verify if __CYGWIN__ should be checked.
  27. //#if defined(_WIN32) && !defined(__CYGWIN__)
  28. #if defined(_WIN32)
  29. this->SupportedGlobalGenerators.push_back("NMake Makefiles");
  30. this->SupportedGlobalGenerators.push_back("MinGW Makefiles");
  31. // this->SupportedGlobalGenerators.push_back("MSYS Makefiles");
  32. #endif
  33. this->SupportedGlobalGenerators.push_back("Ninja");
  34. this->SupportedGlobalGenerators.push_back("Unix Makefiles");
  35. this->SupportsVirtualFolders = true;
  36. this->GenerateLinkedResources = true;
  37. }
  38. //----------------------------------------------------------------------------
  39. void cmExtraEclipseCDT4Generator
  40. ::GetDocumentation(cmDocumentationEntry& entry, const char*) const
  41. {
  42. entry.Name = this->GetName();
  43. entry.Brief = "Generates Eclipse CDT 4.0 project files.";
  44. entry.Full =
  45. "Project files for Eclipse will be created in the top directory. "
  46. "In out of source builds, a linked resource to the top level source "
  47. "directory will be created."
  48. "Additionally a hierarchy of makefiles is generated into the "
  49. "build tree. The appropriate make program can build the project through "
  50. "the default make target. A \"make install\" target is also provided.";
  51. }
  52. //----------------------------------------------------------------------------
  53. void cmExtraEclipseCDT4Generator::Generate()
  54. {
  55. const cmMakefile* mf
  56. = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  57. std::string eclipseVersion = mf->GetSafeDefinition("CMAKE_ECLIPSE_VERSION");
  58. cmsys::RegularExpression regex(".*([0-9]+\\.[0-9]+).*");
  59. if (regex.find(eclipseVersion.c_str()))
  60. {
  61. unsigned int majorVersion = 0;
  62. unsigned int minorVersion = 0;
  63. int res=sscanf(regex.match(1).c_str(), "%u.%u", &majorVersion,
  64. &minorVersion);
  65. if (res == 2)
  66. {
  67. int version = majorVersion * 1000 + minorVersion;
  68. if (version < 3006) // 3.6 is Helios
  69. {
  70. this->SupportsVirtualFolders = false;
  71. }
  72. }
  73. }
  74. // TODO: Decide if these are local or member variables
  75. this->HomeDirectory = mf->GetHomeDirectory();
  76. this->HomeOutputDirectory = mf->GetHomeOutputDirectory();
  77. this->GenerateLinkedResources = mf->IsOn(
  78. "CMAKE_ECLIPSE_GENERATE_LINKED_RESOURCES");
  79. this->IsOutOfSourceBuild = (this->HomeDirectory!=this->HomeOutputDirectory);
  80. this->GenerateSourceProject = (this->IsOutOfSourceBuild &&
  81. mf->IsOn("CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT"));
  82. if ((this->GenerateSourceProject == false)
  83. && (mf->IsOn("ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT")))
  84. {
  85. mf->IssueMessage(cmake::WARNING,
  86. "ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT is set to TRUE, "
  87. "but this variable is not supported anymore since CMake 2.8.7.\n"
  88. "Enable CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT instead.");
  89. }
  90. if (cmSystemTools::IsSubDirectory(this->HomeOutputDirectory.c_str(),
  91. this->HomeDirectory.c_str()))
  92. {
  93. mf->IssueMessage(cmake::WARNING, "The build directory is a subdirectory "
  94. "of the source directory.\n"
  95. "This is not supported well by Eclipse. It is strongly "
  96. "recommended to use a build directory which is a "
  97. "sibling of the source directory.");
  98. }
  99. // NOTE: This is not good, since it pollutes the source tree. However,
  100. // Eclipse doesn't allow CVS/SVN to work when the .project is not in
  101. // the cvs/svn root directory. Hence, this is provided as an option.
  102. if (this->GenerateSourceProject)
  103. {
  104. // create .project file in the source tree
  105. this->CreateSourceProjectFile();
  106. }
  107. // create a .project file
  108. this->CreateProjectFile();
  109. // create a .cproject file
  110. this->CreateCProjectFile();
  111. }
  112. void cmExtraEclipseCDT4Generator::CreateSourceProjectFile()
  113. {
  114. assert(this->HomeDirectory != this->HomeOutputDirectory);
  115. // set up the project name: <project>-Source@<baseSourcePathName>
  116. const cmMakefile* mf
  117. = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  118. std::string name = this->GenerateProjectName(mf->GetProjectName(), "Source",
  119. this->GetPathBasename(this->HomeDirectory));
  120. const std::string filename = this->HomeDirectory + "/.project";
  121. cmGeneratedFileStream fout(filename.c_str());
  122. if (!fout)
  123. {
  124. return;
  125. }
  126. fout <<
  127. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  128. "<projectDescription>\n"
  129. "\t<name>" << this->EscapeForXML(name) << "</name>\n"
  130. "\t<comment></comment>\n"
  131. "\t<projects>\n"
  132. "\t</projects>\n"
  133. "\t<buildSpec>\n"
  134. "\t</buildSpec>\n"
  135. "\t<natures>\n"
  136. "\t</natures>\n"
  137. "\t<linkedResources>\n";
  138. if (this->SupportsVirtualFolders)
  139. {
  140. this->CreateLinksToSubprojects(fout, this->HomeDirectory);
  141. this->SrcLinkedResources.clear();
  142. }
  143. fout <<
  144. "\t</linkedResources>\n"
  145. "</projectDescription>\n"
  146. ;
  147. }
  148. //----------------------------------------------------------------------------
  149. void cmExtraEclipseCDT4Generator::AddEnvVar(cmGeneratedFileStream& fout,
  150. const char* envVar, cmMakefile* mf)
  151. {
  152. // get the variables from the environment and from the cache and then
  153. // figure out which one to use:
  154. const char* envVarValue = getenv(envVar);
  155. std::string cacheEntryName = "CMAKE_ECLIPSE_ENVVAR_";
  156. cacheEntryName += envVar;
  157. const char* cacheValue = mf->GetCacheManager()->GetCacheValue(
  158. cacheEntryName.c_str());
  159. // now we have both, decide which one to use
  160. std::string valueToUse;
  161. if (envVarValue==0 && cacheValue==0)
  162. {
  163. // nothing known, do nothing
  164. valueToUse = "";
  165. }
  166. else if (envVarValue!=0 && cacheValue==0)
  167. {
  168. // The variable is in the env, but not in the cache. Use it and put it
  169. // in the cache
  170. valueToUse = envVarValue;
  171. mf->AddCacheDefinition(cacheEntryName.c_str(), valueToUse.c_str(),
  172. cacheEntryName.c_str(), cmCacheManager::STRING,
  173. true);
  174. mf->GetCacheManager()->SaveCache(mf->GetHomeOutputDirectory());
  175. }
  176. else if (envVarValue==0 && cacheValue!=0)
  177. {
  178. // It is already in the cache, but not in the env, so use it from the cache
  179. valueToUse = cacheValue;
  180. }
  181. else
  182. {
  183. // It is both in the cache and in the env.
  184. // Use the version from the env. except if the value from the env is
  185. // completely contained in the value from the cache (for the case that we
  186. // now have a PATH without MSVC dirs in the env. but had the full PATH with
  187. // all MSVC dirs during the cmake run which stored the var in the cache:
  188. valueToUse = cacheValue;
  189. if (valueToUse.find(envVarValue) == std::string::npos)
  190. {
  191. valueToUse = envVarValue;
  192. mf->AddCacheDefinition(cacheEntryName.c_str(), valueToUse.c_str(),
  193. cacheEntryName.c_str(), cmCacheManager::STRING,
  194. true);
  195. mf->GetCacheManager()->SaveCache(mf->GetHomeOutputDirectory());
  196. }
  197. }
  198. if (!valueToUse.empty())
  199. {
  200. fout << envVar << "=" << valueToUse << "|";
  201. }
  202. }
  203. //----------------------------------------------------------------------------
  204. void cmExtraEclipseCDT4Generator::CreateProjectFile()
  205. {
  206. cmMakefile* mf
  207. = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  208. const std::string filename = this->HomeOutputDirectory + "/.project";
  209. cmGeneratedFileStream fout(filename.c_str());
  210. if (!fout)
  211. {
  212. return;
  213. }
  214. std::string compilerId = mf->GetSafeDefinition("CMAKE_C_COMPILER_ID");
  215. if (compilerId.empty()) // no C compiler, try the C++ compiler:
  216. {
  217. compilerId = mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID");
  218. }
  219. fout <<
  220. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  221. "<projectDescription>\n"
  222. "\t<name>" <<
  223. this->GenerateProjectName(mf->GetProjectName(),
  224. mf->GetSafeDefinition("CMAKE_BUILD_TYPE"),
  225. this->GetPathBasename(this->HomeOutputDirectory))
  226. << "</name>\n"
  227. "\t<comment></comment>\n"
  228. "\t<projects>\n"
  229. "\t</projects>\n"
  230. "\t<buildSpec>\n"
  231. "\t\t<buildCommand>\n"
  232. "\t\t\t<name>org.eclipse.cdt.make.core.makeBuilder</name>\n"
  233. "\t\t\t<triggers>clean,full,incremental,</triggers>\n"
  234. "\t\t\t<arguments>\n"
  235. ;
  236. // use clean target
  237. fout <<
  238. "\t\t\t\t<dictionary>\n"
  239. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>\n"
  240. "\t\t\t\t\t<value>clean</value>\n"
  241. "\t\t\t\t</dictionary>\n"
  242. "\t\t\t\t<dictionary>\n"
  243. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enableCleanBuild</key>\n"
  244. "\t\t\t\t\t<value>true</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.append_environment</key>\n"
  248. "\t\t\t\t\t<value>true</value>\n"
  249. "\t\t\t\t</dictionary>\n"
  250. "\t\t\t\t<dictionary>\n"
  251. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.stopOnError</key>\n"
  252. "\t\t\t\t\t<value>true</value>\n"
  253. "\t\t\t\t</dictionary>\n"
  254. ;
  255. // set the make command
  256. std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  257. const std::string makeArgs = mf->GetSafeDefinition(
  258. "CMAKE_ECLIPSE_MAKE_ARGUMENTS");
  259. fout <<
  260. "\t\t\t\t<dictionary>\n"
  261. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enabledIncrementalBuild</key>\n"
  262. "\t\t\t\t\t<value>true</value>\n"
  263. "\t\t\t\t</dictionary>\n"
  264. "\t\t\t\t<dictionary>\n"
  265. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.command</key>\n"
  266. "\t\t\t\t\t<value>" << this->GetEclipsePath(make) << "</value>\n"
  267. "\t\t\t\t</dictionary>\n"
  268. "\t\t\t\t<dictionary>\n"
  269. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.contents</key>\n"
  270. "\t\t\t\t\t<value>org.eclipse.cdt.make.core.activeConfigSettings</value>\n"
  271. "\t\t\t\t</dictionary>\n"
  272. "\t\t\t\t<dictionary>\n"
  273. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.target.inc</key>\n"
  274. "\t\t\t\t\t<value>all</value>\n"
  275. "\t\t\t\t</dictionary>\n"
  276. "\t\t\t\t<dictionary>\n"
  277. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.arguments</key>\n"
  278. "\t\t\t\t\t<value>" << makeArgs << "</value>\n"
  279. "\t\t\t\t</dictionary>\n"
  280. "\t\t\t\t<dictionary>\n"
  281. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.buildLocation</key>\n"
  282. "\t\t\t\t\t<value>"
  283. << this->GetEclipsePath(this->HomeOutputDirectory) << "</value>\n"
  284. "\t\t\t\t</dictionary>\n"
  285. "\t\t\t\t<dictionary>\n"
  286. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>\n"
  287. "\t\t\t\t\t<value>false</value>\n"
  288. "\t\t\t\t</dictionary>\n"
  289. ;
  290. // set project specific environment
  291. fout <<
  292. "\t\t\t\t<dictionary>\n"
  293. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.environment</key>\n"
  294. "\t\t\t\t\t<value>VERBOSE=1|CMAKE_NO_VERBOSE=1|" //verbose Makefile output
  295. ;
  296. // set vsvars32.bat environment available at CMake time,
  297. // but not necessarily when eclipse is open
  298. if (compilerId == "MSVC")
  299. {
  300. AddEnvVar(fout, "PATH", mf);
  301. AddEnvVar(fout, "INCLUDE", mf);
  302. AddEnvVar(fout, "LIB", mf);
  303. AddEnvVar(fout, "LIBPATH", mf);
  304. }
  305. else if (compilerId == "Intel")
  306. {
  307. // if the env.var is set, use this one and put it in the cache
  308. // if the env.var is not set, but the value is in the cache,
  309. // use it from the cache:
  310. AddEnvVar(fout, "INTEL_LICENSE_FILE", mf);
  311. }
  312. fout <<
  313. "</value>\n"
  314. "\t\t\t\t</dictionary>\n"
  315. ;
  316. fout <<
  317. "\t\t\t\t<dictionary>\n"
  318. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enableFullBuild</key>\n"
  319. "\t\t\t\t\t<value>true</value>\n"
  320. "\t\t\t\t</dictionary>\n"
  321. "\t\t\t\t<dictionary>\n"
  322. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.target.auto</key>\n"
  323. "\t\t\t\t\t<value>all</value>\n"
  324. "\t\t\t\t</dictionary>\n"
  325. "\t\t\t\t<dictionary>\n"
  326. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enableAutoBuild</key>\n"
  327. "\t\t\t\t\t<value>false</value>\n"
  328. "\t\t\t\t</dictionary>\n"
  329. "\t\t\t\t<dictionary>\n"
  330. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.target.clean</key>\n"
  331. "\t\t\t\t\t<value>clean</value>\n"
  332. "\t\t\t\t</dictionary>\n"
  333. "\t\t\t\t<dictionary>\n"
  334. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.fullBuildTarget</key>\n"
  335. "\t\t\t\t\t<value>all</value>\n"
  336. "\t\t\t\t</dictionary>\n"
  337. "\t\t\t\t<dictionary>\n"
  338. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.buildArguments</key>\n"
  339. "\t\t\t\t\t<value></value>\n"
  340. "\t\t\t\t</dictionary>\n"
  341. "\t\t\t\t<dictionary>\n"
  342. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.build.location</key>\n"
  343. "\t\t\t\t\t<value>"
  344. << this->GetEclipsePath(this->HomeOutputDirectory) << "</value>\n"
  345. "\t\t\t\t</dictionary>\n"
  346. "\t\t\t\t<dictionary>\n"
  347. "\t\t\t\t\t<key>org.eclipse.cdt.make.core.autoBuildTarget</key>\n"
  348. "\t\t\t\t\t<value>all</value>\n"
  349. "\t\t\t\t</dictionary>\n"
  350. ;
  351. // set error parsers
  352. fout <<
  353. "\t\t\t\t<dictionary>\n"
  354. "\t\t\t\t\t<key>org.eclipse.cdt.core.errorOutputParser</key>\n"
  355. "\t\t\t\t\t<value>"
  356. ;
  357. if (compilerId == "MSVC")
  358. {
  359. fout << "org.eclipse.cdt.core.VCErrorParser;";
  360. }
  361. else if (compilerId == "Intel")
  362. {
  363. fout << "org.eclipse.cdt.core.ICCErrorParser;";
  364. }
  365. fout <<
  366. "org.eclipse.cdt.core.MakeErrorParser;"
  367. "org.eclipse.cdt.core.GCCErrorParser;"
  368. "org.eclipse.cdt.core.GASErrorParser;"
  369. "org.eclipse.cdt.core.GLDErrorParser;"
  370. "</value>\n"
  371. "\t\t\t\t</dictionary>\n"
  372. ;
  373. fout <<
  374. "\t\t\t</arguments>\n"
  375. "\t\t</buildCommand>\n"
  376. "\t\t<buildCommand>\n"
  377. "\t\t\t<name>org.eclipse.cdt.make.core.ScannerConfigBuilder</name>\n"
  378. "\t\t\t<arguments>\n"
  379. "\t\t\t</arguments>\n"
  380. "\t\t</buildCommand>\n"
  381. "\t</buildSpec>\n"
  382. ;
  383. // set natures for c/c++ projects
  384. fout <<
  385. "\t<natures>\n"
  386. // TODO: ccnature only if it is c++ ???
  387. "\t\t<nature>org.eclipse.cdt.core.ccnature</nature>\n"
  388. "\t\t<nature>org.eclipse.cdt.make.core.makeNature</nature>\n"
  389. "\t\t<nature>org.eclipse.cdt.make.core.ScannerConfigNature</nature>\n"
  390. "\t\t<nature>org.eclipse.cdt.core.cnature</nature>\n"
  391. "\t</natures>\n"
  392. ;
  393. fout << "\t<linkedResources>\n";
  394. // create linked resources
  395. if (this->IsOutOfSourceBuild)
  396. {
  397. // create a linked resource to CMAKE_SOURCE_DIR
  398. // (this is not done anymore for each project because of
  399. // http://public.kitware.com/Bug/view.php?id=9978 and because I found it
  400. // actually quite confusing in bigger projects with many directories and
  401. // projects, Alex
  402. std::string sourceLinkedResourceName = "[Source directory]";
  403. std::string linkSourceDirectory = this->GetEclipsePath(
  404. mf->GetStartDirectory());
  405. // .project dir can't be subdir of a linked resource dir
  406. if (!cmSystemTools::IsSubDirectory(this->HomeOutputDirectory.c_str(),
  407. linkSourceDirectory.c_str()))
  408. {
  409. this->AppendLinkedResource(fout, sourceLinkedResourceName,
  410. this->GetEclipsePath(linkSourceDirectory),
  411. LinkToFolder);
  412. this->SrcLinkedResources.push_back(sourceLinkedResourceName);
  413. }
  414. }
  415. if (this->SupportsVirtualFolders)
  416. {
  417. this->CreateLinksToSubprojects(fout, this->HomeOutputDirectory);
  418. this->CreateLinksForTargets(fout);
  419. }
  420. fout << "\t</linkedResources>\n";
  421. fout << "</projectDescription>\n";
  422. }
  423. //----------------------------------------------------------------------------
  424. void cmExtraEclipseCDT4Generator::CreateLinksForTargets(
  425. cmGeneratedFileStream& fout)
  426. {
  427. std::string linkName = "[Targets]";
  428. this->AppendLinkedResource(fout, linkName, "virtual:/virtual",VirtualFolder);
  429. for (std::vector<cmLocalGenerator*>::const_iterator
  430. lgIt = this->GlobalGenerator->GetLocalGenerators().begin();
  431. lgIt != this->GlobalGenerator->GetLocalGenerators().end();
  432. ++lgIt)
  433. {
  434. cmMakefile* makefile = (*lgIt)->GetMakefile();
  435. const cmTargets& targets = makefile->GetTargets();
  436. for(cmTargets::const_iterator ti=targets.begin(); ti!=targets.end();++ti)
  437. {
  438. std::string linkName2 = linkName;
  439. linkName2 += "/";
  440. switch(ti->second.GetType())
  441. {
  442. case cmTarget::EXECUTABLE:
  443. case cmTarget::STATIC_LIBRARY:
  444. case cmTarget::SHARED_LIBRARY:
  445. case cmTarget::MODULE_LIBRARY:
  446. case cmTarget::OBJECT_LIBRARY:
  447. {
  448. const char* prefix = (ti->second.GetType()==cmTarget::EXECUTABLE ?
  449. "[exe] " : "[lib] ");
  450. linkName2 += prefix;
  451. linkName2 += ti->first;
  452. this->AppendLinkedResource(fout, linkName2, "virtual:/virtual",
  453. VirtualFolder);
  454. if (!this->GenerateLinkedResources)
  455. {
  456. break; // skip generating the linked resources to the source files
  457. }
  458. std::vector<cmSourceGroup> sourceGroups=makefile->GetSourceGroups();
  459. // get the files from the source lists then add them to the groups
  460. cmTarget* tgt = const_cast<cmTarget*>(&ti->second);
  461. std::vector<cmSourceFile*>const & files = tgt->GetSourceFiles();
  462. for(std::vector<cmSourceFile*>::const_iterator sfIt = files.begin();
  463. sfIt != files.end();
  464. sfIt++)
  465. {
  466. // Add the file to the list of sources.
  467. std::string source = (*sfIt)->GetFullPath();
  468. cmSourceGroup& sourceGroup =
  469. makefile->FindSourceGroup(source.c_str(), sourceGroups);
  470. sourceGroup.AssignSource(*sfIt);
  471. }
  472. for(std::vector<cmSourceGroup>::iterator sgIt = sourceGroups.begin();
  473. sgIt != sourceGroups.end();
  474. ++sgIt)
  475. {
  476. std::string linkName3 = linkName2;
  477. linkName3 += "/";
  478. linkName3 += sgIt->GetFullName();
  479. this->AppendLinkedResource(fout, linkName3, "virtual:/virtual",
  480. VirtualFolder);
  481. std::vector<const cmSourceFile*> sFiles = sgIt->GetSourceFiles();
  482. for(std::vector<const cmSourceFile*>::const_iterator fileIt =
  483. sFiles.begin();
  484. fileIt != sFiles.end();
  485. ++fileIt)
  486. {
  487. std::string linkName4 = linkName3;
  488. linkName4 += "/";
  489. linkName4 +=
  490. cmSystemTools::GetFilenameName((*fileIt)->GetFullPath());
  491. this->AppendLinkedResource(fout, linkName4,
  492. (*fileIt)->GetFullPath(), LinkToFile);
  493. }
  494. }
  495. }
  496. break;
  497. // ignore all others:
  498. default:
  499. break;
  500. }
  501. }
  502. }
  503. }
  504. //----------------------------------------------------------------------------
  505. void cmExtraEclipseCDT4Generator::CreateLinksToSubprojects(
  506. cmGeneratedFileStream& fout, const std::string& baseDir)
  507. {
  508. if (!this->GenerateLinkedResources)
  509. {
  510. return;
  511. }
  512. // for each sub project create a linked resource to the source dir
  513. // - only if it is an out-of-source build
  514. this->AppendLinkedResource(fout, "[Subprojects]",
  515. "virtual:/virtual", VirtualFolder);
  516. for (std::map<cmStdString, std::vector<cmLocalGenerator*> >::const_iterator
  517. it = this->GlobalGenerator->GetProjectMap().begin();
  518. it != this->GlobalGenerator->GetProjectMap().end();
  519. ++it)
  520. {
  521. std::string linkSourceDirectory = this->GetEclipsePath(
  522. it->second[0]->GetMakefile()->GetStartDirectory());
  523. // a linked resource must not point to a parent directory of .project or
  524. // .project itself
  525. if ((baseDir != linkSourceDirectory) &&
  526. !cmSystemTools::IsSubDirectory(baseDir.c_str(),
  527. linkSourceDirectory.c_str()))
  528. {
  529. std::string linkName = "[Subprojects]/";
  530. linkName += it->first;
  531. this->AppendLinkedResource(fout, linkName,
  532. this->GetEclipsePath(linkSourceDirectory),
  533. LinkToFolder
  534. );
  535. this->SrcLinkedResources.push_back(it->first);
  536. }
  537. }
  538. }
  539. //----------------------------------------------------------------------------
  540. void cmExtraEclipseCDT4Generator::AppendIncludeDirectories(
  541. cmGeneratedFileStream& fout,
  542. const std::vector<std::string>& includeDirs,
  543. std::set<std::string>& emittedDirs)
  544. {
  545. for(std::vector<std::string>::const_iterator inc = includeDirs.begin();
  546. inc != includeDirs.end();
  547. ++inc)
  548. {
  549. if (!inc->empty())
  550. {
  551. std::string dir = cmSystemTools::CollapseFullPath(inc->c_str());
  552. // handle framework include dirs on OSX, the remainder after the
  553. // Frameworks/ part has to be stripped
  554. // /System/Library/Frameworks/GLUT.framework/Headers
  555. cmsys::RegularExpression frameworkRx("(.+/Frameworks)/.+\\.framework/");
  556. if(frameworkRx.find(dir.c_str()))
  557. {
  558. dir = frameworkRx.match(1);
  559. }
  560. if(emittedDirs.find(dir) == emittedDirs.end())
  561. {
  562. emittedDirs.insert(dir);
  563. fout << "<pathentry include=\""
  564. << cmExtraEclipseCDT4Generator::EscapeForXML(
  565. cmExtraEclipseCDT4Generator::GetEclipsePath(dir))
  566. << "\" kind=\"inc\" path=\"\" system=\"true\"/>\n";
  567. }
  568. }
  569. }
  570. }
  571. //----------------------------------------------------------------------------
  572. void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
  573. {
  574. std::set<std::string> emmited;
  575. const cmMakefile* mf
  576. = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  577. const std::string filename = this->HomeOutputDirectory + "/.cproject";
  578. cmGeneratedFileStream fout(filename.c_str());
  579. if (!fout)
  580. {
  581. return;
  582. }
  583. // add header
  584. fout <<
  585. "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
  586. "<?fileVersion 4.0.0?>\n\n"
  587. "<cproject>\n"
  588. "<storageModule moduleId=\"org.eclipse.cdt.core.settings\">\n"
  589. ;
  590. fout << "<cconfiguration id=\"org.eclipse.cdt.core.default.config.1\">\n";
  591. // Configuration settings...
  592. fout <<
  593. "<storageModule"
  594. " buildSystemId=\"org.eclipse.cdt.core.defaultConfigDataProvider\""
  595. " id=\"org.eclipse.cdt.core.default.config.1\""
  596. " moduleId=\"org.eclipse.cdt.core.settings\" name=\"Configuration\">\n"
  597. "<externalSettings/>\n"
  598. "<extensions>\n"
  599. ;
  600. // TODO: refactor this out...
  601. std::string executableFormat = mf->GetSafeDefinition(
  602. "CMAKE_EXECUTABLE_FORMAT");
  603. if (executableFormat == "ELF")
  604. {
  605. fout << "<extension id=\"org.eclipse.cdt.core.ELF\""
  606. " point=\"org.eclipse.cdt.core.BinaryParser\"/>\n"
  607. ;
  608. fout << "<extension id=\"org.eclipse.cdt.core.GNU_ELF\""
  609. " point=\"org.eclipse.cdt.core.BinaryParser\">\n"
  610. "<attribute key=\"addr2line\" value=\"addr2line\"/>\n"
  611. "<attribute key=\"c++filt\" value=\"c++filt\"/>\n"
  612. "</extension>\n"
  613. ;
  614. }
  615. else
  616. {
  617. std::string systemName = mf->GetSafeDefinition("CMAKE_SYSTEM_NAME");
  618. if (systemName == "CYGWIN")
  619. {
  620. fout << "<extension id=\"org.eclipse.cdt.core.Cygwin_PE\""
  621. " point=\"org.eclipse.cdt.core.BinaryParser\">\n"
  622. "<attribute key=\"addr2line\" value=\"addr2line\"/>\n"
  623. "<attribute key=\"c++filt\" value=\"c++filt\"/>\n"
  624. "<attribute key=\"cygpath\" value=\"cygpath\"/>\n"
  625. "<attribute key=\"nm\" value=\"nm\"/>\n"
  626. "</extension>\n"
  627. ;
  628. }
  629. else if (systemName == "Windows")
  630. {
  631. fout << "<extension id=\"org.eclipse.cdt.core.PE\""
  632. " point=\"org.eclipse.cdt.core.BinaryParser\"/>\n"
  633. ;
  634. }
  635. else if (systemName == "Darwin")
  636. {
  637. fout << "<extension id=\"org.eclipse.cdt.core.MachO\""
  638. " point=\"org.eclipse.cdt.core.BinaryParser\">\n"
  639. "<attribute key=\"c++filt\" value=\"c++filt\"/>\n"
  640. "</extension>\n"
  641. ;
  642. }
  643. else
  644. {
  645. // *** Should never get here ***
  646. fout << "<error_toolchain_type/>\n";
  647. }
  648. }
  649. fout << "</extensions>\n"
  650. "</storageModule>\n"
  651. ;
  652. // ???
  653. fout <<
  654. "<storageModule moduleId=\"org.eclipse.cdt.core.language.mapping\">\n"
  655. "<project-mappings/>\n"
  656. "</storageModule>\n"
  657. ;
  658. // ???
  659. fout<<"<storageModule moduleId=\"org.eclipse.cdt.core.externalSettings\"/>\n"
  660. ;
  661. // set the path entries (includes, libs, source dirs, etc.)
  662. fout << "<storageModule moduleId=\"org.eclipse.cdt.core.pathentry\">\n"
  663. ;
  664. // for each sub project with a linked resource to the source dir:
  665. // - make it type 'src'
  666. // - and exclude it from type 'out'
  667. std::string excludeFromOut;
  668. /* I don't know what the pathentry kind="src" are good for, e.g. autocompletion
  669. * works also without them. Done wrong, the indexer complains, see #12417
  670. * and #12213.
  671. * The CDT documentation is very terse on that:
  672. * "CDT_SOURCE: Entry kind constant describing a path entry identifying a
  673. * folder containing source code to be compiled."
  674. * Also on the cdt-dev list didn't bring any information:
  675. * http://web.archiveorange.com/archive/v/B4NlJDNIpYoOS1SbxFNy
  676. * So I'm disabling them for now, hoping that somebody will report if something
  677. * is not workging anymore.
  678. * Alex */
  679. #ifdef DO_CREATE_SRC_PATH_ENTRIES
  680. for (std::vector<std::string>::const_iterator
  681. it = this->SrcLinkedResources.begin();
  682. it != this->SrcLinkedResources.end();
  683. ++it)
  684. {
  685. fout << "<pathentry kind=\"src\" path=\"" << this->EscapeForXML(*it)
  686. << "\"/>\n";
  687. // exlude source directory from output search path
  688. // - only if not named the same as an output directory
  689. if (!cmSystemTools::FileIsDirectory(
  690. std::string(this->HomeOutputDirectory + "/" + *it).c_str()))
  691. {
  692. excludeFromOut += this->EscapeForXML(*it) + "/|";
  693. }
  694. }
  695. #endif
  696. excludeFromOut += "**/CMakeFiles/";
  697. fout << "<pathentry excluding=\"" << excludeFromOut
  698. << "\" kind=\"out\" path=\"\"/>\n";
  699. // add pre-processor definitions to allow eclipse to gray out sections
  700. emmited.clear();
  701. for (std::vector<cmLocalGenerator*>::const_iterator
  702. it = this->GlobalGenerator->GetLocalGenerators().begin();
  703. it != this->GlobalGenerator->GetLocalGenerators().end();
  704. ++it)
  705. {
  706. if(const char* cdefs = (*it)->GetMakefile()->GetProperty(
  707. "COMPILE_DEFINITIONS"))
  708. {
  709. // Expand the list.
  710. std::vector<std::string> defs;
  711. cmSystemTools::ExpandListArgument(cdefs, defs);
  712. for(std::vector<std::string>::const_iterator di = defs.begin();
  713. di != defs.end(); ++di)
  714. {
  715. std::string::size_type equals = di->find('=', 0);
  716. std::string::size_type enddef = di->length();
  717. std::string def;
  718. std::string val;
  719. if (equals != std::string::npos && equals < enddef)
  720. {
  721. // we have -DFOO=BAR
  722. def = di->substr(0, equals);
  723. val = di->substr(equals + 1, enddef - equals + 1);
  724. }
  725. else
  726. {
  727. // we have -DFOO
  728. def = *di;
  729. }
  730. // insert the definition if not already added.
  731. if(emmited.find(def) == emmited.end())
  732. {
  733. emmited.insert(def);
  734. fout << "<pathentry kind=\"mac\" name=\"" << def
  735. << "\" path=\"\" value=\"" << this->EscapeForXML(val)
  736. << "\"/>\n";
  737. }
  738. }
  739. }
  740. }
  741. // add system defined c macros
  742. const char* cDefs=mf->GetDefinition(
  743. "CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS");
  744. if(cDefs)
  745. {
  746. // Expand the list.
  747. std::vector<std::string> defs;
  748. cmSystemTools::ExpandListArgument(cDefs, defs, true);
  749. // the list must contain only definition-value pairs:
  750. if ((defs.size() % 2) == 0)
  751. {
  752. std::vector<std::string>::const_iterator di = defs.begin();
  753. while (di != defs.end())
  754. {
  755. std::string def = *di;
  756. ++di;
  757. std::string val;
  758. if (di != defs.end())
  759. {
  760. val = *di;
  761. ++di;
  762. }
  763. // insert the definition if not already added.
  764. if(emmited.find(def) == emmited.end())
  765. {
  766. emmited.insert(def);
  767. fout << "<pathentry kind=\"mac\" name=\"" << def
  768. << "\" path=\"\" value=\"" << this->EscapeForXML(val)
  769. << "\"/>\n";
  770. }
  771. }
  772. }
  773. }
  774. // add system defined c++ macros
  775. const char* cxxDefs = mf->GetDefinition(
  776. "CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS");
  777. if(cxxDefs)
  778. {
  779. // Expand the list.
  780. std::vector<std::string> defs;
  781. cmSystemTools::ExpandListArgument(cxxDefs, defs, true);
  782. // the list must contain only definition-value pairs:
  783. if ((defs.size() % 2) == 0)
  784. {
  785. std::vector<std::string>::const_iterator di = defs.begin();
  786. while (di != defs.end())
  787. {
  788. std::string def = *di;
  789. ++di;
  790. std::string val;
  791. if (di != defs.end())
  792. {
  793. val = *di;
  794. ++di;
  795. }
  796. // insert the definition if not already added.
  797. if(emmited.find(def) == emmited.end())
  798. {
  799. emmited.insert(def);
  800. fout << "<pathentry kind=\"mac\" name=\"" << def
  801. << "\" path=\"\" value=\"" << this->EscapeForXML(val)
  802. << "\"/>\n";
  803. }
  804. }
  805. }
  806. }
  807. // include dirs
  808. emmited.clear();
  809. for (std::vector<cmLocalGenerator*>::const_iterator
  810. it = this->GlobalGenerator->GetLocalGenerators().begin();
  811. it != this->GlobalGenerator->GetLocalGenerators().end();
  812. ++it)
  813. {
  814. cmGeneratorTargetsType targets = (*it)->GetMakefile()
  815. ->GetGeneratorTargets();
  816. for (cmGeneratorTargetsType::iterator l = targets.begin();
  817. l != targets.end(); ++l)
  818. {
  819. if (l->first->IsImported())
  820. {
  821. continue;
  822. }
  823. std::vector<std::string> includeDirs;
  824. const char *config = mf->GetDefinition("CMAKE_BUILD_TYPE");
  825. (*it)->GetIncludeDirectories(includeDirs, l->second, "C", config);
  826. this->AppendIncludeDirectories(fout, includeDirs, emmited);
  827. }
  828. }
  829. // now also the system include directories, in case we found them in
  830. // CMakeSystemSpecificInformation.cmake. This makes Eclipse find the
  831. // standard headers.
  832. std::string compiler = mf->GetSafeDefinition("CMAKE_C_COMPILER");
  833. if (!compiler.empty())
  834. {
  835. std::string systemIncludeDirs = mf->GetSafeDefinition(
  836. "CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS");
  837. std::vector<std::string> dirs;
  838. cmSystemTools::ExpandListArgument(systemIncludeDirs.c_str(), dirs);
  839. this->AppendIncludeDirectories(fout, dirs, emmited);
  840. }
  841. compiler = mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
  842. if (!compiler.empty())
  843. {
  844. std::string systemIncludeDirs = mf->GetSafeDefinition(
  845. "CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS");
  846. std::vector<std::string> dirs;
  847. cmSystemTools::ExpandListArgument(systemIncludeDirs.c_str(), dirs);
  848. this->AppendIncludeDirectories(fout, dirs, emmited);
  849. }
  850. fout << "</storageModule>\n";
  851. // add build targets
  852. fout <<
  853. "<storageModule moduleId=\"org.eclipse.cdt.make.core.buildtargets\">\n"
  854. "<buildTargets>\n"
  855. ;
  856. emmited.clear();
  857. const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  858. const std::string makeArgs = mf->GetSafeDefinition(
  859. "CMAKE_ECLIPSE_MAKE_ARGUMENTS");
  860. const std::string cmake = mf->GetRequiredDefinition("CMAKE_COMMAND");
  861. cmGlobalGenerator* generator
  862. = const_cast<cmGlobalGenerator*>(this->GlobalGenerator);
  863. std::string allTarget;
  864. std::string cleanTarget;
  865. if (generator->GetAllTargetName())
  866. {
  867. allTarget = generator->GetAllTargetName();
  868. }
  869. if (generator->GetCleanTargetName())
  870. {
  871. cleanTarget = generator->GetCleanTargetName();
  872. }
  873. // add all executable and library targets and some of the GLOBAL
  874. // and UTILITY targets
  875. for (std::vector<cmLocalGenerator*>::const_iterator
  876. it = this->GlobalGenerator->GetLocalGenerators().begin();
  877. it != this->GlobalGenerator->GetLocalGenerators().end();
  878. ++it)
  879. {
  880. const cmTargets& targets = (*it)->GetMakefile()->GetTargets();
  881. cmMakefile* makefile=(*it)->GetMakefile();
  882. std::string subdir = (*it)->Convert(makefile->GetCurrentOutputDirectory(),
  883. cmLocalGenerator::HOME_OUTPUT);
  884. if (subdir == ".")
  885. {
  886. subdir = "";
  887. }
  888. for(cmTargets::const_iterator ti=targets.begin(); ti!=targets.end(); ++ti)
  889. {
  890. switch(ti->second.GetType())
  891. {
  892. case cmTarget::GLOBAL_TARGET:
  893. {
  894. bool insertTarget = false;
  895. // Only add the global targets from CMAKE_BINARY_DIR,
  896. // not from the subdirs
  897. if (subdir.empty())
  898. {
  899. insertTarget = true;
  900. // only add the "edit_cache" target if it's not ccmake, because
  901. // this will not work within the IDE
  902. if (ti->first == "edit_cache")
  903. {
  904. const char* editCommand = makefile->GetDefinition
  905. ("CMAKE_EDIT_COMMAND");
  906. if (editCommand == 0)
  907. {
  908. insertTarget = false;
  909. }
  910. else if (strstr(editCommand, "ccmake")!=NULL)
  911. {
  912. insertTarget = false;
  913. }
  914. }
  915. }
  916. if (insertTarget)
  917. {
  918. this->AppendTarget(fout, ti->first, make, makeArgs, subdir, ": ");
  919. }
  920. }
  921. break;
  922. case cmTarget::UTILITY:
  923. // Add all utility targets, except the Nightly/Continuous/
  924. // Experimental-"sub"targets as e.g. NightlyStart
  925. if (((ti->first.find("Nightly")==0) &&(ti->first!="Nightly"))
  926. || ((ti->first.find("Continuous")==0)&&(ti->first!="Continuous"))
  927. || ((ti->first.find("Experimental")==0)
  928. && (ti->first!="Experimental")))
  929. {
  930. break;
  931. }
  932. this->AppendTarget(fout, ti->first, make, makeArgs, subdir, ": ");
  933. break;
  934. case cmTarget::EXECUTABLE:
  935. case cmTarget::STATIC_LIBRARY:
  936. case cmTarget::SHARED_LIBRARY:
  937. case cmTarget::MODULE_LIBRARY:
  938. case cmTarget::OBJECT_LIBRARY:
  939. {
  940. const char* prefix = (ti->second.GetType()==cmTarget::EXECUTABLE ?
  941. "[exe] " : "[lib] ");
  942. this->AppendTarget(fout, ti->first, make, makeArgs, subdir, prefix);
  943. std::string fastTarget = ti->first;
  944. fastTarget += "/fast";
  945. this->AppendTarget(fout, fastTarget, make, makeArgs, subdir, prefix);
  946. // Add Build and Clean targets in the virtual folder of targets:
  947. if (this->SupportsVirtualFolders)
  948. {
  949. std::string virtDir = "[Targets]/";
  950. virtDir += prefix;
  951. virtDir += ti->first;
  952. std::string buildArgs = "-C \"";
  953. buildArgs += makefile->GetHomeOutputDirectory();
  954. buildArgs += "\" ";
  955. buildArgs += makeArgs;
  956. this->AppendTarget(fout, "Build", make, buildArgs, virtDir, "",
  957. ti->first.c_str());
  958. std::string cleanArgs = "-E chdir \"";
  959. cleanArgs += makefile->GetCurrentOutputDirectory();
  960. cleanArgs += "\" \"";
  961. cleanArgs += cmake;
  962. cleanArgs += "\" -P \"";
  963. cleanArgs += (*it)->GetTargetDirectory(ti->second);
  964. cleanArgs += "/cmake_clean.cmake\"";
  965. this->AppendTarget(fout, "Clean", cmake, cleanArgs, virtDir, "", "");
  966. }
  967. }
  968. break;
  969. default:
  970. break;
  971. }
  972. }
  973. // insert the all and clean targets in every subdir
  974. if (!allTarget.empty())
  975. {
  976. this->AppendTarget(fout, allTarget, make, makeArgs, subdir, ": ");
  977. }
  978. if (!cleanTarget.empty())
  979. {
  980. this->AppendTarget(fout, cleanTarget, make, makeArgs, subdir, ": ");
  981. }
  982. //insert rules for compiling, preprocessing and assembling individual files
  983. std::vector<std::string> objectFileTargets;
  984. (*it)->GetIndividualFileTargets(objectFileTargets);
  985. for(std::vector<std::string>::const_iterator fit=objectFileTargets.begin();
  986. fit != objectFileTargets.end();
  987. ++fit)
  988. {
  989. const char* prefix = "[obj] ";
  990. if ((*fit)[fit->length()-1] == 's')
  991. {
  992. prefix = "[to asm] ";
  993. }
  994. else if ((*fit)[fit->length()-1] == 'i')
  995. {
  996. prefix = "[pre] ";
  997. }
  998. this->AppendTarget(fout, *fit, make, makeArgs, subdir, prefix);
  999. }
  1000. }
  1001. fout << "</buildTargets>\n"
  1002. "</storageModule>\n"
  1003. ;
  1004. this->AppendStorageScanners(fout, *mf);
  1005. fout << "</cconfiguration>\n"
  1006. "</storageModule>\n"
  1007. "<storageModule moduleId=\"cdtBuildSystem\" version=\"4.0.0\">\n"
  1008. "<project id=\"" << this->EscapeForXML(mf->GetProjectName())
  1009. << ".null.1\" name=\"" << this->EscapeForXML(mf->GetProjectName())
  1010. << "\"/>\n"
  1011. "</storageModule>\n"
  1012. "</cproject>\n"
  1013. ;
  1014. }
  1015. //----------------------------------------------------------------------------
  1016. std::string
  1017. cmExtraEclipseCDT4Generator::GetEclipsePath(const std::string& path)
  1018. {
  1019. #if defined(__CYGWIN__)
  1020. std::string cmd = "cygpath -m " + path;
  1021. std::string out;
  1022. if (!cmSystemTools::RunCommand(cmd.c_str(), out, 0, false))
  1023. {
  1024. return path;
  1025. }
  1026. else
  1027. {
  1028. out.erase(out.find_last_of('\n'));
  1029. return out;
  1030. }
  1031. #else
  1032. return path;
  1033. #endif
  1034. }
  1035. std::string
  1036. cmExtraEclipseCDT4Generator::GetPathBasename(const std::string& path)
  1037. {
  1038. std::string outputBasename = path;
  1039. while (outputBasename.size() > 0 &&
  1040. (outputBasename[outputBasename.size() - 1] == '/' ||
  1041. outputBasename[outputBasename.size() - 1] == '\\'))
  1042. {
  1043. outputBasename.resize(outputBasename.size() - 1);
  1044. }
  1045. std::string::size_type loc = outputBasename.find_last_of("/\\");
  1046. if (loc != std::string::npos)
  1047. {
  1048. outputBasename = outputBasename.substr(loc + 1);
  1049. }
  1050. return outputBasename;
  1051. }
  1052. std::string
  1053. cmExtraEclipseCDT4Generator::GenerateProjectName(const std::string& name,
  1054. const std::string& type,
  1055. const std::string& path)
  1056. {
  1057. return cmExtraEclipseCDT4Generator::EscapeForXML(name)
  1058. +(type.empty() ? "" : "-") + type + "@" + path;
  1059. }
  1060. std::string cmExtraEclipseCDT4Generator::EscapeForXML(const std::string& value)
  1061. {
  1062. std::string str = value;
  1063. cmSystemTools::ReplaceString(str, "&", "&amp;");
  1064. cmSystemTools::ReplaceString(str, "<", "&lt;");
  1065. cmSystemTools::ReplaceString(str, ">", "&gt;");
  1066. cmSystemTools::ReplaceString(str, "\"", "&quot;");
  1067. // NOTE: This one is not necessary, since as of Eclipse CDT4 it will
  1068. // automatically change this to the original value (').
  1069. //cmSystemTools::ReplaceString(str, "'", "&apos;");
  1070. return str;
  1071. }
  1072. //----------------------------------------------------------------------------
  1073. // Helper functions
  1074. //----------------------------------------------------------------------------
  1075. void cmExtraEclipseCDT4Generator
  1076. ::AppendStorageScanners(cmGeneratedFileStream& fout,
  1077. const cmMakefile& makefile)
  1078. {
  1079. // we need the "make" and the C (or C++) compiler which are used, Alex
  1080. std::string make = makefile.GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  1081. std::string compiler = makefile.GetSafeDefinition("CMAKE_C_COMPILER");
  1082. std::string arg1 = makefile.GetSafeDefinition("CMAKE_C_COMPILER_ARG1");
  1083. if (compiler.empty())
  1084. {
  1085. compiler = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER");
  1086. arg1 = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER_ARG1");
  1087. }
  1088. if (compiler.empty()) //Hmm, what to do now ?
  1089. {
  1090. compiler = "gcc";
  1091. }
  1092. // the following right now hardcodes gcc behaviour :-/
  1093. std::string compilerArgs =
  1094. "-E -P -v -dD ${plugin_state_location}/${specs_file}";
  1095. if (!arg1.empty())
  1096. {
  1097. arg1 += " ";
  1098. compilerArgs = arg1 + compilerArgs;
  1099. }
  1100. fout <<
  1101. "<storageModule moduleId=\"scannerConfiguration\">\n"
  1102. "<autodiscovery enabled=\"true\" problemReportingEnabled=\"true\""
  1103. " selectedProfileId="
  1104. "\"org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile\"/>\n"
  1105. ;
  1106. cmExtraEclipseCDT4Generator::AppendScannerProfile(fout,
  1107. "org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile",
  1108. true, "", true, "specsFile",
  1109. compilerArgs,
  1110. compiler, true, true);
  1111. cmExtraEclipseCDT4Generator::AppendScannerProfile(fout,
  1112. "org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile",
  1113. true, "", true, "makefileGenerator",
  1114. "-f ${project_name}_scd.mk",
  1115. make, true, true);
  1116. fout << "</storageModule>\n";
  1117. }
  1118. // The prefix is prepended before the actual name of the target. The purpose
  1119. // of that is to sort the targets in the view of Eclipse, so that at first
  1120. // the global/utility/all/clean targets appear ": ", then the executable
  1121. // targets "[exe] ", then the libraries "[lib]", then the rules for the
  1122. // object files "[obj]", then for preprocessing only "[pre] " and
  1123. // finally the assembly files "[to asm] ". Note the "to" in "to asm",
  1124. // without it, "asm" would be the first targets in the list, with the "to"
  1125. // they are the last targets, which makes more sense.
  1126. void cmExtraEclipseCDT4Generator::AppendTarget(cmGeneratedFileStream& fout,
  1127. const std::string& target,
  1128. const std::string& make,
  1129. const std::string& makeArgs,
  1130. const std::string& path,
  1131. const char* prefix,
  1132. const char* makeTarget
  1133. )
  1134. {
  1135. std::string targetXml = cmExtraEclipseCDT4Generator::EscapeForXML(target);
  1136. std::string makeTargetXml = targetXml;
  1137. if (makeTarget != NULL)
  1138. {
  1139. makeTargetXml = cmExtraEclipseCDT4Generator::EscapeForXML(makeTarget);
  1140. }
  1141. cmExtraEclipseCDT4Generator::EscapeForXML(target);
  1142. std::string pathXml = cmExtraEclipseCDT4Generator::EscapeForXML(path);
  1143. fout <<
  1144. "<target name=\"" << prefix << targetXml << "\""
  1145. " path=\"" << pathXml.c_str() << "\""
  1146. " targetID=\"org.eclipse.cdt.make.MakeTargetBuilder\">\n"
  1147. "<buildCommand>"
  1148. << cmExtraEclipseCDT4Generator::GetEclipsePath(make)
  1149. << "</buildCommand>\n"
  1150. "<buildArguments>" << makeArgs << "</buildArguments>\n"
  1151. "<buildTarget>" << makeTargetXml << "</buildTarget>\n"
  1152. "<stopOnError>true</stopOnError>\n"
  1153. "<useDefaultCommand>false</useDefaultCommand>\n"
  1154. "</target>\n"
  1155. ;
  1156. }
  1157. void cmExtraEclipseCDT4Generator
  1158. ::AppendScannerProfile(cmGeneratedFileStream& fout,
  1159. const std::string& profileID,
  1160. bool openActionEnabled,
  1161. const std::string& openActionFilePath,
  1162. bool pParserEnabled,
  1163. const std::string& scannerInfoProviderID,
  1164. const std::string& runActionArguments,
  1165. const std::string& runActionCommand,
  1166. bool runActionUseDefault,
  1167. bool sipParserEnabled)
  1168. {
  1169. fout <<
  1170. "<profile id=\"" << profileID << "\">\n"
  1171. "<buildOutputProvider>\n"
  1172. "<openAction enabled=\"" << (openActionEnabled ? "true" : "false")
  1173. << "\" filePath=\"" << openActionFilePath << "\"/>\n"
  1174. "<parser enabled=\"" << (pParserEnabled ? "true" : "false") << "\"/>\n"
  1175. "</buildOutputProvider>\n"
  1176. "<scannerInfoProvider id=\"" << scannerInfoProviderID << "\">\n"
  1177. "<runAction arguments=\"" << runActionArguments << "\""
  1178. " command=\"" << runActionCommand
  1179. << "\" useDefault=\"" << (runActionUseDefault ? "true":"false") << "\"/>\n"
  1180. "<parser enabled=\"" << (sipParserEnabled ? "true" : "false") << "\"/>\n"
  1181. "</scannerInfoProvider>\n"
  1182. "</profile>\n"
  1183. ;
  1184. }
  1185. void cmExtraEclipseCDT4Generator
  1186. ::AppendLinkedResource (cmGeneratedFileStream& fout,
  1187. const std::string& name,
  1188. const std::string& path,
  1189. LinkType linkType)
  1190. {
  1191. const char* locationTag = "location";
  1192. const char* typeTag = "2";
  1193. if (linkType == VirtualFolder) // ... and not a linked folder
  1194. {
  1195. locationTag = "locationURI";
  1196. }
  1197. if (linkType == LinkToFile)
  1198. {
  1199. typeTag = "1";
  1200. }
  1201. fout <<
  1202. "\t\t<link>\n"
  1203. "\t\t\t<name>"
  1204. << cmExtraEclipseCDT4Generator::EscapeForXML(name)
  1205. << "</name>\n"
  1206. "\t\t\t<type>" << typeTag << "</type>\n"
  1207. "\t\t\t<" << locationTag << ">"
  1208. << cmExtraEclipseCDT4Generator::EscapeForXML(path)
  1209. << "</" << locationTag << ">\n"
  1210. "\t\t</link>\n"
  1211. ;
  1212. }