如何在 cmake 中将构建类型更改为发布模式? [英] How to change the build type to Release mode in cmake?

查看:37
本文介绍了如何在 cmake 中将构建类型更改为发布模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以发布模式构建一个项目.默认情况下,它是在调试模式下构建的.我在 CMakeLists.txt 中将变量 CMAKE_BUILD_TYPE 设置为Release".但它仍在调试模式下构建项目.当我在 CMake 命令中将Release"作为构建类型传递时,它仍然不起作用.

I am trying to build a project in Release mode. By default it is built in debug mode. I am setting the variable CMAKE_BUILD_TYPE to "Release" in CMakeLists.txt. But it is still building the project in debug mode. When I pass "Release" as the build type in the CMake command, it still does not work.

我使用的 CMake 命令是:

The CMake command that I am using is:

cmake -G"Visual Studio 10" -DCMAKE_BUILD_TYPE=Release
  -H"source_path" -B"Build path"

如果有,请提供解决方案.

Please provide a solution if any.

推荐答案

照常使用,但在根 cmake 文件中添加以下 before project 关键字

Use it as you do it but in the root cmake file add the following before the project keyword

SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING "" FORCE)
PROJECT(MY_PROJECT)#It's here just to show where you should add it.

这篇关于如何在 cmake 中将构建类型更改为发布模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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