cmake - 什么是 CMAKE_BUILD_TYPE : Debug, Release、RelWithDebInfo 和 MinSizeRel?

标签 cmake

来自 docs page :

CMAKE_BUILD_TYPE

Specifies the build type on single-configuration generators.

This statically specifies what build type (configuration) will be built in this build tree. Possible values are empty, Debug, Release, RelWithDebInfo and MinSizeRel. This variable is only meaningful to single-configuration generators (such as Makefile Generators and Ninja) i.e. those which choose a single configuration when CMake runs to generate a build tree as opposed to multi-configuration generators which offer selection of the build configuration within the generated build environment. There are many per-config properties and variables (usually following clean SOME_VAR_<CONFIG> order conventions), such as CMAKE_C_FLAGS_<CONFIG>, specified as uppercase: CMAKE_C_FLAGS_[DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL]. For example, in a build tree configured to build type Debug, CMake will see to having CMAKE_C_FLAGS_DEBUG settings get added to the CMAKE_C_FLAGS settings. See also CMAKE_CONFIGURATION_TYPES.


我知道 Debug 之间的区别构建和 ​​Release构建,但 Release 之间有什么区别? , RelWithDebInfoMinSizeRel ?我猜 RelWithDebInfo意味着创建可调试的二进制文件,以及 MinSizeRel意味着创建尽可能小的二进制文件。
来自 LLVM CMake page :

CMAKE_BUILD_TYPE:STRING

If you are using an IDE such as Visual Studio, you should use the IDE settings to set the build type. Be aware that Release and RelWithDebInfo use different optimization levels on most platforms.


如果我想生成一个生产版本,我应该选择 Release ?

最佳答案

RelWithDebInfo 相同发布 ,让您拥有symbol files用于调试。
例如,在 Visual Studio 中,您将拥有 .pdb如果没有它们,将很难调试,因为二进制文件中的所有签名都不是人类可读的,并且无法将它们映射到源代码。
MinSizeRel 相同发布 ,其优化配置刚刚设置为 Minimize Size而不是 Maximize Speedthis link 中所示例如,在 Visual Studio 中。

If I want to generate a production build, should I choose Release?


是的,这应该适合您。调试/发布是最常用的选项。
阅读this CMAKE FAQ实际上会帮助你很多。

关于cmake - 什么是 CMAKE_BUILD_TYPE : Debug, Release、RelWithDebInfo 和 MinSizeRel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48754619/

相关文章:

opengl - CMake:opengl 包含目录在不同平台上的命名不同

c++ - Clang 版本混淆(OSX 和 Cmake)

CMake 找不到 windres.exe (MingW),CMAKE_RC_COMPILER

c++ - 现代 CMake 应该如何添加 SSE 标志?

c++ - CMake 嵌套项目和目标

windows - cmake:树外构建的问题

c++ - 为什么要两次使用静态库才能使编译工作?

CMake的find_package找不到用add_subdirectory添加的库

c++ - 制作/测试 : Check if code compiles

c++ - cmake:编译统计