为什么这个cmake初始缓存文件会导致如此奇怪的错误? [英] Why does this cmake initial cache file result in such strange errors?

查看:357
本文介绍了为什么这个cmake初始缓存文件会导致如此奇怪的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件 /home/me/.config/Kitware/CMakeCache.txt ,其中包含一些我想在任何地方使用的初始缓存设置。我运行 cmake -C /home/me/.config/Kitware/CMakeCache.txt ,它在第3行中给了我这个文件解析错误:

I have a file /home/me/.config/Kitware/CMakeCache.txt that contains some initial cache settings I'd like to use everywhere. I run cmake -C /home/me/.config/Kitware/CMakeCache.txt and it gives me a parse error on line 3 with this file:

set(CMAKE_CXX_FLAGS "-march=native -mtune=native" CACHE STRING "Flags used by the compiler during all build types.")

set(CMAKE_CXX_FLAGS_DEBUG "-Og -ggdb" CACHE STRING "Flags used by the compiler during debug builds.")

这是我得到的错误:

CMake Error: Parse error in cache file /home/me/.config/Kitware/CMakeCache.txt on line 3. Offending entry: set(CMAKE_CXX_FLAGS_DEBUG "-Og -ggdb" CACHE STRING "Flags used by the compiler during debug builds.")

但是,如果我将行(添加 = )更改为:

But, if I change the line (adding =) to:

set(CMAKE_CXX_FLAGS_DEBUG "=-Og -ggdb" CACHE STRING "Flags used by the compiler during debug builds.")

它可以正常工作,但是在我的项目中生成的缓存文件包含ption设置为 =-Og -ggdb 。实际上, = 符号可以出现在整个 set 语句中的任何位置。但这无论您放在何处都会导致不同的问题。

it works fine, but then the resulting cache file in my project has the option set to =-Og -ggdb. In fact, the = sign can appear anywhere in the entire set statement. But it results in different problems no matter where you put it.

如果我将文件重命名为 /home/me/.config/Kitware/ default.cmake (或除 CMakeCache.txt 以外的其他任何东西,它也可以正常工作,不需要 = 登录每个选项的值。

If I rename the file to /home/me/.config/Kitware/default.cmake (or anything else besides CMakeCache.txt it also works fine and doesn't require an = sign in the value for every option.

这是非常奇怪的行为,我不理解。这是怎么回事?

This is very weird behavior, and I don't understand it. What's going on here?

推荐答案

将我的评论变成答案

参见 cmake.cxx :命令行中名称为 cmakelists.txt cmakecache.txt 的任何内容

因此CMake在这里忽略了 -C 选项,并尝试加载您的 CMakeCache.txt 作为实际的变量缓存文件。这些文件的格式/语法也不同,为 NAME:TYPE = VALUE

So CMake is ignoring your -C option here and tries to load your CMakeCache.txt as an actual variable cache file. And those files have a different formatting/syntax of NAME:TYPE=VALUE.

您可以将此行为视为CMake中的错误。或只是避免使用 CMakeCache.txt 作为初始缓存文件名。

You can consider this behavior a bug in CMake. Or you just avoid using CMakeCache.txt for your initial cache file name.

这篇关于为什么这个cmake初始缓存文件会导致如此奇怪的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆