Coverage Report

Created: 2026-03-12 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmake.h
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#pragma once
4
5
#include "cmConfigure.h" // IWYU pragma: keep
6
7
#include <cstddef>
8
#include <functional>
9
#include <map>
10
#include <memory>
11
#include <set>
12
#include <stack>
13
#include <string>
14
#include <unordered_set>
15
#include <utility>
16
#include <vector>
17
18
#include <cm/string_view>
19
#include <cmext/string_view>
20
21
#include "cmBuildArgs.h"
22
#include "cmDocumentationEntry.h" // IWYU pragma: keep
23
#include "cmGeneratedFileStream.h"
24
#include "cmInstalledFile.h"
25
#include "cmListFileCache.h"
26
#include "cmMessageType.h"
27
#include "cmState.h"
28
#include "cmStateSnapshot.h"
29
#include "cmStateTypes.h"
30
#include "cmValue.h"
31
32
#if !defined(CMAKE_BOOTSTRAP)
33
#  include <cm/optional>
34
35
#  include <cm3p/json/value.h>
36
37
#  include "cmCMakePresetsGraph.h"
38
#  include "cmMakefileProfilingData.h"
39
#endif
40
41
class cmConfigureLog;
42
43
#ifdef CMake_ENABLE_DEBUGGER
44
namespace cmDebugger {
45
class cmDebuggerAdapter;
46
}
47
#endif
48
49
class cmExternalMakefileProjectGeneratorFactory;
50
class cmFileAPI;
51
class cmInstrumentation;
52
class cmFileTimeCache;
53
class cmGlobalGenerator;
54
class cmMakefile;
55
class cmMessenger;
56
class cmVariableWatch;
57
class cmGlobalGeneratorFactory;
58
struct cmBuildOptions;
59
struct cmGlobCacheEntry;
60
61
/** \brief Represents a cmake invocation.
62
 *
63
 * This class represents a cmake invocation. It is the top level class when
64
 * running cmake. Most cmake based GUIs should primarily create an instance
65
 * of this class and communicate with it.
66
 *
67
 * The basic process for a GUI is as follows:
68
 *
69
 * -# Create a cmake instance
70
 * -# Set the Home directories, generator, and cmake command. this
71
 *    can be done using the Set methods or by using SetArgs and passing in
72
 *    command line arguments.
73
 * -# Load the cache by calling LoadCache (duh)
74
 * -# if you are using command line arguments with -D or -C flags then
75
 *    call SetCacheArgs (or if for some other reason you want to modify the
76
 *    cache), do it now.
77
 * -# Finally call Configure
78
 * -# Let the user change values and go back to step 5
79
 * -# call Generate
80
81
 * If your GUI allows the user to change the home directories then
82
 * you must at a minimum redo steps 2 through 7.
83
 */
84
85
class cmake
86
{
87
public:
88
  enum DiagLevel
89
  {
90
    DIAG_IGNORE,
91
    DIAG_WARN,
92
    DIAG_ERROR
93
  };
94
95
  /** \brief Describes the working modes of cmake */
96
  enum WorkingMode
97
  {
98
    NORMAL_MODE, ///< Cmake runs to create project files
99
100
    /** \brief Script mode (started by using -P).
101
     *
102
     * In script mode there is no generator and no cache. Also,
103
     * languages are not enabled, so add_executable and things do
104
     * nothing.
105
     */
106
    SCRIPT_MODE,
107
108
    /** \brief Help mode
109
     *
110
     * Used to print help for things that can only be determined after finding
111
     * the source directory, for example, the list of presets.
112
     */
113
    HELP_MODE,
114
115
    /** \brief A pkg-config like mode
116
     *
117
     * In this mode cmake just searches for a package and prints the results to
118
     * stdout. This is similar to SCRIPT_MODE, but commands like add_library()
119
     * work too, since they may be used e.g. in exported target files. Started
120
     * via --find-package.
121
     */
122
    FIND_PACKAGE_MODE
123
  };
124
125
  enum class CommandFailureAction
126
  {
127
    // When a command fails to execute, treat it as a fatal error.
128
    FATAL_ERROR,
129
130
    // When a command fails to execute, continue execution, but set the exit
131
    // code accordingly.
132
    EXIT_CODE,
133
  };
134
135
  using TraceFormat = cmTraceEnums::TraceOutputFormat;
136
137
  struct GeneratorInfo
138
  {
139
    std::string name;
140
    std::string baseName;
141
    std::string extraName;
142
    bool supportsToolset;
143
    bool supportsPlatform;
144
    std::vector<std::string> supportedPlatforms;
145
    std::string defaultPlatform;
146
    bool isAlias;
147
  };
148
149
  struct FileExtensions
150
  {
151
    bool Test(cm::string_view ext) const
152
0
    {
153
0
      return (this->unordered.find(ext) != this->unordered.end());
154
0
    }
155
156
    std::vector<std::string> ordered;
157
    std::unordered_set<cm::string_view> unordered;
158
  };
159
160
  using InstalledFilesMap = std::map<std::string, cmInstalledFile>;
161
162
  static int const NO_BUILD_PARALLEL_LEVEL =
163
    cmBuildArgs::NO_BUILD_PARALLEL_LEVEL;
164
  static int const DEFAULT_BUILD_PARALLEL_LEVEL =
165
    cmBuildArgs::DEFAULT_BUILD_PARALLEL_LEVEL;
166
167
  /// Default constructor
168
  cmake(cmState::Role role,
169
        cmState::TryCompile isTryCompile = cmState::TryCompile::No);
170
  /// Destructor
171
  ~cmake();
172
173
  cmake(cmake const&) = delete;
174
  cmake& operator=(cmake const&) = delete;
175
176
#if !defined(CMAKE_BOOTSTRAP)
177
  Json::Value ReportVersionJson() const;
178
  Json::Value ReportCapabilitiesJson() const;
179
#endif
180
  std::string ReportCapabilities() const;
181
182
  /**
183
   * Set the home directory from `-S` or from a known location
184
   * that contains a CMakeLists.txt. Will generate warnings
185
   * when overriding an existing source directory.
186
   *
187
   *  |    args           | src dir| warning        |
188
   *  | ----------------- | ------ | -------------- |
189
   *  | `dirA dirA`       | dirA   | N/A            |
190
   *  | `-S dirA -S dirA` | dirA   | N/A            |
191
   *  | `-S dirA -S dirB` | dirB   | Ignoring dirA  |
192
   *  | `-S dirA dirB`    | dirB   | Ignoring dirA  |
193
   *  | `dirA -S dirB`    | dirB   | Ignoring dirA  |
194
   *  | `dirA dirB`       | dirB   | Ignoring dirA  |
195
   */
196
  void SetHomeDirectoryViaCommandLine(std::string const& path);
197
198
  //@{
199
  /**
200
   * Set/Get the home directory (or output directory) in the project. The
201
   * home directory is the top directory of the project. It is the
202
   * path-to-source cmake was run with.
203
   */
204
  void SetHomeDirectory(std::string const& dir);
205
  std::string const& GetHomeDirectory() const;
206
  void SetHomeOutputDirectory(std::string const& dir);
207
  std::string const& GetHomeOutputDirectory() const;
208
  //@}
209
210
  /**
211
   * Working directory at CMake launch
212
   */
213
  std::string const& GetCMakeWorkingDirectory() const
214
0
  {
215
0
    return this->CMakeWorkingDirectory;
216
0
  }
217
218
  /**
219
   * Handle a command line invocation of cmake.
220
   */
221
  int Run(std::vector<std::string> const& args)
222
0
  {
223
0
    return this->Run(args, false);
224
0
  }
225
  int Run(std::vector<std::string> const& args, bool noconfigure);
226
227
  /**
228
   * Run the global generator Generate step.
229
   */
230
  int Generate();
231
232
  /**
233
   * Configure the cmMakefiles. This routine will create a GlobalGenerator if
234
   * one has not already been set. It will then Call Configure on the
235
   * GlobalGenerator. This in turn will read in an process all the CMakeList
236
   * files for the tree. It will not produce any actual Makefiles, or
237
   * workspaces. Generate does that.  */
238
  int Configure();
239
  int ActualConfigure();
240
241
  //! Break up a line like VAR:type="value" into var, type and value
242
  static bool ParseCacheEntry(std::string const& entry, std::string& var,
243
                              std::string& value,
244
                              cmStateEnums::CacheEntryType& type);
245
246
  int LoadCache();
247
  bool LoadCache(std::string const& path);
248
  bool LoadCache(std::string const& path, bool internal,
249
                 std::set<std::string>& excludes,
250
                 std::set<std::string>& includes);
251
  bool SaveCache(std::string const& path);
252
  bool DeleteCache(std::string const& path);
253
  void PreLoadCMakeFiles();
254
255
  //! Create a GlobalGenerator
256
  std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator(
257
    std::string const& name);
258
259
  //! Create a GlobalGenerator and set it as our own
260
  bool CreateAndSetGlobalGenerator(std::string const& name);
261
262
#ifndef CMAKE_BOOTSTRAP
263
  //! Print list of configure presets
264
  void PrintPresetList(cmCMakePresetsGraph const& graph) const;
265
#endif
266
267
  //! Return the global generator assigned to this instance of cmake
268
  cmGlobalGenerator* GetGlobalGenerator()
269
1
  {
270
1
    return this->GlobalGenerator.get();
271
1
  }
272
  //! Return the global generator assigned to this instance of cmake, const
273
  cmGlobalGenerator const* GetGlobalGenerator() const
274
0
  {
275
0
    return this->GlobalGenerator.get();
276
0
  }
277
278
  //! Return the full path to where the CMakeCache.txt file should be.
279
  static std::string FindCacheFile(std::string const& binaryDir);
280
281
  //! Return the global generator assigned to this instance of cmake
282
  void SetGlobalGenerator(std::unique_ptr<cmGlobalGenerator>);
283
284
  //! Get the names of the current registered generators
285
  void GetRegisteredGenerators(std::vector<GeneratorInfo>& generators) const;
286
287
  //! Set the name of the selected generator-specific instance.
288
  void SetGeneratorInstance(std::string const& instance)
289
0
  {
290
0
    this->GeneratorInstance = instance;
291
0
    this->GeneratorInstanceSet = true;
292
0
  }
293
294
  //! Set the name of the selected generator-specific platform.
295
  void SetGeneratorPlatform(std::string const& ts)
296
0
  {
297
0
    this->GeneratorPlatform = ts;
298
0
    this->GeneratorPlatformSet = true;
299
0
  }
300
301
  //! Set the name of the selected generator-specific toolset.
302
  void SetGeneratorToolset(std::string const& ts)
303
0
  {
304
0
    this->GeneratorToolset = ts;
305
0
    this->GeneratorToolsetSet = true;
306
0
  }
307
308
  //! Set the name of the graphviz file.
309
0
  void SetGraphVizFile(std::string const& ts) { this->GraphVizFile = ts; }
310
311
  bool IsAKnownSourceExtension(cm::string_view ext) const
312
0
  {
313
0
    return this->CLikeSourceFileExtensions.Test(ext) ||
314
0
      this->CudaFileExtensions.Test(ext) ||
315
0
      this->FortranFileExtensions.Test(ext) ||
316
0
      this->HipFileExtensions.Test(ext) || this->ISPCFileExtensions.Test(ext);
317
0
  }
318
319
  bool IsACLikeSourceExtension(cm::string_view ext) const
320
0
  {
321
0
    return this->CLikeSourceFileExtensions.Test(ext);
322
0
  }
323
324
  bool IsAKnownExtension(cm::string_view ext) const
325
0
  {
326
0
    return this->IsAKnownSourceExtension(ext) || this->IsAHeaderExtension(ext);
327
0
  }
328
329
  std::vector<std::string> GetAllExtensions() const;
330
331
  std::vector<std::string> const& GetHeaderExtensions() const
332
0
  {
333
0
    return this->HeaderFileExtensions.ordered;
334
0
  }
335
336
  bool IsAHeaderExtension(cm::string_view ext) const
337
0
  {
338
0
    return this->HeaderFileExtensions.Test(ext);
339
0
  }
340
341
  // Strips the extension (if present and known) from a filename
342
  std::string StripExtension(std::string const& file) const;
343
344
  /**
345
   * Given a variable name, return its value (as a string).
346
   */
347
  cmValue GetCacheDefinition(std::string const&) const;
348
  //! Add an entry into the cache
349
  void AddCacheEntry(std::string const& key, std::string const& value,
350
                     std::string const& helpString, int type)
351
3
  {
352
3
    this->AddCacheEntry(key, cmValue{ value }, cmValue{ helpString }, type);
353
3
  }
354
  void AddCacheEntry(std::string const& key, cmValue value,
355
                     std::string const& helpString, int type)
356
0
  {
357
0
    this->AddCacheEntry(key, value, cmValue{ helpString }, type);
358
0
  }
359
  void AddCacheEntry(std::string const& key, cmValue value, cmValue helpString,
360
                     int type);
361
362
  bool DoWriteGlobVerifyTarget() const;
363
  std::string const& GetGlobVerifyScript() const;
364
  std::string const& GetGlobVerifyStamp() const;
365
  void AddGlobCacheEntry(cmGlobCacheEntry const& entry,
366
                         std::string const& variable,
367
                         cmListFileBacktrace const& bt);
368
  std::vector<cmGlobCacheEntry> GetGlobCacheEntries() const;
369
370
  /**
371
   * Get the system information and write it to the file specified
372
   */
373
  int GetSystemInformation(std::vector<std::string>&);
374
375
  //! Parse environment variables
376
  void LoadEnvironmentPresets();
377
378
  //! Parse command line arguments
379
  void SetArgs(std::vector<std::string> const& args);
380
381
  //! Is this cmake running as a result of a TRY_COMPILE command
382
  bool GetIsInTryCompile() const;
383
384
#ifndef CMAKE_BOOTSTRAP
385
  void SetWarningFromPreset(std::string const& name,
386
                            cm::optional<bool> warning,
387
                            cm::optional<bool> error);
388
  void ProcessPresetVariables();
389
  void PrintPresetVariables();
390
  void ProcessPresetEnvironment();
391
  void PrintPresetEnvironment();
392
#endif
393
394
  //! Parse command line arguments that might set cache values
395
  bool SetCacheArgs(std::vector<std::string> const&);
396
397
  void ProcessCacheArg(std::string const& var, std::string const& value,
398
                       cmStateEnums::CacheEntryType type);
399
400
  using ProgressCallbackType = std::function<void(std::string const&, float)>;
401
  /**
402
   *  Set the function used by GUIs to receive progress updates
403
   *  Function gets passed: message as a const char*, a progress
404
   *  amount ranging from 0 to 1.0 and client data. The progress
405
   *  number provided may be negative in cases where a message is
406
   *  to be displayed without any progress percentage.
407
   */
408
  void SetProgressCallback(ProgressCallbackType f);
409
410
  //! this is called by generators to update the progress
411
  void UpdateProgress(std::string const& msg, float prog);
412
413
#if !defined(CMAKE_BOOTSTRAP)
414
  //! Get the variable watch object
415
12
  cmVariableWatch* GetVariableWatch() { return this->VariableWatch.get(); }
416
#endif
417
418
  std::vector<cmDocumentationEntry> GetGeneratorsDocumentation();
419
420
  //! Set/Get a property of this target file
421
  void SetProperty(std::string const& prop, cmValue value);
422
  void SetProperty(std::string const& prop, std::nullptr_t)
423
0
  {
424
0
    this->SetProperty(prop, cmValue{ nullptr });
425
0
  }
426
  void SetProperty(std::string const& prop, std::string const& value)
427
0
  {
428
0
    this->SetProperty(prop, cmValue(value));
429
0
  }
430
  void AppendProperty(std::string const& prop, std::string const& value,
431
                      bool asString = false);
432
  cmValue GetProperty(std::string const& prop);
433
  bool GetPropertyAsBool(std::string const& prop);
434
435
  //! Get or create an cmInstalledFile instance and return a pointer to it
436
  cmInstalledFile* GetOrCreateInstalledFile(cmMakefile* mf,
437
                                            std::string const& name);
438
439
  cmInstalledFile const* GetInstalledFile(std::string const& name) const;
440
441
  InstalledFilesMap const& GetInstalledFiles() const
442
0
  {
443
0
    return this->InstalledFiles;
444
0
  }
445
446
  //! Do all the checks before running configure
447
  int DoPreConfigureChecks();
448
449
  bool RoleSupportsExitCode() const;
450
451
  CommandFailureAction GetCommandFailureAction() const;
452
453
  //! Debug the try compile stuff by not deleting the files
454
0
  bool GetDebugTryCompile() const { return this->DebugTryCompile; }
455
0
  void DebugTryCompileOn() { this->DebugTryCompile = true; }
456
457
  /**
458
   * Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
459
   */
460
  int AddCMakePaths();
461
462
  /**
463
   * Get the file comparison class
464
   */
465
0
  cmFileTimeCache* GetFileTimeCache() { return this->FileTimeCache.get(); }
466
467
0
  bool WasLogLevelSetViaCLI() const { return this->LogLevelWasSetViaCLI; }
468
469
  //! Get the selected log level for `message()` commands during the cmake run.
470
3
  Message::LogLevel GetLogLevel() const { return this->MessageLogLevel; }
471
0
  void SetLogLevel(Message::LogLevel level) { this->MessageLogLevel = level; }
472
  static Message::LogLevel StringToLogLevel(cm::string_view levelStr);
473
  static std::string LogLevelToString(Message::LogLevel level);
474
  static TraceFormat StringToTraceFormat(std::string const& levelStr);
475
476
  bool HasCheckInProgress() const
477
0
  {
478
0
    return !this->CheckInProgressMessages.empty();
479
0
  }
480
  std::size_t GetCheckInProgressSize() const
481
0
  {
482
0
    return this->CheckInProgressMessages.size();
483
0
  }
484
  std::string GetTopCheckInProgressMessage()
485
0
  {
486
0
    auto message = this->CheckInProgressMessages.back();
487
0
    this->CheckInProgressMessages.pop_back();
488
0
    return message;
489
0
  }
490
  void PushCheckInProgressMessage(std::string message)
491
0
  {
492
0
    this->CheckInProgressMessages.emplace_back(std::move(message));
493
0
  }
494
  std::vector<std::string> const& GetCheckInProgressMessages() const
495
0
  {
496
0
    return this->CheckInProgressMessages;
497
0
  }
498
499
  //! Should `message` command display context.
500
0
  bool GetShowLogContext() const { return this->LogContext; }
501
0
  void SetShowLogContext(bool b) { this->LogContext = b; }
502
503
  //! Do we want debug output during the cmake run.
504
0
  bool GetDebugOutput() const { return this->DebugOutput; }
505
0
  void SetDebugOutputOn(bool b) { this->DebugOutput = b; }
506
507
  //! Do we want debug output from the find commands during the cmake run.
508
0
  bool GetDebugFindOutput() const { return this->DebugFindOutput; }
509
  bool GetDebugFindOutput(std::string const& var) const;
510
  bool GetDebugFindPkgOutput(std::string const& pkg) const;
511
0
  void SetDebugFindOutput(bool b) { this->DebugFindOutput = b; }
512
  void SetDebugFindOutputPkgs(std::string const& args);
513
  void SetDebugFindOutputVars(std::string const& args);
514
515
  //! Do we want trace output during the cmake run.
516
  bool GetTrace() const
517
1
  {
518
1
    return this->Trace || !this->cmakeLangTraceCmdStack.empty();
519
1
  }
520
0
  void SetTrace(bool b) { this->Trace = b; }
521
  void PushTraceCmd(bool expandFlag)
522
0
  {
523
0
    this->cmakeLangTraceCmdStack.emplace(expandFlag);
524
0
  }
525
  bool PopTraceCmd();
526
  bool GetTraceExpand() const
527
0
  {
528
0
    return this->TraceExpand ||
529
0
      (!this->cmakeLangTraceCmdStack.empty() &&
530
0
       this->cmakeLangTraceCmdStack.top());
531
0
  }
532
0
  void SetTraceExpand(bool b) { this->TraceExpand = b; }
533
0
  TraceFormat GetTraceFormat() const { return this->TraceFormatVar; }
534
0
  void SetTraceFormat(TraceFormat f) { this->TraceFormatVar = f; }
535
  void AddTraceSource(std::string const& file)
536
0
  {
537
0
    this->TraceOnlyThisSources.push_back(file);
538
0
  }
539
  std::vector<std::string> const& GetTraceSources() const
540
0
  {
541
0
    return this->TraceOnlyThisSources;
542
0
  }
543
  cmGeneratedFileStream& GetTraceFile()
544
0
  {
545
0
    if (this->TraceRedirect) {
546
0
      return this->TraceRedirect->GetTraceFile();
547
0
    }
548
0
    return this->TraceFile;
549
0
  }
550
  void SetTraceFile(std::string const& file);
551
  void PrintTraceFormatVersion();
552
553
#ifndef CMAKE_BOOTSTRAP
554
0
  cmConfigureLog* GetConfigureLog() const { return this->ConfigureLog.get(); }
555
#endif
556
557
  //! Use trace from another ::cmake instance.
558
  void SetTraceRedirect(cmake* other);
559
560
0
  bool GetWarnUninitialized() const { return this->WarnUninitialized; }
561
0
  void SetWarnUninitialized(bool b) { this->WarnUninitialized = b; }
562
0
  bool GetWarnUnusedCli() const { return this->WarnUnusedCli; }
563
0
  void SetWarnUnusedCli(bool b) { this->WarnUnusedCli = b; }
564
1
  bool GetCheckSystemVars() const { return this->CheckSystemVars; }
565
0
  void SetCheckSystemVars(bool b) { this->CheckSystemVars = b; }
566
  bool GetIgnoreCompileWarningAsError() const
567
0
  {
568
0
    return this->IgnoreCompileWarningAsError;
569
0
  }
570
  void SetIgnoreCompileWarningAsError(bool b)
571
0
  {
572
0
    this->IgnoreCompileWarningAsError = b;
573
0
  }
574
  bool GetIgnoreLinkWarningAsError() const
575
0
  {
576
0
    return this->IgnoreLinkWarningAsError;
577
0
  }
578
  void SetIgnoreLinkWarningAsError(bool b)
579
0
  {
580
0
    this->IgnoreLinkWarningAsError = b;
581
0
  }
582
583
  void MarkCliAsUsed(std::string const& variable);
584
585
  /** Get the list of configurations (in upper case) considered to be
586
      debugging configurations.*/
587
  std::vector<std::string> GetDebugConfigs();
588
589
  void SetCMakeEditCommand(std::string const& s)
590
0
  {
591
0
    this->CMakeEditCommand = s;
592
0
  }
593
  std::string const& GetCMakeEditCommand() const
594
0
  {
595
0
    return this->CMakeEditCommand;
596
0
  }
597
598
2
  cmMessenger* GetMessenger() const { return this->Messenger.get(); }
599
600
#ifndef CMAKE_BOOTSTRAP
601
  /// Get the SARIF file path if set manually for this run
602
  cm::optional<std::string> GetSarifFilePath() const
603
2
  {
604
2
    return (this->SarifFileOutput ? cm::make_optional(this->SarifFilePath)
605
2
                                  : cm::nullopt);
606
2
  }
607
#endif
608
609
  /**
610
   * Get the state of the suppression of developer (author) warnings.
611
   * Returns false, by default, if developer warnings should be shown, true
612
   * otherwise.
613
   */
614
  bool GetSuppressDevWarnings() const;
615
  /**
616
   * Set the state of the suppression of developer (author) warnings.
617
   */
618
  void SetSuppressDevWarnings(bool v);
619
620
  /**
621
   * Get the state of the suppression of deprecated warnings.
622
   * Returns false, by default, if deprecated warnings should be shown, true
623
   * otherwise.
624
   */
625
  bool GetSuppressDeprecatedWarnings() const;
626
  /**
627
   * Set the state of the suppression of deprecated warnings.
628
   */
629
  void SetSuppressDeprecatedWarnings(bool v);
630
631
  /**
632
   * Get the state of treating developer (author) warnings as errors.
633
   * Returns false, by default, if warnings should not be treated as errors,
634
   * true otherwise.
635
   */
636
  bool GetDevWarningsAsErrors() const;
637
  /**
638
   * Set the state of treating developer (author) warnings as errors.
639
   */
640
  void SetDevWarningsAsErrors(bool v);
641
642
  /**
643
   * Get the state of treating deprecated warnings as errors.
644
   * Returns false, by default, if warnings should not be treated as errors,
645
   * true otherwise.
646
   */
647
  bool GetDeprecatedWarningsAsErrors() const;
648
  /**
649
   * Set the state of treating developer (author) warnings as errors.
650
   */
651
  void SetDeprecatedWarningsAsErrors(bool v);
652
653
  /** Display a message to the user.  */
654
  void IssueMessage(
655
    MessageType t, std::string const& text,
656
    cmListFileBacktrace const& backtrace = cmListFileBacktrace()) const;
657
658
  //! run the --build option
659
  int Build(cmBuildArgs buildArgs, std::vector<std::string> targets,
660
            std::vector<std::string> nativeOptions,
661
            cmBuildOptions& buildOptions, std::string const& presetName,
662
            bool listPresets, std::vector<std::string> const& args);
663
664
  enum class DryRun
665
  {
666
    No,
667
    Yes,
668
  };
669
670
  //! run the --open option
671
  bool Open(std::string const& dir, DryRun dryRun);
672
673
  //! run the --workflow option
674
  enum class WorkflowListPresets
675
  {
676
    No,
677
    Yes,
678
  };
679
  enum class WorkflowFresh
680
  {
681
    No,
682
    Yes,
683
  };
684
  int Workflow(std::string const& presetName, WorkflowListPresets listPresets,
685
               WorkflowFresh fresh);
686
687
  void UnwatchUnusedCli(std::string const& var);
688
  void WatchUnusedCli(std::string const& var);
689
690
#if !defined(CMAKE_BOOTSTRAP)
691
0
  cmFileAPI* GetFileAPI() const { return this->FileAPI.get(); }
692
  cmInstrumentation* GetInstrumentation() const
693
0
  {
694
0
    return this->Instrumentation.get();
695
0
  }
696
#endif
697
  void InitializeFileAPI();
698
  void InitializeInstrumentation();
699
700
0
  bool GetInInitialCache() const { return this->InInitialCache; }
701
0
  void SetInInitialCache(bool v) { this->InInitialCache = v; }
702
703
49
  cmState* GetState() const { return this->State.get(); }
704
  void SetCurrentSnapshot(cmStateSnapshot const& snapshot)
705
0
  {
706
0
    this->CurrentSnapshot = snapshot;
707
0
  }
708
1
  cmStateSnapshot GetCurrentSnapshot() const { return this->CurrentSnapshot; }
709
710
0
  bool GetRegenerateDuringBuild() const { return this->RegenerateDuringBuild; }
711
712
  void SetCMakeListName(std::string const& name);
713
  std::string GetCMakeListFile(std::string const& dir) const;
714
715
#if !defined(CMAKE_BOOTSTRAP)
716
  cmMakefileProfilingData& GetProfilingOutput();
717
  bool IsProfilingEnabled() const;
718
719
  cm::optional<cmMakefileProfilingData::RAII> CreateProfilingEntry(
720
    std::string const& category, std::string const& name)
721
0
  {
722
0
    return this->CreateProfilingEntry(
723
0
      category, name, []() -> cm::nullopt_t { return cm::nullopt; });
724
0
  }
725
726
  template <typename ArgsFunc>
727
  cm::optional<cmMakefileProfilingData::RAII> CreateProfilingEntry(
728
    std::string const& category, std::string const& name, ArgsFunc&& argsFunc)
729
0
  {
730
0
    if (this->IsProfilingEnabled()) {
731
0
      return cm::make_optional<cmMakefileProfilingData::RAII>(
732
0
        this->GetProfilingOutput(), category, name, argsFunc());
733
0
    }
734
0
    return cm::nullopt;
735
0
  }
Unexecuted instantiation: std::__1::optional<cmMakefileProfilingData::RAII> cmake::CreateProfilingEntry<cmake::CreateProfilingEntry(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::{lambda()#1}>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmake::CreateProfilingEntry(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::{lambda()#1}&&)
Unexecuted instantiation: cmGeneratorExpressionEvaluator.cxx:std::__1::optional<cmMakefileProfilingData::RAII> cmake::CreateProfilingEntry<GeneratorExpressionContent::Evaluate(cm::GenEx::Evaluation*, cmGeneratorExpressionDAGChecker*) const::$_0>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, GeneratorExpressionContent::Evaluate(cm::GenEx::Evaluation*, cmGeneratorExpressionDAGChecker*) const::$_0&&)
Unexecuted instantiation: std::__1::optional<cmMakefileProfilingData::RAII> cmake::CreateProfilingEntry<cmMakefile::CallScope::CallScope(cmMakefile*, cmListFileFunction const&, cmListFileContext const&, cmExecutionStatus&)::{lambda()#1}>(cmMakefile::CallScope::CallScope(cmMakefile*, cmListFileFunction const&, cmListFileContext const&, cmExecutionStatus&)::{lambda()#1}::basic_string<char, cmMakefile::CallScope::CallScope(cmMakefile*, cmListFileFunction const&, cmListFileContext const&, cmExecutionStatus&)::{lambda()#1}::char_traits<char>, cmMakefile::CallScope::CallScope(cmMakefile*, cmListFileFunction const&, cmListFileContext const&, cmExecutionStatus&)::{lambda()#1}::allocator<char> > const&, cmMakefile::CallScope::CallScope(cmMakefile*, cmListFileFunction const&, cmListFileContext const&, cmExecutionStatus&)::{lambda()#1}::basic_string<char, cmMakefile::CallScope::CallScope(cmMakefile*, cmListFileFunction const&, cmListFileContext const&, cmExecutionStatus&)::{lambda()#1}::char_traits<char>, cmMakefile::CallScope::CallScope(cmMakefile*, cmListFileFunction const&, cmListFileContext const&, cmExecutionStatus&)::{lambda()#1}::allocator<char> > const, cmMakefile::CallScope::CallScope(cmMakefile*, cmListFileFunction const&, cmListFileContext const&, cmExecutionStatus&)::{lambda()#1}&&)
736
#endif
737
738
#ifdef CMake_ENABLE_DEBUGGER
739
1
  bool GetDebuggerOn() const { return this->DebuggerOn; }
740
0
  std::string GetDebuggerPipe() const { return this->DebuggerPipe; }
741
  std::string GetDebuggerDapLogFile() const
742
0
  {
743
0
    return this->DebuggerDapLogFile;
744
0
  }
745
0
  void SetDebuggerOn(bool b) { this->DebuggerOn = b; }
746
  bool StartDebuggerIfEnabled();
747
  void StopDebuggerIfNeeded(int exitCode);
748
  std::shared_ptr<cmDebugger::cmDebuggerAdapter> GetDebugAdapter()
749
    const noexcept
750
2
  {
751
2
    return this->DebugAdapter;
752
2
  }
753
#endif
754
755
protected:
756
  void RunCheckForUnusedVariables();
757
  int HandleDeleteCacheVariables(std::string const& var);
758
759
  using RegisteredGeneratorsVector =
760
    std::vector<std::unique_ptr<cmGlobalGeneratorFactory>>;
761
  RegisteredGeneratorsVector Generators;
762
  using RegisteredExtraGeneratorsVector =
763
    std::vector<cmExternalMakefileProjectGeneratorFactory*>;
764
  RegisteredExtraGeneratorsVector ExtraGenerators;
765
  void AddScriptingCommands() const;
766
  void AddProjectCommands() const;
767
  void AddDefaultGenerators();
768
  void AddDefaultExtraGenerators();
769
770
  std::map<std::string, DiagLevel> DiagLevels;
771
  std::string GeneratorInstance;
772
  std::string GeneratorPlatform;
773
  std::string GeneratorToolset;
774
  cm::optional<std::string> IntermediateDirStrategy;
775
  cm::optional<std::string> AutogenIntermediateDirStrategy;
776
  bool GeneratorInstanceSet = false;
777
  bool GeneratorPlatformSet = false;
778
  bool GeneratorToolsetSet = false;
779
780
  //! read in a cmake list file to initialize the cache
781
  void ReadListFile(std::vector<std::string> const& args,
782
                    std::string const& path);
783
  bool FindPackage(std::vector<std::string> const& args);
784
785
  //! Check if CMAKE_CACHEFILE_DIR is set. If it is not, delete the log file.
786
  ///  If it is set, truncate it to 50kb
787
  void TruncateOutputLog(char const* fname);
788
789
  /**
790
   * Method called to check build system integrity at build time.
791
   * Returns 1 if CMake should rerun and 0 otherwise.
792
   */
793
  int CheckBuildSystem();
794
795
  bool SetDirectoriesFromFile(std::string const& arg);
796
797
  //! Make sure all commands are what they say they are and there is no
798
  /// macros.
799
  void CleanupCommandsAndMacros();
800
801
  void GenerateGraphViz(std::string const& fileName) const;
802
803
private:
804
  std::vector<std::string> cmdArgs;
805
  std::string CMakeWorkingDirectory;
806
  ProgressCallbackType ProgressCallback;
807
  bool DebugOutput = false;
808
  bool DebugFindOutput = false;
809
  // Elements of `cmakeLangTraceCmdStack` are "trace requests" pushed
810
  // by `cmake_language(TRACE ON [EXPAND])` and a boolean value is
811
  // a state of a given `EXPAND` option.
812
  std::stack<bool> cmakeLangTraceCmdStack;
813
  bool Trace = false;
814
  bool TraceExpand = false;
815
  TraceFormat TraceFormatVar = TraceFormat::Human;
816
  cmGeneratedFileStream TraceFile;
817
  cmake* TraceRedirect = nullptr;
818
#ifndef CMAKE_BOOTSTRAP
819
  std::unique_ptr<cmConfigureLog> ConfigureLog;
820
#endif
821
  bool WarnUninitialized = false;
822
  bool WarnUnusedCli = true;
823
  bool CheckSystemVars = false;
824
  bool IgnoreCompileWarningAsError = false;
825
  bool IgnoreLinkWarningAsError = false;
826
  std::map<std::string, bool> UsedCliVariables;
827
  std::string CMakeEditCommand;
828
  std::string CXXEnvironment;
829
  std::string CCEnvironment;
830
  std::string CheckBuildSystemArgument;
831
  std::string CheckStampFile;
832
  std::string CheckStampList;
833
  std::string VSSolutionFile;
834
  std::string EnvironmentGenerator;
835
  FileExtensions CLikeSourceFileExtensions;
836
  FileExtensions HeaderFileExtensions;
837
  FileExtensions CudaFileExtensions;
838
  FileExtensions ISPCFileExtensions;
839
  FileExtensions FortranFileExtensions;
840
  FileExtensions HipFileExtensions;
841
  bool ClearBuildSystem = false;
842
  bool DebugTryCompile = false;
843
  bool FreshCache = false;
844
  bool RegenerateDuringBuild = false;
845
  bool InInitialCache = false;
846
  std::string CMakeListName;
847
  std::unique_ptr<cmFileTimeCache> FileTimeCache;
848
  std::string GraphVizFile;
849
  InstalledFilesMap InstalledFiles;
850
#ifndef CMAKE_BOOTSTRAP
851
  std::map<std::string, cm::optional<cmCMakePresetsGraph::CacheVariable>>
852
    UnprocessedPresetVariables;
853
  std::map<std::string, cm::optional<std::string>>
854
    UnprocessedPresetEnvironment;
855
#endif
856
857
#if !defined(CMAKE_BOOTSTRAP)
858
  std::unique_ptr<cmVariableWatch> VariableWatch;
859
  std::unique_ptr<cmFileAPI> FileAPI;
860
  std::unique_ptr<cmInstrumentation> Instrumentation;
861
#endif
862
863
  std::unique_ptr<cmState> State;
864
  cmStateSnapshot CurrentSnapshot;
865
  std::unique_ptr<cmMessenger> Messenger;
866
867
#ifndef CMAKE_BOOTSTRAP
868
  bool SarifFileOutput = false;
869
  std::string SarifFilePath;
870
#endif
871
872
  std::vector<std::string> TraceOnlyThisSources;
873
874
  std::set<std::string> DebugFindPkgs;
875
  std::set<std::string> DebugFindVars;
876
877
  Message::LogLevel MessageLogLevel = Message::LogLevel::LOG_STATUS;
878
  bool LogLevelWasSetViaCLI = false;
879
  bool LogContext = false;
880
881
  std::vector<std::string> CheckInProgressMessages;
882
883
  std::unique_ptr<cmGlobalGenerator> GlobalGenerator;
884
885
  //! Print a list of valid generators to stderr.
886
  void PrintGeneratorList();
887
888
  std::unique_ptr<cmGlobalGenerator> EvaluateDefaultGlobalGenerator();
889
  void CreateDefaultGlobalGenerator();
890
891
  void AppendGlobalGeneratorsDocumentation(std::vector<cmDocumentationEntry>&);
892
  void AppendExtraGeneratorsDocumentation(std::vector<cmDocumentationEntry>&);
893
894
#if !defined(CMAKE_BOOTSTRAP)
895
  template <typename T>
896
  T const* FindPresetForWorkflow(
897
    cm::static_string_view type,
898
    std::map<std::string, cmCMakePresetsGraph::PresetPair<T>> const& presets,
899
    cmCMakePresetsGraph::WorkflowPreset::WorkflowStep const& step);
900
#endif
901
902
#if !defined(CMAKE_BOOTSTRAP)
903
  std::unique_ptr<cmMakefileProfilingData> ProfilingOutput;
904
#endif
905
906
#ifdef CMake_ENABLE_DEBUGGER
907
  std::shared_ptr<cmDebugger::cmDebuggerAdapter> DebugAdapter;
908
  bool DebuggerOn = false;
909
  std::string DebuggerPipe;
910
  std::string DebuggerDapLogFile;
911
#endif
912
913
  cm::optional<int> ScriptModeExitCode;
914
915
public:
916
0
  bool HasScriptModeExitCode() const { return ScriptModeExitCode.has_value(); }
917
0
  void SetScriptModeExitCode(int code) { ScriptModeExitCode = code; }
918
0
  int GetScriptModeExitCode() const { return ScriptModeExitCode.value_or(-1); }
919
920
  static cmDocumentationEntry CMAKE_STANDARD_OPTIONS_TABLE[19];
921
};
922
923
0
#define FOR_EACH_C90_FEATURE(F) F(c_function_prototypes)
924
925
#define FOR_EACH_C99_FEATURE(F)                                               \
926
0
  F(c_restrict)                                                               \
927
0
  F(c_variadic_macros)
928
929
0
#define FOR_EACH_C11_FEATURE(F) F(c_static_assert)
930
931
#define FOR_EACH_C_FEATURE(F)                                                 \
932
0
  F(c_std_90)                                                                 \
933
0
  F(c_std_99)                                                                 \
934
0
  F(c_std_11)                                                                 \
935
0
  F(c_std_17)                                                                 \
936
0
  F(c_std_23)                                                                 \
937
0
  FOR_EACH_C90_FEATURE(F)                                                     \
938
0
  FOR_EACH_C99_FEATURE(F)                                                     \
939
0
  FOR_EACH_C11_FEATURE(F)
940
941
0
#define FOR_EACH_CXX98_FEATURE(F) F(cxx_template_template_parameters)
942
943
#define FOR_EACH_CXX11_FEATURE(F)                                             \
944
0
  F(cxx_alias_templates)                                                      \
945
0
  F(cxx_alignas)                                                              \
946
0
  F(cxx_alignof)                                                              \
947
0
  F(cxx_attributes)                                                           \
948
0
  F(cxx_auto_type)                                                            \
949
0
  F(cxx_constexpr)                                                            \
950
0
  F(cxx_decltype)                                                             \
951
0
  F(cxx_decltype_incomplete_return_types)                                     \
952
0
  F(cxx_default_function_template_args)                                       \
953
0
  F(cxx_defaulted_functions)                                                  \
954
0
  F(cxx_defaulted_move_initializers)                                          \
955
0
  F(cxx_delegating_constructors)                                              \
956
0
  F(cxx_deleted_functions)                                                    \
957
0
  F(cxx_enum_forward_declarations)                                            \
958
0
  F(cxx_explicit_conversions)                                                 \
959
0
  F(cxx_extended_friend_declarations)                                         \
960
0
  F(cxx_extern_templates)                                                     \
961
0
  F(cxx_final)                                                                \
962
0
  F(cxx_func_identifier)                                                      \
963
0
  F(cxx_generalized_initializers)                                             \
964
0
  F(cxx_inheriting_constructors)                                              \
965
0
  F(cxx_inline_namespaces)                                                    \
966
0
  F(cxx_lambdas)                                                              \
967
0
  F(cxx_local_type_template_args)                                             \
968
0
  F(cxx_long_long_type)                                                       \
969
0
  F(cxx_noexcept)                                                             \
970
0
  F(cxx_nonstatic_member_init)                                                \
971
0
  F(cxx_nullptr)                                                              \
972
0
  F(cxx_override)                                                             \
973
0
  F(cxx_range_for)                                                            \
974
0
  F(cxx_raw_string_literals)                                                  \
975
0
  F(cxx_reference_qualified_functions)                                        \
976
0
  F(cxx_right_angle_brackets)                                                 \
977
0
  F(cxx_rvalue_references)                                                    \
978
0
  F(cxx_sizeof_member)                                                        \
979
0
  F(cxx_static_assert)                                                        \
980
0
  F(cxx_strong_enums)                                                         \
981
0
  F(cxx_thread_local)                                                         \
982
0
  F(cxx_trailing_return_types)                                                \
983
0
  F(cxx_unicode_literals)                                                     \
984
0
  F(cxx_uniform_initialization)                                               \
985
0
  F(cxx_unrestricted_unions)                                                  \
986
0
  F(cxx_user_literals)                                                        \
987
0
  F(cxx_variadic_macros)                                                      \
988
0
  F(cxx_variadic_templates)
989
990
#define FOR_EACH_CXX14_FEATURE(F)                                             \
991
0
  F(cxx_aggregate_default_initializers)                                       \
992
0
  F(cxx_attribute_deprecated)                                                 \
993
0
  F(cxx_binary_literals)                                                      \
994
0
  F(cxx_contextual_conversions)                                               \
995
0
  F(cxx_decltype_auto)                                                        \
996
0
  F(cxx_digit_separators)                                                     \
997
0
  F(cxx_generic_lambdas)                                                      \
998
0
  F(cxx_lambda_init_captures)                                                 \
999
0
  F(cxx_relaxed_constexpr)                                                    \
1000
0
  F(cxx_return_type_deduction)                                                \
1001
0
  F(cxx_variable_templates)
1002
1003
#define FOR_EACH_CXX_FEATURE(F)                                               \
1004
0
  F(cxx_std_98)                                                               \
1005
0
  F(cxx_std_11)                                                               \
1006
0
  F(cxx_std_14)                                                               \
1007
0
  F(cxx_std_17)                                                               \
1008
0
  F(cxx_std_20)                                                               \
1009
0
  F(cxx_std_23)                                                               \
1010
0
  F(cxx_std_26)                                                               \
1011
0
  FOR_EACH_CXX98_FEATURE(F)                                                   \
1012
0
  FOR_EACH_CXX11_FEATURE(F)                                                   \
1013
0
  FOR_EACH_CXX14_FEATURE(F)
1014
1015
#define FOR_EACH_CUDA_FEATURE(F)                                              \
1016
0
  F(cuda_std_03)                                                              \
1017
0
  F(cuda_std_11)                                                              \
1018
0
  F(cuda_std_14)                                                              \
1019
0
  F(cuda_std_17)                                                              \
1020
0
  F(cuda_std_20)                                                              \
1021
0
  F(cuda_std_23)                                                              \
1022
0
  F(cuda_std_26)
1023
1024
#define FOR_EACH_HIP_FEATURE(F)                                               \
1025
0
  F(hip_std_98)                                                               \
1026
0
  F(hip_std_11)                                                               \
1027
0
  F(hip_std_14)                                                               \
1028
0
  F(hip_std_17)                                                               \
1029
0
  F(hip_std_20)                                                               \
1030
0
  F(hip_std_23)                                                               \
1031
0
  F(hip_std_26)