cmake.cxx 91 KB

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