固定的cmake输出目录 [英] Fixed cmake output directory

查看:124
本文介绍了固定的cmake输出目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用cmake进行第一个项目,大多数情况下进展顺利,但是遇到了一个我无法弄清的问题.

I'm working on my first project using cmake, and for the most part it's been going well but I've run into one problem I can't figure out.

假设我的CMakeLists.txt文件位于~/project/build.我希望cmake的输出(不是二进制文件,而是makefile/配置文件)与我从哪里运行cmake无关.

Let's say I have my CMakeLists.txt file located at ~/project/build. I would like for the output from cmake (not the binaries, but the makefile/configuration files) to be independent of where I run cmake from.

例如,如果我的终端位于~/project/build目录中,则调用cmake ~/project/build会创建makefile以及~/project/build目录中的所有其他文件.这是我想要的行为.如果我从其他任何地方调用cmake ~/project/build,它将在终端从中调用程序的任何目录中创建makefile和所有其他内容.

As an example, if my terminal is sitting in the ~/project/build directory, calling cmake ~/project/build creates the makefile and everything else within the ~/project/build directory. This is the behaviour that I'd like. If I call cmake ~/project/build from anywhere else, it creates the makefile and everything else in whatever directory the terminal called the program from.

是否可以强制cmake在与CMakeLists.txt文件相同的文件夹中生成其makefile和关联文件?我仔细阅读了文档,发现如何更改二进制输出目录没有任何问题,但是我真的找不到我要执行的操作的任何提示.

Is it possible to force cmake to generate its makefile and associated files in the same folder as the CMakeLists.txt file? I've taken a look through the documentation and I've had no problems figuring out how to change binary output directories, but I can't really find any mention of what I'm trying to do.

我意识到这是一个很小的烦恼(在构建项目之前移入我的build文件夹并不难),但我只是想知道是否有可能,并且是否出于某些原因不建议这样做.

I realize this is a pretty minor annoyance (it's not that hard to move into my build folder before building the project) but I'm just wondering if it's possible and if there's some reason it wouldn't be advised.

推荐答案

您必须为此使用2条命令

You have to use 2 commands for this

1)cmake -B目标路径(您要在其中生成输出文件的任何路径)" -H源路径(根CMakeLists.txt路径)"

1) cmake -B "Dest path(Any path in which u want to generate the output files)" -H"Source path(root CMakeLists.txt path)"

2)cmake-构建目标路径"

2) cmake --build "Dest path"

这篇关于固定的cmake输出目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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