cmLocalUnixMakefileGenerator.cxx 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901
  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 "cmGlobalGenerator.h"
  14. #include "cmLocalUnixMakefileGenerator.h"
  15. #include "cmMakefile.h"
  16. #include "cmSystemTools.h"
  17. #include "cmSourceFile.h"
  18. #include "cmMakeDepend.h"
  19. #include "cmCacheManager.h"
  20. #include "cmGeneratedFileStream.h"
  21. #include <cmsys/RegularExpression.hxx>
  22. cmLocalUnixMakefileGenerator::cmLocalUnixMakefileGenerator()
  23. {
  24. m_WindowsShell = false;
  25. m_IncludeDirective = "include";
  26. m_MakefileVariableSize = 0;
  27. m_IgnoreLibPrefix = false;
  28. m_PassMakeflags = false;
  29. m_UseRelativePaths = false;
  30. }
  31. cmLocalUnixMakefileGenerator::~cmLocalUnixMakefileGenerator()
  32. {
  33. }
  34. void cmLocalUnixMakefileGenerator::Generate(bool fromTheTop)
  35. {
  36. this->ConfigureOutputPaths();
  37. if (!fromTheTop)
  38. {
  39. // Generate depends
  40. cmMakeDepend md;
  41. md.SetMakefile(m_Makefile);
  42. md.GenerateMakefileDependencies();
  43. this->ProcessDepends(md);
  44. }
  45. // output the makefile fragment
  46. std::string dest = m_Makefile->GetStartOutputDirectory();
  47. dest += "/Makefile";
  48. this->OutputMakefile(dest.c_str(), !fromTheTop);
  49. }
  50. //----------------------------------------------------------------------------
  51. void
  52. cmLocalUnixMakefileGenerator::ConfigureOutputPaths()
  53. {
  54. m_UseRelativePaths = m_Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS");
  55. // suppoirt override in output directories
  56. if (m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  57. {
  58. m_LibraryOutputPath = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  59. if(m_LibraryOutputPath.size())
  60. {
  61. m_LibraryOutputPath =
  62. cmSystemTools::CollapseFullPath(m_LibraryOutputPath.c_str(),
  63. m_Makefile->GetStartOutputDirectory());
  64. if(m_LibraryOutputPath[m_LibraryOutputPath.size() -1] != '/')
  65. {
  66. m_LibraryOutputPath += "/";
  67. }
  68. if(!cmSystemTools::MakeDirectory(m_LibraryOutputPath.c_str()))
  69. {
  70. cmSystemTools::Error("Error failed create "
  71. "LIBRARY_OUTPUT_PATH directory:",
  72. m_LibraryOutputPath.c_str());
  73. }
  74. m_Makefile->AddLinkDirectory(m_LibraryOutputPath.c_str());
  75. }
  76. }
  77. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  78. {
  79. m_ExecutableOutputPath =
  80. m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  81. if(m_ExecutableOutputPath.size())
  82. {
  83. m_ExecutableOutputPath =
  84. cmSystemTools::CollapseFullPath(m_ExecutableOutputPath.c_str(),
  85. m_Makefile->GetStartOutputDirectory());
  86. if(m_ExecutableOutputPath[m_ExecutableOutputPath.size() -1] != '/')
  87. {
  88. m_ExecutableOutputPath += "/";
  89. }
  90. if(!cmSystemTools::MakeDirectory(m_ExecutableOutputPath.c_str()))
  91. {
  92. cmSystemTools::Error("Error failed to create "
  93. "EXECUTABLE_OUTPUT_PATH directory:",
  94. m_ExecutableOutputPath.c_str());
  95. }
  96. m_Makefile->AddLinkDirectory(m_ExecutableOutputPath.c_str());
  97. }
  98. }
  99. }
  100. void
  101. cmLocalUnixMakefileGenerator::AddDependenciesToSourceFile(cmDependInformation const *info,
  102. cmSourceFile *i,
  103. std::set<cmDependInformation const*> *visited)
  104. {
  105. // add info to the visited set
  106. visited->insert(info);
  107. // add this dependency and the recurse
  108. // now recurse with info's dependencies
  109. for(cmDependInformation::DependencySet::const_iterator d =
  110. info->m_DependencySet.begin();
  111. d != info->m_DependencySet.end(); ++d)
  112. {
  113. if (visited->find(*d) == visited->end())
  114. {
  115. if((*d)->m_FullPath != "")
  116. {
  117. i->GetDepends().push_back((*d)->m_FullPath.c_str());
  118. }
  119. this->AddDependenciesToSourceFile(*d,i,visited);
  120. }
  121. }
  122. }
  123. void cmLocalUnixMakefileGenerator::ProcessDepends(const cmMakeDepend &md)
  124. {
  125. // Now create cmDependInformation objects for files in the directory
  126. cmTargets &tgts = m_Makefile->GetTargets();
  127. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  128. {
  129. std::vector<cmSourceFile*> &classes = l->second.GetSourceFiles();
  130. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  131. i != classes.end(); ++i)
  132. {
  133. if(!(*i)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  134. {
  135. // get the depends
  136. const cmDependInformation *info =
  137. md.GetDependInformationForSourceFile(*(*i));
  138. // Delete any hints from the source file's dependencies.
  139. (*i)->GetDepends().erase((*i)->GetDepends().begin(), (*i)->GetDepends().end());
  140. // Now add the real dependencies for the file.
  141. if (info)
  142. {
  143. // create visited set
  144. std::set<cmDependInformation const*> visited;
  145. this->AddDependenciesToSourceFile(info,*i, &visited);
  146. }
  147. }
  148. }
  149. }
  150. }
  151. // This is where CMakeTargets.make is generated
  152. void cmLocalUnixMakefileGenerator::OutputMakefile(const char* file,
  153. bool withDepends)
  154. {
  155. // Create sub directories fro aux source directories
  156. std::vector<std::string>& auxSourceDirs =
  157. m_Makefile->GetAuxSourceDirectories();
  158. if( auxSourceDirs.size() )
  159. {
  160. // For the case when this is running as a remote build
  161. // on unix, make the directory
  162. for(std::vector<std::string>::iterator i = auxSourceDirs.begin();
  163. i != auxSourceDirs.end(); ++i)
  164. {
  165. if(i->c_str()[0] != '/')
  166. {
  167. std::string dir = m_Makefile->GetCurrentOutputDirectory();
  168. if(dir.size() && dir[dir.size()-1] != '/')
  169. {
  170. dir += "/";
  171. }
  172. dir += *i;
  173. cmSystemTools::MakeDirectory(dir.c_str());
  174. }
  175. else
  176. {
  177. cmSystemTools::MakeDirectory(i->c_str());
  178. }
  179. }
  180. }
  181. // Create a stream that writes to a temporary file
  182. // then does a copy at the end. This is to allow users
  183. // to hit control-c during the make of the makefile
  184. cmGeneratedFileStream fout(file);
  185. if(!fout)
  186. {
  187. return;
  188. }
  189. fout << "# CMAKE generated Makefile, DO NOT EDIT!\n"
  190. << "# Generated by \"" << m_GlobalGenerator->GetName() << "\""
  191. << " Generator, CMake Version "
  192. << cmMakefile::GetMajorVersion() << "."
  193. << cmMakefile::GetMinorVersion() << "\n"
  194. << "# Generated from the following files:\n# "
  195. << m_Makefile->GetHomeOutputDirectory() << "/CMakeCache.txt\n";
  196. std::vector<std::string> lfiles = m_Makefile->GetListFiles();
  197. // sort the array
  198. std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>());
  199. // remove duplicates
  200. std::vector<std::string>::iterator new_end =
  201. std::unique(lfiles.begin(), lfiles.end());
  202. lfiles.erase(new_end, lfiles.end());
  203. for(std::vector<std::string>::const_iterator i = lfiles.begin();
  204. i != lfiles.end(); ++i)
  205. {
  206. fout << "# " << i->c_str() << "\n";
  207. }
  208. fout << "\n\n";
  209. fout << "# disable some common implicit rules to speed things up\n";
  210. fout << ".SUFFIXES:\n";
  211. fout << ".SUFFIXES:.hpuxmakemusthaverule\n";
  212. // create a make variable with all of the sources for this Makefile
  213. // for depend purposes.
  214. fout << "CMAKE_MAKEFILE_SOURCES = ";
  215. for(std::vector<std::string>::const_iterator i = lfiles.begin();
  216. i != lfiles.end(); ++i)
  217. {
  218. fout << " " << this->ConvertToRelativeOutputPath(i->c_str());
  219. }
  220. // Add the cache to the list
  221. std::string cacheFile = m_Makefile->GetHomeOutputDirectory();
  222. cacheFile += "/CMakeCache.txt";
  223. fout << " " << this->ConvertToRelativeOutputPath(cacheFile.c_str());
  224. fout << "\n\n\n";
  225. this->OutputMakeVariables(fout);
  226. std::string checkCache = m_Makefile->GetHomeOutputDirectory();
  227. checkCache += "/cmake.check_cache";
  228. checkCache = this->ConvertToRelativeOutputPath(checkCache.c_str());
  229. // most unix makes will pass the command line flags to make down
  230. // to sub invoked makes via an environment variable. However, some
  231. // makes do not support that, so you have to pass the flags explicitly
  232. const char* allRule = "$(MAKE) $(MAKESILENT) all";
  233. if(m_PassMakeflags)
  234. {
  235. allRule = "$(MAKE) $(MAKESILENT) -$(MAKEFLAGS) all";
  236. }
  237. // Set up the default target as the VERY first target, so that make with no arguments will run it
  238. this->
  239. OutputMakeRule(fout,
  240. "Default target executed when no arguments are given to make, first make sure cmake.depends exists, cmake.check_depends is up-to-date, check the sources, then build the all target",
  241. "default_target",
  242. checkCache.c_str(),
  243. "$(MAKE) $(MAKESILENT) cmake.depends",
  244. "$(MAKE) $(MAKESILENT) cmake.check_depends",
  245. "$(MAKE) $(MAKESILENT) -f cmake.check_depends",
  246. allRule);
  247. // Generation of SILENT target must be after default_target.
  248. if(!m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  249. {
  250. fout << "# Suppresses display of executed commands\n";
  251. fout << "$(VERBOSE).SILENT:\n\n";
  252. }
  253. this->OutputTargetRules(fout);
  254. this->OutputDependLibs(fout);
  255. this->OutputTargets(fout);
  256. this->OutputSubDirectoryRules(fout);
  257. std::string dependName = m_Makefile->GetStartOutputDirectory();
  258. dependName += "/cmake.depends";
  259. if(withDepends)
  260. {
  261. std::ofstream dependout(dependName.c_str());
  262. if(!dependout)
  263. {
  264. cmSystemTools::Error("Error can not open for write: ", dependName.c_str());
  265. return;
  266. }
  267. dependout << "# .o dependencies in this directory." << std::endl;
  268. std::string checkDepend = m_Makefile->GetStartOutputDirectory();
  269. checkDepend += "/cmake.check_depends";
  270. std::ofstream checkdependout(checkDepend.c_str());
  271. if(!checkdependout)
  272. {
  273. cmSystemTools::Error("Error can not open for write: ", checkDepend.c_str());
  274. return;
  275. }
  276. checkdependout << "# This file is used as a tag file, that all sources depend on. If a source changes, then the rule to rebuild this file will cause cmake.depends to be rebuilt." << std::endl;
  277. // if there were any depends output, then output the check depends
  278. // information inot checkdependout
  279. if(this->OutputObjectDepends(dependout))
  280. {
  281. this->OutputCheckDepends(checkdependout);
  282. }
  283. else
  284. {
  285. checkdependout << "all:\n\t@echo cmake.depends is up-to-date\n";
  286. }
  287. }
  288. this->OutputCustomRules(fout);
  289. this->OutputMakeRules(fout);
  290. // only add the depend include if the depend file exists
  291. if(cmSystemTools::FileExists(dependName.c_str()))
  292. {
  293. fout << m_IncludeDirective << " cmake.depends\n";
  294. }
  295. }
  296. std::string cmLocalUnixMakefileGenerator::GetBaseTargetName(const char* n,
  297. const cmTarget& t)
  298. {
  299. std::string pathPrefix = "";
  300. #ifdef __APPLE__
  301. if ( t.GetPropertyAsBool("MACOSX_BUNDLE") )
  302. {
  303. pathPrefix = n;
  304. pathPrefix += ".app/Contents/MacOS/";
  305. }
  306. #endif
  307. const char* targetPrefix = t.GetProperty("PREFIX");
  308. const char* prefixVar = t.GetPrefixVariable();
  309. // if there is no prefix on the target use the cmake definition
  310. if(!targetPrefix && prefixVar)
  311. {
  312. // first check for a language specific suffix var
  313. const char* ll = t.GetLinkerLanguage(this->GetGlobalGenerator());
  314. if(ll)
  315. {
  316. std::string langPrefix = prefixVar + std::string("_") + ll;
  317. targetPrefix = m_Makefile->GetDefinition(langPrefix.c_str());
  318. }
  319. // if there not a language specific suffix then use the general one
  320. if(!targetPrefix)
  321. {
  322. targetPrefix = m_Makefile->GetSafeDefinition(prefixVar);
  323. }
  324. }
  325. std::string name = pathPrefix + (targetPrefix?targetPrefix:"");
  326. name += n;
  327. return name;
  328. }
  329. // Output the rules for any targets
  330. void cmLocalUnixMakefileGenerator::OutputEcho(std::ostream& fout,
  331. const char *msg)
  332. {
  333. std::string echostring = msg;
  334. // for unix we want to quote the output of echo
  335. // for nmake and borland, the echo should not be quoted
  336. if(strcmp(m_GlobalGenerator->GetName(), "Unix Makefiles") == 0)
  337. {
  338. cmSystemTools::ReplaceString(echostring, "\\\n", " ");
  339. cmSystemTools::ReplaceString(echostring, " \t", " ");
  340. cmSystemTools::ReplaceString(echostring, "\n\t", "\"\n\t@echo \"");
  341. fout << "\t@echo \"" << echostring.c_str() << "\"\n";
  342. }
  343. else
  344. {
  345. cmSystemTools::ReplaceString(echostring, "\n\t", "\n\t@echo ");
  346. fout << "\t@echo " << echostring.c_str() << "\n";
  347. }
  348. }
  349. // Output the rules for any targets
  350. void cmLocalUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
  351. {
  352. const cmTargets &tgts = m_Makefile->GetTargets();
  353. // add the help target
  354. fout << "help:\n";
  355. this->OutputEcho(fout,"The following are some of the valid targets for this Makefile:");
  356. this->OutputEcho(fout,"... all (the default if no target is provided)");
  357. this->OutputEcho(fout,"... clean");
  358. this->OutputEcho(fout,"... depend");
  359. this->OutputEcho(fout,"... install");
  360. this->OutputEcho(fout,"... rebuild_cache");
  361. // libraries
  362. std::string path;
  363. for(cmTargets::const_iterator l = tgts.begin();
  364. l != tgts.end(); l++)
  365. {
  366. if((l->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  367. (l->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  368. (l->second.GetType() == cmTarget::MODULE_LIBRARY))
  369. {
  370. std::string path2 = m_LibraryOutputPath;
  371. path2 += this->GetFullTargetName(l->first.c_str(), l->second);
  372. path = "... ";
  373. path += this->ConvertToRelativeOutputPath(path2.c_str());
  374. this->OutputEcho(fout,path.c_str());
  375. }
  376. }
  377. // executables
  378. for(cmTargets::const_iterator l = tgts.begin();
  379. l != tgts.end(); l++)
  380. {
  381. if ( l->second.GetType() == cmTarget::EXECUTABLE )
  382. {
  383. path = "... ";
  384. path += l->first + cmSystemTools::GetExecutableExtension();
  385. this->OutputEcho(fout,path.c_str());
  386. }
  387. }
  388. // list utilities last
  389. for(cmTargets::const_iterator l = tgts.begin();
  390. l != tgts.end(); l++)
  391. {
  392. if (l->second.GetType() == cmTarget::UTILITY)
  393. {
  394. path = "... ";
  395. path += l->first;
  396. this->OutputEcho(fout,path.c_str());
  397. }
  398. }
  399. fout << "\n\n";
  400. // for each target add to the list of targets
  401. fout << "TARGETS = ";
  402. // list libraries first
  403. for(cmTargets::const_iterator l = tgts.begin();
  404. l != tgts.end(); l++)
  405. {
  406. if (l->second.IsInAll())
  407. {
  408. if((l->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  409. (l->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  410. (l->second.GetType() == cmTarget::MODULE_LIBRARY))
  411. {
  412. path = m_LibraryOutputPath;
  413. path += this->GetFullTargetName(l->first.c_str(), l->second);
  414. fout << " \\\n"
  415. << this->ConvertToMakeTarget(this->ConvertToRelativeOutputPath(path.c_str()).c_str());
  416. }
  417. }
  418. }
  419. // executables
  420. for(cmTargets::const_iterator l = tgts.begin();
  421. l != tgts.end(); l++)
  422. {
  423. if (l->second.GetType() == cmTarget::EXECUTABLE &&
  424. l->second.IsInAll())
  425. {
  426. path = m_ExecutableOutputPath;
  427. path += this->GetFullTargetName(l->first.c_str(), l->second);
  428. fout << " \\\n" << this->ConvertToMakeTarget(this->ConvertToRelativeOutputPath(path.c_str()).c_str());
  429. }
  430. }
  431. // list utilities last
  432. for(cmTargets::const_iterator l = tgts.begin();
  433. l != tgts.end(); l++)
  434. {
  435. if (l->second.GetType() == cmTarget::UTILITY &&
  436. l->second.IsInAll())
  437. {
  438. fout << " \\\n" << l->first.c_str();
  439. }
  440. }
  441. fout << "\n\n";
  442. std::string outputName;
  443. // get the classes from the source lists then add them to the groups
  444. for(cmTargets::const_iterator l = tgts.begin();
  445. l != tgts.end(); l++)
  446. {
  447. std::vector<cmSourceFile*> classes = l->second.GetSourceFiles();
  448. if (classes.begin() != classes.end())
  449. {
  450. fout << this->CreateMakeVariable(l->first.c_str(), "_SRC_OBJS") << " = ";
  451. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  452. i != classes.end(); i++)
  453. {
  454. if(!(*i)->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  455. !(*i)->GetCustomCommand())
  456. {
  457. std::string outExt =
  458. m_GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  459. (*i)->GetSourceExtension().c_str());
  460. if(outExt.size() && !(*i)->GetPropertyAsBool("EXTERNAL_OBJECT") )
  461. {
  462. fout << "\\\n";
  463. std::string ofname = (*i)->GetSourceName() + outExt;
  464. ofname = this->CreateSafeUniqueObjectFileName(ofname.c_str());
  465. fout << this->ConvertToMakeTarget(this->ConvertToRelativeOutputPath(ofname.c_str()).c_str());
  466. }
  467. }
  468. }
  469. fout << "\n\n";
  470. fout << this->CreateMakeVariable(l->first.c_str(), "_EXTERNAL_OBJS") << " = ";
  471. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  472. i != classes.end(); i++)
  473. {
  474. if(!(*i)->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  475. !(*i)->GetCustomCommand())
  476. {
  477. std::string outExt =
  478. m_GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  479. (*i)->GetSourceExtension().c_str());
  480. if(outExt.size() && (*i)->GetPropertyAsBool("EXTERNAL_OBJECT") )
  481. {
  482. fout << "\\\n";
  483. fout << this->ConvertToMakeTarget(this->ConvertToRelativeOutputPath((*i)->GetFullPath().c_str()).c_str()) << " ";
  484. }
  485. }
  486. }
  487. fout << "\n\n";
  488. fout << this->CreateMakeVariable(l->first.c_str(), "_SRC_OBJS_QUOTED") << " = ";
  489. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  490. i != classes.end(); i++)
  491. {
  492. if(!(*i)->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  493. !(*i)->GetCustomCommand())
  494. {
  495. std::string outExt =
  496. m_GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  497. (*i)->GetSourceExtension().c_str());
  498. if(outExt.size() && !(*i)->GetPropertyAsBool("EXTERNAL_OBJECT") )
  499. {
  500. std::string ofname = (*i)->GetSourceName() + outExt;
  501. ofname = this->CreateSafeUniqueObjectFileName(ofname.c_str());
  502. outputName = this->ConvertToMakeTarget(ConvertToRelativeOutputPath(ofname.c_str()).c_str());
  503. fout << "\\\n";
  504. // if it already is double quoted because of spaces don't do it again.
  505. if(outputName.size() && outputName[0] != '\"')
  506. {
  507. fout << "\"" << outputName << "\" ";
  508. }
  509. else
  510. {
  511. fout << outputName << " ";
  512. }
  513. }
  514. }
  515. }
  516. fout << "\n\n";
  517. fout << this->CreateMakeVariable(l->first.c_str(), "_EXTERNAL_OBJS_QUOTED") << " = ";
  518. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  519. i != classes.end(); i++)
  520. {
  521. if(!(*i)->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  522. !(*i)->GetCustomCommand())
  523. {
  524. std::string outExt =
  525. m_GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  526. (*i)->GetSourceExtension().c_str());
  527. if(outExt.size() && (*i)->GetPropertyAsBool("EXTERNAL_OBJECT") )
  528. {
  529. outputName =
  530. this->ConvertToMakeTarget(ConvertToRelativeOutputPath((*i)->GetFullPath().c_str()).c_str());
  531. fout << "\\\n";
  532. // if it already is double quoted because of spaces don't do it again.
  533. if(outputName.size() && outputName[0] != '\"')
  534. {
  535. fout << "\"" << outputName << "\" ";
  536. }
  537. else
  538. {
  539. fout << outputName << " ";
  540. }
  541. }
  542. }
  543. }
  544. fout << "\n\n";
  545. }
  546. }
  547. // This list contains extra files created for a target. It includes
  548. // the extra names associated with a versioned shared library.
  549. fout << "TARGET_EXTRAS = ";
  550. for(cmTargets::const_iterator l = tgts.begin();
  551. l != tgts.end(); l++)
  552. {
  553. if (l->second.IsInAll())
  554. {
  555. if(l->second.GetType() == cmTarget::SHARED_LIBRARY ||
  556. l->second.GetType() == cmTarget::MODULE_LIBRARY)
  557. {
  558. std::string targetName;
  559. std::string targetNameSO;
  560. std::string targetNameReal;
  561. std::string targetNameBase;
  562. this->GetLibraryNames(l->first.c_str(), l->second,
  563. targetName, targetNameSO,
  564. targetNameReal, targetNameBase);
  565. if(targetNameSO != targetName)
  566. {
  567. path = m_LibraryOutputPath;
  568. path += targetNameSO;
  569. fout << " \\\n"
  570. << this->ConvertToRelativeOutputPath(path.c_str());
  571. }
  572. if(targetNameReal != targetName &&
  573. targetNameReal != targetNameSO)
  574. {
  575. path = m_LibraryOutputPath;
  576. path += targetNameReal;
  577. fout << " \\\n"
  578. << this->ConvertToRelativeOutputPath(path.c_str());
  579. }
  580. }
  581. }
  582. }
  583. fout << "\n\n";
  584. fout << "CLEAN_OBJECT_FILES = ";
  585. for(cmTargets::const_iterator l = tgts.begin();
  586. l != tgts.end(); l++)
  587. {
  588. std::vector<cmSourceFile*> classes = l->second.GetSourceFiles();
  589. if (classes.begin() != classes.end())
  590. {
  591. fout << "$(" << this->CreateMakeVariable(l->first.c_str(), "_SRC_OBJS")
  592. << ") ";
  593. }
  594. }
  595. fout << "\n\n";
  596. const char * additional_clean_files =
  597. m_Makefile->GetProperty("ADDITIONAL_MAKE_CLEAN_FILES");
  598. if ( additional_clean_files && strlen(additional_clean_files) > 0 )
  599. {
  600. std::string arg = additional_clean_files;
  601. std::vector<std::string> args;
  602. cmSystemTools::ExpandListArgument(arg, args);
  603. fout << "ADDITIONAL_MAKE_CLEAN_FILES = ";
  604. for(std::vector<std::string>::iterator i = args.begin(); i != args.end(); ++i)
  605. {
  606. fout << this->ConvertToRelativeOutputPath(i->c_str()) << " ";
  607. }
  608. fout << "\n\n";
  609. }
  610. const char * qt_files = m_Makefile->GetDefinition("GENERATED_QT_FILES");
  611. if (qt_files != NULL &&
  612. strlen(m_Makefile->GetDefinition("GENERATED_QT_FILES"))>0)
  613. {
  614. fout << "GENERATED_QT_FILES = ";
  615. fout << qt_files;
  616. fout << "\n\n";
  617. }
  618. }
  619. std::string cmLocalUnixMakefileGenerator::CreatePreBuildRules(
  620. const cmTarget &target, const char* /* targetName */)
  621. {
  622. std::string customRuleCode = "";
  623. bool initNext = false;
  624. for (std::vector<cmCustomCommand>::const_iterator cr =
  625. target.GetPreBuildCommands().begin();
  626. cr != target.GetPreBuildCommands().end(); ++cr)
  627. {
  628. cmCustomCommand cc(*cr);
  629. cc.ExpandVariables(*m_Makefile);
  630. if(initNext)
  631. {
  632. customRuleCode += "\n\t";
  633. }
  634. else
  635. {
  636. initNext = true;
  637. }
  638. std::string command = this->ConvertToRelativeOutputPath(cc.GetCommand().c_str());
  639. customRuleCode += command + " " + cc.GetArguments();
  640. }
  641. return customRuleCode;
  642. }
  643. std::string cmLocalUnixMakefileGenerator::CreatePreLinkRules(
  644. const cmTarget &target, const char* /* targetName */)
  645. {
  646. std::string customRuleCode = "";
  647. bool initNext = false;
  648. for (std::vector<cmCustomCommand>::const_iterator cr =
  649. target.GetPreLinkCommands().begin();
  650. cr != target.GetPreLinkCommands().end(); ++cr)
  651. {
  652. cmCustomCommand cc(*cr);
  653. cc.ExpandVariables(*m_Makefile);
  654. if(initNext)
  655. {
  656. customRuleCode += "\n\t";
  657. }
  658. else
  659. {
  660. initNext = true;
  661. }
  662. std::string command = this->ConvertToRelativeOutputPath(cc.GetCommand().c_str());
  663. customRuleCode += command + " " + cc.GetArguments();
  664. }
  665. return customRuleCode;
  666. }
  667. std::string cmLocalUnixMakefileGenerator::CreatePostBuildRules(
  668. const cmTarget &target, const char* /* targetName */)
  669. {
  670. std::string customRuleCode = "";
  671. bool initNext = false;
  672. for (std::vector<cmCustomCommand>::const_iterator cr =
  673. target.GetPostBuildCommands().begin();
  674. cr != target.GetPostBuildCommands().end(); ++cr)
  675. {
  676. cmCustomCommand cc(*cr);
  677. cc.ExpandVariables(*m_Makefile);
  678. if(initNext)
  679. {
  680. customRuleCode += "\n\t";
  681. }
  682. else
  683. {
  684. initNext = true;
  685. }
  686. std::string command = this->ConvertToRelativeOutputPath(cc.GetCommand().c_str());
  687. customRuleCode += command + " " + cc.GetArguments();
  688. }
  689. return customRuleCode;
  690. }
  691. void cmLocalUnixMakefileGenerator::OutputLibraryRule(std::ostream& fout,
  692. const char* name,
  693. const cmTarget &t,
  694. const char* createVariable,
  695. const char* comment,
  696. const char* linkFlags
  697. )
  698. {
  699. std::string targetName;
  700. std::string targetNameSO;
  701. std::string targetNameReal;
  702. std::string targetNameBase;
  703. this->GetLibraryNames(name, t,
  704. targetName, targetNameSO,
  705. targetNameReal, targetNameBase);
  706. std::string outpath;
  707. std::string outdir;
  708. if(m_UseRelativePaths)
  709. {
  710. outdir = this->ConvertToRelativeOutputPath(m_LibraryOutputPath.c_str());
  711. }
  712. else
  713. {
  714. outdir = m_LibraryOutputPath;
  715. }
  716. if(!m_WindowsShell && m_UseRelativePaths && outdir.size())
  717. {
  718. outpath = "\"`cd ";
  719. }
  720. outpath += outdir;
  721. if(!m_WindowsShell && m_UseRelativePaths && outdir.size())
  722. {
  723. outpath += ";pwd`\"/";
  724. }
  725. if(outdir.size() == 0 && m_UseRelativePaths && !m_WindowsShell)
  726. {
  727. outpath = "\"`pwd`\"/";
  728. }
  729. // The full path versions of the names.
  730. std::string targetFullPath = outpath + targetName;
  731. std::string targetFullPathSO = outpath + targetNameSO;
  732. std::string targetFullPathReal = outpath + targetNameReal;
  733. std::string targetFullPathBase = outpath + targetNameBase;
  734. // If not using relative paths then the output path needs to be
  735. // converted here
  736. if(!m_UseRelativePaths)
  737. {
  738. targetFullPath = this->ConvertToRelativeOutputPath(targetFullPath.c_str());
  739. targetFullPathSO = this->ConvertToRelativeOutputPath(targetFullPathSO.c_str());
  740. targetFullPathReal = this->ConvertToRelativeOutputPath(targetFullPathReal.c_str());
  741. targetFullPathBase = this->ConvertToRelativeOutputPath(targetFullPathBase.c_str());
  742. }
  743. // get the objects that are used to link this library
  744. std::string objs = "$(" + this->CreateMakeVariable(name, "_SRC_OBJS")
  745. + ") $(" + this->CreateMakeVariable(name, "_EXTERNAL_OBJS") + ") ";
  746. std::string objsQuoted = "$(" + this->CreateMakeVariable(name, "_SRC_OBJS_QUOTED")
  747. + ") $(" + this->CreateMakeVariable(name, "_EXTERNAL_OBJS_QUOTED") + ") ";
  748. // create a variable with the objects that this library depends on
  749. std::string depend =
  750. objs + " $(" + this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
  751. std::vector<std::string> commands;
  752. std::string cmakecommand = this->ConvertToOutputForExisting(
  753. m_Makefile->GetRequiredDefinition("CMAKE_COMMAND"));
  754. // Remove any existing files for this library.
  755. std::string remove = cmakecommand;
  756. remove += " -E remove -f ";
  757. remove += targetFullPathReal;
  758. if(targetFullPathSO != targetFullPathReal)
  759. {
  760. remove += " ";
  761. remove += targetFullPathSO;
  762. }
  763. if(targetFullPath != targetFullPathSO &&
  764. targetFullPath != targetFullPathReal)
  765. {
  766. remove += " ";
  767. remove += targetFullPath;
  768. }
  769. commands.push_back(remove);
  770. // collect custom commands for this target and add them to the list
  771. std::string customCommands = this->CreatePreBuildRules(t, name);
  772. if(customCommands.size() > 0)
  773. {
  774. commands.push_back(customCommands);
  775. }
  776. // collect custom commands for this target and add them to the list
  777. customCommands = this->CreatePreLinkRules(t, name);
  778. if(customCommands.size() > 0)
  779. {
  780. commands.push_back(customCommands);
  781. }
  782. // collect up the build rules
  783. std::vector<std::string> rules;
  784. rules.push_back(m_Makefile->GetRequiredDefinition(createVariable));
  785. // expand multi-command semi-colon separated lists
  786. // of commands into separate commands
  787. cmSystemTools::ExpandList(rules, commands);
  788. // Create necessary symlinks for library.
  789. if(targetFullPath != targetFullPathReal)
  790. {
  791. std::string symlink = cmakecommand;
  792. symlink += " -E cmake_symlink_library ";
  793. symlink += targetFullPathReal;
  794. symlink += " ";
  795. symlink += targetFullPathSO;
  796. symlink += " ";
  797. symlink += targetFullPath;
  798. commands.push_back(symlink);
  799. }
  800. // collect custom commands for this target and add them to the list
  801. customCommands = this->CreatePostBuildRules(t, name);
  802. if(customCommands.size() > 0)
  803. {
  804. commands.push_back(customCommands);
  805. }
  806. // collect up the link libraries
  807. cmOStringStream linklibs;
  808. this->OutputLinkLibraries(linklibs, name, t);
  809. for(std::vector<std::string>::iterator i = commands.begin();
  810. i != commands.end(); ++i)
  811. {
  812. this->ExpandRuleVariables(*i,
  813. t.GetLinkerLanguage(m_GlobalGenerator),
  814. objs.c_str(),
  815. targetFullPathReal.c_str(),
  816. linklibs.str().c_str(),
  817. 0, 0, 0, objsQuoted.c_str(),
  818. targetFullPathBase.c_str(),
  819. targetNameSO.c_str(),
  820. linkFlags);
  821. }
  822. targetFullPath = m_LibraryOutputPath + targetName;
  823. this->OutputMakeRule(fout, comment,
  824. targetFullPath.c_str(),
  825. depend.c_str(),
  826. commands);
  827. depend = targetFullPath;
  828. std::string tgt = this->ConvertToRelativeOutputPath(targetFullPath.c_str());
  829. tgt = this->ConvertToMakeTarget(tgt.c_str());
  830. cmSystemTools::ConvertToUnixSlashes(tgt);
  831. if(tgt.find('/', 0) != tgt.npos)
  832. {
  833. // we need a local target
  834. depend = this->ConvertToRelativeOutputPath(depend.c_str());
  835. std::string target = targetName;
  836. commands.resize(0);
  837. this->OutputMakeRule(fout,
  838. comment,
  839. target.c_str(),
  840. depend.c_str(),
  841. commands);
  842. }
  843. // Add a target with the canonical name (no prefix, suffix or path).
  844. this->OutputMakeRule(fout,
  845. comment,
  846. name,
  847. this->ConvertToRelativeOutputPath(tgt.c_str()).c_str(),
  848. 0);
  849. }
  850. void cmLocalUnixMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
  851. const char* name,
  852. const cmTarget &t)
  853. {
  854. const char* linkLanguage = t.GetLinkerLanguage(this->GetGlobalGenerator());
  855. if(!linkLanguage)
  856. {
  857. cmSystemTools::Error("CMake can not determine linker language target:",
  858. t.GetName());
  859. return;
  860. }
  861. std::string createRule = "CMAKE_";
  862. createRule += linkLanguage;
  863. createRule += "_CREATE_SHARED_LIBRARY";
  864. std::string buildType = m_Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  865. buildType = cmSystemTools::UpperCase(buildType);
  866. std::string linkFlags = m_Makefile->GetSafeDefinition("CMAKE_SHARED_LINKER_FLAGS");
  867. linkFlags += " ";
  868. if(buildType.size())
  869. {
  870. std::string build = "CMAKE_SHARED_LINKER_FLAGS_";
  871. build += buildType;
  872. linkFlags += m_Makefile->GetSafeDefinition(build.c_str());
  873. linkFlags += " ";
  874. }
  875. if(m_Makefile->IsOn("WIN32") && !(m_Makefile->IsOn("CYGWIN") || m_Makefile->IsOn("MINGW")))
  876. {
  877. const std::vector<cmSourceFile*>& sources = t.GetSourceFiles();
  878. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  879. i != sources.end(); ++i)
  880. {
  881. if((*i)->GetSourceExtension() == "def")
  882. {
  883. linkFlags += m_Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  884. linkFlags += this->ConvertToRelativeOutputPath((*i)->GetFullPath().c_str());
  885. linkFlags += " ";
  886. }
  887. }
  888. }
  889. const char* targetLinkFlags = t.GetProperty("LINK_FLAGS");
  890. if(targetLinkFlags)
  891. {
  892. linkFlags += targetLinkFlags;
  893. linkFlags += " ";
  894. }
  895. this->OutputLibraryRule(fout, name, t,
  896. createRule.c_str(),
  897. "shared library",
  898. linkFlags.c_str());
  899. }
  900. void cmLocalUnixMakefileGenerator::OutputModuleLibraryRule(std::ostream& fout,
  901. const char* name,
  902. const cmTarget &t)
  903. {
  904. const char* linkLanguage = t.GetLinkerLanguage(this->GetGlobalGenerator());
  905. if(!linkLanguage)
  906. {
  907. cmSystemTools::Error("CMake can not determine linker language for target:",
  908. t.GetName());
  909. return;
  910. }
  911. std::string createRule = "CMAKE_";
  912. createRule += linkLanguage;
  913. createRule += "_CREATE_SHARED_MODULE";
  914. std::string buildType = m_Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  915. buildType = cmSystemTools::UpperCase(buildType);
  916. std::string linkFlags = m_Makefile->GetSafeDefinition("CMAKE_MODULE_LINKER_FLAGS");
  917. linkFlags += " ";
  918. if(buildType.size())
  919. {
  920. std::string build = "CMAKE_MODULE_LINKER_FLAGS_";
  921. build += buildType;
  922. linkFlags += m_Makefile->GetSafeDefinition(build.c_str());
  923. linkFlags += " ";
  924. }
  925. const char* targetLinkFlags = t.GetProperty("LINK_FLAGS");
  926. if(targetLinkFlags)
  927. {
  928. linkFlags += targetLinkFlags;
  929. linkFlags += " ";
  930. }
  931. this->OutputLibraryRule(fout, name, t,
  932. createRule.c_str(),
  933. "shared module",
  934. linkFlags.c_str());
  935. }
  936. void cmLocalUnixMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
  937. const char* name,
  938. const cmTarget &t)
  939. {
  940. const char* linkLanguage = t.GetLinkerLanguage(this->GetGlobalGenerator());
  941. if(!linkLanguage)
  942. {
  943. cmSystemTools::Error("CMake can not determine linker language for target:",
  944. t.GetName());
  945. return;
  946. }
  947. std::string createRule = "CMAKE_";
  948. createRule += linkLanguage;
  949. createRule += "_CREATE_STATIC_LIBRARY";
  950. std::string linkFlags;
  951. const char* targetLinkFlags = t.GetProperty("STATIC_LIBRARY_FLAGS");
  952. if(targetLinkFlags)
  953. {
  954. linkFlags += targetLinkFlags;
  955. linkFlags += " ";
  956. }
  957. this->OutputLibraryRule(fout, name, t,
  958. createRule.c_str(),
  959. "static library",
  960. linkFlags.c_str());
  961. }
  962. void cmLocalUnixMakefileGenerator::OutputExecutableRule(std::ostream& fout,
  963. const char* name,
  964. const cmTarget &t)
  965. {
  966. std::string linkFlags;
  967. std::string buildType = m_Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  968. buildType = cmSystemTools::UpperCase(buildType);
  969. std::string flags;
  970. // Construct the full path to the executable that will be generated.
  971. std::string target = m_ExecutableOutputPath;
  972. if(target.length() == 0)
  973. {
  974. target = m_Makefile->GetCurrentOutputDirectory();
  975. if(target.size() && target[target.size()-1] != '/')
  976. {
  977. target += "/";
  978. }
  979. }
  980. #ifdef __APPLE__
  981. if ( t.GetPropertyAsBool("MACOSX_BUNDLE") )
  982. {
  983. // Make bundle directories
  984. target += name;
  985. target += ".app/Contents/MacOS/";
  986. }
  987. #endif
  988. target += name;
  989. target += cmSystemTools::GetExecutableExtension();
  990. target = this->ConvertToRelativeOutputPath(target.c_str());
  991. bool needsLocalTarget = false;
  992. if(m_UseRelativePaths)
  993. {
  994. cmSystemTools::ConvertToUnixSlashes(target);
  995. std::string tgt = this->ConvertToMakeTarget(target.c_str());
  996. if(tgt.find('/', 0) != tgt.npos)
  997. {
  998. needsLocalTarget = true;
  999. }
  1000. target = cmSystemTools::ConvertToOutputPath(target.c_str());
  1001. }
  1002. else
  1003. {
  1004. needsLocalTarget = true;
  1005. }
  1006. std::string objs = "$(" + this->CreateMakeVariable(name, "_SRC_OBJS") +
  1007. ") $(" + this->CreateMakeVariable(name, "_EXTERNAL_OBJS") + ") ";
  1008. std::string depend = "$(";
  1009. depend += this->CreateMakeVariable(name, "_SRC_OBJS")
  1010. + ") $(" + this->CreateMakeVariable(name, "_EXTERNAL_OBJS")
  1011. + ") $(" + this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
  1012. std::vector<std::string> rules;
  1013. linkFlags += m_Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
  1014. linkFlags += " ";
  1015. if(buildType.size())
  1016. {
  1017. std::string build = "CMAKE_EXE_LINKER_FLAGS_";
  1018. build += buildType;
  1019. linkFlags += m_Makefile->GetSafeDefinition(build.c_str());
  1020. linkFlags += " ";
  1021. }
  1022. const char* linkLanguage = t.GetLinkerLanguage(this->GetGlobalGenerator());
  1023. if(!linkLanguage)
  1024. {
  1025. cmSystemTools::Error("CMake can not determine linker language for target:",
  1026. t.GetName());
  1027. return;
  1028. }
  1029. std::string langVar = "CMAKE_";
  1030. langVar += linkLanguage;
  1031. std::string ruleVar = langVar + "_LINK_EXECUTABLE";
  1032. std::string flagsVar = langVar + "_FLAGS";
  1033. std::string sharedFlagsVar = "CMAKE_SHARED_LIBRARY_";
  1034. sharedFlagsVar += langVar;
  1035. sharedFlagsVar += "_FLAGS";
  1036. rules.push_back(m_Makefile->GetRequiredDefinition(ruleVar.c_str()));
  1037. flags += m_Makefile->GetSafeDefinition(flagsVar.c_str());
  1038. flags += " ";
  1039. flags += m_Makefile->GetSafeDefinition(sharedFlagsVar.c_str());
  1040. flags += " ";
  1041. cmOStringStream linklibs;
  1042. this->OutputLinkLibraries(linklibs, 0, t);
  1043. std::string comment = "executable";
  1044. std::vector<std::string> commands;
  1045. std::string customCommands = this->CreatePreBuildRules(t, name);
  1046. if(customCommands.size() > 0)
  1047. {
  1048. commands.push_back(customCommands.c_str());
  1049. }
  1050. customCommands = this->CreatePreLinkRules(t, name);
  1051. if(customCommands.size() > 0)
  1052. {
  1053. commands.push_back(customCommands.c_str());
  1054. }
  1055. cmSystemTools::ExpandList(rules, commands);
  1056. customCommands = this->CreatePostBuildRules(t, name);
  1057. if(customCommands.size() > 0)
  1058. {
  1059. commands.push_back(customCommands.c_str());
  1060. }
  1061. if(cmSystemTools::IsOn(m_Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1062. {
  1063. std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_") + linkLanguage
  1064. + std::string("_FLAGS");
  1065. linkFlags += m_Makefile->GetSafeDefinition(sFlagVar.c_str());
  1066. linkFlags += " ";
  1067. }
  1068. if ( t.GetPropertyAsBool("WIN32_EXECUTABLE") )
  1069. {
  1070. linkFlags += m_Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
  1071. linkFlags += " ";
  1072. }
  1073. else
  1074. {
  1075. linkFlags += m_Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
  1076. linkFlags += " ";
  1077. }
  1078. const char* targetLinkFlags = t.GetProperty("LINK_FLAGS");
  1079. if(targetLinkFlags)
  1080. {
  1081. linkFlags += targetLinkFlags;
  1082. linkFlags += " ";
  1083. }
  1084. for(std::vector<std::string>::iterator i = commands.begin();
  1085. i != commands.end(); ++i)
  1086. {
  1087. this->ExpandRuleVariables(*i,
  1088. linkLanguage,
  1089. objs.c_str(),
  1090. target.c_str(),
  1091. linklibs.str().c_str(),
  1092. 0,
  1093. 0,
  1094. flags.c_str(),
  1095. 0,
  1096. 0,
  1097. 0,
  1098. linkFlags.c_str());
  1099. }
  1100. this->OutputMakeRule(fout,
  1101. comment.c_str(),
  1102. target.c_str(),
  1103. depend.c_str(),
  1104. commands);
  1105. // If there is no executable output path, add a rule with the
  1106. // relative path to the executable. This is necessary for
  1107. // try-compile to work in this case.
  1108. if(needsLocalTarget)
  1109. {
  1110. depend = target;
  1111. target = name;
  1112. target += cmSystemTools::GetExecutableExtension();
  1113. target = this->ConvertToRelativeOutputPath(target.c_str());
  1114. commands.resize(0);
  1115. this->OutputMakeRule(fout,
  1116. comment.c_str(),
  1117. target.c_str(),
  1118. depend.c_str(),
  1119. commands);
  1120. }
  1121. // Add a target with the canonical name (no prefix, suffix or path).
  1122. // Note that on some platforms the "local target" added above will
  1123. // actually be the canonical name and will have set "target"
  1124. // correctly. Do not duplicate this target.
  1125. if(target != name)
  1126. {
  1127. this->OutputMakeRule(fout, comment.c_str(), name, target.c_str(), 0);
  1128. }
  1129. }
  1130. void cmLocalUnixMakefileGenerator::OutputUtilityRule(std::ostream& fout,
  1131. const char* name,
  1132. const cmTarget &t)
  1133. {
  1134. const char* cc = 0;
  1135. std::string customCommands = this->CreatePreBuildRules(t, name);
  1136. std::string customCommands2 = this->CreatePreLinkRules(t, name);
  1137. if(customCommands2.size() > 0)
  1138. {
  1139. customCommands += customCommands2;
  1140. }
  1141. customCommands2 = this->CreatePostBuildRules(t, name);
  1142. if(customCommands2.size() > 0)
  1143. {
  1144. customCommands += customCommands2;
  1145. }
  1146. if(customCommands.size() > 0)
  1147. {
  1148. cc = customCommands.c_str();
  1149. }
  1150. std::string comment = "Utility";
  1151. std::string depends;
  1152. depends = "$(" + this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
  1153. std::string replaceVars;
  1154. const std::vector<cmCustomCommand> &ccs = t.GetPostBuildCommands();
  1155. for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
  1156. i != ccs.end(); ++i)
  1157. {
  1158. const std::vector<std::string> & dep = i->GetDepends();
  1159. for(std::vector<std::string>::const_iterator d = dep.begin();
  1160. d != dep.end(); ++d)
  1161. {
  1162. depends += " \\\n";
  1163. replaceVars = *d;
  1164. m_Makefile->ExpandVariablesInString(replaceVars);
  1165. depends += this->ConvertToMakeTarget(this->ConvertToRelativeOutputPath(replaceVars.c_str()).c_str());
  1166. }
  1167. }
  1168. this->OutputMakeRule(fout, comment.c_str(), name,
  1169. depends.c_str(), cc);
  1170. }
  1171. void cmLocalUnixMakefileGenerator::OutputTargets(std::ostream& fout)
  1172. {
  1173. // for each target
  1174. const cmTargets &tgts = m_Makefile->GetTargets();
  1175. for(cmTargets::const_iterator l = tgts.begin();
  1176. l != tgts.end(); l++)
  1177. {
  1178. switch(l->second.GetType())
  1179. {
  1180. case cmTarget::STATIC_LIBRARY:
  1181. this->OutputStaticLibraryRule(fout, l->first.c_str(), l->second);
  1182. break;
  1183. case cmTarget::SHARED_LIBRARY:
  1184. this->OutputSharedLibraryRule(fout, l->first.c_str(), l->second);
  1185. break;
  1186. case cmTarget::MODULE_LIBRARY:
  1187. this->OutputModuleLibraryRule(fout, l->first.c_str(), l->second);
  1188. break;
  1189. case cmTarget::EXECUTABLE:
  1190. this->OutputExecutableRule(fout, l->first.c_str(), l->second);
  1191. break;
  1192. case cmTarget::UTILITY:
  1193. this->OutputUtilityRule(fout, l->first.c_str(), l->second);
  1194. break;
  1195. // This is handled by the OutputCustomRules method
  1196. case cmTarget::INSTALL_FILES:
  1197. // This is handled by the OutputInstallRules method
  1198. case cmTarget::INSTALL_PROGRAMS:
  1199. // This is handled by the OutputInstallRules method
  1200. break;
  1201. }
  1202. }
  1203. }
  1204. // For each target that is an executable or shared library, generate
  1205. // the "<name>_DEPEND_LIBS" variable listing its library dependencies.
  1206. void cmLocalUnixMakefileGenerator::OutputDependLibs(std::ostream& fout)
  1207. {
  1208. // Build a set of libraries that will be linked into any target in
  1209. // this directory.
  1210. std::set<cmStdString> used;
  1211. // for each target
  1212. const cmTargets &tgts = m_Makefile->GetTargets();
  1213. for(cmTargets::const_iterator l = tgts.begin();
  1214. l != tgts.end(); l++)
  1215. {
  1216. // Each dependency should only be emitted once per target.
  1217. std::set<cmStdString> emitted;
  1218. if ((l->second.GetType() == cmTarget::SHARED_LIBRARY)
  1219. || (l->second.GetType() == cmTarget::MODULE_LIBRARY)
  1220. || (l->second.GetType() == cmTarget::STATIC_LIBRARY)
  1221. || (l->second.GetType() == cmTarget::EXECUTABLE)
  1222. || (l->second.GetType() == cmTarget::UTILITY))
  1223. {
  1224. fout << this->CreateMakeVariable(l->first.c_str(), "_DEPEND_LIBS") << " = ";
  1225. // A library should not depend on itself!
  1226. emitted.insert(l->first);
  1227. // for static libraries do not depend on other libraries
  1228. if(l->second.GetType() != cmTarget::STATIC_LIBRARY)
  1229. {
  1230. // Now, look at all link libraries specific to this target.
  1231. const cmTarget::LinkLibraries& tlibs = l->second.GetLinkLibraries();
  1232. for(cmTarget::LinkLibraries::const_iterator lib = tlibs.begin();
  1233. lib != tlibs.end(); ++lib)
  1234. {
  1235. // Record that this library was used.
  1236. used.insert(lib->first);
  1237. // Don't emit the same library twice for this target.
  1238. if(emitted.insert(lib->first).second)
  1239. {
  1240. // Output this dependency.
  1241. this->OutputLibDepend(fout, lib->first.c_str());
  1242. }
  1243. }
  1244. }
  1245. // for all targets depend on utilities
  1246. // Now, look at all utilities specific to this target.
  1247. const std::set<cmStdString>& tutils = l->second.GetUtilities();
  1248. for(std::set<cmStdString>::const_iterator util = tutils.begin();
  1249. util != tutils.end(); ++util)
  1250. {
  1251. // Record that this utility was used.
  1252. used.insert(*util);
  1253. // Don't emit the same utility twice for this target.
  1254. if(emitted.insert(*util).second)
  1255. {
  1256. // Output this dependency.
  1257. std::string utilType = *util + "_LIBRARY_TYPE";
  1258. const char* libType = m_Makefile->GetDefinition(utilType.c_str());
  1259. if ( libType )
  1260. {
  1261. this->OutputLibDepend(fout, util->c_str());
  1262. }
  1263. else
  1264. {
  1265. this->OutputExeDepend(fout, util->c_str());
  1266. }
  1267. }
  1268. }
  1269. fout << "\n";
  1270. }
  1271. }
  1272. fout << "\n";
  1273. // Loop over the libraries used and make sure there is a rule to
  1274. // build them in this makefile. If the library is in another
  1275. // directory, add a rule to jump to that directory and make sure it
  1276. // exists.
  1277. for(std::set<cmStdString>::const_iterator lib = used.begin();
  1278. lib != used.end(); ++lib)
  1279. {
  1280. // loop over the list of directories that the libraries might
  1281. // be in, looking for an ADD_LIBRARY(lib...) line. This would
  1282. // be stored in the cache
  1283. std::string libPath = *lib + "_CMAKE_PATH";
  1284. const char* cacheValue = m_Makefile->GetDefinition(libPath.c_str());
  1285. // if cache and not the current directory add a rule, to
  1286. // jump into the directory and build for the first time
  1287. if(cacheValue && *cacheValue &&
  1288. (!this->SamePath(m_Makefile->GetCurrentOutputDirectory(), cacheValue)))
  1289. {
  1290. // add the correct extension
  1291. std::string ltname = *lib+"_LIBRARY_TYPE";
  1292. const char* libType
  1293. = m_Makefile->GetDefinition(ltname.c_str());
  1294. // if it was a library..
  1295. if (libType)
  1296. {
  1297. std::string library;
  1298. std::string libpath = cacheValue;
  1299. if(libType && std::string(libType) == "SHARED")
  1300. {
  1301. library = m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX");
  1302. library += *lib;
  1303. library += m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
  1304. }
  1305. else if(libType && std::string(libType) == "MODULE")
  1306. {
  1307. library = m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_PREFIX");
  1308. library += *lib;
  1309. library += m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_SUFFIX");
  1310. }
  1311. else if(libType && std::string(libType) == "STATIC")
  1312. {
  1313. library = m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX");
  1314. library += *lib;
  1315. library += m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
  1316. }
  1317. else
  1318. {
  1319. cmSystemTools::Error("Unknown library type!");
  1320. return;
  1321. }
  1322. if(m_LibraryOutputPath.size())
  1323. {
  1324. libpath = m_LibraryOutputPath;
  1325. }
  1326. else
  1327. {
  1328. libpath += "/";
  1329. }
  1330. libpath += library;
  1331. // put out a rule to build the library if it does not exist
  1332. this->OutputBuildTargetInDir(fout,
  1333. cacheValue,
  1334. library.c_str(),
  1335. libpath.c_str());
  1336. }
  1337. // something other than a library...
  1338. else
  1339. {
  1340. std::string exepath = cacheValue;
  1341. if(m_ExecutableOutputPath.size())
  1342. {
  1343. exepath = m_ExecutableOutputPath;
  1344. }
  1345. else
  1346. {
  1347. exepath += "/";
  1348. }
  1349. std::string fullName = lib->c_str();
  1350. fullName += cmSystemTools::GetExecutableExtension();
  1351. exepath += fullName;
  1352. this->OutputBuildTargetInDir(fout,
  1353. cacheValue,
  1354. fullName.c_str(),
  1355. exepath.c_str());
  1356. }
  1357. }
  1358. }
  1359. }
  1360. void cmLocalUnixMakefileGenerator::OutputBuildTargetInDirWindows(std::ostream& fout,
  1361. const char* path,
  1362. const char* library,
  1363. const char* fullpath)
  1364. {
  1365. std::string jumpBack;
  1366. if(m_UseRelativePaths)
  1367. {
  1368. jumpBack = cmSystemTools::RelativePath(cmSystemTools::GetProgramPath(path).c_str(),
  1369. m_Makefile->GetCurrentOutputDirectory());
  1370. }
  1371. else
  1372. {
  1373. jumpBack = m_Makefile->GetCurrentOutputDirectory();
  1374. }
  1375. jumpBack = this->ConvertToOutputForExisting(jumpBack.c_str());
  1376. std::string wpath = this->ConvertToOutputForExisting(path);
  1377. std::string wfullpath = this->ConvertToRelativeOutputPath(fullpath);
  1378. fout << wfullpath
  1379. << ":\n\tcd " << wpath << "\n"
  1380. << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) cmake.depends\n"
  1381. << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) cmake.check_depends\n"
  1382. << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) -f cmake.check_depends\n"
  1383. << "\t$(MAKE) $(MAKESILENT) " << library
  1384. << "\n\tcd " << jumpBack << "\n";
  1385. }
  1386. void cmLocalUnixMakefileGenerator::OutputBuildTargetInDir(std::ostream& fout,
  1387. const char* path,
  1388. const char* library,
  1389. const char* fullpath)
  1390. {
  1391. if(m_WindowsShell)
  1392. {
  1393. this->OutputBuildTargetInDirWindows(fout, path, library, fullpath);
  1394. return;
  1395. }
  1396. fout << this->ConvertToOutputForExisting(fullpath)
  1397. << ":\n\tcd " << this->ConvertToOutputForExisting(path)
  1398. << "; $(MAKE) $(MAKESILENT) cmake.depends"
  1399. << "; $(MAKE) $(MAKESILENT) cmake.check_depends"
  1400. << "; $(MAKE) $(MAKESILENT) -f cmake.check_depends"
  1401. << "; $(MAKE) $(MAKESILENT) "
  1402. << library << "\n\n";
  1403. }
  1404. bool cmLocalUnixMakefileGenerator::SamePath(const char* path1, const char* path2)
  1405. {
  1406. if (strcmp(path1, path2) == 0)
  1407. {
  1408. return true;
  1409. }
  1410. #if defined(_WIN32) || defined(__APPLE__)
  1411. return
  1412. cmSystemTools::LowerCase(this->ConvertToOutputForExisting(path1)) ==
  1413. cmSystemTools::LowerCase(this->ConvertToOutputForExisting(path2));
  1414. #else
  1415. return false;
  1416. #endif
  1417. }
  1418. void cmLocalUnixMakefileGenerator::OutputLibDepend(std::ostream& fout,
  1419. const char* name)
  1420. {
  1421. std::string libPath = name;
  1422. libPath += "_CMAKE_PATH";
  1423. const char* cacheValue = m_Makefile->GetDefinition(libPath.c_str());
  1424. if( cacheValue && *cacheValue )
  1425. {
  1426. // if there is a cache value, then this is a library that cmake
  1427. // knows how to build, so we can depend on it
  1428. std::string libpath;
  1429. if (!this->SamePath(m_Makefile->GetCurrentOutputDirectory(), cacheValue))
  1430. {
  1431. // if the library is not in the current directory, then get the full
  1432. // path to it
  1433. if(m_LibraryOutputPath.size())
  1434. {
  1435. libpath = m_LibraryOutputPath;
  1436. }
  1437. else
  1438. {
  1439. libpath = cacheValue;
  1440. libpath += "/";
  1441. }
  1442. }
  1443. else
  1444. {
  1445. // library is in current Makefile so use lib as a prefix
  1446. libpath = m_LibraryOutputPath;
  1447. }
  1448. // add the correct extension
  1449. std::string ltname = name;
  1450. ltname += "_LIBRARY_TYPE";
  1451. const char* libType = m_Makefile->GetDefinition(ltname.c_str());
  1452. if(libType && std::string(libType) == "SHARED")
  1453. {
  1454. libpath += m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX");
  1455. libpath += name;
  1456. libpath += m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
  1457. }
  1458. else if (libType && std::string(libType) == "MODULE")
  1459. {
  1460. libpath += m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_PREFIX");
  1461. libpath += name;
  1462. libpath += m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_SUFFIX");
  1463. }
  1464. else if (libType && std::string(libType) == "STATIC")
  1465. {
  1466. libpath += m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX");
  1467. libpath += name;
  1468. libpath += m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
  1469. }
  1470. fout << this->ConvertToRelativeOutputPath(libpath.c_str()) << " ";
  1471. }
  1472. else
  1473. {
  1474. if(cmSystemTools::FileExists(name))
  1475. {
  1476. std::string nameStr = name;
  1477. // if it starts with / or \ or ?:/ or ?:\ then it must be a full path
  1478. if( (nameStr.size() && (nameStr[0] == '/' || nameStr[0] == '\\')) ||
  1479. ((nameStr.size() > 3) && (nameStr[1] == ':') && (nameStr[2] == '/' || nameStr[2] == '\\')))
  1480. {
  1481. fout << this->ConvertToRelativeOutputPath(name) << " ";
  1482. }
  1483. }
  1484. }
  1485. }
  1486. void cmLocalUnixMakefileGenerator::OutputExeDepend(std::ostream& fout,
  1487. const char* name)
  1488. {
  1489. std::string exePath = name;
  1490. exePath += "_CMAKE_PATH";
  1491. const char* cacheValue = m_Makefile->GetDefinition(exePath.c_str());
  1492. if( cacheValue && *cacheValue )
  1493. {
  1494. // if there is a cache value, then this is a executable/utility that cmake
  1495. // knows how to build, so we can depend on it
  1496. std::string exepath;
  1497. if (!this->SamePath(m_Makefile->GetCurrentOutputDirectory(), cacheValue))
  1498. {
  1499. // if the exe/utility is not in the current directory, then get the full
  1500. // path to it
  1501. if(m_ExecutableOutputPath.size())
  1502. {
  1503. exepath = m_ExecutableOutputPath;
  1504. }
  1505. else
  1506. {
  1507. exepath = cacheValue;
  1508. exepath += "/";
  1509. }
  1510. }
  1511. else
  1512. {
  1513. // library is in current Makefile
  1514. exepath = m_ExecutableOutputPath;
  1515. }
  1516. // add the library name
  1517. exepath += name;
  1518. // add the correct extension
  1519. exepath += cmSystemTools::GetExecutableExtension();
  1520. fout << this->ConvertToRelativeOutputPath(exepath.c_str()) << " ";
  1521. }
  1522. // if it isn't in the cache, it might still be a utility target
  1523. // so check for that
  1524. else
  1525. {
  1526. std::map<cmStdString, cmTarget>& targets = m_Makefile->GetTargets();
  1527. if (targets.find(name) != targets.end())
  1528. {
  1529. fout << name << " ";
  1530. }
  1531. }
  1532. }
  1533. // fix up names of directories so they can be used
  1534. // as targets in makefiles.
  1535. inline std::string FixDirectoryName(const char* dir)
  1536. {
  1537. std::string s = dir;
  1538. // replace ../ with 3 under bars
  1539. size_t pos = s.find("../");
  1540. if(pos != std::string::npos)
  1541. {
  1542. s.replace(pos, 3, "___");
  1543. }
  1544. // replace / directory separators with a single under bar
  1545. pos = s.find("/");
  1546. while(pos != std::string::npos)
  1547. {
  1548. s.replace(pos, 1, "_");
  1549. pos = s.find("/");
  1550. }
  1551. return s;
  1552. }
  1553. void cmLocalUnixMakefileGenerator::
  1554. BuildInSubDirectoryWindows(std::ostream& fout,
  1555. const char* directory,
  1556. const char* target1,
  1557. const char* target2,
  1558. bool silent)
  1559. {
  1560. std::string dir;
  1561. if(target1)
  1562. {
  1563. dir = this->ConvertToOutputForExisting(directory);
  1564. if(dir[0] == '\"')
  1565. {
  1566. dir = dir.substr(1, dir.size()-2);
  1567. }
  1568. fout << "\tif not exist \"" << dir << "\\$(NULL)\""
  1569. << " "
  1570. << "$(MAKE) $(MAKESILENT) rebuild_cache\n";
  1571. if (!silent)
  1572. {
  1573. fout << "\t@echo " << directory << ": building " << target1 << "\n";
  1574. }
  1575. fout << "\tcd " << dir << "\n"
  1576. << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) " << target1 << "\n";
  1577. }
  1578. if(target2)
  1579. {
  1580. if (!silent)
  1581. {
  1582. fout << "\t@echo " << directory << ": building " << target2 << "\n";
  1583. }
  1584. fout << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) " << target2 << "\n";
  1585. }
  1586. std::string currentDir;
  1587. if(m_UseRelativePaths)
  1588. {
  1589. currentDir = dir;
  1590. cmSystemTools::ConvertToUnixSlashes(currentDir);
  1591. std::string cdback = "..";
  1592. unsigned int i = 0;
  1593. if(currentDir.size() > 2 && currentDir[0] == '.' && currentDir[1] == '/')
  1594. {
  1595. // start past ./ if it starts with ./
  1596. i = 2;
  1597. }
  1598. for(; i < currentDir.size(); ++i)
  1599. {
  1600. if(currentDir[i] == '/')
  1601. {
  1602. cdback += "/..";
  1603. }
  1604. }
  1605. fout << "\tcd " << this->ConvertToOutputForExisting(cdback.c_str()) << "\n\n";
  1606. }
  1607. else
  1608. {
  1609. currentDir = m_Makefile->GetCurrentOutputDirectory();
  1610. fout << "\tcd " << this->ConvertToOutputForExisting(currentDir.c_str()) << "\n\n";
  1611. }
  1612. }
  1613. void cmLocalUnixMakefileGenerator::BuildInSubDirectory(std::ostream& fout,
  1614. const char* dir,
  1615. const char* target1,
  1616. const char* target2,
  1617. bool silent)
  1618. {
  1619. if(m_WindowsShell)
  1620. {
  1621. this->BuildInSubDirectoryWindows(fout, dir, target1, target2, silent);
  1622. return;
  1623. }
  1624. std::string directory = this->ConvertToRelativeOutputPath(dir);
  1625. if(target1)
  1626. {
  1627. fout << "\t@if test ! -d " << directory
  1628. << "; then $(MAKE) rebuild_cache; fi\n";
  1629. if (!silent)
  1630. {
  1631. fout << "\t@echo " << directory << ": building " << target1 << "\n";
  1632. }
  1633. fout << "\t@cd " << directory
  1634. << "; $(MAKE) " << target1 << "\n";
  1635. }
  1636. if(target2)
  1637. {
  1638. if (!silent)
  1639. {
  1640. fout << "\t@echo " << directory << ": building " << target2 << "\n";
  1641. }
  1642. fout << "\t@cd " << directory
  1643. << "; $(MAKE) " << target2 << "\n";
  1644. }
  1645. fout << "\n";
  1646. }
  1647. void
  1648. cmLocalUnixMakefileGenerator::
  1649. OutputSubDirectoryVars(std::ostream& fout,
  1650. const char* var,
  1651. const char* target,
  1652. const char* target1,
  1653. const char* target2,
  1654. const char* depend,
  1655. const std::vector<std::pair<cmStdString, bool> >& SubDirectories,
  1656. bool silent, int order)
  1657. {
  1658. if(!depend)
  1659. {
  1660. depend = "";
  1661. }
  1662. if( SubDirectories.size() == 0)
  1663. {
  1664. return;
  1665. }
  1666. fout << "# Variable for making " << target << " in subdirectories.\n";
  1667. fout << var << " = ";
  1668. unsigned int ii;
  1669. // make sure all the pre-order subdirectories are fist
  1670. // other than that keep the same order that the user specified
  1671. std::vector<std::pair<cmStdString, bool> > orderedDirs;
  1672. // collect pre-order first
  1673. for(ii =0; ii < SubDirectories.size(); ii++)
  1674. {
  1675. if(m_Makefile->IsDirectoryPreOrder(SubDirectories[ii].first.c_str()))
  1676. {
  1677. orderedDirs.push_back(SubDirectories[ii]);
  1678. }
  1679. }
  1680. // now collect post order dirs
  1681. for(ii =0; ii < SubDirectories.size(); ii++)
  1682. {
  1683. if(!m_Makefile->IsDirectoryPreOrder(SubDirectories[ii].first.c_str()))
  1684. {
  1685. orderedDirs.push_back(SubDirectories[ii]);
  1686. }
  1687. }
  1688. for(ii =0; ii < orderedDirs.size(); ii++)
  1689. {
  1690. if(!orderedDirs[ii].second)
  1691. {
  1692. continue;
  1693. }
  1694. if(order == 1 && m_Makefile->IsDirectoryPreOrder(orderedDirs[ii].first.c_str()))
  1695. {
  1696. continue;
  1697. }
  1698. if(order == 2 && !m_Makefile->IsDirectoryPreOrder(orderedDirs[ii].first.c_str()))
  1699. {
  1700. continue;
  1701. }
  1702. fout << " \\\n";
  1703. std::string subdir = FixDirectoryName(orderedDirs[ii].first.c_str());
  1704. fout << target << "_" << subdir.c_str();
  1705. }
  1706. fout << " \n\n";
  1707. fout << "# Targets for making " << target << " in subdirectories.\n";
  1708. std::string last = "";
  1709. for(unsigned int cc =0; cc < orderedDirs.size(); cc++)
  1710. {
  1711. if(!orderedDirs[cc].second)
  1712. {
  1713. continue;
  1714. }
  1715. std::string subdir = FixDirectoryName(orderedDirs[cc].first.c_str());
  1716. if(order == 1 && m_Makefile->IsDirectoryPreOrder(orderedDirs[cc].first.c_str()))
  1717. {
  1718. last = subdir;
  1719. continue;
  1720. }
  1721. if(order == 2 && !m_Makefile->IsDirectoryPreOrder(orderedDirs[cc].first.c_str()))
  1722. {
  1723. last = subdir;
  1724. continue;
  1725. }
  1726. fout << target << "_" << subdir.c_str() << ": " << depend;
  1727. // Make each subdirectory depend on previous one. This forces
  1728. // parallel builds (make -j 2) to build in same order as a single
  1729. // threaded build to avoid dependency problems.
  1730. if(cc > 0)
  1731. {
  1732. fout << " " << target << "_" << last.c_str();
  1733. }
  1734. fout << "\n";
  1735. last = subdir;
  1736. std::string dir = m_Makefile->GetCurrentOutputDirectory();
  1737. dir += "/";
  1738. dir += orderedDirs[cc].first;
  1739. this->BuildInSubDirectory(fout, dir.c_str(),
  1740. target1, target2, silent);
  1741. }
  1742. fout << "\n\n";
  1743. }
  1744. // output rules for decending into sub directories
  1745. void cmLocalUnixMakefileGenerator::OutputSubDirectoryRules(std::ostream& fout)
  1746. {
  1747. // Output Sub directory build rules
  1748. const std::vector<std::pair<cmStdString, bool> >& SubDirectories
  1749. = m_Makefile->GetSubDirectories();
  1750. if( SubDirectories.size() == 0)
  1751. {
  1752. return;
  1753. }
  1754. this->OutputSubDirectoryVars(fout,
  1755. "SUBDIR_BUILD",
  1756. "default_target",
  1757. "default_target",
  1758. 0, "$(TARGETS)",
  1759. SubDirectories,
  1760. false, 1);
  1761. this->OutputSubDirectoryVars(fout,
  1762. "SUBDIR_PREORDER_BUILD",
  1763. "default_target",
  1764. "default_target",
  1765. 0, 0,
  1766. SubDirectories,
  1767. false, 2);
  1768. this->OutputSubDirectoryVars(fout, "SUBDIR_CLEAN", "clean",
  1769. "clean",
  1770. 0, 0,
  1771. SubDirectories);
  1772. this->OutputSubDirectoryVars(fout, "SUBDIR_DEPEND", "depend",
  1773. "depend",
  1774. 0, 0,
  1775. SubDirectories);
  1776. }
  1777. // Output the depend information for all the classes
  1778. // in the makefile. These would have been generated
  1779. // by the class cmMakeDepend GenerateMakefile
  1780. bool cmLocalUnixMakefileGenerator::OutputObjectDepends(std::ostream& fout)
  1781. {
  1782. bool ret = false;
  1783. // Iterate over every target.
  1784. std::map<cmStdString, cmTarget>& targets = m_Makefile->GetTargets();
  1785. for(std::map<cmStdString, cmTarget>::const_iterator target = targets.begin();
  1786. target != targets.end(); ++target)
  1787. {
  1788. // Iterate over every source for this target.
  1789. const std::vector<cmSourceFile*>& sources = target->second.GetSourceFiles();
  1790. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  1791. source != sources.end(); ++source)
  1792. {
  1793. if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  1794. {
  1795. if(!(*source)->GetDepends().empty())
  1796. {
  1797. // Iterate through all the dependencies for this source.
  1798. for(std::vector<std::string>::const_iterator dep =
  1799. (*source)->GetDepends().begin();
  1800. dep != (*source)->GetDepends().end(); ++dep)
  1801. {
  1802. std::string s = (*source)->GetSourceName();
  1803. std::string outExt =
  1804. m_GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  1805. (*source)->GetSourceExtension().c_str());
  1806. s += outExt;
  1807. s = this->CreateSafeUniqueObjectFileName(s.c_str());
  1808. fout << this->ConvertToRelativeOutputPath(s.c_str()) << " : "
  1809. << this->ConvertToRelativeOutputPath(dep->c_str()) << "\n";
  1810. ret = true;
  1811. }
  1812. fout << "\n\n";
  1813. }
  1814. }
  1815. }
  1816. }
  1817. return ret;
  1818. }
  1819. // Output the depend information for all the classes
  1820. // in the makefile. These would have been generated
  1821. // by the class cmMakeDepend GenerateMakefile
  1822. void cmLocalUnixMakefileGenerator::OutputCheckDepends(std::ostream& fout)
  1823. {
  1824. std::set<cmStdString> emittedLowerPath;
  1825. std::set<cmStdString> emitted;
  1826. // Iterate over every target.
  1827. std::map<cmStdString, cmTarget>& targets = m_Makefile->GetTargets();
  1828. fout << "# Suppresses display of executed commands\n";
  1829. fout << ".SILENT:\n";
  1830. fout << "# disable some common implicit rules to speed things up\n";
  1831. fout << ".SUFFIXES:\n";
  1832. fout << ".SUFFIXES:.hpuxmakemusthaverule\n";
  1833. this->OutputMakeVariables(fout);
  1834. fout << "default:\n";
  1835. fout << "\t$(MAKE) $(MAKESILENT) -f cmake.check_depends all\n"
  1836. << "\t$(MAKE) $(MAKESILENT) -f cmake.check_depends cmake.depends\n\n";
  1837. for(std::map<cmStdString, cmTarget>::const_iterator target = targets.begin();
  1838. target != targets.end(); ++target)
  1839. {
  1840. // Iterate over every source for this target.
  1841. const std::vector<cmSourceFile*>& sources = target->second.GetSourceFiles();
  1842. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  1843. source != sources.end(); ++source)
  1844. {
  1845. if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  1846. {
  1847. if(!(*source)->GetDepends().empty())
  1848. {
  1849. for(std::vector<std::string>::const_iterator dep =
  1850. (*source)->GetDepends().begin();
  1851. dep != (*source)->GetDepends().end(); ++dep)
  1852. {
  1853. // do not call CollapseFullPath on dep here, because it already
  1854. // has been done because m_FullPath on cmDependInformation
  1855. // always is it called. If it is called here, network builds are
  1856. // very slow because of the number of stats
  1857. std::string dependfile = this->ConvertToRelativeOutputPath(dep->c_str());
  1858. // use the lower path function to create uniqe names
  1859. std::string lowerpath = this->LowerCasePath(dependfile.c_str());
  1860. if(emittedLowerPath.insert(lowerpath).second)
  1861. {
  1862. emitted.insert(dependfile);
  1863. fout << "all: " << dependfile << "\n";
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. fout << "\n\n# if any of these files changes run make dependlocal\n";
  1871. std::set<cmStdString>::iterator i;
  1872. for(i = emitted.begin(); i != emitted.end(); ++i)
  1873. {
  1874. fout << "cmake.depends: " << *i << "\n";
  1875. }
  1876. fout << "cmake.depends: \n"
  1877. << "\t$(MAKE) $(MAKESILENT) dependlocal\n\n";
  1878. fout << "\n\n";
  1879. fout << "# if a .h file is removed then run make dependlocal\n\n";
  1880. for(std::set<cmStdString>::iterator it = emitted.begin();
  1881. it != emitted.end(); ++it)
  1882. {
  1883. fout << *it << ":\n"
  1884. << "\t$(MAKE) $(MAKESILENT) dependlocal\n\n";
  1885. }
  1886. }
  1887. // Output each custom rule in the following format:
  1888. // output: source depends...
  1889. // (tab) command...
  1890. void cmLocalUnixMakefileGenerator::OutputCustomRules(std::ostream& fout)
  1891. {
  1892. // we cannot provide multiple rules for a single output
  1893. // so we will keep track of outputs to make sure we don't write
  1894. // two rules. First found wins
  1895. std::set<cmStdString> processedOutputs;
  1896. // first output all custom rules
  1897. const std::vector<cmSourceFile*>& sources = m_Makefile->GetSourceFiles();
  1898. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1899. i != sources.end(); ++i)
  1900. {
  1901. if ((*i)->GetCustomCommand())
  1902. {
  1903. cmCustomCommand *c = (*i)->GetCustomCommand();
  1904. // escape spaces and convert to native slashes path for
  1905. // the command
  1906. std::string comment = c->GetComment();
  1907. std::string command = c->GetCommand();
  1908. cmSystemTools::ReplaceString(command, "/./", "/");
  1909. command = this->ConvertToRelativeOutputPath(command.c_str());
  1910. command += " ";
  1911. // now add the arguments
  1912. command += c->GetArguments();
  1913. std::vector<std::string> depends;
  1914. // Collect out all the dependencies for this rule.
  1915. for(std::vector<std::string>::const_iterator d =
  1916. c->GetDepends().begin();
  1917. d != c->GetDepends().end(); ++d)
  1918. {
  1919. std::string dep = *d;
  1920. m_Makefile->ExpandVariablesInString(dep);
  1921. // watch for target dependencies,
  1922. std::string libPath = dep + "_CMAKE_PATH";
  1923. const char* cacheValue = m_Makefile->GetDefinition(libPath.c_str());
  1924. if ( cacheValue && *cacheValue )
  1925. {
  1926. libPath = cacheValue;
  1927. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH") &&
  1928. m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH")[0] != '\0')
  1929. {
  1930. libPath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  1931. }
  1932. libPath += "/";
  1933. libPath += dep;
  1934. libPath += cmSystemTools::GetExecutableExtension();
  1935. dep = libPath;
  1936. }
  1937. cmSystemTools::ReplaceString(dep, "/./", "/");
  1938. cmSystemTools::ReplaceString(dep, "/$(IntDir)/", "/");
  1939. dep = this->ConvertToRelativeOutputPath(dep.c_str());
  1940. depends.push_back(dep.c_str());
  1941. }
  1942. // output rule
  1943. if (processedOutputs.find(c->GetOutput()) == processedOutputs.end())
  1944. {
  1945. this->OutputMakeRule(fout,
  1946. (comment.size()?comment.c_str():"Custom command"),
  1947. c->GetOutput().c_str(),
  1948. depends,
  1949. command.c_str());
  1950. processedOutputs.insert(c->GetOutput());
  1951. }
  1952. else
  1953. {
  1954. cmSystemTools::Error("An output was found with multiple rules on how to build it for output: ",
  1955. c->GetOutput().c_str());
  1956. }
  1957. }
  1958. }
  1959. }
  1960. void cmLocalUnixMakefileGenerator::OutputMakeVariables(std::ostream& fout)
  1961. {
  1962. const char* variables =
  1963. "# the standard shell for make\n"
  1964. "SHELL = /bin/sh\n"
  1965. "\n";
  1966. if(!m_WindowsShell)
  1967. {
  1968. fout << variables;
  1969. }
  1970. else
  1971. {
  1972. fout <<
  1973. "!IF \"$(OS)\" == \"Windows_NT\"\n"
  1974. "NULL=\n"
  1975. "!ELSE \n"
  1976. "NULL=nul\n"
  1977. "!ENDIF \n";
  1978. }
  1979. if(m_MakeSilentFlag.size())
  1980. {
  1981. fout << "MAKESILENT = " << m_MakeSilentFlag << "\n";
  1982. }
  1983. std::string cmakecommand = this->ConvertToOutputForExisting(
  1984. m_Makefile->GetRequiredDefinition("CMAKE_COMMAND"));
  1985. fout << "CMAKE_COMMAND = "
  1986. << cmakecommand
  1987. << "\n";
  1988. fout << "RM = " << cmakecommand.c_str() << " -E remove -f\n";
  1989. if(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  1990. {
  1991. fout << "CMAKE_EDIT_COMMAND = "
  1992. << this->ConvertToOutputForExisting(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  1993. << "\n";
  1994. }
  1995. fout << "CMAKE_CURRENT_SOURCE = " <<
  1996. this->ConvertToRelativeOutputPath(m_Makefile->GetStartDirectory())
  1997. << "\n";
  1998. fout << "CMAKE_CURRENT_BINARY = " <<
  1999. this->ConvertToRelativeOutputPath(m_Makefile->GetStartOutputDirectory())
  2000. << "\n";
  2001. fout << "CMAKE_SOURCE_DIR = " <<
  2002. this->ConvertToRelativeOutputPath(m_Makefile->GetHomeDirectory())
  2003. << "\n";
  2004. fout << "CMAKE_BINARY_DIR = " <<
  2005. this->ConvertToRelativeOutputPath(m_Makefile->GetHomeOutputDirectory())
  2006. << "\n";
  2007. fout << "\n\n";
  2008. }
  2009. void cmLocalUnixMakefileGenerator::OutputMakeRules(std::ostream& fout)
  2010. {
  2011. this->OutputMakeRule(fout,
  2012. "default build rule",
  2013. "all",
  2014. "cmake.depends $(SUBDIR_PREORDER_BUILD) $(TARGETS) $(SUBDIR_BUILD)",
  2015. 0);
  2016. this->OutputMakeRule(fout,
  2017. "clean generated files",
  2018. "clean",
  2019. "$(SUBDIR_CLEAN)",
  2020. "-@ $(RM) $(CLEAN_OBJECT_FILES) "
  2021. " $(TARGETS) $(TARGET_EXTRAS) $(GENERATED_QT_FILES) $(GENERATED_FLTK_FILES) $(ADDITIONAL_MAKE_CLEAN_FILES)");
  2022. // collect up all the sources
  2023. std::vector<std::string> allsources;
  2024. std::map<cmStdString, cmTarget>& targets = m_Makefile->GetTargets();
  2025. for(std::map<cmStdString,cmTarget>::const_iterator target = targets.begin();
  2026. target != targets.end(); ++target)
  2027. {
  2028. // Iterate over every source for this target.
  2029. const std::vector<cmSourceFile*>& sources = target->second.GetSourceFiles();
  2030. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  2031. source != sources.end(); ++source)
  2032. {
  2033. if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  2034. {
  2035. allsources.push_back(this->ConvertToRelativeOutputPath((*source)->GetFullPath().c_str()));
  2036. }
  2037. }
  2038. }
  2039. std::string checkCache = m_Makefile->GetHomeOutputDirectory();
  2040. checkCache += "/cmake.check_cache";
  2041. checkCache = this->ConvertToRelativeOutputPath(checkCache.c_str());
  2042. std::vector<std::string> cmake_depends;
  2043. cmake_depends.push_back("$(CMAKE_MAKEFILE_SOURCES)");
  2044. this->OutputMakeRule(fout,
  2045. "dependencies.",
  2046. "cmake.depends",
  2047. cmake_depends,
  2048. "$(CMAKE_COMMAND) "
  2049. "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
  2050. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2051. this->OutputMakeRule(fout,
  2052. "dependencies",
  2053. "cmake.check_depends",
  2054. allsources,
  2055. "$(CMAKE_COMMAND) "
  2056. "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
  2057. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2058. this->OutputMakeRule(fout,
  2059. "dependencies",
  2060. "depend",
  2061. "$(SUBDIR_DEPEND)",
  2062. "$(CMAKE_COMMAND) "
  2063. "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
  2064. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2065. this->OutputMakeRule(fout,
  2066. "dependencies",
  2067. "dependlocal",
  2068. 0,
  2069. "$(CMAKE_COMMAND) "
  2070. "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
  2071. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2072. this->OutputMakeRule(fout,
  2073. "CMakeCache.txt",
  2074. "rebuild_cache",
  2075. 0,
  2076. "$(CMAKE_COMMAND) "
  2077. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2078. std::vector<std::string> check_cache_depends;
  2079. std::string CMakeCache = m_Makefile->GetHomeOutputDirectory();
  2080. CMakeCache += "/CMakeCache.txt";
  2081. CMakeCache = this->ConvertToRelativeOutputPath(CMakeCache.c_str());
  2082. check_cache_depends.push_back("$(CMAKE_MAKEFILE_SOURCES)");
  2083. this->OutputMakeRule(fout,
  2084. "CMakeCache.txt because out-of-date:",
  2085. checkCache.c_str(),
  2086. check_cache_depends,
  2087. "$(CMAKE_COMMAND) "
  2088. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2089. // if CMAKE_EDIT_COMMAND is defined then add a rule to run it
  2090. // called edit_cache
  2091. if(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  2092. {
  2093. this->OutputMakeRule(fout,
  2094. "edit CMakeCache.txt",
  2095. "edit_cache",
  2096. 0,
  2097. "$(CMAKE_EDIT_COMMAND) "
  2098. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2099. }
  2100. else
  2101. {
  2102. this->OutputMakeRule(fout,
  2103. "edit CMakeCache.txt",
  2104. "edit_cache",
  2105. 0,
  2106. "$(CMAKE_COMMAND) "
  2107. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -i");
  2108. }
  2109. std::string cacheFile = m_Makefile->GetHomeOutputDirectory();
  2110. cacheFile += "/CMakeCache.txt";
  2111. cacheFile = this->ConvertToRelativeOutputPath(cacheFile.c_str());
  2112. this->OutputMakeRule(fout,
  2113. "CMakeCache.txt",
  2114. cacheFile.c_str(),
  2115. 0,
  2116. "$(CMAKE_COMMAND) "
  2117. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2118. this->OutputMakeRule(fout,
  2119. "Rule to keep make from removing Makefiles "
  2120. "if control-C is hit during a run of cmake.",
  2121. ".PRECIOUS",
  2122. "Makefile cmake.depends",
  2123. 0);
  2124. this->OutputSourceObjectBuildRules(fout);
  2125. // find ctest
  2126. std::string ctest = m_Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  2127. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  2128. ctest += "/";
  2129. ctest += "ctest";
  2130. ctest += cmSystemTools::GetExecutableExtension();
  2131. if(!cmSystemTools::FileExists(ctest.c_str()))
  2132. {
  2133. ctest = m_Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  2134. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  2135. ctest += "/Debug/";
  2136. ctest += "ctest";
  2137. ctest += cmSystemTools::GetExecutableExtension();
  2138. }
  2139. if(!cmSystemTools::FileExists(ctest.c_str()))
  2140. {
  2141. ctest = m_Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  2142. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  2143. ctest += "/Release/";
  2144. ctest += "ctest";
  2145. ctest += cmSystemTools::GetExecutableExtension();
  2146. }
  2147. if (!cmSystemTools::FileExists(ctest.c_str()))
  2148. {
  2149. if ( !m_Makefile->GetDefinition("PROJECT_NAME") ||
  2150. strcmp(m_Makefile->GetDefinition("PROJECT_NAME"), "CMake") )
  2151. {
  2152. return;
  2153. }
  2154. ctest = m_Makefile->GetRequiredDefinition("EXECUTABLE_OUTPUT_PATH");
  2155. ctest += "/ctest";
  2156. }
  2157. if (m_Makefile->IsOn("CMAKE_TESTING_ENABLED"))
  2158. {
  2159. fout << "ARGS=\n";
  2160. std::string cmd = this->ConvertToOutputForExisting(ctest.c_str());
  2161. cmd += " $(ARGS)";
  2162. this->OutputMakeRule(fout,
  2163. "tests",
  2164. "test",
  2165. "",
  2166. cmd.c_str());
  2167. }
  2168. if(m_Makefile->GetDefinition("CMake_BINARY_DIR"))
  2169. {
  2170. // We are building CMake itself. We cannot use the original
  2171. // executable to install over itself.
  2172. std::string rule = m_Makefile->GetRequiredDefinition("EXECUTABLE_OUTPUT_PATH");
  2173. rule += "/cmake";
  2174. rule = cmSystemTools::ConvertToOutputPath(rule.c_str());
  2175. rule += " -P cmake_install.cmake";
  2176. this->OutputMakeRule(fout, "installation", "install", "", rule.c_str());
  2177. }
  2178. else
  2179. {
  2180. this->OutputMakeRule(fout, "installation", "install", "",
  2181. "$(CMAKE_COMMAND) -P cmake_install.cmake");
  2182. }
  2183. }
  2184. void
  2185. cmLocalUnixMakefileGenerator::
  2186. OutputBuildObjectFromSource(std::ostream& fout,
  2187. const char* shortName,
  2188. const cmSourceFile& source,
  2189. const char* extraCompileFlags,
  2190. bool shared)
  2191. {
  2192. // Header files shouldn't have build rules.
  2193. if(source.GetPropertyAsBool("HEADER_FILE_ONLY") ||
  2194. m_GlobalGenerator->IgnoreFile(source.GetSourceExtension().c_str()))
  2195. {
  2196. return;
  2197. }
  2198. std::string outputExt =
  2199. m_GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  2200. source.GetSourceExtension().c_str());
  2201. std::string objectFile = std::string(shortName) + outputExt;
  2202. objectFile = this->CreateSafeUniqueObjectFileName(objectFile.c_str());
  2203. objectFile = this->ConvertToRelativeOutputPath(objectFile.c_str());
  2204. std::vector<std::string> rules;
  2205. std::string flags;
  2206. if(extraCompileFlags)
  2207. {
  2208. flags += extraCompileFlags;
  2209. }
  2210. std::string sourceFile =
  2211. this->ConvertToRelativeOutputPath(source.GetFullPath().c_str());
  2212. std::string buildType = m_Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  2213. buildType = cmSystemTools::UpperCase(buildType);
  2214. // find out what language the source file is
  2215. const char* lang =
  2216. m_GlobalGenerator->GetLanguageFromExtension(source.GetSourceExtension().c_str());
  2217. // for now if the lang is defined add the rules and flags for it
  2218. std::string comment = outputExt;
  2219. comment += " file";
  2220. if(lang)
  2221. {
  2222. comment += " from ";
  2223. comment += lang;
  2224. comment += ": ";
  2225. if(comment.size() < 18)
  2226. {
  2227. comment.resize(18, ' ');
  2228. }
  2229. }
  2230. if(lang)
  2231. {
  2232. std::string varString = "CMAKE_";
  2233. varString += lang;
  2234. varString += "_COMPILE_OBJECT";
  2235. rules.push_back(m_Makefile->GetRequiredDefinition(varString.c_str()));
  2236. varString = "CMAKE_";
  2237. varString += lang;
  2238. varString += "_FLAGS";
  2239. flags += m_Makefile->GetSafeDefinition(varString.c_str());
  2240. flags += " ";
  2241. if(buildType.size())
  2242. {
  2243. varString += "_";
  2244. varString += buildType;
  2245. flags += m_Makefile->GetSafeDefinition(varString.c_str());
  2246. flags += " ";
  2247. }
  2248. if(shared)
  2249. {
  2250. varString = "CMAKE_SHARED_LIBRARY_";
  2251. varString += lang;
  2252. varString += "_FLAGS";
  2253. flags += m_Makefile->GetSafeDefinition(varString.c_str());
  2254. flags += " ";
  2255. }
  2256. if(cmSystemTools::IsOn(m_Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  2257. {
  2258. varString = "CMAKE_SHARED_BUILD_";
  2259. varString += lang;
  2260. varString += "_FLAGS";
  2261. flags += m_Makefile->GetSafeDefinition(varString.c_str());
  2262. flags += " ";
  2263. }
  2264. }
  2265. else
  2266. {
  2267. // if the language is not defined and should not be ignored,
  2268. // then produce an error
  2269. cmSystemTools::Error("Unexpected file type ",
  2270. sourceFile.c_str());
  2271. }
  2272. flags += this->GetIncludeFlags(lang);
  2273. // expand multi-command semi-colon separated lists
  2274. // of commands into separate commands
  2275. std::vector<std::string> commands;
  2276. cmSystemTools::ExpandList(rules, commands);
  2277. for(std::vector<std::string>::iterator i = commands.begin();
  2278. i != commands.end(); ++i)
  2279. {
  2280. this->ExpandRuleVariables(*i,
  2281. lang,
  2282. 0, // no objects
  2283. 0, // no target
  2284. 0, // no link libs
  2285. sourceFile.c_str(),
  2286. objectFile.c_str(),
  2287. flags.c_str());
  2288. }
  2289. std::vector<std::string> sourceAndDeps;
  2290. sourceAndDeps.push_back(sourceFile);
  2291. // Check for extra object-file dependencies.
  2292. std::vector<std::string> depends;
  2293. const char* additionalDeps = source.GetProperty("OBJECT_DEPENDS");
  2294. if(additionalDeps)
  2295. {
  2296. cmSystemTools::ExpandListArgument(additionalDeps, depends);
  2297. for(std::vector<std::string>::iterator i = depends.begin();
  2298. i != depends.end(); ++i)
  2299. {
  2300. sourceAndDeps.push_back(this->ConvertToRelativeOutputPath(i->c_str()));
  2301. }
  2302. }
  2303. this->OutputMakeRule(fout,
  2304. comment.c_str(),
  2305. objectFile.c_str(),
  2306. sourceAndDeps,
  2307. commands);
  2308. }
  2309. void cmLocalUnixMakefileGenerator::OutputSourceObjectBuildRules(std::ostream& fout)
  2310. {
  2311. fout << "# Rules to build source files :\n\n";
  2312. std::set<cmStdString> rules;
  2313. // Iterate over every target.
  2314. std::map<cmStdString, cmTarget>& targets = m_Makefile->GetTargets();
  2315. for(std::map<cmStdString, cmTarget>::const_iterator target = targets.begin();
  2316. target != targets.end(); ++target)
  2317. {
  2318. bool shared = ((target->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  2319. (target->second.GetType() == cmTarget::MODULE_LIBRARY));
  2320. std::string exportsDef = "";
  2321. if(shared)
  2322. {
  2323. std::string export_symbol;
  2324. if (const char* custom_export_name = target->second.GetProperty("DEFINE_SYMBOL"))
  2325. {
  2326. export_symbol = custom_export_name;
  2327. }
  2328. else
  2329. {
  2330. std::string in = target->first + "_EXPORTS";
  2331. export_symbol = cmSystemTools::MakeCindentifier(in.c_str());
  2332. }
  2333. exportsDef = "-D"+ export_symbol;
  2334. }
  2335. // Iterate over every source for this target.
  2336. const std::vector<cmSourceFile*>& sources =
  2337. target->second.GetSourceFiles();
  2338. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  2339. source != sources.end(); ++source)
  2340. {
  2341. if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  2342. !(*source)->GetCustomCommand())
  2343. {
  2344. std::string shortName;
  2345. std::string sourceName;
  2346. // If the full path to the source file includes this
  2347. // directory, we want to use the relative path for the
  2348. // filename of the object file. Otherwise, we will use just
  2349. // the filename portion.
  2350. if((cmSystemTools::GetFilenamePath(
  2351. (*source)->GetFullPath()).find(
  2352. m_Makefile->GetCurrentDirectory()) == 0)
  2353. || (cmSystemTools::GetFilenamePath(
  2354. (*source)->GetFullPath()).find(
  2355. m_Makefile->GetCurrentOutputDirectory()) == 0))
  2356. {
  2357. sourceName = (*source)->GetSourceName()+"."+
  2358. (*source)->GetSourceExtension();
  2359. shortName = (*source)->GetSourceName();
  2360. // The path may be relative. See if a directory needs to be
  2361. // created for the output file. This is a ugly, and perhaps
  2362. // should be moved elsewhere.
  2363. std::string relPath =
  2364. cmSystemTools::GetFilenamePath((*source)->GetSourceName());
  2365. if(relPath != "")
  2366. {
  2367. std::string outPath = m_Makefile->GetCurrentOutputDirectory();
  2368. outPath += "/"+relPath;
  2369. cmSystemTools::MakeDirectory(outPath.c_str());
  2370. }
  2371. }
  2372. else
  2373. {
  2374. sourceName = (*source)->GetFullPath();
  2375. shortName = cmSystemTools::GetFilenameName((*source)->GetSourceName());
  2376. }
  2377. std::string shortNameWithExt = shortName +
  2378. (*source)->GetSourceExtension();
  2379. // Only output a rule for each .o once.
  2380. std::string compileFlags = exportsDef;
  2381. compileFlags += " ";
  2382. if(rules.find(shortNameWithExt) == rules.end())
  2383. {
  2384. if((*source)->GetProperty("COMPILE_FLAGS"))
  2385. {
  2386. compileFlags += (*source)->GetProperty("COMPILE_FLAGS");
  2387. compileFlags += " ";
  2388. }
  2389. this->OutputBuildObjectFromSource(fout,
  2390. shortName.c_str(),
  2391. *(*source),
  2392. compileFlags.c_str(),
  2393. shared);
  2394. rules.insert(shortNameWithExt);
  2395. }
  2396. }
  2397. }
  2398. }
  2399. }
  2400. void cmLocalUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
  2401. const char* comment,
  2402. const char* target,
  2403. const char* depends,
  2404. const char* command,
  2405. const char* command2,
  2406. const char* command3,
  2407. const char* command4)
  2408. {
  2409. std::vector<std::string> commands;
  2410. if(command)
  2411. {
  2412. commands.push_back(command);
  2413. }
  2414. if(command2)
  2415. {
  2416. commands.push_back(command2);
  2417. }
  2418. if(command3)
  2419. {
  2420. commands.push_back(command3);
  2421. }
  2422. if(command4)
  2423. {
  2424. commands.push_back(command4);
  2425. }
  2426. this->OutputMakeRule(fout, comment, target, depends, commands);
  2427. }
  2428. void cmLocalUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
  2429. const char* comment,
  2430. const char* target,
  2431. const char* depends,
  2432. const std::vector<std::string>& commands)
  2433. {
  2434. std::vector<std::string> depend;
  2435. if(depends)
  2436. {
  2437. depend.push_back(depends);
  2438. }
  2439. this->OutputMakeRule(fout, comment, target, depend, commands);
  2440. }
  2441. void cmLocalUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
  2442. const char* comment,
  2443. const char* target,
  2444. const std::vector<std::string>& depends,
  2445. const char* command)
  2446. {
  2447. std::vector<std::string> commands;
  2448. if(command)
  2449. {
  2450. commands.push_back(command);
  2451. }
  2452. this->OutputMakeRule(fout, comment, target, depends, commands);
  2453. }
  2454. void cmLocalUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
  2455. const char* comment,
  2456. const char* target,
  2457. const std::vector<std::string>& depends,
  2458. const std::vector<std::string>& commands)
  2459. {
  2460. if(!target)
  2461. {
  2462. cmSystemTools::Error("no target for OutputMakeRule");
  2463. return;
  2464. }
  2465. std::string replace;
  2466. if(comment)
  2467. {
  2468. replace = comment;
  2469. m_Makefile->ExpandVariablesInString(replace);
  2470. fout << "#---------------------------------------------------------\n";
  2471. fout << "# " << replace;
  2472. fout << "\n#\n";
  2473. }
  2474. fout << "\n";
  2475. replace = target;
  2476. m_Makefile->ExpandVariablesInString(replace);
  2477. std::string tgt = this->ConvertToRelativeOutputPath(replace.c_str());
  2478. tgt = this->ConvertToMakeTarget(tgt.c_str());
  2479. const char* space = "";
  2480. if(tgt.size() == 1)
  2481. {
  2482. // Add a space before the ":" to avoid drive letter confusion on
  2483. // Windows.
  2484. space = " ";
  2485. }
  2486. if(depends.empty())
  2487. {
  2488. fout << tgt.c_str() << space << ":\n";
  2489. }
  2490. else
  2491. {
  2492. // Split dependencies into multiple rule lines. This allows for
  2493. // very long dependency lists.
  2494. for(std::vector<std::string>::const_iterator dep = depends.begin();
  2495. dep != depends.end(); ++dep)
  2496. {
  2497. replace = *dep;
  2498. m_Makefile->ExpandVariablesInString(replace);
  2499. replace = this->ConvertToMakeTarget(replace.c_str());
  2500. fout << tgt.c_str() << space << ": " << replace.c_str() << "\n";
  2501. }
  2502. }
  2503. int count = 0;
  2504. for (std::vector<std::string>::const_iterator i = commands.begin();
  2505. i != commands.end(); ++i)
  2506. {
  2507. replace = *i;
  2508. m_Makefile->ExpandVariablesInString(replace);
  2509. if(count == 0 && replace.find_first_not_of(" \t\n\r") != std::string::npos &&
  2510. replace[0] != '-' && replace.find("echo") != 0
  2511. && replace.find("$(MAKE)") != 0)
  2512. {
  2513. std::string echostring = "Building ";
  2514. echostring += comment;
  2515. echostring += " ";
  2516. echostring += target;
  2517. echostring += "...";
  2518. this->OutputEcho(fout,echostring.c_str());
  2519. }
  2520. fout << "\t" << replace.c_str() << "\n";
  2521. count++;
  2522. }
  2523. fout << "\n";
  2524. }
  2525. std::string cmLocalUnixMakefileGenerator::LowerCasePath(const char* path)
  2526. {
  2527. #ifdef _WIN32
  2528. return cmSystemTools::LowerCase(path);
  2529. #else
  2530. return std::string(path);
  2531. #endif
  2532. }
  2533. std::string&
  2534. cmLocalUnixMakefileGenerator::CreateSafeUniqueObjectFileName(const char* sin)
  2535. {
  2536. if ( m_Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES") )
  2537. {
  2538. std::map<cmStdString,cmStdString>::iterator it = m_UniqueObjectNamesMap.find(sin);
  2539. if ( it == m_UniqueObjectNamesMap.end() )
  2540. {
  2541. std::string ssin = sin;
  2542. bool done;
  2543. int cc = 0;
  2544. char rpstr[100];
  2545. sprintf(rpstr, "_p_");
  2546. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  2547. std::string sssin = sin;
  2548. do
  2549. {
  2550. done = true;
  2551. for ( it = m_UniqueObjectNamesMap.begin();
  2552. it != m_UniqueObjectNamesMap.end();
  2553. ++ it )
  2554. {
  2555. if ( it->second == ssin )
  2556. {
  2557. done = false;
  2558. }
  2559. }
  2560. if ( done )
  2561. {
  2562. break;
  2563. }
  2564. sssin = ssin;
  2565. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  2566. sprintf(rpstr, "_p%d_", cc++);
  2567. }
  2568. while ( !done );
  2569. m_UniqueObjectNamesMap[sin] = ssin;
  2570. }
  2571. }
  2572. else
  2573. {
  2574. m_UniqueObjectNamesMap[sin] = sin;
  2575. }
  2576. return m_UniqueObjectNamesMap[sin];
  2577. }
  2578. std::string
  2579. cmLocalUnixMakefileGenerator::CreateMakeVariable(const char* sin, const char* s2in)
  2580. {
  2581. std::string s = sin;
  2582. std::string s2 = s2in;
  2583. std::string unmodified = s;
  2584. unmodified += s2;
  2585. // if there is no restriction on the length of make variables
  2586. // and there are no "." charactors in the string, then return the
  2587. // unmodified combination.
  2588. if(!m_MakefileVariableSize && unmodified.find('.') == s.npos)
  2589. {
  2590. return unmodified;
  2591. }
  2592. // see if the variable has been defined before and return
  2593. // the modified version of the variable
  2594. std::map<cmStdString, cmStdString>::iterator i = m_MakeVariableMap.find(unmodified);
  2595. if(i != m_MakeVariableMap.end())
  2596. {
  2597. return i->second;
  2598. }
  2599. // start with the unmodified variable
  2600. std::string ret = unmodified;
  2601. // if this there is no value for m_MakefileVariableSize then
  2602. // the string must have bad characters in it
  2603. if(!m_MakefileVariableSize)
  2604. {
  2605. cmSystemTools::ReplaceString(ret, ".", "_");
  2606. int ni = 0;
  2607. char buffer[5];
  2608. // make sure the _ version is not already used, if
  2609. // it is used then add number to the end of the variable
  2610. while(m_ShortMakeVariableMap.count(ret) && ni < 1000)
  2611. {
  2612. ++ni;
  2613. sprintf(buffer, "%04d", ni);
  2614. ret = unmodified + buffer;
  2615. }
  2616. m_ShortMakeVariableMap[ret] = "1";
  2617. m_MakeVariableMap[unmodified] = ret;
  2618. return ret;
  2619. }
  2620. // if the string is greater the 32 chars it is an invalid vairable name
  2621. // for borland make
  2622. if(static_cast<int>(ret.size()) > m_MakefileVariableSize)
  2623. {
  2624. int keep = m_MakefileVariableSize - 8;
  2625. int size = keep + 3;
  2626. std::string str1 = s;
  2627. std::string str2 = s2;
  2628. // we must shorten the combined string by 4 charactors
  2629. // keep no more than 24 charactors from the second string
  2630. if(static_cast<int>(str2.size()) > keep)
  2631. {
  2632. str2 = str2.substr(0, keep);
  2633. }
  2634. if(static_cast<int>(str1.size()) + static_cast<int>(str2.size()) > size)
  2635. {
  2636. str1 = str1.substr(0, size - str2.size());
  2637. }
  2638. char buffer[5];
  2639. int ni = 0;
  2640. sprintf(buffer, "%04d", ni);
  2641. ret = str1 + str2 + buffer;
  2642. while(m_ShortMakeVariableMap.count(ret) && ni < 1000)
  2643. {
  2644. ++ni;
  2645. sprintf(buffer, "%04d", ni);
  2646. ret = str1 + str2 + buffer;
  2647. }
  2648. if(ni == 1000)
  2649. {
  2650. cmSystemTools::Error("Borland makefile variable length too long");
  2651. return unmodified;
  2652. }
  2653. // once an unused variable is found
  2654. m_ShortMakeVariableMap[ret] = "1";
  2655. }
  2656. // always make an entry into the unmodified to variable map
  2657. m_MakeVariableMap[unmodified] = ret;
  2658. return ret;
  2659. }
  2660. void cmLocalUnixMakefileGenerator::GetLibraryNames(const char* n,
  2661. const cmTarget& t,
  2662. std::string& name,
  2663. std::string& soName,
  2664. std::string& realName,
  2665. std::string& baseName)
  2666. {
  2667. // Check for library version properties.
  2668. const char* version = t.GetProperty("VERSION");
  2669. const char* soversion = t.GetProperty("SOVERSION");
  2670. if((t.GetType() != cmTarget::SHARED_LIBRARY &&
  2671. t.GetType() != cmTarget::MODULE_LIBRARY) ||
  2672. !m_Makefile->GetDefinition("CMAKE_SHARED_LIBRARY_SONAME_C_FLAG"))
  2673. {
  2674. // Versioning is supported only for shared libraries and modules,
  2675. // and then only when the platform supports an soname flag.
  2676. version = 0;
  2677. soversion = 0;
  2678. }
  2679. if(version && !soversion)
  2680. {
  2681. // The soversion must be set if the library version is set. Use
  2682. // the library version as the soversion.
  2683. soversion = version;
  2684. }
  2685. // The library name.
  2686. name = this->GetFullTargetName(n, t);
  2687. // The library's soname.
  2688. soName = name;
  2689. if(soversion)
  2690. {
  2691. soName += ".";
  2692. soName += soversion;
  2693. }
  2694. // The library's real name on disk.
  2695. realName = name;
  2696. if(version)
  2697. {
  2698. realName += ".";
  2699. realName += version;
  2700. }
  2701. else if(soversion)
  2702. {
  2703. realName += ".";
  2704. realName += soversion;
  2705. }
  2706. // The library name without extension.
  2707. baseName = this->GetBaseTargetName(n, t);
  2708. }
  2709. std::string cmLocalUnixMakefileGenerator::ConvertToMakeTarget(const char* tgt)
  2710. {
  2711. // Make targets should not have a leading './' for a file in the
  2712. // directory containing the makefile.
  2713. std::string ret = tgt;
  2714. if(ret.size() > 2 &&
  2715. (ret[0] == '.') &&
  2716. ( (ret[1] == '/') || ret[1] == '\\'))
  2717. {
  2718. std::string upath = ret;
  2719. cmSystemTools::ConvertToUnixSlashes(upath);
  2720. if(upath.find(2, '/') == upath.npos)
  2721. {
  2722. ret = ret.substr(2, ret.size()-2);
  2723. }
  2724. }
  2725. return ret;
  2726. }