Coverage Report

Created: 2026-02-09 06:05

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
24
  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
49
  cmState* GetState() const { return this->State.get(); }
701
  void SetCurrentSnapshot(cmStateSnapshot const& snapshot)
702
0
  {
703
0
    this->CurrentSnapshot = snapshot;
704
0
  }
705
1
  cmStateSnapshot GetCurrentSnapshot() const { return this->CurrentSnapshot; }
706
707
0
  bool GetRegenerateDuringBuild() const { return this->RegenerateDuringBuild; }
708
709
  void SetCMakeListName(std::string const& name);
710
  std::string GetCMakeListFile(std::string const& dir) const;
711
712
#if !defined(CMAKE_BOOTSTRAP)
713
  cmMakefileProfilingData& GetProfilingOutput();
714
  bool IsProfilingEnabled() const;
715
716
  cm::optional<cmMakefileProfilingData::RAII> CreateProfilingEntry(
717
    std::string const& category, std::string const& name)
718
0
  {
719
0
    return this->CreateProfilingEntry(
720
0
      category, name, []() -> cm::nullopt_t { return cm::nullopt; });
721
0
  }
722
723
  template <typename ArgsFunc>
724
  cm::optional<cmMakefileProfilingData::RAII> CreateProfilingEntry(
725
    std::string const& category, std::string const& name, ArgsFunc&& argsFunc)
726
0
  {
727
0
    if (this->IsProfilingEnabled()) {
728
0
      return cm::make_optional<cmMakefileProfilingData::RAII>(
729
0
        this->GetProfilingOutput(), category, name, argsFunc());
730
0
    }
731
0
    return cm::nullopt;
732
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}&&)
733
#endif
734
735
#ifdef CMake_ENABLE_DEBUGGER
736
1
  bool GetDebuggerOn() const { return this->DebuggerOn; }
737
0
  std::string GetDebuggerPipe() const { return this->DebuggerPipe; }
738
  std::string GetDebuggerDapLogFile() const
739
0
  {
740
0
    return this->DebuggerDapLogFile;
741
0
  }
742
0
  void SetDebuggerOn(bool b) { this->DebuggerOn = b; }
743
  bool StartDebuggerIfEnabled();
744
  void StopDebuggerIfNeeded(int exitCode);
745
  std::shared_ptr<cmDebugger::cmDebuggerAdapter> GetDebugAdapter()
746
    const noexcept
747
2
  {
748
2
    return this->DebugAdapter;
749
2
  }
750
#endif
751
752
protected:
753
  void RunCheckForUnusedVariables();
754
  int HandleDeleteCacheVariables(std::string const& var);
755
756
  using RegisteredGeneratorsVector =
757
    std::vector<std::unique_ptr<cmGlobalGeneratorFactory>>;
758
  RegisteredGeneratorsVector Generators;
759
  using RegisteredExtraGeneratorsVector =
760
    std::vector<cmExternalMakefileProjectGeneratorFactory*>;
761
  RegisteredExtraGeneratorsVector ExtraGenerators;
762
  void AddScriptingCommands() const;
763
  void AddProjectCommands() const;
764
  void AddDefaultGenerators();
765
  void AddDefaultExtraGenerators();
766
767
  std::map<std::string, DiagLevel> DiagLevels;
768
  std::string GeneratorInstance;
769
  std::string GeneratorPlatform;
770
  std::string GeneratorToolset;
771
  cm::optional<std::string> IntermediateDirStrategy;
772
  cm::optional<std::string> AutogenIntermediateDirStrategy;
773
  bool GeneratorInstanceSet = false;
774
  bool GeneratorPlatformSet = false;
775
  bool GeneratorToolsetSet = false;
776
777
  //! read in a cmake list file to initialize the cache
778
  void ReadListFile(std::vector<std::string> const& args,
779
                    std::string const& path);
780
  bool FindPackage(std::vector<std::string> const& args);
781
782
  //! Check if CMAKE_CACHEFILE_DIR is set. If it is not, delete the log file.
783
  ///  If it is set, truncate it to 50kb
784
  void TruncateOutputLog(char const* fname);
785
786
  /**
787
   * Method called to check build system integrity at build time.
788
   * Returns 1 if CMake should rerun and 0 otherwise.
789
   */
790
  int CheckBuildSystem();
791
792
  bool SetDirectoriesFromFile(std::string const& arg);
793
794
  //! Make sure all commands are what they say they are and there is no
795
  /// macros.
796
  void CleanupCommandsAndMacros();
797
798
  void GenerateGraphViz(std::string const& fileName) const;
799
800
private:
801
  std::vector<std::string> cmdArgs;
802
  std::string CMakeWorkingDirectory;
803
  ProgressCallbackType ProgressCallback;
804
  bool DebugOutput = false;
805
  bool DebugFindOutput = false;
806
  // Elements of `cmakeLangTraceCmdStack` are "trace requests" pushed
807
  // by `cmake_language(TRACE ON [EXPAND])` and a boolean value is
808
  // a state of a given `EXPAND` option.
809
  std::stack<bool> cmakeLangTraceCmdStack;
810
  bool Trace = false;
811
  bool TraceExpand = false;
812
  TraceFormat TraceFormatVar = TraceFormat::Human;
813
  cmGeneratedFileStream TraceFile;
814
  cmake* TraceRedirect = nullptr;
815
#ifndef CMAKE_BOOTSTRAP
816
  std::unique_ptr<cmConfigureLog> ConfigureLog;
817
#endif
818
  bool WarnUninitialized = false;
819
  bool WarnUnusedCli = true;
820
  bool CheckSystemVars = false;
821
  bool IgnoreCompileWarningAsError = false;
822
  bool IgnoreLinkWarningAsError = false;
823
  std::map<std::string, bool> UsedCliVariables;
824
  std::string CMakeEditCommand;
825
  std::string CXXEnvironment;
826
  std::string CCEnvironment;
827
  std::string CheckBuildSystemArgument;
828
  std::string CheckStampFile;
829
  std::string CheckStampList;
830
  std::string VSSolutionFile;
831
  std::string EnvironmentGenerator;
832
  FileExtensions CLikeSourceFileExtensions;
833
  FileExtensions HeaderFileExtensions;
834
  FileExtensions CudaFileExtensions;
835
  FileExtensions ISPCFileExtensions;
836
  FileExtensions FortranFileExtensions;
837
  FileExtensions HipFileExtensions;
838
  bool ClearBuildSystem = false;
839
  bool DebugTryCompile = false;
840
  bool FreshCache = false;
841
  bool RegenerateDuringBuild = false;
842
  std::string CMakeListName;
843
  std::unique_ptr<cmFileTimeCache> FileTimeCache;
844
  std::string GraphVizFile;
845
  InstalledFilesMap InstalledFiles;
846
#ifndef CMAKE_BOOTSTRAP
847
  std::map<std::string, cm::optional<cmCMakePresetsGraph::CacheVariable>>
848
    UnprocessedPresetVariables;
849
  std::map<std::string, cm::optional<std::string>>
850
    UnprocessedPresetEnvironment;
851
#endif
852
853
#if !defined(CMAKE_BOOTSTRAP)
854
  std::unique_ptr<cmVariableWatch> VariableWatch;
855
  std::unique_ptr<cmFileAPI> FileAPI;
856
  std::unique_ptr<cmInstrumentation> Instrumentation;
857
#endif
858
859
  std::unique_ptr<cmState> State;
860
  cmStateSnapshot CurrentSnapshot;
861
  std::unique_ptr<cmMessenger> Messenger;
862
863
#ifndef CMAKE_BOOTSTRAP
864
  bool SarifFileOutput = false;
865
  std::string SarifFilePath;
866
#endif
867
868
  std::vector<std::string> TraceOnlyThisSources;
869
870
  std::set<std::string> DebugFindPkgs;
871
  std::set<std::string> DebugFindVars;
872
873
  Message::LogLevel MessageLogLevel = Message::LogLevel::LOG_STATUS;
874
  bool LogLevelWasSetViaCLI = false;
875
  bool LogContext = false;
876
877
  std::vector<std::string> CheckInProgressMessages;
878
879
  std::unique_ptr<cmGlobalGenerator> GlobalGenerator;
880
881
  //! Print a list of valid generators to stderr.
882
  void PrintGeneratorList();
883
884
  std::unique_ptr<cmGlobalGenerator> EvaluateDefaultGlobalGenerator();
885
  void CreateDefaultGlobalGenerator();
886
887
  void AppendGlobalGeneratorsDocumentation(std::vector<cmDocumentationEntry>&);
888
  void AppendExtraGeneratorsDocumentation(std::vector<cmDocumentationEntry>&);
889
890
#if !defined(CMAKE_BOOTSTRAP)
891
  template <typename T>
892
  T const* FindPresetForWorkflow(
893
    cm::static_string_view type,
894
    std::map<std::string, cmCMakePresetsGraph::PresetPair<T>> const& presets,
895
    cmCMakePresetsGraph::WorkflowPreset::WorkflowStep const& step);
896
#endif
897
898
#if !defined(CMAKE_BOOTSTRAP)
899
  std::unique_ptr<cmMakefileProfilingData> ProfilingOutput;
900
#endif
901
902
#ifdef CMake_ENABLE_DEBUGGER
903
  std::shared_ptr<cmDebugger::cmDebuggerAdapter> DebugAdapter;
904
  bool DebuggerOn = false;
905
  std::string DebuggerPipe;
906
  std::string DebuggerDapLogFile;
907
#endif
908
909
  cm::optional<int> ScriptModeExitCode;
910
911
public:
912
0
  bool HasScriptModeExitCode() const { return ScriptModeExitCode.has_value(); }
913
0
  void SetScriptModeExitCode(int code) { ScriptModeExitCode = code; }
914
0
  int GetScriptModeExitCode() const { return ScriptModeExitCode.value_or(-1); }
915
916
  static cmDocumentationEntry CMAKE_STANDARD_OPTIONS_TABLE[19];
917
};
918
919
0
#define FOR_EACH_C90_FEATURE(F) F(c_function_prototypes)
920
921
#define FOR_EACH_C99_FEATURE(F)                                               \
922
0
  F(c_restrict)                                                               \
923
0
  F(c_variadic_macros)
924
925
0
#define FOR_EACH_C11_FEATURE(F) F(c_static_assert)
926
927
#define FOR_EACH_C_FEATURE(F)                                                 \
928
0
  F(c_std_90)                                                                 \
929
0
  F(c_std_99)                                                                 \
930
0
  F(c_std_11)                                                                 \
931
0
  F(c_std_17)                                                                 \
932
0
  F(c_std_23)                                                                 \
933
0
  FOR_EACH_C90_FEATURE(F)                                                     \
934
0
  FOR_EACH_C99_FEATURE(F)                                                     \
935
0
  FOR_EACH_C11_FEATURE(F)
936
937
0
#define FOR_EACH_CXX98_FEATURE(F) F(cxx_template_template_parameters)
938
939
#define FOR_EACH_CXX11_FEATURE(F)                                             \
940
0
  F(cxx_alias_templates)                                                      \
941
0
  F(cxx_alignas)                                                              \
942
0
  F(cxx_alignof)                                                              \
943
0
  F(cxx_attributes)                                                           \
944
0
  F(cxx_auto_type)                                                            \
945
0
  F(cxx_constexpr)                                                            \
946
0
  F(cxx_decltype)                                                             \
947
0
  F(cxx_decltype_incomplete_return_types)                                     \
948
0
  F(cxx_default_function_template_args)                                       \
949
0
  F(cxx_defaulted_functions)                                                  \
950
0
  F(cxx_defaulted_move_initializers)                                          \
951
0
  F(cxx_delegating_constructors)                                              \
952
0
  F(cxx_deleted_functions)                                                    \
953
0
  F(cxx_enum_forward_declarations)                                            \
954
0
  F(cxx_explicit_conversions)                                                 \
955
0
  F(cxx_extended_friend_declarations)                                         \
956
0
  F(cxx_extern_templates)                                                     \
957
0
  F(cxx_final)                                                                \
958
0
  F(cxx_func_identifier)                                                      \
959
0
  F(cxx_generalized_initializers)                                             \
960
0
  F(cxx_inheriting_constructors)                                              \
961
0
  F(cxx_inline_namespaces)                                                    \
962
0
  F(cxx_lambdas)                                                              \
963
0
  F(cxx_local_type_template_args)                                             \
964
0
  F(cxx_long_long_type)                                                       \
965
0
  F(cxx_noexcept)                                                             \
966
0
  F(cxx_nonstatic_member_init)                                                \
967
0
  F(cxx_nullptr)                                                              \
968
0
  F(cxx_override)                                                             \
969
0
  F(cxx_range_for)                                                            \
970
0
  F(cxx_raw_string_literals)                                                  \
971
0
  F(cxx_reference_qualified_functions)                                        \
972
0
  F(cxx_right_angle_brackets)                                                 \
973
0
  F(cxx_rvalue_references)                                                    \
974
0
  F(cxx_sizeof_member)                                                        \
975
0
  F(cxx_static_assert)                                                        \
976
0
  F(cxx_strong_enums)                                                         \
977
0
  F(cxx_thread_local)                                                         \
978
0
  F(cxx_trailing_return_types)                                                \
979
0
  F(cxx_unicode_literals)                                                     \
980
0
  F(cxx_uniform_initialization)                                               \
981
0
  F(cxx_unrestricted_unions)                                                  \
982
0
  F(cxx_user_literals)                                                        \
983
0
  F(cxx_variadic_macros)                                                      \
984
0
  F(cxx_variadic_templates)
985
986
#define FOR_EACH_CXX14_FEATURE(F)                                             \
987
0
  F(cxx_aggregate_default_initializers)                                       \
988
0
  F(cxx_attribute_deprecated)                                                 \
989
0
  F(cxx_binary_literals)                                                      \
990
0
  F(cxx_contextual_conversions)                                               \
991
0
  F(cxx_decltype_auto)                                                        \
992
0
  F(cxx_digit_separators)                                                     \
993
0
  F(cxx_generic_lambdas)                                                      \
994
0
  F(cxx_lambda_init_captures)                                                 \
995
0
  F(cxx_relaxed_constexpr)                                                    \
996
0
  F(cxx_return_type_deduction)                                                \
997
0
  F(cxx_variable_templates)
998
999
#define FOR_EACH_CXX_FEATURE(F)                                               \
1000
0
  F(cxx_std_98)                                                               \
1001
0
  F(cxx_std_11)                                                               \
1002
0
  F(cxx_std_14)                                                               \
1003
0
  F(cxx_std_17)                                                               \
1004
0
  F(cxx_std_20)                                                               \
1005
0
  F(cxx_std_23)                                                               \
1006
0
  F(cxx_std_26)                                                               \
1007
0
  FOR_EACH_CXX98_FEATURE(F)                                                   \
1008
0
  FOR_EACH_CXX11_FEATURE(F)                                                   \
1009
0
  FOR_EACH_CXX14_FEATURE(F)
1010
1011
#define FOR_EACH_CUDA_FEATURE(F)                                              \
1012
0
  F(cuda_std_03)                                                              \
1013
0
  F(cuda_std_11)                                                              \
1014
0
  F(cuda_std_14)                                                              \
1015
0
  F(cuda_std_17)                                                              \
1016
0
  F(cuda_std_20)                                                              \
1017
0
  F(cuda_std_23)                                                              \
1018
0
  F(cuda_std_26)
1019
1020
#define FOR_EACH_HIP_FEATURE(F)                                               \
1021
0
  F(hip_std_98)                                                               \
1022
0
  F(hip_std_11)                                                               \
1023
0
  F(hip_std_14)                                                               \
1024
0
  F(hip_std_17)                                                               \
1025
0
  F(hip_std_20)                                                               \
1026
0
  F(hip_std_23)                                                               \
1027
0
  F(hip_std_26)