Coverage Report

Created: 2026-09-14 06:43

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