diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2023-01-25 02:42:47 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2023-08-17 18:42:53 (GMT) |
commit | 249cd3efad6967ec3195b7e24d031eecfc42eba7 (patch) | |
tree | cbfe8883d172f004700224dcbd18162700236da2 /Source/cmExportFileGenerator.cxx | |
parent | 1690e451f7a640fbdd7bc693ea8010ebc52639bc (diff) | |
download | CMake-249cd3efad6967ec3195b7e24d031eecfc42eba7.zip CMake-249cd3efad6967ec3195b7e24d031eecfc42eba7.tar.gz CMake-249cd3efad6967ec3195b7e24d031eecfc42eba7.tar.bz2 |
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.
Diffstat (limited to 'Source/cmExportFileGenerator.cxx')
-rw-r--r-- | Source/cmExportFileGenerator.cxx | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 41234f4..5a12297 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -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) |