1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-15 20:46:37 +08:00

Refactor: Move some common code into separate file

This code is going to be needed by both cmCMakePresetsFile and
cmCMakePresetsFileReadJSON when the upcoming condition types are
created. Move it into a header file.
This commit is contained in:
Kyle Edwards
2021-03-19 10:40:03 -04:00
parent ebbd475e54
commit ce6ea7c927
3 changed files with 26 additions and 17 deletions

View File

@@ -198,6 +198,7 @@ set(SRCS
cmCMakePath.cxx
cmCMakePresetsFile.cxx
cmCMakePresetsFile.h
cmCMakePresetsFileInternal.h
cmCMakePresetsFileReadJSON.cxx
cmCommandArgumentParserHelper.cxx
cmCommonTargetGenerator.cxx

View File

@@ -9,16 +9,10 @@
#include <iterator>
#include <utility>
#include "cmCMakePresetsFileInternal.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#define CHECK_OK(expr) \
{ \
auto _result = expr; \
if (_result != ReadFileResult::READ_OK) \
return _result; \
}
#define CHECK_EXPAND(out, field, expanders, version) \
{ \
switch (ExpandMacros(field, expanders, version)) { \
@@ -44,6 +38,8 @@ using ReadFileResult = cmCMakePresetsFile::ReadFileResult;
using ConfigurePreset = cmCMakePresetsFile::ConfigurePreset;
using BuildPreset = cmCMakePresetsFile::BuildPreset;
using TestPreset = cmCMakePresetsFile::TestPreset;
using ExpandMacroResult = cmCMakePresetsFileInternal::ExpandMacroResult;
using MacroExpander = cmCMakePresetsFileInternal::MacroExpander;
void InheritString(std::string& child, const std::string& parent)
{
@@ -166,16 +162,6 @@ bool IsValidMacroNamespace(const std::string& str)
[&str](const char* prefix) -> bool { return str == prefix; });
}
enum class ExpandMacroResult
{
Ok,
Ignore,
Error,
};
using MacroExpander = std::function<ExpandMacroResult(
const std::string&, const std::string&, std::string&, int version)>;
ExpandMacroResult VisitEnv(std::string& value, CycleStatus& status,
const std::vector<MacroExpander>& macroExpanders,
int version);

View File

@@ -0,0 +1,22 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCMakePresetsFile.h"
#define CHECK_OK(expr) \
{ \
auto _result = expr; \
if (_result != ReadFileResult::READ_OK) \
return _result; \
}
namespace cmCMakePresetsFileInternal {
enum class ExpandMacroResult
{
Ok,
Ignore,
Error,
};
using MacroExpander = std::function<ExpandMacroResult(
const std::string&, const std::string&, std::string&, int version)>;
}