Urho3D Wiki
Register
Advertisement

This tries to be a shorter and easier version of http://urho3d.github.io/documentation/1.5/_using_library.html.

(There's an old guide for Urho 1.32 here: Creating a new Urho3D 1.32 Project.

1. Urho3D Environment Variable

Create a new environment variable (user or system variable) called "URHO3D_HOME" and set the value to the path where you build Urho into:

Urho sv

How this is done in Windows is explained in more details here: Building Urho 1.5 (Windows 10, MinGW/GCC)#3._Set_up_MinGW_for_CMake

2. Create and Fill Project Folder

You can use this quite minimal Urho Sample Project to skip copying and filling the folder manually: https://github.com/gawag/UrhoSampleProject

2. 1. Copy those files and folders from Urho

CMake/
cmake_generic.bat

2.2. Copy one or more of the "cmake_*.bat" files depending on the build system you want to use. If you are using codeblocks, copy "cmake_codeblocks.bat". If you are not on Windows, get the files ending on ".sh" instead of ".bat".

2.3. Create a "bin" folder with a "CoreData" and a "Data" folder inside. You may want to copy "CoreData" from Urho to get same basic materials.

2.4. Create a "CMakeLists.txt" and fill it with:

# Set project name
project (SampleProject)
# Define target name
set (TARGET_NAME SampleProject)
######################################
# Set minimum version
cmake_minimum_required (VERSION 2.8.6)
if (COMMAND cmake_policy)
cmake_policy (SET CMP0003 NEW)
if (CMAKE_VERSION VERSION_GREATER 2.8.12 OR CMAKE_VERSION VERSION_EQUAL 2.8.12)
# INTERFACE_LINK_LIBRARIES defines the link interface
cmake_policy (SET CMP0022 NEW)
endif ()
if (CMAKE_VERSION VERSION_GREATER 3.0.0 OR CMAKE_VERSION VERSION_EQUAL 3.0.0)
# Disallow use of the LOCATION target property - therefore we set to OLD as we still need it
cmake_policy (SET CMP0026 OLD)
# MACOSX_RPATH is enabled by default
cmake_policy (SET CMP0042 NEW)
endif ()
endif ()
# Set CMake modules search path
set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
# Include Urho3D Cmake common module
include (Urho3D-CMake-common)
# Find Urho3D library
find_package (Urho3D REQUIRED)
include_directories (${URHO3D_INCLUDE_DIRS})
# Define source files
define_source_files ()
# Setup target with resource copying
setup_main_executable ()

Replace SampleProject with your project name.

2.5. Create source files. CMake needs at least one .cpp file to set the linker correctly.

Your folder could now look like:

Urho new project

3. Prepare Build and Build

Like in Building Urho 1.5 (Windows 10, MinGW/GCC)#4._Run_CMake_to_create_the_project_files_for_Urho open a terminal and use the cmake script to generate the project build files:

Urho new project prepare

You have to use the same options you used to build Urho.

You can also use the CMake GUI:

Urho new project cmake gui

Note for Mac OS X: There is an issue with the default STL not fully supporting C++11. You need to switch the STL to libc++ with "-stdlib=libc++" like

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")

4. Build

Open the created project file and build it:

Urho new project build
Advertisement