cmake.cxx 75 KB

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