cmake.cxx 90 KB

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