Get Involved/development/Set up a development environment: Difference between revisions

From KDE Community Wiki
(other KDE files)
(Replace page with move to link)
Tag: Replaced
 
(59 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{Info|'''Everything on this page only needs to be done once.''' Once you've done it, your development environment is set up and you can use it to submit patches and develop KDE Software!}}
Moved to: https://develop.kde.org/docs/getting-started/building/kdesrc-build-setup/
 
{{Note|This procedure will set up kdesrc-build for Qt5 and KDE Frameworks 5.<br/>
Setting up kdesrc-build for Qt6 and KDE Frameworks 6 and setting up kdesrc-build inside a Docker container are [[Get_Involved/development/More|advanced topics]].}}
 
Source code for KDE software lives on [https://invent.kde.org KDE Invent]. But before you can work on it, you'll need to set up a '''development environment''': a set of tools that allows you to access and edit the source code, compile it into a form that the computer can run, and deploy it to a safe location. We will now go through the process of setting one up. To accomplish these tasks, you will need to enter commands using a terminal program, such as KDE's [https://apps.kde.org/konsole Konsole].
 
If you're not familiar with the command line interface, you can [[Get_Involved/development/Learn#Unix_command_line|find tutorials here]]. However, advanced command-line skills are not required, and you will learn what you need along the way!
 
If you're a visual learner, we also provide [[Get_Involved/development/Video|video tutorials about setting up kdesrc-build]].
 
== Install basic tools ==
First you will need to use your operating system's package manager to install some basic tools:
* KDE Neon/Kubuntu/Ubuntu/Debian: <code>sudo apt update && sudo apt install git</code>
* Arch/Manjaro: <code>sudo pacman -S git cmake dialog extra-cmake-modules</code>
* Fedora: <code>sudo dnf install git perl perl-IPC-Cmd perl-MD5 perl-FindBin</code>
* openSUSE Tumbleweed: <code>sudo zypper refresh && sudo zypper install git</code>
 
== Configure Git ==
We need to set your authorship information properly so that any changes you make can be properly attributed to you:
{{Input|1=<nowiki>
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
</nowiki>}}
 
The name you provide should be your actual name, not your KDE Identity username or a pseudonym. And the email address must be the same as the email address used for your https://bugs.kde.org account. If they don't match, then the <code>BUG: </code> and <code>FEATURE: </code> keywords won't work (see [[Policies/Commit_Policy#Special_keywords_in_GIT_and_SVN_log_messages|this page]] for more information).
 
Next, in order to authenticate yourself when pushing code changes, you need to add an ssh key to your GitLab profile as [https://invent.kde.org/help/user/ssh.md described here].
 
== Set up kdesrc-build ==
<code>kdesrc-build</code> is the official KDE meta-build-system tool. It is used to manage the building of many software repositories in an automated fashion. Its primary purpose is to '''manage dependencies'''. Every software has dependencies: other pieces of software that provide lower-level functionality they rely on. In order to compile any piece of software, its dependencies must be available.
 
KDE software has two types of dependencies: dependencies on other pieces of KDE software, and dependencies on 3rd-party software. For example, the KDE application KCalc depends on more than 20 other KDE git repositories as well as the Qt toolkit.
 
Some Linux distributions do not provide development packages for [https://develop.kde.org/products/frameworks/ KDE Frameworks] and of other libraries that are up-to-date enough for us to build from the "main" branch of the KDE git repositories (the branch where the development of the next software versions takes place), so we use <code>kdesrc-build</code> to compile them ourselves. The goal is to avoid using KDE binaries, KDE libraries and other KDE files from the operating system where possible (in the Linux case, these files reside in the <code>/usr</code> directory).
 
Let's set it up now! First, create a new directory for all the KDE source code. You will need many gigabytes of free disk space. Budget 50 GB for KDE Frameworks + KDE Plasma, and 10-30 GB more for some apps as well. Then clone the <code>kdesrc-build</code> git repository in that directory:
 
{{Input|1=<nowiki>
mkdir -p ~/kde/src
cd ~/kde/src/
git clone https://invent.kde.org/sdk/kdesrc-build.git && cd kdesrc-build
</nowiki>}}
 
Next, some distros need source repos enabled before you can install the development packages you need. Do that now, if needed:
 
* '''KDE neon/Debian/Ubuntu/Kubuntu/etc:''' <code>sudo sed -i '/^# deb-src/s/^# //' /etc/apt/sources.list && sudo apt update</code>
* '''openSUSE Leap & Tumbleweed:''' <code>sudo zypper mr -e $(zypper repos | awk '/source/{print $5}')</code>
 
With that done, it's time to run the initial setup program, which will make some changes to your <code>~/.bashrc</code> (or  <code>~/.zshrc</code> for zsh users) and install necessary 3rd-party packages:
 
{{Input|1=<nowiki>
./kdesrc-build --initial-setup
source ~/.bashrc
</nowiki>}}
 
The step <code>./kdesrc-build --initial-setup</code> above installs the Linux binary packages that are needed such that <code>kdesrc-buid</code> can build all of KDE Frameworks.
 
{{Note|If you use zsh and you selected yes for auto-completions during <code>kdesrc-build --initial-setup</code>, add the following two lines to <code>~/.zshrc</code> if these two lines are not already there:
<pre>autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit</pre>
If you use fish, you might need to run the following for kdesrc-build and kdesrc-run to appear in your PATH:
<pre>fish_add_path ~/kde/src/kdesrc/build</pre>
}}
 
For more details about 3rd-party dependencies, see [[Get_Involved/development/Install_the_dependencies]]
 
{{Note|This process installs 3rd-party dependencies once, but they can change over time, and <code>kdesrc-build</code> is currently not smart enough to track those changes and apply them later; see https://invent.kde.org/sdk/kdesrc-build/-/issues/9 for more details. So if in the future, you happen to find any external dependencies needed to build KDE software that were not installed with <code>kdesrc-build --initial-setup</code>, then once you finish this tutorial, please send a merge request to https://invent.kde.org/sdk/kdesrc-build/-/blob/master/modules/ksb/FirstRun.pm in order to include the needed packages to the list.}}
 
== Set up Qt ==
Qt is the fundamental framework that is needed for pretty much all KDE development. A recent enough version of Qt is required to proceed.
 
The initial setup of kdesrc-build should have installed the required Qt6 packages for you already. Otherwise, the list of packages can be seen here:
 
<div class="toccolours mw-collapsible mw-collapsed" style="overflow:auto;">
<div style="font-weight:bold;line-height:1.6;">List of Qt6 packages</div>
<div class="mw-collapsible-content">
 
* Debian/Ubuntu:
<pre>
sudo apt install qt6-tools-dev qt6-declarative-dev libqt6core5compat6-dev qt6-wayland qt6-wayland-dev qt6-wayland-dev-tools qt6-base-private-dev libqt6svg6-dev libqt6opengl6-dev libqt6shadertools6-dev doxygen xsltproc xmlto texinfo libutfcpp-dev
 
sudo apt build-dep appstream # I.e. apt install libyaml-dev libsystemd-dev libgirepository1.0-dev libstemmer-dev itstool gi-docgen
</pre>
 
* openSUSE Tumbleweed:
 
For Plasma you will also need the following runtime dependency: <code>sudo zypper in qt6-qt5compat-imports</code>
 
* Arch Linux:
<pre>sudo pacman -S poppler-qt6 qca-qt6 qt6-5compat qt6-base qt6-charts qt6-declarative qt6-multimedia qt6-multimedia-ffmpeg qt6-positioning qt6-tools qt6-translations qt6-wayland qt6-webchannel qt6-webengine qt6-websockets qt6-webview qtkeychain-qt6 qcoro-qt6 qt6-svg qt6-shadertools qt6-sensors</pre>
 
* Fedora:
<pre>sudo dnf install expat-devel libcurl-devel libyaml-devel gtk-doc
 
sudo dnf builddep appstream</pre>
 
</div>
</div>
 
If you have the required packages, proceed to the next section.
 
If your Linux distribution does not provide these packages, it may be a good time to switch distros to something [[Get_Involved/development#Operating_system|better suited for building KDE software from source code]] either as the primary operating system or in a virtual machine. Alternatively, you may also [[Get_Involved/development/More#Build_Qt_using_kdesrc-build|build Qt6 using kdesrc-build]], or [https://community.kde.org/Get_Involved/development/More#Qt_6_installed_using_Qt_online_installer install Qt6 from the online installer].
 
== Disable indexing for your development environment ==
You'll want to disable indexing for your development-related git repos and the files they will build and install. Add <tt>~/kde</tt> to the exclusions list in System Settings > Workspace > Search > File Search, like so:
 
[[File:Getting involved development file index options.png|center|600px|]]
 
== Prepare kdesrc-build to build with Qt6 ==
 
<!-- Remove this whole section once https://invent.kde.org/sdk/kdesrc-build/-/merge_requests/287 is merged -->
 
KDE projects are currently transitioning to Qt6, and so the <code>~/.config/kdesrc-buildrc</code> that is generated during initial setup still targets Qt5. To build projects using Qt6, copy the sample file provided together with kdesrc-build to its right place:
 
<pre>
cp ~/kde/src/kdesrc-build/kdesrc-buildrc-kf6-sample  ~/.config/kdesrc-buildrc
</pre>
 
<!-- Remove the following once https://invent.kde.org/sdk/kdesrc-build/-/merge_requests/295 is merged -->
 
You should then edit the file and change the entries to point to your installation of kdesrc-build, in this tutorial, <code>~/kde</code>. If you used a different installation, for example <code>~/kdecontributions</code>, something like:
 
<pre>kdedir ~/kde6/usr</pre>
 
should be changed to:
 
<pre>kdedir ~/kdecontributions/usr</pre>
 
Certain projects will by default build both their Qt5 and Qt6 variants. In order to build only the Qt6 version, append the following at the end of the file <code>~/kde/src/kdesrc-buildrc</code>:
 
<pre>
options plasma-integration
    cmake-options -DBUILD_WITH_QT6=ON -DBUILD_QT5=OFF
end options
 
options breeze
    cmake-options -DBUILD_WITH_QT6=ON -DBUILD_QT5=OFF
end options
</pre>
 
== Next Steps ==
'''Reboot your computer''' and log back in so the package changes, and the <code>~/.bashrc</code> changes take effect on your user account. Once that's done, your development environment is set up and ready to build software. Time to learn how to use <code>kdesrc-build</code> tool to build software from source code!
 
{{CenteredButton|text=Start compiling KDE software using kdesrc-build|link=Get_Involved/development/Build_software_with_kdesrc-build}}

Latest revision as of 16:13, 18 April 2024