Skip to content
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
14 changes: 11 additions & 3 deletions modules/gmake/gmake_cpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,33 @@
function cpp.initialize()
rule 'cpp'
fileExtension { ".cc", ".cpp", ".cxx", ".mm" }
buildoutputs { "$(OBJDIR)/%{file.objname}.o" }
buildoutputs { "$(OBJDIR)/%{file.objname}%{premake.modules.gmake.cpp.gettooloutputext('cxx', cfg)}" }
buildmessage '$(notdir $<)'
buildcommands {'$(CXX) %{premake.modules.gmake.cpp.fileFlags(cfg, file)} $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"'}
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't that .o also be changed?

Copy link
Member Author

Choose a reason for hiding this comment

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

???

Copy link
Contributor

Choose a reason for hiding this comment

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

"$(@:%.o=%.d)" hardcode .o, should it be "$(@:%%%{premake.modules.gmake.cpp.gettooloutputext('cxx', cfg)}=%.d)"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not the line you've commented on here.


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

rule 'resource'
fileExtension ".rc"
buildoutputs { "$(OBJDIR)/%{file.objname}.res" }
buildoutputs { "$(OBJDIR)/%{file.objname}%{premake.modules.gmake.cpp.gettooloutputext('rc', cfg)}" }
buildmessage '$(notdir $<)'
buildcommands {'$(RESCOMP) $< -O coff -o "$@" $(ALL_RESFLAGS)'}

global(nil)
end

function cpp.gettooloutputext(tool, cfg)
Copy link
Contributor

@Jarod42 Jarod42 Sep 17, 2025

Choose a reason for hiding this comment

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

Why gcc/clang don't provide it too?

Or move that function as helper method (usable by other toolset (as ninja))

Copy link
Member Author

Choose a reason for hiding this comment

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

Why gcc/clang don't provide it too?

I couldn't decide if I should or not, but I'm leaning towards I should now.

This function needs to exist though with the fallback, otherwise all modules that introduce C and C++ toolsets won't use extensions on their files.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

local toolset = gmake.getToolSet(cfg)
if toolset.gettooloutputext ~= nil then
return toolset.gettooloutputext(tool)
end

return iif(tool == "rc", ".res", ".o")
end

function cpp.createRuleTable(prj)
local rules = {}
Expand Down
40 changes: 40 additions & 0 deletions modules/gmake/tests/test_gmake_file_rules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,46 @@
end


--
-- Object filenames use correct extension based on toolset
--

function suite.objectNameExtensions_onDefault()
files { "src/hello.cpp", "src/test.c" }
prepare()
test.capture [[
# File Rules
# #############################################
$(OBJDIR)/hello.o: src/hello.cpp
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/test.o: src/test.c
@echo "$(notdir $<)"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
]]
end

function suite.objectNameExtensions_onMSC()
toolset "msc"
files { "src/hello.cpp", "src/test.c" }
prepare()
test.capture [[
# File Rules
# #############################################
$(OBJDIR)/hello.obj: src/hello.cpp
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/test.obj: src/test.c
@echo "$(notdir $<)"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
]]
end


--
-- Two files with the same base name should have different object files.
--
Expand Down
4 changes: 4 additions & 0 deletions src/tools/clang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,7 @@
end
return value
end

function clang.gettooloutputext(tool)
return gcc.gettooloutputext(tool)
end
4 changes: 4 additions & 0 deletions src/tools/gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -724,3 +724,7 @@
end
return (cfg.gccprefix or "") .. gcc.tools[tool] .. version
end

function gcc.gettooloutputext(tool)
return iif(tool == "rc", ".res", ".o")
end
3 changes: 3 additions & 0 deletions src/tools/msc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@
return msc.tools[tool]
end

function msc.gettooloutputext(tool)
return iif(tool == "rc", ".res", ".obj")
end


function msc.getwarnings(cfg)
Expand Down
Loading