Merge pull request #628 from aleksijuvani/no-link-objects-flag

Add NoLinkObjects flag
This commit is contained in:
Tom van Dijck 2016-11-22 09:08:02 -08:00 committed by GitHub
commit 5c1d86ab78
5 changed files with 151 additions and 4 deletions

View File

@ -701,6 +701,12 @@
tokens = true, tokens = true,
} }
api.register {
name = "linkbuildoutputs",
scope = "config",
kind = "boolean"
}
api.register { api.register {
name = "linkoptions", name = "linkoptions",
scope = "config", scope = "config",

View File

@ -257,10 +257,8 @@
for cfg in project.eachconfig(prj) do for cfg in project.eachconfig(prj) do
local filecfg = incfg[cfg] local filecfg = incfg[cfg]
if filecfg then if filecfg then
-- if the custom build outputs an object file, add it to
-- the link step automatically to match Visual Studio
local output = project.getrelative(prj, filecfg.buildoutputs[1]) local output = project.getrelative(prj, filecfg.buildoutputs[1])
if path.isobjectfile(output) then if path.isobjectfile(output) and (filecfg.linkbuildoutputs == true or filecfg.linkbuildoutputs == nil) then
table.insert(configs[cfg].objects, output) table.insert(configs[cfg].objects, output)
else else
table.insert(configs[cfg].customfiles, output) table.insert(configs[cfg].customfiles, output)

View File

@ -719,6 +719,7 @@
m.excludedFromBuild, m.excludedFromBuild,
m.buildCommands, m.buildCommands,
m.buildOutputs, m.buildOutputs,
m.linkObjects,
m.buildMessage, m.buildMessage,
m.buildAdditionalInputs m.buildAdditionalInputs
} }
@ -1104,6 +1105,13 @@
end end
function m.linkObjects(fcfg, condition)
if fcfg.linkbuildoutputs ~= nil then
m.element("LinkObjects", condition, tostring(fcfg.linkbuildoutputs))
end
end
function m.characterSet(cfg) function m.characterSet(cfg)
if not vstudio.isMakefile(cfg) then if not vstudio.isMakefile(cfg) then
m.element("CharacterSet", nil, iif(cfg.characterset == p.MBCS, "MultiByte", "Unicode")) m.element("CharacterSet", nil, iif(cfg.characterset == p.MBCS, "MultiByte", "Unicode"))

View File

@ -110,7 +110,7 @@ OBJECTS := \
-- link automatically to match the behavior of Visual Studio -- link automatically to match the behavior of Visual Studio
-- --
function suite.customBuildRule() function suite.linkBuildOutputs_onNotSpecified()
files { "hello.x" } files { "hello.x" }
filter "files:**.x" filter "files:**.x"
buildmessage "Compiling %{file.name}" buildmessage "Compiling %{file.name}"
@ -137,6 +137,72 @@ endif
end end
--
-- Also include it in the link step if we explicitly specified so with
-- linkbuildoutputs.
--
function suite.linkBuildOutputs_onOn()
files { "hello.x" }
filter "files:**.x"
buildmessage "Compiling %{file.name}"
buildcommands {
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
'c2o -c "%{cfg.objdir}/%{file.basename}.xo" -o "%{cfg.objdir}/%{file.basename}.obj"'
}
buildoutputs { "%{cfg.objdir}/%{file.basename}.obj" }
linkbuildoutputs "On"
prepare()
test.capture [[
OBJECTS := \
RESOURCES := \
CUSTOMFILES := \
ifeq ($(config),debug)
OBJECTS += \
obj/Debug/hello.obj \
endif
]]
end
--
-- If linkbuildoutputs says that we shouldn't include it in the link however,
-- don't do it.
--
function suite.linkBuildOutputs_onOff()
files { "hello.x" }
filter "files:**.x"
buildmessage "Compiling %{file.name}"
buildcommands {
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
'c2o -c "%{cfg.objdir}/%{file.basename}.xo" -o "%{cfg.objdir}/%{file.basename}.obj"'
}
buildoutputs { "%{cfg.objdir}/%{file.basename}.obj" }
linkbuildoutputs "Off"
prepare()
test.capture [[
OBJECTS := \
RESOURCES := \
CUSTOMFILES := \
ifeq ($(config),debug)
CUSTOMFILES += \
obj/Debug/hello.obj \
endif
]]
end
-- --
-- If a file is excluded from a configuration, it should not be listed. -- If a file is excluded from a configuration, it should not be listed.
-- --

View File

@ -333,6 +333,75 @@
end end
--
-- If a custom rule outputs an object file, it's automatically linked, unless
-- we explicitly specify that it isn't with linkbuildoutputs.
--
function suite.linkBuildOutputs_onNotSpecified()
files { "hello.x" }
filter "files:**.x"
buildcommands { "echo $(InputFile)" }
buildoutputs { "$(InputName).obj" }
prepare()
test.capture [[
<ItemGroup>
<CustomBuild Include="hello.x">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">echo $(InputFile)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(InputName).obj</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">echo $(InputFile)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(InputName).obj</Outputs>
</CustomBuild>
</ItemGroup>
]]
end
function suite.linkBuildOutputs_onOff()
files { "hello.x" }
filter "files:**.x"
buildcommands { "echo $(InputFile)" }
buildoutputs { "$(InputName).obj" }
linkbuildoutputs "Off"
prepare()
test.capture [[
<ItemGroup>
<CustomBuild Include="hello.x">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">echo $(InputFile)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(InputName).obj</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkObjects>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">echo $(InputFile)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(InputName).obj</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkObjects>
</CustomBuild>
</ItemGroup>
]]
end
function suite.linkBuildOutputs_onOn()
files { "hello.x" }
filter "files:**.x"
buildcommands { "echo $(InputFile)" }
buildoutputs { "$(InputName).obj" }
linkbuildoutputs "On"
prepare()
test.capture [[
<ItemGroup>
<CustomBuild Include="hello.x">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">echo $(InputFile)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(InputName).obj</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkObjects>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">echo $(InputFile)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(InputName).obj</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</LinkObjects>
</CustomBuild>
</ItemGroup>
]]
end
-- --
-- If two files at different folder levels have the same name, a different -- If two files at different folder levels have the same name, a different
-- object file name should be used for each. -- object file name should be used for each.