cmGlobalGenerator.cxx 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991
  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) const
  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) const
  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 const& lang,
  676. const char* envVar) const
  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 const& lang) const
  697. {
  698. std::string compilerIdVar = "CMAKE_" + lang + "_COMPILER_ID";
  699. const char* compilerId = mf->GetDefinition(compilerIdVar.c_str());
  700. if(!compilerId)
  701. {
  702. return;
  703. }
  704. if(strcmp(compilerId, "AppleClang") == 0)
  705. {
  706. cmPolicies* policies = this->CMakeInstance->GetPolicies();
  707. switch(mf->GetPolicyStatus(cmPolicies::CMP0025))
  708. {
  709. case cmPolicies::WARN:
  710. if(!this->CMakeInstance->GetIsInTryCompile())
  711. {
  712. cmOStringStream w;
  713. w << policies->GetPolicyWarning(cmPolicies::CMP0025) << "\n"
  714. "Converting " << lang <<
  715. " compiler id \"AppleClang\" to \"Clang\" for compatibility."
  716. ;
  717. mf->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  718. }
  719. case cmPolicies::OLD:
  720. // OLD behavior is to convert AppleClang to Clang.
  721. mf->AddDefinition(compilerIdVar.c_str(), "Clang");
  722. break;
  723. case cmPolicies::REQUIRED_IF_USED:
  724. case cmPolicies::REQUIRED_ALWAYS:
  725. mf->IssueMessage(
  726. cmake::FATAL_ERROR,
  727. policies->GetRequiredPolicyError(cmPolicies::CMP0025)
  728. );
  729. case cmPolicies::NEW:
  730. // NEW behavior is to keep AppleClang.
  731. break;
  732. }
  733. }
  734. if(strcmp(compilerId, "QCC") == 0)
  735. {
  736. cmPolicies* policies = this->CMakeInstance->GetPolicies();
  737. switch(mf->GetPolicyStatus(cmPolicies::CMP0047))
  738. {
  739. case cmPolicies::WARN:
  740. if(!this->CMakeInstance->GetIsInTryCompile())
  741. {
  742. cmOStringStream w;
  743. w << policies->GetPolicyWarning(cmPolicies::CMP0047) << "\n"
  744. "Converting " << lang <<
  745. " compiler id \"QCC\" to \"GNU\" for compatibility."
  746. ;
  747. mf->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  748. }
  749. case cmPolicies::OLD:
  750. // OLD behavior is to convert QCC to GNU.
  751. mf->AddDefinition(compilerIdVar.c_str(), "GNU");
  752. break;
  753. case cmPolicies::REQUIRED_IF_USED:
  754. case cmPolicies::REQUIRED_ALWAYS:
  755. mf->IssueMessage(
  756. cmake::FATAL_ERROR,
  757. policies->GetRequiredPolicyError(cmPolicies::CMP0047)
  758. );
  759. case cmPolicies::NEW:
  760. // NEW behavior is to keep QCC.
  761. break;
  762. }
  763. }
  764. }
  765. //----------------------------------------------------------------------------
  766. std::string
  767. cmGlobalGenerator::GetLanguageOutputExtension(cmSourceFile const& source) const
  768. {
  769. const std::string& lang = source.GetLanguage();
  770. if(!lang.empty())
  771. {
  772. std::map<cmStdString, cmStdString>::const_iterator it =
  773. this->LanguageToOutputExtension.find(lang);
  774. if(it != this->LanguageToOutputExtension.end())
  775. {
  776. return it->second;
  777. }
  778. }
  779. else
  780. {
  781. // if no language is found then check to see if it is already an
  782. // ouput extension for some language. In that case it should be ignored
  783. // and in this map, so it will not be compiled but will just be used.
  784. std::string const& ext = source.GetExtension();
  785. if(!ext.empty())
  786. {
  787. if(this->OutputExtensions.count(ext))
  788. {
  789. return ext;
  790. }
  791. }
  792. }
  793. return "";
  794. }
  795. std::string cmGlobalGenerator::GetLanguageFromExtension(const char* ext) const
  796. {
  797. // if there is an extension and it starts with . then move past the
  798. // . because the extensions are not stored with a . in the map
  799. if(ext && *ext == '.')
  800. {
  801. ++ext;
  802. }
  803. std::map<cmStdString, cmStdString>::const_iterator it
  804. = this->ExtensionToLanguage.find(ext);
  805. if(it != this->ExtensionToLanguage.end())
  806. {
  807. return it->second;
  808. }
  809. return "";
  810. }
  811. /* SetLanguageEnabled() is now split in two parts:
  812. at first the enabled-flag is set. This can then be used in EnabledLanguage()
  813. for checking whether the language is already enabled. After setting this
  814. flag still the values from the cmake variables have to be copied into the
  815. internal maps, this is done in SetLanguageEnabledMaps() which is called
  816. after the system- and compiler specific files have been loaded.
  817. This split was done originally so that compiler-specific configuration
  818. files could change the object file extension
  819. (CMAKE_<LANG>_OUTPUT_EXTENSION) before the CMake variables were copied
  820. to the C++ maps.
  821. */
  822. void cmGlobalGenerator::SetLanguageEnabled(const std::string& l,
  823. cmMakefile* mf)
  824. {
  825. this->SetLanguageEnabledFlag(l, mf);
  826. this->SetLanguageEnabledMaps(l, mf);
  827. }
  828. void cmGlobalGenerator::SetLanguageEnabledFlag(const std::string& l,
  829. cmMakefile* mf)
  830. {
  831. this->LanguageEnabled[l] = true;
  832. // Fill the language-to-extension map with the current variable
  833. // settings to make sure it is available for the try_compile()
  834. // command source file signature. In SetLanguageEnabledMaps this
  835. // will be done again to account for any compiler- or
  836. // platform-specific entries.
  837. this->FillExtensionToLanguageMap(l, mf);
  838. }
  839. void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
  840. cmMakefile* mf)
  841. {
  842. // use LanguageToLinkerPreference to detect whether this functions has
  843. // run before
  844. if (this->LanguageToLinkerPreference.find(l) !=
  845. this->LanguageToLinkerPreference.end())
  846. {
  847. return;
  848. }
  849. std::string linkerPrefVar = std::string("CMAKE_") +
  850. std::string(l) + std::string("_LINKER_PREFERENCE");
  851. const char* linkerPref = mf->GetDefinition(linkerPrefVar.c_str());
  852. int preference = 0;
  853. if(linkerPref)
  854. {
  855. if (sscanf(linkerPref, "%d", &preference)!=1)
  856. {
  857. // backward compatibility: before 2.6 LINKER_PREFERENCE
  858. // was either "None" or "Prefered", and only the first character was
  859. // tested. So if there is a custom language out there and it is
  860. // "Prefered", set its preference high
  861. if (linkerPref[0]=='P')
  862. {
  863. preference = 100;
  864. }
  865. else
  866. {
  867. preference = 0;
  868. }
  869. }
  870. }
  871. if (preference < 0)
  872. {
  873. std::string msg = linkerPrefVar;
  874. msg += " is negative, adjusting it to 0";
  875. cmSystemTools::Message(msg.c_str(), "Warning");
  876. preference = 0;
  877. }
  878. this->LanguageToLinkerPreference[l] = preference;
  879. std::string outputExtensionVar = std::string("CMAKE_") +
  880. std::string(l) + std::string("_OUTPUT_EXTENSION");
  881. const char* outputExtension = mf->GetDefinition(outputExtensionVar.c_str());
  882. if(outputExtension)
  883. {
  884. this->LanguageToOutputExtension[l] = outputExtension;
  885. this->OutputExtensions[outputExtension] = outputExtension;
  886. if(outputExtension[0] == '.')
  887. {
  888. this->OutputExtensions[outputExtension+1] = outputExtension+1;
  889. }
  890. }
  891. // The map was originally filled by SetLanguageEnabledFlag, but
  892. // since then the compiler- and platform-specific files have been
  893. // loaded which might have added more entries.
  894. this->FillExtensionToLanguageMap(l, mf);
  895. std::string ignoreExtensionsVar = std::string("CMAKE_") +
  896. std::string(l) + std::string("_IGNORE_EXTENSIONS");
  897. std::string ignoreExts = mf->GetSafeDefinition(ignoreExtensionsVar.c_str());
  898. std::vector<std::string> extensionList;
  899. cmSystemTools::ExpandListArgument(ignoreExts, extensionList);
  900. for(std::vector<std::string>::iterator i = extensionList.begin();
  901. i != extensionList.end(); ++i)
  902. {
  903. this->IgnoreExtensions[*i] = true;
  904. }
  905. }
  906. void cmGlobalGenerator::FillExtensionToLanguageMap(const std::string& l,
  907. cmMakefile* mf)
  908. {
  909. std::string extensionsVar = std::string("CMAKE_") +
  910. std::string(l) + std::string("_SOURCE_FILE_EXTENSIONS");
  911. std::string exts = mf->GetSafeDefinition(extensionsVar.c_str());
  912. std::vector<std::string> extensionList;
  913. cmSystemTools::ExpandListArgument(exts, extensionList);
  914. for(std::vector<std::string>::iterator i = extensionList.begin();
  915. i != extensionList.end(); ++i)
  916. {
  917. this->ExtensionToLanguage[*i] = l;
  918. }
  919. }
  920. bool cmGlobalGenerator::IgnoreFile(const char* l) const
  921. {
  922. if(!this->GetLanguageFromExtension(l).empty())
  923. {
  924. return false;
  925. }
  926. return (this->IgnoreExtensions.count(l) > 0);
  927. }
  928. bool cmGlobalGenerator::GetLanguageEnabled(const std::string& l) const
  929. {
  930. return (this->LanguageEnabled.find(l)!= this->LanguageEnabled.end());
  931. }
  932. void cmGlobalGenerator::ClearEnabledLanguages()
  933. {
  934. this->LanguageEnabled.clear();
  935. }
  936. bool cmGlobalGenerator::IsDependedOn(const std::string& project,
  937. cmTarget const* targetIn)
  938. {
  939. // Get all local gens for this project
  940. std::map<cmStdString, std::vector<cmLocalGenerator*> >::const_iterator it =
  941. this->ProjectMap.find(project);
  942. if (it == this->ProjectMap.end())
  943. {
  944. return false;
  945. }
  946. // loop over local gens and get the targets for each one
  947. for(std::vector<cmLocalGenerator*>::const_iterator geIt = it->second.begin();
  948. geIt != it->second.end(); ++geIt)
  949. {
  950. cmTargets const& targets = (*geIt)->GetMakefile()->GetTargets();
  951. for (cmTargets::const_iterator l = targets.begin();
  952. l != targets.end(); l++)
  953. {
  954. cmTarget const& target = l->second;
  955. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(target);
  956. if(tgtdeps.count(targetIn))
  957. {
  958. return true;
  959. }
  960. }
  961. }
  962. return false;
  963. }
  964. void cmGlobalGenerator::Configure()
  965. {
  966. this->FirstTimeProgress = 0.0f;
  967. this->ClearGeneratorMembers();
  968. // start with this directory
  969. cmLocalGenerator *lg = this->CreateLocalGenerator();
  970. this->LocalGenerators.push_back(lg);
  971. // set the Start directories
  972. cmMakefile* mf = lg->GetMakefile();
  973. lg->GetMakefile()->SetStartDirectory
  974. (this->CMakeInstance->GetStartDirectory());
  975. lg->GetMakefile()->SetStartOutputDirectory
  976. (this->CMakeInstance->GetStartOutputDirectory());
  977. lg->GetMakefile()->MakeStartDirectoriesCurrent();
  978. this->BinaryDirectories.insert(mf->GetStartOutputDirectory());
  979. // now do it
  980. lg->Configure();
  981. // update the cache entry for the number of local generators, this is used
  982. // for progress
  983. char num[100];
  984. sprintf(num,"%d",static_cast<int>(this->LocalGenerators.size()));
  985. this->GetCMakeInstance()->AddCacheEntry
  986. ("CMAKE_NUMBER_OF_LOCAL_GENERATORS", num,
  987. "number of local generators", cmCacheManager::INTERNAL);
  988. // check for link libraries and include directories containing "NOTFOUND"
  989. // and for infinite loops
  990. this->CheckLocalGenerators();
  991. // at this point this->LocalGenerators has been filled,
  992. // so create the map from project name to vector of local generators
  993. this->FillProjectMap();
  994. if ( this->CMakeInstance->GetWorkingMode() == cmake::NORMAL_MODE)
  995. {
  996. cmOStringStream msg;
  997. if(cmSystemTools::GetErrorOccuredFlag())
  998. {
  999. msg << "Configuring incomplete, errors occurred!";
  1000. const char* logs[] = {"CMakeOutput.log", "CMakeError.log", 0};
  1001. for(const char** log = logs; *log; ++log)
  1002. {
  1003. std::string f = this->CMakeInstance->GetHomeOutputDirectory();
  1004. f += this->CMakeInstance->GetCMakeFilesDirectory();
  1005. f += "/";
  1006. f += *log;
  1007. if(cmSystemTools::FileExists(f.c_str()))
  1008. {
  1009. msg << "\nSee also \"" << f << "\".";
  1010. }
  1011. }
  1012. }
  1013. else
  1014. {
  1015. msg << "Configuring done";
  1016. }
  1017. this->CMakeInstance->UpdateProgress(msg.str().c_str(), -1);
  1018. }
  1019. }
  1020. cmExportBuildFileGenerator*
  1021. cmGlobalGenerator::GetExportedTargetsFile(const std::string &filename) const
  1022. {
  1023. std::map<std::string, cmExportBuildFileGenerator*>::const_iterator it
  1024. = this->BuildExportSets.find(filename);
  1025. return it == this->BuildExportSets.end() ? 0 : it->second;
  1026. }
  1027. //----------------------------------------------------------------------------
  1028. void cmGlobalGenerator::AddCMP0042WarnTarget(const std::string& target)
  1029. {
  1030. this->CMP0042WarnTargets.insert(target);
  1031. }
  1032. bool cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const
  1033. {
  1034. // If the property is not enabled then okay.
  1035. if(!this->CMakeInstance
  1036. ->GetPropertyAsBool("ALLOW_DUPLICATE_CUSTOM_TARGETS"))
  1037. {
  1038. return true;
  1039. }
  1040. // This generator does not support duplicate custom targets.
  1041. cmOStringStream e;
  1042. e << "This project has enabled the ALLOW_DUPLICATE_CUSTOM_TARGETS "
  1043. << "global property. "
  1044. << "The \"" << this->GetName() << "\" generator does not support "
  1045. << "duplicate custom targets. "
  1046. << "Consider using a Makefiles generator or fix the project to not "
  1047. << "use duplicate target names.";
  1048. cmSystemTools::Error(e.str().c_str());
  1049. return false;
  1050. }
  1051. void cmGlobalGenerator::Generate()
  1052. {
  1053. // Some generators track files replaced during the Generate.
  1054. // Start with an empty vector:
  1055. this->FilesReplacedDuringGenerate.clear();
  1056. // clear targets to issue warning CMP0042 for
  1057. this->CMP0042WarnTargets.clear();
  1058. // Check whether this generator is allowed to run.
  1059. if(!this->CheckALLOW_DUPLICATE_CUSTOM_TARGETS())
  1060. {
  1061. return;
  1062. }
  1063. this->FinalizeTargetCompileInfo();
  1064. #ifdef CMAKE_BUILD_WITH_CMAKE
  1065. // Iterate through all targets and set up automoc for those which have
  1066. // the AUTOMOC, AUTOUIC or AUTORCC property set
  1067. AutogensType autogens;
  1068. this->CreateQtAutoGeneratorsTargets(autogens);
  1069. #endif
  1070. // For each existing cmLocalGenerator
  1071. unsigned int i;
  1072. // Put a copy of each global target in every directory.
  1073. cmTargets globalTargets;
  1074. this->CreateDefaultGlobalTargets(&globalTargets);
  1075. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1076. {
  1077. cmMakefile* mf = this->LocalGenerators[i]->GetMakefile();
  1078. cmTargets* targets = &(mf->GetTargets());
  1079. cmTargets::iterator tit;
  1080. for ( tit = globalTargets.begin(); tit != globalTargets.end(); ++ tit )
  1081. {
  1082. (*targets)[tit->first] = tit->second;
  1083. (*targets)[tit->first].SetMakefile(mf);
  1084. }
  1085. }
  1086. // Add generator specific helper commands
  1087. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1088. {
  1089. this->LocalGenerators[i]->AddHelperCommands();
  1090. }
  1091. // Create per-target generator information.
  1092. this->CreateGeneratorTargets();
  1093. #ifdef CMAKE_BUILD_WITH_CMAKE
  1094. for (AutogensType::iterator it = autogens.begin(); it != autogens.end();
  1095. ++it)
  1096. {
  1097. it->first.SetupAutoGenerateTarget(it->second);
  1098. }
  1099. #endif
  1100. // Trace the dependencies, after that no custom commands should be added
  1101. // because their dependencies might not be handled correctly
  1102. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1103. {
  1104. this->LocalGenerators[i]->TraceDependencies();
  1105. }
  1106. // Compute the manifest of main targets generated.
  1107. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1108. {
  1109. this->LocalGenerators[i]->GenerateTargetManifest();
  1110. }
  1111. this->ComputeGeneratorTargetObjects();
  1112. this->ProcessEvaluationFiles();
  1113. // Compute the inter-target dependencies.
  1114. if(!this->ComputeTargetDepends())
  1115. {
  1116. return;
  1117. }
  1118. // Create a map from local generator to the complete set of targets
  1119. // it builds by default.
  1120. this->FillLocalGeneratorToTargetMap();
  1121. // Generate project files
  1122. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1123. {
  1124. this->LocalGenerators[i]->GetMakefile()->SetGeneratingBuildSystem();
  1125. this->SetCurrentLocalGenerator(this->LocalGenerators[i]);
  1126. this->LocalGenerators[i]->Generate();
  1127. if(!this->LocalGenerators[i]->GetMakefile()->IsOn(
  1128. "CMAKE_SKIP_INSTALL_RULES"))
  1129. {
  1130. this->LocalGenerators[i]->GenerateInstallRules();
  1131. }
  1132. this->LocalGenerators[i]->GenerateTestFiles();
  1133. this->CMakeInstance->UpdateProgress("Generating",
  1134. (static_cast<float>(i)+1.0f)/
  1135. static_cast<float>(this->LocalGenerators.size()));
  1136. }
  1137. this->SetCurrentLocalGenerator(0);
  1138. for (std::map<std::string, cmExportBuildFileGenerator*>::iterator
  1139. it = this->BuildExportSets.begin(); it != this->BuildExportSets.end();
  1140. ++it)
  1141. {
  1142. if (!it->second->GenerateImportFile()
  1143. && !cmSystemTools::GetErrorOccuredFlag())
  1144. {
  1145. this->GetCMakeInstance()
  1146. ->IssueMessage(cmake::FATAL_ERROR, "Could not write export file.",
  1147. cmListFileBacktrace());
  1148. return;
  1149. }
  1150. }
  1151. // Update rule hashes.
  1152. this->CheckRuleHashes();
  1153. this->WriteSummary();
  1154. if (this->ExtraGenerator != 0)
  1155. {
  1156. this->ExtraGenerator->Generate();
  1157. }
  1158. if(!this->CMP0042WarnTargets.empty())
  1159. {
  1160. cmOStringStream w;
  1161. w <<
  1162. (this->GetCMakeInstance()->GetPolicies()->
  1163. GetPolicyWarning(cmPolicies::CMP0042)) << "\n";
  1164. w << "MACOSX_RPATH is not specified for"
  1165. " the following targets:\n";
  1166. for(std::set<std::string>::iterator
  1167. iter = this->CMP0042WarnTargets.begin();
  1168. iter != this->CMP0042WarnTargets.end();
  1169. ++iter)
  1170. {
  1171. w << " " << *iter << "\n";
  1172. }
  1173. this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  1174. cmListFileBacktrace());
  1175. }
  1176. this->CMakeInstance->UpdateProgress("Generating done", -1);
  1177. }
  1178. //----------------------------------------------------------------------------
  1179. bool cmGlobalGenerator::ComputeTargetDepends()
  1180. {
  1181. cmComputeTargetDepends ctd(this);
  1182. if(!ctd.Compute())
  1183. {
  1184. return false;
  1185. }
  1186. std::vector<cmTarget const*> const& targets = ctd.GetTargets();
  1187. for(std::vector<cmTarget const*>::const_iterator ti = targets.begin();
  1188. ti != targets.end(); ++ti)
  1189. {
  1190. ctd.GetTargetDirectDepends(*ti, this->TargetDependencies[*ti]);
  1191. }
  1192. return true;
  1193. }
  1194. //----------------------------------------------------------------------------
  1195. void cmGlobalGenerator::CreateQtAutoGeneratorsTargets(AutogensType &autogens)
  1196. {
  1197. #ifdef CMAKE_BUILD_WITH_CMAKE
  1198. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1199. {
  1200. cmTargets& targets =
  1201. this->LocalGenerators[i]->GetMakefile()->GetTargets();
  1202. for(cmTargets::iterator ti = targets.begin();
  1203. ti != targets.end(); ++ti)
  1204. {
  1205. cmTarget& target = ti->second;
  1206. if(target.GetType() == cmTarget::EXECUTABLE ||
  1207. target.GetType() == cmTarget::STATIC_LIBRARY ||
  1208. target.GetType() == cmTarget::SHARED_LIBRARY ||
  1209. target.GetType() == cmTarget::MODULE_LIBRARY ||
  1210. target.GetType() == cmTarget::OBJECT_LIBRARY)
  1211. {
  1212. if((target.GetPropertyAsBool("AUTOMOC")
  1213. || target.GetPropertyAsBool("AUTOUIC")
  1214. || target.GetPropertyAsBool("AUTORCC"))
  1215. && !target.IsImported())
  1216. {
  1217. cmQtAutoGenerators autogen;
  1218. if(autogen.InitializeAutogenTarget(&target))
  1219. {
  1220. autogens.push_back(AutogensType::value_type(autogen, &target));
  1221. }
  1222. }
  1223. }
  1224. }
  1225. }
  1226. #else
  1227. (void)autogens;
  1228. #endif
  1229. }
  1230. //----------------------------------------------------------------------------
  1231. void cmGlobalGenerator::FinalizeTargetCompileInfo()
  1232. {
  1233. // Construct per-target generator information.
  1234. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1235. {
  1236. cmMakefile *mf = this->LocalGenerators[i]->GetMakefile();
  1237. const std::vector<cmValueWithOrigin> noconfig_compile_definitions =
  1238. mf->GetCompileDefinitionsEntries();
  1239. cmTargets& targets = mf->GetTargets();
  1240. for(cmTargets::iterator ti = targets.begin();
  1241. ti != targets.end(); ++ti)
  1242. {
  1243. cmTarget* t = &ti->second;
  1244. t->AppendBuildInterfaceIncludes();
  1245. if (t->GetType() == cmTarget::INTERFACE_LIBRARY)
  1246. {
  1247. continue;
  1248. }
  1249. for (std::vector<cmValueWithOrigin>::const_iterator it
  1250. = noconfig_compile_definitions.begin();
  1251. it != noconfig_compile_definitions.end(); ++it)
  1252. {
  1253. t->InsertCompileDefinition(*it);
  1254. }
  1255. cmPolicies::PolicyStatus polSt
  1256. = mf->GetPolicyStatus(cmPolicies::CMP0043);
  1257. if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD)
  1258. {
  1259. std::vector<std::string> configs;
  1260. mf->GetConfigurations(configs);
  1261. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1262. ci != configs.end(); ++ci)
  1263. {
  1264. std::string defPropName = "COMPILE_DEFINITIONS_";
  1265. defPropName += cmSystemTools::UpperCase(*ci);
  1266. t->AppendProperty(defPropName.c_str(),
  1267. mf->GetProperty(defPropName.c_str()));
  1268. }
  1269. }
  1270. }
  1271. }
  1272. }
  1273. //----------------------------------------------------------------------------
  1274. void cmGlobalGenerator::CreateGeneratorTargets(cmMakefile *mf)
  1275. {
  1276. cmGeneratorTargetsType generatorTargets;
  1277. cmTargets& targets = mf->GetTargets();
  1278. for(cmTargets::iterator ti = targets.begin();
  1279. ti != targets.end(); ++ti)
  1280. {
  1281. cmTarget* t = &ti->second;
  1282. cmGeneratorTarget* gt = new cmGeneratorTarget(t);
  1283. this->GeneratorTargets[t] = gt;
  1284. generatorTargets[t] = gt;
  1285. }
  1286. for(std::vector<cmTarget*>::const_iterator
  1287. j = mf->GetOwnedImportedTargets().begin();
  1288. j != mf->GetOwnedImportedTargets().end(); ++j)
  1289. {
  1290. cmGeneratorTarget* gt = new cmGeneratorTarget(*j);
  1291. this->GeneratorTargets[*j] = gt;
  1292. generatorTargets[*j] = gt;
  1293. }
  1294. mf->SetGeneratorTargets(generatorTargets);
  1295. }
  1296. //----------------------------------------------------------------------------
  1297. void cmGlobalGenerator::CreateGeneratorTargets()
  1298. {
  1299. // Construct per-target generator information.
  1300. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1301. {
  1302. this->CreateGeneratorTargets(this->LocalGenerators[i]->GetMakefile());
  1303. }
  1304. }
  1305. //----------------------------------------------------------------------------
  1306. void cmGlobalGenerator::ComputeGeneratorTargetObjects()
  1307. {
  1308. // Construct per-target generator information.
  1309. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1310. {
  1311. cmMakefile *mf = this->LocalGenerators[i]->GetMakefile();
  1312. cmGeneratorTargetsType targets = mf->GetGeneratorTargets();
  1313. for(cmGeneratorTargetsType::iterator ti = targets.begin();
  1314. ti != targets.end(); ++ti)
  1315. {
  1316. if (ti->second->Target->IsImported()
  1317. || ti->second->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  1318. {
  1319. continue;
  1320. }
  1321. cmGeneratorTarget* gt = ti->second;
  1322. gt->LookupObjectLibraries();
  1323. this->ComputeTargetObjects(gt);
  1324. }
  1325. }
  1326. }
  1327. //----------------------------------------------------------------------------
  1328. void cmGlobalGenerator::ClearGeneratorMembers()
  1329. {
  1330. for(cmGeneratorTargetsType::iterator i = this->GeneratorTargets.begin();
  1331. i != this->GeneratorTargets.end(); ++i)
  1332. {
  1333. delete i->second;
  1334. }
  1335. this->GeneratorTargets.clear();
  1336. for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
  1337. li = this->EvaluationFiles.begin();
  1338. li != this->EvaluationFiles.end();
  1339. ++li)
  1340. {
  1341. delete *li;
  1342. }
  1343. this->EvaluationFiles.clear();
  1344. for(std::map<std::string, cmExportBuildFileGenerator*>::iterator
  1345. i = this->BuildExportSets.begin();
  1346. i != this->BuildExportSets.end(); ++i)
  1347. {
  1348. delete i->second;
  1349. }
  1350. this->BuildExportSets.clear();
  1351. for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
  1352. {
  1353. delete this->LocalGenerators[i];
  1354. }
  1355. this->LocalGenerators.clear();
  1356. this->ExportSets.clear();
  1357. this->TargetDependencies.clear();
  1358. this->TotalTargets.clear();
  1359. this->ImportedTargets.clear();
  1360. this->LocalGeneratorToTargetMap.clear();
  1361. this->ProjectMap.clear();
  1362. this->RuleHashes.clear();
  1363. this->DirectoryContentMap.clear();
  1364. this->BinaryDirectories.clear();
  1365. }
  1366. //----------------------------------------------------------------------------
  1367. cmGeneratorTarget*
  1368. cmGlobalGenerator::GetGeneratorTarget(cmTarget const* t) const
  1369. {
  1370. cmGeneratorTargetsType::const_iterator ti = this->GeneratorTargets.find(t);
  1371. if(ti == this->GeneratorTargets.end())
  1372. {
  1373. this->CMakeInstance->IssueMessage(
  1374. cmake::INTERNAL_ERROR, "Missing cmGeneratorTarget instance!",
  1375. cmListFileBacktrace());
  1376. return 0;
  1377. }
  1378. return ti->second;
  1379. }
  1380. //----------------------------------------------------------------------------
  1381. void cmGlobalGenerator::ComputeTargetObjects(cmGeneratorTarget*) const
  1382. {
  1383. // Implemented in generator subclasses that need this.
  1384. }
  1385. void cmGlobalGenerator::CheckLocalGenerators()
  1386. {
  1387. std::map<cmStdString, cmStdString> notFoundMap;
  1388. // std::set<cmStdString> notFoundMap;
  1389. // after it is all done do a ConfigureFinalPass
  1390. cmCacheManager* manager = 0;
  1391. for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
  1392. {
  1393. manager = this->LocalGenerators[i]->GetMakefile()->GetCacheManager();
  1394. this->LocalGenerators[i]->ConfigureFinalPass();
  1395. cmTargets &targets =
  1396. this->LocalGenerators[i]->GetMakefile()->GetTargets();
  1397. for (cmTargets::iterator l = targets.begin();
  1398. l != targets.end(); l++)
  1399. {
  1400. if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  1401. {
  1402. continue;
  1403. }
  1404. const cmTarget::LinkLibraryVectorType& libs =
  1405. l->second.GetOriginalLinkLibraries();
  1406. for(cmTarget::LinkLibraryVectorType::const_iterator lib = libs.begin();
  1407. lib != libs.end(); ++lib)
  1408. {
  1409. if(lib->first.size() > 9 &&
  1410. cmSystemTools::IsNOTFOUND(lib->first.c_str()))
  1411. {
  1412. std::string varName = lib->first.substr(0, lib->first.size()-9);
  1413. cmCacheManager::CacheIterator it =
  1414. manager->GetCacheIterator(varName.c_str());
  1415. if(it.GetPropertyAsBool("ADVANCED"))
  1416. {
  1417. varName += " (ADVANCED)";
  1418. }
  1419. std::string text = notFoundMap[varName];
  1420. text += "\n linked by target \"";
  1421. text += l->second.GetName();
  1422. text += "\" in directory ";
  1423. text+=this->LocalGenerators[i]->GetMakefile()->GetCurrentDirectory();
  1424. notFoundMap[varName] = text;
  1425. }
  1426. }
  1427. std::vector<std::string> incs;
  1428. const char *incDirProp = l->second.GetProperty("INCLUDE_DIRECTORIES");
  1429. if (!incDirProp)
  1430. {
  1431. continue;
  1432. }
  1433. std::string incDirs = cmGeneratorExpression::Preprocess(incDirProp,
  1434. cmGeneratorExpression::StripAllGeneratorExpressions);
  1435. cmSystemTools::ExpandListArgument(incDirs.c_str(), incs);
  1436. for( std::vector<std::string>::const_iterator incDir = incs.begin();
  1437. incDir != incs.end(); ++incDir)
  1438. {
  1439. if(incDir->size() > 9 &&
  1440. cmSystemTools::IsNOTFOUND(incDir->c_str()))
  1441. {
  1442. std::string varName = incDir->substr(0, incDir->size()-9);
  1443. cmCacheManager::CacheIterator it =
  1444. manager->GetCacheIterator(varName.c_str());
  1445. if(it.GetPropertyAsBool("ADVANCED"))
  1446. {
  1447. varName += " (ADVANCED)";
  1448. }
  1449. std::string text = notFoundMap[varName];
  1450. text += "\n used as include directory in directory ";
  1451. text += this->LocalGenerators[i]
  1452. ->GetMakefile()->GetCurrentDirectory();
  1453. notFoundMap[varName] = text;
  1454. }
  1455. }
  1456. }
  1457. this->CMakeInstance->UpdateProgress
  1458. ("Configuring", 0.9f+0.1f*(static_cast<float>(i)+1.0f)/
  1459. static_cast<float>(this->LocalGenerators.size()));
  1460. }
  1461. if(notFoundMap.size())
  1462. {
  1463. std::string notFoundVars;
  1464. for(std::map<cmStdString, cmStdString>::const_iterator
  1465. ii = notFoundMap.begin();
  1466. ii != notFoundMap.end();
  1467. ++ii)
  1468. {
  1469. notFoundVars += ii->first;
  1470. notFoundVars += ii->second;
  1471. notFoundVars += "\n";
  1472. }
  1473. cmSystemTools::Error("The following variables are used in this project, "
  1474. "but they are set to NOTFOUND.\n"
  1475. "Please set them or make sure they are set and "
  1476. "tested correctly in the CMake files:\n",
  1477. notFoundVars.c_str());
  1478. }
  1479. }
  1480. int cmGlobalGenerator::TryCompile(const char *srcdir, const char *bindir,
  1481. const std::string& projectName,
  1482. const std::string& target, bool fast,
  1483. std::string *output, cmMakefile *mf)
  1484. {
  1485. // if this is not set, then this is a first time configure
  1486. // and there is a good chance that the try compile stuff will
  1487. // take the bulk of the time, so try and guess some progress
  1488. // by getting closer and closer to 100 without actually getting there.
  1489. if (!this->CMakeInstance->GetCacheManager()->GetCacheValue
  1490. ("CMAKE_NUMBER_OF_LOCAL_GENERATORS"))
  1491. {
  1492. // If CMAKE_NUMBER_OF_LOCAL_GENERATORS is not set
  1493. // we are in the first time progress and we have no
  1494. // idea how long it will be. So, just move 1/10th of the way
  1495. // there each time, and don't go over 95%
  1496. this->FirstTimeProgress += ((1.0f - this->FirstTimeProgress) /30.0f);
  1497. if(this->FirstTimeProgress > 0.95f)
  1498. {
  1499. this->FirstTimeProgress = 0.95f;
  1500. }
  1501. this->CMakeInstance->UpdateProgress("Configuring",
  1502. this->FirstTimeProgress);
  1503. }
  1504. std::string newTarget;
  1505. if (!target.empty())
  1506. {
  1507. newTarget += target;
  1508. #if 0
  1509. #if defined(_WIN32) || defined(__CYGWIN__)
  1510. std::string tmp = target;
  1511. // if the target does not already end in . something
  1512. // then assume .exe
  1513. if(tmp.size() < 4 || tmp[tmp.size()-4] != '.')
  1514. {
  1515. newTarget += ".exe";
  1516. }
  1517. #endif // WIN32
  1518. #endif
  1519. }
  1520. const char* config = mf->GetDefinition("CMAKE_TRY_COMPILE_CONFIGURATION");
  1521. return this->Build(srcdir,bindir,projectName,
  1522. newTarget.c_str(),
  1523. output,0,config,false,fast,
  1524. this->TryCompileTimeout);
  1525. }
  1526. void cmGlobalGenerator::GenerateBuildCommand(
  1527. std::vector<std::string>& makeCommand, const char*, const std::string&,
  1528. const char*, const std::string&, const char*, bool,
  1529. std::vector<std::string> const&)
  1530. {
  1531. makeCommand.push_back(
  1532. "cmGlobalGenerator::GenerateBuildCommand not implemented");
  1533. }
  1534. int cmGlobalGenerator::Build(
  1535. const char *, const char *bindir,
  1536. const std::string& projectName, const std::string& target,
  1537. std::string *output,
  1538. const char *makeCommandCSTR,
  1539. const char *config,
  1540. bool clean, bool fast,
  1541. double timeout,
  1542. cmSystemTools::OutputOption outputflag,
  1543. std::vector<std::string> const& nativeOptions)
  1544. {
  1545. /**
  1546. * Run an executable command and put the stdout in output.
  1547. */
  1548. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1549. cmSystemTools::ChangeDirectory(bindir);
  1550. if(output)
  1551. {
  1552. *output += "Change Dir: ";
  1553. *output += bindir;
  1554. *output += "\n";
  1555. }
  1556. int retVal;
  1557. bool hideconsole = cmSystemTools::GetRunCommandHideConsole();
  1558. cmSystemTools::SetRunCommandHideConsole(true);
  1559. std::string outputBuffer;
  1560. std::string* outputPtr = 0;
  1561. if(output)
  1562. {
  1563. outputPtr = &outputBuffer;
  1564. }
  1565. // should we do a clean first?
  1566. if (clean)
  1567. {
  1568. std::vector<std::string> cleanCommand;
  1569. this->GenerateBuildCommand(cleanCommand, makeCommandCSTR, projectName,
  1570. bindir, "clean", config, fast);
  1571. if(output)
  1572. {
  1573. *output += "\nRun Clean Command:";
  1574. *output += cmSystemTools::PrintSingleCommand(cleanCommand);
  1575. *output += "\n";
  1576. }
  1577. if (!cmSystemTools::RunSingleCommand(cleanCommand, outputPtr,
  1578. &retVal, 0, outputflag, timeout))
  1579. {
  1580. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1581. cmSystemTools::Error("Generator: execution of make clean failed.");
  1582. if (output)
  1583. {
  1584. *output += *outputPtr;
  1585. *output += "\nGenerator: execution of make clean failed.\n";
  1586. }
  1587. // return to the original directory
  1588. cmSystemTools::ChangeDirectory(cwd.c_str());
  1589. return 1;
  1590. }
  1591. if (output)
  1592. {
  1593. *output += *outputPtr;
  1594. }
  1595. }
  1596. // now build
  1597. std::vector<std::string> makeCommand;
  1598. this->GenerateBuildCommand(makeCommand, makeCommandCSTR, projectName,
  1599. bindir, target, config, fast, nativeOptions);
  1600. std::string makeCommandStr = cmSystemTools::PrintSingleCommand(makeCommand);
  1601. if(output)
  1602. {
  1603. *output += "\nRun Build Command:";
  1604. *output += makeCommandStr;
  1605. *output += "\n";
  1606. }
  1607. if (!cmSystemTools::RunSingleCommand(makeCommand, outputPtr,
  1608. &retVal, 0, outputflag, timeout))
  1609. {
  1610. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1611. cmSystemTools::Error
  1612. ("Generator: execution of make failed. Make command was: ",
  1613. makeCommandStr.c_str());
  1614. if (output)
  1615. {
  1616. *output += *outputPtr;
  1617. *output += "\nGenerator: execution of make failed. Make command was: "
  1618. + makeCommandStr + "\n";
  1619. }
  1620. // return to the original directory
  1621. cmSystemTools::ChangeDirectory(cwd.c_str());
  1622. return 1;
  1623. }
  1624. if (output)
  1625. {
  1626. *output += *outputPtr;
  1627. }
  1628. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1629. // The SGI MipsPro 7.3 compiler does not return an error code when
  1630. // the source has a #error in it! This is a work-around for such
  1631. // compilers.
  1632. if((retVal == 0) && (output->find("#error") != std::string::npos))
  1633. {
  1634. retVal = 1;
  1635. }
  1636. cmSystemTools::ChangeDirectory(cwd.c_str());
  1637. return retVal;
  1638. }
  1639. //----------------------------------------------------------------------------
  1640. std::string cmGlobalGenerator::GenerateCMakeBuildCommand(
  1641. const std::string& target, const char* config, const char* native,
  1642. bool ignoreErrors)
  1643. {
  1644. std::string makeCommand = cmSystemTools::GetCMakeCommand();
  1645. makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
  1646. makeCommand += " --build .";
  1647. if(config && *config)
  1648. {
  1649. makeCommand += " --config \"";
  1650. makeCommand += config;
  1651. makeCommand += "\"";
  1652. }
  1653. if(!target.empty())
  1654. {
  1655. makeCommand += " --target \"";
  1656. makeCommand += target;
  1657. makeCommand += "\"";
  1658. }
  1659. const char* sep = " -- ";
  1660. if(ignoreErrors)
  1661. {
  1662. const char* iflag = this->GetBuildIgnoreErrorsFlag();
  1663. if(iflag && *iflag)
  1664. {
  1665. makeCommand += sep;
  1666. makeCommand += iflag;
  1667. sep = " ";
  1668. }
  1669. }
  1670. if(native && *native)
  1671. {
  1672. makeCommand += sep;
  1673. makeCommand += native;
  1674. }
  1675. return makeCommand;
  1676. }
  1677. //----------------------------------------------------------------------------
  1678. void cmGlobalGenerator::AddLocalGenerator(cmLocalGenerator *lg)
  1679. {
  1680. this->LocalGenerators.push_back(lg);
  1681. // update progress
  1682. // estimate how many lg there will be
  1683. const char *numGenC =
  1684. this->CMakeInstance->GetCacheManager()->GetCacheValue
  1685. ("CMAKE_NUMBER_OF_LOCAL_GENERATORS");
  1686. if (!numGenC)
  1687. {
  1688. // If CMAKE_NUMBER_OF_LOCAL_GENERATORS is not set
  1689. // we are in the first time progress and we have no
  1690. // idea how long it will be. So, just move half way
  1691. // there each time, and don't go over 95%
  1692. this->FirstTimeProgress += ((1.0f - this->FirstTimeProgress) /30.0f);
  1693. if(this->FirstTimeProgress > 0.95f)
  1694. {
  1695. this->FirstTimeProgress = 0.95f;
  1696. }
  1697. this->CMakeInstance->UpdateProgress("Configuring",
  1698. this->FirstTimeProgress);
  1699. return;
  1700. }
  1701. int numGen = atoi(numGenC);
  1702. float prog = 0.9f*static_cast<float>(this->LocalGenerators.size())/
  1703. static_cast<float>(numGen);
  1704. if (prog > 0.9f)
  1705. {
  1706. prog = 0.9f;
  1707. }
  1708. this->CMakeInstance->UpdateProgress("Configuring", prog);
  1709. }
  1710. void cmGlobalGenerator::AddInstallComponent(const char* component)
  1711. {
  1712. if(component && *component)
  1713. {
  1714. this->InstallComponents.insert(component);
  1715. }
  1716. }
  1717. void cmGlobalGenerator::EnableInstallTarget()
  1718. {
  1719. this->InstallTargetEnabled = true;
  1720. }
  1721. cmLocalGenerator *cmGlobalGenerator::CreateLocalGenerator()
  1722. {
  1723. cmLocalGenerator *lg = new cmLocalGenerator;
  1724. lg->SetGlobalGenerator(this);
  1725. return lg;
  1726. }
  1727. void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator *gen,
  1728. cmMakefile* mf)
  1729. {
  1730. this->SetConfiguredFilesPath(gen);
  1731. this->TryCompileOuterMakefile = mf;
  1732. const char* make =
  1733. gen->GetCMakeInstance()->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
  1734. this->GetCMakeInstance()->AddCacheEntry("CMAKE_MAKE_PROGRAM", make,
  1735. "make program",
  1736. cmCacheManager::FILEPATH);
  1737. // copy the enabled languages
  1738. this->LanguageEnabled = gen->LanguageEnabled;
  1739. this->LanguagesReady = gen->LanguagesReady;
  1740. this->ExtensionToLanguage = gen->ExtensionToLanguage;
  1741. this->IgnoreExtensions = gen->IgnoreExtensions;
  1742. this->LanguageToOutputExtension = gen->LanguageToOutputExtension;
  1743. this->LanguageToLinkerPreference = gen->LanguageToLinkerPreference;
  1744. this->OutputExtensions = gen->OutputExtensions;
  1745. }
  1746. //----------------------------------------------------------------------------
  1747. void cmGlobalGenerator::SetConfiguredFilesPath(cmGlobalGenerator* gen)
  1748. {
  1749. if(!gen->ConfiguredFilesPath.empty())
  1750. {
  1751. this->ConfiguredFilesPath = gen->ConfiguredFilesPath;
  1752. }
  1753. else
  1754. {
  1755. this->ConfiguredFilesPath = gen->CMakeInstance->GetHomeOutputDirectory();
  1756. this->ConfiguredFilesPath += cmake::GetCMakeFilesDirectory();
  1757. }
  1758. }
  1759. bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
  1760. cmLocalGenerator* gen) const
  1761. {
  1762. if(!gen || gen == root)
  1763. {
  1764. // No directory excludes itself.
  1765. return false;
  1766. }
  1767. if(gen->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  1768. {
  1769. // This directory is excluded from its parent.
  1770. return true;
  1771. }
  1772. // This directory is included in its parent. Check whether the
  1773. // parent is excluded.
  1774. return this->IsExcluded(root, gen->GetParent());
  1775. }
  1776. bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
  1777. cmTarget const& target) const
  1778. {
  1779. if(target.GetType() == cmTarget::INTERFACE_LIBRARY
  1780. || target.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  1781. {
  1782. // This target is excluded from its directory.
  1783. return true;
  1784. }
  1785. else
  1786. {
  1787. // This target is included in its directory. Check whether the
  1788. // directory is excluded.
  1789. return this->IsExcluded(root, target.GetMakefile()->GetLocalGenerator());
  1790. }
  1791. }
  1792. void
  1793. cmGlobalGenerator::GetEnabledLanguages(std::vector<std::string>& lang) const
  1794. {
  1795. for(std::map<cmStdString, bool>::const_iterator i =
  1796. this->LanguageEnabled.begin(); i != this->LanguageEnabled.end(); ++i)
  1797. {
  1798. lang.push_back(i->first);
  1799. }
  1800. }
  1801. int cmGlobalGenerator::GetLinkerPreference(const std::string& lang) const
  1802. {
  1803. std::map<cmStdString, int>::const_iterator it =
  1804. this->LanguageToLinkerPreference.find(lang);
  1805. if (it != this->LanguageToLinkerPreference.end())
  1806. {
  1807. return it->second;
  1808. }
  1809. return 0;
  1810. }
  1811. void cmGlobalGenerator::FillProjectMap()
  1812. {
  1813. this->ProjectMap.clear(); // make sure we start with a clean map
  1814. unsigned int i;
  1815. for(i = 0; i < this->LocalGenerators.size(); ++i)
  1816. {
  1817. // for each local generator add all projects
  1818. cmLocalGenerator *lg = this->LocalGenerators[i];
  1819. std::string name;
  1820. do
  1821. {
  1822. if (name != lg->GetMakefile()->GetProjectName())
  1823. {
  1824. name = lg->GetMakefile()->GetProjectName();
  1825. this->ProjectMap[name].push_back(this->LocalGenerators[i]);
  1826. }
  1827. lg = lg->GetParent();
  1828. }
  1829. while (lg);
  1830. }
  1831. }
  1832. // Build a map that contains a the set of targets used by each local
  1833. // generator directory level.
  1834. void cmGlobalGenerator::FillLocalGeneratorToTargetMap()
  1835. {
  1836. this->LocalGeneratorToTargetMap.clear();
  1837. // Loop over all targets in all local generators.
  1838. for(std::vector<cmLocalGenerator*>::const_iterator
  1839. lgi = this->LocalGenerators.begin();
  1840. lgi != this->LocalGenerators.end(); ++lgi)
  1841. {
  1842. cmLocalGenerator* lg = *lgi;
  1843. cmMakefile* mf = lg->GetMakefile();
  1844. cmTargets const& targets = mf->GetTargets();
  1845. for(cmTargets::const_iterator t = targets.begin(); t != targets.end(); ++t)
  1846. {
  1847. cmTarget const& target = t->second;
  1848. // Consider the directory containing the target and all its
  1849. // parents until something excludes the target.
  1850. for(cmLocalGenerator* clg = lg; clg && !this->IsExcluded(clg, target);
  1851. clg = clg->GetParent())
  1852. {
  1853. // This local generator includes the target.
  1854. std::set<cmTarget const*>& targetSet =
  1855. this->LocalGeneratorToTargetMap[clg];
  1856. targetSet.insert(&target);
  1857. // Add dependencies of the included target. An excluded
  1858. // target may still be included if it is a dependency of a
  1859. // non-excluded target.
  1860. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(target);
  1861. for(TargetDependSet::const_iterator ti = tgtdeps.begin();
  1862. ti != tgtdeps.end(); ++ti)
  1863. {
  1864. cmTarget const* ttt = *ti;
  1865. targetSet.insert(ttt);
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. ///! Find a local generator by its startdirectory
  1872. cmLocalGenerator*
  1873. cmGlobalGenerator::FindLocalGenerator(const std::string& start_dir) const
  1874. {
  1875. for(std::vector<cmLocalGenerator*>::const_iterator it =
  1876. this->LocalGenerators.begin(); it != this->LocalGenerators.end(); ++it)
  1877. {
  1878. std::string sd = (*it)->GetMakefile()->GetStartDirectory();
  1879. if (sd == start_dir)
  1880. {
  1881. return *it;
  1882. }
  1883. }
  1884. return 0;
  1885. }
  1886. //----------------------------------------------------------------------------
  1887. void cmGlobalGenerator::AddAlias(const std::string& name, cmTarget *tgt)
  1888. {
  1889. this->AliasTargets[name] = tgt;
  1890. }
  1891. //----------------------------------------------------------------------------
  1892. bool cmGlobalGenerator::IsAlias(const std::string& name) const
  1893. {
  1894. return this->AliasTargets.find(name) != this->AliasTargets.end();
  1895. }
  1896. //----------------------------------------------------------------------------
  1897. cmTarget*
  1898. cmGlobalGenerator::FindTarget(const std::string& name,
  1899. bool excludeAliases) const
  1900. {
  1901. if (!excludeAliases)
  1902. {
  1903. std::map<cmStdString, cmTarget*>::const_iterator ai
  1904. = this->AliasTargets.find(name);
  1905. if (ai != this->AliasTargets.end())
  1906. {
  1907. return ai->second;
  1908. }
  1909. }
  1910. std::map<cmStdString,cmTarget *>::const_iterator i =
  1911. this->TotalTargets.find ( name );
  1912. if ( i != this->TotalTargets.end() )
  1913. {
  1914. return i->second;
  1915. }
  1916. i = this->ImportedTargets.find(name);
  1917. if ( i != this->ImportedTargets.end() )
  1918. {
  1919. return i->second;
  1920. }
  1921. return 0;
  1922. }
  1923. //----------------------------------------------------------------------------
  1924. bool
  1925. cmGlobalGenerator::NameResolvesToFramework(const std::string& libname) const
  1926. {
  1927. if(cmSystemTools::IsPathToFramework(libname.c_str()))
  1928. {
  1929. return true;
  1930. }
  1931. if(cmTarget* tgt = this->FindTarget(libname.c_str()))
  1932. {
  1933. if(tgt->IsFrameworkOnApple())
  1934. {
  1935. return true;
  1936. }
  1937. }
  1938. return false;
  1939. }
  1940. //----------------------------------------------------------------------------
  1941. inline std::string removeQuotes(const std::string& s)
  1942. {
  1943. if(s[0] == '\"' && s[s.size()-1] == '\"')
  1944. {
  1945. return s.substr(1, s.size()-2);
  1946. }
  1947. return s;
  1948. }
  1949. void cmGlobalGenerator::SetCMakeInstance(cmake* cm)
  1950. {
  1951. // Store a pointer to the cmake object instance.
  1952. this->CMakeInstance = cm;
  1953. }
  1954. void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
  1955. {
  1956. cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
  1957. const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
  1958. const char* cmakeCommand = mf->GetRequiredDefinition("CMAKE_COMMAND");
  1959. // CPack
  1960. std::string workingDir = mf->GetStartOutputDirectory();
  1961. cmCustomCommandLines cpackCommandLines;
  1962. std::vector<std::string> depends;
  1963. cmCustomCommandLine singleLine;
  1964. singleLine.push_back(cmSystemTools::GetCPackCommand());
  1965. if ( cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.' )
  1966. {
  1967. singleLine.push_back("-C");
  1968. singleLine.push_back(cmakeCfgIntDir);
  1969. }
  1970. singleLine.push_back("--config");
  1971. std::string configFile = mf->GetStartOutputDirectory();;
  1972. configFile += "/CPackConfig.cmake";
  1973. std::string relConfigFile = "./CPackConfig.cmake";
  1974. singleLine.push_back(relConfigFile);
  1975. cpackCommandLines.push_back(singleLine);
  1976. if ( this->GetPreinstallTargetName() )
  1977. {
  1978. depends.push_back(this->GetPreinstallTargetName());
  1979. }
  1980. else
  1981. {
  1982. const char* noPackageAll =
  1983. mf->GetDefinition("CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY");
  1984. if(!noPackageAll || cmSystemTools::IsOff(noPackageAll))
  1985. {
  1986. depends.push_back(this->GetAllTargetName());
  1987. }
  1988. }
  1989. if(cmSystemTools::FileExists(configFile.c_str()))
  1990. {
  1991. (*targets)[this->GetPackageTargetName()]
  1992. = this->CreateGlobalTarget(this->GetPackageTargetName(),
  1993. "Run CPack packaging tool...",
  1994. &cpackCommandLines, depends,
  1995. workingDir.c_str());
  1996. }
  1997. // CPack source
  1998. const char* packageSourceTargetName = this->GetPackageSourceTargetName();
  1999. if ( packageSourceTargetName )
  2000. {
  2001. cpackCommandLines.erase(cpackCommandLines.begin(),
  2002. cpackCommandLines.end());
  2003. singleLine.erase(singleLine.begin(), singleLine.end());
  2004. depends.erase(depends.begin(), depends.end());
  2005. singleLine.push_back(cmSystemTools::GetCPackCommand());
  2006. singleLine.push_back("--config");
  2007. configFile = mf->GetStartOutputDirectory();;
  2008. configFile += "/CPackSourceConfig.cmake";
  2009. relConfigFile = "./CPackSourceConfig.cmake";
  2010. singleLine.push_back(relConfigFile);
  2011. if(cmSystemTools::FileExists(configFile.c_str()))
  2012. {
  2013. singleLine.push_back(configFile);
  2014. cpackCommandLines.push_back(singleLine);
  2015. (*targets)[packageSourceTargetName]
  2016. = this->CreateGlobalTarget(packageSourceTargetName,
  2017. "Run CPack packaging tool for source...",
  2018. &cpackCommandLines, depends,
  2019. workingDir.c_str()
  2020. );
  2021. }
  2022. }
  2023. // Test
  2024. if(mf->IsOn("CMAKE_TESTING_ENABLED"))
  2025. {
  2026. cpackCommandLines.erase(cpackCommandLines.begin(),
  2027. cpackCommandLines.end());
  2028. singleLine.erase(singleLine.begin(), singleLine.end());
  2029. depends.erase(depends.begin(), depends.end());
  2030. singleLine.push_back(cmSystemTools::GetCTestCommand());
  2031. singleLine.push_back("--force-new-ctest-process");
  2032. if(cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.')
  2033. {
  2034. singleLine.push_back("-C");
  2035. singleLine.push_back(cmakeCfgIntDir);
  2036. }
  2037. else // TODO: This is a hack. Should be something to do with the generator
  2038. {
  2039. singleLine.push_back("$(ARGS)");
  2040. }
  2041. cpackCommandLines.push_back(singleLine);
  2042. (*targets)[this->GetTestTargetName()]
  2043. = this->CreateGlobalTarget(this->GetTestTargetName(),
  2044. "Running tests...", &cpackCommandLines, depends, 0);
  2045. }
  2046. //Edit Cache
  2047. const char* editCacheTargetName = this->GetEditCacheTargetName();
  2048. if ( editCacheTargetName )
  2049. {
  2050. cpackCommandLines.erase(cpackCommandLines.begin(),
  2051. cpackCommandLines.end());
  2052. singleLine.erase(singleLine.begin(), singleLine.end());
  2053. depends.erase(depends.begin(), depends.end());
  2054. // Use generator preference for the edit_cache rule if it is defined.
  2055. std::string edit_cmd = this->GetEditCacheCommand();
  2056. if (!edit_cmd.empty())
  2057. {
  2058. singleLine.push_back(edit_cmd);
  2059. singleLine.push_back("-H$(CMAKE_SOURCE_DIR)");
  2060. singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
  2061. cpackCommandLines.push_back(singleLine);
  2062. (*targets)[editCacheTargetName] =
  2063. this->CreateGlobalTarget(
  2064. editCacheTargetName, "Running CMake cache editor...",
  2065. &cpackCommandLines, depends, 0);
  2066. }
  2067. else
  2068. {
  2069. singleLine.push_back(cmakeCommand);
  2070. singleLine.push_back("-E");
  2071. singleLine.push_back("echo");
  2072. singleLine.push_back("No interactive CMake dialog available.");
  2073. cpackCommandLines.push_back(singleLine);
  2074. (*targets)[editCacheTargetName] =
  2075. this->CreateGlobalTarget(
  2076. editCacheTargetName,
  2077. "No interactive CMake dialog available...",
  2078. &cpackCommandLines, depends, 0);
  2079. }
  2080. }
  2081. //Rebuild Cache
  2082. const char* rebuildCacheTargetName = this->GetRebuildCacheTargetName();
  2083. if ( rebuildCacheTargetName )
  2084. {
  2085. cpackCommandLines.erase(cpackCommandLines.begin(),
  2086. cpackCommandLines.end());
  2087. singleLine.erase(singleLine.begin(), singleLine.end());
  2088. depends.erase(depends.begin(), depends.end());
  2089. singleLine.push_back(cmakeCommand);
  2090. singleLine.push_back("-H$(CMAKE_SOURCE_DIR)");
  2091. singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
  2092. cpackCommandLines.push_back(singleLine);
  2093. (*targets)[rebuildCacheTargetName] =
  2094. this->CreateGlobalTarget(
  2095. rebuildCacheTargetName, "Running CMake to regenerate build system...",
  2096. &cpackCommandLines, depends, 0);
  2097. }
  2098. //Install
  2099. bool skipInstallRules = mf->IsOn("CMAKE_SKIP_INSTALL_RULES");
  2100. if(this->InstallTargetEnabled && skipInstallRules)
  2101. {
  2102. mf->IssueMessage(cmake::WARNING,
  2103. "CMAKE_SKIP_INSTALL_RULES was enabled even though "
  2104. "installation rules have been specified");
  2105. }
  2106. else if(this->InstallTargetEnabled && !skipInstallRules)
  2107. {
  2108. if(!cmakeCfgIntDir || !*cmakeCfgIntDir || cmakeCfgIntDir[0] == '.')
  2109. {
  2110. std::set<cmStdString>* componentsSet = &this->InstallComponents;
  2111. cpackCommandLines.erase(cpackCommandLines.begin(),
  2112. cpackCommandLines.end());
  2113. depends.erase(depends.begin(), depends.end());
  2114. cmOStringStream ostr;
  2115. if ( componentsSet->size() > 0 )
  2116. {
  2117. ostr << "Available install components are:";
  2118. std::set<cmStdString>::iterator it;
  2119. for (
  2120. it = componentsSet->begin();
  2121. it != componentsSet->end();
  2122. ++ it )
  2123. {
  2124. ostr << " \"" << it->c_str() << "\"";
  2125. }
  2126. }
  2127. else
  2128. {
  2129. ostr << "Only default component available";
  2130. }
  2131. singleLine.push_back(ostr.str().c_str());
  2132. (*targets)["list_install_components"]
  2133. = this->CreateGlobalTarget("list_install_components",
  2134. ostr.str().c_str(),
  2135. &cpackCommandLines, depends, 0);
  2136. }
  2137. std::string cmd = cmakeCommand;
  2138. cpackCommandLines.erase(cpackCommandLines.begin(),
  2139. cpackCommandLines.end());
  2140. singleLine.erase(singleLine.begin(), singleLine.end());
  2141. depends.erase(depends.begin(), depends.end());
  2142. if ( this->GetPreinstallTargetName() )
  2143. {
  2144. depends.push_back(this->GetPreinstallTargetName());
  2145. }
  2146. else
  2147. {
  2148. const char* noall =
  2149. mf->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
  2150. if(!noall || cmSystemTools::IsOff(noall))
  2151. {
  2152. depends.push_back(this->GetAllTargetName());
  2153. }
  2154. }
  2155. if(mf->GetDefinition("CMake_BINARY_DIR"))
  2156. {
  2157. // We are building CMake itself. We cannot use the original
  2158. // executable to install over itself. The generator will
  2159. // automatically convert this name to the build-time location.
  2160. cmd = "cmake";
  2161. }
  2162. singleLine.push_back(cmd.c_str());
  2163. if ( cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.' )
  2164. {
  2165. std::string cfgArg = "-DBUILD_TYPE=";
  2166. cfgArg += mf->GetDefinition("CMAKE_CFG_INTDIR");
  2167. singleLine.push_back(cfgArg);
  2168. }
  2169. singleLine.push_back("-P");
  2170. singleLine.push_back("cmake_install.cmake");
  2171. cpackCommandLines.push_back(singleLine);
  2172. (*targets)[this->GetInstallTargetName()] =
  2173. this->CreateGlobalTarget(
  2174. this->GetInstallTargetName(), "Install the project...",
  2175. &cpackCommandLines, depends, 0);
  2176. // install_local
  2177. if(const char* install_local = this->GetInstallLocalTargetName())
  2178. {
  2179. cmCustomCommandLine localCmdLine = singleLine;
  2180. localCmdLine.insert(localCmdLine.begin()+1,
  2181. "-DCMAKE_INSTALL_LOCAL_ONLY=1");
  2182. cpackCommandLines.erase(cpackCommandLines.begin(),
  2183. cpackCommandLines.end());
  2184. cpackCommandLines.push_back(localCmdLine);
  2185. (*targets)[install_local] =
  2186. this->CreateGlobalTarget(
  2187. install_local, "Installing only the local directory...",
  2188. &cpackCommandLines, depends, 0);
  2189. }
  2190. // install_strip
  2191. const char* install_strip = this->GetInstallStripTargetName();
  2192. if((install_strip !=0) && (mf->IsSet("CMAKE_STRIP")))
  2193. {
  2194. cmCustomCommandLine stripCmdLine = singleLine;
  2195. stripCmdLine.insert(stripCmdLine.begin()+1,"-DCMAKE_INSTALL_DO_STRIP=1");
  2196. cpackCommandLines.erase(cpackCommandLines.begin(),
  2197. cpackCommandLines.end());
  2198. cpackCommandLines.push_back(stripCmdLine);
  2199. (*targets)[install_strip] =
  2200. this->CreateGlobalTarget(
  2201. install_strip, "Installing the project stripped...",
  2202. &cpackCommandLines, depends, 0);
  2203. }
  2204. }
  2205. }
  2206. //----------------------------------------------------------------------------
  2207. const char* cmGlobalGenerator::GetPredefinedTargetsFolder()
  2208. {
  2209. const char* prop =
  2210. this->GetCMakeInstance()->GetProperty("PREDEFINED_TARGETS_FOLDER");
  2211. if (prop)
  2212. {
  2213. return prop;
  2214. }
  2215. return "CMakePredefinedTargets";
  2216. }
  2217. //----------------------------------------------------------------------------
  2218. bool cmGlobalGenerator::UseFolderProperty()
  2219. {
  2220. const char* prop = this->GetCMakeInstance()->GetProperty("USE_FOLDERS");
  2221. // If this property is defined, let the setter turn this on or off...
  2222. //
  2223. if (prop)
  2224. {
  2225. return cmSystemTools::IsOn(prop);
  2226. }
  2227. // By default, this feature is OFF, since it is not supported in the
  2228. // Visual Studio Express editions until VS11:
  2229. //
  2230. return false;
  2231. }
  2232. //----------------------------------------------------------------------------
  2233. void cmGlobalGenerator::EnableMinGWLanguage(cmMakefile *mf)
  2234. {
  2235. this->FindMakeProgram(mf);
  2236. std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  2237. std::vector<std::string> locations;
  2238. locations.push_back(cmSystemTools::GetProgramPath(makeProgram.c_str()));
  2239. locations.push_back("/mingw/bin");
  2240. locations.push_back("c:/mingw/bin");
  2241. std::string tgcc = cmSystemTools::FindProgram("gcc", locations);
  2242. std::string gcc = "gcc.exe";
  2243. if(tgcc.size())
  2244. {
  2245. gcc = tgcc;
  2246. }
  2247. std::string tgxx = cmSystemTools::FindProgram("g++", locations);
  2248. std::string gxx = "g++.exe";
  2249. if(tgxx.size())
  2250. {
  2251. gxx = tgxx;
  2252. }
  2253. std::string trc = cmSystemTools::FindProgram("windres", locations);
  2254. std::string rc = "windres.exe";
  2255. if(trc.size())
  2256. {
  2257. rc = trc;
  2258. }
  2259. mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str());
  2260. mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str());
  2261. mf->AddDefinition("CMAKE_GENERATOR_RC", rc.c_str());
  2262. }
  2263. //----------------------------------------------------------------------------
  2264. cmTarget cmGlobalGenerator::CreateGlobalTarget(
  2265. const std::string& name, const char* message,
  2266. const cmCustomCommandLines* commandLines,
  2267. std::vector<std::string> depends,
  2268. const char* workingDirectory)
  2269. {
  2270. // Package
  2271. cmTarget target;
  2272. target.GetProperties().SetCMakeInstance(this->CMakeInstance);
  2273. target.SetType(cmTarget::GLOBAL_TARGET, name);
  2274. target.SetProperty("EXCLUDE_FROM_ALL","TRUE");
  2275. std::vector<std::string> no_outputs;
  2276. std::vector<std::string> no_depends;
  2277. // Store the custom command in the target.
  2278. cmCustomCommand cc(0, no_outputs, no_depends, *commandLines, 0,
  2279. workingDirectory);
  2280. target.AddPostBuildCommand(cc);
  2281. target.SetProperty("EchoString", message);
  2282. std::vector<std::string>::iterator dit;
  2283. for ( dit = depends.begin(); dit != depends.end(); ++ dit )
  2284. {
  2285. target.AddUtility(dit->c_str());
  2286. }
  2287. // Organize in the "predefined targets" folder:
  2288. //
  2289. if (this->UseFolderProperty())
  2290. {
  2291. target.SetProperty("FOLDER", this->GetPredefinedTargetsFolder());
  2292. }
  2293. return target;
  2294. }
  2295. //----------------------------------------------------------------------------
  2296. std::string
  2297. cmGlobalGenerator::GenerateRuleFile(std::string const& output) const
  2298. {
  2299. std::string ruleFile = output;
  2300. ruleFile += ".rule";
  2301. const char* dir = this->GetCMakeCFGIntDir();
  2302. if(dir && dir[0] == '$')
  2303. {
  2304. cmSystemTools::ReplaceString(ruleFile, dir,
  2305. cmake::GetCMakeFilesDirectory());
  2306. }
  2307. return ruleFile;
  2308. }
  2309. //----------------------------------------------------------------------------
  2310. std::string cmGlobalGenerator::GetSharedLibFlagsForLanguage(
  2311. std::string const& l) const
  2312. {
  2313. std::map<cmStdString, cmStdString>::const_iterator it =
  2314. this->LanguageToOriginalSharedLibFlags.find(l);
  2315. if(it != this->LanguageToOriginalSharedLibFlags.end())
  2316. {
  2317. return it->second;
  2318. }
  2319. return "";
  2320. }
  2321. //----------------------------------------------------------------------------
  2322. void cmGlobalGenerator::AppendDirectoryForConfig(const char*, const char*,
  2323. const char*, std::string&)
  2324. {
  2325. // Subclasses that support multiple configurations should implement
  2326. // this method to append the subdirectory for the given build
  2327. // configuration.
  2328. }
  2329. //----------------------------------------------------------------------------
  2330. cmGlobalGenerator::TargetDependSet const&
  2331. cmGlobalGenerator::GetTargetDirectDepends(cmTarget const& target)
  2332. {
  2333. return this->TargetDependencies[&target];
  2334. }
  2335. void cmGlobalGenerator::AddTarget(cmTarget* t)
  2336. {
  2337. if(t->IsImported())
  2338. {
  2339. this->ImportedTargets[t->GetName()] = t;
  2340. }
  2341. else
  2342. {
  2343. this->TotalTargets[t->GetName()] = t;
  2344. }
  2345. }
  2346. bool cmGlobalGenerator::IsReservedTarget(std::string const& name)
  2347. {
  2348. // The following is a list of targets reserved
  2349. // by one or more of the cmake generators.
  2350. // Adding additional targets to this list will require a policy!
  2351. const char* reservedTargets[] =
  2352. {
  2353. "all", "ALL_BUILD",
  2354. "help",
  2355. "install", "INSTALL",
  2356. "preinstall",
  2357. "clean",
  2358. "edit_cache",
  2359. "rebuild_cache",
  2360. "test", "RUN_TESTS",
  2361. "package", "PACKAGE",
  2362. "package_source",
  2363. "ZERO_CHECK",
  2364. 0
  2365. };
  2366. for(const char** reservedTarget = reservedTargets;
  2367. *reservedTarget; ++reservedTarget)
  2368. {
  2369. if(name == *reservedTarget) return true;
  2370. }
  2371. return false;
  2372. }
  2373. void cmGlobalGenerator::SetExternalMakefileProjectGenerator(
  2374. cmExternalMakefileProjectGenerator *extraGenerator)
  2375. {
  2376. this->ExtraGenerator = extraGenerator;
  2377. if (this->ExtraGenerator!=0)
  2378. {
  2379. this->ExtraGenerator->SetGlobalGenerator(this);
  2380. }
  2381. }
  2382. const char* cmGlobalGenerator::GetExtraGeneratorName() const
  2383. {
  2384. return this->ExtraGenerator==0 ? 0 : this->ExtraGenerator->GetName();
  2385. }
  2386. void cmGlobalGenerator::FileReplacedDuringGenerate(const std::string& filename)
  2387. {
  2388. this->FilesReplacedDuringGenerate.push_back(filename);
  2389. }
  2390. void
  2391. cmGlobalGenerator
  2392. ::GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames)
  2393. {
  2394. filenames.clear();
  2395. std::copy(
  2396. this->FilesReplacedDuringGenerate.begin(),
  2397. this->FilesReplacedDuringGenerate.end(),
  2398. std::back_inserter(filenames));
  2399. }
  2400. //----------------------------------------------------------------------------
  2401. void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets,
  2402. TargetDependSet& originalTargets,
  2403. cmLocalGenerator* root,
  2404. GeneratorVector const& generators)
  2405. {
  2406. // loop over all local generators
  2407. for(std::vector<cmLocalGenerator*>::const_iterator i = generators.begin();
  2408. i != generators.end(); ++i)
  2409. {
  2410. // check to make sure generator is not excluded
  2411. if(this->IsExcluded(root, *i))
  2412. {
  2413. continue;
  2414. }
  2415. cmMakefile* mf = (*i)->GetMakefile();
  2416. // Get the targets in the makefile
  2417. cmTargets &tgts = mf->GetTargets();
  2418. // loop over all the targets
  2419. for (cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  2420. {
  2421. cmTarget* target = &l->second;
  2422. if(this->IsRootOnlyTarget(target) &&
  2423. target->GetMakefile() != root->GetMakefile())
  2424. {
  2425. continue;
  2426. }
  2427. // put the target in the set of original targets
  2428. originalTargets.insert(target);
  2429. // Get the set of targets that depend on target
  2430. this->AddTargetDepends(target, projectTargets);
  2431. }
  2432. }
  2433. }
  2434. //----------------------------------------------------------------------------
  2435. bool cmGlobalGenerator::IsRootOnlyTarget(cmTarget* target) const
  2436. {
  2437. return (target->GetType() == cmTarget::GLOBAL_TARGET ||
  2438. target->GetName() == this->GetAllTargetName());
  2439. }
  2440. //----------------------------------------------------------------------------
  2441. void cmGlobalGenerator::AddTargetDepends(cmTarget const* target,
  2442. TargetDependSet& projectTargets)
  2443. {
  2444. // add the target itself
  2445. if(projectTargets.insert(target).second)
  2446. {
  2447. // This is the first time we have encountered the target.
  2448. // Recursively follow its dependencies.
  2449. TargetDependSet const& ts = this->GetTargetDirectDepends(*target);
  2450. for(TargetDependSet::const_iterator i = ts.begin(); i != ts.end(); ++i)
  2451. {
  2452. cmTarget const* dtarget = *i;
  2453. this->AddTargetDepends(dtarget, projectTargets);
  2454. }
  2455. }
  2456. }
  2457. //----------------------------------------------------------------------------
  2458. void cmGlobalGenerator::AddToManifest(const char* config,
  2459. std::string const& f)
  2460. {
  2461. // Add to the main manifest for this configuration.
  2462. this->TargetManifest[config].insert(f);
  2463. // Add to the content listing for the file's directory.
  2464. std::string dir = cmSystemTools::GetFilenamePath(f);
  2465. std::string file = cmSystemTools::GetFilenameName(f);
  2466. this->DirectoryContentMap[dir].insert(file);
  2467. }
  2468. //----------------------------------------------------------------------------
  2469. std::set<cmStdString> const&
  2470. cmGlobalGenerator::GetDirectoryContent(std::string const& dir, bool needDisk)
  2471. {
  2472. DirectoryContent& dc = this->DirectoryContentMap[dir];
  2473. if(needDisk && !dc.LoadedFromDisk)
  2474. {
  2475. // Load the directory content from disk.
  2476. cmsys::Directory d;
  2477. if(d.Load(dir.c_str()))
  2478. {
  2479. unsigned long n = d.GetNumberOfFiles();
  2480. for(unsigned long i = 0; i < n; ++i)
  2481. {
  2482. const char* f = d.GetFile(i);
  2483. if(strcmp(f, ".") != 0 && strcmp(f, "..") != 0)
  2484. {
  2485. dc.insert(f);
  2486. }
  2487. }
  2488. }
  2489. dc.LoadedFromDisk = true;
  2490. }
  2491. return dc;
  2492. }
  2493. //----------------------------------------------------------------------------
  2494. void
  2495. cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs,
  2496. std::string const& content)
  2497. {
  2498. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2499. // Ignore if there are no outputs.
  2500. if(outputs.empty())
  2501. {
  2502. return;
  2503. }
  2504. // Compute a hash of the rule.
  2505. RuleHash hash;
  2506. {
  2507. unsigned char const* data =
  2508. reinterpret_cast<unsigned char const*>(content.c_str());
  2509. int length = static_cast<int>(content.length());
  2510. cmsysMD5* sum = cmsysMD5_New();
  2511. cmsysMD5_Initialize(sum);
  2512. cmsysMD5_Append(sum, data, length);
  2513. cmsysMD5_FinalizeHex(sum, hash.Data);
  2514. cmsysMD5_Delete(sum);
  2515. }
  2516. // Shorten the output name (in expected use case).
  2517. cmLocalGenerator* lg = this->GetLocalGenerators()[0];
  2518. std::string fname = lg->Convert(outputs[0].c_str(),
  2519. cmLocalGenerator::HOME_OUTPUT);
  2520. // Associate the hash with this output.
  2521. this->RuleHashes[fname] = hash;
  2522. #else
  2523. (void)outputs;
  2524. (void)content;
  2525. #endif
  2526. }
  2527. //----------------------------------------------------------------------------
  2528. void cmGlobalGenerator::CheckRuleHashes()
  2529. {
  2530. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2531. std::string home = this->GetCMakeInstance()->GetHomeOutputDirectory();
  2532. std::string pfile = home;
  2533. pfile += this->GetCMakeInstance()->GetCMakeFilesDirectory();
  2534. pfile += "/CMakeRuleHashes.txt";
  2535. this->CheckRuleHashes(pfile, home);
  2536. this->WriteRuleHashes(pfile);
  2537. #endif
  2538. }
  2539. //----------------------------------------------------------------------------
  2540. void cmGlobalGenerator::CheckRuleHashes(std::string const& pfile,
  2541. std::string const& home)
  2542. {
  2543. #if defined(_WIN32) || defined(__CYGWIN__)
  2544. cmsys::ifstream fin(pfile.c_str(), std::ios::in | std::ios::binary);
  2545. #else
  2546. cmsys::ifstream fin(pfile.c_str(), std::ios::in);
  2547. #endif
  2548. if(!fin)
  2549. {
  2550. return;
  2551. }
  2552. std::string line;
  2553. std::string fname;
  2554. while(cmSystemTools::GetLineFromStream(fin, line))
  2555. {
  2556. // Line format is a 32-byte hex string followed by a space
  2557. // followed by a file name (with no escaping).
  2558. // Skip blank and comment lines.
  2559. if(line.size() < 34 || line[0] == '#')
  2560. {
  2561. continue;
  2562. }
  2563. // Get the filename.
  2564. fname = line.substr(33, line.npos);
  2565. // Look for a hash for this file's rule.
  2566. std::map<cmStdString, RuleHash>::const_iterator rhi =
  2567. this->RuleHashes.find(fname);
  2568. if(rhi != this->RuleHashes.end())
  2569. {
  2570. // Compare the rule hash in the file to that we were given.
  2571. if(strncmp(line.c_str(), rhi->second.Data, 32) != 0)
  2572. {
  2573. // The rule has changed. Delete the output so it will be
  2574. // built again.
  2575. fname = cmSystemTools::CollapseFullPath(fname.c_str(), home.c_str());
  2576. cmSystemTools::RemoveFile(fname.c_str());
  2577. }
  2578. }
  2579. else
  2580. {
  2581. // We have no hash for a rule previously listed. This may be a
  2582. // case where a user has turned off a build option and might
  2583. // want to turn it back on later, so do not delete the file.
  2584. // Instead, we keep the rule hash as long as the file exists so
  2585. // that if the feature is turned back on and the rule has
  2586. // changed the file is still rebuilt.
  2587. std::string fpath =
  2588. cmSystemTools::CollapseFullPath(fname.c_str(), home.c_str());
  2589. if(cmSystemTools::FileExists(fpath.c_str()))
  2590. {
  2591. RuleHash hash;
  2592. strncpy(hash.Data, line.c_str(), 32);
  2593. this->RuleHashes[fname] = hash;
  2594. }
  2595. }
  2596. }
  2597. }
  2598. //----------------------------------------------------------------------------
  2599. void cmGlobalGenerator::WriteRuleHashes(std::string const& pfile)
  2600. {
  2601. // Now generate a new persistence file with the current hashes.
  2602. if(this->RuleHashes.empty())
  2603. {
  2604. cmSystemTools::RemoveFile(pfile.c_str());
  2605. }
  2606. else
  2607. {
  2608. cmGeneratedFileStream fout(pfile.c_str());
  2609. fout << "# Hashes of file build rules.\n";
  2610. for(std::map<cmStdString, RuleHash>::const_iterator
  2611. rhi = this->RuleHashes.begin(); rhi != this->RuleHashes.end(); ++rhi)
  2612. {
  2613. fout.write(rhi->second.Data, 32);
  2614. fout << " " << rhi->first << "\n";
  2615. }
  2616. }
  2617. }
  2618. //----------------------------------------------------------------------------
  2619. void cmGlobalGenerator::WriteSummary()
  2620. {
  2621. cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
  2622. // Record all target directories in a central location.
  2623. std::string fname = mf->GetHomeOutputDirectory();
  2624. fname += cmake::GetCMakeFilesDirectory();
  2625. fname += "/TargetDirectories.txt";
  2626. cmGeneratedFileStream fout(fname.c_str());
  2627. // Generate summary information files for each target.
  2628. for(std::map<cmStdString,cmTarget *>::const_iterator ti =
  2629. this->TotalTargets.begin(); ti != this->TotalTargets.end(); ++ti)
  2630. {
  2631. if ((ti->second)->GetType() == cmTarget::INTERFACE_LIBRARY)
  2632. {
  2633. continue;
  2634. }
  2635. this->WriteSummary(ti->second);
  2636. fout << ti->second->GetSupportDirectory() << "\n";
  2637. }
  2638. }
  2639. //----------------------------------------------------------------------------
  2640. void cmGlobalGenerator::WriteSummary(cmTarget* target)
  2641. {
  2642. // Place the labels file in a per-target support directory.
  2643. std::string dir = target->GetSupportDirectory();
  2644. std::string file = dir;
  2645. file += "/Labels.txt";
  2646. // Check whether labels are enabled for this target.
  2647. if(const char* value = target->GetProperty("LABELS"))
  2648. {
  2649. cmSystemTools::MakeDirectory(dir.c_str());
  2650. cmGeneratedFileStream fout(file.c_str());
  2651. // List the target-wide labels. All sources in the target get
  2652. // these labels.
  2653. std::vector<std::string> labels;
  2654. cmSystemTools::ExpandListArgument(value, labels);
  2655. if(!labels.empty())
  2656. {
  2657. fout << "# Target labels\n";
  2658. for(std::vector<std::string>::const_iterator li = labels.begin();
  2659. li != labels.end(); ++li)
  2660. {
  2661. fout << " " << *li << "\n";
  2662. }
  2663. }
  2664. // List the source files with any per-source labels.
  2665. fout << "# Source files and their labels\n";
  2666. std::vector<cmSourceFile*> sources;
  2667. target->GetSourceFiles(sources);
  2668. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  2669. si != sources.end(); ++si)
  2670. {
  2671. cmSourceFile* sf = *si;
  2672. fout << sf->GetFullPath() << "\n";
  2673. if(const char* svalue = sf->GetProperty("LABELS"))
  2674. {
  2675. labels.clear();
  2676. cmSystemTools::ExpandListArgument(svalue, labels);
  2677. for(std::vector<std::string>::const_iterator li = labels.begin();
  2678. li != labels.end(); ++li)
  2679. {
  2680. fout << " " << *li << "\n";
  2681. }
  2682. }
  2683. }
  2684. }
  2685. else
  2686. {
  2687. cmSystemTools::RemoveFile(file.c_str());
  2688. }
  2689. }
  2690. //----------------------------------------------------------------------------
  2691. // static
  2692. std::string cmGlobalGenerator::EscapeJSON(const std::string& s) {
  2693. std::string result;
  2694. for (std::string::size_type i = 0; i < s.size(); ++i) {
  2695. if (s[i] == '"' || s[i] == '\\') {
  2696. result += '\\';
  2697. }
  2698. result += s[i];
  2699. }
  2700. return result;
  2701. }
  2702. //----------------------------------------------------------------------------
  2703. void cmGlobalGenerator::AddEvaluationFile(const std::string &inputFile,
  2704. cmsys::auto_ptr<cmCompiledGeneratorExpression> outputExpr,
  2705. cmMakefile *makefile,
  2706. cmsys::auto_ptr<cmCompiledGeneratorExpression> condition,
  2707. bool inputIsContent)
  2708. {
  2709. this->EvaluationFiles.push_back(
  2710. new cmGeneratorExpressionEvaluationFile(inputFile, outputExpr,
  2711. makefile, condition,
  2712. inputIsContent));
  2713. }
  2714. //----------------------------------------------------------------------------
  2715. void cmGlobalGenerator::ProcessEvaluationFiles()
  2716. {
  2717. std::set<std::string> generatedFiles;
  2718. for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
  2719. li = this->EvaluationFiles.begin();
  2720. li != this->EvaluationFiles.end();
  2721. ++li)
  2722. {
  2723. (*li)->Generate();
  2724. if (cmSystemTools::GetFatalErrorOccured())
  2725. {
  2726. return;
  2727. }
  2728. std::vector<std::string> files = (*li)->GetFiles();
  2729. for(std::vector<std::string>::const_iterator fi = files.begin();
  2730. fi != files.end(); ++fi)
  2731. {
  2732. if (!generatedFiles.insert(*fi).second)
  2733. {
  2734. cmSystemTools::Error("File to be generated by multiple different "
  2735. "commands: ", fi->c_str());
  2736. return;
  2737. }
  2738. }
  2739. }
  2740. }
  2741. //----------------------------------------------------------------------------
  2742. std::string cmGlobalGenerator::ExpandCFGIntDir(const std::string& str,
  2743. const std::string& /*config*/) const
  2744. {
  2745. return str;
  2746. }