cmake.cxx 76 KB

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