cmake.cxx 92 KB

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