How do I make CMake output into a #39;bin#39; dir?(如何将 CMake 输出转换为“bin目录?)
问题描述
我目前正在构建一个具有插件结构的项目.我正在使用 CMake 编译项目.插件编译在单独的目录中.我的问题是 CMake 在源的目录结构中编译并保存二进制文件和插件、动态库.如何让 CMake 将文件保存在 ./bin 目录中?
I'm currently constructing a project with a plugin structure. I'm using CMake to compile the project. The plugins are compiled in separate directories. My problem is that CMake compiles and saves the binaries and plugins, dynamic libraries, in the directory structure of the source. How do I make CMake save the files in something like a ./bin directory?
推荐答案
在 Oleg 的回答中,我相信要设置的正确变量是 CMAKE_RUNTIME_OUTPUT_DIRECTORY.我们在根 CMakeLists.txt 中使用以下内容:
As in Oleg's answer, I believe the correct variable to set is CMAKE_RUNTIME_OUTPUT_DIRECTORY. We use the following in our root CMakeLists.txt:
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
您还可以为每个目标指定输出目录:
You can also specify the output directories on a per-target basis:
set_target_properties( targets...
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
在这两种情况下,您都可以将 _[CONFIG]
附加到变量/属性名称,以使输出目录适用于特定配置(配置的标准值为 DEBUG
、RELEASE
、MINSIZEREL
和 RELWITHDEBINFO
).
In both cases you can append _[CONFIG]
to the variable/property name to make the output directory apply to a specific configuration (the standard values for configuration are DEBUG
, RELEASE
, MINSIZEREL
and RELWITHDEBINFO
).
这篇关于如何将 CMake 输出转换为“bin"目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将 CMake 输出转换为“bin"目录?


- 近似搜索的工作原理 2021-01-01
- C++ 协变模板 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 从python回调到c++的选项 2022-11-16
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01