scripts: build-ninja: add support for installing libraries with cmake, compared to yanking them out of build directory

Set up hlsdk-portable to install in APK style directory (omitting game and game library directories from path).
Minor refactoring.
This commit is contained in:
Alibek Omarov
2025-08-02 10:36:42 +05:00
parent 54091b0875
commit ac162b33e9
3 changed files with 28 additions and 26 deletions

View File

@@ -30,7 +30,7 @@ android {
File(engineRoot, "scripts/configure-ninja.py").path,
engineRoot,
"--variant=\${ndk.variantName}",
"--abi=Android-\${ndk.abi}",
"--abi=\${ndk.abi}",
"--configuration-dir=\${ndk.buildRoot}",
"--ndk-version=\${ndk.moduleNdkVersion}",
"--min-sdk-version=\${ndk.minPlatform}",

View File

@@ -18,23 +18,26 @@ import subprocess
import sys
def run_cmake(path, libs, out):
cmake_exec = ["cmake", "--build", path]
def run_cmake(bin_path, libs, inst_path):
cmake_exec = ["cmake", "--build", bin_path]
cmake_process = subprocess.Popen(cmake_exec)
cmake_process.communicate()
for lib in libs:
src = os.path.join(path, *lib.split("/"))
dest = os.path.join(out, lib.split("/")[-1])
if libs:
for lib in libs:
src = os.path.join(bin_path, *lib.split("/"))
dest = os.path.join(inst_path, lib.split("/")[-1])
dest_dir = os.path.dirname(dest)
dest_dir = os.path.dirname(dest)
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
shutil.copyfile(src, dest)
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
shutil.copyfile(src, dest)
else:
cmake_exec = ["cmake", "--install", bin_path, "--prefix", inst_path]
cmake_process = subprocess.Popen(cmake_exec)
cmake_process.communicate()
def main():
parser = argparse.ArgumentParser()
@@ -57,23 +60,22 @@ def main():
waf_exec += ["--targets={}".format(args.targets)]
else:
# build SDL2 and hlsdk-portable with cmake
sdl_out_path = os.path.join(args.out_dir, "SDL")
hlsdk_out_path = os.path.join(args.out_dir, "hlsdk-portable")
sdl_bin_path = os.path.join(args.out_dir, "SDL")
hlsdk_bin_path = os.path.join(args.out_dir, "hlsdk-portable")
abi = args.waflock.replace(".lock-waf_android_", "").replace("_build", "")
dest_dir = os.path.join(args.top_dir, "android", "app", "src", "main", "jniLibs", abi)
inst_path = os.path.join(args.top_dir, "android", "app", "src", "main", "jniLibs", abi)
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
if not os.path.exists(inst_path):
os.makedirs(inst_path)
run_cmake(sdl_out_path, ["libSDL2.so"], dest_dir)
run_cmake(hlsdk_out_path, ["cl_dll/libclient.so", "dlls/libserver.so"], dest_dir)
run_cmake(sdl_bin_path, ["libSDL2.so"], inst_path)
run_cmake(hlsdk_bin_path, None, inst_path)
process = subprocess.Popen(waf_exec, env=env)
process.communicate()
sys.exit(0)
return 0
if __name__ == "__main__":
main()
sys.exit(main())

View File

@@ -54,7 +54,7 @@ def main():
args, unknown = parser.parse_known_args()
abi = args.abi[8:]
abi = args.abi
cmake_build_type = "Debug" if args.variant in ["debug", "asan"] else "Release"
cmake_toolchain_path = os.path.join(args.ndk_root, "build", "cmake", "android.toolchain.cmake")
@@ -77,7 +77,7 @@ def main():
hlsdk_out_path = os.path.join(args.configuration_dir, "hlsdk-portable")
run_cmake(hlsdk_path, hlsdk_out_path, cmake_toolchain_path, abi, cmake_build_type, args.ndk_root,
args.min_sdk_version)
args.min_sdk_version, "-DANDROID_APK=ON")
# waf configure
waf_path = os.path.join(args.wscript_path, "waf")
@@ -101,8 +101,8 @@ def main():
f.write(os.path.join(out_path, "build.ninja"))
# required for Android Studio
sys.exit(0)
return 0
if __name__ == "__main__":
main()
sys.exit(main())