diff options
| author | ruki <[email protected]> | 2025-06-18 00:51:12 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-06-18 00:51:12 +0800 |
| commit | 0d9bbf140f453a6736620cf90a77fad7d175b6ef (patch) | |
| tree | 61821fbc9ac43dc607702640f46165dab206e324 | |
| parent | bcc6904da2585b98cda0f20befba5fa7afba6b16 (diff) | |
improve conan configurations
3 files changed, 53 insertions, 77 deletions
diff --git a/xmake/modules/package/manager/conan/configurations.lua b/xmake/modules/package/manager/conan/configurations.lua index 01cc8b34c..af045c1e1 100644 --- a/xmake/modules/package/manager/conan/configurations.lua +++ b/xmake/modules/package/manager/conan/configurations.lua @@ -18,6 +18,47 @@ -- @file configurations.lua -- +-- get arch for conan +function arch(arch) + local map = {x86_64 = "x86_64", + x64 = "x86_64", + i386 = "x86", + x86 = "x86", + armv7 = "armv7", + ["armv7-a"] = "armv7", -- for android, deprecated + ["armeabi"] = "armv7", -- for android, removed in ndk r17 + ["armeabi-v7a"] = "armv7", -- for android + armv7s = "armv7s", -- for iphoneos + arm64 = "armv8", -- for iphoneos + ["arm64-v8a"] = "armv8", -- for android + mips = "mips", + mips64 = "mips64", + wasm32 = "wasm"} + return assert(map[arch], "unknown arch(%s)!", arch) +end + +-- get os platform for conan +function plat(plat) + local map = {macosx = "Macos", + windows = "Windows", + mingw = "Windows", + linux = "Linux", + cross = "Linux", + iphoneos = "iOS", + android = "Android", + wasm = "Emscripten"} + return assert(map[plat], "unknown os(%s)!", plat) +end + +-- get build type +function build_type(mode) + if mode == "debug" then + return "Debug" + else + return "Release" + end +end + -- get configurations function main() return diff --git a/xmake/modules/package/manager/conan/find_package.lua b/xmake/modules/package/manager/conan/find_package.lua index 5d8d8c353..12f8973de 100644 --- a/xmake/modules/package/manager/conan/find_package.lua +++ b/xmake/modules/package/manager/conan/find_package.lua @@ -21,6 +21,7 @@ -- imports import("core.base.option") import("core.project.config") +import("package.manager.conan.configurations") -- get build info file function _conan_get_buildinfo_file(name, dep_name) @@ -31,40 +32,12 @@ function _conan_get_buildinfo_file(name, dep_name) return path.absolute(path.join(config.builddir() or os.tmpdir(), ".conan", name, filename)) end --- get conan platform -function _conan_get_plat(opt) - local plats = {macosx = "Macos", windows = "Windows", mingw = "Windows", linux = "Linux", cross = "Linux", iphoneos = "iOS", android = "Android"} - return plats[opt.plat] -end - --- get conan architecture -function _conan_get_arch(opt) - local archs = {x86_64 = "x86_64", - x64 = "x86_64", - i386 = "x86", - x86 = "x86", - armv7 = "armv7", - ["armv7-a"] = "armv7", -- for android, deprecated - ["armeabi"] = "armv7", -- for android, removed in ndk r17 - ["armeabi-v7a"] = "armv7", -- for android - armv7s = "armv7s", -- for iphoneos - arm64 = "armv8", -- for iphoneos - ["arm64-v8a"] = "armv8", -- for android - mips = "mips", - mips64 = "mips64"} - return archs[opt.arch] -end - --- get conan mode -function _conan_get_mode(opt) - return opt.mode == "debug" and "Debug" or "Release" -end - -- get info key function _conan_get_infokey(opt) - local plat = _conan_get_plat(opt) - local arch = _conan_get_arch(opt) - local mode = _conan_get_mode(opt) + opt = opt or {} + local plat = configurations.plat(opt.plat) + local arch = configurations.arch(opt.arch) + local mode = configurations.build_type(opt.mode) if plat and arch and mode then return plat .. "_" .. arch .. "_" .. mode end diff --git a/xmake/modules/package/manager/conan/v2/install_package.lua b/xmake/modules/package/manager/conan/v2/install_package.lua index f93ebaea7..3c4c07da7 100644 --- a/xmake/modules/package/manager/conan/v2/install_package.lua +++ b/xmake/modules/package/manager/conan/v2/install_package.lua @@ -27,6 +27,7 @@ import("core.platform.platform") import("lib.detect.find_tool") import("devel.git") import("net.fasturl") +import("package.manager.conan.configurations") -- get build env function _conan_get_build_env(name, plat) @@ -110,45 +111,6 @@ function _conan_install_xmake_generator(conan) end end --- get arch -function _conan_get_arch(arch) - local map = {x86_64 = "x86_64", - x64 = "x86_64", - i386 = "x86", - x86 = "x86", - armv7 = "armv7", - ["armv7-a"] = "armv7", -- for android, deprecated - ["armeabi"] = "armv7", -- for android, removed in ndk r17 - ["armeabi-v7a"] = "armv7", -- for android - armv7s = "armv7s", -- for iphoneos - arm64 = "armv8", -- for iphoneos - ["arm64-v8a"] = "armv8", -- for android - mips = "mips", - mips64 = "mips64"} - return assert(map[arch], "unknown arch(%s)!", arch) -end - --- get os -function _conan_get_os(plat) - local map = {macosx = "Macos", - windows = "Windows", - mingw = "Windows", - linux = "Linux", - cross = "Linux", - iphoneos = "iOS", - android = "Android"} - return assert(map[plat], "unknown os(%s)!", plat) -end - --- get build type -function _conan_get_build_type(mode) - if mode == "debug" then - return "Debug" - else - return "Release" - end -end - -- get compiler version -- -- https://github.com/conan-io/conan/blob/353c63b16c31c90d370305b5cbb5dc175cf8a443/conan/tools/microsoft/visual.py#L13 @@ -261,9 +223,9 @@ end function _conan_generate_build_profile(configs, opt) local profile = io.open("profile_build.txt", "w") profile:print("[settings]") - profile:print("arch=%s", _conan_get_arch(os.arch())) - profile:print("build_type=%s", _conan_get_build_type(opt.mode)) - profile:print("os=%s", _conan_get_os(os.host())) + profile:print("arch=%s", configurations.arch(os.arch())) + profile:print("build_type=%s", configurations.build_type(opt.mode)) + profile:print("os=%s", configurations.plat(os.host())) _conan_generate_compiler_profile(profile, configs, {plat = os.host(), arch = os.arch()}) profile:close() end @@ -272,9 +234,9 @@ end function _conan_generate_host_profile(configs, opt) local profile = io.open("profile_host.txt", "w") profile:print("[settings]") - profile:print("arch=%s", _conan_get_arch(opt.arch)) - profile:print("build_type=%s", _conan_get_build_type(opt.mode)) - profile:print("os=%s", _conan_get_os(opt.plat)) + profile:print("arch=%s", configurations.arch(opt.arch)) + profile:print("build_type=%s", configurations.build_type(opt.mode)) + profile:print("os=%s", configurations.plat(opt.plat)) _conan_generate_compiler_profile(profile, configs, opt) profile:close() end |
