cmGlobalGenerator.cxx 95 KB

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