No matter what your users set CMAKE_BUILD_TYPE in the CMake cache editor it will *always* be RelWithDebInfo when cmake is run (even though it may appear to be set differently with the cmake gui). You can verify this by doing a "make VERBOSE=1" and examining the compile flags. The reason this is so is because local variables always trump cache variables in scope. "ccmake" and friends can only show you cache variables, not variables created when CMake executes your scripts. If you define a local variable like CMAKE_BUILD_TYPE with the same name as a cache variable, it will override the cache in scope.

So you could simply set CMAKE_BUILD_TYPE to whatever, but this is a bad idea as you probably realize because it leaves your users no choice in choosing their build type. What you probably want to do is create a cache variable which will allow you to define a default value and type for the variable that the user can then edit, e.g:

One of the side effects of the SET(...CACHE) command, however, is only to create a cache variable if one doesn't already exist with that name. (This is to prevent users from overwriting existing cache variables, if you need to do that you should use the FORCE option on the SET() command).

The timing of setting CMAKE_BUILD_TYPE is, therefore, kinda tricky because as I mentioned earlier, CMake itself defines this on an initial configure. It turns out that this definition of CMAKE_BUILD_TYPE occurs in the PROJECT() command so to answer your original question, the best way to assign CMAKE_BUILD_TYPE a default option is to do something similar to the following: