Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headeronlylibs part2 #491

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions src/actions/make/make_cpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@
lddeps = libdeps
end

if #libdeps == 0 and not table.icontains(table.translate(cfg.files, path.issourcefile), true) then
return
end

_p(' ALL_LDFLAGS += $(LDFLAGS)%s', make.list(table.join(cc.getlibdirflags(cfg), cc.getldflags(cfg), cfg.linkoptions)))
_p(' LIBDEPS +=%s', libdeps)
_p(' LDDEPS +=%s', lddeps)
Expand Down
6 changes: 5 additions & 1 deletion src/actions/make/make_swift.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ function swift.file_rules(prj, objfiles)
end

function swift.linker(prj, tool)
local lddeps = make.list(premake.getlinks(prj, "siblings", "fullpath"))
local lddeps = make.list(premake.getlinks(prj, "siblings", "fullpath"))

if #lddeps == 0 and not table.icontains(table.translate(prj.files, path.isswiftfile), true) then
return
end

if prj.kind == "StaticLib" then
_p("$(TARGET): $(OBJECTS) %s ", lddeps)
Expand Down
4 changes: 4 additions & 0 deletions src/actions/ninja/ninja_cpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ end
libs = ninja.list(libs) .. " " .. ninja.list(tool.getlinkflags(cfg))
walibs = ninja.list(walibs)

if #objfiles + #lddeps == 0 then
return
end

local function writevars()
_p(1, "all_ldflags = " .. all_ldflags)
_p(1, "libs = " .. libs)
Expand Down
9 changes: 7 additions & 2 deletions src/actions/ninja/ninja_solution.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,22 @@ end
cfgs[key] = cfg:getoutputfilename() .. " "

if not cfgs["all"] then cfgs["all"] = "" end
cfgs["all"] = cfgs["all"] .. cfg:getoutputfilename() .. " "

-- set first configuration name
-- set first configuration name and 'all' configs to build
if (cfg_start == nil) and (cfg.solution.startproject == key) then
cfg_start = key
end
if (cfg_first == nil) and (cfg.kind == "ConsoleApp" or cfg.kind == "WindowedApp") then
cfg_first = key
cfgs["all"] = cfgs["all"] .. cfg:getoutputfilename() .. " "
end
if (cfg_first_lib == nil) and (cfg.kind == "StaticLib" or cfg.kind == "SharedLib") then
cfg_first_lib = key

-- only set if there's actually something to build
if table.icontains(table.translate(cfg.files, path.issourcefile), true) then
cfgs["all"] = cfgs["all"] .. cfg:getoutputfilename() .. " "
end
end

-- include other ninja file
Expand Down
4 changes: 4 additions & 0 deletions src/actions/ninja/ninja_swift.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ local p = premake

function swift.linker(prj, cfg, objfiles, tool)
local lddeps = ninja.list(premake.getlinks(cfg, "siblings", "fullpath"))

if #objfiles + #lddeps == 0 then
return
end

if cfg.kind == "StaticLib" then
_p("build $target: ar %s | %s ", ninja.list(objfiles), lddeps)
Expand Down
6 changes: 5 additions & 1 deletion src/actions/ninja/ninja_swift_incremental.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,13 @@ function swift.linker(prj, cfg, depfiles, tool)

_p("build $out_dir/$module_name.swiftmodule | $out_dir/$module_name.swiftdoc: swiftm %s | %s", table.concat(modfiles, " "), table.concat(docfiles, " "))
_p("")

local output = cfg:getoutputfilename()

if #objfiles + #modfiles + #docfiles == 0 then
return
end

if cfg.kind == "StaticLib" then
local ar_flags = ninja.list(tool.getarchiveflags(cfg, cfg, false))
_p("build %s: ar %s | %s $out_dir/$module_name.swiftmodule $out_dir/$module_name.swiftdoc", output, table.concat(objfiles, " "), lddeps)
Expand Down
19 changes: 18 additions & 1 deletion src/base/project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
if prj and kind ~= "system" then

local prjcfg = premake.getconfig(prj, cfgname, cfg.platform)
if kind == "dependencies" or canlink(cfg, prjcfg) then
if kind == "dependencies" or canlink(cfg, prjcfg) and premake.projectdoeslink(prj, cfgname, cfg.platform) then
if (part == "directory") then
item = path.rebase(prjcfg.linktarget.directory, prjcfg.location, cfg.location)
elseif (part == "basename") then
Expand Down Expand Up @@ -393,6 +393,23 @@
end


--
-- Checks if the project has something to link
--

function premake.projectdoeslink(prj, cfgname, platform)
local prjcfg = premake.getconfig(prj, cfgname, platform)
local lnkobj = table.icontains(table.translate(prjcfg.files, path.issourcefile), true)
local lnkdep = false
if prj.kind ~= 'StaticLib' then
lnkdep = table.icontains(table.translate(prjcfg.links, function(lnk)
local link = premake.findproject(lnk)
return premake.projectdoeslink(link, cfgname, platform)
end), true)
end
return lnkobj or lnkdep
end


--
-- Gets the name style for a configuration, indicating what kind of prefix,
Expand Down