summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-01-26 14:00:21 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-01-26 14:00:28 (GMT)
commita5124f6bad869a88a63551c494aaaeb2b9272590 (patch)
treecb15b1493d49f2dddff86d3397040b4044e839d0 /Source
parent6b50138ae6e062e6961f02da7b3a0efd9599fc74 (diff)
parentee9da769725c3e58bbb002d648cfe75de94f7a78 (diff)
downloadCMake-a5124f6bad869a88a63551c494aaaeb2b9272590.zip
CMake-a5124f6bad869a88a63551c494aaaeb2b9272590.tar.gz
CMake-a5124f6bad869a88a63551c494aaaeb2b9272590.tar.bz2
Merge topic 'reproducible-unity-id'
ee9da76972 Unity: Generate reproducible unity IDs for anonymous namespaces Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5727
Diffstat (limited to 'Source')
-rw-r--r--Source/cmLocalGenerator.cxx35
-rw-r--r--Source/cmLocalGenerator.h14
2 files changed, 39 insertions, 10 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 86eddc2..a6d898d 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -2768,17 +2768,32 @@ inline void RegisterUnitySources(cmGeneratorTarget* target, cmSourceFile* sf,
target->AddSourceFileToUnityBatch(sf->ResolveFullPath());
sf->SetProperty("UNITY_SOURCE_FILE", filename.c_str());
}
+}
-inline void IncludeFileInUnitySources(cmGeneratedFileStream& unity_file,
- std::string const& sf_full_path,
- cmProp beforeInclude,
- cmProp afterInclude, cmProp uniqueIdName)
+void cmLocalGenerator::IncludeFileInUnitySources(
+ cmGeneratedFileStream& unity_file, std::string const& sf_full_path,
+ cmProp beforeInclude, cmProp afterInclude, cmProp uniqueIdName)
{
-
if (uniqueIdName && !uniqueIdName->empty()) {
- unity_file << "#undef " << *uniqueIdName << "\n"
+ std::string pathToHash;
+ auto PathEqOrSubDir = [](std::string const& a, std::string const& b) {
+ return (cmSystemTools::ComparePath(a, b) ||
+ cmSystemTools::IsSubDirectory(a, b));
+ };
+ const auto path = cmSystemTools::GetFilenamePath(sf_full_path);
+ if (PathEqOrSubDir(path, this->GetBinaryDirectory())) {
+ pathToHash = "BLD_" +
+ cmSystemTools::RelativePath(this->GetBinaryDirectory(), sf_full_path);
+ } else if (PathEqOrSubDir(path, this->GetSourceDirectory())) {
+ pathToHash = "SRC_" +
+ cmSystemTools::RelativePath(this->GetSourceDirectory(), sf_full_path);
+ } else {
+ pathToHash = "ABS_" + sf_full_path;
+ }
+ unity_file << "/* " << pathToHash << " */\n"
+ << "#undef " << *uniqueIdName << "\n"
<< "#define " << *uniqueIdName << " unity_"
- << cmSystemTools::ComputeStringMD5(sf_full_path) << "\n";
+ << cmSystemTools::ComputeStringMD5(pathToHash) << "\n";
}
if (beforeInclude) {
@@ -2790,9 +2805,10 @@ inline void IncludeFileInUnitySources(cmGeneratedFileStream& unity_file,
if (afterInclude) {
unity_file << *afterInclude << "\n";
}
+ unity_file << "\n";
}
-std::vector<std::string> AddUnityFilesModeAuto(
+std::vector<std::string> cmLocalGenerator::AddUnityFilesModeAuto(
cmGeneratorTarget* target, std::string const& lang,
std::vector<cmSourceFile*> const& filtered_sources, cmProp beforeInclude,
cmProp afterInclude, std::string const& filename_base, size_t batchSize)
@@ -2835,7 +2851,7 @@ std::vector<std::string> AddUnityFilesModeAuto(
return unity_files;
}
-std::vector<std::string> AddUnityFilesModeGroup(
+std::vector<std::string> cmLocalGenerator::AddUnityFilesModeGroup(
cmGeneratorTarget* target, std::string const& lang,
std::vector<cmSourceFile*> const& filtered_sources, cmProp beforeInclude,
cmProp afterInclude, std::string const& filename_base)
@@ -2883,7 +2899,6 @@ std::vector<std::string> AddUnityFilesModeGroup(
return unity_files;
}
-}
void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
{
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 91dd8ae..a3610fd 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -4,6 +4,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
+#include <cstddef>
#include <iosfwd>
#include <map>
#include <memory>
@@ -27,6 +28,7 @@ class cmComputeLinkInformation;
class cmCustomCommand;
class cmCustomCommandGenerator;
class cmCustomCommandLines;
+class cmGeneratedFileStream;
class cmGeneratorTarget;
class cmGlobalGenerator;
class cmImplicitDependsList;
@@ -651,6 +653,18 @@ private:
const std::string& ReuseFrom,
cmGeneratorTarget* reuseTarget,
std::vector<std::string> const& extensions);
+ void IncludeFileInUnitySources(cmGeneratedFileStream& unity_file,
+ std::string const& sf_full_path,
+ cmProp beforeInclude, cmProp afterInclude,
+ cmProp uniqueIdName);
+ std::vector<std::string> AddUnityFilesModeAuto(
+ cmGeneratorTarget* target, std::string const& lang,
+ std::vector<cmSourceFile*> const& filtered_sources, cmProp beforeInclude,
+ cmProp afterInclude, std::string const& filename_base, size_t batchSize);
+ std::vector<std::string> AddUnityFilesModeGroup(
+ cmGeneratorTarget* target, std::string const& lang,
+ std::vector<cmSourceFile*> const& filtered_sources, cmProp beforeInclude,
+ cmProp afterInclude, std::string const& filename_base);
};
#if !defined(CMAKE_BOOTSTRAP)