diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2019-02-19 16:02:03 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-02-19 18:11:44 (GMT) |
commit | a4e01d6707e9cfe50b2f49f140c8a9894cd8108f (patch) | |
tree | 4e23a09a70a9d96e34108a105f8d31d9f4cbc18c /Source/cmQtAutoGenGlobalInitializer.cxx | |
parent | e6897c72e7c59f7a0b82ed19c1bdb40d42f7adaa (diff) | |
download | CMake-a4e01d6707e9cfe50b2f49f140c8a9894cd8108f.zip CMake-a4e01d6707e9cfe50b2f49f140c8a9894cd8108f.tar.gz CMake-a4e01d6707e9cfe50b2f49f140c8a9894cd8108f.tar.bz2 |
Autogen: Add output caching GetExecutableTestOutput
This adds the cmQtAutoGenGlobalInitializer::GetExecutableTestOutput method
which caches the output of the called executable and returns the cached value
on any subsequent call.
Diffstat (limited to 'Source/cmQtAutoGenGlobalInitializer.cxx')
-rw-r--r-- | Source/cmQtAutoGenGlobalInitializer.cxx | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index 95a297c..3ad91ee 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -6,10 +6,12 @@ #include "cmAlgorithms.h" #include "cmCustomCommandLines.h" +#include "cmDuration.h" #include "cmGeneratorTarget.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" +#include "cmProcessOutput.h" #include "cmState.h" #include "cmStateTypes.h" #include "cmSystemTools.h" @@ -183,6 +185,68 @@ void cmQtAutoGenGlobalInitializer::AddToGlobalAutoRcc( } } +bool cmQtAutoGenGlobalInitializer::GetExecutableTestOutput( + std::string const& generator, std::string const& executable, + std::string& error, std::string* output) +{ + // Check if we have cached output + { + auto it = this->ExecutableTestOutputs_.find(executable); + if (it != this->ExecutableTestOutputs_.end()) { + // Return output on demand + if (output != nullptr) { + *output = it->second; + } + return true; + } + } + + // Check if the executable exists + if (!cmSystemTools::FileExists(executable, true)) { + error = "The \""; + error += generator; + error += "\" executable "; + error += cmQtAutoGen::Quoted(executable); + error += " does not exist."; + return false; + } + + // Test the executable + std::string stdOut; + { + std::string stdErr; + std::vector<std::string> command; + command.push_back(executable); + command.emplace_back("-h"); + int retVal = 0; + const bool runResult = cmSystemTools::RunSingleCommand( + command, &stdOut, &stdErr, &retVal, nullptr, cmSystemTools::OUTPUT_NONE, + cmDuration::zero(), cmProcessOutput::Auto); + if (!runResult) { + error = "Test run of \""; + error += generator; + error += "\" executable "; + error += cmQtAutoGen::Quoted(executable) + " failed.\n"; + error += cmQtAutoGen::QuotedCommand(command); + error += "\n"; + error += stdOut; + error += "\n"; + error += stdErr; + return false; + } + } + + // Return executable output on demand + if (output != nullptr) { + *output = stdOut; + } + + // Register executable and output + this->ExecutableTestOutputs_.emplace(executable, std::move(stdOut)); + + return true; +} + bool cmQtAutoGenGlobalInitializer::generate() { return (InitializeCustomTargets() && SetupCustomTargets()); |