summaryrefslogtreecommitdiffstats
path: root/Source/cmExportBuildFileGenerator.cxx
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2024-01-18 18:19:17 (GMT)
committerBrad King <brad.king@kitware.com>2024-01-18 22:40:44 (GMT)
commitd791f3a180c7231bc2b45c9204c0a912c06b91ee (patch)
treeb603806f141162f94b2137a00c6da40a714a9674 /Source/cmExportBuildFileGenerator.cxx
parent2352dcc830ca4be6ccf05f801241b158ac79e7d7 (diff)
downloadCMake-d791f3a180c7231bc2b45c9204c0a912c06b91ee.zip
CMake-d791f3a180c7231bc2b45c9204c0a912c06b91ee.tar.gz
CMake-d791f3a180c7231bc2b45c9204c0a912c06b91ee.tar.bz2
cxxmodules: make export trampoline script files unique
Include the name of the `EXPORT` in the filename when generating export information for C++ modules. This allows the same directory to be used for multiple sets of C++ module-using targets. For `export(TARGETS)` uses, generate a name based on the hash of the concatenation of the target names involved with the `export()` call. Fixes: #25609
Diffstat (limited to 'Source/cmExportBuildFileGenerator.cxx')
-rw-r--r--Source/cmExportBuildFileGenerator.cxx31
1 files changed, 23 insertions, 8 deletions
diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx
index bf3bb8b..1a22445 100644
--- a/Source/cmExportBuildFileGenerator.cxx
+++ b/Source/cmExportBuildFileGenerator.cxx
@@ -3,6 +3,7 @@
#include "cmExportBuildFileGenerator.h"
#include <algorithm>
+#include <cstddef>
#include <map>
#include <memory>
#include <set>
@@ -13,6 +14,7 @@
#include <cmext/algorithm>
#include <cmext/string_view>
+#include "cmCryptoHash.h"
#include "cmExportSet.h"
#include "cmFileSet.h"
#include "cmGeneratedFileStream.h"
@@ -156,7 +158,19 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
this->GenerateTargetFileSets(gte, os);
}
- this->GenerateCxxModuleInformation(os);
+ std::string cxx_modules_name;
+ if (this->ExportSet) {
+ cxx_modules_name = this->ExportSet->GetName();
+ } else {
+ cmCryptoHash hasher(cmCryptoHash::AlgoSHA3_512);
+ constexpr std::size_t HASH_TRUNCATION = 12;
+ for (auto const& target : this->Targets) {
+ hasher.Append(target);
+ }
+ cxx_modules_name = hasher.FinalizeHex().substr(0, HASH_TRUNCATION);
+ }
+
+ this->GenerateCxxModuleInformation(cxx_modules_name, os);
// Generate import file content for each configuration.
for (std::string const& c : this->Configurations) {
@@ -165,7 +179,7 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
// Generate import file content for each configuration.
for (std::string const& c : this->Configurations) {
- this->GenerateImportCxxModuleConfigTargetInclusion(c);
+ this->GenerateImportCxxModuleConfigTargetInclusion(cxx_modules_name, c);
}
this->GenerateMissingTargetsCheckCode(os);
@@ -506,7 +520,7 @@ std::string cmExportBuildFileGenerator::GetCxxModulesDirectory() const
}
void cmExportBuildFileGenerator::GenerateCxxModuleConfigInformation(
- std::ostream& os) const
+ std::string const& name, std::ostream& os) const
{
const char* opt = "";
if (this->Configurations.size() > 1) {
@@ -519,13 +533,13 @@ void cmExportBuildFileGenerator::GenerateCxxModuleConfigInformation(
if (c.empty()) {
c = "noconfig";
}
- os << "include(\"${CMAKE_CURRENT_LIST_DIR}/cxx-modules-" << c << ".cmake\""
- << opt << ")\n";
+ os << "include(\"${CMAKE_CURRENT_LIST_DIR}/cxx-modules-" << name << '-'
+ << c << ".cmake\"" << opt << ")\n";
}
}
bool cmExportBuildFileGenerator::GenerateImportCxxModuleConfigTargetInclusion(
- std::string config) const
+ std::string const& name, std::string config) const
{
auto cxx_modules_dirname = this->GetCxxModulesDirectory();
if (cxx_modules_dirname.empty()) {
@@ -536,8 +550,9 @@ bool cmExportBuildFileGenerator::GenerateImportCxxModuleConfigTargetInclusion(
config = "noconfig";
}
- std::string fileName = cmStrCat(this->FileDir, '/', cxx_modules_dirname,
- "/cxx-modules-", config, ".cmake");
+ std::string fileName =
+ cmStrCat(this->FileDir, '/', cxx_modules_dirname, "/cxx-modules-", name,
+ '-', config, ".cmake");
cmGeneratedFileStream os(fileName, true);
if (!os) {