Added precompiled header support for GCC

This commit is contained in:
starkos 2009-05-22 20:27:05 +00:00
parent b4d4863634
commit 9bdccbed33
8 changed files with 48 additions and 23 deletions

View File

@ -6,6 +6,7 @@
- Added Xbox 360 support to Visual Studio 2005/2008 - Added Xbox 360 support to Visual Studio 2005/2008
- Added Mac OS X universal binary support - Added Mac OS X universal binary support
- Added Playstation 3 support - Added Playstation 3 support
- Added precompiled header support for GCC
- Support links and libdirs for Visual Studio static libraries - Support links and libdirs for Visual Studio static libraries
- Fail gracefully when list is assigned to string field - Fail gracefully when list is assigned to string field
- Changed GCC flags to -fno-exceptions and -fno-rtti - Changed GCC flags to -fno-exceptions and -fno-rtti

View File

@ -1,4 +1,4 @@
#include <stdio.h> #include "CppConsoleApp.h"
int main() int main()
{ {

View File

@ -5,9 +5,11 @@ project "CppConsoleApp"
flags { "FatalWarnings", "ExtraWarnings" } flags { "FatalWarnings", "ExtraWarnings" }
files { "*.cpp" } files { "*.h", "*.cpp" }
includedirs { "I:/Code" } includedirs { "I:/Code" }
libdirs { "../lib" } libdirs { "../lib" }
links { "CppSharedLib" } links { "CppSharedLib" }
pchheader "CppConsoleApp.h"

View File

@ -110,14 +110,15 @@
-- begin files block -- -- begin files block --
for _,fname in ipairs(prj.files) do for _,fname in ipairs(prj.files) do
_p('\t\t<Unit filename="%s">', premake.esc(fname)) _p('\t\t<Unit filename="%s">', premake.esc(fname))
if path.getextension(fname) == ".rc" then if path.isresourcefile(fname) then
_p('\t\t\t<Option compilerVar="WINDRES" />') _p('\t\t\t<Option compilerVar="WINDRES" />')
elseif path.iscppfile(fname) then elseif path.iscppfile(fname) then
_p('\t\t\t<Option compilerVar="%s" />', iif(prj.language == "C", "CC", "CPP")) _p('\t\t\t<Option compilerVar="%s" />', iif(prj.language == "C", "CC", "CPP"))
if (not prj.flags.NoPCH and fname == prj.pchheader) then end
_p('\t\t\t<Option compile="1" />') if not prj.flags.NoPCH and fname == prj.pchheader then
_p('\t\t\t<Option weight="0" />') _p('\t\t\t<Option compilerVar="%s" />', iif(prj.language == "C", "CC", "CPP"))
end _p('\t\t\t<Option compile="1" />')
_p('\t\t\t<Option weight="0" />')
end end
_p('\t\t</Unit>') _p('\t\t</Unit>')
end end

View File

@ -62,13 +62,14 @@
_p('') _p('')
if os.is("MacOSX") and prj.kind == "WindowedApp" then if os.is("MacOSX") and prj.kind == "WindowedApp" then
_p('all: $(TARGETDIR) $(OBJDIR) prebuild $(OBJECTS) $(RESOURCES) prelink $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist') _p('all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist')
else else
_p('all: $(TARGETDIR) $(OBJDIR) prebuild $(OBJECTS) $(RESOURCES) prelink $(TARGET)') _p('all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)')
end end
_p('') _p('')
_p('$(TARGET): $(OBJECTS) $(LDDEPS) $(RESOURCES)') -- target build rule
_p('$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES)')
_p('\t@echo Linking %s', prj.name) _p('\t@echo Linking %s', prj.name)
_p('\t$(SILENT) $(LINKCMD)') _p('\t$(SILENT) $(LINKCMD)')
_p('\t$(POSTBUILDCMDS)') _p('\t$(POSTBUILDCMDS)')
@ -111,6 +112,18 @@
_p('\t$(PRELINKCMDS)') _p('\t$(PRELINKCMDS)')
_p('') _p('')
-- precompiler header rule
_p('ifneq (,$(PCH))')
_p('$(GCH): $(PCH)')
_p('\t@echo $(notdir $<)')
if prj.language == "C" then
_p('\t$(SILENT) $(CC) $(CFLAGS) -o $@ -c $<')
else
_p('\t$(SILENT) $(CXX) $(CXXFLAGS) -o $@ -c $<')
end
_p('endif')
_p('')
-- per-file rules -- per-file rules
for _, file in ipairs(prj.files) do for _, file in ipairs(prj.files) do
if path.iscppfile(file) then if path.iscppfile(file) then
@ -190,12 +203,20 @@
_p(' AR = %s', platform.ar) _p(' AR = %s', platform.ar)
end end
_p(' OBJDIR = %s', _MAKE.esc(cfg.objectsdir))
_p(' TARGETDIR = %s', _MAKE.esc(cfg.buildtarget.directory)) _p(' TARGETDIR = %s', _MAKE.esc(cfg.buildtarget.directory))
_p(' TARGET = $(TARGETDIR)/%s', _MAKE.esc(cfg.buildtarget.name)) _p(' TARGET = $(TARGETDIR)/%s', _MAKE.esc(cfg.buildtarget.name))
_p(' OBJDIR = %s', _MAKE.esc(cfg.objectsdir))
_p(' DEFINES += %s', table.concat(cc.getdefines(cfg.defines), " ")) _p(' DEFINES += %s', table.concat(cc.getdefines(cfg.defines), " "))
_p(' INCLUDES += %s', table.concat(cc.getincludedirs(cfg.includedirs), " ")) _p(' INCLUDES += %s', table.concat(cc.getincludedirs(cfg.includedirs), " "))
_p(' CPPFLAGS += %s $(DEFINES) $(INCLUDES)', cc.getcppflags(cfg)) _p(' CPPFLAGS += %s $(DEFINES) $(INCLUDES)', table.concat(cc.getcppflags(cfg), " "))
-- set up precompiled headers
if not cfg.flags.NoPCH and cfg.pchheader then
_p(' PCH = %s', _MAKE.esc(cfg.pchheader))
_p(' GCH = $(OBJDIR)/$(PCH).gch')
_p(' CPPFLAGS += -I$(OBJDIR) -include $(PCH)')
end
_p(' CFLAGS += $(CPPFLAGS) $(ARCH) %s', table.concat(table.join(cc.getcflags(cfg), cfg.buildoptions), " ")) _p(' CFLAGS += $(CPPFLAGS) $(ARCH) %s', table.concat(table.join(cc.getcflags(cfg), cfg.buildoptions), " "))
_p(' CXXFLAGS += $(CFLAGS) %s', table.concat(cc.getcxxflags(cfg), " ")) _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(' LDFLAGS += %s', table.concat(table.join(cc.getldflags(cfg), cfg.linkoptions, cc.getlibdirflags(cfg)), " "))

View File

@ -87,10 +87,11 @@
-- --
function premake.gcc.getcppflags(cfg) function premake.gcc.getcppflags(cfg)
return platforms[cfg.platform].cppflags local result = { }
table.insert(result, platforms[cfg.platform].cppflags)
return result
end end
function premake.gcc.getcflags(cfg) function premake.gcc.getcflags(cfg)
local result = table.translate(cfg.flags, cflags) local result = table.translate(cfg.flags, cflags)
table.insert(result, platforms[cfg.platform].flags) table.insert(result, platforms[cfg.platform].flags)
@ -100,7 +101,6 @@
return result return result
end end
function premake.gcc.getcxxflags(cfg) function premake.gcc.getcxxflags(cfg)
local result = table.translate(cfg.flags, cxxflags) local result = table.translate(cfg.flags, cxxflags)
return result return result

View File

@ -57,7 +57,7 @@
-- --
function premake.ow.getcppflags(cfg) function premake.ow.getcppflags(cfg)
return "" return {}
end end
function premake.ow.getcflags(cfg) function premake.ow.getcflags(cfg)

View File

@ -74,9 +74,9 @@ endif
premake.gmake_cpp_config(cfg, premake.gcc) premake.gmake_cpp_config(cfg, premake.gcc)
test.capture [[ test.capture [[
ifeq ($(config),debug) ifeq ($(config),debug)
OBJDIR = obj/Debug
TARGETDIR = . TARGETDIR = .
TARGET = $(TARGETDIR)/MyProject TARGET = $(TARGETDIR)/MyProject
OBJDIR = obj/Debug
DEFINES += DEFINES +=
INCLUDES += INCLUDES +=
CPPFLAGS += -MMD $(DEFINES) $(INCLUDES) CPPFLAGS += -MMD $(DEFINES) $(INCLUDES)
@ -108,9 +108,9 @@ ifeq ($(config),debugps3)
CC = ppu-lv2-g++ CC = ppu-lv2-g++
CXX = ppu-lv2-g++ CXX = ppu-lv2-g++
AR = ppu-lv2-ar AR = ppu-lv2-ar
OBJDIR = obj/PS3/Debug
TARGETDIR = . TARGETDIR = .
TARGET = $(TARGETDIR)/MyProject.elf TARGET = $(TARGETDIR)/MyProject.elf
OBJDIR = obj/PS3/Debug
DEFINES += DEFINES +=
INCLUDES += INCLUDES +=
CPPFLAGS += -MMD $(DEFINES) $(INCLUDES) CPPFLAGS += -MMD $(DEFINES) $(INCLUDES)
@ -140,9 +140,9 @@ endif
premake.gmake_cpp_config(cfg, premake.gcc) premake.gmake_cpp_config(cfg, premake.gcc)
test.capture [[ test.capture [[
ifeq ($(config),debug64) ifeq ($(config),debug64)
OBJDIR = obj/x64/Debug
TARGETDIR = . TARGETDIR = .
TARGET = $(TARGETDIR)/MyProject TARGET = $(TARGETDIR)/MyProject
OBJDIR = obj/x64/Debug
DEFINES += DEFINES +=
INCLUDES += INCLUDES +=
CPPFLAGS += -MMD $(DEFINES) $(INCLUDES) CPPFLAGS += -MMD $(DEFINES) $(INCLUDES)