From 0651f77a3c3b4a6cb4a7011446e63ef5363f1b06 Mon Sep 17 00:00:00 2001 From: halx99 Date: Thu, 10 Nov 2022 22:53:54 +0800 Subject: [PATCH] Improve gradle scripts Add cmake options from gradle command line properties support --- core/platform/android/libaxmol/axutils.gradle | 21 ++++++++++++++----- .../proj.android/app/build.gradle | 2 ++ .../runtime-src/proj.android/app/build.gradle | 2 ++ tests/cpp-tests/proj.android/app/build.gradle | 2 ++ .../proj.android/app/build.gradle | 2 ++ .../proj.android/app/build.gradle | 2 ++ .../project/proj.android/app/build.gradle | 2 ++ 7 files changed, 28 insertions(+), 5 deletions(-) diff --git a/core/platform/android/libaxmol/axutils.gradle b/core/platform/android/libaxmol/axutils.gradle index 1bd44b8f26..aaea71b812 100644 --- a/core/platform/android/libaxmol/axutils.gradle +++ b/core/platform/android/libaxmol/axutils.gradle @@ -95,10 +95,10 @@ class axutils { // Detecting sdkRoot def sdkRoot = null - Properties projProps = new Properties() + Properties localProps = new Properties() try { - projProps.load(project.rootProject.file("local.properties").newDataInputStream()) - sdkRoot = projProps.getProperty("sdk.dir") + localProps.load(project.rootProject.file("local.properties").newDataInputStream()) + sdkRoot = localProps.getProperty("sdk.dir") } catch(Exception ex) { ex.printStackTrace() @@ -111,9 +111,10 @@ class axutils { } } - def rets = new String[3] // ndkVer,ndkPath,cmakeVer + def rets = new ArrayList(4) // ndkVer,ndkPath,cmakeVer,cmakeOptions(AX_USE_XXX, AX_ENABLE_XXX, AX_ENABLE_EXT_XXX) findNDK(sdkRoot, ndkVer, rets) findCMake(sdkRoot, cmakeVer, rets) + parseCMakeOptions(project.properties, rets) return rets } @@ -228,6 +229,16 @@ class axutils { rets[2] = foundCMakeVer } + private static void parseCMakeOptions(properties, rets) { + def options = new ArrayList() + for(item in properties) { + if (item.key.startsWith('AX_')) { + options.add("\"-D${item.key}=${item.value}\"") + } + } + rets[3] = options + } + private static int compareVersion(String ver1, String ver2) { return new VersionComparator().compare(ver1, ver2) } @@ -268,7 +279,7 @@ class axutils { private static String findCMakeFromBinDir(String cmakeVer, String cmakeBin, boolean allowNewerCMake) { def foundCMakeVer = null - + String ninjaPath = cmakeBin + File.separator + getNinjaProgramName() if(!new File(ninjaPath).isFile()) { println("The required ninja program is not present in cmake bin dir: '$cmakeBin'") diff --git a/templates/cpp-template-default/proj.android/app/build.gradle b/templates/cpp-template-default/proj.android/app/build.gradle index 15e68a492f..78139dfcd8 100644 --- a/templates/cpp-template-default/proj.android/app/build.gradle +++ b/templates/cpp-template-default/proj.android/app/build.gradle @@ -11,6 +11,7 @@ android { ndkPath = nbtInfo[1] } def cmakeVer = nbtInfo[2] + def cmakeOptions = Eval.me(nbtInfo[3]) defaultConfig { applicationId "org.axmol.hellocpp" @@ -22,6 +23,7 @@ android { externalNativeBuild { cmake { arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_shared", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE" + arguments.addAll(cmakeOptions) cppFlags "-frtti -fexceptions -fsigned-char" } } diff --git a/templates/lua-template-default/frameworks/runtime-src/proj.android/app/build.gradle b/templates/lua-template-default/frameworks/runtime-src/proj.android/app/build.gradle index 049e7e1daf..6fdacaa557 100644 --- a/templates/lua-template-default/frameworks/runtime-src/proj.android/app/build.gradle +++ b/templates/lua-template-default/frameworks/runtime-src/proj.android/app/build.gradle @@ -11,6 +11,7 @@ android { ndkPath = nbtInfo[1] } def cmakeVer = nbtInfo[2] + def cmakeOptions = Eval.me(nbtInfo[3]) defaultConfig { applicationId "org.axmol.hellolua" @@ -22,6 +23,7 @@ android { externalNativeBuild { cmake { arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_shared", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE" + arguments.addAll(cmakeOptions) cppFlags "-frtti -fexceptions -fsigned-char" } } diff --git a/tests/cpp-tests/proj.android/app/build.gradle b/tests/cpp-tests/proj.android/app/build.gradle index 919c546393..d2c5257be4 100644 --- a/tests/cpp-tests/proj.android/app/build.gradle +++ b/tests/cpp-tests/proj.android/app/build.gradle @@ -11,6 +11,7 @@ android { ndkPath = nbtInfo[1] } def cmakeVer = nbtInfo[2] + def cmakeOptions = Eval.me(nbtInfo[3]) defaultConfig { applicationId "org.axmol.cpp_tests" @@ -23,6 +24,7 @@ android { cmake { targets 'cpp_tests' arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_shared", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE" + arguments.addAll(cmakeOptions) cppFlags "-frtti -fexceptions -fsigned-char" } } diff --git a/tests/fairygui-tests/proj.android/app/build.gradle b/tests/fairygui-tests/proj.android/app/build.gradle index bb84fec662..cae17171ee 100644 --- a/tests/fairygui-tests/proj.android/app/build.gradle +++ b/tests/fairygui-tests/proj.android/app/build.gradle @@ -11,6 +11,7 @@ android { ndkPath = nbtInfo[1] } def cmakeVer = nbtInfo[2] + def cmakeOptions = Eval.me(nbtInfo[3]) defaultConfig { applicationId "org.axmol.fairygui_tests" @@ -24,6 +25,7 @@ android { targets "fairygui_tests" arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_shared", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE" + arguments.addAll(cmakeOptions) cppFlags "-frtti -fexceptions -fsigned-char" } } diff --git a/tests/live2d-tests/proj.android/app/build.gradle b/tests/live2d-tests/proj.android/app/build.gradle index d4da795168..6f655a25de 100644 --- a/tests/live2d-tests/proj.android/app/build.gradle +++ b/tests/live2d-tests/proj.android/app/build.gradle @@ -11,6 +11,7 @@ android { ndkPath = nbtInfo[1] } def cmakeVer = nbtInfo[2] + def cmakeOptions = Eval.me(nbtInfo[3]) defaultConfig { applicationId "org.axmol.live2d_tests" @@ -22,6 +23,7 @@ android { externalNativeBuild { cmake { arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_shared", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", "-DAX_ENABLE_EXT_LIVE2D=TRUE" + arguments.addAll(cmakeOptions) cppFlags "-frtti -fexceptions -fsigned-char" } } diff --git a/tests/lua-tests/project/proj.android/app/build.gradle b/tests/lua-tests/project/proj.android/app/build.gradle index d14f390a3d..d0f29eedf5 100644 --- a/tests/lua-tests/project/proj.android/app/build.gradle +++ b/tests/lua-tests/project/proj.android/app/build.gradle @@ -11,6 +11,7 @@ android { ndkPath = nbtInfo[1] } def cmakeVer = nbtInfo[2] + def cmakeOptions = Eval.me(nbtInfo[3]) defaultConfig { applicationId "org.axmol.lua_tests" @@ -23,6 +24,7 @@ android { cmake { targets 'lua_tests' arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_shared", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE" + arguments.addAll(cmakeOptions) cppFlags "-frtti -fexceptions -fsigned-char" } }