cmExtraEclipseCDT4Generator.cxx 44 KB

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