cmLocalUnixMakefileGenerator3.cxx 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902
  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 "cmLocalUnixMakefileGenerator3.h"
  14. #include "cmDepends.h"
  15. #include "cmGeneratedFileStream.h"
  16. #include "cmGlobalUnixMakefileGenerator3.h"
  17. #include "cmMakefile.h"
  18. #include "cmMakefileTargetGenerator.h"
  19. #include "cmSourceFile.h"
  20. #include "cmake.h"
  21. // Include dependency scanners for supported languages. Only the
  22. // C/C++ scanner is needed for bootstrapping CMake.
  23. #include "cmDependsC.h"
  24. #ifdef CMAKE_BUILD_WITH_CMAKE
  25. # include "cmDependsFortran.h"
  26. # include "cmDependsJava.h"
  27. #endif
  28. #include <memory> // auto_ptr
  29. #include <queue>
  30. //----------------------------------------------------------------------------
  31. cmLocalUnixMakefileGenerator3::cmLocalUnixMakefileGenerator3()
  32. {
  33. this->SilentNoColon = false;
  34. this->WindowsShell = false;
  35. this->IncludeDirective = "include";
  36. this->MakefileVariableSize = 0;
  37. this->IgnoreLibPrefix = false;
  38. this->PassMakeflags = false;
  39. this->EchoNeedsQuote = true;
  40. this->DefineWindowsNULL = false;
  41. this->UnixCD = true;
  42. this->ForceVerboseMakefiles=false;
  43. this->ColorMakefile = false;
  44. }
  45. //----------------------------------------------------------------------------
  46. cmLocalUnixMakefileGenerator3::~cmLocalUnixMakefileGenerator3()
  47. {
  48. }
  49. //----------------------------------------------------------------------------
  50. void cmLocalUnixMakefileGenerator3::Configure()
  51. {
  52. // Include the rule file for each object.
  53. this->HomeRelativeOutputPath =
  54. cmSystemTools::RelativePath(this->Makefile->GetHomeOutputDirectory(),
  55. this->Makefile->GetStartOutputDirectory());
  56. if (this->HomeRelativeOutputPath.size())
  57. {
  58. this->HomeRelativeOutputPath += "/";
  59. }
  60. this->cmLocalGenerator::Configure();
  61. }
  62. //----------------------------------------------------------------------------
  63. void cmLocalUnixMakefileGenerator3::Generate()
  64. {
  65. // Setup our configuration variables for this directory.
  66. this->ConfigureOutputPaths();
  67. // Record whether color makefiles are enabled to avoid checking many
  68. // times later.
  69. this->ColorMakefile = this->Makefile->IsOn("CMAKE_COLOR_MAKEFILE");
  70. // Generate the rule files for each target.
  71. cmTargets& targets = this->Makefile->GetTargets();
  72. std::string empty;
  73. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  74. {
  75. cmMakefileTargetGenerator *tg =
  76. cmMakefileTargetGenerator::New(this, t->first, &(t->second));
  77. if (tg)
  78. {
  79. this->TargetGenerators.push_back(tg);
  80. t->second.TraceVSDependencies(empty, this->Makefile);
  81. tg->WriteRuleFiles();
  82. }
  83. }
  84. // write the local Makefile
  85. this->WriteLocalMakefile();
  86. // Write the cmake file with information for this directory.
  87. this->WriteDirectoryInformationFile();
  88. }
  89. //----------------------------------------------------------------------------
  90. // return info about progress actions
  91. unsigned long cmLocalUnixMakefileGenerator3::GetNumberOfProgressActions()
  92. {
  93. unsigned long result = 0;
  94. for (std::vector<cmMakefileTargetGenerator *>::iterator mtgIter =
  95. this->TargetGenerators.begin();
  96. mtgIter != this->TargetGenerators.end(); ++mtgIter)
  97. {
  98. result += (*mtgIter)->GetNumberOfProgressActions();
  99. }
  100. return result;
  101. }
  102. //----------------------------------------------------------------------------
  103. // return info about progress actions
  104. unsigned long cmLocalUnixMakefileGenerator3
  105. ::GetNumberOfProgressActionsForTarget(const char *name)
  106. {
  107. for (std::vector<cmMakefileTargetGenerator *>::iterator mtgIter =
  108. this->TargetGenerators.begin();
  109. mtgIter != this->TargetGenerators.end(); ++mtgIter)
  110. {
  111. if (!strcmp(name,(*mtgIter)->GetTargetName()))
  112. {
  113. return (*mtgIter)->GetNumberOfProgressActions();
  114. }
  115. }
  116. return 0;
  117. }
  118. //----------------------------------------------------------------------------
  119. // writes the progreess variables and also closes out the targets
  120. void cmLocalUnixMakefileGenerator3
  121. ::WriteProgressVariables(unsigned long total,
  122. unsigned long &current)
  123. {
  124. // delete the makefile target generator objects
  125. for (std::vector<cmMakefileTargetGenerator *>::iterator mtgIter =
  126. this->TargetGenerators.begin();
  127. mtgIter != this->TargetGenerators.end(); ++mtgIter)
  128. {
  129. (*mtgIter)->WriteProgressVariables(total,current);
  130. delete *mtgIter;
  131. }
  132. this->TargetGenerators.clear();
  133. }
  134. void cmLocalUnixMakefileGenerator3::WriteAllProgressVariable()
  135. {
  136. // write the top level progress for the all target
  137. std::string progressFileNameFull =
  138. this->ConvertToFullPath("progress.make");
  139. cmGeneratedFileStream ruleFileStream(progressFileNameFull.c_str());
  140. if(!ruleFileStream)
  141. {
  142. return;
  143. }
  144. cmGlobalUnixMakefileGenerator3 *gg =
  145. static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
  146. ruleFileStream << "CMAKE_ALL_PROGRESS = "
  147. << gg->GetNumberOfProgressActionsInAll(this);
  148. }
  149. //----------------------------------------------------------------------------
  150. void cmLocalUnixMakefileGenerator3::ConfigureOutputPaths()
  151. {
  152. // Format the library and executable output paths.
  153. if(const char* libOut =
  154. this->Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  155. {
  156. this->LibraryOutputPath = libOut;
  157. this->FormatOutputPath(this->LibraryOutputPath, "LIBRARY");
  158. }
  159. if(const char* exeOut =
  160. this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  161. {
  162. this->ExecutableOutputPath = exeOut;
  163. this->FormatOutputPath(this->ExecutableOutputPath, "EXECUTABLE");
  164. }
  165. // Store the configuration name that will be generated.
  166. if(const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"))
  167. {
  168. // Use the build type given by the user.
  169. this->ConfigurationName = config;
  170. }
  171. else
  172. {
  173. // No configuration type given.
  174. this->ConfigurationName = "";
  175. }
  176. }
  177. //----------------------------------------------------------------------------
  178. void cmLocalUnixMakefileGenerator3::FormatOutputPath(std::string& path,
  179. const char* name)
  180. {
  181. if(!path.empty())
  182. {
  183. // Convert the output path to a full path in case it is
  184. // specified as a relative path. Treat a relative path as
  185. // relative to the current output directory for this makefile.
  186. path = cmSystemTools::CollapseFullPath
  187. (path.c_str(), this->Makefile->GetStartOutputDirectory());
  188. // Add a trailing slash for easy appending later.
  189. if(path.empty() || path[path.size()-1] != '/')
  190. {
  191. path += "/";
  192. }
  193. // Make sure the output path exists on disk.
  194. if(!cmSystemTools::MakeDirectory(path.c_str()))
  195. {
  196. cmSystemTools::Error("Error failed to create ",
  197. name, "_OUTPUT_PATH directory:", path.c_str());
  198. }
  199. // Add this as a link directory automatically.
  200. this->Makefile->AddLinkDirectory(path.c_str());
  201. }
  202. }
  203. //----------------------------------------------------------------------------
  204. void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
  205. {
  206. // generate the includes
  207. std::string ruleFileName = "Makefile";
  208. // Open the rule file. This should be copy-if-different because the
  209. // rules may depend on this file itself.
  210. std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
  211. cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
  212. if(!ruleFileStream)
  213. {
  214. return;
  215. }
  216. // always write the top makefile
  217. if (this->Parent)
  218. {
  219. ruleFileStream.SetCopyIfDifferent(true);
  220. }
  221. // Include the progress variables for the target.
  222. ruleFileStream
  223. << "# Include the progress variables for this target.\n"
  224. << this->IncludeDirective << " "
  225. << "progress.make\n\n";
  226. // write the all rules
  227. this->WriteLocalAllRules(ruleFileStream);
  228. // only write local targets unless at the top Keep track of targets already
  229. // listed.
  230. std::set<cmStdString> emittedTargets;
  231. if (this->Parent)
  232. {
  233. // write our targets, and while doing it collect up the object
  234. // file rules
  235. this->WriteLocalMakefileTargets(ruleFileStream,emittedTargets);
  236. }
  237. else
  238. {
  239. cmGlobalUnixMakefileGenerator3 *gg =
  240. static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
  241. gg->WriteConvenienceRules(ruleFileStream,emittedTargets);
  242. }
  243. std::vector<std::string> depends;
  244. std::vector<std::string> commands;
  245. // now write out the object rules
  246. // for each object file name
  247. for (std::map<cmStdString,std::vector<cmTarget *> >::iterator lo =
  248. this->LocalObjectFiles.begin();
  249. lo != this->LocalObjectFiles.end(); ++lo)
  250. {
  251. commands.clear();
  252. // for each target using the object file
  253. for (std::vector<cmTarget *>::iterator to =
  254. lo->second.begin(); to != lo->second.end(); ++to)
  255. {
  256. std::string tgtMakefileName = this->GetRelativeTargetDirectory(**to);
  257. std::string targetName = tgtMakefileName;
  258. tgtMakefileName += "/build.make";
  259. targetName += "/";
  260. targetName += lo->first.c_str();
  261. commands.push_back(this->GetRecursiveMakeCall
  262. (tgtMakefileName.c_str(),targetName.c_str()));
  263. this->CreateCDCommand(commands,
  264. this->Makefile->GetHomeOutputDirectory(),
  265. this->Makefile->GetStartOutputDirectory());
  266. }
  267. this->WriteMakeRule(ruleFileStream,
  268. "target for object file",
  269. lo->first.c_str(), depends, commands, false);
  270. }
  271. // add a help target as long as there isn;t a real target named help
  272. if(emittedTargets.insert("help").second)
  273. {
  274. cmGlobalUnixMakefileGenerator3 *gg =
  275. static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
  276. gg->WriteHelpRule(ruleFileStream,this);
  277. }
  278. this->WriteSpecialTargetsBottom(ruleFileStream);
  279. }
  280. void cmLocalUnixMakefileGenerator3
  281. ::WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  282. std::set<cmStdString> &emitted)
  283. {
  284. std::vector<std::string> depends;
  285. std::vector<std::string> commands;
  286. // for each target we just provide a rule to cd up to the top and do a make
  287. // on the target
  288. cmTargets& targets = this->Makefile->GetTargets();
  289. std::string localName;
  290. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  291. {
  292. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  293. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  294. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  295. (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
  296. (t->second.GetType() == cmTarget::UTILITY))
  297. {
  298. emitted.insert(t->second.GetName());
  299. // for subdirs add a rule to build this specific target by name.
  300. localName = this->GetRelativeTargetDirectory(t->second);
  301. localName += "/rule";
  302. commands.clear();
  303. depends.clear();
  304. // Build the target for this pass.
  305. std::string tmp = cmake::GetCMakeFilesDirectoryPostSlash();
  306. tmp += "Makefile2";
  307. commands.push_back(this->GetRecursiveMakeCall
  308. (tmp.c_str(),localName.c_str()));
  309. this->CreateCDCommand(commands,
  310. this->Makefile->GetHomeOutputDirectory(),
  311. this->Makefile->GetStartOutputDirectory());
  312. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  313. localName.c_str(), depends, commands, true);
  314. // Add a target with the canonical name (no prefix, suffix or path).
  315. if(localName != t->second.GetName())
  316. {
  317. commands.clear();
  318. depends.push_back(localName);
  319. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  320. t->second.GetName(), depends, commands, true);
  321. }
  322. // Add a fast rule to build the target
  323. std::string makefileName = this->GetRelativeTargetDirectory(t->second);
  324. makefileName += "/build.make";
  325. std::string makeTargetName =
  326. this->GetRelativeTargetDirectory(t->second);
  327. makeTargetName += "/build";
  328. localName = t->second.GetName();
  329. localName += "/fast";
  330. depends.clear();
  331. commands.clear();
  332. commands.push_back(this->GetRecursiveMakeCall
  333. (makefileName.c_str(), makeTargetName.c_str()));
  334. this->CreateCDCommand(commands,
  335. this->Makefile->GetHomeOutputDirectory(),
  336. this->Makefile->GetStartOutputDirectory());
  337. this->WriteMakeRule(ruleFileStream, "fast build rule for target.",
  338. localName.c_str(), depends, commands, true);
  339. }
  340. }
  341. }
  342. //----------------------------------------------------------------------------
  343. void cmLocalUnixMakefileGenerator3::WriteDirectoryInformationFile()
  344. {
  345. std::string infoFileName = this->Makefile->GetStartOutputDirectory();
  346. infoFileName += cmake::GetCMakeFilesDirectory();
  347. infoFileName += "/CMakeDirectoryInformation.cmake";
  348. // Open the output file.
  349. cmGeneratedFileStream infoFileStream(infoFileName.c_str());
  350. if(!infoFileStream)
  351. {
  352. return;
  353. }
  354. // Write the do not edit header.
  355. this->WriteDisclaimer(infoFileStream);
  356. // Tell the dependency scanner to use unix paths if necessary.
  357. if(cmSystemTools::GetForceUnixPaths())
  358. {
  359. infoFileStream
  360. << "# Force unix paths in dependencies.\n"
  361. << "SET(CMAKE_FORCE_UNIX_PATHS 1)\n"
  362. << "\n";
  363. }
  364. // Store the include search path for this directory.
  365. infoFileStream
  366. << "# The C and CXX include file search paths:\n";
  367. infoFileStream
  368. << "SET(CMAKE_C_INCLUDE_PATH\n";
  369. std::vector<std::string> includeDirs;
  370. this->GetIncludeDirectories(includeDirs);
  371. for(std::vector<std::string>::iterator i = includeDirs.begin();
  372. i != includeDirs.end(); ++i)
  373. {
  374. // Note: This path conversion must match that used for
  375. // CMAKE_GENERATED_FILES so that the file names match.
  376. infoFileStream
  377. << " \"" << this->Convert(i->c_str(),HOME_OUTPUT).c_str() << "\"\n";
  378. }
  379. infoFileStream
  380. << " )\n";
  381. infoFileStream
  382. << "SET(CMAKE_CXX_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH})\n";
  383. // Store the include regular expressions for this directory.
  384. infoFileStream
  385. << "\n"
  386. << "# The C and CXX include file regular expressions for "
  387. << "this directory.\n";
  388. infoFileStream
  389. << "SET(CMAKE_C_INCLUDE_REGEX_SCAN ";
  390. this->WriteCMakeArgument(infoFileStream,
  391. this->Makefile->GetIncludeRegularExpression());
  392. infoFileStream
  393. << ")\n";
  394. infoFileStream
  395. << "SET(CMAKE_C_INCLUDE_REGEX_COMPLAIN ";
  396. this->WriteCMakeArgument(infoFileStream,
  397. this->Makefile->GetComplainRegularExpression());
  398. infoFileStream
  399. << ")\n";
  400. infoFileStream
  401. << "SET(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN})\n";
  402. infoFileStream
  403. << "SET(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN "
  404. "${CMAKE_C_INCLUDE_REGEX_COMPLAIN})\n";
  405. // Store the set of available generated files.
  406. infoFileStream
  407. << "\n"
  408. << "# The set of files generated by rules in this directory:\n";
  409. infoFileStream
  410. << "SET(CMAKE_GENERATED_FILES\n";
  411. for(std::vector<cmSourceFile*>::const_iterator
  412. i = this->Makefile->GetSourceFiles().begin();
  413. i != this->Makefile->GetSourceFiles().end(); ++i)
  414. {
  415. cmSourceFile* src = *i;
  416. if(src->GetPropertyAsBool("GENERATED"))
  417. {
  418. // Note: This path conversion must match that used for
  419. // CMAKE_C_INCLUDE_PATH so that the file names match.
  420. infoFileStream
  421. << " \""
  422. << this->Convert(src->GetFullPath().c_str(), HOME_OUTPUT)
  423. << "\"\n";
  424. }
  425. }
  426. infoFileStream
  427. << ")\n";
  428. }
  429. //----------------------------------------------------------------------------
  430. std::string
  431. cmLocalUnixMakefileGenerator3
  432. ::ConvertToFullPath(const std::string& localPath)
  433. {
  434. std::string dir = this->Makefile->GetStartOutputDirectory();
  435. dir += "/";
  436. dir += localPath;
  437. return dir;
  438. }
  439. const std::string &cmLocalUnixMakefileGenerator3::GetHomeRelativeOutputPath()
  440. {
  441. return this->HomeRelativeOutputPath;
  442. }
  443. //----------------------------------------------------------------------------
  444. void
  445. cmLocalUnixMakefileGenerator3
  446. ::WriteMakeRule(std::ostream& os,
  447. const char* comment,
  448. const char* target,
  449. const std::vector<std::string>& depends,
  450. const std::vector<std::string>& commands,
  451. bool symbolic)
  452. {
  453. // Make sure there is a target.
  454. if(!target || !*target)
  455. {
  456. cmSystemTools::Error("No target for WriteMakeRule! called with comment: ",
  457. comment);
  458. return;
  459. }
  460. std::string replace;
  461. // Write the comment describing the rule in the makefile.
  462. if(comment)
  463. {
  464. replace = comment;
  465. std::string::size_type lpos = 0;
  466. std::string::size_type rpos;
  467. while((rpos = replace.find('\n', lpos)) != std::string::npos)
  468. {
  469. os << "# " << replace.substr(lpos, rpos-lpos) << "\n";
  470. lpos = rpos+1;
  471. }
  472. os << "# " << replace.substr(lpos) << "\n";
  473. }
  474. // Construct the left hand side of the rule.
  475. replace = target;
  476. std::string tgt = this->Convert(replace.c_str(),HOME_OUTPUT,MAKEFILE);
  477. tgt = this->ConvertToMakeTarget(tgt.c_str());
  478. const char* space = "";
  479. if(tgt.size() == 1)
  480. {
  481. // Add a space before the ":" to avoid drive letter confusion on
  482. // Windows.
  483. space = " ";
  484. }
  485. // Mark the rule as symbolic if requested.
  486. if(symbolic)
  487. {
  488. if(const char* sym =
  489. this->Makefile->GetDefinition("CMAKE_MAKE_SYMBOLIC_RULE"))
  490. {
  491. os << tgt.c_str() << space << ": " << sym << "\n";
  492. }
  493. }
  494. // Write the rule.
  495. if(depends.empty())
  496. {
  497. // No dependencies. The commands will always run.
  498. os << tgt.c_str() << space << ":\n";
  499. }
  500. else
  501. {
  502. // Split dependencies into multiple rule lines. This allows for
  503. // very long dependency lists even on older make implementations.
  504. for(std::vector<std::string>::const_iterator dep = depends.begin();
  505. dep != depends.end(); ++dep)
  506. {
  507. replace = *dep;
  508. replace = this->Convert(replace.c_str(),HOME_OUTPUT,MAKEFILE);
  509. replace = this->ConvertToMakeTarget(replace.c_str());
  510. os << tgt.c_str() << space << ": " << replace.c_str() << "\n";
  511. }
  512. }
  513. // Write the list of commands.
  514. for(std::vector<std::string>::const_iterator i = commands.begin();
  515. i != commands.end(); ++i)
  516. {
  517. replace = *i;
  518. os << "\t" << replace.c_str() << "\n";
  519. }
  520. os << "\n";
  521. }
  522. //----------------------------------------------------------------------------
  523. void
  524. cmLocalUnixMakefileGenerator3
  525. ::WriteMakeVariables(std::ostream& makefileStream)
  526. {
  527. this->WriteDivider(makefileStream);
  528. makefileStream
  529. << "# Set environment variables for the build.\n"
  530. << "\n";
  531. if(this->DefineWindowsNULL)
  532. {
  533. makefileStream
  534. << "!IF \"$(OS)\" == \"Windows_NT\"\n"
  535. << "NULL=\n"
  536. << "!ELSE\n"
  537. << "NULL=nul\n"
  538. << "!ENDIF\n";
  539. }
  540. if(this->WindowsShell)
  541. {
  542. makefileStream
  543. << "SHELL = cmd.exe\n"
  544. << "\n";
  545. }
  546. else
  547. {
  548. makefileStream
  549. << "# The shell in which to execute make rules.\n"
  550. << "SHELL = /bin/sh\n"
  551. << "\n";
  552. }
  553. std::string cmakecommand =
  554. this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  555. makefileStream
  556. << "# The CMake executable.\n"
  557. << "CMAKE_COMMAND = "
  558. << this->Convert(cmakecommand.c_str(), FULL, SHELL).c_str()
  559. << "\n"
  560. << "\n";
  561. makefileStream
  562. << "# The command to remove a file.\n"
  563. << "RM = "
  564. << this->Convert(cmakecommand.c_str(),FULL,SHELL).c_str()
  565. << " -E remove -f\n"
  566. << "\n";
  567. if(this->Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  568. {
  569. makefileStream
  570. << "# The program to use to edit the cache.\n"
  571. << "CMAKE_EDIT_COMMAND = "
  572. << (this->ConvertToOutputForExisting(
  573. this->Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))) << "\n"
  574. << "\n";
  575. }
  576. makefileStream
  577. << "# The top-level source directory on which CMake was run.\n"
  578. << "CMAKE_SOURCE_DIR = "
  579. << this->Convert(this->Makefile->GetHomeDirectory(), FULL, SHELL)
  580. << "\n"
  581. << "\n";
  582. makefileStream
  583. << "# The top-level build directory on which CMake was run.\n"
  584. << "CMAKE_BINARY_DIR = "
  585. << this->Convert(this->Makefile->GetHomeOutputDirectory(), FULL, SHELL)
  586. << "\n"
  587. << "\n";
  588. }
  589. //----------------------------------------------------------------------------
  590. void
  591. cmLocalUnixMakefileGenerator3
  592. ::WriteSpecialTargetsTop(std::ostream& makefileStream)
  593. {
  594. this->WriteDivider(makefileStream);
  595. makefileStream
  596. << "# Special targets provided by cmake.\n"
  597. << "\n";
  598. // Write special target to silence make output. This must be after
  599. // the default target in case VERBOSE is set (which changes the
  600. // name). The setting of CMAKE_VERBOSE_MAKEFILE to ON will cause a
  601. // "VERBOSE=1" to be added as a make variable which will change the
  602. // name of this special target. This gives a make-time choice to
  603. // the user.
  604. std::vector<std::string> commands;
  605. std::vector<std::string> no_depends;
  606. commands.clear();
  607. if((this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  608. || (this->ForceVerboseMakefiles))
  609. {
  610. makefileStream
  611. << "# Produce verbose output by default.\n"
  612. << "VERBOSE = 1\n"
  613. << "\n";
  614. }
  615. if(this->SilentNoColon)
  616. {
  617. makefileStream << "$(VERBOSE).SILENT\n";
  618. }
  619. else
  620. {
  621. this->WriteMakeRule(makefileStream,
  622. "Suppress display of executed commands.",
  623. "$(VERBOSE).SILENT",
  624. no_depends,
  625. commands, false);
  626. }
  627. // Special target to cleanup operation of make tool.
  628. std::vector<std::string> depends;
  629. this->WriteMakeRule
  630. (makefileStream,
  631. "Disable implicit rules so canoncical targets will work.",
  632. ".SUFFIXES",
  633. depends, commands, false);
  634. // Add a fake suffix to keep HP happy. Must be max 32 chars for SGI make.
  635. depends.push_back(".hpux_make_needs_suffix_list");
  636. this->WriteMakeRule(makefileStream, 0,
  637. ".SUFFIXES", depends, commands, false);
  638. }
  639. //----------------------------------------------------------------------------
  640. void cmLocalUnixMakefileGenerator3
  641. ::WriteSpecialTargetsBottom(std::ostream& makefileStream)
  642. {
  643. this->WriteDivider(makefileStream);
  644. makefileStream
  645. << "# Special targets to cleanup operation of make.\n"
  646. << "\n";
  647. // Write special "cmake_check_build_system" target to run cmake with
  648. // the --check-build-system flag.
  649. {
  650. // Build command to run CMake to check if anything needs regenerating.
  651. std::string cmakefileName = cmake::GetCMakeFilesDirectoryPostSlash();
  652. cmakefileName += "Makefile.cmake";
  653. std::string runRule =
  654. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
  655. runRule += " --check-build-system ";
  656. runRule += this->Convert(cmakefileName.c_str(),NONE,SHELL);
  657. runRule += " 0";
  658. std::vector<std::string> no_depends;
  659. std::vector<std::string> commands;
  660. commands.push_back(runRule);
  661. if(this->Parent)
  662. {
  663. this->CreateCDCommand(commands,
  664. this->Makefile->GetHomeOutputDirectory(),
  665. this->Makefile->GetStartOutputDirectory());
  666. }
  667. this->WriteMakeRule(makefileStream,
  668. "Special rule to run CMake to check the build system "
  669. "integrity.\n"
  670. "No rule that depends on this can have "
  671. "commands that come from listfiles\n"
  672. "because they might be regenerated.",
  673. "cmake_check_build_system",
  674. no_depends,
  675. commands, true);
  676. }
  677. std::vector<std::string> no_commands;
  678. }
  679. //----------------------------------------------------------------------------
  680. void
  681. cmLocalUnixMakefileGenerator3
  682. ::WriteConvenienceRule(std::ostream& ruleFileStream,
  683. const char* realTarget,
  684. const char* helpTarget)
  685. {
  686. // A rule is only needed if the names are different.
  687. if(strcmp(realTarget, helpTarget) != 0)
  688. {
  689. // The helper target depends on the real target.
  690. std::vector<std::string> depends;
  691. depends.push_back(realTarget);
  692. // There are no commands.
  693. std::vector<std::string> no_commands;
  694. // Write the rule.
  695. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  696. helpTarget, depends, no_commands, true);
  697. }
  698. }
  699. //----------------------------------------------------------------------------
  700. std::string
  701. cmLocalUnixMakefileGenerator3::GetRelativeTargetDirectory(cmTarget& target)
  702. {
  703. std::string dir = this->HomeRelativeOutputPath;
  704. dir += this->GetTargetDirectory(target);
  705. return this->Convert(dir.c_str(),NONE,MAKEFILE);
  706. }
  707. //----------------------------------------------------------------------------
  708. void
  709. cmLocalUnixMakefileGenerator3
  710. ::AppendRuleDepend(std::vector<std::string>& depends,
  711. const char* ruleFileName)
  712. {
  713. // Add a dependency on the rule file itself unless an option to skip
  714. // it is specifically enabled by the user or project.
  715. const char* nodep =
  716. this->Makefile->GetDefinition("CMAKE_SKIP_RULE_DEPENDENCY");
  717. if(!nodep || cmSystemTools::IsOff(nodep))
  718. {
  719. depends.push_back(ruleFileName);
  720. }
  721. }
  722. //----------------------------------------------------------------------------
  723. void
  724. cmLocalUnixMakefileGenerator3
  725. ::AppendCustomDepends(std::vector<std::string>& depends,
  726. const std::vector<cmCustomCommand>& ccs)
  727. {
  728. for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
  729. i != ccs.end(); ++i)
  730. {
  731. this->AppendCustomDepend(depends, *i);
  732. }
  733. }
  734. //----------------------------------------------------------------------------
  735. void
  736. cmLocalUnixMakefileGenerator3
  737. ::AppendCustomDepend(std::vector<std::string>& depends,
  738. const cmCustomCommand& cc)
  739. {
  740. for(std::vector<std::string>::const_iterator d = cc.GetDepends().begin();
  741. d != cc.GetDepends().end(); ++d)
  742. {
  743. // Lookup the real name of the dependency in case it is a CMake target.
  744. std::string dep = this->GetRealDependency
  745. (d->c_str(), this->ConfigurationName.c_str());
  746. depends.push_back(dep);
  747. }
  748. }
  749. //----------------------------------------------------------------------------
  750. void
  751. cmLocalUnixMakefileGenerator3
  752. ::AppendCustomCommands(std::vector<std::string>& commands,
  753. const std::vector<cmCustomCommand>& ccs)
  754. {
  755. for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
  756. i != ccs.end(); ++i)
  757. {
  758. this->AppendCustomCommand(commands, *i);
  759. }
  760. }
  761. //----------------------------------------------------------------------------
  762. void
  763. cmLocalUnixMakefileGenerator3
  764. ::AppendCustomCommand(std::vector<std::string>& commands,
  765. const cmCustomCommand& cc)
  766. {
  767. // if the command specified a working directory use it.
  768. const char* dir = this->Makefile->GetStartOutputDirectory();
  769. const char* workingDir = cc.GetWorkingDirectory();
  770. if(workingDir)
  771. {
  772. dir = workingDir;
  773. }
  774. // Add each command line to the set of commands.
  775. std::vector<std::string> commands1;
  776. for(cmCustomCommandLines::const_iterator cl = cc.GetCommandLines().begin();
  777. cl != cc.GetCommandLines().end(); ++cl)
  778. {
  779. // Build the command line in a single string.
  780. const cmCustomCommandLine& commandLine = *cl;
  781. std::string cmd = commandLine[0];
  782. if (cmd.size())
  783. {
  784. cmSystemTools::ReplaceString(cmd, "/./", "/");
  785. // Convert the command to a relative path only if the current
  786. // working directory will be the start-output directory.
  787. if(!workingDir)
  788. {
  789. cmd = this->Convert(cmd.c_str(),START_OUTPUT);
  790. }
  791. if(cmd.find("/") == cmd.npos &&
  792. commandLine[0].find("/") != cmd.npos)
  793. {
  794. // Add a leading "./" for executables in the current directory.
  795. cmd = "./" + cmd;
  796. }
  797. cmd = this->Convert(cmd.c_str(),NONE,SHELL);
  798. for(unsigned int j=1; j < commandLine.size(); ++j)
  799. {
  800. cmd += " ";
  801. bool forceOn = cmSystemTools::GetForceUnixPaths();
  802. if(forceOn && this->WindowsShell)
  803. {
  804. cmSystemTools::SetForceUnixPaths(false);
  805. }
  806. cmd += cmSystemTools::EscapeSpaces(commandLine[j].c_str());
  807. if(forceOn && this->WindowsShell)
  808. {
  809. cmSystemTools::SetForceUnixPaths(true);
  810. }
  811. }
  812. commands1.push_back(cmd);
  813. }
  814. }
  815. // Setup the proper working directory for the commands.
  816. this->CreateCDCommand(commands1, dir,
  817. this->Makefile->GetHomeOutputDirectory());
  818. // push back the custom commands
  819. commands.insert(commands.end(), commands1.begin(), commands1.end());
  820. }
  821. //----------------------------------------------------------------------------
  822. void
  823. cmLocalUnixMakefileGenerator3
  824. ::AppendCleanCommand(std::vector<std::string>& commands,
  825. const std::vector<std::string>& files,
  826. cmTarget& target, const char* filename)
  827. {
  828. if(!files.empty())
  829. {
  830. std::string cleanfile = this->Makefile->GetCurrentOutputDirectory();
  831. cleanfile += "/";
  832. cleanfile += this->GetTargetDirectory(target);
  833. cleanfile += "/cmake_clean";
  834. if(filename)
  835. {
  836. cleanfile += "_";
  837. cleanfile += filename;
  838. }
  839. cleanfile += ".cmake";
  840. std::string cleanfilePath = this->Convert(cleanfile.c_str(), FULL);
  841. std::ofstream fout(cleanfilePath.c_str());
  842. if(!fout)
  843. {
  844. cmSystemTools::Error("Could not create ", cleanfilePath.c_str());
  845. }
  846. fout << "FILE(REMOVE\n";
  847. std::string remove = "$(CMAKE_COMMAND) -P ";
  848. remove += this->Convert(cleanfile.c_str(), START_OUTPUT, SHELL);
  849. for(std::vector<std::string>::const_iterator f = files.begin();
  850. f != files.end(); ++f)
  851. {
  852. fout << "\"" << this->Convert(f->c_str(),START_OUTPUT,UNCHANGED)
  853. << "\"\n";
  854. }
  855. fout << ")\n";
  856. commands.push_back(remove);
  857. }
  858. }
  859. //----------------------------------------------------------------------------
  860. void
  861. cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
  862. const char* text,
  863. EchoColor color)
  864. {
  865. // Choose the color for the text.
  866. std::string color_name;
  867. #ifdef CMAKE_BUILD_WITH_CMAKE
  868. if(this->GlobalGenerator->GetToolSupportsColor() && this->ColorMakefile)
  869. {
  870. // See cmake::ExecuteEchoColor in cmake.cxx for these options.
  871. // This color set is readable on both black and white backgrounds.
  872. switch(color)
  873. {
  874. case EchoNormal:
  875. break;
  876. case EchoDepend:
  877. color_name = "--magenta --bold ";
  878. break;
  879. case EchoBuild:
  880. color_name = "--green ";
  881. break;
  882. case EchoLink:
  883. color_name = "--red --bold ";
  884. break;
  885. case EchoGenerate:
  886. color_name = "--blue --bold ";
  887. break;
  888. case EchoGlobal:
  889. color_name = "--cyan ";
  890. break;
  891. }
  892. }
  893. #else
  894. (void)color;
  895. #endif
  896. // Echo one line at a time.
  897. std::string line;
  898. line.reserve(200);
  899. for(const char* c = text;; ++c)
  900. {
  901. if(*c == '\n' || *c == '\0')
  902. {
  903. // Avoid writing a blank last line on end-of-string.
  904. if(*c != '\0' || !line.empty())
  905. {
  906. // Add a command to echo this line.
  907. std::string cmd;
  908. if(color_name.empty())
  909. {
  910. // Use the native echo command.
  911. cmd = "@echo ";
  912. if(this->EchoNeedsQuote)
  913. {
  914. cmd += "\"";
  915. }
  916. cmd += line;
  917. if(this->EchoNeedsQuote)
  918. {
  919. cmd += "\"";
  920. }
  921. }
  922. else
  923. {
  924. // Use cmake to echo the text in color.
  925. cmd = "@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) ";
  926. cmd += color_name;
  927. cmd += "\"";
  928. cmd += line;
  929. cmd += "\"";
  930. }
  931. commands.push_back(cmd);
  932. }
  933. // Reset the line to emtpy.
  934. line = "";
  935. // Terminate on end-of-string.
  936. if(*c == '\0')
  937. {
  938. return;
  939. }
  940. }
  941. else if(*c != '\r')
  942. {
  943. // Append this character to the current line.
  944. line += *c;
  945. }
  946. }
  947. }
  948. //----------------------------------------------------------------------------
  949. //take a tgt path and convert it into a make target, it could be full, or
  950. //relative
  951. std::string cmLocalUnixMakefileGenerator3
  952. ::ConvertToMakeTarget(const char* tgt)
  953. {
  954. // Make targets should not have a leading './' for a file in the
  955. // directory containing the makefile.
  956. std::string ret = tgt;
  957. if(ret.size() > 2 && (ret[0] == '.') &&
  958. ( (ret[1] == '/') || ret[1] == '\\'))
  959. {
  960. std::string upath = ret;
  961. cmSystemTools::ConvertToUnixSlashes(upath);
  962. if(upath.find(2, '/') == upath.npos)
  963. {
  964. ret = ret.substr(2, ret.size()-2);
  965. }
  966. }
  967. return ret;
  968. }
  969. //----------------------------------------------------------------------------
  970. std::string
  971. cmLocalUnixMakefileGenerator3
  972. ::CreateMakeVariable(const char* sin, const char* s2in)
  973. {
  974. std::string s = sin;
  975. std::string s2 = s2in;
  976. std::string unmodified = s;
  977. unmodified += s2;
  978. // if there is no restriction on the length of make variables
  979. // and there are no "." charactors in the string, then return the
  980. // unmodified combination.
  981. if((!this->MakefileVariableSize && unmodified.find('.') == s.npos)
  982. && (!this->MakefileVariableSize && unmodified.find('-') == s.npos))
  983. {
  984. return unmodified;
  985. }
  986. // see if the variable has been defined before and return
  987. // the modified version of the variable
  988. std::map<cmStdString, cmStdString>::iterator i =
  989. this->MakeVariableMap.find(unmodified);
  990. if(i != this->MakeVariableMap.end())
  991. {
  992. return i->second;
  993. }
  994. // start with the unmodified variable
  995. std::string ret = unmodified;
  996. // if this there is no value for this->MakefileVariableSize then
  997. // the string must have bad characters in it
  998. if(!this->MakefileVariableSize)
  999. {
  1000. cmSystemTools::ReplaceString(ret, ".", "_");
  1001. cmSystemTools::ReplaceString(ret, "-", "__");
  1002. int ni = 0;
  1003. char buffer[5];
  1004. // make sure the _ version is not already used, if
  1005. // it is used then add number to the end of the variable
  1006. while(this->ShortMakeVariableMap.count(ret) && ni < 1000)
  1007. {
  1008. ++ni;
  1009. sprintf(buffer, "%04d", ni);
  1010. ret = unmodified + buffer;
  1011. }
  1012. this->ShortMakeVariableMap[ret] = "1";
  1013. this->MakeVariableMap[unmodified] = ret;
  1014. return ret;
  1015. }
  1016. // if the string is greater the 32 chars it is an invalid vairable name
  1017. // for borland make
  1018. if(static_cast<int>(ret.size()) > this->MakefileVariableSize)
  1019. {
  1020. int keep = this->MakefileVariableSize - 8;
  1021. int size = keep + 3;
  1022. std::string str1 = s;
  1023. std::string str2 = s2;
  1024. // we must shorten the combined string by 4 charactors
  1025. // keep no more than 24 charactors from the second string
  1026. if(static_cast<int>(str2.size()) > keep)
  1027. {
  1028. str2 = str2.substr(0, keep);
  1029. }
  1030. if(static_cast<int>(str1.size()) + static_cast<int>(str2.size()) > size)
  1031. {
  1032. str1 = str1.substr(0, size - str2.size());
  1033. }
  1034. char buffer[5];
  1035. int ni = 0;
  1036. sprintf(buffer, "%04d", ni);
  1037. ret = str1 + str2 + buffer;
  1038. while(this->ShortMakeVariableMap.count(ret) && ni < 1000)
  1039. {
  1040. ++ni;
  1041. sprintf(buffer, "%04d", ni);
  1042. ret = str1 + str2 + buffer;
  1043. }
  1044. if(ni == 1000)
  1045. {
  1046. cmSystemTools::Error("Borland makefile variable length too long");
  1047. return unmodified;
  1048. }
  1049. // once an unused variable is found
  1050. this->ShortMakeVariableMap[ret] = "1";
  1051. }
  1052. // always make an entry into the unmodified to variable map
  1053. this->MakeVariableMap[unmodified] = ret;
  1054. return ret;
  1055. }
  1056. //----------------------------------------------------------------------------
  1057. bool cmLocalUnixMakefileGenerator3::ScanDependencies(const char* tgtInfo)
  1058. {
  1059. // The info file for this target
  1060. std::string const& infoFile = tgtInfo;
  1061. // Read the directory information file.
  1062. cmMakefile* mf = this->Makefile;
  1063. bool haveDirectoryInfo = false;
  1064. std::string dirInfoFile = this->Makefile->GetStartOutputDirectory();
  1065. dirInfoFile += cmake::GetCMakeFilesDirectory();
  1066. dirInfoFile += "/CMakeDirectoryInformation.cmake";
  1067. if(mf->ReadListFile(0, dirInfoFile.c_str()) &&
  1068. !cmSystemTools::GetErrorOccuredFlag())
  1069. {
  1070. haveDirectoryInfo = true;
  1071. }
  1072. // read in the target info file
  1073. if(!mf->ReadListFile(0, infoFile.c_str()) ||
  1074. cmSystemTools::GetErrorOccuredFlag())
  1075. {
  1076. cmSystemTools::Error("Target DependInfo.cmake file not found");
  1077. }
  1078. // Test whether we need to force Unix paths.
  1079. if(haveDirectoryInfo)
  1080. {
  1081. if(const char* force = mf->GetDefinition("CMAKE_FORCE_UNIX_PATHS"))
  1082. {
  1083. if(!cmSystemTools::IsOff(force))
  1084. {
  1085. cmSystemTools::SetForceUnixPaths(true);
  1086. }
  1087. }
  1088. }
  1089. else
  1090. {
  1091. cmSystemTools::Error("Directory Information file not found");
  1092. }
  1093. // create the file stream for the depends file
  1094. std::string dir = cmSystemTools::GetFilenamePath(infoFile);
  1095. // Open the rule file. This should be copy-if-different because the
  1096. // rules may depend on this file itself.
  1097. std::string ruleFileNameFull = dir;
  1098. ruleFileNameFull += "/depend.make";
  1099. cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
  1100. ruleFileStream.SetCopyIfDifferent(true);
  1101. if(!ruleFileStream)
  1102. {
  1103. return false;
  1104. }
  1105. std::string internalRuleFileNameFull = dir;
  1106. internalRuleFileNameFull += "/depend.internal";
  1107. cmGeneratedFileStream
  1108. internalRuleFileStream(internalRuleFileNameFull.c_str());
  1109. internalRuleFileStream.SetCopyIfDifferent(true);
  1110. if(!internalRuleFileStream)
  1111. {
  1112. return false;
  1113. }
  1114. this->WriteDisclaimer(ruleFileStream);
  1115. this->WriteDisclaimer(internalRuleFileStream);
  1116. // Get the set of generated files.
  1117. std::vector<std::string> generatedFilesVec;
  1118. if(haveDirectoryInfo)
  1119. {
  1120. if(const char* generated = mf->GetDefinition("CMAKE_GENERATED_FILES"))
  1121. {
  1122. cmSystemTools::ExpandListArgument(generated, generatedFilesVec);
  1123. }
  1124. }
  1125. // Sort for efficient lookup.
  1126. std::set<cmStdString> generatedFiles;
  1127. for(std::vector<std::string>::iterator gfi = generatedFilesVec.begin();
  1128. gfi != generatedFilesVec.end(); ++gfi)
  1129. {
  1130. generatedFiles.insert(*gfi);
  1131. }
  1132. // for each language we need to scan, scan it
  1133. const char *langStr = mf->GetSafeDefinition("CMAKE_DEPENDS_LANGUAGES");
  1134. std::vector<std::string> langs;
  1135. cmSystemTools::ExpandListArgument(langStr, langs);
  1136. for (std::vector<std::string>::iterator li =
  1137. langs.begin(); li != langs.end(); ++li)
  1138. {
  1139. // construct the checker
  1140. std::string lang = li->c_str();
  1141. // Get the set of include directories.
  1142. std::vector<std::string> includes;
  1143. if(haveDirectoryInfo)
  1144. {
  1145. std::string includePathVar = "CMAKE_";
  1146. includePathVar += lang;
  1147. includePathVar += "_INCLUDE_PATH";
  1148. if(const char* includePath = mf->GetDefinition(includePathVar.c_str()))
  1149. {
  1150. cmSystemTools::ExpandListArgument(includePath, includes);
  1151. }
  1152. }
  1153. // Get the include file regular expression.
  1154. std::string includeRegexScan = "^.*$";
  1155. std::string includeRegexComplain = "^$";
  1156. if(haveDirectoryInfo)
  1157. {
  1158. std::string scanRegexVar = "CMAKE_";
  1159. scanRegexVar += lang;
  1160. scanRegexVar += "_INCLUDE_REGEX_SCAN";
  1161. if(const char* scanRegex = mf->GetDefinition(scanRegexVar.c_str()))
  1162. {
  1163. includeRegexScan = scanRegex;
  1164. }
  1165. std::string complainRegexVar = "CMAKE_";
  1166. complainRegexVar += lang;
  1167. complainRegexVar += "_INCLUDE_REGEX_COMPLAIN";
  1168. if(const char* complainRegex =
  1169. mf->GetDefinition(complainRegexVar.c_str()))
  1170. {
  1171. includeRegexComplain = complainRegex;
  1172. }
  1173. }
  1174. // Create the scanner for this language
  1175. cmDepends *scanner = 0;
  1176. if(lang == "C" || lang == "CXX" || lang == "RC")
  1177. {
  1178. std::string includeCacheFileName = dir;
  1179. includeCacheFileName += "/includecache.";
  1180. includeCacheFileName += lang;
  1181. // TODO: Handle RC (resource files) dependencies correctly.
  1182. scanner = new cmDependsC(includes,
  1183. includeRegexScan.c_str(),
  1184. includeRegexComplain.c_str(),
  1185. generatedFiles, includeCacheFileName);
  1186. scanner->SetLocalGenerator(this);
  1187. }
  1188. #ifdef CMAKE_BUILD_WITH_CMAKE
  1189. else if(lang == "Fortran")
  1190. {
  1191. scanner = new cmDependsFortran(includes);
  1192. }
  1193. else if(lang == "Java")
  1194. {
  1195. scanner = new cmDependsJava();
  1196. }
  1197. #endif
  1198. if (scanner)
  1199. {
  1200. scanner->SetFileComparison
  1201. (this->GlobalGenerator->GetCMakeInstance()->GetFileComparison());
  1202. // for each file we need to scan
  1203. std::string srcLang = "CMAKE_DEPENDS_CHECK_";
  1204. srcLang += lang;
  1205. const char *srcStr = mf->GetSafeDefinition(srcLang.c_str());
  1206. std::vector<std::string> srcs;
  1207. cmSystemTools::ExpandListArgument(srcStr, srcs);
  1208. for (std::vector<std::string>::iterator si =
  1209. srcs.begin(); si != srcs.end(); ++si)
  1210. {
  1211. std::string &src = *si;
  1212. ++si;
  1213. // make sure the object file is relative to home output
  1214. std::string obj = *si;
  1215. obj = this->Convert(obj.c_str(),HOME_OUTPUT,MAKEFILE);
  1216. scanner->Write(src.c_str(),obj.c_str(),
  1217. ruleFileStream, internalRuleFileStream);
  1218. }
  1219. // free the scanner for this language
  1220. delete scanner;
  1221. }
  1222. }
  1223. // dependencies were generated, so touch the mark file
  1224. ruleFileNameFull += ".mark";
  1225. std::ofstream fmark(ruleFileNameFull.c_str());
  1226. fmark << "Dependencies updated>" << std::endl;
  1227. return true;
  1228. }
  1229. //----------------------------------------------------------------------------
  1230. void cmLocalUnixMakefileGenerator3
  1231. ::WriteLocalAllRules(std::ostream& ruleFileStream)
  1232. {
  1233. this->WriteDisclaimer(ruleFileStream);
  1234. this->WriteMakeVariables(ruleFileStream);
  1235. // Write the main entry point target. This must be the VERY first
  1236. // target so that make with no arguments will run it.
  1237. {
  1238. // Just depend on the all target to drive the build.
  1239. std::vector<std::string> depends;
  1240. std::vector<std::string> no_commands;
  1241. depends.push_back("all");
  1242. // Write the rule.
  1243. this->WriteMakeRule(ruleFileStream,
  1244. "Default target executed when no arguments are "
  1245. "given to make.",
  1246. "default_target",
  1247. depends,
  1248. no_commands, true);
  1249. }
  1250. // Write all global targets
  1251. cmTargets* targets = &(this->Makefile->GetTargets());
  1252. cmTargets::iterator glIt;
  1253. for ( glIt = targets->begin(); glIt != targets->end(); ++ glIt )
  1254. {
  1255. if ( glIt->second.GetType() == cmTarget::GLOBAL_TARGET )
  1256. {
  1257. std::string targetString = "Special rule for the target " + glIt->first;
  1258. std::vector<std::string> commands;
  1259. std::vector<std::string> depends;
  1260. const char* text = glIt->second.GetProperty("EchoString");
  1261. if ( !text )
  1262. {
  1263. text = "Running external command ...";
  1264. }
  1265. std::set<cmStdString>::const_iterator dit;
  1266. for ( dit = glIt->second.GetUtilities().begin();
  1267. dit != glIt->second.GetUtilities().end();
  1268. ++ dit )
  1269. {
  1270. depends.push_back(dit->c_str());
  1271. }
  1272. this->AppendEcho(commands, text,
  1273. cmLocalUnixMakefileGenerator3::EchoGlobal);
  1274. // Global targets store their rules in pre- and post-build commands.
  1275. this->AppendCustomDepends(depends,
  1276. glIt->second.GetPreBuildCommands());
  1277. this->AppendCustomDepends(depends,
  1278. glIt->second.GetPostBuildCommands());
  1279. this->AppendCustomCommands(commands,
  1280. glIt->second.GetPreBuildCommands());
  1281. this->AppendCustomCommands(commands,
  1282. glIt->second.GetPostBuildCommands());
  1283. std::string targetName = glIt->second.GetName();
  1284. this->WriteMakeRule(ruleFileStream, targetString.c_str(),
  1285. targetName.c_str(), depends, commands, true);
  1286. // Provide a "/fast" version of the target.
  1287. depends.clear();
  1288. if(targetName == "install")
  1289. {
  1290. // Provide a fast install target that does not depend on all
  1291. // but has the same command.
  1292. depends.push_back("preinstall/fast");
  1293. }
  1294. else
  1295. {
  1296. // Just forward to the real target so at least it will work.
  1297. depends.push_back(targetName);
  1298. commands.clear();
  1299. }
  1300. targetName += "/fast";
  1301. this->WriteMakeRule(ruleFileStream, targetString.c_str(),
  1302. targetName.c_str(), depends, commands, true);
  1303. }
  1304. }
  1305. this->WriteSpecialTargetsTop(ruleFileStream);
  1306. std::vector<std::string> depends;
  1307. std::vector<std::string> commands;
  1308. // Write the all rule.
  1309. std::string dir = this->Makefile->GetStartOutputDirectory();
  1310. dir += "/all";
  1311. dir = this->Convert(dir.c_str(),HOME_OUTPUT,MAKEFILE);
  1312. depends.push_back("cmake_check_build_system");
  1313. std::string progressDir = this->Makefile->GetHomeOutputDirectory();
  1314. progressDir += cmake::GetCMakeFilesDirectory();
  1315. {
  1316. cmOStringStream progCmd;
  1317. progCmd <<
  1318. "$(CMAKE_COMMAND) -E cmake_progress_start ";
  1319. progCmd << this->Convert(progressDir.c_str(),
  1320. cmLocalGenerator::FULL,
  1321. cmLocalGenerator::SHELL);
  1322. progCmd << " $(CMAKE_ALL_PROGRESS)";
  1323. commands.push_back(progCmd.str());
  1324. }
  1325. std::string mf2Dir = cmake::GetCMakeFilesDirectoryPostSlash();
  1326. mf2Dir += "Makefile2";
  1327. commands.push_back(this->GetRecursiveMakeCall(mf2Dir.c_str(),
  1328. dir.c_str()));
  1329. this->CreateCDCommand(commands,
  1330. this->Makefile->GetHomeOutputDirectory(),
  1331. this->Makefile->GetStartOutputDirectory());
  1332. {
  1333. cmOStringStream progCmd;
  1334. progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start "; // # 0
  1335. progCmd << this->Convert(progressDir.c_str(),
  1336. cmLocalGenerator::FULL,
  1337. cmLocalGenerator::SHELL);
  1338. progCmd << " 0";
  1339. commands.push_back(progCmd.str());
  1340. }
  1341. this->WriteMakeRule(ruleFileStream, "The main all target", "all",
  1342. depends, commands, true);
  1343. // Write the clean rule.
  1344. dir = this->Makefile->GetStartOutputDirectory();
  1345. dir += "/clean";
  1346. dir = this->Convert(dir.c_str(),HOME_OUTPUT,MAKEFILE);
  1347. commands.clear();
  1348. depends.clear();
  1349. commands.push_back(this->GetRecursiveMakeCall(mf2Dir.c_str(),
  1350. dir.c_str()));
  1351. this->CreateCDCommand(commands,
  1352. this->Makefile->GetHomeOutputDirectory(),
  1353. this->Makefile->GetStartOutputDirectory());
  1354. this->WriteMakeRule(ruleFileStream, "The main clean target", "clean",
  1355. depends, commands, true);
  1356. commands.clear();
  1357. depends.clear();
  1358. depends.push_back("clean");
  1359. this->WriteMakeRule(ruleFileStream, "The main clean target", "clean/fast",
  1360. depends, commands, true);
  1361. // Write the preinstall rule.
  1362. dir = this->Makefile->GetStartOutputDirectory();
  1363. dir += "/preinstall";
  1364. dir = this->Convert(dir.c_str(), HOME_OUTPUT,MAKEFILE);
  1365. commands.clear();
  1366. depends.clear();
  1367. const char* noall =
  1368. this->Makefile->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
  1369. if(!noall || cmSystemTools::IsOff(noall))
  1370. {
  1371. // Drive the build before installing.
  1372. depends.push_back("all");
  1373. }
  1374. else
  1375. {
  1376. // At least make sure the build system is up to date.
  1377. depends.push_back("cmake_check_build_system");
  1378. }
  1379. commands.push_back
  1380. (this->GetRecursiveMakeCall(mf2Dir.c_str(), dir.c_str()));
  1381. this->CreateCDCommand(commands,
  1382. this->Makefile->GetHomeOutputDirectory(),
  1383. this->Makefile->GetStartOutputDirectory());
  1384. this->WriteMakeRule(ruleFileStream, "Prepare targets for installation.",
  1385. "preinstall", depends, commands, true);
  1386. depends.clear();
  1387. this->WriteMakeRule(ruleFileStream, "Prepare targets for installation.",
  1388. "preinstall/fast", depends, commands, true);
  1389. // write the depend rule, really a recompute depends rule
  1390. depends.clear();
  1391. commands.clear();
  1392. std::string cmakefileName = cmake::GetCMakeFilesDirectoryPostSlash();
  1393. cmakefileName += "Makefile.cmake";
  1394. this->Convert(cmakefileName.c_str(),HOME_OUTPUT,
  1395. cmLocalGenerator::MAKEFILE);
  1396. std::string runRule =
  1397. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
  1398. runRule += " --check-build-system ";
  1399. runRule += this->Convert(cmakefileName.c_str(),cmLocalGenerator::NONE,
  1400. cmLocalGenerator::SHELL);
  1401. runRule += " 1";
  1402. commands.push_back(runRule);
  1403. this->WriteMakeRule(ruleFileStream, "clear depends",
  1404. "depend",
  1405. depends, commands, true);
  1406. }
  1407. //----------------------------------------------------------------------------
  1408. void cmLocalUnixMakefileGenerator3::CheckDependencies(cmMakefile* mf,
  1409. bool verbose,
  1410. bool clear)
  1411. {
  1412. // Get the list of target files to check
  1413. const char* infoDef = mf->GetDefinition("CMAKE_DEPEND_INFO_FILES");
  1414. if(!infoDef)
  1415. {
  1416. return;
  1417. }
  1418. std::vector<std::string> files;
  1419. cmSystemTools::ExpandListArgument(infoDef, files);
  1420. // For each info file run the check
  1421. cmDependsC checker;
  1422. checker.SetVerbose(verbose);
  1423. checker.SetFileComparison
  1424. (this->GlobalGenerator->GetCMakeInstance()->GetFileComparison());
  1425. for(std::vector<std::string>::iterator l = files.begin();
  1426. l != files.end(); ++l)
  1427. {
  1428. // either clear or check the files
  1429. std::string dir = cmSystemTools::GetFilenamePath(l->c_str());
  1430. std::string internalDependFile = dir + "/depend.internal";
  1431. std::string dependFile = dir + "/depend.make";
  1432. if (clear)
  1433. {
  1434. checker.Clear(internalDependFile.c_str());
  1435. checker.Clear(dependFile.c_str());
  1436. }
  1437. else
  1438. {
  1439. checker.Check(dependFile.c_str(), internalDependFile.c_str());
  1440. }
  1441. }
  1442. }
  1443. void cmLocalUnixMakefileGenerator3
  1444. ::WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &target)
  1445. {
  1446. // now write all the language stuff
  1447. // Set the set of files to check for dependency integrity.
  1448. std::set<cmStdString> checkSetLangs;
  1449. std::map<cmStdString,cmLocalUnixMakefileGenerator3::IntegrityCheckSet>&
  1450. checkSet = this->GetIntegrityCheckSet()[target.GetName()];
  1451. for(std::map<cmStdString,
  1452. cmLocalUnixMakefileGenerator3::IntegrityCheckSet>::const_iterator
  1453. l = checkSet.begin(); l != checkSet.end(); ++l)
  1454. {
  1455. checkSetLangs.insert(l->first);
  1456. }
  1457. // list the languages
  1458. cmakefileStream
  1459. << "# The set of files whose dependency integrity should be checked:\n";
  1460. cmakefileStream
  1461. << "SET(CMAKE_DEPENDS_LANGUAGES\n";
  1462. for(std::set<cmStdString>::iterator
  1463. l = checkSetLangs.begin(); l != checkSetLangs.end(); ++l)
  1464. {
  1465. cmakefileStream << " \"" << l->c_str() << "\"\n";
  1466. }
  1467. cmakefileStream << " )\n";
  1468. // now list the files for each language
  1469. for(std::set<cmStdString>::iterator
  1470. l = checkSetLangs.begin(); l != checkSetLangs.end(); ++l)
  1471. {
  1472. cmakefileStream
  1473. << "SET(CMAKE_DEPENDS_CHECK_" << l->c_str() << "\n";
  1474. // get the check set for this local gen and language
  1475. cmLocalUnixMakefileGenerator3::IntegrityCheckSet iCheckSet =
  1476. checkSet[*l];
  1477. // for each file
  1478. for(cmLocalUnixMakefileGenerator3::IntegrityCheckSet::const_iterator
  1479. csIter = iCheckSet.begin();
  1480. csIter != iCheckSet.end(); ++csIter)
  1481. {
  1482. cmakefileStream << " \"" << (*csIter)->GetFullPath() << "\"\n";
  1483. // Get the full path name of the object file.
  1484. std::string obj = this->Makefile->GetStartOutputDirectory();
  1485. obj += "/";
  1486. obj += this->GetObjectFileName(target, **csIter);
  1487. cmakefileStream << " \"" <<
  1488. this->Convert(obj.c_str(),
  1489. cmLocalGenerator::FULL).c_str() << "\"\n";
  1490. }
  1491. cmakefileStream << " )\n";
  1492. }
  1493. }
  1494. //----------------------------------------------------------------------------
  1495. std::string
  1496. cmLocalUnixMakefileGenerator3
  1497. ::GetObjectFileName(cmTarget& target,
  1498. const cmSourceFile& source,
  1499. std::string* nameWithoutTargetDir)
  1500. {
  1501. // Get the object file name independent of target.
  1502. std::string objectName = this->GetObjectFileNameWithoutTarget(source);
  1503. if(nameWithoutTargetDir)
  1504. {
  1505. *nameWithoutTargetDir = objectName;
  1506. }
  1507. // Prepend the target directory.
  1508. std::string obj;
  1509. const char* fileTargetDirectory =
  1510. source.GetProperty("MACOSX_PACKAGE_LOCATION");
  1511. if ( fileTargetDirectory )
  1512. {
  1513. objectName = cmSystemTools::GetFilenameName(objectName.c_str());
  1514. std::string targetName;
  1515. std::string targetNameReal;
  1516. target.GetExecutableNames(targetName, targetNameReal,
  1517. this->ConfigurationName.c_str());
  1518. if ( target.GetPropertyAsBool("MACOSX_BUNDLE") )
  1519. {
  1520. // Construct the full path version of the names.
  1521. obj = this->ExecutableOutputPath;
  1522. if(obj.empty())
  1523. {
  1524. obj = this->Makefile->GetStartOutputDirectory();
  1525. obj += "/";
  1526. }
  1527. obj += targetName + ".app/Contents/";
  1528. obj += fileTargetDirectory;
  1529. }
  1530. else
  1531. {
  1532. // Framework not handled yet
  1533. abort();
  1534. }
  1535. obj = cmSystemTools::RelativePath
  1536. (this->Makefile->GetHomeOutputDirectory(), obj.c_str());
  1537. }
  1538. else
  1539. {
  1540. obj = this->GetTargetDirectory(target);
  1541. }
  1542. obj += "/";
  1543. obj += objectName;
  1544. return obj;
  1545. }
  1546. //----------------------------------------------------------------------------
  1547. void cmLocalUnixMakefileGenerator3::WriteDisclaimer(std::ostream& os)
  1548. {
  1549. os
  1550. << "# CMAKE generated file: DO NOT EDIT!\n"
  1551. << "# Generated by \"" << this->GlobalGenerator->GetName() << "\""
  1552. << " Generator, CMake Version "
  1553. << cmMakefile::GetMajorVersion() << "."
  1554. << cmMakefile::GetMinorVersion() << "\n\n";
  1555. }
  1556. //----------------------------------------------------------------------------
  1557. std::string
  1558. cmLocalUnixMakefileGenerator3
  1559. ::GetRecursiveMakeCall(const char *makefile, const char* tgt)
  1560. {
  1561. // Call make on the given file.
  1562. std::string cmd;
  1563. cmd += "$(MAKE) -f ";
  1564. cmd += makefile;
  1565. cmd += " ";
  1566. // Passg down verbosity level.
  1567. if(this->GetMakeSilentFlag().size())
  1568. {
  1569. cmd += this->GetMakeSilentFlag();
  1570. cmd += " ";
  1571. }
  1572. // Most unix makes will pass the command line flags to make down to
  1573. // sub-invoked makes via an environment variable. However, some
  1574. // makes do not support that, so you have to pass the flags
  1575. // explicitly.
  1576. if(this->GetPassMakeflags())
  1577. {
  1578. cmd += "-$(MAKEFLAGS) ";
  1579. }
  1580. // Add the target.
  1581. if (tgt && tgt[0] != '\0')
  1582. {
  1583. std::string tgt2 = this->Convert(tgt,HOME_OUTPUT,MAKEFILE);
  1584. tgt2 = this->ConvertToMakeTarget(tgt2.c_str());
  1585. cmd += tgt2;
  1586. }
  1587. return cmd;
  1588. }
  1589. //----------------------------------------------------------------------------
  1590. void cmLocalUnixMakefileGenerator3::WriteDivider(std::ostream& os)
  1591. {
  1592. os
  1593. << "#======================================"
  1594. << "=======================================\n";
  1595. }
  1596. //----------------------------------------------------------------------------
  1597. void
  1598. cmLocalUnixMakefileGenerator3
  1599. ::WriteCMakeArgument(std::ostream& os, const char* s)
  1600. {
  1601. // Write the given string to the stream with escaping to get it back
  1602. // into CMake through the lexical scanner.
  1603. os << "\"";
  1604. for(const char* c = s; *c; ++c)
  1605. {
  1606. if(*c == '\\')
  1607. {
  1608. os << "\\\\";
  1609. }
  1610. else if(*c == '"')
  1611. {
  1612. os << "\\\"";
  1613. }
  1614. else
  1615. {
  1616. os << *c;
  1617. }
  1618. }
  1619. os << "\"";
  1620. }
  1621. //----------------------------------------------------------------------------
  1622. std::string
  1623. cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p)
  1624. {
  1625. // Split the path into its components.
  1626. std::vector<std::string> components;
  1627. cmSystemTools::SplitPath(p, components);
  1628. // Return an empty path if there are no components.
  1629. if(components.empty())
  1630. {
  1631. return "\"\"";
  1632. }
  1633. // Choose a slash direction and fix root component.
  1634. const char* slash = "/";
  1635. #if defined(_WIN32) && !defined(__CYGWIN__)
  1636. if(!cmSystemTools::GetForceUnixPaths())
  1637. {
  1638. slash = "\\";
  1639. for(std::string::iterator i = components[0].begin();
  1640. i != components[0].end(); ++i)
  1641. {
  1642. if(*i == '/')
  1643. {
  1644. *i = '\\';
  1645. }
  1646. }
  1647. }
  1648. #endif
  1649. // Begin the quoted result with the root component.
  1650. std::string result = "\"";
  1651. result += components[0];
  1652. // Now add the rest of the components separated by the proper slash
  1653. // direction for this platform.
  1654. bool first = true;
  1655. for(unsigned int i=1; i < components.size(); ++i)
  1656. {
  1657. // Only the last component can be empty to avoid double slashes.
  1658. if(components[i].length() > 0 || (i == (components.size()-1)))
  1659. {
  1660. if(!first)
  1661. {
  1662. result += slash;
  1663. }
  1664. result += components[i];
  1665. first = false;
  1666. }
  1667. }
  1668. // Close the quoted result.
  1669. result += "\"";
  1670. return result;
  1671. }
  1672. //----------------------------------------------------------------------------
  1673. std::string
  1674. cmLocalUnixMakefileGenerator3::GetTargetDirectory(cmTarget& target)
  1675. {
  1676. std::string dir = cmake::GetCMakeFilesDirectoryPostSlash();
  1677. dir += target.GetName();
  1678. dir += ".dir";
  1679. return dir;
  1680. }
  1681. void cmLocalUnixMakefileGenerator3
  1682. ::CreateCDCommand(std::vector<std::string>& commands, const char *tgtDir,
  1683. const char *retDir)
  1684. {
  1685. // do we need to cd?
  1686. if (!strcmp(tgtDir,retDir))
  1687. {
  1688. return;
  1689. }
  1690. if(!this->UnixCD)
  1691. {
  1692. // On Windows we must perform each step separately and then change
  1693. // back because the shell keeps the working directory between
  1694. // commands.
  1695. std::string cmd = "cd ";
  1696. cmd += this->ConvertToOutputForExisting(tgtDir);
  1697. commands.insert(commands.begin(),cmd);
  1698. // Change back to the starting directory. Any trailing slash must be
  1699. // removed to avoid problems with Borland Make.
  1700. std::string back = retDir;
  1701. if(back.size() && back[back.size()-1] == '/')
  1702. {
  1703. back = back.substr(0, back.size()-1);
  1704. }
  1705. cmd = "cd ";
  1706. cmd += this->ConvertToOutputForExisting(back.c_str());
  1707. commands.push_back(cmd);
  1708. }
  1709. else
  1710. {
  1711. // On UNIX we must construct a single shell command to change
  1712. // directory and build because make resets the directory between
  1713. // each command.
  1714. std::vector<std::string>::iterator i = commands.begin();
  1715. for (; i != commands.end(); ++i)
  1716. {
  1717. std::string cmd = "cd ";
  1718. cmd += this->ConvertToOutputForExisting(tgtDir);
  1719. cmd += " && ";
  1720. cmd += *i;
  1721. *i = cmd;
  1722. }
  1723. }
  1724. }
  1725. //----------------------------------------------------------------------------
  1726. const char*
  1727. cmLocalUnixMakefileGenerator3
  1728. ::GetSourceFileLanguage(const cmSourceFile& source)
  1729. {
  1730. const char* lang = source.GetProperty("LANGUAGE");
  1731. if ( lang )
  1732. {
  1733. return lang;
  1734. }
  1735. // Identify the language of the source file.
  1736. return (this->GlobalGenerator
  1737. ->GetLanguageFromExtension(source.GetSourceExtension().c_str()));
  1738. }