cmLocalUnixMakefileGenerator.cxx 112 KB

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