Non-standard Premake4 patches from Yves (plus minor tweaks).

Add nasm support.
Add cxxtest support.
Some other fixes.

This was SVN commit r9829.
This commit is contained in:
Ykkrosh 2011-07-15 17:48:21 +00:00
parent fcab9e3b5e
commit 76ff2cc83a
6 changed files with 258 additions and 37 deletions

View File

@ -26,7 +26,7 @@
-- list intermediate files
_p('OBJECTS := \\')
for _, file in ipairs(prj.files) do
if path.iscppfile(file) then
if path.iscppfile(file) or path.getextension(file) == ".asm" then
_p('\t$(OBJDIR)/%s.o \\', _MAKE.esc(path.getbasename(file)))
end
end
@ -55,15 +55,15 @@
_p('')
if os.is("MacOSX") and prj.kind == "WindowedApp" then
_p('all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist')
_p('all: $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist')
else
_p('all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)')
_p('all: $(TARGET)')
end
_p('\t@:')
_p('')
-- target build rule
_p('$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES)')
_p('$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES) | prelink')
_p('\t@echo Linking %s', prj.name)
_p('\t$(SILENT) $(LINKCMD)')
_p('\t$(POSTBUILDCMDS)')
@ -97,7 +97,7 @@
_p('')
-- custom build step targets
_p('prebuild:')
_p('prebuild: $(TARGETDIR) $(OBJDIR)')
_p('\t$(PREBUILDCMDS)')
_p('')
@ -111,7 +111,7 @@
-- per-file rules
for _, file in ipairs(prj.files) do
if path.iscppfile(file) then
_p('$(OBJDIR)/%s.o: %s', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file))
_p('$(OBJDIR)/%s.o: %s | prebuild', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file))
_p('\t@echo $(notdir $<)')
if (path.iscfile(file)) then
_p('\t$(SILENT) $(CC) $(CFLAGS) -o "$@" -c "$<"')
@ -122,9 +122,56 @@
_p('$(OBJDIR)/%s.res: %s', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file))
_p('\t@echo $(notdir $<)')
_p('\t$(SILENT) windres $< -O coff -o "$@" $(RESFLAGS)')
elseif (path.getextension(file) == ".asm") then
_p('$(OBJDIR)/%s.o: %s', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file))
_p('\t@echo $(notdir $<)')
local opts = ''
if os.is('windows') then
opts = ''
elseif os.is('macosx') then
opts = '-D OS_UNIX=1'
else
opts = '-D DONT_USE_UNDERLINE=1 -D OS_UNIX=1'
end
if not (prj.solution.nasmpath) then
prj.solution.nasmpath = 'nasm'
end
_p('\t$(SILENT)'.._MAKE.esc(prj.solution.nasmpath)..' '..opts..' -i'.._MAKE.esc(path.getdirectory(file))..'/'..' -f '..
_MAKE.esc(prj.solution.nasmformat)..' -o $@ $<\n\t')
_p('\t$(SILENT)'.._MAKE.esc(prj.solution.nasmpath)..' '..opts..' -i'.._MAKE.esc(path.getdirectory(file))..'/'..
' -M -o $@ $< >$(OBJDIR)/$(<F:%%.asm=%%.d)\n')
end
end
_p('')
-- output for test-generation
-- test generation only works if all required parameters are set!
if(prj.solution.cxxtestpath and prj.cxxtestrootfile and prj.cxxtesthdrfiles and prj.cxxtestsrcfiles) then
if not(prj.cxxtestrootoptions) then
prj.cxxtestrootoptions = ''
end
if not(prj.cxxtestoptions) then
prj.cxxtestoptions = ''
end
_p(prj.cxxtestrootfile..': ')
_p('\t@echo $(notdir $<)')
_p('\t$(SILENT)'.._MAKE.esc(prj.solution.cxxtestpath)..' --root '..prj.cxxtestrootoptions..' -o '.._MAKE.esc(prj.cxxtestrootfile))
_p('')
for i, file in ipairs(prj.cxxtesthdrfiles) do
_p('%s: %s', _MAKE.esc(prj.cxxtestsrcfiles[i]), _MAKE.esc(file))
_p('\t@echo $(notdir $<)')
_p('\t$(SILENT)'.._MAKE.esc(prj.solution.cxxtestpath)..' --part '..prj.cxxtestoptions..' -o ' .._MAKE.esc(prj.cxxtestsrcfiles[i])..' '.._MAKE.esc(file))
end
_p('')
end
_p('')
-- include the dependencies, built by GCC (with the -MMD flag)
_p('-include $(OBJECTS:%%.o=%%.d)')
@ -174,6 +221,7 @@
function premake.gmake_cpp_config(cfg, cc)
_p('ifeq ($(config),%s)', _MAKE.esc(cfg.shortname))
-- if this platform requires a special compiler or linker, list it now
local platform = cc.platforms[cfg.platform]
@ -186,6 +234,9 @@
if platform.ar then
_p(' AR = %s', platform.ar)
end
if not(cfg.gnuexternals) then
cfg.gnuexternal = { }
end
_p(' OBJDIR = %s', _MAKE.esc(cfg.objectsdir))
_p(' TARGETDIR = %s', _MAKE.esc(cfg.buildtarget.directory))
@ -200,7 +251,7 @@
_p(' CFLAGS += $(CPPFLAGS) $(ARCH) %s', table.concat(table.join(cc.getcflags(cfg), cfg.buildoptions), " "))
_p(' CXXFLAGS += $(CFLAGS) %s', table.concat(cc.getcxxflags(cfg), " "))
_p(' LDFLAGS += %s', table.concat(table.join(cc.getldflags(cfg), cfg.linkoptions, cc.getlibdirflags(cfg)), " "))
_p(' LIBS += %s', table.concat(cc.getlinkflags(cfg), " "))
_p(' LIBS += %s %s', table.concat(cc.getlinkflags(cfg), " "), table.concat(cfg.gnuexternals, " "))
_p(' RESFLAGS += $(DEFINES) $(INCLUDES) %s', table.concat(table.join(cc.getdefines(cfg.resdefines), cc.getincludedirs(cfg.resincludedirs), cfg.resoptions), " "))
_p(' LDDEPS += %s', table.concat(_MAKE.esc(premake.getlinks(cfg, "siblings", "fullpath")), " "))
@ -213,7 +264,16 @@
else
-- this was $(TARGET) $(LDFLAGS) $(OBJECTS) ... but was having trouble linking to certain
-- static libraries so $(OBJECTS) was moved up
_p(' LINKCMD = $(%s) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(ARCH) $(LIBS)', iif(cfg.language == "C", "CC", "CXX"))
local lddeps = ''
-- on osx, --start-group and --end-group aren't supported by ld
if os.is('macosx') then
lddeps = '$(LDDEPS)'
else
lddeps = '-Xlinker --start-group $(LDDEPS) -Xlinker --end-group'
end
_p(' LINKCMD = $(%s) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(ARCH) %s $(LIBS)',
iif(cfg.language == "C", "CC", "CXX"), lddeps)
end
_p(' define PREBUILDCMDS')
@ -256,7 +316,7 @@
function _.pchrules(prj)
_p('ifneq (,$(PCH))')
_p('$(GCH): $(PCH)')
_p('$(GCH): $(PCH) | $(OBJDIR)')
_p('\t@echo $(notdir $<)')
_p('\t-$(SILENT) cp $< $(OBJDIR)')
if prj.language == "C" then

View File

@ -227,6 +227,37 @@
end
end
end
if (path.getextension(fname) == ".asm") then
for _, cfginfo in ipairs(prj.solution.vstudio_configs) do
if cfginfo.isreal then
-- set defaults if required parameters are not set
if not (prj.solution.nasmformat) then
prj.solution.nasmformat = 'win32'
end
if not (prj.solution.nasmpath) then
prj.solution.nasmpath = 'nasm'
end
local nasmpath = path.translate(path.getrelative(prj.location, prj.solution.nasmpath), "\\")
local command = nasmpath.." -i "..path.translate(path.getdirectory(fname), "\\").."\\ -f "..prj.solution.nasmformat..
" &quot;$(InputPath)&quot; -o &quot;$(IntDir)\$(InputName).obj&quot;"
output(indent, "\t<FileConfiguration")
attrib(indent, "\tName", cfginfo.name)
output(indent, "\t\t>")
output(indent, "\t\t<Tool")
attrib(indent, "\t\tName", "VCCustomBuildTool")
attrib(indent, "\t\tDescription", "Assembling $(InputPath)")
attrib(indent, "\t\tCommandLine", command)
attrib(indent, "\t\tOutputs", "$(IntDir)\$(InputName).obj")
output(indent, "\t\t/>")
output(indent, "\t</FileConfiguration>")
end
end
end
output(indent, "</File>")
end
end
@ -455,4 +486,4 @@
oncleansolution = premake.vstudio.cleansolution,
oncleanproject = premake.vstudio.cleanproject,
oncleantarget = premake.vstudio.cleantarget
}
}

View File

@ -4,14 +4,15 @@ local vs10_helpers = premake.vstudio.vs10_helpers
function vs10_helpers.remove_relative_path(file)
file = file:gsub("%.%.\\",'')
file = file:gsub("%.\\",'')
file = file:gsub("%.%./",'')
file = file:gsub("%./",'')
file = file:gsub("^source/",'')
return file
end
function vs10_helpers.file_path(file)
file = vs10_helpers.remove_relative_path(file)
local path = string.find(file,'\\[%w%.%_%-]+$')
local path = string.find(file,'/[%w%.%_%-]+$')
if path then
return string.sub(file,1,path-1)
else
@ -23,11 +24,11 @@ local vs10_helpers = premake.vstudio.vs10_helpers
local list={}
path = vs10_helpers.remove_relative_path(path)
if path then
for dir in string.gmatch(path,"[%w%-%_%.]+\\")do
for dir in string.gmatch(path,"[%w%-%_%.]+/")do
if #list == 0 then
list[1] = dir:sub(1,#dir-1)
else
list[#list +1] = list[#list] .."\\" ..dir:sub(1,#dir-1)
list[#list +1] = list[#list] .."/" ..dir:sub(1,#dir-1)
end
end
end
@ -59,8 +60,6 @@ local vs10_helpers = premake.vstudio.vs10_helpers
end
--also translates file paths from '/' to '\\'
function vs10_helpers.sort_input_files(files,sorted_container)
local types =
{
@ -71,18 +70,18 @@ local vs10_helpers = premake.vstudio.vs10_helpers
cpp = "ClCompile",
cxx = "ClCompile",
cc = "ClCompile",
rc = "ResourceCompile"
rc = "ResourceCompile",
asm = "ClASM"
}
for _, current_file in ipairs(files) do
local translated_path = path.translate(current_file, '\\')
local ext = vs10_helpers.get_file_extension(translated_path)
local ext = vs10_helpers.get_file_extension(current_file)
if ext then
local type = types[ext]
if type then
table.insert(sorted_container[type],translated_path)
table.insert(sorted_container[type],current_file)
else
table.insert(sorted_container.None,translated_path)
table.insert(sorted_container.None,current_file)
end
end
end
@ -388,16 +387,23 @@ local vs10_helpers = premake.vstudio.vs10_helpers
end
local function event_hooks(cfg)
local function event_hooks(cfg, prj)
if #cfg.postbuildcommands> 0 then
_p(2,'<PostBuildEvent>')
_p(3,'<Command>%s</Command>',premake.esc(table.implode(cfg.postbuildcommands, "", "", "\r\n")))
_p(2,'</PostBuildEvent>')
end
if #cfg.prebuildcommands> 0 then
if #cfg.prebuildcommands> 0 or prj.cxxtestrootfile then
_p(2,'<PreBuildEvent>')
_p(3,'<Command>%s</Command>',premake.esc(table.implode(cfg.prebuildcommands, "", "", "\r\n")))
-- test generation only works if all required parameters are set!
if(prj.solution.cxxtestpath and prj.cxxtestrootfile and prj.cxxtesthdrfiles and prj.cxxtestsrcfiles) then
local cxxtestpath = path.translate(path.getrelative(prj.location, prj.solution.cxxtestpath),"\\")
local cxxtestrootfile = path.translate(prj.cxxtestrootfile,"\\")
_p(3,'<Command>%s --root %s &gt; %s</Command>', cxxtestpath, prj.cxxtestrootoptions, cxxtestrootfile)
end
_p(2,'</PreBuildEvent>')
end
@ -503,10 +509,8 @@ local vs10_helpers = premake.vstudio.vs10_helpers
resource_compile(cfg)
item_def_lib(cfg)
item_link(cfg)
event_hooks(cfg)
event_hooks(cfg, prj)
_p(1,'</ItemDefinitionGroup>')
end
end
@ -518,34 +522,50 @@ local vs10_helpers = premake.vstudio.vs10_helpers
-- <Project>{8fd826f8-3739-44e6-8cc8-997122e53b8d}</Project>
-- </ProjectReference>
-- </ItemGroup>
--
local function write_cxxtestgen_block(prj)
-- test generation only works if all required parameters are set!
if(prj.solution.cxxtestpath and prj.cxxtestrootfile and prj.cxxtesthdrfiles and prj.cxxtestsrcfiles) then
local cxxtestpath = path.translate(path.getrelative(prj.location, prj.solution.cxxtestpath),"\\")
_p(1,'<ItemGroup>')
for i, file in ipairs(prj.cxxtesthdrfiles) do
local cxxtesthdrfile = path.translate(file,"\\")
local cxxtestsrcfile = path.translate(prj.cxxtestsrcfiles[i],"\\")
_p(2,'<CustomBuild Include=\"%s\">', cxxtesthdrfile)
_p(3,'<Message>Generating %s</Message>', path.getname(prj.cxxtestsrcfiles[i]))
_p(3,'<Command>%s --part %s -o \"%s\" \"%s\"</Command>',
cxxtestpath, prj.cxxtestoptions, cxxtestsrcfile, cxxtesthdrfile)
_p(3,'<Outputs>%s;%%(Outputs)</Outputs>', cxxtestsrcfile)
_p(2,'</CustomBuild>')
end
_p(1,'</ItemGroup>')
end
end
local function write_file_type_block(files,group_type)
if #files > 0 then
_p(1,'<ItemGroup>')
for _, current_file in ipairs(files) do
_p(2,'<%s Include=\"%s\" />', group_type,current_file)
_p(2,'<%s Include=\"%s\" />', group_type,path.translate(current_file,"\\"))
end
_p(1,'</ItemGroup>')
end
end
local function write_file_compile_block(files,prj,configs)
if #files > 0 then
local config_mappings = {}
for _, cfginfo in ipairs(configs) do
local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)
if cfg.pchheader and cfg.pchsource and not cfg.flags.NoPCH then
config_mappings[cfginfo] = path.translate(cfg.pchsource, "\\")
config_mappings[cfginfo] = cfg.pchsource
end
end
_p(1,'<ItemGroup>')
for _, current_file in ipairs(files) do
_p(2,'<ClCompile Include=\"%s\">', current_file)
_p(2,'<ClCompile Include=\"%s\">', path.translate(current_file, "\\"))
for _, cfginfo in ipairs(configs) do
if config_mappings[cfginfo] and current_file == config_mappings[cfginfo] then
_p(3,'<PrecompiledHeader '.. if_config_and_platform() .. '>Create</PrecompiledHeader>'
@ -559,6 +579,33 @@ local vs10_helpers = premake.vstudio.vs10_helpers
_p(1,'</ItemGroup>')
end
end
local function write_nasm_asm_block(files, prj, configs)
-- set defaults if required parameters are not set
if not (prj.solution.nasmformat) then
prj.solution.nasmformat = 'win32'
end
if not (prj.solution.nasmpath) then
prj.solution.nasmpath = 'nasm'
end
if #files > 0 then
_p(1,'<ItemGroup>')
local nasmpath = path.translate(path.getrelative(prj.location, prj.solution.nasmpath),"\\")
for _, current_file in ipairs(files) do
_p(2,'<CustomBuild Include=\"%s\">', path.translate(current_file,"\\"))
_p(3,'<Message>Assembling %%(FullPath)</Message>')
_p(3,'<Command>%s -i %s -f %s \"%%(FullPath)\" -o \"$(IntDir)%%(Filename).obj\"</Command>',
nasmpath,
path.translate(path.getdirectory(current_file),"\\").."\\",
prj.solution.nasmformat)
_p(3,'<Outputs>$(IntDir)%%(Filename).obj;%%(Outputs)</Outputs>')
_p(2,'</CustomBuild>')
end
_p(1,'</ItemGroup>')
end
end
local function vcxproj_files(prj)
@ -566,14 +613,17 @@ local vs10_helpers = premake.vstudio.vs10_helpers
{
ClCompile ={},
ClInclude ={},
ClASM ={},
None ={},
ResourceCompile ={}
}
cfg = premake.getconfig(prj)
vs10_helpers.sort_input_files(cfg.files,sorted)
write_cxxtestgen_block(prj)
write_file_type_block(sorted.ClInclude,"ClInclude")
write_file_compile_block(sorted.ClCompile,prj,prj.solution.vstudio_configs)
write_nasm_asm_block(sorted.ClASM, prj, prj.solution.vstudion_configs)
write_file_type_block(sorted.None,'None')
write_file_type_block(sorted.ResourceCompile,'ResourceCompile')
@ -587,7 +637,7 @@ local vs10_helpers = premake.vstudio.vs10_helpers
if #directories >0 then
_p(1,'<ItemGroup>')
for _, dir in pairs(directories) do
_p(2,'<Filter Include="%s">',dir)
_p(2,'<Filter Include="%s">',path.translate(dir,"\\"))
_p(3,'<UniqueIdentifier>{%s}</UniqueIdentifier>',os.uuid())
_p(2,'</Filter>')
end
@ -602,7 +652,7 @@ local vs10_helpers = premake.vstudio.vs10_helpers
local path_to_file = vs10_helpers.file_path(current_file)
if path_to_file then
_p(2,'<%s Include=\"%s\">', group_type,path.translate(current_file, "\\"))
_p(3,'<Filter>%s</Filter>',path_to_file)
_p(3,'<Filter>%s</Filter>',path.translate(path_to_file,"\\"))
_p(2,'</%s>',group_type)
else
_p(2,'<%s Include=\"%s\" />', group_type,path.translate(current_file, "\\"))
@ -620,6 +670,7 @@ local vs10_helpers = premake.vstudio.vs10_helpers
{
ClCompile ={},
ClInclude ={},
ClASM ={},
None ={},
ResourceCompile ={}
}
@ -633,6 +684,8 @@ local vs10_helpers = premake.vstudio.vs10_helpers
write_filter_includes(sorted)
write_file_filter_block(sorted.ClInclude,"ClInclude")
write_file_filter_block(sorted.ClCompile,"ClCompile")
write_file_filter_block(prj.cxxtesthdrfiles,"CustomBuild")
write_file_filter_block(sorted.ClASM,"ClASM")
write_file_filter_block(sorted.None,"None")
write_file_filter_block(sorted.ResourceCompile,"ResourceCompile")
_p('</Project>')
@ -686,4 +739,4 @@ local vs10_helpers = premake.vstudio.vs10_helpers
end

View File

@ -32,6 +32,7 @@
[".nib"] = "Resources",
[".xib"] = "Resources",
[".icns"] = "Resources",
[".asm"] = "Sources"
}
return categories[path.getextension(node.name)]
end
@ -85,6 +86,7 @@
[".strings"] = "text.plist.strings",
[".xib"] = "file.xib",
[".icns"] = "image.icns",
[".asm"] = "sourcecode.asm",
}
return types[path.getextension(node.path)] or "text"
end
@ -263,6 +265,25 @@
end
function xcode.PBXBuildRule(tr)
if not (tr.project.solution.nasmpath) then
tr.project.solution.nasmpath = 'nasm'
end
_p('/* Begin PBXBuildRule section */')
_p(2,'28AD1E6E1336798800207177 /* PBXBuildRule */ = {')
_p(3,'isa = PBXBuildRule;')
_p(3,'compilerSpec = com.apple.compilers.proxy.script;')
_p(3,'fileType = sourcecode.asm;')
_p(3,'isEditable = 1;')
_p(3,'outputFiles = (')
_p(4,'"$(DERIVED_FILES_DIR)/$(INPUT_FILE_BASE).o",')
_p(3,');')
_p(3,'script = "%s -D OS_UNIX=1 -i${INPUT_FILE_DIR}/ -f %s ${INPUT_FILE_PATH} -o ${DERIVED_FILES_DIR}/${INPUT_FILE_BASE}.o";', tr.project.solution.nasmpath, tr.project.solution.nasmformat)
_p(2,'};')
_p('/* End PBXBuildRule section */')
end
function xcode.PBXContainerItemProxy(tr)
if #tr.projects.children > 0 then
_p('/* Begin PBXContainerItemProxy section */')
@ -432,6 +453,7 @@
end
_p(3,');')
_p(3,'buildRules = (')
_p(4,'28AD1E6E1336798800207177 /* PBXBuildRule */,')
_p(3,');')
_p(3,'dependencies = (')

View File

@ -147,6 +147,7 @@
local tr = xcode.buildprjtree(prj)
xcode.Header(tr)
xcode.PBXBuildFile(tr)
xcode.PBXBuildRule(tr)
xcode.PBXContainerItemProxy(tr)
xcode.PBXFileReference(tr)
xcode.PBXFrameworksBuildPhase(tr)

View File

@ -41,6 +41,42 @@
kind = "list",
scope = "solution",
},
cxxtesthdrfiles =
{
kind = "filelist",
scope = "config",
},
cxxtestsrcfiles =
{
kind = "filelist",
scope = "config",
},
cxxtestoptions =
{
kind = "string",
scope = "config",
},
cxxtestpath =
{
kind = "path",
scope = "solution",
},
cxxtestrootfile =
{
kind = "path",
scope = "config",
},
cxxtestrootoptions =
{
kind = "string",
scope = "config",
},
defines =
{
@ -116,6 +152,12 @@
"4.0"
}
},
gnuexternals =
{
kind = "list",
scope = "config",
},
imagepath =
{
@ -219,6 +261,18 @@
kind = "path",
scope = "container",
},
nasmformat =
{
kind = "string",
scope = "solution",
},
nasmpath =
{
kind = "path",
scope = "solution"
},
objdir =
{