I either want the debug build for development or release build for deployment.
I don't see a use-case for anything else, are there more?
You are right, these two are the most frequently required use cases:
- a debug build without any optimization but full debug symbols
- a release build with full optimization and no debug symbols
Others have mentioned certain cases where other combinations of compiler switches may make sense (for example, partially optimizations, optimizations plus debug symbols), but no compilation flags at all may create something arbitrary which is not what you want.
Is this design decision in CMake motivated by an actual practice in software development of creating builds that are neither Debug nor Release or is it a mistake to not specify a default build type in a CMake project in CMakeLists.txt?
The creators of CMake could have made the tool pick a default build configuration when none is specified, but everyone will probably have their own idea what the most useful default is. They could also have made CMake throw an error and stop execution for this case. Or, they could CMake let the decision delegate to the compiler vendor and use whatever the vendor provided as default, when no flags were set. We can only guess why they choose the last alternative, but surely not because it is "actual practice in software development".
However, others have already solved this problem for you: here I found a short article how to make CMake pick your favorite build config according to some simple rule (the example shows how the Debug configuration is chosen when a .git
file is present in the source tree, otherwise the Release configuration). I am sure you can modify this script so it will apply to your environment and your idea what the best default build configuration is.
RelWithDebInfo
? "Release with debug information", rather than "no flags".RelWithDebInfo
on MinGW, but can't test it right now.