diff options
author | Brad King <brad.king@kitware.com> | 2022-06-15 19:07:06 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-07-26 19:09:48 (GMT) |
commit | e73c8eaff20b33452db251ce1de1b1162b647178 (patch) | |
tree | ff5c7fe9b15dcedee5165ae65a74417a2e90223e /Source/cmTryRunCommand.cxx | |
parent | 7ba3a3290fb53d2874e8a355ae0a4d12c8191cfb (diff) | |
download | CMake-e73c8eaff20b33452db251ce1de1b1162b647178.zip CMake-e73c8eaff20b33452db251ce1de1b1162b647178.tar.gz CMake-e73c8eaff20b33452db251ce1de1b1162b647178.tar.bz2 |
cmTry{Compile,Run}Command: Port away from legacy cmCommand
Convert the command entry points to free functions.
Diffstat (limited to 'Source/cmTryRunCommand.cxx')
-rw-r--r-- | Source/cmTryRunCommand.cxx | 82 |
1 files changed, 61 insertions, 21 deletions
diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index 4cd0adc..98cacdc 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -6,7 +6,9 @@ #include "cmsys/FStream.hxx" +#include "cmCoreTryCompile.h" #include "cmDuration.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmMessageType.h" #include "cmRange.h" @@ -17,24 +19,40 @@ #include "cmValue.h" #include "cmake.h" -class cmExecutionStatus; +namespace { -// cmTryRunCommand -bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv, - cmExecutionStatus&) +class TryRunCommandImpl : public cmCoreTryCompile { - if (argv.size() < 4) { - return false; - } - - if (this->Makefile->GetCMakeInstance()->GetWorkingMode() == - cmake::FIND_PACKAGE_MODE) { - this->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - "The try_run() command is not supported in --find-package mode."); - return false; +public: + TryRunCommandImpl(cmMakefile* mf) + : cmCoreTryCompile(mf) + { } + bool TryRunCode(std::vector<std::string> const& args); + + void RunExecutable(const std::string& runArgs, + std::string* runOutputContents, + std::string* runOutputStdOutContents, + std::string* runOutputStdErrContents); + void DoNotRunExecutable(const std::string& runArgs, + const std::string& srcFile, + std::string* runOutputContents, + std::string* runOutputStdOutContents, + std::string* runOutputStdErrContents); + + std::string CompileResultVariable; + std::string RunResultVariable; + std::string OutputVariable; + std::string RunOutputVariable; + std::string RunOutputStdOutVariable; + std::string RunOutputStdErrVariable; + std::string CompileOutputVariable; + std::string WorkingDirectory; +}; + +bool TryRunCommandImpl::TryRunCode(std::vector<std::string> const& argv) +{ // build an arg list for TryCompile and extract the runArgs, std::vector<std::string> tryCompile; @@ -240,9 +258,9 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv, return true; } -void cmTryRunCommand::RunExecutable(const std::string& runArgs, - std::string* out, std::string* stdOut, - std::string* stdErr) +void TryRunCommandImpl::RunExecutable(const std::string& runArgs, + std::string* out, std::string* stdOut, + std::string* stdErr) { int retVal = -1; @@ -288,10 +306,11 @@ void cmTryRunCommand::RunExecutable(const std::string& runArgs, executable, two cache variables are created which will hold the results the executable would have produced. */ -void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, - const std::string& srcFile, - std::string* out, std::string* stdOut, - std::string* stdErr) +void TryRunCommandImpl::DoNotRunExecutable(const std::string& runArgs, + const std::string& srcFile, + std::string* out, + std::string* stdOut, + std::string* stdErr) { // copy the executable out of the CMakeFiles/ directory, so it is not // removed at the end of try_run() and the user can run it manually @@ -521,3 +540,24 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, (*out) = *this->Makefile->GetDefinition(internalRunOutputName); } } +} + +bool cmTryRunCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + if (args.size() < 4) { + return false; + } + + cmMakefile& mf = status.GetMakefile(); + + if (mf.GetCMakeInstance()->GetWorkingMode() == cmake::FIND_PACKAGE_MODE) { + mf.IssueMessage( + MessageType::FATAL_ERROR, + "The try_run() command is not supported in --find-package mode."); + return false; + } + + TryRunCommandImpl tr(&mf); + return tr.TryRunCode(args); +} |