cmake.cxx 91 KB

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