From 4d803f21b3d542ac6af25135b1351a3c8b6c691e Mon Sep 17 00:00:00 2001 From: star9029 Date: Fri, 27 Sep 2024 00:33:50 +0800 Subject: [PATCH] fix target_link_libraries --- xmake/plugins/project/cmake/cmakelists.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index aebc3ec89d..b5b6f6b26e 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -1007,16 +1007,27 @@ function _add_target_link_libraries(cmakelists, target, outputdir) end end - if #target:objectfiles() > objectfiles_set:size() or #object_deps ~= 0 then + local has_links = #target:objectfiles() > objectfiles_set:size() + if has_links then cmakelists:print("target_link_libraries(%s PRIVATE", target:name()) for _, objectfile in ipairs(target:objectfiles()) do if not objectfiles_set:has(objectfile) then cmakelists:print(" " .. _get_relative_unix_path_to_cmake(objectfile, outputdir)) end end + end + + if #object_deps ~= 0 then + if not has_links then + cmakelists:print("target_link_libraries(%s PRIVATE", target:name()) + has_links = true + end for _, dep in ipairs(object_deps) do cmakelists:print(" " .. dep) end + end + + if has_links then cmakelists:print(")") end end