diff options
| author | ruki <[email protected]> | 2026-02-01 16:19:52 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-02-01 16:19:52 +0800 |
| commit | 4cbe78083f6c7701b94730298cc6c70bd6978608 (patch) | |
| tree | 4c28e6b7d297f1aafb602621e53e68d8b43d349e | |
| parent | d6589924f98f6e9f9dc80916912491fff95a1d62 (diff) | |
| parent | a0848dab701b4f64a4345c6ef8ace61c9532dc41 (diff) | |
Merge pull request #7283 from luadebug/cc
enhance compile_commands support and add test cases
| -rw-r--r-- | tests/projects/policy/compile_commands/src/main.c | 3 | ||||
| -rw-r--r-- | tests/projects/policy/compile_commands/xmake.lua | 10 | ||||
| -rw-r--r-- | xmake/core/project/policy.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/project/clang/compile_commands.lua | 5 |
4 files changed, 20 insertions, 0 deletions
diff --git a/tests/projects/policy/compile_commands/src/main.c b/tests/projects/policy/compile_commands/src/main.c new file mode 100644 index 000000000..9b130982d --- /dev/null +++ b/tests/projects/policy/compile_commands/src/main.c @@ -0,0 +1,3 @@ +int main(int argc, char** argv) { + return 0; +} diff --git a/tests/projects/policy/compile_commands/xmake.lua b/tests/projects/policy/compile_commands/xmake.lua new file mode 100644 index 000000000..1ccf48af6 --- /dev/null +++ b/tests/projects/policy/compile_commands/xmake.lua @@ -0,0 +1,10 @@ +add_rules("mode.debug", "mode.release") + +target("enabled") + set_kind("binary") + add_files("src/main.c") + +target("disabled") + set_kind("binary") + add_files("src/main.c") + set_policy("generator.compile_commands", false) diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 1cecfd01a..5123f0a5c 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -192,6 +192,8 @@ function policy.policies() ["network.mode"] = {description = "Set the network mode", type = "string"}, -- Set the compatibility version, e.g. 2.0, 3.0 ["compatibility.version"] = {description = "Set the compatibility version", type = "string", default = "3.0", values = {"2.0", "3.0"}}, + -- Enable compile_commands + ["generator.compile_commands"] = {description = "Enable compile_commands.", default = true, type = "boolean"}, -- Generate the solution file in root output directory -- @see https://github.com/xmake-io/xmake/issues/6519 ["generator.vsxmake.root_sln"] = {description = "Generate the solution file in root output directory", default = false, type = "boolean"} diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua index 4f01354fa..909184800 100644 --- a/xmake/plugins/project/clang/compile_commands.lua +++ b/xmake/plugins/project/clang/compile_commands.lua @@ -266,6 +266,11 @@ function _add_target(jsonfile, target) -- https://github.com/xmake-io/xmake/issues/2337 target:data_set("plugin.project.kind", "compile_commands") + -- disable compile_commands? + if target:policy("generator.compile_commands") == false then + return + end + -- enter package environments local oldenvs = os.addenvs(target:pkgenvs()) |
