cmLocalUnixMakefileGenerator3.cxx 66 KB

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