Parcourir la source

cxxmodules: Do not expect collator install scripts with no CXX_MODULES

Calling `install(EXPORT)` with the `CXX_MODULES_DIRECTORY` parameter
leads to installation rules being generated which `include()` CMake
scripts that set the `IMPORTED_CXX_MODULES_[CONFIG]` target property for
relevant targets.  However, these scripts don't get generated for
targets in an export set which don't have any C++20 modules.  When the
installation rules attempt to `include()` the missing scripts, the
install fails.

Co-authored-by: Brad King <[email protected]>
Tyler il y a 2 ans
Parent
commit
f2a699261b

+ 6 - 0
Source/cmExportBuildFileGenerator.cxx

@@ -542,6 +542,12 @@ bool cmExportBuildFileGenerator::GenerateImportCxxModuleConfigTargetInclusion(
   os.SetCopyIfDifferent(true);
 
   for (auto const* tgt : this->ExportedTargets) {
+    // Only targets with C++ module sources will have a
+    // collator-generated install script.
+    if (!tgt->HaveCxx20ModuleSources()) {
+      continue;
+    }
+
     os << "include(\"${CMAKE_CURRENT_LIST_DIR}/target-" << tgt->GetExportName()
        << '-' << config << ".cmake\")\n";
   }

+ 6 - 0
Source/cmExportInstallFileGenerator.cxx

@@ -752,6 +752,12 @@ bool cmExportInstallFileGenerator::
 
   auto& prop_files = this->ConfigCxxModuleTargetFiles[config];
   for (auto const* tgt : this->ExportedTargets) {
+    // Only targets with C++ module sources will have a
+    // collator-generated install script.
+    if (!tgt->HaveCxx20ModuleSources()) {
+      continue;
+    }
+
     auto prop_filename = cmStrCat("target-", tgt->GetExportName(), '-',
                                   filename_config, ".cmake");
     prop_files.emplace_back(cmStrCat(dest, prop_filename));

+ 3 - 1
Tests/RunCMake/CXXModules/examples/export-bmi-and-interface-build/CMakeLists.txt

@@ -21,7 +21,9 @@ target_sources(export_bmi_and_interfaces
         importable.cxx)
 target_compile_features(export_bmi_and_interfaces PUBLIC cxx_std_20)
 
-install(TARGETS export_bmi_and_interfaces
+add_library(no_modules STATIC no_modules.cxx)
+
+install(TARGETS export_bmi_and_interfaces no_modules
   EXPORT CXXModules
   FILE_SET modules DESTINATION "lib/cxx/miu"
   CXX_MODULES_BMI DESTINATION "lib/cxx/bmi")

+ 3 - 0
Tests/RunCMake/CXXModules/examples/export-bmi-and-interface-build/no_modules.cxx

@@ -0,0 +1,3 @@
+void no_modules()
+{
+}

+ 3 - 1
Tests/RunCMake/CXXModules/examples/export-bmi-and-interface-install/CMakeLists.txt

@@ -21,7 +21,9 @@ target_sources(export_bmi_and_interfaces
         importable.cxx)
 target_compile_features(export_bmi_and_interfaces PUBLIC cxx_std_20)
 
-install(TARGETS export_bmi_and_interfaces
+add_library(no_modules STATIC no_modules.cxx)
+
+install(TARGETS export_bmi_and_interfaces no_modules
   EXPORT CXXModules
   FILE_SET modules DESTINATION "lib/cxx/miu"
   CXX_MODULES_BMI DESTINATION "lib/cxx/bmi")

+ 3 - 0
Tests/RunCMake/CXXModules/examples/export-bmi-and-interface-install/no_modules.cxx

@@ -0,0 +1,3 @@
+void no_modules()
+{
+}

+ 3 - 1
Tests/RunCMake/CXXModules/examples/export-interface-build/CMakeLists.txt

@@ -21,7 +21,9 @@ target_sources(export_interfaces
         importable.cxx)
 target_compile_features(export_interfaces PUBLIC cxx_std_20)
 
-install(TARGETS export_interfaces
+add_library(no_modules STATIC no_modules.cxx)
+
+install(TARGETS export_interfaces no_modules
   EXPORT CXXModules
   FILE_SET modules DESTINATION "lib/cxx/miu")
 export(EXPORT CXXModules

+ 3 - 0
Tests/RunCMake/CXXModules/examples/export-interface-build/no_modules.cxx

@@ -0,0 +1,3 @@
+void no_modules()
+{
+}

+ 3 - 1
Tests/RunCMake/CXXModules/examples/export-interface-install/CMakeLists.txt

@@ -21,7 +21,9 @@ target_sources(export_interfaces
         importable.cxx)
 target_compile_features(export_interfaces PUBLIC cxx_std_20)
 
-install(TARGETS export_interfaces
+add_library(no_modules STATIC no_modules.cxx)
+
+install(TARGETS export_interfaces no_modules
   EXPORT CXXModules
   FILE_SET modules DESTINATION "lib/cxx/miu")
 install(EXPORT CXXModules

+ 3 - 0
Tests/RunCMake/CXXModules/examples/export-interface-install/no_modules.cxx

@@ -0,0 +1,3 @@
+void no_modules()
+{
+}

+ 3 - 1
Tests/RunCMake/CXXModules/examples/export-interface-no-properties-build/CMakeLists.txt

@@ -21,7 +21,9 @@ target_sources(export_interfaces_no_properties
         importable.cxx)
 target_compile_features(export_interfaces_no_properties PUBLIC cxx_std_20)
 
-install(TARGETS export_interfaces_no_properties
+add_library(no_modules STATIC no_modules.cxx)
+
+install(TARGETS export_interfaces_no_properties no_modules
   EXPORT CXXModules
   FILE_SET modules DESTINATION "lib/cxx/miu")
 export(EXPORT CXXModules

+ 3 - 0
Tests/RunCMake/CXXModules/examples/export-interface-no-properties-build/no_modules.cxx

@@ -0,0 +1,3 @@
+void no_modules()
+{
+}

+ 3 - 1
Tests/RunCMake/CXXModules/examples/export-interface-no-properties-install/CMakeLists.txt

@@ -21,7 +21,9 @@ target_sources(export_interfaces_no_properties
         importable.cxx)
 target_compile_features(export_interfaces_no_properties PUBLIC cxx_std_20)
 
-install(TARGETS export_interfaces_no_properties
+add_library(no_modules STATIC no_modules.cxx)
+
+install(TARGETS export_interfaces_no_properties no_modules
   EXPORT CXXModules
   FILE_SET modules DESTINATION "lib/cxx/miu")
 install(EXPORT CXXModules

+ 3 - 0
Tests/RunCMake/CXXModules/examples/export-interface-no-properties-install/no_modules.cxx

@@ -0,0 +1,3 @@
+void no_modules()
+{
+}