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 Mac OS X universal binary support
- Added Playstation 3 support
- Added precompiled header support for GCC
- Support links and libdirs for Visual Studio static libraries
- Fail gracefully when list is assigned to string field
- Changed GCC flags to -fno-exceptions and -fno-rtti

View File

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

View File

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

View File

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

View File

@ -18,7 +18,7 @@
premake.gmake_cpp_config(cfg, cc)
end
end
-- list intermediate files
_p('OBJECTS := \\')
for _, file in ipairs(prj.files) do
@ -62,13 +62,14 @@
_p('')
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
_p('all: $(TARGETDIR) $(OBJDIR) prebuild $(OBJECTS) $(RESOURCES) prelink $(TARGET)')
_p('all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)')
end
_p('')
_p('$(TARGET): $(OBJECTS) $(LDDEPS) $(RESOURCES)')
-- target build rule
_p('$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES)')
_p('\t@echo Linking %s', prj.name)
_p('\t$(SILENT) $(LINKCMD)')
_p('\t$(POSTBUILDCMDS)')
@ -110,7 +111,19 @@
_p('prelink:')
_p('\t$(PRELINKCMDS)')
_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
for _, file in ipairs(prj.files) do
if path.iscppfile(file) then
@ -189,13 +202,21 @@
if platform.ar then
_p(' AR = %s', platform.ar)
end
_p(' OBJDIR = %s', _MAKE.esc(cfg.objectsdir))
_p(' TARGETDIR = %s', _MAKE.esc(cfg.buildtarget.directory))
_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(' 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(' CXXFLAGS += $(CFLAGS) %s', table.concat(cc.getcxxflags(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)
return platforms[cfg.platform].cppflags
local result = { }
table.insert(result, platforms[cfg.platform].cppflags)
return result
end
function premake.gcc.getcflags(cfg)
local result = table.translate(cfg.flags, cflags)
table.insert(result, platforms[cfg.platform].flags)
@ -99,7 +100,6 @@
end
return result
end
function premake.gcc.getcxxflags(cfg)
local result = table.translate(cfg.flags, cxxflags)

View File

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

View File

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