This is an archive of the discontinued LLVM Phabricator instance.

[CMake][NFC] Limit the use of uppercase_CMAKE_BUILD_TYPE
AbandonedPublic

Authored by ctetreau on Oct 20 2020, 11:29 AM.

Details

Reviewers
lebedev.ri
Group Reviewers
Restricted Project
Restricted Project
Restricted Project
Summary

uppercase_CMAKE_BUILD_TYPE is often defined to be
toupper(CMAKE_BUILD_TYPE). This is sometimes neccesary when trying to
programatically inspect the values of builtin cmake variables that have
the build type as part of the name. However, this variable is also often
used to just check the build type.

The use of this variable is error prone because it is not a builtin variable.
Users may add a usage of it without defining it. Since CMake treats undefined
variables as being defined to the empty string, this will not cause any sort
of error. It may even be the case that it appears to work for the author
and bad code makes it into master. (D89807)

This patch removes unneccesary usages of uppercase_CMAKE_BUILD_TYPE.
Remaining usages of it are needed to construct variable names such as
CMAKE_CXX_FLAGS_DEBUG.

Diff Detail

Event Timeline

ctetreau created this revision.Oct 20 2020, 11:29 AM
Herald added projects: Restricted Project, Restricted Project, Restricted Project, Restricted Project, Restricted Project, Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript
ctetreau requested review of this revision.Oct 20 2020, 11:29 AM
lebedev.ri requested changes to this revision.Oct 20 2020, 11:35 AM
lebedev.ri added inline comments.
libcxx/utils/google-benchmark/test/CMakeLists.txt
8–9

How is this an unnecessary usage?

This revision now requires changes to proceed.Oct 20 2020, 11:35 AM

I quite like this. We should strive to use the same name as CMake uses for its build types, i.e. Debug, Release, etc.

If I configure CMake with -DCMAKE_BUILD_TYPE=DEBUG, is CMAKE_BUILD_TYPE normalized back to Debug by CMake, or is it defined to DEBUG? If the latter, then I suggest we might want to add a temporary error message when the CMAKE_BUILD_TYPE is defined to something all-uppercase. This would help catch cases where this patch will be a change in behavior. That would be a nice place to tell users to use the right build type names.

ctetreau marked an inline comment as done.Oct 20 2020, 12:15 PM

I quite like this. We should strive to use the same name as CMake uses for its build types, i.e. Debug, Release, etc.

If I configure CMake with -DCMAKE_BUILD_TYPE=DEBUG, is CMAKE_BUILD_TYPE normalized back to Debug by CMake, or is it defined to DEBUG? If the latter, then I suggest we might want to add a temporary error message when the CMAKE_BUILD_TYPE is defined to something all-uppercase. This would help catch cases where this patch will be a change in behavior. That would be a nice place to tell users to use the right build type names.

My interpretation of https://cmake.org/cmake/help/v3.13/variable/CMAKE_BUILD_TYPE.html, is that it can be the empty string, or CamelCase. However, experimentation shows that passing -DCMAKE_BUILD_TYPE=RELEASE results in an all-capitals version. Given this, I don't think this patch is correct.

It looks like we had case-sensitive CMAKE_BUILD_TYPE, but it was removed in 2015 (https://github.com/llvm/llvm-project/commit/74009be05158c72893e02c2930b771a334543f1b), so making it case sensitive again is probably going to be controversial.

ctetreau abandoned this revision.Oct 20 2020, 12:15 PM

Are generator expressions expanded in if()? If so, we could at least change those to if ("$<UPPER_CASE:CMAKE_BUILD_TYPE>" STREQUAL "DEBUG"). This would preserve the case-insensitivity while solving the problem you were concerned about, and make the code easier to read.

I would assume so. I'll take a look.

I would assume so. I'll take a look.

It doesn't seem to work.