Allowed the Linux toolchain file to accept a compiler override (#656)

cmake/linux.cmake set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER unconditionally.
CMake reads a toolchain file before it consults CC and CXX, and a plain set()
in a toolchain file also takes precedence over -DCMAKE_C_COMPILER, so neither
of the two usual ways to pick a compiler had any effect: the tree could only
ever be built with whatever /usr/bin/gcc happened to point at.

That matters because AGENTS.md names GCC 14 as the project's default compiler
on Linux, while distributions still ship an older gcc as the default for some
time. Selecting GCC 14 previously meant either editing this file or changing
the machine's system-wide default.

Both variables now fall back to gcc and g++ only when nothing else has been
specified, so the default build is byte-for-byte what it was, while
-DCMAKE_C_COMPILER=gcc-14 or CC=gcc-14 now work as expected.

The binutils variables in this file are left alone: they are unused on the
Linux target, so guarding them would be unrelated churn.

Assisted-by: Claude Code (Opus 5)
This commit is contained in:
Frédéric Desbiens
2026-08-24 13:42:31 -04:00
committed by GitHub
parent 9218bad4bc
commit 5a68c9da4b
+19 -2
View File
@@ -1,8 +1,25 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_COMPILER g++)
# Let the compiler be chosen on the command line or from the environment, for example
# -DCMAKE_C_COMPILER=gcc-14 or CC=gcc-14. CMake reads a toolchain file before it consults
# CC and CXX, so setting these unconditionally would quietly override both and leave no
# way to build with anything but the distribution's default gcc.
if(NOT DEFINED CMAKE_C_COMPILER)
if(DEFINED ENV{CC})
set(CMAKE_C_COMPILER $ENV{CC})
else()
set(CMAKE_C_COMPILER gcc)
endif()
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER)
if(DEFINED ENV{CXX})
set(CMAKE_CXX_COMPILER $ENV{CXX})
else()
set(CMAKE_CXX_COMPILER g++)
endif()
endif()
set(AS as)
set(AR ar)
set(OBJCOPY objcopy)