summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-08-14 11:30:28 +0800
committerruki <[email protected]>2022-08-14 11:30:42 +0800
commit077fc878bc8da7804cf36765bf54c687dc95f61d (patch)
treeffb1ac54de08249980cdf00c6bf64dacb256a1b2
parent4560a3458148449eaa959a8a3a62e2c63cfaabba (diff)
improve cmakelist generator
-rw-r--r--xmake/plugins/project/cmake/cmakelists.lua12
-rw-r--r--xmake/plugins/project/make/makefile.lua14
2 files changed, 18 insertions, 8 deletions
diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua
index 09feb78e3..24d78d209 100644
--- a/xmake/plugins/project/cmake/cmakelists.lua
+++ b/xmake/plugins/project/cmake/cmakelists.lua
@@ -212,13 +212,14 @@ function _add_target_sources(cmakelists, target, outputdir)
local has_cuda = false
cmakelists:print("target_sources(%s PRIVATE", target:name())
for _, sourcebatch in table.orderpairs(target:sourcebatches()) do
- local sourcekind = sourcebatch.sourcekind
- if sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "as" or sourcekind == "cu" then
+ -- we can only use rulename to filter them because sourcekind may be bound to multiple rules
+ local rulename = sourcebatch.rulename
+ if rulename == "c++.build" or rulename == "asm.build" or rulename == "cuda.build" then
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
cmakelists:print(" " .. _get_unix_path(sourcefile, outputdir))
end
end
- if sourcekind == "cu" then
+ if sourcebatch.sourcekind == "cu" then
has_cuda = true
end
end
@@ -830,8 +831,9 @@ end
function _add_target_custom_commands(cmakelists, target, outputdir)
_add_target_custom_commands_for_target(cmakelists, target, outputdir, "before")
for _, sourcebatch in table.orderpairs(target:sourcebatches()) do
- local sourcekind = sourcebatch.sourcekind
- if sourcekind ~= "cc" and sourcekind ~= "cxx" and sourcekind ~= "as" then
+ -- we can only use rulename to filter them because sourcekind may be bound to multiple rules
+ local rulename = sourcebatch.rulename
+ if rulename ~= "c++.build" and rulename ~= "asm.build" and rulename ~= "cuda.build" then
_add_target_custom_commands_for_objectrules(cmakelists, target, sourcebatch, outputdir, "before")
_add_target_custom_commands_for_objectrules(cmakelists, target, sourcebatch, outputdir)
_add_target_custom_commands_for_objectrules(cmakelists, target, sourcebatch, outputdir, "after")
diff --git a/xmake/plugins/project/make/makefile.lua b/xmake/plugins/project/make/makefile.lua
index 7b0ec8f60..87c3b6f55 100644
--- a/xmake/plugins/project/make/makefile.lua
+++ b/xmake/plugins/project/make/makefile.lua
@@ -192,10 +192,18 @@ end
-- make objects
function _make_objects(makefile, target, sourcekind, sourcebatch, sourceflags)
-
- -- make them
+ local handled_objects = target:data("makefile.handled_objects")
+ if not handled_objects then
+ handled_objects = {}
+ target:data_set("makefile.handled_objects", handled_objects)
+ end
for index, objectfile in ipairs(sourcebatch.objectfiles) do
- _make_object(makefile, target, sourcebatch.sourcefiles[index], objectfile, sourceflags)
+ -- remove repeat
+ -- this is because some rules will repeatedly bind the same sourcekind, e.g. `rule("c++.build.modules.builder")`
+ if not handled_objects[objectfile] then
+ _make_object(makefile, target, sourcebatch.sourcefiles[index], objectfile, sourceflags)
+ handled_objects[objectfile] = true
+ end
end
end