在 CMake 中将二进制文件放在哪里?

发布于 2024-09-13 11:37:00 字数 289 浏览 3 评论 0原文

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

(这是一种常见的做法,还是我应该将所有智能放在根级别的 CMakeLists.txt 文件中?)

如果我现在构建项目,我的二进制文件将放入 src 文件夹中,但这不会很有意义,我宁愿将其放在根文件夹或专用的“bin”文件夹中。

你如何做到这一点?

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".

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

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.

How do you do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巷雨优美回忆 2024-09-20 11:37:00

如果您想将所有可执行文件放在名为“bin”的子目录中,则可以在顶部 CMakeLists.txt 文件中使用以下行:

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

只需删除 /bin 即可在根目录。库也存在类似的变量:CMAKE_LIBRARY_OUTPUT_DIRECTORY

附言。添加每个目录的逻辑就可以了。这似乎是做事并使事情井然有序的常见方式。

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")

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文