[CMake] I can not set CMAKE_BUILD_TYPE in CMakeList.txt

Attila Krasznahorkay attila.krasznahorkay at gmail.com
Tue Jan 5 02:55:30 EST 2016


Hi Isaac,

ccmake will only allow you to modify cache variables. When you call

set( CMAKE_BUILD_TYPE RelWithDebInfo )

, this creates a local variable in your CMakeLists.txt file. This way it should *always* override whatever you set on the command line, or as a cache variable.

If you want to set the default value to RelWithDebInfo, but allow the user to override it either with ccmake or a command line argument, you should do something like:

set( CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Build type" )

At least I think it should work like this...

Cheers,
              Attila

> On 05 Jan 2016, at 08:11, Isaac Ge <acgtyrant at gmail.com> wrote:
> 
> Hi anyone, I find the `set(CMAKE_BUILD_TYPE RelWithDebInfo)` in CMakeList.txt does not work, because the actual build type show by ccmake is empty. So I have to enter the correct build type in ccmake or add command argument `-D CMAKE_BUILD_TYPE=RelWithDebInfo` while cmake.
> 
> Any idea? Thank you!
> -- 
> 
> Powered by www.kitware.com
> 
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> 
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
> 
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake



More information about the CMake mailing list