Skip to content

Commit 173069f

Browse files
authored
Merge pull request #6429 from PierreEVEN/fix-make_ninja_gen-headeronly_target
Fix make ninja gen headeronly target
2 parents 8dd9b97 + 2e43281 commit 173069f

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

xmake/plugins/project/make/makefile.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ function _add_toolchains(makefile, outputdir)
334334

335335
-- add toolchains from targets
336336
for targetname, target in pairs(project.targets()) do
337-
if not target:is_phony() then
337+
if not _phony_or_headeronly(target) then
338338
local program = _get_program_from_target(target, target:linker():kind())
339339
if program then
340340
makefile:print("%s_%s=%s", targetname, target:linker():kind():upper(), program)
@@ -353,10 +353,14 @@ function _add_toolchains(makefile, outputdir)
353353
makefile:print("")
354354
end
355355

356+
function _phony_or_headeronly(target)
357+
return target:is_phony() or target:is_headeronly()
358+
end
359+
356360
-- add flags
357361
function _add_flags(makefile, targetflags, outputdir)
358362
for targetname, target in pairs(project.targets()) do
359-
if not target:is_phony() then
363+
if not _phony_or_headeronly(target) then
360364
for _, sourcebatch in pairs(target:sourcebatches()) do
361365
local sourcekind = sourcebatch.sourcekind
362366
if sourcekind then
@@ -512,7 +516,7 @@ function _add_build_target(makefile, target, targetflags, outputdir)
512516
local precmds_label = _add_build_custom_commands_before(makefile, target, outputdir)
513517

514518
-- is phony target?
515-
if target:is_phony() then
519+
if _phony_or_headeronly(target) then
516520
return _add_build_phony(makefile, target)
517521
end
518522

@@ -539,7 +543,7 @@ function _add_build_target(makefile, target, targetflags, outputdir)
539543
-- make dependence for the dependent targets
540544
for _, depname in ipairs(target:get("deps")) do
541545
local dep = project.target(depname, {namespace = target:namespace()})
542-
makefile:write(" " .. (dep:is_phony() and depname or _get_relative_unix_path(dep:targetfile(), outputdir)))
546+
makefile:write(" " .. (_phony_or_headeronly(dep) and depname or _get_relative_unix_path(dep:targetfile(), outputdir)))
543547
end
544548

545549
-- make dependence for objects
@@ -650,7 +654,7 @@ function _add_clean_target(makefile, target, outputdir)
650654
makefile:write(" clean_" .. dep)
651655
end
652656
makefile:print("")
653-
if not target:is_phony() then
657+
if not _phony_or_headeronly(target) then
654658
_add_remove_files(makefile, target:targetfile(), outputdir)
655659
_add_remove_files(makefile, target:symbolfile(), outputdir)
656660
_add_remove_files(makefile, target:objectfiles(), outputdir)

xmake/plugins/project/ninja/build_ninja.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ function _add_build_for_target(ninjafile, target, outputdir)
352352
target:data_set("plugin.project.kind", "ninja")
353353

354354
-- is phony target?
355-
if target:is_phony() then
355+
if target:is_phony() or target:is_headeronly() then
356356
return _add_build_for_phony(ninjafile, target)
357357
end
358358

@@ -378,7 +378,10 @@ function _add_build_for_target(ninjafile, target, outputdir)
378378
ninjafile:print(" || $")
379379
ninjafile:write(" ")
380380
for _, dep in ipairs(deps) do
381-
ninjafile:write(" " .. _get_relative_unix_path(project.target(dep, {namespace = target:namespace()}):targetfile(), outputdir))
381+
local dep_target = project.target(dep, {namespace = target:namespace()});
382+
if not dep_target:is_headeronly() then
383+
ninjafile:write(" " .. _get_relative_unix_path(dep_target:targetfile(), outputdir))
384+
end
382385
end
383386
end
384387
ninjafile:print("")

0 commit comments

Comments
 (0)