cmLocalUnixMakefileGenerator3.cxx 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107
  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 "cmLocalUnixMakefileGenerator3.h"
  14. #include "cmDepends.h"
  15. #include "cmGeneratedFileStream.h"
  16. #include "cmGlobalUnixMakefileGenerator3.h"
  17. #include "cmMakefile.h"
  18. #include "cmSourceFile.h"
  19. #include "cmake.h"
  20. // Include dependency scanners for supported languages. Only the
  21. // C/C++ scanner is needed for bootstrapping CMake.
  22. #include "cmDependsC.h"
  23. #ifdef CMAKE_BUILD_WITH_CMAKE
  24. # include "cmDependsFortran.h"
  25. # include "cmDependsJava.h"
  26. #endif
  27. #include <memory> // auto_ptr
  28. #include <queue>
  29. // TODO: Add "help" target.
  30. // TODO: Identify remaining relative path violations.
  31. // TODO: Need test for separate executable/library output path.
  32. //----------------------------------------------------------------------------
  33. cmLocalUnixMakefileGenerator3::cmLocalUnixMakefileGenerator3()
  34. {
  35. m_WindowsShell = false;
  36. m_IncludeDirective = "include";
  37. m_MakefileVariableSize = 0;
  38. m_IgnoreLibPrefix = false;
  39. m_PassMakeflags = false;
  40. m_EchoNeedsQuote = true;
  41. }
  42. //----------------------------------------------------------------------------
  43. cmLocalUnixMakefileGenerator3::~cmLocalUnixMakefileGenerator3()
  44. {
  45. }
  46. //----------------------------------------------------------------------------
  47. void cmLocalUnixMakefileGenerator3::Configure()
  48. {
  49. this->ComputeHomeRelativeOutputPath();
  50. this->cmLocalGenerator::Configure();
  51. }
  52. //----------------------------------------------------------------------------
  53. void cmLocalUnixMakefileGenerator3::Generate()
  54. {
  55. // Setup our configuration variables for this directory.
  56. this->ConfigureOutputPaths();
  57. // Generate the rule files for each target.
  58. cmTargets& targets = m_Makefile->GetTargets();
  59. std::string empty;
  60. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  61. {
  62. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  63. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  64. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  65. (t->second.GetType() == cmTarget::MODULE_LIBRARY))
  66. {
  67. t->second.TraceVSDependencies(empty, m_Makefile);
  68. this->WriteTargetRuleFiles(t->second);
  69. }
  70. else if(t->second.GetType() == cmTarget::UTILITY)
  71. {
  72. t->second.TraceVSDependencies(empty, m_Makefile);
  73. this->WriteUtilityRuleFiles(t->second);
  74. }
  75. }
  76. // write the local Makefile
  77. this->WriteLocalMakefile();
  78. // Write the cmake file with information for this directory.
  79. this->WriteDirectoryInformationFile();
  80. // all custom commands used?
  81. const std::vector<cmSourceFile*> &srcs = m_Makefile->GetSourceFiles();
  82. std::vector<cmSourceFile*>::const_iterator sit = srcs.begin();
  83. for (;sit != srcs.end(); ++sit)
  84. {
  85. if ((*sit)->GetCustomCommand() && !(*sit)->GetCustomCommand()->IsUsed())
  86. {
  87. cmOStringStream err;
  88. err << "Warning: Custom command for source file "
  89. << (*sit)->GetSourceName().c_str() << "."
  90. << (*sit)->GetSourceExtension().c_str()
  91. << " was not used.";
  92. cmSystemTools::Message(err.str().c_str(), "Warning");
  93. }
  94. }
  95. }
  96. //----------------------------------------------------------------------------
  97. void cmLocalUnixMakefileGenerator3::ConfigureOutputPaths()
  98. {
  99. // Format the library and executable output paths.
  100. if(const char* libOut = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  101. {
  102. m_LibraryOutputPath = libOut;
  103. this->FormatOutputPath(m_LibraryOutputPath, "LIBRARY");
  104. }
  105. if(const char* exeOut = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  106. {
  107. m_ExecutableOutputPath = exeOut;
  108. this->FormatOutputPath(m_ExecutableOutputPath, "EXECUTABLE");
  109. }
  110. }
  111. //----------------------------------------------------------------------------
  112. void cmLocalUnixMakefileGenerator3::FormatOutputPath(std::string& path,
  113. const char* name)
  114. {
  115. if(!path.empty())
  116. {
  117. // Convert the output path to a full path in case it is
  118. // specified as a relative path. Treat a relative path as
  119. // relative to the current output directory for this makefile.
  120. path =
  121. cmSystemTools::CollapseFullPath(path.c_str(),
  122. m_Makefile->GetStartOutputDirectory());
  123. // Add a trailing slash for easy appending later.
  124. if(path.empty() || path[path.size()-1] != '/')
  125. {
  126. path += "/";
  127. }
  128. // Make sure the output path exists on disk.
  129. if(!cmSystemTools::MakeDirectory(path.c_str()))
  130. {
  131. cmSystemTools::Error("Error failed to create ",
  132. name, "_OUTPUT_PATH directory:", path.c_str());
  133. }
  134. // Add this as a link directory automatically.
  135. m_Makefile->AddLinkDirectory(path.c_str());
  136. }
  137. }
  138. void cmLocalUnixMakefileGenerator3
  139. ::WriteCustomCommands(cmTarget &target,std::ostream& ruleFileStream,
  140. std::vector<std::string>& cleanFiles)
  141. {
  142. std::string tgtDir = m_Makefile->GetStartOutputDirectory();
  143. tgtDir += "/";
  144. tgtDir += this->GetTargetDirectory(target);
  145. // add custom commands to the clean rules?
  146. const char* clean_no_custom = m_Makefile->GetProperty("CLEAN_NO_CUSTOM");
  147. bool clean = cmSystemTools::IsOff(clean_no_custom);
  148. // Generate the rule files for each custom command.
  149. // get the classes from the source lists then add them to the groups
  150. const std::vector<cmSourceFile*> &classes = target.GetSourceFiles();
  151. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  152. i != classes.end(); i++)
  153. {
  154. if(cmCustomCommand* cc = (*i)->GetCustomCommand())
  155. {
  156. cc->Used();
  157. this->GenerateCustomRuleFile(*cc,tgtDir.c_str(),ruleFileStream);
  158. if (clean)
  159. {
  160. cleanFiles.push_back
  161. (this->Convert(cc->GetOutput(),HOME_OUTPUT,SHELL));
  162. }
  163. }
  164. }
  165. }
  166. //----------------------------------------------------------------------------
  167. void cmLocalUnixMakefileGenerator3::WriteDirectoryInformationFile()
  168. {
  169. std::string infoFileName = m_Makefile->GetStartOutputDirectory();
  170. infoFileName += "/CMakeDirectoryInformation.cmake";
  171. // Open the output file.
  172. cmGeneratedFileStream infoFileStream(infoFileName.c_str());
  173. if(!infoFileStream)
  174. {
  175. return;
  176. }
  177. // Write the do not edit header.
  178. this->WriteDisclaimer(infoFileStream);
  179. // Tell the dependency scanner to use unix paths if necessary.
  180. if(cmSystemTools::GetForceUnixPaths())
  181. {
  182. infoFileStream
  183. << "# Force unix paths in dependencies.\n"
  184. << "SET(CMAKE_FORCE_UNIX_PATHS 1)\n"
  185. << "\n";
  186. }
  187. // Store the include search path for this directory.
  188. infoFileStream
  189. << "# The C and CXX include file search paths:\n";
  190. infoFileStream
  191. << "SET(CMAKE_C_INCLUDE_PATH\n";
  192. std::vector<std::string> includeDirs;
  193. this->GetIncludeDirectories(includeDirs);
  194. for(std::vector<std::string>::iterator i = includeDirs.begin();
  195. i != includeDirs.end(); ++i)
  196. {
  197. infoFileStream
  198. << " \"" << this->Convert(i->c_str(),HOME_OUTPUT).c_str() << "\"\n";
  199. }
  200. infoFileStream
  201. << " )\n";
  202. infoFileStream
  203. << "SET(CMAKE_CXX_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH})\n";
  204. // Store the include regular expressions for this directory.
  205. infoFileStream
  206. << "\n"
  207. << "# The C and CXX include file regular expressions for this directory.\n";
  208. infoFileStream
  209. << "SET(CMAKE_C_INCLUDE_REGEX_SCAN ";
  210. this->WriteCMakeArgument(infoFileStream,
  211. m_Makefile->GetIncludeRegularExpression());
  212. infoFileStream
  213. << ")\n";
  214. infoFileStream
  215. << "SET(CMAKE_C_INCLUDE_REGEX_COMPLAIN ";
  216. this->WriteCMakeArgument(infoFileStream,
  217. m_Makefile->GetComplainRegularExpression());
  218. infoFileStream
  219. << ")\n";
  220. infoFileStream
  221. << "SET(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN})\n";
  222. infoFileStream
  223. << "SET(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN})\n";
  224. }
  225. //----------------------------------------------------------------------------
  226. std::string
  227. cmLocalUnixMakefileGenerator3
  228. ::ConvertToFullPath(const std::string& localPath)
  229. {
  230. std::string dir = m_Makefile->GetStartOutputDirectory();
  231. dir += "/";
  232. dir += localPath;
  233. return dir;
  234. }
  235. //----------------------------------------------------------------------------
  236. void cmLocalUnixMakefileGenerator3::WriteDisclaimer(std::ostream& os)
  237. {
  238. os
  239. << "# CMAKE generated file: DO NOT EDIT!\n"
  240. << "# Generated by \"" << m_GlobalGenerator->GetName() << "\""
  241. << " Generator, CMake Version "
  242. << cmMakefile::GetMajorVersion() << "."
  243. << cmMakefile::GetMinorVersion() << "\n\n";
  244. }
  245. void cmLocalUnixMakefileGenerator3::ComputeHomeRelativeOutputPath()
  246. {
  247. // Include the rule file for each object.
  248. m_HomeRelativeOutputPath =
  249. cmSystemTools::RelativePath(m_Makefile->GetHomeOutputDirectory(),
  250. m_Makefile->GetStartOutputDirectory());
  251. if (m_HomeRelativeOutputPath.size())
  252. {
  253. m_HomeRelativeOutputPath += "/";
  254. }
  255. }
  256. const std::string &cmLocalUnixMakefileGenerator3::GetHomeRelativeOutputPath()
  257. {
  258. return m_HomeRelativeOutputPath;
  259. }
  260. //----------------------------------------------------------------------------
  261. void
  262. cmLocalUnixMakefileGenerator3
  263. ::WriteTargetRuleFiles(cmTarget& target)
  264. {
  265. // Create a directory for this target.
  266. std::string dir = this->GetTargetDirectory(target);
  267. cmSystemTools::MakeDirectory(this->ConvertToFullPath(dir).c_str());
  268. // Generate the build-time dependencies file for this target.
  269. std::string depBase = dir;
  270. depBase += "/";
  271. depBase += target.GetName();
  272. // Construct the rule file name.
  273. std::string ruleFileName = dir;
  274. ruleFileName += "/build.make";
  275. // Open the rule file. This should be copy-if-different because the
  276. // rules may depend on this file itself.
  277. std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
  278. cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
  279. ruleFileStream.SetCopyIfDifferent(true);
  280. if(!ruleFileStream)
  281. {
  282. return;
  283. }
  284. this->WriteDisclaimer(ruleFileStream);
  285. this->WriteMakeVariables(ruleFileStream, HOME_OUTPUT);
  286. // Include the dependencies for the target.
  287. std::string depPath = dir;
  288. depPath += "/depend.make";
  289. depPath = this->ConvertToFullPath(depPath.c_str());
  290. depPath = this->Convert(depPath.c_str(),HOME_OUTPUT,MAKEFILE);
  291. ruleFileStream
  292. << "# Include any dependencies generated for this target.\n"
  293. << m_IncludeDirective << " "
  294. << depPath
  295. << "\n\n";
  296. // make sure the depend file exists
  297. if (!cmSystemTools::FileExists(depPath.c_str()))
  298. {
  299. // Write an empty dependency file.
  300. cmGeneratedFileStream depFileStream(depPath.c_str());
  301. depFileStream
  302. << "# Empty dependencies file for " << target.GetName() << ".\n"
  303. << "# This may be replaced when dependencies are built." << std::endl;
  304. }
  305. // First generate the object rule files. Save a list of all object
  306. // files for this target.
  307. std::vector<std::string> objects;
  308. std::vector<std::string> external_objects;
  309. const std::vector<cmSourceFile*>& sources = target.GetSourceFiles();
  310. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  311. source != sources.end(); ++source)
  312. {
  313. if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  314. !(*source)->GetCustomCommand())
  315. {
  316. if(!m_GlobalGenerator->IgnoreFile((*source)->GetSourceExtension().c_str()))
  317. {
  318. // Generate this object file's rule file.
  319. this->WriteObjectRuleFiles(target, *(*source), objects,
  320. ruleFileStream);
  321. }
  322. else if((*source)->GetPropertyAsBool("EXTERNAL_OBJECT"))
  323. {
  324. // This is an external object file. Just add it.
  325. external_objects.push_back((*source)->GetFullPath());
  326. }
  327. }
  328. }
  329. // write the custom commands for this target
  330. std::vector<std::string> cleanFiles;
  331. // Look for files registered for cleaning in this directory.
  332. if(const char* additional_clean_files =
  333. m_Makefile->GetProperty("ADDITIONAL_MAKE_CLEAN_FILES"))
  334. {
  335. cmSystemTools::ExpandListArgument(additional_clean_files, cleanFiles);
  336. }
  337. this->WriteCustomCommands(target,ruleFileStream,cleanFiles);
  338. // Include the rule file for each object.
  339. std::string relPath = this->GetHomeRelativeOutputPath();
  340. std::string objTarget;
  341. // Write the rule for this target type.
  342. switch(target.GetType())
  343. {
  344. case cmTarget::STATIC_LIBRARY:
  345. this->WriteStaticLibraryRule(ruleFileStream, ruleFileName.c_str(),
  346. target, objects, external_objects,
  347. cleanFiles);
  348. break;
  349. case cmTarget::SHARED_LIBRARY:
  350. this->WriteSharedLibraryRule(ruleFileStream, ruleFileName.c_str(),
  351. target, objects, external_objects,
  352. cleanFiles);
  353. break;
  354. case cmTarget::MODULE_LIBRARY:
  355. this->WriteModuleLibraryRule(ruleFileStream, ruleFileName.c_str(),
  356. target, objects, external_objects,
  357. cleanFiles);
  358. break;
  359. case cmTarget::EXECUTABLE:
  360. this->WriteExecutableRule(ruleFileStream, ruleFileName.c_str(),
  361. target, objects, external_objects,
  362. cleanFiles);
  363. break;
  364. default:
  365. break;
  366. }
  367. // Write the requires target.
  368. this->WriteTargetRequiresRule(ruleFileStream, target, objects);
  369. // Write clean target
  370. this->WriteTargetCleanRule(ruleFileStream, target, cleanFiles);
  371. }
  372. //----------------------------------------------------------------------------
  373. void
  374. cmLocalUnixMakefileGenerator3
  375. ::WriteObjectDependRules(std::ostream& ruleFileStream,
  376. std::string &obj,
  377. const char * lang,
  378. cmSourceFile& source,
  379. std::vector<std::string>& depends,
  380. std::string& depMakeFile)
  381. {
  382. // Create the list of dependencies known at cmake time. These are
  383. // shared between the object file and dependency scanning rule.
  384. depends.push_back(source.GetFullPath());
  385. if(const char* objectDeps = source.GetProperty("OBJECT_DEPENDS"))
  386. {
  387. std::vector<std::string> deps;
  388. cmSystemTools::ExpandListArgument(objectDeps, deps);
  389. for(std::vector<std::string>::iterator i = deps.begin();
  390. i != deps.end(); ++i)
  391. {
  392. depends.push_back(i->c_str());
  393. }
  394. }
  395. }
  396. //----------------------------------------------------------------------------
  397. void
  398. cmLocalUnixMakefileGenerator3
  399. ::WriteObjectBuildFile(std::string &obj,
  400. const char *lang,
  401. cmTarget& target,
  402. cmSourceFile& source,
  403. std::vector<std::string>& depends,
  404. std::string &depMakeFile,
  405. std::ostream &ruleFileStream)
  406. {
  407. // Open the rule file for writing. This should be copy-if-different
  408. // because the rules may depend on this file itself.
  409. std::string ruleFileName = this->GetTargetDirectory(target);
  410. ruleFileName += "/build.make";
  411. std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
  412. // generate the depend scanning rule
  413. this->WriteObjectDependRules(ruleFileStream, obj, lang, source,
  414. depends, depMakeFile);
  415. this->AppendRuleDepend(depends, ruleFileNameFull.c_str());
  416. // Write the build rule.
  417. // Build the set of compiler flags.
  418. std::string flags;
  419. // Add the export symbol definition for shared library objects.
  420. bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
  421. (target.GetType() == cmTarget::MODULE_LIBRARY));
  422. if(shared)
  423. {
  424. flags += "-D";
  425. if(const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
  426. {
  427. flags += custom_export_name;
  428. }
  429. else
  430. {
  431. std::string in = target.GetName();
  432. in += "_EXPORTS";
  433. flags += cmSystemTools::MakeCindentifier(in.c_str());
  434. }
  435. }
  436. // Add flags from source file properties.
  437. this->AppendFlags(flags, source.GetProperty("COMPILE_FLAGS"));
  438. // Add language-specific flags.
  439. this->AddLanguageFlags(flags, lang);
  440. // Add shared-library flags if needed.
  441. this->AddSharedFlags(flags, lang, shared);
  442. // Add include directory flags.
  443. this->AppendFlags(flags, this->GetIncludeFlags(lang));
  444. // Get the output paths for source and object files.
  445. std::string sourceFile = source.GetFullPath();
  446. if(m_UseRelativePaths)
  447. {
  448. sourceFile = this->Convert(sourceFile.c_str(),HOME_OUTPUT);
  449. }
  450. sourceFile = this->Convert(sourceFile.c_str(),NONE,SHELL);
  451. std::string objectFile = this->Convert(obj.c_str(),START_OUTPUT,SHELL);
  452. // Construct the build message.
  453. std::string relativeObj = this->GetHomeRelativeOutputPath();
  454. relativeObj += obj;
  455. std::vector<std::string> commands;
  456. std::string buildEcho = "Building ";
  457. buildEcho += lang;
  458. buildEcho += " object ";
  459. buildEcho += relativeObj;
  460. this->AppendEcho(commands, buildEcho.c_str());
  461. // Construct the compile rules.
  462. std::string compileRuleVar = "CMAKE_";
  463. compileRuleVar += lang;
  464. compileRuleVar += "_COMPILE_OBJECT";
  465. std::string compileRule =
  466. m_Makefile->GetRequiredDefinition(compileRuleVar.c_str());
  467. cmSystemTools::ExpandListArgument(compileRule, commands);
  468. // Expand placeholders in the commands.
  469. for(std::vector<std::string>::iterator i = commands.begin();
  470. i != commands.end(); ++i)
  471. {
  472. this->ExpandRuleVariables(*i,
  473. lang,
  474. 0, // no objects
  475. 0, // no target
  476. 0, // no link libs
  477. sourceFile.c_str(),
  478. relativeObj.c_str(),
  479. flags.c_str());
  480. }
  481. // Write the rule.
  482. this->WriteMakeRule(ruleFileStream, 0,
  483. relativeObj.c_str(), depends, commands);
  484. // If the language needs provides-requires mode, create the
  485. // corresponding targets.
  486. std::string objectRequires = relativeObj;
  487. objectRequires += ".requires";
  488. std::string temp = relativeObj;
  489. temp += ".depend";
  490. std::vector<std::string> no_commands;
  491. std::vector<std::string> p_depends;
  492. p_depends.push_back(temp);
  493. // always provide an empty requires target
  494. this->WriteMakeRule(ruleFileStream, 0,
  495. objectRequires.c_str(), p_depends, no_commands);
  496. // write a build rule to recursively build what this obj provides
  497. std::string objectProvides = relativeObj;
  498. objectProvides += ".provides";
  499. temp = relativeObj;
  500. temp += ".provides.build";
  501. std::vector<std::string> r_commands;
  502. std::string tgtMakefileName = this->GetRelativeTargetDirectory(target);
  503. tgtMakefileName += "/build.make";
  504. r_commands.push_back(this->GetRecursiveMakeCall(tgtMakefileName.c_str(),
  505. temp.c_str()));
  506. p_depends.clear();
  507. p_depends.push_back(objectRequires);
  508. this->WriteMakeRule(ruleFileStream, 0,
  509. objectProvides.c_str(), p_depends, r_commands);
  510. // write the provides.build rule dependency on the obj file
  511. p_depends.clear();
  512. p_depends.push_back(relativeObj);
  513. this->WriteMakeRule(ruleFileStream, 0,
  514. temp.c_str(), p_depends, no_commands);
  515. }
  516. //----------------------------------------------------------------------------
  517. void
  518. cmLocalUnixMakefileGenerator3
  519. ::WriteObjectRuleFiles(cmTarget& target, cmSourceFile& source,
  520. std::vector<std::string>& objects,
  521. std::ostream &ruleFileStream)
  522. {
  523. // Identify the language of the source file.
  524. const char* lang = this->GetSourceFileLanguage(source);
  525. if(!lang)
  526. {
  527. // If language is not known, this is an error.
  528. cmSystemTools::Error("Source file \"", source.GetFullPath().c_str(),
  529. "\" has unknown type.");
  530. return;
  531. }
  532. // Get the full path name of the object file.
  533. std::string obj = this->GetObjectFileName(target, source);
  534. // Avoid generating duplicate rules.
  535. if(m_ObjectFiles.find(obj) == m_ObjectFiles.end())
  536. {
  537. m_ObjectFiles.insert(obj);
  538. }
  539. else
  540. {
  541. cmOStringStream err;
  542. err << "Warning: Source file \""
  543. << source.GetSourceName().c_str() << "."
  544. << source.GetSourceExtension().c_str()
  545. << "\" is listed multiple times for target \"" << target.GetName()
  546. << "\".";
  547. cmSystemTools::Message(err.str().c_str(), "Warning");
  548. return;
  549. }
  550. // Create the directory containing the object file. This may be a
  551. // subdirectory under the target's directory.
  552. std::string dir = cmSystemTools::GetFilenamePath(obj.c_str());
  553. cmSystemTools::MakeDirectory(this->ConvertToFullPath(dir).c_str());
  554. // Save this in the target's list of object files.
  555. objects.push_back(obj);
  556. std::string relativeObj = this->GetHomeRelativeOutputPath();
  557. relativeObj += obj;
  558. // we compute some depends when writing the depend.make that we will also
  559. // use in the build.make, same with depMakeFile
  560. std::vector<std::string> depends;
  561. std::string depMakeFile;
  562. // generate the build rule file
  563. this->WriteObjectBuildFile(obj, lang, target, source, depends, depMakeFile,
  564. ruleFileStream);
  565. // The object file should be checked for dependency integrity.
  566. m_CheckDependFiles[target.GetName()][lang].insert(&source);
  567. // add this to the list of objects for this local generator
  568. m_LocalObjectFiles[cmSystemTools::GetFilenameName(obj)].push_back(&target);
  569. }
  570. //----------------------------------------------------------------------------
  571. void
  572. cmLocalUnixMakefileGenerator3
  573. ::GenerateCustomRuleFile(const cmCustomCommand& cc, const char *dir,
  574. std::ostream &ruleFileStream)
  575. {
  576. // Convert the output name to a relative path if possible.
  577. std::string output = this->Convert(cc.GetOutput(),START_OUTPUT);
  578. // Collect the commands.
  579. std::vector<std::string> commands;
  580. std::string preEcho = "Generating ";
  581. preEcho += output;
  582. this->AppendEcho(commands, preEcho.c_str());
  583. this->AppendCustomCommand(commands, cc);
  584. // Collect the dependencies.
  585. std::vector<std::string> depends;
  586. this->AppendCustomDepend(depends, cc);
  587. // Write the rule.
  588. const char* comment = 0;
  589. if(cc.GetComment() && *cc.GetComment())
  590. {
  591. comment = cc.GetComment();
  592. }
  593. this->WriteMakeRule(ruleFileStream, comment,
  594. cc.GetOutput(), depends, commands);
  595. }
  596. //----------------------------------------------------------------------------
  597. void
  598. cmLocalUnixMakefileGenerator3
  599. ::WriteUtilityRuleFiles(cmTarget& target)
  600. {
  601. // Create a directory for this target.
  602. std::string dir = this->GetTargetDirectory(target);
  603. cmSystemTools::MakeDirectory(this->ConvertToFullPath(dir).c_str());
  604. // Construct the name of the rule file.
  605. std::string ruleFileName = dir;
  606. ruleFileName += "/build.make";
  607. // Open the rule file. This should be copy-if-different because the
  608. // rules may depend on this file itself.
  609. std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
  610. cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
  611. ruleFileStream.SetCopyIfDifferent(true);
  612. if(!ruleFileStream)
  613. {
  614. return;
  615. }
  616. this->WriteDisclaimer(ruleFileStream);
  617. this->WriteMakeVariables(ruleFileStream, HOME_OUTPUT);
  618. ruleFileStream
  619. << "# Utility rule file for " << target.GetName() << ".\n\n";
  620. // write the custom commands for this target
  621. std::vector<std::string> cleanFiles;
  622. if(const char* additional_clean_files =
  623. m_Makefile->GetProperty("ADDITIONAL_MAKE_CLEAN_FILES"))
  624. {
  625. cmSystemTools::ExpandListArgument(additional_clean_files, cleanFiles);
  626. }
  627. this->WriteCustomCommands(target,ruleFileStream, cleanFiles);
  628. // Collect the commands and dependencies.
  629. std::vector<std::string> commands;
  630. std::vector<std::string> depends;
  631. // Utility targets store their rules in pre- and post-build commands.
  632. this->AppendCustomDepends(depends, target.GetPreBuildCommands());
  633. this->AppendCustomDepends(depends, target.GetPostBuildCommands());
  634. this->AppendCustomCommands(commands, target.GetPreBuildCommands());
  635. this->AppendCustomCommands(commands, target.GetPostBuildCommands());
  636. // Add dependencies on targets that must be built first.
  637. this->AppendTargetDepends(depends, target);
  638. // Add a dependency on the rule file itself.
  639. std::string relPath = this->GetHomeRelativeOutputPath();
  640. std::string objTarget = relPath;
  641. objTarget += ruleFileName;
  642. this->AppendRuleDepend(depends, objTarget.c_str());
  643. // Write the rule.
  644. this->WriteMakeRule(ruleFileStream, 0,
  645. target.GetName(), depends, commands);
  646. // Write convenience targets.
  647. dir = m_Makefile->GetStartOutputDirectory();
  648. dir += "/";
  649. dir += this->GetTargetDirectory(target);
  650. std::string buildTargetRuleName = dir;
  651. buildTargetRuleName += "/build";
  652. buildTargetRuleName =
  653. this->Convert(buildTargetRuleName.c_str(),HOME_OUTPUT,MAKEFILE);
  654. this->WriteConvenienceRule(ruleFileStream, target.GetName(),
  655. buildTargetRuleName.c_str());
  656. // Write clean target
  657. this->WriteTargetCleanRule(ruleFileStream, target, cleanFiles);
  658. }
  659. //----------------------------------------------------------------------------
  660. bool
  661. cmLocalUnixMakefileGenerator3
  662. ::GenerateDependsMakeFile(const std::string& lang, const char* objFile,
  663. std::string& depMakeFile, std::string& depMarkFile)
  664. {
  665. // Construct a checker for the given language.
  666. std::auto_ptr<cmDepends>
  667. checker(this->GetDependsChecker(lang,false));
  668. if(checker.get())
  669. {
  670. // Check the dependencies. Ths is required because we need at least an
  671. // empty foo.obj.depends.make for make to include, so at cmake time the
  672. // ::Check() method will generate that if it does not exist
  673. // Todo: could just make sure that file exists,
  674. // use different method not check
  675. checker->Check(objFile);
  676. return true;
  677. }
  678. return false;
  679. }
  680. //----------------------------------------------------------------------------
  681. void
  682. cmLocalUnixMakefileGenerator3
  683. ::WriteMakeRule(std::ostream& os,
  684. const char* comment,
  685. const char* target,
  686. const std::vector<std::string>& depends,
  687. const std::vector<std::string>& commands)
  688. {
  689. // Make sure there is a target.
  690. if(!target || !*target)
  691. {
  692. cmSystemTools::Error("No target for WriteMakeRule! called with comment: ",
  693. comment);
  694. return;
  695. }
  696. std::string replace;
  697. // Write the comment describing the rule in the makefile.
  698. if(comment)
  699. {
  700. replace = comment;
  701. std::string::size_type lpos = 0;
  702. std::string::size_type rpos;
  703. while((rpos = replace.find('\n', lpos)) != std::string::npos)
  704. {
  705. os << "# " << replace.substr(lpos, rpos-lpos) << "\n";
  706. lpos = rpos+1;
  707. }
  708. os << "# " << replace.substr(lpos) << "\n";
  709. }
  710. // Construct the left hand side of the rule.
  711. replace = target;
  712. std::string tgt = this->Convert(replace.c_str(),HOME_OUTPUT,MAKEFILE);
  713. tgt = this->ConvertToMakeTarget(tgt.c_str());
  714. const char* space = "";
  715. if(tgt.size() == 1)
  716. {
  717. // Add a space before the ":" to avoid drive letter confusion on
  718. // Windows.
  719. space = " ";
  720. }
  721. // Write the rule.
  722. if(depends.empty())
  723. {
  724. // No dependencies. The commands will always run.
  725. os << tgt.c_str() << space << ":\n";
  726. }
  727. else
  728. {
  729. // Split dependencies into multiple rule lines. This allows for
  730. // very long dependency lists even on older make implementations.
  731. for(std::vector<std::string>::const_iterator dep = depends.begin();
  732. dep != depends.end(); ++dep)
  733. {
  734. replace = *dep;
  735. replace = this->Convert(replace.c_str(),HOME_OUTPUT,MAKEFILE);
  736. replace = this->ConvertToMakeTarget(replace.c_str());
  737. os << tgt.c_str() << space << ": " << replace.c_str() << "\n";
  738. }
  739. }
  740. // Write the list of commands.
  741. for(std::vector<std::string>::const_iterator i = commands.begin();
  742. i != commands.end(); ++i)
  743. {
  744. replace = *i;
  745. os << "\t" << replace.c_str() << "\n";
  746. }
  747. os << "\n";
  748. }
  749. //----------------------------------------------------------------------------
  750. void cmLocalUnixMakefileGenerator3::WriteDivider(std::ostream& os)
  751. {
  752. os
  753. << "#======================================"
  754. << "=======================================\n";
  755. }
  756. //----------------------------------------------------------------------------
  757. void
  758. cmLocalUnixMakefileGenerator3
  759. ::WriteMakeVariables(std::ostream& makefileStream, RelativeRoot root)
  760. {
  761. this->WriteDivider(makefileStream);
  762. makefileStream
  763. << "# Set environment variables for the build.\n"
  764. << "\n";
  765. if(m_WindowsShell)
  766. {
  767. makefileStream
  768. << "!IF \"$(OS)\" == \"Windows_NT\"\n"
  769. << "NULL=\n"
  770. << "!ELSE\n"
  771. << "NULL=nul\n"
  772. << "!ENDIF\n";
  773. }
  774. else
  775. {
  776. makefileStream
  777. << "# The shell in which to execute make rules.\n"
  778. << "SHELL = /bin/sh\n"
  779. << "\n";
  780. }
  781. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  782. {
  783. makefileStream
  784. << "# Produce verbose output by default.\n"
  785. << "VERBOSE = 1\n"
  786. << "\n";
  787. }
  788. std::string cmakecommand =
  789. this->ConvertToOutputForExisting(
  790. m_Makefile->GetRequiredDefinition("CMAKE_COMMAND"));
  791. makefileStream
  792. << "# The CMake executable.\n"
  793. << "CMAKE_COMMAND = "
  794. << this->Convert(cmakecommand.c_str(), root, MAKEFILE).c_str()
  795. << "\n"
  796. << "\n";
  797. makefileStream
  798. << "# The command to remove a file.\n"
  799. << "RM = "
  800. << this->Convert(cmakecommand.c_str(),root,SHELL).c_str()
  801. << " -E remove -f\n"
  802. << "\n";
  803. if(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  804. {
  805. makefileStream
  806. << "# The program to use to edit the cache.\n"
  807. << "CMAKE_EDIT_COMMAND = "
  808. << (this->ConvertToOutputForExisting(
  809. m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))) << "\n"
  810. << "\n";
  811. }
  812. makefileStream
  813. << "# The top-level source directory on which CMake was run.\n"
  814. << "CMAKE_SOURCE_DIR = "
  815. << this->Convert(m_Makefile->GetHomeDirectory(), root, SHELL)
  816. << "\n"
  817. << "\n";
  818. makefileStream
  819. << "# The top-level build directory on which CMake was run.\n"
  820. << "CMAKE_BINARY_DIR = "
  821. << this->Convert(m_Makefile->GetHomeOutputDirectory(), root, SHELL)
  822. << "\n"
  823. << "\n";
  824. }
  825. //----------------------------------------------------------------------------
  826. void
  827. cmLocalUnixMakefileGenerator3
  828. ::WriteSpecialTargetsTop(std::ostream& makefileStream)
  829. {
  830. this->WriteDivider(makefileStream);
  831. makefileStream
  832. << "# Special targets provided by cmake.\n"
  833. << "\n";
  834. // Write the main entry point target. This must be the VERY first
  835. // target so that make with no arguments will run it.
  836. {
  837. // Just depend on the all target to drive the build.
  838. std::vector<std::string> depends;
  839. std::vector<std::string> no_commands;
  840. depends.push_back("all");
  841. // Write the rule.
  842. this->WriteMakeRule(makefileStream,
  843. "Default target executed when no arguments are "
  844. "given to make.",
  845. "default_target",
  846. depends,
  847. no_commands);
  848. }
  849. // Write special "test" target to run ctest.
  850. if(m_Makefile->IsOn("CMAKE_TESTING_ENABLED"))
  851. {
  852. std::string ctest;
  853. if(m_Makefile->GetDefinition("CMake_BINARY_DIR"))
  854. {
  855. // We are building CMake itself. Use the ctest that comes with
  856. // this version of CMake instead of the one used to build it.
  857. ctest = m_ExecutableOutputPath;
  858. ctest += "ctest";
  859. ctest += cmSystemTools::GetExecutableExtension();
  860. ctest = this->Convert(ctest.c_str(),START_OUTPUT,SHELL);
  861. ctest += " --force-new-ctest-process";
  862. }
  863. else
  864. {
  865. // We are building another project. Use the ctest that comes with
  866. // the CMake building it.
  867. ctest = m_Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  868. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  869. ctest += "/";
  870. ctest += "ctest";
  871. ctest += cmSystemTools::GetExecutableExtension();
  872. ctest = this->ConvertToOutputForExisting(ctest.c_str());
  873. }
  874. std::vector<std::string> no_depends;
  875. std::vector<std::string> commands;
  876. this->AppendEcho(commands, "Running tests...");
  877. ctest += " $(ARGS)";
  878. commands.push_back(ctest);
  879. this->WriteMakeRule(makefileStream,
  880. "Special rule to drive testing with ctest.",
  881. "test", no_depends, commands);
  882. }
  883. // Write special "install" target to run cmake_install.cmake script.
  884. {
  885. std::vector<std::string> depends;
  886. std::vector<std::string> commands;
  887. std::string cmd;
  888. if(m_Makefile->GetDefinition("CMake_BINARY_DIR"))
  889. {
  890. // We are building CMake itself. We cannot use the original
  891. // executable to install over itself.
  892. cmd = m_ExecutableOutputPath;
  893. cmd += "cmake";
  894. cmd = this->Convert(cmd.c_str(),START_OUTPUT,SHELL);
  895. }
  896. else
  897. {
  898. cmd = "$(CMAKE_COMMAND)";
  899. }
  900. cmd += " -P cmake_install.cmake";
  901. commands.push_back(cmd);
  902. const char* noall =
  903. m_Makefile->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
  904. if(!noall || cmSystemTools::IsOff(noall))
  905. {
  906. // Drive the build before installing.
  907. depends.push_back("all");
  908. }
  909. this->WriteMakeRule(makefileStream,
  910. "Special rule to run installation script.",
  911. "install", depends, commands);
  912. }
  913. // Write special "rebuild_cache" target to re-run cmake.
  914. {
  915. std::vector<std::string> no_depends;
  916. std::vector<std::string> commands;
  917. this->AppendEcho(commands, "Running CMake to regenerate build system...");
  918. commands.push_back(
  919. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  920. this->WriteMakeRule(makefileStream,
  921. "Special rule to re-run CMake using make.",
  922. "rebuild_cache",
  923. no_depends,
  924. commands);
  925. }
  926. // Use CMAKE_EDIT_COMMAND for the edit_cache rule if it is defined.
  927. // Otherwise default to the interactive command-line interface.
  928. if(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  929. {
  930. std::vector<std::string> no_depends;
  931. std::vector<std::string> commands;
  932. this->AppendEcho(commands, "Running CMake cache editor...");
  933. commands.push_back(
  934. "$(CMAKE_EDIT_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
  935. this->WriteMakeRule(makefileStream,
  936. "Special rule to re-run CMake cache editor using make.",
  937. "edit_cache",
  938. no_depends,
  939. commands);
  940. }
  941. else
  942. {
  943. std::vector<std::string> no_depends;
  944. std::vector<std::string> commands;
  945. this->AppendEcho(commands,
  946. "Running interactive CMake command-line interface...");
  947. commands.push_back(
  948. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -i");
  949. this->WriteMakeRule(makefileStream,
  950. "Special rule to re-run CMake cache editor using make.",
  951. "edit_cache",
  952. no_depends,
  953. commands);
  954. }
  955. }
  956. //----------------------------------------------------------------------------
  957. void
  958. cmLocalUnixMakefileGenerator3
  959. ::WriteSpecialTargetsBottom(std::ostream& makefileStream)
  960. {
  961. this->WriteDivider(makefileStream);
  962. makefileStream
  963. << "# Special targets to cleanup operation of make.\n"
  964. << "\n";
  965. // Write special "cmake_check_build_system" target to run cmake with
  966. // the --check-build-system flag.
  967. {
  968. // Build command to run CMake to check if anything needs regenerating.
  969. std::string cmakefileName = "Makefile.cmake";
  970. std::string runRule =
  971. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
  972. runRule += " --check-build-system ";
  973. runRule += this->Convert(cmakefileName.c_str(),NONE,SHELL);
  974. runRule += " 0";
  975. std::vector<std::string> no_depends;
  976. std::vector<std::string> commands;
  977. commands.push_back(runRule);
  978. this->WriteMakeRule(makefileStream,
  979. "Special rule to run CMake to check the build system "
  980. "integrity.\n"
  981. "No rule that depends on this can have "
  982. "commands that come from listfiles\n"
  983. "because they might be regenerated.",
  984. "cmake_check_build_system",
  985. no_depends,
  986. commands);
  987. }
  988. std::vector<std::string> no_commands;
  989. // Write special target to silence make output. This must be after
  990. // the default target in case VERBOSE is set (which changes the
  991. // name). The setting of CMAKE_VERBOSE_MAKEFILE to ON will cause a
  992. // "VERBOSE=1" to be added as a make variable which will change the
  993. // name of this special target. This gives a make-time choice to
  994. // the user.
  995. std::vector<std::string> no_depends;
  996. this->WriteMakeRule(makefileStream,
  997. "Suppress display of executed commands.",
  998. "$(VERBOSE).SILENT",
  999. no_depends,
  1000. no_commands);
  1001. // Special target to cleanup operation of make tool.
  1002. std::vector<std::string> depends;
  1003. this->WriteMakeRule(makefileStream,
  1004. "Disable implicit rules so canoncical targets will work.",
  1005. ".SUFFIXES",
  1006. depends,
  1007. no_commands);
  1008. // Add a fake suffix to keep HP happy. Must be max 32 chars for SGI make.
  1009. depends.push_back(".hpux_make_needs_suffix_list");
  1010. this->WriteMakeRule(makefileStream, 0,
  1011. ".SUFFIXES", depends, no_commands);
  1012. }
  1013. //----------------------------------------------------------------------------
  1014. void
  1015. cmLocalUnixMakefileGenerator3
  1016. ::WriteConvenienceRule(std::ostream& ruleFileStream,
  1017. const char* realTarget,
  1018. const char* helpTarget)
  1019. {
  1020. // A rule is only needed if the names are different.
  1021. if(strcmp(realTarget, helpTarget) != 0)
  1022. {
  1023. // The helper target depends on the real target.
  1024. std::vector<std::string> depends;
  1025. depends.push_back(realTarget);
  1026. // There are no commands.
  1027. std::vector<std::string> no_commands;
  1028. // Write the rule.
  1029. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  1030. helpTarget, depends, no_commands);
  1031. }
  1032. }
  1033. //----------------------------------------------------------------------------
  1034. void
  1035. cmLocalUnixMakefileGenerator3
  1036. ::WriteTargetRequiresRule(std::ostream& ruleFileStream, cmTarget& target,
  1037. const std::vector<std::string>& objects)
  1038. {
  1039. std::vector<std::string> depends;
  1040. std::vector<std::string> no_commands;
  1041. // Construct the name of the dependency generation target.
  1042. std::string depTarget = this->GetRelativeTargetDirectory(target);
  1043. depTarget += "/requires";
  1044. // This target drives dependency generation for all object files.
  1045. std::string relPath = this->GetHomeRelativeOutputPath();
  1046. std::string objTarget;
  1047. for(std::vector<std::string>::const_iterator obj = objects.begin();
  1048. obj != objects.end(); ++obj)
  1049. {
  1050. objTarget = relPath;
  1051. objTarget += *obj;
  1052. objTarget += ".requires";
  1053. depends.push_back(objTarget);
  1054. }
  1055. // Write the rule.
  1056. this->WriteMakeRule(ruleFileStream, 0,
  1057. depTarget.c_str(), depends, no_commands);
  1058. }
  1059. //----------------------------------------------------------------------------
  1060. void
  1061. cmLocalUnixMakefileGenerator3
  1062. ::WriteExecutableRule(std::ostream& ruleFileStream,
  1063. const char* ruleFileName,
  1064. cmTarget& target,
  1065. const std::vector<std::string>& objects,
  1066. const std::vector<std::string>& external_objects,
  1067. std::vector<std::string>& cleanFiles)
  1068. {
  1069. // Write the dependency generation rule.
  1070. this->WriteTargetDependRule(ruleFileStream, target, objects);
  1071. std::vector<std::string> commands;
  1072. std::string relPath = this->GetHomeRelativeOutputPath();
  1073. std::string objTarget;
  1074. // Build list of dependencies.
  1075. std::vector<std::string> depends;
  1076. for(std::vector<std::string>::const_iterator obj = objects.begin();
  1077. obj != objects.end(); ++obj)
  1078. {
  1079. objTarget = relPath;
  1080. objTarget += *obj;
  1081. depends.push_back(objTarget);
  1082. }
  1083. // Add dependencies on targets that must be built first.
  1084. this->AppendTargetDepends(depends, target);
  1085. // Add a dependency on the rule file itself.
  1086. objTarget = relPath;
  1087. objTarget += ruleFileName;
  1088. this->AppendRuleDepend(depends, objTarget.c_str());
  1089. // Construct the full path to the executable that will be generated.
  1090. std::string targetFullPath = m_ExecutableOutputPath;
  1091. if(targetFullPath.length() == 0)
  1092. {
  1093. targetFullPath = m_Makefile->GetStartOutputDirectory();
  1094. targetFullPath += "/";
  1095. }
  1096. #ifdef __APPLE__
  1097. if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
  1098. {
  1099. // Make bundle directories
  1100. targetFullPath += target.GetName();
  1101. targetFullPath += ".app/Contents/MacOS/";
  1102. }
  1103. #endif
  1104. // do we have a different executable name?
  1105. if (target.GetProperty("OUTPUT_NAME"))
  1106. {
  1107. targetFullPath += target.GetProperty("OUTPUT_NAME");
  1108. }
  1109. else
  1110. {
  1111. targetFullPath += target.GetName();
  1112. }
  1113. targetFullPath += cmSystemTools::GetExecutableExtension();
  1114. // Convert to the output path to use in constructing commands.
  1115. std::string targetOutPath = this->Convert(targetFullPath.c_str(),HOME_OUTPUT,MAKEFILE);
  1116. // Get the language to use for linking this executable.
  1117. const char* linkLanguage =
  1118. target.GetLinkerLanguage(this->GetGlobalGenerator());
  1119. // Make sure we have a link language.
  1120. if(!linkLanguage)
  1121. {
  1122. cmSystemTools::Error("Cannot determine link language for target \"",
  1123. target.GetName(), "\".");
  1124. return;
  1125. }
  1126. // Add the link message.
  1127. std::string buildEcho = "Linking ";
  1128. buildEcho += linkLanguage;
  1129. buildEcho += " executable ";
  1130. buildEcho += targetOutPath;
  1131. this->AppendEcho(commands, buildEcho.c_str());
  1132. // Build a list of compiler flags and linker flags.
  1133. std::string flags;
  1134. std::string linkFlags;
  1135. #if 0
  1136. // Loop over all libraries and see if all are shared
  1137. const cmTarget::LinkLibraries& tlibs = target.GetLinkLibraries();
  1138. int AllShared = 2; // 0 = false, 1 = true, 2 = unknown
  1139. for(cmTarget::LinkLibraries::const_iterator lib = tlibs.begin();
  1140. lib != tlibs.end(); ++lib)
  1141. {
  1142. // look up the target if there is one
  1143. cmTarget *libtgt = m_GlobalGenerator->FindTarget(0,lib->first.c_str());
  1144. if (libtgt)
  1145. {
  1146. if (libtgt->GetType() != cmTarget::SHARED_LIBRARY)
  1147. {
  1148. AllShared = 0;
  1149. }
  1150. else if (AllShared == 2)
  1151. {
  1152. AllShared = 1;
  1153. }
  1154. }
  1155. }
  1156. // if all libs were shared then add the special borland flag for linking an
  1157. // executable to only shared libs
  1158. if(AllShared == 1)
  1159. {
  1160. this->AppendFlags
  1161. (linkFlags,m_Makefile->GetDefinition("CMAKE_SHARED_BUILD_CXX_FLAGS"));
  1162. }
  1163. #endif
  1164. // Add flags to deal with shared libraries. Any library being
  1165. // linked in might be shared, so always use shared flags for an
  1166. // executable.
  1167. this->AddSharedFlags(linkFlags, linkLanguage, true);
  1168. // Add flags to create an executable.
  1169. this->AddConfigVariableFlags(linkFlags, "CMAKE_EXE_LINKER_FLAGS");
  1170. if(target.GetPropertyAsBool("WIN32_EXECUTABLE"))
  1171. {
  1172. this->AppendFlags(linkFlags,
  1173. m_Makefile->GetDefinition("CMAKE_CREATE_WIN32_EXE"));
  1174. }
  1175. else
  1176. {
  1177. this->AppendFlags(linkFlags,
  1178. m_Makefile->GetDefinition("CMAKE_CREATE_CONSOLE_EXE"));
  1179. }
  1180. // Add language-specific flags.
  1181. this->AddLanguageFlags(flags, linkLanguage);
  1182. // Add target-specific linker flags.
  1183. this->AppendFlags(linkFlags, target.GetProperty("LINK_FLAGS"));
  1184. // Add the pre-build and pre-link rules.
  1185. this->AppendCustomCommands(commands, target.GetPreBuildCommands());
  1186. this->AppendCustomCommands(commands, target.GetPreLinkCommands());
  1187. // Construct the main link rule.
  1188. std::string linkRuleVar = "CMAKE_";
  1189. linkRuleVar += linkLanguage;
  1190. linkRuleVar += "_LINK_EXECUTABLE";
  1191. std::string linkRule = m_Makefile->GetRequiredDefinition(linkRuleVar.c_str());
  1192. cmSystemTools::ExpandListArgument(linkRule, commands);
  1193. // Add the post-build rules.
  1194. this->AppendCustomCommands(commands, target.GetPostBuildCommands());
  1195. // Collect up flags to link in needed libraries.
  1196. cmOStringStream linklibs;
  1197. this->OutputLinkLibraries(linklibs, 0, target);
  1198. // Construct object file lists that may be needed to expand the
  1199. // rule.
  1200. std::string variableName;
  1201. std::string variableNameExternal;
  1202. this->WriteObjectsVariable(ruleFileStream, target, objects, external_objects,
  1203. variableName, variableNameExternal);
  1204. std::string buildObjs = "$(";
  1205. buildObjs += variableName;
  1206. buildObjs += ") $(";
  1207. buildObjs += variableNameExternal;
  1208. buildObjs += ")";
  1209. std::string cleanObjs = "$(";
  1210. cleanObjs += variableName;
  1211. cleanObjs += ")";
  1212. // Expand placeholders in the commands.
  1213. for(std::vector<std::string>::iterator i = commands.begin();
  1214. i != commands.end(); ++i)
  1215. {
  1216. this->ExpandRuleVariables(*i,
  1217. linkLanguage,
  1218. buildObjs.c_str(),
  1219. targetOutPath.c_str(),
  1220. linklibs.str().c_str(),
  1221. 0,
  1222. 0,
  1223. flags.c_str(),
  1224. 0,
  1225. 0,
  1226. 0,
  1227. linkFlags.c_str());
  1228. }
  1229. // Write the build rule.
  1230. this->WriteMakeRule(ruleFileStream, 0,
  1231. targetFullPath.c_str(), depends, commands);
  1232. // Write convenience targets.
  1233. std::string dir = m_Makefile->GetStartOutputDirectory();
  1234. dir += "/";
  1235. dir += this->GetTargetDirectory(target);
  1236. std::string buildTargetRuleName = dir;
  1237. buildTargetRuleName += "/build";
  1238. buildTargetRuleName =
  1239. this->Convert(buildTargetRuleName.c_str(),HOME_OUTPUT,MAKEFILE);
  1240. this->WriteConvenienceRule(ruleFileStream, targetFullPath.c_str(),
  1241. buildTargetRuleName.c_str());
  1242. cleanFiles.push_back(cleanObjs);
  1243. cleanFiles.push_back
  1244. (this->Convert(targetFullPath.c_str(),HOME_OUTPUT,MAKEFILE));
  1245. }
  1246. //----------------------------------------------------------------------------
  1247. void
  1248. cmLocalUnixMakefileGenerator3
  1249. ::WriteStaticLibraryRule(std::ostream& ruleFileStream,
  1250. const char* ruleFileName,
  1251. cmTarget& target,
  1252. const std::vector<std::string>& objects,
  1253. const std::vector<std::string>& external_objects,
  1254. std::vector<std::string>& cleanFiles)
  1255. {
  1256. const char* linkLanguage =
  1257. target.GetLinkerLanguage(this->GetGlobalGenerator());
  1258. std::string linkRuleVar = "CMAKE_";
  1259. if (linkLanguage)
  1260. {
  1261. linkRuleVar += linkLanguage;
  1262. }
  1263. linkRuleVar += "_CREATE_STATIC_LIBRARY";
  1264. std::string extraFlags;
  1265. this->AppendFlags(extraFlags, target.GetProperty("STATIC_LIBRARY_FLAGS"));
  1266. this->WriteLibraryRule(ruleFileStream, ruleFileName, target,
  1267. objects, external_objects,
  1268. linkRuleVar.c_str(), extraFlags.c_str(),cleanFiles);
  1269. }
  1270. //----------------------------------------------------------------------------
  1271. void
  1272. cmLocalUnixMakefileGenerator3
  1273. ::WriteSharedLibraryRule(std::ostream& ruleFileStream,
  1274. const char* ruleFileName,
  1275. cmTarget& target,
  1276. const std::vector<std::string>& objects,
  1277. const std::vector<std::string>& external_objects,
  1278. std::vector<std::string>& cleanFiles)
  1279. {
  1280. const char* linkLanguage =
  1281. target.GetLinkerLanguage(this->GetGlobalGenerator());
  1282. std::string linkRuleVar = "CMAKE_";
  1283. if (linkLanguage)
  1284. {
  1285. linkRuleVar += linkLanguage;
  1286. }
  1287. linkRuleVar += "_CREATE_SHARED_LIBRARY";
  1288. std::string extraFlags;
  1289. this->AppendFlags(extraFlags, target.GetProperty("LINK_FLAGS"));
  1290. this->AddConfigVariableFlags(extraFlags, "CMAKE_SHARED_LINKER_FLAGS");
  1291. if(m_Makefile->IsOn("WIN32") && !(m_Makefile->IsOn("CYGWIN") || m_Makefile->IsOn("MINGW")))
  1292. {
  1293. const std::vector<cmSourceFile*>& sources = target.GetSourceFiles();
  1294. for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
  1295. i != sources.end(); ++i)
  1296. {
  1297. if((*i)->GetSourceExtension() == "def")
  1298. {
  1299. extraFlags += " ";
  1300. extraFlags += m_Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  1301. extraFlags +=
  1302. this->Convert((*i)->GetFullPath().c_str(),HOME_OUTPUT,MAKEFILE);
  1303. }
  1304. }
  1305. }
  1306. this->WriteLibraryRule(ruleFileStream, ruleFileName, target,
  1307. objects, external_objects,
  1308. linkRuleVar.c_str(), extraFlags.c_str(), cleanFiles);
  1309. }
  1310. //----------------------------------------------------------------------------
  1311. void
  1312. cmLocalUnixMakefileGenerator3
  1313. ::WriteModuleLibraryRule(std::ostream& ruleFileStream,
  1314. const char* ruleFileName,
  1315. cmTarget& target,
  1316. const std::vector<std::string>& objects,
  1317. const std::vector<std::string>& external_objects,
  1318. std::vector<std::string>& cleanFiles)
  1319. {
  1320. const char* linkLanguage =
  1321. target.GetLinkerLanguage(this->GetGlobalGenerator());
  1322. std::string linkRuleVar = "CMAKE_";
  1323. if (linkLanguage)
  1324. {
  1325. linkRuleVar += linkLanguage;
  1326. }
  1327. linkRuleVar += "_CREATE_SHARED_MODULE";
  1328. std::string extraFlags;
  1329. this->AppendFlags(extraFlags, target.GetProperty("LINK_FLAGS"));
  1330. this->AddConfigVariableFlags(extraFlags, "CMAKE_MODULE_LINKER_FLAGS");
  1331. // TODO: .def files should be supported here also.
  1332. this->WriteLibraryRule(ruleFileStream, ruleFileName, target,
  1333. objects, external_objects,
  1334. linkRuleVar.c_str(), extraFlags.c_str(), cleanFiles);
  1335. }
  1336. //----------------------------------------------------------------------------
  1337. void
  1338. cmLocalUnixMakefileGenerator3
  1339. ::WriteLibraryRule(std::ostream& ruleFileStream,
  1340. const char* ruleFileName,
  1341. cmTarget& target,
  1342. const std::vector<std::string>& objects,
  1343. const std::vector<std::string>& external_objects,
  1344. const char* linkRuleVar,
  1345. const char* extraFlags,
  1346. std::vector<std::string>& cleanFiles)
  1347. {
  1348. // Write the dependency generation rule.
  1349. this->WriteTargetDependRule(ruleFileStream, target, objects);
  1350. // TODO: Merge the methods that call this method to avoid
  1351. // code duplication.
  1352. std::vector<std::string> commands;
  1353. std::string relPath = this->GetHomeRelativeOutputPath();
  1354. std::string objTarget;
  1355. // Build list of dependencies.
  1356. std::vector<std::string> depends;
  1357. for(std::vector<std::string>::const_iterator obj = objects.begin();
  1358. obj != objects.end(); ++obj)
  1359. {
  1360. objTarget = relPath;
  1361. objTarget += *obj;
  1362. depends.push_back(objTarget);
  1363. }
  1364. // Add dependencies on targets that must be built first.
  1365. this->AppendTargetDepends(depends, target);
  1366. // Add a dependency on the rule file itself.
  1367. objTarget = relPath;
  1368. objTarget += ruleFileName;
  1369. this->AppendRuleDepend(depends, objTarget.c_str());
  1370. // from here up is the same for exe or lib
  1371. for(std::vector<std::string>::const_iterator obj = external_objects.begin();
  1372. obj != external_objects.end(); ++obj)
  1373. {
  1374. depends.push_back(*obj);
  1375. }
  1376. // Get the language to use for linking this library.
  1377. const char* linkLanguage =
  1378. target.GetLinkerLanguage(this->GetGlobalGenerator());
  1379. // Make sure we have a link language.
  1380. if(!linkLanguage)
  1381. {
  1382. cmSystemTools::Error("Cannot determine link language for target \"",
  1383. target.GetName(), "\".");
  1384. return;
  1385. }
  1386. // Create set of linking flags.
  1387. std::string linkFlags;
  1388. this->AppendFlags(linkFlags, extraFlags);
  1389. // Construct the name of the library.
  1390. std::string targetName;
  1391. std::string targetNameSO;
  1392. std::string targetNameReal;
  1393. std::string targetNameBase;
  1394. target.GetLibraryNames(m_Makefile,
  1395. targetName, targetNameSO,
  1396. targetNameReal, targetNameBase);
  1397. // Construct the full path version of the names.
  1398. std::string outpath = m_LibraryOutputPath;
  1399. if(outpath.length() == 0)
  1400. {
  1401. outpath = m_Makefile->GetStartOutputDirectory();
  1402. outpath += "/";
  1403. }
  1404. std::string targetFullPath = outpath + targetName;
  1405. std::string targetFullPathSO = outpath + targetNameSO;
  1406. std::string targetFullPathReal = outpath + targetNameReal;
  1407. std::string targetFullPathBase = outpath + targetNameBase;
  1408. // Construct the output path version of the names for use in command
  1409. // arguments.
  1410. std::string targetOutPath =
  1411. this->Convert(targetFullPath.c_str(),HOME_OUTPUT,MAKEFILE);
  1412. std::string targetOutPathSO =
  1413. this->Convert(targetFullPathSO.c_str(),HOME_OUTPUT,MAKEFILE);
  1414. std::string targetOutPathReal =
  1415. this->Convert(targetFullPathReal.c_str(),HOME_OUTPUT,MAKEFILE);
  1416. std::string targetOutPathBase =
  1417. this->Convert(targetFullPathBase.c_str(),HOME_OUTPUT,MAKEFILE);
  1418. // Add the link message.
  1419. std::string buildEcho = "Linking ";
  1420. buildEcho += linkLanguage;
  1421. switch(target.GetType())
  1422. {
  1423. case cmTarget::STATIC_LIBRARY:
  1424. buildEcho += " static library "; break;
  1425. case cmTarget::SHARED_LIBRARY:
  1426. buildEcho += " shared library "; break;
  1427. case cmTarget::MODULE_LIBRARY:
  1428. buildEcho += " shared module "; break;
  1429. default:
  1430. buildEcho += " library "; break;
  1431. }
  1432. buildEcho += targetOutPath.c_str();
  1433. this->AppendEcho(commands, buildEcho.c_str());
  1434. // Construct a list of files associated with this library that may
  1435. // need to be cleaned.
  1436. std::vector<std::string> libCleanFiles;
  1437. {
  1438. std::string cleanStaticName;
  1439. std::string cleanSharedName;
  1440. std::string cleanSharedSOName;
  1441. std::string cleanSharedRealName;
  1442. target.GetLibraryCleanNames(m_Makefile,
  1443. cleanStaticName,
  1444. cleanSharedName,
  1445. cleanSharedSOName,
  1446. cleanSharedRealName);
  1447. std::string cleanFullStaticName = outpath + cleanStaticName;
  1448. std::string cleanFullSharedName = outpath + cleanSharedName;
  1449. std::string cleanFullSharedSOName = outpath + cleanSharedSOName;
  1450. std::string cleanFullSharedRealName = outpath + cleanSharedRealName;
  1451. libCleanFiles.push_back
  1452. (this->Convert(cleanFullStaticName.c_str(),HOME_OUTPUT,MAKEFILE));
  1453. if(cleanSharedRealName != cleanStaticName)
  1454. {
  1455. libCleanFiles.push_back
  1456. (this->Convert(cleanFullSharedRealName.c_str(),HOME_OUTPUT,MAKEFILE));
  1457. }
  1458. if(cleanSharedSOName != cleanStaticName &&
  1459. cleanSharedSOName != cleanSharedRealName)
  1460. {
  1461. libCleanFiles.push_back
  1462. (this->Convert(cleanFullSharedSOName.c_str(),HOME_OUTPUT,MAKEFILE));
  1463. }
  1464. if(cleanSharedName != cleanStaticName &&
  1465. cleanSharedName != cleanSharedSOName &&
  1466. cleanSharedName != cleanSharedRealName)
  1467. {
  1468. libCleanFiles.push_back
  1469. (this->Convert(cleanFullSharedName.c_str(),HOME_OUTPUT,MAKEFILE));
  1470. }
  1471. }
  1472. // Add a command to remove any existing files for this library.
  1473. this->AppendCleanCommand(commands, libCleanFiles);
  1474. // Add the pre-build and pre-link rules.
  1475. this->AppendCustomCommands(commands, target.GetPreBuildCommands());
  1476. this->AppendCustomCommands(commands, target.GetPreLinkCommands());
  1477. // Construct the main link rule.
  1478. std::string linkRule = m_Makefile->GetRequiredDefinition(linkRuleVar);
  1479. cmSystemTools::ExpandListArgument(linkRule, commands);
  1480. // Add a rule to create necessary symlinks for the library.
  1481. if(targetOutPath != targetOutPathReal)
  1482. {
  1483. std::string symlink = "$(CMAKE_COMMAND) -E cmake_symlink_library ";
  1484. symlink += targetOutPathReal;
  1485. symlink += " ";
  1486. symlink += targetOutPathSO;
  1487. symlink += " ";
  1488. symlink += targetOutPath;
  1489. commands.push_back(symlink);
  1490. }
  1491. // Add the post-build rules.
  1492. this->AppendCustomCommands(commands, target.GetPostBuildCommands());
  1493. // Collect up flags to link in needed libraries.
  1494. cmOStringStream linklibs;
  1495. this->OutputLinkLibraries(linklibs, target.GetName(), target);
  1496. // Construct object file lists that may be needed to expand the
  1497. // rule.
  1498. std::string variableName;
  1499. std::string variableNameExternal;
  1500. this->WriteObjectsVariable(ruleFileStream, target, objects, external_objects,
  1501. variableName, variableNameExternal);
  1502. std::string buildObjs = "$(";
  1503. buildObjs += variableName;
  1504. buildObjs += ") $(";
  1505. buildObjs += variableNameExternal;
  1506. buildObjs += ")";
  1507. std::string cleanObjs = "$(";
  1508. cleanObjs += variableName;
  1509. cleanObjs += ")";
  1510. // Expand placeholders in the commands.
  1511. for(std::vector<std::string>::iterator i = commands.begin();
  1512. i != commands.end(); ++i)
  1513. {
  1514. this->ExpandRuleVariables(*i,
  1515. linkLanguage,
  1516. buildObjs.c_str(),
  1517. targetOutPathReal.c_str(),
  1518. linklibs.str().c_str(),
  1519. 0, 0, 0, buildObjs.c_str(),
  1520. targetOutPathBase.c_str(),
  1521. targetNameSO.c_str(),
  1522. linkFlags.c_str());
  1523. }
  1524. // from here down is the same for exe or lib
  1525. // Write the build rule.
  1526. this->WriteMakeRule(ruleFileStream, 0,
  1527. targetFullPath.c_str(), depends, commands);
  1528. // Write convenience targets.
  1529. std::string dir = m_Makefile->GetStartOutputDirectory();
  1530. dir += "/";
  1531. dir += this->GetTargetDirectory(target);
  1532. std::string buildTargetRuleName = dir;
  1533. buildTargetRuleName += "/build";
  1534. buildTargetRuleName =
  1535. this->Convert(buildTargetRuleName.c_str(),HOME_OUTPUT,MAKEFILE);
  1536. this->WriteConvenienceRule(ruleFileStream, targetFullPath.c_str(),
  1537. buildTargetRuleName.c_str());
  1538. // Clean all the possible library names and symlinks and object files.
  1539. cleanFiles.insert(cleanFiles.end(),libCleanFiles.begin(),libCleanFiles.end());
  1540. cleanFiles.push_back(cleanObjs);
  1541. }
  1542. //----------------------------------------------------------------------------
  1543. void
  1544. cmLocalUnixMakefileGenerator3
  1545. ::WriteObjectsVariable(std::ostream& ruleFileStream,
  1546. cmTarget& target,
  1547. const std::vector<std::string>& objects,
  1548. const std::vector<std::string>& external_objects,
  1549. std::string& variableName,
  1550. std::string& variableNameExternal)
  1551. {
  1552. // Write a make variable assignment that lists all objects for the
  1553. // target.
  1554. variableName = this->CreateMakeVariable(target.GetName(), "_OBJECTS");
  1555. ruleFileStream
  1556. << "# Object files for target " << target.GetName() << "\n"
  1557. << variableName.c_str() << " =";
  1558. std::string relPath = this->GetHomeRelativeOutputPath();
  1559. std::string object;
  1560. for(std::vector<std::string>::const_iterator i = objects.begin();
  1561. i != objects.end(); ++i)
  1562. {
  1563. object = relPath;
  1564. object += *i;
  1565. ruleFileStream
  1566. << " \\\n"
  1567. << this->ConvertToQuotedOutputPath(object.c_str());
  1568. }
  1569. ruleFileStream
  1570. << "\n";
  1571. // Write a make variable assignment that lists all external objects
  1572. // for the target.
  1573. variableNameExternal = this->CreateMakeVariable(target.GetName(),
  1574. "_EXTERNAL_OBJECTS");
  1575. ruleFileStream
  1576. << "\n"
  1577. << "# External object files for target " << target.GetName() << "\n"
  1578. << variableNameExternal.c_str() << " =";
  1579. for(std::vector<std::string>::const_iterator i = external_objects.begin();
  1580. i != external_objects.end(); ++i)
  1581. {
  1582. object = this->Convert(i->c_str(),HOME_OUTPUT);
  1583. ruleFileStream
  1584. << " \\\n"
  1585. << this->ConvertToQuotedOutputPath(object.c_str());
  1586. }
  1587. ruleFileStream
  1588. << "\n"
  1589. << "\n";
  1590. }
  1591. //----------------------------------------------------------------------------
  1592. void
  1593. cmLocalUnixMakefileGenerator3
  1594. ::WriteTargetDependRule(std::ostream& ruleFileStream,
  1595. cmTarget& target,
  1596. const std::vector<std::string>& objects)
  1597. {
  1598. // must write the targets depend info file
  1599. std::string dir = this->GetTargetDirectory(target);
  1600. std::string infoFileName = dir;
  1601. infoFileName += "/DependInfo.cmake";
  1602. std::string ruleFileNameFull = this->ConvertToFullPath(infoFileName);
  1603. cmGeneratedFileStream infoFileStream(ruleFileNameFull.c_str());
  1604. infoFileStream.SetCopyIfDifferent(true);
  1605. if(!infoFileStream)
  1606. {
  1607. return;
  1608. }
  1609. cmGlobalUnixMakefileGenerator3 *gg =
  1610. static_cast<cmGlobalUnixMakefileGenerator3 *>(m_GlobalGenerator);
  1611. this->WriteDependLanguageInfo(infoFileStream,target);
  1612. // and now write the rule to use it
  1613. std::vector<std::string> depends;
  1614. std::vector<std::string> commands;
  1615. // Construct the name of the dependency generation target.
  1616. std::string depTarget = this->GetRelativeTargetDirectory(target);
  1617. depTarget += "/depend";
  1618. std::string depMark = depTarget;
  1619. depMark += ".make.mark";
  1620. depends.push_back(depMark);
  1621. this->WriteMakeRule(ruleFileStream, 0,
  1622. depTarget.c_str(), depends, commands);
  1623. depends.clear();
  1624. // Write the dependency generation rule.
  1625. std::string depEcho = "Scanning dependencies of target ";
  1626. depEcho += target.GetName();
  1627. this->AppendEcho(commands, depEcho.c_str());
  1628. // Add a command to call CMake to scan dependencies. CMake will
  1629. // touch the corresponding depends file after scanning dependencies.
  1630. cmOStringStream depCmd;
  1631. // TODO: Account for source file properties and directory-level
  1632. // definitions when scanning for dependencies.
  1633. depCmd << "$(CMAKE_COMMAND) -E cmake_depends "
  1634. << " \""
  1635. << m_GlobalGenerator->GetName() << "\" "
  1636. << this->Convert(m_Makefile->GetHomeOutputDirectory(),FULL,SHELL)
  1637. << " "
  1638. << this->Convert(m_Makefile->GetStartOutputDirectory(),FULL,SHELL)
  1639. << " "
  1640. << this->Convert(ruleFileNameFull.c_str(),FULL,SHELL);
  1641. commands.push_back(depCmd.str());
  1642. // Write the rule.
  1643. this->WriteMakeRule(ruleFileStream, 0,
  1644. depMark.c_str(), depends, commands);
  1645. #if 0
  1646. // This target drives dependency generation for all object files.
  1647. std::string relPath = this->GetHomeRelativeOutputPath();
  1648. std::string objTarget;
  1649. for(std::vector<std::string>::const_iterator obj = objects.begin();
  1650. obj != objects.end(); ++obj)
  1651. {
  1652. objTarget = relPath;
  1653. objTarget += *obj;
  1654. objTarget += ".depend";
  1655. depends.push_back(objTarget);
  1656. }
  1657. #endif
  1658. }
  1659. //----------------------------------------------------------------------------
  1660. void
  1661. cmLocalUnixMakefileGenerator3
  1662. ::WriteTargetCleanRule(std::ostream& ruleFileStream,
  1663. cmTarget& target,
  1664. const std::vector<std::string>& files)
  1665. {
  1666. std::vector<std::string> no_depends;
  1667. std::vector<std::string> commands;
  1668. // Construct the clean target name.
  1669. std::string cleanTarget = this->GetRelativeTargetDirectory(target);
  1670. cleanTarget += "/clean";
  1671. // Construct the clean command.
  1672. this->AppendCleanCommand(commands, files);
  1673. // Write the rule.
  1674. this->WriteMakeRule(ruleFileStream, 0,
  1675. cleanTarget.c_str(), no_depends, commands);
  1676. }
  1677. //----------------------------------------------------------------------------
  1678. void
  1679. cmLocalUnixMakefileGenerator3
  1680. ::WriteCMakeArgument(std::ostream& os, const char* s)
  1681. {
  1682. // Write the given string to the stream with escaping to get it back
  1683. // into CMake through the lexical scanner.
  1684. os << "\"";
  1685. for(const char* c = s; *c; ++c)
  1686. {
  1687. if(*c == '\\')
  1688. {
  1689. os << "\\\\";
  1690. }
  1691. else if(*c == '"')
  1692. {
  1693. os << "\\\"";
  1694. }
  1695. else
  1696. {
  1697. os << *c;
  1698. }
  1699. }
  1700. os << "\"";
  1701. }
  1702. //----------------------------------------------------------------------------
  1703. std::string
  1704. cmLocalUnixMakefileGenerator3::GetTargetDirectory(cmTarget& target)
  1705. {
  1706. std::string dir;
  1707. // Put a prefix on the name if one is given by the CMake code.
  1708. if(const char* prefix = m_Makefile->GetDefinition("CMAKE_TARGET_DIR_PREFIX"))
  1709. {
  1710. dir += prefix;
  1711. }
  1712. dir += target.GetName();
  1713. dir += ".dir";
  1714. return dir;
  1715. }
  1716. //----------------------------------------------------------------------------
  1717. std::string
  1718. cmLocalUnixMakefileGenerator3::GetRelativeTargetDirectory(cmTarget& target)
  1719. {
  1720. std::string dir = m_Makefile->GetStartOutputDirectory();
  1721. dir += "/";
  1722. dir += this->GetTargetDirectory(target);
  1723. dir = cmSystemTools::RelativePath(m_Makefile->GetHomeOutputDirectory(), dir.c_str());
  1724. return this->Convert(dir.c_str(),NONE,MAKEFILE);
  1725. }
  1726. //----------------------------------------------------------------------------
  1727. std::string
  1728. cmLocalUnixMakefileGenerator3
  1729. ::GetSubdirTargetName(const char* pass, const char* subdir)
  1730. {
  1731. // Convert the subdirectory name to a relative path to keep it short.
  1732. std::string reldir = this->Convert(subdir,START_OUTPUT);
  1733. // Convert the subdirectory name to a valid make target name.
  1734. std::string s = pass;
  1735. s += "_";
  1736. s += reldir;
  1737. // Replace "../" with 3 underscores. This allows one .. at the beginning.
  1738. size_t pos = s.find("../");
  1739. if(pos != std::string::npos)
  1740. {
  1741. s.replace(pos, 3, "___");
  1742. }
  1743. // Replace "/" directory separators with a single underscore.
  1744. while((pos = s.find('/')) != std::string::npos)
  1745. {
  1746. s.replace(pos, 1, "_");
  1747. }
  1748. // Replace ":" drive specifier with a single underscore
  1749. while((pos = s.find(':')) != std::string::npos)
  1750. {
  1751. s.replace(pos, 1, "_");
  1752. }
  1753. return s;
  1754. }
  1755. //----------------------------------------------------------------------------
  1756. std::string
  1757. cmLocalUnixMakefileGenerator3
  1758. ::GetObjectFileName(cmTarget& target,
  1759. const cmSourceFile& source)
  1760. {
  1761. // If the full path to the source file includes this directory,
  1762. // we want to use the relative path for the filename of the
  1763. // object file. Otherwise, we will use just the filename
  1764. // portion.
  1765. std::string objectName;
  1766. if((cmSystemTools::GetFilenamePath(
  1767. source.GetFullPath()).find(
  1768. m_Makefile->GetCurrentDirectory()) == 0)
  1769. || (cmSystemTools::GetFilenamePath(
  1770. source.GetFullPath()).find(
  1771. m_Makefile->GetStartOutputDirectory()) == 0))
  1772. {
  1773. objectName = source.GetSourceName();
  1774. }
  1775. else
  1776. {
  1777. objectName = cmSystemTools::GetFilenameName(source.GetSourceName());
  1778. }
  1779. // Append the object file extension.
  1780. objectName +=
  1781. m_GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  1782. source.GetSourceExtension().c_str());
  1783. // Convert to a safe name.
  1784. objectName = this->CreateSafeUniqueObjectFileName(objectName.c_str());
  1785. // Prepend the target directory.
  1786. std::string obj = this->GetTargetDirectory(target);
  1787. obj += "/";
  1788. obj += objectName;
  1789. return obj;
  1790. }
  1791. //----------------------------------------------------------------------------
  1792. const char*
  1793. cmLocalUnixMakefileGenerator3
  1794. ::GetSourceFileLanguage(const cmSourceFile& source)
  1795. {
  1796. // Identify the language of the source file.
  1797. return (m_GlobalGenerator
  1798. ->GetLanguageFromExtension(source.GetSourceExtension().c_str()));
  1799. }
  1800. //----------------------------------------------------------------------------
  1801. std::string
  1802. cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p)
  1803. {
  1804. // Split the path into its components.
  1805. std::vector<std::string> components;
  1806. cmSystemTools::SplitPath(p, components);
  1807. // Return an empty path if there are no components.
  1808. if(components.empty())
  1809. {
  1810. return "\"\"";
  1811. }
  1812. // Choose a slash direction and fix root component.
  1813. const char* slash = "/";
  1814. #if defined(_WIN32) && !defined(__CYGWIN__)
  1815. if(!cmSystemTools::GetForceUnixPaths())
  1816. {
  1817. slash = "\\";
  1818. for(std::string::iterator i = components[0].begin();
  1819. i != components[0].end(); ++i)
  1820. {
  1821. if(*i == '/')
  1822. {
  1823. *i = '\\';
  1824. }
  1825. }
  1826. }
  1827. #endif
  1828. // Begin the quoted result with the root component.
  1829. std::string result = "\"";
  1830. result += components[0];
  1831. // Now add the rest of the components separated by the proper slash
  1832. // direction for this platform.
  1833. bool first = true;
  1834. for(unsigned int i=1; i < components.size(); ++i)
  1835. {
  1836. // Only the last component can be empty to avoid double slashes.
  1837. if(components[i].length() > 0 || (i == (components.size()-1)))
  1838. {
  1839. if(!first)
  1840. {
  1841. result += slash;
  1842. }
  1843. result += components[i];
  1844. first = false;
  1845. }
  1846. }
  1847. // Close the quoted result.
  1848. result += "\"";
  1849. return result;
  1850. }
  1851. //----------------------------------------------------------------------------
  1852. void
  1853. cmLocalUnixMakefileGenerator3
  1854. ::AppendTargetDepends(std::vector<std::string>& depends,
  1855. cmTarget& target)
  1856. {
  1857. if(target.GetType() == cmTarget::STATIC_LIBRARY)
  1858. {
  1859. return;
  1860. }
  1861. // Keep track of dependencies already listed.
  1862. std::set<cmStdString> emitted;
  1863. // A target should not depend on itself.
  1864. emitted.insert(target.GetName());
  1865. // Loop over all library dependencies.
  1866. const cmTarget::LinkLibraries& tlibs = target.GetLinkLibraries();
  1867. for(cmTarget::LinkLibraries::const_iterator lib = tlibs.begin();
  1868. lib != tlibs.end(); ++lib)
  1869. {
  1870. // Don't emit the same library twice for this target.
  1871. if(emitted.insert(lib->first).second)
  1872. {
  1873. // Add this dependency.
  1874. this->AppendAnyDepend(depends, lib->first.c_str());
  1875. }
  1876. }
  1877. }
  1878. //----------------------------------------------------------------------------
  1879. void
  1880. cmLocalUnixMakefileGenerator3
  1881. ::AppendAnyDepend(std::vector<std::string>& depends, const char* name,
  1882. bool assume_unknown_is_file)
  1883. {
  1884. // There are a few cases for the name of the target:
  1885. // - CMake target in this directory: depend on it.
  1886. // - CMake target in another directory: depend and add jump-and-build.
  1887. // - Full path to a file: depend on it.
  1888. // - Other format (like -lm): do nothing.
  1889. // If it is an executable or library target there will be a
  1890. // definition for it.
  1891. std::string dirVar = name;
  1892. dirVar += "_CMAKE_PATH";
  1893. const char* dir = m_Makefile->GetDefinition(dirVar.c_str());
  1894. if(dir && *dir)
  1895. {
  1896. // This is a CMake target somewhere in this project.
  1897. // Get the type of the library. If it does not have a type then
  1898. // it is an executable.
  1899. std::string typeVar = name;
  1900. typeVar += "_LIBRARY_TYPE";
  1901. const char* libType = m_Makefile->GetDefinition(typeVar.c_str());
  1902. // Get the output path for this target type.
  1903. std::string tgtOutputPath;
  1904. if(libType)
  1905. {
  1906. tgtOutputPath = m_LibraryOutputPath;
  1907. }
  1908. else
  1909. {
  1910. tgtOutputPath = m_ExecutableOutputPath;
  1911. }
  1912. // Get the path to the target.
  1913. std::string tgtPath;
  1914. if(tgtOutputPath.size())
  1915. {
  1916. tgtPath = tgtOutputPath;
  1917. }
  1918. else
  1919. {
  1920. tgtPath = dir;
  1921. tgtPath += "/";
  1922. }
  1923. // Add the name of the targets's file. This depends on the type
  1924. // of the target.
  1925. std::string prefix;
  1926. std::string suffix;
  1927. if(!libType)
  1928. {
  1929. suffix = cmSystemTools::GetExecutableExtension();
  1930. }
  1931. else if(strcmp(libType, "SHARED") == 0)
  1932. {
  1933. prefix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_PREFIX");
  1934. suffix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_LIBRARY_SUFFIX");
  1935. }
  1936. else if(strcmp(libType, "MODULE") == 0)
  1937. {
  1938. prefix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_PREFIX");
  1939. suffix = m_Makefile->GetSafeDefinition("CMAKE_SHARED_MODULE_SUFFIX");
  1940. }
  1941. else if(strcmp(libType, "STATIC") == 0)
  1942. {
  1943. prefix = m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_PREFIX");
  1944. suffix = m_Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
  1945. }
  1946. tgtPath += prefix;
  1947. tgtPath += name;
  1948. tgtPath += suffix;
  1949. // Add a dependency on the target.
  1950. depends.push_back(tgtPath.c_str());
  1951. }
  1952. else if(m_Makefile->GetTargets().find(name) !=
  1953. m_Makefile->GetTargets().end())
  1954. {
  1955. // This is a CMake target that is not an executable or library.
  1956. // It must be in this directory, so just depend on the name
  1957. // directly.
  1958. depends.push_back(name);
  1959. }
  1960. else if(cmSystemTools::FileIsFullPath(name))
  1961. {
  1962. // This is a path to a file. Just trust the listfile author that
  1963. // it will be present or there is a rule to build it.
  1964. depends.push_back(cmSystemTools::CollapseFullPath(name));
  1965. }
  1966. else if(assume_unknown_is_file)
  1967. {
  1968. // Just assume this is a file or make target that will be present.
  1969. depends.push_back(name);
  1970. }
  1971. }
  1972. //----------------------------------------------------------------------------
  1973. void
  1974. cmLocalUnixMakefileGenerator3
  1975. ::AppendRuleDepend(std::vector<std::string>& depends,
  1976. const char* ruleFileName)
  1977. {
  1978. // Add a dependency on the rule file itself unless an option to skip
  1979. // it is specifically enabled by the user or project.
  1980. const char* nodep = m_Makefile->GetDefinition("CMAKE_SKIP_RULE_DEPENDENCY");
  1981. if(!nodep || cmSystemTools::IsOff(nodep))
  1982. {
  1983. depends.push_back(ruleFileName);
  1984. }
  1985. }
  1986. //----------------------------------------------------------------------------
  1987. void
  1988. cmLocalUnixMakefileGenerator3
  1989. ::AppendCustomDepends(std::vector<std::string>& depends,
  1990. const std::vector<cmCustomCommand>& ccs)
  1991. {
  1992. for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
  1993. i != ccs.end(); ++i)
  1994. {
  1995. this->AppendCustomDepend(depends, *i);
  1996. }
  1997. }
  1998. //----------------------------------------------------------------------------
  1999. void
  2000. cmLocalUnixMakefileGenerator3
  2001. ::AppendCustomDepend(std::vector<std::string>& depends,
  2002. const cmCustomCommand& cc)
  2003. {
  2004. for(std::vector<std::string>::const_iterator d = cc.GetDepends().begin();
  2005. d != cc.GetDepends().end(); ++d)
  2006. {
  2007. // Add this dependency.
  2008. this->AppendAnyDepend(depends, d->c_str());
  2009. }
  2010. }
  2011. //----------------------------------------------------------------------------
  2012. void
  2013. cmLocalUnixMakefileGenerator3
  2014. ::AppendCustomCommands(std::vector<std::string>& commands,
  2015. const std::vector<cmCustomCommand>& ccs)
  2016. {
  2017. for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
  2018. i != ccs.end(); ++i)
  2019. {
  2020. this->AppendCustomCommand(commands, *i);
  2021. }
  2022. }
  2023. //----------------------------------------------------------------------------
  2024. void
  2025. cmLocalUnixMakefileGenerator3
  2026. ::AppendCustomCommand(std::vector<std::string>& commands,
  2027. const cmCustomCommand& cc)
  2028. {
  2029. // TODO: Convert outputs/dependencies (arguments?) to relative paths.
  2030. std::vector<std::string> commands1;
  2031. // Add each command line to the set of commands.
  2032. for(cmCustomCommandLines::const_iterator cl = cc.GetCommandLines().begin();
  2033. cl != cc.GetCommandLines().end(); ++cl)
  2034. {
  2035. // Build the command line in a single string.
  2036. const cmCustomCommandLine& commandLine = *cl;
  2037. std::string cmd = commandLine[0];
  2038. if (cmd.size())
  2039. {
  2040. cmSystemTools::ReplaceString(cmd, "/./", "/");
  2041. cmd = this->Convert(cmd.c_str(),START_OUTPUT);
  2042. if(cmd.find("/") == cmd.npos &&
  2043. commandLine[0].find("/") != cmd.npos)
  2044. {
  2045. // Add a leading "./" for executables in the current directory.
  2046. cmd = "./" + cmd;
  2047. }
  2048. cmd = this->Convert(cmd.c_str(),NONE,SHELL);
  2049. for(unsigned int j=1; j < commandLine.size(); ++j)
  2050. {
  2051. cmd += " ";
  2052. cmd += cmSystemTools::EscapeSpaces(commandLine[j].c_str());
  2053. }
  2054. commands1.push_back(cmd);
  2055. }
  2056. }
  2057. // stick this group of commands into a cd of the proper path
  2058. // Build the jump-and-build command list.
  2059. if(m_WindowsShell)
  2060. {
  2061. // On Windows we must perform each step separately and then jump
  2062. // back because the shell keeps the working directory between
  2063. // commands.
  2064. std::string cmd = "cd ";
  2065. cmd += this->ConvertToOutputForExisting(m_Makefile->GetStartOutputDirectory());
  2066. commands.push_back(cmd);
  2067. // push back the custom commands
  2068. commands.insert(commands.end(), commands1.begin(), commands1.end());
  2069. // Jump back to the home directory.
  2070. cmd = "cd ";
  2071. cmd += this->ConvertToOutputForExisting(m_Makefile->GetHomeOutputDirectory());
  2072. commands.push_back(cmd);
  2073. }
  2074. else
  2075. {
  2076. // On UNIX we must construct a single shell command to jump and
  2077. // build because make resets the directory between each command.
  2078. std::string cmd = "cd ";
  2079. cmd += this->ConvertToOutputForExisting(m_Makefile->GetStartOutputDirectory());
  2080. // add the commands
  2081. unsigned int i;
  2082. for (i = 0; i < commands1.size(); ++i)
  2083. {
  2084. cmd += " && ";
  2085. cmd += commands1[i];
  2086. }
  2087. // Add the command as a single line.
  2088. commands.push_back(cmd);
  2089. }
  2090. }
  2091. //----------------------------------------------------------------------------
  2092. void
  2093. cmLocalUnixMakefileGenerator3
  2094. ::AppendCleanCommand(std::vector<std::string>& commands,
  2095. const std::vector<std::string>& files)
  2096. {
  2097. if(!files.empty())
  2098. {
  2099. std::string remove = "$(CMAKE_COMMAND) -E remove -f";
  2100. for(std::vector<std::string>::const_iterator f = files.begin();
  2101. f != files.end(); ++f)
  2102. {
  2103. remove += " ";
  2104. remove += this->Convert(f->c_str(),START_OUTPUT,SHELL);
  2105. }
  2106. commands.push_back(remove);
  2107. }
  2108. }
  2109. //----------------------------------------------------------------------------
  2110. void
  2111. cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
  2112. const char* text)
  2113. {
  2114. // Echo one line at a time.
  2115. std::string line;
  2116. for(const char* c = text;; ++c)
  2117. {
  2118. if(*c == '\n' || *c == '\0')
  2119. {
  2120. // Avoid writing a blank last line on end-of-string.
  2121. if(*c != '\0' || !line.empty())
  2122. {
  2123. // Add a command to echo this line.
  2124. std::string cmd = "@echo ";
  2125. if(m_EchoNeedsQuote)
  2126. {
  2127. cmd += "\"";
  2128. }
  2129. cmd += line;
  2130. if(m_EchoNeedsQuote)
  2131. {
  2132. cmd += "\"";
  2133. }
  2134. commands.push_back(cmd);
  2135. }
  2136. // Reset the line to emtpy.
  2137. line = "";
  2138. // Terminate on end-of-string.
  2139. if(*c == '\0')
  2140. {
  2141. return;
  2142. }
  2143. }
  2144. else if(*c != '\r')
  2145. {
  2146. // Append this character to the current line.
  2147. line += *c;
  2148. }
  2149. }
  2150. }
  2151. //============================================================================
  2152. //----------------------------------------------------------------------------
  2153. bool
  2154. cmLocalUnixMakefileGenerator3::SamePath(const char* path1, const char* path2)
  2155. {
  2156. if (strcmp(path1, path2) == 0)
  2157. {
  2158. return true;
  2159. }
  2160. #if defined(_WIN32) || defined(__APPLE__)
  2161. return
  2162. (cmSystemTools::LowerCase(this->ConvertToOutputForExisting(path1)) ==
  2163. cmSystemTools::LowerCase(this->ConvertToOutputForExisting(path2)));
  2164. #else
  2165. return false;
  2166. #endif
  2167. }
  2168. //----------------------------------------------------------------------------
  2169. // take a tgt path and convert it into a make target, it could be full, or relative
  2170. std::string
  2171. cmLocalUnixMakefileGenerator3
  2172. ::ConvertToMakeTarget(const char* tgt)
  2173. {
  2174. // Make targets should not have a leading './' for a file in the
  2175. // directory containing the makefile.
  2176. std::string ret = tgt;
  2177. if(ret.size() > 2 && (ret[0] == '.') &&
  2178. ( (ret[1] == '/') || ret[1] == '\\'))
  2179. {
  2180. std::string upath = ret;
  2181. cmSystemTools::ConvertToUnixSlashes(upath);
  2182. if(upath.find(2, '/') == upath.npos)
  2183. {
  2184. ret = ret.substr(2, ret.size()-2);
  2185. }
  2186. }
  2187. return ret;
  2188. }
  2189. //----------------------------------------------------------------------------
  2190. std::string&
  2191. cmLocalUnixMakefileGenerator3::CreateSafeUniqueObjectFileName(const char* sin)
  2192. {
  2193. if ( m_Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES") )
  2194. {
  2195. std::map<cmStdString,cmStdString>::iterator it = m_UniqueObjectNamesMap.find(sin);
  2196. if ( it == m_UniqueObjectNamesMap.end() )
  2197. {
  2198. std::string ssin = sin;
  2199. bool done;
  2200. int cc = 0;
  2201. char rpstr[100];
  2202. sprintf(rpstr, "_p_");
  2203. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  2204. std::string sssin = sin;
  2205. do
  2206. {
  2207. done = true;
  2208. for ( it = m_UniqueObjectNamesMap.begin();
  2209. it != m_UniqueObjectNamesMap.end();
  2210. ++ it )
  2211. {
  2212. if ( it->second == ssin )
  2213. {
  2214. done = false;
  2215. }
  2216. }
  2217. if ( done )
  2218. {
  2219. break;
  2220. }
  2221. sssin = ssin;
  2222. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  2223. sprintf(rpstr, "_p%d_", cc++);
  2224. }
  2225. while ( !done );
  2226. m_UniqueObjectNamesMap[sin] = ssin;
  2227. }
  2228. }
  2229. else
  2230. {
  2231. m_UniqueObjectNamesMap[sin] = sin;
  2232. }
  2233. return m_UniqueObjectNamesMap[sin];
  2234. }
  2235. //----------------------------------------------------------------------------
  2236. std::string
  2237. cmLocalUnixMakefileGenerator3
  2238. ::CreateMakeVariable(const char* sin, const char* s2in)
  2239. {
  2240. std::string s = sin;
  2241. std::string s2 = s2in;
  2242. std::string unmodified = s;
  2243. unmodified += s2;
  2244. // if there is no restriction on the length of make variables
  2245. // and there are no "." charactors in the string, then return the
  2246. // unmodified combination.
  2247. if(!m_MakefileVariableSize && unmodified.find('.') == s.npos)
  2248. {
  2249. return unmodified;
  2250. }
  2251. // see if the variable has been defined before and return
  2252. // the modified version of the variable
  2253. std::map<cmStdString, cmStdString>::iterator i = m_MakeVariableMap.find(unmodified);
  2254. if(i != m_MakeVariableMap.end())
  2255. {
  2256. return i->second;
  2257. }
  2258. // start with the unmodified variable
  2259. std::string ret = unmodified;
  2260. // if this there is no value for m_MakefileVariableSize then
  2261. // the string must have bad characters in it
  2262. if(!m_MakefileVariableSize)
  2263. {
  2264. cmSystemTools::ReplaceString(ret, ".", "_");
  2265. int ni = 0;
  2266. char buffer[5];
  2267. // make sure the _ version is not already used, if
  2268. // it is used then add number to the end of the variable
  2269. while(m_ShortMakeVariableMap.count(ret) && ni < 1000)
  2270. {
  2271. ++ni;
  2272. sprintf(buffer, "%04d", ni);
  2273. ret = unmodified + buffer;
  2274. }
  2275. m_ShortMakeVariableMap[ret] = "1";
  2276. m_MakeVariableMap[unmodified] = ret;
  2277. return ret;
  2278. }
  2279. // if the string is greater the 32 chars it is an invalid vairable name
  2280. // for borland make
  2281. if(static_cast<int>(ret.size()) > m_MakefileVariableSize)
  2282. {
  2283. int keep = m_MakefileVariableSize - 8;
  2284. int size = keep + 3;
  2285. std::string str1 = s;
  2286. std::string str2 = s2;
  2287. // we must shorten the combined string by 4 charactors
  2288. // keep no more than 24 charactors from the second string
  2289. if(static_cast<int>(str2.size()) > keep)
  2290. {
  2291. str2 = str2.substr(0, keep);
  2292. }
  2293. if(static_cast<int>(str1.size()) + static_cast<int>(str2.size()) > size)
  2294. {
  2295. str1 = str1.substr(0, size - str2.size());
  2296. }
  2297. char buffer[5];
  2298. int ni = 0;
  2299. sprintf(buffer, "%04d", ni);
  2300. ret = str1 + str2 + buffer;
  2301. while(m_ShortMakeVariableMap.count(ret) && ni < 1000)
  2302. {
  2303. ++ni;
  2304. sprintf(buffer, "%04d", ni);
  2305. ret = str1 + str2 + buffer;
  2306. }
  2307. if(ni == 1000)
  2308. {
  2309. cmSystemTools::Error("Borland makefile variable length too long");
  2310. return unmodified;
  2311. }
  2312. // once an unused variable is found
  2313. m_ShortMakeVariableMap[ret] = "1";
  2314. }
  2315. // always make an entry into the unmodified to variable map
  2316. m_MakeVariableMap[unmodified] = ret;
  2317. return ret;
  2318. }
  2319. //============================================================================
  2320. //----------------------------------------------------------------------------
  2321. cmDepends*
  2322. cmLocalUnixMakefileGenerator3::GetDependsChecker(const std::string& lang,
  2323. bool verbose)
  2324. {
  2325. cmDepends *ret = 0;
  2326. if(lang == "C" || lang == "CXX" || lang == "RC")
  2327. {
  2328. ret = new cmDependsC();
  2329. }
  2330. #ifdef CMAKE_BUILD_WITH_CMAKE
  2331. else if(lang == "Fortran")
  2332. {
  2333. ret = new cmDependsFortran();
  2334. }
  2335. else if(lang == "Java")
  2336. {
  2337. ret = new cmDependsJava();
  2338. }
  2339. #endif
  2340. if (ret)
  2341. {
  2342. ret->SetVerbose(verbose);
  2343. }
  2344. return ret;
  2345. }
  2346. //----------------------------------------------------------------------------
  2347. bool
  2348. cmLocalUnixMakefileGenerator3
  2349. ::ScanDependencies(std::vector<std::string> const& args)
  2350. {
  2351. // Format of arguments is:
  2352. // $(CMAKE_COMMAND), cmake_depends, GeneratorName, home_output_dir, start_output_dir, info file
  2353. // The caller has ensured that all required arguments exist.
  2354. // The info file for this target
  2355. std::string const& infoFile = args[5];
  2356. // Read the directory information file.
  2357. cmake cm;
  2358. cmGlobalGenerator gg;
  2359. gg.SetCMakeInstance(&cm);
  2360. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  2361. lg->SetGlobalGenerator(&gg);
  2362. cmMakefile* mf = lg->GetMakefile();
  2363. mf->SetHomeOutputDirectory(args[3].c_str());
  2364. mf->SetStartOutputDirectory(args[4].c_str());
  2365. lg->SetupPathConversions();
  2366. bool haveDirectoryInfo = false;
  2367. std::string dirInfoFile = args[4];
  2368. dirInfoFile += "/CMakeDirectoryInformation.cmake";
  2369. if(mf->ReadListFile(0, dirInfoFile.c_str()) &&
  2370. !cmSystemTools::GetErrorOccuredFlag())
  2371. {
  2372. haveDirectoryInfo = true;
  2373. }
  2374. // read in the target info file
  2375. if(!mf->ReadListFile(0, infoFile.c_str()) ||
  2376. cmSystemTools::GetErrorOccuredFlag())
  2377. {
  2378. cmSystemTools::Error("Target DependInfo.cmake file not found");
  2379. }
  2380. // Test whether we need to force Unix paths.
  2381. if(haveDirectoryInfo)
  2382. {
  2383. if(const char* force = mf->GetDefinition("CMAKE_FORCE_UNIX_PATHS"))
  2384. {
  2385. if(!cmSystemTools::IsOff(force))
  2386. {
  2387. cmSystemTools::SetForceUnixPaths(true);
  2388. }
  2389. }
  2390. }
  2391. else
  2392. {
  2393. cmSystemTools::Error("Directory Information file not found");
  2394. }
  2395. // create the file stream for the depends file
  2396. std::string dir = cmSystemTools::GetFilenamePath(infoFile);
  2397. dir += "/depend.make";
  2398. // Open the rule file. This should be copy-if-different because the
  2399. // rules may depend on this file itself.
  2400. std::string ruleFileNameFull = dir;
  2401. cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
  2402. ruleFileStream.SetCopyIfDifferent(true);
  2403. if(!ruleFileStream)
  2404. {
  2405. return false;
  2406. }
  2407. this->WriteDisclaimer(ruleFileStream);
  2408. // for each language we need to scan, scan it
  2409. const char *langStr = mf->GetSafeDefinition("CMAKE_DEPENDS_LANGUAGES");
  2410. std::vector<std::string> langs;
  2411. cmSystemTools::ExpandListArgument(langStr, langs);
  2412. for (std::vector<std::string>::iterator li =
  2413. langs.begin(); li != langs.end(); ++li)
  2414. {
  2415. // construct the checker
  2416. std::string lang = li->c_str();
  2417. // Get the set of include directories.
  2418. std::vector<std::string> includes;
  2419. if(haveDirectoryInfo)
  2420. {
  2421. std::string includePathVar = "CMAKE_";
  2422. includePathVar += lang;
  2423. includePathVar += "_INCLUDE_PATH";
  2424. if(const char* includePath = mf->GetDefinition(includePathVar.c_str()))
  2425. {
  2426. cmSystemTools::ExpandListArgument(includePath, includes);
  2427. }
  2428. }
  2429. // Get the include file regular expression.
  2430. std::string includeRegexScan = "^.*$";
  2431. std::string includeRegexComplain = "^$";
  2432. if(haveDirectoryInfo)
  2433. {
  2434. std::string scanRegexVar = "CMAKE_";
  2435. scanRegexVar += lang;
  2436. scanRegexVar += "_INCLUDE_REGEX_SCAN";
  2437. if(const char* scanRegex = mf->GetDefinition(scanRegexVar.c_str()))
  2438. {
  2439. includeRegexScan = scanRegex;
  2440. }
  2441. std::string complainRegexVar = "CMAKE_";
  2442. complainRegexVar += lang;
  2443. complainRegexVar += "_INCLUDE_REGEX_COMPLAIN";
  2444. if(const char* complainRegex = mf->GetDefinition(complainRegexVar.c_str()))
  2445. {
  2446. includeRegexComplain = complainRegex;
  2447. }
  2448. }
  2449. // Create the scanner for this language
  2450. cmDepends *scanner = 0;
  2451. if(lang == "C" || lang == "CXX" || lang == "RC")
  2452. {
  2453. // TODO: Handle RC (resource files) dependencies correctly.
  2454. scanner = new cmDependsC(includes,
  2455. includeRegexScan.c_str(),
  2456. includeRegexComplain.c_str());
  2457. }
  2458. #ifdef CMAKE_BUILD_WITH_CMAKE
  2459. else if(lang == "Fortran")
  2460. {
  2461. scanner = new cmDependsFortran(includes);
  2462. }
  2463. else if(lang == "Java")
  2464. {
  2465. scanner = new cmDependsJava();
  2466. }
  2467. #endif
  2468. // for each file we need to scan
  2469. std::string srcLang = "CMAKE_DEPENDS_CHECK_";
  2470. srcLang += lang;
  2471. const char *srcStr = mf->GetSafeDefinition(srcLang.c_str());
  2472. std::vector<std::string> srcs;
  2473. cmSystemTools::ExpandListArgument(srcStr, srcs);
  2474. for (std::vector<std::string>::iterator si =
  2475. srcs.begin(); si != srcs.end(); ++si)
  2476. {
  2477. std::string &src = *si;
  2478. ++si;
  2479. // make sure the object file is relative to home output
  2480. std::string obj = *si;
  2481. obj = lg->Convert(obj.c_str(),HOME_OUTPUT,MAKEFILE);
  2482. scanner->Write(src.c_str(),obj.c_str(),ruleFileStream);
  2483. }
  2484. // free the scanner for this language
  2485. if (scanner)
  2486. {
  2487. delete scanner;
  2488. }
  2489. }
  2490. // dependencies were generated, so touch the mark file
  2491. dir += ".mark";
  2492. std::ofstream fmark(dir.c_str());
  2493. fmark << "Dependencies updated>" << std::endl;
  2494. return true;
  2495. }
  2496. //----------------------------------------------------------------------------
  2497. void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
  2498. {
  2499. // only write the local Makefile if we are not at the top
  2500. if (!m_Parent)
  2501. {
  2502. return;
  2503. }
  2504. // generate the includes
  2505. std::string ruleFileName = "Makefile";
  2506. // Open the rule file. This should be copy-if-different because the
  2507. // rules may depend on this file itself.
  2508. std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
  2509. cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
  2510. ruleFileStream.SetCopyIfDifferent(true);
  2511. if(!ruleFileStream)
  2512. {
  2513. return;
  2514. }
  2515. this->WriteDisclaimer(ruleFileStream);
  2516. this->WriteMakeVariables(ruleFileStream, START_OUTPUT);
  2517. this->WriteSpecialTargetsTop(ruleFileStream);
  2518. std::vector<std::string> depends;
  2519. std::vector<std::string> commands;
  2520. // Write the all rule.
  2521. std::string dir = m_Makefile->GetStartOutputDirectory();
  2522. dir += "/directorystart";
  2523. dir = this->Convert(dir.c_str(),HOME_OUTPUT,MAKEFILE);
  2524. this->CreateJumpCommand(commands,"Makefile2",dir);
  2525. this->WriteMakeRule(ruleFileStream, "The main all target", "all", depends, commands);
  2526. // Write the clean rule.
  2527. dir = m_Makefile->GetStartOutputDirectory();
  2528. dir += "/clean";
  2529. dir = this->Convert(dir.c_str(),HOME_OUTPUT,MAKEFILE);
  2530. commands.clear();
  2531. this->CreateJumpCommand(commands,"Makefile2",dir);
  2532. this->WriteMakeRule(ruleFileStream, "The main clean target", "clean", depends, commands);
  2533. // write our targets, and while doing it collect up the object
  2534. // file rules
  2535. this->WriteLocalMakefileTargets(ruleFileStream);
  2536. // now write out the object rules
  2537. // for each object file name
  2538. for (std::map<cmStdString,std::vector<cmTarget *> >::iterator lo =
  2539. m_LocalObjectFiles.begin();
  2540. lo != m_LocalObjectFiles.end(); ++lo)
  2541. {
  2542. commands.clear();
  2543. // for each target using the object file
  2544. for (std::vector<cmTarget *>::iterator to =
  2545. lo->second.begin(); to != lo->second.end(); ++to)
  2546. {
  2547. std::string tgtMakefileName = this->GetRelativeTargetDirectory(**to);
  2548. std::string targetName = tgtMakefileName;
  2549. tgtMakefileName += "/build.make";
  2550. targetName += "/";
  2551. targetName += lo->first.c_str();
  2552. this->CreateJumpCommand(commands,tgtMakefileName.c_str(),targetName);
  2553. }
  2554. this->WriteMakeRule(ruleFileStream,
  2555. "target for object file",
  2556. lo->first.c_str(), depends, commands);
  2557. }
  2558. this->WriteHelpRule(ruleFileStream);
  2559. }
  2560. void cmLocalUnixMakefileGenerator3
  2561. ::WriteLocalMakefileTargets(std::ostream& ruleFileStream)
  2562. {
  2563. std::vector<std::string> depends;
  2564. std::vector<std::string> commands;
  2565. // for each target we just provide a rule to cd up to the top and do a make
  2566. // on the target
  2567. cmTargets& targets = m_Makefile->GetTargets();
  2568. std::string localName;
  2569. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  2570. {
  2571. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  2572. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  2573. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  2574. (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
  2575. (t->second.GetType() == cmTarget::UTILITY))
  2576. {
  2577. // Add a rule to build the target by name.
  2578. localName = this->GetRelativeTargetDirectory(t->second);
  2579. localName += "/rule";
  2580. commands.clear();
  2581. depends.clear();
  2582. this->CreateJumpCommand(commands,"Makefile2",localName);
  2583. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  2584. localName.c_str(), depends, commands);
  2585. // Add a target with the canonical name (no prefix, suffix or path).
  2586. if(localName != t->second.GetName())
  2587. {
  2588. commands.clear();
  2589. depends.push_back(localName);
  2590. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  2591. t->second.GetName(), depends, commands);
  2592. }
  2593. }
  2594. }
  2595. }
  2596. void cmLocalUnixMakefileGenerator3
  2597. ::CreateJumpCommand(std::vector<std::string>& commands,
  2598. const char *MakefileName,
  2599. std::string& localName)
  2600. {
  2601. if(m_WindowsShell)
  2602. {
  2603. // On Windows we must perform each step separately and then change
  2604. // back because the shell keeps the working directory between
  2605. // commands.
  2606. std::string cmd = "cd ";
  2607. cmd += this->ConvertToOutputForExisting
  2608. (m_Makefile->GetHomeOutputDirectory());
  2609. commands.push_back(cmd);
  2610. // Build the target for this pass.
  2611. commands.push_back(this->GetRecursiveMakeCall
  2612. (MakefileName,localName.c_str()));
  2613. // Change back to the starting directory. Any trailing slash must be
  2614. // removed to avoid problems with Borland Make.
  2615. std::string back =
  2616. cmSystemTools::RelativePath(m_Makefile->GetHomeOutputDirectory(),
  2617. m_Makefile->GetStartOutputDirectory());
  2618. if(back.size() && back[back.size()-1] == '/')
  2619. {
  2620. back = back.substr(0, back.size()-1);
  2621. }
  2622. cmd = "cd ";
  2623. cmd += this->ConvertToOutputForExisting(back.c_str());
  2624. commands.push_back(cmd);
  2625. }
  2626. else
  2627. {
  2628. // On UNIX we must construct a single shell command to change
  2629. // directory and build because make resets the directory between
  2630. // each command.
  2631. std::string cmd = "cd ";
  2632. cmd += this->ConvertToOutputForExisting(m_Makefile->GetHomeOutputDirectory());
  2633. // Build the target for this pass.
  2634. cmd += " && ";
  2635. cmd += this->GetRecursiveMakeCall(MakefileName,localName.c_str());
  2636. // Add the command as a single line.
  2637. commands.push_back(cmd);
  2638. }
  2639. }
  2640. //----------------------------------------------------------------------------
  2641. void cmLocalUnixMakefileGenerator3::CheckDependencies(cmMakefile* mf,
  2642. bool verbose,
  2643. bool clear)
  2644. {
  2645. // Get the list of target files to check
  2646. const char* infoDef = mf->GetDefinition("CMAKE_DEPEND_INFO_FILES");
  2647. if(!infoDef)
  2648. {
  2649. return;
  2650. }
  2651. std::vector<std::string> files;
  2652. cmSystemTools::ExpandListArgument(infoDef, files);
  2653. // For each info file run the check
  2654. cmDependsC checker;
  2655. checker.SetVerbose(verbose);
  2656. for(std::vector<std::string>::iterator l = files.begin();
  2657. l != files.end(); ++l)
  2658. {
  2659. // either clear or check the files
  2660. std::string dependFile = cmSystemTools::GetFilenamePath(l->c_str());
  2661. dependFile += "/depend.make";
  2662. if (clear)
  2663. {
  2664. checker.Clear(dependFile.c_str());
  2665. }
  2666. else
  2667. {
  2668. checker.Check(dependFile.c_str());
  2669. }
  2670. }
  2671. }
  2672. //----------------------------------------------------------------------------
  2673. std::string
  2674. cmLocalUnixMakefileGenerator3
  2675. ::GetRecursiveMakeCall(const char *Makefile, const char* tgt)
  2676. {
  2677. // Call make on the given file.
  2678. std::string cmd;
  2679. cmd += "$(MAKE) -f ";
  2680. cmd += Makefile;
  2681. cmd += " ";
  2682. // Passg down verbosity level.
  2683. if(this->GetMakeSilentFlag().size())
  2684. {
  2685. cmd += this->GetMakeSilentFlag();
  2686. cmd += " ";
  2687. }
  2688. // Most unix makes will pass the command line flags to make down to
  2689. // sub-invoked makes via an environment variable. However, some
  2690. // makes do not support that, so you have to pass the flags
  2691. // explicitly.
  2692. if(this->GetPassMakeflags())
  2693. {
  2694. cmd += "-$(MAKEFLAGS) ";
  2695. }
  2696. // Add the target.
  2697. if (tgt && tgt[0] != '\0')
  2698. {
  2699. std::string tgt2 = this->Convert(tgt,HOME_OUTPUT,MAKEFILE);
  2700. tgt2 = this->ConvertToMakeTarget(tgt2.c_str());
  2701. cmd += tgt2;
  2702. }
  2703. return cmd;
  2704. }
  2705. //----------------------------------------------------------------------------
  2706. void
  2707. cmLocalUnixMakefileGenerator3::WriteHelpRule(std::ostream& ruleFileStream)
  2708. {
  2709. // add the help target
  2710. std::string path;
  2711. std::vector<std::string> no_depends;
  2712. std::vector<std::string> commands;
  2713. this->AppendEcho(commands,
  2714. "The following are some of the valid targets for this Makefile:");
  2715. this->AppendEcho(commands,"... all (the default if no target is provided)");
  2716. this->AppendEcho(commands,"... clean");
  2717. this->AppendEcho(commands,"... install");
  2718. this->AppendEcho(commands,"... rebuild_cache");
  2719. // Keep track of targets already listed.
  2720. std::set<cmStdString> emittedTargets;
  2721. // for each target Generate the rule files for each target.
  2722. cmTargets& targets = this->GetMakefile()->GetTargets();
  2723. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  2724. {
  2725. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  2726. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  2727. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  2728. (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
  2729. (t->second.GetType() == cmTarget::UTILITY))
  2730. {
  2731. if(emittedTargets.insert(t->second.GetName()).second)
  2732. {
  2733. path = "... ";
  2734. path += t->second.GetName();
  2735. this->AppendEcho(commands,path.c_str());
  2736. }
  2737. }
  2738. }
  2739. this->WriteMakeRule(ruleFileStream, "Help Target",
  2740. "help:",
  2741. no_depends, commands);
  2742. ruleFileStream << "\n\n";
  2743. }
  2744. void cmLocalUnixMakefileGenerator3
  2745. ::WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &target)
  2746. {
  2747. // now write all the language stuff
  2748. // Set the set of files to check for dependency integrity.
  2749. std::set<cmStdString> checkSetLangs;
  2750. std::map<cmStdString,cmLocalUnixMakefileGenerator3::IntegrityCheckSet>&
  2751. checkSet = this->GetIntegrityCheckSet()[target.GetName()];
  2752. for(std::map<cmStdString,
  2753. cmLocalUnixMakefileGenerator3::IntegrityCheckSet>::const_iterator
  2754. l = checkSet.begin(); l != checkSet.end(); ++l)
  2755. {
  2756. checkSetLangs.insert(l->first);
  2757. }
  2758. // list the languages
  2759. cmakefileStream
  2760. << "# The set of files whose dependency integrity should be checked:\n";
  2761. cmakefileStream
  2762. << "SET(CMAKE_DEPENDS_LANGUAGES\n";
  2763. for(std::set<cmStdString>::iterator
  2764. l = checkSetLangs.begin(); l != checkSetLangs.end(); ++l)
  2765. {
  2766. cmakefileStream << " \"" << l->c_str() << "\"\n";
  2767. }
  2768. cmakefileStream << " )\n";
  2769. // now list the files for each language
  2770. for(std::set<cmStdString>::iterator
  2771. l = checkSetLangs.begin(); l != checkSetLangs.end(); ++l)
  2772. {
  2773. cmakefileStream
  2774. << "SET(CMAKE_DEPENDS_CHECK_" << l->c_str() << "\n";
  2775. // get the check set for this local gen and language
  2776. cmLocalUnixMakefileGenerator3::IntegrityCheckSet iCheckSet =
  2777. checkSet[*l];
  2778. // for each file
  2779. for(cmLocalUnixMakefileGenerator3::IntegrityCheckSet::const_iterator
  2780. csIter = iCheckSet.begin();
  2781. csIter != iCheckSet.end(); ++csIter)
  2782. {
  2783. cmakefileStream << " \"" << (*csIter)->GetFullPath() << "\"\n";
  2784. // Get the full path name of the object file.
  2785. std::string obj = this->GetObjectFileName(target, **csIter);
  2786. cmakefileStream << " \"" <<
  2787. this->Convert(obj.c_str(),
  2788. cmLocalGenerator::FULL).c_str() << "\"\n";
  2789. }
  2790. cmakefileStream << " )\n";
  2791. }
  2792. }