如何告诉CMake使用相对路径 [英] How to tell CMake to use relative paths
问题描述
如果我创建项目,则可以看到以下内容:
If I make my project I can see this:
[ 50%] Building C object CMakeFiles/hello.dir/hello.c.obj
/cygdrive/c/users/me/Home/bin/iccarm /cygdrive/c/users/me/Home/sandbox/iar/hello.c -I/cygdrive/c/users/me/Home/sandbox/iar/foo -I/cygdrive/c/users/me/Home/inc -o CMakeFiles/hello.dir/hello.c.obj
因为我总是在 build
目录中调用 make
,为什么不使用相对路径以提高可读性和跨操作系统的兼容性?
Since I always call make
inside my build
directory, why not using relative path for the sake of readability and compatibility across operating systems?
[ 50%] Building C object CMakeFiles/hello.dir/hello.c.obj
iccarm hello.c -Ifoo -Iinc -o CMakeFiles/hello.dir/hello.c.obj
不是更好吗?
有没有办法强迫CMake尽可能多地使用相对路径
Is there a way to force CMake to use relative paths as much as possible?
推荐答案
CMake始终使用绝对路径。这是概念的一部分。因此,您将无法移动生成的构建环境文件,例如将它们置于源代码控制之下或使详细输出变得更漂亮(您可以对
CMake does always use absolute paths. It's part of the concept. Therefore you can't move the generated build environment files nor can you e.g. bring them under source control or make the verbose output prettier (you could just play a little with the rule messages like here).
曾经是 CMAKE_USE_RELATIVE_PATHS
,但文档显示:
There once was CMAKE_USE_RELATIVE_PATHS
, but the documentation reveals:
此变量无效。在CMake 3.4中已删除了它在先前版本中已实现的部分实现。
This variable has no effect. The partially implemented effect it had in previous releases was removed in CMake 3.4.
参考
- CMake FAQ: Why does CMake use full paths, or can I copy my build tree?
- How do I move my folders created by CMake?
这篇关于如何告诉CMake使用相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!