cmGlobalGenerator.cxx 98 KB

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