cmLocalUnixMakefileGenerator.cxx 96 KB

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