将二进制文件放在CMake中的哪里? [英] Where to put the binary in CMake?

查看:312
本文介绍了将二进制文件放在CMake中的哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,所有源代码都驻留在名为 src的文件夹中。我的项目根目录中有一个CMakeLists.txt文件(在 src上方),但仅声明了该项目,并包含 src子目录。 src下的CMakeLists.txt文件可以完成所有工作,包括 add_binary。

in my project, all source code resides in a folder named "src". There's a CMakeLists.txt file in my projects root (above "src"), but it merely declares the project and includes the "src" subdirectory. The CMakeLists.txt file under src does all the work, including "add_binary".

(这是一种常用的方式,还是应该将所有情报都放入其中根目录下的CMakeLists.txt文件?)

(Is that a common way of doing it, or should I put all the intelligence in the CMakeLists.txt file at the root level?)

如果我现在构建项目,则将二进制文件放入src文件夹,但这没什么用从某种意义上说,我宁愿将其放在根文件夹或专用的 bin文件夹中。

If I build the project now, my binary is placed into the src folder, but this doesn't make a lot of sense, I'd rather have it in the root folder or a dedicated "bin" folder.

您如何做到这一点?

推荐答案

如果要将所有可执行文件放在一个名为 bin的子目录中,则可以在顶部CMakeLists.txt文件中使用以下行: / p>

If you want to put all your executable files in a subdirectory called "bin", then you can use the following line in the top CMakeLists.txt file:

SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

只需删除 / bin ,就会在根目录中创建可执行文件。库中存在类似的变量: CMAKE_LIBRARY_OUTPUT_DIRECTORY

Just remove /bin and executables will be created in the root directory. A similar variable exists for libraries: CMAKE_LIBRARY_OUTPUT_DIRECTORY.

PS。添加按目录逻辑很好。这似乎是做事并使事情井井有条的常用方法。

PS. Adding per-directory logic is fine. It seems to be the common way to do things and keeps things nicely organized.

这篇关于将二进制文件放在CMake中的哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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