Skip to content

Commit f49bca9

Browse files
[CMake] Make specifying invalid build type a fatal error (#72021)
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.
1 parent 0718c1a commit f49bca9

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

llvm/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,15 @@ endif()
392392

393393
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
394394

395+
option(LLVM_ADDITIONAL_BUILD_TYPES "Additional build types that are allowed to be passed into CMAKE_BUILD_TYPE" "")
396+
397+
set(ALLOWED_BUILD_TYPES DEBUG RELEASE RELWITHDEBINFO MINSIZEREL ${LLVM_ADDITIONAL_BUILD_TYPES})
398+
string (REPLACE ";" "|" ALLOWED_BUILD_TYPES_STRING "${ALLOWED_BUILD_TYPES}")
399+
string (TOUPPER "${ALLOWED_BUILD_TYPES_STRING}" uppercase_ALLOWED_BUILD_TYPES)
400+
395401
if (CMAKE_BUILD_TYPE AND
396-
NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$")
397-
message(WARNING "Unknown value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
402+
NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(${uppercase_ALLOWED_BUILD_TYPES})$")
403+
message(FATAL_ERROR "Unknown value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
398404
endif()
399405

400406
# LLVM_INSTALL_PACKAGE_DIR needs to be declared prior to adding the tools

llvm/docs/CMake.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ enabled sub-projects. Nearly all of these variable names begin with
321321
enabled or not. A version of LLVM built with ABI breaking checks
322322
is not ABI compatible with a version built without it.
323323

324+
**LLVM_ADDITIONAL_BUILD_TYPES**:LIST
325+
Adding a semicolon separated list of additional build types to this flag
326+
allows for them to be specified as values in CMAKE_BUILD_TYPE without
327+
encountering a fatal error during the configuration process.
328+
324329
**LLVM_UNREACHABLE_OPTIMIZE**:BOOL
325330
This flag controls the behavior of `llvm_unreachable()` in release build
326331
(when assertions are disabled in general). When ON (default) then

0 commit comments

Comments
 (0)