cmLocalUnixMakefileGenerator3.cxx 60 KB

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