summaryrefslogtreecommitdiffstats
path: root/Source/cmcmd.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-01-21 18:48:30 (GMT)
committerBrad King <brad.king@kitware.com>2014-01-21 18:50:49 (GMT)
commit94389f6388367aa4d9bfa58c9cde89e33d1858dc (patch)
treefb39dc1d65ae8332ab8dc791de86dc01eb91fc8b /Source/cmcmd.cxx
parenta86865e96c55c8a35615c24af0cf1c990f4bba68 (diff)
downloadCMake-94389f6388367aa4d9bfa58c9cde89e33d1858dc.zip
CMake-94389f6388367aa4d9bfa58c9cde89e33d1858dc.tar.gz
CMake-94389f6388367aa4d9bfa58c9cde89e33d1858dc.tar.bz2
cmake: Add '-E sleep' command
Add a cmake command-line interface to provide a cross-platform 'sleep'.
Diffstat (limited to 'Source/cmcmd.cxx')
-rw-r--r--Source/cmcmd.cxx28
1 files changed, 28 insertions, 0 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index c1576c4..4ac1986 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -71,6 +71,7 @@ void CMakeCommandUsage(const char* program)
"(on one volume)\n"
<< " tar [cxt][vfz][cvfj] file.tar [file/dir1 file/dir2 ...]\n"
<< " - create or extract a tar or zip archive\n"
+ << " sleep <number>... - sleep for given number of seconds\n"
<< " time command [args] ... - run command and return elapsed time\n"
<< " touch file - touch a file.\n"
<< " touch_nocreate file - touch a file but do not create it.\n"
@@ -279,6 +280,33 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
return 0;
}
+ // Sleep command
+ else if (args[1] == "sleep" && args.size() > 2)
+ {
+ double total = 0;
+ for(size_t i = 2; i < args.size(); ++i)
+ {
+ double num = 0.0;
+ char unit;
+ char extra;
+ int n = sscanf(args[i].c_str(), "%lg%c%c", &num, &unit, &extra);
+ if((n == 1 || (n == 2 && unit == 's')) && num >= 0)
+ {
+ total += num;
+ }
+ else
+ {
+ std::cerr << "Unknown sleep time format \"" << args[i] << "\".\n";
+ return 1;
+ }
+ }
+ if(total > 0)
+ {
+ cmSystemTools::Delay(static_cast<unsigned int>(total*1000));
+ }
+ return 0;
+ }
+
// Clock command
else if (args[1] == "time" && args.size() > 2)
{