Skip to content

scivision/cmake-build-gcc

Repository files navigation

CMake build GCC

Build GCC natively for C, C++, Fortran languages. Builds prerequisite libraries GMP, MPFR, and MPC from CMake.

Platforms working include:

  • Linux (Intel / AMD CPU)

Numerous platforms require specific patches that we don't currently implement. The easiest way may be to clone their GCC fork as we do for Apple Silicon.

This CMake project can be more convenient than manually downloading and configuring each project. We assume fundamental prerequisites such as libc, Autotools, Make, CMake are present. The 3-stage compiler bootstrap is enabled to help ensure a working, performant GCC.

Prerequsites

  • CentOS: dnf install cmake make autoconf autoconf-archive libtool
  • Ubuntu: apt install cmake make autoconf autoconf-archive libtool
  • macOS: brew install cmake autoconf autoconf-archive libtool

Options

These options may be changed by adding the CMake configure arguments:

Set GCC version (Linux only, as macOS uses a GCC fork) : -Dgcc_version=14.2.0

disable ISL for Graphite optimizations : -Disl=off

disable C++ : -Dcpp=off

disable Fortran : -Dfortran=off

disable Gcov coverage tool :-Dgcov=off

disable link time optimization : -Dlto=off

disable Zstd : -Dzstd=off

disable Zstd compression (fallback to Zlib) : -Dzstd=off

Build

This CMake project assumes the system already has Autotools, Make, and a new-enough C/C++ compiler. GCC will take 10s of minutes to build, even on a powerful workstation. The following commands build GCC and install it to ~/gcc-devel. By default, a recent release of GCC is built using source from the GCC GitHub mirror.

cmake -Dprefix=$HOME/gcc-devel -P build.cmake

This script sets environment variables during the build phase to avoid missing .so messages when building GCC.

Specify a URL say from GCC snapshots like:

 cmake -Durl=https://gcc.gnu.org/pub/gcc/snapshots/LATEST-15/gcc-15-20240526.tar.xz -P build.cmake

macOS Apple Silicon may need the GCC gcc-darwin-arm64 fork:

cmake -Durl=https://github.com/iains/gcc-darwin-arm64/archive/refs/heads/master-wip-apple-si.zip -P build.cmake

Usage

Source a script like gcc-dev.sh to use this GCC.

Troubleshooting

About

Build GCC and prereqs driven by CMake

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published