Eric Noulard <eric.noul...@gmail.com> writes: > I think you are wrong. > > May be you can try the attach script. > > try: > cmake -DYOURSTRING="I like # \ it" -DTHE_FILE=toto.txt -P writeany.cmake > > You shouldn't have "quite" problem with the previous approach.
I tried this on Linux: add_custom_command(OUTPUT ${EMACS_BUILD_DIR}/src/buildobj.h COMMAND cmake -DYOURSTRING="#define BUILDOBJ" -DTHE_FILE=buildobj.h -P writeany.cmake COMMENT "Creating buildobj.h" ) It didn't create the file. So tried this: add_custom_command(OUTPUT ${EMACS_BUILD_DIR}/src/buildobj.h COMMAND cmake -DYOURSTRING="\#define BUILDOBJ" -DTHE_FILE=buildobj.h -P writeany.cmake COMMENT "Creating buildobj.h" ) It put this text on the resulting file: #define\ BUILDOBJ That's not quite what I wanted. I would say that having to write and invoke a script for this trivial task seems way too much trouble imposed by an otherwise absolute time-saver as cmake is. >> The task here is to write a literal string containing a "special" >> character (#) to a file, at build time. For "cmake -E echo" it requires >> platform-dependent escape sequences. My idea about the cmake -E commands >> was that they purpose is to abstract platform differences, but seems >> that that is not entirely correct, as they inherit some traits from the >> underlying platform. Or is it a bug? > > I would say a feature :-) > > You do not want to have to "escape" some sequences I'm happy escaping whatever as much sequences as necessary. What is not okay is to change escape rules depending on the plataform (or worse, depending on the shell cmake uses for the generator. "Mingw Makefiles" -> cmd.exe, "MSYS Makefiles" -> sh.exe) [snip] > More seriously I think it's complicated to avoid system specific > issues with a command like "echo". It should be possible to pass an arbitrary string (containing backslashes if necessary) to "echo" and send it to the console or redirected to a file on a platform independent way. That means avoiding any middleman that may reinterpret certain characters as per its own rules. If you pass the string through the shell, all hopes of platform independence are gone. > I think that if you tell me what you would expect I may probably gives > you an example of mine were YOUR bug is a feature for ME. I doubt that, because on the end we want the same: saying "take this string and put it on that file." We can then open the file and test that, effectively, the string is there. OTOH I can't think of a real application for this sort of behavior of the "echo" command. That is, nothing that you could achieve invoking the platform's shell. > That said, that's my own opinion, I may be wrong. _______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake