cmake.cxx 91 KB

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