如何告诉 CMake 使用相对路径 [英] How to tell CMake to use relative paths

查看:26
本文介绍了如何告诉 CMake 使用相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我做我的项目,我可以看到:

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 使用相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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