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
Brad King
CMake
Commits
602988e1
Commit
602988e1
authored
Jan 26, 2018
by
Shane Parris
Browse files
Adds file(TOUCH) and file(TOUCH_NOCREATE) sub-commands
parent
a2ec98b7
Changes
15
Hide whitespace changes
Inline
Side-by-side
Help/command/file.rst
View file @
602988e1
...
...
@@ -283,6 +283,23 @@ If neither ``TLS`` option is given CMake will check variables
------------------------------------------------------------------------------
::
file(TOUCH [<files>...])
file(TOUCH_NOCREATE [<files>...])
Create a file with no content if it does not yet exist. If the file already
exists, its access and/or modification will be updated to the time when the
function call is executed.
Use TOUCH_NOCREATE to touch a file if it exists but not create it. If a file
does not exist it will be silently ignored.
With TOUCH and TOUCH_NOCREATE the contents of an existing file will not be
modified.
------------------------------------------------------------------------------
::
file(TIMESTAMP <filename> <variable> [<format>] [UTC])
...
...
Help/release/dev/file_cmd_touch.rst
0 → 100644
View file @
602988e1
file_cmd_touch
------------------
* The :command:`file(TOUCH)` and :command:`file(TOUCH_NOCREATE)` commands
were added to expose TOUCH functionality without having to use CMake's
command-line tool mode with :command:`execute_process`.
Source/cmFileCommand.cxx
View file @
602988e1
...
...
@@ -160,6 +160,12 @@ bool cmFileCommand::InitialPass(std::vector<std::string> const& args,
if
(
subCommand
==
"TO_NATIVE_PATH"
)
{
return
this
->
HandleCMakePathCommand
(
args
,
true
);
}
if
(
subCommand
==
"TOUCH"
)
{
return
this
->
HandleTouchCommand
(
args
,
true
);
}
if
(
subCommand
==
"TOUCH_NOCREATE"
)
{
return
this
->
HandleTouchCommand
(
args
,
false
);
}
if
(
subCommand
==
"TIMESTAMP"
)
{
return
this
->
HandleTimestampCommand
(
args
);
}
...
...
@@ -905,6 +911,38 @@ bool cmFileCommand::HandleMakeDirectoryCommand(
return
true
;
}
bool
cmFileCommand
::
HandleTouchCommand
(
std
::
vector
<
std
::
string
>
const
&
args
,
bool
create
)
{
// File command has at least one argument
assert
(
args
.
size
()
>
1
);
std
::
vector
<
std
::
string
>::
const_iterator
i
=
args
.
begin
();
i
++
;
// Get rid of subcommand
for
(;
i
!=
args
.
end
();
++
i
)
{
std
::
string
tfile
=
*
i
;
if
(
!
cmsys
::
SystemTools
::
FileIsFullPath
(
tfile
))
{
tfile
=
this
->
Makefile
->
GetCurrentSourceDirectory
();
tfile
+=
"/"
+
*
i
;
}
if
(
!
this
->
Makefile
->
CanIWriteThisFile
(
tfile
))
{
std
::
string
e
=
"attempted to touch a file: "
+
tfile
+
" in a source directory."
;
this
->
SetError
(
e
);
cmSystemTools
::
SetFatalErrorOccured
();
return
false
;
}
if
(
!
cmSystemTools
::
Touch
(
tfile
,
create
))
{
std
::
string
error
=
"problem touching file: "
+
tfile
;
this
->
SetError
(
error
);
return
false
;
}
}
return
true
;
}
bool
cmFileCommand
::
HandleDifferentCommand
(
std
::
vector
<
std
::
string
>
const
&
args
)
{
...
...
Source/cmFileCommand.h
View file @
602988e1
...
...
@@ -39,6 +39,7 @@ protected:
bool
HandleHashCommand
(
std
::
vector
<
std
::
string
>
const
&
args
);
bool
HandleStringsCommand
(
std
::
vector
<
std
::
string
>
const
&
args
);
bool
HandleGlobCommand
(
std
::
vector
<
std
::
string
>
const
&
args
,
bool
recurse
);
bool
HandleTouchCommand
(
std
::
vector
<
std
::
string
>
const
&
args
,
bool
create
);
bool
HandleMakeDirectoryCommand
(
std
::
vector
<
std
::
string
>
const
&
args
);
bool
HandleRelativePathCommand
(
std
::
vector
<
std
::
string
>
const
&
args
);
...
...
Source/cmcmd.cxx
View file @
602988e1
...
...
@@ -689,8 +689,6 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
// Touch file
if
(
args
[
1
]
==
"touch_nocreate"
&&
args
.
size
()
>
2
)
{
for
(
std
::
string
::
size_type
cc
=
2
;
cc
<
args
.
size
();
cc
++
)
{
// Complain if the file could not be removed, still exists,
// and the -f option was not given.
if
(
!
cmSystemTools
::
Touch
(
args
[
cc
],
false
))
{
return
1
;
}
...
...
Tests/RunCMake/file/RunCMakeTest.cmake
View file @
602988e1
...
...
@@ -5,6 +5,9 @@ run_cmake(DOWNLOAD-unused-argument)
run_cmake
(
DOWNLOAD-httpheader-not-set
)
run_cmake
(
DOWNLOAD-netrc-bad
)
run_cmake
(
DOWNLOAD-pass-not-set
)
run_cmake
(
TOUCH
)
run_cmake
(
TOUCH-error-in-source-directory
)
run_cmake
(
TOUCH-error-missing-directory
)
run_cmake
(
UPLOAD-unused-argument
)
run_cmake
(
UPLOAD-httpheader-not-set
)
run_cmake
(
UPLOAD-netrc-bad
)
...
...
Tests/RunCMake/file/TOUCH-error-in-source-directory-result.txt
0 → 100644
View file @
602988e1
1
Tests/RunCMake/file/TOUCH-error-in-source-directory-stderr.txt
0 → 100644
View file @
602988e1
.*file attempted to touch a file:
Tests/RunCMake/file/TOUCH-error-in-source-directory.cmake
0 → 100644
View file @
602988e1
set
(
CMAKE_DISABLE_SOURCE_CHANGES ON
)
file
(
TOUCH
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/touch_test"
)
Tests/RunCMake/file/TOUCH-error-missing-directory-result.txt
0 → 100644
View file @
602988e1
1
Tests/RunCMake/file/TOUCH-error-missing-directory-stderr.txt
0 → 100644
View file @
602988e1
.*file problem touching file:
Tests/RunCMake/file/TOUCH-error-missing-directory.cmake
0 → 100644
View file @
602988e1
file
(
TOUCH
"
${
CMAKE_CURRENT_BINARY_DIR
}
/missing/directory/file.to-touch"
)
Tests/RunCMake/file/TOUCH-result.txt
0 → 100644
View file @
602988e1
1
Tests/RunCMake/file/TOUCH-stderr.txt
0 → 100644
View file @
602988e1
^CMake Error at TOUCH\.cmake:[0-9]+ \(file\):
file must be called with at least two arguments\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)
+
CMake Error at TOUCH\.cmake:[0-9]+ \(file\):
file must be called with at least two arguments\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)
Tests/RunCMake/file/TOUCH.cmake
0 → 100644
View file @
602988e1
set
(
file
"
${
CMAKE_CURRENT_BINARY_DIR
}
/file-to-touch"
)
file
(
REMOVE
"
${
file
}
"
)
file
(
TOUCH_NOCREATE
"
${
file
}
"
)
if
(
EXISTS
"
${
file
}
"
)
message
(
FATAL_ERROR
"error: TOUCH_NOCREATE created a file!"
)
endif
()
file
(
TOUCH
"
${
file
}
"
)
if
(
NOT EXISTS
"
${
file
}
"
)
message
(
FATAL_ERROR
"error: TOUCH did not create a file!"
)
endif
()
file
(
REMOVE
"
${
file
}
"
)
file
(
TOUCH
)
file
(
TOUCH_NOCREATE
)
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