cmGlobalGenerator.cxx 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060
  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 "cmCPackPropertiesGenerator.h"
  29. #include <cmsys/Directory.hxx>
  30. #include <cmsys/FStream.hxx>
  31. #if defined(CMAKE_BUILD_WITH_CMAKE)
  32. # include <cmsys/MD5.h>
  33. #endif
  34. #include <stdlib.h> // required for atof
  35. #include <assert.h>
  36. cmGlobalGenerator::cmGlobalGenerator()
  37. {
  38. // By default the .SYMBOLIC dependency is not needed on symbolic rules.
  39. this->NeedSymbolicMark = false;
  40. // by default use the native paths
  41. this->ForceUnixPaths = false;
  42. // By default do not try to support color.
  43. this->ToolSupportsColor = false;
  44. // By default do not use link scripts.
  45. this->UseLinkScript = false;
  46. // Whether an install target is needed.
  47. this->InstallTargetEnabled = false;
  48. // how long to let try compiles run
  49. this->TryCompileTimeout = 0;
  50. this->ExtraGenerator = 0;
  51. this->CurrentLocalGenerator = 0;
  52. this->TryCompileOuterMakefile = 0;
  53. }
  54. cmGlobalGenerator::~cmGlobalGenerator()
  55. {
  56. this->ClearGeneratorMembers();
  57. if (this->ExtraGenerator)
  58. {
  59. delete this->ExtraGenerator;
  60. }
  61. }
  62. bool cmGlobalGenerator::SetGeneratorToolset(std::string const& ts)
  63. {
  64. cmOStringStream e;
  65. e <<
  66. "Generator\n"
  67. " " << this->GetName() << "\n"
  68. "does not support toolset specification, but toolset\n"
  69. " " << ts << "\n"
  70. "was specified.";
  71. this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(),
  72. cmListFileBacktrace());
  73. return false;
  74. }
  75. std::string cmGlobalGenerator::SelectMakeProgram(
  76. const std::string& inMakeProgram,
  77. const std::string& makeDefault) const
  78. {
  79. std::string makeProgram = inMakeProgram;
  80. if(cmSystemTools::IsOff(makeProgram.c_str()))
  81. {
  82. const char* makeProgramCSTR =
  83. this->CMakeInstance->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
  84. if(cmSystemTools::IsOff(makeProgramCSTR))
  85. {
  86. makeProgram = makeDefault;
  87. }
  88. else
  89. {
  90. makeProgram = makeProgramCSTR;
  91. }
  92. if(cmSystemTools::IsOff(makeProgram.c_str()) &&
  93. !makeProgram.empty())
  94. {
  95. makeProgram = "CMAKE_MAKE_PROGRAM-NOTFOUND";
  96. }
  97. }
  98. return makeProgram;
  99. }
  100. void cmGlobalGenerator::ResolveLanguageCompiler(const std::string &lang,
  101. cmMakefile *mf,
  102. bool optional) const
  103. {
  104. std::string langComp = "CMAKE_";
  105. langComp += lang;
  106. langComp += "_COMPILER";
  107. if(!mf->GetDefinition(langComp))
  108. {
  109. if(!optional)
  110. {
  111. cmSystemTools::Error(langComp.c_str(),
  112. " not set, after EnableLanguage");
  113. }
  114. return;
  115. }
  116. const char* name = mf->GetRequiredDefinition(langComp);
  117. std::string path;
  118. if(!cmSystemTools::FileIsFullPath(name))
  119. {
  120. path = cmSystemTools::FindProgram(name);
  121. }
  122. else
  123. {
  124. path = name;
  125. }
  126. if((path.size() == 0 || !cmSystemTools::FileExists(path.c_str()))
  127. && (optional==false))
  128. {
  129. return;
  130. }
  131. std::string doc = lang;
  132. doc += " compiler.";
  133. const char* cname = this->GetCMakeInstance()->
  134. GetCacheManager()->GetCacheValue(langComp);
  135. std::string changeVars;
  136. if(cname && !optional)
  137. {
  138. std::string cnameString;
  139. if(!cmSystemTools::FileIsFullPath(cname))
  140. {
  141. cnameString = cmSystemTools::FindProgram(cname);
  142. }
  143. else
  144. {
  145. cnameString = cname;
  146. }
  147. std::string pathString = path;
  148. // get rid of potentially multiple slashes:
  149. cmSystemTools::ConvertToUnixSlashes(cnameString);
  150. cmSystemTools::ConvertToUnixSlashes(pathString);
  151. if (cnameString != pathString)
  152. {
  153. const char* cvars =
  154. this->GetCMakeInstance()->GetProperty(
  155. "__CMAKE_DELETE_CACHE_CHANGE_VARS_");
  156. if(cvars)
  157. {
  158. changeVars += cvars;
  159. changeVars += ";";
  160. }
  161. changeVars += langComp;
  162. changeVars += ";";
  163. changeVars += cname;
  164. this->GetCMakeInstance()->SetProperty(
  165. "__CMAKE_DELETE_CACHE_CHANGE_VARS_",
  166. changeVars.c_str());
  167. }
  168. }
  169. mf->AddCacheDefinition(langComp, path.c_str(),
  170. doc.c_str(), cmCacheManager::FILEPATH);
  171. }
  172. void cmGlobalGenerator::AddBuildExportSet(cmExportBuildFileGenerator* gen)
  173. {
  174. this->BuildExportSets[gen->GetMainExportFileName()] = gen;
  175. }
  176. void
  177. cmGlobalGenerator::AddBuildExportExportSet(cmExportBuildFileGenerator* gen)
  178. {
  179. this->BuildExportSets[gen->GetMainExportFileName()] = gen;
  180. this->BuildExportExportSets[gen->GetMainExportFileName()] = gen;
  181. }
  182. bool cmGlobalGenerator::GenerateImportFile(const std::string &file)
  183. {
  184. std::map<std::string, cmExportBuildFileGenerator*>::iterator it
  185. = this->BuildExportSets.find(file);
  186. if (it != this->BuildExportSets.end())
  187. {
  188. bool result = it->second->GenerateImportFile();
  189. delete it->second;
  190. it->second = 0;
  191. this->BuildExportSets.erase(it);
  192. return result;
  193. }
  194. return false;
  195. }
  196. void cmGlobalGenerator::ForceLinkerLanguages()
  197. {
  198. }
  199. bool
  200. cmGlobalGenerator::IsExportedTargetsFile(const std::string &filename) const
  201. {
  202. const std::map<std::string, cmExportBuildFileGenerator*>::const_iterator it
  203. = this->BuildExportSets.find(filename);
  204. if (it == this->BuildExportSets.end())
  205. {
  206. return false;
  207. }
  208. return this->BuildExportExportSets.find(filename)
  209. == this->BuildExportExportSets.end();
  210. }
  211. // Find the make program for the generator, required for try compiles
  212. void cmGlobalGenerator::FindMakeProgram(cmMakefile* mf)
  213. {
  214. if(this->FindMakeProgramFile.size() == 0)
  215. {
  216. cmSystemTools::Error(
  217. "Generator implementation error, "
  218. "all generators must specify this->FindMakeProgramFile");
  219. }
  220. if(!mf->GetDefinition("CMAKE_MAKE_PROGRAM")
  221. || cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM")))
  222. {
  223. std::string setMakeProgram =
  224. mf->GetModulesFile(this->FindMakeProgramFile.c_str());
  225. if(setMakeProgram.size())
  226. {
  227. mf->ReadListFile(0, setMakeProgram.c_str());
  228. }
  229. }
  230. if(!mf->GetDefinition("CMAKE_MAKE_PROGRAM")
  231. || cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM")))
  232. {
  233. cmOStringStream err;
  234. err << "CMake was unable to find a build program corresponding to \""
  235. << this->GetName() << "\". CMAKE_MAKE_PROGRAM is not set. You "
  236. << "probably need to select a different build tool.";
  237. cmSystemTools::Error(err.str().c_str());
  238. cmSystemTools::SetFatalErrorOccured();
  239. return;
  240. }
  241. std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  242. // if there are spaces in the make program use short path
  243. // but do not short path the actual program name, as
  244. // this can cause trouble with VSExpress
  245. if(makeProgram.find(' ') != makeProgram.npos)
  246. {
  247. std::string dir;
  248. std::string file;
  249. cmSystemTools::SplitProgramPath(makeProgram.c_str(),
  250. dir, file);
  251. std::string saveFile = file;
  252. cmSystemTools::GetShortPath(makeProgram.c_str(), makeProgram);
  253. cmSystemTools::SplitProgramPath(makeProgram.c_str(),
  254. dir, file);
  255. makeProgram = dir;
  256. makeProgram += "/";
  257. makeProgram += saveFile;
  258. mf->AddCacheDefinition("CMAKE_MAKE_PROGRAM", makeProgram.c_str(),
  259. "make program",
  260. cmCacheManager::FILEPATH);
  261. }
  262. if(makeProgram.find("xcodebuild") != makeProgram.npos)
  263. {
  264. // due to the text file busy /bin/sh problem with xcodebuild
  265. // use the cmakexbuild wrapper instead. This program
  266. // will run xcodebuild and if it sees the error text file busy
  267. // it will stop forwarding output, and let the build finish.
  268. // Then it will retry the build. It will continue this
  269. // untill no text file busy errors occur.
  270. std::string cmakexbuild =
  271. this->CMakeInstance->GetCacheManager()->GetCacheValue("CMAKE_COMMAND");
  272. cmakexbuild = cmakexbuild.substr(0, cmakexbuild.length()-5);
  273. cmakexbuild += "cmakexbuild";
  274. mf->AddCacheDefinition("CMAKE_MAKE_PROGRAM",
  275. cmakexbuild.c_str(),
  276. "make program",
  277. cmCacheManager::FILEPATH);
  278. }
  279. }
  280. // enable the given language
  281. //
  282. // The following files are loaded in this order:
  283. //
  284. // First figure out what OS we are running on:
  285. //
  286. // CMakeSystem.cmake - configured file created by CMakeDetermineSystem.cmake
  287. // CMakeDetermineSystem.cmake - figure out os info and create
  288. // CMakeSystem.cmake IF CMAKE_SYSTEM
  289. // not set
  290. // CMakeSystem.cmake - configured file created by
  291. // CMakeDetermineSystem.cmake IF CMAKE_SYSTEM_LOADED
  292. // CMakeSystemSpecificInitialize.cmake
  293. // - includes Platform/${CMAKE_SYSTEM_NAME}-Initialize.cmake
  294. // Next try and enable all languages found in the languages vector
  295. //
  296. // FOREACH LANG in languages
  297. // CMake(LANG)Compiler.cmake - configured file create by
  298. // CMakeDetermine(LANG)Compiler.cmake
  299. // CMakeDetermine(LANG)Compiler.cmake - Finds compiler for LANG and
  300. // creates CMake(LANG)Compiler.cmake
  301. // CMake(LANG)Compiler.cmake - configured file created by
  302. // CMakeDetermine(LANG)Compiler.cmake
  303. //
  304. // CMakeSystemSpecificInformation.cmake
  305. // - includes Platform/${CMAKE_SYSTEM_NAME}.cmake
  306. // may use compiler stuff
  307. // FOREACH LANG in languages
  308. // CMake(LANG)Information.cmake
  309. // - loads Platform/${CMAKE_SYSTEM_NAME}-${COMPILER}.cmake
  310. // CMakeTest(LANG)Compiler.cmake
  311. // - Make sure the compiler works with a try compile if
  312. // CMakeDetermine(LANG) was loaded
  313. //
  314. // Now load a few files that can override values set in any of the above
  315. // (PROJECTNAME)Compatibility.cmake
  316. // - load any backwards compatibility stuff for current project
  317. // ${CMAKE_USER_MAKE_RULES_OVERRIDE}
  318. // - allow users a chance to override system variables
  319. //
  320. //
  321. void
  322. cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages,
  323. cmMakefile *mf, bool optional)
  324. {
  325. if(languages.size() == 0)
  326. {
  327. cmSystemTools::Error("EnableLanguage must have a lang specified!");
  328. cmSystemTools::SetFatalErrorOccured();
  329. return;
  330. }
  331. if(this->TryCompileOuterMakefile)
  332. {
  333. // In a try-compile we can only enable languages provided by caller.
  334. for(std::vector<std::string>::const_iterator li = languages.begin();
  335. li != languages.end(); ++li)
  336. {
  337. if(*li == "NONE")
  338. {
  339. this->SetLanguageEnabled("NONE", mf);
  340. }
  341. else
  342. {
  343. const char* lang = li->c_str();
  344. if(this->LanguagesReady.find(lang) == this->LanguagesReady.end())
  345. {
  346. cmOStringStream e;
  347. e << "The test project needs language "
  348. << lang << " which is not enabled.";
  349. this->TryCompileOuterMakefile
  350. ->IssueMessage(cmake::FATAL_ERROR, e.str());
  351. cmSystemTools::SetFatalErrorOccured();
  352. return;
  353. }
  354. }
  355. }
  356. }
  357. bool fatalError = false;
  358. mf->AddDefinition("RUN_CONFIGURE", true);
  359. std::string rootBin = mf->GetHomeOutputDirectory();
  360. rootBin += cmake::GetCMakeFilesDirectory();
  361. // If the configuration files path has been set,
  362. // then we are in a try compile and need to copy the enable language
  363. // files from the parent cmake bin dir, into the try compile bin dir
  364. if(this->ConfiguredFilesPath.size())
  365. {
  366. rootBin = this->ConfiguredFilesPath;
  367. }
  368. rootBin += "/";
  369. rootBin += cmVersion::GetCMakeVersion();
  370. // set the dir for parent files so they can be used by modules
  371. mf->AddDefinition("CMAKE_PLATFORM_INFO_DIR",rootBin.c_str());
  372. // find and make sure CMAKE_MAKE_PROGRAM is defined
  373. this->FindMakeProgram(mf);
  374. // try and load the CMakeSystem.cmake if it is there
  375. std::string fpath = rootBin;
  376. if(!mf->GetDefinition("CMAKE_SYSTEM_LOADED"))
  377. {
  378. fpath += "/CMakeSystem.cmake";
  379. if(cmSystemTools::FileExists(fpath.c_str()))
  380. {
  381. mf->ReadListFile(0,fpath.c_str());
  382. }
  383. }
  384. // Load the CMakeDetermineSystem.cmake file and find out
  385. // what platform we are running on
  386. if (!mf->GetDefinition("CMAKE_SYSTEM"))
  387. {
  388. #if defined(_WIN32) && !defined(__CYGWIN__)
  389. /* Windows version number data. */
  390. OSVERSIONINFO osvi;
  391. ZeroMemory(&osvi, sizeof(osvi));
  392. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  393. GetVersionEx (&osvi);
  394. cmOStringStream windowsVersionString;
  395. windowsVersionString << osvi.dwMajorVersion << "." << osvi.dwMinorVersion;
  396. windowsVersionString.str();
  397. mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION",
  398. windowsVersionString.str().c_str());
  399. #endif
  400. // Read the DetermineSystem file
  401. std::string systemFile = mf->GetModulesFile("CMakeDetermineSystem.cmake");
  402. mf->ReadListFile(0, systemFile.c_str());
  403. // load the CMakeSystem.cmake from the binary directory
  404. // this file is configured by the CMakeDetermineSystem.cmake file
  405. fpath = rootBin;
  406. fpath += "/CMakeSystem.cmake";
  407. mf->ReadListFile(0,fpath.c_str());
  408. }
  409. // **** Load the system specific initialization if not yet loaded
  410. if (!mf->GetDefinition("CMAKE_SYSTEM_SPECIFIC_INITIALIZE_LOADED"))
  411. {
  412. fpath = mf->GetModulesFile("CMakeSystemSpecificInitialize.cmake");
  413. if(!mf->ReadListFile(0,fpath.c_str()))
  414. {
  415. cmSystemTools::Error("Could not find cmake module file: ",
  416. fpath.c_str());
  417. }
  418. }
  419. std::map<std::string, bool> needTestLanguage;
  420. std::map<std::string, bool> needSetLanguageEnabledMaps;
  421. // foreach language
  422. // load the CMakeDetermine(LANG)Compiler.cmake file to find
  423. // the compiler
  424. for(std::vector<std::string>::const_iterator l = languages.begin();
  425. l != languages.end(); ++l)
  426. {
  427. const char* lang = l->c_str();
  428. needSetLanguageEnabledMaps[lang] = false;
  429. if(*l == "NONE")
  430. {
  431. this->SetLanguageEnabled("NONE", mf);
  432. continue;
  433. }
  434. std::string loadedLang = "CMAKE_";
  435. loadedLang += lang;
  436. loadedLang += "_COMPILER_LOADED";
  437. if(!mf->GetDefinition(loadedLang))
  438. {
  439. fpath = rootBin;
  440. fpath += "/CMake";
  441. fpath += lang;
  442. fpath += "Compiler.cmake";
  443. // If the existing build tree was already configured with this
  444. // version of CMake then try to load the configured file first
  445. // to avoid duplicate compiler tests.
  446. if(cmSystemTools::FileExists(fpath.c_str()))
  447. {
  448. if(!mf->ReadListFile(0,fpath.c_str()))
  449. {
  450. cmSystemTools::Error("Could not find cmake module file: ",
  451. fpath.c_str());
  452. }
  453. // if this file was found then the language was already determined
  454. // to be working
  455. needTestLanguage[lang] = false;
  456. this->SetLanguageEnabledFlag(lang, mf);
  457. needSetLanguageEnabledMaps[lang] = true;
  458. // this can only be called after loading CMake(LANG)Compiler.cmake
  459. }
  460. }
  461. if(!this->GetLanguageEnabled(lang) )
  462. {
  463. if (this->CMakeInstance->GetIsInTryCompile())
  464. {
  465. cmSystemTools::Error("This should not have happened. "
  466. "If you see this message, you are probably "
  467. "using a broken CMakeLists.txt file or a "
  468. "problematic release of CMake");
  469. }
  470. // if the CMake(LANG)Compiler.cmake file was not found then
  471. // load CMakeDetermine(LANG)Compiler.cmake
  472. std::string determineCompiler = "CMakeDetermine";
  473. determineCompiler += lang;
  474. determineCompiler += "Compiler.cmake";
  475. std::string determineFile =
  476. mf->GetModulesFile(determineCompiler.c_str());
  477. if(!mf->ReadListFile(0,determineFile.c_str()))
  478. {
  479. cmSystemTools::Error("Could not find cmake module file: ",
  480. determineFile.c_str());
  481. }
  482. needTestLanguage[lang] = true;
  483. // Some generators like visual studio should not use the env variables
  484. // So the global generator can specify that in this variable
  485. if(!mf->GetDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV"))
  486. {
  487. // put ${CMake_(LANG)_COMPILER_ENV_VAR}=${CMAKE_(LANG)_COMPILER
  488. // into the environment, in case user scripts want to run
  489. // configure, or sub cmakes
  490. std::string compilerName = "CMAKE_";
  491. compilerName += lang;
  492. compilerName += "_COMPILER";
  493. std::string compilerEnv = "CMAKE_";
  494. compilerEnv += lang;
  495. compilerEnv += "_COMPILER_ENV_VAR";
  496. std::string envVar = mf->GetRequiredDefinition(compilerEnv);
  497. std::string envVarValue =
  498. mf->GetRequiredDefinition(compilerName);
  499. std::string env = envVar;
  500. env += "=";
  501. env += envVarValue;
  502. cmSystemTools::PutEnv(env.c_str());
  503. }
  504. // if determineLanguage was called then load the file it
  505. // configures CMake(LANG)Compiler.cmake
  506. fpath = rootBin;
  507. fpath += "/CMake";
  508. fpath += lang;
  509. fpath += "Compiler.cmake";
  510. if(!mf->ReadListFile(0,fpath.c_str()))
  511. {
  512. cmSystemTools::Error("Could not find cmake module file: ",
  513. fpath.c_str());
  514. }
  515. this->SetLanguageEnabledFlag(lang, mf);
  516. needSetLanguageEnabledMaps[lang] = true;
  517. // this can only be called after loading CMake(LANG)Compiler.cmake
  518. // the language must be enabled for try compile to work, but we do
  519. // not know if it is a working compiler yet so set the test language
  520. // flag
  521. needTestLanguage[lang] = true;
  522. } // end if(!this->GetLanguageEnabled(lang) )
  523. } // end loop over languages
  524. // **** Load the system specific information if not yet loaded
  525. if (!mf->GetDefinition("CMAKE_SYSTEM_SPECIFIC_INFORMATION_LOADED"))
  526. {
  527. fpath = mf->GetModulesFile("CMakeSystemSpecificInformation.cmake");
  528. if(!mf->ReadListFile(0,fpath.c_str()))
  529. {
  530. cmSystemTools::Error("Could not find cmake module file: ",
  531. fpath.c_str());
  532. }
  533. }
  534. // loop over languages again loading CMake(LANG)Information.cmake
  535. //
  536. for(std::vector<std::string>::const_iterator l = languages.begin();
  537. l != languages.end(); ++l)
  538. {
  539. const char* lang = l->c_str();
  540. if(*l == "NONE")
  541. {
  542. this->SetLanguageEnabled("NONE", mf);
  543. continue;
  544. }
  545. // Check that the compiler was found.
  546. std::string compilerName = "CMAKE_";
  547. compilerName += lang;
  548. compilerName += "_COMPILER";
  549. std::string compilerEnv = "CMAKE_";
  550. compilerEnv += lang;
  551. compilerEnv += "_COMPILER_ENV_VAR";
  552. cmOStringStream noCompiler;
  553. const char* compilerFile = mf->GetDefinition(compilerName);
  554. if(!compilerFile || !*compilerFile ||
  555. cmSystemTools::IsNOTFOUND(compilerFile))
  556. {
  557. noCompiler <<
  558. "No " << compilerName << " could be found.\n"
  559. ;
  560. }
  561. else if(strcmp(lang, "RC") != 0)
  562. {
  563. if(!cmSystemTools::FileIsFullPath(compilerFile))
  564. {
  565. noCompiler <<
  566. "The " << compilerName << ":\n"
  567. " " << compilerFile << "\n"
  568. "is not a full path and was not found in the PATH.\n"
  569. ;
  570. }
  571. else if(!cmSystemTools::FileExists(compilerFile))
  572. {
  573. noCompiler <<
  574. "The " << compilerName << ":\n"
  575. " " << compilerFile << "\n"
  576. "is not a full path to an existing compiler tool.\n"
  577. ;
  578. }
  579. }
  580. if(!noCompiler.str().empty())
  581. {
  582. // Skip testing this language since the compiler is not found.
  583. needTestLanguage[lang] = false;
  584. if(!optional)
  585. {
  586. // The compiler was not found and it is not optional. Remove
  587. // CMake(LANG)Compiler.cmake so we try again next time CMake runs.
  588. std::string compilerLangFile = rootBin;
  589. compilerLangFile += "/CMake";
  590. compilerLangFile += lang;
  591. compilerLangFile += "Compiler.cmake";
  592. cmSystemTools::RemoveFile(compilerLangFile.c_str());
  593. if(!this->CMakeInstance->GetIsInTryCompile())
  594. {
  595. this->PrintCompilerAdvice(noCompiler, lang,
  596. mf->GetDefinition(compilerEnv));
  597. mf->IssueMessage(cmake::FATAL_ERROR, noCompiler.str());
  598. fatalError = true;
  599. }
  600. }
  601. }
  602. std::string langLoadedVar = "CMAKE_";
  603. langLoadedVar += lang;
  604. langLoadedVar += "_INFORMATION_LOADED";
  605. if (!mf->GetDefinition(langLoadedVar))
  606. {
  607. fpath = "CMake";
  608. fpath += lang;
  609. fpath += "Information.cmake";
  610. std::string informationFile = mf->GetModulesFile(fpath.c_str());
  611. if (informationFile.empty())
  612. {
  613. cmSystemTools::Error("Could not find cmake module file: ",
  614. fpath.c_str());
  615. }
  616. else if(!mf->ReadListFile(0, informationFile.c_str()))
  617. {
  618. cmSystemTools::Error("Could not process cmake module file: ",
  619. informationFile.c_str());
  620. }
  621. }
  622. if (needSetLanguageEnabledMaps[lang])
  623. {
  624. this->SetLanguageEnabledMaps(lang, mf);
  625. }
  626. this->LanguagesReady.insert(lang);
  627. // Test the compiler for the language just setup
  628. // (but only if a compiler has been actually found)
  629. // At this point we should have enough info for a try compile
  630. // which is used in the backward stuff
  631. // If the language is untested then test it now with a try compile.
  632. if(needTestLanguage[lang])
  633. {
  634. if (!this->CMakeInstance->GetIsInTryCompile())
  635. {
  636. std::string testLang = "CMakeTest";
  637. testLang += lang;
  638. testLang += "Compiler.cmake";
  639. std::string ifpath = mf->GetModulesFile(testLang.c_str());
  640. if(!mf->ReadListFile(0,ifpath.c_str()))
  641. {
  642. cmSystemTools::Error("Could not find cmake module file: ",
  643. ifpath.c_str());
  644. }
  645. std::string compilerWorks = "CMAKE_";
  646. compilerWorks += lang;
  647. compilerWorks += "_COMPILER_WORKS";
  648. // if the compiler did not work, then remove the
  649. // CMake(LANG)Compiler.cmake file so that it will get tested the
  650. // next time cmake is run
  651. if(!mf->IsOn(compilerWorks))
  652. {
  653. std::string compilerLangFile = rootBin;
  654. compilerLangFile += "/CMake";
  655. compilerLangFile += lang;
  656. compilerLangFile += "Compiler.cmake";
  657. cmSystemTools::RemoveFile(compilerLangFile.c_str());
  658. }
  659. } // end if in try compile
  660. } // end need test language
  661. // Store the shared library flags so that we can satisfy CMP0018
  662. std::string sharedLibFlagsVar = "CMAKE_SHARED_LIBRARY_";
  663. sharedLibFlagsVar += lang;
  664. sharedLibFlagsVar += "_FLAGS";
  665. const char* sharedLibFlags =
  666. mf->GetSafeDefinition(sharedLibFlagsVar);
  667. if (sharedLibFlags)
  668. {
  669. this->LanguageToOriginalSharedLibFlags[lang] = sharedLibFlags;
  670. }
  671. // Translate compiler ids for compatibility.
  672. this->CheckCompilerIdCompatibility(mf, lang);
  673. } // end for each language
  674. // Now load files that can override any settings on the platform or for
  675. // the project First load the project compatibility file if it is in
  676. // cmake
  677. std::string projectCompatibility = mf->GetDefinition("CMAKE_ROOT");
  678. projectCompatibility += "/Modules/";
  679. projectCompatibility += mf->GetSafeDefinition("PROJECT_NAME");
  680. projectCompatibility += "Compatibility.cmake";
  681. if(cmSystemTools::FileExists(projectCompatibility.c_str()))
  682. {
  683. mf->ReadListFile(0,projectCompatibility.c_str());
  684. }
  685. // Inform any extra generator of the new language.
  686. if (this->ExtraGenerator)
  687. {
  688. this->ExtraGenerator->EnableLanguage(languages, mf, false);
  689. }
  690. if(fatalError)
  691. {
  692. cmSystemTools::SetFatalErrorOccured();
  693. }
  694. }
  695. //----------------------------------------------------------------------------
  696. void cmGlobalGenerator::PrintCompilerAdvice(std::ostream& os,
  697. std::string const& lang,
  698. const char* envVar) const
  699. {
  700. // Subclasses override this method if they do not support this advice.
  701. os <<
  702. "Tell CMake where to find the compiler by setting "
  703. ;
  704. if(envVar)
  705. {
  706. os <<
  707. "either the environment variable \"" << envVar << "\" or "
  708. ;
  709. }
  710. os <<
  711. "the CMake cache entry CMAKE_" << lang << "_COMPILER "
  712. "to the full path to the compiler, or to the compiler name "
  713. "if it is in the PATH."
  714. ;
  715. }
  716. //----------------------------------------------------------------------------
  717. void cmGlobalGenerator::CheckCompilerIdCompatibility(cmMakefile* mf,
  718. std::string const& lang) const
  719. {
  720. std::string compilerIdVar = "CMAKE_" + lang + "_COMPILER_ID";
  721. const char* compilerId = mf->GetDefinition(compilerIdVar);
  722. if(!compilerId)
  723. {
  724. return;
  725. }
  726. if(strcmp(compilerId, "AppleClang") == 0)
  727. {
  728. cmPolicies* policies = this->CMakeInstance->GetPolicies();
  729. switch(mf->GetPolicyStatus(cmPolicies::CMP0025))
  730. {
  731. case cmPolicies::WARN:
  732. if(!this->CMakeInstance->GetIsInTryCompile() &&
  733. mf->PolicyOptionalWarningEnabled("CMAKE_POLICY_WARNING_CMP0025"))
  734. {
  735. cmOStringStream w;
  736. w << policies->GetPolicyWarning(cmPolicies::CMP0025) << "\n"
  737. "Converting " << lang <<
  738. " compiler id \"AppleClang\" to \"Clang\" for compatibility."
  739. ;
  740. mf->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  741. }
  742. case cmPolicies::OLD:
  743. // OLD behavior is to convert AppleClang to Clang.
  744. mf->AddDefinition(compilerIdVar, "Clang");
  745. break;
  746. case cmPolicies::REQUIRED_IF_USED:
  747. case cmPolicies::REQUIRED_ALWAYS:
  748. mf->IssueMessage(
  749. cmake::FATAL_ERROR,
  750. policies->GetRequiredPolicyError(cmPolicies::CMP0025)
  751. );
  752. case cmPolicies::NEW:
  753. // NEW behavior is to keep AppleClang.
  754. break;
  755. }
  756. }
  757. if(strcmp(compilerId, "QCC") == 0)
  758. {
  759. cmPolicies* policies = this->CMakeInstance->GetPolicies();
  760. switch(mf->GetPolicyStatus(cmPolicies::CMP0047))
  761. {
  762. case cmPolicies::WARN:
  763. if(!this->CMakeInstance->GetIsInTryCompile() &&
  764. mf->PolicyOptionalWarningEnabled("CMAKE_POLICY_WARNING_CMP0047"))
  765. {
  766. cmOStringStream w;
  767. w << policies->GetPolicyWarning(cmPolicies::CMP0047) << "\n"
  768. "Converting " << lang <<
  769. " compiler id \"QCC\" to \"GNU\" for compatibility."
  770. ;
  771. mf->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  772. }
  773. case cmPolicies::OLD:
  774. // OLD behavior is to convert QCC to GNU.
  775. mf->AddDefinition(compilerIdVar, "GNU");
  776. break;
  777. case cmPolicies::REQUIRED_IF_USED:
  778. case cmPolicies::REQUIRED_ALWAYS:
  779. mf->IssueMessage(
  780. cmake::FATAL_ERROR,
  781. policies->GetRequiredPolicyError(cmPolicies::CMP0047)
  782. );
  783. case cmPolicies::NEW:
  784. // NEW behavior is to keep QCC.
  785. break;
  786. }
  787. }
  788. }
  789. //----------------------------------------------------------------------------
  790. std::string
  791. cmGlobalGenerator::GetLanguageOutputExtension(cmSourceFile const& source) const
  792. {
  793. const std::string& lang = source.GetLanguage();
  794. if(!lang.empty())
  795. {
  796. std::map<std::string, std::string>::const_iterator it =
  797. this->LanguageToOutputExtension.find(lang);
  798. if(it != this->LanguageToOutputExtension.end())
  799. {
  800. return it->second;
  801. }
  802. }
  803. else
  804. {
  805. // if no language is found then check to see if it is already an
  806. // ouput extension for some language. In that case it should be ignored
  807. // and in this map, so it will not be compiled but will just be used.
  808. std::string const& ext = source.GetExtension();
  809. if(!ext.empty())
  810. {
  811. if(this->OutputExtensions.count(ext))
  812. {
  813. return ext;
  814. }
  815. }
  816. }
  817. return "";
  818. }
  819. std::string cmGlobalGenerator::GetLanguageFromExtension(const char* ext) const
  820. {
  821. // if there is an extension and it starts with . then move past the
  822. // . because the extensions are not stored with a . in the map
  823. if(ext && *ext == '.')
  824. {
  825. ++ext;
  826. }
  827. std::map<std::string, std::string>::const_iterator it
  828. = this->ExtensionToLanguage.find(ext);
  829. if(it != this->ExtensionToLanguage.end())
  830. {
  831. return it->second;
  832. }
  833. return "";
  834. }
  835. /* SetLanguageEnabled() is now split in two parts:
  836. at first the enabled-flag is set. This can then be used in EnabledLanguage()
  837. for checking whether the language is already enabled. After setting this
  838. flag still the values from the cmake variables have to be copied into the
  839. internal maps, this is done in SetLanguageEnabledMaps() which is called
  840. after the system- and compiler specific files have been loaded.
  841. This split was done originally so that compiler-specific configuration
  842. files could change the object file extension
  843. (CMAKE_<LANG>_OUTPUT_EXTENSION) before the CMake variables were copied
  844. to the C++ maps.
  845. */
  846. void cmGlobalGenerator::SetLanguageEnabled(const std::string& l,
  847. cmMakefile* mf)
  848. {
  849. this->SetLanguageEnabledFlag(l, mf);
  850. this->SetLanguageEnabledMaps(l, mf);
  851. }
  852. void cmGlobalGenerator::SetLanguageEnabledFlag(const std::string& l,
  853. cmMakefile* mf)
  854. {
  855. this->LanguageEnabled[l] = true;
  856. // Fill the language-to-extension map with the current variable
  857. // settings to make sure it is available for the try_compile()
  858. // command source file signature. In SetLanguageEnabledMaps this
  859. // will be done again to account for any compiler- or
  860. // platform-specific entries.
  861. this->FillExtensionToLanguageMap(l, mf);
  862. }
  863. void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
  864. cmMakefile* mf)
  865. {
  866. // use LanguageToLinkerPreference to detect whether this functions has
  867. // run before
  868. if (this->LanguageToLinkerPreference.find(l) !=
  869. this->LanguageToLinkerPreference.end())
  870. {
  871. return;
  872. }
  873. std::string linkerPrefVar = std::string("CMAKE_") +
  874. std::string(l) + std::string("_LINKER_PREFERENCE");
  875. const char* linkerPref = mf->GetDefinition(linkerPrefVar);
  876. int preference = 0;
  877. if(linkerPref)
  878. {
  879. if (sscanf(linkerPref, "%d", &preference)!=1)
  880. {
  881. // backward compatibility: before 2.6 LINKER_PREFERENCE
  882. // was either "None" or "Prefered", and only the first character was
  883. // tested. So if there is a custom language out there and it is
  884. // "Prefered", set its preference high
  885. if (linkerPref[0]=='P')
  886. {
  887. preference = 100;
  888. }
  889. else
  890. {
  891. preference = 0;
  892. }
  893. }
  894. }
  895. if (preference < 0)
  896. {
  897. std::string msg = linkerPrefVar;
  898. msg += " is negative, adjusting it to 0";
  899. cmSystemTools::Message(msg.c_str(), "Warning");
  900. preference = 0;
  901. }
  902. this->LanguageToLinkerPreference[l] = preference;
  903. std::string outputExtensionVar = std::string("CMAKE_") +
  904. std::string(l) + std::string("_OUTPUT_EXTENSION");
  905. const char* outputExtension = mf->GetDefinition(outputExtensionVar);
  906. if(outputExtension)
  907. {
  908. this->LanguageToOutputExtension[l] = outputExtension;
  909. this->OutputExtensions[outputExtension] = outputExtension;
  910. if(outputExtension[0] == '.')
  911. {
  912. this->OutputExtensions[outputExtension+1] = outputExtension+1;
  913. }
  914. }
  915. // The map was originally filled by SetLanguageEnabledFlag, but
  916. // since then the compiler- and platform-specific files have been
  917. // loaded which might have added more entries.
  918. this->FillExtensionToLanguageMap(l, mf);
  919. std::string ignoreExtensionsVar = std::string("CMAKE_") +
  920. std::string(l) + std::string("_IGNORE_EXTENSIONS");
  921. std::string ignoreExts = mf->GetSafeDefinition(ignoreExtensionsVar);
  922. std::vector<std::string> extensionList;
  923. cmSystemTools::ExpandListArgument(ignoreExts, extensionList);
  924. for(std::vector<std::string>::iterator i = extensionList.begin();
  925. i != extensionList.end(); ++i)
  926. {
  927. this->IgnoreExtensions[*i] = true;
  928. }
  929. }
  930. void cmGlobalGenerator::FillExtensionToLanguageMap(const std::string& l,
  931. cmMakefile* mf)
  932. {
  933. std::string extensionsVar = std::string("CMAKE_") +
  934. std::string(l) + std::string("_SOURCE_FILE_EXTENSIONS");
  935. std::string exts = mf->GetSafeDefinition(extensionsVar);
  936. std::vector<std::string> extensionList;
  937. cmSystemTools::ExpandListArgument(exts, extensionList);
  938. for(std::vector<std::string>::iterator i = extensionList.begin();
  939. i != extensionList.end(); ++i)
  940. {
  941. this->ExtensionToLanguage[*i] = l;
  942. }
  943. }
  944. bool cmGlobalGenerator::IgnoreFile(const char* ext) const
  945. {
  946. if(!this->GetLanguageFromExtension(ext).empty())
  947. {
  948. return false;
  949. }
  950. return (this->IgnoreExtensions.count(ext) > 0);
  951. }
  952. bool cmGlobalGenerator::GetLanguageEnabled(const std::string& l) const
  953. {
  954. return (this->LanguageEnabled.find(l)!= this->LanguageEnabled.end());
  955. }
  956. void cmGlobalGenerator::ClearEnabledLanguages()
  957. {
  958. this->LanguageEnabled.clear();
  959. }
  960. bool cmGlobalGenerator::IsDependedOn(const std::string& project,
  961. cmTarget const* targetIn)
  962. {
  963. // Get all local gens for this project
  964. std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator it =
  965. this->ProjectMap.find(project);
  966. if (it == this->ProjectMap.end())
  967. {
  968. return false;
  969. }
  970. // loop over local gens and get the targets for each one
  971. for(std::vector<cmLocalGenerator*>::const_iterator geIt = it->second.begin();
  972. geIt != it->second.end(); ++geIt)
  973. {
  974. cmTargets const& targets = (*geIt)->GetMakefile()->GetTargets();
  975. for (cmTargets::const_iterator l = targets.begin();
  976. l != targets.end(); l++)
  977. {
  978. cmTarget const& target = l->second;
  979. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(target);
  980. if(tgtdeps.count(targetIn))
  981. {
  982. return true;
  983. }
  984. }
  985. }
  986. return false;
  987. }
  988. void cmGlobalGenerator::Configure()
  989. {
  990. this->FirstTimeProgress = 0.0f;
  991. this->ClearGeneratorMembers();
  992. // start with this directory
  993. cmLocalGenerator *lg = this->CreateLocalGenerator();
  994. this->LocalGenerators.push_back(lg);
  995. // set the Start directories
  996. cmMakefile* mf = lg->GetMakefile();
  997. lg->GetMakefile()->SetStartDirectory
  998. (this->CMakeInstance->GetStartDirectory());
  999. lg->GetMakefile()->SetStartOutputDirectory
  1000. (this->CMakeInstance->GetStartOutputDirectory());
  1001. lg->GetMakefile()->MakeStartDirectoriesCurrent();
  1002. this->BinaryDirectories.insert(mf->GetStartOutputDirectory());
  1003. // now do it
  1004. lg->Configure();
  1005. // update the cache entry for the number of local generators, this is used
  1006. // for progress
  1007. char num[100];
  1008. sprintf(num,"%d",static_cast<int>(this->LocalGenerators.size()));
  1009. this->GetCMakeInstance()->AddCacheEntry
  1010. ("CMAKE_NUMBER_OF_LOCAL_GENERATORS", num,
  1011. "number of local generators", cmCacheManager::INTERNAL);
  1012. // check for link libraries and include directories containing "NOTFOUND"
  1013. // and for infinite loops
  1014. this->CheckLocalGenerators();
  1015. // at this point this->LocalGenerators has been filled,
  1016. // so create the map from project name to vector of local generators
  1017. this->FillProjectMap();
  1018. if ( this->CMakeInstance->GetWorkingMode() == cmake::NORMAL_MODE)
  1019. {
  1020. cmOStringStream msg;
  1021. if(cmSystemTools::GetErrorOccuredFlag())
  1022. {
  1023. msg << "Configuring incomplete, errors occurred!";
  1024. const char* logs[] = {"CMakeOutput.log", "CMakeError.log", 0};
  1025. for(const char** log = logs; *log; ++log)
  1026. {
  1027. std::string f = this->CMakeInstance->GetHomeOutputDirectory();
  1028. f += this->CMakeInstance->GetCMakeFilesDirectory();
  1029. f += "/";
  1030. f += *log;
  1031. if(cmSystemTools::FileExists(f.c_str()))
  1032. {
  1033. msg << "\nSee also \"" << f << "\".";
  1034. }
  1035. }
  1036. }
  1037. else
  1038. {
  1039. msg << "Configuring done";
  1040. }
  1041. this->CMakeInstance->UpdateProgress(msg.str().c_str(), -1);
  1042. }
  1043. }
  1044. cmExportBuildFileGenerator*
  1045. cmGlobalGenerator::GetExportedTargetsFile(const std::string &filename) const
  1046. {
  1047. std::map<std::string, cmExportBuildFileGenerator*>::const_iterator it
  1048. = this->BuildExportSets.find(filename);
  1049. return it == this->BuildExportSets.end() ? 0 : it->second;
  1050. }
  1051. //----------------------------------------------------------------------------
  1052. void cmGlobalGenerator::AddCMP0042WarnTarget(const std::string& target)
  1053. {
  1054. this->CMP0042WarnTargets.insert(target);
  1055. }
  1056. bool cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const
  1057. {
  1058. // If the property is not enabled then okay.
  1059. if(!this->CMakeInstance
  1060. ->GetPropertyAsBool("ALLOW_DUPLICATE_CUSTOM_TARGETS"))
  1061. {
  1062. return true;
  1063. }
  1064. // This generator does not support duplicate custom targets.
  1065. cmOStringStream e;
  1066. e << "This project has enabled the ALLOW_DUPLICATE_CUSTOM_TARGETS "
  1067. << "global property. "
  1068. << "The \"" << this->GetName() << "\" generator does not support "
  1069. << "duplicate custom targets. "
  1070. << "Consider using a Makefiles generator or fix the project to not "
  1071. << "use duplicate target names.";
  1072. cmSystemTools::Error(e.str().c_str());
  1073. return false;
  1074. }
  1075. void cmGlobalGenerator::Generate()
  1076. {
  1077. // Some generators track files replaced during the Generate.
  1078. // Start with an empty vector:
  1079. this->FilesReplacedDuringGenerate.clear();
  1080. // clear targets to issue warning CMP0042 for
  1081. this->CMP0042WarnTargets.clear();
  1082. // Check whether this generator is allowed to run.
  1083. if(!this->CheckALLOW_DUPLICATE_CUSTOM_TARGETS())
  1084. {
  1085. return;
  1086. }
  1087. this->FinalizeTargetCompileInfo();
  1088. #ifdef CMAKE_BUILD_WITH_CMAKE
  1089. // Iterate through all targets and set up automoc for those which have
  1090. // the AUTOMOC, AUTOUIC or AUTORCC property set
  1091. AutogensType autogens;
  1092. this->CreateQtAutoGeneratorsTargets(autogens);
  1093. #endif
  1094. // For each existing cmLocalGenerator
  1095. unsigned int i;
  1096. // Put a copy of each global target in every directory.
  1097. cmTargets globalTargets;
  1098. this->CreateDefaultGlobalTargets(&globalTargets);
  1099. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1100. {
  1101. cmMakefile* mf = this->LocalGenerators[i]->GetMakefile();
  1102. cmTargets* targets = &(mf->GetTargets());
  1103. cmTargets::iterator tit;
  1104. for ( tit = globalTargets.begin(); tit != globalTargets.end(); ++ tit )
  1105. {
  1106. (*targets)[tit->first] = tit->second;
  1107. (*targets)[tit->first].SetMakefile(mf);
  1108. }
  1109. }
  1110. // Add generator specific helper commands
  1111. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1112. {
  1113. this->LocalGenerators[i]->AddHelperCommands();
  1114. }
  1115. // Create per-target generator information.
  1116. this->CreateGeneratorTargets();
  1117. this->ForceLinkerLanguages();
  1118. #ifdef CMAKE_BUILD_WITH_CMAKE
  1119. for (AutogensType::iterator it = autogens.begin(); it != autogens.end();
  1120. ++it)
  1121. {
  1122. it->first.SetupAutoGenerateTarget(it->second);
  1123. }
  1124. #endif
  1125. // Trace the dependencies, after that no custom commands should be added
  1126. // because their dependencies might not be handled correctly
  1127. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1128. {
  1129. this->LocalGenerators[i]->TraceDependencies();
  1130. }
  1131. // Compute the manifest of main targets generated.
  1132. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1133. {
  1134. this->LocalGenerators[i]->GenerateTargetManifest();
  1135. }
  1136. this->ProcessEvaluationFiles();
  1137. // Compute the inter-target dependencies.
  1138. if(!this->ComputeTargetDepends())
  1139. {
  1140. return;
  1141. }
  1142. // Create a map from local generator to the complete set of targets
  1143. // it builds by default.
  1144. this->FillLocalGeneratorToTargetMap();
  1145. // Generate project files
  1146. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1147. {
  1148. this->LocalGenerators[i]->GetMakefile()->SetGeneratingBuildSystem();
  1149. this->SetCurrentLocalGenerator(this->LocalGenerators[i]);
  1150. this->LocalGenerators[i]->Generate();
  1151. if(!this->LocalGenerators[i]->GetMakefile()->IsOn(
  1152. "CMAKE_SKIP_INSTALL_RULES"))
  1153. {
  1154. this->LocalGenerators[i]->GenerateInstallRules();
  1155. }
  1156. this->LocalGenerators[i]->GenerateTestFiles();
  1157. this->CMakeInstance->UpdateProgress("Generating",
  1158. (static_cast<float>(i)+1.0f)/
  1159. static_cast<float>(this->LocalGenerators.size()));
  1160. }
  1161. this->SetCurrentLocalGenerator(0);
  1162. if(!this->GenerateCPackPropertiesFile())
  1163. {
  1164. this->GetCMakeInstance()->IssueMessage(
  1165. cmake::FATAL_ERROR, "Could not write CPack properties file.",
  1166. cmListFileBacktrace());
  1167. }
  1168. for (std::map<std::string, cmExportBuildFileGenerator*>::iterator
  1169. it = this->BuildExportSets.begin(); it != this->BuildExportSets.end();
  1170. ++it)
  1171. {
  1172. if (!it->second->GenerateImportFile()
  1173. && !cmSystemTools::GetErrorOccuredFlag())
  1174. {
  1175. this->GetCMakeInstance()
  1176. ->IssueMessage(cmake::FATAL_ERROR, "Could not write export file.",
  1177. cmListFileBacktrace());
  1178. return;
  1179. }
  1180. }
  1181. // Update rule hashes.
  1182. this->CheckRuleHashes();
  1183. this->WriteSummary();
  1184. if (this->ExtraGenerator != 0)
  1185. {
  1186. this->ExtraGenerator->Generate();
  1187. }
  1188. if(!this->CMP0042WarnTargets.empty())
  1189. {
  1190. cmOStringStream w;
  1191. w <<
  1192. (this->GetCMakeInstance()->GetPolicies()->
  1193. GetPolicyWarning(cmPolicies::CMP0042)) << "\n";
  1194. w << "MACOSX_RPATH is not specified for"
  1195. " the following targets:\n";
  1196. for(std::set<std::string>::iterator
  1197. iter = this->CMP0042WarnTargets.begin();
  1198. iter != this->CMP0042WarnTargets.end();
  1199. ++iter)
  1200. {
  1201. w << " " << *iter << "\n";
  1202. }
  1203. this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  1204. cmListFileBacktrace());
  1205. }
  1206. this->CMakeInstance->UpdateProgress("Generating done", -1);
  1207. }
  1208. //----------------------------------------------------------------------------
  1209. bool cmGlobalGenerator::ComputeTargetDepends()
  1210. {
  1211. cmComputeTargetDepends ctd(this);
  1212. if(!ctd.Compute())
  1213. {
  1214. return false;
  1215. }
  1216. std::vector<cmTarget const*> const& targets = ctd.GetTargets();
  1217. for(std::vector<cmTarget const*>::const_iterator ti = targets.begin();
  1218. ti != targets.end(); ++ti)
  1219. {
  1220. ctd.GetTargetDirectDepends(*ti, this->TargetDependencies[*ti]);
  1221. }
  1222. return true;
  1223. }
  1224. //----------------------------------------------------------------------------
  1225. void cmGlobalGenerator::CreateQtAutoGeneratorsTargets(AutogensType &autogens)
  1226. {
  1227. #ifdef CMAKE_BUILD_WITH_CMAKE
  1228. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1229. {
  1230. cmTargets& targets =
  1231. this->LocalGenerators[i]->GetMakefile()->GetTargets();
  1232. for(cmTargets::iterator ti = targets.begin();
  1233. ti != targets.end(); ++ti)
  1234. {
  1235. cmTarget& target = ti->second;
  1236. if(target.GetType() == cmTarget::EXECUTABLE ||
  1237. target.GetType() == cmTarget::STATIC_LIBRARY ||
  1238. target.GetType() == cmTarget::SHARED_LIBRARY ||
  1239. target.GetType() == cmTarget::MODULE_LIBRARY ||
  1240. target.GetType() == cmTarget::OBJECT_LIBRARY)
  1241. {
  1242. if((target.GetPropertyAsBool("AUTOMOC")
  1243. || target.GetPropertyAsBool("AUTOUIC")
  1244. || target.GetPropertyAsBool("AUTORCC"))
  1245. && !target.IsImported())
  1246. {
  1247. cmQtAutoGenerators autogen;
  1248. if(autogen.InitializeAutogenTarget(&target))
  1249. {
  1250. autogens.push_back(AutogensType::value_type(autogen, &target));
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. #else
  1257. (void)autogens;
  1258. #endif
  1259. }
  1260. //----------------------------------------------------------------------------
  1261. void cmGlobalGenerator::FinalizeTargetCompileInfo()
  1262. {
  1263. // Construct per-target generator information.
  1264. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1265. {
  1266. cmMakefile *mf = this->LocalGenerators[i]->GetMakefile();
  1267. const std::vector<cmValueWithOrigin> noconfig_compile_definitions =
  1268. mf->GetCompileDefinitionsEntries();
  1269. cmTargets& targets = mf->GetTargets();
  1270. for(cmTargets::iterator ti = targets.begin();
  1271. ti != targets.end(); ++ti)
  1272. {
  1273. cmTarget* t = &ti->second;
  1274. t->AppendBuildInterfaceIncludes();
  1275. if (t->GetType() == cmTarget::INTERFACE_LIBRARY)
  1276. {
  1277. continue;
  1278. }
  1279. for (std::vector<cmValueWithOrigin>::const_iterator it
  1280. = noconfig_compile_definitions.begin();
  1281. it != noconfig_compile_definitions.end(); ++it)
  1282. {
  1283. t->InsertCompileDefinition(*it);
  1284. }
  1285. cmPolicies::PolicyStatus polSt
  1286. = mf->GetPolicyStatus(cmPolicies::CMP0043);
  1287. if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD)
  1288. {
  1289. std::vector<std::string> configs;
  1290. mf->GetConfigurations(configs);
  1291. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1292. ci != configs.end(); ++ci)
  1293. {
  1294. std::string defPropName = "COMPILE_DEFINITIONS_";
  1295. defPropName += cmSystemTools::UpperCase(*ci);
  1296. t->AppendProperty(defPropName,
  1297. mf->GetProperty(defPropName));
  1298. }
  1299. }
  1300. }
  1301. }
  1302. }
  1303. //----------------------------------------------------------------------------
  1304. void cmGlobalGenerator::CreateGeneratorTargets(cmMakefile *mf)
  1305. {
  1306. cmGeneratorTargetsType generatorTargets;
  1307. cmTargets& targets = mf->GetTargets();
  1308. for(cmTargets::iterator ti = targets.begin();
  1309. ti != targets.end(); ++ti)
  1310. {
  1311. cmTarget* t = &ti->second;
  1312. cmGeneratorTarget* gt = new cmGeneratorTarget(t);
  1313. this->ComputeTargetObjectDirectory(gt);
  1314. this->GeneratorTargets[t] = gt;
  1315. generatorTargets[t] = gt;
  1316. }
  1317. for(std::vector<cmTarget*>::const_iterator
  1318. j = mf->GetOwnedImportedTargets().begin();
  1319. j != mf->GetOwnedImportedTargets().end(); ++j)
  1320. {
  1321. cmGeneratorTarget* gt = new cmGeneratorTarget(*j);
  1322. this->GeneratorTargets[*j] = gt;
  1323. generatorTargets[*j] = gt;
  1324. }
  1325. mf->SetGeneratorTargets(generatorTargets);
  1326. }
  1327. //----------------------------------------------------------------------------
  1328. void cmGlobalGenerator::CreateGeneratorTargets()
  1329. {
  1330. // Construct per-target generator information.
  1331. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1332. {
  1333. this->CreateGeneratorTargets(this->LocalGenerators[i]->GetMakefile());
  1334. }
  1335. }
  1336. //----------------------------------------------------------------------------
  1337. void cmGlobalGenerator::ClearGeneratorMembers()
  1338. {
  1339. for(cmGeneratorTargetsType::iterator i = this->GeneratorTargets.begin();
  1340. i != this->GeneratorTargets.end(); ++i)
  1341. {
  1342. delete i->second;
  1343. }
  1344. this->GeneratorTargets.clear();
  1345. for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
  1346. li = this->EvaluationFiles.begin();
  1347. li != this->EvaluationFiles.end();
  1348. ++li)
  1349. {
  1350. delete *li;
  1351. }
  1352. this->EvaluationFiles.clear();
  1353. for(std::map<std::string, cmExportBuildFileGenerator*>::iterator
  1354. i = this->BuildExportSets.begin();
  1355. i != this->BuildExportSets.end(); ++i)
  1356. {
  1357. delete i->second;
  1358. }
  1359. this->BuildExportSets.clear();
  1360. for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
  1361. {
  1362. delete this->LocalGenerators[i];
  1363. }
  1364. this->LocalGenerators.clear();
  1365. this->ExportSets.clear();
  1366. this->TargetDependencies.clear();
  1367. this->TotalTargets.clear();
  1368. this->ImportedTargets.clear();
  1369. this->LocalGeneratorToTargetMap.clear();
  1370. this->ProjectMap.clear();
  1371. this->RuleHashes.clear();
  1372. this->DirectoryContentMap.clear();
  1373. this->BinaryDirectories.clear();
  1374. }
  1375. //----------------------------------------------------------------------------
  1376. cmGeneratorTarget*
  1377. cmGlobalGenerator::GetGeneratorTarget(cmTarget const* t) const
  1378. {
  1379. cmGeneratorTargetsType::const_iterator ti = this->GeneratorTargets.find(t);
  1380. if(ti == this->GeneratorTargets.end())
  1381. {
  1382. this->CMakeInstance->IssueMessage(
  1383. cmake::INTERNAL_ERROR, "Missing cmGeneratorTarget instance!",
  1384. cmListFileBacktrace());
  1385. return 0;
  1386. }
  1387. return ti->second;
  1388. }
  1389. //----------------------------------------------------------------------------
  1390. void cmGlobalGenerator::ComputeTargetObjectDirectory(cmGeneratorTarget*) const
  1391. {
  1392. }
  1393. void cmGlobalGenerator::CheckLocalGenerators()
  1394. {
  1395. std::map<std::string, std::string> notFoundMap;
  1396. // std::set<std::string> notFoundMap;
  1397. // after it is all done do a ConfigureFinalPass
  1398. cmCacheManager* manager = 0;
  1399. for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
  1400. {
  1401. manager = this->LocalGenerators[i]->GetMakefile()->GetCacheManager();
  1402. this->LocalGenerators[i]->ConfigureFinalPass();
  1403. cmTargets &targets =
  1404. this->LocalGenerators[i]->GetMakefile()->GetTargets();
  1405. for (cmTargets::iterator l = targets.begin();
  1406. l != targets.end(); l++)
  1407. {
  1408. if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  1409. {
  1410. continue;
  1411. }
  1412. const cmTarget::LinkLibraryVectorType& libs =
  1413. l->second.GetOriginalLinkLibraries();
  1414. for(cmTarget::LinkLibraryVectorType::const_iterator lib = libs.begin();
  1415. lib != libs.end(); ++lib)
  1416. {
  1417. if(lib->first.size() > 9 &&
  1418. cmSystemTools::IsNOTFOUND(lib->first.c_str()))
  1419. {
  1420. std::string varName = lib->first.substr(0, lib->first.size()-9);
  1421. cmCacheManager::CacheIterator it =
  1422. manager->GetCacheIterator(varName.c_str());
  1423. if(it.GetPropertyAsBool("ADVANCED"))
  1424. {
  1425. varName += " (ADVANCED)";
  1426. }
  1427. std::string text = notFoundMap[varName];
  1428. text += "\n linked by target \"";
  1429. text += l->second.GetName();
  1430. text += "\" in directory ";
  1431. text+=this->LocalGenerators[i]->GetMakefile()->GetCurrentDirectory();
  1432. notFoundMap[varName] = text;
  1433. }
  1434. }
  1435. std::vector<std::string> incs;
  1436. const char *incDirProp = l->second.GetProperty("INCLUDE_DIRECTORIES");
  1437. if (!incDirProp)
  1438. {
  1439. continue;
  1440. }
  1441. std::string incDirs = cmGeneratorExpression::Preprocess(incDirProp,
  1442. cmGeneratorExpression::StripAllGeneratorExpressions);
  1443. cmSystemTools::ExpandListArgument(incDirs, incs);
  1444. for( std::vector<std::string>::const_iterator incDir = incs.begin();
  1445. incDir != incs.end(); ++incDir)
  1446. {
  1447. if(incDir->size() > 9 &&
  1448. cmSystemTools::IsNOTFOUND(incDir->c_str()))
  1449. {
  1450. std::string varName = incDir->substr(0, incDir->size()-9);
  1451. cmCacheManager::CacheIterator it =
  1452. manager->GetCacheIterator(varName.c_str());
  1453. if(it.GetPropertyAsBool("ADVANCED"))
  1454. {
  1455. varName += " (ADVANCED)";
  1456. }
  1457. std::string text = notFoundMap[varName];
  1458. text += "\n used as include directory in directory ";
  1459. text += this->LocalGenerators[i]
  1460. ->GetMakefile()->GetCurrentDirectory();
  1461. notFoundMap[varName] = text;
  1462. }
  1463. }
  1464. }
  1465. this->CMakeInstance->UpdateProgress
  1466. ("Configuring", 0.9f+0.1f*(static_cast<float>(i)+1.0f)/
  1467. static_cast<float>(this->LocalGenerators.size()));
  1468. }
  1469. if(notFoundMap.size())
  1470. {
  1471. std::string notFoundVars;
  1472. for(std::map<std::string, std::string>::const_iterator
  1473. ii = notFoundMap.begin();
  1474. ii != notFoundMap.end();
  1475. ++ii)
  1476. {
  1477. notFoundVars += ii->first;
  1478. notFoundVars += ii->second;
  1479. notFoundVars += "\n";
  1480. }
  1481. cmSystemTools::Error("The following variables are used in this project, "
  1482. "but they are set to NOTFOUND.\n"
  1483. "Please set them or make sure they are set and "
  1484. "tested correctly in the CMake files:\n",
  1485. notFoundVars.c_str());
  1486. }
  1487. }
  1488. int cmGlobalGenerator::TryCompile(const std::string& srcdir,
  1489. const std::string& bindir,
  1490. const std::string& projectName,
  1491. const std::string& target, bool fast,
  1492. std::string *output, cmMakefile *mf)
  1493. {
  1494. // if this is not set, then this is a first time configure
  1495. // and there is a good chance that the try compile stuff will
  1496. // take the bulk of the time, so try and guess some progress
  1497. // by getting closer and closer to 100 without actually getting there.
  1498. if (!this->CMakeInstance->GetCacheManager()->GetCacheValue
  1499. ("CMAKE_NUMBER_OF_LOCAL_GENERATORS"))
  1500. {
  1501. // If CMAKE_NUMBER_OF_LOCAL_GENERATORS is not set
  1502. // we are in the first time progress and we have no
  1503. // idea how long it will be. So, just move 1/10th of the way
  1504. // there each time, and don't go over 95%
  1505. this->FirstTimeProgress += ((1.0f - this->FirstTimeProgress) /30.0f);
  1506. if(this->FirstTimeProgress > 0.95f)
  1507. {
  1508. this->FirstTimeProgress = 0.95f;
  1509. }
  1510. this->CMakeInstance->UpdateProgress("Configuring",
  1511. this->FirstTimeProgress);
  1512. }
  1513. std::string newTarget;
  1514. if (!target.empty())
  1515. {
  1516. newTarget += target;
  1517. #if 0
  1518. #if defined(_WIN32) || defined(__CYGWIN__)
  1519. std::string tmp = target;
  1520. // if the target does not already end in . something
  1521. // then assume .exe
  1522. if(tmp.size() < 4 || tmp[tmp.size()-4] != '.')
  1523. {
  1524. newTarget += ".exe";
  1525. }
  1526. #endif // WIN32
  1527. #endif
  1528. }
  1529. std::string config =
  1530. mf->GetSafeDefinition("CMAKE_TRY_COMPILE_CONFIGURATION");
  1531. return this->Build(srcdir,bindir,projectName,
  1532. newTarget,
  1533. output,"",config,false,fast,
  1534. this->TryCompileTimeout);
  1535. }
  1536. void cmGlobalGenerator::GenerateBuildCommand(
  1537. std::vector<std::string>& makeCommand, const std::string&,
  1538. const std::string&, const std::string&, const std::string&,
  1539. const std::string&, bool,
  1540. std::vector<std::string> const&)
  1541. {
  1542. makeCommand.push_back(
  1543. "cmGlobalGenerator::GenerateBuildCommand not implemented");
  1544. }
  1545. int cmGlobalGenerator::Build(
  1546. const std::string&, const std::string& bindir,
  1547. const std::string& projectName, const std::string& target,
  1548. std::string *output,
  1549. const std::string& makeCommandCSTR,
  1550. const std::string& config,
  1551. bool clean, bool fast,
  1552. double timeout,
  1553. cmSystemTools::OutputOption outputflag,
  1554. std::vector<std::string> const& nativeOptions)
  1555. {
  1556. /**
  1557. * Run an executable command and put the stdout in output.
  1558. */
  1559. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1560. cmSystemTools::ChangeDirectory(bindir.c_str());
  1561. if(output)
  1562. {
  1563. *output += "Change Dir: ";
  1564. *output += bindir;
  1565. *output += "\n";
  1566. }
  1567. int retVal;
  1568. bool hideconsole = cmSystemTools::GetRunCommandHideConsole();
  1569. cmSystemTools::SetRunCommandHideConsole(true);
  1570. std::string outputBuffer;
  1571. std::string* outputPtr = 0;
  1572. if(output)
  1573. {
  1574. outputPtr = &outputBuffer;
  1575. }
  1576. // should we do a clean first?
  1577. if (clean)
  1578. {
  1579. std::vector<std::string> cleanCommand;
  1580. this->GenerateBuildCommand(cleanCommand, makeCommandCSTR, projectName,
  1581. bindir, "clean", config, fast);
  1582. if(output)
  1583. {
  1584. *output += "\nRun Clean Command:";
  1585. *output += cmSystemTools::PrintSingleCommand(cleanCommand);
  1586. *output += "\n";
  1587. }
  1588. if (!cmSystemTools::RunSingleCommand(cleanCommand, outputPtr,
  1589. &retVal, 0, outputflag, timeout))
  1590. {
  1591. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1592. cmSystemTools::Error("Generator: execution of make clean failed.");
  1593. if (output)
  1594. {
  1595. *output += *outputPtr;
  1596. *output += "\nGenerator: execution of make clean failed.\n";
  1597. }
  1598. // return to the original directory
  1599. cmSystemTools::ChangeDirectory(cwd.c_str());
  1600. return 1;
  1601. }
  1602. if (output)
  1603. {
  1604. *output += *outputPtr;
  1605. }
  1606. }
  1607. // now build
  1608. std::vector<std::string> makeCommand;
  1609. this->GenerateBuildCommand(makeCommand, makeCommandCSTR, projectName,
  1610. bindir, target, config, fast, nativeOptions);
  1611. std::string makeCommandStr = cmSystemTools::PrintSingleCommand(makeCommand);
  1612. if(output)
  1613. {
  1614. *output += "\nRun Build Command:";
  1615. *output += makeCommandStr;
  1616. *output += "\n";
  1617. }
  1618. if (!cmSystemTools::RunSingleCommand(makeCommand, outputPtr,
  1619. &retVal, 0, outputflag, timeout))
  1620. {
  1621. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1622. cmSystemTools::Error
  1623. ("Generator: execution of make failed. Make command was: ",
  1624. makeCommandStr.c_str());
  1625. if (output)
  1626. {
  1627. *output += *outputPtr;
  1628. *output += "\nGenerator: execution of make failed. Make command was: "
  1629. + makeCommandStr + "\n";
  1630. }
  1631. // return to the original directory
  1632. cmSystemTools::ChangeDirectory(cwd.c_str());
  1633. return 1;
  1634. }
  1635. if (output)
  1636. {
  1637. *output += *outputPtr;
  1638. }
  1639. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1640. // The SGI MipsPro 7.3 compiler does not return an error code when
  1641. // the source has a #error in it! This is a work-around for such
  1642. // compilers.
  1643. if((retVal == 0) && (output->find("#error") != std::string::npos))
  1644. {
  1645. retVal = 1;
  1646. }
  1647. cmSystemTools::ChangeDirectory(cwd.c_str());
  1648. return retVal;
  1649. }
  1650. //----------------------------------------------------------------------------
  1651. std::string cmGlobalGenerator::GenerateCMakeBuildCommand(
  1652. const std::string& target, const std::string& config,
  1653. const std::string& native,
  1654. bool ignoreErrors)
  1655. {
  1656. std::string makeCommand = cmSystemTools::GetCMakeCommand();
  1657. makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
  1658. makeCommand += " --build .";
  1659. if(!config.empty())
  1660. {
  1661. makeCommand += " --config \"";
  1662. makeCommand += config;
  1663. makeCommand += "\"";
  1664. }
  1665. if(!target.empty())
  1666. {
  1667. makeCommand += " --target \"";
  1668. makeCommand += target;
  1669. makeCommand += "\"";
  1670. }
  1671. const char* sep = " -- ";
  1672. if(ignoreErrors)
  1673. {
  1674. const char* iflag = this->GetBuildIgnoreErrorsFlag();
  1675. if(iflag && *iflag)
  1676. {
  1677. makeCommand += sep;
  1678. makeCommand += iflag;
  1679. sep = " ";
  1680. }
  1681. }
  1682. if(!native.empty())
  1683. {
  1684. makeCommand += sep;
  1685. makeCommand += native;
  1686. }
  1687. return makeCommand;
  1688. }
  1689. //----------------------------------------------------------------------------
  1690. void cmGlobalGenerator::AddLocalGenerator(cmLocalGenerator *lg)
  1691. {
  1692. this->LocalGenerators.push_back(lg);
  1693. // update progress
  1694. // estimate how many lg there will be
  1695. const char *numGenC =
  1696. this->CMakeInstance->GetCacheManager()->GetCacheValue
  1697. ("CMAKE_NUMBER_OF_LOCAL_GENERATORS");
  1698. if (!numGenC)
  1699. {
  1700. // If CMAKE_NUMBER_OF_LOCAL_GENERATORS is not set
  1701. // we are in the first time progress and we have no
  1702. // idea how long it will be. So, just move half way
  1703. // there each time, and don't go over 95%
  1704. this->FirstTimeProgress += ((1.0f - this->FirstTimeProgress) /30.0f);
  1705. if(this->FirstTimeProgress > 0.95f)
  1706. {
  1707. this->FirstTimeProgress = 0.95f;
  1708. }
  1709. this->CMakeInstance->UpdateProgress("Configuring",
  1710. this->FirstTimeProgress);
  1711. return;
  1712. }
  1713. int numGen = atoi(numGenC);
  1714. float prog = 0.9f*static_cast<float>(this->LocalGenerators.size())/
  1715. static_cast<float>(numGen);
  1716. if (prog > 0.9f)
  1717. {
  1718. prog = 0.9f;
  1719. }
  1720. this->CMakeInstance->UpdateProgress("Configuring", prog);
  1721. }
  1722. void cmGlobalGenerator::AddInstallComponent(const char* component)
  1723. {
  1724. if(component && *component)
  1725. {
  1726. this->InstallComponents.insert(component);
  1727. }
  1728. }
  1729. void cmGlobalGenerator::EnableInstallTarget()
  1730. {
  1731. this->InstallTargetEnabled = true;
  1732. }
  1733. cmLocalGenerator *cmGlobalGenerator::CreateLocalGenerator()
  1734. {
  1735. cmLocalGenerator *lg = new cmLocalGenerator;
  1736. lg->SetGlobalGenerator(this);
  1737. return lg;
  1738. }
  1739. void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator *gen,
  1740. cmMakefile* mf)
  1741. {
  1742. this->SetConfiguredFilesPath(gen);
  1743. this->TryCompileOuterMakefile = mf;
  1744. const char* make =
  1745. gen->GetCMakeInstance()->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
  1746. this->GetCMakeInstance()->AddCacheEntry("CMAKE_MAKE_PROGRAM", make,
  1747. "make program",
  1748. cmCacheManager::FILEPATH);
  1749. // copy the enabled languages
  1750. this->LanguageEnabled = gen->LanguageEnabled;
  1751. this->LanguagesReady = gen->LanguagesReady;
  1752. this->ExtensionToLanguage = gen->ExtensionToLanguage;
  1753. this->IgnoreExtensions = gen->IgnoreExtensions;
  1754. this->LanguageToOutputExtension = gen->LanguageToOutputExtension;
  1755. this->LanguageToLinkerPreference = gen->LanguageToLinkerPreference;
  1756. this->OutputExtensions = gen->OutputExtensions;
  1757. }
  1758. //----------------------------------------------------------------------------
  1759. void cmGlobalGenerator::SetConfiguredFilesPath(cmGlobalGenerator* gen)
  1760. {
  1761. if(!gen->ConfiguredFilesPath.empty())
  1762. {
  1763. this->ConfiguredFilesPath = gen->ConfiguredFilesPath;
  1764. }
  1765. else
  1766. {
  1767. this->ConfiguredFilesPath = gen->CMakeInstance->GetHomeOutputDirectory();
  1768. this->ConfiguredFilesPath += cmake::GetCMakeFilesDirectory();
  1769. }
  1770. }
  1771. bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
  1772. cmLocalGenerator* gen) const
  1773. {
  1774. if(!gen || gen == root)
  1775. {
  1776. // No directory excludes itself.
  1777. return false;
  1778. }
  1779. if(gen->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  1780. {
  1781. // This directory is excluded from its parent.
  1782. return true;
  1783. }
  1784. // This directory is included in its parent. Check whether the
  1785. // parent is excluded.
  1786. return this->IsExcluded(root, gen->GetParent());
  1787. }
  1788. bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
  1789. cmTarget const& target) const
  1790. {
  1791. if(target.GetType() == cmTarget::INTERFACE_LIBRARY
  1792. || target.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  1793. {
  1794. // This target is excluded from its directory.
  1795. return true;
  1796. }
  1797. else
  1798. {
  1799. // This target is included in its directory. Check whether the
  1800. // directory is excluded.
  1801. return this->IsExcluded(root, target.GetMakefile()->GetLocalGenerator());
  1802. }
  1803. }
  1804. void
  1805. cmGlobalGenerator::GetEnabledLanguages(std::vector<std::string>& lang) const
  1806. {
  1807. for(std::map<std::string, bool>::const_iterator i =
  1808. this->LanguageEnabled.begin(); i != this->LanguageEnabled.end(); ++i)
  1809. {
  1810. lang.push_back(i->first);
  1811. }
  1812. }
  1813. int cmGlobalGenerator::GetLinkerPreference(const std::string& lang) const
  1814. {
  1815. std::map<std::string, int>::const_iterator it =
  1816. this->LanguageToLinkerPreference.find(lang);
  1817. if (it != this->LanguageToLinkerPreference.end())
  1818. {
  1819. return it->second;
  1820. }
  1821. return 0;
  1822. }
  1823. void cmGlobalGenerator::FillProjectMap()
  1824. {
  1825. this->ProjectMap.clear(); // make sure we start with a clean map
  1826. unsigned int i;
  1827. for(i = 0; i < this->LocalGenerators.size(); ++i)
  1828. {
  1829. // for each local generator add all projects
  1830. cmLocalGenerator *lg = this->LocalGenerators[i];
  1831. std::string name;
  1832. do
  1833. {
  1834. if (name != lg->GetMakefile()->GetProjectName())
  1835. {
  1836. name = lg->GetMakefile()->GetProjectName();
  1837. this->ProjectMap[name].push_back(this->LocalGenerators[i]);
  1838. }
  1839. lg = lg->GetParent();
  1840. }
  1841. while (lg);
  1842. }
  1843. }
  1844. // Build a map that contains a the set of targets used by each local
  1845. // generator directory level.
  1846. void cmGlobalGenerator::FillLocalGeneratorToTargetMap()
  1847. {
  1848. this->LocalGeneratorToTargetMap.clear();
  1849. // Loop over all targets in all local generators.
  1850. for(std::vector<cmLocalGenerator*>::const_iterator
  1851. lgi = this->LocalGenerators.begin();
  1852. lgi != this->LocalGenerators.end(); ++lgi)
  1853. {
  1854. cmLocalGenerator* lg = *lgi;
  1855. cmMakefile* mf = lg->GetMakefile();
  1856. cmTargets const& targets = mf->GetTargets();
  1857. for(cmTargets::const_iterator t = targets.begin(); t != targets.end(); ++t)
  1858. {
  1859. cmTarget const& target = t->second;
  1860. // Consider the directory containing the target and all its
  1861. // parents until something excludes the target.
  1862. for(cmLocalGenerator* clg = lg; clg && !this->IsExcluded(clg, target);
  1863. clg = clg->GetParent())
  1864. {
  1865. // This local generator includes the target.
  1866. std::set<cmTarget const*>& targetSet =
  1867. this->LocalGeneratorToTargetMap[clg];
  1868. targetSet.insert(&target);
  1869. // Add dependencies of the included target. An excluded
  1870. // target may still be included if it is a dependency of a
  1871. // non-excluded target.
  1872. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(target);
  1873. for(TargetDependSet::const_iterator ti = tgtdeps.begin();
  1874. ti != tgtdeps.end(); ++ti)
  1875. {
  1876. cmTarget const* ttt = *ti;
  1877. targetSet.insert(ttt);
  1878. }
  1879. }
  1880. }
  1881. }
  1882. }
  1883. ///! Find a local generator by its startdirectory
  1884. cmLocalGenerator*
  1885. cmGlobalGenerator::FindLocalGenerator(const std::string& start_dir) const
  1886. {
  1887. for(std::vector<cmLocalGenerator*>::const_iterator it =
  1888. this->LocalGenerators.begin(); it != this->LocalGenerators.end(); ++it)
  1889. {
  1890. std::string sd = (*it)->GetMakefile()->GetStartDirectory();
  1891. if (sd == start_dir)
  1892. {
  1893. return *it;
  1894. }
  1895. }
  1896. return 0;
  1897. }
  1898. //----------------------------------------------------------------------------
  1899. void cmGlobalGenerator::AddAlias(const std::string& name, cmTarget *tgt)
  1900. {
  1901. this->AliasTargets[name] = tgt;
  1902. }
  1903. //----------------------------------------------------------------------------
  1904. bool cmGlobalGenerator::IsAlias(const std::string& name) const
  1905. {
  1906. return this->AliasTargets.find(name) != this->AliasTargets.end();
  1907. }
  1908. //----------------------------------------------------------------------------
  1909. cmTarget*
  1910. cmGlobalGenerator::FindTarget(const std::string& name,
  1911. bool excludeAliases) const
  1912. {
  1913. if (!excludeAliases)
  1914. {
  1915. TargetMap::const_iterator ai = this->AliasTargets.find(name);
  1916. if (ai != this->AliasTargets.end())
  1917. {
  1918. return ai->second;
  1919. }
  1920. }
  1921. TargetMap::const_iterator i = 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 << "\"";
  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(TargetMap::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. std::vector<std::string> configs;
  2680. target->GetMakefile()->GetConfigurations(configs);
  2681. if (configs.empty())
  2682. {
  2683. configs.push_back("");
  2684. }
  2685. for(std::vector<std::string>::const_iterator ci = configs.begin();
  2686. ci != configs.end(); ++ci)
  2687. {
  2688. target->GetSourceFiles(sources, *ci);
  2689. }
  2690. std::set<cmSourceFile*> emitted;
  2691. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  2692. si != sources.end(); ++si)
  2693. {
  2694. if (!emitted.insert(*si).second)
  2695. {
  2696. continue;
  2697. }
  2698. cmSourceFile* sf = *si;
  2699. fout << sf->GetFullPath() << "\n";
  2700. if(const char* svalue = sf->GetProperty("LABELS"))
  2701. {
  2702. labels.clear();
  2703. cmSystemTools::ExpandListArgument(svalue, labels);
  2704. for(std::vector<std::string>::const_iterator li = labels.begin();
  2705. li != labels.end(); ++li)
  2706. {
  2707. fout << " " << *li << "\n";
  2708. }
  2709. }
  2710. }
  2711. }
  2712. else
  2713. {
  2714. cmSystemTools::RemoveFile(file.c_str());
  2715. }
  2716. }
  2717. //----------------------------------------------------------------------------
  2718. // static
  2719. std::string cmGlobalGenerator::EscapeJSON(const std::string& s) {
  2720. std::string result;
  2721. for (std::string::size_type i = 0; i < s.size(); ++i) {
  2722. if (s[i] == '"' || s[i] == '\\') {
  2723. result += '\\';
  2724. }
  2725. result += s[i];
  2726. }
  2727. return result;
  2728. }
  2729. //----------------------------------------------------------------------------
  2730. void cmGlobalGenerator::AddEvaluationFile(const std::string &inputFile,
  2731. cmsys::auto_ptr<cmCompiledGeneratorExpression> outputExpr,
  2732. cmMakefile *makefile,
  2733. cmsys::auto_ptr<cmCompiledGeneratorExpression> condition,
  2734. bool inputIsContent)
  2735. {
  2736. this->EvaluationFiles.push_back(
  2737. new cmGeneratorExpressionEvaluationFile(inputFile, outputExpr,
  2738. makefile, condition,
  2739. inputIsContent));
  2740. }
  2741. //----------------------------------------------------------------------------
  2742. void cmGlobalGenerator::ProcessEvaluationFiles()
  2743. {
  2744. std::set<std::string> generatedFiles;
  2745. for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
  2746. li = this->EvaluationFiles.begin();
  2747. li != this->EvaluationFiles.end();
  2748. ++li)
  2749. {
  2750. (*li)->Generate();
  2751. if (cmSystemTools::GetFatalErrorOccured())
  2752. {
  2753. return;
  2754. }
  2755. std::vector<std::string> files = (*li)->GetFiles();
  2756. for(std::vector<std::string>::const_iterator fi = files.begin();
  2757. fi != files.end(); ++fi)
  2758. {
  2759. if (!generatedFiles.insert(*fi).second)
  2760. {
  2761. cmSystemTools::Error("File to be generated by multiple different "
  2762. "commands: ", fi->c_str());
  2763. return;
  2764. }
  2765. }
  2766. }
  2767. }
  2768. //----------------------------------------------------------------------------
  2769. std::string cmGlobalGenerator::ExpandCFGIntDir(const std::string& str,
  2770. const std::string& /*config*/) const
  2771. {
  2772. return str;
  2773. }
  2774. //----------------------------------------------------------------------------
  2775. bool cmGlobalGenerator::GenerateCPackPropertiesFile()
  2776. {
  2777. cmake::InstalledFilesMap const& installedFiles =
  2778. this->CMakeInstance->GetInstalledFiles();
  2779. cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
  2780. std::vector<std::string> configs;
  2781. std::string config = mf->GetConfigurations(configs, false);
  2782. std::string path = this->CMakeInstance->GetStartOutputDirectory();
  2783. path += "/CPackProperties.cmake";
  2784. if(!cmSystemTools::FileExists(path.c_str()) && installedFiles.empty())
  2785. {
  2786. return true;
  2787. }
  2788. cmGeneratedFileStream file(path.c_str());
  2789. file << "# CPack properties\n";
  2790. for(cmake::InstalledFilesMap::const_iterator i = installedFiles.begin();
  2791. i != installedFiles.end(); ++i)
  2792. {
  2793. cmInstalledFile const& installedFile = i->second;
  2794. cmCPackPropertiesGenerator cpackPropertiesGenerator(
  2795. mf, installedFile, configs);
  2796. cpackPropertiesGenerator.Generate(file, config, configs);
  2797. }
  2798. return true;
  2799. }