cmake.cxx 91 KB

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