PCSX2 Documentation/Compiling on Linux: Difference between revisions

From PCSX2 Wiki
Jump to navigation Jump to search
m (Honesty in labeling.)
 
(71 intermediate revisions by 8 users not shown)
Line 1: Line 1:
NOTE: Only 32-bit architectures are supported, or distributions that allow the installation of 32-bit packages under a 64-bit architecture.
The following is a guide on how to obtain and compile the PCSX2 source code on the Linux platform.


==Introduction==
'''For a more in-depth guide on the PCSX2 build process, please don't refer to this guide here, as it is massively outdated:'''
*[[PCSX2 Documentation/PCSX2 Build Scripts]]


This is intended to give you an idea of how to compile PCSX2 from git in Linux. Some of the steps may be different on some versions of Linux, and this is not generally supported by the PCSX2 team. If you have issues following this guide, I'd recommend going through this thread for help: http://forums.pcsx2.net/Thread-Linux-Compile-Guide-and-Support
==Obtaining the Source Code==


==CMake Build System==
PCSX2 is hosted on GitHub, a website where people can contribute to each others' programming projects using the Git version control software. GitHub is essentially just a showcase for your projects, to actually work on them you need to download and install Git itself.


===Debian/Ubuntu build dependencies===
*'''Arch Linux:''' <code># pacman -S git</code>
*'''Debian:''' <code># apt-get install git</code>
*'''Fedora:''' <code># dnf install git</code>


====Build system====
Next you are going to want to create a directory on your machine for the PCSX2 code to live in. For this example, let's say the directory you create is /home/your/workspace. You are going to want clone the remote PCSX2 repository like so:
<code>gcc</code>, <code>gcc-multilib</code>, <code>g++</code>, <code>g++-multilib</code>, <code>cmake</code>


====32-bit libraries on x86_64====
<source lang="bash">
<code>libaio-dev:i386</code>, <code>libbz2-dev:i386</code>, <code>libcggl:i386</code>, <code>libegl1-mesa-dev:i386</code>, <code>libglew-dev:i386</code>, <code>libgles2-mesa-dev</code>, <code>libgtk2.0-dev:i386</code>, <code>libjpeg-dev:i386</code>, <code>libsdl1.2-dev:i386</code>, <code>libsoundtouch-dev:i386</code>, <code>libsparsehash-dev</code>, <code>libwxgtk2.8-dev:i386</code>, <code>nvidia-cg-toolkit</code>, <code>portaudio19-dev:i386</code>, <code>zlib1g-dev:i386</code>
$ cd /home/your/workspace
$ git clone git@github.com:PCSX2/pcsx2.git --recurse
</source>


===Arch Linux build dependencies===
You are now making a copy of the remote repository into your own directory.


Some of the required packages to build PCSX2 are available only in the [AUR](https://aur.archlinux.org), so the use of an [AUR helper](https://wiki.archlinux.org/index.php/AUR_Helpers) (ex: yaourt) is highly advised!
==Setting up the Build System==


====Build system====
PCSX2 uses the cmake build system to create project files and other things for multiple platforms, and GCC or clang to compile on the linux platform.
<code>gcc</code>, <code>gcc-multilib</code>, <code>cmake</code>


====32-bit libraries====
Quick compile instructions:
Add or uncomment the following lines in <code>/etc/pacman.conf</code>:


<nowiki>
{| class="wikitable"
[Multilib]
|+ Compiling a release build.
Include = /etc/pacman.d/mirrorlist</nowiki>
|-
! Compiler/build system !! command
|-
| gcc/make || mkdir build && cd build && cmake --preset=gcc-release .. && make -j <number of jobs. Say 4 or 6 if you aren't sure.>
|-
| gcc/ninja || mkdir build && cd build && cmake --preset=gcc-release-ninja .. && ninja
|-
| clang/ninja/lld || mkdir build && cd build && cmake --preset=clang-release .. && ninja
|}


Refresh package list:
And run bin/pcsx2-qt .


<nowiki>
=== Compiling ===
pacman -Sy</nowiki>


`lib32-libaio`, `lib32-libcanberra`, `lib32-libjpeg-turbo`, `lib32-glew`, `lib32-nvidia-cg-toolkit`, `lib32-portaudio`, `lib32-soundtouch`, `lib32-wxgtk2.8` </nowiki>
To compile on linux, you will need git, cmake, and a compiler. For a compiler, gcc and clang are supported. If you are going to use the clang presets, also install lld as a linker. You'll also need make or ninja. Ninja is recommended, and required if using the clang presets.


===Using CMake===
====Arch====


====Basic mode: straightforward compilation====
The required packages to compile PCSX2 can be installed with:
Run the `build.sh` script.
<code># pacman -S cmake gcc</code>
You can view the available options with `build.sh -help`


====Expert mode: CMake build parameters====
and optionally:
Basic parameters:
<code># pacman -S clang lld ninja</code>
- Use Release/Devel/Debug : `-DCMAKE_BUILD_TYPE=Release|Devel|Debug`
  - `Release`: Best in speed, but provides little or no debug/crash info.
  - `Devel`: Adds detailed trace logging abilities, but still lacks debug/crash info.
  - `Debug`: No compiler optimizations. Very good for debug/crash info but also very slooowww.
- Follow XDG standard : `-DXDG_STD=TRUE`
- Build all plugins: `-DEXTRA_PLUGINS=TRUE`


Expert parameters (not supported, the best is to use the default options):
(base-devel has gcc in it as well, and may be a good idea to install.)
- Tune C flags : `-DUSER_CMAKE_C_FLAGS:STRING="cflags"`
- Tune C++ flags : `-DUSER_CMAKE_CXX_FLAGS:STRING="cxxflags"`
- Tune linker flags : `-DUSER_CMAKE_LD_FLAGS:STRING="ldflags"`


Expert debugging parameters (typical developper only option):
====Fedora====
- Build GS replayer: `-DBUILD_REPLAY_LOADERS=TRUE`
- Use Address Sanitizer: `-DUSE_ASAN=TRUE`
- Force wxWidget 2.8 (to spot a regression) : `-DWX28_API=TRUE`


Experimental parameters (not supported, the best is to use the default options):
The required packages to compile PCSX2 can be installed with:
- zzogl: Use GLSL for shading instead of nvidia cg : `-DGLSL_API=TRUE`
<code># sudo yum install cmake g++</code>
- zzogl: Use EGL instead of GLX : `-DEGL_API=TRUE`
- GSdx: Use openGL ES3.1 instead of pure openGL : `-DGLES_API=TRUE`
- Use SDL2 (wxWidget must be linked with SDL1) : `-DSL2_API=TRUE`
- Use GTK3 (wxWidget must be built with GTK3 support) : `-DGTK3_API=TRUE`
- Use clang (nothing work) : `-DUSE_CLANG=TRUE`
- 64 bits support (nothing work): `-D64BIT_BUILD_DONT_WORK=TRUE`


Expert options for package creation
and optionally:
- Enable package mode : follow the FHS for distribution `-DPACKAGE_MODE=TRUE`
<code># sudo yum install ninja-build lld clang</code>
- Plugin install path in package mode : `-DPLUGIN_DIR="/usr/lib/pcsx2"`
- GameDB install path in package mode : `-DGAMEINDEX_DIR="/usr/share/games/pcsx2"`
- GLSL shader install directory : `-DGLSL_SHADER_DIR="/usr/share/games/pcsx2"`
- Update po (translation file) : `-DCMAKE_BUILD_PO=TRUE`
- Rebuild shader : `-DREBUILD_SHADER=TRUE`
- Disable AVX: `-DDISABLE_ADVANCE_SIMD=TRUE`
- Enable/disable the stipping : `-DCMAKE_BUILD_STRIP=TRUE|FALSE`
  - `TRUE`: Remove debugging information.
  - `FALSE`: Keep symbols. Better for debug. (recommended since it should not have any impact on speed)


===Running CMake to generate the makefile:===
====Ubuntu====


It is advised to use a build method that places build files outside the PCSX2 sources directory, as it makes it easier to delete all CMake build files:
The required packages to compile PCSX2 can be installed with:
```
<code># sudo apt install cmake g++</code>
mkdir build && cd build
cmake .. <other options>
```


====Do the compilation:====
and optionally:
```
<code># sudo apt install ninja-build lld clang</code>
make
```


====Install files:====
(Like Arch, if you're having trouble, install build-essential)
```
make install  
```


===Reporting Cmake bugs===
====openSUSE====


Not all distributions and configurations were tested. In case you encounter a CMake bug that is really a CMake issue, you can report it. Please provide the following information:
The required packages to compile PCSX2 can be installed with:
<code>sudo zypper install cmake gcc gcc-c++</code>


1. Linux distribution, the current kernel version, and architecture (32-bit or 64-bit)
and optionally:
2. The CMake commands. For example: `cmake CMakeLists.txt`
<code># sudo zypper install ninja-build lld llvm-clang</code>
3. **All** of CMake's output. Something like this is good:


```
(Not absolutely sure the latter is correct. Could use testing.)
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found GTK2_GTK: /usr/lib/libgtk-x11-2.0.so
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found X11: /usr/lib/libX11.so
-- Found ALSA: /usr/lib/libasound.so
-- Found BZip2: /usr/lib/libbz2.so
-- Looking for BZ2_bzCompressInit in /usr/lib/libbz2.so
-- Looking for BZ2_bzCompressInit in /usr/lib/libbz2.so - found
-- Looking for include files CMAKE_HAVE_PTHREAD_H
-- Looking for include files CMAKE_HAVE_PTHREAD_H - found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found wxWidgets: TRUE
-- Found ZLIB: /usr/lib/libz.so
-- Found Cg: /usr/lib/libCg.so;/usr/lib/libCgGL.so
-- Found PortAudio: /usr/lib/libportaudio.so
-- Found SoundTouch: /usr/lib/libSoundTouch.so
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/playstation/emulateur/package/pcsx2.snapshot-4810
```


==Ubuntu PPA==
==Installing the Dependencies==


With multiarch functionality, you can install a 32-bit PPA on a 64-bit Ubuntu. You need at least Ubuntu 12.04 (Precise) to do this.
PCSX2 relies on a number of 3rd party software libraries, so you are going to need to obtain those before you can compile the source code. Here's a non-exhaustive list of these dependencies.</br>


====Add the x86 architecture to your package manager (x64 installs of 12.04 or newer only)====
If you don't have the following, it will use prebundled versions:
In a terminal, type:
<source lang="bash">
````
sdl2 >= 2.0.22
sudo dpkg --add-architecture i386
fmt >= 7.1.3
````
rapidyaml >= 0.4.0
zstd >= 1.4.5
libzip >= 1.8.0
</source>


====Add the multiverse package repository====
You have to have:
Uncomment lines looking like this, where trusty is replaced by your Ubuntu version
<source lang="bash">
````
pcap
deb http://us.archive.ubuntu.com/ubuntu/ trusty multiverse
liblzma
deb-src http://us.archive.ubuntu.com/ubuntu/ trusty multiverse
libaio
deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
libsoundtouch
deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
qt6
````
</source>


====Add the PCSX2 PPA to your software sources====
If your distribution has development versions of packages, you'll probably need those packages as well. With qt 6, we're probably talking something like:</br>
'''Fedora:'''
<source>yum install qt6-qtbase-devel qt6-qtbase-private-devel qt6-qttools-devel</source>


In a terminal, type:
'''OpenSuse:'''
```
<source>sudo zypper install qt6-base-devel qt6-base-private-devel qt6-tools-devel qt6-linguist-devel</source>
sudo add-apt-repository ppa:gregory-hainaut/pcsx2.official.ppa
sudo apt-get update
```


====Install the package on your system====
'''Ubuntu:'''
<source>apt install qt6-base-dev qt6-base-private-dev qt6-tools-dev qt6-tools-dev-tools qt6-l10n-tools</source>
```
sudo apt-get install pcsx2
```


==Arch Linux==
(All of those worked at one point, but need to be doublechecked.)
NOTE: for 64-bit architectures, multilib must be enabled in order to install PCSX2.  


===PCSX2 Stable===
==Compiling the Source==


Open a terminal, and type:  
If you didn't already get pcsx2's source, run:</br>
```
<code>$ git clone [email protected]:PCSX2/pcsx2.git --recurse</code>
sudo pacman -S pcsx2
```


===PCSX2 Unstable===
Now go into the pcsx2 directory:
Add or uncomment the following lines in `/etc/pacman.conf`:
<source>$ cd ./pcsx2</source>
```
If you forgot the "--recurse" part when cloning, run this command:
[Multilib]
<source>$ git submodule --init --recursive</source>
Include = /etc/pacman.d/mirrorlist
Now, make a build directory:
```
<source>$ mkdir -p ./build && cd ./build</source>
Refresh package list:
```
pacman -Sy
```


Download the tarball from the [AUR package page](https://aur.archlinux.org/packages/pcsx2-git), and unpack it.
Now, it is time to compile the source code! Easiest way to do that is with a preset.<br />
Open the folder that you just unpacked in a terminal, and type:
 
```
If you're using gcc/make:
makepkg -csi
<source lang="bash">$ cmake --preset=gcc-release ..
```
$ make -j <number of jobs. Say 4 or 6 if you aren't sure.></source>
This will build the package, automatically installing all dependencies. It will then prompt for your password to install the package with pacman.
 
If you are using gcc & ninja:
<source lang="bash">$ cmake --preset=gcc-release-ninja ..
$ ninja</source>
 
And if you are using clang with lld and ninja:
<source lang="bash">$ cmake --preset=clang-release ..  
$ ninja</source>
 
Here's a full list, if you want a different preset:
{| class="wikitable"
|+ For reference, here is the current list of presets:
|-
! Name !! Description
|-
| ninja-multi || Generates ninja build files for debug/devel/and release builds for gcc.
|-
| gcc-debug || For making a debug build with gcc and make.
|-
| gcc-devel || For making a development build with gcc and make.
|-
| gcc-release || For making a release build with gcc and make. Does not have LTO.
|-
| gcc-debug-ninja || For making a debug build with gcc and ninja. (ninja builds faster then make.)
|-
| gcc-devel-ninja || For making a development build with gcc and ninja.(ninja builds faster then make.)
|-
| gcc-release-ninja || For making a release build with gcc and ninja. Does not have LTO. (ninja builds faster then make.)
|-
| clang-debug || For making a debug build with clang and ninja. (Fastest builds.)
|-
| clang-devel || For making a development build with clang and ninja. (Fastest builds.)
|-
| clang-release || For making a release build with clang and ninja. (This one has lto, so has the slowest build time.)
|}
 
If omit any of the libraries or headers specified above (or other, newer dependencies not included here), CMake will abort, your compiler may skip certain parts of the overall build or the linker may fail to link all the dependencies into the final PCSX2 executable. The output from any one of these tools should be able to tell the dependencies you're missing.
 
==Running the Binary==
 
This process may take several minutes. Once it has finished, you should be able to run the pcsx2 binary, which should've been output to the <code>build/bin/</code> directory.
 
<source lang="bash">$ ./bin/pcsx2-qt</source>
 
==Additional external, likely outdated links==
* [http://forums.pcsx2.net/Thread-PCSX2-for-Debian-Ubuntu PCSX2 for Debian/Ubuntu]
* [http://forums.pcsx2.net/Thread-PCSX2-for-Archlinux PCSX2 for Archlinux]
* [http://forums.pcsx2.net/Thread-PCSX2-for-Fedora PCSX2 for Fedora]
* [http://forums.pcsx2.net/Thread-PCSX2-for-Gentoo PCSX2 for Gentoo]
 
 
{{PCSX2 Documentation Navbox}}

Latest revision as of 04:33, 13 January 2023

The following is a guide on how to obtain and compile the PCSX2 source code on the Linux platform.

For a more in-depth guide on the PCSX2 build process, please don't refer to this guide here, as it is massively outdated:

Obtaining the Source Code

PCSX2 is hosted on GitHub, a website where people can contribute to each others' programming projects using the Git version control software. GitHub is essentially just a showcase for your projects, to actually work on them you need to download and install Git itself.

  • Arch Linux: # pacman -S git
  • Debian: # apt-get install git
  • Fedora: # dnf install git

Next you are going to want to create a directory on your machine for the PCSX2 code to live in. For this example, let's say the directory you create is /home/your/workspace. You are going to want clone the remote PCSX2 repository like so:

<source lang="bash"> $ cd /home/your/workspace $ git clone [email protected]:PCSX2/pcsx2.git --recurse </source>

You are now making a copy of the remote repository into your own directory.

Setting up the Build System

PCSX2 uses the cmake build system to create project files and other things for multiple platforms, and GCC or clang to compile on the linux platform.

Quick compile instructions:

Compiling a release build.
Compiler/build system command
gcc/make mkdir build && cd build && cmake --preset=gcc-release .. && make -j <number of jobs. Say 4 or 6 if you aren't sure.>
gcc/ninja mkdir build && cd build && cmake --preset=gcc-release-ninja .. && ninja
clang/ninja/lld mkdir build && cd build && cmake --preset=clang-release .. && ninja

And run bin/pcsx2-qt .

Compiling

To compile on linux, you will need git, cmake, and a compiler. For a compiler, gcc and clang are supported. If you are going to use the clang presets, also install lld as a linker. You'll also need make or ninja. Ninja is recommended, and required if using the clang presets.

Arch

The required packages to compile PCSX2 can be installed with: # pacman -S cmake gcc

and optionally: # pacman -S clang lld ninja

(base-devel has gcc in it as well, and may be a good idea to install.)

Fedora

The required packages to compile PCSX2 can be installed with: # sudo yum install cmake g++

and optionally: # sudo yum install ninja-build lld clang

Ubuntu

The required packages to compile PCSX2 can be installed with: # sudo apt install cmake g++

and optionally: # sudo apt install ninja-build lld clang

(Like Arch, if you're having trouble, install build-essential)

openSUSE

The required packages to compile PCSX2 can be installed with: sudo zypper install cmake gcc gcc-c++

and optionally: # sudo zypper install ninja-build lld llvm-clang

(Not absolutely sure the latter is correct. Could use testing.)

Installing the Dependencies

PCSX2 relies on a number of 3rd party software libraries, so you are going to need to obtain those before you can compile the source code. Here's a non-exhaustive list of these dependencies.

If you don't have the following, it will use prebundled versions: <source lang="bash"> sdl2 >= 2.0.22 fmt >= 7.1.3 rapidyaml >= 0.4.0 zstd >= 1.4.5 libzip >= 1.8.0 </source>

You have to have: <source lang="bash"> pcap liblzma libaio libsoundtouch qt6 </source>

If your distribution has development versions of packages, you'll probably need those packages as well. With qt 6, we're probably talking something like:
Fedora: <source>yum install qt6-qtbase-devel qt6-qtbase-private-devel qt6-qttools-devel</source>

OpenSuse: <source>sudo zypper install qt6-base-devel qt6-base-private-devel qt6-tools-devel qt6-linguist-devel</source>

Ubuntu: <source>apt install qt6-base-dev qt6-base-private-dev qt6-tools-dev qt6-tools-dev-tools qt6-l10n-tools</source>

(All of those worked at one point, but need to be doublechecked.)

Compiling the Source

If you didn't already get pcsx2's source, run:
$ git clone [email protected]:PCSX2/pcsx2.git --recurse

Now go into the pcsx2 directory: <source>$ cd ./pcsx2</source> If you forgot the "--recurse" part when cloning, run this command: <source>$ git submodule --init --recursive</source> Now, make a build directory: <source>$ mkdir -p ./build && cd ./build</source>

Now, it is time to compile the source code! Easiest way to do that is with a preset.

If you're using gcc/make: <source lang="bash">$ cmake --preset=gcc-release .. $ make -j <number of jobs. Say 4 or 6 if you aren't sure.></source>

If you are using gcc & ninja: <source lang="bash">$ cmake --preset=gcc-release-ninja .. $ ninja</source>

And if you are using clang with lld and ninja: <source lang="bash">$ cmake --preset=clang-release .. $ ninja</source>

Here's a full list, if you want a different preset:

For reference, here is the current list of presets:
Name Description
ninja-multi Generates ninja build files for debug/devel/and release builds for gcc.
gcc-debug For making a debug build with gcc and make.
gcc-devel For making a development build with gcc and make.
gcc-release For making a release build with gcc and make. Does not have LTO.
gcc-debug-ninja For making a debug build with gcc and ninja. (ninja builds faster then make.)
gcc-devel-ninja For making a development build with gcc and ninja.(ninja builds faster then make.)
gcc-release-ninja For making a release build with gcc and ninja. Does not have LTO. (ninja builds faster then make.)
clang-debug For making a debug build with clang and ninja. (Fastest builds.)
clang-devel For making a development build with clang and ninja. (Fastest builds.)
clang-release For making a release build with clang and ninja. (This one has lto, so has the slowest build time.)

If omit any of the libraries or headers specified above (or other, newer dependencies not included here), CMake will abort, your compiler may skip certain parts of the overall build or the linker may fail to link all the dependencies into the final PCSX2 executable. The output from any one of these tools should be able to tell the dependencies you're missing.

Running the Binary

This process may take several minutes. Once it has finished, you should be able to run the pcsx2 binary, which should've been output to the build/bin/ directory.

<source lang="bash">$ ./bin/pcsx2-qt</source>

Additional external, likely outdated links