cmLocalUnixMakefileGenerator3.cxx 58 KB

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