Here is some information on getting started with building and using Urho3D for Mac OSX users running 10.11 El Capitan.
- When trying to build Urho3D I ran into a bug with one of the dependencies. Apply this patch to fix this issue in file Urho3D/Source/ThirdParty/SDL/src/video/cocoa/SDL_cocoavideo.h. It should look like
/* Fix build with the 10.10 SDK */
#if MAC_OS_X_VERSION_MAX_ALLOWED < 101100
#define NSEventSubtypeTouch NSTouchEventSubtype
#endif
/* Fix build with the 10.11 SDK */
#if MAC_OS_X_VERSION_MAX_ALLOWED < 101200
#define NSEventSubtypeMouseEvent NSMouseEventSubtype
#endif
- When building, I found that the precompiled header isn’t supported. See this thread (it’s a common problem for Mac users). Go into CMakeCache.txt and set “URHO3D_PCH:BOOL=OFF”, or pass
-DURHO3D_PCH=OFF
to cmake when building the library. - Move the Urho3D folder to a location where it can live for the rest of its life. I have a folder called ‘Libs’.
- Whenever you make a new project that will pull in the built Urho3D as a library (e.g. by adapting this or following this tutorial) you have to add the library’s location to the ‘URHO3D_HOME’ environment variable. I went to my sample project’s CMakeCache.txt and set ‘URHO3D_HOME:PATH=/Users/vmost/Libs/Urho3D’. A more reliable way is to add
export URHO3D_HOME=~/Libs/Urho3D
to yourcmake_etc.sh
script file, or bake it into your CMakeLists.txt file withset (ENV{URHO3D_HOME} "~/Libs/Urho3D")
. - When I built my sample project for a little ‘hello world’, the console spit out a bunch of garbage, which you can silence with this patch. Dive into the sample project’s CMakeLists.txt file and add these lines:
set(other_flags "${other_flags} -frtti -fvisibility-inlines-hidden")
set(other_flags "${other_flags} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ ${other_flags}")
With those issues out of the way, here is how to actually build the library (you need git and cmake installed, which can be done with homebrew).
git clone https://github.com/urho3d/Urho3D
cd Urho3D
cmake .
make
- oh, it’s done (after 30mins and assuming nothing else crops up); in Urho3D/bin are a bunch of samples that have been automatically built. You can also use the ‘Urho3DPlayer’ found in that same folder to run a script. It can run any of the samples
a.cd Urho3D/bin
b../Urho3DPlayer Scripts/sample_name.as [options]
c. example option (see the docs):-v
turns on vertical sync, which is interesting
And some hints on setting up a sample project. Keep this page in mind, as it has a lot of information!
- This tutorial is a good starting spot.
- Rather than try and put together everything from scratch, it’s best to just copy several things and run the cmake script to do the rest of the work. Here are the essential parts of an infant project.
a. Folder: bin; contains [CoreData] and [Data] folders (can copy them out of Urho3D/bin)
b. Folder: CMake; contains [Modules] and [Toolchains] folders (can copy Urho3D/CMake folder directly)
c. Folder: script; contains [cmake_generic.sh] (can copy out of Urho3D/script), and [cmake_projectname.sh] which contains the line$(dirname $0)/cmake_generic.sh
. Use the second one for adding stuff instead of editing the generic script.
d. Folder: Source; put C++ source files in here (code files, header files, etc). Need at least one file e.g. ‘app_main.cpp’ which creates an Application derived class and callsURHO3D_DEFINE_APPLICATION_MAIN(MyApp)
e. File: CMakeLists.txt; paste in the stuff from this link. Have to change ‘project name’ and ‘target name’, and add these lines since I prefer putting source files in their own folder:
# Define source files
file (GLOB SRC_CPP_FILES Source/*.cpp)
file (GLOB SRC_H_FILES Source/*.h)
define_source_files (GROUP EXTRA_CPP_FILES ${SRC_CPP_FILES} EXTRA_H_FILES ${SRC_H_FILES})
- The happy moment is when you hit
script/cmake_projectname.sh ./
andmake
, and then your executable shows up inproject_folder/bin
.
note: There are so many things to learn here, I hope these resources are helpful pointers.
Anyway, that’s the first step on this journey.