cmExtraEclipseCDT4Generator.cxx 47 KB

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