cmLocalUnixMakefileGenerator2.cxx 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmLocalUnixMakefileGenerator2.h"
  14. #include "cmGeneratedFileStream.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmMakefile.h"
  17. #include "cmSourceFile.h"
  18. #include <queue>
  19. //----------------------------------------------------------------------------
  20. cmLocalUnixMakefileGenerator2::cmLocalUnixMakefileGenerator2()
  21. {
  22. }
  23. //----------------------------------------------------------------------------
  24. cmLocalUnixMakefileGenerator2::~cmLocalUnixMakefileGenerator2()
  25. {
  26. }
  27. //----------------------------------------------------------------------------
  28. void cmLocalUnixMakefileGenerator2::Generate(bool fromTheTop)
  29. {
  30. // TODO: Account for control-c during Makefile generation.
  31. // Generate old style for now.
  32. this->cmLocalUnixMakefileGenerator::Generate(fromTheTop);
  33. // Generate the rule files for each target.
  34. const cmTargets& targets = m_Makefile->GetTargets();
  35. for(cmTargets::const_iterator t = targets.begin(); t != targets.end(); ++t)
  36. {
  37. // TODO: Dispatch generation of each target type.
  38. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  39. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  40. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  41. (t->second.GetType() == cmTarget::MODULE_LIBRARY))
  42. {
  43. this->GenerateTargetRuleFile(t->second);
  44. }
  45. }
  46. // Generate the main makefile.
  47. this->GenerateMakefile();
  48. // Generate the cmake file that keeps the makefile up to date.
  49. this->GenerateCMakefile();
  50. }
  51. //----------------------------------------------------------------------------
  52. void cmLocalUnixMakefileGenerator2::GenerateMakefile()
  53. {
  54. // Open the output file.
  55. std::string makefileName = m_Makefile->GetStartOutputDirectory();
  56. makefileName += "/Makefile2";
  57. std::ofstream makefileStream(makefileName.c_str());
  58. if(!makefileStream)
  59. {
  60. cmSystemTools::Error("Error can not open for write: ",
  61. makefileName.c_str());
  62. cmSystemTools::ReportLastSystemError("");
  63. return;
  64. }
  65. // Write the do not edit header.
  66. this->WriteDisclaimer(makefileStream);
  67. // Write standard variables to the makefile.
  68. this->WriteMakeVariables(makefileStream);
  69. // Write special targets that belong at the top of the file.
  70. this->WriteSpecialTargetsTop(makefileStream);
  71. // Write the directory-level build rules.
  72. this->WriteAllRule(makefileStream);
  73. // Write include statements to get rules for each target.
  74. this->WriteTargetIncludes(makefileStream);
  75. // Write jump-and-build rules that were recorded in the map.
  76. this->WriteJumpAndBuildRules(makefileStream);
  77. // Write special targets that belong at the bottom of the file.
  78. this->WriteSpecialTargetsBottom(makefileStream);
  79. }
  80. //----------------------------------------------------------------------------
  81. void cmLocalUnixMakefileGenerator2::GenerateCMakefile()
  82. {
  83. std::string makefileName = m_Makefile->GetStartOutputDirectory();
  84. makefileName += "/Makefile2";
  85. std::string cmakefileName = makefileName;
  86. cmakefileName += ".cmake";
  87. // Open the output file.
  88. std::ofstream cmakefileStream(cmakefileName.c_str());
  89. if(!cmakefileStream)
  90. {
  91. cmSystemTools::Error("Error can not open for write: ",
  92. cmakefileName.c_str());
  93. cmSystemTools::ReportLastSystemError("");
  94. return;
  95. }
  96. // Write the do not edit header.
  97. this->WriteDisclaimer(cmakefileStream);
  98. // Get the list of files contributing to this generation step.
  99. // Sort the list and remove duplicates.
  100. std::vector<std::string> lfiles = m_Makefile->GetListFiles();
  101. std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>());
  102. std::vector<std::string>::iterator new_end = std::unique(lfiles.begin(),
  103. lfiles.end());
  104. lfiles.erase(new_end, lfiles.end());
  105. // Save the list to the cmake file.
  106. cmakefileStream
  107. << "# The corresponding makefile\n"
  108. << "# \"" << makefileName << "\"\n"
  109. << "# was generated from the following files:\n"
  110. << "SET(CMAKE_MAKEFILE_DEPENDS\n"
  111. << " \"" << m_Makefile->GetHomeOutputDirectory() << "/CMakeCache.txt\"\n";
  112. for(std::vector<std::string>::const_iterator i = lfiles.begin();
  113. i != lfiles.end(); ++i)
  114. {
  115. cmakefileStream
  116. << " \"" << i->c_str() << "\"\n";
  117. }
  118. cmakefileStream
  119. << " )\n\n";
  120. // Set the corresponding makefile in the cmake file.
  121. cmakefileStream
  122. << "# The corresponding makefile is:\n"
  123. << "SET(CMAKE_MAKEFILE_OUTPUTS\n"
  124. << " \"" << makefileName.c_str() << "\"\n"
  125. << " )\n";
  126. }
  127. //----------------------------------------------------------------------------
  128. void
  129. cmLocalUnixMakefileGenerator2
  130. ::GenerateTargetRuleFile(const cmTarget& target)
  131. {
  132. // Create a directory for this target.
  133. std::string dir = this->GetTargetDirectory(target);
  134. cmSystemTools::MakeDirectory(this->ConvertToFullPath(dir).c_str());
  135. // First generate the object rule files. Save a list of all object
  136. // files for this target.
  137. std::vector<std::string> objects;
  138. const std::vector<cmSourceFile*>& sources = target.GetSourceFiles();
  139. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  140. source != sources.end(); ++source)
  141. {
  142. if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  143. !(*source)->GetCustomCommand() &&
  144. !m_GlobalGenerator->IgnoreFile((*source)->GetSourceExtension().c_str()))
  145. {
  146. // Generate this object file's rule file.
  147. this->GenerateObjectRuleFile(target, *(*source));
  148. // Save the object file name.
  149. objects.push_back(this->GetObjectFileName(target, *(*source)));
  150. }
  151. }
  152. // If there is no dependencies file, create an empty one.
  153. std::string depFileName = dir;
  154. depFileName += "/";
  155. depFileName += target.GetName();
  156. depFileName += ".depends.make";
  157. std::string depFileNameFull = this->ConvertToFullPath(depFileName);
  158. if(!cmSystemTools::FileExists(depFileNameFull.c_str()))
  159. {
  160. std::ofstream depFileStream(depFileNameFull.c_str());
  161. this->WriteDisclaimer(depFileStream);
  162. depFileStream
  163. << "# Empty dependencies file for target " << target.GetName() << ".\n"
  164. << "# This may be replaced when dependencies are built.\n";
  165. }
  166. // Open the rule file. This should be copy-if-different because the
  167. // rules may depend on this file itself.
  168. std::string ruleFileName = dir;
  169. ruleFileName += "/";
  170. ruleFileName += target.GetName();
  171. ruleFileName += ".make";
  172. std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
  173. cmGeneratedFileStream ruleFile(ruleFileNameFull.c_str());
  174. std::ostream& ruleFileStream = ruleFile.GetStream();
  175. if(!ruleFileStream)
  176. {
  177. // TODO: Produce error message that accounts for generated stream
  178. // .tmp.
  179. return;
  180. }
  181. this->WriteDisclaimer(ruleFileStream);
  182. ruleFileStream
  183. << "# Rule file for target " << target.GetName() << ".\n\n";
  184. // Include the dependencies for the target.
  185. ruleFileStream
  186. << "# Include any dependencies generated for this rule.\n"
  187. << m_IncludeDirective << " "
  188. << this->ConvertToOutputForExisting(depFileName.c_str()).c_str()
  189. << "\n\n";
  190. // Include the rule file for each object.
  191. if(!objects.empty())
  192. {
  193. ruleFileStream
  194. << "# Include make rules for object files.\n";
  195. for(std::vector<std::string>::const_iterator obj = objects.begin();
  196. obj != objects.end(); ++obj)
  197. {
  198. std::string objRuleFileName = *obj;
  199. objRuleFileName += ".make";
  200. ruleFileStream
  201. << m_IncludeDirective << " "
  202. << this->ConvertToOutputForExisting(objRuleFileName.c_str()).c_str()
  203. << "\n";
  204. }
  205. ruleFileStream
  206. << "\n";
  207. }
  208. // Write the dependency generation rule.
  209. {
  210. std::vector<std::string> depends;
  211. std::vector<std::string> commands;
  212. std::string depEcho = "Building dependencies for ";
  213. depEcho += target.GetName();
  214. depEcho += "...";
  215. std::string depTarget = dir;
  216. depTarget += "/";
  217. depTarget += target.GetName();
  218. depTarget += ".depends";
  219. for(std::vector<std::string>::const_iterator obj = objects.begin();
  220. obj != objects.end(); ++obj)
  221. {
  222. depends.push_back((*obj)+".depends");
  223. }
  224. depends.push_back(ruleFileName);
  225. this->WriteMakeRule(ruleFileStream, 0, depEcho.c_str(),
  226. depTarget.c_str(), depends, commands);
  227. }
  228. // Write the build rule.
  229. switch(target.GetType())
  230. {
  231. case cmTarget::STATIC_LIBRARY:
  232. this->WriteStaticLibraryRule(ruleFileStream, ruleFileName.c_str(),
  233. target, objects);
  234. break;
  235. case cmTarget::SHARED_LIBRARY:
  236. this->WriteSharedLibraryRule(ruleFileStream, ruleFileName.c_str(),
  237. target, objects);
  238. break;
  239. case cmTarget::MODULE_LIBRARY:
  240. this->WriteModuleLibraryRule(ruleFileStream, ruleFileName.c_str(),
  241. target, objects);
  242. break;
  243. case cmTarget::EXECUTABLE:
  244. this->WriteExecutableRule(ruleFileStream, ruleFileName.c_str(),
  245. target, objects);
  246. break;
  247. default:
  248. break;
  249. }
  250. }
  251. //----------------------------------------------------------------------------
  252. void
  253. cmLocalUnixMakefileGenerator2
  254. ::GenerateObjectRuleFile(const cmTarget& target, const cmSourceFile& source)
  255. {
  256. // Identify the language of the source file.
  257. const char* lang = this->GetSourceFileLanguage(source);
  258. if(!lang)
  259. {
  260. // If language is not known, this is an error.
  261. cmSystemTools::Error("Source file \"", source.GetFullPath().c_str(),
  262. "\" has unknown type.");
  263. return;
  264. }
  265. // Get the full path name of the object file.
  266. std::string obj = this->GetObjectFileName(target, source);
  267. // Create the directory containing the object file. This may be a
  268. // subdirectory under the target's directory.
  269. std::string dir = cmSystemTools::GetFilenamePath(obj.c_str());
  270. cmSystemTools::MakeDirectory(this->ConvertToFullPath(dir).c_str());
  271. // If there is no dependencies file, create an empty one.
  272. std::string depFileName = obj;
  273. depFileName += ".depends.make";
  274. std::string depFileNameFull = this->ConvertToFullPath(depFileName);
  275. if(!cmSystemTools::FileExists(depFileNameFull.c_str()))
  276. {
  277. std::ofstream depFileStream(depFileNameFull.c_str());
  278. this->WriteDisclaimer(depFileStream);
  279. depFileStream
  280. << "# Empty dependencies file for object file " << obj.c_str() << ".\n"
  281. << "# This may be replaced when dependencies are built.\n";
  282. }
  283. // Open the rule file for writing. This should be copy-if-different
  284. // because the rules may depend on this file itself.
  285. std::string ruleFileName = obj;
  286. ruleFileName += ".make";
  287. std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
  288. cmGeneratedFileStream ruleFile(ruleFileNameFull.c_str());
  289. std::ostream& ruleFileStream = ruleFile.GetStream();
  290. if(!ruleFileStream)
  291. {
  292. // TODO: Produce error message that accounts for generated stream
  293. // .tmp.
  294. return;
  295. }
  296. this->WriteDisclaimer(ruleFileStream);
  297. ruleFileStream
  298. << "# Rule file for object file " << obj.c_str() << ".\n\n";
  299. // Include the dependencies for the target.
  300. ruleFileStream
  301. << "# Include any dependencies generated for this rule.\n"
  302. << m_IncludeDirective << " "
  303. << this->ConvertToOutputForExisting(depFileName.c_str()).c_str()
  304. << "\n\n";
  305. // Create the list of dependencies known at cmake time. These are
  306. // shared between the object file and dependency scanning rule.
  307. std::vector<std::string> depends;
  308. depends.push_back(source.GetFullPath());
  309. if(const char* objectDeps = source.GetProperty("OBJECT_DEPENDS"))
  310. {
  311. std::vector<std::string> deps;
  312. cmSystemTools::ExpandListArgument(objectDeps, deps);
  313. for(std::vector<std::string>::iterator i = deps.begin();
  314. i != deps.end(); ++i)
  315. {
  316. depends.push_back(this->ConvertToRelativeOutputPath(i->c_str()));
  317. }
  318. }
  319. depends.push_back(ruleFileName);
  320. // Write the dependency generation rule.
  321. std::string depTarget = obj;
  322. depTarget += ".depends";
  323. {
  324. std::string depEcho = "Scanning ";
  325. depEcho += lang;
  326. depEcho += " dependencies of ";
  327. depEcho += obj;
  328. depEcho += "...";
  329. // Add a command to call CMake to scan dependencies. CMake will
  330. // touch the corresponding depends file after scanning dependencies.
  331. cmOStringStream depCmd;
  332. // TODO: Account for source file properties and directory-level
  333. // definitions when scanning for dependencies.
  334. depCmd << "$(CMAKE_COMMAND) -E cmake_depends " << lang << " "
  335. << this->ConvertToRelativeOutputPath(obj.c_str()) << " "
  336. << this->ConvertToRelativeOutputPath(source.GetFullPath().c_str());
  337. std::vector<std::string> includeDirs;
  338. this->GetIncludeDirectories(includeDirs);
  339. for(std::vector<std::string>::iterator i = includeDirs.begin();
  340. i != includeDirs.end(); ++i)
  341. {
  342. depCmd << " -I" << this->ConvertToRelativeOutputPath(i->c_str());
  343. }
  344. std::vector<std::string> commands;
  345. commands.push_back(depCmd.str());
  346. // Write the rule.
  347. this->WriteMakeRule(ruleFileStream, 0, depEcho.c_str(),
  348. depTarget.c_str(), depends, commands);
  349. }
  350. // Write the build rule.
  351. {
  352. // Build the set of compiler flags.
  353. std::string flags;
  354. // Add the export symbol definition for shared library objects.
  355. bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
  356. (target.GetType() == cmTarget::MODULE_LIBRARY));
  357. if(shared)
  358. {
  359. flags += "-D";
  360. if(const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
  361. {
  362. flags += custom_export_name;
  363. }
  364. else
  365. {
  366. std::string in = target.GetName();
  367. in += "_EXPORTS";
  368. flags += cmSystemTools::MakeCindentifier(in.c_str());
  369. }
  370. }
  371. // Add flags from source file properties.
  372. this->AppendFlags(flags, source.GetProperty("COMPILE_FLAGS"));
  373. // Add language-specific flags.
  374. this->AddLanguageFlags(flags, lang);
  375. // Add shared-library flags if needed.
  376. this->AddSharedFlags(flags, lang, shared);
  377. // Add include directory flags.
  378. this->AppendFlags(flags, this->GetIncludeFlags(lang));
  379. // Get the output paths for source and object files.
  380. std::string sourceFile =
  381. this->ConvertToRelativeOutputPath(source.GetFullPath().c_str());
  382. std::string objectFile =
  383. this->ConvertToRelativeOutputPath(obj.c_str());
  384. // Construct the compile rules.
  385. std::vector<std::string> commands;
  386. std::string compileRuleVar = "CMAKE_";
  387. compileRuleVar += lang;
  388. compileRuleVar += "_COMPILE_OBJECT";
  389. std::string compileRule =
  390. m_Makefile->GetRequiredDefinition(compileRuleVar.c_str());
  391. cmSystemTools::ExpandListArgument(compileRule, commands);
  392. // Expand placeholders in the commands.
  393. for(std::vector<std::string>::iterator i = commands.begin();
  394. i != commands.end(); ++i)
  395. {
  396. this->ExpandRuleVariables(*i,
  397. lang,
  398. 0, // no objects
  399. 0, // no target
  400. 0, // no link libs
  401. sourceFile.c_str(),
  402. objectFile.c_str(),
  403. flags.c_str());
  404. }
  405. // Write the rule.
  406. std::string buildEcho = "Building ";
  407. buildEcho += lang;
  408. buildEcho += " object ";
  409. buildEcho += obj;
  410. buildEcho += "...";
  411. this->WriteMakeRule(ruleFileStream, 0, buildEcho.c_str(),
  412. obj.c_str(), depends, commands);
  413. }
  414. }
  415. //----------------------------------------------------------------------------
  416. void
  417. cmLocalUnixMakefileGenerator2
  418. ::WriteMakeRule(std::ostream& os,
  419. const char* comment,
  420. const char* preEcho,
  421. const char* target,
  422. const std::vector<std::string>& depends,
  423. const std::vector<std::string>& commands,
  424. const char* postEcho)
  425. {
  426. // Make sure there is a target.
  427. if(!target || !*target)
  428. {
  429. cmSystemTools::Error("No target for WriteMakeRule!");
  430. return;
  431. }
  432. std::string replace;
  433. // Write the comment describing the rule in the makefile.
  434. if(comment)
  435. {
  436. replace = comment;
  437. m_Makefile->ExpandVariablesInString(replace);
  438. std::string::size_type lpos = 0;
  439. std::string::size_type rpos;
  440. while((rpos = replace.find(lpos, '\n')) != std::string::npos)
  441. {
  442. os << "# " << replace.substr(lpos, rpos-lpos);
  443. lpos = rpos+1;
  444. }
  445. os << "# " << replace.substr(lpos) << "\n";
  446. }
  447. // Construct the left hand side of the rule.
  448. replace = target;
  449. m_Makefile->ExpandVariablesInString(replace);
  450. std::string tgt = this->ConvertToRelativeOutputPath(replace.c_str());
  451. tgt = this->ConvertToMakeTarget(tgt.c_str());
  452. const char* space = "";
  453. if(tgt.size() == 1)
  454. {
  455. // Add a space before the ":" to avoid drive letter confusion on
  456. // Windows.
  457. space = " ";
  458. }
  459. // Write the rule.
  460. if(depends.empty())
  461. {
  462. // No dependencies. The commands will always run.
  463. os << tgt.c_str() << space << ":\n";
  464. }
  465. else
  466. {
  467. // Split dependencies into multiple rule lines. This allows for
  468. // very long dependency lists even on older make implementations.
  469. for(std::vector<std::string>::const_iterator dep = depends.begin();
  470. dep != depends.end(); ++dep)
  471. {
  472. replace = *dep;
  473. m_Makefile->ExpandVariablesInString(replace);
  474. replace = this->ConvertToMakeTarget(replace.c_str());
  475. os << tgt.c_str() << space << ": " << replace.c_str() << "\n";
  476. }
  477. }
  478. // Write the list of commands.
  479. bool first = true;
  480. for(std::vector<std::string>::const_iterator i = commands.begin();
  481. i != commands.end(); ++i)
  482. {
  483. replace = *i;
  484. m_Makefile->ExpandVariablesInString(replace);
  485. if(first && preEcho)
  486. {
  487. this->OutputEcho(os, preEcho);
  488. }
  489. os << "\t" << replace.c_str() << "\n";
  490. first = false;
  491. }
  492. if(postEcho)
  493. {
  494. this->OutputEcho(os, postEcho);
  495. }
  496. os << "\n";
  497. }
  498. //----------------------------------------------------------------------------
  499. void cmLocalUnixMakefileGenerator2::WriteDivider(std::ostream& os)
  500. {
  501. os
  502. << "#======================================"
  503. << "=======================================\n";
  504. }
  505. //----------------------------------------------------------------------------
  506. void cmLocalUnixMakefileGenerator2::WriteDisclaimer(std::ostream& os)
  507. {
  508. os
  509. << "# CMAKE generated file: DO NOT EDIT!\n"
  510. << "# Generated by \"" << m_GlobalGenerator->GetName() << "\""
  511. << " Generator, CMake Version "
  512. << cmMakefile::GetMajorVersion() << "."
  513. << cmMakefile::GetMinorVersion() << "\n\n";
  514. }
  515. //----------------------------------------------------------------------------
  516. void
  517. cmLocalUnixMakefileGenerator2
  518. ::WriteMakeVariables(std::ostream& makefileStream)
  519. {
  520. this->WriteDivider(makefileStream);
  521. makefileStream
  522. << "# Set environment variables for the build.\n"
  523. << "\n";
  524. if(m_WindowsShell)
  525. {
  526. makefileStream
  527. << "!IF \"$(OS)\" == \"Windows_NT\"\n"
  528. << "NULL=\n"
  529. << "!ELSE\n"
  530. << "NULL=nul\n"
  531. << "!ENDIF\n";
  532. }
  533. else
  534. {
  535. makefileStream
  536. << "# The shell in which to execute make rules.\n"
  537. << "SHELL = /bin/sh\n"
  538. << "\n";
  539. }
  540. std::string cmakecommand =
  541. this->ConvertToOutputForExisting(
  542. m_Makefile->GetRequiredDefinition("CMAKE_COMMAND"));
  543. makefileStream
  544. << "# The CMake executable.\n"
  545. << "CMAKE_COMMAND = " << cmakecommand.c_str() << "\n"
  546. << "\n";
  547. makefileStream
  548. << "# The command to remove a file.\n"
  549. << "RM = " << cmakecommand.c_str() << " -E remove -f\n"
  550. << "\n";
  551. if(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  552. {
  553. makefileStream
  554. << "# The program to use to edit the cache.\n"
  555. << "CMAKE_EDIT_COMMAND = "
  556. << (this->ConvertToOutputForExisting(
  557. m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))) << "\n"
  558. << "\n";
  559. }
  560. makefileStream
  561. << "# The source directory corresponding to this makefile.\n"
  562. << "CMAKE_CURRENT_SOURCE = "
  563. << this->ConvertToRelativeOutputPath(m_Makefile->GetStartDirectory())
  564. << "\n"
  565. << "\n";
  566. makefileStream
  567. << "# The build directory corresponding to this makefile.\n"
  568. << "CMAKE_CURRENT_BINARY = "
  569. << this->ConvertToRelativeOutputPath(m_Makefile->GetStartOutputDirectory())
  570. << "\n"
  571. << "\n";
  572. makefileStream
  573. << "# The top-level source directory on which CMake was run.\n"
  574. << "CMAKE_SOURCE_DIR = "
  575. << this->ConvertToRelativeOutputPath(m_Makefile->GetHomeDirectory())
  576. << "\n"
  577. << "\n";
  578. makefileStream
  579. << "# The top-level build directory on which CMake was run.\n"
  580. << "CMAKE_BINARY_DIR = "
  581. << this->ConvertToRelativeOutputPath(m_Makefile->GetHomeOutputDirectory())
  582. << "\n"
  583. << "\n";
  584. }
  585. //----------------------------------------------------------------------------
  586. void
  587. cmLocalUnixMakefileGenerator2
  588. ::WriteSpecialTargetsTop(std::ostream& makefileStream)
  589. {
  590. this->WriteDivider(makefileStream);
  591. makefileStream
  592. << "# Special targets provided by cmake.\n"
  593. << "\n";
  594. // Build command to run CMake to check if anything needs regenerating.
  595. std::string cmakefileName = m_Makefile->GetStartOutputDirectory();
  596. cmakefileName += "/Makefile2.cmake";
  597. std::string runRule =
  598. "@$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
  599. runRule += " --check-rerun ";
  600. runRule += this->ConvertToRelativeOutputPath(cmakefileName.c_str());
  601. // Write the main entry point target. This must be the VERY first
  602. // target so that make with no arguments will run it.
  603. {
  604. std::vector<std::string> depends;
  605. std::vector<std::string> commands;
  606. // Check the build system in this directory.
  607. depends.push_back("cmake_check_rerun");
  608. // Recursively build dependencies.
  609. commands.push_back(this->GetRecursiveMakeCall("all.depends"));
  610. // Recursively build targets.
  611. commands.push_back(this->GetRecursiveMakeCall("all.build"));
  612. // Write the rule.
  613. std::string preEcho = "Entering directory ";
  614. preEcho += m_Makefile->GetStartOutputDirectory();
  615. std::string postEcho = "Finished directory ";
  616. postEcho += m_Makefile->GetStartOutputDirectory();
  617. this->WriteMakeRule(makefileStream,
  618. "Default target executed when no arguments are "
  619. "given to make.",
  620. preEcho.c_str(),
  621. "all",
  622. depends,
  623. commands,
  624. postEcho.c_str());
  625. }
  626. // Write special "cmake_check_rerun" target to run cmake with the
  627. // --check-rerun flag.
  628. {
  629. std::vector<std::string> no_depends;
  630. std::vector<std::string> commands;
  631. commands.push_back(runRule);
  632. this->WriteMakeRule(makefileStream,
  633. "Special rule to run CMake to check the build system "
  634. "integrity.",
  635. "Checking build system integrity...",
  636. "cmake_check_rerun",
  637. no_depends,
  638. commands);
  639. }
  640. // Write special "rebuild_cache" target to re-run cmake.
  641. {
  642. std::vector<std::string> no_depends;
  643. std::vector<std::string> commands;
  644. commands.push_back(
  645. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  646. this->WriteMakeRule(makefileStream,
  647. "Special rule to re-run CMake using make.",
  648. "Running CMake to regenerate build system...",
  649. "rebuild_cache",
  650. no_depends,
  651. commands);
  652. }
  653. // Use CMAKE_EDIT_COMMAND for the edit_cache rule if it is defined.
  654. // Otherwise default to the interactive command-line interface.
  655. if(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  656. {
  657. std::vector<std::string> no_depends;
  658. std::vector<std::string> commands;
  659. commands.push_back(
  660. "$(CMAKE_EDIT_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  661. this->WriteMakeRule(makefileStream,
  662. "Special rule to re-run CMake cache editor using make.",
  663. "Running CMake cache editor...",
  664. "edit_cache",
  665. no_depends,
  666. commands);
  667. }
  668. else
  669. {
  670. std::vector<std::string> no_depends;
  671. std::vector<std::string> commands;
  672. commands.push_back(
  673. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -i");
  674. this->WriteMakeRule(makefileStream,
  675. "Special rule to re-run CMake cache editor using make.",
  676. "Running interactive CMake command-line interface...",
  677. "edit_cache",
  678. no_depends,
  679. commands);
  680. }
  681. }
  682. //----------------------------------------------------------------------------
  683. void
  684. cmLocalUnixMakefileGenerator2
  685. ::WriteSpecialTargetsBottom(std::ostream& makefileStream)
  686. {
  687. this->WriteDivider(makefileStream);
  688. makefileStream
  689. << "# Special targets to cleanup operation of make.\n"
  690. << "\n";
  691. std::vector<std::string> no_commands;
  692. // Write special target to silence make output. This must be after
  693. // the default target in case VERBOSE is set (which changes the name).
  694. if(!m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  695. {
  696. std::vector<std::string> no_depends;
  697. this->WriteMakeRule(makefileStream,
  698. "Suppress display of executed commands.",
  699. 0,
  700. "$(VERBOSE).SILENT",
  701. no_depends,
  702. no_commands);
  703. }
  704. // Special target to cleanup operation of make tool.
  705. std::vector<std::string> depends;
  706. depends.push_back(".hpux_make_must_have_this_dependency_here");
  707. this->WriteMakeRule(makefileStream,
  708. "Disable some common implicit rules to speed things up.",
  709. 0,
  710. ".SUFFIXES",
  711. depends,
  712. no_commands);
  713. }
  714. //----------------------------------------------------------------------------
  715. void
  716. cmLocalUnixMakefileGenerator2
  717. ::WriteAllRule(std::ostream& makefileStream)
  718. {
  719. // Write section header.
  720. this->WriteDivider(makefileStream);
  721. makefileStream
  722. << "# Main rules for this directory.\n"
  723. << "\n";
  724. const cmTargets& targets = m_Makefile->GetTargets();
  725. // Output top level dependency rule.
  726. {
  727. std::vector<std::string> depends;
  728. std::vector<std::string> commands;
  729. for(cmTargets::const_iterator t = targets.begin(); t != targets.end(); ++t)
  730. {
  731. // TODO: Dispatch generation of each target type.
  732. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  733. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  734. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  735. (t->second.GetType() == cmTarget::MODULE_LIBRARY))
  736. {
  737. if(t->second.IsInAll())
  738. {
  739. std::string dep = this->GetTargetDirectory(t->second);
  740. dep += "/";
  741. dep += t->first;
  742. dep += ".depends";
  743. depends.push_back(dep);
  744. }
  745. }
  746. }
  747. this->WriteMakeRule(makefileStream,
  748. "Main dependencies target for this directory.",
  749. 0,
  750. "all.depends",
  751. depends,
  752. commands);
  753. }
  754. // Output top level build rule.
  755. {
  756. std::vector<std::string> depends;
  757. std::vector<std::string> commands;
  758. for(cmTargets::const_iterator t = targets.begin(); t != targets.end(); ++t)
  759. {
  760. // TODO: Dispatch generation of each target type.
  761. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  762. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  763. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  764. (t->second.GetType() == cmTarget::MODULE_LIBRARY))
  765. {
  766. if(t->second.IsInAll())
  767. {
  768. depends.push_back(t->first+".requires");
  769. }
  770. }
  771. }
  772. this->WriteMakeRule(makefileStream,
  773. "Main build target for this directory.",
  774. 0,
  775. "all.build",
  776. depends,
  777. commands);
  778. }
  779. }
  780. //----------------------------------------------------------------------------
  781. void
  782. cmLocalUnixMakefileGenerator2
  783. ::WriteRequiresRule(std::ostream& ruleFileStream, const cmTarget& target,
  784. const char* targetFullPath)
  785. {
  786. std::vector<std::string> depends;
  787. std::vector<std::string> no_commands;
  788. std::string reqComment = "Requirements for target ";
  789. reqComment += target.GetName();
  790. std::string reqTarget = target.GetName();
  791. reqTarget += ".requires";
  792. depends.push_back(targetFullPath);
  793. this->WriteMakeRule(ruleFileStream, reqComment.c_str(), 0,
  794. reqTarget.c_str(), depends, no_commands);
  795. }
  796. //----------------------------------------------------------------------------
  797. void
  798. cmLocalUnixMakefileGenerator2
  799. ::WriteTargetIncludes(std::ostream& makefileStream)
  800. {
  801. bool first = true;
  802. const cmTargets& targets = m_Makefile->GetTargets();
  803. for(cmTargets::const_iterator t = targets.begin(); t != targets.end(); ++t)
  804. {
  805. // TODO: Handle the rest of the target types.
  806. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  807. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  808. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  809. (t->second.GetType() == cmTarget::MODULE_LIBRARY))
  810. {
  811. // Write the header for this section.
  812. if(first)
  813. {
  814. this->WriteDivider(makefileStream);
  815. makefileStream
  816. << "# Include rule files for each target in this directory.\n"
  817. << "\n";
  818. first = false;
  819. }
  820. // Construct the rule file name for this target.
  821. std::string ruleFileName = this->GetTargetDirectory(t->second);
  822. ruleFileName += "/";
  823. ruleFileName += t->first;
  824. ruleFileName += ".make";
  825. makefileStream
  826. << m_IncludeDirective << " "
  827. << this->ConvertToOutputForExisting(ruleFileName.c_str()).c_str()
  828. << "\n";
  829. }
  830. }
  831. if(!first)
  832. {
  833. makefileStream << "\n";
  834. }
  835. }
  836. //----------------------------------------------------------------------------
  837. void
  838. cmLocalUnixMakefileGenerator2
  839. ::WriteExecutableRule(std::ostream& ruleFileStream,
  840. const char* ruleFileName,
  841. const cmTarget& target,
  842. std::vector<std::string>& objects)
  843. {
  844. std::vector<std::string> commands;
  845. // Build list of dependencies. TODO: depend on other targets.
  846. std::vector<std::string> depends;
  847. for(std::vector<std::string>::const_iterator obj = objects.begin();
  848. obj != objects.end(); ++obj)
  849. {
  850. depends.push_back(*obj);
  851. }
  852. // Add dependencies on libraries that will be linked.
  853. std::set<cmStdString> emitted;
  854. emitted.insert(target.GetName());
  855. const cmTarget::LinkLibraries& tlibs = target.GetLinkLibraries();
  856. for(cmTarget::LinkLibraries::const_iterator lib = tlibs.begin();
  857. lib != tlibs.end(); ++lib)
  858. {
  859. // Don't emit the same library twice for this target.
  860. if(emitted.insert(lib->first).second)
  861. {
  862. // Add this dependency.
  863. this->AppendLibDepend(depends, lib->first.c_str());
  864. }
  865. }
  866. depends.push_back(ruleFileName);
  867. // Construct the full path to the executable that will be generated.
  868. std::string targetFullPath = m_ExecutableOutputPath;
  869. if(targetFullPath.length() == 0)
  870. {
  871. targetFullPath = m_Makefile->GetStartOutputDirectory();
  872. if(targetFullPath.size() && targetFullPath[targetFullPath.size()-1] != '/')
  873. {
  874. targetFullPath += "/";
  875. }
  876. }
  877. #ifdef __APPLE__
  878. if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
  879. {
  880. // Make bundle directories
  881. targetFullPath += target.GetName();
  882. targetFullPath += ".app/Contents/MacOS/";
  883. }
  884. #endif
  885. targetFullPath += target.GetName();
  886. targetFullPath += cmSystemTools::GetExecutableExtension();
  887. targetFullPath = this->ConvertToRelativeOutputPath(targetFullPath.c_str());
  888. // Get the language to use for linking this executable.
  889. const char* linkLanguage =
  890. target.GetLinkerLanguage(this->GetGlobalGenerator());
  891. // Build a list of compiler flags and linker flags.
  892. std::string flags;
  893. std::string linkFlags;
  894. // Add flags to create an executable.
  895. this->AddConfigVariableFlags(linkFlags, "CMAKE_EXE_LINKER_FLAGS");
  896. if(target.GetPropertyAsBool("WIN32_EXECUTABLE"))
  897. {
  898. this->AppendFlags(linkFlags,
  899. m_Makefile->GetDefinition("CMAKE_CREATE_WIN32_EXE"));
  900. }
  901. else
  902. {
  903. this->AppendFlags(linkFlags,
  904. m_Makefile->GetDefinition("CMAKE_CREATE_CONSOLE_EXE"));
  905. }
  906. // Add language-specific flags.
  907. this->AddLanguageFlags(flags, linkLanguage);
  908. // Add flags to deal with shared libraries. Any library being
  909. // linked in might be shared, so always use shared flags for an
  910. // executable.
  911. this->AddSharedFlags(flags, linkLanguage, true);
  912. // Add target-specific linker flags.
  913. this->AppendFlags(linkFlags, target.GetProperty("LINK_FLAGS"));
  914. // TODO: Pre-build and pre-link rules.
  915. // Construct the main link rule.
  916. std::string linkRuleVar = "CMAKE_";
  917. linkRuleVar += linkLanguage;
  918. linkRuleVar += "_LINK_EXECUTABLE";
  919. std::string linkRule = m_Makefile->GetRequiredDefinition(linkRuleVar.c_str());
  920. cmSystemTools::ExpandListArgument(linkRule, commands);
  921. // TODO: Post-build rules.
  922. // Collect up flags to link in needed libraries.
  923. cmOStringStream linklibs;
  924. this->OutputLinkLibraries(linklibs, 0, target);
  925. // Construct object file lists that may be needed to expand the
  926. // rule. TODO: Store these in make variables with line continuation
  927. // to avoid excessively long lines.
  928. std::string objs;
  929. std::string objsQuoted;
  930. const char* space = "";
  931. for(std::vector<std::string>::iterator i = objects.begin();
  932. i != objects.end(); ++i)
  933. {
  934. objs += space;
  935. objs += *i;
  936. objsQuoted += space;
  937. objsQuoted += "\"";
  938. objsQuoted += *i;
  939. objsQuoted += "\"";
  940. space = " ";
  941. }
  942. // Expand placeholders in the commands.
  943. for(std::vector<std::string>::iterator i = commands.begin();
  944. i != commands.end(); ++i)
  945. {
  946. this->ExpandRuleVariables(*i,
  947. linkLanguage,
  948. objs.c_str(),
  949. targetFullPath.c_str(),
  950. linklibs.str().c_str(),
  951. 0,
  952. 0,
  953. flags.c_str(),
  954. 0,
  955. 0,
  956. 0,
  957. linkFlags.c_str());
  958. }
  959. // Write the build rule.
  960. std::string buildEcho = "Linking ";
  961. buildEcho += linkLanguage;
  962. buildEcho += " executable ";
  963. buildEcho += targetFullPath;
  964. buildEcho += "...";
  965. this->WriteMakeRule(ruleFileStream, 0, buildEcho.c_str(),
  966. targetFullPath.c_str(), depends, commands);
  967. // TODO: Add "local" target and canonical target name as rules.
  968. // Write driver rule for this target.
  969. this->WriteRequiresRule(ruleFileStream, target, targetFullPath.c_str());
  970. }
  971. //----------------------------------------------------------------------------
  972. void
  973. cmLocalUnixMakefileGenerator2
  974. ::WriteStaticLibraryRule(std::ostream& ruleFileStream,
  975. const char* ruleFileName,
  976. const cmTarget& target,
  977. std::vector<std::string>& objects)
  978. {
  979. const char* linkLanguage =
  980. target.GetLinkerLanguage(this->GetGlobalGenerator());
  981. std::string linkRuleVar = "CMAKE_";
  982. linkRuleVar += linkLanguage;
  983. linkRuleVar += "_CREATE_STATIC_LIBRARY";
  984. std::string extraFlags;
  985. this->AppendFlags(extraFlags, target.GetProperty("STATIC_LIBRARY_FLAGS"));
  986. this->WriteLibraryRule(ruleFileStream, ruleFileName, target, objects,
  987. linkRuleVar.c_str(), extraFlags.c_str());
  988. }
  989. //----------------------------------------------------------------------------
  990. void
  991. cmLocalUnixMakefileGenerator2
  992. ::WriteSharedLibraryRule(std::ostream& ruleFileStream,
  993. const char* ruleFileName,
  994. const cmTarget& target,
  995. std::vector<std::string>& objects)
  996. {
  997. const char* linkLanguage =
  998. target.GetLinkerLanguage(this->GetGlobalGenerator());
  999. std::string linkRuleVar = "CMAKE_";
  1000. linkRuleVar += linkLanguage;
  1001. linkRuleVar += "_CREATE_SHARED_LIBRARY";
  1002. std::string extraFlags;
  1003. this->AppendFlags(extraFlags, target.GetProperty("LINK_FLAGS"));
  1004. this->AddConfigVariableFlags(extraFlags, "CMAKE_SHARED_LINKER_FLAGS");
  1005. if(m_Makefile->IsOn("WIN32") && !(m_Makefile->IsOn("CYGWIN") || m_Makefile->IsOn("MINGW")))
  1006. {
  1007. const std::vector<cmSourceFile*>& sources = target.GetSourceFiles();
  1008. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1009. i != sources.end(); ++i)
  1010. {
  1011. if((*i)->GetSourceExtension() == "def")
  1012. {
  1013. extraFlags += " ";
  1014. extraFlags += m_Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  1015. extraFlags += this->ConvertToRelativeOutputPath((*i)->GetFullPath().c_str());
  1016. }
  1017. }
  1018. }
  1019. this->WriteLibraryRule(ruleFileStream, ruleFileName, target, objects,
  1020. linkRuleVar.c_str(), extraFlags.c_str());
  1021. }
  1022. //----------------------------------------------------------------------------
  1023. void
  1024. cmLocalUnixMakefileGenerator2
  1025. ::WriteModuleLibraryRule(std::ostream& ruleFileStream,
  1026. const char* ruleFileName,
  1027. const cmTarget& target,
  1028. std::vector<std::string>& objects)
  1029. {
  1030. const char* linkLanguage =
  1031. target.GetLinkerLanguage(this->GetGlobalGenerator());
  1032. std::string linkRuleVar = "CMAKE_";
  1033. linkRuleVar += linkLanguage;
  1034. linkRuleVar += "_CREATE_SHARED_MODULE";
  1035. std::string extraFlags;
  1036. this->AppendFlags(extraFlags, target.GetProperty("LINK_FLAGS"));
  1037. this->AddConfigVariableFlags(extraFlags, "CMAKE_MODULE_LINKER_FLAGS");
  1038. // TODO: Should .def files be supported here also?
  1039. this->WriteLibraryRule(ruleFileStream, ruleFileName, target, objects,
  1040. linkRuleVar.c_str(), extraFlags.c_str());
  1041. }
  1042. //----------------------------------------------------------------------------
  1043. void
  1044. cmLocalUnixMakefileGenerator2
  1045. ::WriteLibraryRule(std::ostream& ruleFileStream,
  1046. const char* ruleFileName,
  1047. const cmTarget& target,
  1048. std::vector<std::string>& objects,
  1049. const char* linkRuleVar,
  1050. const char* extraFlags)
  1051. {
  1052. std::vector<std::string> commands;
  1053. // Build list of dependencies. TODO: depend on other targets.
  1054. std::vector<std::string> depends;
  1055. for(std::vector<std::string>::const_iterator obj = objects.begin();
  1056. obj != objects.end(); ++obj)
  1057. {
  1058. depends.push_back(*obj);
  1059. }
  1060. depends.push_back(ruleFileName);
  1061. const char* linkLanguage =
  1062. target.GetLinkerLanguage(this->GetGlobalGenerator());
  1063. std::string linkFlags;
  1064. this->AppendFlags(linkFlags, extraFlags);
  1065. std::string targetName;
  1066. std::string targetNameSO;
  1067. std::string targetNameReal;
  1068. std::string targetNameBase;
  1069. this->GetLibraryNames(target.GetName(), target,
  1070. targetName, targetNameSO,
  1071. targetNameReal, targetNameBase);
  1072. std::string outpath;
  1073. std::string outdir;
  1074. if(m_UseRelativePaths)
  1075. {
  1076. outdir = this->ConvertToRelativeOutputPath(m_LibraryOutputPath.c_str());
  1077. }
  1078. else
  1079. {
  1080. outdir = m_LibraryOutputPath;
  1081. }
  1082. if(!m_WindowsShell && m_UseRelativePaths && outdir.size())
  1083. {
  1084. outpath = "\"`cd ";
  1085. }
  1086. outpath += outdir;
  1087. if(!m_WindowsShell && m_UseRelativePaths && outdir.size())
  1088. {
  1089. outpath += ";pwd`\"/";
  1090. }
  1091. if(outdir.size() == 0 && m_UseRelativePaths && !m_WindowsShell)
  1092. {
  1093. outpath = "\"`pwd`\"/";
  1094. }
  1095. // The full path versions of the names.
  1096. std::string targetFullPath = outpath + targetName;
  1097. std::string targetFullPathSO = outpath + targetNameSO;
  1098. std::string targetFullPathReal = outpath + targetNameReal;
  1099. std::string targetFullPathBase = outpath + targetNameBase;
  1100. // If not using relative paths then the output path needs to be
  1101. // converted here
  1102. if(!m_UseRelativePaths)
  1103. {
  1104. targetFullPath = this->ConvertToRelativeOutputPath(targetFullPath.c_str());
  1105. targetFullPathSO = this->ConvertToRelativeOutputPath(targetFullPathSO.c_str());
  1106. targetFullPathReal = this->ConvertToRelativeOutputPath(targetFullPathReal.c_str());
  1107. targetFullPathBase = this->ConvertToRelativeOutputPath(targetFullPathBase.c_str());
  1108. }
  1109. // Add a command to remove any existing files for this library.
  1110. std::string remove = "$(CMAKE_COMMAND) -E remove -f ";
  1111. remove += targetFullPathReal;
  1112. if(targetFullPathSO != targetFullPathReal)
  1113. {
  1114. remove += " ";
  1115. remove += targetFullPathSO;
  1116. }
  1117. if(targetFullPath != targetFullPathSO &&
  1118. targetFullPath != targetFullPathReal)
  1119. {
  1120. remove += " ";
  1121. remove += targetFullPath;
  1122. }
  1123. commands.push_back(remove);
  1124. // TODO: Pre-build and pre-link rules.
  1125. // Construct the main link rule.
  1126. std::string linkRule = m_Makefile->GetRequiredDefinition(linkRuleVar);
  1127. cmSystemTools::ExpandListArgument(linkRule, commands);
  1128. // Add a rule to create necessary symlinks for the library.
  1129. if(targetFullPath != targetFullPathReal)
  1130. {
  1131. std::string symlink = "$(CMAKE_COMMAND) -E cmake_symlink_library ";
  1132. symlink += targetFullPathReal;
  1133. symlink += " ";
  1134. symlink += targetFullPathSO;
  1135. symlink += " ";
  1136. symlink += targetFullPath;
  1137. commands.push_back(symlink);
  1138. }
  1139. // TODO: Post-build rules.
  1140. // Collect up flags to link in needed libraries.
  1141. cmOStringStream linklibs;
  1142. this->OutputLinkLibraries(linklibs, target.GetName(), target);
  1143. // Construct object file lists that may be needed to expand the
  1144. // rule. TODO: Store these in make variables with line continuation
  1145. // to avoid excessively long lines.
  1146. std::string objs;
  1147. std::string objsQuoted;
  1148. const char* space = "";
  1149. for(std::vector<std::string>::iterator i = objects.begin();
  1150. i != objects.end(); ++i)
  1151. {
  1152. objs += space;
  1153. objs += *i;
  1154. objsQuoted += space;
  1155. objsQuoted += "\"";
  1156. objsQuoted += *i;
  1157. objsQuoted += "\"";
  1158. space = " ";
  1159. }
  1160. // Expand placeholders in the commands.
  1161. for(std::vector<std::string>::iterator i = commands.begin();
  1162. i != commands.end(); ++i)
  1163. {
  1164. this->ExpandRuleVariables(*i,
  1165. linkLanguage,
  1166. objs.c_str(),
  1167. targetFullPathReal.c_str(),
  1168. linklibs.str().c_str(),
  1169. 0, 0, 0, objsQuoted.c_str(),
  1170. targetFullPathBase.c_str(),
  1171. targetNameSO.c_str(),
  1172. linkFlags.c_str());
  1173. }
  1174. // Write the build rule.
  1175. std::string buildEcho = "Linking ";
  1176. buildEcho += linkLanguage;
  1177. switch(target.GetType())
  1178. {
  1179. case cmTarget::STATIC_LIBRARY:
  1180. buildEcho += " static library "; break;
  1181. case cmTarget::SHARED_LIBRARY:
  1182. buildEcho += " shared library "; break;
  1183. case cmTarget::MODULE_LIBRARY:
  1184. buildEcho += " shared module "; break;
  1185. default:
  1186. buildEcho += " library "; break;
  1187. }
  1188. buildEcho += targetFullPath.c_str();
  1189. buildEcho += "...";
  1190. this->WriteMakeRule(ruleFileStream, 0, buildEcho.c_str(),
  1191. targetFullPath.c_str(), depends, commands);
  1192. // TODO: Add "local" target and canonical target name as rules.
  1193. // Write driver rule for this target.
  1194. this->WriteRequiresRule(ruleFileStream, target, targetFullPath.c_str());
  1195. }
  1196. //----------------------------------------------------------------------------
  1197. std::string
  1198. cmLocalUnixMakefileGenerator2
  1199. ::GetTargetDirectory(const cmTarget& target)
  1200. {
  1201. std::string dir = target.GetName();
  1202. dir += ".dir";
  1203. return dir;
  1204. }
  1205. //----------------------------------------------------------------------------
  1206. std::string
  1207. cmLocalUnixMakefileGenerator2
  1208. ::GetObjectFileName(const cmTarget& target,
  1209. const cmSourceFile& source)
  1210. {
  1211. // If the full path to the source file includes this directory,
  1212. // we want to use the relative path for the filename of the
  1213. // object file. Otherwise, we will use just the filename
  1214. // portion.
  1215. std::string objectName;
  1216. if((cmSystemTools::GetFilenamePath(
  1217. source.GetFullPath()).find(
  1218. m_Makefile->GetCurrentDirectory()) == 0)
  1219. || (cmSystemTools::GetFilenamePath(
  1220. source.GetFullPath()).find(
  1221. m_Makefile->GetStartOutputDirectory()) == 0))
  1222. {
  1223. objectName = source.GetSourceName();
  1224. }
  1225. else
  1226. {
  1227. objectName = cmSystemTools::GetFilenameName(source.GetSourceName());
  1228. }
  1229. // Append the object file extension.
  1230. objectName +=
  1231. m_GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  1232. source.GetSourceExtension().c_str());
  1233. // Convert to a safe name.
  1234. objectName = this->CreateSafeUniqueObjectFileName(objectName.c_str());
  1235. // Prepend the target directory.
  1236. std::string obj = this->GetTargetDirectory(target);
  1237. obj += "/";
  1238. obj += objectName;
  1239. return obj;
  1240. }
  1241. //----------------------------------------------------------------------------
  1242. const char*
  1243. cmLocalUnixMakefileGenerator2
  1244. ::GetSourceFileLanguage(const cmSourceFile& source)
  1245. {
  1246. // Identify the language of the source file.
  1247. return (m_GlobalGenerator
  1248. ->GetLanguageFromExtension(source.GetSourceExtension().c_str()));
  1249. }
  1250. //----------------------------------------------------------------------------
  1251. std::string
  1252. cmLocalUnixMakefileGenerator2
  1253. ::ConvertToFullPath(const std::string& localPath)
  1254. {
  1255. std::string dir = m_Makefile->GetStartOutputDirectory();
  1256. dir += "/";
  1257. dir += localPath;
  1258. return dir;
  1259. }
  1260. //----------------------------------------------------------------------------
  1261. void cmLocalUnixMakefileGenerator2::AddLanguageFlags(std::string& flags,
  1262. const char* lang)
  1263. {
  1264. // Add language-specific flags.
  1265. std::string flagsVar = "CMAKE_";
  1266. flagsVar += lang;
  1267. flagsVar += "_FLAGS";
  1268. this->AddConfigVariableFlags(flags, flagsVar.c_str());
  1269. }
  1270. //----------------------------------------------------------------------------
  1271. void cmLocalUnixMakefileGenerator2::AddSharedFlags(std::string& flags,
  1272. const char* lang,
  1273. bool shared)
  1274. {
  1275. std::string flagsVar;
  1276. // Add flags for dealing with shared libraries for this language.
  1277. if(shared)
  1278. {
  1279. flagsVar = "CMAKE_SHARED_LIBRARY_";
  1280. flagsVar += lang;
  1281. flagsVar += "_FLAGS";
  1282. this->AppendFlags(flags, m_Makefile->GetDefinition(flagsVar.c_str()));
  1283. }
  1284. // Add flags specific to shared builds.
  1285. if(cmSystemTools::IsOn(m_Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1286. {
  1287. flagsVar = "CMAKE_SHARED_BUILD_";
  1288. flagsVar += lang;
  1289. flagsVar += "_FLAGS";
  1290. this->AppendFlags(flags, m_Makefile->GetDefinition(flagsVar.c_str()));
  1291. }
  1292. }
  1293. //----------------------------------------------------------------------------
  1294. void cmLocalUnixMakefileGenerator2::AddConfigVariableFlags(std::string& flags,
  1295. const char* var)
  1296. {
  1297. // Add the flags from the variable itself.
  1298. std::string flagsVar = var;
  1299. this->AppendFlags(flags, m_Makefile->GetDefinition(flagsVar.c_str()));
  1300. // Add the flags from the build-type specific variable.
  1301. const char* buildType = m_Makefile->GetDefinition("CMAKE_BUILD_TYPE");
  1302. if(buildType && *buildType)
  1303. {
  1304. flagsVar += "_";
  1305. flagsVar += cmSystemTools::UpperCase(buildType);
  1306. this->AppendFlags(flags, m_Makefile->GetDefinition(flagsVar.c_str()));
  1307. }
  1308. }
  1309. //----------------------------------------------------------------------------
  1310. void cmLocalUnixMakefileGenerator2::AppendFlags(std::string& flags,
  1311. const char* newFlags)
  1312. {
  1313. if(newFlags && *newFlags)
  1314. {
  1315. if(flags.size())
  1316. {
  1317. flags += " ";
  1318. }
  1319. flags += newFlags;
  1320. }
  1321. }
  1322. //----------------------------------------------------------------------------
  1323. void
  1324. cmLocalUnixMakefileGenerator2
  1325. ::AppendLibDepend(std::vector<std::string>& depends, const char* name)
  1326. {
  1327. // There are a few cases for the name of the target:
  1328. // - CMake target in this directory: depend on it.
  1329. // - CMake target in another directory: depend and add jump-and-build.
  1330. // - Full path to an outside file: depend on it.
  1331. // - Other format (like -lm): do nothing.
  1332. // If it is a CMake target there will be a definition for it.
  1333. std::string dirVar = name;
  1334. dirVar += "_CMAKE_PATH";
  1335. const char* dir = m_Makefile->GetDefinition(dirVar.c_str());
  1336. if(dir && *dir)
  1337. {
  1338. // This is a CMake target somewhere in this project.
  1339. bool jumpAndBuild = false;
  1340. // Get the path to the library.
  1341. std::string libPath;
  1342. if(this->SamePath(m_Makefile->GetStartOutputDirectory(), dir))
  1343. {
  1344. // The target is in the current directory so this makefile will
  1345. // know about it already.
  1346. libPath = m_LibraryOutputPath;
  1347. }
  1348. else
  1349. {
  1350. // The target is in another directory. Get the path to it.
  1351. if(m_LibraryOutputPath.size())
  1352. {
  1353. libPath = m_LibraryOutputPath;
  1354. }
  1355. else
  1356. {
  1357. libPath = dir;
  1358. libPath += "/";
  1359. }
  1360. // We need to add a jump-and-build rule for this library.
  1361. jumpAndBuild = true;
  1362. }
  1363. // Add the name of the library's file. This depends on the type
  1364. // of the library.
  1365. std::string typeVar = name;
  1366. typeVar += "_LIBRARY_TYPE";
  1367. std::string libType = m_Makefile->GetSafeDefinition(typeVar.c_str());
  1368. std::string prefix;
  1369. std::string suffix;
  1370. if(libType == "SHARED")
  1371. {
  1372. prefix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX");
  1373. suffix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
  1374. }
  1375. else if(libType == "MODULE")
  1376. {
  1377. prefix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_PREFIX");
  1378. suffix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_SUFFIX");
  1379. }
  1380. else if(libType == "STATIC")
  1381. {
  1382. prefix = m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX");
  1383. suffix = m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
  1384. }
  1385. libPath += prefix;
  1386. libPath += name;
  1387. libPath += suffix;
  1388. if(jumpAndBuild)
  1389. {
  1390. // We need to add a jump-and-build rule for this library.
  1391. cmLocalUnixMakefileGenerator2::RemoteTarget rt;
  1392. rt.m_BuildDirectory = dir;
  1393. rt.m_FilePath =libPath;
  1394. m_JumpAndBuild[name] = rt;
  1395. }
  1396. // Add a dependency on the library.
  1397. depends.push_back(this->ConvertToRelativeOutputPath(libPath.c_str()));
  1398. }
  1399. else
  1400. {
  1401. // This is not a CMake target. If it exists and is a full path we
  1402. // can depend on it.
  1403. if(cmSystemTools::FileExists(name) && cmSystemTools::FileIsFullPath(name))
  1404. {
  1405. depends.push_back(this->ConvertToRelativeOutputPath(name));
  1406. }
  1407. }
  1408. }
  1409. //----------------------------------------------------------------------------
  1410. std::string
  1411. cmLocalUnixMakefileGenerator2
  1412. ::GetRecursiveMakeCall(const char* tgt)
  1413. {
  1414. // Call make on the given file.
  1415. std::string cmd = "$(MAKE) -f Makefile2 ";
  1416. // Pass down verbosity level.
  1417. if(m_MakeSilentFlag.size())
  1418. {
  1419. cmd += m_MakeSilentFlag;
  1420. cmd += " ";
  1421. }
  1422. // Most unix makes will pass the command line flags to make down to
  1423. // sub-invoked makes via an environment variable. However, some
  1424. // makes do not support that, so you have to pass the flags
  1425. // explicitly.
  1426. if(m_PassMakeflags)
  1427. {
  1428. cmd += "-$(MAKEFLAGS) ";
  1429. }
  1430. // Add the target.
  1431. cmd += tgt;
  1432. return cmd;
  1433. }
  1434. //----------------------------------------------------------------------------
  1435. void
  1436. cmLocalUnixMakefileGenerator2
  1437. ::WriteJumpAndBuildRules(std::ostream& makefileStream)
  1438. {
  1439. // Write the header for this section.
  1440. if(!m_JumpAndBuild.empty())
  1441. {
  1442. this->WriteDivider(makefileStream);
  1443. makefileStream
  1444. << "# Targets to make sure needed libraries exist.\n"
  1445. << "# These will jump to other directories to build targets.\n"
  1446. << "\n";
  1447. }
  1448. std::vector<std::string> depends;
  1449. std::vector<std::string> commands;
  1450. for(std::map<cmStdString, RemoteTarget>::iterator
  1451. jump = m_JumpAndBuild.begin(); jump != m_JumpAndBuild.end(); ++jump)
  1452. {
  1453. const cmLocalUnixMakefileGenerator2::RemoteTarget& rt = jump->second;
  1454. const char* destination = rt.m_BuildDirectory.c_str();
  1455. // Construct the dependency and build target names.
  1456. std::string dep = jump->first;
  1457. dep += ".dir/";
  1458. dep += jump->first;
  1459. dep += ".depends";
  1460. std::string tgt = jump->first;
  1461. tgt += ".requires";
  1462. // Build the jump-and-build command list.
  1463. commands.clear();
  1464. if(m_WindowsShell)
  1465. {
  1466. // On Windows we must perform each step separately and then jump
  1467. // back because the shell keeps the working directory between
  1468. // commands.
  1469. std::string cmd = "cd ";
  1470. cmd += this->ConvertToOutputForExisting(destination);
  1471. commands.push_back(cmd);
  1472. // Check the build system in destination directory.
  1473. commands.push_back(this->GetRecursiveMakeCall("cmake_check_rerun"));
  1474. // Build the targets's dependencies.
  1475. commands.push_back(this->GetRecursiveMakeCall(dep.c_str()));
  1476. // Build the target.
  1477. commands.push_back(this->GetRecursiveMakeCall(tgt.c_str()));
  1478. // Jump back to the starting directory.
  1479. cmd = "cd ";
  1480. cmd += this->ConvertToOutputForExisting(m_Makefile->GetStartOutputDirectory());
  1481. commands.push_back(cmd);
  1482. }
  1483. else
  1484. {
  1485. // On UNIX we must construct a single shell command to jump and
  1486. // build because make resets the directory between each command.
  1487. std::string cmd = "cd ";
  1488. cmd += this->ConvertToOutputForExisting(destination);
  1489. // Check the build system in destination directory.
  1490. cmd += " && ";
  1491. cmd += this->GetRecursiveMakeCall("cmake_check_rerun");
  1492. // Build the targets's dependencies.
  1493. cmd += " && ";
  1494. cmd += this->GetRecursiveMakeCall(dep.c_str());
  1495. // Build the target.
  1496. cmd += " && ";
  1497. cmd += this->GetRecursiveMakeCall(tgt.c_str());
  1498. // Add the command as a single line.
  1499. commands.push_back(cmd);
  1500. }
  1501. // Write the rule.
  1502. std::string jumpPreEcho = "Jumping to ";
  1503. jumpPreEcho += rt.m_BuildDirectory.c_str();
  1504. jumpPreEcho += " to build ";
  1505. jumpPreEcho += jump->first;
  1506. jumpPreEcho += "...";
  1507. std::string jumpPostEcho = "Returning to ";
  1508. jumpPostEcho += m_Makefile->GetStartOutputDirectory();
  1509. jumpPostEcho += "...";
  1510. this->WriteMakeRule(makefileStream, 0, jumpPreEcho.c_str(),
  1511. rt.m_FilePath.c_str(), depends, commands,
  1512. jumpPostEcho.c_str());
  1513. }
  1514. }
  1515. //----------------------------------------------------------------------------
  1516. bool
  1517. cmLocalUnixMakefileGenerator2
  1518. ::ScanDependencies(std::vector<std::string> const& args)
  1519. {
  1520. // Format of arguments is:
  1521. // $(CMAKE_COMMAND), cmake_depends, <lang>, <obj>, <src>, [include-flags]
  1522. // The caller has ensured that all required arguments exist.
  1523. // The file to which to write dependencies.
  1524. const char* objFile = args[3].c_str();
  1525. // The source file at which to start the scan.
  1526. const char* srcFile = args[4].c_str();
  1527. // Convert the include flags to full paths.
  1528. std::vector<std::string> includes;
  1529. for(unsigned int i=5; i < args.size(); ++i)
  1530. {
  1531. if(args[i].substr(0, 2) == "-I")
  1532. {
  1533. // Get the include path without the -I flag.
  1534. std::string inc = args[i].substr(2);
  1535. includes.push_back(cmSystemTools::CollapseFullPath(inc.c_str()));
  1536. }
  1537. }
  1538. // Dispatch the scan for each language.
  1539. std::string const& lang = args[2];
  1540. if(lang == "C" || lang == "CXX")
  1541. {
  1542. return cmLocalUnixMakefileGenerator2::ScanDependenciesC(objFile, srcFile,
  1543. includes);
  1544. }
  1545. return false;
  1546. }
  1547. //----------------------------------------------------------------------------
  1548. void
  1549. cmLocalUnixMakefileGenerator2ScanDependenciesC(
  1550. std::ifstream& fin,
  1551. std::set<cmStdString>& encountered,
  1552. std::queue<cmStdString>& unscanned)
  1553. {
  1554. // Regular expression to identify C preprocessor include directives.
  1555. cmsys::RegularExpression
  1556. includeLine("^[ \t]*#[ \t]*include[ \t]*[<\"]([^\">]+)[\">]");
  1557. // Read one line at a time.
  1558. std::string line;
  1559. while(cmSystemTools::GetLineFromStream(fin, line))
  1560. {
  1561. // Match include directives.
  1562. if(includeLine.find(line.c_str()))
  1563. {
  1564. // Get the file being included.
  1565. std::string includeFile = includeLine.match(1);
  1566. // Queue the file if it has not yet been encountered.
  1567. if(encountered.find(includeFile) == encountered.end())
  1568. {
  1569. encountered.insert(includeFile);
  1570. unscanned.push(includeFile);
  1571. }
  1572. }
  1573. }
  1574. }
  1575. //----------------------------------------------------------------------------
  1576. bool
  1577. cmLocalUnixMakefileGenerator2
  1578. ::ScanDependenciesC(const char* objFile, const char* srcFile,
  1579. std::vector<std::string> const& includes)
  1580. {
  1581. // Walk the dependency graph starting with the source file.
  1582. std::set<cmStdString> dependencies;
  1583. std::set<cmStdString> encountered;
  1584. std::set<cmStdString> scanned;
  1585. std::queue<cmStdString> unscanned;
  1586. unscanned.push(srcFile);
  1587. encountered.insert(srcFile);
  1588. while(!unscanned.empty())
  1589. {
  1590. // Get the next file to scan.
  1591. std::string fname = unscanned.front();
  1592. unscanned.pop();
  1593. // If not a full path, find the file in the include path.
  1594. std::string fullName;
  1595. if(cmSystemTools::FileIsFullPath(fname.c_str()))
  1596. {
  1597. fullName = fname;
  1598. }
  1599. else
  1600. {
  1601. for(std::vector<std::string>::const_iterator i = includes.begin();
  1602. i != includes.end(); ++i)
  1603. {
  1604. std::string temp = *i;
  1605. temp += "/";
  1606. temp += fname;
  1607. if(cmSystemTools::FileExists(temp.c_str()))
  1608. {
  1609. fullName = temp;
  1610. break;
  1611. }
  1612. }
  1613. }
  1614. // Scan the file if it was found and has not been scanned already.
  1615. if(fullName.size() && (scanned.find(fullName) == scanned.end()))
  1616. {
  1617. // Record scanned files.
  1618. scanned.insert(fullName);
  1619. // Try to scan the file. Just leave it out if we cannot find
  1620. // it.
  1621. std::ifstream fin(fullName.c_str());
  1622. if(fin)
  1623. {
  1624. // Add this file as a dependency.
  1625. dependencies.insert(fullName);
  1626. // Scan this file for new dependencies.
  1627. cmLocalUnixMakefileGenerator2ScanDependenciesC(fin, encountered,
  1628. unscanned);
  1629. }
  1630. }
  1631. }
  1632. // Write the dependencies to the output file.
  1633. std::string depMarkFile = objFile;
  1634. std::string depMakeFile = objFile;
  1635. depMarkFile += ".depends";
  1636. depMakeFile += ".depends.make";
  1637. std::ofstream fout(depMakeFile.c_str());
  1638. fout << "# Dependencies for " << objFile << std::endl;
  1639. for(std::set<cmStdString>::iterator i=dependencies.begin();
  1640. i != dependencies.end(); ++i)
  1641. {
  1642. fout << objFile << ": "
  1643. << cmSystemTools::ConvertToOutputPath(i->c_str()).c_str()
  1644. << std::endl;
  1645. }
  1646. fout << std::endl;
  1647. fout << "# Dependencies for " << depMarkFile.c_str() << std::endl;
  1648. for(std::set<cmStdString>::iterator i=dependencies.begin();
  1649. i != dependencies.end(); ++i)
  1650. {
  1651. fout << depMarkFile.c_str() << ": "
  1652. << cmSystemTools::ConvertToOutputPath(i->c_str()).c_str()
  1653. << std::endl;
  1654. }
  1655. // If we could write the dependencies, touch the corresponding
  1656. // depends file to mark dependencies up to date.
  1657. if(fout)
  1658. {
  1659. std::ofstream fmark(depMarkFile.c_str());
  1660. fmark << "Dependencies updated for " << objFile << "\n";
  1661. }
  1662. return true;
  1663. }