cmGlobalGenerator.cxx 97 KB

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