-
Notifications
You must be signed in to change notification settings - Fork 1
Generation of C language natives
This step in the project automation and creation was arguably the more complex portion, being how Quorum code calls down to natively written functions in C, C++, and Objective-C, some interacting with the iOS operating system, through JNI.
Much of this code was already in place, but was spread out among various archive files and was hard to recompile and move between machines.
In summary before getting into the details, what I did here was take the Xcode and cmake projects incorporated in the following static archive files from the previous Quorum iOS iteration:
- libGameEngineCPlugins.a
- libfreetype.a
- libObjectAL.a
And merged these into a single compact cmake project, that is capable of generating the Xcode project needed to compile for iOS architectures.
This was necessary as we required the ability to compile for different devices, being simulators and physical devices, while also having control over which version of iOS we target. The source code for these native packages was modified slightly to cope with the new project structure, where most edits were to imports.
To begin, delete all auto generated files/folders present in the xcode_all_natives_v2allcmake folder. Your directory structure should now only contain the following folders:
|-xcode_all_natives_v2allcmake
|--ObjectAL
|--freetype-2.5.5
|--ios
|--ios_cmake
Now that all the generated content has been removed, we can issue the cmake generation command within the xcode_all_natives_v2allcmake folder (note paths must be modified, full path required for toolchain file):
/Applications/CMake.app/Contents/bin/cmake -G Xcode ./freetype-2.5.5/CMakeLists.txt -DCMAKE_TOOLCHAIN_FILE=/Users/nickvancise/Desktop/xcode_all_natives_v2allcmake/ios_cmake/iOS.cmake -B.
If you encounter an error related to the CmakeCache.txt, simply delete it as it will be regenerated.
Explanation:
This command uses my local cmake (present from the Cmake Application) to generate an Xcode project, based on the modified CmakeLists.txt present in the freestyle-2.5.5 directory. I also specify the toolchain file using -DCMAKE_TOOLCHAIN_FILE, and specify the build directory to be . (xcode_all_natives_v2allcmake) using the -B flag. This packages the project in a single directory, the one containing the source files. After running this command, an Xcode project and the supporting structure is generated for our C/C++/Objective-C source files.
Now from the command line within the xcode_all_natives_v2allcmake folder, we can run the build commands, using the xcodebuild utility.
For a simulator:
xcodebuild -project "allnativesv2.xcodeproj" -target "ALL_BUILD" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8,OS=9.1'
For a physical connected device:
xcodebuild -project "allnativesv2.xcodeproj" -destination "platform=iOS,name=nick vancise's iPhone,OS=13.6"
Note: A device UUID may be used to specify the target device instead of using name within the destination flag, reference.
This is how Quorum Studio is generating these files under the hood, where this can also be achieved with the Cmake GUI application, in combination with opening the generated Xcode project and compiling manually.
To fill out the destination flag, you can use these utilities to find which devices are installed, and their names:
instruments -s devicesxcrun xctrace list devices
After running this command(s) and compiling the source files, the resulting static archive will be located in either the xcode_all_natives_v2allcmake/Debug-iphonesimulator or xcode_all_natives_v2allcmake/Debug-iphoneos directory depending upon which type of device it was built for.
Examination of the resulting liballnatives.a static archive with nm ./liballnatives.a | less will confirm that all necessary functions are included from our source files, where after they are linked, these functions are now accessible to our Quorum source code on device (nm Reference).
Sample screenshot after generation:
The main additions to the CMakeLists.txt consist of the addition of our required source header files, and the source files themselves as shown in Figures 1 and 2 respectively. This is where any future C/C++/Objective-C native code additions should be added.
| Figure 1 | Figure 2 |
|---|---|
![]() |
![]() |
In addition to this, several other modifications were made, such as defining the CMAKE_C_FLAGS and the CMAKE_CXX_FLAGS in the CMakeLists.txt, as this suppressed some errors in the C flags being passed to clang. In the toolchain file (.../xcode_all_natives_v2allcmake/ios_cmake/iOS.cmake) the iOS arch was also adjusted from 32 bit i-386 to 64 bit architectures using $(ARCHS_STANDARD).

