2013-09-03 14:34:29 +04:00
.. _building-label:
2015-08-31 11:48:43 +03:00
===============================
2013-09-03 14:34:29 +04:00
Appendix A: Building the Client
===============================
2012-10-31 17:44:18 +04:00
2021-02-26 21:59:25 +03:00
The goal of this section is to set up a build environment for developing
and testing the Nextcloud Desktop client. If you just want to use the
Nextcloud Desktop client without developing and testing it, you should
download the latest stable build instead.
2012-10-31 17:44:18 +04:00
2021-02-26 21:59:25 +03:00
.. note :: These instructions represent a particular streamlined and easy-to-understand
methodology, but they are by no means the only way of setting up a build
environment.
2013-11-06 14:13:55 +04:00
2021-02-26 21:59:25 +03:00
The steps listed here have been tested multiple times and should allow you
to build the client and/or the documentation with not warnings or errors.
These instructions should be current with the version, |version|, of the
Nextcloud Client with which it ships. If you are using the most recent version
of these instructions, and you run into errors or warnings with the latest
code from the repository, please open a GitHub Issue to let us know so we can
document a workaround or fix any underlying problems.
2016-02-25 00:31:19 +03:00
2021-02-26 21:59:25 +03:00
Using GitHub
------------
2019-10-19 15:21:04 +03:00
2021-02-26 21:59:25 +03:00
By default, cloning the GitHub repository will give you the "master" branch,
which is the most recent. If for some reason you want to build an older
version of the Nextcloud Desktop client, you can choose a branch corresponding
with that version. However, for older versions of the client, please be mindful
that any issues present may have been fixed in more recent versions.
2019-10-19 15:21:04 +03:00
2021-02-26 21:59:25 +03:00
.. note :: Doing anything other than just downloading the existing code will
require you to have a GitHub account.
2019-10-19 15:21:04 +03:00
2021-02-26 21:59:25 +03:00
If your goal in cloning and building the Nextcloud Desktop client is to
contribute to its development, and you are not already a "collaborator"
on the Nextcloud Desktop GitHub repository, you will need to create a "fork"
by clicking the "fork" button in the upper right on any GitHub page in the
repository. It is important to do this in advance because the URL for cloning
the repository is different for a fork than for the main official version.
2019-10-19 15:21:04 +03:00
2021-02-26 21:59:25 +03:00
When cloning a GitHub repository, you have two options for authenticating your
GitHub account, SSH or HTTPS. SSH requires additional setup but is more secure
and simplifies things later on. For an explanation of the differences between
HTTPS and SSH, as well as instructions to set up SSH, see this `GitHub
help article`_ on the subject.
2013-11-06 14:13:55 +04:00
2021-02-26 21:59:25 +03:00
.. _`GitHub help article`: https://help.github.com/en/articles/which-remote-url-should-i-use
2012-10-31 17:44:18 +04:00
2021-02-26 21:59:25 +03:00
The most basic version of the Git command for cloning a repository is as follows:
2013-01-22 18:08:56 +04:00
2021-02-26 21:59:25 +03:00
.. code-block :: bash
2012-10-31 17:44:18 +04:00
2021-02-26 21:59:25 +03:00
$ git clone <repository_url>
2014-06-26 00:04:33 +04:00
2021-02-26 21:59:25 +03:00
Which will clone the repository into the directory where you run the command.
2016-10-19 12:12:11 +03:00
2021-02-26 21:59:25 +03:00
The four versions of the `` git clone `` command are as follows:
2016-10-19 12:12:11 +03:00
2021-02-26 21:59:25 +03:00
1. HTTPS from the official repository:
2012-10-31 18:19:00 +04:00
2021-02-26 21:59:25 +03:00
.. code-block :: bash
2012-10-31 18:19:00 +04:00
2021-02-26 21:59:25 +03:00
$ git clone https://github.com/nextcloud/desktop.git
2017-01-18 16:46:47 +03:00
2021-02-26 21:59:25 +03:00
2. SSH from the official repository:
2017-01-18 16:46:47 +03:00
2021-02-26 21:59:25 +03:00
.. code-block :: bash
2013-05-17 13:40:43 +04:00
2021-02-26 21:59:25 +03:00
$ git clone git@github.com:nextcloud/desktop.git
2013-05-17 13:40:43 +04:00
2021-02-26 21:59:25 +03:00
3. HTTPS from a fork (see above):
2014-10-27 22:50:07 +03:00
2021-02-26 21:59:25 +03:00
.. code-block :: bash
2014-10-27 22:50:07 +03:00
2021-02-26 21:59:25 +03:00
% git clone https://github.com/<github_username>/desktop.git
2014-10-27 22:50:07 +03:00
2021-02-26 21:59:25 +03:00
4. SSH from a fork (see above):
2014-10-27 22:50:07 +03:00
2021-02-26 21:59:25 +03:00
.. code-block :: bash
2016-02-05 16:55:29 +03:00
2021-02-26 21:59:25 +03:00
% git clone git@github.com:<github_username> /desktop.git
2019-10-19 17:11:49 +03:00
2021-02-26 21:59:25 +03:00
macOS Development Build
-----------------------
2019-10-19 17:11:49 +03:00
2021-02-26 21:59:25 +03:00
.. note :: While it is possible to do many of the following steps using GUI
frontends, wherever possible the Terminal commands are listed instead, in order
to streamline the process.
2012-10-31 17:44:18 +04:00
2021-02-26 21:59:25 +03:00
1. Install Xcode from the Mac App Store:
https://apps.apple.com/app/xcode/id497799835
Then, in Terminal:
2. Install Xcode command line tools:
.. code-block :: bash
% xcode-select – install
3. Install Homebrew from `brew.sh`_ (which will just give you the following):
.. _`brew.sh`: https://brew.sh
.. code-block :: bash
% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2023-06-02 14:55:08 +03:00
.. note :: Under certain circumstances, you may get on error along the
2021-02-26 21:59:25 +03:00
lines of `` Permission denied @ apply2files `` when installing certain
Homebrew packages. This is `a known issue`_ and can be fixed by changing
the permissions on the affected files with the following command:
.. code-block :: bash
% sudo chown -R $(whoami):admin /usr/local/* \
&& sudo chmod -R g+rwx /usr/local/*
This workaround may lead to other shell warnings.
.. _`a known issue`: https://stackoverflow.com/a/63241724
4. Install Homebrew packages:
.. code-block :: bash
2024-05-07 22:58:22 +03:00
% brew install git qt qtkeychain cmake openssl glib cmocka karchive
2021-02-26 21:59:25 +03:00
5. Certain Homebrew packages are not automatically linked in places where
the build scripts can find them, so you can create a shell-profile script
that will find and load them dynamically when you run a build:
.. code-block :: bash
2024-05-07 22:58:22 +03:00
% echo 'export QT_PATH=$(brew --prefix qt6)/bin' >> ~/.nextcloud_build_variables
% echo 'export CMAKE_PREFIX_PATH=$(brew --prefix qt6);$(brew --prefix karchive)' >> ~/.nextcloud_build_variables
2021-02-26 21:59:25 +03:00
.. note :: The name `` ~/.nextcloud_build_variables `` is just a suggestion for
convenience. You can use a different file or create an entire shell
script, but this way of doing things is the simplest to explain.
6. Clone the Nextcloud repository to a convenient location, such as `` ~/Repositories `` :
.. code-block :: bash
% mkdir ~/Repositories
(if it doesn't already exist), then:
.. code-block :: bash
% cd ~/Repositories
.. note :: The cloned repository can go basically anywhere your user account
has write access, though it should not go in a directory synced with another
cloud service (especially not iCloud Drive). `` ~/Repositories `` is recommended
for tidiness and consistency.
.. code-block :: bash
% git clone <repository_url>
(See the above section on using GitHub for an explanation of what URL to use.)
7. Create build directory:
.. code-block :: bash
% cd ~/Repositories/desktop
% mkdir build
8. Generate the build files:
.. note ::
By default Nextcloud Desktop will build in a protected directory on macOS,
so you need to specify a build location. You can do this every time you build,
or you can add it to your save build variables, like so:
.. code-block :: bash
2021-04-19 10:32:53 +03:00
% echo 'export CMAKE_INSTALL_PREFIX=~/Builds' >> ~/.nextcloud_build_variables
2021-11-17 13:52:47 +03:00
# If you want to build a macOS app bundle for distribution
% echo 'export BUILD_OWNCLOUD_OSX_BUNDLE=ON' >> ~/.nextcloud_build_variables
2021-02-26 21:59:25 +03:00
2021-04-19 10:32:53 +03:00
Replace `` ~/Builds `` with a different directory if you'd like the build to end up elsewhere.
2021-02-26 21:59:25 +03:00
..
.. code-block :: bash
% source ~/.nextcloud_build_variables
% cd ~/Repositories/desktop/build
% cmake ..
9. Compile and install:
.. code-block :: bash
% make install
2012-10-31 17:44:18 +04:00
2015-02-04 18:51:28 +03:00
Windows Development Build
2017-02-20 12:52:22 +03:00
-------------------------
2012-10-31 17:44:18 +04:00
2024-05-07 22:51:44 +03:00
System requirements
-------------------
- Windows 10 or Windows 11
- `The desktop client code <https://github.com/nextcloud/desktop> `_
- Python 3
- PowerShell
- Microsoft Visual Studio 2022 and tools to compile C++
- `KDE Craft <https://community.kde.org/Craft> `_
2015-02-04 18:51:28 +03:00
2024-05-07 22:51:44 +03:00
Setting up Microsoft Visual Studio
----------------------------------
2015-02-04 18:51:28 +03:00
2024-05-07 23:01:33 +03:00
1. Click on 'Modify' in the Visual Studio Installer:
2015-02-04 18:51:28 +03:00
2024-05-07 22:51:44 +03:00
.. image :: ./images/building/visual-studio-installer.png
:alt: Visual Studio Installer
2024-05-07 23:01:33 +03:00
2. Select 'Desktop development with C++'
2024-05-07 22:51:44 +03:00
.. image :: ./images/building/desktop-development-with-cpp.png
:alt: Desktop development with C++
Handling the dependencies
-------------------------
2024-05-07 23:55:18 +03:00
We handle the dependencies using `KDE Craft <https://community.kde.org/Craft> `_ because it is easy to set it up and it makes the maintenance much more reliable in all platforms.
2024-05-07 22:51:44 +03:00
2024-05-07 23:01:33 +03:00
1. Set up KDE Craft as instructed in `Get Involved/development/Windows - KDE Community Wiki <https://community.kde.org/Get_Involved/development/Windows> `_ - it requires Python 3 and PowerShell.
2. After running:
2024-05-07 22:51:44 +03:00
.. code-block :: winbatch
2015-02-04 18:51:28 +03:00
2024-05-07 22:51:44 +03:00
C:\CraftRoot\craft\craftenv.ps1
2015-02-04 18:51:28 +03:00
2024-05-07 23:01:33 +03:00
3. Add the `desktop client blueprints <https://github.com/nextcloud/desktop-client-blueprints> `_ - the instructions to handle the client dependencies:
2015-02-04 18:51:28 +03:00
2024-05-07 22:51:44 +03:00
.. code-block :: winbatch
2015-02-04 18:51:28 +03:00
2024-05-07 22:51:44 +03:00
craft --add-blueprint-repository [git]https://github.com/nextcloud/desktop-client-blueprints.git
craft craft
2015-02-04 18:51:28 +03:00
2024-05-07 23:01:33 +03:00
4. Install all client dependencies:
2015-02-04 18:51:28 +03:00
2024-05-07 22:51:44 +03:00
.. code-block :: winbatch
2015-02-04 18:51:28 +03:00
2024-05-07 22:51:44 +03:00
craft --install-deps nextcloud-client
2015-02-04 18:51:28 +03:00
2024-05-07 22:51:44 +03:00
Compiling
---------
2015-02-04 18:51:28 +03:00
2024-05-07 23:55:18 +03:00
1. Make sure your environment variable %PATH% has no conflicting information to the environment you will use to compile the client. For instance, if you have installed OpenSSL previously and have added it to %PATH%, the OpenSSL installed might be a different version than what was installed via KDE Craft.
2024-05-07 23:01:33 +03:00
2. Open the Command Prompt (cmd.exe)
3. Run:
2024-05-07 22:51:44 +03:00
.. code-block :: winbatch
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
2024-05-07 23:01:33 +03:00
4. To use the tools installed with Visual Studio, you need the following in your %PATH%:
2024-05-07 22:51:44 +03:00
.. image :: ./images/building/path.png
:alt: Windows environment variables
2024-05-07 23:01:33 +03:00
5. Alternatively you can use the tools installed with KDE Craft by adding them to %PATH%:
2024-05-07 22:51:44 +03:00
.. code-block :: winbatch
set "PATH=C:\CraftRoot\bin;C:\CraftRoot\dev-utils\bin;%PATH%"
.. note ::
C:\CraftRoot is the path used by default by KDE Craft. When you are setting it up you may choose a different folder.
2015-02-04 18:51:28 +03:00
2024-05-07 23:01:33 +03:00
6. Create build folder, run cmake, compile and install:
2015-02-04 18:51:28 +03:00
2024-05-07 22:51:44 +03:00
.. code-block :: winbatch
2015-02-04 18:51:28 +03:00
2024-05-07 22:51:44 +03:00
cd <desktop-repo-path>
mkdir build
cd build
cmake .. -G Ninja -DCMAKE_INSTALL_PREFIX=. -DCMAKE_PREFIX_PATH=C:\CraftRoot -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build . --target install
2024-05-07 23:01:33 +03:00
7. Now you can use `Qt Creator <https://doc.qt.io/qtcreator> `_ to import the build folder with its configurations to be able to work with the code.
2021-02-26 21:59:25 +03:00
Windows Installer (i.e. Deployment) Build (Cross-Compile)
2021-04-19 10:32:53 +03:00
---------------------------------------------------------
2015-02-04 18:51:28 +03:00
Due to the large number of dependencies, building the client installer for Windows
is **currently only officially supported on openSUSE** , by using the MinGW cross compiler.
2016-02-05 16:55:29 +03:00
You can set up any currently supported version of openSUSE in a virtual machine if you do not
2014-06-26 00:04:33 +04:00
have it installed already.
2018-06-04 12:44:03 +03:00
In order to make setup simple, you can use the provided Dockerfile to build your own image.
2012-10-31 17:44:18 +04:00
2018-01-29 03:15:00 +03:00
1. Assuming you are in the root of the Nextcloud Client's source tree, you can
2016-02-05 16:55:29 +03:00
build an image from this Dockerfile like this::
2012-10-31 17:44:18 +04:00
2016-06-05 11:56:56 +03:00
cd admin/win/docker
2018-01-29 03:15:00 +03:00
docker build . -t nextcloud-client-win32:<version>
2012-10-31 17:44:18 +04:00
2016-02-05 16:55:29 +03:00
Replace `` <version> `` by the version of the client you are building, e.g.
|version| for the release of the client that this document describes.
If you do not wish to use docker, you can run the commands in `` RUN `` manually
in a shell, e.g. to create your own build environment in a virtual machine.
2014-06-26 00:04:33 +04:00
2016-02-05 16:55:29 +03:00
.. note :: Docker images are specific to releases. This one refers to |version|.
Newer releases may have different dependencies, and thus require a later
version of the docker image! Always pick the docker image fitting your release
2018-01-29 03:15:00 +03:00
of Nextcloud client!
2014-06-26 00:04:33 +04:00
2016-02-05 16:55:29 +03:00
2. From within the source tree Run the docker instance::
2012-11-19 21:15:25 +04:00
2018-01-29 03:15:00 +03:00
docker run -v "$PWD:/home/user/client" nextcloud-client-win32:<version> \
2016-06-13 16:30:06 +03:00
/home/user/client/admin/win/docker/build.sh client/ $(id -u)
2012-11-21 17:57:04 +04:00
2016-02-05 16:55:29 +03:00
It will run the build, create an NSIS based installer, as well as run tests.
You will find the resulting binary in an newly created `` build-win32 `` subfolder.
2012-10-31 17:44:18 +04:00
2016-02-05 16:55:29 +03:00
If you do not wish to use docker, and ran the `` RUN `` commands above in a virtual machine,
you can run the indented commands in the lower section of `` build.sh `` manually in your
source tree.
2014-06-26 00:04:33 +04:00
2016-02-05 16:55:29 +03:00
4. Finally, you should sign the installer to avoid warnings upon installation.
This requires a `Microsoft Authenticode`_ Certificate `` osslsigncode `` to sign the installer::
2012-10-31 17:44:18 +04:00
2016-02-06 17:01:04 +03:00
osslsigncode -pkcs12 $HOME/.codesign/packages.pfx -h sha256 \
2015-02-27 19:13:14 +03:00
-pass yourpass \
-n "ACME Client" \
-i "http://acme.com" \
-ts "http://timestamp.server/" \
-in ${unsigned_file} \
-out ${installer_file}
2014-10-27 21:53:12 +03:00
2017-02-20 12:52:22 +03:00
For `` -in `` , use the URL to the time stamping server provided by your CA along with the Authenticode certificate. Alternatively,
2015-02-27 19:13:14 +03:00
you may use the official Microsoft `` signtool `` utility on Microsoft Windows.
2016-02-05 16:55:29 +03:00
If you're familiar with docker, you can use the version of `` osslsigncode `` that is part of the docker image.
2015-02-27 19:13:14 +03:00
2015-08-31 12:12:47 +03:00
.. _generic-build-instructions:
2015-08-31 11:48:43 +03:00
2012-10-31 17:44:18 +04:00
Generic Build Instructions
--------------------------
2012-10-31 18:19:00 +04:00
2015-01-30 20:14:42 +03:00
Compared to previous versions, building the desktop sync client has become easier. Unlike
earlier versions, CSync, which is the sync engine library of the client, is now
part of the client source repository and not a separate module.
2014-06-26 00:04:33 +04:00
2016-02-26 19:37:54 +03:00
To build the most up-to-date version of the client:
2014-06-26 00:04:33 +04:00
2021-02-26 21:59:25 +03:00
1. Clone the latest versions of the client from Git_ as follows:
2014-06-26 00:04:33 +04:00
2021-02-26 21:59:25 +03:00
.. code-block :: bash
2014-03-07 12:56:28 +04:00
2021-02-26 21:59:25 +03:00
$ git clone git://github.com/nextcloud/client.git
$ cd client
$ git submodule update --init
2014-03-07 12:56:28 +04:00
2021-02-26 21:59:25 +03:00
2. Create the build directory
.. code-block :: bash
$ mkdir client-build
$ cd client-build
2012-10-31 17:44:18 +04:00
2021-02-26 21:59:25 +03:00
3. Configure the client build
2012-10-31 17:44:18 +04:00
2021-02-26 21:59:25 +03:00
.. code-block :: bash
$ cmake -DCMAKE_BUILD_TYPE="Debug" ..
2018-06-04 12:44:03 +03:00
2016-02-05 16:55:29 +03:00
.. note :: You must use absolute paths for the `` include `` and `` library ``
directories.
2014-10-27 22:50:07 +03:00
2018-06-04 12:44:03 +03:00
.. note :: On macOS, you need to specify `` -DCMAKE_INSTALL_PREFIX=target `` ,
2016-02-05 16:55:29 +03:00
where `` target `` is a private location, i.e. in parallel to your build
dir by specifying `` ../install `` .
2018-06-04 12:44:03 +03:00
2017-04-03 15:49:41 +03:00
.. note :: qtkeychain must be compiled with the same prefix e.g `` CMAKE_INSTALL_PREFIX=/Users/path/to/client/install/ . ``
2018-06-04 12:44:03 +03:00
2024-05-07 22:58:22 +03:00
.. note :: Example:: `` cmake -DCMAKE_PREFIX_PATH=/usr/local/opt/qt6 -DCMAKE_INSTALL_PREFIX=/Users/path/to/client/install/ ``
2018-06-04 12:44:03 +03:00
2014-06-26 00:04:33 +04:00
4. Call `` make `` .
2014-03-07 12:56:28 +04:00
2018-01-29 03:15:00 +03:00
The Nextcloud binary will appear in the `` bin `` directory.
2018-06-04 12:44:03 +03:00
5. (Optional) Call `` make install `` to install the client to the
`` /usr/local/bin `` directory.
2012-10-31 17:44:18 +04:00
2014-06-26 00:04:33 +04:00
The following are known cmake parameters:
2013-03-11 19:18:20 +04:00
2014-06-26 00:04:33 +04:00
* `` QTKEYCHAIN_LIBRARY=/path/to/qtkeychain.dylib -DQTKEYCHAIN_INCLUDE_DIR=/path/to/qtkeychain/ `` :
Used for stored credentials. When compiling with Qt5, the library is called `` qt5keychain.dylib. ``
You need to compile QtKeychain with the same Qt version.
2014-10-27 21:53:12 +03:00
* `` WITH_DOC=TRUE `` : Creates doc and manpages through running `` make `` ; also adds install statements,
providing the ability to install using `` make install `` .
2024-05-07 22:58:22 +03:00
* `` CMAKE_PREFIX_PATH=/path/to/Qt6/6.7.0/yourarch/lib/cmake/ `` : Builds using Qt6.
2014-10-27 22:50:07 +03:00
* `` CMAKE_INSTALL_PREFIX=path `` : Set an install prefix. This is mandatory on Mac OS
2013-03-11 19:18:20 +04:00
2021-04-19 17:08:00 +03:00
Address Sanitizer
=================
You can enable the address sanitizer to detect memory corruptions and other mistakes.
The are the following sanitizers are available:
* Address Sanitizer
* Leak anitizer
* Memory sanitizer
* Undefined sanitizer
* Threads sanitizer
You can enable one or more sanitizers through CMake. For example, to
enable the address and the undefined sanitizer, execute CMake like
`` cmake .. -D ECM_ENABLE_SANITIZERS="address;undefined" `` .
Keep in mind that not all combinations of sanitizers work together, and on some
platforms, not all types of sanitizers are available. For example, on Windows there is
currently only the address sanitizer available. If you are on Windows, you need to
make sure that the linker can find the sanitizer dlls at runtime. If you installed
Visual Studio in the standard location, you could find them in
**C:/ProgramFiles (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/x64/lib/clang/10.0.0/lib/windows** .
Make sure you add this location to your path. You may also need to
`upgrade your Visual Studio version <https://docs.microsoft.com/en-us/cpp/sanitizers/asan?view=msvc-160#install-the-addresssanitizer> `_ .
.. note :: If you use Visual Studio on Windows, you can enable the
sanitizer if you click on **Manage Configurations** , scroll
down to the section **CMake Command Arguments** and enter then
`` -D ECM_ENABLE_SANITIZERS="address" `` in the text input field below.
After that, click on **Save and generate CMake cache to load variables**
right above the table.
2015-02-04 18:51:28 +03:00
.. _CMake: http://www.cmake.org/download
2012-10-31 17:44:18 +04:00
.. _CSync: http://www.csync.org
2018-01-29 03:15:00 +03:00
.. _Client Download Page: https://nextcloud.com/install/#install-clients
2012-10-31 17:44:18 +04:00
.. _Git: http://git-scm.com
2017-07-21 09:54:06 +03:00
.. _OpenSSL Windows Build: http://slproweb.com/products/Win32OpenSSL.html
2015-02-04 18:51:28 +03:00
.. _Qt: http://www.qt.io/download
2016-02-25 00:31:19 +03:00
.. _Microsoft Authenticode: https://msdn.microsoft.com/en-us/library/ie/ms537361%28v=vs.85%29.aspx
2014-10-27 21:53:12 +03:00
.. _QtKeychain: https://github.com/frankosterfeld/qtkeychain