cmake.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <cstddef>
  6. #include <functional>
  7. #include <map>
  8. #include <memory>
  9. #include <set>
  10. #include <stack>
  11. #include <string>
  12. #include <unordered_set>
  13. #include <utility>
  14. #include <vector>
  15. #include <cm/string_view>
  16. #include "cmGeneratedFileStream.h"
  17. #include "cmInstalledFile.h"
  18. #include "cmListFileCache.h"
  19. #include "cmMessageType.h"
  20. #include "cmProperty.h"
  21. #include "cmState.h"
  22. #include "cmStateSnapshot.h"
  23. #include "cmStateTypes.h"
  24. #if !defined(CMAKE_BOOTSTRAP)
  25. # include <cm/optional>
  26. # include <cm3p/json/value.h>
  27. # include "cmCMakePresetsFile.h"
  28. #endif
  29. class cmExternalMakefileProjectGeneratorFactory;
  30. class cmFileAPI;
  31. class cmFileTimeCache;
  32. class cmGlobalGenerator;
  33. class cmGlobalGeneratorFactory;
  34. class cmMakefile;
  35. #if !defined(CMAKE_BOOTSTRAP)
  36. class cmMakefileProfilingData;
  37. #endif
  38. class cmMessenger;
  39. class cmVariableWatch;
  40. struct cmDocumentationEntry;
  41. /** \brief Represents a cmake invocation.
  42. *
  43. * This class represents a cmake invocation. It is the top level class when
  44. * running cmake. Most cmake based GUIs should primarily create an instance
  45. * of this class and communicate with it.
  46. *
  47. * The basic process for a GUI is as follows:
  48. *
  49. * -# Create a cmake instance
  50. * -# Set the Home directories, generator, and cmake command. this
  51. * can be done using the Set methods or by using SetArgs and passing in
  52. * command line arguments.
  53. * -# Load the cache by calling LoadCache (duh)
  54. * -# if you are using command line arguments with -D or -C flags then
  55. * call SetCacheArgs (or if for some other reason you want to modify the
  56. * cache), do it now.
  57. * -# Finally call Configure
  58. * -# Let the user change values and go back to step 5
  59. * -# call Generate
  60. * If your GUI allows the user to change the home directories then
  61. * you must at a minimum redo steps 2 through 7.
  62. */
  63. class cmake
  64. {
  65. public:
  66. enum Role
  67. {
  68. RoleInternal, // no commands
  69. RoleScript, // script commands
  70. RoleProject // all commands
  71. };
  72. enum DiagLevel
  73. {
  74. DIAG_IGNORE,
  75. DIAG_WARN,
  76. DIAG_ERROR
  77. };
  78. /** \brief Describes the working modes of cmake */
  79. enum WorkingMode
  80. {
  81. NORMAL_MODE, ///< Cmake runs to create project files
  82. /** \brief Script mode (started by using -P).
  83. *
  84. * In script mode there is no generator and no cache. Also,
  85. * languages are not enabled, so add_executable and things do
  86. * nothing.
  87. */
  88. SCRIPT_MODE,
  89. /** \brief Help mode
  90. *
  91. * Used to print help for things that can only be determined after finding
  92. * the source directory, for example, the list of presets.
  93. */
  94. HELP_MODE,
  95. /** \brief A pkg-config like mode
  96. *
  97. * In this mode cmake just searches for a package and prints the results to
  98. * stdout. This is similar to SCRIPT_MODE, but commands like add_library()
  99. * work too, since they may be used e.g. in exported target files. Started
  100. * via --find-package.
  101. */
  102. FIND_PACKAGE_MODE
  103. };
  104. /** \brief Define log level constants. */
  105. enum LogLevel
  106. {
  107. LOG_UNDEFINED,
  108. LOG_ERROR,
  109. LOG_WARNING,
  110. LOG_NOTICE,
  111. LOG_STATUS,
  112. LOG_VERBOSE,
  113. LOG_DEBUG,
  114. LOG_TRACE
  115. };
  116. /** \brief Define supported trace formats **/
  117. enum TraceFormat
  118. {
  119. TRACE_UNDEFINED,
  120. TRACE_HUMAN,
  121. TRACE_JSON_V1,
  122. };
  123. struct GeneratorInfo
  124. {
  125. std::string name;
  126. std::string baseName;
  127. std::string extraName;
  128. bool supportsToolset;
  129. bool supportsPlatform;
  130. std::vector<std::string> supportedPlatforms;
  131. std::string defaultPlatform;
  132. bool isAlias;
  133. };
  134. struct FileExtensions
  135. {
  136. bool Test(cm::string_view ext) const
  137. {
  138. return (this->unordered.find(ext) != this->unordered.end());
  139. }
  140. std::vector<std::string> ordered;
  141. std::unordered_set<cm::string_view> unordered;
  142. };
  143. using InstalledFilesMap = std::map<std::string, cmInstalledFile>;
  144. static const int NO_BUILD_PARALLEL_LEVEL = -1;
  145. static const int DEFAULT_BUILD_PARALLEL_LEVEL = 0;
  146. /// Default constructor
  147. cmake(Role role, cmState::Mode mode);
  148. /// Destructor
  149. ~cmake();
  150. cmake(cmake const&) = delete;
  151. cmake& operator=(cmake const&) = delete;
  152. #if !defined(CMAKE_BOOTSTRAP)
  153. Json::Value ReportVersionJson() const;
  154. Json::Value ReportCapabilitiesJson() const;
  155. #endif
  156. std::string ReportCapabilities() const;
  157. //@{
  158. /**
  159. * Set/Get the home directory (or output directory) in the project. The
  160. * home directory is the top directory of the project. It is the
  161. * path-to-source cmake was run with.
  162. */
  163. void SetHomeDirectory(const std::string& dir);
  164. std::string const& GetHomeDirectory() const;
  165. void SetHomeOutputDirectory(const std::string& dir);
  166. std::string const& GetHomeOutputDirectory() const;
  167. //@}
  168. /**
  169. * Handle a command line invocation of cmake.
  170. */
  171. int Run(const std::vector<std::string>& args)
  172. {
  173. return this->Run(args, false);
  174. }
  175. int Run(const std::vector<std::string>& args, bool noconfigure);
  176. /**
  177. * Run the global generator Generate step.
  178. */
  179. int Generate();
  180. /**
  181. * Configure the cmMakefiles. This routine will create a GlobalGenerator if
  182. * one has not already been set. It will then Call Configure on the
  183. * GlobalGenerator. This in turn will read in an process all the CMakeList
  184. * files for the tree. It will not produce any actual Makefiles, or
  185. * workspaces. Generate does that. */
  186. int Configure();
  187. int ActualConfigure();
  188. //! Break up a line like VAR:type="value" into var, type and value
  189. static bool ParseCacheEntry(const std::string& entry, std::string& var,
  190. std::string& value,
  191. cmStateEnums::CacheEntryType& type);
  192. int LoadCache();
  193. bool LoadCache(const std::string& path);
  194. bool LoadCache(const std::string& path, bool internal,
  195. std::set<std::string>& excludes,
  196. std::set<std::string>& includes);
  197. bool SaveCache(const std::string& path);
  198. bool DeleteCache(const std::string& path);
  199. void PreLoadCMakeFiles();
  200. //! Create a GlobalGenerator
  201. std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator(
  202. const std::string& name, bool allowArch = true);
  203. //! Create a GlobalGenerator and set it as our own
  204. bool CreateAndSetGlobalGenerator(const std::string& name, bool allowArch);
  205. #ifndef CMAKE_BOOTSTRAP
  206. //! Print list of presets
  207. void PrintPresetList(const cmCMakePresetsFile& file) const;
  208. #endif
  209. //! Return the global generator assigned to this instance of cmake
  210. cmGlobalGenerator* GetGlobalGenerator()
  211. {
  212. return this->GlobalGenerator.get();
  213. }
  214. //! Return the global generator assigned to this instance of cmake, const
  215. const cmGlobalGenerator* GetGlobalGenerator() const
  216. {
  217. return this->GlobalGenerator.get();
  218. }
  219. //! Return the full path to where the CMakeCache.txt file should be.
  220. static std::string FindCacheFile(const std::string& binaryDir);
  221. //! Return the global generator assigned to this instance of cmake
  222. void SetGlobalGenerator(std::unique_ptr<cmGlobalGenerator>);
  223. //! Get the names of the current registered generators
  224. void GetRegisteredGenerators(std::vector<GeneratorInfo>& generators,
  225. bool includeNamesWithPlatform = true) const;
  226. //! Set the name of the selected generator-specific instance.
  227. void SetGeneratorInstance(std::string const& instance)
  228. {
  229. this->GeneratorInstance = instance;
  230. this->GeneratorInstanceSet = true;
  231. }
  232. //! Set the name of the selected generator-specific platform.
  233. void SetGeneratorPlatform(std::string const& ts)
  234. {
  235. this->GeneratorPlatform = ts;
  236. this->GeneratorPlatformSet = true;
  237. }
  238. //! Set the name of the selected generator-specific toolset.
  239. void SetGeneratorToolset(std::string const& ts)
  240. {
  241. this->GeneratorToolset = ts;
  242. this->GeneratorToolsetSet = true;
  243. }
  244. bool IsAKnownSourceExtension(cm::string_view ext) const
  245. {
  246. return this->CLikeSourceFileExtensions.Test(ext) ||
  247. this->CudaFileExtensions.Test(ext) ||
  248. this->FortranFileExtensions.Test(ext) ||
  249. this->ISPCFileExtensions.Test(ext);
  250. }
  251. bool IsACLikeSourceExtension(cm::string_view ext) const
  252. {
  253. return this->CLikeSourceFileExtensions.Test(ext);
  254. }
  255. bool IsAKnownExtension(cm::string_view ext) const
  256. {
  257. return this->IsAKnownSourceExtension(ext) || this->IsAHeaderExtension(ext);
  258. }
  259. std::vector<std::string> GetAllExtensions() const;
  260. const std::vector<std::string>& GetHeaderExtensions() const
  261. {
  262. return this->HeaderFileExtensions.ordered;
  263. }
  264. bool IsAHeaderExtension(cm::string_view ext) const
  265. {
  266. return this->HeaderFileExtensions.Test(ext);
  267. }
  268. // Strips the extension (if present and known) from a filename
  269. std::string StripExtension(const std::string& file) const;
  270. /**
  271. * Given a variable name, return its value (as a string).
  272. */
  273. cmProp GetCacheDefinition(const std::string&) const;
  274. //! Add an entry into the cache
  275. void AddCacheEntry(const std::string& key, const char* value,
  276. const char* helpString, int type);
  277. bool DoWriteGlobVerifyTarget() const;
  278. std::string const& GetGlobVerifyScript() const;
  279. std::string const& GetGlobVerifyStamp() const;
  280. void AddGlobCacheEntry(bool recurse, bool listDirectories,
  281. bool followSymlinks, const std::string& relative,
  282. const std::string& expression,
  283. const std::vector<std::string>& files,
  284. const std::string& variable,
  285. cmListFileBacktrace const& bt);
  286. /**
  287. * Get the system information and write it to the file specified
  288. */
  289. int GetSystemInformation(std::vector<std::string>&);
  290. //! Parse environment variables
  291. void LoadEnvironmentPresets();
  292. //! Parse command line arguments
  293. void SetArgs(const std::vector<std::string>& args);
  294. //! Is this cmake running as a result of a TRY_COMPILE command
  295. bool GetIsInTryCompile() const;
  296. void SetIsInTryCompile(bool b);
  297. #ifndef CMAKE_BOOTSTRAP
  298. void SetWarningFromPreset(const std::string& name,
  299. const cm::optional<bool>& warning,
  300. const cm::optional<bool>& error);
  301. void ProcessPresetVariables();
  302. void PrintPresetVariables();
  303. void ProcessPresetEnvironment();
  304. void PrintPresetEnvironment();
  305. #endif
  306. //! Parse command line arguments that might set cache values
  307. bool SetCacheArgs(const std::vector<std::string>&);
  308. void ProcessCacheArg(const std::string& var, const std::string& value,
  309. cmStateEnums::CacheEntryType type);
  310. using ProgressCallbackType = std::function<void(const std::string&, float)>;
  311. /**
  312. * Set the function used by GUIs to receive progress updates
  313. * Function gets passed: message as a const char*, a progress
  314. * amount ranging from 0 to 1.0 and client data. The progress
  315. * number provided may be negative in cases where a message is
  316. * to be displayed without any progress percentage.
  317. */
  318. void SetProgressCallback(ProgressCallbackType f);
  319. //! this is called by generators to update the progress
  320. void UpdateProgress(const std::string& msg, float prog);
  321. #if !defined(CMAKE_BOOTSTRAP)
  322. //! Get the variable watch object
  323. cmVariableWatch* GetVariableWatch() { return this->VariableWatch.get(); }
  324. #endif
  325. std::vector<cmDocumentationEntry> GetGeneratorsDocumentation();
  326. //! Set/Get a property of this target file
  327. void SetProperty(const std::string& prop, const char* value);
  328. void AppendProperty(const std::string& prop, const std::string& value,
  329. bool asString = false);
  330. cmProp GetProperty(const std::string& prop);
  331. bool GetPropertyAsBool(const std::string& prop);
  332. //! Get or create an cmInstalledFile instance and return a pointer to it
  333. cmInstalledFile* GetOrCreateInstalledFile(cmMakefile* mf,
  334. const std::string& name);
  335. cmInstalledFile const* GetInstalledFile(const std::string& name) const;
  336. InstalledFilesMap const& GetInstalledFiles() const
  337. {
  338. return this->InstalledFiles;
  339. }
  340. //! Do all the checks before running configure
  341. int DoPreConfigureChecks();
  342. void SetWorkingMode(WorkingMode mode) { this->CurrentWorkingMode = mode; }
  343. WorkingMode GetWorkingMode() { return this->CurrentWorkingMode; }
  344. //! Debug the try compile stuff by not deleting the files
  345. bool GetDebugTryCompile() const { return this->DebugTryCompile; }
  346. void DebugTryCompileOn() { this->DebugTryCompile = true; }
  347. /**
  348. * Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
  349. */
  350. int AddCMakePaths();
  351. /**
  352. * Get the file comparison class
  353. */
  354. cmFileTimeCache* GetFileTimeCache() { return this->FileTimeCache.get(); }
  355. bool WasLogLevelSetViaCLI() const { return this->LogLevelWasSetViaCLI; }
  356. //! Get the selected log level for `message()` commands during the cmake run.
  357. LogLevel GetLogLevel() const { return this->MessageLogLevel; }
  358. void SetLogLevel(LogLevel level) { this->MessageLogLevel = level; }
  359. static LogLevel StringToLogLevel(const std::string& levelStr);
  360. static TraceFormat StringToTraceFormat(const std::string& levelStr);
  361. bool HasCheckInProgress() const
  362. {
  363. return !this->CheckInProgressMessages.empty();
  364. }
  365. std::size_t GetCheckInProgressSize() const
  366. {
  367. return this->CheckInProgressMessages.size();
  368. }
  369. std::string GetTopCheckInProgressMessage()
  370. {
  371. auto message = this->CheckInProgressMessages.top();
  372. this->CheckInProgressMessages.pop();
  373. return message;
  374. }
  375. void PushCheckInProgressMessage(std::string message)
  376. {
  377. this->CheckInProgressMessages.emplace(std::move(message));
  378. }
  379. //! Should `message` command display context.
  380. bool GetShowLogContext() const { return this->LogContext; }
  381. void SetShowLogContext(bool b) { this->LogContext = b; }
  382. //! Do we want debug output during the cmake run.
  383. bool GetDebugOutput() const { return this->DebugOutput; }
  384. void SetDebugOutputOn(bool b) { this->DebugOutput = b; }
  385. //! Do we want debug output from the find commands during the cmake run.
  386. bool GetDebugFindOutput() const { return this->DebugFindOutput; }
  387. void SetDebugFindOutputOn(bool b) { this->DebugFindOutput = b; }
  388. //! Do we want trace output during the cmake run.
  389. bool GetTrace() const { return this->Trace; }
  390. void SetTrace(bool b) { this->Trace = b; }
  391. bool GetTraceExpand() const { return this->TraceExpand; }
  392. void SetTraceExpand(bool b) { this->TraceExpand = b; }
  393. TraceFormat GetTraceFormat() const { return this->TraceFormatVar; }
  394. void SetTraceFormat(TraceFormat f) { this->TraceFormatVar = f; }
  395. void AddTraceSource(std::string const& file)
  396. {
  397. this->TraceOnlyThisSources.push_back(file);
  398. }
  399. std::vector<std::string> const& GetTraceSources() const
  400. {
  401. return this->TraceOnlyThisSources;
  402. }
  403. cmGeneratedFileStream& GetTraceFile() { return this->TraceFile; }
  404. void SetTraceFile(std::string const& file);
  405. void PrintTraceFormatVersion();
  406. bool GetWarnUninitialized() const { return this->WarnUninitialized; }
  407. void SetWarnUninitialized(bool b) { this->WarnUninitialized = b; }
  408. bool GetWarnUnusedCli() const { return this->WarnUnusedCli; }
  409. void SetWarnUnusedCli(bool b) { this->WarnUnusedCli = b; }
  410. bool GetCheckSystemVars() const { return this->CheckSystemVars; }
  411. void SetCheckSystemVars(bool b) { this->CheckSystemVars = b; }
  412. void MarkCliAsUsed(const std::string& variable);
  413. /** Get the list of configurations (in upper case) considered to be
  414. debugging configurations.*/
  415. std::vector<std::string> GetDebugConfigs();
  416. void SetCMakeEditCommand(std::string const& s)
  417. {
  418. this->CMakeEditCommand = s;
  419. }
  420. std::string const& GetCMakeEditCommand() const
  421. {
  422. return this->CMakeEditCommand;
  423. }
  424. cmMessenger* GetMessenger() const { return this->Messenger.get(); }
  425. /**
  426. * Get the state of the suppression of developer (author) warnings.
  427. * Returns false, by default, if developer warnings should be shown, true
  428. * otherwise.
  429. */
  430. bool GetSuppressDevWarnings() const;
  431. /**
  432. * Set the state of the suppression of developer (author) warnings.
  433. */
  434. void SetSuppressDevWarnings(bool v);
  435. /**
  436. * Get the state of the suppression of deprecated warnings.
  437. * Returns false, by default, if deprecated warnings should be shown, true
  438. * otherwise.
  439. */
  440. bool GetSuppressDeprecatedWarnings() const;
  441. /**
  442. * Set the state of the suppression of deprecated warnings.
  443. */
  444. void SetSuppressDeprecatedWarnings(bool v);
  445. /**
  446. * Get the state of treating developer (author) warnings as errors.
  447. * Returns false, by default, if warnings should not be treated as errors,
  448. * true otherwise.
  449. */
  450. bool GetDevWarningsAsErrors() const;
  451. /**
  452. * Set the state of treating developer (author) warnings as errors.
  453. */
  454. void SetDevWarningsAsErrors(bool v);
  455. /**
  456. * Get the state of treating deprecated warnings as errors.
  457. * Returns false, by default, if warnings should not be treated as errors,
  458. * true otherwise.
  459. */
  460. bool GetDeprecatedWarningsAsErrors() const;
  461. /**
  462. * Set the state of treating developer (author) warnings as errors.
  463. */
  464. void SetDeprecatedWarningsAsErrors(bool v);
  465. /** Display a message to the user. */
  466. void IssueMessage(
  467. MessageType t, std::string const& text,
  468. cmListFileBacktrace const& backtrace = cmListFileBacktrace()) const;
  469. //! run the --build option
  470. int Build(int jobs, const std::string& dir,
  471. const std::vector<std::string>& targets, const std::string& config,
  472. const std::vector<std::string>& nativeOptions, bool clean,
  473. bool verbose);
  474. //! run the --open option
  475. bool Open(const std::string& dir, bool dryRun);
  476. void UnwatchUnusedCli(const std::string& var);
  477. void WatchUnusedCli(const std::string& var);
  478. cmState* GetState() const { return this->State.get(); }
  479. void SetCurrentSnapshot(cmStateSnapshot const& snapshot)
  480. {
  481. this->CurrentSnapshot = snapshot;
  482. }
  483. cmStateSnapshot GetCurrentSnapshot() const { return this->CurrentSnapshot; }
  484. bool GetRegenerateDuringBuild() const { return this->RegenerateDuringBuild; }
  485. #if !defined(CMAKE_BOOTSTRAP)
  486. cmMakefileProfilingData& GetProfilingOutput();
  487. bool IsProfilingEnabled() const;
  488. #endif
  489. protected:
  490. void RunCheckForUnusedVariables();
  491. int HandleDeleteCacheVariables(const std::string& var);
  492. using RegisteredGeneratorsVector =
  493. std::vector<std::unique_ptr<cmGlobalGeneratorFactory>>;
  494. RegisteredGeneratorsVector Generators;
  495. using RegisteredExtraGeneratorsVector =
  496. std::vector<cmExternalMakefileProjectGeneratorFactory*>;
  497. RegisteredExtraGeneratorsVector ExtraGenerators;
  498. void AddScriptingCommands() const;
  499. void AddProjectCommands() const;
  500. void AddDefaultGenerators();
  501. void AddDefaultExtraGenerators();
  502. std::map<std::string, DiagLevel> DiagLevels;
  503. std::string GeneratorInstance;
  504. std::string GeneratorPlatform;
  505. std::string GeneratorToolset;
  506. bool GeneratorInstanceSet = false;
  507. bool GeneratorPlatformSet = false;
  508. bool GeneratorToolsetSet = false;
  509. //! read in a cmake list file to initialize the cache
  510. void ReadListFile(const std::vector<std::string>& args,
  511. const std::string& path);
  512. bool FindPackage(const std::vector<std::string>& args);
  513. //! Check if CMAKE_CACHEFILE_DIR is set. If it is not, delete the log file.
  514. /// If it is set, truncate it to 50kb
  515. void TruncateOutputLog(const char* fname);
  516. /**
  517. * Method called to check build system integrity at build time.
  518. * Returns 1 if CMake should rerun and 0 otherwise.
  519. */
  520. int CheckBuildSystem();
  521. void SetDirectoriesFromFile(const std::string& arg);
  522. //! Make sure all commands are what they say they are and there is no
  523. /// macros.
  524. void CleanupCommandsAndMacros();
  525. void GenerateGraphViz(const std::string& fileName) const;
  526. private:
  527. ProgressCallbackType ProgressCallback;
  528. WorkingMode CurrentWorkingMode = NORMAL_MODE;
  529. bool DebugOutput = false;
  530. bool DebugFindOutput = false;
  531. bool Trace = false;
  532. bool TraceExpand = false;
  533. TraceFormat TraceFormatVar = TRACE_HUMAN;
  534. cmGeneratedFileStream TraceFile;
  535. bool WarnUninitialized = false;
  536. bool WarnUnusedCli = true;
  537. bool CheckSystemVars = false;
  538. std::map<std::string, bool> UsedCliVariables;
  539. std::string CMakeEditCommand;
  540. std::string CXXEnvironment;
  541. std::string CCEnvironment;
  542. std::string CheckBuildSystemArgument;
  543. std::string CheckStampFile;
  544. std::string CheckStampList;
  545. std::string VSSolutionFile;
  546. std::string EnvironmentGenerator;
  547. FileExtensions CLikeSourceFileExtensions;
  548. FileExtensions HeaderFileExtensions;
  549. FileExtensions CudaFileExtensions;
  550. FileExtensions ISPCFileExtensions;
  551. FileExtensions FortranFileExtensions;
  552. bool ClearBuildSystem = false;
  553. bool DebugTryCompile = false;
  554. bool RegenerateDuringBuild = false;
  555. std::unique_ptr<cmFileTimeCache> FileTimeCache;
  556. std::string GraphVizFile;
  557. InstalledFilesMap InstalledFiles;
  558. #ifndef CMAKE_BOOTSTRAP
  559. std::map<std::string, cm::optional<cmCMakePresetsFile::CacheVariable>>
  560. UnprocessedPresetVariables;
  561. std::map<std::string, cm::optional<std::string>>
  562. UnprocessedPresetEnvironment;
  563. #endif
  564. #if !defined(CMAKE_BOOTSTRAP)
  565. std::unique_ptr<cmVariableWatch> VariableWatch;
  566. std::unique_ptr<cmFileAPI> FileAPI;
  567. #endif
  568. std::unique_ptr<cmState> State;
  569. cmStateSnapshot CurrentSnapshot;
  570. std::unique_ptr<cmMessenger> Messenger;
  571. std::vector<std::string> TraceOnlyThisSources;
  572. LogLevel MessageLogLevel = LogLevel::LOG_STATUS;
  573. bool LogLevelWasSetViaCLI = false;
  574. bool LogContext = false;
  575. std::stack<std::string> CheckInProgressMessages;
  576. std::unique_ptr<cmGlobalGenerator> GlobalGenerator;
  577. void UpdateConversionPathTable();
  578. //! Print a list of valid generators to stderr.
  579. void PrintGeneratorList();
  580. std::unique_ptr<cmGlobalGenerator> EvaluateDefaultGlobalGenerator();
  581. void CreateDefaultGlobalGenerator();
  582. void AppendGlobalGeneratorsDocumentation(std::vector<cmDocumentationEntry>&);
  583. void AppendExtraGeneratorsDocumentation(std::vector<cmDocumentationEntry>&);
  584. #if !defined(CMAKE_BOOTSTRAP)
  585. std::unique_ptr<cmMakefileProfilingData> ProfilingOutput;
  586. #endif
  587. };
  588. #define CMAKE_STANDARD_OPTIONS_TABLE \
  589. { "-S <path-to-source>", "Explicitly specify a source directory." }, \
  590. { "-B <path-to-build>", "Explicitly specify a build directory." }, \
  591. { "-C <initial-cache>", "Pre-load a script to populate the cache." }, \
  592. { "-D <var>[:<type>]=<value>", "Create or update a cmake cache entry." }, \
  593. { "-U <globbing_expr>", "Remove matching entries from CMake cache." }, \
  594. { "-G <generator-name>", "Specify a build system generator." }, \
  595. { "-T <toolset-name>", \
  596. "Specify toolset name if supported by generator." }, \
  597. { "-A <platform-name>", \
  598. "Specify platform name if supported by generator." }, \
  599. { "-Wdev", "Enable developer warnings." }, \
  600. { "-Wno-dev", "Suppress developer warnings." }, \
  601. { "-Werror=dev", "Make developer warnings errors." }, \
  602. { "-Wno-error=dev", "Make developer warnings not errors." }, \
  603. { "-Wdeprecated", "Enable deprecation warnings." }, \
  604. { "-Wno-deprecated", "Suppress deprecation warnings." }, \
  605. { "-Werror=deprecated", \
  606. "Make deprecated macro and function warnings " \
  607. "errors." }, \
  608. { \
  609. "-Wno-error=deprecated", \
  610. "Make deprecated macro and function warnings " \
  611. "not errors." \
  612. }
  613. #define FOR_EACH_C90_FEATURE(F) F(c_function_prototypes)
  614. #define FOR_EACH_C99_FEATURE(F) \
  615. F(c_restrict) \
  616. F(c_variadic_macros)
  617. #define FOR_EACH_C11_FEATURE(F) F(c_static_assert)
  618. #define FOR_EACH_C_FEATURE(F) \
  619. F(c_std_90) \
  620. F(c_std_99) \
  621. F(c_std_11) \
  622. FOR_EACH_C90_FEATURE(F) \
  623. FOR_EACH_C99_FEATURE(F) \
  624. FOR_EACH_C11_FEATURE(F)
  625. #define FOR_EACH_CXX98_FEATURE(F) F(cxx_template_template_parameters)
  626. #define FOR_EACH_CXX11_FEATURE(F) \
  627. F(cxx_alias_templates) \
  628. F(cxx_alignas) \
  629. F(cxx_alignof) \
  630. F(cxx_attributes) \
  631. F(cxx_auto_type) \
  632. F(cxx_constexpr) \
  633. F(cxx_decltype) \
  634. F(cxx_decltype_incomplete_return_types) \
  635. F(cxx_default_function_template_args) \
  636. F(cxx_defaulted_functions) \
  637. F(cxx_defaulted_move_initializers) \
  638. F(cxx_delegating_constructors) \
  639. F(cxx_deleted_functions) \
  640. F(cxx_enum_forward_declarations) \
  641. F(cxx_explicit_conversions) \
  642. F(cxx_extended_friend_declarations) \
  643. F(cxx_extern_templates) \
  644. F(cxx_final) \
  645. F(cxx_func_identifier) \
  646. F(cxx_generalized_initializers) \
  647. F(cxx_inheriting_constructors) \
  648. F(cxx_inline_namespaces) \
  649. F(cxx_lambdas) \
  650. F(cxx_local_type_template_args) \
  651. F(cxx_long_long_type) \
  652. F(cxx_noexcept) \
  653. F(cxx_nonstatic_member_init) \
  654. F(cxx_nullptr) \
  655. F(cxx_override) \
  656. F(cxx_range_for) \
  657. F(cxx_raw_string_literals) \
  658. F(cxx_reference_qualified_functions) \
  659. F(cxx_right_angle_brackets) \
  660. F(cxx_rvalue_references) \
  661. F(cxx_sizeof_member) \
  662. F(cxx_static_assert) \
  663. F(cxx_strong_enums) \
  664. F(cxx_thread_local) \
  665. F(cxx_trailing_return_types) \
  666. F(cxx_unicode_literals) \
  667. F(cxx_uniform_initialization) \
  668. F(cxx_unrestricted_unions) \
  669. F(cxx_user_literals) \
  670. F(cxx_variadic_macros) \
  671. F(cxx_variadic_templates)
  672. #define FOR_EACH_CXX14_FEATURE(F) \
  673. F(cxx_aggregate_default_initializers) \
  674. F(cxx_attribute_deprecated) \
  675. F(cxx_binary_literals) \
  676. F(cxx_contextual_conversions) \
  677. F(cxx_decltype_auto) \
  678. F(cxx_digit_separators) \
  679. F(cxx_generic_lambdas) \
  680. F(cxx_lambda_init_captures) \
  681. F(cxx_relaxed_constexpr) \
  682. F(cxx_return_type_deduction) \
  683. F(cxx_variable_templates)
  684. #define FOR_EACH_CXX_FEATURE(F) \
  685. F(cxx_std_98) \
  686. F(cxx_std_11) \
  687. F(cxx_std_14) \
  688. F(cxx_std_17) \
  689. F(cxx_std_20) \
  690. FOR_EACH_CXX98_FEATURE(F) \
  691. FOR_EACH_CXX11_FEATURE(F) \
  692. FOR_EACH_CXX14_FEATURE(F)
  693. #define FOR_EACH_CUDA_FEATURE(F) \
  694. F(cuda_std_03) \
  695. F(cuda_std_11) \
  696. F(cuda_std_14) \
  697. F(cuda_std_17) \
  698. F(cuda_std_20)