cmake.cxx 75 KB

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