fileapi: Extend codemodel targets with PRECOMPILE_HEADERS
This commit is contained in:
parent
b698764a31
commit
9f6d40ee23
@ -899,6 +899,22 @@ with members:
|
||||
an unsigned integer 0-based index into the ``backtraceGraph``
|
||||
member's ``nodes`` array.
|
||||
|
||||
``precompileHeaders``
|
||||
Optional member that is present when :command:`target_precompile_headers`
|
||||
or other command invocations set :prop_tgt:`PRECOMPILE_HEADERS` on the
|
||||
target. The value is a JSON array with an entry for each header. Each
|
||||
entry is a JSON object with members:
|
||||
|
||||
``header``
|
||||
Full path to the precompile header file.
|
||||
|
||||
``backtrace``
|
||||
Optional member that is present when a CMake language backtrace to
|
||||
the :command:`target_precompile_headers` or other command invocation
|
||||
that added this precompiled header is available. The value is an
|
||||
unsigned integer 0-based index into the ``backtraceGraph`` member's
|
||||
``nodes`` array.
|
||||
|
||||
``defines``
|
||||
Optional member that is present when there are preprocessor definitions.
|
||||
The value is a JSON array with an entry for each definition. Each
|
||||
|
@ -665,7 +665,7 @@ std::string cmFileAPI::NoSupportedVersion(
|
||||
|
||||
// The "codemodel" object kind.
|
||||
|
||||
static unsigned int const CodeModelV2Minor = 0;
|
||||
static unsigned int const CodeModelV2Minor = 1;
|
||||
|
||||
void cmFileAPI::BuildClientRequestCodeModel(
|
||||
ClientRequest& r, std::vector<RequestVersion> const& versions)
|
||||
|
@ -278,12 +278,14 @@ struct CompileData
|
||||
std::string Sysroot;
|
||||
std::vector<JBT<std::string>> Flags;
|
||||
std::vector<JBT<std::string>> Defines;
|
||||
std::vector<JBT<std::string>> PrecompileHeaders;
|
||||
std::vector<IncludeEntry> Includes;
|
||||
|
||||
friend bool operator==(CompileData const& l, CompileData const& r)
|
||||
{
|
||||
return (l.Language == r.Language && l.Sysroot == r.Sysroot &&
|
||||
l.Flags == r.Flags && l.Defines == r.Defines &&
|
||||
l.PrecompileHeaders == r.PrecompileHeaders &&
|
||||
l.Includes == r.Includes);
|
||||
}
|
||||
};
|
||||
@ -313,6 +315,10 @@ struct hash<CompileData>
|
||||
result = result ^ hash<std::string>()(i.Value) ^
|
||||
hash<Json::ArrayIndex>()(i.Backtrace.Index);
|
||||
}
|
||||
for (auto const& i : in.PrecompileHeaders) {
|
||||
result = result ^ hash<std::string>()(i.Value) ^
|
||||
hash<Json::ArrayIndex>()(i.Backtrace.Index);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@ -369,6 +375,7 @@ class Target
|
||||
Json::Value DumpPaths();
|
||||
Json::Value DumpCompileData(CompileData const& cd);
|
||||
Json::Value DumpInclude(CompileData::IncludeEntry const& inc);
|
||||
Json::Value DumpPrecompileHeader(JBT<std::string> const& header);
|
||||
Json::Value DumpDefine(JBT<std::string> const& def);
|
||||
Json::Value DumpSources();
|
||||
Json::Value DumpSource(cmGeneratorTarget::SourceAndKind const& sk,
|
||||
@ -825,6 +832,11 @@ void Target::ProcessLanguage(std::string const& lang)
|
||||
this->ToJBT(i),
|
||||
this->GT->IsSystemIncludeDirectory(i.Value, this->Config, lang));
|
||||
}
|
||||
std::vector<BT<std::string>> precompileHeaders =
|
||||
this->GT->GetPrecompileHeaders(this->Config, lang);
|
||||
for (BT<std::string> const& pch : precompileHeaders) {
|
||||
cd.PrecompileHeaders.emplace_back(this->ToJBT(pch));
|
||||
}
|
||||
}
|
||||
|
||||
Json::ArrayIndex Target::AddSourceGroup(cmSourceGroup* sg, Json::ArrayIndex si)
|
||||
@ -980,6 +992,9 @@ CompileData Target::MergeCompileData(CompileData const& fd)
|
||||
// All compile groups share the sysroot of the target.
|
||||
cd.Sysroot = td.Sysroot;
|
||||
|
||||
// All compile groups share the precompile headers of the target.
|
||||
cd.PrecompileHeaders = td.PrecompileHeaders;
|
||||
|
||||
// Use target-wide flags followed by source-specific flags.
|
||||
cd.Flags.reserve(td.Flags.size() + fd.Flags.size());
|
||||
cd.Flags.insert(cd.Flags.end(), td.Flags.begin(), td.Flags.end());
|
||||
@ -1130,6 +1145,13 @@ Json::Value Target::DumpCompileData(CompileData const& cd)
|
||||
}
|
||||
result["defines"] = std::move(defines);
|
||||
}
|
||||
if (!cd.PrecompileHeaders.empty()) {
|
||||
Json::Value precompileHeaders = Json::arrayValue;
|
||||
for (JBT<std::string> const& pch : cd.PrecompileHeaders) {
|
||||
precompileHeaders.append(this->DumpPrecompileHeader(pch));
|
||||
}
|
||||
result["precompileHeaders"] = std::move(precompileHeaders);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1145,6 +1167,14 @@ Json::Value Target::DumpInclude(CompileData::IncludeEntry const& inc)
|
||||
return include;
|
||||
}
|
||||
|
||||
Json::Value Target::DumpPrecompileHeader(JBT<std::string> const& header)
|
||||
{
|
||||
Json::Value precompileHeader = Json::objectValue;
|
||||
precompileHeader["header"] = header.Value;
|
||||
this->AddBacktrace(precompileHeader, header.Backtrace);
|
||||
return precompileHeader;
|
||||
}
|
||||
|
||||
Json::Value Target::DumpDefine(JBT<std::string> const& def)
|
||||
{
|
||||
Json::Value define = Json::objectValue;
|
||||
|
@ -1 +1 @@
|
||||
^{"fileApi":{"requests":\[{"kind":"codemodel","version":\[{"major":2,"minor":0}]},{"kind":"cache","version":\[{"major":2,"minor":0}]},{"kind":"cmakeFiles","version":\[{"major":1,"minor":0}]}]},"generators":\[.*\],"serverMode":true,"version":{.*}}$
|
||||
^{"fileApi":{"requests":\[{"kind":"codemodel","version":\[{"major":2,"minor":1}]},{"kind":"cache","version":\[{"major":2,"minor":0}]},{"kind":"cmakeFiles","version":\[{"major":1,"minor":0}]}]},"generators":\[.*\],"serverMode":true,"version":{.*}}$
|
||||
|
@ -12,7 +12,7 @@ def read_codemodel_json_data(filename):
|
||||
def check_objects(o, g):
|
||||
assert is_list(o)
|
||||
assert len(o) == 1
|
||||
check_index_object(o[0], "codemodel", 2, 0, check_object_codemodel(g))
|
||||
check_index_object(o[0], "codemodel", 2, 1, check_object_codemodel(g))
|
||||
|
||||
def check_backtrace(t, b, backtrace):
|
||||
btg = t["backtraceGraph"]
|
||||
@ -404,6 +404,23 @@ def check_target(c):
|
||||
missing_exception=lambda e: "Include path: %s" % e["path"],
|
||||
extra_exception=lambda a: "Include path: %s" % a["path"])
|
||||
|
||||
if "precompileHeaders" in expected:
|
||||
expected_keys.append("precompileHeaders")
|
||||
|
||||
def check_precompile_header(actual, expected):
|
||||
assert is_dict(actual)
|
||||
expected_keys = ["backtrace", "header"]
|
||||
check_backtrace(obj, actual["backtrace"], expected["backtrace"])
|
||||
|
||||
assert sorted(actual.keys()) == sorted(expected_keys)
|
||||
|
||||
check_list_match(lambda a, e: matches(a["header"], e["header"]),
|
||||
actual["precompileHeaders"], expected["precompileHeaders"],
|
||||
check=check_precompile_header,
|
||||
check_exception=lambda a, e: "Precompile header: %s" % a["header"],
|
||||
missing_exception=lambda e: "Precompile header: %s" % e["header"],
|
||||
extra_exception=lambda a: "Precompile header: %s" % a["header"])
|
||||
|
||||
if expected["defines"] is not None:
|
||||
expected_keys.append("defines")
|
||||
|
||||
|
@ -43,6 +43,25 @@
|
||||
],
|
||||
"includes": null,
|
||||
"defines": null,
|
||||
"precompileHeaders": [
|
||||
{
|
||||
"header": ".*empty\\.h$",
|
||||
"backtrace": [
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": 21,
|
||||
"command": "target_precompile_headers",
|
||||
"hasParent": true
|
||||
},
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": null,
|
||||
"command": null,
|
||||
"hasParent": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"compileCommandFragments": [
|
||||
{
|
||||
"fragment" : "TargetCompileOptions",
|
||||
|
@ -7,6 +7,25 @@
|
||||
],
|
||||
"includes": null,
|
||||
"defines": null,
|
||||
"precompileHeaders": [
|
||||
{
|
||||
"header": ".*empty\\.h$",
|
||||
"backtrace": [
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": 21,
|
||||
"command": "target_precompile_headers",
|
||||
"hasParent": true
|
||||
},
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": null,
|
||||
"command": null,
|
||||
"hasParent": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"compileCommandFragments": [
|
||||
{
|
||||
"fragment": "TargetCompileOptions",
|
||||
@ -34,6 +53,25 @@
|
||||
],
|
||||
"includes": null,
|
||||
"defines": null,
|
||||
"precompileHeaders": [
|
||||
{
|
||||
"header": ".*empty\\.h$",
|
||||
"backtrace": [
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": 21,
|
||||
"command": "target_precompile_headers",
|
||||
"hasParent": true
|
||||
},
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": null,
|
||||
"command": null,
|
||||
"hasParent": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"compileCommandFragments": [
|
||||
{
|
||||
"fragment": "TargetCompileOptions",
|
||||
|
@ -7,6 +7,25 @@
|
||||
],
|
||||
"includes": null,
|
||||
"defines": null,
|
||||
"precompileHeaders": [
|
||||
{
|
||||
"header": ".*empty\\.h$",
|
||||
"backtrace": [
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": 21,
|
||||
"command": "target_precompile_headers",
|
||||
"hasParent": true
|
||||
},
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": null,
|
||||
"command": null,
|
||||
"hasParent": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"compileCommandFragments": [
|
||||
{
|
||||
"fragment": "TargetCompileOptions",
|
||||
@ -34,6 +53,25 @@
|
||||
],
|
||||
"includes": null,
|
||||
"defines": null,
|
||||
"precompileHeaders": [
|
||||
{
|
||||
"header": ".*empty\\.h$",
|
||||
"backtrace": [
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": 21,
|
||||
"command": "target_precompile_headers",
|
||||
"hasParent": true
|
||||
},
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": null,
|
||||
"command": null,
|
||||
"hasParent": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"compileCommandFragments": [
|
||||
{
|
||||
"fragment": "TargetCompileOptions",
|
||||
@ -61,6 +99,25 @@
|
||||
],
|
||||
"includes": null,
|
||||
"defines": null,
|
||||
"precompileHeaders": [
|
||||
{
|
||||
"header": ".*empty\\.h$",
|
||||
"backtrace": [
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": 21,
|
||||
"command": "target_precompile_headers",
|
||||
"hasParent": true
|
||||
},
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": null,
|
||||
"command": null,
|
||||
"hasParent": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"compileCommandFragments": [
|
||||
{
|
||||
"fragment": "TargetCompileOptions",
|
||||
|
@ -7,6 +7,25 @@
|
||||
],
|
||||
"includes": null,
|
||||
"defines": null,
|
||||
"precompileHeaders": [
|
||||
{
|
||||
"header": ".*empty\\.h$",
|
||||
"backtrace": [
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": 21,
|
||||
"command": "target_precompile_headers",
|
||||
"hasParent": true
|
||||
},
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": null,
|
||||
"command": null,
|
||||
"hasParent": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"compileCommandFragments": [
|
||||
{
|
||||
"fragment": "TargetCompileOptions",
|
||||
@ -34,6 +53,25 @@
|
||||
],
|
||||
"includes": null,
|
||||
"defines": null,
|
||||
"precompileHeaders": [
|
||||
{
|
||||
"header": ".*empty\\.h$",
|
||||
"backtrace": [
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": 21,
|
||||
"command": "target_precompile_headers",
|
||||
"hasParent": true
|
||||
},
|
||||
{
|
||||
"file": "^cxx/CMakeLists\\.txt$",
|
||||
"line": null,
|
||||
"command": null,
|
||||
"hasParent": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"compileCommandFragments": [
|
||||
{
|
||||
"fragment": "TargetCompileOptions",
|
||||
|
Loading…
Reference in New Issue
Block a user