cmLocalUnixMakefileGenerator3.cxx 96 KB

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