Skip to content

Commit 438f887

Browse files
authored
[cmake] Make CMAKE_BUILD_TYPE=Release the default (#174520)
Currently, we report a fatal error if the user leaves CMAKE_BUILD_TYPE blank. This was implemented in https://reviews.llvm.org/D124153 / 350bdf9 , based on this RFC: https://discourse.llvm.org/t/rfc-select-a-better-linker-by-default-or-warn-about-using-bfd/61899/1 Tom Stellard mentioned that he'd like to revisit this on Discord, and Aiden, myself, and apparently most people on the original RFC agree, so I'm proposing we do it. However, on the review, several folks objected and insisted that Debug was a better default. I want to reopen the question. I think we've made the wrong tradeoff. I wish Debug builds worked out of the box on most systems, but they don't, and LLVM has only gotten bigger over the last four years, making the build scalability problems of Debug builds worse. I think we should optimize our build configuration for new developers, not experienced longtime contributors who are invested enough to tweak the build to their liking. With this PR, we emit a warning, and set the build type to Release, which has a higher likelihood of success for first-time users. Making the build work out of the box is very important for making LLVM development more accessible to new contributors, so it seems worth smoothing over this rough edge. A separate possible improvement would be to set LLVM_ENABLE_ASSERTIONS=ON, but that is out of scope for this PR.
1 parent 2329d04 commit 438f887

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

llvm/CMakeLists.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED YES)
7979
set(CMAKE_CXX_EXTENSIONS NO)
8080

8181
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
82-
message(FATAL_ERROR "
83-
No build type selected. You need to pass -DCMAKE_BUILD_TYPE=<type> in order to configure LLVM.
84-
Available options are:
85-
* -DCMAKE_BUILD_TYPE=Release - For an optimized build with no assertions or debug info.
86-
* -DCMAKE_BUILD_TYPE=Debug - For an unoptimized build with assertions and debug info.
87-
* -DCMAKE_BUILD_TYPE=RelWithDebInfo - For an optimized build with no assertions but with debug info.
88-
* -DCMAKE_BUILD_TYPE=MinSizeRel - For a build optimized for size instead of speed.
89-
Learn more about these options in our documentation at https://llvm.org/docs/CMake.html#cmake-build-type
82+
message(WARNING "No build type selected. Defaulted CMAKE_BUILD_TYPE=Release.
83+
Learn more about the options in our documentation at https://llvm.org/docs/CMake.html#cmake-build-type
9084
")
85+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel" FORCE)
9186
endif()
9287

9388
# Set default build type for cmake's try_compile module.

0 commit comments

Comments
 (0)