CMAKE_BUILD_TYPE doc question

Note that configuration names are case-insensitive. The value of this variable will be the same as it is specified when invoking CMake. For instance, if -DCMAKE_BUILD_TYPE=ReLeAsE is specified, then the value of CMAKE_BUILD_TYPE will be ReLeAsE.

This wording of this portion of the documentation is confusing to me. This seems to imply that CMAKE_BUILD_TYPE is case sensitive not case insensitive.


It is case-insensitive in just about everywhere it gets used (since “all” code does to_upper on the name before using it). It is case-preserving however and will keep the case provided.

Really? Also properties and variable names?

The problem is probably not in functions using the build type string but rather in conditionals in scripts trying to match Debug vs. not Debug. However, the needed regexp is just slightly more complicated.

No, properties and variable names are always case sensitive. It’s just that with build types, “everyone” does string(TOUPPER) on it before using it. This is historical behavior that I wish wouldn’t have been done, but there’s not much to be done about it today.

but then, CMAKE_BUILD_TYPE is case sensitive, it is just that some existing CMake projects are treating it as case insensitive.

So, the latest documentation implies that it is best practice to treat CMAKE_BUILD_TYPE as case insensitive, is this correct? In other words, should any new code behave like historical behaviour?

I agree. In my own projects I am indeed using TOUPPER, but to me it seems that the documentation implies what hex is saying. Any new user might come along and try to use it without TOUPPER.

Please feel free to improve the docs (or file an issue to do so). There’s a lot of history in CMake and explaining these things in the right place helps everyone :slight_smile: .

1 Like