Coverage Report

Created: 2026-04-29 07:01

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