Re: [CMake] Invalid escape sequence in macro
Thank you, Steph This might be related. I think the macro somehow resolves the escapes before executing the marco commands. Today I found out, this error is much worse in a project (instead of a script). Please see the updated code (now we escape correctly at declaration): function(f STRING) message(STATUS "In function: ${STRING}") endfunction() macro(m STRING) message(STATUS "In macro: ${STRING}") endmacro() set(CONTENT "bla bla \\/\\/") message(STATUS "No call1: ${CONTENT}") f(${CONTENT}) m(${CONTENT}) message(STATUS "No call2: ${CONTENT}") Output: C:\Program Files\CMake\cmake-3.13.4-win64-x64\bin>cmake -P test.cmake -- No call1: bla bla \/\/ -- In function: bla bla \/\/ CMake Warning (dev) at test.cmake:6 (message): Syntax error in cmake code at C:/Program Files/CMake/cmake-3.13.4-win64-x64/bin/test.cmake:6 when parsing string In macro: bla bla \/\/ Invalid escape sequence \/ Policy CMP0010 is not set: Bad variable reference syntax is an error. Run "cmake --help-policy CMP0010" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Call Stack (most recent call first): test.cmake:12 (m) This warning is for project developers. Use -Wno-dev to suppress it. -- In macro: bla bla \/\/ -- No call2: bla bla \/\/ Tthis gets way worse when it is a project: project(testEscape) cmake_minimum_required(VERSION 3.10) ... The error is not reported. Silently the string is modified and printed wrongly! C:\Program Files\CMake>cmake-3.13.4-win64-x64\bin\cmake.exe . -Bbuild313 -- Building for: Visual Studio 14 2015 -- The C compiler identification is MSVC 19.0.23918.0 -- The CXX compiler identification is MSVC 19.0.23918.0 -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- No call1: bla bla \/\/ -- In function: bla bla \/\/ -- In macro: bla bla // -- No call2: bla bla \/\/ -- Configuring done -- Generating done -- Build files have been written to: C:/Program Files/CMake/build313 Note that previous policies stopped configuration. Change cmake_minimum_required(VERSION 3.0) And you get: ... -- No call1: bla bla \& -- In function: bla bla \& CMake Error at CMakeLists.txt:9 (message): Syntax error in cmake code at C:/Program Files/CMake/CMakeLists.txt:9 when parsing string In macro: bla bla \& Invalid escape sequence \& Call Stack (most recent call first): CMakeLists.txt:15 (m) -- Configuring incomplete, errors occurred! Regards, Felix -Ursprüngliche Nachricht- Von: stephan.sz...@sony.com [mailto:stephan.sz...@sony.com] Gesendet: Montag, 11. März 2019 17:28 An: Ramold, Felix; cmake@cmake.org Betreff: RE: Invalid escape sequence in macro I would expect that you're running into a consequence of: "In a function, ARGN, ARGC, ARGV and ARGV0, ARGV1, ... are true variables in the usual CMake sense. In a macro, they are not, they are string replacements much like the C preprocessor would do with a macro." So I would expect the backslash escapes are done first on the set line, and then the value of the variable after the escaping are replaced into the message line in the macro which will then try to handle escapes again. It seems like a function may be better for this sort of thing, but what does the actual use case look like? Regards, Steph -Original Message- From: CMake On Behalf Of Ramold, Felix Sent: Monday, March 11, 2019 8:20 AM To: cmake@cmake.org Subject: [CMake] Invalid escape sequence in macro Hi, today i ran into an error with escape characters in macros. Is this a known issue? Is this by design? How can I workaround? Code: function(f STRING) message(STATUS ${STRING}) endfunction() macro(m STRING) message(STATUS ${STRING}) endmacro() set(CONTENT "bla bla \/\/") message(STATUS ${CONTENT}) f(${CONTENT}) m(${CONTENT}) Output: ramold@xxx MINGW64 /c/Program Files/CMake/cmake-3.13.4-win64-x64/bin $ ./cmake.exe -P test.cmake CMake Warning (dev) at test.cmake:9 (set): Syntax error in cmake code at C:/Program Files/CMake/cmake-3.13.4-win64-x64/bin/test.cmake:9 when parsing string bla bla \/\/ Invalid escape sequence \/ Policy CMP0010 is not set: Bad variable reference syntax is an error. Run "
Re: [CMake] Invalid escape sequence in macro
I would expect that you're running into a consequence of: "In a function, ARGN, ARGC, ARGV and ARGV0, ARGV1, ... are true variables in the usual CMake sense. In a macro, they are not, they are string replacements much like the C preprocessor would do with a macro." So I would expect the backslash escapes are done first on the set line, and then the value of the variable after the escaping are replaced into the message line in the macro which will then try to handle escapes again. It seems like a function may be better for this sort of thing, but what does the actual use case look like? Regards, Steph -Original Message- From: CMake On Behalf Of Ramold, Felix Sent: Monday, March 11, 2019 8:20 AM To: cmake@cmake.org Subject: [CMake] Invalid escape sequence in macro Hi, today i ran into an error with escape characters in macros. Is this a known issue? Is this by design? How can I workaround? Code: function(f STRING) message(STATUS ${STRING}) endfunction() macro(m STRING) message(STATUS ${STRING}) endmacro() set(CONTENT "bla bla \/\/") message(STATUS ${CONTENT}) f(${CONTENT}) m(${CONTENT}) Output: ramold@xxx MINGW64 /c/Program Files/CMake/cmake-3.13.4-win64-x64/bin $ ./cmake.exe -P test.cmake CMake Warning (dev) at test.cmake:9 (set): Syntax error in cmake code at C:/Program Files/CMake/cmake-3.13.4-win64-x64/bin/test.cmake:9 when parsing string bla bla \/\/ Invalid escape sequence \/ Policy CMP0010 is not set: Bad variable reference syntax is an error. Run "cmake --help-policy CMP0010" for policy details. Use the cmake_policy command to set the policy and suppress this warning. This warning is for project developers. Use -Wno-dev to suppress it. -- bla bla \/\/ -- bla bla \/\/ CMake Warning (dev) at test.cmake:6 (message): Syntax error in cmake code at C:/Program Files/CMake/cmake-3.13.4-win64-x64/bin/test.cmake:6 when parsing string bla bla \/\/ Invalid escape sequence \/ Policy CMP0010 is not set: Bad variable reference syntax is an error. Run "cmake --help-policy CMP0010" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Call Stack (most recent call first): test.cmake:12 (m) This warning is for project developers. Use -Wno-dev to suppress it. -- bla bla \/\/ Regards, Felix Ramold -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
[CMake] Invalid escape sequence in macro
Hi, today i ran into an error with escape characters in macros. Is this a known issue? Is this by design? How can I workaround? Code: function(f STRING) message(STATUS ${STRING}) endfunction() macro(m STRING) message(STATUS ${STRING}) endmacro() set(CONTENT "bla bla \/\/") message(STATUS ${CONTENT}) f(${CONTENT}) m(${CONTENT}) Output: ramold@xxx MINGW64 /c/Program Files/CMake/cmake-3.13.4-win64-x64/bin $ ./cmake.exe -P test.cmake CMake Warning (dev) at test.cmake:9 (set): Syntax error in cmake code at C:/Program Files/CMake/cmake-3.13.4-win64-x64/bin/test.cmake:9 when parsing string bla bla \/\/ Invalid escape sequence \/ Policy CMP0010 is not set: Bad variable reference syntax is an error. Run "cmake --help-policy CMP0010" for policy details. Use the cmake_policy command to set the policy and suppress this warning. This warning is for project developers. Use -Wno-dev to suppress it. -- bla bla \/\/ -- bla bla \/\/ CMake Warning (dev) at test.cmake:6 (message): Syntax error in cmake code at C:/Program Files/CMake/cmake-3.13.4-win64-x64/bin/test.cmake:6 when parsing string bla bla \/\/ Invalid escape sequence \/ Policy CMP0010 is not set: Bad variable reference syntax is an error. Run "cmake --help-policy CMP0010" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Call Stack (most recent call first): test.cmake:12 (m) This warning is for project developers. Use -Wno-dev to suppress it. -- bla bla \/\/ Regards, Felix Ramold -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake