cmGlobalGenerator.cxx 101 KB

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