From c6c71612e034c2e741add2b9deb69be4c93a8388 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 16 May 2020 00:03:19 +0800 Subject: add xcode toolchain --- xmake/toolchains/xcode/xmake.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 xmake/toolchains/xcode/xmake.lua (limited to 'xmake/toolchains/xcode') diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua new file mode 100644 index 000000000..633f5a45d --- /dev/null +++ b/xmake/toolchains/xcode/xmake.lua @@ -0,0 +1,23 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("xcode") + -- cgit v1.3.1 From ed247a74689d45a4cf9a8a8e4aee64dba741df43 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 16 May 2020 21:28:07 +0800 Subject: check tool for toolchain --- xmake/core/platform/platform.lua | 1 - xmake/core/tool/toolchain.lua | 99 ++++++++++++++++++++++++++++++++++++++-- xmake/toolchains/xcode/xmake.lua | 16 +++++++ 3 files changed, 110 insertions(+), 6 deletions(-) (limited to 'xmake/toolchains/xcode') diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 9a3aff93a..51cbcf33f 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -32,7 +32,6 @@ local toolchain = require("tool/toolchain") local sandbox = require("sandbox/sandbox") local config = require("project/config") local global = require("base/global") -local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance function _instance.new(name, info, rootdir) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 6cfaf5802..6ebae5152 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -28,10 +28,12 @@ local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local global = require("base/global") +local option = require("base/option") local interpreter = require("base/interpreter") local config = require("project/config") local language = require("language/language") local sandbox = require("sandbox/sandbox") +local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance function _instance.new(name, info, rootdir) @@ -84,6 +86,15 @@ end -- get the program and name of the given tool kind function _instance:tool(toolkind) + local toolpathes = self:get("toolsets." .. toolkind) + if toolpathes then + for _, toolpath in ipairs(toolpathes) do + local program, toolname = self:_checktool(toolkind, toolpath) + if program then + return program, toolname + end + end + end end -- get the toolchain script @@ -91,6 +102,83 @@ function _instance:script(name) return self._INFO:get(name) end +-- get the bin directory +function _instance:bindir() + return config.get("bin") or self:get("bindir") +end + +-- get the tool description from the tool kind +function _instance:_description(toolkind) + local descriptions = self._DESCRIPTIONS + if not descriptions then + descriptions = + { + cc = "the c compiler", + cxx = "the c++ compiler", + ld = "the linker", + sh = "the shared library linker", + ar = "the static library archiver", + ex = "the static library extractor", + strip = "the symbols stripper", + dsymutil = "the symbols generator", + mm = "the objc compiler", + mxx = "the objc++ compiler", + as = "the assember", + sc = "the swift compiler", + scld = "the swift linker", + scsh = "the swift shared library linker", + gc = "the golang compiler", + gcld = "the golang linker", + gcar = "the golang static library archiver", + dc = "the dlang compiler", + dcld = "the dlang linker", + dcsh = "the dlang shared library linker", + dcar = "the dlang static library archiver", + rc = "the rust compiler", + rcld = "the rust linker", + rcsh = "the rust shared library linker", + rcar = "the rust static library archiver", + cu = "the cuda compiler", + culd = "the cuda linker", + cuccbin = "the cuda host c++ compiler", + } + self._DESCRIPTIONS = descriptions + end + return descriptions +end + +-- check the given tool path +function _instance:_checktool(toolkind, toolpath) + + -- get find_tool + local find_tool = self._find_tool + if not find_tool then + find_tool = sandbox_module.import("lib.detect.find_tool", {anonymous = true}) + self._find_tool = find_tool + end + + -- find tool program + local program, toolname + local tool = find_tool(toolpath, {program = toolpath, pathes = self:bindir()}) + if tool then + program = tool.program + toolname = tool.name + end + + -- get tool description from the tool kind + local description = self:_description(toolkind) or ("unknown toolkind " .. toolkind) + + -- trace + if option.get("verbose") then + if program then + utils.cprint("${dim}checking for %s (%s) ... ${color.success}%s", description, toolkind, path.filename(program)) + else + utils.cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, name) + end + end + return program, toolname +end + -- is builtin configuration? function _instance:_is_builtin_conf(name) @@ -137,13 +225,14 @@ end function toolchain._apis() return { - values = + values = + { + "toolchain.set_bindir" + } + , keyvalues = { -- toolchain.set_xxx - "toolchain.set_cc" - , "toolchain.set_cxx" - , "toolchain.set_ld" - , "toolchain.set_sh" + "toolchain.set_toolsets" } , script = { diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index 633f5a45d..1c39a6453 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -21,3 +21,19 @@ -- define toolchain toolchain("xcode") + -- set toolsets + set_toolsets("cc", "xcrun -sdk macosx clang") + set_toolsets("cxx", "xcrun -sdk macosx clang", "xcrun -sdk macosx clang++") + set_toolsets("as", "xcrun -sdk macosx clang") + set_toolsets("ld", "xcrun -sdk macosx clang++", "xcrun -sdk macosx clang") + set_toolsets("sh", "xcrun -sdk macosx clang++", "xcrun -sdk macosx clang") + set_toolsets("ar", "xcrun -sdk macosx ar") + set_toolsets("ex", "xcrun -sdk macosx ar") + set_toolsets("strip", "xcrun -sdk macosx strip") + set_toolsets("dsymutil", "xcrun -sdk macosx dsymutil", "dsymutil") + set_toolsets("mm", "xcrun -sdk macosx clang") + set_toolsets("mxx", "xcrun -sdk macosx clang", "xcrun -sdk macosx clang++") + set_toolsets("sc", "xcrun -sdk macosx swiftc", "swiftc") + set_toolsets("scld", "xcrun -sdk macosx swiftc", "swiftc") + set_toolsets("scsh", "xcrun -sdk macosx swiftc", "swiftc") + -- cgit v1.3.1 From c0afaacde90abf081bab19279c3ea6d4dbeae86d Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 17 May 2020 21:57:39 +0800 Subject: add toolchain check --- xmake/core/tool/toolchain.lua | 57 +++++++++++++++--------- xmake/platforms/macosx/config.lua | 3 +- xmake/platforms/macosx/xmake.lua | 2 +- xmake/toolchains/xcode/check.lua | 28 ++++++++++++ xmake/toolchains/xcode/load.lua | 94 +++++++++++++++++++++++++++++++++++++++ xmake/toolchains/xcode/xmake.lua | 5 +++ 6 files changed, 167 insertions(+), 22 deletions(-) create mode 100644 xmake/toolchains/xcode/check.lua create mode 100644 xmake/toolchains/xcode/load.lua (limited to 'xmake/toolchains/xcode') diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 8a62afd8d..246d46a99 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -61,26 +61,6 @@ end -- get the toolchain configuration function _instance:get(name) - - -- attempt to get the static configure value - local value = self._INFO:get(name) - if value ~= nil then - return value - end - - -- lazy loading toolchain if get other configuration - if not self._LOADED and not self:_is_builtin_conf(name) then - local on_load = self._INFO:get("load") - if on_load then - local ok, errors = sandbox.load(on_load, self) - if not ok then - os.raise(errors) - end - end - self._LOADED = true - end - - -- get other toolchain info return self._INFO:get(name) end @@ -107,6 +87,34 @@ function _instance:bindir() return config.get("bin") or self:get("bindir") end +-- do load +function _instance:_load() + if not self._LOADED then + local on_load = self._INFO:get("load") + if on_load then + local ok, errors = sandbox.load(on_load, self) + if not ok then + os.raise(errors) + end + end + self._LOADED = true + end +end + +-- do check +function _instance:_check() + if not self._CHECKED then + local on_check = self._INFO:get("check") + if on_check then + local ok, errors = sandbox.load(on_check, self) + if not ok then + os.raise(errors) + end + end + self._CHECKED = true + end +end + -- get the tool description from the tool kind function _instance:_description(toolkind) local descriptions = self._DESCRIPTIONS @@ -150,6 +158,9 @@ end -- check the given tool path function _instance:_checktool(toolkind, toolpath) + -- ensure to check this toolchain first + self:_check() + -- get find_tool local find_tool = self._find_tool if not find_tool then @@ -176,6 +187,11 @@ function _instance:_checktool(toolkind, toolpath) utils.cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, name) end end + + -- we only load it when checking the given tool successfully + if program then + self:_load() + end return program, toolname end @@ -238,6 +254,7 @@ function toolchain._apis() { -- toolchain.on_xxx "toolchain.on_load" + , "toolchain.on_check" } , dictionary = { diff --git a/xmake/platforms/macosx/config.lua b/xmake/platforms/macosx/config.lua index a5c0893fc..a1713a657 100644 --- a/xmake/platforms/macosx/config.lua +++ b/xmake/platforms/macosx/config.lua @@ -146,6 +146,7 @@ end -- check it function main(platform, name) + --[[ -- only check the given config name? if name then local toolchain = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] @@ -159,6 +160,6 @@ function main(platform, name) -- check xcode check_xcode(config, true) - end + end]] end diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index b7abea032..fc390d953 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -37,7 +37,7 @@ platform("macosx") set_installdir("/usr/local") -- on check project configuration - on_config_check("config") +-- on_config_check("config") -- on check global configuration on_global_check("global") diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua new file mode 100644 index 000000000..c10fe48d9 --- /dev/null +++ b/xmake/toolchains/xcode/check.lua @@ -0,0 +1,28 @@ +--!A cross-toolchain 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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("private.platform.check_xcode") + +-- main entry +function main(toolchain) + check_xcode(config, true) +end diff --git a/xmake/toolchains/xcode/load.lua b/xmake/toolchains/xcode/load.lua new file mode 100644 index 000000000..96d459414 --- /dev/null +++ b/xmake/toolchains/xcode/load.lua @@ -0,0 +1,94 @@ +--!A cross-toolchain 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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init flags for architecture + local arch = config.get("arch") or os.arch() + local target_minver = config.get("target_minver") + + -- init flags for the xcode sdk directory + local xcode_dir = config.get("xcode") + local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkdir = nil + if xcode_dir and xcode_sdkver then + xcode_sdkdir = xcode_dir .. "/Contents/Developer/toolchains/MacOSX.toolchain/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" + end + + -- init flags for c/c++ + toolchain:add("cxflags", "-arch " .. arch) + toolchain:add("ldflags", "-arch " .. arch) + if target_minver then + toolchain:add("cxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("mxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("ldflags", "-mmacosx-version-min=" .. target_minver) + end + if xcode_sdkdir then + toolchain:add("cxflags", "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-isysroot " .. xcode_sdkdir) + else + toolchain:add("cxflags", "-I/usr/local/include") + toolchain:add("cxflags", "-I/usr/include") + toolchain:add("ldflags", "-L/usr/local/lib") + toolchain:add("ldflags", "-L/usr/lib") + end + toolchain:add("ldflags", "-stdlib=libc++") + toolchain:add("ldflags", "-lz") + toolchain:add("shflags", toolchain:get("ldflags")) + + -- init flags for objc/c++ (with ldflags and shflags) + toolchain:add("mxflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("mxflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for asm +-- toolchain:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") +-- toolchain:set("fasm.asflags", "") + toolchain:add("asflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("asflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for swift + if target_minver and xcode_sdkdir then + toolchain:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + end + + --[[ + -- init flags for golang + toolchain:set("gcldflags", "") + + -- init flags for dlang + local dc_archs = { i386 = "-m32", x86_64 = "-m64" } + toolchain:add("dcflags", dc_archs[arch] or "") + toolchain:add("dcshflags", dc_archs[arch] or "") + toolchain:add("dcldflags", dc_archs[arch] or "" ) + + -- init flags for rust + toolchain:set("rcshflags", "") + toolchain:set("rcldflags", "")]] +end diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index 1c39a6453..d9b1d9944 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -37,3 +37,8 @@ toolchain("xcode") set_toolsets("scld", "xcrun -sdk macosx swiftc", "swiftc") set_toolsets("scsh", "xcrun -sdk macosx swiftc", "swiftc") + -- check toolchain + on_check("check") + + -- load toolchain + on_load("load") -- cgit v1.3.1 From 937bd96c26edc111a3226a4feb2a6748041ab461 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:39:36 +0800 Subject: check toolchains for macosx --- xmake/actions/global/main.lua | 5 - xmake/core/platform/platform.lua | 22 +-- .../sandbox/modules/import/core/base/global.lua | 25 --- .../sandbox/modules/import/core/project/config.lua | 7 +- xmake/core/tool/toolchain.lua | 33 ++-- xmake/platforms/android/check.lua | 155 +++++++++++++++++ xmake/platforms/android/config.lua | 155 ----------------- xmake/platforms/android/xmake.lua | 4 +- xmake/platforms/bsd/check.lua | 175 +++++++++++++++++++ xmake/platforms/bsd/config.lua | 175 ------------------- xmake/platforms/bsd/global.lua | 32 ---- xmake/platforms/bsd/xmake.lua | 7 +- xmake/platforms/cross/check.lua | 189 +++++++++++++++++++++ xmake/platforms/cross/config.lua | 189 --------------------- xmake/platforms/cross/xmake.lua | 4 +- xmake/platforms/cygwin/check.lua | 172 +++++++++++++++++++ xmake/platforms/cygwin/config.lua | 172 ------------------- xmake/platforms/cygwin/xmake.lua | 4 +- xmake/platforms/iphoneos/check.lua | 128 ++++++++++++++ xmake/platforms/iphoneos/config.lua | 128 -------------- xmake/platforms/iphoneos/global.lua | 36 ---- xmake/platforms/iphoneos/xmake.lua | 7 +- xmake/platforms/linux/check.lua | 175 +++++++++++++++++++ xmake/platforms/linux/config.lua | 175 ------------------- xmake/platforms/linux/global.lua | 32 ---- xmake/platforms/linux/xmake.lua | 7 +- xmake/platforms/macosx/check.lua | 175 +++++++++++++++++++ xmake/platforms/macosx/config.lua | 165 ------------------ xmake/platforms/macosx/global.lua | 36 ---- xmake/platforms/macosx/xmake.lua | 7 +- xmake/platforms/mingw/check.lua | 128 ++++++++++++++ xmake/platforms/mingw/config.lua | 128 -------------- xmake/platforms/mingw/xmake.lua | 4 +- xmake/platforms/msys/check.lua | 172 +++++++++++++++++++ xmake/platforms/msys/config.lua | 172 ------------------- xmake/platforms/msys/xmake.lua | 4 +- xmake/platforms/sdcc/check.lua | 114 +++++++++++++ xmake/platforms/sdcc/config.lua | 114 ------------- xmake/platforms/sdcc/xmake.lua | 4 +- xmake/platforms/watchos/check.lua | 124 ++++++++++++++ xmake/platforms/watchos/config.lua | 124 -------------- xmake/platforms/watchos/global.lua | 36 ---- xmake/platforms/watchos/xmake.lua | 7 +- xmake/platforms/windows/check.lua | 139 +++++++++++++++ xmake/platforms/windows/config.lua | 139 --------------- xmake/platforms/windows/global.lua | 49 ------ xmake/platforms/windows/xmake.lua | 7 +- xmake/toolchains/xcode/check.lua | 1 + 48 files changed, 1902 insertions(+), 2160 deletions(-) create mode 100644 xmake/platforms/android/check.lua delete mode 100644 xmake/platforms/android/config.lua create mode 100644 xmake/platforms/bsd/check.lua delete mode 100644 xmake/platforms/bsd/config.lua delete mode 100644 xmake/platforms/bsd/global.lua create mode 100644 xmake/platforms/cross/check.lua delete mode 100644 xmake/platforms/cross/config.lua create mode 100644 xmake/platforms/cygwin/check.lua delete mode 100644 xmake/platforms/cygwin/config.lua create mode 100644 xmake/platforms/iphoneos/check.lua delete mode 100644 xmake/platforms/iphoneos/config.lua delete mode 100644 xmake/platforms/iphoneos/global.lua create mode 100644 xmake/platforms/linux/check.lua delete mode 100644 xmake/platforms/linux/config.lua delete mode 100644 xmake/platforms/linux/global.lua create mode 100644 xmake/platforms/macosx/check.lua delete mode 100644 xmake/platforms/macosx/config.lua delete mode 100644 xmake/platforms/macosx/global.lua create mode 100644 xmake/platforms/mingw/check.lua delete mode 100644 xmake/platforms/mingw/config.lua create mode 100644 xmake/platforms/msys/check.lua delete mode 100644 xmake/platforms/msys/config.lua create mode 100644 xmake/platforms/sdcc/check.lua delete mode 100644 xmake/platforms/sdcc/config.lua create mode 100644 xmake/platforms/watchos/check.lua delete mode 100644 xmake/platforms/watchos/config.lua delete mode 100644 xmake/platforms/watchos/global.lua create mode 100644 xmake/platforms/windows/check.lua delete mode 100644 xmake/platforms/windows/config.lua delete mode 100644 xmake/platforms/windows/global.lua (limited to 'xmake/toolchains/xcode') diff --git a/xmake/actions/global/main.lua b/xmake/actions/global/main.lua index 720eb0351..9472c9b24 100644 --- a/xmake/actions/global/main.lua +++ b/xmake/actions/global/main.lua @@ -59,11 +59,6 @@ function main() end end - -- check the global configure - if changed or option.get("clean") then - global.check() - end - -- load and check theme local themename = option.get("theme") if themename then diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index d80b72be5..677e36906 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -163,6 +163,14 @@ function _instance:data_add(name, data) self._DATA[name] = table.unwrap(table.join(self._DATA[name] or {}, data)) end +-- do check +function _instance:check() + local on_check = self:script("check") + if on_check then + on_check(self) + end +end + -- is builtin configuration? function _instance:_is_builtin_conf(name) @@ -219,8 +227,7 @@ function platform._apis() { -- platform.on_xxx "platform.on_load" - , "platform.on_config_check" - , "platform.on_global_check" + , "platform.on_check" , "platform.on_environment_enter" , "platform.on_environment_leave" } @@ -367,17 +374,6 @@ function platform.tool(toolkind, plat) config.set(toolkind, program, {force = true, readonly = true}) config.set("__toolname_" .. toolkind, toolname) config.save() - else - -- TODO deprecated - -- check it first - local on_check = instance:script("config_check") - if on_check then - on_check(instance, toolkind) - end - - -- get it again - program = config.get(toolkind) - toolname = config.get("__toolname_" .. toolkind) end end diff --git a/xmake/core/sandbox/modules/import/core/base/global.lua b/xmake/core/sandbox/modules/import/core/base/global.lua index 4ea5b2745..9141a2d76 100644 --- a/xmake/core/sandbox/modules/import/core/base/global.lua +++ b/xmake/core/sandbox/modules/import/core/base/global.lua @@ -68,31 +68,6 @@ function sandbox_core_base_global.clear() return global.clear() end --- check the configure -function sandbox_core_base_global.check() - - -- check all platforms with the current host - for _, plat in ipairs(table.wrap(platform.plats())) do - - -- load platform - local instance, errors = platform.load(plat) - if not instance then - raise(errors) - end - - -- belong to the current host? - for _, host in ipairs(table.wrap(instance:hosts())) do - if host == os.host() then - local on_check = instance:script("global_check") - if on_check then - on_check(instance) - end - break - end - end - end -end - -- get all options function sandbox_core_base_global.options() return global.options() diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua index 449fac71f..c7121a8a4 100644 --- a/xmake/core/sandbox/modules/import/core/project/config.lua +++ b/xmake/core/sandbox/modules/import/core/project/config.lua @@ -116,12 +116,7 @@ function sandbox_core_project_config.check() -- get the current platform local instance, errors = platform.load() if instance then - - -- do check - local on_check = instance:script("config_check") - if on_check then - on_check(instance) - end + instance:check() else raise(errors) end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 246d46a99..e79a32b22 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -61,6 +61,19 @@ end -- get the toolchain configuration function _instance:get(name) + + -- attempt to get the static configure value + local value = self._INFO:get(name) + if value ~= nil then + return value + end + + -- lazy loading platform if get other configuration + if not self:_is_builtin_conf(name) then + self:_load() + end + + -- get other platform info return self._INFO:get(name) end @@ -102,17 +115,21 @@ function _instance:_load() end -- do check -function _instance:_check() +function _instance:check() + local checkok = true if not self._CHECKED then local on_check = self._INFO:get("check") if on_check then - local ok, errors = sandbox.load(on_check, self) - if not ok then - os.raise(errors) + local ok, results_or_errors = sandbox.load(on_check, self) + if ok then + checkok = results_or_errors + else + os.raise(results_or_errors) end end self._CHECKED = true end + return checkok end -- get the tool description from the tool kind @@ -158,9 +175,6 @@ end -- check the given tool path function _instance:_checktool(toolkind, toolpath) - -- ensure to check this toolchain first - self:_check() - -- get find_tool local find_tool = self._find_tool if not find_tool then @@ -187,11 +201,6 @@ function _instance:_checktool(toolkind, toolpath) utils.cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, name) end end - - -- we only load it when checking the given tool successfully - if program then - self:_load() - end return program, toolname end diff --git a/xmake/platforms/android/check.lua b/xmake/platforms/android/check.lua new file mode 100644 index 000000000..04d639483 --- /dev/null +++ b/xmake/platforms/android/check.lua @@ -0,0 +1,155 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_ndk") +import("detect.sdks.find_android_sdk") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the ndk toolchain +function _check_ndk() + local ndk = find_ndk(config.get("ndk"), {force = true, verbose = true}) + if ndk then + config.set("ndk", ndk.sdkdir, {force = true, readonly = true}) -- maybe to global + config.set("bin", ndk.bindir, {force = true, readonly = true}) + config.set("cross", ndk.cross, {force = true, readonly = true}) + config.set("gcc_toolchain", ndk.gcc_toolchain, {force = true, readonly = true}) + else + -- failed + cprint("${bright color.error}please run:") + cprint(" - xmake config --ndk=xxx") + cprint("or - xmake global --ndk=xxx") + raise() + end +end + +-- check the android sdk +function _check_android_sdk() + local sdk = find_android_sdk(config.get("android_sdk"), {force = true, verbose = true}) + if sdk then + config.set("sdk", sdk.sdkdir, {force = true, readonly = true}) -- maybe to global + end +end + +-- get toolchains +function _toolchains() + + -- get cross + local cross = config.get("cross") + + -- get gcc toolchain bin directory + local gcc_toolchain_bin = nil + local gcc_toolchain = config.get("gcc_toolchain") + if gcc_toolchain then + gcc_toolchain_bin = path.join(gcc_toolchain, "bin") + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local cpp = toolchain("the c preprocessor") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local ranlib = toolchain("the static library index generator") + local strip = toolchain("the symbols stripper") + local as = toolchain("the assember") + local rc = toolchain("the rust compiler") + local rc_ld = toolchain("the rust linker") + local rc_sh = toolchain("the rust shared library linker") + local rc_ar = toolchain("the rust static library archiver") + local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip, + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar} + + -- init the c compiler + cc:add({name = "gcc", cross = cross}, "clang") + + -- init the c++ compiler + cxx:add({name = "g++", cross = cross}, "clang++") + + -- init the c preprocessor + cpp:add({name = "gcc -E", cross = cross}, "clang -E") + + -- init the assember + as:add({name = "gcc", cross = cross}, "clang") + + -- init the linker + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + ld:add("clang++", "clang") + + -- init the shared library linker + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + sh:add("clang++", "clang") + + -- init the static library archiver + ar:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") + + -- init the static library extractor + ex:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") + + -- init the static library index generator + ranlib:add({name = "ranlib", cross = cross, pathes = gcc_toolchain_bin}, "ranlib") + + -- init the symbols stripper + strip:add({name = "strip", cross = cross, pathes = gcc_toolchain_bin}, "strip") + + -- init the rust compiler and linker + rc:add("$(env RC)", "rustc") + rc_ld:add("$(env RC)", "rustc") + rc_sh:add("$(env RC)", "rustc") + rc_ar:add("$(env RC)", "rustc") + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("android.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + check_arch(config, "armeabi-v7a") + + -- check android sdk + _check_android_sdk() + + -- check ndk + _check_ndk() + + -- check ld and sh, @note toolchains must be initialized after calling check_ndk() + local toolchains = singleton.get("android.toolchains", _toolchains) + check_toolchain(config, "ld", toolchains.ld) + check_toolchain(config, "sh", toolchains.sh) + end +end + diff --git a/xmake/platforms/android/config.lua b/xmake/platforms/android/config.lua deleted file mode 100644 index e99a4d14a..000000000 --- a/xmake/platforms/android/config.lua +++ /dev/null @@ -1,155 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_ndk") -import("detect.sdks.find_android_sdk") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the ndk toolchain -function _check_ndk() - local ndk = find_ndk(config.get("ndk"), {force = true, verbose = true}) - if ndk then - config.set("ndk", ndk.sdkdir, {force = true, readonly = true}) -- maybe to global - config.set("bin", ndk.bindir, {force = true, readonly = true}) - config.set("cross", ndk.cross, {force = true, readonly = true}) - config.set("gcc_toolchain", ndk.gcc_toolchain, {force = true, readonly = true}) - else - -- failed - cprint("${bright color.error}please run:") - cprint(" - xmake config --ndk=xxx") - cprint("or - xmake global --ndk=xxx") - raise() - end -end - --- check the android sdk -function _check_android_sdk() - local sdk = find_android_sdk(config.get("android_sdk"), {force = true, verbose = true}) - if sdk then - config.set("sdk", sdk.sdkdir, {force = true, readonly = true}) -- maybe to global - end -end - --- get toolchains -function _toolchains() - - -- get cross - local cross = config.get("cross") - - -- get gcc toolchain bin directory - local gcc_toolchain_bin = nil - local gcc_toolchain = config.get("gcc_toolchain") - if gcc_toolchain then - gcc_toolchain_bin = path.join(gcc_toolchain, "bin") - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local ranlib = toolchain("the static library index generator") - local strip = toolchain("the symbols stripper") - local as = toolchain("the assember") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar} - - -- init the c compiler - cc:add({name = "gcc", cross = cross}, "clang") - - -- init the c++ compiler - cxx:add({name = "g++", cross = cross}, "clang++") - - -- init the c preprocessor - cpp:add({name = "gcc -E", cross = cross}, "clang -E") - - -- init the assember - as:add({name = "gcc", cross = cross}, "clang") - - -- init the linker - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add("clang++", "clang") - - -- init the shared library linker - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add("clang++", "clang") - - -- init the static library archiver - ar:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") - - -- init the static library extractor - ex:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") - - -- init the static library index generator - ranlib:add({name = "ranlib", cross = cross, pathes = gcc_toolchain_bin}, "ranlib") - - -- init the symbols stripper - strip:add({name = "strip", cross = cross, pathes = gcc_toolchain_bin}, "strip") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("android.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "armeabi-v7a") - - -- check android sdk - _check_android_sdk() - - -- check ndk - _check_ndk() - - -- check ld and sh, @note toolchains must be initialized after calling check_ndk() - local toolchains = singleton.get("android.toolchains", _toolchains) - check_toolchain(config, "ld", toolchains.ld) - check_toolchain(config, "sh", toolchains.sh) - end -end - diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua index 45a4eaf8d..cb7d52594 100644 --- a/xmake/platforms/android/xmake.lua +++ b/xmake/platforms/android/xmake.lua @@ -39,8 +39,8 @@ platform("android") -- set formats set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"} - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/bsd/check.lua b/xmake/platforms/bsd/check.lua new file mode 100644 index 000000000..1eb8834ef --- /dev/null +++ b/xmake/platforms/bsd/check.lua @@ -0,0 +1,175 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + + -- init the default architecture + config.set("arch", config.get("cross") and "none" or os.arch()) + + -- trace + print("checking for the architecture ... %s", config.get("arch")) + end +end + +-- get toolchains +function _toolchains() + + -- find cross toolchain + local cross = "" + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + cross = cross_toolchain.cross + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local strip = toolchain("the symbols stripper") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local gc = toolchain("the golang compiler") + local gc_ld = toolchain("the golang linker") + local gc_ar = toolchain("the golang static library archiver") + local dc = toolchain("the dlang compiler") + local dc_ld = toolchain("the dlang linker") + local dc_sh = toolchain("the dlang shared library linker") + local dc_ar = toolchain("the dlang static library archiver") + local rc = toolchain("the rust compiler") + local rc_ld = toolchain("the rust linker") + local rc_sh = toolchain("the rust shared library linker") + local rc_ar = toolchain("the rust static library archiver") + local cu = toolchain("the cuda compiler") + local cu_ld = toolchain("the cuda linker") + local cu_ccbin = toolchain("the cuda host c++ compiler") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, + mm = mm, mxx = mxx, + gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, + dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, + cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + + -- init the c compiler + cc:add("$(env CC)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + cxx:add({name = "g++", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the symbols stripper + strip:add("$(env STRIP)", {name = "strip", cross = cross}) + + -- init the objc compiler + mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the objc++ compiler + mxx:add("$(env MXX)") + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + mxx:add({name = "gcc", cross = cross}) + mxx:add({name = "g++", cross = cross}) + + -- init the golang compiler and linker + gc:add("$(env GC)", "go", "gccgo") + gc_ld:add("$(env GC)", "go", "gccgo") + gc_ar:add("$(env GC)", "go", "gccgo") + + -- init the dlang compiler and linker + dc:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") + + -- init the rust compiler and linker + rc:add("$(env RC)", "rustc") + rc_ld:add("$(env RC)", "rustc") + rc_sh:add("$(env RC)", "rustc") + rc_ar:add("$(env RC)", "rustc") + + -- init the cuda compiler and linker + cu:add("nvcc", "clang++", "clang") + cu_ld:add("nvcc") + if not cross or cross == "" then + cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") + end + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("linux.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + end +end + diff --git a/xmake/platforms/bsd/config.lua b/xmake/platforms/bsd/config.lua deleted file mode 100644 index 69164b8b4..000000000 --- a/xmake/platforms/bsd/config.lua +++ /dev/null @@ -1,175 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.arch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, - mm = mm, mxx = mxx, - gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, - dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - cxx:add({name = "g++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add("$(env STRIP)", {name = "strip", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("linux.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/bsd/global.lua b/xmake/platforms/bsd/global.lua deleted file mode 100644 index d74d84943..000000000 --- a/xmake/platforms/bsd/global.lua +++ /dev/null @@ -1,32 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- imports -import("core.base.global") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end -end - diff --git a/xmake/platforms/bsd/xmake.lua b/xmake/platforms/bsd/xmake.lua index 3ea3ed9f6..d0cacd28a 100644 --- a/xmake/platforms/bsd/xmake.lua +++ b/xmake/platforms/bsd/xmake.lua @@ -36,11 +36,8 @@ platform("bsd") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/cross/check.lua b/xmake/platforms/cross/check.lua new file mode 100644 index 000000000..833dcb921 --- /dev/null +++ b/xmake/platforms/cross/check.lua @@ -0,0 +1,189 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + config.set("arch", "none") + end +end + +-- check the cross toolchain +function _check_cross_toolchain() + -- find cross toolchain + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + + -- TODO add to environment module + -- add bin search library for loading some dependent .dll files windows + if cross_toolchain.bindir and is_host("windows") then + os.addenv("PATH", cross_toolchain.bindir) + end + end +end + +-- get llvm toolchains +function _toolchains_llvm() + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local cpp = toolchain("the c preprocessor") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local strip = toolchain("the symbols stripper") + local ranlib = toolchain("the static library index generator") + local as = toolchain("the assember") + local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} + + -- init the c compiler + cc:add("$(env CC)", "clang") + + -- init the c preprocessor + cpp:add("$(env CPP)", "clang -E") + + -- init the c++ compiler + cxx:add("$(env CXX)", "clang", "clang++") + + -- init the assember + as:add("$(env AS)", "clang") + + -- init the linker + ld:add("$(env LD)", "$(env CXX)", "clang++", "clang") + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)", "clang++", "clang") + + -- init the static library archiver + ar:add("$(env AR)", "llvm-ar") + + -- init the static library extractor + ex:add("$(env AR)", "llvm-ar") + + -- init the static library index generator + ranlib:add("$(env RANLIB)", "llvm-ranlib") + + -- init the symbols stripper + strip:add("$(env STRIP)", "llvm-strip") + return toolchains +end + +-- get toolchains +function _toolchains() + + -- get cross prefix + local cross = config.get("cross") or "" + + -- for llvm toolchains? + if cross == "" and config.get("toolchain") == "llvm" then + return _toolchains_llvm() + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local cpp = toolchain("the c preprocessor") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local strip = toolchain("the symbols stripper") + local ranlib = toolchain("the static library index generator") + local as = toolchain("the assember") + local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} + + -- init the c compiler + cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the c preprocessor + cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}, {name = "clang -E", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "g++", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library index generator + ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) + + -- init the symbols stripper + strip:add("$(env STRIP)", {name = "strip", cross = cross}) + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("cross.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + + -- check cross toolchain + _check_cross_toolchain() + end +end + diff --git a/xmake/platforms/cross/config.lua b/xmake/platforms/cross/config.lua deleted file mode 100644 index b159cf5c1..000000000 --- a/xmake/platforms/cross/config.lua +++ /dev/null @@ -1,189 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - config.set("arch", "none") - end -end - --- check the cross toolchain -function _check_cross_toolchain() - -- find cross toolchain - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - - -- TODO add to environment module - -- add bin search library for loading some dependent .dll files windows - if cross_toolchain.bindir and is_host("windows") then - os.addenv("PATH", cross_toolchain.bindir) - end - end -end - --- get llvm toolchains -function _toolchains_llvm() - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} - - -- init the c compiler - cc:add("$(env CC)", "clang") - - -- init the c preprocessor - cpp:add("$(env CPP)", "clang -E") - - -- init the c++ compiler - cxx:add("$(env CXX)", "clang", "clang++") - - -- init the assember - as:add("$(env AS)", "clang") - - -- init the linker - ld:add("$(env LD)", "$(env CXX)", "clang++", "clang") - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)", "clang++", "clang") - - -- init the static library archiver - ar:add("$(env AR)", "llvm-ar") - - -- init the static library extractor - ex:add("$(env AR)", "llvm-ar") - - -- init the static library index generator - ranlib:add("$(env RANLIB)", "llvm-ranlib") - - -- init the symbols stripper - strip:add("$(env STRIP)", "llvm-strip") - return toolchains -end - --- get toolchains -function _toolchains() - - -- get cross prefix - local cross = config.get("cross") or "" - - -- for llvm toolchains? - if cross == "" and config.get("toolchain") == "llvm" then - return _toolchains_llvm() - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c preprocessor - cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}, {name = "clang -E", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library index generator - ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) - - -- init the symbols stripper - strip:add("$(env STRIP)", {name = "strip", cross = cross}) - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("cross.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - - -- check cross toolchain - _check_cross_toolchain() - end -end - diff --git a/xmake/platforms/cross/xmake.lua b/xmake/platforms/cross/xmake.lua index 31e7f6d95..a76dde03c 100644 --- a/xmake/platforms/cross/xmake.lua +++ b/xmake/platforms/cross/xmake.lua @@ -30,8 +30,8 @@ platform("cross") -- set formats set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"} - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/cygwin/check.lua b/xmake/platforms/cygwin/check.lua new file mode 100644 index 000000000..3b1221387 --- /dev/null +++ b/xmake/platforms/cygwin/check.lua @@ -0,0 +1,172 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + + -- init the default architecture + config.set("arch", config.get("cross") and "none" or os.subarch()) + + -- trace + print("checking for the architecture ... %s", config.get("arch")) + end +end + +-- get toolchains +function _toolchains() + + -- find cross toolchain + local cross = "" + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + cross = cross_toolchain.cross + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local gc = toolchain("the golang compiler") + local gc_ld = toolchain("the golang linker") + local gc_ar = toolchain("the golang static library archiver") + local dc = toolchain("the dlang compiler") + local dc_ld = toolchain("the dlang linker") + local dc_sh = toolchain("the dlang shared library linker") + local dc_ar = toolchain("the dlang static library archiver") + local rc = toolchain("the rust compiler") + local rc_ld = toolchain("the rust linker") + local rc_sh = toolchain("the rust shared library linker") + local rc_ar = toolchain("the rust static library archiver") + local cu = toolchain("the cuda compiler") + local cu_ld = toolchain("the cuda linker") + local cu_ccbin = toolchain("the cuda host c++ compiler") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, + mm = mm, mxx = mxx, + gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, + dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, + cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + + -- init the c compiler + cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "g++", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the objc compiler + mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the objc++ compiler + mxx:add("$(env MXX)") + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + mxx:add({name = "gcc", cross = cross}) + mxx:add({name = "g++", cross = cross}) + + -- init the golang compiler and linker + gc:add("$(env GC)", "go", "gccgo") + gc_ld:add("$(env GC)", "go", "gccgo") + gc_ar:add("$(env GC)", "go", "gccgo") + + -- init the dlang compiler and linker + dc:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") + + -- init the rust compiler and linker + rc:add("$(env RC)", "rustc") + rc_ld:add("$(env RC)", "rustc") + rc_sh:add("$(env RC)", "rustc") + rc_ar:add("$(env RC)", "rustc") + + -- init the cuda compiler and linker + cu:add("nvcc", "clang++", "clang") + cu_ld:add("nvcc") + if not cross or cross == "" then + cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") + end + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("cygwin.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + end +end + diff --git a/xmake/platforms/cygwin/config.lua b/xmake/platforms/cygwin/config.lua deleted file mode 100644 index 26f008970..000000000 --- a/xmake/platforms/cygwin/config.lua +++ /dev/null @@ -1,172 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.subarch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, - mm = mm, mxx = mxx, - gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, - dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("cygwin.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/cygwin/xmake.lua b/xmake/platforms/cygwin/xmake.lua index e43c5e35c..32ab7df58 100644 --- a/xmake/platforms/cygwin/xmake.lua +++ b/xmake/platforms/cygwin/xmake.lua @@ -36,8 +36,8 @@ platform("cygwin") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/iphoneos/check.lua b/xmake/platforms/iphoneos/check.lua new file mode 100644 index 000000000..94a3a9ae9 --- /dev/null +++ b/xmake/platforms/iphoneos/check.lua @@ -0,0 +1,128 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_xcode") +import("private.platform.check_toolchain") + +-- get toolchains +function _toolchains() + + -- init architecture + local arch = config.get("arch") or os.arch() + local simulator = (arch == "i386" or arch == "x86_64") + + -- init cross + local cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " + + -- init toolchains + local cc = toolchain("the c compiler") + local cpp = toolchain("the c preprocessor") + local cxx = toolchain("the c++ compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local strip = toolchain("the symbols stripper") + local dsymutil = toolchain("the symbols generator") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local sc = toolchain("the swift compiler") + local sc_ld = toolchain("the swift linker") + local sc_sh = toolchain("the swift shared library linker") + local toolchains = {cc = cc, cpp = cpp, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, + mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} + + -- init the c compiler + cc:add({name = "clang", cross = cross}) + + -- init the c preprocessor + cpp:add({name = "clang -arch " .. arch .. " -E", cross = cross}) + + -- init the c++ compiler + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + if simulator then + as:add({name = "clang", cross = cross}) + else + as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) + end + + -- init the linker + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add({name = "ar", cross = cross}) + + -- init the static library extractor + ex:add({name = "ar", cross = cross}) + + -- init the symbols stripper + strip:add({name = "strip", cross = cross}) + + -- init the symbols generator + dsymutil:add({name = "dsymutil", cross = cross}) + + -- init the objc compiler + mm:add({name = "clang", cross = cross}) + + -- init the objc++ compiler + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + + -- init the swift compiler and linker + sc:add({name = "swiftc", cross = cross}) + sc_ld:add({name = "swiftc", cross = cross}) + sc_sh:add({name = "swiftc", cross = cross}) + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("iphoneos.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + check_arch(config, "arm64") + + -- check xcode + check_xcode(config) + end +end + diff --git a/xmake/platforms/iphoneos/config.lua b/xmake/platforms/iphoneos/config.lua deleted file mode 100644 index 1e3592f45..000000000 --- a/xmake/platforms/iphoneos/config.lua +++ /dev/null @@ -1,128 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_xcode") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init architecture - local arch = config.get("arch") or os.arch() - local simulator = (arch == "i386" or arch == "x86_64") - - -- init cross - local cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " - - -- init toolchains - local cc = toolchain("the c compiler") - local cpp = toolchain("the c preprocessor") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local dsymutil = toolchain("the symbols generator") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local sc = toolchain("the swift compiler") - local sc_ld = toolchain("the swift linker") - local sc_sh = toolchain("the swift shared library linker") - local toolchains = {cc = cc, cpp = cpp, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} - - -- init the c compiler - cc:add({name = "clang", cross = cross}) - - -- init the c preprocessor - cpp:add({name = "clang -arch " .. arch .. " -E", cross = cross}) - - -- init the c++ compiler - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - if simulator then - as:add({name = "clang", cross = cross}) - else - as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) - end - - -- init the linker - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add({name = "ar", cross = cross}) - - -- init the static library extractor - ex:add({name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add({name = "strip", cross = cross}) - - -- init the symbols generator - dsymutil:add({name = "dsymutil", cross = cross}) - - -- init the objc compiler - mm:add({name = "clang", cross = cross}) - - -- init the objc++ compiler - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - - -- init the swift compiler and linker - sc:add({name = "swiftc", cross = cross}) - sc_ld:add({name = "swiftc", cross = cross}) - sc_sh:add({name = "swiftc", cross = cross}) - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("iphoneos.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "arm64") - - -- check xcode - check_xcode(config) - end -end - diff --git a/xmake/platforms/iphoneos/global.lua b/xmake/platforms/iphoneos/global.lua deleted file mode 100644 index f625eb103..000000000 --- a/xmake/platforms/iphoneos/global.lua +++ /dev/null @@ -1,36 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- imports -import("core.base.global") -import("private.platform.check_xcode") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end - - -- check xcode - check_xcode(global, true) -end - diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index 2f6bcf00f..6d2af82ae 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -33,11 +33,8 @@ platform("iphoneos") -- set formats set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dylib", symbol = "$(name).dSYM"} - -- on check project configuration - on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua new file mode 100644 index 000000000..1671ee0e9 --- /dev/null +++ b/xmake/platforms/linux/check.lua @@ -0,0 +1,175 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + + -- init the default architecture + config.set("arch", config.get("cross") and "none" or os.arch()) + + -- trace + print("checking for the architecture ... %s", config.get("arch")) + end +end + +-- get toolchains +function _toolchains() + + -- find cross toolchain + local cross = "" + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + cross = cross_toolchain.cross + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local strip = toolchain("the symbols stripper") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local gc = toolchain("the golang compiler") + local gc_ld = toolchain("the golang linker") + local gc_ar = toolchain("the golang static library archiver") + local dc = toolchain("the dlang compiler") + local dc_ld = toolchain("the dlang linker") + local dc_sh = toolchain("the dlang shared library linker") + local dc_ar = toolchain("the dlang static library archiver") + local rc = toolchain("the rust compiler") + local rc_ld = toolchain("the rust linker") + local rc_sh = toolchain("the rust shared library linker") + local rc_ar = toolchain("the rust static library archiver") + local cu = toolchain("the cuda compiler") + local cu_ld = toolchain("the cuda linker") + local cu_ccbin = toolchain("the cuda host c++ compiler") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, + mm = mm, mxx = mxx, + gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, + dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, + cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + + -- init the c compiler + cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "g++", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the symbols stripper + strip:add("$(env STRIP)", {name = "strip", cross = cross}) + + -- init the objc compiler + mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the objc++ compiler + mxx:add("$(env MXX)") + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + mxx:add({name = "gcc", cross = cross}) + mxx:add({name = "g++", cross = cross}) + + -- init the golang compiler and linker + gc:add("$(env GC)", "go", "gccgo") + gc_ld:add("$(env GC)", "go", "gccgo") + gc_ar:add("$(env GC)", "go", "gccgo") + + -- init the dlang compiler and linker + dc:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") + + -- init the rust compiler and linker + rc:add("$(env RC)", "rustc") + rc_ld:add("$(env RC)", "rustc") + rc_sh:add("$(env RC)", "rustc") + rc_ar:add("$(env RC)", "rustc") + + -- init the cuda compiler and linker + cu:add("nvcc", "clang++", "clang") + cu_ld:add("nvcc") + if not cross or cross == "" then + cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") + end + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("linux.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + end +end + diff --git a/xmake/platforms/linux/config.lua b/xmake/platforms/linux/config.lua deleted file mode 100644 index ac9b42931..000000000 --- a/xmake/platforms/linux/config.lua +++ /dev/null @@ -1,175 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.arch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, - mm = mm, mxx = mxx, - gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, - dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add("$(env STRIP)", {name = "strip", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("linux.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/linux/global.lua b/xmake/platforms/linux/global.lua deleted file mode 100644 index d74d84943..000000000 --- a/xmake/platforms/linux/global.lua +++ /dev/null @@ -1,32 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- imports -import("core.base.global") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end -end - diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua index 53517239a..21e4d2e51 100644 --- a/xmake/platforms/linux/xmake.lua +++ b/xmake/platforms/linux/xmake.lua @@ -36,11 +36,8 @@ platform("linux") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua new file mode 100644 index 000000000..ff552ad6b --- /dev/null +++ b/xmake/platforms/macosx/check.lua @@ -0,0 +1,175 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") + +--[[ +import("core.base.singleton") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_xcode") +import("private.platform.check_toolchain") + +-- get toolchains +function _toolchains() + + -- init cross + local cross = "xcrun -sdk macosx " + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local strip = toolchain("the symbols stripper") + local dsymutil = toolchain("the symbols generator") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local sc = toolchain("the swift compiler") + local sc_ld = toolchain("the swift linker") + local sc_sh = toolchain("the swift shared library linker") + local gc = toolchain("the golang compiler") + local gc_ld = toolchain("the golang linker") + local gc_ar = toolchain("the golang static library archiver") + local dc = toolchain("the dlang compiler") + local dc_ld = toolchain("the dlang linker") + local dc_sh = toolchain("the dlang shared library linker") + local dc_ar = toolchain("the dlang static library archiver") + local rc = toolchain("the rust compiler") + local rc_ld = toolchain("the rust linker") + local rc_sh = toolchain("the rust shared library linker") + local rc_ar = toolchain("the rust static library archiver") + local cu = toolchain("the cuda compiler") + local cu_ld = toolchain("the cuda linker") + local cu_ccbin = toolchain("the cuda host c++ compiler") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, + mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh, + gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, + dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, + cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + + -- init the c compiler + cc:add("$(env CC)", {name = "clang", cross = cross}, "clang", "gcc") + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + cxx:add("clang", "clang++", "gcc", "g++") + + -- init the assember + as:add("$(env AS)", {name = "clang", cross = cross}, "clang", "gcc") + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + ld:add("clang++", "g++", "clang", "gcc") + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + sh:add("clang++", "g++", "clang", "gcc") + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}, "ar") + + -- init the static library extractor + ex:add({name = "ar", cross = cross}, "ar") + + -- init the symbols stripper + strip:add({name = "strip", cross = cross}, "strip") + + -- init the symbols generator + dsymutil:add({name = "dsymutil", cross = cross}, "dsymutil") + + -- init the objc compiler + mm:add("$(env MM)", {name = "clang", cross = cross}, "clang", "gcc") + + -- init the objc++ compiler + mxx:add("$(env MXX)") + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + mxx:add("clang", "clang++", "gcc", "g++") + + -- init the swift compiler and linker + sc:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") + sc_ld:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") + sc_sh:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") + + -- init the golang compiler and linker + gc:add("$(env GC)", "go", "gccgo") + gc_ld:add("$(env GC)", "go", "gccgo") + gc_ar:add("$(env GC)", "go", "gccgo") + + -- init the dlang compiler and linker + dc:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") + + -- init the rust compiler and linker + rc:add("$(env RC)", "rustc") + rc_ld:add("$(env RC)", "rustc") + rc_sh:add("$(env RC)", "rustc") + rc_ar:add("$(env RC)", "rustc") + + -- init the cuda compiler and linker + cu:add("nvcc", "clang") + cu_ld:add("nvcc") + cu_ccbin:add("$(env CXX)", "$(env CC)", "clang", "gcc") + + return toolchains +end]] + +-- check it +function main(platform) + + -- check toolchains + local toolchains = platform:toolchains() + for idx, toolchain in irpairs(toolchains) do + if not toolchain:check() then + table.remove(toolchains, idx) + end + end + + --[[ + -- only check the given config name? + if name then + local toolchain = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + check_arch(config) + + -- check xcode + check_xcode(config, true) + end]] +end + diff --git a/xmake/platforms/macosx/config.lua b/xmake/platforms/macosx/config.lua deleted file mode 100644 index a1713a657..000000000 --- a/xmake/platforms/macosx/config.lua +++ /dev/null @@ -1,165 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_xcode") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init cross - local cross = "xcrun -sdk macosx " - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local dsymutil = toolchain("the symbols generator") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local sc = toolchain("the swift compiler") - local sc_ld = toolchain("the swift linker") - local sc_sh = toolchain("the swift shared library linker") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh, - gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, - dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "clang", cross = cross}, "clang", "gcc") - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - cxx:add("clang", "clang++", "gcc", "g++") - - -- init the assember - as:add("$(env AS)", {name = "clang", cross = cross}, "clang", "gcc") - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - ld:add("clang++", "g++", "clang", "gcc") - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - sh:add("clang++", "g++", "clang", "gcc") - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}, "ar") - - -- init the static library extractor - ex:add({name = "ar", cross = cross}, "ar") - - -- init the symbols stripper - strip:add({name = "strip", cross = cross}, "strip") - - -- init the symbols generator - dsymutil:add({name = "dsymutil", cross = cross}, "dsymutil") - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, "clang", "gcc") - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add("clang", "clang++", "gcc", "g++") - - -- init the swift compiler and linker - sc:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") - sc_ld:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") - sc_sh:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang") - cu_ld:add("nvcc") - cu_ccbin:add("$(env CXX)", "$(env CC)", "clang", "gcc") - - return toolchains -end - --- check it -function main(platform, name) - - --[[ - -- only check the given config name? - if name then - local toolchain = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config) - - -- check xcode - check_xcode(config, true) - end]] -end - diff --git a/xmake/platforms/macosx/global.lua b/xmake/platforms/macosx/global.lua deleted file mode 100644 index f625eb103..000000000 --- a/xmake/platforms/macosx/global.lua +++ /dev/null @@ -1,36 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- imports -import("core.base.global") -import("private.platform.check_xcode") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end - - -- check xcode - check_xcode(global, true) -end - diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index fc390d953..512499c7c 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -36,11 +36,8 @@ platform("macosx") -- set install directory set_installdir("/usr/local") - -- on check project configuration --- on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/mingw/check.lua b/xmake/platforms/mingw/check.lua new file mode 100644 index 000000000..9905a53cc --- /dev/null +++ b/xmake/platforms/mingw/check.lua @@ -0,0 +1,128 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_mingw") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the mingw toolchain +function _check_mingw() + local mingw = find_mingw(config.get("mingw"), {verbose = true, bindir = config.get("bin"), cross = config.get("cross")}) + if mingw then + config.set("mingw", mingw.sdkdir, {force = true, readonly = true}) + config.set("cross", mingw.cross, {readonly = true, force = true}) + config.set("bin", mingw.bindir, {readonly = true, force = true}) + else + -- failed + cprint("${bright color.error}please run:") + cprint(" - xmake config --ndk=xxx") + cprint("or - xmake global --ndk=xxx") + raise() + end +end + +-- get toolchains +function _toolchains() + + -- get cross + local cross = config.get("cross") + + -- TODO add to environment module + -- add bin search library for loading some dependent .dll files windows + local bindir = config.get("bin") + if bindir and is_host("windows") then + os.addenv("PATH", bindir) + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local cpp = toolchain("the c preprocessor") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local ranlib = toolchain("the static library index generator") + local as = toolchain("the assember") + local mrc = toolchain("the resource compiler") + local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, mrc = mrc} + + -- init the c compiler + cc:add("$(env CC)", {name = "gcc", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "g++", cross = cross}) + + -- init the c preprocessor + cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "gcc", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) + + -- init the resource compiler + mrc:add({name = "windres", cross = cross}) + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("mingw.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + check_arch(config, "x86_64") + + -- check mingw + _check_mingw() + end +end + diff --git a/xmake/platforms/mingw/config.lua b/xmake/platforms/mingw/config.lua deleted file mode 100644 index bbfc6f7f9..000000000 --- a/xmake/platforms/mingw/config.lua +++ /dev/null @@ -1,128 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_mingw") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the mingw toolchain -function _check_mingw() - local mingw = find_mingw(config.get("mingw"), {verbose = true, bindir = config.get("bin"), cross = config.get("cross")}) - if mingw then - config.set("mingw", mingw.sdkdir, {force = true, readonly = true}) - config.set("cross", mingw.cross, {readonly = true, force = true}) - config.set("bin", mingw.bindir, {readonly = true, force = true}) - else - -- failed - cprint("${bright color.error}please run:") - cprint(" - xmake config --ndk=xxx") - cprint("or - xmake global --ndk=xxx") - raise() - end -end - --- get toolchains -function _toolchains() - - -- get cross - local cross = config.get("cross") - - -- TODO add to environment module - -- add bin search library for loading some dependent .dll files windows - local bindir = config.get("bin") - if bindir and is_host("windows") then - os.addenv("PATH", bindir) - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local mrc = toolchain("the resource compiler") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, mrc = mrc} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "g++", cross = cross}) - - -- init the c preprocessor - cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) - - -- init the resource compiler - mrc:add({name = "windres", cross = cross}) - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("mingw.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "x86_64") - - -- check mingw - _check_mingw() - end -end - diff --git a/xmake/platforms/mingw/xmake.lua b/xmake/platforms/mingw/xmake.lua index 7b5ad2624..e119f137f 100644 --- a/xmake/platforms/mingw/xmake.lua +++ b/xmake/platforms/mingw/xmake.lua @@ -33,8 +33,8 @@ platform("mingw") -- set formats set_formats {static = "$(name).lib", object = "$(name).obj", shared = "$(name).dll", binary = "$(name).exe", symbol = "$(name).pdb"} - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/msys/check.lua b/xmake/platforms/msys/check.lua new file mode 100644 index 000000000..8c5a2dcdd --- /dev/null +++ b/xmake/platforms/msys/check.lua @@ -0,0 +1,172 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + + -- init the default architecture + config.set("arch", config.get("cross") and "none" or os.subarch()) + + -- trace + print("checking for the architecture ... %s", config.get("arch")) + end +end + +-- get toolchains +function _toolchains() + + -- find cross toolchain + local cross = "" + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + cross = cross_toolchain.cross + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local gc = toolchain("the golang compiler") + local gc_ld = toolchain("the golang linker") + local gc_ar = toolchain("the golang static library archiver") + local dc = toolchain("the dlang compiler") + local dc_ld = toolchain("the dlang linker") + local dc_sh = toolchain("the dlang shared library linker") + local dc_ar = toolchain("the dlang static library archiver") + local rc = toolchain("the rust compiler") + local rc_ld = toolchain("the rust linker") + local rc_sh = toolchain("the rust shared library linker") + local rc_ar = toolchain("the rust static library archiver") + local cu = toolchain("the cuda compiler") + local cu_ld = toolchain("the cuda linker") + local cu_ccbin = toolchain("the cuda host c++ compiler") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, + mm = mm, mxx = mxx, + gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, + dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, + cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + + -- init the c compiler + cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "g++", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the objc compiler + mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the objc++ compiler + mxx:add("$(env MXX)") + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + mxx:add({name = "gcc", cross = cross}) + mxx:add({name = "g++", cross = cross}) + + -- init the golang compiler and linker + gc:add("$(env GC)", "go", "gccgo") + gc_ld:add("$(env GC)", "go", "gccgo") + gc_ar:add("$(env GC)", "go", "gccgo") + + -- init the dlang compiler and linker + dc:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") + + -- init the rust compiler and linker + rc:add("$(env RC)", "rustc") + rc_ld:add("$(env RC)", "rustc") + rc_sh:add("$(env RC)", "rustc") + rc_ar:add("$(env RC)", "rustc") + + -- init the cuda compiler and linker + cu:add("nvcc", "clang++", "clang") + cu_ld:add("nvcc") + if not cross or cross == "" then + cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") + end + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("msys.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + end +end + diff --git a/xmake/platforms/msys/config.lua b/xmake/platforms/msys/config.lua deleted file mode 100644 index dbb1be255..000000000 --- a/xmake/platforms/msys/config.lua +++ /dev/null @@ -1,172 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.subarch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, - mm = mm, mxx = mxx, - gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, - dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("msys.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/msys/xmake.lua b/xmake/platforms/msys/xmake.lua index b3abadbf9..69c56db22 100644 --- a/xmake/platforms/msys/xmake.lua +++ b/xmake/platforms/msys/xmake.lua @@ -36,8 +36,8 @@ platform("msys") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/sdcc/check.lua b/xmake/platforms/sdcc/check.lua new file mode 100644 index 000000000..6532ea00e --- /dev/null +++ b/xmake/platforms/sdcc/check.lua @@ -0,0 +1,114 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + config.set("arch", "stm8") + end +end + +-- check the cross toolchain +function _check_cross_toolchain() + -- find cross toolchain + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + + -- TODO add to environment module + -- add bin search library for loading some dependent .dll files windows + if cross_toolchain.bindir and is_host("windows") then + os.addenv("PATH", cross_toolchain.bindir) + end + end +end + +-- get toolchains +function _toolchains() + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local cpp = toolchain("the c preprocessor") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local ranlib = toolchain("the static library index generator") + local as = toolchain("the assember") + local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib} + + -- init the c compiler + cc:add("$(env CC)", "sdcc") + + -- init the c preprocessor + cpp:add("$(env CPP)", "sdcpp") + + -- init the c++ compiler + cxx:add("$(env CXX)", "sdcc") + + -- init the assember + as:add("$(env AS)", "sdcc") + + -- init the linker + ld:add("$(env LD)", "$(env CXX)", "sdcc") + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)", "sdcc") + + -- init the static library archiver + ar:add("$(env AR)", "sdar") + + -- init the static library extractor + ex:add("$(env AR)", "sdar") + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("cross.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + + -- check cross toolchain + _check_cross_toolchain() + end +end + diff --git a/xmake/platforms/sdcc/config.lua b/xmake/platforms/sdcc/config.lua deleted file mode 100644 index ad2f14626..000000000 --- a/xmake/platforms/sdcc/config.lua +++ /dev/null @@ -1,114 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - config.set("arch", "stm8") - end -end - --- check the cross toolchain -function _check_cross_toolchain() - -- find cross toolchain - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - - -- TODO add to environment module - -- add bin search library for loading some dependent .dll files windows - if cross_toolchain.bindir and is_host("windows") then - os.addenv("PATH", cross_toolchain.bindir) - end - end -end - --- get toolchains -function _toolchains() - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib} - - -- init the c compiler - cc:add("$(env CC)", "sdcc") - - -- init the c preprocessor - cpp:add("$(env CPP)", "sdcpp") - - -- init the c++ compiler - cxx:add("$(env CXX)", "sdcc") - - -- init the assember - as:add("$(env AS)", "sdcc") - - -- init the linker - ld:add("$(env LD)", "$(env CXX)", "sdcc") - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)", "sdcc") - - -- init the static library archiver - ar:add("$(env AR)", "sdar") - - -- init the static library extractor - ex:add("$(env AR)", "sdar") - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("cross.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - - -- check cross toolchain - _check_cross_toolchain() - end -end - diff --git a/xmake/platforms/sdcc/xmake.lua b/xmake/platforms/sdcc/xmake.lua index b06094f9f..ad2f02be9 100644 --- a/xmake/platforms/sdcc/xmake.lua +++ b/xmake/platforms/sdcc/xmake.lua @@ -30,8 +30,8 @@ platform("sdcc") -- set formats set_formats {static = "$(name).lib", object = "$(name).rel", binary = "$(name).bin", symbol = "$(name).sym"} - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/watchos/check.lua b/xmake/platforms/watchos/check.lua new file mode 100644 index 000000000..89086d74c --- /dev/null +++ b/xmake/platforms/watchos/check.lua @@ -0,0 +1,124 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_xcode") +import("private.platform.check_toolchain") + +-- get toolchains +function _toolchains() + + -- init architecture + local arch = config.get("arch") + local simulator = (arch == "i386") + + -- init cross + local cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local strip = toolchain("the symbols stripper") + local dsymutil = toolchain("the symbols generator") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local sc = toolchain("the swift compiler") + local sc_ld = toolchain("the swift linker") + local sc_sh = toolchain("the swift shared library linker") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, + mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} + + -- init the c compiler + cc:add({name = "clang", cross = cross}) + + -- init the c++ compiler + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + if simulator then + as:add({name = "clang", cross = cross}) + else + as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) + end + + -- init the linker + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add({name = "ar", cross = cross}) + + -- init the static library extractor + ex:add({name = "ar", cross = cross}) + + -- init the symbols stripper + strip:add({name = "strip", cross = cross}) + + -- init the symbols generator + dsymutil:add({name = "dsymutil", cross = cross}) + + -- init the objc compiler + mm:add({name = "clang", cross = cross}) + + -- init the objc++ compiler + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + + -- init the swift compiler and linker + sc:add({name = "swiftc", cross = cross}) + sc_ld:add({name = "swiftc", cross = cross}) + sc_sh:add({name = "swiftc", cross = cross}) + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("watchos.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + check_arch(config, "armv7k") + + -- check xcode + check_xcode(config) + end +end + diff --git a/xmake/platforms/watchos/config.lua b/xmake/platforms/watchos/config.lua deleted file mode 100644 index f16878b2e..000000000 --- a/xmake/platforms/watchos/config.lua +++ /dev/null @@ -1,124 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_xcode") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init architecture - local arch = config.get("arch") - local simulator = (arch == "i386") - - -- init cross - local cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local dsymutil = toolchain("the symbols generator") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local sc = toolchain("the swift compiler") - local sc_ld = toolchain("the swift linker") - local sc_sh = toolchain("the swift shared library linker") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} - - -- init the c compiler - cc:add({name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - if simulator then - as:add({name = "clang", cross = cross}) - else - as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) - end - - -- init the linker - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add({name = "ar", cross = cross}) - - -- init the static library extractor - ex:add({name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add({name = "strip", cross = cross}) - - -- init the symbols generator - dsymutil:add({name = "dsymutil", cross = cross}) - - -- init the objc compiler - mm:add({name = "clang", cross = cross}) - - -- init the objc++ compiler - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - - -- init the swift compiler and linker - sc:add({name = "swiftc", cross = cross}) - sc_ld:add({name = "swiftc", cross = cross}) - sc_sh:add({name = "swiftc", cross = cross}) - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("watchos.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "armv7k") - - -- check xcode - check_xcode(config) - end -end - diff --git a/xmake/platforms/watchos/global.lua b/xmake/platforms/watchos/global.lua deleted file mode 100644 index f625eb103..000000000 --- a/xmake/platforms/watchos/global.lua +++ /dev/null @@ -1,36 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- imports -import("core.base.global") -import("private.platform.check_xcode") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end - - -- check xcode - check_xcode(global, true) -end - diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua index 5c2e2a731..1311c47ba 100644 --- a/xmake/platforms/watchos/xmake.lua +++ b/xmake/platforms/watchos/xmake.lua @@ -33,11 +33,8 @@ platform("watchos") -- set formats set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dylib", symbol = "$(name).dSYM"} - -- on check project configuration - on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/windows/check.lua b/xmake/platforms/windows/check.lua new file mode 100644 index 000000000..55027ff6a --- /dev/null +++ b/xmake/platforms/windows/check.lua @@ -0,0 +1,139 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("core.platform.environment") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_vstudio") +import("private.platform.check_toolchain") + +-- get toolchains +function _toolchains() + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local mrc = toolchain("the resource compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local as = toolchain("the assember") + local gc = toolchain("the golang compiler") + local gc_ld = toolchain("the golang linker") + local gc_ar = toolchain("the golang static library archiver") + local dc = toolchain("the dlang compiler") + local dc_ld = toolchain("the dlang linker") + local dc_sh = toolchain("the dlang shared library linker") + local dc_ar = toolchain("the dlang static library archiver") + local rc = toolchain("the rust compiler") + local rc_ld = toolchain("the rust linker") + local rc_sh = toolchain("the rust shared library linker") + local rc_ar = toolchain("the rust static library archiver") + local cu = toolchain("the cuda compiler") + local cu_ld = toolchain("the cuda linker") + local toolchains = {cc = cc, cxx = cxx, mrc = mrc, as = as, ld = ld, sh = sh, ar = ar, ex = ex, + gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, + dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, + cu = cu, ["cu-ld"] = cu_ld} + + -- init the c compiler + cc:add("cl.exe") + + -- init the c++ compiler + cxx:add("cl.exe") + + -- init the resource compiler + mrc:add("rc.exe") + + -- init the assember + local arch = config.get("arch") + if arch and arch:find("64") then + as:add("ml64.exe") + else + as:add("ml.exe") + end + + -- init the linker + ld:add("link.exe") + + -- init the shared library linker + sh:add("link.exe -dll") + + -- init the static library archiver + ar:add("link.exe -lib") + + -- init the static library extractor + ex:add("lib.exe") + + -- init the golang compiler and linker + gc:add("$(env GC)", "go", "gccgo") + gc_ld:add("$(env GC)", "go", "gccgo") + gc_ar:add("$(env GC)", "go", "gccgo") + + -- init the dlang compiler and linker + dc:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") + + -- init the rust compiler and linker + rc:add("$(env RC)", "rustc") + rc_ld:add("$(env RC)", "rustc") + rc_sh:add("$(env RC)", "rustc") + rc_ar:add("$(env RC)", "rustc") + + -- init the cuda compiler and linker + cu:add("nvcc", "clang") + cu_ld:add("nvcc") + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("windows.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] + if toolchain then + environment.enter("toolchains") + check_toolchain(config, name, toolchain) + environment.leave("toolchains") + end + else + + -- check arch + check_arch(config) + + -- check vstudio + local cc = path.basename(config.get("cc") or "cl"):lower() + local cxx = path.basename(config.get("cxx") or "cl"):lower() + local mrc = path.basename(config.get("mrc") or "rc"):lower() + if cc == "cl" or cxx == "cl" or mrc == "rc" then + check_vstudio(config) + end + end +end + diff --git a/xmake/platforms/windows/config.lua b/xmake/platforms/windows/config.lua deleted file mode 100644 index c74205efe..000000000 --- a/xmake/platforms/windows/config.lua +++ /dev/null @@ -1,139 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("core.platform.environment") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_vstudio") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local mrc = toolchain("the resource compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local toolchains = {cc = cc, cxx = cxx, mrc = mrc, as = as, ld = ld, sh = sh, ar = ar, ex = ex, - gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, - dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld} - - -- init the c compiler - cc:add("cl.exe") - - -- init the c++ compiler - cxx:add("cl.exe") - - -- init the resource compiler - mrc:add("rc.exe") - - -- init the assember - local arch = config.get("arch") - if arch and arch:find("64") then - as:add("ml64.exe") - else - as:add("ml.exe") - end - - -- init the linker - ld:add("link.exe") - - -- init the shared library linker - sh:add("link.exe -dll") - - -- init the static library archiver - ar:add("link.exe -lib") - - -- init the static library extractor - ex:add("lib.exe") - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang") - cu_ld:add("nvcc") - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("windows.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - environment.enter("toolchains") - check_toolchain(config, name, toolchain) - environment.leave("toolchains") - end - else - - -- check arch - check_arch(config) - - -- check vstudio - local cc = path.basename(config.get("cc") or "cl"):lower() - local cxx = path.basename(config.get("cxx") or "cl"):lower() - local mrc = path.basename(config.get("mrc") or "rc"):lower() - if cc == "cl" or cxx == "cl" or mrc == "rc" then - check_vstudio(config) - end - end -end - diff --git a/xmake/platforms/windows/global.lua b/xmake/platforms/windows/global.lua deleted file mode 100644 index 9ef580bef..000000000 --- a/xmake/platforms/windows/global.lua +++ /dev/null @@ -1,49 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- imports -import("core.base.global") -import("private.platform.check_arch") -import("private.platform.check_vstudio") - --- clean temporary global configs -function _clean_global() - global.set("arch", nil) - global.set("__vcvarsall", nil) -end - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end - - -- check arch - check_arch(global) - - -- check vstudio - check_vstudio(global, {try = true}) - - -- clean temporary global configs - _clean_global() -end - diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index 43c7acccb..3bc2bf0cf 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -33,11 +33,8 @@ platform("windows") -- set formats set_formats {static = "$(name).lib", object = "$(name).obj", shared = "$(name).dll", binary = "$(name).exe", symbol = "$(name).pdb"} - -- on check project configuration - on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on environment enter on_environment_enter("environment.enter") diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index c10fe48d9..0e34232a6 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -25,4 +25,5 @@ import("private.platform.check_xcode") -- main entry function main(toolchain) check_xcode(config, true) + return true end -- cgit v1.3.1 From 8405406c0519338e1cfb75746e4b31ca5b6c3cc7 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:41:04 +0800 Subject: improve to check xcode toolchain --- xmake/platforms/macosx/check.lua | 1 + xmake/toolchains/xcode/check.lua | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'xmake/toolchains/xcode') diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua index ff552ad6b..2158dc25a 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -155,6 +155,7 @@ function main(platform) table.remove(toolchains, idx) end end + assert(#toolchains > 0, "toolchains not found!") --[[ -- only check the given config name? diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index 0e34232a6..925db3870 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -19,11 +19,33 @@ -- -- imports +import("core.base.option") import("core.project.config") -import("private.platform.check_xcode") +import("detect.sdks.find_xcode") -- main entry function main(toolchain) - check_xcode(config, true) + + -- find xcode + local xcode = find_xcode(config.get("xcode"), {force = not optional, verbose = true, plat = config.get("plat"), arch = config.get("arch")}) + if xcode then + config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) + else + return false + end + + -- save target minver + local xcode_sdkver = config.get("xcode_sdkver") + local target_minver = config.get("target_minver") + if xcode_sdkver and not target_minver then + target_minver = xcode_sdkver + if is_plat("macosx") then + local macos_ver = macos.version() + if macos_ver then + target_minver = macos_ver:major() .. "." .. macos_ver:minor() + end + end + config.set("target_minver", target_minver) + end return true end -- cgit v1.3.1 From 3537041f82f3c12f6c9312b3325550d1f18eb94e Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:51:09 +0800 Subject: add platform.toolconfig --- xmake/core/package/package.lua | 2 +- xmake/core/platform/platform.lua | 40 ++++++++++++++++++++++ .../modules/import/core/platform/platform.lua | 7 +++- xmake/core/tool/builder.lua | 2 +- xmake/core/tool/compiler.lua | 6 ++-- xmake/core/tool/linker.lua | 8 ++--- .../package/manager/conan/install_package.lua | 2 +- .../modules/private/action/trybuild/autotools.lua | 2 +- xmake/toolchains/xcode/load.lua | 2 +- 9 files changed, 58 insertions(+), 13 deletions(-) (limited to 'xmake/toolchains/xcode') diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index b69b4f094..d47f0fc4e 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -492,7 +492,7 @@ function _instance:build_envs(lazy_loading) setmetatable(build_envs, { __index = function (tbl, key) local value = config.get(key) if value == nil then - value = platform.get(key, self:plat()) + value = platform.toolconfig(key, self:plat()) end if value == nil then value = platform.tool(key, self:plat()) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 677e36906..1bb76db92 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -141,6 +141,36 @@ function _instance:tool(toolkind) end end +-- get tool configuration from the toolchains +function _instance:toolconfig(name) + + -- init tool configs + local toolconfigs = self._TOOLCONFIGS + if not toolconfigs then + toolconfigs = {} + self._TOOLCONFIGS = toolconfigs + end + + -- get configuration + local toolconfig = toolconfigs[name] + if toolconfig == nil then + + -- get them from all toolchains + for _, toolchain_inst in ipairs(self:toolchains()) do + local values = toolchain_inst:get(name) + if values then + toolconfig = toolconfig or {} + table.join2(toolconfig, values) + end + end + + -- cache it + toolconfig = toolconfig or false + toolconfigs[name] = toolconfig + end + return toolconfig or nil +end + -- get the platform script function _instance:script(name) return self._INFO:get(name) @@ -388,6 +418,16 @@ function platform.tool(toolkind, plat) return program, toolname end +-- get the given tool configuration +function platform.toolconfig(name, plat) + local instance, errors = platform.load(plat) + if instance then + return instance:toolconfig(name) + else + os.raise(errors) + end +end + -- get the all platforms function platform.plats() diff --git a/xmake/core/sandbox/modules/import/core/platform/platform.lua b/xmake/core/sandbox/modules/import/core/platform/platform.lua index 2961cb67f..6919010e6 100644 --- a/xmake/core/sandbox/modules/import/core/platform/platform.lua +++ b/xmake/core/sandbox/modules/import/core/platform/platform.lua @@ -50,7 +50,7 @@ function sandbox_core_platform.archs(plat) return platform.archs(plat) end --- get the current platform configure +-- get the current platform configuration function sandbox_core_platform.get(name, plat) return platform.get(name, plat) end @@ -63,5 +63,10 @@ function sandbox_core_platform.tool(toolkind) return platform.tool(toolkind) end +-- get the current platform tool configuration +function sandbox_core_platform.toolconfig(name, plat) + return platform.toolconfig(name, plat) +end + -- return module return sandbox_core_platform diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 3c77247c1..042aa5001 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -263,7 +263,7 @@ function builder:_add_flags_from_language(flags, target, getters) end return values end - , platform = platform.get + , platform = platform.toolconfig , target = function (name) -- only for target diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 0c0a1375a..27c81879c 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -47,8 +47,8 @@ function compiler:_add_flags_from_platform(flags, targetkind) if targetkind then local toolname = self:name() for _, flagkind in ipairs(self:_flagkinds()) do - local toolflags = platform.get(targetkind .. '.' .. toolname .. '.' .. flagkind) - table.join2(flags, toolflags or platform.get(targetkind .. '.' .. flagkind)) + local toolflags = platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind) + table.join2(flags, toolflags or platform.toolconfig(targetkind .. '.' .. flagkind)) end end end @@ -140,7 +140,7 @@ function compiler.load(sourcekind, target) for _, flagkind in ipairs(instance:_flagkinds()) do -- add flags for platform, e.g. gcc.cxflags or cxflags - compiler_tool:add(flagkind, platform.get(toolname .. '.' .. flagkind) or platform.get(flagkind)) + compiler_tool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind)) end -- ok diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index d5a410b31..b3f91a904 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -44,8 +44,8 @@ function linker:_add_flags_from_platform(flags, targetkind) local toolkind = self:kind() local toolname = self:name() for _, flagkind in ipairs(self:_flagkinds()) do - local toolflags = platform.get(targetkind .. '.' .. toolname .. '.' .. toolkind .. 'flags') or platform.get(targetkind .. '.' .. toolname .. '.' .. flagkind) - table.join2(flags, toolflags or platform.get(targetkind .. '.' .. toolkind .. 'flags') or platform.get(targetkind .. '.' .. flagkind)) + local toolflags = platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. toolkind .. 'flags') or platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind) + table.join2(flags, toolflags or platform.toolconfig(targetkind .. '.' .. toolkind .. 'flags') or platform.toolconfig(targetkind .. '.' .. flagkind)) end end end @@ -186,8 +186,8 @@ function linker.load(targetkind, sourcekinds, target) for _, flagkind in ipairs(instance:_flagkinds()) do -- add special lanugage flags first, e.g. go.gcldflags or gcc.ldflags or gcldflags or ldflags - linkertool:add(toolkind .. 'flags', platform.get(toolname .. '.' .. toolkind .. 'flags') or platform.get(toolkind .. 'flags')) - linkertool:add(flagkind, platform.get(toolname .. '.' .. flagkind) or platform.get(flagkind)) + linkertool:add(toolkind .. 'flags', platform.toolconfig(toolname .. '.' .. toolkind .. 'flags') or platform.toolconfig(toolkind .. 'flags')) + linkertool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind)) end -- ok diff --git a/xmake/modules/package/manager/conan/install_package.lua b/xmake/modules/package/manager/conan/install_package.lua index a74cd8817..201c50841 100644 --- a/xmake/modules/package/manager/conan/install_package.lua +++ b/xmake/modules/package/manager/conan/install_package.lua @@ -30,7 +30,7 @@ import("net.fasturl") function _conan_get_build_env(name, plat) local value = config.get(name) if value == nil then - value = platform.get(name, plat) + value = platform.toolconfig(name, plat) end if value == nil then value = platform.tool(name, plat) diff --git a/xmake/modules/private/action/trybuild/autotools.lua b/xmake/modules/private/action/trybuild/autotools.lua index 5c08c6ae0..bf4c30709 100644 --- a/xmake/modules/private/action/trybuild/autotools.lua +++ b/xmake/modules/private/action/trybuild/autotools.lua @@ -39,7 +39,7 @@ end function _get_buildenv(key) local value = config.get(key) if value == nil then - value = platform.get(key, config.plat()) + value = platform.toolconfig(key, config.plat()) end if value == nil then value = platform.tool(key, config.plat()) diff --git a/xmake/toolchains/xcode/load.lua b/xmake/toolchains/xcode/load.lua index 96d459414..4d4165a7e 100644 --- a/xmake/toolchains/xcode/load.lua +++ b/xmake/toolchains/xcode/load.lua @@ -33,7 +33,7 @@ function main(toolchain) local xcode_sdkver = config.get("xcode_sdkver") local xcode_sdkdir = nil if xcode_dir and xcode_sdkver then - xcode_sdkdir = xcode_dir .. "/Contents/Developer/toolchains/MacOSX.toolchain/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" + xcode_sdkdir = xcode_dir .. "/Contents/Developer/platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" end -- init flags for c/c++ -- cgit v1.3.1 From 9aaf4d1f861acb3167ce101ddbf12a5f57b0392a Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:56:42 +0800 Subject: support iphoneos for xcode toolchain --- xmake/platforms/iphoneos/check.lua | 27 +++++---- xmake/platforms/iphoneos/load.lua | 62 --------------------- xmake/platforms/iphoneos/xmake.lua | 4 +- xmake/platforms/macosx/check.lua | 21 ++----- xmake/platforms/macosx/load.lua | 94 -------------------------------- xmake/platforms/macosx/xmake.lua | 3 - xmake/toolchains/xcode/load.lua | 94 -------------------------------- xmake/toolchains/xcode/load_iphoneos.lua | 62 +++++++++++++++++++++ xmake/toolchains/xcode/load_macosx.lua | 94 ++++++++++++++++++++++++++++++++ xmake/toolchains/xcode/xmake.lua | 50 +++++++++++------ 10 files changed, 208 insertions(+), 303 deletions(-) delete mode 100644 xmake/platforms/iphoneos/load.lua delete mode 100644 xmake/platforms/macosx/load.lua delete mode 100644 xmake/toolchains/xcode/load.lua create mode 100644 xmake/toolchains/xcode/load_iphoneos.lua create mode 100644 xmake/toolchains/xcode/load_macosx.lua (limited to 'xmake/toolchains/xcode') diff --git a/xmake/platforms/iphoneos/check.lua b/xmake/platforms/iphoneos/check.lua index 94a3a9ae9..1a7fbd4e3 100644 --- a/xmake/platforms/iphoneos/check.lua +++ b/xmake/platforms/iphoneos/check.lua @@ -20,9 +20,11 @@ -- imports import("core.project.config") +import("private.platform.check_arch") + +--[[ import("core.base.singleton") import("private.platform.toolchain") -import("private.platform.check_arch") import("private.platform.check_xcode") import("private.platform.check_toolchain") @@ -105,24 +107,21 @@ function _toolchains() sc_sh:add({name = "swiftc", cross = cross}) return toolchains -end +end]] -- check it function main(platform, name) - -- only check the given config name? - if name then - local toolchain = singleton.get("iphoneos.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else + -- check arch + check_arch(config, "arm64") - -- check arch - check_arch(config, "arm64") - - -- check xcode - check_xcode(config) + -- check toolchains + local toolchains = platform:toolchains() + for idx, toolchain in irpairs(toolchains) do + if not toolchain:check() then + table.remove(toolchains, idx) + end end + assert(#toolchains > 0, "toolchains not found!") end diff --git a/xmake/platforms/iphoneos/load.lua b/xmake/platforms/iphoneos/load.lua deleted file mode 100644 index 7d54e24be..000000000 --- a/xmake/platforms/iphoneos/load.lua +++ /dev/null @@ -1,62 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file load.lua --- - --- imports -import("core.project.config") - --- load it -function main(platform) - - -- init architecture - local arch = config.get("arch") or "arm64" - local simulator = (arch == "i386" or arch == "x86_64") - - -- init platform name - local platname = simulator and "iPhoneSimulator" or "iPhoneOS" - - -- init target minimal version - local target_minver = config.get("target_minver") - if target_minver and tonumber(target_minver) > 10 and (arch == "armv7" or arch == "armv7s" or arch == "i386") then - target_minver = "10" -- iOS 10 is the maximum deployment target for 32-bit targets - end - local target_minver_flags = (simulator and "-mios-simulator-version-min=" or "-miphoneos-version-min=") .. target_minver - - -- init the xcode sdk directory - local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver") - local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) - - -- init flags for c/c++ - platform:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for objc/c++ - platform:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for asm - platform:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for swift (with platform:add("ldflags and platform:add("shflags) - platform:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) -end - diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index 6d2af82ae..ff5ba2204 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -36,8 +36,8 @@ platform("iphoneos") -- on check on_check("check") - -- on load - on_load("load") + -- set toolchains + set_toolchains("xcode") -- set menu set_menu { diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua index 2158dc25a..1166c3205 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -20,11 +20,11 @@ -- imports import("core.project.config") +import("private.platform.check_arch") --[[ import("core.base.singleton") import("private.platform.toolchain") -import("private.platform.check_arch") import("private.platform.check_xcode") import("private.platform.check_toolchain") @@ -148,6 +148,9 @@ end]] -- check it function main(platform) + -- check arch + check_arch(config) + -- check toolchains local toolchains = platform:toolchains() for idx, toolchain in irpairs(toolchains) do @@ -156,21 +159,5 @@ function main(platform) end end assert(#toolchains > 0, "toolchains not found!") - - --[[ - -- only check the given config name? - if name then - local toolchain = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config) - - -- check xcode - check_xcode(config, true) - end]] end diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua deleted file mode 100644 index 6d2547a75..000000000 --- a/xmake/platforms/macosx/load.lua +++ /dev/null @@ -1,94 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file load.lua --- - --- imports -import("core.project.config") - --- load it -function main(platform) - - -- init flags for architecture - local arch = config.get("arch") or os.arch() - local target_minver = config.get("target_minver") - - -- init flags for the xcode sdk directory - local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver") - local xcode_sdkdir = nil - if xcode_dir and xcode_sdkver then - xcode_sdkdir = xcode_dir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" - end - - -- init flags for c/c++ - platform:add("cxflags", "-arch " .. arch) - platform:add("ldflags", "-arch " .. arch) - if target_minver then - platform:add("cxflags", "-mmacosx-version-min=" .. target_minver) - platform:add("mxflags", "-mmacosx-version-min=" .. target_minver) - platform:add("ldflags", "-mmacosx-version-min=" .. target_minver) - end - if xcode_sdkdir then - platform:add("cxflags", "-isysroot " .. xcode_sdkdir) - platform:add("ldflags", "-isysroot " .. xcode_sdkdir) - else - platform:add("cxflags", "-I/usr/local/include") - platform:add("cxflags", "-I/usr/include") - platform:add("ldflags", "-L/usr/local/lib") - platform:add("ldflags", "-L/usr/lib") - end - platform:add("ldflags", "-stdlib=libc++") - platform:add("ldflags", "-lz") - platform:add("shflags", platform:get("ldflags")) - - -- init flags for objc/c++ (with ldflags and shflags) - platform:add("mxflags", "-arch " .. arch) - if xcode_sdkdir then - platform:add("mxflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for asm - platform:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") - platform:set("fasm.asflags", "") - platform:add("asflags", "-arch " .. arch) - if xcode_sdkdir then - platform:add("asflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for swift - if target_minver and xcode_sdkdir then - platform:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - end - - -- init flags for golang - platform:set("gcldflags", "") - - -- init flags for dlang - local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - platform:add("dcflags", dc_archs[arch] or "") - platform:add("dcshflags", dc_archs[arch] or "") - platform:add("dcldflags", dc_archs[arch] or "" ) - - -- init flags for rust - platform:set("rcshflags", "") - platform:set("rcldflags", "") -end - diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 512499c7c..9fd14a82f 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -39,9 +39,6 @@ platform("macosx") -- on check on_check("check") - -- on load - on_load("load") - -- set toolchains -- set_toolchains("custom", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") set_toolchains("xcode") diff --git a/xmake/toolchains/xcode/load.lua b/xmake/toolchains/xcode/load.lua deleted file mode 100644 index 4d4165a7e..000000000 --- a/xmake/toolchains/xcode/load.lua +++ /dev/null @@ -1,94 +0,0 @@ ---!A cross-toolchain 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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file load.lua --- - --- imports -import("core.project.config") - --- main entry -function main(toolchain) - - -- init flags for architecture - local arch = config.get("arch") or os.arch() - local target_minver = config.get("target_minver") - - -- init flags for the xcode sdk directory - local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver") - local xcode_sdkdir = nil - if xcode_dir and xcode_sdkver then - xcode_sdkdir = xcode_dir .. "/Contents/Developer/platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" - end - - -- init flags for c/c++ - toolchain:add("cxflags", "-arch " .. arch) - toolchain:add("ldflags", "-arch " .. arch) - if target_minver then - toolchain:add("cxflags", "-mmacosx-version-min=" .. target_minver) - toolchain:add("mxflags", "-mmacosx-version-min=" .. target_minver) - toolchain:add("ldflags", "-mmacosx-version-min=" .. target_minver) - end - if xcode_sdkdir then - toolchain:add("cxflags", "-isysroot " .. xcode_sdkdir) - toolchain:add("ldflags", "-isysroot " .. xcode_sdkdir) - else - toolchain:add("cxflags", "-I/usr/local/include") - toolchain:add("cxflags", "-I/usr/include") - toolchain:add("ldflags", "-L/usr/local/lib") - toolchain:add("ldflags", "-L/usr/lib") - end - toolchain:add("ldflags", "-stdlib=libc++") - toolchain:add("ldflags", "-lz") - toolchain:add("shflags", toolchain:get("ldflags")) - - -- init flags for objc/c++ (with ldflags and shflags) - toolchain:add("mxflags", "-arch " .. arch) - if xcode_sdkdir then - toolchain:add("mxflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for asm --- toolchain:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") --- toolchain:set("fasm.asflags", "") - toolchain:add("asflags", "-arch " .. arch) - if xcode_sdkdir then - toolchain:add("asflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for swift - if target_minver and xcode_sdkdir then - toolchain:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - toolchain:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - toolchain:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - end - - --[[ - -- init flags for golang - toolchain:set("gcldflags", "") - - -- init flags for dlang - local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - toolchain:add("dcflags", dc_archs[arch] or "") - toolchain:add("dcshflags", dc_archs[arch] or "") - toolchain:add("dcldflags", dc_archs[arch] or "" ) - - -- init flags for rust - toolchain:set("rcshflags", "") - toolchain:set("rcldflags", "")]] -end diff --git a/xmake/toolchains/xcode/load_iphoneos.lua b/xmake/toolchains/xcode/load_iphoneos.lua new file mode 100644 index 000000000..3aeb78672 --- /dev/null +++ b/xmake/toolchains/xcode/load_iphoneos.lua @@ -0,0 +1,62 @@ +--!A cross-toolchain 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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load_iphoneos.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init architecture + local arch = config.get("arch") or "arm64" + local simulator = (arch == "i386" or arch == "x86_64") + + -- init platform name + local platname = simulator and "iPhoneSimulator" or "iPhoneOS" + + -- init target minimal version + local target_minver = config.get("target_minver") + if target_minver and tonumber(target_minver) > 10 and (arch == "armv7" or arch == "armv7s" or arch == "i386") then + target_minver = "10" -- iOS 10 is the maximum deployment target for 32-bit targets + end + local target_minver_flags = (simulator and "-mios-simulator-version-min=" or "-miphoneos-version-min=") .. target_minver + + -- init the xcode sdk directory + local xcode_dir = config.get("xcode") + local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) + + -- init flags for c/c++ + toolchain:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for objc/c++ + toolchain:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for asm + toolchain:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags) + toolchain:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) +end + diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua new file mode 100644 index 000000000..b735b8d77 --- /dev/null +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -0,0 +1,94 @@ +--!A cross-toolchain 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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load_macosx.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init flags for architecture + local arch = config.get("arch") or os.arch() + local target_minver = config.get("target_minver") + + -- init flags for the xcode sdk directory + local xcode_dir = config.get("xcode") + local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkdir = nil + if xcode_dir and xcode_sdkver then + xcode_sdkdir = xcode_dir .. "/Contents/Developer/platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" + end + + -- init flags for c/c++ + toolchain:add("cxflags", "-arch " .. arch) + toolchain:add("ldflags", "-arch " .. arch) + if target_minver then + toolchain:add("cxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("mxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("ldflags", "-mmacosx-version-min=" .. target_minver) + end + if xcode_sdkdir then + toolchain:add("cxflags", "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-isysroot " .. xcode_sdkdir) + else + toolchain:add("cxflags", "-I/usr/local/include") + toolchain:add("cxflags", "-I/usr/include") + toolchain:add("ldflags", "-L/usr/local/lib") + toolchain:add("ldflags", "-L/usr/lib") + end + toolchain:add("ldflags", "-stdlib=libc++") + toolchain:add("ldflags", "-lz") + toolchain:add("shflags", toolchain:get("ldflags")) + + -- init flags for objc/c++ (with ldflags and shflags) + toolchain:add("mxflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("mxflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for asm +-- toolchain:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") +-- toolchain:set("fasm.asflags", "") + toolchain:add("asflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("asflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for swift + if target_minver and xcode_sdkdir then + toolchain:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + end + + --[[ + -- init flags for golang + toolchain:set("gcldflags", "") + + -- init flags for dlang + local dc_archs = { i386 = "-m32", x86_64 = "-m64" } + toolchain:add("dcflags", dc_archs[arch] or "") + toolchain:add("dcshflags", dc_archs[arch] or "") + toolchain:add("dcldflags", dc_archs[arch] or "" ) + + -- init flags for rust + toolchain:set("rcshflags", "") + toolchain:set("rcldflags", "")]] +end diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index d9b1d9944..4f45f6d60 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -21,24 +21,40 @@ -- define toolchain toolchain("xcode") - -- set toolsets - set_toolsets("cc", "xcrun -sdk macosx clang") - set_toolsets("cxx", "xcrun -sdk macosx clang", "xcrun -sdk macosx clang++") - set_toolsets("as", "xcrun -sdk macosx clang") - set_toolsets("ld", "xcrun -sdk macosx clang++", "xcrun -sdk macosx clang") - set_toolsets("sh", "xcrun -sdk macosx clang++", "xcrun -sdk macosx clang") - set_toolsets("ar", "xcrun -sdk macosx ar") - set_toolsets("ex", "xcrun -sdk macosx ar") - set_toolsets("strip", "xcrun -sdk macosx strip") - set_toolsets("dsymutil", "xcrun -sdk macosx dsymutil", "dsymutil") - set_toolsets("mm", "xcrun -sdk macosx clang") - set_toolsets("mxx", "xcrun -sdk macosx clang", "xcrun -sdk macosx clang++") - set_toolsets("sc", "xcrun -sdk macosx swiftc", "swiftc") - set_toolsets("scld", "xcrun -sdk macosx swiftc", "swiftc") - set_toolsets("scsh", "xcrun -sdk macosx swiftc", "swiftc") - -- check toolchain on_check("check") -- load toolchain - on_load("load") + on_load(function (toolchain) + + -- get cross + local cross + if is_plat("macosx") then + cross = "xcrun -sdk macosx " + elseif is_plat("iphoneos") then + local arch = get_config("arch") or os.arch() + local simulator = (arch == "i386" or arch == "x86_64") + cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " + else + raise("unknown platform for xcode!") + end + + -- set toolsets + toolchain:set("toolsets", "cc", cross .. "clang") + toolchain:set("toolsets", "cxx", cross .. "clang", cross .. "clang++") + toolchain:set("toolsets", "as", cross .. "clang") + toolchain:set("toolsets", "ld", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "sh", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "ar", cross .. "ar") + toolchain:set("toolsets", "ex", cross .. "ar") + toolchain:set("toolsets", "strip", cross .. "strip") + toolchain:set("toolsets", "dsymutil", cross .. "dsymutil", "dsymutil") + toolchain:set("toolsets", "mm", cross .. "clang") + toolchain:set("toolsets", "mxx", cross .. "clang", cross .. "clang++") + toolchain:set("toolsets", "sc", cross .. "swiftc", "swiftc") + toolchain:set("toolsets", "scld", cross .. "swiftc", "swiftc") + toolchain:set("toolsets", "scsh", cross .. "swiftc", "swiftc") + + -- load configurations + import("load_" .. get_config("plat"))(toolchain) + end) -- cgit v1.3.1 From 93db858087c1bdeba2585f2de409e53a8d8e8fbd Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:57:44 +0800 Subject: support watchos for xcode toolchain --- xmake/platforms/watchos/load.lua | 59 --------------------------------- xmake/platforms/watchos/xmake.lua | 4 +-- xmake/toolchains/xcode/load_macosx.lua | 16 --------- xmake/toolchains/xcode/load_watchos.lua | 59 +++++++++++++++++++++++++++++++++ xmake/toolchains/xcode/xmake.lua | 4 +++ 5 files changed, 65 insertions(+), 77 deletions(-) delete mode 100644 xmake/platforms/watchos/load.lua create mode 100644 xmake/toolchains/xcode/load_watchos.lua (limited to 'xmake/toolchains/xcode') diff --git a/xmake/platforms/watchos/load.lua b/xmake/platforms/watchos/load.lua deleted file mode 100644 index 2e0204358..000000000 --- a/xmake/platforms/watchos/load.lua +++ /dev/null @@ -1,59 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file load.lua --- - --- imports -import("core.project.config") - --- load it -function main(platform) - - -- init architecture - local arch = config.get("arch") - local simulator = arch == "i386" - - -- init platform name - local platname = simulator and "WatchSimulator" or "WatchOS" - - -- init target minimal version - local target_minver = config.get("target_minver") - local target_minver_flags = (simulator and "-mwatchos-simulator-version-min=" or "-mwatchos-version-min=") .. target_minver - - -- init the xcode sdk directory - local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver") - local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) - - -- init flags for c/c++ - platform:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for objc/c++ - platform:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for asm - platform:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for swift (with platform:add("ldflags and platform:add("shflags) - platform:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) -end - diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua index 1311c47ba..1356af3ab 100644 --- a/xmake/platforms/watchos/xmake.lua +++ b/xmake/platforms/watchos/xmake.lua @@ -36,8 +36,8 @@ platform("watchos") -- on check on_check("check") - -- on load - on_load("load") + -- set toolchains + set_toolchains("xcode") -- set menu set_menu { diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua index b735b8d77..5cebd96bb 100644 --- a/xmake/toolchains/xcode/load_macosx.lua +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -64,8 +64,6 @@ function main(toolchain) end -- init flags for asm --- toolchain:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") --- toolchain:set("fasm.asflags", "") toolchain:add("asflags", "-arch " .. arch) if xcode_sdkdir then toolchain:add("asflags", "-isysroot " .. xcode_sdkdir) @@ -77,18 +75,4 @@ function main(toolchain) toolchain:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) toolchain:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) end - - --[[ - -- init flags for golang - toolchain:set("gcldflags", "") - - -- init flags for dlang - local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - toolchain:add("dcflags", dc_archs[arch] or "") - toolchain:add("dcshflags", dc_archs[arch] or "") - toolchain:add("dcldflags", dc_archs[arch] or "" ) - - -- init flags for rust - toolchain:set("rcshflags", "") - toolchain:set("rcldflags", "")]] end diff --git a/xmake/toolchains/xcode/load_watchos.lua b/xmake/toolchains/xcode/load_watchos.lua new file mode 100644 index 000000000..5048f4bb7 --- /dev/null +++ b/xmake/toolchains/xcode/load_watchos.lua @@ -0,0 +1,59 @@ +--!A cross-toolchain 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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load_watchos.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init architecture + local arch = config.get("arch") + local simulator = arch == "i386" + + -- init platform name + local platname = simulator and "WatchSimulator" or "WatchOS" + + -- init target minimal version + local target_minver = config.get("target_minver") + local target_minver_flags = (simulator and "-mwatchos-simulator-version-min=" or "-mwatchos-version-min=") .. target_minver + + -- init the xcode sdk directory + local xcode_dir = config.get("xcode") + local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) + + -- init flags for c/c++ + toolchain:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for objc/c++ + toolchain:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for asm + toolchain:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags) + toolchain:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) +end + diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index 4f45f6d60..f20fabe1f 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -35,6 +35,10 @@ toolchain("xcode") local arch = get_config("arch") or os.arch() local simulator = (arch == "i386" or arch == "x86_64") cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " + elseif is_plat("watchos") then + local arch = get_config("arch") or os.arch() + local simulator = (arch == "i386") + cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " else raise("unknown platform for xcode!") end -- cgit v1.3.1 From fb7bc83c06972744d6f2c5139b5bc079e06b7b11 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:59:45 +0800 Subject: add as to xcode toolchain --- xmake/toolchains/xcode/xmake.lua | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'xmake/toolchains/xcode') diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index f20fabe1f..aed4a44e9 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -28,16 +28,16 @@ toolchain("xcode") on_load(function (toolchain) -- get cross - local cross + local cross, arch, simulator if is_plat("macosx") then cross = "xcrun -sdk macosx " elseif is_plat("iphoneos") then - local arch = get_config("arch") or os.arch() - local simulator = (arch == "i386" or arch == "x86_64") + arch = get_config("arch") or os.arch() + simulator = (arch == "i386" or arch == "x86_64") cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " elseif is_plat("watchos") then - local arch = get_config("arch") or os.arch() - local simulator = (arch == "i386") + arch = get_config("arch") or os.arch() + simulator = (arch == "i386") cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " else raise("unknown platform for xcode!") @@ -46,7 +46,6 @@ toolchain("xcode") -- set toolsets toolchain:set("toolsets", "cc", cross .. "clang") toolchain:set("toolsets", "cxx", cross .. "clang", cross .. "clang++") - toolchain:set("toolsets", "as", cross .. "clang") toolchain:set("toolsets", "ld", cross .. "clang++", cross .. "clang") toolchain:set("toolsets", "sh", cross .. "clang++", cross .. "clang") toolchain:set("toolsets", "ar", cross .. "ar") @@ -58,6 +57,16 @@ toolchain("xcode") toolchain:set("toolsets", "sc", cross .. "swiftc", "swiftc") toolchain:set("toolsets", "scld", cross .. "swiftc", "swiftc") toolchain:set("toolsets", "scsh", cross .. "swiftc", "swiftc") + if arch then + toolchain:set("toolsets", "cpp", cross .. "clang -arch " .. arch .. " -E") + end + if is_plat("macosx") then + toolchain:set("toolsets", "as", cross .. "clang") + elseif simulator then + toolchain:set("toolsets", "as", cross .. "clang") + else + toolchain:set("toolsets", "as", path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross) .. "clang") + end -- load configurations import("load_" .. get_config("plat"))(toolchain) -- cgit v1.3.1 From a5a4b0ac5b9674ac00049cc1f4ff8f11d5268f6b Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 22:44:16 +0800 Subject: set standalone toolchain --- tests/projects/asm/nasm/src/main.S | 1 - xmake/actions/config/xmake.lua | 2 +- xmake/core/platform/platform.lua | 25 +++++++++++++++++-------- xmake/core/tool/toolchain.lua | 13 ++++++++++++- xmake/modules/detect/tools/find_fasm.lua | 1 + xmake/modules/detect/tools/find_nasm.lua | 1 + xmake/platforms/bsd/check.lua | 16 +++++----------- xmake/platforms/linux/check.lua | 16 +++++----------- xmake/platforms/macosx/check.lua | 16 +++++----------- xmake/toolchains/clang/xmake.lua | 3 +++ xmake/toolchains/cross/xmake.lua | 3 +++ xmake/toolchains/gcc/xmake.lua | 3 +++ xmake/toolchains/llvm/xmake.lua | 3 +++ xmake/toolchains/xcode/xmake.lua | 3 +++ 14 files changed, 62 insertions(+), 44 deletions(-) (limited to 'xmake/toolchains/xcode') diff --git a/tests/projects/asm/nasm/src/main.S b/tests/projects/asm/nasm/src/main.S index 5b3a93699..e96a8d2c9 100644 --- a/tests/projects/asm/nasm/src/main.S +++ b/tests/projects/asm/nasm/src/main.S @@ -1,6 +1,5 @@ global _main - section .text _main: diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 4953fc718..3b02846d1 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -156,7 +156,7 @@ task("config") , " - sdk/bin" , " - sdk/lib" , " - sdk/include" } - , {nil, "toolchain", "kv", nil, "The Cross Toolchain Name" + , {nil, "toolchain", "kv", nil, "The Toolchain Name" , "e.g." , " - llvm" } diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 1ca688636..328bcce75 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -107,19 +107,28 @@ end function _instance:toolchains() local toolchains = self._TOOLCHAINS if not toolchains then - local names = {} - if config.get("toolchain") then - table.insert(names, config.get("toolchain")) - elseif self._INFO:get("toolchains") then - table.join2(names, self._INFO:get("toolchains")) - end + + -- get the given toolchain toolchains = {} - for _, name in ipairs(names) do - local toolchain_inst, errors = toolchain.load(name, self:name()) + local toolchain_given = config.get("toolchain") + if toolchain_given then + local toolchain_inst, errors = toolchain.load(toolchain_given, self:name()) if not toolchain_inst then os.raise(errors) end table.insert(toolchains, toolchain_inst) + toolchain_given = toolchain_inst + end + + -- get the platform toolchains + if (not toolchain_given or not toolchain_given:standalone()) and self._INFO:get("toolchains") then + for _, name in ipairs(self._INFO:get("toolchains")) do + local toolchain_inst, errors = toolchain.load(name, self:name()) + if not toolchain_inst then + os.raise(errors) + end + table.insert(toolchains, toolchain_inst) + end end self._TOOLCHAINS = toolchains end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 78da9ea7f..f5d6ada4f 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -77,6 +77,16 @@ function _instance:get(name) return self._INFO:get(name) end +-- get toolchain kind +function _instance:kind() + return self._INFO:get("kind") +end + +-- is standalone toolchain? +function _instance:standalone() + return self:kind() == "standalone" +end + -- get the program and name of the given tool kind function _instance:tool(toolkind) local toolpathes = self:get("toolsets." .. toolkind) @@ -271,7 +281,8 @@ function toolchain._apis() { values = { - "toolchain.set_bindir" + "toolchain.set_kind" + , "toolchain.set_bindir" , "toolchain.set_sdkdir" } , keyvalues = diff --git a/xmake/modules/detect/tools/find_fasm.lua b/xmake/modules/detect/tools/find_fasm.lua index 5ebf9e699..0b555a406 100644 --- a/xmake/modules/detect/tools/find_fasm.lua +++ b/xmake/modules/detect/tools/find_fasm.lua @@ -39,6 +39,7 @@ function main(opt) -- init options opt = opt or {} + opt.norun = true -- find program local program = find_program(opt.program or "fasm", opt) diff --git a/xmake/modules/detect/tools/find_nasm.lua b/xmake/modules/detect/tools/find_nasm.lua index 40b710d2e..68936502e 100644 --- a/xmake/modules/detect/tools/find_nasm.lua +++ b/xmake/modules/detect/tools/find_nasm.lua @@ -39,6 +39,7 @@ function main(opt) -- init options opt = opt or {} + opt.check = "-v" -- find program local program = find_program(opt.program or "nasm", opt) diff --git a/xmake/platforms/bsd/check.lua b/xmake/platforms/bsd/check.lua index 3cd6b8980..71d2e555c 100644 --- a/xmake/platforms/bsd/check.lua +++ b/xmake/platforms/bsd/check.lua @@ -22,12 +22,6 @@ import("core.project.config") import("private.platform.check_arch") --- is basic toolchain? -function _is_basic_toolchain(toolchain) - local name = toolchain:name() - return name == "clang" or name == "gcc" -end - -- check it function main(platform) @@ -38,16 +32,16 @@ function main(platform) local toolchains = platform:toolchains() local idx = 1 local num = #toolchains - local has_basic = false + local standalone = false while idx <= num do local toolchain = toolchains[idx] - -- we need remove other same basic toolchains if basic toolchain found - if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then + -- we need remove other standalone toolchains if standalone toolchain found + if (standalone and toolchain:standalone()) or not toolchain:check() then table.remove(toolchains, idx) num = num - 1 else - if _is_basic_toolchain(toolchain) then - has_basic = true + if toolchain:standalone() then + standalone = true end idx = idx + 1 end diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua index a851256e5..71d2e555c 100644 --- a/xmake/platforms/linux/check.lua +++ b/xmake/platforms/linux/check.lua @@ -22,12 +22,6 @@ import("core.project.config") import("private.platform.check_arch") --- is basic toolchain? -function _is_basic_toolchain(toolchain) - local name = toolchain:name() - return name == "cross" or name == "clang" or name == "gcc" -end - -- check it function main(platform) @@ -38,16 +32,16 @@ function main(platform) local toolchains = platform:toolchains() local idx = 1 local num = #toolchains - local has_basic = false + local standalone = false while idx <= num do local toolchain = toolchains[idx] - -- we need remove other same basic toolchains if basic toolchain found - if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then + -- we need remove other standalone toolchains if standalone toolchain found + if (standalone and toolchain:standalone()) or not toolchain:check() then table.remove(toolchains, idx) num = num - 1 else - if _is_basic_toolchain(toolchain) then - has_basic = true + if toolchain:standalone() then + standalone = true end idx = idx + 1 end diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua index 08e04d7d6..b4eb3b73b 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -22,12 +22,6 @@ import("core.project.config") import("private.platform.check_arch") --- is basic toolchain? -function _is_basic_toolchain(toolchain) - local name = toolchain:name() - return name == "xcode" or name == "clang" or name == "gcc" -end - -- check it function main(platform) @@ -38,16 +32,16 @@ function main(platform) local toolchains = platform:toolchains() local idx = 1 local num = #toolchains - local has_basic = false + local standalone = false while idx <= num do local toolchain = toolchains[idx] - -- we need remove other same basic toolchains if basic toolchain found - if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then + -- we need remove other standalone toolchains if standalone toolchain found + if (standalone and toolchain:standalone()) or not toolchain:check() then table.remove(toolchains, idx) num = num - 1 else - if _is_basic_toolchain(toolchain) then - has_basic = true + if toolchain:standalone() then + standalone = true end idx = idx + 1 end diff --git a/xmake/toolchains/clang/xmake.lua b/xmake/toolchains/clang/xmake.lua index 5d495fff5..ca84a94be 100644 --- a/xmake/toolchains/clang/xmake.lua +++ b/xmake/toolchains/clang/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("clang") + + -- mark as standalone toolchain + set_kind("standalone") -- set toolsets set_toolsets("cc", "clang") diff --git a/xmake/toolchains/cross/xmake.lua b/xmake/toolchains/cross/xmake.lua index 78be10f98..1cf211646 100644 --- a/xmake/toolchains/cross/xmake.lua +++ b/xmake/toolchains/cross/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("cross") + + -- mark as standalone toolchain + set_kind("standalone") -- check toolchain on_check("check") diff --git a/xmake/toolchains/gcc/xmake.lua b/xmake/toolchains/gcc/xmake.lua index ba1ef6989..77f2ef228 100644 --- a/xmake/toolchains/gcc/xmake.lua +++ b/xmake/toolchains/gcc/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("gcc") + + -- mark as standalone toolchain + set_kind("standalone") -- set toolsets set_toolsets("cc", "gcc") diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua index d04234809..4c6c4748b 100644 --- a/xmake/toolchains/llvm/xmake.lua +++ b/xmake/toolchains/llvm/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("llvm") + + -- mark as standalone toolchain + set_kind("standalone") -- check toolchain on_check("check") diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index aed4a44e9..74462908c 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -21,6 +21,9 @@ -- define toolchain toolchain("xcode") + -- mark as standalone toolchain + set_kind("standalone") + -- check toolchain on_check("check") -- cgit v1.3.1