cmake.cxx 76 KB

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