用调试符号和cmake编译项目的正确方法 [英] Proper way to compile project with debug symbols and cmake

查看:499
本文介绍了用调试符号和cmake编译项目的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处建议在我将CMAKE_BUILD_TYPE作为参数传递给cmake想获得调试或发布项目版本.我正在尝试使用cmake编译 libharu ,我想使用调试符号对其进行编译.我已经搜索 libharu 中包含的CMakeLists.txt,以查找以下字符串:

Here is recommended to pass CMAKE_BUILD_TYPE as an argument to cmake when I want to obtain debug or release project builds. I'm trying to compile libharu with cmake and I would like to compile it with debug symbols. I've searched CMakeLists.txt included in libharu for following strings:

CMAKE_BUILD_TYPE
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_DEBUG

但是我什么都没找到.我的问题是,当 libharu 的CMakeLists.txt没有指定CMAKE_BUILD_TYPE是否有意义时,提吗?如果没有,如何使用调试符号编译 libharu ?

but I've found nothing. My question is that if it does make any sense to specify CMAKE_BUILD_TYPE when libharu's CMakeLists.txt doesn't mention it? If not, how can I compile libharu with debug symbols?

PS:我注意到使用cmake为Visual Studio 2013生成的项目已设置Debug/Win32,这足够吗?该信息在CMakeLists.txt中的何处指定?

PS: I've noticed that project that was generated for Visual Studio 2013 with cmake had set Debug/Win32, is this sufficient? Where in CMakeLists.txt is specified this info?

PPS:我想这个问题在很大程度上取决于特定的项目,但是总的来说有什么办法吗?我的意思是,CMAKE_BUILD_TYPE=Debug总是创建Debug版本吗?还是我应该注意的其他事情?

PPS: I guess this question is highly depending on particular project but is there some way to do this in general? I mean, does CMAKE_BUILD_TYPE=Debug always create Debug build or is there something else that I should be aware of?

谢谢

推荐答案

通过CMAKE_BUILD_TYPE设置配置类型会将编译器的其他选项集切换为一个,而通常反映了配置的含义.也就是说,通过

Setting configuration type via CMAKE_BUILD_TYPE switches set of additional options for compiler to one, which normally reflects meaning of the configuration. That is, passing

-DCMAKE_BUILD_TYPE=Debug

cmake告诉编译器生成调试信息除非CMakeLists.txt修改了该行为.

to cmake tells compiler to generate debugging information unless CMakeLists.txt modifies that behavior.

依赖于配置的编译器选项包含在变量CMAKE_<LANG>_FLAGS_<CONFIG>中.例如,变量CMAKE_C_FLAGS_DEBUG包含调试"配置中C编译器的其他选项.这些变量由CMake自动填充,而CMakeLists.txt本身很少对其进行修改.

Config-dependent compiler options are contained in variables CMAKE_<LANG>_FLAGS_<CONFIG>. For example, variable CMAKE_C_FLAGS_DEBUG contains additional options for C compiler in "Debug" configuration. These variables are filled by CMake automatically, and CMakeLists.txt itself rare modifies them.

因此,如果您发现CMakeLists.txt不能与变量CMAKE_BUILD_TYPECMAKE_<LANG>_FLAGS_<CONFIG>一起使用,则它遵循有关配置类型的通用约定.

So, if you found that CMakeLists.txt doesn't play with variables CMAKE_BUILD_TYPE and CMAKE_<LANG>_FLAGS_<CONFIG>, then it follows common conventions about configuration type.

并不意味着 CMakeLists.txt 不应使用该变量.

通常CMakeLists.txt会将CMAKE_BUILD_TYPE设置为某个默认值,前提是用户未设置变量并且使用了单配置生成器.如果编译器的默认设置不适合该项目,则CMakeLists.txt可能还会设置一些变量CMAKE_<LANG>_FLAGS_<CONFIG>.

Often CMakeLists.txt sets CMAKE_BUILD_TYPE to some default value, provided the variable is not set by the user and single-config generator is used. CMakeLists.txt also may set some of variables CMAKE_<LANG>_FLAGS_<CONFIG>, if default setting for compiler is not suited for the project.

但是,即使CMakeLists.txt不触摸这些变量,它们也可以工作.

But even if CMakeLists.txt does not touch these variables, they work.

这篇关于用调试符号和cmake编译项目的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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