Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the build type to Release mode in cmake?

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.

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.

like image 676
123r789 Avatar asked Sep 26 '13 09:09

123r789


People also ask

Does CMake default to release or debug?

In this answer, it says Debug is the default cmake build configuration.

What does CMake build type do?

Specifies the build type on single-configuration generators (e.g. Makefile Generators or Ninja ). Typical values include Debug , Release , RelWithDebInfo and MinSizeRel , but custom build types can also be defined.

How do you reconfigure CMake?

You could force CMake to reconfigure every time e.g. by calling make rebuild_cache before your actual build or by adding e.g. add_custom_command(TARGET MyExe POST_BUILD ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/version.

What is MinSizeRel?

MinSizeRel is the same as Release, with its optimization configuration just set to Minimize Size instead of Maximize Speed as illustrated in this link in Visual Studio, for example. If I want to generate a production build, should I choose Release?


1 Answers

To change the build type, on Windows, it must be done at build time:

cmake --build {DIR} --config Release 

By default it's Debug. I'm still looking for a way of changing this default. CMAKE_BUILD_TYPE doesn't work of course, and tweaking CMAKE_CONFIGURATION_TYPES doesn't work either, obviously for the same reason, they only apply for Unix makefiles, not for Visual projects.

like image 133
Rok Avatar answered Nov 13 '22 04:11

Rok