Skip to content
2 changes: 2 additions & 0 deletions src/actions/make/_make.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@
if premake.isdotnetproject(prj) then
premake.generate(prj, makefile, premake.make_csharp)
elseif premake.iscppproject(prj) then
local dummyfile = _MAKE.getdummysourcefilename(prj)
if dummyfile then premake.generate(prj, dummyfile, premake.make_cpp_dummy) end
premake.generate(prj, makefile, premake.make_cpp)
elseif premake.isswiftproject(prj) then
premake.generate(prj, makefile, premake.make_swift)
Expand Down
57 changes: 57 additions & 0 deletions src/actions/make/make_cpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,63 @@
_p('')
end

--
-- Generate dummy build unit
--

function _MAKE.getdummysourcefilename(prj)
-- create a shortcut to the compiler interface
local cc = premake.gettool(prj)

-- build a list of supported target platforms that also includes a generic build
local platforms = premake.filterplatforms(prj.solution, cc.platforms, "Native")

-- check whether dummy should be generated
--> no flag 'NoDummySource'
--> no actual source file
local shouldGenerate = false
for _, platform in ipairs(platforms) do
for cfg in premake.eachconfig(prj, platform) do
if not table.icontains(cfg.flags, "NoDummySource") then
if (prj.language == 'C++' and not table.icontains(table.translate(cfg.files, path.iscppfile), true))
or (prj.language == 'C' and not table.icontains(table.translate(cfg.files, path.iscfile), true)) then
shouldGenerate = true
break
end
end
end
end

if not shouldGenerate then
return nil
end

local extension = ("_dummy%s"):format(prj.language == 'C++' and '.cpp' or '.c')
return prj.name .. extension
end

function premake.make_cpp_dummy(prj)
local dummyfile = _MAKE.getdummysourcefilename(prj)

-- generate dummy
premake.ninja.cpp.generate_dummysourcefile(prj)

-- add dummy back to configuration that need it
--> same conditions as above
local cc = premake.gettool(prj)
local platforms = premake.filterplatforms(prj.solution, cc.platforms, "Native")
for _, platform in ipairs(platforms) do
for cfg in premake.eachconfig(prj, platform) do
if not table.icontains(cfg.flags, "NoDummySource") then
if (prj.language == 'C++' and not table.icontains(table.translate(cfg.files, path.iscppfile), true))
or (prj.language == 'C' and not table.icontains(table.translate(cfg.files, path.iscfile), true)) then
table.insert(cfg.files, dummyfile)
end
end
end
end
end


--
-- Platform support
Expand Down
10 changes: 10 additions & 0 deletions src/actions/ninja/ninja_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ function cfg_proxy:getoutputfilename()
return path.join(self.buildtarget.directory, self.buildtarget.name)
end

function cfg_proxy:getdummysourcefilename(extension, fullpath)
local name = self.project.name .. "_dummy" .. extension

if fullpath ~= nil then
return path.join(self.location, name)
end

return name
end

local proxy_cache = {
prj = { new = new_prj_proxy },
cfg = { new = new_cfg_proxy },
Expand Down
23 changes: 21 additions & 2 deletions src/actions/ninja/ninja_cpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ end

for _, platform in ipairs(platforms) do
for cfg in p.eachconfig(pxy, platform) do

if not table.icontains(cfg.flags, "NoDummySource") then
local dummyfile
if prj.language == 'C++' and not table.icontains(table.translate(cfg.files, path.iscppfile), true) then
dummyfile = cfg:getdummysourcefilename('.cpp')
elseif prj.language == 'C' and not table.icontains(table.translate(cfg.files, path.iscfile), true) then
dummyfile = cfg:getdummysourcefilename('.c')
end
if dummyfile then
p.generate(cfg, dummyfile, function() cpp.generate_dummysourcefile(prj) end)
table.insert(cfg.files, dummyfile)
end
end

p.generate(cfg, cfg:getprojectfilename(), function() cpp.generate_config(prj, cfg) end)
end
end
Expand Down Expand Up @@ -390,5 +404,10 @@ end

end



function cpp.generate_dummysourcefile(prj)
_p("/* dummy source generated by GENie */")
_p("static void %s_dummy()", prj.name:gsub('[^%w]', '_'))
_p('{')
_p(1, '/* nothing here */')
_p('}')
end
1 change: 1 addition & 0 deletions src/base/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ end
NativeWChar = 1,
No64BitChecks = 1,
NoBufferSecurityCheck = 1,
NoDummySource = 1,
NoEditAndContinue = 1,
NoExceptions = 1,
NoFramePointer = 1,
Expand Down