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
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
                                        )
_______________________________________________
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to