cmake.cxx 76 KB

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