[CMake] Does the echo command use the system shell?

Óscar Fuentes ofv at wanadoo.es
Wed Jul 28 13:19:08 EDT 2010


For creating a file at build time with a content like this:

#define foo "bar"

I use this on Linux:

add_custom_command(OUTPUT buildobj.h
  COMMAND ${CMAKE_COMMAND} -E echo "\\#define foo \\\"bar\\\""
  > buildobj.h
  )

but that doesn't work on Windows, because it outpus:

\#define foo "bar"

Removing the backslashes before `#' fixes the problem on Windows, but
then breaks the Linux build.

This looks as if `echo' was using the system shell for doing the job,
because the escapes works differently on each system.

What's the right way to write the above command so it works on all
platforms?



More information about the CMake mailing list