[CMake] Invalid escape sequence in macro

Stephan.Szabo at sony.com Stephan.Szabo at sony.com
Mon Mar 11 12:28:12 EDT 2019


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 <cmake-bounces at cmake.org> On Behalf Of Ramold, Felix
Sent: Monday, March 11, 2019 8:20 AM
To: cmake at 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 at 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


More information about the CMake mailing list