cmLocalUnixMakefileGenerator3.cxx 63 KB

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