View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015242CMakeCMakepublic2014-11-11 13:002016-06-10 14:31
ReporterIlya 
Assigned ToKitware Robot 
PrioritynormalSeverityfeatureReproducibilityalways
StatusclosedResolutionmoved 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0015242: Teach the "cmake -E echo" command to write to a file.
DescriptionThere 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.
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0037180)
Brad King (manager)
2014-11-11 13:05

In an add_custom_command one can do

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

or put into foo.cmake:

file(WRITE ...)

And then run cmake -P foo.cmake.
(0037183)
Ilya (reporter)
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 (manager)
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 (reporter)
2014-11-18 13:42

When it's started out of shell.
(0037234)
Brad King (manager)
2014-11-19 10:31

Please provide a code example.
(0039134)
dbanet (reporter)
2015-07-14 03:49

Up?
(0039138)
Ilya (reporter)
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 (manager)
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 (reporter)
2015-07-14 12:46
edited on: 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 (manager)
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 (reporter)
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 (manager)
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 (administrator)
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.

 Issue History
Date Modified Username Field Change
2014-11-11 13:00 Ilya New Issue
2014-11-11 13:05 Brad King Note Added: 0037180
2014-11-11 13:27 Rolf Eike Beer Note Added: 0037182
2014-11-11 13:45 Ilya Note Added: 0037183
2014-11-11 13:51 Brad King Note Added: 0037184
2014-11-18 13:42 Ilya Note Added: 0037232
2014-11-19 10:31 Brad King Note Added: 0037234
2015-07-14 03:49 dbanet Note Added: 0039134
2015-07-14 10:45 Ilya Note Added: 0039138
2015-07-14 11:07 Brad King Note Added: 0039139
2015-07-14 12:46 Ilya Note Added: 0039140
2015-07-14 12:46 Ilya Note Edited: 0039140
2015-07-14 13:12 Brad King Note Added: 0039141
2015-07-14 13:14 Ilya Note Added: 0039142
2015-07-14 13:29 Brad King Note Added: 0039143
2016-06-10 14:29 Kitware Robot Note Added: 0042663
2016-06-10 14:29 Kitware Robot Status new => resolved
2016-06-10 14:29 Kitware Robot Resolution open => moved
2016-06-10 14:29 Kitware Robot Assigned To => Kitware Robot
2016-06-10 14:31 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team