summaryrefslogtreecommitdiffstats
path: root/Source/cmLocalGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-11-10 16:22:14 (GMT)
committerBrad King <brad.king@kitware.com>2021-11-10 18:53:57 (GMT)
commit0b56f92576232d82a23ab37c597ef9af84daf9e5 (patch)
tree6af221ec70120b5a397581f70acb94815dcfc3ef /Source/cmLocalGenerator.cxx
parent4fd2d62613af072204910b303fc1506804279df1 (diff)
downloadCMake-0b56f92576232d82a23ab37c597ef9af84daf9e5.zip
CMake-0b56f92576232d82a23ab37c597ef9af84daf9e5.tar.gz
CMake-0b56f92576232d82a23ab37c597ef9af84daf9e5.tar.bz2
cmLocalGenerator: De-duplicate unity source file generation
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r--Source/cmLocalGenerator.cxx72
1 files changed, 32 insertions, 40 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 68a6a44..66b49e0 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -37,6 +37,7 @@
#include "cmInstallTargetGenerator.h"
#include "cmLinkLineComputer.h"
#include "cmMakefile.h"
+#include "cmRange.h"
#include "cmRulePlaceholderExpander.h"
#include "cmSourceFile.h"
#include "cmSourceFileLocation.h"
@@ -2806,6 +2807,29 @@ inline void RegisterUnitySources(cmGeneratorTarget* target, cmSourceFile* sf,
}
}
+std::string cmLocalGenerator::WriteUnitySource(
+ cmGeneratorTarget* target,
+ cmRange<std::vector<cmSourceFile*>::const_iterator> sources,
+ cmValue beforeInclude, cmValue afterInclude, std::string filename) const
+{
+ cmValue uniqueIdName = target->GetProperty("UNITY_BUILD_UNIQUE_ID");
+ const std::string filename_tmp = cmStrCat(filename, ".tmp");
+ {
+ cmGeneratedFileStream file(
+ filename_tmp, false,
+ target->GetGlobalGenerator()->GetMakefileEncoding());
+ file << "/* generated by CMake */\n\n";
+
+ for (cmSourceFile* sf : sources) {
+ RegisterUnitySources(target, sf, filename);
+ IncludeFileInUnitySources(file, sf->ResolveFullPath(), beforeInclude,
+ afterInclude, uniqueIdName);
+ }
+ }
+ cmSystemTools::MoveFileIfDifferent(filename_tmp, filename);
+ return filename;
+}
+
void cmLocalGenerator::IncludeFileInUnitySources(
cmGeneratedFileStream& unity_file, std::string const& sf_full_path,
cmValue beforeInclude, cmValue afterInclude, cmValue uniqueIdName) const
@@ -2856,8 +2880,6 @@ std::vector<std::string> cmLocalGenerator::AddUnityFilesModeAuto(
batchSize = filtered_sources.size();
}
- cmValue uniqueIdName = target->GetProperty("UNITY_BUILD_UNIQUE_ID");
-
std::vector<std::string> unity_files;
for (size_t itemsLeft = filtered_sources.size(), chunk, batch = 0;
itemsLeft > 0; itemsLeft -= chunk, ++batch) {
@@ -2866,26 +2888,11 @@ std::vector<std::string> cmLocalGenerator::AddUnityFilesModeAuto(
std::string filename = cmStrCat(filename_base, "unity_", batch,
(lang == "C") ? "_c.c" : "_cxx.cxx");
-
- const std::string filename_tmp = cmStrCat(filename, ".tmp");
- {
- size_t begin = batch * batchSize;
- size_t end = begin + chunk;
-
- cmGeneratedFileStream file(
- filename_tmp, false,
- target->GetGlobalGenerator()->GetMakefileEncoding());
- file << "/* generated by CMake */\n\n";
-
- for (; begin != end; ++begin) {
- cmSourceFile* sf = filtered_sources[begin];
- RegisterUnitySources(target, sf, filename);
- IncludeFileInUnitySources(file, sf->ResolveFullPath(), beforeInclude,
- afterInclude, uniqueIdName);
- }
- }
- cmSystemTools::MoveFileIfDifferent(filename_tmp, filename);
- unity_files.emplace_back(std::move(filename));
+ auto const begin = filtered_sources.begin() + batch * batchSize;
+ auto const end = begin + chunk;
+ unity_files.emplace_back(
+ this->WriteUnitySource(target, cmMakeRange(begin, end), beforeInclude,
+ afterInclude, std::move(filename)));
}
return unity_files;
}
@@ -2912,28 +2919,13 @@ std::vector<std::string> cmLocalGenerator::AddUnityFilesModeGroup(
}
}
- cmValue uniqueIdName = target->GetProperty("UNITY_BUILD_UNIQUE_ID");
-
for (auto const& item : explicit_mapping) {
auto const& name = item.first;
std::string filename = cmStrCat(filename_base, "unity_", name,
(lang == "C") ? "_c.c" : "_cxx.cxx");
-
- const std::string filename_tmp = cmStrCat(filename, ".tmp");
- {
- cmGeneratedFileStream file(
- filename_tmp, false,
- target->GetGlobalGenerator()->GetMakefileEncoding());
- file << "/* generated by CMake */\n\n";
-
- for (cmSourceFile* sf : item.second) {
- RegisterUnitySources(target, sf, filename);
- IncludeFileInUnitySources(file, sf->ResolveFullPath(), beforeInclude,
- afterInclude, uniqueIdName);
- }
- }
- cmSystemTools::MoveFileIfDifferent(filename_tmp, filename);
- unity_files.emplace_back(std::move(filename));
+ unity_files.emplace_back(
+ this->WriteUnitySource(target, cmMakeRange(item.second), beforeInclude,
+ afterInclude, std::move(filename)));
}
return unity_files;