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.
In this answer, it says Debug is the default cmake build configuration.
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.
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.
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With