xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.05k stars 786 forks source link

compile_commands.json缺少对pb头文件路径的包含 #3032

Closed pankey888 closed 1 year ago

pankey888 commented 1 year ago

Xmake 版本

2.7.2

操作系统版本和架构

Ubuntu 22.04

描述问题

建立两个工程目标,一个用于转换proto文件(假定目标为test2_pb),另一个使用它(假定目标为test)。当多次执行xmake project -k compile_commands,或通过vscode插件命令XMake: UpdateIntellisense更新compile_commands.json时,会有较大概率出现先生成test,再生成test2_pb,test的编译命令中缺少对test2_pb头文件路径的包含,如下所示:

[
{
  "directory": "/home/cjm/projects/protobuf",
  "arguments": ["/usr/bin/gcc", "-c", "-m64", "-fvisibility=hidden", "-fvisibility-inlines-hidden", "-O3", "-std=c++17", "-DNDEBUG", "-o", "build/.objs/test/linux/x86_64/release/src/test/src/test.cc.o", "src/test/src/test.cc"],
  "file": "src/test/src/test.cc"
},
{
  "directory": "/home/cjm/projects/protobuf",
  "arguments": ["/usr/bin/gcc", "-c", "-m64", "-fvisibility=hidden", "-fvisibility-inlines-hidden", "-O3", "-std=c++17", "-DNDEBUG", "-std=c++11", "-Ibuild/.gens/test2_pb/linux/x86_64/release/rules/protobuf/src/proto", "-o", "build/.objs/test2_pb/linux/x86_64/release/gens/rules/protobuf/src/proto/test2.pb.cc.o", "build/.gens/test2_pb/linux/x86_64/release/rules/protobuf/src/proto/test2.pb.cc"],
  "file": "build/.gens/test2_pb/linux/x86_64/release/rules/protobuf/src/proto/test2.pb.cc"
}]

而正确的应该是:

[
{
  "directory": "/home/cjm/projects/protobuf",
  "arguments": ["/usr/bin/gcc", "-c", "-m64", "-fvisibility=hidden", "-fvisibility-inlines-hidden", "-O3", "-std=c++17", "-DNDEBUG", "-std=c++11", "-Ibuild/.gens/test2_pb/linux/x86_64/release/rules/protobuf/src/proto", "-o", "build/.objs/test2_pb/linux/x86_64/release/gens/rules/protobuf/src/proto/test2.pb.cc.o", "build/.gens/test2_pb/linux/x86_64/release/rules/protobuf/src/proto/test2.pb.cc"],
  "file": "build/.gens/test2_pb/linux/x86_64/release/rules/protobuf/src/proto/test2.pb.cc"
},
{
  "directory": "/home/cjm/projects/protobuf",
  "arguments": ["/usr/bin/gcc", "-c", "-m64", "-fvisibility=hidden", "-fvisibility-inlines-hidden", "-O3", "-std=c++17", "-Ibuild/.gens/test2_pb/linux/x86_64/release/rules/protobuf/src/proto", "-DNDEBUG", "-o", "build/.objs/test/linux/x86_64/release/src/test/src/test.cc.o", "src/test/src/test.cc"],
  "file": "src/test/src/test.cc"
}]

期待的结果

能正确生成compile_commands.json文件。

工程配置

protobuf.tar.gz

附加信息和错误日志

No response

waruqi commented 1 year ago
add_requires("protobuf-cpp")

target("test2_pb")
    set_kind("object")
    add_rules("protobuf.cpp")
    add_packages("protobuf-cpp", {public = true})
    add_syslinks("pthread", {public = true})
    add_files("test2.proto", {proto_public = true})
pankey888 commented 1 year ago

搞定,多谢!