Skip to content

Commit 3358c77

Browse files
authored
[CMake] Deprecate GCC_INSTALL_PREFIX (#77537)
Part of https://reviews.llvm.org/D158218 GCC_INSTALL_PREFIX is a rarely-used legacy option inherited from pre-CMake build system and has configuration file replacement nowadays. Many `clang/test/Driver` tests specify `--gcc-toolchain=` to prevent failures when `GCC_INSTALL_PREFIX` is specified: some contributors add them to fix tests and some just do cargo culting. This is not healthy for contributors adding cross compilation support for this rarely used option. `DEFAULT_SYSROOT` should in spirit be deprecated as well, but a relative path doesn't have good replacement, so don't deprecate it for now. Link: https://discourse.llvm.org/t/add-gcc-install-dir-deprecate-gcc-toolchain-and-remove-gcc-install-prefix/65091 Link: https://discourse.llvm.org/t/correct-cmake-parameters-for-building-clang-and-lld-for-riscv/72833 --- With `GCC_INSTALL_PREFIX=/usr`, `clang a.c` behaves like `clang --gcc-toolchain=/usr a.c`. Here is a simplified version of GCC installation detection code. ``` if (OPT_gcc_install_dir_EQ) return OPT_gcc_install_dir_EQ; if (OPT_gcc_triple) candidate_gcc_triples = {OPT_gcc_triple}; else candidate_gcc_triples = collectCandidateTriples(); if (OPT_gcc_toolchain) prefixes = {OPT_gcc_toolchain}; else prefixes = {OPT_sysroot/usr, OPT_sysroot}; for (prefix : prefixes) if "$prefix/lib/gcc" exists // also tries $prefix/lib/gcc-cross for (triple : candidate_gcc_triples) if "$prefix/lib/gcc/$triple" exists return "$prefix/lib/gcc/$triple/$version"; // pick the largest version ``` `--gcc-toolchain=` specifies a directory where `lib/gcc{,-cross}/$triple/$version` can be found. If you actually want to use a specific version of GCC, specify something like `--gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/11` in a configuration file. You can also specify `--gcc-triple=`. On Debian and its derivatives where the target triple omits the vendor part, the following ways are roughly equivalent, except that `--gcc-install-dir=` specifies a version as well: ``` clang --gcc-toolchain=/usr a.c clang --gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/11 a.c clang --gcc-triple=x86_64-linux-gnu a.c ```
1 parent 5c9b713 commit 3358c77

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

clang/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ set(C_INCLUDE_DIRS "" CACHE STRING
193193
set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." )
194194
set(DEFAULT_SYSROOT "" CACHE STRING
195195
"Default <path> to all compiler invocations for --sysroot=<path>." )
196+
if(GCC_INSTALL_PREFIX)
197+
message(WARNING "GCC_INSTALL_PREFIX is deprecated and will be removed. Use "
198+
"configuration files (https://clang.llvm.org/docs/UsersManual.html#configuration-files)"
199+
"to specify the default --gcc-install-dir= or --gcc-triple=. --gcc-toolchain= is discouraged. "
200+
"See https://github.com/llvm/llvm-project/pull/77537 for detail.")
201+
endif()
196202

197203
set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld")
198204

clang/docs/ReleaseNotes.rst

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ These changes are ones which we think may surprise users when upgrading to
3737
Clang |release| because of the opportunity they pose for disruption to existing
3838
code bases.
3939

40+
- The CMake variable ``GCC_INSTALL_PREFIX`` (which sets the default
41+
``--gcc-toolchain=``) is deprecated and will be removed. Specify
42+
``--gcc-install-dir=`` or ``--gcc-triple=`` in a `configuration file
43+
<https://clang.llvm.org/docs/UsersManual.html#configuration-files>` as a
44+
replacement.
45+
(`#77537 <https://github.com/llvm/llvm-project/pull/77537>`_)
4046

4147
C/C++ Language Potentially Breaking Changes
4248
-------------------------------------------

0 commit comments

Comments
 (0)