Skip to main content

Installation

Using native and cross-compiler toolchains to install Urho3D library

Requirements#

First prepares the build environment by installing a compiler toolchain for your target platform, and the required build tools. The compiler can be GCC, Clang, MSVC, MinGW-w64, or the one bundled in the SDK like Android SDK, Emscripten SDK, etc. On Ubuntu you can easily prepare the build environment by installing the build-essential package, on Windows by installing Visual Studio IDE, and on macOS by installing Xcode IDE. However, for cross-compiling usually you have to download and install the corresponding SDK manually. Make sure at the minimum the build environment has these build tools installed:

  • CMake
  • Git
  • Rake

Optionally these as well:

  • ccache - for speeding up the build
  • Doxygen and Graphviz - for building documentation

Although Urho3D project has included all required third-party libraries as source code, there may be system-level dependency packages that must be satisfied before Urho3D can be built from source successfully. The list below is by no mean comprehensive nor canonical, this is especially true on platforms with Linux operating system, but it should get you started.

note

This may change in the future when the project uses better package manager and Modern CMake. Ideally, the project should bootstrap itself with more ease than currently is.

Install OpenJDK, and Android Studio or IntelliJ IDEA.
Remember to complete the Android SDK installation as per instructed by IDE.

Tested tool version: 29.0.2
Tested NDK version: 21.3.6528147
Tested Android gradle plugin version: 4.0.2

Required RAM size: 16 GB

In general when cross-compiling the build system requires both the cross-compiler and native compiler toolchains to be installed on the host machine. This is because Urho3D build system builds the host-tool using the native compiler on the fly while cross-compiling the library for the target platform in one go. Check the table below on the supported cross-compiling scenario using Linux, Mac, and Windows host machine, respectively.

LinuxMacWindows
Target PlatformAndroid
Apple
Arm
Linux
RPI
Web
Windows
Click or tap on the table for more information

Setup ccache#

It is highly recommended having ccache installed on Linux build environment. It reduces the recompilation time drastically. To activate it, simply export these environment variables:

~/.bash_profile
export USE_CCACHE=1 CCACHE_SLOPPINESS=pch_defines,time_macros CCACHE_COMPRESS=1
# When also targeting Android platform
export ANDROID_CCACHE=$(which ccache)

Adjust the PATH environment variable so that the ccache symlinks directory is in front of the /usr/bin entry, if it has not been automatically system-wide adjusted after installing the package. Basically by doing so, whenever a compiler command is about to be invoked, it would be "intercepted" and invoking one of the ccache symlinks instead.

~/.bashrc
PATH=$(whereis -b ccache |grep -o '[^ ]*$'):$PATH

Finally, below is an easy way to verify the setup.

[[ -L $(which gcc) ]] && echo "Good!" || echo "Oh no!"
info

This is the reason Dockerized Build Environment is fast.

Install Urho3D Library#

Using CLI#

Clone the Urho3D project from the main branch, change directory to its project root, and execute only one of the following commands to install the library for your desired target platform. For simplicity's sake, this section provides instruction that install the Urho3D library into a default install location under user's home directory that does not require superuser privilege. Unless specified otherwise, the default install location is ~/.urho3d/install/<platform>/. For example, on Linux platform with GCC it is ~/.urho3d/install/linux/. For Clang on Linux platform it is ~/.urho3d/install/linux-clang/ to prevent clash with GCC. For Android platform, it is installed in ~/.m2/repository/ as AAR in Maven format.

caution

On Windows host the environment variables have to be set on separate command before invoking Rake task.

# When using Rake task, always install to Maven local repository
PLATFORM=android rake build install
# When using Gradle wrapper on Linux or Mac
./gradlew build publishToMavenLocal
# When using Gradle wrapper on Windows
gradlew.bat build publishToMavenLocal

Using IDE#

The Urho3D project can be opened directly in the IDE that supports CMake or Gradle build system, like Android Studio, CLion, IntelliJ IDEA, and Visual Studio. For other IDEs, like Xcode, use CMake to generate the initial build tree first. This section tries to cover a few of the IDEs available in the market. The steps outlined here should be easily adaptable for other IDEs.

caution

Do not update the Android Gradle Plugin when being prompted, unless you know what you are doing.

  • Choose "Open an Existing Project" or "Get from Version Control" if you haven't cloned the Urho3D project yet.
  • After Gradle sync is completed, select "launcher-app" from the "Edit Run/Debug Configurations" drop down list, and press "Ctrl+F9" to build the sample launcher app. This should build the Urho3D library as well.
  • To run the sample app, press "Shift+F10".
  • To install the Urho3D library for later use, locate the Gradle task called publishToMavenLocal and execute it.