cmake.cxx 91 KB

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