diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2023-05-25 02:33:18 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2023-05-25 06:07:03 +0200 |
commit | 45549e020fd99195b9db3222a1733e21af2032d5 (patch) | |
tree | b428a52bd3133dcca9f8c97830a374aa28d23dcc /tools/cmake.py | |
parent | ee40730c205c2eff6c4078ed6229ccbe1c6c02d2 (diff) | |
download | fork-godot-webrtc-native-45549e020fd99195b9db3222a1733e21af2032d5.tar.gz fork-godot-webrtc-native-45549e020fd99195b9db3222a1733e21af2032d5.tar.bz2 fork-godot-webrtc-native-45549e020fd99195b9db3222a1733e21af2032d5.zip |
[SCons] Move platform configuration to cmake tool.
Diffstat (limited to 'tools/cmake.py')
-rw-r--r-- | tools/cmake.py | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/tools/cmake.py b/tools/cmake.py index 2362312..d552da6 100644 --- a/tools/cmake.py +++ b/tools/cmake.py @@ -1,3 +1,6 @@ +import os + + def exists(env): return True @@ -5,6 +8,7 @@ def exists(env): def generate(env): env.AddMethod(cmake_configure, "CMakeConfigure") env.AddMethod(cmake_build, "CMakeBuild") + env.AddMethod(cmake_platform_flags, "CMakePlatformFlags") def cmake_configure(env, source, target, opt_args): @@ -22,5 +26,58 @@ def cmake_configure(env, source, target, opt_args): def cmake_build(env, source, target=""): jobs = env.GetOption("num_jobs") - env = env.Clone() return env.Execute("cmake --build %s %s -j%s" % (source, "-t %s" % target if target else "", jobs)) + + +def cmake_platform_flags(env, config=None): + if config is None: + config = {} + + if "CC" in env: + config["CMAKE_C_COMPILER"] = env["CC"] + if "CXX" in env: + config["CMAKE_CXX_COMPILER"] = env["CXX"] + + if env["platform"] == "android": + api = env["android_api_level"] + abi = { + "arm64": "arm64-v8a", + "arm32": "armeabi-v7a", + "x86_32": "x86", + "x86_64": "x86_64", + }[env["arch"]] + config["CMAKE_SYSTEM_NAME"] = "Android" + config["CMAKE_SYSTEM_VERSION"] = api + config["CMAKE_ANDROID_ARCH_ABI"] = abi + config["ANDROID_ABI"] = abi + config["CMAKE_TOOLCHAIN_FILE"] = "%s/build/cmake/android.toolchain.cmake" % os.environ.get( + "ANDROID_NDK_ROOT", "" + ) + config["CMAKE_ANDROID_STL_TYPE"] = "c++_static" + + elif env["platform"] == "linux": + march = "-m32" if env["arch"] == "x86_32" else "-m64" + config["CMAKE_C_FLAGS"] = march + config["CMAKE_CXX_FLAGS"] = march + + elif env["platform"] == "macos": + if env["arch"] == "universal": + raise ValueError("OSX architecture not supported: %s" % env["arch"]) + config["CMAKE_OSX_ARCHITECTURES"] = env["arch"] + if env["macos_deployment_target"] != "default": + config["CMAKE_OSX_DEPLOYMENT_TARGET"] = env["macos_deployment_target"] + + elif env["platform"] == "ios": + if env["arch"] == "universal": + raise ValueError("iOS architecture not supported: %s" % env["arch"]) + config["CMAKE_SYSTEM_NAME"] = "iOS" + config["CMAKE_OSX_ARCHITECTURES"] = env["arch"] + if env["ios_min_version"] != "default": + config["CMAKE_OSX_DEPLOYMENT_TARGET"] = env["ios_min_version"] + if env["ios_simulator"]: + config["CMAKE_OSX_SYSROOT"] = "iphonesimulator" + + elif env["platform"] == "windows": + config["CMAKE_SYSTEM_NAME"] = "Windows" + + return config |