PROJECT (test) ADD_CUSTOM_TARGET ( SvnRevision ALL ${CMAKE_COMMAND} -E echo "1234" > svnrevision.txt # # This works under cmake version 2.4-patch 6 running under Windows with -G"MinGW Makefiles" # # This fails under cmake version 2.4-patch 7 running under Linux with -G"Unix Makefiles" # # Backslash escapes seem to fail with Unix generator under both O/S, see generated makefile rule in: # # .../CMakeFiles/SvnRevision.dir/build.make # # CMakeFiles/SvnRevision: # /usr/bin/cmake -E echo 1234 > svnrevision.txt # sed -e s/\(.*\)/#define\ SVN_REVISION\ \ r\1\"/" svnrevision.txt > svnrevision.h # # Inner two double quotes should have been retained, but instead last two have been generated. # # FYI, Windows "MinGW Makefiles" generator generates this: # # sed -e "s/\(.*\)/#define SVN_REVISION \" r\1\"/" svnrevision.txt > svnrevision.h # # FYI, Windows "Unix Makefiles" generator generates the same as when running on Linux: # # sed -e s/\(.*\)/#define\ SVN_REVISION\ \ r\1\"/" svnrevision.txt > svnrevision.h # # # PS: Unsure way there is an extra space in front of " r\1" in both. # # COMMAND sed -e "s/\\(.*\\)/#define SVN_REVISION \\"r\\1\\"/" svnrevision.txt > svnrevision.h # Dummy command without any backslashes just to prove basic rule is OK #COMMAND ${CMAKE_COMMAND} -E echo \\"#define SVN_REVISION \\" > svnrevision.h )