cmLocalUnixMakefileGenerator3.cxx 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001
  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 "cmGlobalGenerator.h"
  17. #include "cmMakefile.h"
  18. #include "cmSourceFile.h"
  19. #include "cmake.h"
  20. // Include dependency scanners for supported languages. Only the
  21. // C/C++ scanner is needed for bootstrapping CMake.
  22. #include "cmDependsC.h"
  23. #ifdef CMAKE_BUILD_WITH_CMAKE
  24. # include "cmDependsFortran.h"
  25. # include "cmDependsJava.h"
  26. #endif
  27. #include <memory> // auto_ptr
  28. #include <queue>
  29. // TODO: Add "help" target.
  30. // TODO: Identify remaining relative path violations.
  31. // TODO: Need test for separate executable/library output path.
  32. //----------------------------------------------------------------------------
  33. cmLocalUnixMakefileGenerator3::cmLocalUnixMakefileGenerator3()
  34. {
  35. m_WindowsShell = false;
  36. m_IncludeDirective = "include";
  37. m_MakefileVariableSize = 0;
  38. m_IgnoreLibPrefix = false;
  39. m_PassMakeflags = false;
  40. m_EchoNeedsQuote = true;
  41. }
  42. //----------------------------------------------------------------------------
  43. cmLocalUnixMakefileGenerator3::~cmLocalUnixMakefileGenerator3()
  44. {
  45. }
  46. //----------------------------------------------------------------------------
  47. void cmLocalUnixMakefileGenerator3::Configure()
  48. {
  49. this->ComputeHomeRelativeOutputPath();
  50. this->cmLocalGenerator::Configure();
  51. }
  52. //----------------------------------------------------------------------------
  53. void cmLocalUnixMakefileGenerator3::Generate()
  54. {
  55. // Setup our configuration variables for this directory.
  56. this->ConfigureOutputPaths();
  57. // Generate the rule files for each target.
  58. cmTargets& targets = m_Makefile->GetTargets();
  59. std::string empty;
  60. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  61. {
  62. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  63. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  64. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  65. (t->second.GetType() == cmTarget::MODULE_LIBRARY))
  66. {
  67. t->second.TraceVSDependencies(empty, m_Makefile);
  68. this->WriteTargetRuleFiles(t->second);
  69. }
  70. else if(t->second.GetType() == cmTarget::UTILITY)
  71. {
  72. t->second.TraceVSDependencies(empty, m_Makefile);
  73. this->WriteUtilityRuleFiles(t->second);
  74. }
  75. }
  76. // write the local Makefile
  77. this->WriteLocalMakefile();
  78. // Write the cmake file with information for this directory.
  79. this->WriteDirectoryInformationFile();
  80. // all custom commands used?
  81. const std::vector<cmSourceFile*> &srcs = m_Makefile->GetSourceFiles();
  82. std::vector<cmSourceFile*>::const_iterator sit = srcs.begin();
  83. for (;sit != srcs.end(); ++sit)
  84. {
  85. if ((*sit)->GetCustomCommand() && !(*sit)->GetCustomCommand()->IsUsed())
  86. {
  87. cmOStringStream err;
  88. err << "Warning: Custom command for source file "
  89. << (*sit)->GetSourceName().c_str() << "."
  90. << (*sit)->GetSourceExtension().c_str()
  91. << " was not used.";
  92. cmSystemTools::Message(err.str().c_str(), "Warning");
  93. }
  94. }
  95. }
  96. //----------------------------------------------------------------------------
  97. void cmLocalUnixMakefileGenerator3::ConfigureOutputPaths()
  98. {
  99. // Format the library and executable output paths.
  100. if(const char* libOut = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  101. {
  102. m_LibraryOutputPath = libOut;
  103. this->FormatOutputPath(m_LibraryOutputPath, "LIBRARY");
  104. }
  105. if(const char* exeOut = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  106. {
  107. m_ExecutableOutputPath = exeOut;
  108. this->FormatOutputPath(m_ExecutableOutputPath, "EXECUTABLE");
  109. }
  110. }
  111. //----------------------------------------------------------------------------
  112. void cmLocalUnixMakefileGenerator3::FormatOutputPath(std::string& path,
  113. const char* name)
  114. {
  115. if(!path.empty())
  116. {
  117. // Convert the output path to a full path in case it is
  118. // specified as a relative path. Treat a relative path as
  119. // relative to the current output directory for this makefile.
  120. path =
  121. cmSystemTools::CollapseFullPath(path.c_str(),
  122. m_Makefile->GetStartOutputDirectory());
  123. // Add a trailing slash for easy appending later.
  124. if(path.empty() || path[path.size()-1] != '/')
  125. {
  126. path += "/";
  127. }
  128. // Make sure the output path exists on disk.
  129. if(!cmSystemTools::MakeDirectory(path.c_str()))
  130. {
  131. cmSystemTools::Error("Error failed to create ",
  132. name, "_OUTPUT_PATH directory:", path.c_str());
  133. }
  134. // Add this as a link directory automatically.
  135. m_Makefile->AddLinkDirectory(path.c_str());
  136. }
  137. }
  138. void cmLocalUnixMakefileGenerator3
  139. ::WriteCustomCommands(cmTarget &target,std::ostream& ruleFileStream,
  140. std::vector<std::string>& cleanFiles)
  141. {
  142. std::string tgtDir = m_Makefile->GetStartOutputDirectory();
  143. tgtDir += "/";
  144. tgtDir += this->GetTargetDirectory(target);
  145. // add custom commands to the clean rules?
  146. const char* clean_no_custom = m_Makefile->GetProperty("CLEAN_NO_CUSTOM");
  147. bool clean = cmSystemTools::IsOff(clean_no_custom);
  148. // Generate the rule files for each custom command.
  149. // get the classes from the source lists then add them to the groups
  150. const std::vector<cmSourceFile*> &classes = target.GetSourceFiles();
  151. std::string objTarget;
  152. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  153. i != classes.end(); i++)
  154. {
  155. if(cmCustomCommand* cc = (*i)->GetCustomCommand())
  156. {
  157. cc->Used();
  158. objTarget = this->GenerateCustomRuleFile(*cc,tgtDir.c_str());
  159. if (clean)
  160. {
  161. cleanFiles.push_back
  162. (this->Convert(cc->GetOutput(),HOME_OUTPUT,SHELL));
  163. }
  164. ruleFileStream
  165. << m_IncludeDirective << " "
  166. << this->ConvertToOutputForExisting(objTarget.c_str()).c_str()
  167. << "\n";
  168. }
  169. }
  170. }
  171. //----------------------------------------------------------------------------
  172. void cmLocalUnixMakefileGenerator3::WriteDirectoryInformationFile()
  173. {
  174. std::string infoFileName = m_Makefile->GetStartOutputDirectory();
  175. infoFileName += "/CMakeDirectoryInformation.cmake";
  176. // Open the output file.
  177. cmGeneratedFileStream infoFileStream(infoFileName.c_str());
  178. if(!infoFileStream)
  179. {
  180. return;
  181. }
  182. // Write the do not edit header.
  183. this->WriteDisclaimer(infoFileStream);
  184. // Tell the dependency scanner to use unix paths if necessary.
  185. if(cmSystemTools::GetForceUnixPaths())
  186. {
  187. infoFileStream
  188. << "# Force unix paths in dependencies.\n"
  189. << "SET(CMAKE_FORCE_UNIX_PATHS 1)\n"
  190. << "\n";
  191. }
  192. // Store the include search path for this directory.
  193. infoFileStream
  194. << "# The C and CXX include file search paths:\n";
  195. infoFileStream
  196. << "SET(CMAKE_C_INCLUDE_PATH\n";
  197. std::vector<std::string> includeDirs;
  198. this->GetIncludeDirectories(includeDirs);
  199. for(std::vector<std::string>::iterator i = includeDirs.begin();
  200. i != includeDirs.end(); ++i)
  201. {
  202. infoFileStream
  203. << " \"" << this->Convert(i->c_str(),HOME_OUTPUT).c_str() << "\"\n";
  204. }
  205. infoFileStream
  206. << " )\n";
  207. infoFileStream
  208. << "SET(CMAKE_CXX_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH})\n";
  209. // Store the include regular expressions for this directory.
  210. infoFileStream
  211. << "\n"
  212. << "# The C and CXX include file regular expressions for this directory.\n";
  213. infoFileStream
  214. << "SET(CMAKE_C_INCLUDE_REGEX_SCAN ";
  215. this->WriteCMakeArgument(infoFileStream,
  216. m_Makefile->GetIncludeRegularExpression());
  217. infoFileStream
  218. << ")\n";
  219. infoFileStream
  220. << "SET(CMAKE_C_INCLUDE_REGEX_COMPLAIN ";
  221. this->WriteCMakeArgument(infoFileStream,
  222. m_Makefile->GetComplainRegularExpression());
  223. infoFileStream
  224. << ")\n";
  225. infoFileStream
  226. << "SET(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN})\n";
  227. infoFileStream
  228. << "SET(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN})\n";
  229. }
  230. //----------------------------------------------------------------------------
  231. std::string
  232. cmLocalUnixMakefileGenerator3
  233. ::ConvertToFullPath(const std::string& localPath)
  234. {
  235. std::string dir = m_Makefile->GetStartOutputDirectory();
  236. dir += "/";
  237. dir += localPath;
  238. return dir;
  239. }
  240. //----------------------------------------------------------------------------
  241. void cmLocalUnixMakefileGenerator3::WriteDisclaimer(std::ostream& os)
  242. {
  243. os
  244. << "# CMAKE generated file: DO NOT EDIT!\n"
  245. << "# Generated by \"" << m_GlobalGenerator->GetName() << "\""
  246. << " Generator, CMake Version "
  247. << cmMakefile::GetMajorVersion() << "."
  248. << cmMakefile::GetMinorVersion() << "\n\n";
  249. }
  250. void cmLocalUnixMakefileGenerator3::ComputeHomeRelativeOutputPath()
  251. {
  252. // Include the rule file for each object.
  253. m_HomeRelativeOutputPath =
  254. cmSystemTools::RelativePath(m_Makefile->GetHomeOutputDirectory(),
  255. m_Makefile->GetStartOutputDirectory());
  256. if (m_HomeRelativeOutputPath.size())
  257. {
  258. m_HomeRelativeOutputPath += "/";
  259. }
  260. }
  261. const std::string &cmLocalUnixMakefileGenerator3::GetHomeRelativeOutputPath()
  262. {
  263. return m_HomeRelativeOutputPath;
  264. }
  265. //----------------------------------------------------------------------------
  266. void
  267. cmLocalUnixMakefileGenerator3
  268. ::WriteTargetRuleFiles(cmTarget& target)
  269. {
  270. // Create a directory for this target.
  271. std::string dir = this->GetTargetDirectory(target);
  272. cmSystemTools::MakeDirectory(this->ConvertToFullPath(dir).c_str());
  273. // First generate the object rule files. Save a list of all object
  274. // files for this target.
  275. std::vector<std::string> objects;
  276. std::vector<std::string> external_objects;
  277. const std::vector<cmSourceFile*>& sources = target.GetSourceFiles();
  278. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  279. source != sources.end(); ++source)
  280. {
  281. if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  282. !(*source)->GetCustomCommand())
  283. {
  284. if(!m_GlobalGenerator->IgnoreFile((*source)->GetSourceExtension().c_str()))
  285. {
  286. // Generate this object file's rule file.
  287. this->WriteObjectRuleFiles(target, *(*source), objects);
  288. }
  289. else if((*source)->GetPropertyAsBool("EXTERNAL_OBJECT"))
  290. {
  291. // This is an external object file. Just add it.
  292. external_objects.push_back((*source)->GetFullPath());
  293. }
  294. }
  295. }
  296. // Generate the build-time dependencies file for this target.
  297. std::string depBase = dir;
  298. depBase += "/";
  299. depBase += target.GetName();
  300. // Construct the rule file name.
  301. std::string ruleFileName = dir;
  302. ruleFileName += "/build.make";
  303. // Open the rule file. This should be copy-if-different because the
  304. // rules may depend on this file itself.
  305. std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
  306. cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
  307. ruleFileStream.SetCopyIfDifferent(true);
  308. if(!ruleFileStream)
  309. {
  310. return;
  311. }
  312. this->WriteDisclaimer(ruleFileStream);
  313. this->WriteMakeVariables(ruleFileStream);
  314. // write the custom commands for this target
  315. std::vector<std::string> cleanFiles;
  316. // Look for files registered for cleaning in this directory.
  317. if(const char* additional_clean_files =
  318. m_Makefile->GetProperty("ADDITIONAL_MAKE_CLEAN_FILES"))
  319. {
  320. cmSystemTools::ExpandListArgument(additional_clean_files, cleanFiles);
  321. }
  322. this->WriteCustomCommands(target,ruleFileStream,cleanFiles);
  323. // Include the rule file for each object.
  324. std::string relPath = this->GetHomeRelativeOutputPath();
  325. std::string objTarget;
  326. if(!objects.empty())
  327. {
  328. ruleFileStream
  329. << "# Include make rules for object files.\n";
  330. for(std::vector<std::string>::const_iterator obj = objects.begin();
  331. obj != objects.end(); ++obj)
  332. {
  333. objTarget = relPath;
  334. objTarget += *obj;
  335. objTarget += ".build.make";
  336. ruleFileStream
  337. << m_IncludeDirective << " "
  338. << this->ConvertToOutputForExisting(objTarget.c_str()).c_str()
  339. << "\n";
  340. }
  341. ruleFileStream
  342. << "\n";
  343. }
  344. // Write the rule for this target type.
  345. switch(target.GetType())
  346. {
  347. case cmTarget::STATIC_LIBRARY:
  348. this->WriteStaticLibraryRule(ruleFileStream, ruleFileName.c_str(),
  349. target, objects, external_objects,
  350. cleanFiles);
  351. break;
  352. case cmTarget::SHARED_LIBRARY:
  353. this->WriteSharedLibraryRule(ruleFileStream, ruleFileName.c_str(),
  354. target, objects, external_objects,
  355. cleanFiles);
  356. break;
  357. case cmTarget::MODULE_LIBRARY:
  358. this->WriteModuleLibraryRule(ruleFileStream, ruleFileName.c_str(),
  359. target, objects, external_objects,
  360. cleanFiles);
  361. break;
  362. case cmTarget::EXECUTABLE:
  363. this->WriteExecutableRule(ruleFileStream, ruleFileName.c_str(),
  364. target, objects, external_objects,
  365. cleanFiles);
  366. break;
  367. default:
  368. break;
  369. }
  370. // Write the requires target.
  371. this->WriteTargetRequiresRule(ruleFileStream, target, objects);
  372. // Write clean target
  373. this->WriteTargetCleanRule(ruleFileStream, target, cleanFiles);
  374. }
  375. //----------------------------------------------------------------------------
  376. void
  377. cmLocalUnixMakefileGenerator3
  378. ::WriteObjectDependRules(std::ostream& ruleFileStream,
  379. std::string &obj,
  380. const char * lang,
  381. const cmSourceFile& source,
  382. std::vector<std::string>& depends,
  383. std::string& depMakeFile)
  384. {
  385. // Generate the build-time dependencies file for this object file.
  386. std::string depMarkFile;
  387. if(!this->GenerateDependsMakeFile(lang, obj.c_str(),
  388. depMakeFile, depMarkFile))
  389. {
  390. cmSystemTools::Error("No dependency checker available for language \"",
  391. lang, "\".");
  392. return;
  393. }
  394. // Create the list of dependencies known at cmake time. These are
  395. // shared between the object file and dependency scanning rule.
  396. depends.push_back(source.GetFullPath());
  397. if(const char* objectDeps = source.GetProperty("OBJECT_DEPENDS"))
  398. {
  399. std::vector<std::string> deps;
  400. cmSystemTools::ExpandListArgument(objectDeps, deps);
  401. for(std::vector<std::string>::iterator i = deps.begin();
  402. i != deps.end(); ++i)
  403. {
  404. depends.push_back(i->c_str());
  405. }
  406. }
  407. // Write the dependency generation rule.
  408. std::string relativeObj = this->GetHomeRelativeOutputPath();
  409. relativeObj += obj;
  410. std::vector<std::string> commands;
  411. std::string depEcho = "Scanning ";
  412. depEcho += lang;
  413. depEcho += " dependencies of ";
  414. depEcho += this->Convert(relativeObj.c_str(),NONE,SHELL);
  415. this->AppendEcho(commands, depEcho.c_str());
  416. // Add a command to call CMake to scan dependencies. CMake will
  417. // touch the corresponding depends file after scanning dependencies.
  418. cmOStringStream depCmd;
  419. // TODO: Account for source file properties and directory-level
  420. // definitions when scanning for dependencies.
  421. depCmd << "$(CMAKE_COMMAND) -E cmake_depends "
  422. << " \""
  423. << m_GlobalGenerator->GetName() << "\" "
  424. << this->Convert(m_Makefile->GetHomeOutputDirectory(),FULL,SHELL)
  425. << " "
  426. << this->Convert(m_Makefile->GetStartOutputDirectory(),FULL,SHELL)
  427. << " "
  428. << lang << " "
  429. << relativeObj.c_str() << " "
  430. << this->Convert(source.GetFullPath().c_str(),HOME_OUTPUT,SHELL);
  431. commands.push_back(depCmd.str());
  432. // compute the target
  433. std::string relPath = this->GetHomeRelativeOutputPath();
  434. relPath += depMarkFile;
  435. // Write the rule.
  436. this->WriteMakeRule(ruleFileStream, 0,
  437. relPath.c_str(), depends, commands);
  438. }
  439. //----------------------------------------------------------------------------
  440. void
  441. cmLocalUnixMakefileGenerator3
  442. ::WriteObjectBuildFile(std::string &obj,
  443. const char *lang,
  444. cmTarget& target,
  445. const cmSourceFile& source,
  446. std::vector<std::string>& depends,
  447. std::string &depMakeFile)
  448. {
  449. // Open the rule file for writing. This should be copy-if-different
  450. // because the rules may depend on this file itself.
  451. std::string ruleFileName = obj;
  452. ruleFileName += ".build.make";
  453. std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
  454. cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
  455. ruleFileStream.SetCopyIfDifferent(true);
  456. if(!ruleFileStream)
  457. {
  458. return;
  459. }
  460. this->WriteDisclaimer(ruleFileStream);
  461. ruleFileStream
  462. << "# Rule file for object file " << obj.c_str() << ".\n\n";
  463. // generate the depend scanning rule
  464. this->WriteObjectDependRules(ruleFileStream, obj, lang, source,
  465. depends, depMakeFile);
  466. this->AppendRuleDepend(depends, ruleFileNameFull.c_str());
  467. // Include the dependencies for the target.
  468. std::string depPath = this->GetHomeRelativeOutputPath();
  469. depPath += depMakeFile;
  470. depMakeFile = this->Convert(depPath.c_str(),HOME_OUTPUT,MAKEFILE);
  471. ruleFileStream
  472. << "# Include any dependencies generated for this rule.\n"
  473. << m_IncludeDirective << " "
  474. << depMakeFile
  475. << "\n\n";
  476. // Write the build rule.
  477. // Build the set of compiler flags.
  478. std::string flags;
  479. // Add the export symbol definition for shared library objects.
  480. bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
  481. (target.GetType() == cmTarget::MODULE_LIBRARY));
  482. if(shared)
  483. {
  484. flags += "-D";
  485. if(const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
  486. {
  487. flags += custom_export_name;
  488. }
  489. else
  490. {
  491. std::string in = target.GetName();
  492. in += "_EXPORTS";
  493. flags += cmSystemTools::MakeCindentifier(in.c_str());
  494. }
  495. }
  496. // Add flags from source file properties.
  497. this->AppendFlags(flags, source.GetProperty("COMPILE_FLAGS"));
  498. // Add language-specific flags.
  499. this->AddLanguageFlags(flags, lang);
  500. // Add shared-library flags if needed.
  501. this->AddSharedFlags(flags, lang, shared);
  502. // Add include directory flags.
  503. this->AppendFlags(flags, this->GetIncludeFlags(lang));
  504. // Get the output paths for source and object files.
  505. std::string sourceFile = source.GetFullPath();
  506. if(m_UseRelativePaths)
  507. {
  508. sourceFile = this->Convert(sourceFile.c_str(),HOME_OUTPUT);
  509. }
  510. sourceFile = this->Convert(sourceFile.c_str(),NONE,SHELL);
  511. std::string objectFile = this->Convert(obj.c_str(),START_OUTPUT,SHELL);
  512. // Construct the build message.
  513. std::string relativeObj = this->GetHomeRelativeOutputPath();
  514. relativeObj += obj;
  515. std::vector<std::string> commands;
  516. std::string buildEcho = "Building ";
  517. buildEcho += lang;
  518. buildEcho += " object ";
  519. buildEcho += relativeObj;
  520. this->AppendEcho(commands, buildEcho.c_str());
  521. // Construct the compile rules.
  522. std::string compileRuleVar = "CMAKE_";
  523. compileRuleVar += lang;
  524. compileRuleVar += "_COMPILE_OBJECT";
  525. std::string compileRule =
  526. m_Makefile->GetRequiredDefinition(compileRuleVar.c_str());
  527. cmSystemTools::ExpandListArgument(compileRule, commands);
  528. // Expand placeholders in the commands.
  529. for(std::vector<std::string>::iterator i = commands.begin();
  530. i != commands.end(); ++i)
  531. {
  532. this->ExpandRuleVariables(*i,
  533. lang,
  534. 0, // no objects
  535. 0, // no target
  536. 0, // no link libs
  537. sourceFile.c_str(),
  538. relativeObj.c_str(),
  539. flags.c_str());
  540. }
  541. // Write the rule.
  542. this->WriteMakeRule(ruleFileStream, 0,
  543. relativeObj.c_str(), depends, commands);
  544. // If the language needs provides-requires mode, create the
  545. // corresponding targets.
  546. std::string objectRequires = relativeObj;
  547. objectRequires += ".requires";
  548. std::string temp = relativeObj;
  549. temp += ".depend";
  550. std::vector<std::string> no_commands;
  551. std::vector<std::string> p_depends;
  552. p_depends.push_back(temp);
  553. // always provide an empty requires target
  554. this->WriteMakeRule(ruleFileStream, 0,
  555. objectRequires.c_str(), p_depends, no_commands);
  556. // write a build rule to recursively build what this obj provides
  557. std::string objectProvides = relativeObj;
  558. objectProvides += ".provides";
  559. temp = relativeObj;
  560. temp += ".provides.build";
  561. std::vector<std::string> r_commands;
  562. std::string tgtMakefileName = this->GetRelativeTargetDirectory(target);
  563. tgtMakefileName += "/build.make";
  564. r_commands.push_back(this->GetRecursiveMakeCall(tgtMakefileName.c_str(),
  565. temp.c_str()));
  566. p_depends.clear();
  567. p_depends.push_back(objectRequires);
  568. this->WriteMakeRule(ruleFileStream, 0,
  569. objectProvides.c_str(), p_depends, r_commands);
  570. // write the provides.build rule dependency on the obj file
  571. p_depends.clear();
  572. p_depends.push_back(relativeObj);
  573. this->WriteMakeRule(ruleFileStream, 0,
  574. temp.c_str(), p_depends, no_commands);
  575. }
  576. //----------------------------------------------------------------------------
  577. void
  578. cmLocalUnixMakefileGenerator3
  579. ::WriteObjectRuleFiles(cmTarget& target, const cmSourceFile& source,
  580. std::vector<std::string>& objects)
  581. {
  582. // Identify the language of the source file.
  583. const char* lang = this->GetSourceFileLanguage(source);
  584. if(!lang)
  585. {
  586. // If language is not known, this is an error.
  587. cmSystemTools::Error("Source file \"", source.GetFullPath().c_str(),
  588. "\" has unknown type.");
  589. return;
  590. }
  591. // Get the full path name of the object file.
  592. std::string obj = this->GetObjectFileName(target, source);
  593. // Avoid generating duplicate rules.
  594. if(m_ObjectFiles.find(obj) == m_ObjectFiles.end())
  595. {
  596. m_ObjectFiles.insert(obj);
  597. }
  598. else
  599. {
  600. cmOStringStream err;
  601. err << "Warning: Source file \""
  602. << source.GetSourceName().c_str() << "."
  603. << source.GetSourceExtension().c_str()
  604. << "\" is listed multiple times for target \"" << target.GetName()
  605. << "\".";
  606. cmSystemTools::Message(err.str().c_str(), "Warning");
  607. return;
  608. }
  609. // Create the directory containing the object file. This may be a
  610. // subdirectory under the target's directory.
  611. std::string dir = cmSystemTools::GetFilenamePath(obj.c_str());
  612. cmSystemTools::MakeDirectory(this->ConvertToFullPath(dir).c_str());
  613. // Save this in the target's list of object files.
  614. objects.push_back(obj);
  615. std::string relativeObj = this->GetHomeRelativeOutputPath();
  616. relativeObj += obj;
  617. // we compute some depends when writing the depend.make that we will also
  618. // use in the build.make, same with depMakeFile
  619. std::vector<std::string> depends;
  620. std::string depMakeFile;
  621. // generate the build rule file
  622. this->WriteObjectBuildFile(obj, lang, target, source, depends, depMakeFile);
  623. // The object file should be checked for dependency integrity.
  624. m_CheckDependFiles[lang].insert(relativeObj);
  625. // add this to the list of objects for this local generator
  626. m_LocalObjectFiles[cmSystemTools::GetFilenameName(obj)].push_back(&target);
  627. }
  628. //----------------------------------------------------------------------------
  629. std::string
  630. cmLocalUnixMakefileGenerator3
  631. ::GenerateCustomRuleFile(const cmCustomCommand& cc, const char *dir)
  632. {
  633. // Convert the output name to a relative path if possible.
  634. std::string output = this->Convert(cc.GetOutput(),START_OUTPUT);
  635. // Construct the name of the rule file by transforming the output
  636. // name to a valid file name. Since the output is already a file
  637. // everything but the path characters is valid.
  638. std::string customName = output;
  639. cmSystemTools::ReplaceString(customName, "../", "___");
  640. cmSystemTools::ReplaceString(customName, "/", "_");
  641. cmSystemTools::ReplaceString(customName, ":", "_");
  642. std::string ruleFileName = dir;
  643. ruleFileName += "/";
  644. ruleFileName += customName;
  645. ruleFileName += ".build.make";
  646. // what is the relative path to the rule file
  647. std::string relRuleFile = this->Convert(ruleFileName.c_str(),HOME_OUTPUT);
  648. // Open the rule file. This should be copy-if-different because the
  649. // rules may depend on this file itself.
  650. cmGeneratedFileStream ruleFileStream(ruleFileName.c_str());
  651. ruleFileStream.SetCopyIfDifferent(true);
  652. if(!ruleFileStream)
  653. {
  654. return relRuleFile;
  655. }
  656. this->WriteDisclaimer(ruleFileStream);
  657. ruleFileStream
  658. << "# Custom command rule file for " << output.c_str() << ".\n\n";
  659. // Collect the commands.
  660. std::vector<std::string> commands;
  661. std::string preEcho = "Generating ";
  662. preEcho += output;
  663. this->AppendEcho(commands, preEcho.c_str());
  664. this->AppendCustomCommand(commands, cc);
  665. // Collect the dependencies.
  666. std::vector<std::string> depends;
  667. this->AppendCustomDepend(depends, cc);
  668. // Add a dependency on the rule file itself.
  669. this->AppendRuleDepend(depends, relRuleFile.c_str());
  670. // Write the rule.
  671. const char* comment = 0;
  672. if(cc.GetComment() && *cc.GetComment())
  673. {
  674. comment = cc.GetComment();
  675. }
  676. this->WriteMakeRule(ruleFileStream, comment,
  677. cc.GetOutput(), depends, commands);
  678. return relRuleFile;
  679. }
  680. //----------------------------------------------------------------------------
  681. void
  682. cmLocalUnixMakefileGenerator3
  683. ::WriteUtilityRuleFiles(cmTarget& target)
  684. {
  685. // Create a directory for this target.
  686. std::string dir = this->GetTargetDirectory(target);
  687. cmSystemTools::MakeDirectory(this->ConvertToFullPath(dir).c_str());
  688. // Construct the name of the rule file.
  689. std::string ruleFileName = dir;
  690. ruleFileName += "/build.make";
  691. // Open the rule file. This should be copy-if-different because the
  692. // rules may depend on this file itself.
  693. std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
  694. cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
  695. ruleFileStream.SetCopyIfDifferent(true);
  696. if(!ruleFileStream)
  697. {
  698. return;
  699. }
  700. this->WriteDisclaimer(ruleFileStream);
  701. this->WriteMakeVariables(ruleFileStream);
  702. ruleFileStream
  703. << "# Utility rule file for " << target.GetName() << ".\n\n";
  704. // write the custom commands for this target
  705. std::vector<std::string> cleanFiles;
  706. if(const char* additional_clean_files =
  707. m_Makefile->GetProperty("ADDITIONAL_MAKE_CLEAN_FILES"))
  708. {
  709. cmSystemTools::ExpandListArgument(additional_clean_files, cleanFiles);
  710. }
  711. this->WriteCustomCommands(target,ruleFileStream, cleanFiles);
  712. // Collect the commands and dependencies.
  713. std::vector<std::string> commands;
  714. std::vector<std::string> depends;
  715. // Utility targets store their rules in pre- and post-build commands.
  716. this->AppendCustomDepends(depends, target.GetPreBuildCommands());
  717. this->AppendCustomDepends(depends, target.GetPostBuildCommands());
  718. this->AppendCustomCommands(commands, target.GetPreBuildCommands());
  719. this->AppendCustomCommands(commands, target.GetPostBuildCommands());
  720. // Add dependencies on targets that must be built first.
  721. this->AppendTargetDepends(depends, target);
  722. // Add a dependency on the rule file itself.
  723. std::string relPath = this->GetHomeRelativeOutputPath();
  724. std::string objTarget = relPath;
  725. objTarget += ruleFileName;
  726. this->AppendRuleDepend(depends, objTarget.c_str());
  727. // Write the rule.
  728. this->WriteMakeRule(ruleFileStream, 0,
  729. target.GetName(), depends, commands);
  730. // Write convenience targets.
  731. dir = m_Makefile->GetStartOutputDirectory();
  732. dir += "/";
  733. dir += this->GetTargetDirectory(target);
  734. std::string buildTargetRuleName = dir;
  735. buildTargetRuleName += "/build";
  736. buildTargetRuleName =
  737. this->Convert(buildTargetRuleName.c_str(),HOME_OUTPUT,MAKEFILE);
  738. this->WriteConvenienceRule(ruleFileStream, target.GetName(),
  739. buildTargetRuleName.c_str());
  740. // Write clean target
  741. this->WriteTargetCleanRule(ruleFileStream, target, cleanFiles);
  742. }
  743. //----------------------------------------------------------------------------
  744. bool
  745. cmLocalUnixMakefileGenerator3
  746. ::GenerateDependsMakeFile(const std::string& lang, const char* objFile,
  747. std::string& depMakeFile, std::string& depMarkFile)
  748. {
  749. // Construct a checker for the given language.
  750. std::auto_ptr<cmDepends>
  751. checker(this->GetDependsChecker(lang,
  752. m_Makefile->GetStartOutputDirectory(),
  753. objFile, false));
  754. if(checker.get())
  755. {
  756. // Save the make and mark file names.
  757. depMakeFile = checker->GetMakeFileName();
  758. depMarkFile = checker->GetMarkFileName();
  759. // Check the dependencies. Ths is required because we need at least an
  760. // empty foo.obj.depends.make for make to include, so at cmake time the
  761. // ::Check() method will generate that if it does not exist
  762. checker->Check();
  763. return true;
  764. }
  765. return false;
  766. }
  767. //----------------------------------------------------------------------------
  768. void
  769. cmLocalUnixMakefileGenerator3
  770. ::WriteMakeRule(std::ostream& os,
  771. const char* comment,
  772. const char* target,
  773. const std::vector<std::string>& depends,
  774. const std::vector<std::string>& commands)
  775. {
  776. // Make sure there is a target.
  777. if(!target || !*target)
  778. {
  779. cmSystemTools::Error("No target for WriteMakeRule! called with comment: ",
  780. comment);
  781. return;
  782. }
  783. std::string replace;
  784. // Write the comment describing the rule in the makefile.
  785. if(comment)
  786. {
  787. replace = comment;
  788. std::string::size_type lpos = 0;
  789. std::string::size_type rpos;
  790. while((rpos = replace.find('\n', lpos)) != std::string::npos)
  791. {
  792. os << "# " << replace.substr(lpos, rpos-lpos) << "\n";
  793. lpos = rpos+1;
  794. }
  795. os << "# " << replace.substr(lpos) << "\n";
  796. }
  797. // Construct the left hand side of the rule.
  798. replace = target;
  799. std::string tgt = this->Convert(replace.c_str(),HOME_OUTPUT,MAKEFILE);
  800. tgt = this->ConvertToMakeTarget(tgt.c_str());
  801. const char* space = "";
  802. if(tgt.size() == 1)
  803. {
  804. // Add a space before the ":" to avoid drive letter confusion on
  805. // Windows.
  806. space = " ";
  807. }
  808. // Write the rule.
  809. if(depends.empty())
  810. {
  811. // No dependencies. The commands will always run.
  812. os << tgt.c_str() << space << ":\n";
  813. }
  814. else
  815. {
  816. // Split dependencies into multiple rule lines. This allows for
  817. // very long dependency lists even on older make implementations.
  818. for(std::vector<std::string>::const_iterator dep = depends.begin();
  819. dep != depends.end(); ++dep)
  820. {
  821. replace = *dep;
  822. replace = this->Convert(replace.c_str(),HOME_OUTPUT,MAKEFILE);
  823. replace = this->ConvertToMakeTarget(replace.c_str());
  824. os << tgt.c_str() << space << ": " << replace.c_str() << "\n";
  825. }
  826. }
  827. // Write the list of commands.
  828. for(std::vector<std::string>::const_iterator i = commands.begin();
  829. i != commands.end(); ++i)
  830. {
  831. replace = *i;
  832. os << "\t" << replace.c_str() << "\n";
  833. }
  834. os << "\n";
  835. }
  836. //----------------------------------------------------------------------------
  837. void cmLocalUnixMakefileGenerator3::WriteDivider(std::ostream& os)
  838. {
  839. os
  840. << "#======================================"
  841. << "=======================================\n";
  842. }
  843. //----------------------------------------------------------------------------
  844. void
  845. cmLocalUnixMakefileGenerator3
  846. ::WriteMakeVariables(std::ostream& makefileStream)
  847. {
  848. this->WriteDivider(makefileStream);
  849. makefileStream
  850. << "# Set environment variables for the build.\n"
  851. << "\n";
  852. if(m_WindowsShell)
  853. {
  854. makefileStream
  855. << "!IF \"$(OS)\" == \"Windows_NT\"\n"
  856. << "NULL=\n"
  857. << "!ELSE\n"
  858. << "NULL=nul\n"
  859. << "!ENDIF\n";
  860. }
  861. else
  862. {
  863. makefileStream
  864. << "# The shell in which to execute make rules.\n"
  865. << "SHELL = /bin/sh\n"
  866. << "\n";
  867. }
  868. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  869. {
  870. makefileStream
  871. << "# Produce verbose output by default.\n"
  872. << "VERBOSE = 1\n"
  873. << "\n";
  874. }
  875. std::string cmakecommand =
  876. this->ConvertToOutputForExisting(
  877. m_Makefile->GetRequiredDefinition("CMAKE_COMMAND"));
  878. makefileStream
  879. << "# The CMake executable.\n"
  880. << "CMAKE_COMMAND = "
  881. << this->Convert(cmakecommand.c_str(),HOME_OUTPUT,MAKEFILE).c_str() << "\n"
  882. << "\n";
  883. makefileStream
  884. << "# The command to remove a file.\n"
  885. << "RM = "
  886. << this->Convert(cmakecommand.c_str(),HOME_OUTPUT,SHELL).c_str()
  887. << " -E remove -f\n"
  888. << "\n";
  889. if(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  890. {
  891. makefileStream
  892. << "# The program to use to edit the cache.\n"
  893. << "CMAKE_EDIT_COMMAND = "
  894. << (this->ConvertToOutputForExisting(
  895. m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))) << "\n"
  896. << "\n";
  897. }
  898. makefileStream
  899. << "# The top-level source directory on which CMake was run.\n"
  900. << "CMAKE_SOURCE_DIR = "
  901. << this->Convert(m_Makefile->GetHomeDirectory(), HOME_OUTPUT, SHELL)
  902. << "\n"
  903. << "\n";
  904. makefileStream
  905. << "# The top-level build directory on which CMake was run.\n"
  906. << "CMAKE_BINARY_DIR = ."
  907. << "\n"
  908. << "\n";
  909. }
  910. //----------------------------------------------------------------------------
  911. void
  912. cmLocalUnixMakefileGenerator3
  913. ::WriteSpecialTargetsTop(std::ostream& makefileStream)
  914. {
  915. this->WriteDivider(makefileStream);
  916. makefileStream
  917. << "# Special targets provided by cmake.\n"
  918. << "\n";
  919. // Write the main entry point target. This must be the VERY first
  920. // target so that make with no arguments will run it.
  921. {
  922. // Just depend on the all target to drive the build.
  923. std::vector<std::string> depends;
  924. std::vector<std::string> no_commands;
  925. depends.push_back("all");
  926. // Write the rule.
  927. this->WriteMakeRule(makefileStream,
  928. "Default target executed when no arguments are "
  929. "given to make.",
  930. "default_target",
  931. depends,
  932. no_commands);
  933. }
  934. // Write special "test" target to run ctest.
  935. if(m_Makefile->IsOn("CMAKE_TESTING_ENABLED"))
  936. {
  937. std::string ctest;
  938. if(m_Makefile->GetDefinition("CMake_BINARY_DIR"))
  939. {
  940. // We are building CMake itself. Use the ctest that comes with
  941. // this version of CMake instead of the one used to build it.
  942. ctest = m_ExecutableOutputPath;
  943. ctest += "ctest";
  944. ctest += cmSystemTools::GetExecutableExtension();
  945. ctest = this->Convert(ctest.c_str(),START_OUTPUT,SHELL);
  946. ctest += " --force-new-ctest-process";
  947. }
  948. else
  949. {
  950. // We are building another project. Use the ctest that comes with
  951. // the CMake building it.
  952. ctest = m_Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  953. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  954. ctest += "/";
  955. ctest += "ctest";
  956. ctest += cmSystemTools::GetExecutableExtension();
  957. ctest = this->ConvertToOutputForExisting(ctest.c_str());
  958. }
  959. std::vector<std::string> no_depends;
  960. std::vector<std::string> commands;
  961. this->AppendEcho(commands, "Running tests...");
  962. ctest += " $(ARGS)";
  963. commands.push_back(ctest);
  964. this->WriteMakeRule(makefileStream,
  965. "Special rule to drive testing with ctest.",
  966. "test", no_depends, commands);
  967. }
  968. // Write special "install" target to run cmake_install.cmake script.
  969. {
  970. std::vector<std::string> depends;
  971. std::vector<std::string> commands;
  972. std::string cmd;
  973. if(m_Makefile->GetDefinition("CMake_BINARY_DIR"))
  974. {
  975. // We are building CMake itself. We cannot use the original
  976. // executable to install over itself.
  977. cmd = m_ExecutableOutputPath;
  978. cmd += "cmake";
  979. cmd = this->Convert(cmd.c_str(),START_OUTPUT,SHELL);
  980. }
  981. else
  982. {
  983. cmd = "$(CMAKE_COMMAND)";
  984. }
  985. cmd += " -P cmake_install.cmake";
  986. commands.push_back(cmd);
  987. const char* noall =
  988. m_Makefile->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
  989. if(!noall || cmSystemTools::IsOff(noall))
  990. {
  991. // Drive the build before installing.
  992. depends.push_back("all");
  993. }
  994. this->WriteMakeRule(makefileStream,
  995. "Special rule to run installation script.",
  996. "install", depends, commands);
  997. }
  998. // Write special "rebuild_cache" target to re-run cmake.
  999. {
  1000. std::vector<std::string> no_depends;
  1001. std::vector<std::string> commands;
  1002. this->AppendEcho(commands, "Running CMake to regenerate build system...");
  1003. commands.push_back(
  1004. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  1005. this->WriteMakeRule(makefileStream,
  1006. "Special rule to re-run CMake using make.",
  1007. "rebuild_cache",
  1008. no_depends,
  1009. commands);
  1010. }
  1011. // Use CMAKE_EDIT_COMMAND for the edit_cache rule if it is defined.
  1012. // Otherwise default to the interactive command-line interface.
  1013. if(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  1014. {
  1015. std::vector<std::string> no_depends;
  1016. std::vector<std::string> commands;
  1017. this->AppendEcho(commands, "Running CMake cache editor...");
  1018. commands.push_back(
  1019. "$(CMAKE_EDIT_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  1020. this->WriteMakeRule(makefileStream,
  1021. "Special rule to re-run CMake cache editor using make.",
  1022. "edit_cache",
  1023. no_depends,
  1024. commands);
  1025. }
  1026. else
  1027. {
  1028. std::vector<std::string> no_depends;
  1029. std::vector<std::string> commands;
  1030. this->AppendEcho(commands,
  1031. "Running interactive CMake command-line interface...");
  1032. commands.push_back(
  1033. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -i");
  1034. this->WriteMakeRule(makefileStream,
  1035. "Special rule to re-run CMake cache editor using make.",
  1036. "edit_cache",
  1037. no_depends,
  1038. commands);
  1039. }
  1040. }
  1041. //----------------------------------------------------------------------------
  1042. void
  1043. cmLocalUnixMakefileGenerator3
  1044. ::WriteSpecialTargetsBottom(std::ostream& makefileStream)
  1045. {
  1046. this->WriteDivider(makefileStream);
  1047. makefileStream
  1048. << "# Special targets to cleanup operation of make.\n"
  1049. << "\n";
  1050. // Write special "cmake_check_build_system" target to run cmake with
  1051. // the --check-build-system flag.
  1052. {
  1053. // Build command to run CMake to check if anything needs regenerating.
  1054. std::string cmakefileName = "Makefile.cmake";
  1055. std::string runRule =
  1056. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
  1057. runRule += " --check-build-system ";
  1058. runRule += this->Convert(cmakefileName.c_str(),NONE,SHELL);
  1059. runRule += " 0";
  1060. std::vector<std::string> no_depends;
  1061. std::vector<std::string> commands;
  1062. commands.push_back(runRule);
  1063. this->WriteMakeRule(makefileStream,
  1064. "Special rule to run CMake to check the build system "
  1065. "integrity.\n"
  1066. "No rule that depends on this can have "
  1067. "commands that come from listfiles\n"
  1068. "because they might be regenerated.",
  1069. "cmake_check_build_system",
  1070. no_depends,
  1071. commands);
  1072. }
  1073. std::vector<std::string> no_commands;
  1074. // Write special target to silence make output. This must be after
  1075. // the default target in case VERBOSE is set (which changes the
  1076. // name). The setting of CMAKE_VERBOSE_MAKEFILE to ON will cause a
  1077. // "VERBOSE=1" to be added as a make variable which will change the
  1078. // name of this special target. This gives a make-time choice to
  1079. // the user.
  1080. std::vector<std::string> no_depends;
  1081. this->WriteMakeRule(makefileStream,
  1082. "Suppress display of executed commands.",
  1083. "$(VERBOSE).SILENT",
  1084. no_depends,
  1085. no_commands);
  1086. // Special target to cleanup operation of make tool.
  1087. std::vector<std::string> depends;
  1088. this->WriteMakeRule(makefileStream,
  1089. "Disable implicit rules so canoncical targets will work.",
  1090. ".SUFFIXES",
  1091. depends,
  1092. no_commands);
  1093. // Add a fake suffix to keep HP happy. Must be max 32 chars for SGI make.
  1094. depends.push_back(".hpux_make_needs_suffix_list");
  1095. this->WriteMakeRule(makefileStream, 0,
  1096. ".SUFFIXES", depends, no_commands);
  1097. }
  1098. //----------------------------------------------------------------------------
  1099. void
  1100. cmLocalUnixMakefileGenerator3
  1101. ::WriteConvenienceRule(std::ostream& ruleFileStream,
  1102. const char* realTarget,
  1103. const char* helpTarget)
  1104. {
  1105. // A rule is only needed if the names are different.
  1106. if(strcmp(realTarget, helpTarget) != 0)
  1107. {
  1108. // The helper target depends on the real target.
  1109. std::vector<std::string> depends;
  1110. depends.push_back(realTarget);
  1111. // There are no commands.
  1112. std::vector<std::string> no_commands;
  1113. // Write the rule.
  1114. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  1115. helpTarget, depends, no_commands);
  1116. }
  1117. }
  1118. //----------------------------------------------------------------------------
  1119. void
  1120. cmLocalUnixMakefileGenerator3
  1121. ::WriteTargetRequiresRule(std::ostream& ruleFileStream, cmTarget& target,
  1122. const std::vector<std::string>& objects)
  1123. {
  1124. std::vector<std::string> depends;
  1125. std::vector<std::string> no_commands;
  1126. // Construct the name of the dependency generation target.
  1127. std::string depTarget = this->GetRelativeTargetDirectory(target);
  1128. depTarget += "/requires";
  1129. // This target drives dependency generation for all object files.
  1130. std::string relPath = this->GetHomeRelativeOutputPath();
  1131. std::string objTarget;
  1132. for(std::vector<std::string>::const_iterator obj = objects.begin();
  1133. obj != objects.end(); ++obj)
  1134. {
  1135. objTarget = relPath;
  1136. objTarget += *obj;
  1137. objTarget += ".requires";
  1138. depends.push_back(objTarget);
  1139. }
  1140. // Write the rule.
  1141. this->WriteMakeRule(ruleFileStream, 0,
  1142. depTarget.c_str(), depends, no_commands);
  1143. }
  1144. //----------------------------------------------------------------------------
  1145. void
  1146. cmLocalUnixMakefileGenerator3
  1147. ::WriteExecutableRule(std::ostream& ruleFileStream,
  1148. const char* ruleFileName,
  1149. cmTarget& target,
  1150. const std::vector<std::string>& objects,
  1151. const std::vector<std::string>& external_objects,
  1152. std::vector<std::string>& cleanFiles)
  1153. {
  1154. // Write the dependency generation rule.
  1155. this->WriteTargetDependRule(ruleFileStream, target, objects);
  1156. std::vector<std::string> commands;
  1157. std::string relPath = this->GetHomeRelativeOutputPath();
  1158. std::string objTarget;
  1159. // Build list of dependencies.
  1160. std::vector<std::string> depends;
  1161. for(std::vector<std::string>::const_iterator obj = objects.begin();
  1162. obj != objects.end(); ++obj)
  1163. {
  1164. objTarget = relPath;
  1165. objTarget += *obj;
  1166. depends.push_back(objTarget);
  1167. }
  1168. // Add dependencies on targets that must be built first.
  1169. this->AppendTargetDepends(depends, target);
  1170. // Add a dependency on the rule file itself.
  1171. objTarget = relPath;
  1172. objTarget += ruleFileName;
  1173. this->AppendRuleDepend(depends, objTarget.c_str());
  1174. // Construct the full path to the executable that will be generated.
  1175. std::string targetFullPath = m_ExecutableOutputPath;
  1176. if(targetFullPath.length() == 0)
  1177. {
  1178. targetFullPath = m_Makefile->GetStartOutputDirectory();
  1179. targetFullPath += "/";
  1180. }
  1181. #ifdef __APPLE__
  1182. if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
  1183. {
  1184. // Make bundle directories
  1185. targetFullPath += target.GetName();
  1186. targetFullPath += ".app/Contents/MacOS/";
  1187. }
  1188. #endif
  1189. // do we have a different executable name?
  1190. if (target.GetProperty("OUTPUT_NAME"))
  1191. {
  1192. targetFullPath += target.GetProperty("OUTPUT_NAME");
  1193. }
  1194. else
  1195. {
  1196. targetFullPath += target.GetName();
  1197. }
  1198. targetFullPath += cmSystemTools::GetExecutableExtension();
  1199. // Convert to the output path to use in constructing commands.
  1200. std::string targetOutPath = this->Convert(targetFullPath.c_str(),HOME_OUTPUT,MAKEFILE);
  1201. // Get the language to use for linking this executable.
  1202. const char* linkLanguage =
  1203. target.GetLinkerLanguage(this->GetGlobalGenerator());
  1204. // Make sure we have a link language.
  1205. if(!linkLanguage)
  1206. {
  1207. cmSystemTools::Error("Cannot determine link language for target \"",
  1208. target.GetName(), "\".");
  1209. return;
  1210. }
  1211. // Add the link message.
  1212. std::string buildEcho = "Linking ";
  1213. buildEcho += linkLanguage;
  1214. buildEcho += " executable ";
  1215. buildEcho += targetOutPath;
  1216. this->AppendEcho(commands, buildEcho.c_str());
  1217. // Build a list of compiler flags and linker flags.
  1218. std::string flags;
  1219. std::string linkFlags;
  1220. // Add flags to create an executable.
  1221. this->AddConfigVariableFlags(linkFlags, "CMAKE_EXE_LINKER_FLAGS");
  1222. if(target.GetPropertyAsBool("WIN32_EXECUTABLE"))
  1223. {
  1224. this->AppendFlags(linkFlags,
  1225. m_Makefile->GetDefinition("CMAKE_CREATE_WIN32_EXE"));
  1226. }
  1227. else
  1228. {
  1229. this->AppendFlags(linkFlags,
  1230. m_Makefile->GetDefinition("CMAKE_CREATE_CONSOLE_EXE"));
  1231. }
  1232. // Add language-specific flags.
  1233. this->AddLanguageFlags(flags, linkLanguage);
  1234. // Add flags to deal with shared libraries. Any library being
  1235. // linked in might be shared, so always use shared flags for an
  1236. // executable.
  1237. this->AddSharedFlags(flags, linkLanguage, true);
  1238. // Add target-specific linker flags.
  1239. this->AppendFlags(linkFlags, target.GetProperty("LINK_FLAGS"));
  1240. // Add the pre-build and pre-link rules.
  1241. this->AppendCustomCommands(commands, target.GetPreBuildCommands());
  1242. this->AppendCustomCommands(commands, target.GetPreLinkCommands());
  1243. // Construct the main link rule.
  1244. std::string linkRuleVar = "CMAKE_";
  1245. linkRuleVar += linkLanguage;
  1246. linkRuleVar += "_LINK_EXECUTABLE";
  1247. std::string linkRule = m_Makefile->GetRequiredDefinition(linkRuleVar.c_str());
  1248. cmSystemTools::ExpandListArgument(linkRule, commands);
  1249. // Add the post-build rules.
  1250. this->AppendCustomCommands(commands, target.GetPostBuildCommands());
  1251. // Collect up flags to link in needed libraries.
  1252. cmOStringStream linklibs;
  1253. this->OutputLinkLibraries(linklibs, 0, target);
  1254. // Construct object file lists that may be needed to expand the
  1255. // rule.
  1256. std::string variableName;
  1257. std::string variableNameExternal;
  1258. this->WriteObjectsVariable(ruleFileStream, target, objects, external_objects,
  1259. variableName, variableNameExternal);
  1260. std::string buildObjs = "$(";
  1261. buildObjs += variableName;
  1262. buildObjs += ") $(";
  1263. buildObjs += variableNameExternal;
  1264. buildObjs += ")";
  1265. std::string cleanObjs = "$(";
  1266. cleanObjs += variableName;
  1267. cleanObjs += ")";
  1268. // Expand placeholders in the commands.
  1269. for(std::vector<std::string>::iterator i = commands.begin();
  1270. i != commands.end(); ++i)
  1271. {
  1272. this->ExpandRuleVariables(*i,
  1273. linkLanguage,
  1274. buildObjs.c_str(),
  1275. targetOutPath.c_str(),
  1276. linklibs.str().c_str(),
  1277. 0,
  1278. 0,
  1279. flags.c_str(),
  1280. 0,
  1281. 0,
  1282. 0,
  1283. linkFlags.c_str());
  1284. }
  1285. // Write the build rule.
  1286. this->WriteMakeRule(ruleFileStream, 0,
  1287. targetFullPath.c_str(), depends, commands);
  1288. // Write convenience targets.
  1289. std::string dir = m_Makefile->GetStartOutputDirectory();
  1290. dir += "/";
  1291. dir += this->GetTargetDirectory(target);
  1292. std::string buildTargetRuleName = dir;
  1293. buildTargetRuleName += "/build";
  1294. buildTargetRuleName =
  1295. this->Convert(buildTargetRuleName.c_str(),HOME_OUTPUT,MAKEFILE);
  1296. this->WriteConvenienceRule(ruleFileStream, targetFullPath.c_str(),
  1297. buildTargetRuleName.c_str());
  1298. cleanFiles.push_back(cleanObjs);
  1299. cleanFiles.push_back
  1300. (this->Convert(targetFullPath.c_str(),HOME_OUTPUT,MAKEFILE));
  1301. }
  1302. //----------------------------------------------------------------------------
  1303. void
  1304. cmLocalUnixMakefileGenerator3
  1305. ::WriteStaticLibraryRule(std::ostream& ruleFileStream,
  1306. const char* ruleFileName,
  1307. cmTarget& target,
  1308. const std::vector<std::string>& objects,
  1309. const std::vector<std::string>& external_objects,
  1310. std::vector<std::string>& cleanFiles)
  1311. {
  1312. const char* linkLanguage =
  1313. target.GetLinkerLanguage(this->GetGlobalGenerator());
  1314. std::string linkRuleVar = "CMAKE_";
  1315. if (linkLanguage)
  1316. {
  1317. linkRuleVar += linkLanguage;
  1318. }
  1319. linkRuleVar += "_CREATE_STATIC_LIBRARY";
  1320. std::string extraFlags;
  1321. this->AppendFlags(extraFlags, target.GetProperty("STATIC_LIBRARY_FLAGS"));
  1322. this->WriteLibraryRule(ruleFileStream, ruleFileName, target,
  1323. objects, external_objects,
  1324. linkRuleVar.c_str(), extraFlags.c_str(),cleanFiles);
  1325. }
  1326. //----------------------------------------------------------------------------
  1327. void
  1328. cmLocalUnixMakefileGenerator3
  1329. ::WriteSharedLibraryRule(std::ostream& ruleFileStream,
  1330. const char* ruleFileName,
  1331. cmTarget& target,
  1332. const std::vector<std::string>& objects,
  1333. const std::vector<std::string>& external_objects,
  1334. std::vector<std::string>& cleanFiles)
  1335. {
  1336. const char* linkLanguage =
  1337. target.GetLinkerLanguage(this->GetGlobalGenerator());
  1338. std::string linkRuleVar = "CMAKE_";
  1339. if (linkLanguage)
  1340. {
  1341. linkRuleVar += linkLanguage;
  1342. }
  1343. linkRuleVar += "_CREATE_SHARED_LIBRARY";
  1344. std::string extraFlags;
  1345. this->AppendFlags(extraFlags, target.GetProperty("LINK_FLAGS"));
  1346. this->AddConfigVariableFlags(extraFlags, "CMAKE_SHARED_LINKER_FLAGS");
  1347. if(m_Makefile->IsOn("WIN32") && !(m_Makefile->IsOn("CYGWIN") || m_Makefile->IsOn("MINGW")))
  1348. {
  1349. const std::vector<cmSourceFile*>& sources = target.GetSourceFiles();
  1350. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1351. i != sources.end(); ++i)
  1352. {
  1353. if((*i)->GetSourceExtension() == "def")
  1354. {
  1355. extraFlags += " ";
  1356. extraFlags += m_Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  1357. extraFlags +=
  1358. this->Convert((*i)->GetFullPath().c_str(),HOME_OUTPUT,MAKEFILE);
  1359. }
  1360. }
  1361. }
  1362. this->WriteLibraryRule(ruleFileStream, ruleFileName, target,
  1363. objects, external_objects,
  1364. linkRuleVar.c_str(), extraFlags.c_str(), cleanFiles);
  1365. }
  1366. //----------------------------------------------------------------------------
  1367. void
  1368. cmLocalUnixMakefileGenerator3
  1369. ::WriteModuleLibraryRule(std::ostream& ruleFileStream,
  1370. const char* ruleFileName,
  1371. cmTarget& target,
  1372. const std::vector<std::string>& objects,
  1373. const std::vector<std::string>& external_objects,
  1374. std::vector<std::string>& cleanFiles)
  1375. {
  1376. const char* linkLanguage =
  1377. target.GetLinkerLanguage(this->GetGlobalGenerator());
  1378. std::string linkRuleVar = "CMAKE_";
  1379. if (linkLanguage)
  1380. {
  1381. linkRuleVar += linkLanguage;
  1382. }
  1383. linkRuleVar += "_CREATE_SHARED_MODULE";
  1384. std::string extraFlags;
  1385. this->AppendFlags(extraFlags, target.GetProperty("LINK_FLAGS"));
  1386. this->AddConfigVariableFlags(extraFlags, "CMAKE_MODULE_LINKER_FLAGS");
  1387. // TODO: .def files should be supported here also.
  1388. this->WriteLibraryRule(ruleFileStream, ruleFileName, target,
  1389. objects, external_objects,
  1390. linkRuleVar.c_str(), extraFlags.c_str(), cleanFiles);
  1391. }
  1392. //----------------------------------------------------------------------------
  1393. void
  1394. cmLocalUnixMakefileGenerator3
  1395. ::WriteLibraryRule(std::ostream& ruleFileStream,
  1396. const char* ruleFileName,
  1397. cmTarget& target,
  1398. const std::vector<std::string>& objects,
  1399. const std::vector<std::string>& external_objects,
  1400. const char* linkRuleVar,
  1401. const char* extraFlags,
  1402. std::vector<std::string>& cleanFiles)
  1403. {
  1404. // Write the dependency generation rule.
  1405. this->WriteTargetDependRule(ruleFileStream, target, objects);
  1406. // TODO: Merge the methods that call this method to avoid
  1407. // code duplication.
  1408. std::vector<std::string> commands;
  1409. std::string relPath = this->GetHomeRelativeOutputPath();
  1410. std::string objTarget;
  1411. // Build list of dependencies.
  1412. std::vector<std::string> depends;
  1413. for(std::vector<std::string>::const_iterator obj = objects.begin();
  1414. obj != objects.end(); ++obj)
  1415. {
  1416. objTarget = relPath;
  1417. objTarget += *obj;
  1418. depends.push_back(objTarget);
  1419. }
  1420. // Add dependencies on targets that must be built first.
  1421. this->AppendTargetDepends(depends, target);
  1422. // Add a dependency on the rule file itself.
  1423. objTarget = relPath;
  1424. objTarget += ruleFileName;
  1425. this->AppendRuleDepend(depends, objTarget.c_str());
  1426. // from here up is the same for exe or lib
  1427. for(std::vector<std::string>::const_iterator obj = external_objects.begin();
  1428. obj != external_objects.end(); ++obj)
  1429. {
  1430. depends.push_back(*obj);
  1431. }
  1432. // Get the language to use for linking this library.
  1433. const char* linkLanguage =
  1434. target.GetLinkerLanguage(this->GetGlobalGenerator());
  1435. // Make sure we have a link language.
  1436. if(!linkLanguage)
  1437. {
  1438. cmSystemTools::Error("Cannot determine link language for target \"",
  1439. target.GetName(), "\".");
  1440. return;
  1441. }
  1442. // Create set of linking flags.
  1443. std::string linkFlags;
  1444. this->AppendFlags(linkFlags, extraFlags);
  1445. // Construct the name of the library.
  1446. std::string targetName;
  1447. std::string targetNameSO;
  1448. std::string targetNameReal;
  1449. std::string targetNameBase;
  1450. target.GetLibraryNames(m_Makefile,
  1451. targetName, targetNameSO,
  1452. targetNameReal, targetNameBase);
  1453. // Construct the full path version of the names.
  1454. std::string outpath = m_LibraryOutputPath;
  1455. if(outpath.length() == 0)
  1456. {
  1457. outpath = m_Makefile->GetStartOutputDirectory();
  1458. outpath += "/";
  1459. }
  1460. std::string targetFullPath = outpath + targetName;
  1461. std::string targetFullPathSO = outpath + targetNameSO;
  1462. std::string targetFullPathReal = outpath + targetNameReal;
  1463. std::string targetFullPathBase = outpath + targetNameBase;
  1464. // Construct the output path version of the names for use in command
  1465. // arguments.
  1466. std::string targetOutPath =
  1467. this->Convert(targetFullPath.c_str(),HOME_OUTPUT,MAKEFILE);
  1468. std::string targetOutPathSO =
  1469. this->Convert(targetFullPathSO.c_str(),HOME_OUTPUT,MAKEFILE);
  1470. std::string targetOutPathReal =
  1471. this->Convert(targetFullPathReal.c_str(),HOME_OUTPUT,MAKEFILE);
  1472. std::string targetOutPathBase =
  1473. this->Convert(targetFullPathBase.c_str(),HOME_OUTPUT,MAKEFILE);
  1474. // Add the link message.
  1475. std::string buildEcho = "Linking ";
  1476. buildEcho += linkLanguage;
  1477. switch(target.GetType())
  1478. {
  1479. case cmTarget::STATIC_LIBRARY:
  1480. buildEcho += " static library "; break;
  1481. case cmTarget::SHARED_LIBRARY:
  1482. buildEcho += " shared library "; break;
  1483. case cmTarget::MODULE_LIBRARY:
  1484. buildEcho += " shared module "; break;
  1485. default:
  1486. buildEcho += " library "; break;
  1487. }
  1488. buildEcho += targetOutPath.c_str();
  1489. this->AppendEcho(commands, buildEcho.c_str());
  1490. // Construct a list of files associated with this library that may
  1491. // need to be cleaned.
  1492. std::vector<std::string> libCleanFiles;
  1493. {
  1494. std::string cleanStaticName;
  1495. std::string cleanSharedName;
  1496. std::string cleanSharedSOName;
  1497. std::string cleanSharedRealName;
  1498. target.GetLibraryCleanNames(m_Makefile,
  1499. cleanStaticName,
  1500. cleanSharedName,
  1501. cleanSharedSOName,
  1502. cleanSharedRealName);
  1503. std::string cleanFullStaticName = outpath + cleanStaticName;
  1504. std::string cleanFullSharedName = outpath + cleanSharedName;
  1505. std::string cleanFullSharedSOName = outpath + cleanSharedSOName;
  1506. std::string cleanFullSharedRealName = outpath + cleanSharedRealName;
  1507. libCleanFiles.push_back
  1508. (this->Convert(cleanFullStaticName.c_str(),HOME_OUTPUT,MAKEFILE));
  1509. if(cleanSharedRealName != cleanStaticName)
  1510. {
  1511. libCleanFiles.push_back
  1512. (this->Convert(cleanFullSharedRealName.c_str(),HOME_OUTPUT,MAKEFILE));
  1513. }
  1514. if(cleanSharedSOName != cleanStaticName &&
  1515. cleanSharedSOName != cleanSharedRealName)
  1516. {
  1517. libCleanFiles.push_back
  1518. (this->Convert(cleanFullSharedSOName.c_str(),HOME_OUTPUT,MAKEFILE));
  1519. }
  1520. if(cleanSharedName != cleanStaticName &&
  1521. cleanSharedName != cleanSharedSOName &&
  1522. cleanSharedName != cleanSharedRealName)
  1523. {
  1524. libCleanFiles.push_back
  1525. (this->Convert(cleanFullSharedName.c_str(),HOME_OUTPUT,MAKEFILE));
  1526. }
  1527. }
  1528. // Add a command to remove any existing files for this library.
  1529. this->AppendCleanCommand(commands, libCleanFiles);
  1530. // Add the pre-build and pre-link rules.
  1531. this->AppendCustomCommands(commands, target.GetPreBuildCommands());
  1532. this->AppendCustomCommands(commands, target.GetPreLinkCommands());
  1533. // Construct the main link rule.
  1534. std::string linkRule = m_Makefile->GetRequiredDefinition(linkRuleVar);
  1535. cmSystemTools::ExpandListArgument(linkRule, commands);
  1536. // Add a rule to create necessary symlinks for the library.
  1537. if(targetOutPath != targetOutPathReal)
  1538. {
  1539. std::string symlink = "$(CMAKE_COMMAND) -E cmake_symlink_library ";
  1540. symlink += targetOutPathReal;
  1541. symlink += " ";
  1542. symlink += targetOutPathSO;
  1543. symlink += " ";
  1544. symlink += targetOutPath;
  1545. commands.push_back(symlink);
  1546. }
  1547. // Add the post-build rules.
  1548. this->AppendCustomCommands(commands, target.GetPostBuildCommands());
  1549. // Collect up flags to link in needed libraries.
  1550. cmOStringStream linklibs;
  1551. this->OutputLinkLibraries(linklibs, target.GetName(), target);
  1552. // Construct object file lists that may be needed to expand the
  1553. // rule.
  1554. std::string variableName;
  1555. std::string variableNameExternal;
  1556. this->WriteObjectsVariable(ruleFileStream, target, objects, external_objects,
  1557. variableName, variableNameExternal);
  1558. std::string buildObjs = "$(";
  1559. buildObjs += variableName;
  1560. buildObjs += ") $(";
  1561. buildObjs += variableNameExternal;
  1562. buildObjs += ")";
  1563. std::string cleanObjs = "$(";
  1564. cleanObjs += variableName;
  1565. cleanObjs += ")";
  1566. // Expand placeholders in the commands.
  1567. for(std::vector<std::string>::iterator i = commands.begin();
  1568. i != commands.end(); ++i)
  1569. {
  1570. this->ExpandRuleVariables(*i,
  1571. linkLanguage,
  1572. buildObjs.c_str(),
  1573. targetOutPathReal.c_str(),
  1574. linklibs.str().c_str(),
  1575. 0, 0, 0, buildObjs.c_str(),
  1576. targetOutPathBase.c_str(),
  1577. targetNameSO.c_str(),
  1578. linkFlags.c_str());
  1579. }
  1580. // from here down is the same for exe or lib
  1581. // Write the build rule.
  1582. this->WriteMakeRule(ruleFileStream, 0,
  1583. targetFullPath.c_str(), depends, commands);
  1584. // Write convenience targets.
  1585. std::string dir = m_Makefile->GetStartOutputDirectory();
  1586. dir += "/";
  1587. dir += this->GetTargetDirectory(target);
  1588. std::string buildTargetRuleName = dir;
  1589. buildTargetRuleName += "/build";
  1590. buildTargetRuleName =
  1591. this->Convert(buildTargetRuleName.c_str(),HOME_OUTPUT,MAKEFILE);
  1592. this->WriteConvenienceRule(ruleFileStream, targetFullPath.c_str(),
  1593. buildTargetRuleName.c_str());
  1594. // Clean all the possible library names and symlinks and object files.
  1595. cleanFiles.insert(cleanFiles.end(),libCleanFiles.begin(),libCleanFiles.end());
  1596. cleanFiles.push_back(cleanObjs);
  1597. }
  1598. //----------------------------------------------------------------------------
  1599. void
  1600. cmLocalUnixMakefileGenerator3
  1601. ::WriteObjectsVariable(std::ostream& ruleFileStream,
  1602. cmTarget& target,
  1603. const std::vector<std::string>& objects,
  1604. const std::vector<std::string>& external_objects,
  1605. std::string& variableName,
  1606. std::string& variableNameExternal)
  1607. {
  1608. // Write a make variable assignment that lists all objects for the
  1609. // target.
  1610. variableName = this->CreateMakeVariable(target.GetName(), "_OBJECTS");
  1611. ruleFileStream
  1612. << "# Object files for target " << target.GetName() << "\n"
  1613. << variableName.c_str() << " =";
  1614. std::string relPath = this->GetHomeRelativeOutputPath();
  1615. std::string object;
  1616. for(std::vector<std::string>::const_iterator i = objects.begin();
  1617. i != objects.end(); ++i)
  1618. {
  1619. object = relPath;
  1620. object += *i;
  1621. ruleFileStream
  1622. << " \\\n"
  1623. << this->ConvertToQuotedOutputPath(object.c_str());
  1624. }
  1625. ruleFileStream
  1626. << "\n";
  1627. // Write a make variable assignment that lists all external objects
  1628. // for the target.
  1629. variableNameExternal = this->CreateMakeVariable(target.GetName(),
  1630. "_EXTERNAL_OBJECTS");
  1631. ruleFileStream
  1632. << "\n"
  1633. << "# External object files for target " << target.GetName() << "\n"
  1634. << variableNameExternal.c_str() << " =";
  1635. for(std::vector<std::string>::const_iterator i = external_objects.begin();
  1636. i != external_objects.end(); ++i)
  1637. {
  1638. object = this->Convert(i->c_str(),HOME_OUTPUT);
  1639. ruleFileStream
  1640. << " \\\n"
  1641. << this->ConvertToQuotedOutputPath(object.c_str());
  1642. }
  1643. ruleFileStream
  1644. << "\n"
  1645. << "\n";
  1646. }
  1647. //----------------------------------------------------------------------------
  1648. void
  1649. cmLocalUnixMakefileGenerator3
  1650. ::WriteTargetDependRule(std::ostream& ruleFileStream,
  1651. cmTarget& target,
  1652. const std::vector<std::string>& objects)
  1653. {
  1654. std::vector<std::string> depends;
  1655. std::vector<std::string> no_commands;
  1656. // Construct the name of the dependency generation target.
  1657. std::string depTarget = this->GetRelativeTargetDirectory(target);
  1658. depTarget += "/depend";
  1659. // This target drives dependency generation for all object files.
  1660. std::string relPath = this->GetHomeRelativeOutputPath();
  1661. std::string objTarget;
  1662. for(std::vector<std::string>::const_iterator obj = objects.begin();
  1663. obj != objects.end(); ++obj)
  1664. {
  1665. objTarget = relPath;
  1666. objTarget += *obj;
  1667. objTarget += ".depend";
  1668. depends.push_back(objTarget);
  1669. }
  1670. // Write the rule.
  1671. this->WriteMakeRule(ruleFileStream, 0,
  1672. depTarget.c_str(), depends, no_commands);
  1673. }
  1674. //----------------------------------------------------------------------------
  1675. void
  1676. cmLocalUnixMakefileGenerator3
  1677. ::WriteTargetCleanRule(std::ostream& ruleFileStream,
  1678. cmTarget& target,
  1679. const std::vector<std::string>& files)
  1680. {
  1681. std::vector<std::string> no_depends;
  1682. std::vector<std::string> commands;
  1683. // Construct the clean target name.
  1684. std::string cleanTarget = this->GetRelativeTargetDirectory(target);
  1685. cleanTarget += "/clean";
  1686. // Construct the clean command.
  1687. this->AppendCleanCommand(commands, files);
  1688. // Write the rule.
  1689. this->WriteMakeRule(ruleFileStream, 0,
  1690. cleanTarget.c_str(), no_depends, commands);
  1691. }
  1692. //----------------------------------------------------------------------------
  1693. void
  1694. cmLocalUnixMakefileGenerator3
  1695. ::WriteCMakeArgument(std::ostream& os, const char* s)
  1696. {
  1697. // Write the given string to the stream with escaping to get it back
  1698. // into CMake through the lexical scanner.
  1699. os << "\"";
  1700. for(const char* c = s; *c; ++c)
  1701. {
  1702. if(*c == '\\')
  1703. {
  1704. os << "\\\\";
  1705. }
  1706. else if(*c == '"')
  1707. {
  1708. os << "\\\"";
  1709. }
  1710. else
  1711. {
  1712. os << *c;
  1713. }
  1714. }
  1715. os << "\"";
  1716. }
  1717. //----------------------------------------------------------------------------
  1718. std::string
  1719. cmLocalUnixMakefileGenerator3::GetTargetDirectory(cmTarget& target)
  1720. {
  1721. std::string dir = target.GetName();
  1722. dir += ".dir";
  1723. return dir;
  1724. }
  1725. //----------------------------------------------------------------------------
  1726. std::string
  1727. cmLocalUnixMakefileGenerator3::GetRelativeTargetDirectory(cmTarget& target)
  1728. {
  1729. std::string dir = m_Makefile->GetStartOutputDirectory();
  1730. dir += "/";
  1731. dir += this->GetTargetDirectory(target);
  1732. dir = cmSystemTools::RelativePath(m_Makefile->GetHomeOutputDirectory(), dir.c_str());
  1733. return this->Convert(dir.c_str(),NONE,MAKEFILE);
  1734. }
  1735. //----------------------------------------------------------------------------
  1736. std::string
  1737. cmLocalUnixMakefileGenerator3
  1738. ::GetSubdirTargetName(const char* pass, const char* subdir)
  1739. {
  1740. // Convert the subdirectory name to a relative path to keep it short.
  1741. std::string reldir = this->Convert(subdir,START_OUTPUT);
  1742. // Convert the subdirectory name to a valid make target name.
  1743. std::string s = pass;
  1744. s += "_";
  1745. s += reldir;
  1746. // Replace "../" with 3 underscores. This allows one .. at the beginning.
  1747. size_t pos = s.find("../");
  1748. if(pos != std::string::npos)
  1749. {
  1750. s.replace(pos, 3, "___");
  1751. }
  1752. // Replace "/" directory separators with a single underscore.
  1753. while((pos = s.find('/')) != std::string::npos)
  1754. {
  1755. s.replace(pos, 1, "_");
  1756. }
  1757. // Replace ":" drive specifier with a single underscore
  1758. while((pos = s.find(':')) != std::string::npos)
  1759. {
  1760. s.replace(pos, 1, "_");
  1761. }
  1762. return s;
  1763. }
  1764. //----------------------------------------------------------------------------
  1765. std::string
  1766. cmLocalUnixMakefileGenerator3
  1767. ::GetObjectFileName(cmTarget& target,
  1768. const cmSourceFile& source)
  1769. {
  1770. // If the full path to the source file includes this directory,
  1771. // we want to use the relative path for the filename of the
  1772. // object file. Otherwise, we will use just the filename
  1773. // portion.
  1774. std::string objectName;
  1775. if((cmSystemTools::GetFilenamePath(
  1776. source.GetFullPath()).find(
  1777. m_Makefile->GetCurrentDirectory()) == 0)
  1778. || (cmSystemTools::GetFilenamePath(
  1779. source.GetFullPath()).find(
  1780. m_Makefile->GetStartOutputDirectory()) == 0))
  1781. {
  1782. objectName = source.GetSourceName();
  1783. }
  1784. else
  1785. {
  1786. objectName = cmSystemTools::GetFilenameName(source.GetSourceName());
  1787. }
  1788. // Append the object file extension.
  1789. objectName +=
  1790. m_GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  1791. source.GetSourceExtension().c_str());
  1792. // Convert to a safe name.
  1793. objectName = this->CreateSafeUniqueObjectFileName(objectName.c_str());
  1794. // Prepend the target directory.
  1795. std::string obj = this->GetTargetDirectory(target);
  1796. obj += "/";
  1797. obj += objectName;
  1798. return obj;
  1799. }
  1800. //----------------------------------------------------------------------------
  1801. const char*
  1802. cmLocalUnixMakefileGenerator3
  1803. ::GetSourceFileLanguage(const cmSourceFile& source)
  1804. {
  1805. // Identify the language of the source file.
  1806. return (m_GlobalGenerator
  1807. ->GetLanguageFromExtension(source.GetSourceExtension().c_str()));
  1808. }
  1809. //----------------------------------------------------------------------------
  1810. std::string
  1811. cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p)
  1812. {
  1813. // Split the path into its components.
  1814. std::vector<std::string> components;
  1815. cmSystemTools::SplitPath(p, components);
  1816. // Return an empty path if there are no components.
  1817. if(components.empty())
  1818. {
  1819. return "\"\"";
  1820. }
  1821. // Choose a slash direction and fix root component.
  1822. const char* slash = "/";
  1823. #if defined(_WIN32) && !defined(__CYGWIN__)
  1824. if(!cmSystemTools::GetForceUnixPaths())
  1825. {
  1826. slash = "\\";
  1827. for(std::string::iterator i = components[0].begin();
  1828. i != components[0].end(); ++i)
  1829. {
  1830. if(*i == '/')
  1831. {
  1832. *i = '\\';
  1833. }
  1834. }
  1835. }
  1836. #endif
  1837. // Begin the quoted result with the root component.
  1838. std::string result = "\"";
  1839. result += components[0];
  1840. // Now add the rest of the components separated by the proper slash
  1841. // direction for this platform.
  1842. bool first = true;
  1843. for(unsigned int i=1; i < components.size(); ++i)
  1844. {
  1845. // Only the last component can be empty to avoid double slashes.
  1846. if(components[i].length() > 0 || (i == (components.size()-1)))
  1847. {
  1848. if(!first)
  1849. {
  1850. result += slash;
  1851. }
  1852. result += components[i];
  1853. first = false;
  1854. }
  1855. }
  1856. // Close the quoted result.
  1857. result += "\"";
  1858. return result;
  1859. }
  1860. //----------------------------------------------------------------------------
  1861. void
  1862. cmLocalUnixMakefileGenerator3
  1863. ::AppendTargetDepends(std::vector<std::string>& depends,
  1864. cmTarget& target)
  1865. {
  1866. // Do not bother with dependencies for static libraries.
  1867. if(target.GetType() == cmTarget::STATIC_LIBRARY)
  1868. {
  1869. return;
  1870. }
  1871. // Keep track of dependencies already listed.
  1872. std::set<cmStdString> emitted;
  1873. // A target should not depend on itself.
  1874. emitted.insert(target.GetName());
  1875. // Loop over all library dependencies.
  1876. const cmTarget::LinkLibraries& tlibs = target.GetLinkLibraries();
  1877. for(cmTarget::LinkLibraries::const_iterator lib = tlibs.begin();
  1878. lib != tlibs.end(); ++lib)
  1879. {
  1880. // Don't emit the same library twice for this target.
  1881. if(emitted.insert(lib->first).second)
  1882. {
  1883. // Add this dependency.
  1884. this->AppendAnyDepend(depends, lib->first.c_str());
  1885. }
  1886. }
  1887. // Loop over all utility dependencies.
  1888. // Ken --- we trust that the parent build system handled the utility
  1889. // targets, really we trust that it also handled the libs but there is no
  1890. // harm in listing the libs as depends, if the libs are not present they
  1891. // cannot be built (the rules are not there) but at least it will squak
  1892. #if 0
  1893. const std::set<cmStdString>& tutils = target.GetUtilities();
  1894. for(std::set<cmStdString>::const_iterator util = tutils.begin();
  1895. util != tutils.end(); ++util)
  1896. {
  1897. // Don't emit the same utility twice for this target.
  1898. if(emitted.insert(*util).second)
  1899. {
  1900. // Add this dependency.
  1901. this->AppendAnyDepend(depends, util->c_str());
  1902. }
  1903. }
  1904. #endif
  1905. }
  1906. //----------------------------------------------------------------------------
  1907. void
  1908. cmLocalUnixMakefileGenerator3
  1909. ::AppendAnyDepend(std::vector<std::string>& depends, const char* name,
  1910. bool assume_unknown_is_file)
  1911. {
  1912. // There are a few cases for the name of the target:
  1913. // - CMake target in this directory: depend on it.
  1914. // - CMake target in another directory: depend and add jump-and-build.
  1915. // - Full path to a file: depend on it.
  1916. // - Other format (like -lm): do nothing.
  1917. // If it is an executable or library target there will be a
  1918. // definition for it.
  1919. std::string dirVar = name;
  1920. dirVar += "_CMAKE_PATH";
  1921. const char* dir = m_Makefile->GetDefinition(dirVar.c_str());
  1922. if(dir && *dir)
  1923. {
  1924. // This is a CMake target somewhere in this project.
  1925. // Get the type of the library. If it does not have a type then
  1926. // it is an executable.
  1927. std::string typeVar = name;
  1928. typeVar += "_LIBRARY_TYPE";
  1929. const char* libType = m_Makefile->GetDefinition(typeVar.c_str());
  1930. // Get the output path for this target type.
  1931. std::string tgtOutputPath;
  1932. if(libType)
  1933. {
  1934. tgtOutputPath = m_LibraryOutputPath;
  1935. }
  1936. else
  1937. {
  1938. tgtOutputPath = m_ExecutableOutputPath;
  1939. }
  1940. // Get the path to the target.
  1941. std::string tgtPath;
  1942. if(tgtOutputPath.size())
  1943. {
  1944. tgtPath = tgtOutputPath;
  1945. }
  1946. else
  1947. {
  1948. tgtPath = dir;
  1949. tgtPath += "/";
  1950. }
  1951. // Add the name of the targets's file. This depends on the type
  1952. // of the target.
  1953. std::string prefix;
  1954. std::string suffix;
  1955. if(!libType)
  1956. {
  1957. suffix = cmSystemTools::GetExecutableExtension();
  1958. }
  1959. else if(strcmp(libType, "SHARED") == 0)
  1960. {
  1961. prefix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX");
  1962. suffix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
  1963. }
  1964. else if(strcmp(libType, "MODULE") == 0)
  1965. {
  1966. prefix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_PREFIX");
  1967. suffix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_SUFFIX");
  1968. }
  1969. else if(strcmp(libType, "STATIC") == 0)
  1970. {
  1971. prefix = m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX");
  1972. suffix = m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
  1973. }
  1974. tgtPath += prefix;
  1975. tgtPath += name;
  1976. tgtPath += suffix;
  1977. // Add a dependency on the target.
  1978. depends.push_back(tgtPath.c_str());
  1979. }
  1980. else if(m_Makefile->GetTargets().find(name) !=
  1981. m_Makefile->GetTargets().end())
  1982. {
  1983. // This is a CMake target that is not an executable or library.
  1984. // It must be in this directory, so just depend on the name
  1985. // directly.
  1986. depends.push_back(name);
  1987. }
  1988. else if(cmSystemTools::FileIsFullPath(name))
  1989. {
  1990. // This is a path to a file. Just trust the listfile author that
  1991. // it will be present or there is a rule to build it.
  1992. depends.push_back(cmSystemTools::CollapseFullPath(name));
  1993. }
  1994. else if(assume_unknown_is_file)
  1995. {
  1996. // Just assume this is a file or make target that will be present.
  1997. depends.push_back(name);
  1998. }
  1999. }
  2000. //----------------------------------------------------------------------------
  2001. void
  2002. cmLocalUnixMakefileGenerator3
  2003. ::AppendRuleDepend(std::vector<std::string>& depends,
  2004. const char* ruleFileName)
  2005. {
  2006. // Add a dependency on the rule file itself unless an option to skip
  2007. // it is specifically enabled by the user or project.
  2008. const char* nodep = m_Makefile->GetDefinition("CMAKE_SKIP_RULE_DEPENDENCY");
  2009. if(!nodep || cmSystemTools::IsOff(nodep))
  2010. {
  2011. depends.push_back(ruleFileName);
  2012. }
  2013. }
  2014. //----------------------------------------------------------------------------
  2015. void
  2016. cmLocalUnixMakefileGenerator3
  2017. ::AppendCustomDepends(std::vector<std::string>& depends,
  2018. const std::vector<cmCustomCommand>& ccs)
  2019. {
  2020. for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
  2021. i != ccs.end(); ++i)
  2022. {
  2023. this->AppendCustomDepend(depends, *i);
  2024. }
  2025. }
  2026. //----------------------------------------------------------------------------
  2027. void
  2028. cmLocalUnixMakefileGenerator3
  2029. ::AppendCustomDepend(std::vector<std::string>& depends,
  2030. const cmCustomCommand& cc)
  2031. {
  2032. for(std::vector<std::string>::const_iterator d = cc.GetDepends().begin();
  2033. d != cc.GetDepends().end(); ++d)
  2034. {
  2035. // Add this dependency.
  2036. this->AppendAnyDepend(depends, d->c_str(), true);
  2037. }
  2038. }
  2039. //----------------------------------------------------------------------------
  2040. void
  2041. cmLocalUnixMakefileGenerator3
  2042. ::AppendCustomCommands(std::vector<std::string>& commands,
  2043. const std::vector<cmCustomCommand>& ccs)
  2044. {
  2045. for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
  2046. i != ccs.end(); ++i)
  2047. {
  2048. this->AppendCustomCommand(commands, *i);
  2049. }
  2050. }
  2051. //----------------------------------------------------------------------------
  2052. void
  2053. cmLocalUnixMakefileGenerator3
  2054. ::AppendCustomCommand(std::vector<std::string>& commands,
  2055. const cmCustomCommand& cc)
  2056. {
  2057. // TODO: Convert outputs/dependencies (arguments?) to relative paths.
  2058. std::vector<std::string> commands1;
  2059. // Add each command line to the set of commands.
  2060. for(cmCustomCommandLines::const_iterator cl = cc.GetCommandLines().begin();
  2061. cl != cc.GetCommandLines().end(); ++cl)
  2062. {
  2063. // Build the command line in a single string.
  2064. const cmCustomCommandLine& commandLine = *cl;
  2065. std::string cmd = commandLine[0];
  2066. if (cmd.size())
  2067. {
  2068. cmSystemTools::ReplaceString(cmd, "/./", "/");
  2069. cmd = this->Convert(cmd.c_str(),START_OUTPUT);
  2070. if(cmd.find("/") == cmd.npos &&
  2071. commandLine[0].find("/") != cmd.npos)
  2072. {
  2073. // Add a leading "./" for executables in the current directory.
  2074. cmd = "./" + cmd;
  2075. }
  2076. cmd = this->Convert(cmd.c_str(),NONE,SHELL);
  2077. for(unsigned int j=1; j < commandLine.size(); ++j)
  2078. {
  2079. cmd += " ";
  2080. cmd += cmSystemTools::EscapeSpaces(commandLine[j].c_str());
  2081. }
  2082. commands1.push_back(cmd);
  2083. }
  2084. }
  2085. // stick this group of commands into a cd of the proper path
  2086. // Build the jump-and-build command list.
  2087. if(m_WindowsShell)
  2088. {
  2089. // On Windows we must perform each step separately and then jump
  2090. // back because the shell keeps the working directory between
  2091. // commands.
  2092. std::string cmd = "cd ";
  2093. cmd += this->ConvertToOutputForExisting(m_Makefile->GetStartOutputDirectory());
  2094. commands.push_back(cmd);
  2095. // push back the custom commands
  2096. commands.insert(commands.end(), commands1.begin(), commands1.end());
  2097. // Jump back to the home directory.
  2098. cmd = "cd ";
  2099. cmd += this->ConvertToOutputForExisting(m_Makefile->GetHomeOutputDirectory());
  2100. commands.push_back(cmd);
  2101. }
  2102. else
  2103. {
  2104. // On UNIX we must construct a single shell command to jump and
  2105. // build because make resets the directory between each command.
  2106. std::string cmd = "cd ";
  2107. cmd += this->ConvertToOutputForExisting(m_Makefile->GetStartOutputDirectory());
  2108. // add the commands
  2109. unsigned int i;
  2110. for (i = 0; i < commands1.size(); ++i)
  2111. {
  2112. cmd += " && ";
  2113. cmd += commands1[i];
  2114. }
  2115. // Add the command as a single line.
  2116. commands.push_back(cmd);
  2117. }
  2118. }
  2119. //----------------------------------------------------------------------------
  2120. void
  2121. cmLocalUnixMakefileGenerator3
  2122. ::AppendCleanCommand(std::vector<std::string>& commands,
  2123. const std::vector<std::string>& files)
  2124. {
  2125. if(!files.empty())
  2126. {
  2127. std::string remove = "$(CMAKE_COMMAND) -E remove -f";
  2128. for(std::vector<std::string>::const_iterator f = files.begin();
  2129. f != files.end(); ++f)
  2130. {
  2131. remove += " ";
  2132. remove += this->Convert(f->c_str(),START_OUTPUT,SHELL);
  2133. }
  2134. commands.push_back(remove);
  2135. }
  2136. }
  2137. //----------------------------------------------------------------------------
  2138. void
  2139. cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
  2140. const char* text)
  2141. {
  2142. // Echo one line at a time.
  2143. std::string line;
  2144. for(const char* c = text;; ++c)
  2145. {
  2146. if(*c == '\n' || *c == '\0')
  2147. {
  2148. // Avoid writing a blank last line on end-of-string.
  2149. if(*c != '\0' || !line.empty())
  2150. {
  2151. // Add a command to echo this line.
  2152. std::string cmd = "@echo ";
  2153. if(m_EchoNeedsQuote)
  2154. {
  2155. cmd += "\"";
  2156. }
  2157. cmd += line;
  2158. if(m_EchoNeedsQuote)
  2159. {
  2160. cmd += "\"";
  2161. }
  2162. commands.push_back(cmd);
  2163. }
  2164. // Reset the line to emtpy.
  2165. line = "";
  2166. // Terminate on end-of-string.
  2167. if(*c == '\0')
  2168. {
  2169. return;
  2170. }
  2171. }
  2172. else if(*c != '\r')
  2173. {
  2174. // Append this character to the current line.
  2175. line += *c;
  2176. }
  2177. }
  2178. }
  2179. //============================================================================
  2180. //----------------------------------------------------------------------------
  2181. bool
  2182. cmLocalUnixMakefileGenerator3::SamePath(const char* path1, const char* path2)
  2183. {
  2184. if (strcmp(path1, path2) == 0)
  2185. {
  2186. return true;
  2187. }
  2188. #if defined(_WIN32) || defined(__APPLE__)
  2189. return
  2190. (cmSystemTools::LowerCase(this->ConvertToOutputForExisting(path1)) ==
  2191. cmSystemTools::LowerCase(this->ConvertToOutputForExisting(path2)));
  2192. #else
  2193. return false;
  2194. #endif
  2195. }
  2196. //----------------------------------------------------------------------------
  2197. // take a tgt path and convert it into a make target, it could be full, or relative
  2198. std::string
  2199. cmLocalUnixMakefileGenerator3
  2200. ::ConvertToMakeTarget(const char* tgt)
  2201. {
  2202. // Make targets should not have a leading './' for a file in the
  2203. // directory containing the makefile.
  2204. std::string ret = tgt;
  2205. if(ret.size() > 2 && (ret[0] == '.') &&
  2206. ( (ret[1] == '/') || ret[1] == '\\'))
  2207. {
  2208. std::string upath = ret;
  2209. cmSystemTools::ConvertToUnixSlashes(upath);
  2210. if(upath.find(2, '/') == upath.npos)
  2211. {
  2212. ret = ret.substr(2, ret.size()-2);
  2213. }
  2214. }
  2215. return ret;
  2216. }
  2217. //----------------------------------------------------------------------------
  2218. std::string&
  2219. cmLocalUnixMakefileGenerator3::CreateSafeUniqueObjectFileName(const char* sin)
  2220. {
  2221. if ( m_Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES") )
  2222. {
  2223. std::map<cmStdString,cmStdString>::iterator it = m_UniqueObjectNamesMap.find(sin);
  2224. if ( it == m_UniqueObjectNamesMap.end() )
  2225. {
  2226. std::string ssin = sin;
  2227. bool done;
  2228. int cc = 0;
  2229. char rpstr[100];
  2230. sprintf(rpstr, "_p_");
  2231. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  2232. std::string sssin = sin;
  2233. do
  2234. {
  2235. done = true;
  2236. for ( it = m_UniqueObjectNamesMap.begin();
  2237. it != m_UniqueObjectNamesMap.end();
  2238. ++ it )
  2239. {
  2240. if ( it->second == ssin )
  2241. {
  2242. done = false;
  2243. }
  2244. }
  2245. if ( done )
  2246. {
  2247. break;
  2248. }
  2249. sssin = ssin;
  2250. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  2251. sprintf(rpstr, "_p%d_", cc++);
  2252. }
  2253. while ( !done );
  2254. m_UniqueObjectNamesMap[sin] = ssin;
  2255. }
  2256. }
  2257. else
  2258. {
  2259. m_UniqueObjectNamesMap[sin] = sin;
  2260. }
  2261. return m_UniqueObjectNamesMap[sin];
  2262. }
  2263. //----------------------------------------------------------------------------
  2264. std::string
  2265. cmLocalUnixMakefileGenerator3
  2266. ::CreateMakeVariable(const char* sin, const char* s2in)
  2267. {
  2268. std::string s = sin;
  2269. std::string s2 = s2in;
  2270. std::string unmodified = s;
  2271. unmodified += s2;
  2272. // if there is no restriction on the length of make variables
  2273. // and there are no "." charactors in the string, then return the
  2274. // unmodified combination.
  2275. if(!m_MakefileVariableSize && unmodified.find('.') == s.npos)
  2276. {
  2277. return unmodified;
  2278. }
  2279. // see if the variable has been defined before and return
  2280. // the modified version of the variable
  2281. std::map<cmStdString, cmStdString>::iterator i = m_MakeVariableMap.find(unmodified);
  2282. if(i != m_MakeVariableMap.end())
  2283. {
  2284. return i->second;
  2285. }
  2286. // start with the unmodified variable
  2287. std::string ret = unmodified;
  2288. // if this there is no value for m_MakefileVariableSize then
  2289. // the string must have bad characters in it
  2290. if(!m_MakefileVariableSize)
  2291. {
  2292. cmSystemTools::ReplaceString(ret, ".", "_");
  2293. int ni = 0;
  2294. char buffer[5];
  2295. // make sure the _ version is not already used, if
  2296. // it is used then add number to the end of the variable
  2297. while(m_ShortMakeVariableMap.count(ret) && ni < 1000)
  2298. {
  2299. ++ni;
  2300. sprintf(buffer, "%04d", ni);
  2301. ret = unmodified + buffer;
  2302. }
  2303. m_ShortMakeVariableMap[ret] = "1";
  2304. m_MakeVariableMap[unmodified] = ret;
  2305. return ret;
  2306. }
  2307. // if the string is greater the 32 chars it is an invalid vairable name
  2308. // for borland make
  2309. if(static_cast<int>(ret.size()) > m_MakefileVariableSize)
  2310. {
  2311. int keep = m_MakefileVariableSize - 8;
  2312. int size = keep + 3;
  2313. std::string str1 = s;
  2314. std::string str2 = s2;
  2315. // we must shorten the combined string by 4 charactors
  2316. // keep no more than 24 charactors from the second string
  2317. if(static_cast<int>(str2.size()) > keep)
  2318. {
  2319. str2 = str2.substr(0, keep);
  2320. }
  2321. if(static_cast<int>(str1.size()) + static_cast<int>(str2.size()) > size)
  2322. {
  2323. str1 = str1.substr(0, size - str2.size());
  2324. }
  2325. char buffer[5];
  2326. int ni = 0;
  2327. sprintf(buffer, "%04d", ni);
  2328. ret = str1 + str2 + buffer;
  2329. while(m_ShortMakeVariableMap.count(ret) && ni < 1000)
  2330. {
  2331. ++ni;
  2332. sprintf(buffer, "%04d", ni);
  2333. ret = str1 + str2 + buffer;
  2334. }
  2335. if(ni == 1000)
  2336. {
  2337. cmSystemTools::Error("Borland makefile variable length too long");
  2338. return unmodified;
  2339. }
  2340. // once an unused variable is found
  2341. m_ShortMakeVariableMap[ret] = "1";
  2342. }
  2343. // always make an entry into the unmodified to variable map
  2344. m_MakeVariableMap[unmodified] = ret;
  2345. return ret;
  2346. }
  2347. //============================================================================
  2348. //----------------------------------------------------------------------------
  2349. cmDepends*
  2350. cmLocalUnixMakefileGenerator3::GetDependsChecker(const std::string& lang,
  2351. const char* dir,
  2352. const char* objFile,
  2353. bool verbose)
  2354. {
  2355. cmDepends *ret = 0;
  2356. if(lang == "C" || lang == "CXX" || lang == "RC")
  2357. {
  2358. ret = new cmDependsC();
  2359. }
  2360. #ifdef CMAKE_BUILD_WITH_CMAKE
  2361. else if(lang == "Fortran")
  2362. {
  2363. ret = new cmDependsFortran();
  2364. }
  2365. else if(lang == "Java")
  2366. {
  2367. ret = new cmDependsJava();
  2368. }
  2369. #endif
  2370. if (ret)
  2371. {
  2372. ret->SetTargetFile(dir, objFile, ".depend",".build.depend.make");
  2373. ret->SetCompileDirectory(m_Makefile->GetHomeOutputDirectory());
  2374. ret->SetVerbose(verbose);
  2375. }
  2376. return ret;
  2377. }
  2378. //----------------------------------------------------------------------------
  2379. bool
  2380. cmLocalUnixMakefileGenerator3
  2381. ::ScanDependencies(std::vector<std::string> const& args)
  2382. {
  2383. // Format of arguments is:
  2384. // $(CMAKE_COMMAND), cmake_depends, home_output_dir, start_output_dir, GeneratorName, <lang>, <obj>, <src>
  2385. // The caller has ensured that all required arguments exist.
  2386. // The language for which we are scanning dependencies.
  2387. std::string const& lang = args[5];
  2388. // The file to which to write dependencies.
  2389. const char* objFile = args[6].c_str();
  2390. // The source file at which to start the scan.
  2391. const char* srcFile = args[7].c_str();
  2392. // Read the directory information file.
  2393. cmake cm;
  2394. cmGlobalGenerator gg;
  2395. gg.SetCMakeInstance(&cm);
  2396. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  2397. lg->SetGlobalGenerator(&gg);
  2398. cmMakefile* mf = lg->GetMakefile();
  2399. mf->SetHomeOutputDirectory(args[3].c_str());
  2400. mf->SetStartOutputDirectory(args[4].c_str());
  2401. bool haveDirectoryInfo = false;
  2402. std::string dirInfoFile = args[4];
  2403. dirInfoFile += "/CMakeDirectoryInformation.cmake";
  2404. if(mf->ReadListFile(0, dirInfoFile.c_str()) &&
  2405. !cmSystemTools::GetErrorOccuredFlag())
  2406. {
  2407. haveDirectoryInfo = true;
  2408. }
  2409. // Test whether we need to force Unix paths.
  2410. if(haveDirectoryInfo)
  2411. {
  2412. if(const char* force = mf->GetDefinition("CMAKE_FORCE_UNIX_PATHS"))
  2413. {
  2414. if(!cmSystemTools::IsOff(force))
  2415. {
  2416. cmSystemTools::SetForceUnixPaths(true);
  2417. }
  2418. }
  2419. }
  2420. else
  2421. {
  2422. cmSystemTools::Error("Directory Information file not found");
  2423. }
  2424. // Get the set of include directories.
  2425. std::vector<std::string> includes;
  2426. if(haveDirectoryInfo)
  2427. {
  2428. std::string includePathVar = "CMAKE_";
  2429. includePathVar += lang;
  2430. includePathVar += "_INCLUDE_PATH";
  2431. if(const char* includePath = mf->GetDefinition(includePathVar.c_str()))
  2432. {
  2433. cmSystemTools::ExpandListArgument(includePath, includes);
  2434. }
  2435. }
  2436. // Get the include file regular expression.
  2437. std::string includeRegexScan = "^.*$";
  2438. std::string includeRegexComplain = "^$";
  2439. if(haveDirectoryInfo)
  2440. {
  2441. std::string scanRegexVar = "CMAKE_";
  2442. scanRegexVar += lang;
  2443. scanRegexVar += "_INCLUDE_REGEX_SCAN";
  2444. if(const char* scanRegex = mf->GetDefinition(scanRegexVar.c_str()))
  2445. {
  2446. includeRegexScan = scanRegex;
  2447. }
  2448. std::string complainRegexVar = "CMAKE_";
  2449. complainRegexVar += lang;
  2450. complainRegexVar += "_INCLUDE_REGEX_COMPLAIN";
  2451. if(const char* complainRegex = mf->GetDefinition(complainRegexVar.c_str()))
  2452. {
  2453. includeRegexComplain = complainRegex;
  2454. }
  2455. }
  2456. // Dispatch the scan for each language.
  2457. if(lang == "C" || lang == "CXX" || lang == "RC")
  2458. {
  2459. // TODO: Handle RC (resource files) dependencies correctly.
  2460. cmDependsC scanner(srcFile, includes,
  2461. includeRegexScan.c_str(), includeRegexComplain.c_str());
  2462. scanner.SetTargetFile(".",objFile,".depend",".build.depend.make");
  2463. return scanner.Write();
  2464. }
  2465. #ifdef CMAKE_BUILD_WITH_CMAKE
  2466. else if(lang == "Fortran")
  2467. {
  2468. cmDependsFortran scanner(srcFile, includes);
  2469. scanner.SetTargetFile(".",objFile,".depend",".build.depend.make");
  2470. return scanner.Write();
  2471. }
  2472. else if(lang == "Java")
  2473. {
  2474. cmDependsJava scanner(srcFile);
  2475. scanner.SetTargetFile(".",objFile,".depend",".build.depend.make");
  2476. return scanner.Write();
  2477. }
  2478. #endif
  2479. return false;
  2480. }
  2481. //----------------------------------------------------------------------------
  2482. void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
  2483. {
  2484. // only write the local Makefile if we are not at the top
  2485. if (!m_Parent)
  2486. {
  2487. return;
  2488. }
  2489. // generate the includes
  2490. std::string ruleFileName = "Makefile";
  2491. // Open the rule file. This should be copy-if-different because the
  2492. // rules may depend on this file itself.
  2493. std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
  2494. cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
  2495. ruleFileStream.SetCopyIfDifferent(true);
  2496. if(!ruleFileStream)
  2497. {
  2498. return;
  2499. }
  2500. this->WriteDisclaimer(ruleFileStream);
  2501. this->WriteMakeVariables(ruleFileStream);
  2502. std::vector<std::string> depends;
  2503. std::vector<std::string> commands;
  2504. // Write the all rule.
  2505. std::string dir = m_Makefile->GetStartOutputDirectory();
  2506. dir += "/directorystart";
  2507. dir = this->Convert(dir.c_str(),HOME_OUTPUT,MAKEFILE);
  2508. this->CreateJumpCommand(commands,"Makefile2",dir);
  2509. this->WriteMakeRule(ruleFileStream, "The main all target", "all", depends, commands);
  2510. // Write the clean rule.
  2511. dir = m_Makefile->GetStartOutputDirectory();
  2512. dir += "/clean";
  2513. dir = this->Convert(dir.c_str(),HOME_OUTPUT,MAKEFILE);
  2514. commands.clear();
  2515. this->CreateJumpCommand(commands,"Makefile2",dir);
  2516. this->WriteMakeRule(ruleFileStream, "The main clean target", "clean", depends, commands);
  2517. // recursively write our targets, and while doing it collect up the object
  2518. // file rules
  2519. this->WriteLocalMakefileTargets(ruleFileStream);
  2520. // now write out the object rules
  2521. // for each object file name
  2522. for (std::map<cmStdString,std::vector<cmTarget *> >::iterator lo =
  2523. m_LocalObjectFiles.begin();
  2524. lo != m_LocalObjectFiles.end(); ++lo)
  2525. {
  2526. commands.clear();
  2527. // for each target using the object file
  2528. for (std::vector<cmTarget *>::iterator to =
  2529. lo->second.begin(); to != lo->second.end(); ++to)
  2530. {
  2531. std::string tgtMakefileName = this->GetRelativeTargetDirectory(**to);
  2532. std::string targetName = tgtMakefileName;
  2533. tgtMakefileName += "/build.make";
  2534. targetName += "/";
  2535. targetName += lo->first.c_str();
  2536. this->CreateJumpCommand(commands,tgtMakefileName.c_str(),targetName);
  2537. }
  2538. this->WriteMakeRule(ruleFileStream,
  2539. "target for object file",
  2540. lo->first.c_str(), depends, commands);
  2541. }
  2542. }
  2543. void cmLocalUnixMakefileGenerator3
  2544. ::WriteLocalMakefileTargets(std::ostream& ruleFileStream)
  2545. {
  2546. std::vector<std::string> depends;
  2547. std::vector<std::string> commands;
  2548. // for each target we just provide a rule to cd up to the top and do a make
  2549. // on the target
  2550. cmTargets& targets = m_Makefile->GetTargets();
  2551. std::string localName;
  2552. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  2553. {
  2554. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  2555. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  2556. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  2557. (t->second.GetType() == cmTarget::MODULE_LIBRARY))
  2558. {
  2559. // Add a rule to build the target by name.
  2560. localName = this->GetRelativeTargetDirectory(t->second);
  2561. localName += "/rule";
  2562. commands.clear();
  2563. depends.clear();
  2564. this->CreateJumpCommand(commands,"Makefile2",localName);
  2565. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  2566. localName.c_str(), depends, commands);
  2567. // Add a target with the canonical name (no prefix, suffix or path).
  2568. if(localName != t->second.GetName())
  2569. {
  2570. commands.clear();
  2571. depends.push_back(localName);
  2572. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  2573. t->second.GetName(), depends, commands);
  2574. }
  2575. }
  2576. }
  2577. }
  2578. void cmLocalUnixMakefileGenerator3
  2579. ::CreateJumpCommand(std::vector<std::string>& commands,
  2580. const char *MakefileName,
  2581. std::string& localName)
  2582. {
  2583. if(m_WindowsShell)
  2584. {
  2585. // On Windows we must perform each step separately and then change
  2586. // back because the shell keeps the working directory between
  2587. // commands.
  2588. std::string cmd = "cd ";
  2589. cmd += this->ConvertToOutputForExisting
  2590. (m_Makefile->GetHomeOutputDirectory());
  2591. commands.push_back(cmd);
  2592. // Build the target for this pass.
  2593. commands.push_back(this->GetRecursiveMakeCall
  2594. (MakefileName,localName.c_str()));
  2595. // Change back to the starting directory. Any trailing slash must be
  2596. // removed to avoid problems with Borland Make.
  2597. std::string back =
  2598. cmSystemTools::RelativePath(m_Makefile->GetHomeOutputDirectory(),
  2599. m_Makefile->GetStartOutputDirectory());
  2600. if(back.size() && back[back.size()-1] == '/')
  2601. {
  2602. back = back.substr(0, back.size()-1);
  2603. }
  2604. cmd = "cd ";
  2605. cmd += this->ConvertToOutputForExisting(back.c_str());
  2606. commands.push_back(cmd);
  2607. }
  2608. else
  2609. {
  2610. // On UNIX we must construct a single shell command to change
  2611. // directory and build because make resets the directory between
  2612. // each command.
  2613. std::string cmd = "cd ";
  2614. cmd += this->ConvertToOutputForExisting(m_Makefile->GetHomeOutputDirectory());
  2615. // Build the target for this pass.
  2616. cmd += " && ";
  2617. cmd += this->GetRecursiveMakeCall(MakefileName,localName.c_str());
  2618. // Add the command as a single line.
  2619. commands.push_back(cmd);
  2620. }
  2621. }
  2622. //----------------------------------------------------------------------------
  2623. void cmLocalUnixMakefileGenerator3::CheckDependencies(cmMakefile* mf,
  2624. bool verbose,
  2625. bool clear)
  2626. {
  2627. // Get the list of languages that may have sources to check.
  2628. const char* langDef = mf->GetDefinition("CMAKE_DEPENDS_LANGUAGES");
  2629. if(!langDef)
  2630. {
  2631. return;
  2632. }
  2633. std::vector<std::string> languages;
  2634. cmSystemTools::ExpandListArgument(langDef, languages);
  2635. // For each language get the set of files to check.
  2636. for(std::vector<std::string>::iterator l = languages.begin();
  2637. l != languages.end(); ++l)
  2638. {
  2639. std::string depCheck = "CMAKE_DEPENDS_CHECK_";
  2640. depCheck += *l;
  2641. if(const char* fileDef = mf->GetDefinition(depCheck.c_str()))
  2642. {
  2643. // Check each file. The current working directory is already
  2644. // correct.
  2645. std::vector<std::string> files;
  2646. cmSystemTools::ExpandListArgument(fileDef, files);
  2647. for(std::vector<std::string>::iterator f = files.begin();
  2648. f != files.end(); ++f)
  2649. {
  2650. // Construct a checker for the given language.
  2651. std::auto_ptr<cmDepends>
  2652. checker(this->GetDependsChecker(*l, ".", f->c_str(), verbose));
  2653. if(checker.get())
  2654. {
  2655. if (clear)
  2656. {
  2657. checker->Clear();
  2658. }
  2659. else
  2660. {
  2661. checker->Check();
  2662. }
  2663. }
  2664. }
  2665. }
  2666. }
  2667. }
  2668. //----------------------------------------------------------------------------
  2669. std::string
  2670. cmLocalUnixMakefileGenerator3
  2671. ::GetRecursiveMakeCall(const char *Makefile, const char* tgt)
  2672. {
  2673. // Call make on the given file.
  2674. std::string cmd;
  2675. cmd += "$(MAKE) -f ";
  2676. cmd += Makefile;
  2677. cmd += " ";
  2678. // Passg down verbosity level.
  2679. if(this->GetMakeSilentFlag().size())
  2680. {
  2681. cmd += this->GetMakeSilentFlag();
  2682. cmd += " ";
  2683. }
  2684. // Most unix makes will pass the command line flags to make down to
  2685. // sub-invoked makes via an environment variable. However, some
  2686. // makes do not support that, so you have to pass the flags
  2687. // explicitly.
  2688. if(this->GetPassMakeflags())
  2689. {
  2690. cmd += "-$(MAKEFLAGS) ";
  2691. }
  2692. // Add the target.
  2693. if (tgt && tgt[0] != '\0')
  2694. {
  2695. std::string tgt2 = this->Convert(tgt,HOME_OUTPUT,MAKEFILE);
  2696. tgt2 = this->ConvertToMakeTarget(tgt2.c_str());
  2697. cmd += tgt2;
  2698. }
  2699. return cmd;
  2700. }