cmLocalUnixMakefileGenerator3.cxx 97 KB

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