diff options
-rw-r--r-- | CHANGES.txt | 1 | ||||
-rw-r--r-- | samples/project/CppConsoleApp/CppConsoleApp.cpp | 2 | ||||
-rw-r--r-- | samples/project/CppConsoleApp/premake4.lua | 4 | ||||
-rw-r--r-- | src/actions/codeblocks/codeblocks_cbp.lua | 11 | ||||
-rw-r--r-- | src/actions/make/make_cpp.lua | 39 | ||||
-rw-r--r-- | src/tools/gcc.lua | 6 | ||||
-rw-r--r-- | src/tools/ow.lua | 2 | ||||
-rw-r--r-- | tests/test_gmake_cpp.lua | 6 |
8 files changed, 48 insertions, 23 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 363aa2c..5c72b27 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/samples/project/CppConsoleApp/CppConsoleApp.cpp b/samples/project/CppConsoleApp/CppConsoleApp.cpp index c237aba..fcd83a2 100644 --- a/samples/project/CppConsoleApp/CppConsoleApp.cpp +++ b/samples/project/CppConsoleApp/CppConsoleApp.cpp @@ -1,4 +1,4 @@ -#include <stdio.h> +#include "CppConsoleApp.h" int main() { diff --git a/samples/project/CppConsoleApp/premake4.lua b/samples/project/CppConsoleApp/premake4.lua index 2983e4d..62dae97 100644 --- a/samples/project/CppConsoleApp/premake4.lua +++ b/samples/project/CppConsoleApp/premake4.lua @@ -5,9 +5,11 @@ project "CppConsoleApp" flags { "FatalWarnings", "ExtraWarnings" } - files { "*.cpp" } + files { "*.h", "*.cpp" } includedirs { "I:/Code" } libdirs { "../lib" } links { "CppSharedLib" } + + pchheader "CppConsoleApp.h" diff --git a/src/actions/codeblocks/codeblocks_cbp.lua b/src/actions/codeblocks/codeblocks_cbp.lua index e4d99dd..f58113a 100644 --- a/src/actions/codeblocks/codeblocks_cbp.lua +++ b/src/actions/codeblocks/codeblocks_cbp.lua @@ -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 diff --git a/src/actions/make/make_cpp.lua b/src/actions/make/make_cpp.lua index 592cc79..608f27e 100644 --- a/src/actions/make/make_cpp.lua +++ b/src/actions/make/make_cpp.lua @@ -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)), " ")) diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index dd63ad2..769a1bb 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -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) diff --git a/src/tools/ow.lua b/src/tools/ow.lua index 888e78a..84aafb2 100644 --- a/src/tools/ow.lua +++ b/src/tools/ow.lua @@ -57,7 +57,7 @@ -- function premake.ow.getcppflags(cfg) - return "" + return {} end function premake.ow.getcflags(cfg) diff --git a/tests/test_gmake_cpp.lua b/tests/test_gmake_cpp.lua index e7df651..a312b01 100644 --- a/tests/test_gmake_cpp.lua +++ b/tests/test_gmake_cpp.lua @@ -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) |