Skip to content

Commit 350bdf9

Browse files
committed
[CMake] Make omitting CMAKE_BUILD_TYPE an error
After a lot of discussion in this diff the consensus was that it is really hard to guess the users intention with their LLVM build. Instead of trying to guess if Debug or Release is the correct default option we opted for just not specifying CMAKE_BUILD_TYPE a error. Discussion on discourse here: https://discourse.llvm.org/t/rfc-select-a-better-linker-by-default-or-warn-about-using-bfd Reviewed By: hans, mehdi_amini, aaron.ballman, jhenderson, MaskRay, awarzynski Differential Revision: https://reviews.llvm.org/D124153
1 parent cbd3902 commit 350bdf9

File tree

6 files changed

+28
-12
lines changed

6 files changed

+28
-12
lines changed

llvm/CMakeLists.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,15 @@ else()
6464
endif()
6565

6666
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
67-
message(STATUS "No build type selected, default to Debug")
68-
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type (default Debug)" FORCE)
67+
message(FATAL_ERROR "
68+
No build type selected. You need to pass -DCMAKE_BUILD_TYPE=<type> in order to configure LLVM.
69+
Available options are:
70+
* -DCMAKE_BUILD_TYPE=Release - For an optimized build with no assertions or debug info.
71+
* -DCMAKE_BUILD_TYPE=Debug - For an unoptimized build with assertions and debug info.
72+
* -DCMAKE_BUILD_TYPE=RelWithDebInfo - For an optimized build with no assertions but with debug info.
73+
* -DCMAKE_BUILD_TYPE=MinSizeRel - For a build optimized for size instead of speed.
74+
Learn more about these options in our documentation at https://llvm.org/docs/CMake.html#cmake-build-type
75+
")
6976
endif()
7077

7178
# Side-by-side subprojects layout: automatically set the
@@ -1252,11 +1259,11 @@ if (LLVM_INCLUDE_BENCHMARKS)
12521259
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Don't install benchmark" FORCE)
12531260
set(BENCHMARK_DOWNLOAD_DEPENDENCIES OFF CACHE BOOL "Don't download dependencies" FORCE)
12541261
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Disable Google Test in benchmark" FORCE)
1255-
set(BENCHMARK_ENABLE_WERROR ${LLVM_ENABLE_WERROR} CACHE BOOL
1262+
set(BENCHMARK_ENABLE_WERROR ${LLVM_ENABLE_WERROR} CACHE BOOL
12561263
"Handle -Werror for Google Benchmark based on LLVM_ENABLE_WERROR" FORCE)
12571264
# Since LLVM requires C++11 it is safe to assume that std::regex is available.
12581265
set(HAVE_STD_REGEX ON CACHE BOOL "OK" FORCE)
1259-
add_subdirectory(${LLVM_THIRD_PARTY_DIR}/benchmark
1266+
add_subdirectory(${LLVM_THIRD_PARTY_DIR}/benchmark
12601267
${CMAKE_CURRENT_BINARY_DIR}/third-party/benchmark)
12611268
add_subdirectory(benchmarks)
12621269
endif()

llvm/docs/AdvancedBuilds.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ CLANG_ENABLE_BOOTSTRAP.
3434

3535
.. code-block:: console
3636
37-
$ cmake -G Ninja -DCLANG_ENABLE_BOOTSTRAP=On <path to source>
37+
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCLANG_ENABLE_BOOTSTRAP=On <path to source>
3838
$ ninja stage2
3939
4040
This command itself isn't terribly useful because it assumes default
@@ -48,7 +48,7 @@ CMake option, each variable separated by a ";". As example:
4848

4949
.. code-block:: console
5050
51-
$ cmake -G Ninja -DCLANG_ENABLE_BOOTSTRAP=On -DCLANG_BOOTSTRAP_PASSTHROUGH="CMAKE_INSTALL_PREFIX;CMAKE_VERBOSE_MAKEFILE" <path to source>
51+
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCLANG_ENABLE_BOOTSTRAP=On -DCLANG_BOOTSTRAP_PASSTHROUGH="CMAKE_INSTALL_PREFIX;CMAKE_VERBOSE_MAKEFILE" <path to source>
5252
$ ninja stage2
5353
5454
CMake options starting by ``BOOTSTRAP_`` will be passed only to the stage2 build.

llvm/docs/GettingStarted.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ This is an example workflow and configuration to get and build the LLVM source:
4848
* ``cd llvm-project``
4949
* ``mkdir build``
5050
* ``cd build``
51-
* ``cmake -G <generator> [options] ../llvm``
51+
* ``cmake -G <generator> -DCMAKE_BUILD_TYPE=<type> [options] ../llvm``
5252

5353
Some common build system generators are:
5454

@@ -665,7 +665,7 @@ To configure LLVM, follow these steps:
665665

666666
.. code-block:: console
667667
668-
% cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/install/path
668+
% cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=<type> -DCMAKE_INSTALL_PREFIX=/install/path
669669
[other options] SRC_ROOT
670670
671671
Compiling the LLVM Suite Source Code
@@ -677,7 +677,7 @@ invocation:
677677

678678
.. code-block:: console
679679
680-
% cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=type SRC_ROOT
680+
% cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=<type> -DCMAKE_BUILD_TYPE=type SRC_ROOT
681681
682682
Between runs, CMake preserves the values set for all options. CMake has the
683683
following build types defined:
@@ -784,7 +784,7 @@ platforms or configurations using the same source tree.
784784

785785
.. code-block:: console
786786
787-
% cmake -G "Unix Makefiles" SRC_ROOT
787+
% cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release SRC_ROOT
788788
789789
The LLVM build will create a structure underneath *OBJ_ROOT* that matches the
790790
LLVM source tree. At each level where source files are present in the source

llvm/docs/HowToCrossCompileLLVM.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ Finally, if you're using your platform compiler, run:
145145

146146
.. code-block:: bash
147147
148-
$ cmake -G Ninja <source-dir> <options above>
148+
$ cmake -G Ninja <source-dir> -DCMAKE_BUILD_TYPE=<type> <options above>
149149
150150
If you're using Clang as the cross-compiler, run:
151151

152152
.. code-block:: bash
153153
154-
$ CC='clang' CXX='clang++' cmake -G Ninja <source-dir> <options above>
154+
$ CC='clang' CXX='clang++' cmake -G Ninja <source-dir> -DCMAKE_BUILD_TYPE=<type> <options above>
155155
156156
If you have ``clang``/``clang++`` on the path, it should just work, and special
157157
Ninja files will be created in the build directory. I strongly suggest

llvm/docs/ReleaseNotes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ Changes to the LLVM IR
6969
Changes to building LLVM
7070
------------------------
7171

72+
* Omitting ``CMAKE_BUILD_TYPE`` when using a single configuration generator is now
73+
an error. You now have to pass ``-DCMAKE_BUILD_TYPE=<type>`` in order to configure
74+
LLVM. This is done to help new users of LLVM select the correct type: since building
75+
LLVM in Debug mode is very resource intensive, we want to make sure that new users
76+
make the choice that lines up with their usage. We have also improved documentation
77+
around this setting that should help new users. You can find this documentation
78+
`here <https://llvm.org/docs/CMake.html#cmake-build-type>`_.
79+
7280
Changes to TableGen
7381
-------------------
7482

llvm/docs/TestSuiteGuide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ There are two ways to run the tests in a cross compilation setting:
386386
```bash
387387
% cmake -G Ninja -D CMAKE_C_COMPILER=path/to/clang \
388388
-C ../test-suite/cmake/caches/target-arm64-iphoneos-internal.cmake \
389+
-D CMAKE_BUILD_TYPE=Release \
389390
-D TEST_SUITE_REMOTE_HOST=mydevice \
390391
../test-suite
391392
% ninja

0 commit comments

Comments
 (0)