cmake.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  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. cmState::ProjectKind projectKind = cmState::ProjectKind::Normal);
  149. /// Destructor
  150. ~cmake();
  151. cmake(cmake const&) = delete;
  152. cmake& operator=(cmake const&) = delete;
  153. #if !defined(CMAKE_BOOTSTRAP)
  154. Json::Value ReportVersionJson() const;
  155. Json::Value ReportCapabilitiesJson() const;
  156. #endif
  157. std::string ReportCapabilities() const;
  158. //@{
  159. /**
  160. * Set/Get the home directory (or output directory) in the project. The
  161. * home directory is the top directory of the project. It is the
  162. * path-to-source cmake was run with.
  163. */
  164. void SetHomeDirectory(const std::string& dir);
  165. std::string const& GetHomeDirectory() const;
  166. void SetHomeOutputDirectory(const std::string& dir);
  167. std::string const& GetHomeOutputDirectory() const;
  168. //@}
  169. /**
  170. * Working directory at CMake launch
  171. */
  172. std::string const& GetCMakeWorkingDirectory() const
  173. {
  174. return this->CMakeWorkingDirectory;
  175. }
  176. /**
  177. * Handle a command line invocation of cmake.
  178. */
  179. int Run(const std::vector<std::string>& args)
  180. {
  181. return this->Run(args, false);
  182. }
  183. int Run(const std::vector<std::string>& args, bool noconfigure);
  184. /**
  185. * Run the global generator Generate step.
  186. */
  187. int Generate();
  188. /**
  189. * Configure the cmMakefiles. This routine will create a GlobalGenerator if
  190. * one has not already been set. It will then Call Configure on the
  191. * GlobalGenerator. This in turn will read in an process all the CMakeList
  192. * files for the tree. It will not produce any actual Makefiles, or
  193. * workspaces. Generate does that. */
  194. int Configure();
  195. int ActualConfigure();
  196. //! Break up a line like VAR:type="value" into var, type and value
  197. static bool ParseCacheEntry(const std::string& entry, std::string& var,
  198. std::string& value,
  199. cmStateEnums::CacheEntryType& type);
  200. int LoadCache();
  201. bool LoadCache(const std::string& path);
  202. bool LoadCache(const std::string& path, bool internal,
  203. std::set<std::string>& excludes,
  204. std::set<std::string>& includes);
  205. bool SaveCache(const std::string& path);
  206. bool DeleteCache(const std::string& path);
  207. void PreLoadCMakeFiles();
  208. //! Create a GlobalGenerator
  209. std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator(
  210. const std::string& name, bool allowArch = true);
  211. //! Create a GlobalGenerator and set it as our own
  212. bool CreateAndSetGlobalGenerator(const std::string& name, bool allowArch);
  213. #ifndef CMAKE_BOOTSTRAP
  214. //! Print list of configure presets
  215. void PrintPresetList(const cmCMakePresetsFile& file) const;
  216. #endif
  217. //! Return the global generator assigned to this instance of cmake
  218. cmGlobalGenerator* GetGlobalGenerator()
  219. {
  220. return this->GlobalGenerator.get();
  221. }
  222. //! Return the global generator assigned to this instance of cmake, const
  223. const cmGlobalGenerator* GetGlobalGenerator() const
  224. {
  225. return this->GlobalGenerator.get();
  226. }
  227. //! Return the full path to where the CMakeCache.txt file should be.
  228. static std::string FindCacheFile(const std::string& binaryDir);
  229. //! Return the global generator assigned to this instance of cmake
  230. void SetGlobalGenerator(std::unique_ptr<cmGlobalGenerator>);
  231. //! Get the names of the current registered generators
  232. void GetRegisteredGenerators(std::vector<GeneratorInfo>& generators,
  233. bool includeNamesWithPlatform = true) const;
  234. //! Set the name of the selected generator-specific instance.
  235. void SetGeneratorInstance(std::string const& instance)
  236. {
  237. this->GeneratorInstance = instance;
  238. this->GeneratorInstanceSet = true;
  239. }
  240. //! Set the name of the selected generator-specific platform.
  241. void SetGeneratorPlatform(std::string const& ts)
  242. {
  243. this->GeneratorPlatform = ts;
  244. this->GeneratorPlatformSet = true;
  245. }
  246. //! Set the name of the selected generator-specific toolset.
  247. void SetGeneratorToolset(std::string const& ts)
  248. {
  249. this->GeneratorToolset = ts;
  250. this->GeneratorToolsetSet = true;
  251. }
  252. bool IsAKnownSourceExtension(cm::string_view ext) const
  253. {
  254. return this->CLikeSourceFileExtensions.Test(ext) ||
  255. this->CudaFileExtensions.Test(ext) ||
  256. this->FortranFileExtensions.Test(ext) ||
  257. this->HipFileExtensions.Test(ext) || this->ISPCFileExtensions.Test(ext);
  258. }
  259. bool IsACLikeSourceExtension(cm::string_view ext) const
  260. {
  261. return this->CLikeSourceFileExtensions.Test(ext);
  262. }
  263. bool IsAKnownExtension(cm::string_view ext) const
  264. {
  265. return this->IsAKnownSourceExtension(ext) || this->IsAHeaderExtension(ext);
  266. }
  267. std::vector<std::string> GetAllExtensions() const;
  268. const std::vector<std::string>& GetHeaderExtensions() const
  269. {
  270. return this->HeaderFileExtensions.ordered;
  271. }
  272. bool IsAHeaderExtension(cm::string_view ext) const
  273. {
  274. return this->HeaderFileExtensions.Test(ext);
  275. }
  276. // Strips the extension (if present and known) from a filename
  277. std::string StripExtension(const std::string& file) const;
  278. /**
  279. * Given a variable name, return its value (as a string).
  280. */
  281. cmProp GetCacheDefinition(const std::string&) const;
  282. //! Add an entry into the cache
  283. void AddCacheEntry(const std::string& key, const char* value,
  284. const char* helpString, int type);
  285. bool DoWriteGlobVerifyTarget() const;
  286. std::string const& GetGlobVerifyScript() const;
  287. std::string const& GetGlobVerifyStamp() const;
  288. void AddGlobCacheEntry(bool recurse, bool listDirectories,
  289. bool followSymlinks, const std::string& relative,
  290. const std::string& expression,
  291. const std::vector<std::string>& files,
  292. const std::string& variable,
  293. cmListFileBacktrace const& bt);
  294. /**
  295. * Get the system information and write it to the file specified
  296. */
  297. int GetSystemInformation(std::vector<std::string>&);
  298. //! Parse environment variables
  299. void LoadEnvironmentPresets();
  300. //! Parse command line arguments
  301. void SetArgs(const std::vector<std::string>& args);
  302. //! Is this cmake running as a result of a TRY_COMPILE command
  303. bool GetIsInTryCompile() const;
  304. #ifndef CMAKE_BOOTSTRAP
  305. void SetWarningFromPreset(const std::string& name,
  306. const cm::optional<bool>& warning,
  307. const cm::optional<bool>& error);
  308. void ProcessPresetVariables();
  309. void PrintPresetVariables();
  310. void ProcessPresetEnvironment();
  311. void PrintPresetEnvironment();
  312. #endif
  313. //! Parse command line arguments that might set cache values
  314. bool SetCacheArgs(const std::vector<std::string>&);
  315. void ProcessCacheArg(const std::string& var, const std::string& value,
  316. cmStateEnums::CacheEntryType type);
  317. using ProgressCallbackType = std::function<void(const std::string&, float)>;
  318. /**
  319. * Set the function used by GUIs to receive progress updates
  320. * Function gets passed: message as a const char*, a progress
  321. * amount ranging from 0 to 1.0 and client data. The progress
  322. * number provided may be negative in cases where a message is
  323. * to be displayed without any progress percentage.
  324. */
  325. void SetProgressCallback(ProgressCallbackType f);
  326. //! this is called by generators to update the progress
  327. void UpdateProgress(const std::string& msg, float prog);
  328. #if !defined(CMAKE_BOOTSTRAP)
  329. //! Get the variable watch object
  330. cmVariableWatch* GetVariableWatch() { return this->VariableWatch.get(); }
  331. #endif
  332. std::vector<cmDocumentationEntry> GetGeneratorsDocumentation();
  333. //! Set/Get a property of this target file
  334. void SetProperty(const std::string& prop, const char* value);
  335. void SetProperty(const std::string& prop, cmProp value);
  336. void SetProperty(const std::string& prop, const std::string& value)
  337. {
  338. this->SetProperty(prop, cmProp(value));
  339. }
  340. void AppendProperty(const std::string& prop, const std::string& value,
  341. bool asString = false);
  342. cmProp GetProperty(const std::string& prop);
  343. bool GetPropertyAsBool(const std::string& prop);
  344. //! Get or create an cmInstalledFile instance and return a pointer to it
  345. cmInstalledFile* GetOrCreateInstalledFile(cmMakefile* mf,
  346. const std::string& name);
  347. cmInstalledFile const* GetInstalledFile(const std::string& name) const;
  348. InstalledFilesMap const& GetInstalledFiles() const
  349. {
  350. return this->InstalledFiles;
  351. }
  352. //! Do all the checks before running configure
  353. int DoPreConfigureChecks();
  354. void SetWorkingMode(WorkingMode mode) { this->CurrentWorkingMode = mode; }
  355. WorkingMode GetWorkingMode() { return this->CurrentWorkingMode; }
  356. //! Debug the try compile stuff by not deleting the files
  357. bool GetDebugTryCompile() const { return this->DebugTryCompile; }
  358. void DebugTryCompileOn() { this->DebugTryCompile = true; }
  359. /**
  360. * Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
  361. */
  362. int AddCMakePaths();
  363. /**
  364. * Get the file comparison class
  365. */
  366. cmFileTimeCache* GetFileTimeCache() { return this->FileTimeCache.get(); }
  367. bool WasLogLevelSetViaCLI() const { return this->LogLevelWasSetViaCLI; }
  368. //! Get the selected log level for `message()` commands during the cmake run.
  369. LogLevel GetLogLevel() const { return this->MessageLogLevel; }
  370. void SetLogLevel(LogLevel level) { this->MessageLogLevel = level; }
  371. static LogLevel StringToLogLevel(const std::string& levelStr);
  372. static TraceFormat StringToTraceFormat(const std::string& levelStr);
  373. bool HasCheckInProgress() const
  374. {
  375. return !this->CheckInProgressMessages.empty();
  376. }
  377. std::size_t GetCheckInProgressSize() const
  378. {
  379. return this->CheckInProgressMessages.size();
  380. }
  381. std::string GetTopCheckInProgressMessage()
  382. {
  383. auto message = this->CheckInProgressMessages.top();
  384. this->CheckInProgressMessages.pop();
  385. return message;
  386. }
  387. void PushCheckInProgressMessage(std::string message)
  388. {
  389. this->CheckInProgressMessages.emplace(std::move(message));
  390. }
  391. //! Should `message` command display context.
  392. bool GetShowLogContext() const { return this->LogContext; }
  393. void SetShowLogContext(bool b) { this->LogContext = b; }
  394. //! Do we want debug output during the cmake run.
  395. bool GetDebugOutput() const { return this->DebugOutput; }
  396. void SetDebugOutputOn(bool b) { this->DebugOutput = b; }
  397. //! Do we want debug output from the find commands during the cmake run.
  398. bool GetDebugFindOutput() const { return this->DebugFindOutput; }
  399. void SetDebugFindOutputOn(bool b) { this->DebugFindOutput = b; }
  400. //! Do we want trace output during the cmake run.
  401. bool GetTrace() const { return this->Trace; }
  402. void SetTrace(bool b) { this->Trace = b; }
  403. bool GetTraceExpand() const { return this->TraceExpand; }
  404. void SetTraceExpand(bool b) { this->TraceExpand = b; }
  405. TraceFormat GetTraceFormat() const { return this->TraceFormatVar; }
  406. void SetTraceFormat(TraceFormat f) { this->TraceFormatVar = f; }
  407. void AddTraceSource(std::string const& file)
  408. {
  409. this->TraceOnlyThisSources.push_back(file);
  410. }
  411. std::vector<std::string> const& GetTraceSources() const
  412. {
  413. return this->TraceOnlyThisSources;
  414. }
  415. cmGeneratedFileStream& GetTraceFile() { return this->TraceFile; }
  416. void SetTraceFile(std::string const& file);
  417. void PrintTraceFormatVersion();
  418. bool GetWarnUninitialized() const { return this->WarnUninitialized; }
  419. void SetWarnUninitialized(bool b) { this->WarnUninitialized = b; }
  420. bool GetWarnUnusedCli() const { return this->WarnUnusedCli; }
  421. void SetWarnUnusedCli(bool b) { this->WarnUnusedCli = b; }
  422. bool GetCheckSystemVars() const { return this->CheckSystemVars; }
  423. void SetCheckSystemVars(bool b) { this->CheckSystemVars = b; }
  424. void MarkCliAsUsed(const std::string& variable);
  425. /** Get the list of configurations (in upper case) considered to be
  426. debugging configurations.*/
  427. std::vector<std::string> GetDebugConfigs();
  428. void SetCMakeEditCommand(std::string const& s)
  429. {
  430. this->CMakeEditCommand = s;
  431. }
  432. std::string const& GetCMakeEditCommand() const
  433. {
  434. return this->CMakeEditCommand;
  435. }
  436. cmMessenger* GetMessenger() const { return this->Messenger.get(); }
  437. /**
  438. * Get the state of the suppression of developer (author) warnings.
  439. * Returns false, by default, if developer warnings should be shown, true
  440. * otherwise.
  441. */
  442. bool GetSuppressDevWarnings() const;
  443. /**
  444. * Set the state of the suppression of developer (author) warnings.
  445. */
  446. void SetSuppressDevWarnings(bool v);
  447. /**
  448. * Get the state of the suppression of deprecated warnings.
  449. * Returns false, by default, if deprecated warnings should be shown, true
  450. * otherwise.
  451. */
  452. bool GetSuppressDeprecatedWarnings() const;
  453. /**
  454. * Set the state of the suppression of deprecated warnings.
  455. */
  456. void SetSuppressDeprecatedWarnings(bool v);
  457. /**
  458. * Get the state of treating developer (author) warnings as errors.
  459. * Returns false, by default, if warnings should not be treated as errors,
  460. * true otherwise.
  461. */
  462. bool GetDevWarningsAsErrors() const;
  463. /**
  464. * Set the state of treating developer (author) warnings as errors.
  465. */
  466. void SetDevWarningsAsErrors(bool v);
  467. /**
  468. * Get the state of treating deprecated warnings as errors.
  469. * Returns false, by default, if warnings should not be treated as errors,
  470. * true otherwise.
  471. */
  472. bool GetDeprecatedWarningsAsErrors() const;
  473. /**
  474. * Set the state of treating developer (author) warnings as errors.
  475. */
  476. void SetDeprecatedWarningsAsErrors(bool v);
  477. /** Display a message to the user. */
  478. void IssueMessage(
  479. MessageType t, std::string const& text,
  480. cmListFileBacktrace const& backtrace = cmListFileBacktrace()) const;
  481. //! run the --build option
  482. int Build(int jobs, std::string dir, std::vector<std::string> targets,
  483. std::string config, std::vector<std::string> nativeOptions,
  484. bool clean, bool verbose, const std::string& presetName,
  485. bool listPresets);
  486. //! run the --open option
  487. bool Open(const std::string& dir, bool dryRun);
  488. void UnwatchUnusedCli(const std::string& var);
  489. void WatchUnusedCli(const std::string& var);
  490. cmState* GetState() const { return this->State.get(); }
  491. void SetCurrentSnapshot(cmStateSnapshot const& snapshot)
  492. {
  493. this->CurrentSnapshot = snapshot;
  494. }
  495. cmStateSnapshot GetCurrentSnapshot() const { return this->CurrentSnapshot; }
  496. bool GetRegenerateDuringBuild() const { return this->RegenerateDuringBuild; }
  497. #if !defined(CMAKE_BOOTSTRAP)
  498. cmMakefileProfilingData& GetProfilingOutput();
  499. bool IsProfilingEnabled() const;
  500. #endif
  501. protected:
  502. void RunCheckForUnusedVariables();
  503. int HandleDeleteCacheVariables(const std::string& var);
  504. using RegisteredGeneratorsVector =
  505. std::vector<std::unique_ptr<cmGlobalGeneratorFactory>>;
  506. RegisteredGeneratorsVector Generators;
  507. using RegisteredExtraGeneratorsVector =
  508. std::vector<cmExternalMakefileProjectGeneratorFactory*>;
  509. RegisteredExtraGeneratorsVector ExtraGenerators;
  510. void AddScriptingCommands() const;
  511. void AddProjectCommands() const;
  512. void AddDefaultGenerators();
  513. void AddDefaultExtraGenerators();
  514. std::map<std::string, DiagLevel> DiagLevels;
  515. std::string GeneratorInstance;
  516. std::string GeneratorPlatform;
  517. std::string GeneratorToolset;
  518. bool GeneratorInstanceSet = false;
  519. bool GeneratorPlatformSet = false;
  520. bool GeneratorToolsetSet = false;
  521. //! read in a cmake list file to initialize the cache
  522. void ReadListFile(const std::vector<std::string>& args,
  523. const std::string& path);
  524. bool FindPackage(const std::vector<std::string>& args);
  525. //! Check if CMAKE_CACHEFILE_DIR is set. If it is not, delete the log file.
  526. /// If it is set, truncate it to 50kb
  527. void TruncateOutputLog(const char* fname);
  528. /**
  529. * Method called to check build system integrity at build time.
  530. * Returns 1 if CMake should rerun and 0 otherwise.
  531. */
  532. int CheckBuildSystem();
  533. void SetDirectoriesFromFile(const std::string& arg);
  534. //! Make sure all commands are what they say they are and there is no
  535. /// macros.
  536. void CleanupCommandsAndMacros();
  537. void GenerateGraphViz(const std::string& fileName) const;
  538. private:
  539. std::string CMakeWorkingDirectory;
  540. ProgressCallbackType ProgressCallback;
  541. WorkingMode CurrentWorkingMode = NORMAL_MODE;
  542. bool DebugOutput = false;
  543. bool DebugFindOutput = false;
  544. bool Trace = false;
  545. bool TraceExpand = false;
  546. TraceFormat TraceFormatVar = TRACE_HUMAN;
  547. cmGeneratedFileStream TraceFile;
  548. bool WarnUninitialized = false;
  549. bool WarnUnusedCli = true;
  550. bool CheckSystemVars = false;
  551. std::map<std::string, bool> UsedCliVariables;
  552. std::string CMakeEditCommand;
  553. std::string CXXEnvironment;
  554. std::string CCEnvironment;
  555. std::string CheckBuildSystemArgument;
  556. std::string CheckStampFile;
  557. std::string CheckStampList;
  558. std::string VSSolutionFile;
  559. std::string EnvironmentGenerator;
  560. FileExtensions CLikeSourceFileExtensions;
  561. FileExtensions HeaderFileExtensions;
  562. FileExtensions CudaFileExtensions;
  563. FileExtensions ISPCFileExtensions;
  564. FileExtensions FortranFileExtensions;
  565. FileExtensions HipFileExtensions;
  566. bool ClearBuildSystem = false;
  567. bool DebugTryCompile = false;
  568. bool RegenerateDuringBuild = false;
  569. std::unique_ptr<cmFileTimeCache> FileTimeCache;
  570. std::string GraphVizFile;
  571. InstalledFilesMap InstalledFiles;
  572. #ifndef CMAKE_BOOTSTRAP
  573. std::map<std::string, cm::optional<cmCMakePresetsFile::CacheVariable>>
  574. UnprocessedPresetVariables;
  575. std::map<std::string, cm::optional<std::string>>
  576. UnprocessedPresetEnvironment;
  577. #endif
  578. #if !defined(CMAKE_BOOTSTRAP)
  579. std::unique_ptr<cmVariableWatch> VariableWatch;
  580. std::unique_ptr<cmFileAPI> FileAPI;
  581. #endif
  582. std::unique_ptr<cmState> State;
  583. cmStateSnapshot CurrentSnapshot;
  584. std::unique_ptr<cmMessenger> Messenger;
  585. std::vector<std::string> TraceOnlyThisSources;
  586. LogLevel MessageLogLevel = LogLevel::LOG_STATUS;
  587. bool LogLevelWasSetViaCLI = false;
  588. bool LogContext = false;
  589. std::stack<std::string> CheckInProgressMessages;
  590. std::unique_ptr<cmGlobalGenerator> GlobalGenerator;
  591. void UpdateConversionPathTable();
  592. //! Print a list of valid generators to stderr.
  593. void PrintGeneratorList();
  594. std::unique_ptr<cmGlobalGenerator> EvaluateDefaultGlobalGenerator();
  595. void CreateDefaultGlobalGenerator();
  596. void AppendGlobalGeneratorsDocumentation(std::vector<cmDocumentationEntry>&);
  597. void AppendExtraGeneratorsDocumentation(std::vector<cmDocumentationEntry>&);
  598. #if !defined(CMAKE_BOOTSTRAP)
  599. std::unique_ptr<cmMakefileProfilingData> ProfilingOutput;
  600. #endif
  601. };
  602. #define CMAKE_STANDARD_OPTIONS_TABLE \
  603. { "-S <path-to-source>", "Explicitly specify a source directory." }, \
  604. { "-B <path-to-build>", "Explicitly specify a build directory." }, \
  605. { "-C <initial-cache>", "Pre-load a script to populate the cache." }, \
  606. { "-D <var>[:<type>]=<value>", "Create or update a cmake cache entry." }, \
  607. { "-U <globbing_expr>", "Remove matching entries from CMake cache." }, \
  608. { "-G <generator-name>", "Specify a build system generator." }, \
  609. { "-T <toolset-name>", \
  610. "Specify toolset name if supported by generator." }, \
  611. { "-A <platform-name>", \
  612. "Specify platform name if supported by generator." }, \
  613. { "--toolchain <file>", \
  614. "Specify toolchain file [CMAKE_TOOLCHAIN_FILE]." }, \
  615. { "--install-prefix <directory>", \
  616. "Specify install directory [CMAKE_INSTALL_PREFIX]." }, \
  617. { "-Wdev", "Enable developer warnings." }, \
  618. { "-Wno-dev", "Suppress developer warnings." }, \
  619. { "-Werror=dev", "Make developer warnings errors." }, \
  620. { "-Wno-error=dev", "Make developer warnings not errors." }, \
  621. { "-Wdeprecated", "Enable deprecation warnings." }, \
  622. { "-Wno-deprecated", "Suppress deprecation warnings." }, \
  623. { "-Werror=deprecated", \
  624. "Make deprecated macro and function warnings " \
  625. "errors." }, \
  626. { \
  627. "-Wno-error=deprecated", \
  628. "Make deprecated macro and function warnings " \
  629. "not errors." \
  630. }
  631. #define FOR_EACH_C90_FEATURE(F) F(c_function_prototypes)
  632. #define FOR_EACH_C99_FEATURE(F) \
  633. F(c_restrict) \
  634. F(c_variadic_macros)
  635. #define FOR_EACH_C11_FEATURE(F) F(c_static_assert)
  636. #define FOR_EACH_C_FEATURE(F) \
  637. F(c_std_90) \
  638. F(c_std_99) \
  639. F(c_std_11) \
  640. F(c_std_17) \
  641. F(c_std_23) \
  642. FOR_EACH_C90_FEATURE(F) \
  643. FOR_EACH_C99_FEATURE(F) \
  644. FOR_EACH_C11_FEATURE(F)
  645. #define FOR_EACH_CXX98_FEATURE(F) F(cxx_template_template_parameters)
  646. #define FOR_EACH_CXX11_FEATURE(F) \
  647. F(cxx_alias_templates) \
  648. F(cxx_alignas) \
  649. F(cxx_alignof) \
  650. F(cxx_attributes) \
  651. F(cxx_auto_type) \
  652. F(cxx_constexpr) \
  653. F(cxx_decltype) \
  654. F(cxx_decltype_incomplete_return_types) \
  655. F(cxx_default_function_template_args) \
  656. F(cxx_defaulted_functions) \
  657. F(cxx_defaulted_move_initializers) \
  658. F(cxx_delegating_constructors) \
  659. F(cxx_deleted_functions) \
  660. F(cxx_enum_forward_declarations) \
  661. F(cxx_explicit_conversions) \
  662. F(cxx_extended_friend_declarations) \
  663. F(cxx_extern_templates) \
  664. F(cxx_final) \
  665. F(cxx_func_identifier) \
  666. F(cxx_generalized_initializers) \
  667. F(cxx_inheriting_constructors) \
  668. F(cxx_inline_namespaces) \
  669. F(cxx_lambdas) \
  670. F(cxx_local_type_template_args) \
  671. F(cxx_long_long_type) \
  672. F(cxx_noexcept) \
  673. F(cxx_nonstatic_member_init) \
  674. F(cxx_nullptr) \
  675. F(cxx_override) \
  676. F(cxx_range_for) \
  677. F(cxx_raw_string_literals) \
  678. F(cxx_reference_qualified_functions) \
  679. F(cxx_right_angle_brackets) \
  680. F(cxx_rvalue_references) \
  681. F(cxx_sizeof_member) \
  682. F(cxx_static_assert) \
  683. F(cxx_strong_enums) \
  684. F(cxx_thread_local) \
  685. F(cxx_trailing_return_types) \
  686. F(cxx_unicode_literals) \
  687. F(cxx_uniform_initialization) \
  688. F(cxx_unrestricted_unions) \
  689. F(cxx_user_literals) \
  690. F(cxx_variadic_macros) \
  691. F(cxx_variadic_templates)
  692. #define FOR_EACH_CXX14_FEATURE(F) \
  693. F(cxx_aggregate_default_initializers) \
  694. F(cxx_attribute_deprecated) \
  695. F(cxx_binary_literals) \
  696. F(cxx_contextual_conversions) \
  697. F(cxx_decltype_auto) \
  698. F(cxx_digit_separators) \
  699. F(cxx_generic_lambdas) \
  700. F(cxx_lambda_init_captures) \
  701. F(cxx_relaxed_constexpr) \
  702. F(cxx_return_type_deduction) \
  703. F(cxx_variable_templates)
  704. #define FOR_EACH_CXX_FEATURE(F) \
  705. F(cxx_std_98) \
  706. F(cxx_std_11) \
  707. F(cxx_std_14) \
  708. F(cxx_std_17) \
  709. F(cxx_std_20) \
  710. F(cxx_std_23) \
  711. FOR_EACH_CXX98_FEATURE(F) \
  712. FOR_EACH_CXX11_FEATURE(F) \
  713. FOR_EACH_CXX14_FEATURE(F)
  714. #define FOR_EACH_CUDA_FEATURE(F) \
  715. F(cuda_std_03) \
  716. F(cuda_std_11) \
  717. F(cuda_std_14) \
  718. F(cuda_std_17) \
  719. F(cuda_std_20) \
  720. F(cuda_std_23)
  721. #define FOR_EACH_HIP_FEATURE(F) \
  722. F(hip_std_98) \
  723. F(hip_std_11) \
  724. F(hip_std_14) \
  725. F(hip_std_17) \
  726. F(hip_std_20) \
  727. F(hip_std_23)