diff options
author | Brad King <brad.king@kitware.com> | 2021-02-04 13:22:13 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-02-04 13:22:19 (GMT) |
commit | 4cd23c5e0d5835781b95f6eda778a35d2f55beb8 (patch) | |
tree | b1d1b4380ae20258cf37efd1df15ef2ba21c698e /Source | |
parent | bf6e6550315097db430b5d5773e6973facd5ad17 (diff) | |
parent | 5af38a11ce8da342006bb29d6af00596f79e002c (diff) | |
download | CMake-4cd23c5e0d5835781b95f6eda778a35d2f55beb8.zip CMake-4cd23c5e0d5835781b95f6eda778a35d2f55beb8.tar.gz CMake-4cd23c5e0d5835781b95f6eda778a35d2f55beb8.tar.bz2 |
Merge topic 'issue-17634'
5af38a11ce try_run: Allow to set working directory
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5757
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmTryRunCommand.cxx | 21 | ||||
-rw-r--r-- | Source/cmTryRunCommand.h | 1 |
2 files changed, 20 insertions, 2 deletions
diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index 3f89641..8cac74d 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -84,6 +84,14 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv, } i++; this->CompileOutputVariable = argv[i]; + } else if (argv[i] == "WORKING_DIRECTORY") { + if (argv.size() <= (i + 1)) { + cmSystemTools::Error( + "WORKING_DIRECTORY specified but there is no variable"); + return false; + } + i++; + this->WorkingDirectory = argv[i]; } else { tryCompile.push_back(argv[i]); } @@ -102,6 +110,14 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv, return false; } + if (!this->WorkingDirectory.empty()) { + if (!cmSystemTools::MakeDirectory(this->WorkingDirectory)) { + cmSystemTools::Error(cmStrCat("Error creating working directory \"", + this->WorkingDirectory, "\".")); + return false; + } + } + bool captureRunOutput = false; if (!this->OutputVariable.empty()) { captureRunOutput = true; @@ -188,8 +204,9 @@ void cmTryRunCommand::RunExecutable(const std::string& runArgs, finalCommand += runArgs; } bool worked = cmSystemTools::RunSingleCommand( - finalCommand, out, out, &retVal, nullptr, cmSystemTools::OUTPUT_NONE, - cmDuration::zero()); + finalCommand, out, out, &retVal, + this->WorkingDirectory.empty() ? nullptr : this->WorkingDirectory.c_str(), + cmSystemTools::OUTPUT_NONE, cmDuration::zero()); // set the run var char retChar[16]; const char* retStr; diff --git a/Source/cmTryRunCommand.h b/Source/cmTryRunCommand.h index 070c63c..d45acd8 100644 --- a/Source/cmTryRunCommand.h +++ b/Source/cmTryRunCommand.h @@ -49,4 +49,5 @@ private: std::string OutputVariable; std::string RunOutputVariable; std::string CompileOutputVariable; + std::string WorkingDirectory; }; |