MantisBT - CMake
View Issue Details
0015242CMakeCMakepublic2014-11-11 13:002016-06-10 14:31
Ilya 
Kitware Robot 
normalfeaturealways
closedmoved 
 
 
0015242: Teach the "cmake -E echo" command to write to a file.
There are commands to create files, copy files and print strings to stdout. And cmake already supports the file(WRITE) command.

Having a cross-platform solution to write to files or at least to create files with content would be awesome.
No tags attached.
Issue History
2014-11-11 13:00IlyaNew Issue
2014-11-11 13:05Brad KingNote Added: 0037180
2014-11-11 13:27Rolf Eike BeerNote Added: 0037182
2014-11-11 13:45IlyaNote Added: 0037183
2014-11-11 13:51Brad KingNote Added: 0037184
2014-11-18 13:42IlyaNote Added: 0037232
2014-11-19 10:31Brad KingNote Added: 0037234
2015-07-14 03:49dbanetNote Added: 0039134
2015-07-14 10:45IlyaNote Added: 0039138
2015-07-14 11:07Brad KingNote Added: 0039139
2015-07-14 12:46IlyaNote Added: 0039140
2015-07-14 12:46IlyaNote Edited: 0039140bug_revision_view_page.php?bugnote_id=39140#r1847
2015-07-14 13:12Brad KingNote Added: 0039141
2015-07-14 13:14IlyaNote Added: 0039142
2015-07-14 13:29Brad KingNote Added: 0039143
2016-06-10 14:29Kitware RobotNote Added: 0042663
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0037180)
Brad King   
2014-11-11 13:05   
In an add_custom_command one can do

 cmake -E echo text > file.txt
(0037182)
Rolf Eike Beer   
2014-11-11 13:27   
or put into foo.cmake:

file(WRITE ...)

And then run cmake -P foo.cmake.
(0037183)
Ilya   
2014-11-11 13:45   
The problem with cmake -P solution is that one will have to supply additional file which is less intuitive then having a line in code. From the perspective of someone who will need to understand build scripts it will raise more questions than answers

As of the shell redirect operator: as I was pointed out in IRC it does not work under all contexts.
(0037184)
Brad King   
2014-11-11 13:51   
Re 0015242:0037183: In what context do you need this to work in which shell redirection does not work? I've used it in many projects.
(0037232)
Ilya   
2014-11-18 13:42   
When it's started out of shell.
(0037234)
Brad King   
2014-11-19 10:31   
Please provide a code example.
(0039134)
dbanet   
2015-07-14 03:49   
Up?
(0039138)
Ilya   
2015-07-14 10:45   
E.g. when you start cmake from Python:

    import subprocess
    subprocess.check_call(['cmake', …], shell=False)

Note, that it's from a comment from IRC made (I believe) by one of developers.
(0039139)
Brad King   
2015-07-14 11:07   
Re 0015242:0039138: Try:

import subprocess
out = open('output.txt', 'w')
subprocess.check_call(['cmake', '-E', 'echo', 'message'], shell=False, stdout=out)
out.close()
(0039140)
Ilya   
2015-07-14 12:46   
Brad, sorry for misleading you.

I wanted to use cmake -E echo from cmake scripts to write to a file at build time. My cmake scripts can be run from something like python.

(0039141)
Brad King   
2015-07-14 13:12   
Re 0015242:0039140: I do not understand what you're trying to do. Please provide a sample source tarball showing your use case with a comment where you'd like the new option to be used.

Even the bash "echo" command does not support explicit options for writing to a file because one can always redirect stdout. It is not the job of every tool to have an option to write output to a file.
(0039142)
Ilya   
2015-07-14 13:14   
Bash's echo does not have an option for writing to a file, because it's supposed to be run in bash.

My case is that one of custom commands in cmake script needs to write something to a file. That cmake script can be started out of shell.

If > is guaranteed to work in this scenario, then ok, but I was just pointe in IRC that it may not work.
(0039143)
Brad King   
2015-07-14 13:29   
Re 0015242:0039142: Without an example source tarball to show your use case concretely I cannot help further.
(0042663)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.