summaryrefslogtreecommitdiffstats
path: root/Source/cmCMakeLanguageCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-09-21 18:53:10 (GMT)
committerBrad King <brad.king@kitware.com>2020-09-29 14:00:24 (GMT)
commit4ebe9c4ce15734ee9a167f7b48b8ed8931adb0ca (patch)
tree7ab556eedec3f31ad0635f18261d01e88bef3729 /Source/cmCMakeLanguageCommand.cxx
parent78ff24a3a778805e5ffa8b44e26d04cd283ff52a (diff)
downloadCMake-4ebe9c4ce15734ee9a167f7b48b8ed8931adb0ca.zip
CMake-4ebe9c4ce15734ee9a167f7b48b8ed8931adb0ca.tar.gz
CMake-4ebe9c4ce15734ee9a167f7b48b8ed8931adb0ca.tar.bz2
cmake_language(EVAL): Factor out internal helper
Diffstat (limited to 'Source/cmCMakeLanguageCommand.cxx')
-rw-r--r--Source/cmCMakeLanguageCommand.cxx56
1 files changed, 32 insertions, 24 deletions
diff --git a/Source/cmCMakeLanguageCommand.cxx b/Source/cmCMakeLanguageCommand.cxx
index d513611..ae80066 100644
--- a/Source/cmCMakeLanguageCommand.cxx
+++ b/Source/cmCMakeLanguageCommand.cxx
@@ -28,6 +28,37 @@ std::array<cm::static_string_view, 12> InvalidCommands{
"foreach"_s, "endforeach"_s
} // clang-format on
};
+
+bool cmCMakeLanguageCommandEVAL(std::vector<cmListFileArgument> const& args,
+ cmExecutionStatus& status)
+{
+ cmMakefile& makefile = status.GetMakefile();
+ cmListFileContext context = makefile.GetBacktrace().Top();
+ std::vector<std::string> expandedArgs;
+ makefile.ExpandArguments(args, expandedArgs);
+
+ if (expandedArgs.size() < 2) {
+ status.SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ if (expandedArgs[1] != "CODE") {
+ auto code_iter =
+ std::find(expandedArgs.begin() + 2, expandedArgs.end(), "CODE");
+ if (code_iter == expandedArgs.end()) {
+ status.SetError("called without CODE argument");
+ } else {
+ status.SetError(
+ "called with unsupported arguments between EVAL and CODE arguments");
+ }
+ return false;
+ }
+
+ const std::string code =
+ cmJoin(cmMakeRange(expandedArgs.begin() + 2, expandedArgs.end()), " ");
+ return makefile.ReadListFileAsString(
+ code, cmStrCat(context.FilePath, ":", context.Line, ":EVAL"));
+}
}
bool cmCMakeLanguageCommand(std::vector<cmListFileArgument> const& args,
@@ -105,30 +136,7 @@ bool cmCMakeLanguageCommand(std::vector<cmListFileArgument> const& args,
result = makefile.ExecuteCommand(func, status);
} else if (dispatchExpandedArgs[0] == "EVAL") {
- std::vector<std::string> expandedArgs;
- makefile.ExpandArguments(args, expandedArgs);
-
- if (expandedArgs.size() < 2) {
- status.SetError("called with incorrect number of arguments");
- return false;
- }
-
- if (expandedArgs[1] != "CODE") {
- auto code_iter =
- std::find(expandedArgs.begin() + 2, expandedArgs.end(), "CODE");
- if (code_iter == expandedArgs.end()) {
- status.SetError("called without CODE argument");
- } else {
- status.SetError(
- "called with unsupported arguments between EVAL and CODE arguments");
- }
- return false;
- }
-
- const std::string code =
- cmJoin(cmMakeRange(expandedArgs.begin() + 2, expandedArgs.end()), " ");
- result = makefile.ReadListFileAsString(
- code, cmStrCat(context.FilePath, ":", context.Line, ":EVAL"));
+ return cmCMakeLanguageCommandEVAL(args, status);
} else {
status.SetError("called with unknown meta-operation");
}