Skip to content

Commit

Permalink
apply runtime to package targets (for check_cxxsnippet support)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthapz committed Apr 3, 2024
1 parent c7e1441 commit aa321b0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
26 changes: 17 additions & 9 deletions xmake/core/tool/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,13 @@ function builder:_add_flags_from_target(flags, target)

-- only for target and option
local target_type = target:type()
if target_type ~= "target" and target_type ~= "option" then
return
end

-- init cache
self._TARGETFLAGS = self._TARGETFLAGS or {}
local cache = self._TARGETFLAGS

-- get flags from cache first
local key = target:cachekey()
local key = target_type == "package" and tostring(target) or target:cachekey()
local targetflags = cache[key]
if not targetflags then

Expand Down Expand Up @@ -417,6 +414,7 @@ function builder:_add_flags_from_language(flags, opt)
-- get order named items
local items = {}
local target = opt.target

for _, flaginfo in ipairs(self:_nameflags()) do

-- get flag info
Expand All @@ -429,7 +427,6 @@ function builder:_add_flags_from_language(flags, opt)
checkstate = false
end
end

-- get api name of tool
local apiname = flagname:gsub("^nf_", "")

Expand All @@ -453,10 +450,21 @@ function builder:_add_flags_from_language(flags, opt)
opt_.getter = getter
self:_add_items_from_getter(items, flagname, opt_)
end
elseif flagscope == "target" and target and target:type() == "target" then
self:_add_items_from_target(items, flagname, opt_)
elseif flagscope == "target" and target and target:type() == "option" then
self:_add_items_from_option(items, flagname, opt_)
elseif flagscope == "target" and target then
if target:type() == "target" then
self:_add_items_from_target(items, flagname, opt_)
elseif target:type() == "option" then
self:_add_items_from_option(items, flagname, opt_)
elseif target:type() == "package" then
if apiname == "runtime" then
table.insert(items, {
name = "runtime",
values = table.wrap(target:runtimes()),
check = checkstate,
multival = multival,
mapper = mapper})
end
end
elseif flagscope == "config" then
self:_add_items_from_config(items, flagname, opt_)
elseif flagscope == "toolchain" then
Expand Down
21 changes: 12 additions & 9 deletions xmake/modules/core/tools/clang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ function nf_runtime(self, runtime, opt)
end
elseif kind == "ld" or kind == "sh" then
local target = opt.target
if target and target.sourcekinds and table.contains(table.wrap(target:sourcekinds()), "cxx") then
if target then
maps["c++_static"] = "-stdlib=libc++"
maps["c++_shared"] = "-stdlib=libc++"
maps["stdc++_static"] = "-stdlib=libstdc++"
Expand All @@ -290,14 +290,17 @@ function nf_runtime(self, runtime, opt)
maps["c++_static"] = table.join(maps["c++_static"], "-L" .. triple_libdir)
maps["c++_shared"] = table.join(maps["c++_shared"], "-L" .. triple_libdir)
end
-- add rpath to avoid the user need to set LD_LIBRARY_PATH by hand
maps["c++_shared"] = table.join(maps["c++_shared"], nf_rpathdir(self, libdir))
if triple_libdir then
maps["c++_shared"] = table.join(maps["c++_shared"], nf_rpathdir(self, triple_libdir))
end
if target:is_shared() and self:is_plat("macosx", "iphoneos", "watchos") then
maps["c++_shared"] = table.join(maps["c++_shared"], "-install_name")
maps["c++_shared"] = table.join(maps["c++_shared"], "@rpath/" .. target:filename())

if target:type() == "target" then
-- add rpath to avoid the user need to set LD_LIBRARY_PATH by hand
maps["c++_shared"] = table.join(maps["c++_shared"], nf_rpathdir(self, libdir))
if triple_libdir then
maps["c++_shared"] = table.join(maps["c++_shared"], nf_rpathdir(self, triple_libdir))
end
if target:is_shared() and self:is_plat("macosx", "iphoneos", "watchos") then
maps["c++_shared"] = table.join(maps["c++_shared"], "-install_name")
maps["c++_shared"] = table.join(maps["c++_shared"], "@rpath/" .. target:filename())
end
end
end
if runtime:endswith("_static") and _has_static_libstdcxx(self) then
Expand Down

0 comments on commit aa321b0

Please sign in to comment.