cmLocalUnixMakefileGenerator.cxx 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904
  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. if(initNext)
  629. {
  630. customRuleCode += "\n\t";
  631. }
  632. else
  633. {
  634. initNext = true;
  635. }
  636. customRuleCode += this->ConstructScript(cr->GetCommandLines(), "\n\t");
  637. }
  638. return customRuleCode;
  639. }
  640. std::string cmLocalUnixMakefileGenerator::CreatePreLinkRules(
  641. const cmTarget &target, const char* /* targetName */)
  642. {
  643. std::string customRuleCode = "";
  644. bool initNext = false;
  645. for (std::vector<cmCustomCommand>::const_iterator cr =
  646. target.GetPreLinkCommands().begin();
  647. cr != target.GetPreLinkCommands().end(); ++cr)
  648. {
  649. if(initNext)
  650. {
  651. customRuleCode += "\n\t";
  652. }
  653. else
  654. {
  655. initNext = true;
  656. }
  657. customRuleCode += this->ConstructScript(cr->GetCommandLines(), "\n\t");
  658. }
  659. return customRuleCode;
  660. }
  661. std::string cmLocalUnixMakefileGenerator::CreatePostBuildRules(
  662. const cmTarget &target, const char* /* targetName */)
  663. {
  664. std::string customRuleCode = "";
  665. bool initNext = false;
  666. for (std::vector<cmCustomCommand>::const_iterator cr =
  667. target.GetPostBuildCommands().begin();
  668. cr != target.GetPostBuildCommands().end(); ++cr)
  669. {
  670. if(initNext)
  671. {
  672. customRuleCode += "\n\t";
  673. }
  674. else
  675. {
  676. initNext = true;
  677. }
  678. customRuleCode += this->ConstructScript(cr->GetCommandLines(), "\n\t");
  679. }
  680. return customRuleCode;
  681. }
  682. void cmLocalUnixMakefileGenerator::OutputLibraryRule(std::ostream& fout,
  683. const char* name,
  684. const cmTarget &t,
  685. const char* createVariable,
  686. const char* comment,
  687. const char* linkFlags
  688. )
  689. {
  690. std::string targetName;
  691. std::string targetNameSO;
  692. std::string targetNameReal;
  693. std::string targetNameBase;
  694. this->GetLibraryNames(name, t,
  695. targetName, targetNameSO,
  696. targetNameReal, targetNameBase);
  697. std::string outpath;
  698. std::string outdir;
  699. if(m_UseRelativePaths)
  700. {
  701. outdir = this->ConvertToRelativeOutputPath(m_LibraryOutputPath.c_str());
  702. }
  703. else
  704. {
  705. outdir = m_LibraryOutputPath;
  706. }
  707. if(!m_WindowsShell && m_UseRelativePaths && outdir.size())
  708. {
  709. outpath = "\"`cd ";
  710. }
  711. outpath += outdir;
  712. if(!m_WindowsShell && m_UseRelativePaths && outdir.size())
  713. {
  714. outpath += ";pwd`\"/";
  715. }
  716. if(outdir.size() == 0 && m_UseRelativePaths && !m_WindowsShell)
  717. {
  718. outpath = "\"`pwd`\"/";
  719. }
  720. // The full path versions of the names.
  721. std::string targetFullPath = outpath + targetName;
  722. std::string targetFullPathSO = outpath + targetNameSO;
  723. std::string targetFullPathReal = outpath + targetNameReal;
  724. std::string targetFullPathBase = outpath + targetNameBase;
  725. // If not using relative paths then the output path needs to be
  726. // converted here
  727. if(!m_UseRelativePaths)
  728. {
  729. targetFullPath = this->ConvertToRelativeOutputPath(targetFullPath.c_str());
  730. targetFullPathSO = this->ConvertToRelativeOutputPath(targetFullPathSO.c_str());
  731. targetFullPathReal = this->ConvertToRelativeOutputPath(targetFullPathReal.c_str());
  732. targetFullPathBase = this->ConvertToRelativeOutputPath(targetFullPathBase.c_str());
  733. }
  734. // get the objects that are used to link this library
  735. std::string objs = "$(" + this->CreateMakeVariable(name, "_SRC_OBJS")
  736. + ") $(" + this->CreateMakeVariable(name, "_EXTERNAL_OBJS") + ") ";
  737. std::string objsQuoted = "$(" + this->CreateMakeVariable(name, "_SRC_OBJS_QUOTED")
  738. + ") $(" + this->CreateMakeVariable(name, "_EXTERNAL_OBJS_QUOTED") + ") ";
  739. // create a variable with the objects that this library depends on
  740. std::string depend =
  741. objs + " $(" + this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
  742. std::vector<std::string> commands;
  743. std::string cmakecommand = this->ConvertToOutputForExisting(
  744. m_Makefile->GetRequiredDefinition("CMAKE_COMMAND"));
  745. // Remove any existing files for this library.
  746. std::string remove = cmakecommand;
  747. remove += " -E remove -f ";
  748. remove += targetFullPathReal;
  749. if(targetFullPathSO != targetFullPathReal)
  750. {
  751. remove += " ";
  752. remove += targetFullPathSO;
  753. }
  754. if(targetFullPath != targetFullPathSO &&
  755. targetFullPath != targetFullPathReal)
  756. {
  757. remove += " ";
  758. remove += targetFullPath;
  759. }
  760. commands.push_back(remove);
  761. // collect custom commands for this target and add them to the list
  762. std::string customCommands = this->CreatePreBuildRules(t, name);
  763. if(customCommands.size() > 0)
  764. {
  765. commands.push_back(customCommands);
  766. }
  767. // collect custom commands for this target and add them to the list
  768. customCommands = this->CreatePreLinkRules(t, name);
  769. if(customCommands.size() > 0)
  770. {
  771. commands.push_back(customCommands);
  772. }
  773. // collect up the build rules
  774. std::vector<std::string> rules;
  775. rules.push_back(m_Makefile->GetRequiredDefinition(createVariable));
  776. // expand multi-command semi-colon separated lists
  777. // of commands into separate commands
  778. cmSystemTools::ExpandList(rules, commands);
  779. // Create necessary symlinks for library.
  780. if(targetFullPath != targetFullPathReal)
  781. {
  782. std::string symlink = cmakecommand;
  783. symlink += " -E cmake_symlink_library ";
  784. symlink += targetFullPathReal;
  785. symlink += " ";
  786. symlink += targetFullPathSO;
  787. symlink += " ";
  788. symlink += targetFullPath;
  789. commands.push_back(symlink);
  790. }
  791. // collect custom commands for this target and add them to the list
  792. customCommands = this->CreatePostBuildRules(t, name);
  793. if(customCommands.size() > 0)
  794. {
  795. commands.push_back(customCommands);
  796. }
  797. // collect up the link libraries
  798. cmOStringStream linklibs;
  799. this->OutputLinkLibraries(linklibs, name, t);
  800. for(std::vector<std::string>::iterator i = commands.begin();
  801. i != commands.end(); ++i)
  802. {
  803. this->ExpandRuleVariables(*i,
  804. t.GetLinkerLanguage(m_GlobalGenerator),
  805. objs.c_str(),
  806. targetFullPathReal.c_str(),
  807. linklibs.str().c_str(),
  808. 0, 0, 0, objsQuoted.c_str(),
  809. targetFullPathBase.c_str(),
  810. targetNameSO.c_str(),
  811. linkFlags);
  812. }
  813. targetFullPath = m_LibraryOutputPath + targetName;
  814. this->OutputMakeRule(fout, comment,
  815. targetFullPath.c_str(),
  816. depend.c_str(),
  817. commands);
  818. depend = targetFullPath;
  819. std::string tgt = this->ConvertToRelativeOutputPath(targetFullPath.c_str());
  820. tgt = this->ConvertToMakeTarget(tgt.c_str());
  821. cmSystemTools::ConvertToUnixSlashes(tgt);
  822. if(tgt.find('/', 0) != tgt.npos)
  823. {
  824. // we need a local target
  825. depend = this->ConvertToRelativeOutputPath(depend.c_str());
  826. std::string target = targetName;
  827. commands.resize(0);
  828. this->OutputMakeRule(fout,
  829. comment,
  830. target.c_str(),
  831. depend.c_str(),
  832. commands);
  833. }
  834. // Add a target with the canonical name (no prefix, suffix or path).
  835. this->OutputMakeRule(fout,
  836. comment,
  837. name,
  838. this->ConvertToRelativeOutputPath(tgt.c_str()).c_str(),
  839. 0);
  840. }
  841. void cmLocalUnixMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
  842. const char* name,
  843. const cmTarget &t)
  844. {
  845. const char* linkLanguage = t.GetLinkerLanguage(this->GetGlobalGenerator());
  846. if(!linkLanguage)
  847. {
  848. cmSystemTools::Error("CMake can not determine linker language target:",
  849. t.GetName());
  850. return;
  851. }
  852. std::string createRule = "CMAKE_";
  853. createRule += linkLanguage;
  854. createRule += "_CREATE_SHARED_LIBRARY";
  855. std::string buildType = m_Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  856. buildType = cmSystemTools::UpperCase(buildType);
  857. std::string linkFlags = m_Makefile->GetSafeDefinition("CMAKE_SHARED_LINKER_FLAGS");
  858. linkFlags += " ";
  859. if(buildType.size())
  860. {
  861. std::string build = "CMAKE_SHARED_LINKER_FLAGS_";
  862. build += buildType;
  863. linkFlags += m_Makefile->GetSafeDefinition(build.c_str());
  864. linkFlags += " ";
  865. }
  866. if(m_Makefile->IsOn("WIN32") && !(m_Makefile->IsOn("CYGWIN") || m_Makefile->IsOn("MINGW")))
  867. {
  868. const std::vector<cmSourceFile*>& sources = t.GetSourceFiles();
  869. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  870. i != sources.end(); ++i)
  871. {
  872. if((*i)->GetSourceExtension() == "def")
  873. {
  874. linkFlags += m_Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  875. linkFlags += this->ConvertToRelativeOutputPath((*i)->GetFullPath().c_str());
  876. linkFlags += " ";
  877. }
  878. }
  879. }
  880. const char* targetLinkFlags = t.GetProperty("LINK_FLAGS");
  881. if(targetLinkFlags)
  882. {
  883. linkFlags += targetLinkFlags;
  884. linkFlags += " ";
  885. }
  886. this->OutputLibraryRule(fout, name, t,
  887. createRule.c_str(),
  888. "shared library",
  889. linkFlags.c_str());
  890. }
  891. void cmLocalUnixMakefileGenerator::OutputModuleLibraryRule(std::ostream& fout,
  892. const char* name,
  893. const cmTarget &t)
  894. {
  895. const char* linkLanguage = t.GetLinkerLanguage(this->GetGlobalGenerator());
  896. if(!linkLanguage)
  897. {
  898. cmSystemTools::Error("CMake can not determine linker language for target:",
  899. t.GetName());
  900. return;
  901. }
  902. std::string createRule = "CMAKE_";
  903. createRule += linkLanguage;
  904. createRule += "_CREATE_SHARED_MODULE";
  905. std::string buildType = m_Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  906. buildType = cmSystemTools::UpperCase(buildType);
  907. std::string linkFlags = m_Makefile->GetSafeDefinition("CMAKE_MODULE_LINKER_FLAGS");
  908. linkFlags += " ";
  909. if(buildType.size())
  910. {
  911. std::string build = "CMAKE_MODULE_LINKER_FLAGS_";
  912. build += buildType;
  913. linkFlags += m_Makefile->GetSafeDefinition(build.c_str());
  914. linkFlags += " ";
  915. }
  916. const char* targetLinkFlags = t.GetProperty("LINK_FLAGS");
  917. if(targetLinkFlags)
  918. {
  919. linkFlags += targetLinkFlags;
  920. linkFlags += " ";
  921. }
  922. this->OutputLibraryRule(fout, name, t,
  923. createRule.c_str(),
  924. "shared module",
  925. linkFlags.c_str());
  926. }
  927. void cmLocalUnixMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
  928. const char* name,
  929. const cmTarget &t)
  930. {
  931. const char* linkLanguage = t.GetLinkerLanguage(this->GetGlobalGenerator());
  932. if(!linkLanguage)
  933. {
  934. cmSystemTools::Error("CMake can not determine linker language for target:",
  935. t.GetName());
  936. return;
  937. }
  938. std::string createRule = "CMAKE_";
  939. createRule += linkLanguage;
  940. createRule += "_CREATE_STATIC_LIBRARY";
  941. std::string linkFlags;
  942. const char* targetLinkFlags = t.GetProperty("STATIC_LIBRARY_FLAGS");
  943. if(targetLinkFlags)
  944. {
  945. linkFlags += targetLinkFlags;
  946. linkFlags += " ";
  947. }
  948. this->OutputLibraryRule(fout, name, t,
  949. createRule.c_str(),
  950. "static library",
  951. linkFlags.c_str());
  952. }
  953. void cmLocalUnixMakefileGenerator::OutputExecutableRule(std::ostream& fout,
  954. const char* name,
  955. const cmTarget &t)
  956. {
  957. std::string linkFlags;
  958. std::string buildType = m_Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  959. buildType = cmSystemTools::UpperCase(buildType);
  960. std::string flags;
  961. // Construct the full path to the executable that will be generated.
  962. std::string target = m_ExecutableOutputPath;
  963. if(target.length() == 0)
  964. {
  965. target = m_Makefile->GetCurrentOutputDirectory();
  966. if(target.size() && target[target.size()-1] != '/')
  967. {
  968. target += "/";
  969. }
  970. }
  971. #ifdef __APPLE__
  972. if ( t.GetPropertyAsBool("MACOSX_BUNDLE") )
  973. {
  974. // Make bundle directories
  975. target += name;
  976. target += ".app/Contents/MacOS/";
  977. }
  978. #endif
  979. target += name;
  980. target += cmSystemTools::GetExecutableExtension();
  981. target = this->ConvertToRelativeOutputPath(target.c_str());
  982. bool needsLocalTarget = false;
  983. if(m_UseRelativePaths)
  984. {
  985. cmSystemTools::ConvertToUnixSlashes(target);
  986. std::string tgt = this->ConvertToMakeTarget(target.c_str());
  987. if(tgt.find('/', 0) != tgt.npos)
  988. {
  989. needsLocalTarget = true;
  990. }
  991. target = cmSystemTools::ConvertToOutputPath(target.c_str());
  992. }
  993. else
  994. {
  995. needsLocalTarget = true;
  996. }
  997. std::string objs = "$(" + this->CreateMakeVariable(name, "_SRC_OBJS") +
  998. ") $(" + this->CreateMakeVariable(name, "_EXTERNAL_OBJS") + ") ";
  999. std::string depend = "$(";
  1000. depend += this->CreateMakeVariable(name, "_SRC_OBJS")
  1001. + ") $(" + this->CreateMakeVariable(name, "_EXTERNAL_OBJS")
  1002. + ") $(" + this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
  1003. std::vector<std::string> rules;
  1004. linkFlags += m_Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
  1005. linkFlags += " ";
  1006. if(buildType.size())
  1007. {
  1008. std::string build = "CMAKE_EXE_LINKER_FLAGS_";
  1009. build += buildType;
  1010. linkFlags += m_Makefile->GetSafeDefinition(build.c_str());
  1011. linkFlags += " ";
  1012. }
  1013. const char* linkLanguage = t.GetLinkerLanguage(this->GetGlobalGenerator());
  1014. if(!linkLanguage)
  1015. {
  1016. cmSystemTools::Error("CMake can not determine linker language for target:",
  1017. t.GetName());
  1018. return;
  1019. }
  1020. std::string langVar = "CMAKE_";
  1021. langVar += linkLanguage;
  1022. std::string ruleVar = langVar + "_LINK_EXECUTABLE";
  1023. std::string flagsVar = langVar + "_FLAGS";
  1024. std::string sharedFlagsVar = "CMAKE_SHARED_LIBRARY_";
  1025. sharedFlagsVar += langVar;
  1026. sharedFlagsVar += "_FLAGS";
  1027. rules.push_back(m_Makefile->GetRequiredDefinition(ruleVar.c_str()));
  1028. flags += m_Makefile->GetSafeDefinition(flagsVar.c_str());
  1029. flags += " ";
  1030. flags += m_Makefile->GetSafeDefinition(sharedFlagsVar.c_str());
  1031. flags += " ";
  1032. cmOStringStream linklibs;
  1033. this->OutputLinkLibraries(linklibs, 0, t);
  1034. std::string comment = "executable";
  1035. std::vector<std::string> commands;
  1036. std::string customCommands = this->CreatePreBuildRules(t, name);
  1037. if(customCommands.size() > 0)
  1038. {
  1039. commands.push_back(customCommands.c_str());
  1040. }
  1041. customCommands = this->CreatePreLinkRules(t, name);
  1042. if(customCommands.size() > 0)
  1043. {
  1044. commands.push_back(customCommands.c_str());
  1045. }
  1046. cmSystemTools::ExpandList(rules, commands);
  1047. customCommands = this->CreatePostBuildRules(t, name);
  1048. if(customCommands.size() > 0)
  1049. {
  1050. commands.push_back(customCommands.c_str());
  1051. }
  1052. if(cmSystemTools::IsOn(m_Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  1053. {
  1054. std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_") + linkLanguage
  1055. + std::string("_FLAGS");
  1056. linkFlags += m_Makefile->GetSafeDefinition(sFlagVar.c_str());
  1057. linkFlags += " ";
  1058. }
  1059. if ( t.GetPropertyAsBool("WIN32_EXECUTABLE") )
  1060. {
  1061. linkFlags += m_Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
  1062. linkFlags += " ";
  1063. }
  1064. else
  1065. {
  1066. linkFlags += m_Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
  1067. linkFlags += " ";
  1068. }
  1069. const char* targetLinkFlags = t.GetProperty("LINK_FLAGS");
  1070. if(targetLinkFlags)
  1071. {
  1072. linkFlags += targetLinkFlags;
  1073. linkFlags += " ";
  1074. }
  1075. for(std::vector<std::string>::iterator i = commands.begin();
  1076. i != commands.end(); ++i)
  1077. {
  1078. this->ExpandRuleVariables(*i,
  1079. linkLanguage,
  1080. objs.c_str(),
  1081. target.c_str(),
  1082. linklibs.str().c_str(),
  1083. 0,
  1084. 0,
  1085. flags.c_str(),
  1086. 0,
  1087. 0,
  1088. 0,
  1089. linkFlags.c_str());
  1090. }
  1091. this->OutputMakeRule(fout,
  1092. comment.c_str(),
  1093. target.c_str(),
  1094. depend.c_str(),
  1095. commands);
  1096. // If there is no executable output path, add a rule with the
  1097. // relative path to the executable. This is necessary for
  1098. // try-compile to work in this case.
  1099. if(needsLocalTarget)
  1100. {
  1101. depend = target;
  1102. target = name;
  1103. target += cmSystemTools::GetExecutableExtension();
  1104. target = this->ConvertToRelativeOutputPath(target.c_str());
  1105. commands.resize(0);
  1106. this->OutputMakeRule(fout,
  1107. comment.c_str(),
  1108. target.c_str(),
  1109. depend.c_str(),
  1110. commands);
  1111. }
  1112. // Add a target with the canonical name (no prefix, suffix or path).
  1113. // Note that on some platforms the "local target" added above will
  1114. // actually be the canonical name and will have set "target"
  1115. // correctly. Do not duplicate this target.
  1116. if(target != name)
  1117. {
  1118. this->OutputMakeRule(fout, comment.c_str(), name, target.c_str(), 0);
  1119. }
  1120. }
  1121. void cmLocalUnixMakefileGenerator::OutputUtilityRule(std::ostream& fout,
  1122. const char* name,
  1123. const cmTarget &t)
  1124. {
  1125. const char* cc = 0;
  1126. std::string customCommands = this->CreatePreBuildRules(t, name);
  1127. std::string customCommands2 = this->CreatePreLinkRules(t, name);
  1128. if(customCommands2.size() > 0)
  1129. {
  1130. customCommands += customCommands2;
  1131. }
  1132. customCommands2 = this->CreatePostBuildRules(t, name);
  1133. if(customCommands2.size() > 0)
  1134. {
  1135. customCommands += customCommands2;
  1136. }
  1137. if(customCommands.size() > 0)
  1138. {
  1139. cc = customCommands.c_str();
  1140. }
  1141. std::string comment = "Utility";
  1142. std::string depends;
  1143. depends = "$(" + this->CreateMakeVariable(name, "_DEPEND_LIBS") + ")";
  1144. std::string replaceVars;
  1145. const std::vector<cmCustomCommand> &ccs = t.GetPostBuildCommands();
  1146. for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
  1147. i != ccs.end(); ++i)
  1148. {
  1149. const std::vector<std::string> & dep = i->GetDepends();
  1150. for(std::vector<std::string>::const_iterator d = dep.begin();
  1151. d != dep.end(); ++d)
  1152. {
  1153. depends += " \\\n";
  1154. replaceVars = *d;
  1155. m_Makefile->ExpandVariablesInString(replaceVars);
  1156. depends += this->ConvertToMakeTarget(this->ConvertToRelativeOutputPath(replaceVars.c_str()).c_str());
  1157. }
  1158. }
  1159. this->OutputMakeRule(fout, comment.c_str(), name,
  1160. depends.c_str(), cc);
  1161. }
  1162. void cmLocalUnixMakefileGenerator::OutputTargets(std::ostream& fout)
  1163. {
  1164. // for each target
  1165. const cmTargets &tgts = m_Makefile->GetTargets();
  1166. for(cmTargets::const_iterator l = tgts.begin();
  1167. l != tgts.end(); l++)
  1168. {
  1169. switch(l->second.GetType())
  1170. {
  1171. case cmTarget::STATIC_LIBRARY:
  1172. this->OutputStaticLibraryRule(fout, l->first.c_str(), l->second);
  1173. break;
  1174. case cmTarget::SHARED_LIBRARY:
  1175. this->OutputSharedLibraryRule(fout, l->first.c_str(), l->second);
  1176. break;
  1177. case cmTarget::MODULE_LIBRARY:
  1178. this->OutputModuleLibraryRule(fout, l->first.c_str(), l->second);
  1179. break;
  1180. case cmTarget::EXECUTABLE:
  1181. this->OutputExecutableRule(fout, l->first.c_str(), l->second);
  1182. break;
  1183. case cmTarget::UTILITY:
  1184. this->OutputUtilityRule(fout, l->first.c_str(), l->second);
  1185. break;
  1186. // This is handled by the OutputCustomRules method
  1187. case cmTarget::INSTALL_FILES:
  1188. // This is handled by the OutputInstallRules method
  1189. case cmTarget::INSTALL_PROGRAMS:
  1190. // This is handled by the OutputInstallRules method
  1191. break;
  1192. }
  1193. }
  1194. }
  1195. // For each target that is an executable or shared library, generate
  1196. // the "<name>_DEPEND_LIBS" variable listing its library dependencies.
  1197. void cmLocalUnixMakefileGenerator::OutputDependLibs(std::ostream& fout)
  1198. {
  1199. // Build a set of libraries that will be linked into any target in
  1200. // this directory.
  1201. std::set<cmStdString> used;
  1202. // for each target
  1203. const cmTargets &tgts = m_Makefile->GetTargets();
  1204. for(cmTargets::const_iterator l = tgts.begin();
  1205. l != tgts.end(); l++)
  1206. {
  1207. // Each dependency should only be emitted once per target.
  1208. std::set<cmStdString> emitted;
  1209. if ((l->second.GetType() == cmTarget::SHARED_LIBRARY)
  1210. || (l->second.GetType() == cmTarget::MODULE_LIBRARY)
  1211. || (l->second.GetType() == cmTarget::STATIC_LIBRARY)
  1212. || (l->second.GetType() == cmTarget::EXECUTABLE)
  1213. || (l->second.GetType() == cmTarget::UTILITY))
  1214. {
  1215. fout << this->CreateMakeVariable(l->first.c_str(), "_DEPEND_LIBS") << " = ";
  1216. // A library should not depend on itself!
  1217. emitted.insert(l->first);
  1218. // for static libraries do not depend on other libraries
  1219. if(l->second.GetType() != cmTarget::STATIC_LIBRARY)
  1220. {
  1221. // Now, look at all link libraries specific to this target.
  1222. const cmTarget::LinkLibraries& tlibs = l->second.GetLinkLibraries();
  1223. for(cmTarget::LinkLibraries::const_iterator lib = tlibs.begin();
  1224. lib != tlibs.end(); ++lib)
  1225. {
  1226. // Record that this library was used.
  1227. used.insert(lib->first);
  1228. // Don't emit the same library twice for this target.
  1229. if(emitted.insert(lib->first).second)
  1230. {
  1231. // Output this dependency.
  1232. this->OutputLibDepend(fout, lib->first.c_str());
  1233. }
  1234. }
  1235. }
  1236. // for all targets depend on utilities
  1237. // Now, look at all utilities specific to this target.
  1238. const std::set<cmStdString>& tutils = l->second.GetUtilities();
  1239. for(std::set<cmStdString>::const_iterator util = tutils.begin();
  1240. util != tutils.end(); ++util)
  1241. {
  1242. // Record that this utility was used.
  1243. used.insert(*util);
  1244. // Don't emit the same utility twice for this target.
  1245. if(emitted.insert(*util).second)
  1246. {
  1247. // Output this dependency.
  1248. std::string utilType = *util + "_LIBRARY_TYPE";
  1249. const char* libType = m_Makefile->GetDefinition(utilType.c_str());
  1250. if ( libType )
  1251. {
  1252. this->OutputLibDepend(fout, util->c_str());
  1253. }
  1254. else
  1255. {
  1256. this->OutputExeDepend(fout, util->c_str());
  1257. }
  1258. }
  1259. }
  1260. fout << "\n";
  1261. }
  1262. }
  1263. fout << "\n";
  1264. // Loop over the libraries used and make sure there is a rule to
  1265. // build them in this makefile. If the library is in another
  1266. // directory, add a rule to jump to that directory and make sure it
  1267. // exists.
  1268. for(std::set<cmStdString>::const_iterator lib = used.begin();
  1269. lib != used.end(); ++lib)
  1270. {
  1271. // loop over the list of directories that the libraries might
  1272. // be in, looking for an ADD_LIBRARY(lib...) line. This would
  1273. // be stored in the cache
  1274. std::string libPath = *lib + "_CMAKE_PATH";
  1275. const char* cacheValue = m_Makefile->GetDefinition(libPath.c_str());
  1276. // if cache and not the current directory add a rule, to
  1277. // jump into the directory and build for the first time
  1278. if(cacheValue && *cacheValue &&
  1279. (!this->SamePath(m_Makefile->GetCurrentOutputDirectory(), cacheValue)))
  1280. {
  1281. // add the correct extension
  1282. std::string ltname = *lib+"_LIBRARY_TYPE";
  1283. const char* libType
  1284. = m_Makefile->GetDefinition(ltname.c_str());
  1285. // if it was a library..
  1286. if (libType)
  1287. {
  1288. std::string library;
  1289. std::string libpath = cacheValue;
  1290. if(libType && std::string(libType) == "SHARED")
  1291. {
  1292. library = m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX");
  1293. library += *lib;
  1294. library += m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
  1295. }
  1296. else if(libType && std::string(libType) == "MODULE")
  1297. {
  1298. library = m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_PREFIX");
  1299. library += *lib;
  1300. library += m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_SUFFIX");
  1301. }
  1302. else if(libType && std::string(libType) == "STATIC")
  1303. {
  1304. library = m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX");
  1305. library += *lib;
  1306. library += m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
  1307. }
  1308. else
  1309. {
  1310. cmSystemTools::Error("Unknown library type!");
  1311. return;
  1312. }
  1313. if(m_LibraryOutputPath.size())
  1314. {
  1315. libpath = m_LibraryOutputPath;
  1316. }
  1317. else
  1318. {
  1319. libpath += "/";
  1320. }
  1321. libpath += library;
  1322. // put out a rule to build the library if it does not exist
  1323. this->OutputBuildTargetInDir(fout,
  1324. cacheValue,
  1325. library.c_str(),
  1326. libpath.c_str());
  1327. }
  1328. // something other than a library...
  1329. else
  1330. {
  1331. std::string exepath = cacheValue;
  1332. if(m_ExecutableOutputPath.size())
  1333. {
  1334. exepath = m_ExecutableOutputPath;
  1335. }
  1336. else
  1337. {
  1338. exepath += "/";
  1339. }
  1340. std::string fullName = lib->c_str();
  1341. fullName += cmSystemTools::GetExecutableExtension();
  1342. exepath += fullName;
  1343. this->OutputBuildTargetInDir(fout,
  1344. cacheValue,
  1345. fullName.c_str(),
  1346. exepath.c_str());
  1347. }
  1348. }
  1349. }
  1350. }
  1351. void cmLocalUnixMakefileGenerator::OutputBuildTargetInDirWindows(std::ostream& fout,
  1352. const char* path,
  1353. const char* library,
  1354. const char* fullpath)
  1355. {
  1356. std::string jumpBack;
  1357. if(m_UseRelativePaths)
  1358. {
  1359. jumpBack = cmSystemTools::RelativePath(cmSystemTools::GetProgramPath(path).c_str(),
  1360. m_Makefile->GetCurrentOutputDirectory());
  1361. }
  1362. else
  1363. {
  1364. jumpBack = m_Makefile->GetCurrentOutputDirectory();
  1365. }
  1366. jumpBack = this->ConvertToOutputForExisting(jumpBack.c_str());
  1367. std::string wpath = this->ConvertToOutputForExisting(path);
  1368. std::string wfullpath = this->ConvertToRelativeOutputPath(fullpath);
  1369. fout << wfullpath
  1370. << ":\n\tcd " << wpath << "\n"
  1371. << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) cmake.depends\n"
  1372. << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) cmake.check_depends\n"
  1373. << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) -f cmake.check_depends\n"
  1374. << "\t$(MAKE) $(MAKESILENT) " << library
  1375. << "\n\tcd " << jumpBack << "\n";
  1376. }
  1377. void cmLocalUnixMakefileGenerator::OutputBuildTargetInDir(std::ostream& fout,
  1378. const char* path,
  1379. const char* library,
  1380. const char* fullpath)
  1381. {
  1382. if(m_WindowsShell)
  1383. {
  1384. this->OutputBuildTargetInDirWindows(fout, path, library, fullpath);
  1385. return;
  1386. }
  1387. fout << this->ConvertToOutputForExisting(fullpath)
  1388. << ":\n\tcd " << this->ConvertToOutputForExisting(path)
  1389. << "; $(MAKE) $(MAKESILENT) cmake.depends"
  1390. << "; $(MAKE) $(MAKESILENT) cmake.check_depends"
  1391. << "; $(MAKE) $(MAKESILENT) -f cmake.check_depends"
  1392. << "; $(MAKE) $(MAKESILENT) "
  1393. << library << "\n\n";
  1394. }
  1395. bool cmLocalUnixMakefileGenerator::SamePath(const char* path1, const char* path2)
  1396. {
  1397. if (strcmp(path1, path2) == 0)
  1398. {
  1399. return true;
  1400. }
  1401. #if defined(_WIN32) || defined(__APPLE__)
  1402. return
  1403. cmSystemTools::LowerCase(this->ConvertToOutputForExisting(path1)) ==
  1404. cmSystemTools::LowerCase(this->ConvertToOutputForExisting(path2));
  1405. #else
  1406. return false;
  1407. #endif
  1408. }
  1409. void cmLocalUnixMakefileGenerator::OutputLibDepend(std::ostream& fout,
  1410. const char* name)
  1411. {
  1412. std::string libPath = name;
  1413. libPath += "_CMAKE_PATH";
  1414. const char* cacheValue = m_Makefile->GetDefinition(libPath.c_str());
  1415. if( cacheValue && *cacheValue )
  1416. {
  1417. // if there is a cache value, then this is a library that cmake
  1418. // knows how to build, so we can depend on it
  1419. std::string libpath;
  1420. if (!this->SamePath(m_Makefile->GetCurrentOutputDirectory(), cacheValue))
  1421. {
  1422. // if the library is not in the current directory, then get the full
  1423. // path to it
  1424. if(m_LibraryOutputPath.size())
  1425. {
  1426. libpath = m_LibraryOutputPath;
  1427. }
  1428. else
  1429. {
  1430. libpath = cacheValue;
  1431. libpath += "/";
  1432. }
  1433. }
  1434. else
  1435. {
  1436. // library is in current Makefile so use lib as a prefix
  1437. libpath = m_LibraryOutputPath;
  1438. }
  1439. // add the correct extension
  1440. std::string ltname = name;
  1441. ltname += "_LIBRARY_TYPE";
  1442. const char* libType = m_Makefile->GetDefinition(ltname.c_str());
  1443. if(libType && std::string(libType) == "SHARED")
  1444. {
  1445. libpath += m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX");
  1446. libpath += name;
  1447. libpath += m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
  1448. }
  1449. else if (libType && std::string(libType) == "MODULE")
  1450. {
  1451. libpath += m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_PREFIX");
  1452. libpath += name;
  1453. libpath += m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_SUFFIX");
  1454. }
  1455. else if (libType && std::string(libType) == "STATIC")
  1456. {
  1457. libpath += m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX");
  1458. libpath += name;
  1459. libpath += m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
  1460. }
  1461. fout << this->ConvertToRelativeOutputPath(libpath.c_str()) << " ";
  1462. }
  1463. else
  1464. {
  1465. if(cmSystemTools::FileExists(name))
  1466. {
  1467. std::string nameStr = name;
  1468. // if it starts with / or \ or ?:/ or ?:\ then it must be a full path
  1469. if( (nameStr.size() && (nameStr[0] == '/' || nameStr[0] == '\\')) ||
  1470. ((nameStr.size() > 3) && (nameStr[1] == ':') && (nameStr[2] == '/' || nameStr[2] == '\\')))
  1471. {
  1472. fout << this->ConvertToRelativeOutputPath(name) << " ";
  1473. }
  1474. }
  1475. }
  1476. }
  1477. void cmLocalUnixMakefileGenerator::OutputExeDepend(std::ostream& fout,
  1478. const char* name)
  1479. {
  1480. std::string exePath = name;
  1481. exePath += "_CMAKE_PATH";
  1482. const char* cacheValue = m_Makefile->GetDefinition(exePath.c_str());
  1483. if( cacheValue && *cacheValue )
  1484. {
  1485. // if there is a cache value, then this is a executable/utility that cmake
  1486. // knows how to build, so we can depend on it
  1487. std::string exepath;
  1488. if (!this->SamePath(m_Makefile->GetCurrentOutputDirectory(), cacheValue))
  1489. {
  1490. // if the exe/utility is not in the current directory, then get the full
  1491. // path to it
  1492. if(m_ExecutableOutputPath.size())
  1493. {
  1494. exepath = m_ExecutableOutputPath;
  1495. }
  1496. else
  1497. {
  1498. exepath = cacheValue;
  1499. exepath += "/";
  1500. }
  1501. }
  1502. else
  1503. {
  1504. // library is in current Makefile
  1505. exepath = m_ExecutableOutputPath;
  1506. }
  1507. // add the library name
  1508. exepath += name;
  1509. // add the correct extension
  1510. exepath += cmSystemTools::GetExecutableExtension();
  1511. fout << this->ConvertToRelativeOutputPath(exepath.c_str()) << " ";
  1512. }
  1513. // if it isn't in the cache, it might still be a utility target
  1514. // so check for that
  1515. else
  1516. {
  1517. std::map<cmStdString, cmTarget>& targets = m_Makefile->GetTargets();
  1518. if (targets.find(name) != targets.end())
  1519. {
  1520. fout << name << " ";
  1521. }
  1522. }
  1523. }
  1524. // fix up names of directories so they can be used
  1525. // as targets in makefiles.
  1526. inline std::string FixDirectoryName(const char* dir)
  1527. {
  1528. std::string s = dir;
  1529. // replace ../ with 3 under bars
  1530. size_t pos = s.find("../");
  1531. if(pos != std::string::npos)
  1532. {
  1533. s.replace(pos, 3, "___");
  1534. }
  1535. // replace / directory separators with a single under bar
  1536. pos = s.find("/");
  1537. while(pos != std::string::npos)
  1538. {
  1539. s.replace(pos, 1, "_");
  1540. pos = s.find("/");
  1541. }
  1542. return s;
  1543. }
  1544. void cmLocalUnixMakefileGenerator::
  1545. BuildInSubDirectoryWindows(std::ostream& fout,
  1546. const char* directory,
  1547. const char* target1,
  1548. const char* target2,
  1549. bool silent)
  1550. {
  1551. std::string dir;
  1552. if(target1)
  1553. {
  1554. dir = this->ConvertToOutputForExisting(directory);
  1555. if(dir[0] == '\"')
  1556. {
  1557. dir = dir.substr(1, dir.size()-2);
  1558. }
  1559. fout << "\tif not exist \"" << dir << "\\$(NULL)\""
  1560. << " "
  1561. << "$(MAKE) $(MAKESILENT) rebuild_cache\n";
  1562. if (!silent)
  1563. {
  1564. fout << "\t@echo " << directory << ": building " << target1 << "\n";
  1565. }
  1566. fout << "\tcd " << dir << "\n"
  1567. << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) " << target1 << "\n";
  1568. }
  1569. if(target2)
  1570. {
  1571. if (!silent)
  1572. {
  1573. fout << "\t@echo " << directory << ": building " << target2 << "\n";
  1574. }
  1575. fout << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) " << target2 << "\n";
  1576. }
  1577. std::string currentDir;
  1578. if(m_UseRelativePaths)
  1579. {
  1580. currentDir = dir;
  1581. cmSystemTools::ConvertToUnixSlashes(currentDir);
  1582. std::string cdback = "..";
  1583. unsigned int i = 0;
  1584. if(currentDir.size() > 2 && currentDir[0] == '.' && currentDir[1] == '/')
  1585. {
  1586. // start past ./ if it starts with ./
  1587. i = 2;
  1588. }
  1589. for(; i < currentDir.size(); ++i)
  1590. {
  1591. if(currentDir[i] == '/')
  1592. {
  1593. cdback += "/..";
  1594. }
  1595. }
  1596. fout << "\tcd " << this->ConvertToOutputForExisting(cdback.c_str()) << "\n\n";
  1597. }
  1598. else
  1599. {
  1600. currentDir = m_Makefile->GetCurrentOutputDirectory();
  1601. fout << "\tcd " << this->ConvertToOutputForExisting(currentDir.c_str()) << "\n\n";
  1602. }
  1603. }
  1604. void cmLocalUnixMakefileGenerator::BuildInSubDirectory(std::ostream& fout,
  1605. const char* dir,
  1606. const char* target1,
  1607. const char* target2,
  1608. bool silent)
  1609. {
  1610. if(m_WindowsShell)
  1611. {
  1612. this->BuildInSubDirectoryWindows(fout, dir, target1, target2, silent);
  1613. return;
  1614. }
  1615. std::string directory = this->ConvertToRelativeOutputPath(dir);
  1616. if(target1)
  1617. {
  1618. fout << "\t@if test ! -d " << directory
  1619. << "; then $(MAKE) rebuild_cache; fi\n";
  1620. if (!silent)
  1621. {
  1622. fout << "\t@echo " << directory << ": building " << target1 << "\n";
  1623. }
  1624. fout << "\t@cd " << directory
  1625. << "; $(MAKE) " << target1 << "\n";
  1626. }
  1627. if(target2)
  1628. {
  1629. if (!silent)
  1630. {
  1631. fout << "\t@echo " << directory << ": building " << target2 << "\n";
  1632. }
  1633. fout << "\t@cd " << directory
  1634. << "; $(MAKE) " << target2 << "\n";
  1635. }
  1636. fout << "\n";
  1637. }
  1638. void
  1639. cmLocalUnixMakefileGenerator::
  1640. OutputSubDirectoryVars(std::ostream& fout,
  1641. const char* var,
  1642. const char* target,
  1643. const char* target1,
  1644. const char* target2,
  1645. const char* depend,
  1646. const std::vector<std::pair<cmStdString, bool> >& SubDirectories,
  1647. bool silent, int order)
  1648. {
  1649. if(!depend)
  1650. {
  1651. depend = "";
  1652. }
  1653. if( SubDirectories.size() == 0)
  1654. {
  1655. return;
  1656. }
  1657. fout << "# Variable for making " << target << " in subdirectories.\n";
  1658. fout << var << " = ";
  1659. unsigned int ii;
  1660. // make sure all the pre-order subdirectories are fist
  1661. // other than that keep the same order that the user specified
  1662. std::vector<std::pair<cmStdString, bool> > orderedDirs;
  1663. // collect pre-order first
  1664. for(ii =0; ii < SubDirectories.size(); ii++)
  1665. {
  1666. if(m_Makefile->IsDirectoryPreOrder(SubDirectories[ii].first.c_str()))
  1667. {
  1668. orderedDirs.push_back(SubDirectories[ii]);
  1669. }
  1670. }
  1671. // now collect post order dirs
  1672. for(ii =0; ii < SubDirectories.size(); ii++)
  1673. {
  1674. if(!m_Makefile->IsDirectoryPreOrder(SubDirectories[ii].first.c_str()))
  1675. {
  1676. orderedDirs.push_back(SubDirectories[ii]);
  1677. }
  1678. }
  1679. for(ii =0; ii < orderedDirs.size(); ii++)
  1680. {
  1681. if(!orderedDirs[ii].second)
  1682. {
  1683. continue;
  1684. }
  1685. if(order == 1 && m_Makefile->IsDirectoryPreOrder(orderedDirs[ii].first.c_str()))
  1686. {
  1687. continue;
  1688. }
  1689. if(order == 2 && !m_Makefile->IsDirectoryPreOrder(orderedDirs[ii].first.c_str()))
  1690. {
  1691. continue;
  1692. }
  1693. fout << " \\\n";
  1694. std::string subdir = FixDirectoryName(orderedDirs[ii].first.c_str());
  1695. fout << target << "_" << subdir.c_str();
  1696. }
  1697. fout << " \n\n";
  1698. fout << "# Targets for making " << target << " in subdirectories.\n";
  1699. std::string last = "";
  1700. for(unsigned int cc =0; cc < orderedDirs.size(); cc++)
  1701. {
  1702. if(!orderedDirs[cc].second)
  1703. {
  1704. continue;
  1705. }
  1706. std::string subdir = FixDirectoryName(orderedDirs[cc].first.c_str());
  1707. if(order == 1 && m_Makefile->IsDirectoryPreOrder(orderedDirs[cc].first.c_str()))
  1708. {
  1709. last = subdir;
  1710. continue;
  1711. }
  1712. if(order == 2 && !m_Makefile->IsDirectoryPreOrder(orderedDirs[cc].first.c_str()))
  1713. {
  1714. last = subdir;
  1715. continue;
  1716. }
  1717. fout << target << "_" << subdir.c_str() << ": " << depend;
  1718. // Make each subdirectory depend on previous one. This forces
  1719. // parallel builds (make -j 2) to build in same order as a single
  1720. // threaded build to avoid dependency problems.
  1721. if(cc > 0)
  1722. {
  1723. fout << " " << target << "_" << last.c_str();
  1724. }
  1725. fout << "\n";
  1726. last = subdir;
  1727. std::string dir = m_Makefile->GetCurrentOutputDirectory();
  1728. dir += "/";
  1729. dir += orderedDirs[cc].first;
  1730. this->BuildInSubDirectory(fout, dir.c_str(),
  1731. target1, target2, silent);
  1732. }
  1733. fout << "\n\n";
  1734. }
  1735. // output rules for decending into sub directories
  1736. void cmLocalUnixMakefileGenerator::OutputSubDirectoryRules(std::ostream& fout)
  1737. {
  1738. // Output Sub directory build rules
  1739. const std::vector<std::pair<cmStdString, bool> >& SubDirectories
  1740. = m_Makefile->GetSubDirectories();
  1741. if( SubDirectories.size() == 0)
  1742. {
  1743. return;
  1744. }
  1745. this->OutputSubDirectoryVars(fout,
  1746. "SUBDIR_BUILD",
  1747. "default_target",
  1748. "default_target",
  1749. 0, "$(TARGETS)",
  1750. SubDirectories,
  1751. false, 1);
  1752. this->OutputSubDirectoryVars(fout,
  1753. "SUBDIR_PREORDER_BUILD",
  1754. "default_target",
  1755. "default_target",
  1756. 0, 0,
  1757. SubDirectories,
  1758. false, 2);
  1759. this->OutputSubDirectoryVars(fout, "SUBDIR_CLEAN", "clean",
  1760. "clean",
  1761. 0, 0,
  1762. SubDirectories);
  1763. this->OutputSubDirectoryVars(fout, "SUBDIR_DEPEND", "depend",
  1764. "depend",
  1765. 0, 0,
  1766. SubDirectories);
  1767. }
  1768. // Output the depend information for all the classes
  1769. // in the makefile. These would have been generated
  1770. // by the class cmMakeDepend GenerateMakefile
  1771. bool cmLocalUnixMakefileGenerator::OutputObjectDepends(std::ostream& fout)
  1772. {
  1773. bool ret = false;
  1774. // Iterate over every target.
  1775. std::map<cmStdString, cmTarget>& targets = m_Makefile->GetTargets();
  1776. for(std::map<cmStdString, cmTarget>::const_iterator target = targets.begin();
  1777. target != targets.end(); ++target)
  1778. {
  1779. // Iterate over every source for this target.
  1780. const std::vector<cmSourceFile*>& sources = target->second.GetSourceFiles();
  1781. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  1782. source != sources.end(); ++source)
  1783. {
  1784. if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  1785. {
  1786. if(!(*source)->GetDepends().empty())
  1787. {
  1788. // Iterate through all the dependencies for this source.
  1789. for(std::vector<std::string>::const_iterator dep =
  1790. (*source)->GetDepends().begin();
  1791. dep != (*source)->GetDepends().end(); ++dep)
  1792. {
  1793. std::string s = (*source)->GetSourceName();
  1794. std::string outExt =
  1795. m_GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  1796. (*source)->GetSourceExtension().c_str());
  1797. s += outExt;
  1798. s = this->CreateSafeUniqueObjectFileName(s.c_str());
  1799. fout << this->ConvertToRelativeOutputPath(s.c_str()) << " : "
  1800. << this->ConvertToRelativeOutputPath(dep->c_str()) << "\n";
  1801. ret = true;
  1802. }
  1803. fout << "\n\n";
  1804. }
  1805. }
  1806. }
  1807. }
  1808. return ret;
  1809. }
  1810. // Output the depend information for all the classes
  1811. // in the makefile. These would have been generated
  1812. // by the class cmMakeDepend GenerateMakefile
  1813. void cmLocalUnixMakefileGenerator::OutputCheckDepends(std::ostream& fout)
  1814. {
  1815. std::set<cmStdString> emittedLowerPath;
  1816. std::set<cmStdString> emitted;
  1817. // Iterate over every target.
  1818. std::map<cmStdString, cmTarget>& targets = m_Makefile->GetTargets();
  1819. fout << "# Suppresses display of executed commands\n";
  1820. fout << ".SILENT:\n";
  1821. fout << "# disable some common implicit rules to speed things up\n";
  1822. fout << ".SUFFIXES:\n";
  1823. fout << ".SUFFIXES:.hpuxmakemusthaverule\n";
  1824. this->OutputMakeVariables(fout);
  1825. fout << "default:\n";
  1826. fout << "\t$(MAKE) $(MAKESILENT) -f cmake.check_depends all\n"
  1827. << "\t$(MAKE) $(MAKESILENT) -f cmake.check_depends cmake.depends\n\n";
  1828. for(std::map<cmStdString, cmTarget>::const_iterator target = targets.begin();
  1829. target != targets.end(); ++target)
  1830. {
  1831. // Iterate over every source for this target.
  1832. const std::vector<cmSourceFile*>& sources = target->second.GetSourceFiles();
  1833. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  1834. source != sources.end(); ++source)
  1835. {
  1836. if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  1837. {
  1838. if(!(*source)->GetDepends().empty())
  1839. {
  1840. for(std::vector<std::string>::const_iterator dep =
  1841. (*source)->GetDepends().begin();
  1842. dep != (*source)->GetDepends().end(); ++dep)
  1843. {
  1844. // do not call CollapseFullPath on dep here, because it already
  1845. // has been done because m_FullPath on cmDependInformation
  1846. // always is it called. If it is called here, network builds are
  1847. // very slow because of the number of stats
  1848. std::string dependfile = this->ConvertToRelativeOutputPath(dep->c_str());
  1849. // use the lower path function to create uniqe names
  1850. std::string lowerpath = this->LowerCasePath(dependfile.c_str());
  1851. if(emittedLowerPath.insert(lowerpath).second)
  1852. {
  1853. emitted.insert(dependfile);
  1854. fout << "all: " << dependfile << "\n";
  1855. }
  1856. }
  1857. }
  1858. }
  1859. }
  1860. }
  1861. fout << "\n\n# if any of these files changes run make dependlocal\n";
  1862. std::set<cmStdString>::iterator i;
  1863. for(i = emitted.begin(); i != emitted.end(); ++i)
  1864. {
  1865. fout << "cmake.depends: " << *i << "\n";
  1866. }
  1867. fout << "cmake.depends: \n"
  1868. << "\t$(MAKE) $(MAKESILENT) dependlocal\n\n";
  1869. fout << "\n\n";
  1870. fout << "# if a .h file is removed then run make dependlocal\n\n";
  1871. for(std::set<cmStdString>::iterator it = emitted.begin();
  1872. it != emitted.end(); ++it)
  1873. {
  1874. fout << *it << ":\n"
  1875. << "\t$(MAKE) $(MAKESILENT) dependlocal\n\n";
  1876. }
  1877. }
  1878. // Output each custom rule in the following format:
  1879. // output: source depends...
  1880. // (tab) command...
  1881. void cmLocalUnixMakefileGenerator::OutputCustomRules(std::ostream& fout)
  1882. {
  1883. // we cannot provide multiple rules for a single output
  1884. // so we will keep track of outputs to make sure we don't write
  1885. // two rules. First found wins
  1886. std::set<cmStdString> processedOutputs;
  1887. // first output all custom rules
  1888. const std::vector<cmSourceFile*>& sources = m_Makefile->GetSourceFiles();
  1889. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1890. i != sources.end(); ++i)
  1891. {
  1892. if ((*i)->GetCustomCommand())
  1893. {
  1894. cmCustomCommand *c = (*i)->GetCustomCommand();
  1895. // escape spaces and convert to native slashes path for
  1896. // the command
  1897. std::string comment = c->GetComment();
  1898. std::vector<std::string> commands;
  1899. // Add each command line to the set of commands.
  1900. for(cmCustomCommandLines::const_iterator cl = c->GetCommandLines().begin();
  1901. cl != c->GetCommandLines().end(); ++cl)
  1902. {
  1903. // Build the command line in a single string.
  1904. const cmCustomCommandLine& commandLine = *cl;
  1905. std::string cmd = commandLine[0];
  1906. cmSystemTools::ReplaceString(cmd, "/./", "/");
  1907. cmd = this->ConvertToRelativeOutputPath(cmd.c_str());
  1908. for(unsigned int j=1; j < commandLine.size(); ++j)
  1909. {
  1910. cmd += " ";
  1911. cmd += cmSystemTools::EscapeSpaces(commandLine[j].c_str());
  1912. }
  1913. commands.push_back(cmd);
  1914. }
  1915. std::vector<std::string> depends;
  1916. // Collect out all the dependencies for this rule.
  1917. for(std::vector<std::string>::const_iterator d =
  1918. c->GetDepends().begin();
  1919. d != c->GetDepends().end(); ++d)
  1920. {
  1921. std::string dep = *d;
  1922. m_Makefile->ExpandVariablesInString(dep);
  1923. // watch for target dependencies,
  1924. std::string libPath = dep + "_CMAKE_PATH";
  1925. const char* cacheValue = m_Makefile->GetDefinition(libPath.c_str());
  1926. if ( cacheValue && *cacheValue )
  1927. {
  1928. libPath = cacheValue;
  1929. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH") &&
  1930. m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH")[0] != '\0')
  1931. {
  1932. libPath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  1933. }
  1934. libPath += "/";
  1935. libPath += dep;
  1936. libPath += cmSystemTools::GetExecutableExtension();
  1937. dep = libPath;
  1938. }
  1939. cmSystemTools::ReplaceString(dep, "/./", "/");
  1940. cmSystemTools::ReplaceString(dep, "/$(IntDir)/", "/");
  1941. dep = this->ConvertToRelativeOutputPath(dep.c_str());
  1942. depends.push_back(dep.c_str());
  1943. }
  1944. // output rule
  1945. if (processedOutputs.find(c->GetOutput()) == processedOutputs.end())
  1946. {
  1947. this->OutputMakeRule(fout,
  1948. (comment.size()?comment.c_str():"Custom command"),
  1949. c->GetOutput(),
  1950. depends,
  1951. commands);
  1952. processedOutputs.insert(c->GetOutput());
  1953. }
  1954. else
  1955. {
  1956. cmSystemTools::Error("An output was found with multiple rules on how to build it for output: ",
  1957. c->GetOutput());
  1958. }
  1959. }
  1960. }
  1961. }
  1962. void cmLocalUnixMakefileGenerator::OutputMakeVariables(std::ostream& fout)
  1963. {
  1964. const char* variables =
  1965. "# the standard shell for make\n"
  1966. "SHELL = /bin/sh\n"
  1967. "\n";
  1968. if(!m_WindowsShell)
  1969. {
  1970. fout << variables;
  1971. }
  1972. else
  1973. {
  1974. fout <<
  1975. "!IF \"$(OS)\" == \"Windows_NT\"\n"
  1976. "NULL=\n"
  1977. "!ELSE \n"
  1978. "NULL=nul\n"
  1979. "!ENDIF \n";
  1980. }
  1981. if(m_MakeSilentFlag.size())
  1982. {
  1983. fout << "MAKESILENT = " << m_MakeSilentFlag << "\n";
  1984. }
  1985. std::string cmakecommand = this->ConvertToOutputForExisting(
  1986. m_Makefile->GetRequiredDefinition("CMAKE_COMMAND"));
  1987. fout << "CMAKE_COMMAND = "
  1988. << cmakecommand
  1989. << "\n";
  1990. fout << "RM = " << cmakecommand.c_str() << " -E remove -f\n";
  1991. if(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  1992. {
  1993. fout << "CMAKE_EDIT_COMMAND = "
  1994. << this->ConvertToOutputForExisting(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  1995. << "\n";
  1996. }
  1997. fout << "CMAKE_CURRENT_SOURCE = " <<
  1998. this->ConvertToRelativeOutputPath(m_Makefile->GetStartDirectory())
  1999. << "\n";
  2000. fout << "CMAKE_CURRENT_BINARY = " <<
  2001. this->ConvertToRelativeOutputPath(m_Makefile->GetStartOutputDirectory())
  2002. << "\n";
  2003. fout << "CMAKE_SOURCE_DIR = " <<
  2004. this->ConvertToRelativeOutputPath(m_Makefile->GetHomeDirectory())
  2005. << "\n";
  2006. fout << "CMAKE_BINARY_DIR = " <<
  2007. this->ConvertToRelativeOutputPath(m_Makefile->GetHomeOutputDirectory())
  2008. << "\n";
  2009. fout << "\n\n";
  2010. }
  2011. void cmLocalUnixMakefileGenerator::OutputMakeRules(std::ostream& fout)
  2012. {
  2013. this->OutputMakeRule(fout,
  2014. "default build rule",
  2015. "all",
  2016. "cmake.depends $(SUBDIR_PREORDER_BUILD) $(TARGETS) $(SUBDIR_BUILD)",
  2017. 0);
  2018. this->OutputMakeRule(fout,
  2019. "clean generated files",
  2020. "clean",
  2021. "$(SUBDIR_CLEAN)",
  2022. "-@ $(RM) $(CLEAN_OBJECT_FILES) "
  2023. " $(TARGETS) $(TARGET_EXTRAS) $(GENERATED_QT_FILES) $(GENERATED_FLTK_FILES) $(ADDITIONAL_MAKE_CLEAN_FILES)");
  2024. // collect up all the sources
  2025. std::vector<std::string> allsources;
  2026. std::map<cmStdString, cmTarget>& targets = m_Makefile->GetTargets();
  2027. for(std::map<cmStdString,cmTarget>::const_iterator target = targets.begin();
  2028. target != targets.end(); ++target)
  2029. {
  2030. // Iterate over every source for this target.
  2031. const std::vector<cmSourceFile*>& sources = target->second.GetSourceFiles();
  2032. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  2033. source != sources.end(); ++source)
  2034. {
  2035. if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY"))
  2036. {
  2037. allsources.push_back(this->ConvertToRelativeOutputPath((*source)->GetFullPath().c_str()));
  2038. }
  2039. }
  2040. }
  2041. std::string checkCache = m_Makefile->GetHomeOutputDirectory();
  2042. checkCache += "/cmake.check_cache";
  2043. checkCache = this->ConvertToRelativeOutputPath(checkCache.c_str());
  2044. std::vector<std::string> cmake_depends;
  2045. cmake_depends.push_back("$(CMAKE_MAKEFILE_SOURCES)");
  2046. this->OutputMakeRule(fout,
  2047. "dependencies.",
  2048. "cmake.depends",
  2049. cmake_depends,
  2050. "$(CMAKE_COMMAND) "
  2051. "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
  2052. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2053. this->OutputMakeRule(fout,
  2054. "dependencies",
  2055. "cmake.check_depends",
  2056. allsources,
  2057. "$(CMAKE_COMMAND) "
  2058. "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
  2059. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2060. this->OutputMakeRule(fout,
  2061. "dependencies",
  2062. "depend",
  2063. "$(SUBDIR_DEPEND)",
  2064. "$(CMAKE_COMMAND) "
  2065. "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
  2066. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2067. this->OutputMakeRule(fout,
  2068. "dependencies",
  2069. "dependlocal",
  2070. 0,
  2071. "$(CMAKE_COMMAND) "
  2072. "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
  2073. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2074. this->OutputMakeRule(fout,
  2075. "CMakeCache.txt",
  2076. "rebuild_cache",
  2077. 0,
  2078. "$(CMAKE_COMMAND) "
  2079. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2080. std::vector<std::string> check_cache_depends;
  2081. std::string CMakeCache = m_Makefile->GetHomeOutputDirectory();
  2082. CMakeCache += "/CMakeCache.txt";
  2083. CMakeCache = this->ConvertToRelativeOutputPath(CMakeCache.c_str());
  2084. check_cache_depends.push_back("$(CMAKE_MAKEFILE_SOURCES)");
  2085. this->OutputMakeRule(fout,
  2086. "CMakeCache.txt because out-of-date:",
  2087. checkCache.c_str(),
  2088. check_cache_depends,
  2089. "$(CMAKE_COMMAND) "
  2090. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2091. // if CMAKE_EDIT_COMMAND is defined then add a rule to run it
  2092. // called edit_cache
  2093. if(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  2094. {
  2095. this->OutputMakeRule(fout,
  2096. "edit CMakeCache.txt",
  2097. "edit_cache",
  2098. 0,
  2099. "$(CMAKE_EDIT_COMMAND) "
  2100. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2101. }
  2102. else
  2103. {
  2104. this->OutputMakeRule(fout,
  2105. "edit CMakeCache.txt",
  2106. "edit_cache",
  2107. 0,
  2108. "$(CMAKE_COMMAND) "
  2109. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -i");
  2110. }
  2111. std::string cacheFile = m_Makefile->GetHomeOutputDirectory();
  2112. cacheFile += "/CMakeCache.txt";
  2113. cacheFile = this->ConvertToRelativeOutputPath(cacheFile.c_str());
  2114. this->OutputMakeRule(fout,
  2115. "CMakeCache.txt",
  2116. cacheFile.c_str(),
  2117. 0,
  2118. "$(CMAKE_COMMAND) "
  2119. "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  2120. this->OutputMakeRule(fout,
  2121. "Rule to keep make from removing Makefiles "
  2122. "if control-C is hit during a run of cmake.",
  2123. ".PRECIOUS",
  2124. "Makefile cmake.depends",
  2125. 0);
  2126. this->OutputSourceObjectBuildRules(fout);
  2127. // find ctest
  2128. std::string ctest = m_Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  2129. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  2130. ctest += "/";
  2131. ctest += "ctest";
  2132. ctest += cmSystemTools::GetExecutableExtension();
  2133. if(!cmSystemTools::FileExists(ctest.c_str()))
  2134. {
  2135. ctest = m_Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  2136. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  2137. ctest += "/Debug/";
  2138. ctest += "ctest";
  2139. ctest += cmSystemTools::GetExecutableExtension();
  2140. }
  2141. if(!cmSystemTools::FileExists(ctest.c_str()))
  2142. {
  2143. ctest = m_Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  2144. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  2145. ctest += "/Release/";
  2146. ctest += "ctest";
  2147. ctest += cmSystemTools::GetExecutableExtension();
  2148. }
  2149. if (!cmSystemTools::FileExists(ctest.c_str()))
  2150. {
  2151. if ( !m_Makefile->GetDefinition("PROJECT_NAME") ||
  2152. strcmp(m_Makefile->GetDefinition("PROJECT_NAME"), "CMake") )
  2153. {
  2154. return;
  2155. }
  2156. ctest = m_Makefile->GetRequiredDefinition("EXECUTABLE_OUTPUT_PATH");
  2157. ctest += "/ctest";
  2158. }
  2159. if (m_Makefile->IsOn("CMAKE_TESTING_ENABLED"))
  2160. {
  2161. fout << "ARGS=\n";
  2162. std::string cmd = this->ConvertToOutputForExisting(ctest.c_str());
  2163. cmd += " $(ARGS)";
  2164. this->OutputMakeRule(fout,
  2165. "tests",
  2166. "test",
  2167. "",
  2168. cmd.c_str());
  2169. }
  2170. if(m_Makefile->GetDefinition("CMake_BINARY_DIR"))
  2171. {
  2172. // We are building CMake itself. We cannot use the original
  2173. // executable to install over itself.
  2174. std::string rule = m_Makefile->GetRequiredDefinition("EXECUTABLE_OUTPUT_PATH");
  2175. rule += "/cmake";
  2176. rule = cmSystemTools::ConvertToOutputPath(rule.c_str());
  2177. rule += " -P cmake_install.cmake";
  2178. this->OutputMakeRule(fout, "installation", "install", "", rule.c_str());
  2179. }
  2180. else
  2181. {
  2182. this->OutputMakeRule(fout, "installation", "install", "",
  2183. "$(CMAKE_COMMAND) -P cmake_install.cmake");
  2184. }
  2185. }
  2186. void
  2187. cmLocalUnixMakefileGenerator::
  2188. OutputBuildObjectFromSource(std::ostream& fout,
  2189. const char* shortName,
  2190. const cmSourceFile& source,
  2191. const char* extraCompileFlags,
  2192. bool shared)
  2193. {
  2194. // Header files shouldn't have build rules.
  2195. if(source.GetPropertyAsBool("HEADER_FILE_ONLY") ||
  2196. m_GlobalGenerator->IgnoreFile(source.GetSourceExtension().c_str()))
  2197. {
  2198. return;
  2199. }
  2200. std::string outputExt =
  2201. m_GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  2202. source.GetSourceExtension().c_str());
  2203. std::string objectFile = std::string(shortName) + outputExt;
  2204. objectFile = this->CreateSafeUniqueObjectFileName(objectFile.c_str());
  2205. objectFile = this->ConvertToRelativeOutputPath(objectFile.c_str());
  2206. std::vector<std::string> rules;
  2207. std::string flags;
  2208. if(extraCompileFlags)
  2209. {
  2210. flags += extraCompileFlags;
  2211. }
  2212. std::string sourceFile =
  2213. this->ConvertToRelativeOutputPath(source.GetFullPath().c_str());
  2214. std::string buildType = m_Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  2215. buildType = cmSystemTools::UpperCase(buildType);
  2216. // find out what language the source file is
  2217. const char* lang =
  2218. m_GlobalGenerator->GetLanguageFromExtension(source.GetSourceExtension().c_str());
  2219. // for now if the lang is defined add the rules and flags for it
  2220. std::string comment = outputExt;
  2221. comment += " file";
  2222. if(lang)
  2223. {
  2224. comment += " from ";
  2225. comment += lang;
  2226. comment += ": ";
  2227. if(comment.size() < 18)
  2228. {
  2229. comment.resize(18, ' ');
  2230. }
  2231. }
  2232. if(lang)
  2233. {
  2234. std::string varString = "CMAKE_";
  2235. varString += lang;
  2236. varString += "_COMPILE_OBJECT";
  2237. rules.push_back(m_Makefile->GetRequiredDefinition(varString.c_str()));
  2238. varString = "CMAKE_";
  2239. varString += lang;
  2240. varString += "_FLAGS";
  2241. flags += m_Makefile->GetSafeDefinition(varString.c_str());
  2242. flags += " ";
  2243. if(buildType.size())
  2244. {
  2245. varString += "_";
  2246. varString += buildType;
  2247. flags += m_Makefile->GetSafeDefinition(varString.c_str());
  2248. flags += " ";
  2249. }
  2250. if(shared)
  2251. {
  2252. varString = "CMAKE_SHARED_LIBRARY_";
  2253. varString += lang;
  2254. varString += "_FLAGS";
  2255. flags += m_Makefile->GetSafeDefinition(varString.c_str());
  2256. flags += " ";
  2257. }
  2258. if(cmSystemTools::IsOn(m_Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  2259. {
  2260. varString = "CMAKE_SHARED_BUILD_";
  2261. varString += lang;
  2262. varString += "_FLAGS";
  2263. flags += m_Makefile->GetSafeDefinition(varString.c_str());
  2264. flags += " ";
  2265. }
  2266. }
  2267. else
  2268. {
  2269. // if the language is not defined and should not be ignored,
  2270. // then produce an error
  2271. cmSystemTools::Error("Unexpected file type ",
  2272. sourceFile.c_str());
  2273. }
  2274. flags += this->GetIncludeFlags(lang);
  2275. // expand multi-command semi-colon separated lists
  2276. // of commands into separate commands
  2277. std::vector<std::string> commands;
  2278. cmSystemTools::ExpandList(rules, commands);
  2279. for(std::vector<std::string>::iterator i = commands.begin();
  2280. i != commands.end(); ++i)
  2281. {
  2282. this->ExpandRuleVariables(*i,
  2283. lang,
  2284. 0, // no objects
  2285. 0, // no target
  2286. 0, // no link libs
  2287. sourceFile.c_str(),
  2288. objectFile.c_str(),
  2289. flags.c_str());
  2290. }
  2291. std::vector<std::string> sourceAndDeps;
  2292. sourceAndDeps.push_back(sourceFile);
  2293. // Check for extra object-file dependencies.
  2294. std::vector<std::string> depends;
  2295. const char* additionalDeps = source.GetProperty("OBJECT_DEPENDS");
  2296. if(additionalDeps)
  2297. {
  2298. cmSystemTools::ExpandListArgument(additionalDeps, depends);
  2299. for(std::vector<std::string>::iterator i = depends.begin();
  2300. i != depends.end(); ++i)
  2301. {
  2302. sourceAndDeps.push_back(this->ConvertToRelativeOutputPath(i->c_str()));
  2303. }
  2304. }
  2305. this->OutputMakeRule(fout,
  2306. comment.c_str(),
  2307. objectFile.c_str(),
  2308. sourceAndDeps,
  2309. commands);
  2310. }
  2311. void cmLocalUnixMakefileGenerator::OutputSourceObjectBuildRules(std::ostream& fout)
  2312. {
  2313. fout << "# Rules to build source files :\n\n";
  2314. std::set<cmStdString> rules;
  2315. // Iterate over every target.
  2316. std::map<cmStdString, cmTarget>& targets = m_Makefile->GetTargets();
  2317. for(std::map<cmStdString, cmTarget>::const_iterator target = targets.begin();
  2318. target != targets.end(); ++target)
  2319. {
  2320. bool shared = ((target->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  2321. (target->second.GetType() == cmTarget::MODULE_LIBRARY));
  2322. std::string exportsDef = "";
  2323. if(shared)
  2324. {
  2325. std::string export_symbol;
  2326. if (const char* custom_export_name = target->second.GetProperty("DEFINE_SYMBOL"))
  2327. {
  2328. export_symbol = custom_export_name;
  2329. }
  2330. else
  2331. {
  2332. std::string in = target->first + "_EXPORTS";
  2333. export_symbol = cmSystemTools::MakeCindentifier(in.c_str());
  2334. }
  2335. exportsDef = "-D"+ export_symbol;
  2336. }
  2337. // Iterate over every source for this target.
  2338. const std::vector<cmSourceFile*>& sources =
  2339. target->second.GetSourceFiles();
  2340. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  2341. source != sources.end(); ++source)
  2342. {
  2343. if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  2344. !(*source)->GetCustomCommand())
  2345. {
  2346. std::string shortName;
  2347. std::string sourceName;
  2348. // If the full path to the source file includes this
  2349. // directory, we want to use the relative path for the
  2350. // filename of the object file. Otherwise, we will use just
  2351. // the filename portion.
  2352. if((cmSystemTools::GetFilenamePath(
  2353. (*source)->GetFullPath()).find(
  2354. m_Makefile->GetCurrentDirectory()) == 0)
  2355. || (cmSystemTools::GetFilenamePath(
  2356. (*source)->GetFullPath()).find(
  2357. m_Makefile->GetCurrentOutputDirectory()) == 0))
  2358. {
  2359. sourceName = (*source)->GetSourceName()+"."+
  2360. (*source)->GetSourceExtension();
  2361. shortName = (*source)->GetSourceName();
  2362. // The path may be relative. See if a directory needs to be
  2363. // created for the output file. This is a ugly, and perhaps
  2364. // should be moved elsewhere.
  2365. std::string relPath =
  2366. cmSystemTools::GetFilenamePath((*source)->GetSourceName());
  2367. if(relPath != "")
  2368. {
  2369. std::string outPath = m_Makefile->GetCurrentOutputDirectory();
  2370. outPath += "/"+relPath;
  2371. cmSystemTools::MakeDirectory(outPath.c_str());
  2372. }
  2373. }
  2374. else
  2375. {
  2376. sourceName = (*source)->GetFullPath();
  2377. shortName = cmSystemTools::GetFilenameName((*source)->GetSourceName());
  2378. }
  2379. std::string shortNameWithExt = shortName +
  2380. (*source)->GetSourceExtension();
  2381. // Only output a rule for each .o once.
  2382. std::string compileFlags = exportsDef;
  2383. compileFlags += " ";
  2384. if(rules.find(shortNameWithExt) == rules.end())
  2385. {
  2386. if((*source)->GetProperty("COMPILE_FLAGS"))
  2387. {
  2388. compileFlags += (*source)->GetProperty("COMPILE_FLAGS");
  2389. compileFlags += " ";
  2390. }
  2391. this->OutputBuildObjectFromSource(fout,
  2392. shortName.c_str(),
  2393. *(*source),
  2394. compileFlags.c_str(),
  2395. shared);
  2396. rules.insert(shortNameWithExt);
  2397. }
  2398. }
  2399. }
  2400. }
  2401. }
  2402. void cmLocalUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
  2403. const char* comment,
  2404. const char* target,
  2405. const char* depends,
  2406. const char* command,
  2407. const char* command2,
  2408. const char* command3,
  2409. const char* command4)
  2410. {
  2411. std::vector<std::string> commands;
  2412. if(command)
  2413. {
  2414. commands.push_back(command);
  2415. }
  2416. if(command2)
  2417. {
  2418. commands.push_back(command2);
  2419. }
  2420. if(command3)
  2421. {
  2422. commands.push_back(command3);
  2423. }
  2424. if(command4)
  2425. {
  2426. commands.push_back(command4);
  2427. }
  2428. this->OutputMakeRule(fout, comment, target, depends, commands);
  2429. }
  2430. void cmLocalUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
  2431. const char* comment,
  2432. const char* target,
  2433. const char* depends,
  2434. const std::vector<std::string>& commands)
  2435. {
  2436. std::vector<std::string> depend;
  2437. if(depends)
  2438. {
  2439. depend.push_back(depends);
  2440. }
  2441. this->OutputMakeRule(fout, comment, target, depend, commands);
  2442. }
  2443. void cmLocalUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
  2444. const char* comment,
  2445. const char* target,
  2446. const std::vector<std::string>& depends,
  2447. const char* command)
  2448. {
  2449. std::vector<std::string> commands;
  2450. if(command)
  2451. {
  2452. commands.push_back(command);
  2453. }
  2454. this->OutputMakeRule(fout, comment, target, depends, commands);
  2455. }
  2456. void cmLocalUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
  2457. const char* comment,
  2458. const char* target,
  2459. const std::vector<std::string>& depends,
  2460. const std::vector<std::string>& commands)
  2461. {
  2462. if(!target)
  2463. {
  2464. cmSystemTools::Error("no target for OutputMakeRule");
  2465. return;
  2466. }
  2467. std::string replace;
  2468. if(comment)
  2469. {
  2470. replace = comment;
  2471. m_Makefile->ExpandVariablesInString(replace);
  2472. fout << "#---------------------------------------------------------\n";
  2473. fout << "# " << replace;
  2474. fout << "\n#\n";
  2475. }
  2476. fout << "\n";
  2477. replace = target;
  2478. m_Makefile->ExpandVariablesInString(replace);
  2479. std::string tgt = this->ConvertToRelativeOutputPath(replace.c_str());
  2480. tgt = this->ConvertToMakeTarget(tgt.c_str());
  2481. const char* space = "";
  2482. if(tgt.size() == 1)
  2483. {
  2484. // Add a space before the ":" to avoid drive letter confusion on
  2485. // Windows.
  2486. space = " ";
  2487. }
  2488. if(depends.empty())
  2489. {
  2490. fout << tgt.c_str() << space << ":\n";
  2491. }
  2492. else
  2493. {
  2494. // Split dependencies into multiple rule lines. This allows for
  2495. // very long dependency lists.
  2496. for(std::vector<std::string>::const_iterator dep = depends.begin();
  2497. dep != depends.end(); ++dep)
  2498. {
  2499. replace = *dep;
  2500. m_Makefile->ExpandVariablesInString(replace);
  2501. replace = this->ConvertToMakeTarget(replace.c_str());
  2502. fout << tgt.c_str() << space << ": " << replace.c_str() << "\n";
  2503. }
  2504. }
  2505. int count = 0;
  2506. for (std::vector<std::string>::const_iterator i = commands.begin();
  2507. i != commands.end(); ++i)
  2508. {
  2509. replace = *i;
  2510. m_Makefile->ExpandVariablesInString(replace);
  2511. if(count == 0 && replace.find_first_not_of(" \t\n\r") != std::string::npos &&
  2512. replace[0] != '-' && replace.find("echo") != 0
  2513. && replace.find("$(MAKE)") != 0)
  2514. {
  2515. std::string echostring = "Building ";
  2516. echostring += comment;
  2517. echostring += " ";
  2518. echostring += target;
  2519. echostring += "...";
  2520. this->OutputEcho(fout,echostring.c_str());
  2521. }
  2522. fout << "\t" << replace.c_str() << "\n";
  2523. count++;
  2524. }
  2525. fout << "\n";
  2526. }
  2527. std::string cmLocalUnixMakefileGenerator::LowerCasePath(const char* path)
  2528. {
  2529. #ifdef _WIN32
  2530. return cmSystemTools::LowerCase(path);
  2531. #else
  2532. return std::string(path);
  2533. #endif
  2534. }
  2535. std::string&
  2536. cmLocalUnixMakefileGenerator::CreateSafeUniqueObjectFileName(const char* sin)
  2537. {
  2538. if ( m_Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES") )
  2539. {
  2540. std::map<cmStdString,cmStdString>::iterator it = m_UniqueObjectNamesMap.find(sin);
  2541. if ( it == m_UniqueObjectNamesMap.end() )
  2542. {
  2543. std::string ssin = sin;
  2544. bool done;
  2545. int cc = 0;
  2546. char rpstr[100];
  2547. sprintf(rpstr, "_p_");
  2548. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  2549. std::string sssin = sin;
  2550. do
  2551. {
  2552. done = true;
  2553. for ( it = m_UniqueObjectNamesMap.begin();
  2554. it != m_UniqueObjectNamesMap.end();
  2555. ++ it )
  2556. {
  2557. if ( it->second == ssin )
  2558. {
  2559. done = false;
  2560. }
  2561. }
  2562. if ( done )
  2563. {
  2564. break;
  2565. }
  2566. sssin = ssin;
  2567. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  2568. sprintf(rpstr, "_p%d_", cc++);
  2569. }
  2570. while ( !done );
  2571. m_UniqueObjectNamesMap[sin] = ssin;
  2572. }
  2573. }
  2574. else
  2575. {
  2576. m_UniqueObjectNamesMap[sin] = sin;
  2577. }
  2578. return m_UniqueObjectNamesMap[sin];
  2579. }
  2580. std::string
  2581. cmLocalUnixMakefileGenerator::CreateMakeVariable(const char* sin, const char* s2in)
  2582. {
  2583. std::string s = sin;
  2584. std::string s2 = s2in;
  2585. std::string unmodified = s;
  2586. unmodified += s2;
  2587. // if there is no restriction on the length of make variables
  2588. // and there are no "." charactors in the string, then return the
  2589. // unmodified combination.
  2590. if(!m_MakefileVariableSize && unmodified.find('.') == s.npos)
  2591. {
  2592. return unmodified;
  2593. }
  2594. // see if the variable has been defined before and return
  2595. // the modified version of the variable
  2596. std::map<cmStdString, cmStdString>::iterator i = m_MakeVariableMap.find(unmodified);
  2597. if(i != m_MakeVariableMap.end())
  2598. {
  2599. return i->second;
  2600. }
  2601. // start with the unmodified variable
  2602. std::string ret = unmodified;
  2603. // if this there is no value for m_MakefileVariableSize then
  2604. // the string must have bad characters in it
  2605. if(!m_MakefileVariableSize)
  2606. {
  2607. cmSystemTools::ReplaceString(ret, ".", "_");
  2608. int ni = 0;
  2609. char buffer[5];
  2610. // make sure the _ version is not already used, if
  2611. // it is used then add number to the end of the variable
  2612. while(m_ShortMakeVariableMap.count(ret) && ni < 1000)
  2613. {
  2614. ++ni;
  2615. sprintf(buffer, "%04d", ni);
  2616. ret = unmodified + buffer;
  2617. }
  2618. m_ShortMakeVariableMap[ret] = "1";
  2619. m_MakeVariableMap[unmodified] = ret;
  2620. return ret;
  2621. }
  2622. // if the string is greater the 32 chars it is an invalid vairable name
  2623. // for borland make
  2624. if(static_cast<int>(ret.size()) > m_MakefileVariableSize)
  2625. {
  2626. int keep = m_MakefileVariableSize - 8;
  2627. int size = keep + 3;
  2628. std::string str1 = s;
  2629. std::string str2 = s2;
  2630. // we must shorten the combined string by 4 charactors
  2631. // keep no more than 24 charactors from the second string
  2632. if(static_cast<int>(str2.size()) > keep)
  2633. {
  2634. str2 = str2.substr(0, keep);
  2635. }
  2636. if(static_cast<int>(str1.size()) + static_cast<int>(str2.size()) > size)
  2637. {
  2638. str1 = str1.substr(0, size - str2.size());
  2639. }
  2640. char buffer[5];
  2641. int ni = 0;
  2642. sprintf(buffer, "%04d", ni);
  2643. ret = str1 + str2 + buffer;
  2644. while(m_ShortMakeVariableMap.count(ret) && ni < 1000)
  2645. {
  2646. ++ni;
  2647. sprintf(buffer, "%04d", ni);
  2648. ret = str1 + str2 + buffer;
  2649. }
  2650. if(ni == 1000)
  2651. {
  2652. cmSystemTools::Error("Borland makefile variable length too long");
  2653. return unmodified;
  2654. }
  2655. // once an unused variable is found
  2656. m_ShortMakeVariableMap[ret] = "1";
  2657. }
  2658. // always make an entry into the unmodified to variable map
  2659. m_MakeVariableMap[unmodified] = ret;
  2660. return ret;
  2661. }
  2662. void cmLocalUnixMakefileGenerator::GetLibraryNames(const char* n,
  2663. const cmTarget& t,
  2664. std::string& name,
  2665. std::string& soName,
  2666. std::string& realName,
  2667. std::string& baseName)
  2668. {
  2669. // Check for library version properties.
  2670. const char* version = t.GetProperty("VERSION");
  2671. const char* soversion = t.GetProperty("SOVERSION");
  2672. if((t.GetType() != cmTarget::SHARED_LIBRARY &&
  2673. t.GetType() != cmTarget::MODULE_LIBRARY) ||
  2674. !m_Makefile->GetDefinition("CMAKE_SHARED_LIBRARY_SONAME_C_FLAG"))
  2675. {
  2676. // Versioning is supported only for shared libraries and modules,
  2677. // and then only when the platform supports an soname flag.
  2678. version = 0;
  2679. soversion = 0;
  2680. }
  2681. if(version && !soversion)
  2682. {
  2683. // The soversion must be set if the library version is set. Use
  2684. // the library version as the soversion.
  2685. soversion = version;
  2686. }
  2687. // The library name.
  2688. name = this->GetFullTargetName(n, t);
  2689. // The library's soname.
  2690. soName = name;
  2691. if(soversion)
  2692. {
  2693. soName += ".";
  2694. soName += soversion;
  2695. }
  2696. // The library's real name on disk.
  2697. realName = name;
  2698. if(version)
  2699. {
  2700. realName += ".";
  2701. realName += version;
  2702. }
  2703. else if(soversion)
  2704. {
  2705. realName += ".";
  2706. realName += soversion;
  2707. }
  2708. // The library name without extension.
  2709. baseName = this->GetBaseTargetName(n, t);
  2710. }
  2711. std::string cmLocalUnixMakefileGenerator::ConvertToMakeTarget(const char* tgt)
  2712. {
  2713. // Make targets should not have a leading './' for a file in the
  2714. // directory containing the makefile.
  2715. std::string ret = tgt;
  2716. if(ret.size() > 2 &&
  2717. (ret[0] == '.') &&
  2718. ( (ret[1] == '/') || ret[1] == '\\'))
  2719. {
  2720. std::string upath = ret;
  2721. cmSystemTools::ConvertToUnixSlashes(upath);
  2722. if(upath.find(2, '/') == upath.npos)
  2723. {
  2724. ret = ret.substr(2, ret.size()-2);
  2725. }
  2726. }
  2727. return ret;
  2728. }