Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't restrict list of CMake build types #60975

Closed
rossburton opened this issue Feb 24, 2023 · 10 comments
Closed

Don't restrict list of CMake build types #60975

rossburton opened this issue Feb 24, 2023 · 10 comments
Labels
cmake Build system in general and CMake in particular

Comments

@rossburton
Copy link

rossburton commented Feb 24, 2023

For example, the llvm directory restricts the value of CMAKE_BUILD_TYPE:

if (CMAKE_BUILD_TYPE AND
    NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$")
  message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
endif()

https://github.com/llvm/llvm-project/blob/main/llvm/CMakeLists.txt#L389

That is the default set of build types, but it is not the exhaustive list of build types. Quoting from the CMake manual:

Typical values include Debug, Release, RelWithDebInfo and MinSizeRel, but custom build types can also be defined.

I suggest just deleting this chunk, as it doesn't serve any purpose: the person building llvm should be able to specify a custom build type if they wish.

@EugeneZelenko EugeneZelenko added cmake Build system in general and CMake in particular and removed new issue labels Feb 24, 2023
@fsb4000
Copy link
Member

fsb4000 commented Feb 24, 2023

I suggest just deleting this chunk, as it doesn't serve any purpose: the person building llvm should be able to specify a custom build type if they wish.

I found the commit with that changes: 55f097f

Apparently if you make a typo in the argument to CMAKE_BUILD_TYPE,
cmake silently accepts this but doesn't apply any particular build
type to your build. This means you get a build that doesn't really
make any sense - it's sort of a debug build with asserts disabled.

Error out instead.

I think that commit makes sense.

@fsb4000
Copy link
Member

fsb4000 commented Feb 24, 2023

ping @bogner , what do you think?

Should we close this issue or maybe add more CMAKE_BUILD_TYPEs to the list?

@rossburton
Copy link
Author

I disagree, mainly as the list of build types is not fixed. If someone means to type Release but types Releas they don’t get a broken build, it’s just missing some optimisation. They made the mistake.

The context here is that I’m defining a new build type as we’re trying to control the build flags, and this fatal error means that fails.

@bogner
Copy link
Contributor

bogner commented Feb 26, 2023

It’s probably fine to remove this check and let people do custom cmake build types. It’s definitely broken if someone makes a typo here, so I do like the safety net, but that’s not the only instance where cmake’s interface is user-hostile and it isn’t really realistic for us to catch all of the ways this can go wrong.

@whisperity
Copy link
Member

Suggestion: message(FATAL_ERROR -> message(WARNING? That way we could have a blanket check that still catches the vast majority of accidents (as lots of people defining custom build targets seems to be unlikely) but doesn't immediately axe the build nevertheless?

@rossburton
Copy link
Author

I'd certainly be happy with a warning that the build type is unknown. I'm defining a new one so I'm happy with that, but should help users who are new to cmake.

@fsb4000
Copy link
Member

fsb4000 commented Feb 27, 2023

I've created: https://reviews.llvm.org/D144835

@pogo59
Copy link
Collaborator

pogo59 commented Feb 27, 2023

If you're defining your own build type, you could modify the check to include your new keyword? I appreciate code that keeps me from wasting time with typos.

@rossburton
Copy link
Author

Defining a build type is just a matter of naming it, if I pass -DCMAKE_BUILD_TYPE=FooBar to cmake then it looks for variables named CMAKE_CXX_FLAGS_FOOBAR. By default, cmake sets CMAKE_CXX_FLAGS_DEBUG and so on.

@fsb4000 fsb4000 closed this as completed in c75dbed Mar 7, 2023
@boomanaiden154
Copy link
Contributor

boomanaiden154 commented Sep 4, 2023

Just adding to this conversation that I just spent a non-insignificant amount of time tracking down an issue that turned out to be related to a typo I made in specifying CMAKE_BUILD_TYPE. It would've been very nice to have the FATAL_ERROR safety check still in place to catch this as I never ended up seeing the warning.

As @bogner mentions, CMake's design is fairly user-hostile here and doesn't have great support for doing this elegantly, but the current fix seems to optimize for a relatively niche use case at the expense of usability for everyone else. I think there are certainly alternative solutions that allow for this use case while still allowing for the message to set FATAL_ERROR. Maybe something like an addition LLVM_ADDITIONAL_BUILD_TYPES flag that can be set with additional build types that should be accepted? We could also just make the accepted types a cache variable and allow for it to be set as a flag.

boomanaiden154 added a commit to boomanaiden154/llvm-project that referenced this issue Nov 11, 2023
This patch makes it so that specifying an invalid value for
CMAKE_BUILD_TYPE is a fatal error. Having this simply as a warning has
caused me (and probably others) a decent amount of headache. The check
was present before, but was proposed to be modified to a warning in
llvm#60975 and changed to a
warning in c75dbed. This patch
reenables that behavior to hopefully reduce frustration for people
building LLVM in the common case while still allowing for alternative
build types to be setup without needing to perform source modification
through the addition of a CMake flag.
boomanaiden154 added a commit that referenced this issue Nov 16, 2023
This patch makes it so that specifying an invalid value for
CMAKE_BUILD_TYPE is a fatal error. Having this simply as a warning has
caused me (and probably others) a decent amount of headache. The check
was present before, but was proposed to be modified to a warning in
#60975 and changed to a
warning in c75dbed. This patch
reenables that behavior to hopefully reduce frustration for people
building LLVM in the common case while still allowing for alternative
build types to be setup without needing to perform source modification
through the addition of a CMake flag.
sr-tream pushed a commit to sr-tream/llvm-project that referenced this issue Nov 20, 2023
This patch makes it so that specifying an invalid value for
CMAKE_BUILD_TYPE is a fatal error. Having this simply as a warning has
caused me (and probably others) a decent amount of headache. The check
was present before, but was proposed to be modified to a warning in
llvm#60975 and changed to a
warning in c75dbed. This patch
reenables that behavior to hopefully reduce frustration for people
building LLVM in the common case while still allowing for alternative
build types to be setup without needing to perform source modification
through the addition of a CMake flag.
zahiraam pushed a commit to zahiraam/llvm-project that referenced this issue Nov 20, 2023
This patch makes it so that specifying an invalid value for
CMAKE_BUILD_TYPE is a fatal error. Having this simply as a warning has
caused me (and probably others) a decent amount of headache. The check
was present before, but was proposed to be modified to a warning in
llvm#60975 and changed to a
warning in c75dbed. This patch
reenables that behavior to hopefully reduce frustration for people
building LLVM in the common case while still allowing for alternative
build types to be setup without needing to perform source modification
through the addition of a CMake flag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular
Projects
None yet
Development

No branches or pull requests

7 participants