From b3d1bbbbcc841b452f132b9927bef1424625d923 Mon Sep 17 00:00:00 2001
From: Ben Boeckel <ben.boeckel@kitware.com>
Date: Tue, 26 Sep 2023 08:51:12 -0400
Subject: cmExportFileGenerator: relocate include directories for C++ modules

Include directories are paths that need munged on install to support the
installation prefix.

Fixes: #25275
---
 Source/cmExportFileGenerator.cxx | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
index 5a12297..dae061b 100644
--- a/Source/cmExportFileGenerator.cxx
+++ b/Source/cmExportFileGenerator.cxx
@@ -1256,6 +1256,18 @@ void cmExportFileGenerator::GenerateImportedFileChecksCode(
   os << ")\n\n";
 }
 
+enum class PropertyType
+{
+  Strings,
+  Paths,
+};
+
+struct ModulePropertyTable
+{
+  cm::static_string_view Name;
+  PropertyType Type;
+};
+
 bool cmExportFileGenerator::PopulateCxxModuleExportProperties(
   cmGeneratorTarget const* gte, ImportPropertyMap& properties,
   cmGeneratorExpression::PreprocessContext ctx, std::string& errorMessage)
@@ -1279,14 +1291,14 @@ bool cmExportFileGenerator::PopulateCxxModuleExportProperties(
     }
   }
 
-  const cm::static_string_view exportedModuleProperties[] = {
-    "INCLUDE_DIRECTORIES"_s,
-    "COMPILE_DEFINITIONS"_s,
-    "COMPILE_OPTIONS"_s,
-    "COMPILE_FEATURES"_s,
+  const ModulePropertyTable exportedModuleProperties[] = {
+    { "INCLUDE_DIRECTORIES"_s, PropertyType::Paths },
+    { "COMPILE_DEFINITIONS"_s, PropertyType::Strings },
+    { "COMPILE_OPTIONS"_s, PropertyType::Strings },
+    { "COMPILE_FEATURES"_s, PropertyType::Strings },
   };
-  for (auto const& propName : exportedModuleProperties) {
-    auto const propNameStr = std::string(propName);
+  for (auto const& propEntry : exportedModuleProperties) {
+    auto const propNameStr = std::string(propEntry.Name);
     cmValue prop = gte->Target->GetComputedProperty(
       propNameStr, *gte->Target->GetMakefile());
     if (!prop) {
@@ -1294,9 +1306,14 @@ bool cmExportFileGenerator::PopulateCxxModuleExportProperties(
     }
     if (prop) {
       auto const exportedPropName =
-        cmStrCat("IMPORTED_CXX_MODULES_", propName);
+        cmStrCat("IMPORTED_CXX_MODULES_", propEntry.Name);
       properties[exportedPropName] =
         cmGeneratorExpression::Preprocess(*prop, ctx);
+      if (ctx == cmGeneratorExpression::InstallInterface &&
+          propEntry.Type == PropertyType::Paths) {
+        this->ReplaceInstallPrefix(properties[exportedPropName]);
+        prefixItems(properties[exportedPropName]);
+      }
     }
   }
 
-- 
cgit v0.12