[CMake] COMMAND does not accept standard method of splitting stderr and stdout results

Michael Wild themiwi at gmail.com
Wed Mar 17 17:57:28 EDT 2010


On 17. Mar, 2010, at 21:46 , Alan W. Irwin wrote:

> On 2010-03-17 20:21+0100 Michael Wild wrote:
> 
>> Thing is, cmake is neither bash nor ksh, else it would be called cash ;-)
> 
> True, but COMMAND does execute a command on the command line, and on the
> Unix side of things that must involve the shell.  To confirm that, note that
> the Makefiles generated by CMake have the following two lines (at least on
> Linux.  I am sure other Unices have something similar to refer to the
> Bourne-compatible family of shells)
> 
> # The shell in which to execute make rules.
> SHELL = /bin/sh
> 
> So if CMake screws up standard sh syntax (and I am pretty sure that "Unix in
> a nutshell" does emphasize the lowest-common-denominator, bog-standard sh
> syntax), then CMake is crippled more than it needs to be.
> 
>> 
>> To do what you want to do in a platform independent way, is to wrap your command in a .cmake script and in there use EXECUTE_PROCESS, where you have the OUTPUT_VARIABLE, OUTPUT_FILE, ERROR_VARIABLE and ERROR_FILE options.
>> 
> 
> That's a good idea for a single instance, but that might get a little
> complicated if you have hundreds of these. Dave's idea of a single shell
> script to work around this issue is pretty simple and should work for all my
> instances so that is what I will use.
> 
> Despite the availability of workarounds, I still think a useful goal is for
> CMake not to mess up bog-standard sh syntax (such as the syntax covered in
> "Unix in a nutshell") so that the necessity of workarounds is considerably
> reduced.

Well, you still could use a cmake script like a normal shell script, passing the arguments using -D flags...

I just tried a few things, and it seems that you can use eval to your advantage:

project(test C)
add_custom_command(OUTPUT bla.stderr bla.stdout
  COMMAND eval
    "((echo 'this is stdout'; echo 'this is stderr' >&2) > bla.stdout) 2> bla.stderr"
  VERBATIM
  )
add_custom_target(bla ALL DEPENDS bla.stderr bla.stdout VERBATIM)


Tried it with the "Unix Makefiles" and "Xcode" generators, works for both.

Michael



More information about the CMake mailing list