cmGlobalGenerator.cxx 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #if defined(_WIN32) && !defined(__CYGWIN__)
  11. #include "windows.h" // this must be first to define GetCurrentDirectory
  12. #endif
  13. #include "cmGlobalGenerator.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmExternalMakefileProjectGenerator.h"
  16. #include "cmake.h"
  17. #include "cmMakefile.h"
  18. #include "cmQtAutoGenerators.h"
  19. #include "cmSourceFile.h"
  20. #include "cmVersion.h"
  21. #include "cmTargetExport.h"
  22. #include "cmComputeTargetDepends.h"
  23. #include "cmGeneratedFileStream.h"
  24. #include "cmGeneratorTarget.h"
  25. #include "cmGeneratorExpression.h"
  26. #include "cmGeneratorExpressionEvaluationFile.h"
  27. #include "cmExportBuildFileGenerator.h"
  28. #include <cmsys/Directory.hxx>
  29. #include <cmsys/FStream.hxx>
  30. #if defined(CMAKE_BUILD_WITH_CMAKE)
  31. # include <cmsys/MD5.h>
  32. #endif
  33. #include <stdlib.h> // required for atof
  34. #include <assert.h>
  35. cmGlobalGenerator::cmGlobalGenerator()
  36. {
  37. // By default the .SYMBOLIC dependency is not needed on symbolic rules.
  38. this->NeedSymbolicMark = false;
  39. // by default use the native paths
  40. this->ForceUnixPaths = false;
  41. // By default do not try to support color.
  42. this->ToolSupportsColor = false;
  43. // By default do not use link scripts.
  44. this->UseLinkScript = false;
  45. // Whether an install target is needed.
  46. this->InstallTargetEnabled = false;
  47. // how long to let try compiles run
  48. this->TryCompileTimeout = 0;
  49. this->ExtraGenerator = 0;
  50. this->CurrentLocalGenerator = 0;
  51. this->TryCompileOuterMakefile = 0;
  52. }
  53. cmGlobalGenerator::~cmGlobalGenerator()
  54. {
  55. this->ClearGeneratorMembers();
  56. if (this->ExtraGenerator)
  57. {
  58. delete this->ExtraGenerator;
  59. }
  60. }
  61. bool cmGlobalGenerator::SetGeneratorToolset(std::string const& ts)
  62. {
  63. cmOStringStream e;
  64. e <<
  65. "Generator\n"
  66. " " << this->GetName() << "\n"
  67. "does not support toolset specification, but toolset\n"
  68. " " << ts << "\n"
  69. "was specified.";
  70. this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(),
  71. cmListFileBacktrace());
  72. return false;
  73. }
  74. std::string cmGlobalGenerator::SelectMakeProgram(const char* makeProgram,
  75. std::string makeDefault)
  76. {
  77. if(cmSystemTools::IsOff(makeProgram))
  78. {
  79. makeProgram =
  80. this->CMakeInstance->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
  81. if(cmSystemTools::IsOff(makeProgram))
  82. {
  83. makeProgram = makeDefault.c_str();
  84. }
  85. if(cmSystemTools::IsOff(makeProgram) &&
  86. !(makeProgram && *makeProgram))
  87. {
  88. makeProgram = "CMAKE_MAKE_PROGRAM-NOTFOUND";
  89. }
  90. }
  91. return makeProgram;
  92. }
  93. void cmGlobalGenerator::ResolveLanguageCompiler(const std::string &lang,
  94. cmMakefile *mf,
  95. bool optional)
  96. {
  97. std::string langComp = "CMAKE_";
  98. langComp += lang;
  99. langComp += "_COMPILER";
  100. if(!mf->GetDefinition(langComp.c_str()))
  101. {
  102. if(!optional)
  103. {
  104. cmSystemTools::Error(langComp.c_str(),
  105. " not set, after EnableLanguage");
  106. }
  107. return;
  108. }
  109. const char* name = mf->GetRequiredDefinition(langComp.c_str());
  110. std::string path;
  111. if(!cmSystemTools::FileIsFullPath(name))
  112. {
  113. path = cmSystemTools::FindProgram(name);
  114. }
  115. else
  116. {
  117. path = name;
  118. }
  119. if((path.size() == 0 || !cmSystemTools::FileExists(path.c_str()))
  120. && (optional==false))
  121. {
  122. return;
  123. }
  124. std::string doc = lang;
  125. doc += " compiler.";
  126. const char* cname = this->GetCMakeInstance()->
  127. GetCacheManager()->GetCacheValue(langComp.c_str());
  128. std::string changeVars;
  129. if(cname && !optional)
  130. {
  131. std::string cnameString;
  132. if(!cmSystemTools::FileIsFullPath(cname))
  133. {
  134. cnameString = cmSystemTools::FindProgram(cname);
  135. }
  136. else
  137. {
  138. cnameString = cname;
  139. }
  140. std::string pathString = path;
  141. // get rid of potentially multiple slashes:
  142. cmSystemTools::ConvertToUnixSlashes(cnameString);
  143. cmSystemTools::ConvertToUnixSlashes(pathString);
  144. if (cnameString != pathString)
  145. {
  146. const char* cvars =
  147. this->GetCMakeInstance()->GetProperty(
  148. "__CMAKE_DELETE_CACHE_CHANGE_VARS_");
  149. if(cvars)
  150. {
  151. changeVars += cvars;
  152. changeVars += ";";
  153. }
  154. changeVars += langComp;
  155. changeVars += ";";
  156. changeVars += cname;
  157. this->GetCMakeInstance()->SetProperty(
  158. "__CMAKE_DELETE_CACHE_CHANGE_VARS_",
  159. changeVars.c_str());
  160. }
  161. }
  162. mf->AddCacheDefinition(langComp.c_str(), path.c_str(),
  163. doc.c_str(), cmCacheManager::FILEPATH);
  164. }
  165. void cmGlobalGenerator::AddBuildExportSet(cmExportBuildFileGenerator* gen)
  166. {
  167. this->BuildExportSets[gen->GetMainExportFileName()] = gen;
  168. }
  169. void
  170. cmGlobalGenerator::AddBuildExportExportSet(cmExportBuildFileGenerator* gen)
  171. {
  172. this->BuildExportSets[gen->GetMainExportFileName()] = gen;
  173. this->BuildExportExportSets[gen->GetMainExportFileName()] = gen;
  174. }
  175. bool cmGlobalGenerator::GenerateImportFile(const std::string &file)
  176. {
  177. std::map<std::string, cmExportBuildFileGenerator*>::iterator it
  178. = this->BuildExportSets.find(file);
  179. if (it != this->BuildExportSets.end())
  180. {
  181. bool result = it->second->GenerateImportFile();
  182. delete it->second;
  183. it->second = 0;
  184. this->BuildExportSets.erase(it);
  185. return result;
  186. }
  187. return false;
  188. }
  189. bool
  190. cmGlobalGenerator::IsExportedTargetsFile(const std::string &filename) const
  191. {
  192. const std::map<std::string, cmExportBuildFileGenerator*>::const_iterator it
  193. = this->BuildExportSets.find(filename);
  194. if (it == this->BuildExportSets.end())
  195. {
  196. return false;
  197. }
  198. return this->BuildExportExportSets.find(filename)
  199. == this->BuildExportExportSets.end();
  200. }
  201. // Find the make program for the generator, required for try compiles
  202. void cmGlobalGenerator::FindMakeProgram(cmMakefile* mf)
  203. {
  204. if(this->FindMakeProgramFile.size() == 0)
  205. {
  206. cmSystemTools::Error(
  207. "Generator implementation error, "
  208. "all generators must specify this->FindMakeProgramFile");
  209. }
  210. if(!mf->GetDefinition("CMAKE_MAKE_PROGRAM")
  211. || cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM")))
  212. {
  213. std::string setMakeProgram =
  214. mf->GetModulesFile(this->FindMakeProgramFile.c_str());
  215. if(setMakeProgram.size())
  216. {
  217. mf->ReadListFile(0, setMakeProgram.c_str());
  218. }
  219. }
  220. if(!mf->GetDefinition("CMAKE_MAKE_PROGRAM")
  221. || cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM")))
  222. {
  223. cmOStringStream err;
  224. err << "CMake was unable to find a build program corresponding to \""
  225. << this->GetName() << "\". CMAKE_MAKE_PROGRAM is not set. You "
  226. << "probably need to select a different build tool.";
  227. cmSystemTools::Error(err.str().c_str());
  228. cmSystemTools::SetFatalErrorOccured();
  229. return;
  230. }
  231. std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  232. // if there are spaces in the make program use short path
  233. // but do not short path the actual program name, as
  234. // this can cause trouble with VSExpress
  235. if(makeProgram.find(' ') != makeProgram.npos)
  236. {
  237. std::string dir;
  238. std::string file;
  239. cmSystemTools::SplitProgramPath(makeProgram.c_str(),
  240. dir, file);
  241. std::string saveFile = file;
  242. cmSystemTools::GetShortPath(makeProgram.c_str(), makeProgram);
  243. cmSystemTools::SplitProgramPath(makeProgram.c_str(),
  244. dir, file);
  245. makeProgram = dir;
  246. makeProgram += "/";
  247. makeProgram += saveFile;
  248. mf->AddCacheDefinition("CMAKE_MAKE_PROGRAM", makeProgram.c_str(),
  249. "make program",
  250. cmCacheManager::FILEPATH);
  251. }
  252. if(makeProgram.find("xcodebuild") != makeProgram.npos)
  253. {
  254. // due to the text file busy /bin/sh problem with xcodebuild
  255. // use the cmakexbuild wrapper instead. This program
  256. // will run xcodebuild and if it sees the error text file busy
  257. // it will stop forwarding output, and let the build finish.
  258. // Then it will retry the build. It will continue this
  259. // untill no text file busy errors occur.
  260. std::string cmakexbuild =
  261. this->CMakeInstance->GetCacheManager()->GetCacheValue("CMAKE_COMMAND");
  262. cmakexbuild = cmakexbuild.substr(0, cmakexbuild.length()-5);
  263. cmakexbuild += "cmakexbuild";
  264. mf->AddCacheDefinition("CMAKE_MAKE_PROGRAM",
  265. cmakexbuild.c_str(),
  266. "make program",
  267. cmCacheManager::FILEPATH);
  268. }
  269. }
  270. // enable the given language
  271. //
  272. // The following files are loaded in this order:
  273. //
  274. // First figure out what OS we are running on:
  275. //
  276. // CMakeSystem.cmake - configured file created by CMakeDetermineSystem.cmake
  277. // CMakeDetermineSystem.cmake - figure out os info and create
  278. // CMakeSystem.cmake IF CMAKE_SYSTEM
  279. // not set
  280. // CMakeSystem.cmake - configured file created by
  281. // CMakeDetermineSystem.cmake IF CMAKE_SYSTEM_LOADED
  282. // Next try and enable all languages found in the languages vector
  283. //
  284. // FOREACH LANG in languages
  285. // CMake(LANG)Compiler.cmake - configured file create by
  286. // CMakeDetermine(LANG)Compiler.cmake
  287. // CMakeDetermine(LANG)Compiler.cmake - Finds compiler for LANG and
  288. // creates CMake(LANG)Compiler.cmake
  289. // CMake(LANG)Compiler.cmake - configured file created by
  290. // CMakeDetermine(LANG)Compiler.cmake
  291. //
  292. // CMakeSystemSpecificInformation.cmake
  293. // - includes Platform/${CMAKE_SYSTEM_NAME}.cmake
  294. // may use compiler stuff
  295. // FOREACH LANG in languages
  296. // CMake(LANG)Information.cmake
  297. // - loads Platform/${CMAKE_SYSTEM_NAME}-${COMPILER}.cmake
  298. // CMakeTest(LANG)Compiler.cmake
  299. // - Make sure the compiler works with a try compile if
  300. // CMakeDetermine(LANG) was loaded
  301. //
  302. // Now load a few files that can override values set in any of the above
  303. // (PROJECTNAME)Compatibility.cmake
  304. // - load any backwards compatibility stuff for current project
  305. // ${CMAKE_USER_MAKE_RULES_OVERRIDE}
  306. // - allow users a chance to override system variables
  307. //
  308. //
  309. void
  310. cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages,
  311. cmMakefile *mf, bool optional)
  312. {
  313. if(languages.size() == 0)
  314. {
  315. cmSystemTools::Error("EnableLanguage must have a lang specified!");
  316. cmSystemTools::SetFatalErrorOccured();
  317. return;
  318. }
  319. if(this->TryCompileOuterMakefile)
  320. {
  321. // In a try-compile we can only enable languages provided by caller.
  322. for(std::vector<std::string>::const_iterator li = languages.begin();
  323. li != languages.end(); ++li)
  324. {
  325. if(*li == "NONE")
  326. {
  327. this->SetLanguageEnabled("NONE", mf);
  328. }
  329. else
  330. {
  331. const char* lang = li->c_str();
  332. if(this->LanguagesReady.find(lang) == this->LanguagesReady.end())
  333. {
  334. cmOStringStream e;
  335. e << "The test project needs language "
  336. << lang << " which is not enabled.";
  337. this->TryCompileOuterMakefile
  338. ->IssueMessage(cmake::FATAL_ERROR, e.str());
  339. cmSystemTools::SetFatalErrorOccured();
  340. return;
  341. }
  342. }
  343. }
  344. }
  345. bool fatalError = false;
  346. mf->AddDefinition("RUN_CONFIGURE", true);
  347. std::string rootBin = mf->GetHomeOutputDirectory();
  348. rootBin += cmake::GetCMakeFilesDirectory();
  349. // If the configuration files path has been set,
  350. // then we are in a try compile and need to copy the enable language
  351. // files from the parent cmake bin dir, into the try compile bin dir
  352. if(this->ConfiguredFilesPath.size())
  353. {
  354. rootBin = this->ConfiguredFilesPath;
  355. }
  356. rootBin += "/";
  357. rootBin += cmVersion::GetCMakeVersion();
  358. // set the dir for parent files so they can be used by modules
  359. mf->AddDefinition("CMAKE_PLATFORM_INFO_DIR",rootBin.c_str());
  360. // find and make sure CMAKE_MAKE_PROGRAM is defined
  361. this->FindMakeProgram(mf);
  362. // try and load the CMakeSystem.cmake if it is there
  363. std::string fpath = rootBin;
  364. if(!mf->GetDefinition("CMAKE_SYSTEM_LOADED"))
  365. {
  366. fpath += "/CMakeSystem.cmake";
  367. if(cmSystemTools::FileExists(fpath.c_str()))
  368. {
  369. mf->ReadListFile(0,fpath.c_str());
  370. }
  371. }
  372. // Load the CMakeDetermineSystem.cmake file and find out
  373. // what platform we are running on
  374. if (!mf->GetDefinition("CMAKE_SYSTEM"))
  375. {
  376. #if defined(_WIN32) && !defined(__CYGWIN__)
  377. /* Windows version number data. */
  378. OSVERSIONINFO osvi;
  379. ZeroMemory(&osvi, sizeof(osvi));
  380. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  381. GetVersionEx (&osvi);
  382. cmOStringStream windowsVersionString;
  383. windowsVersionString << osvi.dwMajorVersion << "." << osvi.dwMinorVersion;
  384. windowsVersionString.str();
  385. mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION",
  386. windowsVersionString.str().c_str());
  387. #endif
  388. // Read the DetermineSystem file
  389. std::string systemFile = mf->GetModulesFile("CMakeDetermineSystem.cmake");
  390. mf->ReadListFile(0, systemFile.c_str());
  391. // load the CMakeSystem.cmake from the binary directory
  392. // this file is configured by the CMakeDetermineSystem.cmake file
  393. fpath = rootBin;
  394. fpath += "/CMakeSystem.cmake";
  395. mf->ReadListFile(0,fpath.c_str());
  396. }
  397. std::map<cmStdString, bool> needTestLanguage;
  398. std::map<cmStdString, bool> needSetLanguageEnabledMaps;
  399. // foreach language
  400. // load the CMakeDetermine(LANG)Compiler.cmake file to find
  401. // the compiler
  402. for(std::vector<std::string>::const_iterator l = languages.begin();
  403. l != languages.end(); ++l)
  404. {
  405. const char* lang = l->c_str();
  406. needSetLanguageEnabledMaps[lang] = false;
  407. if(*l == "NONE")
  408. {
  409. this->SetLanguageEnabled("NONE", mf);
  410. continue;
  411. }
  412. std::string loadedLang = "CMAKE_";
  413. loadedLang += lang;
  414. loadedLang += "_COMPILER_LOADED";
  415. if(!mf->GetDefinition(loadedLang.c_str()))
  416. {
  417. fpath = rootBin;
  418. fpath += "/CMake";
  419. fpath += lang;
  420. fpath += "Compiler.cmake";
  421. // If the existing build tree was already configured with this
  422. // version of CMake then try to load the configured file first
  423. // to avoid duplicate compiler tests.
  424. if(cmSystemTools::FileExists(fpath.c_str()))
  425. {
  426. if(!mf->ReadListFile(0,fpath.c_str()))
  427. {
  428. cmSystemTools::Error("Could not find cmake module file: ",
  429. fpath.c_str());
  430. }
  431. // if this file was found then the language was already determined
  432. // to be working
  433. needTestLanguage[lang] = false;
  434. this->SetLanguageEnabledFlag(lang, mf);
  435. needSetLanguageEnabledMaps[lang] = true;
  436. // this can only be called after loading CMake(LANG)Compiler.cmake
  437. }
  438. }
  439. if(!this->GetLanguageEnabled(lang) )
  440. {
  441. if (this->CMakeInstance->GetIsInTryCompile())
  442. {
  443. cmSystemTools::Error("This should not have happened. "
  444. "If you see this message, you are probably "
  445. "using a broken CMakeLists.txt file or a "
  446. "problematic release of CMake");
  447. }
  448. // if the CMake(LANG)Compiler.cmake file was not found then
  449. // load CMakeDetermine(LANG)Compiler.cmake
  450. std::string determineCompiler = "CMakeDetermine";
  451. determineCompiler += lang;
  452. determineCompiler += "Compiler.cmake";
  453. std::string determineFile =
  454. mf->GetModulesFile(determineCompiler.c_str());
  455. if(!mf->ReadListFile(0,determineFile.c_str()))
  456. {
  457. cmSystemTools::Error("Could not find cmake module file: ",
  458. determineFile.c_str());
  459. }
  460. needTestLanguage[lang] = true;
  461. // Some generators like visual studio should not use the env variables
  462. // So the global generator can specify that in this variable
  463. if(!mf->GetDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV"))
  464. {
  465. // put ${CMake_(LANG)_COMPILER_ENV_VAR}=${CMAKE_(LANG)_COMPILER
  466. // into the environment, in case user scripts want to run
  467. // configure, or sub cmakes
  468. std::string compilerName = "CMAKE_";
  469. compilerName += lang;
  470. compilerName += "_COMPILER";
  471. std::string compilerEnv = "CMAKE_";
  472. compilerEnv += lang;
  473. compilerEnv += "_COMPILER_ENV_VAR";
  474. std::string envVar = mf->GetRequiredDefinition(compilerEnv.c_str());
  475. std::string envVarValue =
  476. mf->GetRequiredDefinition(compilerName.c_str());
  477. std::string env = envVar;
  478. env += "=";
  479. env += envVarValue;
  480. cmSystemTools::PutEnv(env.c_str());
  481. }
  482. // if determineLanguage was called then load the file it
  483. // configures CMake(LANG)Compiler.cmake
  484. fpath = rootBin;
  485. fpath += "/CMake";
  486. fpath += lang;
  487. fpath += "Compiler.cmake";
  488. if(!mf->ReadListFile(0,fpath.c_str()))
  489. {
  490. cmSystemTools::Error("Could not find cmake module file: ",
  491. fpath.c_str());
  492. }
  493. this->SetLanguageEnabledFlag(lang, mf);
  494. needSetLanguageEnabledMaps[lang] = true;
  495. // this can only be called after loading CMake(LANG)Compiler.cmake
  496. // the language must be enabled for try compile to work, but we do
  497. // not know if it is a working compiler yet so set the test language
  498. // flag
  499. needTestLanguage[lang] = true;
  500. } // end if(!this->GetLanguageEnabled(lang) )
  501. } // end loop over languages
  502. // **** Load the system specific information if not yet loaded
  503. if (!mf->GetDefinition("CMAKE_SYSTEM_SPECIFIC_INFORMATION_LOADED"))
  504. {
  505. fpath = mf->GetModulesFile("CMakeSystemSpecificInformation.cmake");
  506. if(!mf->ReadListFile(0,fpath.c_str()))
  507. {
  508. cmSystemTools::Error("Could not find cmake module file: ",
  509. fpath.c_str());
  510. }
  511. }
  512. // loop over languages again loading CMake(LANG)Information.cmake
  513. //
  514. for(std::vector<std::string>::const_iterator l = languages.begin();
  515. l != languages.end(); ++l)
  516. {
  517. const char* lang = l->c_str();
  518. if(*l == "NONE")
  519. {
  520. this->SetLanguageEnabled("NONE", mf);
  521. continue;
  522. }
  523. // Check that the compiler was found.
  524. std::string compilerName = "CMAKE_";
  525. compilerName += lang;
  526. compilerName += "_COMPILER";
  527. std::string compilerEnv = "CMAKE_";
  528. compilerEnv += lang;
  529. compilerEnv += "_COMPILER_ENV_VAR";
  530. cmOStringStream noCompiler;
  531. const char* compilerFile = mf->GetDefinition(compilerName.c_str());
  532. if(!compilerFile || !*compilerFile ||
  533. cmSystemTools::IsNOTFOUND(compilerFile))
  534. {
  535. noCompiler <<
  536. "No " << compilerName << " could be found.\n"
  537. ;
  538. }
  539. else if(strcmp(lang, "RC") != 0)
  540. {
  541. if(!cmSystemTools::FileIsFullPath(compilerFile))
  542. {
  543. noCompiler <<
  544. "The " << compilerName << ":\n"
  545. " " << compilerFile << "\n"
  546. "is not a full path and was not found in the PATH.\n"
  547. ;
  548. }
  549. else if(!cmSystemTools::FileExists(compilerFile))
  550. {
  551. noCompiler <<
  552. "The " << compilerName << ":\n"
  553. " " << compilerFile << "\n"
  554. "is not a full path to an existing compiler tool.\n"
  555. ;
  556. }
  557. }
  558. if(!noCompiler.str().empty())
  559. {
  560. // Skip testing this language since the compiler is not found.
  561. needTestLanguage[lang] = false;
  562. if(!optional)
  563. {
  564. // The compiler was not found and it is not optional. Remove
  565. // CMake(LANG)Compiler.cmake so we try again next time CMake runs.
  566. std::string compilerLangFile = rootBin;
  567. compilerLangFile += "/CMake";
  568. compilerLangFile += lang;
  569. compilerLangFile += "Compiler.cmake";
  570. cmSystemTools::RemoveFile(compilerLangFile.c_str());
  571. if(!this->CMakeInstance->GetIsInTryCompile())
  572. {
  573. this->PrintCompilerAdvice(noCompiler, lang,
  574. mf->GetDefinition(compilerEnv.c_str()));
  575. mf->IssueMessage(cmake::FATAL_ERROR, noCompiler.str());
  576. fatalError = true;
  577. }
  578. }
  579. }
  580. std::string langLoadedVar = "CMAKE_";
  581. langLoadedVar += lang;
  582. langLoadedVar += "_INFORMATION_LOADED";
  583. if (!mf->GetDefinition(langLoadedVar.c_str()))
  584. {
  585. fpath = "CMake";
  586. fpath += lang;
  587. fpath += "Information.cmake";
  588. std::string informationFile = mf->GetModulesFile(fpath.c_str());
  589. if (informationFile.empty())
  590. {
  591. cmSystemTools::Error("Could not find cmake module file: ",
  592. fpath.c_str());
  593. }
  594. else if(!mf->ReadListFile(0, informationFile.c_str()))
  595. {
  596. cmSystemTools::Error("Could not process cmake module file: ",
  597. informationFile.c_str());
  598. }
  599. }
  600. if (needSetLanguageEnabledMaps[lang])
  601. {
  602. this->SetLanguageEnabledMaps(lang, mf);
  603. }
  604. this->LanguagesReady.insert(lang);
  605. // Test the compiler for the language just setup
  606. // (but only if a compiler has been actually found)
  607. // At this point we should have enough info for a try compile
  608. // which is used in the backward stuff
  609. // If the language is untested then test it now with a try compile.
  610. if(needTestLanguage[lang])
  611. {
  612. if (!this->CMakeInstance->GetIsInTryCompile())
  613. {
  614. std::string testLang = "CMakeTest";
  615. testLang += lang;
  616. testLang += "Compiler.cmake";
  617. std::string ifpath = mf->GetModulesFile(testLang.c_str());
  618. if(!mf->ReadListFile(0,ifpath.c_str()))
  619. {
  620. cmSystemTools::Error("Could not find cmake module file: ",
  621. ifpath.c_str());
  622. }
  623. std::string compilerWorks = "CMAKE_";
  624. compilerWorks += lang;
  625. compilerWorks += "_COMPILER_WORKS";
  626. // if the compiler did not work, then remove the
  627. // CMake(LANG)Compiler.cmake file so that it will get tested the
  628. // next time cmake is run
  629. if(!mf->IsOn(compilerWorks.c_str()))
  630. {
  631. std::string compilerLangFile = rootBin;
  632. compilerLangFile += "/CMake";
  633. compilerLangFile += lang;
  634. compilerLangFile += "Compiler.cmake";
  635. cmSystemTools::RemoveFile(compilerLangFile.c_str());
  636. }
  637. } // end if in try compile
  638. } // end need test language
  639. // Store the shared library flags so that we can satisfy CMP0018
  640. std::string sharedLibFlagsVar = "CMAKE_SHARED_LIBRARY_";
  641. sharedLibFlagsVar += lang;
  642. sharedLibFlagsVar += "_FLAGS";
  643. const char* sharedLibFlags =
  644. mf->GetSafeDefinition(sharedLibFlagsVar.c_str());
  645. if (sharedLibFlags)
  646. {
  647. this->LanguageToOriginalSharedLibFlags[lang] = sharedLibFlags;
  648. }
  649. // Translate compiler ids for compatibility.
  650. this->CheckCompilerIdCompatibility(mf, lang);
  651. } // end for each language
  652. // Now load files that can override any settings on the platform or for
  653. // the project First load the project compatibility file if it is in
  654. // cmake
  655. std::string projectCompatibility = mf->GetDefinition("CMAKE_ROOT");
  656. projectCompatibility += "/Modules/";
  657. projectCompatibility += mf->GetSafeDefinition("PROJECT_NAME");
  658. projectCompatibility += "Compatibility.cmake";
  659. if(cmSystemTools::FileExists(projectCompatibility.c_str()))
  660. {
  661. mf->ReadListFile(0,projectCompatibility.c_str());
  662. }
  663. // Inform any extra generator of the new language.
  664. if (this->ExtraGenerator)
  665. {
  666. this->ExtraGenerator->EnableLanguage(languages, mf, false);
  667. }
  668. if(fatalError)
  669. {
  670. cmSystemTools::SetFatalErrorOccured();
  671. }
  672. }
  673. //----------------------------------------------------------------------------
  674. void cmGlobalGenerator::PrintCompilerAdvice(std::ostream& os,
  675. std::string lang,
  676. const char* envVar)
  677. {
  678. // Subclasses override this method if they do not support this advice.
  679. os <<
  680. "Tell CMake where to find the compiler by setting "
  681. ;
  682. if(envVar)
  683. {
  684. os <<
  685. "either the environment variable \"" << envVar << "\" or "
  686. ;
  687. }
  688. os <<
  689. "the CMake cache entry CMAKE_" << lang << "_COMPILER "
  690. "to the full path to the compiler, or to the compiler name "
  691. "if it is in the PATH."
  692. ;
  693. }
  694. //----------------------------------------------------------------------------
  695. void cmGlobalGenerator::CheckCompilerIdCompatibility(cmMakefile* mf,
  696. std::string lang)
  697. {
  698. std::string compilerIdVar = "CMAKE_" + lang + "_COMPILER_ID";
  699. const char* compilerId = mf->GetDefinition(compilerIdVar.c_str());
  700. if(compilerId && strcmp(compilerId, "AppleClang") == 0)
  701. {
  702. cmPolicies* policies = this->CMakeInstance->GetPolicies();
  703. switch(mf->GetPolicyStatus(cmPolicies::CMP0025))
  704. {
  705. case cmPolicies::WARN:
  706. if(!this->CMakeInstance->GetIsInTryCompile())
  707. {
  708. cmOStringStream w;
  709. w << policies->GetPolicyWarning(cmPolicies::CMP0025) << "\n"
  710. "Converting " << lang <<
  711. " compiler id \"AppleClang\" to \"Clang\" for compatibility."
  712. ;
  713. mf->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  714. }
  715. case cmPolicies::OLD:
  716. // OLD behavior is to convert AppleClang to Clang.
  717. mf->AddDefinition(compilerIdVar.c_str(), "Clang");
  718. break;
  719. case cmPolicies::REQUIRED_IF_USED:
  720. case cmPolicies::REQUIRED_ALWAYS:
  721. mf->IssueMessage(
  722. cmake::FATAL_ERROR,
  723. policies->GetRequiredPolicyError(cmPolicies::CMP0025)
  724. );
  725. case cmPolicies::NEW:
  726. // NEW behavior is to keep AppleClang.
  727. break;
  728. }
  729. }
  730. }
  731. //----------------------------------------------------------------------------
  732. const char*
  733. cmGlobalGenerator::GetLanguageOutputExtension(cmSourceFile const& source)
  734. {
  735. if(const char* lang = source.GetLanguage())
  736. {
  737. if(this->LanguageToOutputExtension.count(lang) > 0)
  738. {
  739. return this->LanguageToOutputExtension[lang].c_str();
  740. }
  741. }
  742. else
  743. {
  744. // if no language is found then check to see if it is already an
  745. // ouput extension for some language. In that case it should be ignored
  746. // and in this map, so it will not be compiled but will just be used.
  747. std::string const& ext = source.GetExtension();
  748. if(!ext.empty())
  749. {
  750. if(this->OutputExtensions.count(ext))
  751. {
  752. return ext.c_str();
  753. }
  754. }
  755. }
  756. return "";
  757. }
  758. const char* cmGlobalGenerator::GetLanguageFromExtension(const char* ext)
  759. {
  760. // if there is an extension and it starts with . then move past the
  761. // . because the extensions are not stored with a . in the map
  762. if(ext && *ext == '.')
  763. {
  764. ++ext;
  765. }
  766. if(this->ExtensionToLanguage.count(ext) > 0)
  767. {
  768. return this->ExtensionToLanguage[ext].c_str();
  769. }
  770. return 0;
  771. }
  772. /* SetLanguageEnabled() is now split in two parts:
  773. at first the enabled-flag is set. This can then be used in EnabledLanguage()
  774. for checking whether the language is already enabled. After setting this
  775. flag still the values from the cmake variables have to be copied into the
  776. internal maps, this is done in SetLanguageEnabledMaps() which is called
  777. after the system- and compiler specific files have been loaded.
  778. This split was done originally so that compiler-specific configuration
  779. files could change the object file extension
  780. (CMAKE_<LANG>_OUTPUT_EXTENSION) before the CMake variables were copied
  781. to the C++ maps.
  782. */
  783. void cmGlobalGenerator::SetLanguageEnabled(const char* l, cmMakefile* mf)
  784. {
  785. this->SetLanguageEnabledFlag(l, mf);
  786. this->SetLanguageEnabledMaps(l, mf);
  787. }
  788. void cmGlobalGenerator::SetLanguageEnabledFlag(const char* l, cmMakefile* mf)
  789. {
  790. this->LanguageEnabled[l] = true;
  791. // Fill the language-to-extension map with the current variable
  792. // settings to make sure it is available for the try_compile()
  793. // command source file signature. In SetLanguageEnabledMaps this
  794. // will be done again to account for any compiler- or
  795. // platform-specific entries.
  796. this->FillExtensionToLanguageMap(l, mf);
  797. }
  798. void cmGlobalGenerator::SetLanguageEnabledMaps(const char* l, cmMakefile* mf)
  799. {
  800. // use LanguageToLinkerPreference to detect whether this functions has
  801. // run before
  802. if (this->LanguageToLinkerPreference.find(l) !=
  803. this->LanguageToLinkerPreference.end())
  804. {
  805. return;
  806. }
  807. std::string linkerPrefVar = std::string("CMAKE_") +
  808. std::string(l) + std::string("_LINKER_PREFERENCE");
  809. const char* linkerPref = mf->GetDefinition(linkerPrefVar.c_str());
  810. int preference = 0;
  811. if(linkerPref)
  812. {
  813. if (sscanf(linkerPref, "%d", &preference)!=1)
  814. {
  815. // backward compatibility: before 2.6 LINKER_PREFERENCE
  816. // was either "None" or "Prefered", and only the first character was
  817. // tested. So if there is a custom language out there and it is
  818. // "Prefered", set its preference high
  819. if (linkerPref[0]=='P')
  820. {
  821. preference = 100;
  822. }
  823. else
  824. {
  825. preference = 0;
  826. }
  827. }
  828. }
  829. if (preference < 0)
  830. {
  831. std::string msg = linkerPrefVar;
  832. msg += " is negative, adjusting it to 0";
  833. cmSystemTools::Message(msg.c_str(), "Warning");
  834. preference = 0;
  835. }
  836. this->LanguageToLinkerPreference[l] = preference;
  837. std::string outputExtensionVar = std::string("CMAKE_") +
  838. std::string(l) + std::string("_OUTPUT_EXTENSION");
  839. const char* outputExtension = mf->GetDefinition(outputExtensionVar.c_str());
  840. if(outputExtension)
  841. {
  842. this->LanguageToOutputExtension[l] = outputExtension;
  843. this->OutputExtensions[outputExtension] = outputExtension;
  844. if(outputExtension[0] == '.')
  845. {
  846. this->OutputExtensions[outputExtension+1] = outputExtension+1;
  847. }
  848. }
  849. // The map was originally filled by SetLanguageEnabledFlag, but
  850. // since then the compiler- and platform-specific files have been
  851. // loaded which might have added more entries.
  852. this->FillExtensionToLanguageMap(l, mf);
  853. std::string ignoreExtensionsVar = std::string("CMAKE_") +
  854. std::string(l) + std::string("_IGNORE_EXTENSIONS");
  855. std::string ignoreExts = mf->GetSafeDefinition(ignoreExtensionsVar.c_str());
  856. std::vector<std::string> extensionList;
  857. cmSystemTools::ExpandListArgument(ignoreExts, extensionList);
  858. for(std::vector<std::string>::iterator i = extensionList.begin();
  859. i != extensionList.end(); ++i)
  860. {
  861. this->IgnoreExtensions[*i] = true;
  862. }
  863. }
  864. void cmGlobalGenerator::FillExtensionToLanguageMap(const char* l,
  865. cmMakefile* mf)
  866. {
  867. std::string extensionsVar = std::string("CMAKE_") +
  868. std::string(l) + std::string("_SOURCE_FILE_EXTENSIONS");
  869. std::string exts = mf->GetSafeDefinition(extensionsVar.c_str());
  870. std::vector<std::string> extensionList;
  871. cmSystemTools::ExpandListArgument(exts, extensionList);
  872. for(std::vector<std::string>::iterator i = extensionList.begin();
  873. i != extensionList.end(); ++i)
  874. {
  875. this->ExtensionToLanguage[*i] = l;
  876. }
  877. }
  878. bool cmGlobalGenerator::IgnoreFile(const char* l)
  879. {
  880. if(this->GetLanguageFromExtension(l))
  881. {
  882. return false;
  883. }
  884. return (this->IgnoreExtensions.count(l) > 0);
  885. }
  886. bool cmGlobalGenerator::GetLanguageEnabled(const char* l) const
  887. {
  888. return (this->LanguageEnabled.find(l)!= this->LanguageEnabled.end());
  889. }
  890. void cmGlobalGenerator::ClearEnabledLanguages()
  891. {
  892. this->LanguageEnabled.clear();
  893. }
  894. bool cmGlobalGenerator::IsDependedOn(const char* project,
  895. cmTarget const* targetIn)
  896. {
  897. // Get all local gens for this project
  898. std::vector<cmLocalGenerator*>* gens = &this->ProjectMap[project];
  899. // loop over local gens and get the targets for each one
  900. for(unsigned int i = 0; i < gens->size(); ++i)
  901. {
  902. cmTargets& targets = (*gens)[i]->GetMakefile()->GetTargets();
  903. for (cmTargets::iterator l = targets.begin();
  904. l != targets.end(); l++)
  905. {
  906. cmTarget& target = l->second;
  907. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(target);
  908. if(tgtdeps.count(targetIn))
  909. {
  910. return true;
  911. }
  912. }
  913. }
  914. return false;
  915. }
  916. void cmGlobalGenerator::Configure()
  917. {
  918. this->FirstTimeProgress = 0.0f;
  919. this->ClearGeneratorMembers();
  920. // start with this directory
  921. cmLocalGenerator *lg = this->CreateLocalGenerator();
  922. this->LocalGenerators.push_back(lg);
  923. // set the Start directories
  924. cmMakefile* mf = lg->GetMakefile();
  925. lg->GetMakefile()->SetStartDirectory
  926. (this->CMakeInstance->GetStartDirectory());
  927. lg->GetMakefile()->SetStartOutputDirectory
  928. (this->CMakeInstance->GetStartOutputDirectory());
  929. lg->GetMakefile()->MakeStartDirectoriesCurrent();
  930. this->BinaryDirectories.insert(mf->GetStartOutputDirectory());
  931. // now do it
  932. lg->Configure();
  933. // update the cache entry for the number of local generators, this is used
  934. // for progress
  935. char num[100];
  936. sprintf(num,"%d",static_cast<int>(this->LocalGenerators.size()));
  937. this->GetCMakeInstance()->AddCacheEntry
  938. ("CMAKE_NUMBER_OF_LOCAL_GENERATORS", num,
  939. "number of local generators", cmCacheManager::INTERNAL);
  940. // check for link libraries and include directories containing "NOTFOUND"
  941. // and for infinite loops
  942. this->CheckLocalGenerators();
  943. // at this point this->LocalGenerators has been filled,
  944. // so create the map from project name to vector of local generators
  945. this->FillProjectMap();
  946. if ( this->CMakeInstance->GetWorkingMode() == cmake::NORMAL_MODE)
  947. {
  948. cmOStringStream msg;
  949. if(cmSystemTools::GetErrorOccuredFlag())
  950. {
  951. msg << "Configuring incomplete, errors occurred!";
  952. const char* logs[] = {"CMakeOutput.log", "CMakeError.log", 0};
  953. for(const char** log = logs; *log; ++log)
  954. {
  955. std::string f = this->CMakeInstance->GetHomeOutputDirectory();
  956. f += this->CMakeInstance->GetCMakeFilesDirectory();
  957. f += "/";
  958. f += *log;
  959. if(cmSystemTools::FileExists(f.c_str()))
  960. {
  961. msg << "\nSee also \"" << f << "\".";
  962. }
  963. }
  964. }
  965. else
  966. {
  967. msg << "Configuring done";
  968. }
  969. this->CMakeInstance->UpdateProgress(msg.str().c_str(), -1);
  970. }
  971. }
  972. cmExportBuildFileGenerator*
  973. cmGlobalGenerator::GetExportedTargetsFile(const std::string &filename) const
  974. {
  975. std::map<std::string, cmExportBuildFileGenerator*>::const_iterator it
  976. = this->BuildExportSets.find(filename);
  977. return it == this->BuildExportSets.end() ? 0 : it->second;
  978. }
  979. //----------------------------------------------------------------------------
  980. void cmGlobalGenerator::AddCMP0042WarnTarget(const std::string& target)
  981. {
  982. this->CMP0042WarnTargets.insert(target);
  983. }
  984. bool cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS()
  985. {
  986. // If the property is not enabled then okay.
  987. if(!this->CMakeInstance
  988. ->GetPropertyAsBool("ALLOW_DUPLICATE_CUSTOM_TARGETS"))
  989. {
  990. return true;
  991. }
  992. // This generator does not support duplicate custom targets.
  993. cmOStringStream e;
  994. e << "This project has enabled the ALLOW_DUPLICATE_CUSTOM_TARGETS "
  995. << "global property. "
  996. << "The \"" << this->GetName() << "\" generator does not support "
  997. << "duplicate custom targets. "
  998. << "Consider using a Makefiles generator or fix the project to not "
  999. << "use duplicate target names.";
  1000. cmSystemTools::Error(e.str().c_str());
  1001. return false;
  1002. }
  1003. void cmGlobalGenerator::Generate()
  1004. {
  1005. // Some generators track files replaced during the Generate.
  1006. // Start with an empty vector:
  1007. this->FilesReplacedDuringGenerate.clear();
  1008. // clear targets to issue warning CMP0042 for
  1009. this->CMP0042WarnTargets.clear();
  1010. // Check whether this generator is allowed to run.
  1011. if(!this->CheckALLOW_DUPLICATE_CUSTOM_TARGETS())
  1012. {
  1013. return;
  1014. }
  1015. // Check that all targets are valid.
  1016. if(!this->CheckTargets())
  1017. {
  1018. return;
  1019. }
  1020. this->FinalizeTargetCompileInfo();
  1021. #ifdef CMAKE_BUILD_WITH_CMAKE
  1022. // Iterate through all targets and set up automoc for those which have
  1023. // the AUTOMOC, AUTOUIC or AUTORCC property set
  1024. AutogensType autogens;
  1025. this->CreateQtAutoGeneratorsTargets(autogens);
  1026. #endif
  1027. // For each existing cmLocalGenerator
  1028. unsigned int i;
  1029. // Put a copy of each global target in every directory.
  1030. cmTargets globalTargets;
  1031. this->CreateDefaultGlobalTargets(&globalTargets);
  1032. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1033. {
  1034. cmMakefile* mf = this->LocalGenerators[i]->GetMakefile();
  1035. cmTargets* targets = &(mf->GetTargets());
  1036. cmTargets::iterator tit;
  1037. for ( tit = globalTargets.begin(); tit != globalTargets.end(); ++ tit )
  1038. {
  1039. (*targets)[tit->first] = tit->second;
  1040. (*targets)[tit->first].SetMakefile(mf);
  1041. }
  1042. }
  1043. // Add generator specific helper commands
  1044. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1045. {
  1046. this->LocalGenerators[i]->AddHelperCommands();
  1047. }
  1048. // Create per-target generator information.
  1049. this->CreateGeneratorTargets();
  1050. #ifdef CMAKE_BUILD_WITH_CMAKE
  1051. for (AutogensType::iterator it = autogens.begin(); it != autogens.end();
  1052. ++it)
  1053. {
  1054. it->first.SetupAutoGenerateTarget(it->second);
  1055. }
  1056. #endif
  1057. // Trace the dependencies, after that no custom commands should be added
  1058. // because their dependencies might not be handled correctly
  1059. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1060. {
  1061. this->LocalGenerators[i]->TraceDependencies();
  1062. }
  1063. // Compute the manifest of main targets generated.
  1064. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1065. {
  1066. this->LocalGenerators[i]->GenerateTargetManifest();
  1067. }
  1068. this->ComputeGeneratorTargetObjects();
  1069. this->ProcessEvaluationFiles();
  1070. // Compute the inter-target dependencies.
  1071. if(!this->ComputeTargetDepends())
  1072. {
  1073. return;
  1074. }
  1075. // Create a map from local generator to the complete set of targets
  1076. // it builds by default.
  1077. this->FillLocalGeneratorToTargetMap();
  1078. // Generate project files
  1079. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1080. {
  1081. this->LocalGenerators[i]->GetMakefile()->SetGeneratingBuildSystem();
  1082. this->SetCurrentLocalGenerator(this->LocalGenerators[i]);
  1083. this->LocalGenerators[i]->Generate();
  1084. this->LocalGenerators[i]->GenerateInstallRules();
  1085. this->LocalGenerators[i]->GenerateTestFiles();
  1086. this->CMakeInstance->UpdateProgress("Generating",
  1087. (static_cast<float>(i)+1.0f)/
  1088. static_cast<float>(this->LocalGenerators.size()));
  1089. }
  1090. this->SetCurrentLocalGenerator(0);
  1091. for (std::map<std::string, cmExportBuildFileGenerator*>::iterator
  1092. it = this->BuildExportSets.begin(); it != this->BuildExportSets.end();
  1093. ++it)
  1094. {
  1095. if (!it->second->GenerateImportFile()
  1096. && !cmSystemTools::GetErrorOccuredFlag())
  1097. {
  1098. this->GetCMakeInstance()
  1099. ->IssueMessage(cmake::FATAL_ERROR, "Could not write export file.",
  1100. cmListFileBacktrace());
  1101. return;
  1102. }
  1103. }
  1104. // Update rule hashes.
  1105. this->CheckRuleHashes();
  1106. this->WriteSummary();
  1107. if (this->ExtraGenerator != 0)
  1108. {
  1109. this->ExtraGenerator->Generate();
  1110. }
  1111. if(!this->CMP0042WarnTargets.empty())
  1112. {
  1113. cmOStringStream w;
  1114. w <<
  1115. (this->GetCMakeInstance()->GetPolicies()->
  1116. GetPolicyWarning(cmPolicies::CMP0042)) << "\n";
  1117. w << "MACOSX_RPATH is not specified for"
  1118. " the following targets:\n";
  1119. for(std::set<std::string>::iterator
  1120. iter = this->CMP0042WarnTargets.begin();
  1121. iter != this->CMP0042WarnTargets.end();
  1122. ++iter)
  1123. {
  1124. w << " " << *iter << "\n";
  1125. }
  1126. this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  1127. cmListFileBacktrace());
  1128. }
  1129. this->CMakeInstance->UpdateProgress("Generating done", -1);
  1130. }
  1131. //----------------------------------------------------------------------------
  1132. bool cmGlobalGenerator::ComputeTargetDepends()
  1133. {
  1134. cmComputeTargetDepends ctd(this);
  1135. if(!ctd.Compute())
  1136. {
  1137. return false;
  1138. }
  1139. std::vector<cmTarget const*> const& targets = ctd.GetTargets();
  1140. for(std::vector<cmTarget const*>::const_iterator ti = targets.begin();
  1141. ti != targets.end(); ++ti)
  1142. {
  1143. ctd.GetTargetDirectDepends(*ti, this->TargetDependencies[*ti]);
  1144. }
  1145. return true;
  1146. }
  1147. //----------------------------------------------------------------------------
  1148. bool cmGlobalGenerator::CheckTargets()
  1149. {
  1150. // Make sure all targets can find their source files.
  1151. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1152. {
  1153. cmTargets& targets =
  1154. this->LocalGenerators[i]->GetMakefile()->GetTargets();
  1155. for(cmTargets::iterator ti = targets.begin();
  1156. ti != targets.end(); ++ti)
  1157. {
  1158. cmTarget& target = ti->second;
  1159. if(target.GetType() == cmTarget::EXECUTABLE ||
  1160. target.GetType() == cmTarget::STATIC_LIBRARY ||
  1161. target.GetType() == cmTarget::SHARED_LIBRARY ||
  1162. target.GetType() == cmTarget::MODULE_LIBRARY ||
  1163. target.GetType() == cmTarget::OBJECT_LIBRARY ||
  1164. target.GetType() == cmTarget::UTILITY)
  1165. {
  1166. if(!target.FindSourceFiles())
  1167. {
  1168. return false;
  1169. }
  1170. }
  1171. }
  1172. }
  1173. return true;
  1174. }
  1175. //----------------------------------------------------------------------------
  1176. void cmGlobalGenerator::CreateQtAutoGeneratorsTargets(AutogensType &autogens)
  1177. {
  1178. #ifdef CMAKE_BUILD_WITH_CMAKE
  1179. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1180. {
  1181. cmTargets& targets =
  1182. this->LocalGenerators[i]->GetMakefile()->GetTargets();
  1183. for(cmTargets::iterator ti = targets.begin();
  1184. ti != targets.end(); ++ti)
  1185. {
  1186. cmTarget& target = ti->second;
  1187. if(target.GetType() == cmTarget::EXECUTABLE ||
  1188. target.GetType() == cmTarget::STATIC_LIBRARY ||
  1189. target.GetType() == cmTarget::SHARED_LIBRARY ||
  1190. target.GetType() == cmTarget::MODULE_LIBRARY ||
  1191. target.GetType() == cmTarget::OBJECT_LIBRARY)
  1192. {
  1193. if((target.GetPropertyAsBool("AUTOMOC")
  1194. || target.GetPropertyAsBool("AUTOUIC")
  1195. || target.GetPropertyAsBool("AUTORCC"))
  1196. && !target.IsImported())
  1197. {
  1198. cmQtAutoGenerators autogen;
  1199. if(autogen.InitializeAutogenTarget(&target))
  1200. {
  1201. autogens.push_back(AutogensType::value_type(autogen, &target));
  1202. }
  1203. }
  1204. }
  1205. }
  1206. }
  1207. #else
  1208. (void)autogens;
  1209. #endif
  1210. }
  1211. //----------------------------------------------------------------------------
  1212. void cmGlobalGenerator::FinalizeTargetCompileInfo()
  1213. {
  1214. // Construct per-target generator information.
  1215. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1216. {
  1217. cmMakefile *mf = this->LocalGenerators[i]->GetMakefile();
  1218. const std::vector<cmValueWithOrigin> noconfig_compile_definitions =
  1219. mf->GetCompileDefinitionsEntries();
  1220. std::vector<std::string> configs;
  1221. mf->GetConfigurations(configs);
  1222. cmTargets& targets = mf->GetTargets();
  1223. for(cmTargets::iterator ti = targets.begin();
  1224. ti != targets.end(); ++ti)
  1225. {
  1226. cmTarget* t = &ti->second;
  1227. t->AppendBuildInterfaceIncludes();
  1228. if (t->GetType() == cmTarget::INTERFACE_LIBRARY)
  1229. {
  1230. continue;
  1231. }
  1232. for (std::vector<cmValueWithOrigin>::const_iterator it
  1233. = noconfig_compile_definitions.begin();
  1234. it != noconfig_compile_definitions.end(); ++it)
  1235. {
  1236. t->InsertCompileDefinition(*it);
  1237. }
  1238. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1239. ci != configs.end(); ++ci)
  1240. {
  1241. std::string defPropName = "COMPILE_DEFINITIONS_";
  1242. defPropName += cmSystemTools::UpperCase(*ci);
  1243. t->AppendProperty(defPropName.c_str(),
  1244. mf->GetProperty(defPropName.c_str()));
  1245. }
  1246. }
  1247. }
  1248. }
  1249. //----------------------------------------------------------------------------
  1250. void cmGlobalGenerator::CreateGeneratorTargets()
  1251. {
  1252. // Construct per-target generator information.
  1253. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1254. {
  1255. cmGeneratorTargetsType generatorTargets;
  1256. cmMakefile *mf = this->LocalGenerators[i]->GetMakefile();
  1257. cmTargets& targets = mf->GetTargets();
  1258. for(cmTargets::iterator ti = targets.begin();
  1259. ti != targets.end(); ++ti)
  1260. {
  1261. cmTarget* t = &ti->second;
  1262. cmGeneratorTarget* gt = new cmGeneratorTarget(t);
  1263. this->GeneratorTargets[t] = gt;
  1264. generatorTargets[t] = gt;
  1265. }
  1266. for(std::vector<cmTarget*>::const_iterator
  1267. j = mf->GetOwnedImportedTargets().begin();
  1268. j != mf->GetOwnedImportedTargets().end(); ++j)
  1269. {
  1270. cmGeneratorTarget* gt = new cmGeneratorTarget(*j);
  1271. this->GeneratorTargets[*j] = gt;
  1272. generatorTargets[*j] = gt;
  1273. }
  1274. mf->SetGeneratorTargets(generatorTargets);
  1275. }
  1276. }
  1277. //----------------------------------------------------------------------------
  1278. void cmGlobalGenerator::ComputeGeneratorTargetObjects()
  1279. {
  1280. // Construct per-target generator information.
  1281. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1282. {
  1283. cmMakefile *mf = this->LocalGenerators[i]->GetMakefile();
  1284. cmGeneratorTargetsType targets = mf->GetGeneratorTargets();
  1285. for(cmGeneratorTargetsType::iterator ti = targets.begin();
  1286. ti != targets.end(); ++ti)
  1287. {
  1288. if (ti->second->Target->IsImported())
  1289. {
  1290. continue;
  1291. }
  1292. cmGeneratorTarget* gt = ti->second;
  1293. gt->ClassifySources();
  1294. gt->LookupObjectLibraries();
  1295. this->ComputeTargetObjects(gt);
  1296. }
  1297. }
  1298. }
  1299. //----------------------------------------------------------------------------
  1300. void cmGlobalGenerator::ClearGeneratorMembers()
  1301. {
  1302. for(cmGeneratorTargetsType::iterator i = this->GeneratorTargets.begin();
  1303. i != this->GeneratorTargets.end(); ++i)
  1304. {
  1305. delete i->second;
  1306. }
  1307. this->GeneratorTargets.clear();
  1308. for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
  1309. li = this->EvaluationFiles.begin();
  1310. li != this->EvaluationFiles.end();
  1311. ++li)
  1312. {
  1313. delete *li;
  1314. }
  1315. this->EvaluationFiles.clear();
  1316. for(std::map<std::string, cmExportBuildFileGenerator*>::iterator
  1317. i = this->BuildExportSets.begin();
  1318. i != this->BuildExportSets.end(); ++i)
  1319. {
  1320. delete i->second;
  1321. }
  1322. this->BuildExportSets.clear();
  1323. for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
  1324. {
  1325. delete this->LocalGenerators[i];
  1326. }
  1327. this->LocalGenerators.clear();
  1328. this->ExportSets.clear();
  1329. this->TargetDependencies.clear();
  1330. this->TotalTargets.clear();
  1331. this->ImportedTargets.clear();
  1332. this->LocalGeneratorToTargetMap.clear();
  1333. this->ProjectMap.clear();
  1334. this->RuleHashes.clear();
  1335. this->DirectoryContentMap.clear();
  1336. this->BinaryDirectories.clear();
  1337. }
  1338. //----------------------------------------------------------------------------
  1339. cmGeneratorTarget*
  1340. cmGlobalGenerator::GetGeneratorTarget(cmTarget const* t) const
  1341. {
  1342. cmGeneratorTargetsType::const_iterator ti = this->GeneratorTargets.find(t);
  1343. if(ti == this->GeneratorTargets.end())
  1344. {
  1345. this->CMakeInstance->IssueMessage(
  1346. cmake::INTERNAL_ERROR, "Missing cmGeneratorTarget instance!",
  1347. cmListFileBacktrace());
  1348. return 0;
  1349. }
  1350. return ti->second;
  1351. }
  1352. //----------------------------------------------------------------------------
  1353. void cmGlobalGenerator::ComputeTargetObjects(cmGeneratorTarget*) const
  1354. {
  1355. // Implemented in generator subclasses that need this.
  1356. }
  1357. void cmGlobalGenerator::CheckLocalGenerators()
  1358. {
  1359. std::map<cmStdString, cmStdString> notFoundMap;
  1360. // std::set<cmStdString> notFoundMap;
  1361. // after it is all done do a ConfigureFinalPass
  1362. cmCacheManager* manager = 0;
  1363. for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
  1364. {
  1365. manager = this->LocalGenerators[i]->GetMakefile()->GetCacheManager();
  1366. this->LocalGenerators[i]->ConfigureFinalPass();
  1367. cmTargets &targets =
  1368. this->LocalGenerators[i]->GetMakefile()->GetTargets();
  1369. for (cmTargets::iterator l = targets.begin();
  1370. l != targets.end(); l++)
  1371. {
  1372. if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  1373. {
  1374. continue;
  1375. }
  1376. const cmTarget::LinkLibraryVectorType& libs =
  1377. l->second.GetOriginalLinkLibraries();
  1378. for(cmTarget::LinkLibraryVectorType::const_iterator lib = libs.begin();
  1379. lib != libs.end(); ++lib)
  1380. {
  1381. if(lib->first.size() > 9 &&
  1382. cmSystemTools::IsNOTFOUND(lib->first.c_str()))
  1383. {
  1384. std::string varName = lib->first.substr(0, lib->first.size()-9);
  1385. cmCacheManager::CacheIterator it =
  1386. manager->GetCacheIterator(varName.c_str());
  1387. if(it.GetPropertyAsBool("ADVANCED"))
  1388. {
  1389. varName += " (ADVANCED)";
  1390. }
  1391. std::string text = notFoundMap[varName];
  1392. text += "\n linked by target \"";
  1393. text += l->second.GetName();
  1394. text += "\" in directory ";
  1395. text+=this->LocalGenerators[i]->GetMakefile()->GetCurrentDirectory();
  1396. notFoundMap[varName] = text;
  1397. }
  1398. }
  1399. std::vector<std::string> incs;
  1400. const char *incDirProp = l->second.GetProperty("INCLUDE_DIRECTORIES");
  1401. if (!incDirProp)
  1402. {
  1403. continue;
  1404. }
  1405. std::string incDirs = cmGeneratorExpression::Preprocess(incDirProp,
  1406. cmGeneratorExpression::StripAllGeneratorExpressions);
  1407. cmSystemTools::ExpandListArgument(incDirs.c_str(), incs);
  1408. for( std::vector<std::string>::const_iterator incDir = incs.begin();
  1409. incDir != incs.end(); ++incDir)
  1410. {
  1411. if(incDir->size() > 9 &&
  1412. cmSystemTools::IsNOTFOUND(incDir->c_str()))
  1413. {
  1414. std::string varName = incDir->substr(0, incDir->size()-9);
  1415. cmCacheManager::CacheIterator it =
  1416. manager->GetCacheIterator(varName.c_str());
  1417. if(it.GetPropertyAsBool("ADVANCED"))
  1418. {
  1419. varName += " (ADVANCED)";
  1420. }
  1421. std::string text = notFoundMap[varName];
  1422. text += "\n used as include directory in directory ";
  1423. text += this->LocalGenerators[i]
  1424. ->GetMakefile()->GetCurrentDirectory();
  1425. notFoundMap[varName] = text;
  1426. }
  1427. }
  1428. }
  1429. this->CMakeInstance->UpdateProgress
  1430. ("Configuring", 0.9f+0.1f*(static_cast<float>(i)+1.0f)/
  1431. static_cast<float>(this->LocalGenerators.size()));
  1432. }
  1433. if(notFoundMap.size())
  1434. {
  1435. std::string notFoundVars;
  1436. for(std::map<cmStdString, cmStdString>::const_iterator
  1437. ii = notFoundMap.begin();
  1438. ii != notFoundMap.end();
  1439. ++ii)
  1440. {
  1441. notFoundVars += ii->first;
  1442. notFoundVars += ii->second;
  1443. notFoundVars += "\n";
  1444. }
  1445. cmSystemTools::Error("The following variables are used in this project, "
  1446. "but they are set to NOTFOUND.\n"
  1447. "Please set them or make sure they are set and "
  1448. "tested correctly in the CMake files:\n",
  1449. notFoundVars.c_str());
  1450. }
  1451. }
  1452. int cmGlobalGenerator::TryCompile(const char *srcdir, const char *bindir,
  1453. const char *projectName,
  1454. const char *target, bool fast,
  1455. std::string *output, cmMakefile *mf)
  1456. {
  1457. // if this is not set, then this is a first time configure
  1458. // and there is a good chance that the try compile stuff will
  1459. // take the bulk of the time, so try and guess some progress
  1460. // by getting closer and closer to 100 without actually getting there.
  1461. if (!this->CMakeInstance->GetCacheManager()->GetCacheValue
  1462. ("CMAKE_NUMBER_OF_LOCAL_GENERATORS"))
  1463. {
  1464. // If CMAKE_NUMBER_OF_LOCAL_GENERATORS is not set
  1465. // we are in the first time progress and we have no
  1466. // idea how long it will be. So, just move 1/10th of the way
  1467. // there each time, and don't go over 95%
  1468. this->FirstTimeProgress += ((1.0f - this->FirstTimeProgress) /30.0f);
  1469. if(this->FirstTimeProgress > 0.95f)
  1470. {
  1471. this->FirstTimeProgress = 0.95f;
  1472. }
  1473. this->CMakeInstance->UpdateProgress("Configuring",
  1474. this->FirstTimeProgress);
  1475. }
  1476. std::string newTarget;
  1477. if (target && strlen(target))
  1478. {
  1479. newTarget += target;
  1480. #if 0
  1481. #if defined(_WIN32) || defined(__CYGWIN__)
  1482. std::string tmp = target;
  1483. // if the target does not already end in . something
  1484. // then assume .exe
  1485. if(tmp.size() < 4 || tmp[tmp.size()-4] != '.')
  1486. {
  1487. newTarget += ".exe";
  1488. }
  1489. #endif // WIN32
  1490. #endif
  1491. }
  1492. const char* config = mf->GetDefinition("CMAKE_TRY_COMPILE_CONFIGURATION");
  1493. return this->Build(srcdir,bindir,projectName,
  1494. newTarget.c_str(),
  1495. output,0,config,false,fast,
  1496. this->TryCompileTimeout);
  1497. }
  1498. void cmGlobalGenerator::GenerateBuildCommand(
  1499. std::vector<std::string>& makeCommand, const char*, const char*, const char*,
  1500. const char*, const char*, bool, std::vector<std::string> const&)
  1501. {
  1502. makeCommand.push_back(
  1503. "cmGlobalGenerator::GenerateBuildCommand not implemented");
  1504. }
  1505. int cmGlobalGenerator::Build(
  1506. const char *, const char *bindir,
  1507. const char *projectName, const char *target,
  1508. std::string *output,
  1509. const char *makeCommandCSTR,
  1510. const char *config,
  1511. bool clean, bool fast,
  1512. double timeout,
  1513. cmSystemTools::OutputOption outputflag,
  1514. std::vector<std::string> const& nativeOptions)
  1515. {
  1516. /**
  1517. * Run an executable command and put the stdout in output.
  1518. */
  1519. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1520. cmSystemTools::ChangeDirectory(bindir);
  1521. if(output)
  1522. {
  1523. *output += "Change Dir: ";
  1524. *output += bindir;
  1525. *output += "\n";
  1526. }
  1527. int retVal;
  1528. bool hideconsole = cmSystemTools::GetRunCommandHideConsole();
  1529. cmSystemTools::SetRunCommandHideConsole(true);
  1530. std::string outputBuffer;
  1531. std::string* outputPtr = 0;
  1532. if(output)
  1533. {
  1534. outputPtr = &outputBuffer;
  1535. }
  1536. // should we do a clean first?
  1537. if (clean)
  1538. {
  1539. std::vector<std::string> cleanCommand;
  1540. this->GenerateBuildCommand(cleanCommand, makeCommandCSTR, projectName,
  1541. bindir, "clean", config, fast);
  1542. if(output)
  1543. {
  1544. *output += "\nRun Clean Command:";
  1545. *output += cmSystemTools::PrintSingleCommand(cleanCommand);
  1546. *output += "\n";
  1547. }
  1548. if (!cmSystemTools::RunSingleCommand(cleanCommand, outputPtr,
  1549. &retVal, 0, outputflag, timeout))
  1550. {
  1551. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1552. cmSystemTools::Error("Generator: execution of make clean failed.");
  1553. if (output)
  1554. {
  1555. *output += *outputPtr;
  1556. *output += "\nGenerator: execution of make clean failed.\n";
  1557. }
  1558. // return to the original directory
  1559. cmSystemTools::ChangeDirectory(cwd.c_str());
  1560. return 1;
  1561. }
  1562. if (output)
  1563. {
  1564. *output += *outputPtr;
  1565. }
  1566. }
  1567. // now build
  1568. std::vector<std::string> makeCommand;
  1569. this->GenerateBuildCommand(makeCommand, makeCommandCSTR, projectName,
  1570. bindir, target, config, fast, nativeOptions);
  1571. std::string makeCommandStr = cmSystemTools::PrintSingleCommand(makeCommand);
  1572. if(output)
  1573. {
  1574. *output += "\nRun Build Command:";
  1575. *output += makeCommandStr;
  1576. *output += "\n";
  1577. }
  1578. if (!cmSystemTools::RunSingleCommand(makeCommand, outputPtr,
  1579. &retVal, 0, outputflag, timeout))
  1580. {
  1581. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1582. cmSystemTools::Error
  1583. ("Generator: execution of make failed. Make command was: ",
  1584. makeCommandStr.c_str());
  1585. if (output)
  1586. {
  1587. *output += *outputPtr;
  1588. *output += "\nGenerator: execution of make failed. Make command was: "
  1589. + makeCommandStr + "\n";
  1590. }
  1591. // return to the original directory
  1592. cmSystemTools::ChangeDirectory(cwd.c_str());
  1593. return 1;
  1594. }
  1595. if (output)
  1596. {
  1597. *output += *outputPtr;
  1598. }
  1599. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1600. // The SGI MipsPro 7.3 compiler does not return an error code when
  1601. // the source has a #error in it! This is a work-around for such
  1602. // compilers.
  1603. if((retVal == 0) && (output->find("#error") != std::string::npos))
  1604. {
  1605. retVal = 1;
  1606. }
  1607. cmSystemTools::ChangeDirectory(cwd.c_str());
  1608. return retVal;
  1609. }
  1610. //----------------------------------------------------------------------------
  1611. std::string cmGlobalGenerator::GenerateCMakeBuildCommand(
  1612. const char* target, const char* config, const char* native,
  1613. bool ignoreErrors)
  1614. {
  1615. std::string makeCommand = cmSystemTools::GetCMakeCommand();
  1616. makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
  1617. makeCommand += " --build .";
  1618. if(config && *config)
  1619. {
  1620. makeCommand += " --config \"";
  1621. makeCommand += config;
  1622. makeCommand += "\"";
  1623. }
  1624. if(target && *target)
  1625. {
  1626. makeCommand += " --target \"";
  1627. makeCommand += target;
  1628. makeCommand += "\"";
  1629. }
  1630. const char* sep = " -- ";
  1631. if(ignoreErrors)
  1632. {
  1633. const char* iflag = this->GetBuildIgnoreErrorsFlag();
  1634. if(iflag && *iflag)
  1635. {
  1636. makeCommand += sep;
  1637. makeCommand += iflag;
  1638. sep = " ";
  1639. }
  1640. }
  1641. if(native && *native)
  1642. {
  1643. makeCommand += sep;
  1644. makeCommand += native;
  1645. }
  1646. return makeCommand;
  1647. }
  1648. //----------------------------------------------------------------------------
  1649. void cmGlobalGenerator::AddLocalGenerator(cmLocalGenerator *lg)
  1650. {
  1651. this->LocalGenerators.push_back(lg);
  1652. // update progress
  1653. // estimate how many lg there will be
  1654. const char *numGenC =
  1655. this->CMakeInstance->GetCacheManager()->GetCacheValue
  1656. ("CMAKE_NUMBER_OF_LOCAL_GENERATORS");
  1657. if (!numGenC)
  1658. {
  1659. // If CMAKE_NUMBER_OF_LOCAL_GENERATORS is not set
  1660. // we are in the first time progress and we have no
  1661. // idea how long it will be. So, just move half way
  1662. // there each time, and don't go over 95%
  1663. this->FirstTimeProgress += ((1.0f - this->FirstTimeProgress) /30.0f);
  1664. if(this->FirstTimeProgress > 0.95f)
  1665. {
  1666. this->FirstTimeProgress = 0.95f;
  1667. }
  1668. this->CMakeInstance->UpdateProgress("Configuring",
  1669. this->FirstTimeProgress);
  1670. return;
  1671. }
  1672. int numGen = atoi(numGenC);
  1673. float prog = 0.9f*static_cast<float>(this->LocalGenerators.size())/
  1674. static_cast<float>(numGen);
  1675. if (prog > 0.9f)
  1676. {
  1677. prog = 0.9f;
  1678. }
  1679. this->CMakeInstance->UpdateProgress("Configuring", prog);
  1680. }
  1681. void cmGlobalGenerator::AddInstallComponent(const char* component)
  1682. {
  1683. if(component && *component)
  1684. {
  1685. this->InstallComponents.insert(component);
  1686. }
  1687. }
  1688. void cmGlobalGenerator::EnableInstallTarget()
  1689. {
  1690. this->InstallTargetEnabled = true;
  1691. }
  1692. cmLocalGenerator *cmGlobalGenerator::CreateLocalGenerator()
  1693. {
  1694. cmLocalGenerator *lg = new cmLocalGenerator;
  1695. lg->SetGlobalGenerator(this);
  1696. return lg;
  1697. }
  1698. void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator *gen,
  1699. cmMakefile* mf)
  1700. {
  1701. this->SetConfiguredFilesPath(gen);
  1702. this->TryCompileOuterMakefile = mf;
  1703. const char* make =
  1704. gen->GetCMakeInstance()->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
  1705. this->GetCMakeInstance()->AddCacheEntry("CMAKE_MAKE_PROGRAM", make,
  1706. "make program",
  1707. cmCacheManager::FILEPATH);
  1708. // copy the enabled languages
  1709. this->LanguageEnabled = gen->LanguageEnabled;
  1710. this->LanguagesReady = gen->LanguagesReady;
  1711. this->ExtensionToLanguage = gen->ExtensionToLanguage;
  1712. this->IgnoreExtensions = gen->IgnoreExtensions;
  1713. this->LanguageToOutputExtension = gen->LanguageToOutputExtension;
  1714. this->LanguageToLinkerPreference = gen->LanguageToLinkerPreference;
  1715. this->OutputExtensions = gen->OutputExtensions;
  1716. }
  1717. //----------------------------------------------------------------------------
  1718. void cmGlobalGenerator::SetConfiguredFilesPath(cmGlobalGenerator* gen)
  1719. {
  1720. if(!gen->ConfiguredFilesPath.empty())
  1721. {
  1722. this->ConfiguredFilesPath = gen->ConfiguredFilesPath;
  1723. }
  1724. else
  1725. {
  1726. this->ConfiguredFilesPath = gen->CMakeInstance->GetHomeOutputDirectory();
  1727. this->ConfiguredFilesPath += cmake::GetCMakeFilesDirectory();
  1728. }
  1729. }
  1730. bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
  1731. cmLocalGenerator* gen)
  1732. {
  1733. if(!gen || gen == root)
  1734. {
  1735. // No directory excludes itself.
  1736. return false;
  1737. }
  1738. if(gen->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  1739. {
  1740. // This directory is excluded from its parent.
  1741. return true;
  1742. }
  1743. // This directory is included in its parent. Check whether the
  1744. // parent is excluded.
  1745. return this->IsExcluded(root, gen->GetParent());
  1746. }
  1747. bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
  1748. cmTarget& target)
  1749. {
  1750. if(target.GetType() == cmTarget::INTERFACE_LIBRARY
  1751. || target.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  1752. {
  1753. // This target is excluded from its directory.
  1754. return true;
  1755. }
  1756. else
  1757. {
  1758. // This target is included in its directory. Check whether the
  1759. // directory is excluded.
  1760. return this->IsExcluded(root, target.GetMakefile()->GetLocalGenerator());
  1761. }
  1762. }
  1763. void cmGlobalGenerator::GetEnabledLanguages(std::vector<std::string>& lang)
  1764. {
  1765. for(std::map<cmStdString, bool>::iterator i =
  1766. this->LanguageEnabled.begin(); i != this->LanguageEnabled.end(); ++i)
  1767. {
  1768. lang.push_back(i->first);
  1769. }
  1770. }
  1771. int cmGlobalGenerator::GetLinkerPreference(const char* lang)
  1772. {
  1773. std::map<cmStdString, int>::const_iterator it =
  1774. this->LanguageToLinkerPreference.find(lang);
  1775. if (it != this->LanguageToLinkerPreference.end())
  1776. {
  1777. return it->second;
  1778. }
  1779. return 0;
  1780. }
  1781. void cmGlobalGenerator::FillProjectMap()
  1782. {
  1783. this->ProjectMap.clear(); // make sure we start with a clean map
  1784. unsigned int i;
  1785. for(i = 0; i < this->LocalGenerators.size(); ++i)
  1786. {
  1787. // for each local generator add all projects
  1788. cmLocalGenerator *lg = this->LocalGenerators[i];
  1789. std::string name;
  1790. do
  1791. {
  1792. if (name != lg->GetMakefile()->GetProjectName())
  1793. {
  1794. name = lg->GetMakefile()->GetProjectName();
  1795. this->ProjectMap[name].push_back(this->LocalGenerators[i]);
  1796. }
  1797. lg = lg->GetParent();
  1798. }
  1799. while (lg);
  1800. }
  1801. }
  1802. // Build a map that contains a the set of targets used by each local
  1803. // generator directory level.
  1804. void cmGlobalGenerator::FillLocalGeneratorToTargetMap()
  1805. {
  1806. this->LocalGeneratorToTargetMap.clear();
  1807. // Loop over all targets in all local generators.
  1808. for(std::vector<cmLocalGenerator*>::const_iterator
  1809. lgi = this->LocalGenerators.begin();
  1810. lgi != this->LocalGenerators.end(); ++lgi)
  1811. {
  1812. cmLocalGenerator* lg = *lgi;
  1813. cmMakefile* mf = lg->GetMakefile();
  1814. cmTargets& targets = mf->GetTargets();
  1815. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  1816. {
  1817. cmTarget& target = t->second;
  1818. // Consider the directory containing the target and all its
  1819. // parents until something excludes the target.
  1820. for(cmLocalGenerator* clg = lg; clg && !this->IsExcluded(clg, target);
  1821. clg = clg->GetParent())
  1822. {
  1823. // This local generator includes the target.
  1824. std::set<cmTarget const*>& targetSet =
  1825. this->LocalGeneratorToTargetMap[clg];
  1826. targetSet.insert(&target);
  1827. // Add dependencies of the included target. An excluded
  1828. // target may still be included if it is a dependency of a
  1829. // non-excluded target.
  1830. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(target);
  1831. for(TargetDependSet::const_iterator ti = tgtdeps.begin();
  1832. ti != tgtdeps.end(); ++ti)
  1833. {
  1834. cmTarget const* ttt = *ti;
  1835. targetSet.insert(ttt);
  1836. }
  1837. }
  1838. }
  1839. }
  1840. }
  1841. ///! Find a local generator by its startdirectory
  1842. cmLocalGenerator* cmGlobalGenerator::FindLocalGenerator(const char* start_dir)
  1843. {
  1844. std::vector<cmLocalGenerator*>* gens = &this->LocalGenerators;
  1845. for(unsigned int i = 0; i < gens->size(); ++i)
  1846. {
  1847. std::string sd = (*gens)[i]->GetMakefile()->GetStartDirectory();
  1848. if (sd == start_dir)
  1849. {
  1850. return (*gens)[i];
  1851. }
  1852. }
  1853. return 0;
  1854. }
  1855. //----------------------------------------------------------------------------
  1856. void cmGlobalGenerator::AddAlias(const char *name, cmTarget *tgt)
  1857. {
  1858. this->AliasTargets[name] = tgt;
  1859. }
  1860. //----------------------------------------------------------------------------
  1861. bool cmGlobalGenerator::IsAlias(const char *name) const
  1862. {
  1863. return this->AliasTargets.find(name) != this->AliasTargets.end();
  1864. }
  1865. //----------------------------------------------------------------------------
  1866. cmTarget*
  1867. cmGlobalGenerator::FindTarget(const char* project, const char* name,
  1868. bool excludeAliases) const
  1869. {
  1870. // if project specific
  1871. if(project)
  1872. {
  1873. std::map<cmStdString, std::vector<cmLocalGenerator*> >::const_iterator
  1874. gens = this->ProjectMap.find(project);
  1875. for(unsigned int i = 0; i < gens->second.size(); ++i)
  1876. {
  1877. cmTarget* ret = (gens->second)[i]->GetMakefile()->FindTarget(name,
  1878. excludeAliases);
  1879. if(ret)
  1880. {
  1881. return ret;
  1882. }
  1883. }
  1884. }
  1885. // if all projects/directories
  1886. else
  1887. {
  1888. if (!excludeAliases)
  1889. {
  1890. std::map<cmStdString, cmTarget*>::const_iterator ai
  1891. = this->AliasTargets.find(name);
  1892. if (ai != this->AliasTargets.end())
  1893. {
  1894. return ai->second;
  1895. }
  1896. }
  1897. std::map<cmStdString,cmTarget *>::const_iterator i =
  1898. this->TotalTargets.find ( name );
  1899. if ( i != this->TotalTargets.end() )
  1900. {
  1901. return i->second;
  1902. }
  1903. i = this->ImportedTargets.find(name);
  1904. if ( i != this->ImportedTargets.end() )
  1905. {
  1906. return i->second;
  1907. }
  1908. }
  1909. return 0;
  1910. }
  1911. //----------------------------------------------------------------------------
  1912. bool
  1913. cmGlobalGenerator::NameResolvesToFramework(const std::string& libname) const
  1914. {
  1915. if(cmSystemTools::IsPathToFramework(libname.c_str()))
  1916. {
  1917. return true;
  1918. }
  1919. if(cmTarget* tgt = this->FindTarget(0, libname.c_str()))
  1920. {
  1921. if(tgt->IsFrameworkOnApple())
  1922. {
  1923. return true;
  1924. }
  1925. }
  1926. return false;
  1927. }
  1928. //----------------------------------------------------------------------------
  1929. inline std::string removeQuotes(const std::string& s)
  1930. {
  1931. if(s[0] == '\"' && s[s.size()-1] == '\"')
  1932. {
  1933. return s.substr(1, s.size()-2);
  1934. }
  1935. return s;
  1936. }
  1937. void cmGlobalGenerator::SetCMakeInstance(cmake* cm)
  1938. {
  1939. // Store a pointer to the cmake object instance.
  1940. this->CMakeInstance = cm;
  1941. }
  1942. void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
  1943. {
  1944. cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
  1945. const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
  1946. const char* cmakeCommand = mf->GetRequiredDefinition("CMAKE_COMMAND");
  1947. // CPack
  1948. std::string workingDir = mf->GetStartOutputDirectory();
  1949. cmCustomCommandLines cpackCommandLines;
  1950. std::vector<std::string> depends;
  1951. cmCustomCommandLine singleLine;
  1952. singleLine.push_back(cmSystemTools::GetCPackCommand());
  1953. if ( cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.' )
  1954. {
  1955. singleLine.push_back("-C");
  1956. singleLine.push_back(cmakeCfgIntDir);
  1957. }
  1958. singleLine.push_back("--config");
  1959. std::string configFile = mf->GetStartOutputDirectory();;
  1960. configFile += "/CPackConfig.cmake";
  1961. std::string relConfigFile = "./CPackConfig.cmake";
  1962. singleLine.push_back(relConfigFile);
  1963. cpackCommandLines.push_back(singleLine);
  1964. if ( this->GetPreinstallTargetName() )
  1965. {
  1966. depends.push_back(this->GetPreinstallTargetName());
  1967. }
  1968. else
  1969. {
  1970. const char* noPackageAll =
  1971. mf->GetDefinition("CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY");
  1972. if(!noPackageAll || cmSystemTools::IsOff(noPackageAll))
  1973. {
  1974. depends.push_back(this->GetAllTargetName());
  1975. }
  1976. }
  1977. if(cmSystemTools::FileExists(configFile.c_str()))
  1978. {
  1979. (*targets)[this->GetPackageTargetName()]
  1980. = this->CreateGlobalTarget(this->GetPackageTargetName(),
  1981. "Run CPack packaging tool...",
  1982. &cpackCommandLines, depends,
  1983. workingDir.c_str());
  1984. }
  1985. // CPack source
  1986. const char* packageSourceTargetName = this->GetPackageSourceTargetName();
  1987. if ( packageSourceTargetName )
  1988. {
  1989. cpackCommandLines.erase(cpackCommandLines.begin(),
  1990. cpackCommandLines.end());
  1991. singleLine.erase(singleLine.begin(), singleLine.end());
  1992. depends.erase(depends.begin(), depends.end());
  1993. singleLine.push_back(cmSystemTools::GetCPackCommand());
  1994. singleLine.push_back("--config");
  1995. configFile = mf->GetStartOutputDirectory();;
  1996. configFile += "/CPackSourceConfig.cmake";
  1997. relConfigFile = "./CPackSourceConfig.cmake";
  1998. singleLine.push_back(relConfigFile);
  1999. if(cmSystemTools::FileExists(configFile.c_str()))
  2000. {
  2001. singleLine.push_back(configFile);
  2002. cpackCommandLines.push_back(singleLine);
  2003. (*targets)[packageSourceTargetName]
  2004. = this->CreateGlobalTarget(packageSourceTargetName,
  2005. "Run CPack packaging tool for source...",
  2006. &cpackCommandLines, depends,
  2007. workingDir.c_str()
  2008. );
  2009. }
  2010. }
  2011. // Test
  2012. if(mf->IsOn("CMAKE_TESTING_ENABLED"))
  2013. {
  2014. cpackCommandLines.erase(cpackCommandLines.begin(),
  2015. cpackCommandLines.end());
  2016. singleLine.erase(singleLine.begin(), singleLine.end());
  2017. depends.erase(depends.begin(), depends.end());
  2018. singleLine.push_back(cmSystemTools::GetCTestCommand());
  2019. singleLine.push_back("--force-new-ctest-process");
  2020. if(cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.')
  2021. {
  2022. singleLine.push_back("-C");
  2023. singleLine.push_back(cmakeCfgIntDir);
  2024. }
  2025. else // TODO: This is a hack. Should be something to do with the generator
  2026. {
  2027. singleLine.push_back("$(ARGS)");
  2028. }
  2029. cpackCommandLines.push_back(singleLine);
  2030. (*targets)[this->GetTestTargetName()]
  2031. = this->CreateGlobalTarget(this->GetTestTargetName(),
  2032. "Running tests...", &cpackCommandLines, depends, 0);
  2033. }
  2034. //Edit Cache
  2035. const char* editCacheTargetName = this->GetEditCacheTargetName();
  2036. if ( editCacheTargetName )
  2037. {
  2038. cpackCommandLines.erase(cpackCommandLines.begin(),
  2039. cpackCommandLines.end());
  2040. singleLine.erase(singleLine.begin(), singleLine.end());
  2041. depends.erase(depends.begin(), depends.end());
  2042. // Use generator preference for the edit_cache rule if it is defined.
  2043. std::string edit_cmd = this->GetEditCacheCommand();
  2044. if (!edit_cmd.empty())
  2045. {
  2046. singleLine.push_back(edit_cmd);
  2047. singleLine.push_back("-H$(CMAKE_SOURCE_DIR)");
  2048. singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
  2049. cpackCommandLines.push_back(singleLine);
  2050. (*targets)[editCacheTargetName] =
  2051. this->CreateGlobalTarget(
  2052. editCacheTargetName, "Running CMake cache editor...",
  2053. &cpackCommandLines, depends, 0);
  2054. }
  2055. else
  2056. {
  2057. singleLine.push_back(cmakeCommand);
  2058. singleLine.push_back("-E");
  2059. singleLine.push_back("echo");
  2060. singleLine.push_back("No interactive CMake dialog available.");
  2061. cpackCommandLines.push_back(singleLine);
  2062. (*targets)[editCacheTargetName] =
  2063. this->CreateGlobalTarget(
  2064. editCacheTargetName,
  2065. "No interactive CMake dialog available...",
  2066. &cpackCommandLines, depends, 0);
  2067. }
  2068. }
  2069. //Rebuild Cache
  2070. const char* rebuildCacheTargetName = this->GetRebuildCacheTargetName();
  2071. if ( rebuildCacheTargetName )
  2072. {
  2073. cpackCommandLines.erase(cpackCommandLines.begin(),
  2074. cpackCommandLines.end());
  2075. singleLine.erase(singleLine.begin(), singleLine.end());
  2076. depends.erase(depends.begin(), depends.end());
  2077. singleLine.push_back(cmakeCommand);
  2078. singleLine.push_back("-H$(CMAKE_SOURCE_DIR)");
  2079. singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
  2080. cpackCommandLines.push_back(singleLine);
  2081. (*targets)[rebuildCacheTargetName] =
  2082. this->CreateGlobalTarget(
  2083. rebuildCacheTargetName, "Running CMake to regenerate build system...",
  2084. &cpackCommandLines, depends, 0);
  2085. }
  2086. //Install
  2087. if(this->InstallTargetEnabled)
  2088. {
  2089. if(!cmakeCfgIntDir || !*cmakeCfgIntDir || cmakeCfgIntDir[0] == '.')
  2090. {
  2091. std::set<cmStdString>* componentsSet = &this->InstallComponents;
  2092. cpackCommandLines.erase(cpackCommandLines.begin(),
  2093. cpackCommandLines.end());
  2094. depends.erase(depends.begin(), depends.end());
  2095. cmOStringStream ostr;
  2096. if ( componentsSet->size() > 0 )
  2097. {
  2098. ostr << "Available install components are:";
  2099. std::set<cmStdString>::iterator it;
  2100. for (
  2101. it = componentsSet->begin();
  2102. it != componentsSet->end();
  2103. ++ it )
  2104. {
  2105. ostr << " \"" << it->c_str() << "\"";
  2106. }
  2107. }
  2108. else
  2109. {
  2110. ostr << "Only default component available";
  2111. }
  2112. singleLine.push_back(ostr.str().c_str());
  2113. (*targets)["list_install_components"]
  2114. = this->CreateGlobalTarget("list_install_components",
  2115. ostr.str().c_str(),
  2116. &cpackCommandLines, depends, 0);
  2117. }
  2118. std::string cmd = cmakeCommand;
  2119. cpackCommandLines.erase(cpackCommandLines.begin(),
  2120. cpackCommandLines.end());
  2121. singleLine.erase(singleLine.begin(), singleLine.end());
  2122. depends.erase(depends.begin(), depends.end());
  2123. if ( this->GetPreinstallTargetName() )
  2124. {
  2125. depends.push_back(this->GetPreinstallTargetName());
  2126. }
  2127. else
  2128. {
  2129. const char* noall =
  2130. mf->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
  2131. if(!noall || cmSystemTools::IsOff(noall))
  2132. {
  2133. depends.push_back(this->GetAllTargetName());
  2134. }
  2135. }
  2136. if(mf->GetDefinition("CMake_BINARY_DIR"))
  2137. {
  2138. // We are building CMake itself. We cannot use the original
  2139. // executable to install over itself. The generator will
  2140. // automatically convert this name to the build-time location.
  2141. cmd = "cmake";
  2142. }
  2143. singleLine.push_back(cmd.c_str());
  2144. if ( cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.' )
  2145. {
  2146. std::string cfgArg = "-DBUILD_TYPE=";
  2147. cfgArg += mf->GetDefinition("CMAKE_CFG_INTDIR");
  2148. singleLine.push_back(cfgArg);
  2149. }
  2150. singleLine.push_back("-P");
  2151. singleLine.push_back("cmake_install.cmake");
  2152. cpackCommandLines.push_back(singleLine);
  2153. (*targets)[this->GetInstallTargetName()] =
  2154. this->CreateGlobalTarget(
  2155. this->GetInstallTargetName(), "Install the project...",
  2156. &cpackCommandLines, depends, 0);
  2157. // install_local
  2158. if(const char* install_local = this->GetInstallLocalTargetName())
  2159. {
  2160. cmCustomCommandLine localCmdLine = singleLine;
  2161. localCmdLine.insert(localCmdLine.begin()+1,
  2162. "-DCMAKE_INSTALL_LOCAL_ONLY=1");
  2163. cpackCommandLines.erase(cpackCommandLines.begin(),
  2164. cpackCommandLines.end());
  2165. cpackCommandLines.push_back(localCmdLine);
  2166. (*targets)[install_local] =
  2167. this->CreateGlobalTarget(
  2168. install_local, "Installing only the local directory...",
  2169. &cpackCommandLines, depends, 0);
  2170. }
  2171. // install_strip
  2172. const char* install_strip = this->GetInstallStripTargetName();
  2173. if((install_strip !=0) && (mf->IsSet("CMAKE_STRIP")))
  2174. {
  2175. cmCustomCommandLine stripCmdLine = singleLine;
  2176. stripCmdLine.insert(stripCmdLine.begin()+1,"-DCMAKE_INSTALL_DO_STRIP=1");
  2177. cpackCommandLines.erase(cpackCommandLines.begin(),
  2178. cpackCommandLines.end());
  2179. cpackCommandLines.push_back(stripCmdLine);
  2180. (*targets)[install_strip] =
  2181. this->CreateGlobalTarget(
  2182. install_strip, "Installing the project stripped...",
  2183. &cpackCommandLines, depends, 0);
  2184. }
  2185. }
  2186. }
  2187. //----------------------------------------------------------------------------
  2188. const char* cmGlobalGenerator::GetPredefinedTargetsFolder()
  2189. {
  2190. const char* prop =
  2191. this->GetCMakeInstance()->GetProperty("PREDEFINED_TARGETS_FOLDER");
  2192. if (prop)
  2193. {
  2194. return prop;
  2195. }
  2196. return "CMakePredefinedTargets";
  2197. }
  2198. //----------------------------------------------------------------------------
  2199. bool cmGlobalGenerator::UseFolderProperty()
  2200. {
  2201. const char* prop = this->GetCMakeInstance()->GetProperty("USE_FOLDERS");
  2202. // If this property is defined, let the setter turn this on or off...
  2203. //
  2204. if (prop)
  2205. {
  2206. return cmSystemTools::IsOn(prop);
  2207. }
  2208. // By default, this feature is OFF, since it is not supported in the
  2209. // Visual Studio Express editions until VS11:
  2210. //
  2211. return false;
  2212. }
  2213. //----------------------------------------------------------------------------
  2214. void cmGlobalGenerator::EnableMinGWLanguage(cmMakefile *mf)
  2215. {
  2216. this->FindMakeProgram(mf);
  2217. std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  2218. std::vector<std::string> locations;
  2219. locations.push_back(cmSystemTools::GetProgramPath(makeProgram.c_str()));
  2220. locations.push_back("/mingw/bin");
  2221. locations.push_back("c:/mingw/bin");
  2222. std::string tgcc = cmSystemTools::FindProgram("gcc", locations);
  2223. std::string gcc = "gcc.exe";
  2224. if(tgcc.size())
  2225. {
  2226. gcc = tgcc;
  2227. }
  2228. std::string tgxx = cmSystemTools::FindProgram("g++", locations);
  2229. std::string gxx = "g++.exe";
  2230. if(tgxx.size())
  2231. {
  2232. gxx = tgxx;
  2233. }
  2234. std::string trc = cmSystemTools::FindProgram("windres", locations);
  2235. std::string rc = "windres.exe";
  2236. if(trc.size())
  2237. {
  2238. rc = trc;
  2239. }
  2240. mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str());
  2241. mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str());
  2242. mf->AddDefinition("CMAKE_GENERATOR_RC", rc.c_str());
  2243. }
  2244. //----------------------------------------------------------------------------
  2245. cmTarget cmGlobalGenerator::CreateGlobalTarget(
  2246. const char* name, const char* message,
  2247. const cmCustomCommandLines* commandLines,
  2248. std::vector<std::string> depends,
  2249. const char* workingDirectory)
  2250. {
  2251. // Package
  2252. cmTarget target;
  2253. target.GetProperties().SetCMakeInstance(this->CMakeInstance);
  2254. target.SetType(cmTarget::GLOBAL_TARGET, name);
  2255. target.SetProperty("EXCLUDE_FROM_ALL","TRUE");
  2256. std::vector<std::string> no_outputs;
  2257. std::vector<std::string> no_depends;
  2258. // Store the custom command in the target.
  2259. cmCustomCommand cc(0, no_outputs, no_depends, *commandLines, 0,
  2260. workingDirectory);
  2261. target.AddPostBuildCommand(cc);
  2262. target.SetProperty("EchoString", message);
  2263. std::vector<std::string>::iterator dit;
  2264. for ( dit = depends.begin(); dit != depends.end(); ++ dit )
  2265. {
  2266. target.AddUtility(dit->c_str());
  2267. }
  2268. // Organize in the "predefined targets" folder:
  2269. //
  2270. if (this->UseFolderProperty())
  2271. {
  2272. target.SetProperty("FOLDER", this->GetPredefinedTargetsFolder());
  2273. }
  2274. return target;
  2275. }
  2276. //----------------------------------------------------------------------------
  2277. std::string
  2278. cmGlobalGenerator::GenerateRuleFile(std::string const& output) const
  2279. {
  2280. std::string ruleFile = output;
  2281. ruleFile += ".rule";
  2282. const char* dir = this->GetCMakeCFGIntDir();
  2283. if(dir && dir[0] == '$')
  2284. {
  2285. cmSystemTools::ReplaceString(ruleFile, dir,
  2286. cmake::GetCMakeFilesDirectory());
  2287. }
  2288. return ruleFile;
  2289. }
  2290. //----------------------------------------------------------------------------
  2291. std::string cmGlobalGenerator::GetSharedLibFlagsForLanguage(
  2292. std::string const& l)
  2293. {
  2294. if(this->LanguageToOriginalSharedLibFlags.count(l) > 0)
  2295. {
  2296. return this->LanguageToOriginalSharedLibFlags[l];
  2297. }
  2298. return "";
  2299. }
  2300. //----------------------------------------------------------------------------
  2301. void cmGlobalGenerator::AppendDirectoryForConfig(const char*, const char*,
  2302. const char*, std::string&)
  2303. {
  2304. // Subclasses that support multiple configurations should implement
  2305. // this method to append the subdirectory for the given build
  2306. // configuration.
  2307. }
  2308. //----------------------------------------------------------------------------
  2309. cmGlobalGenerator::TargetDependSet const&
  2310. cmGlobalGenerator::GetTargetDirectDepends(cmTarget const& target)
  2311. {
  2312. return this->TargetDependencies[&target];
  2313. }
  2314. void cmGlobalGenerator::AddTarget(cmTarget* t)
  2315. {
  2316. if(t->IsImported())
  2317. {
  2318. this->ImportedTargets[t->GetName()] = t;
  2319. }
  2320. else
  2321. {
  2322. this->TotalTargets[t->GetName()] = t;
  2323. }
  2324. }
  2325. bool cmGlobalGenerator::IsReservedTarget(std::string const& name)
  2326. {
  2327. // The following is a list of targets reserved
  2328. // by one or more of the cmake generators.
  2329. // Adding additional targets to this list will require a policy!
  2330. const char* reservedTargets[] =
  2331. {
  2332. "all", "ALL_BUILD",
  2333. "help",
  2334. "install", "INSTALL",
  2335. "preinstall",
  2336. "clean",
  2337. "edit_cache",
  2338. "rebuild_cache",
  2339. "test", "RUN_TESTS",
  2340. "package", "PACKAGE",
  2341. "package_source",
  2342. "ZERO_CHECK",
  2343. 0
  2344. };
  2345. for(const char** reservedTarget = reservedTargets;
  2346. *reservedTarget; ++reservedTarget)
  2347. {
  2348. if(name == *reservedTarget) return true;
  2349. }
  2350. return false;
  2351. }
  2352. void cmGlobalGenerator::SetExternalMakefileProjectGenerator(
  2353. cmExternalMakefileProjectGenerator *extraGenerator)
  2354. {
  2355. this->ExtraGenerator = extraGenerator;
  2356. if (this->ExtraGenerator!=0)
  2357. {
  2358. this->ExtraGenerator->SetGlobalGenerator(this);
  2359. }
  2360. }
  2361. const char* cmGlobalGenerator::GetExtraGeneratorName() const
  2362. {
  2363. return this->ExtraGenerator==0 ? 0 : this->ExtraGenerator->GetName();
  2364. }
  2365. void cmGlobalGenerator::FileReplacedDuringGenerate(const std::string& filename)
  2366. {
  2367. this->FilesReplacedDuringGenerate.push_back(filename);
  2368. }
  2369. void
  2370. cmGlobalGenerator
  2371. ::GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames)
  2372. {
  2373. filenames.clear();
  2374. std::copy(
  2375. this->FilesReplacedDuringGenerate.begin(),
  2376. this->FilesReplacedDuringGenerate.end(),
  2377. std::back_inserter(filenames));
  2378. }
  2379. //----------------------------------------------------------------------------
  2380. void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets,
  2381. TargetDependSet& originalTargets,
  2382. cmLocalGenerator* root,
  2383. GeneratorVector const& generators)
  2384. {
  2385. // loop over all local generators
  2386. for(std::vector<cmLocalGenerator*>::const_iterator i = generators.begin();
  2387. i != generators.end(); ++i)
  2388. {
  2389. // check to make sure generator is not excluded
  2390. if(this->IsExcluded(root, *i))
  2391. {
  2392. continue;
  2393. }
  2394. cmMakefile* mf = (*i)->GetMakefile();
  2395. // Get the targets in the makefile
  2396. cmTargets &tgts = mf->GetTargets();
  2397. // loop over all the targets
  2398. for (cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  2399. {
  2400. cmTarget* target = &l->second;
  2401. if(this->IsRootOnlyTarget(target) &&
  2402. target->GetMakefile() != root->GetMakefile())
  2403. {
  2404. continue;
  2405. }
  2406. // put the target in the set of original targets
  2407. originalTargets.insert(target);
  2408. // Get the set of targets that depend on target
  2409. this->AddTargetDepends(target, projectTargets);
  2410. }
  2411. }
  2412. }
  2413. //----------------------------------------------------------------------------
  2414. bool cmGlobalGenerator::IsRootOnlyTarget(cmTarget* target)
  2415. {
  2416. return (target->GetType() == cmTarget::GLOBAL_TARGET ||
  2417. strcmp(target->GetName(), this->GetAllTargetName()) == 0);
  2418. }
  2419. //----------------------------------------------------------------------------
  2420. void cmGlobalGenerator::AddTargetDepends(cmTarget const* target,
  2421. TargetDependSet& projectTargets)
  2422. {
  2423. // add the target itself
  2424. if(projectTargets.insert(target).second)
  2425. {
  2426. // This is the first time we have encountered the target.
  2427. // Recursively follow its dependencies.
  2428. TargetDependSet const& ts = this->GetTargetDirectDepends(*target);
  2429. for(TargetDependSet::const_iterator i = ts.begin(); i != ts.end(); ++i)
  2430. {
  2431. cmTarget const* dtarget = *i;
  2432. this->AddTargetDepends(dtarget, projectTargets);
  2433. }
  2434. }
  2435. }
  2436. //----------------------------------------------------------------------------
  2437. void cmGlobalGenerator::AddToManifest(const char* config,
  2438. std::string const& f)
  2439. {
  2440. // Add to the main manifest for this configuration.
  2441. this->TargetManifest[config].insert(f);
  2442. // Add to the content listing for the file's directory.
  2443. std::string dir = cmSystemTools::GetFilenamePath(f);
  2444. std::string file = cmSystemTools::GetFilenameName(f);
  2445. this->DirectoryContentMap[dir].insert(file);
  2446. }
  2447. //----------------------------------------------------------------------------
  2448. std::set<cmStdString> const&
  2449. cmGlobalGenerator::GetDirectoryContent(std::string const& dir, bool needDisk)
  2450. {
  2451. DirectoryContent& dc = this->DirectoryContentMap[dir];
  2452. if(needDisk && !dc.LoadedFromDisk)
  2453. {
  2454. // Load the directory content from disk.
  2455. cmsys::Directory d;
  2456. if(d.Load(dir.c_str()))
  2457. {
  2458. unsigned long n = d.GetNumberOfFiles();
  2459. for(unsigned long i = 0; i < n; ++i)
  2460. {
  2461. const char* f = d.GetFile(i);
  2462. if(strcmp(f, ".") != 0 && strcmp(f, "..") != 0)
  2463. {
  2464. dc.insert(f);
  2465. }
  2466. }
  2467. }
  2468. dc.LoadedFromDisk = true;
  2469. }
  2470. return dc;
  2471. }
  2472. //----------------------------------------------------------------------------
  2473. void
  2474. cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs,
  2475. std::string const& content)
  2476. {
  2477. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2478. // Ignore if there are no outputs.
  2479. if(outputs.empty())
  2480. {
  2481. return;
  2482. }
  2483. // Compute a hash of the rule.
  2484. RuleHash hash;
  2485. {
  2486. unsigned char const* data =
  2487. reinterpret_cast<unsigned char const*>(content.c_str());
  2488. int length = static_cast<int>(content.length());
  2489. cmsysMD5* sum = cmsysMD5_New();
  2490. cmsysMD5_Initialize(sum);
  2491. cmsysMD5_Append(sum, data, length);
  2492. cmsysMD5_FinalizeHex(sum, hash.Data);
  2493. cmsysMD5_Delete(sum);
  2494. }
  2495. // Shorten the output name (in expected use case).
  2496. cmLocalGenerator* lg = this->GetLocalGenerators()[0];
  2497. std::string fname = lg->Convert(outputs[0].c_str(),
  2498. cmLocalGenerator::HOME_OUTPUT);
  2499. // Associate the hash with this output.
  2500. this->RuleHashes[fname] = hash;
  2501. #else
  2502. (void)outputs;
  2503. (void)content;
  2504. #endif
  2505. }
  2506. //----------------------------------------------------------------------------
  2507. void cmGlobalGenerator::CheckRuleHashes()
  2508. {
  2509. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2510. std::string home = this->GetCMakeInstance()->GetHomeOutputDirectory();
  2511. std::string pfile = home;
  2512. pfile += this->GetCMakeInstance()->GetCMakeFilesDirectory();
  2513. pfile += "/CMakeRuleHashes.txt";
  2514. this->CheckRuleHashes(pfile, home);
  2515. this->WriteRuleHashes(pfile);
  2516. #endif
  2517. }
  2518. //----------------------------------------------------------------------------
  2519. void cmGlobalGenerator::CheckRuleHashes(std::string const& pfile,
  2520. std::string const& home)
  2521. {
  2522. #if defined(_WIN32) || defined(__CYGWIN__)
  2523. cmsys::ifstream fin(pfile.c_str(), std::ios::in | std::ios::binary);
  2524. #else
  2525. cmsys::ifstream fin(pfile.c_str(), std::ios::in);
  2526. #endif
  2527. if(!fin)
  2528. {
  2529. return;
  2530. }
  2531. std::string line;
  2532. std::string fname;
  2533. while(cmSystemTools::GetLineFromStream(fin, line))
  2534. {
  2535. // Line format is a 32-byte hex string followed by a space
  2536. // followed by a file name (with no escaping).
  2537. // Skip blank and comment lines.
  2538. if(line.size() < 34 || line[0] == '#')
  2539. {
  2540. continue;
  2541. }
  2542. // Get the filename.
  2543. fname = line.substr(33, line.npos);
  2544. // Look for a hash for this file's rule.
  2545. std::map<cmStdString, RuleHash>::const_iterator rhi =
  2546. this->RuleHashes.find(fname);
  2547. if(rhi != this->RuleHashes.end())
  2548. {
  2549. // Compare the rule hash in the file to that we were given.
  2550. if(strncmp(line.c_str(), rhi->second.Data, 32) != 0)
  2551. {
  2552. // The rule has changed. Delete the output so it will be
  2553. // built again.
  2554. fname = cmSystemTools::CollapseFullPath(fname.c_str(), home.c_str());
  2555. cmSystemTools::RemoveFile(fname.c_str());
  2556. }
  2557. }
  2558. else
  2559. {
  2560. // We have no hash for a rule previously listed. This may be a
  2561. // case where a user has turned off a build option and might
  2562. // want to turn it back on later, so do not delete the file.
  2563. // Instead, we keep the rule hash as long as the file exists so
  2564. // that if the feature is turned back on and the rule has
  2565. // changed the file is still rebuilt.
  2566. std::string fpath =
  2567. cmSystemTools::CollapseFullPath(fname.c_str(), home.c_str());
  2568. if(cmSystemTools::FileExists(fpath.c_str()))
  2569. {
  2570. RuleHash hash;
  2571. strncpy(hash.Data, line.c_str(), 32);
  2572. this->RuleHashes[fname] = hash;
  2573. }
  2574. }
  2575. }
  2576. }
  2577. //----------------------------------------------------------------------------
  2578. void cmGlobalGenerator::WriteRuleHashes(std::string const& pfile)
  2579. {
  2580. // Now generate a new persistence file with the current hashes.
  2581. if(this->RuleHashes.empty())
  2582. {
  2583. cmSystemTools::RemoveFile(pfile.c_str());
  2584. }
  2585. else
  2586. {
  2587. cmGeneratedFileStream fout(pfile.c_str());
  2588. fout << "# Hashes of file build rules.\n";
  2589. for(std::map<cmStdString, RuleHash>::const_iterator
  2590. rhi = this->RuleHashes.begin(); rhi != this->RuleHashes.end(); ++rhi)
  2591. {
  2592. fout.write(rhi->second.Data, 32);
  2593. fout << " " << rhi->first << "\n";
  2594. }
  2595. }
  2596. }
  2597. //----------------------------------------------------------------------------
  2598. void cmGlobalGenerator::WriteSummary()
  2599. {
  2600. cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
  2601. // Record all target directories in a central location.
  2602. std::string fname = mf->GetHomeOutputDirectory();
  2603. fname += cmake::GetCMakeFilesDirectory();
  2604. fname += "/TargetDirectories.txt";
  2605. cmGeneratedFileStream fout(fname.c_str());
  2606. // Generate summary information files for each target.
  2607. std::string dir;
  2608. for(std::map<cmStdString,cmTarget *>::const_iterator ti =
  2609. this->TotalTargets.begin(); ti != this->TotalTargets.end(); ++ti)
  2610. {
  2611. if ((ti->second)->GetType() == cmTarget::INTERFACE_LIBRARY)
  2612. {
  2613. continue;
  2614. }
  2615. this->WriteSummary(ti->second);
  2616. fout << ti->second->GetSupportDirectory() << "\n";
  2617. }
  2618. }
  2619. //----------------------------------------------------------------------------
  2620. void cmGlobalGenerator::WriteSummary(cmTarget* target)
  2621. {
  2622. // Place the labels file in a per-target support directory.
  2623. std::string dir = target->GetSupportDirectory();
  2624. std::string file = dir;
  2625. file += "/Labels.txt";
  2626. // Check whether labels are enabled for this target.
  2627. if(const char* value = target->GetProperty("LABELS"))
  2628. {
  2629. cmSystemTools::MakeDirectory(dir.c_str());
  2630. cmGeneratedFileStream fout(file.c_str());
  2631. // List the target-wide labels. All sources in the target get
  2632. // these labels.
  2633. std::vector<std::string> labels;
  2634. cmSystemTools::ExpandListArgument(value, labels);
  2635. if(!labels.empty())
  2636. {
  2637. fout << "# Target labels\n";
  2638. for(std::vector<std::string>::const_iterator li = labels.begin();
  2639. li != labels.end(); ++li)
  2640. {
  2641. fout << " " << *li << "\n";
  2642. }
  2643. }
  2644. // List the source files with any per-source labels.
  2645. fout << "# Source files and their labels\n";
  2646. std::vector<cmSourceFile*> sources;
  2647. target->GetSourceFiles(sources);
  2648. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  2649. si != sources.end(); ++si)
  2650. {
  2651. cmSourceFile* sf = *si;
  2652. fout << sf->GetFullPath() << "\n";
  2653. if(const char* svalue = sf->GetProperty("LABELS"))
  2654. {
  2655. labels.clear();
  2656. cmSystemTools::ExpandListArgument(svalue, labels);
  2657. for(std::vector<std::string>::const_iterator li = labels.begin();
  2658. li != labels.end(); ++li)
  2659. {
  2660. fout << " " << *li << "\n";
  2661. }
  2662. }
  2663. }
  2664. }
  2665. else
  2666. {
  2667. cmSystemTools::RemoveFile(file.c_str());
  2668. }
  2669. }
  2670. //----------------------------------------------------------------------------
  2671. // static
  2672. std::string cmGlobalGenerator::EscapeJSON(const std::string& s) {
  2673. std::string result;
  2674. for (std::string::size_type i = 0; i < s.size(); ++i) {
  2675. if (s[i] == '"' || s[i] == '\\') {
  2676. result += '\\';
  2677. }
  2678. result += s[i];
  2679. }
  2680. return result;
  2681. }
  2682. //----------------------------------------------------------------------------
  2683. void cmGlobalGenerator::AddEvaluationFile(const std::string &inputFile,
  2684. cmsys::auto_ptr<cmCompiledGeneratorExpression> outputExpr,
  2685. cmMakefile *makefile,
  2686. cmsys::auto_ptr<cmCompiledGeneratorExpression> condition,
  2687. bool inputIsContent)
  2688. {
  2689. this->EvaluationFiles.push_back(
  2690. new cmGeneratorExpressionEvaluationFile(inputFile, outputExpr,
  2691. makefile, condition,
  2692. inputIsContent));
  2693. }
  2694. //----------------------------------------------------------------------------
  2695. void cmGlobalGenerator::ProcessEvaluationFiles()
  2696. {
  2697. std::set<std::string> generatedFiles;
  2698. for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
  2699. li = this->EvaluationFiles.begin();
  2700. li != this->EvaluationFiles.end();
  2701. ++li)
  2702. {
  2703. (*li)->Generate();
  2704. if (cmSystemTools::GetFatalErrorOccured())
  2705. {
  2706. return;
  2707. }
  2708. std::vector<std::string> files = (*li)->GetFiles();
  2709. for(std::vector<std::string>::const_iterator fi = files.begin();
  2710. fi != files.end(); ++fi)
  2711. {
  2712. if (!generatedFiles.insert(*fi).second)
  2713. {
  2714. cmSystemTools::Error("File to be generated by multiple different "
  2715. "commands: ", fi->c_str());
  2716. return;
  2717. }
  2718. }
  2719. }
  2720. }