cmLocalUnixMakefileGenerator.cxx 112 KB

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