Merge topic 'findhdf5-fix-nohl' into release-3.18

e038107ee7 FindHDF5: fix compiler detection when HL is disabled

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5112
diff --git a/Help/prop_tgt/AUTOMOC_PATH_PREFIX.rst b/Help/prop_tgt/AUTOMOC_PATH_PREFIX.rst
index 3e3059d..5ed504f 100644
--- a/Help/prop_tgt/AUTOMOC_PATH_PREFIX.rst
+++ b/Help/prop_tgt/AUTOMOC_PATH_PREFIX.rst
@@ -13,7 +13,7 @@
 relative include path in that case.
 
 :prop_tgt:`AUTOMOC_PATH_PREFIX` is initialized from the variable
-:variable:`CMAKE_AUTOMOC_PATH_PREFIX`, which is ``ON`` by default.
+:variable:`CMAKE_AUTOMOC_PATH_PREFIX`, which is ``OFF`` by default.
 
 See the :manual:`cmake-qt(7)` manual for more information on using CMake
 with Qt.
@@ -24,8 +24,7 @@
 For reproducible builds it is recommended to keep headers that are ``moc``
 compiled in one of the target
 :command:`include directories <target_include_directories>` and set
-:prop_tgt:`AUTOMOC_PATH_PREFIX` to ``ON`` (which is the default).  This ensures
-that:
+:prop_tgt:`AUTOMOC_PATH_PREFIX` to ``ON``.  This ensures that:
 
 - ``moc`` output files are identical on different build setups,
 - ``moc`` output files will compile correctly when the source and/or
diff --git a/Help/release/3.18.rst b/Help/release/3.18.rst
index ba80d2b..93694f6 100644
--- a/Help/release/3.18.rst
+++ b/Help/release/3.18.rst
@@ -339,3 +339,11 @@
   that were using manual quoting or escaping to work around the prior
   limitation.  This fix has been reverted in 3.18.1, but may be
   re-introduced in future versions of CMake with a policy for compatibility.
+
+3.18.2
+------
+
+* The default value of :variable:`CMAKE_AUTOMOC_PATH_PREFIX` was changed to
+  ``OFF`` because this feature can break existing projects that have
+  identically named header files in different include directories.
+  This restores compatibility with behavior of CMake 3.15 and below.
diff --git a/Help/variable/CMAKE_AUTOMOC_PATH_PREFIX.rst b/Help/variable/CMAKE_AUTOMOC_PATH_PREFIX.rst
index dca0b06..1e9790f 100644
--- a/Help/variable/CMAKE_AUTOMOC_PATH_PREFIX.rst
+++ b/Help/variable/CMAKE_AUTOMOC_PATH_PREFIX.rst
@@ -8,4 +8,4 @@
 property on all the targets.  See that target property for additional
 information.
 
-The default value is ``ON``.
+The default value is ``OFF``.
diff --git a/Modules/CMakeGenericSystem.cmake b/Modules/CMakeGenericSystem.cmake
index 000fba1..6f665a6 100644
--- a/Modules/CMakeGenericSystem.cmake
+++ b/Modules/CMakeGenericSystem.cmake
@@ -26,7 +26,9 @@
 
 set(CMAKE_AUTOGEN_ORIGIN_DEPENDS ON)
 set(CMAKE_AUTOMOC_COMPILER_PREDEFINES ON)
-set(CMAKE_AUTOMOC_PATH_PREFIX ON)
+if(NOT DEFINED CMAKE_AUTOMOC_PATH_PREFIX)
+  set(CMAKE_AUTOMOC_PATH_PREFIX OFF)
+endif()
 set(CMAKE_AUTOMOC_MACRO_NAMES "Q_OBJECT" "Q_GADGET" "Q_NAMESPACE" "Q_NAMESPACE_EXPORT")
 
 # basically all general purpose OSs support shared libs
diff --git a/Modules/FindOpenGL.cmake b/Modules/FindOpenGL.cmake
index 74392da..17ffe85 100644
--- a/Modules/FindOpenGL.cmake
+++ b/Modules/FindOpenGL.cmake
@@ -424,8 +424,15 @@
 endif()
 
 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+if (CMAKE_FIND_PACKAGE_NAME STREQUAL "GLU")
+  # FindGLU include()'s this module. It's an old pattern, but rather than
+  # trying to suppress this from outside the module (which is then sensitive to
+  # the contents, detect the case in this module and suppress it explicitly.
+  set(FPHSA_NAME_MISMATCHED 1)
+endif ()
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS}
                                   HANDLE_COMPONENTS)
+unset(FPHSA_NAME_MISMATCHED)
 unset(_OpenGL_REQUIRED_VARS)
 
 # OpenGL:: targets
diff --git a/Modules/FindPerl.cmake b/Modules/FindPerl.cmake
index fd120bf..c14e059 100644
--- a/Modules/FindPerl.cmake
+++ b/Modules/FindPerl.cmake
@@ -73,8 +73,15 @@
 set(PERL ${PERL_EXECUTABLE})
 
 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+if (CMAKE_FIND_PACKAGE_NAME STREQUAL "PerlLibs")
+  # FindPerlLibs include()'s this module. It's an old pattern, but rather than
+  # trying to suppress this from outside the module (which is then sensitive to
+  # the contents, detect the case in this module and suppress it explicitly.
+  set(FPHSA_NAME_MISMATCHED 1)
+endif ()
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Perl
                                   REQUIRED_VARS PERL_EXECUTABLE
                                   VERSION_VAR PERL_VERSION_STRING)
+unset(FPHSA_NAME_MISMATCHED)
 
 mark_as_advanced(PERL_EXECUTABLE)
diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake
index 1be0625..9b65f39 100644
--- a/Modules/FindPython/Support.cmake
+++ b/Modules/FindPython/Support.cmake
@@ -5,17 +5,13 @@
 # This file is a "template" file used by various FindPython modules.
 #
 
-cmake_policy (GET CMP0094 _${_PYTHON_PREFIX}_LOOKUP_POLICY)
-
-cmake_policy (VERSION 3.7)
-
-if (_${_PYTHON_PREFIX}_LOOKUP_POLICY)
-  cmake_policy (SET CMP0094 ${_${_PYTHON_PREFIX}_LOOKUP_POLICY})
-endif()
-
 #
 # Initial configuration
 #
+
+# IN_LIST operator
+cmake_policy (SET CMP0057 NEW)
+
 if (NOT DEFINED _PYTHON_PREFIX)
   message (FATAL_ERROR "FindPython: INTERNAL ERROR")
 endif()
@@ -1097,6 +1093,7 @@
 unset (${_PYTHON_PREFIX}_SOABI)
 
 # Define lookup strategy
+cmake_policy (GET CMP0094 _${_PYTHON_PREFIX}_LOOKUP_POLICY)
 if (_${_PYTHON_PREFIX}_LOOKUP_POLICY STREQUAL "NEW")
   set (_${_PYTHON_PREFIX}_FIND_STRATEGY "LOCATION")
 else()
diff --git a/Modules/FindQt3.cmake b/Modules/FindQt3.cmake
index 563ed46..b5bc8b1 100644
--- a/Modules/FindQt3.cmake
+++ b/Modules/FindQt3.cmake
@@ -201,9 +201,16 @@
 
 # if the include a library are found then we have it
 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+if (CMAKE_FIND_PACKAGE_NAME STREQUAL "Qt")
+  # FindQt include()'s this module. It's an old pattern, but rather than trying
+  # to suppress this from outside the module (which is then sensitive to the
+  # contents, detect the case in this module and suppress it explicitly.
+  set(FPHSA_NAME_MISMATCHED 1)
+endif ()
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Qt3
                                   REQUIRED_VARS QT_QT_LIBRARY QT_INCLUDE_DIR QT_MOC_EXECUTABLE
                                   VERSION_VAR QT_VERSION_STRING)
+unset(FPHSA_NAME_MISMATCHED)
 set(QT_FOUND ${QT3_FOUND} )
 
 if(QT_FOUND)
diff --git a/Modules/FindQt4.cmake b/Modules/FindQt4.cmake
index 3993968..2e3da74 100644
--- a/Modules/FindQt4.cmake
+++ b/Modules/FindQt4.cmake
@@ -1318,10 +1318,18 @@
       endif()
     endif()
 else()
+  if (CMAKE_FIND_PACKAGE_NAME STREQUAL "Qt")
+    # FindQt include()'s this module. It's an old pattern, but rather than
+    # trying to suppress this from outside the module (which is then sensitive
+    # to the contents, detect the case in this module and suppress it
+    # explicitly.
+    set(FPHSA_NAME_MISMATCHED 1)
+  endif ()
   FIND_PACKAGE_HANDLE_STANDARD_ARGS(Qt4 FOUND_VAR Qt4_FOUND
     REQUIRED_VARS ${_QT4_FOUND_REQUIRED_VARS}
     VERSION_VAR QTVERSION
     )
+  unset(FPHSA_NAME_MISMATCHED)
 endif()
 
 #######################################
diff --git a/Modules/FindRuby.cmake b/Modules/FindRuby.cmake
index 1bdee60..3b8122e 100644
--- a/Modules/FindRuby.cmake
+++ b/Modules/FindRuby.cmake
@@ -50,7 +50,7 @@
 
 Also:
 
-``Ruby_INCLUDE_PATH``
+``RUBY_INCLUDE_PATH``
   same as Ruby_INCLUDE_DIRS, only provided for compatibility reasons, don't use it
 
 Hints
@@ -493,7 +493,6 @@
     Ruby_VERSION_MAJOR
     Ruby_VERSION_MINOR
     Ruby_VERSION_PATCH
-    Ruby_INCLUDE_PATH
 
     Ruby_ARCH_DIR
     Ruby_ARCH
diff --git a/Modules/FindTCL.cmake b/Modules/FindTCL.cmake
index 960265f..9b771dc 100644
--- a/Modules/FindTCL.cmake
+++ b/Modules/FindTCL.cmake
@@ -223,6 +223,12 @@
 
 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
 
+if (CMAKE_FIND_PACKAGE_NAME STREQUAL "TclStub")
+  # FindTclStub include()'s this module. It's an old pattern, but rather than
+  # trying to suppress this from outside the module (which is then sensitive to
+  # the contents, detect the case in this module and suppress it explicitly.
+  set(FPHSA_NAME_MISMATCHED 1)
+endif ()
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(TCL DEFAULT_MSG TCL_LIBRARY TCL_INCLUDE_PATH)
 set(FPHSA_NAME_MISMATCHED 1)
 set(TCLTK_FIND_REQUIRED ${TCL_FIND_REQUIRED})
diff --git a/Modules/FindTclsh.cmake b/Modules/FindTclsh.cmake
index 82be473..5555d59 100644
--- a/Modules/FindTclsh.cmake
+++ b/Modules/FindTclsh.cmake
@@ -92,8 +92,17 @@
 endif()
 
 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+if (CMAKE_FIND_PACKAGE_NAME STREQUAL "TCL" OR
+    CMAKE_FIND_PACKAGE_NAME STREQUAL "TclStub")
+  # FindTCL include()'s this module. It's an old pattern, but rather than
+  # trying to suppress this from outside the module (which is then sensitive to
+  # the contents, detect the case in this module and suppress it explicitly.
+  # Transitively, FindTclStub includes FindTCL.
+  set(FPHSA_NAME_MISMATCHED 1)
+endif ()
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Tclsh
                                   REQUIRED_VARS TCL_TCLSH
                                   VERSION_VAR TCLSH_VERSION_STRING)
+unset(FPHSA_NAME_MISMATCHED)
 
 mark_as_advanced(TCL_TCLSH)
diff --git a/Modules/FindX11.cmake b/Modules/FindX11.cmake
index aa83575..ccd0252 100644
--- a/Modules/FindX11.cmake
+++ b/Modules/FindX11.cmake
@@ -404,9 +404,17 @@
   endif ()
 
   include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+  if (CMAKE_FIND_PACKAGE_NAME STREQUAL "FLTK")
+    # FindFLTK include()'s this module. It's an old pattern, but rather than
+    # trying to suppress this from outside the module (which is then sensitive
+    # to the contents, detect the case in this module and suppress it
+    # explicitly.
+    set(FPHSA_NAME_MISMATCHED 1)
+  endif ()
   find_package_handle_standard_args(X11
     REQUIRED_VARS X11_X11_INCLUDE_PATH X11_X11_LIB
     HANDLE_COMPONENTS)
+  unset(FPHSA_NAME_MISMATCHED)
 
   if(X11_FOUND)
     include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
diff --git a/Modules/GoogleTestAddTests.cmake b/Modules/GoogleTestAddTests.cmake
index 5d098d9..883e1f4 100644
--- a/Modules/GoogleTestAddTests.cmake
+++ b/Modules/GoogleTestAddTests.cmake
@@ -44,8 +44,8 @@
   cmake_parse_arguments(
     ""
     ""
-    "NO_PRETTY_TYPES;NO_PRETTY_VALUES;TEST_EXECUTABLE;TEST_EXECUTOR;TEST_WORKING_DIR;TEST_PREFIX;TEST_SUFFIX;TEST_LIST;CTEST_FILE;TEST_DISCOVERY_TIMEOUT;TEST_XML_OUTPUT_DIR"
-    "TEST_EXTRA_ARGS;TEST_PROPERTIES"
+    "NO_PRETTY_TYPES;NO_PRETTY_VALUES;TEST_EXECUTABLE;TEST_WORKING_DIR;TEST_PREFIX;TEST_SUFFIX;TEST_LIST;CTEST_FILE;TEST_DISCOVERY_TIMEOUT;TEST_XML_OUTPUT_DIR"
+    "TEST_EXTRA_ARGS;TEST_PROPERTIES;TEST_EXECUTOR"
     ${ARGN}
   )
 
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index c7baf2b..ab6a26c 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -3032,6 +3032,9 @@
 void cmGeneratorTarget::GetAppleArchs(const std::string& config,
                                       std::vector<std::string>& archVec) const
 {
+  if (!this->Makefile->IsOn("APPLE")) {
+    return;
+  }
   cmProp archs = nullptr;
   if (!config.empty()) {
     std::string defVarName =
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index f0737e8..b28395a 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -3158,6 +3158,12 @@
   std::string symroot = cmStrCat(root->GetCurrentBinaryDirectory(), "/build");
   buildSettings->AddAttribute("SYMROOT", this->CreateString(symroot));
 
+  // Inside a try_compile project, do not require signing on any platform.
+  if (this->CMakeInstance->GetIsInTryCompile()) {
+    buildSettings->AddAttribute("CODE_SIGNING_ALLOWED",
+                                this->CreateString("NO"));
+  }
+
   for (auto& config : configs) {
     cmXCodeObject* buildSettingsForCfg = this->CreateFlatClone(buildSettings);
 
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index e26dc94..c15ca7c 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -2789,7 +2789,7 @@
     }
     file << "      break()\n"
          << "    endif()\n";
-    file << "  else()\n"
+    file << "  elseif(NOT EXISTS \"" << from_file << "\")\n"
          << "    execute_process(COMMAND ${CMAKE_COMMAND}"
          << " -E sleep 1)\n"
          << "  endif()\n";
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 0f01f85..32ab9f8 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -733,12 +733,8 @@
     static_cast<int>(cmSystemTools::CalculateCommandLineLengthLimit()) -
     globalGen->GetRuleCmdLength(this->LanguageLinkerDeviceRule(config));
 
-  std::string path = localGen.GetHomeRelativeOutputPath();
-  if (!path.empty()) {
-    path += '/';
-  }
   build.RspFile = this->ConvertToNinjaPath(
-    cmStrCat(path, "CMakeFiles/", genTarget->GetName(),
+    cmStrCat("CMakeFiles/", genTarget->GetName(),
              globalGen->IsMultiConfig() ? cmStrCat('.', config) : "", ".rsp"));
 
   // Gather order-only dependencies.
@@ -1159,12 +1155,8 @@
       globalGen->GetRuleCmdLength(linkBuild.Rule);
   }
 
-  std::string path = localGen.GetHomeRelativeOutputPath();
-  if (!path.empty()) {
-    path += '/';
-  }
   linkBuild.RspFile = this->ConvertToNinjaPath(
-    cmStrCat(path, "CMakeFiles/", gt->GetName(),
+    cmStrCat("CMakeFiles/", gt->GetName(),
              globalGen->IsMultiConfig() ? cmStrCat('.', config) : "", ".rsp"));
 
   // Gather order-only dependencies.
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx
index 511a018..1132852 100644
--- a/Source/cmQtAutoGenInitializer.cxx
+++ b/Source/cmQtAutoGenInitializer.cxx
@@ -1182,11 +1182,54 @@
     if (useNinjaDepfile) {
       // Create a custom command that generates a timestamp file and
       // has a depfile assigned. The depfile is created by JobDepFilesMergeT.
+      //
+      // Also create an additional '_autogen_timestamp_deps' that the custom
+      // command will depend on. It will have no sources or commands to
+      // execute, but it will have dependencies that would originally be
+      // assigned to the pre-Qt 5.15 'autogen' target. These dependencies will
+      // serve as a list of order-only dependencies for the custom command,
+      // without forcing the custom command to re-execute.
+      //
+      // The dependency tree would then look like
+      // '_autogen_timestamp_deps (order-only)' <- '/timestamp' file <-
+      // '_autogen' target.
+      const auto timestampTargetName =
+        cmStrCat(this->GenTarget->GetName(), "_autogen_timestamp_deps");
+      std::vector<std::string> timestampTargetProvides;
+      cmCustomCommandLines timestampTargetCommandLines;
 
-      // Add additional autogen target dependencies
+      // Add additional autogen target dependencies to
+      // '_autogen_timestamp_deps'.
       for (const cmTarget* t : this->AutogenTarget.DependTargets) {
         dependencies.push_back(t->GetName());
       }
+
+      cmTarget* timestampTarget = this->LocalGen->AddUtilityCommand(
+        timestampTargetName, true, this->Dir.Work.c_str(),
+        /*byproducts=*/timestampTargetProvides,
+        /*depends=*/dependencies, timestampTargetCommandLines, false, nullptr);
+      this->LocalGen->AddGeneratorTarget(
+        cm::make_unique<cmGeneratorTarget>(timestampTarget, this->LocalGen));
+
+      // Set FOLDER property on the timestamp target, so it appears in the
+      // appropriate folder in an IDE or in the file api.
+      if (!this->TargetsFolder.empty()) {
+        timestampTarget->SetProperty("FOLDER", this->TargetsFolder);
+      }
+
+      // Make '/timestamp' file depend on '_autogen_timestamp_deps' and on the
+      // moc and uic executables (whichever are enabled).
+      dependencies.clear();
+      dependencies.push_back(timestampTargetName);
+
+      if (this->Moc.ExecutableTarget != nullptr) {
+        dependencies.push_back(this->Moc.ExecutableTarget->Target->GetName());
+      }
+      if (this->Uic.ExecutableTarget != nullptr) {
+        dependencies.push_back(this->Uic.ExecutableTarget->Target->GetName());
+      }
+
+      // Create the custom command that outputs the timestamp file.
       const char timestampFileName[] = "timestamp";
       const std::string outputFile =
         cmStrCat(this->Dir.Build, "/", timestampFileName);
diff --git a/Source/cmQtAutoMocUic.cxx b/Source/cmQtAutoMocUic.cxx
index 9adcabb..f6cccfb 100644
--- a/Source/cmQtAutoMocUic.cxx
+++ b/Source/cmQtAutoMocUic.cxx
@@ -2163,7 +2163,9 @@
 void cmQtAutoMocUicT::JobDepFilesMergeT::Process()
 {
   if (Log().Verbose()) {
-    Log().Info(GenT::MOC, "Merging MOC dependencies");
+    Log().Info(GenT::MOC,
+               cmStrCat("Merging MOC dependencies into ",
+                        MessagePath(BaseConst().DepFile.c_str())));
   }
   auto processDepFile =
     [](const std::string& mocOutputFile) -> std::vector<std::string> {
diff --git a/Tests/FindPython/FindPythonScript.cmake b/Tests/FindPython/FindPythonScript.cmake
index bc7e0d1..808496e 100644
--- a/Tests/FindPython/FindPythonScript.cmake
+++ b/Tests/FindPython/FindPythonScript.cmake
@@ -1,4 +1,4 @@
-
+cmake_minimum_required(VERSION 3.12)
 if (PYTHON_MUST_NOT_BE_FOUND)
   find_package(${PYTHON_PACKAGE_NAME} QUIET)
   if (${PYTHON_PACKAGE_NAME}_FOUND)
diff --git a/Tests/QtAutogen/MocIncludeSymlink/CMakeLists.txt b/Tests/QtAutogen/MocIncludeSymlink/CMakeLists.txt
index 1627b39..8b11b46 100644
--- a/Tests/QtAutogen/MocIncludeSymlink/CMakeLists.txt
+++ b/Tests/QtAutogen/MocIncludeSymlink/CMakeLists.txt
@@ -61,6 +61,7 @@
     "${sourceDir}"
     MocInclude
     CMAKE_FLAGS "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
+                "-DCMAKE_AUTOMOC_PATH_PREFIX=ON"
                 "-DCMAKE_AUTOGEN_VERBOSE=${CMAKE_AUTOGEN_VERBOSE}"
                 "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
     OUTPUT_VARIABLE output
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 10e66c3..5d00554 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -142,6 +142,9 @@
   if(CMAKE_Fortran_COMPILER)
     list(APPEND Ninja_ARGS -DTEST_Fortran=1)
   endif()
+  if(CMake_TEST_Qt5 AND Qt5Core_FOUND)
+    list(APPEND Ninja_ARGS -DCMake_TEST_Qt5=1 -DCMAKE_TEST_Qt5Core_Version=${Qt5Core_VERSION})
+  endif()
   add_RunCMake_test(Ninja)
   set(NinjaMultiConfig_ARGS
     -DCYGWIN=${CYGWIN}
diff --git a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake
index dc77915..4e6eef6 100644
--- a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake
+++ b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake
@@ -1,5 +1,10 @@
 include(RunCMake)
 
+# Isolate test cases from caller's environment.
+set(ENV{CMAKE_PREFIX_PATH} "")
+set(ENV{CMAKE_APPBUNDLE_PATH} "")
+set(ENV{CMAKE_FRAMEWORK_PATH} "")
+
 run_cmake(PkgConfigDoesNotExist)
 
 run_cmake(FindPkgConfig_NO_PKGCONFIG_PATH)
diff --git a/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake b/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake
new file mode 100644
index 0000000..d69a119
--- /dev/null
+++ b/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake
@@ -0,0 +1,9 @@
+enable_language(CXX)
+
+find_package(Qt5Core REQUIRED)
+
+set(CMAKE_AUTOMOC ON)
+
+add_library(simple_lib SHARED simple_lib.cpp)
+add_executable(app_with_qt app.cpp app_qt.cpp)
+target_link_libraries(app_with_qt PRIVATE simple_lib Qt5::Core)
diff --git a/Tests/RunCMake/Ninja/RunCMakeTest.cmake b/Tests/RunCMake/Ninja/RunCMakeTest.cmake
index 8f9c263..d43023b 100644
--- a/Tests/RunCMake/Ninja/RunCMakeTest.cmake
+++ b/Tests/RunCMake/Ninja/RunCMakeTest.cmake
@@ -138,6 +138,7 @@
     message(FATAL_ERROR
       "top ninja build failed exited with status ${ninja_result}")
   endif()
+  set(ninja_stdout "${ninja_stdout}" PARENT_SCOPE)
 endfunction(run_ninja)
 
 function (run_LooseObjectDepends)
@@ -322,3 +323,23 @@
   run_ninja("${RunCMake_TEST_BINARY_DIR}" -w dupbuild=err)
 endfunction()
 run_ChangeBuildType()
+
+function(run_Qt5AutoMocDeps)
+  if(CMake_TEST_Qt5 AND CMAKE_TEST_Qt5Core_Version VERSION_GREATER_EQUAL 5.15.0)
+    set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Qt5AutoMocDeps-build)
+    run_cmake(Qt5AutoMocDeps)
+    unset(RunCMake_TEST_OPTIONS)
+    # Build the project.
+    run_ninja("${RunCMake_TEST_BINARY_DIR}")
+    # Touch just the library source file, which shouldn't cause a rerun of AUTOMOC
+    # for app_with_qt target.
+    touch("${RunCMake_SOURCE_DIR}/simple_lib.cpp")
+    # Build and assert that AUTOMOC was not run for app_with_qt.
+    run_ninja("${RunCMake_TEST_BINARY_DIR}")
+    if(ninja_stdout MATCHES "Automatic MOC for target app_with_qt")
+        message(FATAL_ERROR
+               "AUTOMOC should not have executed for 'app_with_qt' target:\nstdout:\n${ninja_stdout}")
+    endif()
+  endif()
+endfunction()
+run_Qt5AutoMocDeps()
diff --git a/Tests/RunCMake/Ninja/app.cpp b/Tests/RunCMake/Ninja/app.cpp
new file mode 100644
index 0000000..57380e4
--- /dev/null
+++ b/Tests/RunCMake/Ninja/app.cpp
@@ -0,0 +1,6 @@
+int main(int argc, char* argv[])
+{
+  (void)argc;
+  (void)argv;
+  return 0;
+}
diff --git a/Tests/RunCMake/Ninja/app_qt.cpp b/Tests/RunCMake/Ninja/app_qt.cpp
new file mode 100644
index 0000000..302c672
--- /dev/null
+++ b/Tests/RunCMake/Ninja/app_qt.cpp
@@ -0,0 +1,11 @@
+#include <QObject>
+
+class Mango : public QObject
+{
+  Q_OBJECT
+public:
+Q_SIGNALS:
+  void eatFruit();
+};
+
+#include "app_qt.moc"
diff --git a/Tests/RunCMake/Ninja/simple_lib.cpp b/Tests/RunCMake/Ninja/simple_lib.cpp
new file mode 100644
index 0000000..cf8d689
--- /dev/null
+++ b/Tests/RunCMake/Ninja/simple_lib.cpp
@@ -0,0 +1,6 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+  void dummy_symbol()
+{
+}