summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-12-29 21:49:51 +0800
committerruki <[email protected]>2018-12-29 21:49:51 +0800
commit6ba45b97db448ba35711c0c06970436de3cad009 (patch)
treef89a09db9a2903dc3a143199abf162493705741f
parent04aca8108118992c4962bff9862b34ff8d4384a1 (diff)
improve platform
-rw-r--r--xmake/core/base/singleton.lua83
-rw-r--r--xmake/core/platform/platform.lua12
-rw-r--r--xmake/core/sandbox/modules/import/core/base/global.lua6
-rw-r--r--xmake/core/sandbox/modules/import/core/base/singleton.lua26
-rw-r--r--xmake/core/sandbox/modules/import/core/project/config.lua15
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_program.lua2
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_programver.lua2
-rw-r--r--xmake/modules/private/platform/check_arch.lua42
-rw-r--r--xmake/modules/private/platform/check_cuda.lua48
-rw-r--r--xmake/modules/private/platform/check_toolchain.lua87
-rw-r--r--xmake/modules/private/platform/check_vstudio.lua105
-rw-r--r--xmake/modules/private/platform/check_xcode.lua55
-rw-r--r--xmake/modules/private/platform/toolchain.lua42
-rw-r--r--xmake/platforms/android/check.lua123
-rw-r--r--xmake/platforms/android/config.lua134
-rw-r--r--xmake/platforms/android/xmake.lua4
-rw-r--r--xmake/platforms/checker.lua203
-rw-r--r--xmake/platforms/cross/check.lua112
-rw-r--r--xmake/platforms/cross/config.lua128
-rw-r--r--xmake/platforms/cross/xmake.lua4
-rw-r--r--xmake/platforms/iphoneos/check.lua105
-rw-r--r--xmake/platforms/iphoneos/config.lua126
-rw-r--r--xmake/platforms/iphoneos/global.lua40
-rw-r--r--xmake/platforms/iphoneos/xmake.lua7
-rw-r--r--xmake/platforms/linux/check.lua183
-rw-r--r--xmake/platforms/linux/config.lua184
-rw-r--r--xmake/platforms/linux/global.lua40
-rw-r--r--xmake/platforms/linux/xmake.lua7
-rw-r--r--xmake/platforms/macosx/check.lua166
-rw-r--r--xmake/platforms/macosx/config.lua170
-rw-r--r--xmake/platforms/macosx/global.lua44
-rw-r--r--xmake/platforms/macosx/xmake.lua7
-rw-r--r--xmake/platforms/mingw/check.lua104
-rw-r--r--xmake/platforms/mingw/config.lua130
-rw-r--r--xmake/platforms/mingw/xmake.lua4
-rw-r--r--xmake/platforms/watchos/check.lua105
-rw-r--r--xmake/platforms/watchos/config.lua126
-rw-r--r--xmake/platforms/watchos/global.lua40
-rw-r--r--xmake/platforms/watchos/xmake.lua7
-rw-r--r--xmake/platforms/windows/check.lua220
-rw-r--r--xmake/platforms/windows/config.lua152
-rw-r--r--xmake/platforms/windows/global.lua56
-rw-r--r--xmake/platforms/windows/xmake.lua7
43 files changed, 1914 insertions, 1349 deletions
diff --git a/xmake/core/base/singleton.lua b/xmake/core/base/singleton.lua
new file mode 100644
index 000000000..4579cf6fe
--- /dev/null
+++ b/xmake/core/base/singleton.lua
@@ -0,0 +1,83 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file singleton.lua
+--
+
+-- define module
+local singleton = singleton or {}
+
+-- get a singleton instance and create it if not exists
+--
+-- e.g.
+--
+-- local instance = singleton.get("key")
+--
+-- function get_xxx()
+--
+-- -- get instance
+-- local instance, inited = singleton.get(get_xxx)
+-- if inited then
+-- return instance
+-- end
+--
+-- -- init instance
+-- instance.xxx = 1
+-- return instance
+-- end
+--
+function singleton.get(key)
+
+ -- get key
+ key = tostring(key)
+
+ -- get all instances
+ local instances = singleton.instances()
+
+ -- get singleton instance
+ local inited = true
+ local instance = instances[key]
+ if instance == nil then
+
+ -- mark as not inited
+ inited = false
+
+ -- init instance
+ instance = {}
+
+ -- save this instance
+ instances[key] = instance
+ end
+ return instance, inited
+end
+
+-- get all singleton instances
+function singleton.instances()
+ local instances = singleton._INSTANCES
+ if not instances then
+ instances = {}
+ singleton._INSTANCES = instances
+ end
+ return instances
+end
+
+-- return module: singleton
+return singleton
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua
index 3e153c2f2..fcab41b59 100644
--- a/xmake/core/platform/platform.lua
+++ b/xmake/core/platform/platform.lua
@@ -305,11 +305,17 @@ function platform.tool(toolkind)
local program = config.get(toolkind)
local toolname = config.get("__toolname_" .. toolkind)
if program == nil then
+
+ -- get the current platform
+ local instance, errors = platform.load()
+ if not instance then
+ os.raise(errors)
+ end
-- check it first
- local check = platform.get("check")
- if check then
- check("config", toolkind)
+ local on_check = instance:script("config_check")
+ if on_check then
+ on_check(instance, toolkind)
end
-- get it again
diff --git a/xmake/core/sandbox/modules/import/core/base/global.lua b/xmake/core/sandbox/modules/import/core/base/global.lua
index b74b0e987..038be5011 100644
--- a/xmake/core/sandbox/modules/import/core/base/global.lua
+++ b/xmake/core/sandbox/modules/import/core/base/global.lua
@@ -92,9 +92,9 @@ function sandbox_core_base_global.check()
-- belong to the current host?
for _, host in ipairs(table.wrap(instance:hosts())) do
if host == os.host() then
- local check = instance:get("check")
- if check ~= nil then
- check("global")
+ local on_check = instance:script("global_check")
+ if on_check then
+ on_check(instance)
end
break
end
diff --git a/xmake/core/sandbox/modules/import/core/base/singleton.lua b/xmake/core/sandbox/modules/import/core/base/singleton.lua
new file mode 100644
index 000000000..14ae3c3d6
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/base/singleton.lua
@@ -0,0 +1,26 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file singleton.lua
+--
+
+-- return module
+return require("base/singleton")
diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua
index 657c37d57..37e3a8e5a 100644
--- a/xmake/core/sandbox/modules/import/core/project/config.lua
+++ b/xmake/core/sandbox/modules/import/core/project/config.lua
@@ -114,10 +114,17 @@ end
-- check the configuration
function sandbox_core_project_config.check()
- -- get the check script
- local check = platform.get("check")
- if check then
- check("config")
+ -- 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
+ else
+ raise(errors)
end
end
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
index f354b5a56..2c599d6ad 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
@@ -219,7 +219,7 @@ function sandbox_lib_detect_find_program.main(name, opt)
cacheinfo[name] = utils.ifelse(result, result, false)
-- save cache info
- cache.save("find_program", cacheinfo)
+ cache.save(cachekey, cacheinfo)
-- trace
if option.get("verbose") or opt.verbose then
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua b/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua
index ef616e8cd..8b5dbf1f1 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua
@@ -105,7 +105,7 @@ function sandbox_lib_detect_find_programver.main(program, opt)
cacheinfo[program] = utils.ifelse(result, result, false)
-- save cache info
- cache.save("find_programver", cacheinfo)
+ cache.save(cachekey, cacheinfo)
-- ok?
return result
diff --git a/xmake/modules/private/platform/check_arch.lua b/xmake/modules/private/platform/check_arch.lua
new file mode 100644
index 000000000..7d89afdd5
--- /dev/null
+++ b/xmake/modules/private/platform/check_arch.lua
@@ -0,0 +1,42 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file check_arch.lua
+--
+
+-- imports
+import("core.base.option")
+
+-- check the architecture
+function main(config, default)
+
+ -- get the architecture
+ local arch = config.get("arch")
+ if not arch then
+
+ -- init the default architecture
+ config.set("arch", default or os.arch())
+
+ -- trace
+ cprint("checking for the architecture ... ${green}%s", config.get("arch"))
+ end
+end
+
diff --git a/xmake/modules/private/platform/check_cuda.lua b/xmake/modules/private/platform/check_cuda.lua
new file mode 100644
index 000000000..64a88e9ca
--- /dev/null
+++ b/xmake/modules/private/platform/check_cuda.lua
@@ -0,0 +1,48 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file check_cuda.lua
+--
+
+-- imports
+import("core.base.option")
+import("detect.sdks.find_cuda")
+
+-- check the cuda sdk toolchains
+function main(config)
+
+ -- get the cuda directory
+ local cuda_dir = config.get("cuda")
+ if not cuda_dir then
+
+ -- check ok? update it
+ local toolchains = find_cuda()
+ if toolchains then
+
+ -- save it
+ config.set("cuda", toolchains.cudadir)
+
+ -- trace
+ cprint("checking for the Cuda SDK directory ... ${green}%s", toolchains.cudadir)
+ end
+ end
+end
+
diff --git a/xmake/modules/private/platform/check_toolchain.lua b/xmake/modules/private/platform/check_toolchain.lua
new file mode 100644
index 000000000..41964fea3
--- /dev/null
+++ b/xmake/modules/private/platform/check_toolchain.lua
@@ -0,0 +1,87 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file check_toolchain.lua
+--
+
+-- imports
+import("core.base.option")
+import("lib.detect.find_tool")
+
+-- check the given tool
+function _check_tool(config, toolkind, description, name, cross, check)
+
+ -- get the program
+ local program = config.get(toolkind)
+ if not program then
+
+ -- translate program name to attempt to get `$(env XX)`
+ name = vformat(name)
+ if #name == 0 then
+ return
+ end
+
+ -- attempt to check it
+ local toolname = nil
+ if not program then
+ local tool = find_tool(name, {program = (cross or "") .. name, pathes = config.get("bin"), check = check})
+ if tool then
+ program = tool.program
+ toolname = tool.name
+ end
+ end
+
+ -- check ok?
+ if program then
+ config.set(toolkind, program)
+ config.set("__toolname_" .. toolkind, toolname)
+ config.save()
+ end
+
+ -- trace
+ if option.get("verbose") then
+ if program then
+ cprint("checking for %s (%s) ... ${green}%s", description, toolkind, path.filename(program))
+ else
+ cprint("checking for %s (%s: ${red}%s${clear}) ... ${red}no", description, toolkind, name)
+ end
+ end
+ end
+
+ -- ok?
+ return program
+end
+
+-- check the toolchain
+function main(config, name, toolchain)
+ for _, toolinfo in ipairs(toolchain.list) do
+ if type(toolinfo) == "string" then
+ if _check_tool(config, name, toolchain.description, toolinfo) then
+ break
+ end
+ else
+ if _check_tool(config, name, toolchain.description, toolinfo.name, toolinfo.cross, toolinfo.check) then
+ break
+ end
+ end
+ end
+end
+
diff --git a/xmake/modules/private/platform/check_vstudio.lua b/xmake/modules/private/platform/check_vstudio.lua
new file mode 100644
index 000000000..033c7c48b
--- /dev/null
+++ b/xmake/modules/private/platform/check_vstudio.lua
@@ -0,0 +1,105 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file check_vstudio.lua
+--
+
+-- imports
+import("core.base.option")
+import("detect.sdks.find_vstudio")
+import("lib.detect.find_tool")
+import("core.platform.environment")
+
+-- attempt to check vs environment
+function _check_vsenv(config)
+
+ -- have been checked?
+ local vs = config.get("vs")
+ if vs and config.get("__vcvarsall") then
+ return vs
+ end
+
+ -- find vstudio
+ local vstudio = find_vstudio({vcvars_ver = config.get("vs_toolset"), sdkver = config.get("vs_sdkver")})
+ if vstudio then
+
+ -- make order vsver
+ local vsvers = {}
+ for vsver, _ in pairs(vstudio) do
+ if not vs or vs ~= vsver then
+ table.insert(vsvers, vsver)
+ end
+ end
+ table.sort(vsvers, function (a, b) return tonumber(a) > tonumber(b) end)
+ if vs then
+ table.insert(vsvers, 1, vs)
+ end
+
+ -- get vcvarsall
+ for _, vsver in ipairs(vsvers) do
+ local vcvarsall = (vstudio[vsver] or {}).vcvarsall or {}
+ local vsenv = vcvarsall[config.get("arch") or ""]
+ if vsenv and vsenv.path and vsenv.include and vsenv.lib then
+
+ -- save vsenv
+ config.set("__vcvarsall", vcvarsall)
+
+ -- check compiler
+ environment.enter("toolchains")
+ local program = nil
+ local tool = find_tool("cl.exe", {force = true})
+ if tool then
+ program = tool.program
+ end
+ environment.leave("toolchains")
+
+ -- ok?
+ if program then
+ return vsver
+ end
+ end
+ end
+ end
+end
+
+-- check the visual stdio
+function main(config)
+
+ -- attempt to check the given vs version first
+ local vs = _check_vsenv(config)
+ if vs then
+
+ -- save it
+ config.set("vs", vs, {readonly = true, force = true})
+
+ -- trace
+ print("checking for the Microsoft Visual Studio (%s) version ... %s", config.get("arch"), vs)
+ else
+ -- failed
+ print("checking for the Microsoft Visual Studio (%s) version ... no", config.get("arch"))
+ print("please run:")
+ print(" - xmake config --vs=xxx [--vs_toolset=xxx]")
+ print("or - xmake global --vs=xxx")
+ raise()
+ end
+end
+
+
diff --git a/xmake/modules/private/platform/check_xcode.lua b/xmake/modules/private/platform/check_xcode.lua
new file mode 100644
index 000000000..a129820a5
--- /dev/null
+++ b/xmake/modules/private/platform/check_xcode.lua
@@ -0,0 +1,55 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file check_xcode.lua
+--
+
+-- imports
+import("core.base.option")
+import("detect.sdks.find_xcode")
+
+-- check the xcode application directory
+function main(config, optional)
+
+ -- 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
+
+ -- save it (maybe to global)
+ config.set("xcode", xcode.sdkdir, {force = true, readonly = true})
+
+ elseif not optional then
+
+ -- failed
+ cprint("${bright red}please run:")
+ cprint("${red} - xmake config --xcode=xxx")
+ cprint("${red}or - xmake global --xcode=xxx")
+ raise()
+ 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
+ config.set("target_minver", xcode_sdkver)
+ end
+end
+
diff --git a/xmake/modules/private/platform/toolchain.lua b/xmake/modules/private/platform/toolchain.lua
new file mode 100644
index 000000000..5d7e1f8e9
--- /dev/null
+++ b/xmake/modules/private/platform/toolchain.lua
@@ -0,0 +1,42 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file toolchain.lua
+--
+
+-- imports
+import("core.base.object")
+
+-- init toolchain
+local toolchain = toolchain or object {_init = {"description", "list"}}
+
+-- add tool to toolchain list
+function toolchain:add(...)
+ for _, item in ipairs({...}) do
+ table.insert(self.list, item)
+ end
+end
+
+-- create a toolchain object
+function main(description)
+ return toolchain {description, {}}
+end
+
diff --git a/xmake/platforms/android/check.lua b/xmake/platforms/android/check.lua
deleted file mode 100644
index 4e5d4e9ea..000000000
--- a/xmake/platforms/android/check.lua
+++ /dev/null
@@ -1,123 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed to the Apache Software Foundation (ASF) under one
--- or more contributor license agreements. See the NOTICE file
--- distributed with this work for additional information
--- regarding copyright ownership. The ASF licenses this file
--- to you 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 - 2018, TBOOX Open Source Group.
---
--- @author ruki
--- @file check.lua
---
-
--- imports
-import("platforms.checker", {rootdir = os.programdir()})
-import("detect.sdks.find_ndk")
-
--- check the ndk toolchain
-function _check_ndk(config)
- 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 red}please run:")
- cprint("${red} - xmake config --ndk=xxx")
- cprint("${red}or - xmake global --ndk=xxx")
- raise()
- end
-end
-
--- get toolchains
-function _toolchains(config)
-
- -- attempt to get it from cache first
- if _g.TOOLCHAINS then
- return _g.TOOLCHAINS
- end
-
- -- get architecture
- local arch = config.get("arch")
-
- -- get cross
- local cross = config.get("cross")
-
- -- init toolchains
- local toolchains = {}
-
- -- check c/c++ tools to toolchains
- checker.toolchain_insert(toolchains, "cc", cross, "gcc", "the c compiler")
- checker.toolchain_insert(toolchains, "cxx", cross, "g++", "the c++ compiler")
- checker.toolchain_insert(toolchains, "as", cross, "gcc", "the assember")
- checker.toolchain_insert(toolchains, "ld", cross, "g++", "the linker")
- checker.toolchain_insert(toolchains, "ld", cross, "gcc", "the linker")
- checker.toolchain_insert(toolchains, "ar", cross, "ar", "the static library archiver")
- checker.toolchain_insert(toolchains, "ex", cross, "ar", "the static library extractor")
- checker.toolchain_insert(toolchains, "sh", cross, "g++", "the shared library linker")
- checker.toolchain_insert(toolchains, "sh", cross, "gcc", "the shared library linker")
- checker.toolchain_insert(toolchains, "cc", "", "clang", "the c compiler")
- checker.toolchain_insert(toolchains, "cxx", "", "clang++", "the c++ compiler")
- checker.toolchain_insert(toolchains, "as", "", "clang", "the assember")
- checker.toolchain_insert(toolchains, "ld", "", "clang++", "the linker")
- checker.toolchain_insert(toolchains, "ld", "", "clang", "the linker")
- checker.toolchain_insert(toolchains, "sh", "", "clang++", "the shared library linker")
- checker.toolchain_insert(toolchains, "sh", "", "clang", "the shared library linker")
- checker.toolchain_insert(toolchains, "ar", "", "llvm-ar", "the static library archiver")
- checker.toolchain_insert(toolchains, "ex", "", "llvm-ar", "the static library extractor")
-
- -- insert rust tools to toolchains
- checker.toolchain_insert(toolchains, "rc", "", "rustc", "the rust compiler")
- checker.toolchain_insert(toolchains, "rc-ar", "", "rustc", "the rust static library archiver")
- checker.toolchain_insert(toolchains, "rc-sh", "", "rustc", "the rust shared library linker")
- checker.toolchain_insert(toolchains, "rc-ld", "", "rustc", "the rust linker")
-
- -- save toolchains
- _g.TOOLCHAINS = toolchains
-
- -- ok
- return toolchains
-end
-
--- check it
-function main(kind, toolkind)
-
- -- only check the given tool?
- if toolkind then
- return checker.toolchain_check(kind, toolkind, _toolchains)
- end
-
- -- init the check list of config
- _g.config =
- {
- { checker.check_arch, "armv7-a" }
- , _check_ndk
- , { checker.toolchain_check, "sh", _toolchains }
- , { checker.toolchain_check, "ld", _toolchains }
- }
-
- -- init the check list of global
- _g.global =
- {
- _check_ndk_sdkver
- }
-
- -- check it
- checker.check(kind, _g)
-end
-
-
diff --git a/xmake/platforms/android/config.lua b/xmake/platforms/android/config.lua
new file mode 100644
index 000000000..5efaee97b
--- /dev/null
+++ b/xmake/platforms/android/config.lua
@@ -0,0 +1,134 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file config.lua
+--
+
+-- imports
+import("core.project.config")
+import("detect.sdks.find_ndk")
+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 red}please run:")
+ cprint("${red} - xmake config --ndk=xxx")
+ cprint("${red}or - xmake global --ndk=xxx")
+ raise()
+ end
+end
+
+-- get toolchains
+function _toolchains()
+
+ -- attempt to get it from cache first
+ if _g.TOOLCHAINS then
+ return _g.TOOLCHAINS
+ end
+
+ -- get cross
+ local cross = config.get("cross")
+
+ -- 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 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, as = as, ld = ld, sh = sh, ar = ar, ex = ex,
+ rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = 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 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}, "llvm-ar")
+
+ -- init the static library extractor
+ ex:add({name = "ar", cross = cross}, "llvm-ar")
+
+ -- 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")
+
+ -- save toolchains
+ _g.TOOLCHAINS = toolchains
+ return toolchains
+end
+
+-- check it
+function main(platform, name)
+
+ -- only check the given config name?
+ if name then
+ local toolchain = _toolchains()[name]
+ if toolchain then
+ check_toolchain(config, name, toolchain)
+ end
+ else
+
+ -- check arch
+ check_arch(config, "armv7-a")
+
+ -- check ndk
+ _check_ndk()
+
+ -- check ld and sh, @note toolchains must be initialized after calling check_ndk()
+ local 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 7d06c60ac..dc22bf688 100644
--- a/xmake/platforms/android/xmake.lua
+++ b/xmake/platforms/android/xmake.lua
@@ -37,8 +37,8 @@ platform("android")
-- set formats
set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"}
- -- on check
- on_check("check")
+ -- on check project configuration
+ on_config_check("config")
-- on load
on_load("load")
diff --git a/xmake/platforms/checker.lua b/xmake/platforms/checker.lua
deleted file mode 100644
index 35efba82f..000000000
--- a/xmake/platforms/checker.lua
+++ /dev/null
@@ -1,203 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed to the Apache Software Foundation (ASF) under one
--- or more contributor license agreements. See the NOTICE file
--- distributed with this work for additional information
--- regarding copyright ownership. The ASF licenses this file
--- to you 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 - 2018, TBOOX Open Source Group.
---
--- @author ruki
--- @file checker.lua
---
-
--- imports
-import("core.base.option")
-import("detect.sdks.find_xcode")
-import("detect.sdks.find_cuda")
-import("lib.detect.find_tool")
-
--- find the given tool
-function _toolchain_check(config, toolkind, toolinfo)
-
- -- get the program
- local program = config.get(toolkind)
- if not program then
-
- -- get name and attempt to get `$(env XX)`
- local name = vformat(toolinfo.name)
- if #name == 0 then
- return
- end
-
- -- get cross
- local cross = toolinfo.cross or ""
-
- -- attempt to check it
- local toolname = nil
- if not program then
- local tool = find_tool(name, {program = cross .. name, pathes = config.get("bin"), check = toolinfo.check})
- if tool then
- program = tool.program
- toolname = tool.name
- end
- end
-
- -- check ok?
- if program then
- config.set(toolkind, program)
- config.set("__toolname_" .. toolkind, toolname)
- end
-
- -- trace
- if option.get("verbose") then
- if program then
- cprint("checking for %s (%s) ... ${green}%s", toolinfo.description, toolkind, path.filename(program))
- else
- cprint("checking for %s (%s: ${red}%s${clear}) ... ${red}no", toolinfo.description, toolkind, name)
- end
- end
- end
-
- -- ok?
- return program
-end
-
--- check all for the given config kind
-function check(kind, checkers)
-
- -- init config name
- local confignames = {config = "core.project.config", global = "core.base.global"}
-
- -- import config module
- local config = import(confignames[kind])
-
- -- check all
- for _, checker in ipairs(checkers[kind]) do
-
- -- has arguments?
- local args = {}
- if type(checker) == "table" then
- for idx, arg in ipairs(checker) do
- if idx == 1 then
- checker = arg
- else
- table.insert(args, arg)
- end
- end
- end
-
- -- check it
- checker(config, unpack(args))
- end
-end
-
--- check the architecture
-function check_arch(config, default)
-
- -- get the architecture
- local arch = config.get("arch")
- if not arch then
-
- -- init the default architecture
- config.set("arch", default or os.arch())
-
- -- trace
- cprint("checking for the architecture ... ${green}%s", config.get("arch"))
- end
-end
-
--- check the xcode application directory
-function check_xcode(config, optional)
-
- -- 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
-
- -- save it (maybe to global)
- config.set("xcode", xcode.sdkdir, {force = true, readonly = true})
-
- elseif not optional then
-
- -- failed
- cprint("${bright red}please run:")
- cprint("${red} - xmake config --xcode=xxx")
- cprint("${red}or - xmake global --xcode=xxx")
- raise()
- 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
- config.set("target_minver", xcode_sdkver)
- end
-end
-
--- check the cuda sdk toolchains
-function check_cuda(config)
-
- -- get the cuda directory
- local cuda_dir = config.get("cuda")
- if not cuda_dir then
-
- -- check ok? update it
- local toolchains = find_cuda()
- if toolchains then
-
- -- save it
- config.set("cuda", toolchains.cudadir)
-
- -- trace
- cprint("checking for the Cuda SDK directory ... ${green}%s", toolchains.cudadir)
- end
- end
-end
-
--- insert toolchain
-function toolchain_insert(toolchains, toolkind, cross, name, description, check)
-
- -- insert to the given toolchain
- toolchains[toolkind] = toolchains[toolkind] or {}
- table.insert(toolchains[toolkind], {cross = cross, name = name, description = description, check = check})
-end
-
--- check the toolchain
-function toolchain_check(config_or_kind, toolkind, toolchains)
-
- -- init config name
- local confignames = {config = "core.project.config", global = "core.base.global"}
-
- -- import config module
- local config = config_or_kind
- if type(config_or_kind) == "string" then
- config = import(confignames[config_or_kind])
- end
-
- -- load toolchains if be function
- if type(toolchains) == "function" then
- toolchains = toolchains(config)
- end
-
- -- check this toolchain
- for _, toolinfo in ipairs(toolchains[toolkind]) do
- if _toolchain_check(config, toolkind, toolinfo) then
- break
- end
- end
-
- -- save config
- config.save()
-end
-
diff --git a/xmake/platforms/cross/check.lua b/xmake/platforms/cross/check.lua
deleted file mode 100644
index 90592b3a5..000000000
--- a/xmake/platforms/cross/check.lua
+++ /dev/null
@@ -1,112 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed to the Apache Software Foundation (ASF) under one
--- or more contributor license agreements. See the NOTICE file
--- distributed with this work for additional information
--- regarding copyright ownership. The ASF licenses this file
--- to you 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 - 2018, TBOOX Open Source Group.
---
--- @author ruki
--- @file check.lua
---
-
--- imports
-import("detect.sdks.find_cross_toolchain")
-import("platforms.checker", {rootdir = os.programdir()})
-
--- check the architecture
-function __check_arch(config)
-
- -- get the architecture
- local arch = config.get("arch")
- if not arch then
- config.set("arch", "none")
- end
-end
-
--- get toolchains
-function _toolchains(config)
-
- -- attempt to get it from cache first
- if _g.TOOLCHAINS then
- return _g.TOOLCHAINS
- end
-
- -- find cross toolchain
- local cross = ""
- local toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")})
- if toolchain then
-
- -- save toolchain
- config.set("cross", toolchain.cross, {readonly = true, force = true})
- config.set("bin", toolchain.bindir, {readonly = true, force = true})
- cross = toolchain.cross
-
- -- add bin search library for loading some dependent .dll files windows
- if toolchain.bindir and is_host("windows") then
- os.addenv("PATH", toolchain.bindir)
- end
- end
-
- -- init toolchains
- local toolchains = {}
-
- -- insert c/c++ tools to toolchains
- checker.toolchain_insert(toolchains, "cc", cross, "gcc", "the c compiler")
- checker.toolchain_insert(toolchains, "cc", cross, "clang", "the c compiler")
- checker.toolchain_insert(toolchains, "cxx", cross, "gcc", "the c++ compiler")
- checker.toolchain_insert(toolchains, "cxx", cross, "clang", "the c++ compiler")
- checker.toolchain_insert(toolchains, "cxx", cross, "g++", "the c++ compiler")
- checker.toolchain_insert(toolchains, "cxx", cross, "clang++", "the c++ compiler")
- checker.toolchain_insert(toolchains, "ld", cross, "g++", "the linker")
- checker.toolchain_insert(toolchains, "ld", cross, "gcc", "the linker")
- checker.toolchain_insert(toolchains, "ld", cross, "clang++", "the linker")
- checker.toolchain_insert(toolchains, "ld", cross, "clang", "the linker")
- checker.toolchain_insert(toolchains, "ar", cross, "ar", "the static library archiver")
- checker.toolchain_insert(toolchains, "ex", cross, "ar", "the static library extractor")
- checker.toolchain_insert(toolchains, "sh", cross, "g++", "the shared library linker")
- checker.toolchain_insert(toolchains, "sh", cross, "gcc", "the shared library linker")
- checker.toolchain_insert(toolchains, "sh", cross, "clang++", "the shared library linker")
- checker.toolchain_insert(toolchains, "sh", cross, "clang", "the shared library linker")
-
- -- insert asm tools to toolchains
- checker.toolchain_insert(toolchains, "as", cross, "clang", "the assember")
- checker.toolchain_insert(toolchains, "as", cross, "gcc", "the assember")
-
- -- save toolchains
- _g.TOOLCHAINS = toolchains
-
- -- ok
- return toolchains
-end
-
--- check it
-function main(kind, toolkind)
-
- -- only check the given tool?
- if toolkind then
- return checker.toolchain_check(kind, toolkind, _toolchains)
- end
-
- -- init the check list of config
- _g.config =
- {
- __check_arch
- }
-
- -- check it
- checker.check(kind, _g)
-end
-
diff --git a/xmake/platforms/cross/config.lua b/xmake/platforms/cross/config.lua
new file mode 100644
index 000000000..802aa0e41
--- /dev/null
+++ b/xmake/platforms/cross/config.lua
@@ -0,0 +1,128 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file config.lua
+--
+
+-- imports
+import("core.project.config")
+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
+
+-- get toolchains
+function _toolchains()
+
+ -- attempt to get it from cache first
+ if _g.TOOLCHAINS then
+ return _g.TOOLCHAINS
+ end
+
+ -- 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
+
+ -- 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
+
+ -- 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 as = toolchain("the assember")
+ local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex}
+
+ -- 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})
+
+ -- save toolchains
+ _g.TOOLCHAINS = toolchains
+ return toolchains
+end
+
+-- check it
+function main(platform, name)
+
+ -- only check the given config name?
+ if name then
+ local toolchain = _toolchains()[name]
+ if toolchain then
+ check_toolchain(config, name, toolchain)
+ end
+ else
+
+ -- check arch
+ _check_arch()
+ end
+end
+
diff --git a/xmake/platforms/cross/xmake.lua b/xmake/platforms/cross/xmake.lua
index ee6debaf4..f57e84b23 100644
--- a/xmake/platforms/cross/xmake.lua
+++ b/xmake/platforms/cross/xmake.lua
@@ -31,8 +31,8 @@ platform("cross")
-- set formats
set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"}
- -- on check
- on_check("check")
+ -- on check project configuration
+ on_config_check("config")
-- on load
on_load("load")
diff --git a/xmake/platforms/iphoneos/check.lua b/xmake/platforms/iphoneos/check.lua
deleted file mode 100644
index fc1b971b1..000000000
--- a/xmake/platforms/iphoneos/check.lua
+++ /dev/null
@@ -1,105 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed to the Apache Software Foundation (ASF) under one
--- or more contributor license agreements. See the NOTICE file
--- distributed with this work for additional information
--- regarding copyright ownership. The ASF licenses this file
--- to you 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 - 2018, TBOOX Open Source Group.
---
--- @author ruki
--- @file check.lua
---
-
--- imports
-import("platforms.checker", {rootdir = os.programdir()})
-
--- get toolchains
-function _toolchains(config)
-
- -- attempt to get it from cache first
- if _g.TOOLCHAINS then
- return _g.TOOLCHAINS
- end
-
- -- init architecture
- local arch = config.get("arch")
- local simulator = (arch == "i386" or arch == "x86_64")
-
- -- init cross
- local cross = ifelse(simulator, "xcrun -sdk iphonesimulator ", "xcrun -sdk iphoneos ")
-
- -- init toolchains
- local toolchains = {}
-
- -- insert c/c++ tools to toolchains
- checker.toolchain_insert(toolchains, "cc", cross, "clang", "the c compiler")
- checker.toolchain_insert(toolchains, "cxx", cross, "clang", "the c++ compiler")
- checker.toolchain_insert(toolchains, "cxx", cross, "clang++", "the c++ compiler")
- checker.toolchain_insert(toolchains, "ld", cross, "clang++", "the linker")
- checker.toolchain_insert(toolchains, "ld", cross, "clang", "the linker")
- checker.toolchain_insert(toolchains, "ar", cross, "ar", "the static library archiver")
- checker.toolchain_insert(toolchains, "ex", cross, "ar", "the static library extractor")
- checker.toolchain_insert(toolchains, "sh", cross, "clang++", "the shared library linker")
- checker.toolchain_insert(toolchains, "sh", cross, "clang", "the shared library linker")
-
- -- insert objc/c++ tools to toolchains
- checker.toolchain_insert(toolchains, "mm", cross, "clang", "the objc compiler")
- checker.toolchain_insert(toolchains, "mxx", cross, "clang++", "the objc++ compiler")
- checker.toolchain_insert(toolchains, "mxx", cross, "clang", "the objc++ compiler")
-
- -- insert swift tools to toolchains
- checker.toolchain_insert(toolchains, "sc", cross, "swiftc", "the swift compiler")
- checker.toolchain_insert(toolchains, "sc-ld", cross, "swiftc", "the swift linker")
- checker.toolchain_insert(toolchains, "sc-sh", cross, "swiftc", "the swift shared library linker")
-
- -- insert asm tools to toolchains
- if simulator then
- checker.toolchain_insert(toolchains, "as", cross, "clang", "the assember")
- else
- checker.toolchain_insert(toolchains, "as", path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross), "clang", "the assember")
- end
-
- -- save toolchains
- _g.TOOLCHAINS = toolchains
-
- -- ok
- return toolchains
-end
-
--- check it
-function main(kind, toolkind)
-
- -- only check the given tool?
- if toolkind then
- return checker.toolchain_check(kind, toolkind, _toolchains)
- end
-
- -- init the check list of config
- _g.config =
- {
- { checker.check_arch, "arm64" }
- , checker.check_xcode
- }
-
- -- init the check list of global
- _g.global =
- {
- { checker.check_xcode, true }
- }
-
- -- check it
- checker.check(kind, _g)
-end
-
diff --git a/xmake/platforms/iphoneos/config.lua b/xmake/platforms/iphoneos/config.lua
new file mode 100644
index 000000000..db815ee3a
--- /dev/null
+++ b/xmake/platforms/iphoneos/config.lua
@@ -0,0 +1,126 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file config.lua
+--
+
+-- imports
+import("core.project.config")
+import("private.platform.toolchain")
+import("private.platform.check_arch")
+import("private.platform.check_xcode")
+import("private.platform.check_toolchain")
+
+-- get toolchains
+function _toolchains()
+
+ -- attempt to get it from cache first
+ if _g.TOOLCHAINS then
+ return _g.TOOLCHAINS
+ end
+
+ -- init architecture
+ local arch = config.get("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 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 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,
+ mm = mm, mxx = mxx, sc = sc, ["sc-ld"] = sc_ld, ["sc-sh"] = 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 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})
+
+ -- save toolchains
+ _g.TOOLCHAINS = toolchains
+ return toolchains
+end
+
+-- check it
+function main(platform, name)
+
+ -- only check the given config name?
+ if name then
+ local toolchain = _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
new file mode 100644
index 000000000..0464ceb1f
--- /dev/null
+++ b/xmake/platforms/iphoneos/global.lua
@@ -0,0 +1,40 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, 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 a6dc69508..85fb8bd6e 100644
--- a/xmake/platforms/iphoneos/xmake.lua
+++ b/xmake/platforms/iphoneos/xmake.lua
@@ -37,8 +37,11 @@ platform("iphoneos")
-- set formats
set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dylib", symbol = "$(name).sym"}
- -- on check
- on_check("check")
+ -- on check project configuration
+ on_config_check("config")
+
+ -- on check global configuration
+ on_global_check("global")
-- on load
on_load("load")
diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua
deleted file mode 100644
index b226ab206..000000000
--- a/xmake/platforms/linux/check.lua
+++ /dev/null
@@ -1,183 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed to the Apache Software Foundation (ASF) under one
--- or more contributor license agreements. See the NOTICE file
--- distributed with this work for additional information
--- regarding copyright ownership. The ASF licenses this file
--- to you 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 - 2018, TBOOX Open Source Group.
---
--- @author ruki
--- @file check.lua
---
-
--- imports
-import("detect.sdks.find_cross_toolchain")
-import("platforms.checker", {rootdir = os.programdir()})
-
--- check the architecture
-function __check_arch(config)
-
- -- get the architecture
- local arch = config.get("arch")
- if not arch then
-
- -- init the default architecture
- config.set("arch", ifelse(config.get("cross"), "none", os.arch()))
-
- -- trace
- print("checking for the architecture ... %s", config.get("arch"))
- end
-end
-
--- get toolchains
-function _toolchains(config)
-
- -- attempt to get it from cache first
- if _g.TOOLCHAINS then
- return _g.TOOLCHAINS
- end
-
- -- find cross toolchain
- local cross = ""
- local toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")})
- if toolchain then
- config.set("cross", toolchain.cross, {readonly = true, force = true})
- config.set("bin", toolchain.bindir, {readonly = true, force = true})
- cross = toolchain.cross
- end
-
- -- init toolchains
- local toolchains = {}
-
- -- inset tools from environment variables if not cross-compilation
- if #cross == 0 then
- checker.toolchain_insert(toolchains, "cc", "", "$(env CC)", "the c compiler")
- checker.toolchain_insert(toolchains, "cxx", "", "$(env CXX)", "the linker")
- checker.toolchain_insert(toolchains, "ld", "", "$(env LD)", "the linker")
- checker.toolchain_insert(toolchains, "ld", "", "$(env CXX)", "the linker")
- checker.toolchain_insert(toolchains, "ar", "", "$(env AR)", "the static library archiver")
- checker.toolchain_insert(toolchains, "sh", "", "$(env SH)", "the shared library linker")
- checker.toolchain_insert(toolchains, "mm", "", "$(env MM)", "the objc compiler")
- checker.toolchain_insert(toolchains, "mxx", "", "$(env MXX)", "the objc++ compiler")
- checker.toolchain_insert(toolchains, "as", "", "$(env AS)", "the assember")
- end
-
- -- insert c/c++ tools to toolchains
- checker.toolchain_insert(toolchains, "cc", cross, "gcc", "the c compiler")
- checker.toolchain_insert(toolchains, "cc", cross, "clang", "the c compiler")
- checker.toolchain_insert(toolchains, "cxx", cross, "gcc", "the c++ compiler")
- checker.toolchain_insert(toolchains, "cxx", cross, "clang", "the c++ compiler")
- checker.toolchain_insert(toolchains, "cxx", cross, "g++", "the c++ compiler")
- checker.toolchain_insert(toolchains, "cxx", cross, "clang++", "the c++ compiler")
- checker.toolchain_insert(toolchains, "ld", cross, "g++", "the linker")
- checker.toolchain_insert(toolchains, "ld", cross, "gcc", "the linker")
- checker.toolchain_insert(toolchains, "ld", cross, "clang++", "the linker")
- checker.toolchain_insert(toolchains, "ld", cross, "clang", "the linker")
- checker.toolchain_insert(toolchains, "ar", cross, "ar", "the static library archiver")
- checker.toolchain_insert(toolchains, "ex", cross, "ar", "the static library extractor")
- checker.toolchain_insert(toolchains, "sh", cross, "g++", "the shared library linker")
- checker.toolchain_insert(toolchains, "sh", cross, "gcc", "the shared library linker")
- checker.toolchain_insert(toolchains, "sh", cross, "clang++", "the shared library linker")
- checker.toolchain_insert(toolchains, "sh", cross, "clang", "the shared library linker")
-
- -- insert objc/c++ tools to toolchains
- checker.toolchain_insert(toolchains, "mm", cross, "clang", "the objc compiler")
- checker.toolchain_insert(toolchains, "mm", cross, "gcc", "the objc compiler")
- checker.toolchain_insert(toolchains, "mxx", cross, "clang++", "the objc++ compiler")
- checker.toolchain_insert(toolchains, "mxx", cross, "clang", "the objc++ compiler")
- checker.toolchain_insert(toolchains, "mxx", cross, "g++", "the objc++ compiler")
- checker.toolchain_insert(toolchains, "mxx", cross, "gcc", "the objc++ compiler")
-
- -- insert asm tools to toolchains
- checker.toolchain_insert(toolchains, "as", cross, "clang", "the assember")
- checker.toolchain_insert(toolchains, "as", cross, "gcc", "the assember")
-
- -- insert golang tools to toolchains
- checker.toolchain_insert(toolchains, "gc", "", "$(env GC)", "the golang compiler")
- checker.toolchain_insert(toolchains, "gc-ar", "", "$(env GC)", "the golang static library archiver")
- checker.toolchain_insert(toolchains, "gc-ld", "", "$(env GC)", "the golang linker")
- checker.toolchain_insert(toolchains, "gc", "", "go", "the golang compiler")
- checker.toolchain_insert(toolchains, "gc", "", "gccgo", "the golang compiler")
- checker.toolchain_insert(toolchains, "gc-ar", "", "go", "the golang static library archiver")
- checker.toolchain_insert(toolchains, "gc-ar", "", "gccgo", "the golang static library archiver")
- checker.toolchain_insert(toolchains, "gc-ld", "", "go", "the golang linker")
- checker.toolchain_insert(toolchains, "gc-ld", "", "gccgo", "the golang linker")
-
- -- insert dlang tools to toolchains
- checker.toolchain_insert(toolchains, "dc", "", "$(env DC)", "the dlang compiler")
- checker.toolchain_insert(toolchains, "dc-ar", "", "$(env Dc)", "the dlang static library archiver")
- checker.toolchain_insert(toolchains, "dc-sh", "", "$(env DC)", "the dlang shared library linker")
- checker.toolchain_insert(toolchains, "dc-ld", "", "$(env DC)", "the dlang linker")
- checker.toolchain_insert(toolchains, "dc", "", "dmd", "the dlang compiler")
- checker.toolchain_insert(toolchains, "dc", "", "ldc2", "the dlang compiler")
- checker.toolchain_insert(toolchains, "dc", "", "gdc", "the dlang compiler")
- checker.toolchain_insert(toolchains, "dc-ar", "", "dmd", "the dlang static library archiver")
- checker.toolchain_insert(toolchains, "dc-ar", "", "ldc2", "the dlang static library archiver")
- checker.toolchain_insert(toolchains, "dc-ar", "", "gdc", "the dlang static library archiver")
- checker.toolchain_insert(toolchains, "dc-sh", "", "dmd", "the dlang shared library linker")
- checker.toolchain_insert(toolchains, "dc-sh", "", "ldc2", "the dlang shared library linker")
- checker.toolchain_insert(toolchains, "dc-sh", "", "gdc", "the dlang shared library linker")
- checker.toolchain_insert(toolchains, "dc-ld", "", "dmd", "the dlang linker")
- checker.toolchain_insert(toolchains, "dc-ld", "", "ldc2", "the dlang linker")
- checker.toolchain_insert(toolchains, "dc-ld", "", "gdc", "the dlang linker")
-
- -- insert rust tools to toolchains
- checker.toolchain_insert(toolchains, "rc", "", "$(env RC)", "the rust compiler")
- checker.toolchain_insert(toolchains, "rc-ar", "", "$(env RC)", "the rust static library archiver")
- checker.toolchain_insert(toolchains, "rc-sh", "", "$(env RC)", "the rust shared library linker")
- checker.toolchain_insert(toolchains, "rc-ld", "", "$(env RC)", "the rust linker")
- checker.toolchain_insert(toolchains, "rc", "", "rustc", "the rust compiler")
- checker.toolchain_insert(toolchains, "rc-ar", "", "rustc", "the rust static library archiver")
- checker.toolchain_insert(toolchains, "rc-sh", "", "rustc", "the rust shared library linker")
- checker.toolchain_insert(toolchains, "rc-ld", "", "rustc", "the rust linker")
-
- -- insert cuda tools to toolchains
- checker.toolchain_insert(toolchains, "cu", "", "nvcc", "the cuda compiler")
- checker.toolchain_insert(toolchains, "cu-sh", "", "nvcc", "the cuda shared library linker")
- checker.toolchain_insert(toolchains, "cu-ld", "", "nvcc", "the cuda linker")
-
- -- save toolchains
- _g.TOOLCHAINS = toolchains
-
- -- ok
- return toolchains
-end
-
--- check it
-function main(kind, toolkind)
-
- -- only check the given tool?
- if toolkind then
- return checker.toolchain_check(kind, toolkind, _toolchains)
- end
-
- -- init the check list of config
- _g.config =
- {
- __check_arch
- , checker.check_cuda
- }
-
- -- init the check list of global
- _g.global =
- {
- _check_ndk_sdkver
- , checker.check_cuda
- }
-
- -- check it
- checker.check(kind, _g)
-end
-
diff --git a/xmake/platforms/linux/config.lua b/xmake/platforms/linux/config.lua
new file mode 100644
index 000000000..ed6fcf543
--- /dev/null
+++ b/xmake/platforms/linux/config.lua
@@ -0,0 +1,184 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file config.lua
+--
+
+-- imports
+import("core.project.config")
+import("detect.sdks.find_cross_toolchain")
+import("private.platform.toolchain")
+import("private.platform.check_arch")
+import("private.platform.check_cuda")
+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()
+
+ -- attempt to get it from cache first
+ if _g.TOOLCHAINS then
+ return _g.TOOLCHAINS
+ end
+
+ -- 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_sh = toolchain("the cuda shared library linker")
+ local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex,
+ mm = mm, mxx = mxx,
+ gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar,
+ dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar,
+ rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar,
+ cu = cu, ["cu-ld"] = cu_ld, ["cu-sh"] = cu_sh}
+
+ -- 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")
+ cu_ld:add("nvcc")
+ cu_sh:add("nvcc")
+
+ -- save toolchains
+ _g.TOOLCHAINS = toolchains
+ return toolchains
+end
+
+-- check it
+function main(platform, name)
+
+ -- only check the given config name?
+ if name then
+ local toolchain = _toolchains()[name]
+ if toolchain then
+ check_toolchain(config, name, toolchain)
+ end
+ else
+
+ -- check arch
+ _check_arch()
+
+ -- check cuda
+ check_cuda(config)
+ end
+end
+
diff --git a/xmake/platforms/linux/global.lua b/xmake/platforms/linux/global.lua
new file mode 100644
index 000000000..c51241190
--- /dev/null
+++ b/xmake/platforms/linux/global.lua
@@ -0,0 +1,40 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file global.lua
+--
+
+-- imports
+import("core.base.global")
+import("private.platform.check_cuda")
+
+-- 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 cuda
+ check_cuda(global)
+end
+
diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua
index b5b712df4..c1c5f051d 100644
--- a/xmake/platforms/linux/xmake.lua
+++ b/xmake/platforms/linux/xmake.lua
@@ -40,8 +40,11 @@ platform("linux")
-- set install directory
set_installdir("/usr/local")
- -- on check
- on_check("check")
+ -- on check project configuration
+ on_config_check("config")
+
+ -- on check global configuration
+ on_global_check("global")
-- on load
on_load("load")
diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua
deleted file mode 100644
index 43d37dd1c..000000000
--- a/xmake/platforms/macosx/check.lua
+++ /dev/null
@@ -1,166 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed to the Apache Software Foundation (ASF) under one
--- or more contributor license agreements. See the NOTICE file
--- distributed with this work for additional information
--- regarding copyright ownership. The ASF licenses this file
--- to you 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 - 2018, TBOOX Open Source Group.
---
--- @author ruki
--- @file check.lua
---
-
--- imports
-import("platforms.checker", {rootdir = os.programdir()})
-
--- get toolchains
-function _toolchains(config)
-
- -- attempt to get it from cache first
- if _g.TOOLCHAINS then
- return _g.TOOLCHAINS
- end
-
- -- init toolchains
- local toolchains = {}
-
- -- insert c/c++ tools to toolchains
- checker.toolchain_insert(toolchains, "cc", "", "$(env CC)", "the c compiler")
- checker.toolchain_insert(toolchains, "cxx", "", "$(env CXX)", "the c++ compiler")
- checker.toolchain_insert(toolchains, "ld", "", "$(env LD)", "the linker")
- checker.toolchain_insert(toolchains, "ld", "", "$(env CXX)", "the linker")
- checker.toolchain_insert(toolchains, "ar", "", "$(env AR)", "the static library archiver")
- checker.toolchain_insert(toolchains, "sh", "", "$(env SH)", "the shared library linker")
- checker.toolchain_insert(toolchains, "cc", "xcrun -sdk macosx ", "clang", "the c compiler")
- checker.toolchain_insert(toolchains, "cxx", "xcrun -sdk macosx ", "clang", "the c++ compiler")
- checker.toolchain_insert(toolchains, "cxx", "xcrun -sdk macosx ", "clang++", "the c++ compiler")
- checker.toolchain_insert(toolchains, "ld", "xcrun -sdk macosx ", "clang++", "the linker")
- checker.toolchain_insert(toolchains, "ld", "xcrun -sdk macosx ", "clang", "the linker")
- checker.toolchain_insert(toolchains, "ar", "xcrun -sdk macosx ", "ar", "the static library archiver")
- checker.toolchain_insert(toolchains, "ex", "xcrun -sdk macosx ", "ar", "the static library extractor")
- checker.toolchain_insert(toolchains, "sh", "xcrun -sdk macosx ", "clang++", "the shared library linker")
- checker.toolchain_insert(toolchains, "sh", "xcrun -sdk macosx ", "clang", "the shared library linker")
- checker.toolchain_insert(toolchains, "cc", "", "clang", "the c compiler")
- checker.toolchain_insert(toolchains, "cc", "", "gcc", "the c compiler")
- checker.toolchain_insert(toolchains, "cxx", "", "clang", "the c++ compiler")
- checker.toolchain_insert(toolchains, "cxx", "", "gcc", "the c++ compiler")
- checker.toolchain_insert(toolchains, "ld", "", "clang++", "the linker")
- checker.toolchain_insert(toolchains, "ld", "", "g++", "the linker")
- checker.toolchain_insert(toolchains, "ld", "", "clang", "the linker")
- checker.toolchain_insert(toolchains, "ld", "", "gcc", "the linker")
- checker.toolchain_insert(toolchains, "ar", "", "ar", "the static library archiver")
- checker.toolchain_insert(toolchains, "ex", "", "ar", "the static library extractor")
- checker.toolchain_insert(toolchains, "sh", "", "clang++", "the shared library linker")
- checker.toolchain_insert(toolchains, "sh", "", "g++", "the shared library linker")
- checker.toolchain_insert(toolchains, "sh", "", "clang", "the shared library linker")
- checker.toolchain_insert(toolchains, "sh", "", "gcc", "the shared library linker")
-
- -- insert objc/c++ tools to toolchains
- checker.toolchain_insert(toolchains, "mm", "", "$(env MM)", "the objc compiler")
- checker.toolchain_insert(toolchains, "mxx", "", "$(env MXX)", "the objc++ compiler")
- checker.toolchain_insert(toolchains, "mm", "xcrun -sdk macosx ", "clang", "the objc compiler")
- checker.toolchain_insert(toolchains, "mxx", "xcrun -sdk macosx ", "clang++", "the objc++ compiler")
- checker.toolchain_insert(toolchains, "mxx", "xcrun -sdk macosx ", "clang", "the objc++ compiler")
-
- -- insert asm tools to toolchains
- checker.toolchain_insert(toolchains, "as", "", "$(env AS)", "the assember")
- checker.toolchain_insert(toolchains, "as", "xcrun -sdk macosx ", "clang", "the assember")
-
- -- insert swift tools to toolchains
- checker.toolchain_insert(toolchains, "sc", "", "$(env SC)", "the swift compiler")
- checker.toolchain_insert(toolchains, "sc-ld", "", "$(env SC)", "the swift linker")
- checker.toolchain_insert(toolchains, "sc-sh", "", "$(env SC)", "the swift shared library linker")
- checker.toolchain_insert(toolchains, "sc", "xcrun -sdk macosx ", "swiftc", "the swift compiler")
- checker.toolchain_insert(toolchains, "sc-ld", "xcrun -sdk macosx ", "swiftc", "the swift linker")
- checker.toolchain_insert(toolchains, "sc-sh", "xcrun -sdk macosx ", "swiftc", "the swift shared library linker")
-
- -- insert golang tools to toolchains
- checker.toolchain_insert(toolchains, "gc", "", "$(env GC)", "the golang compiler")
- checker.toolchain_insert(toolchains, "gc-ar", "", "$(env GC)", "the golang static library archiver")
- checker.toolchain_insert(toolchains, "gc-ld", "", "$(env GC)", "the golang linker")
- checker.toolchain_insert(toolchains, "gc", "", "go", "the golang compiler")
- checker.toolchain_insert(toolchains, "gc", "", "gccgo", "the golang compiler")
- checker.toolchain_insert(toolchains, "gc-ar", "", "go", "the golang static library archiver")
- checker.toolchain_insert(toolchains, "gc-ar", "", "gccgo", "the golang static library archiver")
- checker.toolchain_insert(toolchains, "gc-ld", "", "go", "the golang linker")
- checker.toolchain_insert(toolchains, "gc-ld", "", "gccgo", "the golang linker")
-
- -- insert dlang tools to toolchains
- checker.toolchain_insert(toolchains, "dc", "", "$(env DC)", "the dlang compiler")
- checker.toolchain_insert(toolchains, "dc-ar", "", "$(env DC)", "the dlang static library archiver")
- checker.toolchain_insert(toolchains, "dc-sh", "", "$(env DC)", "the dlang shared library linker")
- checker.toolchain_insert(toolchains, "dc-ld", "", "$(env DC)", "the dlang linker")
- checker.toolchain_insert(toolchains, "dc", "", "dmd", "the dlang compiler")
- checker.toolchain_insert(toolchains, "dc", "", "ldc2", "the dlang compiler")
- checker.toolchain_insert(toolchains, "dc", "", "gdc", "the dlang compiler")
- checker.toolchain_insert(toolchains, "dc-ar", "", "dmd", "the dlang static library archiver")
- checker.toolchain_insert(toolchains, "dc-ar", "", "ldc2", "the dlang static library archiver")
- checker.toolchain_insert(toolchains, "dc-ar", "", "gdc", "the dlang static library archiver")
- checker.toolchain_insert(toolchains, "dc-sh", "", "dmd", "the dlang shared library linker")
- checker.toolchain_insert(toolchains, "dc-sh", "", "ldc2", "the dlang shared library linker")
- checker.toolchain_insert(toolchains, "dc-sh", "", "gdc", "the dlang shared library linker")
- checker.toolchain_insert(toolchains, "dc-ld", "", "dmd", "the dlang linker")
- checker.toolchain_insert(toolchains, "dc-ld", "", "ldc2", "the dlang linker")
- checker.toolchain_insert(toolchains, "dc-ld", "", "gdc", "the dlang linker")
-
- -- insert rust tools to toolchains
- checker.toolchain_insert(toolchains, "rc", "", "$(env RC)", "the rust compiler")
- checker.toolchain_insert(toolchains, "rc-ar", "", "$(env RC)", "the rust static library archiver")
- checker.toolchain_insert(toolchains, "rc-sh", "", "$(env RC)", "the rust shared library linker")
- checker.toolchain_insert(toolchains, "rc-ld", "", "$(env RC)", "the rust linker")
- checker.toolchain_insert(toolchains, "rc", "", "rustc", "the rust compiler")
- checker.toolchain_insert(toolchains, "rc-ar", "", "rustc", "the rust static library archiver")
- checker.toolchain_insert(toolchains, "rc-sh", "", "rustc", "the rust shared library linker")
- checker.toolchain_insert(toolchains, "rc-ld", "", "rustc", "the rust linker")
-
- -- insert cuda tools to toolchains
- checker.toolchain_insert(toolchains, "cu", "", "nvcc", "the cuda compiler")
- checker.toolchain_insert(toolchains, "cu-sh", "", "nvcc", "the cuda shared library linker")
- checker.toolchain_insert(toolchains, "cu-ld", "", "nvcc", "the cuda linker")
-
- -- save toolchains
- _g.TOOLCHAINS = toolchains
-
- -- ok
- return toolchains
-end
-
--- check it
-function main(kind, toolkind)
-
- -- only check the given tool?
- if toolkind then
- return checker.toolchain_check(kind, toolkind, _toolchains)
- end
-
- -- init the check list of config
- _g.config =
- {
- checker.check_arch
- , { checker.check_xcode, true }
- , checker.check_cuda
- }
-
- -- init the check list of global
- _g.global =
- {
- { checker.check_xcode, true }
- , checker.check_cuda
- }
-
- -- check it
- checker.check(kind, _g)
-end
-
diff --git a/xmake/platforms/macosx/config.lua b/xmake/platforms/macosx/config.lua
new file mode 100644
index 000000000..e114f266e
--- /dev/null
+++ b/xmake/platforms/macosx/config.lua
@@ -0,0 +1,170 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file config.lua
+--
+
+-- imports
+import("core.project.config")
+import("private.platform.toolchain")
+import("private.platform.check_arch")
+import("private.platform.check_cuda")
+import("private.platform.check_xcode")
+import("private.platform.check_toolchain")
+
+-- get toolchains
+function _toolchains()
+
+ -- attempt to get it from cache first
+ if _g.TOOLCHAINS then
+ return _g.TOOLCHAINS
+ end
+
+ -- 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 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_sh = toolchain("the cuda shared library linker")
+ local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex,
+ mm = mm, mxx = mxx, sc = sc, ["sc-ld"] = sc_ld, ["sc-sh"] = sc_sh,
+ gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar,
+ dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar,
+ rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar,
+ cu = cu, ["cu-ld"] = cu_ld, ["cu-sh"] = cu_sh}
+
+ -- 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 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")
+ cu_ld:add("nvcc")
+ cu_sh:add("nvcc")
+
+ -- save toolchains
+ _g.TOOLCHAINS = toolchains
+ return toolchains
+end
+
+-- check it
+function main(platform, name)
+
+ -- only check the given config name?
+ if name then
+ local toolchain = _toolchains()[name]
+ if toolchain then
+ check_toolchain(config, name, toolchain)
+ end
+ else
+
+ -- check arch
+ check_arch(config)
+
+ -- check xcode
+ check_xcode(config, true)
+
+ -- check cuda
+ check_cuda(config)
+ end
+end
+
diff --git a/xmake/platforms/macosx/global.lua b/xmake/platforms/macosx/global.lua
new file mode 100644
index 000000000..9bfad87b1
--- /dev/null
+++ b/xmake/platforms/macosx/global.lua
@@ -0,0 +1,44 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file global.lua
+--
+
+-- imports
+import("core.base.global")
+import("private.platform.check_cuda")
+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)
+
+ -- check cuda
+ check_cuda(global)
+end
+
diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua
index ccd978120..b1edba11a 100644
--- a/xmake/platforms/macosx/xmake.lua
+++ b/xmake/platforms/macosx/xmake.lua
@@ -40,8 +40,11 @@ platform("macosx")
-- set install directory
set_installdir("/usr/local")
- -- on check
- on_check("check")
+ -- on check project configuration
+ on_config_check("config")
+
+ -- on check global configuration
+ on_global_check("global")
-- on load
on_load("load")
diff --git a/xmake/platforms/mingw/check.lua b/xmake/platforms/mingw/check.lua
deleted file mode 100644
index b5b6d90bf..000000000
--- a/xmake/platforms/mingw/check.lua
+++ /dev/null
@@ -1,104 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed to the Apache Software Foundation (ASF) under one
--- or more contributor license agreements. See the NOTICE file
--- distributed with this work for additional information
--- regarding copyright ownership. The ASF licenses this file
--- to you 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 - 2018, TBOOX Open Source Group.
---
--- @author ruki
--- @file check.lua
---
-
--- imports
-import("detect.sdks.find_mingw")
-import("platforms.checker", {rootdir = os.programdir()})
-
--- check the mingw toolchain
-function _check_mingw(config)
- 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}) -- maybe to global
- config.set("cross", mingw.cross, {readonly = true, force = true})
- config.set("bin", mingw.bindir, {readonly = true, force = true})
- else
- -- failed
- cprint("${bright red}please run:")
- cprint("${red} - xmake config --ndk=xxx")
- cprint("${red}or - xmake global --ndk=xxx")
- raise()
- end
-end
-
--- get toolchains
-function _toolchains(config)
-
- -- attempt to get it from cache first
- if _g.TOOLCHAINS then
- return _g.TOOLCHAINS
- end
-
- -- get cross
- local cross = config.get("cross")
-
- -- 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
-
- -- make toolchains
- local toolchains = {}
- checker.toolchain_insert(toolchains, "cc", cross, "gcc", "the c compiler")
- checker.toolchain_insert(toolchains, "cxx", cross, "g++", "the c++ compiler")
- checker.toolchain_insert(toolchains, "cxx", cross, "gcc", "the c++ compiler")
- checker.toolchain_insert(toolchains, "mrc", cross, "windres", "the resource compiler")
- checker.toolchain_insert(toolchains, "as", cross, "gcc", "the assember")
- checker.toolchain_insert(toolchains, "ld", cross, "g++", "the linker")
- checker.toolchain_insert(toolchains, "ld", cross, "gcc", "the linker")
- checker.toolchain_insert(toolchains, "ar", cross, "ar", "the static library archiver")
- checker.toolchain_insert(toolchains, "ex", cross, "ar", "the static library extractor")
- checker.toolchain_insert(toolchains, "sh", cross, "g++", "the shared library linker")
- checker.toolchain_insert(toolchains, "sh", cross, "gcc", "the shared library linker")
-
- -- save toolchains
- _g.TOOLCHAINS = toolchains
-
- -- ok
- return toolchains
-end
-
--- check it
-function main(kind, toolkind)
-
- -- only check the given tool?
- if toolkind then
- return checker.toolchain_check(kind, toolkind, _toolchains)
- end
-
- -- init the check list of config
- _g.config =
- {
- { checker.check_arch, "x86_64" }
- , _check_mingw
- }
-
- -- init the check list of global
- _g.global = {}
-
- -- check it
- checker.check(kind, _g)
-end
-
diff --git a/xmake/platforms/mingw/config.lua b/xmake/platforms/mingw/config.lua
new file mode 100644
index 000000000..d875abd21
--- /dev/null
+++ b/xmake/platforms/mingw/config.lua
@@ -0,0 +1,130 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file config.lua
+--
+
+-- imports
+import("core.project.config")
+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 red}please run:")
+ cprint("${red} - xmake config --ndk=xxx")
+ cprint("${red}or - xmake global --ndk=xxx")
+ raise()
+ end
+end
+
+-- get toolchains
+function _toolchains()
+
+ -- attempt to get it from cache first
+ if _g.TOOLCHAINS then
+ return _g.TOOLCHAINS
+ end
+
+ -- 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 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 mrc = toolchain("the resource compiler")
+ local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, 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 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 resource compiler
+ mrc:add({name = "windres", cross = cross})
+
+ -- save toolchains
+ _g.TOOLCHAINS = toolchains
+ return toolchains
+end
+
+-- check it
+function main(platform, name)
+
+ -- only check the given config name?
+ if name then
+ local toolchain = _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 e7469750f..5b803bad5 100644
--- a/xmake/platforms/mingw/xmake.lua
+++ b/xmake/platforms/mingw/xmake.lua
@@ -37,8 +37,8 @@ platform("mingw")
-- set formats
set_formats {static = "$(name).lib", object = "$(name).obj", shared = "$(name).dll", binary = "$(name).exe", symbol = "$(name).pdb"}
- -- on check
- on_check("check")
+ -- on check project configuration
+ on_config_check("config")
-- on load
on_load("load")
diff --git a/xmake/platforms/watchos/check.lua b/xmake/platforms/watchos/check.lua
deleted file mode 100644
index b9c943210..000000000
--- a/xmake/platforms/watchos/check.lua
+++ /dev/null
@@ -1,105 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed to the Apache Software Foundation (ASF) under one
--- or more contributor license agreements. See the NOTICE file
--- distributed with this work for additional information
--- regarding copyright ownership. The ASF licenses this file
--- to you 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 - 2018, TBOOX Open Source Group.
---
--- @author ruki
--- @file check.lua
---
-
--- imports
-import("platforms.checker", {rootdir = os.programdir()})
-
--- get toolchains
-function _toolchains(config)
-
- -- attempt to get it from cache first
- if _g.TOOLCHAINS then
- return _g.TOOLCHAINS
- end
-
- -- init architecture
- local arch = config.get("arch")
- local simulator = (arch == "i386")
-
- -- init cross
- local cross = ifelse(simulator, "xcrun -sdk watchsimulator ", "xcrun -sdk watchos ")
-
- -- init toolchains
- local toolchains = {}
-
- -- insert c/c++ tools to toolchains
- checker.toolchain_insert(toolchains, "cc", cross, "clang", "the c compiler")
- checker.toolchain_insert(toolchains, "cxx", cross, "clang", "the c++ compiler")
- checker.toolchain_insert(toolchains, "cxx", cross, "clang++", "the c++ compiler")
- checker.toolchain_insert(toolchains, "ld", cross, "clang++", "the linker")
- checker.toolchain_insert(toolchains, "ld", cross, "clang", "the linker")
- checker.toolchain_insert(toolchains, "ar", cross, "ar", "the static library archiver")
- checker.toolchain_insert(toolchains, "ex", cross, "ar", "the static library extractor")
- checker.toolchain_insert(toolchains, "sh", cross, "clang++", "the shared library linker")
- checker.toolchain_insert(toolchains, "sh", cross, "clang", "the shared library linker")
-
- -- insert objc/c++ tools to toolchains
- checker.toolchain_insert(toolchains, "mm", cross, "clang", "the objc compiler")
- checker.toolchain_insert(toolchains, "mxx", cross, "clang++", "the objc++ compiler")
- checker.toolchain_insert(toolchains, "mxx", cross, "clang", "the objc++ compiler")
-
- -- insert swift tools to toolchains
- checker.toolchain_insert(toolchains, "sc", cross, "swiftc", "the swift compiler")
- checker.toolchain_insert(toolchains, "sc-ld", cross, "swiftc", "the swift linker")
- checker.toolchain_insert(toolchains, "sc-sh", cross, "swiftc", "the swift shared library linker")
-
- -- insert asm tools to toolchains
- if simulator then
- checker.toolchain_insert(toolchains, "as", cross, "clang", "the assember")
- else
- checker.toolchain_insert(toolchains, "as", path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross), "clang", "the assember")
- end
-
- -- save toolchains
- _g.TOOLCHAINS = toolchains
-
- -- ok
- return toolchains
-end
-
--- check it
-function main(kind, toolkind)
-
- -- only check the given tool?
- if toolkind then
- return checker.toolchain_check(kind, toolkind, _toolchains)
- end
-
- -- init the check list of config
- _g.config =
- {
- { checker.check_arch, "armv7k" }
- , checker.check_xcode
- }
-
- -- init the check list of global
- _g.global =
- {
- { checker.check_xcode, true }
- }
-
- -- check it
- checker.check(kind, _g)
-end
-
diff --git a/xmake/platforms/watchos/config.lua b/xmake/platforms/watchos/config.lua
new file mode 100644
index 000000000..b791b7b65
--- /dev/null
+++ b/xmake/platforms/watchos/config.lua
@@ -0,0 +1,126 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file config.lua
+--
+
+-- imports
+import("core.project.config")
+import("private.platform.toolchain")
+import("private.platform.check_arch")
+import("private.platform.check_xcode")
+import("private.platform.check_toolchain")
+
+-- get toolchains
+function _toolchains()
+
+ -- attempt to get it from cache first
+ if _g.TOOLCHAINS then
+ return _g.TOOLCHAINS
+ end
+
+ -- 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 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,
+ mm = mm, mxx = mxx, sc = sc, ["sc-ld"] = sc_ld, ["sc-sh"] = 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 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})
+
+ -- save toolchains
+ _g.TOOLCHAINS = toolchains
+ return toolchains
+end
+
+-- check it
+function main(platform, name)
+
+ -- only check the given config name?
+ if name then
+ local toolchain = _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
new file mode 100644
index 000000000..0464ceb1f
--- /dev/null
+++ b/xmake/platforms/watchos/global.lua
@@ -0,0 +1,40 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, 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 8c472440f..06de8cce5 100644
--- a/xmake/platforms/watchos/xmake.lua
+++ b/xmake/platforms/watchos/xmake.lua
@@ -37,8 +37,11 @@ platform("watchos")
-- set formats
set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dylib", symbol = "$(name).sym"}
- -- on check
- on_check("check")
+ -- on check project configuration
+ on_config_check("config")
+
+ -- on check global configuration
+ on_global_check("global")
-- on load
on_load("load")
diff --git a/xmake/platforms/windows/check.lua b/xmake/platforms/windows/check.lua
deleted file mode 100644
index f25b349fa..000000000
--- a/xmake/platforms/windows/check.lua
+++ /dev/null
@@ -1,220 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed to the Apache Software Foundation (ASF) under one
--- or more contributor license agreements. See the NOTICE file
--- distributed with this work for additional information
--- regarding copyright ownership. The ASF licenses this file
--- to you 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 - 2018, TBOOX Open Source Group.
---
--- @author ruki
--- @file check.lua
---
-
--- imports
-import("platforms.checker", {rootdir = os.programdir()})
-import("core.platform.environment")
-import("core.base.option")
-import("detect.sdks.find_vstudio")
-import("lib.detect.find_tool")
-
--- attempt to check vs environment
-function _check_vsenv(config)
-
- -- have been checked?
- local vs = config.get("vs")
- if vs and config.get("__vcvarsall") then
- return vs
- end
-
- -- find vstudio
- local vstudio = find_vstudio({vcvars_ver = config.get("vs_toolset"), sdkver = config.get("vs_sdkver")})
- if vstudio then
-
- -- make order vsver
- local vsvers = {}
- for vsver, _ in pairs(vstudio) do
- if not vs or vs ~= vsver then
- table.insert(vsvers, vsver)
- end
- end
- table.sort(vsvers, function (a, b) return tonumber(a) > tonumber(b) end)
- if vs then
- table.insert(vsvers, 1, vs)
- end
-
- -- get vcvarsall
- for _, vsver in ipairs(vsvers) do
- local vcvarsall = (vstudio[vsver] or {}).vcvarsall or {}
- local vsenv = vcvarsall[config.get("arch") or ""]
- if vsenv and vsenv.path and vsenv.include and vsenv.lib then
-
- -- save vsenv
- config.set("__vcvarsall", vcvarsall)
-
- -- check compiler
- environment.enter("toolchains")
- local program = nil
- local tool = find_tool("cl.exe", {force = true})
- if tool then
- program = tool.program
- end
- environment.leave("toolchains")
-
- -- ok?
- if program then
- return vsver
- end
- end
- end
- end
-end
-
--- clean temporary global configs
-function _clean_global(config)
-
- -- clean it for global config (need not it)
- config.set("arch", nil)
- config.set("__vcvarsall", nil)
-end
-
--- check the visual stdio
-function _check_vs(config)
-
- -- attempt to check the given vs version first
- local vs = _check_vsenv(config)
- if vs then
-
- -- save it
- config.set("vs", vs, {readonly = true, force = true})
-
- -- trace
- print("checking for the Microsoft Visual Studio (%s) version ... %s", config.get("arch"), vs)
- else
- -- failed
- print("checking for the Microsoft Visual Studio (%s) version ... no", config.get("arch"))
- print("please run:")
- print(" - xmake config --vs=xxx [--vs_toolset=xxx]")
- print("or - xmake global --vs=xxx")
- raise()
- end
-end
-
--- get toolchains
-function _toolchains(config)
-
- -- attempt to get it from cache first
- if _g.TOOLCHAINS then
- return _g.TOOLCHAINS
- end
-
- -- init toolchains
- local toolchains = {}
-
- -- insert c/c++ tools to toolchains
- checker.toolchain_insert(toolchains, "cc", "", "cl.exe", "the c compiler")
- checker.toolchain_insert(toolchains, "cxx", "", "cl.exe", "the c++ compiler")
- checker.toolchain_insert(toolchains, "mrc", "", "rc.exe", "the resource compiler")
- checker.toolchain_insert(toolchains, "ld", "", "link.exe", "the linker")
- checker.toolchain_insert(toolchains, "ar", "", "link.exe -lib", "the static library archiver")
- checker.toolchain_insert(toolchains, "sh", "", "link.exe -dll", "the shared library linker")
- checker.toolchain_insert(toolchains, "ex", "", "lib.exe", "the static library extractor")
-
- -- insert golang tools to toolchains
- checker.toolchain_insert(toolchains, "gc", "", "go", "the golang compiler")
- checker.toolchain_insert(toolchains, "gc", "", "gccgo", "the golang compiler")
- checker.toolchain_insert(toolchains, "gc-ar", "", "go", "the golang static library archiver")
- checker.toolchain_insert(toolchains, "gc-ar", "", "gccgo", "the golang static library archiver")
- checker.toolchain_insert(toolchains, "gc-ld", "", "go", "the golang linker")
- checker.toolchain_insert(toolchains, "gc-ld", "", "gccgo", "the golang linker")
-
- -- insert dlang tools to toolchains
- checker.toolchain_insert(toolchains, "dc", "", "dmd", "the dlang compiler")
- checker.toolchain_insert(toolchains, "dc", "", "ldc2", "the dlang compiler")
- checker.toolchain_insert(toolchains, "dc", "", "gdc", "the dlang compiler")
- checker.toolchain_insert(toolchains, "dc-ar", "", "dmd", "the dlang static library archiver")
- checker.toolchain_insert(toolchains, "dc-ar", "", "ldc2", "the dlang static library archiver")
- checker.toolchain_insert(toolchains, "dc-ar", "", "gdc", "the dlang static library archiver")
- checker.toolchain_insert(toolchains, "dc-sh", "", "dmd", "the dlang shared library linker")
- checker.toolchain_insert(toolchains, "dc-sh", "", "ldc2", "the dlang shared library linker")
- checker.toolchain_insert(toolchains, "dc-sh", "", "gdc", "the dlang shared library linker")
- checker.toolchain_insert(toolchains, "dc-ld", "", "dmd", "the dlang linker")
- checker.toolchain_insert(toolchains, "dc-ld", "", "ldc2", "the dlang linker")
- checker.toolchain_insert(toolchains, "dc-ld", "", "gdc", "the dlang linker")
-
- -- insert rust tools to toolchains
- checker.toolchain_insert(toolchains, "rc", "", "rustc", "the rust compiler")
- checker.toolchain_insert(toolchains, "rc-ar", "", "rustc", "the rust static library archiver")
- checker.toolchain_insert(toolchains, "rc-sh", "", "rustc", "the rust shared library linker")
- checker.toolchain_insert(toolchains, "rc-ld", "", "rustc", "the rust linker")
-
- -- insert asm tools to toolchains
- if config.get("arch"):find("64") then
- checker.toolchain_insert(toolchains, "as", "", "ml64.exe", "the assember")
- else
- checker.toolchain_insert(toolchains, "as", "", "ml.exe", "the assember")
- end
-
- -- insert cuda tools to toolchains
- checker.toolchain_insert(toolchains, "cu", "", "nvcc", "the cuda compiler")
- checker.toolchain_insert(toolchains, "cu-sh", "", "nvcc", "the cuda shared library linker")
- checker.toolchain_insert(toolchains, "cu-ld", "", "nvcc", "the cuda linker")
-
- -- save toolchains
- _g.TOOLCHAINS = toolchains
-
- -- ok
- return toolchains
-end
-
--- check it
-function main(kind, toolkind)
-
- -- only check the given tool?
- if toolkind then
-
- -- enter environment
- environment.enter("toolchains")
-
- -- check it
- checker.toolchain_check(kind, toolkind, _toolchains)
-
- -- leave environment
- environment.leave("toolchains")
-
- -- end
- return
- end
-
- -- init the check list of config
- _g.config =
- {
- checker.check_arch
- , _check_vs
- , checker.check_cuda
- }
-
- -- init the check list of global
- _g.global =
- {
- checker.check_arch
- , _check_vs
- , checker.check_cuda
- , _clean_global
- }
-
- -- check it
- checker.check(kind, _g)
-end
-
diff --git a/xmake/platforms/windows/config.lua b/xmake/platforms/windows/config.lua
new file mode 100644
index 000000000..c6ccec4ef
--- /dev/null
+++ b/xmake/platforms/windows/config.lua
@@ -0,0 +1,152 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file config.lua
+--
+
+-- imports
+import("core.project.config")
+import("core.platform.environment")
+import("private.platform.toolchain")
+import("private.platform.check_arch")
+import("private.platform.check_cuda")
+import("private.platform.check_vstudio")
+import("private.platform.check_toolchain")
+
+-- get toolchains
+function _toolchains()
+
+ -- attempt to get it from cache first
+ if _g.TOOLCHAINS then
+ return _g.TOOLCHAINS
+ end
+
+ -- init cross
+ local cross = "xcrun -sdk macosx "
+
+ -- 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 cu_sh = toolchain("the cuda shared library linker")
+ local toolchains = {cc = cc, cxx = cxx, mrc = mrc, as = as, ld = ld, sh = sh, ar = ar, ex = ex,
+ gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar,
+ dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar,
+ rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar,
+ cu = cu, ["cu-ld"] = cu_ld, ["cu-sh"] = cu_sh}
+
+ -- 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
+ if config.get("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")
+ cu_ld:add("nvcc")
+ cu_sh:add("nvcc")
+
+ -- save toolchains
+ _g.TOOLCHAINS = toolchains
+ return toolchains
+end
+
+-- check it
+function main(platform, name)
+
+ -- only check the given config name?
+ if name then
+ local toolchain = _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
+ check_vstudio(config)
+
+ -- check cuda
+ check_cuda(config)
+ end
+end
+
diff --git a/xmake/platforms/windows/global.lua b/xmake/platforms/windows/global.lua
new file mode 100644
index 000000000..6909f39ce
--- /dev/null
+++ b/xmake/platforms/windows/global.lua
@@ -0,0 +1,56 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file global.lua
+--
+
+-- imports
+import("core.base.global")
+import("private.platform.check_cuda")
+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)
+
+ -- check cuda
+ check_cuda(global)
+
+ -- clean temporary global configs
+ _clean_global()
+end
+
diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua
index 961062ad2..5127b638e 100644
--- a/xmake/platforms/windows/xmake.lua
+++ b/xmake/platforms/windows/xmake.lua
@@ -37,8 +37,11 @@ platform("windows")
-- set formats
set_formats {static = "$(name).lib", object = "$(name).obj", shared = "$(name).dll", binary = "$(name).exe", symbol = "$(name).pdb"}
- -- on check
- on_check("check")
+ -- on check project configuration
+ on_config_check("config")
+
+ -- on check global configuration
+ on_global_check("global")
-- on environment enter
on_environment_enter("environment.enter")