Added application icon support for C# executable projects
This commit is contained in:
parent
47c8a568d4
commit
68287a1437
@ -1,7 +1,7 @@
|
||||
--
|
||||
-- make_csharp.lua
|
||||
-- Generate a C# project makefile.
|
||||
-- Copyright (c) 2002-2012 Jason Perkins and the Premake project
|
||||
-- Copyright (c) 2002-2013 Jason Perkins and the Premake project
|
||||
--
|
||||
|
||||
premake.make.cs = {}
|
||||
@ -17,8 +17,8 @@
|
||||
|
||||
function make.generate_csharp(prj)
|
||||
-- I've only got one .NET toolset right now
|
||||
local toolset = premake.tools.dotnet
|
||||
|
||||
local toolset = premake.tools.dotnet
|
||||
|
||||
make.header(prj)
|
||||
|
||||
-- main build rule(s)
|
||||
@ -59,23 +59,23 @@
|
||||
end
|
||||
_p('')
|
||||
--]]
|
||||
|
||||
|
||||
make.detectshell()
|
||||
|
||||
|
||||
_p('all: $(TARGETDIR) $(OBJDIR) prebuild $(EMBEDFILES) $(COPYFILES) prelink $(TARGET)')
|
||||
_p('')
|
||||
|
||||
|
||||
_p('$(TARGET): $(SOURCES) $(EMBEDFILES) $(DEPENDS)')
|
||||
_p('\t$(SILENT) $(CSC) /nologo /out:$@ $(FLAGS) $(REFERENCES) $(SOURCES) $(patsubst %%,/resource:%%,$(EMBEDFILES))')
|
||||
_p('\t$(POSTBUILDCMDS)')
|
||||
_p('')
|
||||
|
||||
|
||||
make.mkdirrule("$(TARGETDIR)")
|
||||
make.mkdirrule("$(OBJDIR)")
|
||||
|
||||
|
||||
-- clean target
|
||||
local target = firstcfg.buildtarget
|
||||
|
||||
|
||||
_p('clean:')
|
||||
_p('\t@echo Cleaning %s', prj.name)
|
||||
_p('ifeq (posix,$(SHELLTYPE))')
|
||||
@ -94,12 +94,12 @@
|
||||
_p('\t$(SILENT) if exist $(subst /,\\\\,$(OBJDIR)) rmdir /s /q $(subst /,\\\\,$(OBJDIR))')
|
||||
_p('endif')
|
||||
_p('')
|
||||
|
||||
|
||||
-- custom build step targets
|
||||
_p('prebuild:')
|
||||
_p('\t$(PREBUILDCMDS)')
|
||||
_p('')
|
||||
|
||||
|
||||
_p('prelink:')
|
||||
_p('\t$(PRELINKCMDS)')
|
||||
_p('')
|
||||
@ -115,14 +115,14 @@
|
||||
_p('endif')
|
||||
_p('')
|
||||
end
|
||||
|
||||
|
||||
_p('# Copied file rules')
|
||||
for target, source in pairs(copypairs) do
|
||||
premake.make_copyrule(source, target)
|
||||
end
|
||||
|
||||
_p('# Embedded file rules')
|
||||
for _, fname in ipairs(embedded) do
|
||||
for _, fname in ipairs(embedded) do
|
||||
if path.getextension(fname) == ".resx" then
|
||||
_p('%s: %s', getresourcefilename(prj, fname), _MAKE.esc(fname))
|
||||
_p('\t$(SILENT) $(RESGEN) $^ $@')
|
||||
@ -139,46 +139,46 @@
|
||||
|
||||
function cs.config(cfg, toolset)
|
||||
_p('ifeq ($(config),%s)', make.esc(cfg.shortname))
|
||||
|
||||
|
||||
-- write toolset specific configurations
|
||||
cs.toolconfig(cfg, toolset)
|
||||
|
||||
-- write target information (target dir, name, obj dir)
|
||||
make.targetconfig(cfg)
|
||||
|
||||
|
||||
-- write flags
|
||||
cs.flags(cfg, toolset)
|
||||
|
||||
-- write the linking information
|
||||
cs.linking(cfg, toolset)
|
||||
|
||||
-- write the custom build commands
|
||||
-- write the custom build commands
|
||||
_p(' define PREBUILDCMDS')
|
||||
if #cfg.prebuildcommands > 0 then
|
||||
_p('\t@echo Running pre-build commands')
|
||||
_p('\t%s', table.implode(cfg.prebuildcommands, "", "", "\n\t"))
|
||||
end
|
||||
_p(' endef')
|
||||
|
||||
|
||||
_p(' define PRELINKCMDS')
|
||||
if #cfg.prelinkcommands > 0 then
|
||||
_p('\t@echo Running pre-link commands')
|
||||
_p('\t%s', table.implode(cfg.prelinkcommands, "", "", "\n\t"))
|
||||
end
|
||||
_p(' endef')
|
||||
|
||||
|
||||
_p(' define POSTBUILDCMDS')
|
||||
if #cfg.postbuildcommands > 0 then
|
||||
_p('\t@echo Running post-build commands')
|
||||
_p('\t%s', table.implode(cfg.postbuildcommands, "", "", "\n\t"))
|
||||
end
|
||||
_p(' endef')
|
||||
|
||||
|
||||
-- write out config-level makesettings blocks
|
||||
make.settings(cfg, toolset)
|
||||
|
||||
|
||||
_p('endif')
|
||||
_p('')
|
||||
_p('')
|
||||
end
|
||||
|
||||
|
||||
@ -187,9 +187,7 @@
|
||||
--
|
||||
|
||||
function cs.flags(cfg, toolset)
|
||||
local defines = table.implode(cfg.defines, "/d:", "", " ")
|
||||
local flags = table.join(defines, toolset.getflags(cfg), cfg.buildoptions)
|
||||
_p(' FLAGS = %s', table.concat(flags, " "))
|
||||
_p(' FLAGS =%s', make.list(toolset.getflags(cfg)))
|
||||
end
|
||||
|
||||
|
||||
@ -197,12 +195,12 @@
|
||||
-- Given a .resx resource file, builds the path to corresponding .resource
|
||||
-- file, matching the behavior and naming of Visual Studio.
|
||||
--
|
||||
|
||||
|
||||
function cs.getresourcefilename(cfg, fname)
|
||||
if path.getextension(fname) == ".resx" then
|
||||
local name = cfg.buildtarget.basename .. "."
|
||||
local dir = path.getdirectory(fname)
|
||||
if dir ~= "." then
|
||||
if dir ~= "." then
|
||||
name = name .. path.translate(dir, ".") .. "."
|
||||
end
|
||||
return "$(OBJDIR)/" .. make.esc(name .. path.getbasename(fname)) .. ".resources"
|
||||
@ -236,7 +234,7 @@
|
||||
_p('\t%s \\', make.esc(path.translate(value)))
|
||||
end
|
||||
end
|
||||
})
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
@ -247,9 +245,9 @@
|
||||
|
||||
function cs.prj_config(cfg, toolset)
|
||||
local kindflag = "/t:" .. toolset.getkind(cfg):lower()
|
||||
local libdirs = table.implode(make.esc(cfg.libdirs), "/lib:", "", " ")
|
||||
local libdirs = table.implode(make.esc(cfg.libdirs), "/lib:", "", " ")
|
||||
_p('FLAGS += %s', table.concat(table.join(kindflag, libdirs), " "))
|
||||
|
||||
|
||||
local refs = make.esc(config.getlinks(cfg, "system", "fullpath"))
|
||||
_p('REFERENCES += %s', table.implode(refs, "/r:", "", " "))
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
--
|
||||
-- vs2005_csproj.lua
|
||||
-- Generate a Visual Studio 2005/2008 C# project.
|
||||
-- Copyright (c) 2009-2012 Jason Perkins and the Premake project
|
||||
-- Generate a Visual Studio 2005-2010 C# project.
|
||||
-- Copyright (c) 2009-2013 Jason Perkins and the Premake project
|
||||
--
|
||||
|
||||
premake.vstudio.cs2005 = {}
|
||||
@ -19,7 +19,7 @@
|
||||
function cs2005.generate_ng(prj)
|
||||
io.eol = "\r\n"
|
||||
io.indent = " "
|
||||
|
||||
|
||||
cs2005.projectelement(prj)
|
||||
cs2005.projectsettings(prj)
|
||||
|
||||
@ -28,9 +28,10 @@
|
||||
cs2005.debugProps(cfg)
|
||||
cs2005.outputProps(cfg)
|
||||
cs2005.compilerProps(cfg)
|
||||
_p(1,'</PropertyGroup>')
|
||||
_p(1,'</PropertyGroup>')
|
||||
end
|
||||
|
||||
cs2005.applicationIcon(prj)
|
||||
cs2005.assemblyReferences(prj)
|
||||
|
||||
_p(1,'<ItemGroup>')
|
||||
@ -84,24 +85,24 @@
|
||||
vs2010 = '8.0.30703',
|
||||
vs2012 = '8.0.30703',
|
||||
}
|
||||
|
||||
|
||||
local frameworks = {
|
||||
vs2010 = "4.0",
|
||||
vs2012 = "4.5",
|
||||
}
|
||||
|
||||
_p(1,'<PropertyGroup>')
|
||||
|
||||
|
||||
-- find the first configuration in the project, use as the default
|
||||
local cfg = project.getfirstconfig(prj)
|
||||
|
||||
|
||||
_p(2,'<Configuration Condition=" \'$(Configuration)\' == \'\' ">%s</Configuration>', premake.esc(cfg.buildcfg))
|
||||
_p(2,'<Platform Condition=" \'$(Platform)\' == \'\' ">%s</Platform>', cs2005.arch(prj))
|
||||
|
||||
|
||||
_p(2,'<ProductVersion>%s</ProductVersion>', version[_ACTION])
|
||||
_p(2,'<SchemaVersion>2.0</SchemaVersion>')
|
||||
_p(2,'<ProjectGuid>{%s}</ProjectGuid>', prj.uuid)
|
||||
|
||||
|
||||
_p(2,'<OutputType>%s</OutputType>', dotnet.getkind(cfg))
|
||||
_p(2,'<AppDesignerFolder>Properties</AppDesignerFolder>')
|
||||
|
||||
@ -118,7 +119,7 @@
|
||||
_p(2,'<TargetFrameworkProfile></TargetFrameworkProfile>')
|
||||
_p(2,'<FileAlignment>512</FileAlignment>')
|
||||
end
|
||||
|
||||
|
||||
_p(1,'</PropertyGroup>')
|
||||
end
|
||||
|
||||
@ -139,7 +140,7 @@
|
||||
local action = dotnet.getbuildaction(filecfg)
|
||||
local fname = path.translate(node.relpath)
|
||||
local elements, dependency = cs2005.getrelated(prj, filecfg, action)
|
||||
|
||||
|
||||
if elements == "None" then
|
||||
_p(2,'<%s Include="%s" />', action, fname)
|
||||
else
|
||||
@ -180,8 +181,8 @@
|
||||
|
||||
if #prj.prebuildcommands > 0 or #prj.postbuildcommands > 0 then
|
||||
_p(1,'<PropertyGroup>')
|
||||
output("Pre", prj.prebuildcommands)
|
||||
output("Post", prj.postbuildcommands)
|
||||
output("Pre", prj.prebuildcommands)
|
||||
output("Post", prj.postbuildcommands)
|
||||
_p(1,'</PropertyGroup>')
|
||||
end
|
||||
end
|
||||
@ -200,7 +201,7 @@
|
||||
if cfg.flags.Unsafe then
|
||||
_p(2,'<AllowUnsafeBlocks>true</AllowUnsafeBlocks>')
|
||||
end
|
||||
|
||||
|
||||
if cfg.flags.FatalWarnings then
|
||||
_p(2,'<TreatWarningsAsErrors>true</TreatWarningsAsErrors>')
|
||||
end
|
||||
@ -229,7 +230,7 @@
|
||||
function cs2005.outputProps(cfg)
|
||||
local outdir = project.getrelative(cfg.project, cfg.buildtarget.directory)
|
||||
_x(2,'<OutputPath>%s\\</OutputPath>', path.translate(outdir))
|
||||
|
||||
|
||||
-- Want to set BaseIntermediateOutputPath because otherwise VS will create obj/
|
||||
-- anyway. But VS2008 throws up ominous warning if present.
|
||||
local objdir = path.translate(project.getrelative(cfg.project, cfg.objdir))
|
||||
@ -266,7 +267,7 @@
|
||||
if project.hasfile(prj, testname) then
|
||||
return "Dependency", testname
|
||||
end
|
||||
|
||||
|
||||
-- is there a matching *.resx file
|
||||
testname = basename .. ".resx"
|
||||
if project.hasfile(prj, testname) then
|
||||
@ -279,13 +280,13 @@
|
||||
if project.hasfile(prj, testname) then
|
||||
return "Form"
|
||||
end
|
||||
|
||||
|
||||
if filecfg.flags and filecfg.flags.Component then
|
||||
return "Component"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if action == "EmbeddedResource" and fname:endswith(".resx") then
|
||||
local basename = fname:sub(1, -6)
|
||||
|
||||
@ -305,11 +306,11 @@
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if action == "Content" then
|
||||
return "PreserveNewest"
|
||||
end
|
||||
|
||||
|
||||
return "None"
|
||||
end
|
||||
|
||||
@ -333,11 +334,11 @@
|
||||
_x(2,'<Reference Include="%s" />', path.getbasename(link))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
_p(1,'</ItemGroup>')
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Write the list of project dependencies.
|
||||
--
|
||||
@ -346,7 +347,7 @@
|
||||
|
||||
local deps = project.getdependencies(prj)
|
||||
if #deps > 0 then
|
||||
local prjpath = project.getlocation(prj)
|
||||
local prjpath = project.getlocation(prj)
|
||||
for _, dep in ipairs(deps) do
|
||||
local relpath = path.getrelative(prjpath, vstudio.projectfile(dep))
|
||||
_x(2,'<ProjectReference Include="%s">', path.translate(relpath))
|
||||
@ -355,14 +356,14 @@
|
||||
_p(2,'</ProjectReference>')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
_p(1,'</ItemGroup>')
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Return the Visual Studio architecture identification string. The logic
|
||||
-- to select this is getting more complicated in VS2010, but I haven't
|
||||
-- to select this is getting more complicated in VS2010, but I haven't
|
||||
-- tackled all the permutations yet.
|
||||
--
|
||||
|
||||
@ -386,3 +387,18 @@
|
||||
_x(2,'<PlatformTarget>%s</PlatformTarget>', arch)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Generators for individual project elements.
|
||||
--
|
||||
|
||||
function cs2005.applicationIcon(prj)
|
||||
if prj.icon then
|
||||
local icon = path.translate(project.getrelative(prj, prj.icon))
|
||||
_p(1,'<PropertyGroup>')
|
||||
_x(2,'<ApplicationIcon>%s</ApplicationIcon>', icon)
|
||||
_p(1,'</PropertyGroup>')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -692,6 +692,13 @@
|
||||
},
|
||||
}
|
||||
|
||||
api.register {
|
||||
name = "icon",
|
||||
scope = "project",
|
||||
kind = "file",
|
||||
tokens = true,
|
||||
}
|
||||
|
||||
api.register {
|
||||
name = "imageoptions",
|
||||
scope = "config",
|
||||
|
@ -1,15 +1,16 @@
|
||||
--
|
||||
-- dotnet.lua
|
||||
-- Interface for the C# compilers, all of which are flag compatible.
|
||||
-- Copyright (c) 2002-2009 Jason Perkins and the Premake project
|
||||
-- Copyright (c) 2002-2013 Jason Perkins and the Premake project
|
||||
--
|
||||
|
||||
|
||||
|
||||
premake.tools.dotnet = {}
|
||||
local dotnet = premake.tools.dotnet
|
||||
|
||||
local project = premake5.project
|
||||
|
||||
dotnet.namestyle = "windows"
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Translation of Premake flags into CSC flags
|
||||
@ -42,8 +43,8 @@
|
||||
return "None"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Retrieves the executable command name for a tool, based on the
|
||||
@ -66,7 +67,7 @@
|
||||
pnet = "cscc",
|
||||
}
|
||||
|
||||
if tool == "csc" then
|
||||
if tool == "csc" then
|
||||
local toolset = _OPTIONS.dotnet or iif(os.is(premake.WINDOWS), "msnet", "mono")
|
||||
return compilers[toolset]
|
||||
else
|
||||
@ -81,8 +82,19 @@
|
||||
--
|
||||
|
||||
function dotnet.getflags(cfg)
|
||||
local result = table.translate(cfg.flags, flags)
|
||||
return result
|
||||
local flags = {}
|
||||
|
||||
if cfg.project.icon then
|
||||
local fn = project.getrelative(cfg.project, cfg.project.icon)
|
||||
table.insert(flags, string.format('/win32icon:"%s"', fn))
|
||||
end
|
||||
|
||||
if #cfg.defines > 0 then
|
||||
table.insert(flags, table.implode(cfg.defines, "/d:", "", " "))
|
||||
end
|
||||
|
||||
flags = table.join(flags, table.translate(cfg.flags, flags), cfg.buildoptions)
|
||||
return flags
|
||||
end
|
||||
|
||||
|
||||
|
52
tests/actions/make/cs/test_flags.lua
Normal file
52
tests/actions/make/cs/test_flags.lua
Normal file
@ -0,0 +1,52 @@
|
||||
--
|
||||
-- tests/actions/make/cs/test_flags.lua
|
||||
-- Tests compiler and linker flags for C# Makefiles.
|
||||
-- Copyright (c) 2013 Jason Perkins and the Premake project
|
||||
--
|
||||
|
||||
local suite = test.declare("make_cs_flags")
|
||||
local make = premake.make
|
||||
local cs = premake.make.cs
|
||||
local project = premake5.project
|
||||
|
||||
|
||||
--
|
||||
-- Setup
|
||||
--
|
||||
|
||||
local sln, prj, cfg
|
||||
|
||||
function suite.setup()
|
||||
sln = test.createsolution()
|
||||
end
|
||||
|
||||
local function prepare()
|
||||
prj = premake.solution.getproject_ng(sln, 1)
|
||||
cfg = project.getconfig(prj, "Debug")
|
||||
cs.flags(cfg, premake.tools.dotnet)
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Should return an empty assignment if nothing has been specified.
|
||||
--
|
||||
|
||||
function suite.isEmptyAssignment_onNoSettings()
|
||||
prepare()
|
||||
test.capture [[
|
||||
FLAGS =
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- If an application icon has been set, it should be specified.
|
||||
--
|
||||
|
||||
function suite.onApplicationIcon()
|
||||
icon "MyProject.ico"
|
||||
prepare()
|
||||
test.capture [[
|
||||
FLAGS = /win32icon:"MyProject.ico"
|
||||
]]
|
||||
end
|
49
tests/actions/vstudio/cs2005/test_icon.lua
Normal file
49
tests/actions/vstudio/cs2005/test_icon.lua
Normal file
@ -0,0 +1,49 @@
|
||||
--
|
||||
-- tests/actions/vstudio/cs2005/test_icon.lua
|
||||
-- Validate generation of the application icon declaration.
|
||||
-- Copyright (c) 2013 Jason Perkins and the Premake project
|
||||
--
|
||||
|
||||
local suite = test.declare("vstudio_cs2005_icon")
|
||||
local cs2005 = premake.vstudio.cs2005
|
||||
|
||||
|
||||
--
|
||||
-- Setup
|
||||
--
|
||||
|
||||
local sln
|
||||
|
||||
function suite.setup()
|
||||
sln, prj = test.createsolution()
|
||||
end
|
||||
|
||||
local function prepare()
|
||||
prj = premake.solution.getproject_ng(sln, 1)
|
||||
cs2005.applicationIcon(prj)
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- By default, there should be no output.
|
||||
--
|
||||
|
||||
function suite.noOutput_onNoIcon()
|
||||
prepare()
|
||||
test.isemptycapture()
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- If an icon is specified, output the property group.
|
||||
--
|
||||
|
||||
function suite.doesOutput_onIcon()
|
||||
icon "MyApp.ico"
|
||||
prepare()
|
||||
test.capture [[
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>MyApp.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
]]
|
||||
end
|
@ -98,6 +98,7 @@
|
||||
dofile("actions/vstudio/cs2005/test_compiler_props.lua")
|
||||
dofile("actions/vstudio/cs2005/test_debug_props.lua")
|
||||
dofile("actions/vstudio/cs2005/test_files.lua")
|
||||
dofile("actions/vstudio/cs2005/test_icon.lua")
|
||||
dofile("actions/vstudio/cs2005/test_output_props.lua")
|
||||
dofile("actions/vstudio/cs2005/projectelement.lua")
|
||||
dofile("actions/vstudio/cs2005/test_platform_groups.lua")
|
||||
@ -166,6 +167,9 @@
|
||||
dofile("actions/make/cpp/test_target_rules.lua")
|
||||
dofile("actions/make/cpp/test_wiidev.lua")
|
||||
|
||||
-- Makefile C# projects
|
||||
dofile("actions/make/cs/test_flags.lua")
|
||||
|
||||
|
||||
--
|
||||
-- Register a test action
|
||||
|
Loading…
Reference in New Issue
Block a user