[CMake] ADD_CUSTOM_COMMAND, crating file with echo redirection, platform independent

Arne Pagel arne at pagelnet.de
Wed Oct 27 14:02:47 EDT 2010


Hello,

I need a custom command in my build process.
The tool that I am using has a small problem, I have to insert a line of code in
the output file manually:
#include <gtk/gtk.h>

I tried this with echo and output redirection:
echo "#include <gtk/gtk.h>" > images.c

The tool, gdk-pixbuf-csource, is not able to generate a file, therefor its output has to be 
redirected to the file too:
gdk-pixbuf-csource --raw pix1 ./images/pix1.png >> images.c

I can get it work one linux and win32 system, but with different syntax:

This works on a win32 System:

ADD_CUSTOM_COMMAND (OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/images.c
		    COMMAND ${CMAKE_COMMAND} -E echo "\#include <gtk/gtk.h>" > images.c
                     COMMAND gdk-pixbuf-csource --raw pix1 ./images/pix1.png >> images.c
                     DEPENDS ./images/pix1.png )


This works on a linux System:

ADD_CUSTOM_COMMAND (OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/images.c
                     COMMAND echo "\"""#include""<gtk/gtk.h>" "\"" > images.c
                     COMMAND gdk-pixbuf-csource --raw pix1 ./images/pix1.png >> images.c
                     DEPENDS ./images/pix1.png )

I tried many variations of above examples, but I can't get running on both systems with the same 
syntax, any idea what might be right?

Perhaps there is another way then "echo" to write something in a file, I tried FILE(WRITE) but I 
failed with this.

I could make a file with the include line already inserted and than try to copy it, I saw some 
commands for that, is this the better Way? Actually I don't prefer this, I don't want to have a 
strange single-line source file in the project.

regards
   Arne


More information about the CMake mailing list