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,40 +2879,67 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target) ...@@ -2879,40 +2879,67 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
cmProp unityMode = target->GetProperty("UNITY_BUILD_MODE"); cmProp unityMode = target->GetProperty("UNITY_BUILD_MODE");
for (std::string lang : { "C", "CXX" }) { for (std::string lang : { "C", "CXX" }) {
std::vector<cmSourceFile*> filtered_sources; std::unordered_map<std::string, std::vector<cmSourceFile*>>
std::copy_if(sources.begin(), sources.end(), filtered_source_map;
std::back_inserter(filtered_sources), [&](cmSourceFile* sf) { for (auto* sf : sources) {
return sf->GetLanguage() == lang && if (sf->GetLanguage() != lang)
!sf->GetPropertyAsBool("SKIP_UNITY_BUILD_INCLUSION") && continue;
!sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
!sf->GetProperty("COMPILE_OPTIONS") && if (sf->GetPropertyAsBool("SKIP_UNITY_BUILD_INCLUSION") ||
!sf->GetProperty("COMPILE_DEFINITIONS") && sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
!sf->GetProperty("COMPILE_FLAGS") && continue;
!sf->GetProperty("INCLUDE_DIRECTORIES");
}); std::string key = "";
std::vector<std::string> unity_files; if (sf->GetProperty("COMPILE_OPTIONS")) {
if (!unityMode || *unityMode == "BATCH") { for (const auto& bt_str : sf->GetCompileOptions()) {
unity_files = key += bt_str.Value;
AddUnityFilesModeAuto(target, lang, filtered_sources, beforeInclude, }
afterInclude, filename_base, unityBatchSize); }
} else if (unityMode && *unityMode == "GROUP") {
unity_files = if (auto* flag = sf->GetProperty("COMPILE_FLAGS")) {
AddUnityFilesModeGroup(target, lang, filtered_sources, beforeInclude, key += *(flag);
afterInclude, filename_base); }
} else {
// unity mode is set to an unsupported value if (sf->GetProperty("INCLUDE_DIRECTORIES")) {
std::string e("Invalid UNITY_BUILD_MODE value of " + *unityMode + for (const auto& bt_str : sf->GetIncludeDirectories()) {
" assigned to target " + target->GetName() + key += bt_str.Value;
". Acceptable values are BATCH and GROUP."); }
this->IssueMessage(MessageType::FATAL_ERROR, e); }
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 const& file : unity_files) { for (auto& itr : filtered_source_map) {
auto unity = this->GetMakefile()->GetOrCreateSource(file); auto& filtered_sources = itr.second;
target->AddSource(file, true);
unity->SetProperty("SKIP_UNITY_BUILD_INCLUSION", "ON"); std::vector<std::string> unity_files;
unity->SetProperty("UNITY_SOURCE_FILE", file.c_str()); if (!unityMode || *unityMode == "BATCH") {
unity_files =
AddUnityFilesModeAuto(target, lang, filtered_sources, beforeInclude,
afterInclude, filename_base, unityBatchSize);
} else if (unityMode && *unityMode == "GROUP") {
unity_files =
AddUnityFilesModeGroup(target, lang, filtered_sources, beforeInclude,
afterInclude, filename_base);
} else {
// unity mode is set to an unsupported value
std::string e("Invalid UNITY_BUILD_MODE value of " + *unityMode +
" assigned to target " + target->GetName() +
". Acceptable values are BATCH and GROUP.");
this->IssueMessage(MessageType::FATAL_ERROR, e);
}
for (auto const& file : unity_files) {
auto unity = this->GetMakefile()->GetOrCreateSource(file);
target->AddSource(file, true);
unity->SetProperty("SKIP_UNITY_BUILD_INCLUSION", "ON");
unity->SetProperty("UNITY_SOURCE_FILE", file.c_str());
}
} }
} }
} }
......
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