diff options
author | Brad King <brad.king@kitware.com> | 2018-11-28 14:05:04 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-11-28 14:05:16 (GMT) |
commit | 5daf7d92f8971f13fb2f6fac117f44f355ec504a (patch) | |
tree | b47d11b26eedf8aa55d4f440f75c46378054b643 /Source | |
parent | 18b9cf4abc351f98bbf549604d3c327a554a0143 (diff) | |
parent | 12b471e828e4462cce4354c87bb4fe18aeb600e3 (diff) | |
download | CMake-5daf7d92f8971f13fb2f6fac117f44f355ec504a.zip CMake-5daf7d92f8971f13fb2f6fac117f44f355ec504a.tar.gz CMake-5daf7d92f8971f13fb2f6fac117f44f355ec504a.tar.bz2 |
Merge topic 'file-size'
12b471e828 file: add SIZE option
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2639
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmFileCommand.cxx | 32 | ||||
-rw-r--r-- | Source/cmFileCommand.h | 1 |
2 files changed, 33 insertions, 0 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index fa2a3e1..73ff5a1 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -177,6 +177,9 @@ bool cmFileCommand::InitialPass(std::vector<std::string> const& args, if (subCommand == "LOCK") { return this->HandleLockCommand(args); } + if (subCommand == "SIZE") { + return this->HandleSizeCommand(args); + } std::string e = "does not recognize sub-command " + subCommand; this->SetError(e); @@ -3606,3 +3609,32 @@ bool cmFileCommand::HandleTimestampCommand( return true; } + +bool cmFileCommand::HandleSizeCommand(std::vector<std::string> const& args) +{ + if (args.size() != 3) { + std::ostringstream e; + e << args[0] << " requires a file name and output variable"; + this->SetError(e.str()); + return false; + } + + unsigned int argsIndex = 1; + + const std::string& filename = args[argsIndex++]; + + const std::string& outputVariable = args[argsIndex++]; + + if (!cmSystemTools::FileExists(filename, true)) { + std::ostringstream e; + e << "SIZE requested of path that is not readable " << filename; + this->SetError(e.str()); + return false; + } + + this->Makefile->AddDefinition( + outputVariable, + std::to_string(cmSystemTools::FileLength(filename)).c_str()); + + return true; +} diff --git a/Source/cmFileCommand.h b/Source/cmFileCommand.h index 719dca2..01e007d 100644 --- a/Source/cmFileCommand.h +++ b/Source/cmFileCommand.h @@ -59,6 +59,7 @@ protected: bool HandleTimestampCommand(std::vector<std::string> const& args); bool HandleGenerateCommand(std::vector<std::string> const& args); bool HandleLockCommand(std::vector<std::string> const& args); + bool HandleSizeCommand(std::vector<std::string> const& args); private: void AddEvaluationFile(const std::string& inputName, |