diff options
| author | ruki <[email protected]> | 2023-06-06 23:35:08 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-06-06 23:35:08 +0800 |
| commit | be433ce47536db2b420d9744a19cf02d94ecb9b9 (patch) | |
| tree | e77af99182d196f59a6dc87d1f23417d19b24216 | |
| parent | 2a76eb4639af33cac5adf07be29abae34e5614bd (diff) | |
add toolchain utils
| -rw-r--r-- | xmake/modules/package/tools/cmake.lua | 13 | ||||
| -rw-r--r-- | xmake/modules/package/tools/xmake.lua | 13 | ||||
| -rw-r--r-- | xmake/modules/private/action/trybuild/cmake.lua | 14 | ||||
| -rw-r--r-- | xmake/modules/private/utils/toolchain.lua | 33 |
4 files changed, 41 insertions, 32 deletions
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 97829c36a..b3d669c51 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -28,6 +28,7 @@ import("lib.detect.find_file") import("lib.detect.find_tool") import("package.tools.ninja") import("detect.sdks.find_emsdk") +import("private.utils.toolchain", {alias = "toolchain_utils"}) -- get the number of parallel jobs function _get_parallel_njobs(opt) @@ -75,16 +76,8 @@ end -- is the toolchain compatible with the host? function _is_toolchain_compatible_with_host(package) - local toolchains = package:config("toolchains") - if toolchains then - toolchains = table.wrap(toolchains) - if is_host("linux", "macosx", "bsd") then - for _, name in ipairs(toolchains) do - if name:startswith("clang") or name:startswith("gcc") then - return true - end - end - elseif is_host("windows") and table.contains(toolchains, "msvc") then + for _, name in ipairs(package:config("toolchains")) do + if toolchain_utils.is_compatible_with_host(name) then return true end end diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index c138e770e..e253fee16 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -25,6 +25,7 @@ import("core.tool.toolchain") import("core.project.project") import("core.package.repository") import("private.action.require.impl.package", {alias = "require_package"}) +import("private.utils.toolchain", {alias = "toolchain_utils"}) -- get config from toolchains function _get_config_from_toolchains(package, name) @@ -38,16 +39,8 @@ end -- is the toolchain compatible with the host? function _is_toolchain_compatible_with_host(package) - local toolchains = package:config("toolchains") - if toolchains then - toolchains = table.wrap(toolchains) - if is_host("linux", "macosx", "bsd") then - for _, name in ipairs(toolchains) do - if name:startswith("clang") or name:startswith("gcc") then - return true - end - end - elseif is_host("windows") and table.contains(toolchains, "msvc") then + for _, name in ipairs(package:config("toolchains")) do + if toolchain_utils.is_compatible_with_host(name) then return true end end diff --git a/xmake/modules/private/action/trybuild/cmake.lua b/xmake/modules/private/action/trybuild/cmake.lua index 5e4c74799..f4b78fdf7 100644 --- a/xmake/modules/private/action/trybuild/cmake.lua +++ b/xmake/modules/private/action/trybuild/cmake.lua @@ -25,6 +25,7 @@ import("core.tool.toolchain") import("core.platform.platform") import("lib.detect.find_file") import("lib.detect.find_tool") +import("private.utils.toolchain", {alias = "toolchain_utils"}) -- get build directory function _get_buildir() @@ -100,17 +101,6 @@ function _is_cross_compilation() return false end --- is the toolchain compatible with the host? -function _is_toolchain_compatible_with_host(name) - if is_host("linux", "macosx", "bsd") then - if name:startswith("clang") or name:startswith("gcc") then - return true - end - elseif is_host("windows") and name == "msvc" then - return true - end -end - -- get configs for windows function _get_configs_for_windows(configs) table.insert(configs, "-A") @@ -403,7 +393,7 @@ function _get_configs(opt) elseif config.get("toolchain") then -- we still need find system libraries, -- it just pass toolchain environments if the toolchain is compatible with host - if _is_toolchain_compatible_with_host(config.get("toolchain")) then + if toolchain_utils.is_compatible_with_host(config.get("toolchain")) then _get_configs_for_host_toolchain(configs) else _get_configs_for_cross(configs) diff --git a/xmake/modules/private/utils/toolchain.lua b/xmake/modules/private/utils/toolchain.lua new file mode 100644 index 000000000..dd1b6df0c --- /dev/null +++ b/xmake/modules/private/utils/toolchain.lua @@ -0,0 +1,33 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file toolchain.lua +-- + +-- is the compatible with the host? +function is_compatible_with_host(name) + if is_host("linux", "macosx", "bsd") then + if name:startswith("clang") or name:startswith("gcc") or name == "llvm" then + return true + end + elseif is_host("windows") then + if name == "msvc" or name == "llvm" then + return true + end + end +end + |
