cmLocalUnixMakefileGenerator3.cxx 99 KB

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