diff --git a/src/actions/make/_make.lua b/src/actions/make/_make.lua index 0f1a4b60..e1710c8b 100644 --- a/src/actions/make/_make.lua +++ b/src/actions/make/_make.lua @@ -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) diff --git a/src/actions/make/make_cpp.lua b/src/actions/make/make_cpp.lua index a4e92521..c8cf571e 100644 --- a/src/actions/make/make_cpp.lua +++ b/src/actions/make/make_cpp.lua @@ -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 diff --git a/src/actions/ninja/ninja_base.lua b/src/actions/ninja/ninja_base.lua index 499089d6..dba4f0f0 100644 --- a/src/actions/ninja/ninja_base.lua +++ b/src/actions/ninja/ninja_base.lua @@ -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 }, diff --git a/src/actions/ninja/ninja_cpp.lua b/src/actions/ninja/ninja_cpp.lua index ded2fa2c..e8422017 100644 --- a/src/actions/ninja/ninja_cpp.lua +++ b/src/actions/ninja/ninja_cpp.lua @@ -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 @@ -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 diff --git a/src/base/api.lua b/src/base/api.lua index a5aa0472..b9fcd8ae 100644 --- a/src/base/api.lua +++ b/src/base/api.lua @@ -847,6 +847,7 @@ end NativeWChar = 1, No64BitChecks = 1, NoBufferSecurityCheck = 1, + NoDummySource = 1, NoEditAndContinue = 1, NoExceptions = 1, NoFramePointer = 1,