cmake.cxx 90 KB

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