create-urhoapp.mdx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. ---
  2. sidebar_position: 30
  3. ---
  4. import clsx from "clsx";
  5. import Tabs from '@theme/Tabs';
  6. import TabItem from '@theme/TabItem';
  7. import styles from './getting-started.module.scss';
  8. # Create New Project
  9. Create your first UrhoApp project
  10. You need an installed Urho3D library for the desired target platform to proceed. If you have been following along the previous section to install the library then you should be able to create a new project using the library in no time. The most commonly encountered issue by newbie in the past was figuring out how to tell the build script where to find the correct Urho3D library to use. The new rake tasks have been designed to address this issue by providing opinionated sane default for most of the use cases, but without sacrificing the possibility to override the default when necessary.
  11. ## Project Scaffolding
  12. All you need is to execute the following command to create a new UrhoApp project.
  13. ```bash
  14. rake new[UrhoApp,demo]
  15. ```
  16. By default, this task creates a new project named **UrhoApp** in the `~/projects/` directory. You can override that by specifying explicitly the name of the new project as well as the parent directory where it should be created, as shown in the example above. Next, change directory to the project root of the newly created project and build it. You can build using CLI or IDE too.
  17. :::info
  18. The UrhoApp project is cross-platform out of the box!
  19. :::
  20. ## Build UrhoApp project
  21. ### Using CLI {#build-urhoapp-project-using-cli}
  22. Simply invoke `rake build` or just `rake` (as build is the default task). In order to target a specific platform, set the `PLATFORM` environment variable just before invoking the task. By default, the build task assumes to target native platform of the host machine.
  23. <Tabs
  24. className={styles.cliUrhoApp}
  25. groupId={'target-platform'}
  26. defaultValue={'android'}
  27. values={[
  28. {label: 'Android', value: 'android'},
  29. {label: 'Apple', value: 'apple'},
  30. {label: 'Arm', value: 'arm'},
  31. {label: 'Linux', value: 'linux'},
  32. {label: 'RPI', value: 'rpi'},
  33. {label: 'Web', value: 'web'},
  34. {label: 'Windows', value: 'win'},
  35. ]
  36. }>
  37. <TabItem value={'android'}>
  38. ```bash
  39. # When using Rake task
  40. PLATFORM=android rake
  41. # When using Gradle wrapper on Linux or Mac
  42. ./gradlew build
  43. # When using Gradle wrapper on Windows
  44. gradlew.bat build
  45. ```
  46. </TabItem>
  47. <TabItem value={'apple'}>
  48. ```bash
  49. # When targeting macOS, "PLATFORM=macOS" is the default on Mac
  50. rake
  51. # When targeting iOS
  52. PLATFORM=iOS rake
  53. # When targeting tvOS
  54. PLATFORM=tvOS rake
  55. ```
  56. </TabItem>
  57. <TabItem value={'arm'}>
  58. ```bash
  59. # When compiling natively on the ARM board, "PLATFORM=arm" should be already set
  60. rake
  61. # When cross-compiling on Linux host machine, substitute '?' accordingly
  62. ARM_ABI_FLAGS=? ARM_PREFIX=? ARM_SYSROOT=? PLATFORM=arm rake
  63. ```
  64. </TabItem>
  65. <TabItem value={'linux'}>
  66. ```bash
  67. # When using GCC, "PLATFORM=linux" is the default on Linux
  68. rake
  69. # When using Clang, override the "CC" and "CXX" environment variables
  70. CC=clang CXX=clang++ rake
  71. ```
  72. </TabItem>
  73. <TabItem value={'rpi'}>
  74. ```bash
  75. # When compiling natively on the RPI board, "PLATFORM=rpi" should be already set
  76. RPI_ABI=RPI3 rake
  77. # When cross-compiling on Linux host machine, substitute '?' accordingly
  78. RPI_ABI=RPI3 RPI_PREFIX=? RPI_SYSROOT=? PLATFORM=rpi rake
  79. ```
  80. </TabItem>
  81. <TabItem value={'web'}>
  82. ```bash
  83. # When using Rake task on Linux or Mac
  84. PLATFORM=web rake
  85. # When using Rake task on Windows
  86. set "PLATFORM=web" && rake
  87. ```
  88. </TabItem>
  89. <TabItem value={'win'}>
  90. ```bash
  91. # When compiling natively using VS, "PLATFORM=win" is the default on Windows
  92. rake
  93. # When compiling natively using MinGW-w64
  94. set "GENERATOR=mingw" && rake
  95. # When cross-compiling on Linux host machine, substitute '?' accordingly
  96. MINGW_PREFIX=? PLATFORM=mingw rake
  97. ```
  98. </TabItem>
  99. </Tabs>
  100. Except for Android platform, the task generates the initial build tree under <code>build/<em>&lt;platform&gt;</em>/</code> relative to the project root. Assuming it was built successfully for Linux platform, you could then run the UrhoApp executable like so:
  101. ```bash
  102. build/linux/bin/UrhoApp
  103. ```
  104. For Android platform, you would have to use other gradle task (e.g., `installDebug`) to deploy the UrhoApp to an Android Emulator or actual device.
  105. ![UrhoApp screenshot on Android platform](/img/docs/urhoapp-android-screenshot.png)
  106. ### Using IDE {#build-urhoapp-project-using-ide}
  107. Similar to Urho3D project, the UrhoApp project can be opened directly in the IDE that supports CMake or Gradle build system or by opening the generated project file in the build tree.
  108. <Tabs
  109. className={styles.ideUrhoApp}
  110. groupId={'ide'}
  111. defaultValue={'android-studio'}
  112. values={[
  113. {label: 'Android Studio', value: 'android-studio'},
  114. {label: 'CLion', value: 'clion'},
  115. {label: 'Code::Blocks', value: 'code-blocks'},
  116. {label: 'CodeLite', value: 'codelite'},
  117. {label: 'IntelliJ IDEA', value: 'intellij'},
  118. {label: 'Visual Studio', value: 'visual-studio'},
  119. {label: 'Xcode', value: 'xcode'},
  120. ]
  121. }>
  122. <TabItem value={'android-studio'}>
  123. <div className={clsx('textBlock', styles.fixedHeight)}>
  124. :::caution
  125. Do not update the Android Gradle Plugin when being prompted, unless you know what you are doing.
  126. :::
  127. - Choose "Open an Existing Project" to open the new project.
  128. - After Gradle sync is completed, select "UrhoApp" from the "Edit Run/Debug Configurations" drop down list, and press "Ctrl+F9" to build the UrhoApp.
  129. - To run the UrhoApp, press "Shift+F10".
  130. </div>
  131. </TabItem>
  132. <TabItem value={'clion'}>
  133. <div className={clsx('textBlock', styles.fixedHeight)}>
  134. :::caution
  135. Disable the Gradle plugin and Gradle Native plugin as they may interfere and prevent proper project setup.
  136. :::
  137. - Choose "Open" to open the new project.
  138. - In the "Open Project Wizard" or in the "CMake Settings", set the `URHO3D_HOME` accordingly in the "CMake options" field, e.g.:
  139. - `~/.urho3d/install/linux` when targeting Linux platform with GCC
  140. - `%USERPROFILE%\.urho3d\install\win` when targeting Windows platform with MSVC
  141. - Select "UrhoApp" from the "Select Run/Debug Configuration" drop down list and press "Ctrl+F9" to build the UrhoApp.
  142. - To run the UrhoApp, press "Shift+F10".
  143. </div>
  144. </TabItem>
  145. <TabItem value={'code-blocks'}>
  146. <div className={clsx('textBlock', styles.fixedHeight)}>
  147. - Generate a build tree using CMake's Code::Blocks generator. One way to do it is by using rake task, like so: `GENERATOR=codeblocks rake cmake`
  148. - Open the "UrhoApp.cbp" Code::Blocks project file in the build tree. In the above case, the project file can be found in `build/linux-codeblocks/` directory.
  149. - **// FIXME: Please submit PR to complete the steps.**
  150. </div>
  151. </TabItem>
  152. <TabItem value={'codelite'}>
  153. <div className={clsx('textBlock', styles.fixedHeight)}>
  154. - Generate a build tree using CMake's CodeLite generator. One way to do it is by using rake task, like so: `GENERATOR=codelite rake cmake`
  155. - Open the "UrhoApp.workspace" CodeLite workspace file in the build tree. In the above case, the workspace file can be found in `build/linux-codelite/` directory.
  156. - **// FIXME: Please submit PR to complete the steps.**
  157. </div>
  158. </TabItem>
  159. <TabItem value={'intellij'}>
  160. <div className={clsx('textBlock', styles.fixedHeight)}>
  161. :::caution
  162. Do not update the Android Gradle Plugin when being prompted, unless you know what you are doing.
  163. :::
  164. - Choose "Open" to open the new project.
  165. - After Gradle sync is completed, select "UrhoApp" from the "Select Run/Debug Configuration" drop down list, and press "Ctrl+F9" to build the UrhoApp.
  166. - To run the UrhoApp, press "Shift+F10".
  167. </div>
  168. </TabItem>
  169. <TabItem value={'visual-studio'}>
  170. <div className={clsx('textBlock', styles.fixedHeight)}>
  171. - Choose "Open a project or solution" to open the new project.
  172. - After CMake initial build tree is generated, open the "CMake Settings for UrhoApp" under the "Project" menu, then in the "CMake variables and cache" section:
  173. - Disable the `URHO3D_PCH` build option
  174. - Set the `URHO3D_HOME` to `%USERPROFILE%\.urho3d\install\win`
  175. - Save the above changes to allow CMake to reconfigure the build tree.
  176. - Double click the "Folder View" in the "Solution Explorer", then select the "UrhoApp.exe" from the "Select Startup Item" drop down list and press "Ctrl+B" to build the UrhoApp.
  177. - To run the UrhoApp, press "Ctrl+F5".
  178. </div>
  179. </TabItem>
  180. <TabItem value={'xcode'}>
  181. <div className={clsx('textBlock', styles.fixedHeight)}>
  182. - Generate a build tree using CMake's Xcode generator. One way to do it is by using rake task, like so:
  183. - `rake cmake` for targeting macOS
  184. - `PLATFORM=iOS rake cmake` for targeting iOS
  185. - `PLATFORM=tvOS rake cmake` for targeting tvOS
  186. - Open the "UrhoApp.xcodeproj" Xcode project file in the build tree. In the above case, the project file can be found in "build/macos", "build/ios", and "build/tvos", respectively.
  187. - Select "UrhoApp" from the list of targets and press "⌘+B" to build the UrhoApp.
  188. - To run the UrhoApp, press "⌘+R".
  189. </div>
  190. </TabItem>
  191. </Tabs>
  192. ## Project Structure
  193. In order to reuse the same build system for Urho3D project to successfully build your own UrhoApp project, the UrhoApp project must be structured similarly to Urho3D project. Assuming you chose to use the `rake new` to create the UrhoApp project, you will have the following project structure under a new app directory:
  194. ```
  195. UrhoApp
  196. ├─ app
  197. │ ├─ build.gradle.kts
  198. │ ├─ CMakeLists.txt
  199. │ ├─ proguard-rules.pro
  200. │ └─ src
  201. │ ├─ cpp
  202. │ │ ├─ UrhoApp.cpp
  203. │ │ └─ UrhoApp.h
  204. │ ├─ java
  205. │ │ └─ io/urho3d/urhoapp
  206. │ │ └─ MainActivity.kt
  207. │ ├─ res
  208. │ | └─ (truncated)
  209. │ └─ AndroidManifest.xml
  210. ├─ bin
  211. │ ├─ CoreData
  212. │ │ └─ (as in Urho3D)
  213. │ └─ Data
  214. │ ├─ Materials
  215. │ │ └─ Mushroom.xml
  216. │ ├─ Models
  217. │ │ └─ Mushroom.mdl
  218. │ ├─ Music
  219. │ │ └─ Ninja Gods.ogg
  220. │ └─ Textures
  221. │ ├─ Mushroom.dds
  222. │ ├─ UrhoIcon.icns
  223. │ └─ UrhoIcon.png
  224. ├─ build.gradle.kts
  225. ├─ cmake
  226. │ └─ (as in Urho3D)
  227. ├─ CMakeLists.txt
  228. ├─ gradle/wrapper
  229. │ ├─ gradle-wrapper.jar
  230. │ └─ gradle-wrapper.properties
  231. ├─ gradle.properties
  232. ├─ gradlew
  233. ├─ gradlew.bat
  234. ├─ rakefile
  235. ├─ scripts
  236. │ └─ (as in Urho3D)
  237. ├─ settings.gradle.kts
  238. ├─ .clang-format
  239. ├─ .clang-tidy
  240. ├─ .gitattributes
  241. └─ .gitignore
  242. ```
  243. At the root of the project there are a few build scripts which can be grouped as follows:
  244. - **CMake** - consist of `CMakeLists.txt` and all the CMake modules and toolchains in the `cmake/` directory.
  245. - **Gradle** - consist of `build.gradle.kts`, `settings.gradle.kts`, `gradle.properties`, and the Gradle wrapper scripts.
  246. - **Shell** - consist of convenience *nix bash shell script and Windows batch files in the `script/` directory.
  247. - **Rake** - one `rakefile` that defines all the common tasks with opinionated default options.
  248. If you are very familiar with CMake then you can directly invoke `cmake`, `ccmake`, or `cmake-gui` to generate a build tree for all the supported platforms, except for Android platform. For the latter case you need to use `gradle`, or via its wrapper script if you don't have Gradle installed globally. For the most cases though, you will probably find it useful to use the convenience shell scripts or to use them as reference for your own convenience scripts. Finally, the `rake` command can be used to execute rake tasks for building the project and more.
  249. All the above are for the build system, the actual meat of the UrhoApp project are only residing in the following two directories:
  250. - `app/` - mainly contains the C++ source code in `src/cpp/` and Kotlin/Java source code in `src/java/`.
  251. - `bin/` - contains the assets used by the Urho3D game engine, at the very least it should have `CoreData/` and `Data/`.