windowsvisual-studio-2010cmake

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.


Solution

  • 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.