Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
CMake
CMake
Commits
94389f63
Commit
94389f63
authored
Jan 21, 2014
by
Brad King
Browse files
cmake: Add '-E sleep' command
Add a cmake command-line interface to provide a cross-platform 'sleep'.
parent
a86865e9
Changes
9
Hide whitespace changes
Inline
Side-by-side
Help/manual/cmake.1.rst
View file @
94389f63
...
...
@@ -39,7 +39,7 @@ Options
that can be used on all systems. Run with -E help for the usage
information. Commands available are: chdir, compare_files, copy,
copy_directory, copy_if_different, echo, echo_append, environment,
make_directory, md5sum, remove, remove_directory, rename, tar, time,
make_directory, md5sum, remove, remove_directory, rename,
sleep,
tar, time,
touch, touch_nocreate. In addition, some platform specific commands
are available. On Windows: delete_regv, write_regv. On
UNIX: create_symlink.
...
...
Source/cmcmd.cxx
View file @
94389f63
...
...
@@ -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
)
{
...
...
Tests/RunCMake/CommandLine/E_sleep-bad-arg1-result.txt
0 → 100644
View file @
94389f63
1
Tests/RunCMake/CommandLine/E_sleep-bad-arg1-stderr.txt
0 → 100644
View file @
94389f63
^Unknown sleep time format "x"\.$
Tests/RunCMake/CommandLine/E_sleep-bad-arg2-result.txt
0 → 100644
View file @
94389f63
1
Tests/RunCMake/CommandLine/E_sleep-bad-arg2-stderr.txt
0 → 100644
View file @
94389f63
^Unknown sleep time format "-1"\.$
Tests/RunCMake/CommandLine/E_sleep-no-args-result.txt
0 → 100644
View file @
94389f63
1
Tests/RunCMake/CommandLine/E_sleep-no-args-stderr.cmake
0 → 100644
View file @
94389f63
Usage: .*/cmake -E \[command\] \[arguments \.\.\.\]
Available commands:
Tests/RunCMake/CommandLine/RunCMakeTest.cmake
View file @
94389f63
...
...
@@ -23,3 +23,8 @@ if(UNIX)
${
CMAKE_COMMAND
}
-E create_symlink T .
)
endif
()
run_cmake_command
(
E_sleep-no-args
${
CMAKE_COMMAND
}
-E sleep
)
run_cmake_command
(
E_sleep-bad-arg1
${
CMAKE_COMMAND
}
-E sleep x
)
run_cmake_command
(
E_sleep-bad-arg2
${
CMAKE_COMMAND
}
-E sleep 1 -1
)
run_cmake_command
(
E_sleep-one-tenth
${
CMAKE_COMMAND
}
-E sleep 0.1
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment