From 06128cf94964697279970a80ddfc1ce2ef7b4da5 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Tue, 29 Sep 2020 10:15:34 -0400 Subject: Presets: Add cmCMakePresetsFile class --- Source/cmCMakePresetsFile.h | 141 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 Source/cmCMakePresetsFile.h (limited to 'Source/cmCMakePresetsFile.h') diff --git a/Source/cmCMakePresetsFile.h b/Source/cmCMakePresetsFile.h new file mode 100644 index 0000000000..17f6a886ef --- /dev/null +++ b/Source/cmCMakePresetsFile.h @@ -0,0 +1,141 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#pragma once + +#include +#include +#include +#include + +#include + +class cmCMakePresetsFile +{ +public: + enum class CMakeGeneratorConfig + { + Default, + Ignore, + }; + + class CacheVariable + { + public: + std::string Type; + std::string Value; + }; + + class Preset + { + public: +#if __cplusplus < 201703L && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L) + Preset() = default; + Preset(const Preset& other) = default; + Preset(Preset&& other) = default; + + Preset& operator=(const Preset& other) = default; + + // The move assignment operators for several STL classes did not become + // noexcept until C++17, which causes some tools to warn about this move + // assignment operator throwing an exception when it shouldn't. Disable the + // move assignment operator until C++17 is enabled. + Preset& operator=(Preset&& other) = delete; +#endif + + std::string Name; + std::vector Inherits; + bool Hidden; + bool User; + std::string DisplayName; + std::string Description; + std::string Generator; + std::string Architecture; + std::string Toolset; + cm::optional GeneratorConfig; + std::string BinaryDir; + + std::map> CacheVariables; + std::map> Environment; + + cm::optional WarnDev; + cm::optional ErrorDev; + cm::optional WarnDeprecated; + cm::optional ErrorDeprecated; + cm::optional WarnUninitialized; + cm::optional WarnUnusedCli; + cm::optional WarnSystemVars; + + cm::optional DebugOutput; + cm::optional DebugTryCompile; + cm::optional DebugFind; + }; + + class UnexpandedPreset : public Preset + { + public: + using Preset::Preset; + + UnexpandedPreset() = default; + UnexpandedPreset(const Preset& preset) + : Preset(preset) + { + } + UnexpandedPreset(Preset&& preset) + : Preset(std::move(preset)) + { + } + }; + + class ExpandedPreset : public Preset + { + public: + using Preset::Preset; + + ExpandedPreset() = default; + ExpandedPreset(const Preset& preset) + : Preset(preset) + { + } + ExpandedPreset(Preset&& preset) + : Preset(std::move(preset)) + { + } + }; + + std::string SourceDir; + std::map Presets; + std::vector PresetOrder; + + enum class ReadFileResult + { + READ_OK, + FILE_NOT_FOUND, + JSON_PARSE_ERROR, + INVALID_ROOT, + NO_VERSION, + INVALID_VERSION, + UNRECOGNIZED_VERSION, + INVALID_CMAKE_VERSION, + UNRECOGNIZED_CMAKE_VERSION, + INVALID_PRESETS, + INVALID_PRESET, + INVALID_VARIABLE, + DUPLICATE_PRESETS, + CYCLIC_PRESET_INHERITANCE, + USER_PRESET_INHERITANCE, + }; + + static std::string GetFilename(const std::string& sourceDir); + static std::string GetUserFilename(const std::string& sourceDir); + ReadFileResult ReadProjectPresets(const std::string& sourceDir, + bool allowNoFiles = false); + static const char* ResultToString(ReadFileResult result); + + cm::optional ExpandMacros( + const UnexpandedPreset& preset) const; + +private: + ReadFileResult ReadJSONFile( + const std::string& filename, std::vector& presetOrder, + std::map& presetMap, bool user); +}; -- cgit v1.2.1