Merge branch 'backport-genex-SOURCES-test' into release-3.9
diff --git a/Copyright.txt b/Copyright.txt
index daaa1d1..3320108 100644
--- a/Copyright.txt
+++ b/Copyright.txt
@@ -68,6 +68,7 @@
 * Matthaeus G. Chajdas
 * Matthias Kretz <kretz@kde.org>
 * Matthias Maennich <matthias@maennich.net>
+* Michael Stürmer
 * Miguel A. Figueroa-Villanueva
 * Mike Jackson
 * Mike McQuaid <mike@mikemcquaid.com>
diff --git a/Help/manual/cmake-qt.7.rst b/Help/manual/cmake-qt.7.rst
index 00d6e6e..b7f16b9 100644
--- a/Help/manual/cmake-qt.7.rst
+++ b/Help/manual/cmake-qt.7.rst
@@ -70,8 +70,8 @@
 Included ``moc_*.cpp`` and ``*.moc`` files will be generated in the
 ``<AUTOGEN_BUILD_DIR>/include`` directory which is
 automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`.
-(This differs from CMake 3.7 and below; see their documentation for details.)
 
+* This differs from CMake 3.7 and below; see their documentation for details.
 * See :prop_tgt:`AUTOGEN_BUILD_DIR`.
 
 Not included ``moc_<basename>.cpp`` files will be generated in custom
@@ -107,16 +107,23 @@
 be run, and to create rules to execute ``uic`` at the appropriate time.
 
 If a preprocessor ``#include`` directive is found which matches
-``ui_<basename>.h``, and a ``<basename>.ui`` file exists, then ``uic`` will
-be executed to generate the appropriate file. The ``<basename>.ui`` file is
-searched for first in the vicinity of including file and afterwards in the
-optional :prop_tgt:`AUTOUIC_SEARCH_PATHS` of the target.
+``<path>ui_<basename>.h``, and a ``<basename>.ui`` file exists,
+then ``uic`` will be executed to generate the appropriate file.
+The ``<basename>.ui`` file is searched for in the following places
+
+1. ``<source_dir>/<basename>.ui``
+2. ``<source_dir>/<path><basename>.ui``
+3. ``<AUTOUIC_SEARCH_PATHS>/<basename>.ui``
+4. ``<AUTOUIC_SEARCH_PATHS>/<path><basename>.ui``
+
+where ``<source_dir>`` is the directory of the C++ file and
+:prop_tgt:`AUTOUIC_SEARCH_PATHS` is a list of additional search paths.
 
 The generated generated ``ui_*.h`` files are placed in the
 ``<AUTOGEN_BUILD_DIR>/include`` directory which is
 automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`.
-(This differs from CMake 3.7 and below; see their documentation for details.)
 
+* This differs from CMake 3.7 and below; see their documentation for details.
 * See :prop_tgt:`AUTOGEN_BUILD_DIR`.
 
 The :prop_tgt:`AUTOUIC` target property may be pre-set for all following
diff --git a/Help/release/3.9.rst b/Help/release/3.9.rst
index ae55105..897e268 100644
--- a/Help/release/3.9.rst
+++ b/Help/release/3.9.rst
@@ -34,8 +34,6 @@
   This is an experimental feature and can be activated by setting the
   :variable:`CMAKE_XCODE_GENERATE_SCHEME` variable to a ``TRUE`` value.
 
-* The :generator:`Xcode` generator now supports Xcode 9.
-
 Commands
 --------
 
@@ -310,9 +308,6 @@
   in dependent targets may now compile without waiting for their targets'
   dependencies to link.
 
-* On macOS, the default application bundle ``Info.plist`` file now enables
-  Hi-DPI support.
-
 * On macOS, ``RPATH`` settings such as :prop_tgt:`BUILD_WITH_INSTALL_RPATH`
   no longer affect the ``install_name`` field.  See policy :policy:`CMP0068`.
 
@@ -333,3 +328,15 @@
   CMake 3.9.0 has been removed for the 3.9 series due to regressions
   caused by new use of ``<PackageName>_ROOT`` variables.  The behavior
   may be re-introduced in the future in a more-compatible way.
+
+3.9.2
+-----
+
+* On macOS, the default application bundle ``Info.plist`` file no longer
+  enables Hi-DPI support as it did in 3.9.0 and 3.9.1.  The change had
+  to be reverted because it broke iOS applications.
+
+* The Xcode generator no longer adds "outputPaths" to custom script
+  build phases as it did in 3.9.0 and 3.9.1.  This was added in an
+  attempt to support Xcode 9's new build system, but broke incremental
+  rebuilds for both the old and new Xcode build systems.
diff --git a/Modules/CMakeCSharpInformation.cmake b/Modules/CMakeCSharpInformation.cmake
index cd86016..f71dcef 100644
--- a/Modules/CMakeCSharpInformation.cmake
+++ b/Modules/CMakeCSharpInformation.cmake
@@ -43,7 +43,7 @@
 # on the initial values computed in the platform/*.cmake files
 # use _INIT variables so that this only happens the first time
 # and you can set these flags in the cmake cache
-set(CMAKE_CSharp_FLAGS_INIT "$ENV{CSharpFLAGS} ${CMAKE_CSharp_FLAGS_INIT}")
+set(CMAKE_CSharp_FLAGS_INIT "$ENV{CSFLAGS} ${CMAKE_CSharp_FLAGS_INIT}")
 # avoid just having a space as the initial value for the cache
 if(CMAKE_CSharp_FLAGS_INIT STREQUAL " ")
   set(CMAKE_CSharp_FLAGS_INIT)
diff --git a/Modules/CMakeCUDAInformation.cmake b/Modules/CMakeCUDAInformation.cmake
index 9bba847..f4609cd 100644
--- a/Modules/CMakeCUDAInformation.cmake
+++ b/Modules/CMakeCUDAInformation.cmake
@@ -198,11 +198,11 @@
 #These are used when linking relocatable (dc) cuda code
 if(NOT CMAKE_CUDA_DEVICE_LINK_LIBRARY)
   set(CMAKE_CUDA_DEVICE_LINK_LIBRARY
-    "<CMAKE_CUDA_COMPILER> <CMAKE_CUDA_LINK_FLAGS> <LANGUAGE_COMPILE_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+    "<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <CMAKE_CUDA_LINK_FLAGS> <LANGUAGE_COMPILE_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
 endif()
 if(NOT CMAKE_CUDA_DEVICE_LINK_EXECUTABLE)
   set(CMAKE_CUDA_DEVICE_LINK_EXECUTABLE
-    "<CMAKE_CUDA_COMPILER> <FLAGS> <CMAKE_CUDA_LINK_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+    "<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <FLAGS> <CMAKE_CUDA_LINK_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
 endif()
 
 unset(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS)
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake
index eeb806f..7588f63 100644
--- a/Modules/CMakeDetermineCompilerId.cmake
+++ b/Modules/CMakeDetermineCompilerId.cmake
@@ -706,6 +706,7 @@
     OUTPUT_VARIABLE out
     ERROR_VARIABLE err
     RESULT_VARIABLE res
+    ENCODING AUTO # cl prints in current code page
     )
   if(res EQUAL 0 AND "${out}" MATCHES "(^|\n)([^:\n]*:[^:\n]*:[ \t]*)")
     set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "${CMAKE_MATCH_2}" PARENT_SCOPE)
diff --git a/Modules/Compiler/Clang-FindBinUtils.cmake b/Modules/Compiler/Clang-FindBinUtils.cmake
index e2822a1..b852660 100644
--- a/Modules/Compiler/Clang-FindBinUtils.cmake
+++ b/Modules/Compiler/Clang-FindBinUtils.cmake
@@ -2,6 +2,12 @@
   message(FATAL_ERROR "Internal error: _CMAKE_PROCESSING_LANGUAGE is not set")
 endif()
 
+# Debian:
+# * /usr/bin/llvm-ar-4.0
+# * /usr/bin/llvm-ranlib-4.0
+string(REGEX MATCH "^([0-9]+\\.[0-9]+)" __version_x_y
+    "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_VERSION}")
+
 # Try to find tools in the same directory as Clang itself
 get_filename_component(__clang_hint_1 "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER}" REALPATH)
 get_filename_component(__clang_hint_1 "${__clang_hint_1}" DIRECTORY)
@@ -12,6 +18,7 @@
 
 # http://manpages.ubuntu.com/manpages/precise/en/man1/llvm-ar.1.html
 find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR NAMES
+    "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ar-${__version_x_y}"
     "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ar"
     HINTS ${__clang_hints}
     DOC "LLVM archiver"
@@ -20,6 +27,7 @@
 
 # http://manpages.ubuntu.com/manpages/precise/en/man1/llvm-ranlib.1.html
 find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_RANLIB NAMES
+    "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ranlib-${__version_x_y}"
     "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ranlib"
     HINTS ${__clang_hints}
     DOC "Generate index for LLVM archive"
diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake
index b4abf75..b970e2b 100644
--- a/Modules/FindBoost.cmake
+++ b/Modules/FindBoost.cmake
@@ -208,10 +208,6 @@
 #
 # Set Boost_NO_BOOST_CMAKE to ON to disable the search for boost-cmake.
 
-# Save project's policies
-cmake_policy(PUSH)
-cmake_policy(SET CMP0057 NEW) # if IN_LIST
-
 #-------------------------------------------------------------------------------
 # Before we go searching, check whether boost-cmake is available, unless the
 # user specifically asked NOT to search for boost-cmake.
@@ -876,7 +872,9 @@
       set(_Boost_${uppercomponent}_DEPENDENCIES ${_Boost_${uppercomponent}_DEPENDENCIES} PARENT_SCOPE)
       set(_Boost_IMPORTED_TARGETS ${_Boost_IMPORTED_TARGETS} PARENT_SCOPE)
       foreach(componentdep ${_Boost_${uppercomponent}_DEPENDENCIES})
-        if (NOT ("${componentdep}" IN_LIST _boost_processed_components OR "${componentdep}" IN_LIST _boost_new_components))
+        list(FIND _boost_processed_components "${componentdep}" _boost_component_found)
+        list(FIND _boost_new_components "${componentdep}" _boost_component_new)
+        if (_boost_component_found EQUAL -1 AND _boost_component_new EQUAL -1)
           list(APPEND _boost_new_components ${componentdep})
         endif()
       endforeach()
@@ -1503,7 +1501,8 @@
 _Boost_MISSING_DEPENDENCIES(Boost_FIND_COMPONENTS _Boost_EXTRA_FIND_COMPONENTS)
 
 # If thread is required, get the thread libs as a dependency
-if("thread" IN_LIST Boost_FIND_COMPONENTS)
+list(FIND Boost_FIND_COMPONENTS thread _Boost_THREAD_DEPENDENCY_LIBS)
+if(NOT _Boost_THREAD_DEPENDENCY_LIBS EQUAL -1)
   include(CMakeFindDependencyMacro)
   find_dependency(Threads)
 endif()
@@ -1928,6 +1927,3 @@
 list(SORT _Boost_COMPONENTS_SEARCHED)
 set(_Boost_COMPONENTS_SEARCHED "${_Boost_COMPONENTS_SEARCHED}"
   CACHE INTERNAL "Components requested for this build tree.")
-
-# Restore project's policies
-cmake_policy(POP)
diff --git a/Modules/FindCygwin.cmake b/Modules/FindCygwin.cmake
index b2ed703..c6913da 100644
--- a/Modules/FindCygwin.cmake
+++ b/Modules/FindCygwin.cmake
@@ -8,14 +8,17 @@
 # this module looks for Cygwin
 
 if (WIN32)
-  find_program(CYGWIN_INSTALL_PATH
+  if(CYGWIN_INSTALL_PATH)
+    set(CYGWIN_BAT "${CYGWIN_INSTALL_PATH}/cygwin.bat")
+  endif()
+
+  find_program(CYGWIN_BAT
     cygwin.bat
     "C:/Cygwin"
     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygwin\\setup;rootdir]"
     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\/;native]"
   )
-  get_filename_component(CYGWIN_INSTALL_PATH "${CYGWIN_INSTALL_PATH}" DIRECTORY)
-  mark_as_advanced(
-    CYGWIN_INSTALL_PATH
-  )
+  get_filename_component(CYGWIN_INSTALL_PATH "${CYGWIN_BAT}" DIRECTORY)
+  mark_as_advanced(CYGWIN_BAT)
+
 endif ()
diff --git a/Modules/FindOpenMP.cmake b/Modules/FindOpenMP.cmake
index 1093be0..ee74a1a 100644
--- a/Modules/FindOpenMP.cmake
+++ b/Modules/FindOpenMP.cmake
@@ -429,6 +429,8 @@
   endif()
 endforeach()
 
+set(OpenMP_FOUND ${OPENMP_FOUND})
+
 if(CMAKE_Fortran_COMPILER_LOADED AND OpenMP_Fortran_FOUND)
   if(NOT DEFINED OpenMP_Fortran_HAVE_OMPLIB_MODULE)
     set(OpenMP_Fortran_HAVE_OMPLIB_MODULE FALSE CACHE BOOL INTERNAL "")
diff --git a/Modules/InstallRequiredSystemLibraries.cmake b/Modules/InstallRequiredSystemLibraries.cmake
index 6d33fc6..4e8713a 100644
--- a/Modules/InstallRequiredSystemLibraries.cmake
+++ b/Modules/InstallRequiredSystemLibraries.cmake
@@ -89,6 +89,8 @@
   endif()
 
   if(MSVC_VERSION EQUAL 1400)
+    set(MSVC_REDIST_NAME VC80)
+
     # Find the runtime library redistribution directory.
     get_filename_component(msvc_install_dir
       "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0;InstallDir]" ABSOLUTE)
@@ -129,6 +131,8 @@
   endif()
 
   if(MSVC_VERSION EQUAL 1500)
+    set(MSVC_REDIST_NAME VC90)
+
     # Find the runtime library redistribution directory.
     get_filename_component(msvc_install_dir
       "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0;InstallDir]" ABSOLUTE)
@@ -171,24 +175,35 @@
     endif()
   endif()
 
-  if(MSVC_VERSION EQUAL 1910)
+  set(MSVC_REDIST_NAME "")
+  set(_MSVCRT_DLL_VERSION "")
+  set(_MSVCRT_IDE_VERSION "")
+  if(MSVC_VERSION GREATER_EQUAL 2000)
+    message(WARNING "MSVC ${MSVC_VERSION} not yet supported.")
+  elseif(MSVC_VERSION GREATER_EQUAL 1911)
+    set(MSVC_REDIST_NAME VC141)
+    set(_MSVCRT_DLL_VERSION 140)
+    set(_MSVCRT_IDE_VERSION 15)
+  elseif(MSVC_VERSION EQUAL 1910)
+    set(MSVC_REDIST_NAME VC150)
     set(_MSVCRT_DLL_VERSION 140)
     set(_MSVCRT_IDE_VERSION 15)
   elseif(MSVC_VERSION EQUAL 1900)
+    set(MSVC_REDIST_NAME VC140)
     set(_MSVCRT_DLL_VERSION 140)
     set(_MSVCRT_IDE_VERSION 14)
   elseif(MSVC_VERSION EQUAL 1800)
+    set(MSVC_REDIST_NAME VC120)
     set(_MSVCRT_DLL_VERSION 120)
     set(_MSVCRT_IDE_VERSION 12)
   elseif(MSVC_VERSION EQUAL 1700)
+    set(MSVC_REDIST_NAME VC110)
     set(_MSVCRT_DLL_VERSION 110)
     set(_MSVCRT_IDE_VERSION 11)
   elseif(MSVC_VERSION EQUAL 1600)
+    set(MSVC_REDIST_NAME VC100)
     set(_MSVCRT_DLL_VERSION 100)
     set(_MSVCRT_IDE_VERSION 10)
-  else()
-    set(_MSVCRT_DLL_VERSION "")
-    set(_MSVCRT_IDE_VERSION "")
   endif()
 
   if(_MSVCRT_DLL_VERSION)
@@ -219,10 +234,10 @@
       unset(_vs_dir)
       unset(programfilesx86)
     endif()
-    find_path(MSVC_REDIST_DIR NAMES ${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.CRT PATHS ${_vs_redist_paths})
+    find_path(MSVC_REDIST_DIR NAMES ${CMAKE_MSVC_ARCH}/Microsoft.${MSVC_REDIST_NAME}.CRT PATHS ${_vs_redist_paths})
     unset(_vs_redist_paths)
     mark_as_advanced(MSVC_REDIST_DIR)
-    set(MSVC_CRT_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.CRT")
+    set(MSVC_CRT_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.${MSVC_REDIST_NAME}.CRT")
 
     if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY)
       set(__install__libs
@@ -242,7 +257,7 @@
 
     if(CMAKE_INSTALL_DEBUG_LIBRARIES)
       set(MSVC_CRT_DIR
-        "${MSVC_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.DebugCRT")
+        "${MSVC_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.${MSVC_REDIST_NAME}.DebugCRT")
       set(__install__libs ${__install__libs}
         "${MSVC_CRT_DIR}/msvcp${v}d.dll"
         )
@@ -383,7 +398,11 @@
         )
     endif()
 
-    if(MSVC_VERSION EQUAL 1910)
+    set(_MFC_DLL_VERSION "")
+    set(_MFC_IDE_VERSION "")
+    if(MSVC_VERSION GREATER_EQUAL 2000)
+      # Version not yet supported.
+    elseif(MSVC_VERSION GREATER_EQUAL 1910)
       set(_MFC_DLL_VERSION 140)
       set(_MFC_IDE_VERSION 15)
     elseif(MSVC_VERSION EQUAL 1900)
@@ -398,9 +417,6 @@
     elseif(MSVC_VERSION EQUAL 1600)
       set(_MFC_DLL_VERSION 100)
       set(_MFC_IDE_VERSION 10)
-    else()
-      set(_MFC_DLL_VERSION "")
-      set(_MFC_IDE_VERSION "")
     endif()
 
     if(_MFC_DLL_VERSION)
@@ -410,7 +426,7 @@
       # Starting with VS 15 the MFC DLLs may be in a different directory.
       if (NOT vs VERSION_LESS 15)
         file(GLOB _MSVC_REDIST_DIRS "${MSVC_REDIST_DIR}/../*")
-        find_path(MSVC_REDIST_MFC_DIR NAMES ${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.MFC
+        find_path(MSVC_REDIST_MFC_DIR NAMES ${CMAKE_MSVC_ARCH}/Microsoft.${MSVC_REDIST_NAME}.MFC
           PATHS ${_MSVC_REDIST_DIRS} NO_DEFAULT_PATH)
         mark_as_advanced(MSVC_REDIST_MFC_DIR)
         unset(_MSVC_REDIST_DIRS)
@@ -424,7 +440,7 @@
 
       if(CMAKE_INSTALL_DEBUG_LIBRARIES)
         set(MSVC_MFC_DIR
-          "${MSVC_REDIST_MFC_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.DebugMFC")
+          "${MSVC_REDIST_MFC_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.${MSVC_REDIST_NAME}.DebugMFC")
         set(__install__libs ${__install__libs}
           "${MSVC_MFC_DIR}/mfc${v}ud.dll"
           "${MSVC_MFC_DIR}/mfcm${v}ud.dll"
@@ -437,7 +453,7 @@
         endif()
       endif()
 
-      set(MSVC_MFC_DIR "${MSVC_REDIST_MFC_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.MFC")
+      set(MSVC_MFC_DIR "${MSVC_REDIST_MFC_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.${MSVC_REDIST_NAME}.MFC")
       if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY)
         set(__install__libs ${__install__libs}
           "${MSVC_MFC_DIR}/mfc${v}u.dll"
@@ -452,7 +468,7 @@
       endif()
 
       # include the language dll's as well as the actuall dll's
-      set(MSVC_MFCLOC_DIR "${MSVC_REDIST_MFC_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.MFCLOC")
+      set(MSVC_MFCLOC_DIR "${MSVC_REDIST_MFC_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.${MSVC_REDIST_NAME}.MFCLOC")
       set(__install__libs ${__install__libs}
         "${MSVC_MFCLOC_DIR}/mfc${v}chs.dll"
         "${MSVC_MFCLOC_DIR}/mfc${v}cht.dll"
@@ -471,7 +487,11 @@
   # MSVC 8 was the first version with OpenMP
   # Furthermore, there is no debug version of this
   if(CMAKE_INSTALL_OPENMP_LIBRARIES)
-    if(MSVC_VERSION EQUAL 1910)
+    set(_MSOMP_DLL_VERSION "")
+    set(_MSOMP_IDE_VERSION "")
+    if(MSVC_VERSION GREATER_EQUAL 2000)
+      # Version not yet supported.
+    elseif(MSVC_VERSION GREATER_EQUAL 1910)
       set(_MSOMP_DLL_VERSION 140)
       set(_MSOMP_IDE_VERSION 15)
     elseif(MSVC_VERSION EQUAL 1900)
@@ -492,15 +512,12 @@
     elseif(MSVC_VERSION EQUAL 1400)
       set(_MSOMP_DLL_VERSION 80)
       set(_MSOMP_IDE_VERSION 8)
-    else()
-      set(_MSOMP_DLL_VERSION "")
-      set(_MSOMP_IDE_VERSION "")
     endif()
 
     if(_MSOMP_DLL_VERSION)
       set(v "${_MSOMP_DLL_VERSION}")
       set(vs "${_MSOMP_IDE_VERSION}")
-      set(MSVC_OPENMP_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.OPENMP")
+      set(MSVC_OPENMP_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.${MSVC_REDIST_NAME}.OPENMP")
 
       if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY)
         set(__install__libs ${__install__libs}
diff --git a/Modules/MacOSXBundleInfo.plist.in b/Modules/MacOSXBundleInfo.plist.in
index e06b17e..a4009bc 100644
--- a/Modules/MacOSXBundleInfo.plist.in
+++ b/Modules/MacOSXBundleInfo.plist.in
@@ -30,9 +30,5 @@
 	<true/>
 	<key>NSHumanReadableCopyright</key>
 	<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
-	<key>NSPrincipalClass</key>
-	<string>NSApplication</string>
-	<key>NSHighResolutionCapable</key>
-	<string>True</string>
 </dict>
 </plist>
diff --git a/Modules/Platform/Android/Determine-Compiler-NDK.cmake b/Modules/Platform/Android/Determine-Compiler-NDK.cmake
index d983dd6..0649925 100644
--- a/Modules/Platform/Android/Determine-Compiler-NDK.cmake
+++ b/Modules/Platform/Android/Determine-Compiler-NDK.cmake
@@ -124,7 +124,7 @@
 unset(_ANDROID_TOOL_SETUP_MK)
 set(_ANDROID_TOOL_PREFIX "")
 set(_ANDROID_TOOL_NAME_ONLY "")
-set(_ANDROID_TOOL_LLVM_NAME "")
+set(_ANDROID_TOOL_LLVM_NAME "llvm")
 set(_ANDROID_TOOL_LLVM_VERS "")
 foreach(line IN LISTS _ANDROID_TOOL_SETUP)
   if(CMAKE_ANDROID_NDK_TOOLCHAIN_DEBUG)
diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx
index 9864cf3..d26d5bc 100644
--- a/Source/CPack/cmCPackDragNDropGenerator.cxx
+++ b/Source/CPack/cmCPackDragNDropGenerator.cxx
@@ -9,6 +9,7 @@
 
 #include "cmsys/FStream.hxx"
 #include "cmsys/RegularExpression.hxx"
+#include <algorithm>
 #include <iomanip>
 #include <map>
 #include <stdlib.h>
diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx
index 87a22d1..bbff48e 100644
--- a/Source/cmGlobalVisualStudioGenerator.cxx
+++ b/Source/cmGlobalVisualStudioGenerator.cxx
@@ -778,6 +778,19 @@
   return false;
 }
 
+bool cmGlobalVisualStudioGenerator::TargetCanBeReferenced(
+  cmGeneratorTarget const* gt)
+{
+  if (this->TargetIsCSharpOnly(gt)) {
+    return true;
+  }
+  if (gt->GetType() != cmStateEnums::SHARED_LIBRARY &&
+      gt->GetType() != cmStateEnums::EXECUTABLE) {
+    return false;
+  }
+  return true;
+}
+
 bool cmGlobalVisualStudioGenerator::TargetCompare::operator()(
   cmGeneratorTarget const* l, cmGeneratorTarget const* r) const
 {
diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h
index c12a933..3c43ccd 100644
--- a/Source/cmGlobalVisualStudioGenerator.h
+++ b/Source/cmGlobalVisualStudioGenerator.h
@@ -85,6 +85,9 @@
   // return true if target is C# only
   static bool TargetIsCSharpOnly(cmGeneratorTarget const* gt);
 
+  // return true if target can be referenced by C# targets
+  bool TargetCanBeReferenced(cmGeneratorTarget const* gt);
+
   /** Get the top-level registry key for this VS version.  */
   std::string GetRegistryBase();
 
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 3cd14e1..9037961 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -1517,17 +1517,6 @@
   makecmd += " all";
   buildphase->AddAttribute("shellScript", this->CreateString(makecmd));
   buildphase->AddAttribute("showEnvVarsInLog", this->CreateString("0"));
-
-  cmXCodeObject* outputFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
-  for (std::vector<cmCustomCommand>::const_iterator i = commands.begin();
-       i != commands.end(); ++i) {
-    std::vector<std::string> const& outputs = i->GetOutputs();
-    for (std::vector<std::string>::const_iterator j = outputs.begin();
-         j != outputs.end(); ++j) {
-      outputFiles->AddObject(this->CreateString(*j));
-    }
-  }
-  buildphase->AddAttribute("outputPaths", outputFiles);
 }
 
 void cmGlobalXCodeGenerator::CreateCustomRulesMakefile(
diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx
index c79f66d..d12d96d 100644
--- a/Source/cmQtAutoGenerators.cxx
+++ b/Source/cmQtAutoGenerators.cxx
@@ -1446,31 +1446,62 @@
 
 bool cmQtAutoGenerators::UicFindIncludedFile(std::string& absFile,
                                              const std::string& sourceFile,
-                                             const std::string& includeString)
+                                             const std::string& searchPath,
+                                             const std::string& searchFile)
 {
   bool success = false;
-  // Search in vicinity of the source
+  std::vector<std::string> testFiles;
+  // Collect search paths list
   {
-    std::string testPath = SubDirPrefix(sourceFile);
-    testPath += includeString;
-    if (cmsys::SystemTools::FileExists(testPath.c_str())) {
-      absFile = cmsys::SystemTools::GetRealPath(testPath);
-      success = true;
+    const std::string searchFileFull = searchPath + searchFile;
+    // Vicinity of the source
+    {
+      const std::string sourcePath = SubDirPrefix(sourceFile);
+      testFiles.push_back(sourcePath + searchFile);
+      if (!searchPath.empty()) {
+        testFiles.push_back(sourcePath + searchFileFull);
+      }
     }
-  }
-  // Search in include directories
-  if (!success) {
-    for (std::vector<std::string>::const_iterator iit =
-           this->UicSearchPaths.begin();
-         iit != this->UicSearchPaths.end(); ++iit) {
-      const std::string fullPath = ((*iit) + '/' + includeString);
-      if (cmsys::SystemTools::FileExists(fullPath.c_str())) {
-        absFile = cmsys::SystemTools::GetRealPath(fullPath);
-        success = true;
-        break;
+    // AUTOUIC search paths
+    if (!this->UicSearchPaths.empty()) {
+      for (std::vector<std::string>::const_iterator iit =
+             this->UicSearchPaths.begin();
+           iit != this->UicSearchPaths.end(); ++iit) {
+        testFiles.push_back(*iit + "/" + searchFile);
+      }
+      if (!searchPath.empty()) {
+        for (std::vector<std::string>::const_iterator iit =
+               this->UicSearchPaths.begin();
+             iit != this->UicSearchPaths.end(); ++iit) {
+          testFiles.push_back(*iit + "/" + searchFileFull);
+        }
       }
     }
   }
+
+  // Search for the .ui file!
+  for (std::vector<std::string>::const_iterator iit = testFiles.begin();
+       iit != testFiles.end(); ++iit) {
+    const std::string& testFile = *iit;
+    if (cmsys::SystemTools::FileExists(testFile.c_str())) {
+      absFile = cmsys::SystemTools::GetRealPath(testFile);
+      success = true;
+      break;
+    }
+  }
+
+  // Log error
+  if (!success) {
+    std::ostringstream ost;
+    ost << "AutoUic: Error: " << Quoted(sourceFile) << "\n";
+    ost << "Could not find " << Quoted(searchFile) << " in\n";
+    for (std::vector<std::string>::const_iterator iit = testFiles.begin();
+         iit != testFiles.end(); ++iit) {
+      ost << "  " << Quoted(*iit) << "\n";
+    }
+    this->LogError(ost.str());
+  }
+
   return success;
 }
 
@@ -1500,16 +1531,14 @@
         const std::string uiBasePath = SubDirPrefix(*uit);
         const std::string uiBaseName =
           cmsys::SystemTools::GetFilenameWithoutLastExtension(*uit).substr(3);
-        const std::string searchFileName = uiBasePath + uiBaseName + ".ui";
+        const std::string uiFileName = uiBaseName + ".ui";
         std::string uiInputFile;
-        if (UicFindIncludedFile(uiInputFile, source, searchFileName)) {
+        if (UicFindIncludedFile(uiInputFile, source, uiBasePath, uiFileName)) {
           std::string uiOutputFile = uiBasePath + "ui_" + uiBaseName + ".h";
           cmSystemTools::ReplaceString(uiOutputFile, "..", "__");
           uiGenMap[uiInputFile] = uiOutputFile;
           testMap[uiInputFile] = uiOutputFile;
         } else {
-          this->LogError("AutoUic: Error: " + Quoted(sit->first) +
-                         "\nCould not find " + Quoted(searchFileName));
           return false;
         }
       }
diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h
index b525364..337aa17 100644
--- a/Source/cmQtAutoGenerators.h
+++ b/Source/cmQtAutoGenerators.h
@@ -112,7 +112,8 @@
 
   // -- Uic file generation
   bool UicFindIncludedFile(std::string& absFile, const std::string& sourceFile,
-                           const std::string& includeString);
+                           const std::string& searchPath,
+                           const std::string& searchFile);
   bool UicGenerateAll(
     const std::map<std::string, std::vector<std::string> >& includedUis);
   bool UicGenerateFile(const std::string& realName,
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 88fa19c..dee153f 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -3502,6 +3502,13 @@
     (*this->BuildFileStream) << "</Project>\n";
     this->WriteString("<Name>", 3);
     (*this->BuildFileStream) << name << "</Name>\n";
+    if (csproj == this->ProjectType) {
+      if (!static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
+             ->TargetCanBeReferenced(dt)) {
+        this->WriteString(
+          "<ReferenceOutputAssembly>false</ReferenceOutputAssembly>\n", 3);
+      }
+    }
     this->WriteString("</ProjectReference>\n", 2);
   }
   this->WriteString("</ItemGroup>\n", 1);
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index c5a6836..da1fe6d 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -306,7 +306,7 @@
     return ret;
   }
   cmake::Role const role =
-    workingMode == cmake::NORMAL_MODE ? cmake::RoleProject : cmake::RoleScript;
+    workingMode == cmake::SCRIPT_MODE ? cmake::RoleScript : cmake::RoleProject;
   cmake cm(role);
   cm.SetHomeDirectory("");
   cm.SetHomeOutputDirectory("");
diff --git a/Tests/CSharpLinkToCxx/CMakeLists.txt b/Tests/CSharpLinkToCxx/CMakeLists.txt
index c4269e0..153c57c 100644
--- a/Tests/CSharpLinkToCxx/CMakeLists.txt
+++ b/Tests/CSharpLinkToCxx/CMakeLists.txt
@@ -15,3 +15,9 @@
 add_executable(CSharpLinkToCxx csharp.cs)
 
 target_link_libraries(CSharpLinkToCxx CLIApp)
+
+# this unmanaged C++ library will be added to the C#/.NET
+# references of CSharpLinkToCxx but it will show a warning
+# because it is unmanaged
+add_library(CppNativeApp SHARED cpp_native.hpp cpp_native.cpp)
+target_link_libraries(CSharpLinkToCxx CppNativeApp)
diff --git a/Tests/CSharpLinkToCxx/cpp_native.cpp b/Tests/CSharpLinkToCxx/cpp_native.cpp
new file mode 100644
index 0000000..dc7670f
--- /dev/null
+++ b/Tests/CSharpLinkToCxx/cpp_native.cpp
@@ -0,0 +1,10 @@
+#include "cpp_native.hpp"
+
+#include <iostream>
+
+namespace CppApp {
+void MyCpp::testMyCpp()
+{
+  std::cout << "#message from CppApp" << std::endl;
+}
+}
diff --git a/Tests/CSharpLinkToCxx/cpp_native.hpp b/Tests/CSharpLinkToCxx/cpp_native.hpp
new file mode 100644
index 0000000..0fa1a3b
--- /dev/null
+++ b/Tests/CSharpLinkToCxx/cpp_native.hpp
@@ -0,0 +1,9 @@
+#pragma once
+
+namespace CppApp {
+class MyCpp
+{
+public:
+  void testMyCpp();
+};
+}
diff --git a/Tests/FindPackageModeMakefileTest/FindFoo.cmake.in b/Tests/FindPackageModeMakefileTest/FindFoo.cmake.in
index dc62bac..2eb7b7a 100644
--- a/Tests/FindPackageModeMakefileTest/FindFoo.cmake.in
+++ b/Tests/FindPackageModeMakefileTest/FindFoo.cmake.in
@@ -5,5 +5,7 @@
 set(FOO_LIBRARIES ${FOO_LIBRARY})
 set(FOO_INCLUDE_DIRS "${FOO_INCLUDE_DIR}"  "/some/path/with a space/include" )
 
+add_library(Foo::Foo INTERFACE IMPORTED)
+
 include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(Foo  DEFAULT_MSG  FOO_LIBRARY FOO_INCLUDE_DIR )
diff --git a/Tests/QtAutogen/uicInclude/PageC2.ui b/Tests/QtAutogen/uicInclude/PageC2.ui
new file mode 100644
index 0000000..daab868
--- /dev/null
+++ b/Tests/QtAutogen/uicInclude/PageC2.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>PageC2</class>
+ <widget class="QWidget" name="PageC2">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <widget class="QTreeView" name="treeView"/>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Tests/QtAutogen/uicInclude/dirB/sub/PageB.ui b/Tests/QtAutogen/uicInclude/dirB/PageB.ui
similarity index 100%
rename from Tests/QtAutogen/uicInclude/dirB/sub/PageB.ui
rename to Tests/QtAutogen/uicInclude/dirB/PageB.ui
diff --git a/Tests/QtAutogen/uicInclude/dirB/PageB2.ui b/Tests/QtAutogen/uicInclude/dirB/PageB2.ui
new file mode 100644
index 0000000..2225150
--- /dev/null
+++ b/Tests/QtAutogen/uicInclude/dirB/PageB2.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>PageB2</class>
+ <widget class="QWidget" name="PageB2">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <widget class="QTreeView" name="treeView"/>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Tests/QtAutogen/uicInclude/dirB/subB/PageBsub.ui b/Tests/QtAutogen/uicInclude/dirB/subB/PageBsub.ui
new file mode 100644
index 0000000..873016e
--- /dev/null
+++ b/Tests/QtAutogen/uicInclude/dirB/subB/PageBsub.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>PageBsub</class>
+ <widget class="QWidget" name="PageBsub">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <widget class="QTreeView" name="treeView"/>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Tests/QtAutogen/uicInclude/main.cpp b/Tests/QtAutogen/uicInclude/main.cpp
index 4ca66a7..c8e7609 100644
--- a/Tests/QtAutogen/uicInclude/main.cpp
+++ b/Tests/QtAutogen/uicInclude/main.cpp
@@ -6,5 +6,13 @@
   return 0;
 }
 
-#include "sub/ui_PageB.h"
+// .ui files in CMAKE_AUTOUIC_SEARCH_PATHS
+#include "ui_PageA.h"
+// .ui files in AUTOUIC_SEARCH_PATHS
+#include "sub/gen/deep/ui_PageB2.h"
+#include "subB/ui_PageBsub.h"
+#include "ui_PageB.h"
+// .ui files in source's vicinity
+#include "sub/gen/deep/ui_PageC2.h"
+#include "subC/ui_PageCsub.h"
 #include "ui_PageC.h"
diff --git a/Tests/QtAutogen/uicInclude/subC/PageCsub.ui b/Tests/QtAutogen/uicInclude/subC/PageCsub.ui
new file mode 100644
index 0000000..0268326
--- /dev/null
+++ b/Tests/QtAutogen/uicInclude/subC/PageCsub.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>PageCsub</class>
+ <widget class="QWidget" name="PageCsub">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <widget class="QTreeView" name="treeView"/>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>