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 "
[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
Re: [CMake] --warn-uninitialized works in only first configuration
It is not a cache variable. Here is an example: cmake_minimum_required(VERSION 3.10) project(TEST_UNINITIALIZED) file(WRITE dummy.cpp "") add_library(dummy dummy.cpp ${UNINITIALIZED}) Also UNINITIALIZED is not added to CMakeCache.txt. Calling cmake twice (even without a change to the list) also shows this warning. -Ursprüngliche Nachricht- Von: Robert Maynard [mailto:robert.mayn...@kitware.com] Gesendet: Montag, 4. Februar 2019 18:16 An: Ramold, Felix Cc: cmake@cmake.org Betreff: Re: [CMake] --warn-uninitialized works in only first configuration This generally occurs with CACHE variables as for non first runs they exist in the cache and therefore are initialized. On Mon, Feb 4, 2019 at 10:16 AM Ramold, Felix wrote: > > Hi, > > > > I configure a project with --warn-uninitialized and get a lot of warnings. I > successfully run the build. > > Then I change any CMakeLists.txt file. I run the build again. CMake checks > its dependencies and reconfigures before the actual build. > > Those warnings (or at least those in the edited file) don’t appear again. > > Is this the standard behavior? > > > > Thanks, > > Felix > > -- > > 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 D:\CMake>cmake . -BBuild --warn-uninitialized Warn about uninitialized values. -- 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 -- 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 CMake Warning (dev) at CMakeLists.txt:5 (add_library): uninitialized variable 'UNINITIALIZED' This warning is for project developers. Use -Wno-dev to suppress it. -- Configuring done -- Generating done -- Build files have been written to: D:/CMake/Build D:\CMake>cmake . -BBuild --warn-uninitialized Warn about uninitialized values. CMake Warning (dev) at CMakeLists.txt:5 (add_library): uninitialized variable 'UNINITIALIZED' This warning is for project developers. Use -Wno-dev to suppress it. -- Configuring done -- Generating done -- Build files have been written to: D:/CMake/Build D:\CMake>cmake --build Build Microsoft (R)-Buildmodul, Version 14.0.25123.0 Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. Der Buildvorgang wurde am 05.02.2019 18:03:39 gestartet. Projekt "D:\CMake\Build\ALL_BUILD.vcxproj" auf Knoten "1" (Standardziele). Das Projekt "D:\CMake\Build\ALL_BUILD.vcxproj" (1) erstellt "D:\CMake\Build\ZERO_CHECK.vcxproj" (2) auf Knoten "1" (Standardziele). PrepareForBuild: Das Verzeichnis "Win32\Debug\ZERO_CHECK\" wird erstellt. Das Verzeichnis "D:\CMake\Build\Debug\" wird erstellt. Das Verzeichnis "Win32\Debug\ZERO_CHECK\ZERO_CHECK.tlog\" wird erstellt. InitializeBuildStatus: "Win32\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild" wird erstellt, da "AlwaysCreate" angegeben wurde. CustomBuild: Checking Build System CMake does not need to re-run because D:/CMake/Build/CMakeFiles/generate.stamp is up-to-date. FinalizeBuildStatus: Die Datei "Win32\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild" wird gelöscht. Aktualisieren des Timestamps von "Win32\Debug\ZERO_CHECK\ZERO_CHECK.tlog\ZERO_CHECK.lastbuildstate". Die Erstellung von Projekt "D:\CMake\Build\ZERO_CHECK.vcxproj" ist abgeschlossen (Standardziele). Das Projekt "D:\CMake\Build\ALL_BUILD.vcxproj" (1) erstellt "D:\CMake\Build\dummy.vcxproj" (3) auf Knoten "1" (Standardziele). PrepareForBuild: Das Verzeichnis "dummy.dir\Debug\" wird erstellt. Das Verzei
[CMake] --warn-uninitialized works in only first configuration
Hi, I configure a project with --warn-uninitialized and get a lot of warnings. I successfully run the build. Then I change any CMakeLists.txt file. I run the build again. CMake checks its dependencies and reconfigures before the actual build. Those warnings (or at least those in the edited file) don't appear again. Is this the standard behavior? Thanks, Felix -- 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] Testing our CMake Modules
We created multiple additional functions for CMake. They became quite a lot, and we need to (unit) test them. There are simple ones, that are only variable bases like: function(join_list LIST GLUE) These can be tested with a custom CMake Script, that checks the results. For this we also wrote a set of assert-macros. This becomes way harder when the functions are target based: function(target_my_custom_property_set TARGET VALUE) We need a multiple CMakeLists.txt Files that need to be configured. Configuration must succeed or fail with specified messages. Also the result files must be checked. I wonder, is there an easier way? Is there a existing framework? How does Kitware test the shipped modules? Note: My original Stackoverflow question: https://stackoverflow.com/questions/51948060/testing-our-cmake-modules Thanks, Felix -- 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