Merge topic 'execute_process-encoding'

20f059d025 execute_process: Warn on unknown ENCODING value

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !9825
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index 7b62c4b..87831d1 100644
--- a/Source/CMakeVersion.cmake
+++ b/Source/CMakeVersion.cmake
@@ -1,7 +1,7 @@
 # CMake version number components.
 set(CMake_VERSION_MAJOR 3)
 set(CMake_VERSION_MINOR 30)
-set(CMake_VERSION_PATCH 20240917)
+set(CMake_VERSION_PATCH 20240918)
 #set(CMake_VERSION_RC 0)
 set(CMake_VERSION_IS_DIRTY 0)
 
diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx
index 0583aba..f12bcdb 100644
--- a/Source/cmComputeLinkDepends.cxx
+++ b/Source/cmComputeLinkDepends.cxx
@@ -33,6 +33,7 @@
 #include "cmState.h"
 #include "cmStateTypes.h"
 #include "cmStringAlgorithms.h"
+#include "cmSystemTools.h"
 #include "cmTarget.h"
 #include "cmValue.h"
 #include "cmake.h"
@@ -540,7 +541,22 @@
   {
     for (auto index : libEntries) {
       LinkEntry const& entry = this->Entries[index];
-      if (this->IncludeEntry(entry) || this->Emitted.insert(index).second) {
+      if (this->IncludeEntry(entry)) {
+        this->FinalEntries.emplace_back(entry);
+        continue;
+      }
+      if (entry.Target && entry.Target->IsImported()) {
+        // Different imported targets can point to the same library so check
+        // also library paths
+        if (this->Emitted.insert(index).second &&
+            this->ImportedEmitted
+              .insert(cmSystemTools::GetRealPath(entry.Item.Value))
+              .second) {
+          this->FinalEntries.emplace_back(entry);
+        }
+        continue;
+      }
+      if (this->Emitted.insert(index).second) {
         this->FinalEntries.emplace_back(entry);
       }
     }
@@ -553,6 +569,7 @@
   EntryVector& Entries;
   EntryVector& FinalEntries;
   std::set<size_t> Emitted;
+  std::set<std::string> ImportedEmitted;
   const std::map<size_t, std::vector<size_t>>* Groups = nullptr;
 };
 }
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx
index 37f4d69..1fd406c 100644
--- a/Source/cmQtAutoGenInitializer.cxx
+++ b/Source/cmQtAutoGenInitializer.cxx
@@ -1613,13 +1613,17 @@
   std::string const& infoFile, std::string const& processName,
   cmCustomCommandLines& commandLines)
 {
+  std::vector<std::string> autogenConfigs;
+  this->GlobalGen->GetQtAutoGenConfigs(autogenConfigs);
   if (this->CrossConfig && this->UseBetterGraph) {
     commandLines.push_back(cmMakeCommandLine(
       { cmSystemTools::GetCMakeCommand(), "-E", processName, infoFile,
         "$<CONFIG>", "$<COMMAND_CONFIG:$<CONFIG>>" }));
   } else if ((this->MultiConfig && this->GlobalGen->IsXcode()) ||
              this->CrossConfig) {
-    for (std::string const& config : this->ConfigsList) {
+    const auto& configs =
+      processName == "cmake_autorcc" ? this->ConfigsList : autogenConfigs;
+    for (std::string const& config : configs) {
       commandLines.push_back(
         cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E",
                             processName, infoFile, config }));
@@ -1629,9 +1633,7 @@
     if (this->MultiConfig) {
       autoInfoFileConfig = "$<CONFIG>";
     } else {
-      std::vector<std::string> configs;
-      this->GlobalGen->GetQtAutoGenConfigs(configs);
-      autoInfoFileConfig = configs[0];
+      autoInfoFileConfig = autogenConfigs[0];
     }
     commandLines.push_back(
       cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E", processName,
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 79df9a4..883d787 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -5933,7 +5933,8 @@
 {
   std::vector<std::string> packageReferences;
 
-  if (this->GeneratorTarget->HasPackageReferences()) {
+  if (this->GeneratorTarget->IsDotNetSdkTarget() ||
+      this->GeneratorTarget->HasPackageReferences()) {
     // Store a cache entry that later determines, if a package restore is
     // required.
     this->GeneratorTarget->Makefile->AddCacheDefinition(
@@ -5950,7 +5951,7 @@
     OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET);
 
     for (cmGeneratorTarget const* dt : depends) {
-      if (dt->HasPackageReferences()) {
+      if (dt->IsDotNetSdkTarget() || dt->HasPackageReferences()) {
         this->GeneratorTarget->Makefile->AddCacheDefinition(
           cmStrCat(this->GeneratorTarget->GetName(),
                    "_REQUIRES_VS_PACKAGE_RESTORE"),
diff --git a/Tests/RunCMake/Autogen_common/utils.cmake b/Tests/RunCMake/Autogen_common/utils.cmake
index 1208807..0692ca5 100644
--- a/Tests/RunCMake/Autogen_common/utils.cmake
+++ b/Tests/RunCMake/Autogen_common/utils.cmake
@@ -232,24 +232,33 @@
       set(RunCMake_MAKE_PROGRAM ${CMAKE_COMMAND})
       run_make_program(${RunCMake_TEST_BINARY_DIR}  --build . --config Debug)
       if (exe STREQUAL "Moc")
-        set(expected_count 16)
-      elseif (exe STREQUAL "Uic")
         set(expected_count 4)
+      elseif (exe STREQUAL "Uic")
+        set(expected_count 1)
       else()
         set(expected_count 12)
       endif()
       expect_n_times("${make_program_stdout}" "Auto${exe}:" ${expected_count} "${exe}Example-build-Auto${exe}")
-      expect_n_times("${make_program_stdout}" "Auto${exe}:" ${expected_count} "${exe}Example-build-Auto${exe}")
 
       if (exe STREQUAL "Moc" OR exe STREQUAL "Uic")
-        expect_n_times("${make_program_stdout}" "AutoGen:" 20 "${exe}Example-build-AutoGen:")
+        expect_n_times("${make_program_stdout}" "AutoGen:" 5 "${exe}Example-build-AutoGen:")
       endif()
 
-      foreach(config IN ITEMS Debug Release RelWithDebInfo)
+
+      foreach(config IN ITEMS Release RelWithDebInfo)
         block()
+          # Note: We expect to see Auto${exe} or AutoGen in the output for
+          # moc and uic because they should be triggered per configuration.
+          # For rcc, we don't expect to see Auto${exe} or AutoGen in the output
+          # because all configurations trigger with the first configuration.
           run_make_program(${RunCMake_TEST_BINARY_DIR} --build . --config ${config})
-          not_expect("${make_program_stdout}" "Auto${exe}" "${exe}Example-${config}_Auto${exe}")
-          not_expect("${make_program_stdout}" "AutoGen:" "${exe}Example-${config}_AutoGen")
+          if (exe STREQUAL "Moc" OR exe STREQUAL "Uic")
+            expect_n_times("${make_program_stdout}" "Auto${exe}:" ${expected_count} "${exe}Example-build-${config}-Auto${exe}")
+            expect_n_times("${make_program_stdout}" "AutoGen" 5 "${exe}Example-build-${config}-AutoGen:")
+          else()
+            not_expect("${make_program_stdout}" "Auto${exe}" "${exe}Example-build-${config}_Auto${exe}")
+            not_expect("${make_program_stdout}" "AutoGen" "${exe}Example-build-${config}_AutoGen")
+          endif()
         endblock()
       endforeach()
     endblock()
diff --git a/Tests/RunCMake/CMP0156/CMP0156-Common-Imported.cmake b/Tests/RunCMake/CMP0156/CMP0156-Common-Imported.cmake
new file mode 100644
index 0000000..0c0e34f
--- /dev/null
+++ b/Tests/RunCMake/CMP0156/CMP0156-Common-Imported.cmake
@@ -0,0 +1,21 @@
+
+enable_language(C)
+
+add_library(lib1 STATIC lib1.c)
+set_property(TARGET lib1 PROPERTY ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIG>")
+
+# This function simulates a find_package call for the third-party lib
+# by making an imported target with non-global scope.
+function(find_package_lib1)
+  add_library(lib1::lib1 STATIC IMPORTED)
+
+  set_target_properties(lib1::lib1 PROPERTIES
+    IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/Release/${CMAKE_STATIC_LIBRARY_PREFIX}lib1${CMAKE_STATIC_LIBRARY_SUFFIX}"
+  )
+
+  add_dependencies(lib1::lib1 lib1)
+endfunction()
+
+# ------------------------------------------------------------------------------
+add_subdirectory(subdir1)
+add_subdirectory(subdir2)
diff --git a/Tests/RunCMake/CMP0156/CMP0156-NEW-AppleClang-Imported.cmake b/Tests/RunCMake/CMP0156/CMP0156-NEW-AppleClang-Imported.cmake
new file mode 100644
index 0000000..bdfc7b8
--- /dev/null
+++ b/Tests/RunCMake/CMP0156/CMP0156-NEW-AppleClang-Imported.cmake
@@ -0,0 +1,5 @@
+
+cmake_policy(SET CMP0156 NEW)
+set(APPLE_TEST TRUE)
+
+include (CMP0156-Common-Imported.cmake)
diff --git a/Tests/RunCMake/CMP0156/CMP0156-NEW-Imported.cmake b/Tests/RunCMake/CMP0156/CMP0156-NEW-Imported.cmake
new file mode 100644
index 0000000..92101d0
--- /dev/null
+++ b/Tests/RunCMake/CMP0156/CMP0156-NEW-Imported.cmake
@@ -0,0 +1,4 @@
+
+cmake_policy(SET CMP0156 NEW)
+
+include (CMP0156-Common-Imported.cmake)
diff --git a/Tests/RunCMake/CMP0156/RunCMakeTest.cmake b/Tests/RunCMake/CMP0156/RunCMakeTest.cmake
index bd51830..052547c 100644
--- a/Tests/RunCMake/CMP0156/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CMP0156/RunCMakeTest.cmake
@@ -3,10 +3,14 @@
 # CMP0156 control how libraries are specified for the link step
 # a sensible configuration is how circular dependency is handled
 
+if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
+  set(OPTIONS -DCMAKE_BUILD_TYPE=Release)
+endif()
+
 macro(run_cmake_and_build test)
   set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
   set(RunCMake_TEST_OUTPUT_MERGE TRUE)
-  run_cmake(${test})
+  run_cmake_with_options(${test} ${OPTIONS})
   set(RunCMake_TEST_NO_CLEAN TRUE)
   run_cmake_command(${test}-build ${CMAKE_COMMAND} --build . --config Release)
   unset(RunCMake_TEST_NO_CLEAN)
@@ -24,3 +28,12 @@
   run_cmake_and_build(CMP0156-OLD-AppleClang)
   run_cmake_and_build(CMP0156-NEW-AppleClang)
 endif()
+
+
+run_cmake_and_build(CMP0156-NEW-Imported)
+
+if (CMAKE_C_COMPILER_ID STREQUAL "AppleClang"
+    AND CMAKE_C_COMPILER_VERSION GREATER_EQUAL "15.0")
+  # special case for Apple: with CMP0156=OLD, linker will warning on duplicate libraries
+  run_cmake_and_build(CMP0156-NEW-AppleClang-Imported)
+endif()
diff --git a/Tests/RunCMake/CMP0156/subdir1/CMakeLists.txt b/Tests/RunCMake/CMP0156/subdir1/CMakeLists.txt
new file mode 100644
index 0000000..0e88cd5
--- /dev/null
+++ b/Tests/RunCMake/CMP0156/subdir1/CMakeLists.txt
@@ -0,0 +1,5 @@
+
+find_package_lib1()
+
+add_library(lib2 STATIC ../lib2.c)
+target_link_libraries(lib2 PUBLIC lib1::lib1)
diff --git a/Tests/RunCMake/CMP0156/subdir2/CMakeLists.txt b/Tests/RunCMake/CMP0156/subdir2/CMakeLists.txt
new file mode 100644
index 0000000..724483c
--- /dev/null
+++ b/Tests/RunCMake/CMP0156/subdir2/CMakeLists.txt
@@ -0,0 +1,14 @@
+
+find_package_lib1()
+
+# -----------------------------------
+# This target depends on the third-party lib1 both
+# directly and transitively.
+add_executable(main ../main.c)
+target_link_libraries(main PRIVATE lib1::lib1 lib2)
+
+if (APPLE_TEST)
+  target_link_options(main PRIVATE "LINKER:-fatal_warnings")
+else()
+  target_link_options(main PRIVATE "$<$<AND:$<NOT:$<TARGET_POLICY:CMP0156>>,$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,15.0>>:LINKER:-no_warn_duplicate_libraries>")
+endif()
diff --git a/Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake b/Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake
index 0b2525c..68a6d5c 100644
--- a/Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake
+++ b/Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake
@@ -25,9 +25,8 @@
   file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
   file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
   run_cmake(${CASE})
-  set(build_flags /restore)
-  run_cmake_command(${CASE}-build ${CMAKE_COMMAND} --build . -- ${build_flags})
   run_cmake_command(${CASE}-build ${CMAKE_COMMAND} --build .)
 endfunction()
 
 runCmakeAndBuild(VsDotnetSdkCustomCommandsTarget)
+runCmakeAndBuild(VsDotnetSdkNugetRestore)
diff --git a/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkNugetRestore-build-stdout.txt b/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkNugetRestore-build-stdout.txt
new file mode 100644
index 0000000..b0c8da7
--- /dev/null
+++ b/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkNugetRestore-build-stdout.txt
@@ -0,0 +1 @@
+Determining projects to restore
diff --git a/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkNugetRestore.cmake b/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkNugetRestore.cmake
new file mode 100644
index 0000000..5feb265
--- /dev/null
+++ b/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkNugetRestore.cmake
@@ -0,0 +1,8 @@
+enable_language(CSharp)
+if(NOT CMAKE_CSharp_COMPILER)
+    return()
+endif()
+
+set(CMAKE_DOTNET_SDK "Microsoft.NET.Sdk")
+
+add_executable(foo csharponly.cs lib1.cs)