cmake在Windows上生成错误,因为它使用uses作为转义序列 [英] cmake generate error on windows as it uses \ as escape seq
问题描述
我的cmake中有这样的东西:
I have something such as this in my cmake:
set(MyLib_SRC $ENV{MyLib_DIR}/MyLib.cpp)
add_library(MyLibrary STATIC ${MyLib_SRC})
但是当我运行cmake时,我正在收到此错误:
but when I ran the cmake, I am getting this error:
CMake Warning (dev) at CMakeLists.txt:97 (add_library):
Syntax error in cmake code when parsing string
D:\New\Development\Lib/myLib.cpp
Invalid escape sequence \N
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.
我阅读了此操作系统答案 cmake解析错误:无效的转义序列,但是如何将宏(哪个宏!)更改为函数?
I read this OS answer cmake parse error :Invalid escape sequence \o but How can I chang the macro (which macro!) to a function?
env变量的值是
MyLib_DIR=D:\New\Development\Lib
推荐答案
问题是 $ ENV {MyLib_DIR}
逐字扩展环境变量,包括用作路径分隔符的反斜杠。然后,这些可以重新解释为转义序列。
The problem is that $ENV{MyLib_DIR}
expands the environment variable verbatim, including the backslashes used as path separators. These can then get re-interpreted as escape sequences.
您要做的是在使用CMake代码处理之前,将路径转换为CMake的内部格式:
What you want to do is convert the path to CMake's internal format before handling it in CMake code:
file(TO_CMAKE_PATH $ENV{MyLib_DIR} MyLib_DIR)
set(MyLib_SRC ${MyLib_DIR}/MyLib.cpp)
add_library(MyLibrary STATIC ${MyLib_SRC})
这篇关于cmake在Windows上生成错误,因为它使用uses作为转义序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!