diff options
author | Cristian Adam <cristian.adam@gmail.com> | 2020-02-27 19:20:22 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-03-03 13:42:13 (GMT) |
commit | 598b676b5e77540b366b01b3c10154c2a633d23c (patch) | |
tree | eb3aaea48e3c1743835a74be111ca64ee4a9a4e5 /Source/cmCMakeCommand.cxx | |
parent | c58b9c5ab94d674c76a17e6154f05e0e8c5c37d1 (diff) | |
download | CMake-598b676b5e77540b366b01b3c10154c2a633d23c.zip CMake-598b676b5e77540b366b01b3c10154c2a633d23c.tar.gz CMake-598b676b5e77540b366b01b3c10154c2a633d23c.tar.bz2 |
cmake_command: Add command to EVAL a CMake script as a string
Diffstat (limited to 'Source/cmCMakeCommand.cxx')
-rw-r--r-- | Source/cmCMakeCommand.cxx | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/Source/cmCMakeCommand.cxx b/Source/cmCMakeCommand.cxx index 5699086..c11a003 100644 --- a/Source/cmCMakeCommand.cxx +++ b/Source/cmCMakeCommand.cxx @@ -2,11 +2,14 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCMakeCommand.h" +#include <algorithm> #include <cstddef> #include "cmExecutionStatus.h" #include "cmListFileCache.h" #include "cmMakefile.h" +#include "cmRange.h" +#include "cmStringAlgorithms.h" bool cmCMakeCommand(std::vector<std::string> const& args, cmExecutionStatus& status) @@ -19,6 +22,8 @@ bool cmCMakeCommand(std::vector<std::string> const& args, cmMakefile& makefile = status.GetMakefile(); cmListFileContext context = makefile.GetExecutionContext(); + bool result = false; + if (args[0] == "INVOKE") { if (args.size() == 1) { status.SetError("called with incorrect number of arguments"); @@ -39,9 +44,25 @@ bool cmCMakeCommand(std::vector<std::string> const& args, func.Arguments.emplace_back(lfarg); } - return makefile.ExecuteCommand(func, status); + result = makefile.ExecuteCommand(func, status); + } else if (args[0] == "EVAL") { + if (args.size() < 2) { + status.SetError("called with incorrect number of arguments"); + return false; + } + + auto code_iter = std::find(args.begin(), args.end(), "CODE"); + if (code_iter == args.end()) { + status.SetError("called without CODE argument"); + return false; + } + + const std::string code = cmJoin(cmMakeRange(++code_iter, args.end()), " "); + result = makefile.ReadListFileAsString( + code, cmStrCat(context.FilePath, ":", context.Line, ":EVAL")); + } else { + status.SetError("called with unknown meta-operation"); } - status.SetError("called with unknown meta-operation"); - return false; + return result; } |