Merge topic 'CMP0126-WARNING' into release-3.21

16208ac113 CMP0126: Add control for warnings

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Ben Boeckel <ben.boeckel@kitware.com>
Merge-request: !6282
diff --git a/Help/cpack_gen/rpm.rst b/Help/cpack_gen/rpm.rst
index 5260a1d..322ab68 100644
--- a/Help/cpack_gen/rpm.rst
+++ b/Help/cpack_gen/rpm.rst
@@ -394,8 +394,10 @@
  * Mandatory : NO
  * Default   : -
 
- May be used to set weak RPM dependencies (suggests). Note that you must
- enclose the complete requires string between quotes.
+ May be used to set weak RPM dependencies (suggests). If ``rpmbuild`` doesn't
+ support the ``Suggests`` tag, CPack will emit a warning and ignore this
+ variable. Note that you must enclose the complete requires string between
+ quotes.
 
 .. variable:: CPACK_RPM_PACKAGE_PROVIDES
               CPACK_RPM_<component>_PACKAGE_PROVIDES
diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake
index cd07ba9..ca497f1 100644
--- a/Modules/CMakeDetermineCCompiler.cmake
+++ b/Modules/CMakeDetermineCCompiler.cmake
@@ -85,6 +85,10 @@
 
     # ARMClang need target options
     "--target=arm-arm-none-eabi -mcpu=cortex-m3"
+
+    # MSVC needs at least one include directory for __has_include to function,
+    # but custom toolchains may run MSVC with no INCLUDE env var and no -I flags.
+    "-I__does_not_exist__"
     )
 endif()
 if(CMAKE_C_COMPILER_TARGET)
diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake
index 3d1a7bb..e297f90 100644
--- a/Modules/CMakeDetermineCXXCompiler.cmake
+++ b/Modules/CMakeDetermineCXXCompiler.cmake
@@ -80,6 +80,10 @@
 
     # ARMClang need target options
     "--target=arm-arm-none-eabi -mcpu=cortex-m3"
+
+    # MSVC needs at least one include directory for __has_include to function,
+    # but custom toolchains may run MSVC with no INCLUDE env var and no -I flags.
+    "-I__does_not_exist__"
     )
 endif()
 
diff --git a/Modules/Compiler/Clang.cmake b/Modules/Compiler/Clang.cmake
index 7035d93..f885eb0 100644
--- a/Modules/Compiler/Clang.cmake
+++ b/Modules/Compiler/Clang.cmake
@@ -56,6 +56,7 @@
     set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
 
     string(COMPARE EQUAL "${CMAKE_${lang}_COMPILER_ID}" "AppleClang" __is_apple_clang)
+    string(COMPARE EQUAL "${CMAKE_${lang}_COMPILER_ID}" "FujitsuClang" __is_fujitsu_clang)
 
     # '-flto=thin' available since Clang 3.9 and Xcode 8
     # * http://clang.llvm.org/docs/ThinLTO.html#clang-llvm
@@ -65,6 +66,8 @@
       if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 8.0)
         set(_CMAKE_LTO_THIN FALSE)
       endif()
+    elseif(__is_fujitsu_clang)
+      set(_CMAKE_LTO_THIN FALSE)
     else()
       if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.9)
         set(_CMAKE_LTO_THIN FALSE)
diff --git a/Modules/Compiler/FujitsuClang-FindBinUtils.cmake b/Modules/Compiler/FujitsuClang-FindBinUtils.cmake
new file mode 100644
index 0000000..4a6401d
--- /dev/null
+++ b/Modules/Compiler/FujitsuClang-FindBinUtils.cmake
@@ -0,0 +1,6 @@
+if(NOT DEFINED _CMAKE_PROCESSING_LANGUAGE OR _CMAKE_PROCESSING_LANGUAGE STREQUAL "")
+  message(FATAL_ERROR "Internal error: _CMAKE_PROCESSING_LANGUAGE is not set")
+endif()
+
+set(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR ar)
+set(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_RANLIB ranlib)
diff --git a/Modules/Internal/CPack/CPackRPM.cmake b/Modules/Internal/CPack/CPackRPM.cmake
index bece2dd..47d2a5c 100644
--- a/Modules/Internal/CPack/CPackRPM.cmake
+++ b/Modules/Internal/CPack/CPackRPM.cmake
@@ -1074,6 +1074,21 @@
     OUTPUT_STRIP_TRAILING_WHITESPACE)
   string(REPLACE "\n" ";" RPMBUILD_TAG_LIST "${RPMBUILD_TAG_LIST}")
 
+  # In some versions of RPM, weak dependency tags are present in the --querytags
+  # list, but unsupported by rpmbuild. A different method must be used to check
+  # if they are supported.
+
+  execute_process(
+    COMMAND ${RPM_EXECUTABLE} --suggests
+    ERROR_QUIET
+    RESULT_VARIABLE RPMBUILD_SUGGESTS_RESULT)
+
+  if(NOT RPMBUILD_SUGGESTS_RESULT EQUAL 0)
+    foreach(_WEAK_DEP SUGGESTS RECOMMENDS SUPPLEMENTS ENHANCES)
+      list(REMOVE_ITEM RPMBUILD_TAG_LIST ${_WEAK_DEP})
+    endforeach()
+  endif()
+
   if(CPACK_RPM_PACKAGE_EPOCH)
     set(TMP_RPM_EPOCH "Epoch: ${CPACK_RPM_PACKAGE_EPOCH}")
   endif()
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index f268c6c..f1ef130 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -6346,11 +6346,11 @@
 }
 
 cm::optional<cmLinkItem> cmGeneratorTarget::LookupLinkItem(
-  std::string const& n, cmListFileBacktrace const& bt) const
+  std::string const& n, cmListFileBacktrace const& bt,
+  LookupLinkItemScope* scope) const
 {
   cm::optional<cmLinkItem> maybeItem;
-  cmLocalGenerator const* lg = this->LocalGenerator;
-  if (this->IsLinkLookupScope(n, lg)) {
+  if (this->IsLinkLookupScope(n, scope->LG)) {
     return maybeItem;
   }
 
@@ -6358,7 +6358,7 @@
   if (name == this->GetName() || name.empty()) {
     return maybeItem;
   }
-  maybeItem = this->ResolveLinkItem(name, bt, lg);
+  maybeItem = this->ResolveLinkItem(name, bt, scope->LG);
   return maybeItem;
 }
 
@@ -6385,9 +6385,10 @@
                              &dagChecker, this, headTarget->LinkerLanguage),
                libs);
   cmMakefile const* mf = this->LocalGenerator->GetMakefile();
+  LookupLinkItemScope scope{ this->LocalGenerator };
   for (std::string const& lib : libs) {
     if (cm::optional<cmLinkItem> maybeItem =
-          this->LookupLinkItem(lib, cge->GetBacktrace())) {
+          this->LookupLinkItem(lib, cge->GetBacktrace(), &scope)) {
       if (!maybeItem->Target) {
         // Report explicitly linked object files separately.
         std::string const& maybeObj = maybeItem->AsStr();
@@ -7089,9 +7090,10 @@
                           iface.HadContextSensitiveCondition,
                           iface.HadLinkLanguageSensitiveCondition);
     std::vector<std::string> deps = cmExpandedList(info->SharedDeps);
+    LookupLinkItemScope scope{ this->LocalGenerator };
     for (std::string const& dep : deps) {
       if (cm::optional<cmLinkItem> maybeItem =
-            this->LookupLinkItem(dep, cmListFileBacktrace())) {
+            this->LookupLinkItem(dep, cmListFileBacktrace(), &scope)) {
         iface.SharedDeps.emplace_back(std::move(*maybeItem));
       }
     }
diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h
index ed66fb1..6d2aa85 100644
--- a/Source/cmGeneratorTarget.h
+++ b/Source/cmGeneratorTarget.h
@@ -1042,8 +1042,13 @@
                        bool& hadHeadSensitiveCondition,
                        bool& hadContextSensitiveCondition,
                        bool& hadLinkLanguageSensitiveCondition) const;
+  struct LookupLinkItemScope
+  {
+    cmLocalGenerator const* LG;
+  };
   cm::optional<cmLinkItem> LookupLinkItem(std::string const& n,
-                                          cmListFileBacktrace const& bt) const;
+                                          cmListFileBacktrace const& bt,
+                                          LookupLinkItemScope* scope) const;
 
   std::vector<BT<std::string>> GetSourceFilePaths(
     std::string const& config) const;
diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx
index aafc9d5..4fab0b9 100644
--- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx
+++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx
@@ -211,7 +211,6 @@
     platforms.emplace_back("Win32");
     platforms.emplace_back("ARM");
     platforms.emplace_back("ARM64");
-    platforms.emplace_back("ARM64EC");
     return platforms;
   }
 
@@ -305,6 +304,7 @@
     platforms.emplace_back("Win32");
     platforms.emplace_back("ARM");
     platforms.emplace_back("ARM64");
+    platforms.emplace_back("ARM64EC");
     return platforms;
   }
 
@@ -369,6 +369,7 @@
     platforms.emplace_back("Win32");
     platforms.emplace_back("ARM");
     platforms.emplace_back("ARM64");
+    platforms.emplace_back("ARM64EC");
     return platforms;
   }
 
diff --git a/Source/kwsys/EncodingC.c b/Source/kwsys/EncodingC.c
index e12236a..13127f1 100644
--- a/Source/kwsys/EncodingC.c
+++ b/Source/kwsys/EncodingC.c
@@ -60,7 +60,7 @@
 char* kwsysEncoding_DupToNarrow(const wchar_t* str)
 {
   char* ret = NULL;
-  size_t length = kwsysEncoding_wcstombs(0, str, 0) + 1;
+  size_t length = kwsysEncoding_wcstombs(NULL, str, 0) + 1;
   if (length > 0) {
     ret = (char*)malloc(length);
     if (ret) {
diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx
index 117ff8d..12f9139 100644
--- a/Source/kwsys/SystemInformation.cxx
+++ b/Source/kwsys/SystemInformation.cxx
@@ -1383,7 +1383,7 @@
   }
 #  else
 // second fallback use builtin backtrace_symbols
-// to decode the bactrace.
+// to decode the backtrace.
 #  endif
 }
 #endif // don't define this class if we're not using it
diff --git a/Source/kwsys/testDynamicLoader.cxx b/Source/kwsys/testDynamicLoader.cxx
index 703ad4d..9ba204e 100644
--- a/Source/kwsys/testDynamicLoader.cxx
+++ b/Source/kwsys/testDynamicLoader.cxx
@@ -8,6 +8,25 @@
 #  include <be/kernel/OS.h> /* disable_debugger() API. */
 #endif
 
+// Needed for __GLIBC__ test macro.
+#ifdef __linux__
+#  include <features.h>
+#endif
+
+// Will define LIBDL_SO macro on systems with glibc.
+#ifdef __GLIBC__
+#  include <gnu/lib-names.h>
+// Define to LIBC_SO, if not defined by above header.
+#  ifndef LIBDL_SO
+#    define LIBDL_SO LIBC_SO
+#  endif
+#endif
+
+// Define the LIBDL_SO macro, if not defined above.
+#ifndef LIBDL_SO
+#  define LIBDL_SO "libdl.so"
+#endif
+
 // Work-around CMake dependency scanning limitation.  This must
 // duplicate the above list of headers.
 #if 0
@@ -107,8 +126,8 @@
   // This one is actually fun to test, since dlopen is by default
   // loaded...wonder why :)
   res += TestDynamicLoader("foobar.lib", "dlopen", 0, 1, 0);
-  res += TestDynamicLoader("libdl.so", "dlopen", 1, 1, 1);
-  res += TestDynamicLoader("libdl.so", "TestDynamicLoader", 1, 0, 1);
+  res += TestDynamicLoader(LIBDL_SO, "dlopen", 1, 1, 1);
+  res += TestDynamicLoader(LIBDL_SO, "TestDynamicLoader", 1, 0, 1);
 #endif
   // Now try on the generated library
   std::string libname = GetLibName(KWSYS_NAMESPACE_STRING "TestDynload");
diff --git a/Templates/TestDriver.cxx.in b/Templates/TestDriver.cxx.in
index e3efa79..6113417 100644
--- a/Templates/TestDriver.cxx.in
+++ b/Templates/TestDriver.cxx.in
@@ -136,9 +136,11 @@
       t = clock();
       status = (*cmakeGeneratedFunctionMapEntries[i].func)(ac, av);
       t = clock() - t;
-      double time_taken = ((double)t) / CLOCKS_PER_SEC;
       status_message = (status == -1) ? "not ok" : "ok";
-      printf("%s %d %s # %f\n", status_message, i + 1, name, time_taken);
+      {
+        double time_taken = ((double)t) / CLOCKS_PER_SEC;
+        printf("%s %d %s # %f\n", status_message, i + 1, name, time_taken);
+      }
     }
     printf("All tests finished.\n");
 
diff --git a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
index aa8e21a..07ec4e3 100644
--- a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
+++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
@@ -140,6 +140,8 @@
 cmake_policy(SET CMP0022 NEW)
 cmake_policy(SET CMP0079 NEW)
 add_executable(TopDir TopDir.c)
+add_library(TopDirInterface INTERFACE)
+target_link_libraries(TopDir PRIVATE TopDirInterface)
 add_subdirectory(SubDirA)
 add_subdirectory(SubDirB)
 target_link_libraries(SubDirB TopDirImported)
diff --git a/Tests/CMakeCommands/target_link_libraries/SubDirA/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/SubDirA/CMakeLists.txt
index 4dae103..df7c483 100644
--- a/Tests/CMakeCommands/target_link_libraries/SubDirA/CMakeLists.txt
+++ b/Tests/CMakeCommands/target_link_libraries/SubDirA/CMakeLists.txt
@@ -3,6 +3,8 @@
 # Link to a target imported in this directory that would not normally
 # be visible to the directory in which TopDir is defined.
 target_link_libraries(TopDir PUBLIC SameNameImported)
+# Do the same through an interface library in the top.
+target_link_libraries(TopDirInterface INTERFACE SameNameImported2)
 
 # Link SubDirA to a target imported in this directory that has the same
 # name as a target imported in SubDirB's directory.  SubDirB will also
@@ -13,3 +15,5 @@
 # Distinguish this copy by having a unique usage requirement.
 add_library(SameNameImported IMPORTED INTERFACE)
 target_compile_definitions(SameNameImported INTERFACE DEF_SameNameImportedSubDirA)
+add_library(SameNameImported2 INTERFACE IMPORTED)
+target_compile_definitions(SameNameImported2 INTERFACE DEF_SameNameImported2SubDirA)
diff --git a/Tests/CMakeCommands/target_link_libraries/SubDirB/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/SubDirB/CMakeLists.txt
index 06d1111..9af577c 100644
--- a/Tests/CMakeCommands/target_link_libraries/SubDirB/CMakeLists.txt
+++ b/Tests/CMakeCommands/target_link_libraries/SubDirB/CMakeLists.txt
@@ -3,6 +3,8 @@
 # Link to a target imported in this directory that would not normally
 # be visible to the directory in which TopDir is defined.
 target_link_libraries(TopDir PUBLIC debug SameNameImported optimized SameNameImported)
+# Do the same through an interface library in the top.
+target_link_libraries(TopDirInterface INTERFACE debug SameNameImported2 optimized SameNameImported2)
 
 # Link to a list of targets imported in this directory that would not
 # normally be visible to the directory in which TopDir is defined.
@@ -17,3 +19,5 @@
 # Distinguish this copy by having a unique usage requirement.
 add_library(SameNameImported IMPORTED INTERFACE)
 target_compile_definitions(SameNameImported INTERFACE DEF_SameNameImportedSubDirB)
+add_library(SameNameImported2 INTERFACE IMPORTED)
+target_compile_definitions(SameNameImported2 INTERFACE DEF_SameNameImported2SubDirB)
diff --git a/Tests/CMakeCommands/target_link_libraries/TopDir.c b/Tests/CMakeCommands/target_link_libraries/TopDir.c
index d8066e5..708b5c1 100644
--- a/Tests/CMakeCommands/target_link_libraries/TopDir.c
+++ b/Tests/CMakeCommands/target_link_libraries/TopDir.c
@@ -4,6 +4,12 @@
 #ifndef DEF_SameNameImportedSubDirB
 #  error "DEF_SameNameImportedSubDirB is not defined but should be!"
 #endif
+#ifndef DEF_SameNameImported2SubDirA
+#  error "DEF_SameNameImported2SubDirA is not defined but should be!"
+#endif
+#ifndef DEF_SameNameImported2SubDirB
+#  error "DEF_SameNameImported2SubDirB is not defined but should be!"
+#endif
 #ifdef DEF_TopDirImported
 #  error "DEF_TopDirImported is defined but should not be!"
 #endif
diff --git a/Tests/RunCMake/CPack/tests/SUGGESTS/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/SUGGESTS/VerifyResult.cmake
index 61ce752..d1d615b 100644
--- a/Tests/RunCMake/CPack/tests/SUGGESTS/VerifyResult.cmake
+++ b/Tests/RunCMake/CPack/tests/SUGGESTS/VerifyResult.cmake
@@ -1,15 +1,13 @@
-execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --querytags
-                OUTPUT_VARIABLE RPMBUILD_CAPS
-                RESULT_VARIABLE RPMBUILD_CAPS_RESULT)
+# CPack uses `rpm --suggests` to check if rpmbuild supports the "Suggests:" tag.
+# This test intentionally uses a different method (build a test .spec) so any
+# problems will be caught early if functionality should change in the future.
+execute_process(
+  COMMAND ${RPMBUILD_EXECUTABLE} --nobuild test_suggests.spec
+  ERROR_QUIET
+  RESULT_VARIABLE RPMBUILD_SUGGESTS_RESULT)
 
-if(NOT RPMBUILD_CAPS_RESULT)
-  string(REPLACE "\n" ";" RPMBUILD_CAPS "${RPMBUILD_CAPS}")
-  cmake_policy(PUSH)
-    cmake_policy(SET CMP0057 NEW)
-    if(SUGGESTS IN_LIST RPMBUILD_CAPS)
-      set(should_contain_suggests_tag_ true)
-    endif()
-  cmake_policy(POP)
+if(RPMBUILD_SUGGESTS_RESULT EQUAL 0)
+  set(should_contain_suggests_tag_ true)
 endif()
 
 # Only verify that suggests tag is present only if that tag is supported.
diff --git a/Tests/RunCMake/CPack/tests/SUGGESTS/test_suggests.spec b/Tests/RunCMake/CPack/tests/SUGGESTS/test_suggests.spec
new file mode 100644
index 0000000..e766fa9
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/SUGGESTS/test_suggests.spec
@@ -0,0 +1,22 @@
+# This spec file is used to check if the provided version of rpmbuild supports the "Suggests:" tag
+
+Name:           test
+Version:        0
+Release:        1
+Summary:        test
+License:        test
+
+Suggests: suggested_package
+
+%description
+
+
+%prep
+
+%build
+%configure
+%install
+%clean
+%files
+%doc
+%changelog
diff --git a/Tests/RunCMake/Ninja/RunCMakeTest.cmake b/Tests/RunCMake/Ninja/RunCMakeTest.cmake
index 8c91b34..3f239b9 100644
--- a/Tests/RunCMake/Ninja/RunCMakeTest.cmake
+++ b/Tests/RunCMake/Ninja/RunCMakeTest.cmake
@@ -18,6 +18,9 @@
   message(FATAL_ERROR "'ninja --version' reported:\n${ninja_out}")
 endif()
 
+# Sanitize NINJA_STATUS since we expect default behavior.
+unset(ENV{NINJA_STATUS})
+
 if(CMAKE_HOST_WIN32)
   run_cmake(SelectCompilerWindows)
 else()
diff --git a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake
index e7acbc2..559c8f7 100644
--- a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake
+++ b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake
@@ -5,6 +5,9 @@
 set(RunCMake_GENERATOR "Ninja Multi-Config")
 set(RunCMake_GENERATOR_IS_MULTI_CONFIG 1)
 
+# Sanitize NINJA_STATUS since we expect default behavior.
+unset(ENV{NINJA_STATUS})
+
 function(check_files dir)
   cmake_parse_arguments(_check_files "" "" "INCLUDE;EXCLUDE" ${ARGN})
 
diff --git a/Utilities/cmcurl/lib/vtls/schannel.c b/Utilities/cmcurl/lib/vtls/schannel.c
index 2bcf11d..3286a9e 100644
--- a/Utilities/cmcurl/lib/vtls/schannel.c
+++ b/Utilities/cmcurl/lib/vtls/schannel.c
@@ -874,6 +874,7 @@
 
 #ifdef USE_HTTP2
     if(data->state.httpwant >= CURL_HTTP_VERSION_2) {
+      alpn_buffer[cur++] = ALPN_H2_LENGTH;
       memcpy(&alpn_buffer[cur], ALPN_H2, ALPN_H2_LENGTH);
       cur += ALPN_H2_LENGTH;
       infof(data, "schannel: ALPN, offering %s\n", ALPN_H2);