cmake.cxx 75 KB

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