[CMake] Backslash expansion of double quotes different for MinGW and Unix generators

Trevor Kellaway tkellaway at asl-vision.co.uk
Sun Oct 5 13:16:57 EDT 2008


Hi (Bill / Alex),
 <<CMakeLists.txt>> 
 
I've recently been getting my CMake project building under Linux as well
as my existing Windows MinGW environment.

One difference that cropped up is the following custom rule, which
builds a header file with svn revision number in it (simplified in this
example). The escaping of the double quotes seems to behave differently
for the CMake "MinGW" and "Unix" generators, with the Unix version
mucking up the handling of the backslash double quoted escapes.

See example dummy project below (file also attached):
 
 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
	)

Any idea what's going on here?

The only workaround to avoid use of "sed" is either put the sed edit
rule in a file, or use a CMake template (e.g. svnrevision.h.in) and
replace with a variable read in from a file containing svn version.

-Trev
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CMakeLists.txt
URL: <http://www.cmake.org/pipermail/cmake/attachments/20081005/aa318597/attachment.txt>


More information about the CMake mailing list