Skip to content

Get CMake to support Android and iOS platforms - #312

Closed
LeventSevgili wants to merge 1 commit into
ValveSoftware:masterfrom
LeventSevgili:Android-iOS-CMake
Closed

LeventSevgili wants to merge 1 commit into
ValveSoftware:masterfrom
LeventSevgili:Android-iOS-CMake

Conversation

@LeventSevgili

Copy link
Copy Markdown
Contributor

I always wanted to get CMake to support Android and iOS platforms. I had a little time window and managed to work it and I am happy to share. I will be super glad if it helps to someone!

It may have points to discuss. I'm glad to iterate. I had comments on files. Thanks!

Also edit some files to success the build.
@ANURAGX

ANURAGX commented Jan 3, 2025

Copy link
Copy Markdown

When this will be merged?

@corentin35000

corentin35000 commented Jul 23, 2025 •

Copy link
Copy Markdown

Just a note for the iOS package distribution, I see in the README, a dynamic library (.dylib) this has not been allowed for a long time on Apple stores, it is mandatory to have a static library: .a or .xcframework! I will soon post a github URL of one of my repositories, for :

  • iOS/iPadOS (arm64)
  • Android (arm64-v8a / armeabi-v7a)
  • Linux (x64/arm64)
  • Windows (x64/arm64)
  • macOS (x64 /arm64)
  • Steam Linux (x64 /arm64) via the Steam Linux Runtime 3.0 Sniper SDK
  • Steam Deck (x64) via the Steam Runtime 3.0 Sniper SDK

Which will contain all the pre-compiled libraries in static form that you can retrieve via the artifacts of the Github Actions CI: protobuf + OpenSSL + GameNetworkingSockets, with obviously the latest version latest release of the libraries! I automated it from a CI so I would just have to change the tag / commitsha of protobuf (+absail) / openssl / GameNetworkingSockets, when I have the devkit for consoles I will also make the request to extend on consoles!

@jzavala-YYG

jzavala-YYG commented Jan 8, 2026 •

Copy link
Copy Markdown

If someone need build for Android with a newer NDK. this worked for me using NDK 26.1.10909125

build_android_game_networking_sockets.md

zpostfacto pushed a commit that referenced this pull request Oct 2, 2026
Taken from PR #312.

The NDK toolchain sets CMAKE_SYSTEM_NAME to Android, which previously hit
the "Could not identify your target operating system" error in both
CMakeLists files.

Plat_IsInDebugSession now has an Android case.

This does not make Android build on its own. Still needed: link liblog,
and cast bionic's INADDR_LOOPBACK and INADDR_BROADCAST (unsigned long on
LP64) to uint32 in netadr.cpp.
zpostfacto added a commit that referenced this pull request Oct 2, 2026
On Android, bionic takes these straight from the kernel headers, where
they are unsigned long. On LP64 that is 64 bits, which trips the
compile-time size assert in BigDWord. glibc redefines them as in_addr_t,
so Linux never saw it. No change on any other platform.

Noted in PR #312.
zpostfacto added a commit that referenced this pull request Oct 2, 2026
Static protobuf references __android_log_write, so the client library
must link liblog on Android.

Noted in PR #312.
@zpostfacto

Copy link
Copy Markdown
Contributor

Hi @LeventSevgili,

First, an apology: this PR has been open since early 2024 and it's nearly
2027. That's far too long to leave a contribution without a real answer, and
I'm sorry about that. You put genuine work into this and deserved a response
long ago.

I've now taken the parts of this I could, and I want to explain what I did
and didn't take.

Merged, with you as author (baca770): the Android branches in both
CMakeLists files so the NDK toolchain is recognized, and the Android case in
Plat_IsInDebugSession. Those hunks went in as you wrote them.

Merged as follow-up commits, credited to this PR (2e5eb56, 7386ffc): linking
liblog, and the DWordSwapC assert you ran into. For the latter I kept the
assert and fixed the call sites instead. The root cause is that bionic's
INADDR_LOOPBACK and INADDR_BROADCAST are unsigned long, so they're 64 bits
on arm64. Casting them to uint32 at the two uses in netadr.cpp fixes the
assert without disabling it. Thank you for finding both of these.

Not taken: the iOS side has since been covered by a separate effort (#428)
that landed iOS, tvOS and visionOS support with xcframework packaging, so
that half is superseded. On the Android side, the system for fetching and
building protobuf and OpenSSL at configure time is something I don't want in
this project's CMake files. Dependency management belongs to vcpkg (which has
Android triplets) or the consumer's own toolchain, and pinning NDK and
OpenSSL versions and driving those builds from inside configure is more than
I can maintain, especially since I have no way to test Android builds myself.
I also left out the EVP_MD_CTX_free check bypass, since that check passes
when OpenSSL is located correctly and skipping it would hide a real
misconfiguration.

With the merged pieces, master should now configure and compile for Android
against a user-supplied protobuf and OpenSSL. I haven't been able to verify
that here. If anyone wants to finish the job, the welcome shape is a short
Android section in BUILDING.md pointing at the vcpkg triplet and NDK
toolchain file, and a GitHub Actions job so it stays tested.

Thanks again for taking the time to put this together and share it, and
again, I'm sorry it took this long.

@zpostfacto zpostfacto closed this Oct 2, 2026
zpostfacto pushed a commit that referenced this pull request Oct 3, 2026
Taken from PR #312.

The NDK toolchain sets CMAKE_SYSTEM_NAME to Android, which previously hit
the "Could not identify your target operating system" error in both
CMakeLists files.

Plat_IsInDebugSession now has an Android case.

This does not make Android build on its own. Still needed: link liblog,
and cast bionic's INADDR_LOOPBACK and INADDR_BROADCAST (unsigned long on
LP64) to uint32 in netadr.cpp.

(cherry picked from commit baca770)
zpostfacto added a commit that referenced this pull request Oct 3, 2026
On Android, bionic takes these straight from the kernel headers, where
they are unsigned long. On LP64 that is 64 bits, which trips the
compile-time size assert in BigDWord. glibc redefines them as in_addr_t,
so Linux never saw it. No change on any other platform.

Noted in PR #312.

(cherry picked from commit 2e5eb56)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants