diff options
| author | ruki <[email protected]> | 2020-05-26 22:36:59 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-05-26 09:41:58 +0800 |
| commit | 11c655cdde82b1c82c25ea29227e90cea658ba35 (patch) | |
| tree | 60dae7766ac0c43c891c3c77873e1a60db90266c | |
| parent | 5c8d2277d8a3500a2078cf488c49c3c167349717 (diff) | |
add target:toolconfig
| -rw-r--r-- | xmake/core/project/target.lua | 30 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 8 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 37 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 41 | ||||
| -rw-r--r-- | xmake/languages/asm/xmake.lua | 18 | ||||
| -rw-r--r-- | xmake/languages/c++/xmake.lua | 34 | ||||
| -rw-r--r-- | xmake/languages/cuda/xmake.lua | 26 | ||||
| -rw-r--r-- | xmake/languages/dlang/xmake.lua | 16 | ||||
| -rw-r--r-- | xmake/languages/golang/xmake.lua | 18 | ||||
| -rw-r--r-- | xmake/languages/msrc/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/languages/objc++/xmake.lua | 32 | ||||
| -rw-r--r-- | xmake/languages/rust/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/languages/swift/xmake.lua | 32 |
13 files changed, 180 insertions, 124 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index a397f7adc..a25578677 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1711,6 +1711,36 @@ function _instance:tool(toolkind) return program, toolname end +-- get tool configuration from the toolchains +function _instance:toolconfig(name) + + -- init tool configs + local toolconfigs = self._TOOLCONFIGS + if not toolconfigs then + toolconfigs = {} + self._TOOLCONFIGS = toolconfigs + end + + -- get configuration + local toolconfig = toolconfigs[name] + if toolconfig == nil then + + -- get them from all toolchains + for _, toolchain_inst in ipairs(self:toolchains()) do + local values = toolchain_inst:get(name) + if values then + toolconfig = toolconfig or {} + table.join2(toolconfig, values) + end + end + + -- cache it + toolconfig = toolconfig or false + toolconfigs[name] = toolconfig + end + return toolconfig or nil +end + -- get target apis function target.apis() diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 042aa5001..03a9f34ed 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -263,7 +263,13 @@ function builder:_add_flags_from_language(flags, target, getters) end return values end - , platform = platform.toolconfig + , toolchain = function (name) + if target and target:type() == "target" then + return target:toolconfig(name) + else + return platform.toolconfig(name) + end + end , target = function (name) -- only for target diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 8d6db1da8..b99bfdfca 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -40,15 +40,22 @@ function compiler:_language() return self._LANGUAGE end --- add flags from the platform -function compiler:_add_flags_from_platform(flags, targetkind) +-- add flags from the toolchains +function compiler:_add_flags_from_toolchains(flags, targetkind, target) -- add flags for platform with the given target kind, e.g. binary.gcc.cxflags or binary.cxflags if targetkind then local toolname = self:name() - for _, flagkind in ipairs(self:_flagkinds()) do - local toolflags = platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind) - table.join2(flags, toolflags or platform.toolconfig(targetkind .. '.' .. flagkind)) + if target and target:type() == "target" then + for _, flagkind in ipairs(self:_flagkinds()) do + local toolflags = target:toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind) + table.join2(flags, toolflags or target:toolconfig(targetkind .. '.' .. flagkind)) + end + else + for _, flagkind in ipairs(self:_flagkinds()) do + local toolflags = platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind) + table.join2(flags, toolflags or platform.toolconfig(targetkind .. '.' .. flagkind)) + end end end end @@ -129,15 +136,17 @@ function compiler.load(sourcekind, target) -- save this instance compiler._INSTANCES[cachekey] = instance - -- add platform flags to the compiler tool + -- add toolchains flags to the compiler tool, e.g. gcc.cxflags or cxflags local toolname = compiler_tool:name() - for _, flagkind in ipairs(instance:_flagkinds()) do - - -- add flags for platform, e.g. gcc.cxflags or cxflags - compiler_tool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind)) + if target and target:type() == "target" then + for _, flagkind in ipairs(instance:_flagkinds()) do + compiler_tool:add(flagkind, target:toolconfig(toolname .. '.' .. flagkind) or target:toolconfig(flagkind)) + end + else + for _, flagkind in ipairs(instance:_flagkinds()) do + compiler_tool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind)) + end end - - -- ok return instance end @@ -312,8 +321,8 @@ function compiler:compflags(opt) self:_add_flags_from_argument(flags, target, configs) end - -- add flags from the platform - self:_add_flags_from_platform(flags, targetkind) + -- add flags from the toolchains + self:_add_flags_from_toolchains(flags, targetkind, target) -- add flags from the compiler self:_add_flags_from_compiler(flags, targetkind) diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index 9a6141f03..baafde7ae 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -36,16 +36,23 @@ local tool = require("tool/tool") local builder = require("tool/builder") local compiler = require("tool/compiler") --- add flags from the platform -function linker:_add_flags_from_platform(flags, targetkind) +-- add flags from the toolchains +function linker:_add_flags_from_toolchains(flags, targetkind, target) -- attempt to add special lanugage flags first for target kind, e.g. binary.go.gcldflags, static.dcarflags if targetkind then local toolkind = self:kind() local toolname = self:name() - for _, flagkind in ipairs(self:_flagkinds()) do - local toolflags = platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. toolkind .. 'flags') or platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind) - table.join2(flags, toolflags or platform.toolconfig(targetkind .. '.' .. toolkind .. 'flags') or platform.toolconfig(targetkind .. '.' .. flagkind)) + if target and target:type() == "target" then + for _, flagkind in ipairs(self:_flagkinds()) do + local toolflags = target:toolconfig(targetkind .. '.' .. toolname .. '.' .. toolkind .. 'flags') or target:toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind) + table.join2(flags, toolflags or target:toolconfig(targetkind .. '.' .. toolkind .. 'flags') or target:toolconfig(targetkind .. '.' .. flagkind)) + end + else + for _, flagkind in ipairs(self:_flagkinds()) do + local toolflags = platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. toolkind .. 'flags') or platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind) + table.join2(flags, toolflags or platform.toolconfig(targetkind .. '.' .. toolkind .. 'flags') or platform.toolconfig(targetkind .. '.' .. flagkind)) + end end end end @@ -174,17 +181,21 @@ function linker.load(targetkind, sourcekinds, target) -- save this instance builder._INSTANCES[cachekey] = instance - -- add platform flags to the linker tool + -- add toolchains flags to the linker tool + -- add special lanugage flags first, e.g. go.gcldflags or gcc.ldflags or gcldflags or ldflags local toolkind = linkertool:kind() local toolname = linkertool:name() - for _, flagkind in ipairs(instance:_flagkinds()) do - - -- add special lanugage flags first, e.g. go.gcldflags or gcc.ldflags or gcldflags or ldflags - linkertool:add(toolkind .. 'flags', platform.toolconfig(toolname .. '.' .. toolkind .. 'flags') or platform.toolconfig(toolkind .. 'flags')) - linkertool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind)) + if target and target:type() == "target" then + for _, flagkind in ipairs(instance:_flagkinds()) do + linkertool:add(toolkind .. 'flags', target:toolconfig(toolname .. '.' .. toolkind .. 'flags') or target:toolconfig(toolkind .. 'flags')) + linkertool:add(flagkind, target:toolconfig(toolname .. '.' .. flagkind) or target:toolconfig(flagkind)) + end + else + for _, flagkind in ipairs(instance:_flagkinds()) do + linkertool:add(toolkind .. 'flags', platform.toolconfig(toolname .. '.' .. toolkind .. 'flags') or platform.toolconfig(toolkind .. 'flags')) + linkertool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind)) + end end - - -- ok return instance end @@ -236,8 +247,8 @@ function linker:linkflags(opt) self:_add_flags_from_argument(flags, target, configs) end - -- add flags from the platform - self:_add_flags_from_platform(flags, targetkind) + -- add flags from the toolchains + self:_add_flags_from_toolchains(flags, targetkind, target) -- add flags from the linker self:_add_flags_from_linker(flags) diff --git a/xmake/languages/asm/xmake.lua b/xmake/languages/asm/xmake.lua index 7b3e00514..e27ab9767 100644 --- a/xmake/languages/asm/xmake.lua +++ b/xmake/languages/asm/xmake.lua @@ -69,9 +69,9 @@ language("asm") , "option.undefines" , "option.defines_if_ok" , "option.undefines_if_ok" - , "platform.includedirs" - , "platform.defines" - , "platform.undefines" + , "toolchain.includedirs" + , "toolchain.defines" + , "toolchain.undefines" } , binary = { @@ -84,12 +84,12 @@ language("asm") , "option.symbols" , "option.linkdirs" , "option.rpathdirs" - , "platform.linkdirs" - , "platform.rpathdirs" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" , "config.links" , "target.links" , "option.links" - , "platform.links" + , "toolchain.links" } , shared = { @@ -100,15 +100,15 @@ language("asm") , "option.strip" , "option.symbols" , "option.linkdirs" - , "platform.linkdirs" + , "toolchain.linkdirs" , "config.links" , "target.links" , "option.links" - , "platform.links" + , "toolchain.links" , "config.syslinks" , "target.syslinks" , "option.syslinks" - , "platform.syslinks" + , "toolchain.syslinks" } , static = { diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua index 50e7cb8bb..67d2e1d86 100644 --- a/xmake/languages/c++/xmake.lua +++ b/xmake/languages/c++/xmake.lua @@ -80,11 +80,11 @@ language("c++") , "option.undefines_if_ok" , "option.frameworkdirs" , "option.frameworks" - , "platform.includedirs" - , "platform.defines" - , "platform.undefines" - , "platform.frameworkdirs" - , "platform.frameworks" + , "toolchain.includedirs" + , "toolchain.defines" + , "toolchain.undefines" + , "toolchain.frameworkdirs" + , "toolchain.frameworks" } , binary = { @@ -100,21 +100,21 @@ language("c++") , "option.linkdirs" , "option.rpathdirs" , "option.frameworkdirs" - , "platform.linkdirs" - , "platform.rpathdirs" - , "platform.frameworkdirs" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" + , "toolchain.frameworkdirs" , "config.links" , "target.links" , "option.links" - , "platform.links" + , "toolchain.links" , "config.frameworks" , "target.frameworks" , "option.frameworks" - , "platform.frameworks" + , "toolchain.frameworks" , "config.syslinks" , "target.syslinks" , "option.syslinks" - , "platform.syslinks" + , "toolchain.syslinks" } , shared = { @@ -130,21 +130,21 @@ language("c++") , "option.linkdirs" , "option.rpathdirs" , "option.frameworkdirs" - , "platform.linkdirs" - , "platform.rpathdirs" - , "platform.frameworkdirs" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" + , "toolchain.frameworkdirs" , "config.links" , "target.links" , "option.links" - , "platform.links" + , "toolchain.links" , "config.frameworks" , "target.frameworks" , "option.frameworks" - , "platform.frameworks" + , "toolchain.frameworks" , "config.syslinks" , "target.syslinks" , "option.syslinks" - , "platform.syslinks" + , "toolchain.syslinks" } , static = { diff --git a/xmake/languages/cuda/xmake.lua b/xmake/languages/cuda/xmake.lua index 535d652f2..3a3fed06a 100644 --- a/xmake/languages/cuda/xmake.lua +++ b/xmake/languages/cuda/xmake.lua @@ -70,9 +70,9 @@ language("cuda") , "option.languages" , "option.defines" , "option.undefines" - , "platform.includedirs" - , "platform.defines" - , "platform.undefines" + , "toolchain.includedirs" + , "toolchain.defines" + , "toolchain.undefines" } , binary = { @@ -83,16 +83,16 @@ language("cuda") , "target.symbols" , "option.linkdirs" , "option.rpathdirs" - , "platform.linkdirs" - , "platform.rpathdirs" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" , "config.links" , "target.links" , "option.links" - , "platform.links" + , "toolchain.links" , "config.syslinks" , "target.syslinks" , "option.syslinks" - , "platform.syslinks" + , "toolchain.syslinks" } , shared = { @@ -101,15 +101,15 @@ language("cuda") , "target.strip" , "target.symbols" , "option.linkdirs" - , "platform.linkdirs" + , "toolchain.linkdirs" , "config.links" , "target.links" , "option.links" - , "platform.links" + , "toolchain.links" , "config.syslinks" , "target.syslinks" , "option.syslinks" - , "platform.syslinks" + , "toolchain.syslinks" } , static = { @@ -121,15 +121,15 @@ language("cuda") "config.linkdirs" , "target.linkdirs" , "option.linkdirs" - , "platform.linkdirs" + , "toolchain.linkdirs" , "config.links" , "target.links" , "option.links" - , "platform.links" + , "toolchain.links" , "config.syslinks" , "target.syslinks" , "option.syslinks" - , "platform.syslinks" + , "toolchain.syslinks" } } diff --git a/xmake/languages/dlang/xmake.lua b/xmake/languages/dlang/xmake.lua index f30706797..2bc283286 100644 --- a/xmake/languages/dlang/xmake.lua +++ b/xmake/languages/dlang/xmake.lua @@ -59,7 +59,7 @@ language("dlang") , "target.optimize:check" , "target.vectorexts:check" , "target.includedirs" - , "platform.includedirs" + , "toolchain.includedirs" } , binary = { @@ -70,16 +70,16 @@ language("dlang") , "target.symbols" , "option.linkdirs" , "option.rpathdirs" - , "platform.linkdirs" - , "platform.rpathdirs" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" , "config.links" , "target.links" , "option.links" - , "platform.links" + , "toolchain.links" , "config.syslinks" , "target.syslinks" , "option.syslinks" - , "platform.syslinks" + , "toolchain.syslinks" } , shared = { @@ -88,15 +88,15 @@ language("dlang") , "target.strip" , "target.symbols" , "option.linkdirs" - , "platform.linkdirs" + , "toolchain.linkdirs" , "config.links" , "target.links" , "option.links" - , "platform.links" + , "toolchain.links" , "config.syslinks" , "target.syslinks" , "option.syslinks" - , "platform.syslinks" + , "toolchain.syslinks" } , static = { diff --git a/xmake/languages/golang/xmake.lua b/xmake/languages/golang/xmake.lua index d78d64e1d..e7c354d41 100644 --- a/xmake/languages/golang/xmake.lua +++ b/xmake/languages/golang/xmake.lua @@ -61,9 +61,9 @@ language("golang") , "target.defines" , "target.undefines" , "target.includedirs" - , "platform.includedirs" - , "platform.defines" - , "platform.undefines" + , "toolchain.includedirs" + , "toolchain.defines" + , "toolchain.undefines" } , binary = { @@ -72,15 +72,15 @@ language("golang") , "target.strip" , "target.symbols" , "option.linkdirs" - , "platform.linkdirs" + , "toolchain.linkdirs" , "config.links" , "target.links" , "option.links" - , "platform.links" + , "toolchain.links" , "config.syslinks" , "target.syslinks" , "option.syslinks" - , "platform.syslinks" + , "toolchain.syslinks" } , shared = { @@ -89,15 +89,15 @@ language("golang") , "target.strip" , "target.symbols" , "option.linkdirs" - , "platform.linkdirs" + , "toolchain.linkdirs" , "config.links" , "target.links" , "option.links" - , "platform.links" + , "toolchain.links" , "config.syslinks" , "target.syslinks" , "option.syslinks" - , "platform.syslinks" + , "toolchain.syslinks" } } diff --git a/xmake/languages/msrc/xmake.lua b/xmake/languages/msrc/xmake.lua index 384faa875..721f0d09d 100644 --- a/xmake/languages/msrc/xmake.lua +++ b/xmake/languages/msrc/xmake.lua @@ -52,9 +52,9 @@ language("msrc") , "option.undefines" , "option.defines_if_ok" , "option.undefines_if_ok" - , "platform.includedirs" - , "platform.defines" - , "platform.undefines" + , "toolchain.includedirs" + , "toolchain.defines" + , "toolchain.undefines" } } diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua index 205398484..41cc10d38 100644 --- a/xmake/languages/objc++/xmake.lua +++ b/xmake/languages/objc++/xmake.lua @@ -80,11 +80,11 @@ language("objc++") , "option.undefines_if_ok" , "option.frameworkdirs" , "option.frameworks" - , "platform.includedirs" - , "platform.defines" - , "platform.undefines" - , "platform.frameworkdirs" - , "platform.frameworks" + , "toolchain.includedirs" + , "toolchain.defines" + , "toolchain.undefines" + , "toolchain.frameworkdirs" + , "toolchain.frameworks" } , binary = { @@ -100,21 +100,21 @@ language("objc++") , "option.linkdirs" , "option.rpathdirs" , "option.frameworkdirs" - , "platform.linkdirs" - , "platform.rpathdirs" - , "platform.frameworkdirs" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" + , "toolchain.frameworkdirs" , "config.links" , "target.links" , "option.links" - , "platform.links" + , "toolchain.links" , "config.frameworks" , "target.frameworks" , "option.frameworks" - , "platform.frameworks" + , "toolchain.frameworks" , "config.syslinks" , "target.syslinks" , "option.syslinks" - , "platform.syslinks" + , "toolchain.syslinks" } , shared = { @@ -128,20 +128,20 @@ language("objc++") , "option.symbols" , "option.linkdirs" , "option.frameworkdirs" - , "platform.linkdirs" - , "platform.frameworkdirs" + , "toolchain.linkdirs" + , "toolchain.frameworkdirs" , "config.links" , "target.links" , "option.links" - , "platform.links" + , "toolchain.links" , "config.frameworks" , "target.frameworks" , "option.frameworks" - , "platform.frameworks" + , "toolchain.frameworks" , "config.syslinks" , "target.syslinks" , "option.syslinks" - , "platform.syslinks" + , "toolchain.syslinks" } , static = { diff --git a/xmake/languages/rust/xmake.lua b/xmake/languages/rust/xmake.lua index 044ed0111..8a3b73b91 100644 --- a/xmake/languages/rust/xmake.lua +++ b/xmake/languages/rust/xmake.lua @@ -67,8 +67,8 @@ language("rust") , "target.symbols" , "option.linkdirs" , "option.rpathdirs" - , "platform.linkdirs" - , "platform.rpathdirs" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" } , shared = { @@ -77,7 +77,7 @@ language("rust") , "target.strip" , "target.symbols" , "option.linkdirs" - , "platform.linkdirs" + , "toolchain.linkdirs" } , static = { diff --git a/xmake/languages/swift/xmake.lua b/xmake/languages/swift/xmake.lua index 3ac1f0b87..b786c73b7 100644 --- a/xmake/languages/swift/xmake.lua +++ b/xmake/languages/swift/xmake.lua @@ -75,11 +75,11 @@ language("swift") , "option.undefines_if_ok" , "option.frameworkdirs" , "option.frameworks" - , "platform.includedirs" - , "platform.defines" - , "platform.undefines" - , "platform.frameworkdirs" - , "platform.frameworks" + , "toolchain.includedirs" + , "toolchain.defines" + , "toolchain.undefines" + , "toolchain.frameworkdirs" + , "toolchain.frameworks" } , binary = { @@ -95,21 +95,21 @@ language("swift") , "option.linkdirs" , "option.rpathdirs" , "option.frameworkdirs" - , "platform.linkdirs" - , "platform.rpathdirs" - , "platform.frameworkdirs" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" + , "toolchain.frameworkdirs" , "config.links" , "target.links" , "option.links" - , "platform.links" + , "toolchain.links" , "config.frameworks" , "target.frameworks" , "option.frameworks" - , "platform.frameworks" + , "toolchain.frameworks" , "config.syslinks" , "target.syslinks" , "option.syslinks" - , "platform.syslinks" + , "toolchain.syslinks" } , shared = { @@ -123,20 +123,20 @@ language("swift") , "option.symbols" , "option.linkdirs" , "option.frameworkdirs" - , "platform.linkdirs" - , "platform.frameworkdirs" + , "toolchain.linkdirs" + , "toolchain.frameworkdirs" , "config.links" , "target.links" , "option.links" - , "platform.links" + , "toolchain.links" , "config.frameworks" , "target.frameworks" , "option.frameworks" - , "platform.frameworks" + , "toolchain.frameworks" , "config.syslinks" , "target.syslinks" , "option.syslinks" - , "platform.syslinks" + , "toolchain.syslinks" } , static = { |
