cmake.cxx 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712
  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. #include "cmake.h"
  11. #include "cmCacheManager.h"
  12. #include "cmMakefile.h"
  13. #include "cmLocalGenerator.h"
  14. #include "cmExternalMakefileProjectGenerator.h"
  15. #include "cmCommands.h"
  16. #include "cmCommand.h"
  17. #include "cmFileTimeComparison.h"
  18. #include "cmSourceFile.h"
  19. #include "cmTest.h"
  20. #include "cmDocumentationFormatter.h"
  21. #include "cmAlgorithms.h"
  22. #include "cmState.h"
  23. #if defined(CMAKE_BUILD_WITH_CMAKE)
  24. # include "cmGraphVizWriter.h"
  25. # include "cmVariableWatch.h"
  26. # include <cmsys/SystemInformation.hxx>
  27. #endif
  28. #include <cmsys/Glob.hxx>
  29. #include <cmsys/RegularExpression.hxx>
  30. #include <cmsys/FStream.hxx>
  31. // only build kdevelop generator on non-windows platforms
  32. // when not bootstrapping cmake
  33. #if !defined(_WIN32)
  34. # if defined(CMAKE_BUILD_WITH_CMAKE)
  35. # define CMAKE_USE_KDEVELOP
  36. # endif
  37. #endif
  38. #if defined(CMAKE_BUILD_WITH_CMAKE)
  39. # define CMAKE_USE_ECLIPSE
  40. #endif
  41. #if defined(__MINGW32__) && !defined(CMAKE_BUILD_WITH_CMAKE)
  42. # define CMAKE_BOOT_MINGW
  43. #endif
  44. // include the generator
  45. #if defined(_WIN32) && !defined(__CYGWIN__)
  46. # if !defined(CMAKE_BOOT_MINGW)
  47. # include "cmGlobalVisualStudio6Generator.h"
  48. # include "cmGlobalVisualStudio7Generator.h"
  49. # include "cmGlobalVisualStudio71Generator.h"
  50. # include "cmGlobalVisualStudio8Generator.h"
  51. # include "cmGlobalVisualStudio9Generator.h"
  52. # include "cmGlobalVisualStudio10Generator.h"
  53. # include "cmGlobalVisualStudio11Generator.h"
  54. # include "cmGlobalVisualStudio12Generator.h"
  55. # include "cmGlobalVisualStudio14Generator.h"
  56. # include "cmGlobalBorlandMakefileGenerator.h"
  57. # include "cmGlobalNMakeMakefileGenerator.h"
  58. # include "cmGlobalJOMMakefileGenerator.h"
  59. # define CMAKE_HAVE_VS_GENERATORS
  60. # endif
  61. # include "cmGlobalMSYSMakefileGenerator.h"
  62. # include "cmGlobalMinGWMakefileGenerator.h"
  63. #else
  64. #endif
  65. #if defined(CMAKE_USE_WMAKE)
  66. # include "cmGlobalWatcomWMakeGenerator.h"
  67. #endif
  68. #include "cmGlobalUnixMakefileGenerator3.h"
  69. #include "cmGlobalNinjaGenerator.h"
  70. #include "cmExtraCodeLiteGenerator.h"
  71. #if !defined(CMAKE_BOOT_MINGW)
  72. # include "cmExtraCodeBlocksGenerator.h"
  73. #endif
  74. #include "cmExtraSublimeTextGenerator.h"
  75. #include "cmExtraKateGenerator.h"
  76. #ifdef CMAKE_USE_KDEVELOP
  77. # include "cmGlobalKdevelopGenerator.h"
  78. #endif
  79. #include "cmExtraQbsGenerator.h"
  80. #ifdef CMAKE_USE_ECLIPSE
  81. # include "cmExtraEclipseCDT4Generator.h"
  82. #endif
  83. #include <stdlib.h> // required for atoi
  84. #if defined( __APPLE__ )
  85. # if defined(CMAKE_BUILD_WITH_CMAKE)
  86. # include "cmGlobalXCodeGenerator.h"
  87. # define CMAKE_USE_XCODE 1
  88. # endif
  89. # include <sys/types.h>
  90. # include <sys/time.h>
  91. # include <sys/resource.h>
  92. #endif
  93. #include <sys/stat.h> // struct stat
  94. #include <list>
  95. static bool cmakeCheckStampFile(const char* stampName);
  96. static bool cmakeCheckStampList(const char* stampName);
  97. void cmWarnUnusedCliWarning(const std::string& variable,
  98. int, void* ctx, const char*, const cmMakefile*)
  99. {
  100. cmake* cm = reinterpret_cast<cmake*>(ctx);
  101. cm->MarkCliAsUsed(variable);
  102. }
  103. cmake::cmake()
  104. {
  105. this->Trace = false;
  106. this->WarnUninitialized = false;
  107. this->WarnUnused = false;
  108. this->WarnUnusedCli = true;
  109. this->CheckSystemVars = false;
  110. this->SuppressDevWarnings = false;
  111. this->DoSuppressDevWarnings = false;
  112. this->DebugOutput = false;
  113. this->DebugTryCompile = false;
  114. this->ClearBuildSystem = false;
  115. this->FileComparison = new cmFileTimeComparison;
  116. this->Policies = new cmPolicies();
  117. this->State = new cmState(this);
  118. #ifdef __APPLE__
  119. struct rlimit rlp;
  120. if(!getrlimit(RLIMIT_STACK, &rlp))
  121. {
  122. if(rlp.rlim_cur != rlp.rlim_max)
  123. {
  124. rlp.rlim_cur = rlp.rlim_max;
  125. setrlimit(RLIMIT_STACK, &rlp);
  126. }
  127. }
  128. #endif
  129. this->Verbose = false;
  130. this->CacheManager = new cmCacheManager(this);
  131. this->GlobalGenerator = 0;
  132. this->ProgressCallback = 0;
  133. this->ProgressCallbackClientData = 0;
  134. this->CurrentWorkingMode = NORMAL_MODE;
  135. #ifdef CMAKE_BUILD_WITH_CMAKE
  136. this->VariableWatch = new cmVariableWatch;
  137. #endif
  138. this->AddDefaultGenerators();
  139. this->AddDefaultExtraGenerators();
  140. this->AddDefaultCommands();
  141. // Make sure we can capture the build tool output.
  142. cmSystemTools::EnableVSConsoleOutput();
  143. }
  144. cmake::~cmake()
  145. {
  146. delete this->CacheManager;
  147. delete this->Policies;
  148. delete this->State;
  149. if (this->GlobalGenerator)
  150. {
  151. delete this->GlobalGenerator;
  152. this->GlobalGenerator = 0;
  153. }
  154. cmDeleteAll(this->Generators);
  155. #ifdef CMAKE_BUILD_WITH_CMAKE
  156. delete this->VariableWatch;
  157. #endif
  158. delete this->FileComparison;
  159. }
  160. void cmake::CleanupCommandsAndMacros()
  161. {
  162. this->State->Initialize();
  163. this->State->RemoveUserDefinedCommands();
  164. }
  165. // Parse the args
  166. bool cmake::SetCacheArgs(const std::vector<std::string>& args)
  167. {
  168. bool findPackageMode = false;
  169. for(unsigned int i=1; i < args.size(); ++i)
  170. {
  171. std::string arg = args[i];
  172. if(arg.find("-D",0) == 0)
  173. {
  174. std::string entry = arg.substr(2);
  175. if(entry.empty())
  176. {
  177. ++i;
  178. if(i < args.size())
  179. {
  180. entry = args[i];
  181. }
  182. else
  183. {
  184. cmSystemTools::Error("-D must be followed with VAR=VALUE.");
  185. return false;
  186. }
  187. }
  188. std::string var, value;
  189. cmState::CacheEntryType type = cmState::UNINITIALIZED;
  190. if(cmCacheManager::ParseEntry(entry, var, value, type))
  191. {
  192. // The value is transformed if it is a filepath for example, so
  193. // we can't compare whether the value is already in the cache until
  194. // after we call AddCacheEntry.
  195. bool haveValue = false;
  196. std::string cachedValue;
  197. if(this->WarnUnusedCli)
  198. {
  199. if(const char *v = this->State->GetInitializedCacheValue(var))
  200. {
  201. haveValue = true;
  202. cachedValue = v;
  203. }
  204. }
  205. this->State->AddCacheEntry(var, value.c_str(),
  206. "No help, variable specified on the command line.", type);
  207. if(this->WarnUnusedCli)
  208. {
  209. if (!haveValue ||
  210. cachedValue != this->State->GetInitializedCacheValue(var))
  211. {
  212. this->WatchUnusedCli(var);
  213. }
  214. }
  215. }
  216. else
  217. {
  218. std::cerr << "Parse error in command line argument: " << arg << "\n"
  219. << "Should be: VAR:type=value\n";
  220. cmSystemTools::Error("No cmake script provided.");
  221. return false;
  222. }
  223. }
  224. else if(arg.find("-Wno-dev",0) == 0)
  225. {
  226. this->SuppressDevWarnings = true;
  227. this->DoSuppressDevWarnings = true;
  228. }
  229. else if(arg.find("-Wdev",0) == 0)
  230. {
  231. this->SuppressDevWarnings = false;
  232. this->DoSuppressDevWarnings = true;
  233. }
  234. else if(arg.find("-U",0) == 0)
  235. {
  236. std::string entryPattern = arg.substr(2);
  237. if(entryPattern.empty())
  238. {
  239. ++i;
  240. if(i < args.size())
  241. {
  242. entryPattern = args[i];
  243. }
  244. else
  245. {
  246. cmSystemTools::Error("-U must be followed with VAR.");
  247. return false;
  248. }
  249. }
  250. cmsys::RegularExpression regex(
  251. cmsys::Glob::PatternToRegex(entryPattern, true, true).c_str());
  252. //go through all cache entries and collect the vars which will be removed
  253. std::vector<std::string> entriesToDelete;
  254. std::vector<std::string> cacheKeys = this->State->GetCacheEntryKeys();
  255. for (std::vector<std::string>::const_iterator it = cacheKeys.begin();
  256. it != cacheKeys.end(); ++it)
  257. {
  258. cmState::CacheEntryType t = this->State->GetCacheEntryType(*it);
  259. if(t != cmState::STATIC)
  260. {
  261. if (regex.find(it->c_str()))
  262. {
  263. entriesToDelete.push_back(*it);
  264. }
  265. }
  266. }
  267. // now remove them from the cache
  268. for(std::vector<std::string>::const_iterator currentEntry =
  269. entriesToDelete.begin();
  270. currentEntry != entriesToDelete.end();
  271. ++currentEntry)
  272. {
  273. this->State->RemoveCacheEntry(*currentEntry);
  274. }
  275. }
  276. else if(arg.find("-C",0) == 0)
  277. {
  278. std::string path = arg.substr(2);
  279. if (path.empty())
  280. {
  281. ++i;
  282. if(i < args.size())
  283. {
  284. path = args[i];
  285. }
  286. else
  287. {
  288. cmSystemTools::Error("-C must be followed by a file name.");
  289. return false;
  290. }
  291. }
  292. std::cout << "loading initial cache file " << path << "\n";
  293. this->ReadListFile(args, path.c_str());
  294. }
  295. else if(arg.find("-P",0) == 0)
  296. {
  297. i++;
  298. if(i >= args.size())
  299. {
  300. cmSystemTools::Error("-P must be followed by a file name.");
  301. return false;
  302. }
  303. std::string path = args[i];
  304. if (path.empty())
  305. {
  306. cmSystemTools::Error("No cmake script provided.");
  307. return false;
  308. }
  309. this->ReadListFile(args, path.c_str());
  310. }
  311. else if (arg.find("--find-package",0) == 0)
  312. {
  313. findPackageMode = true;
  314. }
  315. }
  316. if (findPackageMode)
  317. {
  318. return this->FindPackage(args);
  319. }
  320. return true;
  321. }
  322. void cmake::ReadListFile(const std::vector<std::string>& args,
  323. const char *path)
  324. {
  325. // if a generator was not yet created, temporarily create one
  326. cmGlobalGenerator *gg = this->GetGlobalGenerator();
  327. bool created = false;
  328. // if a generator was not specified use a generic one
  329. if (!gg)
  330. {
  331. gg = new cmGlobalGenerator;
  332. gg->SetCMakeInstance(this);
  333. created = true;
  334. }
  335. // read in the list file to fill the cache
  336. if(path)
  337. {
  338. cmsys::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator());
  339. lg->GetMakefile()->SetHomeOutputDirectory
  340. (cmSystemTools::GetCurrentWorkingDirectory());
  341. lg->GetMakefile()->SetStartOutputDirectory
  342. (cmSystemTools::GetCurrentWorkingDirectory());
  343. lg->GetMakefile()->SetHomeDirectory
  344. (cmSystemTools::GetCurrentWorkingDirectory());
  345. lg->GetMakefile()->SetStartDirectory
  346. (cmSystemTools::GetCurrentWorkingDirectory());
  347. if (this->GetWorkingMode() != NORMAL_MODE)
  348. {
  349. std::string file(cmSystemTools::CollapseFullPath(path));
  350. cmSystemTools::ConvertToUnixSlashes(file);
  351. lg->GetMakefile()->SetScriptModeFile(file.c_str());
  352. lg->GetMakefile()->SetArgcArgv(args);
  353. }
  354. if (!lg->GetMakefile()->ReadListFile(path))
  355. {
  356. cmSystemTools::Error("Error processing file: ", path);
  357. }
  358. }
  359. // free generic one if generated
  360. if (created)
  361. {
  362. delete gg;
  363. }
  364. }
  365. bool cmake::FindPackage(const std::vector<std::string>& args)
  366. {
  367. // if a generator was not yet created, temporarily create one
  368. cmGlobalGenerator *gg = new cmGlobalGenerator;
  369. gg->SetCMakeInstance(this);
  370. this->SetGlobalGenerator(gg);
  371. // read in the list file to fill the cache
  372. cmsys::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator());
  373. cmMakefile* mf = lg->GetMakefile();
  374. mf->SetHomeOutputDirectory
  375. (cmSystemTools::GetCurrentWorkingDirectory());
  376. mf->SetStartOutputDirectory
  377. (cmSystemTools::GetCurrentWorkingDirectory());
  378. mf->SetHomeDirectory
  379. (cmSystemTools::GetCurrentWorkingDirectory());
  380. mf->SetStartDirectory
  381. (cmSystemTools::GetCurrentWorkingDirectory());
  382. mf->SetArgcArgv(args);
  383. std::string systemFile = mf->GetModulesFile("CMakeFindPackageMode.cmake");
  384. mf->ReadListFile(systemFile.c_str());
  385. std::string language = mf->GetSafeDefinition("LANGUAGE");
  386. std::string mode = mf->GetSafeDefinition("MODE");
  387. std::string packageName = mf->GetSafeDefinition("NAME");
  388. bool packageFound = mf->IsOn("PACKAGE_FOUND");
  389. bool quiet = mf->IsOn("PACKAGE_QUIET");
  390. if (!packageFound)
  391. {
  392. if (!quiet)
  393. {
  394. printf("%s not found.\n", packageName.c_str());
  395. }
  396. }
  397. else if (mode == "EXIST")
  398. {
  399. if (!quiet)
  400. {
  401. printf("%s found.\n", packageName.c_str());
  402. }
  403. }
  404. else if (mode == "COMPILE")
  405. {
  406. std::string includes = mf->GetSafeDefinition("PACKAGE_INCLUDE_DIRS");
  407. std::vector<std::string> includeDirs;
  408. cmSystemTools::ExpandListArgument(includes, includeDirs);
  409. std::string includeFlags = lg->GetIncludeFlags(includeDirs, 0,
  410. language, false);
  411. std::string definitions = mf->GetSafeDefinition("PACKAGE_DEFINITIONS");
  412. printf("%s %s\n", includeFlags.c_str(), definitions.c_str());
  413. }
  414. else if (mode == "LINK")
  415. {
  416. const char* targetName = "dummy";
  417. std::vector<std::string> srcs;
  418. cmTarget* tgt = mf->AddExecutable(targetName, srcs, true);
  419. tgt->SetProperty("LINKER_LANGUAGE", language.c_str());
  420. std::string libs = mf->GetSafeDefinition("PACKAGE_LIBRARIES");
  421. std::vector<std::string> libList;
  422. cmSystemTools::ExpandListArgument(libs, libList);
  423. for(std::vector<std::string>::const_iterator libIt=libList.begin();
  424. libIt != libList.end();
  425. ++libIt)
  426. {
  427. mf->AddLinkLibraryForTarget(targetName, *libIt,
  428. cmTarget::GENERAL);
  429. }
  430. std::string linkLibs;
  431. std::string frameworkPath;
  432. std::string linkPath;
  433. std::string flags;
  434. std::string linkFlags;
  435. gg->CreateGeneratorTargets(mf);
  436. cmGeneratorTarget *gtgt = gg->GetGeneratorTarget(tgt);
  437. lg->GetTargetFlags(linkLibs, frameworkPath, linkPath, flags, linkFlags,
  438. gtgt, false);
  439. linkLibs = frameworkPath + linkPath + linkLibs;
  440. printf("%s\n", linkLibs.c_str() );
  441. /* if ( use_win32 )
  442. {
  443. tgt->SetProperty("WIN32_EXECUTABLE", "ON");
  444. }
  445. if ( use_macbundle)
  446. {
  447. tgt->SetProperty("MACOSX_BUNDLE", "ON");
  448. }*/
  449. }
  450. // free generic one if generated
  451. // this->SetGlobalGenerator(0); // setting 0-pointer is not possible
  452. // delete gg; // this crashes inside the cmake instance
  453. return packageFound;
  454. }
  455. // Parse the args
  456. void cmake::SetArgs(const std::vector<std::string>& args,
  457. bool directoriesSetBefore)
  458. {
  459. bool directoriesSet = directoriesSetBefore;
  460. bool haveToolset = false;
  461. bool havePlatform = false;
  462. for(unsigned int i=1; i < args.size(); ++i)
  463. {
  464. std::string arg = args[i];
  465. if(arg.find("-H",0) == 0)
  466. {
  467. directoriesSet = true;
  468. std::string path = arg.substr(2);
  469. path = cmSystemTools::CollapseFullPath(path);
  470. cmSystemTools::ConvertToUnixSlashes(path);
  471. this->SetHomeDirectory(path);
  472. }
  473. else if(arg.find("-S",0) == 0)
  474. {
  475. // There is no local generate anymore. Ignore -S option.
  476. }
  477. else if(arg.find("-O",0) == 0)
  478. {
  479. // There is no local generate anymore. Ignore -O option.
  480. }
  481. else if(arg.find("-B",0) == 0)
  482. {
  483. directoriesSet = true;
  484. std::string path = arg.substr(2);
  485. path = cmSystemTools::CollapseFullPath(path);
  486. cmSystemTools::ConvertToUnixSlashes(path);
  487. this->SetHomeOutputDirectory(path);
  488. }
  489. else if((i < args.size()-2) && (arg.find("--check-build-system",0) == 0))
  490. {
  491. this->CheckBuildSystemArgument = args[++i];
  492. this->ClearBuildSystem = (atoi(args[++i].c_str()) > 0);
  493. }
  494. else if((i < args.size()-1) && (arg.find("--check-stamp-file",0) == 0))
  495. {
  496. this->CheckStampFile = args[++i];
  497. }
  498. else if((i < args.size()-1) && (arg.find("--check-stamp-list",0) == 0))
  499. {
  500. this->CheckStampList = args[++i];
  501. }
  502. #if defined(CMAKE_HAVE_VS_GENERATORS)
  503. else if((i < args.size()-1) && (arg.find("--vs-solution-file",0) == 0))
  504. {
  505. this->VSSolutionFile = args[++i];
  506. }
  507. #endif
  508. else if(arg.find("-V",0) == 0)
  509. {
  510. this->Verbose = true;
  511. }
  512. else if(arg.find("-D",0) == 0)
  513. {
  514. // skip for now
  515. }
  516. else if(arg.find("-U",0) == 0)
  517. {
  518. // skip for now
  519. }
  520. else if(arg.find("-C",0) == 0)
  521. {
  522. // skip for now
  523. }
  524. else if(arg.find("-P",0) == 0)
  525. {
  526. // skip for now
  527. i++;
  528. }
  529. else if(arg.find("--find-package",0) == 0)
  530. {
  531. // skip for now
  532. i++;
  533. }
  534. else if(arg.find("-Wno-dev",0) == 0)
  535. {
  536. // skip for now
  537. }
  538. else if(arg.find("-Wdev",0) == 0)
  539. {
  540. // skip for now
  541. }
  542. else if(arg.find("--graphviz=",0) == 0)
  543. {
  544. std::string path = arg.substr(strlen("--graphviz="));
  545. path = cmSystemTools::CollapseFullPath(path);
  546. cmSystemTools::ConvertToUnixSlashes(path);
  547. this->GraphVizFile = path;
  548. if ( this->GraphVizFile.empty() )
  549. {
  550. cmSystemTools::Error("No file specified for --graphviz");
  551. }
  552. }
  553. else if(arg.find("--debug-trycompile",0) == 0)
  554. {
  555. std::cout << "debug trycompile on\n";
  556. this->DebugTryCompileOn();
  557. }
  558. else if(arg.find("--debug-output",0) == 0)
  559. {
  560. std::cout << "Running with debug output on.\n";
  561. this->SetDebugOutputOn(true);
  562. }
  563. else if(arg.find("--trace",0) == 0)
  564. {
  565. std::cout << "Running with trace output on.\n";
  566. this->SetTrace(true);
  567. }
  568. else if(arg.find("--warn-uninitialized",0) == 0)
  569. {
  570. std::cout << "Warn about uninitialized values.\n";
  571. this->SetWarnUninitialized(true);
  572. }
  573. else if(arg.find("--warn-unused-vars",0) == 0)
  574. {
  575. std::cout << "Finding unused variables.\n";
  576. this->SetWarnUnused(true);
  577. }
  578. else if(arg.find("--no-warn-unused-cli",0) == 0)
  579. {
  580. std::cout << "Not searching for unused variables given on the " <<
  581. "command line.\n";
  582. this->SetWarnUnusedCli(false);
  583. }
  584. else if(arg.find("--check-system-vars",0) == 0)
  585. {
  586. std::cout << "Also check system files when warning about unused and " <<
  587. "uninitialized variables.\n";
  588. this->SetCheckSystemVars(true);
  589. }
  590. else if(arg.find("-A",0) == 0)
  591. {
  592. std::string value = arg.substr(2);
  593. if(value.empty())
  594. {
  595. ++i;
  596. if(i >= args.size())
  597. {
  598. cmSystemTools::Error("No platform specified for -A");
  599. return;
  600. }
  601. value = args[i];
  602. }
  603. if(havePlatform)
  604. {
  605. cmSystemTools::Error("Multiple -A options not allowed");
  606. return;
  607. }
  608. this->GeneratorPlatform = value;
  609. havePlatform = true;
  610. }
  611. else if(arg.find("-T",0) == 0)
  612. {
  613. std::string value = arg.substr(2);
  614. if(value.empty())
  615. {
  616. ++i;
  617. if(i >= args.size())
  618. {
  619. cmSystemTools::Error("No toolset specified for -T");
  620. return;
  621. }
  622. value = args[i];
  623. }
  624. if(haveToolset)
  625. {
  626. cmSystemTools::Error("Multiple -T options not allowed");
  627. return;
  628. }
  629. this->GeneratorToolset = value;
  630. haveToolset = true;
  631. }
  632. else if(arg.find("-G",0) == 0)
  633. {
  634. std::string value = arg.substr(2);
  635. if(value.empty())
  636. {
  637. ++i;
  638. if(i >= args.size())
  639. {
  640. cmSystemTools::Error("No generator specified for -G");
  641. this->PrintGeneratorList();
  642. return;
  643. }
  644. value = args[i];
  645. }
  646. cmGlobalGenerator* gen =
  647. this->CreateGlobalGenerator(value);
  648. if(!gen)
  649. {
  650. cmSystemTools::Error("Could not create named generator ",
  651. value.c_str());
  652. this->PrintGeneratorList();
  653. }
  654. else
  655. {
  656. this->SetGlobalGenerator(gen);
  657. }
  658. }
  659. // no option assume it is the path to the source
  660. else
  661. {
  662. directoriesSet = true;
  663. this->SetDirectoriesFromFile(arg.c_str());
  664. }
  665. }
  666. if(!directoriesSet)
  667. {
  668. this->SetHomeOutputDirectory
  669. (cmSystemTools::GetCurrentWorkingDirectory());
  670. this->SetHomeDirectory
  671. (cmSystemTools::GetCurrentWorkingDirectory());
  672. }
  673. this->SetStartDirectory(this->GetHomeDirectory());
  674. this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
  675. }
  676. //----------------------------------------------------------------------------
  677. void cmake::SetDirectoriesFromFile(const char* arg)
  678. {
  679. // Check if the argument refers to a CMakeCache.txt or
  680. // CMakeLists.txt file.
  681. std::string listPath;
  682. std::string cachePath;
  683. bool argIsFile = false;
  684. if(cmSystemTools::FileIsDirectory(arg))
  685. {
  686. std::string path = cmSystemTools::CollapseFullPath(arg);
  687. cmSystemTools::ConvertToUnixSlashes(path);
  688. std::string cacheFile = path;
  689. cacheFile += "/CMakeCache.txt";
  690. std::string listFile = path;
  691. listFile += "/CMakeLists.txt";
  692. if(cmSystemTools::FileExists(cacheFile.c_str()))
  693. {
  694. cachePath = path;
  695. }
  696. if(cmSystemTools::FileExists(listFile.c_str()))
  697. {
  698. listPath = path;
  699. }
  700. }
  701. else if(cmSystemTools::FileExists(arg))
  702. {
  703. argIsFile = true;
  704. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  705. std::string name = cmSystemTools::GetFilenameName(fullPath);
  706. name = cmSystemTools::LowerCase(name);
  707. if(name == "cmakecache.txt")
  708. {
  709. cachePath = cmSystemTools::GetFilenamePath(fullPath);
  710. }
  711. else if(name == "cmakelists.txt")
  712. {
  713. listPath = cmSystemTools::GetFilenamePath(fullPath);
  714. }
  715. }
  716. else
  717. {
  718. // Specified file or directory does not exist. Try to set things
  719. // up to produce a meaningful error message.
  720. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  721. std::string name = cmSystemTools::GetFilenameName(fullPath);
  722. name = cmSystemTools::LowerCase(name);
  723. if(name == "cmakecache.txt" || name == "cmakelists.txt")
  724. {
  725. argIsFile = true;
  726. listPath = cmSystemTools::GetFilenamePath(fullPath);
  727. }
  728. else
  729. {
  730. listPath = fullPath;
  731. }
  732. }
  733. // If there is a CMakeCache.txt file, use its settings.
  734. if(!cachePath.empty())
  735. {
  736. if(this->LoadCache(cachePath))
  737. {
  738. const char* existingValue =
  739. this->State->GetCacheEntryValue("CMAKE_HOME_DIRECTORY");
  740. if (existingValue)
  741. {
  742. this->SetHomeOutputDirectory(cachePath);
  743. this->SetStartOutputDirectory(cachePath);
  744. this->SetHomeDirectory(existingValue);
  745. this->SetStartDirectory(existingValue);
  746. return;
  747. }
  748. }
  749. }
  750. // If there is a CMakeLists.txt file, use it as the source tree.
  751. if(!listPath.empty())
  752. {
  753. this->SetHomeDirectory(listPath);
  754. this->SetStartDirectory(listPath);
  755. if(argIsFile)
  756. {
  757. // Source CMakeLists.txt file given. It was probably dropped
  758. // onto the executable in a GUI. Default to an in-source build.
  759. this->SetHomeOutputDirectory(listPath);
  760. this->SetStartOutputDirectory(listPath);
  761. }
  762. else
  763. {
  764. // Source directory given on command line. Use current working
  765. // directory as build tree.
  766. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  767. this->SetHomeOutputDirectory(cwd);
  768. this->SetStartOutputDirectory(cwd);
  769. }
  770. return;
  771. }
  772. // We didn't find a CMakeLists.txt or CMakeCache.txt file from the
  773. // argument. Assume it is the path to the source tree, and use the
  774. // current working directory as the build tree.
  775. std::string full = cmSystemTools::CollapseFullPath(arg);
  776. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  777. this->SetHomeDirectory(full);
  778. this->SetStartDirectory(full);
  779. this->SetHomeOutputDirectory(cwd);
  780. this->SetStartOutputDirectory(cwd);
  781. }
  782. // at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the
  783. // cache
  784. int cmake::AddCMakePaths()
  785. {
  786. // Save the value in the cache
  787. this->CacheManager->AddCacheEntry
  788. ("CMAKE_COMMAND", cmSystemTools::GetCMakeCommand().c_str(),
  789. "Path to CMake executable.", cmState::INTERNAL);
  790. #ifdef CMAKE_BUILD_WITH_CMAKE
  791. this->CacheManager->AddCacheEntry
  792. ("CMAKE_CTEST_COMMAND", cmSystemTools::GetCTestCommand().c_str(),
  793. "Path to ctest program executable.", cmState::INTERNAL);
  794. this->CacheManager->AddCacheEntry
  795. ("CMAKE_CPACK_COMMAND", cmSystemTools::GetCPackCommand().c_str(),
  796. "Path to cpack program executable.", cmState::INTERNAL);
  797. #endif
  798. if(!cmSystemTools::FileExists(
  799. (cmSystemTools::GetCMakeRoot()+"/Modules/CMake.cmake").c_str()))
  800. {
  801. // couldn't find modules
  802. cmSystemTools::Error("Could not find CMAKE_ROOT !!!\n"
  803. "CMake has most likely not been installed correctly.\n"
  804. "Modules directory not found in\n",
  805. cmSystemTools::GetCMakeRoot().c_str());
  806. return 0;
  807. }
  808. this->CacheManager->AddCacheEntry
  809. ("CMAKE_ROOT", cmSystemTools::GetCMakeRoot().c_str(),
  810. "Path to CMake installation.", cmState::INTERNAL);
  811. return 1;
  812. }
  813. void cmake::AddExtraGenerator(const std::string& name,
  814. CreateExtraGeneratorFunctionType newFunction)
  815. {
  816. cmExternalMakefileProjectGenerator* extraGenerator = newFunction();
  817. const std::vector<std::string>& supportedGlobalGenerators =
  818. extraGenerator->GetSupportedGlobalGenerators();
  819. for(std::vector<std::string>::const_iterator
  820. it = supportedGlobalGenerators.begin();
  821. it != supportedGlobalGenerators.end();
  822. ++it )
  823. {
  824. std::string fullName = cmExternalMakefileProjectGenerator::
  825. CreateFullGeneratorName(*it, name);
  826. this->ExtraGenerators[fullName] = newFunction;
  827. }
  828. delete extraGenerator;
  829. }
  830. void cmake::AddDefaultExtraGenerators()
  831. {
  832. #if defined(CMAKE_BUILD_WITH_CMAKE)
  833. #if defined(_WIN32) && !defined(__CYGWIN__)
  834. // e.g. kdevelop4 ?
  835. #endif
  836. this->AddExtraGenerator(cmExtraCodeBlocksGenerator::GetActualName(),
  837. &cmExtraCodeBlocksGenerator::New);
  838. this->AddExtraGenerator(cmExtraCodeLiteGenerator::GetActualName(),
  839. &cmExtraCodeLiteGenerator::New);
  840. this->AddExtraGenerator(cmExtraSublimeTextGenerator::GetActualName(),
  841. &cmExtraSublimeTextGenerator::New);
  842. this->AddExtraGenerator(cmExtraKateGenerator::GetActualName(),
  843. &cmExtraKateGenerator::New);
  844. this->AddExtraGenerator(cmExtraQbsGenerator::GetActualName(),
  845. &cmExtraQbsGenerator::New);
  846. #ifdef CMAKE_USE_ECLIPSE
  847. this->AddExtraGenerator(cmExtraEclipseCDT4Generator::GetActualName(),
  848. &cmExtraEclipseCDT4Generator::New);
  849. #endif
  850. #ifdef CMAKE_USE_KDEVELOP
  851. this->AddExtraGenerator(cmGlobalKdevelopGenerator::GetActualName(),
  852. &cmGlobalKdevelopGenerator::New);
  853. // for kdevelop also add the generator with just the name of the
  854. // extra generator, since it was this way since cmake 2.2
  855. this->ExtraGenerators[cmGlobalKdevelopGenerator::GetActualName()]
  856. = &cmGlobalKdevelopGenerator::New;
  857. #endif
  858. #endif
  859. }
  860. //----------------------------------------------------------------------------
  861. void cmake::GetRegisteredGenerators(std::vector<std::string>& names)
  862. {
  863. for(RegisteredGeneratorsVector::const_iterator i = this->Generators.begin();
  864. i != this->Generators.end(); ++i)
  865. {
  866. (*i)->GetGenerators(names);
  867. }
  868. for(RegisteredExtraGeneratorsMap::const_iterator
  869. i = this->ExtraGenerators.begin();
  870. i != this->ExtraGenerators.end(); ++i)
  871. {
  872. names.push_back(i->first);
  873. }
  874. }
  875. cmGlobalGenerator* cmake::CreateGlobalGenerator(const std::string& gname)
  876. {
  877. cmExternalMakefileProjectGenerator* extraGenerator = 0;
  878. std::string name = gname;
  879. RegisteredExtraGeneratorsMap::const_iterator extraGenIt =
  880. this->ExtraGenerators.find(name);
  881. if (extraGenIt != this->ExtraGenerators.end())
  882. {
  883. extraGenerator = (extraGenIt->second)();
  884. name = extraGenerator->GetGlobalGeneratorName(name);
  885. }
  886. cmGlobalGenerator* generator = 0;
  887. for (RegisteredGeneratorsVector::const_iterator i =
  888. this->Generators.begin(); i != this->Generators.end(); ++i)
  889. {
  890. generator = (*i)->CreateGlobalGenerator(name);
  891. if (generator)
  892. {
  893. break;
  894. }
  895. }
  896. if (generator)
  897. {
  898. generator->SetCMakeInstance(this);
  899. generator->SetExternalMakefileProjectGenerator(extraGenerator);
  900. }
  901. else
  902. {
  903. delete extraGenerator;
  904. }
  905. return generator;
  906. }
  907. void cmake::SetHomeDirectory(const std::string& dir)
  908. {
  909. this->cmHomeDirectory = dir;
  910. cmSystemTools::ConvertToUnixSlashes(this->cmHomeDirectory);
  911. }
  912. const char* cmake::GetHomeDirectory() const
  913. {
  914. return this->cmHomeDirectory.c_str();
  915. }
  916. void cmake::SetHomeOutputDirectory(const std::string& dir)
  917. {
  918. this->HomeOutputDirectory = dir;
  919. cmSystemTools::ConvertToUnixSlashes(this->HomeOutputDirectory);
  920. }
  921. const char* cmake::GetHomeOutputDirectory() const
  922. {
  923. return this->HomeOutputDirectory.c_str();
  924. }
  925. const char* cmake::GetStartDirectory() const
  926. {
  927. return this->cmStartDirectory.c_str();
  928. }
  929. void cmake::SetStartDirectory(const std::string& dir)
  930. {
  931. this->cmStartDirectory = dir;
  932. cmSystemTools::ConvertToUnixSlashes(this->cmStartDirectory);
  933. }
  934. const char* cmake::GetStartOutputDirectory() const
  935. {
  936. return this->StartOutputDirectory.c_str();
  937. }
  938. void cmake::SetStartOutputDirectory(const std::string& dir)
  939. {
  940. this->StartOutputDirectory = dir;
  941. cmSystemTools::ConvertToUnixSlashes(this->StartOutputDirectory);
  942. }
  943. void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
  944. {
  945. if(!gg)
  946. {
  947. cmSystemTools::Error("Error SetGlobalGenerator called with null");
  948. return;
  949. }
  950. // delete the old generator
  951. if (this->GlobalGenerator)
  952. {
  953. delete this->GlobalGenerator;
  954. // restore the original environment variables CXX and CC
  955. // Restore CC
  956. std::string env = "CC=";
  957. if(!this->CCEnvironment.empty())
  958. {
  959. env += this->CCEnvironment;
  960. }
  961. cmSystemTools::PutEnv(env);
  962. env = "CXX=";
  963. if(!this->CXXEnvironment.empty())
  964. {
  965. env += this->CXXEnvironment;
  966. }
  967. cmSystemTools::PutEnv(env);
  968. }
  969. // set the new
  970. this->GlobalGenerator = gg;
  971. // set the global flag for unix style paths on cmSystemTools as soon as
  972. // the generator is set. This allows gmake to be used on windows.
  973. cmSystemTools::SetForceUnixPaths
  974. (this->GlobalGenerator->GetForceUnixPaths());
  975. // Save the environment variables CXX and CC
  976. const char* cxx = getenv("CXX");
  977. const char* cc = getenv("CC");
  978. if(cxx)
  979. {
  980. this->CXXEnvironment = cxx;
  981. }
  982. else
  983. {
  984. this->CXXEnvironment = "";
  985. }
  986. if(cc)
  987. {
  988. this->CCEnvironment = cc;
  989. }
  990. else
  991. {
  992. this->CCEnvironment = "";
  993. }
  994. // set the cmake instance just to be sure
  995. gg->SetCMakeInstance(this);
  996. }
  997. int cmake::DoPreConfigureChecks()
  998. {
  999. // Make sure the Start directory contains a CMakeLists.txt file.
  1000. std::string srcList = this->GetHomeDirectory();
  1001. srcList += "/CMakeLists.txt";
  1002. if(!cmSystemTools::FileExists(srcList.c_str()))
  1003. {
  1004. std::ostringstream err;
  1005. if(cmSystemTools::FileIsDirectory(this->GetHomeDirectory()))
  1006. {
  1007. err << "The source directory \"" << this->GetHomeDirectory()
  1008. << "\" does not appear to contain CMakeLists.txt.\n";
  1009. }
  1010. else if(cmSystemTools::FileExists(this->GetHomeDirectory()))
  1011. {
  1012. err << "The source directory \"" << this->GetHomeDirectory()
  1013. << "\" is a file, not a directory.\n";
  1014. }
  1015. else
  1016. {
  1017. err << "The source directory \"" << this->GetHomeDirectory()
  1018. << "\" does not exist.\n";
  1019. }
  1020. err << "Specify --help for usage, or press the help button on the CMake "
  1021. "GUI.";
  1022. cmSystemTools::Error(err.str().c_str());
  1023. return -2;
  1024. }
  1025. // do a sanity check on some values
  1026. if(this->CacheManager->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY"))
  1027. {
  1028. std::string cacheStart =
  1029. this->CacheManager->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY");
  1030. cacheStart += "/CMakeLists.txt";
  1031. std::string currentStart = this->GetHomeDirectory();
  1032. currentStart += "/CMakeLists.txt";
  1033. if(!cmSystemTools::SameFile(cacheStart, currentStart))
  1034. {
  1035. std::string message = "The source \"";
  1036. message += currentStart;
  1037. message += "\" does not match the source \"";
  1038. message += cacheStart;
  1039. message += "\" used to generate cache. ";
  1040. message += "Re-run cmake with a different source directory.";
  1041. cmSystemTools::Error(message.c_str());
  1042. return -2;
  1043. }
  1044. }
  1045. else
  1046. {
  1047. return 0;
  1048. }
  1049. return 1;
  1050. }
  1051. struct SaveCacheEntry
  1052. {
  1053. std::string key;
  1054. std::string value;
  1055. std::string help;
  1056. cmState::CacheEntryType type;
  1057. };
  1058. int cmake::HandleDeleteCacheVariables(const std::string& var)
  1059. {
  1060. std::vector<std::string> argsSplit;
  1061. cmSystemTools::ExpandListArgument(std::string(var), argsSplit, true);
  1062. // erase the property to avoid infinite recursion
  1063. this->State
  1064. ->SetGlobalProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_", "");
  1065. if(this->State->GetIsInTryCompile())
  1066. {
  1067. return 0;
  1068. }
  1069. std::vector<SaveCacheEntry> saved;
  1070. std::ostringstream warning;
  1071. warning
  1072. << "You have changed variables that require your cache to be deleted.\n"
  1073. << "Configure will be re-run and you may have to reset some variables.\n"
  1074. << "The following variables have changed:\n";
  1075. for(std::vector<std::string>::iterator i = argsSplit.begin();
  1076. i != argsSplit.end(); ++i)
  1077. {
  1078. SaveCacheEntry save;
  1079. save.key = *i;
  1080. warning << *i << "= ";
  1081. i++;
  1082. save.value = *i;
  1083. warning << *i << "\n";
  1084. const char* existingValue =
  1085. this->CacheManager->GetCacheEntryValue(save.key);
  1086. if(existingValue)
  1087. {
  1088. save.type = this->CacheManager->GetCacheEntryType(save.key);
  1089. if(const char* help =
  1090. this->CacheManager->GetCacheEntryProperty(save.key, "HELPSTRING"))
  1091. {
  1092. save.help = help;
  1093. }
  1094. }
  1095. saved.push_back(save);
  1096. }
  1097. // remove the cache
  1098. this->CacheManager->DeleteCache(this->GetStartOutputDirectory());
  1099. // load the empty cache
  1100. this->LoadCache();
  1101. // restore the changed compilers
  1102. for(std::vector<SaveCacheEntry>::iterator i = saved.begin();
  1103. i != saved.end(); ++i)
  1104. {
  1105. this->AddCacheEntry(i->key, i->value.c_str(),
  1106. i->help.c_str(), i->type);
  1107. }
  1108. cmSystemTools::Message(warning.str().c_str());
  1109. // avoid reconfigure if there were errors
  1110. if(!cmSystemTools::GetErrorOccuredFlag())
  1111. {
  1112. // re-run configure
  1113. return this->Configure();
  1114. }
  1115. return 0;
  1116. }
  1117. int cmake::Configure()
  1118. {
  1119. if(this->DoSuppressDevWarnings)
  1120. {
  1121. if(this->SuppressDevWarnings)
  1122. {
  1123. this->CacheManager->
  1124. AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "TRUE",
  1125. "Suppress Warnings that are meant for"
  1126. " the author of the CMakeLists.txt files.",
  1127. cmState::INTERNAL);
  1128. }
  1129. else
  1130. {
  1131. this->CacheManager->
  1132. AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "FALSE",
  1133. "Suppress Warnings that are meant for"
  1134. " the author of the CMakeLists.txt files.",
  1135. cmState::INTERNAL);
  1136. }
  1137. }
  1138. int ret = this->ActualConfigure();
  1139. const char* delCacheVars = this->State
  1140. ->GetGlobalProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_");
  1141. if(delCacheVars && delCacheVars[0] != 0)
  1142. {
  1143. return this->HandleDeleteCacheVariables(delCacheVars);
  1144. }
  1145. return ret;
  1146. }
  1147. int cmake::ActualConfigure()
  1148. {
  1149. // Construct right now our path conversion table before it's too late:
  1150. this->UpdateConversionPathTable();
  1151. this->CleanupCommandsAndMacros();
  1152. int res = 0;
  1153. if ( this->GetWorkingMode() == NORMAL_MODE )
  1154. {
  1155. res = this->DoPreConfigureChecks();
  1156. }
  1157. if ( res < 0 )
  1158. {
  1159. return -2;
  1160. }
  1161. if ( !res )
  1162. {
  1163. this->CacheManager->AddCacheEntry
  1164. ("CMAKE_HOME_DIRECTORY",
  1165. this->GetHomeDirectory(),
  1166. "Start directory with the top level CMakeLists.txt file for this "
  1167. "project",
  1168. cmState::INTERNAL);
  1169. }
  1170. // no generator specified on the command line
  1171. if(!this->GlobalGenerator)
  1172. {
  1173. const char* genName =
  1174. this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR");
  1175. const char* extraGenName =
  1176. this->CacheManager->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
  1177. if(genName)
  1178. {
  1179. std::string fullName = cmExternalMakefileProjectGenerator::
  1180. CreateFullGeneratorName(genName,
  1181. extraGenName ? extraGenName : "");
  1182. this->GlobalGenerator = this->CreateGlobalGenerator(fullName);
  1183. }
  1184. if(this->GlobalGenerator)
  1185. {
  1186. // set the global flag for unix style paths on cmSystemTools as
  1187. // soon as the generator is set. This allows gmake to be used
  1188. // on windows.
  1189. cmSystemTools::SetForceUnixPaths
  1190. (this->GlobalGenerator->GetForceUnixPaths());
  1191. }
  1192. else
  1193. {
  1194. #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
  1195. std::string installedCompiler;
  1196. // Try to find the newest VS installed on the computer and
  1197. // use that as a default if -G is not specified
  1198. const std::string vsregBase =
  1199. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\";
  1200. std::vector<std::string> vsVerions;
  1201. vsVerions.push_back("VisualStudio\\");
  1202. vsVerions.push_back("VCExpress\\");
  1203. vsVerions.push_back("WDExpress\\");
  1204. struct VSRegistryEntryName
  1205. {
  1206. const char* MSVersion;
  1207. const char* GeneratorName;
  1208. };
  1209. VSRegistryEntryName version[] = {
  1210. {"6.0", "Visual Studio 6"},
  1211. {"7.0", "Visual Studio 7"},
  1212. {"7.1", "Visual Studio 7 .NET 2003"},
  1213. {"8.0", "Visual Studio 8 2005"},
  1214. {"9.0", "Visual Studio 9 2008"},
  1215. {"10.0", "Visual Studio 10 2010"},
  1216. {"11.0", "Visual Studio 11 2012"},
  1217. {"12.0", "Visual Studio 12 2013"},
  1218. {"14.0", "Visual Studio 14 2015"},
  1219. {0, 0}};
  1220. for(int i=0; version[i].MSVersion != 0; i++)
  1221. {
  1222. for(size_t b=0; b < vsVerions.size(); b++)
  1223. {
  1224. std::string reg = vsregBase + vsVerions[b] + version[i].MSVersion;
  1225. reg += ";InstallDir]";
  1226. cmSystemTools::ExpandRegistryValues(reg,
  1227. cmSystemTools::KeyWOW64_32);
  1228. if (!(reg == "/registry"))
  1229. {
  1230. installedCompiler = version[i].GeneratorName;
  1231. break;
  1232. }
  1233. }
  1234. }
  1235. cmGlobalGenerator* gen
  1236. = this->CreateGlobalGenerator(installedCompiler.c_str());
  1237. if(!gen)
  1238. {
  1239. gen = new cmGlobalNMakeMakefileGenerator;
  1240. }
  1241. this->SetGlobalGenerator(gen);
  1242. std::cout << "-- Building for: " << gen->GetName() << "\n";
  1243. #else
  1244. this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator3);
  1245. #endif
  1246. }
  1247. if(!this->GlobalGenerator)
  1248. {
  1249. cmSystemTools::Error("Could not create generator");
  1250. return -1;
  1251. }
  1252. }
  1253. const char* genName = this->CacheManager
  1254. ->GetInitializedCacheValue("CMAKE_GENERATOR");
  1255. if(genName)
  1256. {
  1257. if(!this->GlobalGenerator->MatchesGeneratorName(genName))
  1258. {
  1259. std::string message = "Error: generator : ";
  1260. message += this->GlobalGenerator->GetName();
  1261. message += "\nDoes not match the generator used previously: ";
  1262. message += genName;
  1263. message +=
  1264. "\nEither remove the CMakeCache.txt file and CMakeFiles "
  1265. "directory or choose a different binary directory.";
  1266. cmSystemTools::Error(message.c_str());
  1267. return -2;
  1268. }
  1269. }
  1270. if(!this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR"))
  1271. {
  1272. this->CacheManager->AddCacheEntry("CMAKE_GENERATOR",
  1273. this->GlobalGenerator->GetName().c_str(),
  1274. "Name of generator.",
  1275. cmState::INTERNAL);
  1276. this->CacheManager->AddCacheEntry("CMAKE_EXTRA_GENERATOR",
  1277. this->GlobalGenerator->GetExtraGeneratorName().c_str(),
  1278. "Name of external makefile project generator.",
  1279. cmState::INTERNAL);
  1280. }
  1281. if(const char* platformName =
  1282. this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR_PLATFORM"))
  1283. {
  1284. if(this->GeneratorPlatform.empty())
  1285. {
  1286. this->GeneratorPlatform = platformName;
  1287. }
  1288. else if(this->GeneratorPlatform != platformName)
  1289. {
  1290. std::string message = "Error: generator platform: ";
  1291. message += this->GeneratorPlatform;
  1292. message += "\nDoes not match the platform used previously: ";
  1293. message += platformName;
  1294. message +=
  1295. "\nEither remove the CMakeCache.txt file and CMakeFiles "
  1296. "directory or choose a different binary directory.";
  1297. cmSystemTools::Error(message.c_str());
  1298. return -2;
  1299. }
  1300. }
  1301. else
  1302. {
  1303. this->CacheManager->AddCacheEntry("CMAKE_GENERATOR_PLATFORM",
  1304. this->GeneratorPlatform.c_str(),
  1305. "Name of generator platform.",
  1306. cmState::INTERNAL);
  1307. }
  1308. if(const char* tsName =
  1309. this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR_TOOLSET"))
  1310. {
  1311. if(this->GeneratorToolset.empty())
  1312. {
  1313. this->GeneratorToolset = tsName;
  1314. }
  1315. else if(this->GeneratorToolset != tsName)
  1316. {
  1317. std::string message = "Error: generator toolset: ";
  1318. message += this->GeneratorToolset;
  1319. message += "\nDoes not match the toolset used previously: ";
  1320. message += tsName;
  1321. message +=
  1322. "\nEither remove the CMakeCache.txt file and CMakeFiles "
  1323. "directory or choose a different binary directory.";
  1324. cmSystemTools::Error(message.c_str());
  1325. return -2;
  1326. }
  1327. }
  1328. else
  1329. {
  1330. this->CacheManager->AddCacheEntry("CMAKE_GENERATOR_TOOLSET",
  1331. this->GeneratorToolset.c_str(),
  1332. "Name of generator toolset.",
  1333. cmState::INTERNAL);
  1334. }
  1335. // reset any system configuration information, except for when we are
  1336. // InTryCompile. With TryCompile the system info is taken from the parent's
  1337. // info to save time
  1338. if (!this->State->GetIsInTryCompile())
  1339. {
  1340. this->GlobalGenerator->ClearEnabledLanguages();
  1341. this->TruncateOutputLog("CMakeOutput.log");
  1342. this->TruncateOutputLog("CMakeError.log");
  1343. }
  1344. // actually do the configure
  1345. this->GlobalGenerator->Configure();
  1346. // Before saving the cache
  1347. // if the project did not define one of the entries below, add them now
  1348. // so users can edit the values in the cache:
  1349. // We used to always present LIBRARY_OUTPUT_PATH and
  1350. // EXECUTABLE_OUTPUT_PATH. They are now documented as old-style and
  1351. // should no longer be used. Therefore we present them only if the
  1352. // project requires compatibility with CMake 2.4. We detect this
  1353. // here by looking for the old CMAKE_BACKWARDS_COMPATIBILITY
  1354. // variable created when CMP0001 is not set to NEW.
  1355. if(this->State
  1356. ->GetInitializedCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
  1357. {
  1358. if(!this->State->GetInitializedCacheValue("LIBRARY_OUTPUT_PATH"))
  1359. {
  1360. this->State->AddCacheEntry
  1361. ("LIBRARY_OUTPUT_PATH", "",
  1362. "Single output directory for building all libraries.",
  1363. cmState::PATH);
  1364. }
  1365. if(!this->State
  1366. ->GetInitializedCacheValue("EXECUTABLE_OUTPUT_PATH"))
  1367. {
  1368. this->State->AddCacheEntry
  1369. ("EXECUTABLE_OUTPUT_PATH", "",
  1370. "Single output directory for building all executables.",
  1371. cmState::PATH);
  1372. }
  1373. }
  1374. if(!this->State
  1375. ->GetInitializedCacheValue("CMAKE_USE_RELATIVE_PATHS"))
  1376. {
  1377. this->State->AddCacheEntry
  1378. ("CMAKE_USE_RELATIVE_PATHS", "OFF",
  1379. "If true, cmake will use relative paths in makefiles and projects.",
  1380. cmState::BOOL);
  1381. if (!this->State->GetCacheEntryProperty("CMAKE_USE_RELATIVE_PATHS",
  1382. "ADVANCED"))
  1383. {
  1384. this->State->SetCacheEntryProperty("CMAKE_USE_RELATIVE_PATHS",
  1385. "ADVANCED", "1");
  1386. }
  1387. }
  1388. if(cmSystemTools::GetFatalErrorOccured())
  1389. {
  1390. const char* makeProgram =
  1391. this->State->GetInitializedCacheValue("CMAKE_MAKE_PROGRAM");
  1392. if (!makeProgram || cmSystemTools::IsOff(makeProgram))
  1393. {
  1394. // We must have a bad generator selection. Wipe the cache entry so the
  1395. // user can select another.
  1396. this->State->RemoveCacheEntry("CMAKE_GENERATOR");
  1397. this->State->RemoveCacheEntry("CMAKE_EXTRA_GENERATOR");
  1398. }
  1399. }
  1400. cmMakefile* mf=this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  1401. if (mf->IsOn("CTEST_USE_LAUNCHERS")
  1402. && !this->State->GetGlobalProperty("RULE_LAUNCH_COMPILE"))
  1403. {
  1404. cmSystemTools::Error("CTEST_USE_LAUNCHERS is enabled, but the "
  1405. "RULE_LAUNCH_COMPILE global property is not defined.\n"
  1406. "Did you forget to include(CTest) in the toplevel "
  1407. "CMakeLists.txt ?");
  1408. }
  1409. // only save the cache if there were no fatal errors
  1410. if ( this->GetWorkingMode() == NORMAL_MODE )
  1411. {
  1412. this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
  1413. }
  1414. if(cmSystemTools::GetErrorOccuredFlag())
  1415. {
  1416. return -1;
  1417. }
  1418. return 0;
  1419. }
  1420. void cmake::PreLoadCMakeFiles()
  1421. {
  1422. std::vector<std::string> args;
  1423. std::string pre_load = this->GetHomeDirectory();
  1424. if (!pre_load.empty())
  1425. {
  1426. pre_load += "/PreLoad.cmake";
  1427. if ( cmSystemTools::FileExists(pre_load.c_str()) )
  1428. {
  1429. this->ReadListFile(args, pre_load.c_str());
  1430. }
  1431. }
  1432. pre_load = this->GetHomeOutputDirectory();
  1433. if (!pre_load.empty())
  1434. {
  1435. pre_load += "/PreLoad.cmake";
  1436. if ( cmSystemTools::FileExists(pre_load.c_str()) )
  1437. {
  1438. this->ReadListFile(args, pre_load.c_str());
  1439. }
  1440. }
  1441. }
  1442. // handle a command line invocation
  1443. int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
  1444. {
  1445. // Process the arguments
  1446. this->SetArgs(args);
  1447. if(cmSystemTools::GetErrorOccuredFlag())
  1448. {
  1449. return -1;
  1450. }
  1451. // If we are given a stamp list file check if it is really out of date.
  1452. if(!this->CheckStampList.empty() &&
  1453. cmakeCheckStampList(this->CheckStampList.c_str()))
  1454. {
  1455. return 0;
  1456. }
  1457. // If we are given a stamp file check if it is really out of date.
  1458. if(!this->CheckStampFile.empty() &&
  1459. cmakeCheckStampFile(this->CheckStampFile.c_str()))
  1460. {
  1461. return 0;
  1462. }
  1463. if ( this->GetWorkingMode() == NORMAL_MODE )
  1464. {
  1465. // load the cache
  1466. if(this->LoadCache() < 0)
  1467. {
  1468. cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
  1469. return -1;
  1470. }
  1471. }
  1472. else
  1473. {
  1474. this->AddCMakePaths();
  1475. }
  1476. // Add any cache args
  1477. if ( !this->SetCacheArgs(args) )
  1478. {
  1479. cmSystemTools::Error("Problem processing arguments. Aborting.\n");
  1480. return -1;
  1481. }
  1482. // In script mode we terminate after running the script.
  1483. if(this->GetWorkingMode() != NORMAL_MODE)
  1484. {
  1485. if(cmSystemTools::GetErrorOccuredFlag())
  1486. {
  1487. return -1;
  1488. }
  1489. else
  1490. {
  1491. return 0;
  1492. }
  1493. }
  1494. // If MAKEFLAGS are given in the environment, remove the environment
  1495. // variable. This will prevent try-compile from succeeding when it
  1496. // should fail (if "-i" is an option). We cannot simply test
  1497. // whether "-i" is given and remove it because some make programs
  1498. // encode the MAKEFLAGS variable in a strange way.
  1499. if(getenv("MAKEFLAGS"))
  1500. {
  1501. cmSystemTools::PutEnv("MAKEFLAGS=");
  1502. }
  1503. this->PreLoadCMakeFiles();
  1504. if ( noconfigure )
  1505. {
  1506. return 0;
  1507. }
  1508. // now run the global generate
  1509. // Check the state of the build system to see if we need to regenerate.
  1510. if(!this->CheckBuildSystem())
  1511. {
  1512. return 0;
  1513. }
  1514. // If we are doing global generate, we better set start and start
  1515. // output directory to the root of the project.
  1516. std::string oldstartdir = this->GetStartDirectory();
  1517. std::string oldstartoutputdir = this->GetStartOutputDirectory();
  1518. this->SetStartDirectory(this->GetHomeDirectory());
  1519. this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
  1520. int ret = this->Configure();
  1521. if (ret || this->GetWorkingMode() != NORMAL_MODE)
  1522. {
  1523. #if defined(CMAKE_HAVE_VS_GENERATORS)
  1524. if(!this->VSSolutionFile.empty() && this->GlobalGenerator)
  1525. {
  1526. // CMake is running to regenerate a Visual Studio build tree
  1527. // during a build from the VS IDE. The build files cannot be
  1528. // regenerated, so we should stop the build.
  1529. cmSystemTools::Message(
  1530. "CMake Configure step failed. "
  1531. "Build files cannot be regenerated correctly. "
  1532. "Attempting to stop IDE build.");
  1533. cmGlobalVisualStudioGenerator* gg =
  1534. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  1535. gg->CallVisualStudioMacro(cmGlobalVisualStudioGenerator::MacroStop,
  1536. this->VSSolutionFile.c_str());
  1537. }
  1538. #endif
  1539. return ret;
  1540. }
  1541. ret = this->Generate();
  1542. std::string message = "Build files have been written to: ";
  1543. message += this->GetHomeOutputDirectory();
  1544. this->UpdateProgress(message.c_str(), -1);
  1545. if(ret)
  1546. {
  1547. return ret;
  1548. }
  1549. this->SetStartDirectory(oldstartdir);
  1550. this->SetStartOutputDirectory(oldstartoutputdir);
  1551. return ret;
  1552. }
  1553. int cmake::Generate()
  1554. {
  1555. if(!this->GlobalGenerator)
  1556. {
  1557. return -1;
  1558. }
  1559. this->GlobalGenerator->DoGenerate();
  1560. if ( !this->GraphVizFile.empty() )
  1561. {
  1562. std::cout << "Generate graphviz: " << this->GraphVizFile << std::endl;
  1563. this->GenerateGraphViz(this->GraphVizFile.c_str());
  1564. }
  1565. if(this->WarnUnusedCli)
  1566. {
  1567. this->RunCheckForUnusedVariables();
  1568. }
  1569. if(cmSystemTools::GetErrorOccuredFlag())
  1570. {
  1571. return -1;
  1572. }
  1573. // Save the cache again after a successful Generate so that any internal
  1574. // variables created during Generate are saved. (Specifically target GUIDs
  1575. // for the Visual Studio and Xcode generators.)
  1576. if ( this->GetWorkingMode() == NORMAL_MODE )
  1577. {
  1578. this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
  1579. }
  1580. return 0;
  1581. }
  1582. void cmake::AddCacheEntry(const std::string& key, const char* value,
  1583. const char* helpString,
  1584. int type)
  1585. {
  1586. this->CacheManager->AddCacheEntry(key, value,
  1587. helpString,
  1588. cmState::CacheEntryType(type));
  1589. }
  1590. const char* cmake::GetCacheDefinition(const std::string& name) const
  1591. {
  1592. return this->CacheManager->GetInitializedCacheValue(name);
  1593. }
  1594. void cmake::AddDefaultCommands()
  1595. {
  1596. std::vector<cmCommand*> commands;
  1597. GetBootstrapCommands1(commands);
  1598. GetBootstrapCommands2(commands);
  1599. GetPredefinedCommands(commands);
  1600. for(std::vector<cmCommand*>::iterator i = commands.begin();
  1601. i != commands.end(); ++i)
  1602. {
  1603. this->State->AddCommand(*i);
  1604. }
  1605. }
  1606. void cmake::AddDefaultGenerators()
  1607. {
  1608. #if defined(_WIN32) && !defined(__CYGWIN__)
  1609. # if !defined(CMAKE_BOOT_MINGW)
  1610. this->Generators.push_back(
  1611. cmGlobalVisualStudio14Generator::NewFactory());
  1612. this->Generators.push_back(
  1613. cmGlobalVisualStudio12Generator::NewFactory());
  1614. this->Generators.push_back(
  1615. cmGlobalVisualStudio11Generator::NewFactory());
  1616. this->Generators.push_back(
  1617. cmGlobalVisualStudio10Generator::NewFactory());
  1618. this->Generators.push_back(
  1619. cmGlobalVisualStudio9Generator::NewFactory());
  1620. this->Generators.push_back(
  1621. cmGlobalVisualStudio8Generator::NewFactory());
  1622. this->Generators.push_back(
  1623. cmGlobalVisualStudio71Generator::NewFactory());
  1624. this->Generators.push_back(
  1625. cmGlobalVisualStudio7Generator::NewFactory());
  1626. this->Generators.push_back(
  1627. cmGlobalVisualStudio6Generator::NewFactory());
  1628. this->Generators.push_back(
  1629. cmGlobalBorlandMakefileGenerator::NewFactory());
  1630. this->Generators.push_back(
  1631. cmGlobalNMakeMakefileGenerator::NewFactory());
  1632. this->Generators.push_back(
  1633. cmGlobalJOMMakefileGenerator::NewFactory());
  1634. # endif
  1635. this->Generators.push_back(
  1636. cmGlobalMSYSMakefileGenerator::NewFactory());
  1637. this->Generators.push_back(
  1638. cmGlobalMinGWMakefileGenerator::NewFactory());
  1639. #endif
  1640. this->Generators.push_back(
  1641. cmGlobalUnixMakefileGenerator3::NewFactory());
  1642. this->Generators.push_back(
  1643. cmGlobalNinjaGenerator::NewFactory());
  1644. #if defined(CMAKE_USE_WMAKE)
  1645. this->Generators.push_back(
  1646. cmGlobalWatcomWMakeGenerator::NewFactory());
  1647. #endif
  1648. #ifdef CMAKE_USE_XCODE
  1649. this->Generators.push_back(
  1650. cmGlobalXCodeGenerator::NewFactory());
  1651. #endif
  1652. }
  1653. bool cmake::ParseCacheEntry(const std::string& entry,
  1654. std::string& var,
  1655. std::string& value,
  1656. cmState::CacheEntryType& type)
  1657. {
  1658. return cmCacheManager::ParseEntry(entry, var, value, type);
  1659. }
  1660. int cmake::LoadCache()
  1661. {
  1662. // could we not read the cache
  1663. if (!this->LoadCache(this->GetHomeOutputDirectory()))
  1664. {
  1665. // if it does exist, but isn't readable then warn the user
  1666. std::string cacheFile = this->GetHomeOutputDirectory();
  1667. cacheFile += "/CMakeCache.txt";
  1668. if(cmSystemTools::FileExists(cacheFile.c_str()))
  1669. {
  1670. cmSystemTools::Error(
  1671. "There is a CMakeCache.txt file for the current binary tree but "
  1672. "cmake does not have permission to read it. Please check the "
  1673. "permissions of the directory you are trying to run CMake on.");
  1674. return -1;
  1675. }
  1676. }
  1677. // setup CMAKE_ROOT and CMAKE_COMMAND
  1678. if(!this->AddCMakePaths())
  1679. {
  1680. return -3;
  1681. }
  1682. return 0;
  1683. }
  1684. bool cmake::LoadCache(const std::string& path)
  1685. {
  1686. return this->CacheManager->LoadCache(path);
  1687. }
  1688. bool cmake::LoadCache(const std::string& path, bool internal,
  1689. std::set<std::string>& excludes,
  1690. std::set<std::string>& includes)
  1691. {
  1692. return this->CacheManager->LoadCache(path, internal, excludes, includes);
  1693. }
  1694. bool cmake::SaveCache(const std::string& path)
  1695. {
  1696. return this->CacheManager->SaveCache(path);
  1697. }
  1698. bool cmake::DeleteCache(const std::string& path)
  1699. {
  1700. return this->CacheManager->DeleteCache(path);
  1701. }
  1702. void cmake::SetProgressCallback(ProgressCallbackType f, void *cd)
  1703. {
  1704. this->ProgressCallback = f;
  1705. this->ProgressCallbackClientData = cd;
  1706. }
  1707. void cmake::UpdateProgress(const char *msg, float prog)
  1708. {
  1709. if(this->ProgressCallback && !this->State->GetIsInTryCompile())
  1710. {
  1711. (*this->ProgressCallback)(msg, prog, this->ProgressCallbackClientData);
  1712. return;
  1713. }
  1714. }
  1715. bool cmake::GetIsInTryCompile() const
  1716. {
  1717. return this->State->GetIsInTryCompile();
  1718. }
  1719. void cmake::SetIsInTryCompile(bool b)
  1720. {
  1721. this->State->SetIsInTryCompile(b);
  1722. }
  1723. void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
  1724. {
  1725. for(RegisteredGeneratorsVector::const_iterator i =
  1726. this->Generators.begin(); i != this->Generators.end(); ++i)
  1727. {
  1728. cmDocumentationEntry e;
  1729. (*i)->GetDocumentation(e);
  1730. v.push_back(e);
  1731. }
  1732. for(RegisteredExtraGeneratorsMap::const_iterator i =
  1733. this->ExtraGenerators.begin(); i != this->ExtraGenerators.end(); ++i)
  1734. {
  1735. cmDocumentationEntry e;
  1736. cmExternalMakefileProjectGenerator* generator = (i->second)();
  1737. generator->GetDocumentation(e, i->first);
  1738. e.Name = i->first;
  1739. delete generator;
  1740. v.push_back(e);
  1741. }
  1742. }
  1743. void cmake::PrintGeneratorList()
  1744. {
  1745. #ifdef CMAKE_BUILD_WITH_CMAKE
  1746. cmDocumentation doc;
  1747. std::vector<cmDocumentationEntry> generators;
  1748. this->GetGeneratorDocumentation(generators);
  1749. doc.AppendSection("Generators",generators);
  1750. std::cerr << "\n";
  1751. doc.PrintDocumentation(cmDocumentation::ListGenerators, std::cerr);
  1752. #endif
  1753. }
  1754. void cmake::UpdateConversionPathTable()
  1755. {
  1756. // Update the path conversion table with any specified file:
  1757. const char* tablepath =
  1758. this->CacheManager
  1759. ->GetInitializedCacheValue("CMAKE_PATH_TRANSLATION_FILE");
  1760. if(tablepath)
  1761. {
  1762. cmsys::ifstream table( tablepath );
  1763. if(!table)
  1764. {
  1765. cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to ", tablepath,
  1766. ". CMake can not open file.");
  1767. cmSystemTools::ReportLastSystemError("CMake can not open file.");
  1768. }
  1769. else
  1770. {
  1771. std::string a, b;
  1772. while(!table.eof())
  1773. {
  1774. // two entries per line
  1775. table >> a; table >> b;
  1776. cmSystemTools::AddTranslationPath( a, b);
  1777. }
  1778. }
  1779. }
  1780. }
  1781. //----------------------------------------------------------------------------
  1782. int cmake::CheckBuildSystem()
  1783. {
  1784. // We do not need to rerun CMake. Check dependency integrity. Use
  1785. // the make system's VERBOSE environment variable to enable verbose
  1786. // output. This can be skipped by setting CMAKE_NO_VERBOSE (which is set
  1787. // by the Eclipse and KDevelop generators).
  1788. bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0)
  1789. && (cmSystemTools::GetEnv("CMAKE_NO_VERBOSE") == 0));
  1790. // This method will check the integrity of the build system if the
  1791. // option was given on the command line. It reads the given file to
  1792. // determine whether CMake should rerun.
  1793. // If no file is provided for the check, we have to rerun.
  1794. if(this->CheckBuildSystemArgument.empty())
  1795. {
  1796. if(verbose)
  1797. {
  1798. std::ostringstream msg;
  1799. msg << "Re-run cmake no build system arguments\n";
  1800. cmSystemTools::Stdout(msg.str().c_str());
  1801. }
  1802. return 1;
  1803. }
  1804. // If the file provided does not exist, we have to rerun.
  1805. if(!cmSystemTools::FileExists(this->CheckBuildSystemArgument.c_str()))
  1806. {
  1807. if(verbose)
  1808. {
  1809. std::ostringstream msg;
  1810. msg << "Re-run cmake missing file: "
  1811. << this->CheckBuildSystemArgument << "\n";
  1812. cmSystemTools::Stdout(msg.str().c_str());
  1813. }
  1814. return 1;
  1815. }
  1816. // Read the rerun check file and use it to decide whether to do the
  1817. // global generate.
  1818. cmake cm;
  1819. cmGlobalGenerator gg;
  1820. gg.SetCMakeInstance(&cm);
  1821. cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  1822. cmMakefile* mf = lg->GetMakefile();
  1823. if(!mf->ReadListFile(this->CheckBuildSystemArgument.c_str()) ||
  1824. cmSystemTools::GetErrorOccuredFlag())
  1825. {
  1826. if(verbose)
  1827. {
  1828. std::ostringstream msg;
  1829. msg << "Re-run cmake error reading : "
  1830. << this->CheckBuildSystemArgument << "\n";
  1831. cmSystemTools::Stdout(msg.str().c_str());
  1832. }
  1833. // There was an error reading the file. Just rerun.
  1834. return 1;
  1835. }
  1836. if(this->ClearBuildSystem)
  1837. {
  1838. // Get the generator used for this build system.
  1839. const char* genName = mf->GetDefinition("CMAKE_DEPENDS_GENERATOR");
  1840. if(!genName || genName[0] == '\0')
  1841. {
  1842. genName = "Unix Makefiles";
  1843. }
  1844. // Create the generator and use it to clear the dependencies.
  1845. cmsys::auto_ptr<cmGlobalGenerator>
  1846. ggd(this->CreateGlobalGenerator(genName));
  1847. if(ggd.get())
  1848. {
  1849. cmsys::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
  1850. lgd->ClearDependencies(mf, verbose);
  1851. }
  1852. }
  1853. // If any byproduct of makefile generation is missing we must re-run.
  1854. std::vector<std::string> products;
  1855. if(const char* productStr = mf->GetDefinition("CMAKE_MAKEFILE_PRODUCTS"))
  1856. {
  1857. cmSystemTools::ExpandListArgument(productStr, products);
  1858. }
  1859. for(std::vector<std::string>::const_iterator pi = products.begin();
  1860. pi != products.end(); ++pi)
  1861. {
  1862. if(!(cmSystemTools::FileExists(pi->c_str()) ||
  1863. cmSystemTools::FileIsSymlink(*pi)))
  1864. {
  1865. if(verbose)
  1866. {
  1867. std::ostringstream msg;
  1868. msg << "Re-run cmake, missing byproduct: " << *pi << "\n";
  1869. cmSystemTools::Stdout(msg.str().c_str());
  1870. }
  1871. return 1;
  1872. }
  1873. }
  1874. // Get the set of dependencies and outputs.
  1875. std::vector<std::string> depends;
  1876. std::vector<std::string> outputs;
  1877. const char* dependsStr = mf->GetDefinition("CMAKE_MAKEFILE_DEPENDS");
  1878. const char* outputsStr = mf->GetDefinition("CMAKE_MAKEFILE_OUTPUTS");
  1879. if(dependsStr && outputsStr)
  1880. {
  1881. cmSystemTools::ExpandListArgument(dependsStr, depends);
  1882. cmSystemTools::ExpandListArgument(outputsStr, outputs);
  1883. }
  1884. if(depends.empty() || outputs.empty())
  1885. {
  1886. // Not enough information was provided to do the test. Just rerun.
  1887. if(verbose)
  1888. {
  1889. std::ostringstream msg;
  1890. msg << "Re-run cmake no CMAKE_MAKEFILE_DEPENDS "
  1891. "or CMAKE_MAKEFILE_OUTPUTS :\n";
  1892. cmSystemTools::Stdout(msg.str().c_str());
  1893. }
  1894. return 1;
  1895. }
  1896. // Find the newest dependency.
  1897. std::vector<std::string>::iterator dep = depends.begin();
  1898. std::string dep_newest = *dep++;
  1899. for(;dep != depends.end(); ++dep)
  1900. {
  1901. int result = 0;
  1902. if(this->FileComparison->FileTimeCompare(dep_newest.c_str(),
  1903. dep->c_str(), &result))
  1904. {
  1905. if(result < 0)
  1906. {
  1907. dep_newest = *dep;
  1908. }
  1909. }
  1910. else
  1911. {
  1912. if(verbose)
  1913. {
  1914. std::ostringstream msg;
  1915. msg << "Re-run cmake: build system dependency is missing\n";
  1916. cmSystemTools::Stdout(msg.str().c_str());
  1917. }
  1918. return 1;
  1919. }
  1920. }
  1921. // Find the oldest output.
  1922. std::vector<std::string>::iterator out = outputs.begin();
  1923. std::string out_oldest = *out++;
  1924. for(;out != outputs.end(); ++out)
  1925. {
  1926. int result = 0;
  1927. if(this->FileComparison->FileTimeCompare(out_oldest.c_str(),
  1928. out->c_str(), &result))
  1929. {
  1930. if(result > 0)
  1931. {
  1932. out_oldest = *out;
  1933. }
  1934. }
  1935. else
  1936. {
  1937. if(verbose)
  1938. {
  1939. std::ostringstream msg;
  1940. msg << "Re-run cmake: build system output is missing\n";
  1941. cmSystemTools::Stdout(msg.str().c_str());
  1942. }
  1943. return 1;
  1944. }
  1945. }
  1946. // If any output is older than any dependency then rerun.
  1947. {
  1948. int result = 0;
  1949. if(!this->FileComparison->FileTimeCompare(out_oldest.c_str(),
  1950. dep_newest.c_str(),
  1951. &result) ||
  1952. result < 0)
  1953. {
  1954. if(verbose)
  1955. {
  1956. std::ostringstream msg;
  1957. msg << "Re-run cmake file: " << out_oldest
  1958. << " older than: " << dep_newest << "\n";
  1959. cmSystemTools::Stdout(msg.str().c_str());
  1960. }
  1961. return 1;
  1962. }
  1963. }
  1964. // No need to rerun.
  1965. return 0;
  1966. }
  1967. //----------------------------------------------------------------------------
  1968. void cmake::TruncateOutputLog(const char* fname)
  1969. {
  1970. std::string fullPath = this->GetHomeOutputDirectory();
  1971. fullPath += "/";
  1972. fullPath += fname;
  1973. struct stat st;
  1974. if ( ::stat(fullPath.c_str(), &st) )
  1975. {
  1976. return;
  1977. }
  1978. if (!this->State->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR"))
  1979. {
  1980. cmSystemTools::RemoveFile(fullPath);
  1981. return;
  1982. }
  1983. off_t fsize = st.st_size;
  1984. const off_t maxFileSize = 50 * 1024;
  1985. if ( fsize < maxFileSize )
  1986. {
  1987. //TODO: truncate file
  1988. return;
  1989. }
  1990. }
  1991. inline std::string removeQuotes(const std::string& s)
  1992. {
  1993. if(s[0] == '\"' && s[s.size()-1] == '\"')
  1994. {
  1995. return s.substr(1, s.size()-2);
  1996. }
  1997. return s;
  1998. }
  1999. void cmake::MarkCliAsUsed(const std::string& variable)
  2000. {
  2001. this->UsedCliVariables[variable] = true;
  2002. }
  2003. void cmake::GenerateGraphViz(const char* fileName) const
  2004. {
  2005. #ifdef CMAKE_BUILD_WITH_CMAKE
  2006. cmsys::auto_ptr<cmGraphVizWriter> gvWriter(
  2007. new cmGraphVizWriter(this->GetGlobalGenerator()->GetLocalGenerators()));
  2008. std::string settingsFile = this->GetHomeOutputDirectory();
  2009. settingsFile += "/CMakeGraphVizOptions.cmake";
  2010. std::string fallbackSettingsFile = this->GetHomeDirectory();
  2011. fallbackSettingsFile += "/CMakeGraphVizOptions.cmake";
  2012. gvWriter->ReadSettings(settingsFile.c_str(), fallbackSettingsFile.c_str());
  2013. gvWriter->WritePerTargetFiles(fileName);
  2014. gvWriter->WriteTargetDependersFiles(fileName);
  2015. gvWriter->WriteGlobalFile(fileName);
  2016. #endif
  2017. }
  2018. void cmake::SetProperty(const std::string& prop, const char* value)
  2019. {
  2020. this->State->SetGlobalProperty(prop, value);
  2021. }
  2022. void cmake::AppendProperty(const std::string& prop,
  2023. const char* value, bool asString)
  2024. {
  2025. this->State->AppendGlobalProperty(prop, value, asString);
  2026. }
  2027. const char *cmake::GetProperty(const std::string& prop)
  2028. {
  2029. return this->State->GetGlobalProperty(prop);
  2030. }
  2031. bool cmake::GetPropertyAsBool(const std::string& prop)
  2032. {
  2033. return this->State->GetGlobalPropertyAsBool(prop);
  2034. }
  2035. cmInstalledFile *cmake::GetOrCreateInstalledFile(
  2036. cmMakefile* mf, const std::string& name)
  2037. {
  2038. std::map<std::string, cmInstalledFile>::iterator i =
  2039. this->InstalledFiles.find(name);
  2040. if(i != this->InstalledFiles.end())
  2041. {
  2042. cmInstalledFile &file = i->second;
  2043. return &file;
  2044. }
  2045. else
  2046. {
  2047. cmInstalledFile &file = this->InstalledFiles[name];
  2048. file.SetName(mf, name);
  2049. return &file;
  2050. }
  2051. }
  2052. cmInstalledFile const* cmake::GetInstalledFile(const std::string& name) const
  2053. {
  2054. std::map<std::string, cmInstalledFile>::const_iterator i =
  2055. this->InstalledFiles.find(name);
  2056. if(i != this->InstalledFiles.end())
  2057. {
  2058. cmInstalledFile const& file = i->second;
  2059. return &file;
  2060. }
  2061. else
  2062. {
  2063. return 0;
  2064. }
  2065. }
  2066. int cmake::GetSystemInformation(std::vector<std::string>& args)
  2067. {
  2068. // so create the directory
  2069. std::string resultFile;
  2070. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  2071. std::string destPath = cwd + "/__cmake_systeminformation";
  2072. cmSystemTools::RemoveADirectory(destPath);
  2073. if (!cmSystemTools::MakeDirectory(destPath.c_str()))
  2074. {
  2075. std::cerr << "Error: --system-information must be run from a "
  2076. "writable directory!\n";
  2077. return 1;
  2078. }
  2079. // process the arguments
  2080. bool writeToStdout = true;
  2081. for(unsigned int i=1; i < args.size(); ++i)
  2082. {
  2083. std::string arg = args[i];
  2084. if(arg.find("-V",0) == 0)
  2085. {
  2086. this->Verbose = true;
  2087. }
  2088. else if(arg.find("-G",0) == 0)
  2089. {
  2090. std::string value = arg.substr(2);
  2091. if(value.empty())
  2092. {
  2093. ++i;
  2094. if(i >= args.size())
  2095. {
  2096. cmSystemTools::Error("No generator specified for -G");
  2097. this->PrintGeneratorList();
  2098. return -1;
  2099. }
  2100. value = args[i];
  2101. }
  2102. cmGlobalGenerator* gen =
  2103. this->CreateGlobalGenerator(value);
  2104. if(!gen)
  2105. {
  2106. cmSystemTools::Error("Could not create named generator ",
  2107. value.c_str());
  2108. this->PrintGeneratorList();
  2109. }
  2110. else
  2111. {
  2112. this->SetGlobalGenerator(gen);
  2113. }
  2114. }
  2115. // no option assume it is the output file
  2116. else
  2117. {
  2118. if (!cmSystemTools::FileIsFullPath(arg.c_str()))
  2119. {
  2120. resultFile = cwd;
  2121. resultFile += "/";
  2122. }
  2123. resultFile += arg;
  2124. writeToStdout = false;
  2125. }
  2126. }
  2127. // we have to find the module directory, so we can copy the files
  2128. this->AddCMakePaths();
  2129. std::string modulesPath =
  2130. this->State->GetInitializedCacheValue("CMAKE_ROOT");
  2131. modulesPath += "/Modules";
  2132. std::string inFile = modulesPath;
  2133. inFile += "/SystemInformation.cmake";
  2134. std::string outFile = destPath;
  2135. outFile += "/CMakeLists.txt";
  2136. // Copy file
  2137. if(!cmSystemTools::cmCopyFile(inFile.c_str(), outFile.c_str()))
  2138. {
  2139. std::cerr << "Error copying file \"" << inFile
  2140. << "\" to \"" << outFile << "\".\n";
  2141. return 1;
  2142. }
  2143. // do we write to a file or to stdout?
  2144. if (resultFile.empty())
  2145. {
  2146. resultFile = cwd;
  2147. resultFile += "/__cmake_systeminformation/results.txt";
  2148. }
  2149. // now run cmake on the CMakeLists file
  2150. cmSystemTools::ChangeDirectory(destPath);
  2151. std::vector<std::string> args2;
  2152. args2.push_back(args[0]);
  2153. args2.push_back(destPath);
  2154. std::string resultArg = "-DRESULT_FILE=";
  2155. resultArg += resultFile;
  2156. args2.push_back(resultArg);
  2157. int res = this->Run(args2, false);
  2158. if (res != 0)
  2159. {
  2160. std::cerr << "Error: --system-information failed on internal CMake!\n";
  2161. return res;
  2162. }
  2163. // change back to the original directory
  2164. cmSystemTools::ChangeDirectory(cwd);
  2165. // echo results to stdout if needed
  2166. if (writeToStdout)
  2167. {
  2168. FILE* fin = cmsys::SystemTools::Fopen(resultFile, "r");
  2169. if(fin)
  2170. {
  2171. const int bufferSize = 4096;
  2172. char buffer[bufferSize];
  2173. size_t n;
  2174. while((n = fread(buffer, 1, bufferSize, fin)) > 0)
  2175. {
  2176. for(char* c = buffer; c < buffer+n; ++c)
  2177. {
  2178. putc(*c, stdout);
  2179. }
  2180. fflush(stdout);
  2181. }
  2182. fclose(fin);
  2183. }
  2184. }
  2185. // clean up the directory
  2186. cmSystemTools::RemoveADirectory(destPath);
  2187. return 0;
  2188. }
  2189. //----------------------------------------------------------------------------
  2190. static bool cmakeCheckStampFile(const char* stampName)
  2191. {
  2192. // The stamp file does not exist. Use the stamp dependencies to
  2193. // determine whether it is really out of date. This works in
  2194. // conjunction with cmLocalVisualStudio7Generator to avoid
  2195. // repeatedly re-running CMake when the user rebuilds the entire
  2196. // solution.
  2197. std::string stampDepends = stampName;
  2198. stampDepends += ".depend";
  2199. #if defined(_WIN32) || defined(__CYGWIN__)
  2200. cmsys::ifstream fin(stampDepends.c_str(), std::ios::in | std::ios::binary);
  2201. #else
  2202. cmsys::ifstream fin(stampDepends.c_str(), std::ios::in);
  2203. #endif
  2204. if(!fin)
  2205. {
  2206. // The stamp dependencies file cannot be read. Just assume the
  2207. // build system is really out of date.
  2208. std::cout << "CMake is re-running because " << stampName
  2209. << " dependency file is missing.\n";
  2210. return false;
  2211. }
  2212. // Compare the stamp dependencies against the dependency file itself.
  2213. cmFileTimeComparison ftc;
  2214. std::string dep;
  2215. while(cmSystemTools::GetLineFromStream(fin, dep))
  2216. {
  2217. int result;
  2218. if(!dep.empty() && dep[0] != '#' &&
  2219. (!ftc.FileTimeCompare(stampDepends.c_str(), dep.c_str(), &result)
  2220. || result < 0))
  2221. {
  2222. // The stamp depends file is older than this dependency. The
  2223. // build system is really out of date.
  2224. std::cout << "CMake is re-running because " << stampName
  2225. << " is out-of-date.\n";
  2226. std::cout << " the file '" << dep << "'\n";
  2227. std::cout << " is newer than '" << stampDepends << "'\n";
  2228. std::cout << " result='" << result << "'\n";
  2229. return false;
  2230. }
  2231. }
  2232. // The build system is up to date. The stamp file has been removed
  2233. // by the VS IDE due to a "rebuild" request. Restore it atomically.
  2234. std::ostringstream stampTempStream;
  2235. stampTempStream << stampName << ".tmp" << cmSystemTools::RandomSeed();
  2236. std::string stampTempString = stampTempStream.str();
  2237. const char* stampTemp = stampTempString.c_str();
  2238. {
  2239. // TODO: Teach cmGeneratedFileStream to use a random temp file (with
  2240. // multiple tries in unlikely case of conflict) and use that here.
  2241. cmsys::ofstream stamp(stampTemp);
  2242. stamp << "# CMake generation timestamp file for this directory.\n";
  2243. }
  2244. if(cmSystemTools::RenameFile(stampTemp, stampName))
  2245. {
  2246. // Notify the user why CMake is not re-running. It is safe to
  2247. // just print to stdout here because this code is only reachable
  2248. // through an undocumented flag used by the VS generator.
  2249. std::cout << "CMake does not need to re-run because "
  2250. << stampName << " is up-to-date.\n";
  2251. return true;
  2252. }
  2253. else
  2254. {
  2255. cmSystemTools::RemoveFile(stampTemp);
  2256. cmSystemTools::Error("Cannot restore timestamp ", stampName);
  2257. return false;
  2258. }
  2259. }
  2260. //----------------------------------------------------------------------------
  2261. static bool cmakeCheckStampList(const char* stampList)
  2262. {
  2263. // If the stamp list does not exist CMake must rerun to generate it.
  2264. if(!cmSystemTools::FileExists(stampList))
  2265. {
  2266. std::cout << "CMake is re-running because generate.stamp.list "
  2267. << "is missing.\n";
  2268. return false;
  2269. }
  2270. cmsys::ifstream fin(stampList);
  2271. if(!fin)
  2272. {
  2273. std::cout << "CMake is re-running because generate.stamp.list "
  2274. << "could not be read.\n";
  2275. return false;
  2276. }
  2277. // Check each stamp.
  2278. std::string stampName;
  2279. while(cmSystemTools::GetLineFromStream(fin, stampName))
  2280. {
  2281. if(!cmakeCheckStampFile(stampName.c_str()))
  2282. {
  2283. return false;
  2284. }
  2285. }
  2286. return true;
  2287. }
  2288. //----------------------------------------------------------------------------
  2289. void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
  2290. cmListFileBacktrace const& bt)
  2291. {
  2292. cmListFileBacktrace backtrace = bt;
  2293. backtrace.MakeRelative();
  2294. std::ostringstream msg;
  2295. bool isError = false;
  2296. // Construct the message header.
  2297. if(t == cmake::FATAL_ERROR)
  2298. {
  2299. isError = true;
  2300. msg << "CMake Error";
  2301. }
  2302. else if(t == cmake::INTERNAL_ERROR)
  2303. {
  2304. isError = true;
  2305. msg << "CMake Internal Error (please report a bug)";
  2306. }
  2307. else if(t == cmake::LOG)
  2308. {
  2309. msg << "CMake Debug Log";
  2310. }
  2311. else if(t == cmake::DEPRECATION_ERROR)
  2312. {
  2313. msg << "CMake Deprecation Error";
  2314. isError = true;
  2315. }
  2316. else if (t == cmake::DEPRECATION_WARNING)
  2317. {
  2318. msg << "CMake Deprecation Warning";
  2319. }
  2320. else
  2321. {
  2322. msg << "CMake Warning";
  2323. if(t == cmake::AUTHOR_WARNING)
  2324. {
  2325. // Allow suppression of these warnings.
  2326. const char* suppress = this->State->GetCacheEntryValue(
  2327. "CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
  2328. if(suppress && cmSystemTools::IsOn(suppress))
  2329. {
  2330. return;
  2331. }
  2332. msg << " (dev)";
  2333. }
  2334. }
  2335. // Add the immediate context.
  2336. cmListFileBacktrace::const_iterator i = backtrace.begin();
  2337. if(i != backtrace.end())
  2338. {
  2339. cmListFileContext const& lfc = *i;
  2340. msg << (lfc.Line? " at ": " in ") << lfc;
  2341. ++i;
  2342. }
  2343. // Add the message text.
  2344. {
  2345. msg << ":\n";
  2346. cmDocumentationFormatter formatter;
  2347. formatter.SetIndent(" ");
  2348. formatter.PrintFormatted(msg, text.c_str());
  2349. }
  2350. // Add the rest of the context.
  2351. if(i != backtrace.end())
  2352. {
  2353. msg << "Call Stack (most recent call first):\n";
  2354. while(i != backtrace.end())
  2355. {
  2356. cmListFileContext const& lfc = *i;
  2357. msg << " " << lfc << "\n";
  2358. ++i;
  2359. }
  2360. }
  2361. // Add a note about warning suppression.
  2362. if(t == cmake::AUTHOR_WARNING)
  2363. {
  2364. msg <<
  2365. "This warning is for project developers. Use -Wno-dev to suppress it.";
  2366. }
  2367. // Add a terminating blank line.
  2368. msg << "\n";
  2369. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2370. // Add a C++ stack trace to internal errors.
  2371. if(t == cmake::INTERNAL_ERROR)
  2372. {
  2373. std::string stack = cmsys::SystemInformation::GetProgramStack(0,0);
  2374. if(!stack.empty())
  2375. {
  2376. if(cmHasLiteralPrefix(stack, "WARNING:"))
  2377. {
  2378. stack = "Note:" + stack.substr(8);
  2379. }
  2380. msg << stack << "\n";
  2381. }
  2382. }
  2383. #endif
  2384. // Output the message.
  2385. if(isError)
  2386. {
  2387. cmSystemTools::SetErrorOccured();
  2388. cmSystemTools::Message(msg.str().c_str(), "Error");
  2389. }
  2390. else
  2391. {
  2392. cmSystemTools::Message(msg.str().c_str(), "Warning");
  2393. }
  2394. }
  2395. //----------------------------------------------------------------------------
  2396. std::vector<std::string> cmake::GetDebugConfigs()
  2397. {
  2398. std::vector<std::string> configs;
  2399. if(const char* config_list =
  2400. this->State->GetGlobalProperty("DEBUG_CONFIGURATIONS"))
  2401. {
  2402. // Expand the specified list and convert to upper-case.
  2403. cmSystemTools::ExpandListArgument(config_list, configs);
  2404. std::transform(configs.begin(),
  2405. configs.end(),
  2406. configs.begin(),
  2407. cmSystemTools::UpperCase);
  2408. }
  2409. // If no configurations were specified, use a default list.
  2410. if(configs.empty())
  2411. {
  2412. configs.push_back("DEBUG");
  2413. }
  2414. return configs;
  2415. }
  2416. int cmake::Build(const std::string& dir,
  2417. const std::string& target,
  2418. const std::string& config,
  2419. const std::vector<std::string>& nativeOptions,
  2420. bool clean)
  2421. {
  2422. if(!cmSystemTools::FileIsDirectory(dir))
  2423. {
  2424. std::cerr << "Error: " << dir << " is not a directory\n";
  2425. return 1;
  2426. }
  2427. std::string cachePath = dir;
  2428. cmSystemTools::ConvertToUnixSlashes(cachePath);
  2429. if(!this->LoadCache(cachePath))
  2430. {
  2431. std::cerr << "Error: could not load cache\n";
  2432. return 1;
  2433. }
  2434. const char* cachedGenerator =
  2435. this->State->GetCacheEntryValue("CMAKE_GENERATOR");
  2436. if(!cachedGenerator)
  2437. {
  2438. std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n";
  2439. return 1;
  2440. }
  2441. cmsys::auto_ptr<cmGlobalGenerator> gen(
  2442. this->CreateGlobalGenerator(cachedGenerator));
  2443. if(!gen.get())
  2444. {
  2445. std::cerr << "Error: could create CMAKE_GENERATOR \""
  2446. << cachedGenerator << "\"\n";
  2447. return 1;
  2448. }
  2449. std::string output;
  2450. std::string projName;
  2451. const char* cachedProjectName =
  2452. this->State->GetCacheEntryValue("CMAKE_PROJECT_NAME");
  2453. if(!cachedProjectName)
  2454. {
  2455. std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n";
  2456. return 1;
  2457. }
  2458. projName = cachedProjectName;
  2459. bool verbose = false;
  2460. const char* cachedVerbose =
  2461. this->State->GetCacheEntryValue("CMAKE_VERBOSE_MAKEFILE");
  2462. if(cachedVerbose)
  2463. {
  2464. verbose = cmSystemTools::IsOn(cachedVerbose);
  2465. }
  2466. return gen->Build("", dir,
  2467. projName, target,
  2468. output,
  2469. "",
  2470. config, clean, false, verbose, 0,
  2471. cmSystemTools::OUTPUT_PASSTHROUGH,
  2472. nativeOptions);
  2473. }
  2474. void cmake::WatchUnusedCli(const std::string& var)
  2475. {
  2476. #ifdef CMAKE_BUILD_WITH_CMAKE
  2477. this->VariableWatch->AddWatch(var, cmWarnUnusedCliWarning, this);
  2478. if(this->UsedCliVariables.find(var) == this->UsedCliVariables.end())
  2479. {
  2480. this->UsedCliVariables[var] = false;
  2481. }
  2482. #endif
  2483. }
  2484. void cmake::UnwatchUnusedCli(const std::string& var)
  2485. {
  2486. #ifdef CMAKE_BUILD_WITH_CMAKE
  2487. this->VariableWatch->RemoveWatch(var, cmWarnUnusedCliWarning);
  2488. this->UsedCliVariables.erase(var);
  2489. #endif
  2490. }
  2491. void cmake::RunCheckForUnusedVariables()
  2492. {
  2493. #ifdef CMAKE_BUILD_WITH_CMAKE
  2494. bool haveUnused = false;
  2495. std::ostringstream msg;
  2496. msg << "Manually-specified variables were not used by the project:";
  2497. for(std::map<std::string, bool>::const_iterator
  2498. it = this->UsedCliVariables.begin();
  2499. it != this->UsedCliVariables.end(); ++it)
  2500. {
  2501. if(!it->second)
  2502. {
  2503. haveUnused = true;
  2504. msg << "\n " << it->first;
  2505. }
  2506. }
  2507. if(haveUnused)
  2508. {
  2509. this->IssueMessage(cmake::WARNING, msg.str());
  2510. }
  2511. #endif
  2512. }