如何检查 CMake 构建目录构建类型是 Debug 还是 Release? [英] How to check if a CMake build directory build type is Debug or Release?

查看:28
本文介绍了如何检查 CMake 构建目录构建类型是 Debug 还是 Release?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以使用 -DCMAKE_BUILD_TYPE=Release-DCMAKE_BUILD_TYPE=Debug 设置构建类型,但是是否有命令行方法来检查/确认哪个构建类型是正在被 CMake 使用?

I know the build type can be set using -DCMAKE_BUILD_TYPE=Release or -DCMAKE_BUILD_TYPE=Debug but is there a command line way to check/confirm which build type is being used by CMake?

推荐答案

除了查看 CMakeCache.txt 之外,您还可以 - 在构建目录中 - 使用

Besides looking in CMakeCache.txt you could - in the build directory - use

cmake -L . | grep CMAKE_BUILD_TYPE
...
CMAKE_BUILD_TYPE:STRING=Release

或者你可以例如将自定义目标添加到您的 CMakeLists.txt 以执行此操作

or you could e.g. add a customized target to your CMakeLists.txt for doing it

add_custom_target(print_build_type COMMAND ${CMAKE_COMMAND} -E echo ${CMAKE_BUILD_TYPE})

然后会用类似的东西调用

will then be called with something like

$ make --silent print_build_type
Release

但是 CMAKE_BUILD_TYPE 可以空着.

But CMAKE_BUILD_TYPE could be empty.

所以这里是使用 的更通用的版本生成器表达式:

add_custom_target(
    print_build_type 
    COMMAND ${CMAKE_COMMAND} -E echo $<$<CONFIG:>:Undefined>$<$<NOT:$<CONFIG:>>:$<CONFIG>>
)

参考资料

这篇关于如何检查 CMake 构建目录构建类型是 Debug 还是 Release?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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