cmGlobalGenerator.cxx 98 KB

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