Difference between revisions of "How to build VCMI (iOS)"

From VCMI Project Wiki
Jump to: navigation, search
m (note about cpack output extension)
(Replaced content with "{{Template:MovedToWebpage|https://vcmi.eu/developers/Building_iOS/}}")
 
Line 1: Line 1:
== Requirements ==
+
{{Template:MovedToWebpage|https://vcmi.eu/developers/Building_iOS/}}
# '''macOS'''
 
# Xcode: https://developer.apple.com/xcode/
 
# CMake 3.21+: <code>brew install --cask cmake</code> or get from https://cmake.org/download/
 
 
 
== Obtaining source code ==
 
Clone https://github.com/vcmi/vcmi with submodules. Example for command line:
 
<nowiki>git clone --recurse-submodules https://github.com/vcmi/vcmi.git</nowiki>
 
 
 
== Obtaining dependencies ==
 
There're 2 ways to get prebuilt dependencies:
 
 
 
* [https://github.com/vcmi/vcmi/tree/develop/docs/conan.md Conan package manager] - recommended. Note that the link points to the cutting-edge state in <code>develop</code> branch, for the latest release check the same document in the [https://github.com/vcmi/vcmi/tree/master/docs/conan.md master branch].
 
* [https://github.com/vcmi/vcmi-ios-deps legacy manually built libraries] - can be used if you have Xcode 11/12 or to build for simulator / armv7 device
 
 
 
== Configuring project ==
 
Only Xcode generator (<code>-G Xcode</code>) is supported!
 
 
 
As a minimum, you must pass the following variables to CMake:
 
 
 
* <code>BUNDLE_IDENTIFIER_PREFIX</code>: unique bundle identifier prefix, something like <code>com.MY-NAME</code>
 
* (if using legacy dependencies) <code>CMAKE_PREFIX_PATH</code>: path to the downloaded dependencies, e.g. <code>~/Downloads/vcmi-ios-depends/build/iphoneos</code>
 
 
 
There're a few [https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html CMake presets]: for device (Conan and legacy dependencies) and for simulator, named <code>ios-device-conan</code>, <code>ios-device</code> and <code>ios-simulator</code> respectively. You can also create your local "user preset" to avoid typing variables each time, see example [https://gist.github.com/kambala-decapitator/59438030c34b53aed7d3895aaa48b718 here].
 
 
 
Open terminal and <code>cd</code> to the directory with source code. Configuration example for device with Conan:
 
<nowiki>cmake --preset ios-device-conan \
 
  -D BUNDLE_IDENTIFIER_PREFIX=com.MY-NAME</nowiki>
 
 
 
By default build directory containing Xcode project will appear at <code>../build-ios-device-conan</code>, but you can change it with <code>-B</code> option.
 
 
 
=== Building for device ===
 
To be able to build for iOS device, you must also specify codesigning settings. If you don't know your development team ID, open the generated Xcode project, open project settings (click '''VCMI''' with blue icon on the very top in the left panel with files), select '''vcmiclient''' target, open '''Signing & Capabilities''' tab and select yout team. Now you can copy the value from '''Build Settings''' tab - <code>DEVELOPMENT_TEAM</code> variable (paste it in the Filter field on the right) - click the greenish value - Other... - copy. Now you can pass it in <code>CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM</code> variable when configuring the project to avoid selecting the team manually every time CMake re-generates the project.
 
 
 
Advanced users who know exact private key and provisioning profile to sign with, can use <code>CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY</code> and <code>CMAKE_XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER</code> variables instead. In this case you must also pass
 
 
 
<code>-D CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE=Manual</code>.
 
 
 
== Building project ==
 
 
 
=== From Xcode IDE ===
 
Open <code>VCMI.xcodeproj</code> from the build directory, select <code>vcmiclient</code> scheme (the only one with nice icon) with your destination device/simulator and hit Run (Cmd+R).
 
 
 
You must also install game files, see [[Installation on iOS]]. But this is not necessary if you are going to run on simulator, as it is able to use game data from your Mac located at <code>~/Library/Application Support/vcmi</code>.
 
 
 
=== From command line ===
 
<code>cmake --build <path to build directory> --target vcmiclient -- -quiet</code>
 
 
 
You can pass additional xcodebuild options after the <code>--</code>. Here <code>-quiet</code> is passed to reduce amount of output.
 
 
 
Alternatively, you can invoke <code>xcodebuild</code> directly.
 
 
 
There's also <code>ios-release-conan</code> configure and build preset that is used to create release build on CI.
 
 
 
== Creating ipa file for distribution ==
 
Invoke <code>cpack</code> after building:
 
 
 
<code>cpack -C Release</code>
 
 
 
This will generate file with extension '''ipa''' if you use CMake 3.25+ and '''zip''' otherwise (simply change extension to ipa).
 

Latest revision as of 16:07, 16 July 2024

Logo256.png    Page moved to VCMI-Homepage