Commit 85226e35 authored by Takafumi Kubota's avatar Takafumi Kubota
Browse files

Unity Builds: Do more detailed property checks

This patch increases unity-build opportunities.
Currently, the source files that have properties are simply excluded, even if
they have the same properties.
Here, I apply unity builds to the source file that can be bundled
together.
parent b4315cd2
Pipeline #195098 waiting for manual action with stages
in 3 minutes and 34 seconds
......@@ -2879,17 +2879,43 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
cmProp unityMode = target->GetProperty("UNITY_BUILD_MODE");
for (std::string lang : { "C", "CXX" }) {
std::vector<cmSourceFile*> filtered_sources;
std::copy_if(sources.begin(), sources.end(),
std::back_inserter(filtered_sources), [&](cmSourceFile* sf) {
return sf->GetLanguage() == lang &&
!sf->GetPropertyAsBool("SKIP_UNITY_BUILD_INCLUSION") &&
!sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
!sf->GetProperty("COMPILE_OPTIONS") &&
!sf->GetProperty("COMPILE_DEFINITIONS") &&
!sf->GetProperty("COMPILE_FLAGS") &&
!sf->GetProperty("INCLUDE_DIRECTORIES");
});
std::unordered_map<std::string, std::vector<cmSourceFile*>>
filtered_source_map;
for (auto* sf : sources) {
if (sf->GetLanguage() != lang)
continue;
if (sf->GetPropertyAsBool("SKIP_UNITY_BUILD_INCLUSION") ||
sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
continue;
std::string key = "";
if (sf->GetProperty("COMPILE_OPTIONS")) {
for (const auto& bt_str : sf->GetCompileOptions()) {
key += bt_str.Value;
}
}
if (auto* flag = sf->GetProperty("COMPILE_FLAGS")) {
key += *(flag);
}
if (sf->GetProperty("INCLUDE_DIRECTORIES")) {
for (const auto& bt_str : sf->GetIncludeDirectories()) {
key += bt_str.Value;
}
}
if (filtered_source_map.find(key) == filtered_source_map.end()) {
filtered_source_map[key] = { sf };
} else {
filtered_source_map[key].push_back(sf);
}
}
for (auto& itr : filtered_source_map) {
auto& filtered_sources = itr.second;
std::vector<std::string> unity_files;
if (!unityMode || *unityMode == "BATCH") {
......@@ -2915,6 +2941,7 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
unity->SetProperty("UNITY_SOURCE_FILE", file.c_str());
}
}
}
}
void cmLocalGenerator::AppendIPOLinkerFlags(std::string& flags,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment