Merge branch 'implicit-libNN-dirs' into release
diff --git a/Help/manual/cmake-qt.7.rst b/Help/manual/cmake-qt.7.rst
index e4c3246..cad4951 100644
--- a/Help/manual/cmake-qt.7.rst
+++ b/Help/manual/cmake-qt.7.rst
@@ -173,7 +173,7 @@
 that the qtmain.lib static library shipped with Qt will be linked by all
 dependent executables which have the :prop_tgt:`WIN32_EXECUTABLE` enabled.
 
-Do disable this behavior, enable the ``Qt5_NO_LINK_QTMAIN`` target property for
+To disable this behavior, enable the ``Qt5_NO_LINK_QTMAIN`` target property for
 Qt 5 based targets or ``QT4_NO_LINK_QTMAIN`` target property for Qt 4 based
 targets.
 
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index d9d7a0c..f4b9666 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -131,6 +131,7 @@
    /variable/CMAKE_MODULE_PATH
    /variable/CMAKE_NOT_USING_CONFIG_FLAGS
    /variable/CMAKE_POLICY_DEFAULT_CMPNNNN
+   /variable/CMAKE_POLICY_WARNING_CMPNNNN
    /variable/CMAKE_PREFIX_PATH
    /variable/CMAKE_PROGRAM_PATH
    /variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE
diff --git a/Help/policy/CMP0025.rst b/Help/policy/CMP0025.rst
index f3b39e3..8d19edf 100644
--- a/Help/policy/CMP0025.rst
+++ b/Help/policy/CMP0025.rst
@@ -1,21 +1,27 @@
 CMP0025
 -------
 
-Compiler id for Apple Clang is now AppleClang.
+Compiler id for Apple Clang is now ``AppleClang``.
 
-CMake >= 3.0 recognize that Apple Clang is a different compiler
+CMake 3.0 and above recognize that Apple Clang is a different compiler
 than upstream Clang and that they have different version numbers.
-CMake now prefers to present this to projects by setting
-CMAKE_<LANG>_COMPILER_ID to "AppleClang" instead of "Clang".  However,
-existing projects may assume the compiler id for Apple Clang is just
-"Clang" as it was in CMake < 3.0.  Therefore this policy determines
-for Apple Clang which compiler id to report in
-CMAKE_<LANG>_COMPILER_ID after <LANG> is enabled by the project() or
-enable_language() command.
+CMake now prefers to present this to projects by setting the
+:variable:`CMAKE_<LANG>_COMPILER_ID` variable to ``AppleClang`` instead
+of ``Clang``.  However, existing projects may assume the compiler id for
+Apple Clang is just ``Clang`` as it was in CMake versions prior to 3.0.
+Therefore this policy determines for Apple Clang which compiler id to
+report in the :variable:`CMAKE_<LANG>_COMPILER_ID` variable after
+language ``<LANG>`` is enabled by the :command:`project` or
+:command:`enable_language` command.  The policy must be set prior
+to the invocation of either command.
 
-The OLD behavior for this policy is to use compiler id "Clang".  The
-NEW behavior for this policy is to use compiler id "AppleClang".
+The OLD behavior for this policy is to use compiler id ``Clang``.  The
+NEW behavior for this policy is to use compiler id ``AppleClang``.
 
-This policy was introduced in CMake version 3.0.  CMake version
-|release| warns when the policy is not set and uses OLD behavior.  Use
-the cmake_policy command to set it to OLD or NEW explicitly.
+This policy was introduced in CMake version 3.0.  Use the
+:command:`cmake_policy` command to set this policy to OLD or NEW explicitly.
+Unlike most policies, CMake version |release| does *not* warn
+by default when this policy is not set and simply uses OLD behavior.
+See documentation of the
+:variable:`CMAKE_POLICY_WARNING_CMP0025 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
+variable to control the warning.
diff --git a/Help/policy/CMP0047.rst b/Help/policy/CMP0047.rst
index c2d951b..26ae439 100644
--- a/Help/policy/CMP0047.rst
+++ b/Help/policy/CMP0047.rst
@@ -1,16 +1,28 @@
 CMP0047
 -------
 
-Use QCC compiler id for the qcc drivers on QNX.
+Use ``QCC`` compiler id for the qcc drivers on QNX.
 
-CMake 2.8.12 and lower assigned the QNX qcc and QCC compiler drivers the "GNU"
-compiler id.
+CMake 3.0 and above recognize that the QNX qcc compiler driver is
+different from the GNU compiler.
+CMake now prefers to present this to projects by setting the
+:variable:`CMAKE_<LANG>_COMPILER_ID` variable to ``QCC`` instead
+of ``GNU``.  However, existing projects may assume the compiler id for
+QNX qcc is just ``GNU`` as it was in CMake versions prior to 3.0.
+Therefore this policy determines for QNX qcc which compiler id to
+report in the :variable:`CMAKE_<LANG>_COMPILER_ID` variable after
+language ``<LANG>`` is enabled by the :command:`project` or
+:command:`enable_language` command.  The policy must be set prior
+to the invocation of either command.
 
-The OLD behavior for this policy is to use the "GNU" compiler id for the qcc
-and QCC compiler drivers. The NEW behavior for this policy is to use the "QCC"
-compiler id for those drivers.
+The OLD behavior for this policy is to use the ``GNU`` compiler id
+for the qcc and QCC compiler drivers. The NEW behavior for this policy
+is to use the ``QCC`` compiler id for those drivers.
 
-This policy was introduced in CMake version 3.0.
-CMake version |release| warns when the policy is not set and uses
-OLD behavior.  Use the cmake_policy command to set it to OLD or
-NEW explicitly.
+This policy was introduced in CMake version 3.0.  Use the
+:command:`cmake_policy` command to set this policy to OLD or NEW explicitly.
+Unlike most policies, CMake version |release| does *not* warn
+by default when this policy is not set and simply uses OLD behavior.
+See documentation of the
+:variable:`CMAKE_POLICY_WARNING_CMP0047 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
+variable to control the warning.
diff --git a/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst b/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst
new file mode 100644
index 0000000..b563aea
--- /dev/null
+++ b/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst
@@ -0,0 +1,17 @@
+CMAKE_POLICY_WARNING_CMP<NNNN>
+------------------------------
+
+Explicitly enable or disable the warning when CMake Policy ``CMP<NNNN>``
+is not set.  This is meaningful only for the few policies that do not
+warn by default:
+
+* ``CMAKE_POLICY_WARNING_CMP0025`` controls the warning for
+  policy :policy:`CMP0025`.
+* ``CMAKE_POLICY_WARNING_CMP0047`` controls the warning for
+  policy :policy:`CMP0047`.
+
+This variable should not be set by a project in CMake code.  Project
+developers running CMake may set this variable in their cache to
+enable the warning (e.g. ``-DCMAKE_POLICY_WARNING_CMP<NNNN>=ON``).
+Alternatively, running :manual:`cmake(1)` with the ``--debug-output``
+or ``--trace`` option will also enable the warning.
diff --git a/Modules/CMakeDetermineVSServicePack.cmake b/Modules/CMakeDetermineVSServicePack.cmake
index 353aed6..2854387 100644
--- a/Modules/CMakeDetermineVSServicePack.cmake
+++ b/Modules/CMakeDetermineVSServicePack.cmake
@@ -2,15 +2,15 @@
 # CMakeDetermineVSServicePack
 # ---------------------------
 #
+# Deprecated.  Do not use.
+#
+# The functionality of this module has been superseded by the
+# :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable that contains
+# the compiler version number.
+#
 # Determine the Visual Studio service pack of the 'cl' in use.
 #
-# The functionality of this module has been superseded by the platform
-# variable CMAKE_<LANG>_COMPILER_VERSION that contains the compiler
-# version number.
-#
-# Usage:
-#
-# ::
+# Usage::
 #
 #   if(MSVC)
 #     include(CMakeDetermineVSServicePack)
@@ -21,14 +21,12 @@
 #   endif()
 #
 # Function DetermineVSServicePack sets the given variable to one of the
-# following values or an empty string if unknown:
-#
-# ::
+# following values or an empty string if unknown::
 #
 #   vc80, vc80sp1
 #   vc90, vc90sp1
 #   vc100, vc100sp1
-#   vc110, vc110sp1, vc110sp2
+#   vc110, vc110sp1, vc110sp2, vc110sp3, vc110sp4
 
 #=============================================================================
 # Copyright 2009-2013 Kitware, Inc.
@@ -68,6 +66,8 @@
        set(_version "vc110sp2")
    elseif(${_cl_version} VERSION_EQUAL "17.00.60610.1")
        set(_version "vc110sp3")
+   elseif(${_cl_version} VERSION_EQUAL "17.00.61030")
+       set(_version "vc110sp4")
    else()
        set(_version "")
    endif()
@@ -86,27 +86,14 @@
           OUTPUT_QUIET
         )
 
-      string(REGEX MATCH "Compiler Version [0-9]+.[0-9]+.[0-9]+.[0-9]+"
-        _cl_version "${_output}")
-
-      if(_cl_version)
-        string(REGEX MATCHALL "[0-9]+"
-            _cl_version_list "${_cl_version}")
-        list(GET _cl_version_list 0 _major)
-        list(GET _cl_version_list 1 _minor)
-        list(GET _cl_version_list 2 _patch)
-        list(GET _cl_version_list 3 _tweak)
-
+      if(_output MATCHES "Compiler Version (([0-9]+)\\.([0-9]+)\\.([0-9]+)(\\.([0-9]+))?)")
+        set(_cl_version ${CMAKE_MATCH_1})
+        set(_major ${CMAKE_MATCH_2})
+        set(_minor ${CMAKE_MATCH_3})
         if("${_major}${_minor}" STREQUAL "${MSVC_VERSION}")
-          set(_cl_version ${_major}.${_minor}.${_patch}.${_tweak})
-        else()
-          unset(_cl_version)
-        endif()
-      endif()
-
-      if(_cl_version)
           set(${_SUCCESS_VAR} true PARENT_SCOPE)
           set(${_VERSION_VAR} ${_cl_version} PARENT_SCOPE)
+        endif()
       endif()
     endif()
 endfunction()
@@ -127,20 +114,9 @@
 
     file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc")
 
-    string(REGEX MATCH "Compiler Version [0-9]+.[0-9]+.[0-9]+.[0-9]+"
-      _cl_version "${_output}")
-
-    if(_cl_version)
-      string(REGEX MATCHALL "[0-9]+"
-          _cl_version_list "${_cl_version}")
-
-      list(GET _cl_version_list 0 _major)
-      list(GET _cl_version_list 1 _minor)
-      list(GET _cl_version_list 2 _patch)
-      list(GET _cl_version_list 3 _tweak)
-
+    if(_output MATCHES "Compiler Version (([0-9]+)\\.([0-9]+)\\.([0-9]+)(\\.([0-9]+))?)")
       set(${_SUCCESS_VAR} true PARENT_SCOPE)
-      set(${_VERSION_VAR} ${_major}.${_minor}.${_patch}.${_tweak} PARENT_SCOPE)
+      set(${_VERSION_VAR} "${CMAKE_MATCH_1}" PARENT_SCOPE)
     endif()
 endfunction()
 
diff --git a/Modules/CMakeFortranCompilerABI.F b/Modules/CMakeFortranCompilerABI.F
index 21ca7ff..b34c284 100644
--- a/Modules/CMakeFortranCompilerABI.F
+++ b/Modules/CMakeFortranCompilerABI.F
@@ -10,11 +10,15 @@
         PRINT *, 'INFO:sizeof_dptr[8]'
 #elif defined(_M_AMD64)
         PRINT *, 'INFO:sizeof_dptr[8]'
+#elif defined(__x86_64__)
+        PRINT *, 'INFO:sizeof_dptr[8]'
 
 #elif defined(_ILP32)
         PRINT *, 'INFO:sizeof_dptr[4]'
 #elif defined(_M_IX86)
         PRINT *, 'INFO:sizeof_dptr[4]'
+#elif defined(__i386__)
+        PRINT *, 'INFO:sizeof_dptr[4]'
 
 #elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8
         PRINT *, 'INFO:sizeof_dptr[8]'
diff --git a/Modules/CMakeRCInformation.cmake b/Modules/CMakeRCInformation.cmake
index 8ffe50a..6bb2636 100644
--- a/Modules/CMakeRCInformation.cmake
+++ b/Modules/CMakeRCInformation.cmake
@@ -13,15 +13,16 @@
 #  License text for the above reference.)
 
 
-# This file sets the basic flags for the Fortran language in CMake.
+# This file sets the basic flags for the Windows Resource Compiler.
 # It also loads the available platform file for the system-compiler
 # if it exists.
 
 # make sure we don't use CMAKE_BASE_NAME from somewhere else
 set(CMAKE_BASE_NAME)
-get_filename_component(CMAKE_BASE_NAME ${CMAKE_RC_COMPILER} NAME_WE)
-if("${CMAKE_BASE_NAME}" MATCHES "windres")
-  set(CMAKE_BASE_NAME "windres")
+if(CMAKE_RC_COMPILER MATCHES "windres[^/]*$")
+ set(CMAKE_BASE_NAME "windres")
+else()
+ get_filename_component(CMAKE_BASE_NAME ${CMAKE_RC_COMPILER} NAME_WE)
 endif()
 set(CMAKE_SYSTEM_AND_RC_COMPILER_INFO_FILE
   ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}.cmake)
@@ -30,7 +31,7 @@
 
 
 set (CMAKE_RC_FLAGS "$ENV{RCFLAGS} ${CMAKE_RC_FLAGS_INIT}" CACHE STRING
-     "Flags for Fortran compiler.")
+     "Flags for Windows Resource Compiler.")
 
 # These are the only types of flags that should be passed to the rc
 # command, if COMPILE_FLAGS is used on a target this will be used
diff --git a/Modules/Qt4Macros.cmake b/Modules/Qt4Macros.cmake
index 8baf896..5ada030 100644
--- a/Modules/Qt4Macros.cmake
+++ b/Modules/Qt4Macros.cmake
@@ -103,7 +103,7 @@
 
 
 # helper macro to set up a moc rule
-macro (QT4_CREATE_MOC_COMMAND infile outfile moc_flags moc_options moc_target)
+function (QT4_CREATE_MOC_COMMAND infile outfile moc_flags moc_options moc_target)
   # For Windows, create a parameters file to work around command line length limit
   # Pass the parameters in a file.  Set the working directory to
   # be that containing the parameters file and reference it by
@@ -144,7 +144,7 @@
                       DEPENDS ${infile}
                       ${_moc_working_dir}
                       VERBATIM)
-endmacro ()
+endfunction ()
 
 
 macro (QT4_GENERATE_MOC infile outfile )
diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx
index ef62523..e27d830 100644
--- a/Source/cmAddCustomTargetCommand.cxx
+++ b/Source/cmAddCustomTargetCommand.cxx
@@ -165,10 +165,13 @@
   if (!nameOk)
     {
     cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+    cmOStringStream e;
     bool issueMessage = false;
     switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0037))
       {
       case cmPolicies::WARN:
+        e << (this->Makefile->GetPolicies()
+          ->GetPolicyWarning(cmPolicies::CMP0037)) << "\n";
         issueMessage = true;
       case cmPolicies::OLD:
         break;
@@ -180,9 +183,6 @@
       }
     if (issueMessage)
       {
-      cmOStringStream e;
-      e << (this->Makefile->GetPolicies()
-           ->GetPolicyWarning(cmPolicies::CMP0037)) << "\n";
       e << "The target name \"" << targetName <<
           "\" is reserved or not valid for certain "
           "CMake features, such as generator expressions, and may result "
diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx
index 62b6667..3f9400e 100644
--- a/Source/cmAddExecutableCommand.cxx
+++ b/Source/cmAddExecutableCommand.cxx
@@ -79,10 +79,13 @@
   if (!nameOk)
     {
     cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+    cmOStringStream e;
     bool issueMessage = false;
     switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0037))
       {
       case cmPolicies::WARN:
+        e << (this->Makefile->GetPolicies()
+          ->GetPolicyWarning(cmPolicies::CMP0037)) << "\n";
         issueMessage = true;
       case cmPolicies::OLD:
         break;
@@ -94,9 +97,6 @@
       }
     if (issueMessage)
       {
-      cmOStringStream e;
-      e << (this->Makefile->GetPolicies()
-            ->GetPolicyWarning(cmPolicies::CMP0037)) << "\n";
       e << "The target name \"" << exename <<
           "\" is reserved or not valid for certain "
           "CMake features, such as generator expressions, and may result "
diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx
index 009b1ca..e62a40e 100644
--- a/Source/cmAddLibraryCommand.cxx
+++ b/Source/cmAddLibraryCommand.cxx
@@ -214,11 +214,17 @@
   if (!nameOk)
     {
     cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+    cmOStringStream e;
     bool issueMessage = false;
     switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0037))
       {
       case cmPolicies::WARN:
-        issueMessage = type != cmTarget::INTERFACE_LIBRARY;
+        if(type != cmTarget::INTERFACE_LIBRARY)
+          {
+          e << (this->Makefile->GetPolicies()
+            ->GetPolicyWarning(cmPolicies::CMP0037)) << "\n";
+          issueMessage = true;
+          }
       case cmPolicies::OLD:
         break;
       case cmPolicies::NEW:
@@ -229,9 +235,6 @@
       }
     if (issueMessage)
       {
-      cmOStringStream e;
-      e << (this->Makefile->GetPolicies()
-            ->GetPolicyWarning(cmPolicies::CMP0037)) << "\n";
       e << "The target name \"" << libName <<
           "\" is reserved or not valid for certain "
           "CMake features, such as generator expressions, and may result "
diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx
index 7870564..9136869 100644
--- a/Source/cmComputeTargetDepends.cxx
+++ b/Source/cmComputeTargetDepends.cxx
@@ -349,9 +349,12 @@
     cmMakefile *makefile = depender->GetMakefile();
     cmake::MessageType messageType = cmake::AUTHOR_WARNING;
     bool issueMessage = false;
+    cmOStringStream e;
     switch(depender->GetPolicyStatusCMP0046())
       {
       case cmPolicies::WARN:
+        e << (makefile->GetPolicies()
+          ->GetPolicyWarning(cmPolicies::CMP0046)) << "\n";
         issueMessage = true;
       case cmPolicies::OLD:
         break;
@@ -364,9 +367,7 @@
     if(issueMessage)
       {
       cmake* cm = this->GlobalGenerator->GetCMakeInstance();
-      cmOStringStream e;
-      e << (makefile->GetPolicies()
-        ->GetPolicyWarning(cmPolicies::CMP0046)) << "\n";
+
       e << "The dependency target \"" <<  dependee_name
         << "\" of target \"" << depender->GetName() << "\" does not exist.";
 
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 4f3328d..beb10da 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -759,7 +759,8 @@
     switch(mf->GetPolicyStatus(cmPolicies::CMP0025))
       {
       case cmPolicies::WARN:
-        if(!this->CMakeInstance->GetIsInTryCompile())
+        if(!this->CMakeInstance->GetIsInTryCompile() &&
+           mf->PolicyOptionalWarningEnabled("CMAKE_POLICY_WARNING_CMP0025"))
           {
           cmOStringStream w;
           w << policies->GetPolicyWarning(cmPolicies::CMP0025) << "\n"
@@ -790,7 +791,8 @@
     switch(mf->GetPolicyStatus(cmPolicies::CMP0047))
       {
       case cmPolicies::WARN:
-        if(!this->CMakeInstance->GetIsInTryCompile())
+        if(!this->CMakeInstance->GetIsInTryCompile() &&
+           mf->PolicyOptionalWarningEnabled("CMAKE_POLICY_WARNING_CMP0047"))
           {
           cmOStringStream w;
           w << policies->GetPolicyWarning(cmPolicies::CMP0047) << "\n"
diff --git a/Source/cmIncludeCommand.cxx b/Source/cmIncludeCommand.cxx
index e8ee33f..fbcbc75 100644
--- a/Source/cmIncludeCommand.cxx
+++ b/Source/cmIncludeCommand.cxx
@@ -98,11 +98,14 @@
   if (gg->IsExportedTargetsFile(fname_abs))
     {
     const char *modal = 0;
+    cmOStringStream e;
     cmake::MessageType messageType = cmake::AUTHOR_WARNING;
 
     switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0024))
       {
       case cmPolicies::WARN:
+        e << (this->Makefile->GetPolicies()
+          ->GetPolicyWarning(cmPolicies::CMP0024)) << "\n";
         modal = "should";
       case cmPolicies::OLD:
         break;
@@ -114,9 +117,6 @@
       }
     if (modal)
       {
-      cmOStringStream e;
-      e << (this->Makefile->GetPolicies()
-            ->GetPolicyWarning(cmPolicies::CMP0024)) << "\n";
       e << "The file\n  " << fname_abs << "\nwas generated by the export() "
         "command.  It " << modal << " not be used as the argument to the "
         "include() command.  Use ALIAS targets instead to refer to targets "
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 10137ec..27ce999 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -893,9 +893,12 @@
     {
     cmake::MessageType messageType = cmake::AUTHOR_WARNING;
     bool issueMessage = false;
+    cmOStringStream e;
     switch(this->GetPolicyStatus(cmPolicies::CMP0040))
       {
       case cmPolicies::WARN:
+        e << (this->GetPolicies()
+          ->GetPolicyWarning(cmPolicies::CMP0040)) << "\n";
         issueMessage = true;
       case cmPolicies::OLD:
         break;
@@ -908,9 +911,6 @@
 
     if(issueMessage)
       {
-      cmOStringStream e;
-      e << (this->GetPolicies()
-        ->GetPolicyWarning(cmPolicies::CMP0040)) << "\n";
       e << "The target name \"" << target << "\" is unknown in this context.";
       IssueMessage(messageType, e.str().c_str());
       }
@@ -4350,6 +4350,22 @@
   return this->GetPolicies()->GetPolicyStatus(id);
 }
 
+//----------------------------------------------------------------------------
+bool cmMakefile::PolicyOptionalWarningEnabled(std::string const& var)
+{
+  // Check for an explicit CMAKE_POLICY_WARNING_CMP<NNNN> setting.
+  if(!var.empty())
+    {
+    if(const char* val = this->GetDefinition(var.c_str()))
+      {
+      return cmSystemTools::IsOn(val);
+      }
+    }
+  // Enable optional policy warnings with --debug-output or --trace.
+  cmake* cm = this->GetCMakeInstance();
+  return cm->GetDebugOutput() || cm->GetTrace();
+}
+
 bool cmMakefile::SetPolicy(const char *id,
                            cmPolicies::PolicyStatus status)
 {
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 45f3b9f..f00fd20 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -875,6 +875,8 @@
   std::set<cmStdString> const & GetSystemIncludeDirectories() const
     { return this->SystemIncludeDirectories; }
 
+  bool PolicyOptionalWarningEnabled(std::string const& var);
+
 protected:
   // add link libraries and directories to the target
   void AddGlobalLinkInformation(const char* name, cmTarget& target);
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 0c89656..e2a568b 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -2636,11 +2636,14 @@
     {
     return true;
     }
+  cmOStringStream e;
   const char *modal = 0;
   cmake::MessageType messageType = cmake::AUTHOR_WARNING;
   switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0026))
     {
     case cmPolicies::WARN:
+      e << (this->Makefile->GetPolicies()
+        ->GetPolicyWarning(cmPolicies::CMP0026)) << "\n";
       modal = "should";
     case cmPolicies::OLD:
       break;
@@ -2653,9 +2656,6 @@
 
   if (modal)
     {
-    cmOStringStream e;
-    e << (this->Makefile->GetPolicies()
-          ->GetPolicyWarning(cmPolicies::CMP0026)) << "\n";
     e << "The LOCATION property " << modal << " not be read from target \""
       << this->GetName() << "\".  Use the target name directly with "
       "add_custom_command, or use the generator expression $<TARGET_FILE>, "
diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx
index 02da933..95a2cba 100644
--- a/Source/cmTargetLinkLibrariesCommand.cxx
+++ b/Source/cmTargetLinkLibrariesCommand.cxx
@@ -103,11 +103,14 @@
 
   if (this->Target->GetType() == cmTarget::UTILITY)
     {
+    cmOStringStream e;
     const char *modal = 0;
     cmake::MessageType messageType = cmake::AUTHOR_WARNING;
     switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0039))
       {
       case cmPolicies::WARN:
+        e << this->Makefile->GetPolicies()
+          ->GetPolicyWarning(cmPolicies::CMP0039) << "\n";
         modal = "should";
       case cmPolicies::OLD:
         break;
@@ -119,9 +122,7 @@
       }
     if (modal)
       {
-      cmOStringStream e;
-      e << this->Makefile->GetPolicies()
-                            ->GetPolicyWarning(cmPolicies::CMP0039) << "\n"
+      e <<
         "Utility target \"" << this->Target->GetName() << "\" " << modal
         << " not be used as the target of a target_link_libraries call.";
       this->Makefile->IssueMessage(messageType, e.str().c_str());
@@ -373,11 +374,14 @@
         ? cmTarget::KeywordTLLSignature : cmTarget::PlainTLLSignature;
   if (!this->Target->PushTLLCommandTrace(sig))
     {
+    cmOStringStream e;
     const char *modal = 0;
     cmake::MessageType messageType = cmake::AUTHOR_WARNING;
     switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0023))
       {
       case cmPolicies::WARN:
+        e << this->Makefile->GetPolicies()
+          ->GetPolicyWarning(cmPolicies::CMP0023) << "\n";
         modal = "should";
       case cmPolicies::OLD:
         break;
@@ -390,14 +394,12 @@
 
       if(modal)
         {
-        cmOStringStream e;
         // If the sig is a keyword form and there is a conflict, the existing
         // form must be the plain form.
         const char *existingSig
                     = (sig == cmTarget::KeywordTLLSignature ? "plain"
                                                             : "keyword");
-        e << this->Makefile->GetPolicies()
-                              ->GetPolicyWarning(cmPolicies::CMP0023) << "\n"
+          e <<
             "The " << existingSig << " signature for target_link_libraries "
             "has already been used with the target \""
           << this->Target->GetName() << "\".  All uses of "
diff --git a/Templates/TestDriver.cxx.in b/Templates/TestDriver.cxx.in
index 82537ef..0e0a872 100644
--- a/Templates/TestDriver.cxx.in
+++ b/Templates/TestDriver.cxx.in
@@ -58,7 +58,7 @@
 
 int main(int ac, char *av[])
 {
-  int i, NumTests, testNum, partial_match;
+  int i, NumTests, testNum = 0, partial_match;
   char *arg, *test_name;
   int count;
   int testToRun = -1;
@@ -81,7 +81,6 @@
       }
     printf("To run a test, enter the test number: ");
     fflush(stdout);
-    testNum = 0;
     if( scanf("%d", &testNum) != 1 )
       {
       printf("Couldn't parse that input as a number\n");
diff --git a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-stderr.txt
index 07982bd..05b0217 100644
--- a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-stderr.txt
+++ b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-stderr.txt
@@ -1,8 +1,4 @@
 CMake Error at CMP0026-CONFIG-LOCATION-NEW.cmake:7 \(get_target_property\):
-  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
-  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
-  command to set the policy and suppress this warning.
-
   The LOCATION property may not be read from target "somelib".  Use the
   target name directly with add_custom_command, or use the generator
   expression \$<TARGET_FILE>, as appropriate.
diff --git a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-stderr.txt
index 0e90f96..fec9dfb 100644
--- a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-stderr.txt
+++ b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-stderr.txt
@@ -1,8 +1,4 @@
 CMake Error at CMP0026-LOCATION-CONFIG-NEW.cmake:7 \(get_target_property\):
-  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
-  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
-  command to set the policy and suppress this warning.
-
   The LOCATION property may not be read from target "somelib".  Use the
   target name directly with add_custom_command, or use the generator
   expression \$<TARGET_FILE>, as appropriate.
diff --git a/Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt
index 2a05a4d..fa02512 100644
--- a/Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt
+++ b/Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt
@@ -1,8 +1,4 @@
 CMake Error at CMP0026-NEW.cmake:7 \(get_target_property\):
-  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
-  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
-  command to set the policy and suppress this warning.
-
   The LOCATION property may not be read from target "somelib".  Use the
   target name directly with add_custom_command, or use the generator
   expression \$<TARGET_FILE>, as appropriate.
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-colon-stderr.txt b/Tests/RunCMake/CMP0037/CMP0037-NEW-colon-stderr.txt
index 9d2c35b..ec2315f 100644
--- a/Tests/RunCMake/CMP0037/CMP0037-NEW-colon-stderr.txt
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-colon-stderr.txt
@@ -1,9 +1,4 @@
 CMake Error at CMP0037-NEW-colon.cmake:4 \(add_library\):
-  Policy CMP0037 is not set: Target names should not be reserved and should
-  match a validity pattern.  Run "cmake --help-policy CMP0037" for policy
-  details.  Use the cmake_policy command to set the policy and suppress this
-  warning.
-
   The target name "lib:colon" is reserved or not valid for certain CMake
   features, such as generator expressions, and may result in undefined
   behavior.
@@ -11,11 +6,6 @@
   CMakeLists.txt:3 \(include\)
 +
 CMake Error at CMP0037-NEW-colon.cmake:5 \(add_executable\):
-  Policy CMP0037 is not set: Target names should not be reserved and should
-  match a validity pattern.  Run "cmake --help-policy CMP0037" for policy
-  details.  Use the cmake_policy command to set the policy and suppress this
-  warning.
-
   The target name "exe:colon" is reserved or not valid for certain CMake
   features, such as generator expressions, and may result in undefined
   behavior.
@@ -23,11 +13,6 @@
   CMakeLists.txt:3 \(include\)
 +
 CMake Error at CMP0037-NEW-colon.cmake:6 \(add_custom_target\):
-  Policy CMP0037 is not set: Target names should not be reserved and should
-  match a validity pattern.  Run "cmake --help-policy CMP0037" for policy
-  details.  Use the cmake_policy command to set the policy and suppress this
-  warning.
-
   The target name "custom:colon" is reserved or not valid for certain CMake
   features, such as generator expressions, and may result in undefined
   behavior.
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved-stderr.txt b/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved-stderr.txt
index 13835af..5789e38 100644
--- a/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved-stderr.txt
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved-stderr.txt
@@ -1,20 +1,10 @@
 CMake Error at CMP0037-NEW-reserved.cmake:4 \(add_library\):
-  Policy CMP0037 is not set: Target names should not be reserved and should
-  match a validity pattern.  Run "cmake --help-policy CMP0037" for policy
-  details.  Use the cmake_policy command to set the policy and suppress this
-  warning.
-
   The target name "all" is reserved or not valid for certain CMake features,
   such as generator expressions, and may result in undefined behavior.
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
 +
 CMake Error at CMP0037-NEW-reserved.cmake:5 \(add_executable\):
-  Policy CMP0037 is not set: Target names should not be reserved and should
-  match a validity pattern.  Run "cmake --help-policy CMP0037" for policy
-  details.  Use the cmake_policy command to set the policy and suppress this
-  warning.
-
   The target name "clean" is reserved or not valid for certain CMake
   features, such as generator expressions, and may result in undefined
   behavior.
@@ -22,11 +12,6 @@
   CMakeLists.txt:3 \(include\)
 +
 CMake Error at CMP0037-NEW-reserved.cmake:6 \(add_custom_target\):
-  Policy CMP0037 is not set: Target names should not be reserved and should
-  match a validity pattern.  Run "cmake --help-policy CMP0037" for policy
-  details.  Use the cmake_policy command to set the policy and suppress this
-  warning.
-
   The target name "help" is reserved or not valid for certain CMake features,
   such as generator expressions, and may result in undefined behavior.
 Call Stack \(most recent call first\):
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-space-stderr.txt b/Tests/RunCMake/CMP0037/CMP0037-NEW-space-stderr.txt
index 2525bcd..e14cec0 100644
--- a/Tests/RunCMake/CMP0037/CMP0037-NEW-space-stderr.txt
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-space-stderr.txt
@@ -1,9 +1,4 @@
 CMake Error at CMP0037-NEW-space.cmake:4 \(add_library\):
-  Policy CMP0037 is not set: Target names should not be reserved and should
-  match a validity pattern.  Run "cmake --help-policy CMP0037" for policy
-  details.  Use the cmake_policy command to set the policy and suppress this
-  warning.
-
   The target name "lib with spaces" is reserved or not valid for certain
   CMake features, such as generator expressions, and may result in undefined
   behavior.
@@ -11,11 +6,6 @@
   CMakeLists.txt:3 \(include\)
 +
 CMake Error at CMP0037-NEW-space.cmake:5 \(add_executable\):
-  Policy CMP0037 is not set: Target names should not be reserved and should
-  match a validity pattern.  Run "cmake --help-policy CMP0037" for policy
-  details.  Use the cmake_policy command to set the policy and suppress this
-  warning.
-
   The target name "exe with spaces" is reserved or not valid for certain
   CMake features, such as generator expressions, and may result in undefined
   behavior.
@@ -23,11 +13,6 @@
   CMakeLists.txt:3 \(include\)
 +
 CMake Error at CMP0037-NEW-space.cmake:6 \(add_custom_target\):
-  Policy CMP0037 is not set: Target names should not be reserved and should
-  match a validity pattern.  Run "cmake --help-policy CMP0037" for policy
-  details.  Use the cmake_policy command to set the policy and suppress this
-  warning.
-
   The target name "custom with spaces" is reserved or not valid for certain
   CMake features, such as generator expressions, and may result in undefined
   behavior.
diff --git a/Tests/RunCMake/CMP0039/CMP0039-NEW-stderr.txt b/Tests/RunCMake/CMP0039/CMP0039-NEW-stderr.txt
index 821c4f8..3d9d225 100644
--- a/Tests/RunCMake/CMP0039/CMP0039-NEW-stderr.txt
+++ b/Tests/RunCMake/CMP0039/CMP0039-NEW-stderr.txt
@@ -1,8 +1,4 @@
 CMake Error at CMP0039-NEW.cmake:7 \(target_link_libraries\):
-  Policy CMP0039 is not set: Utility targets may not have link dependencies.
-  Run "cmake --help-policy CMP0039" for policy details.  Use the cmake_policy
-  command to set the policy and suppress this warning.
-
   Utility target "utility" must not be used as the target of a
   target_link_libraries call.
 Call Stack \(most recent call first\):
diff --git a/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt b/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt
index 03a0217..3f82d8c 100644
--- a/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt
+++ b/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt
@@ -1,9 +1,4 @@
 CMake Error at CMP0040-NEW-missing-target.cmake:3 \(add_custom_command\):
-  Policy CMP0040 is not set: The target in the TARGET signature of
-  add_custom_command\(\) must exist.  Run "cmake --help-policy CMP0040" for
-  policy details.  Use the cmake_policy command to set the policy and
-  suppress this warning.
-+
   The target name "foobar" is unknown in this context.
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency-stderr.txt b/Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency-stderr.txt
index 0c23c43..381647f 100644
--- a/Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency-stderr.txt
+++ b/Tests/RunCMake/CMP0046/CMP0046-NEW-missing-dependency-stderr.txt
@@ -1,8 +1,4 @@
 CMake Error at CMP0046-NEW-missing-dependency.cmake:4 \(add_dependencies\):
-  Policy CMP0046 is not set: Error on non-existent dependency in
-  add_dependencies.  Run "cmake --help-policy CMP0046" for policy details.
-  Use the cmake_policy command to set the policy and suppress this warning.
-+
   The dependency target "bar" of target "foo" does not exist.
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/include/CMP0024-NEW-stderr.txt b/Tests/RunCMake/include/CMP0024-NEW-stderr.txt
index 059d7e4..0fdb3ca 100644
--- a/Tests/RunCMake/include/CMP0024-NEW-stderr.txt
+++ b/Tests/RunCMake/include/CMP0024-NEW-stderr.txt
@@ -1,8 +1,4 @@
 CMake Error at subdir2/CMakeLists.txt:2 \(include\):
-  Policy CMP0024 is not set: Disallow include export result.  Run "cmake
-  --help-policy CMP0024" for policy details.  Use the cmake_policy command to
-  set the policy and suppress this warning.
-
   The file
 
     .*/Tests/RunCMake/include/CMP0024-NEW-build/subdir1/theTargets.cmake
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-stderr.txt b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-stderr.txt
index d27686d..8e3f315 100644
--- a/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-stderr.txt
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-stderr.txt
@@ -1,9 +1,4 @@
 CMake Error at CMP0023-NEW-2.cmake:11 \(target_link_libraries\):
-  Policy CMP0023 is not set: Plain and keyword target_link_libraries
-  signatures cannot be mixed.  Run "cmake --help-policy CMP0023" for policy
-  details.  Use the cmake_policy command to set the policy and suppress this
-  warning.
-
   The plain signature for target_link_libraries has already been used with
   the target "foo".  All uses of target_link_libraries with a target must be
   either all-keyword or all-plain.
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-NEW-stderr.txt b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-stderr.txt
index d7be0ff..2ef2290 100644
--- a/Tests/RunCMake/target_link_libraries/CMP0023-NEW-stderr.txt
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-stderr.txt
@@ -1,9 +1,4 @@
 CMake Error at CMP0023-NEW.cmake:11 \(target_link_libraries\):
-  Policy CMP0023 is not set: Plain and keyword target_link_libraries
-  signatures cannot be mixed.  Run "cmake --help-policy CMP0023" for policy
-  details.  Use the cmake_policy command to set the policy and suppress this
-  warning.
-
   The plain signature for target_link_libraries has already been used with
   the target "foo".  All uses of target_link_libraries with a target must be
   either all-keyword or all-plain.