cmLocalUnixMakefileGenerator3.cxx 59 KB

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