1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
11 #include <unordered_set>
15 #include <cm/optional>
17 #include "CTest/cmCTestTypes.h"
19 enum class PackageResolveMode;
21 class cmCMakePresetsGraph
24 enum class ReadFileResult
33 INVALID_CMAKE_VERSION,
34 UNRECOGNIZED_CMAKE_VERSION,
39 CYCLIC_PRESET_INHERITANCE,
40 INHERITED_PRESET_UNREACHABLE_FROM_FILE,
41 CONFIGURE_PRESET_UNREACHABLE_FROM_FILE,
42 INVALID_MACRO_EXPANSION,
43 BUILD_TEST_PRESETS_UNSUPPORTED,
44 PACKAGE_PRESETS_UNSUPPORTED,
45 WORKFLOW_PRESETS_UNSUPPORTED,
48 INVALID_CONFIGURE_PRESET,
49 INSTALL_PREFIX_UNSUPPORTED,
51 CONDITION_UNSUPPORTED,
52 TOOLCHAIN_FILE_UNSUPPORTED,
54 TEST_OUTPUT_TRUNCATION_UNSUPPORTED,
55 INVALID_WORKFLOW_STEPS,
56 WORKFLOW_STEP_UNREACHABLE_FROM_FILE,
57 CTEST_JUNIT_UNSUPPORTED,
61 enum class ArchToolsetStrategy
82 std::unordered_set<File*> ReachableFiles;
89 Preset(Preset&& /*other*/) = default;
90 Preset(const Preset& /*other*/) = default;
91 Preset& operator=(const Preset& /*other*/) = default;
92 virtual ~Preset() = default;
93 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
94 Preset& operator=(Preset&& /*other*/) = default;
96 // The move assignment operators for several STL classes did not become
97 // noexcept until C++17, which causes some tools to warn about this move
98 // assignment operator throwing an exception when it shouldn't.
99 Preset& operator=(Preset&& /*other*/) = delete;
103 std::vector<std::string> Inherits;
106 std::string DisplayName;
107 std::string Description;
109 std::shared_ptr<Condition> ConditionEvaluator;
110 bool ConditionResult = true;
112 std::map<std::string, cm::optional<std::string>> Environment;
114 virtual ReadFileResult VisitPresetInherit(const Preset& parent) = 0;
115 virtual ReadFileResult VisitPresetBeforeInherit()
117 return ReadFileResult::READ_OK;
120 virtual ReadFileResult VisitPresetAfterInherit(int /* version */)
122 return ReadFileResult::READ_OK;
126 class ConfigurePreset : public Preset
129 ConfigurePreset() = default;
130 ConfigurePreset(ConfigurePreset&& /*other*/) = default;
131 ConfigurePreset(const ConfigurePreset& /*other*/) = default;
132 ConfigurePreset& operator=(const ConfigurePreset& /*other*/) = default;
133 ~ConfigurePreset() override = default;
134 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
135 ConfigurePreset& operator=(ConfigurePreset&& /*other*/) = default;
137 // The move assignment operators for several STL classes did not become
138 // noexcept until C++17, which causes some tools to warn about this move
139 // assignment operator throwing an exception when it shouldn't.
140 ConfigurePreset& operator=(ConfigurePreset&& /*other*/) = delete;
143 std::string Generator;
144 std::string Architecture;
145 cm::optional<ArchToolsetStrategy> ArchitectureStrategy;
147 cm::optional<ArchToolsetStrategy> ToolsetStrategy;
148 std::string ToolchainFile;
149 std::string BinaryDir;
150 std::string InstallDir;
152 std::map<std::string, cm::optional<CacheVariable>> CacheVariables;
154 cm::optional<bool> WarnDev;
155 cm::optional<bool> ErrorDev;
156 cm::optional<bool> WarnDeprecated;
157 cm::optional<bool> ErrorDeprecated;
158 cm::optional<bool> WarnUninitialized;
159 cm::optional<bool> WarnUnusedCli;
160 cm::optional<bool> WarnSystemVars;
162 cm::optional<bool> DebugOutput;
163 cm::optional<bool> DebugTryCompile;
164 cm::optional<bool> DebugFind;
166 ReadFileResult VisitPresetInherit(const Preset& parent) override;
167 ReadFileResult VisitPresetBeforeInherit() override;
168 ReadFileResult VisitPresetAfterInherit(int version) override;
171 class BuildPreset : public Preset
174 BuildPreset() = default;
175 BuildPreset(BuildPreset&& /*other*/) = default;
176 BuildPreset(const BuildPreset& /*other*/) = default;
177 BuildPreset& operator=(const BuildPreset& /*other*/) = default;
178 ~BuildPreset() override = default;
179 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
180 BuildPreset& operator=(BuildPreset&& /*other*/) = default;
182 // The move assignment operators for several STL classes did not become
183 // noexcept until C++17, which causes some tools to warn about this move
184 // assignment operator throwing an exception when it shouldn't.
185 BuildPreset& operator=(BuildPreset&& /*other*/) = delete;
188 std::string ConfigurePreset;
189 cm::optional<bool> InheritConfigureEnvironment;
190 cm::optional<int> Jobs;
191 std::vector<std::string> Targets;
192 std::string Configuration;
193 cm::optional<bool> CleanFirst;
194 cm::optional<bool> Verbose;
195 std::vector<std::string> NativeToolOptions;
196 cm::optional<PackageResolveMode> ResolvePackageReferences;
198 ReadFileResult VisitPresetInherit(const Preset& parent) override;
199 ReadFileResult VisitPresetAfterInherit(int /* version */) override;
202 class TestPreset : public Preset
205 TestPreset() = default;
206 TestPreset(TestPreset&& /*other*/) = default;
207 TestPreset(const TestPreset& /*other*/) = default;
208 TestPreset& operator=(const TestPreset& /*other*/) = default;
209 ~TestPreset() override = default;
210 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
211 TestPreset& operator=(TestPreset&& /*other*/) = default;
213 // The move assignment operators for several STL classes did not become
214 // noexcept until C++17, which causes some tools to warn about this move
215 // assignment operator throwing an exception when it shouldn't.
216 TestPreset& operator=(TestPreset&& /*other*/) = delete;
221 enum class VerbosityEnum
228 cm::optional<bool> ShortProgress;
229 cm::optional<VerbosityEnum> Verbosity;
230 cm::optional<bool> Debug;
231 cm::optional<bool> OutputOnFailure;
232 cm::optional<bool> Quiet;
233 std::string OutputLogFile;
234 std::string OutputJUnitFile;
235 cm::optional<bool> LabelSummary;
236 cm::optional<bool> SubprojectSummary;
237 cm::optional<int> MaxPassedTestOutputSize;
238 cm::optional<int> MaxFailedTestOutputSize;
239 cm::optional<cmCTestTypes::TruncationMode> TestOutputTruncation;
240 cm::optional<int> MaxTestNameWidth;
243 struct IncludeOptions
247 cm::optional<int> Start;
248 cm::optional<int> End;
249 cm::optional<int> Stride;
250 std::vector<int> SpecificTests;
252 std::string IndexFile;
257 cm::optional<IndexOptions> Index;
258 cm::optional<bool> UseUnion;
261 struct ExcludeOptions
263 struct FixturesOptions
272 cm::optional<FixturesOptions> Fixtures;
277 cm::optional<IncludeOptions> Include;
278 cm::optional<ExcludeOptions> Exclude;
281 struct ExecutionOptions
283 enum class ShowOnlyEnum
302 enum class NoTestsActionEnum
309 cm::optional<bool> StopOnFailure;
310 cm::optional<bool> EnableFailover;
311 cm::optional<int> Jobs;
312 std::string ResourceSpecFile;
313 cm::optional<int> TestLoad;
314 cm::optional<ShowOnlyEnum> ShowOnly;
316 cm::optional<RepeatOptions> Repeat;
317 cm::optional<bool> InteractiveDebugging;
318 cm::optional<bool> ScheduleRandom;
319 cm::optional<int> Timeout;
320 cm::optional<NoTestsActionEnum> NoTestsAction;
323 std::string ConfigurePreset;
324 cm::optional<bool> InheritConfigureEnvironment;
325 std::string Configuration;
326 std::vector<std::string> OverwriteConfigurationFile;
327 cm::optional<OutputOptions> Output;
328 cm::optional<FilterOptions> Filter;
329 cm::optional<ExecutionOptions> Execution;
331 ReadFileResult VisitPresetInherit(const Preset& parent) override;
332 ReadFileResult VisitPresetAfterInherit(int /* version */) override;
335 class PackagePreset : public Preset
338 PackagePreset() = default;
339 PackagePreset(PackagePreset&& /*other*/) = default;
340 PackagePreset(const PackagePreset& /*other*/) = default;
341 PackagePreset& operator=(const PackagePreset& /*other*/) = default;
342 ~PackagePreset() override = default;
343 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
344 PackagePreset& operator=(PackagePreset&& /*other*/) = default;
346 // The move assignment operators for several STL classes did not become
347 // noexcept until C++17, which causes some tools to warn about this move
348 // assignment operator throwing an exception when it shouldn't.
349 PackagePreset& operator=(PackagePreset&& /*other*/) = delete;
352 std::string ConfigurePreset;
353 cm::optional<bool> InheritConfigureEnvironment;
354 std::vector<std::string> Generators;
355 std::vector<std::string> Configurations;
356 std::map<std::string, std::string> Variables;
357 std::string ConfigFile;
359 cm::optional<bool> DebugOutput;
360 cm::optional<bool> VerboseOutput;
362 std::string PackageName;
363 std::string PackageVersion;
364 std::string PackageDirectory;
365 std::string VendorName;
367 ReadFileResult VisitPresetInherit(const Preset& parent) override;
368 ReadFileResult VisitPresetAfterInherit(int /* version */) override;
371 class WorkflowPreset : public Preset
374 WorkflowPreset() = default;
375 WorkflowPreset(WorkflowPreset&& /*other*/) = default;
376 WorkflowPreset(const WorkflowPreset& /*other*/) = default;
377 WorkflowPreset& operator=(const WorkflowPreset& /*other*/) = default;
378 ~WorkflowPreset() override = default;
379 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
380 WorkflowPreset& operator=(WorkflowPreset&& /*other*/) = default;
382 // The move assignment operators for several STL classes did not become
383 // noexcept until C++17, which causes some tools to warn about this move
384 // assignment operator throwing an exception when it shouldn't.
385 WorkflowPreset& operator=(WorkflowPreset&& /*other*/) = delete;
399 std::string PresetName;
402 std::vector<WorkflowStep> Steps;
404 ReadFileResult VisitPresetInherit(const Preset& parent) override;
405 ReadFileResult VisitPresetAfterInherit(int /* version */) override;
413 cm::optional<T> Expanded;
416 std::map<std::string, PresetPair<ConfigurePreset>> ConfigurePresets;
417 std::map<std::string, PresetPair<BuildPreset>> BuildPresets;
418 std::map<std::string, PresetPair<TestPreset>> TestPresets;
419 std::map<std::string, PresetPair<PackagePreset>> PackagePresets;
420 std::map<std::string, PresetPair<WorkflowPreset>> WorkflowPresets;
422 std::vector<std::string> ConfigurePresetOrder;
423 std::vector<std::string> BuildPresetOrder;
424 std::vector<std::string> TestPresetOrder;
425 std::vector<std::string> PackagePresetOrder;
426 std::vector<std::string> WorkflowPresetOrder;
428 std::string SourceDir;
429 std::vector<std::unique_ptr<File>> Files;
431 int GetVersion(const Preset& preset) const
433 return preset.OriginFile->Version;
436 static std::string GetFilename(const std::string& sourceDir);
437 static std::string GetUserFilename(const std::string& sourceDir);
438 ReadFileResult ReadProjectPresets(const std::string& sourceDir,
439 bool allowNoFiles = false);
440 static const char* ResultToString(ReadFileResult result);
442 std::string GetGeneratorForPreset(const std::string& presetName) const
444 auto configurePresetName = presetName;
446 auto buildPresetIterator = this->BuildPresets.find(presetName);
447 if (buildPresetIterator != this->BuildPresets.end()) {
448 configurePresetName =
449 buildPresetIterator->second.Unexpanded.ConfigurePreset;
451 auto testPresetIterator = this->TestPresets.find(presetName);
452 if (testPresetIterator != this->TestPresets.end()) {
453 configurePresetName =
454 testPresetIterator->second.Unexpanded.ConfigurePreset;
458 auto configurePresetIterator =
459 this->ConfigurePresets.find(configurePresetName);
460 if (configurePresetIterator != this->ConfigurePresets.end()) {
461 return configurePresetIterator->second.Unexpanded.Generator;
464 // This should only happen if the preset is hidden
465 // or (for build or test presets) if ConfigurePreset is invalid.
469 enum class PrintPrecedingNewline
474 static void printPrecedingNewline(PrintPrecedingNewline* p);
476 static void PrintPresets(
477 const std::vector<const cmCMakePresetsGraph::Preset*>& presets);
478 void PrintConfigurePresetList(
479 PrintPrecedingNewline* newline = nullptr) const;
480 void PrintConfigurePresetList(
481 const std::function<bool(const ConfigurePreset&)>& filter,
482 PrintPrecedingNewline* newline = nullptr) const;
483 void PrintBuildPresetList(PrintPrecedingNewline* newline = nullptr) const;
484 void PrintTestPresetList(PrintPrecedingNewline* newline = nullptr) const;
485 void PrintPackagePresetList(PrintPrecedingNewline* newline = nullptr) const;
486 void PrintPackagePresetList(
487 const std::function<bool(const PackagePreset&)>& filter,
488 PrintPrecedingNewline* newline = nullptr) const;
489 void PrintWorkflowPresetList(PrintPrecedingNewline* newline = nullptr) const;
490 void PrintAllPresets() const;
499 enum class ReadReason
505 ReadFileResult ReadProjectPresetsInternal(bool allowNoFiles);
506 ReadFileResult ReadJSONFile(const std::string& filename, RootType rootType,
507 ReadReason readReason,
508 std::vector<File*>& inProgressFiles, File*& file,
509 std::string& errMsg);