1
0

cmLocalUnixMakefileGenerator.cxx 112 KB

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