Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gmake2: Remove pch from FORCE_INCLUDE to allow NoPCH per-file #1100

Merged
merged 2 commits into from
Jun 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions modules/gmake2/gmake2_cpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@
fileExtension { ".cc", ".cpp", ".cxx", ".mm" }
buildoutputs { "$(OBJDIR)/%{premake.modules.gmake2.cpp.makeUnique(cfg, file.objname)}.o" }
buildmessage '$(notdir $<)'
buildcommands {'$(CXX) $(%{premake.modules.gmake2.cpp.fileFlags(cfg, file)}) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"'}
buildcommands {'$(CXX) %{premake.modules.gmake2.cpp.fileFlags(cfg, file)} $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"'}

rule 'cc'
fileExtension {".c", ".s", ".m"}
buildoutputs { "$(OBJDIR)/%{premake.modules.gmake2.cpp.makeUnique(cfg, file.objname)}.o" }
buildmessage '$(notdir $<)'
buildcommands {'$(CC) $(%{premake.modules.gmake2.cpp.fileFlags(cfg, file)}) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"'}
buildcommands {'$(CC) %{premake.modules.gmake2.cpp.fileFlags(cfg, file)} $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"'}

rule 'resource'
fileExtension ".rc"
Expand Down Expand Up @@ -443,9 +443,6 @@

function cpp.forceInclude(cfg, toolset)
local includes = toolset.getforceincludes(cfg)
if not cfg.flags.NoPCH and cfg.pchheader then
table.insert(includes, 1, "-include $(PCH_PLACEHOLDER)")
end
p.outln('FORCE_INCLUDE +=' .. gmake2.list(includes))
end

Expand Down Expand Up @@ -603,23 +600,25 @@

function cpp.fileFlags(cfg, file)
local fcfg = fileconfig.getconfig(file, cfg)
if fcfg and fcfg.flagsVariable then
return fcfg.flagsVariable
end
local flags = {}

if fcfg and fcfg.compileas then
if p.languages.isc(fcfg.compileas) then
return 'ALL_CFLAGS'
elseif p.languages.iscpp(fcfg.compileas) then
return 'ALL_CXXFLAGS'
end
if cfg.pchheader and not cfg.flags.NoPCH and (not fcfg or not fcfg.flags.NoPCH) then
table.insert(flags, "-include $(PCH_PLACEHOLDER)")
end

if path.iscfile(file.name) then
return 'ALL_CFLAGS'
if fcfg and fcfg.flagsVariable then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure what flagsVariable is, why that would override the $(ALL_*FLAGS) flag, or how it's related to PCH files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the per-file arguments variable name.

With gmake2, if files have specific arguments, the generator will create a Makefile var PERFILE_FLAGS_* to group them.

As an example, You can have this:
PERFILE_FLAGS_0 = $(ALL_CXXFLAGS) -mf16c

then your file rule will be
$(SILENT) $(CXX) $(PERFILE_FLAGS_0) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
instead of
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"

The way it is implemented is that ALL_*FLAGS is contained in PERFILE_FLAGS_* if necessary so it doesn't need to be added as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do remember seeing those, this makes sense - thanks for that!

table.insert(flags, string.format("$(%s)", fcfg.flagsVariable))
else
return 'ALL_CXXFLAGS'
local fileExt = cpp.determineFiletype(cfg, file)

if path.iscfile(fileExt) then
table.insert(flags, "$(ALL_CFLAGS)")
elseif path.iscppfile(fileExt) then
table.insert(flags, "$(ALL_CXXFLAGS)")
end
end

return table.concat(flags, ' ')
end

--
Expand Down
70 changes: 68 additions & 2 deletions modules/gmake2/tests/test_gmake2_pch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
local wks, prj
function suite.setup()
os.chdir(_TESTS_DIR)
gmake2.cpp.initialize()
wks, prj = test.createWorkspace()
end

Expand All @@ -34,6 +35,12 @@
gmake2.cpp.pchRules(cfg.project)
end

local function prepareFlags()
local project = test.getproject(wks, 1)
gmake2.cpp.createRuleTable(project)
gmake2.cpp.createFileTable(project)
gmake2.cpp.outputFileRuleSection(project)
end

--
-- If no header has been set, nothing should be output.
Expand All @@ -53,8 +60,21 @@
function suite.noConfig_onHeaderAndNoPCHFlag()
pchheader "include/myproject.h"
flags "NoPCH"
prepareVars()
test.isemptycapture()

files { 'a.cpp', 'b.cpp' }

prepareFlags()
test.capture [[
# File Rules
# #############################################

$(OBJDIR)/a.o: a.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/b.o: b.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
]]
end


Expand Down Expand Up @@ -156,3 +176,49 @@ endif
PCH = ../../../../src/host/premake.h
]]
end

--
-- If the header is located on one of the include file
-- search directories, it should get found automatically.
--

function suite.PCHFlag()
pchheader "include/myproject.h"

files { 'a.cpp', 'b.cpp' }

prepareFlags()
test.capture [[
# File Rules
# #############################################

$(OBJDIR)/a.o: a.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) -include $(PCH_PLACEHOLDER) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/b.o: b.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) -include $(PCH_PLACEHOLDER) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
]]
end

function suite.PCHFlag_PerFile()
pchheader "include/myproject.h"

files { 'a.cpp', 'b.cpp' }

filter { "files:a.cpp" }
flags "NoPCH"

prepareFlags()
test.capture [[
# File Rules
# #############################################

$(OBJDIR)/a.o: a.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/b.o: b.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) -include $(PCH_PLACEHOLDER) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
]]
end