The guide for installing SWI-Prolog from source is maintained on the SWI-Prolog website at the following location. Here you notably find how to download the system, prepare the sources and get the dependencies for your environment.
https://www.swi-prolog.org/build/
Hints for using CMake to configure SWI-Prolog are in CMAKE.md.
Installing from source is typically a good idea on Linux and *BSD systems. On MacOS it is adviced to use the binary installer or install from source using Macports or Homebrew. The Windows version is cross-compiled on a Linux machine using MinGW. We provide a Docker recipe for building.