summaryrefslogtreecommitdiff
path: root/xmake/plugins
diff options
context:
space:
mode:
authorruki <[email protected]>2021-10-28 23:31:06 +0800
committerruki <[email protected]>2021-10-28 23:31:06 +0800
commit6f1d565decf6623cad7c56ff3d1badcc2f40e6d4 (patch)
tree9e3f1313682b0e9e9c92e85bd87ec76775138573 /xmake/plugins
parentee15c74a2d73fc8df4a11efdc2dd4848807ffe27 (diff)
improve pre-build for cmake custom command
Diffstat (limited to 'xmake/plugins')
-rw-r--r--xmake/plugins/project/cmake/cmakelists.lua32
1 files changed, 24 insertions, 8 deletions
diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua
index c43f7584f..b4d9fe952 100644
--- a/xmake/plugins/project/cmake/cmakelists.lua
+++ b/xmake/plugins/project/cmake/cmakelists.lua
@@ -481,15 +481,31 @@ end
-- add custom command
function _add_target_custom_command(cmakelists, target, command, suffix)
- cmakelists:print("add_custom_command(TARGET %s", target:name())
- if suffix == "prefix" then
- cmakelists:print(" PRE_BUILD")
- elseif suffix == "suffix" then
- cmakelists:print(" POST_BUILD")
+ local command_str = os.args(command)
+ if suffix == "before" then
+ -- ADD_CUSTOM_COMMAND and PRE_BUILD did not work as I expected,
+ -- so we need use add_dependencies and fake target to support it.
+ --
+ -- @see https://gitlab.kitware.com/cmake/cmake/-/issues/17802
+ --
+ local key = hash.uuid(command_str):split("-", {plain = true})[1]
+ cmakelists:print("add_custom_command(OUTPUT output_%s", key)
+ cmakelists:print(" COMMAND %s", command_str)
+ cmakelists:print(" VERBATIM")
+ cmakelists:print(")")
+ cmakelists:print("add_custom_target(target_%s", key)
+ cmakelists:print(" DEPENDS output_%s", key)
+ cmakelists:print(")")
+ cmakelists:print("add_dependencies(%s target_%s)", target:name(), key)
+ else
+ cmakelists:print("add_custom_command(TARGET %s", target:name())
+ if suffix == "after" then
+ cmakelists:print(" POST_BUILD")
+ end
+ cmakelists:print(" COMMAND %s", command_str)
+ cmakelists:print(" VERBATIM")
+ cmakelists:print(")")
end
- cmakelists:print(" COMMAND %s", os.args(command))
- cmakelists:print(" VERBATIM")
- cmakelists:print(")")
end
-- add target custom commands for target