Skip to content

scivision/cmake-build-gcc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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) : -Dversion=13.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 like:

 cmake -Durl=https://gcc.gnu.org/pub/gcc/snapshots/14.1.0-RC-20240503/gcc-14.1.0-RC-20240503.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

Make a script like below and source it to use this GCC:

#!/usr/bin/env bash

prefix=$HOME/gcc-devel

case "$OSTYPE" in
  darwin*)
    export LIBRARY_PATH=$prefix/lib:$LIBRARY_PATH
  ;;
  linux*)
    export LD_LIBRARY_PATH=$prefix/lib64:$prefix/lib:$LD_LIBRARY_PATH
  ;;
esac

export PATH=$prefix/bin:$PATH

export CC=$prefix/bin/gcc CXX=$prefix/bin/g++ FC=$prefix/bin/gfortran

Troubleshooting

About

Build GCC and prereqs driven by CMake

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Languages