Merge topic 'fileapi-windows-implib-missing-error' into release-4.2

c6a940761c fileapi: Handle unused imported libraries with missing IMPORTED_IMPLIB

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !11585
diff --git a/Help/cpack_gen/appimage.rst b/Help/cpack_gen/appimage.rst
index 03d02b8..42dec8e 100644
--- a/Help/cpack_gen/appimage.rst
+++ b/Help/cpack_gen/appimage.rst
@@ -40,6 +40,13 @@
       endforeach()
   ]])
 
+The CPack AppImage generator will generate a default `AppRun`_ based on the
+provided ``.desktop`` entry.  Alternatively, if a custom ``AppRun`` is
+installed, e.g., via the :command:`install` command, it will be used instead
+of the generated one.
+
+.. _`AppRun`: https://docs.appimage.org/introduction/software-overview.html#apprun
+
 For Qt-based projects, it is recommended to call
 ``qt_generate_deploy_app_script()`` or ``qt_generate_deploy_qml_app_script()``
 and install the files generated by the script.  This will install the
diff --git a/Source/CPack/cmCPackAppImageGenerator.cxx b/Source/CPack/cmCPackAppImageGenerator.cxx
index 373dcfa..c6d4d8a 100644
--- a/Source/CPack/cmCPackAppImageGenerator.cxx
+++ b/Source/CPack/cmCPackAppImageGenerator.cxx
@@ -18,6 +18,7 @@
 #include "cmCPackLog.h"
 #include "cmELF.h"
 #include "cmGeneratedFileStream.h"
+#include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
 #include "cmValue.h"
 
@@ -182,8 +183,18 @@
   }
 
   std::string const appRunFile = this->toplevel + "/AppRun";
-  {
-    // AppRun script will run our application
+  if (cmSystemTools::PathExists(appRunFile)) {
+    // User provided an AppRun file
+    cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+                  cmStrCat("Found AppRun file: \"", appRunFile, '"')
+                    << std::endl);
+  } else {
+    // Generate a default AppRun script that will run our application
+    cmCPackLogger(
+      cmCPackLog::LOG_OUTPUT,
+      cmStrCat("No AppRun found, generating a default one that will run: \"",
+               application, '"')
+        << std::endl);
     cmGeneratedFileStream appRun(appRunFile);
     appRun << R"sh(#! /usr/bin/env bash
 
diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx
index 39086f7..84f036d 100644
--- a/Source/cmGlobalVisualStudioGenerator.cxx
+++ b/Source/cmGlobalVisualStudioGenerator.cxx
@@ -972,7 +972,8 @@
       if (!projectType.IsEmpty()) {
         project->TypeId = *projectType;
       } else {
-        project->TypeId = this->ExternalProjectTypeId(project->Path);
+        project->TypeId =
+          std::string{ this->ExternalProjectTypeId(project->Path) };
       }
       for (std::string const& config : solution.Configs) {
         cmList mapConfig{ gt->GetProperty(cmStrCat(
@@ -1005,13 +1006,13 @@
       cm::string_view vcprojExt;
       if (this->TargetIsFortranOnly(gt)) {
         vcprojExt = ".vfproj"_s;
-        project->TypeId = Solution::Project::TypeIdFortran;
+        project->TypeId = std::string{ Solution::Project::TypeIdFortran };
       } else if (gt->IsCSharpOnly()) {
         vcprojExt = ".csproj"_s;
-        project->TypeId = Solution::Project::TypeIdCSharp;
+        project->TypeId = std::string{ Solution::Project::TypeIdCSharp };
       } else {
         vcprojExt = ".vcproj"_s;
-        project->TypeId = Solution::Project::TypeIdDefault;
+        project->TypeId = std::string{ Solution::Project::TypeIdDefault };
       }
       if (cmValue genExt = gt->GetProperty("GENERATOR_FILE_NAME_EXT")) {
         vcprojExt = *genExt;
@@ -1064,7 +1065,7 @@
     cmSourceGroup* sg = mf->FindSourceGroup(item, sourceGroups);
     std::string folderName = sg->GetFullName();
     if (folderName.empty()) {
-      folderName = "Solution Items"_s;
+      folderName = "Solution Items";
     }
     Solution::Folder* folder =
       this->CreateSolutionFolder(solution, folderName);
diff --git a/Source/cmVSSolution.cxx b/Source/cmVSSolution.cxx
index 2ec3f02..cc75b8a 100644
--- a/Source/cmVSSolution.cxx
+++ b/Source/cmVSSolution.cxx
@@ -64,7 +64,7 @@
   auto i = entryMap.find(name);
   if (i == entryMap.end()) {
     auto p = cm::make_unique<T>();
-    p->Name = name;
+    p->Name = std::string{ name };
     i = entryMap.emplace(p->Name, std::move(p)).first;
   }
   return i->second.get();
diff --git a/Tests/RunCMake/CPack_AppImage/AppImageTestApp-cpack-AppImage-stdout.txt b/Tests/RunCMake/CPack_AppImage/AppImageTestApp-cpack-AppImage-stdout.txt
index 67d5a51..c8ec5f5 100644
--- a/Tests/RunCMake/CPack_AppImage/AppImageTestApp-cpack-AppImage-stdout.txt
+++ b/Tests/RunCMake/CPack_AppImage/AppImageTestApp-cpack-AppImage-stdout.txt
@@ -7,6 +7,7 @@
 CPack: Desktop file destination: "[^"]*/_CPack_Packages/Linux/AppImage/GeneratorTest-1\.2\.3-Linux/com\.example\.app\.desktop"
 CPack: Icon file: "[^"]*/_CPack_Packages/Linux/AppImage/GeneratorTest-1\.2\.3-Linux/share/icons/hicolor/64x64/apps/ApplicationIcon\.png"
 CPack: Icon link destination: "[^"]*/_CPack_Packages/Linux/AppImage/GeneratorTest-1\.2\.3-Linux/ApplicationIcon\.png"
+CPack: No AppRun found, generating a default one that will run: "bin/app"
 CPack: Running AppImageTool: "[^"]*" "[^"]*/_CPack_Packages/Linux/AppImage/GeneratorTest-1\.2\.3-Linux" "\.\./GeneratorTest-1\.2\.3-Linux\.AppImage" "--runtime-file" "[^"]*"
 [^
 ]*/_CPack_Packages/Linux/AppImage/GeneratorTest-1\.2\.3-Linux should be packaged as \.\./GeneratorTest-1\.2\.3-Linux\.AppImage