cmake.cxx 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853
  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 (std::vector<std::string>::iterator i = argsSplit.begin();
  1161. i != argsSplit.end(); ++i) {
  1162. SaveCacheEntry save;
  1163. save.key = *i;
  1164. warning << *i << "= ";
  1165. i++;
  1166. save.value = *i;
  1167. warning << *i << "\n";
  1168. const char* existingValue = this->State->GetCacheEntryValue(save.key);
  1169. if (existingValue) {
  1170. save.type = this->State->GetCacheEntryType(save.key);
  1171. if (const char* help =
  1172. this->State->GetCacheEntryProperty(save.key, "HELPSTRING")) {
  1173. save.help = help;
  1174. }
  1175. }
  1176. saved.push_back(std::move(save));
  1177. }
  1178. // remove the cache
  1179. this->DeleteCache(this->GetHomeOutputDirectory());
  1180. // load the empty cache
  1181. this->LoadCache();
  1182. // restore the changed compilers
  1183. for (SaveCacheEntry const& i : saved) {
  1184. this->AddCacheEntry(i.key, i.value.c_str(), i.help.c_str(), i.type);
  1185. }
  1186. cmSystemTools::Message(warning.str());
  1187. // avoid reconfigure if there were errors
  1188. if (!cmSystemTools::GetErrorOccuredFlag()) {
  1189. // re-run configure
  1190. return this->Configure();
  1191. }
  1192. return 0;
  1193. }
  1194. int cmake::Configure()
  1195. {
  1196. DiagLevel diagLevel;
  1197. if (this->DiagLevels.count("deprecated") == 1) {
  1198. diagLevel = this->DiagLevels["deprecated"];
  1199. if (diagLevel == DIAG_IGNORE) {
  1200. this->SetSuppressDeprecatedWarnings(true);
  1201. this->SetDeprecatedWarningsAsErrors(false);
  1202. } else if (diagLevel == DIAG_WARN) {
  1203. this->SetSuppressDeprecatedWarnings(false);
  1204. this->SetDeprecatedWarningsAsErrors(false);
  1205. } else if (diagLevel == DIAG_ERROR) {
  1206. this->SetSuppressDeprecatedWarnings(false);
  1207. this->SetDeprecatedWarningsAsErrors(true);
  1208. }
  1209. }
  1210. if (this->DiagLevels.count("dev") == 1) {
  1211. bool setDeprecatedVariables = false;
  1212. const char* cachedWarnDeprecated =
  1213. this->State->GetCacheEntryValue("CMAKE_WARN_DEPRECATED");
  1214. const char* cachedErrorDeprecated =
  1215. this->State->GetCacheEntryValue("CMAKE_ERROR_DEPRECATED");
  1216. // don't overwrite deprecated warning setting from a previous invocation
  1217. if (!cachedWarnDeprecated && !cachedErrorDeprecated) {
  1218. setDeprecatedVariables = true;
  1219. }
  1220. diagLevel = this->DiagLevels["dev"];
  1221. if (diagLevel == DIAG_IGNORE) {
  1222. this->SetSuppressDevWarnings(true);
  1223. this->SetDevWarningsAsErrors(false);
  1224. if (setDeprecatedVariables) {
  1225. this->SetSuppressDeprecatedWarnings(true);
  1226. this->SetDeprecatedWarningsAsErrors(false);
  1227. }
  1228. } else if (diagLevel == DIAG_WARN) {
  1229. this->SetSuppressDevWarnings(false);
  1230. this->SetDevWarningsAsErrors(false);
  1231. if (setDeprecatedVariables) {
  1232. this->SetSuppressDeprecatedWarnings(false);
  1233. this->SetDeprecatedWarningsAsErrors(false);
  1234. }
  1235. } else if (diagLevel == DIAG_ERROR) {
  1236. this->SetSuppressDevWarnings(false);
  1237. this->SetDevWarningsAsErrors(true);
  1238. if (setDeprecatedVariables) {
  1239. this->SetSuppressDeprecatedWarnings(false);
  1240. this->SetDeprecatedWarningsAsErrors(true);
  1241. }
  1242. }
  1243. }
  1244. // Cache variables may have already been set by a previous invocation,
  1245. // so we cannot rely on command line options alone. Always ensure our
  1246. // messenger is in sync with the cache.
  1247. const char* value = this->State->GetCacheEntryValue("CMAKE_WARN_DEPRECATED");
  1248. this->Messenger->SetSuppressDeprecatedWarnings(value && cmIsOff(value));
  1249. value = this->State->GetCacheEntryValue("CMAKE_ERROR_DEPRECATED");
  1250. this->Messenger->SetDeprecatedWarningsAsErrors(cmIsOn(value));
  1251. value = this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
  1252. this->Messenger->SetSuppressDevWarnings(cmIsOn(value));
  1253. value = this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_ERRORS");
  1254. this->Messenger->SetDevWarningsAsErrors(value && cmIsOff(value));
  1255. int ret = this->ActualConfigure();
  1256. const char* delCacheVars =
  1257. this->State->GetGlobalProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_");
  1258. if (delCacheVars && delCacheVars[0] != 0) {
  1259. return this->HandleDeleteCacheVariables(delCacheVars);
  1260. }
  1261. return ret;
  1262. }
  1263. int cmake::ActualConfigure()
  1264. {
  1265. // Construct right now our path conversion table before it's too late:
  1266. this->UpdateConversionPathTable();
  1267. this->CleanupCommandsAndMacros();
  1268. int res = this->DoPreConfigureChecks();
  1269. if (res < 0) {
  1270. return -2;
  1271. }
  1272. if (!res) {
  1273. this->AddCacheEntry(
  1274. "CMAKE_HOME_DIRECTORY", this->GetHomeDirectory().c_str(),
  1275. "Source directory with the top level CMakeLists.txt file for this "
  1276. "project",
  1277. cmStateEnums::INTERNAL);
  1278. }
  1279. // no generator specified on the command line
  1280. if (!this->GlobalGenerator) {
  1281. const std::string* genName =
  1282. this->State->GetInitializedCacheValue("CMAKE_GENERATOR");
  1283. const std::string* extraGenName =
  1284. this->State->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
  1285. if (genName) {
  1286. std::string fullName =
  1287. cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
  1288. *genName, extraGenName ? *extraGenName : "");
  1289. this->GlobalGenerator = this->CreateGlobalGenerator(fullName);
  1290. }
  1291. if (this->GlobalGenerator) {
  1292. // set the global flag for unix style paths on cmSystemTools as
  1293. // soon as the generator is set. This allows gmake to be used
  1294. // on windows.
  1295. cmSystemTools::SetForceUnixPaths(
  1296. this->GlobalGenerator->GetForceUnixPaths());
  1297. } else {
  1298. this->CreateDefaultGlobalGenerator();
  1299. }
  1300. if (!this->GlobalGenerator) {
  1301. cmSystemTools::Error("Could not create generator");
  1302. return -1;
  1303. }
  1304. }
  1305. const std::string* genName =
  1306. this->State->GetInitializedCacheValue("CMAKE_GENERATOR");
  1307. if (genName) {
  1308. if (!this->GlobalGenerator->MatchesGeneratorName(*genName)) {
  1309. std::string message =
  1310. cmStrCat("Error: generator : ", this->GlobalGenerator->GetName(),
  1311. "\nDoes not match the generator used previously: ", *genName,
  1312. "\nEither remove the CMakeCache.txt file and CMakeFiles "
  1313. "directory or choose a different binary directory.");
  1314. cmSystemTools::Error(message);
  1315. return -2;
  1316. }
  1317. }
  1318. if (!this->State->GetInitializedCacheValue("CMAKE_GENERATOR")) {
  1319. this->AddCacheEntry("CMAKE_GENERATOR",
  1320. this->GlobalGenerator->GetName().c_str(),
  1321. "Name of generator.", cmStateEnums::INTERNAL);
  1322. this->AddCacheEntry("CMAKE_EXTRA_GENERATOR",
  1323. this->GlobalGenerator->GetExtraGeneratorName().c_str(),
  1324. "Name of external makefile project generator.",
  1325. cmStateEnums::INTERNAL);
  1326. }
  1327. if (const std::string* instance =
  1328. this->State->GetInitializedCacheValue("CMAKE_GENERATOR_INSTANCE")) {
  1329. if (this->GeneratorInstanceSet && this->GeneratorInstance != *instance) {
  1330. std::string message =
  1331. cmStrCat("Error: generator instance: ", this->GeneratorInstance,
  1332. "\nDoes not match the instance used previously: ", *instance,
  1333. "\nEither remove the CMakeCache.txt file and CMakeFiles "
  1334. "directory or choose a different binary directory.");
  1335. cmSystemTools::Error(message);
  1336. return -2;
  1337. }
  1338. } else {
  1339. this->AddCacheEntry(
  1340. "CMAKE_GENERATOR_INSTANCE", this->GeneratorInstance.c_str(),
  1341. "Generator instance identifier.", cmStateEnums::INTERNAL);
  1342. }
  1343. if (const std::string* platformName =
  1344. this->State->GetInitializedCacheValue("CMAKE_GENERATOR_PLATFORM")) {
  1345. if (this->GeneratorPlatformSet &&
  1346. this->GeneratorPlatform != *platformName) {
  1347. std::string message = cmStrCat(
  1348. "Error: generator platform: ", this->GeneratorPlatform,
  1349. "\nDoes not match the platform used previously: ", *platformName,
  1350. "\nEither remove the CMakeCache.txt file and CMakeFiles "
  1351. "directory or choose a different binary directory.");
  1352. cmSystemTools::Error(message);
  1353. return -2;
  1354. }
  1355. } else {
  1356. this->AddCacheEntry("CMAKE_GENERATOR_PLATFORM",
  1357. this->GeneratorPlatform.c_str(),
  1358. "Name of generator platform.", cmStateEnums::INTERNAL);
  1359. }
  1360. if (const std::string* tsName =
  1361. this->State->GetInitializedCacheValue("CMAKE_GENERATOR_TOOLSET")) {
  1362. if (this->GeneratorToolsetSet && this->GeneratorToolset != *tsName) {
  1363. std::string message =
  1364. cmStrCat("Error: generator toolset: ", this->GeneratorToolset,
  1365. "\nDoes not match the toolset used previously: ", *tsName,
  1366. "\nEither remove the CMakeCache.txt file and CMakeFiles "
  1367. "directory or choose a different binary directory.");
  1368. cmSystemTools::Error(message);
  1369. return -2;
  1370. }
  1371. } else {
  1372. this->AddCacheEntry("CMAKE_GENERATOR_TOOLSET",
  1373. this->GeneratorToolset.c_str(),
  1374. "Name of generator toolset.", cmStateEnums::INTERNAL);
  1375. }
  1376. // reset any system configuration information, except for when we are
  1377. // InTryCompile. With TryCompile the system info is taken from the parent's
  1378. // info to save time
  1379. if (!this->State->GetIsInTryCompile()) {
  1380. this->GlobalGenerator->ClearEnabledLanguages();
  1381. this->TruncateOutputLog("CMakeOutput.log");
  1382. this->TruncateOutputLog("CMakeError.log");
  1383. }
  1384. #if !defined(CMAKE_BOOTSTRAP)
  1385. this->FileAPI = cm::make_unique<cmFileAPI>(this);
  1386. this->FileAPI->ReadQueries();
  1387. #endif
  1388. // actually do the configure
  1389. this->GlobalGenerator->Configure();
  1390. // Before saving the cache
  1391. // if the project did not define one of the entries below, add them now
  1392. // so users can edit the values in the cache:
  1393. // We used to always present LIBRARY_OUTPUT_PATH and
  1394. // EXECUTABLE_OUTPUT_PATH. They are now documented as old-style and
  1395. // should no longer be used. Therefore we present them only if the
  1396. // project requires compatibility with CMake 2.4. We detect this
  1397. // here by looking for the old CMAKE_BACKWARDS_COMPATIBILITY
  1398. // variable created when CMP0001 is not set to NEW.
  1399. if (this->State->GetInitializedCacheValue("CMAKE_BACKWARDS_COMPATIBILITY")) {
  1400. if (!this->State->GetInitializedCacheValue("LIBRARY_OUTPUT_PATH")) {
  1401. this->AddCacheEntry(
  1402. "LIBRARY_OUTPUT_PATH", "",
  1403. "Single output directory for building all libraries.",
  1404. cmStateEnums::PATH);
  1405. }
  1406. if (!this->State->GetInitializedCacheValue("EXECUTABLE_OUTPUT_PATH")) {
  1407. this->AddCacheEntry(
  1408. "EXECUTABLE_OUTPUT_PATH", "",
  1409. "Single output directory for building all executables.",
  1410. cmStateEnums::PATH);
  1411. }
  1412. }
  1413. cmMakefile* mf = this->GlobalGenerator->GetMakefiles()[0];
  1414. if (mf->IsOn("CTEST_USE_LAUNCHERS") &&
  1415. !this->State->GetGlobalProperty("RULE_LAUNCH_COMPILE")) {
  1416. cmSystemTools::Error(
  1417. "CTEST_USE_LAUNCHERS is enabled, but the "
  1418. "RULE_LAUNCH_COMPILE global property is not defined.\n"
  1419. "Did you forget to include(CTest) in the toplevel "
  1420. "CMakeLists.txt ?");
  1421. }
  1422. this->State->SaveVerificationScript(this->GetHomeOutputDirectory());
  1423. this->SaveCache(this->GetHomeOutputDirectory());
  1424. if (cmSystemTools::GetErrorOccuredFlag()) {
  1425. return -1;
  1426. }
  1427. return 0;
  1428. }
  1429. std::unique_ptr<cmGlobalGenerator> cmake::EvaluateDefaultGlobalGenerator()
  1430. {
  1431. if (!this->EnvironmentGenerator.empty()) {
  1432. cmGlobalGenerator* gen =
  1433. this->CreateGlobalGenerator(this->EnvironmentGenerator);
  1434. if (!gen) {
  1435. cmSystemTools::Error("CMAKE_GENERATOR was set but the specified "
  1436. "generator doesn't exist. Using CMake default.");
  1437. } else {
  1438. return std::unique_ptr<cmGlobalGenerator>(gen);
  1439. }
  1440. }
  1441. #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
  1442. std::string found;
  1443. // Try to find the newest VS installed on the computer and
  1444. // use that as a default if -G is not specified
  1445. const std::string vsregBase = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\";
  1446. static const char* const vsVariants[] = {
  1447. /* clang-format needs this comment to break after the opening brace */
  1448. "VisualStudio\\", "VCExpress\\", "WDExpress\\"
  1449. };
  1450. struct VSVersionedGenerator
  1451. {
  1452. const char* MSVersion;
  1453. const char* GeneratorName;
  1454. };
  1455. static VSVersionedGenerator const vsGenerators[] = {
  1456. { "14.0", "Visual Studio 14 2015" }, //
  1457. { "12.0", "Visual Studio 12 2013" }, //
  1458. { "11.0", "Visual Studio 11 2012" }, //
  1459. { "10.0", "Visual Studio 10 2010" }, //
  1460. { "9.0", "Visual Studio 9 2008" }
  1461. };
  1462. static const char* const vsEntries[] = {
  1463. "\\Setup\\VC;ProductDir", //
  1464. ";InstallDir" //
  1465. };
  1466. if (cmVSSetupAPIHelper(16).IsVSInstalled()) {
  1467. found = "Visual Studio 16 2019";
  1468. } else if (cmVSSetupAPIHelper(15).IsVSInstalled()) {
  1469. found = "Visual Studio 15 2017";
  1470. } else {
  1471. for (VSVersionedGenerator const* g = cm::cbegin(vsGenerators);
  1472. found.empty() && g != cm::cend(vsGenerators); ++g) {
  1473. for (const char* const* v = cm::cbegin(vsVariants);
  1474. found.empty() && v != cm::cend(vsVariants); ++v) {
  1475. for (const char* const* e = cm::cbegin(vsEntries);
  1476. found.empty() && e != cm::cend(vsEntries); ++e) {
  1477. std::string const reg = vsregBase + *v + g->MSVersion + *e;
  1478. std::string dir;
  1479. if (cmSystemTools::ReadRegistryValue(reg, dir,
  1480. cmSystemTools::KeyWOW64_32) &&
  1481. cmSystemTools::PathExists(dir)) {
  1482. found = g->GeneratorName;
  1483. }
  1484. }
  1485. }
  1486. }
  1487. }
  1488. cmGlobalGenerator* gen = this->CreateGlobalGenerator(found);
  1489. if (!gen) {
  1490. gen = new cmGlobalNMakeMakefileGenerator(this);
  1491. }
  1492. return std::unique_ptr<cmGlobalGenerator>(gen);
  1493. #else
  1494. return cm::make_unique<cmGlobalUnixMakefileGenerator3>(this);
  1495. #endif
  1496. }
  1497. void cmake::CreateDefaultGlobalGenerator()
  1498. {
  1499. auto gen = this->EvaluateDefaultGlobalGenerator();
  1500. #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
  1501. // This print could be unified for all platforms
  1502. std::cout << "-- Building for: " << gen->GetName() << "\n";
  1503. #endif
  1504. this->SetGlobalGenerator(gen.release());
  1505. }
  1506. void cmake::PreLoadCMakeFiles()
  1507. {
  1508. std::vector<std::string> args;
  1509. std::string pre_load = this->GetHomeDirectory();
  1510. if (!pre_load.empty()) {
  1511. pre_load += "/PreLoad.cmake";
  1512. if (cmSystemTools::FileExists(pre_load)) {
  1513. this->ReadListFile(args, pre_load);
  1514. }
  1515. }
  1516. pre_load = this->GetHomeOutputDirectory();
  1517. if (!pre_load.empty()) {
  1518. pre_load += "/PreLoad.cmake";
  1519. if (cmSystemTools::FileExists(pre_load)) {
  1520. this->ReadListFile(args, pre_load);
  1521. }
  1522. }
  1523. }
  1524. // handle a command line invocation
  1525. int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
  1526. {
  1527. // Process the arguments
  1528. this->SetArgs(args);
  1529. if (cmSystemTools::GetErrorOccuredFlag()) {
  1530. return -1;
  1531. }
  1532. // If we are given a stamp list file check if it is really out of date.
  1533. if (!this->CheckStampList.empty() &&
  1534. cmakeCheckStampList(this->CheckStampList)) {
  1535. return 0;
  1536. }
  1537. // If we are given a stamp file check if it is really out of date.
  1538. if (!this->CheckStampFile.empty() &&
  1539. cmakeCheckStampFile(this->CheckStampFile)) {
  1540. return 0;
  1541. }
  1542. if (this->GetWorkingMode() == NORMAL_MODE) {
  1543. // load the cache
  1544. if (this->LoadCache() < 0) {
  1545. cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
  1546. return -1;
  1547. }
  1548. } else {
  1549. this->AddCMakePaths();
  1550. }
  1551. // Add any cache args
  1552. if (!this->SetCacheArgs(args)) {
  1553. cmSystemTools::Error("Problem processing arguments. Aborting.\n");
  1554. return -1;
  1555. }
  1556. // In script mode we terminate after running the script.
  1557. if (this->GetWorkingMode() != NORMAL_MODE) {
  1558. if (cmSystemTools::GetErrorOccuredFlag()) {
  1559. return -1;
  1560. }
  1561. return 0;
  1562. }
  1563. // If MAKEFLAGS are given in the environment, remove the environment
  1564. // variable. This will prevent try-compile from succeeding when it
  1565. // should fail (if "-i" is an option). We cannot simply test
  1566. // whether "-i" is given and remove it because some make programs
  1567. // encode the MAKEFLAGS variable in a strange way.
  1568. if (cmSystemTools::HasEnv("MAKEFLAGS")) {
  1569. cmSystemTools::PutEnv("MAKEFLAGS=");
  1570. }
  1571. this->PreLoadCMakeFiles();
  1572. if (noconfigure) {
  1573. return 0;
  1574. }
  1575. // now run the global generate
  1576. // Check the state of the build system to see if we need to regenerate.
  1577. if (!this->CheckBuildSystem()) {
  1578. return 0;
  1579. }
  1580. int ret = this->Configure();
  1581. if (ret) {
  1582. #if defined(CMAKE_HAVE_VS_GENERATORS)
  1583. if (!this->VSSolutionFile.empty() && this->GlobalGenerator) {
  1584. // CMake is running to regenerate a Visual Studio build tree
  1585. // during a build from the VS IDE. The build files cannot be
  1586. // regenerated, so we should stop the build.
  1587. cmSystemTools::Message("CMake Configure step failed. "
  1588. "Build files cannot be regenerated correctly. "
  1589. "Attempting to stop IDE build.");
  1590. cmGlobalVisualStudioGenerator* gg =
  1591. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  1592. gg->CallVisualStudioMacro(cmGlobalVisualStudioGenerator::MacroStop,
  1593. this->VSSolutionFile.c_str());
  1594. }
  1595. #endif
  1596. return ret;
  1597. }
  1598. ret = this->Generate();
  1599. if (ret) {
  1600. cmSystemTools::Message("CMake Generate step failed. "
  1601. "Build files cannot be regenerated correctly.");
  1602. return ret;
  1603. }
  1604. std::string message = cmStrCat("Build files have been written to: ",
  1605. this->GetHomeOutputDirectory());
  1606. this->UpdateProgress(message, -1);
  1607. return ret;
  1608. }
  1609. int cmake::Generate()
  1610. {
  1611. if (!this->GlobalGenerator) {
  1612. return -1;
  1613. }
  1614. if (!this->GlobalGenerator->Compute()) {
  1615. return -1;
  1616. }
  1617. this->GlobalGenerator->Generate();
  1618. if (!this->GraphVizFile.empty()) {
  1619. std::cout << "Generate graphviz: " << this->GraphVizFile << std::endl;
  1620. this->GenerateGraphViz(this->GraphVizFile);
  1621. }
  1622. if (this->WarnUnusedCli) {
  1623. this->RunCheckForUnusedVariables();
  1624. }
  1625. if (cmSystemTools::GetErrorOccuredFlag()) {
  1626. return -1;
  1627. }
  1628. // Save the cache again after a successful Generate so that any internal
  1629. // variables created during Generate are saved. (Specifically target GUIDs
  1630. // for the Visual Studio and Xcode generators.)
  1631. this->SaveCache(this->GetHomeOutputDirectory());
  1632. #if !defined(CMAKE_BOOTSTRAP)
  1633. this->FileAPI->WriteReplies();
  1634. #endif
  1635. return 0;
  1636. }
  1637. void cmake::AddCacheEntry(const std::string& key, const char* value,
  1638. const char* helpString, int type)
  1639. {
  1640. this->State->AddCacheEntry(key, value, helpString,
  1641. cmStateEnums::CacheEntryType(type));
  1642. this->UnwatchUnusedCli(key);
  1643. if (key == "CMAKE_WARN_DEPRECATED") {
  1644. this->Messenger->SetSuppressDeprecatedWarnings(value && cmIsOff(value));
  1645. } else if (key == "CMAKE_ERROR_DEPRECATED") {
  1646. this->Messenger->SetDeprecatedWarningsAsErrors(cmIsOn(value));
  1647. } else if (key == "CMAKE_SUPPRESS_DEVELOPER_WARNINGS") {
  1648. this->Messenger->SetSuppressDevWarnings(cmIsOn(value));
  1649. } else if (key == "CMAKE_SUPPRESS_DEVELOPER_ERRORS") {
  1650. this->Messenger->SetDevWarningsAsErrors(value && cmIsOff(value));
  1651. }
  1652. }
  1653. bool cmake::DoWriteGlobVerifyTarget() const
  1654. {
  1655. return this->State->DoWriteGlobVerifyTarget();
  1656. }
  1657. std::string const& cmake::GetGlobVerifyScript() const
  1658. {
  1659. return this->State->GetGlobVerifyScript();
  1660. }
  1661. std::string const& cmake::GetGlobVerifyStamp() const
  1662. {
  1663. return this->State->GetGlobVerifyStamp();
  1664. }
  1665. void cmake::AddGlobCacheEntry(bool recurse, bool listDirectories,
  1666. bool followSymlinks, const std::string& relative,
  1667. const std::string& expression,
  1668. const std::vector<std::string>& files,
  1669. const std::string& variable,
  1670. cmListFileBacktrace const& backtrace)
  1671. {
  1672. this->State->AddGlobCacheEntry(recurse, listDirectories, followSymlinks,
  1673. relative, expression, files, variable,
  1674. backtrace);
  1675. }
  1676. std::string cmake::StripExtension(const std::string& file) const
  1677. {
  1678. auto dotpos = file.rfind('.');
  1679. if (dotpos != std::string::npos) {
  1680. auto ext = file.substr(dotpos + 1);
  1681. #if defined(_WIN32) || defined(__APPLE__)
  1682. ext = cmSystemTools::LowerCase(ext);
  1683. #endif
  1684. if (this->IsSourceExtension(ext) || this->IsHeaderExtension(ext)) {
  1685. return file.substr(0, dotpos);
  1686. }
  1687. }
  1688. return file;
  1689. }
  1690. const char* cmake::GetCacheDefinition(const std::string& name) const
  1691. {
  1692. const std::string* p = this->State->GetInitializedCacheValue(name);
  1693. return p ? p->c_str() : nullptr;
  1694. }
  1695. void cmake::AddScriptingCommands()
  1696. {
  1697. GetScriptingCommands(this->GetState());
  1698. }
  1699. void cmake::AddProjectCommands()
  1700. {
  1701. GetProjectCommands(this->GetState());
  1702. }
  1703. void cmake::AddDefaultGenerators()
  1704. {
  1705. #if defined(_WIN32) && !defined(__CYGWIN__)
  1706. # if !defined(CMAKE_BOOT_MINGW)
  1707. this->Generators.push_back(
  1708. cmGlobalVisualStudioVersionedGenerator::NewFactory16());
  1709. this->Generators.push_back(
  1710. cmGlobalVisualStudioVersionedGenerator::NewFactory15());
  1711. this->Generators.push_back(cmGlobalVisualStudio14Generator::NewFactory());
  1712. this->Generators.push_back(cmGlobalVisualStudio12Generator::NewFactory());
  1713. this->Generators.push_back(cmGlobalVisualStudio11Generator::NewFactory());
  1714. this->Generators.push_back(cmGlobalVisualStudio10Generator::NewFactory());
  1715. this->Generators.push_back(cmGlobalVisualStudio9Generator::NewFactory());
  1716. this->Generators.push_back(cmGlobalBorlandMakefileGenerator::NewFactory());
  1717. this->Generators.push_back(cmGlobalNMakeMakefileGenerator::NewFactory());
  1718. this->Generators.push_back(cmGlobalJOMMakefileGenerator::NewFactory());
  1719. # endif
  1720. this->Generators.push_back(cmGlobalMSYSMakefileGenerator::NewFactory());
  1721. this->Generators.push_back(cmGlobalMinGWMakefileGenerator::NewFactory());
  1722. #endif
  1723. this->Generators.push_back(cmGlobalUnixMakefileGenerator3::NewFactory());
  1724. #if !defined(CMAKE_BOOTSTRAP)
  1725. # if defined(__linux__) || defined(_WIN32)
  1726. this->Generators.push_back(cmGlobalGhsMultiGenerator::NewFactory());
  1727. # endif
  1728. this->Generators.push_back(cmGlobalNinjaGenerator::NewFactory());
  1729. #endif
  1730. #if defined(CMAKE_USE_WMAKE)
  1731. this->Generators.push_back(cmGlobalWatcomWMakeGenerator::NewFactory());
  1732. #endif
  1733. #ifdef CMAKE_USE_XCODE
  1734. this->Generators.push_back(cmGlobalXCodeGenerator::NewFactory());
  1735. #endif
  1736. }
  1737. bool cmake::ParseCacheEntry(const std::string& entry, std::string& var,
  1738. std::string& value,
  1739. cmStateEnums::CacheEntryType& type)
  1740. {
  1741. return cmState::ParseCacheEntry(entry, var, value, type);
  1742. }
  1743. int cmake::LoadCache()
  1744. {
  1745. // could we not read the cache
  1746. if (!this->LoadCache(this->GetHomeOutputDirectory())) {
  1747. // if it does exist, but isn't readable then warn the user
  1748. std::string cacheFile =
  1749. cmStrCat(this->GetHomeOutputDirectory(), "/CMakeCache.txt");
  1750. if (cmSystemTools::FileExists(cacheFile)) {
  1751. cmSystemTools::Error(
  1752. "There is a CMakeCache.txt file for the current binary tree but "
  1753. "cmake does not have permission to read it. Please check the "
  1754. "permissions of the directory you are trying to run CMake on.");
  1755. return -1;
  1756. }
  1757. }
  1758. // setup CMAKE_ROOT and CMAKE_COMMAND
  1759. if (!this->AddCMakePaths()) {
  1760. return -3;
  1761. }
  1762. return 0;
  1763. }
  1764. bool cmake::LoadCache(const std::string& path)
  1765. {
  1766. std::set<std::string> emptySet;
  1767. return this->LoadCache(path, true, emptySet, emptySet);
  1768. }
  1769. bool cmake::LoadCache(const std::string& path, bool internal,
  1770. std::set<std::string>& excludes,
  1771. std::set<std::string>& includes)
  1772. {
  1773. bool result = this->State->LoadCache(path, internal, excludes, includes);
  1774. static const auto entries = { "CMAKE_CACHE_MAJOR_VERSION",
  1775. "CMAKE_CACHE_MINOR_VERSION" };
  1776. for (auto const& entry : entries) {
  1777. this->UnwatchUnusedCli(entry);
  1778. }
  1779. return result;
  1780. }
  1781. bool cmake::SaveCache(const std::string& path)
  1782. {
  1783. bool result = this->State->SaveCache(path, this->GetMessenger());
  1784. static const auto entries = { "CMAKE_CACHE_MAJOR_VERSION",
  1785. "CMAKE_CACHE_MINOR_VERSION",
  1786. "CMAKE_CACHE_PATCH_VERSION",
  1787. "CMAKE_CACHEFILE_DIR" };
  1788. for (auto const& entry : entries) {
  1789. this->UnwatchUnusedCli(entry);
  1790. }
  1791. return result;
  1792. }
  1793. bool cmake::DeleteCache(const std::string& path)
  1794. {
  1795. return this->State->DeleteCache(path);
  1796. }
  1797. void cmake::SetProgressCallback(ProgressCallbackType f)
  1798. {
  1799. this->ProgressCallback = std::move(f);
  1800. }
  1801. void cmake::UpdateProgress(const std::string& msg, float prog)
  1802. {
  1803. if (this->ProgressCallback && !this->State->GetIsInTryCompile()) {
  1804. this->ProgressCallback(msg, prog);
  1805. }
  1806. }
  1807. bool cmake::GetIsInTryCompile() const
  1808. {
  1809. return this->State->GetIsInTryCompile();
  1810. }
  1811. void cmake::SetIsInTryCompile(bool b)
  1812. {
  1813. this->State->SetIsInTryCompile(b);
  1814. }
  1815. void cmake::AppendGlobalGeneratorsDocumentation(
  1816. std::vector<cmDocumentationEntry>& v)
  1817. {
  1818. const auto defaultGenerator = this->EvaluateDefaultGlobalGenerator();
  1819. const std::string defaultName = defaultGenerator->GetName();
  1820. bool foundDefaultOne = false;
  1821. for (cmGlobalGeneratorFactory* g : this->Generators) {
  1822. cmDocumentationEntry e;
  1823. g->GetDocumentation(e);
  1824. if (!foundDefaultOne && cmHasPrefix(e.Name, defaultName)) {
  1825. e.CustomNamePrefix = '*';
  1826. foundDefaultOne = true;
  1827. }
  1828. v.push_back(std::move(e));
  1829. }
  1830. }
  1831. void cmake::AppendExtraGeneratorsDocumentation(
  1832. std::vector<cmDocumentationEntry>& v)
  1833. {
  1834. for (cmExternalMakefileProjectGeneratorFactory* eg : this->ExtraGenerators) {
  1835. const std::string doc = eg->GetDocumentation();
  1836. const std::string name = eg->GetName();
  1837. // Aliases:
  1838. for (std::string const& a : eg->Aliases) {
  1839. cmDocumentationEntry e;
  1840. e.Name = a;
  1841. e.Brief = doc;
  1842. v.push_back(std::move(e));
  1843. }
  1844. // Full names:
  1845. const std::vector<std::string> generators =
  1846. eg->GetSupportedGlobalGenerators();
  1847. for (std::string const& g : generators) {
  1848. cmDocumentationEntry e;
  1849. e.Name =
  1850. cmExternalMakefileProjectGenerator::CreateFullGeneratorName(g, name);
  1851. e.Brief = doc;
  1852. v.push_back(std::move(e));
  1853. }
  1854. }
  1855. }
  1856. std::vector<cmDocumentationEntry> cmake::GetGeneratorsDocumentation()
  1857. {
  1858. std::vector<cmDocumentationEntry> v;
  1859. this->AppendGlobalGeneratorsDocumentation(v);
  1860. this->AppendExtraGeneratorsDocumentation(v);
  1861. return v;
  1862. }
  1863. void cmake::PrintGeneratorList()
  1864. {
  1865. #ifndef CMAKE_BOOTSTRAP
  1866. cmDocumentation doc;
  1867. auto generators = this->GetGeneratorsDocumentation();
  1868. doc.AppendSection("Generators", generators);
  1869. std::cerr << "\n";
  1870. doc.PrintDocumentation(cmDocumentation::ListGenerators, std::cerr);
  1871. #endif
  1872. }
  1873. void cmake::UpdateConversionPathTable()
  1874. {
  1875. // Update the path conversion table with any specified file:
  1876. const std::string* tablepath =
  1877. this->State->GetInitializedCacheValue("CMAKE_PATH_TRANSLATION_FILE");
  1878. if (tablepath) {
  1879. cmsys::ifstream table(tablepath->c_str());
  1880. if (!table) {
  1881. cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to " + *tablepath +
  1882. ". CMake can not open file.");
  1883. cmSystemTools::ReportLastSystemError("CMake can not open file.");
  1884. } else {
  1885. std::string a;
  1886. std::string b;
  1887. while (!table.eof()) {
  1888. // two entries per line
  1889. table >> a;
  1890. table >> b;
  1891. cmSystemTools::AddTranslationPath(a, b);
  1892. }
  1893. }
  1894. }
  1895. }
  1896. int cmake::CheckBuildSystem()
  1897. {
  1898. // We do not need to rerun CMake. Check dependency integrity.
  1899. const bool verbose = isCMakeVerbose();
  1900. // This method will check the integrity of the build system if the
  1901. // option was given on the command line. It reads the given file to
  1902. // determine whether CMake should rerun.
  1903. // If no file is provided for the check, we have to rerun.
  1904. if (this->CheckBuildSystemArgument.empty()) {
  1905. if (verbose) {
  1906. cmSystemTools::Stdout("Re-run cmake no build system arguments\n");
  1907. }
  1908. return 1;
  1909. }
  1910. // If the file provided does not exist, we have to rerun.
  1911. if (!cmSystemTools::FileExists(this->CheckBuildSystemArgument)) {
  1912. if (verbose) {
  1913. std::ostringstream msg;
  1914. msg << "Re-run cmake missing file: " << this->CheckBuildSystemArgument
  1915. << "\n";
  1916. cmSystemTools::Stdout(msg.str());
  1917. }
  1918. return 1;
  1919. }
  1920. // Read the rerun check file and use it to decide whether to do the
  1921. // global generate.
  1922. // Actually, all we need is the `set` command.
  1923. cmake cm(RoleScript, cmState::Unknown);
  1924. cm.SetHomeDirectory("");
  1925. cm.SetHomeOutputDirectory("");
  1926. cm.GetCurrentSnapshot().SetDefaultDefinitions();
  1927. cmGlobalGenerator gg(&cm);
  1928. cmMakefile mf(&gg, cm.GetCurrentSnapshot());
  1929. if (!mf.ReadListFile(this->CheckBuildSystemArgument) ||
  1930. cmSystemTools::GetErrorOccuredFlag()) {
  1931. if (verbose) {
  1932. std::ostringstream msg;
  1933. msg << "Re-run cmake error reading : " << this->CheckBuildSystemArgument
  1934. << "\n";
  1935. cmSystemTools::Stdout(msg.str());
  1936. }
  1937. // There was an error reading the file. Just rerun.
  1938. return 1;
  1939. }
  1940. if (this->ClearBuildSystem) {
  1941. // Get the generator used for this build system.
  1942. const char* genName = mf.GetDefinition("CMAKE_DEPENDS_GENERATOR");
  1943. if (!genName || genName[0] == '\0') {
  1944. genName = "Unix Makefiles";
  1945. }
  1946. // Create the generator and use it to clear the dependencies.
  1947. std::unique_ptr<cmGlobalGenerator> ggd(
  1948. this->CreateGlobalGenerator(genName));
  1949. if (ggd) {
  1950. cm.GetCurrentSnapshot().SetDefaultDefinitions();
  1951. cmMakefile mfd(ggd.get(), cm.GetCurrentSnapshot());
  1952. std::unique_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator(&mfd));
  1953. lgd->ClearDependencies(&mfd, verbose);
  1954. }
  1955. }
  1956. // If any byproduct of makefile generation is missing we must re-run.
  1957. std::vector<std::string> products;
  1958. if (const char* productStr = mf.GetDefinition("CMAKE_MAKEFILE_PRODUCTS")) {
  1959. cmExpandList(productStr, products);
  1960. }
  1961. for (std::string const& p : products) {
  1962. if (!(cmSystemTools::FileExists(p) || cmSystemTools::FileIsSymlink(p))) {
  1963. if (verbose) {
  1964. std::ostringstream msg;
  1965. msg << "Re-run cmake, missing byproduct: " << p << "\n";
  1966. cmSystemTools::Stdout(msg.str());
  1967. }
  1968. return 1;
  1969. }
  1970. }
  1971. // Get the set of dependencies and outputs.
  1972. std::vector<std::string> depends;
  1973. std::vector<std::string> outputs;
  1974. const char* dependsStr = mf.GetDefinition("CMAKE_MAKEFILE_DEPENDS");
  1975. const char* outputsStr = mf.GetDefinition("CMAKE_MAKEFILE_OUTPUTS");
  1976. if (dependsStr && outputsStr) {
  1977. cmExpandList(dependsStr, depends);
  1978. cmExpandList(outputsStr, outputs);
  1979. }
  1980. if (depends.empty() || outputs.empty()) {
  1981. // Not enough information was provided to do the test. Just rerun.
  1982. if (verbose) {
  1983. cmSystemTools::Stdout("Re-run cmake no CMAKE_MAKEFILE_DEPENDS "
  1984. "or CMAKE_MAKEFILE_OUTPUTS :\n");
  1985. }
  1986. return 1;
  1987. }
  1988. // Find the newest dependency.
  1989. std::vector<std::string>::iterator dep = depends.begin();
  1990. std::string dep_newest = *dep++;
  1991. for (; dep != depends.end(); ++dep) {
  1992. int result = 0;
  1993. if (this->FileTimeCache->Compare(dep_newest, *dep, &result)) {
  1994. if (result < 0) {
  1995. dep_newest = *dep;
  1996. }
  1997. } else {
  1998. if (verbose) {
  1999. cmSystemTools::Stdout(
  2000. "Re-run cmake: build system dependency is missing\n");
  2001. }
  2002. return 1;
  2003. }
  2004. }
  2005. // Find the oldest output.
  2006. std::vector<std::string>::iterator out = outputs.begin();
  2007. std::string out_oldest = *out++;
  2008. for (; out != outputs.end(); ++out) {
  2009. int result = 0;
  2010. if (this->FileTimeCache->Compare(out_oldest, *out, &result)) {
  2011. if (result > 0) {
  2012. out_oldest = *out;
  2013. }
  2014. } else {
  2015. if (verbose) {
  2016. cmSystemTools::Stdout(
  2017. "Re-run cmake: build system output is missing\n");
  2018. }
  2019. return 1;
  2020. }
  2021. }
  2022. // If any output is older than any dependency then rerun.
  2023. {
  2024. int result = 0;
  2025. if (!this->FileTimeCache->Compare(out_oldest, dep_newest, &result) ||
  2026. result < 0) {
  2027. if (verbose) {
  2028. std::ostringstream msg;
  2029. msg << "Re-run cmake file: " << out_oldest
  2030. << " older than: " << dep_newest << "\n";
  2031. cmSystemTools::Stdout(msg.str());
  2032. }
  2033. return 1;
  2034. }
  2035. }
  2036. // No need to rerun.
  2037. return 0;
  2038. }
  2039. void cmake::TruncateOutputLog(const char* fname)
  2040. {
  2041. std::string fullPath = cmStrCat(this->GetHomeOutputDirectory(), '/', fname);
  2042. struct stat st;
  2043. if (::stat(fullPath.c_str(), &st)) {
  2044. return;
  2045. }
  2046. if (!this->State->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR")) {
  2047. cmSystemTools::RemoveFile(fullPath);
  2048. return;
  2049. }
  2050. off_t fsize = st.st_size;
  2051. const off_t maxFileSize = 50 * 1024;
  2052. if (fsize < maxFileSize) {
  2053. // TODO: truncate file
  2054. return;
  2055. }
  2056. }
  2057. void cmake::MarkCliAsUsed(const std::string& variable)
  2058. {
  2059. this->UsedCliVariables[variable] = true;
  2060. }
  2061. void cmake::GenerateGraphViz(const std::string& fileName) const
  2062. {
  2063. #ifndef CMAKE_BOOTSTRAP
  2064. cmGraphVizWriter gvWriter(this->GetGlobalGenerator());
  2065. std::string settingsFile =
  2066. cmStrCat(this->GetHomeOutputDirectory(), "/CMakeGraphVizOptions.cmake");
  2067. std::string fallbackSettingsFile =
  2068. cmStrCat(this->GetHomeDirectory(), "/CMakeGraphVizOptions.cmake");
  2069. gvWriter.ReadSettings(settingsFile, fallbackSettingsFile);
  2070. gvWriter.WritePerTargetFiles(fileName);
  2071. gvWriter.WriteTargetDependersFiles(fileName);
  2072. gvWriter.WriteGlobalFile(fileName);
  2073. #endif
  2074. }
  2075. void cmake::SetProperty(const std::string& prop, const char* value)
  2076. {
  2077. this->State->SetGlobalProperty(prop, value);
  2078. }
  2079. void cmake::AppendProperty(const std::string& prop, const char* value,
  2080. bool asString)
  2081. {
  2082. this->State->AppendGlobalProperty(prop, value, asString);
  2083. }
  2084. const char* cmake::GetProperty(const std::string& prop)
  2085. {
  2086. return this->State->GetGlobalProperty(prop);
  2087. }
  2088. bool cmake::GetPropertyAsBool(const std::string& prop)
  2089. {
  2090. return this->State->GetGlobalPropertyAsBool(prop);
  2091. }
  2092. cmInstalledFile* cmake::GetOrCreateInstalledFile(cmMakefile* mf,
  2093. const std::string& name)
  2094. {
  2095. std::map<std::string, cmInstalledFile>::iterator i =
  2096. this->InstalledFiles.find(name);
  2097. if (i != this->InstalledFiles.end()) {
  2098. cmInstalledFile& file = i->second;
  2099. return &file;
  2100. }
  2101. cmInstalledFile& file = this->InstalledFiles[name];
  2102. file.SetName(mf, name);
  2103. return &file;
  2104. }
  2105. cmInstalledFile const* cmake::GetInstalledFile(const std::string& name) const
  2106. {
  2107. std::map<std::string, cmInstalledFile>::const_iterator i =
  2108. this->InstalledFiles.find(name);
  2109. if (i != this->InstalledFiles.end()) {
  2110. cmInstalledFile const& file = i->second;
  2111. return &file;
  2112. }
  2113. return nullptr;
  2114. }
  2115. int cmake::GetSystemInformation(std::vector<std::string>& args)
  2116. {
  2117. // so create the directory
  2118. std::string resultFile;
  2119. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  2120. std::string destPath = cwd + "/__cmake_systeminformation";
  2121. cmSystemTools::RemoveADirectory(destPath);
  2122. if (!cmSystemTools::MakeDirectory(destPath)) {
  2123. std::cerr << "Error: --system-information must be run from a "
  2124. "writable directory!\n";
  2125. return 1;
  2126. }
  2127. // process the arguments
  2128. bool writeToStdout = true;
  2129. for (unsigned int i = 1; i < args.size(); ++i) {
  2130. std::string const& arg = args[i];
  2131. if (arg.find("-G", 0) == 0) {
  2132. std::string value = arg.substr(2);
  2133. if (value.empty()) {
  2134. ++i;
  2135. if (i >= args.size()) {
  2136. cmSystemTools::Error("No generator specified for -G");
  2137. this->PrintGeneratorList();
  2138. return -1;
  2139. }
  2140. value = args[i];
  2141. }
  2142. cmGlobalGenerator* gen = this->CreateGlobalGenerator(value);
  2143. if (!gen) {
  2144. cmSystemTools::Error("Could not create named generator " + value);
  2145. this->PrintGeneratorList();
  2146. } else {
  2147. this->SetGlobalGenerator(gen);
  2148. }
  2149. }
  2150. // no option assume it is the output file
  2151. else {
  2152. if (!cmSystemTools::FileIsFullPath(arg)) {
  2153. resultFile = cmStrCat(cwd, '/');
  2154. }
  2155. resultFile += arg;
  2156. writeToStdout = false;
  2157. }
  2158. }
  2159. // we have to find the module directory, so we can copy the files
  2160. this->AddCMakePaths();
  2161. std::string modulesPath =
  2162. cmStrCat(cmSystemTools::GetCMakeRoot(), "/Modules");
  2163. std::string inFile = cmStrCat(modulesPath, "/SystemInformation.cmake");
  2164. std::string outFile = cmStrCat(destPath, "/CMakeLists.txt");
  2165. // Copy file
  2166. if (!cmsys::SystemTools::CopyFileAlways(inFile, outFile)) {
  2167. std::cerr << "Error copying file \"" << inFile << "\" to \"" << outFile
  2168. << "\".\n";
  2169. return 1;
  2170. }
  2171. // do we write to a file or to stdout?
  2172. if (resultFile.empty()) {
  2173. resultFile = cmStrCat(cwd, "/__cmake_systeminformation/results.txt");
  2174. }
  2175. {
  2176. // now run cmake on the CMakeLists file
  2177. cmWorkingDirectory workdir(destPath);
  2178. if (workdir.Failed()) {
  2179. // We created the directory and we were able to copy the CMakeLists.txt
  2180. // file to it, so we wouldn't expect to get here unless the default
  2181. // permissions are questionable or some other process has deleted the
  2182. // directory
  2183. std::cerr << "Failed to change to directory " << destPath << " : "
  2184. << std::strerror(workdir.GetLastResult()) << std::endl;
  2185. return 1;
  2186. }
  2187. std::vector<std::string> args2;
  2188. args2.push_back(args[0]);
  2189. args2.push_back(destPath);
  2190. args2.push_back("-DRESULT_FILE=" + resultFile);
  2191. int res = this->Run(args2, false);
  2192. if (res != 0) {
  2193. std::cerr << "Error: --system-information failed on internal CMake!\n";
  2194. return res;
  2195. }
  2196. }
  2197. // echo results to stdout if needed
  2198. if (writeToStdout) {
  2199. FILE* fin = cmsys::SystemTools::Fopen(resultFile, "r");
  2200. if (fin) {
  2201. const int bufferSize = 4096;
  2202. char buffer[bufferSize];
  2203. size_t n;
  2204. while ((n = fread(buffer, 1, bufferSize, fin)) > 0) {
  2205. for (char* c = buffer; c < buffer + n; ++c) {
  2206. putc(*c, stdout);
  2207. }
  2208. fflush(stdout);
  2209. }
  2210. fclose(fin);
  2211. }
  2212. }
  2213. // clean up the directory
  2214. cmSystemTools::RemoveADirectory(destPath);
  2215. return 0;
  2216. }
  2217. static bool cmakeCheckStampFile(const std::string& stampName)
  2218. {
  2219. // The stamp file does not exist. Use the stamp dependencies to
  2220. // determine whether it is really out of date. This works in
  2221. // conjunction with cmLocalVisualStudio7Generator to avoid
  2222. // repeatedly re-running CMake when the user rebuilds the entire
  2223. // solution.
  2224. std::string stampDepends = cmStrCat(stampName, ".depend");
  2225. #if defined(_WIN32) || defined(__CYGWIN__)
  2226. cmsys::ifstream fin(stampDepends.c_str(), std::ios::in | std::ios::binary);
  2227. #else
  2228. cmsys::ifstream fin(stampDepends.c_str());
  2229. #endif
  2230. if (!fin) {
  2231. // The stamp dependencies file cannot be read. Just assume the
  2232. // build system is really out of date.
  2233. std::cout << "CMake is re-running because " << stampName
  2234. << " dependency file is missing.\n";
  2235. return false;
  2236. }
  2237. // Compare the stamp dependencies against the dependency file itself.
  2238. {
  2239. cmFileTimeCache ftc;
  2240. std::string dep;
  2241. while (cmSystemTools::GetLineFromStream(fin, dep)) {
  2242. int result;
  2243. if (!dep.empty() && dep[0] != '#' &&
  2244. (!ftc.Compare(stampDepends, dep, &result) || result < 0)) {
  2245. // The stamp depends file is older than this dependency. The
  2246. // build system is really out of date.
  2247. std::cout << "CMake is re-running because " << stampName
  2248. << " is out-of-date.\n";
  2249. std::cout << " the file '" << dep << "'\n";
  2250. std::cout << " is newer than '" << stampDepends << "'\n";
  2251. std::cout << " result='" << result << "'\n";
  2252. return false;
  2253. }
  2254. }
  2255. }
  2256. // The build system is up to date. The stamp file has been removed
  2257. // by the VS IDE due to a "rebuild" request. Restore it atomically.
  2258. std::ostringstream stampTempStream;
  2259. stampTempStream << stampName << ".tmp" << cmSystemTools::RandomSeed();
  2260. std::string stampTemp = stampTempStream.str();
  2261. {
  2262. // TODO: Teach cmGeneratedFileStream to use a random temp file (with
  2263. // multiple tries in unlikely case of conflict) and use that here.
  2264. cmsys::ofstream stamp(stampTemp.c_str());
  2265. stamp << "# CMake generation timestamp file for this directory.\n";
  2266. }
  2267. if (cmSystemTools::RenameFile(stampTemp, stampName)) {
  2268. // CMake does not need to re-run because the stamp file is up-to-date.
  2269. return true;
  2270. }
  2271. cmSystemTools::RemoveFile(stampTemp);
  2272. cmSystemTools::Error("Cannot restore timestamp " + stampName);
  2273. return false;
  2274. }
  2275. static bool cmakeCheckStampList(const std::string& stampList)
  2276. {
  2277. // If the stamp list does not exist CMake must rerun to generate it.
  2278. if (!cmSystemTools::FileExists(stampList)) {
  2279. std::cout << "CMake is re-running because generate.stamp.list "
  2280. << "is missing.\n";
  2281. return false;
  2282. }
  2283. cmsys::ifstream fin(stampList.c_str());
  2284. if (!fin) {
  2285. std::cout << "CMake is re-running because generate.stamp.list "
  2286. << "could not be read.\n";
  2287. return false;
  2288. }
  2289. // Check each stamp.
  2290. std::string stampName;
  2291. while (cmSystemTools::GetLineFromStream(fin, stampName)) {
  2292. if (!cmakeCheckStampFile(stampName)) {
  2293. return false;
  2294. }
  2295. }
  2296. return true;
  2297. }
  2298. void cmake::IssueMessage(MessageType t, std::string const& text,
  2299. cmListFileBacktrace const& backtrace) const
  2300. {
  2301. this->Messenger->IssueMessage(t, text, backtrace);
  2302. }
  2303. std::vector<std::string> cmake::GetDebugConfigs()
  2304. {
  2305. std::vector<std::string> configs;
  2306. if (const char* config_list =
  2307. this->State->GetGlobalProperty("DEBUG_CONFIGURATIONS")) {
  2308. // Expand the specified list and convert to upper-case.
  2309. cmExpandList(config_list, configs);
  2310. std::transform(configs.begin(), configs.end(), configs.begin(),
  2311. cmSystemTools::UpperCase);
  2312. }
  2313. // If no configurations were specified, use a default list.
  2314. if (configs.empty()) {
  2315. configs.emplace_back("DEBUG");
  2316. }
  2317. return configs;
  2318. }
  2319. int cmake::Build(int jobs, const std::string& dir,
  2320. const std::vector<std::string>& targets,
  2321. const std::string& config,
  2322. const std::vector<std::string>& nativeOptions, bool clean,
  2323. bool verbose)
  2324. {
  2325. this->SetHomeDirectory("");
  2326. this->SetHomeOutputDirectory("");
  2327. if (!cmSystemTools::FileIsDirectory(dir)) {
  2328. std::cerr << "Error: " << dir << " is not a directory\n";
  2329. return 1;
  2330. }
  2331. std::string cachePath = FindCacheFile(dir);
  2332. if (!this->LoadCache(cachePath)) {
  2333. std::cerr << "Error: could not load cache\n";
  2334. return 1;
  2335. }
  2336. const char* cachedGenerator =
  2337. this->State->GetCacheEntryValue("CMAKE_GENERATOR");
  2338. if (!cachedGenerator) {
  2339. std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n";
  2340. return 1;
  2341. }
  2342. cmGlobalGenerator* gen = this->CreateGlobalGenerator(cachedGenerator);
  2343. if (!gen) {
  2344. std::cerr << "Error: could create CMAKE_GENERATOR \"" << cachedGenerator
  2345. << "\"\n";
  2346. return 1;
  2347. }
  2348. this->SetGlobalGenerator(gen);
  2349. const char* cachedGeneratorInstance =
  2350. this->State->GetCacheEntryValue("CMAKE_GENERATOR_INSTANCE");
  2351. if (cachedGeneratorInstance) {
  2352. cmMakefile mf(gen, this->GetCurrentSnapshot());
  2353. if (!gen->SetGeneratorInstance(cachedGeneratorInstance, &mf)) {
  2354. return 1;
  2355. }
  2356. }
  2357. const char* cachedGeneratorPlatform =
  2358. this->State->GetCacheEntryValue("CMAKE_GENERATOR_PLATFORM");
  2359. if (cachedGeneratorPlatform) {
  2360. cmMakefile mf(gen, this->GetCurrentSnapshot());
  2361. if (!gen->SetGeneratorPlatform(cachedGeneratorPlatform, &mf)) {
  2362. return 1;
  2363. }
  2364. }
  2365. std::string output;
  2366. std::string projName;
  2367. const char* cachedProjectName =
  2368. this->State->GetCacheEntryValue("CMAKE_PROJECT_NAME");
  2369. if (!cachedProjectName) {
  2370. std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n";
  2371. return 1;
  2372. }
  2373. projName = cachedProjectName;
  2374. const char* cachedVerbose =
  2375. this->State->GetCacheEntryValue("CMAKE_VERBOSE_MAKEFILE");
  2376. if (cmIsOn(cachedVerbose)) {
  2377. verbose = true;
  2378. }
  2379. #ifdef CMAKE_HAVE_VS_GENERATORS
  2380. // For VS generators, explicitly check if regeneration is necessary before
  2381. // actually starting the build. If not done separately from the build
  2382. // itself, there is the risk of building an out-of-date solution file due
  2383. // to limitations of the underlying build system.
  2384. std::string const stampList = cachePath + "/" + "CMakeFiles/" +
  2385. cmGlobalVisualStudio9Generator::GetGenerateStampList();
  2386. // Note that the stampList file only exists for VS generators.
  2387. if (cmSystemTools::FileExists(stampList)) {
  2388. // Check if running for Visual Studio 9 - we need to explicitly run
  2389. // the glob verification script before starting the build
  2390. this->AddScriptingCommands();
  2391. if (this->GlobalGenerator->MatchesGeneratorName("Visual Studio 9 2008")) {
  2392. std::string const globVerifyScript =
  2393. cachePath + "/" + "CMakeFiles/" + "VerifyGlobs.cmake";
  2394. if (cmSystemTools::FileExists(globVerifyScript)) {
  2395. std::vector<std::string> args;
  2396. this->ReadListFile(args, globVerifyScript);
  2397. }
  2398. }
  2399. if (!cmakeCheckStampList(stampList)) {
  2400. // Correctly initialize the home (=source) and home output (=binary)
  2401. // directories, which is required for running the generation step.
  2402. std::string homeOrig = this->GetHomeDirectory();
  2403. std::string homeOutputOrig = this->GetHomeOutputDirectory();
  2404. this->SetDirectoriesFromFile(cachePath);
  2405. this->AddProjectCommands();
  2406. int ret = this->Configure();
  2407. if (ret) {
  2408. cmSystemTools::Message("CMake Configure step failed. "
  2409. "Build files cannot be regenerated correctly.");
  2410. return ret;
  2411. }
  2412. ret = this->Generate();
  2413. if (ret) {
  2414. cmSystemTools::Message("CMake Generate step failed. "
  2415. "Build files cannot be regenerated correctly.");
  2416. return ret;
  2417. }
  2418. std::string message = cmStrCat("Build files have been written to: ",
  2419. this->GetHomeOutputDirectory());
  2420. this->UpdateProgress(message, -1);
  2421. // Restore the previously set directories to their original value.
  2422. this->SetHomeDirectory(homeOrig);
  2423. this->SetHomeOutputDirectory(homeOutputOrig);
  2424. }
  2425. }
  2426. #endif
  2427. gen->PrintBuildCommandAdvice(std::cerr, jobs);
  2428. return gen->Build(jobs, "", dir, projName, targets, output, "", config,
  2429. clean, false, verbose, cmDuration::zero(),
  2430. cmSystemTools::OUTPUT_PASSTHROUGH, nativeOptions);
  2431. }
  2432. bool cmake::Open(const std::string& dir, bool dryRun)
  2433. {
  2434. this->SetHomeDirectory("");
  2435. this->SetHomeOutputDirectory("");
  2436. if (!cmSystemTools::FileIsDirectory(dir)) {
  2437. std::cerr << "Error: " << dir << " is not a directory\n";
  2438. return false;
  2439. }
  2440. std::string cachePath = FindCacheFile(dir);
  2441. if (!this->LoadCache(cachePath)) {
  2442. std::cerr << "Error: could not load cache\n";
  2443. return false;
  2444. }
  2445. const char* genName = this->State->GetCacheEntryValue("CMAKE_GENERATOR");
  2446. if (!genName) {
  2447. std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n";
  2448. return false;
  2449. }
  2450. const std::string* extraGenName =
  2451. this->State->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
  2452. std::string fullName =
  2453. cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
  2454. genName, extraGenName ? *extraGenName : "");
  2455. std::unique_ptr<cmGlobalGenerator> gen(
  2456. this->CreateGlobalGenerator(fullName));
  2457. if (!gen) {
  2458. std::cerr << "Error: could create CMAKE_GENERATOR \"" << fullName
  2459. << "\"\n";
  2460. return false;
  2461. }
  2462. const char* cachedProjectName =
  2463. this->State->GetCacheEntryValue("CMAKE_PROJECT_NAME");
  2464. if (!cachedProjectName) {
  2465. std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n";
  2466. return false;
  2467. }
  2468. return gen->Open(dir, cachedProjectName, dryRun);
  2469. }
  2470. void cmake::WatchUnusedCli(const std::string& var)
  2471. {
  2472. #ifndef CMAKE_BOOTSTRAP
  2473. this->VariableWatch->AddWatch(var, cmWarnUnusedCliWarning, this);
  2474. if (!cmContains(this->UsedCliVariables, var)) {
  2475. this->UsedCliVariables[var] = false;
  2476. }
  2477. #endif
  2478. }
  2479. void cmake::UnwatchUnusedCli(const std::string& var)
  2480. {
  2481. #ifndef CMAKE_BOOTSTRAP
  2482. this->VariableWatch->RemoveWatch(var, cmWarnUnusedCliWarning);
  2483. this->UsedCliVariables.erase(var);
  2484. #endif
  2485. }
  2486. void cmake::RunCheckForUnusedVariables()
  2487. {
  2488. #ifndef CMAKE_BOOTSTRAP
  2489. bool haveUnused = false;
  2490. std::ostringstream msg;
  2491. msg << "Manually-specified variables were not used by the project:";
  2492. for (auto const& it : this->UsedCliVariables) {
  2493. if (!it.second) {
  2494. haveUnused = true;
  2495. msg << "\n " << it.first;
  2496. }
  2497. }
  2498. if (haveUnused) {
  2499. this->IssueMessage(MessageType::WARNING, msg.str());
  2500. }
  2501. #endif
  2502. }
  2503. bool cmake::GetSuppressDevWarnings() const
  2504. {
  2505. return this->Messenger->GetSuppressDevWarnings();
  2506. }
  2507. void cmake::SetSuppressDevWarnings(bool b)
  2508. {
  2509. std::string value;
  2510. // equivalent to -Wno-dev
  2511. if (b) {
  2512. value = "TRUE";
  2513. }
  2514. // equivalent to -Wdev
  2515. else {
  2516. value = "FALSE";
  2517. }
  2518. this->AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", value.c_str(),
  2519. "Suppress Warnings that are meant for"
  2520. " the author of the CMakeLists.txt files.",
  2521. cmStateEnums::INTERNAL);
  2522. }
  2523. bool cmake::GetSuppressDeprecatedWarnings() const
  2524. {
  2525. return this->Messenger->GetSuppressDeprecatedWarnings();
  2526. }
  2527. void cmake::SetSuppressDeprecatedWarnings(bool b)
  2528. {
  2529. std::string value;
  2530. // equivalent to -Wno-deprecated
  2531. if (b) {
  2532. value = "FALSE";
  2533. }
  2534. // equivalent to -Wdeprecated
  2535. else {
  2536. value = "TRUE";
  2537. }
  2538. this->AddCacheEntry("CMAKE_WARN_DEPRECATED", value.c_str(),
  2539. "Whether to issue warnings for deprecated "
  2540. "functionality.",
  2541. cmStateEnums::INTERNAL);
  2542. }
  2543. bool cmake::GetDevWarningsAsErrors() const
  2544. {
  2545. return this->Messenger->GetDevWarningsAsErrors();
  2546. }
  2547. void cmake::SetDevWarningsAsErrors(bool b)
  2548. {
  2549. std::string value;
  2550. // equivalent to -Werror=dev
  2551. if (b) {
  2552. value = "FALSE";
  2553. }
  2554. // equivalent to -Wno-error=dev
  2555. else {
  2556. value = "TRUE";
  2557. }
  2558. this->AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_ERRORS", value.c_str(),
  2559. "Suppress errors that are meant for"
  2560. " the author of the CMakeLists.txt files.",
  2561. cmStateEnums::INTERNAL);
  2562. }
  2563. bool cmake::GetDeprecatedWarningsAsErrors() const
  2564. {
  2565. return this->Messenger->GetDeprecatedWarningsAsErrors();
  2566. }
  2567. void cmake::SetDeprecatedWarningsAsErrors(bool b)
  2568. {
  2569. std::string value;
  2570. // equivalent to -Werror=deprecated
  2571. if (b) {
  2572. value = "TRUE";
  2573. }
  2574. // equivalent to -Wno-error=deprecated
  2575. else {
  2576. value = "FALSE";
  2577. }
  2578. this->AddCacheEntry("CMAKE_ERROR_DEPRECATED", value.c_str(),
  2579. "Whether to issue deprecation errors for macros"
  2580. " and functions.",
  2581. cmStateEnums::INTERNAL);
  2582. }