cmake.cxx 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856
  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. std::string message = "Build files have been written to: ";
  1579. message += this->GetHomeOutputDirectory();
  1580. this->UpdateProgress(message, -1);
  1581. return ret;
  1582. }
  1583. int cmake::Generate()
  1584. {
  1585. if (!this->GlobalGenerator) {
  1586. return -1;
  1587. }
  1588. if (!this->GlobalGenerator->Compute()) {
  1589. return -1;
  1590. }
  1591. this->GlobalGenerator->Generate();
  1592. if (!this->GraphVizFile.empty()) {
  1593. std::cout << "Generate graphviz: " << this->GraphVizFile << std::endl;
  1594. this->GenerateGraphViz(this->GraphVizFile.c_str());
  1595. }
  1596. if (this->WarnUnusedCli) {
  1597. this->RunCheckForUnusedVariables();
  1598. }
  1599. if (cmSystemTools::GetErrorOccuredFlag()) {
  1600. return -1;
  1601. }
  1602. // Save the cache again after a successful Generate so that any internal
  1603. // variables created during Generate are saved. (Specifically target GUIDs
  1604. // for the Visual Studio and Xcode generators.)
  1605. this->SaveCache(this->GetHomeOutputDirectory());
  1606. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1607. this->FileAPI->WriteReplies();
  1608. #endif
  1609. return 0;
  1610. }
  1611. void cmake::AddCacheEntry(const std::string& key, const char* value,
  1612. const char* helpString, int type)
  1613. {
  1614. this->State->AddCacheEntry(key, value, helpString,
  1615. cmStateEnums::CacheEntryType(type));
  1616. this->UnwatchUnusedCli(key);
  1617. if (key == "CMAKE_WARN_DEPRECATED") {
  1618. this->Messenger->SetSuppressDeprecatedWarnings(
  1619. value && cmSystemTools::IsOff(value));
  1620. } else if (key == "CMAKE_ERROR_DEPRECATED") {
  1621. this->Messenger->SetDeprecatedWarningsAsErrors(cmSystemTools::IsOn(value));
  1622. } else if (key == "CMAKE_SUPPRESS_DEVELOPER_WARNINGS") {
  1623. this->Messenger->SetSuppressDevWarnings(cmSystemTools::IsOn(value));
  1624. } else if (key == "CMAKE_SUPPRESS_DEVELOPER_ERRORS") {
  1625. this->Messenger->SetDevWarningsAsErrors(value &&
  1626. cmSystemTools::IsOff(value));
  1627. }
  1628. }
  1629. bool cmake::DoWriteGlobVerifyTarget() const
  1630. {
  1631. return this->State->DoWriteGlobVerifyTarget();
  1632. }
  1633. std::string const& cmake::GetGlobVerifyScript() const
  1634. {
  1635. return this->State->GetGlobVerifyScript();
  1636. }
  1637. std::string const& cmake::GetGlobVerifyStamp() const
  1638. {
  1639. return this->State->GetGlobVerifyStamp();
  1640. }
  1641. void cmake::AddGlobCacheEntry(bool recurse, bool listDirectories,
  1642. bool followSymlinks, const std::string& relative,
  1643. const std::string& expression,
  1644. const std::vector<std::string>& files,
  1645. const std::string& variable,
  1646. cmListFileBacktrace const& backtrace)
  1647. {
  1648. this->State->AddGlobCacheEntry(recurse, listDirectories, followSymlinks,
  1649. relative, expression, files, variable,
  1650. backtrace);
  1651. }
  1652. std::string cmake::StripExtension(const std::string& file) const
  1653. {
  1654. auto dotpos = file.rfind('.');
  1655. if (dotpos != std::string::npos) {
  1656. auto ext = file.substr(dotpos + 1);
  1657. #if defined(_WIN32) || defined(__APPLE__)
  1658. ext = cmSystemTools::LowerCase(ext);
  1659. #endif
  1660. if (this->IsSourceExtension(ext) || this->IsHeaderExtension(ext)) {
  1661. return file.substr(0, dotpos);
  1662. }
  1663. }
  1664. return file;
  1665. }
  1666. const char* cmake::GetCacheDefinition(const std::string& name) const
  1667. {
  1668. const std::string* p = this->State->GetInitializedCacheValue(name);
  1669. return p ? p->c_str() : nullptr;
  1670. }
  1671. void cmake::AddScriptingCommands()
  1672. {
  1673. GetScriptingCommands(this->State);
  1674. }
  1675. void cmake::AddProjectCommands()
  1676. {
  1677. GetProjectCommands(this->State);
  1678. }
  1679. void cmake::AddDefaultGenerators()
  1680. {
  1681. #if defined(_WIN32) && !defined(__CYGWIN__)
  1682. # if !defined(CMAKE_BOOT_MINGW)
  1683. this->Generators.push_back(
  1684. cmGlobalVisualStudioVersionedGenerator::NewFactory16());
  1685. this->Generators.push_back(
  1686. cmGlobalVisualStudioVersionedGenerator::NewFactory15());
  1687. this->Generators.push_back(cmGlobalVisualStudio14Generator::NewFactory());
  1688. this->Generators.push_back(cmGlobalVisualStudio12Generator::NewFactory());
  1689. this->Generators.push_back(cmGlobalVisualStudio11Generator::NewFactory());
  1690. this->Generators.push_back(cmGlobalVisualStudio10Generator::NewFactory());
  1691. this->Generators.push_back(cmGlobalVisualStudio9Generator::NewFactory());
  1692. this->Generators.push_back(cmGlobalBorlandMakefileGenerator::NewFactory());
  1693. this->Generators.push_back(cmGlobalNMakeMakefileGenerator::NewFactory());
  1694. this->Generators.push_back(cmGlobalJOMMakefileGenerator::NewFactory());
  1695. # endif
  1696. this->Generators.push_back(cmGlobalMSYSMakefileGenerator::NewFactory());
  1697. this->Generators.push_back(cmGlobalMinGWMakefileGenerator::NewFactory());
  1698. #endif
  1699. this->Generators.push_back(cmGlobalUnixMakefileGenerator3::NewFactory());
  1700. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1701. # if defined(__linux__) || defined(_WIN32)
  1702. this->Generators.push_back(cmGlobalGhsMultiGenerator::NewFactory());
  1703. # endif
  1704. this->Generators.push_back(cmGlobalNinjaGenerator::NewFactory());
  1705. #endif
  1706. #if defined(CMAKE_USE_WMAKE)
  1707. this->Generators.push_back(cmGlobalWatcomWMakeGenerator::NewFactory());
  1708. #endif
  1709. #ifdef CMAKE_USE_XCODE
  1710. this->Generators.push_back(cmGlobalXCodeGenerator::NewFactory());
  1711. #endif
  1712. }
  1713. bool cmake::ParseCacheEntry(const std::string& entry, std::string& var,
  1714. std::string& value,
  1715. cmStateEnums::CacheEntryType& type)
  1716. {
  1717. return cmState::ParseCacheEntry(entry, var, value, type);
  1718. }
  1719. int cmake::LoadCache()
  1720. {
  1721. // could we not read the cache
  1722. if (!this->LoadCache(this->GetHomeOutputDirectory())) {
  1723. // if it does exist, but isn't readable then warn the user
  1724. std::string cacheFile = this->GetHomeOutputDirectory();
  1725. cacheFile += "/CMakeCache.txt";
  1726. if (cmSystemTools::FileExists(cacheFile)) {
  1727. cmSystemTools::Error(
  1728. "There is a CMakeCache.txt file for the current binary tree but "
  1729. "cmake does not have permission to read it. Please check the "
  1730. "permissions of the directory you are trying to run CMake on.");
  1731. return -1;
  1732. }
  1733. }
  1734. // setup CMAKE_ROOT and CMAKE_COMMAND
  1735. if (!this->AddCMakePaths()) {
  1736. return -3;
  1737. }
  1738. return 0;
  1739. }
  1740. bool cmake::LoadCache(const std::string& path)
  1741. {
  1742. std::set<std::string> emptySet;
  1743. return this->LoadCache(path, true, emptySet, emptySet);
  1744. }
  1745. bool cmake::LoadCache(const std::string& path, bool internal,
  1746. std::set<std::string>& excludes,
  1747. std::set<std::string>& includes)
  1748. {
  1749. bool result = this->State->LoadCache(path, internal, excludes, includes);
  1750. static const auto entries = { "CMAKE_CACHE_MAJOR_VERSION",
  1751. "CMAKE_CACHE_MINOR_VERSION" };
  1752. for (auto const& entry : entries) {
  1753. this->UnwatchUnusedCli(entry);
  1754. }
  1755. return result;
  1756. }
  1757. bool cmake::SaveCache(const std::string& path)
  1758. {
  1759. bool result = this->State->SaveCache(path, this->GetMessenger());
  1760. static const auto entries = { "CMAKE_CACHE_MAJOR_VERSION",
  1761. "CMAKE_CACHE_MINOR_VERSION",
  1762. "CMAKE_CACHE_PATCH_VERSION",
  1763. "CMAKE_CACHEFILE_DIR" };
  1764. for (auto const& entry : entries) {
  1765. this->UnwatchUnusedCli(entry);
  1766. }
  1767. return result;
  1768. }
  1769. bool cmake::DeleteCache(const std::string& path)
  1770. {
  1771. return this->State->DeleteCache(path);
  1772. }
  1773. void cmake::SetProgressCallback(ProgressCallbackType f)
  1774. {
  1775. this->ProgressCallback = std::move(f);
  1776. }
  1777. void cmake::UpdateProgress(const std::string& msg, float prog)
  1778. {
  1779. if (this->ProgressCallback && !this->State->GetIsInTryCompile()) {
  1780. this->ProgressCallback(msg, prog);
  1781. }
  1782. }
  1783. bool cmake::GetIsInTryCompile() const
  1784. {
  1785. return this->State->GetIsInTryCompile();
  1786. }
  1787. void cmake::SetIsInTryCompile(bool b)
  1788. {
  1789. this->State->SetIsInTryCompile(b);
  1790. }
  1791. void cmake::AppendGlobalGeneratorsDocumentation(
  1792. std::vector<cmDocumentationEntry>& v)
  1793. {
  1794. const auto defaultGenerator = this->EvaluateDefaultGlobalGenerator();
  1795. const std::string defaultName = defaultGenerator->GetName();
  1796. bool foundDefaultOne = false;
  1797. for (cmGlobalGeneratorFactory* g : this->Generators) {
  1798. cmDocumentationEntry e;
  1799. g->GetDocumentation(e);
  1800. if (!foundDefaultOne &&
  1801. cmSystemTools::StringStartsWith(e.Name, defaultName.c_str())) {
  1802. e.CustomNamePrefix = '*';
  1803. foundDefaultOne = true;
  1804. }
  1805. v.push_back(std::move(e));
  1806. }
  1807. }
  1808. void cmake::AppendExtraGeneratorsDocumentation(
  1809. std::vector<cmDocumentationEntry>& v)
  1810. {
  1811. for (cmExternalMakefileProjectGeneratorFactory* eg : this->ExtraGenerators) {
  1812. const std::string doc = eg->GetDocumentation();
  1813. const std::string name = eg->GetName();
  1814. // Aliases:
  1815. for (std::string const& a : eg->Aliases) {
  1816. cmDocumentationEntry e;
  1817. e.Name = a;
  1818. e.Brief = doc;
  1819. v.push_back(std::move(e));
  1820. }
  1821. // Full names:
  1822. const std::vector<std::string> generators =
  1823. eg->GetSupportedGlobalGenerators();
  1824. for (std::string const& g : generators) {
  1825. cmDocumentationEntry e;
  1826. e.Name =
  1827. cmExternalMakefileProjectGenerator::CreateFullGeneratorName(g, name);
  1828. e.Brief = doc;
  1829. v.push_back(std::move(e));
  1830. }
  1831. }
  1832. }
  1833. std::vector<cmDocumentationEntry> cmake::GetGeneratorsDocumentation()
  1834. {
  1835. std::vector<cmDocumentationEntry> v;
  1836. this->AppendGlobalGeneratorsDocumentation(v);
  1837. this->AppendExtraGeneratorsDocumentation(v);
  1838. return v;
  1839. }
  1840. void cmake::PrintGeneratorList()
  1841. {
  1842. #ifdef CMAKE_BUILD_WITH_CMAKE
  1843. cmDocumentation doc;
  1844. auto generators = this->GetGeneratorsDocumentation();
  1845. doc.AppendSection("Generators", generators);
  1846. std::cerr << "\n";
  1847. doc.PrintDocumentation(cmDocumentation::ListGenerators, std::cerr);
  1848. #endif
  1849. }
  1850. void cmake::UpdateConversionPathTable()
  1851. {
  1852. // Update the path conversion table with any specified file:
  1853. const std::string* tablepath =
  1854. this->State->GetInitializedCacheValue("CMAKE_PATH_TRANSLATION_FILE");
  1855. if (tablepath) {
  1856. cmsys::ifstream table(tablepath->c_str());
  1857. if (!table) {
  1858. cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to " + *tablepath +
  1859. ". CMake can not open file.");
  1860. cmSystemTools::ReportLastSystemError("CMake can not open file.");
  1861. } else {
  1862. std::string a, b;
  1863. while (!table.eof()) {
  1864. // two entries per line
  1865. table >> a;
  1866. table >> b;
  1867. cmSystemTools::AddTranslationPath(a, b);
  1868. }
  1869. }
  1870. }
  1871. }
  1872. int cmake::CheckBuildSystem()
  1873. {
  1874. // We do not need to rerun CMake. Check dependency integrity.
  1875. const bool verbose = isCMakeVerbose();
  1876. // This method will check the integrity of the build system if the
  1877. // option was given on the command line. It reads the given file to
  1878. // determine whether CMake should rerun.
  1879. // If no file is provided for the check, we have to rerun.
  1880. if (this->CheckBuildSystemArgument.empty()) {
  1881. if (verbose) {
  1882. std::ostringstream msg;
  1883. msg << "Re-run cmake no build system arguments\n";
  1884. cmSystemTools::Stdout(msg.str());
  1885. }
  1886. return 1;
  1887. }
  1888. // If the file provided does not exist, we have to rerun.
  1889. if (!cmSystemTools::FileExists(this->CheckBuildSystemArgument)) {
  1890. if (verbose) {
  1891. std::ostringstream msg;
  1892. msg << "Re-run cmake missing file: " << this->CheckBuildSystemArgument
  1893. << "\n";
  1894. cmSystemTools::Stdout(msg.str());
  1895. }
  1896. return 1;
  1897. }
  1898. // Read the rerun check file and use it to decide whether to do the
  1899. // global generate.
  1900. // Actually, all we need is the `set` command.
  1901. cmake cm(RoleScript, cmState::Unknown);
  1902. cm.SetHomeDirectory("");
  1903. cm.SetHomeOutputDirectory("");
  1904. cm.GetCurrentSnapshot().SetDefaultDefinitions();
  1905. cmGlobalGenerator gg(&cm);
  1906. cmMakefile mf(&gg, cm.GetCurrentSnapshot());
  1907. if (!mf.ReadListFile(this->CheckBuildSystemArgument) ||
  1908. cmSystemTools::GetErrorOccuredFlag()) {
  1909. if (verbose) {
  1910. std::ostringstream msg;
  1911. msg << "Re-run cmake error reading : " << this->CheckBuildSystemArgument
  1912. << "\n";
  1913. cmSystemTools::Stdout(msg.str());
  1914. }
  1915. // There was an error reading the file. Just rerun.
  1916. return 1;
  1917. }
  1918. if (this->ClearBuildSystem) {
  1919. // Get the generator used for this build system.
  1920. const char* genName = mf.GetDefinition("CMAKE_DEPENDS_GENERATOR");
  1921. if (!genName || genName[0] == '\0') {
  1922. genName = "Unix Makefiles";
  1923. }
  1924. // Create the generator and use it to clear the dependencies.
  1925. std::unique_ptr<cmGlobalGenerator> ggd(
  1926. this->CreateGlobalGenerator(genName));
  1927. if (ggd) {
  1928. cm.GetCurrentSnapshot().SetDefaultDefinitions();
  1929. cmMakefile mfd(ggd.get(), cm.GetCurrentSnapshot());
  1930. std::unique_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator(&mfd));
  1931. lgd->ClearDependencies(&mfd, verbose);
  1932. }
  1933. }
  1934. // If any byproduct of makefile generation is missing we must re-run.
  1935. std::vector<std::string> products;
  1936. if (const char* productStr = mf.GetDefinition("CMAKE_MAKEFILE_PRODUCTS")) {
  1937. cmSystemTools::ExpandListArgument(productStr, products);
  1938. }
  1939. for (std::string const& p : products) {
  1940. if (!(cmSystemTools::FileExists(p) || cmSystemTools::FileIsSymlink(p))) {
  1941. if (verbose) {
  1942. std::ostringstream msg;
  1943. msg << "Re-run cmake, missing byproduct: " << p << "\n";
  1944. cmSystemTools::Stdout(msg.str());
  1945. }
  1946. return 1;
  1947. }
  1948. }
  1949. // Get the set of dependencies and outputs.
  1950. std::vector<std::string> depends;
  1951. std::vector<std::string> outputs;
  1952. const char* dependsStr = mf.GetDefinition("CMAKE_MAKEFILE_DEPENDS");
  1953. const char* outputsStr = mf.GetDefinition("CMAKE_MAKEFILE_OUTPUTS");
  1954. if (dependsStr && outputsStr) {
  1955. cmSystemTools::ExpandListArgument(dependsStr, depends);
  1956. cmSystemTools::ExpandListArgument(outputsStr, outputs);
  1957. }
  1958. if (depends.empty() || outputs.empty()) {
  1959. // Not enough information was provided to do the test. Just rerun.
  1960. if (verbose) {
  1961. std::ostringstream msg;
  1962. msg << "Re-run cmake no CMAKE_MAKEFILE_DEPENDS "
  1963. "or CMAKE_MAKEFILE_OUTPUTS :\n";
  1964. cmSystemTools::Stdout(msg.str());
  1965. }
  1966. return 1;
  1967. }
  1968. // Find the newest dependency.
  1969. std::vector<std::string>::iterator dep = depends.begin();
  1970. std::string dep_newest = *dep++;
  1971. for (; dep != depends.end(); ++dep) {
  1972. int result = 0;
  1973. if (this->FileTimeCache->Compare(dep_newest, *dep, &result)) {
  1974. if (result < 0) {
  1975. dep_newest = *dep;
  1976. }
  1977. } else {
  1978. if (verbose) {
  1979. std::ostringstream msg;
  1980. msg << "Re-run cmake: build system dependency is missing\n";
  1981. cmSystemTools::Stdout(msg.str());
  1982. }
  1983. return 1;
  1984. }
  1985. }
  1986. // Find the oldest output.
  1987. std::vector<std::string>::iterator out = outputs.begin();
  1988. std::string out_oldest = *out++;
  1989. for (; out != outputs.end(); ++out) {
  1990. int result = 0;
  1991. if (this->FileTimeCache->Compare(out_oldest, *out, &result)) {
  1992. if (result > 0) {
  1993. out_oldest = *out;
  1994. }
  1995. } else {
  1996. if (verbose) {
  1997. std::ostringstream msg;
  1998. msg << "Re-run cmake: build system output is missing\n";
  1999. cmSystemTools::Stdout(msg.str());
  2000. }
  2001. return 1;
  2002. }
  2003. }
  2004. // If any output is older than any dependency then rerun.
  2005. {
  2006. int result = 0;
  2007. if (!this->FileTimeCache->Compare(out_oldest, dep_newest, &result) ||
  2008. result < 0) {
  2009. if (verbose) {
  2010. std::ostringstream msg;
  2011. msg << "Re-run cmake file: " << out_oldest
  2012. << " older than: " << dep_newest << "\n";
  2013. cmSystemTools::Stdout(msg.str());
  2014. }
  2015. return 1;
  2016. }
  2017. }
  2018. // No need to rerun.
  2019. return 0;
  2020. }
  2021. void cmake::TruncateOutputLog(const char* fname)
  2022. {
  2023. std::string fullPath = this->GetHomeOutputDirectory();
  2024. fullPath += "/";
  2025. fullPath += fname;
  2026. struct stat st;
  2027. if (::stat(fullPath.c_str(), &st)) {
  2028. return;
  2029. }
  2030. if (!this->State->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR")) {
  2031. cmSystemTools::RemoveFile(fullPath);
  2032. return;
  2033. }
  2034. off_t fsize = st.st_size;
  2035. const off_t maxFileSize = 50 * 1024;
  2036. if (fsize < maxFileSize) {
  2037. // TODO: truncate file
  2038. return;
  2039. }
  2040. }
  2041. inline std::string removeQuotes(const std::string& s)
  2042. {
  2043. if (s.front() == '\"' && s.back() == '\"') {
  2044. return s.substr(1, s.size() - 2);
  2045. }
  2046. return s;
  2047. }
  2048. void cmake::MarkCliAsUsed(const std::string& variable)
  2049. {
  2050. this->UsedCliVariables[variable] = true;
  2051. }
  2052. void cmake::GenerateGraphViz(const char* fileName) const
  2053. {
  2054. #ifdef CMAKE_BUILD_WITH_CMAKE
  2055. cmGraphVizWriter gvWriter(this->GetGlobalGenerator());
  2056. std::string settingsFile = this->GetHomeOutputDirectory();
  2057. settingsFile += "/CMakeGraphVizOptions.cmake";
  2058. std::string fallbackSettingsFile = this->GetHomeDirectory();
  2059. fallbackSettingsFile += "/CMakeGraphVizOptions.cmake";
  2060. gvWriter.ReadSettings(settingsFile.c_str(), fallbackSettingsFile.c_str());
  2061. gvWriter.WritePerTargetFiles(fileName);
  2062. gvWriter.WriteTargetDependersFiles(fileName);
  2063. gvWriter.WriteGlobalFile(fileName);
  2064. #endif
  2065. }
  2066. void cmake::SetProperty(const std::string& prop, const char* value)
  2067. {
  2068. this->State->SetGlobalProperty(prop, value);
  2069. }
  2070. void cmake::AppendProperty(const std::string& prop, const char* value,
  2071. bool asString)
  2072. {
  2073. this->State->AppendGlobalProperty(prop, value, asString);
  2074. }
  2075. const char* cmake::GetProperty(const std::string& prop)
  2076. {
  2077. return this->State->GetGlobalProperty(prop);
  2078. }
  2079. bool cmake::GetPropertyAsBool(const std::string& prop)
  2080. {
  2081. return this->State->GetGlobalPropertyAsBool(prop);
  2082. }
  2083. cmInstalledFile* cmake::GetOrCreateInstalledFile(cmMakefile* mf,
  2084. const std::string& name)
  2085. {
  2086. std::map<std::string, cmInstalledFile>::iterator i =
  2087. this->InstalledFiles.find(name);
  2088. if (i != this->InstalledFiles.end()) {
  2089. cmInstalledFile& file = i->second;
  2090. return &file;
  2091. }
  2092. cmInstalledFile& file = this->InstalledFiles[name];
  2093. file.SetName(mf, name);
  2094. return &file;
  2095. }
  2096. cmInstalledFile const* cmake::GetInstalledFile(const std::string& name) const
  2097. {
  2098. std::map<std::string, cmInstalledFile>::const_iterator i =
  2099. this->InstalledFiles.find(name);
  2100. if (i != this->InstalledFiles.end()) {
  2101. cmInstalledFile const& file = i->second;
  2102. return &file;
  2103. }
  2104. return nullptr;
  2105. }
  2106. int cmake::GetSystemInformation(std::vector<std::string>& args)
  2107. {
  2108. // so create the directory
  2109. std::string resultFile;
  2110. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  2111. std::string destPath = cwd + "/__cmake_systeminformation";
  2112. cmSystemTools::RemoveADirectory(destPath);
  2113. if (!cmSystemTools::MakeDirectory(destPath)) {
  2114. std::cerr << "Error: --system-information must be run from a "
  2115. "writable directory!\n";
  2116. return 1;
  2117. }
  2118. // process the arguments
  2119. bool writeToStdout = true;
  2120. for (unsigned int i = 1; i < args.size(); ++i) {
  2121. std::string const& arg = args[i];
  2122. if (arg.find("-G", 0) == 0) {
  2123. std::string value = arg.substr(2);
  2124. if (value.empty()) {
  2125. ++i;
  2126. if (i >= args.size()) {
  2127. cmSystemTools::Error("No generator specified for -G");
  2128. this->PrintGeneratorList();
  2129. return -1;
  2130. }
  2131. value = args[i];
  2132. }
  2133. cmGlobalGenerator* gen = this->CreateGlobalGenerator(value);
  2134. if (!gen) {
  2135. cmSystemTools::Error("Could not create named generator " + value);
  2136. this->PrintGeneratorList();
  2137. } else {
  2138. this->SetGlobalGenerator(gen);
  2139. }
  2140. }
  2141. // no option assume it is the output file
  2142. else {
  2143. if (!cmSystemTools::FileIsFullPath(arg)) {
  2144. resultFile = cwd;
  2145. resultFile += "/";
  2146. }
  2147. resultFile += arg;
  2148. writeToStdout = false;
  2149. }
  2150. }
  2151. // we have to find the module directory, so we can copy the files
  2152. this->AddCMakePaths();
  2153. std::string modulesPath = cmSystemTools::GetCMakeRoot();
  2154. modulesPath += "/Modules";
  2155. std::string inFile = modulesPath;
  2156. inFile += "/SystemInformation.cmake";
  2157. std::string outFile = destPath;
  2158. outFile += "/CMakeLists.txt";
  2159. // Copy file
  2160. if (!cmsys::SystemTools::CopyFileAlways(inFile, outFile)) {
  2161. std::cerr << "Error copying file \"" << inFile << "\" to \"" << outFile
  2162. << "\".\n";
  2163. return 1;
  2164. }
  2165. // do we write to a file or to stdout?
  2166. if (resultFile.empty()) {
  2167. resultFile = cwd;
  2168. resultFile += "/__cmake_systeminformation/results.txt";
  2169. }
  2170. {
  2171. // now run cmake on the CMakeLists file
  2172. cmWorkingDirectory workdir(destPath);
  2173. if (workdir.Failed()) {
  2174. // We created the directory and we were able to copy the CMakeLists.txt
  2175. // file to it, so we wouldn't expect to get here unless the default
  2176. // permissions are questionable or some other process has deleted the
  2177. // directory
  2178. std::cerr << "Failed to change to directory " << destPath << " : "
  2179. << std::strerror(workdir.GetLastResult()) << std::endl;
  2180. return 1;
  2181. }
  2182. std::vector<std::string> args2;
  2183. args2.push_back(args[0]);
  2184. args2.push_back(destPath);
  2185. args2.push_back("-DRESULT_FILE=" + resultFile);
  2186. int res = this->Run(args2, false);
  2187. if (res != 0) {
  2188. std::cerr << "Error: --system-information failed on internal CMake!\n";
  2189. return res;
  2190. }
  2191. }
  2192. // echo results to stdout if needed
  2193. if (writeToStdout) {
  2194. FILE* fin = cmsys::SystemTools::Fopen(resultFile, "r");
  2195. if (fin) {
  2196. const int bufferSize = 4096;
  2197. char buffer[bufferSize];
  2198. size_t n;
  2199. while ((n = fread(buffer, 1, bufferSize, fin)) > 0) {
  2200. for (char* c = buffer; c < buffer + n; ++c) {
  2201. putc(*c, stdout);
  2202. }
  2203. fflush(stdout);
  2204. }
  2205. fclose(fin);
  2206. }
  2207. }
  2208. // clean up the directory
  2209. cmSystemTools::RemoveADirectory(destPath);
  2210. return 0;
  2211. }
  2212. static bool cmakeCheckStampFile(const std::string& stampName)
  2213. {
  2214. // The stamp file does not exist. Use the stamp dependencies to
  2215. // determine whether it is really out of date. This works in
  2216. // conjunction with cmLocalVisualStudio7Generator to avoid
  2217. // repeatedly re-running CMake when the user rebuilds the entire
  2218. // solution.
  2219. std::string stampDepends = stampName;
  2220. stampDepends += ".depend";
  2221. #if defined(_WIN32) || defined(__CYGWIN__)
  2222. cmsys::ifstream fin(stampDepends.c_str(), std::ios::in | std::ios::binary);
  2223. #else
  2224. cmsys::ifstream fin(stampDepends.c_str());
  2225. #endif
  2226. if (!fin) {
  2227. // The stamp dependencies file cannot be read. Just assume the
  2228. // build system is really out of date.
  2229. std::cout << "CMake is re-running because " << stampName
  2230. << " dependency file is missing.\n";
  2231. return false;
  2232. }
  2233. // Compare the stamp dependencies against the dependency file itself.
  2234. {
  2235. cmFileTimeCache ftc;
  2236. std::string dep;
  2237. while (cmSystemTools::GetLineFromStream(fin, dep)) {
  2238. int result;
  2239. if (!dep.empty() && dep[0] != '#' &&
  2240. (!ftc.Compare(stampDepends, dep, &result) || result < 0)) {
  2241. // The stamp depends file is older than this dependency. The
  2242. // build system is really out of date.
  2243. std::cout << "CMake is re-running because " << stampName
  2244. << " is out-of-date.\n";
  2245. std::cout << " the file '" << dep << "'\n";
  2246. std::cout << " is newer than '" << stampDepends << "'\n";
  2247. std::cout << " result='" << result << "'\n";
  2248. return false;
  2249. }
  2250. }
  2251. }
  2252. // The build system is up to date. The stamp file has been removed
  2253. // by the VS IDE due to a "rebuild" request. Restore it atomically.
  2254. std::ostringstream stampTempStream;
  2255. stampTempStream << stampName << ".tmp" << cmSystemTools::RandomSeed();
  2256. std::string stampTemp = stampTempStream.str();
  2257. {
  2258. // TODO: Teach cmGeneratedFileStream to use a random temp file (with
  2259. // multiple tries in unlikely case of conflict) and use that here.
  2260. cmsys::ofstream stamp(stampTemp.c_str());
  2261. stamp << "# CMake generation timestamp file for this directory.\n";
  2262. }
  2263. if (cmSystemTools::RenameFile(stampTemp, stampName)) {
  2264. // CMake does not need to re-run because the stamp file is up-to-date.
  2265. return true;
  2266. }
  2267. cmSystemTools::RemoveFile(stampTemp);
  2268. cmSystemTools::Error("Cannot restore timestamp " + stampName);
  2269. return false;
  2270. }
  2271. static bool cmakeCheckStampList(const std::string& stampList)
  2272. {
  2273. // If the stamp list does not exist CMake must rerun to generate it.
  2274. if (!cmSystemTools::FileExists(stampList)) {
  2275. std::cout << "CMake is re-running because generate.stamp.list "
  2276. << "is missing.\n";
  2277. return false;
  2278. }
  2279. cmsys::ifstream fin(stampList.c_str());
  2280. if (!fin) {
  2281. std::cout << "CMake is re-running because generate.stamp.list "
  2282. << "could not be read.\n";
  2283. return false;
  2284. }
  2285. // Check each stamp.
  2286. std::string stampName;
  2287. while (cmSystemTools::GetLineFromStream(fin, stampName)) {
  2288. if (!cmakeCheckStampFile(stampName)) {
  2289. return false;
  2290. }
  2291. }
  2292. return true;
  2293. }
  2294. void cmake::IssueMessage(MessageType t, std::string const& text,
  2295. cmListFileBacktrace const& backtrace) const
  2296. {
  2297. this->Messenger->IssueMessage(t, text, backtrace);
  2298. }
  2299. std::vector<std::string> cmake::GetDebugConfigs()
  2300. {
  2301. std::vector<std::string> configs;
  2302. if (const char* config_list =
  2303. this->State->GetGlobalProperty("DEBUG_CONFIGURATIONS")) {
  2304. // Expand the specified list and convert to upper-case.
  2305. cmSystemTools::ExpandListArgument(config_list, configs);
  2306. std::transform(configs.begin(), configs.end(), configs.begin(),
  2307. cmSystemTools::UpperCase);
  2308. }
  2309. // If no configurations were specified, use a default list.
  2310. if (configs.empty()) {
  2311. configs.emplace_back("DEBUG");
  2312. }
  2313. return configs;
  2314. }
  2315. cmMessenger* cmake::GetMessenger() const
  2316. {
  2317. return this->Messenger;
  2318. }
  2319. int cmake::Build(int jobs, const std::string& dir,
  2320. const std::vector<std::string>& targets,
  2321. const std::string& config,
  2322. const std::vector<std::string>& nativeOptions, bool clean,
  2323. bool verbose)
  2324. {
  2325. this->SetHomeDirectory("");
  2326. this->SetHomeOutputDirectory("");
  2327. if (!cmSystemTools::FileIsDirectory(dir)) {
  2328. std::cerr << "Error: " << dir << " is not a directory\n";
  2329. return 1;
  2330. }
  2331. std::string cachePath = FindCacheFile(dir);
  2332. if (!this->LoadCache(cachePath)) {
  2333. std::cerr << "Error: could not load cache\n";
  2334. return 1;
  2335. }
  2336. const char* cachedGenerator =
  2337. this->State->GetCacheEntryValue("CMAKE_GENERATOR");
  2338. if (!cachedGenerator) {
  2339. std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n";
  2340. return 1;
  2341. }
  2342. cmGlobalGenerator* gen = this->CreateGlobalGenerator(cachedGenerator);
  2343. if (!gen) {
  2344. std::cerr << "Error: could create CMAKE_GENERATOR \"" << cachedGenerator
  2345. << "\"\n";
  2346. return 1;
  2347. }
  2348. this->SetGlobalGenerator(gen);
  2349. const char* cachedGeneratorInstance =
  2350. this->State->GetCacheEntryValue("CMAKE_GENERATOR_INSTANCE");
  2351. if (cachedGeneratorInstance) {
  2352. cmMakefile mf(gen, this->GetCurrentSnapshot());
  2353. if (!gen->SetGeneratorInstance(cachedGeneratorInstance, &mf)) {
  2354. return 1;
  2355. }
  2356. }
  2357. const char* cachedGeneratorPlatform =
  2358. this->State->GetCacheEntryValue("CMAKE_GENERATOR_PLATFORM");
  2359. if (cachedGeneratorPlatform) {
  2360. cmMakefile mf(gen, this->GetCurrentSnapshot());
  2361. if (!gen->SetGeneratorPlatform(cachedGeneratorPlatform, &mf)) {
  2362. return 1;
  2363. }
  2364. }
  2365. std::string output;
  2366. std::string projName;
  2367. const char* cachedProjectName =
  2368. this->State->GetCacheEntryValue("CMAKE_PROJECT_NAME");
  2369. if (!cachedProjectName) {
  2370. std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n";
  2371. return 1;
  2372. }
  2373. projName = cachedProjectName;
  2374. const char* cachedVerbose =
  2375. this->State->GetCacheEntryValue("CMAKE_VERBOSE_MAKEFILE");
  2376. if (cmSystemTools::IsOn(cachedVerbose)) {
  2377. verbose = true;
  2378. }
  2379. #ifdef CMAKE_HAVE_VS_GENERATORS
  2380. // For VS generators, explicitly check if regeneration is necessary before
  2381. // actually starting the build. If not done separately from the build
  2382. // itself, there is the risk of building an out-of-date solution file due
  2383. // to limitations of the underlying build system.
  2384. std::string const stampList = cachePath + "/" + "CMakeFiles/" +
  2385. cmGlobalVisualStudio9Generator::GetGenerateStampList();
  2386. // Note that the stampList file only exists for VS generators.
  2387. if (cmSystemTools::FileExists(stampList)) {
  2388. // Check if running for Visual Studio 9 - we need to explicitly run
  2389. // the glob verification script before starting the build
  2390. this->AddScriptingCommands();
  2391. if (this->GlobalGenerator->MatchesGeneratorName("Visual Studio 9 2008")) {
  2392. std::string const globVerifyScript =
  2393. cachePath + "/" + "CMakeFiles/" + "VerifyGlobs.cmake";
  2394. if (cmSystemTools::FileExists(globVerifyScript)) {
  2395. std::vector<std::string> args;
  2396. this->ReadListFile(args, globVerifyScript);
  2397. }
  2398. }
  2399. if (!cmakeCheckStampList(stampList)) {
  2400. // Correctly initialize the home (=source) and home output (=binary)
  2401. // directories, which is required for running the generation step.
  2402. std::string homeOrig = this->GetHomeDirectory();
  2403. std::string homeOutputOrig = this->GetHomeOutputDirectory();
  2404. this->SetDirectoriesFromFile(cachePath.c_str());
  2405. this->AddProjectCommands();
  2406. int ret = this->Configure();
  2407. if (ret) {
  2408. cmSystemTools::Message("CMake Configure step failed. "
  2409. "Build files cannot be regenerated correctly.");
  2410. return ret;
  2411. }
  2412. ret = this->Generate();
  2413. if (ret) {
  2414. cmSystemTools::Message("CMake Generate step failed. "
  2415. "Build files cannot be regenerated correctly.");
  2416. return ret;
  2417. }
  2418. std::string message = "Build files have been written to: ";
  2419. message += this->GetHomeOutputDirectory();
  2420. this->UpdateProgress(message, -1);
  2421. // Restore the previously set directories to their original value.
  2422. this->SetHomeDirectory(homeOrig);
  2423. this->SetHomeOutputDirectory(homeOutputOrig);
  2424. }
  2425. }
  2426. #endif
  2427. gen->PrintBuildCommandAdvice(std::cerr, jobs);
  2428. return gen->Build(jobs, "", dir, projName, targets, output, "", config,
  2429. clean, false, verbose, cmDuration::zero(),
  2430. cmSystemTools::OUTPUT_PASSTHROUGH, nativeOptions);
  2431. }
  2432. bool cmake::Open(const std::string& dir, bool dryRun)
  2433. {
  2434. this->SetHomeDirectory("");
  2435. this->SetHomeOutputDirectory("");
  2436. if (!cmSystemTools::FileIsDirectory(dir)) {
  2437. std::cerr << "Error: " << dir << " is not a directory\n";
  2438. return false;
  2439. }
  2440. std::string cachePath = FindCacheFile(dir);
  2441. if (!this->LoadCache(cachePath)) {
  2442. std::cerr << "Error: could not load cache\n";
  2443. return false;
  2444. }
  2445. const char* genName = this->State->GetCacheEntryValue("CMAKE_GENERATOR");
  2446. if (!genName) {
  2447. std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n";
  2448. return false;
  2449. }
  2450. const std::string* extraGenName =
  2451. this->State->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
  2452. std::string fullName =
  2453. cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
  2454. genName, extraGenName ? *extraGenName : "");
  2455. std::unique_ptr<cmGlobalGenerator> gen(
  2456. this->CreateGlobalGenerator(fullName));
  2457. if (!gen) {
  2458. std::cerr << "Error: could create CMAKE_GENERATOR \"" << fullName
  2459. << "\"\n";
  2460. return false;
  2461. }
  2462. const char* cachedProjectName =
  2463. this->State->GetCacheEntryValue("CMAKE_PROJECT_NAME");
  2464. if (!cachedProjectName) {
  2465. std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n";
  2466. return false;
  2467. }
  2468. return gen->Open(dir, cachedProjectName, dryRun);
  2469. }
  2470. void cmake::WatchUnusedCli(const std::string& var)
  2471. {
  2472. #ifdef CMAKE_BUILD_WITH_CMAKE
  2473. this->VariableWatch->AddWatch(var, cmWarnUnusedCliWarning, this);
  2474. if (this->UsedCliVariables.find(var) == this->UsedCliVariables.end()) {
  2475. this->UsedCliVariables[var] = false;
  2476. }
  2477. #endif
  2478. }
  2479. void cmake::UnwatchUnusedCli(const std::string& var)
  2480. {
  2481. #ifdef CMAKE_BUILD_WITH_CMAKE
  2482. this->VariableWatch->RemoveWatch(var, cmWarnUnusedCliWarning);
  2483. this->UsedCliVariables.erase(var);
  2484. #endif
  2485. }
  2486. void cmake::RunCheckForUnusedVariables()
  2487. {
  2488. #ifdef CMAKE_BUILD_WITH_CMAKE
  2489. bool haveUnused = false;
  2490. std::ostringstream msg;
  2491. msg << "Manually-specified variables were not used by the project:";
  2492. for (auto const& it : this->UsedCliVariables) {
  2493. if (!it.second) {
  2494. haveUnused = true;
  2495. msg << "\n " << it.first;
  2496. }
  2497. }
  2498. if (haveUnused) {
  2499. this->IssueMessage(MessageType::WARNING, msg.str());
  2500. }
  2501. #endif
  2502. }
  2503. bool cmake::GetSuppressDevWarnings() const
  2504. {
  2505. return this->Messenger->GetSuppressDevWarnings();
  2506. }
  2507. void cmake::SetSuppressDevWarnings(bool b)
  2508. {
  2509. std::string value;
  2510. // equivalent to -Wno-dev
  2511. if (b) {
  2512. value = "TRUE";
  2513. }
  2514. // equivalent to -Wdev
  2515. else {
  2516. value = "FALSE";
  2517. }
  2518. this->AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", value.c_str(),
  2519. "Suppress Warnings that are meant for"
  2520. " the author of the CMakeLists.txt files.",
  2521. cmStateEnums::INTERNAL);
  2522. }
  2523. bool cmake::GetSuppressDeprecatedWarnings() const
  2524. {
  2525. return this->Messenger->GetSuppressDeprecatedWarnings();
  2526. }
  2527. void cmake::SetSuppressDeprecatedWarnings(bool b)
  2528. {
  2529. std::string value;
  2530. // equivalent to -Wno-deprecated
  2531. if (b) {
  2532. value = "FALSE";
  2533. }
  2534. // equivalent to -Wdeprecated
  2535. else {
  2536. value = "TRUE";
  2537. }
  2538. this->AddCacheEntry("CMAKE_WARN_DEPRECATED", value.c_str(),
  2539. "Whether to issue warnings for deprecated "
  2540. "functionality.",
  2541. cmStateEnums::INTERNAL);
  2542. }
  2543. bool cmake::GetDevWarningsAsErrors() const
  2544. {
  2545. return this->Messenger->GetDevWarningsAsErrors();
  2546. }
  2547. void cmake::SetDevWarningsAsErrors(bool b)
  2548. {
  2549. std::string value;
  2550. // equivalent to -Werror=dev
  2551. if (b) {
  2552. value = "FALSE";
  2553. }
  2554. // equivalent to -Wno-error=dev
  2555. else {
  2556. value = "TRUE";
  2557. }
  2558. this->AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_ERRORS", value.c_str(),
  2559. "Suppress errors that are meant for"
  2560. " the author of the CMakeLists.txt files.",
  2561. cmStateEnums::INTERNAL);
  2562. }
  2563. bool cmake::GetDeprecatedWarningsAsErrors() const
  2564. {
  2565. return this->Messenger->GetDeprecatedWarningsAsErrors();
  2566. }
  2567. void cmake::SetDeprecatedWarningsAsErrors(bool b)
  2568. {
  2569. std::string value;
  2570. // equivalent to -Werror=deprecated
  2571. if (b) {
  2572. value = "TRUE";
  2573. }
  2574. // equivalent to -Wno-error=deprecated
  2575. else {
  2576. value = "FALSE";
  2577. }
  2578. this->AddCacheEntry("CMAKE_ERROR_DEPRECATED", value.c_str(),
  2579. "Whether to issue deprecation errors for macros"
  2580. " and functions.",
  2581. cmStateEnums::INTERNAL);
  2582. }