summaryrefslogtreecommitdiff
path: root/xmake/rules
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/rules')
-rw-r--r--xmake/rules/c++/modules/gcc/support.lua3
-rw-r--r--xmake/rules/c++/modules/msvc/support.lua4
-rw-r--r--xmake/rules/linker/link_scripts/xmake.lua28
3 files changed, 18 insertions, 17 deletions
diff --git a/xmake/rules/c++/modules/gcc/support.lua b/xmake/rules/c++/modules/gcc/support.lua
index 112272893..623444ce4 100644
--- a/xmake/rules/c++/modules/gcc/support.lua
+++ b/xmake/rules/c++/modules/gcc/support.lua
@@ -311,7 +311,8 @@ function get_cppversionflag(target)
if cppversionflag == nil then
local compinst = target:compiler("cxx")
local flags = compinst:compflags({target = target})
- cppversionflag = table.find_if(flags, function(v) string.startswith(v, "-std=c++") end) or "-std=c++20"
+ local idx = table.find_first_if(flags, function(_, v) return string.startswith(v, "-std=c++") end)
+ cppversionflag = (idx and flags[idx]) or "-std=c++20"
_g.cppversionflag = cppversionflag
end
return cppversionflag or nil
diff --git a/xmake/rules/c++/modules/msvc/support.lua b/xmake/rules/c++/modules/msvc/support.lua
index 1f066de43..588921d0e 100644
--- a/xmake/rules/c++/modules/msvc/support.lua
+++ b/xmake/rules/c++/modules/msvc/support.lua
@@ -261,7 +261,9 @@ function get_cppversionflag(target)
if cppversionflag == nil then
local compinst = target:compiler("cxx")
local flags = compinst:compflags({target = target})
- cppversionflag = table.find_if(flags, function(v) string.startswith(v, "/std:c++") end) or "/std:c++latest"
+ local idx = table.find_first_if(flags, function(_, v) return string.startswith(v, "/std:c++") end)
+ cppversionflag = (idx and flags[idx]) or "/std:c++latest"
+ _g.cppversionflag = cppversionflag
end
return cppversionflag or nil
end
diff --git a/xmake/rules/linker/link_scripts/xmake.lua b/xmake/rules/linker/link_scripts/xmake.lua
index 72411543b..e5fa32bb6 100644
--- a/xmake/rules/linker/link_scripts/xmake.lua
+++ b/xmake/rules/linker/link_scripts/xmake.lua
@@ -24,28 +24,26 @@ rule("linker.link_scripts")
if not target:is_binary() and not target:is_shared() then
return
end
- local scriptfile
local sourcebatch = target:sourcebatches()["linker.link_scripts"]
- if sourcebatch then
- for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
- scriptfile = sourcefile
- break
- end
- end
- if not scriptfile then
+ if not sourcebatch or not sourcebatch.sourcefiles or #sourcebatch.sourcefiles == 0 then
return
end
+
-- @note apple's linker does not support it
if target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then
return
end
- if target:has_tool("ld", "gcc", "gxx", "clang", "clangxx") or
- target:has_tool("sh", "gcc", "gxx", "clang", "clangxx") then
- target:add(target:is_shared() and "shflags" or "ldflags", "-T " .. scriptfile, {force = true})
- target:data_add("linkdepfiles", scriptfile)
- elseif target:has_tool("ld", "ld") or target:has_tool("sh", "ld") then
- target:add(target:is_shared() and "shflags" or "ldflags", "-T " .. scriptfile, {force = true})
- target:data_add("linkdepfiles", scriptfile)
+
+ -- Check for supported linkers (GNU and LLVM linkers support multiple -T flags)
+ if target:has_tool("ld", "gcc", "gxx", "clang", "clangxx", "ld") or
+ target:has_tool("sh", "gcc", "gxx", "clang", "clangxx", "ld") then
+
+ -- Add all linker scripts with -T flag
+ -- https://github.com/xmake-io/xmake/issues/7227
+ for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ target:add(target:is_shared() and "shflags" or "ldflags", "-T " .. sourcefile, {force = true})
+ target:data_add("linkdepfiles", sourcefile)
+ end
end
end)