如何将 CMake 输出转换为“bin"目录? [英] How do I make CMake output into a 'bin' dir?

查看:34
本文介绍了如何将 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] 附加到变量/属性名称,以使输出目录适用于特定配置(配置的标准值为 DEBUGRELEASEMINSIZERELRELWITHDEBINFO).

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"目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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