cmExtraEclipseCDT4Generator.cxx 47 KB

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