From 2d76e97e891dc655df0fe97c02c626b6497c0b45 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 24 Jul 2023 22:54:40 +0800 Subject: fix pch for #3988 --- xmake/modules/private/action/build/object.lua | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua index 479ef8add..6668d9695 100644 --- a/xmake/modules/private/action/build/object.lua +++ b/xmake/modules/private/action/build/object.lua @@ -90,15 +90,25 @@ function _do_build_file(target, sourcefile, opt) dependinfo.files = {} assert(compinst:compile(sourcefile, objectfile, {dependinfo = dependinfo, compflags = compflags})) - -- update files and values to the dependent file + -- update files and values to the depfiles dependinfo.values = depvalues table.insert(dependinfo.files, sourcefile) - local pcoutputfile = target:pcoutputfile("cxx") - if target:has_sourcekind("cxx") and pcoutputfile then - table.insert(dependinfo.files, pcoutputfile) - end + + -- add precompiled header to the depfiles when building sourcefile + local build_pch + local pcxxoutputfile = target:pcoutputfile("cxx") local pcoutputfile = target:pcoutputfile("c") - if target:has_sourcekind("cc") and pcoutputfile then + if pcxxoutputfile or pcoutputfile then + -- https://github.com/xmake-io/xmake/issues/3988 + local extension = path.extension(sourcefile) + if (extension:startswith(".h") or extension == ".inl") then + build_pch = true + end + end + if target:has_sourcekind("cxx") and pcxxoutputfile and not build_pch then + table.insert(dependinfo.files, pcxxoutputfile) + end + if target:has_sourcekind("cc") and pcoutputfile and not build_pch then table.insert(dependinfo.files, pcoutputfile) end depend.save(dependinfo, dependfile) -- cgit v1.3.1