|
|
@@ -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;
|