mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-02 20:29:49 -05:00
cmLocalGenerator: De-duplicate unity source file generation
This commit is contained in:
+32
-40
@@ -37,6 +37,7 @@
|
|||||||
#include "cmInstallTargetGenerator.h"
|
#include "cmInstallTargetGenerator.h"
|
||||||
#include "cmLinkLineComputer.h"
|
#include "cmLinkLineComputer.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
|
#include "cmRange.h"
|
||||||
#include "cmRulePlaceholderExpander.h"
|
#include "cmRulePlaceholderExpander.h"
|
||||||
#include "cmSourceFile.h"
|
#include "cmSourceFile.h"
|
||||||
#include "cmSourceFileLocation.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(
|
void cmLocalGenerator::IncludeFileInUnitySources(
|
||||||
cmGeneratedFileStream& unity_file, std::string const& sf_full_path,
|
cmGeneratedFileStream& unity_file, std::string const& sf_full_path,
|
||||||
cmValue beforeInclude, cmValue afterInclude, cmValue uniqueIdName) const
|
cmValue beforeInclude, cmValue afterInclude, cmValue uniqueIdName) const
|
||||||
@@ -2856,8 +2880,6 @@ std::vector<std::string> cmLocalGenerator::AddUnityFilesModeAuto(
|
|||||||
batchSize = filtered_sources.size();
|
batchSize = filtered_sources.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
cmValue uniqueIdName = target->GetProperty("UNITY_BUILD_UNIQUE_ID");
|
|
||||||
|
|
||||||
std::vector<std::string> unity_files;
|
std::vector<std::string> unity_files;
|
||||||
for (size_t itemsLeft = filtered_sources.size(), chunk, batch = 0;
|
for (size_t itemsLeft = filtered_sources.size(), chunk, batch = 0;
|
||||||
itemsLeft > 0; itemsLeft -= chunk, ++batch) {
|
itemsLeft > 0; itemsLeft -= chunk, ++batch) {
|
||||||
@@ -2866,26 +2888,11 @@ std::vector<std::string> cmLocalGenerator::AddUnityFilesModeAuto(
|
|||||||
|
|
||||||
std::string filename = cmStrCat(filename_base, "unity_", batch,
|
std::string filename = cmStrCat(filename_base, "unity_", batch,
|
||||||
(lang == "C") ? "_c.c" : "_cxx.cxx");
|
(lang == "C") ? "_c.c" : "_cxx.cxx");
|
||||||
|
auto const begin = filtered_sources.begin() + batch * batchSize;
|
||||||
const std::string filename_tmp = cmStrCat(filename, ".tmp");
|
auto const end = begin + chunk;
|
||||||
{
|
unity_files.emplace_back(
|
||||||
size_t begin = batch * batchSize;
|
this->WriteUnitySource(target, cmMakeRange(begin, end), beforeInclude,
|
||||||
size_t end = begin + chunk;
|
afterInclude, std::move(filename)));
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
return unity_files;
|
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) {
|
for (auto const& item : explicit_mapping) {
|
||||||
auto const& name = item.first;
|
auto const& name = item.first;
|
||||||
std::string filename = cmStrCat(filename_base, "unity_", name,
|
std::string filename = cmStrCat(filename_base, "unity_", name,
|
||||||
(lang == "C") ? "_c.c" : "_cxx.cxx");
|
(lang == "C") ? "_c.c" : "_cxx.cxx");
|
||||||
|
unity_files.emplace_back(
|
||||||
const std::string filename_tmp = cmStrCat(filename, ".tmp");
|
this->WriteUnitySource(target, cmMakeRange(item.second), beforeInclude,
|
||||||
{
|
afterInclude, std::move(filename)));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return unity_files;
|
return unity_files;
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ class cmState;
|
|||||||
class cmTarget;
|
class cmTarget;
|
||||||
class cmake;
|
class cmake;
|
||||||
|
|
||||||
|
template <typename Iter>
|
||||||
|
class cmRange;
|
||||||
|
|
||||||
/** Flag if byproducts shall also be considered. */
|
/** Flag if byproducts shall also be considered. */
|
||||||
enum class cmSourceOutputKind
|
enum class cmSourceOutputKind
|
||||||
{
|
{
|
||||||
@@ -657,6 +660,11 @@ private:
|
|||||||
const std::string& ReuseFrom,
|
const std::string& ReuseFrom,
|
||||||
cmGeneratorTarget* reuseTarget,
|
cmGeneratorTarget* reuseTarget,
|
||||||
std::vector<std::string> const& extensions);
|
std::vector<std::string> const& extensions);
|
||||||
|
|
||||||
|
std::string WriteUnitySource(
|
||||||
|
cmGeneratorTarget* target,
|
||||||
|
cmRange<std::vector<cmSourceFile*>::const_iterator> sources,
|
||||||
|
cmValue beforeInclude, cmValue afterInclude, std::string filename) const;
|
||||||
void IncludeFileInUnitySources(cmGeneratedFileStream& unity_file,
|
void IncludeFileInUnitySources(cmGeneratedFileStream& unity_file,
|
||||||
std::string const& sf_full_path,
|
std::string const& sf_full_path,
|
||||||
cmValue beforeInclude, cmValue afterInclude,
|
cmValue beforeInclude, cmValue afterInclude,
|
||||||
|
|||||||
Reference in New Issue
Block a user