mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 21:31:08 -06:00
cmExportFileGenerator: export private compile info for C++ modules
When consuming exported targets which contain C++ modules, the consuming project must be able to recompile BMI files using the original target's flags. This is because a module source may use some private target usage requirement but not want to propagate it to consumers. To facilitate this, export the private information as necessary for consumers to be able to perform the BMI compilations.
This commit is contained in:
@@ -126,6 +126,15 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
|
||||
properties);
|
||||
|
||||
std::string errorMessage;
|
||||
if (!this->PopulateCxxModuleExportProperties(
|
||||
gte, properties, cmGeneratorExpression::BuildInterface,
|
||||
errorMessage)) {
|
||||
this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
|
||||
MessageType::FATAL_ERROR, errorMessage,
|
||||
this->LG->GetMakefile()->GetBacktrace());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->PopulateExportProperties(gte, properties, errorMessage)) {
|
||||
this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
|
||||
MessageType::FATAL_ERROR, errorMessage,
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include <cm/memory>
|
||||
#include <cmext/string_view>
|
||||
|
||||
#include "cmsys/FStream.hxx"
|
||||
|
||||
@@ -1255,6 +1256,77 @@ void cmExportFileGenerator::GenerateImportedFileChecksCode(
|
||||
os << ")\n\n";
|
||||
}
|
||||
|
||||
bool cmExportFileGenerator::PopulateCxxModuleExportProperties(
|
||||
cmGeneratorTarget const* gte, ImportPropertyMap& properties,
|
||||
cmGeneratorExpression::PreprocessContext ctx, std::string& errorMessage)
|
||||
{
|
||||
if (!gte->HaveCxx20ModuleSources(&errorMessage)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const cm::static_string_view exportedDirectModuleProperties[] = {
|
||||
"CXX_EXTENSIONS"_s,
|
||||
};
|
||||
for (auto const& propName : exportedDirectModuleProperties) {
|
||||
auto const propNameStr = std::string(propName);
|
||||
cmValue prop = gte->Target->GetComputedProperty(
|
||||
propNameStr, *gte->Target->GetMakefile());
|
||||
if (!prop) {
|
||||
prop = gte->Target->GetProperty(propNameStr);
|
||||
}
|
||||
if (prop) {
|
||||
properties[propNameStr] = cmGeneratorExpression::Preprocess(*prop, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
const cm::static_string_view exportedModuleProperties[] = {
|
||||
"INCLUDE_DIRECTORIES"_s,
|
||||
"COMPILE_DEFINITIONS"_s,
|
||||
"COMPILE_OPTIONS"_s,
|
||||
"COMPILE_FEATURES"_s,
|
||||
};
|
||||
for (auto const& propName : exportedModuleProperties) {
|
||||
auto const propNameStr = std::string(propName);
|
||||
cmValue prop = gte->Target->GetComputedProperty(
|
||||
propNameStr, *gte->Target->GetMakefile());
|
||||
if (!prop) {
|
||||
prop = gte->Target->GetProperty(propNameStr);
|
||||
}
|
||||
if (prop) {
|
||||
auto const exportedPropName =
|
||||
cmStrCat("IMPORTED_CXX_MODULES_", propName);
|
||||
properties[exportedPropName] =
|
||||
cmGeneratorExpression::Preprocess(*prop, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
const cm::static_string_view exportedLinkModuleProperties[] = {
|
||||
"LINK_LIBRARIES"_s,
|
||||
};
|
||||
for (auto const& propName : exportedLinkModuleProperties) {
|
||||
auto const propNameStr = std::string(propName);
|
||||
cmValue prop = gte->Target->GetComputedProperty(
|
||||
propNameStr, *gte->Target->GetMakefile());
|
||||
if (!prop) {
|
||||
prop = gte->Target->GetProperty(propNameStr);
|
||||
}
|
||||
if (prop) {
|
||||
auto const exportedPropName =
|
||||
cmStrCat("IMPORTED_CXX_MODULES_", propName);
|
||||
auto value = cmGeneratorExpression::Preprocess(*prop, ctx);
|
||||
this->ResolveTargetsInGeneratorExpressions(
|
||||
value, gte, cmExportFileGenerator::ReplaceFreeTargets);
|
||||
std::vector<std::string> wrappedValues;
|
||||
for (auto& item : cmList{ value }) {
|
||||
wrappedValues.push_back(cmStrCat("$<COMPILE_ONLY:", item, '>'));
|
||||
}
|
||||
properties[exportedPropName] = cmJoin(wrappedValues, ";");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cmExportFileGenerator::PopulateExportProperties(
|
||||
cmGeneratorTarget const* gte, ImportPropertyMap& properties,
|
||||
std::string& errorMessage)
|
||||
|
||||
@@ -175,6 +175,9 @@ protected:
|
||||
virtual void GenerateRequiredCMakeVersion(std::ostream& os,
|
||||
const char* versionString);
|
||||
|
||||
bool PopulateCxxModuleExportProperties(
|
||||
cmGeneratorTarget const* gte, ImportPropertyMap& properties,
|
||||
cmGeneratorExpression::PreprocessContext ctx, std::string& errorMessage);
|
||||
bool PopulateExportProperties(cmGeneratorTarget const* gte,
|
||||
ImportPropertyMap& properties,
|
||||
std::string& errorMessage);
|
||||
|
||||
@@ -126,6 +126,13 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
|
||||
gt, cmGeneratorExpression::InstallInterface, properties);
|
||||
|
||||
std::string errorMessage;
|
||||
if (!this->PopulateCxxModuleExportProperties(
|
||||
gt, properties, cmGeneratorExpression::InstallInterface,
|
||||
errorMessage)) {
|
||||
cmSystemTools::Error(errorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->PopulateExportProperties(gt, properties, errorMessage)) {
|
||||
cmSystemTools::Error(errorMessage);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user