在 CMake 中将二进制文件放在哪里?
在我的项目中,所有源代码都位于名为“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想将所有可执行文件放在名为“bin”的子目录中,则可以在顶部 CMakeLists.txt 文件中使用以下行:
只需删除
/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:
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.