cmake.cxx 91 KB

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