diff options
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | xmake/modules/package/tools/cmake.lua | 15 | ||||
| -rw-r--r-- | xmake/modules/private/action/trybuild/cmake.lua | 21 |
3 files changed, 35 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index acc5a162f..9b4cb7e10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ * [#931](https://github.com/xmake-io/xmake/issues/931): Support to export packages with all dependences * [#930](https://github.com/xmake-io/xmake/issues/930): Support to download package without version list directly * [#927](https://github.com/xmake-io/xmake/issues/927): Support to switch arm/thumb mode for android ndk +* Improve trybuild/cmake to support android toolchain ### Bugs fixed @@ -829,6 +830,7 @@ * [#931](https://github.com/xmake-io/xmake/issues/931): 改进导出包,支持导出所有依赖包 * [#930](https://github.com/xmake-io/xmake/issues/930): 如果私有包定义没有版本定义,支持直接尝试下载包 * [#927](https://github.com/xmake-io/xmake/issues/927): 改进android ndk,支持arm/thumb指令模式切换 +* 改进 trybuild/cmake 支持 Android 工具链 ### Bugs修复 diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index f980ae4f6..0a73b09ee 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -35,6 +35,21 @@ function _get_configs(package, configs) table.insert(configs, '-DCMAKE_C_FLAGS_DEBUG="/' .. vs_runtime .. 'd"') table.insert(configs, '-DCMAKE_C_FLAGS_RELEASE="/' .. vs_runtime .. '"') end + elseif package:is_plat("android") then + -- https://developer.android.google.cn/ndk/guides/cmake + local ndk = get_config("ndk") + if ndk and os.isdir(ndk) then + local ndk_sdkver = get_config("ndk_sdkver") + local ndk_cxxstl = get_config("ndk_cxxstl") + table.insert(configs, "-DCMAKE_TOOLCHAIN_FILE=" .. path.join(ndk, "build/cmake/android.toolchain.cmake")) + table.insert(configs, "-DANDROID_ABI=" .. package:arch()) + if ndk_sdkver then + table.insert(configs, "-DANDROID_NATIVE_API_LEVEL=" .. ndk_sdkver) + end + if ndk_cxxstl then + table.insert(configs, "-DANDROID_STL=" .. ndk_cxxstl) + end + end end local cflags = package:config("cflags") if cflags then diff --git a/xmake/modules/private/action/trybuild/cmake.lua b/xmake/modules/private/action/trybuild/cmake.lua index 684941c39..5ec6a6506 100644 --- a/xmake/modules/private/action/trybuild/cmake.lua +++ b/xmake/modules/private/action/trybuild/cmake.lua @@ -44,6 +44,24 @@ function _get_configs(artifacts_dir) if is_plat("windows") and is_arch("x64") then table.insert(configs, "-A") table.insert(configs, "x64") + elseif is_plat("android") then + -- https://developer.android.google.cn/ndk/guides/cmake + local ndk = config.get("ndk") + if ndk and os.isdir(ndk) then + local arch = config.arch() + local ndk_sdkver = config.get("ndk_sdkver") + local ndk_cxxstl = config.get("ndk_cxxstl") + table.insert(configs, "-DCMAKE_TOOLCHAIN_FILE=" .. path.join(ndk, "build/cmake/android.toolchain.cmake")) + if arch then + table.insert(configs, "-DANDROID_ABI=" .. arch) + end + if ndk_sdkver then + table.insert(configs, "-DANDROID_NATIVE_API_LEVEL=" .. ndk_sdkver) + end + if ndk_cxxstl then + table.insert(configs, "-DANDROID_STL=" .. ndk_cxxstl) + end + end end -- enable verbose? @@ -91,9 +109,6 @@ end -- do build function build() - -- only support the current subsystem host platform now! - assert(is_subhost(config.plat()), "cmake: %s not supported!", config.plat()) - -- get artifacts directory local artifacts_dir = _get_artifacts_dir() if not os.isdir(artifacts_dir) then |
