[Pkg-cmake-commits] [cmake] 03/07: Imported Upstream version 3.5.0

Felix Geyer fgeyer at moszumanska.debian.org
Sun Mar 13 17:00:26 UTC 2016


This is an automated email from the git hooks/post-receive script.

fgeyer pushed a commit to branch master
in repository cmake.

commit 4a69966b600359abc4b043a0c8ccce1410ffdf4e
Author: Felix Geyer <fgeyer at debian.org>
Date:   Sun Mar 13 13:35:51 2016 +0100

    Imported Upstream version 3.5.0
---
 Auxiliary/cmake-mode.el                            |    2 +-
 CMakeCPack.cmake                                   |   11 +
 CMakeCPackOptions.cmake.in                         |   62 +-
 CMakeLists.txt                                     |   31 +-
 CTestCustom.cmake.in                               |    5 +-
 Copyright.txt                                      |    2 +-
 Help/command/add_custom_command.rst                |    7 +-
 Help/command/cmake_minimum_required.rst            |    2 +-
 Help/command/cmake_parse_arguments.rst             |   85 +
 Help/command/get_target_property.rst               |    2 +-
 Help/command/if.rst                                |    9 +-
 Help/command/install.rst                           |   26 +-
 Help/manual/OPTIONS_BUILD.txt                      |   41 +-
 Help/manual/cmake-buildsystem.7.rst                |   11 +-
 Help/manual/cmake-commands.7.rst                   |    1 +
 Help/manual/cmake-developer.7.rst                  |    2 +-
 Help/manual/cmake-modules.7.rst                    |    1 +
 Help/manual/cmake-packages.7.rst                   |   10 +-
 Help/manual/cmake-properties.7.rst                 |    1 +
 Help/manual/cmake-toolchains.7.rst                 |   30 +
 Help/manual/cmake-variables.7.rst                  |    2 +
 Help/manual/cmake.1.rst                            |   42 +-
 Help/module/FindXalanC.rst                         |    1 +
 Help/policy/CMP0040.rst                            |   19 +-
 Help/prop_dir/CLEAN_NO_CUSTOM.rst                  |    7 +-
 Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst           |   34 +-
 Help/prop_tgt/BUNDLE.rst                           |    6 +-
 Help/prop_tgt/BUNDLE_EXTENSION.rst                 |    4 +-
 Help/prop_tgt/ENABLE_EXPORTS.rst                   |    4 +-
 Help/prop_tgt/FRAMEWORK.rst                        |   28 +-
 Help/prop_tgt/FRAMEWORK_VERSION.rst                |    3 +
 Help/prop_tgt/IOS_INSTALL_COMBINED.rst             |   11 +
 Help/prop_tgt/MACOSX_BUNDLE.rst                    |   16 +-
 Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst         |    4 +-
 Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst      |    4 +-
 Help/prop_tgt/MACOSX_RPATH.rst                     |   21 +-
 Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst         |    2 +-
 Help/prop_tgt/PRIVATE_HEADER.rst                   |   10 +-
 Help/prop_tgt/PUBLIC_HEADER.rst                    |   12 +-
 Help/prop_tgt/RESOURCE.rst                         |   66 +-
 Help/release/3.5.rst                               |  185 ++
 Help/release/index.rst                             |    1 +
 Help/variable/APPLE.rst                            |    4 +-
 Help/variable/CMAKE_BINARY_DIR.rst                 |    5 +
 Help/variable/CMAKE_CURRENT_BINARY_DIR.rst         |    5 +
 Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst         |    5 +
 Help/variable/CMAKE_ENABLE_EXPORTS.rst             |    8 +-
 Help/variable/CMAKE_ERROR_DEPRECATED.rst           |    7 +-
 Help/variable/CMAKE_EXPORT_COMPILE_COMMANDS.rst    |   30 +
 Help/variable/CMAKE_HOST_SYSTEM_NAME.rst           |    2 +-
 Help/variable/CMAKE_INSTALL_NAME_DIR.rst           |    2 +-
 Help/variable/CMAKE_IOS_INSTALL_COMBINED.rst       |    8 +
 Help/variable/CMAKE_LANG_COMPILER_ID.rst           |    1 +
 Help/variable/CMAKE_MACOSX_RPATH.rst               |    2 +-
 Help/variable/CMAKE_OSX_ARCHITECTURES.rst          |    2 +-
 Help/variable/CMAKE_SOURCE_DIR.rst                 |    5 +
 .../CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION.rst   |    3 +-
 Help/variable/CMAKE_WARN_DEPRECATED.rst            |    9 +-
 .../CMAKE_XCODE_ATTRIBUTE_an-attribute.rst         |    6 +
 Modules/BundleUtilities.cmake                      |    4 +-
 Modules/CMakeCCompiler.cmake.in                    |    1 +
 Modules/CMakeCCompilerId.c.in                      |    7 +
 Modules/CMakeCInformation.cmake                    |    8 +
 Modules/CMakeCXXCompiler.cmake.in                  |    1 +
 Modules/CMakeCXXCompilerId.cpp.in                  |    7 +
 Modules/CMakeCXXInformation.cmake                  |    8 +
 Modules/CMakeCompilerIdDetection.cmake             |    1 +
 Modules/CMakeDetermineASMCompiler.cmake            |    4 +
 Modules/CMakeDetermineCompilerId.cmake             |    9 +-
 Modules/CMakeDetermineFortranCompiler.cmake        |    2 +
 Modules/CMakeForceCompiler.cmake                   |   24 +-
 Modules/CMakeFortranCompiler.cmake.in              |    1 +
 Modules/CMakeFortranCompilerId.F.in                |    3 +
 Modules/CMakeFortranInformation.cmake              |    8 +
 Modules/CMakeIOSInstallCombined.cmake              |  297 +++
 Modules/CMakeLanguageInformation.cmake             |   37 +
 Modules/CMakeParseArguments.cmake                  |  148 +-
 Modules/CPack.cmake                                |    2 +-
 Modules/CPackDMG.cmake                             |   51 +-
 Modules/CPackDeb.cmake                             |  105 +-
 Modules/CPackNSIS.cmake                            |    8 +
 Modules/CPackRPM.cmake                             |   39 +-
 Modules/CPackWIX.cmake                             |    3 +-
 Modules/CheckCSourceCompiles.cmake                 |    2 +-
 Modules/CheckCSourceRuns.cmake                     |    2 +-
 Modules/CheckCXXSourceCompiles.cmake               |    2 +-
 Modules/CheckCXXSourceRuns.cmake                   |    2 +-
 Modules/CheckForPthreads.c                         |    4 +-
 Modules/CheckFortranSourceCompiles.cmake           |    2 +-
 Modules/Compiler/ARMCC-ASM.cmake                   |    7 +
 Modules/Compiler/ARMCC-C.cmake                     |    2 +
 Modules/Compiler/ARMCC-CXX.cmake                   |    2 +
 Modules/Compiler/ARMCC-DetermineCompiler.cmake     |   16 +
 Modules/Compiler/ARMCC.cmake                       |   36 +
 Modules/Compiler/Clang-CXX.cmake                   |    4 +-
 Modules/Compiler/CrayPrgEnv-C.cmake                |   11 +
 Modules/Compiler/CrayPrgEnv-CXX.cmake              |   11 +
 Modules/Compiler/CrayPrgEnv-Cray-C.cmake           |    7 +
 Modules/Compiler/CrayPrgEnv-Cray-CXX.cmake         |    7 +
 Modules/Compiler/CrayPrgEnv-Cray-Fortran.cmake     |    7 +
 Modules/Compiler/CrayPrgEnv-Fortran.cmake          |   11 +
 Modules/Compiler/CrayPrgEnv-GNU-C.cmake            |    7 +
 Modules/Compiler/CrayPrgEnv-GNU-CXX.cmake          |    7 +
 Modules/Compiler/CrayPrgEnv-GNU-Fortran.cmake      |    7 +
 Modules/Compiler/CrayPrgEnv-Intel-C.cmake          |    7 +
 Modules/Compiler/CrayPrgEnv-Intel-CXX.cmake        |    7 +
 Modules/Compiler/CrayPrgEnv-Intel-Fortran.cmake    |    7 +
 Modules/Compiler/CrayPrgEnv-PGI-C.cmake            |    7 +
 Modules/Compiler/CrayPrgEnv-PGI-CXX.cmake          |    7 +
 Modules/Compiler/CrayPrgEnv-PGI-Fortran.cmake      |    7 +
 Modules/Compiler/CrayPrgEnv.cmake                  |   91 +
 .../Compiler/Embarcadero-DetermineCompiler.cmake   |    2 +-
 Modules/ExternalProject.cmake                      |   47 +-
 Modules/FindBLAS.cmake                             |   12 +-
 Modules/FindBoost.cmake                            |  402 +++-
 Modules/FindCUDA.cmake                             |   25 +-
 Modules/FindDCMTK.cmake                            |  275 ++-
 Modules/FindFLEX.cmake                             |   87 +-
 Modules/FindGTK2.cmake                             |   69 +
 Modules/FindGTest.cmake                            |  160 +-
 Modules/FindGit.cmake                              |   32 +-
 Modules/FindJNI.cmake                              |    6 +-
 Modules/FindJava.cmake                             |    6 +-
 Modules/FindOpenAL.cmake                           |    9 +-
 Modules/FindOpenGL.cmake                           |   12 +-
 Modules/FindOpenMP.cmake                           |    3 +
 Modules/FindOpenSSL.cmake                          |   27 +-
 Modules/FindPNG.cmake                              |   50 +-
 Modules/FindPkgConfig.cmake                        |   20 +-
 Modules/FindProtobuf.cmake                         |    2 +-
 Modules/FindPythonInterp.cmake                     |    7 +-
 Modules/FindPythonLibs.cmake                       |    7 +-
 Modules/FindTIFF.cmake                             |   67 +-
 Modules/FindXalanC.cmake                           |  162 ++
 Modules/FindXercesC.cmake                          |   67 +-
 Modules/FindwxWidgets.cmake                        |   12 -
 Modules/GenerateExportHeader.cmake                 |    4 +
 Modules/GetPrerequisites.cmake                     |    4 +-
 Modules/NSIS.template.in                           |    2 +
 Modules/Platform/AIX-GNU.cmake                     |   12 +-
 Modules/Platform/AIX-XL.cmake                      |   12 +-
 Modules/Platform/CrayLinuxEnvironment.cmake        |  143 ++
 Modules/Platform/HP-UX-GNU.cmake                   |    4 +-
 Modules/Platform/HP-UX-HP.cmake                    |    4 +-
 Modules/Platform/SunOS.cmake                       |    6 -
 Modules/Platform/Windows-Embarcadero.cmake         |    6 +-
 Modules/Platform/Windows-MSVC.cmake                |    2 +
 Modules/Platform/WindowsPaths.cmake                |   52 +-
 Modules/UseJava.cmake                              |    8 +-
 Packaging/CMakeDMGBackground.tif                   |  Bin 0 -> 95690 bytes
 Packaging/CMakeDMGSetup.scpt                       |   42 +
 README.rst                                         |    2 +-
 Source/CMakeInstallDestinations.cmake              |    5 +
 Source/CMakeLists.txt                              |   19 +-
 Source/CMakeVersion.cmake                          |    4 +-
 Source/CPack/IFW/cmCPackIFWGenerator.cxx           |    1 -
 Source/CPack/WiX/cmCPackWIXGenerator.cxx           |   37 +-
 Source/CPack/WiX/cmCPackWIXGenerator.h             |    3 +
 Source/CPack/WiX/cmWIXPatch.cxx                    |   44 +-
 Source/CPack/WiX/cmWIXPatch.h                      |    5 +-
 Source/CPack/WiX/cmWIXPatchParser.cxx              |   52 +-
 Source/CPack/WiX/cmWIXPatchParser.h                |   29 +-
 Source/CPack/WiX/cmWIXSourceWriter.cxx             |   19 +
 Source/CPack/WiX/cmWIXSourceWriter.h               |    2 +
 Source/CPack/cmCPackArchiveGenerator.cxx           |    1 -
 Source/CPack/cmCPackCygwinBinaryGenerator.cxx      |    1 -
 Source/CPack/cmCPackCygwinSourceGenerator.cxx      |    1 -
 Source/CPack/cmCPackDebGenerator.cxx               |    7 +
 Source/CPack/cmCPackDragNDropGenerator.cxx         |  542 ++++-
 Source/CPack/cmCPackDragNDropGenerator.h           |   15 +
 Source/CPack/cmCPackGenerator.cxx                  |    4 +-
 Source/CPack/cmCPackNSISGenerator.cxx              |   23 +-
 Source/CPack/cmCPackOSXX11Generator.cxx            |    1 -
 Source/CPack/cmCPackPackageMakerGenerator.cxx      |    1 -
 Source/CPack/cmCPackSTGZGenerator.cxx              |    1 -
 Source/CPack/cpack.cxx                             |    4 +-
 Source/CTest/cmCTestBuildHandler.cxx               |    1 -
 Source/CTest/cmCTestCoverageHandler.cxx            |   48 +-
 Source/CTest/cmCTestLaunch.cxx                     |    4 +-
 Source/CTest/cmCTestScriptHandler.cxx              |   24 +-
 Source/CTest/cmCTestScriptHandler.h                |    2 -
 Source/CTest/cmCTestStartCommand.cxx               |    1 -
 Source/CTest/cmCTestTestHandler.cxx                |   10 +-
 Source/CTest/cmCTestUpdateHandler.cxx              |    1 -
 Source/QtDialog/CMakeLists.txt                     |   14 +-
 Source/QtDialog/CMakeSetupDialog.cxx               |   26 +-
 Source/QtDialog/CMakeSetupDialog.h                 |    4 +-
 Source/QtDialog/FirstConfigure.cxx                 |   70 +-
 Source/QtDialog/FirstConfigure.h                   |   15 +-
 Source/QtDialog/QCMake.cxx                         |   74 +-
 Source/QtDialog/QCMake.h                           |   28 +-
 Source/QtDialog/RegexExplorer.cxx                  |  166 ++
 Source/QtDialog/RegexExplorer.h                    |   48 +
 Source/QtDialog/RegexExplorer.ui                   |  155 ++
 Source/QtDialog/WarningMessagesDialog.cxx          |   99 +
 Source/QtDialog/WarningMessagesDialog.h            |   75 +
 Source/QtDialog/WarningMessagesDialog.ui           |  173 ++
 Source/bindexplib.cxx                              |   61 +-
 .../KWIML/test/test_INT_C.c => Source/bindexplib.h |   31 +-
 Source/cmAddDependenciesCommand.cxx                |    1 -
 Source/cmAddExecutableCommand.cxx                  |    8 +-
 Source/cmAddLibraryCommand.cxx                     |   66 +-
 Source/cmAlgorithms.h                              |   10 +-
 Source/cmArchiveWrite.cxx                          |    4 +
 Source/cmAuxSourceDirectoryCommand.cxx             |    8 +-
 Source/cmBootstrapCommands1.cxx                    |    2 +
 Source/cmBuildCommand.cxx                          |    1 -
 Source/cmCPackPropertiesGenerator.cxx              |    4 +-
 Source/cmCPluginAPI.cxx                            |   18 +-
 Source/cmCTest.cxx                                 |    3 +-
 Source/cmCacheManager.cxx                          |  107 +-
 Source/cmCacheManager.h                            |   13 +-
 Source/cmCommonTargetGenerator.cxx                 |   41 +-
 Source/cmCommonTargetGenerator.h                   |    4 +-
 Source/cmComputeLinkDepends.cxx                    |   50 +-
 Source/cmComputeLinkDepends.h                      |   17 +-
 Source/cmComputeLinkInformation.cxx                |  124 +-
 Source/cmComputeLinkInformation.h                  |   17 +-
 Source/cmComputeTargetDepends.cxx                  |   65 +-
 Source/cmConditionEvaluator.cxx                    |   10 +
 Source/cmCoreTryCompile.cxx                        |   19 +-
 Source/cmCurl.cxx                                  |    5 +
 Source/cmCustomCommandGenerator.cxx                |   15 +-
 Source/cmDependsFortran.cxx                        |    2 +-
 Source/cmELF.cxx                                   |   12 +-
 Source/cmEnableTestingCommand.cxx                  |    1 -
 Source/cmExportBuildFileGenerator.cxx              |   98 +-
 Source/cmExportBuildFileGenerator.h                |   19 +-
 Source/cmExportCommand.cxx                         |    7 +-
 Source/cmExportFileGenerator.cxx                   |  160 +-
 Source/cmExportFileGenerator.h                     |   33 +-
 Source/cmExportInstallFileGenerator.cxx            |   67 +-
 Source/cmExportInstallFileGenerator.h              |   11 +-
 Source/cmExportLibraryDependenciesCommand.cxx      |   10 +-
 Source/cmExportSet.cxx                             |   10 +
 Source/cmExportSet.h                               |    3 +
 Source/cmExportTryCompileFileGenerator.cxx         |   63 +-
 Source/cmExportTryCompileFileGenerator.h           |   22 +-
 Source/cmExtraCodeBlocksGenerator.cxx              |  144 +-
 Source/cmExtraCodeBlocksGenerator.h                |   10 +-
 Source/cmExtraCodeLiteGenerator.cxx                |   64 +-
 Source/cmExtraEclipseCDT4Generator.cxx             |  144 +-
 Source/cmExtraEclipseCDT4Generator.h               |    2 +-
 Source/cmExtraKateGenerator.cxx                    |   96 +-
 Source/cmExtraKateGenerator.h                      |   11 +-
 Source/cmExtraSublimeTextGenerator.cxx             |   77 +-
 Source/cmExtraSublimeTextGenerator.h               |    6 +-
 Source/cmFLTKWrapUICommand.cxx                     |   39 -
 Source/cmFileCommand.cxx                           |    5 +-
 Source/cmFileTimeComparison.cxx                    |   39 +-
 Source/cmFindPackageCommand.h                      |    2 +-
 Source/cmFortranLexer.cxx                          |  592 ++---
 Source/cmFortranLexer.h                            |   16 +-
 Source/cmFortranLexer.in.l                         |    3 +-
 Source/cmFortranParser.cxx                         |  473 ++--
 Source/cmFortranParser.h                           |    2 +
 Source/cmFortranParser.y                           |   10 +-
 Source/cmFortranParserImpl.cxx                     |   26 +
 Source/cmFortranParserTokens.h                     |  108 +-
 Source/cmFunctionBlocker.h                         |    2 +-
 Source/cmGeneratorExpression.cxx                   |   24 +-
 Source/cmGeneratorExpression.h                     |   32 +-
 Source/cmGeneratorExpressionContext.cxx            |    9 +-
 Source/cmGeneratorExpressionContext.h              |   27 +-
 Source/cmGeneratorExpressionDAGChecker.cxx         |    8 +-
 Source/cmGeneratorExpressionEvaluationFile.cxx     |   10 +-
 Source/cmGeneratorExpressionEvaluator.h            |    6 +-
 Source/cmGeneratorExpressionNode.cxx               |  146 +-
 Source/cmGeneratorExpressionNode.h                 |    7 +-
 Source/cmGeneratorExpressionParser.h               |    2 -
 Source/cmGeneratorTarget.cxx                       | 2261 +++++++++++++++++---
 Source/cmGeneratorTarget.h                         |  264 ++-
 Source/cmGetCMakePropertyCommand.cxx               |    1 -
 Source/cmGetPropertyCommand.cxx                    |    1 -
 Source/cmGhsMultiTargetGenerator.cxx               |   99 +-
 Source/cmGhsMultiTargetGenerator.h                 |   15 +-
 Source/cmGlobalGenerator.cxx                       |  376 ++--
 Source/cmGlobalGenerator.h                         |   82 +-
 Source/cmGlobalGeneratorFactory.h                  |    6 +
 Source/cmGlobalGhsMultiGenerator.cxx               |   21 +-
 Source/cmGlobalGhsMultiGenerator.h                 |   11 +-
 Source/cmGlobalKdevelopGenerator.cxx               |   32 +-
 Source/cmGlobalNinjaGenerator.cxx                  |   96 +-
 Source/cmGlobalNinjaGenerator.h                    |   25 +-
 Source/cmGlobalUnixMakefileGenerator3.cxx          |  201 +-
 Source/cmGlobalUnixMakefileGenerator3.h            |   14 +-
 Source/cmGlobalVisualStudio10Generator.cxx         |   26 +-
 Source/cmGlobalVisualStudio10Generator.h           |    6 +-
 Source/cmGlobalVisualStudio11Generator.cxx         |    8 +-
 Source/cmGlobalVisualStudio11Generator.h           |    2 +-
 Source/cmGlobalVisualStudio12Generator.cxx         |    2 +
 Source/cmGlobalVisualStudio14Generator.cxx         |   53 +-
 Source/cmGlobalVisualStudio14Generator.h           |    2 +-
 Source/cmGlobalVisualStudio6Generator.cxx          |   29 +-
 Source/cmGlobalVisualStudio6Generator.h            |   12 +-
 Source/cmGlobalVisualStudio71Generator.cxx         |   14 +-
 Source/cmGlobalVisualStudio71Generator.h           |    6 +-
 Source/cmGlobalVisualStudio7Generator.cxx          |   70 +-
 Source/cmGlobalVisualStudio7Generator.h            |   21 +-
 Source/cmGlobalVisualStudio8Generator.cxx          |   60 +-
 Source/cmGlobalVisualStudio8Generator.h            |   11 +-
 Source/cmGlobalVisualStudio9Generator.cxx          |    2 +
 Source/cmGlobalVisualStudioGenerator.cxx           |  123 +-
 Source/cmGlobalVisualStudioGenerator.h             |   34 +-
 Source/cmGlobalXCodeGenerator.cxx                  |  808 +++----
 Source/cmGlobalXCodeGenerator.h                    |   55 +-
 Source/cmGraphVizWriter.cxx                        |   73 +-
 Source/cmGraphVizWriter.h                          |    9 +-
 Source/cmIDEFlagTable.h                            |    1 +
 Source/cmIDEOptions.cxx                            |   10 +-
 Source/cmIfCommand.cxx                             |    1 +
 Source/cmIncludeExternalMSProjectCommand.cxx       |    2 +-
 Source/cmInstallCommand.cxx                        |   37 +-
 Source/cmInstallDirectoryGenerator.cxx             |   31 +-
 Source/cmInstallDirectoryGenerator.h               |    3 +-
 Source/cmInstallExportGenerator.cxx                |    3 +-
 Source/cmInstallFilesGenerator.cxx                 |    4 +-
 Source/cmInstallTargetGenerator.cxx                |  158 +-
 Source/cmInstallTargetGenerator.h                  |    5 +-
 Source/cmLinkItem.h                                |   34 +-
 Source/cmLinkLibrariesCommand.cxx                  |    4 +-
 Source/cmListFileCache.cxx                         |    2 +-
 Source/cmListFileCache.h                           |    9 -
 Source/cmLocalGenerator.cxx                        |  314 ++-
 Source/cmLocalGenerator.h                          |   75 +-
 Source/cmLocalGhsMultiGenerator.cxx                |   11 +-
 Source/cmLocalNinjaGenerator.cxx                   |   46 +-
 Source/cmLocalNinjaGenerator.h                     |   12 +-
 Source/cmLocalUnixMakefileGenerator3.cxx           |  188 +-
 Source/cmLocalUnixMakefileGenerator3.h             |   34 +-
 Source/cmLocalVisualStudio10Generator.cxx          |   14 +-
 Source/cmLocalVisualStudio6Generator.cxx           |  388 ++--
 Source/cmLocalVisualStudio6Generator.h             |   32 +-
 Source/cmLocalVisualStudio7Generator.cxx           |  322 ++-
 Source/cmLocalVisualStudio7Generator.h             |   38 +-
 Source/cmLocalVisualStudioGenerator.cxx            |   12 +-
 Source/cmLocalVisualStudioGenerator.h              |    6 +-
 Source/cmLocalXCodeGenerator.cxx                   |   16 +-
 Source/cmLocalXCodeGenerator.h                     |    3 +-
 Source/cmMacroCommand.cxx                          |   16 +-
 Source/cmMakeDepend.cxx                            |  361 ----
 Source/cmMakeDepend.h                              |  150 --
 Source/cmMakefile.cxx                              |  362 ++--
 Source/cmMakefile.h                                |   69 +-
 Source/cmMakefileExecutableTargetGenerator.cxx     |   45 +-
 Source/cmMakefileLibraryTargetGenerator.cxx        |  123 +-
 Source/cmMakefileTargetGenerator.cxx               |  123 +-
 Source/cmMakefileTargetGenerator.h                 |    3 -
 Source/cmMakefileUtilityTargetGenerator.cxx        |   18 +-
 Source/cmMarkAsAdvancedCommand.cxx                 |    3 +-
 Source/cmMessageCommand.cxx                        |   22 +-
 Source/cmNinjaNormalTargetGenerator.cxx            |  125 +-
 Source/cmNinjaTargetGenerator.cxx                  |   90 +-
 Source/cmNinjaTargetGenerator.h                    |    5 +-
 Source/cmNinjaUtilityTargetGenerator.cxx           |   26 +-
 Source/cmOSXBundleGenerator.cxx                    |   25 +-
 Source/cmOrderDirectories.cxx                      |    4 +-
 Source/cmOutputRequiredFilesCommand.cxx            |  598 +++++-
 Source/cmOutputRequiredFilesCommand.h              |    3 +-
 Source/cmParseArgumentsCommand.cxx                 |  200 ++
 Source/cmParseArgumentsCommand.h                   |   54 +
 Source/cmPolicies.h                                |   17 +
 Source/cmQtAutoGeneratorInitializer.cxx            | 1700 ++++++++-------
 Source/cmQtAutoGeneratorInitializer.h              |   41 +-
 Source/cmQtAutoGenerators.cxx                      |    8 +-
 Source/cmSetTargetPropertiesCommand.cxx            |    1 -
 Source/cmSourceFile.cxx                            |    7 +-
 Source/cmSourceFileLocation.cxx                    |   13 +-
 Source/cmStandardIncludes.h                        |    8 +-
 Source/cmState.cxx                                 |  271 ++-
 Source/cmState.h                                   |   46 +-
 Source/cmSystemTools.cxx                           |  113 +-
 Source/cmSystemTools.h                             |    6 +-
 Source/cmTarget.cxx                                | 2034 +++---------------
 Source/cmTarget.h                                  |  239 +--
 Source/cmTargetExport.h                            |    5 +-
 Source/cmTargetLinkLibrariesCommand.cxx            |   36 +-
 Source/cmTargetLinkLibrariesCommand.h              |    2 +-
 Source/cmTargetPropCommandBase.cxx                 |   14 +-
 Source/cmTestGenerator.cxx                         |   12 +-
 Source/cmUtilitySourceCommand.cxx                  |   10 +-
 Source/cmVS10LinkFlagTable.h                       |    3 +-
 Source/cmVS11LinkFlagTable.h                       |    3 +-
 Source/cmVS12LinkFlagTable.h                       |    3 +-
 Source/cmVS14LinkFlagTable.h                       |    5 +-
 Source/cmVersion.h                                 |    2 +-
 Source/cmVisualStudio10TargetGenerator.cxx         |  428 ++--
 Source/cmVisualStudio10TargetGenerator.h           |    4 +-
 Source/cmXCodeObject.cxx                           |    4 +-
 Source/cmXCodeObject.h                             |   12 +-
 Source/cm_sha2.c                                   |   13 +-
 Source/cm_sha2.h                                   |   10 +-
 Source/cmake.cxx                                   |  637 +++++-
 Source/cmake.h                                     |  102 +-
 Source/cmcmd.cxx                                   |  142 +-
 Source/kwsys/CMakeLists.txt                        |   77 +-
 Source/kwsys/CPU.h.in                              |  141 --
 Source/kwsys/Configure.h.in                        |    5 +
 Source/kwsys/Configure.hxx.in                      |    4 -
 Source/kwsys/EncodingCXX.cxx                       |    1 +
 Source/kwsys/FStream.cxx                           |    2 +
 Source/kwsys/FundamentalType.h.in                  |  146 --
 Source/kwsys/MD5.c                                 |    4 +-
 Source/kwsys/ProcessUNIX.c                         |    6 +-
 Source/kwsys/SharedForward.h.in                    |    6 +
 Source/kwsys/SystemTools.cxx                       |  133 +-
 Source/kwsys/SystemTools.hxx.in                    |    4 +-
 Source/kwsys/Terminal.c                            |   11 +
 Source/kwsys/kwsysPlatformTestsCXX.cxx             |  126 +-
 Source/kwsys/testFStream.cxx                       |   79 +-
 Source/kwsys/testSystemTools.cxx                   |  188 ++
 Tests/AliasTarget/CMakeLists.txt                   |    4 +-
 Tests/AliasTarget/subdir/CMakeLists.txt            |    3 +
 Tests/AliasTarget/subdir/empty.cpp                 |    7 +
 Tests/CMakeLists.txt                               |   48 +-
 Tests/CMakeOnly/CompilerIdC/CMakeLists.txt         |    7 +
 Tests/CMakeOnly/CompilerIdCXX/CMakeLists.txt       |    7 +
 Tests/CMakeOnly/CompilerIdFortran/CMakeLists.txt   |    7 +
 .../MyLibCPackConfig-components-source.cmake.in    |   33 +
 .../MyLibCPackConfig-compression.cmake.in          |   11 +
 .../RunCPackVerifyResult-components-source.cmake   |   75 +
 .../RunCPackVerifyResult-compression.cmake         |   54 +
 .../CPackComponentsDEB/RunCPackVerifyResult.cmake  |    6 +-
 Tests/CTestUpdateGIT.cmake.in                      |   30 +-
 Tests/CompileOptions/CMakeLists.txt                |    2 +-
 ....pas).html => UTCovTest(UTCovTest.pas).html.in} |    0
 Tests/ExportImport/Export/CMakeLists.txt           |   18 +-
 Tests/ExportImport/Export/testLibDepends.c         |    7 +-
 .../Export/testStaticLibRequiredPrivate.c          |    1 +
 Tests/FindBoost/CMakeLists.txt                     |   10 +
 Tests/FindBoost/Test/CMakeLists.txt                |   18 +
 Tests/FindBoost/Test/main.cxx                      |   26 +
 Tests/FindGTest/CMakeLists.txt                     |   10 +
 Tests/FindGTest/Test/CMakeLists.txt                |   17 +
 Tests/FindGTest/Test/main.cxx                      |    6 +
 Tests/FindPNG/CMakeLists.txt                       |   10 +
 Tests/FindPNG/Test/CMakeLists.txt                  |   16 +
 Tests/FindPNG/Test/main.c                          |   20 +
 Tests/FindTIFF/CMakeLists.txt                      |   10 +
 Tests/FindTIFF/Test/CMakeLists.txt                 |   17 +
 Tests/FindTIFF/Test/main.c                         |   12 +
 Tests/FindXalanC/CMakeLists.txt                    |   10 +
 Tests/FindXalanC/Test/CMakeLists.txt               |   17 +
 Tests/FindXalanC/Test/main.cxx                     |   10 +
 Tests/FindXercesC/CMakeLists.txt                   |   10 +
 Tests/FindXercesC/Test/CMakeLists.txt              |   17 +
 Tests/FindXercesC/Test/main.cxx                    |    7 +
 Tests/Fortran/CMakeLists.txt                       |    1 +
 Tests/Fortran/Executable/CMakeLists.txt            |    2 +-
 Tests/Fortran/Executable/main.f90                  |    1 +
 Tests/Fortran/Subdir/CMakeLists.txt                |    2 +
 Tests/Fortran/Subdir/subdir.f90                    |    2 +
 Tests/JavaJavah/C.cpp                              |   10 +
 Tests/JavaJavah/C.java                             |   19 +
 Tests/JavaJavah/CMakeLists.txt                     |    9 +-
 Tests/JavaJavah/HelloWorld2.java                   |    5 +
 .../GenerateExportHeader/exportheader_test.cpp     |   12 +
 Tests/RunCMake/BuildDepends/Custom-Always.cmake    |   24 +
 Tests/RunCMake/BuildDepends/RunCMakeTest.cmake     |    2 +
 .../CMP0040/CMP0040-NEW-missing-target-stderr.txt  |    2 +-
 .../CMP0040/CMP0040-WARN-missing-target-stderr.txt |    2 +-
 Tests/RunCMake/CMakeLists.txt                      |    7 +
 .../DEB/PER_COMPONENT_FIELDS-ExpectedFiles.cmake   |    9 +
 .../DEB/PER_COMPONENT_FIELDS-VerifyResult.cmake    |   18 +
 .../CPack/DEB/PER_COMPONENT_FIELDS-specifics.cmake |    6 +
 Tests/RunCMake/CPack/PER_COMPONENT_FIELDS.cmake    |    5 +
 Tests/RunCMake/CPack/RPM/Helpers.cmake             |    9 +
 .../RPM/PER_COMPONENT_FIELDS-ExpectedFiles.cmake   |    9 +
 .../RPM/PER_COMPONENT_FIELDS-VerifyResult.cmake    |   18 +
 .../CPack/RPM/PER_COMPONENT_FIELDS-specifics.cmake |    5 +
 Tests/RunCMake/CPack/RunCMakeTest.cmake            |    1 +
 Tests/RunCMake/CommandLine/E-no-arg-stderr.txt     |    2 +-
 ...source-directory-target-is-directory-result.txt |    1 +
 ...source-directory-target-is-directory-stderr.txt |    0
 .../E_copy-one-source-file-result.txt}             |    0
 .../CommandLine/E_copy-one-source-file-stderr.txt  |    1 +
 ...ree-source-files-target-is-directory-result.txt |    1 +
 ...ree-source-files-target-is-directory-stderr.txt |    0
 ...y-three-source-files-target-is-file-result.txt} |    0
 ...py-three-source-files-target-is-file-stderr.txt |    1 +
 ...ad-source-files-target-is-directory-result.txt} |    0
 ...bad-source-files-target-is-directory-stderr.txt |    1 +
 ...ree-source-files-target-is-directory-result.txt |    1 +
 ...ree-source-files-target-is-directory-stderr.txt |    0
 ...y-three-source-files-target-is-file-result.txt} |    0
 ...ry-three-source-files-target-is-file-stderr.txt |    3 +
 ...ree-source-files-target-is-not-exist-result.txt |    1 +
 ...ree-source-files-target-is-not-exist-stderr.txt |    0
 ...source-directory-target-is-directory-result.txt |    1 +
 ...source-directory-target-is-directory-stderr.txt |    0
 ...ree-source-files-target-is-directory-result.txt |    1 +
 ...ree-source-files-target-is-directory-stderr.txt |    0
 ...t-three-source-files-target-is-file-result.txt} |    0
 ...nt-three-source-files-target-is-file-stderr.txt |    1 +
 .../CommandLine/E_create_symlink-no-arg-stderr.txt |    2 +-
 ...make_directory-directory-with-parent-result.txt |    1 +
 ...make_directory-directory-with-parent-stderr.txt |    0
 ...irectory-three-directories-and-file-result.txt} |    0
 ...directory-three-directories-and-file-stderr.txt |    1 +
 .../E_make_directory-three-directories-result.txt  |    1 +
 .../E_make_directory-three-directories-stderr.txt  |    0
 .../CommandLine/E_rename-no-arg-stderr.txt         |    2 +-
 .../E_time-no-arg-result.txt}                      |    0
 ...-no-arg-stderr.txt => E_time-no-arg-stderr.txt} |    2 +-
 Tests/RunCMake/CommandLine/E_time-stdout.txt       |    3 +
 .../CommandLine/E_touch_nocreate-no-arg-stderr.txt |    2 +-
 Tests/RunCMake/CommandLine/P_working-dir.cmake     |   14 +
 Tests/RunCMake/CommandLine/RunCMakeTest.cmake      |  123 ++
 .../W_bad-arg1-result.txt}                         |    0
 Tests/RunCMake/CommandLine/W_bad-arg1-stderr.txt   |    2 +
 .../W_bad-arg2-result.txt}                         |    0
 Tests/RunCMake/CommandLine/W_bad-arg2-stderr.txt   |    2 +
 .../W_bad-arg3-result.txt}                         |    0
 Tests/RunCMake/CommandLine/W_bad-arg3-stderr.txt   |    2 +
 Tests/RunCMake/CommandLine/Wdeprecated-stderr.txt  |    4 +
 Tests/RunCMake/CommandLine/Wdeprecated.cmake       |    1 +
 Tests/RunCMake/CommandLine/Wdev-stderr.txt         |    2 +-
 Tests/RunCMake/CommandLine/Wdev.cmake              |    2 +-
 .../Werror_deprecated-result.txt}                  |    0
 .../CommandLine/Werror_deprecated-stderr.txt       |    4 +
 Tests/RunCMake/CommandLine/Werror_deprecated.cmake |    1 +
 .../Werror_dev-result.txt}                         |    0
 Tests/RunCMake/CommandLine/Werror_dev-stderr.txt   |   11 +
 Tests/RunCMake/CommandLine/Werror_dev.cmake        |    7 +
 Tests/RunCMake/CommandLine/Wno-deprecated.cmake    |    1 +
 Tests/RunCMake/CommandLine/Wno-dev.cmake           |    2 +-
 .../CommandLine/Wno-error_deprecated-stderr.txt    |    4 +
 .../CommandLine/Wno-error_deprecated.cmake         |    2 +
 .../{Wdev-stderr.txt => Wno-error_dev-stderr.txt}  |    6 +-
 Tests/RunCMake/CommandLine/Wno-error_dev.cmake     |    7 +
 .../cache-bad-entry-result.txt}                    |    0
 .../CommandLine/cache-bad-entry-stderr.txt         |    1 +
 .../CommandLine/cache-bad-entry/CMakeCache.txt     |   10 +
 .../cache-empty-entry-result.txt}                  |    0
 .../CommandLine/cache-empty-entry-stderr.txt       |    1 +
 .../CommandLine/cache-empty-entry/CMakeCache.txt   |    7 +
 Tests/RunCMake/CommandLine/copy_input/d1/d1.txt    |    0
 Tests/RunCMake/CommandLine/copy_input/d2/d2.txt    |    0
 Tests/RunCMake/CommandLine/copy_input/d3/d3.txt    |    0
 Tests/RunCMake/CommandLine/copy_input/f1.txt       |    0
 Tests/RunCMake/CommandLine/copy_input/f2.txt       |    0
 Tests/RunCMake/CommandLine/copy_input/f3.txt       |    0
 .../FindPkgConfig_cache_variables.cmake            |   16 +
 Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake    |    1 +
 Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh   |    5 +-
 .../RunCMake/{install => Framework}/CMakeLists.txt |    2 +-
 Tests/RunCMake/Framework/FrameworkLayout.cmake     |   11 +
 .../Framework/OSXFrameworkLayout-build-check.cmake |   35 +
 Tests/RunCMake/Framework/RunCMakeTest.cmake        |   33 +
 Tests/RunCMake/Framework/foo.c                     |    1 +
 Tests/RunCMake/Framework/foo.h                     |    1 +
 .../Framework/iOSFrameworkLayout-build-check.cmake |   35 +
 Tests/RunCMake/Framework/ios.cmake                 |   25 +
 Tests/RunCMake/Framework/osx.cmake                 |   18 +
 Tests/RunCMake/Framework/res.txt                   |    0
 .../VisibilityPreset/CMP0063-WARN-exe-stderr.txt   |   15 +
 ...P0063-WARN-yes.cmake => CMP0063-WARN-exe.cmake} |    5 +-
 .../VisibilityPreset/CMP0063-WARN-obj-stderr.txt   |   15 +
 ...P0063-WARN-yes.cmake => CMP0063-WARN-obj.cmake} |    5 +-
 .../VisibilityPreset/CMP0063-WARN-sta-stderr.txt   |   15 +
 ...P0063-WARN-yes.cmake => CMP0063-WARN-sta.cmake} |    5 +-
 .../VisibilityPreset/CMP0063-WARN-yes-stderr.txt   |   50 -
 Tests/RunCMake/VisibilityPreset/RunCMakeTest.cmake |    4 +-
 Tests/RunCMake/XcodeProject/RunCMakeTest.cmake     |   72 +
 .../XcodeProject/XcodeAttributeGenex-check.cmake   |   48 +
 .../XcodeProject/XcodeAttributeGenex.cmake         |   14 +-
 Tests/RunCMake/XcodeProject/XcodeBundles.cmake     |   30 +-
 .../XcodeIOSInstallCombined-install-check.cmake    |   30 +
 .../XcodeProject/XcodeIOSInstallCombined.cmake     |   27 +
 ...codeIOSInstallCombinedPrune-install-check.cmake |   26 +
 ...XcodeIOSInstallCombinedPrune-install-stdout.txt |    2 +
 .../XcodeIOSInstallCombinedPrune.cmake             |   36 +
 .../XcodeObjectNeedsEscape-check.cmake             |    7 +
 .../XcodeProject/XcodeObjectNeedsEscape.cmake      |    3 +
 .../XcodeOptimizationFlags-check.cmake             |    7 +
 .../XcodeProject/XcodeOptimizationFlags.cmake      |   20 +
 .../XcodePreserveNonOptimizationFlags-check.cmake  |    8 +
 .../XcodePreserveNonOptimizationFlags.cmake        |   12 +
 .../XcodeProject/XcodePreserveObjcFlag-check.cmake |    7 +
 .../XcodeProject/XcodePreserveObjcFlag.cmake       |    6 +
 Tests/RunCMake/XcodeProject/main.cpp               |    3 +
 .../RunCMake/add_custom_command/RunCMakeTest.cmake |    2 +
 .../TargetImported-result.txt}                     |    0
 .../add_custom_command/TargetImported-stderr.txt   |    4 +
 .../add_custom_command/TargetImported.cmake        |    2 +
 .../TargetNotInDir-result.txt}                     |    0
 .../add_custom_command/TargetNotInDir-stderr.txt   |    4 +
 .../add_custom_command/TargetNotInDir.cmake        |    2 +
 .../TargetNotInDir/CMakeLists.txt                  |    1 +
 .../CMakeLists.txt                                 |    2 +-
 .../cmake_parse_arguments/CornerCases.cmake        |   34 +
 .../Errors-result.txt}                             |    0
 .../cmake_parse_arguments/Errors-stderr.txt        |   44 +
 Tests/RunCMake/cmake_parse_arguments/Errors.cmake  |   14 +
 .../cmake_parse_arguments/Initialization.cmake     |   68 +
 Tests/RunCMake/cmake_parse_arguments/Mix.cmake     |   24 +
 .../cmake_parse_arguments/RunCMakeTest.cmake       |    7 +
 Tests/RunCMake/cmake_parse_arguments/Utils.cmake   |   20 +
 .../cmake_parse_arguments/test_utils.cmake         |   20 +
 .../ctest_submit/CDashSubmitQuiet-stderr.txt       |    2 +-
 .../RunCMake/ctest_submit/FailDrop-ftp-stderr.txt  |    2 +-
 .../RunCMake/ctest_submit/FailDrop-http-stderr.txt |    2 +-
 .../ctest_submit/FailDrop-https-stderr.txt         |    2 +-
 Tests/RunCMake/ctest_test/RunCMakeTest.cmake       |    1 +
 .../RunCMake/ctest_test/TestOutputSize-check.cmake |   10 +-
 Tests/RunCMake/if/MatchesSelf.cmake                |    4 +
 Tests/RunCMake/if/RunCMakeTest.cmake               |    2 +
 Tests/RunCMake/install/CMP0062-NEW.cmake           |    2 +-
 Tests/RunCMake/install/CMP0062-OLD.cmake           |    2 +-
 Tests/RunCMake/install/CMP0062-WARN.cmake          |    1 +
 Tests/RunCMake/install/CMakeLists.txt              |    2 +-
 .../DIRECTORY-DIRECTORY-bad-result.txt}            |    0
 .../install/DIRECTORY-DIRECTORY-bad-stderr.txt     |    6 +
 .../RunCMake/install/DIRECTORY-DIRECTORY-bad.cmake |    1 +
 Tests/RunCMake/install/EXPORT-OldIFace.cmake       |    7 +
 .../install/EXPORT-OldIFace/CMakeLists.txt         |    2 +
 Tests/RunCMake/install/RunCMakeTest.cmake          |    2 +
 Tests/RunCMake/message/RunCMakeTest.cmake          |    7 +-
 Tests/RunCMake/message/defaultmessage-result.txt   |    1 +
 Tests/RunCMake/message/defaultmessage-stderr.txt   |   11 +
 Tests/RunCMake/message/defaultmessage.cmake        |    4 +
 Tests/RunCMake/message/errormessage-stderr.txt     |    4 -
 Tests/RunCMake/message/errormessage.cmake          |    4 -
 ...sult.txt => errormessage_deprecated-result.txt} |    0
 .../message/errormessage_deprecated-stderr.txt     |    4 +
 .../RunCMake/message/errormessage_deprecated.cmake |    3 +
 ...sage-result.txt => errormessage_dev-result.txt} |    0
 Tests/RunCMake/message/errormessage_dev-stderr.txt |    5 +
 Tests/RunCMake/message/errormessage_dev.cmake      |    3 +
 Tests/RunCMake/message/nomessage.cmake             |    6 +
 Tests/RunCMake/message/warnmessage-stderr.txt      |   11 +-
 Tests/RunCMake/message/warnmessage.cmake           |    6 +-
 .../target_link_libraries/RunCMakeTest.cmake       |    2 +
 .../StaticPrivateDepNotExported-result.txt}        |    0
 .../StaticPrivateDepNotExported-stderr.txt         |    1 +
 .../StaticPrivateDepNotExported.cmake              |    7 +
 .../StaticPrivateDepNotTarget.cmake                |    6 +
 Tests/SimpleInstall/CMakeLists.txt                 |    4 +-
 Tests/SimpleInstallS2/CMakeLists.txt               |    4 +-
 Tests/SubDir/CMakeLists.txt                        |    4 +
 Tests/SubDir/Executable/CMakeLists.txt             |   12 +
 Tests/Wrapping/CMakeLists.txt                      |   10 +-
 Tests/Wrapping/fltk2.fl                            |    0
 Tests/Wrapping/wrapFLTK.c                          |    1 +
 Utilities/CMakeLists.txt                           |    4 +
 Utilities/KWIML/.gitattributes                     |    1 +
 Utilities/KWIML/ABI.h.in                           |  506 -----
 Utilities/KWIML/CMakeLists.txt                     |  145 +-
 Utilities/KWIML/Copyright.txt                      |    2 +-
 Utilities/KWIML/INT.h.in                           |  861 --------
 Utilities/KWIML/README.md                          |   36 +
 Utilities/KWIML/README.txt                         |   29 -
 Utilities/KWIML/include/kwiml/abi.h                |  562 +++++
 Utilities/KWIML/include/kwiml/int.h                | 1069 +++++++++
 Utilities/KWIML/src/kwiml-config.cmake.in          |    1 +
 Utilities/KWIML/src/version.h.in                   |   59 +
 Utilities/KWIML/test/CMakeLists.txt                |   48 +-
 Utilities/KWIML/test/test.c                        |   32 +-
 Utilities/KWIML/test/test.cxx                      |   16 +-
 Utilities/KWIML/test/test.h                        |   31 +-
 Utilities/KWIML/test/test_ABI_C.c                  |   22 -
 Utilities/KWIML/test/test_ABI_CXX.cxx              |   22 -
 Utilities/KWIML/test/test_ABI_endian.h.in          |   47 -
 Utilities/KWIML/test/test_INT_CXX.cxx              |   22 -
 Utilities/KWIML/test/test_abi_C.c                  |   19 +
 Utilities/KWIML/test/test_abi_CXX.cxx              |   19 +
 Utilities/KWIML/test/test_abi_endian.h             |   41 +
 Utilities/KWIML/test/test_include_C.c              |   20 +-
 Utilities/KWIML/test/test_include_CXX.cxx          |   20 +-
 Utilities/KWIML/test/test_int_C.c                  |   19 +
 Utilities/KWIML/test/test_int_CXX.cxx              |   19 +
 .../{test_INT_format.h.in => test_int_format.h}    |   83 +-
 Utilities/Release/WiX/CMakeLists.txt               |   12 +
 Utilities/Release/WiX/CustomAction/CMakeLists.txt  |   13 +
 .../WiX/CustomAction/detect_nsis_overwrite.cpp     |   45 +
 Utilities/Release/WiX/CustomAction/exports.def     |    2 +
 Utilities/Release/WiX/WIX.template.in              |   46 +
 Utilities/Release/WiX/cmake_extra_dialog.wxs       |   36 +
 .../Release/WiX/cmake_nsis_overwrite_dialog.wxs    |   21 +
 Utilities/Release/WiX/custom_action_dll.wxs.in     |    6 +
 Utilities/Release/WiX/install_dir.wxs              |   72 +
 Utilities/Release/WiX/patch_desktop_shortcut.xml   |    5 +
 Utilities/Release/WiX/patch_path_env.xml           |   26 +
 .../{cpack_wix_ui_banner.jpg => WiX/ui_banner.jpg} |  Bin
 .../{cpack_wix_ui_dialog.jpg => WiX/ui_dialog.jpg} |  Bin
 Utilities/Release/create-cmake-release.cmake       |    5 +-
 Utilities/Release/dash2win64_cygwin.cmake          |    2 +
 ...win64_release.cmake => dash3win7_release.cmake} |   17 +-
 Utilities/Release/dashmacmini2_release.cmake       |   25 -
 Utilities/Release/release_cmake.cmake              |   37 +-
 Utilities/Release/release_cmake.sh.in              |    1 +
 Utilities/Release/upload_release.cmake             |    2 +-
 Utilities/Scripts/BoostScanDeps.cmake              |  217 ++
 Utilities/Scripts/update-kwiml.bash                |   20 +
 Utilities/Scripts/update-kwsys.bash                |   22 +
 Utilities/Scripts/update-third-party.bash          |  146 ++
 Utilities/Sphinx/CMakeLists.txt                    |    8 +
 Utilities/cmThirdParty.h.in                        |    1 +
 .../cm_kwiml.h                                     |   25 +-
 Utilities/cmjsoncpp/CMakeLists.txt                 |    1 +
 Utilities/cmlibarchive/CMakeLists.txt              |   77 +-
 Utilities/cmlibarchive/COPYING                     |    5 +-
 Utilities/cmlibarchive/README-CMake.txt            |    8 +-
 .../build/cmake/CreatePkgConfigFile.cmake          |    6 +-
 Utilities/cmlibarchive/build/cmake/config.h.in     |   41 +-
 Utilities/cmlibarchive/libarchive/CMakeLists.txt   |   21 +-
 Utilities/cmlibarchive/libarchive/archive.h        |  186 +-
 .../cmlibarchive/libarchive/archive_cryptor.c      |  435 ++++
 .../libarchive/archive_cryptor_private.h           |  152 ++
 .../{archive_crypto.c => archive_digest.c}         |   10 +-
 ...e_crypto_private.h => archive_digest_private.h} |   42 +-
 Utilities/cmlibarchive/libarchive/archive_entry.3  |    2 +-
 Utilities/cmlibarchive/libarchive/archive_entry.c  |  130 +-
 Utilities/cmlibarchive/libarchive/archive_entry.h  |   59 +-
 .../cmlibarchive/libarchive/archive_entry_acl.3    |    2 +-
 .../cmlibarchive/libarchive/archive_entry_paths.3  |    2 +-
 .../cmlibarchive/libarchive/archive_entry_perms.3  |    2 +-
 .../cmlibarchive/libarchive/archive_entry_stat.3   |    4 +-
 .../cmlibarchive/libarchive/archive_entry_time.3   |    2 +-
 .../cmlibarchive/libarchive/archive_entry_xattr.c  |    5 +-
 Utilities/cmlibarchive/libarchive/archive_hmac.c   |  234 ++
 .../cmlibarchive/libarchive/archive_hmac_private.h |   95 +
 Utilities/cmlibarchive/libarchive/archive_match.c  |    9 +-
 .../cmlibarchive/libarchive/archive_pathmatch.c    |    8 +-
 .../cmlibarchive/libarchive/archive_private.h      |   19 +
 Utilities/cmlibarchive/libarchive/archive_random.c |  269 +++
 ...write_add_filter.c => archive_random_private.h} |   50 +-
 Utilities/cmlibarchive/libarchive/archive_read.3   |    4 +-
 Utilities/cmlibarchive/libarchive/archive_read.c   |   74 +-
 ..._write_data.3 => archive_read_add_passphrase.3} |   66 +-
 .../libarchive/archive_read_add_passphrase.c       |  186 ++
 .../libarchive/archive_read_append_filter.c        |    6 +-
 .../cmlibarchive/libarchive/archive_read_data.3    |    2 +-
 .../libarchive/archive_read_disk_entry_from_file.c |    8 +-
 .../libarchive/archive_read_disk_posix.c           |   23 +-
 .../libarchive/archive_read_disk_private.h         |    5 +
 .../archive_read_disk_set_standard_lookup.c        |    2 +-
 .../libarchive/archive_read_disk_windows.c         |   19 +-
 .../cmlibarchive/libarchive/archive_read_extract.c |   17 -
 .../libarchive/archive_read_extract2.c             |   21 +-
 .../cmlibarchive/libarchive/archive_read_filter.3  |   17 +-
 .../cmlibarchive/libarchive/archive_read_open.3    |    4 +-
 .../cmlibarchive/libarchive/archive_read_open_fd.c |   29 +
 .../libarchive/archive_read_open_memory.c          |   12 +-
 .../cmlibarchive/libarchive/archive_read_private.h |   43 +-
 .../libarchive/archive_read_set_options.c          |    7 +-
 .../libarchive/archive_read_support_filter_all.c   |    2 +
 .../archive_read_support_filter_compress.c         |   24 +-
 .../libarchive/archive_read_support_filter_lz4.c   |  728 +++++++
 .../libarchive/archive_read_support_filter_lzop.c  |    7 +
 .../libarchive/archive_read_support_filter_uu.c    |    3 +-
 .../libarchive/archive_read_support_filter_xz.c    |    2 +-
 .../libarchive/archive_read_support_format_7zip.c  |   48 +-
 .../libarchive/archive_read_support_format_all.c   |    1 +
 .../libarchive/archive_read_support_format_ar.c    |   21 +-
 .../libarchive/archive_read_support_format_cpio.c  |   22 +-
 .../archive_read_support_format_iso9660.c          |   72 +-
 .../libarchive/archive_read_support_format_lha.c   |  480 +++--
 .../libarchive/archive_read_support_format_mtree.c |  266 +--
 .../libarchive/archive_read_support_format_rar.c   |   34 +-
 .../libarchive/archive_read_support_format_tar.c   |   44 +-
 .../libarchive/archive_read_support_format_warc.c  |  794 +++++++
 .../libarchive/archive_read_support_format_xar.c   |   34 +-
 .../libarchive/archive_read_support_format_zip.c   | 1074 ++++++++--
 Utilities/cmlibarchive/libarchive/archive_string.c |   91 +-
 Utilities/cmlibarchive/libarchive/archive_util.c   |  143 +-
 .../cmlibarchive/libarchive/archive_windows.h      |    2 +
 Utilities/cmlibarchive/libarchive/archive_write.3  |   15 +-
 Utilities/cmlibarchive/libarchive/archive_write.c  |   11 +
 .../libarchive/archive_write_add_filter.c          |    1 +
 .../libarchive/archive_write_add_filter_by_name.c  |    1 +
 .../libarchive/archive_write_add_filter_lz4.c      |  646 ++++++
 .../libarchive/archive_write_add_filter_xz.c       |   44 +-
 .../cmlibarchive/libarchive/archive_write_data.3   |   14 +-
 .../cmlibarchive/libarchive/archive_write_disk.3   |   10 +-
 .../libarchive/archive_write_disk_posix.c          |   87 +-
 .../archive_write_disk_set_standard_lookup.c       |    7 +-
 .../libarchive/archive_write_disk_windows.c        |    6 +-
 .../cmlibarchive/libarchive/archive_write_filter.3 |   18 +-
 .../libarchive/archive_write_finish_entry.3        |    2 +-
 .../cmlibarchive/libarchive/archive_write_format.3 |   16 +-
 .../cmlibarchive/libarchive/archive_write_open.3   |    2 +-
 .../libarchive/archive_write_open_filename.c       |    5 +-
 .../libarchive/archive_write_private.h             |   15 +
 .../libarchive/archive_write_set_format.c          |    1 +
 .../libarchive/archive_write_set_format_by_name.c  |    1 +
 .../archive_write_set_format_filter_by_ext.c       |  142 ++
 .../libarchive/archive_write_set_format_iso9660.c  |   10 +
 .../libarchive/archive_write_set_format_mtree.c    |    4 +-
 .../libarchive/archive_write_set_format_warc.c     |  439 ++++
 .../libarchive/archive_write_set_format_xar.c      |   63 +-
 .../libarchive/archive_write_set_format_zip.c      |  678 +++++-
 .../libarchive/archive_write_set_options.3         |   42 +
 ...write_data.3 => archive_write_set_passphrase.3} |   66 +-
 .../libarchive/archive_write_set_passphrase.c      |   95 +
 ...archive_write_add_filter.c => archive_xxhash.h} |   55 +-
 Utilities/cmlibarchive/libarchive/libarchive.3     |    4 +-
 .../cmlibarchive/libarchive/libarchive_internals.3 |    2 +-
 Utilities/cmlibarchive/libarchive/mtree.5          |   18 -
 Utilities/cmlibarchive/libarchive/tar.5            |    2 +-
 Utilities/cmlibarchive/libarchive/xxhash.c         |  500 +++++
 bootstrap                                          |   67 +-
 802 files changed, 28110 insertions(+), 13063 deletions(-)

diff --git a/Auxiliary/cmake-mode.el b/Auxiliary/cmake-mode.el
index e50ae7b..08ac490 100644
--- a/Auxiliary/cmake-mode.el
+++ b/Auxiliary/cmake-mode.el
@@ -177,7 +177,7 @@ the indentation.  Otherwise it retains the same position on the line"
   (interactive)
   (save-excursion
     (goto-char (point-min))
-    (while (re-search-forward "^\\([ \t]*\\)\\(\\w+\\)\\([ \t]*(\\)" nil t)
+    (while (re-search-forward "^\\([ \t]*\\)\\_<\\(\\(?:\\w\\|\\s_\\)+\\)\\_>\\([ \t]*(\\)" nil t)
       (replace-match
        (concat
         (match-string 1)
diff --git a/CMakeCPack.cmake b/CMakeCPack.cmake
index a0aadcc..3203279 100644
--- a/CMakeCPack.cmake
+++ b/CMakeCPack.cmake
@@ -198,6 +198,17 @@ if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
 
   set(CPACK_WIX_UPGRADE_GUID "8ffd1d72-b7f1-11e2-8ee5-00238bca4991")
 
+  if(MSVC AND NOT "$ENV{WIX}" STREQUAL "")
+    set(WIX_CUSTOM_ACTION_ENABLED TRUE)
+    if(CMAKE_CONFIGURATION_TYPES)
+      set(WIX_CUSTOM_ACTION_MULTI_CONFIG TRUE)
+    else()
+      set(WIX_CUSTOM_ACTION_MULTI_CONFIG FALSE)
+    endif()
+  else()
+    set(WIX_CUSTOM_ACTION_ENABLED FALSE)
+  endif()
+
   # Set the options file that needs to be included inside CMakeCPackOptions.cmake
   set(QT_DIALOG_CPACK_OPTIONS_FILE ${CMake_BINARY_DIR}/Source/QtDialog/QtDialogCPack.cmake)
   configure_file("${CMake_SOURCE_DIR}/CMakeCPackOptions.cmake.in"
diff --git a/CMakeCPackOptions.cmake.in b/CMakeCPackOptions.cmake.in
index b6013ef..59ae224 100644
--- a/CMakeCPackOptions.cmake.in
+++ b/CMakeCPackOptions.cmake.in
@@ -183,13 +183,20 @@ if("${CPACK_GENERATOR}" STREQUAL "PackageMaker")
   endif()
 endif()
 
+if("${CPACK_GENERATOR}" STREQUAL "DragNDrop")
+  set(CPACK_DMG_BACKGROUND_IMAGE
+      "@CMake_SOURCE_DIR@/Packaging/CMakeDMGBackground.tif")
+  set(CPACK_DMG_DS_STORE_SETUP_SCRIPT
+      "@CMake_SOURCE_DIR@/Packaging/CMakeDMGSetup.scpt")
+endif()
+
 if("${CPACK_GENERATOR}" STREQUAL "WIX")
   # Reset CPACK_PACKAGE_VERSION to deal with WiX restriction.
   # But the file names still use the full CMake_VERSION value:
   set(CPACK_PACKAGE_FILE_NAME
-    "${CPACK_PACKAGE_NAME}- at CMake_VERSION@-${CPACK_SYSTEM_NAME}")
+    "cmake- at CMake_VERSION@-${CPACK_SYSTEM_NAME}")
   set(CPACK_SOURCE_PACKAGE_FILE_NAME
-    "${CPACK_PACKAGE_NAME}- at CMake_VERSION@-Source")
+    "cmake- at CMake_VERSION@")
 
   if(NOT CPACK_WIX_SIZEOF_VOID_P)
     set(CPACK_WIX_SIZEOF_VOID_P "@CMAKE_SIZEOF_VOID_P@")
@@ -227,10 +234,57 @@ if("${CPACK_GENERATOR}" STREQUAL "WIX")
   set(CPACK_WIX_LIGHT_EXTRA_FLAGS "-dcl:high")
 
   set(CPACK_WIX_UI_BANNER
-    "@CMake_SOURCE_DIR@/Utilities/Release/cpack_wix_ui_banner.jpg"
+    "@CMake_SOURCE_DIR@/Utilities/Release/WiX/ui_banner.jpg"
   )
 
   set(CPACK_WIX_UI_DIALOG
-    "@CMake_SOURCE_DIR@/Utilities/Release/cpack_wix_ui_dialog.jpg"
+    "@CMake_SOURCE_DIR@/Utilities/Release/WiX/ui_dialog.jpg"
+  )
+
+  set(CPACK_WIX_EXTRA_SOURCES
+    "@CMake_SOURCE_DIR@/Utilities/Release/WiX/install_dir.wxs"
+    "@CMake_SOURCE_DIR@/Utilities/Release/WiX/cmake_extra_dialog.wxs"
+  )
+
+  set(_WIX_CUSTOM_ACTION_ENABLED "@WIX_CUSTOM_ACTION_ENABLED@")
+  if(_WIX_CUSTOM_ACTION_ENABLED)
+    list(APPEND CPACK_WIX_EXTRA_SOURCES
+      "@CMake_SOURCE_DIR@/Utilities/Release/WiX/cmake_nsis_overwrite_dialog.wxs"
+      )
+    list(APPEND CPACK_WIX_CANDLE_EXTRA_FLAGS -dCHECK_NSIS=1)
+
+    set(_WIX_CUSTOM_ACTION_MULTI_CONFIG "@WIX_CUSTOM_ACTION_MULTI_CONFIG@")
+    if(_WIX_CUSTOM_ACTION_MULTI_CONFIG)
+      if(CPACK_BUILD_CONFIG)
+        set(_WIX_CUSTOM_ACTION_CONFIG "${CPACK_BUILD_CONFIG}")
+      else()
+        set(_WIX_CUSTOM_ACTION_CONFIG "Release")
+      endif()
+
+      list(APPEND CPACK_WIX_EXTRA_SOURCES
+        "@CMake_BINARY_DIR@/Utilities/Release/WiX/custom_action_dll-${_WIX_CUSTOM_ACTION_CONFIG}.wxs")
+    else()
+      list(APPEND CPACK_WIX_EXTRA_SOURCES
+        "@CMake_BINARY_DIR@/Utilities/Release/WiX/custom_action_dll.wxs")
+    endif()
+  endif()
+
+  set(CPACK_WIX_UI_REF "CMakeUI_InstallDir")
+
+  set(CPACK_WIX_PATCH_FILE
+    "@CMake_SOURCE_DIR@/Utilities/Release/WiX/patch_path_env.xml"
+  )
+
+  set(CPACK_WIX_TEMPLATE
+    "@CMake_SOURCE_DIR@/Utilities/Release/WiX/WIX.template.in"
   )
+
+  set(BUILD_QtDialog "@BUILD_QtDialog@")
+
+  if(BUILD_QtDialog)
+    list(APPEND CPACK_WIX_PATCH_FILE
+      "@CMake_SOURCE_DIR@/Utilities/Release/WiX/patch_desktop_shortcut.xml"
+      )
+    list(APPEND CPACK_WIX_CANDLE_EXTRA_FLAGS -dBUILD_QtDialog=1)
+  endif()
 endif()
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c96f68b..9381f35 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -138,8 +138,13 @@ macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
   option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
   option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}")
 
+  # For now use system KWIML only if explicitly requested rather
+  # than activating via the general system libs options.
+  option(CMAKE_USE_SYSTEM_KWIML "Use system-installed KWIML" OFF)
+  mark_as_advanced(CMAKE_USE_SYSTEM_KWIML)
+
   # Mention to the user what system libraries are being used.
-  foreach(util ${UTILITIES})
+  foreach(util ${UTILITIES} KWIML)
     if(CMAKE_USE_SYSTEM_${util})
       message(STATUS "Using system-installed ${util}")
     endif()
@@ -270,6 +275,20 @@ macro (CMAKE_BUILD_UTILITIES)
   # (a macro defined in this file)
   CMAKE_HANDLE_SYSTEM_LIBRARIES()
 
+  if(CMAKE_USE_SYSTEM_KWIML)
+    find_package(KWIML 1.0)
+    if(NOT KWIML_FOUND)
+      message(FATAL_ERROR "CMAKE_USE_SYSTEM_KWIML is ON but KWIML is not found!")
+    endif()
+    set(CMake_KWIML_LIBRARIES kwiml::kwiml)
+  else()
+    set(CMake_KWIML_LIBRARIES "")
+    if(BUILD_TESTING)
+      set(KWIML_TEST_ENABLE 1)
+    endif()
+    add_subdirectory(Utilities/KWIML)
+  endif()
+
   #---------------------------------------------------------------------
   # Build zlib library for Curl, CMake, and CTest.
   set(CMAKE_ZLIB_HEADER "cm_zlib.h")
@@ -372,12 +391,14 @@ macro (CMAKE_BUILD_UTILITIES)
     set(ENABLE_LZMA ON CACHE INTERNAL "Enable the use of the system found LZMA library if found")
     set(ENABLE_ZLIB ON CACHE INTERNAL "Enable the use of the system found ZLIB library if found")
     set(ENABLE_BZip2 ON CACHE INTERNAL "Enable the use of the system found BZip2 library if found")
+    set(ENABLE_LIBXML2 OFF CACHE INTERNAL "Enable the use of the system found libxml2 library if found")
     set(ENABLE_EXPAT OFF CACHE INTERNAL "Enable the use of the system found EXPAT library if found")
     set(ENABLE_PCREPOSIX OFF CACHE INTERNAL "Enable the use of the system found PCREPOSIX library if found")
     set(ENABLE_LibGCC OFF CACHE INTERNAL "Enable the use of the system found LibGCC library if found")
     set(ENABLE_XATTR OFF CACHE INTERNAL "Enable extended attribute support")
     set(ENABLE_ACL OFF CACHE INTERNAL "Enable ACL support")
     set(ENABLE_ICONV OFF CACHE INTERNAL "Enable iconv support")
+    set(ENABLE_CNG OFF CACHE INTERNAL "Enable the use of CNG(Crypto Next Generation)")
     add_subdirectory(Utilities/cmlibarchive)
     CMAKE_SET_TARGET_FOLDER(cmlibarchive "Utilities/3rdParty")
     set(CMAKE_TAR_LIBRARIES cmlibarchive ${BZIP2_LIBRARIES})
@@ -536,10 +557,10 @@ if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x")
   set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org")
 endif()
 
-# Create the KWIML library for CMake.
-set(KWIML cmIML)
-set(KWIML_HEADER_ROOT ${CMake_BINARY_DIR}/Utilities)
-add_subdirectory(Utilities/KWIML)
+if(CMake_TEST_EXTERNAL_CMAKE)
+  set(KWIML_TEST_ENABLE 1)
+  add_subdirectory(Utilities/KWIML)
+endif()
 
 if(NOT CMake_TEST_EXTERNAL_CMAKE)
   # build the utilities (a macro defined in this file)
diff --git a/CTestCustom.cmake.in b/CTestCustom.cmake.in
index 2adf317..abef692 100644
--- a/CTestCustom.cmake.in
+++ b/CTestCustom.cmake.in
@@ -21,7 +21,8 @@ list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION
   "Utilities.cmcurl"
   "Utilities.cmexpat."
   "Utilities.cmlibarchive"
-  "/usr/include.*warning.*shadowed declaration is here"
+  "warning: declaration of .single. shadows a global declaration"
+  "/usr/include.*(warning|note).*shadowed declaration is here"
   "/usr/bin/ld.*warning.*-..*directory.name.*bin.*does not exist"
   "Redeclaration of .send..... with a different storage class specifier"
   "is not used for resolving any symbol"
@@ -36,7 +37,7 @@ list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION
   "LINK : warning LNK4089: all references to.*SHELL32.dll.*discarded by /OPT:REF"
   "LINK : warning LNK4089: all references to.*USER32.dll.*discarded by /OPT:REF"
   "LINK : warning LNK4089: all references to.*ole32.dll.*discarded by /OPT:REF"
-  "Warning.*: .*/Utilities/KWIML/test/test_INT_format.h.* # Redundant preprocessing concatenation"
+  "Warning.*: .*/Utilities/KWIML/test/test_int_format.h.* # Redundant preprocessing concatenation"
   "Warning: library was too large for page size.*"
   "Warning: public.*_archive_.*in module.*archive_*clashes with prior module.*archive_.*"
   "Warning: public.*BZ2_bz.*in module.*bzlib.*clashes with prior module.*bzlib.*"
diff --git a/Copyright.txt b/Copyright.txt
index 6c9fb09..f99998f 100644
--- a/Copyright.txt
+++ b/Copyright.txt
@@ -1,5 +1,5 @@
 CMake - Cross Platform Makefile Generator
-Copyright 2000-2015 Kitware, Inc.
+Copyright 2000-2016 Kitware, Inc.
 Copyright 2000-2011 Insight Software Consortium
 All rights reserved.
 
diff --git a/Help/command/add_custom_command.rst b/Help/command/add_custom_command.rst
index ecbf9dd..8726b70 100644
--- a/Help/command/add_custom_command.rst
+++ b/Help/command/add_custom_command.rst
@@ -178,7 +178,7 @@ target is already built, the command will not execute.
 
 ::
 
-  add_custom_command(TARGET target
+  add_custom_command(TARGET <target>
                      PRE_BUILD | PRE_LINK | POST_BUILD
                      COMMAND command1 [ARGS] [args1...]
                      [COMMAND command2 [ARGS] [args2...] ...]
@@ -188,7 +188,10 @@ target is already built, the command will not execute.
                      [VERBATIM] [USES_TERMINAL])
 
 This defines a new command that will be associated with building the
-specified target.  When the command will happen is determined by which
+specified ``<target>``.  The ``<target>`` must be defined in the current
+directory; targets defined in other directories may not be specified.
+
+When the command will happen is determined by which
 of the following is specified:
 
 ``PRE_BUILD``
diff --git a/Help/command/cmake_minimum_required.rst b/Help/command/cmake_minimum_required.rst
index 8573218..dc65a9e 100644
--- a/Help/command/cmake_minimum_required.rst
+++ b/Help/command/cmake_minimum_required.rst
@@ -5,7 +5,7 @@ Set the minimum required version of cmake for a project.
 
 ::
 
-  cmake_minimum_required(VERSION major[.minor[.patch[.tweak]]]
+  cmake_minimum_required(VERSION major.minor[.patch[.tweak]]
                          [FATAL_ERROR])
 
 If the current version of CMake is lower than that required it will
diff --git a/Help/command/cmake_parse_arguments.rst b/Help/command/cmake_parse_arguments.rst
new file mode 100644
index 0000000..6206611
--- /dev/null
+++ b/Help/command/cmake_parse_arguments.rst
@@ -0,0 +1,85 @@
+cmake_parse_arguments
+---------------------
+
+``cmake_parse_arguments`` is intended to be used in macros or functions for
+parsing the arguments given to that macro or function.  It processes the
+arguments and defines a set of variables which hold the values of the
+respective options.
+
+::
+
+  cmake_parse_arguments(<prefix> <options> <one_value_keywords>
+                        <multi_value_keywords> args...)
+
+
+The ``<options>`` argument contains all options for the respective macro,
+i.e.  keywords which can be used when calling the macro without any value
+following, like e.g.  the ``OPTIONAL`` keyword of the :command:`install`
+command.
+
+The ``<one_value_keywords>`` argument contains all keywords for this macro
+which are followed by one value, like e.g. ``DESTINATION`` keyword of the
+:command:`install` command.
+
+The ``<multi_value_keywords>`` argument contains all keywords for this
+macro which can be followed by more than one value, like e.g. the
+``TARGETS`` or ``FILES`` keywords of the :command:`install` command.
+
+.. note::
+
+   All keywords shall be unique. I.e. every keyword shall only be specified
+   once in either ``<options>``, ``<one_value_keywords>`` or
+   ``<multi_value_keywords>``. A warning will be emitted if uniqueness is
+   violated.
+
+When done, ``cmake_parse_arguments`` will have defined for each of the
+keywords listed in ``<options>``, ``<one_value_keywords>`` and
+``<multi_value_keywords>`` a variable composed of the given ``<prefix>``
+followed by ``"_"`` and the name of the respective keyword.  These
+variables will then hold the respective value from the argument list.
+For the ``<options>`` keywords this will be ``TRUE`` or ``FALSE``.
+
+All remaining arguments are collected in a variable
+``<prefix>_UNPARSED_ARGUMENTS``, this can be checked afterwards to see
+whether your macro was called with unrecognized parameters.
+
+As an example here a ``my_install()`` macro, which takes similar arguments
+as the real :command:`install` command:
+
+.. code-block:: cmake
+
+   function(MY_INSTALL)
+       set(options OPTIONAL FAST)
+       set(oneValueArgs DESTINATION RENAME)
+       set(multiValueArgs TARGETS CONFIGURATIONS)
+       cmake_parse_arguments(MY_INSTALL "${options}" "${oneValueArgs}"
+                             "${multiValueArgs}" ${ARGN} )
+
+       # ...
+
+Assume ``my_install()`` has been called like this:
+
+.. code-block:: cmake
+
+   my_install(TARGETS foo bar DESTINATION bin OPTIONAL blub)
+
+After the ``cmake_parse_arguments`` call the macro will have set the
+following variables::
+
+   MY_INSTALL_OPTIONAL = TRUE
+   MY_INSTALL_FAST = FALSE (was not used in call to my_install)
+   MY_INSTALL_DESTINATION = "bin"
+   MY_INSTALL_RENAME = "" (was not used)
+   MY_INSTALL_TARGETS = "foo;bar"
+   MY_INSTALL_CONFIGURATIONS = "" (was not used)
+   MY_INSTALL_UNPARSED_ARGUMENTS = "blub" (nothing expected after "OPTIONAL")
+
+You can then continue and process these variables.
+
+Keywords terminate lists of values, e.g.  if directly after a
+one_value_keyword another recognized keyword follows, this is
+interpreted as the beginning of the new option.  E.g.
+``my_install(TARGETS foo DESTINATION OPTIONAL)`` would result in
+``MY_INSTALL_DESTINATION`` set to ``"OPTIONAL"``, but as ``OPTIONAL``
+is a keyword itself ``MY_INSTALL_DESTINATION`` will be empty and
+``MY_INSTALL_OPTIONAL`` will therefore be set to ``TRUE``.
diff --git a/Help/command/get_target_property.rst b/Help/command/get_target_property.rst
index 7798252..2a72c3a 100644
--- a/Help/command/get_target_property.rst
+++ b/Help/command/get_target_property.rst
@@ -13,6 +13,6 @@ the variable ``VAR``.  If the property is not found, ``VAR`` will be set to
 Properties are usually used to control how a target is built, but some
 query the target instead.  This command can get properties for any
 target so far created.  The targets do not need to be in the current
-CMakeLists.txt file.
+``CMakeLists.txt`` file.
 
 See also the more general :command:`get_property` command.
diff --git a/Help/command/if.rst b/Help/command/if.rst
index 2465bde..56e618c 100644
--- a/Help/command/if.rst
+++ b/Help/command/if.rst
@@ -67,9 +67,10 @@ Possible expressions are:
  True if the given name is an existing policy (of the form ``CMP<NNNN>``).
 
 ``if(TARGET target-name)``
- True if the given name is an existing logical target name such as those
- created by the :command:`add_executable`, :command:`add_library`, or
- :command:`add_custom_target` commands.
+ True if the given name is an existing logical target name created
+ by a call to the :command:`add_executable`, :command:`add_library`,
+ or :command:`add_custom_target` command that has already been invoked
+ (in any directory).
 
 ``if(TEST test-name)``
  True if the given name is an existing test name created by the
@@ -80,7 +81,7 @@ Possible expressions are:
  only for full paths.
 
 ``if(file1 IS_NEWER_THAN file2)``
- True if file1 is newer than file2 or if one of the two files doesn't
+ True if ``file1`` is newer than ``file2`` or if one of the two files doesn't
  exist.  Behavior is well-defined only for full paths.  If the file
  time stamps are exactly the same, an ``IS_NEWER_THAN`` comparison returns
  true, so that any dependent build operations will occur in the event
diff --git a/Help/command/install.rst b/Help/command/install.rst
index 423899e..45167bc 100644
--- a/Help/command/install.rst
+++ b/Help/command/install.rst
@@ -72,12 +72,13 @@ Installing Targets
           [[ARCHIVE|LIBRARY|RUNTIME|FRAMEWORK|BUNDLE|
             PRIVATE_HEADER|PUBLIC_HEADER|RESOURCE]
            [DESTINATION <dir>]
-           [INCLUDES DESTINATION [<dir> ...]]
            [PERMISSIONS permissions...]
            [CONFIGURATIONS [Debug|Release|...]]
            [COMPONENT <component>]
            [OPTIONAL] [NAMELINK_ONLY|NAMELINK_SKIP]
-          ] [...])
+          ] [...]
+          [INCLUDES DESTINATION [<dir> ...]]
+          )
 
 The ``TARGETS`` form specifies rules for installing targets from a
 project.  There are five kinds of target files that may be installed:
@@ -97,11 +98,7 @@ change the type of target to which the subsequent properties apply.
 If none is given the installation properties apply to all target
 types.  If only one is given then only targets of that type will be
 installed (which can be used to install just a DLL or just an import
-library).  The ``INCLUDES DESTINATION`` specifies a list of directories
-which will be added to the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`
-target property of the ``<targets>`` when exported by the
-:command:`install(EXPORT)` command.  If a relative path is
-specified, it is treated as relative to the ``$<INSTALL_PREFIX>``.
+library).
 
 The ``PRIVATE_HEADER``, ``PUBLIC_HEADER``, and ``RESOURCE`` arguments
 cause subsequent properties to be applied to installing a ``FRAMEWORK``
@@ -131,6 +128,14 @@ option installs nothing.  See the :prop_tgt:`VERSION` and
 :prop_tgt:`SOVERSION` target properties for details on creating versioned
 shared libraries.
 
+The ``INCLUDES DESTINATION`` specifies a list of directories
+which will be added to the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`
+target property of the ``<targets>`` when exported by the
+:command:`install(EXPORT)` command.  If a relative path is
+specified, it is treated as relative to the ``$<INSTALL_PREFIX>``.
+This is independent of the rest of the argument groups and does
+not actually install anything.
+
 One or more groups of properties may be specified in a single call to
 the ``TARGETS`` form of this command.  A target may be installed more than
 once to different locations.  Consider hypothetical targets ``myExe``,
@@ -271,9 +276,10 @@ will install the ``icons`` directory to ``share/myproj/icons`` and the
 file permissions, the scripts will be given specific permissions, and any
 ``CVS`` directories will be excluded.
 
-The install destination given to the directory install ``DESTINATION`` may
-use "generator expressions" with the syntax ``$<...>``.  See the
-:manual:`cmake-generator-expressions(7)` manual for available expressions.
+The list of ``dirs...`` given to ``DIRECTORY`` and the install destination
+given to the directory install ``DESTINATION`` may use "generator expressions"
+with the syntax ``$<...>``.  See the :manual:`cmake-generator-expressions(7)`
+manual for available expressions.
 
 Custom Installation Logic
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/Help/manual/OPTIONS_BUILD.txt b/Help/manual/OPTIONS_BUILD.txt
index 4207db4..b428a74 100644
--- a/Help/manual/OPTIONS_BUILD.txt
+++ b/Help/manual/OPTIONS_BUILD.txt
@@ -77,10 +77,47 @@
  Suppress developer warnings.
 
  Suppress warnings that are meant for the author of the
- CMakeLists.txt files.
+ CMakeLists.txt files. By default this will also turn off
+ deprecation warnings.
 
 ``-Wdev``
  Enable developer warnings.
 
  Enable warnings that are meant for the author of the CMakeLists.txt
- files.
+ files. By default this will also turn on deprecation warnings.
+
+``-Werror=dev``
+ Make developer warnings errors.
+
+ Make warnings that are meant for the author of the CMakeLists.txt files
+ errors. By default this will also turn on deprecated warnings as errors.
+
+``-Wno-error=dev``
+ Make developer warnings not errors.
+
+ Make warnings that are meant for the author of the CMakeLists.txt files not
+ errors. By default this will also turn off deprecated warnings as errors.
+
+``-Wdeprecated``
+ Enable deprecated functionality warnings.
+
+ Enable warnings for usage of deprecated functionality, that are meant
+ for the author of the CMakeLists.txt files.
+
+``-Wno-deprecated``
+ Suppress deprecated functionality warnings.
+
+ Suppress warnings for usage of deprecated functionality, that are meant
+ for the author of the CMakeLists.txt files.
+
+``-Werror=deprecated``
+ Make deprecated macro and function warnings errors.
+
+ Make warnings for usage of deprecated macros and functions, that are meant
+ for the author of the CMakeLists.txt files, errors.
+
+``-Wno-error=deprecated``
+ Make deprecated macro and function warnings not errors.
+
+ Make warnings for usage of deprecated macros and functions, that are meant
+ for the author of the CMakeLists.txt files, not errors.
diff --git a/Help/manual/cmake-buildsystem.7.rst b/Help/manual/cmake-buildsystem.7.rst
index bc633e6..9004bb2 100644
--- a/Help/manual/cmake-buildsystem.7.rst
+++ b/Help/manual/cmake-buildsystem.7.rst
@@ -95,15 +95,18 @@ Apple Frameworks
 """"""""""""""""
 
 A ``SHARED`` library may be marked with the :prop_tgt:`FRAMEWORK`
-target property to create an OS X Framework:
+target property to create an OS X or iOS Framework Bundle.
+The ``MACOSX_FRAMEWORK_IDENTIFIER`` sets ``CFBundleIdentifier`` key
+and it uniquely identifies the bundle.
 
 .. code-block:: cmake
 
   add_library(MyFramework SHARED MyFramework.cpp)
   set_target_properties(MyFramework PROPERTIES
-    FRAMEWORK 1
+    FRAMEWORK TRUE
     FRAMEWORK_VERSION A
-    )
+    MACOSX_FRAMEWORK_IDENTIFIER org.cmake.MyFramework
+  )
 
 .. _`Object Libraries`:
 
@@ -424,7 +427,7 @@ specified will be calculated:
   )
 
   add_library(lib1Version3 SHARED lib1_v3.cpp)
-  set_property(TARGET lib1Version2 PROPERTY INTERFACE_CONTAINER_SIZE_REQUIRED 1000)
+  set_property(TARGET lib1Version3 PROPERTY INTERFACE_CONTAINER_SIZE_REQUIRED 1000)
 
   add_executable(exe1 exe1.cpp)
   # CONTAINER_SIZE_REQUIRED will be "200"
diff --git a/Help/manual/cmake-commands.7.rst b/Help/manual/cmake-commands.7.rst
index 5b92b51..d0c2986 100644
--- a/Help/manual/cmake-commands.7.rst
+++ b/Help/manual/cmake-commands.7.rst
@@ -29,6 +29,7 @@ These commands may be used freely in CMake projects.
    /command/build_command
    /command/cmake_host_system_information
    /command/cmake_minimum_required
+   /command/cmake_parse_arguments
    /command/cmake_policy
    /command/configure_file
    /command/continue
diff --git a/Help/manual/cmake-developer.7.rst b/Help/manual/cmake-developer.7.rst
index a335384..7bfdcad 100644
--- a/Help/manual/cmake-developer.7.rst
+++ b/Help/manual/cmake-developer.7.rst
@@ -718,7 +718,7 @@ same consideration applies to macros, functions and imported targets.
   If False, do not try to use the relevant CMake wrapping command.
 
 ``Xxx_Yy_FOUND``
-  If False, optional Yy part of Xxx sytem is not available.
+  If False, optional Yy part of Xxx system is not available.
 
 ``Xxx_FOUND``
   Set to false, or undefined, if we haven't found, or don't want to use
diff --git a/Help/manual/cmake-modules.7.rst b/Help/manual/cmake-modules.7.rst
index c9219d5..10f05df 100644
--- a/Help/manual/cmake-modules.7.rst
+++ b/Help/manual/cmake-modules.7.rst
@@ -213,6 +213,7 @@ All Modules
    /module/FindwxWidgets
    /module/FindwxWindows
    /module/FindXCTest
+   /module/FindXalanC
    /module/FindXercesC
    /module/FindX11
    /module/FindXMLRPC
diff --git a/Help/manual/cmake-packages.7.rst b/Help/manual/cmake-packages.7.rst
index b9073a5..aebc5d9 100644
--- a/Help/manual/cmake-packages.7.rst
+++ b/Help/manual/cmake-packages.7.rst
@@ -89,7 +89,7 @@ a package is to set the ``CMAKE_PREFIX_PATH`` cache variable.
 
 Config-file packages are provided by upstream vendors as part of development
 packages, that is, they belong with the header files and any other files
-provided to assist downsteams in using the package.
+provided to assist downstreams in using the package.
 
 A set of variables which provide package status information are also set
 automatically when using a config-file package.  The ``<Package>_FOUND``
@@ -352,7 +352,7 @@ version-specific variables ``<Package>_VERSION``, ``<Package>_VERSION_MAJOR``,
 used to export the targets in the ``ClimbingStatsTargets`` export-set, defined
 previously by the :command:`install(TARGETS)` command. This command generates
 the ``ClimbingStatsTargets.cmake`` file to contain :prop_tgt:`IMPORTED`
-targets, suitable for use by downsteams and arranges to install it to
+targets, suitable for use by downstreams and arranges to install it to
 ``lib/cmake/ClimbingStats``.  The generated ``ClimbingStatsConfigVersion.cmake``
 and a ``cmake/ClimbingStatsConfig.cmake`` are installed to the same location,
 completing the package.
@@ -383,7 +383,7 @@ In this case, when using :command:`install(TARGETS)` the ``INCLUDES DESTINATION`
 was specified.  This causes the ``IMPORTED`` targets to have their
 :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` populated with the ``include``
 directory in the :variable:`CMAKE_INSTALL_PREFIX`.  When the ``IMPORTED``
-target is used by downsteam, it automatically consumes the entries from
+target is used by downstream, it automatically consumes the entries from
 that property.
 
 Creating a Package Configuration File
@@ -412,7 +412,7 @@ This can also be extended to cover dependencies:
   target_link_libraries(ClimbingStats PUBLIC Stats::Types)
 
 As the ``Stats::Types`` target is a ``PUBLIC`` dependency of ``ClimbingStats``,
-downsteams must also find the ``Stats`` package and link to the ``Stats::Types``
+downstreams must also find the ``Stats`` package and link to the ``Stats::Types``
 library.  The ``Stats`` package should be found in the ``ClimbingStatsConfig.cmake``
 file to ensure this.  The ``find_dependency`` macro from the
 :module:`CMakeFindDependencyMacro` helps with this by propagating
@@ -464,7 +464,7 @@ Creating a Package Configuration File for the Build Tree
 
 The :command:`export(EXPORT)` command creates an :prop_tgt:`IMPORTED` targets
 definition file which is specific to the build-tree, and is not relocatable.
-This can similiarly be used with a suitable package configuration file and
+This can similarly be used with a suitable package configuration file and
 package version file to define a package for the build tree which may be used
 without installation.  Consumers of the build tree can simply ensure that the
 :variable:`CMAKE_PREFIX_PATH` contains the build directory, or set the
diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
index 931363c..a41d484 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -191,6 +191,7 @@ Properties on Targets
    /prop_tgt/INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
    /prop_tgt/INTERPROCEDURAL_OPTIMIZATION_CONFIG
    /prop_tgt/INTERPROCEDURAL_OPTIMIZATION
+   /prop_tgt/IOS_INSTALL_COMBINED
    /prop_tgt/JOB_POOL_COMPILE
    /prop_tgt/JOB_POOL_LINK
    /prop_tgt/LABELS
diff --git a/Help/manual/cmake-toolchains.7.rst b/Help/manual/cmake-toolchains.7.rst
index 492fcac..7b294a8 100644
--- a/Help/manual/cmake-toolchains.7.rst
+++ b/Help/manual/cmake-toolchains.7.rst
@@ -151,6 +151,36 @@ target system prefixes, whereas executables which must be run as part of the bui
 should be found only on the host and not on the target. This is the purpose of
 the ``CMAKE_FIND_ROOT_PATH_MODE_*`` variables.
 
+.. _`Cray Cross-Compile`:
+
+Cross Compiling for the Cray Linux Environment
+----------------------------------------------
+
+Cross compiling for compute nodes in the Cray Linux Environment can be done
+without needing a separate toolchain file.  Specifying
+``-DCMAKE_SYSTEM_NAME=CrayLinuxEnvironment`` on the CMake command line will
+ensure that the appropriate build settings and search paths are configured.
+The platform will pull its configuration from the current environment
+variables and will configure a project to use the compiler wrappers from the
+Cray Programming Environment's ``PrgEnv-*`` modules if present and loaded.
+
+The default configuration of the Cray Programming Environment is to only
+support static libraries.  This can be overridden and shared libraries
+enabled by setting the ``CRAYPE_LINK_TYPE`` environment variable to
+``dynamic``.
+
+Running CMake without specifying :variable:`CMAKE_SYSTEM_NAME` will
+run the configure step in host mode assuming a standard Linux environment.
+If not overridden, the ``PrgEnv-*`` compiler wrappers will end up getting used,
+which if targeting the either the login node or compute node, is likely not the
+desired behavior.  The exception to this would be if you are building directly
+on a NID instead of cross-compiling from a login node. If trying to build
+software for a login node, you will need to either first unload the
+currently loaded ``PrgEnv-*`` module or explicitly tell CMake to use the
+system compilers in ``/usr/bin`` instead of the Cray wrappers.  If instead
+targeting a compute node is desired, just specify the
+:variable:`CMAKE_SYSTEM_NAME` as mentioned above.
+
 Cross Compiling using Clang
 ---------------------------
 
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index 2116900..15eaece 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -118,6 +118,7 @@ Variables that Change Behavior
    /variable/CMAKE_DISABLE_FIND_PACKAGE_PackageName
    /variable/CMAKE_ERROR_DEPRECATED
    /variable/CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION
+   /variable/CMAKE_EXPORT_COMPILE_COMMANDS
    /variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY
    /variable/CMAKE_SYSROOT
    /variable/CMAKE_FIND_APPBUNDLE
@@ -257,6 +258,7 @@ Variables that Control the Build
    /variable/CMAKE_INSTALL_NAME_DIR
    /variable/CMAKE_INSTALL_RPATH
    /variable/CMAKE_INSTALL_RPATH_USE_LINK_PATH
+   /variable/CMAKE_IOS_INSTALL_COMBINED
    /variable/CMAKE_LANG_COMPILER_LAUNCHER
    /variable/CMAKE_LANG_INCLUDE_WHAT_YOU_USE
    /variable/CMAKE_LANG_VISIBILITY_PRESET
diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst
index dac16bf..92f5230 100644
--- a/Help/manual/cmake.1.rst
+++ b/Help/manual/cmake.1.rst
@@ -167,16 +167,23 @@ Available commands are:
   Change the current working directory and run a command.
 
 ``compare_files <file1> <file2>``
-  Check if file1 is same as file2.
+  Check if ``<file1>`` is same as ``<file2>``. If files are the same,
+  then returns 0, if not itreturns 1.
 
-``copy <file> <destination>``
-  Copy file to destination (either file or directory).
+``copy <file>... <destination>``
+  Copy files to ``<destination>`` (either file or directory).
+  If multiple files are specified, the ``<destination>`` must be
+  directory and it must exist.
 
-``copy_directory <source> <destination>``
-  Copy directory 'source' content to directory 'destination'.
+``copy_directory <dir>... <destination>``
+  Copy directories to ``<destination>`` directory.
+  If ``<destination>`` directory does not exist it will be created.
 
-``copy_if_different <in-file> <out-file>``
-  Copy file if input has changed.
+``copy_if_different <file>... <destination>``
+  Copy files to ``<destination>`` (either file or directory) if
+  they have changed.
+  If multiple files are specified, the ``<destination>`` must be
+  directory and it must exist.
 
 ``echo [<string>...]``
   Displays arguments as text.
@@ -188,19 +195,23 @@ Available commands are:
   Run command in a modified environment.
 
 ``environment``
-  Display the current environment.
+  Display the current environment variables.
 
-``make_directory <dir>``
-  Create a directory.
+``make_directory <dir>...``
+  Create ``<dir>`` directories.  If necessary, create parent
+  directories too.  If a directory already exists it will be
+  silently ignored.
 
-``md5sum [<file>...]``
+``md5sum <file>...``
   Compute md5sum of files.
 
-``remove [-f] [<file>...]``
-  Remove the file(s), use ``-f`` to force it.
+``remove [-f] <file>...``
+  Remove the file(s), use ``-f`` to force it.  If a file does
+  not exist it will be silently ignored.
 
 ``remove_directory <dir>``
-  Remove a directory and its contents.
+  Remove a directory and its contents.  If a directory does
+  not exist it will be silently ignored.
 
 ``rename <oldname> <newname>``
   Rename a file or directory (on one volume).
@@ -233,7 +244,8 @@ Available commands are:
   Touch a file.
 
 ``touch_nocreate <file>``
-  Touch a file if it exists but do not create it.
+  Touch a file if it exists but do not create it.  If a file does
+  not exist it will be silently ignored.
 
 UNIX-specific Command-Line Tools
 --------------------------------
diff --git a/Help/module/FindXalanC.rst b/Help/module/FindXalanC.rst
new file mode 100644
index 0000000..b99d212
--- /dev/null
+++ b/Help/module/FindXalanC.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindXalanC.cmake
diff --git a/Help/policy/CMP0040.rst b/Help/policy/CMP0040.rst
index e746c03..d46baf6 100644
--- a/Help/policy/CMP0040.rst
+++ b/Help/policy/CMP0040.rst
@@ -1,18 +1,21 @@
 CMP0040
 -------
 
-The target in the TARGET signature of add_custom_command() must exist.
+The target in the ``TARGET`` signature of :command:`add_custom_command`
+must exist and must be defined in current directory.
 
 CMake 2.8.12 and lower silently ignored a custom command created with
-the TARGET signature of :command:`add_custom_command`
-if the target is unknown.
+the ``TARGET`` signature of :command:`add_custom_command`
+if the target is unknown or was defined outside the current directory.
 
-The OLD behavior for this policy is to ignore custom commands
-for unknown targets. The NEW behavior for this policy is to report an error
-if the target referenced in :command:`add_custom_command` is unknown.
+The ``OLD`` behavior for this policy is to ignore custom commands
+for unknown targets.  The ``NEW`` behavior for this policy is to report
+an error if the target referenced in :command:`add_custom_command` is
+unknown or was defined outside the current directory.
 
 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.
+|release| warns when the policy is not set and uses ``OLD`` behavior.
+Use the :command:`cmake_policy` command to set it to ``OLD`` or
+``NEW`` explicitly.
 
 .. include:: DEPRECATED.txt
diff --git a/Help/prop_dir/CLEAN_NO_CUSTOM.rst b/Help/prop_dir/CLEAN_NO_CUSTOM.rst
index 9a4173e..5ae78bf 100644
--- a/Help/prop_dir/CLEAN_NO_CUSTOM.rst
+++ b/Help/prop_dir/CLEAN_NO_CUSTOM.rst
@@ -1,7 +1,6 @@
 CLEAN_NO_CUSTOM
 ---------------
 
-Should the output of custom commands be left.
-
-If this is true then the outputs of custom commands for this directory
-will not be removed during the "make clean" stage.
+Set to true to tell :ref:`Makefile Generators` not to remove the outputs of
+custom commands for this directory during the ``make clean`` operation.
+This is ignored on other generators because it is not possible to implement.
diff --git a/Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst b/Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst
index 27f2929..69cdcb7 100644
--- a/Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst
+++ b/Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst
@@ -1,19 +1,23 @@
 MACOSX_PACKAGE_LOCATION
 -----------------------
 
-Place a source file inside a Mac OS X bundle, CFBundle, or framework.
+Place a source file inside a Application Bundle
+(:prop_tgt:`MACOSX_BUNDLE`), Core Foundation Bundle (:prop_tgt:`BUNDLE`),
+or Framework Bundle (:prop_tgt:`FRAMEWORK`).  It is applicable for OS X
+and iOS.
 
-Executable targets with the MACOSX_BUNDLE property set are built as
-Mac OS X application bundles on Apple platforms.  Shared library
-targets with the FRAMEWORK property set are built as Mac OS X
-frameworks on Apple platforms.  Module library targets with the BUNDLE
-property set are built as Mac OS X CFBundle bundles on Apple
-platforms.  Source files listed in the target with this property set
-will be copied to a directory inside the bundle or framework content
-folder specified by the property value.  For bundles the content
-folder is "<name>.app/Contents".  For frameworks the content folder is
-"<name>.framework/Versions/<version>".  For cfbundles the content
-folder is "<name>.bundle/Contents" (unless the extension is changed).
-See the PUBLIC_HEADER, PRIVATE_HEADER, and RESOURCE target properties
-for specifying files meant for Headers, PrivateHeaders, or Resources
-directories.
+Executable targets with the :prop_tgt:`MACOSX_BUNDLE` property set are
+built as OS X or iOS application bundles on Apple platforms.  Shared
+library targets with the :prop_tgt:`FRAMEWORK` property set are built as
+OS X or iOS frameworks on Apple platforms.  Module library targets with
+the :prop_tgt:`BUNDLE` property set are built as OS X ``CFBundle`` bundles
+on Apple platforms.  Source files listed in the target with this property
+set will be copied to a directory inside the bundle or framework content
+folder specified by the property value.  For OS X Application Bundles the
+content folder is ``<name>.app/Contents``.  For OS X Frameworks the
+content folder is ``<name>.framework/Versions/<version>``.  For OS X
+CFBundles the content folder is ``<name>.bundle/Contents`` (unless the
+extension is changed).  See the :prop_tgt:`PUBLIC_HEADER`,
+:prop_tgt:`PRIVATE_HEADER`, and :prop_tgt:`RESOURCE` target properties for
+specifying files meant for ``Headers``, ``PrivateHeaders``, or
+``Resources`` directories.
diff --git a/Help/prop_tgt/BUNDLE.rst b/Help/prop_tgt/BUNDLE.rst
index 166659f..075f017 100644
--- a/Help/prop_tgt/BUNDLE.rst
+++ b/Help/prop_tgt/BUNDLE.rst
@@ -1,9 +1,9 @@
 BUNDLE
 ------
 
-This target is a CFBundle on the Mac.
+This target is a ``CFBundle`` on the OS X.
 
 If a module library target has this property set to true it will be
-built as a CFBundle when built on the mac.  It will have the directory
-structure required for a CFBundle and will be suitable to be used for
+built as a ``CFBundle`` when built on the mac.  It will have the directory
+structure required for a ``CFBundle`` and will be suitable to be used for
 creating Browser Plugins or other application resources.
diff --git a/Help/prop_tgt/BUNDLE_EXTENSION.rst b/Help/prop_tgt/BUNDLE_EXTENSION.rst
index 94ac935..ea265b3 100644
--- a/Help/prop_tgt/BUNDLE_EXTENSION.rst
+++ b/Help/prop_tgt/BUNDLE_EXTENSION.rst
@@ -1,7 +1,7 @@
 BUNDLE_EXTENSION
 ----------------
 
-The file extension used to name a BUNDLE target on the Mac.
+The file extension used to name a :prop_tgt:`BUNDLE` target on the OS X and iOS.
 
-The default value is "bundle" - you can also use "plugin" or whatever
+The default value is ``bundle`` - you can also use ``plugin`` or whatever
 file extension is required by the host app for your bundle.
diff --git a/Help/prop_tgt/ENABLE_EXPORTS.rst b/Help/prop_tgt/ENABLE_EXPORTS.rst
index dfd4af7..9e22309 100644
--- a/Help/prop_tgt/ENABLE_EXPORTS.rst
+++ b/Help/prop_tgt/ENABLE_EXPORTS.rst
@@ -12,9 +12,9 @@ dependency on the executable is created for targets that link to it.
 For DLL platforms an import library will be created for the exported
 symbols and then used for linking.  All Windows-based systems
 including Cygwin are DLL platforms.  For non-DLL platforms that
-require all symbols to be resolved at link time, such as Mac OS X, the
+require all symbols to be resolved at link time, such as OS X, the
 module will "link" to the executable using a flag like
-"-bundle_loader".  For other non-DLL platforms the link rule is simply
+``-bundle_loader``.  For other non-DLL platforms the link rule is simply
 ignored since the dynamic loader will automatically bind symbols when
 the module is loaded.
 
diff --git a/Help/prop_tgt/FRAMEWORK.rst b/Help/prop_tgt/FRAMEWORK.rst
index dcb6d3b..6c212c3 100644
--- a/Help/prop_tgt/FRAMEWORK.rst
+++ b/Help/prop_tgt/FRAMEWORK.rst
@@ -1,11 +1,31 @@
 FRAMEWORK
 ---------
 
-This target is a framework on the Mac.
+Build ``SHARED`` library as Framework Bundle on the OS X and iOS.
 
-If a shared library target has this property set to true it will be
-built as a framework when built on the mac.  It will have the
+If a ``SHARED`` library target has this property set to ``TRUE`` it will be
+built as a framework when built on the OS X and iOS.  It will have the
 directory structure required for a framework and will be suitable to
 be used with the ``-framework`` option
 
-See also the :prop_tgt:`FRAMEWORK_VERSION` target property.
+To customize ``Info.plist`` file in the framework, use
+:prop_tgt:`MACOSX_FRAMEWORK_INFO_PLIST` target property.
+
+For OS X see also the :prop_tgt:`FRAMEWORK_VERSION` target property.
+
+Example of creation ``dynamicFramework``:
+
+.. code-block:: cmake
+
+  add_library(dynamicFramework SHARED
+              dynamicFramework.c
+              dynamicFramework.h
+  )
+  set_target_properties(dynamicFramework PROPERTIES
+    FRAMEWORK TRUE
+    FRAMEWORK_VERSION C
+    MACOSX_FRAMEWORK_IDENTIFIER com.cmake.dynamicFramework
+    MACOSX_FRAMEWORK_INFO_PLIST Info.plist
+    PUBLIC_HEADER dynamicFramework.h
+    XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
+  )
diff --git a/Help/prop_tgt/FRAMEWORK_VERSION.rst b/Help/prop_tgt/FRAMEWORK_VERSION.rst
index bf650a7..6aa3026 100644
--- a/Help/prop_tgt/FRAMEWORK_VERSION.rst
+++ b/Help/prop_tgt/FRAMEWORK_VERSION.rst
@@ -3,3 +3,6 @@ FRAMEWORK_VERSION
 
 Version of a framework created using the :prop_tgt:`FRAMEWORK` target
 property (e.g. ``A``).
+
+This property only affects OS X, as iOS doesn't have versioned
+directory structure.
diff --git a/Help/prop_tgt/IOS_INSTALL_COMBINED.rst b/Help/prop_tgt/IOS_INSTALL_COMBINED.rst
new file mode 100644
index 0000000..59f67a7
--- /dev/null
+++ b/Help/prop_tgt/IOS_INSTALL_COMBINED.rst
@@ -0,0 +1,11 @@
+IOS_INSTALL_COMBINED
+--------------------
+
+Build a combined (device and simulator) target when installing.
+
+When this property is set to set to false (which is the default) then it will
+either be built with the device SDK or the simulator SDK depending on the SDK
+set. But if this property is set to true then the target will at install time
+also be built for the corresponding SDK and combined into one library.
+
+This feature requires at least Xcode version 6.
diff --git a/Help/prop_tgt/MACOSX_BUNDLE.rst b/Help/prop_tgt/MACOSX_BUNDLE.rst
index ff21e61..7cd8046 100644
--- a/Help/prop_tgt/MACOSX_BUNDLE.rst
+++ b/Help/prop_tgt/MACOSX_BUNDLE.rst
@@ -1,12 +1,12 @@
 MACOSX_BUNDLE
 -------------
 
-Build an executable as an application bundle on Mac OS X.
+Build an executable as an Application Bundle on OS X or iOS.
 
-When this property is set to true the executable when built on Mac OS
-X will be created as an application bundle.  This makes it a GUI
-executable that can be launched from the Finder.  See the
-MACOSX_BUNDLE_INFO_PLIST target property for information about
-creation of the Info.plist file for the application bundle.  This
-property is initialized by the value of the variable
-CMAKE_MACOSX_BUNDLE if it is set when a target is created.
+When this property is set to ``TRUE`` the executable when built on OS X
+or iOS will be created as an application bundle.  This makes it
+a GUI executable that can be launched from the Finder.  See the
+:prop_tgt:`MACOSX_FRAMEWORK_INFO_PLIST` target property for information about
+creation of the ``Info.plist`` file for the application bundle.
+This property is initialized by the value of the variable
+:variable:`CMAKE_MACOSX_BUNDLE` if it is set when a target is created.
diff --git a/Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst b/Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst
index 07a933f..8515acc 100644
--- a/Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst
+++ b/Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst
@@ -1,10 +1,10 @@
 MACOSX_BUNDLE_INFO_PLIST
 ------------------------
 
-Specify a custom ``Info.plist`` template for a Mac OS X App Bundle.
+Specify a custom ``Info.plist`` template for a OS X and iOS Application Bundle.
 
 An executable target with :prop_tgt:`MACOSX_BUNDLE` enabled will be built as an
-application bundle on Mac OS X.  By default its ``Info.plist`` file is created
+application bundle on OS X.  By default its ``Info.plist`` file is created
 by configuring a template called ``MacOSXBundleInfo.plist.in`` located in the
 :variable:`CMAKE_MODULE_PATH`.  This property specifies an alternative template
 file name which may be a full path.
diff --git a/Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst b/Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst
index 548c3ac..58f31d4 100644
--- a/Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst
+++ b/Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst
@@ -1,10 +1,10 @@
 MACOSX_FRAMEWORK_INFO_PLIST
 ---------------------------
 
-Specify a custom ``Info.plist`` template for a Mac OS X Framework.
+Specify a custom ``Info.plist`` template for a OS X and iOS Framework.
 
 A library target with :prop_tgt:`FRAMEWORK` enabled will be built as a
-framework on Mac OS X.  By default its ``Info.plist`` file is created by
+framework on OS X.  By default its ``Info.plist`` file is created by
 configuring a template called ``MacOSXFrameworkInfo.plist.in`` located in the
 :variable:`CMAKE_MODULE_PATH`.  This property specifies an alternative template
 file name which may be a full path.
diff --git a/Help/prop_tgt/MACOSX_RPATH.rst b/Help/prop_tgt/MACOSX_RPATH.rst
index d3934ba..1f9a036 100644
--- a/Help/prop_tgt/MACOSX_RPATH.rst
+++ b/Help/prop_tgt/MACOSX_RPATH.rst
@@ -1,18 +1,23 @@
 MACOSX_RPATH
 ------------
 
-Whether to use rpaths on Mac OS X.
+Whether this target on OS X or iOS is located at runtime using rpaths.
+
+When this property is set to ``TRUE``, the directory portion of
+the ``install_name`` field of this shared library will be ``@rpath``
+unless overridden by :prop_tgt:`INSTALL_NAME_DIR`.  This indicates
+the shared library is to be found at runtime using runtime
+paths (rpaths).
 
-When this property is set to true, the directory portion of
-the "install_name" field of shared libraries will be ``@rpath``
-unless overridden by :prop_tgt:`INSTALL_NAME_DIR`.  Runtime
-paths will also be embedded in binaries using this target and
-can be controlled by the :prop_tgt:`INSTALL_RPATH` target property.
 This property is initialized by the value of the variable
 :variable:`CMAKE_MACOSX_RPATH` if it is set when a target is
 created.
 
-Policy CMP0042 was introduced to change the default value of
-MACOSX_RPATH to ON.  This is because use of ``@rpath`` is a
+Runtime paths will also be embedded in binaries using this target and
+can be controlled by the :prop_tgt:`INSTALL_RPATH` target property on
+the target linking to this target.
+
+Policy :policy:`CMP0042` was introduced to change the default value of
+``MACOSX_RPATH`` to ``TRUE``.  This is because use of ``@rpath`` is a
 more flexible and powerful alternative to ``@executable_path`` and
 ``@loader_path``.
diff --git a/Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst b/Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst
index f8fdcff..fb78177 100644
--- a/Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst
+++ b/Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst
@@ -1,7 +1,7 @@
 OSX_ARCHITECTURES_<CONFIG>
 --------------------------
 
-Per-configuration OS X binary architectures for a target.
+Per-configuration OS X and iOS binary architectures for a target.
 
 This property is the configuration-specific version of
 :prop_tgt:`OSX_ARCHITECTURES`.
diff --git a/Help/prop_tgt/PRIVATE_HEADER.rst b/Help/prop_tgt/PRIVATE_HEADER.rst
index da2127b..c4412ed 100644
--- a/Help/prop_tgt/PRIVATE_HEADER.rst
+++ b/Help/prop_tgt/PRIVATE_HEADER.rst
@@ -1,11 +1,11 @@
 PRIVATE_HEADER
 --------------
 
-Specify private header files in a FRAMEWORK shared library target.
+Specify private header files in a :prop_tgt:`FRAMEWORK` shared library target.
 
-Shared library targets marked with the FRAMEWORK property generate
-frameworks on OS X and normal shared libraries on other platforms.
+Shared library targets marked with the :prop_tgt:`FRAMEWORK` property generate
+frameworks on OS X, iOS and normal shared libraries on other platforms.
 This property may be set to a list of header files to be placed in the
 PrivateHeaders directory inside the framework folder.  On non-Apple
-platforms these headers may be installed using the PRIVATE_HEADER
-option to the install(TARGETS) command.
+platforms these headers may be installed using the ``PRIVATE_HEADER``
+option to the ``install(TARGETS)`` command.
diff --git a/Help/prop_tgt/PUBLIC_HEADER.rst b/Help/prop_tgt/PUBLIC_HEADER.rst
index 6e25d94..d4a636c 100644
--- a/Help/prop_tgt/PUBLIC_HEADER.rst
+++ b/Help/prop_tgt/PUBLIC_HEADER.rst
@@ -1,11 +1,11 @@
 PUBLIC_HEADER
 -------------
 
-Specify public header files in a FRAMEWORK shared library target.
+Specify public header files in a :prop_tgt:`FRAMEWORK` shared library target.
 
-Shared library targets marked with the FRAMEWORK property generate
-frameworks on OS X and normal shared libraries on other platforms.
+Shared library targets marked with the :prop_tgt:`FRAMEWORK` property generate
+frameworks on OS X, iOS and normal shared libraries on other platforms.
 This property may be set to a list of header files to be placed in the
-Headers directory inside the framework folder.  On non-Apple platforms
-these headers may be installed using the PUBLIC_HEADER option to the
-install(TARGETS) command.
+``Headers`` directory inside the framework folder.  On non-Apple platforms
+these headers may be installed using the ``PUBLIC_HEADER`` option to the
+``install(TARGETS)`` command.
diff --git a/Help/prop_tgt/RESOURCE.rst b/Help/prop_tgt/RESOURCE.rst
index 1e9921d..d837f7b 100644
--- a/Help/prop_tgt/RESOURCE.rst
+++ b/Help/prop_tgt/RESOURCE.rst
@@ -1,11 +1,61 @@
 RESOURCE
 --------
 
-Specify resource files in a FRAMEWORK shared library target.
-
-Shared library targets marked with the FRAMEWORK property generate
-frameworks on OS X and normal shared libraries on other platforms.
-This property may be set to a list of files to be placed in the
-Resources directory inside the framework folder.  On non-Apple
-platforms these files may be installed using the RESOURCE option to
-the install(TARGETS) command.
+Specify resource files in a :prop_tgt:`FRAMEWORK` or :prop_tgt:`BUNDLE`.
+
+Target marked with the :prop_tgt:`FRAMEWORK` or :prop_tgt:`BUNDLE` property
+generate framework or application bundle (both OS X and iOS is supported)
+or normal shared libraries on other platforms.
+This property may be set to a list of files to be placed in the corresponding
+directory (eg. ``Resources`` directory for OS X) inside the bundle.
+On non-Apple platforms these files may be installed using the ``RESOURCE``
+option to the ``install(TARGETS)`` command.
+
+Following example of Application Bundle:
+
+.. code-block:: cmake
+
+  add_executable(ExecutableTarget
+    addDemo.c
+    resourcefile.txt
+    appresourcedir/appres.txt
+  )
+
+  target_link_libraries(ExecutableTarget heymath mul)
+
+  set(RESOURCE_FILES
+    resourcefile.txt
+    appresourcedir/appres.txt
+  )
+
+  set_target_properties(ExecutableTarget PROPERTIES
+    MACOSX_BUNDLE TRUE
+    MACOSX_FRAMEWORK_IDENTIFIER org.cmake.ExecutableTarget
+    RESOURCE "${RESOURCE_FILES}"
+  )
+
+will produce flat structure for iOS systems::
+
+  ExecutableTarget.app
+    appres.txt
+    ExecutableTarget
+    Info.plist
+    resourcefile.txt
+
+For OS X systems it will produce following directory structure::
+
+  ExecutableTarget.app/
+    Contents
+      Info.plist
+      MacOS
+        ExecutableTarget
+      Resources
+        appres.txt
+        resourcefile.txt
+
+For Linux, such cmake script produce following files::
+
+  ExecutableTarget
+  Resources
+    appres.txt
+    resourcefile.txt
diff --git a/Help/release/3.5.rst b/Help/release/3.5.rst
new file mode 100644
index 0000000..009eb3c
--- /dev/null
+++ b/Help/release/3.5.rst
@@ -0,0 +1,185 @@
+CMake 3.5 Release Notes
+***********************
+
+.. only:: html
+
+  .. contents::
+
+Changes made since CMake 3.4 include the following.
+
+New Features
+============
+
+GUI
+---
+
+* The :manual:`cmake-gui(1)` gained options to control warnings about
+  deprecated functionality.
+
+* The :manual:`cmake-gui(1)` learned an option to set the toolset
+  to be used with VS IDE and Xcode generators, much like the
+  existing ``-T`` option to :manual:`cmake(1)`.
+
+* The :manual:`cmake-gui(1)` gained a Regular Expression Explorer which
+  may be used to create and evaluate regular expressions in real-time.
+  The explorer window is available via the ``Tools`` menu.
+
+Command-Line
+------------
+
+* The ``-Wdev`` and ``-Wno-dev`` :manual:`cmake(1)` options now also enable
+  and suppress the deprecated warnings output by default.
+
+* The suppression of developer warnings as errors can now be controlled with
+  the new ``-Werror=dev`` and ``-Wno-error=dev`` :manual:`cmake(1)` options.
+
+* The :manual:`cmake(1)` ``-E`` command-line tools ``copy``,
+  ``copy_if_different``, ``copy_directory``, and ``make_directory``
+  learned to support multiple input files or directories.
+
+Commands
+--------
+
+* The :command:`cmake_parse_arguments` command is now implemented natively.
+  The :module:`CMakeParseArguments` module remains as an empty placeholder
+  for compatibility.
+
+* The :command:`install(DIRECTORY)` command learned to support
+  :manual:`generator expressions <cmake-generator-expressions(7)>`
+  in the list of directories.
+
+Variables
+---------
+
+* The :variable:`CMAKE_ERROR_DEPRECATED` variable can now be set using the
+  ``-Werror=deprecated`` and ``-Wno-error=deprecated`` :manual:`cmake(1)`
+  options.
+
+* The :variable:`CMAKE_WARN_DEPRECATED` variable can now be set using the
+  ``-Wdeprecated`` and ``-Wno-deprecated`` :manual:`cmake(1)` options.
+
+Properties
+----------
+
+* The :prop_tgt:`VS_GLOBAL_<variable>` target property is now implemented
+  for VS 2010 and above.  Previously it worked only in VS 2008 and below.
+
+Modules
+-------
+
+* The :module:`ExternalProject` module learned a new ``GIT_REMOTE_NAME``
+  option to control the ``git clone --origin`` value.
+
+* The :module:`FindBoost` module now provides imported targets
+  such as ``Boost::boost`` and ``Boost::filesystem``.
+
+* The :module:`FindFLEX` module ``FLEX_TARGET`` macro learned a
+  new ``DEFINES_FILE`` option to specify a custom output header
+  to be generated.
+
+* The :module:`FindGTest` module now provides imported targets.
+
+* The :module:`FindGTK2` module, when ``GTK2_USE_IMPORTED_TARGETS`` is
+  enabled, now sets ``GTK2_LIBRARIES`` to contain the list of imported
+  targets instead of the paths to the libraries.  Moreover it now sets
+  a new ``GTK2_TARGETS`` variable containing all the targets imported.
+
+* The :module:`FindOpenMP` module learned to support Clang.
+
+* The :module:`FindOpenSSL` module gained a new
+  ``OPENSSL_MSVC_STATIC_RT`` option to search for libraries using
+  the MSVC static runtime.
+
+* The :module:`FindPNG` module now provides imported targets.
+
+* The :module:`FindTIFF` module now provides imported targets.
+
+* A :module:`FindXalanC` module was introduced to find the
+  Apache Xalan-C++ XSL transform processing library.
+
+* The :module:`FindXercesC` module now provides imported targets.
+
+Platforms
+---------
+
+* Support was added for the ARM Compiler (arm.com) with compiler id ``ARMCC``.
+
+* A new platform file for cross-compiling in the Cray Linux Environment to
+  target compute nodes was added.  See
+  :ref:`Cross Compiling for the Cray Linux Environment <Cray Cross-Compile>`
+  for usage details.
+
+* The :manual:`Compile Features <cmake-compile-features(7)>` functionality
+  is now aware of features supported by Clang compilers on Windows (MinGW).
+
+* When building for embedded Apple platforms like iOS CMake learned to build and
+  install combined targets which contain both a device and a simulator build.
+  This behavior can be enabled by setting the :prop_tgt:`IOS_INSTALL_COMBINED`
+  target property.
+
+CPack
+-----
+
+* The :module:`CPackDMG` module learned new variable to specify AppleScript
+  file run to customize appearance of ``DragNDrop`` installer folder,
+  including background image setting using supplied PNG or multi-resolution
+  TIFF file.  See the :variable:`CPACK_DMG_DS_STORE_SETUP_SCRIPT` and
+  :variable:`CPACK_DMG_BACKGROUND_IMAGE` variables.
+
+* The :module:`CPackDeb` module learned to set the optional config
+  file ``Source`` field using a monolithic or per-component variable.
+  See :variable:`CPACK_DEBIAN_PACKAGE_SOURCE`.
+
+* The :module:`CPackDeb` module learned to set Package, Section
+  and Priority control fields per-component.
+  See variables :variable:`CPACK_DEBIAN_<COMPONENT>_PACKAGE_SECTION` and
+  :variable:`CPACK_DEBIAN_<COMPONENT>_PACKAGE_PRIORITY`.
+
+* The :module:`CPack DragNDrop generator <CPackDMG>` learned to add
+  multi-lingual SLAs to a DMG which is presented to the user when they try to
+  mount the DMG.  See the :variable:`CPACK_DMG_SLA_LANGUAGES` and
+  :variable:`CPACK_DMG_SLA_DIR` variables for details.
+
+* The :module:`CPackNSIS` module learned new variables to add bitmaps to the
+  installer.  See the :variable:`CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP`
+  and :variable:`CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP` variables.
+
+* The :module:`CPackRPM` module learned to set Name and Group
+  control fields per-component.
+  See :variable:`CPACK_RPM_<component>_PACKAGE_NAME`
+  and :variable:`CPACK_RPM_<component>_PACKAGE_GROUP`.
+
+Other
+-----
+
+* Warnings about deprecated functionality are now enabled by default.
+  They may be suppressed with ``-Wno-deprecated`` or by setting the
+  :variable:`CMAKE_WARN_DEPRECATED` variable to false.
+
+Deprecated and Removed Features
+===============================
+
+* The :manual:`cmake(1)` ``-E time`` command now properly passes arguments
+  with spaces or special characters through to the child process.  This
+  may break scripts that worked around the bug with their own extra
+  quoting or escaping.
+
+* The :generator:`Xcode` generator was fixed to escape backslashes in
+  strings consistently with other generators.  Projects that previously
+  worked around the inconsistecy with an extra level of backslashes
+  conditioned on the Xcode generator must be updated to remove the
+  workaround for CMake 3.5 and greater.
+
+Other Changes
+=============
+
+* The :generator:`Visual Studio 14 2015` generator learned to map the
+  ``/debug:fastlink`` linker flag to the ``.vcxproj`` file property.
+
+* The :module:`FindGTK2` module now configures the ``GTK2::sigc++`` imported
+  target to enable c++11 on its dependents when using sigc++ 2.5.1 or higher.
+
+* The precompiled Windows binary provided on ``cmake.org`` is now a
+  ``.msi`` package instead of an installer executable.  One may need
+  to manually uninstall CMake versions lower than 3.5 before installing
+  the new package.
diff --git a/Help/release/index.rst b/Help/release/index.rst
index 5d1a3f7..6b7da3c 100644
--- a/Help/release/index.rst
+++ b/Help/release/index.rst
@@ -11,6 +11,7 @@ Releases
 .. toctree::
    :maxdepth: 1
 
+   3.5 <3.5>
    3.4 <3.4>
    3.3 <3.3>
    3.2 <3.2>
diff --git a/Help/variable/APPLE.rst b/Help/variable/APPLE.rst
index a8d2429..75eecf1 100644
--- a/Help/variable/APPLE.rst
+++ b/Help/variable/APPLE.rst
@@ -1,6 +1,6 @@
 APPLE
 -----
 
-``True`` if running on Mac OS X.
+``True`` if running on OS X.
 
-Set to ``true`` on Mac OS X.
+Set to ``true`` on OS X.
diff --git a/Help/variable/CMAKE_BINARY_DIR.rst b/Help/variable/CMAKE_BINARY_DIR.rst
index f8dd8ab..3b323b7 100644
--- a/Help/variable/CMAKE_BINARY_DIR.rst
+++ b/Help/variable/CMAKE_BINARY_DIR.rst
@@ -6,3 +6,8 @@ The path to the top level of the build tree.
 This is the full path to the top level of the current CMake build
 tree.  For an in-source build, this would be the same as
 :variable:`CMAKE_SOURCE_DIR`.
+
+When run in -P script mode, CMake sets the variables
+:variable:`CMAKE_BINARY_DIR`, :variable:`CMAKE_SOURCE_DIR`,
+:variable:`CMAKE_CURRENT_BINARY_DIR` and
+:variable:`CMAKE_CURRENT_SOURCE_DIR` to the current working directory.
diff --git a/Help/variable/CMAKE_CURRENT_BINARY_DIR.rst b/Help/variable/CMAKE_CURRENT_BINARY_DIR.rst
index cc3b639..40496b5 100644
--- a/Help/variable/CMAKE_CURRENT_BINARY_DIR.rst
+++ b/Help/variable/CMAKE_CURRENT_BINARY_DIR.rst
@@ -8,3 +8,8 @@ processed by cmake.  Each directory added by :command:`add_subdirectory` will
 create a binary directory in the build tree, and as it is being
 processed this variable will be set.  For in-source builds this is the
 current source directory being processed.
+
+When run in -P script mode, CMake sets the variables
+:variable:`CMAKE_BINARY_DIR`, :variable:`CMAKE_SOURCE_DIR`,
+:variable:`CMAKE_CURRENT_BINARY_DIR` and
+:variable:`CMAKE_CURRENT_SOURCE_DIR` to the current working directory.
diff --git a/Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst b/Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst
index db063a4..c1b755a 100644
--- a/Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst
+++ b/Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst
@@ -5,3 +5,8 @@ The path to the source directory currently being processed.
 
 This the full path to the source directory that is currently being
 processed by cmake.
+
+When run in -P script mode, CMake sets the variables
+:variable:`CMAKE_BINARY_DIR`, :variable:`CMAKE_SOURCE_DIR`,
+:variable:`CMAKE_CURRENT_BINARY_DIR` and
+:variable:`CMAKE_CURRENT_SOURCE_DIR` to the current working directory.
diff --git a/Help/variable/CMAKE_ENABLE_EXPORTS.rst b/Help/variable/CMAKE_ENABLE_EXPORTS.rst
index 1f9ba6f..9a877e7 100644
--- a/Help/variable/CMAKE_ENABLE_EXPORTS.rst
+++ b/Help/variable/CMAKE_ENABLE_EXPORTS.rst
@@ -6,15 +6,15 @@ Specify whether an executable exports symbols for loadable modules.
 Normally an executable does not export any symbols because it is the
 final program.  It is possible for an executable to export symbols to
 be used by loadable modules.  When this property is set to true CMake
-will allow other targets to "link" to the executable with the
+will allow other targets to ``link`` to the executable with the
 :command:`TARGET_LINK_LIBRARIES` command.  On all platforms a target-level
 dependency on the executable is created for targets that link to it.
 For DLL platforms an import library will be created for the exported
 symbols and then used for linking.  All Windows-based systems
 including Cygwin are DLL platforms.  For non-DLL platforms that
-require all symbols to be resolved at link time, such as Mac OS X, the
-module will "link" to the executable using a flag like
-"-bundle_loader".  For other non-DLL platforms the link rule is simply
+require all symbols to be resolved at link time, such as OS X, the
+module will ``link`` to the executable using a flag like
+``-bundle_loader``.  For other non-DLL platforms the link rule is simply
 ignored since the dynamic loader will automatically bind symbols when
 the module is loaded.
 
diff --git a/Help/variable/CMAKE_ERROR_DEPRECATED.rst b/Help/variable/CMAKE_ERROR_DEPRECATED.rst
index 277a4cc..f3a6738 100644
--- a/Help/variable/CMAKE_ERROR_DEPRECATED.rst
+++ b/Help/variable/CMAKE_ERROR_DEPRECATED.rst
@@ -1,8 +1,7 @@
 CMAKE_ERROR_DEPRECATED
 ----------------------
 
-Whether to issue deprecation errors for macros and functions.
+Whether to issue errors for deprecated functionality.
 
-If ``TRUE``, this can be used by macros and functions to issue fatal
-errors when deprecated macros or functions are used.  This variable is
-``FALSE`` by default.
+If ``TRUE``, use of deprecated functionality will issue fatal errors.
+If this variable is not set, CMake behaves as if it were set to ``FALSE``.
diff --git a/Help/variable/CMAKE_EXPORT_COMPILE_COMMANDS.rst b/Help/variable/CMAKE_EXPORT_COMPILE_COMMANDS.rst
new file mode 100644
index 0000000..8776279
--- /dev/null
+++ b/Help/variable/CMAKE_EXPORT_COMPILE_COMMANDS.rst
@@ -0,0 +1,30 @@
+CMAKE_EXPORT_COMPILE_COMMANDS
+-----------------------------
+
+Enable/Disable output of compile commands during generation.
+
+If enabled, generates a ``compile_commands.json`` file containing the exact
+compiler calls for all translation units of the project in machine-readable
+form.  The format of the JSON file looks like:
+
+.. code-block:: javascript
+
+  [
+    {
+      "directory": "/home/user/development/project",
+      "command": "/usr/bin/c++ ... -c ../foo/foo.cc",
+      "file": "../foo/foo.cc"
+    },
+
+    ...
+
+    {
+      "directory": "/home/user/development/project",
+      "command": "/usr/bin/c++ ... -c ../foo/bar.cc",
+      "file": "../foo/bar.cc"
+    }
+  ]
+
+.. note::
+  This option is implemented only by :ref:`Makefile Generators`
+  and the :generator:`Ninja`.  It is ignored on other generators.
diff --git a/Help/variable/CMAKE_HOST_SYSTEM_NAME.rst b/Help/variable/CMAKE_HOST_SYSTEM_NAME.rst
index e5e6f67..c673592 100644
--- a/Help/variable/CMAKE_HOST_SYSTEM_NAME.rst
+++ b/Help/variable/CMAKE_HOST_SYSTEM_NAME.rst
@@ -4,5 +4,5 @@ CMAKE_HOST_SYSTEM_NAME
 Name of the OS CMake is running on.
 
 On systems that have the uname command, this variable is set to the
-output of ``uname -s``.  ``Linux``, ``Windows``, and ``Darwin`` for Mac OS X
+output of ``uname -s``.  ``Linux``, ``Windows``, and ``Darwin`` for OS X
 are the values found on the big three operating systems.
diff --git a/Help/variable/CMAKE_INSTALL_NAME_DIR.rst b/Help/variable/CMAKE_INSTALL_NAME_DIR.rst
index 961d712..1f2d62b 100644
--- a/Help/variable/CMAKE_INSTALL_NAME_DIR.rst
+++ b/Help/variable/CMAKE_INSTALL_NAME_DIR.rst
@@ -1,7 +1,7 @@
 CMAKE_INSTALL_NAME_DIR
 ----------------------
 
-Mac OS X directory name for installed targets.
+OS X directory name for installed targets.
 
 ``CMAKE_INSTALL_NAME_DIR`` is used to initialize the
 :prop_tgt:`INSTALL_NAME_DIR` property on all targets.  See that target
diff --git a/Help/variable/CMAKE_IOS_INSTALL_COMBINED.rst b/Help/variable/CMAKE_IOS_INSTALL_COMBINED.rst
new file mode 100644
index 0000000..c5cb9b6
--- /dev/null
+++ b/Help/variable/CMAKE_IOS_INSTALL_COMBINED.rst
@@ -0,0 +1,8 @@
+CMAKE_IOS_INSTALL_COMBINED
+--------------------------
+
+Default value for :prop_tgt:`IOS_INSTALL_COMBINED` of targets.
+
+This variable is used to initialize the :prop_tgt:`IOS_INSTALL_COMBINED`
+property on all the targets.  See that target property for additional
+information.
diff --git a/Help/variable/CMAKE_LANG_COMPILER_ID.rst b/Help/variable/CMAKE_LANG_COMPILER_ID.rst
index 1c3b134..81976a9 100644
--- a/Help/variable/CMAKE_LANG_COMPILER_ID.rst
+++ b/Help/variable/CMAKE_LANG_COMPILER_ID.rst
@@ -11,6 +11,7 @@ include:
   Absoft = Absoft Fortran (absoft.com)
   ADSP = Analog VisualDSP++ (analog.com)
   AppleClang = Apple Clang (apple.com)
+  ARMCC = ARM Compiler (arm.com)
   CCur = Concurrent Fortran (ccur.com)
   Clang = LLVM Clang (clang.llvm.org)
   Cray = Cray Compiler (cray.com)
diff --git a/Help/variable/CMAKE_MACOSX_RPATH.rst b/Help/variable/CMAKE_MACOSX_RPATH.rst
index ac897c0..042e807 100644
--- a/Help/variable/CMAKE_MACOSX_RPATH.rst
+++ b/Help/variable/CMAKE_MACOSX_RPATH.rst
@@ -1,7 +1,7 @@
 CMAKE_MACOSX_RPATH
 -------------------
 
-Whether to use rpaths on Mac OS X.
+Whether to use rpaths on OS X and iOS.
 
 This variable is used to initialize the :prop_tgt:`MACOSX_RPATH` property on
 all targets.
diff --git a/Help/variable/CMAKE_OSX_ARCHITECTURES.rst b/Help/variable/CMAKE_OSX_ARCHITECTURES.rst
index b9de518..93916dd 100644
--- a/Help/variable/CMAKE_OSX_ARCHITECTURES.rst
+++ b/Help/variable/CMAKE_OSX_ARCHITECTURES.rst
@@ -1,7 +1,7 @@
 CMAKE_OSX_ARCHITECTURES
 -----------------------
 
-Target specific architectures for OS X.
+Target specific architectures for OS X and iOS.
 
 This variable is used to initialize the :prop_tgt:`OSX_ARCHITECTURES`
 property on each target as it is creaed.  See that target property
diff --git a/Help/variable/CMAKE_SOURCE_DIR.rst b/Help/variable/CMAKE_SOURCE_DIR.rst
index 3df0226..416fbe1 100644
--- a/Help/variable/CMAKE_SOURCE_DIR.rst
+++ b/Help/variable/CMAKE_SOURCE_DIR.rst
@@ -6,3 +6,8 @@ The path to the top level of the source tree.
 This is the full path to the top level of the current CMake source
 tree.  For an in-source build, this would be the same as
 :variable:`CMAKE_BINARY_DIR`.
+
+When run in -P script mode, CMake sets the variables
+:variable:`CMAKE_BINARY_DIR`, :variable:`CMAKE_SOURCE_DIR`,
+:variable:`CMAKE_CURRENT_BINARY_DIR` and
+:variable:`CMAKE_CURRENT_SOURCE_DIR` to the current working directory.
diff --git a/Help/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION.rst b/Help/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION.rst
index 6392849..e0be3a4 100644
--- a/Help/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION.rst
+++ b/Help/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION.rst
@@ -8,4 +8,5 @@ specification of a target Windows version to select a corresponding SDK.
 The :variable:`CMAKE_SYSTEM_VERSION` variable may be set to specify a
 version.  Otherwise CMake computes a default version based on the Windows
 SDK versions available.  The chosen Windows target version number is provided
-in ``CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION``.
+in ``CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION``.  If no Windows 10 SDK
+is available this value will be empty.
diff --git a/Help/variable/CMAKE_WARN_DEPRECATED.rst b/Help/variable/CMAKE_WARN_DEPRECATED.rst
index 662cbd8..4a224fa 100644
--- a/Help/variable/CMAKE_WARN_DEPRECATED.rst
+++ b/Help/variable/CMAKE_WARN_DEPRECATED.rst
@@ -1,7 +1,10 @@
 CMAKE_WARN_DEPRECATED
 ---------------------
 
-Whether to issue deprecation warnings for macros and functions.
+Whether to issue warnings for deprecated functionality.
 
-If ``TRUE``, this can be used by macros and functions to issue deprecation
-warnings.  This variable is ``FALSE`` by default.
+If not ``FALSE``, use of deprecated functionality will issue warnings.
+If this variable is not set, CMake behaves as if it were set to ``TRUE``.
+
+When running :manual:`cmake(1)`, this option can be enabled with the
+``-Wdeprecated`` option, or disabled with the ``-Wno-deprecated`` option.
diff --git a/Help/variable/CMAKE_XCODE_ATTRIBUTE_an-attribute.rst b/Help/variable/CMAKE_XCODE_ATTRIBUTE_an-attribute.rst
index 122b9f6..be683d6 100644
--- a/Help/variable/CMAKE_XCODE_ATTRIBUTE_an-attribute.rst
+++ b/Help/variable/CMAKE_XCODE_ATTRIBUTE_an-attribute.rst
@@ -8,3 +8,9 @@ in the generated Xcode project.  Ignored on other generators.
 
 See the :prop_tgt:`XCODE_ATTRIBUTE_<an-attribute>` target property
 to set attributes on a specific target.
+
+Contents of ``CMAKE_XCODE_ATTRIBUTE_<an-attribute>`` may use
+"generator expressions" with the syntax ``$<...>``.  See the
+:manual:`cmake-generator-expressions(7)` manual for available
+expressions.  See the :manual:`cmake-buildsystem(7)` manual
+for more on defining buildsystem properties.
diff --git a/Modules/BundleUtilities.cmake b/Modules/BundleUtilities.cmake
index b7975d3..45dda40 100644
--- a/Modules/BundleUtilities.cmake
+++ b/Modules/BundleUtilities.cmake
@@ -424,7 +424,9 @@ function(get_item_rpaths item rpaths_var)
     string(REGEX MATCHALL "rpath [^\n]+" load_cmds_ov "${load_cmds_ov}")
     string(REGEX REPLACE "rpath " "" load_cmds_ov "${load_cmds_ov}")
     if(load_cmds_ov)
-      gp_append_unique(${rpaths_var} "${load_cmds_ov}")
+      foreach(rpath ${load_cmds_ov})
+        gp_append_unique(${rpaths_var} "${rpath}")
+      endforeach()
     endif()
   endif()
 
diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in
index c72e338..f109a14 100644
--- a/Modules/CMakeCCompiler.cmake.in
+++ b/Modules/CMakeCCompiler.cmake.in
@@ -2,6 +2,7 @@ set(CMAKE_C_COMPILER "@CMAKE_C_COMPILER@")
 set(CMAKE_C_COMPILER_ARG1 "@CMAKE_C_COMPILER_ARG1@")
 set(CMAKE_C_COMPILER_ID "@CMAKE_C_COMPILER_ID@")
 set(CMAKE_C_COMPILER_VERSION "@CMAKE_C_COMPILER_VERSION@")
+set(CMAKE_C_COMPILER_WRAPPER "@CMAKE_C_COMPILER_WRAPPER@")
 set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "@CMAKE_C_STANDARD_COMPUTED_DEFAULT@")
 set(CMAKE_C_COMPILE_FEATURES "@CMAKE_C_COMPILE_FEATURES@")
 set(CMAKE_C90_COMPILE_FEATURES "@CMAKE_C90_COMPILE_FEATURES@")
diff --git a/Modules/CMakeCCompilerId.c.in b/Modules/CMakeCCompilerId.c.in
index 63f8787..5bfe0fd 100644
--- a/Modules/CMakeCCompilerId.c.in
+++ b/Modules/CMakeCCompilerId.c.in
@@ -21,6 +21,10 @@ char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
 char const* qnxnto = "INFO" ":" "qnxnto[]";
 #endif
 
+#if defined(__CRAYXE) || defined(__CRAYXC)
+char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]";
+#endif
+
 @CMAKE_C_COMPILER_ID_PLATFORM_CONTENT@
 @CMAKE_C_COMPILER_ID_ERROR_FOR_TEST@
 
@@ -55,6 +59,9 @@ int main(int argc, char* argv[])
 #ifdef SIMULATE_VERSION_MAJOR
   require += info_simulate_version[argc];
 #endif
+#if defined(__CRAYXE) || defined(__CRAYXC)
+  require += info_cray[argc];
+#endif
   require += info_language_dialect_default[argc];
   (void)argv;
   return require;
diff --git a/Modules/CMakeCInformation.cmake b/Modules/CMakeCInformation.cmake
index d2417aa..fa87ca8 100644
--- a/Modules/CMakeCInformation.cmake
+++ b/Modules/CMakeCInformation.cmake
@@ -18,6 +18,8 @@
 # It also loads a system - compiler - processor (or target hardware)
 # specific file, which is mainly useful for crosscompiling and embedded systems.
 
+include(CMakeLanguageInformation)
+
 # some compilers use different extensions (e.g. sdcc uses .rel)
 # so set the extension here first so it can be overridden by the compiler specific file
 if(UNIX)
@@ -60,6 +62,12 @@ if (NOT _INCLUDED_FILE)
   include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}
     OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
 endif ()
+
+# load any compiler-wrapper specific information
+if (CMAKE_C_COMPILER_WRAPPER)
+  __cmake_include_compiler_wrapper(C)
+endif ()
+
 # We specify the compiler information in the system file for some
 # platforms, but this language may not have been enabled when the file
 # was first included.  Include it again to get the language info.
diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in
index 52e44f6..9e90aea 100644
--- a/Modules/CMakeCXXCompiler.cmake.in
+++ b/Modules/CMakeCXXCompiler.cmake.in
@@ -2,6 +2,7 @@ set(CMAKE_CXX_COMPILER "@CMAKE_CXX_COMPILER@")
 set(CMAKE_CXX_COMPILER_ARG1 "@CMAKE_CXX_COMPILER_ARG1@")
 set(CMAKE_CXX_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@")
 set(CMAKE_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@")
+set(CMAKE_CXX_COMPILER_WRAPPER "@CMAKE_CXX_COMPILER_WRAPPER@")
 set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "@CMAKE_CXX_STANDARD_COMPUTED_DEFAULT@")
 set(CMAKE_CXX_COMPILE_FEATURES "@CMAKE_CXX_COMPILE_FEATURES@")
 set(CMAKE_CXX98_COMPILE_FEATURES "@CMAKE_CXX98_COMPILE_FEATURES@")
diff --git a/Modules/CMakeCXXCompilerId.cpp.in b/Modules/CMakeCXXCompilerId.cpp.in
index 61cd790..3e5c0fc 100644
--- a/Modules/CMakeCXXCompilerId.cpp.in
+++ b/Modules/CMakeCXXCompilerId.cpp.in
@@ -20,6 +20,10 @@ char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
 char const* qnxnto = "INFO" ":" "qnxnto[]";
 #endif
 
+#if defined(__CRAYXE) || defined(__CRAYXC)
+char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]";
+#endif
+
 @CMAKE_CXX_COMPILER_ID_PLATFORM_CONTENT@
 @CMAKE_CXX_COMPILER_ID_ERROR_FOR_TEST@
 
@@ -49,6 +53,9 @@ int main(int argc, char* argv[])
 #ifdef SIMULATE_VERSION_MAJOR
   require += info_simulate_version[argc];
 #endif
+#if defined(__CRAYXE) || defined(__CRAYXC)
+  require += info_cray[argc];
+#endif
   require += info_language_dialect_default[argc];
   (void)argv;
   return require;
diff --git a/Modules/CMakeCXXInformation.cmake b/Modules/CMakeCXXInformation.cmake
index 091627b..b35280f 100644
--- a/Modules/CMakeCXXInformation.cmake
+++ b/Modules/CMakeCXXInformation.cmake
@@ -18,6 +18,8 @@
 # It also loads a system - compiler - processor (or target hardware)
 # specific file, which is mainly useful for crosscompiling and embedded systems.
 
+include(CMakeLanguageInformation)
+
 # some compilers use different extensions (e.g. sdcc uses .rel)
 # so set the extension here first so it can be overridden by the compiler specific file
 if(UNIX)
@@ -59,6 +61,12 @@ if (NOT _INCLUDED_FILE)
   include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL
           RESULT_VARIABLE _INCLUDED_FILE)
 endif ()
+
+# load any compiler-wrapper specific information
+if (CMAKE_CXX_COMPILER_WRAPPER)
+  __cmake_include_compiler_wrapper(CXX)
+endif ()
+
 # We specify the compiler information in the system file for some
 # platforms, but this language may not have been enabled when the file
 # was first included.  Include it again to get the language info.
diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake
index 19bcbcc..cbc0055 100644
--- a/Modules/CMakeCompilerIdDetection.cmake
+++ b/Modules/CMakeCompilerIdDetection.cmake
@@ -89,6 +89,7 @@ function(compiler_id_detection outvar lang)
       MSVC
       ADSP
       IAR
+      ARMCC
     )
     if (lang STREQUAL C)
       list(APPEND ordered_compilers
diff --git a/Modules/CMakeDetermineASMCompiler.cmake b/Modules/CMakeDetermineASMCompiler.cmake
index 25af3e3..91111d2 100644
--- a/Modules/CMakeDetermineASMCompiler.cmake
+++ b/Modules/CMakeDetermineASMCompiler.cmake
@@ -92,6 +92,10 @@ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
   set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_IAR )
   set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_IAR "IAR Assembler")
 
+  list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS ARMCC)
+  set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_ARMCC )
+  set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_ARMCC "(ARM Compiler)|(ARM Assembler)")
+
   include(CMakeDetermineCompilerId)
   CMAKE_DETERMINE_COMPILER_ID_VENDOR(ASM${ASM_DIALECT})
 
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake
index 81c2509..feae1c4 100644
--- a/Modules/CMakeDetermineCompilerId.cmake
+++ b/Modules/CMakeDetermineCompilerId.cmake
@@ -107,6 +107,7 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
     PARENT_SCOPE)
   set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "${CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX}" PARENT_SCOPE)
   set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE)
+  set(CMAKE_${lang}_COMPILER_WRAPPER "${CMAKE_${lang}_COMPILER_WRAPPER}" PARENT_SCOPE)
   set(CMAKE_${lang}_SIMULATE_ID "${CMAKE_${lang}_SIMULATE_ID}" PARENT_SCOPE)
   set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
   set(CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT "${CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT}" PARENT_SCOPE)
@@ -182,9 +183,6 @@ Id flags: ${testflags}
       set(v 6)
       set(ext dsp)
     endif()
-    if("${id_platform}" STREQUAL "Itanium")
-      set(id_platform ia64)
-    endif()
     if(CMAKE_VS_PLATFORM_TOOLSET)
       if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")
         set(id_toolset "<NdkToolchainVersion>${CMAKE_VS_PLATFORM_TOOLSET}</NdkToolchainVersion>")
@@ -435,6 +433,7 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
     set(HAVE_COMPILER_VERSION_MINOR 0)
     set(HAVE_COMPILER_VERSION_PATCH 0)
     set(HAVE_COMPILER_VERSION_TWEAK 0)
+    set(COMPILER_WRAPPER)
     set(DIGIT_VALUE_1 1)
     set(DIGIT_VALUE_2 10)
     set(DIGIT_VALUE_3 100)
@@ -476,6 +475,9 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
           endif()
         endforeach()
       endforeach()
+      if("${info}" MATCHES "INFO:compiler_wrapper\\[([^]\"]*)\\]")
+        set(COMPILER_WRAPPER "${CMAKE_MATCH_1}")
+      endif()
       if("${info}" MATCHES "INFO:simulate\\[([^]\"]*)\\]")
         set(SIMULATE_ID "${CMAKE_MATCH_1}")
       endif()
@@ -588,6 +590,7 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
   set(MSVC_${lang}_ARCHITECTURE_ID "${MSVC_${lang}_ARCHITECTURE_ID}"
     PARENT_SCOPE)
   set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE)
+  set(CMAKE_${lang}_COMPILER_WRAPPER "${COMPILER_WRAPPER}" PARENT_SCOPE)
   set(CMAKE_${lang}_SIMULATE_ID "${CMAKE_${lang}_SIMULATE_ID}" PARENT_SCOPE)
   set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
   set(CMAKE_EXECUTABLE_FORMAT "${CMAKE_EXECUTABLE_FORMAT}" PARENT_SCOPE)
diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake
index 911ffac..ccafb07 100644
--- a/Modules/CMakeDetermineFortranCompiler.cmake
+++ b/Modules/CMakeDetermineFortranCompiler.cmake
@@ -54,6 +54,7 @@ else()
     if(NOT CMAKE_Fortran_COMPILER_INIT)
       # Known compilers:
       #  f77/f90/f95: generic compiler names
+      #  ftn: Cray fortran compiler wrapper
       #  g77: GNU Fortran 77 compiler
       #  gfortran: putative GNU Fortran 95+ compiler (in progress)
       #  fort77: native F77 compiler under HP-UX (and some older Crays)
@@ -73,6 +74,7 @@ else()
       #  then 77 or older compilers, gnu is always last in the group,
       #  so if you paid for a compiler it is picked by default.
       set(CMAKE_Fortran_COMPILER_LIST
+        ftn
         ifort ifc af95 af90 efc f95 pathf2003 pathf95 pgf95 pgfortran lf95 xlf95
         fort gfortran gfortran-4 g95 f90 pathf90 pgf90 xlf90 epcf90 fort77
         frt pgf77 xlf fl32 af77 g77 f77
diff --git a/Modules/CMakeForceCompiler.cmake b/Modules/CMakeForceCompiler.cmake
index 1d8b110..faa0dc5 100644
--- a/Modules/CMakeForceCompiler.cmake
+++ b/Modules/CMakeForceCompiler.cmake
@@ -2,11 +2,25 @@
 # CMakeForceCompiler
 # ------------------
 #
-#
-#
-# This module defines macros intended for use by cross-compiling
-# toolchain files when CMake is not able to automatically detect the
-# compiler identification.
+# Discouraged.  Avoid using this module if possible.  It will be deprecated
+# by a future version of CMake once alternatives have been provided for all
+# toolchain file use cases.
+#
+# The macros provided by this module were once intended for use by
+# cross-compiling toolchain files when CMake was not able to automatically
+# detect the compiler identification.  Since the introduction of this module,
+# CMake's compiler identification capabilities have improved and can now be
+# taught to recognize any compiler.  Furthermore, the suite of information
+# CMake detects from a compiler is now too extensive to be provided by
+# toolchain files using these macros.
+#
+# The only known remaining use case for these macros is to write toolchain
+# files for cross-compilers that cannot link binaries without special flags or
+# custom linker scripts.  These macros cause CMake to skip checks it normally
+# performs as part of enabling a language and introspecting the toolchain.
+# However, skipping these checks may limit some generation functionality.
+#
+# -------------------------------------------------------------------------
 #
 # Macro CMAKE_FORCE_C_COMPILER has the following signature:
 #
diff --git a/Modules/CMakeFortranCompiler.cmake.in b/Modules/CMakeFortranCompiler.cmake.in
index 14fdd60..2a4bea4 100644
--- a/Modules/CMakeFortranCompiler.cmake.in
+++ b/Modules/CMakeFortranCompiler.cmake.in
@@ -2,6 +2,7 @@ set(CMAKE_Fortran_COMPILER "@CMAKE_Fortran_COMPILER@")
 set(CMAKE_Fortran_COMPILER_ARG1 "@CMAKE_Fortran_COMPILER_ARG1@")
 set(CMAKE_Fortran_COMPILER_ID "@CMAKE_Fortran_COMPILER_ID@")
 set(CMAKE_Fortran_COMPILER_VERSION "@CMAKE_Fortran_COMPILER_VERSION@")
+set(CMAKE_Fortran_COMPILER_WRAPPER "@CMAKE_Fortran_COMPILER_WRAPPER@")
 set(CMAKE_Fortran_PLATFORM_ID "@CMAKE_Fortran_PLATFORM_ID@")
 set(CMAKE_Fortran_SIMULATE_ID "@CMAKE_Fortran_SIMULATE_ID@")
 set(CMAKE_Fortran_SIMULATE_VERSION "@CMAKE_Fortran_SIMULATE_VERSION@")
diff --git a/Modules/CMakeFortranCompilerId.F.in b/Modules/CMakeFortranCompilerId.F.in
index 2f7f40e..67cda3b 100644
--- a/Modules/CMakeFortranCompilerId.F.in
+++ b/Modules/CMakeFortranCompilerId.F.in
@@ -110,6 +110,9 @@
 #       endif
         PRINT *, 'INFO:compiler[]'
 #endif
+#if defined(__CRAYXE) || defined(__CRAYXC)
+        PRINT *, 'INFO:compiler_wrapper[CrayPrgEnv]'
+#endif
 
 #if 0
 ! Identify the platform
diff --git a/Modules/CMakeFortranInformation.cmake b/Modules/CMakeFortranInformation.cmake
index 79393d3..1fd0972 100644
--- a/Modules/CMakeFortranInformation.cmake
+++ b/Modules/CMakeFortranInformation.cmake
@@ -12,6 +12,8 @@
 # (To distribute this file outside of CMake, substitute the full
 #  License text for the above reference.)
 
+include(CMakeLanguageInformation)
+
 # This file sets the basic flags for the Fortran language in CMake.
 # It also loads the available platform file for the system-compiler
 # if it exists.
@@ -36,6 +38,12 @@ if (NOT _INCLUDED_FILE)
   include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL
           RESULT_VARIABLE _INCLUDED_FILE)
 endif ()
+
+# load any compiler-wrapper specific information
+if (CMAKE_Fortran_COMPILER_WRAPPER)
+  __cmake_include_compiler_wrapper(Fortran)
+endif ()
+
 # We specify the compiler information in the system file for some
 # platforms, but this language may not have been enabled when the file
 # was first included.  Include it again to get the language info.
diff --git a/Modules/CMakeIOSInstallCombined.cmake b/Modules/CMakeIOSInstallCombined.cmake
new file mode 100644
index 0000000..f052a3b
--- /dev/null
+++ b/Modules/CMakeIOSInstallCombined.cmake
@@ -0,0 +1,297 @@
+
+#=============================================================================
+# Copyright 2014-2015 Ruslan Baratov, Gregor Jasny
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+# Function to print messages of this module
+function(_ios_install_combined_message)
+  message("[iOS combined] " ${ARGN})
+endfunction()
+
+# Get build settings for the current target/config/SDK by running
+# `xcodebuild -sdk ... -showBuildSettings` and parsing it's output
+function(_ios_install_combined_get_build_setting sdk variable resultvar)
+  if("${sdk}" STREQUAL "")
+    message(FATAL_ERROR "`sdk` is empty")
+  endif()
+
+  if("${variable}" STREQUAL "")
+    message(FATAL_ERROR "`variable` is empty")
+  endif()
+
+  if("${resultvar}" STREQUAL "")
+    message(FATAL_ERROR "`resultvar` is empty")
+  endif()
+
+  set(
+      cmd
+      xcodebuild -showBuildSettings
+      -sdk "${sdk}"
+      -target "${CURRENT_TARGET}"
+      -config "${CURRENT_CONFIG}"
+  )
+
+  execute_process(
+      COMMAND ${cmd}
+      WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
+      RESULT_VARIABLE result
+      OUTPUT_VARIABLE output
+  )
+
+  if(NOT result EQUAL 0)
+    message(FATAL_ERROR "Command failed (${result}): ${cmd}")
+  endif()
+
+  if(NOT output MATCHES " ${variable} = ([^\n]*)")
+    message(FATAL_ERROR "${variable} not found.")
+  endif()
+
+  set("${resultvar}" "${CMAKE_MATCH_1}" PARENT_SCOPE)
+endfunction()
+
+# Get architectures of given SDK (iphonesimulator/iphoneos)
+function(_ios_install_combined_get_valid_archs sdk resultvar)
+  cmake_policy(SET CMP0007 NEW)
+
+  if("${resultvar}" STREQUAL "")
+    message(FATAL_ERROR "`resultvar` is empty")
+  endif()
+
+  _ios_install_combined_get_build_setting("${sdk}" "VALID_ARCHS" valid_archs)
+
+  separate_arguments(valid_archs)
+  list(REMOVE_ITEM valid_archs "") # remove empty elements
+  list(REMOVE_DUPLICATES valid_archs)
+
+  set("${resultvar}" "${valid_archs}" PARENT_SCOPE)
+endfunction()
+
+# Final target can contain more architectures that specified by SDK. This
+# function will run 'lipo -info' and parse output. Result will be returned
+# as a CMake list.
+function(_ios_install_combined_get_real_archs filename resultvar)
+  set(cmd "${_lipo_path}" -info "${filename}")
+  execute_process(
+      COMMAND ${cmd}
+      RESULT_VARIABLE result
+      OUTPUT_VARIABLE output
+      ERROR_VARIABLE output
+      OUTPUT_STRIP_TRAILING_WHITESPACE
+      ERROR_STRIP_TRAILING_WHITESPACE
+  )
+  if(NOT result EQUAL 0)
+    message(
+        FATAL_ERROR "Command failed (${result}): ${cmd}\n\nOutput:\n${output}"
+    )
+  endif()
+
+  if(NOT output MATCHES "(Architectures in the fat file: [^\n]+ are|Non-fat file: [^\n]+ is architecture): ([^\n]*)")
+    message(FATAL_ERROR "Could not detect architecture from: ${output}")
+  endif()
+
+  separate_arguments(CMAKE_MATCH_2)
+  set(${resultvar} ${CMAKE_MATCH_2} PARENT_SCOPE)
+endfunction()
+
+# Run build command for the given SDK
+function(_ios_install_combined_build sdk)
+  if("${sdk}" STREQUAL "")
+    message(FATAL_ERROR "`sdk` is empty")
+  endif()
+
+  _ios_install_combined_message("Build `${CURRENT_TARGET}` for `${sdk}`")
+
+  execute_process(
+      COMMAND
+      "${CMAKE_COMMAND}"
+      --build
+      .
+      --target "${CURRENT_TARGET}"
+      --config ${CURRENT_CONFIG}
+      --
+      -sdk "${sdk}"
+      WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
+      RESULT_VARIABLE result
+  )
+
+  if(NOT result EQUAL 0)
+    message(FATAL_ERROR "Build failed")
+  endif()
+endfunction()
+
+# Remove given architecture from file. This step needed only in rare cases
+# when target was built in "unusual" way. Emit warning message.
+function(_ios_install_combined_remove_arch lib arch)
+  _ios_install_combined_message(
+    "Warning! Unexpected architecture `${arch}` detected and will be removed "
+    "from file `${lib}`")
+  set(cmd "${_lipo_path}" -remove ${arch} -output ${lib} ${lib})
+  execute_process(
+      COMMAND ${cmd}
+      RESULT_VARIABLE result
+      OUTPUT_VARIABLE output
+      ERROR_VARIABLE output
+      OUTPUT_STRIP_TRAILING_WHITESPACE
+      ERROR_STRIP_TRAILING_WHITESPACE
+  )
+  if(NOT result EQUAL 0)
+    message(
+        FATAL_ERROR "Command failed (${result}): ${cmd}\n\nOutput:\n${output}"
+    )
+  endif()
+endfunction()
+
+# Check that 'lib' contains only 'archs' architectures (remove others).
+function(_ios_install_combined_keep_archs lib archs)
+  _ios_install_combined_get_real_archs("${lib}" real_archs)
+  set(archs_to_remove ${real_archs})
+  list(REMOVE_ITEM archs_to_remove ${archs})
+  foreach(x ${archs_to_remove})
+    _ios_install_combined_remove_arch("${lib}" "${x}")
+  endforeach()
+endfunction()
+
+function(_ios_install_combined_detect_sdks this_sdk_var corr_sdk_var)
+  cmake_policy(SET CMP0057 NEW)
+
+  set(this_sdk "$ENV{PLATFORM_NAME}")
+  if("${this_sdk}" STREQUAL "")
+    message(FATAL_ERROR "Environment variable PLATFORM_NAME is empty")
+  endif()
+
+  set(all_platforms "$ENV{SUPPORTED_PLATFORMS}")
+  if("${all_platforms}" STREQUAL "")
+    message(FATAL_ERROR "Environment variable SUPPORTED_PLATFORMS is empty")
+  endif()
+
+  separate_arguments(all_platforms)
+  if(NOT this_sdk IN_LIST all_platforms)
+    message(FATAL_ERROR "`${this_sdk}` not found in `${all_platforms}`")
+  endif()
+
+  list(REMOVE_ITEM all_platforms "" "${this_sdk}")
+  list(LENGTH all_platforms all_platforms_length)
+  if(NOT all_platforms_length EQUAL 1)
+    message(FATAL_ERROR "Expected one element: ${all_platforms}")
+  endif()
+
+  set(${this_sdk_var} "${this_sdk}" PARENT_SCOPE)
+  set(${corr_sdk_var} "${all_platforms}" PARENT_SCOPE)
+endfunction()
+
+# Create combined binary for the given target.
+#
+# Preconditions:
+#  * Target already installed at ${destination}
+#    for the ${PLATFORM_NAME} platform
+#
+# This function will:
+#  * Run build for the lacking platform, i.e. opposite to the ${PLATFORM_NAME}
+#  * Fuse both libraries by running lipo
+function(ios_install_combined target destination)
+  if("${target}" STREQUAL "")
+    message(FATAL_ERROR "`target` is empty")
+  endif()
+
+  if("${destination}" STREQUAL "")
+    message(FATAL_ERROR "`destination` is empty")
+  endif()
+
+  if(NOT IS_ABSOLUTE "${destination}")
+    message(FATAL_ERROR "`destination` is not absolute: ${destination}")
+  endif()
+
+  if(IS_DIRECTORY "${destination}" OR IS_SYMLINK "${destination}")
+    message(FATAL_ERROR "`destination` is no regular file: ${destination}")
+  endif()
+
+  if("${CMAKE_BINARY_DIR}" STREQUAL "")
+    message(FATAL_ERROR "`CMAKE_BINARY_DIR` is empty")
+  endif()
+
+  if(NOT IS_DIRECTORY "${CMAKE_BINARY_DIR}")
+    message(FATAL_ERROR "Is not a directory: ${CMAKE_BINARY_DIR}")
+  endif()
+
+  if("${CMAKE_INSTALL_CONFIG_NAME}" STREQUAL "")
+    message(FATAL_ERROR "CMAKE_INSTALL_CONFIG_NAME is empty")
+  endif()
+
+  set(cmd xcrun -f lipo)
+  execute_process(
+      COMMAND ${cmd}
+      RESULT_VARIABLE result
+      OUTPUT_VARIABLE output
+      ERROR_VARIABLE output
+      OUTPUT_STRIP_TRAILING_WHITESPACE
+      ERROR_STRIP_TRAILING_WHITESPACE
+  )
+  if(NOT result EQUAL 0)
+    message(
+        FATAL_ERROR "Command failed (${result}): ${cmd}\n\nOutput:\n${output}"
+    )
+  endif()
+  set(_lipo_path ${output})
+
+  set(CURRENT_CONFIG "${CMAKE_INSTALL_CONFIG_NAME}")
+  set(CURRENT_TARGET "${target}")
+
+  _ios_install_combined_message("Target: ${CURRENT_TARGET}")
+  _ios_install_combined_message("Config: ${CURRENT_CONFIG}")
+  _ios_install_combined_message("Destination: ${destination}")
+
+  # Get SDKs
+  _ios_install_combined_detect_sdks(this_sdk corr_sdk)
+
+  # Get architectures of the target
+  _ios_install_combined_get_valid_archs("${corr_sdk}" corr_valid_archs)
+  _ios_install_combined_get_valid_archs("${this_sdk}" this_valid_archs)
+
+  # Return if there are no valid architectures for the SDK.
+  # (note that library already installed)
+  if("${corr_valid_archs}" STREQUAL "")
+    _ios_install_combined_message(
+        "No architectures detected for `${corr_sdk}` (skip)"
+    )
+    return()
+  endif()
+
+  # Trigger build of corresponding target
+  _ios_install_combined_build("${corr_sdk}")
+
+  # Get location of the library in build directory
+  _ios_install_combined_get_build_setting(
+    "${corr_sdk}" "CONFIGURATION_BUILD_DIR" corr_build_dir)
+  _ios_install_combined_get_build_setting(
+    "${corr_sdk}" "EXECUTABLE_PATH" corr_executable_path)
+  set(corr "${corr_build_dir}/${corr_executable_path}")
+
+  _ios_install_combined_keep_archs("${corr}" "${corr_valid_archs}")
+  _ios_install_combined_keep_archs("${destination}" "${this_valid_archs}")
+
+  _ios_install_combined_message("Current: ${destination}")
+  _ios_install_combined_message("Corresponding: ${corr}")
+
+  set(cmd "${_lipo_path}" -create ${corr} ${destination} -output ${destination})
+
+  execute_process(
+      COMMAND ${cmd}
+      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+      RESULT_VARIABLE result
+  )
+
+  if(NOT result EQUAL 0)
+    message(FATAL_ERROR "Command failed: ${cmd}")
+  endif()
+
+  _ios_install_combined_message("Install done: ${destination}")
+endfunction()
diff --git a/Modules/CMakeLanguageInformation.cmake b/Modules/CMakeLanguageInformation.cmake
new file mode 100644
index 0000000..e03d149
--- /dev/null
+++ b/Modules/CMakeLanguageInformation.cmake
@@ -0,0 +1,37 @@
+
+#=============================================================================
+# Copyright 2015 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+# This file contains common code blocks used by all the language information
+# files
+
+# load any compiler-wrapper specific information
+macro(__cmake_include_compiler_wrapper lang)
+  set(_INCLUDED_WRAPPER_FILE 0)
+  if (CMAKE_${lang}_COMPILER_ID)
+    include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_${lang}_COMPILER_WRAPPER}-${CMAKE_${lang}_COMPILER_ID}-${lang} OPTIONAL RESULT_VARIABLE _INCLUDED_WRAPPER_FILE)
+  endif()
+  if (NOT _INCLUDED_WRAPPER_FILE)
+    include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_${lang}_COMPILER_WRAPPER}-${lang} OPTIONAL RESULT_VARIABLE _INCLUDED_WRAPPER_FILE)
+  endif ()
+
+  # No platform - wrapper - lang information so maybe there's just wrapper - lang information
+  if(NOT _INCLUDED_WRAPPER_FILE)
+    if (CMAKE_${lang}_COMPILER_ID)
+      include(Compiler/${CMAKE_${lang}_COMPILER_WRAPPER}-${CMAKE_${lang}_COMPILER_ID}-${lang} OPTIONAL RESULT_VARIABLE _INCLUDED_WRAPPER_FILE)
+    endif()
+    if (NOT _INCLUDED_WRAPPER_FILE)
+      include(Compiler/${CMAKE_${lang}_COMPILER_WRAPPER}-${lang} OPTIONAL RESULT_VARIABLE _INCLUDED_WRAPPER_FILE)
+    endif ()
+  endif ()
+endmacro ()
diff --git a/Modules/CMakeParseArguments.cmake b/Modules/CMakeParseArguments.cmake
index 8553f38..fc64ab9 100644
--- a/Modules/CMakeParseArguments.cmake
+++ b/Modules/CMakeParseArguments.cmake
@@ -2,86 +2,10 @@
 # CMakeParseArguments
 # -------------------
 #
-#
-#
-# CMAKE_PARSE_ARGUMENTS(<prefix> <options> <one_value_keywords>
-# <multi_value_keywords> args...)
-#
-# CMAKE_PARSE_ARGUMENTS() is intended to be used in macros or functions
-# for parsing the arguments given to that macro or function.  It
-# processes the arguments and defines a set of variables which hold the
-# values of the respective options.
-#
-# The <options> argument contains all options for the respective macro,
-# i.e.  keywords which can be used when calling the macro without any
-# value following, like e.g.  the OPTIONAL keyword of the install()
-# command.
-#
-# The <one_value_keywords> argument contains all keywords for this macro
-# which are followed by one value, like e.g.  DESTINATION keyword of the
-# install() command.
-#
-# The <multi_value_keywords> argument contains all keywords for this
-# macro which can be followed by more than one value, like e.g.  the
-# TARGETS or FILES keywords of the install() command.
-#
-# When done, CMAKE_PARSE_ARGUMENTS() will have defined for each of the
-# keywords listed in <options>, <one_value_keywords> and
-# <multi_value_keywords> a variable composed of the given <prefix>
-# followed by "_" and the name of the respective keyword.  These
-# variables will then hold the respective value from the argument list.
-# For the <options> keywords this will be TRUE or FALSE.
-#
-# All remaining arguments are collected in a variable
-# <prefix>_UNPARSED_ARGUMENTS, this can be checked afterwards to see
-# whether your macro was called with unrecognized parameters.
-#
-# As an example here a my_install() macro, which takes similar arguments
-# as the real install() command:
-#
-# ::
-#
-#    function(MY_INSTALL)
-#      set(options OPTIONAL FAST)
-#      set(oneValueArgs DESTINATION RENAME)
-#      set(multiValueArgs TARGETS CONFIGURATIONS)
-#      cmake_parse_arguments(MY_INSTALL "${options}" "${oneValueArgs}"
-#                            "${multiValueArgs}" ${ARGN} )
-#      ...
-#
-#
-#
-# Assume my_install() has been called like this:
-#
-# ::
-#
-#    my_install(TARGETS foo bar DESTINATION bin OPTIONAL blub)
-#
-#
-#
-# After the cmake_parse_arguments() call the macro will have set the
-# following variables:
-#
-# ::
-#
-#    MY_INSTALL_OPTIONAL = TRUE
-#    MY_INSTALL_FAST = FALSE (this option was not used when calling my_install()
-#    MY_INSTALL_DESTINATION = "bin"
-#    MY_INSTALL_RENAME = "" (was not used)
-#    MY_INSTALL_TARGETS = "foo;bar"
-#    MY_INSTALL_CONFIGURATIONS = "" (was not used)
-#    MY_INSTALL_UNPARSED_ARGUMENTS = "blub" (no value expected after "OPTIONAL"
-#
-#
-#
-# You can then continue and process these variables.
-#
-# Keywords terminate lists of values, e.g.  if directly after a
-# one_value_keyword another recognized keyword follows, this is
-# interpreted as the beginning of the new option.  E.g.
-# my_install(TARGETS foo DESTINATION OPTIONAL) would result in
-# MY_INSTALL_DESTINATION set to "OPTIONAL", but MY_INSTALL_DESTINATION
-# would be empty and MY_INSTALL_OPTIONAL would be set to TRUE therefor.
+# This module once implemented the :command:`cmake_parse_arguments` command
+# that is now implemented natively by CMake.  It is now an empty placeholder
+# for compatibility with projects that include it to get the command from
+# CMake 3.4 and lower.
 
 #=============================================================================
 # Copyright 2010 Alexander Neundorf <neundorf at kde.org>
@@ -95,67 +19,3 @@
 #=============================================================================
 # (To distribute this file outside of CMake, substitute the full
 #  License text for the above reference.)
-
-
-if(__CMAKE_PARSE_ARGUMENTS_INCLUDED)
-  return()
-endif()
-set(__CMAKE_PARSE_ARGUMENTS_INCLUDED TRUE)
-
-
-function(CMAKE_PARSE_ARGUMENTS prefix _optionNames _singleArgNames _multiArgNames)
-  # first set all result variables to empty/FALSE
-  foreach(arg_name ${_singleArgNames} ${_multiArgNames})
-    set(${prefix}_${arg_name})
-  endforeach()
-
-  foreach(option ${_optionNames})
-    set(${prefix}_${option} FALSE)
-  endforeach()
-
-  set(${prefix}_UNPARSED_ARGUMENTS)
-
-  set(insideValues FALSE)
-  set(currentArgName)
-
-  # now iterate over all arguments and fill the result variables
-  foreach(currentArg ${ARGN})
-    list(FIND _optionNames "${currentArg}" optionIndex)  # ... then this marks the end of the arguments belonging to this keyword
-    list(FIND _singleArgNames "${currentArg}" singleArgIndex)  # ... then this marks the end of the arguments belonging to this keyword
-    list(FIND _multiArgNames "${currentArg}" multiArgIndex)  # ... then this marks the end of the arguments belonging to this keyword
-
-    if(${optionIndex} EQUAL -1  AND  ${singleArgIndex} EQUAL -1  AND  ${multiArgIndex} EQUAL -1)
-      if(insideValues)
-        if("${insideValues}" STREQUAL "SINGLE")
-          set(${prefix}_${currentArgName} ${currentArg})
-          set(insideValues FALSE)
-        elseif("${insideValues}" STREQUAL "MULTI")
-          list(APPEND ${prefix}_${currentArgName} ${currentArg})
-        endif()
-      else()
-        list(APPEND ${prefix}_UNPARSED_ARGUMENTS ${currentArg})
-      endif()
-    else()
-      if(NOT ${optionIndex} EQUAL -1)
-        set(${prefix}_${currentArg} TRUE)
-        set(insideValues FALSE)
-      elseif(NOT ${singleArgIndex} EQUAL -1)
-        set(currentArgName ${currentArg})
-        set(${prefix}_${currentArgName})
-        set(insideValues "SINGLE")
-      elseif(NOT ${multiArgIndex} EQUAL -1)
-        set(currentArgName ${currentArg})
-        set(${prefix}_${currentArgName})
-        set(insideValues "MULTI")
-      endif()
-    endif()
-
-  endforeach()
-
-  # propagate the result variables to the caller:
-  foreach(arg_name ${_singleArgNames} ${_multiArgNames} ${_optionNames})
-    set(${prefix}_${arg_name}  ${${prefix}_${arg_name}} PARENT_SCOPE)
-  endforeach()
-  set(${prefix}_UNPARSED_ARGUMENTS ${${prefix}_UNPARSED_ARGUMENTS} PARENT_SCOPE)
-
-endfunction()
diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake
index 5756001..77f854d 100644
--- a/Modules/CPack.cmake
+++ b/Modules/CPack.cmake
@@ -586,7 +586,7 @@ _cpack_set_default(CPACK_WIX_SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}")
 
 # set sysroot so SDK tools can be used
 if(CMAKE_OSX_SYSROOT)
-  _cpack_set_default(CPACK_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}")
+  _cpack_set_default(CPACK_OSX_SYSROOT "${_CMAKE_OSX_SYSROOT_PATH}")
 endif()
 
 if(DEFINED CPACK_COMPONENTS_ALL)
diff --git a/Modules/CPackDMG.cmake b/Modules/CPackDMG.cmake
index b7a6ba5..e34f8cd 100644
--- a/Modules/CPackDMG.cmake
+++ b/Modules/CPackDMG.cmake
@@ -26,15 +26,56 @@
 #  Path to a custom DS_Store file. This .DS_Store file e.g. can be used to
 #  specify the Finder window position/geometry and layout (such as hidden
 #  toolbars, placement of the icons etc.). This file has to be generated by
-#  the Finder (either manually or through OSA-script) using a normal folder
+#  the Finder (either manually or through AppleScript) using a normal folder
 #  from which the .DS_Store file can then be extracted.
 #
+# .. variable:: CPACK_DMG_DS_STORE_SETUP_SCRIPT
+#
+#  Path to a custom AppleScript file.  This AppleScript is used to generate
+#  a .DS_Store file which specifies the Finder window position/geometry and
+#  layout (such as hidden toolbars, placement of the icons etc.).
+#  By specifying a custom AppleScript there is no need to use
+#  CPACK_DMG_DS_STORE, as the .DS_Store that is generated by the AppleScript
+#  will be packaged.
+#
 # .. variable:: CPACK_DMG_BACKGROUND_IMAGE
 #
-#  Path to a background image file. This file will be used as the background
-#  for the Finder Window when the disk image is opened.  By default no
-#  background image is set. The background image is applied after applying the
-#  custom .DS_Store file.
+#  Path to an image file to be used as the background.  This file will be
+#  copied to .background/background.<ext>, where ext is the original image file
+#  extension.  The background image is installed into the image before
+#  CPACK_DMG_DS_STORE_SETUP_SCRIPT is executed or CPACK_DMG_DS_STORE is
+#  installed.  By default no background image is set.
+#
+# .. variable:: CPACK_DMG_SLA_DIR
+#
+#   Directory where license and menu files for different languages are stored.
+#   Setting this causes CPack to look for a ``<language>.menu.txt`` and
+#   ``<language>.license.txt`` file for every language defined in
+#   ``CPACK_DMG_SLA_LANGUAGES``. If both this variable and
+#   ``CPACK_RESOURCE_FILE_LICENSE`` are set, CPack will only look for the menu
+#   files and use the same license file for all languages.
+#
+# .. variable:: CPACK_DMG_SLA_LANGUAGES
+#
+#   Languages for which a license agreement is provided when mounting the
+#   generated DMG. A menu file consists of 9 lines of text. The first line is
+#   is the name of the language itself, uppercase, in English (e.g. German).
+#   The other lines are translations of the following strings:
+#
+#   - Agree
+#   - Disagree
+#   - Print
+#   - Save...
+#   - You agree to the terms of the License Agreement when you click the
+#     "Agree" button.
+#   - Software License Agreement
+#   - This text cannot be saved. The disk may be full or locked, or the file
+#     may be locked.
+#   - Unable to print. Make sure you have selected a printer.
+#
+#   For every language in this list, CPack will try to find files
+#   ``<language>.menu.txt`` and ``<language>.license.txt`` in the directory
+#   specified by the :variable:`CPACK_DMG_SLA_DIR` variable.
 #
 # .. variable:: CPACK_COMMAND_HDIUTIL
 #
diff --git a/Modules/CPackDeb.cmake b/Modules/CPackDeb.cmake
index 60e0d1f..2aaef61 100644
--- a/Modules/CPackDeb.cmake
+++ b/Modules/CPackDeb.cmake
@@ -8,7 +8,7 @@
 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 #
 # CPackDeb may be used to create Deb package using CPack.
-# CPackDeb is a CPack generator thus it uses the CPACK_XXX variables
+# CPackDeb is a CPack generator thus it uses the ``CPACK_XXX`` variables
 # used by CPack : https://cmake.org/Wiki/CMake:CPackConfiguration.
 # CPackDeb generator should work on any linux host but it will produce
 # better deb package when Debian specific tools 'dpkg-xxx' are usable on
@@ -18,7 +18,7 @@
 # :code:`CPACK_DEBIAN_XXX` variables.
 #
 # :code:`CPACK_DEBIAN_<COMPONENT>_XXXX` variables may be used in order to have
-# **component** specific values.  Note however that <COMPONENT> refers to the
+# **component** specific values.  Note however that ``<COMPONENT>`` refers to the
 # **grouping name** written in upper case. It may be either a component name or
 # a component GROUP name.
 #
@@ -27,11 +27,20 @@
 # However as a handy reminder here comes the list of specific variables:
 #
 # .. variable:: CPACK_DEBIAN_PACKAGE_NAME
+#               CPACK_DEBIAN_<COMPONENT>_PACKAGE_NAME
 #
-#  The Debian package summary
+#  Set Package control field (variable is automatically transformed to lower
+#  case).
 #
 #  * Mandatory : YES
-#  * Default   : :variable:`CPACK_PACKAGE_NAME` (lower case)
+#  * Default   :
+#
+#    - :variable:`CPACK_PACKAGE_NAME` for non-component based
+#      installations
+#    - :variable:`CPACK_DEBIAN_PACKAGE_NAME` suffixed with -<COMPONENT>
+#      for component-based installations.
+#
+#  See https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Source
 #
 #
 # .. variable:: CPACK_DEBIAN_PACKAGE_VERSION
@@ -100,10 +109,16 @@
 #
 #
 # .. variable:: CPACK_DEBIAN_PACKAGE_SECTION
+#               CPACK_DEBIAN_<COMPONENT>_PACKAGE_SECTION
+#
+#  Set Section control field e.g. admin, devel, doc, ...
 #
 #  * Mandatory : YES
 #  * Default   : 'devel'
 #
+#  See https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections
+#
+#
 # .. variable:: CPACK_DEBIAN_COMPRESSION_TYPE
 #
 #  The compression used for creating the Debian package.
@@ -114,12 +129,16 @@
 #
 #
 # .. variable:: CPACK_DEBIAN_PACKAGE_PRIORITY
+#               CPACK_DEBIAN_<COMPONENT>_PACKAGE_PRIORITY
 #
-#  The Debian package priority
+#  Set Priority control field e.g. required, important, standard, optional,
+#  extra
 #
 #  * Mandatory : YES
 #  * Default   : 'optional'
 #
+#  See https://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities
+#
 #
 # .. variable:: CPACK_DEBIAN_PACKAGE_HOMEPAGE
 #
@@ -354,7 +373,28 @@
 #    set by Debian policy
 #    https://www.debian.org/doc/debian-policy/ch-files.html#s-permissions-owners
 #
-
+# .. variable:: CPACK_DEBIAN_PACKAGE_SOURCE
+#               CPACK_DEBIAN_<COMPONENT>_PACKAGE_SOURCE
+#
+#  Sets the ``Source`` field of the binary Debian package.
+#  When the binary package name is not the same as the source package name
+#  (in particular when several components/binaries are generated from one
+#  source) the source from which the binary has been generated should be
+#  indicated with the field ``Source``.
+#
+#  * Mandatory : NO
+#  * Default   :
+#
+#    - An empty string for non-component based installations
+#    - :variable:`CPACK_DEBIAN_PACKAGE_SOURCE` for component-based
+#      installations.
+#
+#  See https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Source
+#
+#  .. note::
+#
+#    This value is not interpreted. It is possible to pass an optional
+#    revision number of the referenced source package as well.
 
 #=============================================================================
 # Copyright 2007-2009 Kitware, Inc.
@@ -554,24 +594,33 @@ function(cpack_deb_prepare_package_vars)
       )
   endif()
 
+  # Source: (optional)
+  # in case several packages are constructed from a unique source
+  # (multipackaging), the source may be indicated as well.
+  # The source might contain a version if the generated package
+  # version is different from the source version
+  if(NOT CPACK_DEBIAN_PACKAGE_SOURCE)
+    set(CPACK_DEBIAN_PACKAGE_SOURCE "")
+  endif()
+
   # have a look at get_property(result GLOBAL PROPERTY ENABLED_FEATURES),
   # this returns the successful find_package() calls, maybe this can help
   # Depends:
   # You should set: DEBIAN_PACKAGE_DEPENDS
   # TODO: automate 'objdump -p | grep NEEDED'
 
-  # if per-component dependency, overrides the global CPACK_DEBIAN_PACKAGE_${dependency_type_}
+  # if per-component variable, overrides the global CPACK_DEBIAN_PACKAGE_${variable_type_}
   # automatic dependency discovery will be performed afterwards.
   if(CPACK_DEB_PACKAGE_COMPONENT)
-    foreach(dependency_type_ DEPENDS RECOMMENDS SUGGESTS PREDEPENDS ENHANCES BREAKS CONFLICTS PROVIDES REPLACES)
-      set(_component_var "CPACK_DEBIAN_${_local_component_name}_PACKAGE_${dependency_type_}")
+    foreach(value_type_ DEPENDS RECOMMENDS SUGGESTS PREDEPENDS ENHANCES BREAKS CONFLICTS PROVIDES REPLACES SOURCE SECTION PRIORITY NAME)
+      set(_component_var "CPACK_DEBIAN_${_local_component_name}_PACKAGE_${value_type_}")
 
-      # if set, overrides the global dependency
+      # if set, overrides the global variable
       if(DEFINED ${_component_var})
-        set(CPACK_DEBIAN_PACKAGE_${dependency_type_} "${${_component_var}}")
+        set(CPACK_DEBIAN_PACKAGE_${value_type_} "${${_component_var}}")
         if(CPACK_DEBIAN_PACKAGE_DEBUG)
-          message("CPackDeb Debug: component '${_local_component_name}' ${dependency_type_}"
-            "dependencies set to '${CPACK_DEBIAN_PACKAGE_${dependency_}}'")
+          message("CPackDeb Debug: component '${_local_component_name}' ${value_type_} "
+            "value set to '${CPACK_DEBIAN_PACKAGE_${value_type_}}'")
         endif()
       endif()
     endforeach()
@@ -664,23 +713,25 @@ function(cpack_deb_prepare_package_vars)
       endif()
     endforeach()
 
-    set(CPACK_DEB_PACKAGE_COMPONENT_PART_NAME "-${CPACK_DEB_PACKAGE_COMPONENT}")
-    string(TOLOWER "${CPACK_PACKAGE_NAME}${CPACK_DEB_PACKAGE_COMPONENT_PART_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
-  else()
-    set(CPACK_DEB_PACKAGE_COMPONENT_PART_NAME "")
+    if(CPACK_DEBIAN_${_local_component_name}_PACKAGE_NAME)
+      string(TOLOWER "${CPACK_DEBIAN_${_local_component_name}_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
+    else()
+      string(TOLOWER "${CPACK_DEBIAN_PACKAGE_NAME}-${CPACK_DEB_PACKAGE_COMPONENT}" CPACK_DEBIAN_PACKAGE_NAME)
+    endif()
   endif()
 
   # Print out some debug information if we were asked for that
   if(CPACK_DEBIAN_PACKAGE_DEBUG)
-     message("CPackDeb:Debug: CPACK_TOPLEVEL_DIRECTORY          = ${CPACK_TOPLEVEL_DIRECTORY}")
-     message("CPackDeb:Debug: CPACK_TOPLEVEL_TAG                = ${CPACK_TOPLEVEL_TAG}")
-     message("CPackDeb:Debug: CPACK_TEMPORARY_DIRECTORY         = ${CPACK_TEMPORARY_DIRECTORY}")
-     message("CPackDeb:Debug: CPACK_OUTPUT_FILE_NAME            = ${CPACK_OUTPUT_FILE_NAME}")
-     message("CPackDeb:Debug: CPACK_OUTPUT_FILE_PATH            = ${CPACK_OUTPUT_FILE_PATH}")
-     message("CPackDeb:Debug: CPACK_PACKAGE_FILE_NAME           = ${CPACK_PACKAGE_FILE_NAME}")
-     message("CPackDeb:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY   = ${CPACK_PACKAGE_INSTALL_DIRECTORY}")
-     message("CPackDeb:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
-     message("CPackDeb:Debug: CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION = ${CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION}")
+     message("CPackDeb:Debug: CPACK_TOPLEVEL_DIRECTORY          = '${CPACK_TOPLEVEL_DIRECTORY}'")
+     message("CPackDeb:Debug: CPACK_TOPLEVEL_TAG                = '${CPACK_TOPLEVEL_TAG}'")
+     message("CPackDeb:Debug: CPACK_TEMPORARY_DIRECTORY         = '${CPACK_TEMPORARY_DIRECTORY}'")
+     message("CPackDeb:Debug: CPACK_OUTPUT_FILE_NAME            = '${CPACK_OUTPUT_FILE_NAME}'")
+     message("CPackDeb:Debug: CPACK_OUTPUT_FILE_PATH            = '${CPACK_OUTPUT_FILE_PATH}'")
+     message("CPackDeb:Debug: CPACK_PACKAGE_FILE_NAME           = '${CPACK_PACKAGE_FILE_NAME}'")
+     message("CPackDeb:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY   = '${CPACK_PACKAGE_INSTALL_DIRECTORY}'")
+     message("CPackDeb:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = '${CPACK_TEMPORARY_PACKAGE_FILE_NAME}'")
+     message("CPackDeb:Debug: CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION = '${CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION}'")
+     message("CPackDeb:Debug: CPACK_DEBIAN_PACKAGE_SOURCE       = '${CPACK_DEBIAN_PACKAGE_SOURCE}'")
   endif()
 
   # For debian source packages:
@@ -719,6 +770,8 @@ function(cpack_deb_prepare_package_vars)
   set(GEN_CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA}" PARENT_SCOPE)
   set(GEN_CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION
       "${CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION}" PARENT_SCOPE)
+  set(GEN_CPACK_DEBIAN_PACKAGE_SOURCE
+     "${CPACK_DEBIAN_PACKAGE_SOURCE}" PARENT_SCOPE)
   set(GEN_WDIR "${WDIR}" PARENT_SCOPE)
 endfunction()
 
diff --git a/Modules/CPackNSIS.cmake b/Modules/CPackNSIS.cmake
index c6b3d19..db5984a 100644
--- a/Modules/CPackNSIS.cmake
+++ b/Modules/CPackNSIS.cmake
@@ -30,6 +30,14 @@
 #
 #  undocumented.
 #
+# .. variable:: CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP
+#
+#  The filename of a bitmap to use as the NSIS MUI_WELCOMEFINISHPAGE_BITMAP.
+#
+# .. variable:: CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP
+#
+#  The filename of a bitmap to use as the NSIS MUI_UNWELCOMEFINISHPAGE_BITMAP.
+#
 # .. variable:: CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS
 #
 #  Extra NSIS commands that will be added to the beginning of the install
diff --git a/Modules/CPackRPM.cmake b/Modules/CPackRPM.cmake
index 1e7b055..7fb11c3 100644
--- a/Modules/CPackRPM.cmake
+++ b/Modules/CPackRPM.cmake
@@ -37,6 +37,7 @@
 #  * Default   : CPACK_PACKAGE_DESCRIPTION_SUMMARY
 #
 # .. variable:: CPACK_RPM_PACKAGE_NAME
+#               CPACK_RPM_<component>_PACKAGE_NAME
 #
 #  The RPM package name.
 #
@@ -81,6 +82,7 @@
 #  * Default   : "unknown"
 #
 # .. variable:: CPACK_RPM_PACKAGE_GROUP
+#               CPACK_RPM_<component>_PACKAGE_GROUP
 #
 #  The RPM package group.
 #
@@ -1106,10 +1108,7 @@ function(cpack_rpm_generate_package)
 
   # Are we packaging components ?
   if(CPACK_RPM_PACKAGE_COMPONENT)
-    set(CPACK_RPM_PACKAGE_COMPONENT_PART_NAME "-${CPACK_RPM_PACKAGE_COMPONENT}")
     string(TOUPPER ${CPACK_RPM_PACKAGE_COMPONENT} CPACK_RPM_PACKAGE_COMPONENT_UPPER)
-  else()
-    set(CPACK_RPM_PACKAGE_COMPONENT_PART_NAME "")
   endif()
 
   set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}")
@@ -1143,10 +1142,19 @@ function(cpack_rpm_generate_package)
   endif()
 
   # CPACK_RPM_PACKAGE_NAME (mandatory)
+
   if(NOT CPACK_RPM_PACKAGE_NAME)
     string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_NAME)
   endif()
 
+  if(CPACK_RPM_PACKAGE_COMPONENT)
+    if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_NAME)
+      set(CPACK_RPM_PACKAGE_NAME ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_NAME})
+    else()
+      set(CPACK_RPM_PACKAGE_NAME ${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_COMPONENT})
+    endif()
+  endif()
+
   # CPACK_RPM_PACKAGE_VERSION (mandatory)
   if(NOT CPACK_RPM_PACKAGE_VERSION)
     if(NOT CPACK_PACKAGE_VERSION)
@@ -1206,6 +1214,15 @@ function(cpack_rpm_generate_package)
   endif()
 
   # CPACK_RPM_PACKAGE_GROUP
+
+  #Check for component group first.
+  #If not set, it will use regular package group logic.
+  if(CPACK_RPM_PACKAGE_COMPONENT)
+    if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_GROUP)
+      set(CPACK_RPM_PACKAGE_GROUP ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_GROUP})
+    endif()
+  endif()
+
   if(NOT CPACK_RPM_PACKAGE_GROUP)
     set(CPACK_RPM_PACKAGE_GROUP "unknown")
   endif()
@@ -1613,7 +1630,7 @@ function(cpack_rpm_generate_package)
     )
 
   # The name of the final spec file to be used by rpmbuild
-  set(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.spec")
+  set(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}.spec")
 
   # Print out some debug information if we were asked for that
   if(CPACK_RPM_PACKAGE_DEBUG)
@@ -1645,7 +1662,7 @@ function(cpack_rpm_generate_package)
       "# -*- rpm-spec -*-
 BuildRoot:      \@CPACK_RPM_DIRECTORY\@/\@CPACK_PACKAGE_FILE_NAME\@\@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH\@
 Summary:        \@CPACK_RPM_PACKAGE_SUMMARY\@
-Name:           \@CPACK_RPM_PACKAGE_NAME\@\@CPACK_RPM_PACKAGE_COMPONENT_PART_NAME\@
+Name:           \@CPACK_RPM_PACKAGE_NAME\@
 Version:        \@CPACK_RPM_PACKAGE_VERSION\@
 Release:        \@CPACK_RPM_PACKAGE_RELEASE\@
 License:        \@CPACK_RPM_PACKAGE_LICENSE\@
@@ -1749,15 +1766,15 @@ mv \"\@CPACK_TOPLEVEL_DIRECTORY\@/tmpBBroot\" $RPM_BUILD_ROOT
               "${CPACK_RPM_BINARY_SPECFILE}"
       WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
       RESULT_VARIABLE CPACK_RPMBUILD_EXEC_RESULT
-      ERROR_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.err"
-      OUTPUT_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.out")
+      ERROR_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err"
+      OUTPUT_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out")
     if(CPACK_RPM_PACKAGE_DEBUG OR CPACK_RPMBUILD_EXEC_RESULT)
-      file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.err RPMBUILDERR)
-      file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.out RPMBUILDOUT)
+      file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err RPMBUILDERR)
+      file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out RPMBUILDOUT)
       message("CPackRPM:Debug: You may consult rpmbuild logs in: ")
-      message("CPackRPM:Debug:    - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.err")
+      message("CPackRPM:Debug:    - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err")
       message("CPackRPM:Debug: *** ${RPMBUILDERR} ***")
-      message("CPackRPM:Debug:    - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.out")
+      message("CPackRPM:Debug:    - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out")
       message("CPackRPM:Debug: *** ${RPMBUILDOUT} ***")
     endif()
   else()
diff --git a/Modules/CPackWIX.cmake b/Modules/CPackWIX.cmake
index bef8e16..4994005 100644
--- a/Modules/CPackWIX.cmake
+++ b/Modules/CPackWIX.cmake
@@ -119,7 +119,8 @@
 #
 # .. variable:: CPACK_WIX_PATCH_FILE
 #
-#  Optional XML file with fragments to be inserted into generated WiX sources
+#  Optional list of XML files with fragments to be inserted into
+#  generated WiX sources
 #
 #  This optional variable can be used to specify an XML file that the
 #  WiX generator will use to inject fragments into its generated
diff --git a/Modules/CheckCSourceCompiles.cmake b/Modules/CheckCSourceCompiles.cmake
index 6e80fb5..c2b1723 100644
--- a/Modules/CheckCSourceCompiles.cmake
+++ b/Modules/CheckCSourceCompiles.cmake
@@ -93,7 +93,7 @@ macro(CHECK_C_SOURCE_COMPILES SOURCE VAR)
         message(STATUS "Performing Test ${VAR} - Success")
       endif()
       file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
-        "Performing C SOURCE FILE Test ${VAR} succeded with the following output:\n"
+        "Performing C SOURCE FILE Test ${VAR} succeeded with the following output:\n"
         "${OUTPUT}\n"
         "Source file was:\n${SOURCE}\n")
     else()
diff --git a/Modules/CheckCSourceRuns.cmake b/Modules/CheckCSourceRuns.cmake
index 0ce423c..5afeab6 100644
--- a/Modules/CheckCSourceRuns.cmake
+++ b/Modules/CheckCSourceRuns.cmake
@@ -81,7 +81,7 @@ macro(CHECK_C_SOURCE_RUNS SOURCE VAR)
         message(STATUS "Performing Test ${VAR} - Success")
       endif()
       file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
-        "Performing C SOURCE FILE Test ${VAR} succeded with the following output:\n"
+        "Performing C SOURCE FILE Test ${VAR} succeeded with the following output:\n"
         "${OUTPUT}\n"
         "Return value: ${${VAR}}\n"
         "Source file was:\n${SOURCE}\n")
diff --git a/Modules/CheckCXXSourceCompiles.cmake b/Modules/CheckCXXSourceCompiles.cmake
index 6d52ec6..f8736e2 100644
--- a/Modules/CheckCXXSourceCompiles.cmake
+++ b/Modules/CheckCXXSourceCompiles.cmake
@@ -94,7 +94,7 @@ macro(CHECK_CXX_SOURCE_COMPILES SOURCE VAR)
         message(STATUS "Performing Test ${VAR} - Success")
       endif()
       file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
-        "Performing C++ SOURCE FILE Test ${VAR} succeded with the following output:\n"
+        "Performing C++ SOURCE FILE Test ${VAR} succeeded with the following output:\n"
         "${OUTPUT}\n"
         "Source file was:\n${SOURCE}\n")
     else()
diff --git a/Modules/CheckCXXSourceRuns.cmake b/Modules/CheckCXXSourceRuns.cmake
index 3c06d75..84b661d 100644
--- a/Modules/CheckCXXSourceRuns.cmake
+++ b/Modules/CheckCXXSourceRuns.cmake
@@ -82,7 +82,7 @@ macro(CHECK_CXX_SOURCE_RUNS SOURCE VAR)
         message(STATUS "Performing Test ${VAR} - Success")
       endif()
       file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
-        "Performing C++ SOURCE FILE Test ${VAR} succeded with the following output:\n"
+        "Performing C++ SOURCE FILE Test ${VAR} succeeded with the following output:\n"
         "${OUTPUT}\n"
         "Return value: ${${VAR}}\n"
         "Source file was:\n${SOURCE}\n")
diff --git a/Modules/CheckForPthreads.c b/Modules/CheckForPthreads.c
index 2732957..344c81b 100644
--- a/Modules/CheckForPthreads.c
+++ b/Modules/CheckForPthreads.c
@@ -16,8 +16,8 @@ int main(int ac, char*av[]){
   pthread_create(&tid[0], 0, runner, (void*)1);
   pthread_create(&tid[1], 0, runner, (void*)2);
 
-#if defined(__BEOS__) && !defined(__ZETA__) // (no usleep on BeOS 5.)
-  usleep(1); // for strange behavior on single-processor sun
+#if defined(__BEOS__) && !defined(__ZETA__) /* (no usleep on BeOS 5.) */
+  usleep(1); /* for strange behavior on single-processor sun */
 #endif
 
   pthread_join(tid[0], 0);
diff --git a/Modules/CheckFortranSourceCompiles.cmake b/Modules/CheckFortranSourceCompiles.cmake
index f90d05b..0bdcffa 100644
--- a/Modules/CheckFortranSourceCompiles.cmake
+++ b/Modules/CheckFortranSourceCompiles.cmake
@@ -94,7 +94,7 @@ macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR)
         message(STATUS "Performing Test ${VAR} - Success")
       endif()
       file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
-        "Performing Fortran SOURCE FILE Test ${VAR} succeded with the following output:\n"
+        "Performing Fortran SOURCE FILE Test ${VAR} succeeded with the following output:\n"
         "${OUTPUT}\n"
         "Source file was:\n${SOURCE}\n")
     else()
diff --git a/Modules/Compiler/ARMCC-ASM.cmake b/Modules/Compiler/ARMCC-ASM.cmake
new file mode 100644
index 0000000..8e3cfc5
--- /dev/null
+++ b/Modules/Compiler/ARMCC-ASM.cmake
@@ -0,0 +1,7 @@
+include(Compiler/ARMCC)
+
+set(CMAKE_ASM_OUTPUT_EXTENSION ".o")
+set(CMAKE_ASM_OUTPUT_EXTENSION_REPLACE 1)
+
+set(CMAKE_ASM_COMPILE_OBJECT       "<CMAKE_ASM_COMPILER> <FLAGS> -o <OBJECT> <SOURCE>")
+set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;asm;msa)
diff --git a/Modules/Compiler/ARMCC-C.cmake b/Modules/Compiler/ARMCC-C.cmake
new file mode 100644
index 0000000..dcdcaab
--- /dev/null
+++ b/Modules/Compiler/ARMCC-C.cmake
@@ -0,0 +1,2 @@
+include(Compiler/ARMCC)
+__compiler_armcc(C)
diff --git a/Modules/Compiler/ARMCC-CXX.cmake b/Modules/Compiler/ARMCC-CXX.cmake
new file mode 100644
index 0000000..811fc93
--- /dev/null
+++ b/Modules/Compiler/ARMCC-CXX.cmake
@@ -0,0 +1,2 @@
+include(Compiler/ARMCC)
+__compiler_armcc(CXX)
diff --git a/Modules/Compiler/ARMCC-DetermineCompiler.cmake b/Modules/Compiler/ARMCC-DetermineCompiler.cmake
new file mode 100644
index 0000000..a3667d7
--- /dev/null
+++ b/Modules/Compiler/ARMCC-DetermineCompiler.cmake
@@ -0,0 +1,16 @@
+# ARMCC Toolchain
+set(_compiler_id_pp_test "defined(__ARMCC_VERSION)")
+
+set(_compiler_id_version_compute "
+#if __ARMCC_VERSION >= 1000000
+  /* __ARMCC_VERSION = VRRPPPP */
+  # define @PREFIX at COMPILER_VERSION_MAJOR @MACRO_DEC@(__ARMCC_VERSION/1000000)
+  # define @PREFIX at COMPILER_VERSION_MINOR @MACRO_DEC@(__ARMCC_VERSION/10000 % 100)
+  # define @PREFIX at COMPILER_VERSION_PATCH @MACRO_DEC@(__ARMCC_VERSION     % 10000)
+#else
+  /* __ARMCC_VERSION = VRPPPP */
+  # define @PREFIX at COMPILER_VERSION_MAJOR @MACRO_DEC@(__ARMCC_VERSION/100000)
+  # define @PREFIX at COMPILER_VERSION_MINOR @MACRO_DEC@(__ARMCC_VERSION/10000 % 10)
+  # define @PREFIX at COMPILER_VERSION_PATCH @MACRO_DEC@(__ARMCC_VERSION    % 10000)
+#endif
+")
diff --git a/Modules/Compiler/ARMCC.cmake b/Modules/Compiler/ARMCC.cmake
new file mode 100644
index 0000000..3cf628c
--- /dev/null
+++ b/Modules/Compiler/ARMCC.cmake
@@ -0,0 +1,36 @@
+if(_ARMCC_CMAKE_LOADED)
+  return()
+endif()
+set(_ARMCC_CMAKE_LOADED TRUE)
+
+# See ARM Compiler documentation at:
+# http://infocenter.arm.com/help/topic/com.arm.doc.set.swdev/index.html
+
+get_filename_component(_CMAKE_C_TOOLCHAIN_LOCATION "${CMAKE_C_COMPILER}" PATH)
+get_filename_component(_CMAKE_CXX_TOOLCHAIN_LOCATION "${CMAKE_CXX_COMPILER}" PATH)
+
+set(CMAKE_EXECUTABLE_SUFFIX ".elf")
+
+find_program(CMAKE_ARMCC_LINKER armlink HINTS "${_CMAKE_C_TOOLCHAIN_LOCATION}" "${_CMAKE_CXX_TOOLCHAIN_LOCATION}" )
+find_program(CMAKE_ARMCC_AR     armar   HINTS "${_CMAKE_C_TOOLCHAIN_LOCATION}" "${_CMAKE_CXX_TOOLCHAIN_LOCATION}" )
+
+set(CMAKE_LINKER "${CMAKE_ARMCC_LINKER}" CACHE FILEPATH "The ARMCC linker" FORCE)
+mark_as_advanced(CMAKE_ARMCC_LINKER)
+set(CMAKE_AR "${CMAKE_ARMCC_AR}" CACHE FILEPATH "The ARMCC archiver" FORCE)
+mark_as_advanced(CMAKE_ARMCC_AR)
+
+macro(__compiler_armcc lang)
+  set(CMAKE_${lang}_FLAGS_INIT "")
+  set(CMAKE_${lang}_FLAGS_DEBUG_INIT "-g")
+  set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "-Ospace -DNDEBUG")
+  set(CMAKE_${lang}_FLAGS_RELEASE_INIT "-Otime -DNDEBUG")
+  set(CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "-O2 -g")
+
+  set(CMAKE_${lang}_OUTPUT_EXTENSION ".o")
+  set(CMAKE_${lang}_OUTPUT_EXTENSION_REPLACE 1)
+
+  set(CMAKE_${lang}_LINK_EXECUTABLE      "<CMAKE_LINKER> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> <OBJECTS> -o <TARGET> --list <TARGET_BASE>.map")
+  set(CMAKE_${lang}_CREATE_STATIC_LIBRARY  "<CMAKE_AR> --create -cr <TARGET> <LINK_FLAGS> <OBJECTS>")
+
+  set(CMAKE_DEPFILE_FLAGS_${lang} "--depend=<DEPFILE> --depend_single_line --no_depend_system_headers")
+endmacro()
diff --git a/Modules/Compiler/Clang-CXX.cmake b/Modules/Compiler/Clang-CXX.cmake
index 6a0a5e2..dc62711 100644
--- a/Modules/Compiler/Clang-CXX.cmake
+++ b/Modules/Compiler/Clang-CXX.cmake
@@ -6,7 +6,7 @@ if(NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
 endif()
 
 cmake_policy(GET CMP0025 appleClangPolicy)
-if(WIN32 OR (APPLE AND NOT appleClangPolicy STREQUAL NEW))
+if(APPLE AND NOT appleClangPolicy STREQUAL NEW)
   return()
 endif()
 
@@ -49,7 +49,7 @@ macro(cmake_record_cxx_compile_features)
   endmacro()
 
   set(_result 0)
-  if (UNIX AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
+  if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
     _get_clang_features(${CMAKE_CXX14_STANDARD_COMPILE_OPTION} CMAKE_CXX14_COMPILE_FEATURES)
     if (_result EQUAL 0)
       _get_clang_features(${CMAKE_CXX11_STANDARD_COMPILE_OPTION} CMAKE_CXX11_COMPILE_FEATURES)
diff --git a/Modules/Compiler/CrayPrgEnv-C.cmake b/Modules/Compiler/CrayPrgEnv-C.cmake
new file mode 100644
index 0000000..6b461ce
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv-C.cmake
@@ -0,0 +1,11 @@
+if(__craylinux_crayprgenv_c)
+  return()
+endif()
+set(__craylinux_crayprgenv_c 1)
+
+include(Compiler/CrayPrgEnv)
+macro(__CrayPrgEnv_setup_C compiler_cmd link_cmd)
+  __CrayPrgEnv_setup(C
+    ${CMAKE_ROOT}/Modules/CMakeCCompilerABI.c
+    ${compiler_cmd} ${link_cmd})
+endmacro()
diff --git a/Modules/Compiler/CrayPrgEnv-CXX.cmake b/Modules/Compiler/CrayPrgEnv-CXX.cmake
new file mode 100644
index 0000000..aad85b6
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv-CXX.cmake
@@ -0,0 +1,11 @@
+if(__craylinux_crayprgenv_cxx)
+  return()
+endif()
+set(__craylinux_crayprgenv_cxx 1)
+
+include(Compiler/CrayPrgEnv)
+macro(__CrayPrgEnv_setup_CXX compiler_cmd link_cmd)
+  __CrayPrgEnv_setup(CXX
+    ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp
+    ${compiler_cmd} ${link_cmd})
+endmacro()
diff --git a/Modules/Compiler/CrayPrgEnv-Cray-C.cmake b/Modules/Compiler/CrayPrgEnv-Cray-C.cmake
new file mode 100644
index 0000000..547a4b4
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv-Cray-C.cmake
@@ -0,0 +1,7 @@
+if(__craylinux_crayprgenv_cray_c)
+  return()
+endif()
+set(__craylinux_crayprgenv_cray_c 1)
+
+include(Compiler/CrayPrgEnv-C)
+__CrayPrgEnv_setup_C("/opt/cray/cce/.*/ccfe" "/opt/cray/cce/.*/ld")
diff --git a/Modules/Compiler/CrayPrgEnv-Cray-CXX.cmake b/Modules/Compiler/CrayPrgEnv-Cray-CXX.cmake
new file mode 100644
index 0000000..df8452c
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv-Cray-CXX.cmake
@@ -0,0 +1,7 @@
+if(__craylinux_crayprgenv_cray_cxx)
+  return()
+endif()
+set(__craylinux_crayprgenv_cray_cxx 1)
+
+include(Compiler/CrayPrgEnv-CXX)
+__CrayPrgEnv_setup_CXX("/opt/cray/cce/.*/ccfe" "/opt/cray/cce/.*/ld")
diff --git a/Modules/Compiler/CrayPrgEnv-Cray-Fortran.cmake b/Modules/Compiler/CrayPrgEnv-Cray-Fortran.cmake
new file mode 100644
index 0000000..9f46a04
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv-Cray-Fortran.cmake
@@ -0,0 +1,7 @@
+if(__craylinux_crayprgenv_cray_fortran)
+  return()
+endif()
+set(__craylinux_crayprgenv_cray_fortran 1)
+
+include(Compiler/CrayPrgEnv-Fortran)
+__CrayPrgEnv_setup_Fortran("/opt/cray/cce/.*/ftnfe" "/opt/cray/cce/.*/ld")
diff --git a/Modules/Compiler/CrayPrgEnv-Fortran.cmake b/Modules/Compiler/CrayPrgEnv-Fortran.cmake
new file mode 100644
index 0000000..9c4d269
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv-Fortran.cmake
@@ -0,0 +1,11 @@
+if(__craylinux_crayprgenv_fortran)
+  return()
+endif()
+set(__craylinux_crayprgenv_fortran 1)
+
+include(Compiler/CrayPrgEnv)
+macro(__CrayPrgEnv_setup_Fortran compiler_cmd link_cmd)
+  __CrayPrgEnv_setup(Fortran
+    ${CMAKE_ROOT}/Modules/CMakeFortranCompilerABI.F
+    ${compiler_cmd} ${link_cmd})
+endmacro()
diff --git a/Modules/Compiler/CrayPrgEnv-GNU-C.cmake b/Modules/Compiler/CrayPrgEnv-GNU-C.cmake
new file mode 100644
index 0000000..248081b
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv-GNU-C.cmake
@@ -0,0 +1,7 @@
+if(__craylinux_crayprgenv_gnu_c)
+  return()
+endif()
+set(__craylinux_crayprgenv_gnu_c 1)
+
+include(Compiler/CrayPrgEnv-C)
+__CrayPrgEnv_setup_C("/opt/gcc/.*/cc1" "/opt/gcc/.*/collect2")
diff --git a/Modules/Compiler/CrayPrgEnv-GNU-CXX.cmake b/Modules/Compiler/CrayPrgEnv-GNU-CXX.cmake
new file mode 100644
index 0000000..be4eb6d
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv-GNU-CXX.cmake
@@ -0,0 +1,7 @@
+if(__craylinux_crayprgenv_gnu_cxx)
+  return()
+endif()
+set(__craylinux_crayprgenv_gnu_cxx 1)
+
+include(Compiler/CrayPrgEnv-CXX)
+__CrayPrgEnv_setup_CXX("/opt/gcc/.*/cc1plus" "/opt/gcc/.*/collect2")
diff --git a/Modules/Compiler/CrayPrgEnv-GNU-Fortran.cmake b/Modules/Compiler/CrayPrgEnv-GNU-Fortran.cmake
new file mode 100644
index 0000000..8bd23ff
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv-GNU-Fortran.cmake
@@ -0,0 +1,7 @@
+if(__craylinux_crayprgenv_gnu_fortran)
+  return()
+endif()
+set(__craylinux_crayprgenv_gnu_fortran 1)
+
+include(Compiler/CrayPrgEnv-Fortran)
+__CrayPrgEnv_setup_Fortran("/opt/gcc/.*/f951" "/opt/gcc/.*/collect2")
diff --git a/Modules/Compiler/CrayPrgEnv-Intel-C.cmake b/Modules/Compiler/CrayPrgEnv-Intel-C.cmake
new file mode 100644
index 0000000..83c4e38
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv-Intel-C.cmake
@@ -0,0 +1,7 @@
+if(__craylinux_crayprgenv_intel_c)
+  return()
+endif()
+set(__craylinux_crayprgenv_intel_c 1)
+
+include(Compiler/CrayPrgEnv-C)
+__CrayPrgEnv_setup_C("/opt/intel/.*/mcpcom" "^ld ")
diff --git a/Modules/Compiler/CrayPrgEnv-Intel-CXX.cmake b/Modules/Compiler/CrayPrgEnv-Intel-CXX.cmake
new file mode 100644
index 0000000..3c3c3e6
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv-Intel-CXX.cmake
@@ -0,0 +1,7 @@
+if(__craylinux_crayprgenv_intel_cxx)
+  return()
+endif()
+set(__craylinux_crayprgenv_intel_cxx 1)
+
+include(Compiler/CrayPrgEnv-CXX)
+__CrayPrgEnv_setup_CXX("/opt/intel/.*/mcpcom" "^ld ")
diff --git a/Modules/Compiler/CrayPrgEnv-Intel-Fortran.cmake b/Modules/Compiler/CrayPrgEnv-Intel-Fortran.cmake
new file mode 100644
index 0000000..08a316d
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv-Intel-Fortran.cmake
@@ -0,0 +1,7 @@
+if(__craylinux_crayprgenv_intel_fortran)
+  return()
+endif()
+set(__craylinux_crayprgenv_intel_fortran 1)
+
+include(Compiler/CrayPrgEnv-Fortran)
+__CrayPrgEnv_setup_Fortran("/opt/intel/.*/fortcom" "^ld ")
diff --git a/Modules/Compiler/CrayPrgEnv-PGI-C.cmake b/Modules/Compiler/CrayPrgEnv-PGI-C.cmake
new file mode 100644
index 0000000..f45767c
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv-PGI-C.cmake
@@ -0,0 +1,7 @@
+if(__craylinux_crayprgenv_pgi_c)
+  return()
+endif()
+set(__craylinux_crayprgenv_pgi_c 1)
+
+include(Compiler/CrayPrgEnv-C)
+__CrayPrgEnv_setup_C("/opt/pgi/[^ ]*/pgc" "/usr/bin/ld")
diff --git a/Modules/Compiler/CrayPrgEnv-PGI-CXX.cmake b/Modules/Compiler/CrayPrgEnv-PGI-CXX.cmake
new file mode 100644
index 0000000..a2a286f
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv-PGI-CXX.cmake
@@ -0,0 +1,7 @@
+if(__craylinux_crayprgenv_pgi_cxx)
+  return()
+endif()
+set(__craylinux_crayprgenv_pgi_cxx 1)
+
+include(Compiler/CrayPrgEnv-CXX)
+__CrayPrgEnv_setup_CXX("/opt/pgi/[^ ]*/pgcpp" "/usr/bin/ld")
diff --git a/Modules/Compiler/CrayPrgEnv-PGI-Fortran.cmake b/Modules/Compiler/CrayPrgEnv-PGI-Fortran.cmake
new file mode 100644
index 0000000..f6ba7c0
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv-PGI-Fortran.cmake
@@ -0,0 +1,7 @@
+if(__craylinux_crayprgenv_pgi_fortran)
+  return()
+endif()
+set(__craylinux_crayprgenv_pgi_fortran 1)
+
+include(Compiler/CrayPrgEnv-Fortran)
+__CrayPrgEnv_setup_Fortran("/opt/pgi/[^ ]*/pgf" "/usr/bin/ld")
diff --git a/Modules/Compiler/CrayPrgEnv.cmake b/Modules/Compiler/CrayPrgEnv.cmake
new file mode 100644
index 0000000..fa39b00
--- /dev/null
+++ b/Modules/Compiler/CrayPrgEnv.cmake
@@ -0,0 +1,91 @@
+# Guard against multiple inclusions
+if(__craylinux_crayprgenv)
+  return()
+endif()
+set(__craylinux_crayprgenv 1)
+
+macro(__cray_extract_args cmd tag_regex out_var make_absolute)
+  string(REGEX MATCHALL "${tag_regex}" args "${cmd}")
+  foreach(arg IN LISTS args)
+    string(REGEX REPLACE "^${tag_regex}$" "\\2" param "${arg}")
+    if(make_absolute)
+      get_filename_component(param "${param}" ABSOLUTE)
+    endif()
+    list(APPEND ${out_var} ${param})
+  endforeach()
+endmacro()
+
+function(__cray_extract_implicit src compiler_cmd link_cmd lang include_dirs_var link_dirs_var link_libs_var)
+  set(BIN "${CMAKE_PLATFORM_INFO_DIR}/CrayExtractImplicit_${lang}.bin")
+  execute_process(
+    COMMAND ${CMAKE_${lang}_COMPILER} ${CMAKE_${lang}_VERBOSE_FLAG} -o ${BIN}
+    RESULT_VARIABLE result
+    OUTPUT_VARIABLE output
+    ERROR_VARIABLE error
+    )
+  if(EXISTS "${BIN}")
+    file(REMOVE "${BIN}")
+  endif()
+  set(include_dirs)
+  set(link_dirs)
+  set(link_libs)
+  string(REGEX REPLACE "\r?\n" ";" output_lines "${output}\n${error}")
+  foreach(line IN LISTS output_lines)
+    if("${line}" MATCHES "${compiler_cmd}")
+      __cray_extract_args("${line}" " -(I ?|isystem )([^ ]*)" include_dirs 1)
+      set(processed_include 1)
+    endif()
+    if("${line}" MATCHES "${link_cmd}")
+      __cray_extract_args("${line}" " -(L ?)([^ ]*)" link_dirs 1)
+      __cray_extract_args("${line}" " -(l ?)([^ ]*)" link_libs 0)
+      set(processed_link 1)
+    endif()
+    if(processed_include AND processed_link)
+      break()
+    endif()
+  endforeach()
+
+  set(${include_dirs_var} "${include_dirs}" PARENT_SCOPE)
+  set(${link_dirs_var}    "${link_dirs}" PARENT_SCOPE)
+  set(${link_libs_var}    "${link_libs}" PARENT_SCOPE)
+  set(CRAY_${lang}_EXTRACTED_IMPLICIT 1 CACHE INTERNAL "" FORCE)
+endfunction()
+
+macro(__CrayPrgEnv_setup lang test_src compiler_cmd link_cmd)
+  if(DEFINED ENV{CRAYPE_VERSION})
+    message(STATUS "Cray Programming Environment $ENV{CRAYPE_VERSION} ${lang}")
+  elseif(DEFINED ENV{ASYNCPE_VERSION})
+    message(STATUS "Cray XT Programming Environment $ENV{ASYNCPE_VERSION} ${lang}")
+  endif()
+
+  # Flags for the Cray wrappers
+  set(CMAKE_STATIC_LIBRARY_LINK_${lang}_FLAGS "-static")
+  set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "")
+  set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
+  set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-dynamic")
+
+  # If the link type is not explicitly specified in the environment then
+  # the Cray wrappers assume that the code will be built staticly so
+  # we check the following condition(s) are NOT met
+  #  Compiler flags are explicitly dynamic
+  #  Env var is dynamic and compiler flags are not explicitly static
+  if(NOT (((CMAKE_${lang}_FLAGS MATCHES "(^| )-dynamic($| )") OR
+         (CMAKE_EXE_LINKER_FLAGS MATCHES "(^| )-dynamic($| )"))
+         OR
+         (("$ENV{CRAYPE_LINK_TYPE}" STREQUAL "dynamic") AND
+          NOT ((CMAKE_${lang}_FLAGS MATCHES "(^| )-static($| )") OR
+               (CMAKE_EXE_LINKER_FLAGS MATCHES "(^| )-static($| )")))))
+    set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
+    set(BUILD_SHARED_LIBS FALSE CACHE BOOL "")
+    set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+    set(CMAKE_LINK_SEARCH_START_STATIC TRUE)
+  endif()
+  if(NOT CRAY_${lang}_EXTRACTED_IMPLICIT)
+    __cray_extract_implicit(
+      ${test_src} ${compiler_cmd} ${link_cmd} ${lang}
+      CMAKE_${lang}_IMPLICIT_INCLUDE_DIRECTORIES
+      CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES
+      CMAKE_${lang}_IMPLICIT_LINK_LIBRARIES
+      )
+  endif()
+endmacro()
diff --git a/Modules/Compiler/Embarcadero-DetermineCompiler.cmake b/Modules/Compiler/Embarcadero-DetermineCompiler.cmake
index 2feedac..8375624 100644
--- a/Modules/Compiler/Embarcadero-DetermineCompiler.cmake
+++ b/Modules/Compiler/Embarcadero-DetermineCompiler.cmake
@@ -4,4 +4,4 @@ set(_compiler_id_pp_test "defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__
 set(_compiler_id_version_compute "
 # define @PREFIX at COMPILER_VERSION_MAJOR @MACRO_HEX@(__CODEGEARC_VERSION__>>24 & 0x00FF)
 # define @PREFIX at COMPILER_VERSION_MINOR @MACRO_HEX@(__CODEGEARC_VERSION__>>16 & 0x00FF)
-# define @PREFIX at COMPILER_VERSION_PATCH @MACRO_HEX@(__CODEGEARC_VERSION__     & 0xFFFF)")
+# define @PREFIX at COMPILER_VERSION_PATCH @MACRO_DEC@(__CODEGEARC_VERSION__     & 0xFFFF)")
diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake
index c822bdb..249658d 100644
--- a/Modules/ExternalProject.cmake
+++ b/Modules/ExternalProject.cmake
@@ -57,6 +57,8 @@ Create custom targets to build projects in external trees
     URL of git repo
   ``GIT_TAG <tag>``
     Git branch name, commit id or tag
+  ``GIT_REMOTE_NAME <name>``
+    The optional name of the remote, default to ``origin``
   ``GIT_SUBMODULES <module>...``
     Git submodules that shall be updated, all if empty
   ``HG_REPOSITORY <url>``
@@ -494,7 +496,7 @@ define_property(DIRECTORY PROPERTY "EP_UPDATE_DISCONNECTED" INHERITED
   "ExternalProject module."
   )
 
-function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git_repository git_tag git_submodules src_name work_dir gitclone_infofile gitclone_stampfile)
+function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git_repository git_tag git_remote_name git_submodules src_name work_dir gitclone_infofile gitclone_stampfile)
   file(WRITE ${script_filename}
 "if(\"${git_tag}\" STREQUAL \"\")
   message(FATAL_ERROR \"Tag for git checkout should not be empty.\")
@@ -524,7 +526,7 @@ set(error_code 1)
 set(number_of_tries 0)
 while(error_code AND number_of_tries LESS 3)
   execute_process(
-    COMMAND \"${git_EXECUTABLE}\" clone \"${git_repository}\" \"${src_name}\"
+    COMMAND \"${git_EXECUTABLE}\" clone --origin \"${git_remote_name}\" \"${git_repository}\" \"${src_name}\"
     WORKING_DIRECTORY \"${work_dir}\"
     RESULT_VARIABLE error_code
     )
@@ -645,7 +647,7 @@ endif()
 endfunction()
 
 
-function(_ep_write_gitupdate_script script_filename git_EXECUTABLE git_tag git_submodules git_repository work_dir)
+function(_ep_write_gitupdate_script script_filename git_EXECUTABLE git_tag git_remote_name git_submodules git_repository work_dir)
   if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.6)
     set(git_stash_save_options --all --quiet)
   else()
@@ -687,7 +689,7 @@ if(\"\${show_ref_output}\" MATCHES \"refs/remotes/${git_tag}\")
   set(git_remote \"\${CMAKE_MATCH_1}\")
   set(git_tag \"\${CMAKE_MATCH_2}\")
 else()
-  set(git_remote \"origin\")
+  set(git_remote \"${git_remote_name}\")
   set(git_tag \"${git_tag}\")
 endif()
 
@@ -1228,9 +1230,24 @@ function(_ep_get_build_command name step cmd_var)
           set(cmd "${CMAKE_COMMAND}")
         endif()
         set(args --build ".")
-        if (CMAKE_CFG_INTDIR AND NOT CMAKE_CFG_INTDIR STREQUAL ".")
-          list(APPEND args --config "${CMAKE_CFG_INTDIR}")
-        endif ()
+        if(CMAKE_CONFIGURATION_TYPES)
+          if (CMAKE_CFG_INTDIR AND
+              NOT CMAKE_CFG_INTDIR STREQUAL "." AND
+              NOT CMAKE_CFG_INTDIR MATCHES "\\$")
+            # CMake 3.4 and below used the CMAKE_CFG_INTDIR placeholder value
+            # provided by multi-configuration generators.  Some projects were
+            # taking advantage of that undocumented implementation detail to
+            # specify a specific configuration here.  They should use
+            # BUILD_COMMAND to change the default command instead, but for
+            # compatibility honor the value.
+            set(config ${CMAKE_CFG_INTDIR})
+            message(AUTHOR_WARNING "CMAKE_CFG_INTDIR should not be set by project code.\n"
+              "To get a non-default build command, use the BUILD_COMMAND option.")
+          else()
+            set(config $<CONFIG>)
+          endif()
+          list(APPEND args --config ${config})
+        endif()
         if(step STREQUAL "INSTALL")
           list(APPEND args --target install)
         endif()
@@ -1238,6 +1255,9 @@ function(_ep_get_build_command name step cmd_var)
         if("x${step}x" STREQUAL "xTESTx")
           string(REGEX REPLACE "^(.*/)cmake([^/]*)$" "\\1ctest\\2" cmd "${cmd}")
           set(args "")
+          if(CMAKE_CONFIGURATION_TYPES)
+            list(APPEND args -C ${config})
+          endif()
         endif()
       endif()
     else()
@@ -1749,6 +1769,11 @@ function(_ep_add_download_command name)
     endif()
     get_property(git_submodules TARGET ${name} PROPERTY _EP_GIT_SUBMODULES)
 
+    get_property(git_remote_name TARGET ${name} PROPERTY _EP_GIT_REMOTE_NAME)
+    if(NOT git_remote_name)
+      set(git_remote_name "origin")
+    endif()
+
     # For the download step, and the git clone operation, only the repository
     # should be recorded in a configured RepositoryInfo file. If the repo
     # changes, the clone script should be run again. But if only the tag
@@ -1772,7 +1797,7 @@ function(_ep_add_download_command name)
     # The script will delete the source directory and then call git clone.
     #
     _ep_write_gitclone_script(${tmp_dir}/${name}-gitclone.cmake ${source_dir}
-      ${GIT_EXECUTABLE} ${git_repository} ${git_tag} "${git_submodules}" ${src_name} ${work_dir}
+      ${GIT_EXECUTABLE} ${git_repository} ${git_tag} ${git_remote_name} "${git_submodules}" ${src_name} ${work_dir}
       ${stamp_dir}/${name}-gitinfo.txt ${stamp_dir}/${name}-gitclone-lastrun.txt
       )
     set(comment "Performing download step (git clone) for '${name}'")
@@ -1993,9 +2018,13 @@ function(_ep_add_update_command name)
     if(NOT git_tag)
       set(git_tag "master")
     endif()
+    get_property(git_remote_name TARGET ${name} PROPERTY _EP_GIT_REMOTE_NAME)
+    if(NOT git_remote_name)
+      set(git_remote_name "origin")
+    endif()
     get_property(git_submodules TARGET ${name} PROPERTY _EP_GIT_SUBMODULES)
     _ep_write_gitupdate_script(${tmp_dir}/${name}-gitupdate.cmake
-      ${GIT_EXECUTABLE} ${git_tag} "${git_submodules}" ${git_repository} ${work_dir}
+      ${GIT_EXECUTABLE} ${git_tag} ${git_remote_name} "${git_submodules}" ${git_repository} ${work_dir}
       )
     set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitupdate.cmake)
     set(always 1)
diff --git a/Modules/FindBLAS.cmake b/Modules/FindBLAS.cmake
index 6a583d9..416b666 100644
--- a/Modules/FindBLAS.cmake
+++ b/Modules/FindBLAS.cmake
@@ -494,18 +494,18 @@ if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
         list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
           "mkl_blas95${BLAS_mkl_DLL_SUFFIX} mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
       endif()
-      if (BLA_VENDOR STREQUAL "Intel10_64lp*" OR BLA_VENDOR STREQUAL "All")
+      if (BLA_VENDOR MATCHES "^Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
         list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
           "mkl_blas95_lp64${BLAS_mkl_DLL_SUFFIX} mkl_intel_lp64${BLAS_mkl_DLL_SUFFIX}")
       endif ()
 
       # Add threading/sequential libs
       set(BLAS_SEARCH_LIBS_WIN_THREAD "")
-      if (BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
+      if (BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All")
         list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
           "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
       endif()
-      if (NOT BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
+      if (NOT BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All")
         # old version
         list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
           "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
@@ -561,14 +561,14 @@ if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
         list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
           "mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
       endif()
-      if (BLA_VENDOR STREQUAL "Intel10_64lp*" OR BLA_VENDOR STREQUAL "All")
+      if (BLA_VENDOR MATCHES "^Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
         list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
           "mkl_intel_lp64${BLAS_mkl_DLL_SUFFIX}")
       endif ()
 
       # Add threading/sequential libs
       set(BLAS_SEARCH_LIBS_WIN_THREAD "")
-      if (NOT BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
+      if (NOT BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All")
         # old version
         list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
           "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
@@ -576,7 +576,7 @@ if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
         list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
           "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
       endif()
-      if (BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
+      if (BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All")
         list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
           "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
       endif()
diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake
index 33e6a49..c3058ea 100644
--- a/Modules/FindBoost.cmake
+++ b/Modules/FindBoost.cmake
@@ -54,6 +54,33 @@
 #   Boost_<C>_LIBRARY_DEBUG   - Component <C> library debug variant
 #   Boost_<C>_LIBRARY_RELEASE - Component <C> library release variant
 #
+# The following :prop_tgt:`IMPORTED` targets are also defined::
+#
+#   Boost::boost                  - Target for header-only dependencies
+#                                   (Boost include directory)
+#   Boost::<C>                    - Target for specific component dependency
+#                                   (shared or static library); <C> is lower-
+#                                   case
+#   Boost::diagnostic_definitions - interface target to enable diagnostic
+#                                   information about Boost's automatic linking
+#                                   during compilation (adds BOOST_LIB_DIAGNOSTIC)
+#   Boost::disable_autolinking    - interface target to disable automatic
+#                                   linking with MSVC (adds BOOST_ALL_NO_LIB)
+#   Boost::dynamic_linking        - interface target to enable dynamic linking
+#                                   linking with MSVC (adds BOOST_ALL_DYN_LINK)
+#
+# Implicit dependencies such as Boost::filesystem requiring
+# Boost::system will be automatically detected and satisfied, even
+# if system is not specified when using find_package and if
+# Boost::system is not added to target_link_libraries.  If using
+# Boost::thread, then Thread::Thread will also be added automatically.
+#
+# It is important to note that the imported targets behave differently
+# than variables created by this module: multiple calls to
+# find_package(Boost) in the same directory or sub-directories with
+# different options (e.g. static or shared) will not override the
+# values of the targets created by the first call.
+#
 # Users may set these hints or results as cache entries.  Projects
 # should not read these entries directly but instead use the above
 # result variables.  Note that some hint names start in upper-case
@@ -142,6 +169,14 @@
 #     add_executable(foo foo.cc)
 #   endif()
 #
+# Example to find Boost libraries and use imported targets::
+#
+#   find_package(Boost 1.56 REQUIRED COMPONENTS
+#                date_time filesystem iostreams)
+#   add_executable(foo foo.cc)
+#   target_link_libraries(foo Boost::date_time Boost::filesystem
+#                             Boost::iostreams)
+#
 # Example to find Boost headers and some *static* libraries::
 #
 #   set(Boost_USE_STATIC_LIBS        ON) # only find static libs
@@ -472,6 +507,276 @@ function(_Boost_GUESS_COMPILER_PREFIX _ret)
 endfunction()
 
 #
+# Get component dependencies.  Requires the dependencies to have been
+# defined for the Boost release version.
+#
+# component - the component to check
+# _ret - list of library dependencies
+#
+function(_Boost_COMPONENT_DEPENDENCIES component _ret)
+  # Note: to add a new Boost release, run
+  #
+  #   % cmake -DBOOST_DIR=/path/to/boost/source -P Utilities/Scripts/BoostScanDeps.cmake
+  #
+  # The output may be added in a new block below.  If it's the same as
+  # the previous release, simply update the version range of the block
+  # for the previous release.
+  #
+  # This information was originally generated by running
+  # BoostScanDeps.cmake against every boost release to date supported
+  # by FindBoost:
+  #
+  #   % for version in /path/to/boost/sources/*
+  #     do
+  #       cmake -DBOOST_DIR=$version -P Utilities/Scripts/BoostScanDeps.cmake
+  #     done
+  #
+  # The output was then updated by search and replace with these regexes:
+  #
+  # - Strip message(STATUS) prefix dashes
+  #   s;^-- ;;
+  # - Indent
+  #   s;^set(;    set(;;
+  # - Add conditionals
+  #   s;Scanning /path/to/boost/sources/boost_\(.*\)_\(.*\)_\(.*);  elseif(NOT Boost_VERSION VERSION_LESS \10\20\3 AND Boost_VERSION VERSION_LESS xxxx);
+  #
+  # This results in the logic seen below, but will require the xxxx
+  # replacing with the following Boost release version (or the next
+  # minor version to be released, e.g. 1.59 was the latest at the time
+  # of writing, making 1.60 the next, so 106000 is the needed version
+  # number).  Identical consecutive releases were then merged together
+  # by updating the end range of the first block and removing the
+  # following redundant blocks.
+  #
+  # Running the script against all historical releases should be
+  # required only if the BoostScanDeps.cmake script logic is changed.
+  # The addition of a new release should only require it to be run
+  # against the new release.
+  set(_Boost_IMPORTED_TARGETS TRUE)
+  if(NOT Boost_VERSION VERSION_LESS 103300 AND Boost_VERSION VERSION_LESS 103500)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex thread)
+    set(_Boost_REGEX_DEPENDENCIES thread)
+    set(_Boost_WAVE_DEPENDENCIES filesystem thread)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  elseif(NOT Boost_VERSION VERSION_LESS 103500 AND Boost_VERSION VERSION_LESS 103600)
+    set(_Boost_FILESYSTEM_DEPENDENCIES system)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+    set(_Boost_MPI_DEPENDENCIES serialization)
+    set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+    set(_Boost_WAVE_DEPENDENCIES filesystem system thread)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  elseif(NOT Boost_VERSION VERSION_LESS 103600 AND Boost_VERSION VERSION_LESS 103800)
+    set(_Boost_FILESYSTEM_DEPENDENCIES system)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+    set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l)
+    set(_Boost_MPI_DEPENDENCIES serialization)
+    set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+    set(_Boost_WAVE_DEPENDENCIES filesystem system thread)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  elseif(NOT Boost_VERSION VERSION_LESS 103800 AND Boost_VERSION VERSION_LESS 104300)
+    set(_Boost_FILESYSTEM_DEPENDENCIES system)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+    set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l)
+    set(_Boost_MPI_DEPENDENCIES serialization)
+    set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+    set(_Boost_THREAD_DEPENDENCIES date_time)
+    set(_Boost_WAVE_DEPENDENCIES filesystem system thread date_time)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  elseif(NOT Boost_VERSION VERSION_LESS 104300 AND Boost_VERSION VERSION_LESS 104400)
+    set(_Boost_FILESYSTEM_DEPENDENCIES system)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+    set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l random)
+    set(_Boost_MPI_DEPENDENCIES serialization)
+    set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+    set(_Boost_THREAD_DEPENDENCIES date_time)
+    set(_Boost_WAVE_DEPENDENCIES filesystem system thread date_time)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  elseif(NOT Boost_VERSION VERSION_LESS 104400 AND Boost_VERSION VERSION_LESS 104500)
+    set(_Boost_FILESYSTEM_DEPENDENCIES system)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+    set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l random serialization)
+    set(_Boost_MPI_DEPENDENCIES serialization)
+    set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+    set(_Boost_THREAD_DEPENDENCIES date_time)
+    set(_Boost_WAVE_DEPENDENCIES serialization filesystem system thread date_time)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  elseif(NOT Boost_VERSION VERSION_LESS 104500 AND Boost_VERSION VERSION_LESS 104700)
+    set(_Boost_FILESYSTEM_DEPENDENCIES system)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+    set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l random)
+    set(_Boost_MPI_DEPENDENCIES serialization)
+    set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+    set(_Boost_THREAD_DEPENDENCIES date_time)
+    set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread date_time)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  elseif(NOT Boost_VERSION VERSION_LESS 104700 AND Boost_VERSION VERSION_LESS 104800)
+    set(_Boost_CHRONO_DEPENDENCIES system)
+    set(_Boost_FILESYSTEM_DEPENDENCIES system)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+    set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l random)
+    set(_Boost_MPI_DEPENDENCIES serialization)
+    set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+    set(_Boost_THREAD_DEPENDENCIES date_time)
+    set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread date_time)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  elseif(NOT Boost_VERSION VERSION_LESS 104800 AND Boost_VERSION VERSION_LESS 105000)
+    set(_Boost_CHRONO_DEPENDENCIES system)
+    set(_Boost_FILESYSTEM_DEPENDENCIES system)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+    set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l random)
+    set(_Boost_MPI_DEPENDENCIES serialization)
+    set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+    set(_Boost_THREAD_DEPENDENCIES date_time)
+    set(_Boost_TIMER_DEPENDENCIES chrono system)
+    set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread date_time)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  elseif(NOT Boost_VERSION VERSION_LESS 105000 AND Boost_VERSION VERSION_LESS 105300)
+    set(_Boost_CHRONO_DEPENDENCIES system)
+    set(_Boost_FILESYSTEM_DEPENDENCIES system)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+    set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l regex random)
+    set(_Boost_MPI_DEPENDENCIES serialization)
+    set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+    set(_Boost_THREAD_DEPENDENCIES chrono system date_time)
+    set(_Boost_TIMER_DEPENDENCIES chrono system)
+    set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  elseif(NOT Boost_VERSION VERSION_LESS 105300 AND Boost_VERSION VERSION_LESS 105400)
+    set(_Boost_ATOMIC_DEPENDENCIES thread chrono system date_time)
+    set(_Boost_CHRONO_DEPENDENCIES system)
+    set(_Boost_FILESYSTEM_DEPENDENCIES system)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+    set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l regex random)
+    set(_Boost_MPI_DEPENDENCIES serialization)
+    set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+    set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
+    set(_Boost_TIMER_DEPENDENCIES chrono system)
+    set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  elseif(NOT Boost_VERSION VERSION_LESS 105400 AND Boost_VERSION VERSION_LESS 105500)
+    set(_Boost_ATOMIC_DEPENDENCIES thread chrono system date_time)
+    set(_Boost_CHRONO_DEPENDENCIES system)
+    set(_Boost_FILESYSTEM_DEPENDENCIES system)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+    set(_Boost_LOG_DEPENDENCIES log_setup date_time system filesystem thread regex chrono)
+    set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l regex random)
+    set(_Boost_MPI_DEPENDENCIES serialization)
+    set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+    set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
+    set(_Boost_TIMER_DEPENDENCIES chrono system)
+    set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  elseif(NOT Boost_VERSION VERSION_LESS 105500 AND Boost_VERSION VERSION_LESS 105600)
+    set(_Boost_CHRONO_DEPENDENCIES system)
+    set(_Boost_COROUTINE_DEPENDENCIES context system)
+    set(_Boost_FILESYSTEM_DEPENDENCIES system)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+    set(_Boost_LOG_DEPENDENCIES log_setup date_time system filesystem thread regex chrono)
+    set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l regex random)
+    set(_Boost_MPI_DEPENDENCIES serialization)
+    set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+    set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
+    set(_Boost_TIMER_DEPENDENCIES chrono system)
+    set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  elseif(NOT Boost_VERSION VERSION_LESS 105600 AND Boost_VERSION VERSION_LESS 105900)
+    set(_Boost_CHRONO_DEPENDENCIES system)
+    set(_Boost_COROUTINE_DEPENDENCIES context system)
+    set(_Boost_FILESYSTEM_DEPENDENCIES system)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+    set(_Boost_LOG_DEPENDENCIES log_setup date_time system filesystem thread regex chrono)
+    set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
+    set(_Boost_MPI_DEPENDENCIES serialization)
+    set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+    set(_Boost_RANDOM_DEPENDENCIES system)
+    set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
+    set(_Boost_TIMER_DEPENDENCIES chrono system)
+    set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  elseif(NOT Boost_VERSION VERSION_LESS 105900 AND Boost_VERSION VERSION_LESS 106000)
+    set(_Boost_CHRONO_DEPENDENCIES system)
+    set(_Boost_COROUTINE_DEPENDENCIES context system)
+    set(_Boost_FILESYSTEM_DEPENDENCIES system)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+    set(_Boost_LOG_DEPENDENCIES log_setup date_time system filesystem thread regex chrono atomic)
+    set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
+    set(_Boost_MPI_DEPENDENCIES serialization)
+    set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+    set(_Boost_RANDOM_DEPENDENCIES system)
+    set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
+    set(_Boost_TIMER_DEPENDENCIES chrono system)
+    set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  elseif(NOT Boost_VERSION VERSION_LESS 106000 AND Boost_VERSION VERSION_LESS 106200)
+    set(_Boost_CHRONO_DEPENDENCIES system)
+    set(_Boost_COROUTINE_DEPENDENCIES context system)
+    set(_Boost_FILESYSTEM_DEPENDENCIES system)
+    set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+    set(_Boost_LOG_DEPENDENCIES date_time log_setup system filesystem thread regex chrono atomic)
+    set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
+    set(_Boost_MPI_DEPENDENCIES serialization)
+    set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+    set(_Boost_RANDOM_DEPENDENCIES system)
+    set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
+    set(_Boost_TIMER_DEPENDENCIES chrono system)
+    set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
+    set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+  else()
+    message(WARNING "Imported targets not available for Boost version ${Boost_VERSION}")
+    set(_Boost_IMPORTED_TARGETS FALSE)
+  endif()
+
+  string(TOUPPER ${component} uppercomponent)
+  set(${_ret} ${_Boost_${uppercomponent}_DEPENDENCIES} PARENT_SCOPE)
+  set(_Boost_IMPORTED_TARGETS ${_Boost_IMPORTED_TARGETS} PARENT_SCOPE)
+
+  string(REGEX REPLACE ";" " " _boost_DEPS_STRING "${_Boost_${uppercomponent}_DEPENDENCIES}")
+  if (NOT _boost_DEPS_STRING)
+    set(_boost_DEPS_STRING "(none)")
+  endif()
+  # message(STATUS "Dependencies for Boost::${component}: ${_boost_DEPS_STRING}")
+endfunction()
+
+#
+# Determine if any missing dependencies require adding to the component list.
+#
+# Sets _Boost_${COMPONENT}_DEPENDENCIES for each required component,
+# plus _Boost_IMPORTED_TARGETS (TRUE if imported targets should be
+# defined; FALSE if dependency information is unavailable).
+#
+# componentvar - the component list variable name
+#
+#
+function(_Boost_MISSING_DEPENDENCIES componentvar)
+  # _boost_unprocessed_components - list of components requiring processing
+  # _boost_processed_components - components already processed (or currently being processed)
+  # _boost_new_components - new components discovered for future processing
+  #
+  list(APPEND _boost_unprocessed_components ${${componentvar}})
+
+  while(_boost_unprocessed_components)
+    list(APPEND _boost_processed_components ${_boost_unprocessed_components})
+    foreach(component ${_boost_unprocessed_components})
+      string(TOUPPER ${component} uppercomponent)
+  set(${_ret} ${_Boost_${uppercomponent}_DEPENDENCIES} PARENT_SCOPE)
+      _Boost_COMPONENT_DEPENDENCIES("${component}" _Boost_${uppercomponent}_DEPENDENCIES)
+      set(_Boost_${uppercomponent}_DEPENDENCIES ${_Boost_${uppercomponent}_DEPENDENCIES} PARENT_SCOPE)
+      set(_Boost_IMPORTED_TARGETS ${_Boost_IMPORTED_TARGETS} PARENT_SCOPE)
+      foreach(componentdep ${_Boost_${uppercomponent}_DEPENDENCIES})
+        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()
+    endforeach()
+    set(_boost_unprocessed_components ${_boost_new_components})
+    unset(_boost_new_components)
+  endwhile()
+  set(${componentvar} ${_boost_processed_components} PARENT_SCOPE)
+endfunction()
+
+#
 # End functions/macros
 #
 #-------------------------------------------------------------------------------
@@ -511,8 +816,12 @@ if(Boost_FIND_VERSION_EXACT)
 else()
   # The user has not requested an exact version.  Among known
   # versions, find those that are acceptable to the user request.
+  #
+  # Note: When adding a new Boost release, also update the dependency
+  # information in _Boost_COMPONENT_DEPENDENCIES.  See the
+  # instructions at the top of _Boost_COMPONENT_DEPENDENCIES.
   set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS}
-
+    "1.61.0" "1.61" "1.60.0" "1.60"
     "1.59.0" "1.59" "1.58.0" "1.58" "1.57.0" "1.57" "1.56.0" "1.56" "1.55.0" "1.55"
     "1.54.0" "1.54" "1.53.0" "1.53" "1.52.0" "1.52" "1.51.0" "1.51"
     "1.50.0" "1.50" "1.49.0" "1.49" "1.48.0" "1.48" "1.47.0" "1.47" "1.46.1"
@@ -562,6 +871,16 @@ if(Boost_DEBUG)
                  "Boost_NO_SYSTEM_PATHS = ${Boost_NO_SYSTEM_PATHS}")
 endif()
 
+# Supply Boost_LIB_DIAGNOSTIC_DEFINITIONS as a convenience target. It
+# will only contain any interface definitions on WIN32, but is created
+# on all platforms to keep end user code free from platform dependent
+# code.  Also provide convenience targets to disable autolinking and
+# enable dynamic linking.
+if(NOT TARGET Boost::diagnostic_definitions)
+  add_library(Boost::diagnostic_definitions INTERFACE IMPORTED)
+  add_library(Boost::disable_autolinking INTERFACE IMPORTED)
+  add_library(Boost::dynamic_linking INTERFACE IMPORTED)
+endif()
 if(WIN32)
   # In windows, automatic linking is performed, so you do not have
   # to specify the libraries.  If you are linking to a dynamic
@@ -581,6 +900,12 @@ if(WIN32)
   # code to emit a #pragma message each time a library is selected
   # for linking.
   set(Boost_LIB_DIAGNOSTIC_DEFINITIONS "-DBOOST_LIB_DIAGNOSTIC")
+  set_target_properties(Boost::diagnostic_definitions PROPERTIES
+    INTERFACE_COMPILE_DEFINITIONS "BOOST_LIB_DIAGNOSTIC")
+  set_target_properties(Boost::disable_autolinking PROPERTIES
+    INTERFACE_COMPILE_DEFINITIONS "BOOST_ALL_NO_LIB")
+  set_target_properties(Boost::dynamic_linking PROPERTIES
+    INTERFACE_COMPILE_DEFINITIONS "BOOST_ALL_DYN_LINK")
 endif()
 
 _Boost_CHECK_SPELLING(Boost_ROOT)
@@ -979,6 +1304,17 @@ if(Boost_VERSION AND Boost_FIND_COMPONENTS)
    endif()
 endif()
 
+# Additional components may be required via component dependencies.
+# Add any missing components to the list.
+_Boost_MISSING_DEPENDENCIES(Boost_FIND_COMPONENTS)
+
+# If thread is required, get the thread libs as a dependency
+list(FIND Boost_FIND_COMPONENTS thread _Boost_THREAD_DEPENDENCY_LIBS)
+if(NOT _Boost_THREAD_DEPENDENCY_LIBS EQUAL -1)
+  include(CMakeFindDependencyMacro)
+  find_dependency(Threads)
+endif()
+
 # If the user changed any of our control inputs flush previous results.
 if(_Boost_CHANGE_LIBDIR OR _Boost_CHANGE_LIBNAME)
   foreach(COMPONENT ${_Boost_COMPONENTS_SEARCHED})
@@ -1222,6 +1558,70 @@ else()
 endif()
 
 # ------------------------------------------------------------------------
+#  Add imported targets
+# ------------------------------------------------------------------------
+
+if(Boost_FOUND AND _Boost_IMPORTED_TARGETS)
+  # For header-only libraries
+  if(NOT TARGET Boost::boost)
+    add_library(Boost::boost INTERFACE IMPORTED)
+    if(Boost_INCLUDE_DIRS)
+      set_target_properties(Boost::boost PROPERTIES
+        INTERFACE_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIRS}")
+    endif()
+  endif()
+
+  foreach(COMPONENT ${Boost_FIND_COMPONENTS})
+    if(NOT TARGET Boost::${COMPONENT})
+      string(TOUPPER ${COMPONENT} UPPERCOMPONENT)
+      if(Boost_${UPPERCOMPONENT}_FOUND)
+        if(Boost_USE_STATIC_LIBS)
+          add_library(Boost::${COMPONENT} STATIC IMPORTED)
+        else()
+          # Even if Boost_USE_STATIC_LIBS is OFF, we might have static
+          # libraries as a result.
+          add_library(Boost::${COMPONENT} UNKNOWN IMPORTED)
+        endif()
+        if(Boost_INCLUDE_DIRS)
+          set_target_properties(Boost::${COMPONENT} PROPERTIES
+            INTERFACE_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIRS}")
+        endif()
+        if(EXISTS "${Boost_${UPPERCOMPONENT}_LIBRARY}")
+          set_target_properties(Boost::${COMPONENT} PROPERTIES
+            IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
+            IMPORTED_LOCATION "${Boost_${UPPERCOMPONENT}_LIBRARY}")
+        endif()
+        if(EXISTS "${Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG}")
+          set_property(TARGET Boost::${COMPONENT} APPEND PROPERTY
+            IMPORTED_CONFIGURATIONS DEBUG)
+          set_target_properties(Boost::${COMPONENT} PROPERTIES
+            IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
+            IMPORTED_LOCATION_DEBUG "${Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG}")
+        endif()
+        if(EXISTS "${Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE}")
+          set_property(TARGET Boost::${COMPONENT} APPEND PROPERTY
+            IMPORTED_CONFIGURATIONS RELEASE)
+          set_target_properties(Boost::${COMPONENT} PROPERTIES
+            IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
+            IMPORTED_LOCATION_RELEASE "${Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE}")
+        endif()
+        if(_Boost_${UPPERCOMPONENT}_DEPENDENCIES)
+          unset(_Boost_${UPPERCOMPONENT}_TARGET_DEPENDENCIES)
+          foreach(dep ${_Boost_${UPPERCOMPONENT}_DEPENDENCIES})
+            list(APPEND _Boost_${UPPERCOMPONENT}_TARGET_DEPENDENCIES Boost::${dep})
+          endforeach()
+          if(COMPONENT STREQUAL "thread")
+            list(APPEND _Boost_${UPPERCOMPONENT}_TARGET_DEPENDENCIES Threads::Threads)
+          endif()
+          set_target_properties(Boost::${COMPONENT} PROPERTIES
+            INTERFACE_LINK_LIBRARIES "${_Boost_${UPPERCOMPONENT}_TARGET_DEPENDENCIES}")
+        endif()
+      endif()
+    endif()
+  endforeach()
+endif()
+
+# ------------------------------------------------------------------------
 #  Notification to end user about what was found
 # ------------------------------------------------------------------------
 
diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake
index 1fc582f..47c03f3 100644
--- a/Modules/FindCUDA.cmake
+++ b/Modules/FindCUDA.cmake
@@ -653,6 +653,9 @@ set(CUDA_VERSION_STRING "${CUDA_VERSION}")
 # Support for arm cross compilation with CUDA 5.5
 if(CUDA_VERSION VERSION_GREATER "5.0" AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm" AND EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/targets/armv7-linux-gnueabihf")
   set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT_DIR}/targets/armv7-linux-gnueabihf" CACHE PATH "Toolkit target location.")
+# Support for aarch64 cross compilation with CUDA 7.0
+elseif(CUDA_VERSION VERSION_GREATER "6.5" AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" AND EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/targets/aarch64-linux")
+  set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT_DIR}/targets/aarch64-linux" CACHE PATH "Toolkit target location.")
 else()
   set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT_DIR}" CACHE PATH "Toolkit target location.")
 endif()
@@ -764,13 +767,9 @@ if(CUDA_USE_STATIC_CUDA_RUNTIME)
     if (NOT APPLE)
       # Here is librt that has things such as, clock_gettime, shm_open, and shm_unlink.
       find_library(CUDA_rt_LIBRARY rt)
-      find_library(CUDA_dl_LIBRARY dl)
       if (NOT CUDA_rt_LIBRARY)
         message(WARNING "Expecting to find librt for libcudart_static, but didn't find it.")
       endif()
-      if (NOT CUDA_dl_LIBRARY)
-        message(WARNING "Expecting to find libdl for libcudart_static, but didn't find it.")
-      endif()
     endif()
   endif()
 endif()
@@ -793,13 +792,10 @@ set(CUDA_LIBRARIES)
 if(CUDA_BUILD_EMULATION AND CUDA_CUDARTEMU_LIBRARY)
   list(APPEND CUDA_LIBRARIES ${CUDA_CUDARTEMU_LIBRARY})
 elseif(CUDA_USE_STATIC_CUDA_RUNTIME AND CUDA_cudart_static_LIBRARY)
-  list(APPEND CUDA_LIBRARIES ${CUDA_cudart_static_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
+  list(APPEND CUDA_LIBRARIES ${CUDA_cudart_static_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
   if (CUDA_rt_LIBRARY)
     list(APPEND CUDA_LIBRARIES ${CUDA_rt_LIBRARY})
   endif()
-  if (CUDA_dl_LIBRARY)
-    list(APPEND CUDA_LIBRARIES ${CUDA_dl_LIBRARY})
-  endif()
   if(APPLE)
     # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that
     # the static cuda runtime can find it at runtime.
@@ -1460,6 +1456,11 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
         set(cuda_build_comment_string "Building NVCC (${cuda_build_type}) object ${generated_file_relative_path}")
       endif()
 
+      set(_verbatim VERBATIM)
+      if(ccbin_flags MATCHES "\\$\\(VCInstallDir\\)")
+        set(_verbatim "")
+      endif()
+
       # Build the generated file and dependency file ##########################
       add_custom_command(
         OUTPUT ${generated_file}
@@ -1478,6 +1479,7 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
           -P "${custom_target_script}"
         WORKING_DIRECTORY "${cuda_compile_intermediate_directory}"
         COMMENT "${cuda_build_comment_string}"
+        ${_verbatim}
         )
 
       # Make sure the build system knows the file is generated.
@@ -1589,6 +1591,11 @@ function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options
       set(do_obj_build_rule FALSE)
     endif()
 
+    set(_verbatim VERBATIM)
+    if(nvcc_flags MATCHES "\\$\\(VCInstallDir\\)")
+      set(_verbatim "")
+    endif()
+
     if (do_obj_build_rule)
       add_custom_command(
         OUTPUT ${output_file}
@@ -1596,6 +1603,7 @@ function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options
         COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} -dlink ${object_files} -o ${output_file}
         ${flags}
         COMMENT "Building NVCC intermediate link file ${output_file_relative_path}"
+        ${_verbatim}
         )
     else()
       get_filename_component(output_file_dir "${output_file}" DIRECTORY)
@@ -1605,6 +1613,7 @@ function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options
         COMMAND ${CMAKE_COMMAND} -E echo "Building NVCC intermediate link file ${output_file_relative_path}"
         COMMAND ${CMAKE_COMMAND} -E make_directory "${output_file_dir}"
         COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} ${flags} -dlink ${object_files} -o "${output_file}"
+        ${_verbatim}
         )
     endif()
  endif()
diff --git a/Modules/FindDCMTK.cmake b/Modules/FindDCMTK.cmake
index 91aafbb..63d253d 100644
--- a/Modules/FindDCMTK.cmake
+++ b/Modules/FindDCMTK.cmake
@@ -2,17 +2,78 @@
 # FindDCMTK
 # ---------
 #
-# find DCMTK libraries and applications
-
-#  DCMTK_INCLUDE_DIRS   - Directories to include to use DCMTK
+# Find DCMTK libraries and applications
+#
+# The module defines the following variables::
+#
+#  DCMTK_INCLUDE_DIRS  - Directories to include to use DCMTK
 #  DCMTK_LIBRARIES     - Files to link against to use DCMTK
 #  DCMTK_FOUND         - If false, don't try to use DCMTK
 #  DCMTK_DIR           - (optional) Source directory for DCMTK
 #
-# DCMTK_DIR can be used to make it simpler to find the various include
-# directories and compiled libraries if you've just compiled it in the
-# source tree. Just set it to the root of the tree where you extracted
-# the source (default to /usr/include/dcmtk/)
+# Compatibility
+# ^^^^^^^^^^^^^
+#
+# This module is able to find a version of DCMTK that does or does not export
+# a *DCMTKConfig.cmake* file. It applies a two step process:
+#
+# * Step 1:  Attempt to find DCMTK version providing a *DCMTKConfig.cmake* file.
+# * Step 2:  If step 1 failed, rely on *FindDCMTK.cmake* to set `DCMTK_*` variables details below.
+#
+#
+# `Recent DCMTK
+# <http://git.dcmtk.org/web?p=dcmtk.git;a=commit;h=662ae187c493c6b9a73dd5e3875372cebd0c11fe>`_
+# provides a *DCMTKConfig.cmake* :manual:`package configuration file
+# <cmake-packages(7)>`. To exclusively use the package configuration file
+# (recommended when possible), pass the `NO_MODULE` option to
+# :command:`find_package`. For example, `find_package(DCMTK NO_MODULE)`.
+# This requires official DCMTK snapshot *3.6.1_20140617* or newer.
+#
+#
+# Until all clients update to the more recent DCMTK, build systems will need
+# to support different versions of DCMTK.
+#
+# On any given system, the following combinations of DCMTK versions could be
+# considered:
+#
+# +--------+---------------------+-----------------------+-------------------+
+# |        |   SYSTEM DCMTK      |      LOCAL DCMTK      |     Supported ?   |
+# +--------+---------------------+-----------------------+-------------------+
+# | Case A |   NA                |      [ ] DCMTKConfig  |         YES       |
+# +--------+---------------------+-----------------------+-------------------+
+# | Case B |   NA                |      [X] DCMTKConfig  |         YES       |
+# +--------+---------------------+-----------------------+-------------------+
+# | Case C |   [ ] DCMTKConfig   |      NA               |         YES       |
+# +--------+---------------------+-----------------------+-------------------+
+# | Case D |   [X] DCMTKConfig   |      NA               |         YES       |
+# +--------+---------------------+-----------------------+-------------------+
+# | Case E |   [ ] DCMTKConfig   |      [ ] DCMTKConfig  |         YES (*)   |
+# +--------+---------------------+-----------------------+-------------------+
+# | Case F |   [X] DCMTKConfig   |      [ ] DCMTKConfig  |         NO        |
+# +--------+---------------------+-----------------------+-------------------+
+# | Case G |   [ ] DCMTKConfig   |      [X] DCMTKConfig  |         YES       |
+# +--------+---------------------+-----------------------+-------------------+
+# | Case H |   [X] DCMTKConfig   |      [X] DCMTKConfig  |         YES       |
+# +--------+---------------------+-----------------------+-------------------+
+#
+#  (*) See Troubleshooting section.
+#
+# Legend:
+#
+#   NA ...............: Means that no System or Local DCMTK is available
+#
+#   [ ] DCMTKConfig ..: Means that the version of DCMTK does NOT export a DCMTKConfig.cmake file.
+#
+#   [X] DCMTKConfig ..: Means that the version of DCMTK exports a DCMTKConfig.cmake file.
+#
+#
+# Troubleshooting
+# ^^^^^^^^^^^^^^^
+#
+# What to do if my project finds a different version of DCMTK?
+#
+# Remove DCMTK entry from the CMake cache per :command:`find_package`
+# documentation.
 
 #=============================================================================
 # Copyright 2004-2009 Kitware, Inc.
@@ -35,50 +96,142 @@
 # Modified for EasyViz by Thomas Sondergaard.
 #
 
-if(NOT DCMTK_FOUND AND NOT DCMTK_DIR)
-  set(DCMTK_DIR
-    "/usr/include/dcmtk/"
-    CACHE
-    PATH
-    "Root of DCMTK source tree (optional).")
-  mark_as_advanced(DCMTK_DIR)
+set(_dcmtk_dir_description "The directory of DCMTK build or install tree.")
+
+# Ensure that DCMTK_DIR is set to a reasonable default value
+# so that DCMTK libraries can be found on a standard Unix distribution.
+# It also overwrite the value of DCMTK_DIR after this one has been
+# set by a successful discovery of DCMTK by the unpatched FindDCMTK.cmake module
+# distributed with CMake (as of 0167cea)
+if(NOT DCMTK_DIR OR DCMTK_DIR STREQUAL "/usr/include/dcmtk")
+  set(DCMTK_DIR "/usr" CACHE PATH ${_dcmtk_dir_description} FORCE)
+endif()
+
+set(_SAVED_DCMTK_DIR ${DCMTK_DIR})
+
+#
+# Step1: Attempt to find a version of DCMTK providing a DCMTKConfig.cmake file.
+#
+if(NOT DCMTK_FIND_QUIETLY)
+  message(STATUS "Trying to find DCMTK expecting DCMTKConfig.cmake")
 endif()
+find_package(DCMTK QUIET NO_MODULE)
+if(DCMTK_FOUND
+    AND NOT "x" STREQUAL "x${DCMTK_LIBRARIES}"
+    AND NOT "x" STREQUAL "x${DCMTK_INCLUDE_DIRS}")
 
+  if(NOT DCMTK_FIND_QUIETLY)
+    message(STATUS "Trying to find DCMTK expecting DCMTKConfig.cmake - ok")
+  endif()
+  return()
+else()
+  if(NOT DCMTK_FIND_QUIETLY)
+    message(STATUS "Trying to find DCMTK expecting DCMTKConfig.cmake - failed")
+  endif()
+endif()
+
+if(NOT DCMTK_FIND_QUIETLY)
+  message(STATUS "Trying to find DCMTK relying on FindDCMTK.cmake")
+endif()
 
+# Restore the value reset by the previous call to 'find_package(DCMTK QUIET NO_MODULE)'
+set(DCMTK_DIR ${_SAVED_DCMTK_DIR} CACHE PATH ${_dcmtk_dir_description} FORCE)
+
+
+#
+# Step2: Attempt to find a version of DCMTK that does NOT provide a DCMTKConfig.cmake file.
+#
+
+# prefer DCMTK_DIR over default system paths like /usr/lib
+if(DCMTK_DIR)
+  set(CMAKE_PREFIX_PATH ${DCMTK_DIR}/lib ${CMAKE_PREFIX_PATH}) # this is given to FIND_LIBRARY or FIND_PATH
+endif()
+
+# Find all libraries, store debug and release separately
 foreach(lib
-    dcmdata
-    dcmimage
-    dcmimgle
-    dcmjpeg
-    dcmnet
     dcmpstat
-    dcmqrdb
-    dcmsign
     dcmsr
+    dcmsign
     dcmtls
+    dcmqrdb
+    dcmnet
+    dcmjpeg
+    dcmimage
+    dcmimgle
+    dcmdata
+    oflog
+    ofstd
     ijg12
     ijg16
     ijg8
-    ofstd)
+    )
 
-  find_library(DCMTK_${lib}_LIBRARY
+  # Find Release libraries
+  find_library(DCMTK_${lib}_LIBRARY_RELEASE
     ${lib}
     PATHS
     ${DCMTK_DIR}/${lib}/libsrc
     ${DCMTK_DIR}/${lib}/libsrc/Release
-    ${DCMTK_DIR}/${lib}/libsrc/Debug
     ${DCMTK_DIR}/${lib}/Release
+    ${DCMTK_DIR}/lib
+    ${DCMTK_DIR}/lib/Release
+    ${DCMTK_DIR}/dcmjpeg/lib${lib}/Release
+    NO_DEFAULT_PATH
+    )
+
+  # Find Debug libraries
+  find_library(DCMTK_${lib}_LIBRARY_DEBUG
+    ${lib}${DCMTK_CMAKE_DEBUG_POSTFIX}
+    PATHS
+    ${DCMTK_DIR}/${lib}/libsrc
+    ${DCMTK_DIR}/${lib}/libsrc/Debug
     ${DCMTK_DIR}/${lib}/Debug
-    ${DCMTK_DIR}/lib)
+    ${DCMTK_DIR}/lib
+    ${DCMTK_DIR}/lib/Debug
+    ${DCMTK_DIR}/dcmjpeg/lib${lib}/Debug
+    NO_DEFAULT_PATH
+    )
 
-  mark_as_advanced(DCMTK_${lib}_LIBRARY)
+  mark_as_advanced(DCMTK_${lib}_LIBRARY_RELEASE)
+  mark_as_advanced(DCMTK_${lib}_LIBRARY_DEBUG)
+
+  # Add libraries to variable according to build type
+  if(DCMTK_${lib}_LIBRARY_RELEASE)
+    list(APPEND DCMTK_LIBRARIES optimized ${DCMTK_${lib}_LIBRARY_RELEASE})
+  endif()
 
-  if(DCMTK_${lib}_LIBRARY)
-    list(APPEND DCMTK_LIBRARIES ${DCMTK_${lib}_LIBRARY})
+  if(DCMTK_${lib}_LIBRARY_DEBUG)
+    list(APPEND DCMTK_LIBRARIES debug ${DCMTK_${lib}_LIBRARY_DEBUG})
   endif()
 
 endforeach()
 
+set(CMAKE_THREAD_LIBS_INIT)
+if(DCMTK_oflog_LIBRARY_RELEASE OR DCMTK_oflog_LIBRARY_DEBUG)
+  # Hack - Not having a DCMTKConfig.cmake file to read the settings from, we will attempt to
+  # find the library in all cases.
+  # Ideally, pthread library should be discovered only if DCMTK_WITH_THREADS is enabled.
+  set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
+  find_package(Threads)
+endif()
+
+if(CMAKE_THREAD_LIBS_INIT)
+  list(APPEND DCMTK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
+endif()
+
+#
+# SPECIFIC CASE FOR DCMTK BUILD DIR as DCMTK_DIR
+# (as opposed to a DCMTK install dir)
+# Have to find the source directory.
+if(EXISTS ${DCMTK_DIR}/CMakeCache.txt)
+          load_cache(${DCMTK_DIR} READ_WITH_PREFIX "EXT"
+          DCMTK_SOURCE_DIR)
+  if(NOT EXISTS ${EXTDCMTK_SOURCE_DIR})
+    message(FATAL_ERROR
+      "DCMTK build directory references
+nonexistant DCMTK source directory ${EXTDCMTK_SOURCE_DIR}")
+  endif()
+endif()
 
 set(DCMTK_config_TEST_HEADER osconfig.h)
 set(DCMTK_dcmdata_TEST_HEADER dctypes.h)
@@ -92,6 +245,10 @@ set(DCMTK_dcmsign_TEST_HEADER sicert.h)
 set(DCMTK_dcmsr_TEST_HEADER dsrtree.h)
 set(DCMTK_dcmtls_TEST_HEADER tlslayer.h)
 set(DCMTK_ofstd_TEST_HEADER ofstdinc.h)
+set(DCMTK_oflog_TEST_HEADER oflog.h)
+set(DCMTK_dcmjpls_TEST_HEADER djlsutil.h)
+
+set(DCMTK_INCLUDE_DIR_NAMES)
 
 foreach(dir
     config
@@ -99,31 +256,47 @@ foreach(dir
     dcmimage
     dcmimgle
     dcmjpeg
+    dcmjpls
     dcmnet
     dcmpstat
     dcmqrdb
     dcmsign
     dcmsr
     dcmtls
-    ofstd)
+    ofstd
+    oflog)
+  if(EXTDCMTK_SOURCE_DIR)
+    set(SOURCE_DIR_PATH
+      ${EXTDCMTK_SOURCE_DIR}/${dir}/include/dcmtk/${dir})
+  endif()
   find_path(DCMTK_${dir}_INCLUDE_DIR
     ${DCMTK_${dir}_TEST_HEADER}
     PATHS
     ${DCMTK_DIR}/${dir}/include
     ${DCMTK_DIR}/${dir}
-    ${DCMTK_DIR}/include/${dir}
     ${DCMTK_DIR}/include/dcmtk/${dir}
     ${DCMTK_DIR}/${dir}/include/dcmtk/${dir}
+    ${DCMTK_DIR}/include/${dir}
+    ${SOURCE_DIR_PATH}
     )
   mark_as_advanced(DCMTK_${dir}_INCLUDE_DIR)
+  list(APPEND DCMTK_INCLUDE_DIR_NAMES DCMTK_${dir}_INCLUDE_DIR)
 
   if(DCMTK_${dir}_INCLUDE_DIR)
+    # add the 'include' path so eg
+    #include "dcmtk/dcmimgle/dcmimage.h"
+    # works
+    get_filename_component(_include ${DCMTK_${dir}_INCLUDE_DIR} PATH)
+    get_filename_component(_include ${_include} PATH)
     list(APPEND
       DCMTK_INCLUDE_DIRS
-      ${DCMTK_${dir}_INCLUDE_DIR})
+      ${DCMTK_${dir}_INCLUDE_DIR}
+      ${_include})
   endif()
 endforeach()
 
+list(APPEND DCMTK_INCLUDE_DIRS ${DCMTK_DIR}/include)
+
 if(WIN32)
   list(APPEND DCMTK_LIBRARIES netapi32 wsock32)
 endif()
@@ -137,21 +310,31 @@ if(DCMTK_ofstd_INCLUDE_DIR)
   mark_as_advanced(DCMTK_dcmtk_INCLUDE_DIR)
 endif()
 
-include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
-find_package_handle_standard_args(DCMTK DEFAULT_MSG
-  DCMTK_config_INCLUDE_DIR
-  DCMTK_ofstd_INCLUDE_DIR
-  DCMTK_ofstd_LIBRARY
-  DCMTK_dcmdata_INCLUDE_DIR
-  DCMTK_dcmdata_LIBRARY
-  DCMTK_dcmimgle_INCLUDE_DIR
-  DCMTK_dcmimgle_LIBRARY)
-
 # Compatibility: This variable is deprecated
 set(DCMTK_INCLUDE_DIR ${DCMTK_INCLUDE_DIRS})
 
-foreach(executable dcmdump dcmdjpeg dcmdrle)
-  string(TOUPPER ${executable} EXECUTABLE)
-  find_program(DCMTK_${EXECUTABLE}_EXECUTABLE ${executable} ${DCMTK_DIR}/bin)
-  mark_as_advanced(DCMTK_${EXECUTABLE}_EXECUTABLE)
-endforeach()
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(DCMTK
+  REQUIRED_VARS ${DCMTK_INCLUDE_DIR_NAMES} DCMTK_LIBRARIES
+  FAIL_MESSAGE "Please set DCMTK_DIR and re-run configure")
+
+# Workaround bug in packaging of DCMTK 3.6.0 on Debian.
+# See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=637687
+if(DCMTK_FOUND AND UNIX AND NOT APPLE)
+  include(CheckCXXSourceCompiles)
+  set(CMAKE_REQUIRED_FLAGS )
+  set(CMAKE_REQUIRED_DEFINITIONS )
+  set(CMAKE_REQUIRED_INCLUDES ${DCMTK_INCLUDE_DIRS})
+  set(CMAKE_REQUIRED_LIBRARIES ${DCMTK_LIBRARIES})
+  set(CMAKE_REQUIRED_QUIET ${DCMTK_FIND_QUIETLY})
+  check_cxx_source_compiles("#include <dcmtk/config/osconfig.h>\n#include <dcmtk/ofstd/ofstream.h>\nint main(int,char*[]){return 0;}"
+    DCMTK_HAVE_CONFIG_H_OPTIONAL
+    )
+  if(NOT DCMTK_HAVE_CONFIG_H_OPTIONAL)
+    set(DCMTK_DEFINITIONS "HAVE_CONFIG_H")
+  endif()
+endif()
+
+if(NOT DCMTK_FIND_QUIETLY)
+  message(STATUS "Trying to find DCMTK relying on FindDCMTK.cmake - ok")
+endif()
diff --git a/Modules/FindFLEX.cmake b/Modules/FindFLEX.cmake
index c837c52..ca66493 100644
--- a/Modules/FindFLEX.cmake
+++ b/Modules/FindFLEX.cmake
@@ -27,13 +27,17 @@
 #
 # ::
 #
-#   FLEX_TARGET(Name FlexInput FlexOutput [COMPILE_FLAGS <string>])
+#   FLEX_TARGET(Name FlexInput FlexOutput
+#               [COMPILE_FLAGS <string>]
+#               [DEFINES_FILE <string>]
+#               )
 #
 # which creates a custom command to generate the <FlexOutput> file from
 # the <FlexInput> file.  If COMPILE_FLAGS option is specified, the next
-# parameter is added to the flex command line.  Name is an alias used to
-# get details of this custom command.  Indeed the macro defines the
-# following variables:
+# parameter is added to the flex command line. If flex is configured to
+# output a header file, the DEFINES_FILE option may be used to specify its
+# name. Name is an alias used to get details of this custom command.
+# Indeed the macro defines the following variables:
 #
 # ::
 #
@@ -41,6 +45,7 @@
 #   FLEX_${Name}_OUTPUTS - the source file generated by the custom rule, an
 #   alias for FlexOutput
 #   FLEX_${Name}_INPUT - the flex source file, an alias for ${FlexInput}
+#   FLEX_${Name}_OUTPUT_HEADER - the header flex output, if any.
 #
 #
 #
@@ -113,6 +118,8 @@ find_path(FLEX_INCLUDE_DIR FlexLexer.h
 
 mark_as_advanced(FL_LIBRARY FLEX_INCLUDE_DIR)
 
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
+
 set(FLEX_INCLUDE_DIRS ${FLEX_INCLUDE_DIR})
 set(FLEX_LIBRARIES ${FL_LIBRARY})
 
@@ -145,31 +152,55 @@ if(FLEX_EXECUTABLE)
   #============================================================
   #
   macro(FLEX_TARGET Name Input Output)
-    set(FLEX_TARGET_usage "FLEX_TARGET(<Name> <Input> <Output> [COMPILE_FLAGS <string>]")
-    if(${ARGC} GREATER 3)
-      if(${ARGC} EQUAL 5)
-        if("${ARGV3}" STREQUAL "COMPILE_FLAGS")
-          set(FLEX_EXECUTABLE_opts  "${ARGV4}")
-          separate_arguments(FLEX_EXECUTABLE_opts)
-        else()
-          message(SEND_ERROR ${FLEX_TARGET_usage})
-        endif()
+    set(FLEX_TARGET_outputs "${Output}")
+    set(FLEX_EXECUTABLE_opts "")
+
+    set(FLEX_TARGET_PARAM_OPTIONS)
+    set(FLEX_TARGET_PARAM_ONE_VALUE_KEYWORDS
+      COMPILE_FLAGS
+      DEFINES_FILE
+      )
+    set(FLEX_TARGET_PARAM_MULTI_VALUE_KEYWORDS)
+
+    cmake_parse_arguments(
+      FLEX_TARGET_ARG
+      "${FLEX_TARGET_PARAM_OPTIONS}"
+      "${FLEX_TARGET_PARAM_ONE_VALUE_KEYWORDS}"
+      "${FLEX_TARGET_MULTI_VALUE_KEYWORDS}"
+      ${ARGN}
+      )
+
+    set(FLEX_TARGET_usage "FLEX_TARGET(<Name> <Input> <Output> [COMPILE_FLAGS <string>] [DEFINES_FILE <string>]")
+
+    if(NOT "${FLEX_TARGET_ARG_UNPARSED_ARGUMENTS}" STREQUAL "")
+      message(SEND_ERROR ${FLEX_TARGET_usage})
+    else()
+      if(NOT "${FLEX_TARGET_ARG_COMPILE_FLAGS}" STREQUAL "")
+        set(FLEX_EXECUTABLE_opts "${FLEX_TARGET_ARG_COMPILE_FLAGS}")
+        separate_arguments(FLEX_EXECUTABLE_opts)
+      endif()
+      if(NOT "${FLEX_TARGET_ARG_DEFINES_FILE}" STREQUAL "")
+        list(APPEND FLEX_TARGET_outputs "${FLEX_TARGET_ARG_DEFINES_FILE}")
+        list(APPEND FLEX_EXECUTABLE_opts --header-file=${FLEX_TARGET_ARG_DEFINES_FILE})
+      endif()
+
+      add_custom_command(OUTPUT ${FLEX_TARGET_outputs}
+        COMMAND ${FLEX_EXECUTABLE}
+        ARGS ${FLEX_EXECUTABLE_opts} -o${Output} ${Input}
+        DEPENDS ${Input}
+        COMMENT "[FLEX][${Name}] Building scanner with flex ${FLEX_VERSION}"
+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+
+      set(FLEX_${Name}_DEFINED TRUE)
+      set(FLEX_${Name}_OUTPUTS ${Output})
+      set(FLEX_${Name}_INPUT ${Input})
+      set(FLEX_${Name}_COMPILE_FLAGS ${FLEX_EXECUTABLE_opts})
+      if("${FLEX_TARGET_ARG_DEFINES_FILE}" STREQUAL "")
+        set(FLEX_${Name}_OUTPUT_HEADER "")
       else()
-        message(SEND_ERROR ${FLEX_TARGET_usage})
+        set(FLEX_${Name}_OUTPUT_HEADER ${FLEX_TARGET_ARG_DEFINES_FILE})
       endif()
     endif()
-
-    add_custom_command(OUTPUT ${Output}
-      COMMAND ${FLEX_EXECUTABLE}
-      ARGS ${FLEX_EXECUTABLE_opts} -o${Output} ${Input}
-      DEPENDS ${Input}
-      COMMENT "[FLEX][${Name}] Building scanner with flex ${FLEX_VERSION}"
-      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
-
-    set(FLEX_${Name}_DEFINED TRUE)
-    set(FLEX_${Name}_OUTPUTS ${Output})
-    set(FLEX_${Name}_INPUT ${Input})
-    set(FLEX_${Name}_COMPILE_FLAGS ${FLEX_EXECUTABLE_opts})
   endmacro()
   #============================================================
 
@@ -181,11 +212,11 @@ if(FLEX_EXECUTABLE)
   macro(ADD_FLEX_BISON_DEPENDENCY FlexTarget BisonTarget)
 
     if(NOT FLEX_${FlexTarget}_OUTPUTS)
-      message(SEND_ERROR "Flex target `${FlexTarget}' does not exists.")
+      message(SEND_ERROR "Flex target `${FlexTarget}' does not exist.")
     endif()
 
     if(NOT BISON_${BisonTarget}_OUTPUT_HEADER)
-      message(SEND_ERROR "Bison target `${BisonTarget}' does not exists.")
+      message(SEND_ERROR "Bison target `${BisonTarget}' does not exist.")
     endif()
 
     set_source_files_properties(${FLEX_${FlexTarget}_OUTPUTS}
diff --git a/Modules/FindGTK2.cmake b/Modules/FindGTK2.cmake
index 72bb8eb..6e4a7f2 100644
--- a/Modules/FindGTK2.cmake
+++ b/Modules/FindGTK2.cmake
@@ -34,6 +34,7 @@
 #    GTK2_FOUND - Were all of your specified components found?
 #    GTK2_INCLUDE_DIRS - All include directories
 #    GTK2_LIBRARIES - All libraries
+#    GTK2_TARGETS - All imported targets
 #    GTK2_DEFINITIONS - Additional compiler flags
 #
 #
@@ -202,6 +203,43 @@ function(_GTK2_GET_VERSION _OUT_major _OUT_minor _OUT_micro _gtkversion_hdr)
     endif()
 endfunction()
 
+
+#=============================================================
+# _GTK2_SIGCXX_GET_VERSION
+# Internal function to parse the version number in
+# sigc++config.h
+#   _OUT_major = Major version number
+#   _OUT_minor = Minor version number
+#   _OUT_micro = Micro version number
+#   _sigcxxversion_hdr = Header file to parse
+#=============================================================
+
+function(_GTK2_SIGCXX_GET_VERSION _OUT_major _OUT_minor _OUT_micro _sigcxxversion_hdr)
+    file(STRINGS ${_sigcxxversion_hdr} _contents REGEX "#define SIGCXX_M[A-Z]+_VERSION[ \t]+")
+    if(_contents)
+        string(REGEX REPLACE ".*#define SIGCXX_MAJOR_VERSION[ \t]+([0-9]+).*" "\\1" ${_OUT_major} "${_contents}")
+        string(REGEX REPLACE ".*#define SIGCXX_MINOR_VERSION[ \t]+([0-9]+).*" "\\1" ${_OUT_minor} "${_contents}")
+        string(REGEX REPLACE ".*#define SIGCXX_MICRO_VERSION[ \t]+([0-9]+).*" "\\1" ${_OUT_micro} "${_contents}")
+
+        if(NOT ${_OUT_major} MATCHES "[0-9]+")
+            message(FATAL_ERROR "Version parsing failed for SIGCXX_MAJOR_VERSION!")
+        endif()
+        if(NOT ${_OUT_minor} MATCHES "[0-9]+")
+            message(FATAL_ERROR "Version parsing failed for SIGCXX_MINOR_VERSION!")
+        endif()
+        if(NOT ${_OUT_micro} MATCHES "[0-9]+")
+            message(FATAL_ERROR "Version parsing failed for SIGCXX_MICRO_VERSION!")
+        endif()
+
+        set(${_OUT_major} ${${_OUT_major}} PARENT_SCOPE)
+        set(${_OUT_minor} ${${_OUT_minor}} PARENT_SCOPE)
+        set(${_OUT_micro} ${${_OUT_micro}} PARENT_SCOPE)
+    else()
+        message(FATAL_ERROR "Include file ${_gtkversion_hdr} does not exist")
+    endif()
+endfunction()
+
+
 #=============================================================
 # _GTK2_FIND_INCLUDE_DIR
 # Internal function to find the GTK include directories
@@ -513,6 +551,9 @@ function(_GTK2_ADD_TARGET _var)
 
         add_library(GTK2::${_basename} UNKNOWN IMPORTED)
 
+        set(GTK2_TARGETS ${GTK2_TARGETS} GTK2::${_basename})
+        set(GTK2_TARGETS ${GTK2_TARGETS} PARENT_SCOPE)
+
         if(GTK2_${_var}_LIBRARY_RELEASE)
             set_property(TARGET GTK2::${_basename} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
             set_property(TARGET GTK2::${_basename}        PROPERTY IMPORTED_LOCATION_RELEASE "${GTK2_${_var}_LIBRARY_RELEASE}" )
@@ -565,6 +606,7 @@ endfunction()
 set(GTK2_FOUND)
 set(GTK2_INCLUDE_DIRS)
 set(GTK2_LIBRARIES)
+set(GTK2_TARGETS)
 set(GTK2_DEFINITIONS)
 
 if(NOT GTK2_FIND_COMPONENTS)
@@ -734,6 +776,27 @@ foreach(_GTK2_component ${GTK2_FIND_COMPONENTS})
         _GTK2_FIND_INCLUDE_DIR(SIGC++CONFIG sigc++config.h)
         _GTK2_FIND_LIBRARY    (SIGC++ sigc true true)
         _GTK2_ADD_TARGET      (SIGC++)
+        # Since sigc++ 2.5.1 c++11 support is required
+        if(GTK2_SIGC++CONFIG_INCLUDE_DIR)
+            _GTK2_SIGCXX_GET_VERSION(GTK2_SIGC++_VERSION_MAJOR
+                                     GTK2_SIGC++_VERSION_MINOR
+                                     GTK2_SIGC++_VERSION_MICRO
+                                     ${GTK2_SIGC++CONFIG_INCLUDE_DIR}/sigc++config.h)
+            if(NOT ${GTK2_SIGC++_VERSION_MAJOR}.${GTK2_SIGC++_VERSION_MINOR}.${GTK2_SIGC++_VERSION_MICRO} VERSION_LESS 2.5.1)
+                # These are the features needed by clients in order to include the
+                # project headers:
+                set_property(TARGET GTK2::sigc++
+                             PROPERTY INTERFACE_COMPILE_FEATURES cxx_alias_templates
+                                                                 cxx_auto_type
+                                                                 cxx_decltype
+                                                                 cxx_deleted_functions
+                                                                 cxx_noexcept
+                                                                 cxx_nullptr
+                                                                 cxx_right_angle_brackets
+                                                                 cxx_rvalue_references
+                                                                 cxx_variadic_templates)
+            endif()
+        endif()
 
         _GTK2_FIND_INCLUDE_DIR(GLIBMM glibmm.h)
         _GTK2_FIND_INCLUDE_DIR(GLIBMMCONFIG glibmmconfig.h)
@@ -882,6 +945,11 @@ foreach(_GTK2_component ${GTK2_FIND_COMPONENTS})
     endif()
 endforeach()
 
+if(GTK2_USE_IMPORTED_TARGETS)
+    set(GTK2_LIBRARIES ${GTK2_TARGETS})
+endif()
+
+
 if(_GTK2_did_we_find_everything AND NOT GTK2_VERSION_CHECK_FAILED)
     set(GTK2_FOUND true)
 else()
@@ -893,6 +961,7 @@ else()
     set(GTK2_VERSION_PATCH)
     set(GTK2_INCLUDE_DIRS)
     set(GTK2_LIBRARIES)
+    set(GTK2_TARGETS)
     set(GTK2_DEFINITIONS)
 endif()
 
diff --git a/Modules/FindGTest.cmake b/Modules/FindGTest.cmake
index eb7abfd..ca49e4a 100644
--- a/Modules/FindGTest.cmake
+++ b/Modules/FindGTest.cmake
@@ -4,88 +4,89 @@
 #
 # Locate the Google C++ Testing Framework.
 #
-# Defines the following variables:
+# Imported targets
+# ^^^^^^^^^^^^^^^^
 #
-# ::
-#
-#    GTEST_FOUND - Found the Google Testing framework
-#    GTEST_INCLUDE_DIRS - Include directories
+# This module defines the following :prop_tgt:`IMPORTED` targets:
 #
+# ``GTest::GTest``
+#   The Google Test ``gtest`` library, if found; adds Thread::Thread
+#   automatically
+# ``GTest::Main``
+#   The Google Test ``gtest_main`` library, if found
 #
 #
-# Also defines the library variables below as normal variables.  These
-# contain debug/optimized keywords when a debugging library is found.
-#
-# ::
+# Result variables
+# ^^^^^^^^^^^^^^^^
 #
-#    GTEST_BOTH_LIBRARIES - Both libgtest & libgtest-main
-#    GTEST_LIBRARIES - libgtest
-#    GTEST_MAIN_LIBRARIES - libgtest-main
+# This module will set the following variables in your project:
 #
+# ``GTEST_FOUND``
+#   Found the Google Testing framework
+# ``GTEST_INCLUDE_DIRS``
+#   the directory containing the Google Test headers
 #
+# The library variables below are set as normal variables.  These
+# contain debug/optimized keywords when a debugging library is found.
 #
-# Accepts the following variables as input:
-#
-# ::
-#
-#    GTEST_ROOT - (as a CMake or environment variable)
-#                 The root directory of the gtest install prefix
-#
-#
+# ``GTEST_LIBRARIES``
+#   The Google Test ``gtest`` library; note it also requires linking
+#   with an appropriate thread library
+# ``GTEST_MAIN_LIBRARIES``
+#   The Google Test ``gtest_main`` library
+# ``GTEST_BOTH_LIBRARIES``
+#   Both ``gtest`` and ``gtest_main``
 #
-# ::
+# Cache variables
+# ^^^^^^^^^^^^^^^
 #
-#    GTEST_MSVC_SEARCH - If compiling with MSVC, this variable can be set to
-#                        "MD" or "MT" to enable searching a GTest build tree
-#                        (defaults: "MD")
+# The following cache variables may also be set:
 #
+# ``GTEST_ROOT``
+#   The root directory of the Google Test installation (may also be
+#   set as an environment variable)
+# ``GTEST_MSVC_SEARCH``
+#   If compiling with MSVC, this variable can be set to ``MD`` or
+#   ``MT`` (the default) to enable searching a GTest build tree
 #
 #
-# Example Usage:
+# Example usage
+# ^^^^^^^^^^^^^
 #
 # ::
 #
 #     enable_testing()
 #     find_package(GTest REQUIRED)
-#     include_directories(${GTEST_INCLUDE_DIRS})
-#
-#
-#
-# ::
 #
 #     add_executable(foo foo.cc)
-#     target_link_libraries(foo ${GTEST_BOTH_LIBRARIES})
-#
-#
-#
-# ::
+#     target_link_libraries(foo GTest::GTest GTest::Main)
 #
 #     add_test(AllTestsInFoo foo)
 #
 #
-#
-#
+# Deeper integration with CTest
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 #
 # If you would like each Google test to show up in CTest as a test you
-# may use the following macro.  NOTE: It will slow down your tests by
-# running an executable for each test and test fixture.  You will also
-# have to rerun CMake after adding or removing tests or test fixtures.
-#
-# GTEST_ADD_TESTS(executable extra_args ARGN)
-#
-# ::
+# may use the following macro::
 #
-#     executable = The path to the test executable
-#     extra_args = Pass a list of extra arguments to be passed to
-#                  executable enclosed in quotes (or "" for none)
-#     ARGN =       A list of source files to search for tests & test
-#                  fixtures. Or AUTO to find them from executable target.
+#     GTEST_ADD_TESTS(executable extra_args files...)
 #
+# ``executable``
+#   the path to the test executable
+# ``extra_args``
+#   a list of extra arguments to be passed to executable enclosed in
+#   quotes (or ``""`` for none)
+# ``files...``
+#   a list of source files to search for tests and test fixtures.  Or
+#   ``AUTO`` to find them from executable target
 #
+# However, note that this macro will slow down your tests by running
+# an executable for each test and test fixture.  You will also have to
+# re-run CMake after adding or removing tests or test fixtures.
 #
-# ::
+# Example usage::
 #
-#   Example:
 #      set(FooTestArgs --foo 1 --bar 2)
 #      add_executable(FooTest FooUnitTest.cc)
 #      GTEST_ADD_TESTS(FooTest "${FooTestArgs}" AUTO)
@@ -208,5 +209,60 @@ if(GTEST_FOUND)
     _gtest_append_debugs(GTEST_LIBRARIES      GTEST_LIBRARY)
     _gtest_append_debugs(GTEST_MAIN_LIBRARIES GTEST_MAIN_LIBRARY)
     set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
-endif()
 
+    include(CMakeFindDependencyMacro)
+    find_dependency(Threads)
+
+    if(NOT TARGET GTest::GTest)
+        add_library(GTest::GTest UNKNOWN IMPORTED)
+        set_target_properties(GTest::GTest PROPERTIES
+            INTERFACE_LINK_LIBRARIES "Threads::Threads")
+        if(GTEST_INCLUDE_DIRS)
+            set_target_properties(GTest::GTest PROPERTIES
+                INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIRS}")
+        endif()
+        if(EXISTS "${GTEST_LIBRARY}")
+            set_target_properties(GTest::GTest PROPERTIES
+                IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
+                IMPORTED_LOCATION "${GTEST_LIBRARY}")
+        endif()
+        if(EXISTS "${GTEST_LIBRARY_DEBUG}")
+            set_property(TARGET GTest::GTest APPEND PROPERTY
+                IMPORTED_CONFIGURATIONS DEBUG)
+            set_target_properties(GTest::GTest PROPERTIES
+                IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
+                IMPORTED_LOCATION_DEBUG "${GTEST_LIBRARY_DEBUG}")
+        endif()
+        if(EXISTS "${GTEST_LIBRARY_RELEASE}")
+            set_property(TARGET GTest::GTest APPEND PROPERTY
+                IMPORTED_CONFIGURATIONS RELEASE)
+            set_target_properties(GTest::GTest PROPERTIES
+                IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
+                IMPORTED_LOCATION_RELEASE "${GTEST_LIBRARY_RELEASE}")
+        endif()
+      endif()
+      if(NOT TARGET GTest::Main)
+          add_library(GTest::Main UNKNOWN IMPORTED)
+          set_target_properties(GTest::Main PROPERTIES
+              INTERFACE_LINK_LIBRARIES "GTest::GTest")
+          if(EXISTS "${GTEST_MAIN_LIBRARY}")
+              set_target_properties(GTest::Main PROPERTIES
+                  IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
+                  IMPORTED_LOCATION "${GTEST_MAIN_LIBRARY}")
+          endif()
+          if(EXISTS "${GTEST_MAIN_LIBRARY_DEBUG}")
+            set_property(TARGET GTest::Main APPEND PROPERTY
+                IMPORTED_CONFIGURATIONS DEBUG)
+            set_target_properties(GTest::Main PROPERTIES
+                IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
+                IMPORTED_LOCATION_DEBUG "${GTEST_MAIN_LIBRARY_DEBUG}")
+          endif()
+          if(EXISTS "${GTEST_MAIN_LIBRARY_RELEASE}")
+            set_property(TARGET GTest::Main APPEND PROPERTY
+                IMPORTED_CONFIGURATIONS RELEASE)
+            set_target_properties(GTest::Main PROPERTIES
+                IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
+                IMPORTED_LOCATION_RELEASE "${GTEST_MAIN_LIBRARY_RELEASE}")
+          endif()
+    endif()
+endif()
diff --git a/Modules/FindGit.cmake b/Modules/FindGit.cmake
index b4f7b4b..d18f965 100644
--- a/Modules/FindGit.cmake
+++ b/Modules/FindGit.cmake
@@ -2,27 +2,26 @@
 # FindGit
 # -------
 #
-#
-#
 # The module defines the following variables:
 #
-# ::
-#
-#    GIT_EXECUTABLE - path to git command line client
-#    GIT_FOUND - true if the command line client was found
-#    GIT_VERSION_STRING - the version of git found (since CMake 2.8.8)
+# ``GIT_EXECUTABLE``
+#   Path to Git command-line client.
+# ``Git_FOUND``, ``GIT_FOUND``
+#   True if the Git command-line client was found.
+# ``GIT_VERSION_STRING``
+#   The version of Git found.
 #
 # Example usage:
 #
-# ::
+# .. code-block:: cmake
 #
 #    find_package(Git)
-#    if(GIT_FOUND)
-#      message("git found: ${GIT_EXECUTABLE}")
+#    if(Git_FOUND)
+#      message("Git found: ${GIT_EXECUTABLE}")
 #    endif()
 
 #=============================================================================
-# Copyright 2010 Kitware, Inc.
+# Copyright 2010-2016 Kitware, Inc.
 # Copyright 2012 Rolf Eike Beer <eike at sf-mail.de>
 #
 # Distributed under the OSI-approved BSD License (the "License");
@@ -48,17 +47,22 @@ if(WIN32)
     # GitHub search path for Windows
     set(github_path "$ENV{LOCALAPPDATA}/Github/PortableGit*/bin")
     file(GLOB github_path "${github_path}")
+    # SourceTree search path for Windows
+    set(_git_sourcetree_path "$ENV{LOCALAPPDATA}/Atlassian/SourceTree/git_local/bin")
   endif()
 endif()
 
 find_program(GIT_EXECUTABLE
   NAMES ${git_names}
-  PATHS ${github_path}
+  PATHS ${github_path} ${_git_sourcetree_path}
   PATH_SUFFIXES Git/cmd Git/bin
-  DOC "git command line client"
+  DOC "Git command line client"
   )
 mark_as_advanced(GIT_EXECUTABLE)
 
+unset(git_names)
+unset(_git_sourcetree_path)
+
 if(GIT_EXECUTABLE)
   execute_process(COMMAND ${GIT_EXECUTABLE} --version
                   OUTPUT_VARIABLE git_version
@@ -70,7 +74,7 @@ if(GIT_EXECUTABLE)
   unset(git_version)
 endif()
 
-# Handle the QUIETLY and REQUIRED arguments and set GIT_FOUND to TRUE if
+# Handle the QUIETLY and REQUIRED arguments and set Git_FOUND to TRUE if
 # all listed variables are TRUE
 
 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
diff --git a/Modules/FindJNI.cmake b/Modules/FindJNI.cmake
index cbe21d7..135038c 100644
--- a/Modules/FindJNI.cmake
+++ b/Modules/FindJNI.cmake
@@ -63,7 +63,7 @@ macro(java_append_library_directories _var)
     elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
         set(_java_libarch "ppc64" "ppc")
     elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)")
-        set(_java_libarch "ppc")
+        set(_java_libarch "ppc" "ppc64")
     elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
         # Both flavours can run on the same processor
         set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "sparc" "sparcv9")
@@ -271,7 +271,8 @@ find_path(JAVA_INCLUDE_PATH jni.h
   ${JAVA_AWT_INCLUDE_DIRECTORIES}
 )
 
-find_path(JAVA_INCLUDE_PATH2 jni_md.h
+find_path(JAVA_INCLUDE_PATH2 NAMES jni_md.h jniport.h
+  PATHS
   ${JAVA_INCLUDE_PATH}
   ${JAVA_INCLUDE_PATH}/darwin
   ${JAVA_INCLUDE_PATH}/win32
@@ -281,6 +282,7 @@ find_path(JAVA_INCLUDE_PATH2 jni_md.h
   ${JAVA_INCLUDE_PATH}/solaris
   ${JAVA_INCLUDE_PATH}/hp-ux
   ${JAVA_INCLUDE_PATH}/alpha
+  ${JAVA_INCLUDE_PATH}/aix
 )
 
 find_path(JAVA_AWT_INCLUDE_PATH jawt.h
diff --git a/Modules/FindJava.cmake b/Modules/FindJava.cmake
index 9f87997..cc67df6 100644
--- a/Modules/FindJava.cmake
+++ b/Modules/FindJava.cmake
@@ -228,12 +228,12 @@ if(Java_FIND_COMPONENTS)
       endif()
     elseif(component STREQUAL "IdlJ")
       list(APPEND _JAVA_REQUIRED_VARS Java_IDLJ_EXECUTABLE)
-      if(Java_IdlJ_EXECUTABLE)
-        set(Java_Extra_FOUND TRUE)
+      if(Java_IDLJ_EXECUTABLE)
+        set(Java_IdlJ_FOUND TRUE)
       endif()
     elseif(component STREQUAL "JarSigner")
       list(APPEND _JAVA_REQUIRED_VARS Java_JARSIGNER_EXECUTABLE)
-      if(Java_IDLJ_EXECUTABLE)
+      if(Java_JARSIGNER_EXECUTABLE)
         set(Java_JarSigner_FOUND TRUE)
       endif()
     else()
diff --git a/Modules/FindOpenAL.cmake b/Modules/FindOpenAL.cmake
index 8150ff2..eb63cef 100644
--- a/Modules/FindOpenAL.cmake
+++ b/Modules/FindOpenAL.cmake
@@ -79,11 +79,17 @@ find_path(OPENAL_INCLUDE_DIR al.h
   [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]
 )
 
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+  set(_OpenAL_ARCH_DIR libs/Win64)
+else()
+  set(_OpenAL_ARCH_DIR libs/Win32)
+endif()
+
 find_library(OPENAL_LIBRARY
   NAMES OpenAL al openal OpenAL32
   HINTS
     ENV OPENALDIR
-  PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64
+  PATH_SUFFIXES lib64 lib libs64 libs ${_OpenAL_ARCH_DIR}
   PATHS
   ~/Library/Frameworks
   /Library/Frameworks
@@ -94,6 +100,7 @@ find_library(OPENAL_LIBRARY
   [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]
 )
 
+unset(_OpenAL_ARCH_DIR)
 
 # handle the QUIETLY and REQUIRED arguments and set OPENAL_FOUND to TRUE if
 # all listed variables are TRUE
diff --git a/Modules/FindOpenGL.cmake b/Modules/FindOpenGL.cmake
index a7eefa7..93e488b 100644
--- a/Modules/FindOpenGL.cmake
+++ b/Modules/FindOpenGL.cmake
@@ -71,9 +71,11 @@ elseif (WIN32)
 
 elseif (APPLE)
 
-  find_library(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL lib for OSX")
-  find_library(OPENGL_glu_LIBRARY AGL DOC "AGL lib for OSX")
-  find_path(OPENGL_INCLUDE_DIR OpenGL/gl.h DOC "Include for OpenGL on OSX")
+  # The OpenGL.framework provides both gl and glu
+  find_library(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL library for OS X")
+  find_library(OPENGL_glu_LIBRARY OpenGL DOC
+    "GLU library for OS X (usually same as OpenGL library)")
+  find_path(OPENGL_INCLUDE_DIR OpenGL/gl.h DOC "Include for OpenGL on OS X")
   list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
 
 else()
@@ -149,7 +151,9 @@ if(OPENGL_gl_LIBRARY)
     set( OPENGL_LIBRARIES  ${OPENGL_gl_LIBRARY} ${OPENGL_LIBRARIES})
     if(OPENGL_glu_LIBRARY)
       set( OPENGL_GLU_FOUND "YES" )
-      set( OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARIES} )
+      if(NOT "${OPENGL_glu_LIBRARY}" STREQUAL "${OPENGL_gl_LIBRARY}")
+        set( OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARIES} )
+      endif()
     else()
       set( OPENGL_GLU_FOUND "NO" )
     endif()
diff --git a/Modules/FindOpenMP.cmake b/Modules/FindOpenMP.cmake
index a102c66..ee4bdd6 100644
--- a/Modules/FindOpenMP.cmake
+++ b/Modules/FindOpenMP.cmake
@@ -50,6 +50,8 @@ function(_OPENMP_FLAG_CANDIDATES LANG)
     " "
     #GNU
     "-fopenmp"
+    #Clang
+    "-fopenmp=libomp"
     #Microsoft Visual Studio
     "/openmp"
     #Intel windows
@@ -67,6 +69,7 @@ function(_OPENMP_FLAG_CANDIDATES LANG)
   )
 
   set(OMP_FLAG_GNU "-fopenmp")
+  set(OMP_FLAG_Clang "-fopenmp=libomp")
   set(OMP_FLAG_HP "+Oopenmp")
   if(WIN32)
     set(OMP_FLAG_Intel "-Qopenmp")
diff --git a/Modules/FindOpenSSL.cmake b/Modules/FindOpenSSL.cmake
index d75e8ab..8b4b988 100644
--- a/Modules/FindOpenSSL.cmake
+++ b/Modules/FindOpenSSL.cmake
@@ -37,6 +37,7 @@
 #
 # Set ``OPENSSL_ROOT_DIR`` to the root directory of an OpenSSL installation.
 # Set ``OPENSSL_USE_STATIC_LIBS`` to ``TRUE`` to look for static libraries.
+# Set ``OPENSSL_MSVC_STATIC_RT`` set ``TRUE`` to choose the MT version of the lib.
 
 #=============================================================================
 # Copyright 2006-2009 Kitware, Inc.
@@ -113,7 +114,7 @@ if(WIN32 AND NOT CYGWIN)
     # /MD and /MDd are the standard values - if someone wants to use
     # others, the libnames have to change here too
     # use also ssl and ssleay32 in debug as fallback for openssl < 0.9.8b
-    # TODO: handle /MT and static lib
+    # enable OPENSSL_MSVC_STATIC_RT to get the libs build /MT (Multithreaded no-DLL)
     # In Visual C++ naming convention each of these four kinds of Windows libraries has it's standard suffix:
     #   * MD for dynamic-release
     #   * MDd for dynamic-debug
@@ -126,6 +127,12 @@ if(WIN32 AND NOT CYGWIN)
     # ssleay32MD.lib is identical to ../ssleay32.lib
     # enable OPENSSL_USE_STATIC_LIBS to use the static libs located in lib/VC/static
 
+    if (OPENSSL_MSVC_STATIC_RT)
+      set(_OPENSSL_MSVC_RT_MODE "MT")
+    else ()
+      set(_OPENSSL_MSVC_RT_MODE "MD")
+    endif ()
+
     if(OPENSSL_USE_STATIC_LIBS)
       set(_OPENSSL_PATH_SUFFIXES
         "lib"
@@ -142,7 +149,7 @@ if(WIN32 AND NOT CYGWIN)
 
     find_library(LIB_EAY_DEBUG
       NAMES
-        libeay32MDd
+        libeay32${_OPENSSL_MSVC_RT_MODE}d
         libeay32d
       ${_OPENSSL_ROOT_HINTS_AND_PATHS}
       PATH_SUFFIXES
@@ -151,7 +158,7 @@ if(WIN32 AND NOT CYGWIN)
 
     find_library(LIB_EAY_RELEASE
       NAMES
-        libeay32MD
+        libeay32${_OPENSSL_MSVC_RT_MODE}
         libeay32
       ${_OPENSSL_ROOT_HINTS_AND_PATHS}
       PATH_SUFFIXES
@@ -160,7 +167,7 @@ if(WIN32 AND NOT CYGWIN)
 
     find_library(SSL_EAY_DEBUG
       NAMES
-        ssleay32MDd
+        ssleay32${_OPENSSL_MSVC_RT_MODE}d
         ssleay32d
       ${_OPENSSL_ROOT_HINTS_AND_PATHS}
       PATH_SUFFIXES
@@ -169,7 +176,7 @@ if(WIN32 AND NOT CYGWIN)
 
     find_library(SSL_EAY_RELEASE
       NAMES
-        ssleay32MD
+        ssleay32${_OPENSSL_MSVC_RT_MODE}
         ssleay32
         ssl
       ${_OPENSSL_ROOT_HINTS_AND_PATHS}
@@ -193,12 +200,8 @@ if(WIN32 AND NOT CYGWIN)
     set(OPENSSL_LIBRARIES ${SSL_EAY_LIBRARY} ${LIB_EAY_LIBRARY} )
   elseif(MINGW)
     # same player, for MinGW
-    set(LIB_EAY_NAMES libeay32)
-    set(SSL_EAY_NAMES ssleay32)
-    if(CMAKE_CROSSCOMPILING)
-      list(APPEND LIB_EAY_NAMES crypto)
-      list(APPEND SSL_EAY_NAMES ssl)
-    endif()
+    set(LIB_EAY_NAMES crypto libeay32)
+    set(SSL_EAY_NAMES ssl ssleay32)
     find_library(LIB_EAY
       NAMES
         ${LIB_EAY_NAMES}
@@ -318,7 +321,7 @@ endfunction()
 if (OPENSSL_INCLUDE_DIR)
   if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h")
     file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str
-         REGEX "^# *define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*")
+         REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*")
 
     # The version number is encoded as 0xMNNFFPPS: major minor fix patch status
     # The status gives if this is a developer or prerelease and is ignored here.
diff --git a/Modules/FindPNG.cmake b/Modules/FindPNG.cmake
index 7cf3f22..cae41ac 100644
--- a/Modules/FindPNG.cmake
+++ b/Modules/FindPNG.cmake
@@ -2,13 +2,20 @@
 # FindPNG
 # -------
 #
-# Find the native PNG includes and library
+# Find libpng, the official reference library for the PNG image format.
 #
+# Imported targets
+# ^^^^^^^^^^^^^^^^
 #
+# This module defines the following :prop_tgt:`IMPORTED` target:
 #
-# This module searches libpng, the library for working with PNG images.
+# ``PNG::PNG``
+#   The libpng library, if found.
 #
-# It defines the following variables
+# Result variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module will set the following variables in your project:
 #
 # ``PNG_INCLUDE_DIRS``
 #   where to find png.h, etc.
@@ -22,19 +29,22 @@
 # ``PNG_VERSION_STRING``
 #   the version of the PNG library found (since CMake 2.8.8)
 #
-# Also defined, but not for general use are
+# Obsolete variables
+# ^^^^^^^^^^^^^^^^^^
+#
+# The following variables may also be set, for backwards compatibility:
 #
 # ``PNG_LIBRARY``
 #   where to find the PNG library.
-#
-# For backward compatiblity the variable PNG_INCLUDE_DIR is also set.
-# It has the same value as PNG_INCLUDE_DIRS.
+# ``PNG_INCLUDE_DIR``
+#   where to find the PNG headers (same as PNG_INCLUDE_DIRS)
 #
 # Since PNG depends on the ZLib compression library, none of the above
 # will be defined unless ZLib can be found.
 
 #=============================================================================
 # Copyright 2002-2009 Kitware, Inc.
+# Copyright 2016 Raumfeld
 #
 # Distributed under the OSI-approved BSD License (the "License");
 # see accompanying file Copyright.txt for details.
@@ -105,6 +115,32 @@ if(ZLIB_FOUND)
         endif()
       endif ()
 
+      if(NOT TARGET PNG::PNG)
+        add_library(PNG::PNG UNKNOWN IMPORTED)
+        set_target_properties(PNG::PNG PROPERTIES
+          INTERFACE_COMPILE_DEFINITIONS "${PNG_DEFINITIONS}"
+          INTERFACE_INCLUDE_DIRECTORIES "${PNG_INCLUDE_DIRS}"
+          INTERFACE_LINK_LIBRARIES ZLIB::ZLIB)
+        if(EXISTS "${PNG_LIBRARY}")
+          set_target_properties(PNG::PNG PROPERTIES
+            IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+            IMPORTED_LOCATION "${PNG_LIBRARY}")
+        endif()
+        if(EXISTS "${PNG_LIBRARY_DEBUG}")
+          set_property(TARGET PNG::PNG APPEND PROPERTY
+            IMPORTED_CONFIGURATIONS DEBUG)
+          set_target_properties(PNG::PNG PROPERTIES
+            IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
+            IMPORTED_LOCATION_DEBUG "${PNG_LIBRARY_DEBUG}")
+        endif()
+        if(EXISTS "${PNG_LIBRARY_RELEASE}")
+          set_property(TARGET PNG::PNG APPEND PROPERTY
+            IMPORTED_CONFIGURATIONS RELEASE)
+          set_target_properties(PNG::PNG PROPERTIES
+            IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
+            IMPORTED_LOCATION_RELEASE "${PNG_LIBRARY_RELEASE}")
+        endif()
+      endif()
   endif ()
 
   if (PNG_PNG_INCLUDE_DIR AND EXISTS "${PNG_PNG_INCLUDE_DIR}/png.h")
diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake
index e822b9c..4f50e38 100644
--- a/Modules/FindPkgConfig.cmake
+++ b/Modules/FindPkgConfig.cmake
@@ -238,8 +238,8 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma
     if(NOT "${_extra_paths}" STREQUAL "")
       # Save the PKG_CONFIG_PATH environment variable, and add paths
       # from the CMAKE_PREFIX_PATH variables
-      set(_pkgconfig_path_old $ENV{PKG_CONFIG_PATH})
-      set(_pkgconfig_path ${_pkgconfig_path_old})
+      set(_pkgconfig_path_old "$ENV{PKG_CONFIG_PATH}")
+      set(_pkgconfig_path "${_pkgconfig_path_old}")
       if(NOT "${_pkgconfig_path}" STREQUAL "")
         file(TO_CMAKE_PATH "${_pkgconfig_path}" _pkgconfig_path)
       endif()
@@ -263,6 +263,7 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma
         endif()
       endif()
       list(APPEND _lib_dirs "lib/pkgconfig")
+      list(APPEND _lib_dirs "share/pkgconfig")
 
       # Check if directories exist and eventually append them to the
       # pkgconfig path list
@@ -284,7 +285,7 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma
           string(REPLACE ";" ":" _pkgconfig_path "${_pkgconfig_path}")
           string(REPLACE "\\ " " " _pkgconfig_path "${_pkgconfig_path}")
         endif()
-        set(ENV{PKG_CONFIG_PATH} ${_pkgconfig_path})
+        set(ENV{PKG_CONFIG_PATH} "${_pkgconfig_path}")
       endif()
 
       # Unset variables
@@ -328,7 +329,7 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma
       if (_pkg_check_modules_pkg_op)
         list(APPEND _pkg_check_modules_exist_query "${_pkg_check_modules_pkg_ver}")
       else()
-        list(APPEND _pkg_check_modules_exist_query --exists)
+        list(APPEND _pkg_check_modules_exist_query --exists --print-errors --short-errors)
       endif()
 
       _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_VERSION)
@@ -342,12 +343,14 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma
       # execute the query
       execute_process(
         COMMAND ${PKG_CONFIG_EXECUTABLE} ${_pkg_check_modules_exist_query}
-        RESULT_VARIABLE _pkgconfig_retval)
+        RESULT_VARIABLE _pkgconfig_retval
+        ERROR_VARIABLE _pkgconfig_error
+        ERROR_STRIP_TRAILING_WHITESPACE)
 
       # evaluate result and tell failures
       if (_pkgconfig_retval)
         if(NOT ${_is_silent})
-          message(STATUS "  Package '${_pkg_check_modules_pkg}' not found")
+          message(STATUS "  ${_pkgconfig_error}")
         endif()
 
         set(_pkg_check_modules_failed 1)
@@ -379,6 +382,9 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma
         pkg_get_variable("${_pkg_check_prefix}_PREFIX" ${_pkg_check_modules_pkg} "prefix")
         pkg_get_variable("${_pkg_check_prefix}_INCLUDEDIR" ${_pkg_check_modules_pkg} "includedir")
         pkg_get_variable("${_pkg_check_prefix}_LIBDIR" ${_pkg_check_modules_pkg} "libdir")
+        foreach (variable IN ITEMS PREFIX INCLUDEDIR LIBDIR)
+          _pkgconfig_set("${_pkg_check_modules_pkg}_${variable}" "${${_pkg_check_modules_pkg}_${variable}}")
+        endforeach ()
 
         if (NOT ${_is_silent})
           message(STATUS "  Found ${_pkg_check_modules_pkg}, version ${_pkgconfig_VERSION}")
@@ -398,7 +404,7 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma
 
     if(NOT "${_extra_paths}" STREQUAL "")
       # Restore the environment variable
-      set(ENV{PKG_CONFIG_PATH} ${_pkgconfig_path})
+      set(ENV{PKG_CONFIG_PATH} "${_pkgconfig_path_old}")
     endif()
 
     unset(_extra_paths)
diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake
index 4a68cd1..2f13b09 100644
--- a/Modules/FindProtobuf.cmake
+++ b/Modules/FindProtobuf.cmake
@@ -305,7 +305,7 @@ mark_as_advanced(PROTOBUF_PROTOC_EXECUTABLE)
 
 
 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(PROTOBUF DEFAULT_MSG
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Protobuf DEFAULT_MSG
     PROTOBUF_LIBRARY PROTOBUF_INCLUDE_DIR)
 
 if(PROTOBUF_FOUND)
diff --git a/Modules/FindPythonInterp.cmake b/Modules/FindPythonInterp.cmake
index 879192e..e194185 100644
--- a/Modules/FindPythonInterp.cmake
+++ b/Modules/FindPythonInterp.cmake
@@ -28,9 +28,10 @@
 # for Python.  You need to set this variable before calling
 # find_package(PythonInterp).
 #
-# If also calling find_package(PythonLibs), call find_package(PythonInterp)
-# first to get the currently active Python version by default with a consistent
-# version of PYTHON_LIBRARIES.
+# If calling both ``find_package(PythonInterp)`` and
+# ``find_package(PythonLibs)``, call ``find_package(PythonInterp)`` first to
+# get the currently active Python version by default with a consistent version
+# of PYTHON_LIBRARIES.
 
 #=============================================================================
 # Copyright 2005-2010 Kitware, Inc.
diff --git a/Modules/FindPythonLibs.cmake b/Modules/FindPythonLibs.cmake
index 68e1228..ab92f86 100644
--- a/Modules/FindPythonLibs.cmake
+++ b/Modules/FindPythonLibs.cmake
@@ -32,9 +32,10 @@
 #   PYTHON_LIBRARY             - path to the python library
 #   PYTHON_INCLUDE_DIR         - path to where Python.h is found
 #
-# If also calling find_package(PythonInterp), call find_package(PythonInterp)
-# first to get the currently active Python version by default with a consistent
-# version of PYTHON_LIBRARIES.
+# If calling both ``find_package(PythonInterp)`` and
+# ``find_package(PythonLibs)``, call ``find_package(PythonInterp)`` first to
+# get the currently active Python version by default with a consistent version
+# of PYTHON_LIBRARIES.
 
 #=============================================================================
 # Copyright 2001-2009 Kitware, Inc.
diff --git a/Modules/FindTIFF.cmake b/Modules/FindTIFF.cmake
index ed092ea..e600498 100644
--- a/Modules/FindTIFF.cmake
+++ b/Modules/FindTIFF.cmake
@@ -2,24 +2,43 @@
 # FindTIFF
 # --------
 #
-# Find TIFF library
+# Find the TIFF library (libtiff).
 #
-# Find the native TIFF includes and library This module defines
+# Imported targets
+# ^^^^^^^^^^^^^^^^
 #
-# ::
+# This module defines the following :prop_tgt:`IMPORTED` targets:
 #
-#   TIFF_INCLUDE_DIR, where to find tiff.h, etc.
-#   TIFF_LIBRARIES, libraries to link against to use TIFF.
-#   TIFF_FOUND, If false, do not try to use TIFF.
+# ``TIFF::TIFF``
+#   The TIFF library, if found.
 #
-# also defined, but not for general use are
+# Result variables
+# ^^^^^^^^^^^^^^^^
 #
-# ::
+# This module will set the following variables in your project:
 #
-#   TIFF_LIBRARY, where to find the TIFF library.
+# ``TIFF_FOUND``
+#   true if the TIFF headers and libraries were found
+# ``TIFF_INCLUDE_DIR``
+#   the directory containing the TIFF headers
+# ``TIFF_INCLUDE_DIRS``
+#   the directory containing the TIFF headers
+# ``TIFF_LIBRARIES``
+#   TIFF libraries to be linked
+#
+# Cache variables
+# ^^^^^^^^^^^^^^^
+#
+# The following cache variables may also be set:
+#
+# ``TIFF_INCLUDE_DIR``
+#   the directory containing the TIFF headers
+# ``TIFF_LIBRARY``
+#   the path to the TIFF library
 
 #=============================================================================
 # Copyright 2002-2009 Kitware, Inc.
+# Copyright 2015 University of Dundee
 #
 # Distributed under the OSI-approved BSD License (the "License");
 # see accompanying file Copyright.txt for details.
@@ -65,7 +84,35 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(TIFF
                                   VERSION_VAR TIFF_VERSION_STRING)
 
 if(TIFF_FOUND)
-  set( TIFF_LIBRARIES ${TIFF_LIBRARY} )
+  set(TIFF_LIBRARIES ${TIFF_LIBRARY})
+  set(TIFF_INCLUDE_DIRS "${TIFF_INCLUDE_DIR}")
+
+  if(NOT TARGET TIFF::TIFF)
+    add_library(TIFF::TIFF UNKNOWN IMPORTED)
+    if(TIFF_INCLUDE_DIRS)
+      set_target_properties(TIFF::TIFF PROPERTIES
+        INTERFACE_INCLUDE_DIRECTORIES "${TIFF_INCLUDE_DIRS}")
+    endif()
+    if(EXISTS "${TIFF_LIBRARY}")
+      set_target_properties(TIFF::TIFF PROPERTIES
+        IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+        IMPORTED_LOCATION "${TIFF_LIBRARY}")
+    endif()
+    if(EXISTS "${TIFF_LIBRARY_DEBUG}")
+      set_property(TARGET TIFF::TIFF APPEND PROPERTY
+        IMPORTED_CONFIGURATIONS DEBUG)
+      set_target_properties(TIFF::TIFF PROPERTIES
+        IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
+        IMPORTED_LOCATION_DEBUG "${TIFF_LIBRARY_DEBUG}")
+    endif()
+    if(EXISTS "${TIFF_LIBRARY_RELEASE}")
+      set_property(TARGET TIFF::TIFF APPEND PROPERTY
+        IMPORTED_CONFIGURATIONS RELEASE)
+      set_target_properties(TIFF::TIFF PROPERTIES
+        IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
+        IMPORTED_LOCATION_RELEASE "${TIFF_LIBRARY_RELEASE}")
+    endif()
+  endif()
 endif()
 
 mark_as_advanced(TIFF_INCLUDE_DIR TIFF_LIBRARY)
diff --git a/Modules/FindXalanC.cmake b/Modules/FindXalanC.cmake
new file mode 100644
index 0000000..016b7aa
--- /dev/null
+++ b/Modules/FindXalanC.cmake
@@ -0,0 +1,162 @@
+#.rst:
+# FindXalanC
+# -----------
+#
+# Find the Apache Xalan-C++ XSL transform processor headers and libraries.
+#
+# Imported targets
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines the following :prop_tgt:`IMPORTED` targets:
+#
+# ``XalanC::XalanC``
+#   The Xalan-C++ ``xalan-c`` library, if found.
+#
+# Result variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module will set the following variables in your project:
+#
+# ``XalanC_FOUND``
+#   true if the Xalan headers and libraries were found
+# ``XalanC_VERSION``
+#   Xalan release version
+# ``XalanC_INCLUDE_DIRS``
+#   the directory containing the Xalan headers; note
+#   ``XercesC_INCLUDE_DIRS`` is also required
+# ``XalanC_LIBRARIES``
+#   Xalan libraries to be linked; note ``XercesC_LIBRARIES`` is also
+#   required
+#
+# Cache variables
+# ^^^^^^^^^^^^^^^
+#
+# The following cache variables may also be set:
+#
+# ``XalanC_INCLUDE_DIR``
+#   the directory containing the Xalan headers
+# ``XalanC_LIBRARY``
+#   the Xalan library
+
+# Written by Roger Leigh <rleigh at codelibre.net>
+
+#=============================================================================
+# Copyright 2016 University of Dundee
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+function(_XalanC_GET_VERSION  version_hdr)
+    file(STRINGS ${version_hdr} _contents REGEX "^[ \t]*#define XALAN_VERSION_.*")
+    if(_contents)
+        string(REGEX REPLACE "[^*]*#define XALAN_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" XalanC_MAJOR "${_contents}")
+        string(REGEX REPLACE "[^*]*#define XALAN_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" XalanC_MINOR "${_contents}")
+        string(REGEX REPLACE "[^*]*#define XALAN_VERSION_REVISION[ \t]+([0-9]+).*" "\\1" XalanC_PATCH "${_contents}")
+
+        if(NOT XalanC_MAJOR MATCHES "^[0-9]+$")
+            message(FATAL_ERROR "Version parsing failed for XALAN_VERSION_MAJOR!")
+        endif()
+        if(NOT XalanC_MINOR MATCHES "^[0-9]+$")
+            message(FATAL_ERROR "Version parsing failed for XALAN_VERSION_MINOR!")
+        endif()
+        if(NOT XalanC_PATCH MATCHES "^[0-9]+$")
+            message(FATAL_ERROR "Version parsing failed for XALAN_VERSION_REVISION!")
+        endif()
+
+        set(XalanC_VERSION "${XalanC_MAJOR}.${XalanC_MINOR}.${XalanC_PATCH}" PARENT_SCOPE)
+        set(XalanC_VERSION_MAJOR "${XalanC_MAJOR}" PARENT_SCOPE)
+        set(XalanC_VERSION_MINOR "${XalanC_MINOR}" PARENT_SCOPE)
+        set(XalanC_VERSION_PATCH "${XalanC_PATCH}" PARENT_SCOPE)
+    else()
+        message(FATAL_ERROR "Include file ${version_hdr} does not exist or does not contain expected version information")
+    endif()
+endfunction()
+
+# Find include directory
+find_path(XalanC_INCLUDE_DIR
+          NAMES "xalanc/XalanTransformer/XalanTransformer.hpp"
+          DOC "Xalan-C++ include directory")
+mark_as_advanced(XalanC_INCLUDE_DIR)
+
+if(XalanC_INCLUDE_DIR)
+  _XalanC_GET_VERSION("${XalanC_INCLUDE_DIR}/xalanc/Include/XalanVersion.hpp")
+endif()
+
+if(NOT XalanC_LIBRARY)
+  # Find all XalanC libraries
+  find_library(XalanC_LIBRARY_RELEASE
+               NAMES "Xalan-C" "xalan-c"
+                     "Xalan-C_${XalanC_VERSION_MAJOR}"
+                     "Xalan-C_${XalanC_VERSION_MAJOR}_${XalanC_VERSION_MINOR}"
+               DOC "Xalan-C++ libraries (release)")
+  find_library(XalanC_LIBRARY_DEBUG
+               NAMES "Xalan-CD" "xalan-cd"
+                     "Xalan-C_${XalanC_VERSION_MAJOR}D"
+                     "Xalan-C_${XalanC_VERSION_MAJOR}_${XalanC_VERSION_MINOR}D"
+               DOC "Xalan-C++ libraries (debug)")
+  include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
+  select_library_configurations(XalanC)
+  mark_as_advanced(XalanC_LIBRARY_RELEASE XalanC_LIBRARY_DEBUG)
+endif()
+
+unset(XalanC_VERSION_MAJOR)
+unset(XalanC_VERSION_MINOR)
+unset(XalanC_VERSION_PATCH)
+
+unset(XalanC_XERCESC_REQUIRED)
+if(XalanC_FIND_REQUIRED)
+  set(XalanC_XERCESC_REQUIRED REQUIRED)
+endif()
+find_package(XercesC ${XalanC_XERCESC_REQUIRED})
+unset(XalanC_XERCESC_REQUIRED)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(XalanC
+                                  FOUND_VAR XalanC_FOUND
+                                  REQUIRED_VARS XalanC_LIBRARY
+                                                XalanC_INCLUDE_DIR
+                                                XalanC_VERSION
+                                                XercesC_FOUND
+                                  VERSION_VAR XalanC_VERSION
+                                  FAIL_MESSAGE "Failed to find XalanC")
+
+if(XalanC_FOUND)
+  set(XalanC_INCLUDE_DIRS "${XalanC_INCLUDE_DIR}" ${XercesC_INCLUDE_DIRS})
+  set(XalanC_LIBRARIES "${XalanC_LIBRARY}" ${XercesC_LIBRARIES})
+
+  # For header-only libraries
+  if(NOT TARGET XalanC::XalanC)
+    add_library(XalanC::XalanC UNKNOWN IMPORTED)
+    if(XalanC_INCLUDE_DIRS)
+      set_target_properties(XalanC::XalanC PROPERTIES
+        INTERFACE_INCLUDE_DIRECTORIES "${XalanC_INCLUDE_DIRS}")
+    endif()
+    if(EXISTS "${XalanC_LIBRARY}")
+      set_target_properties(XalanC::XalanC PROPERTIES
+        IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
+        IMPORTED_LOCATION "${XalanC_LIBRARY}")
+    endif()
+    if(EXISTS "${XalanC_LIBRARY_DEBUG}")
+      set_property(TARGET XalanC::XalanC APPEND PROPERTY
+        IMPORTED_CONFIGURATIONS DEBUG)
+      set_target_properties(XalanC::XalanC PROPERTIES
+        IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
+        IMPORTED_LOCATION_DEBUG "${XalanC_LIBRARY_DEBUG}")
+    endif()
+    if(EXISTS "${XalanC_LIBRARY_RELEASE}")
+      set_property(TARGET XalanC::XalanC APPEND PROPERTY
+        IMPORTED_CONFIGURATIONS RELEASE)
+      set_target_properties(XalanC::XalanC PROPERTIES
+        IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
+        IMPORTED_LOCATION_RELEASE "${XalanC_LIBRARY_RELEASE}")
+    endif()
+    set_target_properties(XalanC::XalanC PROPERTIES INTERFACE_LINK_LIBRARIES XercesC::XercesC)
+  endif()
+endif()
diff --git a/Modules/FindXercesC.cmake b/Modules/FindXercesC.cmake
index cf84826..a4b80e5 100644
--- a/Modules/FindXercesC.cmake
+++ b/Modules/FindXercesC.cmake
@@ -4,23 +4,42 @@
 #
 # Find the Apache Xerces-C++ validating XML parser headers and libraries.
 #
-# This module reports information about the Xerces installation in
-# several variables.  General variables::
+# Imported targets
+# ^^^^^^^^^^^^^^^^
 #
-#   XercesC_FOUND - true if the Xerces headers and libraries were found
-#   XercesC_VERSION - Xerces release version
-#   XercesC_INCLUDE_DIRS - the directory containing the Xerces headers
-#   XercesC_LIBRARIES - Xerces libraries to be linked
+# This module defines the following :prop_tgt:`IMPORTED` targets:
 #
-# The following cache variables may also be set::
+# ``XercesC::XercesC``
+#   The Xerces-C++ ``xerces-c`` library, if found.
 #
-#   XercesC_INCLUDE_DIR - the directory containing the Xerces headers
-#   XercesC_LIBRARY - the Xerces library
+# Result variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module will set the following variables in your project:
+#
+# ``XercesC_FOUND``
+#   true if the Xerces headers and libraries were found
+# ``XercesC_VERSION``
+#   Xerces release version
+# ``XercesC_INCLUDE_DIRS``
+#   the directory containing the Xerces headers
+# ``XercesC_LIBRARIES``
+#   Xerces libraries to be linked
+#
+# Cache variables
+# ^^^^^^^^^^^^^^^
+#
+# The following cache variables may also be set:
+#
+# ``XercesC_INCLUDE_DIR``
+#   the directory containing the Xerces headers
+# ``XercesC_LIBRARY``
+#   the Xerces library
 
 # Written by Roger Leigh <rleigh at codelibre.net>
 
 #=============================================================================
-# Copyright 2014 University of Dundee
+# Copyright 2014-2015 University of Dundee
 #
 # Distributed under the OSI-approved BSD License (the "License");
 # see accompanying file Copyright.txt for details.
@@ -90,4 +109,32 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(XercesC
 if(XercesC_FOUND)
   set(XercesC_INCLUDE_DIRS "${XercesC_INCLUDE_DIR}")
   set(XercesC_LIBRARIES "${XercesC_LIBRARY}")
+
+  # For header-only libraries
+  if(NOT TARGET XercesC::XercesC)
+    add_library(XercesC::XercesC UNKNOWN IMPORTED)
+    if(XercesC_INCLUDE_DIRS)
+      set_target_properties(XercesC::XercesC PROPERTIES
+        INTERFACE_INCLUDE_DIRECTORIES "${XercesC_INCLUDE_DIRS}")
+    endif()
+    if(EXISTS "${XercesC_LIBRARY}")
+      set_target_properties(XercesC::XercesC PROPERTIES
+        IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
+        IMPORTED_LOCATION "${XercesC_LIBRARY}")
+    endif()
+    if(EXISTS "${XercesC_LIBRARY_DEBUG}")
+      set_property(TARGET XercesC::XercesC APPEND PROPERTY
+        IMPORTED_CONFIGURATIONS DEBUG)
+      set_target_properties(XercesC::XercesC PROPERTIES
+        IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
+        IMPORTED_LOCATION_DEBUG "${XercesC_LIBRARY_DEBUG}")
+    endif()
+    if(EXISTS "${XercesC_LIBRARY_RELEASE}")
+      set_property(TARGET XercesC::XercesC APPEND PROPERTY
+        IMPORTED_CONFIGURATIONS RELEASE)
+      set_target_properties(XercesC::XercesC PROPERTIES
+        IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
+        IMPORTED_LOCATION_RELEASE "${XercesC_LIBRARY_RELEASE}")
+    endif()
+  endif()
 endif()
diff --git a/Modules/FindwxWidgets.cmake b/Modules/FindwxWidgets.cmake
index 9037594..49ce57e 100644
--- a/Modules/FindwxWidgets.cmake
+++ b/Modules/FindwxWidgets.cmake
@@ -188,18 +188,6 @@ set(wxWidgets_LIBRARIES    "")
 set(wxWidgets_LIBRARY_DIRS "")
 set(wxWidgets_CXX_FLAGS    "")
 
-# Using SYSTEM with INCLUDE_DIRECTORIES in conjunction with wxWidgets on
-# the Mac produces compiler errors. Set wxWidgets_INCLUDE_DIRS_NO_SYSTEM
-# to prevent UsewxWidgets.cmake from using SYSTEM.
-#
-# See cmake mailing list discussions for more info:
-#   https://cmake.org/pipermail/cmake/2008-April/021115.html
-#   https://cmake.org/pipermail/cmake/2008-April/021146.html
-#
-if(APPLE OR CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
-  set(wxWidgets_INCLUDE_DIRS_NO_SYSTEM 1)
-endif()
-
 # DEPRECATED: This is a patch to support the DEPRECATED use of
 # wxWidgets_USE_LIBS.
 #
diff --git a/Modules/GenerateExportHeader.cmake b/Modules/GenerateExportHeader.cmake
index 8205425..4f4efbc 100644
--- a/Modules/GenerateExportHeader.cmake
+++ b/Modules/GenerateExportHeader.cmake
@@ -230,7 +230,11 @@ macro(_test_compiler_hidden_visibility)
 endmacro()
 
 macro(_test_compiler_has_deprecated)
+  # NOTE:  Some Embarcadero compilers silently compile __declspec(deprecated)
+  # without error, but this is not a documented feature and the attribute does
+  # not actually generate any warnings.
   if(CMAKE_CXX_COMPILER_ID MATCHES Borland
+      OR CMAKE_CXX_COMPILER_ID MATCHES Embarcadero
       OR CMAKE_CXX_COMPILER_ID MATCHES HP
       OR GCC_TOO_OLD
       OR CMAKE_CXX_COMPILER_ID MATCHES PGI
diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake
index e4018b6..391e7f8 100644
--- a/Modules/GetPrerequisites.cmake
+++ b/Modules/GetPrerequisites.cmake
@@ -538,7 +538,7 @@ function(gp_resolved_file_type original_file file exepath dirs type_var)
       string(TOLOWER "$ENV{windir}" windir)
       file(TO_CMAKE_PATH "${windir}" windir)
 
-      if(lower MATCHES "^(${sysroot}/sys(tem|wow)|${windir}/sys(tem|wow)|(.*/)*msvc[^/]+dll)")
+      if(lower MATCHES "^(api-ms-win-|${sysroot}/sys(tem|wow)|${windir}/sys(tem|wow)|(.*/)*msvc[^/]+dll)")
         set(is_system 1)
       endif()
 
@@ -566,7 +566,7 @@ function(gp_resolved_file_type original_file file exepath dirs type_var)
           string(TOLOWER "${env_windir}" windir)
           string(TOLOWER "${env_sysdir}" sysroot)
 
-          if(lower MATCHES "^(${sysroot}/sys(tem|wow)|${windir}/sys(tem|wow)|(.*/)*msvc[^/]+dll)")
+          if(lower MATCHES "^(api-ms-win-|${sysroot}/sys(tem|wow)|${windir}/sys(tem|wow)|(.*/)*msvc[^/]+dll)")
             set(is_system 1)
           endif()
         endif()
diff --git a/Modules/NSIS.template.in b/Modules/NSIS.template.in
index 76310af..1ef3d28 100644
--- a/Modules/NSIS.template.in
+++ b/Modules/NSIS.template.in
@@ -542,6 +542,8 @@ FunctionEnd
 ; Define some macro setting for the gui
 @CPACK_NSIS_INSTALLER_MUI_ICON_CODE@
 @CPACK_NSIS_INSTALLER_ICON_CODE@
+ at CPACK_NSIS_INSTALLER_MUI_WELCOMEFINISH_CODE@
+ at CPACK_NSIS_INSTALLER_MUI_UNWELCOMEFINISH_CODE@
 @CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC@
 @CPACK_NSIS_INSTALLER_MUI_FINISHPAGE_RUN_CODE@
 
diff --git a/Modules/Platform/AIX-GNU.cmake b/Modules/Platform/AIX-GNU.cmake
index e5d9434..d6f5331 100644
--- a/Modules/Platform/AIX-GNU.cmake
+++ b/Modules/Platform/AIX-GNU.cmake
@@ -18,10 +18,20 @@ if(__AIX_COMPILER_GNU)
 endif()
 set(__AIX_COMPILER_GNU 1)
 
+#
+# By default, runtime linking is enabled. All shared objects specified on the command line
+# will be listed, even if there are no symbols referenced, in the output file.
+set (CMAKE_SHARED_LINKER_FLAGS_INIT "-Wl,-brtl")
+set (CMAKE_MODULE_LINKER_FLAGS_INIT "-Wl,-brtl")
+set (CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-brtl")
+
+
 macro(__aix_compiler_gnu lang)
   set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG "-Wl,-blibpath:")
   set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ":")
   set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS} -Wl,-G,-bnoipath")
-  set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-brtl,-bnoipath,-bexpall")  # +s, flag for exe link to use shared lib
+  set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-bexpall")
   set(CMAKE_${lang}_USE_IMPLICIT_LINK_DIRECTORIES_IN_RUNTIME_PATH 1)
+
+  set(CMAKE_${lang}_LINK_FLAGS "-Wl,-bnoipath")
 endmacro()
diff --git a/Modules/Platform/AIX-XL.cmake b/Modules/Platform/AIX-XL.cmake
index abf3855..5470441 100644
--- a/Modules/Platform/AIX-XL.cmake
+++ b/Modules/Platform/AIX-XL.cmake
@@ -18,11 +18,21 @@ if(__AIX_COMPILER_XL)
 endif()
 set(__AIX_COMPILER_XL 1)
 
+#
+# By default, runtime linking is enabled. All shared objects specified on the command line
+# will be listed, even if there are no symbols referenced, in the output file.
+set(CMAKE_SHARED_LINKER_FLAGS_INIT "-Wl,-brtl")
+set(CMAKE_MODULE_LINKER_FLAGS_INIT "-Wl,-brtl")
+set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-brtl")
+
+
 macro(__aix_compiler_xl lang)
   set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG "-Wl,-blibpath:")
   set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ":")
   set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-G -Wl,-bnoipath")  # -shared
-  set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-brtl,-bnoipath,-bexpall")  # +s, flag for exe link to use shared lib
+  set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-bexpall")
   set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS " ")
   set(CMAKE_SHARED_MODULE_${lang}_FLAGS  " ")
+
+  set(CMAKE_${lang}_LINK_FLAGS "-Wl,-bnoipath")
 endmacro()
diff --git a/Modules/Platform/CrayLinuxEnvironment.cmake b/Modules/Platform/CrayLinuxEnvironment.cmake
new file mode 100644
index 0000000..97771a2
--- /dev/null
+++ b/Modules/Platform/CrayLinuxEnvironment.cmake
@@ -0,0 +1,143 @@
+# Compute Node Linux doesn't quite work the same as native Linux so all of this
+# needs to be custom.  We use the variables defined through Cray's environment
+# modules to set up the right paths for things.
+
+set(UNIX 1)
+
+if(DEFINED ENV{CRAYOS_VERSION})
+  set(CMAKE_SYSTEM_VERSION "$ENV{CRAYOS_VERSION}")
+elseif(DEFINED ENV{XTOS_VERSION})
+  set(CMAKE_SYSTEM_VERSION "$ENV{XTOS_VERSION}")
+else()
+  message(FATAL_ERROR "Neither the CRAYOS_VERSION or XTOS_VERSION environment variables are defined.  This platform file should be used inside the Cray Linux Environment for targeting compute nodes (NIDs)")
+endif()
+
+# Guard against multiple messages
+if(NOT __CrayLinuxEnvironment_message)
+  set(__CrayLinuxEnvironment_message 1)
+  message(STATUS "Cray Linux Environment ${CMAKE_SYSTEM_VERSION}")
+endif()
+
+# All cray systems are x86 CPUs and have been for quite some time
+# Note: this may need to change in the future with 64-bit ARM
+set(CMAKE_SYSTEM_PROCESSOR "x86_64")
+
+set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
+set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
+set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
+
+set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
+
+# Don't override shared lib support if it's already been set and possibly
+# overridden elsewhere by the CrayPrgEnv module
+if(NOT CMAKE_FIND_LIBRARY_SUFFIXES)
+  set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
+  set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
+endif()
+
+set(CMAKE_DL_LIBS dl)
+
+# Note: Much of this is pulled from UnixPaths.cmake but adjusted to the Cray
+# environment accordingly
+
+# Get the install directory of the running cmake to the search directories
+# CMAKE_ROOT is CMAKE_INSTALL_PREFIX/share/cmake, so we need to go two levels up
+get_filename_component(__cmake_install_dir "${CMAKE_ROOT}" PATH)
+get_filename_component(__cmake_install_dir "${__cmake_install_dir}" PATH)
+
+# Note: Some Cray's have the SYSROOT_DIR variable defined, pointing to a copy
+# of the NIDs userland.  If so, then we'll use it.  Otherwise, just assume
+# the userland from the login node is ok
+
+# List common installation prefixes.  These will be used for all
+# search types.
+list(APPEND CMAKE_SYSTEM_PREFIX_PATH
+  # Standard
+  $ENV{SYSROOT_DIR}/usr/local $ENV{SYSROOT_DIR}/usr $ENV{SYSROOT_DIR}/
+
+  # CMake install location
+  "${__cmake_install_dir}"
+  )
+if (NOT CMAKE_FIND_NO_INSTALL_PREFIX)
+  list(APPEND CMAKE_SYSTEM_PREFIX_PATH
+    # Project install destination.
+    "${CMAKE_INSTALL_PREFIX}"
+  )
+  if(CMAKE_STAGING_PREFIX)
+    list(APPEND CMAKE_SYSTEM_PREFIX_PATH
+      # User-supplied staging prefix.
+      "${CMAKE_STAGING_PREFIX}"
+    )
+  endif()
+endif()
+
+list(APPEND CMAKE_SYSTEM_INCLUDE_PATH
+  $ENV{SYSROOT_DIR}/usr/include
+  $ENV{SYSROOT_DIR}/usr/include/X11
+)
+list(APPEND CMAKE_SYSTEM_LIBRARY_PATH
+  $ENV{SYSROOT_DIR}/usr/local/lib64
+  $ENV{SYSROOT_DIR}/usr/lib64
+  $ENV{SYSROOT_DIR}/lib64
+)
+list(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
+  $ENV{SYSROOT_DIR}/usr/local/lib64
+  $ENV{SYSROOT_DIR}/usr/lib64
+  $ENV{SYSROOT_DIR}/lib64
+)
+
+# Compute the intersection of several lists
+function(__cray_list_intersect OUTPUT INPUT0)
+  if(ARGC EQUAL 2)
+    list(APPEND ${OUTPUT} ${${INPUT0}})
+  else()
+    foreach(I IN LISTS ${INPUT0})
+      set(__is_common 1)
+      foreach(L IN LISTS ARGN)
+        list(FIND ${L} "${I}" __idx)
+        if(__idx EQUAL -1)
+          set(__is_common 0)
+          break()
+        endif()
+      endforeach()
+      if(__is_common)
+        list(APPEND ${OUTPUT}  "${I}")
+      endif()
+    endforeach()
+  endif()
+  set(${OUTPUT} ${${OUTPUT}} PARENT_SCOPE)
+endfunction()
+
+macro(__list_clean_dupes var)
+  if(${var})
+    list(REMOVE_DUPLICATES ${var})
+  endif()
+endmacro()
+
+get_property(__langs GLOBAL PROPERTY ENABLED_LANGUAGES)
+set(__cray_inc_path_vars)
+set(__cray_lib_path_vars)
+foreach(__lang IN LISTS __langs)
+  list(APPEND __cray_inc_path_vars CMAKE_${__lang}_IMPLICIT_INCLUDE_DIRECTORIES)
+  list(APPEND __cray_lib_path_vars CMAKE_${__lang}_IMPLICIT_LINK_DIRECTORIES)
+endforeach()
+if(__cray_inc_path_vars)
+  __cray_list_intersect(__cray_implicit_include_dirs ${__cray_inc_path_vars})
+  if(__cray_implicit_include_dirs)
+    list(INSERT CMAKE_SYSTEM_INCLUDE_PATH 0 ${__cray_implicit_include_dirs})
+  endif()
+endif()
+if(__cray_lib_path_vars)
+  __cray_list_intersect(__cray_implicit_library_dirs ${__cray_lib_path_vars})
+  if(__cray_implicit_library_dirs)
+    list(INSERT CMAKE_SYSTEM_LIBRARY_PATH 0 ${__cray_implicit_library_dirs})
+  endif()
+endif()
+__list_clean_dupes(CMAKE_SYSTEM_PREFIX_PATH)
+__list_clean_dupes(CMAKE_SYSTEM_INCLUDE_PATH)
+__list_clean_dupes(CMAKE_SYSTEM_LIBRARY_PATH)
+__list_clean_dupes(CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES)
+
+# Enable use of lib64 search path variants by default.
+set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
diff --git a/Modules/Platform/HP-UX-GNU.cmake b/Modules/Platform/HP-UX-GNU.cmake
index eb909fe..6c71784 100644
--- a/Modules/Platform/HP-UX-GNU.cmake
+++ b/Modules/Platform/HP-UX-GNU.cmake
@@ -20,8 +20,10 @@ set(__HPUX_COMPILER_GNU 1)
 
 macro(__hpux_compiler_gnu lang)
   set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS} -Wl,-E,-b,+nodefaultrpath")
-  set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,+s,-E,+nodefaultrpath")
+  set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-E")
   set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG "-Wl,+b")
   set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ":")
   set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG "-Wl,+h")
+
+  set(CMAKE_${lang}_LINK_FLAGS "-Wl,+s,+nodefaultrpath")
 endmacro()
diff --git a/Modules/Platform/HP-UX-HP.cmake b/Modules/Platform/HP-UX-HP.cmake
index 871ea13..3935c31 100644
--- a/Modules/Platform/HP-UX-HP.cmake
+++ b/Modules/Platform/HP-UX-HP.cmake
@@ -22,10 +22,12 @@ macro(__hpux_compiler_hp lang)
   set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "+Z")
   set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "+Z")
   set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-Wl,-E,+nodefaultrpath -b -L/usr/lib")
-  set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,+s,-E,+nodefaultrpath")
+  set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-E")
   set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG "-Wl,+b")
   set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ":")
   set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG "-Wl,+h")
 
   set(CMAKE_${lang}_FLAGS_INIT "")
+
+  set(CMAKE_${lang}_LINK_FLAGS "-Wl,+s,+nodefaultrpath")
 endmacro()
diff --git a/Modules/Platform/SunOS.cmake b/Modules/Platform/SunOS.cmake
index 77946f2..58398c0 100644
--- a/Modules/Platform/SunOS.cmake
+++ b/Modules/Platform/SunOS.cmake
@@ -9,12 +9,6 @@ endif()
 
 include(Platform/UnixPaths)
 
-# Add the compiler's implicit link directories.
-if("${CMAKE_C_COMPILER_ID} ${CMAKE_CXX_COMPILER_ID}" MATCHES SunPro)
-  list(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
-    /opt/SUNWspro/lib /opt/SUNWspro/prod/lib /usr/ccs/lib)
-endif()
-
 # The Sun linker needs to find transitive shared library dependencies
 # in the -L path.
 set(CMAKE_LINK_DEPENDENT_LIBRARY_DIRS 1)
diff --git a/Modules/Platform/Windows-Embarcadero.cmake b/Modules/Platform/Windows-Embarcadero.cmake
index 5295a48..102e3a6 100644
--- a/Modules/Platform/Windows-Embarcadero.cmake
+++ b/Modules/Platform/Windows-Embarcadero.cmake
@@ -78,7 +78,11 @@ set (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_SHARED_LINKER_FLAGS_R
 # invocations within a single working directory.
 if(NOT DEFINED CMAKE_JOB_POOL_LINK)
   set(CMAKE_JOB_POOL_LINK BCC32LinkPool)
-  set_property(GLOBAL APPEND PROPERTY JOB_POOLS BCC32LinkPool=1)
+  get_property(_bccjp GLOBAL PROPERTY JOB_POOLS)
+  if(NOT _bccjp MATCHES "BCC32LinkPool=")
+      set_property(GLOBAL APPEND PROPERTY JOB_POOLS BCC32LinkPool=1)
+  endif()
+  unset(_bccjp)
 endif()
 
 macro(__embarcadero_language lang)
diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake
index b421b0d..a61413a 100644
--- a/Modules/Platform/Windows-MSVC.cmake
+++ b/Modules/Platform/Windows-MSVC.cmake
@@ -302,6 +302,7 @@ macro(__windows_compiler_msvc lang)
   set(CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "/MD /Zi /O2 /Ob1 /D NDEBUG")
   set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "/MD /O1 /Ob1 /D NDEBUG")
   set(CMAKE_${lang}_LINKER_SUPPORTS_PDB ON)
+  set(CMAKE_NINJA_DEPTYPE_${lang} msvc)
 
   if(NOT CMAKE_RC_COMPILER_INIT)
     set(CMAKE_RC_COMPILER_INIT rc)
@@ -311,4 +312,5 @@ macro(__windows_compiler_msvc lang)
   endif()
 
   enable_language(RC)
+  set(CMAKE_NINJA_CMCLDEPS_RC 1)
 endmacro()
diff --git a/Modules/Platform/WindowsPaths.cmake b/Modules/Platform/WindowsPaths.cmake
index 658de3b..eafa8fa 100644
--- a/Modules/Platform/WindowsPaths.cmake
+++ b/Modules/Platform/WindowsPaths.cmake
@@ -28,46 +28,32 @@ set(__WINDOWS_PATHS_INCLUDED 1)
 # Windows 64-bit Binary:
 #   ENV{ProgramFiles(x86)} = [C:\Program Files (x86)]
 #   ENV{ProgramFiles} = [C:\Program Files]
-#   ENV{ProgramW6432} = <not set>
-# (executed from cygwin):
-#   ENV{ProgramFiles(x86)} = <not set>
-#   ENV{ProgramFiles} = [C:\Program Files]
-#   ENV{ProgramW6432} = <not set>
+#   ENV{ProgramW6432} = [C:\Program Files] or <not set>
 #
-# Windows 32-bit Binary:
+# Windows 32-bit Binary on 64-bit Windows:
 #   ENV{ProgramFiles(x86)} = [C:\Program Files (x86)]
 #   ENV{ProgramFiles} = [C:\Program Files (x86)]
 #   ENV{ProgramW6432} = [C:\Program Files]
-# (executed from cygwin):
-#   ENV{ProgramFiles(x86)} = <not set>
-#   ENV{ProgramFiles} = [C:\Program Files (x86)]
-#   ENV{ProgramW6432} = [C:\Program Files]
-if(DEFINED "ENV{ProgramW6432}")
-  # 32-bit binary on 64-bit windows.
-  # The 64-bit program files are in ProgramW6432.
-  list(APPEND CMAKE_SYSTEM_PREFIX_PATH "$ENV{ProgramW6432}")
-
-  # The 32-bit program files are in ProgramFiles.
-  if(DEFINED "ENV{ProgramFiles}")
-    list(APPEND CMAKE_SYSTEM_PREFIX_PATH "$ENV{ProgramFiles}")
+set(_programfiles "")
+foreach(v "ProgramW6432" "ProgramFiles" "ProgramFiles(x86)")
+  if(DEFINED "ENV{${v}}")
+    file(TO_CMAKE_PATH "$ENV{${v}}" _env_programfiles)
+    list(APPEND _programfiles "${_env_programfiles}")
+    unset(_env_programfiles)
   endif()
-else()
-  # 64-bit binary, or 32-bit binary on 32-bit windows.
-  if(DEFINED "ENV{ProgramFiles}")
-    list(APPEND CMAKE_SYSTEM_PREFIX_PATH "$ENV{ProgramFiles}")
-  endif()
-  set(programfilesx86 "ProgramFiles(x86)")
-  if(DEFINED "ENV{${programfilesx86}}")
-    # 64-bit binary.  32-bit program files are in ProgramFiles(x86).
-    list(APPEND CMAKE_SYSTEM_PREFIX_PATH "$ENV{${programfilesx86}}")
-  elseif(DEFINED "ENV{SystemDrive}")
-    # Guess the 32-bit program files location.
-    if(EXISTS "$ENV{SystemDrive}/Program Files (x86)")
-      list(APPEND CMAKE_SYSTEM_PREFIX_PATH
-        "$ENV{SystemDrive}/Program Files (x86)")
+endforeach()
+if(DEFINED "ENV{SystemDrive}")
+  foreach(d "Program Files" "Program Files (x86)")
+    if(EXISTS "$ENV{SystemDrive}/${d}")
+      list(APPEND _programfiles "$ENV{SystemDrive}/${d}")
     endif()
-  endif()
+  endforeach()
+endif()
+if(_programfiles)
+  list(REMOVE_DUPLICATES _programfiles)
+  list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${_programfiles})
 endif()
+unset(_programfiles)
 
 # Add the CMake install location.
 get_filename_component(_CMAKE_INSTALL_DIR "${CMAKE_ROOT}" PATH)
diff --git a/Modules/UseJava.cmake b/Modules/UseJava.cmake
index dced6ec..475ad5e 100644
--- a/Modules/UseJava.cmake
+++ b/Modules/UseJava.cmake
@@ -184,7 +184,7 @@
 #                       This is used by install_jni_symlink().
 #    JAR_FILE           The location of the jar file so that you can include
 #                       it.
-#    CLASS_DIR          The directory where the class files can be found. For
+#    CLASSDIR           The directory where the class files can be found. For
 #                       example to use them with javah.
 #
 # ::
@@ -444,7 +444,7 @@ function(add_jar _TARGET_NAME)
 
     if (_add_jar_MANIFEST)
         set(_MANIFEST_OPTION m)
-        set(_MANIFEST_VALUE ${_add_jar_MANIFEST})
+        get_filename_component (_MANIFEST_VALUE "${_add_jar_MANIFEST}" ABSOLUTE)
     endif ()
 
     if (LIBRARY_OUTPUT_PATH)
@@ -1212,7 +1212,7 @@ function (create_javah)
 
     set (_output_files)
     if (WIN32 AND NOT CYGWIN AND CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
-      set(_classpath_sep ";")
+      set(_classpath_sep "$<SEMICOLON>")
     else ()
       set(_classpath_sep ":")
     endif()
@@ -1242,7 +1242,7 @@ function (create_javah)
         endif()
       endforeach()
       string (REPLACE ";" "${_classpath_sep}" _classpath "${_classpath}")
-      list (APPEND _javah_options -classpath ${_classpath})
+      list (APPEND _javah_options -classpath "${_classpath}")
     endif()
 
     if (_create_javah_OUTPUT_DIR)
diff --git a/Packaging/CMakeDMGBackground.tif b/Packaging/CMakeDMGBackground.tif
new file mode 100644
index 0000000..91c4b13
Binary files /dev/null and b/Packaging/CMakeDMGBackground.tif differ
diff --git a/Packaging/CMakeDMGSetup.scpt b/Packaging/CMakeDMGSetup.scpt
new file mode 100644
index 0000000..c7ddcfb
--- /dev/null
+++ b/Packaging/CMakeDMGSetup.scpt
@@ -0,0 +1,42 @@
+on run argv
+  set image_name to item 1 of argv
+
+  tell application "Finder"
+  tell disk image_name
+
+    -- open the image the first time and save a DS_Store with just
+    -- background and icon setup
+    open
+      set current view of container window to icon view
+      set theViewOptions to the icon view options of container window
+      set background picture of theViewOptions to file ".background:background.tif"
+      set arrangement of theViewOptions to not arranged
+      set icon size of theViewOptions to 128
+      delay 1
+    close
+
+    -- next setup the position of the app and Applications symlink
+    -- plus hide all the window decoration
+    open
+      update without registering applications
+      tell container window
+        set sidebar width to 0
+        set statusbar visible to false
+        set toolbar visible to false
+        set the bounds to { 400, 100, 900, 465 }
+        set position of item "CMake.app" to { 133, 200 }
+        set position of item "Applications" to { 378, 200 }
+      end tell
+      update without registering applications
+      delay 1
+    close
+
+    -- one last open and close so you can see everything looks correct
+    open
+      delay 5
+    close
+
+  end tell
+  delay 1
+end tell
+end run
diff --git a/README.rst b/README.rst
index 5e7a323..9599a04 100644
--- a/README.rst
+++ b/README.rst
@@ -46,7 +46,7 @@ UNIX/Mac OSX/MinGW/MSYS/Cygwin
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 You need to have a compiler and a make installed.
-Run the ``bootstrap`` script you find the in the source directory of CMake.
+Run the ``bootstrap`` script you find in the source directory of CMake.
 You can use the ``--help`` option to see the supported options.
 You may use the ``--prefix=<install_prefix>`` option to specify a custom
 installation directory for CMake. You can run the ``bootstrap`` script from
diff --git a/Source/CMakeInstallDestinations.cmake b/Source/CMakeInstallDestinations.cmake
index 99c86ca..2f9d95a 100644
--- a/Source/CMakeInstallDestinations.cmake
+++ b/Source/CMakeInstallDestinations.cmake
@@ -3,24 +3,29 @@ if(BEOS)
   set(CMAKE_DATA_DIR_DEFAULT "share/cmake-${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}") # HAIKU
   set(CMAKE_MAN_DIR_DEFAULT "documentation/man") # HAIKU
   set(CMAKE_DOC_DIR_DEFAULT "documentation/doc/cmake-${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}") # HAIKU
+  set(CMAKE_XDGDATA_DIR_DEFAULT "share") # HAIKU
 elseif(CYGWIN)
   set(CMAKE_DATA_DIR_DEFAULT "share/cmake-${CMake_VERSION}") # CYGWIN
   set(CMAKE_DOC_DIR_DEFAULT "share/doc/cmake-${CMake_VERSION}") # CYGWIN
   set(CMAKE_MAN_DIR_DEFAULT "share/man") # CYGWIN
+  set(CMAKE_XDGDATA_DIR_DEFAULT "share") # CYGWIN
 else()
   set(CMAKE_DATA_DIR_DEFAULT "share/cmake-${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}") # OTHER
   set(CMAKE_DOC_DIR_DEFAULT "doc/cmake-${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}") # OTHER
   set(CMAKE_MAN_DIR_DEFAULT "man") # OTHER
+  set(CMAKE_XDGDATA_DIR_DEFAULT "share") # OTHER
 endif()
 
 set(CMAKE_DATA_DIR_DESC "data")
 set(CMAKE_DOC_DIR_DESC "docs")
 set(CMAKE_MAN_DIR_DESC "man pages")
+set(CMAKE_XDGDATA_DIR_DESC "XDG specific files")
 
 foreach(v
     CMAKE_DATA_DIR
     CMAKE_DOC_DIR
     CMAKE_MAN_DIR
+    CMAKE_XDGDATA_DIR
     )
   # Populate the cache with empty values so we know when the user sets them.
   set(${v} "" CACHE STRING "")
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index ae5b03f..ab70568 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -299,8 +299,6 @@ set(SRCS
   cmLocalUnixMakefileGenerator3.cxx
   cmLocale.h
   ${MACH_SRCS}
-  cmMakeDepend.cxx
-  cmMakeDepend.h
   cmMakefile.cxx
   cmMakefile.h
   cmMakefileTargetGenerator.cxx
@@ -548,6 +546,19 @@ foreach(v CURL_CA_BUNDLE CURL_CA_PATH)
   endif()
 endforeach()
 
+foreach(check
+    STAT_HAS_ST_MTIM
+    STAT_HAS_ST_MTIMESPEC
+    )
+  if(KWSYS_CXX_${check}_COMPILED) # abuse KWSys check cache entry
+    set(CMake_${check} 1)
+  else()
+    set(CMake_${check} 0)
+  endif()
+  set_property(SOURCE cmFileTimeComparison.cxx APPEND PROPERTY
+    COMPILE_DEFINITIONS CMake_${check}=${CMake_${check}})
+endforeach()
+
 # create a library used by the command line and the GUI
 add_library(CMakeLib ${SRCS})
 target_link_libraries(CMakeLib cmsys
@@ -555,6 +566,7 @@ target_link_libraries(CMakeLib cmsys
   ${CMAKE_TAR_LIBRARIES} ${CMAKE_COMPRESS_LIBRARIES}
   ${CMAKE_CURL_LIBRARIES}
   ${CMAKE_JSONCPP_LIBRARIES}
+  ${CMake_KWIML_LIBRARIES}
   )
 
 # On Apple we need CoreFoundation
@@ -715,6 +727,9 @@ endif()
 # Build CPackLib
 add_library(CPackLib ${CPACK_SRCS})
 target_link_libraries(CPackLib CMakeLib)
+if(APPLE)
+  target_link_libraries(CPackLib "-framework Carbon")
+endif()
 
 if(APPLE)
   add_executable(cmakexbuild cmakexbuild.cxx)
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index 5717d37..129a882 100644
--- a/Source/CMakeVersion.cmake
+++ b/Source/CMakeVersion.cmake
@@ -1,5 +1,5 @@
 # CMake version number components.
 set(CMake_VERSION_MAJOR 3)
-set(CMake_VERSION_MINOR 4)
-set(CMake_VERSION_PATCH 1)
+set(CMake_VERSION_MINOR 5)
+set(CMake_VERSION_PATCH 0)
 #set(CMake_VERSION_RC 0)
diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.cxx b/Source/CPack/IFW/cmCPackIFWGenerator.cxx
index 43d34ee..4eb23c1 100644
--- a/Source/CPack/IFW/cmCPackIFWGenerator.cxx
+++ b/Source/CPack/IFW/cmCPackIFWGenerator.cxx
@@ -24,7 +24,6 @@
 #include <cmsys/RegularExpression.hxx>
 
 #include <cmGlobalGenerator.h>
-#include <cmLocalGenerator.h>
 #include <cmSystemTools.h>
 #include <cmMakefile.h>
 #include <cmGeneratedFileStream.h>
diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
index 6f25e50..ece327a 100644
--- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx
+++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
@@ -242,7 +242,16 @@ bool cmCPackWIXGenerator::InitializeWiXConfiguration()
   const char* patchFilePath = GetOption("CPACK_WIX_PATCH_FILE");
   if(patchFilePath)
     {
-    this->Patch->LoadFragments(patchFilePath);
+    std::vector<std::string> patchFilePaths;
+    cmSystemTools::ExpandListArgument(patchFilePath, patchFilePaths);
+
+    for(size_t i = 0; i < patchFilePaths.size(); ++i)
+      {
+      if(!this->Patch->LoadFragments(patchFilePaths[i]))
+        {
+        return false;
+        }
+      }
     }
 
   return true;
@@ -482,6 +491,7 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles()
   featureDefinitions.BeginElement("Feature");
   featureDefinitions.AddAttribute("Id", "ProductFeature");
   featureDefinitions.AddAttribute("Display", "expand");
+  featureDefinitions.AddAttribute("Absent", "disallow");
   featureDefinitions.AddAttribute("ConfigurableDirectory", "INSTALL_ROOT");
 
   std::string cpackPackageName;
@@ -816,6 +826,8 @@ bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType(
   fileDefinitions.AddAttribute("Id", componentId);
   fileDefinitions.AddAttribute("Guid", "*");
 
+  this->Patch->ApplyFragment(componentId, fileDefinitions);
+
   std::string registryKey = std::string("Software\\") +
     cpackVendor + "\\" + cpackPackageName;
 
@@ -910,8 +922,9 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons(
     relativeDirectoryPath = ".";
     }
 
-  cmInstalledFile const* directoryInstalledFile =
-    this->GetInstalledFile(relativeDirectoryPath);
+  cmInstalledFile const* directoryInstalledFile = this->GetInstalledFile(
+      this->RelativePathWithoutComponentPrefix(relativeDirectoryPath)
+  );
 
   bool emptyDirectory = dir.GetNumberOfFiles() == 2;
   bool createDirectory = false;
@@ -979,8 +992,9 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons(
       }
     else
       {
-      cmInstalledFile const* installedFile =
-        this->GetInstalledFile(relativePath);
+      cmInstalledFile const* installedFile = this->GetInstalledFile(
+        this->RelativePathWithoutComponentPrefix(relativePath)
+      );
 
       if(installedFile)
         {
@@ -1229,3 +1243,16 @@ void cmCPackWIXGenerator::AddCustomFlags(
       stream << " " << QuotePath(*i);
     }
 }
+
+std::string cmCPackWIXGenerator::RelativePathWithoutComponentPrefix(
+  std::string const& path)
+{
+  if(this->Components.empty())
+    {
+    return path;
+    }
+
+  std::string::size_type pos = path.find('/');
+
+  return path.substr(pos + 1);
+}
diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.h b/Source/CPack/WiX/cmCPackWIXGenerator.h
index d501609..3f66b2c 100644
--- a/Source/CPack/WiX/cmCPackWIXGenerator.h
+++ b/Source/CPack/WiX/cmCPackWIXGenerator.h
@@ -168,6 +168,9 @@ private:
   void AddCustomFlags(
     std::string const& variableName, std::ostream& stream);
 
+  std::string RelativePathWithoutComponentPrefix(
+    std::string const& path);
+
   std::vector<std::string> WixSources;
   id_map_t PathToIdMap;
   ambiguity_map_t IdAmbiguityCounter;
diff --git a/Source/CPack/WiX/cmWIXPatch.cxx b/Source/CPack/WiX/cmWIXPatch.cxx
index 5a8dc63..07375da 100644
--- a/Source/CPack/WiX/cmWIXPatch.cxx
+++ b/Source/CPack/WiX/cmWIXPatch.cxx
@@ -20,10 +20,18 @@ cmWIXPatch::cmWIXPatch(cmCPackLog* logger):
 
 }
 
-void cmWIXPatch::LoadFragments(std::string const& patchFilePath)
+bool cmWIXPatch::LoadFragments(std::string const& patchFilePath)
 {
   cmWIXPatchParser parser(Fragments, Logger);
-  parser.ParseFile(patchFilePath.c_str());
+  if(!parser.ParseFile(patchFilePath.c_str()))
+    {
+    cmCPackLogger(cmCPackLog::LOG_ERROR,
+      "Failed parsing XML patch file: '" <<
+      patchFilePath << "'" << std::endl);
+    return false;
+    }
+
+  return true;
 }
 
 void cmWIXPatch::ApplyFragment(
@@ -33,13 +41,30 @@ void cmWIXPatch::ApplyFragment(
   if(i == Fragments.end()) return;
 
   const cmWIXPatchElement& fragment = i->second;
+
+  this->ApplyElementChildren(fragment, writer);
+
+  Fragments.erase(i);
+}
+
+void cmWIXPatch::ApplyElementChildren(
+  const cmWIXPatchElement& element, cmWIXSourceWriter& writer)
+{
   for(cmWIXPatchElement::child_list_t::const_iterator
-    j = fragment.children.begin(); j != fragment.children.end(); ++j)
+    j = element.children.begin(); j != element.children.end(); ++j)
+  {
+  cmWIXPatchNode *node = *j;
+
+  switch(node->type())
     {
-    ApplyElement(**j, writer);
+    case cmWIXPatchNode::ELEMENT:
+      ApplyElement(dynamic_cast<const cmWIXPatchElement&>(*node), writer);
+      break;
+    case cmWIXPatchNode::TEXT:
+      writer.AddTextNode(dynamic_cast<const cmWIXPatchText&>(*node).text);
+      break;
     }
-
-  Fragments.erase(i);
+  }
 }
 
 void cmWIXPatch::ApplyElement(
@@ -53,16 +78,11 @@ void cmWIXPatch::ApplyElement(
     writer.AddAttribute(i->first, i->second);
     }
 
-  for(cmWIXPatchElement::child_list_t::const_iterator
-    i = element.children.begin(); i != element.children.end(); ++i)
-    {
-    ApplyElement(**i, writer);
-    }
+  this->ApplyElementChildren(element, writer);
 
   writer.EndElement(element.name);
 }
 
-
 bool cmWIXPatch::CheckForUnappliedFragments()
 {
   std::string fragmentList;
diff --git a/Source/CPack/WiX/cmWIXPatch.h b/Source/CPack/WiX/cmWIXPatch.h
index 7b7b2f1..2f31a01 100644
--- a/Source/CPack/WiX/cmWIXPatch.h
+++ b/Source/CPack/WiX/cmWIXPatch.h
@@ -26,13 +26,16 @@ class cmWIXPatch
 public:
   cmWIXPatch(cmCPackLog* logger);
 
-  void LoadFragments(std::string const& patchFilePath);
+  bool LoadFragments(std::string const& patchFilePath);
 
   void ApplyFragment(std::string const& id, cmWIXSourceWriter& writer);
 
   bool CheckForUnappliedFragments();
 
 private:
+  void ApplyElementChildren(const cmWIXPatchElement& element,
+    cmWIXSourceWriter& writer);
+
   void ApplyElement(const cmWIXPatchElement& element,
     cmWIXSourceWriter& writer);
 
diff --git a/Source/CPack/WiX/cmWIXPatchParser.cxx b/Source/CPack/WiX/cmWIXPatchParser.cxx
index e066c28..14c5413 100644
--- a/Source/CPack/WiX/cmWIXPatchParser.cxx
+++ b/Source/CPack/WiX/cmWIXPatchParser.cxx
@@ -16,6 +16,21 @@
 
 #include <cm_expat.h>
 
+cmWIXPatchNode::Type cmWIXPatchText::type()
+{
+  return cmWIXPatchNode::TEXT;
+}
+
+cmWIXPatchNode::Type cmWIXPatchElement::type()
+{
+  return cmWIXPatchNode::ELEMENT;
+}
+
+cmWIXPatchNode::~cmWIXPatchNode()
+{
+
+}
+
 cmWIXPatchElement::~cmWIXPatchElement()
 {
   for(child_list_t::iterator i = children.begin(); i != children.end(); ++i)
@@ -63,20 +78,20 @@ void cmWIXPatchParser::StartElement(const std::string& name, const char **atts)
     {
       cmWIXPatchElement &parent = *ElementStack.back();
 
-      parent.children.resize(parent.children.size() + 1);
-      cmWIXPatchElement*& currentElement = parent.children.back();
-      currentElement = new cmWIXPatchElement;
-      currentElement->name = name;
+      cmWIXPatchElement *element = new cmWIXPatchElement;
+      parent.children.push_back(element);
+
+      element->name = name;
 
       for(size_t i = 0; atts[i]; i += 2)
         {
         std::string key = atts[i];
         std::string value = atts[i+1];
 
-        currentElement->attributes[key] = value;
+        element->attributes[key] = value;
         }
 
-      ElementStack.push_back(currentElement);
+      ElementStack.push_back(element);
     }
 }
 
@@ -117,11 +132,34 @@ void cmWIXPatchParser::EndElement(const std::string& name)
         }
       else
         {
-          ElementStack.pop_back();
+        ElementStack.pop_back();
         }
     }
 }
 
+void cmWIXPatchParser::CharacterDataHandler(const char* data, int length)
+{
+  const char* whitespace = "\x20\x09\x0d\x0a";
+
+  if(State == INSIDE_FRAGMENT)
+    {
+    cmWIXPatchElement &parent = *ElementStack.back();
+
+    std::string text(data, length);
+
+    std::string::size_type first = text.find_first_not_of(whitespace);
+    std::string::size_type last = text.find_last_not_of(whitespace);
+
+    if(first != std::string::npos && last != std::string::npos)
+      {
+      cmWIXPatchText *text_node = new cmWIXPatchText;
+      text_node->text = text.substr(first, last - first + 1);
+
+      parent.children.push_back(text_node);
+      }
+    }
+}
+
 void cmWIXPatchParser::ReportError(int line, int column, const char* msg)
 {
   cmCPackLogger(cmCPackLog::LOG_ERROR,
diff --git a/Source/CPack/WiX/cmWIXPatchParser.h b/Source/CPack/WiX/cmWIXPatchParser.h
index acfb4c0..acaeae3 100644
--- a/Source/CPack/WiX/cmWIXPatchParser.h
+++ b/Source/CPack/WiX/cmWIXPatchParser.h
@@ -20,11 +20,33 @@
 #include <map>
 #include <list>
 
-struct cmWIXPatchElement
+struct cmWIXPatchNode
 {
+  enum Type
+  {
+    TEXT,
+    ELEMENT
+  };
+
+  virtual ~cmWIXPatchNode();
+
+  virtual Type type() = 0;
+};
+
+struct cmWIXPatchText : public cmWIXPatchNode
+{
+  virtual Type type();
+
+  std::string text;
+};
+
+struct cmWIXPatchElement : cmWIXPatchNode
+{
+  virtual Type type();
+
   ~cmWIXPatchElement();
 
-  typedef std::list<cmWIXPatchElement*> child_list_t;
+  typedef std::list<cmWIXPatchNode*> child_list_t;
   typedef std::map<std::string, std::string> attributes_t;
 
   std::string name;
@@ -48,6 +70,9 @@ private:
   void StartFragment(const char **attributes);
 
   virtual void EndElement(const std::string& name);
+
+  virtual void CharacterDataHandler(const char* data, int length);
+
   virtual void ReportError(int line, int column, const char* msg);
 
   void ReportValidationError(std::string const& message);
diff --git a/Source/CPack/WiX/cmWIXSourceWriter.cxx b/Source/CPack/WiX/cmWIXSourceWriter.cxx
index 8d38e9b..63acb27 100644
--- a/Source/CPack/WiX/cmWIXSourceWriter.cxx
+++ b/Source/CPack/WiX/cmWIXSourceWriter.cxx
@@ -102,6 +102,25 @@ void cmWIXSourceWriter::EndElement(std::string const& name)
   State = DEFAULT;
 }
 
+void cmWIXSourceWriter::AddTextNode(std::string const& text)
+{
+  if(State == BEGIN)
+    {
+    File << ">";
+    }
+
+  if(Elements.empty())
+    {
+    cmCPackLogger(cmCPackLog::LOG_ERROR,
+      "can not add text without open WiX element in '" <<
+      SourceFilename << "'" << std::endl);
+    return;
+    }
+
+  File << this->EscapeAttributeValue(text);
+  State = DEFAULT;
+}
+
 void cmWIXSourceWriter::AddProcessingInstruction(
   std::string const& target, std::string const& content)
 {
diff --git a/Source/CPack/WiX/cmWIXSourceWriter.h b/Source/CPack/WiX/cmWIXSourceWriter.h
index 3b9999c..9e303f0 100644
--- a/Source/CPack/WiX/cmWIXSourceWriter.h
+++ b/Source/CPack/WiX/cmWIXSourceWriter.h
@@ -34,6 +34,8 @@ public:
 
   void EndElement(std::string const& name);
 
+  void AddTextNode(std::string const& text);
+
   void AddProcessingInstruction(
     std::string const& target, std::string const& content);
 
diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx
index 70de757..db985db 100644
--- a/Source/CPack/cmCPackArchiveGenerator.cxx
+++ b/Source/CPack/cmCPackArchiveGenerator.cxx
@@ -14,7 +14,6 @@
 
 #include "cmake.h"
 #include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmSystemTools.h"
 #include "cmMakefile.h"
 #include "cmGeneratedFileStream.h"
diff --git a/Source/CPack/cmCPackCygwinBinaryGenerator.cxx b/Source/CPack/cmCPackCygwinBinaryGenerator.cxx
index 6605f16..1f905c0 100644
--- a/Source/CPack/cmCPackCygwinBinaryGenerator.cxx
+++ b/Source/CPack/cmCPackCygwinBinaryGenerator.cxx
@@ -14,7 +14,6 @@
 
 #include "cmake.h"
 #include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmSystemTools.h"
 #include "cmMakefile.h"
 #include "cmGeneratedFileStream.h"
diff --git a/Source/CPack/cmCPackCygwinSourceGenerator.cxx b/Source/CPack/cmCPackCygwinSourceGenerator.cxx
index f1e8539..f5cb53c 100644
--- a/Source/CPack/cmCPackCygwinSourceGenerator.cxx
+++ b/Source/CPack/cmCPackCygwinSourceGenerator.cxx
@@ -14,7 +14,6 @@
 
 #include "cmake.h"
 #include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmSystemTools.h"
 #include "cmMakefile.h"
 #include "cmGeneratedFileStream.h"
diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx
index 04efb71..13c8d8f 100644
--- a/Source/CPack/cmCPackDebGenerator.cxx
+++ b/Source/CPack/cmCPackDebGenerator.cxx
@@ -339,6 +339,9 @@ int cmCPackDebGenerator::createDeb()
       this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_PROVIDES");
   const char* debian_pkg_replaces =
       this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_REPLACES");
+  const char* debian_pkg_source =
+      this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SOURCE");
+
 
     { // the scope is needed for cmGeneratedFileStream
     cmGeneratedFileStream out(ctlfilename.c_str());
@@ -347,6 +350,10 @@ int cmCPackDebGenerator::createDeb()
     out << "Section: " << debian_pkg_section << "\n";
     out << "Priority: " << debian_pkg_priority << "\n";
     out << "Architecture: " << debian_pkg_arch << "\n";
+    if(debian_pkg_source && *debian_pkg_source)
+      {
+      out << "Source: " << debian_pkg_source << "\n";
+      }
     if(debian_pkg_dep && *debian_pkg_dep)
       {
       out << "Depends: " << debian_pkg_dep << "\n";
diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx
index 4c400d9..7b94ca3 100644
--- a/Source/CPack/cmCPackDragNDropGenerator.cxx
+++ b/Source/CPack/cmCPackDragNDropGenerator.cxx
@@ -18,6 +18,24 @@
 #include <cmsys/RegularExpression.hxx>
 #include <cmsys/FStream.hxx>
 
+#include <iomanip>
+
+#include <CoreFoundation/CFBase.h>
+#include <CoreFoundation/CFString.h>
+#include <CoreFoundation/CFLocale.h>
+
+// The carbon framework is deprecated, but the Region codes it supplies are
+// needed for the LPic data structure used for generating multi-lingual SLAs.
+// There does not seem to be a replacement API for these region codes.
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+#include <Carbon/Carbon.h>
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+
 static const char* SLAHeader =
 "data 'LPic' (5000) {\n"
 "    $\"0002 0011 0003 0001 0000 0000 0002 0000\"\n"
@@ -51,6 +69,7 @@ static const char* SLASTREnglish =
 
 //----------------------------------------------------------------------
 cmCPackDragNDropGenerator::cmCPackDragNDropGenerator()
+  : singleLicense(false)
 {
   // default to one package file for components
   this->componentPackageMethod = ONE_PACKAGE;
@@ -103,6 +122,70 @@ int cmCPackDragNDropGenerator::InitializeInternal()
     }
   this->SetOptionIfNotSet("CPACK_COMMAND_REZ", rez_path.c_str());
 
+  if(this->IsSet("CPACK_DMG_SLA_DIR"))
+    {
+    slaDirectory = this->GetOption("CPACK_DMG_SLA_DIR");
+    if(!slaDirectory.empty() && this->IsSet("CPACK_RESOURCE_FILE_LICENSE"))
+      {
+      std::string license_file =
+        this->GetOption("CPACK_RESOURCE_FILE_LICENSE");
+      if(!license_file.empty() &&
+         (license_file.find("CPack.GenericLicense.txt") == std::string::npos))
+        {
+        cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+          "Both CPACK_DMG_SLA_DIR and CPACK_RESOURCE_FILE_LICENSE specified, "
+          "using CPACK_RESOURCE_FILE_LICENSE as a license for all languages."
+          << std::endl);
+        singleLicense = true;
+        }
+      }
+    if(!this->IsSet("CPACK_DMG_SLA_LANGUAGES"))
+      {
+      cmCPackLogger(cmCPackLog::LOG_ERROR,
+        "CPACK_DMG_SLA_DIR set but no languages defined "
+        "(set CPACK_DMG_SLA_LANGUAGES)"
+        << std::endl);
+      return 0;
+      }
+    if(!cmSystemTools::FileExists(slaDirectory, false))
+      {
+      cmCPackLogger(cmCPackLog::LOG_ERROR,
+        "CPACK_DMG_SLA_DIR does not exist"
+        << std::endl);
+      return 0;
+      }
+
+    std::vector<std::string> languages;
+    cmSystemTools::ExpandListArgument(
+      this->GetOption("CPACK_DMG_SLA_LANGUAGES"), languages);
+    if(languages.empty())
+      {
+      cmCPackLogger(cmCPackLog::LOG_ERROR,
+        "CPACK_DMG_SLA_LANGUAGES set but empty"
+        << std::endl);
+      return 0;
+      }
+    for(size_t i = 0; i < languages.size(); ++i)
+      {
+      std::string license = slaDirectory + "/" + languages[i] + ".license.txt";
+      if (!singleLicense && !cmSystemTools::FileExists(license))
+        {
+        cmCPackLogger(cmCPackLog::LOG_ERROR,
+          "Missing license file " << languages[i] << ".license.txt"
+          << std::endl);
+        return 0;
+        }
+      std::string menu = slaDirectory + "/" + languages[i] + ".menu.txt";
+      if (!cmSystemTools::FileExists(menu))
+        {
+        cmCPackLogger(cmCPackLog::LOG_ERROR,
+          "Missing menu file " << languages[i] << ".menu.txt"
+          << std::endl);
+        return 0;
+        }
+      }
+    }
+
   return this->Superclass::InitializeInternal();
 }
 
@@ -190,6 +273,28 @@ bool cmCPackDragNDropGenerator::CopyFile(std::ostringstream& source,
 }
 
 //----------------------------------------------------------------------
+bool cmCPackDragNDropGenerator::CreateEmptyFile(std::ostringstream& target,
+                                                size_t size)
+{
+  cmsys::ofstream fout(target.str().c_str(),
+                       std::ios::out | std::ios::binary);
+  if(!fout)
+    {
+    return false;
+    }
+  else
+    {
+    // Seek to desired size - 1 byte
+    fout.seekp(size - 1, std::ios_base::beg);
+    char byte = 0;
+    // Write one byte to ensure file grows
+    fout.write(&byte, 1);
+    }
+
+  return true;
+}
+
+//----------------------------------------------------------------------
 bool cmCPackDragNDropGenerator::RunCommand(std::ostringstream& command,
   std::string* output)
 {
@@ -246,12 +351,27 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
     this->GetOption("CPACK_DMG_DS_STORE")
     ? this->GetOption("CPACK_DMG_DS_STORE") : "";
 
+  const std::string cpack_dmg_languages =
+    this->GetOption("CPACK_DMG_SLA_LANGUAGES")
+      ? this->GetOption("CPACK_DMG_SLA_LANGUAGES") : "";
+
+  const std::string cpack_dmg_ds_store_setup_script =
+    this->GetOption("CPACK_DMG_DS_STORE_SETUP_SCRIPT")
+    ? this->GetOption("CPACK_DMG_DS_STORE_SETUP_SCRIPT") : "";
+
   // only put license on dmg if is user provided
   if(!cpack_license_file.empty() &&
       cpack_license_file.find("CPack.GenericLicense.txt") != std::string::npos)
-  {
+    {
+    cpack_license_file = "";
+    }
+
+  // use sla_dir if both sla_dir and license_file are set
+  if(!cpack_license_file.empty() &&
+     !slaDirectory.empty() && !singleLicense)
+    {
     cpack_license_file = "";
-  }
+    }
 
   // The staging directory contains everything that will end-up inside the
   // final disk image ...
@@ -307,13 +427,18 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
     }
 
   // Optionally add a custom background image ...
+  // Make sure the background file type is the same as the custom image
+  // and that the file is hidden so it doesn't show up.
   if(!cpack_dmg_background_image.empty())
     {
+    const std::string extension =
+        cmSystemTools::GetFilenameLastExtension(cpack_dmg_background_image);
     std::ostringstream package_background_source;
     package_background_source << cpack_dmg_background_image;
 
     std::ostringstream package_background_destination;
-    package_background_destination << staging.str() << "/background.png";
+    package_background_destination << staging.str()
+                                   << "/.background/background" << extension;
 
     if(!this->CopyFile(package_background_source,
         package_background_destination))
@@ -325,18 +450,22 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
 
       return 0;
       }
+    }
 
-    std::ostringstream temp_background_hiding_command;
-    temp_background_hiding_command << this->GetOption("CPACK_COMMAND_SETFILE");
-    temp_background_hiding_command << " -a V \"";
-    temp_background_hiding_command << package_background_destination.str();
-    temp_background_hiding_command << "\"";
+  bool remount_image = !cpack_package_icon.empty() ||
+                       !cpack_dmg_ds_store_setup_script.empty();
 
-    if(!this->RunCommand(temp_background_hiding_command))
+  // Create 1 MB dummy padding file in staging area when we need to remount
+  // image, so we have enough space for storing changes ...
+  if(remount_image)
+    {
+    std::ostringstream dummy_padding;
+    dummy_padding << staging.str() << "/.dummy-padding-file";
+    if(!this->CreateEmptyFile(dummy_padding, 1048576))
       {
-        cmCPackLogger(cmCPackLog::LOG_ERROR,
-          "Error setting attributes on disk volume background image."
-          << std::endl);
+      cmCPackLogger(cmCPackLog::LOG_ERROR,
+        "Error creating dummy padding file."
+        << std::endl);
 
       return 0;
       }
@@ -365,10 +494,11 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
     return 0;
     }
 
-  // Optionally set the custom icon flag for the image ...
-  if(!cpack_package_icon.empty())
+  if(remount_image)
     {
-    std::ostringstream temp_mount;
+    // Store that we have a failure so that we always unmount the image
+    // before we exit.
+    bool had_error = false;
 
     std::ostringstream attach_command;
     attach_command << this->GetOption("CPACK_COMMAND_HDIUTIL");
@@ -387,20 +517,57 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
 
     cmsys::RegularExpression mountpoint_regex(".*(/Volumes/[^\n]+)\n.*");
     mountpoint_regex.find(attach_output.c_str());
+    std::ostringstream temp_mount;
     temp_mount << mountpoint_regex.match(1);
 
-    std::ostringstream setfile_command;
-    setfile_command << this->GetOption("CPACK_COMMAND_SETFILE");
-    setfile_command << " -a C";
-    setfile_command << " \"" << temp_mount.str() << "\"";
-
-    if(!this->RunCommand(setfile_command))
+    // Remove dummy padding file so we have enough space on RW image ...
+    std::ostringstream dummy_padding;
+    dummy_padding << temp_mount.str() << "/.dummy-padding-file";
+    if(!cmSystemTools::RemoveFile(dummy_padding.str()))
       {
       cmCPackLogger(cmCPackLog::LOG_ERROR,
-        "Error assigning custom icon to temporary disk image."
+        "Error removing dummy padding file."
         << std::endl);
 
-      return 0;
+      had_error = true;
+      }
+
+    // Optionally set the custom icon flag for the image ...
+    if(!had_error && !cpack_package_icon.empty())
+      {
+      std::ostringstream setfile_command;
+      setfile_command << this->GetOption("CPACK_COMMAND_SETFILE");
+      setfile_command << " -a C";
+      setfile_command << " \"" << temp_mount.str() << "\"";
+
+      if(!this->RunCommand(setfile_command))
+        {
+        cmCPackLogger(cmCPackLog::LOG_ERROR,
+          "Error assigning custom icon to temporary disk image."
+          << std::endl);
+
+        had_error = true;
+        }
+      }
+
+    // Optionally we can execute a custom apple script to generate
+    // the .DS_Store for the volume folder ...
+    if(!had_error && !cpack_dmg_ds_store_setup_script.empty())
+      {
+      std::ostringstream setup_script_command;
+      setup_script_command << "osascript"
+                           << " \"" << cpack_dmg_ds_store_setup_script << "\""
+                           << " \"" << cpack_dmg_volume_name << "\"";
+      std::string error;
+      if(!this->RunCommand(setup_script_command, &error))
+        {
+        cmCPackLogger(cmCPackLog::LOG_ERROR,
+          "Error executing custom script on disk image." << std::endl
+          << error
+          << std::endl);
+
+        had_error = true;
+        }
       }
 
     std::ostringstream detach_command;
@@ -416,56 +583,158 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
 
       return 0;
       }
+
+    if(had_error)
+      {
+      return 0;
+      }
     }
 
-  if(!cpack_license_file.empty())
-  {
+  if(!cpack_license_file.empty() || !slaDirectory.empty())
+    {
+    // Use old hardcoded style if sla_dir is not set
+    bool oldStyle = slaDirectory.empty();
     std::string sla_r = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
     sla_r += "/sla.r";
 
-    cmsys::ifstream ifs;
-    ifs.open(cpack_license_file.c_str());
-    if(ifs.is_open())
-    {
-      cmGeneratedFileStream osf(sla_r.c_str());
-      osf << "#include <CoreServices/CoreServices.r>\n\n";
-      osf << SLAHeader;
-      osf << "\n";
-      osf << "data 'TEXT' (5002, \"English\") {\n";
-      while(ifs.good())
+    std::vector<std::string> languages;
+    if(!oldStyle)
       {
-        std::string line;
-        std::getline(ifs, line);
-        // escape quotes
-        std::string::size_type pos = line.find('\"');
-        while(pos != std::string::npos)
+      cmSystemTools::ExpandListArgument(cpack_dmg_languages, languages);
+      }
+
+    cmGeneratedFileStream ofs(sla_r.c_str());
+    ofs << "#include <CoreServices/CoreServices.r>\n\n";
+    if(oldStyle)
+      {
+      ofs << SLAHeader;
+      ofs << "\n";
+      }
+    else
+      {
+      /*
+       * LPic Layout
+       * (https://github.com/pypt/dmg-add-license/blob/master/main.c)
+       * as far as I can tell (no official documentation seems to exist):
+       * struct LPic {
+       *  uint16_t default_language; // points to a resid, defaulting to 0,
+       *                             // which is the first set language
+       *  uint16_t length;
+       *  struct {
+       *    uint16_t language_code;
+       *    uint16_t resid;
+       *    uint16_t encoding; // Encoding from TextCommon.h,
+       *                       // forcing MacRoman (0) for now. Might need to
+       *                       // allow overwrite per license by user later
+       *  } item[1];
+       * }
+       */
+
+      // Create vector first for readability, then iterate to write to ofs
+      std::vector<uint16_t> header_data;
+      header_data.push_back(0);
+      header_data.push_back(languages.size());
+      for(size_t i = 0; i < languages.size(); ++i)
         {
-          line.replace(pos, 1, "\\\"");
-          pos = line.find('\"', pos+2);
+        CFStringRef language_cfstring = CFStringCreateWithCString(
+          NULL, languages[i].c_str(), kCFStringEncodingUTF8);
+        CFStringRef iso_language =
+          CFLocaleCreateCanonicalLanguageIdentifierFromString(
+            NULL, language_cfstring);
+        if (!iso_language)
+          {
+          cmCPackLogger(cmCPackLog::LOG_ERROR,
+            languages[i] << " is not a recognized language"
+            << std::endl);
+          }
+        char *iso_language_cstr = (char *) malloc(65);
+        CFStringGetCString(iso_language, iso_language_cstr, 64,
+                           kCFStringEncodingMacRoman);
+        LangCode lang = 0;
+        RegionCode region = 0;
+        OSStatus err = LocaleStringToLangAndRegionCodes(iso_language_cstr,
+                                                        &lang, &region);
+        if (err != noErr)
+          {
+          cmCPackLogger(cmCPackLog::LOG_ERROR,
+            "No language/region code available for " << iso_language_cstr
+            << std::endl);
+          free(iso_language_cstr);
+          return 0;
+          }
+        free(iso_language_cstr);
+        header_data.push_back(region);
+        header_data.push_back(i);
+        header_data.push_back(0);
         }
-        // break up long lines to avoid Rez errors
-        std::vector<std::string> lines;
-        const size_t max_line_length = 512;
-        for(size_t i=0; i<line.size(); i+= max_line_length)
+      ofs << "data 'LPic' (5000) {\n";
+      ofs << std::hex << std::uppercase << std::setfill('0');
+
+      for(size_t i = 0; i < header_data.size(); ++i)
+        {
+        if(i % 8 == 0)
           {
-          int line_length = max_line_length;
-          if(i+max_line_length > line.size())
-            line_length = line.size()-i;
-          lines.push_back(line.substr(i, line_length));
+          ofs << "    $\"";
           }
 
-        for(size_t i=0; i<lines.size(); i++)
+        ofs << std::setw(4) << header_data[i];
+
+        if(i % 8 == 7 || i == header_data.size() - 1)
+          {
+          ofs << "\"\n";
+          }
+        else
           {
-          osf << "        \"" << lines[i] << "\"\n";
+          ofs << " ";
           }
-        osf << "        \"\\n\"\n";
+        }
+      ofs << "};\n\n";
+      // Reset ofs options
+      ofs << std::dec << std::nouppercase << std::setfill(' ');
+      }
+
+    bool have_write_license_error = false;
+    std::string error;
+
+    if(oldStyle)
+      {
+      if(!this->WriteLicense(ofs, 0, "", cpack_license_file, &error))
+        {
+        have_write_license_error = true;
+        }
+      }
+    else
+      {
+      for(size_t i = 0; i < languages.size() && !have_write_license_error; ++i)
+        {
+        if(singleLicense)
+          {
+          if(!this->WriteLicense(ofs, i + 5000, languages[i],
+                                 cpack_license_file, &error))
+            {
+            have_write_license_error = true;
+            }
+          }
+        else
+          {
+          if(!this->WriteLicense(ofs, i + 5000, languages[i], "", &error))
+            {
+            have_write_license_error = true;
+            }
+          }
+        }
+      }
+
+    ofs.Close();
+
+    if(have_write_license_error)
+      {
+      cmCPackLogger(cmCPackLog::LOG_ERROR,
+        "Error writing license file to SLA." << std::endl
+        << error
+        << std::endl);
+      return 0;
       }
-      osf << "};\n";
-      osf << "\n";
-      osf << SLASTREnglish;
-      ifs.close();
-      osf.close();
-    }
 
     // convert to UDCO
     std::string temp_udco = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
@@ -477,7 +746,6 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
     udco_image_command << " -format UDCO";
     udco_image_command << " -ov -o \"" << temp_udco << "\"";
 
-    std::string error;
     if(!this->RunCommand(udco_image_command, &error))
       {
       cmCPackLogger(cmCPackLog::LOG_ERROR,
@@ -539,7 +807,7 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
       }
 
     temp_image = temp_udco;
-  }
+    }
 
 
   // Create the final compressed read-only disk image ...
@@ -607,3 +875,155 @@ cmCPackDragNDropGenerator::GetComponentInstallDirNameSuffix(
 
   return GetComponentPackageFileName(package_file_name, componentName, false);
 }
+
+bool
+cmCPackDragNDropGenerator::WriteLicense(cmGeneratedFileStream& outputStream,
+  int licenseNumber, std::string licenseLanguage, std::string licenseFile,
+  std::string *error)
+{
+  if(!licenseFile.empty() && !singleLicense)
+    {
+    licenseNumber = 5002;
+    licenseLanguage = "English";
+    }
+
+  // License header
+  outputStream << "data 'TEXT' (" << licenseNumber << ", \""
+    << licenseLanguage << "\") {\n";
+  // License body
+  std::string actual_license = !licenseFile.empty() ? licenseFile :
+    (slaDirectory + "/" + licenseLanguage + ".license.txt");
+  cmsys::ifstream license_ifs;
+  license_ifs.open(actual_license.c_str());
+  if(license_ifs.is_open())
+    {
+    while(license_ifs.good())
+      {
+      std::string line;
+      std::getline(license_ifs, line);
+      if(!line.empty())
+        {
+        EscapeQuotesAndBackslashes(line);
+        std::vector<std::string> lines;
+        if(!this->BreakLongLine(line, lines, error))
+          {
+          return false;
+          }
+        for(size_t i = 0; i < lines.size(); ++i)
+          {
+          outputStream << "        \"" << lines[i] << "\"\n";
+          }
+        }
+      outputStream << "        \"\\n\"\n";
+      }
+    license_ifs.close();
+    }
+
+  // End of License
+  outputStream << "};\n\n";
+  if(!licenseFile.empty() && !singleLicense)
+    {
+    outputStream << SLASTREnglish;
+    }
+  else
+    {
+    // Menu header
+    outputStream << "resource 'STR#' (" << licenseNumber << ", \""
+      << licenseLanguage << "\") {\n";
+    outputStream << "    {\n";
+
+    // Menu body
+    cmsys::ifstream menu_ifs;
+    menu_ifs.open((slaDirectory+"/"+licenseLanguage+".menu.txt").c_str());
+    if(menu_ifs.is_open())
+      {
+      size_t lines_written = 0;
+      while(menu_ifs.good())
+        {
+        // Lines written from original file, not from broken up lines
+        std::string line;
+        std::getline(menu_ifs, line);
+        if(!line.empty())
+          {
+          EscapeQuotesAndBackslashes(line);
+          std::vector<std::string> lines;
+          if(!this->BreakLongLine(line, lines, error))
+            {
+            return false;
+            }
+          for(size_t i = 0; i < lines.size(); ++i)
+            {
+            std::string comma;
+            // We need a comma after every complete string,
+            // but not on the very last line
+            if(lines_written != 8 && i == lines.size() - 1)
+              {
+              comma = ",";
+              }
+            else
+              {
+              comma = "";
+              }
+            outputStream << "        \"" << lines[i] << "\"" << comma << "\n";
+            }
+          ++lines_written;
+          }
+        }
+      menu_ifs.close();
+      }
+
+    //End of menu
+    outputStream << "    }\n";
+    outputStream << "};\n";
+    outputStream << "\n";
+    }
+
+  return true;
+}
+
+bool
+cmCPackDragNDropGenerator::BreakLongLine(const std::string& line,
+  std::vector<std::string>& lines, std::string *error)
+{
+  const size_t max_line_length = 512;
+  for(size_t i = 0; i < line.size(); i += max_line_length)
+    {
+    size_t line_length = max_line_length;
+    if(i + line_length > line.size())
+      {
+      line_length = line.size() - i;
+      }
+    else while(line_length > 0 && line[i + line_length - 1] != ' ')
+      {
+      line_length = line_length - 1;
+      }
+
+    if(line_length == 0)
+      {
+      *error = "Please make sure there are no words "
+               "(or character sequences not broken up by spaces or newlines) "
+               "in your license file which are more than 512 characters long.";
+      return false;
+      }
+    lines.push_back(line.substr(i, line_length));
+    }
+  return true;
+}
+
+void
+cmCPackDragNDropGenerator::EscapeQuotesAndBackslashes(std::string& line)
+{
+  std::string::size_type backslash_pos = line.find('\\');
+  while(backslash_pos != std::string::npos)
+    {
+    line.replace(backslash_pos, 1, "\\\\");
+    backslash_pos = line.find('\\', backslash_pos + 2);
+    }
+
+  std::string::size_type quote_pos = line.find('\"');
+  while(quote_pos != std::string::npos)
+    {
+    line.replace(quote_pos, 1, "\\\"");
+    quote_pos = line.find('\"', quote_pos + 2);
+    }
+}
diff --git a/Source/CPack/cmCPackDragNDropGenerator.h b/Source/CPack/cmCPackDragNDropGenerator.h
index 1c84d49..604cdf5 100644
--- a/Source/CPack/cmCPackDragNDropGenerator.h
+++ b/Source/CPack/cmCPackDragNDropGenerator.h
@@ -15,6 +15,8 @@
 
 #include "cmCPackGenerator.h"
 
+class cmGeneratedFileStream;
+
 /** \class cmCPackDragNDropGenerator
  * \brief A generator for OSX drag-n-drop installs
  */
@@ -34,6 +36,7 @@ protected:
 
 
   bool CopyFile(std::ostringstream& source, std::ostringstream& target);
+  bool CreateEmptyFile(std::ostringstream& target, size_t size);
   bool RunCommand(std::ostringstream& command, std::string* output = 0);
 
   std::string
@@ -42,6 +45,18 @@ protected:
   int CreateDMG(const std::string& src_dir, const std::string& output_file);
 
   std::string InstallPrefix;
+
+private:
+  std::string slaDirectory;
+  bool singleLicense;
+
+  bool WriteLicense(cmGeneratedFileStream& outputStream, int licenseNumber,
+    std::string licenseLanguage, std::string licenseFile,
+    std::string *error);
+  bool BreakLongLine(const std::string& line,
+    std::vector<std::string>& lines,
+    std::string *error);
+  void EscapeQuotesAndBackslashes(std::string& line);
 };
 
 #endif
diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx
index def9fc7..22d4bf0 100644
--- a/Source/CPack/cmCPackGenerator.cxx
+++ b/Source/CPack/cmCPackGenerator.cxx
@@ -16,7 +16,6 @@
 #include "cmCPackLog.h"
 #include "cmake.h"
 #include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmGeneratedFileStream.h"
 #include "cmCPackComponentGroup.h"
 #include "cmXMLSafe.h"
@@ -718,13 +717,12 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
         cmake cm;
         cm.SetHomeDirectory("");
         cm.SetHomeOutputDirectory("");
+        cm.GetCurrentSnapshot().SetDefaultDefinitions();
         cm.AddCMakePaths();
         cm.SetProgressCallback(cmCPackGeneratorProgress, this);
         cmGlobalGenerator gg(&cm);
         cmsys::auto_ptr<cmMakefile> mf(
               new cmMakefile(&gg, cm.GetCurrentSnapshot()));
-        cmsys::auto_ptr<cmLocalGenerator> lg(
-              gg.CreateLocalGenerator(mf.get()));
         std::string realInstallDirectory = tempInstallDirectory;
         if ( !installSubDirectory.empty() && installSubDirectory != "/" )
           {
diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx
index 6cdda28..5ba639f 100644
--- a/Source/CPack/cmCPackNSISGenerator.cxx
+++ b/Source/CPack/cmCPackNSISGenerator.cxx
@@ -13,7 +13,6 @@
 #include "cmCPackNSISGenerator.h"
 
 #include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmSystemTools.h"
 #include "cmMakefile.h"
 #include "cmGeneratedFileStream.h"
@@ -158,6 +157,28 @@ int cmCPackNSISGenerator::PackageFiles()
                             installerIconCode.c_str());
     }
 
+  if (this->IsSet("CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP"))
+    {
+    std::string installerBitmapCode =
+      "!define MUI_WELCOMEFINISHPAGE_BITMAP \"";
+    installerBitmapCode +=
+      this->GetOption("CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP");
+    installerBitmapCode += "\"\n";
+    this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_WELCOMEFINISH_CODE",
+                            installerBitmapCode.c_str());
+    }
+
+  if (this->IsSet("CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP"))
+    {
+    std::string installerBitmapCode =
+      "!define MUI_UNWELCOMEFINISHPAGE_BITMAP \"";
+    installerBitmapCode +=
+      this->GetOption("CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP");
+    installerBitmapCode += "\"\n";
+    this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_UNWELCOMEFINISH_CODE",
+                            installerBitmapCode.c_str());
+    }
+
   if(this->IsSet("CPACK_NSIS_MUI_FINISHPAGE_RUN"))
     {
     std::string installerRunCode = "!define MUI_FINISHPAGE_RUN \"$INSTDIR\\";
diff --git a/Source/CPack/cmCPackOSXX11Generator.cxx b/Source/CPack/cmCPackOSXX11Generator.cxx
index d533af8..8940f54 100644
--- a/Source/CPack/cmCPackOSXX11Generator.cxx
+++ b/Source/CPack/cmCPackOSXX11Generator.cxx
@@ -13,7 +13,6 @@
 
 #include "cmake.h"
 #include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmSystemTools.h"
 #include "cmMakefile.h"
 #include "cmGeneratedFileStream.h"
diff --git a/Source/CPack/cmCPackPackageMakerGenerator.cxx b/Source/CPack/cmCPackPackageMakerGenerator.cxx
index 880663f..8fdc036 100644
--- a/Source/CPack/cmCPackPackageMakerGenerator.cxx
+++ b/Source/CPack/cmCPackPackageMakerGenerator.cxx
@@ -13,7 +13,6 @@
 
 #include "cmake.h"
 #include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmSystemTools.h"
 #include "cmMakefile.h"
 #include "cmGeneratedFileStream.h"
diff --git a/Source/CPack/cmCPackSTGZGenerator.cxx b/Source/CPack/cmCPackSTGZGenerator.cxx
index 109dcb7..68b893f 100644
--- a/Source/CPack/cmCPackSTGZGenerator.cxx
+++ b/Source/CPack/cmCPackSTGZGenerator.cxx
@@ -14,7 +14,6 @@
 
 #include "cmake.h"
 #include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmSystemTools.h"
 #include "cmMakefile.h"
 #include "cmCPackLog.h"
diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx
index cb9cbc4..c08897f 100644
--- a/Source/CPack/cpack.cxx
+++ b/Source/CPack/cpack.cxx
@@ -18,7 +18,6 @@
 #include "cmCPackGenerator.h"
 #include "cmake.h"
 #include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmMakefile.h"
 
 #include "cmCPackLog.h"
@@ -200,12 +199,11 @@ int main (int argc, char const* const* argv)
   cmake cminst;
   cminst.SetHomeDirectory("");
   cminst.SetHomeOutputDirectory("");
+  cminst.GetCurrentSnapshot().SetDefaultDefinitions();
   cminst.GetState()->RemoveUnscriptableCommands();
   cmGlobalGenerator cmgg(&cminst);
   cmsys::auto_ptr<cmMakefile> globalMF(
         new cmMakefile(&cmgg, cminst.GetCurrentSnapshot()));
-  cmsys::auto_ptr<cmLocalGenerator> cmlg(
-        cmgg.CreateLocalGenerator(globalMF.get()));
 #if defined(__CYGWIN__)
   globalMF->AddDefinition("CMAKE_LEGACY_CYGWIN_WIN32", "0");
 #endif
diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx
index 6dbb245..0d74f48 100644
--- a/Source/CTest/cmCTestBuildHandler.cxx
+++ b/Source/CTest/cmCTestBuildHandler.cxx
@@ -15,7 +15,6 @@
 #include "cmCTest.h"
 #include "cmake.h"
 #include "cmMakefile.h"
-#include "cmLocalGenerator.h"
 #include "cmGlobalGenerator.h"
 #include "cmGeneratedFileStream.h"
 #include "cmXMLWriter.h"
diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx
index 20807c8..2c2cd48 100644
--- a/Source/CTest/cmCTestCoverageHandler.cxx
+++ b/Source/CTest/cmCTestCoverageHandler.cxx
@@ -820,11 +820,26 @@ int cmCTestCoverageHandler::HandleCoberturaCoverage(
 {
   cmParseCoberturaCoverage cov(*cont, this->CTest);
 
-  // Assume the coverage.xml is in the source directory
-  std::string coverageXMLFile = this->CTest->GetBinaryDir() + "/coverage.xml";
+  // Assume the coverage.xml is in the binary directory
+  // check for the COBERTURADIR environment variable,
+  // if it doesn't exist or is empty, assume the
+  // binary directory is used.
+  std::string coverageXMLFile;
+  const char* covDir = cmSystemTools::GetEnv("COBERTURADIR");
+  if(covDir && strlen(covDir) != 0)
+    {
+      coverageXMLFile = std::string(covDir);
+    }
+  else
+    {
+      coverageXMLFile = this->CTest->GetBinaryDir();
+    }
+  // build the find file string with the directory from above
+  coverageXMLFile += "/coverage.xml";
 
   if(cmSystemTools::FileExists(coverageXMLFile.c_str()))
     {
+    // If file exists, parse it
     cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
                "Parsing Cobertura XML file: " << coverageXMLFile
                << std::endl, this->Quiet);
@@ -833,7 +848,7 @@ int cmCTestCoverageHandler::HandleCoberturaCoverage(
   else
     {
     cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
-               "Cannot find Cobertura XML file: " << coverageXMLFile
+               " Cannot find Cobertura XML file: " << coverageXMLFile
                << std::endl, this->Quiet);
     }
   return static_cast<int>(cont->TotalCoverage.size());
@@ -913,16 +928,33 @@ int cmCTestCoverageHandler::HandleJacocoCoverage(
 {
   cmParseJacocoCoverage cov =
    cmParseJacocoCoverage(*cont, this->CTest);
-  cmsys::Glob g;
+
+  // Search in the source directory.
+  cmsys::Glob g1;
   std::vector<std::string> files;
-  g.SetRecurse(true);
+  g1.SetRecurse(true);
 
   std::string SourceDir
     = this->CTest->GetCTestConfiguration("SourceDirectory");
   std::string coverageFile = SourceDir+ "/*jacoco.xml";
 
-  g.FindFiles(coverageFile);
-  files=g.GetFiles();
+  g1.FindFiles(coverageFile);
+  files = g1.GetFiles();
+
+  // ...and in the binary directory.
+  cmsys::Glob g2;
+  std::vector<std::string> binFiles;
+  g2.SetRecurse(true);
+  std::string binaryDir
+    = this->CTest->GetCTestConfiguration("BuildDirectory");
+  std::string binCoverageFile = binaryDir+ "/*jacoco.xml";
+  g2.FindFiles(binCoverageFile);
+  binFiles = g2.GetFiles();
+  if (!binFiles.empty())
+    {
+    files.insert(files.end(), binFiles.begin(), binFiles.end());
+    }
+
   if (!files.empty())
     {
     cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
@@ -2287,7 +2319,7 @@ int cmCTestCoverageHandler::RunBullseyeSourceSummary(
         {
         cper /= 2.0f;
         }
-      percent_coverage += cper;
+      percent_coverage += static_cast<double>(cper);
       float cmet = static_cast<float>(percentFunction + percentBranch);
       if(totalBranches > 0)
         {
diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx
index fb0cce6..749a5be 100644
--- a/Source/CTest/cmCTestLaunch.cxx
+++ b/Source/CTest/cmCTestLaunch.cxx
@@ -728,7 +728,6 @@ int cmCTestLaunch::Main(int argc, const char* const argv[])
 
 //----------------------------------------------------------------------------
 #include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmMakefile.h"
 #include "cmake.h"
 #include <cmsys/auto_ptr.hxx>
@@ -737,10 +736,9 @@ void cmCTestLaunch::LoadConfig()
   cmake cm;
   cm.SetHomeDirectory("");
   cm.SetHomeOutputDirectory("");
+  cm.GetCurrentSnapshot().SetDefaultDefinitions();
   cmGlobalGenerator gg(&cm);
   cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
-  cmsys::auto_ptr<cmLocalGenerator> lg(
-        gg.CreateLocalGenerator(mf.get()));
   std::string fname = this->LogDir;
   fname += "CTestLaunchConfig.cmake";
   if(cmSystemTools::FileExists(fname.c_str()) &&
diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx
index c1ba279..ee15271 100644
--- a/Source/CTest/cmCTestScriptHandler.cxx
+++ b/Source/CTest/cmCTestScriptHandler.cxx
@@ -16,7 +16,6 @@
 #include "cmake.h"
 #include "cmFunctionBlocker.h"
 #include "cmMakefile.h"
-#include "cmLocalGenerator.h"
 #include "cmGlobalGenerator.h"
 #include "cmGeneratedFileStream.h"
 
@@ -86,7 +85,6 @@ cmCTestScriptHandler::cmCTestScriptHandler()
   this->EmptyBinDir = false;
   this->EmptyBinDirOnce = false;
   this->Makefile = 0;
-  this->LocalGenerator = 0;
   this->CMake = 0;
   this->GlobalGenerator = 0;
 
@@ -128,9 +126,6 @@ void cmCTestScriptHandler::Initialize()
   delete this->Makefile;
   this->Makefile = 0;
 
-  delete this->LocalGenerator;
-  this->LocalGenerator = 0;
-
   delete this->GlobalGenerator;
   this->GlobalGenerator = 0;
 
@@ -141,7 +136,6 @@ void cmCTestScriptHandler::Initialize()
 cmCTestScriptHandler::~cmCTestScriptHandler()
 {
   delete this->Makefile;
-  delete this->LocalGenerator;
   delete this->GlobalGenerator;
   delete this->CMake;
 }
@@ -179,15 +173,14 @@ int cmCTestScriptHandler::ProcessHandler()
 
 void cmCTestScriptHandler::UpdateElapsedTime()
 {
-  if (this->LocalGenerator)
+  if (this->Makefile)
     {
     // set the current elapsed time
     char timeString[20];
     int itime = static_cast<unsigned int>(cmSystemTools::GetTime()
                                           - this->ScriptStartTime);
     sprintf(timeString,"%i",itime);
-    this->LocalGenerator->GetMakefile()->AddDefinition("CTEST_ELAPSED_TIME",
-                                                   timeString);
+    this->Makefile->AddDefinition("CTEST_ELAPSED_TIME", timeString);
     }
 }
 
@@ -316,28 +309,23 @@ void cmCTestScriptHandler::CreateCMake()
     {
     delete this->CMake;
     delete this->GlobalGenerator;
-    delete this->LocalGenerator;
     delete this->Makefile;
     }
   this->CMake = new cmake;
   this->CMake->SetHomeDirectory("");
   this->CMake->SetHomeOutputDirectory("");
+  this->CMake->GetCurrentSnapshot().SetDefaultDefinitions();
   this->CMake->AddCMakePaths();
   this->GlobalGenerator = new cmGlobalGenerator(this->CMake);
 
   cmState::Snapshot snapshot = this->CMake->GetCurrentSnapshot();
+  std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+  snapshot.GetDirectory().SetCurrentSource(cwd);
+  snapshot.GetDirectory().SetCurrentBinary(cwd);
   this->Makefile = new cmMakefile(this->GlobalGenerator, snapshot);
-  this->LocalGenerator =
-      this->GlobalGenerator->CreateLocalGenerator(this->Makefile);
 
   this->CMake->SetProgressCallback(ctestScriptProgressCallback, this->CTest);
 
-  // Set CMAKE_CURRENT_SOURCE_DIR and CMAKE_CURRENT_BINARY_DIR.
-  // Also, some commands need Makefile->GetCurrentSourceDirectory().
-  std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
-  this->Makefile->SetCurrentSourceDirectory(cwd);
-  this->Makefile->SetCurrentBinaryDirectory(cwd);
-
   // remove all cmake commands which are not scriptable, since they can't be
   // used in ctest scripts
   this->CMake->GetState()->RemoveUnscriptableCommands();
diff --git a/Source/CTest/cmCTestScriptHandler.h b/Source/CTest/cmCTestScriptHandler.h
index 42c2f20..c9d0b6a 100644
--- a/Source/CTest/cmCTestScriptHandler.h
+++ b/Source/CTest/cmCTestScriptHandler.h
@@ -18,7 +18,6 @@
 #include "cmListFileCache.h"
 
 class cmMakefile;
-class cmLocalGenerator;
 class cmGlobalGenerator;
 class cmake;
 class cmCTestCommand;
@@ -166,7 +165,6 @@ private:
   double ScriptStartTime;
 
   cmMakefile *Makefile;
-  cmLocalGenerator *LocalGenerator;
   cmGlobalGenerator *GlobalGenerator;
   cmake *CMake;
 };
diff --git a/Source/CTest/cmCTestStartCommand.cxx b/Source/CTest/cmCTestStartCommand.cxx
index e19e4f4..36576c5 100644
--- a/Source/CTest/cmCTestStartCommand.cxx
+++ b/Source/CTest/cmCTestStartCommand.cxx
@@ -12,7 +12,6 @@
 #include "cmCTestStartCommand.h"
 
 #include "cmCTest.h"
-#include "cmLocalGenerator.h"
 #include "cmGlobalGenerator.h"
 #include "cmCTestVC.h"
 #include "cmGeneratedFileStream.h"
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
index f9678e7..b6a4819 100644
--- a/Source/CTest/cmCTestTestHandler.cxx
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -24,7 +24,6 @@
 #include <cmsys/FStream.hxx>
 #include "cmMakefile.h"
 #include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmCommand.h"
 #include "cmSystemTools.h"
 #include "cmXMLWriter.h"
@@ -580,7 +579,7 @@ int cmCTestTestHandler::ProcessHandler()
       }
 
     cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl
-               << static_cast<int>(percent + .5) << "% tests passed, "
+               << static_cast<int>(percent + .5f) << "% tests passed, "
                << failed.size() << " tests failed out of "
                << total << std::endl);
     if(this->CTest->GetLabelSummary())
@@ -610,11 +609,11 @@ int cmCTestTestHandler::ProcessHandler()
         if ( ftit->Status != cmCTestTestHandler::COMPLETED )
           {
           ofs << ftit->TestCount << ":" << ftit->Name << std::endl;
-          cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\t" << std::setw(3)
+          cmCTestLog(this->CTest, HANDLER_OUTPUT, "\t" << std::setw(3)
                      << ftit->TestCount << " - "
                      << ftit->Name << " ("
                      << this->GetTestStatus(ftit->Status) << ")"
-                     << std::endl, this->Quiet);
+                     << std::endl);
           }
         }
       }
@@ -1591,10 +1590,9 @@ void cmCTestTestHandler::GetListOfTests()
   cmake cm;
   cm.SetHomeDirectory("");
   cm.SetHomeOutputDirectory("");
+  cm.GetCurrentSnapshot().SetDefaultDefinitions();
   cmGlobalGenerator gg(&cm);
   cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
-  cmsys::auto_ptr<cmLocalGenerator> lg(
-        gg.CreateLocalGenerator(mf.get()));
   mf->AddDefinition("CTEST_CONFIGURATION_TYPE",
     this->CTest->GetConfigType().c_str());
 
diff --git a/Source/CTest/cmCTestUpdateHandler.cxx b/Source/CTest/cmCTestUpdateHandler.cxx
index 963e501..bf2f34a 100644
--- a/Source/CTest/cmCTestUpdateHandler.cxx
+++ b/Source/CTest/cmCTestUpdateHandler.cxx
@@ -15,7 +15,6 @@
 #include "cmCTest.h"
 #include "cmake.h"
 #include "cmMakefile.h"
-#include "cmLocalGenerator.h"
 #include "cmGlobalGenerator.h"
 #include "cmVersion.h"
 #include "cmGeneratedFileStream.h"
diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt
index 66fd18b..f17de5d 100644
--- a/Source/QtDialog/CMakeLists.txt
+++ b/Source/QtDialog/CMakeLists.txt
@@ -113,12 +113,18 @@ set(SRCS
   QCMakeCacheView.h
   QCMakeWidgets.cxx
   QCMakeWidgets.h
+  RegexExplorer.cxx
+  RegexExplorer.h
+  WarningMessagesDialog.cxx
+  WarningMessagesDialog.h
   )
 QT4_WRAP_UI(UI_SRCS
   CMakeSetupDialog.ui
   Compilers.ui
   CrossCompiler.ui
   AddCacheEntry.ui
+  RegexExplorer.ui
+  WarningMessagesDialog.ui
   )
 QT4_WRAP_CPP(MOC_SRCS
   AddCacheEntry.h
@@ -128,6 +134,8 @@ QT4_WRAP_CPP(MOC_SRCS
   QCMake.h
   QCMakeCacheView.h
   QCMakeWidgets.h
+  RegexExplorer.h
+  WarningMessagesDialog.h
   )
 QT4_ADD_RESOURCES(RC_SRCS CMakeSetup.qrc)
 
@@ -185,7 +193,7 @@ if(UNIX AND NOT APPLE)
   foreach (size IN ITEMS 32 128)
     install(
       FILES       "${CMAKE_CURRENT_SOURCE_DIR}/CMakeSetup${size}.png"
-      DESTINATION "share/icons/hicolor/${size}x${size}/apps"
+      DESTINATION "${CMAKE_XDGDATA_DIR}/icons/hicolor/${size}x${size}/apps"
       ${COMPONENT}
       RENAME      "CMakeSetup.png")
   endforeach ()
@@ -193,10 +201,10 @@ if(UNIX AND NOT APPLE)
   # install a desktop file so CMake appears in the application start menu
   # with an icon
   install(FILES CMake.desktop
-    DESTINATION share/applications
+    DESTINATION "${CMAKE_XDGDATA_DIR}/applications"
     ${COMPONENT})
   install(FILES cmakecache.xml
-    DESTINATION share/mime/packages
+    DESTINATION "${CMAKE_XDGDATA_DIR}/mime/packages"
     ${COMPONENT})
 endif()
 
diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx
index 03417f3..2fc4faf 100644
--- a/Source/QtDialog/CMakeSetupDialog.cxx
+++ b/Source/QtDialog/CMakeSetupDialog.cxx
@@ -33,6 +33,8 @@
 #include "QCMakeCacheView.h"
 #include "AddCacheEntry.h"
 #include "FirstConfigure.h"
+#include "RegexExplorer.h"
+#include "WarningMessagesDialog.h"
 #include "cmSystemTools.h"
 #include "cmVersion.h"
 
@@ -125,6 +127,9 @@ CMakeSetupDialog::CMakeSetupDialog()
                    this, SLOT(doInstallForCommandLine()));
 #endif
   ToolsMenu->addSeparator();
+  ToolsMenu->addAction(tr("Regular Expression Explorer..."),
+                       this, SLOT(doRegexExplorerDialog()));
+  ToolsMenu->addSeparator();
   ToolsMenu->addAction(tr("&Find in Output..."),
                        this, SLOT(doOutputFindDialog()),
                        QKeySequence::Find);
@@ -141,9 +146,8 @@ CMakeSetupDialog::CMakeSetupDialog()
                        this, SLOT(doOutputErrorNext()));  // in Eclipse
 
   QMenu* OptionsMenu = this->menuBar()->addMenu(tr("&Options"));
-  this->SuppressDevWarningsAction =
-    OptionsMenu->addAction(tr("&Suppress dev Warnings (-Wno-dev)"));
-  this->SuppressDevWarningsAction->setCheckable(true);
+  OptionsMenu->addAction(tr("Warning Messages..."),
+                         this, SLOT(doWarningMessagesDialog()));
   this->WarnUninitializedAction =
     OptionsMenu->addAction(tr("&Warn Uninitialized (--warn-uninitialized)"));
   this->WarnUninitializedAction->setCheckable(true);
@@ -274,9 +278,6 @@ void CMakeSetupDialog::initialize()
   QObject::connect(this->AddEntry, SIGNAL(clicked(bool)),
                    this, SLOT(addCacheEntry()));
 
-  QObject::connect(this->SuppressDevWarningsAction, SIGNAL(triggered(bool)),
-                   this->CMakeThread->cmakeInstance(), SLOT(setSuppressDevWarnings(bool)));
-
   QObject::connect(this->WarnUninitializedAction, SIGNAL(triggered(bool)),
                    this->CMakeThread->cmakeInstance(),
                    SLOT(setWarnUninitializedMode(bool)));
@@ -734,6 +735,7 @@ bool CMakeSetupDialog::setupFirstConfigure()
     {
     dialog.saveToSettings();
     this->CMakeThread->cmakeInstance()->setGenerator(dialog.getGenerator());
+    this->CMakeThread->cmakeInstance()->setToolset(dialog.getToolset());
 
     QCMakeCacheModel* m = this->CacheValues->cacheModel();
 
@@ -1271,6 +1273,12 @@ void CMakeSetupDialog::doOutputFindDialog()
     }
 }
 
+void CMakeSetupDialog::doRegexExplorerDialog()
+{
+  RegexExplorer dialog(this);
+  dialog.exec();
+}
+
 void CMakeSetupDialog::doOutputFindPrev()
 {
   doOutputFindNext(false);
@@ -1358,3 +1366,9 @@ void CMakeSetupDialog::doOutputErrorNext()
     this->Output->setTextCursor(textCursor);
     }
 }
+
+void CMakeSetupDialog::doWarningMessagesDialog()
+{
+  WarningMessagesDialog dialog(this, this->CMakeThread->cmakeInstance());
+  dialog.exec();
+}
diff --git a/Source/QtDialog/CMakeSetupDialog.h b/Source/QtDialog/CMakeSetupDialog.h
index 1b26c64..4b53b1c 100644
--- a/Source/QtDialog/CMakeSetupDialog.h
+++ b/Source/QtDialog/CMakeSetupDialog.h
@@ -82,6 +82,9 @@ protected slots:
   void doOutputFindNext(bool directionForward = true);
   void doOutputFindPrev();
   void doOutputErrorNext();
+  void doRegexExplorerDialog();
+  /// display the modal warning messages dialog window
+  void doWarningMessagesDialog();
 
 protected:
 
@@ -101,7 +104,6 @@ protected:
   QAction* ExitAction;
   QAction* ConfigureAction;
   QAction* GenerateAction;
-  QAction* SuppressDevWarningsAction;
   QAction* WarnUninitializedAction;
   QAction* WarnUnusedAction;
   QAction* InstallForCommandLineAction;
diff --git a/Source/QtDialog/FirstConfigure.cxx b/Source/QtDialog/FirstConfigure.cxx
index 6de9f00..61aad72 100644
--- a/Source/QtDialog/FirstConfigure.cxx
+++ b/Source/QtDialog/FirstConfigure.cxx
@@ -15,6 +15,11 @@ StartCompilerSetup::StartCompilerSetup(QWidget* p)
   l->addWidget(new QLabel(tr("Specify the generator for this project")));
   this->GeneratorOptions = new QComboBox(this);
   l->addWidget(this->GeneratorOptions);
+
+  // Add the ability to specify toolset (-T parameter)
+  ToolsetFrame = CreateToolsetWidgets();
+  l->addWidget(ToolsetFrame);
+
   l->addSpacing(6);
 
   this->CompilerSetupOptions[0] = new QRadioButton(tr("Use default native compilers"), this);
@@ -36,17 +41,51 @@ StartCompilerSetup::StartCompilerSetup(QWidget* p)
                    this, SLOT(onSelectionChanged(bool)));
   QObject::connect(this->CompilerSetupOptions[3], SIGNAL(toggled(bool)),
                    this, SLOT(onSelectionChanged(bool)));
+  QObject::connect(GeneratorOptions,
+                   SIGNAL(currentIndexChanged(QString const&)),
+                   this, SLOT(onGeneratorChanged(QString const&)));
+}
+
+QFrame* StartCompilerSetup::CreateToolsetWidgets()
+{
+  QFrame* frame = new QFrame(this);
+  QVBoxLayout* l = new QVBoxLayout(frame);
+  l->setContentsMargins(0, 0, 0, 0);
+
+  ToolsetLabel = new QLabel(tr("Optional toolset to use (-T parameter)"));
+  l->addWidget(ToolsetLabel);
+
+  Toolset = new QLineEdit(frame);
+  l->addWidget(Toolset);
+
+  return frame;
 }
 
 StartCompilerSetup::~StartCompilerSetup()
 {
 }
 
-void StartCompilerSetup::setGenerators(const QStringList& gens)
+void StartCompilerSetup::setGenerators(
+  std::vector<cmake::GeneratorInfo> const& gens)
 {
   this->GeneratorOptions->clear();
-  this->GeneratorOptions->addItems(gens);
-};
+
+  QStringList generator_list;
+
+  std::vector<cmake::GeneratorInfo>::const_iterator it;
+  for (it = gens.begin(); it != gens.end(); ++it)
+    {
+    generator_list.append(QString::fromLocal8Bit(it->name.c_str()));
+
+    if (it->supportsToolset)
+      {
+      this->GeneratorsSupportingToolset.append(
+        QString::fromLocal8Bit(it->name.c_str()));
+      }
+    }
+
+  this->GeneratorOptions->addItems(generator_list);
+}
 
 void StartCompilerSetup::setCurrentGenerator(const QString& gen)
 {
@@ -62,6 +101,11 @@ QString StartCompilerSetup::getGenerator() const
   return this->GeneratorOptions->currentText();
 };
 
+QString StartCompilerSetup::getToolset() const
+{
+  return this->Toolset->text();
+};
+
 bool StartCompilerSetup::defaultSetup() const
 {
   return this->CompilerSetupOptions[0]->isChecked();
@@ -88,6 +132,18 @@ void StartCompilerSetup::onSelectionChanged(bool on)
     selectionChanged();
 }
 
+void StartCompilerSetup::onGeneratorChanged(QString const& name)
+{
+  if (GeneratorsSupportingToolset.contains(name))
+    {
+    ToolsetFrame->show();
+    }
+  else
+    {
+    ToolsetFrame->hide();
+    }
+}
+
 int StartCompilerSetup::nextId() const
 {
   if(compilerSetup())
@@ -325,7 +381,8 @@ FirstConfigure::~FirstConfigure()
 {
 }
 
-void FirstConfigure::setGenerators(const QStringList& gens)
+void FirstConfigure::setGenerators(
+  std::vector<cmake::GeneratorInfo> const& gens)
 {
   this->mStartCompilerSetupPage->setGenerators(gens);
 }
@@ -335,6 +392,11 @@ QString FirstConfigure::getGenerator() const
   return this->mStartCompilerSetupPage->getGenerator();
 }
 
+QString FirstConfigure::getToolset() const
+{
+  return this->mStartCompilerSetupPage->getToolset();
+}
+
 void FirstConfigure::loadFromSettings()
 {
   QSettings settings;
diff --git a/Source/QtDialog/FirstConfigure.h b/Source/QtDialog/FirstConfigure.h
index be390b0..09952b6 100644
--- a/Source/QtDialog/FirstConfigure.h
+++ b/Source/QtDialog/FirstConfigure.h
@@ -4,6 +4,7 @@
 
 #include <QWizard>
 #include <QWizardPage>
+#include "cmake.h"
 #include "ui_Compilers.h"
 #include "ui_CrossCompiler.h"
 
@@ -27,9 +28,10 @@ class StartCompilerSetup : public QWizardPage
   public:
     StartCompilerSetup(QWidget* p);
     ~StartCompilerSetup();
-    void setGenerators(const QStringList& gens);
+    void setGenerators(std::vector<cmake::GeneratorInfo> const& gens);
     void setCurrentGenerator(const QString& gen);
     QString getGenerator() const;
+    QString getToolset() const;
 
     bool defaultSetup() const;
     bool compilerSetup() const;
@@ -43,10 +45,18 @@ class StartCompilerSetup : public QWizardPage
 
   protected slots:
     void onSelectionChanged(bool);
+    void onGeneratorChanged(QString const& name);
 
   protected:
     QComboBox* GeneratorOptions;
     QRadioButton* CompilerSetupOptions[4];
+    QFrame* ToolsetFrame;
+    QLineEdit* Toolset;
+    QLabel* ToolsetLabel;
+    QStringList GeneratorsSupportingToolset;
+
+  private:
+    QFrame* CreateToolsetWidgets();
 };
 
 //! the page that gives basic options for native compilers
@@ -140,8 +150,9 @@ public:
   FirstConfigure();
   ~FirstConfigure();
 
-  void setGenerators(const QStringList& gens);
+  void setGenerators(std::vector<cmake::GeneratorInfo> const& gens);
   QString getGenerator() const;
+  QString getToolset() const;
 
   bool defaultSetup() const;
   bool compilerSetup() const;
diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx
index 9edbb20..dd7c138 100644
--- a/Source/QtDialog/QCMake.cxx
+++ b/Source/QtDialog/QCMake.cxx
@@ -15,7 +15,6 @@
 #include <QDir>
 #include <QCoreApplication>
 
-#include "cmake.h"
 #include "cmState.h"
 #include "cmSystemTools.h"
 #include "cmExternalMakefileProjectGenerator.h"
@@ -27,7 +26,6 @@
 QCMake::QCMake(QObject* p)
   : QObject(p)
 {
-  this->SuppressDevWarnings = false;
   this->WarnUninitializedMode = false;
   this->WarnUnusedMode = false;
   qRegisterMetaType<QCMakeProperty>();
@@ -46,21 +44,23 @@ QCMake::QCMake(QObject* p)
 
   cmSystemTools::SetInterruptCallback(QCMake::interruptCallback, this);
 
-  std::vector<std::string> generators;
+  std::vector<cmake::GeneratorInfo> generators;
   this->CMakeInstance->GetRegisteredGenerators(generators);
-  std::vector<std::string>::iterator iter;
-  for(iter = generators.begin(); iter != generators.end(); ++iter)
+
+  std::vector<cmake::GeneratorInfo>::const_iterator it;
+  for(it = generators.begin(); it != generators.end(); ++it)
     {
     // Skip the generator "KDevelop3", since there is also
     // "KDevelop3 - Unix Makefiles", which is the full and official name.
     // The short name is actually only still there since this was the name
     // in CMake 2.4, to keep "command line argument compatibility", but
     // this is not necessary in the GUI.
-    if (*iter == "KDevelop3")
+    if (it->name == "KDevelop3")
       {
       continue;
       }
-    this->AvailableGenerators.append(QString::fromLocal8Bit(iter->c_str()));
+
+    this->AvailableGenerators.push_back(*it);
     }
 }
 
@@ -96,6 +96,7 @@ void QCMake::setBinaryDirectory(const QString& _dir)
     emit this->binaryDirChanged(this->BinaryDirectory);
     cmState* state = this->CMakeInstance->GetState();
     this->setGenerator(QString());
+    this->setToolset(QString());
     if(!this->CMakeInstance->LoadCache(
       this->BinaryDirectory.toLocal8Bit().data()))
       {
@@ -124,6 +125,12 @@ void QCMake::setBinaryDirectory(const QString& _dir)
         CreateFullGeneratorName(gen, extraGen? extraGen : "");
       this->setGenerator(QString::fromLocal8Bit(curGen.c_str()));
       }
+
+    const char* toolset = state->GetCacheEntryValue("CMAKE_GENERATOR_TOOLSET");
+    if (toolset)
+      {
+      this->setToolset(QString::fromLocal8Bit(toolset));
+      }
     }
 }
 
@@ -137,6 +144,15 @@ void QCMake::setGenerator(const QString& gen)
     }
 }
 
+void QCMake::setToolset(const QString& toolset)
+{
+  if(this->Toolset != toolset)
+    {
+    this->Toolset = toolset;
+    emit this->toolsetChanged(this->Toolset);
+    }
+}
+
 void QCMake::configure()
 {
 #ifdef Q_OS_WIN
@@ -148,9 +164,8 @@ void QCMake::configure()
   this->CMakeInstance->SetGlobalGenerator(
     this->CMakeInstance->CreateGlobalGenerator(this->Generator.toLocal8Bit().data()));
   this->CMakeInstance->SetGeneratorPlatform("");
-  this->CMakeInstance->SetGeneratorToolset("");
+  this->CMakeInstance->SetGeneratorToolset(this->Toolset.toLocal8Bit().data());
   this->CMakeInstance->LoadCache();
-  this->CMakeInstance->SetSuppressDevWarnings(this->SuppressDevWarnings);
   this->CMakeInstance->SetWarnUninitialized(this->WarnUninitializedMode);
   this->CMakeInstance->SetWarnUnused(this->WarnUnusedMode);
   this->CMakeInstance->PreLoadCMakeFiles();
@@ -396,9 +411,9 @@ QString QCMake::generator() const
   return this->Generator;
 }
 
-QStringList QCMake::availableGenerators() const
+std::vector<cmake::GeneratorInfo> const& QCMake::availableGenerators() const
 {
-  return this->AvailableGenerators;
+  return AvailableGenerators;
 }
 
 void QCMake::deleteCache()
@@ -409,6 +424,7 @@ void QCMake::deleteCache()
   this->CMakeInstance->LoadCache(this->BinaryDirectory.toLocal8Bit().data());
   // emit no generator and no properties
   this->setGenerator(QString());
+  this->setToolset(QString());
   QCMakePropertyList props = this->properties();
   emit this->propertiesChanged(props);
 }
@@ -439,10 +455,44 @@ bool QCMake::getDebugOutput() const
   return this->CMakeInstance->GetDebugOutput();
 }
 
+bool QCMake::getSuppressDevWarnings()
+{
+  return this->CMakeInstance->GetSuppressDevWarnings();
+}
 
 void QCMake::setSuppressDevWarnings(bool value)
 {
-  this->SuppressDevWarnings = value;
+  this->CMakeInstance->SetSuppressDevWarnings(value);
+}
+
+bool QCMake::getSuppressDeprecatedWarnings()
+{
+  return this->CMakeInstance->GetSuppressDeprecatedWarnings();
+}
+
+void QCMake::setSuppressDeprecatedWarnings(bool value)
+{
+  this->CMakeInstance->SetSuppressDeprecatedWarnings(value);
+}
+
+bool QCMake::getDevWarningsAsErrors()
+{
+  return this->CMakeInstance->GetDevWarningsAsErrors();
+}
+
+void QCMake::setDevWarningsAsErrors(bool value)
+{
+  this->CMakeInstance->SetDevWarningsAsErrors(value);
+}
+
+bool QCMake::getDeprecatedWarningsAsErrors()
+{
+  return this->CMakeInstance->GetDeprecatedWarningsAsErrors();
+}
+
+void QCMake::setDeprecatedWarningsAsErrors(bool value)
+{
+  this->CMakeInstance->SetDeprecatedWarningsAsErrors(value);
 }
 
 void QCMake::setWarnUninitializedMode(bool value)
diff --git a/Source/QtDialog/QCMake.h b/Source/QtDialog/QCMake.h
index d910eb7..8942e7c 100644
--- a/Source/QtDialog/QCMake.h
+++ b/Source/QtDialog/QCMake.h
@@ -17,6 +17,8 @@
 #pragma warning ( disable : 4512 )
 #endif
 
+#include <vector>
+
 #include <QObject>
 #include <QString>
 #include <QVariant>
@@ -25,7 +27,7 @@
 #include <QMetaType>
 #include <QAtomicInt>
 
-class cmake;
+#include "cmake.h"
 
 /// struct to represent cmake properties in Qt
 /// Value is of type String or Bool
@@ -73,6 +75,8 @@ public slots:
   void setBinaryDirectory(const QString& dir);
   /// set the desired generator to use
   void setGenerator(const QString& generator);
+  /// set the desired generator to use
+  void setToolset(const QString& toolset);
   /// do the configure step
   void configure();
   /// generate the files
@@ -87,8 +91,22 @@ public slots:
   void reloadCache();
   /// set whether to do debug output
   void setDebugOutput(bool);
+  /// get whether to do suppress dev warnings
+  bool getSuppressDevWarnings();
   /// set whether to do suppress dev warnings
   void setSuppressDevWarnings(bool value);
+  /// get whether to do suppress deprecated warnings
+  bool getSuppressDeprecatedWarnings();
+  /// set whether to do suppress deprecated warnings
+  void setSuppressDeprecatedWarnings(bool value);
+  /// get whether to treat developer (author) warnings as errors
+  bool getDevWarningsAsErrors();
+  /// set whether to treat developer (author) warnings as errors
+  void setDevWarningsAsErrors(bool value);
+  /// get whether to treat deprecated warnings as errors
+  bool getDeprecatedWarningsAsErrors();
+  /// set whether to treat deprecated warnings as errors
+  void setDeprecatedWarningsAsErrors(bool value);
   /// set whether to run cmake with warnings about uninitialized variables
   void setWarnUninitializedMode(bool value);
   /// set whether to run cmake with warnings about unused variables
@@ -104,7 +122,7 @@ public:
   /// get the current generator
   QString generator() const;
   /// get the available generators
-  QStringList availableGenerators() const;
+  std::vector<cmake::GeneratorInfo> const& availableGenerators() const;
   /// get whether to do debug output
   bool getDebugOutput() const;
 
@@ -130,6 +148,8 @@ signals:
   void errorMessage(const QString& msg);
   /// signal when debug output changes
   void debugOutputChanged(bool);
+  /// signal when the toolset changes
+  void toolsetChanged(const QString& toolset);
 
 protected:
   cmake* CMakeInstance;
@@ -140,14 +160,14 @@ protected:
                               bool&, void* cd);
   static void stdoutCallback(const char* msg, size_t len, void* cd);
   static void stderrCallback(const char* msg, size_t len, void* cd);
-  bool SuppressDevWarnings;
   bool WarnUninitializedMode;
   bool WarnUnusedMode;
   bool WarnUnusedAllMode;
   QString SourceDirectory;
   QString BinaryDirectory;
   QString Generator;
-  QStringList AvailableGenerators;
+  QString Toolset;
+  std::vector<cmake::GeneratorInfo> AvailableGenerators;
   QString CMakeExecutable;
   QAtomicInt InterruptFlag;
 };
diff --git a/Source/QtDialog/RegexExplorer.cxx b/Source/QtDialog/RegexExplorer.cxx
new file mode 100644
index 0000000..dfcf048
--- /dev/null
+++ b/Source/QtDialog/RegexExplorer.cxx
@@ -0,0 +1,166 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2015 Kitware, Inc., Gregor Jasny
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
+#include "RegexExplorer.h"
+
+RegexExplorer::RegexExplorer(QWidget* p) : QDialog(p), m_matched(false)
+{
+  this->setupUi(this);
+
+  for(int i = 1; i < cmsys::RegularExpression::NSUBEXP; ++i)
+    {
+    matchNumber->addItem(
+      QString("Match %1").arg(QString::number(i)),
+      QVariant(i));
+    }
+  matchNumber->setCurrentIndex(0);
+}
+
+void RegexExplorer::setStatusColor(QWidget* widget, bool successful)
+{
+  QColor color = successful ? QColor(0, 127, 0) : Qt::red;
+
+  QPalette palette = widget->palette();
+  palette.setColor(QPalette::Foreground, color);
+  widget->setPalette(palette);
+}
+
+void RegexExplorer::on_regularExpression_textChanged(const QString& text)
+{
+#ifdef QT_NO_STL
+  m_regex = text.toAscii().constData();
+#else
+  m_regex = text.toStdString();
+#endif
+
+  bool validExpression =
+    stripEscapes(m_regex) && m_regexParser.compile(m_regex);
+  if(!validExpression)
+    {
+    m_regexParser.set_invalid();
+    }
+
+  setStatusColor(labelRegexValid, validExpression);
+
+  on_inputText_textChanged();
+}
+
+void RegexExplorer::on_inputText_textChanged()
+{
+  if(m_regexParser.is_valid())
+    {
+    QString plainText = inputText->toPlainText();
+#ifdef QT_NO_STL
+    m_text = plainText.toAscii().constData();
+#else
+    m_text = plainText.toStdString();
+#endif
+    m_matched = m_regexParser.find(m_text);
+    }
+  else
+    {
+    m_matched = false;
+    }
+
+  setStatusColor(labelRegexMatch, m_matched);
+
+  if(!m_matched)
+    {
+    clearMatch();
+    return;
+    }
+
+#ifdef QT_NO_STL
+  QString matchText = m_regexParser.match(0).c_str();
+#else
+  QString matchText = QString::fromStdString(m_regexParser.match(0));
+#endif
+  match0->setPlainText(matchText);
+
+  on_matchNumber_currentIndexChanged(matchNumber->currentIndex());
+}
+
+void RegexExplorer::on_matchNumber_currentIndexChanged(int index)
+{
+  if(!m_matched)
+    {
+    return;
+    }
+
+  QVariant itemData = matchNumber->itemData(index);
+  int idx = itemData.toInt();
+
+  if(idx < 1 || idx >= cmsys::RegularExpression::NSUBEXP)
+    {
+    return;
+    }
+
+#ifdef QT_NO_STL
+  QString match = m_regexParser.match(idx).c_str();
+#else
+  QString match = QString::fromStdString(m_regexParser.match(idx));
+#endif
+  matchN->setPlainText(match);
+}
+
+void RegexExplorer::clearMatch()
+{
+  match0->clear();
+  matchN->clear();
+}
+
+bool RegexExplorer::stripEscapes(std::string& source)
+{
+  const char* in = source.c_str();
+
+  std::string result;
+  result.reserve(source.size());
+
+  for(char inc = *in; inc != '\0'; inc = *++in)
+    {
+    if(inc == '\\')
+      {
+      char nextc = in[1];
+      if(nextc == 't')
+        {
+        result.append(1, '\t');
+        in++;
+        }
+      else if(nextc == 'n')
+        {
+        result.append(1, '\n');
+        in++;
+        }
+      else if(nextc == 't')
+        {
+        result.append(1, '\t');
+        in++;
+        }
+      else if(isalnum(nextc) || nextc == '\0')
+        {
+        return false;
+        }
+      else
+        {
+        result.append(1, nextc);
+        in++;
+        }
+      }
+    else
+      {
+        result.append(1, inc);
+      }
+    }
+
+    source = result;
+    return true;
+}
diff --git a/Source/QtDialog/RegexExplorer.h b/Source/QtDialog/RegexExplorer.h
new file mode 100644
index 0000000..2ac9c3e
--- /dev/null
+++ b/Source/QtDialog/RegexExplorer.h
@@ -0,0 +1,48 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2015 Kitware, Inc., Gregor Jasny
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
+#ifndef RegexExplorer_h
+#define RegexExplorer_h
+
+#include <string>
+#include <cmsys/RegularExpression.hxx>
+#include <QDialog>
+
+#include "ui_RegexExplorer.h"
+
+class QString;
+class QWidget;
+
+class RegexExplorer : public QDialog, public Ui::RegexExplorer
+{
+  Q_OBJECT
+public:
+  RegexExplorer(QWidget* p);
+
+private slots:
+  void on_regularExpression_textChanged(const QString& text);
+  void on_inputText_textChanged();
+  void on_matchNumber_currentIndexChanged(int index);
+
+private:
+  static void setStatusColor(QWidget* widget, bool successful);
+  static bool stripEscapes(std::string& regex);
+
+  void clearMatch();
+
+  cmsys::RegularExpression m_regexParser;
+  std::string m_text;
+  std::string m_regex;
+  bool m_matched;
+};
+
+#endif
diff --git a/Source/QtDialog/RegexExplorer.ui b/Source/QtDialog/RegexExplorer.ui
new file mode 100644
index 0000000..2c2d761
--- /dev/null
+++ b/Source/QtDialog/RegexExplorer.ui
@@ -0,0 +1,155 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>RegexExplorer</class>
+ <widget class="QDialog" name="RegexExplorer">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>639</width>
+    <height>555</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Regular Expression Explorer</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QLabel" name="label">
+     <property name="text">
+      <string>Input Text</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QPlainTextEdit" name="inputText"/>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout_2">
+     <item>
+      <widget class="QLabel" name="label_2">
+       <property name="text">
+        <string>Regular Expression</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_3">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeType">
+        <enum>QSizePolicy::Fixed</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QLabel" name="labelRegexValid">
+       <property name="text">
+        <string>Valid</string>
+       </property>
+       <property name="alignment">
+        <set>Qt::AlignCenter</set>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_4">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeType">
+        <enum>QSizePolicy::Fixed</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QLabel" name="labelRegexMatch">
+       <property name="text">
+        <string>Match</string>
+       </property>
+       <property name="alignment">
+        <set>Qt::AlignCenter</set>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_2">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QLineEdit" name="regularExpression"/>
+   </item>
+   <item>
+    <widget class="QLabel" name="label_3">
+     <property name="text">
+      <string>Complete Match</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QPlainTextEdit" name="match0">
+     <property name="readOnly">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QComboBox" name="matchNumber">
+       <property name="editable">
+        <bool>false</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QPlainTextEdit" name="matchN">
+     <property name="readOnly">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Source/QtDialog/WarningMessagesDialog.cxx b/Source/QtDialog/WarningMessagesDialog.cxx
new file mode 100644
index 0000000..4bd541f
--- /dev/null
+++ b/Source/QtDialog/WarningMessagesDialog.cxx
@@ -0,0 +1,99 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2015 Kitware, Inc., Gregor Jasny
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
+#include "WarningMessagesDialog.h"
+
+WarningMessagesDialog::WarningMessagesDialog(QWidget* prnt, QCMake* instance)
+  : QDialog(prnt), cmakeInstance(instance)
+{
+  this->setupUi(this);
+  this->setInitialValues();
+  this->setupSignals();
+}
+
+void WarningMessagesDialog::setInitialValues()
+{
+  this->suppressDeveloperWarnings->setChecked(
+    this->cmakeInstance->getSuppressDevWarnings());
+  this->suppressDeprecatedWarnings->setChecked(
+    this->cmakeInstance->getSuppressDeprecatedWarnings());
+
+  this->developerWarningsAsErrors->setChecked(
+    this->cmakeInstance->getDevWarningsAsErrors());
+  this->deprecatedWarningsAsErrors->setChecked(
+    this->cmakeInstance->getDeprecatedWarningsAsErrors());
+}
+
+void WarningMessagesDialog::setupSignals()
+{
+  QObject::connect(this->buttonBox, SIGNAL(accepted()),
+                   this, SLOT(doAccept()));
+
+  QObject::connect(this->suppressDeveloperWarnings, SIGNAL(stateChanged(int)),
+                   this, SLOT(doSuppressDeveloperWarningsChanged(int)));
+  QObject::connect(this->suppressDeprecatedWarnings, SIGNAL(stateChanged(int)),
+                   this, SLOT(doSuppressDeprecatedWarningsChanged(int)));
+
+  QObject::connect(this->developerWarningsAsErrors, SIGNAL(stateChanged(int)),
+                   this, SLOT(doDeveloperWarningsAsErrorsChanged(int)));
+  QObject::connect(this->deprecatedWarningsAsErrors, SIGNAL(stateChanged(int)),
+                   this, SLOT(doDeprecatedWarningsAsErrorsChanged(int)));
+}
+
+void WarningMessagesDialog::doAccept()
+{
+  this->cmakeInstance->setSuppressDevWarnings(
+    this->suppressDeveloperWarnings->isChecked());
+  this->cmakeInstance->setSuppressDeprecatedWarnings(
+    this->suppressDeprecatedWarnings->isChecked());
+
+  this->cmakeInstance->setDevWarningsAsErrors(
+    this->developerWarningsAsErrors->isChecked());
+  this->cmakeInstance->setDeprecatedWarningsAsErrors(
+    this->deprecatedWarningsAsErrors->isChecked());
+}
+
+void WarningMessagesDialog::doSuppressDeveloperWarningsChanged(int state)
+{
+  // no warnings implies no errors either
+  if (state)
+    {
+    this->developerWarningsAsErrors->setChecked(false);
+    }
+}
+
+void WarningMessagesDialog::doSuppressDeprecatedWarningsChanged(int state)
+{
+  // no warnings implies no errors either
+  if (state)
+    {
+    this->deprecatedWarningsAsErrors->setChecked(false);
+    }
+}
+
+void WarningMessagesDialog::doDeveloperWarningsAsErrorsChanged(int state)
+{
+  // warnings as errors implies warnings are not suppressed
+  if (state)
+    {
+    this->suppressDeveloperWarnings->setChecked(false);
+    }
+}
+
+void WarningMessagesDialog::doDeprecatedWarningsAsErrorsChanged(int state)
+{
+  // warnings as errors implies warnings are not suppressed
+  if (state)
+    {
+    this->suppressDeprecatedWarnings->setChecked(false);
+    }
+}
diff --git a/Source/QtDialog/WarningMessagesDialog.h b/Source/QtDialog/WarningMessagesDialog.h
new file mode 100644
index 0000000..6c274a7
--- /dev/null
+++ b/Source/QtDialog/WarningMessagesDialog.h
@@ -0,0 +1,75 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2015 Kitware, Inc., Gregor Jasny
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
+#ifndef WarningMessagesDialog_h
+#define WarningMessagesDialog_h
+
+#include <QDialog>
+#include <QWidget>
+
+#include "ui_WarningMessagesDialog.h"
+#include "QCMake.h"
+
+/**
+ * Dialog window for setting the warning message related options.
+ */
+class WarningMessagesDialog : public QDialog, public Ui_MessagesDialog
+{
+  Q_OBJECT
+
+public:
+  WarningMessagesDialog(QWidget* prnt, QCMake* instance);
+
+private slots:
+  /**
+   * Handler for the accept event of the ok/cancel button box.
+   */
+  void doAccept();
+
+  /**
+   * Handler for checked state changed event of the suppress developer warnings
+   * checkbox.
+   */
+  void doSuppressDeveloperWarningsChanged(int state);
+  /**
+   * Handler for checked state changed event of the suppress deprecated
+   * warnings checkbox.
+   */
+  void doSuppressDeprecatedWarningsChanged(int state);
+
+  /**
+   * Handler for checked state changed event of the developer warnings as
+   * errors checkbox.
+   */
+  void doDeveloperWarningsAsErrorsChanged(int state);
+  /**
+   * Handler for checked state changed event of the deprecated warnings as
+   * errors checkbox.
+   */
+  void doDeprecatedWarningsAsErrorsChanged(int state);
+
+private:
+  QCMake* cmakeInstance;
+
+  /**
+   * Set the initial values of the widgets on this dialog window, using the
+   * current state of the cache.
+   */
+  void setInitialValues();
+
+  /**
+   * Setup the signals for the widgets on this dialog window.
+   */
+  void setupSignals();
+};
+
+#endif /* MessageDialog_h */
diff --git a/Source/QtDialog/WarningMessagesDialog.ui b/Source/QtDialog/WarningMessagesDialog.ui
new file mode 100644
index 0000000..3b35cbc
--- /dev/null
+++ b/Source/QtDialog/WarningMessagesDialog.ui
@@ -0,0 +1,173 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MessagesDialog</class>
+ <widget class="QDialog" name="MessagesDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>300</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Warning Messages</string>
+  </property>
+  <property name="modal">
+   <bool>true</bool>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QGroupBox" name="groupBox">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="title">
+      <string>Suppress Warnings</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout_2">
+      <item>
+       <widget class="QCheckBox" name="suppressDeveloperWarnings">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="toolTip">
+         <string>Suppress developer (author) warnings.</string>
+        </property>
+        <property name="text">
+         <string>Developer Warnings</string>
+        </property>
+        <property name="tristate">
+         <bool>false</bool>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QCheckBox" name="suppressDeprecatedWarnings">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="toolTip">
+         <string>Suppress deprecated warnings.</string>
+        </property>
+        <property name="text">
+         <string>Deprecated Warnings</string>
+        </property>
+        <property name="tristate">
+         <bool>false</bool>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="groupBox_2">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="title">
+      <string>Warnings as Errors</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout_3">
+      <item>
+       <widget class="QCheckBox" name="developerWarningsAsErrors">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="toolTip">
+         <string>Treat developer (author) warnings as errors.</string>
+        </property>
+        <property name="text">
+         <string>Developer Warnings as Errors</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QCheckBox" name="deprecatedWarningsAsErrors">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="toolTip">
+         <string>Treat deprecated warnings as errors.</string>
+        </property>
+        <property name="text">
+         <string>Deprecated Warnings as Errors</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>MessagesDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>MessagesDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
diff --git a/Source/bindexplib.cxx b/Source/bindexplib.cxx
index b250842..e7263ae 100644
--- a/Source/bindexplib.cxx
+++ b/Source/bindexplib.cxx
@@ -70,7 +70,7 @@
 * Author:   Valery Fine 16/09/96  (E-mail: fine at vxcern.cern.ch)
 *----------------------------------------------------------------------
 */
-
+#include "bindexplib.h"
 #include <cmsys/Encoding.hxx>
 #include <windows.h>
 #include <stdio.h>
@@ -173,15 +173,17 @@ public:
    */
 
    DumpSymbols(ObjectHeaderType* ih,
-               FILE* fout, bool is64) {
+               std::set<std::string>& symbols,
+               std::set<std::string>& dataSymbols,
+               bool is64)
+     :Symbols(symbols), DataSymbols(dataSymbols)
+    {
       this->ObjectImageHeader = ih;
       this->SymbolTable = (SymbolTableType*)
       ((DWORD_PTR)this->ObjectImageHeader
        + this->ObjectImageHeader->PointerToSymbolTable);
-      this->FileOut = fout;
       this->SectionHeaders =
         GetSectionHeaderOffset(this->ObjectImageHeader);
-      this->ImportFlag = true;
       this->SymbolCount = this->ObjectImageHeader->NumberOfSymbols;
       this->Is64Bit = is64;
    }
@@ -296,10 +298,6 @@ public:
                 symbol.erase(0,1);
                 }
               }
-            if (this->ImportFlag) {
-               this->ImportFlag = false;
-               fprintf(this->FileOut,"EXPORTS \n");
-            }
             /*
             Check whether it is "Scalar deleting destructor" and
             "Vector deleting destructor"
@@ -319,11 +317,11 @@ public:
                  SectionHeaders[pSymbolTable->SectionNumber-1].Characteristics;
                if (!pSymbolTable->Type  && (SectChar & IMAGE_SCN_MEM_WRITE)) {
                   // Read only (i.e. constants) must be excluded
-                  fprintf(this->FileOut, "\t%s \t DATA\n", symbol.c_str());
+                  this->DataSymbols.insert(symbol);
                } else {
                   if ( pSymbolTable->Type  ||
                        !(SectChar & IMAGE_SCN_MEM_READ)) {
-                     fprintf(this->FileOut, "\t%s\n", symbol.c_str());
+                     this->Symbols.insert(symbol);
                   } else {
                      // printf(" strange symbol: %s \n",symbol.c_str());
                   }
@@ -340,11 +338,7 @@ public:
             symbol = stringTable + pSymbolTable->N.Name.Long;
             while (isspace(symbol[0]))  symbol.erase(0,1);
             if (symbol[0] == '_') symbol.erase(0,1);
-            if (!this->ImportFlag) {
-               this->ImportFlag = true;
-               fprintf(this->FileOut,"IMPORTS \n");
-            }
-            fprintf(this->FileOut, "\t%s DATA \n", symbol.c_str()+1);
+            this->DataSymbols.insert(symbol);
          }
       }
 
@@ -357,8 +351,8 @@ public:
     }
   }
 private:
-  bool ImportFlag;
-  FILE* FileOut;
+  std::set<std::string>& Symbols;
+  std::set<std::string>& DataSymbols;
   DWORD_PTR SymbolCount;
   PIMAGE_SECTION_HEADER SectionHeaders;
   ObjectHeaderType* ObjectImageHeader;
@@ -367,7 +361,9 @@ private:
 };
 
 bool
-DumpFile(const char* filename, FILE *fout)
+DumpFile(const char* filename,
+         std::set<std::string>& symbols,
+         std::set<std::string>& dataSymbols)
 {
    HANDLE hFile;
    HANDLE hFileMapping;
@@ -415,7 +411,7 @@ DumpFile(const char* filename, FILE *fout)
       * and IMAGE_FILE_HEADER.SizeOfOptionalHeader == 0;
       */
       DumpSymbols<IMAGE_FILE_HEADER, IMAGE_SYMBOL>
-        symbolDumper((PIMAGE_FILE_HEADER) lpFileBase, fout,
+        symbolDumper((PIMAGE_FILE_HEADER) lpFileBase, symbols, dataSymbols,
                      (dosHeader->e_magic == IMAGE_FILE_MACHINE_AMD64));
       symbolDumper.DumpObjFile();
    } else {
@@ -424,7 +420,8 @@ DumpFile(const char* filename, FILE *fout)
         (cmANON_OBJECT_HEADER_BIGOBJ*) lpFileBase;
       if(h->Sig1 == 0x0 && h->Sig2 == 0xffff) {
          DumpSymbols<cmANON_OBJECT_HEADER_BIGOBJ, cmIMAGE_SYMBOL_EX>
-           symbolDumper((cmANON_OBJECT_HEADER_BIGOBJ*) lpFileBase, fout,
+           symbolDumper((cmANON_OBJECT_HEADER_BIGOBJ*) lpFileBase, symbols,
+                        dataSymbols,
                         (h->Machine == IMAGE_FILE_MACHINE_AMD64));
          symbolDumper.DumpObjFile();
       } else {
@@ -437,3 +434,27 @@ DumpFile(const char* filename, FILE *fout)
    CloseHandle(hFile);
    return true;
 }
+
+bool bindexplib::AddObjectFile(const char* filename)
+{
+  if(!DumpFile(filename, this->Symbols, this->DataSymbols))
+    {
+    return false;
+    }
+  return true;
+}
+
+void bindexplib::WriteFile(FILE* file)
+{
+  fprintf(file,"EXPORTS \n");
+  for(std::set<std::string>::const_iterator i = this->DataSymbols.begin();
+      i!= this->DataSymbols.end(); ++i)
+    {
+    fprintf(file, "\t%s \t DATA\n", i->c_str());
+    }
+  for(std::set<std::string>::const_iterator i = this->Symbols.begin();
+      i!= this->Symbols.end(); ++i)
+    {
+    fprintf(file, "\t%s\n", i->c_str());
+    }
+}
diff --git a/Utilities/KWIML/test/test_INT_C.c b/Source/bindexplib.h
similarity index 54%
rename from Utilities/KWIML/test/test_INT_C.c
rename to Source/bindexplib.h
index 5513a0b..8661a4a 100644
--- a/Utilities/KWIML/test/test_INT_C.c
+++ b/Source/bindexplib.h
@@ -1,6 +1,6 @@
 /*============================================================================
-  Kitware Information Macro Library
-  Copyright 2010-2011 Kitware, Inc.
+  CMake - Cross Platform Makefile Generator
+  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
 
   Distributed under the OSI-approved BSD License (the "License");
   see accompanying file Copyright.txt for details.
@@ -9,14 +9,21 @@
   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   See the License for more information.
 ============================================================================*/
-#include "test.h"
-#include KWIML_HEADER(INT.h)
-#include "test_INT_format.h"
-int test_INT_C(void)
+
+#ifndef bindexplib_h
+#define bindexplib_h
+
+#include "cmStandardIncludes.h"
+
+
+class bindexplib
 {
-  if(!test_INT_format())
-    {
-    return 0;
-    }
-  return 1;
-}
+public:
+  bindexplib() {}
+  bool AddObjectFile(const char* filename);
+  void WriteFile(FILE* file);
+private:
+  std::set<std::string> Symbols;
+  std::set<std::string> DataSymbols;
+};
+#endif
diff --git a/Source/cmAddDependenciesCommand.cxx b/Source/cmAddDependenciesCommand.cxx
index 3a74946..01e5253 100644
--- a/Source/cmAddDependenciesCommand.cxx
+++ b/Source/cmAddDependenciesCommand.cxx
@@ -10,7 +10,6 @@
   See the License for more information.
 ============================================================================*/
 #include "cmAddDependenciesCommand.h"
-#include "cmLocalGenerator.h"
 #include "cmGlobalGenerator.h"
 
 // cmDependenciesCommand
diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx
index d15fc1e..a84bb9d 100644
--- a/Source/cmAddExecutableCommand.cxx
+++ b/Source/cmAddExecutableCommand.cxx
@@ -174,8 +174,8 @@ bool cmAddExecutableCommand
       this->SetError(e.str());
       return false;
       }
-    cmTarget::TargetType type = aliasedTarget->GetType();
-    if(type != cmTarget::EXECUTABLE)
+    cmState::TargetType type = aliasedTarget->GetType();
+    if(type != cmState::EXECUTABLE)
       {
       std::ostringstream e;
       e << "cannot create ALIAS target \"" << exename
@@ -192,7 +192,7 @@ bool cmAddExecutableCommand
       this->SetError(e.str());
       return false;
       }
-    this->Makefile->AddAlias(exename, aliasedTarget);
+    this->Makefile->AddAlias(exename, aliasedName);
     return true;
     }
 
@@ -210,7 +210,7 @@ bool cmAddExecutableCommand
       }
 
     // Create the imported target.
-    this->Makefile->AddImportedTarget(exename, cmTarget::EXECUTABLE,
+    this->Makefile->AddImportedTarget(exename, cmState::EXECUTABLE,
                                       importGlobal);
     return true;
     }
diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx
index a844cf1..5296cbb 100644
--- a/Source/cmAddLibraryCommand.cxx
+++ b/Source/cmAddLibraryCommand.cxx
@@ -25,10 +25,10 @@ bool cmAddLibraryCommand
     }
   // Library type defaults to value of BUILD_SHARED_LIBS, if it exists,
   // otherwise it defaults to static library.
-  cmTarget::TargetType type = cmTarget::SHARED_LIBRARY;
+  cmState::TargetType type = cmState::SHARED_LIBRARY;
   if (cmSystemTools::IsOff(this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
     {
-    type = cmTarget::STATIC_LIBRARY;
+    type = cmState::STATIC_LIBRARY;
     }
   bool excludeFromAll = false;
   bool importTarget = false;
@@ -50,7 +50,7 @@ bool cmAddLibraryCommand
     std::string libType = *s;
     if(libType == "STATIC")
       {
-      if (type == cmTarget::INTERFACE_LIBRARY)
+      if (type == cmState::INTERFACE_LIBRARY)
         {
         std::ostringstream e;
         e << "INTERFACE library specified with conflicting STATIC type.";
@@ -58,12 +58,12 @@ bool cmAddLibraryCommand
         return false;
         }
       ++s;
-      type = cmTarget::STATIC_LIBRARY;
+      type = cmState::STATIC_LIBRARY;
       haveSpecifiedType = true;
       }
     else if(libType == "SHARED")
       {
-      if (type == cmTarget::INTERFACE_LIBRARY)
+      if (type == cmState::INTERFACE_LIBRARY)
         {
         std::ostringstream e;
         e << "INTERFACE library specified with conflicting SHARED type.";
@@ -71,12 +71,12 @@ bool cmAddLibraryCommand
         return false;
         }
       ++s;
-      type = cmTarget::SHARED_LIBRARY;
+      type = cmState::SHARED_LIBRARY;
       haveSpecifiedType = true;
       }
     else if(libType == "MODULE")
       {
-      if (type == cmTarget::INTERFACE_LIBRARY)
+      if (type == cmState::INTERFACE_LIBRARY)
         {
         std::ostringstream e;
         e << "INTERFACE library specified with conflicting MODULE type.";
@@ -84,12 +84,12 @@ bool cmAddLibraryCommand
         return false;
         }
       ++s;
-      type = cmTarget::MODULE_LIBRARY;
+      type = cmState::MODULE_LIBRARY;
       haveSpecifiedType = true;
       }
     else if(libType == "OBJECT")
       {
-      if (type == cmTarget::INTERFACE_LIBRARY)
+      if (type == cmState::INTERFACE_LIBRARY)
         {
         std::ostringstream e;
         e << "INTERFACE library specified with conflicting OBJECT type.";
@@ -97,12 +97,12 @@ bool cmAddLibraryCommand
         return false;
         }
       ++s;
-      type = cmTarget::OBJECT_LIBRARY;
+      type = cmState::OBJECT_LIBRARY;
       haveSpecifiedType = true;
       }
     else if(libType == "UNKNOWN")
       {
-      if (type == cmTarget::INTERFACE_LIBRARY)
+      if (type == cmState::INTERFACE_LIBRARY)
         {
         std::ostringstream e;
         e << "INTERFACE library specified with conflicting UNKNOWN type.";
@@ -110,12 +110,12 @@ bool cmAddLibraryCommand
         return false;
         }
       ++s;
-      type = cmTarget::UNKNOWN_LIBRARY;
+      type = cmState::UNKNOWN_LIBRARY;
       haveSpecifiedType = true;
       }
     else if(libType == "ALIAS")
       {
-      if (type == cmTarget::INTERFACE_LIBRARY)
+      if (type == cmState::INTERFACE_LIBRARY)
         {
         std::ostringstream e;
         e << "INTERFACE library specified with conflicting ALIAS type.";
@@ -149,12 +149,12 @@ bool cmAddLibraryCommand
         return false;
         }
       ++s;
-      type = cmTarget::INTERFACE_LIBRARY;
+      type = cmState::INTERFACE_LIBRARY;
       haveSpecifiedType = true;
       }
     else if(*s == "EXCLUDE_FROM_ALL")
       {
-      if (type == cmTarget::INTERFACE_LIBRARY)
+      if (type == cmState::INTERFACE_LIBRARY)
         {
         std::ostringstream e;
         e << "INTERFACE library may not be used with EXCLUDE_FROM_ALL.";
@@ -174,7 +174,7 @@ bool cmAddLibraryCommand
       ++s;
       importGlobal = true;
       }
-    else if(type == cmTarget::INTERFACE_LIBRARY && *s == "GLOBAL")
+    else if(type == cmState::INTERFACE_LIBRARY && *s == "GLOBAL")
       {
       std::ostringstream e;
       e << "GLOBAL option may only be used with IMPORTED libraries.";
@@ -187,7 +187,7 @@ bool cmAddLibraryCommand
       }
     }
 
-  if (type == cmTarget::INTERFACE_LIBRARY)
+  if (type == cmState::INTERFACE_LIBRARY)
     {
     if (s != args.end())
       {
@@ -220,7 +220,7 @@ bool cmAddLibraryCommand
     switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0037))
       {
       case cmPolicies::WARN:
-        if(type != cmTarget::INTERFACE_LIBRARY)
+        if(type != cmState::INTERFACE_LIBRARY)
           {
           e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0037) << "\n";
           issueMessage = true;
@@ -293,12 +293,12 @@ bool cmAddLibraryCommand
       this->SetError(e.str());
       return false;
       }
-    cmTarget::TargetType aliasedType = aliasedTarget->GetType();
-    if(aliasedType != cmTarget::SHARED_LIBRARY
-        && aliasedType != cmTarget::STATIC_LIBRARY
-        && aliasedType != cmTarget::MODULE_LIBRARY
-        && aliasedType != cmTarget::OBJECT_LIBRARY
-        && aliasedType != cmTarget::INTERFACE_LIBRARY)
+    cmState::TargetType aliasedType = aliasedTarget->GetType();
+    if(aliasedType != cmState::SHARED_LIBRARY
+        && aliasedType != cmState::STATIC_LIBRARY
+        && aliasedType != cmState::MODULE_LIBRARY
+        && aliasedType != cmState::OBJECT_LIBRARY
+        && aliasedType != cmState::INTERFACE_LIBRARY)
       {
       std::ostringstream e;
       e << "cannot create ALIAS target \"" << libName
@@ -314,7 +314,7 @@ bool cmAddLibraryCommand
       this->SetError(e.str());
       return false;
       }
-    this->Makefile->AddAlias(libName, aliasedTarget);
+    this->Makefile->AddAlias(libName, aliasedName);
     return true;
     }
 
@@ -328,19 +328,19 @@ bool cmAddLibraryCommand
     CMAKE_${LANG}_CREATE_SHARED_LIBRARY is defined and if not default to
     STATIC. But at this point we know only the name of the target, but not
     yet its linker language. */
-  if ((type == cmTarget::SHARED_LIBRARY ||
-       type == cmTarget::MODULE_LIBRARY) &&
+  if ((type == cmState::SHARED_LIBRARY ||
+       type == cmState::MODULE_LIBRARY) &&
        (this->Makefile->GetState()->GetGlobalPropertyAsBool(
                                       "TARGET_SUPPORTS_SHARED_LIBS") == false))
     {
     std::ostringstream w;
     w <<
       "ADD_LIBRARY called with " <<
-      (type==cmTarget::SHARED_LIBRARY ? "SHARED" : "MODULE") <<
+      (type==cmState::SHARED_LIBRARY ? "SHARED" : "MODULE") <<
       " option but the target platform does not support dynamic linking. "
       "Building a STATIC library instead. This may lead to problems.";
     this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
-    type = cmTarget::STATIC_LIBRARY;
+    type = cmState::STATIC_LIBRARY;
     }
 
   // Handle imported target creation.
@@ -352,7 +352,7 @@ bool cmAddLibraryCommand
       this->SetError("called with IMPORTED argument but no library type.");
       return false;
       }
-    if(type == cmTarget::OBJECT_LIBRARY)
+    if(type == cmState::OBJECT_LIBRARY)
       {
       this->Makefile->IssueMessage(
         cmake::FATAL_ERROR,
@@ -360,7 +360,7 @@ bool cmAddLibraryCommand
         );
       return true;
       }
-    if(type == cmTarget::INTERFACE_LIBRARY)
+    if(type == cmState::INTERFACE_LIBRARY)
       {
       if (!cmGeneratorExpression::IsValidTargetName(libName))
         {
@@ -387,7 +387,7 @@ bool cmAddLibraryCommand
     }
 
   // A non-imported target may not have UNKNOWN type.
-  if(type == cmTarget::UNKNOWN_LIBRARY)
+  if(type == cmState::UNKNOWN_LIBRARY)
     {
     this->Makefile->IssueMessage(
       cmake::FATAL_ERROR,
@@ -408,7 +408,7 @@ bool cmAddLibraryCommand
 
   std::vector<std::string> srclists;
 
-  if(type == cmTarget::INTERFACE_LIBRARY)
+  if(type == cmState::INTERFACE_LIBRARY)
     {
     if (!cmGeneratorExpression::IsValidTargetName(libName)
         || libName.find("::") != std::string::npos)
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h
index bda933b..bb65ea5 100644
--- a/Source/cmAlgorithms.h
+++ b/Source/cmAlgorithms.h
@@ -52,13 +52,13 @@ template<typename T, size_t N>
 size_t cmArraySize(const T (&)[N]) { return N; }
 
 template<typename T, size_t N>
-bool cmHasLiteralPrefix(T str1, const char (&str2)[N])
+bool cmHasLiteralPrefix(const T& str1, const char (&str2)[N])
 {
   return cmHasLiteralPrefixImpl(str1, str2, N - 1);
 }
 
 template<typename T, size_t N>
-bool cmHasLiteralSuffix(T str1, const char (&str2)[N])
+bool cmHasLiteralSuffix(const T& str1, const char (&str2)[N])
 {
   return cmHasLiteralSuffixImpl(str1, str2, N - 1);
 }
@@ -162,13 +162,13 @@ struct cmRange
   const_iterator end() const { return End; }
   bool empty() const { return std::distance(Begin, End) == 0; }
   difference_type size() const { return std::distance(Begin, End); }
-  cmRange& advance(cmIML_INT_intptr_t amount)
+  cmRange& advance(KWIML_INT_intptr_t amount)
   {
     std::advance(Begin, amount);
     return *this;
   }
 
-  cmRange& retreat(cmIML_INT_intptr_t amount)
+  cmRange& retreat(KWIML_INT_intptr_t amount)
   {
     std::advance(End, -amount);
     return *this;
@@ -230,7 +230,7 @@ template<typename Range>
 std::string cmJoin(Range const& r, std::string delimiter)
 {
   return cmJoin(r, delimiter.c_str());
-};
+}
 
 template<typename Range>
 typename Range::const_iterator cmRemoveN(Range& r, size_t n)
diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx
index 7946950..e62a2ed 100644
--- a/Source/cmArchiveWrite.cxx
+++ b/Source/cmArchiveWrite.cxx
@@ -18,6 +18,10 @@
 #include <cm_libarchive.h>
 #include "cm_get_date.h"
 
+#ifndef __LA_SSIZE_T
+# define __LA_SSIZE_T la_ssize_t
+#endif
+
 //----------------------------------------------------------------------------
 static std::string cm_archive_error_string(struct archive* a)
 {
diff --git a/Source/cmAuxSourceDirectoryCommand.cxx b/Source/cmAuxSourceDirectoryCommand.cxx
index 5f5017d..92ac07d 100644
--- a/Source/cmAuxSourceDirectoryCommand.cxx
+++ b/Source/cmAuxSourceDirectoryCommand.cxx
@@ -60,10 +60,10 @@ bool cmAuxSourceDirectoryCommand::InitialPass
         std::string ext = file.substr(dotpos+1);
         std::string base = file.substr(0, dotpos);
         // Process only source files
-        if(!base.empty()
-            && std::find( this->Makefile->GetSourceExtensions().begin(),
-                          this->Makefile->GetSourceExtensions().end(), ext )
-                 != this->Makefile->GetSourceExtensions().end() )
+        std::vector<std::string> srcExts =
+            this->Makefile->GetCMakeInstance()->GetSourceExtensions();
+        if(!base.empty() &&
+           std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end())
           {
           std::string fullname = templateDirectory;
           fullname += "/";
diff --git a/Source/cmBootstrapCommands1.cxx b/Source/cmBootstrapCommands1.cxx
index 1184514..0782b3b 100644
--- a/Source/cmBootstrapCommands1.cxx
+++ b/Source/cmBootstrapCommands1.cxx
@@ -54,6 +54,7 @@
 #include "cmFunctionCommand.cxx"
 #include "cmPathLabel.cxx"
 #include "cmSearchPath.cxx"
+#include "cmParseArgumentsCommand.cxx"
 
 void GetBootstrapCommands1(std::vector<cmCommand*>& commands)
 {
@@ -91,4 +92,5 @@ void GetBootstrapCommands1(std::vector<cmCommand*>& commands)
   commands.push_back(new cmFindProgramCommand);
   commands.push_back(new cmForEachCommand);
   commands.push_back(new cmFunctionCommand);
+  commands.push_back(new cmParseArgumentsCommand);
 }
diff --git a/Source/cmBuildCommand.cxx b/Source/cmBuildCommand.cxx
index 62fafa5..64d4fca 100644
--- a/Source/cmBuildCommand.cxx
+++ b/Source/cmBuildCommand.cxx
@@ -11,7 +11,6 @@
 ============================================================================*/
 #include "cmBuildCommand.h"
 
-#include "cmLocalGenerator.h"
 #include "cmGlobalGenerator.h"
 
 //----------------------------------------------------------------------
diff --git a/Source/cmCPackPropertiesGenerator.cxx b/Source/cmCPackPropertiesGenerator.cxx
index cbcdd81..35b3d59 100644
--- a/Source/cmCPackPropertiesGenerator.cxx
+++ b/Source/cmCPackPropertiesGenerator.cxx
@@ -18,7 +18,7 @@ void cmCPackPropertiesGenerator::GenerateScriptForConfig(std::ostream& os,
   const std::string& config, Indent const& indent)
 {
   std::string const& expandedFileName =
-      this->InstalledFile.GetNameExpression().Evaluate(this->LG->GetMakefile(),
+      this->InstalledFile.GetNameExpression().Evaluate(this->LG,
                                                        config);
 
   cmInstalledFile::PropertyMapType const& properties =
@@ -38,7 +38,7 @@ void cmCPackPropertiesGenerator::GenerateScriptForConfig(std::ostream& os,
       j = property.ValueExpressions.begin();
       j != property.ValueExpressions.end(); ++j)
       {
-      std::string value = (*j)->Evaluate(LG->GetMakefile(), config);
+      std::string value = (*j)->Evaluate(this->LG, config);
       os << " " << cmOutputConverter::EscapeForCMake(value);
       }
 
diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx
index 7da334e..fb78446 100644
--- a/Source/cmCPluginAPI.cxx
+++ b/Source/cmCPluginAPI.cxx
@@ -51,14 +51,14 @@ void CCONV cmSetError(void *info, const char *err)
 unsigned int CCONV  cmGetCacheMajorVersion(void *arg)
 {
   cmMakefile *mf = static_cast<cmMakefile *>(arg);
-  cmCacheManager *manager = mf->GetCMakeInstance()->GetCacheManager();
-  return manager->GetCacheMajorVersion();
+  cmState *state = mf->GetState();
+  return state->GetCacheMajorVersion();
 }
 unsigned int CCONV cmGetCacheMinorVersion(void *arg)
 {
   cmMakefile *mf = static_cast<cmMakefile *>(arg);
-  cmCacheManager *manager = mf->GetCMakeInstance()->GetCacheManager();
-  return manager->GetCacheMinorVersion();
+  cmState *state = mf->GetState();
+  return state->GetCacheMinorVersion();
 }
 
 unsigned int CCONV cmGetMajorVersion(void *)
@@ -116,7 +116,7 @@ const char* CCONV cmGetProjectName(void *arg)
 {
   cmMakefile *mf = static_cast<cmMakefile *>(arg);
   static std::string name;
-  name = mf->GetProjectName();
+  name = mf->GetStateSnapshot().GetProjectName();
   return name.c_str();
 }
 
@@ -373,13 +373,13 @@ void CCONV cmAddLinkLibraryForTarget(void *arg, const char *tgt,
   switch (libtype)
     {
     case CM_LIBRARY_GENERAL:
-      mf->AddLinkLibraryForTarget(tgt,value, cmTarget::GENERAL);
+      mf->AddLinkLibraryForTarget(tgt,value, GENERAL_LibraryType);
       break;
     case CM_LIBRARY_DEBUG:
-      mf->AddLinkLibraryForTarget(tgt,value, cmTarget::DEBUG);
+      mf->AddLinkLibraryForTarget(tgt,value, DEBUG_LibraryType);
       break;
     case CM_LIBRARY_OPTIMIZED:
-      mf->AddLinkLibraryForTarget(tgt,value, cmTarget::OPTIMIZED);
+      mf->AddLinkLibraryForTarget(tgt,value, OPTIMIZED_LibraryType);
       break;
     }
 }
@@ -395,7 +395,7 @@ void CCONV cmAddLibrary(void *arg, const char *libname, int shared,
     srcs2.push_back(srcs[i]);
     }
   mf->AddLibrary(libname,
-                 (shared? cmTarget::SHARED_LIBRARY : cmTarget::STATIC_LIBRARY),
+                 (shared? cmState::SHARED_LIBRARY : cmState::STATIC_LIBRARY),
                   srcs2);
 }
 
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index 6e55d89..f3e7121 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -14,7 +14,6 @@
 #include "cmCTest.h"
 #include "cmake.h"
 #include "cmMakefile.h"
-#include "cmLocalGenerator.h"
 #include "cmGlobalGenerator.h"
 #include <cmsys/Base64.h>
 #include <cmsys/Directory.hxx>
@@ -518,9 +517,9 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
   cmake cm;
   cm.SetHomeDirectory("");
   cm.SetHomeOutputDirectory("");
+  cm.GetCurrentSnapshot().SetDefaultDefinitions();
   cmGlobalGenerator gg(&cm);
   cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
-  cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator(mf.get()));
   if ( !this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(),
                                               mf.get()) )
     {
diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx
index 54209c5..7466c29 100644
--- a/Source/cmCacheManager.cxx
+++ b/Source/cmCacheManager.cxx
@@ -13,7 +13,6 @@
 #include "cmCacheManager.h"
 #include "cmSystemTools.h"
 #include "cmGeneratedFileStream.h"
-#include "cmMakefile.h"
 #include "cmake.h"
 #include "cmVersion.h"
 
@@ -22,101 +21,10 @@
 #include <cmsys/FStream.hxx>
 #include <cmsys/RegularExpression.hxx>
 
-cmCacheManager::cmCacheManager(cmake* cm)
+cmCacheManager::cmCacheManager()
 {
   this->CacheMajorVersion = 0;
   this->CacheMinorVersion = 0;
-  this->CMakeInstance = cm;
-}
-
-bool cmCacheManager::LoadCache(const std::string& path)
-{
-  std::set<std::string> emptySet;
-  return this->LoadCache(path, true, emptySet, emptySet);
-}
-
-static bool ParseEntryWithoutType(const std::string& entry,
-                                  std::string& var,
-                                  std::string& value)
-{
-  // input line is:         key=value
-  static cmsys::RegularExpression reg(
-    "^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
-  // input line is:         "key"=value
-  static cmsys::RegularExpression regQuoted(
-    "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
-  bool flag = false;
-  if(regQuoted.find(entry))
-    {
-    var = regQuoted.match(1);
-    value = regQuoted.match(2);
-    flag = true;
-    }
-  else if (reg.find(entry))
-    {
-    var = reg.match(1);
-    value = reg.match(2);
-    flag = true;
-    }
-
-  // if value is enclosed in single quotes ('foo') then remove them
-  // it is used to enclose trailing space or tab
-  if (flag &&
-      value.size() >= 2 &&
-      value[0] == '\'' &&
-      value[value.size() - 1] == '\'')
-    {
-    value = value.substr(1,
-                         value.size() - 2);
-    }
-
-  return flag;
-}
-
-bool cmCacheManager::ParseEntry(const std::string& entry,
-                                std::string& var,
-                                std::string& value,
-                                cmState::CacheEntryType& type)
-{
-  // input line is:         key:type=value
-  static cmsys::RegularExpression reg(
-    "^([^=:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
-  // input line is:         "key":type=value
-  static cmsys::RegularExpression regQuoted(
-    "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
-  bool flag = false;
-  if(regQuoted.find(entry))
-    {
-    var = regQuoted.match(1);
-    type = cmState::StringToCacheEntryType(regQuoted.match(2).c_str());
-    value = regQuoted.match(3);
-    flag = true;
-    }
-  else if (reg.find(entry))
-    {
-    var = reg.match(1);
-    type = cmState::StringToCacheEntryType(reg.match(2).c_str());
-    value = reg.match(3);
-    flag = true;
-    }
-
-  // if value is enclosed in single quotes ('foo') then remove them
-  // it is used to enclose trailing space or tab
-  if (flag &&
-      value.size() >= 2 &&
-      value[0] == '\'' &&
-      value[value.size() - 1] == '\'')
-    {
-    value = value.substr(1,
-                         value.size() - 2);
-    }
-
-  if (!flag)
-    {
-    return ParseEntryWithoutType(entry, var, value);
-    }
-
-  return flag;
 }
 
 void cmCacheManager::CleanCMakeFiles(const std::string& path)
@@ -156,12 +64,14 @@ bool cmCacheManager::LoadCache(const std::string& path,
   const char *realbuffer;
   std::string buffer;
   std::string entryKey;
+  unsigned int lineno = 0;
   while(fin)
     {
     // Format is key:type=value
     std::string helpString;
     CacheEntry e;
     cmSystemTools::GetLineFromStream(fin, buffer);
+    lineno++;
     realbuffer = buffer.c_str();
     while(*realbuffer != '0' &&
           (*realbuffer == ' ' ||
@@ -169,6 +79,7 @@ bool cmCacheManager::LoadCache(const std::string& path,
            *realbuffer == '\r' ||
            *realbuffer == '\n'))
       {
+      if (*realbuffer == '\n') lineno++;
       realbuffer++;
       }
     // skip blank lines and comment lines
@@ -188,6 +99,7 @@ bool cmCacheManager::LoadCache(const std::string& path,
         helpString += &realbuffer[2];
         }
       cmSystemTools::GetLineFromStream(fin, buffer);
+      lineno++;
       realbuffer = buffer.c_str();
       if(!fin)
         {
@@ -195,7 +107,7 @@ bool cmCacheManager::LoadCache(const std::string& path,
         }
       }
     e.SetProperty("HELPSTRING", helpString.c_str());
-    if(cmCacheManager::ParseEntry(realbuffer, entryKey, e.Value, e.Type))
+    if(cmState::ParseCacheEntry(realbuffer, entryKey, e.Value, e.Type))
       {
       if ( excludes.find(entryKey) == excludes.end() )
         {
@@ -230,8 +142,10 @@ bool cmCacheManager::LoadCache(const std::string& path,
       }
     else
       {
-      cmSystemTools::Error("Parse error in cache file ", cacheFile.c_str(),
-                           ". Offending entry: ", realbuffer);
+      std::ostringstream error;
+      error << "Parse error in cache file " << cacheFile;
+      error << " on line " << lineno << ". Offending entry: " << realbuffer;
+      cmSystemTools::Error(error.str().c_str());
       }
     }
   this->CacheMajorVersion = 0;
@@ -678,7 +592,6 @@ void cmCacheManager::AddCacheEntry(const std::string& key,
     }
   e.SetProperty("HELPSTRING", helpString? helpString :
                 "(This variable does not exist and should not be used)");
-  this->CMakeInstance->UnwatchUnusedCli(key);
 }
 
 bool cmCacheManager::CacheIterator::IsAtEnd() const
diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h
index 8462259..6f063eb 100644
--- a/Source/cmCacheManager.h
+++ b/Source/cmCacheManager.h
@@ -16,9 +16,7 @@
 #include "cmPropertyMap.h"
 #include "cmState.h"
 
-class cmMakefile;
 class cmMarkAsAdvancedCommand;
-class cmake;
 
 /** \class cmCacheManager
  * \brief Control class for cmake's cache
@@ -29,7 +27,7 @@ class cmake;
 class cmCacheManager
 {
 public:
-  cmCacheManager(cmake* cm);
+  cmCacheManager();
   class CacheIterator;
   friend class cmCacheManager::CacheIterator;
 
@@ -100,7 +98,6 @@ public:
     }
 
   ///! Load a cache for given makefile.  Loads from path/CMakeCache.txt.
-  bool LoadCache(const std::string& path);
   bool LoadCache(const std::string& path, bool internal,
                  std::set<std::string>& excludes,
                  std::set<std::string>& includes);
@@ -124,12 +121,6 @@ public:
   int GetSize() {
     return static_cast<int>(this->Cache.size()); }
 
-  ///! Break up a line like VAR:type="value" into var, type and value
-  static bool ParseEntry(const std::string& entry,
-                         std::string& var,
-                         std::string& value,
-                         cmState::CacheEntryType& type);
-
   ///! Get a value from the cache given a key
   const char* GetInitializedCacheValue(const std::string& key) const;
 
@@ -241,7 +232,7 @@ private:
   void WritePropertyEntries(std::ostream& os, CacheIterator const& i);
 
   CacheEntryMap Cache;
-  // Only cmake and cmMakefile should be able to add cache values
+  // Only cmake and cmState should be able to add cache values
   // the commands should never use the cmCacheManager directly
   friend class cmState; // allow access to add cache values
   friend class cmake; // allow access to add cache values
diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx
index 252e231..76ed038 100644
--- a/Source/cmCommonTargetGenerator.cxx
+++ b/Source/cmCommonTargetGenerator.cxx
@@ -18,7 +18,6 @@
 #include "cmMakefile.h"
 #include "cmSourceFile.h"
 #include "cmSystemTools.h"
-#include "cmTarget.h"
 
 cmCommonTargetGenerator::cmCommonTargetGenerator(
   cmOutputConverter::RelativeRoot wd,
@@ -26,7 +25,6 @@ cmCommonTargetGenerator::cmCommonTargetGenerator(
   )
   : WorkingDirectory(wd)
   , GeneratorTarget(gt)
-  , Target(gt->Target)
   , Makefile(gt->Makefile)
   , LocalGenerator(static_cast<cmLocalCommonGenerator*>(gt->LocalGenerator))
   , GlobalGenerator(static_cast<cmGlobalCommonGenerator*>(
@@ -83,7 +81,7 @@ void cmCommonTargetGenerator::AddFeatureFlags(
 //----------------------------------------------------------------------------
 void cmCommonTargetGenerator::AddModuleDefinitionFlag(std::string& flags)
 {
-  if(this->ModuleDefinitionFile.empty())
+  if(!this->ModuleDefinitionFile)
     {
     return;
     }
@@ -100,7 +98,7 @@ void cmCommonTargetGenerator::AddModuleDefinitionFlag(std::string& flags)
   // vs6's "cl -link" pass it to the linker.
   std::string flag = defFileFlag;
   flag += (this->LocalGenerator->ConvertToLinkReference(
-             this->ModuleDefinitionFile));
+             this->ModuleDefinitionFile->GetFullPath()));
   this->LocalGenerator->AppendFlags(flags, flag);
 }
 
@@ -109,7 +107,7 @@ std::string cmCommonTargetGenerator::ComputeFortranModuleDirectory() const
 {
   std::string mod_dir;
   const char* target_mod_dir =
-    this->Target->GetProperty("Fortran_MODULE_DIRECTORY");
+    this->GeneratorTarget->GetProperty("Fortran_MODULE_DIRECTORY");
   const char* moddir_flag =
     this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG");
   if(target_mod_dir && moddir_flag)
@@ -123,7 +121,7 @@ std::string cmCommonTargetGenerator::ComputeFortranModuleDirectory() const
     else
       {
       // Interpret relative to the current output directory.
-      mod_dir = this->Makefile->GetCurrentBinaryDirectory();
+      mod_dir = this->LocalGenerator->GetCurrentBinaryDirectory();
       mod_dir += "/";
       mod_dir += target_mod_dir;
       }
@@ -214,7 +212,7 @@ cmCommonTargetGenerator
     this->LocalGenerator->GetFortranFormat(srcfmt);
   if(format == cmLocalGenerator::FortranFormatNone)
     {
-    const char* tgtfmt = this->Target->GetProperty("Fortran_FORMAT");
+    const char* tgtfmt = this->GeneratorTarget->GetProperty("Fortran_FORMAT");
     format = this->LocalGenerator->GetFortranFormat(tgtfmt);
     }
   const char* var = 0;
@@ -265,7 +263,7 @@ std::string cmCommonTargetGenerator::GetFrameworkFlags(std::string const& l)
   for(std::vector<std::string>::iterator i = includes.begin();
       i != includes.end(); ++i)
     {
-    if(this->Target->NameResolvesToFramework(*i))
+    if(this->GlobalGenerator->NameResolvesToFramework(*i))
       {
       std::string frameworkDir = *i;
       frameworkDir += "/../";
@@ -316,10 +314,11 @@ std::string cmCommonTargetGenerator::GetFlags(const std::string &l)
       this->AddFortranFlags(flags);
       }
 
-    this->LocalGenerator->AddCMP0018Flags(flags, this->Target,
+    this->LocalGenerator->AddCMP0018Flags(flags, this->GeneratorTarget,
                                           lang, this->ConfigName);
 
-    this->LocalGenerator->AddVisibilityPresetFlags(flags, this->Target,
+    this->LocalGenerator->AddVisibilityPresetFlags(flags,
+                                                   this->GeneratorTarget,
                                                    lang);
 
     // Append old-style preprocessor definition flags.
@@ -331,7 +330,7 @@ std::string cmCommonTargetGenerator::GetFlags(const std::string &l)
       AppendFlags(flags,this->GetFrameworkFlags(l));
 
     // Add target-specific flags.
-    this->LocalGenerator->AddCompileOptions(flags, this->Target,
+    this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget,
                                             lang, this->ConfigName);
 
     ByLanguageMap::value_type entry(l, flags);
@@ -348,13 +347,14 @@ std::string cmCommonTargetGenerator::GetDefines(const std::string &l)
     std::set<std::string> defines;
     const char *lang = l.c_str();
     // Add the export symbol definition for shared library objects.
-    if(const char* exportMacro = this->Target->GetExportMacro())
+    if(const char* exportMacro =
+       this->GeneratorTarget->GetExportMacro())
       {
       this->LocalGenerator->AppendDefines(defines, exportMacro);
       }
 
     // Add preprocessor definitions for this target and configuration.
-    this->LocalGenerator->AddCompileDefinitions(defines, this->Target,
+    this->LocalGenerator->AddCompileDefinitions(defines, this->GeneratorTarget,
                             this->LocalGenerator->GetConfigName(), l);
 
     std::string definesString;
@@ -383,7 +383,7 @@ std::vector<std::string>
 cmCommonTargetGenerator::GetLinkedTargetDirectories() const
 {
   std::vector<std::string> dirs;
-  std::set<cmTarget const*> emitted;
+  std::set<cmGeneratorTarget const*> emitted;
   if (cmComputeLinkInformation* cli =
       this->GeneratorTarget->GetLinkInformation(this->ConfigName))
     {
@@ -391,21 +391,18 @@ cmCommonTargetGenerator::GetLinkedTargetDirectories() const
     for(cmComputeLinkInformation::ItemVector::const_iterator
           i = items.begin(); i != items.end(); ++i)
       {
-      cmTarget const* linkee = i->Target;
+      cmGeneratorTarget const* linkee = i->Target;
       if(linkee && !linkee->IsImported()
                 // We can ignore the INTERFACE_LIBRARY items because
                 // Target->GetLinkInformation already processed their
                 // link interface and they don't have any output themselves.
-                && linkee->GetType() != cmTarget::INTERFACE_LIBRARY
+                && linkee->GetType() != cmState::INTERFACE_LIBRARY
                 && emitted.insert(linkee).second)
         {
-        cmGeneratorTarget* gt =
-          this->GlobalGenerator->GetGeneratorTarget(linkee);
-        cmLocalGenerator* lg = gt->GetLocalGenerator();
-        cmMakefile* mf = linkee->GetMakefile();
-        std::string di = mf->GetCurrentBinaryDirectory();
+        cmLocalGenerator* lg = linkee->GetLocalGenerator();
+        std::string di = lg->GetCurrentBinaryDirectory();
         di += "/";
-        di += lg->GetTargetDirectory(*linkee);
+        di += lg->GetTargetDirectory(linkee);
         dirs.push_back(di);
         }
       }
diff --git a/Source/cmCommonTargetGenerator.h b/Source/cmCommonTargetGenerator.h
index a4b2c10..0c17500 100644
--- a/Source/cmCommonTargetGenerator.h
+++ b/Source/cmCommonTargetGenerator.h
@@ -21,7 +21,6 @@ class cmGlobalCommonGenerator;
 class cmLocalCommonGenerator;
 class cmMakefile;
 class cmSourceFile;
-class cmTarget;
 
 /** \class cmCommonTargetGenerator
  * \brief Common infrastructure for Makefile and Ninja per-target generators
@@ -49,14 +48,13 @@ protected:
 
   cmOutputConverter::RelativeRoot WorkingDirectory;
   cmGeneratorTarget* GeneratorTarget;
-  cmTarget* Target;
   cmMakefile* Makefile;
   cmLocalCommonGenerator* LocalGenerator;
   cmGlobalCommonGenerator* GlobalGenerator;
   std::string ConfigName;
 
   // The windows module definition source file (.def), if any.
-  std::string ModuleDefinitionFile;
+  cmSourceFile const* ModuleDefinitionFile;
 
   // Target-wide Fortran module output directory.
   bool FortranModuleDirectoryComputed;
diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx
index 1b5c9f4..13098ad 100644
--- a/Source/cmComputeLinkDepends.cxx
+++ b/Source/cmComputeLinkDepends.cxx
@@ -185,7 +185,9 @@ cmComputeLinkDepends
   // The configuration being linked.
   this->HasConfig = !config.empty();
   this->Config = (this->HasConfig)? config : std::string();
-  this->LinkType = this->Target->Target->ComputeLinkType(this->Config);
+  std::vector<std::string> debugConfigs =
+    this->Makefile->GetCMakeInstance()->GetDebugConfigs();
+  this->LinkType = CMP0003_ComputeLinkType(this->Config, debugConfigs);
 
   // Enable debug mode if requested.
   this->DebugMode = this->Makefile->IsOn("CMAKE_LINK_DEPENDS_DEBUG_MODE");
@@ -268,9 +270,9 @@ cmComputeLinkDepends::Compute()
     {
     int i = *li;
     LinkEntry const& e = this->EntryList[i];
-    cmTarget const* t = e.Target;
+    cmGeneratorTarget const* t = e.Target;
     // Entries that we know the linker will re-use do not need to be repeated.
-    bool uniquify = t && t->GetType() == cmTarget::SHARED_LIBRARY;
+    bool uniquify = t && t->GetType() == cmState::SHARED_LIBRARY;
     if(!uniquify || emmitted.insert(i).second)
       {
       this->FinalLinkEntries.push_back(e);
@@ -362,14 +364,12 @@ void cmComputeLinkDepends::FollowLinkEntry(BFSEntry const& qe)
   // Follow the item's dependencies.
   if(entry.Target)
     {
-    cmGeneratorTarget* gtgt =
-        this->GlobalGenerator->GetGeneratorTarget(entry.Target);
     // Follow the target dependencies.
     if(cmLinkInterface const* iface =
-       gtgt->GetLinkInterface(this->Config, this->Target->Target))
+       entry.Target->GetLinkInterface(this->Config, this->Target))
       {
       const bool isIface =
-                      entry.Target->GetType() == cmTarget::INTERFACE_LIBRARY;
+                      entry.Target->GetType() == cmState::INTERFACE_LIBRARY;
       // This target provides its own link interface information.
       this->AddLinkEntries(depender_index, iface->Libraries);
 
@@ -463,10 +463,8 @@ void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep)
   // Target items may have their own dependencies.
   if(entry.Target)
     {
-    cmGeneratorTarget* gtgt =
-        this->GlobalGenerator->GetGeneratorTarget(entry.Target);
     if(cmLinkInterface const* iface =
-       gtgt->GetLinkInterface(this->Config, this->Target->Target))
+       entry.Target->GetLinkInterface(this->Config, this->Target))
       {
       // Follow public and private dependencies transitively.
       this->FollowSharedDeps(index, iface, true);
@@ -486,24 +484,24 @@ void cmComputeLinkDepends::AddVarLinkEntries(int depender_index,
 
   // Look for entries meant for this configuration.
   std::vector<cmLinkItem> actual_libs;
-  cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
+  cmTargetLinkLibraryType llt = GENERAL_LibraryType;
   bool haveLLT = false;
   for(std::vector<std::string>::const_iterator di = deplist.begin();
       di != deplist.end(); ++di)
     {
     if(*di == "debug")
       {
-      llt = cmTarget::DEBUG;
+      llt = DEBUG_LibraryType;
       haveLLT = true;
       }
     else if(*di == "optimized")
       {
-      llt = cmTarget::OPTIMIZED;
+      llt = OPTIMIZED_LibraryType;
       haveLLT = true;
       }
     else if(*di == "general")
       {
-      llt = cmTarget::GENERAL;
+      llt = GENERAL_LibraryType;
       haveLLT = true;
       }
     else if(!di->empty())
@@ -521,17 +519,17 @@ void cmComputeLinkDepends::AddVarLinkEntries(int depender_index,
           {
           if(strcmp(val, "debug") == 0)
             {
-            llt = cmTarget::DEBUG;
+            llt = DEBUG_LibraryType;
             }
           else if(strcmp(val, "optimized") == 0)
             {
-            llt = cmTarget::OPTIMIZED;
+            llt = OPTIMIZED_LibraryType;
             }
           }
         }
 
       // If the library is meant for this link type then use it.
-      if(llt == cmTarget::GENERAL || llt == this->LinkType)
+      if(llt == GENERAL_LibraryType || llt == this->LinkType)
         {
         cmLinkItem item(*di, this->FindTargetToLink(depender_index, *di));
         actual_libs.push_back(item);
@@ -543,7 +541,7 @@ void cmComputeLinkDepends::AddVarLinkEntries(int depender_index,
         }
 
       // Reset the link type until another explicit type is given.
-      llt = cmTarget::GENERAL;
+      llt = GENERAL_LibraryType;
       haveLLT = false;
       }
     }
@@ -635,14 +633,16 @@ cmComputeLinkDepends::AddLinkEntries(
 }
 
 //----------------------------------------------------------------------------
-cmTarget const* cmComputeLinkDepends::FindTargetToLink(int depender_index,
-                                                 const std::string& name)
+cmGeneratorTarget const*
+cmComputeLinkDepends::FindTargetToLink(int depender_index,
+                                       const std::string& name)
 {
   // Look for a target in the scope of the depender.
-  cmTarget const* from = this->Target->Target;
+  cmGeneratorTarget const* from = this->Target;
   if(depender_index >= 0)
     {
-    if(cmTarget const* depender = this->EntryList[depender_index].Target)
+    if(cmGeneratorTarget const* depender =
+       this->EntryList[depender_index].Target)
       {
       from = depender;
       }
@@ -934,12 +934,10 @@ int cmComputeLinkDepends::ComputeComponentCount(NodeList const& nl)
   int count = 2;
   for(NodeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
     {
-    if(cmTarget const* target = this->EntryList[*ni].Target)
+    if(cmGeneratorTarget const* target = this->EntryList[*ni].Target)
       {
-      cmGeneratorTarget* gtgt =
-          this->GlobalGenerator->GetGeneratorTarget(target);
       if(cmLinkInterface const* iface =
-         gtgt->GetLinkInterface(this->Config, this->Target->Target))
+         target->GetLinkInterface(this->Config, this->Target))
         {
         if(iface->Multiplicity > count)
           {
diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h
index 2cbb430..f10e4e4 100644
--- a/Source/cmComputeLinkDepends.h
+++ b/Source/cmComputeLinkDepends.h
@@ -13,7 +13,7 @@
 #define cmComputeLinkDepends_h
 
 #include "cmStandardIncludes.h"
-#include "cmTarget.h"
+#include "cmLinkItem.h"
 
 #include "cmGraphAdjacencyList.h"
 
@@ -23,7 +23,6 @@ class cmComputeComponentGraph;
 class cmGlobalGenerator;
 class cmMakefile;
 class cmGeneratorTarget;
-class cmTarget;
 class cmake;
 
 /** \class cmComputeLinkDepends
@@ -40,7 +39,7 @@ public:
   struct LinkEntry
   {
     std::string Item;
-    cmTarget const* Target;
+    cmGeneratorTarget const* Target;
     bool IsSharedDep;
     bool IsFlag;
     LinkEntry(): Item(), Target(0), IsSharedDep(false), IsFlag(false) {}
@@ -53,7 +52,7 @@ public:
   EntryVector const& Compute();
 
   void SetOldLinkDirMode(bool b);
-  std::set<cmTarget const*> const& GetOldWrongConfigItems() const
+  std::set<cmGeneratorTarget const*> const& GetOldWrongConfigItems() const
     { return this->OldWrongConfigItems; }
 
 private:
@@ -66,8 +65,6 @@ private:
   std::string Config;
   EntryVector FinalLinkEntries;
 
-  typedef cmTarget::LinkLibraryVectorType LinkLibraryVectorType;
-
   std::map<std::string, int>::iterator
   AllocateLinkEntry(std::string const& item);
   int AddLinkEntry(cmLinkItem const& item);
@@ -75,8 +72,8 @@ private:
   void AddDirectLinkEntries();
   template <typename T>
     void AddLinkEntries(int depender_index, std::vector<T> const& libs);
-  cmTarget const* FindTargetToLink(int depender_index,
-                                   const std::string& name);
+  cmGeneratorTarget const* FindTargetToLink(int depender_index,
+                                            const std::string& name);
 
   // One entry for each unique item.
   std::vector<LinkEntry> EntryList;
@@ -153,11 +150,11 @@ private:
 
   // Record of the original link line.
   std::vector<int> OriginalEntries;
-  std::set<cmTarget const*> OldWrongConfigItems;
+  std::set<cmGeneratorTarget const*> OldWrongConfigItems;
   void CheckWrongConfigItem(cmLinkItem const& item);
 
   int ComponentOrderId;
-  cmTarget::LinkLibraryType LinkType;
+  cmTargetLinkLibraryType LinkType;
   bool HasConfig;
   bool DebugMode;
   bool OldLinkDirMode;
diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx
index d35b566..50d8324 100644
--- a/Source/cmComputeLinkInformation.cxx
+++ b/Source/cmComputeLinkInformation.cxx
@@ -19,7 +19,6 @@
 #include "cmState.h"
 #include "cmOutputConverter.h"
 #include "cmMakefile.h"
-#include "cmTarget.h"
 #include "cmGeneratorTarget.h"
 #include "cmake.h"
 #include "cmAlgorithms.h"
@@ -284,14 +283,14 @@ cmComputeLinkInformation
 
   // Check whether we should skip dependencies on shared library files.
   this->LinkDependsNoShared =
-    this->Target->Target->GetPropertyAsBool("LINK_DEPENDS_NO_SHARED");
+    this->Target->GetPropertyAsBool("LINK_DEPENDS_NO_SHARED");
 
   // On platforms without import libraries there may be a special flag
   // to use when creating a plugin (module) that obtains symbols from
   // the program that will load it.
   this->LoaderFlag = 0;
   if(!this->UseImportLibrary &&
-     this->Target->Target->GetType() == cmTarget::MODULE_LIBRARY)
+     this->Target->GetType() == cmState::MODULE_LIBRARY)
     {
     std::string loader_flag_var = "CMAKE_SHARED_MODULE_LOADER_";
     loader_flag_var += this->LinkLanguage;
@@ -309,10 +308,10 @@ cmComputeLinkInformation
 
   // Get options needed to specify RPATHs.
   this->RuntimeUseChrpath = false;
-  if(this->Target->Target->GetType() != cmTarget::STATIC_LIBRARY)
+  if(this->Target->GetType() != cmState::STATIC_LIBRARY)
     {
     const char* tType =
-      ((this->Target->Target->GetType() == cmTarget::EXECUTABLE)?
+      ((this->Target->GetType() == cmState::EXECUTABLE)?
        "EXECUTABLE" : "SHARED_LIBRARY");
     std::string rtVar = "CMAKE_";
     rtVar += tType;
@@ -378,9 +377,9 @@ cmComputeLinkInformation
 
   // Add the search path entries requested by the user to path ordering.
   this->OrderLinkerSearchPath
-    ->AddUserDirectories(this->Target->Target->GetLinkDirectories());
+    ->AddUserDirectories(this->Target->GetLinkDirectories());
   this->OrderRuntimeSearchPath
-    ->AddUserDirectories(this->Target->Target->GetLinkDirectories());
+    ->AddUserDirectories(this->Target->GetLinkDirectories());
 
   // Set up the implicit link directories.
   this->LoadImplicitLinkInfo();
@@ -408,13 +407,13 @@ cmComputeLinkInformation
   // order to support such projects we need to add the directories
   // containing libraries linked with a full path to the -L path.
   this->OldLinkDirMode =
-    this->Target->Target->GetPolicyStatusCMP0003() != cmPolicies::NEW;
+    this->Target->GetPolicyStatusCMP0003() != cmPolicies::NEW;
   if(this->OldLinkDirMode)
     {
     // Construct a mask to not bother with this behavior for link
     // directories already specified by the user.
     std::vector<std::string> const& dirs =
-        this->Target->Target->GetLinkDirectories();
+        this->Target->GetLinkDirectories();
     this->OldLinkDirMask.insert(dirs.begin(), dirs.end());
     }
 
@@ -471,7 +470,7 @@ std::vector<std::string> const& cmComputeLinkInformation::GetFrameworkPaths()
 }
 
 //----------------------------------------------------------------------------
-std::set<cmTarget const*> const&
+const std::set<const cmGeneratorTarget*>&
 cmComputeLinkInformation::GetSharedLibrariesLinked()
 {
   return this->SharedLibrariesLinked;
@@ -481,10 +480,10 @@ cmComputeLinkInformation::GetSharedLibrariesLinked()
 bool cmComputeLinkInformation::Compute()
 {
   // Skip targets that do not link.
-  if(!(this->Target->GetType() == cmTarget::EXECUTABLE ||
-       this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
-       this->Target->GetType() == cmTarget::MODULE_LIBRARY ||
-       this->Target->GetType() == cmTarget::STATIC_LIBRARY))
+  if(!(this->Target->GetType() == cmState::EXECUTABLE ||
+       this->Target->GetType() == cmState::SHARED_LIBRARY ||
+       this->Target->GetType() == cmState::MODULE_LIBRARY ||
+       this->Target->GetType() == cmState::STATIC_LIBRARY))
     {
     return false;
     }
@@ -521,7 +520,7 @@ bool cmComputeLinkInformation::Compute()
   // Restore the target link type so the correct system runtime
   // libraries are found.
   const char* lss =
-      this->Target->Target->GetProperty("LINK_SEARCH_END_STATIC");
+      this->Target->GetProperty("LINK_SEARCH_END_STATIC");
   if(cmSystemTools::IsOn(lss))
     {
     this->SetCurrentLinkType(LinkStatic);
@@ -537,16 +536,16 @@ bool cmComputeLinkInformation::Compute()
     // For CMake 2.4 bug-compatibility we need to consider the output
     // directories of targets linked in another configuration as link
     // directories.
-    std::set<cmTarget const*> const& wrongItems = cld.GetOldWrongConfigItems();
-    for(std::set<cmTarget const*>::const_iterator i = wrongItems.begin();
-        i != wrongItems.end(); ++i)
+    std::set<cmGeneratorTarget const*> const& wrongItems =
+        cld.GetOldWrongConfigItems();
+    for(std::set<cmGeneratorTarget const*>::const_iterator i =
+        wrongItems.begin(); i != wrongItems.end(); ++i)
       {
-      cmTarget const* tgt = *i;
-      cmGeneratorTarget *gtgt = this->GlobalGenerator->GetGeneratorTarget(tgt);
+      cmGeneratorTarget const* tgt = *i;
       bool implib =
         (this->UseImportLibrary &&
-         (tgt->GetType() == cmTarget::SHARED_LIBRARY));
-      std::string lib = gtgt->GetFullPath(this->Config , implib, true);
+         (tgt->GetType() == cmState::SHARED_LIBRARY));
+      std::string lib = tgt->GetFullPath(this->Config , implib, true);
       this->OldLinkDirItems.push_back(lib);
       }
     }
@@ -572,7 +571,7 @@ bool cmComputeLinkInformation::Compute()
       "name."
       ;
     this->CMakeInstance->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
-                                      this->Target->Target->GetBacktrace());
+                                      this->Target->GetBacktrace());
     }
 
   return true;
@@ -632,7 +631,7 @@ void cmComputeLinkInformation::AddImplicitLinkInfo(std::string const& lang)
 
 //----------------------------------------------------------------------------
 void cmComputeLinkInformation::AddItem(std::string const& item,
-                                       cmTarget const* tgt)
+                                       cmGeneratorTarget const* tgt)
 {
   // Compute the proper name to use to link this library.
   const std::string& config = this->Config;
@@ -646,7 +645,6 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
 
   if(tgt && tgt->IsLinkable())
     {
-    cmGeneratorTarget *gtgt = this->GlobalGenerator->GetGeneratorTarget(tgt);
     // This is a CMake target.  Ask the target for its real name.
     if(impexe && this->LoaderFlag)
       {
@@ -656,13 +654,13 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
       std::string linkItem;
       linkItem = this->LoaderFlag;
 
-      std::string exe = gtgt->GetFullPath(config, this->UseImportLibrary,
+      std::string exe = tgt->GetFullPath(config, this->UseImportLibrary,
                                          true);
       linkItem += exe;
       this->Items.push_back(Item(linkItem, true, tgt));
       this->Depends.push_back(exe);
       }
-    else if(tgt->GetType() == cmTarget::INTERFACE_LIBRARY)
+    else if(tgt->GetType() == cmState::INTERFACE_LIBRARY)
       {
       // Add the interface library as an item so it can be considered as part
       // of COMPATIBLE_INTERFACE_ enforcement.  The generators will ignore
@@ -674,12 +672,12 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
       // Decide whether to use an import library.
       bool implib =
         (this->UseImportLibrary &&
-         (impexe || tgt->GetType() == cmTarget::SHARED_LIBRARY));
+         (impexe || tgt->GetType() == cmState::SHARED_LIBRARY));
 
       // Pass the full path to the target file.
-      std::string lib = gtgt->GetFullPath(config, implib, true);
+      std::string lib = tgt->GetFullPath(config, implib, true);
       if(!this->LinkDependsNoShared ||
-         tgt->GetType() != cmTarget::SHARED_LIBRARY)
+         tgt->GetType() != cmState::SHARED_LIBRARY)
         {
         this->Depends.push_back(lib);
         }
@@ -716,7 +714,7 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
 
 //----------------------------------------------------------------------------
 void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
-                                                cmTarget const* tgt)
+                                                const cmGeneratorTarget* tgt)
 {
   // If dropping shared library dependencies, ignore them.
   if(this->SharedDependencyMode == SharedDepModeNone)
@@ -730,7 +728,7 @@ void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
     {
     // The target will provide a full path.  Make sure it is a shared
     // library.
-    if(tgt->GetType() != cmTarget::SHARED_LIBRARY)
+    if(tgt->GetType() != cmState::SHARED_LIBRARY)
       {
       return;
       }
@@ -760,17 +758,13 @@ void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
     return;
     }
 
-  cmGeneratorTarget *gtgt = 0;
-
   // Get a full path to the dependent shared library.
   // Add it to the runtime path computation so that the target being
   // linked will be able to find it.
   std::string lib;
   if(tgt)
     {
-    gtgt = this->GlobalGenerator->GetGeneratorTarget(tgt);
-
-    lib = gtgt->GetFullPath(this->Config, this->UseImportLibrary);
+    lib = tgt->GetFullPath(this->Config, this->UseImportLibrary);
     this->AddLibraryRuntimeInfo(lib, tgt);
     }
   else
@@ -795,9 +789,9 @@ void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
     }
   if(order)
     {
-    if(gtgt)
+    if(tgt)
       {
-      std::string soName = gtgt->GetSOName(this->Config);
+      std::string soName = tgt->GetSOName(this->Config);
       const char* soname = soName.empty()? 0 : soName.c_str();
       order->AddRuntimeLibrary(lib, soname);
       }
@@ -824,9 +818,9 @@ void cmComputeLinkInformation::ComputeLinkTypeInfo()
   const char* target_type_str = 0;
   switch(this->Target->GetType())
     {
-    case cmTarget::EXECUTABLE:     target_type_str = "EXE"; break;
-    case cmTarget::SHARED_LIBRARY: target_type_str = "SHARED_LIBRARY"; break;
-    case cmTarget::MODULE_LIBRARY: target_type_str = "SHARED_MODULE"; break;
+    case cmState::EXECUTABLE:     target_type_str = "EXE"; break;
+    case cmState::SHARED_LIBRARY: target_type_str = "SHARED_LIBRARY"; break;
+    case cmState::MODULE_LIBRARY: target_type_str = "SHARED_MODULE"; break;
     default: break;
     }
   if(target_type_str)
@@ -860,7 +854,7 @@ void cmComputeLinkInformation::ComputeLinkTypeInfo()
 
   // Lookup the starting link type from the target (linked statically?).
   const char* lss =
-      this->Target->Target->GetProperty("LINK_SEARCH_START_STATIC");
+      this->Target->GetProperty("LINK_SEARCH_START_STATIC");
   this->StartLinkType = cmSystemTools::IsOn(lss)? LinkStatic : LinkShared;
   this->CurrentLinkType = this->StartLinkType;
 }
@@ -1082,7 +1076,7 @@ void cmComputeLinkInformation::SetCurrentLinkType(LinkType lt)
 
 //----------------------------------------------------------------------------
 void cmComputeLinkInformation::AddTargetItem(std::string const& item,
-                                             cmTarget const* target)
+                                             cmGeneratorTarget const* target)
 {
   // This is called to handle a link item that is a full path to a target.
   // If the target is not a static library make sure the link type is
@@ -1090,13 +1084,13 @@ void cmComputeLinkInformation::AddTargetItem(std::string const& item,
   // shared and static libraries but static-mode can handle only
   // static libraries.  If a previous user item changed the link type
   // to static we need to make sure it is back to shared.
-  if(target->GetType() != cmTarget::STATIC_LIBRARY)
+  if(target->GetType() != cmState::STATIC_LIBRARY)
     {
     this->SetCurrentLinkType(LinkShared);
     }
 
   // Keep track of shared library targets linked.
-  if(target->GetType() == cmTarget::SHARED_LIBRARY)
+  if(target->GetType() == cmState::SHARED_LIBRARY)
     {
     this->SharedLibrariesLinked.insert(target);
     }
@@ -1146,7 +1140,7 @@ void cmComputeLinkInformation::AddFullItem(std::string const& item)
   // Full path libraries should specify a valid library file name.
   // See documentation of CMP0008.
   std::string generator = this->GlobalGenerator->GetName();
-  if(this->Target->Target->GetPolicyStatusCMP0008() != cmPolicies::NEW &&
+  if(this->Target->GetPolicyStatusCMP0008() != cmPolicies::NEW &&
      (generator.find("Visual Studio") != generator.npos ||
       generator.find("Xcode") != generator.npos))
     {
@@ -1227,7 +1221,7 @@ bool cmComputeLinkInformation::CheckImplicitDirItem(std::string const& item)
     }
 
   // Check the policy for whether we should use the approach below.
-  switch (this->Target->Target->GetPolicyStatusCMP0060())
+  switch (this->Target->GetPolicyStatusCMP0060())
     {
     case cmPolicies::WARN:
       if (this->CMP0060Warn)
@@ -1537,7 +1531,7 @@ void cmComputeLinkInformation::HandleBadFullItem(std::string const& item,
   this->OrderLinkerSearchPath->AddLinkLibrary(item);
 
   // Produce any needed message.
-  switch(this->Target->Target->GetPolicyStatusCMP0008())
+  switch(this->Target->GetPolicyStatusCMP0008())
     {
     case cmPolicies::WARN:
       {
@@ -1554,7 +1548,7 @@ void cmComputeLinkInformation::HandleBadFullItem(std::string const& item,
           << "  " << item << "\n"
           << "which is a full-path but not a valid library file name.";
         this->CMakeInstance->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
-                                        this->Target->Target->GetBacktrace());
+                                        this->Target->GetBacktrace());
         }
       }
     case cmPolicies::OLD:
@@ -1572,7 +1566,7 @@ void cmComputeLinkInformation::HandleBadFullItem(std::string const& item,
           << "  " << item << "\n"
           << "which is a full-path but not a valid library file name.";
       this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(),
-                                        this->Target->Target->GetBacktrace());
+                                        this->Target->GetBacktrace());
       }
       break;
     }
@@ -1589,7 +1583,7 @@ bool cmComputeLinkInformation::FinishLinkerSearchDirectories()
     }
 
   // Enforce policy constraints.
-  switch(this->Target->Target->GetPolicyStatusCMP0003())
+  switch(this->Target->GetPolicyStatusCMP0003())
     {
     case cmPolicies::WARN:
       if(!this->CMakeInstance->GetState()
@@ -1600,7 +1594,7 @@ bool cmComputeLinkInformation::FinishLinkerSearchDirectories()
         std::ostringstream w;
         this->PrintLinkPolicyDiagnosis(w);
         this->CMakeInstance->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
-                                        this->Target->Target->GetBacktrace());
+                                        this->Target->GetBacktrace());
         }
     case cmPolicies::OLD:
       // OLD behavior is to add the paths containing libraries with
@@ -1616,7 +1610,7 @@ bool cmComputeLinkInformation::FinishLinkerSearchDirectories()
       e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0003) << "\n";
       this->PrintLinkPolicyDiagnosis(e);
       this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(),
-                                        this->Target->Target->GetBacktrace());
+                                        this->Target->GetBacktrace());
       return false;
       }
     }
@@ -1781,7 +1775,7 @@ cmComputeLinkInformation::GetRuntimeSearchPath()
 //----------------------------------------------------------------------------
 void
 cmComputeLinkInformation::AddLibraryRuntimeInfo(std::string const& fullPath,
-                                                cmTarget const* target)
+                                              cmGeneratorTarget const* target)
 {
   // Ignore targets on Apple where install_name is not @rpath.
   // The dependenty library can be found with other means such as
@@ -1796,22 +1790,21 @@ cmComputeLinkInformation::AddLibraryRuntimeInfo(std::string const& fullPath,
 
   // Libraries with unknown type must be handled using just the file
   // on disk.
-  if(target->GetType() == cmTarget::UNKNOWN_LIBRARY)
+  if(target->GetType() == cmState::UNKNOWN_LIBRARY)
     {
     this->AddLibraryRuntimeInfo(fullPath);
     return;
     }
 
   // Skip targets that are not shared libraries (modules cannot be linked).
-  if(target->GetType() != cmTarget::SHARED_LIBRARY)
+  if(target->GetType() != cmState::SHARED_LIBRARY)
     {
     return;
     }
 
   // Try to get the soname of the library.  Only files with this name
   // could possibly conflict.
-  cmGeneratorTarget *gtgt = this->GlobalGenerator->GetGeneratorTarget(target);
-  std::string soName = gtgt->GetSOName(this->Config);
+  std::string soName = target->GetSOName(this->Config);
   const char* soname = soName.empty()? 0 : soName.c_str();
 
   // Include this library in the runtime path ordering.
@@ -1918,9 +1911,9 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
   // build tree.
   bool linking_for_install =
     (for_install ||
-     this->Target->Target->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"));
+     this->Target->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"));
   bool use_install_rpath =
-    (outputRuntime && this->Target->Target->HaveInstallTreeRPATH() &&
+    (outputRuntime && this->Target->HaveInstallTreeRPATH() &&
      linking_for_install);
   bool use_build_rpath =
     (outputRuntime && this->Target->HaveBuildTreeRPATH(this->Config) &&
@@ -1928,14 +1921,14 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
   bool use_link_rpath =
     outputRuntime && linking_for_install &&
     !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH") &&
-    this->Target->Target->GetPropertyAsBool("INSTALL_RPATH_USE_LINK_PATH");
+    this->Target->GetPropertyAsBool("INSTALL_RPATH_USE_LINK_PATH");
 
   // Construct the RPATH.
   std::set<std::string> emitted;
   if(use_install_rpath)
     {
     const char* install_rpath =
-        this->Target->Target->GetProperty("INSTALL_RPATH");
+        this->Target->GetProperty("INSTALL_RPATH");
     cmCLI_ExpandListUnique(install_rpath, runtimeDirs, emitted);
     }
   if(use_build_rpath || use_link_rpath)
@@ -1975,8 +1968,9 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
       else if(use_link_rpath)
         {
         // Do not add any path inside the source or build tree.
-        const char* topSourceDir = this->Makefile->GetHomeDirectory();
-        const char* topBinaryDir = this->Makefile->GetHomeOutputDirectory();
+        const char* topSourceDir = this->CMakeInstance->GetHomeDirectory();
+        const char* topBinaryDir =
+            this->CMakeInstance->GetHomeOutputDirectory();
         if(!cmSystemTools::ComparePath(*ri, topSourceDir) &&
            !cmSystemTools::ComparePath(*ri, topBinaryDir) &&
            !cmSystemTools::IsSubDirectory(*ri, topSourceDir) &&
diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h
index 8b83574..5eecf7d 100644
--- a/Source/cmComputeLinkInformation.h
+++ b/Source/cmComputeLinkInformation.h
@@ -19,7 +19,6 @@
 class cmake;
 class cmGlobalGenerator;
 class cmMakefile;
-class cmTarget;
 class cmGeneratorTarget;
 class cmOrderDirectories;
 
@@ -39,11 +38,11 @@ public:
     Item(): Value(), IsPath(true), Target(0) {}
     Item(Item const& item):
       Value(item.Value), IsPath(item.IsPath), Target(item.Target) {}
-    Item(std::string const& v, bool p, cmTarget const* target = 0):
+    Item(std::string const& v, bool p, cmGeneratorTarget const* target = 0):
       Value(v), IsPath(p), Target(target) {}
     std::string Value;
     bool IsPath;
-    cmTarget const* Target;
+    cmGeneratorTarget const* Target;
   };
   typedef std::vector<Item> ItemVector;
   ItemVector const& GetItems();
@@ -57,13 +56,13 @@ public:
   void GetRPath(std::vector<std::string>& runtimeDirs, bool for_install);
   std::string GetRPathString(bool for_install);
   std::string GetChrpathString();
-  std::set<cmTarget const*> const& GetSharedLibrariesLinked();
+  std::set<cmGeneratorTarget const*> const& GetSharedLibrariesLinked();
 
   std::string const& GetRPathLinkFlag() const { return this->RPathLinkFlag; }
   std::string GetRPathLinkString();
 private:
-  void AddItem(std::string const& item, cmTarget const* tgt);
-  void AddSharedDepItem(std::string const& item, cmTarget const* tgt);
+  void AddItem(std::string const& item, const cmGeneratorTarget* tgt);
+  void AddSharedDepItem(std::string const& item, cmGeneratorTarget const* tgt);
 
   // Output information.
   ItemVector Items;
@@ -71,7 +70,7 @@ private:
   std::vector<std::string> Depends;
   std::vector<std::string> FrameworkPaths;
   std::vector<std::string> RuntimeSearchPath;
-  std::set<cmTarget const*> SharedLibrariesLinked;
+  std::set<cmGeneratorTarget const*> SharedLibrariesLinked;
 
   // Context information.
   cmGeneratorTarget const* Target;
@@ -129,7 +128,7 @@ private:
   std::string NoCaseExpression(const char* str);
 
   // Handling of link items.
-  void AddTargetItem(std::string const& item, cmTarget const* target);
+  void AddTargetItem(std::string const& item, const cmGeneratorTarget* target);
   void AddFullItem(std::string const& item);
   bool CheckImplicitDirItem(std::string const& item);
   void AddUserItem(std::string const& item, bool pathNotKnown);
@@ -183,7 +182,7 @@ private:
   bool CMP0060Warn;
 
   void AddLibraryRuntimeInfo(std::string const& fullPath,
-                             cmTarget const* target);
+                             const cmGeneratorTarget* target);
   void AddLibraryRuntimeInfo(std::string const& fullPath);
 
 };
diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx
index 9e37c35..586b5bf 100644
--- a/Source/cmComputeTargetDepends.cxx
+++ b/Source/cmComputeTargetDepends.cxx
@@ -175,13 +175,12 @@ void cmComputeTargetDepends::CollectTargets()
     this->GlobalGenerator->GetLocalGenerators();
   for(unsigned int i = 0; i < lgens.size(); ++i)
     {
-    const cmTargets& targets = lgens[i]->GetMakefile()->GetTargets();
-    for(cmTargets::const_iterator ti = targets.begin();
+    const std::vector<cmGeneratorTarget*> targets =
+        lgens[i]->GetGeneratorTargets();
+    for(std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin();
         ti != targets.end(); ++ti)
       {
-      cmTarget const* target = &ti->second;
-      cmGeneratorTarget* gt =
-          this->GlobalGenerator->GetGeneratorTarget(target);
+      cmGeneratorTarget* gt = *ti;
       int index = static_cast<int>(this->Targets.size());
       this->TargetIndex[gt] = index;
       this->Targets.push_back(gt);
@@ -207,7 +206,7 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
 {
   // Get the depender.
   cmGeneratorTarget const* depender = this->Targets[depender_index];
-  if (depender->GetType() == cmTarget::INTERFACE_LIBRARY)
+  if (depender->GetType() == cmState::INTERFACE_LIBRARY)
     {
     return;
     }
@@ -236,16 +235,16 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
       std::string objLib = (*oi)->GetObjectLibrary();
       if (!objLib.empty() && emitted.insert(objLib).second)
         {
-        if(depender->GetType() != cmTarget::EXECUTABLE &&
-            depender->GetType() != cmTarget::STATIC_LIBRARY &&
-            depender->GetType() != cmTarget::SHARED_LIBRARY &&
-            depender->GetType() != cmTarget::MODULE_LIBRARY)
+        if(depender->GetType() != cmState::EXECUTABLE &&
+            depender->GetType() != cmState::STATIC_LIBRARY &&
+            depender->GetType() != cmState::SHARED_LIBRARY &&
+            depender->GetType() != cmState::MODULE_LIBRARY)
           {
           this->GlobalGenerator->GetCMakeInstance()
             ->IssueMessage(cmake::FATAL_ERROR,
                             "Only executables and non-OBJECT libraries may "
                             "reference target objects.",
-                            depender->Target->GetBacktrace());
+                            depender->GetBacktrace());
           return;
           }
         const_cast<cmGeneratorTarget*>(depender)->Target->AddUtility(objLib);
@@ -272,7 +271,7 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
 
   // Loop over all utility dependencies.
   {
-  std::set<cmLinkItem> const& tutils = depender->Target->GetUtilityItems();
+  std::set<cmLinkItem> const& tutils = depender->GetUtilityItems();
   std::set<std::string> emitted;
   // A target should not depend on itself.
   emitted.insert(depender->GetName());
@@ -297,7 +296,7 @@ void cmComputeTargetDepends::AddInterfaceDepends(int depender_index,
   cmGeneratorTarget const* depender = this->Targets[depender_index];
   if(cmLinkInterface const* iface =
                                 dependee->GetLinkInterface(config,
-                                                           depender->Target))
+                                                           depender))
     {
     for(std::vector<cmLinkItem>::const_iterator
         lib = iface->Libraries.begin();
@@ -319,12 +318,12 @@ void cmComputeTargetDepends::AddInterfaceDepends(int depender_index,
                                              std::set<std::string> &emitted)
 {
   cmGeneratorTarget const* depender = this->Targets[depender_index];
-  cmTarget const* dependee = dependee_name.Target;
+  cmGeneratorTarget const* dependee = dependee_name.Target;
   // Skip targets that will not really be linked.  This is probably a
   // name conflict between an external library and an executable
   // within the project.
   if(dependee &&
-     dependee->GetType() == cmTarget::EXECUTABLE &&
+     dependee->GetType() == cmState::EXECUTABLE &&
      !dependee->IsExecutableWithExports())
     {
     dependee = 0;
@@ -332,9 +331,7 @@ void cmComputeTargetDepends::AddInterfaceDepends(int depender_index,
 
   if(dependee)
     {
-    cmGeneratorTarget* gt =
-        this->GlobalGenerator->GetGeneratorTarget(dependee);
-    this->AddInterfaceDepends(depender_index, gt, "", emitted);
+    this->AddInterfaceDepends(depender_index, dependee, "", emitted);
     std::vector<std::string> configs;
     depender->Makefile->GetConfigurations(configs);
     for (std::vector<std::string>::const_iterator it = configs.begin();
@@ -342,7 +339,7 @@ void cmComputeTargetDepends::AddInterfaceDepends(int depender_index,
       {
       // A target should not depend on itself.
       emitted.insert(depender->GetName());
-      this->AddInterfaceDepends(depender_index, gt, *it, emitted);
+      this->AddInterfaceDepends(depender_index, dependee, *it, emitted);
       }
     }
 }
@@ -356,15 +353,15 @@ void cmComputeTargetDepends::AddTargetDepend(
   cmGeneratorTarget const* depender = this->Targets[depender_index];
 
   // Check the target's makefile first.
-  cmTarget const* dependee = dependee_name.Target;
+  cmGeneratorTarget const* dependee = dependee_name.Target;
 
   if(!dependee && !linking &&
-    (depender->GetType() != cmTarget::GLOBAL_TARGET))
+    (depender->GetType() != cmState::GLOBAL_TARGET))
     {
     cmake::MessageType messageType = cmake::AUTHOR_WARNING;
     bool issueMessage = false;
     std::ostringstream e;
-    switch(depender->Target->GetPolicyStatusCMP0046())
+    switch(depender->GetPolicyStatusCMP0046())
       {
       case cmPolicies::WARN:
         e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0046) << "\n";
@@ -385,7 +382,7 @@ void cmComputeTargetDepends::AddTargetDepend(
         << "\" of target \"" << depender->GetName() << "\" does not exist.";
 
       cmListFileBacktrace const* backtrace =
-        depender->Target->GetUtilityBacktrace(dependee_name);
+        depender->GetUtilityBacktrace(dependee_name);
       if(backtrace)
         {
         cm->IssueMessage(messageType, e.str(), *backtrace);
@@ -402,7 +399,7 @@ void cmComputeTargetDepends::AddTargetDepend(
   // name conflict between an external library and an executable
   // within the project.
   if(linking && dependee &&
-     dependee->GetType() == cmTarget::EXECUTABLE &&
+     dependee->GetType() == cmState::EXECUTABLE &&
      !dependee->IsExecutableWithExports())
     {
     dependee = 0;
@@ -410,9 +407,7 @@ void cmComputeTargetDepends::AddTargetDepend(
 
   if(dependee)
     {
-    cmGeneratorTarget* gt =
-        this->GlobalGenerator->GetGeneratorTarget(dependee);
-    this->AddTargetDepend(depender_index, gt, linking);
+    this->AddTargetDepend(depender_index, dependee, linking);
     }
 }
 
@@ -421,20 +416,18 @@ void cmComputeTargetDepends::AddTargetDepend(int depender_index,
                                              const cmGeneratorTarget* dependee,
                                              bool linking)
 {
-  if(dependee->Target->IsImported() ||
-     dependee->GetType() == cmTarget::INTERFACE_LIBRARY)
+  if(dependee->IsImported() ||
+     dependee->GetType() == cmState::INTERFACE_LIBRARY)
     {
     // Skip IMPORTED and INTERFACE targets but follow their utility
     // dependencies.
-    std::set<cmLinkItem> const& utils = dependee->Target->GetUtilityItems();
+    std::set<cmLinkItem> const& utils = dependee->GetUtilityItems();
     for(std::set<cmLinkItem>::const_iterator i = utils.begin();
         i != utils.end(); ++i)
       {
-      if(cmTarget const* transitive_dependee = i->Target)
+      if(cmGeneratorTarget const* transitive_dependee = i->Target)
         {
-        cmGeneratorTarget* gt =
-            this->GlobalGenerator->GetGeneratorTarget(transitive_dependee);
-        this->AddTargetDepend(depender_index, gt, false);
+        this->AddTargetDepend(depender_index, transitive_dependee, false);
         }
       }
     }
@@ -529,7 +522,7 @@ cmComputeTargetDepends
     // Make sure the component is all STATIC_LIBRARY targets.
     for(NodeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
       {
-      if(this->Targets[*ni]->GetType() != cmTarget::STATIC_LIBRARY)
+      if(this->Targets[*ni]->GetType() != cmState::STATIC_LIBRARY)
         {
         this->ComplainAboutBadComponent(ccg, c);
         return false;
@@ -560,7 +553,7 @@ cmComputeTargetDepends
 
     // Describe the depender.
     e << "  \"" << depender->GetName() << "\" of type "
-      << cmTarget::GetTargetTypeName(depender->Target->GetType()) << "\n";
+      << cmState::GetTargetTypeName(depender->GetType()) << "\n";
 
     // List its dependencies that are inside the component.
     EdgeList const& nl = this->InitialGraph[i];
diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx
index 5330acd..6a0ebec 100644
--- a/Source/cmConditionEvaluator.cxx
+++ b/Source/cmConditionEvaluator.cxx
@@ -12,6 +12,7 @@
 
 #include "cmConditionEvaluator.h"
 #include "cmOutputConverter.h"
+#include "cmAlgorithms.h"
 
 cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile,
                                            const cmListFileContext &context,
@@ -578,6 +579,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList &newArgs,
                   cmake::MessageType &status)
 {
   int reducible;
+  std::string def_buf;
   const char *def;
   const char *def2;
   do
@@ -594,6 +596,14 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList &newArgs,
         IsKeyword("MATCHES", *argP1))
         {
         def = this->GetVariableOrString(*arg);
+        if (def != arg->c_str() // yes, we compare the pointer value
+            && cmHasLiteralPrefix(arg->GetValue(), "CMAKE_MATCH_"))
+          {
+          // The string to match is owned by our match result variables.
+          // Move it to our own buffer before clearing them.
+          def_buf = def;
+          def = def_buf.c_str();
+          }
         const char* rex = argP2->c_str();
         this->Makefile.ClearMatches();
         cmsys::RegularExpression regEntry;
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 3d9c4bf..4a1f770 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -34,7 +34,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
   std::string outputVariable;
   std::string copyFile;
   std::string copyFileError;
-  std::vector<cmTarget const*> targets;
+  std::vector<std::string> targets;
   std::string libsToLink = " ";
   bool useOldLinkLibs = true;
   char targetNameBuf[64];
@@ -93,12 +93,12 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
         {
         switch(tgt->GetType())
           {
-          case cmTarget::SHARED_LIBRARY:
-          case cmTarget::STATIC_LIBRARY:
-          case cmTarget::INTERFACE_LIBRARY:
-          case cmTarget::UNKNOWN_LIBRARY:
+          case cmState::SHARED_LIBRARY:
+          case cmState::STATIC_LIBRARY:
+          case cmState::INTERFACE_LIBRARY:
+          case cmState::UNKNOWN_LIBRARY:
             break;
-          case cmTarget::EXECUTABLE:
+          case cmState::EXECUTABLE:
             if (tgt->IsExecutableWithExports())
               {
               break;
@@ -107,12 +107,12 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
             this->Makefile->IssueMessage(cmake::FATAL_ERROR,
               "Only libraries may be used as try_compile or try_run IMPORTED "
               "LINK_LIBRARIES.  Got " + std::string(tgt->GetName()) + " of "
-              "type " + tgt->GetTargetTypeName(tgt->GetType()) + ".");
+              "type " + cmState::GetTargetTypeName(tgt->GetType()) + ".");
             return -1;
           }
         if (tgt->IsImported())
           {
-          targets.push_back(tgt);
+          targets.push_back(argv[i]);
           }
         }
       }
@@ -375,9 +375,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
     if (!targets.empty())
       {
       std::string fname = "/" + std::string(targetName) + "Targets.cmake";
-      cmExportTryCompileFileGenerator tcfg(gg);
+      cmExportTryCompileFileGenerator tcfg(gg, targets, this->Makefile);
       tcfg.SetExportFile((this->BinaryDirectory + fname).c_str());
-      tcfg.SetExports(targets);
       tcfg.SetConfig(this->Makefile->GetSafeDefinition(
                                           "CMAKE_TRY_COMPILE_CONFIGURATION"));
 
diff --git a/Source/cmCurl.cxx b/Source/cmCurl.cxx
index ad0c7d3..4f3d890 100644
--- a/Source/cmCurl.cxx
+++ b/Source/cmCurl.cxx
@@ -12,6 +12,11 @@
 #include "cmCurl.h"
 #include "cmSystemTools.h"
 
+// curl versions before 7.21.5 did not provide this error code
+#if defined(LIBCURL_VERSION_NUM) && LIBCURL_VERSION_NUM < 0x071505
+# define CURLE_NOT_BUILT_IN 4
+#endif
+
 #define check_curl_result(result, errstr)                               \
   if (result != CURLE_OK && result != CURLE_NOT_BUILT_IN)               \
     {                                                                   \
diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx
index 7f3b651..dc06678 100644
--- a/Source/cmCustomCommandGenerator.cxx
+++ b/Source/cmCustomCommandGenerator.cxx
@@ -43,15 +43,14 @@ std::string cmCustomCommandGenerator::GetCommand(unsigned int c) const
 {
   std::string const& argv0 = this->CC.GetCommandLines()[c][0];
   cmGeneratorTarget* target =
-      this->LG->GetMakefile()->FindGeneratorTargetToUse(argv0);
-  if(target && target->GetType() == cmTarget::EXECUTABLE &&
-     (target->Target->IsImported()
+      this->LG->FindGeneratorTargetToUse(argv0);
+  if(target && target->GetType() == cmState::EXECUTABLE &&
+     (target->IsImported()
       || !this->LG->GetMakefile()->IsOn("CMAKE_CROSSCOMPILING")))
     {
     return target->GetLocation(this->Config);
     }
-  return this->GE->Parse(argv0)->Evaluate(this->LG->GetMakefile(),
-                                          this->Config);
+  return this->GE->Parse(argv0)->Evaluate(this->LG, this->Config);
 }
 
 //----------------------------------------------------------------------------
@@ -92,7 +91,7 @@ cmCustomCommandGenerator
   for(unsigned int j=1;j < commandLine.size(); ++j)
     {
     std::string arg =
-        this->GE->Parse(commandLine[j])->Evaluate(this->LG->GetMakefile(),
+        this->GE->Parse(commandLine[j])->Evaluate(this->LG,
                                                   this->Config);
     cmd += " ";
     if(this->OldStyle)
@@ -101,7 +100,7 @@ cmCustomCommandGenerator
       }
     else
       {
-      cmOutputConverter converter(this->LG->GetMakefile()->GetStateSnapshot());
+      cmOutputConverter converter(this->LG->GetStateSnapshot());
       cmd += converter.EscapeForShell(arg, this->MakeVars);
       }
     }
@@ -146,7 +145,7 @@ std::vector<std::string> const& cmCustomCommandGenerator::GetDepends() const
                                               = this->GE->Parse(*i);
       std::vector<std::string> result;
       cmSystemTools::ExpandListArgument(
-            cge->Evaluate(this->LG->GetMakefile(), this->Config), result);
+            cge->Evaluate(this->LG, this->Config), result);
       for (std::vector<std::string>::iterator it = result.begin();
           it != result.end(); ++it)
         {
diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx
index 856dcd4..80f560f 100644
--- a/Source/cmDependsFortran.cxx
+++ b/Source/cmDependsFortran.cxx
@@ -160,7 +160,7 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
   if (mod_dir.empty())
     {
     mod_dir =
-      this->LocalGenerator->GetMakefile()->GetCurrentBinaryDirectory();
+      this->LocalGenerator->GetCurrentBinaryDirectory();
     }
 
   // Actually write dependencies to the streams.
diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx
index 37dd328..b480cd5 100644
--- a/Source/cmELF.cxx
+++ b/Source/cmELF.cxx
@@ -15,10 +15,6 @@
 #include <cmsys/auto_ptr.hxx>
 #include <cmsys/FStream.hxx>
 
-// Need the native byte order of the running CPU.
-#define cmsys_CPU_UNKNOWN_OKAY // We can decide at runtime if not known.
-#include <cmsys/CPU.h>
-
 // Include the ELF format information system header.
 #if defined(__OpenBSD__)
 # include <stdint.h>
@@ -102,9 +98,9 @@ public:
     // In most cases the processor-specific byte order will match that
     // of the target execution environment.  If we choose wrong here
     // it is fixed when the header is read.
-#if cmsys_CPU_ENDIAN_ID == cmsys_CPU_ENDIAN_ID_LITTLE
+#if KWIML_ABI_ENDIAN_ID == KWIML_ABI_ENDIAN_ID_LITTLE
     this->NeedSwap = (this->ByteOrder == ByteOrderMSB);
-#elif cmsys_CPU_ENDIAN_ID == cmsys_CPU_ENDIAN_ID_BIG
+#elif KWIML_ABI_ENDIAN_ID == KWIML_ABI_ENDIAN_ID_BIG
     this->NeedSwap = (this->ByteOrder == ByteOrderLSB);
 #else
     this->NeedSwap = false; // Final decision is at runtime anyway.
@@ -198,7 +194,7 @@ struct cmELFTypes32
   typedef Elf32_Shdr ELF_Shdr;
   typedef Elf32_Dyn  ELF_Dyn;
   typedef Elf32_Half ELF_Half;
-  typedef cmIML_INT_uint32_t tagtype;
+  typedef KWIML_INT_uint32_t tagtype;
   static const char* GetName() { return "32-bit"; }
 };
 
@@ -209,7 +205,7 @@ struct cmELFTypes64
   typedef Elf64_Shdr ELF_Shdr;
   typedef Elf64_Dyn  ELF_Dyn;
   typedef Elf64_Half ELF_Half;
-  typedef cmIML_INT_uint64_t tagtype;
+  typedef KWIML_INT_uint64_t tagtype;
   static const char* GetName() { return "64-bit"; }
 };
 
diff --git a/Source/cmEnableTestingCommand.cxx b/Source/cmEnableTestingCommand.cxx
index aa41ef7..6a7fd46 100644
--- a/Source/cmEnableTestingCommand.cxx
+++ b/Source/cmEnableTestingCommand.cxx
@@ -10,7 +10,6 @@
   See the License for more information.
 ============================================================================*/
 #include "cmEnableTestingCommand.h"
-#include "cmLocalGenerator.h"
 
 // we do this in the final pass so that we now the subdirs have all
 // been defined
diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx
index fed0dbc..dcb2187 100644
--- a/Source/cmExportBuildFileGenerator.cxx
+++ b/Source/cmExportBuildFileGenerator.cxx
@@ -18,16 +18,24 @@
 
 //----------------------------------------------------------------------------
 cmExportBuildFileGenerator::cmExportBuildFileGenerator()
-  : Backtrace()
 {
-  this->Makefile = 0;
+  this->LG = 0;
   this->ExportSet = 0;
 }
 
 //----------------------------------------------------------------------------
+void cmExportBuildFileGenerator::Compute(cmLocalGenerator* lg)
+{
+  this->LG = lg;
+  if (this->ExportSet)
+    {
+    this->ExportSet->Compute(lg);
+    }
+}
+
+//----------------------------------------------------------------------------
 bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
 {
-  std::vector<cmGeneratorTarget*> allTargets;
   {
   std::string expectedTargets;
   std::string sep;
@@ -37,11 +45,11 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
         tei = targets.begin();
       tei != targets.end(); ++tei)
     {
-    cmGeneratorTarget *te = this->Makefile
+    cmGeneratorTarget *te = this->LG
                                 ->FindGeneratorTargetToUse(*tei);
-    expectedTargets += sep + this->Namespace + te->Target->GetExportName();
+    expectedTargets += sep + this->Namespace + te->GetExportName();
     sep = " ";
-    if(this->ExportedTargets.insert(te->Target).second)
+    if(this->ExportedTargets.insert(te).second)
       {
       this->Exports.push_back(te);
       }
@@ -49,11 +57,12 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
       {
       std::ostringstream e;
       e << "given target \"" << te->GetName() << "\" more than once.";
-      this->Makefile->GetCMakeInstance()
-          ->IssueMessage(cmake::FATAL_ERROR, e.str(), this->Backtrace);
+      this->LG->GetGlobalGenerator()->GetCMakeInstance()
+          ->IssueMessage(cmake::FATAL_ERROR, e.str(),
+                         this->LG->GetMakefile()->GetBacktrace());
       return false;
       }
-    if (te->GetType() == cmTarget::INTERFACE_LIBRARY)
+    if (te->GetType() == cmState::INTERFACE_LIBRARY)
       {
       this->GenerateRequiredCMakeVersion(os, "3.0.0");
       }
@@ -70,45 +79,44 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
       tei != this->Exports.end(); ++tei)
     {
     cmGeneratorTarget* gte = *tei;
-    cmTarget* te = gte->Target;
-    this->GenerateImportTargetCode(os, te);
+    this->GenerateImportTargetCode(os, gte);
 
-    te->AppendBuildInterfaceIncludes();
+    gte->Target->AppendBuildInterfaceIncludes();
 
     ImportPropertyMap properties;
 
-    this->PopulateInterfaceProperty("INTERFACE_INCLUDE_DIRECTORIES", te,
+    this->PopulateInterfaceProperty("INTERFACE_INCLUDE_DIRECTORIES", gte,
                                     cmGeneratorExpression::BuildInterface,
                                     properties, missingTargets);
-    this->PopulateInterfaceProperty("INTERFACE_SOURCES", te,
+    this->PopulateInterfaceProperty("INTERFACE_SOURCES", gte,
                                     cmGeneratorExpression::BuildInterface,
                                     properties, missingTargets);
-    this->PopulateInterfaceProperty("INTERFACE_COMPILE_DEFINITIONS", te,
+    this->PopulateInterfaceProperty("INTERFACE_COMPILE_DEFINITIONS", gte,
                                     cmGeneratorExpression::BuildInterface,
                                     properties, missingTargets);
-    this->PopulateInterfaceProperty("INTERFACE_COMPILE_OPTIONS", te,
+    this->PopulateInterfaceProperty("INTERFACE_COMPILE_OPTIONS", gte,
                                     cmGeneratorExpression::BuildInterface,
                                     properties, missingTargets);
-    this->PopulateInterfaceProperty("INTERFACE_AUTOUIC_OPTIONS", te,
+    this->PopulateInterfaceProperty("INTERFACE_AUTOUIC_OPTIONS", gte,
                                     cmGeneratorExpression::BuildInterface,
                                     properties, missingTargets);
-    this->PopulateInterfaceProperty("INTERFACE_COMPILE_FEATURES", te,
+    this->PopulateInterfaceProperty("INTERFACE_COMPILE_FEATURES", gte,
                                     cmGeneratorExpression::BuildInterface,
                                     properties, missingTargets);
     this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE",
-                                  te, properties);
+                                  gte, properties);
     const bool newCMP0022Behavior =
-                              te->GetPolicyStatusCMP0022() != cmPolicies::WARN
-                           && te->GetPolicyStatusCMP0022() != cmPolicies::OLD;
+        gte->GetPolicyStatusCMP0022() != cmPolicies::WARN
+        && gte->GetPolicyStatusCMP0022() != cmPolicies::OLD;
     if (newCMP0022Behavior)
       {
-      this->PopulateInterfaceLinkLibrariesProperty(te,
+      this->PopulateInterfaceLinkLibrariesProperty(gte,
                                     cmGeneratorExpression::BuildInterface,
                                     properties, missingTargets);
       }
     this->PopulateCompatibleInterfaceProperties(gte, properties);
 
-    this->GenerateInterfaceProperties(te, os, properties);
+    this->GenerateInterfaceProperties(gte, os, properties);
     }
 
   // Generate import file content for each configuration.
@@ -140,14 +148,14 @@ cmExportBuildFileGenerator
     cmGeneratorTarget* target = *tei;
     ImportPropertyMap properties;
 
-    if (target->GetType() != cmTarget::INTERFACE_LIBRARY)
+    if (target->GetType() != cmState::INTERFACE_LIBRARY)
       {
       this->SetImportLocationProperty(config, suffix, target, properties);
       }
     if(!properties.empty())
       {
       // Get the rest of the target details.
-      if (target->GetType() != cmTarget::INTERFACE_LIBRARY)
+      if (target->GetType() != cmState::INTERFACE_LIBRARY)
         {
         this->SetImportDetailProperties(config, suffix,
                                         target,
@@ -165,7 +173,7 @@ cmExportBuildFileGenerator
       //                              properties);
 
       // Generate code in the export file.
-      this->GenerateImportPropertyCode(os, config, target->Target,
+      this->GenerateImportPropertyCode(os, config, target,
                                        properties);
       }
     }
@@ -193,7 +201,7 @@ cmExportBuildFileGenerator
   std::string prop = "IMPORTED_LOCATION";
   prop += suffix;
   std::string value;
-  if(target->Target->IsAppBundleOnApple())
+  if(target->IsAppBundleOnApple())
     {
     value = target->GetFullPath(config, false);
     }
@@ -204,20 +212,16 @@ cmExportBuildFileGenerator
   properties[prop] = value;
   }
 
-  // Check whether this is a DLL platform.
-  bool dll_platform =
-    (mf->IsOn("WIN32") || mf->IsOn("CYGWIN") || mf->IsOn("MINGW"));
-
   // Add the import library for windows DLLs.
-  if(dll_platform &&
-     (target->GetType() == cmTarget::SHARED_LIBRARY ||
-      target->Target->IsExecutableWithExports()) &&
+  if(target->IsDLLPlatform() &&
+     (target->GetType() == cmState::SHARED_LIBRARY ||
+      target->IsExecutableWithExports()) &&
      mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
     {
     std::string prop = "IMPORTED_IMPLIB";
     prop += suffix;
     std::string value = target->GetFullPath(config, true);
-    target->Target->GetImplibGNUtoMS(value, value,
+    target->GetImplibGNUtoMS(value, value,
                              "${CMAKE_IMPORT_LIBRARY_SUFFIX}");
     properties[prop] = value;
     }
@@ -226,14 +230,18 @@ cmExportBuildFileGenerator
 //----------------------------------------------------------------------------
 void
 cmExportBuildFileGenerator::HandleMissingTarget(
-  std::string& link_libs, std::vector<std::string>& missingTargets,
-  cmMakefile* mf, cmTarget* depender, cmTarget* dependee)
+    std::string& link_libs,
+    std::vector<std::string>& missingTargets,
+    cmGeneratorTarget* depender,
+    cmGeneratorTarget* dependee)
 {
   // The target is not in the export.
   if(!this->AppendMode)
     {
     const std::string name = dependee->GetName();
-    std::vector<std::string> namespaces = this->FindNamespaces(mf, name);
+    cmGlobalGenerator* gg =
+        dependee->GetLocalGenerator()->GetGlobalGenerator();
+    std::vector<std::string> namespaces = this->FindNamespaces(gg, name);
 
     int targetOccurrences = (int)namespaces.size();
     if (targetOccurrences == 1)
@@ -268,7 +276,7 @@ void cmExportBuildFileGenerator
           tei = this->ExportSet->GetTargetExports()->begin();
           tei != this->ExportSet->GetTargetExports()->end(); ++tei)
       {
-      targets.push_back((*tei)->Target->GetName());
+      targets.push_back((*tei)->TargetName);
       }
     return;
     }
@@ -278,10 +286,9 @@ void cmExportBuildFileGenerator
 //----------------------------------------------------------------------------
 std::vector<std::string>
 cmExportBuildFileGenerator
-::FindNamespaces(cmMakefile* mf, const std::string& name)
+::FindNamespaces(cmGlobalGenerator* gg, const std::string& name)
 {
   std::vector<std::string> namespaces;
-  cmGlobalGenerator* gg = mf->GetGlobalGenerator();
 
   std::map<std::string, cmExportBuildFileGenerator*>& exportSets
                                                   = gg->GetBuildExportSets();
@@ -304,8 +311,8 @@ cmExportBuildFileGenerator
 //----------------------------------------------------------------------------
 void
 cmExportBuildFileGenerator
-::ComplainAboutMissingTarget(cmTarget* depender,
-                             cmTarget* dependee,
+::ComplainAboutMissingTarget(cmGeneratorTarget* depender,
+                             cmGeneratorTarget* dependee,
                              int occurrences)
 {
   if(cmSystemTools::GetErrorOccuredFlag())
@@ -328,8 +335,9 @@ cmExportBuildFileGenerator
   e << "If the required target is not easy to reference in this call, "
     << "consider using the APPEND option with multiple separate calls.";
 
-  this->Makefile->GetCMakeInstance()
-      ->IssueMessage(cmake::FATAL_ERROR, e.str(), this->Backtrace);
+  this->LG->GetGlobalGenerator()->GetCMakeInstance()
+      ->IssueMessage(cmake::FATAL_ERROR, e.str(),
+                     this->LG->GetMakefile()->GetBacktrace());
 }
 
 std::string
diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h
index ff3d2e1..85aae2f 100644
--- a/Source/cmExportBuildFileGenerator.h
+++ b/Source/cmExportBuildFileGenerator.h
@@ -43,10 +43,7 @@ public:
   /** Set whether to append generated code to the output file.  */
   void SetAppendMode(bool append) { this->AppendMode = append; }
 
-  void SetMakefile(cmMakefile *mf) {
-    this->Makefile = mf;
-    this->Backtrace = this->Makefile->GetBacktrace();
-  }
+  void Compute(cmLocalGenerator* lg);
 
 protected:
   // Implement virtual methods from the superclass.
@@ -57,12 +54,11 @@ protected:
                             std::vector<std::string> &missingTargets);
   virtual void HandleMissingTarget(std::string& link_libs,
                                    std::vector<std::string>& missingTargets,
-                                   cmMakefile* mf,
-                                   cmTarget* depender,
-                                   cmTarget* dependee);
+                                   cmGeneratorTarget* depender,
+                                   cmGeneratorTarget* dependee);
 
-  void ComplainAboutMissingTarget(cmTarget* depender,
-                                  cmTarget* dependee,
+  void ComplainAboutMissingTarget(cmGeneratorTarget* depender,
+                                  cmGeneratorTarget* dependee,
                                   int occurrences);
 
   /** Fill in properties indicating built file locations.  */
@@ -75,13 +71,12 @@ protected:
                              const std::string& config);
 
   std::vector<std::string>
-  FindNamespaces(cmMakefile* mf, const std::string& name);
+  FindNamespaces(cmGlobalGenerator* gg, const std::string& name);
 
   std::vector<std::string> Targets;
   cmExportSet *ExportSet;
   std::vector<cmGeneratorTarget*> Exports;
-  cmMakefile* Makefile;
-  cmListFileBacktrace Backtrace;
+  cmLocalGenerator* LG;
 };
 
 #endif
diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx
index 96ea77b..4eec66a 100644
--- a/Source/cmExportCommand.cxx
+++ b/Source/cmExportCommand.cxx
@@ -11,7 +11,6 @@
 ============================================================================*/
 #include "cmExportCommand.h"
 #include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmGeneratedFileStream.h"
 #include "cmake.h"
 
@@ -169,7 +168,7 @@ bool cmExportCommand
 
       if(cmTarget* target = gg->FindTarget(*currentTarget))
         {
-        if(target->GetType() == cmTarget::OBJECT_LIBRARY)
+        if(target->GetType() == cmState::OBJECT_LIBRARY)
           {
           std::ostringstream e;
           e << "given OBJECT library \"" << *currentTarget
@@ -177,7 +176,7 @@ bool cmExportCommand
           this->SetError(e.str());
           return false;
           }
-        if (target->GetType() == cmTarget::UTILITY)
+        if (target->GetType() == cmState::UTILITY)
           {
           this->SetError("given custom target \"" + *currentTarget
                          + "\" which may not be exported.");
@@ -222,7 +221,7 @@ bool cmExportCommand
     {
     ebfg->SetTargets(targets);
     }
-  ebfg->SetMakefile(this->Makefile);
+  this->Makefile->AddExportBuildFileGenerator(ebfg);
   ebfg->SetExportOld(this->ExportOld.IsEnabled());
 
   // Compute the set of configurations exported.
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
index 9a7d73f..c005995 100644
--- a/Source/cmExportFileGenerator.cxx
+++ b/Source/cmExportFileGenerator.cxx
@@ -18,7 +18,6 @@
 #include "cmLocalGenerator.h"
 #include "cmMakefile.h"
 #include "cmSystemTools.h"
-#include "cmTarget.h"
 #include "cmTargetExport.h"
 #include "cmVersion.h"
 #include "cmComputeLinkInformation.h"
@@ -155,7 +154,7 @@ void cmExportFileGenerator::GenerateImportConfig(std::ostream& os,
 //----------------------------------------------------------------------------
 void cmExportFileGenerator::PopulateInterfaceProperty(
                                               const std::string& propName,
-                                              cmTarget *target,
+                                              cmGeneratorTarget *target,
                                               ImportPropertyMap &properties)
 {
   const char *input = target->GetProperty(propName);
@@ -169,7 +168,7 @@ void cmExportFileGenerator::PopulateInterfaceProperty(
 void cmExportFileGenerator::PopulateInterfaceProperty(
                       const std::string& propName,
                       const std::string& outputName,
-                      cmTarget *target,
+                      cmGeneratorTarget *target,
                       cmGeneratorExpression::PreprocessContext preprocessRule,
                       ImportPropertyMap &properties,
                       std::vector<std::string> &missingTargets)
@@ -206,7 +205,7 @@ void cmExportFileGenerator::GenerateRequiredCMakeVersion(std::ostream& os,
 
 //----------------------------------------------------------------------------
 bool cmExportFileGenerator::PopulateInterfaceLinkLibrariesProperty(
-                      cmTarget *target,
+                      cmGeneratorTarget *target,
                       cmGeneratorExpression::PreprocessContext preprocessRule,
                       ImportPropertyMap &properties,
                       std::vector<std::string> &missingTargets)
@@ -241,12 +240,14 @@ static bool isSubDirectory(const char* a, const char* b)
 
 //----------------------------------------------------------------------------
 static bool checkInterfaceDirs(const std::string &prepro,
-                      cmTarget *target, const std::string& prop)
+                      cmGeneratorTarget *target, const std::string& prop)
 {
   const char* installDir =
-            target->GetMakefile()->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
-  const char* topSourceDir = target->GetMakefile()->GetHomeDirectory();
-  const char* topBinaryDir = target->GetMakefile()->GetHomeOutputDirectory();
+            target->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
+  const char* topSourceDir =
+      target->GetLocalGenerator()->GetSourceDirectory();
+  const char* topBinaryDir =
+      target->GetLocalGenerator()->GetBinaryDirectory();
 
   std::vector<std::string> parts;
   cmGeneratorExpression::Split(prepro, parts);
@@ -298,7 +299,7 @@ static bool checkInterfaceDirs(const std::string &prepro,
       e << "Target \"" << target->GetName() << "\" " << prop <<
            " property contains relative path:\n"
            "  \"" << *li << "\"";
-      target->GetMakefile()->IssueMessage(messageType, e.str());
+      target->GetLocalGenerator()->IssueMessage(messageType, e.str());
       }
     bool inBinary = isSubDirectory(li->c_str(), topBinaryDir);
     bool inSource = isSubDirectory(li->c_str(), topSourceDir);
@@ -329,7 +330,7 @@ static bool checkInterfaceDirs(const std::string &prepro,
                 "a subdirectory of the " << (inBinary ? "build" : "source")
                 << " tree:\n    \"" << (inBinary ? topBinaryDir : topSourceDir)
                 << "\"" << std::endl;
-              target->GetMakefile()->IssueMessage(cmake::AUTHOR_WARNING,
+              target->GetLocalGenerator()->IssueMessage(cmake::AUTHOR_WARNING,
                                                   s.str());
               }
             case cmPolicies::OLD:
@@ -352,7 +353,7 @@ static bool checkInterfaceDirs(const std::string &prepro,
       e << "Target \"" << target->GetName() << "\" " << prop <<
            " property contains path:\n"
            "  \"" << *li << "\"\nwhich is prefixed in the build directory.";
-      target->GetMakefile()->IssueMessage(messageType, e.str());
+      target->GetLocalGenerator()->IssueMessage(messageType, e.str());
       }
     if (!inSourceBuild)
       {
@@ -361,7 +362,7 @@ static bool checkInterfaceDirs(const std::string &prepro,
         e << "Target \"" << target->GetName() << "\" " << prop <<
             " property contains path:\n"
             "  \"" << *li << "\"\nwhich is prefixed in the source directory.";
-        target->GetMakefile()->IssueMessage(messageType, e.str());
+        target->GetLocalGenerator()->IssueMessage(messageType, e.str());
         }
       }
     }
@@ -396,11 +397,11 @@ void cmExportFileGenerator::PopulateSourcesInterface(
                       ImportPropertyMap &properties,
                       std::vector<std::string> &missingTargets)
 {
-  cmTarget *target = tei->Target;
+  cmGeneratorTarget* gt = tei->Target;
   assert(preprocessRule == cmGeneratorExpression::InstallInterface);
 
   const char *propName = "INTERFACE_SOURCES";
-  const char *input = target->GetProperty(propName);
+  const char *input = gt->GetProperty(propName);
 
   if (!input)
     {
@@ -418,10 +419,10 @@ void cmExportFileGenerator::PopulateSourcesInterface(
                                                          true);
   if (!prepro.empty())
     {
-    this->ResolveTargetsInGeneratorExpressions(prepro, target,
+    this->ResolveTargetsInGeneratorExpressions(prepro, gt,
                                                 missingTargets);
 
-    if (!checkInterfaceDirs(prepro, target, propName))
+    if (!checkInterfaceDirs(prepro, gt, propName))
       {
       return;
       }
@@ -436,7 +437,7 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
                       ImportPropertyMap &properties,
                       std::vector<std::string> &missingTargets)
 {
-  cmTarget *target = tei->Target;
+  cmGeneratorTarget *target = tei->Target;
   assert(preprocessRule == cmGeneratorExpression::InstallInterface);
 
   const char *propName = "INTERFACE_INCLUDE_DIRECTORIES";
@@ -450,18 +451,18 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
                                             true);
   this->ReplaceInstallPrefix(dirs);
   cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs);
-  std::string exportDirs = cge->Evaluate(target->GetMakefile(), "",
+  std::string exportDirs = cge->Evaluate(target->GetLocalGenerator(), "",
                                          false, target);
 
   if (cge->GetHadContextSensitiveCondition())
     {
-    cmMakefile* mf = target->GetMakefile();
+    cmLocalGenerator* lg = target->GetLocalGenerator();
     std::ostringstream e;
     e << "Target \"" << target->GetName() << "\" is installed with "
     "INCLUDES DESTINATION set to a context sensitive path.  Paths which "
     "depend on the configuration, policy values or the link interface are "
     "not supported.  Consider using target_include_directories instead.";
-    mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+    lg->IssueMessage(cmake::FATAL_ERROR, e.str());
     return;
     }
 
@@ -500,7 +501,7 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
 //----------------------------------------------------------------------------
 void cmExportFileGenerator::PopulateInterfaceProperty(
                       const std::string& propName,
-                      cmTarget *target,
+                      cmGeneratorTarget* target,
                       cmGeneratorExpression::PreprocessContext preprocessRule,
                       ImportPropertyMap &properties,
                       std::vector<std::string> &missingTargets)
@@ -511,8 +512,9 @@ void cmExportFileGenerator::PopulateInterfaceProperty(
 
 
 //----------------------------------------------------------------------------
-void getPropertyContents(cmTarget const* tgt, const std::string& prop,
-         std::set<std::string> &ifaceProperties)
+void getPropertyContents(cmGeneratorTarget const* tgt,
+                         const std::string& prop,
+                         std::set<std::string> &ifaceProperties)
 {
   const char *p = tgt->GetProperty(prop);
   if (!p)
@@ -533,11 +535,11 @@ void getCompatibleInterfaceProperties(cmGeneratorTarget *target,
 
   if (!info)
     {
-    cmMakefile* mf = target->Target->GetMakefile();
+    cmLocalGenerator* lg = target->GetLocalGenerator();
     std::ostringstream e;
     e << "Exporting the target \"" << target->GetName() << "\" is not "
         "allowed since its linker language cannot be determined";
-    mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+    lg->IssueMessage(cmake::FATAL_ERROR, e.str());
     return;
     }
 
@@ -571,31 +573,30 @@ void cmExportFileGenerator::PopulateCompatibleInterfaceProperties(
                                 cmGeneratorTarget *gtarget,
                                 ImportPropertyMap &properties)
 {
-  cmTarget *target = gtarget->Target;
   this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_BOOL",
-                                target, properties);
+                                gtarget, properties);
   this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_STRING",
-                                target, properties);
+                                gtarget, properties);
   this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_NUMBER_MIN",
-                                target, properties);
+                                gtarget, properties);
   this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_NUMBER_MAX",
-                                target, properties);
+                                gtarget, properties);
 
   std::set<std::string> ifaceProperties;
 
-  getPropertyContents(target, "COMPATIBLE_INTERFACE_BOOL", ifaceProperties);
-  getPropertyContents(target, "COMPATIBLE_INTERFACE_STRING", ifaceProperties);
-  getPropertyContents(target, "COMPATIBLE_INTERFACE_NUMBER_MIN",
+  getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_BOOL", ifaceProperties);
+  getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_STRING", ifaceProperties);
+  getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_NUMBER_MIN",
                       ifaceProperties);
-  getPropertyContents(target, "COMPATIBLE_INTERFACE_NUMBER_MAX",
+  getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_NUMBER_MAX",
                       ifaceProperties);
 
-  if (target->GetType() != cmTarget::INTERFACE_LIBRARY)
+  if (gtarget->GetType() != cmState::INTERFACE_LIBRARY)
     {
     getCompatibleInterfaceProperties(gtarget, ifaceProperties, "");
 
     std::vector<std::string> configNames;
-    target->GetMakefile()->GetConfigurations(configNames);
+    gtarget->Target->GetMakefile()->GetConfigurations(configNames);
 
     for (std::vector<std::string>::const_iterator ci = configNames.begin();
       ci != configNames.end(); ++ci)
@@ -608,12 +609,13 @@ void cmExportFileGenerator::PopulateCompatibleInterfaceProperties(
     it != ifaceProperties.end(); ++it)
     {
     this->PopulateInterfaceProperty("INTERFACE_" + *it,
-                                    target, properties);
+                                    gtarget, properties);
     }
 }
 
 //----------------------------------------------------------------------------
-void cmExportFileGenerator::GenerateInterfaceProperties(cmTarget const* target,
+void cmExportFileGenerator::GenerateInterfaceProperties(
+                                        const cmGeneratorTarget* target,
                                         std::ostream& os,
                                         const ImportPropertyMap &properties)
 {
@@ -635,12 +637,12 @@ void cmExportFileGenerator::GenerateInterfaceProperties(cmTarget const* target,
 //----------------------------------------------------------------------------
 bool
 cmExportFileGenerator::AddTargetNamespace(std::string &input,
-                                    cmTarget* target,
+                                    cmGeneratorTarget* target,
                                     std::vector<std::string> &missingTargets)
 {
-  cmMakefile *mf = target->GetMakefile();
+  cmLocalGenerator *lg = target->GetLocalGenerator();
 
-  cmTarget *tgt = mf->FindTargetToUse(input);
+  cmGeneratorTarget *tgt = lg->FindGeneratorTargetToUse(input);
   if (!tgt)
     {
     return false;
@@ -658,7 +660,7 @@ cmExportFileGenerator::AddTargetNamespace(std::string &input,
     {
     std::string namespacedTarget;
     this->HandleMissingTarget(namespacedTarget, missingTargets,
-                              mf, target, tgt);
+                              target, tgt);
     if (!namespacedTarget.empty())
       {
       input = namespacedTarget;
@@ -671,7 +673,7 @@ cmExportFileGenerator::AddTargetNamespace(std::string &input,
 void
 cmExportFileGenerator::ResolveTargetsInGeneratorExpressions(
                                     std::string &input,
-                                    cmTarget* target,
+                                    cmGeneratorTarget* target,
                                     std::vector<std::string> &missingTargets,
                                     FreeTargetsReplace replace)
 {
@@ -708,14 +710,12 @@ cmExportFileGenerator::ResolveTargetsInGeneratorExpressions(
 void
 cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
                                     std::string &input,
-                                    cmTarget* target,
+                                    cmGeneratorTarget* target,
                                     std::vector<std::string> &missingTargets)
 {
   std::string::size_type pos = 0;
   std::string::size_type lastPos = pos;
 
-  cmMakefile *mf = target->GetMakefile();
-
   while((pos = input.find("$<TARGET_PROPERTY:", lastPos)) != input.npos)
     {
     std::string::size_type nameStartPos = pos +
@@ -772,11 +772,32 @@ cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
     lastPos = endPos;
     }
 
+  pos = 0;
+  lastPos = pos;
+  while (errorString.empty() &&
+         (pos = input.find("$<LINK_ONLY:", lastPos)) != input.npos)
+    {
+    std::string::size_type nameStartPos = pos + sizeof("$<LINK_ONLY:") - 1;
+    std::string::size_type endPos = input.find(">", nameStartPos);
+    if (endPos == input.npos)
+      {
+      errorString = "$<LINK_ONLY:...> expression incomplete";
+      break;
+      }
+    std::string libName = input.substr(nameStartPos, endPos - nameStartPos);
+    if (cmGeneratorExpression::IsValidTargetName(libName) &&
+        this->AddTargetNamespace(libName, target, missingTargets))
+      {
+      input.replace(nameStartPos, endPos - nameStartPos, libName);
+      }
+    lastPos = nameStartPos + libName.size() + 1;
+    }
+
   this->ReplaceInstallPrefix(input);
 
   if (!errorString.empty())
     {
-    mf->IssueMessage(cmake::FATAL_ERROR, errorString);
+    target->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, errorString);
     }
 }
 
@@ -797,7 +818,7 @@ cmExportFileGenerator
 {
   // Add the transitive link dependencies for this configuration.
   cmLinkInterface const* iface = target->GetLinkInterface(config,
-                                                          target->Target);
+                                                          target);
   if (!iface)
     {
     return;
@@ -830,20 +851,18 @@ cmExportFileGenerator
     }
 
   const bool newCMP0022Behavior =
-                        target->Target
-                              ->GetPolicyStatusCMP0022() != cmPolicies::WARN
-                     && target->Target
-                              ->GetPolicyStatusCMP0022() != cmPolicies::OLD;
+                        target->GetPolicyStatusCMP0022() != cmPolicies::WARN
+                     && target->GetPolicyStatusCMP0022() != cmPolicies::OLD;
 
   if(newCMP0022Behavior && !this->ExportOld)
     {
-    cmMakefile *mf = target->Target->GetMakefile();
+    cmLocalGenerator *lg = target->GetLocalGenerator();
     std::ostringstream e;
     e << "Target \"" << target->GetName() << "\" has policy CMP0022 enabled, "
          "but also has old-style LINK_INTERFACE_LIBRARIES properties "
          "populated, but it was exported without the "
          "EXPORT_LINK_INTERFACE_LIBRARIES to export the old-style properties";
-    mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+    lg->IssueMessage(cmake::FATAL_ERROR, e.str());
     return;
     }
 
@@ -857,7 +876,7 @@ cmExportFileGenerator
                                                          preprocessRule);
   if (!prepro.empty())
     {
-    this->ResolveTargetsInGeneratorExpressions(prepro, target->Target,
+    this->ResolveTargetsInGeneratorExpressions(prepro, target,
                                                missingTargets,
                                                ReplaceFreeTargets);
     properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = prepro;
@@ -878,13 +897,10 @@ cmExportFileGenerator
   cmMakefile* mf = target->Makefile;
 
   // Add the soname for unix shared libraries.
-  if(target->GetType() == cmTarget::SHARED_LIBRARY ||
-     target->GetType() == cmTarget::MODULE_LIBRARY)
+  if(target->GetType() == cmState::SHARED_LIBRARY ||
+     target->GetType() == cmState::MODULE_LIBRARY)
     {
-    // Check whether this is a DLL platform.
-    bool dll_platform =
-      (mf->IsOn("WIN32") || mf->IsOn("CYGWIN") || mf->IsOn("MINGW"));
-    if(!dll_platform)
+    if(!target->IsDLLPlatform())
       {
       std::string prop;
       std::string value;
@@ -909,7 +925,7 @@ cmExportFileGenerator
 
   // Add the transitive link dependencies for this configuration.
   if(cmLinkInterface const* iface =
-                            target->GetLinkInterface(config, target->Target))
+                            target->GetLinkInterface(config, target))
     {
     this->SetImportLinkProperty(suffix, target,
                                 "IMPORTED_LINK_INTERFACE_LANGUAGES",
@@ -959,7 +975,7 @@ cmExportFileGenerator
     sep = ";";
 
     std::string temp = *li;
-    this->AddTargetNamespace(temp, target->Target, missingTargets);
+    this->AddTargetNamespace(temp, target, missingTargets);
     link_entries += temp;
     }
 
@@ -1041,7 +1057,7 @@ void cmExportFileGenerator::GenerateExpectedTargetsCode(std::ostream& os,
 //----------------------------------------------------------------------------
 void
 cmExportFileGenerator
-::GenerateImportTargetCode(std::ostream& os, cmTarget const* target)
+::GenerateImportTargetCode(std::ostream& os, const cmGeneratorTarget* target)
 {
   // Construct the imported target name.
   std::string targetName = this->Namespace;
@@ -1052,22 +1068,22 @@ cmExportFileGenerator
   os << "# Create imported target " << targetName << "\n";
   switch(target->GetType())
     {
-    case cmTarget::EXECUTABLE:
+    case cmState::EXECUTABLE:
       os << "add_executable(" << targetName << " IMPORTED)\n";
       break;
-    case cmTarget::STATIC_LIBRARY:
+    case cmState::STATIC_LIBRARY:
       os << "add_library(" << targetName << " STATIC IMPORTED)\n";
       break;
-    case cmTarget::SHARED_LIBRARY:
+    case cmState::SHARED_LIBRARY:
       os << "add_library(" << targetName << " SHARED IMPORTED)\n";
       break;
-    case cmTarget::MODULE_LIBRARY:
+    case cmState::MODULE_LIBRARY:
       os << "add_library(" << targetName << " MODULE IMPORTED)\n";
       break;
-    case cmTarget::UNKNOWN_LIBRARY:
+    case cmState::UNKNOWN_LIBRARY:
       os << "add_library(" << targetName << " UNKNOWN IMPORTED)\n";
       break;
-    case cmTarget::INTERFACE_LIBRARY:
+    case cmState::INTERFACE_LIBRARY:
       os << "add_library(" << targetName << " INTERFACE IMPORTED)\n";
       break;
     default:  // should never happen
@@ -1107,7 +1123,7 @@ cmExportFileGenerator
 void
 cmExportFileGenerator
 ::GenerateImportPropertyCode(std::ostream& os, const std::string& config,
-                             cmTarget const* target,
+                             cmGeneratorTarget const* target,
                              ImportPropertyMap const& properties)
 {
   // Construct the imported target name.
@@ -1227,7 +1243,7 @@ cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
 //----------------------------------------------------------------------------
 void
 cmExportFileGenerator
-::GenerateImportedFileChecksCode(std::ostream& os, cmTarget* target,
+::GenerateImportedFileChecksCode(std::ostream& os, cmGeneratorTarget* target,
                                  ImportPropertyMap const& properties,
                                 const std::set<std::string>& importedLocations)
 {
diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h
index 44f779b..18f0b00 100644
--- a/Source/cmExportFileGenerator.h
+++ b/Source/cmExportFileGenerator.h
@@ -75,11 +75,13 @@ protected:
                                 const std::string& config = "");
   void GenerateImportFooterCode(std::ostream& os);
   void GenerateImportVersionCode(std::ostream& os);
-  void GenerateImportTargetCode(std::ostream& os, cmTarget const* target);
+  void GenerateImportTargetCode(std::ostream& os,
+                                cmGeneratorTarget const* target);
   void GenerateImportPropertyCode(std::ostream& os, const std::string& config,
-                                  cmTarget const* target,
+                                  cmGeneratorTarget const* target,
                                   ImportPropertyMap const& properties);
-  void GenerateImportedFileChecksCode(std::ostream& os, cmTarget* target,
+  void GenerateImportedFileChecksCode(std::ostream& os,
+                                      cmGeneratorTarget* target,
                                       ImportPropertyMap const& properties,
                                const std::set<std::string>& importedLocations);
   void GenerateImportedFileCheckLoop(std::ostream& os);
@@ -118,23 +120,24 @@ protected:
    *  export set.  */
   virtual void HandleMissingTarget(std::string& link_libs,
                                    std::vector<std::string>& missingTargets,
-                                   cmMakefile* mf,
-                                   cmTarget* depender,
-                                   cmTarget* dependee) = 0;
+                                   cmGeneratorTarget* depender,
+                                   cmGeneratorTarget* dependee) = 0;
   void PopulateInterfaceProperty(const std::string&,
-                                 cmTarget *target,
+                                 cmGeneratorTarget *target,
                                  cmGeneratorExpression::PreprocessContext,
                                  ImportPropertyMap &properties,
                                  std::vector<std::string> &missingTargets);
-  bool PopulateInterfaceLinkLibrariesProperty(cmTarget *target,
+  bool PopulateInterfaceLinkLibrariesProperty(cmGeneratorTarget* target,
                                  cmGeneratorExpression::PreprocessContext,
                                  ImportPropertyMap &properties,
                                  std::vector<std::string> &missingTargets);
-  void PopulateInterfaceProperty(const std::string& propName, cmTarget *target,
+  void PopulateInterfaceProperty(const std::string& propName,
+                                 cmGeneratorTarget* target,
                                  ImportPropertyMap &properties);
   void PopulateCompatibleInterfaceProperties(cmGeneratorTarget *target,
                                  ImportPropertyMap &properties);
-  void GenerateInterfaceProperties(cmTarget const* target, std::ostream& os,
+  void GenerateInterfaceProperties(cmGeneratorTarget const* target,
+                                   std::ostream& os,
                                    const ImportPropertyMap &properties);
   void PopulateIncludeDirectoriesInterface(
                       cmTargetExport *target,
@@ -159,7 +162,7 @@ protected:
   };
 
   void ResolveTargetsInGeneratorExpressions(std::string &input,
-                          cmTarget* target,
+                          cmGeneratorTarget* target,
                           std::vector<std::string> &missingTargets,
                           FreeTargetsReplace replace = NoReplaceFreeTargets);
 
@@ -182,20 +185,20 @@ protected:
   bool AppendMode;
 
   // The set of targets included in the export.
-  std::set<cmTarget*> ExportedTargets;
+  std::set<cmGeneratorTarget*> ExportedTargets;
 
 private:
   void PopulateInterfaceProperty(const std::string&, const std::string&,
-                                 cmTarget *target,
+                                 cmGeneratorTarget* target,
                                  cmGeneratorExpression::PreprocessContext,
                                  ImportPropertyMap &properties,
                                  std::vector<std::string> &missingTargets);
 
-  bool AddTargetNamespace(std::string &input, cmTarget* target,
+  bool AddTargetNamespace(std::string &input, cmGeneratorTarget* target,
                           std::vector<std::string> &missingTargets);
 
   void ResolveTargetsInGeneratorExpression(std::string &input,
-                                    cmTarget* target,
+                                    cmGeneratorTarget* target,
                                     std::vector<std::string> &missingTargets);
 
   virtual void ReplaceInstallPrefix(std::string &input);
diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx
index 7ffab0c..71418e8 100644
--- a/Source/cmExportInstallFileGenerator.cxx
+++ b/Source/cmExportInstallFileGenerator.cxx
@@ -48,7 +48,8 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
         tei = this->IEGen->GetExportSet()->GetTargetExports()->begin();
       tei != this->IEGen->GetExportSet()->GetTargetExports()->end(); ++tei)
     {
-    expectedTargets += sep + this->Namespace + (*tei)->Target->GetExportName();
+    expectedTargets +=
+        sep + this->Namespace + (*tei)->Target->GetExportName();
     sep = " ";
     cmTargetExport * te = *tei;
     if(this->ExportedTargets.insert(te->Target).second)
@@ -131,12 +132,12 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
         tei = allTargets.begin();
       tei != allTargets.end(); ++tei)
     {
-    cmTarget* te = (*tei)->Target;
+    cmGeneratorTarget* gt = (*tei)->Target;
 
     requiresConfigFiles = requiresConfigFiles
-                              || te->GetType() != cmTarget::INTERFACE_LIBRARY;
+                              || gt->GetType() != cmState::INTERFACE_LIBRARY;
 
-    this->GenerateImportTargetCode(os, te);
+    this->GenerateImportTargetCode(os, gt);
 
     ImportPropertyMap properties;
 
@@ -147,32 +148,32 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
                                   cmGeneratorExpression::InstallInterface,
                                   properties, missingTargets);
     this->PopulateInterfaceProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES",
-                                  te,
+                                  gt,
                                   cmGeneratorExpression::InstallInterface,
                                   properties, missingTargets);
     this->PopulateInterfaceProperty("INTERFACE_COMPILE_DEFINITIONS",
-                                  te,
+                                  gt,
                                   cmGeneratorExpression::InstallInterface,
                                   properties, missingTargets);
     this->PopulateInterfaceProperty("INTERFACE_COMPILE_OPTIONS",
-                                  te,
+                                  gt,
                                   cmGeneratorExpression::InstallInterface,
                                   properties, missingTargets);
     this->PopulateInterfaceProperty("INTERFACE_AUTOUIC_OPTIONS",
-                                  te,
+                                  gt,
                                   cmGeneratorExpression::InstallInterface,
                                   properties, missingTargets);
     this->PopulateInterfaceProperty("INTERFACE_COMPILE_FEATURES",
-                                  te,
+                                  gt,
                                   cmGeneratorExpression::InstallInterface,
                                   properties, missingTargets);
 
     const bool newCMP0022Behavior =
-                              te->GetPolicyStatusCMP0022() != cmPolicies::WARN
-                           && te->GetPolicyStatusCMP0022() != cmPolicies::OLD;
+        gt->GetPolicyStatusCMP0022() != cmPolicies::WARN
+        && gt->GetPolicyStatusCMP0022() != cmPolicies::OLD;
     if (newCMP0022Behavior)
       {
-      if (this->PopulateInterfaceLinkLibrariesProperty(te,
+      if (this->PopulateInterfaceLinkLibrariesProperty(gt,
                                     cmGeneratorExpression::InstallInterface,
                                     properties, missingTargets)
           && !this->ExportOld)
@@ -180,11 +181,11 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
         require2_8_12 = true;
         }
       }
-    if (te->GetType() == cmTarget::INTERFACE_LIBRARY)
+    if (gt->GetType() == cmState::INTERFACE_LIBRARY)
       {
       require3_0_0 = true;
       }
-    if(te->GetProperty("INTERFACE_SOURCES"))
+    if(gt->GetProperty("INTERFACE_SOURCES"))
       {
       // We can only generate INTERFACE_SOURCES in CMake 3.3, but CMake 3.1
       // can consume them.
@@ -192,14 +193,11 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
       }
 
     this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE",
-                                  te, properties);
-    cmGeneratorTarget *gtgt = te->GetMakefile()
-                                ->GetGlobalGenerator()
-                                ->GetGeneratorTarget(te);
+                                  gt, properties);
 
-    this->PopulateCompatibleInterfaceProperties(gtgt, properties);
+    this->PopulateCompatibleInterfaceProperties(gt, properties);
 
-    this->GenerateInterfaceProperties(te, os, properties);
+    this->GenerateInterfaceProperties(gt, os, properties);
     }
 
   if (require3_1_0)
@@ -337,7 +335,7 @@ cmExportInstallFileGenerator
     {
     // Collect import properties for this target.
     cmTargetExport const* te = *tei;
-    if (te->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
+    if (te->Target->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
@@ -362,8 +360,7 @@ cmExportInstallFileGenerator
     if(!properties.empty())
       {
       // Get the rest of the target details.
-      cmGeneratorTarget *gtgt = te->Target->GetMakefile()
-                    ->GetGlobalGenerator()->GetGeneratorTarget(te->Target);
+      cmGeneratorTarget *gtgt = te->Target;
       this->SetImportDetailProperties(config, suffix,
                                       gtgt, properties, missingTargets);
 
@@ -378,8 +375,8 @@ cmExportInstallFileGenerator
       //                              properties);
 
       // Generate code in the export file.
-      this->GenerateImportPropertyCode(os, config, te->Target, properties);
-      this->GenerateImportedFileChecksCode(os, te->Target, properties,
+      this->GenerateImportPropertyCode(os, config, gtgt, properties);
+      this->GenerateImportedFileChecksCode(os, gtgt, properties,
                                            importedLocations);
       }
     }
@@ -402,7 +399,7 @@ cmExportInstallFileGenerator
     }
 
   // Get the target to be installed.
-  cmTarget* target = itgen->GetTarget()->Target;
+  cmGeneratorTarget* target = itgen->GetTarget();
 
   // Construct the installed location of the target.
   std::string dest = itgen->GetDestination(config);
@@ -456,12 +453,13 @@ cmExportInstallFileGenerator
 
 //----------------------------------------------------------------------------
 void
-cmExportInstallFileGenerator::HandleMissingTarget(
-  std::string& link_libs, std::vector<std::string>& missingTargets,
-  cmMakefile* mf, cmTarget* depender, cmTarget* dependee)
+cmExportInstallFileGenerator::HandleMissingTarget(std::string& link_libs,
+  std::vector<std::string>& missingTargets,
+  cmGeneratorTarget* depender, cmGeneratorTarget* dependee)
 {
   const std::string name = dependee->GetName();
-  std::vector<std::string> namespaces = this->FindNamespaces(mf, name);
+  cmGlobalGenerator* gg = dependee->GetLocalGenerator()->GetGlobalGenerator();
+  std::vector<std::string> namespaces = this->FindNamespaces(gg, name);
   int targetOccurrences = (int)namespaces.size();
   if (targetOccurrences == 1)
     {
@@ -482,10 +480,9 @@ cmExportInstallFileGenerator::HandleMissingTarget(
 //----------------------------------------------------------------------------
 std::vector<std::string>
 cmExportInstallFileGenerator
-::FindNamespaces(cmMakefile* mf, const std::string& name)
+::FindNamespaces(cmGlobalGenerator* gg, const std::string& name)
 {
   std::vector<std::string> namespaces;
-  cmGlobalGenerator* gg = mf->GetGlobalGenerator();
   const cmExportSetMap& exportSets = gg->GetExportSets();
 
   for(cmExportSetMap::const_iterator expIt = exportSets.begin();
@@ -499,7 +496,7 @@ cmExportInstallFileGenerator
     bool containsTarget = false;
     for(unsigned int i=0; i<targets->size(); i++)
       {
-      if (name == (*targets)[i]->Target->GetName())
+      if (name == (*targets)[i]->TargetName)
         {
         containsTarget = true;
         break;
@@ -523,8 +520,8 @@ cmExportInstallFileGenerator
 //----------------------------------------------------------------------------
 void
 cmExportInstallFileGenerator
-::ComplainAboutMissingTarget(cmTarget* depender,
-                             cmTarget* dependee,
+::ComplainAboutMissingTarget(cmGeneratorTarget* depender,
+                             cmGeneratorTarget* dependee,
                              int occurrences)
 {
   std::ostringstream e;
diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h
index b06fee5..13dae89 100644
--- a/Source/cmExportInstallFileGenerator.h
+++ b/Source/cmExportInstallFileGenerator.h
@@ -57,17 +57,16 @@ protected:
                             std::vector<std::string> &missingTargets);
   virtual void HandleMissingTarget(std::string& link_libs,
                                    std::vector<std::string>& missingTargets,
-                                   cmMakefile* mf,
-                                   cmTarget* depender,
-                                   cmTarget* dependee);
+                                   cmGeneratorTarget* depender,
+                                   cmGeneratorTarget* dependee);
 
   virtual void ReplaceInstallPrefix(std::string &input);
 
-  void ComplainAboutMissingTarget(cmTarget* depender,
-                                  cmTarget* dependee,
+  void ComplainAboutMissingTarget(cmGeneratorTarget* depender,
+                                  cmGeneratorTarget* dependee,
                                   int occurrences);
 
-  std::vector<std::string> FindNamespaces(cmMakefile* mf,
+  std::vector<std::string> FindNamespaces(cmGlobalGenerator* gg,
                                           const std::string& name);
 
 
diff --git a/Source/cmExportLibraryDependenciesCommand.cxx b/Source/cmExportLibraryDependenciesCommand.cxx
index fde8fb1..21d961f 100644
--- a/Source/cmExportLibraryDependenciesCommand.cxx
+++ b/Source/cmExportLibraryDependenciesCommand.cxx
@@ -96,8 +96,8 @@ void cmExportLibraryDependenciesCommand::ConstFinalPass() const
       cmTarget const& target = l->second;
 
       // Skip non-library targets.
-      if(target.GetType() < cmTarget::STATIC_LIBRARY
-         || target.GetType() > cmTarget::MODULE_LIBRARY)
+      if(target.GetType() < cmState::STATIC_LIBRARY
+         || target.GetType() > cmState::MODULE_LIBRARY)
         {
         continue;
         }
@@ -120,15 +120,15 @@ void cmExportLibraryDependenciesCommand::ConstFinalPass() const
         std::string ltValue;
         switch(li->second)
           {
-          case cmTarget::GENERAL:
+          case GENERAL_LibraryType:
             valueNew += "general;";
             ltValue = "general";
             break;
-          case cmTarget::DEBUG:
+          case DEBUG_LibraryType:
             valueNew += "debug;";
             ltValue = "debug";
             break;
-          case cmTarget::OPTIMIZED:
+          case OPTIMIZED_LibraryType:
             valueNew += "optimized;";
             ltValue = "optimized";
             break;
diff --git a/Source/cmExportSet.cxx b/Source/cmExportSet.cxx
index 4148fb5..0059b64 100644
--- a/Source/cmExportSet.cxx
+++ b/Source/cmExportSet.cxx
@@ -13,12 +13,22 @@
 #include "cmExportSet.h"
 #include "cmTargetExport.h"
 #include "cmAlgorithms.h"
+#include "cmLocalGenerator.h"
 
 cmExportSet::~cmExportSet()
 {
   cmDeleteAll(this->TargetExports);
 }
 
+void cmExportSet::Compute(cmLocalGenerator* lg)
+{
+  for (std::vector<cmTargetExport*>::iterator it = this->TargetExports.begin();
+       it != this->TargetExports.end(); ++it)
+    {
+    (*it)->Target = lg->FindGeneratorTargetToUse((*it)->TargetName);
+    }
+}
+
 void cmExportSet::AddTargetExport(cmTargetExport* te)
 {
   this->TargetExports.push_back(te);
diff --git a/Source/cmExportSet.h b/Source/cmExportSet.h
index a57aa12..d780a22 100644
--- a/Source/cmExportSet.h
+++ b/Source/cmExportSet.h
@@ -15,6 +15,7 @@
 #include "cmSystemTools.h"
 class cmTargetExport;
 class cmInstallExportGenerator;
+class cmLocalGenerator;
 
 /// A set of targets that were installed with the same EXPORT parameter.
 class cmExportSet
@@ -25,6 +26,8 @@ public:
   /// Destructor
   ~cmExportSet();
 
+  void Compute(cmLocalGenerator* lg);
+
   void AddTargetExport(cmTargetExport* tgt);
 
   void AddInstallation(cmInstallExportGenerator const* installation);
diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx
index ba66531..83127e7 100644
--- a/Source/cmExportTryCompileFileGenerator.cxx
+++ b/Source/cmExportTryCompileFileGenerator.cxx
@@ -14,22 +14,25 @@
 
 #include "cmGeneratedFileStream.h"
 #include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
 #include "cmGeneratorExpressionDAGChecker.h"
 
 //----------------------------------------------------------------------------
 cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator(
-    cmGlobalGenerator* gg)
+    cmGlobalGenerator* gg,
+    const std::vector<std::string>& targets,
+    cmMakefile* mf)
 {
-  gg->CreateGenerationObjects(cmGlobalGenerator::ImportedOnly);
+  gg->CreateImportedGenerationObjects(mf, targets, this->Exports);
 }
 
 bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os)
 {
-  std::set<cmTarget const*> emitted;
-  std::set<cmTarget const*> emittedDeps;
+  std::set<cmGeneratorTarget const*> emitted;
+  std::set<cmGeneratorTarget const*> emittedDeps;
   while(!this->Exports.empty())
     {
-    cmTarget const* te = this->Exports.back();
+    cmGeneratorTarget const* te = this->Exports.back();
     this->Exports.pop_back();
     if (emitted.insert(te).second)
       {
@@ -54,9 +57,9 @@ bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os)
 }
 
 std::string cmExportTryCompileFileGenerator::FindTargets(
-                                          const std::string& propName,
-                                          cmTarget const* tgt,
-                                          std::set<cmTarget const*> &emitted)
+                                  const std::string& propName,
+                                  cmGeneratorTarget const* tgt,
+                                  std::set<cmGeneratorTarget const*> &emitted)
 {
   const char *prop = tgt->GetProperty(propName);
   if(!prop)
@@ -73,15 +76,19 @@ std::string cmExportTryCompileFileGenerator::FindTargets(
   cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
 
   cmTarget dummyHead;
-  dummyHead.SetType(cmTarget::EXECUTABLE, "try_compile_dummy_exe");
-  dummyHead.SetMakefile(tgt->GetMakefile());
+  dummyHead.SetType(cmState::EXECUTABLE, "try_compile_dummy_exe");
+  dummyHead.SetMakefile(tgt->Target->GetMakefile());
 
-  std::string result = cge->Evaluate(tgt->GetMakefile(), this->Config,
-                                     false, &dummyHead, tgt, &dagChecker);
+  cmGeneratorTarget gDummyHead(&dummyHead, tgt->GetLocalGenerator());
 
-  const std::set<cmTarget const*> &allTargets = cge->GetAllTargetsSeen();
-  for(std::set<cmTarget const*>::const_iterator li = allTargets.begin();
-      li != allTargets.end(); ++li)
+  std::string result = cge->Evaluate(tgt->GetLocalGenerator(), this->Config,
+                                     false, &gDummyHead,
+                                     tgt, &dagChecker);
+
+  const std::set<cmGeneratorTarget const*> &allTargets =
+      cge->GetAllTargetsSeen();
+  for(std::set<cmGeneratorTarget const*>::const_iterator li =
+      allTargets.begin(); li != allTargets.end(); ++li)
     {
     if(emitted.insert(*li).second)
       {
@@ -93,20 +100,23 @@ std::string cmExportTryCompileFileGenerator::FindTargets(
 
 //----------------------------------------------------------------------------
 void
-cmExportTryCompileFileGenerator::PopulateProperties(cmTarget const* target,
-                                                ImportPropertyMap& properties,
-                                          std::set<cmTarget const*> &emitted)
+cmExportTryCompileFileGenerator::PopulateProperties(
+                                 const cmGeneratorTarget* target,
+                                 ImportPropertyMap& properties,
+                                 std::set<cmGeneratorTarget const*> &emitted)
 {
-  cmPropertyMap props = target->GetProperties();
-  for(cmPropertyMap::const_iterator i = props.begin(); i != props.end(); ++i)
+  std::vector<std::string> props = target->GetPropertyKeys();
+  for(std::vector<std::string>::const_iterator i = props.begin();
+      i != props.end(); ++i)
     {
-    properties[i->first] = i->second.GetValue();
 
-    if(i->first.find("IMPORTED_LINK_INTERFACE_LIBRARIES") == 0
-        || i->first.find("IMPORTED_LINK_DEPENDENT_LIBRARIES") == 0
-        || i->first.find("INTERFACE_LINK_LIBRARIES") == 0)
+    properties[*i] = target->GetProperty(*i);
+
+    if(i->find("IMPORTED_LINK_INTERFACE_LIBRARIES") == 0
+        || i->find("IMPORTED_LINK_DEPENDENT_LIBRARIES") == 0
+        || i->find("INTERFACE_LINK_LIBRARIES") == 0)
       {
-      std::string evalResult = this->FindTargets(i->first,
+      std::string evalResult = this->FindTargets(*i,
                                                  target, emitted);
 
       std::vector<std::string> depends;
@@ -114,7 +124,8 @@ cmExportTryCompileFileGenerator::PopulateProperties(cmTarget const* target,
       for(std::vector<std::string>::const_iterator li = depends.begin();
           li != depends.end(); ++li)
         {
-        cmTarget *tgt = target->GetMakefile()->FindTargetToUse(*li);
+        cmGeneratorTarget *tgt =
+            target->GetLocalGenerator()->FindGeneratorTargetToUse(*li);
         if(tgt && emitted.insert(tgt).second)
           {
           this->Exports.push_back(tgt);
diff --git a/Source/cmExportTryCompileFileGenerator.h b/Source/cmExportTryCompileFileGenerator.h
index 8838eca..fc135a4 100644
--- a/Source/cmExportTryCompileFileGenerator.h
+++ b/Source/cmExportTryCompileFileGenerator.h
@@ -20,11 +20,11 @@ class cmInstallTargetGenerator;
 class cmExportTryCompileFileGenerator: public cmExportFileGenerator
 {
 public:
-  cmExportTryCompileFileGenerator(cmGlobalGenerator* gg);
+  cmExportTryCompileFileGenerator(cmGlobalGenerator* gg,
+                                  std::vector<std::string> const& targets,
+                                  cmMakefile* mf);
 
   /** Set the list of targets to export.  */
-  void SetExports(const std::vector<cmTarget const*> &exports)
-    { this->Exports = exports; }
   void SetConfig(const std::string& config) { this->Config = config; }
 protected:
 
@@ -37,22 +37,22 @@ protected:
                             std::vector<std::string>&) {}
   virtual void HandleMissingTarget(std::string&,
                                    std::vector<std::string>&,
-                                   cmMakefile*,
-                                   cmTarget*,
-                                   cmTarget*) {}
+                                   cmGeneratorTarget*,
+                                   cmGeneratorTarget*) {}
 
-  void PopulateProperties(cmTarget const* target,
+  void PopulateProperties(cmGeneratorTarget const* target,
                           ImportPropertyMap& properties,
-                          std::set<cmTarget const*> &emitted);
+                          std::set<const cmGeneratorTarget*>& emitted);
 
   std::string InstallNameDir(cmGeneratorTarget* target,
                              const std::string& config);
 private:
-  std::string FindTargets(const std::string& prop, cmTarget const* tgt,
-                   std::set<cmTarget const*> &emitted);
+  std::string FindTargets(const std::string& prop,
+                          const cmGeneratorTarget* tgt,
+                          std::set<const cmGeneratorTarget*>& emitted);
 
 
-  std::vector<cmTarget const*> Exports;
+  std::vector<cmGeneratorTarget const*> Exports;
   std::string Config;
 };
 
diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx
index dfd51c7..9348ef2 100644
--- a/Source/cmExtraCodeBlocksGenerator.cxx
+++ b/Source/cmExtraCodeBlocksGenerator.cxx
@@ -17,7 +17,6 @@
 #include "cmake.h"
 #include "cmSourceFile.h"
 #include "cmGeneratedFileStream.h"
-#include "cmTarget.h"
 #include "cmSystemTools.h"
 #include "cmXMLSafe.h"
 
@@ -76,9 +75,8 @@ void cmExtraCodeBlocksGenerator::Generate()
 void cmExtraCodeBlocksGenerator::CreateProjectFile(
                                      const std::vector<cmLocalGenerator*>& lgs)
 {
-  const cmMakefile* mf=lgs[0]->GetMakefile();
-  std::string outputDir=mf->GetCurrentBinaryDirectory();
-  std::string projectName=mf->GetProjectName();
+  std::string outputDir=lgs[0]->GetCurrentBinaryDirectory();
+  std::string projectName=lgs[0]->GetProjectName();
 
   std::string filename=outputDir+"/";
   filename+=projectName+".cbp";
@@ -273,7 +271,7 @@ void cmExtraCodeBlocksGenerator
         }
 
       const std::string &relative = cmSystemTools::RelativePath(
-                         it->second[0]->GetMakefile()->GetHomeDirectory(),
+                         it->second[0]->GetSourceDirectory(),
                          jt->c_str());
       std::vector<std::string> splitted;
       cmSystemTools::SplitPath(relative, splitted, false);
@@ -297,7 +295,7 @@ void cmExtraCodeBlocksGenerator
   tree.BuildVirtualFolder(virtualFolders);
   // And one for <Unit>
   std::string unitFiles;
-  tree.BuildUnit(unitFiles, std::string(mf->GetHomeDirectory()) + "/");
+  tree.BuildUnit(unitFiles, std::string(lgs[0]->GetSourceDirectory()) + "/");
 
   // figure out the compiler
   std::string compiler = this->GetCBCompilerId(mf);
@@ -307,7 +305,7 @@ void cmExtraCodeBlocksGenerator
         "<CodeBlocks_project_file>\n"
         "   <FileVersion major=\"1\" minor=\"6\" />\n"
         "   <Project>\n"
-        "      <Option title=\"" << mf->GetProjectName()<<"\" />\n"
+        "      <Option title=\"" << lgs[0]->GetProjectName()<<"\" />\n"
         "      <Option makefile_is_custom=\"1\" />\n"
         "      <Option compiler=\"" << compiler << "\" />\n"
         "      "<<virtualFolders<<"\n"
@@ -320,50 +318,52 @@ void cmExtraCodeBlocksGenerator
   for (std::vector<cmLocalGenerator*>::const_iterator lg=lgs.begin();
        lg!=lgs.end(); lg++)
     {
-    cmMakefile* makefile=(*lg)->GetMakefile();
-    cmTargets& targets=makefile->GetTargets();
-    for (cmTargets::iterator ti = targets.begin();
+    std::vector<cmGeneratorTarget*> targets=(*lg)->GetGeneratorTargets();
+    for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
          ti != targets.end(); ti++)
       {
-      switch(ti->second.GetType())
+      std::string targetName = (*ti)->GetName();
+      switch((*ti)->GetType())
         {
-        case cmTarget::GLOBAL_TARGET:
+        case cmState::GLOBAL_TARGET:
           {
           // Only add the global targets from CMAKE_BINARY_DIR,
           // not from the subdirs
-          if (strcmp(makefile->GetCurrentBinaryDirectory(),
-                     makefile->GetHomeOutputDirectory())==0)
+          if (strcmp((*lg)->GetCurrentBinaryDirectory(),
+                     (*lg)->GetBinaryDirectory())==0)
             {
-            this->AppendTarget(fout, ti->first, 0,
+            this->AppendTarget(fout, targetName, 0,
                                make.c_str(), *lg, compiler.c_str());
             }
           }
           break;
-        case cmTarget::UTILITY:
+        case cmState::UTILITY:
           // Add all utility targets, except the Nightly/Continuous/
           // Experimental-"sub"targets as e.g. NightlyStart
-          if (((ti->first.find("Nightly")==0)   &&(ti->first!="Nightly"))
-             || ((ti->first.find("Continuous")==0)&&(ti->first!="Continuous"))
-             || ((ti->first.find("Experimental")==0)
-                                               && (ti->first!="Experimental")))
+          if (((targetName.find("Nightly")==0)   &&(targetName!="Nightly"))
+             || ((targetName.find("Continuous")==0)
+                 &&(targetName!="Continuous"))
+             || ((targetName.find("Experimental")==0)
+                                             && (targetName!="Experimental")))
             {
             break;
             }
 
-          this->AppendTarget(fout, ti->first, 0,
+          this->AppendTarget(fout, targetName, 0,
                                  make.c_str(), *lg, compiler.c_str());
           break;
-        case cmTarget::EXECUTABLE:
-        case cmTarget::STATIC_LIBRARY:
-        case cmTarget::SHARED_LIBRARY:
-        case cmTarget::MODULE_LIBRARY:
-        case cmTarget::OBJECT_LIBRARY:
+        case cmState::EXECUTABLE:
+        case cmState::STATIC_LIBRARY:
+        case cmState::SHARED_LIBRARY:
+        case cmState::MODULE_LIBRARY:
+        case cmState::OBJECT_LIBRARY:
           {
-          this->AppendTarget(fout, ti->first, &ti->second,
+          cmGeneratorTarget* gt = *ti;
+          this->AppendTarget(fout, targetName, gt,
                              make.c_str(), *lg, compiler.c_str());
-          std::string fastTarget = ti->first;
+          std::string fastTarget = targetName;
           fastTarget += "/fast";
-          this->AppendTarget(fout, fastTarget, &ti->second,
+          this->AppendTarget(fout, fastTarget, gt,
                              make.c_str(), *lg, compiler.c_str());
           }
           break;
@@ -383,25 +383,29 @@ void cmExtraCodeBlocksGenerator
   all_files_map_t allFiles;
   std::vector<std::string> cFiles;
 
+  std::vector<std::string> srcExts =
+      this->GlobalGenerator->GetCMakeInstance()->GetSourceExtensions();
+
   for (std::vector<cmLocalGenerator*>::const_iterator lg=lgs.begin();
        lg!=lgs.end(); lg++)
     {
     cmMakefile* makefile=(*lg)->GetMakefile();
-    cmTargets& targets=makefile->GetTargets();
-    for (cmTargets::iterator ti = targets.begin();
+    std::vector<cmGeneratorTarget*> targets=(*lg)->GetGeneratorTargets();
+    for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
          ti != targets.end(); ti++)
       {
-      switch(ti->second.GetType())
+      switch((*ti)->GetType())
         {
-        case cmTarget::EXECUTABLE:
-        case cmTarget::STATIC_LIBRARY:
-        case cmTarget::SHARED_LIBRARY:
-        case cmTarget::MODULE_LIBRARY:
-        case cmTarget::OBJECT_LIBRARY:
-        case cmTarget::UTILITY: // can have sources since 2.6.3
+        case cmState::EXECUTABLE:
+        case cmState::STATIC_LIBRARY:
+        case cmState::SHARED_LIBRARY:
+        case cmState::MODULE_LIBRARY:
+        case cmState::OBJECT_LIBRARY:
+        case cmState::UTILITY: // can have sources since 2.6.3
           {
           std::vector<cmSourceFile*> sources;
-          ti->second.GetSourceFiles(sources,
+          cmGeneratorTarget* gt = *ti;
+          gt->GetSourceFiles(sources,
                             makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
           for (std::vector<cmSourceFile*>::const_iterator si=sources.begin();
                si!=sources.end(); si++)
@@ -419,9 +423,7 @@ void cmExtraCodeBlocksGenerator
               {
               std::string srcext = (*si)->GetExtension();
               for(std::vector<std::string>::const_iterator
-                  ext = mf->GetSourceExtensions().begin();
-                  ext !=  mf->GetSourceExtensions().end();
-                  ++ext)
+                  ext = srcExts.begin(); ext != srcExts.end(); ++ext)
                 {
                 if (srcext == *ext)
                   {
@@ -439,7 +441,7 @@ void cmExtraCodeBlocksGenerator
               }
 
             CbpUnit &cbpUnit = allFiles[fullPath];
-            cbpUnit.Targets.push_back(&(ti->second));
+            cbpUnit.Targets.push_back(*ti);
             }
           }
         default:  // intended fallthrough
@@ -448,6 +450,9 @@ void cmExtraCodeBlocksGenerator
       }
     }
 
+  std::vector<std::string> headerExts =
+      this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions();
+
   // The following loop tries to add header files matching to implementation
   // files to the project. It does that by iterating over all
   // C/C++ source files,
@@ -467,8 +472,8 @@ void cmExtraCodeBlocksGenerator
 
     // check if there's a matching header around
     for(std::vector<std::string>::const_iterator
-        ext = mf->GetHeaderExtensions().begin();
-        ext !=  mf->GetHeaderExtensions().end();
+        ext = headerExts.begin();
+        ext != headerExts.end();
         ++ext)
       {
       std::string hname=headerBasename;
@@ -499,8 +504,9 @@ void cmExtraCodeBlocksGenerator
 
     fout<<"      <Unit filename=\""<< cmXMLSafe(unitFilename) <<"\">\n";
 
-    for(std::vector<const cmTarget*>::const_iterator ti = unit.Targets.begin();
-      ti != unit.Targets.end(); ++ti)
+    for(std::vector<const cmGeneratorTarget*>::const_iterator ti =
+        unit.Targets.begin();
+        ti != unit.Targets.end(); ++ti)
       {
       std::string const& targetName = (*ti)->GetName();
       fout<<"         <Option target=\""<< cmXMLSafe(targetName) <<"\"/>\n";
@@ -520,15 +526,14 @@ void cmExtraCodeBlocksGenerator
 // Write a dummy file for OBJECT libraries, so C::B can reference some file
 std::string cmExtraCodeBlocksGenerator::CreateDummyTargetFile(
                                         cmLocalGenerator* lg,
-                                        cmTarget* target) const
+                                        cmGeneratorTarget* target) const
 {
-  cmMakefile *mf = lg->GetMakefile();
   // this file doesn't seem to be used by C::B in custom makefile mode,
   // but we generate a unique file for each OBJECT library so in case
   // C::B uses it in some way, the targets don't interfere with each other.
-  std::string filename = mf->GetCurrentBinaryDirectory();
+  std::string filename = lg->GetCurrentBinaryDirectory();
   filename += "/";
-  filename += lg->GetTargetDirectory(*target);
+  filename += lg->GetTargetDirectory(target);
   filename += "/";
   filename += target->GetName();
   filename += ".objlib";
@@ -547,21 +552,21 @@ std::string cmExtraCodeBlocksGenerator::CreateDummyTargetFile(
 // Generate the xml code for one target.
 void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
                                               const std::string& targetName,
-                                              cmTarget* target,
+                                              cmGeneratorTarget* target,
                                               const char* make,
                                               const cmLocalGenerator* lg,
                                               const char* compiler)
 {
   cmMakefile const* makefile = lg->GetMakefile();
-  std::string makefileName = makefile->GetCurrentBinaryDirectory();
+  std::string makefileName = lg->GetCurrentBinaryDirectory();
   makefileName += "/Makefile";
 
   fout<<"      <Target title=\"" << targetName << "\">\n";
   if (target!=0)
     {
     int cbTargetType = this->GetCBTargetType(target);
-    std::string workingDir = makefile->GetCurrentBinaryDirectory();
-    if ( target->GetType()==cmTarget::EXECUTABLE)
+    std::string workingDir = lg->GetCurrentBinaryDirectory();
+    if ( target->GetType()==cmState::EXECUTABLE)
       {
       // Determine the directory where the executable target is created, and
       // set the working directory to this dir.
@@ -584,16 +589,14 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
 
     std::string buildType = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
     std::string location;
-    if ( target->GetType()==cmTarget::OBJECT_LIBRARY)
+    if ( target->GetType()==cmState::OBJECT_LIBRARY)
       {
       location = this->CreateDummyTargetFile(const_cast<cmLocalGenerator*>(lg),
                                              target);
       }
     else
       {
-      cmGeneratorTarget* gt =
-          this->GlobalGenerator->GetGeneratorTarget(target);
-      location = gt->GetLocation(buildType);
+      location = target->GetLocation(buildType);
       }
 
     fout<<"         <Option output=\"" << location
@@ -604,12 +607,9 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
           "         <Option compiler=\"" << compiler << "\" />\n"
           "         <Compiler>\n";
 
-    cmGeneratorTarget *gtgt = this->GlobalGenerator
-                                  ->GetGeneratorTarget(target);
-
     // the compilerdefines for this target
     std::vector<std::string> cdefs;
-    gtgt->GetCompileDefinitions(cdefs, buildType, "C");
+    target->GetCompileDefinitions(cdefs, buildType, "C");
 
     // Expand the list.
     for(std::vector<std::string>::const_iterator di = cdefs.begin();
@@ -623,7 +623,7 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
     std::set<std::string> uniqIncludeDirs;
 
     std::vector<std::string> includes;
-    lg->GetIncludeDirectories(includes, gtgt, "C", buildType);
+    lg->GetIncludeDirectories(includes, target, "C", buildType);
 
     uniqIncludeDirs.insert(includes.begin(), includes.end());
 
@@ -657,7 +657,7 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
   else // e.g. all and the GLOBAL and UTILITY targets
     {
     fout<<"         <Option working_dir=\""
-        << makefile->GetCurrentBinaryDirectory() << "\" />\n"
+        << lg->GetCurrentBinaryDirectory() << "\" />\n"
         <<"         <Option type=\"" << 4 << "\" />\n";
     }
 
@@ -691,8 +691,6 @@ std::string cmExtraCodeBlocksGenerator::GetCBCompilerId(const cmMakefile* mf)
     compilerIdVar = "CMAKE_C_COMPILER_ID";
     }
 
-  std::string hostSystemName = mf->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME");
-  std::string systemName = mf->GetSafeDefinition("CMAKE_SYSTEM_NAME");
   std::string compilerId = mf->GetSafeDefinition(compilerIdVar);
   std::string compiler = "gcc";  // default to gcc
   if (compilerId == "MSVC")
@@ -724,9 +722,9 @@ std::string cmExtraCodeBlocksGenerator::GetCBCompilerId(const cmMakefile* mf)
 
 
 // Translate the cmake target type into the CodeBlocks target type id
-int cmExtraCodeBlocksGenerator::GetCBTargetType(cmTarget* target)
+int cmExtraCodeBlocksGenerator::GetCBTargetType(cmGeneratorTarget* target)
 {
-  if ( target->GetType()==cmTarget::EXECUTABLE)
+  if ( target->GetType()==cmState::EXECUTABLE)
     {
     if ((target->GetPropertyAsBool("WIN32_EXECUTABLE"))
         || (target->GetPropertyAsBool("MACOSX_BUNDLE")))
@@ -738,13 +736,13 @@ int cmExtraCodeBlocksGenerator::GetCBTargetType(cmTarget* target)
       return 1;
       }
     }
-  else if (( target->GetType()==cmTarget::STATIC_LIBRARY)
-        || (target->GetType()==cmTarget::OBJECT_LIBRARY))
+  else if (( target->GetType()==cmState::STATIC_LIBRARY)
+        || (target->GetType()==cmState::OBJECT_LIBRARY))
     {
     return 2;
     }
-  else if ((target->GetType()==cmTarget::SHARED_LIBRARY)
-           || (target->GetType()==cmTarget::MODULE_LIBRARY))
+  else if ((target->GetType()==cmState::SHARED_LIBRARY)
+           || (target->GetType()==cmState::MODULE_LIBRARY))
     {
     return 3;
     }
diff --git a/Source/cmExtraCodeBlocksGenerator.h b/Source/cmExtraCodeBlocksGenerator.h
index e5ede9a..0c3846d 100644
--- a/Source/cmExtraCodeBlocksGenerator.h
+++ b/Source/cmExtraCodeBlocksGenerator.h
@@ -17,7 +17,7 @@
 
 class cmLocalGenerator;
 class cmMakefile;
-class cmTarget;
+class cmGeneratorTarget;
 class cmGeneratedFileStream;
 
 /** \class cmExtraCodeBlocksGenerator
@@ -41,7 +41,7 @@ public:
 private:
   struct CbpUnit
   {
-    std::vector<const cmTarget*> Targets;
+    std::vector<const cmGeneratorTarget*> Targets;
   };
 
   void CreateProjectFile(const std::vector<cmLocalGenerator*>& lgs);
@@ -49,15 +49,15 @@ private:
   void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
                                 const std::string& filename);
   std::string CreateDummyTargetFile(cmLocalGenerator* lg,
-                                    cmTarget* target) const;
+                                    cmGeneratorTarget* target) const;
 
   std::string GetCBCompilerId(const cmMakefile* mf);
-  int GetCBTargetType(cmTarget* target);
+  int GetCBTargetType(cmGeneratorTarget* target);
   std::string BuildMakeCommand(const std::string& make, const char* makefile,
                                const std::string& target);
   void AppendTarget(cmGeneratedFileStream& fout,
                     const std::string& targetName,
-                    cmTarget* target,
+                    cmGeneratorTarget* target,
                     const char* make,
                     const cmLocalGenerator* lg,
                     const char* compiler);
diff --git a/Source/cmExtraCodeLiteGenerator.cxx b/Source/cmExtraCodeLiteGenerator.cxx
index c2cff14..67aa157 100644
--- a/Source/cmExtraCodeLiteGenerator.cxx
+++ b/Source/cmExtraCodeLiteGenerator.cxx
@@ -68,15 +68,15 @@ void cmExtraCodeLiteGenerator::Generate()
     const cmMakefile* mf =it->second[0]->GetMakefile();
     this->ConfigName = GetConfigurationName( mf );
 
-    if (strcmp(mf->GetCurrentBinaryDirectory(),
-               mf->GetHomeOutputDirectory()) == 0)
+    if (strcmp(it->second[0]->GetCurrentBinaryDirectory(),
+               it->second[0]->GetBinaryDirectory()) == 0)
       {
-      workspaceOutputDir   = mf->GetCurrentBinaryDirectory();
-      workspaceProjectName = mf->GetProjectName();
-      workspaceSourcePath  = mf->GetHomeDirectory();
+      workspaceOutputDir   = it->second[0]->GetCurrentBinaryDirectory();
+      workspaceProjectName = it->second[0]->GetProjectName();
+      workspaceSourcePath  = it->second[0]->GetSourceDirectory();
       workspaceFileName    = workspaceOutputDir+"/";
       workspaceFileName   += workspaceProjectName + ".workspace";
-      this->WorkspacePath = mf->GetCurrentBinaryDirectory();;
+      this->WorkspacePath = it->second[0]->GetCurrentBinaryDirectory();;
 
       fout.Open(workspaceFileName.c_str(), false, false);
       fout << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
@@ -91,9 +91,8 @@ void cmExtraCodeLiteGenerator::Generate()
        ++it)
     {
     // retrive project information
-    const cmMakefile* mf    = it->second[0]->GetMakefile();
-    std::string outputDir   = mf->GetCurrentBinaryDirectory();
-    std::string projectName = mf->GetProjectName();
+    std::string outputDir   = it->second[0]->GetCurrentBinaryDirectory();
+    std::string projectName = it->second[0]->GetProjectName();
     std::string filename    = outputDir + "/" + projectName + ".project";
 
     // Make the project file relative to the workspace
@@ -121,9 +120,8 @@ void cmExtraCodeLiteGenerator::Generate()
 void cmExtraCodeLiteGenerator::CreateProjectFile(
   const std::vector<cmLocalGenerator*>& lgs)
 {
-  const cmMakefile* mf    = lgs[0]->GetMakefile();
-  std::string outputDir   = mf->GetCurrentBinaryDirectory();
-  std::string projectName = mf->GetProjectName();
+  std::string outputDir   = lgs[0]->GetCurrentBinaryDirectory();
+  std::string projectName = lgs[0]->GetProjectName();
   std::string filename    = outputDir + "/";
 
   filename += projectName + ".project";
@@ -143,7 +141,7 @@ void cmExtraCodeLiteGenerator
 
   ////////////////////////////////////
   fout << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
-       "<CodeLite_Project Name=\"" << mf->GetProjectName()
+       "<CodeLite_Project Name=\"" << lgs[0]->GetProjectName()
        << "\" InternalType=\"\">\n";
 
   // Collect all used source files in the project
@@ -151,35 +149,40 @@ void cmExtraCodeLiteGenerator
   // which may have an acompanying header, one for all other files
   std::string projectType;
 
+  std::vector<std::string> srcExts =
+      this->GlobalGenerator->GetCMakeInstance()->GetSourceExtensions();
+  std::vector<std::string> headerExts =
+      this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions();
+
   std::map<std::string, cmSourceFile*> cFiles;
   std::set<std::string> otherFiles;
   for (std::vector<cmLocalGenerator*>::const_iterator lg=lgs.begin();
        lg!=lgs.end(); lg++)
     {
     cmMakefile* makefile=(*lg)->GetMakefile();
-    cmTargets& targets=makefile->GetTargets();
-    for (cmTargets::iterator ti = targets.begin();
+    std::vector<cmGeneratorTarget*> targets=(*lg)->GetGeneratorTargets();
+    for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
          ti != targets.end(); ti++)
       {
 
-      switch(ti->second.GetType())
+      switch((*ti)->GetType())
         {
-        case cmTarget::EXECUTABLE:
+        case cmState::EXECUTABLE:
           {
           projectType = "Executable";
           }
         break;
-        case cmTarget::STATIC_LIBRARY:
+        case cmState::STATIC_LIBRARY:
           {
           projectType = "Static Library";
           }
         break;
-        case cmTarget::SHARED_LIBRARY:
+        case cmState::SHARED_LIBRARY:
           {
           projectType = "Dynamic Library";
           }
         break;
-        case cmTarget::MODULE_LIBRARY:
+        case cmState::MODULE_LIBRARY:
           {
           projectType = "Dynamic Library";
           }
@@ -188,15 +191,16 @@ void cmExtraCodeLiteGenerator
           break;
         }
 
-      switch(ti->second.GetType())
+      switch((*ti)->GetType())
         {
-        case cmTarget::EXECUTABLE:
-        case cmTarget::STATIC_LIBRARY:
-        case cmTarget::SHARED_LIBRARY:
-        case cmTarget::MODULE_LIBRARY:
+        case cmState::EXECUTABLE:
+        case cmState::STATIC_LIBRARY:
+        case cmState::SHARED_LIBRARY:
+        case cmState::MODULE_LIBRARY:
           {
           std::vector<cmSourceFile*> sources;
-          ti->second.GetSourceFiles(sources,
+          cmGeneratorTarget* gt = *ti;
+          gt->GetSourceFiles(sources,
                             makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
           for (std::vector<cmSourceFile*>::const_iterator si=sources.begin();
                si!=sources.end(); si++)
@@ -208,9 +212,7 @@ void cmExtraCodeLiteGenerator
               {
               std::string srcext = (*si)->GetExtension();
               for(std::vector<std::string>::const_iterator
-                  ext = mf->GetSourceExtensions().begin();
-                  ext !=  mf->GetSourceExtensions().end();
-                  ++ext)
+                  ext = srcExts.begin(); ext != srcExts.end(); ++ext)
                 {
                 if (srcext == *ext)
                   {
@@ -254,8 +256,8 @@ void cmExtraCodeLiteGenerator
 
     // check if there's a matching header around
     for(std::vector<std::string>::const_iterator
-        ext = mf->GetHeaderExtensions().begin();
-        ext !=  mf->GetHeaderExtensions().end();
+        ext = headerExts.begin();
+        ext != headerExts.end();
         ++ext)
       {
       std::string hname=headerBasename;
diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx
index 44bf586..aedf6f4 100644
--- a/Source/cmExtraEclipseCDT4Generator.cxx
+++ b/Source/cmExtraEclipseCDT4Generator.cxx
@@ -79,8 +79,8 @@ void cmExtraEclipseCDT4Generator
 //----------------------------------------------------------------------------
 void cmExtraEclipseCDT4Generator::Generate()
 {
-  const cmMakefile* mf
-    = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
+  cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
+  const cmMakefile* mf = lg->GetMakefile();
 
   std::string eclipseVersion = mf->GetSafeDefinition("CMAKE_ECLIPSE_VERSION");
   cmsys::RegularExpression regex(".*([0-9]+\\.[0-9]+).*");
@@ -106,8 +106,8 @@ void cmExtraEclipseCDT4Generator::Generate()
     }
 
   // TODO: Decide if these are local or member variables
-  this->HomeDirectory       = mf->GetHomeDirectory();
-  this->HomeOutputDirectory = mf->GetHomeOutputDirectory();
+  this->HomeDirectory       = lg->GetSourceDirectory();
+  this->HomeOutputDirectory = lg->GetBinaryDirectory();
 
   this->GenerateLinkedResources = mf->IsOn(
                                     "CMAKE_ECLIPSE_GENERATE_LINKED_RESOURCES");
@@ -157,9 +157,8 @@ void cmExtraEclipseCDT4Generator::CreateSourceProjectFile()
   assert(this->HomeDirectory != this->HomeOutputDirectory);
 
   // set up the project name: <project>-Source@<baseSourcePathName>
-  const cmMakefile* mf
-     = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
-  std::string name = this->GenerateProjectName(mf->GetProjectName(), "Source",
+  cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
+  std::string name = this->GenerateProjectName(lg->GetProjectName(), "Source",
                                    this->GetPathBasename(this->HomeDirectory));
 
   const std::string filename = this->HomeDirectory + "/.project";
@@ -197,8 +196,11 @@ void cmExtraEclipseCDT4Generator::CreateSourceProjectFile()
 
 //----------------------------------------------------------------------------
 void cmExtraEclipseCDT4Generator::AddEnvVar(cmGeneratedFileStream& fout,
-                                            const char* envVar, cmMakefile* mf)
+                                            const char* envVar,
+                                            cmLocalGenerator* lg)
 {
+  cmMakefile* mf = lg->GetMakefile();
+
   // get the variables from the environment and from the cache and then
   // figure out which one to use:
 
@@ -206,7 +208,7 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(cmGeneratedFileStream& fout,
 
   std::string cacheEntryName = "CMAKE_ECLIPSE_ENVVAR_";
   cacheEntryName += envVar;
-  const char* cacheValue = mf->GetState()->GetInitializedCacheValue(
+  const char* cacheValue = lg->GetState()->GetInitializedCacheValue(
                                                        cacheEntryName);
 
   // now we have both, decide which one to use
@@ -224,7 +226,7 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(cmGeneratedFileStream& fout,
     mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(),
                            cacheEntryName.c_str(), cmState::STRING,
                            true);
-    mf->GetCMakeInstance()->SaveCache(mf->GetHomeOutputDirectory());
+    mf->GetCMakeInstance()->SaveCache(lg->GetBinaryDirectory());
     }
   else if (envVarValue==0 && cacheValue!=0)
     {
@@ -245,7 +247,7 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(cmGeneratedFileStream& fout,
       mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(),
                              cacheEntryName.c_str(), cmState::STRING,
                              true);
-      mf->GetCMakeInstance()->SaveCache(mf->GetHomeOutputDirectory());
+      mf->GetCMakeInstance()->SaveCache(lg->GetBinaryDirectory());
       }
     }
 
@@ -259,8 +261,8 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(cmGeneratedFileStream& fout,
 //----------------------------------------------------------------------------
 void cmExtraEclipseCDT4Generator::CreateProjectFile()
 {
-  cmMakefile* mf
-    = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
+  cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
+  cmMakefile* mf = lg->GetMakefile();
 
   const std::string filename = this->HomeOutputDirectory + "/.project";
 
@@ -280,7 +282,7 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile()
     "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
     "<projectDescription>\n"
     "\t<name>" <<
-    this->GenerateProjectName(mf->GetProjectName(),
+    this->GenerateProjectName(lg->GetProjectName(),
                               mf->GetSafeDefinition("CMAKE_BUILD_TYPE"),
                               this->GetPathBasename(this->HomeOutputDirectory))
     << "</name>\n"
@@ -361,17 +363,17 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile()
   //   but not necessarily when eclipse is open
   if (compilerId == "MSVC")
     {
-    AddEnvVar(fout, "PATH", mf);
-    AddEnvVar(fout, "INCLUDE", mf);
-    AddEnvVar(fout, "LIB", mf);
-    AddEnvVar(fout, "LIBPATH", mf);
+    AddEnvVar(fout, "PATH", lg);
+    AddEnvVar(fout, "INCLUDE", lg);
+    AddEnvVar(fout, "LIB", lg);
+    AddEnvVar(fout, "LIBPATH", lg);
     }
   else if (compilerId == "Intel")
     {
     // if the env.var is set, use this one and put it in the cache
     // if the env.var is not set, but the value is in the cache,
     // use it from the cache:
-    AddEnvVar(fout, "INTEL_LICENSE_FILE", mf);
+    AddEnvVar(fout, "INTEL_LICENSE_FILE", lg);
     }
   fout <<
     "</value>\n"
@@ -495,7 +497,7 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile()
 
     std::string sourceLinkedResourceName = "[Source directory]";
     std::string linkSourceDirectory = this->GetEclipsePath(
-                                             mf->GetCurrentSourceDirectory());
+                                             lg->GetCurrentSourceDirectory());
     // .project dir can't be subdir of a linked resource dir
     if (!cmSystemTools::IsSubDirectory(this->HomeOutputDirectory,
                                          linkSourceDirectory))
@@ -534,24 +536,26 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(
        ++lgIt)
     {
     cmMakefile* makefile = (*lgIt)->GetMakefile();
-    const cmTargets& targets = makefile->GetTargets();
+    const std::vector<cmGeneratorTarget*> targets =
+        (*lgIt)->GetGeneratorTargets();
 
-    for(cmTargets::const_iterator ti=targets.begin(); ti!=targets.end();++ti)
+    for(std::vector<cmGeneratorTarget*>::const_iterator ti=targets.begin();
+        ti!=targets.end();++ti)
       {
       std::string linkName2 = linkName;
       linkName2 += "/";
-      switch(ti->second.GetType())
+      switch((*ti)->GetType())
         {
-        case cmTarget::EXECUTABLE:
-        case cmTarget::STATIC_LIBRARY:
-        case cmTarget::SHARED_LIBRARY:
-        case cmTarget::MODULE_LIBRARY:
-        case cmTarget::OBJECT_LIBRARY:
+        case cmState::EXECUTABLE:
+        case cmState::STATIC_LIBRARY:
+        case cmState::SHARED_LIBRARY:
+        case cmState::MODULE_LIBRARY:
+        case cmState::OBJECT_LIBRARY:
           {
-          const char* prefix = (ti->second.GetType()==cmTarget::EXECUTABLE ?
+          const char* prefix = ((*ti)->GetType()==cmState::EXECUTABLE ?
                                                           "[exe] " : "[lib] ");
           linkName2 += prefix;
-          linkName2 += ti->first;
+          linkName2 += (*ti)->GetName();
           this->AppendLinkedResource(fout, linkName2, "virtual:/virtual",
                                      VirtualFolder);
           if (!this->GenerateLinkedResources)
@@ -560,9 +564,9 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(
             }
           std::vector<cmSourceGroup> sourceGroups=makefile->GetSourceGroups();
           // get the files from the source lists then add them to the groups
-          cmTarget* tgt = const_cast<cmTarget*>(&ti->second);
+          cmGeneratorTarget* gt = const_cast<cmGeneratorTarget*>(*ti);
           std::vector<cmSourceFile*> files;
-          tgt->GetSourceFiles(files,
+          gt->GetSourceFiles(files,
                             makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
           for(std::vector<cmSourceFile*>::const_iterator sfIt = files.begin();
               sfIt != files.end();
@@ -634,7 +638,7 @@ void cmExtraEclipseCDT4Generator::CreateLinksToSubprojects(
        ++it)
     {
     std::string linkSourceDirectory = this->GetEclipsePath(
-                   it->second[0]->GetMakefile()->GetCurrentSourceDirectory());
+                   it->second[0]->GetCurrentSourceDirectory());
     // a linked resource must not point to a parent directory of .project or
     // .project itself
     if ((baseDir != linkSourceDirectory) &&
@@ -694,8 +698,8 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
 {
   std::set<std::string> emmited;
 
-  const cmMakefile* mf
-    = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
+  cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
+  const cmMakefile* mf = lg->GetMakefile();
 
   const std::string filename = this->HomeOutputDirectory + "/.cproject";
 
@@ -961,18 +965,13 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
        it != this->GlobalGenerator->GetLocalGenerators().end();
        ++it)
     {
-    cmGeneratorTargetsType targets = (*it)->GetMakefile()
-                                        ->GetGeneratorTargets();
-    for (cmGeneratorTargetsType::iterator l = targets.begin();
+    std::vector<cmGeneratorTarget*> targets = (*it)->GetGeneratorTargets();
+    for (std::vector<cmGeneratorTarget*>::iterator l = targets.begin();
          l != targets.end(); ++l)
       {
-      if (l->first->IsImported())
-        {
-        continue;
-        }
       std::vector<std::string> includeDirs;
       std::string config = mf->GetSafeDefinition("CMAKE_BUILD_TYPE");
-      (*it)->GetIncludeDirectories(includeDirs, l->second, "C", config);
+      (*it)->GetIncludeDirectories(includeDirs, *l, "C", config);
       this->AppendIncludeDirectories(fout, includeDirs, emmited);
       }
     }
@@ -1031,52 +1030,54 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
        it != this->GlobalGenerator->GetLocalGenerators().end();
        ++it)
     {
-    const cmTargets& targets = (*it)->GetMakefile()->GetTargets();
-    cmMakefile* makefile=(*it)->GetMakefile();
-    std::string subdir = (*it)->Convert(makefile->GetCurrentBinaryDirectory(),
+    const std::vector<cmGeneratorTarget*> targets =
+        (*it)->GetGeneratorTargets();
+    std::string subdir = (*it)->Convert((*it)->GetCurrentBinaryDirectory(),
                            cmLocalGenerator::HOME_OUTPUT);
     if (subdir == ".")
       {
       subdir = "";
       }
 
-    for(cmTargets::const_iterator ti=targets.begin(); ti!=targets.end(); ++ti)
+    for(std::vector<cmGeneratorTarget*>::const_iterator ti =
+        targets.begin(); ti!=targets.end(); ++ti)
       {
-      switch(ti->second.GetType())
+      std::string targetName = (*ti)->GetName();
+      switch((*ti)->GetType())
         {
-        case cmTarget::GLOBAL_TARGET:
+        case cmState::GLOBAL_TARGET:
           {
           // Only add the global targets from CMAKE_BINARY_DIR,
           // not from the subdirs
           if (subdir.empty())
            {
-           this->AppendTarget(fout, ti->first, make, makeArgs, subdir, ": ");
+           this->AppendTarget(fout, targetName, make, makeArgs, subdir, ": ");
            }
          }
          break;
-       case cmTarget::UTILITY:
+       case cmState::UTILITY:
          // Add all utility targets, except the Nightly/Continuous/
          // Experimental-"sub"targets as e.g. NightlyStart
-         if (((ti->first.find("Nightly")==0)   &&(ti->first!="Nightly"))
-          || ((ti->first.find("Continuous")==0)&&(ti->first!="Continuous"))
-          || ((ti->first.find("Experimental")==0)
-                                            && (ti->first!="Experimental")))
+         if (((targetName.find("Nightly")==0)   &&(targetName!="Nightly"))
+          || ((targetName.find("Continuous")==0)&&(targetName!="Continuous"))
+          || ((targetName.find("Experimental")==0)
+                                            && (targetName!="Experimental")))
            {
            break;
            }
 
-         this->AppendTarget(fout, ti->first, make, makeArgs, subdir, ": ");
+         this->AppendTarget(fout, targetName, make, makeArgs, subdir, ": ");
          break;
-       case cmTarget::EXECUTABLE:
-       case cmTarget::STATIC_LIBRARY:
-       case cmTarget::SHARED_LIBRARY:
-       case cmTarget::MODULE_LIBRARY:
-       case cmTarget::OBJECT_LIBRARY:
+       case cmState::EXECUTABLE:
+       case cmState::STATIC_LIBRARY:
+       case cmState::SHARED_LIBRARY:
+       case cmState::MODULE_LIBRARY:
+       case cmState::OBJECT_LIBRARY:
          {
-         const char* prefix = (ti->second.GetType()==cmTarget::EXECUTABLE ?
+         const char* prefix = ((*ti)->GetType()==cmState::EXECUTABLE ?
                                                           "[exe] " : "[lib] ");
-         this->AppendTarget(fout, ti->first, make, makeArgs, subdir, prefix);
-         std::string fastTarget = ti->first;
+         this->AppendTarget(fout, targetName, make, makeArgs, subdir, prefix);
+         std::string fastTarget = targetName;
          fastTarget += "/fast";
          this->AppendTarget(fout, fastTarget, make, makeArgs, subdir, prefix);
 
@@ -1085,20 +1086,21 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
           {
           std::string virtDir = "[Targets]/";
           virtDir += prefix;
-          virtDir += ti->first;
+          virtDir += targetName;
           std::string buildArgs = "-C \"";
-          buildArgs += makefile->GetHomeOutputDirectory();
+          buildArgs += (*it)->GetBinaryDirectory();
           buildArgs += "\" ";
           buildArgs += makeArgs;
           this->AppendTarget(fout, "Build", make, buildArgs, virtDir, "",
-                             ti->first.c_str());
+                             targetName.c_str());
 
           std::string cleanArgs = "-E chdir \"";
-          cleanArgs += makefile->GetCurrentBinaryDirectory();
+          cleanArgs += (*it)->GetCurrentBinaryDirectory();
           cleanArgs += "\" \"";
           cleanArgs += cmSystemTools::GetCMakeCommand();
           cleanArgs += "\" -P \"";
-          cleanArgs += (*it)->GetTargetDirectory(ti->second);
+          cmGeneratorTarget* gt = *ti;
+          cleanArgs += (*it)->GetTargetDirectory(gt);
           cleanArgs += "/cmake_clean.cmake\"";
           this->AppendTarget(fout, "Clean", cmSystemTools::GetCMakeCommand(),
                              cleanArgs, virtDir, "", "");
@@ -1149,8 +1151,8 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
   fout << "</cconfiguration>\n"
           "</storageModule>\n"
           "<storageModule moduleId=\"cdtBuildSystem\" version=\"4.0.0\">\n"
-          "<project id=\"" << this->EscapeForXML(mf->GetProjectName())
-       << ".null.1\" name=\"" << this->EscapeForXML(mf->GetProjectName())
+          "<project id=\"" << this->EscapeForXML(lg->GetProjectName())
+       << ".null.1\" name=\"" << this->EscapeForXML(lg->GetProjectName())
        << "\"/>\n"
           "</storageModule>\n"
           "</cproject>\n"
diff --git a/Source/cmExtraEclipseCDT4Generator.h b/Source/cmExtraEclipseCDT4Generator.h
index ef99760..16675f2 100644
--- a/Source/cmExtraEclipseCDT4Generator.h
+++ b/Source/cmExtraEclipseCDT4Generator.h
@@ -100,7 +100,7 @@ private:
                                    std::set<std::string>& emittedDirs);
 
   static void AddEnvVar(cmGeneratedFileStream& fout, const char* envVar,
-                        cmMakefile* mf);
+                        cmLocalGenerator* lg);
 
   void CreateLinksToSubprojects(cmGeneratedFileStream& fout,
                                 const std::string& baseDir);
diff --git a/Source/cmExtraKateGenerator.cxx b/Source/cmExtraKateGenerator.cxx
index f83b5cf..ff5d3ab 100644
--- a/Source/cmExtraKateGenerator.cxx
+++ b/Source/cmExtraKateGenerator.cxx
@@ -17,7 +17,6 @@
 #include "cmake.h"
 #include "cmSourceFile.h"
 #include "cmGeneratedFileStream.h"
-#include "cmTarget.h"
 #include "cmSystemTools.h"
 
 #include <cmsys/SystemTools.hxx>
@@ -46,21 +45,22 @@ cmExtraKateGenerator::cmExtraKateGenerator()
 
 void cmExtraKateGenerator::Generate()
 {
-  const cmMakefile* mf
-     = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
-  this->ProjectName = this->GenerateProjectName(mf->GetProjectName(),
+  cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
+  const cmMakefile* mf = lg->GetMakefile();
+  this->ProjectName = this->GenerateProjectName(lg->GetProjectName(),
                           mf->GetSafeDefinition("CMAKE_BUILD_TYPE"),
-                          this->GetPathBasename(mf->GetHomeOutputDirectory()));
+                          this->GetPathBasename(lg->GetBinaryDirectory()));
   this->UseNinja = (this->GlobalGenerator->GetName() == "Ninja");
 
-  this->CreateKateProjectFile(mf);
-  this->CreateDummyKateProjectFile(mf);
+  this->CreateKateProjectFile(lg);
+  this->CreateDummyKateProjectFile(lg);
 }
 
 
-void cmExtraKateGenerator::CreateKateProjectFile(const cmMakefile* mf) const
+void cmExtraKateGenerator::CreateKateProjectFile(
+    const cmLocalGenerator* lg) const
 {
-  std::string filename = mf->GetHomeOutputDirectory();
+  std::string filename = lg->GetBinaryDirectory();
   filename += "/.kateproject";
   cmGeneratedFileStream fout(filename.c_str());
   if (!fout)
@@ -68,31 +68,29 @@ void cmExtraKateGenerator::CreateKateProjectFile(const cmMakefile* mf) const
     return;
     }
 
-  std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
-  std::string args = mf->GetSafeDefinition("CMAKE_KATE_MAKE_ARGUMENTS");
-
   fout <<
     "{\n"
     "\t\"name\": \"" << this->ProjectName << "\",\n"
-    "\t\"directory\": \"" << mf->GetHomeDirectory() << "\",\n"
-    "\t\"files\": [ { " << this->GenerateFilesString(mf) << "} ],\n";
-  this->WriteTargets(mf, fout);
+    "\t\"directory\": \"" << lg->GetSourceDirectory() << "\",\n"
+    "\t\"files\": [ { " << this->GenerateFilesString(lg) << "} ],\n";
+  this->WriteTargets(lg, fout);
   fout << "}\n";
 }
 
 
 void
-cmExtraKateGenerator::WriteTargets(const cmMakefile* mf,
+cmExtraKateGenerator::WriteTargets(const cmLocalGenerator* lg,
                                    cmGeneratedFileStream& fout) const
 {
+  cmMakefile const* mf = lg->GetMakefile();
   const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
   const std::string makeArgs = mf->GetSafeDefinition(
     "CMAKE_KATE_MAKE_ARGUMENTS");
-  const char* homeOutputDir = mf->GetHomeOutputDirectory();
+  const char* homeOutputDir = lg->GetBinaryDirectory();
 
   fout <<
   "\t\"build\": {\n"
-  "\t\t\"directory\": \"" << mf->GetHomeOutputDirectory() << "\",\n"
+  "\t\t\"directory\": \"" << lg->GetBinaryDirectory() << "\",\n"
   "\t\t\"default_target\": \"all\",\n"
   "\t\t\"clean_target\": \"clean\",\n";
 
@@ -120,16 +118,18 @@ cmExtraKateGenerator::WriteTargets(const cmMakefile* mf,
        it != this->GlobalGenerator->GetLocalGenerators().end();
        ++it)
     {
-    const cmTargets& targets = (*it)->GetMakefile()->GetTargets();
-    cmMakefile* makefile=(*it)->GetMakefile();
-    std::string currentDir = makefile->GetCurrentBinaryDirectory();
-    bool topLevel = (currentDir == makefile->GetHomeOutputDirectory());
+    const std::vector<cmGeneratorTarget*> targets =
+        (*it)->GetGeneratorTargets();
+    std::string currentDir = (*it)->GetCurrentBinaryDirectory();
+    bool topLevel = (currentDir == (*it)->GetBinaryDirectory());
 
-    for(cmTargets::const_iterator ti=targets.begin(); ti!=targets.end(); ++ti)
+    for(std::vector<cmGeneratorTarget*>::const_iterator ti =
+        targets.begin(); ti!=targets.end(); ++ti)
       {
-      switch(ti->second.GetType())
+      std::string targetName = (*ti)->GetName();
+      switch((*ti)->GetType())
         {
-        case cmTarget::GLOBAL_TARGET:
+        case cmState::GLOBAL_TARGET:
           {
           bool insertTarget = false;
           // Only add the global targets from CMAKE_BINARY_DIR,
@@ -139,9 +139,9 @@ cmExtraKateGenerator::WriteTargets(const cmMakefile* mf,
             insertTarget = true;
             // only add the "edit_cache" target if it's not ccmake, because
             // this will not work within the IDE
-            if (ti->first == "edit_cache")
+            if (targetName == "edit_cache")
               {
-              const char* editCommand = makefile->GetDefinition
+              const char* editCommand = (*it)->GetMakefile()->GetDefinition
               ("CMAKE_EDIT_COMMAND");
               if (editCommand == 0)
                 {
@@ -155,34 +155,35 @@ cmExtraKateGenerator::WriteTargets(const cmMakefile* mf,
             }
           if (insertTarget)
             {
-            this->AppendTarget(fout, ti->first, make, makeArgs,
+            this->AppendTarget(fout, targetName, make, makeArgs,
                                currentDir, homeOutputDir);
             }
         }
         break;
-        case cmTarget::UTILITY:
+        case cmState::UTILITY:
           // Add all utility targets, except the Nightly/Continuous/
           // Experimental-"sub"targets as e.g. NightlyStart
-          if (((ti->first.find("Nightly")==0)   &&(ti->first!="Nightly"))
-            || ((ti->first.find("Continuous")==0)&&(ti->first!="Continuous"))
-            || ((ti->first.find("Experimental")==0)
-            && (ti->first!="Experimental")))
+          if (((targetName.find("Nightly")==0)   &&(targetName!="Nightly"))
+            || ((targetName.find("Continuous")==0)
+                &&(targetName!="Continuous"))
+            || ((targetName.find("Experimental")==0)
+            && (targetName!="Experimental")))
             {
               break;
             }
 
-            this->AppendTarget(fout, ti->first, make, makeArgs,
+            this->AppendTarget(fout, targetName, make, makeArgs,
                                currentDir, homeOutputDir);
           break;
-        case cmTarget::EXECUTABLE:
-        case cmTarget::STATIC_LIBRARY:
-        case cmTarget::SHARED_LIBRARY:
-        case cmTarget::MODULE_LIBRARY:
-        case cmTarget::OBJECT_LIBRARY:
+        case cmState::EXECUTABLE:
+        case cmState::STATIC_LIBRARY:
+        case cmState::SHARED_LIBRARY:
+        case cmState::MODULE_LIBRARY:
+        case cmState::OBJECT_LIBRARY:
         {
-          this->AppendTarget(fout, ti->first, make, makeArgs,
+          this->AppendTarget(fout, targetName, make, makeArgs,
                              currentDir, homeOutputDir);
-          std::string fastTarget = ti->first;
+          std::string fastTarget = targetName;
           fastTarget += "/fast";
           this->AppendTarget(fout, fastTarget, make, makeArgs,
                              currentDir, homeOutputDir);
@@ -234,9 +235,10 @@ cmExtraKateGenerator::AppendTarget(cmGeneratedFileStream& fout,
 
 
 void
-cmExtraKateGenerator::CreateDummyKateProjectFile(const cmMakefile* mf) const
+cmExtraKateGenerator::CreateDummyKateProjectFile(
+    const cmLocalGenerator* lg) const
 {
-  std::string filename = mf->GetHomeOutputDirectory();
+  std::string filename = lg->GetBinaryDirectory();
   filename += "/";
   filename += this->ProjectName;
   filename += ".kateproject";
@@ -252,23 +254,23 @@ cmExtraKateGenerator::CreateDummyKateProjectFile(const cmMakefile* mf) const
 
 
 std::string
-cmExtraKateGenerator::GenerateFilesString(const cmMakefile* mf) const
+cmExtraKateGenerator::GenerateFilesString(const cmLocalGenerator* lg) const
 {
-  std::string s = mf->GetHomeDirectory();
+  std::string s = lg->GetSourceDirectory();
   s += "/.git";
   if(cmSystemTools::FileExists(s.c_str()))
   {
     return std::string("\"git\": 1 ");
   }
 
-  s = mf->GetHomeDirectory();
+  s = lg->GetSourceDirectory();
   s += "/.svn";
   if(cmSystemTools::FileExists(s.c_str()))
   {
     return std::string("\"svn\": 1 ");
   }
 
-  s = mf->GetHomeDirectory();
+  s = lg->GetSourceDirectory();
   s += "/";
 
   std::set<std::string> files;
diff --git a/Source/cmExtraKateGenerator.h b/Source/cmExtraKateGenerator.h
index f800feb..281c1ef 100644
--- a/Source/cmExtraKateGenerator.h
+++ b/Source/cmExtraKateGenerator.h
@@ -16,8 +16,6 @@
 #include "cmExternalMakefileProjectGenerator.h"
 
 class cmLocalGenerator;
-class cmMakefile;
-class cmTarget;
 class cmGeneratedFileStream;
 
 /** \class cmExtraKateGenerator
@@ -39,9 +37,10 @@ public:
 
   virtual void Generate();
 private:
-  void CreateKateProjectFile(const cmMakefile* mf) const;
-  void CreateDummyKateProjectFile(const cmMakefile* mf) const;
-  void WriteTargets(const cmMakefile* mf, cmGeneratedFileStream& fout) const;
+  void CreateKateProjectFile(const cmLocalGenerator* lg) const;
+  void CreateDummyKateProjectFile(const cmLocalGenerator* lg) const;
+  void WriteTargets(const cmLocalGenerator* lg,
+                    cmGeneratedFileStream& fout) const;
   void AppendTarget(cmGeneratedFileStream& fout,
                     const std::string&     target,
                     const std::string&     make,
@@ -49,7 +48,7 @@ private:
                     const std::string&     path,
                     const char*            homeOutputDir) const;
 
-  std::string GenerateFilesString(const cmMakefile* mf) const;
+  std::string GenerateFilesString(const cmLocalGenerator* lg) const;
   std::string GetPathBasename(const std::string& path) const;
   std::string GenerateProjectName(const std::string& name,
                                   const std::string& type,
diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index 163a75b..92d38b9 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -20,7 +20,6 @@
 #include "cmMakefile.h"
 #include "cmSourceFile.h"
 #include "cmSystemTools.h"
-#include "cmTarget.h"
 
 #include <cmsys/SystemTools.hxx>
 
@@ -77,9 +76,8 @@ void cmExtraSublimeTextGenerator::Generate()
 void cmExtraSublimeTextGenerator::CreateProjectFile(
                                      const std::vector<cmLocalGenerator*>& lgs)
 {
-  const cmMakefile* mf=lgs[0]->GetMakefile();
-  std::string outputDir=mf->GetCurrentBinaryDirectory();
-  std::string projectName=mf->GetProjectName();
+  std::string outputDir=lgs[0]->GetCurrentBinaryDirectory();
+  std::string projectName=lgs[0]->GetProjectName();
 
   const std::string filename =
                      outputDir + "/" + projectName + ".sublime-project";
@@ -99,8 +97,8 @@ void cmExtraSublimeTextGenerator
     }
 
   const std::string &sourceRootRelativeToOutput = cmSystemTools::RelativePath(
-                     mf->GetHomeOutputDirectory(),
-                     mf->GetHomeDirectory());
+                     lgs[0]->GetBinaryDirectory(),
+                     lgs[0]->GetSourceDirectory());
   // Write the folder entries to the project file
   fout << "{\n";
   fout << "\t\"folders\":\n\t[\n\t";
@@ -108,8 +106,8 @@ void cmExtraSublimeTextGenerator
     {
       fout << "\t{\n\t\t\t\"path\": \"" << sourceRootRelativeToOutput << "\"";
       const std::string &outputRelativeToSourceRoot =
-        cmSystemTools::RelativePath(mf->GetHomeDirectory(),
-                                    mf->GetHomeOutputDirectory());
+        cmSystemTools::RelativePath(lgs[0]->GetSourceDirectory(),
+                                    lgs[0]->GetBinaryDirectory());
       if ((!outputRelativeToSourceRoot.empty()) &&
         ((outputRelativeToSourceRoot.length() < 3) ||
           (outputRelativeToSourceRoot.substr(0, 3) != "../")))
@@ -163,52 +161,54 @@ void cmExtraSublimeTextGenerator::
        lg!=lgs.end(); lg++)
     {
     cmMakefile* makefile=(*lg)->GetMakefile();
-    cmTargets& targets=makefile->GetTargets();
-    for (cmTargets::iterator ti = targets.begin();
+    std::vector<cmGeneratorTarget*> targets=(*lg)->GetGeneratorTargets();
+    for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
          ti != targets.end(); ti++)
       {
-      switch(ti->second.GetType())
+      std::string targetName = (*ti)->GetName();
+      switch((*ti)->GetType())
         {
-        case cmTarget::GLOBAL_TARGET:
+        case cmState::GLOBAL_TARGET:
           {
           // Only add the global targets from CMAKE_BINARY_DIR,
           // not from the subdirs
-          if (strcmp(makefile->GetCurrentBinaryDirectory(),
-                     makefile->GetHomeOutputDirectory())==0)
+          if (strcmp((*lg)->GetCurrentBinaryDirectory(),
+                     (*lg)->GetBinaryDirectory())==0)
             {
-            this->AppendTarget(fout, ti->first, *lg, 0,
+            this->AppendTarget(fout, targetName, *lg, 0,
                                make.c_str(), makefile, compiler.c_str(),
                                sourceFileFlags, false);
             }
           }
           break;
-        case cmTarget::UTILITY:
+        case cmState::UTILITY:
           // Add all utility targets, except the Nightly/Continuous/
           // Experimental-"sub"targets as e.g. NightlyStart
-          if (((ti->first.find("Nightly")==0)   &&(ti->first!="Nightly"))
-             || ((ti->first.find("Continuous")==0)&&(ti->first!="Continuous"))
-             || ((ti->first.find("Experimental")==0)
-                                               && (ti->first!="Experimental")))
+          if (((targetName.find("Nightly")==0)   &&(targetName!="Nightly"))
+             || ((targetName.find("Continuous")==0)
+                 &&(targetName!="Continuous"))
+             || ((targetName.find("Experimental")==0)
+                 && (targetName!="Experimental")))
             {
             break;
             }
 
-          this->AppendTarget(fout, ti->first, *lg, 0,
+          this->AppendTarget(fout, targetName, *lg, 0,
                              make.c_str(), makefile, compiler.c_str(),
                              sourceFileFlags, false);
           break;
-        case cmTarget::EXECUTABLE:
-        case cmTarget::STATIC_LIBRARY:
-        case cmTarget::SHARED_LIBRARY:
-        case cmTarget::MODULE_LIBRARY:
-        case cmTarget::OBJECT_LIBRARY:
+        case cmState::EXECUTABLE:
+        case cmState::STATIC_LIBRARY:
+        case cmState::SHARED_LIBRARY:
+        case cmState::MODULE_LIBRARY:
+        case cmState::OBJECT_LIBRARY:
           {
-          this->AppendTarget(fout, ti->first, *lg, &ti->second,
+          this->AppendTarget(fout, targetName, *lg, *ti,
                              make.c_str(), makefile, compiler.c_str(),
                              sourceFileFlags, false);
-          std::string fastTarget = ti->first;
+          std::string fastTarget = targetName;
           fastTarget += "/fast";
-          this->AppendTarget(fout, fastTarget, *lg, &ti->second,
+          this->AppendTarget(fout, fastTarget, *lg, *ti,
                              make.c_str(), makefile, compiler.c_str(),
                              sourceFileFlags, false);
           }
@@ -224,7 +224,7 @@ void cmExtraSublimeTextGenerator::
   AppendTarget(cmGeneratedFileStream& fout,
                const std::string& targetName,
                cmLocalGenerator* lg,
-               cmTarget* target,
+               cmGeneratorTarget* target,
                const char* make,
                const cmMakefile* makefile,
                const char*, //compiler
@@ -234,8 +234,6 @@ void cmExtraSublimeTextGenerator::
 
   if (target != 0)
     {
-      cmGeneratorTarget *gtgt = this->GlobalGenerator
-                                    ->GetGeneratorTarget(target);
       std::vector<cmSourceFile*> sourceFiles;
       target->GetSourceFiles(sourceFiles,
                              makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
@@ -255,9 +253,9 @@ void cmExtraSublimeTextGenerator::
             }
           std::vector<std::string>& flags = sourceFileFlagsIter->second;
           std::string flagsString =
-            this->ComputeFlagsForObject(*iter, lg, target, gtgt);
+            this->ComputeFlagsForObject(*iter, lg, target);
           std::string definesString =
-            this->ComputeDefines(*iter, lg, target, gtgt);
+            this->ComputeDefines(*iter, lg, target);
           flags.clear();
           cmsys::RegularExpression flagRegex;
           // Regular expression to extract compiler flags from a string
@@ -302,7 +300,7 @@ void cmExtraSublimeTextGenerator::
     {
     fout << ",\n\t";
     }
-  fout << "\t{\n\t\t\t\"name\": \"" << makefile->GetProjectName() << " - " <<
+  fout << "\t{\n\t\t\t\"name\": \"" << lg->GetProjectName() << " - " <<
           targetName << "\",\n";
   fout << "\t\t\t\"cmd\": [" <<
           this->BuildMakeCommand(make, makefileName.c_str(), targetName) <<
@@ -365,7 +363,6 @@ std::string cmExtraSublimeTextGenerator::BuildMakeCommand(
 std::string
 cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source,
                                                    cmLocalGenerator* lg,
-                                                   cmTarget *target,
                                                    cmGeneratorTarget* gtgt)
 {
   std::string flags;
@@ -390,7 +387,7 @@ cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source,
   //   }
 
   // Add shared-library flags if needed.
-  lg->AddCMP0018Flags(flags, target, language, config);
+  lg->AddCMP0018Flags(flags, gtgt, language, config);
 
   // Add include directory flags.
   {
@@ -405,7 +402,7 @@ cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source,
   lg->AppendFlags(flags, makefile->GetDefineFlags());
 
   // Add target-specific flags.
-  lg->AddCompileOptions(flags, target, language, config);
+  lg->AddCompileOptions(flags, gtgt, language, config);
 
   // Add source file specific flags.
   lg->AppendFlags(flags, source->GetProperty("COMPILE_FLAGS"));
@@ -419,8 +416,8 @@ cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source,
 // void cmMakefileTargetGenerator::WriteTargetLanguageFlags().
 std::string
 cmExtraSublimeTextGenerator::
-ComputeDefines(cmSourceFile *source, cmLocalGenerator* lg, cmTarget *target,
-               cmGeneratorTarget*)
+ComputeDefines(cmSourceFile *source, cmLocalGenerator* lg,
+               cmGeneratorTarget* target)
 
 {
   std::set<std::string> defines;
diff --git a/Source/cmExtraSublimeTextGenerator.h b/Source/cmExtraSublimeTextGenerator.h
index 4173b7d..cf31ee0 100644
--- a/Source/cmExtraSublimeTextGenerator.h
+++ b/Source/cmExtraSublimeTextGenerator.h
@@ -18,7 +18,6 @@
 
 class cmLocalGenerator;
 class cmMakefile;
-class cmTarget;
 class cmGeneratedFileStream;
 class cmGeneratorTarget;
 
@@ -67,7 +66,7 @@ private:
   void AppendTarget(cmGeneratedFileStream& fout,
                     const std::string& targetName,
                     cmLocalGenerator* lg,
-                    cmTarget* target,
+                    cmGeneratorTarget* target,
                     const char* make,
                     const cmMakefile* makefile,
                     const char* compiler,
@@ -79,11 +78,10 @@ private:
    */
   std::string ComputeFlagsForObject(cmSourceFile *source,
                                     cmLocalGenerator* lg,
-                                    cmTarget *target,
                                     cmGeneratorTarget* gtgt);
 
   std::string ComputeDefines(cmSourceFile *source, cmLocalGenerator* lg,
-                             cmTarget *target, cmGeneratorTarget* gtgt);
+                             cmGeneratorTarget* gtgt);
 };
 
 #endif
diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx
index 12adfd9..d17d664 100644
--- a/Source/cmFLTKWrapUICommand.cxx
+++ b/Source/cmFLTKWrapUICommand.cxx
@@ -129,45 +129,6 @@ void cmFLTKWrapUICommand::FinalPass()
     cmSystemTools::Message(msg.c_str(),"Warning");
     return;
     }
-  std::vector<cmSourceFile*> srcs;
-  target->GetSourceFiles(srcs, "");
-  bool found = false;
-  for (unsigned int i = 0; i < srcs.size(); ++i)
-    {
-    if (srcs[i]->GetFullPath() ==
-        this->GeneratedSourcesClasses[0]->GetFullPath())
-      {
-      found = true;
-      break;
-      }
-    }
-  if (!found)
-    {
-    std::string msg =
-      "In CMake 2.2 the FLTK_WRAP_UI command sets a variable to the list of "
-      "source files that should be added to your executable or library. It "
-      "appears that you have not added these source files to your target. "
-      "You should change your CMakeLists.txt file to "
-      "directly add the generated files to the target. "
-      "For example FTLK_WRAP_UI(foo src1 src2 src3) "
-      "will create a variable named foo_FLTK_UI_SRCS that contains the list "
-      "of sources to add to your target when you call ADD_LIBRARY or "
-      "ADD_EXECUTABLE. For now CMake will add the sources to your target "
-      "for you as was done in CMake 2.0 and earlier. In the future this may "
-      "become an error.";
-    msg +="The problem was found while processing the source directory: ";
-    msg += this->Makefile->GetCurrentSourceDirectory();
-    cmSystemTools::Message(msg.c_str(),"Warning");
-    // first we add the rules for all the .fl to .h and .cxx files
-    size_t lastHeadersClass = this->GeneratedSourcesClasses.size();
-
-    // Generate code for all the .fl files
-    for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
-      {
-      this->Makefile->GetTargets()[this->Target]
-        .AddSource(this->GeneratedSourcesClasses[classNum]->GetFullPath());
-      }
-    }
 }
 
 
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 87faf84..b3557f9 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -15,7 +15,6 @@
 #include "cmHexFileConverter.h"
 #include "cmInstallType.h"
 #include "cmFileTimeComparison.h"
-#include "cmLocalGenerator.h"
 #include "cmGlobalGenerator.h"
 #include "cmCryptoHash.h"
 #include "cmAlgorithms.h"
@@ -2812,8 +2811,8 @@ namespace {
       case CURLINFO_SSL_DATA_OUT:
         {
         char buf[128];
-        int n = sprintf(buf, "[%" cmIML_INT_PRIu64 " bytes data]\n",
-                        static_cast<cmIML_INT_uint64_t>(size));
+        int n = sprintf(buf, "[%" KWIML_INT_PRIu64 " bytes data]\n",
+                        static_cast<KWIML_INT_uint64_t>(size));
         if (n > 0)
           {
           vec->insert(vec->end(), buf, buf + n);
diff --git a/Source/cmFileTimeComparison.cxx b/Source/cmFileTimeComparison.cxx
index 13e2a66..279b61d 100644
--- a/Source/cmFileTimeComparison.cxx
+++ b/Source/cmFileTimeComparison.cxx
@@ -148,7 +148,7 @@ int cmFileTimeComparisonInternal::Compare(cmFileTimeComparison_Type* s1,
                                           cmFileTimeComparison_Type* s2)
 {
 #if !defined(_WIN32) || defined(__CYGWIN__)
-# if cmsys_STAT_HAS_ST_MTIM
+# if CMake_STAT_HAS_ST_MTIM
   // Compare using nanosecond resolution.
   if(s1->st_mtim.tv_sec < s2->st_mtim.tv_sec)
     {
@@ -166,6 +166,24 @@ int cmFileTimeComparisonInternal::Compare(cmFileTimeComparison_Type* s1,
     {
     return 1;
     }
+# elif CMake_STAT_HAS_ST_MTIMESPEC
+  // Compare using nanosecond resolution.
+  if(s1->st_mtimespec.tv_sec < s2->st_mtimespec.tv_sec)
+    {
+    return -1;
+    }
+  else if(s1->st_mtimespec.tv_sec > s2->st_mtimespec.tv_sec)
+    {
+    return 1;
+    }
+  else if(s1->st_mtimespec.tv_nsec < s2->st_mtimespec.tv_nsec)
+    {
+    return -1;
+    }
+  else if(s1->st_mtimespec.tv_nsec > s2->st_mtimespec.tv_nsec)
+    {
+    return 1;
+    }
 # else
   // Compare using 1 second resolution.
   if(s1->st_mtime < s2->st_mtime)
@@ -190,7 +208,7 @@ bool cmFileTimeComparisonInternal::TimesDiffer(cmFileTimeComparison_Type* s1,
                                                cmFileTimeComparison_Type* s2)
 {
 #if !defined(_WIN32) || defined(__CYGWIN__)
-# if cmsys_STAT_HAS_ST_MTIM
+# if CMake_STAT_HAS_ST_MTIM
   // Times are integers in units of 1ns.
   long long bil = 1000000000;
   long long t1 = s1->st_mtim.tv_sec * bil + s1->st_mtim.tv_nsec;
@@ -207,6 +225,23 @@ bool cmFileTimeComparisonInternal::TimesDiffer(cmFileTimeComparison_Type* s1,
     {
     return false;
     }
+# elif CMake_STAT_HAS_ST_MTIMESPEC
+  // Times are integers in units of 1ns.
+  long long bil = 1000000000;
+  long long t1 = s1->st_mtimespec.tv_sec * bil + s1->st_mtimespec.tv_nsec;
+  long long t2 = s2->st_mtimespec.tv_sec * bil + s2->st_mtimespec.tv_nsec;
+  if(t1 < t2)
+    {
+    return (t2 - t1) >= bil;
+    }
+  else if(t2 < t1)
+    {
+    return (t1 - t2) >= bil;
+    }
+  else
+    {
+    return false;
+    }
 # else
   // Times are integers in units of 1s.
   if(s1->st_mtime < s2->st_mtime)
diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h
index 3eee404..8bfd405 100644
--- a/Source/cmFindPackageCommand.h
+++ b/Source/cmFindPackageCommand.h
@@ -130,7 +130,7 @@ private:
   unsigned int VersionFoundPatch;
   unsigned int VersionFoundTweak;
   unsigned int VersionFoundCount;
-  cmIML_INT_uint64_t RequiredCMakeVersion;
+  KWIML_INT_uint64_t RequiredCMakeVersion;
   bool Quiet;
   bool Required;
   bool UseConfigFiles;
diff --git a/Source/cmFortranLexer.cxx b/Source/cmFortranLexer.cxx
index b727f0e..6779c1a 100644
--- a/Source/cmFortranLexer.cxx
+++ b/Source/cmFortranLexer.cxx
@@ -1,6 +1,6 @@
 /*============================================================================
   CMake - Cross Platform Makefile Generator
-  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
+  Copyright 2000-2015 Kitware, Inc., Insight Software Consortium
 
   Distributed under the OSI-approved BSD License (the "License");
   see accompanying file Copyright.txt for details.
@@ -20,7 +20,7 @@
 #define FLEX_SCANNER
 #define YY_FLEX_MAJOR_VERSION 2
 #define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 35
+#define YY_FLEX_SUBMINOR_VERSION 39
 #if YY_FLEX_SUBMINOR_VERSION > 0
 #define FLEX_BETA
 #endif
@@ -190,11 +190,17 @@ typedef void* yyscan_t;
 typedef struct yy_buffer_state *YY_BUFFER_STATE;
 #endif
 
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
 #define EOB_ACT_CONTINUE_SCAN 0
 #define EOB_ACT_END_OF_FILE 1
 #define EOB_ACT_LAST_MATCH 2
 
     #define YY_LESS_LINENO(n)
+    #define YY_LINENO_REWIND_TO(ptr)
 
 /* Return all but the first "n" matched characters back to the input stream. */
 #define yyless(n) \
@@ -212,11 +218,6 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE;
 
 #define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
 
-#ifndef YY_TYPEDEF_YY_SIZE_T
-#define YY_TYPEDEF_YY_SIZE_T
-typedef size_t yy_size_t;
-#endif
-
 #ifndef YY_STRUCT_YY_BUFFER_STATE
 #define YY_STRUCT_YY_BUFFER_STATE
 struct yy_buffer_state
@@ -234,7 +235,7 @@ struct yy_buffer_state
         /* Number of characters read into yy_ch_buf, not including EOB
          * characters.
          */
-        int yy_n_chars;
+        yy_size_t yy_n_chars;
 
         /* Whether we "own" the buffer - i.e., we know we created it,
          * and can realloc() it to grow it, and should free() it to
@@ -313,7 +314,7 @@ static void cmFortran_yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yys
 
 YY_BUFFER_STATE cmFortran_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
 YY_BUFFER_STATE cmFortran_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
-YY_BUFFER_STATE cmFortran_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmFortran_yy_scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner );
 
 void *cmFortran_yyalloc (yy_size_t ,yyscan_t yyscanner );
 void *cmFortran_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
@@ -345,7 +346,7 @@ void cmFortran_yyfree (void * ,yyscan_t yyscanner );
 
 /* Begin user sect3 */
 
-#define cmFortran_yywrap(n) 1
+#define cmFortran_yywrap(yyscanner) 1
 #define YY_SKIP_YYWRAP
 
 typedef unsigned char YY_CHAR;
@@ -369,8 +370,8 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
         *yy_cp = '\0'; \
         yyg->yy_c_buf_p = yy_cp;
 
-#define YY_NUM_RULES 44
-#define YY_END_OF_BUFFER 45
+#define YY_NUM_RULES 45
+#define YY_END_OF_BUFFER 46
 /* This struct is not used in this scanner,
    but its presence is necessary. */
 struct yy_trans_info
@@ -378,26 +379,27 @@ struct yy_trans_info
         flex_int32_t yy_verify;
         flex_int32_t yy_nxt;
         };
-static yyconst flex_int16_t yy_accept[165] =
+static yyconst flex_int16_t yy_accept[173] =
     {   0,
         0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-       45,   39,   41,   40,   43,    1,   39,   32,    2,   34,
-       39,   40,   37,   39,   38,   39,   38,   41,   39,   40,
-       39,   38,    9,    8,    9,    4,    3,   39,    0,   10,
-        0,    0,    0,    0,    0,   32,   32,   33,   35,   37,
-       39,   38,    0,   42,   38,    0,    0,    0,    0,    0,
-        0,    0,    0,   39,    0,   11,   38,    0,    0,    5,
-        0,    0,    0,   28,    0,    0,   32,   32,   32,   32,
-        0,    0,    0,    0,    0,   22,    0,    0,    0,    0,
-        0,    6,    0,    0,    0,    0,    0,    0,    0,    0,
+       46,   40,   42,   41,   44,    1,   40,   33,    2,   35,
+       40,   41,   38,   40,   39,   40,   39,   42,   40,   41,
+       40,   39,    9,    8,    9,    4,    3,   40,    0,   10,
+        0,    0,    0,    0,    0,   33,   33,   34,   36,   38,
+       40,   39,    0,   43,   39,    0,    0,    0,   12,    0,
+        0,    0,    0,    0,    0,   40,    0,   11,   39,    0,
+        0,    5,    0,    0,    0,   29,    0,    0,   33,   33,
+       33,   33,    0,    0,   12,   12,    0,    0,    0,   23,
+        0,    0,    0,    0,    0,    0,    6,    0,    0,    0,
 
         0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-        0,    0,   29,   30,    0,    0,    0,    0,    0,    0,
-        0,   23,   24,    0,    0,    0,    0,    0,    0,    0,
-        0,   31,   26,    0,    0,   19,    0,    0,   25,   20,
-        0,    0,   18,    0,    0,   17,   27,    0,    0,   16,
-       21,    0,    7,   36,    7,   14,    0,   13,   15,    0,
-        0,    0,   12,    0
+        0,    0,    0,    0,    0,    0,    0,    0,   30,   31,
+        0,    0,    0,    0,    0,    0,    0,   24,   25,    0,
+        0,    0,    0,    0,    0,    0,    0,    0,   32,   27,
+        0,    0,   20,    0,    0,   26,   21,    0,    0,    0,
+       19,    0,    0,   18,   28,    0,    0,   17,   22,    0,
+        7,   37,    7,   15,    0,   14,   16,    0,    0,    0,
+       13,    0
     } ;
 
 static yyconst flex_int32_t yy_ec[256] =
@@ -441,178 +443,186 @@ static yyconst flex_int32_t yy_meta[42] =
         7
     } ;
 
-static yyconst flex_int16_t yy_base[174] =
+static yyconst flex_int16_t yy_base[182] =
     {   0,
-        0,   40,    0,   41,  188,   48,   44,   54,   56,   65,
-      186,    0,  505,  505,  171,  505,   81,   74,  505,  505,
-      158,  505,  151,  137,    0,   85,  122,   87,  153,  145,
-      194,  226,  505,  143,   91,  505,  505,    0,  142,  505,
-      266,   34,   70,   74,   34,  122,  141,  505,    0,  505,
-      112,    0,   98,  505,    0,  154,  306,    0,   43,  133,
-      139,   46,  130,  347,  130,  505,    0,  121,  163,  179,
-      104,  156,  129,  176,  147,  178,  214,  267,  273,  292,
-      279,  179,  249,  280,  257,  265,  288,  289,  116,  107,
-      317,  505,  287,  289,  291,  302,  307,  310,  307,  311,
-
-      316,  326,  329,  333,  332,  336,  347,  345,  349,  101,
-       86,  346,  505,  505,  350,  351,  353,  350,  357,  362,
-      362,  505,  505,  367,  369,  371,  366,  372,   56,   47,
-      374,  505,  505,  374,  379,  505,  374,  387,  505,  505,
-      387,  391,  505,  117,    0,  505,  505,  392,  394,  505,
-      505,  394,  505,  505,  505,  505,  395,  419,  505,  429,
-        0,   25,  505,  505,  446,  453,  459,  462,  469,  476,
-      483,  490,  497
+        0,   40,    0,   41,  220,   48,   44,   54,   56,   65,
+      220,    0,  535,  535,  216,  535,   81,   74,  535,  535,
+      186,  535,  153,  145,    0,   85,  122,   87,  154,  155,
+      195,  227,  535,  147,   91,  535,  535,    0,  147,  535,
+      267,   34,   70,   74,   34,  122,  141,  535,    0,  535,
+      112,    0,   98,  535,    0,  156,  307,    0,  143,   43,
+      155,  151,   48,  101,  130,  348,  130,  535,    0,  121,
+      197,  165,  172,  244,  182,  183,  191,  248,  273,  293,
+      308,  314,  321,  246,  275,  216,  269,  299,  304,  327,
+      307,  304,  312,  116,  107,  367,  535,  327,  334,  347,
+
+      347,  350,  352,  349,  354,  359,  357,  363,  366,  365,
+      369,  372,  369,  373,  374,  101,   86,  372,  535,  535,
+      378,  380,  386,  382,  388,  388,  389,  535,  535,  393,
+      394,  396,  392,  430,  400,   56,   47,  403,  535,  535,
+      409,  414,  535,  409,  416,  535,  535,  416,  419,  441,
+      535,  117,    0,  535,  535,  423,  426,  535,  535,  430,
+      535,  535,  535,  535,  432,  457,  535,  459,    0,   25,
+      535,  535,  476,  483,  489,  492,  499,  506,  513,  520,
+      527
     } ;
 
-static yyconst flex_int16_t yy_def[174] =
+static yyconst flex_int16_t yy_def[182] =
     {   0,
-      164,    1,    1,    1,    1,    1,  165,  165,  165,  165,
-      164,  166,  164,  164,  167,  164,  166,  164,  164,  164,
-      166,  164,  164,  166,  168,  166,  168,  164,  166,  164,
-      169,  164,  164,  164,  164,  164,  164,  166,  167,  164,
-      164,  164,  164,  164,  164,  164,  170,  164,  166,  164,
-      166,  168,  164,  164,   27,  164,  164,   57,  164,  164,
-      164,  164,  164,  169,  169,  164,   32,  164,  164,  164,
-      164,  164,  164,  164,  164,  164,  170,  170,  170,  170,
-      164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
-      164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
-
-      164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
-      164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
-      164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
-      164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
-      164,  164,  164,  171,  172,  164,  164,  164,  164,  164,
-      164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
-      173,  173,  164,    0,  164,  164,  164,  164,  164,  164,
-      164,  164,  164
+      172,    1,    1,    1,    1,    1,  173,  173,  173,  173,
+      172,  174,  172,  172,  175,  172,  174,  172,  172,  172,
+      174,  172,  172,  174,  176,  174,  176,  172,  172,  172,
+      177,  172,  172,  172,  172,  172,  172,  174,  175,  172,
+      172,  172,  172,  172,  172,  172,  178,  172,  174,  172,
+      174,  176,  172,  172,   27,  172,  172,   57,  174,  172,
+      172,  172,  172,  172,  172,  177,  177,  172,   32,  172,
+      172,  172,  172,  172,  172,  172,  172,  172,  178,  178,
+      178,  178,  172,  172,  172,  172,  172,  172,  172,  172,
+      172,  172,  172,  172,  172,  172,  172,  172,  172,  172,
+
+      172,  172,  172,  172,  172,  172,  172,  172,  172,  172,
+      172,  172,  172,  172,  172,  172,  172,  172,  172,  172,
+      172,  172,  172,  172,  172,  172,  172,  172,  172,  172,
+      172,  172,  172,  172,  172,  172,  172,  172,  172,  172,
+      172,  172,  172,  172,  172,  172,  172,  172,  172,  172,
+      172,  179,  180,  172,  172,  172,  172,  172,  172,  172,
+      172,  172,  172,  172,  172,  172,  172,  172,  181,  181,
+      172,    0,  172,  172,  172,  172,  172,  172,  172,  172,
+      172
     } ;
 
-static yyconst flex_int16_t yy_nxt[547] =
+static yyconst flex_int16_t yy_nxt[577] =
     {   0,
        12,   13,   14,   13,   13,   15,   16,   12,   17,   18,
        19,   12,   20,   12,   21,   22,   12,   23,   12,   24,
        25,   25,   25,   25,   25,   25,   25,   25,   25,   25,
        26,   27,   25,   25,   25,   25,   25,   25,   25,   25,
-       25,   28,   28,  163,   28,   28,   34,   29,   29,   28,
-       30,  145,   28,   35,   36,   29,   34,   71,   34,   31,
-      144,   76,   37,   35,   36,   35,   83,   34,   71,   32,
-       32,   37,   76,   88,   35,   46,   46,   83,   46,   47,
-       32,   32,   41,   48,   88,   41,   53,   54,   56,   53,
-      130,   56,   69,   70,   57,   69,   72,   73,   74,   53,
-
-       54,   75,   53,   42,   43,  129,   44,   72,   73,   74,
-       45,  111,   75,   81,   42,   43,   81,   44,  154,  154,
-      110,   45,   38,   46,   46,   90,   46,   47,   93,   38,
-       38,   48,   66,   38,   89,   55,   38,   82,   38,   93,
-       38,   38,   78,   46,   40,   78,   79,   68,   82,   63,
-       80,   96,   38,   55,   58,   56,   51,   58,   56,   84,
-       85,   57,   96,   86,   69,   70,   87,   69,   99,   50,
-       84,   85,   49,   40,   86,   59,   60,   87,   61,   99,
-       91,   94,   62,   91,   95,  164,   59,   60,   92,   61,
-       30,  164,   94,   62,   64,   95,   66,  164,   97,  164,
-
-      100,   64,   64,   98,  164,   64,  101,   64,   64,   97,
-       64,  100,   64,   64,   98,   78,   46,  101,   78,   79,
-      164,  164,  164,   80,   64,   64,   65,   65,   66,   65,
-       65,   65,   65,   65,   65,   65,   65,   65,   65,   67,
-       65,   65,   65,   65,   65,   65,   67,   67,   67,   67,
-       67,   67,   67,   67,   67,   67,   65,   67,   67,   67,
-       67,   67,   67,   67,   67,   67,   67,   41,   78,   46,
-       41,   78,   79,  102,   78,   46,   80,   78,   79,  105,
-       81,  164,   80,   81,  102,  164,  164,  106,   42,   43,
-      105,   44,  107,   78,   46,   45,   78,   79,  106,   42,
-
-       43,   80,   44,  107,   82,  103,   45,   58,  104,  108,
-       58,  109,  112,  113,  114,   82,  103,  164,   91,  104,
-      108,   91,  109,  112,  113,  114,   92,  115,   59,   60,
-      116,   61,  117,  118,  119,   62,  164,  120,  115,   59,
-       60,  116,   61,  117,  118,  119,   62,   64,  120,   66,
-      164,  121,  164,  122,   64,   64,  123,  124,   64,  125,
-       64,   64,  121,   64,  122,   64,   64,  123,  124,  126,
-      125,  127,  128,  131,  132,  133,  134,   64,   64,  135,
-      126,  136,  127,  128,  131,  132,  133,  134,  137,  138,
-      135,  139,  136,  140,  141,  142,  143,  146,  147,  137,
-
-      138,  148,  139,  149,  140,  141,  142,  143,  146,  147,
-      150,  151,  148,  152,  149,  156,  157,  158,  159,  164,
-      160,  150,  151,  160,  152,  164,  156,  157,  158,  159,
-      160,  164,  164,  160,  164,  161,  164,  164,  164,  164,
-      164,  164,  164,  164,  164,  161,   33,   33,   33,   33,
-       33,   33,   33,   38,  164,  164,  164,   38,   38,   39,
-       39,   39,   39,   39,   39,   39,   52,  164,   52,   65,
-       65,   65,   65,   65,   65,   65,   77,   77,   77,   77,
-       77,   77,   77,  153,  153,  153,  164,  153,  153,  153,
-      155,  164,  155,  164,  155,  155,  155,  162,  162,  162,
-
-      162,  162,  164,  162,   11,  164,  164,  164,  164,  164,
-      164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
-      164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
-      164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
-      164,  164,  164,  164,  164,  164
+       25,   28,   28,  171,   28,   28,   34,   29,   29,   28,
+       30,  153,   28,   35,   36,   29,   34,   73,   34,   31,
+      152,   78,   37,   35,   36,   35,   87,   34,   73,   32,
+       32,   37,   78,   92,   35,   46,   46,   87,   46,   47,
+       32,   32,   41,   48,   92,   41,   53,   54,   56,   53,
+      137,   56,   71,   72,   57,   71,   74,   75,   76,   53,
+
+       54,   77,   53,   42,   43,  136,   44,   74,   75,   76,
+       45,  117,   77,   83,   42,   43,   83,   44,  162,  162,
+      116,   45,   38,   46,   46,   95,   46,   47,   93,   38,
+       38,   48,   68,   38,   94,   55,   38,   84,   38,   93,
+       38,   38,   80,   46,   86,   80,   81,   86,   84,   40,
+       82,   70,   38,   55,   38,   58,   59,   56,   58,   65,
+       56,   38,   38,   57,   51,   38,   96,   59,   38,   96,
+       38,   50,   38,   38,   97,   90,   60,   61,   91,   62,
+       63,   88,   89,   64,   38,   38,   90,   60,   61,   91,
+       62,   63,   88,   89,   64,   66,   98,   68,   71,   72,
+
+       49,   71,   66,   66,  101,  102,   66,   98,   66,   66,
+      103,   66,  104,   66,   66,  101,  102,   86,   40,  172,
+       86,  103,   30,  104,  172,   66,   66,   67,   67,   68,
+       67,   67,   67,   67,   67,   67,   67,   67,   67,   67,
+       69,   67,   67,   67,   67,   67,   67,   69,   69,   69,
+       69,   69,   69,   69,   69,   69,   69,   67,   69,   69,
+       69,   69,   69,   69,   69,   69,   69,   69,   41,   99,
+      105,   41,  100,  106,   80,   46,   86,   80,   81,   86,
+       99,  105,   82,  100,  106,  172,  172,  172,   85,   42,
+       43,  172,   44,  107,   80,   46,   45,   80,   81,  172,
+
+       42,   43,   82,   44,  107,  172,  172,   45,   58,   80,
+       46,   58,   80,   81,  172,   80,   46,   82,   80,   81,
+       85,  172,   83,   82,  108,   83,  110,  109,  113,   60,
+       61,  114,   62,   63,  115,  108,   64,  110,  109,  113,
+       60,   61,  114,   62,   63,  115,   84,   64,   66,  111,
+       68,  172,  118,  172,  112,   66,   66,   84,  119,   66,
+      111,   66,   66,  118,   66,  112,   66,   66,   96,  119,
+      120,   96,  121,  122,  123,  124,   97,  125,   66,   66,
+      126,  120,  127,  121,  122,  123,  124,  128,  125,  129,
+      130,  126,  131,  127,  132,  133,  134,  135,  128,  138,
+
+      129,  130,  139,  131,  140,  132,  133,  134,  135,  141,
+      138,  142,  143,  139,  144,  140,  145,  146,  147,  148,
+      141,  149,  142,  143,  151,  144,  154,  145,  146,  147,
+      148,  150,  149,  155,  150,  151,  156,  154,  157,  158,
+      159,  160,  150,   85,  155,  150,  164,  156,  165,  157,
+      158,  159,  160,  166,   85,  167,  172,  164,  168,  165,
+      168,  168,  172,  168,  166,  172,  167,  172,  172,  172,
+      172,  172,  172,  169,  172,  169,   33,   33,   33,   33,
+       33,   33,   33,   38,  172,  172,  172,   38,   38,   39,
+       39,   39,   39,   39,   39,   39,   52,  172,   52,   67,
+
+       67,   67,   67,   67,   67,   67,   79,   79,   79,   79,
+       79,   79,   79,  161,  161,  161,  172,  161,  161,  161,
+      163,  172,  163,  172,  163,  163,  163,  170,  170,  170,
+      170,  170,  172,  170,   11,  172,  172,  172,  172,  172,
+      172,  172,  172,  172,  172,  172,  172,  172,  172,  172,
+      172,  172,  172,  172,  172,  172,  172,  172,  172,  172,
+      172,  172,  172,  172,  172,  172,  172,  172,  172,  172,
+      172,  172,  172,  172,  172,  172
     } ;
 
-static yyconst flex_int16_t yy_chk[547] =
+static yyconst flex_int16_t yy_chk[577] =
     {   0,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    2,    4,  162,    2,    4,    7,    2,    4,    6,
-        6,  130,    6,    7,    7,    6,    8,   42,    9,    6,
-      129,   45,    9,    8,    8,    9,   59,   10,   42,    6,
-        6,   10,   45,   62,   10,   18,   18,   59,   18,   18,
-        6,    6,   17,   18,   62,   17,   26,   26,   28,   26,
-      111,   28,   35,   35,   28,   35,   43,   43,   44,   53,
-
-       53,   44,   53,   17,   17,  110,   17,   43,   43,   44,
-       17,   90,   44,   51,   17,   17,   51,   17,  144,  144,
-       89,   17,   27,   46,   46,   68,   46,   46,   71,   27,
-       27,   46,   65,   27,   63,   27,   27,   51,   27,   71,
-       27,   27,   47,   47,   39,   47,   47,   34,   51,   30,
-       47,   73,   27,   27,   29,   56,   24,   29,   56,   60,
-       60,   56,   73,   61,   69,   69,   61,   69,   75,   23,
-       60,   60,   21,   15,   61,   29,   29,   61,   29,   75,
-       70,   72,   29,   70,   72,   11,   29,   29,   70,   29,
-        5,    0,   72,   29,   31,   72,   31,    0,   74,    0,
-
-       76,   31,   31,   74,    0,   31,   82,   31,   31,   74,
-       31,   76,   31,   31,   74,   77,   77,   82,   77,   77,
-        0,    0,    0,   77,   31,   31,   32,   32,   32,   32,
+        1,    2,    4,  170,    2,    4,    7,    2,    4,    6,
+        6,  137,    6,    7,    7,    6,    8,   42,    9,    6,
+      136,   45,    9,    8,    8,    9,   60,   10,   42,    6,
+        6,   10,   45,   63,   10,   18,   18,   60,   18,   18,
+        6,    6,   17,   18,   63,   17,   26,   26,   28,   26,
+      117,   28,   35,   35,   28,   35,   43,   43,   44,   53,
+
+       53,   44,   53,   17,   17,  116,   17,   43,   43,   44,
+       17,   95,   44,   51,   17,   17,   51,   17,  152,  152,
+       94,   17,   27,   46,   46,   70,   46,   46,   64,   27,
+       27,   46,   67,   27,   65,   27,   27,   51,   27,   64,
+       27,   27,   47,   47,   59,   47,   47,   59,   51,   39,
+       47,   34,   27,   27,   29,   29,   59,   56,   29,   30,
+       56,   29,   29,   56,   24,   29,   72,   29,   29,   72,
+       29,   23,   29,   29,   72,   62,   29,   29,   62,   29,
+       29,   61,   61,   29,   29,   29,   62,   29,   29,   62,
+       29,   29,   61,   61,   29,   31,   73,   31,   71,   71,
+
+       21,   71,   31,   31,   75,   76,   31,   73,   31,   31,
+       76,   31,   77,   31,   31,   75,   76,   86,   15,   11,
+       86,   76,    5,   77,    0,   31,   31,   32,   32,   32,
        32,   32,   32,   32,   32,   32,   32,   32,   32,   32,
        32,   32,   32,   32,   32,   32,   32,   32,   32,   32,
        32,   32,   32,   32,   32,   32,   32,   32,   32,   32,
-       32,   32,   32,   32,   32,   32,   32,   41,   78,   78,
-       41,   78,   78,   83,   79,   79,   78,   79,   79,   85,
-       81,    0,   79,   81,   83,    0,    0,   86,   41,   41,
-       85,   41,   86,   80,   80,   41,   80,   80,   86,   41,
-
-       41,   80,   41,   86,   81,   84,   41,   57,   84,   87,
-       57,   88,   93,   94,   95,   81,   84,    0,   91,   84,
-       87,   91,   88,   93,   94,   95,   91,   96,   57,   57,
-       97,   57,   98,   99,  100,   57,    0,  101,   96,   57,
-       57,   97,   57,   98,   99,  100,   57,   64,  101,   64,
-        0,  102,    0,  103,   64,   64,  104,  105,   64,  106,
-       64,   64,  102,   64,  103,   64,   64,  104,  105,  107,
-      106,  108,  109,  112,  115,  116,  117,   64,   64,  118,
-      107,  119,  108,  109,  112,  115,  116,  117,  120,  121,
-      118,  124,  119,  125,  126,  127,  128,  131,  134,  120,
-
-      121,  135,  124,  137,  125,  126,  127,  128,  131,  134,
-      138,  141,  135,  142,  137,  148,  149,  152,  157,    0,
-      158,  138,  141,  158,  142,    0,  148,  149,  152,  157,
-      160,    0,    0,  160,    0,  158,    0,    0,    0,    0,
-        0,    0,    0,    0,    0,  160,  165,  165,  165,  165,
-      165,  165,  165,  166,    0,    0,    0,  166,  166,  167,
-      167,  167,  167,  167,  167,  167,  168,    0,  168,  169,
-      169,  169,  169,  169,  169,  169,  170,  170,  170,  170,
-      170,  170,  170,  171,  171,  171,    0,  171,  171,  171,
-      172,    0,  172,    0,  172,  172,  172,  173,  173,  173,
-
-      173,  173,    0,  173,  164,  164,  164,  164,  164,  164,
-      164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
-      164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
-      164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
-      164,  164,  164,  164,  164,  164
+       32,   32,   32,   32,   32,   32,   32,   32,   41,   74,
+       78,   41,   74,   84,   79,   79,   85,   79,   79,   85,
+       74,   78,   79,   74,   84,    0,    0,    0,   85,   41,
+       41,    0,   41,   87,   80,   80,   41,   80,   80,    0,
+
+       41,   41,   80,   41,   87,    0,    0,   41,   57,   81,
+       81,   57,   81,   81,    0,   82,   82,   81,   82,   82,
+       57,    0,   83,   82,   88,   83,   89,   88,   91,   57,
+       57,   92,   57,   57,   93,   88,   57,   89,   88,   91,
+       57,   57,   92,   57,   57,   93,   83,   57,   66,   90,
+       66,    0,   98,    0,   90,   66,   66,   83,   99,   66,
+       90,   66,   66,   98,   66,   90,   66,   66,   96,   99,
+      100,   96,  101,  102,  103,  104,   96,  105,   66,   66,
+      106,  100,  107,  101,  102,  103,  104,  108,  105,  109,
+      110,  106,  111,  107,  112,  113,  114,  115,  108,  118,
+
+      109,  110,  121,  111,  122,  112,  113,  114,  115,  123,
+      118,  124,  125,  121,  126,  122,  127,  130,  131,  132,
+      123,  133,  124,  125,  135,  126,  138,  127,  130,  131,
+      132,  134,  133,  141,  134,  135,  142,  138,  144,  145,
+      148,  149,  150,  134,  141,  150,  156,  142,  157,  144,
+      145,  148,  149,  160,  150,  165,    0,  156,  166,  157,
+      168,  166,    0,  168,  160,    0,  165,    0,    0,    0,
+        0,    0,    0,  166,    0,  168,  173,  173,  173,  173,
+      173,  173,  173,  174,    0,    0,    0,  174,  174,  175,
+      175,  175,  175,  175,  175,  175,  176,    0,  176,  177,
+
+      177,  177,  177,  177,  177,  177,  178,  178,  178,  178,
+      178,  178,  178,  179,  179,  179,    0,  179,  179,  179,
+      180,    0,  180,    0,  180,  180,  180,  181,  181,  181,
+      181,  181,    0,  181,  172,  172,  172,  172,  172,  172,
+      172,  172,  172,  172,  172,  172,  172,  172,  172,  172,
+      172,  172,  172,  172,  172,  172,  172,  172,  172,  172,
+      172,  172,  172,  172,  172,  172,  172,  172,  172,  172,
+      172,  172,  172,  172,  172,  172
     } ;
 
 /* The intent behind this definition is that it'll catch
@@ -655,6 +665,7 @@ Run flex like this:
 
 Modify cmFortranLexer.cxx:
   - remove TABs
+  - remove use of the 'register' storage class specifier
   - remove "yyscanner" argument from these methods:
       yy_fatal_error, cmFortran_yyalloc, cmFortran_yyrealloc, cmFortran_yyfree
   - remove "yyscanner = NULL" from end of cmFortran_yylex_destroy
@@ -685,7 +696,7 @@ Modify cmFortranLexer.h:
 /*--------------------------------------------------------------------------*/
 
 
-#line 678 "cmFortranLexer.cxx"
+#line 689 "cmFortranLexer.cxx"
 
 #define INITIAL 0
 #define free_fmt 1
@@ -718,8 +729,8 @@ struct yyguts_t
     size_t yy_buffer_stack_max; /**< capacity of stack. */
     YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
     char yy_hold_char;
-    int yy_n_chars;
-    int yyleng_r;
+    yy_size_t yy_n_chars;
+    yy_size_t yyleng_r;
     char *yy_c_buf_p;
     int yy_init;
     int yy_start;
@@ -766,7 +777,7 @@ FILE *cmFortran_yyget_out (yyscan_t yyscanner );
 
 void cmFortran_yyset_out  (FILE * out_str ,yyscan_t yyscanner );
 
-int cmFortran_yyget_leng (yyscan_t yyscanner );
+yy_size_t cmFortran_yyget_leng (yyscan_t yyscanner );
 
 char *cmFortran_yyget_text (yyscan_t yyscanner );
 
@@ -774,6 +785,10 @@ int cmFortran_yyget_lineno (yyscan_t yyscanner );
 
 void cmFortran_yyset_lineno (int line_number ,yyscan_t yyscanner );
 
+int cmFortran_yyget_column  (yyscan_t yyscanner );
+
+void cmFortran_yyset_column (int column_no ,yyscan_t yyscanner );
+
 /* Macros after this point can all be overridden by user definitions in
  * section 1.
  */
@@ -918,11 +933,6 @@ YY_DECL
         int yy_act;
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
 
-#line 71 "cmFortranLexer.in.l"
-
-
-#line 914 "cmFortranLexer.cxx"
-
         if ( !yyg->yy_init )
                 {
                 yyg->yy_init = 1;
@@ -949,6 +959,12 @@ YY_DECL
                 cmFortran_yy_load_buffer_state(yyscanner );
                 }
 
+        {
+#line 72 "cmFortranLexer.in.l"
+
+
+#line 956 "cmFortranLexer.cxx"
+
         for(;;)             /* loops until end-of-file is reached */
                 {
                 yy_cp = yyg->yy_c_buf_p;
@@ -966,7 +982,7 @@ YY_DECL
 yy_match:
                 do
                         {
-                        YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+                        YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
                         if ( yy_accept[yy_current_state] )
                                 {
                                 yyg->yy_last_accepting_state = yy_current_state;
@@ -975,13 +991,13 @@ yy_match:
                         while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
                                 {
                                 yy_current_state = (int) yy_def[yy_current_state];
-                                if ( yy_current_state >= 165 )
+                                if ( yy_current_state >= 173 )
                                         yy_c = yy_meta[(unsigned int) yy_c];
                                 }
                         yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
                         ++yy_cp;
                         }
-                while ( yy_base[yy_current_state] != 505 );
+                while ( yy_base[yy_current_state] != 535 );
 
 yy_find_action:
                 yy_act = yy_accept[yy_current_state];
@@ -1007,7 +1023,7 @@ do_action:      /* This label is used only to access EOF actions. */
 
 case 1:
 YY_RULE_SETUP
-#line 73 "cmFortranLexer.in.l"
+#line 74 "cmFortranLexer.in.l"
 {
   cmFortranParser_StringStart(yyextra);
   cmFortranParser_SetOldStartcond(yyextra, YY_START);
@@ -1016,7 +1032,7 @@ YY_RULE_SETUP
         YY_BREAK
 case 2:
 YY_RULE_SETUP
-#line 79 "cmFortranLexer.in.l"
+#line 80 "cmFortranLexer.in.l"
 {
   cmFortranParser_StringStart(yyextra);
   cmFortranParser_SetOldStartcond(yyextra, YY_START);
@@ -1024,10 +1040,10 @@ YY_RULE_SETUP
 }
         YY_BREAK
 case 3:
-#line 86 "cmFortranLexer.in.l"
+#line 87 "cmFortranLexer.in.l"
 case 4:
 YY_RULE_SETUP
-#line 86 "cmFortranLexer.in.l"
+#line 87 "cmFortranLexer.in.l"
 {
   BEGIN(cmFortranParser_GetOldStartcond(yyextra) );
   yylvalp->string = strdup(cmFortranParser_StringEnd(yyextra));
@@ -1035,17 +1051,17 @@ YY_RULE_SETUP
 }
 case 5:
 /* rule 5 can match eol */
-#line 93 "cmFortranLexer.in.l"
+#line 94 "cmFortranLexer.in.l"
 case 6:
 /* rule 6 can match eol */
 YY_RULE_SETUP
-#line 93 "cmFortranLexer.in.l"
+#line 94 "cmFortranLexer.in.l"
 /* Ignore (continued strings, free fmt) */
         YY_BREAK
 case 7:
 /* rule 7 can match eol */
 YY_RULE_SETUP
-#line 95 "cmFortranLexer.in.l"
+#line 96 "cmFortranLexer.in.l"
 {
   if (cmFortranParser_GetOldStartcond(yyextra) == fixed_fmt)
     ; /* Ignore (cont. strings, fixed fmt) */
@@ -1058,7 +1074,7 @@ YY_RULE_SETUP
 case 8:
 /* rule 8 can match eol */
 YY_RULE_SETUP
-#line 105 "cmFortranLexer.in.l"
+#line 106 "cmFortranLexer.in.l"
 {
   unput ('\n');
   BEGIN(INITIAL);
@@ -1066,7 +1082,7 @@ YY_RULE_SETUP
 }
 case 9:
 YY_RULE_SETUP
-#line 111 "cmFortranLexer.in.l"
+#line 112 "cmFortranLexer.in.l"
 {
   cmFortranParser_StringAppend(yyextra, yytext[0]);
 }
@@ -1074,165 +1090,169 @@ YY_RULE_SETUP
 case 10:
 /* rule 10 can match eol */
 YY_RULE_SETUP
-#line 115 "cmFortranLexer.in.l"
+#line 116 "cmFortranLexer.in.l"
 { return EOSTMT; } /* Treat comments like */
 case 11:
 /* rule 11 can match eol */
 YY_RULE_SETUP
-#line 116 "cmFortranLexer.in.l"
+#line 117 "cmFortranLexer.in.l"
 { return EOSTMT; } /* empty lines */
 case 12:
-/* rule 12 can match eol */
 YY_RULE_SETUP
-#line 118 "cmFortranLexer.in.l"
+#line 119 "cmFortranLexer.in.l"
+{ return CPP_LINE_DIRECTIVE; }
+case 13:
+/* rule 13 can match eol */
+YY_RULE_SETUP
+#line 120 "cmFortranLexer.in.l"
 {
   yytext[yyleng-1] = 0;
   yylvalp->string = strdup(strchr(yytext, '<')+1);
   return CPP_INCLUDE_ANGLE;
 }
-case 13:
-YY_RULE_SETUP
-#line 123 "cmFortranLexer.in.l"
-{ return CPP_INCLUDE; }
 case 14:
 YY_RULE_SETUP
-#line 124 "cmFortranLexer.in.l"
-{ return F90PPR_INCLUDE; }
+#line 125 "cmFortranLexer.in.l"
+{ return CPP_INCLUDE; }
 case 15:
 YY_RULE_SETUP
-#line 125 "cmFortranLexer.in.l"
-{ return COCO_INCLUDE; }
+#line 126 "cmFortranLexer.in.l"
+{ return F90PPR_INCLUDE; }
 case 16:
 YY_RULE_SETUP
 #line 127 "cmFortranLexer.in.l"
-{ return CPP_DEFINE; }
+{ return COCO_INCLUDE; }
 case 17:
 YY_RULE_SETUP
-#line 128 "cmFortranLexer.in.l"
-{ return F90PPR_DEFINE; }
+#line 129 "cmFortranLexer.in.l"
+{ return CPP_DEFINE; }
 case 18:
 YY_RULE_SETUP
 #line 130 "cmFortranLexer.in.l"
-{ return CPP_UNDEF; }
+{ return F90PPR_DEFINE; }
 case 19:
 YY_RULE_SETUP
-#line 131 "cmFortranLexer.in.l"
-{ return F90PPR_UNDEF; }
+#line 132 "cmFortranLexer.in.l"
+{ return CPP_UNDEF; }
 case 20:
 YY_RULE_SETUP
 #line 133 "cmFortranLexer.in.l"
-{ return CPP_IFDEF; }
+{ return F90PPR_UNDEF; }
 case 21:
 YY_RULE_SETUP
-#line 134 "cmFortranLexer.in.l"
-{ return CPP_IFNDEF; }
+#line 135 "cmFortranLexer.in.l"
+{ return CPP_IFDEF; }
 case 22:
 YY_RULE_SETUP
-#line 135 "cmFortranLexer.in.l"
-{ return CPP_IF; }
+#line 136 "cmFortranLexer.in.l"
+{ return CPP_IFNDEF; }
 case 23:
 YY_RULE_SETUP
-#line 136 "cmFortranLexer.in.l"
-{ return CPP_ELIF; }
+#line 137 "cmFortranLexer.in.l"
+{ return CPP_IF; }
 case 24:
 YY_RULE_SETUP
-#line 137 "cmFortranLexer.in.l"
-{ return CPP_ELSE; }
+#line 138 "cmFortranLexer.in.l"
+{ return CPP_ELIF; }
 case 25:
 YY_RULE_SETUP
-#line 138 "cmFortranLexer.in.l"
-{ return CPP_ENDIF; }
+#line 139 "cmFortranLexer.in.l"
+{ return CPP_ELSE; }
 case 26:
 YY_RULE_SETUP
 #line 140 "cmFortranLexer.in.l"
-{ return F90PPR_IFDEF; }
+{ return CPP_ENDIF; }
 case 27:
 YY_RULE_SETUP
-#line 141 "cmFortranLexer.in.l"
-{ return F90PPR_IFNDEF; }
+#line 142 "cmFortranLexer.in.l"
+{ return F90PPR_IFDEF; }
 case 28:
 YY_RULE_SETUP
-#line 142 "cmFortranLexer.in.l"
-{ return F90PPR_IF; }
+#line 143 "cmFortranLexer.in.l"
+{ return F90PPR_IFNDEF; }
 case 29:
 YY_RULE_SETUP
-#line 143 "cmFortranLexer.in.l"
-{ return F90PPR_ELIF; }
+#line 144 "cmFortranLexer.in.l"
+{ return F90PPR_IF; }
 case 30:
 YY_RULE_SETUP
-#line 144 "cmFortranLexer.in.l"
-{ return F90PPR_ELSE; }
+#line 145 "cmFortranLexer.in.l"
+{ return F90PPR_ELIF; }
 case 31:
 YY_RULE_SETUP
-#line 145 "cmFortranLexer.in.l"
-{ return F90PPR_ENDIF; }
-/* Line continuations, possible involving comments.  */
+#line 146 "cmFortranLexer.in.l"
+{ return F90PPR_ELSE; }
 case 32:
-/* rule 32 can match eol */
 YY_RULE_SETUP
-#line 148 "cmFortranLexer.in.l"
-
-        YY_BREAK
+#line 147 "cmFortranLexer.in.l"
+{ return F90PPR_ENDIF; }
+/* Line continuations, possible involving comments.  */
 case 33:
 /* rule 33 can match eol */
 YY_RULE_SETUP
-#line 149 "cmFortranLexer.in.l"
+#line 150 "cmFortranLexer.in.l"
 
         YY_BREAK
 case 34:
+/* rule 34 can match eol */
 YY_RULE_SETUP
 #line 151 "cmFortranLexer.in.l"
-{ return COMMA; }
+
+        YY_BREAK
 case 35:
 YY_RULE_SETUP
 #line 153 "cmFortranLexer.in.l"
-{ return DCOLON; }
+{ return COMMA; }
 case 36:
-/* rule 36 can match eol */
 YY_RULE_SETUP
 #line 155 "cmFortranLexer.in.l"
-{ return GARBAGE; }
+{ return DCOLON; }
 case 37:
+/* rule 37 can match eol */
 YY_RULE_SETUP
 #line 157 "cmFortranLexer.in.l"
-{ return ASSIGNMENT_OP; }
+{ return GARBAGE; }
 case 38:
 YY_RULE_SETUP
 #line 159 "cmFortranLexer.in.l"
+{ return ASSIGNMENT_OP; }
+case 39:
+YY_RULE_SETUP
+#line 161 "cmFortranLexer.in.l"
 {
   yylvalp->string = strdup(yytext);
   return WORD;
 }
-case 39:
-YY_RULE_SETUP
-#line 164 "cmFortranLexer.in.l"
-{ return GARBAGE; }
 case 40:
-/* rule 40 can match eol */
 YY_RULE_SETUP
 #line 166 "cmFortranLexer.in.l"
-{ return EOSTMT; }
+{ return GARBAGE; }
 case 41:
+/* rule 41 can match eol */
 YY_RULE_SETUP
-#line 169 "cmFortranLexer.in.l"
-/* Ignore */
-        YY_BREAK
+#line 168 "cmFortranLexer.in.l"
+{ return EOSTMT; }
 case 42:
-/* rule 42 can match eol */
 YY_RULE_SETUP
-#line 170 "cmFortranLexer.in.l"
-/* Ignore line-endings preceeded by \ */
+#line 171 "cmFortranLexer.in.l"
+/* Ignore */
         YY_BREAK
 case 43:
+/* rule 43 can match eol */
 YY_RULE_SETUP
 #line 172 "cmFortranLexer.in.l"
+/* Ignore line-endings preceeded by \ */
+        YY_BREAK
+case 44:
+YY_RULE_SETUP
+#line 174 "cmFortranLexer.in.l"
 { return *yytext; }
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(free_fmt):
 case YY_STATE_EOF(fixed_fmt):
 case YY_STATE_EOF(str_sq):
 case YY_STATE_EOF(str_dq):
-#line 174 "cmFortranLexer.in.l"
+#line 176 "cmFortranLexer.in.l"
 {
   if(!cmFortranParser_FilePop(yyextra) )
     {
@@ -1240,12 +1260,12 @@ case YY_STATE_EOF(str_dq):
     }
 }
         YY_BREAK
-case 44:
+case 45:
 YY_RULE_SETUP
-#line 181 "cmFortranLexer.in.l"
+#line 183 "cmFortranLexer.in.l"
 ECHO;
         YY_BREAK
-#line 1270 "cmFortranLexer.cxx"
+#line 1291 "cmFortranLexer.cxx"
 
         case YY_END_OF_BUFFER:
                 {
@@ -1374,6 +1394,7 @@ ECHO;
                         "fatal flex scanner internal error--no action found" );
         } /* end of action switch */
                 } /* end of scanning one token */
+        } /* end of user's declarations */
 } /* end of cmFortran_yylex */
 
 /* yy_get_next_buffer - try to read in a new buffer
@@ -1430,21 +1451,21 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
 
         else
                 {
-                        int num_to_read =
+                        yy_size_t num_to_read =
                         YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
 
                 while ( num_to_read <= 0 )
                         { /* Not enough room in the buffer - grow it. */
 
                         /* just a shorter name for the current buffer */
-                        YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
+                        YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
 
                         int yy_c_buf_p_offset =
                                 (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
 
                         if ( b->yy_is_our_buffer )
                                 {
-                                int new_size = b->yy_buf_size * 2;
+                                yy_size_t new_size = b->yy_buf_size * 2;
 
                                 if ( new_size <= 0 )
                                         b->yy_buf_size += b->yy_buf_size / 8;
@@ -1475,7 +1496,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
 
                 /* Read in more data. */
                 YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
-                        yyg->yy_n_chars, (size_t) num_to_read );
+                        yyg->yy_n_chars, num_to_read );
 
                 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
                 }
@@ -1538,7 +1559,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
                 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
                         {
                         yy_current_state = (int) yy_def[yy_current_state];
-                        if ( yy_current_state >= 165 )
+                        if ( yy_current_state >= 173 )
                                 yy_c = yy_meta[(unsigned int) yy_c];
                         }
                 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@@ -1567,12 +1588,13 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
         while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
                 {
                 yy_current_state = (int) yy_def[yy_current_state];
-                if ( yy_current_state >= 165 )
+                if ( yy_current_state >= 173 )
                         yy_c = yy_meta[(unsigned int) yy_c];
                 }
         yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
-        yy_is_jam = (yy_current_state == 164);
+        yy_is_jam = (yy_current_state == 172);
 
+        (void)yyg;
         return yy_is_jam ? 0 : yy_current_state;
 }
 
@@ -1589,7 +1611,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
         if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
                 { /* need to shift things up to make room */
                 /* +2 for EOB chars. */
-                int number_to_move = yyg->yy_n_chars + 2;
+                yy_size_t number_to_move = yyg->yy_n_chars + 2;
                 char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
                                         YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
                 char *source =
@@ -1639,7 +1661,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
 
                 else
                         { /* need more input */
-                        int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
+                        yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
                         ++yyg->yy_c_buf_p;
 
                         switch ( yy_get_next_buffer( yyscanner ) )
@@ -1805,10 +1827,6 @@ static void cmFortran_yy_load_buffer_state  (yyscan_t yyscanner)
         cmFortran_yyfree((void *) b ,yyscanner );
 }
 
-#ifndef __cplusplus
-extern int isatty (int );
-#endif /* __cplusplus */
-
 /* Initializes or reinitializes a buffer.
  * This function is sometimes called more than once on the same buffer,
  * such as during a cmFortran_yyrestart() or at EOF.
@@ -1925,7 +1943,7 @@ void cmFortran_yypop_buffer_state (yyscan_t yyscanner)
  */
 static void cmFortran_yyensure_buffer_stack (yyscan_t yyscanner)
 {
-        int num_to_alloc;
+        yy_size_t num_to_alloc;
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
 
         if (!yyg->yy_buffer_stack) {
@@ -2023,12 +2041,12 @@ YY_BUFFER_STATE cmFortran_yy_scan_string (yyconst char * yystr , yyscan_t yyscan
  * @param yyscanner The scanner object.
  * @return the newly allocated buffer state object.
  */
-YY_BUFFER_STATE cmFortran_yy_scan_bytes  (yyconst char * yybytes, int  _yybytes_len , yyscan_t yyscanner)
+YY_BUFFER_STATE cmFortran_yy_scan_bytes  (yyconst char * yybytes, yy_size_t  _yybytes_len , yyscan_t yyscanner)
 {
         YY_BUFFER_STATE b;
         char *buf;
         yy_size_t n;
-        int i;
+        yy_size_t i;
 
         /* Get memory for full buffer, including space for trailing EOB's. */
         n = _yybytes_len + 2;
@@ -2138,7 +2156,7 @@ FILE *cmFortran_yyget_out  (yyscan_t yyscanner)
 /** Get the length of the current token.
  * @param yyscanner The scanner object.
  */
-int cmFortran_yyget_leng  (yyscan_t yyscanner)
+yy_size_t cmFortran_yyget_leng  (yyscan_t yyscanner)
 {
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
     return yyleng;
@@ -2174,7 +2192,7 @@ void cmFortran_yyset_lineno (int  line_number , yyscan_t yyscanner)
 
         /* lineno is only valid if an input buffer exists. */
         if (! YY_CURRENT_BUFFER )
-           yy_fatal_error( "cmFortran_yyset_lineno called with no buffer" , yyscanner);
+           YY_FATAL_ERROR( "cmFortran_yyset_lineno called with no buffer" );
 
     yylineno = line_number;
 }
@@ -2189,7 +2207,7 @@ void cmFortran_yyset_column (int  column_no , yyscan_t yyscanner)
 
         /* column is only valid if an input buffer exists. */
         if (! YY_CURRENT_BUFFER )
-           yy_fatal_error( "cmFortran_yyset_column called with no buffer" , yyscanner);
+           YY_FATAL_ERROR( "cmFortran_yyset_column called with no buffer" );
 
     yycolumn = column_no;
 }
@@ -2400,7 +2418,7 @@ void cmFortran_yyfree (void * ptr , yyscan_t)
 
 #define YYTABLES_NAME "yytables"
 
-#line 181 "cmFortranLexer.in.l"
+#line 182 "cmFortranLexer.in.l"
 
 
 
diff --git a/Source/cmFortranLexer.h b/Source/cmFortranLexer.h
index c67e332..b9ff0dc 100644
--- a/Source/cmFortranLexer.h
+++ b/Source/cmFortranLexer.h
@@ -1,6 +1,6 @@
 /*============================================================================
   CMake - Cross Platform Makefile Generator
-  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
+  Copyright 2000-2015 Kitware, Inc., Insight Software Consortium
 
   Distributed under the OSI-approved BSD License (the "License");
   see accompanying file Copyright.txt for details.
@@ -20,7 +20,7 @@
 #define FLEX_SCANNER
 #define YY_FLEX_MAJOR_VERSION 2
 #define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 35
+#define YY_FLEX_SUBMINOR_VERSION 39
 #if YY_FLEX_SUBMINOR_VERSION > 0
 #define FLEX_BETA
 #endif
@@ -177,7 +177,7 @@ struct yy_buffer_state
         /* Number of characters read into yy_ch_buf, not including EOB
          * characters.
          */
-        int yy_n_chars;
+        yy_size_t yy_n_chars;
 
         /* Whether we "own" the buffer - i.e., we know we created it,
          * and can realloc() it to grow it, and should free() it to
@@ -221,7 +221,7 @@ void cmFortran_yypop_buffer_state (yyscan_t yyscanner );
 
 YY_BUFFER_STATE cmFortran_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
 YY_BUFFER_STATE cmFortran_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
-YY_BUFFER_STATE cmFortran_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
+YY_BUFFER_STATE cmFortran_yy_scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner );
 
 void *cmFortran_yyalloc (yy_size_t ,yyscan_t yyscanner );
 void *cmFortran_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
@@ -229,7 +229,7 @@ void cmFortran_yyfree (void * ,yyscan_t yyscanner );
 
 /* Begin user sect3 */
 
-#define cmFortran_yywrap(n) 1
+#define cmFortran_yywrap(yyscanner) 1
 #define YY_SKIP_YYWRAP
 
 #define yytext_ptr yytext_r
@@ -272,7 +272,7 @@ FILE *cmFortran_yyget_out (yyscan_t yyscanner );
 
 void cmFortran_yyset_out  (FILE * out_str ,yyscan_t yyscanner );
 
-int cmFortran_yyget_leng (yyscan_t yyscanner );
+yy_size_t cmFortran_yyget_leng (yyscan_t yyscanner );
 
 char *cmFortran_yyget_text (yyscan_t yyscanner );
 
@@ -280,6 +280,10 @@ int cmFortran_yyget_lineno (yyscan_t yyscanner );
 
 void cmFortran_yyset_lineno (int line_number ,yyscan_t yyscanner );
 
+int cmFortran_yyget_column  (yyscan_t yyscanner );
+
+void cmFortran_yyset_column (int column_no ,yyscan_t yyscanner );
+
 /* Macros after this point can all be overridden by user definitions in
  * section 1.
  */
diff --git a/Source/cmFortranLexer.in.l b/Source/cmFortranLexer.in.l
index 03fa90c..53984bb 100644
--- a/Source/cmFortranLexer.in.l
+++ b/Source/cmFortranLexer.in.l
@@ -1,7 +1,7 @@
 %{
 /*============================================================================
   CMake - Cross Platform Makefile Generator
-  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
+  Copyright 2000-2015 Kitware, Inc., Insight Software Consortium
 
   Distributed under the OSI-approved BSD License (the "License");
   see accompanying file Copyright.txt for details.
@@ -116,6 +116,7 @@ Modify cmFortranLexer.h:
 !.*\n                   { return EOSTMT; } /* Treat comments like */
 <fixed_fmt>^[cC*dD].*\n { return EOSTMT; } /* empty lines */
 
+^[ \t]*#([ \t]*line)?[ \t]*[0-9]+[ \t]* { return CPP_LINE_DIRECTIVE; }
 ^[ \t]*#[ \t]*include[ \t]*<[^>]+> {
   yytext[yyleng-1] = 0;
   yylvalp->string = strdup(strchr(yytext, '<')+1);
diff --git a/Source/cmFortranParser.cxx b/Source/cmFortranParser.cxx
index 0230f02..21a6443 100644
--- a/Source/cmFortranParser.cxx
+++ b/Source/cmFortranParser.cxx
@@ -72,7 +72,7 @@
 
 /*============================================================================
   CMake - Cross Platform Makefile Generator
-  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
+  Copyright 2000-2015 Kitware, Inc., Insight Software Consortium
 
   Distributed under the OSI-approved BSD License (the "License");
   see accompanying file Copyright.txt for details.
@@ -177,64 +177,66 @@ extern int cmFortran_yydebug;
     EOSTMT = 258,
     ASSIGNMENT_OP = 259,
     GARBAGE = 260,
-    CPP_INCLUDE = 261,
-    F90PPR_INCLUDE = 262,
-    COCO_INCLUDE = 263,
-    F90PPR_DEFINE = 264,
-    CPP_DEFINE = 265,
-    F90PPR_UNDEF = 266,
-    CPP_UNDEF = 267,
-    CPP_IFDEF = 268,
-    CPP_IFNDEF = 269,
-    CPP_IF = 270,
-    CPP_ELSE = 271,
-    CPP_ELIF = 272,
-    CPP_ENDIF = 273,
-    F90PPR_IFDEF = 274,
-    F90PPR_IFNDEF = 275,
-    F90PPR_IF = 276,
-    F90PPR_ELSE = 277,
-    F90PPR_ELIF = 278,
-    F90PPR_ENDIF = 279,
-    COMMA = 280,
-    DCOLON = 281,
-    CPP_TOENDL = 282,
-    UNTERMINATED_STRING = 283,
-    STRING = 284,
-    WORD = 285,
-    CPP_INCLUDE_ANGLE = 286
+    CPP_LINE_DIRECTIVE = 261,
+    CPP_INCLUDE = 262,
+    F90PPR_INCLUDE = 263,
+    COCO_INCLUDE = 264,
+    F90PPR_DEFINE = 265,
+    CPP_DEFINE = 266,
+    F90PPR_UNDEF = 267,
+    CPP_UNDEF = 268,
+    CPP_IFDEF = 269,
+    CPP_IFNDEF = 270,
+    CPP_IF = 271,
+    CPP_ELSE = 272,
+    CPP_ELIF = 273,
+    CPP_ENDIF = 274,
+    F90PPR_IFDEF = 275,
+    F90PPR_IFNDEF = 276,
+    F90PPR_IF = 277,
+    F90PPR_ELSE = 278,
+    F90PPR_ELIF = 279,
+    F90PPR_ENDIF = 280,
+    COMMA = 281,
+    DCOLON = 282,
+    CPP_TOENDL = 283,
+    UNTERMINATED_STRING = 284,
+    STRING = 285,
+    WORD = 286,
+    CPP_INCLUDE_ANGLE = 287
   };
 #endif
 /* Tokens.  */
 #define EOSTMT 258
 #define ASSIGNMENT_OP 259
 #define GARBAGE 260
-#define CPP_INCLUDE 261
-#define F90PPR_INCLUDE 262
-#define COCO_INCLUDE 263
-#define F90PPR_DEFINE 264
-#define CPP_DEFINE 265
-#define F90PPR_UNDEF 266
-#define CPP_UNDEF 267
-#define CPP_IFDEF 268
-#define CPP_IFNDEF 269
-#define CPP_IF 270
-#define CPP_ELSE 271
-#define CPP_ELIF 272
-#define CPP_ENDIF 273
-#define F90PPR_IFDEF 274
-#define F90PPR_IFNDEF 275
-#define F90PPR_IF 276
-#define F90PPR_ELSE 277
-#define F90PPR_ELIF 278
-#define F90PPR_ENDIF 279
-#define COMMA 280
-#define DCOLON 281
-#define CPP_TOENDL 282
-#define UNTERMINATED_STRING 283
-#define STRING 284
-#define WORD 285
-#define CPP_INCLUDE_ANGLE 286
+#define CPP_LINE_DIRECTIVE 261
+#define CPP_INCLUDE 262
+#define F90PPR_INCLUDE 263
+#define COCO_INCLUDE 264
+#define F90PPR_DEFINE 265
+#define CPP_DEFINE 266
+#define F90PPR_UNDEF 267
+#define CPP_UNDEF 268
+#define CPP_IFDEF 269
+#define CPP_IFNDEF 270
+#define CPP_IF 271
+#define CPP_ELSE 272
+#define CPP_ELIF 273
+#define CPP_ENDIF 274
+#define F90PPR_IFDEF 275
+#define F90PPR_IFNDEF 276
+#define F90PPR_IF 277
+#define F90PPR_ELSE 278
+#define F90PPR_ELIF 279
+#define F90PPR_ENDIF 280
+#define COMMA 281
+#define DCOLON 282
+#define CPP_TOENDL 283
+#define UNTERMINATED_STRING 284
+#define STRING 285
+#define WORD 286
+#define CPP_INCLUDE_ANGLE 287
 
 /* Value type.  */
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
@@ -245,7 +247,7 @@ union YYSTYPE
 
   char* string;
 
-#line 249 "cmFortranParser.cxx" /* yacc.c:355  */
+#line 251 "cmFortranParser.cxx" /* yacc.c:355  */
 };
 # define YYSTYPE_IS_TRIVIAL 1
 # define YYSTYPE_IS_DECLARED 1
@@ -259,7 +261,7 @@ int cmFortran_yyparse (yyscan_t yyscanner);
 
 /* Copy the second part of user declarations.  */
 
-#line 263 "cmFortranParser.cxx" /* yacc.c:358  */
+#line 265 "cmFortranParser.cxx" /* yacc.c:358  */
 
 #ifdef short
 # undef short
@@ -501,21 +503,21 @@ union yyalloc
 /* YYFINAL -- State number of the termination state.  */
 #define YYFINAL  2
 /* YYLAST -- Last index in YYTABLE.  */
-#define YYLAST   276
+#define YYLAST   290
 
 /* YYNTOKENS -- Number of terminals.  */
-#define YYNTOKENS  32
+#define YYNTOKENS  33
 /* YYNNTS -- Number of nonterminals.  */
 #define YYNNTS  16
 /* YYNRULES -- Number of rules.  */
-#define YYNRULES  53
+#define YYNRULES  54
 /* YYNSTATES -- Number of states.  */
-#define YYNSTATES  97
+#define YYNSTATES  101
 
 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
    by yylex, with out-of-bounds checking.  */
 #define YYUNDEFTOK  2
-#define YYMAXUTOK   286
+#define YYMAXUTOK   287
 
 #define YYTRANSLATE(YYX)                                                \
   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
@@ -552,19 +554,19 @@ static const yytype_uint8 yytranslate[] =
        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
-      25,    26,    27,    28,    29,    30,    31
+      25,    26,    27,    28,    29,    30,    31,    32
 };
 
 #if YYDEBUG
   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
 static const yytype_uint16 yyrline[] =
 {
-       0,   103,   103,   103,   105,   105,   107,   113,   123,   153,
-     164,   177,   188,   195,   202,   208,   214,   220,   226,   231,
-     236,   241,   246,   250,   251,   252,   257,   257,   257,   258,
-     258,   259,   259,   260,   260,   261,   261,   262,   262,   263,
-     263,   264,   264,   265,   265,   266,   266,   269,   270,   271,
-     272,   273,   274,   275
+       0,   104,   104,   104,   106,   106,   108,   114,   124,   154,
+     165,   178,   189,   196,   203,   210,   216,   222,   228,   234,
+     239,   244,   249,   254,   258,   259,   260,   265,   265,   265,
+     266,   266,   267,   267,   268,   268,   269,   269,   270,   270,
+     271,   271,   272,   272,   273,   273,   274,   274,   277,   278,
+     279,   280,   281,   282,   283
 };
 #endif
 
@@ -574,14 +576,15 @@ static const yytype_uint16 yyrline[] =
 static const char *const yytname[] =
 {
   "$end", "error", "$undefined", "EOSTMT", "ASSIGNMENT_OP", "GARBAGE",
-  "CPP_INCLUDE", "F90PPR_INCLUDE", "COCO_INCLUDE", "F90PPR_DEFINE",
-  "CPP_DEFINE", "F90PPR_UNDEF", "CPP_UNDEF", "CPP_IFDEF", "CPP_IFNDEF",
-  "CPP_IF", "CPP_ELSE", "CPP_ELIF", "CPP_ENDIF", "F90PPR_IFDEF",
-  "F90PPR_IFNDEF", "F90PPR_IF", "F90PPR_ELSE", "F90PPR_ELIF",
-  "F90PPR_ENDIF", "COMMA", "DCOLON", "CPP_TOENDL", "UNTERMINATED_STRING",
-  "STRING", "WORD", "CPP_INCLUDE_ANGLE", "$accept", "code", "stmt",
-  "assignment_stmt", "keyword_stmt", "include", "define", "undef", "ifdef",
-  "ifndef", "if", "elif", "else", "endif", "other", "misc_code", YY_NULLPTR
+  "CPP_LINE_DIRECTIVE", "CPP_INCLUDE", "F90PPR_INCLUDE", "COCO_INCLUDE",
+  "F90PPR_DEFINE", "CPP_DEFINE", "F90PPR_UNDEF", "CPP_UNDEF", "CPP_IFDEF",
+  "CPP_IFNDEF", "CPP_IF", "CPP_ELSE", "CPP_ELIF", "CPP_ENDIF",
+  "F90PPR_IFDEF", "F90PPR_IFNDEF", "F90PPR_IF", "F90PPR_ELSE",
+  "F90PPR_ELIF", "F90PPR_ENDIF", "COMMA", "DCOLON", "CPP_TOENDL",
+  "UNTERMINATED_STRING", "STRING", "WORD", "CPP_INCLUDE_ANGLE", "$accept",
+  "code", "stmt", "assignment_stmt", "keyword_stmt", "include", "define",
+  "undef", "ifdef", "ifndef", "if", "elif", "else", "endif", "other",
+  "misc_code", YY_NULLPTR
 };
 #endif
 
@@ -593,14 +596,14 @@ static const yytype_uint16 yytoknum[] =
        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
      275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
-     285,   286
+     285,   286,   287
 };
 # endif
 
-#define YYPACT_NINF -29
+#define YYPACT_NINF -30
 
 #define yypact_value_is_default(Yystate) \
-  (!!((Yystate) == (-29)))
+  (!!((Yystate) == (-30)))
 
 #define YYTABLE_NINF -1
 
@@ -611,16 +614,17 @@ static const yytype_uint16 yytoknum[] =
      STATE-NUM.  */
 static const yytype_int16 yypact[] =
 {
-     -29,    39,   -29,   -29,   -29,   -29,   -29,   -29,   -29,   -29,
-     -29,   -29,   -29,   -29,   -29,   -29,   -29,   -29,   -29,   -29,
-     -29,   -29,   -29,   -29,   -29,   246,   -29,   -29,   -29,   -29,
-     -28,   -27,   -22,   -17,   -16,   -29,   -29,   -29,   -29,     2,
-     -29,   -29,   -29,   -13,   -12,   -29,   -29,    61,   -29,   -29,
-     -29,   -29,   -29,    68,    74,    80,   108,   -29,   -29,   -29,
-     -29,   -29,   -29,   -29,   -29,   -29,   114,   120,   -24,   -29,
-     126,   154,   -29,   160,   166,   172,   200,   206,   -29,   -29,
-     -29,   -29,   -29,   -29,    -9,   212,   -29,   -29,   -29,   -29,
-     -29,   -29,   -29,   -29,   -29,   218,   -29
+     -30,    41,   -30,   -30,   -30,   -30,   -29,   -30,   -30,   -30,
+     -30,   -30,   -30,   -30,   -30,   -30,   -30,   -30,   -30,   -30,
+     -30,   -30,   -30,   -30,   -30,   -30,   259,   -30,   -30,   -30,
+     -30,   -28,   -23,   -18,   -16,   -13,   -30,   -30,   -30,   -30,
+       2,   -30,   -30,   -30,   -30,   -12,    -9,   -30,   -30,    64,
+     -30,   -30,   -30,   -30,   -30,    71,    77,    83,   112,   -30,
+     -30,   -30,   -30,   -30,   -30,   -30,   -30,   -30,   118,   124,
+     130,   -24,   -30,   159,   165,   -30,   171,   177,   206,   212,
+     218,   -30,   -30,   -30,   -30,   -30,   -30,   -30,    -1,   224,
+     -30,   -30,   -30,   -30,   -30,   -30,   -30,   -30,   -30,   253,
+     -30
 };
 
   /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
@@ -628,30 +632,31 @@ static const yytype_int16 yypact[] =
      means the default is an error.  */
 static const yytype_uint8 yydefact[] =
 {
-       2,     0,     1,    25,    24,    45,    26,    27,    28,    30,
-      29,    32,    31,    33,    35,    37,    41,    39,    43,    34,
-      36,    38,    42,    40,    44,     0,    45,     3,     5,     4,
-       0,     0,     0,     0,     0,    45,    45,    45,    45,     0,
-       7,    45,    45,     0,     0,    45,    45,     0,    45,    45,
-      45,    45,    45,     0,     0,     0,     0,    23,    50,    49,
-      52,    51,    53,    48,    47,    46,     0,     0,     0,    45,
-       0,     0,    12,     0,     0,     0,     0,     0,    18,    19,
-      20,    21,     6,    22,     0,     0,    11,     8,    13,    14,
-      15,    16,    17,    45,     9,     0,    10
+       2,     0,     1,    26,    25,    46,     0,    27,    28,    29,
+      31,    30,    33,    32,    34,    36,    38,    42,    40,    44,
+      35,    37,    39,    43,    41,    45,     0,    46,     3,     5,
+       4,     0,     0,     0,     0,     0,    46,    46,    46,    46,
+       0,    46,     7,    46,    46,     0,     0,    46,    46,     0,
+      46,    46,    46,    46,    46,     0,     0,     0,     0,    24,
+      51,    50,    53,    52,    54,    49,    48,    47,     0,     0,
+       0,     0,    46,     0,     0,    13,     0,     0,     0,     0,
+       0,    19,    20,    21,    22,    12,     6,    23,     0,     0,
+      11,     8,    14,    15,    16,    17,    18,    46,     9,     0,
+      10
 };
 
   /* YYPGOTO[NTERM-NUM].  */
 static const yytype_int8 yypgoto[] =
 {
-     -29,   -29,   -29,   -29,   -29,   -29,   -29,   -29,   -29,   -29,
-     -29,   -29,   -29,   -29,   -26,   -29
+     -30,   -30,   -30,   -30,   -30,   -30,   -30,   -30,   -30,   -30,
+     -30,   -30,   -30,   -30,   -27,   -30
 };
 
   /* YYDEFGOTO[NTERM-NUM].  */
 static const yytype_int8 yydefgoto[] =
 {
-      -1,     1,    27,    28,    29,    30,    31,    32,    33,    34,
-      35,    36,    37,    38,    39,    65
+      -1,     1,    28,    29,    30,    31,    32,    33,    34,    35,
+      36,    37,    38,    39,    40,    67
 };
 
   /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
@@ -659,104 +664,109 @@ static const yytype_int8 yydefgoto[] =
      number is the opposite.  If YYTABLE_NINF, syntax error.  */
 static const yytype_uint8 yytable[] =
 {
-      47,    48,    84,    49,     0,    57,    58,    59,    50,    53,
-      54,    55,    56,    51,    52,    66,    67,    68,    69,    70,
-      71,    93,    73,    74,    75,    76,    77,    60,    61,     0,
-      62,    63,    64,     0,     0,     0,     0,     0,     0,     2,
-       3,     0,     4,    85,     5,     6,     7,     8,     9,    10,
-      11,    12,    13,    14,    15,    16,    17,    18,    19,    20,
-      21,    22,    23,    24,    72,    58,    59,    95,     0,    25,
-      26,    78,    58,    59,     0,     0,     0,    79,    58,    59,
-       0,     0,     0,    80,    58,    59,    60,    61,     0,    62,
-      63,    64,     0,    60,    61,     0,    62,    63,    64,    60,
-      61,     0,    62,    63,    64,    60,    61,     0,    62,    63,
-      64,    81,    58,    59,     0,     0,     0,    82,    58,    59,
-       0,     0,     0,    83,    58,    59,     0,     0,     0,    86,
-      58,    59,     0,    60,    61,     0,    62,    63,    64,    60,
-      61,     0,    62,    63,    64,    60,    61,     0,    62,    63,
-      64,    60,    61,     0,    62,    63,    64,    87,    58,    59,
-       0,     0,     0,    88,    58,    59,     0,     0,     0,    89,
-      58,    59,     0,     0,     0,    90,    58,    59,     0,    60,
-      61,     0,    62,    63,    64,    60,    61,     0,    62,    63,
-      64,    60,    61,     0,    62,    63,    64,    60,    61,     0,
-      62,    63,    64,    91,    58,    59,     0,     0,     0,    92,
-      58,    59,     0,     0,     0,    94,    58,    59,     0,     0,
-       0,    96,    58,    59,     0,    60,    61,     0,    62,    63,
-      64,    60,    61,     0,    62,    63,    64,    60,    61,     0,
-      62,    63,    64,    60,    61,     0,    62,    63,    64,    40,
-      41,    42,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,    43,    44,     0,     0,    45,    46
+      49,    41,    50,    88,     0,    59,    60,    61,    51,    55,
+      56,    57,    58,    52,    68,    53,    69,    70,    54,    71,
+      73,    74,    72,    76,    77,    78,    79,    80,    62,    63,
+      97,    64,    65,    66,     0,     0,     0,     0,     0,     0,
+       0,     2,     3,     0,     4,    89,     5,     6,     7,     8,
+       9,    10,    11,    12,    13,    14,    15,    16,    17,    18,
+      19,    20,    21,    22,    23,    24,    25,    75,    60,    61,
+      99,     0,    26,    27,    81,    60,    61,     0,     0,     0,
+      82,    60,    61,     0,     0,     0,    83,    60,    61,     0,
+      62,    63,     0,    64,    65,    66,     0,    62,    63,     0,
+      64,    65,    66,    62,    63,     0,    64,    65,    66,    62,
+      63,     0,    64,    65,    66,    84,    60,    61,     0,     0,
+       0,    85,    60,    61,     0,     0,     0,    86,    60,    61,
+       0,     0,     0,    87,    60,    61,     0,     0,    62,    63,
+       0,    64,    65,    66,    62,    63,     0,    64,    65,    66,
+      62,    63,     0,    64,    65,    66,    62,    63,     0,    64,
+      65,    66,    90,    60,    61,     0,     0,     0,    91,    60,
+      61,     0,     0,     0,    92,    60,    61,     0,     0,     0,
+      93,    60,    61,     0,     0,    62,    63,     0,    64,    65,
+      66,    62,    63,     0,    64,    65,    66,    62,    63,     0,
+      64,    65,    66,    62,    63,     0,    64,    65,    66,    94,
+      60,    61,     0,     0,     0,    95,    60,    61,     0,     0,
+       0,    96,    60,    61,     0,     0,     0,    98,    60,    61,
+       0,     0,    62,    63,     0,    64,    65,    66,    62,    63,
+       0,    64,    65,    66,    62,    63,     0,    64,    65,    66,
+      62,    63,     0,    64,    65,    66,   100,    60,    61,     0,
+       0,     0,    42,    43,    44,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,    62,
+      63,     0,    64,    65,    66,    45,    46,     0,     0,    47,
+      48
 };
 
 static const yytype_int8 yycheck[] =
 {
-      26,    29,    26,    30,    -1,     3,     4,     5,    30,    35,
-      36,    37,    38,    30,    30,    41,    42,    30,    30,    45,
-      46,    30,    48,    49,    50,    51,    52,    25,    26,    -1,
-      28,    29,    30,    -1,    -1,    -1,    -1,    -1,    -1,     0,
-       1,    -1,     3,    69,     5,     6,     7,     8,     9,    10,
-      11,    12,    13,    14,    15,    16,    17,    18,    19,    20,
-      21,    22,    23,    24,     3,     4,     5,    93,    -1,    30,
-      31,     3,     4,     5,    -1,    -1,    -1,     3,     4,     5,
-      -1,    -1,    -1,     3,     4,     5,    25,    26,    -1,    28,
-      29,    30,    -1,    25,    26,    -1,    28,    29,    30,    25,
-      26,    -1,    28,    29,    30,    25,    26,    -1,    28,    29,
-      30,     3,     4,     5,    -1,    -1,    -1,     3,     4,     5,
-      -1,    -1,    -1,     3,     4,     5,    -1,    -1,    -1,     3,
-       4,     5,    -1,    25,    26,    -1,    28,    29,    30,    25,
-      26,    -1,    28,    29,    30,    25,    26,    -1,    28,    29,
-      30,    25,    26,    -1,    28,    29,    30,     3,     4,     5,
-      -1,    -1,    -1,     3,     4,     5,    -1,    -1,    -1,     3,
-       4,     5,    -1,    -1,    -1,     3,     4,     5,    -1,    25,
-      26,    -1,    28,    29,    30,    25,    26,    -1,    28,    29,
-      30,    25,    26,    -1,    28,    29,    30,    25,    26,    -1,
-      28,    29,    30,     3,     4,     5,    -1,    -1,    -1,     3,
+      27,    30,    30,    27,    -1,     3,     4,     5,    31,    36,
+      37,    38,    39,    31,    41,    31,    43,    44,    31,    31,
+      47,    48,    31,    50,    51,    52,    53,    54,    26,    27,
+      31,    29,    30,    31,    -1,    -1,    -1,    -1,    -1,    -1,
+      -1,     0,     1,    -1,     3,    72,     5,     6,     7,     8,
+       9,    10,    11,    12,    13,    14,    15,    16,    17,    18,
+      19,    20,    21,    22,    23,    24,    25,     3,     4,     5,
+      97,    -1,    31,    32,     3,     4,     5,    -1,    -1,    -1,
+       3,     4,     5,    -1,    -1,    -1,     3,     4,     5,    -1,
+      26,    27,    -1,    29,    30,    31,    -1,    26,    27,    -1,
+      29,    30,    31,    26,    27,    -1,    29,    30,    31,    26,
+      27,    -1,    29,    30,    31,     3,     4,     5,    -1,    -1,
+      -1,     3,     4,     5,    -1,    -1,    -1,     3,     4,     5,
+      -1,    -1,    -1,     3,     4,     5,    -1,    -1,    26,    27,
+      -1,    29,    30,    31,    26,    27,    -1,    29,    30,    31,
+      26,    27,    -1,    29,    30,    31,    26,    27,    -1,    29,
+      30,    31,     3,     4,     5,    -1,    -1,    -1,     3,     4,
+       5,    -1,    -1,    -1,     3,     4,     5,    -1,    -1,    -1,
+       3,     4,     5,    -1,    -1,    26,    27,    -1,    29,    30,
+      31,    26,    27,    -1,    29,    30,    31,    26,    27,    -1,
+      29,    30,    31,    26,    27,    -1,    29,    30,    31,     3,
        4,     5,    -1,    -1,    -1,     3,     4,     5,    -1,    -1,
-      -1,     3,     4,     5,    -1,    25,    26,    -1,    28,    29,
-      30,    25,    26,    -1,    28,    29,    30,    25,    26,    -1,
-      28,    29,    30,    25,    26,    -1,    28,    29,    30,     3,
-       4,     5,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
-      -1,    25,    26,    -1,    -1,    29,    30
+      -1,     3,     4,     5,    -1,    -1,    -1,     3,     4,     5,
+      -1,    -1,    26,    27,    -1,    29,    30,    31,    26,    27,
+      -1,    29,    30,    31,    26,    27,    -1,    29,    30,    31,
+      26,    27,    -1,    29,    30,    31,     3,     4,     5,    -1,
+      -1,    -1,     3,     4,     5,    -1,    -1,    -1,    -1,    -1,
+      -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    26,
+      27,    -1,    29,    30,    31,    26,    27,    -1,    -1,    30,
+      31
 };
 
   /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
      symbol of state STATE-NUM.  */
 static const yytype_uint8 yystos[] =
 {
-       0,    33,     0,     1,     3,     5,     6,     7,     8,     9,
+       0,    34,     0,     1,     3,     5,     6,     7,     8,     9,
       10,    11,    12,    13,    14,    15,    16,    17,    18,    19,
-      20,    21,    22,    23,    24,    30,    31,    34,    35,    36,
+      20,    21,    22,    23,    24,    25,    31,    32,    35,    36,
       37,    38,    39,    40,    41,    42,    43,    44,    45,    46,
-       3,     4,     5,    25,    26,    29,    30,    46,    29,    30,
-      30,    30,    30,    46,    46,    46,    46,     3,     4,     5,
-      25,    26,    28,    29,    30,    47,    46,    46,    30,    30,
-      46,    46,     3,    46,    46,    46,    46,    46,     3,     3,
-       3,     3,     3,     3,    26,    46,     3,     3,     3,     3,
-       3,     3,     3,    30,     3,    46,     3
+      47,    30,     3,     4,     5,    26,    27,    30,    31,    47,
+      30,    31,    31,    31,    31,    47,    47,    47,    47,     3,
+       4,     5,    26,    27,    29,    30,    31,    48,    47,    47,
+      47,    31,    31,    47,    47,     3,    47,    47,    47,    47,
+      47,     3,     3,     3,     3,     3,     3,     3,    27,    47,
+       3,     3,     3,     3,     3,     3,     3,    31,     3,    47,
+       3
 };
 
   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
 static const yytype_uint8 yyr1[] =
 {
-       0,    32,    33,    33,    34,    34,    35,    36,    36,    36,
-      36,    36,    36,    36,    36,    36,    36,    36,    36,    36,
-      36,    36,    36,    36,    36,    36,    37,    37,    37,    38,
-      38,    39,    39,    40,    40,    41,    41,    42,    42,    43,
-      43,    44,    44,    45,    45,    46,    46,    47,    47,    47,
-      47,    47,    47,    47
+       0,    33,    34,    34,    35,    35,    36,    37,    37,    37,
+      37,    37,    37,    37,    37,    37,    37,    37,    37,    37,
+      37,    37,    37,    37,    37,    37,    37,    38,    38,    38,
+      39,    39,    40,    40,    41,    41,    42,    42,    43,    43,
+      44,    44,    45,    45,    46,    46,    47,    47,    48,    48,
+      48,    48,    48,    48,    48
 };
 
   /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
 static const yytype_uint8 yyr2[] =
 {
        0,     2,     0,     2,     1,     1,     4,     2,     4,     5,
-       7,     4,     3,     4,     4,     4,     4,     4,     3,     3,
-       3,     3,     4,     3,     1,     1,     1,     1,     1,     1,
+       7,     4,     4,     3,     4,     4,     4,     4,     4,     3,
+       3,     3,     3,     4,     3,     1,     1,     1,     1,     1,
        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
-       1,     1,     1,     1,     1,     0,     2,     1,     1,     1,
-       1,     1,     1,     1
+       1,     1,     1,     1,     1,     1,     0,     2,     1,     1,
+       1,     1,     1,     1,     1
 };
 
 
@@ -1439,15 +1449,15 @@ yyreduce:
   switch (yyn)
     {
         case 6:
-#line 108 "cmFortranParser.y" /* yacc.c:1646  */
+#line 109 "cmFortranParser.y" /* yacc.c:1646  */
     {
     free((yyvsp[-3].string));
     }
-#line 1447 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1457 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
   case 7:
-#line 114 "cmFortranParser.y" /* yacc.c:1646  */
+#line 115 "cmFortranParser.y" /* yacc.c:1646  */
     {
     if (cmFortranParserIsKeyword((yyvsp[-1].string), "interface"))
       {
@@ -1457,11 +1467,11 @@ yyreduce:
       }
     free((yyvsp[-1].string));
     }
-#line 1461 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1471 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
   case 8:
-#line 124 "cmFortranParser.y" /* yacc.c:1646  */
+#line 125 "cmFortranParser.y" /* yacc.c:1646  */
     {
     if (cmFortranParserIsKeyword((yyvsp[-3].string), "use"))
       {
@@ -1491,11 +1501,11 @@ yyreduce:
     free((yyvsp[-3].string));
     free((yyvsp[-2].string));
     }
-#line 1495 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1505 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
   case 9:
-#line 154 "cmFortranParser.y" /* yacc.c:1646  */
+#line 155 "cmFortranParser.y" /* yacc.c:1646  */
     {
     if (cmFortranParserIsKeyword((yyvsp[-4].string), "use"))
       {
@@ -1506,11 +1516,11 @@ yyreduce:
     free((yyvsp[-4].string));
     free((yyvsp[-2].string));
     }
-#line 1510 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1520 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
   case 10:
-#line 165 "cmFortranParser.y" /* yacc.c:1646  */
+#line 166 "cmFortranParser.y" /* yacc.c:1646  */
     {
     if (cmFortranParserIsKeyword((yyvsp[-6].string), "use") &&
         cmFortranParserIsKeyword((yyvsp[-4].string), "non_intrinsic") )
@@ -1523,11 +1533,11 @@ yyreduce:
     free((yyvsp[-4].string));
     free((yyvsp[-2].string));
     }
-#line 1527 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1537 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
   case 11:
-#line 178 "cmFortranParser.y" /* yacc.c:1646  */
+#line 179 "cmFortranParser.y" /* yacc.c:1646  */
     {
     if (cmFortranParserIsKeyword((yyvsp[-3].string), "include"))
       {
@@ -1538,129 +1548,140 @@ yyreduce:
     free((yyvsp[-3].string));
     free((yyvsp[-2].string));
     }
-#line 1542 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1552 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
   case 12:
-#line 189 "cmFortranParser.y" /* yacc.c:1646  */
+#line 190 "cmFortranParser.y" /* yacc.c:1646  */
     {
     cmFortranParser* parser =
       cmFortran_yyget_extra(yyscanner);
-    cmFortranParser_RuleInclude(parser, (yyvsp[-2].string));
+    cmFortranParser_RuleLineDirective(parser, (yyvsp[-2].string));
     free((yyvsp[-2].string));
     }
-#line 1553 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1563 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
   case 13:
-#line 196 "cmFortranParser.y" /* yacc.c:1646  */
+#line 197 "cmFortranParser.y" /* yacc.c:1646  */
     {
     cmFortranParser* parser =
       cmFortran_yyget_extra(yyscanner);
     cmFortranParser_RuleInclude(parser, (yyvsp[-2].string));
     free((yyvsp[-2].string));
     }
-#line 1564 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1574 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
   case 14:
-#line 203 "cmFortranParser.y" /* yacc.c:1646  */
+#line 204 "cmFortranParser.y" /* yacc.c:1646  */
+    {
+    cmFortranParser* parser =
+      cmFortran_yyget_extra(yyscanner);
+    cmFortranParser_RuleInclude(parser, (yyvsp[-2].string));
+    free((yyvsp[-2].string));
+    }
+#line 1585 "cmFortranParser.cxx" /* yacc.c:1646  */
+    break;
+
+  case 15:
+#line 211 "cmFortranParser.y" /* yacc.c:1646  */
     {
     cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
     cmFortranParser_RuleDefine(parser, (yyvsp[-2].string));
     free((yyvsp[-2].string));
     }
-#line 1574 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1595 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
-  case 15:
-#line 209 "cmFortranParser.y" /* yacc.c:1646  */
+  case 16:
+#line 217 "cmFortranParser.y" /* yacc.c:1646  */
     {
     cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
     cmFortranParser_RuleUndef(parser, (yyvsp[-2].string));
     free((yyvsp[-2].string));
     }
-#line 1584 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1605 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
-  case 16:
-#line 215 "cmFortranParser.y" /* yacc.c:1646  */
+  case 17:
+#line 223 "cmFortranParser.y" /* yacc.c:1646  */
     {
     cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
     cmFortranParser_RuleIfdef(parser, (yyvsp[-2].string));
     free((yyvsp[-2].string));
     }
-#line 1594 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1615 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
-  case 17:
-#line 221 "cmFortranParser.y" /* yacc.c:1646  */
+  case 18:
+#line 229 "cmFortranParser.y" /* yacc.c:1646  */
     {
     cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
     cmFortranParser_RuleIfndef(parser, (yyvsp[-2].string));
     free((yyvsp[-2].string));
     }
-#line 1604 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1625 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
-  case 18:
-#line 227 "cmFortranParser.y" /* yacc.c:1646  */
+  case 19:
+#line 235 "cmFortranParser.y" /* yacc.c:1646  */
     {
     cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
     cmFortranParser_RuleIf(parser);
     }
-#line 1613 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1634 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
-  case 19:
-#line 232 "cmFortranParser.y" /* yacc.c:1646  */
+  case 20:
+#line 240 "cmFortranParser.y" /* yacc.c:1646  */
     {
     cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
     cmFortranParser_RuleElif(parser);
     }
-#line 1622 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1643 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
-  case 20:
-#line 237 "cmFortranParser.y" /* yacc.c:1646  */
+  case 21:
+#line 245 "cmFortranParser.y" /* yacc.c:1646  */
     {
     cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
     cmFortranParser_RuleElse(parser);
     }
-#line 1631 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1652 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
-  case 21:
-#line 242 "cmFortranParser.y" /* yacc.c:1646  */
+  case 22:
+#line 250 "cmFortranParser.y" /* yacc.c:1646  */
     {
     cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
     cmFortranParser_RuleEndif(parser);
     }
-#line 1640 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1661 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
-  case 22:
-#line 247 "cmFortranParser.y" /* yacc.c:1646  */
+  case 23:
+#line 255 "cmFortranParser.y" /* yacc.c:1646  */
     {
     free((yyvsp[-3].string));
     }
-#line 1648 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1669 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
-  case 47:
-#line 269 "cmFortranParser.y" /* yacc.c:1646  */
+  case 48:
+#line 277 "cmFortranParser.y" /* yacc.c:1646  */
     { free ((yyvsp[0].string)); }
-#line 1654 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1675 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
-  case 48:
-#line 270 "cmFortranParser.y" /* yacc.c:1646  */
+  case 49:
+#line 278 "cmFortranParser.y" /* yacc.c:1646  */
     { free ((yyvsp[0].string)); }
-#line 1660 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1681 "cmFortranParser.cxx" /* yacc.c:1646  */
     break;
 
 
-#line 1664 "cmFortranParser.cxx" /* yacc.c:1646  */
+#line 1685 "cmFortranParser.cxx" /* yacc.c:1646  */
       default: break;
     }
   /* User semantic actions sometimes alter yychar, and that requires
@@ -1890,6 +1911,6 @@ yyreturn:
 #endif
   return yyresult;
 }
-#line 278 "cmFortranParser.y" /* yacc.c:1906  */
+#line 286 "cmFortranParser.y" /* yacc.c:1906  */
 
 /* End of grammar */
diff --git a/Source/cmFortranParser.h b/Source/cmFortranParser.h
index 156c38a..cdaf46b 100644
--- a/Source/cmFortranParser.h
+++ b/Source/cmFortranParser.h
@@ -55,6 +55,8 @@ void cmFortranParser_Error(cmFortranParser* parser,
                                   const char* message);
 void cmFortranParser_RuleUse(cmFortranParser* parser,
                                     const char* name);
+void cmFortranParser_RuleLineDirective(cmFortranParser* parser,
+                                       const char* filename);
 void cmFortranParser_RuleInclude(cmFortranParser* parser,
                                         const char* name);
 void cmFortranParser_RuleModule(cmFortranParser* parser,
diff --git a/Source/cmFortranParser.y b/Source/cmFortranParser.y
index 996bef6..83f441a 100644
--- a/Source/cmFortranParser.y
+++ b/Source/cmFortranParser.y
@@ -1,7 +1,7 @@
 %{
 /*============================================================================
   CMake - Cross Platform Makefile Generator
-  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
+  Copyright 2000-2015 Kitware, Inc., Insight Software Consortium
 
   Distributed under the OSI-approved BSD License (the "License");
   see accompanying file Copyright.txt for details.
@@ -85,6 +85,7 @@ static bool cmFortranParserIsKeyword(const char* word,
 /*-------------------------------------------------------------------------*/
 /* Tokens */
 %token EOSTMT ASSIGNMENT_OP GARBAGE
+%token CPP_LINE_DIRECTIVE
 %token CPP_INCLUDE F90PPR_INCLUDE COCO_INCLUDE
 %token F90PPR_DEFINE CPP_DEFINE F90PPR_UNDEF CPP_UNDEF
 %token CPP_IFDEF CPP_IFNDEF CPP_IF CPP_ELSE CPP_ELIF CPP_ENDIF
@@ -185,6 +186,13 @@ keyword_stmt:
     free($1);
     free($2);
     }
+| CPP_LINE_DIRECTIVE STRING other EOSTMT
+    {
+    cmFortranParser* parser =
+      cmFortran_yyget_extra(yyscanner);
+    cmFortranParser_RuleLineDirective(parser, $2);
+    free($2);
+    }
 | CPP_INCLUDE_ANGLE other EOSTMT
     {
     cmFortranParser* parser =
diff --git a/Source/cmFortranParserImpl.cxx b/Source/cmFortranParserImpl.cxx
index a09c545..c175e62 100644
--- a/Source/cmFortranParserImpl.cxx
+++ b/Source/cmFortranParserImpl.cxx
@@ -210,6 +210,32 @@ void cmFortranParser_RuleUse(cmFortranParser* parser,
 }
 
 //----------------------------------------------------------------------------
+void cmFortranParser_RuleLineDirective(cmFortranParser* parser,
+                                       const char* filename)
+{
+  // This is a #line directive naming a file encountered during preprocessing.
+  std::string included = filename;
+
+  // Skip #line directives referencing non-files like
+  // "<built-in>" or "<command-line>".
+  if (included.empty() || included[0] == '<')
+    {
+    return;
+    }
+
+  // Fix windows file path separators since our lexer does not
+  // process escape sequences in string literals.
+  cmSystemTools::ReplaceString(included, "\\\\", "\\");
+  cmSystemTools::ConvertToUnixSlashes(included);
+
+  // Save the named file as included in the source.
+  if (cmSystemTools::FileExists(included))
+    {
+    parser->Info.Includes.insert(included);
+    }
+}
+
+//----------------------------------------------------------------------------
 void cmFortranParser_RuleInclude(cmFortranParser* parser,
                                         const char* name)
 {
diff --git a/Source/cmFortranParserTokens.h b/Source/cmFortranParserTokens.h
index df1aec3..ac49840 100644
--- a/Source/cmFortranParserTokens.h
+++ b/Source/cmFortranParserTokens.h
@@ -48,64 +48,66 @@ extern int cmFortran_yydebug;
     EOSTMT = 258,
     ASSIGNMENT_OP = 259,
     GARBAGE = 260,
-    CPP_INCLUDE = 261,
-    F90PPR_INCLUDE = 262,
-    COCO_INCLUDE = 263,
-    F90PPR_DEFINE = 264,
-    CPP_DEFINE = 265,
-    F90PPR_UNDEF = 266,
-    CPP_UNDEF = 267,
-    CPP_IFDEF = 268,
-    CPP_IFNDEF = 269,
-    CPP_IF = 270,
-    CPP_ELSE = 271,
-    CPP_ELIF = 272,
-    CPP_ENDIF = 273,
-    F90PPR_IFDEF = 274,
-    F90PPR_IFNDEF = 275,
-    F90PPR_IF = 276,
-    F90PPR_ELSE = 277,
-    F90PPR_ELIF = 278,
-    F90PPR_ENDIF = 279,
-    COMMA = 280,
-    DCOLON = 281,
-    CPP_TOENDL = 282,
-    UNTERMINATED_STRING = 283,
-    STRING = 284,
-    WORD = 285,
-    CPP_INCLUDE_ANGLE = 286
+    CPP_LINE_DIRECTIVE = 261,
+    CPP_INCLUDE = 262,
+    F90PPR_INCLUDE = 263,
+    COCO_INCLUDE = 264,
+    F90PPR_DEFINE = 265,
+    CPP_DEFINE = 266,
+    F90PPR_UNDEF = 267,
+    CPP_UNDEF = 268,
+    CPP_IFDEF = 269,
+    CPP_IFNDEF = 270,
+    CPP_IF = 271,
+    CPP_ELSE = 272,
+    CPP_ELIF = 273,
+    CPP_ENDIF = 274,
+    F90PPR_IFDEF = 275,
+    F90PPR_IFNDEF = 276,
+    F90PPR_IF = 277,
+    F90PPR_ELSE = 278,
+    F90PPR_ELIF = 279,
+    F90PPR_ENDIF = 280,
+    COMMA = 281,
+    DCOLON = 282,
+    CPP_TOENDL = 283,
+    UNTERMINATED_STRING = 284,
+    STRING = 285,
+    WORD = 286,
+    CPP_INCLUDE_ANGLE = 287
   };
 #endif
 /* Tokens.  */
 #define EOSTMT 258
 #define ASSIGNMENT_OP 259
 #define GARBAGE 260
-#define CPP_INCLUDE 261
-#define F90PPR_INCLUDE 262
-#define COCO_INCLUDE 263
-#define F90PPR_DEFINE 264
-#define CPP_DEFINE 265
-#define F90PPR_UNDEF 266
-#define CPP_UNDEF 267
-#define CPP_IFDEF 268
-#define CPP_IFNDEF 269
-#define CPP_IF 270
-#define CPP_ELSE 271
-#define CPP_ELIF 272
-#define CPP_ENDIF 273
-#define F90PPR_IFDEF 274
-#define F90PPR_IFNDEF 275
-#define F90PPR_IF 276
-#define F90PPR_ELSE 277
-#define F90PPR_ELIF 278
-#define F90PPR_ENDIF 279
-#define COMMA 280
-#define DCOLON 281
-#define CPP_TOENDL 282
-#define UNTERMINATED_STRING 283
-#define STRING 284
-#define WORD 285
-#define CPP_INCLUDE_ANGLE 286
+#define CPP_LINE_DIRECTIVE 261
+#define CPP_INCLUDE 262
+#define F90PPR_INCLUDE 263
+#define COCO_INCLUDE 264
+#define F90PPR_DEFINE 265
+#define CPP_DEFINE 266
+#define F90PPR_UNDEF 267
+#define CPP_UNDEF 268
+#define CPP_IFDEF 269
+#define CPP_IFNDEF 270
+#define CPP_IF 271
+#define CPP_ELSE 272
+#define CPP_ELIF 273
+#define CPP_ENDIF 274
+#define F90PPR_IFDEF 275
+#define F90PPR_IFNDEF 276
+#define F90PPR_IF 277
+#define F90PPR_ELSE 278
+#define F90PPR_ELIF 279
+#define F90PPR_ENDIF 280
+#define COMMA 281
+#define DCOLON 282
+#define CPP_TOENDL 283
+#define UNTERMINATED_STRING 284
+#define STRING 285
+#define WORD 286
+#define CPP_INCLUDE_ANGLE 287
 
 /* Value type.  */
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
@@ -116,7 +118,7 @@ union YYSTYPE
 
   char* string;
 
-#line 120 "cmFortranParserTokens.h" /* yacc.c:1909  */
+#line 122 "cmFortranParserTokens.h" /* yacc.c:1909  */
 };
 # define YYSTYPE_IS_TRIVIAL 1
 # define YYSTYPE_IS_DECLARED 1
diff --git a/Source/cmFunctionBlocker.h b/Source/cmFunctionBlocker.h
index 68bf762..a3b8078 100644
--- a/Source/cmFunctionBlocker.h
+++ b/Source/cmFunctionBlocker.h
@@ -39,7 +39,7 @@ public:
   /** Set/Get the context in which this blocker is created.  */
   void SetStartingContext(cmListFileContext const& lfc)
     { this->StartingContext = lfc; }
-  cmListFileContext const& GetStartingContext()
+  cmListFileContext const& GetStartingContext() const
     { return this->StartingContext; }
 private:
   cmListFileContext StartingContext;
diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx
index 80a4f81..6796a01 100644
--- a/Source/cmGeneratorExpression.cxx
+++ b/Source/cmGeneratorExpression.cxx
@@ -11,10 +11,9 @@
 ============================================================================*/
 #include "cmGeneratorExpression.h"
 
-#include "cmMakefile.h"
-#include "cmTarget.h"
 #include "assert.h"
 #include "cmAlgorithms.h"
+#include "cmSystemTools.h"
 
 #include "cmGeneratorExpressionEvaluator.h"
 #include "cmGeneratorExpressionLexer.h"
@@ -48,13 +47,13 @@ cmGeneratorExpression::~cmGeneratorExpression()
 }
 
 //----------------------------------------------------------------------------
-const char *cmCompiledGeneratorExpression::Evaluate(
-  cmMakefile* mf, const std::string& config, bool quiet,
-  cmTarget const* headTarget,
+const char *cmCompiledGeneratorExpression::Evaluate(cmLocalGenerator* lg,
+  const std::string& config, bool quiet,
+  const cmGeneratorTarget* headTarget,
   cmGeneratorExpressionDAGChecker *dagChecker,
                        std::string const& language) const
 {
-  return this->Evaluate(mf,
+  return this->Evaluate(lg,
                         config,
                         quiet,
                         headTarget,
@@ -65,13 +64,13 @@ const char *cmCompiledGeneratorExpression::Evaluate(
 
 //----------------------------------------------------------------------------
 const char *cmCompiledGeneratorExpression::Evaluate(
-  cmMakefile* mf, const std::string& config, bool quiet,
-  cmTarget const* headTarget,
-  cmTarget const* currentTarget,
+  cmLocalGenerator* lg, const std::string& config, bool quiet,
+  const cmGeneratorTarget* headTarget,
+  const cmGeneratorTarget* currentTarget,
   cmGeneratorExpressionDAGChecker *dagChecker,
   std::string const& language) const
 {
-  cmGeneratorExpressionContext context(mf, config, quiet, headTarget,
+  cmGeneratorExpressionContext context(lg, config, quiet, headTarget,
                                   currentTarget ? currentTarget : headTarget,
                                   this->EvaluateForBuildsystem,
                                   this->Backtrace, language);
@@ -463,10 +462,11 @@ bool cmGeneratorExpression::IsValidTargetName(const std::string &input)
 
 //----------------------------------------------------------------------------
 void
-cmCompiledGeneratorExpression::GetMaxLanguageStandard(cmTarget const* tgt,
+cmCompiledGeneratorExpression::GetMaxLanguageStandard(
+    const cmGeneratorTarget* tgt,
                   std::map<std::string, std::string>& mapping)
 {
-  typedef std::map<cmTarget const*,
+  typedef std::map<cmGeneratorTarget const*,
                    std::map<std::string, std::string> > MapType;
   MapType::const_iterator it = this->MaxLanguageStandard.find(tgt);
   if (it != this->MaxLanguageStandard.end())
diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h
index cd19bc0..efd381b 100644
--- a/Source/cmGeneratorExpression.h
+++ b/Source/cmGeneratorExpression.h
@@ -19,8 +19,8 @@
 #include <cmsys/RegularExpression.hxx>
 #include <cmsys/auto_ptr.hxx>
 
-class cmTarget;
-class cmMakefile;
+class cmGeneratorTarget;
+class cmLocalGenerator;
 class cmListFileBacktrace;
 
 struct cmGeneratorExpressionEvaluator;
@@ -78,26 +78,26 @@ private:
 class cmCompiledGeneratorExpression
 {
 public:
-  const char* Evaluate(cmMakefile* mf, const std::string& config,
+  const char* Evaluate(cmLocalGenerator* lg, const std::string& config,
                        bool quiet = false,
-                       cmTarget const* headTarget = 0,
-                       cmTarget const* currentTarget = 0,
+                       cmGeneratorTarget const* headTarget = 0,
+                       cmGeneratorTarget const* currentTarget = 0,
                        cmGeneratorExpressionDAGChecker *dagChecker = 0,
                        std::string const& language = std::string()) const;
-  const char* Evaluate(cmMakefile* mf, const std::string& config,
+  const char* Evaluate(cmLocalGenerator* lg, const std::string& config,
                        bool quiet,
-                       cmTarget const* headTarget,
+                       cmGeneratorTarget const* headTarget,
                        cmGeneratorExpressionDAGChecker *dagChecker,
                        std::string const& language = std::string()) const;
 
   /** Get set of targets found during evaluations.  */
-  std::set<cmTarget*> const& GetTargets() const
+  std::set<cmGeneratorTarget*> const& GetTargets() const
     { return this->DependTargets; }
 
   std::set<std::string> const& GetSeenTargetProperties() const
     { return this->SeenTargetProperties; }
 
-  std::set<cmTarget const*> const& GetAllTargetsSeen() const
+  std::set<cmGeneratorTarget const*> const& GetAllTargetsSeen() const
     { return this->AllTargetsSeen; }
 
   ~cmCompiledGeneratorExpression();
@@ -119,7 +119,7 @@ public:
   {
     return this->HadHeadSensitiveCondition;
   }
-  std::set<cmTarget const*> GetSourceSensitiveTargets() const
+  std::set<cmGeneratorTarget const*> GetSourceSensitiveTargets() const
   {
     return this->SourceSensitiveTargets;
   }
@@ -129,7 +129,7 @@ public:
     this->EvaluateForBuildsystem = eval;
   }
 
-  void GetMaxLanguageStandard(cmTarget const* tgt,
+  void GetMaxLanguageStandard(cmGeneratorTarget const* tgt,
                     std::map<std::string, std::string>& mapping);
 
 private:
@@ -149,15 +149,15 @@ private:
   const std::string Input;
   bool NeedsEvaluation;
 
-  mutable std::set<cmTarget*> DependTargets;
-  mutable std::set<cmTarget const*> AllTargetsSeen;
+  mutable std::set<cmGeneratorTarget*> DependTargets;
+  mutable std::set<cmGeneratorTarget const*> AllTargetsSeen;
   mutable std::set<std::string> SeenTargetProperties;
-  mutable std::map<cmTarget const*, std::map<std::string, std::string> >
-                                                          MaxLanguageStandard;
+  mutable std::map<cmGeneratorTarget const*,
+                   std::map<std::string, std::string> > MaxLanguageStandard;
   mutable std::string Output;
   mutable bool HadContextSensitiveCondition;
   mutable bool HadHeadSensitiveCondition;
-  mutable std::set<cmTarget const*>  SourceSensitiveTargets;
+  mutable std::set<cmGeneratorTarget const*>  SourceSensitiveTargets;
   bool EvaluateForBuildsystem;
 };
 
diff --git a/Source/cmGeneratorExpressionContext.cxx b/Source/cmGeneratorExpressionContext.cxx
index 947015e..5c9462f 100644
--- a/Source/cmGeneratorExpressionContext.cxx
+++ b/Source/cmGeneratorExpressionContext.cxx
@@ -11,16 +11,17 @@
 ============================================================================*/
 
 #include "cmGeneratorExpressionContext.h"
+#include "cmGeneratorTarget.h"
 
 cmGeneratorExpressionContext::cmGeneratorExpressionContext(
-      cmMakefile* mf, std::string const& config,
-      bool quiet, cmTarget const* headTarget,
-      cmTarget const* currentTarget,
+      cmLocalGenerator* lg, std::string const& config,
+      bool quiet, cmGeneratorTarget const* headTarget,
+      const cmGeneratorTarget* currentTarget,
       bool evaluateForBuildsystem,
       cmListFileBacktrace const& backtrace,
       std::string const& language)
   : Backtrace(backtrace),
-    Makefile(mf),
+    LG(lg),
     Config(config),
     Language(language),
     HeadTarget(headTarget),
diff --git a/Source/cmGeneratorExpressionContext.h b/Source/cmGeneratorExpressionContext.h
index ed83509..e802138 100644
--- a/Source/cmGeneratorExpressionContext.h
+++ b/Source/cmGeneratorExpressionContext.h
@@ -18,32 +18,35 @@
 #include <map>
 #include <string>
 
-class cmTarget;
+class cmGeneratorTarget;
+class cmLocalGenerator;
 
 //----------------------------------------------------------------------------
 struct cmGeneratorExpressionContext
 {
-  cmGeneratorExpressionContext(cmMakefile* mf, std::string const& config,
-                               bool quiet, cmTarget const* headTarget,
-                               cmTarget const* currentTarget,
+  cmGeneratorExpressionContext(cmLocalGenerator* lg, std::string const& config,
+                               bool quiet, const cmGeneratorTarget* headTarget,
+                               cmGeneratorTarget const* currentTarget,
                                bool evaluateForBuildsystem,
                                cmListFileBacktrace const& backtrace,
                                std::string const& language);
 
 
   cmListFileBacktrace Backtrace;
-  std::set<cmTarget*> DependTargets;
-  std::set<cmTarget const*> AllTargets;
+  std::set<cmGeneratorTarget*> DependTargets;
+  std::set<cmGeneratorTarget const*> AllTargets;
   std::set<std::string> SeenTargetProperties;
-  std::set<cmTarget const*> SourceSensitiveTargets;
-  std::map<cmTarget const*, std::map<std::string, std::string> >
+  std::set<cmGeneratorTarget const*> SourceSensitiveTargets;
+  std::map<cmGeneratorTarget const*, std::map<std::string, std::string> >
                                                           MaxLanguageStandard;
-  cmMakefile *Makefile;
+  cmLocalGenerator *LG;
   std::string Config;
   std::string Language;
-  cmTarget const* HeadTarget; // The target whose property is being evaluated.
-  cmTarget const* CurrentTarget; // The dependent of HeadTarget which appears
-                                 // directly or indirectly in the property.
+  // The target whose property is being evaluated.
+  cmGeneratorTarget const* HeadTarget;
+  // The dependent of HeadTarget which appears
+  // directly or indirectly in the property.
+  cmGeneratorTarget const* CurrentTarget;
   bool Quiet;
   bool HadError;
   bool HadContextSensitiveCondition;
diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx
index 851aacd..c3b0272 100644
--- a/Source/cmGeneratorExpressionDAGChecker.cxx
+++ b/Source/cmGeneratorExpressionDAGChecker.cxx
@@ -12,7 +12,7 @@
 
 #include "cmGeneratorExpressionDAGChecker.h"
 
-#include "cmMakefile.h"
+#include "cmLocalGenerator.h"
 #include "cmAlgorithms.h"
 
 //----------------------------------------------------------------------------
@@ -110,7 +110,7 @@ void cmGeneratorExpressionDAGChecker::ReportError(
       << "  " << expr << "\n"
       << "Self reference on target \""
       << context->HeadTarget->GetName() << "\".\n";
-    context->Makefile->GetCMakeInstance()
+    context->LG->GetCMakeInstance()
       ->IssueMessage(cmake::FATAL_ERROR, e.str(),
                       parent->Backtrace);
     return;
@@ -121,7 +121,7 @@ void cmGeneratorExpressionDAGChecker::ReportError(
   e << "Error evaluating generator expression:\n"
     << "  " << expr << "\n"
     << "Dependency loop found.";
-  context->Makefile->GetCMakeInstance()
+  context->LG->GetCMakeInstance()
     ->IssueMessage(cmake::FATAL_ERROR, e.str(),
                     context->Backtrace);
   }
@@ -134,7 +134,7 @@ void cmGeneratorExpressionDAGChecker::ReportError(
       << "  "
       << (parent->Content ? parent->Content->GetOriginalExpression() : expr)
       << "\n";
-    context->Makefile->GetCMakeInstance()
+    context->LG->GetCMakeInstance()
       ->IssueMessage(cmake::FATAL_ERROR, e.str(),
                       parent->Backtrace);
     parent = parent->Parent;
diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx
index e4d9f10..4ac2a0d 100644
--- a/Source/cmGeneratorExpressionEvaluationFile.cxx
+++ b/Source/cmGeneratorExpressionEvaluationFile.cxx
@@ -44,7 +44,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg,
   std::string rawCondition = this->Condition->GetInput();
   if (!rawCondition.empty())
     {
-    std::string condResult = this->Condition->Evaluate(lg->GetMakefile(),
+    std::string condResult = this->Condition->Evaluate(lg,
                                                        config,
                                                        false, 0, 0, 0, lang);
     if (condResult == "0")
@@ -62,10 +62,10 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg,
     }
 
   const std::string outputFileName
-                    = this->OutputFileExpr->Evaluate(lg->GetMakefile(), config,
+                    = this->OutputFileExpr->Evaluate(lg, config,
                                                      false, 0, 0, 0, lang);
   const std::string outputContent
-                          = inputExpression->Evaluate(lg->GetMakefile(),
+                          = inputExpression->Evaluate(lg,
                                                       config,
                                                       false, 0, 0, 0, lang);
 
@@ -110,7 +110,7 @@ void cmGeneratorExpressionEvaluationFile::CreateOutputFile(
   for(std::vector<std::string>::const_iterator le = enabledLanguages.begin();
       le != enabledLanguages.end(); ++le)
     {
-    std::string name = this->OutputFileExpr->Evaluate(lg->GetMakefile(),
+    std::string name = this->OutputFileExpr->Evaluate(lg,
                                                       config,
                                                       false, 0, 0, 0, *le);
     cmSourceFile* sf = lg->GetMakefile()->GetOrCreateSource(name);
@@ -139,7 +139,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator *lg)
       {
       std::ostringstream e;
       e << "Evaluation file \"" << this->Input << "\" cannot be read.";
-      lg->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
+      lg->IssueMessage(cmake::FATAL_ERROR, e.str());
       return;
       }
 
diff --git a/Source/cmGeneratorExpressionEvaluator.h b/Source/cmGeneratorExpressionEvaluator.h
index 7c1bd8c..407f83f 100644
--- a/Source/cmGeneratorExpressionEvaluator.h
+++ b/Source/cmGeneratorExpressionEvaluator.h
@@ -12,13 +12,11 @@
 #ifndef cmGeneratorExpressionEvaluator_h
 #define cmGeneratorExpressionEvaluator_h
 
-#include <vector>
-#include <string>
-
 #include "cmListFileCache.h"
 #include "cmGeneratorExpressionContext.h"
 
-class cmTarget;
+#include <vector>
+#include <string>
 
 struct cmGeneratorExpressionDAGChecker;
 struct cmGeneratorExpressionNode;
diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx
index 1c350ab..32b2f82 100644
--- a/Source/cmGeneratorExpressionNode.cxx
+++ b/Source/cmGeneratorExpressionNode.cxx
@@ -14,18 +14,20 @@
 #include "cmGlobalGenerator.h"
 #include "cmAlgorithms.h"
 #include "cmOutputConverter.h"
+#include "cmMakefile.h"
 
 //----------------------------------------------------------------------------
 std::string cmGeneratorExpressionNode::EvaluateDependentExpression(
-    std::string const& prop, cmMakefile *makefile,
+    std::string const& prop, cmLocalGenerator *lg,
     cmGeneratorExpressionContext *context,
-    cmTarget const* headTarget, cmTarget const* currentTarget,
+    cmGeneratorTarget const* headTarget,
+    cmGeneratorTarget const* currentTarget,
     cmGeneratorExpressionDAGChecker *dagChecker)
 {
   cmGeneratorExpression ge(context->Backtrace);
   cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
   cge->SetEvaluateForBuildsystem(context->EvaluateForBuildsystem);
-  std::string result = cge->Evaluate(makefile,
+  std::string result = cge->Evaluate(lg,
                         context->Config,
                         context->Quiet,
                         headTarget,
@@ -367,7 +369,8 @@ struct CompilerIdNode : public cmGeneratorExpressionNode
                        const std::string &lang) const
   {
     const char *compilerId =
-      context->Makefile->GetSafeDefinition("CMAKE_" + lang + "_COMPILER_ID");
+      context->LG->GetMakefile()
+        ->GetSafeDefinition("CMAKE_" + lang + "_COMPILER_ID");
     if (parameters.empty())
       {
       return compilerId ? compilerId : "";
@@ -391,13 +394,13 @@ struct CompilerIdNode : public cmGeneratorExpressionNode
 
     if (cmsysString_strcasecmp(parameters.begin()->c_str(), compilerId) == 0)
       {
-      switch(context->Makefile->GetPolicyStatus(cmPolicies::CMP0044))
+      switch(context->LG->GetPolicyStatus(cmPolicies::CMP0044))
         {
         case cmPolicies::WARN:
           {
           std::ostringstream e;
           e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0044);
-          context->Makefile->GetCMakeInstance()
+          context->LG->GetCMakeInstance()
                  ->IssueMessage(cmake::AUTHOR_WARNING,
                                 e.str(), context->Backtrace);
           }
@@ -470,8 +473,9 @@ struct CompilerVersionNode : public cmGeneratorExpressionNode
                        cmGeneratorExpressionDAGChecker *,
                        const std::string &lang) const
   {
-    const char *compilerVersion = context->Makefile->GetSafeDefinition(
-        "CMAKE_" + lang + "_COMPILER_VERSION");
+    const char *compilerVersion =
+        context->LG->GetMakefile()->GetSafeDefinition(
+          "CMAKE_" + lang + "_COMPILER_VERSION");
     if (parameters.empty())
       {
       return compilerVersion ? compilerVersion : "";
@@ -553,7 +557,7 @@ struct PlatformIdNode : public cmGeneratorExpressionNode
                        cmGeneratorExpressionDAGChecker *) const
   {
     const char *platformId =
-      context->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME");
+      context->LG->GetMakefile()->GetSafeDefinition("CMAKE_SYSTEM_NAME");
     if (parameters.empty())
       {
       return platformId ? platformId : "";
@@ -702,7 +706,7 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
       const char* loc = 0;
       const char* imp = 0;
       std::string suffix;
-      if (context->CurrentTarget->GetMappedConfig(context->Config,
+      if (context->CurrentTarget->Target->GetMappedConfig(context->Config,
                                                   &loc,
                                                   &imp,
                                                   suffix))
@@ -768,7 +772,7 @@ static const struct CompileLanguageNode : public cmGeneratorExpressionNode
       }
 
     std::vector<std::string> enabledLanguages;
-    cmGlobalGenerator* gg = context->Makefile->GetGlobalGenerator();
+    cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
     gg->GetEnabledLanguages(enabledLanguages);
     if (!parameters.empty() &&
           std::find(enabledLanguages.begin(), enabledLanguages.end(),
@@ -831,8 +835,8 @@ template <typename T>
 std::string
 getLinkedTargetsContent(
   std::vector<T> const &libraries,
-  cmTarget const* target,
-  cmTarget const* headTarget,
+  cmGeneratorTarget const* target,
+  cmGeneratorTarget const* headTarget,
   cmGeneratorExpressionContext *context,
   cmGeneratorExpressionDAGChecker *dagChecker,
   const std::string &interfacePropertyName)
@@ -858,8 +862,10 @@ getLinkedTargetsContent(
     {
     linkedTargetsContent =
         cmGeneratorExpressionNode::EvaluateDependentExpression(depString,
-                                        target->GetMakefile(), context,
-                                        headTarget, target, dagChecker);
+                                        target->GetLocalGenerator(),
+                                        context,
+                                        headTarget,
+                                        target, dagChecker);
     }
   linkedTargetsContent =
     cmGeneratorExpression::StripEmptyListElements(linkedTargetsContent);
@@ -888,7 +894,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
       }
     static cmsys::RegularExpression propertyNameValidator("^[A-Za-z0-9_]+$");
 
-    cmTarget const* target = context->HeadTarget;
+    cmGeneratorTarget const* target = context->HeadTarget;
     std::string propertyName = *parameters.begin();
 
     if (parameters.size() == 1)
@@ -938,16 +944,17 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
         }
       if(propertyName == "ALIASED_TARGET")
         {
-        if(context->Makefile->IsAlias(targetName))
+        if(context->LG->GetMakefile()->IsAlias(targetName))
           {
-          if(cmTarget* tgt = context->Makefile->FindTargetToUse(targetName))
+          if(cmGeneratorTarget* tgt =
+             context->LG->FindGeneratorTargetToUse(targetName))
             {
             return tgt->GetName();
             }
           }
         return "";
         }
-      target = context->Makefile->FindTargetToUse(targetName);
+      target = context->LG->FindGeneratorTargetToUse(targetName);
 
       if (!target)
         {
@@ -991,9 +998,6 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
 
     assert(target);
 
-    cmGeneratorTarget* gtgt =
-        context->Makefile->GetGlobalGenerator()->GetGeneratorTarget(target);
-
     if (propertyName == "LINKER_LANGUAGE")
       {
       if (target->LinkLanguagePropagatesToDependents() &&
@@ -1005,7 +1009,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
             "link libraries for a static library");
         return std::string();
         }
-      return gtgt->GetLinkerLanguage(context->Config);
+      return target->GetLinkerLanguage(context->Config);
       }
 
     cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace,
@@ -1097,20 +1101,21 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
                            "COMPILE_DEFINITIONS_"))
       {
       cmPolicies::PolicyStatus polSt =
-                      context->Makefile->GetPolicyStatus(cmPolicies::CMP0043);
+          context->LG->GetPolicyStatus(cmPolicies::CMP0043);
       if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD)
         {
         interfacePropertyName = "INTERFACE_COMPILE_DEFINITIONS";
         }
       }
 #undef POPULATE_INTERFACE_PROPERTY_NAME
-    cmTarget const* headTarget = context->HeadTarget && isInterfaceProperty
+    cmGeneratorTarget const* headTarget =
+        context->HeadTarget && isInterfaceProperty
                                ? context->HeadTarget : target;
 
     if(isInterfaceProperty)
       {
       if(cmLinkInterfaceLibraries const* iface =
-         gtgt->GetLinkInterfaceLibraries(context->Config, headTarget, true))
+         target->GetLinkInterfaceLibraries(context->Config, headTarget, true))
         {
         linkedTargetsContent =
           getLinkedTargetsContent(iface->Libraries, target,
@@ -1135,44 +1140,44 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
     if (!prop)
       {
       if (target->IsImported()
-          || target->GetType() == cmTarget::INTERFACE_LIBRARY)
+          || target->GetType() == cmState::INTERFACE_LIBRARY)
         {
         return linkedTargetsContent;
         }
-      if (gtgt->IsLinkInterfaceDependentBoolProperty(propertyName,
+      if (target->IsLinkInterfaceDependentBoolProperty(propertyName,
                                                      context->Config))
         {
         context->HadContextSensitiveCondition = true;
-        return gtgt->GetLinkInterfaceDependentBoolProperty(
+        return target->GetLinkInterfaceDependentBoolProperty(
                                                 propertyName,
                                                 context->Config) ? "1" : "0";
         }
-      if (gtgt->IsLinkInterfaceDependentStringProperty(propertyName,
+      if (target->IsLinkInterfaceDependentStringProperty(propertyName,
                                                        context->Config))
         {
         context->HadContextSensitiveCondition = true;
         const char *propContent =
-                              gtgt->GetLinkInterfaceDependentStringProperty(
+                              target->GetLinkInterfaceDependentStringProperty(
                                                 propertyName,
                                                 context->Config);
         return propContent ? propContent : "";
         }
-      if (gtgt->IsLinkInterfaceDependentNumberMinProperty(propertyName,
+      if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
                                                           context->Config))
         {
         context->HadContextSensitiveCondition = true;
         const char *propContent =
-                          gtgt->GetLinkInterfaceDependentNumberMinProperty(
+                          target->GetLinkInterfaceDependentNumberMinProperty(
                                                 propertyName,
                                                 context->Config);
         return propContent ? propContent : "";
         }
-      if (gtgt->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
+      if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
                                                           context->Config))
         {
         context->HadContextSensitiveCondition = true;
         const char *propContent =
-                          gtgt->GetLinkInterfaceDependentNumberMaxProperty(
+                          target->GetLinkInterfaceDependentNumberMaxProperty(
                                                 propertyName,
                                                 context->Config);
         return propContent ? propContent : "";
@@ -1184,22 +1189,22 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
     if (!target->IsImported()
         && dagCheckerParent && !dagCheckerParent->EvaluatingLinkLibraries())
       {
-      if (gtgt->IsLinkInterfaceDependentNumberMinProperty(propertyName,
+      if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
                                                           context->Config))
         {
         context->HadContextSensitiveCondition = true;
         const char *propContent =
-                            gtgt->GetLinkInterfaceDependentNumberMinProperty(
+                            target->GetLinkInterfaceDependentNumberMinProperty(
                                                 propertyName,
                                                 context->Config);
         return propContent ? propContent : "";
         }
-      if (gtgt->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
+      if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
                                                           context->Config))
         {
         context->HadContextSensitiveCondition = true;
         const char *propContent =
-                            gtgt->GetLinkInterfaceDependentNumberMaxProperty(
+                            target->GetLinkInterfaceDependentNumberMaxProperty(
                                                 propertyName,
                                                 context->Config);
         return propContent ? propContent : "";
@@ -1208,7 +1213,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
     if(!interfacePropertyName.empty())
       {
       std::string result = this->EvaluateDependentExpression(prop,
-                                        context->Makefile, context,
+                                        context->LG, context,
                                         headTarget, target, &dagChecker);
       if (!linkedTargetsContent.empty())
         {
@@ -1264,7 +1269,7 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode
 
     std::string tgtName = parameters.front();
     cmGeneratorTarget* gt =
-                context->Makefile->FindGeneratorTargetToUse(tgtName);
+                context->LG->FindGeneratorTargetToUse(tgtName);
     if (!gt)
       {
       std::ostringstream e;
@@ -1273,7 +1278,7 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode
       reportError(context, content->GetOriginalExpression(), e.str());
       return std::string();
       }
-    if (gt->GetType() != cmTarget::OBJECT_LIBRARY)
+    if (gt->GetType() != cmState::OBJECT_LIBRARY)
       {
       std::ostringstream e;
       e << "Objects of target \"" << tgtName
@@ -1307,7 +1312,8 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode
       assert(!map_it->second.empty());
       result += sep;
       std::string objFile = obj_dir + map_it->second;
-      cmSourceFile* sf = context->Makefile->GetOrCreateSource(objFile, true);
+      cmSourceFile* sf =
+          context->LG->GetMakefile()->GetOrCreateSource(objFile, true);
       sf->SetObjectLibrary(tgtName);
       sf->SetProperty("EXTERNAL_OBJECT", "1");
       result += objFile;
@@ -1329,7 +1335,7 @@ static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
                        const GeneratorExpressionContent *content,
                        cmGeneratorExpressionDAGChecker *dagChecker) const
   {
-    cmTarget const* target = context->HeadTarget;
+    cmGeneratorTarget const* target = context->HeadTarget;
     if (!target)
       {
       reportError(context, content->GetOriginalExpression(),
@@ -1349,7 +1355,8 @@ static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
       {
       std::string error;
       std::string lang;
-      if (!context->Makefile->CompileFeatureKnown(context->HeadTarget,
+      if (!context->LG->GetMakefile()->CompileFeatureKnown(
+            context->HeadTarget->Target,
                                                   *it, lang, &error))
         {
         reportError(context, content->GetOriginalExpression(), error);
@@ -1360,7 +1367,8 @@ static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
       if (availableFeatures.find(lang) == availableFeatures.end())
         {
         const char* featuresKnown
-                  = context->Makefile->CompileFeaturesAvailable(lang, &error);
+            = context->LG->GetMakefile()->CompileFeaturesAvailable(lang,
+                                                                   &error);
         if (!featuresKnown)
           {
           reportError(context, content->GetOriginalExpression(), error);
@@ -1378,7 +1386,7 @@ static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
       {
       std::vector<std::string> const& langAvailable
                                               = availableFeatures[lit->first];
-      const char* standardDefault = context->Makefile
+      const char* standardDefault = context->LG->GetMakefile()
         ->GetDefinition("CMAKE_" + lit->first + "_STANDARD_DEFAULT");
       for (std::vector<std::string>::const_iterator it = lit->second.begin();
           it != lit->second.end(); ++it)
@@ -1394,7 +1402,7 @@ static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
           // All features known for the language are always available.
           continue;
           }
-        if (!context->Makefile->HaveStandardAvailable(target,
+        if (!context->LG->GetMakefile()->HaveStandardAvailable(target->Target,
                                                       lit->first, *it))
           {
           if (evalLL)
@@ -1429,7 +1437,7 @@ static const char* targetPolicyWhitelist[] = {
 #undef TARGET_POLICY_STRING
 };
 
-cmPolicies::PolicyStatus statusForTarget(cmTarget const* tgt,
+cmPolicies::PolicyStatus statusForTarget(cmGeneratorTarget const* tgt,
                                          const char *policy)
 {
 #define RETURN_POLICY(POLICY) \
@@ -1490,11 +1498,11 @@ static const struct TargetPolicyNode : public cmGeneratorExpressionNode
       const char *policy = targetPolicyWhitelist[i];
       if (parameters.front() == policy)
         {
-        cmMakefile *mf = context->HeadTarget->GetMakefile();
+        cmLocalGenerator* lg = context->HeadTarget->GetLocalGenerator();
         switch(statusForTarget(context->HeadTarget, policy))
           {
           case cmPolicies::WARN:
-            mf->IssueMessage(cmake::AUTHOR_WARNING,
+            lg->IssueMessage(cmake::AUTHOR_WARNING,
                         cmPolicies::GetPolicyWarning(policyForString(policy)));
           case cmPolicies::REQUIRED_IF_USED:
           case cmPolicies::REQUIRED_ALWAYS:
@@ -1572,21 +1580,21 @@ struct TargetFilesystemArtifactResultCreator<ArtifactSonameTag>
                             const GeneratorExpressionContent *content)
   {
     // The target soname file (.so.1).
-    if(target->Target->IsDLLPlatform())
+    if(target->IsDLLPlatform())
       {
       ::reportError(context, content->GetOriginalExpression(),
                     "TARGET_SONAME_FILE is not allowed "
                     "for DLL target platforms.");
       return std::string();
       }
-    if(target->GetType() != cmTarget::SHARED_LIBRARY)
+    if(target->GetType() != cmState::SHARED_LIBRARY)
       {
       ::reportError(context, content->GetOriginalExpression(),
                     "TARGET_SONAME_FILE is allowed only for "
                     "SHARED libraries.");
       return std::string();
       }
-    std::string result = target->Target->GetDirectory(context->Config);
+    std::string result = target->GetDirectory(context->Config);
     result += "/";
     result += target->GetSOName(context->Config);
     return result;
@@ -1612,18 +1620,18 @@ struct TargetFilesystemArtifactResultCreator<ArtifactPdbTag>
 
     std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB";
 
-    if(!context->Makefile->IsOn(pdbSupportVar))
+    if(!context->LG->GetMakefile()->IsOn(pdbSupportVar))
       {
       ::reportError(context, content->GetOriginalExpression(),
                     "TARGET_PDB_FILE is not supported by the target linker.");
       return std::string();
       }
 
-    cmTarget::TargetType targetType = target->Target->GetType();
+    cmState::TargetType targetType = target->GetType();
 
-    if(targetType != cmTarget::SHARED_LIBRARY &&
-       targetType != cmTarget::MODULE_LIBRARY &&
-       targetType != cmTarget::EXECUTABLE)
+    if(targetType != cmState::SHARED_LIBRARY &&
+       targetType != cmState::MODULE_LIBRARY &&
+       targetType != cmState::EXECUTABLE)
       {
       ::reportError(context, content->GetOriginalExpression(),
                     "TARGET_PDB_FILE is allowed only for "
@@ -1631,7 +1639,7 @@ struct TargetFilesystemArtifactResultCreator<ArtifactPdbTag>
       return std::string();
       }
 
-    std::string result = target->Target->GetPDBDirectory(context->Config);
+    std::string result = target->GetPDBDirectory(context->Config);
     result += "/";
     result += target->GetPDBName(context->Config);
     return result;
@@ -1647,7 +1655,7 @@ struct TargetFilesystemArtifactResultCreator<ArtifactLinkerTag>
                             const GeneratorExpressionContent *content)
   {
     // The file used to link to the target (.so, .lib, .a).
-    if(!target->Target->IsLinkable())
+    if(!target->IsLinkable())
       {
       ::reportError(context, content->GetOriginalExpression(),
                     "TARGET_LINKER_FILE is allowed only for libraries and "
@@ -1655,7 +1663,7 @@ struct TargetFilesystemArtifactResultCreator<ArtifactLinkerTag>
       return std::string();
       }
     return target->GetFullPath(context->Config,
-                               target->Target->HasImportLibrary());
+                               target->HasImportLibrary());
   }
 };
 
@@ -1726,15 +1734,15 @@ struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
       return std::string();
       }
     cmGeneratorTarget* target =
-        context->Makefile->FindGeneratorTargetToUse(name);
+        context->LG->FindGeneratorTargetToUse(name);
     if(!target)
       {
       ::reportError(context, content->GetOriginalExpression(),
                     "No target \"" + name + "\"");
       return std::string();
       }
-    if(target->GetType() >= cmTarget::OBJECT_LIBRARY &&
-      target->GetType() != cmTarget::UNKNOWN_LIBRARY)
+    if(target->GetType() >= cmState::OBJECT_LIBRARY &&
+      target->GetType() != cmState::UNKNOWN_LIBRARY)
       {
       ::reportError(context, content->GetOriginalExpression(),
                   "Target \"" + name + "\" is not an executable or library.");
@@ -1749,8 +1757,8 @@ struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
                     "be used while evaluating link libraries");
       return std::string();
       }
-    context->DependTargets.insert(target->Target);
-    context->AllTargets.insert(target->Target);
+    context->DependTargets.insert(target);
+    context->AllTargets.insert(target);
 
     std::string result =
                 TargetFilesystemArtifactResultCreator<ArtifactT>::Create(
@@ -1808,7 +1816,7 @@ static const struct ShellPathNode : public cmGeneratorExpressionNode
                   "\"" + parameters.front() + "\" is not an absolute path.");
       return std::string();
       }
-    cmOutputConverter converter(context->Makefile->GetStateSnapshot());
+    cmOutputConverter converter(context->LG->GetStateSnapshot());
     return converter.ConvertDirectorySeparatorsForShell(parameters.front());
   }
 } shellPathNode;
@@ -1892,7 +1900,7 @@ void reportError(cmGeneratorExpressionContext *context,
   e << "Error evaluating generator expression:\n"
     << "  " << expr << "\n"
     << result;
-  context->Makefile->GetCMakeInstance()
+  context->LG->GetCMakeInstance()
     ->IssueMessage(cmake::FATAL_ERROR, e.str(),
                     context->Backtrace);
 }
diff --git a/Source/cmGeneratorExpressionNode.h b/Source/cmGeneratorExpressionNode.h
index 847a00a..854811b 100644
--- a/Source/cmGeneratorExpressionNode.h
+++ b/Source/cmGeneratorExpressionNode.h
@@ -12,8 +12,6 @@
 #ifndef cmGeneratorExpressionNode_h
 #define cmGeneratorExpressionNode_h
 
-#include "cmMakefile.h"
-
 #include "cmGeneratorExpressionEvaluator.h"
 #include "cmGeneratorExpressionParser.h"
 #include "cmGeneratorExpressionDAGChecker.h"
@@ -54,9 +52,10 @@ struct cmGeneratorExpressionNode
                               ) const = 0;
 
   static std::string EvaluateDependentExpression(
-    std::string const& prop, cmMakefile *makefile,
+    std::string const& prop, cmLocalGenerator *lg,
     cmGeneratorExpressionContext *context,
-    cmTarget const* headTarget, cmTarget const* currentTarget,
+    const cmGeneratorTarget* headTarget,
+    const cmGeneratorTarget* currentTarget,
     cmGeneratorExpressionDAGChecker *dagChecker);
 
   static const cmGeneratorExpressionNode* GetNode(
diff --git a/Source/cmGeneratorExpressionParser.h b/Source/cmGeneratorExpressionParser.h
index 28f1441..5bd6777 100644
--- a/Source/cmGeneratorExpressionParser.h
+++ b/Source/cmGeneratorExpressionParser.h
@@ -19,8 +19,6 @@
 
 #include "cmListFileCache.h"
 
-class cmMakefile;
-class cmTarget;
 struct cmGeneratorExpressionEvaluator;
 
 //----------------------------------------------------------------------------
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 194cd88..ff12320 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -62,7 +62,7 @@ void reportBadObjLib(std::vector<cmSourceFile*> const& badObjLib,
     e << "but may contain only sources that compile, header files, and "
          "other files that would not affect linking of a normal library.";
     cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
-                     target->Target->GetBacktrace());
+                     target->GetBacktrace());
     }
 }
 
@@ -155,7 +155,7 @@ struct TagVisitor
     : Data(data), Target(target),
     GlobalGenerator(target->GetLocalGenerator()->GetGlobalGenerator()),
     Header(CM_HEADER_REGEX),
-    IsObjLib(target->GetType() == cmTarget::OBJECT_LIBRARY)
+    IsObjLib(target->GetType() == cmState::OBJECT_LIBRARY)
   {
   }
 
@@ -172,7 +172,7 @@ struct TagVisitor
       {
       DoAccept<IsSameTag<Tag, CustomCommandsTag>::Result>::Do(this->Data, sf);
       }
-    else if(this->Target->GetType() == cmTarget::UTILITY)
+    else if(this->Target->GetType() == cmState::UTILITY)
       {
       DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
       }
@@ -269,7 +269,10 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
   DebugIncludesDone(false),
   DebugCompileOptionsDone(false),
   DebugCompileFeaturesDone(false),
-  DebugCompileDefinitionsDone(false)
+  DebugCompileDefinitionsDone(false),
+  DebugSourcesDone(false),
+  LinkImplementationLanguageIsContextDependent(true),
+  UtilityItemsDone(false)
 {
   this->Makefile = this->Target->GetMakefile();
   this->LocalGenerator = lg;
@@ -296,6 +299,17 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
         t->GetCompileDefinitionsEntries(),
         t->GetCompileDefinitionsBacktraces(),
         this->CompileDefinitionsEntries);
+
+  CreatePropertyGeneratorExpressions(
+        t->GetSourceEntries(),
+        t->GetSourceBacktraces(),
+        this->SourceEntries, true);
+
+  this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
+                       this->Makefile->IsOn("CYGWIN") ||
+                       this->Makefile->IsOn("MINGW"));
+
+  this->PolicyMap = t->PolicyMap;
 }
 
 cmGeneratorTarget::~cmGeneratorTarget()
@@ -304,6 +318,7 @@ cmGeneratorTarget::~cmGeneratorTarget()
   cmDeleteAll(this->CompileOptionsEntries);
   cmDeleteAll(this->CompileFeaturesEntries);
   cmDeleteAll(this->CompileDefinitionsEntries);
+  cmDeleteAll(this->SourceEntries);
   cmDeleteAll(this->LinkInformation);
   this->LinkInformation.clear();
 }
@@ -314,24 +329,100 @@ cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
 }
 
 //----------------------------------------------------------------------------
-int cmGeneratorTarget::GetType() const
+cmState::TargetType cmGeneratorTarget::GetType() const
 {
   return this->Target->GetType();
 }
 
 //----------------------------------------------------------------------------
-std::string cmGeneratorTarget::GetName() const
+const std::string& cmGeneratorTarget::GetName() const
 {
   return this->Target->GetName();
 }
 
 //----------------------------------------------------------------------------
+std::string cmGeneratorTarget::GetExportName() const
+{
+  const char *exportName = this->GetProperty("EXPORT_NAME");
+
+  if (exportName && *exportName)
+    {
+    if (!cmGeneratorExpression::IsValidTargetName(exportName))
+      {
+      std::ostringstream e;
+      e << "EXPORT_NAME property \"" << exportName << "\" for \""
+        << this->GetName() << "\": is not valid.";
+      cmSystemTools::Error(e.str().c_str());
+      return "";
+      }
+    return exportName;
+    }
+  return this->GetName();
+}
+
+//----------------------------------------------------------------------------
 const char *cmGeneratorTarget::GetProperty(const std::string& prop) const
 {
   return this->Target->GetProperty(prop);
 }
 
 //----------------------------------------------------------------------------
+const char* cmGeneratorTarget::GetOutputTargetType(bool implib) const
+{
+  switch(this->GetType())
+    {
+    case cmState::SHARED_LIBRARY:
+      if(this->IsDLLPlatform())
+        {
+        if(implib)
+          {
+          // A DLL import library is treated as an archive target.
+          return "ARCHIVE";
+          }
+        else
+          {
+          // A DLL shared library is treated as a runtime target.
+          return "RUNTIME";
+          }
+        }
+      else
+        {
+        // For non-DLL platforms shared libraries are treated as
+        // library targets.
+        return "LIBRARY";
+        }
+    case cmState::STATIC_LIBRARY:
+      // Static libraries are always treated as archive targets.
+      return "ARCHIVE";
+    case cmState::MODULE_LIBRARY:
+      if(implib)
+        {
+        // Module libraries are always treated as library targets.
+        return "ARCHIVE";
+        }
+      else
+        {
+        // Module import libraries are treated as archive targets.
+        return "LIBRARY";
+        }
+    case cmState::EXECUTABLE:
+      if(implib)
+        {
+        // Executable import libraries are treated as archive targets.
+        return "ARCHIVE";
+        }
+      else
+        {
+        // Executables are always treated as runtime targets.
+        return "RUNTIME";
+        }
+    default:
+      break;
+    }
+  return "";
+}
+
+//----------------------------------------------------------------------------
 std::string cmGeneratorTarget::GetOutputName(const std::string& config,
                                              bool implib) const
 {
@@ -347,7 +438,7 @@ std::string cmGeneratorTarget::GetOutputName(const std::string& config,
 
     // Compute output name.
     std::vector<std::string> props;
-    std::string type = this->Target->GetOutputTargetType(implib);
+    std::string type = this->GetOutputTargetType(implib);
     std::string configUpper = cmSystemTools::UpperCase(config);
     if(!type.empty() && !configUpper.empty())
       {
@@ -373,7 +464,7 @@ std::string cmGeneratorTarget::GetOutputName(const std::string& config,
     for(std::vector<std::string>::const_iterator it = props.begin();
         it != props.end(); ++it)
       {
-      if (const char* outNameProp = this->Target->GetProperty(*it))
+      if (const char* outNameProp = this->GetProperty(*it))
         {
         outName = outNameProp;
         break;
@@ -388,35 +479,67 @@ std::string cmGeneratorTarget::GetOutputName(const std::string& config,
     // Now evaluate genex and update the previously-prepared map entry.
     cmGeneratorExpression ge;
     cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
-    i->second = cge->Evaluate(this->Makefile, config);
+    i->second = cge->Evaluate(this->LocalGenerator, config);
     }
   else if(i->second.empty())
     {
     // An empty map entry indicates we have been called recursively
     // from the above block.
-    this->Makefile->GetCMakeInstance()->IssueMessage(
+    this->LocalGenerator->GetCMakeInstance()
+          ->IssueMessage(
       cmake::FATAL_ERROR,
       "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
-      this->Target->GetBacktrace());
+      this->GetBacktrace());
     }
   return i->second;
 }
 
+void cmGeneratorTarget::AddSource(const std::string& src)
+{
+  this->Target->AddSource(src);
+  cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+  cmGeneratorExpression ge(lfbt);
+  cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
+  cge->SetEvaluateForBuildsystem(true);
+  this->SourceEntries.push_back(
+                        new TargetPropertyEntry(cge));
+  this->SourceFilesMap.clear();
+  this->LinkImplementationLanguageIsContextDependent = true;
+}
+
+void cmGeneratorTarget::AddTracedSources(std::vector<std::string> const& srcs)
+{
+  this->Target->AddTracedSources(srcs);
+  if (!srcs.empty())
+    {
+    std::string srcFiles = cmJoin(srcs, ";");
+    this->SourceFilesMap.clear();
+    this->LinkImplementationLanguageIsContextDependent = true;
+    cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+    cmGeneratorExpression ge(lfbt);
+    cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(srcFiles);
+    cge->SetEvaluateForBuildsystem(true);
+    this->SourceEntries.push_back(
+          new cmGeneratorTarget::TargetPropertyEntry(cge));
+    }
+}
+
 //----------------------------------------------------------------------------
 std::vector<cmSourceFile*> const*
 cmGeneratorTarget::GetSourceDepends(cmSourceFile const* sf) const
 {
-  SourceEntriesType::const_iterator i = this->SourceEntries.find(sf);
-  if(i != this->SourceEntries.end())
+  SourceEntriesType::const_iterator i = this->SourceDepends.find(sf);
+  if(i != this->SourceDepends.end())
     {
     return &i->second.Depends;
     }
   return 0;
 }
 
-static void handleSystemIncludesDep(cmMakefile *mf, cmTarget const* depTgt,
+static void handleSystemIncludesDep(cmLocalGenerator *lg,
+                                  cmGeneratorTarget const* depTgt,
                                   const std::string& config,
-                                  cmTarget *headTarget,
+                                  cmGeneratorTarget const* headTarget,
                                   cmGeneratorExpressionDAGChecker *dagChecker,
                                   std::vector<std::string>& result,
                                   bool excludeImported)
@@ -426,7 +549,7 @@ static void handleSystemIncludesDep(cmMakefile *mf, cmTarget const* depTgt,
     {
     cmGeneratorExpression ge;
     cmSystemTools::ExpandListArgument(ge.Parse(dirs)
-                                      ->Evaluate(mf,
+                                      ->Evaluate(lg,
                                       config, false, headTarget,
                                       depTgt, dagChecker), result);
     }
@@ -440,7 +563,7 @@ static void handleSystemIncludesDep(cmMakefile *mf, cmTarget const* depTgt,
     {
     cmGeneratorExpression ge;
     cmSystemTools::ExpandListArgument(ge.Parse(dirs)
-                                      ->Evaluate(mf,
+                                      ->Evaluate(lg,
                                       config, false, headTarget,
                                       depTgt, dagChecker), result);
     }
@@ -449,8 +572,8 @@ static void handleSystemIncludesDep(cmMakefile *mf, cmTarget const* depTgt,
 #define IMPLEMENT_VISIT_IMPL(DATA, DATATYPE) \
   { \
   std::vector<cmSourceFile*> sourceFiles; \
-  this->Target->GetSourceFiles(sourceFiles, config); \
-  TagVisitor<DATA ## Tag DATATYPE> visitor(this, data); \
+  this->GetSourceFiles(sourceFiles, config); \
+  TagVisitor< DATA##Tag DATATYPE > visitor(this, data); \
   for(std::vector<cmSourceFile*>::const_iterator si = sourceFiles.begin(); \
       si != sourceFiles.end(); ++si) \
     { \
@@ -517,12 +640,12 @@ const char* cmGeneratorTarget::GetFeature(const std::string& feature,
     std::string featureConfig = feature;
     featureConfig += "_";
     featureConfig += cmSystemTools::UpperCase(config);
-    if(const char* value = this->Target->GetProperty(featureConfig))
+    if(const char* value = this->GetProperty(featureConfig))
       {
       return value;
       }
     }
-  if(const char* value = this->Target->GetProperty(feature))
+  if(const char* value = this->GetProperty(feature))
     {
     return value;
     }
@@ -665,7 +788,24 @@ cmGeneratorTarget::GetExpectedXamlSources(std::set<std::string>& srcs,
 {
   XamlData data;
   IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
-  srcs = data.ExpectedXamlSources;
+      srcs = data.ExpectedXamlSources;
+}
+
+std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const
+{
+  if(!this->UtilityItemsDone)
+    {
+    this->UtilityItemsDone = true;
+    std::set<std::string> const& utilities = this->GetUtilities();
+    for(std::set<std::string>::const_iterator i = utilities.begin();
+        i != utilities.end(); ++i)
+      {
+      cmGeneratorTarget* gt =
+          this->LocalGenerator->FindGeneratorTargetToUse(*i);
+      this->UtilityItems.insert(cmLinkItem(*i, gt));
+      }
+    }
+  return this->UtilityItems;
 }
 
 //----------------------------------------------------------------------------
@@ -682,7 +822,7 @@ void cmGeneratorTarget
 const char* cmGeneratorTarget::GetLocation(const std::string& config) const
 {
   static std::string location;
-  if (this->Target->IsImported())
+  if (this->IsImported())
     {
     location = this->Target->ImportedGetFullPath(config, false);
     }
@@ -693,11 +833,34 @@ const char* cmGeneratorTarget::GetLocation(const std::string& config) const
   return location.c_str();
 }
 
+std::vector<cmCustomCommand> const&
+cmGeneratorTarget::GetPreBuildCommands() const
+{
+  return this->Target->GetPreBuildCommands();
+}
+
+std::vector<cmCustomCommand> const&
+cmGeneratorTarget::GetPreLinkCommands() const
+{
+  return this->Target->GetPreLinkCommands();
+}
+
+std::vector<cmCustomCommand> const&
+cmGeneratorTarget::GetPostBuildCommands() const
+{
+  return this->Target->GetPostBuildCommands();
+}
+
 bool cmGeneratorTarget::IsImported() const
 {
   return this->Target->IsImported();
 }
 
+bool cmGeneratorTarget::IsImportedGloballyVisible() const
+{
+  return this->Target->IsImportedGloballyVisible();
+}
+
 //----------------------------------------------------------------------------
 const char* cmGeneratorTarget::GetLocationForBuild() const
 {
@@ -709,7 +872,7 @@ const char* cmGeneratorTarget::GetLocationForBuild() const
     }
 
   // Now handle the deprecated build-time configuration location.
-  location = this->Target->GetDirectory();
+  location = this->GetDirectory();
   const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
   if(cfgid && strcmp(cfgid, ".") != 0)
     {
@@ -717,7 +880,7 @@ const char* cmGeneratorTarget::GetLocationForBuild() const
     location += cfgid;
     }
 
-  if(this->Target->IsAppBundleOnApple())
+  if(this->IsAppBundleOnApple())
     {
     std::string macdir = this->BuildMacContentDirectory("", "",
                                                                 false);
@@ -737,7 +900,7 @@ const char* cmGeneratorTarget::GetLocationForBuild() const
 bool cmGeneratorTarget::IsSystemIncludeDirectory(const std::string& dir,
                                               const std::string& config) const
 {
-  assert(this->GetType() != cmTarget::INTERFACE_LIBRARY);
+  assert(this->GetType() != cmState::INTERFACE_LIBRARY);
   std::string config_upper;
   if(!config.empty())
     {
@@ -755,7 +918,7 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory(const std::string& dir,
                                         "SYSTEM_INCLUDE_DIRECTORIES", 0, 0);
 
     bool excludeImported
-                = this->Target->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
+                = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
 
     std::vector<std::string> result;
     for (std::set<std::string>::const_iterator
@@ -764,17 +927,17 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory(const std::string& dir,
       {
       cmGeneratorExpression ge;
       cmSystemTools::ExpandListArgument(ge.Parse(*it)
-                                          ->Evaluate(this->Makefile,
-                                          config, false, this->Target,
+                                          ->Evaluate(this->LocalGenerator,
+                                          config, false, this,
                                           &dagChecker), result);
       }
 
-    std::vector<cmTarget const*> const& deps =
+    std::vector<cmGeneratorTarget const*> const& deps =
       this->GetLinkImplementationClosure(config);
-    for(std::vector<cmTarget const*>::const_iterator
+    for(std::vector<cmGeneratorTarget const*>::const_iterator
           li = deps.begin(), le = deps.end(); li != le; ++li)
       {
-      handleSystemIncludesDep(this->Makefile, *li, config, this->Target,
+      handleSystemIncludesDep(this->LocalGenerator, *li, config, this,
                               &dagChecker, result, excludeImported);
       }
 
@@ -802,10 +965,258 @@ bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
 }
 
 //----------------------------------------------------------------------------
+static void AddInterfaceEntries(
+  cmGeneratorTarget const* thisTarget, std::string const& config,
+  std::string const& prop,
+  std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries)
+{
+  if(cmLinkImplementationLibraries const* impl =
+     thisTarget->GetLinkImplementationLibraries(config))
+    {
+    for (std::vector<cmLinkImplItem>::const_iterator
+           it = impl->Libraries.begin(), end = impl->Libraries.end();
+         it != end; ++it)
+      {
+      if(it->Target)
+        {
+        std::string genex =
+          "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
+        cmGeneratorExpression ge(it->Backtrace);
+        cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
+        cge->SetEvaluateForBuildsystem(true);
+        entries.push_back(
+          new cmGeneratorTarget::TargetPropertyEntry(cge, *it));
+        }
+      }
+    }
+}
+
+//----------------------------------------------------------------------------
+static bool processSources(cmGeneratorTarget const* tgt,
+      const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
+      std::vector<std::string> &srcs,
+      UNORDERED_SET<std::string> &uniqueSrcs,
+      cmGeneratorExpressionDAGChecker *dagChecker,
+      std::string const& config, bool debugSources)
+{
+  cmMakefile *mf = tgt->Target->GetMakefile();
+
+  bool contextDependent = false;
+
+  for (std::vector<cmGeneratorTarget::TargetPropertyEntry*>::const_iterator
+      it = entries.begin(), end = entries.end(); it != end; ++it)
+    {
+    cmLinkImplItem const& item = (*it)->LinkImplItem;
+    std::string const& targetName = item;
+    std::vector<std::string> entrySources;
+    cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(
+                                              tgt->GetLocalGenerator(),
+                                              config,
+                                              false,
+                                              tgt,
+                                              tgt,
+                                              dagChecker),
+                                    entrySources);
+
+    if ((*it)->ge->GetHadContextSensitiveCondition())
+      {
+      contextDependent = true;
+      }
+
+    for(std::vector<std::string>::iterator i = entrySources.begin();
+        i != entrySources.end(); ++i)
+      {
+      std::string& src = *i;
+      cmSourceFile* sf = mf->GetOrCreateSource(src);
+      std::string e;
+      std::string fullPath = sf->GetFullPath(&e);
+      if(fullPath.empty())
+        {
+        if(!e.empty())
+          {
+          cmake* cm = tgt->GetLocalGenerator()->GetCMakeInstance();
+          cm->IssueMessage(cmake::FATAL_ERROR, e,
+                          tgt->GetBacktrace());
+          }
+        return contextDependent;
+        }
+
+      if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src.c_str()))
+        {
+        std::ostringstream err;
+        if (!targetName.empty())
+          {
+          err << "Target \"" << targetName << "\" contains relative "
+            "path in its INTERFACE_SOURCES:\n"
+            "  \"" << src << "\"";
+          }
+        else
+          {
+          err << "Found relative path while evaluating sources of "
+          "\"" << tgt->GetName() << "\":\n  \"" << src << "\"\n";
+          }
+        tgt->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, err.str());
+        return contextDependent;
+        }
+      src = fullPath;
+      }
+    std::string usedSources;
+    for(std::vector<std::string>::iterator
+          li = entrySources.begin(); li != entrySources.end(); ++li)
+      {
+      std::string src = *li;
+
+      if(uniqueSrcs.insert(src).second)
+        {
+        srcs.push_back(src);
+        if (debugSources)
+          {
+          usedSources += " * " + src + "\n";
+          }
+        }
+      }
+    if (!usedSources.empty())
+      {
+      tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(cmake::LOG,
+                            std::string("Used sources for target ")
+                            + tgt->GetName() + ":\n"
+                            + usedSources, (*it)->ge->GetBacktrace());
+      }
+    }
+  return contextDependent;
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorTarget::GetSourceFiles(std::vector<std::string> &files,
+                              const std::string& config) const
+{
+  assert(this->GetType() != cmState::INTERFACE_LIBRARY);
+
+  if (!this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026())
+    {
+    // At configure-time, this method can be called as part of getting the
+    // LOCATION property or to export() a file to be include()d.  However
+    // there is no cmGeneratorTarget at configure-time, so search the SOURCES
+    // for TARGET_OBJECTS instead for backwards compatibility with OLD
+    // behavior of CMP0024 and CMP0026 only.
+
+    cmStringRange sourceEntries = this->Target->GetSourceEntries();
+    for(cmStringRange::const_iterator
+          i = sourceEntries.begin();
+        i != sourceEntries.end(); ++i)
+      {
+      std::string const& entry = *i;
+
+      std::vector<std::string> items;
+      cmSystemTools::ExpandListArgument(entry, items);
+      for (std::vector<std::string>::const_iterator
+          li = items.begin(); li != items.end(); ++li)
+        {
+        if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
+            (*li)[li->size() - 1] == '>')
+          {
+          continue;
+          }
+        files.push_back(*li);
+        }
+      }
+    return;
+    }
+
+  std::vector<std::string> debugProperties;
+  const char *debugProp =
+              this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
+  if (debugProp)
+    {
+    cmSystemTools::ExpandListArgument(debugProp, debugProperties);
+    }
+
+  bool debugSources = !this->DebugSourcesDone
+                    && std::find(debugProperties.begin(),
+                                 debugProperties.end(),
+                                 "SOURCES")
+                        != debugProperties.end();
+
+  if (this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026())
+    {
+    this->DebugSourcesDone = true;
+    }
+
+  cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
+                                             "SOURCES", 0, 0);
+
+  UNORDERED_SET<std::string> uniqueSrcs;
+  bool contextDependentDirectSources = processSources(this,
+                 this->SourceEntries,
+                 files,
+                 uniqueSrcs,
+                 &dagChecker,
+                 config,
+                 debugSources);
+
+  std::vector<cmGeneratorTarget::TargetPropertyEntry*>
+    linkInterfaceSourcesEntries;
+
+  AddInterfaceEntries(
+    this, config, "INTERFACE_SOURCES",
+    linkInterfaceSourcesEntries);
+
+  std::vector<std::string>::size_type numFilesBefore = files.size();
+  bool contextDependentInterfaceSources = processSources(this,
+    linkInterfaceSourcesEntries,
+                            files,
+                            uniqueSrcs,
+                            &dagChecker,
+                            config,
+                            debugSources);
+
+  if (!contextDependentDirectSources
+      && !(contextDependentInterfaceSources && numFilesBefore < files.size()))
+    {
+    this->LinkImplementationLanguageIsContextDependent = false;
+    }
+
+  cmDeleteAll(linkInterfaceSourcesEntries);
+}
+
+//----------------------------------------------------------------------------
 void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
                                        const std::string& config) const
 {
-  this->Target->GetSourceFiles(files, config);
+
+  // Lookup any existing link implementation for this configuration.
+  std::string key = cmSystemTools::UpperCase(config);
+
+  if(!this->LinkImplementationLanguageIsContextDependent)
+    {
+    files = this->SourceFilesMap.begin()->second;
+    return;
+    }
+
+  SourceFilesMapType::iterator
+    it = this->SourceFilesMap.find(key);
+  if(it != this->SourceFilesMap.end())
+    {
+    files = it->second;
+    }
+  else
+    {
+    std::vector<std::string> srcs;
+    this->GetSourceFiles(srcs, config);
+
+    std::set<cmSourceFile*> emitted;
+
+    for(std::vector<std::string>::const_iterator i = srcs.begin();
+        i != srcs.end(); ++i)
+      {
+      cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
+      if (emitted.insert(sf).second)
+        {
+        files.push_back(sf);
+        }
+      }
+    this->SourceFilesMap[key] = files;
+    }
 }
 
 //----------------------------------------------------------------------------
@@ -821,13 +1232,13 @@ cmGeneratorTarget::GetCompilePDBName(const std::string& config) const
   std::string configUpper = cmSystemTools::UpperCase(config);
   std::string configProp = "COMPILE_PDB_NAME_";
   configProp += configUpper;
-  const char* config_name = this->Target->GetProperty(configProp);
+  const char* config_name = this->GetProperty(configProp);
   if(config_name && *config_name)
     {
     return prefix + config_name + ".pdb";
     }
 
-  const char* name = this->Target->GetProperty("COMPILE_PDB_NAME");
+  const char* name = this->GetProperty("COMPILE_PDB_NAME");
   if(name && *name)
     {
     return prefix + name + ".pdb";
@@ -844,7 +1255,7 @@ cmGeneratorTarget::GetCompilePDBPath(const std::string& config) const
   std::string name = this->GetCompilePDBName(config);
   if(dir.empty() && !name.empty())
     {
-    dir = this->Target->GetPDBDirectory(config);
+    dir = this->GetPDBDirectory(config);
     }
   if(!dir.empty())
     {
@@ -858,7 +1269,7 @@ bool cmGeneratorTarget::HasSOName(const std::string& config) const
 {
   // soname is supported only for shared libraries and modules,
   // and then only when the platform supports an soname flag.
-  return ((this->GetType() == cmTarget::SHARED_LIBRARY) &&
+  return ((this->GetType() == cmState::SHARED_LIBRARY) &&
           !this->GetPropertyAsBool("NO_SONAME") &&
           this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
 }
@@ -869,9 +1280,9 @@ cmGeneratorTarget::NeedRelinkBeforeInstall(const std::string& config) const
 {
   // Only executables and shared libraries can have an rpath and may
   // need relinking.
-  if(this->GetType() != cmTarget::EXECUTABLE &&
-     this->GetType() != cmTarget::SHARED_LIBRARY &&
-     this->GetType() != cmTarget::MODULE_LIBRARY)
+  if(this->GetType() != cmState::EXECUTABLE &&
+     this->GetType() != cmState::SHARED_LIBRARY &&
+     this->GetType() != cmState::MODULE_LIBRARY)
     {
     return false;
     }
@@ -926,16 +1337,16 @@ cmGeneratorTarget::NeedRelinkBeforeInstall(const std::string& config) const
   // will likely change between the build tree and install tree and
   // this target must be relinked.
   return this->HaveBuildTreeRPATH(config)
-      || this->Target->HaveInstallTreeRPATH();
+      || this->HaveInstallTreeRPATH();
 }
 
 //----------------------------------------------------------------------------
 bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
 {
   // Only certain target types have an rpath.
-  if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
-       this->GetType() == cmTarget::MODULE_LIBRARY ||
-       this->GetType() == cmTarget::EXECUTABLE))
+  if(!(this->GetType() == cmState::SHARED_LIBRARY ||
+       this->GetType() == cmState::MODULE_LIBRARY ||
+       this->GetType() == cmState::EXECUTABLE))
     {
     return false;
     }
@@ -996,38 +1407,168 @@ bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
   return false;
 }
 
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::IsImportedSharedLibWithoutSOName(
+                                          const std::string& config) const
+{
+  if(this->IsImported() && this->GetType() == cmState::SHARED_LIBRARY)
+    {
+    if(cmGeneratorTarget::ImportInfo const* info =
+       this->GetImportInfo(config))
+      {
+      return info->NoSOName;
+      }
+    }
+  return false;
+}
 
 //----------------------------------------------------------------------------
-std::string cmGeneratorTarget::GetSOName(const std::string& config) const
+bool cmGeneratorTarget::HasMacOSXRpathInstallNameDir(
+    const std::string& config) const
 {
-  if(this->Target->IsImported())
+  bool install_name_is_rpath = false;
+  bool macosx_rpath = false;
+
+  if(!this->IsImported())
+    {
+    if(this->GetType() != cmState::SHARED_LIBRARY)
+      {
+      return false;
+      }
+    const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
+    bool use_install_name =
+      this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
+    if(install_name && use_install_name &&
+       std::string(install_name) == "@rpath")
+      {
+      install_name_is_rpath = true;
+      }
+    else if(install_name && use_install_name)
+      {
+      return false;
+      }
+    if(!install_name_is_rpath)
+      {
+      macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
+      }
+    }
+  else
     {
     // Lookup the imported soname.
-    if(cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config))
+    if(cmGeneratorTarget::ImportInfo const* info =
+       this->GetImportInfo(config))
       {
-      if(info->NoSOName)
+      if(!info->NoSOName && !info->SOName.empty())
         {
-        // The imported library has no builtin soname so the name
-        // searched at runtime will be just the filename.
-        return cmSystemTools::GetFilenameName(info->Location);
+        if(info->SOName.find("@rpath/") == 0)
+          {
+          install_name_is_rpath = true;
+          }
         }
       else
         {
-        // Use the soname given if any.
-        if(info->SOName.find("@rpath/") == 0)
+        std::string install_name;
+        cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
+        if(install_name.find("@rpath") != std::string::npos)
           {
-          return info->SOName.substr(6);
+          install_name_is_rpath = true;
           }
-        return info->SOName;
         }
       }
+    }
+
+  if(!install_name_is_rpath && !macosx_rpath)
+    {
+    return false;
+    }
+
+  if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
+    {
+    std::ostringstream w;
+    w << "Attempting to use";
+    if(macosx_rpath)
+      {
+      w << " MACOSX_RPATH";
+      }
     else
       {
-      return "";
+      w << " @rpath";
       }
+    w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
+    w << "  This could be because you are using a Mac OS X version";
+    w << " less than 10.5 or because CMake's platform configuration is";
+    w << " corrupt.";
+    cmake* cm = this->LocalGenerator->GetCMakeInstance();
+    cm->IssueMessage(cmake::FATAL_ERROR, w.str(),
+                     this->GetBacktrace());
     }
-  else
-    {
+
+  return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::MacOSXRpathInstallNameDirDefault() const
+{
+  // we can't do rpaths when unsupported
+  if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
+    {
+    return false;
+    }
+
+  const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
+  if(macosx_rpath_str)
+    {
+    return this->GetPropertyAsBool("MACOSX_RPATH");
+    }
+
+  cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
+
+  if(cmp0042 == cmPolicies::WARN)
+    {
+    this->LocalGenerator->GetGlobalGenerator()->
+      AddCMP0042WarnTarget(this->GetName());
+    }
+
+  if(cmp0042 == cmPolicies::NEW)
+    {
+    return true;
+    }
+
+  return false;
+}
+
+//----------------------------------------------------------------------------
+std::string cmGeneratorTarget::GetSOName(const std::string& config) const
+{
+  if(this->IsImported())
+    {
+    // Lookup the imported soname.
+    if(cmGeneratorTarget::ImportInfo const* info =
+       this->GetImportInfo(config))
+      {
+      if(info->NoSOName)
+        {
+        // The imported library has no builtin soname so the name
+        // searched at runtime will be just the filename.
+        return cmSystemTools::GetFilenameName(info->Location);
+        }
+      else
+        {
+        // Use the soname given if any.
+        if(info->SOName.find("@rpath/") == 0)
+          {
+          return info->SOName.substr(6);
+          }
+        return info->SOName;
+        }
+      }
+    else
+      {
+      return "";
+      }
+    }
+  else
+    {
     // Compute the soname that will be built.
     std::string name;
     std::string soName;
@@ -1060,9 +1601,9 @@ cmGeneratorTarget::GetAppBundleDirectory(const std::string& config,
 //----------------------------------------------------------------------------
 bool cmGeneratorTarget::IsBundleOnApple() const
 {
-  return this->Target->IsFrameworkOnApple()
-      || this->Target->IsAppBundleOnApple()
-      || this->Target->IsCFBundleOnApple();
+  return this->IsFrameworkOnApple()
+      || this->IsAppBundleOnApple()
+      || this->IsCFBundleOnApple();
 }
 
 //----------------------------------------------------------------------------
@@ -1072,10 +1613,10 @@ std::string cmGeneratorTarget::GetCFBundleDirectory(const std::string& config,
   std::string fpath;
   fpath += this->GetOutputName(config, false);
   fpath += ".";
-  const char *ext = this->Target->GetProperty("BUNDLE_EXTENSION");
+  const char *ext = this->GetProperty("BUNDLE_EXTENSION");
   if (!ext)
     {
-    if (this->Target->IsXCTestOnApple())
+    if (this->IsXCTestOnApple())
       {
       ext = "xctest";
       }
@@ -1105,7 +1646,7 @@ cmGeneratorTarget::GetFrameworkDirectory(const std::string& config,
   if(!rootDir && !this->Makefile->PlatformIsAppleIos())
     {
     fpath += "/Versions/";
-    fpath += this->Target->GetFrameworkVersion();
+    fpath += this->GetFrameworkVersion();
     }
   return fpath;
 }
@@ -1114,9 +1655,9 @@ cmGeneratorTarget::GetFrameworkDirectory(const std::string& config,
 std::string
 cmGeneratorTarget::GetFullName(const std::string& config, bool implib) const
 {
-  if(this->Target->IsImported())
+  if(this->IsImported())
     {
-    return this->Target->GetFullNameImported(config, implib);
+    return this->GetFullNameImported(config, implib);
     }
   else
     {
@@ -1142,13 +1683,13 @@ cmGeneratorTarget::GetInstallNameDirForBuildTree(
      !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
     {
     std::string dir;
-    if(this->Target->MacOSXRpathInstallNameDirDefault())
+    if(this->MacOSXRpathInstallNameDirDefault())
       {
       dir = "@rpath";
       }
     else
       {
-      dir = this->Target->GetDirectory(config);
+      dir = this->GetDirectory(config);
       }
     dir += "/";
     return dir;
@@ -1178,7 +1719,7 @@ std::string cmGeneratorTarget::GetInstallNameDirForInstallTree() const
       }
     if(!install_name_dir)
       {
-      if(this->Target->MacOSXRpathInstallNameDirDefault())
+      if(this->MacOSXRpathInstallNameDirDefault())
         {
         dir = "@rpath/";
         }
@@ -1191,6 +1732,63 @@ std::string cmGeneratorTarget::GetInstallNameDirForInstallTree() const
     }
 }
 
+cmListFileBacktrace cmGeneratorTarget::GetBacktrace() const
+{
+  return this->Target->GetBacktrace();
+}
+
+const std::vector<std::string>&cmGeneratorTarget::GetLinkDirectories() const
+{
+  return this->Target->GetLinkDirectories();
+}
+
+const std::set<std::string>& cmGeneratorTarget::GetUtilities() const
+{
+  return this->Target->GetUtilities();
+}
+
+const cmListFileBacktrace*
+cmGeneratorTarget::GetUtilityBacktrace(const std::string& u) const
+{
+  return this->Target->GetUtilityBacktrace(u);
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::HaveWellDefinedOutputFiles() const
+{
+  return
+    this->GetType() == cmState::STATIC_LIBRARY ||
+    this->GetType() == cmState::SHARED_LIBRARY ||
+    this->GetType() == cmState::MODULE_LIBRARY ||
+    this->GetType() == cmState::EXECUTABLE;
+}
+
+//----------------------------------------------------------------------------
+const char* cmGeneratorTarget::GetExportMacro() const
+{
+  // Define the symbol for targets that export symbols.
+  if(this->GetType() == cmState::SHARED_LIBRARY ||
+     this->GetType() == cmState::MODULE_LIBRARY ||
+     this->IsExecutableWithExports())
+    {
+    if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
+      {
+      this->ExportMacro = custom_export_name;
+      }
+    else
+      {
+      std::string in = this->GetName();
+      in += "_EXPORTS";
+      this->ExportMacro = cmSystemTools::MakeCidentifier(in);
+      }
+    return this->ExportMacro.c_str();
+    }
+  else
+    {
+    return 0;
+    }
+}
+
 //----------------------------------------------------------------------------
 class cmTargetCollectLinkLanguages
 {
@@ -1198,10 +1796,10 @@ public:
   cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
                                const std::string& config,
                                UNORDERED_SET<std::string>& languages,
-                               cmTarget const* head):
+                               cmGeneratorTarget const* head):
     Config(config), Languages(languages), HeadTarget(head),
-    Makefile(target->Target->GetMakefile()), Target(target)
-  { this->Visited.insert(target->Target); }
+    Target(target)
+  { this->Visited.insert(target); }
 
   void Visit(cmLinkItem const& item)
     {
@@ -1212,7 +1810,8 @@ public:
         bool noMessage = false;
         cmake::MessageType messageType = cmake::FATAL_ERROR;
         std::stringstream e;
-        switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0028))
+        switch(this->Target->GetLocalGenerator()
+               ->GetPolicyStatus(cmPolicies::CMP0028))
           {
           case cmPolicies::WARN:
             {
@@ -1236,8 +1835,8 @@ public:
             << "\" but the target was not found.  Perhaps a find_package() "
             "call is missing for an IMPORTED target, or an ALIAS target is "
             "missing?";
-          this->Makefile->GetCMakeInstance()->IssueMessage(
-            messageType, e.str(), this->Target->Target->GetBacktrace());
+          this->Target->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
+            messageType, e.str(), this->Target->GetBacktrace());
           }
         }
       return;
@@ -1246,11 +1845,8 @@ public:
       {
       return;
       }
-    cmGeneratorTarget* gtgt =
-        this->Target->GetLocalGenerator()->GetGlobalGenerator()
-            ->GetGeneratorTarget(item.Target);
     cmLinkInterface const* iface =
-      gtgt->GetLinkInterface(this->Config, this->HeadTarget);
+      item.Target->GetLinkInterface(this->Config, this->HeadTarget);
     if(!iface) { return; }
 
     for(std::vector<std::string>::const_iterator
@@ -1268,10 +1864,9 @@ public:
 private:
   std::string Config;
   UNORDERED_SET<std::string>& Languages;
-  cmTarget const* HeadTarget;
-  cmMakefile* Makefile;
+  cmGeneratorTarget const* HeadTarget;
   const cmGeneratorTarget* Target;
-  std::set<cmTarget const*> Visited;
+  std::set<cmGeneratorTarget const*> Visited;
 };
 
 //----------------------------------------------------------------------------
@@ -1296,14 +1891,12 @@ class cmTargetSelectLinker
 {
   int Preference;
   cmGeneratorTarget const* Target;
-  cmMakefile* Makefile;
   cmGlobalGenerator* GG;
   std::set<std::string> Preferred;
 public:
   cmTargetSelectLinker(cmGeneratorTarget const* target)
       : Preference(0), Target(target)
     {
-    this->Makefile = this->Target->Makefile;
     this->GG = this->Target->GetLocalGenerator()->GetGlobalGenerator();
     }
   void Consider(const char* lang)
@@ -1337,9 +1930,9 @@ public:
         e << "  " << *li << "\n";
         }
       e << "Set the LINKER_LANGUAGE property for this target.";
-      cmake* cm = this->Makefile->GetCMakeInstance();
+      cmake* cm = this->Target->GetLocalGenerator()->GetCMakeInstance();
       cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
-                       this->Target->Target->GetBacktrace());
+                       this->Target->GetBacktrace());
       }
     return *this->Preferred.begin();
     }
@@ -1361,7 +1954,7 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
     }
 
   // Add interface languages from linked targets.
-  cmTargetCollectLinkLanguages cll(this, config, languages, this->Target);
+  cmTargetCollectLinkLanguages cll(this, config, languages, this);
   for(std::vector<cmLinkImplItem>::const_iterator li = impl->Libraries.begin();
       li != impl->Libraries.end(); ++li)
     {
@@ -1428,15 +2021,15 @@ cmGeneratorTarget::BuildMacContentDirectory(const std::string& base,
                                             bool contentOnly) const
 {
   std::string fpath = base;
-  if(this->Target->IsAppBundleOnApple())
+  if(this->IsAppBundleOnApple())
     {
     fpath += this->GetAppBundleDirectory(config, contentOnly);
     }
-  if(this->Target->IsFrameworkOnApple())
+  if(this->IsFrameworkOnApple())
     {
     fpath += this->GetFrameworkDirectory(config, contentOnly);
     }
-  if(this->Target->IsCFBundleOnApple())
+  if(this->IsCFBundleOnApple())
     {
     fpath += this->GetCFBundleDirectory(config, contentOnly);
     }
@@ -1449,10 +2042,10 @@ cmGeneratorTarget::GetMacContentDirectory(const std::string& config,
                                           bool implib) const
 {
   // Start with the output directory for the target.
-  std::string fpath = this->Target->GetDirectory(config, implib);
+  std::string fpath = this->GetDirectory(config, implib);
   fpath += "/";
   bool contentOnly = true;
-  if(this->Target->IsFrameworkOnApple())
+  if(this->IsFrameworkOnApple())
     {
     // additional files with a framework go into the version specific
     // directory
@@ -1473,12 +2066,12 @@ cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
     return 0;
     }
 
-  if(this->GetType() > cmTarget::OBJECT_LIBRARY)
+  if(this->GetType() > cmState::OBJECT_LIBRARY)
     {
     std::string msg = "cmTarget::GetCompileInfo called for ";
     msg += this->GetName();
     msg += " which has type ";
-    msg += cmTarget::GetTargetTypeName(this->Target->GetType());
+    msg += cmState::GetTargetTypeName(this->GetType());
     this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
     return 0;
     }
@@ -1494,8 +2087,7 @@ cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
   if(i == this->CompileInfoMap.end())
     {
     CompileInfo info;
-    this->Target
-        ->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
+    this->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
     CompileInfoMapType::value_type entry(config_upper, info);
     i = this->CompileInfoMap.insert(entry).first;
     }
@@ -1503,12 +2095,23 @@ cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
 }
 
 //----------------------------------------------------------------------------
-std::string
+cmSourceFile const*
 cmGeneratorTarget::GetModuleDefinitionFile(const std::string& config) const
 {
-  std::string data;
-  IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile, COMMA std::string)
-  return data;
+  std::vector<cmSourceFile const*> data;
+  IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile,
+                       COMMA std::vector<cmSourceFile const*>)
+  if(!data.empty())
+    {
+    return data.front();
+    }
+
+  return 0;
+}
+
+bool cmGeneratorTarget::IsDLLPlatform() const
+{
+  return this->DLLPlatform;
 }
 
 //----------------------------------------------------------------------------
@@ -1518,27 +2121,26 @@ cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs,
 {
   std::vector<cmSourceFile const*> objectFiles;
   this->GetExternalObjects(objectFiles, config);
-  std::vector<cmTarget*> objectLibraries;
+  std::vector<cmGeneratorTarget*> objectLibraries;
   for(std::vector<cmSourceFile const*>::const_iterator
       it = objectFiles.begin(); it != objectFiles.end(); ++it)
     {
     std::string objLib = (*it)->GetObjectLibrary();
-    if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
+    if (cmGeneratorTarget* tgt =
+        this->LocalGenerator->FindGeneratorTargetToUse(objLib))
       {
       objectLibraries.push_back(tgt);
       }
     }
 
-  std::vector<cmTarget*>::const_iterator end
+  std::vector<cmGeneratorTarget*>::const_iterator end
       = cmRemoveDuplicates(objectLibraries);
 
-  for(std::vector<cmTarget*>::const_iterator
+  for(std::vector<cmGeneratorTarget*>::const_iterator
         ti = objectLibraries.begin();
       ti != end; ++ti)
     {
-    cmTarget* objLib = *ti;
-    cmGeneratorTarget* ogt =
-      this->GlobalGenerator->GetGeneratorTarget(objLib);
+    cmGeneratorTarget* ogt = *ti;
     std::vector<cmSourceFile const*> objectSources;
     ogt->GetObjectSources(objectSources, config);
     for(std::vector<cmSourceFile const*>::const_iterator
@@ -1569,28 +2171,27 @@ void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string> &result,
                                       this->GetName(),
                                       "AUTOUIC_OPTIONS", 0, 0);
   cmSystemTools::ExpandListArgument(ge.Parse(prop)
-                                      ->Evaluate(this->Makefile,
+                                      ->Evaluate(this->LocalGenerator,
                                                 config,
                                                 false,
-                                                this->Target,
+                                                this,
                                                 &dagChecker),
                                   result);
 }
 
 //----------------------------------------------------------------------------
 void processILibs(const std::string& config,
-                  cmTarget const* headTarget,
+                  cmGeneratorTarget const* headTarget,
                   cmLinkItem const& item,
                   cmGlobalGenerator* gg,
-                  std::vector<cmTarget const*>& tgts,
-                  std::set<cmTarget const*>& emitted)
+                  std::vector<cmGeneratorTarget const*>& tgts,
+                  std::set<cmGeneratorTarget const*>& emitted)
 {
   if (item.Target && emitted.insert(item.Target).second)
     {
     tgts.push_back(item.Target);
-    cmGeneratorTarget* gt = gg->GetGeneratorTarget(item.Target);
     if(cmLinkInterfaceLibraries const* iface =
-       gt->GetLinkInterfaceLibraries(config, headTarget, true))
+       item.Target->GetLinkInterfaceLibraries(config, headTarget, true))
       {
       for(std::vector<cmLinkItem>::const_iterator
             it = iface->Libraries.begin();
@@ -1603,7 +2204,7 @@ void processILibs(const std::string& config,
 }
 
 //----------------------------------------------------------------------------
-const std::vector<const cmTarget*>&
+const std::vector<const cmGeneratorTarget*>&
 cmGeneratorTarget::GetLinkImplementationClosure(
     const std::string& config) const
 {
@@ -1612,16 +2213,16 @@ cmGeneratorTarget::GetLinkImplementationClosure(
   if(!tgts.Done)
     {
     tgts.Done = true;
-    std::set<cmTarget const*> emitted;
+    std::set<cmGeneratorTarget const*> emitted;
 
     cmLinkImplementationLibraries const* impl
-      = this->Target->GetLinkImplementationLibraries(config);
+      = this->GetLinkImplementationLibraries(config);
 
     for(std::vector<cmLinkImplItem>::const_iterator
           it = impl->Libraries.begin();
         it != impl->Libraries.end(); ++it)
       {
-      processILibs(config, this->Target, *it,
+      processILibs(config, this, *it,
                    this->LocalGenerator->GetGlobalGenerator(),
                    tgts , emitted);
       }
@@ -1636,9 +2237,9 @@ public:
   cmTargetTraceDependencies(cmGeneratorTarget* target);
   void Trace();
 private:
-  cmTarget* Target;
   cmGeneratorTarget* GeneratorTarget;
   cmMakefile* Makefile;
+  cmLocalGenerator* LocalGenerator;
   cmGlobalGenerator const* GlobalGenerator;
   typedef cmGeneratorTarget::SourceEntry SourceEntry;
   SourceEntry* CurrentEntry;
@@ -1662,15 +2263,16 @@ private:
 //----------------------------------------------------------------------------
 cmTargetTraceDependencies
 ::cmTargetTraceDependencies(cmGeneratorTarget* target):
-  Target(target->Target), GeneratorTarget(target)
+  GeneratorTarget(target)
 {
   // Convenience.
-  this->Makefile = this->Target->GetMakefile();
-  this->GlobalGenerator = target->GetLocalGenerator()->GetGlobalGenerator();
+  this->Makefile = target->Target->GetMakefile();
+  this->LocalGenerator = target->GetLocalGenerator();
+  this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
   this->CurrentEntry = 0;
 
   // Queue all the source files already specified for the target.
-  if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
+  if (target->GetType() != cmState::INTERFACE_LIBRARY)
     {
     std::vector<std::string> configs;
     this->Makefile->GetConfigurations(configs);
@@ -1683,14 +2285,14 @@ cmTargetTraceDependencies
         ci != configs.end(); ++ci)
       {
       std::vector<cmSourceFile*> sources;
-      this->Target->GetSourceFiles(sources, *ci);
+      this->GeneratorTarget->GetSourceFiles(sources, *ci);
       for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
           si != sources.end(); ++si)
         {
         cmSourceFile* sf = *si;
-        const std::set<cmTarget const*> tgts =
+        const std::set<cmGeneratorTarget const*> tgts =
                           this->GlobalGenerator->GetFilenameTargetDepends(sf);
-        if (tgts.find(this->Target) != tgts.end())
+        if (tgts.find(this->GeneratorTarget) != tgts.end())
           {
           std::ostringstream e;
           e << "Evaluation output file\n  \"" << sf->GetFullPath()
@@ -1709,9 +2311,12 @@ cmTargetTraceDependencies
     }
 
   // Queue pre-build, pre-link, and post-build rule dependencies.
-  this->CheckCustomCommands(this->Target->GetPreBuildCommands());
-  this->CheckCustomCommands(this->Target->GetPreLinkCommands());
-  this->CheckCustomCommands(this->Target->GetPostBuildCommands());
+  this->CheckCustomCommands(
+        this->GeneratorTarget->GetPreBuildCommands());
+  this->CheckCustomCommands(
+        this->GeneratorTarget->GetPreLinkCommands());
+  this->CheckCustomCommands(
+        this->GeneratorTarget->GetPostBuildCommands());
 }
 
 //----------------------------------------------------------------------------
@@ -1723,7 +2328,7 @@ void cmTargetTraceDependencies::Trace()
     // Get the next source from the queue.
     cmSourceFile* sf = this->SourceQueue.front();
     this->SourceQueue.pop();
-    this->CurrentEntry = &this->GeneratorTarget->SourceEntries[sf];
+    this->CurrentEntry = &this->GeneratorTarget->SourceDepends[sf];
 
     // Queue dependencies added explicitly by the user.
     if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
@@ -1755,7 +2360,7 @@ void cmTargetTraceDependencies::Trace()
     }
   this->CurrentEntry = 0;
 
-  this->Target->AddTracedSources(this->NewSources);
+  this->GeneratorTarget->AddTracedSources(this->NewSources);
 }
 
 //----------------------------------------------------------------------------
@@ -1820,15 +2425,16 @@ bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
 
   // Check for a target with this name.
   if(cmGeneratorTarget* t
-                    = this->Makefile->FindGeneratorTargetToUse(util))
+                    = this->GeneratorTarget->
+                    GetLocalGenerator()->FindGeneratorTargetToUse(util))
     {
     // If we find the target and the dep was given as a full path,
     // then make sure it was not a full path to something else, and
     // the fact that the name matched a target was just a coincidence.
     if(cmSystemTools::FileIsFullPath(dep.c_str()))
       {
-      if(t->GetType() >= cmTarget::EXECUTABLE &&
-         t->GetType() <= cmTarget::MODULE_LIBRARY)
+      if(t->GetType() >= cmState::EXECUTABLE &&
+         t->GetType() <= cmState::MODULE_LIBRARY)
         {
         // This is really only for compatibility so we do not need to
         // worry about configuration names and output names.
@@ -1839,7 +2445,7 @@ bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
         tLocation = cmSystemTools::CollapseFullPath(tLocation);
         if(depLocation == tLocation)
           {
-          this->Target->AddUtility(util);
+          this->GeneratorTarget->Target->AddUtility(util);
           return true;
           }
         }
@@ -1848,7 +2454,7 @@ bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
       {
       // The original name of the dependency was not a full path.  It
       // must name a target, so add the target-level dependency.
-      this->Target->AddUtility(util);
+      this->GeneratorTarget->Target->AddUtility(util);
       return true;
       }
     }
@@ -1867,22 +2473,23 @@ cmTargetTraceDependencies
   cmGeneratorExpression ge(cc.GetBacktrace());
 
   // Add target-level dependencies referenced by generator expressions.
-  std::set<cmTarget*> targets;
+  std::set<cmGeneratorTarget*> targets;
 
   for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
       cit != cc.GetCommandLines().end(); ++cit)
     {
     std::string const& command = *cit->begin();
     // Check for a target with this name.
-    if(cmTarget* t = this->Makefile->FindTargetToUse(command))
+    if(cmGeneratorTarget* t =
+       this->LocalGenerator->FindGeneratorTargetToUse(command))
       {
-      if(t->GetType() == cmTarget::EXECUTABLE)
+      if(t->GetType() == cmState::EXECUTABLE)
         {
         // The command refers to an executable target built in
         // this project.  Add the target-level dependency to make
         // sure the executable is up to date before this custom
         // command possibly runs.
-        this->Target->AddUtility(command);
+        this->GeneratorTarget->Target->AddUtility(command);
         }
       }
 
@@ -1892,16 +2499,16 @@ cmTargetTraceDependencies
       {
       const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
                                                               = ge.Parse(*cli);
-      cge->Evaluate(this->Makefile, "", true);
-      std::set<cmTarget*> geTargets = cge->GetTargets();
+      cge->Evaluate(this->GeneratorTarget->GetLocalGenerator(), "", true);
+      std::set<cmGeneratorTarget*> geTargets = cge->GetTargets();
       targets.insert(geTargets.begin(), geTargets.end());
       }
     }
 
-  for(std::set<cmTarget*>::iterator ti = targets.begin();
+  for(std::set<cmGeneratorTarget*>::iterator ti = targets.begin();
       ti != targets.end(); ++ti)
     {
-    this->Target->AddUtility((*ti)->GetName());
+    this->GeneratorTarget->Target->AddUtility((*ti)->GetName());
     }
 
   // Queue the custom command dependencies.
@@ -1964,7 +2571,7 @@ void cmGeneratorTarget::TraceDependencies()
   // would find nothing anyway, but when building CMake itself the "install"
   // target command ends up referencing the "cmake" target but we do not
   // really want the dependency because "install" depend on "all" anyway.
-  if(this->GetType() == cmTarget::GLOBAL_TARGET)
+  if(this->GetType() == cmState::GLOBAL_TARGET)
     {
     return;
     }
@@ -1993,11 +2600,11 @@ void cmGeneratorTarget::GetAppleArchs(const std::string& config,
     {
     std::string defVarName = "OSX_ARCHITECTURES_";
     defVarName += cmSystemTools::UpperCase(config);
-    archs = this->Target->GetProperty(defVarName);
+    archs = this->GetProperty(defVarName);
     }
   if(!archs)
     {
-    archs = this->Target->GetProperty("OSX_ARCHITECTURES");
+    archs = this->GetProperty("OSX_ARCHITECTURES");
     }
   if(archs)
     {
@@ -2012,7 +2619,7 @@ cmGeneratorTarget::GetCreateRuleVariable(std::string const& lang,
 {
   switch(this->GetType())
     {
-    case cmTarget::STATIC_LIBRARY:
+    case cmState::STATIC_LIBRARY:
       {
       std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
       if(this->GetFeatureAsBool(
@@ -2026,11 +2633,11 @@ cmGeneratorTarget::GetCreateRuleVariable(std::string const& lang,
         }
       return var;
       }
-    case cmTarget::SHARED_LIBRARY:
+    case cmState::SHARED_LIBRARY:
       return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
-    case cmTarget::MODULE_LIBRARY:
+    case cmState::MODULE_LIBRARY:
       return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
-    case cmTarget::EXECUTABLE:
+    case cmState::EXECUTABLE:
       return "CMAKE_" + lang + "_LINK_EXECUTABLE";
     default:
       break;
@@ -2046,8 +2653,6 @@ static void processIncludeDirectories(cmGeneratorTarget const* tgt,
       const std::string& config, bool debugIncludes,
       const std::string& language)
 {
-  cmMakefile *mf = tgt->Target->GetMakefile();
-
   for (std::vector<cmGeneratorTarget::TargetPropertyEntry*>::const_iterator
       it = entries.begin(), end = entries.end(); it != end; ++it)
     {
@@ -2056,10 +2661,11 @@ static void processIncludeDirectories(cmGeneratorTarget const* tgt,
     bool const fromImported = item.Target && item.Target->IsImported();
     bool const checkCMP0027 = item.FromGenex;
     std::vector<std::string> entryIncludes;
-    cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
+    cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(
+                                        tgt->GetLocalGenerator(),
                                               config,
                                               false,
-                                              tgt->Target,
+                                              tgt,
                                               dagChecker, language),
                                     entryIncludes);
 
@@ -2074,7 +2680,7 @@ static void processIncludeDirectories(cmGeneratorTarget const* tgt,
         cmake::MessageType messageType = cmake::FATAL_ERROR;
         if (checkCMP0027)
           {
-          switch(tgt->Target->GetPolicyStatusCMP0027())
+          switch(tgt->GetPolicyStatusCMP0027())
             {
             case cmPolicies::WARN:
               e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n";
@@ -2113,7 +2719,7 @@ static void processIncludeDirectories(cmGeneratorTarget const* tgt,
           }
         else
           {
-          switch(tgt->Target->GetPolicyStatusCMP0021())
+          switch(tgt->GetPolicyStatusCMP0021())
             {
             case cmPolicies::WARN:
               {
@@ -2159,7 +2765,7 @@ static void processIncludeDirectories(cmGeneratorTarget const* tgt,
       }
     if (!usedIncludes.empty())
       {
-      mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
+      tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(cmake::LOG,
                             std::string("Used includes for target ")
                             + tgt->GetName() + ":\n"
                             + usedIncludes, (*it)->ge->GetBacktrace());
@@ -2167,34 +2773,6 @@ static void processIncludeDirectories(cmGeneratorTarget const* tgt,
     }
 }
 
-
-//----------------------------------------------------------------------------
-static void AddInterfaceEntries(
-  cmGeneratorTarget const* thisTarget, std::string const& config,
-  std::string const& prop,
-  std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries)
-{
-  if(cmLinkImplementationLibraries const* impl =
-     thisTarget->Target->GetLinkImplementationLibraries(config))
-    {
-    for (std::vector<cmLinkImplItem>::const_iterator
-           it = impl->Libraries.begin(), end = impl->Libraries.end();
-         it != end; ++it)
-      {
-      if(it->Target)
-        {
-        std::string genex =
-          "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
-        cmGeneratorExpression ge(it->Backtrace);
-        cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
-        cge->SetEvaluateForBuildsystem(true);
-        entries.push_back(
-          new cmGeneratorTarget::TargetPropertyEntry(cge, *it));
-        }
-      }
-    }
-}
-
 //----------------------------------------------------------------------------
 std::vector<std::string>
 cmGeneratorTarget::GetIncludeDirectories(const std::string& config,
@@ -2243,7 +2821,7 @@ cmGeneratorTarget::GetIncludeDirectories(const std::string& config,
   if(this->Makefile->IsOn("APPLE"))
     {
     cmLinkImplementationLibraries const* impl =
-        this->Target->GetLinkImplementationLibraries(config);
+        this->GetLinkImplementationLibraries(config);
     for(std::vector<cmLinkImplItem>::const_iterator
         it = impl->Libraries.begin();
         it != impl->Libraries.end(); ++it)
@@ -2290,16 +2868,15 @@ static void processCompileOptionsInternal(cmGeneratorTarget const* tgt,
       const std::string& config, bool debugOptions, const char *logName,
       std::string const& language)
 {
-  cmMakefile *mf = tgt->Target->GetMakefile();
-
   for (std::vector<cmGeneratorTarget::TargetPropertyEntry*>::const_iterator
       it = entries.begin(), end = entries.end(); it != end; ++it)
     {
     std::vector<std::string> entryOptions;
-    cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
+    cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(
+                                        tgt->GetLocalGenerator(),
                                               config,
                                               false,
-                                              tgt->Target,
+                                              tgt,
                                               dagChecker,
                                               language),
                                     entryOptions);
@@ -2320,7 +2897,7 @@ static void processCompileOptionsInternal(cmGeneratorTarget const* tgt,
       }
     if (!usedOptions.empty())
       {
-      mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
+      tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(cmake::LOG,
                             std::string("Used compile ") + logName
                             + std::string(" for target ")
                             + tgt->GetName() + ":\n"
@@ -2528,7 +3105,7 @@ void cmGeneratorTarget::GetCompileDefinitions(std::vector<std::string> &list,
     {
     std::string configPropName = "COMPILE_DEFINITIONS_"
                                         + cmSystemTools::UpperCase(config);
-    const char *configProp = this->Target->GetProperty(configPropName);
+    const char *configProp = this->GetProperty(configPropName);
     if (configProp)
       {
       switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043))
@@ -2573,7 +3150,7 @@ void cmGeneratorTarget::GetCompileDefinitions(std::vector<std::string> &list,
 void cmGeneratorTarget::ComputeTargetManifest(
                                               const std::string& config) const
 {
-  if (this->Target->IsImported())
+  if (this->IsImported())
     {
     return;
     }
@@ -2585,13 +3162,13 @@ void cmGeneratorTarget::ComputeTargetManifest(
   std::string realName;
   std::string impName;
   std::string pdbName;
-  if(this->GetType() == cmTarget::EXECUTABLE)
+  if(this->GetType() == cmState::EXECUTABLE)
     {
     this->GetExecutableNames(name, realName, impName, pdbName, config);
     }
-  else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
-          this->GetType() == cmTarget::SHARED_LIBRARY ||
-          this->GetType() == cmTarget::MODULE_LIBRARY)
+  else if(this->GetType() == cmState::STATIC_LIBRARY ||
+          this->GetType() == cmState::SHARED_LIBRARY ||
+          this->GetType() == cmState::MODULE_LIBRARY)
     {
     this->GetLibraryNames(name, soName, realName, impName, pdbName,
                                   config);
@@ -2602,7 +3179,7 @@ void cmGeneratorTarget::ComputeTargetManifest(
     }
 
   // Get the directory.
-  std::string dir = this->Target->GetDirectory(config, false);
+  std::string dir = this->GetDirectory(config, false);
 
   // Add each name.
   std::string f;
@@ -2636,7 +3213,7 @@ void cmGeneratorTarget::ComputeTargetManifest(
     }
   if(!impName.empty())
     {
-    f = this->Target->GetDirectory(config, true);
+    f = this->GetDirectory(config, true);
     f += "/";
     f += impName;
     gg->AddToManifest(f);
@@ -2647,7 +3224,7 @@ void cmGeneratorTarget::ComputeTargetManifest(
 std::string cmGeneratorTarget::GetFullPath(const std::string& config,
                                            bool implib, bool realname) const
 {
-  if(this->Target->IsImported())
+  if(this->IsImported())
     {
     return this->Target->ImportedGetFullPath(config, implib);
     }
@@ -2661,9 +3238,9 @@ std::string cmGeneratorTarget::NormalGetFullPath(const std::string& config,
                                                  bool implib,
                                                  bool realname) const
 {
-  std::string fpath = this->Target->GetDirectory(config, implib);
+  std::string fpath = this->GetDirectory(config, implib);
   fpath += "/";
-  if(this->Target->IsAppBundleOnApple())
+  if(this->IsAppBundleOnApple())
     {
     fpath = this->BuildMacContentDirectory(fpath, config, false);
     fpath += "/";
@@ -2692,14 +3269,14 @@ cmGeneratorTarget::NormalGetRealName(const std::string& config) const
   // This should not be called for imported targets.
   // TODO: Split cmTarget into a class hierarchy to get compile-time
   // enforcement of the limited imported target API.
-  if(this->Target->IsImported())
+  if(this->IsImported())
     {
     std::string msg =  "NormalGetRealName called on imported target: ";
     msg += this->GetName();
     this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
     }
 
-  if(this->GetType() == cmTarget::EXECUTABLE)
+  if(this->GetType() == cmState::EXECUTABLE)
     {
     // Compute the real name that will be built.
     std::string name;
@@ -2734,7 +3311,7 @@ void cmGeneratorTarget::GetLibraryNames(std::string& name,
   // This should not be called for imported targets.
   // TODO: Split cmTarget into a class hierarchy to get compile-time
   // enforcement of the limited imported target API.
-  if(this->Target->IsImported())
+  if(this->IsImported())
     {
     std::string msg =  "GetLibraryNames called on imported target: ";
     msg += this->GetName();
@@ -2748,7 +3325,7 @@ void cmGeneratorTarget::GetLibraryNames(std::string& name,
   const char* soversion = this->GetProperty("SOVERSION");
   if(!this->HasSOName(config) ||
      this->Makefile->IsOn("CMAKE_PLATFORM_NO_VERSIONED_SONAME") ||
-     this->Target->IsFrameworkOnApple())
+     this->IsFrameworkOnApple())
     {
     // Versioning is supported only for shared libraries and modules,
     // and then only when the platform supports an soname flag.
@@ -2776,13 +3353,13 @@ void cmGeneratorTarget::GetLibraryNames(std::string& name,
   // The library name.
   name = prefix+base+suffix;
 
-  if(this->Target->IsFrameworkOnApple())
+  if(this->IsFrameworkOnApple())
     {
     realName = prefix;
     if(!this->Makefile->PlatformIsAppleIos())
       {
       realName += "Versions/";
-      realName += this->Target->GetFrameworkVersion();
+      realName += this->GetFrameworkVersion();
       realName += "/";
       }
     realName += base;
@@ -2791,17 +3368,17 @@ void cmGeneratorTarget::GetLibraryNames(std::string& name,
   else
   {
     // The library's soname.
-    this->Target->ComputeVersionedName(soName, prefix, base, suffix,
+    this->ComputeVersionedName(soName, prefix, base, suffix,
                               name, soversion);
 
     // The library's real name on disk.
-    this->Target->ComputeVersionedName(realName, prefix, base, suffix,
+    this->ComputeVersionedName(realName, prefix, base, suffix,
                               name, version);
   }
 
   // The import library name.
-  if(this->GetType() == cmTarget::SHARED_LIBRARY ||
-     this->GetType() == cmTarget::MODULE_LIBRARY)
+  if(this->GetType() == cmState::SHARED_LIBRARY ||
+     this->GetType() == cmState::MODULE_LIBRARY)
     {
     impName = this->GetFullNameInternal(config, true);
     }
@@ -2824,7 +3401,7 @@ void cmGeneratorTarget::GetExecutableNames(std::string& name,
   // This should not be called for imported targets.
   // TODO: Split cmTarget into a class hierarchy to get compile-time
   // enforcement of the limited imported target API.
-  if(this->Target->IsImported())
+  if(this->IsImported())
     {
     std::string msg =
       "GetExecutableNames called on imported target: ";
@@ -2839,7 +3416,7 @@ void cmGeneratorTarget::GetExecutableNames(std::string& name,
 #else
   // Check for executable version properties.
   const char* version = this->GetProperty("VERSION");
-  if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
+  if(this->GetType() != cmState::EXECUTABLE || this->Makefile->IsOn("XCODE"))
     {
     version = 0;
     }
@@ -2888,6 +3465,24 @@ std::string cmGeneratorTarget::GetFullNameInternal(const std::string& config,
 }
 
 //----------------------------------------------------------------------------
+const char*
+cmGeneratorTarget::ImportedGetLocation(const std::string& config) const
+{
+  static std::string location;
+  assert(this->IsImported());
+  location = this->Target->ImportedGetFullPath(config, false);
+  return location.c_str();
+}
+
+//----------------------------------------------------------------------------
+std::string cmGeneratorTarget::GetFullNameImported(const std::string& config,
+                                                   bool implib) const
+{
+  return cmSystemTools::GetFilenameName(
+    this->Target->ImportedGetFullPath(config, implib));
+}
+
+//----------------------------------------------------------------------------
 void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
                                             bool implib,
                                             std::string& outPrefix,
@@ -2895,10 +3490,10 @@ void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
                                             std::string& outSuffix) const
 {
   // Use just the target name for non-main target types.
-  if(this->GetType() != cmTarget::STATIC_LIBRARY &&
-     this->GetType() != cmTarget::SHARED_LIBRARY &&
-     this->GetType() != cmTarget::MODULE_LIBRARY &&
-     this->GetType() != cmTarget::EXECUTABLE)
+  if(this->GetType() != cmState::STATIC_LIBRARY &&
+     this->GetType() != cmState::SHARED_LIBRARY &&
+     this->GetType() != cmState::MODULE_LIBRARY &&
+     this->GetType() != cmState::EXECUTABLE)
     {
     outPrefix = "";
     outBase = this->GetName();
@@ -2919,9 +3514,9 @@ void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
 
   // The implib option is only allowed for shared libraries, module
   // libraries, and executables.
-  if(this->GetType() != cmTarget::SHARED_LIBRARY &&
-     this->GetType() != cmTarget::MODULE_LIBRARY &&
-     this->GetType() != cmTarget::EXECUTABLE)
+  if(this->GetType() != cmState::SHARED_LIBRARY &&
+     this->GetType() != cmState::MODULE_LIBRARY &&
+     this->GetType() != cmState::EXECUTABLE)
     {
     implib = false;
     }
@@ -2941,8 +3536,7 @@ void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
     configPostfix = this->GetProperty(configProp);
     // Mac application bundles and frameworks have no postfix.
     if(configPostfix &&
-       (this->Target->IsAppBundleOnApple()
-         || this->Target->IsFrameworkOnApple()))
+       (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
       {
       configPostfix = 0;
       }
@@ -2979,7 +3573,7 @@ void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
 
   // frameworks have directory prefix but no suffix
   std::string fw_prefix;
-  if(this->Target->IsFrameworkOnApple())
+  if(this->IsFrameworkOnApple())
     {
     fw_prefix = this->GetOutputName(config, false);
     fw_prefix += ".framework/";
@@ -2987,7 +3581,7 @@ void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
     targetSuffix = 0;
     }
 
-  if(this->Target->IsCFBundleOnApple())
+  if(this->IsCFBundleOnApple())
     {
     fw_prefix = this->GetCFBundleDirectory(config, false);
     fw_prefix += "/";
@@ -3007,7 +3601,7 @@ void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
   // Name shared libraries with their version number on some platforms.
   if(const char* soversion = this->GetProperty("SOVERSION"))
     {
-    if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
+    if(this->GetType() == cmState::SHARED_LIBRARY && !implib &&
        this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
       {
       outBase += "-";
@@ -3059,14 +3653,14 @@ std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
   return prefix+base+".pdb";
 }
 
-bool cmStrictTargetComparison::operator()(cmTarget const* t1,
-                                          cmTarget const* t2) const
+bool cmGeneratorTarget::StrictTargetComparison::operator()(
+    cmGeneratorTarget const* t1, cmGeneratorTarget const* t2) const
 {
   int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
   if (nameResult == 0)
     {
-    return strcmp(t1->GetMakefile()->GetCurrentBinaryDirectory(),
-                  t2->GetMakefile()->GetCurrentBinaryDirectory()) < 0;
+    return strcmp(t1->GetLocalGenerator()->GetCurrentBinaryDirectory(),
+                  t2->GetLocalGenerator()->GetCurrentBinaryDirectory()) < 0;
     }
   return nameResult < 0;
 }
@@ -3113,7 +3707,7 @@ void cmGeneratorTarget::ConstructSourceFileFlags() const
   this->SourceFileFlagsConstructed = true;
 
   // Process public headers to mark the source files.
-  if(const char* files = this->Target->GetProperty("PUBLIC_HEADER"))
+  if(const char* files = this->GetProperty("PUBLIC_HEADER"))
     {
     std::vector<std::string> relFiles;
     cmSystemTools::ExpandListArgument(files, relFiles);
@@ -3131,7 +3725,7 @@ void cmGeneratorTarget::ConstructSourceFileFlags() const
 
   // Process private headers after public headers so that they take
   // precedence if a file is listed in both.
-  if(const char* files = this->Target->GetProperty("PRIVATE_HEADER"))
+  if(const char* files = this->GetProperty("PRIVATE_HEADER"))
     {
     std::vector<std::string> relFiles;
     cmSystemTools::ExpandListArgument(files, relFiles);
@@ -3148,7 +3742,7 @@ void cmGeneratorTarget::ConstructSourceFileFlags() const
     }
 
   // Mark sources listed as resources.
-  if(const char* files = this->Target->GetProperty("RESOURCE"))
+  if(const char* files = this->GetProperty("RESOURCE"))
     {
     std::vector<std::string> relFiles;
     cmSystemTools::ExpandListArgument(files, relFiles);
@@ -3158,7 +3752,11 @@ void cmGeneratorTarget::ConstructSourceFileFlags() const
       if(cmSourceFile* sf = this->Makefile->GetSource(*it))
         {
         SourceFileFlags& flags = this->SourceFlagsMap[sf];
-        flags.MacFolder = "Resources";
+        flags.MacFolder = "";
+        if(!this->Makefile->PlatformIsAppleIos())
+          {
+          flags.MacFolder = "Resources";
+          }
         flags.Type = cmGeneratorTarget::SourceFileTypeResource;
         }
       }
@@ -3176,10 +3774,10 @@ cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
     compat.Done = true;
     compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
     compat.PropsString.insert("AUTOUIC_OPTIONS");
-    std::vector<cmTarget const*> const& deps =
+    std::vector<cmGeneratorTarget const*> const& deps =
       this->GetLinkImplementationClosure(config);
-    for(std::vector<cmTarget const*>::const_iterator li = deps.begin();
-        li != deps.end(); ++li)
+    for(std::vector<cmGeneratorTarget const*>::const_iterator li =
+        deps.begin(); li != deps.end(); ++li)
       {
 #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
       if(const char* prop = (*li)->GetProperty("COMPATIBLE_INTERFACE_" #X)) \
@@ -3202,8 +3800,8 @@ cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
 bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
     const std::string &p, const std::string& config) const
 {
-  if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
-      || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
+  if (this->GetType() == cmState::OBJECT_LIBRARY
+      || this->GetType() == cmState::INTERFACE_LIBRARY)
     {
     return false;
     }
@@ -3214,8 +3812,8 @@ bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
 bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
     const std::string &p, const std::string& config) const
 {
-  if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
-      || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
+  if (this->GetType() == cmState::OBJECT_LIBRARY
+      || this->GetType() == cmState::INTERFACE_LIBRARY)
     {
     return false;
     }
@@ -3226,8 +3824,8 @@ bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
 bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
     const std::string &p, const std::string& config) const
 {
-  if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
-      || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
+  if (this->GetType() == cmState::OBJECT_LIBRARY
+      || this->GetType() == cmState::INTERFACE_LIBRARY)
     {
     return false;
     }
@@ -3238,8 +3836,8 @@ bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
 bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMaxProperty(
     const std::string &p, const std::string& config) const
 {
-  if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
-      || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
+  if (this->GetType() == cmState::OBJECT_LIBRARY
+      || this->GetType() == cmState::INTERFACE_LIBRARY)
     {
     return false;
     }
@@ -3296,7 +3894,7 @@ const char * getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
 //----------------------------------------------------------------------------
 template<typename PropertyType>
 void checkPropertyConsistency(cmGeneratorTarget const* depender,
-                              cmTarget const* dependee,
+                              cmGeneratorTarget const* dependee,
                               const std::string& propName,
                               std::set<std::string> &emitted,
                               const std::string& config,
@@ -3312,7 +3910,7 @@ void checkPropertyConsistency(cmGeneratorTarget const* depender,
   std::vector<std::string> props;
   cmSystemTools::ExpandListArgument(prop, props);
   std::string pdir =
-    dependee->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
+    dependee->Target->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
   pdir += "/Help/prop_tgt/";
 
   for(std::vector<std::string>::iterator pi = props.begin();
@@ -3525,18 +4123,20 @@ std::string compatibilityAgree(CompatibleType t, bool dominant)
 
 //----------------------------------------------------------------------------
 template<typename PropertyType>
-PropertyType getTypedProperty(cmTarget const* tgt, const std::string& prop);
+PropertyType getTypedProperty(cmGeneratorTarget const* tgt,
+                              const std::string& prop);
 
 //----------------------------------------------------------------------------
 template<>
-bool getTypedProperty<bool>(cmTarget const* tgt, const std::string& prop)
+bool getTypedProperty<bool>(cmGeneratorTarget const* tgt,
+                            const std::string& prop)
 {
   return tgt->GetPropertyAsBool(prop);
 }
 
 //----------------------------------------------------------------------------
 template<>
-const char *getTypedProperty<const char *>(cmTarget const* tgt,
+const char *getTypedProperty<const char *>(cmGeneratorTarget const* tgt,
                                            const std::string& prop)
 {
   return tgt->GetProperty(prop);
@@ -3666,16 +4266,18 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
                                           CompatibleType t,
                                           PropertyType *)
 {
-  PropertyType propContent = getTypedProperty<PropertyType>(tgt->Target, p);
-  const bool explicitlySet = tgt->Target->GetProperties()
-                                  .find(p)
-                                  != tgt->Target->GetProperties().end();
+  PropertyType propContent = getTypedProperty<PropertyType>(tgt, p);
+  std::vector<std::string> headPropKeys = tgt->GetPropertyKeys();
+  const bool explicitlySet =
+      std::find(headPropKeys.begin(), headPropKeys.end(),
+                p) != headPropKeys.end();
+
   const bool impliedByUse =
-          tgt->Target->IsNullImpliedByLinkLibraries(p);
+          tgt->IsNullImpliedByLinkLibraries(p);
   assert((impliedByUse ^ explicitlySet)
       || (!impliedByUse && !explicitlySet));
 
-  std::vector<cmTarget const*> const& deps =
+  std::vector<cmGeneratorTarget const*> const& deps =
     tgt->GetLinkImplementationClosure(config);
 
   if(deps.empty())
@@ -3702,7 +4304,7 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
     }
 
   std::string interfaceProperty = "INTERFACE_" + p;
-  for(std::vector<cmTarget const*>::const_iterator li =
+  for(std::vector<cmGeneratorTarget const*>::const_iterator li =
       deps.begin();
       li != deps.end(); ++li)
     {
@@ -3712,11 +4314,13 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
     // target itself has a POSITION_INDEPENDENT_CODE which disagrees
     // with a dependency.
 
-    cmTarget const* theTarget = *li;
+    cmGeneratorTarget const* theTarget = *li;
+
+    std::vector<std::string> propKeys = theTarget->GetPropertyKeys();
 
-    const bool ifaceIsSet = theTarget->GetProperties()
-                            .find(interfaceProperty)
-                            != theTarget->GetProperties().end();
+    const bool ifaceIsSet =
+        std::find(propKeys.begin(), propKeys.end(),
+                  interfaceProperty) != propKeys.end();
     PropertyType ifacePropContent =
                     getTypedProperty<PropertyType>(theTarget,
                               interfaceProperty);
@@ -3920,6 +4524,93 @@ cmGeneratorTarget::GetLinkInformation(const std::string& config) const
 }
 
 //----------------------------------------------------------------------------
+void cmGeneratorTarget::GetTargetVersion(int& major, int& minor) const
+{
+  int patch;
+  this->GetTargetVersion(false, major, minor, patch);
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorTarget::GetTargetVersion(bool soversion,
+                                int& major, int& minor, int& patch) const
+{
+  // Set the default values.
+  major = 0;
+  minor = 0;
+  patch = 0;
+
+  assert(this->GetType() != cmState::INTERFACE_LIBRARY);
+
+  // Look for a VERSION or SOVERSION property.
+  const char* prop = soversion? "SOVERSION" : "VERSION";
+  if(const char* version = this->GetProperty(prop))
+    {
+    // Try to parse the version number and store the results that were
+    // successfully parsed.
+    int parsed_major;
+    int parsed_minor;
+    int parsed_patch;
+    switch(sscanf(version, "%d.%d.%d",
+                  &parsed_major, &parsed_minor, &parsed_patch))
+      {
+      case 3: patch = parsed_patch; // no break!
+      case 2: minor = parsed_minor; // no break!
+      case 1: major = parsed_major; // no break!
+      default: break;
+      }
+    }
+}
+
+//----------------------------------------------------------------------------
+std::string cmGeneratorTarget::GetFrameworkVersion() const
+{
+  assert(this->GetType() != cmState::INTERFACE_LIBRARY);
+
+  if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
+    {
+    return fversion;
+    }
+  else if(const char* tversion = this->GetProperty("VERSION"))
+    {
+    return tversion;
+    }
+  else
+    {
+    return "A";
+    }
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorTarget::ComputeVersionedName(std::string& vName,
+                                    std::string const& prefix,
+                                    std::string const& base,
+                                    std::string const& suffix,
+                                    std::string const& name,
+                                    const char* version) const
+{
+  vName = this->Makefile->IsOn("APPLE") ? (prefix+base) : name;
+  if(version)
+    {
+    vName += ".";
+    vName += version;
+    }
+  vName += this->Makefile->IsOn("APPLE") ? suffix : std::string();
+}
+
+std::vector<std::string> cmGeneratorTarget::GetPropertyKeys() const
+{
+  cmPropertyMap propsObject = this->Target->GetProperties();
+  std::vector<std::string> props;
+  props.reserve(propsObject.size());
+  for (cmPropertyMap::const_iterator it = propsObject.begin();
+       it != propsObject.end(); ++it)
+    {
+    props.push_back(it->first);
+    }
+  return props;
+}
+
+//----------------------------------------------------------------------------
 void
 cmGeneratorTarget::ReportPropertyOrigin(const std::string &p,
                                const std::string &result,
@@ -3956,7 +4647,7 @@ cmGeneratorTarget::ReportPropertyOrigin(const std::string &p,
   areport += result;
   areport += "\"):\n" + report;
 
-  this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
+  this->LocalGenerator->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
 }
 
 //----------------------------------------------------------------------------
@@ -3966,12 +4657,12 @@ void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
   for(std::vector<std::string>::const_iterator i = names.begin();
       i != names.end(); ++i)
     {
-    std::string name = this->Target->CheckCMP0004(*i);
+    std::string name = this->CheckCMP0004(*i);
     if(name == this->GetName() || name.empty())
       {
       continue;
       }
-    items.push_back(cmLinkItem(name, this->Target->FindTargetToLink(name)));
+    items.push_back(cmLinkItem(name, this->FindTargetToLink(name)));
     }
 }
 
@@ -3979,7 +4670,7 @@ void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
 void cmGeneratorTarget::ExpandLinkItems(std::string const& prop,
                                std::string const& value,
                                std::string const& config,
-                               cmTarget const* headTarget,
+                               cmGeneratorTarget const* headTarget,
                                bool usage_requirements_only,
                                std::vector<cmLinkItem>& items,
                                bool& hadHeadSensitiveCondition) const
@@ -3995,11 +4686,11 @@ void cmGeneratorTarget::ExpandLinkItems(std::string const& prop,
   std::vector<std::string> libs;
   cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
   cmSystemTools::ExpandListArgument(cge->Evaluate(
-                                      this->Makefile,
+                                      this->LocalGenerator,
                                       config,
                                       false,
                                       headTarget,
-                                      this->Target, &dagChecker), libs);
+                                      this, &dagChecker), libs);
   this->LookupLinkItems(libs, items);
   hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
 }
@@ -4007,7 +4698,7 @@ void cmGeneratorTarget::ExpandLinkItems(std::string const& prop,
 //----------------------------------------------------------------------------
 cmLinkInterface const*
 cmGeneratorTarget::GetLinkInterface(const std::string& config,
-                                    cmTarget const* head) const
+                                    cmGeneratorTarget const* head) const
 {
   // Imported targets have their own link interface.
   if(this->IsImported())
@@ -4017,8 +4708,8 @@ cmGeneratorTarget::GetLinkInterface(const std::string& config,
 
   // Link interfaces are not supported for executables that do not
   // export symbols.
-  if(this->GetType() == cmTarget::EXECUTABLE &&
-     !this->Target->IsExecutableWithExports())
+  if(this->GetType() == cmState::EXECUTABLE &&
+     !this->IsExecutableWithExports())
     {
     return 0;
     }
@@ -4056,13 +4747,13 @@ cmGeneratorTarget::GetLinkInterface(const std::string& config,
 //----------------------------------------------------------------------------
 void cmGeneratorTarget::ComputeLinkInterface(const std::string& config,
                                     cmOptionalLinkInterface &iface,
-                                    cmTarget const* headTarget) const
+                                    cmGeneratorTarget const* headTarget) const
 {
   if(iface.ExplicitLibraries)
     {
-    if(this->GetType() == cmTarget::SHARED_LIBRARY
-        || this->GetType() == cmTarget::STATIC_LIBRARY
-        || this->GetType() == cmTarget::INTERFACE_LIBRARY)
+    if(this->GetType() == cmState::SHARED_LIBRARY
+        || this->GetType() == cmState::STATIC_LIBRARY
+        || this->GetType() == cmState::INTERFACE_LIBRARY)
       {
       // Shared libraries may have runtime implementation dependencies
       // on other shared libraries that are not in the interface.
@@ -4072,7 +4763,7 @@ void cmGeneratorTarget::ComputeLinkInterface(const std::string& config,
         {
         emitted.insert(*li);
         }
-      if (this->GetType() != cmTarget::INTERFACE_LIBRARY)
+      if (this->GetType() != cmState::INTERFACE_LIBRARY)
         {
         cmLinkImplementation const* impl =
             this->GetLinkImplementation(config);
@@ -4084,7 +4775,7 @@ void cmGeneratorTarget::ComputeLinkInterface(const std::string& config,
             if(li->Target)
               {
               // This is a runtime dependency on another shared library.
-              if(li->Target->GetType() == cmTarget::SHARED_LIBRARY)
+              if(li->Target->GetType() == cmState::SHARED_LIBRARY)
                 {
                 iface.SharedDeps.push_back(*li);
                 }
@@ -4101,18 +4792,18 @@ void cmGeneratorTarget::ComputeLinkInterface(const std::string& config,
         }
       }
     }
-  else if (this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN
-        || this->Target->GetPolicyStatusCMP0022() == cmPolicies::OLD)
+  else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN
+        || this->GetPolicyStatusCMP0022() == cmPolicies::OLD)
     {
     // The link implementation is the default link interface.
     cmLinkImplementationLibraries const*
-      impl = this->Target->GetLinkImplementationLibrariesInternal(config,
-                                                                headTarget);
+      impl = this->GetLinkImplementationLibrariesInternal(config,
+                                                          headTarget);
     iface.ImplementationIsInterface = true;
     iface.WrongConfigLibraries = impl->WrongConfigLibraries;
     }
 
-  if(this->Target->LinkLanguagePropagatesToDependents())
+  if(this->LinkLanguagePropagatesToDependents())
     {
     // Targets using this archive need its language runtime libraries.
     if(cmLinkImplementation const* impl =
@@ -4122,7 +4813,7 @@ void cmGeneratorTarget::ComputeLinkInterface(const std::string& config,
       }
     }
 
-  if(this->GetType() == cmTarget::STATIC_LIBRARY)
+  if(this->GetType() == cmState::STATIC_LIBRARY)
     {
     // Construct the property name suffix for this configuration.
     std::string suffix = "_";
@@ -4154,7 +4845,7 @@ void cmGeneratorTarget::ComputeLinkInterface(const std::string& config,
 //----------------------------------------------------------------------------
 const cmLinkInterfaceLibraries *
 cmGeneratorTarget::GetLinkInterfaceLibraries(const std::string& config,
-                                    cmTarget const* head,
+                                    cmGeneratorTarget const* head,
                                     bool usage_requirements_only) const
 {
   // Imported targets have their own link interface.
@@ -4166,8 +4857,8 @@ cmGeneratorTarget::GetLinkInterfaceLibraries(const std::string& config,
 
   // Link interfaces are not supported for executables that do not
   // export symbols.
-  if(this->GetType() == cmTarget::EXECUTABLE &&
-     !this->Target->IsExecutableWithExports())
+  if(this->GetType() == cmState::EXECUTABLE &&
+     !this->IsExecutableWithExports())
     {
     return 0;
     }
@@ -4198,59 +4889,309 @@ cmGeneratorTarget::GetLinkInterfaceLibraries(const std::string& config,
 }
 
 //----------------------------------------------------------------------------
-void
-cmGeneratorTarget::ComputeLinkInterfaceLibraries(
-  const std::string& config,
-  cmOptionalLinkInterface& iface,
-  cmTarget const* headTarget,
-  bool usage_requirements_only) const
+std::string cmGeneratorTarget::GetDirectory(const std::string& config,
+                                   bool implib) const
 {
-  // Construct the property name suffix for this configuration.
-  std::string suffix = "_";
-  if(!config.empty())
+  if (this->IsImported())
     {
-    suffix += cmSystemTools::UpperCase(config);
+    // Return the directory from which the target is imported.
+    return
+      cmSystemTools::GetFilenamePath(
+      this->Target->ImportedGetFullPath(config, implib));
     }
-  else
+  else if(OutputInfo const* info = this->GetOutputInfo(config))
     {
-    suffix += "NOCONFIG";
+    // Return the directory in which the target will be built.
+    return implib? info->ImpDir : info->OutDir;
     }
+  return "";
+}
 
-  // An explicit list of interface libraries may be set for shared
-  // libraries and executables that export symbols.
-  const char* explicitLibraries = 0;
-  std::string linkIfaceProp;
-  if(this->Target->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
-     this->Target->GetPolicyStatusCMP0022() != cmPolicies::WARN)
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::UsesDefaultOutputDir(const std::string& config,
+                                    bool implib) const
+{
+  std::string dir;
+  return this->ComputeOutputDir(config, implib, dir);
+}
+
+//----------------------------------------------------------------------------
+cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo(
+    const std::string& config) const
+{
+  // There is no output information for imported targets.
+  if(this->IsImported())
     {
-    // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
-    linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
-    explicitLibraries = this->GetProperty(linkIfaceProp);
+    return 0;
     }
-  else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
-          this->Target->IsExecutableWithExports())
+
+  // Only libraries and executables have well-defined output files.
+  if(!this->HaveWellDefinedOutputFiles())
     {
-    // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
-    // shared lib or executable.
+    std::string msg = "cmGeneratorTarget::GetOutputInfo called for ";
+    msg += this->GetName();
+    msg += " which has type ";
+    msg += cmState::GetTargetTypeName(this->GetType());
+    this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
+    return 0;
+    }
 
-    // Lookup the per-configuration property.
-    linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
-    linkIfaceProp += suffix;
-    explicitLibraries = this->GetProperty(linkIfaceProp);
+  // Lookup/compute/cache the output information for this configuration.
+  std::string config_upper;
+  if(!config.empty())
+    {
+    config_upper = cmSystemTools::UpperCase(config);
+    }
+  OutputInfoMapType::iterator i =
+    this->OutputInfoMap.find(config_upper);
+  if(i == this->OutputInfoMap.end())
+    {
+    // Add empty info in map to detect potential recursion.
+    OutputInfo info;
+    OutputInfoMapType::value_type entry(config_upper, info);
+    i = this->OutputInfoMap.insert(entry).first;
 
-    // If not set, try the generic property.
-    if(!explicitLibraries)
+    // Compute output directories.
+    this->ComputeOutputDir(config, false, info.OutDir);
+    this->ComputeOutputDir(config, true, info.ImpDir);
+    if(!this->ComputePDBOutputDir("PDB", config, info.PdbDir))
       {
-      linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
-      explicitLibraries = this->GetProperty(linkIfaceProp);
+      info.PdbDir = info.OutDir;
       }
+
+    // Now update the previously-prepared map entry.
+    i->second = info;
+    }
+  else if(i->second.empty())
+    {
+    // An empty map entry indicates we have been called recursively
+    // from the above block.
+    this->LocalGenerator->GetCMakeInstance()->IssueMessage(
+      cmake::FATAL_ERROR,
+      "Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.",
+      this->GetBacktrace());
+    return 0;
     }
+  return &i->second;
+}
 
-  if(explicitLibraries &&
-     this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
-     !this->PolicyWarnedCMP0022)
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::ComputeOutputDir(const std::string& config,
+                                bool implib, std::string& out) const
+{
+  bool usesDefaultOutputDir = false;
+  std::string conf = config;
+
+  // Look for a target property defining the target output directory
+  // based on the target type.
+  std::string targetTypeName = this->GetOutputTargetType(implib);
+  const char* propertyName = 0;
+  std::string propertyNameStr = targetTypeName;
+  if(!propertyNameStr.empty())
     {
-    // Compare the explicitly set old link interface properties to the
+    propertyNameStr += "_OUTPUT_DIRECTORY";
+    propertyName = propertyNameStr.c_str();
+    }
+
+  // Check for a per-configuration output directory target property.
+  std::string configUpper = cmSystemTools::UpperCase(conf);
+  const char* configProp = 0;
+  std::string configPropStr = targetTypeName;
+  if(!configPropStr.empty())
+    {
+    configPropStr += "_OUTPUT_DIRECTORY_";
+    configPropStr += configUpper;
+    configProp = configPropStr.c_str();
+    }
+
+  // Select an output directory.
+  if(const char* config_outdir = this->GetProperty(configProp))
+    {
+    // Use the user-specified per-configuration output directory.
+    cmGeneratorExpression ge;
+    cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
+      ge.Parse(config_outdir);
+    out = cge->Evaluate(this->LocalGenerator, config);
+
+    // Skip per-configuration subdirectory.
+    conf = "";
+    }
+  else if(const char* outdir = this->GetProperty(propertyName))
+    {
+    // Use the user-specified output directory.
+    cmGeneratorExpression ge;
+    cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
+      ge.Parse(outdir);
+    out = cge->Evaluate(this->LocalGenerator, config);
+
+    // Skip per-configuration subdirectory if the value contained a
+    // generator expression.
+    if (out != outdir)
+      {
+      conf = "";
+      }
+    }
+  else if(this->GetType() == cmState::EXECUTABLE)
+    {
+    // Lookup the output path for executables.
+    out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
+    }
+  else if(this->GetType() == cmState::STATIC_LIBRARY ||
+          this->GetType() == cmState::SHARED_LIBRARY ||
+          this->GetType() == cmState::MODULE_LIBRARY)
+    {
+    // Lookup the output path for libraries.
+    out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
+    }
+  if(out.empty())
+    {
+    // Default to the current output directory.
+    usesDefaultOutputDir = true;
+    out = ".";
+    }
+
+  // Convert the output path to a full path in case it is
+  // specified as a relative path.  Treat a relative path as
+  // relative to the current output directory for this makefile.
+  out = (cmSystemTools::CollapseFullPath
+         (out, this->LocalGenerator->GetCurrentBinaryDirectory()));
+
+  // The generator may add the configuration's subdirectory.
+  if(!conf.empty())
+    {
+    bool iosPlatform = this->Makefile->PlatformIsAppleIos();
+    std::string suffix =
+      usesDefaultOutputDir && iosPlatform ? "${EFFECTIVE_PLATFORM_NAME}" : "";
+    this->LocalGenerator->GetGlobalGenerator()->
+      AppendDirectoryForConfig("/", conf, suffix, out);
+    }
+
+  return usesDefaultOutputDir;
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind,
+                                   const std::string& config,
+                                   std::string& out) const
+{
+  // Look for a target property defining the target output directory
+  // based on the target type.
+  const char* propertyName = 0;
+  std::string propertyNameStr = kind;
+  if(!propertyNameStr.empty())
+    {
+    propertyNameStr += "_OUTPUT_DIRECTORY";
+    propertyName = propertyNameStr.c_str();
+    }
+  std::string conf = config;
+
+  // Check for a per-configuration output directory target property.
+  std::string configUpper = cmSystemTools::UpperCase(conf);
+  const char* configProp = 0;
+  std::string configPropStr = kind;
+  if(!configPropStr.empty())
+    {
+    configPropStr += "_OUTPUT_DIRECTORY_";
+    configPropStr += configUpper;
+    configProp = configPropStr.c_str();
+    }
+
+  // Select an output directory.
+  if(const char* config_outdir = this->GetProperty(configProp))
+    {
+    // Use the user-specified per-configuration output directory.
+    out = config_outdir;
+
+    // Skip per-configuration subdirectory.
+    conf = "";
+    }
+  else if(const char* outdir = this->GetProperty(propertyName))
+    {
+    // Use the user-specified output directory.
+    out = outdir;
+    }
+  if(out.empty())
+    {
+    return false;
+    }
+
+  // Convert the output path to a full path in case it is
+  // specified as a relative path.  Treat a relative path as
+  // relative to the current output directory for this makefile.
+  out = (cmSystemTools::CollapseFullPath
+         (out, this->LocalGenerator->GetCurrentBinaryDirectory()));
+
+  // The generator may add the configuration's subdirectory.
+  if(!conf.empty())
+    {
+    this->LocalGenerator->GetGlobalGenerator()->
+      AppendDirectoryForConfig("/", conf, "", out);
+    }
+  return true;
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::HaveInstallTreeRPATH() const
+{
+  const char* install_rpath = this->GetProperty("INSTALL_RPATH");
+  return (install_rpath && *install_rpath) &&
+          !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
+}
+
+//----------------------------------------------------------------------------
+void
+cmGeneratorTarget::ComputeLinkInterfaceLibraries(
+  const std::string& config,
+  cmOptionalLinkInterface& iface,
+  cmGeneratorTarget const* headTarget,
+  bool usage_requirements_only) const
+{
+  // Construct the property name suffix for this configuration.
+  std::string suffix = "_";
+  if(!config.empty())
+    {
+    suffix += cmSystemTools::UpperCase(config);
+    }
+  else
+    {
+    suffix += "NOCONFIG";
+    }
+
+  // An explicit list of interface libraries may be set for shared
+  // libraries and executables that export symbols.
+  const char* explicitLibraries = 0;
+  std::string linkIfaceProp;
+  if(this->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
+     this->GetPolicyStatusCMP0022() != cmPolicies::WARN)
+    {
+    // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
+    linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
+    explicitLibraries = this->GetProperty(linkIfaceProp);
+    }
+  else if(this->GetType() == cmState::SHARED_LIBRARY ||
+          this->IsExecutableWithExports())
+    {
+    // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
+    // shared lib or executable.
+
+    // Lookup the per-configuration property.
+    linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
+    linkIfaceProp += suffix;
+    explicitLibraries = this->GetProperty(linkIfaceProp);
+
+    // If not set, try the generic property.
+    if(!explicitLibraries)
+      {
+      linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
+      explicitLibraries = this->GetProperty(linkIfaceProp);
+      }
+    }
+
+  if(explicitLibraries &&
+     this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
+     !this->PolicyWarnedCMP0022)
+    {
+    // Compare the explicitly set old link interface properties to the
     // preferred new link interface property one and warn if different.
     const char* newExplicitLibraries =
       this->GetProperty("INTERFACE_LINK_LIBRARIES");
@@ -4275,8 +5216,8 @@ cmGeneratorTarget::ComputeLinkInterfaceLibraries(
   // There is no implicit link interface for executables or modules
   // so if none was explicitly set then there is no link interface.
   if(!explicitLibraries &&
-     (this->GetType() == cmTarget::EXECUTABLE ||
-      (this->GetType() == cmTarget::MODULE_LIBRARY)))
+     (this->GetType() == cmState::EXECUTABLE ||
+      (this->GetType() == cmState::MODULE_LIBRARY)))
     {
     return;
     }
@@ -4292,8 +5233,8 @@ cmGeneratorTarget::ComputeLinkInterfaceLibraries(
                                 iface.Libraries,
                                 iface.HadHeadSensitiveCondition);
     }
-  else if (this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN
-        || this->Target->GetPolicyStatusCMP0022() == cmPolicies::OLD)
+  else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN
+        || this->GetPolicyStatusCMP0022() == cmPolicies::OLD)
     // If CMP0022 is NEW then the plain tll signature sets the
     // INTERFACE_LINK_LIBRARIES, so if we get here then the project
     // cleared the property explicitly and we should not fall back
@@ -4301,11 +5242,10 @@ cmGeneratorTarget::ComputeLinkInterfaceLibraries(
     {
     // The link implementation is the default link interface.
     cmLinkImplementationLibraries const* impl =
-      this->Target->GetLinkImplementationLibrariesInternal(config,
-                                                           headTarget);
+      this->GetLinkImplementationLibrariesInternal(config, headTarget);
     iface.Libraries.insert(iface.Libraries.end(),
                            impl->Libraries.begin(), impl->Libraries.end());
-    if(this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
+    if(this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
        !this->PolicyWarnedCMP0022 && !usage_requirements_only)
       {
       // Compare the link implementation fallback link interface to the
@@ -4316,8 +5256,9 @@ cmGeneratorTarget::ComputeLinkInterfaceLibraries(
         {
         bool hadHeadSensitiveConditionDummy = false;
         this->ExpandLinkItems(newProp, newExplicitLibraries, config,
-                                    headTarget, usage_requirements_only,
-                                ifaceLibs, hadHeadSensitiveConditionDummy);
+                              headTarget,
+                              usage_requirements_only,
+                              ifaceLibs, hadHeadSensitiveConditionDummy);
         }
       if (ifaceLibs != iface.Libraries)
         {
@@ -4351,10 +5292,10 @@ cmGeneratorTarget::ComputeLinkInterfaceLibraries(
 //----------------------------------------------------------------------------
 const cmLinkInterface *
 cmGeneratorTarget::GetImportLinkInterface(const std::string& config,
-                                 cmTarget const* headTarget,
+                                 cmGeneratorTarget const* headTarget,
                                  bool usage_requirements_only) const
 {
-  cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config);
+  cmGeneratorTarget::ImportInfo const* info = this->GetImportInfo(config);
   if(!info)
     {
     return 0;
@@ -4392,6 +5333,223 @@ cmGeneratorTarget::GetImportLinkInterface(const std::string& config,
   return &iface;
 }
 
+//----------------------------------------------------------------------------
+cmGeneratorTarget::ImportInfo const*
+cmGeneratorTarget::GetImportInfo(const std::string& config) const
+{
+  // There is no imported information for non-imported targets.
+  if(!this->IsImported())
+    {
+    return 0;
+    }
+
+  // Lookup/compute/cache the import information for this
+  // configuration.
+  std::string config_upper;
+  if(!config.empty())
+    {
+    config_upper = cmSystemTools::UpperCase(config);
+    }
+  else
+    {
+    config_upper = "NOCONFIG";
+    }
+
+  ImportInfoMapType::const_iterator i =
+    this->ImportInfoMap.find(config_upper);
+  if(i == this->ImportInfoMap.end())
+    {
+    ImportInfo info;
+    this->ComputeImportInfo(config_upper, info);
+    ImportInfoMapType::value_type entry(config_upper, info);
+    i = this->ImportInfoMap.insert(entry).first;
+    }
+
+  if(this->GetType() == cmState::INTERFACE_LIBRARY)
+    {
+    return &i->second;
+    }
+  // If the location is empty then the target is not available for
+  // this configuration.
+  if(i->second.Location.empty() && i->second.ImportLibrary.empty())
+    {
+    return 0;
+    }
+
+  // Return the import information.
+  return &i->second;
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorTarget::ComputeImportInfo(std::string const& desired_config,
+                                 ImportInfo& info) const
+{
+  // This method finds information about an imported target from its
+  // properties.  The "IMPORTED_" namespace is reserved for properties
+  // defined by the project exporting the target.
+
+  // Initialize members.
+  info.NoSOName = false;
+
+  const char* loc = 0;
+  const char* imp = 0;
+  std::string suffix;
+  if (!this->Target->GetMappedConfig(desired_config, &loc, &imp, suffix))
+    {
+    return;
+    }
+
+  // Get the link interface.
+  {
+  std::string linkProp = "INTERFACE_LINK_LIBRARIES";
+  const char *propertyLibs = this->GetProperty(linkProp);
+
+  if (this->GetType() != cmState::INTERFACE_LIBRARY)
+    {
+    if(!propertyLibs)
+      {
+      linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
+      linkProp += suffix;
+      propertyLibs = this->GetProperty(linkProp);
+      }
+
+    if(!propertyLibs)
+      {
+      linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
+      propertyLibs = this->GetProperty(linkProp);
+      }
+    }
+  if(propertyLibs)
+    {
+    info.LibrariesProp = linkProp;
+    info.Libraries = propertyLibs;
+    }
+  }
+  if(this->GetType() == cmState::INTERFACE_LIBRARY)
+    {
+    return;
+    }
+
+  // A provided configuration has been chosen.  Load the
+  // configuration's properties.
+
+  // Get the location.
+  if(loc)
+    {
+    info.Location = loc;
+    }
+  else
+    {
+    std::string impProp = "IMPORTED_LOCATION";
+    impProp += suffix;
+    if(const char* config_location = this->GetProperty(impProp))
+      {
+      info.Location = config_location;
+      }
+    else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
+      {
+      info.Location = location;
+      }
+    }
+
+  // Get the soname.
+  if(this->GetType() == cmState::SHARED_LIBRARY)
+    {
+    std::string soProp = "IMPORTED_SONAME";
+    soProp += suffix;
+    if(const char* config_soname = this->GetProperty(soProp))
+      {
+      info.SOName = config_soname;
+      }
+    else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
+      {
+      info.SOName = soname;
+      }
+    }
+
+  // Get the "no-soname" mark.
+  if(this->GetType() == cmState::SHARED_LIBRARY)
+    {
+    std::string soProp = "IMPORTED_NO_SONAME";
+    soProp += suffix;
+    if(const char* config_no_soname = this->GetProperty(soProp))
+      {
+      info.NoSOName = cmSystemTools::IsOn(config_no_soname);
+      }
+    else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
+      {
+      info.NoSOName = cmSystemTools::IsOn(no_soname);
+      }
+    }
+
+  // Get the import library.
+  if(imp)
+    {
+    info.ImportLibrary = imp;
+    }
+  else if(this->GetType() == cmState::SHARED_LIBRARY ||
+          this->IsExecutableWithExports())
+    {
+    std::string impProp = "IMPORTED_IMPLIB";
+    impProp += suffix;
+    if(const char* config_implib = this->GetProperty(impProp))
+      {
+      info.ImportLibrary = config_implib;
+      }
+    else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
+      {
+      info.ImportLibrary = implib;
+      }
+    }
+
+  // Get the link dependencies.
+  {
+  std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
+  linkProp += suffix;
+  if(const char* config_libs = this->GetProperty(linkProp))
+    {
+    info.SharedDeps = config_libs;
+    }
+  else if(const char* libs =
+          this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
+    {
+    info.SharedDeps = libs;
+    }
+  }
+
+  // Get the link languages.
+  if(this->LinkLanguagePropagatesToDependents())
+    {
+    std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
+    linkProp += suffix;
+    if(const char* config_libs = this->GetProperty(linkProp))
+      {
+      info.Languages = config_libs;
+      }
+    else if(const char* libs =
+            this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
+      {
+      info.Languages = libs;
+      }
+    }
+
+  // Get the cyclic repetition count.
+  if(this->GetType() == cmState::STATIC_LIBRARY)
+    {
+    std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
+    linkProp += suffix;
+    if(const char* config_reps = this->GetProperty(linkProp))
+      {
+      sscanf(config_reps, "%u", &info.Multiplicity);
+      }
+    else if(const char* reps =
+            this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
+      {
+      sscanf(reps, "%u", &info.Multiplicity);
+      }
+    }
+}
+
 cmHeadToLinkInterfaceMap&
 cmGeneratorTarget::GetHeadToLinkInterfaceMap(const std::string &config) const
 {
@@ -4412,17 +5570,17 @@ const cmLinkImplementation *
 cmGeneratorTarget::GetLinkImplementation(const std::string& config) const
 {
   // There is no link implementation for imported targets.
-  if(this->Target->IsImported())
+  if(this->IsImported())
     {
     return 0;
     }
 
-  cmOptionalLinkImplementation& impl = this->Target->GetLinkImplMap(config);
+  std::string CONFIG = cmSystemTools::UpperCase(config);
+  cmOptionalLinkImplementation& impl = this->LinkImplMap[CONFIG][this];
   if(!impl.LibrariesDone)
     {
     impl.LibrariesDone = true;
-    this->Target->ComputeLinkImplementationLibraries(config, impl,
-                                                     this->Target);
+    this->ComputeLinkImplementationLibraries(config, impl, this);
     }
   if(!impl.LanguagesDone)
     {
@@ -4445,12 +5603,12 @@ bool cmGeneratorTarget::GetConfigCommonSourceFiles(
 
   std::vector<std::string>::const_iterator it = configs.begin();
   const std::string& firstConfig = *it;
-  this->Target->GetSourceFiles(files, firstConfig);
+  this->GetSourceFiles(files, firstConfig);
 
   for ( ; it != configs.end(); ++it)
     {
     std::vector<cmSourceFile*> configFiles;
-    this->Target->GetSourceFiles(configFiles, *it);
+    this->GetSourceFiles(configFiles, *it);
     if (configFiles != files)
       {
       std::string firstConfigFiles;
@@ -4490,6 +5648,105 @@ bool cmGeneratorTarget::GetConfigCommonSourceFiles(
 }
 
 //----------------------------------------------------------------------------
+void cmGeneratorTarget::GetObjectLibrariesCMP0026(
+    std::vector<cmGeneratorTarget*>& objlibs) const
+{
+  // At configure-time, this method can be called as part of getting the
+  // LOCATION property or to export() a file to be include()d.  However
+  // there is no cmGeneratorTarget at configure-time, so search the SOURCES
+  // for TARGET_OBJECTS instead for backwards compatibility with OLD
+  // behavior of CMP0024 and CMP0026 only.
+  cmStringRange rng = this->Target->GetSourceEntries();
+  for(std::vector<std::string>::const_iterator
+        i = rng.begin(); i != rng.end(); ++i)
+    {
+    std::string const& entry = *i;
+
+    std::vector<std::string> files;
+    cmSystemTools::ExpandListArgument(entry, files);
+    for (std::vector<std::string>::const_iterator
+        li = files.begin(); li != files.end(); ++li)
+      {
+      if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
+          (*li)[li->size() - 1] == '>')
+        {
+        std::string objLibName = li->substr(17, li->size()-18);
+
+        if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
+          {
+          continue;
+          }
+        cmGeneratorTarget *objLib =
+            this->LocalGenerator->FindGeneratorTargetToUse(objLibName);
+        if(objLib)
+          {
+          objlibs.push_back(objLib);
+          }
+        }
+      }
+    }
+}
+
+//----------------------------------------------------------------------------
+std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const
+{
+  // Strip whitespace off the library names because we used to do this
+  // in case variables were expanded at generate time.  We no longer
+  // do the expansion but users link to libraries like " ${VAR} ".
+  std::string lib = item;
+  std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
+  if(pos != lib.npos)
+    {
+    lib = lib.substr(pos, lib.npos);
+    }
+  pos = lib.find_last_not_of(" \t\r\n");
+  if(pos != lib.npos)
+    {
+    lib = lib.substr(0, pos+1);
+    }
+  if(lib != item)
+    {
+    cmake* cm = this->LocalGenerator->GetCMakeInstance();
+    switch(this->GetPolicyStatusCMP0004())
+      {
+      case cmPolicies::WARN:
+        {
+        std::ostringstream w;
+        w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
+          << "Target \"" << this->GetName() << "\" links to item \""
+          << item << "\" which has leading or trailing whitespace.";
+        cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
+                         this->GetBacktrace());
+        }
+      case cmPolicies::OLD:
+        break;
+      case cmPolicies::NEW:
+        {
+        std::ostringstream e;
+        e << "Target \"" << this->GetName() << "\" links to item \""
+          << item << "\" which has leading or trailing whitespace.  "
+          << "This is now an error according to policy CMP0004.";
+        cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
+                         this->GetBacktrace());
+        }
+        break;
+      case cmPolicies::REQUIRED_IF_USED:
+      case cmPolicies::REQUIRED_ALWAYS:
+        {
+        std::ostringstream e;
+        e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
+          << "Target \"" << this->GetName() << "\" links to item \""
+          << item << "\" which has leading or trailing whitespace.";
+        cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
+                         this->GetBacktrace());
+        }
+        break;
+      }
+    }
+  return lib;
+}
+
+//----------------------------------------------------------------------------
 void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
                             const std::string& config) const
 {
@@ -4509,14 +5766,13 @@ void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
   std::vector<cmSourceFile const*> externalObjects;
   if (!this->GlobalGenerator->GetConfigureDoneCMP0026())
     {
-    std::vector<cmTarget*> objectTargets;
-    this->Target->GetObjectLibrariesCMP0026(objectTargets);
+    std::vector<cmGeneratorTarget*> objectTargets;
+    this->GetObjectLibrariesCMP0026(objectTargets);
     objectLibraries.reserve(objectTargets.size());
-    for (std::vector<cmTarget*>::const_iterator it = objectTargets.begin();
-         it != objectTargets.end(); ++it)
+    for (std::vector<cmGeneratorTarget*>::const_iterator it =
+         objectTargets.begin(); it != objectTargets.end(); ++it)
       {
-      objectLibraries.push_back(this->GlobalGenerator
-                                ->GetGeneratorTarget(*it));
+      objectLibraries.push_back(*it);
       }
     }
   else
@@ -4526,10 +5782,10 @@ void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
           i = externalObjects.begin(); i != externalObjects.end(); ++i)
       {
       std::string objLib = (*i)->GetObjectLibrary();
-      if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
+      if (cmGeneratorTarget* tgt =
+          this->LocalGenerator->FindGeneratorTargetToUse(objLib))
         {
-        objectLibraries.push_back(this->GlobalGenerator
-                                  ->GetGeneratorTarget(tgt));
+        objectLibraries.push_back(tgt);
         }
       }
     }
@@ -4557,14 +5813,317 @@ void cmGeneratorTarget::ComputeLinkImplementationLanguages(
 //----------------------------------------------------------------------------
 bool cmGeneratorTarget::HaveBuildTreeRPATH(const std::string& config) const
 {
-  if (this->Target->GetPropertyAsBool("SKIP_BUILD_RPATH"))
+  if (this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
     {
     return false;
     }
   if(cmLinkImplementationLibraries const* impl =
-     this->Target->GetLinkImplementationLibraries(config))
+     this->GetLinkImplementationLibraries(config))
     {
     return !impl->Libraries.empty();
     }
   return false;
 }
+
+//----------------------------------------------------------------------------
+cmLinkImplementationLibraries const*
+cmGeneratorTarget::GetLinkImplementationLibraries(
+    const std::string& config) const
+{
+  return this->GetLinkImplementationLibrariesInternal(config, this);
+}
+
+//----------------------------------------------------------------------------
+cmLinkImplementationLibraries const*
+cmGeneratorTarget::GetLinkImplementationLibrariesInternal(
+    const std::string& config, cmGeneratorTarget const* head) const
+{
+  // There is no link implementation for imported targets.
+  if(this->IsImported())
+    {
+    return 0;
+    }
+
+  // Populate the link implementation libraries for this configuration.
+  std::string CONFIG = cmSystemTools::UpperCase(config);
+  HeadToLinkImplementationMap& hm =
+    this->LinkImplMap[CONFIG];
+
+  // If the link implementation does not depend on the head target
+  // then return the one we computed first.
+  if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
+    {
+    return &hm.begin()->second;
+    }
+
+  cmOptionalLinkImplementation& impl = hm[head];
+  if(!impl.LibrariesDone)
+    {
+    impl.LibrariesDone = true;
+    this->ComputeLinkImplementationLibraries(config, impl, head);
+    }
+  return &impl;
+}
+
+//----------------------------------------------------------------------------
+bool
+cmGeneratorTarget::IsNullImpliedByLinkLibraries(const std::string &p) const
+{
+  return this->LinkImplicitNullProperties.find(p)
+      != this->LinkImplicitNullProperties.end();
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorTarget::ComputeLinkImplementationLibraries(
+  const std::string& config,
+  cmOptionalLinkImplementation& impl,
+  cmGeneratorTarget const* head) const
+{
+  cmStringRange entryRange =
+      this->Target->GetLinkImplementationEntries();
+  cmBacktraceRange btRange =
+      this->Target->GetLinkImplementationBacktraces();
+  cmBacktraceRange::const_iterator btIt = btRange.begin();
+  // Collect libraries directly linked in this configuration.
+  for (cmStringRange::const_iterator le = entryRange.begin(),
+      end = entryRange.end(); le != end; ++le, ++btIt)
+    {
+    std::vector<std::string> llibs;
+    cmGeneratorExpressionDAGChecker dagChecker(
+                                        this->GetName(),
+                                        "LINK_LIBRARIES", 0, 0);
+    cmGeneratorExpression ge(*btIt);
+    cmsys::auto_ptr<cmCompiledGeneratorExpression> const cge =
+      ge.Parse(*le);
+    std::string const evaluated =
+      cge->Evaluate(this->LocalGenerator, config, false, head, &dagChecker);
+    cmSystemTools::ExpandListArgument(evaluated, llibs);
+    if(cge->GetHadHeadSensitiveCondition())
+      {
+      impl.HadHeadSensitiveCondition = true;
+      }
+
+    for(std::vector<std::string>::const_iterator li = llibs.begin();
+        li != llibs.end(); ++li)
+      {
+      // Skip entries that resolve to the target itself or are empty.
+      std::string name = this->CheckCMP0004(*li);
+      if(name == this->GetName() || name.empty())
+        {
+        if(name == this->GetName())
+          {
+          bool noMessage = false;
+          cmake::MessageType messageType = cmake::FATAL_ERROR;
+          std::ostringstream e;
+          switch(this->GetPolicyStatusCMP0038())
+            {
+            case cmPolicies::WARN:
+              {
+              e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n";
+              messageType = cmake::AUTHOR_WARNING;
+              }
+              break;
+            case cmPolicies::OLD:
+              noMessage = true;
+            case cmPolicies::REQUIRED_IF_USED:
+            case cmPolicies::REQUIRED_ALWAYS:
+            case cmPolicies::NEW:
+              // Issue the fatal message.
+              break;
+            }
+
+          if(!noMessage)
+            {
+            e << "Target \"" << this->GetName() << "\" links to itself.";
+            this->LocalGenerator->GetCMakeInstance()->IssueMessage(
+              messageType, e.str(), this->GetBacktrace());
+            if (messageType == cmake::FATAL_ERROR)
+              {
+              return;
+              }
+            }
+          }
+        continue;
+        }
+
+      // The entry is meant for this configuration.
+      impl.Libraries.push_back(
+        cmLinkImplItem(name, this->FindTargetToLink(name),
+                       *btIt, evaluated != *le));
+      }
+
+    std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
+    for (std::set<std::string>::const_iterator it = seenProps.begin();
+        it != seenProps.end(); ++it)
+      {
+      if (!this->GetProperty(*it))
+        {
+        this->LinkImplicitNullProperties.insert(*it);
+        }
+      }
+    cge->GetMaxLanguageStandard(this,
+                                this->MaxLanguageStandards);
+    }
+
+  // Get the list of configurations considered to be DEBUG.
+  std::vector<std::string> debugConfigs =
+    this->Makefile->GetCMakeInstance()->GetDebugConfigs();
+
+  cmTargetLinkLibraryType linkType =
+      CMP0003_ComputeLinkType(config, debugConfigs);
+  cmTarget::LinkLibraryVectorType const& oldllibs =
+    this->Target->GetOriginalLinkLibraries();
+  for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
+      li != oldllibs.end(); ++li)
+    {
+    if(li->second != GENERAL_LibraryType && li->second != linkType)
+      {
+      std::string name = this->CheckCMP0004(li->first);
+      if(name == this->GetName() || name.empty())
+        {
+        continue;
+        }
+      // Support OLD behavior for CMP0003.
+      impl.WrongConfigLibraries.push_back(
+        cmLinkItem(name, this->FindTargetToLink(name)));
+      }
+    }
+}
+
+//----------------------------------------------------------------------------
+cmGeneratorTarget*
+cmGeneratorTarget::FindTargetToLink(std::string const& name) const
+{
+  cmGeneratorTarget* tgt =
+      this->LocalGenerator->FindGeneratorTargetToUse(name);
+
+  // Skip targets that will not really be linked.  This is probably a
+  // name conflict between an external library and an executable
+  // within the project.
+  if(tgt && tgt->GetType() == cmState::EXECUTABLE &&
+     !tgt->IsExecutableWithExports())
+    {
+    tgt = 0;
+    }
+
+  if(tgt && tgt->GetType() == cmState::OBJECT_LIBRARY)
+    {
+    std::ostringstream e;
+    e << "Target \"" << this->GetName() << "\" links to "
+      "OBJECT library \"" << tgt->GetName() << "\" but this is not "
+      "allowed.  "
+      "One may link only to STATIC or SHARED libraries, or to executables "
+      "with the ENABLE_EXPORTS property set.";
+    cmake* cm = this->LocalGenerator->GetCMakeInstance();
+    cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
+                     this->GetBacktrace());
+    tgt = 0;
+    }
+
+  return tgt;
+}
+
+//----------------------------------------------------------------------------
+std::string
+cmGeneratorTarget::GetPDBDirectory(const std::string& config) const
+{
+  if(OutputInfo const* info = this->GetOutputInfo(config))
+    {
+    // Return the directory in which the target will be built.
+    return info->PdbDir;
+    }
+  return "";
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::HasImplibGNUtoMS() const
+{
+  return this->HasImportLibrary()
+      && this->GetPropertyAsBool("GNUtoMS");
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::GetImplibGNUtoMS(std::string const& gnuName,
+                                std::string& out, const char* newExt) const
+{
+  if(this->HasImplibGNUtoMS() &&
+     gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
+    {
+    out = gnuName.substr(0, gnuName.size()-6);
+    out += newExt? newExt : ".lib";
+    return true;
+    }
+  return false;
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::IsExecutableWithExports() const
+{
+  return (this->GetType() == cmState::EXECUTABLE &&
+          this->GetPropertyAsBool("ENABLE_EXPORTS"));
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::HasImportLibrary() const
+{
+  return (this->IsDLLPlatform() &&
+          (this->GetType() == cmState::SHARED_LIBRARY ||
+           this->IsExecutableWithExports()));
+}
+
+//----------------------------------------------------------------------------
+std::string cmGeneratorTarget::GetSupportDirectory() const
+{
+  std::string dir = this->LocalGenerator->GetCurrentBinaryDirectory();
+  dir += cmake::GetCMakeFilesDirectory();
+  dir += "/";
+  dir += this->GetName();
+#if defined(__VMS)
+  dir += "_dir";
+#else
+  dir += ".dir";
+#endif
+  return dir;
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::IsLinkable() const
+{
+  return (this->GetType() == cmState::STATIC_LIBRARY ||
+          this->GetType() == cmState::SHARED_LIBRARY ||
+          this->GetType() == cmState::MODULE_LIBRARY ||
+          this->GetType() == cmState::UNKNOWN_LIBRARY ||
+          this->GetType() == cmState::INTERFACE_LIBRARY ||
+          this->IsExecutableWithExports());
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::IsFrameworkOnApple() const
+{
+  return (this->GetType() == cmState::SHARED_LIBRARY &&
+          this->Makefile->IsOn("APPLE") &&
+          this->GetPropertyAsBool("FRAMEWORK"));
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::IsAppBundleOnApple() const
+{
+  return (this->GetType() == cmState::EXECUTABLE &&
+          this->Makefile->IsOn("APPLE") &&
+          this->GetPropertyAsBool("MACOSX_BUNDLE"));
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::IsXCTestOnApple() const
+{
+  return (this->IsCFBundleOnApple() &&
+          this->GetPropertyAsBool("XCTEST"));
+}
+
+//----------------------------------------------------------------------------
+bool cmGeneratorTarget::IsCFBundleOnApple() const
+{
+  return (this->GetType() == cmState::MODULE_LIBRARY &&
+          this->Makefile->IsOn("APPLE") &&
+          this->GetPropertyAsBool("BUNDLE"));
+}
diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h
index 916f281..d96a32c 100644
--- a/Source/cmGeneratorTarget.h
+++ b/Source/cmGeneratorTarget.h
@@ -31,8 +31,21 @@ public:
   cmLocalGenerator* GetLocalGenerator() const;
 
   bool IsImported() const;
+  bool IsImportedGloballyVisible() const;
   const char *GetLocation(const std::string& config) const;
 
+  std::vector<cmCustomCommand> const &GetPreBuildCommands() const;
+  std::vector<cmCustomCommand> const &GetPreLinkCommands() const;
+  std::vector<cmCustomCommand> const &GetPostBuildCommands() const;
+
+#define DECLARE_TARGET_POLICY(POLICY) \
+  cmPolicies::PolicyStatus GetPolicyStatus ## POLICY () const \
+    { return this->PolicyMap.Get(cmPolicies::POLICY); }
+
+  CM_FOR_EACH_TARGET_POLICY(DECLARE_TARGET_POLICY)
+
+#undef DECLARE_TARGET_POLICY
+
   /** Get the location of the target in the build tree with a placeholder
       referencing the configuration in the native build system.  This
       location is suitable for use as the LOCATION target property.  */
@@ -41,8 +54,11 @@ public:
   cmComputeLinkInformation*
     GetLinkInformation(const std::string& config) const;
 
-  int GetType() const;
-  std::string GetName() const;
+  cmState::TargetType GetType() const;
+  const std::string& GetName() const;
+  std::string GetExportName() const;
+
+  std::vector<std::string> GetPropertyKeys() const;
   const char *GetProperty(const std::string& prop) const;
   bool GetPropertyAsBool(const std::string& prop) const;
   void GetSourceFiles(std::vector<cmSourceFile*>& files,
@@ -82,6 +98,8 @@ public:
   void GetExpectedXamlSources(std::set<std::string>&,
                               const std::string& config) const;
 
+  std::set<cmLinkItem>const& GetUtilityItems() const;
+
   void ComputeObjectMapping();
 
   const char* GetFeature(const std::string& feature,
@@ -109,19 +127,19 @@ public:
                          const std::string& config) const;
 
   cmLinkInterface const* GetLinkInterface(const std::string& config,
-                                        cmTarget const* headTarget) const;
+                                    const cmGeneratorTarget* headTarget) const;
   void ComputeLinkInterface(const std::string& config,
                             cmOptionalLinkInterface& iface,
-                            cmTarget const* head) const;
+                            const cmGeneratorTarget* head) const;
 
   cmLinkInterfaceLibraries const*
     GetLinkInterfaceLibraries(const std::string& config,
-                              cmTarget const* headTarget,
+                              const cmGeneratorTarget* headTarget,
                               bool usage_requirements_only) const;
 
   void ComputeLinkInterfaceLibraries(const std::string& config,
                                      cmOptionalLinkInterface &iface,
-                                     cmTarget const* head,
+                                     const cmGeneratorTarget* head,
                                      bool usage_requirements_only) const;
 
   /** Get the full path to the target according to the settings in its
@@ -149,6 +167,10 @@ public:
   std::string GetFrameworkDirectory(const std::string& config,
                                     bool rootDir) const;
 
+  /** Return the framework version string.  Undefined if
+      IsFrameworkOnApple returns false.  */
+  std::string GetFrameworkVersion() const;
+
   /** @return the Mac CFBundle directory without the base */
   std::string GetCFBundleDirectory(const std::string& config,
                                    bool contentOnly) const;
@@ -162,6 +184,20 @@ public:
     * install tree.  For example: "\@rpath/" or "\@loader_path/". */
   std::string GetInstallNameDirForInstallTree() const;
 
+  cmListFileBacktrace GetBacktrace() const;
+
+  const std::vector<std::string>& GetLinkDirectories() const;
+
+  std::set<std::string>const& GetUtilities() const;
+  cmListFileBacktrace const* GetUtilityBacktrace(const std::string& u) const;
+
+  bool LinkLanguagePropagatesToDependents() const
+  { return this->GetType() == cmState::STATIC_LIBRARY; }
+
+  /** Get the macro to define when building sources in this target.
+      If no macro should be defined null is returned.  */
+  const char* GetExportMacro() const;
+
   /** Get the soname of the target.  Allowed only for a shared library.  */
   std::string GetSOName(const std::string& config) const;
 
@@ -184,7 +220,13 @@ public:
   cmLocalGenerator* LocalGenerator;
   cmGlobalGenerator const* GlobalGenerator;
 
-  std::string GetModuleDefinitionFile(const std::string& config) const;
+  cmSourceFile const* GetModuleDefinitionFile(const std::string& config) const;
+
+  /** Return whether or not the target is for a DLL platform.  */
+  bool IsDLLPlatform() const;
+
+  /** @return whether this target have a well defined output file name. */
+  bool HaveWellDefinedOutputFiles() const;
 
   /** Link information from the transitive closure of the link
       implementation and the interfaces of its dependencies.  */
@@ -207,6 +249,15 @@ public:
                                           cmOptionalLinkImplementation& impl
                                           ) const;
 
+  cmLinkImplementationLibraries const*
+    GetLinkImplementationLibraries(const std::string& config) const;
+
+  void ComputeLinkImplementationLibraries(const std::string& config,
+                                          cmOptionalLinkImplementation& impl,
+                                          const cmGeneratorTarget* head) const;
+
+  cmGeneratorTarget* FindTargetToLink(std::string const& name) const;
+
   // Compute the set of languages compiled by the target.  This is
   // computed every time it is called because the languages can change
   // when source file properties are changed and we do not have enough
@@ -215,6 +266,12 @@ public:
   void GetLanguages(std::set<std::string>& languages,
                     std::string const& config) const;
 
+  void
+  GetObjectLibrariesCMP0026(std::vector<cmGeneratorTarget*>& objlibs) const;
+
+  std::string GetFullNameImported(const std::string& config,
+                                  bool implib) const;
+
   bool GetConfigCommonSourceFiles(std::vector<cmSourceFile*>& files) const;
 
   bool HaveBuildTreeRPATH(const std::string& config) const;
@@ -261,6 +318,13 @@ public:
    */
   void TraceDependencies();
 
+  /** Get the directory in which this target will be built.  If the
+      configuration name is given then the generator will add its
+      subdirectory for that configuration.  Otherwise just the canonical
+      output directory is given.  */
+  std::string GetDirectory(const std::string& config = "",
+                           bool implib = false) const;
+
   /** Get the directory in which to place the target compiler .pdb file.
       If the configuration name is given then the generator will add its
       subdirectory for that configuration.  Otherwise just the canonical
@@ -271,6 +335,22 @@ public:
   std::vector<cmSourceFile*> const*
   GetSourceDepends(cmSourceFile const* sf) const;
 
+  /** Return whether this target uses the default value for its output
+      directory.  */
+  bool UsesDefaultOutputDir(const std::string& config, bool implib) const;
+
+  // Cache target output paths for each configuration.
+  struct OutputInfo
+  {
+    std::string OutDir;
+    std::string ImpDir;
+    std::string PdbDir;
+    bool empty() const
+      { return OutDir.empty() && ImpDir.empty() && PdbDir.empty(); }
+  };
+
+  OutputInfo const* GetOutputInfo(const std::string& config) const;
+
   /** Get the name of the pdb file for the target.  */
   std::string GetPDBName(const std::string& config="") const;
 
@@ -287,6 +367,8 @@ public:
   typedef std::map<std::string, CompileInfo> CompileInfoMapType;
   mutable CompileInfoMapType CompileInfoMap;
 
+  bool IsNullImpliedByLinkLibraries(const std::string &p) const;
+
   /** Get the name of the compiler pdb file for the target.  */
   std::string GetCompilePDBName(const std::string& config="") const;
 
@@ -296,6 +378,9 @@ public:
   // Get the target base name.
   std::string GetOutputName(const std::string& config, bool implib) const;
 
+  void AddSource(const std::string& src);
+  void AddTracedSources(std::vector<std::string> const& srcs);
+
   /**
    * Flags for a given source file as used in this target. Typically assigned
    * via SET_TARGET_PROPERTIES when the property is a list of source files.
@@ -342,9 +427,47 @@ public:
   /** Return true if builtin chrpath will work for this target */
   bool IsChrpathUsed(const std::string& config) const;
 
+  /** Get the directory in which this targets .pdb files will be placed.
+      If the configuration name is given then the generator will add its
+      subdirectory for that configuration.  Otherwise just the canonical
+      pdb output directory is given.  */
+  std::string GetPDBDirectory(const std::string& config) const;
+
   ///! Return the preferred linker language for this target
   std::string GetLinkerLanguage(const std::string& config = "") const;
 
+  /** Does this target have a GNU implib to convert to MS format?  */
+  bool HasImplibGNUtoMS() const;
+
+  /** Convert the given GNU import library name (.dll.a) to a name with a new
+      extension (.lib or ${CMAKE_IMPORT_LIBRARY_SUFFIX}).  */
+  bool GetImplibGNUtoMS(std::string const& gnuName, std::string& out,
+                        const char* newExt = 0) const;
+
+  bool IsExecutableWithExports() const;
+
+  /** Return whether or not the target has a DLL import library.  */
+  bool HasImportLibrary() const;
+
+  /** Get a build-tree directory in which to place target support files.  */
+  std::string GetSupportDirectory() const;
+
+  /** Return whether this target may be used to link another target.  */
+  bool IsLinkable() const;
+
+  /** Return whether this target is a shared library Framework on
+      Apple.  */
+  bool IsFrameworkOnApple() const;
+
+  /** Return whether this target is an executable Bundle on Apple.  */
+  bool IsAppBundleOnApple() const;
+
+  /** Return whether this target is a XCTest on Apple.  */
+  bool IsXCTestOnApple() const;
+
+  /** Return whether this target is a CFBundle (plugin) on Apple.  */
+  bool IsCFBundleOnApple() const;
+
   struct SourceFileFlags
   GetTargetSourceFileFlags(const cmSourceFile* sf) const;
 
@@ -366,15 +489,42 @@ public:
 
   class TargetPropertyEntry;
 
+  bool HaveInstallTreeRPATH() const;
+
+  /** Whether this library has \@rpath and platform supports it.  */
+  bool HasMacOSXRpathInstallNameDir(const std::string& config) const;
+
+  /** Whether this library defaults to \@rpath.  */
+  bool MacOSXRpathInstallNameDirDefault() const;
+
+  /** Test for special case of a third-party shared library that has
+      no soname at all.  */
+  bool IsImportedSharedLibWithoutSOName(const std::string& config) const;
+
+  const char* ImportedGetLocation(const std::string& config) const;
+
+  /** Get the target major and minor version numbers interpreted from
+      the VERSION property.  Version 0 is returned if the property is
+      not set or cannot be parsed.  */
+  void GetTargetVersion(int& major, int& minor) const;
+
+  /** Get the target major, minor, and patch version numbers
+      interpreted from the VERSION or SOVERSION property.  Version 0
+      is returned if the property is not set or cannot be parsed.  */
+  void
+  GetTargetVersion(bool soversion, int& major, int& minor, int& patch) const;
+
 private:
   friend class cmTargetTraceDependencies;
   struct SourceEntry { std::vector<cmSourceFile*> Depends; };
   typedef std::map<cmSourceFile const*, SourceEntry> SourceEntriesType;
-  SourceEntriesType SourceEntries;
+  SourceEntriesType SourceDepends;
   mutable std::map<cmSourceFile const*, std::string> Objects;
   std::set<cmSourceFile const*> ExplicitObjectName;
   mutable std::map<std::string, std::vector<std::string> > SystemIncludesCache;
 
+  mutable std::string ExportMacro;
+
   void ConstructSourceFileFlags() const;
   mutable bool SourceFileFlagsConstructed;
   mutable std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
@@ -390,6 +540,16 @@ private:
   typedef std::map<std::string, LinkClosure> LinkClosureMapType;
   mutable LinkClosureMapType LinkClosureMap;
 
+  // Returns ARCHIVE, LIBRARY, or RUNTIME based on platform and type.
+  const char* GetOutputTargetType(bool implib) const;
+
+  void ComputeVersionedName(std::string& vName,
+                            std::string const& prefix,
+                            std::string const& base,
+                            std::string const& suffix,
+                            std::string const& name,
+                            const char* version) const;
+
   struct CompatibleInterfacesBase
   {
     std::set<std::string> PropsBool;
@@ -417,7 +577,7 @@ private:
   cmGeneratorTarget(cmGeneratorTarget const&);
   void operator=(cmGeneratorTarget const&);
 
-  struct LinkImplClosure: public std::vector<cmTarget const*>
+  struct LinkImplClosure: public std::vector<cmGeneratorTarget const*>
   {
     LinkImplClosure(): Done(false) {}
     bool Done;
@@ -434,44 +594,108 @@ private:
   cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceUsageRequirementsMap(
       std::string const& config) const;
 
+  // Cache import information from properties for each configuration.
+  struct ImportInfo
+  {
+    ImportInfo(): NoSOName(false), Multiplicity(0) {}
+    bool NoSOName;
+    int Multiplicity;
+    std::string Location;
+    std::string SOName;
+    std::string ImportLibrary;
+    std::string Languages;
+    std::string Libraries;
+    std::string LibrariesProp;
+    std::string SharedDeps;
+  };
+
+  typedef std::map<std::string, ImportInfo> ImportInfoMapType;
+  mutable ImportInfoMapType ImportInfoMap;
+  void ComputeImportInfo(std::string const& desired_config,
+                         ImportInfo& info) const;
+  ImportInfo const* GetImportInfo(const std::string& config) const;
+
+  /** Strip off leading and trailing whitespace from an item named in
+      the link dependencies of this target.  */
+  std::string CheckCMP0004(std::string const& item) const;
+
   cmLinkInterface const*
-    GetImportLinkInterface(const std::string& config, cmTarget const* head,
+    GetImportLinkInterface(const std::string& config,
+                           const cmGeneratorTarget* head,
                            bool usage_requirements_only) const;
 
+  typedef std::map<std::string, std::vector<cmSourceFile*> >
+                                                       SourceFilesMapType;
+  mutable SourceFilesMapType SourceFilesMap;
+
   std::vector<TargetPropertyEntry*> IncludeDirectoriesEntries;
   std::vector<TargetPropertyEntry*> CompileOptionsEntries;
   std::vector<TargetPropertyEntry*> CompileFeaturesEntries;
   std::vector<TargetPropertyEntry*> CompileDefinitionsEntries;
+  std::vector<TargetPropertyEntry*> SourceEntries;
+  mutable std::set<std::string> LinkImplicitNullProperties;
 
   void ExpandLinkItems(std::string const& prop, std::string const& value,
-                       std::string const& config, cmTarget const* headTarget,
+                       std::string const& config,
+                       const cmGeneratorTarget* headTarget,
                        bool usage_requirements_only,
                        std::vector<cmLinkItem>& items,
                        bool& hadHeadSensitiveCondition) const;
   void LookupLinkItems(std::vector<std::string> const& names,
                        std::vector<cmLinkItem>& items) const;
 
+  void GetSourceFiles(std::vector<std::string>& files,
+                      const std::string& config) const;
+
+  struct HeadToLinkImplementationMap:
+    public std::map<cmGeneratorTarget const*, cmOptionalLinkImplementation> {};
+  typedef std::map<std::string,
+                   HeadToLinkImplementationMap> LinkImplMapType;
+  mutable LinkImplMapType LinkImplMap;
+
+  cmLinkImplementationLibraries const*
+    GetLinkImplementationLibrariesInternal(const std::string& config,
+                                          const cmGeneratorTarget* head) const;
+  bool
+  ComputeOutputDir(const std::string& config,
+                   bool implib, std::string& out) const;
+
+  typedef std::map<std::string, OutputInfo> OutputInfoMapType;
+  mutable OutputInfoMapType OutputInfoMap;
+
   typedef std::pair<std::string, bool> OutputNameKey;
   typedef std::map<OutputNameKey, std::string> OutputNameMapType;
   mutable OutputNameMapType OutputNameMap;
+  mutable std::set<cmLinkItem> UtilityItems;
+  cmPolicies::PolicyMap PolicyMap;
   mutable bool PolicyWarnedCMP0022;
   mutable bool DebugIncludesDone;
   mutable bool DebugCompileOptionsDone;
   mutable bool DebugCompileFeaturesDone;
   mutable bool DebugCompileDefinitionsDone;
+  mutable bool DebugSourcesDone;
+  mutable bool LinkImplementationLanguageIsContextDependent;
+  mutable bool UtilityItemsDone;
+  bool DLLPlatform;
+
+  bool ComputePDBOutputDir(const std::string& kind, const std::string& config,
+                           std::string& out) const;
 
 public:
-  std::vector<cmTarget const*> const&
-    GetLinkImplementationClosure(const std::string& config) const;
+  const std::vector<const cmGeneratorTarget*>&
+  GetLinkImplementationClosure(const std::string& config) const;
 
-};
+  mutable std::map<std::string, std::string> MaxLanguageStandards;
+  std::map<std::string, std::string> const&
+  GetMaxLanguageStandards() const
+  {
+    return this->MaxLanguageStandards;
+  }
 
-struct cmStrictTargetComparison {
-  bool operator()(cmTarget const* t1, cmTarget const* t2) const;
+  struct StrictTargetComparison {
+    bool operator()(cmGeneratorTarget const* t1,
+                    cmGeneratorTarget const* t2) const;
+  };
 };
 
-typedef std::map<cmTarget const*,
-                 cmGeneratorTarget*,
-                 cmStrictTargetComparison> cmGeneratorTargetsType;
-
 #endif
diff --git a/Source/cmGetCMakePropertyCommand.cxx b/Source/cmGetCMakePropertyCommand.cxx
index 248ce59..1a91183 100644
--- a/Source/cmGetCMakePropertyCommand.cxx
+++ b/Source/cmGetCMakePropertyCommand.cxx
@@ -12,7 +12,6 @@
 #include "cmGetCMakePropertyCommand.h"
 
 #include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmake.h"
 #include "cmState.h"
 #include "cmAlgorithms.h"
diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx
index 4c42f53..617a811 100644
--- a/Source/cmGetPropertyCommand.cxx
+++ b/Source/cmGetPropertyCommand.cxx
@@ -15,7 +15,6 @@
 #include "cmState.h"
 #include "cmTest.h"
 #include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmSourceFile.h"
 #include "cmPropertyDefinition.h"
 
diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx
index cae5c2f..18e140e 100644
--- a/Source/cmGhsMultiTargetGenerator.cxx
+++ b/Source/cmGhsMultiTargetGenerator.cxx
@@ -22,23 +22,22 @@
 std::string const cmGhsMultiTargetGenerator::DDOption("-dynamic");
 
 cmGhsMultiTargetGenerator::cmGhsMultiTargetGenerator(cmGeneratorTarget *target)
-  : Target(target->Target)
-  , GeneratorTarget(target)
+  : GeneratorTarget(target)
   , LocalGenerator(static_cast<cmLocalGhsMultiGenerator *>(
                      target->GetLocalGenerator()))
   , Makefile(target->Target->GetMakefile())
-  , TargetGroup(DetermineIfTargetGroup(target->Target))
+  , TargetGroup(DetermineIfTargetGroup(target))
   , DynamicDownload(false)
 {
-  this->RelBuildFilePath = this->GetRelBuildFilePath(target->Target);
+  this->RelBuildFilePath = this->GetRelBuildFilePath(target);
 
   this->RelOutputFileName =
-    this->RelBuildFilePath + this->Target->GetName() + ".a";
+    this->RelBuildFilePath + target->GetName() + ".a";
 
   this->RelBuildFileName = this->RelBuildFilePath;
-  this->RelBuildFileName += this->GetBuildFileName(target->Target);
+  this->RelBuildFileName += this->GetBuildFileName(target);
 
-  std::string absPathToRoot = this->GetAbsPathToRoot(target->Target);
+  std::string absPathToRoot = this->GetAbsPathToRoot(target);
   absPathToRoot = this->AddSlashIfNeededToPath(absPathToRoot);
   this->AbsBuildFilePath = absPathToRoot + this->RelBuildFilePath;
   this->AbsBuildFileName = absPathToRoot + this->RelBuildFileName;
@@ -51,7 +50,8 @@ cmGhsMultiTargetGenerator::~cmGhsMultiTargetGenerator()
 }
 
 std::string
-cmGhsMultiTargetGenerator::GetRelBuildFilePath(const cmTarget *target)
+cmGhsMultiTargetGenerator::GetRelBuildFilePath(
+        const cmGeneratorTarget *target)
 {
   std::string output;
   char const *folderProp = target->GetProperty("FOLDER");
@@ -66,13 +66,13 @@ cmGhsMultiTargetGenerator::GetRelBuildFilePath(const cmTarget *target)
 }
 
 std::string
-cmGhsMultiTargetGenerator::GetAbsPathToRoot(const cmTarget *target)
+cmGhsMultiTargetGenerator::GetAbsPathToRoot(const cmGeneratorTarget *target)
 {
-  return target->GetMakefile()->GetHomeOutputDirectory();
+  return target->GetLocalGenerator()->GetBinaryDirectory();
 }
 
 std::string
-cmGhsMultiTargetGenerator::GetAbsBuildFilePath(const cmTarget *target)
+cmGhsMultiTargetGenerator::GetAbsBuildFilePath(const cmGeneratorTarget *target)
 {
   std::string output;
   output = cmGhsMultiTargetGenerator::GetAbsPathToRoot(target);
@@ -82,7 +82,7 @@ cmGhsMultiTargetGenerator::GetAbsBuildFilePath(const cmTarget *target)
 }
 
 std::string
-cmGhsMultiTargetGenerator::GetRelBuildFileName(const cmTarget *target)
+cmGhsMultiTargetGenerator::GetRelBuildFileName(const cmGeneratorTarget *target)
 {
   std::string output;
   output = cmGhsMultiTargetGenerator::GetRelBuildFilePath(target);
@@ -91,7 +91,8 @@ cmGhsMultiTargetGenerator::GetRelBuildFileName(const cmTarget *target)
   return  output;
 }
 
-std::string cmGhsMultiTargetGenerator::GetBuildFileName(const cmTarget *target)
+std::string
+cmGhsMultiTargetGenerator::GetBuildFileName(const cmGeneratorTarget *target)
 {
   std::string output;
   output = target->GetName();
@@ -146,7 +147,7 @@ void cmGhsMultiTargetGenerator::Generate()
     this->WriteCompilerFlags(config, language);
     this->WriteCompilerDefinitions(config, language);
     this->WriteIncludes(config, language);
-    if (this->Target->GetType() == cmTarget::EXECUTABLE)
+    if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE)
       {
       this->WriteTargetLinkLibraries();
       }
@@ -159,7 +160,8 @@ void cmGhsMultiTargetGenerator::Generate()
 bool cmGhsMultiTargetGenerator::IncludeThisTarget()
 {
   bool output = true;
-  char const *excludeFromAll = this->Target->GetProperty("EXCLUDE_FROM_ALL");
+  char const *excludeFromAll =
+      this->GeneratorTarget->GetProperty("EXCLUDE_FROM_ALL");
   if (NULL != excludeFromAll && '1' == excludeFromAll[0] &&
       '\0' == excludeFromAll[1])
     {
@@ -172,23 +174,24 @@ std::vector<cmSourceFile *> cmGhsMultiTargetGenerator::GetSources() const
 {
   std::vector<cmSourceFile *> output;
   std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
-  this->Target->GetSourceFiles(output, config);
+  this->GeneratorTarget->GetSourceFiles(output, config);
   return output;
 }
 
 GhsMultiGpj::Types cmGhsMultiTargetGenerator::GetGpjTag() const
 {
-  return cmGhsMultiTargetGenerator::GetGpjTag(this->Target);
+  return cmGhsMultiTargetGenerator::GetGpjTag(this->GeneratorTarget);
 }
 
-GhsMultiGpj::Types cmGhsMultiTargetGenerator::GetGpjTag(const cmTarget *target)
+GhsMultiGpj::Types cmGhsMultiTargetGenerator::GetGpjTag(
+    const cmGeneratorTarget *target)
 {
   GhsMultiGpj::Types output;
   if (cmGhsMultiTargetGenerator::DetermineIfTargetGroup(target))
     {
     output = GhsMultiGpj::INTERGRITY_APPLICATION;
     }
-  else if (target->GetType() == cmTarget::STATIC_LIBRARY)
+  else if (target->GetType() == cmState::STATIC_LIBRARY)
     {
     output = GhsMultiGpj::LIBRARY;
     }
@@ -212,13 +215,13 @@ void cmGhsMultiTargetGenerator::WriteTypeSpecifics(const std::string &config,
   std::string outputDir(this->GetOutputDirectory(config));
   std::string outputFilename(this->GetOutputFilename(config));
 
-  if (this->Target->GetType() == cmTarget::STATIC_LIBRARY)
+  if (this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY)
     {
-    *this->GetFolderBuildStreams() << "    {optgroup=GhsCommonOptions} -o \""
+    *this->GetFolderBuildStreams() << "    -o \""
                                    << outputDir << outputFilename << ".a\""
                                    << std::endl;
     }
-  else if (this->Target->GetType() == cmTarget::EXECUTABLE)
+  else if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE)
     {
     if (notKernel && !this->IsTargetGroup())
       {
@@ -227,7 +230,7 @@ void cmGhsMultiTargetGenerator::WriteTypeSpecifics(const std::string &config,
     if (this->IsTargetGroup())
       {
       *this->GetFolderBuildStreams()
-          << "    {optgroup=GhsCommonOptions} -o \"" << outputDir
+          << "    -o \"" << outputDir
           << outputFilename << ".elf\"" << std::endl;
       *this->GetFolderBuildStreams() << "    :extraOutputFile=\"" << outputDir
                                      << outputFilename << ".elf.ael\""
@@ -235,7 +238,7 @@ void cmGhsMultiTargetGenerator::WriteTypeSpecifics(const std::string &config,
       }
     else
       {
-      *this->GetFolderBuildStreams() << "    {optgroup=GhsCommonOptions} -o \""
+      *this->GetFolderBuildStreams() << "    -o \""
                                      << outputDir << outputFilename << ".as\""
                                      << std::endl;
       }
@@ -262,8 +265,11 @@ void cmGhsMultiTargetGenerator::SetCompilerFlags(std::string const &config,
         this->LocalGenerator->AddLanguageFlags(
             flags, lang + std::string("_GHS_KERNEL"), config);
       }
-    this->LocalGenerator->AddCMP0018Flags(flags, this->Target, lang, config);
-    this->LocalGenerator->AddVisibilityPresetFlags(flags, this->Target, lang);
+    this->LocalGenerator->AddCMP0018Flags(flags, this->GeneratorTarget,
+                                          lang, config);
+    this->LocalGenerator->AddVisibilityPresetFlags(flags,
+                                                   this->GeneratorTarget,
+                                                   lang);
 
     // Append old-style preprocessor definition flags.
     if (std::string(" ") != std::string(this->Makefile->GetDefineFlags()))
@@ -273,7 +279,8 @@ void cmGhsMultiTargetGenerator::SetCompilerFlags(std::string const &config,
       }
 
     // Add target-specific flags.
-    this->LocalGenerator->AddCompileOptions(flags, this->Target, lang, config);
+    this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget,
+                                            lang, config);
 
     std::map<std::string, std::string>::value_type entry(language, flags);
     i = this->FlagsByLanguage.insert(entry).first;
@@ -290,13 +297,14 @@ std::string cmGhsMultiTargetGenerator::GetDefines(const std::string &language,
     std::set<std::string> defines;
     const char *lang = language.c_str();
     // Add the export symbol definition for shared library objects.
-    if (const char *exportMacro = this->Target->GetExportMacro())
+    if (const char *exportMacro = this->GeneratorTarget->GetExportMacro())
       {
       this->LocalGenerator->AppendDefines(defines, exportMacro);
       }
 
     // Add preprocessor definitions for this target and configuration.
-    this->LocalGenerator->AddCompileDefinitions(defines, this->Target, config,
+    this->LocalGenerator->AddCompileDefinitions(defines,
+                                                this->GeneratorTarget, config,
                                                 language);
 
     std::string definesString;
@@ -359,13 +367,13 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLibraries()
   for (cmTargetDependSet::iterator tdsI = tds.begin(); tdsI != tds.end();
        ++tdsI)
     {
-    const cmTarget *tg = (*tdsI)->Target;
+    const cmGeneratorTarget *tg = *tdsI;
     *this->GetFolderBuildStreams() << "    -L\"" << GetAbsBuildFilePath(tg)
                                    << "\"" << std::endl;
     }
   // library targets
   cmTarget::LinkLibraryVectorType llv =
-    this->Target->GetOriginalLinkLibraries();
+    this->GeneratorTarget->Target->GetOriginalLinkLibraries();
   for (cmTarget::LinkLibraryVectorType::const_iterator llvI = llv.begin();
        llvI != llv.end(); ++llvI)
     {
@@ -383,10 +391,12 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLibraries()
 
 void cmGhsMultiTargetGenerator::WriteCustomCommands()
 {
-  WriteCustomCommandsHelper(this->Target->GetPreBuildCommands(),
-                            cmTarget::PRE_BUILD);
-  WriteCustomCommandsHelper(this->Target->GetPostBuildCommands(),
-                            cmTarget::POST_BUILD);
+  WriteCustomCommandsHelper(
+        this->GeneratorTarget->GetPreBuildCommands(),
+        cmTarget::PRE_BUILD);
+  WriteCustomCommandsHelper(
+        this->GeneratorTarget->GetPostBuildCommands(),
+        cmTarget::POST_BUILD);
 }
 
 void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper(
@@ -449,7 +459,7 @@ void cmGhsMultiTargetGenerator::WriteSources(
     cmSystemTools::ConvertToUnixSlashes(sgPath);
     cmGlobalGhsMultiGenerator::AddFilesUpToPath(
       this->GetFolderBuildStreams(), &this->FolderBuildStreams,
-      this->Makefile->GetHomeOutputDirectory(), sgPath,
+      this->LocalGenerator->GetBinaryDirectory(), sgPath,
       GhsMultiGpj::SUBPROJECT, this->RelBuildFilePath);
 
     std::string fullSourcePath((*si)->GetFullPath());
@@ -510,7 +520,7 @@ cmGhsMultiTargetGenerator::GetOutputDirectory(const std::string &config) const
   std::string outputDir(AbsBuildFilePath);
 
   const char *runtimeOutputProp =
-    this->Target->GetProperty("RUNTIME_OUTPUT_DIRECTORY");
+    this->GeneratorTarget->GetProperty("RUNTIME_OUTPUT_DIRECTORY");
   if (NULL != runtimeOutputProp)
     {
     outputDir = runtimeOutputProp;
@@ -518,7 +528,8 @@ cmGhsMultiTargetGenerator::GetOutputDirectory(const std::string &config) const
 
   std::string configCapped(cmSystemTools::UpperCase(config));
   const char *runtimeOutputSProp =
-    this->Target->GetProperty("RUNTIME_OUTPUT_DIRECTORY_" + configCapped);
+    this->GeneratorTarget
+      ->GetProperty("RUNTIME_OUTPUT_DIRECTORY_" + configCapped);
   if (NULL != runtimeOutputSProp)
     {
     outputDir = runtimeOutputSProp;
@@ -536,9 +547,10 @@ cmGhsMultiTargetGenerator::GetOutputDirectory(const std::string &config) const
 std::string
 cmGhsMultiTargetGenerator::GetOutputFilename(const std::string &config) const
 {
-  std::string outputFilename(this->Target->GetName());
+  std::string outputFilename(this->GeneratorTarget->GetName());
 
-  const char *outputNameProp = this->Target->GetProperty("OUTPUT_NAME");
+  const char *outputNameProp =
+      this->GeneratorTarget->GetProperty("OUTPUT_NAME");
   if (NULL != outputNameProp)
     {
     outputFilename = outputNameProp;
@@ -546,7 +558,7 @@ cmGhsMultiTargetGenerator::GetOutputFilename(const std::string &config) const
 
   std::string configCapped(cmSystemTools::UpperCase(config));
   const char *outputNameSProp =
-    this->Target->GetProperty(configCapped + "_OUTPUT_NAME");
+    this->GeneratorTarget->GetProperty(configCapped + "_OUTPUT_NAME");
   if (NULL != outputNameSProp)
     {
     outputFilename = outputNameSProp;
@@ -566,12 +578,13 @@ bool cmGhsMultiTargetGenerator::IsNotKernel(std::string const &config,
   return output;
 }
 
-bool cmGhsMultiTargetGenerator::DetermineIfTargetGroup(const cmTarget *target)
+bool cmGhsMultiTargetGenerator::DetermineIfTargetGroup(
+    const cmGeneratorTarget *target)
 {
   bool output = false;
   std::vector<cmSourceFile *> sources;
   std::string config =
-      target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
+      target->Target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
   target->GetSourceFiles(sources, config);
   for (std::vector<cmSourceFile *>::const_iterator sources_i = sources.begin();
        sources.end() != sources_i; ++sources_i)
diff --git a/Source/cmGhsMultiTargetGenerator.h b/Source/cmGhsMultiTargetGenerator.h
index c29a31e..327fdef 100644
--- a/Source/cmGhsMultiTargetGenerator.h
+++ b/Source/cmGhsMultiTargetGenerator.h
@@ -36,7 +36,7 @@ public:
   bool IncludeThisTarget();
   std::vector<cmSourceFile *> GetSources() const;
   GhsMultiGpj::Types GetGpjTag() const;
-  static GhsMultiGpj::Types GetGpjTag(const cmTarget *target);
+  static GhsMultiGpj::Types GetGpjTag(const cmGeneratorTarget* target);
   const char *GetAbsBuildFilePath() const
   {
     return this->AbsBuildFilePath.c_str();
@@ -54,11 +54,11 @@ public:
     return this->AbsOutputFileName.c_str();
   }
 
-  static std::string GetRelBuildFilePath(const cmTarget *target);
-  static std::string GetAbsPathToRoot(const cmTarget *target);
-  static std::string GetAbsBuildFilePath(const cmTarget *target);
-  static std::string GetRelBuildFileName(const cmTarget *target);
-  static std::string GetBuildFileName(const cmTarget *target);
+  static std::string GetRelBuildFilePath(const cmGeneratorTarget *target);
+  static std::string GetAbsPathToRoot(const cmGeneratorTarget *target);
+  static std::string GetAbsBuildFilePath(const cmGeneratorTarget *target);
+  static std::string GetRelBuildFileName(const cmGeneratorTarget *target);
+  static std::string GetBuildFileName(const cmGeneratorTarget *target);
   static std::string AddSlashIfNeededToPath(std::string const &input);
 
 private:
@@ -95,11 +95,10 @@ private:
   std::string GetOutputFilename(const std::string &config) const;
 
   bool IsNotKernel(std::string const &config, const std::string &language);
-  static bool DetermineIfTargetGroup(const cmTarget *target);
+  static bool DetermineIfTargetGroup(const cmGeneratorTarget* target);
   bool DetermineIfDynamicDownload(std::string const &config,
                                   const std::string &language);
 
-  cmTarget *Target;
   cmGeneratorTarget* GeneratorTarget;
   cmLocalGhsMultiGenerator *LocalGenerator;
   cmMakefile *Makefile;
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 4a48b5d..848028f 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -48,6 +48,18 @@
 
 #include <assert.h>
 
+bool cmTarget::StrictTargetComparison::operator()(cmTarget const* t1,
+                                                  cmTarget const* t2) const
+{
+  int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
+  if (nameResult == 0)
+    {
+    return strcmp(t1->GetMakefile()->GetCurrentBinaryDirectory(),
+                  t2->GetMakefile()->GetCurrentBinaryDirectory()) < 0;
+    }
+  return nameResult < 0;
+}
+
 cmGlobalGenerator::cmGlobalGenerator(cmake* cm)
   : CMakeInstance(cm)
 {
@@ -73,7 +85,14 @@ cmGlobalGenerator::cmGlobalGenerator(cmake* cm)
   this->CurrentMakefile = 0;
   this->TryCompileOuterMakefile = 0;
 
-  this->ConfigureDoneCMP0026 = false;
+  this->ConfigureDoneCMP0026AndCMP0024 = false;
+
+  cm->GetState()->SetMinGWMake(false);
+  cm->GetState()->SetMSYSShell(false);
+  cm->GetState()->SetNMake(false);
+  cm->GetState()->SetWatcomWMake(false);
+  cm->GetState()->SetWindowsShell(false);
+  cm->GetState()->SetWindowsVSIDE(false);
 }
 
 cmGlobalGenerator::~cmGlobalGenerator()
@@ -234,6 +253,16 @@ bool cmGlobalGenerator::GenerateImportFile(const std::string &file)
   if (it != this->BuildExportSets.end())
     {
     bool result = it->second->GenerateImportFile();
+
+    if (!this->ConfigureDoneCMP0026AndCMP0024)
+      {
+      for (std::vector<cmMakefile*>::const_iterator mit =
+           this->Makefiles.begin(); mit != this->Makefiles.end(); ++mit)
+        {
+        (*mit)->RemoveExportBuildFileGeneratorCMP0024(it->second);
+        }
+      }
+
     delete it->second;
     it->second = 0;
     this->BuildExportSets.erase(it);
@@ -399,7 +428,7 @@ cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages,
   bool fatalError = false;
 
   mf->AddDefinition("RUN_CONFIGURE", true);
-  std::string rootBin = mf->GetHomeOutputDirectory();
+  std::string rootBin = this->CMakeInstance->GetHomeOutputDirectory();
   rootBin += cmake::GetCMakeFilesDirectory();
 
   // If the configuration files path has been set,
@@ -1108,25 +1137,25 @@ void cmGlobalGenerator::Configure()
   this->FirstTimeProgress = 0.0f;
   this->ClearGeneratorMembers();
 
-  cmMakefile* dirMf =
-      new cmMakefile(this, this->GetCMakeInstance()->GetCurrentSnapshot());
-  this->Makefiles.push_back(dirMf);
+  cmState::Snapshot snapshot = this->CMakeInstance->GetCurrentSnapshot();
 
-  // set the Start directories
-  dirMf->SetCurrentSourceDirectory
+  snapshot.GetDirectory().SetCurrentSource
     (this->CMakeInstance->GetHomeDirectory());
-  dirMf->SetCurrentBinaryDirectory
+  snapshot.GetDirectory().SetCurrentBinary
     (this->CMakeInstance->GetHomeOutputDirectory());
 
+  cmMakefile* dirMf = new cmMakefile(this, snapshot);
+  this->Makefiles.push_back(dirMf);
+
   this->BinaryDirectories.insert(
       this->CMakeInstance->GetHomeOutputDirectory());
 
   // now do it
-  this->ConfigureDoneCMP0026 = false;
+  this->ConfigureDoneCMP0026AndCMP0024 = false;
   dirMf->Configure();
   dirMf->EnforceDirectoryLevelRules();
 
-  this->ConfigureDoneCMP0026 = true;
+  this->ConfigureDoneCMP0026AndCMP0024 = true;
 
   // Put a copy of each global target in every directory.
   cmTargets globalTargets;
@@ -1186,9 +1215,28 @@ void cmGlobalGenerator::Configure()
 void cmGlobalGenerator::CreateGenerationObjects(TargetTypes targetTypes)
 {
   this->CreateLocalGenerators();
-  cmDeleteAll(this->GeneratorTargets);
-  this->GeneratorTargets.clear();
   this->CreateGeneratorTargets(targetTypes);
+  this->ComputeBuildFileGenerators();
+}
+
+void cmGlobalGenerator::CreateImportedGenerationObjects(cmMakefile* mf,
+    const std::vector<std::string>& targets,
+    std::vector<const cmGeneratorTarget*>& exports)
+{
+  this->CreateGenerationObjects(ImportedOnly);
+  std::vector<cmMakefile*>::iterator mfit =
+      std::find(this->Makefiles.begin(), this->Makefiles.end(), mf);
+  cmLocalGenerator* lg =
+      this->LocalGenerators[std::distance(this->Makefiles.begin(), mfit)];
+  for (std::vector<std::string>::const_iterator it = targets.begin();
+       it != targets.end(); ++it)
+    {
+    cmGeneratorTarget* gt = lg->FindGeneratorTargetToUse(*it);
+    if (gt)
+      {
+      exports.push_back(gt);
+      }
+    }
 }
 
 cmExportBuildFileGenerator*
@@ -1226,6 +1274,20 @@ bool cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const
   return false;
 }
 
+void cmGlobalGenerator::ComputeBuildFileGenerators()
+{
+  for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
+    {
+    std::vector<cmExportBuildFileGenerator*> gens =
+        this->Makefiles[i]->GetExportBuildFileGenerators();
+    for (std::vector<cmExportBuildFileGenerator*>::const_iterator it =
+         gens.begin(); it != gens.end(); ++it)
+      {
+      (*it)->Compute(this->LocalGenerators[i]);
+      }
+    }
+}
+
 bool cmGlobalGenerator::Compute()
 {
   // Some generators track files replaced during the Generate.
@@ -1251,7 +1313,7 @@ bool cmGlobalGenerator::Compute()
 #ifdef CMAKE_BUILD_WITH_CMAKE
   // Iterate through all targets and set up automoc for those which have
   // the AUTOMOC, AUTOUIC or AUTORCC property set
-  std::vector<cmTarget const*> autogenTargets =
+  std::vector<cmGeneratorTarget const*> autogenTargets =
       this->CreateQtAutoGeneratorsTargets();
 #endif
 
@@ -1264,8 +1326,8 @@ bool cmGlobalGenerator::Compute()
     }
 
 #ifdef CMAKE_BUILD_WITH_CMAKE
-  for (std::vector<cmTarget const*>::iterator it = autogenTargets.begin();
-       it != autogenTargets.end(); ++it)
+  for (std::vector<cmGeneratorTarget const*>::iterator it =
+       autogenTargets.begin(); it != autogenTargets.end(); ++it)
     {
     cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget(*it);
     }
@@ -1282,12 +1344,7 @@ bool cmGlobalGenerator::Compute()
       }
     }
 
-  return true;
-}
-
-void cmGlobalGenerator::Generate()
-{
-  unsigned int i;
+  this->AddExtraIDETargets();
 
   // Trace the dependencies, after that no custom commands should be added
   // because their dependencies might not be handled correctly
@@ -1307,22 +1364,27 @@ void cmGlobalGenerator::Generate()
   // Compute the inter-target dependencies.
   if(!this->ComputeTargetDepends())
     {
-    return;
+    return false;
     }
 
+  for (i = 0; i < this->LocalGenerators.size(); ++i)
+    {
+    this->LocalGenerators[i]->ComputeHomeRelativeOutputPath();
+    }
+
+  return true;
+}
+
+void cmGlobalGenerator::Generate()
+{
   // Create a map from local generator to the complete set of targets
   // it builds by default.
   this->InitializeProgressMarks();
 
   this->ProcessEvaluationFiles();
 
-  for (i = 0; i < this->LocalGenerators.size(); ++i)
-    {
-    this->LocalGenerators[i]->ComputeHomeRelativeOutputPath();
-    }
-
   // Generate project files
-  for (i = 0; i < this->LocalGenerators.size(); ++i)
+  for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
     {
     this->SetCurrentMakefile(this->LocalGenerators[i]->GetMakefile());
     this->LocalGenerators[i]->Generate();
@@ -1403,42 +1465,42 @@ bool cmGlobalGenerator::ComputeTargetDepends()
 }
 
 //----------------------------------------------------------------------------
-std::vector<const cmTarget*>
+std::vector<const cmGeneratorTarget*>
 cmGlobalGenerator::CreateQtAutoGeneratorsTargets()
 {
-  std::vector<const cmTarget*> autogenTargets;
+  std::vector<const cmGeneratorTarget*> autogenTargets;
 
 #ifdef CMAKE_BUILD_WITH_CMAKE
   for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
     {
-    cmTargets& targets =
-      this->LocalGenerators[i]->GetMakefile()->GetTargets();
-    std::vector<std::string> targetNames;
-    targetNames.reserve(targets.size());
-    for(cmTargets::iterator ti = targets.begin();
+    std::vector<cmGeneratorTarget*> targets =
+      this->LocalGenerators[i]->GetGeneratorTargets();
+    std::vector<cmGeneratorTarget*> filteredTargets;
+    filteredTargets.reserve(targets.size());
+    for(std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
         ti != targets.end(); ++ti)
       {
-      if (ti->second.GetType() == cmTarget::GLOBAL_TARGET)
+      if ((*ti)->GetType() == cmState::GLOBAL_TARGET)
         {
         continue;
         }
-      if(ti->second.GetType() != cmTarget::EXECUTABLE &&
-         ti->second.GetType() != cmTarget::STATIC_LIBRARY &&
-         ti->second.GetType() != cmTarget::SHARED_LIBRARY &&
-         ti->second.GetType() != cmTarget::MODULE_LIBRARY &&
-         ti->second.GetType() != cmTarget::OBJECT_LIBRARY)
+      if((*ti)->GetType() != cmState::EXECUTABLE &&
+         (*ti)->GetType() != cmState::STATIC_LIBRARY &&
+         (*ti)->GetType() != cmState::SHARED_LIBRARY &&
+         (*ti)->GetType() != cmState::MODULE_LIBRARY &&
+         (*ti)->GetType() != cmState::OBJECT_LIBRARY)
         {
         continue;
         }
-      if((!ti->second.GetPropertyAsBool("AUTOMOC")
-            && !ti->second.GetPropertyAsBool("AUTOUIC")
-            && !ti->second.GetPropertyAsBool("AUTORCC"))
-          || ti->second.IsImported())
+      if((!(*ti)->GetPropertyAsBool("AUTOMOC")
+            && !(*ti)->GetPropertyAsBool("AUTOUIC")
+            && !(*ti)->GetPropertyAsBool("AUTORCC"))
+          || (*ti)->IsImported())
         {
         continue;
         }
       // don't do anything if there is no Qt4 or Qt5Core (which contains moc):
-      cmMakefile* mf = ti->second.GetMakefile();
+      cmMakefile* mf = (*ti)->Target->GetMakefile();
       std::string qtMajorVersion = mf->GetSafeDefinition("QT_VERSION_MAJOR");
       if (qtMajorVersion == "")
         {
@@ -1449,17 +1511,17 @@ cmGlobalGenerator::CreateQtAutoGeneratorsTargets()
         continue;
         }
 
-      cmQtAutoGeneratorInitializer::InitializeAutogenSources(&ti->second);
-      targetNames.push_back(ti->second.GetName());
+      cmGeneratorTarget* gt = *ti;
+
+      cmQtAutoGeneratorInitializer::InitializeAutogenSources(gt);
+      filteredTargets.push_back(gt);
       }
-    for(std::vector<std::string>::iterator ti = targetNames.begin();
-        ti != targetNames.end(); ++ti)
+    for(std::vector<cmGeneratorTarget*>::iterator ti = filteredTargets.begin();
+        ti != filteredTargets.end(); ++ti)
       {
-      cmTarget* target = this->LocalGenerators[i]
-                              ->GetMakefile()->FindTarget(*ti, true);
       cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
-           this->LocalGenerators[i], target);
-      autogenTargets.push_back(target);
+           this->LocalGenerators[i], *ti);
+      autogenTargets.push_back(*ti);
       }
     }
 #endif
@@ -1484,14 +1546,14 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo()
         ti != targets.end(); ++ti)
       {
       cmTarget* t = &ti->second;
-      if (t->GetType() == cmTarget::GLOBAL_TARGET)
+      if (t->GetType() == cmState::GLOBAL_TARGET)
         {
         continue;
         }
 
       t->AppendBuildInterfaceIncludes();
 
-      if (t->GetType() == cmTarget::INTERFACE_LIBRARY)
+      if (t->GetType() == cmState::INTERFACE_LIBRARY)
         {
         continue;
         }
@@ -1526,11 +1588,12 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo()
 }
 
 //----------------------------------------------------------------------------
-void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes,
-                                               cmLocalGenerator *lg)
+void cmGlobalGenerator::CreateGeneratorTargets(
+    TargetTypes targetTypes,
+    cmMakefile *mf,
+    cmLocalGenerator *lg,
+    std::map<cmTarget*, cmGeneratorTarget*> const& importedMap)
 {
-  cmGeneratorTargetsType generatorTargets;
-  cmMakefile* mf = lg->GetMakefile();
   if (targetTypes == AllTargets)
     {
     cmTargets& targets = mf->GetTargets();
@@ -1539,29 +1602,42 @@ void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes,
       {
       cmTarget* t = &ti->second;
       cmGeneratorTarget* gt = new cmGeneratorTarget(t, lg);
-      this->GeneratorTargets[t] = gt;
-      generatorTargets[t] = gt;
+      lg->AddGeneratorTarget(gt);
       }
     }
 
+  std::vector<cmTarget*> itgts = mf->GetImportedTargets();
+
   for(std::vector<cmTarget*>::const_iterator
-        j = mf->GetOwnedImportedTargets().begin();
-      j != mf->GetOwnedImportedTargets().end(); ++j)
+        j = itgts.begin(); j != itgts.end(); ++j)
     {
-    cmGeneratorTarget* gt = new cmGeneratorTarget(*j, lg);
-    this->GeneratorTargets[*j] = gt;
-    generatorTargets[*j] = gt;
+    lg->AddImportedGeneratorTarget(importedMap.find(*j)->second);
     }
-  mf->SetGeneratorTargets(generatorTargets);
 }
 
 //----------------------------------------------------------------------------
 void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes)
 {
+  std::map<cmTarget*, cmGeneratorTarget*> importedMap;
+  for(unsigned int i=0; i < this->Makefiles.size(); ++i)
+    {
+    cmMakefile* mf = this->Makefiles[i];
+    for(std::vector<cmTarget*>::const_iterator
+          j = mf->GetOwnedImportedTargets().begin();
+        j != mf->GetOwnedImportedTargets().end(); ++j)
+      {
+      cmLocalGenerator* lg = this->LocalGenerators[i];
+      cmGeneratorTarget* gt = new cmGeneratorTarget(*j, lg);
+      lg->AddOwnedImportedGeneratorTarget(gt);
+      importedMap[*j] = gt;
+      }
+    }
+
   // Construct per-target generator information.
   for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
     {
-    this->CreateGeneratorTargets(targetTypes, this->LocalGenerators[i]);
+    this->CreateGeneratorTargets(targetTypes, this->Makefiles[i],
+                                 this->LocalGenerators[i], importedMap);
     }
 }
 
@@ -1569,9 +1645,6 @@ void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes)
 //----------------------------------------------------------------------------
 void cmGlobalGenerator::ClearGeneratorMembers()
 {
-  cmDeleteAll(this->GeneratorTargets);
-  this->GeneratorTargets.clear();
-
   cmDeleteAll(this->BuildExportSets);
   this->BuildExportSets.clear();
 
@@ -1583,8 +1656,8 @@ void cmGlobalGenerator::ClearGeneratorMembers()
 
   this->ExportSets.clear();
   this->TargetDependencies.clear();
-  this->TotalTargets.clear();
-  this->ImportedTargets.clear();
+  this->TargetSearchIndex.clear();
+  this->GeneratorTargetSearchIndex.clear();
   this->ProjectMap.clear();
   this->RuleHashes.clear();
   this->DirectoryContentMap.clear();
@@ -1592,20 +1665,6 @@ void cmGlobalGenerator::ClearGeneratorMembers()
 }
 
 //----------------------------------------------------------------------------
-cmGeneratorTarget*
-cmGlobalGenerator::GetGeneratorTarget(cmTarget const* t) const
-{
-  cmGeneratorTargetsType::const_iterator ti = this->GeneratorTargets.find(t);
-  if(ti == this->GeneratorTargets.end())
-    {
-    this->CMakeInstance->IssueMessage(
-      cmake::INTERNAL_ERROR, "Missing cmGeneratorTarget instance!");
-    return 0;
-    }
-  return ti->second;
-}
-
-//----------------------------------------------------------------------------
 void cmGlobalGenerator::ComputeTargetObjectDirectory(cmGeneratorTarget*) const
 {
 }
@@ -1624,7 +1683,7 @@ void cmGlobalGenerator::CheckTargetProperties()
     for (cmTargets::iterator l = targets.begin();
          l != targets.end(); l++)
       {
-      if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
+      if (l->second.GetType() == cmState::INTERFACE_LIBRARY)
         {
         continue;
         }
@@ -1800,7 +1859,7 @@ int cmGlobalGenerator::Build(
       !makeCommand.empty() && cmSystemTools::LowerCase(
         cmSystemTools::GetFilenameName(makeCommand[0])) == "vcexpress.exe")
     {
-    outputflag = cmSystemTools::OUTPUT_NORMAL;
+    outputflag = cmSystemTools::OUTPUT_FORWARD;
     }
 
   // should we do a clean first?
@@ -2032,8 +2091,8 @@ bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
 bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
                                    cmGeneratorTarget* target) const
 {
-  if(target->GetType() == cmTarget::INTERFACE_LIBRARY
-      || target->Target->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
+  if(target->GetType() == cmState::INTERFACE_LIBRARY
+      || target->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
     {
     // This target is excluded from its directory.
     return true;
@@ -2105,7 +2164,7 @@ cmGlobalGenerator::FindLocalGenerator(const std::string& start_dir) const
   for(std::vector<cmLocalGenerator*>::const_iterator it =
       this->LocalGenerators.begin(); it != this->LocalGenerators.end(); ++it)
     {
-    std::string sd = (*it)->GetMakefile()->GetCurrentSourceDirectory();
+    std::string sd = (*it)->GetCurrentSourceDirectory();
     if (sd == start_dir)
       {
       return *it;
@@ -2115,9 +2174,10 @@ cmGlobalGenerator::FindLocalGenerator(const std::string& start_dir) const
 }
 
 //----------------------------------------------------------------------------
-void cmGlobalGenerator::AddAlias(const std::string& name, cmTarget *tgt)
+void cmGlobalGenerator::AddAlias(const std::string& name,
+                                 std::string const& tgtName)
 {
-  this->AliasTargets[name] = tgt;
+  this->AliasTargets[name] = tgtName;
 }
 
 //----------------------------------------------------------------------------
@@ -2126,6 +2186,44 @@ bool cmGlobalGenerator::IsAlias(const std::string& name) const
   return this->AliasTargets.find(name) != this->AliasTargets.end();
 }
 
+void cmGlobalGenerator::IndexTarget(cmTarget* t)
+{
+  if (!t->IsImported() || t->IsImportedGloballyVisible())
+    {
+    this->TargetSearchIndex[t->GetName()] = t;
+    }
+}
+
+void cmGlobalGenerator::IndexGeneratorTarget(cmGeneratorTarget* gt)
+{
+  if (!gt->IsImported() || gt->IsImportedGloballyVisible())
+    {
+    this->GeneratorTargetSearchIndex[gt->GetName()] = gt;
+    }
+}
+
+cmTarget* cmGlobalGenerator::FindTargetImpl(std::string const& name) const
+{
+  TargetMap::const_iterator i = this->TargetSearchIndex.find(name);
+  if (i != this->TargetSearchIndex.end())
+    {
+    return i->second;
+    }
+  return 0;
+}
+
+cmGeneratorTarget*
+cmGlobalGenerator::FindGeneratorTargetImpl(std::string const& name) const
+{
+  GeneratorTargetMap::const_iterator i =
+    this->GeneratorTargetSearchIndex.find(name);
+  if (i != this->GeneratorTargetSearchIndex.end())
+    {
+    return i->second;
+    }
+  return 0;
+}
+
 //----------------------------------------------------------------------------
 cmTarget*
 cmGlobalGenerator::FindTarget(const std::string& name,
@@ -2133,23 +2231,26 @@ cmGlobalGenerator::FindTarget(const std::string& name,
 {
   if (!excludeAliases)
     {
-    TargetMap::const_iterator ai = this->AliasTargets.find(name);
+    std::map<std::string, std::string>::const_iterator ai =
+        this->AliasTargets.find(name);
     if (ai != this->AliasTargets.end())
       {
-      return ai->second;
+      return this->FindTargetImpl(ai->second);
       }
     }
-  TargetMap::const_iterator i = this->TotalTargets.find ( name );
-  if ( i != this->TotalTargets.end() )
-    {
-    return i->second;
-    }
-  i = this->ImportedTargets.find(name);
-  if ( i != this->ImportedTargets.end() )
+  return this->FindTargetImpl(name);
+}
+
+cmGeneratorTarget*
+cmGlobalGenerator::FindGeneratorTarget(const std::string& name) const
+{
+  std::map<std::string, std::string>::const_iterator ai =
+      this->AliasTargets.find(name);
+  if (ai != this->AliasTargets.end())
     {
-    return i->second;
+    return this->FindGeneratorTargetImpl(ai->second);
     }
-  return 0;
+  return this->FindGeneratorTargetImpl(name);
 }
 
 //----------------------------------------------------------------------------
@@ -2493,7 +2594,7 @@ cmTarget cmGlobalGenerator::CreateGlobalTarget(
 {
   // Package
   cmTarget target;
-  target.SetType(cmTarget::GLOBAL_TARGET, name);
+  target.SetType(cmState::GLOBAL_TARGET, name);
   target.SetProperty("EXCLUDE_FROM_ALL","TRUE");
 
   std::vector<std::string> no_outputs;
@@ -2567,18 +2668,6 @@ cmGlobalGenerator::GetTargetDirectDepends(cmGeneratorTarget const* target)
   return this->TargetDependencies[target];
 }
 
-void cmGlobalGenerator::AddTarget(cmTarget* t)
-{
-  if(t->IsImported())
-    {
-    this->ImportedTargets[t->GetName()] = t;
-    }
-  else
-    {
-    this->TotalTargets[t->GetName()] = t;
-    }
-}
-
 bool cmGlobalGenerator::IsReservedTarget(std::string const& name)
 {
   // The following is a list of targets reserved
@@ -2651,31 +2740,30 @@ void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets,
       {
       continue;
       }
-    cmMakefile* mf = (*i)->GetMakefile();
     // Get the targets in the makefile
-    cmTargets &tgts = mf->GetTargets();
+    std::vector<cmGeneratorTarget*> tgts = (*i)->GetGeneratorTargets();
     // loop over all the targets
-    for (cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
+    for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
+         l != tgts.end(); ++l)
       {
-      cmTarget* target = &l->second;
+      cmGeneratorTarget* target = *l;
       if(this->IsRootOnlyTarget(target) &&
-         target->GetMakefile() != root->GetMakefile())
+         target->GetLocalGenerator() != root)
         {
         continue;
         }
       // put the target in the set of original targets
-      cmGeneratorTarget* gt = this->GetGeneratorTarget(target);
-      originalTargets.insert(gt);
+      originalTargets.insert(target);
       // Get the set of targets that depend on target
-      this->AddTargetDepends(gt, projectTargets);
+      this->AddTargetDepends(target, projectTargets);
       }
     }
 }
 
 //----------------------------------------------------------------------------
-bool cmGlobalGenerator::IsRootOnlyTarget(cmTarget* target) const
+bool cmGlobalGenerator::IsRootOnlyTarget(cmGeneratorTarget* target) const
 {
-  return (target->GetType() == cmTarget::GLOBAL_TARGET ||
+  return (target->GetType() == cmState::GLOBAL_TARGET ||
           target->GetName() == this->GetAllTargetName());
 }
 
@@ -2879,29 +2967,31 @@ void cmGlobalGenerator::WriteRuleHashes(std::string const& pfile)
 //----------------------------------------------------------------------------
 void cmGlobalGenerator::WriteSummary()
 {
-  cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
-
   // Record all target directories in a central location.
-  std::string fname = mf->GetHomeOutputDirectory();
+  std::string fname = this->CMakeInstance->GetHomeOutputDirectory();
   fname += cmake::GetCMakeFilesDirectory();
   fname += "/TargetDirectories.txt";
   cmGeneratedFileStream fout(fname.c_str());
 
-  // Generate summary information files for each target.
-  for(TargetMap::const_iterator ti =
-        this->TotalTargets.begin(); ti != this->TotalTargets.end(); ++ti)
+  for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
     {
-    if ((ti->second)->GetType() == cmTarget::INTERFACE_LIBRARY)
+    std::vector<cmGeneratorTarget*> tgts =
+        this->LocalGenerators[i]->GetGeneratorTargets();
+    for (std::vector<cmGeneratorTarget*>::iterator it = tgts.begin();
+         it != tgts.end(); ++it)
       {
-      continue;
+      if ((*it)->GetType() == cmState::INTERFACE_LIBRARY)
+        {
+        continue;
+        }
+      this->WriteSummary(*it);
+      fout << (*it)->GetSupportDirectory() << "\n";
       }
-    this->WriteSummary(ti->second);
-    fout << ti->second->GetSupportDirectory() << "\n";
     }
 }
 
 //----------------------------------------------------------------------------
-void cmGlobalGenerator::WriteSummary(cmTarget* target)
+void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target)
 {
   // Place the labels file in a per-target support directory.
   std::string dir = target->GetSupportDirectory();
@@ -2944,7 +3034,7 @@ void cmGlobalGenerator::WriteSummary(cmTarget* target)
     fout << "# Source files and their labels\n";
     std::vector<cmSourceFile*> sources;
     std::vector<std::string> configs;
-    target->GetMakefile()->GetConfigurations(configs);
+    target->Target->GetMakefile()->GetConfigurations(configs);
     if (configs.empty())
       {
       configs.push_back("");
@@ -3004,13 +3094,13 @@ std::string cmGlobalGenerator::EscapeJSON(const std::string& s) {
 
 //----------------------------------------------------------------------------
 void cmGlobalGenerator::SetFilenameTargetDepends(cmSourceFile* sf,
-                                              std::set<cmTarget const*> tgts)
+                                     std::set<cmGeneratorTarget const*> tgts)
 {
   this->FilenameTargetDepends[sf] = tgts;
 }
 
 //----------------------------------------------------------------------------
-std::set<cmTarget const*> const&
+std::set<cmGeneratorTarget const*> const&
 cmGlobalGenerator::GetFilenameTargetDepends(cmSourceFile* sf) const {
   return this->FilenameTargetDepends[sf];
 }
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index ba74c9e..48fa704 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -83,13 +83,17 @@ public:
    */
   virtual void Configure();
 
-  virtual bool Compute();
+  bool Compute();
+  virtual void AddExtraIDETargets() {}
 
   enum TargetTypes {
     AllTargets,
     ImportedOnly
   };
 
+  void CreateImportedGenerationObjects(cmMakefile* mf,
+                             std::vector<std::string> const& targets,
+                             std::vector<cmGeneratorTarget const*>& exports);
   void CreateGenerationObjects(TargetTypes targetTypes = AllTargets);
 
   /**
@@ -246,7 +250,9 @@ public:
   cmTarget* FindTarget(const std::string& name,
                        bool excludeAliases = false) const;
 
-  void AddAlias(const std::string& name, cmTarget *tgt);
+  cmGeneratorTarget* FindGeneratorTarget(const std::string& name) const;
+
+  void AddAlias(const std::string& name, const std::string& tgtName);
   bool IsAlias(const std::string& name) const;
 
   /** Determine if a name resolves to a framework on disk or a built target
@@ -272,7 +278,8 @@ public:
   std::set<std::string> const& GetDirectoryContent(std::string const& dir,
                                                    bool needDisk = true);
 
-  void AddTarget(cmTarget* t);
+  void IndexTarget(cmTarget* t);
+  void IndexGeneratorTarget(cmGeneratorTarget* gt);
 
   static bool IsReservedTarget(std::string const& name);
 
@@ -299,14 +306,6 @@ public:
   TargetDependSet const& GetTargetDirectDepends(
       const cmGeneratorTarget* target);
 
-  /** Get per-target generator information.  */
-  cmGeneratorTarget* GetGeneratorTarget(cmTarget const*) const;
-
-  void AddGeneratorTarget(cmTarget* t, cmGeneratorTarget* gt)
-  {
-    this->GeneratorTargets[t] = gt;
-  }
-
   const std::map<std::string, std::vector<cmLocalGenerator*> >& GetProjectMap()
                                                const {return this->ProjectMap;}
 
@@ -353,15 +352,16 @@ public:
   void CreateEvaluationSourceFiles(std::string const& config) const;
 
   void SetFilenameTargetDepends(cmSourceFile* sf,
-                                std::set<cmTarget const*> tgts);
-  std::set<cmTarget const*> const&
+                                std::set<const cmGeneratorTarget*> tgts);
+  const std::set<const cmGeneratorTarget*>&
   GetFilenameTargetDepends(cmSourceFile* sf) const;
 
 #if defined(CMAKE_BUILD_WITH_CMAKE)
   cmFileLockPool& GetFileLockPool() { return FileLockPool; }
 #endif
 
-  bool GetConfigureDoneCMP0026() const { return this->ConfigureDoneCMP0026; }
+  bool GetConfigureDoneCMP0026() const
+  { return this->ConfigureDoneCMP0026AndCMP0024; }
 
   std::string MakeSilentFlag;
 protected:
@@ -371,7 +371,7 @@ protected:
   void GetTargetSets(TargetDependSet& projectTargets,
                              TargetDependSet& originalTargets,
                              cmLocalGenerator* root, GeneratorVector const&);
-  bool IsRootOnlyTarget(cmTarget* target) const;
+  bool IsRootOnlyTarget(cmGeneratorTarget* target) const;
   void AddTargetDepends(const cmGeneratorTarget* target,
                         TargetDependSet& projectTargets);
   void SetLanguageEnabledFlag(const std::string& l, cmMakefile* mf);
@@ -384,7 +384,7 @@ protected:
 
   virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const;
 
-  std::vector<cmTarget const*> CreateQtAutoGeneratorsTargets();
+  std::vector<const cmGeneratorTarget*> CreateQtAutoGeneratorsTargets();
 
   std::string SelectMakeProgram(const std::string& makeProgram,
                                 const std::string& makeDefault = "") const;
@@ -420,24 +420,38 @@ protected:
   std::map<std::string, cmExportBuildFileGenerator*> BuildExportSets;
   std::map<std::string, cmExportBuildFileGenerator*> BuildExportExportSets;
 
-  // All targets in the entire project.
+  std::map<std::string, std::string> AliasTargets;
+
+  cmTarget* FindTargetImpl(std::string const& name) const;
+
+  cmGeneratorTarget* FindGeneratorTargetImpl(std::string const& name) const;
+  cmGeneratorTarget*
+  FindImportedGeneratorTargetImpl(std::string const& name) const;
+
+  const char* GetPredefinedTargetsFolder();
+  virtual bool UseFolderProperty();
+
+private:
+
 #if defined(CMAKE_BUILD_WITH_CMAKE)
-#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
+# ifdef CMake_HAVE_CXX11_UNORDERED_MAP
   typedef std::unordered_map<std::string, cmTarget*> TargetMap;
-#else
+  typedef std::unordered_map<std::string, cmGeneratorTarget*>
+    GeneratorTargetMap;
+# else
   typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
-#endif
+  typedef cmsys::hash_map<std::string, cmGeneratorTarget*> GeneratorTargetMap;
+# endif
 #else
   typedef std::map<std::string,cmTarget *> TargetMap;
+  typedef std::map<std::string,cmGeneratorTarget *> GeneratorTargetMap;
 #endif
-  TargetMap TotalTargets;
-  TargetMap AliasTargets;
-  TargetMap ImportedTargets;
+  // Map efficiently from target name to cmTarget instance.
+  // Do not use this structure for looping over all targets.
+  // It contains both normal and globally visible imported targets.
+  TargetMap TargetSearchIndex;
+  GeneratorTargetMap GeneratorTargetSearchIndex;
 
-  const char* GetPredefinedTargetsFolder();
-  virtual bool UseFolderProperty();
-
-private:
   cmMakefile* TryCompileOuterMakefile;
   // If you add a new map here, make sure it is copied
   // in EnableLanguagesFromGenerator
@@ -457,7 +471,7 @@ private:
   void WriteRuleHashes(std::string const& pfile);
 
   void WriteSummary();
-  void WriteSummary(cmTarget* target);
+  void WriteSummary(cmGeneratorTarget* target);
   void FinalizeTargetCompileInfo();
 
   virtual void ForceLinkerLanguages();
@@ -467,6 +481,8 @@ private:
   void CheckCompilerIdCompatibility(cmMakefile* mf,
                                     std::string const& lang) const;
 
+  void ComputeBuildFileGenerators();
+
   cmExternalMakefileProjectGenerator* ExtraGenerator;
 
   // track files replaced during a Generate
@@ -476,10 +492,10 @@ private:
   typedef std::map<cmGeneratorTarget const*, TargetDependSet> TargetDependMap;
   TargetDependMap TargetDependencies;
 
-  // Per-target generator information.
-  cmGeneratorTargetsType GeneratorTargets;
   friend class cmake;
-  void CreateGeneratorTargets(TargetTypes targetTypes, cmLocalGenerator* lg);
+  void CreateGeneratorTargets(TargetTypes targetTypes, cmMakefile* mf,
+                   cmLocalGenerator* lg,
+                   std::map<cmTarget*, cmGeneratorTarget*> const& importedMap);
   void CreateGeneratorTargets(TargetTypes targetTypes);
 
   void ClearGeneratorMembers();
@@ -504,7 +520,7 @@ private:
   // track targets to issue CMP0042 warning for.
   std::set<std::string> CMP0042WarnTargets;
 
-  mutable std::map<cmSourceFile*, std::set<cmTarget const*> >
+  mutable std::map<cmSourceFile*, std::set<cmGeneratorTarget const*> >
   FilenameTargetDepends;
 
 #if defined(CMAKE_BUILD_WITH_CMAKE)
@@ -519,7 +535,7 @@ protected:
   bool ForceUnixPaths;
   bool ToolSupportsColor;
   bool InstallTargetEnabled;
-  bool ConfigureDoneCMP0026;
+  bool ConfigureDoneCMP0026AndCMP0024;
 };
 
 #endif
diff --git a/Source/cmGlobalGeneratorFactory.h b/Source/cmGlobalGeneratorFactory.h
index ebba599..18d4324 100644
--- a/Source/cmGlobalGeneratorFactory.h
+++ b/Source/cmGlobalGeneratorFactory.h
@@ -38,6 +38,9 @@ public:
 
   /** Get the names of the current registered generators */
   virtual void GetGenerators(std::vector<std::string>& names) const = 0;
+
+  /** Determine whether or not this generator supports toolsets */
+  virtual bool SupportsToolset() const = 0;
 };
 
 template<class T>
@@ -57,6 +60,9 @@ public:
   /** Get the names of the current registered generators */
   virtual void GetGenerators(std::vector<std::string>& names) const {
     names.push_back(T::GetActualName()); }
+
+  /** Determine whether or not this generator supports toolsets */
+  virtual bool SupportsToolset() const { return T::SupportsToolset(); }
 };
 
 #endif
diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx
index 6dde1e3..1bcbd26 100644
--- a/Source/cmGlobalGhsMultiGenerator.cxx
+++ b/Source/cmGlobalGhsMultiGenerator.cxx
@@ -287,8 +287,8 @@ void cmGlobalGhsMultiGenerator::Generate()
       {
       cmLocalGhsMultiGenerator *lg =
         static_cast<cmLocalGhsMultiGenerator *>(this->LocalGenerators[i]);
-      cmGeneratorTargetsType tgts = lg->GetMakefile()->GetGeneratorTargets();
-      this->UpdateBuildFiles(&tgts);
+      std::vector<cmGeneratorTarget*> tgts = lg->GetGeneratorTargets();
+      this->UpdateBuildFiles(tgts);
       }
     }
 
@@ -481,15 +481,15 @@ cmGlobalGhsMultiGenerator::GetFileNameFromPath(std::string const &path)
 }
 
 void cmGlobalGhsMultiGenerator::UpdateBuildFiles(
-  cmGeneratorTargetsType *tgts)
+  std::vector<cmGeneratorTarget*> tgts)
 {
-  for (cmGeneratorTargetsType::iterator tgtsI = tgts->begin();
-       tgtsI != tgts->end(); ++tgtsI)
+  for (std::vector<cmGeneratorTarget*>::iterator tgtsI = tgts.begin();
+       tgtsI != tgts.end(); ++tgtsI)
     {
-    const cmTarget *tgt(tgtsI->first);
+    const cmGeneratorTarget *tgt = *tgtsI;
     if (IsTgtForBuild(tgt))
       {
-      char const *rawFolderName = tgtsI->first->GetProperty("FOLDER");
+      char const *rawFolderName = tgt->GetProperty("FOLDER");
       if (NULL == rawFolderName)
         {
         rawFolderName = "";
@@ -509,16 +509,17 @@ void cmGlobalGhsMultiGenerator::UpdateBuildFiles(
                                        splitPath.back());
       *this->TargetFolderBuildStreams[folderName] << foldNameRelBuildFile
                                                   << " ";
-      GhsMultiGpj::WriteGpjTag(cmGhsMultiTargetGenerator::GetGpjTag(tgt),
+      GhsMultiGpj::WriteGpjTag(cmGhsMultiTargetGenerator::GetGpjTag(
+                                 tgt),
                                this->TargetFolderBuildStreams[folderName]);
       }
     }
 }
 
-bool cmGlobalGhsMultiGenerator::IsTgtForBuild(const cmTarget *tgt)
+bool cmGlobalGhsMultiGenerator::IsTgtForBuild(const cmGeneratorTarget *tgt)
 {
   const std::string config =
-    tgt->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
+    tgt->Target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
   std::vector<cmSourceFile *> tgtSources;
   tgt->GetSourceFiles(tgtSources, config);
   bool tgtInBuild = true;
diff --git a/Source/cmGlobalGhsMultiGenerator.h b/Source/cmGlobalGhsMultiGenerator.h
index 8f88d4f..6f86c5d 100644
--- a/Source/cmGlobalGhsMultiGenerator.h
+++ b/Source/cmGlobalGhsMultiGenerator.h
@@ -35,6 +35,7 @@ public:
 
   /// @return the name of this generator.
   static std::string GetActualName() { return "Green Hills MULTI"; }
+
   ///! Get the name for this generator
   virtual std::string GetName() const { return this->GetActualName(); }
 
@@ -42,6 +43,12 @@ public:
   static void GetDocumentation(cmDocumentationEntry &entry);
 
   /**
+   * Utilized by the generator factory to determine if this generator
+   * supports toolsets.
+   */
+  static bool SupportsToolset() { return false; }
+
+  /**
   * Try to determine system information such as shared library
   * extension, pthreads, byte order etc.
   */
@@ -110,8 +117,8 @@ private:
       std::vector<cmsys::String>::const_iterator end,
       GhsMultiGpj::Types projType);
   static std::string GetFileNameFromPath(std::string const &path);
-  void UpdateBuildFiles(cmGeneratorTargetsType *tgts);
-  bool IsTgtForBuild(const cmTarget *tgt);
+  void UpdateBuildFiles(std::vector<cmGeneratorTarget*> tgts);
+  bool IsTgtForBuild(const cmGeneratorTarget *tgt);
 
   std::vector<cmGeneratedFileStream *> TargetSubProjects;
   std::map<std::string, cmGeneratedFileStream *> TargetFolderBuildStreams;
diff --git a/Source/cmGlobalKdevelopGenerator.cxx b/Source/cmGlobalKdevelopGenerator.cxx
index 138ddbb..018ab24 100644
--- a/Source/cmGlobalKdevelopGenerator.cxx
+++ b/Source/cmGlobalKdevelopGenerator.cxx
@@ -49,10 +49,9 @@ void cmGlobalKdevelopGenerator::Generate()
       it!= this->GlobalGenerator->GetProjectMap().end();
       ++it)
     {
-    cmMakefile* mf = it->second[0]->GetMakefile();
-    std::string outputDir=mf->GetCurrentBinaryDirectory();
-    std::string projectDir=mf->GetHomeDirectory();
-    std::string projectName=mf->GetProjectName();
+    std::string outputDir=it->second[0]->GetCurrentBinaryDirectory();
+    std::string projectDir=it->second[0]->GetSourceDirectory();
+    std::string projectName=it->second[0]->GetProjectName();
     std::string cmakeFilePattern("CMakeLists.txt;*.cmake;");
     std::string fileToOpen;
     const std::vector<cmLocalGenerator*>& lgs= it->second;
@@ -69,14 +68,14 @@ void cmGlobalKdevelopGenerator::Generate()
     for (std::vector<cmLocalGenerator*>::const_iterator lg=lgs.begin();
          lg!=lgs.end(); lg++)
       {
-      cmMakefile* makefile=(*lg)->GetMakefile();
-      cmGeneratorTargetsType const& targets = makefile->GetGeneratorTargets();
-      for (cmGeneratorTargetsType::const_iterator ti = targets.begin();
-           ti != targets.end(); ti++)
+      std::vector<cmGeneratorTarget*> const& targets =
+          (*lg)->GetGeneratorTargets();
+      for (std::vector<cmGeneratorTarget*>::const_iterator ti =
+           targets.begin(); ti != targets.end(); ti++)
         {
-        if (ti->second->GetType()==cmTarget::EXECUTABLE)
+        if ((*ti)->GetType()==cmState::EXECUTABLE)
           {
-          executable = ti->second->GetLocation("");
+          executable = (*ti)->GetLocation("");
           break;
           }
         }
@@ -106,6 +105,9 @@ bool cmGlobalKdevelopGenerator
   std::set<std::string> files;
   std::string tmp;
 
+  std::vector<std::string> hdrExts =
+      this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions();
+
   for (std::vector<cmLocalGenerator*>::const_iterator it=lgs.begin();
        it!=lgs.end(); it++)
     {
@@ -134,12 +136,13 @@ bool cmGlobalKdevelopGenerator
       }
 
     //get all sources
-    cmTargets& targets=makefile->GetTargets();
-    for (cmTargets::iterator ti = targets.begin();
+    std::vector<cmGeneratorTarget*> targets=(*it)->GetGeneratorTargets();
+    for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
          ti != targets.end(); ti++)
       {
       std::vector<cmSourceFile*> sources;
-      ti->second.GetSourceFiles(sources, ti->second.GetMakefile()
+      cmGeneratorTarget* gt = *ti;
+      gt->GetSourceFiles(sources, gt->Target->GetMakefile()
                                     ->GetSafeDefinition("CMAKE_BUILD_TYPE"));
       for (std::vector<cmSourceFile*>::const_iterator si=sources.begin();
            si!=sources.end(); si++)
@@ -160,8 +163,7 @@ bool cmGlobalKdevelopGenerator
 
           // check if there's a matching header around
           for(std::vector<std::string>::const_iterator
-                ext = makefile->GetHeaderExtensions().begin();
-              ext !=  makefile->GetHeaderExtensions().end(); ++ext)
+                ext = hdrExts.begin(); ext != hdrExts.end(); ++ext)
             {
             std::string hname=headerBasename;
             hname += ".";
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 9d8193b..0f06e43 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -275,7 +275,7 @@ void cmGlobalNinjaGenerator::AddCustomCommandRule()
                 /*deptype*/ "",
                 /*rspfile*/ "",
                 /*rspcontent*/ "",
-                /*restat*/ "1",
+                /*restat*/ "", // bound on each build statement as needed
                 /*generator*/ false);
 }
 
@@ -284,6 +284,7 @@ cmGlobalNinjaGenerator::WriteCustomCommandBuild(const std::string& command,
                                                 const std::string& description,
                                                 const std::string& comment,
                                                 bool uses_terminal,
+                                                bool restat,
                                                 const cmNinjaDeps& outputs,
                                                 const cmNinjaDeps& deps,
                                                 const cmNinjaDeps& orderOnly)
@@ -300,6 +301,10 @@ cmGlobalNinjaGenerator::WriteCustomCommandBuild(const std::string& command,
   cmNinjaVars vars;
   vars["COMMAND"] = cmd;
   vars["DESC"] = EncodeLiteral(description);
+  if (restat)
+    {
+    vars["restat"] = "1";
+    }
   if (uses_terminal && SupportsConsolePool())
     {
     vars["pool"] = "console";
@@ -548,11 +553,11 @@ void cmGlobalNinjaGenerator::Generate()
 {
   // Check minimum Ninja version.
   if (cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
-                                    CurrentNinjaVersion().c_str(),
+                                    this->NinjaVersion.c_str(),
                                     RequiredNinjaVersion().c_str()))
     {
     std::ostringstream msg;
-    msg << "The detected version of Ninja (" << this->CurrentNinjaVersion();
+    msg << "The detected version of Ninja (" << this->NinjaVersion;
     msg << ") is less than the version of Ninja required by CMake (";
     msg << this->RequiredNinjaVersion() << ").";
     this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, msg.str());
@@ -585,6 +590,23 @@ void cmGlobalNinjaGenerator::Generate()
   this->CloseBuildFileStream();
 }
 
+void cmGlobalNinjaGenerator::FindMakeProgram(cmMakefile* mf)
+{
+  this->cmGlobalGenerator::FindMakeProgram(mf);
+  if (const char* ninjaCommand = mf->GetDefinition("CMAKE_MAKE_PROGRAM"))
+    {
+    this->NinjaCommand = ninjaCommand;
+    std::vector<std::string> command;
+    command.push_back(this->NinjaCommand);
+    command.push_back("--version");
+    std::string version;
+    cmSystemTools::RunSingleCommand(command,
+                                    &version, 0, 0, 0,
+                                    cmSystemTools::OUTPUT_NONE);
+    this->NinjaVersion = cmSystemTools::TrimWhitespace(version);
+    }
+}
+
 void cmGlobalNinjaGenerator
 ::EnableLanguage(std::vector<std::string>const& langs,
                  cmMakefile* mf,
@@ -717,13 +739,11 @@ std::string cmGlobalNinjaGenerator::GetEditCacheCommand() const
 void cmGlobalNinjaGenerator
 ::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const
 {
-  cmTarget* target = gt->Target;
-
   // Compute full path to object file directory for this target.
   std::string dir;
-  dir += gt->Makefile->GetCurrentBinaryDirectory();
+  dir += gt->LocalGenerator->GetCurrentBinaryDirectory();
   dir += "/";
-  dir += gt->LocalGenerator->GetTargetDirectory(*target);
+  dir += gt->LocalGenerator->GetTargetDirectory(gt);
   dir += "/";
   gt->ObjectDirectory = dir;
 }
@@ -888,7 +908,7 @@ void cmGlobalNinjaGenerator::WriteDisclaimer(std::ostream& os)
     << cmVersion::GetMinorVersion() << "\n\n";
 }
 
-void cmGlobalNinjaGenerator::AddDependencyToAll(cmTarget* target)
+void cmGlobalNinjaGenerator::AddDependencyToAll(cmGeneratorTarget* target)
 {
   this->AppendTargetOutputs(target, this->AllDependencies);
 }
@@ -908,16 +928,17 @@ void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies()
     WriteCustomCommandBuild(/*command=*/"", /*description=*/"",
                             "Assume dependencies for generated source file.",
                             /*uses_terminal*/false,
+                            /*restat*/true,
                             cmNinjaDeps(1, i->first), deps);
   }
 }
 
 void
 cmGlobalNinjaGenerator
-::AppendTargetOutputs(cmTarget const* target, cmNinjaDeps& outputs)
+::AppendTargetOutputs(cmGeneratorTarget const* target, cmNinjaDeps& outputs)
 {
   std::string configName =
-    target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
+    target->Target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
 
   // for frameworks, we want the real name, not smple name
   // frameworks always appear versioned, and the build.ninja
@@ -926,20 +947,19 @@ cmGlobalNinjaGenerator
   bool realname = target->IsFrameworkOnApple();
 
   switch (target->GetType()) {
-  case cmTarget::EXECUTABLE:
-  case cmTarget::SHARED_LIBRARY:
-  case cmTarget::STATIC_LIBRARY:
-  case cmTarget::MODULE_LIBRARY:
+  case cmState::EXECUTABLE:
+  case cmState::SHARED_LIBRARY:
+  case cmState::STATIC_LIBRARY:
+  case cmState::MODULE_LIBRARY:
     {
-    cmGeneratorTarget *gtgt = this->GetGeneratorTarget(target);
     outputs.push_back(this->ConvertToNinjaPath(
-      gtgt->GetFullPath(configName, false, realname)));
+      target->GetFullPath(configName, false, realname)));
     break;
     }
-  case cmTarget::OBJECT_LIBRARY:
-  case cmTarget::UTILITY: {
+  case cmState::OBJECT_LIBRARY:
+  case cmState::UTILITY: {
     std::string path = this->ConvertToNinjaPath(
-      target->GetMakefile()->GetCurrentBinaryDirectory());
+      target->GetLocalGenerator()->GetCurrentBinaryDirectory());
     if (path.empty() || path == ".")
       outputs.push_back(target->GetName());
     else {
@@ -950,7 +970,7 @@ cmGlobalNinjaGenerator
     break;
   }
 
-  case cmTarget::GLOBAL_TARGET:
+  case cmState::GLOBAL_TARGET:
     // Always use the target in HOME instead of an unused duplicate in a
     // subdirectory.
     outputs.push_back(target->GetName());
@@ -963,30 +983,29 @@ cmGlobalNinjaGenerator
 
 void
 cmGlobalNinjaGenerator
-::AppendTargetDepends(cmTarget const* target, cmNinjaDeps& outputs)
+::AppendTargetDepends(cmGeneratorTarget const* target, cmNinjaDeps& outputs)
 {
-  if (target->GetType() == cmTarget::GLOBAL_TARGET) {
+  if (target->GetType() == cmState::GLOBAL_TARGET) {
     // Global targets only depend on other utilities, which may not appear in
     // the TargetDepends set (e.g. "all").
     std::set<std::string> const& utils = target->GetUtilities();
     std::copy(utils.begin(), utils.end(), std::back_inserter(outputs));
   } else {
-    cmGeneratorTarget* gt = this->GetGeneratorTarget(target);
-    cmTargetDependSet const& targetDeps = this->GetTargetDirectDepends(gt);
+    cmTargetDependSet const& targetDeps = this->GetTargetDirectDepends(target);
     for (cmTargetDependSet::const_iterator i = targetDeps.begin();
          i != targetDeps.end(); ++i)
       {
-      if ((*i)->GetType() == cmTarget::INTERFACE_LIBRARY)
+      if ((*i)->GetType() == cmState::INTERFACE_LIBRARY)
         {
         continue;
         }
-      this->AppendTargetOutputs((*i)->Target, outputs);
+      this->AppendTargetOutputs(*i, outputs);
     }
   }
 }
 
 void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias,
-                                            cmTarget* target) {
+                                            cmGeneratorTarget* target) {
   cmNinjaDeps outputs;
   this->AppendTargetOutputs(target, outputs);
   // Mark the target's outputs as ambiguous to ensure that no other target uses
@@ -1198,16 +1217,15 @@ void cmGlobalNinjaGenerator::WriteTargetAll(std::ostream& os)
 void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
 {
   cmLocalGenerator *lg = this->LocalGenerators[0];
-  cmMakefile* mfRoot = lg->GetMakefile();
 
   std::ostringstream cmd;
   cmd << lg->ConvertToOutputFormat(cmSystemTools::GetCMakeCommand(),
                                    cmLocalGenerator::SHELL)
       << " -H"
-      << lg->ConvertToOutputFormat(mfRoot->GetHomeDirectory(),
+      << lg->ConvertToOutputFormat(lg->GetSourceDirectory(),
                                    cmLocalGenerator::SHELL)
       << " -B"
-      << lg->ConvertToOutputFormat(mfRoot->GetHomeOutputDirectory(),
+      << lg->ConvertToOutputFormat(lg->GetBinaryDirectory(),
                                    cmLocalGenerator::SHELL);
   WriteRule(*this->RulesFileStream,
             "RERUN_CMAKE",
@@ -1265,28 +1283,16 @@ std::string cmGlobalNinjaGenerator::ninjaCmd() const
 {
   cmLocalGenerator* lgen = this->LocalGenerators[0];
   if (lgen) {
-    return lgen->ConvertToOutputFormat(
-             lgen->GetMakefile()->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"),
-                                    cmLocalGenerator::SHELL);
+    return lgen->ConvertToOutputFormat(this->NinjaCommand,
+                                       cmLocalGenerator::SHELL);
   }
   return "ninja";
 }
 
-std::string cmGlobalNinjaGenerator::CurrentNinjaVersion() const
-{
-  std::string version;
-  std::string command = ninjaCmd() + " --version";
-  cmSystemTools::RunSingleCommand(command.c_str(),
-                                  &version, 0, 0, 0,
-                                  cmSystemTools::OUTPUT_NONE);
-
-  return cmSystemTools::TrimWhitespace(version);
-}
-
 bool cmGlobalNinjaGenerator::SupportsConsolePool() const
 {
   return cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
-    CurrentNinjaVersion().c_str(),
+    this->NinjaVersion.c_str(),
     RequiredNinjaVersionForConsolePool().c_str()) == false;
 }
 
diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h
index 292f7c7..8656590 100644
--- a/Source/cmGlobalNinjaGenerator.h
+++ b/Source/cmGlobalNinjaGenerator.h
@@ -74,6 +74,12 @@ public:
   static void WriteComment(std::ostream& os, const std::string& comment);
 
   /**
+   * Utilized by the generator factory to determine if this generator
+   * supports toolsets.
+   */
+  static bool SupportsToolset() { return false; }
+
+  /**
    * Write a build statement to @a os with the @a comment using
    * the @a rule the list of @a outputs files and inputs.
    * It also writes the variables bound to this build statement.
@@ -106,6 +112,7 @@ public:
                                const std::string& description,
                                const std::string& comment,
                                bool uses_terminal,
+                               bool restat,
                                const cmNinjaDeps& outputs,
                                const cmNinjaDeps& deps = cmNinjaDeps(),
                                const cmNinjaDeps& orderOnly = cmNinjaDeps());
@@ -285,9 +292,11 @@ public:
     ASD.insert(deps.begin(), deps.end());
   }
 
-  void AppendTargetOutputs(cmTarget const* target, cmNinjaDeps& outputs);
-  void AppendTargetDepends(cmTarget const* target, cmNinjaDeps& outputs);
-  void AddDependencyToAll(cmTarget* target);
+  void AppendTargetOutputs(cmGeneratorTarget const* target,
+                           cmNinjaDeps& outputs);
+  void AppendTargetDepends(cmGeneratorTarget const* target,
+                           cmNinjaDeps& outputs);
+  void AddDependencyToAll(cmGeneratorTarget* target);
   void AddDependencyToAll(const std::string& input);
 
   const std::vector<cmLocalGenerator*>& GetLocalGenerators() const {
@@ -299,11 +308,10 @@ public:
   int GetRuleCmdLength(const std::string& name) {
     return RuleCmdLength[name]; }
 
-  void AddTargetAlias(const std::string& alias, cmTarget* target);
+  void AddTargetAlias(const std::string& alias, cmGeneratorTarget* target);
 
   virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
 
-  std::string CurrentNinjaVersion() const;
   // Ninja generator uses 'deps' and 'msvc_deps_prefix' introduced in 1.3
   static std::string RequiredNinjaVersion() { return "1.3"; }
   static std::string RequiredNinjaVersionForConsolePool() { return "1.5"; }
@@ -318,7 +326,7 @@ protected:
 
 private:
   virtual std::string GetEditCacheCommand() const;
-
+  virtual void FindMakeProgram(cmMakefile* mf);
 
   void OpenBuildFileStream();
   void CloseBuildFileStream();
@@ -388,8 +396,11 @@ private:
   /// The mapping from source file to assumed dependencies.
   std::map<std::string, std::set<std::string> > AssumedSourceDependencies;
 
-  typedef std::map<std::string, cmTarget*> TargetAliasMap;
+  typedef std::map<std::string, cmGeneratorTarget*> TargetAliasMap;
   TargetAliasMap TargetAliases;
+
+  std::string NinjaCommand;
+  std::string NinjaVersion;
 };
 
 #endif // ! cmGlobalNinjaGenerator_h
diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx
index 0064713..ce7815d 100644
--- a/Source/cmGlobalUnixMakefileGenerator3.cxx
+++ b/Source/cmGlobalUnixMakefileGenerator3.cxx
@@ -15,8 +15,6 @@
 #include "cmMakefile.h"
 #include "cmake.h"
 #include "cmGeneratedFileStream.h"
-#include "cmSourceFile.h"
-#include "cmTarget.h"
 #include "cmGeneratorTarget.h"
 #include "cmAlgorithms.h"
 
@@ -114,13 +112,11 @@ void
 cmGlobalUnixMakefileGenerator3
 ::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const
 {
-  cmTarget* target = gt->Target;
-
   // Compute full path to object file directory for this target.
   std::string dir;
-  dir += gt->Makefile->GetCurrentBinaryDirectory();
+  dir += gt->LocalGenerator->GetCurrentBinaryDirectory();
   dir += "/";
-  dir += gt->LocalGenerator->GetTargetDirectory(*target);
+  dir += gt->LocalGenerator->GetTargetDirectory(gt);
   dir += "/";
   gt->ObjectDirectory = dir;
 }
@@ -161,9 +157,8 @@ void cmGlobalUnixMakefileGenerator3::Generate()
     }
   for(unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
     {
-    cmLocalUnixMakefileGenerator3 *lg =
-      static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
-    std::string markFileName = lg->GetMakefile()->GetCurrentBinaryDirectory();
+    cmLocalGenerator *lg = this->LocalGenerators[i];
+    std::string markFileName = lg->GetCurrentBinaryDirectory();
     markFileName += "/";
     markFileName += cmake::GetCMakeFilesDirectory();
     markFileName += "/progress.marks";
@@ -395,7 +390,7 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
     {
     lg =
       static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
-    tmpStr = lg->GetMakefile()->GetCurrentBinaryDirectory();
+    tmpStr = lg->GetCurrentBinaryDirectory();
     tmpStr += cmake::GetCMakeFilesDirectory();
     tmpStr += "/CMakeDirectoryInformation.cmake";
     cmakefileStream << "  \"" <<
@@ -425,17 +420,19 @@ void cmGlobalUnixMakefileGenerator3
     {
     lg = static_cast<cmLocalUnixMakefileGenerator3 *>(lGenerators[i]);
     // for all of out targets
-    for (cmTargets::iterator l = lg->GetMakefile()->GetTargets().begin();
-         l != lg->GetMakefile()->GetTargets().end(); l++)
+    std::vector<cmGeneratorTarget*> tgts = lg->GetGeneratorTargets();
+    for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
+         l != tgts.end(); l++)
       {
-      if((l->second.GetType() == cmTarget::EXECUTABLE) ||
-         (l->second.GetType() == cmTarget::STATIC_LIBRARY) ||
-         (l->second.GetType() == cmTarget::SHARED_LIBRARY) ||
-         (l->second.GetType() == cmTarget::MODULE_LIBRARY) ||
-         (l->second.GetType() == cmTarget::OBJECT_LIBRARY) ||
-         (l->second.GetType() == cmTarget::UTILITY))
+      if(((*l)->GetType() == cmState::EXECUTABLE) ||
+         ((*l)->GetType() == cmState::STATIC_LIBRARY) ||
+         ((*l)->GetType() == cmState::SHARED_LIBRARY) ||
+         ((*l)->GetType() == cmState::MODULE_LIBRARY) ||
+         ((*l)->GetType() == cmState::OBJECT_LIBRARY) ||
+         ((*l)->GetType() == cmState::UTILITY))
         {
-        std::string tname = lg->GetRelativeTargetDirectory(l->second);
+        cmGeneratorTarget* gt = *l;
+        std::string tname = lg->GetRelativeTargetDirectory(gt);
         tname += "/DependInfo.cmake";
         cmSystemTools::ConvertToUnixSlashes(tname);
         cmakefileStream << "  \"" << tname << "\"\n";
@@ -454,37 +451,33 @@ cmGlobalUnixMakefileGenerator3
                       bool check_relink)
 {
   // Get the relative path to the subdirectory from the top.
-  std::string makeTarget = lg->GetMakefile()->GetCurrentBinaryDirectory();
+  std::string makeTarget = lg->GetCurrentBinaryDirectory();
   makeTarget += "/";
   makeTarget += pass;
 
   // The directory-level rule should depend on the target-level rules
   // for all targets in the directory.
   std::vector<std::string> depends;
-  cmGeneratorTargetsType targets = lg->GetMakefile()->GetGeneratorTargets();
-  for(cmGeneratorTargetsType::iterator l = targets.begin();
+  std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets();
+  for(std::vector<cmGeneratorTarget*>::iterator l = targets.begin();
       l != targets.end(); ++l)
     {
-    cmGeneratorTarget* gtarget = l->second;
+    cmGeneratorTarget* gtarget = *l;
     int type = gtarget->GetType();
-    if((type == cmTarget::EXECUTABLE) ||
-       (type == cmTarget::STATIC_LIBRARY) ||
-       (type == cmTarget::SHARED_LIBRARY) ||
-       (type == cmTarget::MODULE_LIBRARY) ||
-       (type == cmTarget::OBJECT_LIBRARY) ||
-       (type == cmTarget::UTILITY))
+    if((type == cmState::EXECUTABLE) ||
+       (type == cmState::STATIC_LIBRARY) ||
+       (type == cmState::SHARED_LIBRARY) ||
+       (type == cmState::MODULE_LIBRARY) ||
+       (type == cmState::OBJECT_LIBRARY) ||
+       (type == cmState::UTILITY))
       {
-      if(gtarget->Target->IsImported())
-        {
-        continue;
-        }
       // Add this to the list of depends rules in this directory.
       if((!check_all || !gtarget->GetPropertyAsBool("EXCLUDE_FROM_ALL")) &&
          (!check_relink ||
           gtarget
             ->NeedRelinkBeforeInstall(lg->GetConfigName())))
         {
-        std::string tname = lg->GetRelativeTargetDirectory(*gtarget->Target);
+        std::string tname = lg->GetRelativeTargetDirectory(gtarget);
         tname += "/";
         tname += pass;
         depends.push_back(tname);
@@ -495,7 +488,7 @@ cmGlobalUnixMakefileGenerator3
   // The directory-level rule should depend on the directory-level
   // rules of the subdirectories.
   std::vector<cmState::Snapshot> children
-      = lg->GetMakefile()->GetStateSnapshot().GetChildren();
+      = lg->GetStateSnapshot().GetChildren();
   for(std::vector<cmState::Snapshot>::const_iterator
         ci = children.begin(); ci != children.end(); ++ci)
     {
@@ -528,13 +521,13 @@ cmGlobalUnixMakefileGenerator3
                        cmLocalUnixMakefileGenerator3* lg)
 {
   // Only subdirectories need these rules.
-  if(lg->GetMakefile()->IsRootMakefile())
+  if(lg->IsRootMakefile())
     {
     return;
     }
 
   // Begin the directory-level rules section.
-  std::string dir = lg->GetMakefile()->GetCurrentBinaryDirectory();
+  std::string dir = lg->GetCurrentBinaryDirectory();
   dir = lg->Convert(dir, cmLocalGenerator::HOME_OUTPUT,
                     cmLocalGenerator::MAKERULE);
   lg->WriteDivider(ruleFileStream);
@@ -585,12 +578,12 @@ void cmGlobalUnixMakefileGenerator3
     else
       {
       cmState::Snapshot snapshot = this->CMakeInstance->GetCurrentSnapshot();
-      mf = new cmMakefile(this, snapshot);
-      // set the Start directories
-      mf->SetCurrentSourceDirectory
+      snapshot.GetDirectory().SetCurrentSource
         (this->CMakeInstance->GetHomeDirectory());
-      mf->SetCurrentBinaryDirectory
+      snapshot.GetDirectory().SetCurrentBinary
         (this->CMakeInstance->GetHomeOutputDirectory());
+      snapshot.SetDefaultDefinitions();
+      mf = new cmMakefile(this, snapshot);
       }
 
     std::string tname = targetName;
@@ -628,15 +621,11 @@ cmGlobalUnixMakefileGenerator3
     lg = static_cast<cmLocalUnixMakefileGenerator3 *>
       (this->LocalGenerators[i]);
     // for each target Generate the rule files for each target.
-    cmGeneratorTargetsType targets = lg->GetMakefile()->GetGeneratorTargets();
-    for(cmGeneratorTargetsType::iterator t = targets.begin();
+    std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets();
+    for(std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
         t != targets.end(); ++t)
       {
-      cmGeneratorTarget* gtarget = t->second;
-      if(gtarget->Target->IsImported())
-        {
-        continue;
-        }
+      cmGeneratorTarget* gtarget = *t;
       // Don't emit the same rule twice (e.g. two targets with the same
       // simple name)
       int type = gtarget->GetType();
@@ -645,12 +634,12 @@ cmGlobalUnixMakefileGenerator3
          emitted.insert(name).second &&
          // Handle user targets here.  Global targets are handled in
          // the local generator on a per-directory basis.
-         ((type == cmTarget::EXECUTABLE) ||
-          (type == cmTarget::STATIC_LIBRARY) ||
-          (type == cmTarget::SHARED_LIBRARY) ||
-          (type == cmTarget::MODULE_LIBRARY) ||
-          (type == cmTarget::OBJECT_LIBRARY) ||
-          (type == cmTarget::UTILITY)))
+         ((type == cmState::EXECUTABLE) ||
+          (type == cmState::STATIC_LIBRARY) ||
+          (type == cmState::SHARED_LIBRARY) ||
+          (type == cmState::MODULE_LIBRARY) ||
+          (type == cmState::OBJECT_LIBRARY) ||
+          (type == cmState::UTILITY)))
         {
         // Add a rule to build the target by name.
         lg->WriteDivider(ruleFileStream);
@@ -673,7 +662,7 @@ cmGlobalUnixMakefileGenerator3
 
         // Add a fast rule to build the target
         std::string localName =
-                          lg->GetRelativeTargetDirectory(*gtarget->Target);
+                          lg->GetRelativeTargetDirectory(gtarget);
         std::string makefileName;
         makefileName = localName;
         makefileName += "/build.make";
@@ -693,7 +682,7 @@ cmGlobalUnixMakefileGenerator3
         if(gtarget
              ->NeedRelinkBeforeInstall(lg->GetConfigName()))
           {
-          makeTargetName = lg->GetRelativeTargetDirectory(*gtarget->Target);
+          makeTargetName = lg->GetRelativeTargetDirectory(gtarget);
           makeTargetName += "/preinstall";
           localName = name;
           localName += "/preinstall";
@@ -729,32 +718,28 @@ cmGlobalUnixMakefileGenerator3
   depends.push_back("cmake_check_build_system");
 
   // for each target Generate the rule files for each target.
-  cmGeneratorTargetsType targets = lg->GetMakefile()->GetGeneratorTargets();
-  for(cmGeneratorTargetsType::iterator t = targets.begin();
+  std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets();
+  for(std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
       t != targets.end(); ++t)
     {
-    cmGeneratorTarget* gtarget = t->second;
-    if(gtarget->Target->IsImported())
-      {
-      continue;
-      }
+    cmGeneratorTarget* gtarget = *t;
     int type = gtarget->GetType();
     std::string name = gtarget->GetName();
     if (!name.empty()
-     && (  (type == cmTarget::EXECUTABLE)
-        || (type == cmTarget::STATIC_LIBRARY)
-        || (type == cmTarget::SHARED_LIBRARY)
-        || (type == cmTarget::MODULE_LIBRARY)
-        || (type == cmTarget::OBJECT_LIBRARY)
-        || (type == cmTarget::UTILITY)))
+     && (  (type == cmState::EXECUTABLE)
+        || (type == cmState::STATIC_LIBRARY)
+        || (type == cmState::SHARED_LIBRARY)
+        || (type == cmState::MODULE_LIBRARY)
+        || (type == cmState::OBJECT_LIBRARY)
+        || (type == cmState::UTILITY)))
       {
       std::string makefileName;
       // Add a rule to build the target by name.
-      localName = lg->GetRelativeTargetDirectory(*gtarget->Target);
+      localName = lg->GetRelativeTargetDirectory(gtarget);
       makefileName = localName;
       makefileName += "/build.make";
 
-      bool needRequiresStep = this->NeedRequiresStep(*gtarget->Target);
+      bool needRequiresStep = this->NeedRequiresStep(gtarget);
 
       lg->WriteDivider(ruleFileStream);
       ruleFileStream
@@ -785,13 +770,13 @@ cmGlobalUnixMakefileGenerator3
       depends.clear();
 
       cmLocalUnixMakefileGenerator3::EchoProgress progress;
-      progress.Dir = lg->GetMakefile()->GetHomeOutputDirectory();
+      progress.Dir = lg->GetBinaryDirectory();
       progress.Dir += cmake::GetCMakeFilesDirectory();
       {
       std::ostringstream progressArg;
       const char* sep = "";
       std::vector<unsigned long>& progFiles =
-        this->ProgressMap[gtarget->Target].Marks;
+        this->ProgressMap[gtarget].Marks;
       for (std::vector<unsigned long>::iterator i = progFiles.begin();
            i != progFiles.end(); ++i)
         {
@@ -861,7 +846,7 @@ cmGlobalUnixMakefileGenerator3
       }
       depends.clear();
       depends.push_back("cmake_check_build_system");
-      localName = lg->GetRelativeTargetDirectory(*gtarget->Target);
+      localName = lg->GetRelativeTargetDirectory(gtarget);
       localName += "/rule";
       lg->WriteMakeRule(ruleFileStream,
                         "Build rule for subdir invocation for target.",
@@ -878,7 +863,7 @@ cmGlobalUnixMakefileGenerator3
       if(gtarget
            ->NeedRelinkBeforeInstall(lg->GetConfigName()))
         {
-        localName = lg->GetRelativeTargetDirectory(*gtarget->Target);
+        localName = lg->GetRelativeTargetDirectory(gtarget);
         localName += "/preinstall";
         depends.clear();
         commands.clear();
@@ -899,7 +884,7 @@ cmGlobalUnixMakefileGenerator3
         }
 
       // add the clean rule
-      localName = lg->GetRelativeTargetDirectory(*gtarget->Target);
+      localName = lg->GetRelativeTargetDirectory(gtarget);
       makeTargetName = localName;
       makeTargetName += "/clean";
       depends.clear();
@@ -927,18 +912,16 @@ void cmGlobalUnixMakefileGenerator3::InitializeProgressMarks()
       lgi != this->LocalGenerators.end(); ++lgi)
     {
     cmLocalGenerator* lg = *lgi;
-    cmMakefile* mf = lg->GetMakefile();
-    cmTargets const& targets = mf->GetTargets();
-    for(cmTargets::const_iterator t = targets.begin(); t != targets.end(); ++t)
+    std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets();
+    for(std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin();
+        t != targets.end(); ++t)
       {
-      cmTarget const& target = t->second;
-
-      cmGeneratorTarget* gt = this->GetGeneratorTarget(&target);
+      cmGeneratorTarget* gt = *t;
 
       cmLocalGenerator* tlg = gt->GetLocalGenerator();
 
-      if(gt->GetType() == cmTarget::INTERFACE_LIBRARY
-          || gt->Target->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
+      if(gt->GetType() == cmState::INTERFACE_LIBRARY
+          || gt->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
         {
         continue;
         }
@@ -979,12 +962,12 @@ cmGlobalUnixMakefileGenerator3
   size_t count = 0;
   if(emitted.insert(target).second)
     {
-    count = this->ProgressMap[target->Target].Marks.size();
+    count = this->ProgressMap[target].Marks.size();
     TargetDependSet const& depends = this->GetTargetDirectDepends(target);
     for(TargetDependSet::const_iterator di = depends.begin();
         di != depends.end(); ++di)
       {
-      if ((*di)->GetType() == cmTarget::INTERFACE_LIBRARY)
+      if ((*di)->GetType() == cmState::INTERFACE_LIBRARY)
         {
         continue;
         }
@@ -997,7 +980,7 @@ cmGlobalUnixMakefileGenerator3
 //----------------------------------------------------------------------------
 size_t
 cmGlobalUnixMakefileGenerator3
-::CountProgressMarksInAll(cmLocalUnixMakefileGenerator3* lg)
+::CountProgressMarksInAll(cmLocalGenerator* lg)
 {
   size_t count = 0;
   std::set<cmGeneratorTarget const*> emitted;
@@ -1016,7 +999,7 @@ void
 cmGlobalUnixMakefileGenerator3::RecordTargetProgress(
   cmMakefileTargetGenerator* tg)
 {
-  TargetProgress& tp = this->ProgressMap[tg->GetTarget()];
+  TargetProgress& tp = this->ProgressMap[tg->GetGeneratorTarget()];
   tp.NumberOfActions = tg->GetNumberOfProgressActions();
   tp.VariableFile = tg->GetProgressFileNameFull();
 }
@@ -1060,13 +1043,14 @@ cmGlobalUnixMakefileGenerator3
     {
     // Create the target-level dependency.
     cmGeneratorTarget const* dep = *i;
-    if (dep->GetType() == cmTarget::INTERFACE_LIBRARY)
+    if (dep->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
     cmLocalUnixMakefileGenerator3* lg3 =
       static_cast<cmLocalUnixMakefileGenerator3*>(dep->GetLocalGenerator());
-    std::string tgtName = lg3->GetRelativeTargetDirectory(*(*dep).Target);
+    std::string tgtName =
+        lg3->GetRelativeTargetDirectory(const_cast<cmGeneratorTarget*>(dep));
     tgtName += "/all";
     depends.push_back(tgtName);
     }
@@ -1098,23 +1082,24 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule
       static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
     // for the passed in makefile or if this is the top Makefile wripte out
     // the targets
-    if (lg2 == lg || lg->GetMakefile()->IsRootMakefile())
+    if (lg2 == lg || lg->IsRootMakefile())
       {
       // for each target Generate the rule files for each target.
-      cmTargets& targets = lg2->GetMakefile()->GetTargets();
-      for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
+      std::vector<cmGeneratorTarget*> targets = lg2->GetGeneratorTargets();
+      for(std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
+          t != targets.end(); ++t)
         {
-        cmTarget const& target = t->second;
-        cmTarget::TargetType type = target.GetType();
-        if((type == cmTarget::EXECUTABLE) ||
-           (type == cmTarget::STATIC_LIBRARY) ||
-           (type == cmTarget::SHARED_LIBRARY) ||
-           (type == cmTarget::MODULE_LIBRARY) ||
-           (type == cmTarget::OBJECT_LIBRARY) ||
-           (type == cmTarget::GLOBAL_TARGET) ||
-           (type == cmTarget::UTILITY))
+        cmGeneratorTarget* target = *t;
+        cmState::TargetType type = target->GetType();
+        if((type == cmState::EXECUTABLE) ||
+           (type == cmState::STATIC_LIBRARY) ||
+           (type == cmState::SHARED_LIBRARY) ||
+           (type == cmState::MODULE_LIBRARY) ||
+           (type == cmState::OBJECT_LIBRARY) ||
+           (type == cmState::GLOBAL_TARGET) ||
+           (type == cmState::UTILITY))
           {
-          std::string name = target.GetName();
+          std::string name = target->GetName();
           if(emittedTargets.insert(name).second)
             {
             path = "... ";
@@ -1141,19 +1126,19 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule
 
 
 bool cmGlobalUnixMakefileGenerator3
-::NeedRequiresStep(cmTarget const& target)
+::NeedRequiresStep(const cmGeneratorTarget* target)
 {
   std::set<std::string> languages;
-  cmGeneratorTarget* gtgt = this->GetGeneratorTarget(&target);
-  gtgt->GetLanguages(languages,
-                target.GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+  target->GetLanguages(languages,
+                       target->Target->GetMakefile()
+                       ->GetSafeDefinition("CMAKE_BUILD_TYPE"));
   for(std::set<std::string>::const_iterator l = languages.begin();
       l != languages.end(); ++l)
     {
     std::string var = "CMAKE_NEEDS_REQUIRES_STEP_";
     var += *l;
     var += "_FLAG";
-    if(target.GetMakefile()->GetDefinition(var))
+    if(target->Target->GetMakefile()->GetDefinition(var))
       {
       return true;
       }
diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h
index 5f39c79..0591a5a 100644
--- a/Source/cmGlobalUnixMakefileGenerator3.h
+++ b/Source/cmGlobalUnixMakefileGenerator3.h
@@ -64,6 +64,12 @@ public:
     return cmGlobalUnixMakefileGenerator3::GetActualName();}
   static std::string GetActualName() {return "Unix Makefiles";}
 
+  /**
+   * Utilized by the generator factory to determine if this generator
+   * supports toolsets.
+   */
+  static bool SupportsToolset() { return false; }
+
   /** Get the documentation entry for this generator.  */
   static void GetDocumentation(cmDocumentationEntry& entry);
 
@@ -154,7 +160,7 @@ protected:
                                  cmGeneratorTarget* target);
 
   // does this generator need a requires step for any of its targets
-  bool NeedRequiresStep(cmTarget const&);
+  bool NeedRequiresStep(cmGeneratorTarget const*);
 
   // Target name hooks for superclass.
   const char* GetAllTargetName()           const { return "all"; }
@@ -192,13 +198,13 @@ protected:
     std::vector<unsigned long> Marks;
     void WriteProgressVariables(unsigned long total, unsigned long& current);
   };
-  typedef std::map<cmTarget const*, TargetProgress,
-                   cmStrictTargetComparison> ProgressMapType;
+  typedef std::map<cmGeneratorTarget const*, TargetProgress,
+                   cmGeneratorTarget::StrictTargetComparison> ProgressMapType;
   ProgressMapType ProgressMap;
 
   size_t CountProgressMarksInTarget(cmGeneratorTarget const* target,
                                  std::set<cmGeneratorTarget const*>& emitted);
-  size_t CountProgressMarksInAll(cmLocalUnixMakefileGenerator3* lg);
+  size_t CountProgressMarksInAll(cmLocalGenerator* lg);
 
   cmGeneratedFileStream *CommandDatabase;
 private:
diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx
index 59e8f8c..c49008d 100644
--- a/Source/cmGlobalVisualStudio10Generator.cxx
+++ b/Source/cmGlobalVisualStudio10Generator.cxx
@@ -81,6 +81,8 @@ public:
     names.push_back(vs10generatorName + std::string(" IA64"));
     names.push_back(vs10generatorName + std::string(" Win64"));
     }
+
+  virtual bool SupportsToolset() const { return true; }
 };
 
 //----------------------------------------------------------------------------
@@ -325,23 +327,13 @@ cmLocalGenerator* cmGlobalVisualStudio10Generator::CreateLocalGenerator(
   return new cmLocalVisualStudio10Generator(this, mf);
 }
 
-//----------------------------------------------------------------------------
-bool cmGlobalVisualStudio10Generator::Compute()
-{
-  if (!cmGlobalVisualStudio8Generator::Compute())
-    {
-    return false;
-    }
-  this->LongestSource = LongestSourcePath();
-  return true;
-}
-
 void cmGlobalVisualStudio10Generator::Generate()
 {
+  this->LongestSource = LongestSourcePath();
   this->cmGlobalVisualStudio8Generator::Generate();
   if(this->LongestSource.Length > 0)
     {
-    cmMakefile* mf = this->LongestSource.Target->GetMakefile();
+    cmLocalGenerator* lg = this->LongestSource.Target->GetLocalGenerator();
     std::ostringstream e;
     e <<
       "The binary and/or source directory paths may be too long to generate "
@@ -356,13 +348,13 @@ void cmGlobalVisualStudio10Generator::Generate()
       "  " << this->LongestSource.SourceFile->GetFullPath() << "\n"
       "This is because some Visual Studio tools would append the relative "
       "path to the end of the referencing directory path, as in:\n"
-      "  " << mf->GetCurrentBinaryDirectory() << "/"
+      "  " << lg->GetCurrentBinaryDirectory() << "/"
       << this->LongestSource.SourceRel << "\n"
       "and then incorrectly complain that the file does not exist because "
       "the path length is too long for some internal buffer or API.  "
       "To avoid this problem CMake must use a full path for this file "
       "which then triggers the VS 10 property dialog bug.";
-    mf->IssueMessage(cmake::WARNING, e.str().c_str());
+    lg->IssueMessage(cmake::WARNING, e.str().c_str());
     }
 }
 
@@ -601,9 +593,11 @@ cmGlobalVisualStudio10Generator
 
 //----------------------------------------------------------------------------
 void cmGlobalVisualStudio10Generator::PathTooLong(
-  cmTarget* target, cmSourceFile const* sf, std::string const& sfRel)
+        cmGeneratorTarget *target, cmSourceFile const* sf,
+        std::string const& sfRel)
 {
-  size_t len = (strlen(target->GetMakefile()->GetCurrentBinaryDirectory()) +
+  size_t len =
+      (strlen(target->GetLocalGenerator()->GetCurrentBinaryDirectory()) +
                 1 + sfRel.length());
   if(len > this->LongestSource.Length)
     {
diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h
index f4861dc..6bf4740 100644
--- a/Source/cmGlobalVisualStudio10Generator.h
+++ b/Source/cmGlobalVisualStudio10Generator.h
@@ -45,8 +45,6 @@ public:
     std::vector<std::string> const& makeOptions = std::vector<std::string>()
     );
 
-  virtual bool Compute();
-
   ///! create the correct local generator
   virtual cmLocalGenerator *CreateLocalGenerator(cmMakefile* mf);
 
@@ -97,7 +95,7 @@ public:
   /** Generate an <output>.rule file path for a given command output.  */
   virtual std::string GenerateRuleFile(std::string const& output) const;
 
-  void PathTooLong(cmTarget* target, cmSourceFile const* sf,
+  void PathTooLong(cmGeneratorTarget* target, cmSourceFile const* sf,
                    std::string const& sfRel);
 
   virtual const char* GetToolsVersion() { return "4.0"; }
@@ -141,7 +139,7 @@ private:
   {
     LongestSourcePath(): Length(0), Target(0), SourceFile(0) {}
     size_t Length;
-    cmTarget* Target;
+    cmGeneratorTarget* Target;
     cmSourceFile const* SourceFile;
     std::string SourceRel;
   };
diff --git a/Source/cmGlobalVisualStudio11Generator.cxx b/Source/cmGlobalVisualStudio11Generator.cxx
index 419bf8a..9522f6e 100644
--- a/Source/cmGlobalVisualStudio11Generator.cxx
+++ b/Source/cmGlobalVisualStudio11Generator.cxx
@@ -96,6 +96,8 @@ public:
       names.push_back(std::string(vs11generatorName) + " " + *i);
       }
     }
+
+  virtual bool SupportsToolset() const { return true; }
 };
 
 //----------------------------------------------------------------------------
@@ -278,10 +280,10 @@ cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs()
 
 //----------------------------------------------------------------------------
 bool
-cmGlobalVisualStudio11Generator::NeedsDeploy(cmTarget::TargetType type) const
+cmGlobalVisualStudio11Generator::NeedsDeploy(cmState::TargetType type) const
 {
-  if((type == cmTarget::EXECUTABLE ||
-      type == cmTarget::SHARED_LIBRARY) &&
+  if((type == cmState::EXECUTABLE ||
+      type == cmState::SHARED_LIBRARY) &&
      (this->SystemIsWindowsPhone ||
       this->SystemIsWindowsStore))
     {
diff --git a/Source/cmGlobalVisualStudio11Generator.h b/Source/cmGlobalVisualStudio11Generator.h
index 9499d80..f3f6b2b 100644
--- a/Source/cmGlobalVisualStudio11Generator.h
+++ b/Source/cmGlobalVisualStudio11Generator.h
@@ -48,7 +48,7 @@ protected:
   static std::set<std::string> GetInstalledWindowsCESDKs();
 
   /** Return true if the configuration needs to be deployed */
-  virtual bool NeedsDeploy(cmTarget::TargetType type) const;
+  virtual bool NeedsDeploy(cmState::TargetType type) const;
 private:
   class Factory;
   friend class Factory;
diff --git a/Source/cmGlobalVisualStudio12Generator.cxx b/Source/cmGlobalVisualStudio12Generator.cxx
index efa1133..568d4d7 100644
--- a/Source/cmGlobalVisualStudio12Generator.cxx
+++ b/Source/cmGlobalVisualStudio12Generator.cxx
@@ -76,6 +76,8 @@ public:
     names.push_back(vs12generatorName + std::string(" ARM"));
     names.push_back(vs12generatorName + std::string(" Win64"));
     }
+
+  virtual bool SupportsToolset() const { return true; }
 };
 
 //----------------------------------------------------------------------------
diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx
index 41825fb..c058f8c 100644
--- a/Source/cmGlobalVisualStudio14Generator.cxx
+++ b/Source/cmGlobalVisualStudio14Generator.cxx
@@ -76,6 +76,8 @@ public:
     names.push_back(vs14generatorName + std::string(" ARM"));
     names.push_back(vs14generatorName + std::string(" Win64"));
     }
+
+  virtual bool SupportsToolset() const { return true; }
 };
 
 //----------------------------------------------------------------------------
@@ -115,7 +117,7 @@ bool cmGlobalVisualStudio14Generator::InitializeWindows(cmMakefile* mf)
 {
   if (cmHasLiteralPrefix(this->SystemVersion, "10.0"))
     {
-    return this->SelectWindows10SDK(mf);
+    return this->SelectWindows10SDK(mf, false);
     }
   return true;
 }
@@ -143,17 +145,18 @@ bool cmGlobalVisualStudio14Generator::InitializeWindowsStore(cmMakefile* mf)
     }
   if (cmHasLiteralPrefix(this->SystemVersion, "10.0"))
     {
-    return this->SelectWindows10SDK(mf);
+    return this->SelectWindows10SDK(mf, true);
     }
   return true;
 }
 
 //----------------------------------------------------------------------------
-bool cmGlobalVisualStudio14Generator::SelectWindows10SDK(cmMakefile* mf)
+bool cmGlobalVisualStudio14Generator::SelectWindows10SDK(cmMakefile* mf,
+                                                         bool required)
 {
   // Find the default version of the Windows 10 SDK.
   this->WindowsTargetPlatformVersion = this->GetWindows10SDKVersion();
-  if (this->WindowsTargetPlatformVersion.empty())
+  if (required && this->WindowsTargetPlatformVersion.empty())
     {
     std::ostringstream  e;
     e << "Could not find an appropriate version of the Windows 10 SDK"
@@ -229,6 +232,16 @@ cmGlobalVisualStudio14Generator::IsWindowsStoreToolsetInstalled() const
     win10SDK, cmSystemTools::KeyWOW64_32);
 }
 
+#if defined(_WIN32) && !defined(__CYGWIN__)
+struct NoWindowsH
+{
+  bool operator()(std::string const& p)
+    {
+    return !cmSystemTools::FileExists(p + "/um/windows.h", true);
+    }
+};
+#endif
+
 //----------------------------------------------------------------------------
 std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion()
 {
@@ -252,6 +265,12 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion()
   std::string path = win10Root + "Include/*";
   // Grab the paths of the different SDKs that are installed
   cmSystemTools::GlobDirs(path, sdks);
+
+  // Skip SDKs that do not contain <um/windows.h> because that indicates that
+  // only the UCRT MSIs were installed for them.
+  sdks.erase(std::remove_if(sdks.begin(), sdks.end(), NoWindowsH()),
+             sdks.end());
+
   if (!sdks.empty())
     {
     // Only use the filename, which will be the SDK version.
@@ -261,29 +280,21 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion()
       *i = cmSystemTools::GetFilenameName(*i);
       }
 
-    // Sort the results to make sure we select the most recent one that
-    // has a version less or equal to our version of the operating system
+    // Sort the results to make sure we select the most recent one.
     std::sort(sdks.begin(), sdks.end(), cmSystemTools::VersionCompareGreater);
 
-    // Select a suitable SDK version.
-    if (this->SystemVersion == "10.0")
-      {
-      // Use the latest Windows 10 SDK since no build version was given.
-      return sdks.at(0);
-      }
-    else
+    // Look for a SDK exactly matching the requested target version.
+    for (std::vector<std::string>::iterator i = sdks.begin();
+         i != sdks.end(); ++i)
       {
-      // Find the SDK less or equal to our specified version
-      for (std::vector<std::string>::iterator i = sdks.begin();
-           i != sdks.end(); ++i)
+      if (cmSystemTools::VersionCompareEqual(*i, this->SystemVersion))
         {
-        if (!cmSystemTools::VersionCompareGreater(*i, this->SystemVersion))
-          {
-          // This is the most recent SDK that we can run safely
-          return *i;
-          }
+        return *i;
         }
       }
+
+    // Use the latest Windows 10 SDK since the exact version is not available.
+    return sdks.at(0);
     }
 #endif
   // Return an empty string
diff --git a/Source/cmGlobalVisualStudio14Generator.h b/Source/cmGlobalVisualStudio14Generator.h
index 76c15d9..57e6284 100644
--- a/Source/cmGlobalVisualStudio14Generator.h
+++ b/Source/cmGlobalVisualStudio14Generator.h
@@ -39,7 +39,7 @@ protected:
   bool IsWindowsStoreToolsetInstalled() const;
 
   virtual const char* GetIDEVersion() { return "14.0"; }
-  virtual bool SelectWindows10SDK(cmMakefile* mf);
+  virtual bool SelectWindows10SDK(cmMakefile* mf, bool required);
 
   // Used to verify that the Desktop toolset for the current generator is
   // installed on the machine.
diff --git a/Source/cmGlobalVisualStudio6Generator.cxx b/Source/cmGlobalVisualStudio6Generator.cxx
index 14de698..5866c0e 100644
--- a/Source/cmGlobalVisualStudio6Generator.cxx
+++ b/Source/cmGlobalVisualStudio6Generator.cxx
@@ -223,8 +223,8 @@ void cmGlobalVisualStudio6Generator
         tt = orderedProjectTargets.begin();
       tt != orderedProjectTargets.end(); ++tt)
     {
-    cmTarget const* target = (*tt)->Target;
-    if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
+    cmGeneratorTarget const* target = *tt;
+    if(target->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
@@ -235,14 +235,15 @@ void cmGlobalVisualStudio6Generator
       std::string project = target->GetName();
       std::string location = expath;
       this->WriteExternalProject(fout, project.c_str(),
-                                 location.c_str(), target->GetUtilities());
+          location.c_str(), target->GetUtilities());
       }
     else
       {
       std::string dspname = GetVS6TargetName(target->GetName());
-      std::string dir = target->GetMakefile()->GetCurrentBinaryDirectory();
+      std::string dir =
+          target->GetLocalGenerator()->GetCurrentBinaryDirectory();
       dir = root->Convert(dir.c_str(), cmLocalGenerator::START_OUTPUT);
-      this->WriteProject(fout, dspname.c_str(), dir.c_str(), *target);
+      this->WriteProject(fout, dspname.c_str(), dir.c_str(), target);
       }
     }
 
@@ -260,7 +261,7 @@ void cmGlobalVisualStudio6Generator
     }
   std::string fname = root->GetMakefile()->GetCurrentBinaryDirectory();
   fname += "/";
-  fname += root->GetMakefile()->GetProjectName();
+  fname += root->GetProjectName();
   fname += ".dsw";
   cmsys::ofstream fout(fname.c_str());
   if(!fout)
@@ -287,9 +288,9 @@ void cmGlobalVisualStudio6Generator::OutputDSWFile()
 // Note, that dependencies from executables to
 // the libraries it uses are also done here
 void cmGlobalVisualStudio6Generator::WriteProject(std::ostream& fout,
-                                                  const std::string& dspname,
-                                                  const char* dir,
-                                                  cmTarget const& target)
+                                            const std::string& dspname,
+                                            const char* dir,
+                                            const cmGeneratorTarget *target)
 {
   fout << "#########################################################"
     "######################\n\n";
@@ -298,7 +299,7 @@ void cmGlobalVisualStudio6Generator::WriteProject(std::ostream& fout,
   fout << "Package=<5>\n{{{\n}}}\n\n";
   fout << "Package=<4>\n";
   fout << "{{{\n";
-  VSDependSet const& depends = this->VSTargetDepends[&target];
+  VSDependSet const& depends = this->VSTargetDepends[target];
   for(VSDependSet::const_iterator di = depends.begin();
       di != depends.end(); ++di)
     {
@@ -309,7 +310,7 @@ void cmGlobalVisualStudio6Generator::WriteProject(std::ostream& fout,
     }
   fout << "}}}\n\n";
 
-  UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
+  UtilityDependsMap::iterator ui = this->UtilityDepends.find(target);
   if(ui != this->UtilityDepends.end())
     {
     const char* uname = ui->second.c_str();
@@ -382,12 +383,14 @@ void cmGlobalVisualStudio6Generator::WriteDSWHeader(std::ostream& fout)
 
 //----------------------------------------------------------------------------
 std::string
-cmGlobalVisualStudio6Generator::WriteUtilityDepend(cmTarget const* target)
+cmGlobalVisualStudio6Generator::WriteUtilityDepend(
+        const cmGeneratorTarget *target)
 {
   std::string pname = target->GetName();
   pname += "_UTILITY";
   pname = GetVS6TargetName(pname.c_str());
-  std::string fname = target->GetMakefile()->GetCurrentBinaryDirectory();
+  std::string fname =
+          target->GetLocalGenerator()->GetCurrentBinaryDirectory();
   fname += "/";
   fname += pname;
   fname += ".dsp";
diff --git a/Source/cmGlobalVisualStudio6Generator.h b/Source/cmGlobalVisualStudio6Generator.h
index e9b24ea..ae2988e 100644
--- a/Source/cmGlobalVisualStudio6Generator.h
+++ b/Source/cmGlobalVisualStudio6Generator.h
@@ -15,8 +15,6 @@
 #include "cmGlobalVisualStudioGenerator.h"
 #include "cmGlobalGeneratorFactory.h"
 
-class cmTarget;
-
 /** \class cmGlobalVisualStudio6Generator
  * \brief Write a Unix makefiles.
  *
@@ -38,6 +36,12 @@ public:
   /** Get the documentation entry for this generator.  */
   static void GetDocumentation(cmDocumentationEntry& entry);
 
+  /**
+   * Utilized by the generator factory to determine if this generator
+   * supports toolsets.
+   */
+  static bool SupportsToolset() { return false; }
+
   ///! Create a local generator appropriate to this Global Generator
   virtual cmLocalGenerator *CreateLocalGenerator(cmMakefile* mf);
 
@@ -94,12 +98,12 @@ private:
   void WriteDSWHeader(std::ostream& fout);
   void WriteProject(std::ostream& fout,
                     const std::string& name, const char* path,
-                    cmTarget const& t);
+                    cmGeneratorTarget const* t);
   void WriteExternalProject(std::ostream& fout,
                             const std::string& name, const char* path,
                             const std::set<std::string>& dependencies);
   void WriteDSWFooter(std::ostream& fout);
-  virtual std::string WriteUtilityDepend(cmTarget const* target);
+  virtual std::string WriteUtilityDepend(const cmGeneratorTarget *target);
   std::string MSDevCommand;
   bool MSDevCommandInitialized;
   std::string const& GetMSDevCommand();
diff --git a/Source/cmGlobalVisualStudio71Generator.cxx b/Source/cmGlobalVisualStudio71Generator.cxx
index b913afc..8227b82 100644
--- a/Source/cmGlobalVisualStudio71Generator.cxx
+++ b/Source/cmGlobalVisualStudio71Generator.cxx
@@ -152,7 +152,7 @@ void
 cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
                                               const std::string& dspname,
                                               const char* dir,
-                                              cmTarget const& t)
+                                              cmGeneratorTarget const* t)
 {
   // check to see if this is a fortran build
   const char* ext = ".vcproj";
@@ -163,7 +163,7 @@ cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
     ext = ".vfproj";
     project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
     }
-  const char* targetExt = t.GetProperty("GENERATOR_FILE_NAME_EXT");
+  const char* targetExt = t->GetProperty("GENERATOR_FILE_NAME_EXT");
   if(targetExt)
     {
     ext = targetExt;
@@ -180,7 +180,7 @@ cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
 
   fout <<"EndProject\n";
 
-  UtilityDependsMap::iterator ui = this->UtilityDepends.find(&t);
+  UtilityDependsMap::iterator ui = this->UtilityDepends.find(t);
   if(ui != this->UtilityDepends.end())
     {
     const char* uname = ui->second.c_str();
@@ -204,9 +204,9 @@ void
 cmGlobalVisualStudio71Generator
 ::WriteProjectDepends(std::ostream& fout,
                       const std::string&,
-                      const char*, cmTarget const& target)
+                      const char*, cmGeneratorTarget const* target)
 {
-  VSDependSet const& depends = this->VSTargetDepends[&target];
+  VSDependSet const& depends = this->VSTargetDepends[target];
   for(VSDependSet::const_iterator di = depends.begin();
       di != depends.end(); ++di)
     {
@@ -215,7 +215,7 @@ cmGlobalVisualStudio71Generator
     if(guid.empty())
       {
       std::string m = "Target: ";
-      m += target.GetName();
+      m += target->GetName();
       m += " depends on unknown target: ";
       m += name;
       cmSystemTools::Error(m.c_str());
@@ -272,7 +272,7 @@ void cmGlobalVisualStudio71Generator
 // executables to the libraries it uses are also done here
 void cmGlobalVisualStudio71Generator
 ::WriteProjectConfigurations(
-  std::ostream& fout, const std::string& name, cmTarget::TargetType,
+  std::ostream& fout, const std::string& name, cmState::TargetType,
   std::vector<std::string> const& configs,
   const std::set<std::string>& configsPartOfDefaultBuild,
   std::string const& platformMapping)
diff --git a/Source/cmGlobalVisualStudio71Generator.h b/Source/cmGlobalVisualStudio71Generator.h
index fbb9ecc..5035fda 100644
--- a/Source/cmGlobalVisualStudio71Generator.h
+++ b/Source/cmGlobalVisualStudio71Generator.h
@@ -59,12 +59,12 @@ protected:
     std::ostream& fout, std::vector<std::string> const& configs);
   virtual void WriteProject(std::ostream& fout,
                             const std::string& name, const char* path,
-                            cmTarget const& t);
+                            const cmGeneratorTarget *t);
   virtual void WriteProjectDepends(std::ostream& fout,
                            const std::string& name, const char* path,
-                           cmTarget const& t);
+                           cmGeneratorTarget const* t);
   virtual void WriteProjectConfigurations(
-    std::ostream& fout, const std::string& name, cmTarget::TargetType type,
+    std::ostream& fout, const std::string& name, cmState::TargetType type,
     std::vector<std::string> const& configs,
     const std::set<std::string>& configsPartOfDefaultBuild,
     const std::string& platformMapping = "");
diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx
index 05da022..f5848ab 100644
--- a/Source/cmGlobalVisualStudio7Generator.cxx
+++ b/Source/cmGlobalVisualStudio7Generator.cxx
@@ -362,10 +362,10 @@ void cmGlobalVisualStudio7Generator
     {
     return;
     }
-  this->CurrentProject = root->GetMakefile()->GetProjectName();
-  std::string fname = root->GetMakefile()->GetCurrentBinaryDirectory();
+  this->CurrentProject = root->GetProjectName();
+  std::string fname = root->GetCurrentBinaryDirectory();
   fname += "/";
-  fname += root->GetMakefile()->GetProjectName();
+  fname += root->GetProjectName();
   fname += ".sln";
   cmGeneratedFileStream fout(fname.c_str());
   fout.SetCopyIfDifferent(true);
@@ -401,8 +401,8 @@ void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
   for(OrderedTargetDependSet::const_iterator tt =
         projectTargets.begin(); tt != projectTargets.end(); ++tt)
     {
-    cmTarget const* target = (*tt)->Target;
-    if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
+    cmGeneratorTarget const* target = *tt;
+    if(target->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
@@ -441,8 +441,8 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
   for(OrderedTargetDependSet::const_iterator tt =
         projectTargets.begin(); tt != projectTargets.end(); ++tt)
     {
-    cmTarget const* target = (*tt)->Target;
-    if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
+    cmGeneratorTarget const* target = *tt;
+    if(target->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
@@ -468,8 +468,8 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
         target->GetProperty("GENERATOR_FILE_NAME");
       if(vcprojName)
         {
-        cmMakefile* tmf = target->GetMakefile();
-        std::string dir = tmf->GetCurrentBinaryDirectory();
+        cmLocalGenerator* lg = target->GetLocalGenerator();
+        std::string dir = lg->GetCurrentBinaryDirectory();
         dir = root->Convert(dir.c_str(),
                             cmLocalGenerator::START_OUTPUT);
         if(dir == ".")
@@ -477,7 +477,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
           dir = ""; // msbuild cannot handle ".\" prefix
           }
         this->WriteProject(fout, vcprojName, dir.c_str(),
-                           *target);
+                           target);
         written = true;
         }
       }
@@ -533,19 +533,19 @@ void cmGlobalVisualStudio7Generator::WriteTargetDepends(
   for(OrderedTargetDependSet::const_iterator tt =
         projectTargets.begin(); tt != projectTargets.end(); ++tt)
     {
-    cmTarget const* target = (*tt)->Target;
-    if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
+    cmGeneratorTarget const* target = *tt;
+    if(target->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
-    cmMakefile* mf = target->GetMakefile();
     const char *vcprojName =
       target->GetProperty("GENERATOR_FILE_NAME");
     if (vcprojName)
       {
-      std::string dir = mf->GetCurrentSourceDirectory();
+      std::string dir = target->GetLocalGenerator()
+              ->GetCurrentSourceDirectory();
       this->WriteProjectDepends(fout, vcprojName,
-                                dir.c_str(), *target);
+                                dir.c_str(), target);
       }
     }
 }
@@ -685,7 +685,8 @@ cmGlobalVisualStudio7Generator::ConvertToSolutionPath(const char* path)
 // the libraries it uses are also done here
 void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
                                const std::string& dspname,
-                               const char* dir, cmTarget const& target)
+                               const char* dir,
+                               cmGeneratorTarget const* target)
 {
    // check to see if this is a fortran build
   const char* ext = ".vcproj";
@@ -703,7 +704,7 @@ void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
        << dspname << ext << "\", \"{"
        << this->GetGUID(dspname) << "}\"\nEndProject\n";
 
-  UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
+  UtilityDependsMap::iterator ui = this->UtilityDepends.find(target);
   if(ui != this->UtilityDepends.end())
     {
     const char* uname = ui->second.c_str();
@@ -725,11 +726,11 @@ void
 cmGlobalVisualStudio7Generator
 ::WriteProjectDepends(std::ostream& fout,
                       const std::string& dspname,
-                      const char*, cmTarget const& target)
+                      const char*, cmGeneratorTarget const* target)
 {
   int depcount = 0;
   std::string dspguid = this->GetGUID(dspname);
-  VSDependSet const& depends = this->VSTargetDepends[&target];
+  VSDependSet const& depends = this->VSTargetDepends[target];
   for(VSDependSet::const_iterator di = depends.begin();
       di != depends.end(); ++di)
     {
@@ -738,7 +739,7 @@ cmGlobalVisualStudio7Generator
     if(guid.empty())
       {
       std::string m = "Target: ";
-      m += target.GetName();
+      m += target->GetName();
       m += " depends on unknown target: ";
       m += name;
       cmSystemTools::Error(m.c_str());
@@ -747,7 +748,7 @@ cmGlobalVisualStudio7Generator
     depcount++;
     }
 
-  UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
+  UtilityDependsMap::iterator ui = this->UtilityDepends.find(target);
   if(ui != this->UtilityDepends.end())
     {
     const char* uname = ui->second.c_str();
@@ -760,7 +761,7 @@ cmGlobalVisualStudio7Generator
 // executables to the libraries it uses are also done here
 void cmGlobalVisualStudio7Generator
 ::WriteProjectConfigurations(
-  std::ostream& fout, const std::string& name, cmTarget::TargetType,
+  std::ostream& fout, const std::string& name, cmState::TargetType,
   std::vector<std::string> const& configs,
   const std::set<std::string>& configsPartOfDefaultBuild,
   const std::string& platformMapping)
@@ -887,13 +888,14 @@ void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
 
 //----------------------------------------------------------------------------
 std::string
-cmGlobalVisualStudio7Generator::WriteUtilityDepend(cmTarget const* target)
+cmGlobalVisualStudio7Generator::WriteUtilityDepend(
+        cmGeneratorTarget const* target)
 {
   std::vector<std::string> configs;
-  target->GetMakefile()->GetConfigurations(configs);
+  target->Target->GetMakefile()->GetConfigurations(configs);
   std::string pname = target->GetName();
   pname += "_UTILITY";
-  std::string fname = target->GetMakefile()->GetCurrentBinaryDirectory();
+  std::string fname = target->GetLocalGenerator()->GetCurrentBinaryDirectory();
   fname += "/";
   fname += pname;
   fname += ".vcproj";
@@ -994,13 +996,14 @@ cmGlobalVisualStudio7Generator
 std::set<std::string>
 cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
   std::vector<std::string> const& configs,
-  OrderedTargetDependSet const& projectTargets, cmTarget const* target)
+  OrderedTargetDependSet const& projectTargets,
+  cmGeneratorTarget const* target)
 {
   std::set<std::string> activeConfigs;
   // if it is a utilitiy target then only make it part of the
   // default build if another target depends on it
   int type = target->GetType();
-  if (type == cmTarget::GLOBAL_TARGET)
+  if (type == cmState::GLOBAL_TARGET)
     {
     // check if INSTALL target is part of default build
     if(target->GetName() == "INSTALL")
@@ -1009,12 +1012,13 @@ cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
       for(std::vector<std::string>::const_iterator i = configs.begin();
           i != configs.end(); ++i)
         {
-        const char* propertyValue = target->GetMakefile()
+        const char* propertyValue = target->Target->GetMakefile()
           ->GetDefinition("CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD");
         cmGeneratorExpression ge;
         cmsys::auto_ptr<cmCompiledGeneratorExpression>
           cge = ge.Parse(propertyValue);
-        if(cmSystemTools::IsOn(cge->Evaluate(target->GetMakefile(), *i)))
+        if(cmSystemTools::IsOn(cge->Evaluate(target->GetLocalGenerator(),
+                                             *i)))
           {
           activeConfigs.insert(*i);
           }
@@ -1022,17 +1026,16 @@ cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
       }
     return activeConfigs;
     }
-  if(type == cmTarget::UTILITY && !this->IsDependedOn(projectTargets, target))
+  if(type == cmState::UTILITY && !this->IsDependedOn(projectTargets, target))
     {
     return activeConfigs;
     }
-  cmGeneratorTarget* gt = this->GetGeneratorTarget(target);
   // inspect EXCLUDE_FROM_DEFAULT_BUILD[_<CONFIG>] properties
   for(std::vector<std::string>::const_iterator i = configs.begin();
       i != configs.end(); ++i)
     {
     const char* propertyValue =
-      gt->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i->c_str());
+      target->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i->c_str());
     if(cmSystemTools::IsOff(propertyValue))
       {
       activeConfigs.insert(*i);
@@ -1044,9 +1047,8 @@ cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
 bool
 cmGlobalVisualStudio7Generator
 ::IsDependedOn(OrderedTargetDependSet const& projectTargets,
-               cmTarget const* targetIn)
+               cmGeneratorTarget const* gtIn)
 {
-  cmGeneratorTarget* gtIn = this->GetGeneratorTarget(targetIn);
   for (OrderedTargetDependSet::const_iterator l = projectTargets.begin();
        l != projectTargets.end(); ++l)
     {
diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h
index 35575d1..de2d35e 100644
--- a/Source/cmGlobalVisualStudio7Generator.h
+++ b/Source/cmGlobalVisualStudio7Generator.h
@@ -53,6 +53,12 @@ public:
   static void GetDocumentation(cmDocumentationEntry& entry);
 
   /**
+   * Utilized by the generator factory to determine if this generator
+   * supports toolsets.
+   */
+  static bool SupportsToolset() { return false; }
+
+  /**
    * Try to determine system information such as shared library
    * extension, pthreads, byte order etc.
    */
@@ -94,7 +100,8 @@ public:
 
   /** Return true if the target project file should have the option
       LinkLibraryDependencies and link to .sln dependencies. */
-  virtual bool NeedLinkLibraryDependencies(cmTarget&) { return false; }
+  virtual bool NeedLinkLibraryDependencies(cmGeneratorTarget*)
+  { return false; }
 
   const char* GetIntelProjectVersion();
 
@@ -123,12 +130,12 @@ protected:
                             std::vector<cmLocalGenerator*>& generators);
   virtual void WriteProject(std::ostream& fout,
                             const std::string& name, const char* path,
-                            cmTarget const& t);
+                            const cmGeneratorTarget *t);
   virtual void WriteProjectDepends(std::ostream& fout,
                            const std::string& name, const char* path,
-                           cmTarget const&t);
+                           cmGeneratorTarget const* t);
   virtual void WriteProjectConfigurations(
-    std::ostream& fout, const std::string& name, cmTarget::TargetType type,
+    std::ostream& fout, const std::string& name, cmState::TargetType type,
     std::vector<std::string> const& configs,
     const std::set<std::string>& configsPartOfDefaultBuild,
     const std::string& platformMapping = "");
@@ -136,7 +143,7 @@ protected:
                                       cmLocalGenerator* root);
   virtual void WriteSLNFooter(std::ostream& fout);
   virtual void WriteSLNHeader(std::ostream& fout);
-  virtual std::string WriteUtilityDepend(cmTarget const* target);
+  virtual std::string WriteUtilityDepend(const cmGeneratorTarget *target);
 
   virtual void WriteTargetsToSolution(
     std::ostream& fout,
@@ -162,9 +169,9 @@ protected:
   std::set<std::string>
     IsPartOfDefaultBuild(std::vector<std::string> const& configs,
                          OrderedTargetDependSet const& projectTargets,
-                         cmTarget const* target);
+                         cmGeneratorTarget const* target);
   bool IsDependedOn(OrderedTargetDependSet const& projectTargets,
-                    cmTarget const* target);
+                    cmGeneratorTarget const* target);
   std::map<std::string, std::string> GUIDMap;
 
   virtual void WriteFolders(std::ostream& fout);
diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx
index 70c00e9..3abff6c 100644
--- a/Source/cmGlobalVisualStudio8Generator.cxx
+++ b/Source/cmGlobalVisualStudio8Generator.cxx
@@ -84,6 +84,8 @@ public:
       names.push_back("Visual Studio 8 2005 " + *i);
       }
   }
+
+  virtual bool SupportsToolset() const { return false; }
 };
 
 //----------------------------------------------------------------------------
@@ -256,7 +258,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
                           noCommandLines);
 
   cmGeneratorTarget* gt = new cmGeneratorTarget(tgt, lg);
-  mf->AddGeneratorTarget(tgt, gt);
+  lg->AddGeneratorTarget(gt);
 
   // Organize in the "predefined targets" folder:
   //
@@ -312,10 +314,10 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
   cmCustomCommandLine commandLine;
   commandLine.push_back(cmSystemTools::GetCMakeCommand());
   std::string argH = "-H";
-  argH += mf->GetHomeDirectory();
+  argH += lg->GetSourceDirectory();
   commandLine.push_back(argH);
   std::string argB = "-B";
-  argB += mf->GetHomeOutputDirectory();
+  argB += lg->GetBinaryDirectory();
   commandLine.push_back(argB);
   commandLine.push_back("--check-stamp-list");
   commandLine.push_back(stampList.c_str());
@@ -336,7 +338,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
        no_main_dependency, commandLines, "Checking Build System",
        no_working_directory, true))
     {
-    tgt->AddSource(file->GetFullPath());
+    gt->AddSource(file->GetFullPath());
     }
   else
     {
@@ -348,27 +350,26 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
 }
 
 //----------------------------------------------------------------------------
-bool cmGlobalVisualStudio8Generator::Compute()
+void cmGlobalVisualStudio8Generator::AddExtraIDETargets()
 {
-  if (!cmGlobalVisualStudio7Generator::Compute())
-    {
-    return false;
-    }
-
+  cmGlobalVisualStudio7Generator::AddExtraIDETargets();
   if(this->AddCheckTarget())
     {
-    // All targets depend on the build-system check target.
-    for(TargetMap::const_iterator
-          ti = this->TotalTargets.begin();
-        ti != this->TotalTargets.end(); ++ti)
+    for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
       {
-      if(ti->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
+      std::vector<cmGeneratorTarget*> tgts =
+          this->LocalGenerators[i]->GetGeneratorTargets();
+      // All targets depend on the build-system check target.
+      for(std::vector<cmGeneratorTarget*>::iterator ti = tgts.begin();
+          ti != tgts.end(); ++ti)
         {
-        ti->second->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
+        if((*ti)->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
+          {
+          (*ti)->Target->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
+          }
         }
       }
     }
-  return true;
 }
 
 //----------------------------------------------------------------------------
@@ -391,7 +392,7 @@ cmGlobalVisualStudio8Generator
 void
 cmGlobalVisualStudio8Generator
 ::WriteProjectConfigurations(
-  std::ostream& fout, const std::string& name, cmTarget::TargetType type,
+  std::ostream& fout, const std::string& name, cmState::TargetType type,
   std::vector<std::string> const& configs,
   const std::set<std::string>& configsPartOfDefaultBuild,
   std::string const& platformMapping)
@@ -428,10 +429,10 @@ cmGlobalVisualStudio8Generator
 
 //----------------------------------------------------------------------------
 bool
-cmGlobalVisualStudio8Generator::NeedsDeploy(cmTarget::TargetType type) const
+cmGlobalVisualStudio8Generator::NeedsDeploy(cmState::TargetType type) const
 {
-  bool needsDeploy = (type == cmTarget::EXECUTABLE ||
-                      type == cmTarget::SHARED_LIBRARY);
+  bool needsDeploy = (type == cmState::EXECUTABLE ||
+                      type == cmState::SHARED_LIBRARY);
   return this->TargetsWindowsCE() && needsDeploy;
 }
 
@@ -445,15 +446,15 @@ bool cmGlobalVisualStudio8Generator::ComputeTargetDepends()
 
 //----------------------------------------------------------------------------
 void cmGlobalVisualStudio8Generator::WriteProjectDepends(
-  std::ostream& fout, const std::string&, const char*, cmTarget const& t)
+  std::ostream& fout, const std::string&, const char*,
+        cmGeneratorTarget const* gt)
 {
-  cmGeneratorTarget* gt = this->GetGeneratorTarget(&t);
   TargetDependSet const& unordered = this->GetTargetDirectDepends(gt);
   OrderedTargetDependSet depends(unordered, std::string());
   for(OrderedTargetDependSet::const_iterator i = depends.begin();
       i != depends.end(); ++i)
     {
-    if((*i)->GetType() == cmTarget::INTERFACE_LIBRARY)
+    if((*i)->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
@@ -464,16 +465,17 @@ void cmGlobalVisualStudio8Generator::WriteProjectDepends(
 
 //----------------------------------------------------------------------------
 bool cmGlobalVisualStudio8Generator::NeedLinkLibraryDependencies(
-  cmTarget& target)
+        cmGeneratorTarget *target)
 {
   // Look for utility dependencies that magically link.
   for(std::set<std::string>::const_iterator ui =
-        target.GetUtilities().begin();
-      ui != target.GetUtilities().end(); ++ui)
+        target->GetUtilities().begin();
+      ui != target->GetUtilities().end(); ++ui)
     {
-    if(cmTarget* depTarget = this->FindTarget(ui->c_str()))
+    if(cmGeneratorTarget* depTarget =
+        target->GetLocalGenerator()->FindGeneratorTargetToUse(ui->c_str()))
       {
-      if(depTarget->GetType() != cmTarget::INTERFACE_LIBRARY
+      if(depTarget->GetType() != cmState::INTERFACE_LIBRARY
           && depTarget->GetProperty("EXTERNAL_MSPROJECT"))
         {
         // This utility dependency names an external .vcproj target.
diff --git a/Source/cmGlobalVisualStudio8Generator.h b/Source/cmGlobalVisualStudio8Generator.h
index 1c61103..b3093cc 100644
--- a/Source/cmGlobalVisualStudio8Generator.h
+++ b/Source/cmGlobalVisualStudio8Generator.h
@@ -60,14 +60,14 @@ public:
 
   /** Return true if the target project file should have the option
       LinkLibraryDependencies and link to .sln dependencies. */
-  virtual bool NeedLinkLibraryDependencies(cmTarget& target);
+  virtual bool NeedLinkLibraryDependencies(cmGeneratorTarget* target);
 
   /** Return true if building for Windows CE */
   virtual bool TargetsWindowsCE() const {
     return !this->WindowsCEVersion.empty(); }
 
 protected:
-  virtual bool Compute();
+  virtual void AddExtraIDETargets();
   virtual const char* GetIDEVersion() { return "8.0"; }
 
   virtual std::string FindDevEnvCommand();
@@ -77,21 +77,22 @@ protected:
   bool AddCheckTarget();
 
   /** Return true if the configuration needs to be deployed */
-  virtual bool NeedsDeploy(cmTarget::TargetType type) const;
+  virtual bool NeedsDeploy(cmState::TargetType type) const;
 
   static cmIDEFlagTable const* GetExtraFlagTableVS8();
   virtual void WriteSLNHeader(std::ostream& fout);
   virtual void WriteSolutionConfigurations(
     std::ostream& fout, std::vector<std::string> const& configs);
   virtual void WriteProjectConfigurations(
-    std::ostream& fout, const std::string& name, cmTarget::TargetType type,
+    std::ostream& fout, const std::string& name, cmState::TargetType type,
     std::vector<std::string> const& configs,
     const std::set<std::string>& configsPartOfDefaultBuild,
     const std::string& platformMapping = "");
   virtual bool ComputeTargetDepends();
   virtual void WriteProjectDepends(std::ostream& fout,
                                    const std::string& name,
-                                   const char* path, cmTarget const& t);
+                                   const char* path,
+                                   const cmGeneratorTarget *t);
 
   std::string Name;
   std::string WindowsCEVersion;
diff --git a/Source/cmGlobalVisualStudio9Generator.cxx b/Source/cmGlobalVisualStudio9Generator.cxx
index d98793a..884f754 100644
--- a/Source/cmGlobalVisualStudio9Generator.cxx
+++ b/Source/cmGlobalVisualStudio9Generator.cxx
@@ -88,6 +88,8 @@ public:
       names.push_back("Visual Studio 9 2008 " + *i);
       }
   }
+
+  virtual bool SupportsToolset() const { return false; }
 };
 
 //----------------------------------------------------------------------------
diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx
index 7552d67..6a1aa29 100644
--- a/Source/cmGlobalVisualStudioGenerator.cxx
+++ b/Source/cmGlobalVisualStudioGenerator.cxx
@@ -64,13 +64,8 @@ std::string cmGlobalVisualStudioGenerator::GetRegistryBase(
 }
 
 //----------------------------------------------------------------------------
-bool cmGlobalVisualStudioGenerator::Compute()
+void cmGlobalVisualStudioGenerator::AddExtraIDETargets()
 {
-  if (!cmGlobalGenerator::Compute())
-    {
-    return false;
-    }
-
   // Add a special target that depends on ALL projects for easy build
   // of one configuration only.
   const char* no_working_dir = 0;
@@ -92,7 +87,7 @@ bool cmGlobalVisualStudioGenerator::Compute()
                           "Build all projects");
 
       cmGeneratorTarget* gt = new cmGeneratorTarget(allBuild, gen[0]);
-      allBuild->GetMakefile()->AddGeneratorTarget(allBuild, gt);
+      gen[0]->AddGeneratorTarget(gt);
 
 #if 0
       // Can't activate this code because we want ALL_BUILD
@@ -112,19 +107,20 @@ bool cmGlobalVisualStudioGenerator::Compute()
       for(std::vector<cmLocalGenerator*>::iterator i = gen.begin();
           i != gen.end(); ++i)
         {
-        cmGeneratorTargetsType targets =
-            (*i)->GetMakefile()->GetGeneratorTargets();
-        for(cmGeneratorTargetsType::iterator t = targets.begin();
+        std::vector<cmGeneratorTarget*> targets =
+            (*i)->GetGeneratorTargets();
+        for(std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
             t != targets.end(); ++t)
           {
-          if (t->second->GetType() == cmTarget::GLOBAL_TARGET
-              || t->first->IsImported())
+          cmGeneratorTarget* tgt = *t;
+          if (tgt->GetType() == cmState::GLOBAL_TARGET
+              || tgt->IsImported())
             {
             continue;
             }
-          if(!this->IsExcluded(gen[0], t->second))
+          if(!this->IsExcluded(gen[0], tgt))
             {
-            allBuild->AddUtility(t->second->GetName());
+            allBuild->AddUtility(tgt->GetName());
             }
           }
         }
@@ -144,16 +140,15 @@ bool cmGlobalVisualStudioGenerator::Compute()
       static_cast<cmLocalVisualStudioGenerator*>(*lgi);
     lg->AddCMakeListsRules();
     }
-  return true;
 }
 
 //----------------------------------------------------------------------------
 void cmGlobalVisualStudioGenerator
 ::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const
 {
-  std::string dir = gt->Makefile->GetCurrentBinaryDirectory();
+  std::string dir = gt->LocalGenerator->GetCurrentBinaryDirectory();
   dir += "/";
-  std::string tgtDir = gt->LocalGenerator->GetTargetDirectory(*gt->Target);
+  std::string tgtDir = gt->LocalGenerator->GetTargetDirectory(gt);
   if(!tgtDir.empty())
     {
     dir += tgtDir;
@@ -256,7 +251,7 @@ cmGlobalVisualStudioGenerator
         {
         topLevelSlnName = mf->GetCurrentBinaryDirectory();
         topLevelSlnName += "/";
-        topLevelSlnName += mf->GetProjectName();
+        topLevelSlnName += this->LocalGenerators[0]->GetProjectName();
         topLevelSlnName += ".sln";
         }
 
@@ -307,19 +302,20 @@ std::string cmGlobalVisualStudioGenerator::GetUserMacrosRegKeyBase()
 }
 
 //----------------------------------------------------------------------------
-void cmGlobalVisualStudioGenerator::FillLinkClosure(cmTarget const* target,
-                                                    TargetSet& linked)
+void cmGlobalVisualStudioGenerator::FillLinkClosure(
+        const cmGeneratorTarget *target,
+        TargetSet& linked)
 {
   if(linked.insert(target).second)
     {
-    cmGeneratorTarget* gt = this->GetGeneratorTarget(target);
-    TargetDependSet const& depends = this->GetTargetDirectDepends(gt);
+    TargetDependSet const& depends =
+            this->GetTargetDirectDepends(target);
     for(TargetDependSet::const_iterator di = depends.begin();
         di != depends.end(); ++di)
       {
       if(di->IsLink())
         {
-        this->FillLinkClosure((*di)->Target, linked);
+        this->FillLinkClosure(*di, linked);
         }
       }
     }
@@ -327,7 +323,7 @@ void cmGlobalVisualStudioGenerator::FillLinkClosure(cmTarget const* target,
 
 //----------------------------------------------------------------------------
 cmGlobalVisualStudioGenerator::TargetSet const&
-cmGlobalVisualStudioGenerator::GetTargetLinkClosure(cmTarget* target)
+cmGlobalVisualStudioGenerator::GetTargetLinkClosure(cmGeneratorTarget* target)
 {
   TargetSetMap::iterator i = this->TargetLinkClosure.find(target);
   if(i == this->TargetLinkClosure.end())
@@ -341,25 +337,25 @@ cmGlobalVisualStudioGenerator::GetTargetLinkClosure(cmTarget* target)
 
 //----------------------------------------------------------------------------
 void cmGlobalVisualStudioGenerator::FollowLinkDepends(
-  cmTarget const* target, std::set<cmTarget const*>& linked)
+        const cmGeneratorTarget *target,
+        std::set<const cmGeneratorTarget *> &linked)
 {
-  if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
+  if(target->GetType() == cmState::INTERFACE_LIBRARY)
     {
     return;
     }
   if(linked.insert(target).second &&
-     target->GetType() == cmTarget::STATIC_LIBRARY)
+     target->GetType() == cmState::STATIC_LIBRARY)
     {
     // Static library targets do not list their link dependencies so
     // we must follow them transitively now.
-    cmGeneratorTarget* gt = this->GetGeneratorTarget(target);
-    TargetDependSet const& depends = this->GetTargetDirectDepends(gt);
+    TargetDependSet const& depends = this->GetTargetDirectDepends(target);
     for(TargetDependSet::const_iterator di = depends.begin();
         di != depends.end(); ++di)
       {
       if(di->IsLink())
         {
-        this->FollowLinkDepends((*di)->Target, linked);
+        this->FollowLinkDepends(*di, linked);
         }
       }
     }
@@ -379,11 +375,11 @@ bool cmGlobalVisualStudioGenerator::ComputeTargetDepends()
     for(std::vector<cmLocalGenerator*>::iterator i = gen.begin();
         i != gen.end(); ++i)
       {
-      cmTargets& targets = (*i)->GetMakefile()->GetTargets();
-      for(cmTargets::iterator ti = targets.begin();
+      std::vector<cmGeneratorTarget*> targets = (*i)->GetGeneratorTargets();
+      for(std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
           ti != targets.end(); ++ti)
         {
-        this->ComputeVSTargetDepends(ti->second);
+        this->ComputeVSTargetDepends(*ti);
         }
       }
     }
@@ -391,19 +387,20 @@ bool cmGlobalVisualStudioGenerator::ComputeTargetDepends()
 }
 
 //----------------------------------------------------------------------------
-static bool VSLinkable(cmTarget const* t)
+static bool VSLinkable(cmGeneratorTarget const* t)
 {
-  return t->IsLinkable() || t->GetType() == cmTarget::OBJECT_LIBRARY;
+  return t->IsLinkable() || t->GetType() == cmState::OBJECT_LIBRARY;
 }
 
 //----------------------------------------------------------------------------
-void cmGlobalVisualStudioGenerator::ComputeVSTargetDepends(cmTarget& target)
+void cmGlobalVisualStudioGenerator::ComputeVSTargetDepends(
+        cmGeneratorTarget* target)
 {
-  if(this->VSTargetDepends.find(&target) != this->VSTargetDepends.end())
+  if(this->VSTargetDepends.find(target) != this->VSTargetDepends.end())
     {
     return;
     }
-  VSDependSet& vsTargetDepend = this->VSTargetDepends[&target];
+  VSDependSet& vsTargetDepend = this->VSTargetDepends[target];
   // VS <= 7.1 has two behaviors that affect solution dependencies.
   //
   // (1) Solution-level dependencies between a linkable target and a
@@ -423,19 +420,18 @@ void cmGlobalVisualStudioGenerator::ComputeVSTargetDepends(cmTarget& target)
   // leaving them out for the static library itself but following them
   // transitively for other targets.
 
-  bool allowLinkable = (target.GetType() != cmTarget::STATIC_LIBRARY &&
-                        target.GetType() != cmTarget::SHARED_LIBRARY &&
-                        target.GetType() != cmTarget::MODULE_LIBRARY &&
-                        target.GetType() != cmTarget::EXECUTABLE);
+  bool allowLinkable = (target->GetType() != cmState::STATIC_LIBRARY &&
+                        target->GetType() != cmState::SHARED_LIBRARY &&
+                        target->GetType() != cmState::MODULE_LIBRARY &&
+                        target->GetType() != cmState::EXECUTABLE);
 
-  cmGeneratorTarget* gt = this->GetGeneratorTarget(&target);
-  TargetDependSet const& depends = this->GetTargetDirectDepends(gt);
+  TargetDependSet const& depends = this->GetTargetDirectDepends(target);
 
   // Collect implicit link dependencies (target_link_libraries).
   // Static libraries cannot depend on their link implementation
   // due to behavior (2), but they do not really need to.
-  std::set<cmTarget const*> linkDepends;
-  if(target.GetType() != cmTarget::STATIC_LIBRARY)
+  std::set<cmGeneratorTarget const*> linkDepends;
+  if(target->GetType() != cmState::STATIC_LIBRARY)
     {
     for(TargetDependSet::const_iterator di = depends.begin();
         di != depends.end(); ++di)
@@ -443,54 +439,54 @@ void cmGlobalVisualStudioGenerator::ComputeVSTargetDepends(cmTarget& target)
       cmTargetDepend dep = *di;
       if(dep.IsLink())
         {
-        this->FollowLinkDepends(dep->Target, linkDepends);
+        this->FollowLinkDepends(*di, linkDepends);
         }
       }
     }
 
   // Collect explicit util dependencies (add_dependencies).
-  std::set<cmTarget const*> utilDepends;
+  std::set<cmGeneratorTarget const*> utilDepends;
   for(TargetDependSet::const_iterator di = depends.begin();
       di != depends.end(); ++di)
     {
     cmTargetDepend dep = *di;
     if(dep.IsUtil())
       {
-      this->FollowLinkDepends(dep->Target, utilDepends);
+      this->FollowLinkDepends(*di, utilDepends);
       }
     }
 
   // Collect all targets linked by this target so we can avoid
   // intermediate targets below.
   TargetSet linked;
-  if(target.GetType() != cmTarget::STATIC_LIBRARY)
+  if(target->GetType() != cmState::STATIC_LIBRARY)
     {
-    linked = this->GetTargetLinkClosure(&target);
+    linked = this->GetTargetLinkClosure(target);
     }
 
   // Emit link dependencies.
-  for(std::set<cmTarget const*>::iterator di = linkDepends.begin();
+  for(std::set<cmGeneratorTarget const*>::iterator di = linkDepends.begin();
       di != linkDepends.end(); ++di)
     {
-    cmTarget const* dep = *di;
+    cmGeneratorTarget const* dep = *di;
     vsTargetDepend.insert(dep->GetName());
     }
 
   // Emit util dependencies.  Possibly use intermediate targets.
-  for(std::set<cmTarget const*>::iterator di = utilDepends.begin();
+  for(std::set<cmGeneratorTarget const*>::iterator di = utilDepends.begin();
       di != utilDepends.end(); ++di)
     {
-    cmTarget const* dep = *di;
-    if(allowLinkable || !VSLinkable(dep) || linked.count(dep))
+    cmGeneratorTarget const* dgt = *di;
+    if(allowLinkable || !VSLinkable(dgt) || linked.count(dgt))
       {
       // Direct dependency allowed.
-      vsTargetDepend.insert(dep->GetName());
+      vsTargetDepend.insert(dgt->GetName());
       }
     else
       {
       // Direct dependency on linkable target not allowed.
       // Use an intermediate utility target.
-      vsTargetDepend.insert(this->GetUtilityDepend(dep));
+      vsTargetDepend.insert(this->GetUtilityDepend(dgt));
       }
     }
 }
@@ -510,7 +506,8 @@ void cmGlobalVisualStudioGenerator::FindMakeProgram(cmMakefile* mf)
 
 //----------------------------------------------------------------------------
 std::string
-cmGlobalVisualStudioGenerator::GetUtilityDepend(cmTarget const* target)
+cmGlobalVisualStudioGenerator::GetUtilityDepend(
+        cmGeneratorTarget const* target)
 {
   UtilityDependsMap::iterator i = this->UtilityDepends.find(target);
   if(i == this->UtilityDepends.end())
@@ -833,10 +830,8 @@ void RegisterVisualStudioMacros(const std::string& macrosFile,
     }
 }
 bool
-cmGlobalVisualStudioGenerator::TargetIsFortranOnly(cmTarget const& target)
+cmGlobalVisualStudioGenerator::TargetIsFortranOnly(cmGeneratorTarget const* gt)
 {
-  cmGeneratorTarget* gt = this->GetGeneratorTarget(&target);
-
   // check to see if this is a fortran build
   std::set<std::string> languages;
   {
@@ -895,9 +890,7 @@ cmGlobalVisualStudioGenerator::OrderedTargetDependSet
   for (TargetSet::const_iterator it = targets.begin();
        it != targets.end(); ++it)
     {
-    cmGeneratorTarget* gt =
-        (*it)->GetMakefile()->GetGlobalGenerator()->GetGeneratorTarget(*it);
-    this->insert(gt);
+    this->insert(*it);
     }
 }
 
diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h
index c940eb3..f827f26 100644
--- a/Source/cmGlobalVisualStudioGenerator.h
+++ b/Source/cmGlobalVisualStudioGenerator.h
@@ -73,7 +73,7 @@ public:
                              const char* vsSolutionFile = 0);
 
   // return true if target is fortran only
-  bool TargetIsFortranOnly(cmTarget const& t);
+  bool TargetIsFortranOnly(const cmGeneratorTarget *gt);
 
   /** Get the top-level registry key for this VS version.  */
   std::string GetRegistryBase();
@@ -88,7 +88,7 @@ public:
   /** Return true if building for Windows CE */
   virtual bool TargetsWindowsCE() const { return false; }
 
-  class TargetSet: public std::set<cmTarget const*> {};
+  class TargetSet: public std::set<cmGeneratorTarget const*> {};
   class TargetCompare
   {
     std::string First;
@@ -111,7 +111,7 @@ public:
     cmGeneratorTarget*, std::vector<cmCustomCommand>& commands,
     std::string const& configName);
 protected:
-  virtual bool Compute();
+  virtual void AddExtraIDETargets();
 
   // Does this VS version link targets to each other if there are
   // dependencies in the SLN file?  This was done for VS versions
@@ -122,15 +122,16 @@ protected:
 
   virtual bool ComputeTargetDepends();
   class VSDependSet: public std::set<std::string> {};
-  class VSDependMap: public std::map<cmTarget const*, VSDependSet> {};
+  class VSDependMap: public std::map<cmGeneratorTarget const*, VSDependSet> {};
   VSDependMap VSTargetDepends;
-  void ComputeVSTargetDepends(cmTarget&);
-
-  bool CheckTargetLinks(cmTarget& target, const std::string& name);
-  std::string GetUtilityForTarget(cmTarget& target, const std::string&);
-  virtual std::string WriteUtilityDepend(cmTarget const*) = 0;
-  std::string GetUtilityDepend(cmTarget const* target);
-  typedef std::map<cmTarget const*, std::string> UtilityDependsMap;
+  void ComputeVSTargetDepends(cmGeneratorTarget *);
+
+  bool CheckTargetLinks(cmGeneratorTarget& target, const std::string& name);
+  std::string GetUtilityForTarget(cmGeneratorTarget& target,
+                                  const std::string&);
+  virtual std::string WriteUtilityDepend(cmGeneratorTarget const*) = 0;
+  std::string GetUtilityDepend(const cmGeneratorTarget *target);
+  typedef std::map<cmGeneratorTarget const*, std::string> UtilityDependsMap;
   UtilityDependsMap UtilityDepends;
 
 protected:
@@ -141,13 +142,14 @@ private:
   void PrintCompilerAdvice(std::ostream&, std::string const&,
                            const char*) const {}
 
-  void FollowLinkDepends(cmTarget const* target,
-                         std::set<cmTarget const*>& linked);
+  void FollowLinkDepends(cmGeneratorTarget const* target,
+                         std::set<cmGeneratorTarget const*>& linked);
 
-  class TargetSetMap: public std::map<cmTarget*, TargetSet> {};
+  class TargetSetMap: public std::map<cmGeneratorTarget*, TargetSet> {};
   TargetSetMap TargetLinkClosure;
-  void FillLinkClosure(cmTarget const* target, TargetSet& linked);
-  TargetSet const& GetTargetLinkClosure(cmTarget* target);
+  void FillLinkClosure(const cmGeneratorTarget *target,
+                       TargetSet& linked);
+  TargetSet const& GetTargetLinkClosure(cmGeneratorTarget* target);
 };
 
 class cmGlobalVisualStudioGenerator::OrderedTargetDependSet:
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 33babec..526e32f 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -125,6 +125,8 @@ public:
 
   virtual void GetGenerators(std::vector<std::string>& names) const {
     names.push_back(cmGlobalXCodeGenerator::GetActualName()); }
+
+  virtual bool SupportsToolset() const { return true; }
 };
 
 //----------------------------------------------------------------------------
@@ -376,14 +378,8 @@ cmGlobalXCodeGenerator::CreateLocalGenerator(cmMakefile* mf)
   return new cmLocalXCodeGenerator(this, mf);
 }
 
-//----------------------------------------------------------------------------
-bool cmGlobalXCodeGenerator::Compute()
+void cmGlobalXCodeGenerator::AddExtraIDETargets()
 {
-  if (!cmGlobalGenerator::Compute())
-    {
-      return false;
-    }
-
   std::map<std::string, std::vector<cmLocalGenerator*> >::iterator it;
   // make sure extra targets are added before calling
   // the parent generate which will call trace depends
@@ -394,7 +390,6 @@ bool cmGlobalXCodeGenerator::Compute()
     // add ALL_BUILD, INSTALL, etc
     this->AddExtraTargets(root, it->second);
     }
-  return true;
 }
 
 void cmGlobalXCodeGenerator::Generate()
@@ -417,15 +412,17 @@ void cmGlobalXCodeGenerator::Generate()
 //----------------------------------------------------------------------------
 void cmGlobalXCodeGenerator::SetGenerationRoot(cmLocalGenerator* root)
 {
-  this->CurrentProject = root->GetMakefile()->GetProjectName();
+  this->CurrentProject = root->GetProjectName();
   this->SetCurrentLocalGenerator(root);
-  cmSystemTools::SplitPath(this->CurrentMakefile->GetCurrentSourceDirectory(),
-                           this->ProjectSourceDirectoryComponents);
-  cmSystemTools::SplitPath(this->CurrentMakefile->GetCurrentBinaryDirectory(),
-                           this->ProjectOutputDirectoryComponents);
+  cmSystemTools::SplitPath(
+        this->CurrentLocalGenerator->GetCurrentSourceDirectory(),
+        this->ProjectSourceDirectoryComponents);
+  cmSystemTools::SplitPath(
+        this->CurrentLocalGenerator->GetCurrentBinaryDirectory(),
+        this->ProjectOutputDirectoryComponents);
 
   this->CurrentXCodeHackMakefile =
-    root->GetMakefile()->GetCurrentBinaryDirectory();
+    root->GetCurrentBinaryDirectory();
   this->CurrentXCodeHackMakefile += "/CMakeScripts";
   cmSystemTools::MakeDirectory(this->CurrentXCodeHackMakefile.c_str());
   this->CurrentXCodeHackMakefile += "/XCODE_DEPEND_HELPER.make";
@@ -464,16 +461,16 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
                         "echo", "Build all projects");
 
   cmGeneratorTarget* allBuildGt = new cmGeneratorTarget(allbuild, root);
-  mf->AddGeneratorTarget(allbuild, allBuildGt);
+  root->AddGeneratorTarget(allBuildGt);
 
   // Refer to the main build configuration file for easy editing.
-  std::string listfile = mf->GetCurrentSourceDirectory();
+  std::string listfile = root->GetCurrentSourceDirectory();
   listfile += "/";
   listfile += "CMakeLists.txt";
-  allbuild->AddSourceCMP0049(listfile.c_str());
+  allBuildGt->AddSource(listfile.c_str());
 
   // Add XCODE depend helper
-  std::string dir = mf->GetCurrentBinaryDirectory();
+  std::string dir = root->GetCurrentBinaryDirectory();
   cmCustomCommandLine makeHelper;
   if(this->XcodeVersion < 50)
     {
@@ -499,7 +496,7 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
                           "make", "-f", file.c_str());
 
     cmGeneratorTarget* checkGt = new cmGeneratorTarget(check, root);
-    mf->AddGeneratorTarget(check, checkGt);
+    root->AddGeneratorTarget(checkGt);
     }
 
   // now make the allbuild depend on all the non-utility targets
@@ -513,19 +510,22 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
       continue;
       }
 
-    cmTargets& tgts = lg->GetMakefile()->GetTargets();
-    for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
+    std::vector<cmGeneratorTarget*> tgts = lg->GetGeneratorTargets();
+    for(std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
+        l != tgts.end(); l++)
       {
-      cmTarget& target = l->second;
+      cmGeneratorTarget* target = *l;
 
-      if (target.GetType() == cmTarget::GLOBAL_TARGET)
+      if (target->GetType() == cmState::GLOBAL_TARGET)
         {
         continue;
         }
 
-      if (regenerate && (l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET))
+      std::string targetName = target->GetName();
+
+      if (regenerate && (targetName != CMAKE_CHECK_BUILD_SYSTEM_TARGET))
         {
-        target.AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
+        target->Target->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
         }
 
       // make all exe, shared libs and modules
@@ -533,19 +533,19 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
       // this will make sure that when the next target is built
       // things are up-to-date
       if(!makeHelper.empty() &&
-         (target.GetType() == cmTarget::EXECUTABLE ||
+         (target->GetType() == cmState::EXECUTABLE ||
 // Nope - no post-build for OBJECT_LIRBRARY
-//          target.GetType() == cmTarget::OBJECT_LIBRARY ||
-          target.GetType() == cmTarget::STATIC_LIBRARY ||
-          target.GetType() == cmTarget::SHARED_LIBRARY ||
-          target.GetType() == cmTarget::MODULE_LIBRARY))
+//          target->GetType() == cmState::OBJECT_LIBRARY ||
+          target->GetType() == cmState::STATIC_LIBRARY ||
+          target->GetType() == cmState::SHARED_LIBRARY ||
+          target->GetType() == cmState::MODULE_LIBRARY))
         {
         makeHelper[makeHelper.size()-1] = // fill placeholder
-          this->PostBuildMakeTarget(target.GetName(), "$(CONFIGURATION)");
+          this->PostBuildMakeTarget(target->GetName(), "$(CONFIGURATION)");
         cmCustomCommandLines commandLines;
         commandLines.push_back(makeHelper);
         std::vector<std::string> no_byproducts;
-        lg->GetMakefile()->AddCustomCommandToTarget(target.GetName(),
+        lg->GetMakefile()->AddCustomCommandToTarget(target->GetName(),
                                                     no_byproducts,
                                                     no_depends,
                                                     commandLines,
@@ -554,17 +554,17 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
                                                     dir.c_str());
         }
 
-      if(target.GetType() != cmTarget::INTERFACE_LIBRARY
-          && !target.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
+      if(target->GetType() != cmState::INTERFACE_LIBRARY
+          && !target->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
         {
-        allbuild->AddUtility(target.GetName());
+        allbuild->AddUtility(target->GetName());
         }
 
       // Refer to the build configuration file for easy editing.
-      listfile = lg->GetMakefile()->GetCurrentSourceDirectory();
+      listfile = lg->GetCurrentSourceDirectory();
       listfile += "/";
       listfile += "CMakeLists.txt";
-      target.AddSourceCMP0049(listfile.c_str());
+      target->AddSource(listfile.c_str());
       }
     }
 }
@@ -573,7 +573,6 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
 void cmGlobalXCodeGenerator::CreateReRunCMakeFile(
   cmLocalGenerator* root, std::vector<cmLocalGenerator*> const& gens)
 {
-  cmMakefile* mf = root->GetMakefile();
   std::vector<std::string> lfiles;
   for(std::vector<cmLocalGenerator*>::const_iterator gi = gens.begin();
       gi != gens.end(); ++gi)
@@ -587,7 +586,7 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile(
   std::vector<std::string>::iterator new_end =
     std::unique(lfiles.begin(), lfiles.end());
   lfiles.erase(new_end, lfiles.end());
-  this->CurrentReRunCMakeMakefile = mf->GetCurrentBinaryDirectory();
+  this->CurrentReRunCMakeMakefile = root->GetCurrentBinaryDirectory();
   this->CurrentReRunCMakeMakefile += "/CMakeScripts";
   cmSystemTools::MakeDirectory(this->CurrentReRunCMakeMakefile.c_str());
   this->CurrentReRunCMakeMakefile += "/ReRunCMake.make";
@@ -595,7 +594,7 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile(
     (this->CurrentReRunCMakeMakefile.c_str());
   makefileStream.SetCopyIfDifferent(true);
   makefileStream << "# Generated by CMake, DO NOT EDIT\n";
-  std::string checkCache = mf->GetHomeOutputDirectory();
+  std::string checkCache = root->GetBinaryDirectory();
   checkCache += "/";
   checkCache += cmake::GetCMakeFilesDirectoryPostSlash();
   checkCache += "cmake.check_cache";
@@ -609,9 +608,9 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile(
   makefileStream << "\n\t" <<
     this->ConvertToRelativeForMake(cmSystemTools::GetCMakeCommand().c_str())
                  << " -H" << this->ConvertToRelativeForMake(
-                   mf->GetHomeDirectory())
+                   root->GetSourceDirectory())
                  << " -B" << this->ConvertToRelativeForMake(
-                   mf->GetHomeOutputDirectory()) << "\n";
+                   root->GetBinaryDirectory()) << "\n";
 }
 
 //----------------------------------------------------------------------------
@@ -711,10 +710,19 @@ cmXCodeObject* cmGlobalXCodeGenerator
 }
 
 //----------------------------------------------------------------------------
+cmXCodeObject* cmGlobalXCodeGenerator
+::CreateFlatClone(cmXCodeObject* orig)
+{
+  cmXCodeObject* obj = this->CreateObject(orig->GetType());
+  obj->CopyAttributes(orig);
+  return obj;
+}
+
+//----------------------------------------------------------------------------
 std::string
-GetGroupMapKeyFromPath(cmTarget& cmtarget, const std::string& fullpath)
+GetGroupMapKeyFromPath(cmGeneratorTarget* target, const std::string& fullpath)
 {
-  std::string key(cmtarget.GetName());
+  std::string key(target->GetName());
   key += "-";
   key += fullpath;
   return key;
@@ -722,16 +730,16 @@ GetGroupMapKeyFromPath(cmTarget& cmtarget, const std::string& fullpath)
 
 //----------------------------------------------------------------------------
 std::string
-GetGroupMapKey(cmTarget& cmtarget, cmSourceFile* sf)
+GetGroupMapKey(cmGeneratorTarget* target, cmSourceFile* sf)
 {
-  return GetGroupMapKeyFromPath(cmtarget, sf->GetFullPath());
+  return GetGroupMapKeyFromPath(target, sf->GetFullPath());
 }
 
 //----------------------------------------------------------------------------
 cmXCodeObject*
 cmGlobalXCodeGenerator::CreateXCodeSourceFileFromPath(
   const std::string &fullpath,
-  cmTarget& cmtarget,
+  cmGeneratorTarget* target,
   const std::string &lang,
   cmSourceFile* sf)
 {
@@ -739,7 +747,7 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFileFromPath(
   // fileRef object for any given full path.
   //
   cmXCodeObject* fileRef =
-    this->CreateXCodeFileReferenceFromPath(fullpath, cmtarget, lang, sf);
+    this->CreateXCodeFileReferenceFromPath(fullpath, target, lang, sf);
 
   cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile);
   buildFile->SetComment(fileRef->GetComment());
@@ -752,7 +760,7 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFileFromPath(
 cmXCodeObject*
 cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
                                               cmSourceFile* sf,
-                                              cmTarget& cmtarget)
+                                              cmGeneratorTarget* gtgt)
 {
   // Add flags from target and source file properties.
   std::string flags;
@@ -782,7 +790,7 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
     this->CurrentLocalGenerator->GetSourceFileLanguage(*sf);
 
   cmXCodeObject* buildFile =
-    this->CreateXCodeSourceFileFromPath(sf->GetFullPath(), cmtarget, lang, sf);
+    this->CreateXCodeSourceFileFromPath(sf->GetFullPath(), gtgt, lang, sf);
   cmXCodeObject* fileRef = buildFile->GetObject("fileRef")->GetObject();
 
   cmXCodeObject* settings =
@@ -791,14 +799,15 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
 
   // Is this a resource file in this target? Add it to the resources group...
   //
+
   cmGeneratorTarget::SourceFileFlags tsFlags =
-            this->GetGeneratorTarget(&cmtarget)->GetTargetSourceFileFlags(sf);
+      gtgt->GetTargetSourceFileFlags(sf);
   bool isResource = tsFlags.Type == cmGeneratorTarget::SourceFileTypeResource;
 
   // Is this a "private" or "public" framework header file?
   // Set the ATTRIBUTES attribute appropriately...
   //
-  if(cmtarget.IsFrameworkOnApple())
+  if(gtgt->IsFrameworkOnApple())
     {
     if(tsFlags.Type == cmGeneratorTarget::SourceFileTypePrivateHeader)
       {
@@ -925,11 +934,11 @@ GetSourcecodeValueFromFileExtension(const std::string& _ext,
 cmXCodeObject*
 cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath(
   const std::string &fullpath,
-  cmTarget& cmtarget,
+  cmGeneratorTarget* target,
   const std::string &lang,
   cmSourceFile* sf)
 {
-  std::string key = GetGroupMapKeyFromPath(cmtarget, fullpath);
+  std::string key = GetGroupMapKeyFromPath(target, fullpath);
   cmXCodeObject* fileRef = this->FileRefs[key];
   if(!fileRef)
     {
@@ -1006,13 +1015,13 @@ cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath(
 //----------------------------------------------------------------------------
 cmXCodeObject*
 cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf,
-                                                 cmTarget& cmtarget)
+                                                 cmGeneratorTarget* target)
 {
   std::string lang =
     this->CurrentLocalGenerator->GetSourceFileLanguage(*sf);
 
   return this->CreateXCodeFileReferenceFromPath(
-    sf->GetFullPath(), cmtarget, lang, sf);
+    sf->GetFullPath(), target, lang, sf);
 }
 
 //----------------------------------------------------------------------------
@@ -1038,7 +1047,7 @@ void cmGlobalXCodeGenerator::SetCurrentLocalGenerator(cmLocalGenerator* gen)
   this->CurrentLocalGenerator = gen;
   this->CurrentMakefile = gen->GetMakefile();
   std::string outdir =
-    cmSystemTools::CollapseFullPath(this->CurrentMakefile->
+    cmSystemTools::CollapseFullPath(this->CurrentLocalGenerator->
                                     GetCurrentBinaryDirectory());
   cmSystemTools::SplitPath(outdir.c_str(),
                            this->CurrentOutputDirectoryComponents);
@@ -1085,34 +1094,38 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
                                            targets)
 {
   this->SetCurrentLocalGenerator(gen);
-  cmTargets &tgts = this->CurrentMakefile->GetTargets();
-  typedef std::map<std::string, cmTarget*, cmCompareTargets> cmSortedTargets;
+  std::vector<cmGeneratorTarget*> tgts =
+      this->CurrentLocalGenerator->GetGeneratorTargets();
+  typedef std::map<std::string, cmGeneratorTarget*, cmCompareTargets>
+      cmSortedTargets;
   cmSortedTargets sortedTargets;
-  for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
+  for(std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
+      l != tgts.end(); l++)
     {
-    sortedTargets[l->first] = &l->second;
+    sortedTargets[(*l)->GetName()] = *l;
     }
   for(cmSortedTargets::iterator l = sortedTargets.begin();
       l != sortedTargets.end(); l++)
     {
-    cmTarget& cmtarget = *l->second;
-    cmGeneratorTarget* gtgt = this->GetGeneratorTarget(&cmtarget);
+    cmGeneratorTarget* gtgt = l->second;
+
+    std::string targetName = gtgt->GetName();
 
     // make sure ALL_BUILD, INSTALL, etc are only done once
-    if(this->SpecialTargetEmitted(l->first.c_str()))
+    if(this->SpecialTargetEmitted(targetName.c_str()))
       {
       continue;
       }
 
-    if(cmtarget.GetType() == cmTarget::INTERFACE_LIBRARY)
+    if(gtgt->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
 
-    if(cmtarget.GetType() == cmTarget::UTILITY ||
-       cmtarget.GetType() == cmTarget::GLOBAL_TARGET)
+    if(gtgt->GetType() == cmState::UTILITY ||
+       gtgt->GetType() == cmState::GLOBAL_TARGET)
       {
-      cmXCodeObject* t = this->CreateUtilityTarget(cmtarget);
+      cmXCodeObject* t = this->CreateUtilityTarget(gtgt);
       if (!t)
         {
         return false;
@@ -1140,7 +1153,7 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
       {
       cmXCodeObject* xsf =
         this->CreateXCodeSourceFile(this->CurrentLocalGenerator,
-                                    *i, cmtarget);
+                                    *i, gtgt);
       cmXCodeObject* fr = xsf->GetObject("fileRef");
       cmXCodeObject* filetype =
         fr->GetObject()->GetObject("explicitFileType");
@@ -1191,15 +1204,15 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
         {
         std::string obj = *oi;
         cmXCodeObject* xsf =
-          this->CreateXCodeSourceFileFromPath(obj, cmtarget, "", 0);
+          this->CreateXCodeSourceFileFromPath(obj, gtgt, "", 0);
         externalObjFiles.push_back(xsf);
         }
       }
 
     // some build phases only apply to bundles and/or frameworks
-    bool isFrameworkTarget = cmtarget.IsFrameworkOnApple();
-    bool isBundleTarget = cmtarget.GetPropertyAsBool("MACOSX_BUNDLE");
-    bool isCFBundleTarget = cmtarget.IsCFBundleOnApple();
+    bool isFrameworkTarget = gtgt->IsFrameworkOnApple();
+    bool isBundleTarget = gtgt->GetPropertyAsBool("MACOSX_BUNDLE");
+    bool isCFBundleTarget = gtgt->IsCFBundleOnApple();
 
     cmXCodeObject* buildFiles = 0;
 
@@ -1293,7 +1306,7 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
         copyFilesBuildPhase->AddAttribute("dstSubfolderSpec",
           this->CreateString("6"));
         std::ostringstream ostr;
-        if (cmtarget.IsFrameworkOnApple())
+        if (gtgt->IsFrameworkOnApple())
           {
           // dstPath in frameworks is relative to Versions/<version>
           ostr << mit->first;
@@ -1314,7 +1327,7 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
           {
           cmXCodeObject* xsf =
             this->CreateXCodeSourceFile(this->CurrentLocalGenerator,
-                                        *sfIt, cmtarget);
+                                        *sfIt, gtgt);
           buildFiles->AddObject(xsf);
           }
         contentBuildPhases.push_back(copyFilesBuildPhase);
@@ -1348,9 +1361,9 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
     this->CreateCustomCommands(buildPhases, sourceBuildPhase,
                                headerBuildPhase, resourceBuildPhase,
                                contentBuildPhases,
-                               frameworkBuildPhase, cmtarget);
+                               frameworkBuildPhase, gtgt);
 
-    targets.push_back(this->CreateXCodeTarget(cmtarget, buildPhases));
+    targets.push_back(this->CreateXCodeTarget(gtgt, buildPhases));
     }
   return true;
 }
@@ -1358,26 +1371,31 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
 //----------------------------------------------------------------------------
 void cmGlobalXCodeGenerator::ForceLinkerLanguages()
 {
-  // This makes sure all targets link using the proper language.
-  for(TargetMap::const_iterator
-        ti = this->TotalTargets.begin(); ti != this->TotalTargets.end(); ++ti)
+  for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
     {
-    this->ForceLinkerLanguage(*ti->second);
+    std::vector<cmGeneratorTarget*> tgts =
+        this->LocalGenerators[i]->GetGeneratorTargets();
+    // All targets depend on the build-system check target.
+    for(std::vector<cmGeneratorTarget*>::const_iterator ti = tgts.begin();
+        ti != tgts.end(); ++ti)
+      {
+      // This makes sure all targets link using the proper language.
+      this->ForceLinkerLanguage(*ti);
+      }
     }
 }
 
 //----------------------------------------------------------------------------
-void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmTarget& cmtarget)
+void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmGeneratorTarget* gtgt)
 {
   // This matters only for targets that link.
-  if(cmtarget.GetType() != cmTarget::EXECUTABLE &&
-     cmtarget.GetType() != cmTarget::SHARED_LIBRARY &&
-     cmtarget.GetType() != cmTarget::MODULE_LIBRARY)
+  if(gtgt->GetType() != cmState::EXECUTABLE &&
+     gtgt->GetType() != cmState::SHARED_LIBRARY &&
+     gtgt->GetType() != cmState::MODULE_LIBRARY)
     {
     return;
     }
 
-  cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&cmtarget);
   std::string llang = gtgt->GetLinkerLanguage("NOCONFIG");
   if(llang.empty()) { return; }
 
@@ -1393,11 +1411,11 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmTarget& cmtarget)
   // Add an empty source file to the target that compiles with the
   // linker language.  This should convince Xcode to choose the proper
   // language.
-  cmMakefile* mf = cmtarget.GetMakefile();
-  std::string fname = mf->GetCurrentBinaryDirectory();
+  cmMakefile* mf = gtgt->Target->GetMakefile();
+  std::string fname = gtgt->GetLocalGenerator()->GetCurrentBinaryDirectory();
   fname += cmake::GetCMakeFilesDirectory();
   fname += "/";
-  fname += cmtarget.GetName();
+  fname += gtgt->GetName();
   fname += "-CMakeForceLinker";
   fname += ".";
   fname += cmSystemTools::LowerCase(llang);
@@ -1408,7 +1426,7 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmTarget& cmtarget)
   if(cmSourceFile* sf = mf->GetOrCreateSource(fname.c_str()))
     {
     sf->SetProperty("LANGUAGE", llang.c_str());
-    cmtarget.AddSource(fname);
+    gtgt->AddSource(fname);
     }
 }
 
@@ -1416,7 +1434,7 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmTarget& cmtarget)
 bool cmGlobalXCodeGenerator::IsHeaderFile(cmSourceFile* sf)
 {
   const std::vector<std::string>& hdrExts =
-    this->CurrentMakefile->GetHeaderExtensions();
+    this->CMakeInstance->GetHeaderExtensions();
   return (std::find(hdrExts.begin(), hdrExts.end(), sf->GetExtension()) !=
           hdrExts.end());
 }
@@ -1425,7 +1443,7 @@ bool cmGlobalXCodeGenerator::IsHeaderFile(cmSourceFile* sf)
 cmXCodeObject*
 cmGlobalXCodeGenerator::CreateBuildPhase(const char* name,
                                          const char* name2,
-                                         cmTarget& cmtarget,
+                                         cmGeneratorTarget* target,
                                          const std::vector<cmCustomCommand>&
                                          commands)
 {
@@ -1445,7 +1463,7 @@ cmGlobalXCodeGenerator::CreateBuildPhase(const char* name,
                            this->CreateString("0"));
   buildPhase->AddAttribute("shellPath",
                            this->CreateString("/bin/sh"));
-  this->AddCommandsToBuildPhase(buildPhase, cmtarget, commands,
+  this->AddCommandsToBuildPhase(buildPhase, target, commands,
                                 name2);
   return buildPhase;
 }
@@ -1462,17 +1480,17 @@ void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
                                                   contentBuildPhases,
                                                   cmXCodeObject*
                                                   frameworkBuildPhase,
-                                                  cmTarget& cmtarget)
+                                                  cmGeneratorTarget* gtgt)
 {
   std::vector<cmCustomCommand> const & prebuild
-    = cmtarget.GetPreBuildCommands();
+    = gtgt->GetPreBuildCommands();
   std::vector<cmCustomCommand> const & prelink
-    = cmtarget.GetPreLinkCommands();
+    = gtgt->GetPreLinkCommands();
   std::vector<cmCustomCommand> postbuild
-    = cmtarget.GetPostBuildCommands();
+    = gtgt->GetPostBuildCommands();
 
-  if(cmtarget.GetType() == cmTarget::SHARED_LIBRARY &&
-    !cmtarget.IsFrameworkOnApple())
+  if(gtgt->GetType() == cmState::SHARED_LIBRARY &&
+    !gtgt->IsFrameworkOnApple())
     {
     cmCustomCommandLines cmd;
     cmd.resize(1);
@@ -1480,13 +1498,13 @@ void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
     cmd[0].push_back("-E");
     cmd[0].push_back("cmake_symlink_library");
     std::string str_file = "$<TARGET_FILE:";
-    str_file += cmtarget.GetName();
+    str_file += gtgt->GetName();
     str_file += ">";
     std::string str_so_file = "$<TARGET_SONAME_FILE:";
-    str_so_file += cmtarget.GetName();
+    str_so_file += gtgt->GetName();
     str_so_file += ">";
     std::string str_link_file = "$<TARGET_LINKER_FILE:";
-    str_link_file += cmtarget.GetName();
+    str_link_file += gtgt->GetName();
     str_link_file += ">";
     cmd[0].push_back(str_file);
     cmd[0].push_back(str_so_file);
@@ -1504,7 +1522,6 @@ void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
     }
 
   std::vector<cmSourceFile*> classes;
-  cmGeneratorTarget* gtgt = this->GetGeneratorTarget(&cmtarget);
   if (!gtgt->GetConfigCommonSourceFiles(classes))
     {
     return;
@@ -1523,19 +1540,19 @@ void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
   cmXCodeObject* cmakeRulesBuildPhase =
     this->CreateBuildPhase("CMake Rules",
                            "cmakeRulesBuildPhase",
-                           cmtarget, commands);
+                           gtgt, commands);
   // create prebuild phase
   cmXCodeObject* preBuildPhase =
     this->CreateBuildPhase("CMake PreBuild Rules", "preBuildCommands",
-                           cmtarget, prebuild);
+                           gtgt, prebuild);
   // create prelink phase
   cmXCodeObject* preLinkPhase =
     this->CreateBuildPhase("CMake PreLink Rules", "preLinkCommands",
-                           cmtarget, prelink);
+                           gtgt, prelink);
   // create postbuild phase
   cmXCodeObject* postBuildPhase =
     this->CreateBuildPhase("CMake PostBuild Rules", "postBuildPhase",
-                           cmtarget, postbuild);
+                           gtgt, postbuild);
 
   // The order here is the order they will be built in.
   // The order "headers, resources, sources" mimics a native project generated
@@ -1616,19 +1633,92 @@ std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag,
 }
 
 //----------------------------------------------------------------------------
+// This function removes each matching occurrence of the expression and
+// returns the last one (i.e., the dominant flag in GCC)
+std::string cmGlobalXCodeGenerator::ExtractFlagRegex(const char* exp,
+                                                     int matchIndex,
+                                                     std::string& flags)
+{
+  std::string retFlag;
+
+  cmsys::RegularExpression regex(exp);
+  assert(regex.is_valid());
+  if(!regex.is_valid())
+    {
+    return retFlag;
+    }
+
+  std::string::size_type offset = 0;
+
+  while(regex.find(flags.c_str() + offset))
+    {
+    const std::string::size_type startPos = offset + regex.start(matchIndex);
+    const std::string::size_type endPos = offset + regex.end(matchIndex);
+    const std::string::size_type size = endPos - startPos;
+
+    offset = startPos + 1;
+
+    retFlag.assign(flags, startPos, size);
+    flags.replace(startPos, size, size, ' ');
+    }
+
+  return retFlag;
+}
+
+ //----------------------------------------------------------------------------
+// This function strips off Xcode attributes that do not target the current
+// configuration
+void
+cmGlobalXCodeGenerator
+::FilterConfigurationAttribute(std::string const& configName,
+                               std::string& attribute)
+{
+  // Handle [variant=<config>] condition explicitly here.
+  std::string::size_type beginVariant = attribute.find("[variant=");
+  if (beginVariant == std::string::npos)
+    {
+    // There is no variant in this attribute.
+    return;
+    }
+
+  std::string::size_type endVariant = attribute.find("]", beginVariant+9);
+  if (endVariant == std::string::npos)
+    {
+    // There is no terminating bracket.
+    return;
+    }
+
+  // Compare the variant to the configuration.
+  std::string variant =
+    attribute.substr(beginVariant+9, endVariant-beginVariant-9);
+  if (variant == configName)
+    {
+    // The variant matches the configuration so use this
+    // attribute but drop the [variant=<config>] condition.
+    attribute.erase(beginVariant, endVariant-beginVariant+1);
+    }
+  else
+    {
+    // The variant does not match the configuration so
+    // do not use this attribute.
+    attribute.clear();
+    }
+}
+
+//----------------------------------------------------------------------------
 void
 cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase,
-                                                cmTarget& target,
+                                                cmGeneratorTarget* target,
                                                 std::vector<cmCustomCommand>
                                                 const & commands,
                                                 const char* name)
 {
-  std::string dir = this->CurrentMakefile->GetCurrentBinaryDirectory();
+  std::string dir = this->CurrentLocalGenerator->GetCurrentBinaryDirectory();
   dir += "/CMakeScripts";
   cmSystemTools::MakeDirectory(dir.c_str());
   std::string makefile = dir;
   makefile += "/";
-  makefile += target.GetName();
+  makefile += target->GetName();
   makefile += "_";
   makefile += name;
   makefile += ".make";
@@ -1644,15 +1734,14 @@ cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase,
                                     currentConfig->c_str());
     }
 
-  std::string cdir = this->CurrentMakefile->GetCurrentBinaryDirectory();
-  cdir = this->ConvertToRelativeForXCode(cdir.c_str());
+  std::string cdir = this->CurrentLocalGenerator->GetCurrentBinaryDirectory();
+  cdir = this->ConvertToRelativeForMake(cdir.c_str());
   std::string makecmd = "make -C ";
   makecmd += cdir;
   makecmd += " -f ";
   makecmd += this->ConvertToRelativeForMake(
                                           (makefile+"$CONFIGURATION").c_str());
   makecmd += " all";
-  cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
   buildphase->AddAttribute("shellScript",
                            this->CreateString(makecmd.c_str()));
   buildphase->AddAttribute("showEnvVarsInLog",
@@ -1662,7 +1751,7 @@ cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase,
 //----------------------------------------------------------------------------
 void  cmGlobalXCodeGenerator
 ::CreateCustomRulesMakefile(const char* makefileBasename,
-                            cmTarget& target,
+                            cmGeneratorTarget* target,
                             std::vector<cmCustomCommand>
                             const & commands,
                             const std::string& configName)
@@ -1679,7 +1768,7 @@ void  cmGlobalXCodeGenerator
     }
   makefileStream.SetCopyIfDifferent(true);
   makefileStream << "# Generated by CMake, DO NOT EDIT\n";
-  makefileStream << "# Custom rules for " << target.GetName() << "\n";
+  makefileStream << "# Custom rules for " << target->GetName() << "\n";
 
   // disable the implicit rules
   makefileStream << ".SUFFIXES: " << "\n";
@@ -1708,7 +1797,7 @@ void  cmGlobalXCodeGenerator
         {
         std::ostringstream str;
         str << "_buildpart_" << count++ ;
-        tname[&ccg.GetCC()] = std::string(target.GetName()) + str.str();
+        tname[&ccg.GetCC()] = std::string(target->GetName()) + str.str();
         makefileStream << "\\\n\t" << tname[&ccg.GetCC()];
         }
       }
@@ -1786,26 +1875,25 @@ void  cmGlobalXCodeGenerator
 }
 
 //----------------------------------------------------------------------------
-void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
+void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
                                                 cmXCodeObject* buildSettings,
                                                 const std::string& configName)
 {
-  if(target.GetType() == cmTarget::INTERFACE_LIBRARY)
+  if(gtgt->GetType() == cmState::INTERFACE_LIBRARY)
     {
     return;
     }
 
   std::string defFlags;
-  bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
-                 (target.GetType() == cmTarget::MODULE_LIBRARY));
-  bool binary = ((target.GetType() == cmTarget::OBJECT_LIBRARY) ||
-                 (target.GetType() == cmTarget::STATIC_LIBRARY) ||
-                 (target.GetType() == cmTarget::EXECUTABLE) ||
+  bool shared = ((gtgt->GetType() == cmState::SHARED_LIBRARY) ||
+                 (gtgt->GetType() == cmState::MODULE_LIBRARY));
+  bool binary = ((gtgt->GetType() == cmState::OBJECT_LIBRARY) ||
+                 (gtgt->GetType() == cmState::STATIC_LIBRARY) ||
+                 (gtgt->GetType() == cmState::EXECUTABLE) ||
                  shared);
 
   // Compute the compilation flags for each language.
   std::set<std::string> languages;
-  cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&target);
   gtgt->GetLanguages(languages, configName);
   std::map<std::string, std::string> cflags;
   for (std::set<std::string>::iterator li = languages.begin();
@@ -1818,14 +1906,14 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
     this->CurrentLocalGenerator->AddLanguageFlags(flags, lang, configName);
 
     // Add shared-library flags if needed.
-    this->CurrentLocalGenerator->AddCMP0018Flags(flags, &target,
+    this->CurrentLocalGenerator->AddCMP0018Flags(flags, gtgt,
                                                  lang, configName);
 
-    this->CurrentLocalGenerator->AddVisibilityPresetFlags(flags, &target,
+    this->CurrentLocalGenerator->AddVisibilityPresetFlags(flags, gtgt,
                                                    lang);
 
     this->CurrentLocalGenerator->
-      AddCompileOptions(flags, &target, lang, configName);
+      AddCompileOptions(flags, gtgt, lang, configName);
     }
 
   std::string llang = gtgt->GetLinkerLanguage(configName);
@@ -1833,7 +1921,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
     {
     cmSystemTools::Error
       ("CMake can not determine linker language for target: ",
-       target.GetName().c_str());
+       gtgt->GetName().c_str());
     return;
     }
 
@@ -1849,7 +1937,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
     this->AppendDefines(ppDefs,
       "CMAKE_INTDIR=\"$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)\"");
     }
-  if(const char* exportMacro = target.GetExportMacro())
+  if(const char* exportMacro = gtgt->GetExportMacro())
     {
     // Add the export symbol definition for shared library objects.
     this->AppendDefines(ppDefs, exportMacro);
@@ -1862,15 +1950,15 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
 
   std::string extraLinkOptionsVar;
   std::string extraLinkOptions;
-  if(target.GetType() == cmTarget::EXECUTABLE)
+  if(gtgt->GetType() == cmState::EXECUTABLE)
     {
     extraLinkOptionsVar = "CMAKE_EXE_LINKER_FLAGS";
     }
-  else if(target.GetType() == cmTarget::SHARED_LIBRARY)
+  else if(gtgt->GetType() == cmState::SHARED_LIBRARY)
     {
     extraLinkOptionsVar = "CMAKE_SHARED_LINKER_FLAGS";
     }
-  else if(target.GetType() == cmTarget::MODULE_LIBRARY)
+  else if(gtgt->GetType() == cmState::MODULE_LIBRARY)
     {
     extraLinkOptionsVar = "CMAKE_MODULE_LINKER_FLAGS";
     }
@@ -1882,17 +1970,17 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
                                configName);
     }
 
-  if(target.GetType() == cmTarget::OBJECT_LIBRARY ||
-     target.GetType() == cmTarget::STATIC_LIBRARY)
+  if(gtgt->GetType() == cmState::OBJECT_LIBRARY ||
+     gtgt->GetType() == cmState::STATIC_LIBRARY)
     {
     this->CurrentLocalGenerator
       ->GetStaticLibraryFlags(extraLinkOptions,
                               cmSystemTools::UpperCase(configName),
-                              &target);
+                              gtgt);
     }
   else
     {
-    const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
+    const char* targetLinkFlags = gtgt->GetProperty("LINK_FLAGS");
     if(targetLinkFlags)
       {
       this->CurrentLocalGenerator->
@@ -1902,7 +1990,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
       {
       std::string linkFlagsVar = "LINK_FLAGS_";
       linkFlagsVar += cmSystemTools::UpperCase(configName);
-      if(const char* linkFlags = target.GetProperty(linkFlagsVar.c_str()))
+      if(const char* linkFlags = gtgt->GetProperty(linkFlagsVar.c_str()))
         {
         this->CurrentLocalGenerator->
           AppendFlags(extraLinkOptions, linkFlags);
@@ -1945,9 +2033,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
   std::string pnsuffix;
   gtgt->GetFullNameComponents(pnprefix, pnbase, pnsuffix, configName);
 
-  const char* version = target.GetProperty("VERSION");
-  const char* soversion = target.GetProperty("SOVERSION");
-  if(!gtgt->HasSOName(configName) || target.IsFrameworkOnApple())
+  const char* version = gtgt->GetProperty("VERSION");
+  const char* soversion = gtgt->GetProperty("SOVERSION");
+  if(!gtgt->HasSOName(configName) || gtgt->IsFrameworkOnApple())
     {
     version = 0;
     soversion = 0;
@@ -1972,17 +2060,17 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
     }
 
   // Set attributes to specify the proper name for the target.
-  std::string pndir = this->CurrentMakefile->GetCurrentBinaryDirectory();
-  if(target.GetType() == cmTarget::STATIC_LIBRARY ||
-     target.GetType() == cmTarget::SHARED_LIBRARY ||
-     target.GetType() == cmTarget::MODULE_LIBRARY ||
-     target.GetType() == cmTarget::EXECUTABLE)
+  std::string pndir = this->CurrentLocalGenerator->GetCurrentBinaryDirectory();
+  if(gtgt->GetType() == cmState::STATIC_LIBRARY ||
+     gtgt->GetType() == cmState::SHARED_LIBRARY ||
+     gtgt->GetType() == cmState::MODULE_LIBRARY ||
+     gtgt->GetType() == cmState::EXECUTABLE)
     {
     if(this->XcodeVersion >= 21)
       {
-      if(!target.UsesDefaultOutputDir(configName, false))
+      if(!gtgt->UsesDefaultOutputDir(configName, false))
         {
-        std::string pncdir = target.GetDirectory(configName);
+        std::string pncdir = gtgt->GetDirectory(configName);
         buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR",
                                     this->CreateString(pncdir.c_str()));
         }
@@ -1991,10 +2079,10 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
       {
       buildSettings->AddAttribute("OBJROOT",
                                   this->CreateString(pndir.c_str()));
-      pndir = target.GetDirectory(configName);
+      pndir = gtgt->GetDirectory(configName);
       }
 
-    if(target.IsFrameworkOnApple() || target.IsCFBundleOnApple())
+    if(gtgt->IsFrameworkOnApple() || gtgt->IsCFBundleOnApple())
       {
       pnprefix = "";
       }
@@ -2004,16 +2092,16 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
     buildSettings->AddAttribute("EXECUTABLE_SUFFIX",
                                 this->CreateString(pnsuffix.c_str()));
     }
-  else if(target.GetType() == cmTarget::OBJECT_LIBRARY)
+  else if(gtgt->GetType() == cmState::OBJECT_LIBRARY)
     {
     pnprefix = "lib";
-    pnbase = target.GetName();
+    pnbase = gtgt->GetName();
     pnsuffix = ".a";
 
     if(this->XcodeVersion >= 21)
       {
       std::string pncdir = this->GetObjectsNormalDirectory(
-        this->CurrentProject, configName, &target);
+        this->CurrentProject, configName, gtgt);
       buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR",
                                   this->CreateString(pncdir.c_str()));
       }
@@ -2022,7 +2110,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
       buildSettings->AddAttribute("OBJROOT",
                                   this->CreateString(pndir.c_str()));
       pndir = this->GetObjectsNormalDirectory(
-        this->CurrentProject, configName, &target);
+        this->CurrentProject, configName, gtgt);
       }
     }
 
@@ -2033,21 +2121,21 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
                               this->CreateString(pndir.c_str()));
 
   // Handle settings for each target type.
-  switch(target.GetType())
+  switch(gtgt->GetType())
     {
-    case cmTarget::OBJECT_LIBRARY:
-    case cmTarget::STATIC_LIBRARY:
+    case cmState::OBJECT_LIBRARY:
+    case cmState::STATIC_LIBRARY:
     {
     buildSettings->AddAttribute("LIBRARY_STYLE",
                                 this->CreateString("STATIC"));
     break;
     }
 
-    case cmTarget::MODULE_LIBRARY:
+    case cmState::MODULE_LIBRARY:
     {
     buildSettings->AddAttribute("LIBRARY_STYLE",
                                 this->CreateString("BUNDLE"));
-    if (target.IsCFBundleOnApple())
+    if (gtgt->IsCFBundleOnApple())
       {
       // It turns out that a BUNDLE is basically the same
       // in many ways as an application bundle, as far as
@@ -2060,18 +2148,16 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
         extraLinkOptions += " ";
         extraLinkOptions += createFlags;
         }
-      std::string plist = this->ComputeInfoPListLocation(target);
+      std::string plist = this->ComputeInfoPListLocation(gtgt);
       // Xcode will create the final version of Info.plist at build time,
       // so let it replace the cfbundle name. This avoids creating
       // a per-configuration Info.plist file. The cfbundle plist
       // is very similar to the application bundle plist
       this->CurrentLocalGenerator
-        ->GenerateAppleInfoPList(&target, "$(EXECUTABLE_NAME)",
+        ->GenerateAppleInfoPList(gtgt, "$(EXECUTABLE_NAME)",
                                  plist.c_str());
-      std::string path =
-        this->ConvertToRelativeForXCode(plist.c_str());
       buildSettings->AddAttribute("INFOPLIST_FILE",
-                                  this->CreateString(path.c_str()));
+                                  this->CreateString(plist));
       }
     else if(this->XcodeVersion >= 22)
       {
@@ -2102,25 +2188,23 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
       }
     break;
     }
-    case cmTarget::SHARED_LIBRARY:
+    case cmState::SHARED_LIBRARY:
     {
-    if(target.GetPropertyAsBool("FRAMEWORK"))
+    if(gtgt->GetPropertyAsBool("FRAMEWORK"))
       {
-      std::string fw_version = target.GetFrameworkVersion();
+      std::string fw_version = gtgt->GetFrameworkVersion();
       buildSettings->AddAttribute("FRAMEWORK_VERSION",
                                   this->CreateString(fw_version.c_str()));
 
-      std::string plist = this->ComputeInfoPListLocation(target);
+      std::string plist = this->ComputeInfoPListLocation(gtgt);
       // Xcode will create the final version of Info.plist at build time,
       // so let it replace the framework name. This avoids creating
       // a per-configuration Info.plist file.
       this->CurrentLocalGenerator
-        ->GenerateFrameworkInfoPList(&target, "$(EXECUTABLE_NAME)",
+        ->GenerateFrameworkInfoPList(gtgt, "$(EXECUTABLE_NAME)",
                                      plist.c_str());
-      std::string path =
-        this->ConvertToRelativeForXCode(plist.c_str());
       buildSettings->AddAttribute("INFOPLIST_FILE",
-                                  this->CreateString(path.c_str()));
+                                  this->CreateString(plist));
       }
     else
       {
@@ -2139,7 +2223,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
                                 this->CreateString("DYNAMIC"));
     break;
     }
-    case cmTarget::EXECUTABLE:
+    case cmState::EXECUTABLE:
     {
     // Add the flags to create an executable.
     std::string createFlags =
@@ -2151,19 +2235,17 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
       }
 
     // Handle bundles and normal executables separately.
-    if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
+    if(gtgt->GetPropertyAsBool("MACOSX_BUNDLE"))
       {
-      std::string plist = this->ComputeInfoPListLocation(target);
+      std::string plist = this->ComputeInfoPListLocation(gtgt);
       // Xcode will create the final version of Info.plist at build time,
       // so let it replace the executable name.  This avoids creating
       // a per-configuration Info.plist file.
       this->CurrentLocalGenerator
-        ->GenerateAppleInfoPList(&target, "$(EXECUTABLE_NAME)",
+        ->GenerateAppleInfoPList(gtgt, "$(EXECUTABLE_NAME)",
                                  plist.c_str());
-      std::string path =
-        this->ConvertToRelativeForXCode(plist.c_str());
       buildSettings->AddAttribute("INFOPLIST_FILE",
-                                  this->CreateString(path.c_str()));
+                                  this->CreateString(plist));
 
       }
     }
@@ -2231,9 +2313,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
   bool same_gflags = true;
   std::map<std::string, std::string> gflags;
   std::string const* last_gflag = 0;
-  char optLevel[2];
-  optLevel[0] = '0';
-  optLevel[1] = 0;
+  std::string optLevel = "0";
 
   // Minimal map of flags to build settings.
   for (std::set<std::string>::iterator li = languages.begin();
@@ -2241,14 +2321,15 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
     {
     std::string& flags = cflags[*li];
     std::string& gflag = gflags[*li];
-    std::string oflag = this->ExtractFlag("-O", flags);
-    if(oflag.size() == 3)
+    std::string oflag =
+      this->ExtractFlagRegex("(^| )(-Ofast|-Os|-O[0-9]*)( |$)", 2, flags);
+    if(oflag.size() == 2)
       {
-      optLevel[0] = oflag[2];
+      optLevel = "1";
       }
-    if(oflag.size() == 2)
+    else if(oflag.size() > 2)
       {
-      optLevel[0] = '1';
+      optLevel = oflag.substr(2);
       }
     gflag = this->ExtractFlag("-g", flags);
     // put back gdwarf-2 if used since there is no way
@@ -2316,7 +2397,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
 
   // Add Fortran source format attribute if property is set.
   const char* format = 0;
-  const char* tgtfmt = target.GetProperty("Fortran_FORMAT");
+  const char* tgtfmt = gtgt->GetProperty("Fortran_FORMAT");
   switch(this->CurrentLocalGenerator->GetFortranFormat(tgtfmt))
     {
     case cmLocalGenerator::FortranFormatFixed: format = "fixed"; break;
@@ -2331,7 +2412,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
 
   // Create the INSTALL_PATH attribute.
   std::string install_name_dir;
-  if(target.GetType() == cmTarget::SHARED_LIBRARY)
+  if(gtgt->GetType() == cmState::SHARED_LIBRARY)
     {
     // Get the install_name directory for the build tree.
     install_name_dir = gtgt->GetInstallNameDirForBuildTree(configName);
@@ -2393,7 +2474,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
       }
     }
 
-  buildSettings->AddAttribute(this->GetTargetLinkFlagsVar(target),
+  buildSettings->AddAttribute(this->GetTargetLinkFlagsVar(gtgt),
                               this->CreateString(extraLinkOptions.c_str()));
   buildSettings->AddAttribute("OTHER_REZFLAGS",
                               this->CreateString(""));
@@ -2419,14 +2500,14 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
     }
 
   // Runtime version information.
-  if(target.GetType() == cmTarget::SHARED_LIBRARY)
+  if(gtgt->GetType() == cmState::SHARED_LIBRARY)
     {
     int major;
     int minor;
     int patch;
 
     // VERSION -> current_version
-    target.GetTargetVersion(false, major, minor, patch);
+    gtgt->GetTargetVersion(false, major, minor, patch);
     std::ostringstream v;
 
     // Xcode always wants at least 1.0.0 or nothing
@@ -2438,7 +2519,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
                                 this->CreateString(v.str().c_str()));
 
     // SOVERSION -> compatibility_version
-    target.GetTargetVersion(true, major, minor, patch);
+    gtgt->GetTargetVersion(true, major, minor, patch);
     std::ostringstream vso;
 
     // Xcode always wants at least 1.0.0 or nothing
@@ -2452,45 +2533,19 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
   // put this last so it can override existing settings
   // Convert "XCODE_ATTRIBUTE_*" properties directly.
   {
-  cmPropertyMap const& props = target.GetProperties();
-  for(cmPropertyMap::const_iterator i = props.begin();
+  std::vector<std::string> const& props = gtgt->GetPropertyKeys();
+  for(std::vector<std::string>::const_iterator i = props.begin();
       i != props.end(); ++i)
     {
-    if(i->first.find("XCODE_ATTRIBUTE_") == 0)
+    if(i->find("XCODE_ATTRIBUTE_") == 0)
       {
-      std::string attribute = i->first.substr(16);
-      // Handle [variant=<config>] condition explicitly here.
-      std::string::size_type beginVariant =
-        attribute.find("[variant=");
-      if (beginVariant != std::string::npos)
-        {
-        std::string::size_type endVariant =
-          attribute.find("]", beginVariant+9);
-        if (endVariant != std::string::npos)
-          {
-          // Compare the variant to the configuration.
-          std::string variant =
-            attribute.substr(beginVariant+9, endVariant-beginVariant-9);
-          if (variant == configName)
-            {
-            // The variant matches the configuration so use this
-            // attribute but drop the [variant=<config>] condition.
-            attribute.erase(beginVariant, endVariant-beginVariant+1);
-            }
-          else
-            {
-            // The variant does not match the configuration so
-            // do not use this attribute.
-            attribute.clear();
-            }
-          }
-        }
-
+      std::string attribute = i->substr(16);
+      this->FilterConfigurationAttribute(configName, attribute);
       if (!attribute.empty())
         {
         cmGeneratorExpression ge;
-        std::string processed = ge.Parse(i->second.GetValue())
-          ->Evaluate(this->CurrentMakefile, configName);
+        std::string processed = ge.Parse(gtgt->GetProperty(*i))
+          ->Evaluate(this->CurrentLocalGenerator, configName);
         buildSettings->AddAttribute(attribute.c_str(),
                                     this->CreateString(processed));
         }
@@ -2501,7 +2556,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
 
 //----------------------------------------------------------------------------
 cmXCodeObject*
-cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
+cmGlobalXCodeGenerator::CreateUtilityTarget(cmGeneratorTarget* gtgt)
 {
   cmXCodeObject* shellBuildPhase =
     this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
@@ -2525,16 +2580,16 @@ cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
 
   cmXCodeObject* target =
     this->CreateObject(cmXCodeObject::PBXAggregateTarget);
-  target->SetComment(cmtarget.GetName().c_str());
+  target->SetComment(gtgt->GetName().c_str());
   cmXCodeObject* buildPhases =
     this->CreateObject(cmXCodeObject::OBJECT_LIST);
   std::vector<cmXCodeObject*> emptyContentVector;
   this->CreateCustomCommands(buildPhases, 0, 0, 0, emptyContentVector, 0,
-                             cmtarget);
+                             gtgt);
   target->AddAttribute("buildPhases", buildPhases);
   if(this->XcodeVersion > 20)
     {
-    this->AddConfigurations(target, cmtarget);
+    this->AddConfigurations(target, gtgt);
     }
   else
     {
@@ -2542,22 +2597,21 @@ cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
       this->CurrentMakefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
     cmXCodeObject* buildSettings =
       this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
-    this->CreateBuildSettings(cmtarget, buildSettings, theConfig);
+    this->CreateBuildSettings(gtgt, buildSettings, theConfig);
     target->AddAttribute("buildSettings", buildSettings);
     }
   cmXCodeObject* dependencies =
     this->CreateObject(cmXCodeObject::OBJECT_LIST);
   target->AddAttribute("dependencies", dependencies);
-  target->AddAttribute("name", this->CreateString(cmtarget.GetName()));
-  target->AddAttribute("productName",this->CreateString(cmtarget.GetName()));
-  target->SetTarget(&cmtarget);
-  this->XCodeObjectMap[&cmtarget] = target;
+  target->AddAttribute("name", this->CreateString(gtgt->GetName()));
+  target->AddAttribute("productName",this->CreateString(gtgt->GetName()));
+  target->SetTarget(gtgt);
+  this->XCodeObjectMap[gtgt] = target;
 
   // Add source files without build rules for editing convenience.
-  if(cmtarget.GetType() == cmTarget::UTILITY)
+  if(gtgt->GetType() == cmState::UTILITY)
     {
     std::vector<cmSourceFile*> sources;
-    cmGeneratorTarget* gtgt = this->GetGeneratorTarget(&cmtarget);
     if (!gtgt->GetConfigCommonSourceFiles(sources))
       {
       return 0;
@@ -2568,20 +2622,20 @@ cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
       {
       if(!(*i)->GetPropertyAsBool("GENERATED"))
         {
-        this->CreateXCodeFileReference(*i, cmtarget);
+        this->CreateXCodeFileReference(*i, gtgt);
         }
       }
     }
 
   target->SetId(this->GetOrCreateId(
-    cmtarget.GetName(), target->GetId()).c_str());
+    gtgt->GetName(), target->GetId()).c_str());
 
   return target;
 }
 
 //----------------------------------------------------------------------------
 std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
-                                                      cmTarget& cmtarget)
+                                                      cmGeneratorTarget* gtgt)
 {
   std::string configTypes =
     this->CurrentMakefile->GetRequiredDefinition("CMAKE_CONFIGURATION_TYPES");
@@ -2597,7 +2651,7 @@ std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
   std::string comment = "Build configuration list for ";
   comment += cmXCodeObject::PBXTypeNames[target->GetIsA()];
   comment += " \"";
-  comment += cmtarget.GetName();
+  comment += gtgt->GetName();
   comment += "\"";
   configlist->SetComment(comment.c_str());
   target->AddAttribute("buildConfigurationList",
@@ -2609,7 +2663,7 @@ std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
     buildConfigurations->AddObject(config);
     cmXCodeObject* buildSettings =
       this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
-    this->CreateBuildSettings(cmtarget, buildSettings,
+    this->CreateBuildSettings(gtgt, buildSettings,
                               configVector[i].c_str());
     config->AddAttribute("name", this->CreateString(configVector[i].c_str()));
     config->SetComment(configVector[i].c_str());
@@ -2627,12 +2681,12 @@ std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
 }
 
 //----------------------------------------------------------------------------
-const char*
-cmGlobalXCodeGenerator::GetTargetLinkFlagsVar(cmTarget const& cmtarget) const
+const char* cmGlobalXCodeGenerator::GetTargetLinkFlagsVar(
+    cmGeneratorTarget const* target) const
 {
   if(this->XcodeVersion >= 60 &&
-     (cmtarget.GetType() == cmTarget::STATIC_LIBRARY ||
-      cmtarget.GetType() == cmTarget::OBJECT_LIBRARY))
+     (target->GetType() == cmState::STATIC_LIBRARY ||
+      target->GetType() == cmState::OBJECT_LIBRARY))
     {
     return "OTHER_LIBTOOLFLAGS";
     }
@@ -2643,25 +2697,26 @@ cmGlobalXCodeGenerator::GetTargetLinkFlagsVar(cmTarget const& cmtarget) const
 }
 
 //----------------------------------------------------------------------------
-const char* cmGlobalXCodeGenerator::GetTargetFileType(cmTarget& cmtarget)
+const char* cmGlobalXCodeGenerator::GetTargetFileType(
+    cmGeneratorTarget* target)
 {
-  switch(cmtarget.GetType())
+  switch(target->GetType())
     {
-    case cmTarget::OBJECT_LIBRARY:
-    case cmTarget::STATIC_LIBRARY:
+    case cmState::OBJECT_LIBRARY:
+    case cmState::STATIC_LIBRARY:
       return "archive.ar";
-    case cmTarget::MODULE_LIBRARY:
-      if (cmtarget.IsXCTestOnApple())
+    case cmState::MODULE_LIBRARY:
+      if (target->IsXCTestOnApple())
         return "wrapper.cfbundle";
-      else if (cmtarget.IsCFBundleOnApple())
+      else if (target->IsCFBundleOnApple())
         return "wrapper.plug-in";
       else
         return ((this->XcodeVersion >= 22)?
               "compiled.mach-o.executable" : "compiled.mach-o.dylib");
-    case cmTarget::SHARED_LIBRARY:
-      return (cmtarget.GetPropertyAsBool("FRAMEWORK")?
+    case cmState::SHARED_LIBRARY:
+      return (target->GetPropertyAsBool("FRAMEWORK")?
               "wrapper.framework" : "compiled.mach-o.dylib");
-    case cmTarget::EXECUTABLE:
+    case cmState::EXECUTABLE:
       return "compiled.mach-o.executable";
     default: break;
     }
@@ -2669,28 +2724,29 @@ const char* cmGlobalXCodeGenerator::GetTargetFileType(cmTarget& cmtarget)
 }
 
 //----------------------------------------------------------------------------
-const char* cmGlobalXCodeGenerator::GetTargetProductType(cmTarget& cmtarget)
+const char* cmGlobalXCodeGenerator::GetTargetProductType(
+    cmGeneratorTarget* target)
 {
-  switch(cmtarget.GetType())
+  switch(target->GetType())
     {
-    case cmTarget::OBJECT_LIBRARY:
-    case cmTarget::STATIC_LIBRARY:
+    case cmState::OBJECT_LIBRARY:
+    case cmState::STATIC_LIBRARY:
       return "com.apple.product-type.library.static";
-    case cmTarget::MODULE_LIBRARY:
-      if (cmtarget.IsXCTestOnApple())
+    case cmState::MODULE_LIBRARY:
+      if (target->IsXCTestOnApple())
         return "com.apple.product-type.bundle.unit-test";
-      else if (cmtarget.IsCFBundleOnApple())
+      else if (target->IsCFBundleOnApple())
         return "com.apple.product-type.bundle";
       else
         return ((this->XcodeVersion >= 22)?
                 "com.apple.product-type.tool" :
                 "com.apple.product-type.library.dynamic");
-    case cmTarget::SHARED_LIBRARY:
-      return (cmtarget.GetPropertyAsBool("FRAMEWORK")?
+    case cmState::SHARED_LIBRARY:
+      return (target->GetPropertyAsBool("FRAMEWORK")?
               "com.apple.product-type.framework" :
               "com.apple.product-type.library.dynamic");
-    case cmTarget::EXECUTABLE:
-      return (cmtarget.GetPropertyAsBool("MACOSX_BUNDLE")?
+    case cmState::EXECUTABLE:
+      return (target->GetPropertyAsBool("MACOSX_BUNDLE")?
               "com.apple.product-type.application" :
               "com.apple.product-type.tool");
     default: break;
@@ -2700,10 +2756,10 @@ const char* cmGlobalXCodeGenerator::GetTargetProductType(cmTarget& cmtarget)
 
 //----------------------------------------------------------------------------
 cmXCodeObject*
-cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
+cmGlobalXCodeGenerator::CreateXCodeTarget(cmGeneratorTarget* gtgt,
                                           cmXCodeObject* buildPhases)
 {
-  if(cmtarget.GetType() == cmTarget::INTERFACE_LIBRARY)
+  if(gtgt->GetType() == cmState::INTERFACE_LIBRARY)
     {
     return 0;
     }
@@ -2715,67 +2771,67 @@ cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
   std::string defConfig;
   if(this->XcodeVersion > 20)
     {
-    defConfig = this->AddConfigurations(target, cmtarget);
+    defConfig = this->AddConfigurations(target, gtgt);
     }
   else
     {
     cmXCodeObject* buildSettings =
       this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
     defConfig = this->CurrentMakefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
-    this->CreateBuildSettings(cmtarget, buildSettings, defConfig.c_str());
+    this->CreateBuildSettings(gtgt, buildSettings, defConfig.c_str());
     target->AddAttribute("buildSettings", buildSettings);
     }
   cmXCodeObject* dependencies =
     this->CreateObject(cmXCodeObject::OBJECT_LIST);
   target->AddAttribute("dependencies", dependencies);
-  target->AddAttribute("name", this->CreateString(cmtarget.GetName()));
-  target->AddAttribute("productName",this->CreateString(cmtarget.GetName()));
+  target->AddAttribute("name", this->CreateString(gtgt->GetName()));
+  target->AddAttribute("productName",this->CreateString(gtgt->GetName()));
 
   cmXCodeObject* fileRef =
     this->CreateObject(cmXCodeObject::PBXFileReference);
-  if(const char* fileType = this->GetTargetFileType(cmtarget))
+  if(const char* fileType = this->GetTargetFileType(gtgt))
     {
     fileRef->AddAttribute("explicitFileType", this->CreateString(fileType));
     }
   std::string fullName;
-  if(cmtarget.GetType() == cmTarget::OBJECT_LIBRARY)
+  if(gtgt->GetType() == cmState::OBJECT_LIBRARY)
     {
     fullName = "lib";
-    fullName += cmtarget.GetName();
+    fullName += gtgt->GetName();
     fullName += ".a";
     }
   else
     {
-    cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&cmtarget);
     fullName = gtgt->GetFullName(defConfig.c_str());
     }
   fileRef->AddAttribute("path", this->CreateString(fullName.c_str()));
   fileRef->AddAttribute("refType", this->CreateString("0"));
   fileRef->AddAttribute("sourceTree",
                         this->CreateString("BUILT_PRODUCTS_DIR"));
-  fileRef->SetComment(cmtarget.GetName().c_str());
+  fileRef->SetComment(gtgt->GetName().c_str());
   target->AddAttribute("productReference",
                        this->CreateObjectReference(fileRef));
-  if(const char* productType = this->GetTargetProductType(cmtarget))
+  if(const char* productType = this->GetTargetProductType(gtgt))
     {
     target->AddAttribute("productType", this->CreateString(productType));
     }
-  target->SetTarget(&cmtarget);
-  this->XCodeObjectMap[&cmtarget] = target;
+  target->SetTarget(gtgt);
+  this->XCodeObjectMap[gtgt] = target;
   target->SetId(this->GetOrCreateId(
-    cmtarget.GetName(), target->GetId()).c_str());
+    gtgt->GetName(), target->GetId()).c_str());
   return target;
 }
 
 //----------------------------------------------------------------------------
-cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget const* t)
+cmXCodeObject*
+cmGlobalXCodeGenerator::FindXCodeTarget(cmGeneratorTarget const* t)
 {
   if(!t)
     {
     return 0;
     }
 
-  std::map<cmTarget const*, cmXCodeObject*>::const_iterator const i =
+  std::map<cmGeneratorTarget const*, cmXCodeObject*>::const_iterator const i =
     this->XCodeObjectMap.find(t);
   if (i == this->XCodeObjectMap.end())
     {
@@ -2912,23 +2968,22 @@ void cmGlobalXCodeGenerator
 void cmGlobalXCodeGenerator
 ::AddDependAndLinkInformation(cmXCodeObject* target)
 {
-  cmTarget* cmtarget = target->GetTarget();
-  if(cmtarget->GetType() == cmTarget::INTERFACE_LIBRARY)
+  cmGeneratorTarget* gt = target->GetTarget();
+  if(!gt)
     {
+    cmSystemTools::Error("Error no target on xobject\n");
     return;
     }
-  if(!cmtarget)
+  if(gt->GetType() == cmState::INTERFACE_LIBRARY)
     {
-    cmSystemTools::Error("Error no target on xobject\n");
     return;
     }
 
   // Add dependencies on other CMake targets.
-  cmGeneratorTarget* gt = this->GetGeneratorTarget(cmtarget);
   TargetDependSet const& deps = this->GetTargetDirectDepends(gt);
   for(TargetDependSet::const_iterator i = deps.begin(); i != deps.end(); ++i)
     {
-    if(cmXCodeObject* dptarget = this->FindXCodeTarget((*i)->Target))
+    if(cmXCodeObject* dptarget = this->FindXCodeTarget(*i))
       {
       this->AddDependTarget(target, dptarget);
       }
@@ -2948,7 +3003,7 @@ void cmGlobalXCodeGenerator
       std::string linkObjs;
       const char* sep = "";
       std::vector<std::string> objs;
-      this->GetGeneratorTarget(cmtarget)->UseObjectLibraries(objs, "");
+      gt->UseObjectLibraries(objs, "");
       for(std::vector<std::string>::const_iterator
             oi = objs.begin(); oi != objs.end(); ++oi)
         {
@@ -2957,20 +3012,19 @@ void cmGlobalXCodeGenerator
         linkObjs += this->XCodeEscapePath(oi->c_str());
         }
       this->AppendBuildSettingAttribute(
-        target, this->GetTargetLinkFlagsVar(*cmtarget),
+        target, this->GetTargetLinkFlagsVar(gt),
         linkObjs.c_str(), configName);
       }
 
     // Skip link information for object libraries.
-    if(cmtarget->GetType() == cmTarget::OBJECT_LIBRARY ||
-       cmtarget->GetType() == cmTarget::STATIC_LIBRARY)
+    if(gt->GetType() == cmState::OBJECT_LIBRARY ||
+       gt->GetType() == cmState::STATIC_LIBRARY)
       {
       continue;
       }
 
     // Compute the link library and directory information.
-    cmGeneratorTarget* gtgt = this->GetGeneratorTarget(cmtarget);
-    cmComputeLinkInformation* pcli = gtgt->GetLinkInformation(configName);
+    cmComputeLinkInformation* pcli = gt->GetLinkInformation(configName);
     if(!pcli)
       {
       continue;
@@ -3028,7 +3082,7 @@ void cmGlobalXCodeGenerator
         linkLibs += this->XCodeEscapePath(li->Value.c_str());
         }
       else if (!li->Target
-          || li->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
+          || li->Target->GetType() != cmState::INTERFACE_LIBRARY)
         {
         linkLibs += li->Value;
         }
@@ -3038,7 +3092,7 @@ void cmGlobalXCodeGenerator
         }
       }
     this->AppendBuildSettingAttribute(
-      target, this->GetTargetLinkFlagsVar(*cmtarget),
+      target, this->GetTargetLinkFlagsVar(gt),
       linkLibs.c_str(), configName);
     }
     }
@@ -3058,35 +3112,35 @@ bool cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
       }
     cmMakefile* mf = (*i)->GetMakefile();
     std::vector<cmSourceGroup> sourceGroups = mf->GetSourceGroups();
-    cmTargets &tgts = mf->GetTargets();
-    for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
+    std::vector<cmGeneratorTarget*> tgts = (*i)->GetGeneratorTargets();
+    for(std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
+        l != tgts.end(); l++)
       {
-      cmTarget& cmtarget = l->second;
+      cmGeneratorTarget* gtgt = *l;
 
       // Same skipping logic here as in CreateXCodeTargets so that we do not
       // end up with (empty anyhow) ALL_BUILD and XCODE_DEPEND_HELPER source
       // groups:
       //
-      if(cmtarget.GetType() == cmTarget::GLOBAL_TARGET)
+      if(gtgt->GetType() == cmState::GLOBAL_TARGET)
         {
         continue;
         }
-      if(cmtarget.GetType() == cmTarget::INTERFACE_LIBRARY)
+      if(gtgt->GetType() == cmState::INTERFACE_LIBRARY)
         {
         continue;
         }
 
       // add the soon to be generated Info.plist file as a source for a
       // MACOSX_BUNDLE file
-      if(cmtarget.GetPropertyAsBool("MACOSX_BUNDLE"))
+      if(gtgt->GetPropertyAsBool("MACOSX_BUNDLE"))
         {
-        std::string plist = this->ComputeInfoPListLocation(cmtarget);
+        std::string plist = this->ComputeInfoPListLocation(gtgt);
         mf->GetOrCreateSource(plist, true);
-        cmtarget.AddSource(plist);
+        gtgt->AddSource(plist);
         }
 
       std::vector<cmSourceFile*> classes;
-      cmGeneratorTarget* gtgt = this->GetGeneratorTarget(&cmtarget);
       if (!gtgt->GetConfigCommonSourceFiles(classes))
         {
         return false;
@@ -3101,14 +3155,14 @@ bool cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
         cmSourceGroup* sourceGroup =
           mf->FindSourceGroup(source.c_str(), sourceGroups);
         cmXCodeObject* pbxgroup =
-          this->CreateOrGetPBXGroup(cmtarget, sourceGroup);
-        std::string key = GetGroupMapKey(cmtarget, sf);
+          this->CreateOrGetPBXGroup(gtgt, sourceGroup);
+        std::string key = GetGroupMapKey(gtgt, sf);
         this->GroupMap[key] = pbxgroup;
         }
 
       // Put OBJECT_LIBRARY objects in proper groups:
       std::vector<std::string> objs;
-      this->GetGeneratorTarget(&cmtarget)->UseObjectLibraries(objs, "");
+      gtgt->UseObjectLibraries(objs, "");
       for(std::vector<std::string>::const_iterator
             oi = objs.begin(); oi != objs.end(); ++oi)
         {
@@ -3116,8 +3170,8 @@ bool cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
         cmSourceGroup* sourceGroup =
           mf->FindSourceGroup(source.c_str(), sourceGroups);
         cmXCodeObject* pbxgroup =
-          this->CreateOrGetPBXGroup(cmtarget, sourceGroup);
-        std::string key = GetGroupMapKeyFromPath(cmtarget, source);
+          this->CreateOrGetPBXGroup(gtgt, sourceGroup);
+        std::string key = GetGroupMapKeyFromPath(gtgt, source);
         this->GroupMap[key] = pbxgroup;
         }
       }
@@ -3148,16 +3202,16 @@ cmXCodeObject *cmGlobalXCodeGenerator
 
 //----------------------------------------------------------------------------
 cmXCodeObject* cmGlobalXCodeGenerator
-::CreateOrGetPBXGroup(cmTarget& cmtarget, cmSourceGroup* sg)
+::CreateOrGetPBXGroup(cmGeneratorTarget* gtgt, cmSourceGroup* sg)
 {
   std::string s;
   std::string target;
-  const char *targetFolder= cmtarget.GetProperty("FOLDER");
+  const char *targetFolder= gtgt->GetProperty("FOLDER");
   if(targetFolder) {
     target = targetFolder;
     target += "/";
   }
-  target += cmtarget.GetName();
+  target += gtgt->GetName();
   s = target + "/";
   s += sg->GetFullName();
   std::map<std::string, cmXCodeObject* >::iterator it =
@@ -3346,7 +3400,7 @@ bool cmGlobalXCodeGenerator
   this->RootObject->SetComment("Project object");
 
   std::string project_id = "PROJECT_";
-  project_id += root->GetMakefile()->GetProjectName();
+  project_id += root->GetProjectName();
   this->RootObject->SetId(this->GetOrCreateId(
     project_id.c_str(), this->RootObject->GetId()).c_str());
 
@@ -3362,6 +3416,9 @@ bool cmGlobalXCodeGenerator
     group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
     group->AddAttribute("BuildIndependentTargetsInParallel",
                         this->CreateString("YES"));
+    std::ostringstream v;
+    v << std::setfill('0') << std::setw(4) << XcodeVersion * 10;
+    group->AddAttribute("LastUpgradeCheck", this->CreateString(v.str()));
     this->RootObject->AddAttribute("attributes", group);
     if (this->XcodeVersion >= 32)
       this->RootObject->AddAttribute("compatibilityVersion",
@@ -3376,7 +3433,7 @@ bool cmGlobalXCodeGenerator
   // Point Xcode at the top of the source tree.
   {
   std::string pdir =
-    this->RelativeToBinary(root->GetMakefile()->GetCurrentSourceDirectory());
+    this->RelativeToBinary(root->GetCurrentSourceDirectory());
   this->RootObject->AddAttribute("projectDirPath",
                                  this->CreateString(pdir.c_str()));
   this->RootObject->AddAttribute("projectRoot", this->CreateString(""));
@@ -3385,18 +3442,19 @@ bool cmGlobalXCodeGenerator
     this->CreateObject(cmXCodeObject::XCConfigurationList);
   cmXCodeObject* buildConfigurations =
     this->CreateObject(cmXCodeObject::OBJECT_LIST);
-  std::vector<cmXCodeObject*> configs;
+  typedef std::vector<std::pair<std::string, cmXCodeObject*> > Configs;
+  Configs configs;
   const char *defaultConfigName = "Debug";
   if(this->XcodeVersion == 15)
     {
     cmXCodeObject* configDebug =
       this->CreateObject(cmXCodeObject::XCBuildConfiguration);
     configDebug->AddAttribute("name", this->CreateString("Debug"));
-    configs.push_back(configDebug);
+    configs.push_back(std::make_pair("Debug", configDebug));
     cmXCodeObject* configRelease =
       this->CreateObject(cmXCodeObject::XCBuildConfiguration);
     configRelease->AddAttribute("name", this->CreateString("Release"));
-    configs.push_back(configRelease);
+    configs.push_back(std::make_pair("Release", configRelease));
     }
   else
     {
@@ -3410,13 +3468,12 @@ bool cmGlobalXCodeGenerator
       cmXCodeObject* config =
         this->CreateObject(cmXCodeObject::XCBuildConfiguration);
       config->AddAttribute("name", this->CreateString(name));
-      configs.push_back(config);
+      configs.push_back(std::make_pair(name, config));
       }
     }
-  for(std::vector<cmXCodeObject*>::iterator c = configs.begin();
-      c != configs.end(); ++c)
+  for(Configs::iterator c = configs.begin(); c != configs.end(); ++c)
     {
-    buildConfigurations->AddObject(*c);
+    buildConfigurations->AddObject(c->second);
     }
   configlist->AddAttribute("buildConfigurations", buildConfigurations);
 
@@ -3472,30 +3529,37 @@ bool cmGlobalXCodeGenerator
       this->CreateString(this->GeneratorToolset.c_str()));
     }
 
-  // Put this last so it can override existing settings
-  // Convert "CMAKE_XCODE_ATTRIBUTE_*" variables directly.
-  {
-    std::vector<std::string> vars = this->CurrentMakefile->GetDefinitions();
-    for(std::vector<std::string>::const_iterator i = vars.begin();
-        i != vars.end(); ++i)
-    {
-      if(i->find("CMAKE_XCODE_ATTRIBUTE_") == 0)
-      {
-        buildSettings->AddAttribute(i->substr(22).c_str(),
-          this->CreateString(
-            this->CurrentMakefile->GetDefinition(i->c_str())));
-      }
-    }
-  }
-
-  std::string symroot = root->GetMakefile()->GetCurrentBinaryDirectory();
+  std::string symroot = root->GetCurrentBinaryDirectory();
   symroot += "/build";
   buildSettings->AddAttribute("SYMROOT", this->CreateString(symroot.c_str()));
 
-  for( std::vector<cmXCodeObject*>::iterator i = configs.begin();
-       i != configs.end(); ++i)
+  for(Configs::iterator i = configs.begin(); i != configs.end(); ++i)
     {
-    (*i)->AddAttribute("buildSettings", buildSettings);
+    cmXCodeObject* buildSettingsForCfg = this->CreateFlatClone(buildSettings);
+
+    // Put this last so it can override existing settings
+    // Convert "CMAKE_XCODE_ATTRIBUTE_*" variables directly.
+    std::vector<std::string> vars = this->CurrentMakefile->GetDefinitions();
+    for(std::vector<std::string>::const_iterator d = vars.begin();
+        d != vars.end(); ++d)
+      {
+      if(d->find("CMAKE_XCODE_ATTRIBUTE_") == 0)
+        {
+        std::string attribute = d->substr(22);
+        this->FilterConfigurationAttribute(i->first, attribute);
+        if(!attribute.empty())
+          {
+          cmGeneratorExpression ge;
+          std::string processed =
+            ge.Parse(this->CurrentMakefile->GetDefinition(*d))
+              ->Evaluate(this->CurrentLocalGenerator, i->first);
+          buildSettingsForCfg->AddAttribute(attribute,
+            this->CreateString(processed));
+          }
+        }
+      }
+    // store per-config buildSettings into configuration object
+    i->second->AddAttribute("buildSettings", buildSettingsForCfg);
     }
 
   this->RootObject->AddAttribute("buildConfigurationList",
@@ -3547,10 +3611,10 @@ std::string
 cmGlobalXCodeGenerator::GetObjectsNormalDirectory(
   const std::string &projName,
   const std::string &configName,
-  const cmTarget *t) const
+  const cmGeneratorTarget *t) const
 {
   std::string dir =
-    t->GetMakefile()->GetCurrentBinaryDirectory();
+    t->GetLocalGenerator()->GetCurrentBinaryDirectory();
   dir += "/";
   dir += projName;
   dir += ".build/";
@@ -3624,24 +3688,23 @@ cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
         i != targets.end(); ++i)
       {
       cmXCodeObject* target = *i;
-      cmTarget* t =target->GetTarget();
-      cmGeneratorTarget *gt = this->GetGeneratorTarget(t);
+      cmGeneratorTarget* gt =target->GetTarget();
 
-      if(t->GetType() == cmTarget::EXECUTABLE ||
+      if(gt->GetType() == cmState::EXECUTABLE ||
 // Nope - no post-build for OBJECT_LIRBRARY
-//         t->GetType() == cmTarget::OBJECT_LIBRARY ||
-         t->GetType() == cmTarget::STATIC_LIBRARY ||
-         t->GetType() == cmTarget::SHARED_LIBRARY ||
-         t->GetType() == cmTarget::MODULE_LIBRARY)
+//         gt->GetType() == cmState::OBJECT_LIBRARY ||
+         gt->GetType() == cmState::STATIC_LIBRARY ||
+         gt->GetType() == cmState::SHARED_LIBRARY ||
+         gt->GetType() == cmState::MODULE_LIBRARY)
         {
         // Declare an entry point for the target post-build phase.
-        makefileStream << this->PostBuildMakeTarget(t->GetName(), *ct)
+        makefileStream << this->PostBuildMakeTarget(gt->GetName(), *ct)
                        << ":\n";
         }
 
-      if(t->GetType() == cmTarget::EXECUTABLE ||
-         t->GetType() == cmTarget::SHARED_LIBRARY ||
-         t->GetType() == cmTarget::MODULE_LIBRARY)
+      if(gt->GetType() == cmState::EXECUTABLE ||
+         gt->GetType() == cmState::SHARED_LIBRARY ||
+         gt->GetType() == cmState::MODULE_LIBRARY)
         {
         std::string tfull = gt->GetFullPath(configName);
         std::string trel = this->ConvertToRelativeForMake(tfull.c_str());
@@ -3686,7 +3749,7 @@ cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
         if(this->Architectures.size() > 1)
           {
           std::string universal = this->GetObjectsNormalDirectory(
-            this->CurrentProject, configName, t);
+            this->CurrentProject, configName, gt);
           for( std::vector<std::string>::iterator arch =
                  this->Architectures.begin();
                arch != this->Architectures.end(); ++arch)
@@ -3731,9 +3794,9 @@ cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
     {
     return;
     }
-  std::string xcodeDir = root->GetMakefile()->GetCurrentBinaryDirectory();
+  std::string xcodeDir = root->GetCurrentBinaryDirectory();
   xcodeDir += "/";
-  xcodeDir += root->GetMakefile()->GetProjectName();
+  xcodeDir += root->GetProjectName();
   xcodeDir += ".xcode";
   if(this->XcodeVersion > 20)
     {
@@ -3753,7 +3816,7 @@ cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
   // Since this call may have created new cache entries, save the cache:
   //
   root->GetMakefile()->GetCMakeInstance()->SaveCache(
-    root->GetMakefile()->GetHomeOutputDirectory());
+    root->GetBinaryDirectory());
 }
 
 //----------------------------------------------------------------------------
@@ -3841,12 +3904,6 @@ std::string cmGlobalXCodeGenerator::ConvertToRelativeForMake(const char* p)
 }
 
 //----------------------------------------------------------------------------
-std::string cmGlobalXCodeGenerator::ConvertToRelativeForXCode(const char* p)
-{
-  return cmSystemTools::ConvertToOutputPath(p);
-}
-
-//----------------------------------------------------------------------------
 std::string cmGlobalXCodeGenerator::RelativeToSource(const char* p)
 {
   // We force conversion because Xcode breakpoints do not work unless
@@ -3982,8 +4039,8 @@ void cmGlobalXCodeGenerator::AppendFlag(std::string& flags,
 
   // We escape a flag as follows:
   //   - Place each flag in single quotes ''
-  //   - Escape a single quote as \\'
-  //   - Escape a backslash as \\\\ since it itself is an escape
+  //   - Escape a single quote as \'
+  //   - Escape a backslash as \\ since it itself is an escape
   // Note that in the code below we need one more level of escapes for
   // C string syntax in this source file.
   //
@@ -4003,16 +4060,16 @@ void cmGlobalXCodeGenerator::AppendFlag(std::string& flags,
       {
       if (this->XcodeVersion >= 40)
         {
-        flags += "'\\\\''";
+        flags += "'\\''";
         }
       else
         {
-        flags += "\\\\'";
+        flags += "\\'";
         }
       }
     else if(*c == '\\')
       {
-      flags += "\\\\\\\\";
+      flags += "\\\\";
       }
     else
       {
@@ -4029,12 +4086,13 @@ void cmGlobalXCodeGenerator::AppendFlag(std::string& flags,
 
 //----------------------------------------------------------------------------
 std::string
-cmGlobalXCodeGenerator::ComputeInfoPListLocation(cmTarget& target)
+cmGlobalXCodeGenerator::ComputeInfoPListLocation(cmGeneratorTarget* target)
 {
-  std::string plist = target.GetMakefile()->GetCurrentBinaryDirectory();
+  std::string plist =
+      target->GetLocalGenerator()->GetCurrentBinaryDirectory();
   plist += cmake::GetCMakeFilesDirectory();
   plist += "/";
-  plist += target.GetName();
+  plist += target->GetName();
   plist += ".dir/Info.plist";
   return plist;
 }
@@ -4060,7 +4118,7 @@ void cmGlobalXCodeGenerator
 {
   std::string configName = this->GetCMakeCFGIntDir();
   std::string dir = this->GetObjectsNormalDirectory(
-    "$(PROJECT_NAME)", configName, gt->Target);
+    "$(PROJECT_NAME)", configName, gt);
   if(this->XcodeVersion >= 21)
     {
     dir += "$(CURRENT_ARCH)/";
diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h
index 102c036..862746f 100644
--- a/Source/cmGlobalXCodeGenerator.h
+++ b/Source/cmGlobalXCodeGenerator.h
@@ -16,7 +16,6 @@
 #include "cmXCodeObject.h"
 #include "cmCustomCommand.h"
 class cmGlobalGeneratorFactory;
-class cmTarget;
 class cmSourceFile;
 class cmSourceGroup;
 
@@ -87,10 +86,10 @@ public:
   virtual bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf);
   void AppendFlag(std::string& flags, std::string const& flag);
 protected:
-  virtual bool Compute();
+  virtual void AddExtraIDETargets();
   virtual void Generate();
 private:
-  cmXCodeObject* CreateOrGetPBXGroup(cmTarget& cmtarget,
+  cmXCodeObject* CreateOrGetPBXGroup(cmGeneratorTarget* gtgt,
                                      cmSourceGroup* sg);
   cmXCodeObject* CreatePBXGroup(cmXCodeObject *parent,
                                 std::string name);
@@ -100,7 +99,6 @@ private:
   std::string XCodeEscapePath(const char* p);
   std::string RelativeToSource(const char* p);
   std::string RelativeToBinary(const char* p);
-  std::string ConvertToRelativeForXCode(const char* p);
   std::string ConvertToRelativeForMake(const char* p);
   void CreateCustomCommands(cmXCodeObject* buildPhases,
                             cmXCodeObject* sourceBuildPhase,
@@ -108,22 +106,22 @@ private:
                             cmXCodeObject* resourceBuildPhase,
                             std::vector<cmXCodeObject*> contentBuildPhases,
                             cmXCodeObject* frameworkBuildPhase,
-                            cmTarget& cmtarget);
+                            cmGeneratorTarget *gtgt);
 
-  std::string ComputeInfoPListLocation(cmTarget& target);
+  std::string ComputeInfoPListLocation(cmGeneratorTarget *target);
 
   void AddCommandsToBuildPhase(cmXCodeObject* buildphase,
-                               cmTarget& target,
+                               cmGeneratorTarget *target,
                                std::vector<cmCustomCommand>
                                const & commands,
                                const char* commandFileName);
 
   void CreateCustomRulesMakefile(const char* makefileBasename,
-                                 cmTarget& target,
+                                 cmGeneratorTarget* target,
                                  std::vector<cmCustomCommand> const & commands,
                                  const std::string& configName);
 
-  cmXCodeObject* FindXCodeTarget(cmTarget const*);
+  cmXCodeObject* FindXCodeTarget(const cmGeneratorTarget *);
   std::string GetOrCreateId(const std::string& name, const std::string& id);
 
   // create cmXCodeObject from these functions so that memory can be managed
@@ -132,25 +130,31 @@ private:
   cmXCodeObject* CreateObject(cmXCodeObject::Type type);
   cmXCodeObject* CreateString(const std::string& s);
   cmXCodeObject* CreateObjectReference(cmXCodeObject*);
-  cmXCodeObject* CreateXCodeTarget(cmTarget& target,
+  cmXCodeObject* CreateFlatClone(cmXCodeObject*);
+  cmXCodeObject* CreateXCodeTarget(cmGeneratorTarget *gtgt,
                                    cmXCodeObject* buildPhases);
   void ForceLinkerLanguages();
-  void ForceLinkerLanguage(cmTarget& cmtarget);
-  const char* GetTargetLinkFlagsVar(cmTarget const& cmtarget) const;
-  const char* GetTargetFileType(cmTarget& cmtarget);
-  const char* GetTargetProductType(cmTarget& cmtarget);
-  std::string AddConfigurations(cmXCodeObject* target, cmTarget& cmtarget);
+  void ForceLinkerLanguage(cmGeneratorTarget* gtgt);
+  const char* GetTargetLinkFlagsVar(const cmGeneratorTarget *target) const;
+  const char* GetTargetFileType(cmGeneratorTarget* target);
+  const char* GetTargetProductType(cmGeneratorTarget* target);
+  std::string AddConfigurations(cmXCodeObject* target,
+                                cmGeneratorTarget *gtgt);
   void AppendOrAddBuildSetting(cmXCodeObject* settings, const char* attr,
                                const char* value);
   void AppendBuildSettingAttribute(cmXCodeObject* target, const char* attr,
                                    const char* value,
                                    const std::string& configName);
-  cmXCodeObject* CreateUtilityTarget(cmTarget& target);
+  cmXCodeObject* CreateUtilityTarget(cmGeneratorTarget *gtgt);
   void AddDependAndLinkInformation(cmXCodeObject* target);
-  void CreateBuildSettings(cmTarget& target,
+  void CreateBuildSettings(cmGeneratorTarget *gtgt,
                            cmXCodeObject* buildSettings,
                            const std::string& buildType);
   std::string ExtractFlag(const char* flag, std::string& flags);
+  std::string ExtractFlagRegex(const char* exp, int matchIndex,
+                               std::string& flags);
+  void FilterConfigurationAttribute(std::string const& configName,
+                                    std::string& attribute);
   void SortXCodeObjects();
   // delete all objects in the this->XCodeObjects vector.
   void ClearXCodeObjects();
@@ -161,18 +165,18 @@ private:
   void WriteXCodePBXProj(std::ostream& fout, cmLocalGenerator* root,
                          std::vector<cmLocalGenerator*>& generators);
   cmXCodeObject* CreateXCodeFileReferenceFromPath(const std::string &fullpath,
-                                                  cmTarget& cmtarget,
+                                                  cmGeneratorTarget *target,
                                                   const std::string &lang,
                                                   cmSourceFile* sf);
   cmXCodeObject* CreateXCodeSourceFileFromPath(const std::string &fullpath,
-                                               cmTarget& cmtarget,
+                                               cmGeneratorTarget *target,
                                                const std::string &lang,
                                                cmSourceFile* sf);
   cmXCodeObject* CreateXCodeFileReference(cmSourceFile* sf,
-                                          cmTarget& cmtarget);
+                                          cmGeneratorTarget *target);
   cmXCodeObject* CreateXCodeSourceFile(cmLocalGenerator* gen,
                                        cmSourceFile* sf,
-                                       cmTarget& cmtarget);
+                                       cmGeneratorTarget *gtgt);
   bool CreateXCodeTargets(cmLocalGenerator* gen,
                           std::vector<cmXCodeObject*>&);
   bool IsHeaderFile(cmSourceFile*);
@@ -185,7 +189,7 @@ private:
                        std::vector<cmLocalGenerator*>& gens);
   cmXCodeObject* CreateBuildPhase(const char* name,
                                   const char* name2,
-                                  cmTarget& cmtarget,
+                                  cmGeneratorTarget *target,
                                   const std::vector<cmCustomCommand>&);
   void CreateReRunCMakeFile(cmLocalGenerator* root,
                             std::vector<cmLocalGenerator*> const& gens);
@@ -224,10 +228,9 @@ private:
   void PrintCompilerAdvice(std::ostream&, std::string const&,
                            const char*) const {}
 
-  std::string GetObjectsNormalDirectory(
-    const std::string &projName,
+  std::string GetObjectsNormalDirectory(const std::string &projName,
     const std::string &configName,
-    const cmTarget *t) const;
+    const cmGeneratorTarget *t) const;
 
   void addObject(cmXCodeObject *obj);
   std::string PostBuildMakeTarget(std::string const& tName,
@@ -249,7 +252,7 @@ private:
   std::map<std::string, cmXCodeObject* > GroupNameMap;
   std::map<std::string, cmXCodeObject* > TargetGroup;
   std::map<std::string, cmXCodeObject* > FileRefs;
-  std::map<cmTarget const*, cmXCodeObject* > XCodeObjectMap;
+  std::map<cmGeneratorTarget const*, cmXCodeObject* > XCodeObjectMap;
   std::vector<std::string> Architectures;
   std::string GeneratorToolset;
 };
diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx
index 2023697..448306f 100644
--- a/Source/cmGraphVizWriter.cxx
+++ b/Source/cmGraphVizWriter.cxx
@@ -17,7 +17,7 @@
 
 
 
-static const char* getShapeForTarget(const cmTarget* target)
+static const char* getShapeForTarget(const cmGeneratorTarget* target)
 {
   if (!target)
     {
@@ -26,13 +26,13 @@ static const char* getShapeForTarget(const cmTarget* target)
 
   switch ( target->GetType() )
     {
-    case cmTarget::EXECUTABLE:
+    case cmState::EXECUTABLE:
       return "house";
-    case cmTarget::STATIC_LIBRARY:
+    case cmState::STATIC_LIBRARY:
       return "diamond";
-    case cmTarget::SHARED_LIBRARY:
+    case cmState::SHARED_LIBRARY:
       return "polygon";
-    case cmTarget::MODULE_LIBRARY:
+    case cmState::MODULE_LIBRARY:
       return "octagon";
     default:
       break;
@@ -67,6 +67,7 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
   cmake cm;
   cm.SetHomeDirectory("");
   cm.SetHomeOutputDirectory("");
+  cm.GetCurrentSnapshot().SetDefaultDefinitions();
   cmGlobalGenerator ggi(&cm);
   cmsys::auto_ptr<cmMakefile> mf(
         new cmMakefile(&ggi, cm.GetCurrentSnapshot()));
@@ -162,7 +163,7 @@ void cmGraphVizWriter::WriteTargetDependersFiles(const char* fileName)
 
   this->CollectTargetsAndLibs();
 
-  for(std::map<std::string, const cmTarget*>::const_iterator ptrIt =
+  for(std::map<std::string, const cmGeneratorTarget*>::const_iterator ptrIt =
                                                       this->TargetPtrs.begin();
       ptrIt != this->TargetPtrs.end();
       ++ptrIt)
@@ -213,7 +214,7 @@ void cmGraphVizWriter::WritePerTargetFiles(const char* fileName)
 
   this->CollectTargetsAndLibs();
 
-  for(std::map<std::string, const cmTarget*>::const_iterator ptrIt =
+  for(std::map<std::string, const cmGeneratorTarget*>::const_iterator ptrIt =
                                                       this->TargetPtrs.begin();
       ptrIt != this->TargetPtrs.end();
       ++ptrIt)
@@ -267,7 +268,7 @@ void cmGraphVizWriter::WriteGlobalFile(const char* fileName)
   std::set<std::string> insertedConnections;
   std::set<std::string> insertedNodes;
 
-  for(std::map<std::string, const cmTarget*>::const_iterator ptrIt =
+  for(std::map<std::string, const cmGeneratorTarget*>::const_iterator ptrIt =
                                                       this->TargetPtrs.begin();
       ptrIt != this->TargetPtrs.end();
       ++ptrIt)
@@ -291,7 +292,7 @@ void cmGraphVizWriter::WriteGlobalFile(const char* fileName)
 
 void cmGraphVizWriter::WriteHeader(cmGeneratedFileStream& str) const
 {
-  str << this->GraphType << " " << this->GraphName << " {" << std::endl;
+  str << this->GraphType << " \"" << this->GraphName << "\" {" << std::endl;
   str << this->GraphHeader << std::endl;
 }
 
@@ -307,8 +308,8 @@ void cmGraphVizWriter::WriteConnections(const std::string& targetName,
                                     std::set<std::string>& insertedConnections,
                                     cmGeneratedFileStream& str) const
 {
-  std::map<std::string, const cmTarget* >::const_iterator targetPtrIt =
-                                             this->TargetPtrs.find(targetName);
+  std::map<std::string, const cmGeneratorTarget* >::const_iterator targetPtrIt
+      = this->TargetPtrs.find(targetName);
 
   if (targetPtrIt == this->TargetPtrs.end())  // not found at all
     {
@@ -326,7 +327,7 @@ void cmGraphVizWriter::WriteConnections(const std::string& targetName,
   std::string myNodeName = this->TargetNamesNodes.find(targetName)->second;
 
   const cmTarget::LinkLibraryVectorType* ll =
-                            &(targetPtrIt->second->GetOriginalLinkLibraries());
+      &(targetPtrIt->second->Target->GetOriginalLinkLibraries());
 
   for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
        llit != ll->end();
@@ -366,8 +367,8 @@ void cmGraphVizWriter::WriteDependerConnections(const std::string& targetName,
                                     std::set<std::string>& insertedConnections,
                                     cmGeneratedFileStream& str) const
 {
-  std::map<std::string, const cmTarget* >::const_iterator targetPtrIt =
-                                             this->TargetPtrs.find(targetName);
+  std::map<std::string, const cmGeneratorTarget* >::const_iterator targetPtrIt
+      = this->TargetPtrs.find(targetName);
 
   if (targetPtrIt == this->TargetPtrs.end())  // not found at all
     {
@@ -385,8 +386,8 @@ void cmGraphVizWriter::WriteDependerConnections(const std::string& targetName,
   std::string myNodeName = this->TargetNamesNodes.find(targetName)->second;
 
   // now search who links against me
-  for(std::map<std::string, const cmTarget*>::const_iterator dependerIt =
-                                                      this->TargetPtrs.begin();
+  for(std::map<std::string, const cmGeneratorTarget*>::const_iterator
+      dependerIt = this->TargetPtrs.begin();
       dependerIt != this->TargetPtrs.end();
       ++dependerIt)
     {
@@ -403,7 +404,7 @@ void cmGraphVizWriter::WriteDependerConnections(const std::string& targetName,
     // Now we have a target, check whether it links against targetName.
     // If so, draw a connection, and then continue with dependers on that one.
     const cmTarget::LinkLibraryVectorType* ll =
-                            &(dependerIt->second->GetOriginalLinkLibraries());
+        &(dependerIt->second->Target->GetOriginalLinkLibraries());
 
     for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
          llit != ll->end();
@@ -447,7 +448,7 @@ void cmGraphVizWriter::WriteDependerConnections(const std::string& targetName,
 
 
 void cmGraphVizWriter::WriteNode(const std::string& targetName,
-                                 const cmTarget* target,
+                                 const cmGeneratorTarget* target,
                                  std::set<std::string>& insertedNodes,
                                  cmGeneratedFileStream& str) const
 {
@@ -487,12 +488,11 @@ int cmGraphVizWriter::CollectAllTargets()
        lit != this->LocalGenerators.end();
        ++ lit )
     {
-    const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets());
-    for ( cmTargets::const_iterator tit = targets->begin();
-          tit != targets->end();
-          ++ tit )
+    std::vector<cmGeneratorTarget*> targets = (*lit)->GetGeneratorTargets();
+    for ( std::vector<cmGeneratorTarget*>::const_iterator it =
+          targets.begin(); it != targets.end(); ++it )
       {
-      const char* realTargetName = tit->first.c_str();
+      const char* realTargetName = (*it)->GetName().c_str();
       if(this->IgnoreThisTarget(realTargetName))
         {
         // Skip ignored targets
@@ -502,7 +502,7 @@ int cmGraphVizWriter::CollectAllTargets()
       std::ostringstream ostr;
       ostr << this->GraphNodePrefix << cnt++;
       this->TargetNamesNodes[realTargetName] = ostr.str();
-      this->TargetPtrs[realTargetName] = &tit->second;
+      this->TargetPtrs[realTargetName] = *it;
       }
     }
 
@@ -518,19 +518,18 @@ int cmGraphVizWriter::CollectAllExternalLibs(int cnt)
        lit != this->LocalGenerators.end();
        ++ lit )
     {
-    const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets());
-    for ( cmTargets::const_iterator tit = targets->begin();
-          tit != targets->end();
-          ++ tit )
+    std::vector<cmGeneratorTarget*> targets = (*lit)->GetGeneratorTargets();
+    for ( std::vector<cmGeneratorTarget*>::const_iterator it =
+          targets.begin(); it != targets.end(); ++it )
       {
-      const char* realTargetName = tit->first.c_str();
+      const char* realTargetName = (*it)->GetName().c_str();
       if (this->IgnoreThisTarget(realTargetName))
         {
         // Skip ignored targets
         continue;
         }
       const cmTarget::LinkLibraryVectorType* ll =
-                                     &(tit->second.GetOriginalLinkLibraries());
+          &((*it)->Target->GetOriginalLinkLibraries());
       for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
            llit != ll->end();
            ++ llit )
@@ -542,8 +541,8 @@ int cmGraphVizWriter::CollectAllExternalLibs(int cnt)
           continue;
           }
 
-        std::map<std::string, const cmTarget*>::const_iterator tarIt =
-                                                this->TargetPtrs.find(libName);
+        std::map<std::string, const cmGeneratorTarget*>::const_iterator tarIt
+            = this->TargetPtrs.find(libName);
         if ( tarIt == this->TargetPtrs.end() )
           {
           std::ostringstream ostr;
@@ -581,18 +580,18 @@ bool cmGraphVizWriter::IgnoreThisTarget(const std::string& name)
 }
 
 
-bool cmGraphVizWriter::GenerateForTargetType(cmTarget::TargetType targetType)
+bool cmGraphVizWriter::GenerateForTargetType(cmState::TargetType targetType)
                                                                           const
 {
   switch (targetType)
   {
-    case cmTarget::EXECUTABLE:
+    case cmState::EXECUTABLE:
       return this->GenerateForExecutables;
-    case cmTarget::STATIC_LIBRARY:
+    case cmState::STATIC_LIBRARY:
       return this->GenerateForStaticLibs;
-    case cmTarget::SHARED_LIBRARY:
+    case cmState::SHARED_LIBRARY:
       return this->GenerateForSharedLibs;
-    case cmTarget::MODULE_LIBRARY:
+    case cmState::MODULE_LIBRARY:
       return this->GenerateForModuleLibs;
     default:
       break;
diff --git a/Source/cmGraphVizWriter.h b/Source/cmGraphVizWriter.h
index 64de684..90d31d3 100644
--- a/Source/cmGraphVizWriter.h
+++ b/Source/cmGraphVizWriter.h
@@ -14,9 +14,9 @@
 #include "cmStandardIncludes.h"
 #include "cmLocalGenerator.h"
 #include "cmGeneratedFileStream.h"
-#include "cmTarget.h"
 #include <cmsys/RegularExpression.hxx>
 
+class cmGeneratorTarget;
 
 /** This class implements writing files for graphviz (dot) for graphs
  * representing the dependencies between the targets in the project. */
@@ -54,7 +54,8 @@ protected:
                                 std::set<std::string>& insertedConnections,
                                 cmGeneratedFileStream& str) const;
 
-  void WriteNode(const std::string& targetName, const cmTarget* target,
+  void WriteNode(const std::string& targetName,
+                 const cmGeneratorTarget* target,
                  std::set<std::string>& insertedNodes,
                  cmGeneratedFileStream& str) const;
 
@@ -62,7 +63,7 @@ protected:
 
   bool IgnoreThisTarget(const std::string& name);
 
-  bool GenerateForTargetType(cmTarget::TargetType targetType) const;
+  bool GenerateForTargetType(cmState::TargetType targetType) const;
 
   std::string GraphType;
   std::string GraphName;
@@ -73,7 +74,7 @@ protected:
 
   const std::vector<cmLocalGenerator*>& LocalGenerators;
 
-  std::map<std::string, const cmTarget*> TargetPtrs;
+  std::map<std::string, const cmGeneratorTarget*> TargetPtrs;
   // maps from the actual target names to node names in dot:
   std::map<std::string, std::string> TargetNamesNodes;
 
diff --git a/Source/cmIDEFlagTable.h b/Source/cmIDEFlagTable.h
index d9a045d..adc7763 100644
--- a/Source/cmIDEFlagTable.h
+++ b/Source/cmIDEFlagTable.h
@@ -32,6 +32,7 @@ struct cmIDEFlagTable
                                   // /NODEFAULTLIB: =>
                                   // IgnoreDefaultLibraryNames)
     UserFollowing = (1<<5), // expect value in following argument
+    CaseInsensitive = (1<<6), // flag may be any case
 
     UserValueIgnored  = UserValue | UserIgnored,
     UserValueRequired = UserValue | UserRequired
diff --git a/Source/cmIDEOptions.cxx b/Source/cmIDEOptions.cxx
index 0eb903d..509602f 100644
--- a/Source/cmIDEOptions.cxx
+++ b/Source/cmIDEOptions.cxx
@@ -13,6 +13,8 @@
 
 #include "cmSystemTools.h"
 
+#include <cmsys/String.h>
+
 //----------------------------------------------------------------------------
 cmIDEOptions::cmIDEOptions()
 {
@@ -104,7 +106,9 @@ bool cmIDEOptions::CheckFlagTable(cmIDEFlagTable const* table,
       // the entry specifies UserRequired we must match only if a
       // non-empty value is given.
       int n = static_cast<int>(strlen(entry->commandFlag));
-      if(strncmp(flag+1, entry->commandFlag, n) == 0 &&
+      if((strncmp(flag+1, entry->commandFlag, n) == 0 ||
+          (entry->special & cmIDEFlagTable::CaseInsensitive &&
+           cmsysString_strncasecmp(flag+1, entry->commandFlag, n))) &&
          (!(entry->special & cmIDEFlagTable::UserRequired) ||
           static_cast<int>(strlen(flag+1)) > n))
         {
@@ -112,7 +116,9 @@ bool cmIDEOptions::CheckFlagTable(cmIDEFlagTable const* table,
         entry_found = true;
         }
       }
-    else if(strcmp(flag+1, entry->commandFlag) == 0)
+    else if(strcmp(flag+1, entry->commandFlag) == 0 ||
+            (entry->special & cmIDEFlagTable::CaseInsensitive &&
+             cmsysString_strcasecmp(flag+1, entry->commandFlag) == 0))
       {
       if(entry->special & cmIDEFlagTable::UserFollowing)
         {
diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx
index 9e71d37..5964ef1 100644
--- a/Source/cmIfCommand.cxx
+++ b/Source/cmIfCommand.cxx
@@ -11,6 +11,7 @@
 ============================================================================*/
 #include "cmIfCommand.h"
 #include "cmStringCommand.h"
+#include "cmOutputConverter.h"
 
 #include "cmConditionEvaluator.h"
 
diff --git a/Source/cmIncludeExternalMSProjectCommand.cxx b/Source/cmIncludeExternalMSProjectCommand.cxx
index 1e7258a..c64d128 100644
--- a/Source/cmIncludeExternalMSProjectCommand.cxx
+++ b/Source/cmIncludeExternalMSProjectCommand.cxx
@@ -77,7 +77,7 @@ bool cmIncludeExternalMSProjectCommand
       }
 
     // Create a target instance for this utility.
-    cmTarget* target=this->Makefile->AddNewTarget(cmTarget::UTILITY,
+    cmTarget* target=this->Makefile->AddNewTarget(cmState::UTILITY,
                                                   utility_name.c_str());
 
     target->SetProperty("GENERATOR_FILE_NAME", utility_name.c_str());
diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx
index d3c2e26..2d78a41 100644
--- a/Source/cmInstallCommand.cxx
+++ b/Source/cmInstallCommand.cxx
@@ -384,12 +384,12 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
     if(cmTarget* target=this->Makefile->FindTarget(*targetIt))
       {
       // Found the target.  Check its type.
-      if(target->GetType() != cmTarget::EXECUTABLE &&
-         target->GetType() != cmTarget::STATIC_LIBRARY &&
-         target->GetType() != cmTarget::SHARED_LIBRARY &&
-         target->GetType() != cmTarget::MODULE_LIBRARY &&
-         target->GetType() != cmTarget::OBJECT_LIBRARY &&
-         target->GetType() != cmTarget::INTERFACE_LIBRARY)
+      if(target->GetType() != cmState::EXECUTABLE &&
+         target->GetType() != cmState::STATIC_LIBRARY &&
+         target->GetType() != cmState::SHARED_LIBRARY &&
+         target->GetType() != cmState::MODULE_LIBRARY &&
+         target->GetType() != cmState::OBJECT_LIBRARY &&
+         target->GetType() != cmState::INTERFACE_LIBRARY)
         {
         std::ostringstream e;
         e << "TARGETS given target \"" << (*targetIt)
@@ -397,7 +397,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
         this->SetError(e.str());
         return false;
         }
-      else if(target->GetType() == cmTarget::OBJECT_LIBRARY)
+      else if(target->GetType() == cmState::OBJECT_LIBRARY)
         {
         std::ostringstream e;
         e << "TARGETS given OBJECT library \"" << (*targetIt)
@@ -450,7 +450,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
 
     switch(target.GetType())
       {
-      case cmTarget::SHARED_LIBRARY:
+      case cmState::SHARED_LIBRARY:
         {
         // Shared libraries are handled differently on DLL and non-DLL
         // platforms.  All windows platforms are DLL platforms including
@@ -533,7 +533,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
           }
         }
         break;
-      case cmTarget::STATIC_LIBRARY:
+      case cmState::STATIC_LIBRARY:
         {
         // Static libraries use ARCHIVE properties.
         if (!archiveArgs.GetDestination().empty())
@@ -551,7 +551,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
           }
         }
         break;
-      case cmTarget::MODULE_LIBRARY:
+      case cmState::MODULE_LIBRARY:
         {
         // Modules use LIBRARY properties.
         if (!libraryArgs.GetDestination().empty())
@@ -572,7 +572,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
           }
         }
         break;
-      case cmTarget::EXECUTABLE:
+      case cmState::EXECUTABLE:
         {
         if(target.IsAppBundleOnApple())
           {
@@ -636,7 +636,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
           }
         }
         break;
-      case cmTarget::INTERFACE_LIBRARY:
+      case cmState::INTERFACE_LIBRARY:
           // Nothing to do. An INTERFACE_LIBRARY can be installed, but the
           // only effect of that is to make it exportable. It installs no
           // other files itself.
@@ -655,7 +655,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
     bool createInstallGeneratorsForTargetFileSets = true;
 
     if(target.IsFrameworkOnApple()
-        || target.GetType() == cmTarget::INTERFACE_LIBRARY)
+        || target.GetType() == cmState::INTERFACE_LIBRARY)
       {
       createInstallGeneratorsForTargetFileSets = false;
       }
@@ -768,7 +768,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
     if(!exports.GetString().empty() && !namelinkOnly)
       {
       cmTargetExport *te = new cmTargetExport;
-      te->Target = ⌖
+      te->TargetName = target.GetName();
       te->ArchiveGenerator = archiveGenerator;
       te->BundleGenerator = bundleGenerator;
       te->FrameworkGenerator = frameworkGenerator;
@@ -1374,16 +1374,19 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
         tei != exportSet->GetTargetExports()->end(); ++tei)
       {
       cmTargetExport const* te = *tei;
+      cmTarget* tgt =
+        this->Makefile->GetGlobalGenerator()->FindTarget(te->TargetName);
       const bool newCMP0022Behavior =
-                      te->Target->GetPolicyStatusCMP0022() != cmPolicies::WARN
-                   && te->Target->GetPolicyStatusCMP0022() != cmPolicies::OLD;
+        (tgt &&
+         tgt->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
+         tgt->GetPolicyStatusCMP0022() != cmPolicies::OLD);
 
       if(!newCMP0022Behavior)
         {
         std::ostringstream e;
         e << "INSTALL(EXPORT) given keyword \""
           << "EXPORT_LINK_INTERFACE_LIBRARIES" << "\", but target \""
-          << te->Target->GetName()
+          << te->TargetName
           << "\" does not have policy CMP0022 set to NEW.";
         this->SetError(e.str());
         return false;
diff --git a/Source/cmInstallDirectoryGenerator.cxx b/Source/cmInstallDirectoryGenerator.cxx
index 78cb5f0..f2e8609 100644
--- a/Source/cmInstallDirectoryGenerator.cxx
+++ b/Source/cmInstallDirectoryGenerator.cxx
@@ -11,7 +11,6 @@
 ============================================================================*/
 #include "cmInstallDirectoryGenerator.h"
 
-#include "cmTarget.h"
 #include "cmGeneratorExpression.h"
 #include "cmLocalGenerator.h"
 
@@ -37,6 +36,16 @@ cmInstallDirectoryGenerator
     {
     this->ActionsPerConfig = true;
     }
+
+  // We need per-config actions if any directories have generator expressions.
+  for(std::vector<std::string>::const_iterator i = dirs.begin();
+      !this->ActionsPerConfig && i != dirs.end(); ++i)
+    {
+    if(cmGeneratorExpression::Find(*i) != std::string::npos)
+      {
+      this->ActionsPerConfig = true;
+      }
+    }
 }
 
 //----------------------------------------------------------------------------
@@ -61,7 +70,7 @@ cmInstallDirectoryGenerator::GenerateScriptActions(std::ostream& os,
     }
   else
     {
-    this->AddDirectoryInstallRule(os, "", indent);
+    this->AddDirectoryInstallRule(os, "", indent, this->Directories);
     }
 }
 
@@ -70,20 +79,30 @@ void cmInstallDirectoryGenerator::GenerateScriptForConfig(
   const std::string& config,
   Indent const& indent)
 {
-  this->AddDirectoryInstallRule(os, config, indent);
+  std::vector<std::string> dirs;
+  cmGeneratorExpression ge;
+  for(std::vector<std::string>::const_iterator i = this->Directories.begin();
+      i != this->Directories.end(); ++i)
+    {
+    cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*i);
+    cmSystemTools::ExpandListArgument(cge->Evaluate(
+        this->LocalGenerator, config), dirs);
+    }
+  this->AddDirectoryInstallRule(os, config, indent, dirs);
 }
 
 void cmInstallDirectoryGenerator::AddDirectoryInstallRule(
   std::ostream& os,
   const std::string& config,
-  Indent const& indent)
+  Indent const& indent,
+  std::vector<std::string> const& dirs)
 {
   // Write code to install the directories.
   const char* no_rename = 0;
   this->AddInstallRule(os,
                        this->GetDestination(config),
                        cmInstallType_DIRECTORY,
-                       this->Directories,
+                       dirs,
                        this->Optional,
                        this->FilePermissions.c_str(),
                        this->DirPermissions.c_str(),
@@ -97,5 +116,5 @@ cmInstallDirectoryGenerator::GetDestination(std::string const& config) const
 {
   cmGeneratorExpression ge;
   return ge.Parse(this->Destination)
-    ->Evaluate(this->LocalGenerator->GetMakefile(), config);
+    ->Evaluate(this->LocalGenerator, config);
 }
diff --git a/Source/cmInstallDirectoryGenerator.h b/Source/cmInstallDirectoryGenerator.h
index 04107e1..9b732d3 100644
--- a/Source/cmInstallDirectoryGenerator.h
+++ b/Source/cmInstallDirectoryGenerator.h
@@ -42,7 +42,8 @@ protected:
                                        Indent const& indent);
   void AddDirectoryInstallRule(std::ostream& os,
                                const std::string& config,
-                               Indent const& indent);
+                               Indent const& indent,
+                               std::vector<std::string> const& dirs);
   cmLocalGenerator* LocalGenerator;
   std::vector<std::string> Directories;
   std::string FilePermissions;
diff --git a/Source/cmInstallExportGenerator.cxx b/Source/cmInstallExportGenerator.cxx
index 97b9405..9570ba3 100644
--- a/Source/cmInstallExportGenerator.cxx
+++ b/Source/cmInstallExportGenerator.cxx
@@ -56,6 +56,7 @@ cmInstallExportGenerator::~cmInstallExportGenerator()
 void cmInstallExportGenerator::Compute(cmLocalGenerator* lg)
 {
   this->LocalGenerator = lg;
+  this->ExportSet->Compute(lg);
 }
 
 //----------------------------------------------------------------------------
@@ -64,7 +65,7 @@ void cmInstallExportGenerator::ComputeTempDir()
   // Choose a temporary directory in which to generate the import
   // files to be installed.
   this->TempDir =
-      this->LocalGenerator->GetMakefile()->GetCurrentBinaryDirectory();
+      this->LocalGenerator->GetCurrentBinaryDirectory();
   this->TempDir += cmake::GetCMakeFilesDirectory();
   this->TempDir += "/Export";
   if(this->Destination.empty())
diff --git a/Source/cmInstallFilesGenerator.cxx b/Source/cmInstallFilesGenerator.cxx
index e2c16c8..383031b 100644
--- a/Source/cmInstallFilesGenerator.cxx
+++ b/Source/cmInstallFilesGenerator.cxx
@@ -68,7 +68,7 @@ cmInstallFilesGenerator::GetDestination(std::string const& config) const
 {
   cmGeneratorExpression ge;
   return ge.Parse(this->Destination)
-    ->Evaluate(this->LocalGenerator->GetMakefile(), config);
+    ->Evaluate(this->LocalGenerator, config);
 }
 
 //----------------------------------------------------------------------------
@@ -117,7 +117,7 @@ void cmInstallFilesGenerator::GenerateScriptForConfig(std::ostream& os,
     {
     cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*i);
     cmSystemTools::ExpandListArgument(cge->Evaluate(
-        this->LocalGenerator->GetMakefile(), config), files);
+        this->LocalGenerator, config), files);
     }
   this->AddFilesInstallRule(os, config, indent, files);
 }
diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx
index 30cf175..5e88fa2 100644
--- a/Source/cmInstallTargetGenerator.cxx
+++ b/Source/cmInstallTargetGenerator.cxx
@@ -76,14 +76,14 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
   if(this->Target->NeedRelinkBeforeInstall(config))
     {
     fromDirConfig =
-        this->Target->Target->GetMakefile()->GetCurrentBinaryDirectory();
+        this->Target->GetLocalGenerator()->GetCurrentBinaryDirectory();
     fromDirConfig += cmake::GetCMakeFilesDirectory();
     fromDirConfig += "/CMakeRelink.dir/";
     }
   else
     {
     fromDirConfig =
-        this->Target->Target->GetDirectory(config, this->ImportLibrary);
+        this->Target->GetDirectory(config, this->ImportLibrary);
     fromDirConfig += "/";
     }
   std::string toDir =
@@ -94,29 +94,28 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
   std::vector<std::string> filesFrom;
   std::vector<std::string> filesTo;
   std::string literal_args;
-  cmTarget::TargetType targetType =
-      static_cast<cmTarget::TargetType>(this->Target->GetType());
+  cmState::TargetType targetType = this->Target->GetType();
   cmInstallType type = cmInstallType();
   switch(targetType)
     {
-    case cmTarget::EXECUTABLE: type = cmInstallType_EXECUTABLE; break;
-    case cmTarget::STATIC_LIBRARY: type = cmInstallType_STATIC_LIBRARY; break;
-    case cmTarget::SHARED_LIBRARY: type = cmInstallType_SHARED_LIBRARY; break;
-    case cmTarget::MODULE_LIBRARY: type = cmInstallType_MODULE_LIBRARY; break;
-    case cmTarget::INTERFACE_LIBRARY:
+    case cmState::EXECUTABLE: type = cmInstallType_EXECUTABLE; break;
+    case cmState::STATIC_LIBRARY: type = cmInstallType_STATIC_LIBRARY; break;
+    case cmState::SHARED_LIBRARY: type = cmInstallType_SHARED_LIBRARY; break;
+    case cmState::MODULE_LIBRARY: type = cmInstallType_MODULE_LIBRARY; break;
+    case cmState::INTERFACE_LIBRARY:
       // Not reachable. We never create a cmInstallTargetGenerator for
       // an INTERFACE_LIBRARY.
       assert(0 && "INTERFACE_LIBRARY targets have no installable outputs.");
       break;
-    case cmTarget::OBJECT_LIBRARY:
-    case cmTarget::UTILITY:
-    case cmTarget::GLOBAL_TARGET:
-    case cmTarget::UNKNOWN_LIBRARY:
-      this->Target->Target->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR,
+    case cmState::OBJECT_LIBRARY:
+    case cmState::UTILITY:
+    case cmState::GLOBAL_TARGET:
+    case cmState::UNKNOWN_LIBRARY:
+      this->Target->GetLocalGenerator()->IssueMessage(cmake::INTERNAL_ERROR,
         "cmInstallTargetGenerator created with non-installable target.");
       return;
     }
-  if(targetType == cmTarget::EXECUTABLE)
+  if(targetType == cmState::EXECUTABLE)
     {
     // There is a bug in cmInstallCommand if this fails.
     assert(this->NamelinkMode == NamelinkModeNone);
@@ -135,7 +134,7 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
       filesFrom.push_back(from1);
       filesTo.push_back(to1);
       std::string targetNameImportLib;
-      if(this->Target->Target->GetImplibGNUtoMS(targetNameImport,
+      if(this->Target->GetImplibGNUtoMS(targetNameImport,
                                         targetNameImportLib))
         {
         filesFrom.push_back(fromDirConfig + targetNameImportLib);
@@ -151,15 +150,21 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
       std::string to1 = toDir + targetName;
 
       // Handle OSX Bundles.
-      if(this->Target->Target->IsAppBundleOnApple())
+      if(this->Target->IsAppBundleOnApple())
         {
+        cmMakefile const* mf = this->Target->Target->GetMakefile();
+
         // Install the whole app bundle directory.
         type = cmInstallType_DIRECTORY;
         literal_args += " USE_SOURCE_PERMISSIONS";
         from1 += ".app";
 
         // Tweaks apply to the binary inside the bundle.
-        to1 += ".app/Contents/MacOS/";
+        to1 += ".app/";
+        if(!mf->PlatformIsAppleIos())
+          {
+          to1 += "Contents/MacOS/";
+          }
         to1 += targetName;
         }
       else
@@ -199,7 +204,7 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
       filesFrom.push_back(from1);
       filesTo.push_back(to1);
       std::string targetNameImportLib;
-      if(this->Target->Target->GetImplibGNUtoMS(targetNameImport,
+      if(this->Target->GetImplibGNUtoMS(targetNameImport,
                                         targetNameImportLib))
         {
         filesFrom.push_back(fromDirConfig + targetNameImportLib);
@@ -209,7 +214,7 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
       // An import library looks like a static library.
       type = cmInstallType_STATIC_LIBRARY;
       }
-    else if(this->Target->Target->IsFrameworkOnApple())
+    else if(this->Target->IsFrameworkOnApple())
       {
       // There is a bug in cmInstallCommand if this fails.
       assert(this->NamelinkMode == NamelinkModeNone);
@@ -227,7 +232,7 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
       filesFrom.push_back(from1);
       filesTo.push_back(to1);
       }
-    else if(this->Target->Target->IsCFBundleOnApple())
+    else if(this->Target->IsCFBundleOnApple())
       {
       // Install the whole app bundle directory.
       type = cmInstallType_DIRECTORY;
@@ -351,7 +356,7 @@ cmInstallTargetGenerator::GetDestination(std::string const& config) const
 {
   cmGeneratorExpression ge;
   return ge.Parse(this->Destination)
-    ->Evaluate(this->Target->Target->GetMakefile(), config);
+    ->Evaluate(this->Target->GetLocalGenerator(), config);
 }
 
 //----------------------------------------------------------------------------
@@ -360,28 +365,25 @@ cmInstallTargetGenerator::GetInstallFilename(const std::string& config) const
 {
   NameType nameType = this->ImportLibrary? NameImplib : NameNormal;
   return
-    cmInstallTargetGenerator::GetInstallFilename(this->Target->Target, config,
+    cmInstallTargetGenerator::GetInstallFilename(this->Target, config,
                                                  nameType);
 }
 
 //----------------------------------------------------------------------------
 std::string
-cmInstallTargetGenerator::GetInstallFilename(cmTarget const* target,
+cmInstallTargetGenerator::GetInstallFilename(cmGeneratorTarget const* target,
                                              const std::string& config,
                                              NameType nameType)
 {
   std::string fname;
   // Compute the name of the library.
-  cmGeneratorTarget *gtgt = target->GetMakefile()
-                                  ->GetGlobalGenerator()
-                                  ->GetGeneratorTarget(target);
-  if(target->GetType() == cmTarget::EXECUTABLE)
+  if(target->GetType() == cmState::EXECUTABLE)
     {
     std::string targetName;
     std::string targetNameReal;
     std::string targetNameImport;
     std::string targetNamePDB;
-    gtgt->GetExecutableNames(targetName, targetNameReal,
+    target->GetExecutableNames(targetName, targetNameReal,
                                targetNameImport, targetNamePDB,
                                config);
     if(nameType == NameImplib)
@@ -411,7 +413,7 @@ cmInstallTargetGenerator::GetInstallFilename(cmTarget const* target,
     std::string targetNameReal;
     std::string targetNameImport;
     std::string targetNamePDB;
-    gtgt->GetLibraryNames(targetName, targetNameSO, targetNameReal,
+    target->GetLibraryNames(targetName, targetNameSO, targetNameReal,
                             targetNameImport, targetNamePDB, config);
     if(nameType == NameImplib)
       {
@@ -444,8 +446,7 @@ cmInstallTargetGenerator::GetInstallFilename(cmTarget const* target,
 
 void cmInstallTargetGenerator::Compute(cmLocalGenerator* lg)
 {
-  this->Target = lg->GetGlobalGenerator()->GetGeneratorTarget(
-        lg->GetMakefile()->FindTarget(this->TargetName));
+  this->Target = lg->FindGeneratorTarget(this->TargetName);
 }
 
 //----------------------------------------------------------------------------
@@ -530,6 +531,7 @@ void cmInstallTargetGenerator::PostReplacementTweaks(std::ostream& os,
 {
   this->AddInstallNamePatchRule(os, indent, config, file);
   this->AddChrpathPatchRule(os, indent, config, file);
+  this->AddUniversalInstallRule(os, indent, file);
   this->AddRanlibRule(os, indent, file);
   this->AddStripRule(os, indent, file);
 }
@@ -542,9 +544,9 @@ cmInstallTargetGenerator
                           std::string const& toDestDirPath)
 {
   if(this->ImportLibrary ||
-     !(this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
-       this->Target->GetType() == cmTarget::MODULE_LIBRARY ||
-       this->Target->GetType() == cmTarget::EXECUTABLE))
+     !(this->Target->GetType() == cmState::SHARED_LIBRARY ||
+       this->Target->GetType() == cmState::MODULE_LIBRARY ||
+       this->Target->GetType() == cmState::EXECUTABLE))
     {
     return;
     }
@@ -563,12 +565,12 @@ cmInstallTargetGenerator
   std::map<std::string, std::string> install_name_remap;
   if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(config))
     {
-    std::set<cmTarget const*> const& sharedLibs
+    std::set<cmGeneratorTarget const*> const& sharedLibs
                                             = cli->GetSharedLibrariesLinked();
-    for(std::set<cmTarget const*>::const_iterator j = sharedLibs.begin();
-        j != sharedLibs.end(); ++j)
+    for(std::set<cmGeneratorTarget const*>::const_iterator j
+        = sharedLibs.begin(); j != sharedLibs.end(); ++j)
       {
-      cmTarget const* tgt = *j;
+      cmGeneratorTarget const* tgt = *j;
 
       // The install_name of an imported target does not change.
       if(tgt->IsImported())
@@ -576,14 +578,11 @@ cmInstallTargetGenerator
         continue;
         }
 
-      cmGeneratorTarget *gtgt = tgt->GetMakefile()
-                                          ->GetGlobalGenerator()
-                                          ->GetGeneratorTarget(tgt);
       // If the build tree and install tree use different path
       // components of the install_name field then we need to create a
       // mapping to be applied after installation.
-      std::string for_build = gtgt->GetInstallNameDirForBuildTree(config);
-      std::string for_install = gtgt->GetInstallNameDirForInstallTree();
+      std::string for_build = tgt->GetInstallNameDirForBuildTree(config);
+      std::string for_install = tgt->GetInstallNameDirForInstallTree();
       if(for_build != for_install)
         {
         // The directory portions differ.  Append the filename to
@@ -605,14 +604,14 @@ cmInstallTargetGenerator
 
   // Edit the install_name of the target itself if necessary.
   std::string new_id;
-  if(this->Target->GetType() == cmTarget::SHARED_LIBRARY)
+  if(this->Target->GetType() == cmState::SHARED_LIBRARY)
     {
     std::string for_build =
       this->Target->GetInstallNameDirForBuildTree(config);
     std::string for_install =
       this->Target->GetInstallNameDirForInstallTree();
 
-    if(this->Target->Target->IsFrameworkOnApple() && for_install.empty())
+    if(this->Target->IsFrameworkOnApple() && for_install.empty())
       {
       // Frameworks seem to have an id corresponding to their own full
       // path.
@@ -626,7 +625,7 @@ cmInstallTargetGenerator
       {
       // Prepare to refer to the install-tree install_name.
       new_id = for_install;
-      new_id += this->GetInstallFilename(this->Target->Target, config, NameSO);
+      new_id += this->GetInstallFilename(this->Target, config, NameSO);
       }
     }
 
@@ -792,18 +791,10 @@ cmInstallTargetGenerator
       }
 
     // Write a rule to run chrpath to set the install-tree RPATH
-    if(newRpath.empty())
-      {
-      os << indent << "file(RPATH_REMOVE\n"
-         << indent << "     FILE \"" << toDestDirPath << "\")\n";
-      }
-    else
-      {
-      os << indent << "file(RPATH_CHANGE\n"
-         << indent << "     FILE \"" << toDestDirPath << "\"\n"
-         << indent << "     OLD_RPATH \"" << oldRpath << "\"\n"
-         << indent << "     NEW_RPATH \"" << newRpath << "\")\n";
-      }
+    os << indent << "file(RPATH_CHANGE\n"
+       << indent << "     FILE \"" << toDestDirPath << "\"\n"
+       << indent << "     OLD_RPATH \"" << oldRpath << "\"\n"
+       << indent << "     NEW_RPATH \"" << newRpath << "\")\n";
     }
 }
 
@@ -816,14 +807,14 @@ cmInstallTargetGenerator::AddStripRule(std::ostream& os,
 
   // don't strip static and import libraries, because it removes the only
   // symbol table they have so you can't link to them anymore
-  if(this->Target->GetType()==cmTarget::STATIC_LIBRARY || this->ImportLibrary)
+  if(this->Target->GetType()==cmState::STATIC_LIBRARY || this->ImportLibrary)
     {
     return;
     }
 
   // Don't handle OSX Bundles.
   if(this->Target->Target->GetMakefile()->IsOn("APPLE") &&
-     this->Target->Target->GetPropertyAsBool("MACOSX_BUNDLE"))
+     this->Target->GetPropertyAsBool("MACOSX_BUNDLE"))
     {
     return;
     }
@@ -847,7 +838,7 @@ cmInstallTargetGenerator::AddRanlibRule(std::ostream& os,
                                         const std::string& toDestDirPath)
 {
   // Static libraries need ranlib on this platform.
-  if(this->Target->GetType() != cmTarget::STATIC_LIBRARY)
+  if(this->Target->GetType() != cmState::STATIC_LIBRARY)
     {
     return;
     }
@@ -869,3 +860,46 @@ cmInstallTargetGenerator::AddRanlibRule(std::ostream& os,
   os << indent << "execute_process(COMMAND \""
      << ranlib << "\" \"" << toDestDirPath << "\")\n";
 }
+
+//----------------------------------------------------------------------------
+void
+cmInstallTargetGenerator
+::AddUniversalInstallRule(std::ostream& os,
+                          Indent const& indent,
+                          const std::string& toDestDirPath)
+{
+  cmMakefile const* mf = this->Target->Target->GetMakefile();
+
+  if(!mf->PlatformIsAppleIos() || !mf->IsOn("XCODE"))
+    {
+    return;
+    }
+
+  const char* xcodeVersion = mf->GetDefinition("XCODE_VERSION");
+  if(!xcodeVersion || cmSystemTools::VersionCompareGreater("6", xcodeVersion))
+    {
+    return;
+    }
+
+  switch(this->Target->GetType())
+    {
+    case cmState::EXECUTABLE:
+    case cmState::STATIC_LIBRARY:
+    case cmState::SHARED_LIBRARY:
+    case cmState::MODULE_LIBRARY:
+      break;
+
+    default:
+      return;
+    }
+
+  if(!this->Target->Target->GetPropertyAsBool("IOS_INSTALL_COMBINED"))
+   {
+   return;
+   }
+
+  os << indent << "include(CMakeIOSInstallCombined)\n";
+  os << indent << "ios_install_combined("
+               << "\"" << this->Target->Target->GetName() << "\" "
+               << "\"" << toDestDirPath << "\")\n";
+}
diff --git a/Source/cmInstallTargetGenerator.h b/Source/cmInstallTargetGenerator.h
index a8f4a75..18b3130 100644
--- a/Source/cmInstallTargetGenerator.h
+++ b/Source/cmInstallTargetGenerator.h
@@ -14,7 +14,6 @@
 
 #include "cmInstallGenerator.h"
 
-class cmTarget;
 class cmGeneratorTarget;
 
 /** \class cmInstallTargetGenerator
@@ -54,7 +53,7 @@ public:
     NameReal
   };
 
-  static std::string GetInstallFilename(cmTarget const* target,
+  static std::string GetInstallFilename(const cmGeneratorTarget* target,
                                         const std::string& config,
                                         NameType nameType = NameNormal);
 
@@ -102,6 +101,8 @@ protected:
                     const std::string& toDestDirPath);
   void AddRanlibRule(std::ostream& os, Indent const& indent,
                      const std::string& toDestDirPath);
+  void AddUniversalInstallRule(std::ostream& os, Indent const& indent,
+                               const std::string& toDestDirPath);
 
   std::string TargetName;
   cmGeneratorTarget* Target;
diff --git a/Source/cmLinkItem.h b/Source/cmLinkItem.h
index 10dd465..b603bcc 100644
--- a/Source/cmLinkItem.h
+++ b/Source/cmLinkItem.h
@@ -14,8 +14,9 @@
 #define cmLinkItem_h
 
 #include "cmListFileCache.h"
+#include "cmSystemTools.h"
 
-class cmTarget;
+class cmGeneratorTarget;
 
 // Basic information about each link item.
 class cmLinkItem: public std::string
@@ -24,9 +25,9 @@ class cmLinkItem: public std::string
 public:
   cmLinkItem(): std_string(), Target(0) {}
   cmLinkItem(const std_string& n,
-             cmTarget const* t): std_string(n), Target(t) {}
+             cmGeneratorTarget const* t): std_string(n), Target(t) {}
   cmLinkItem(cmLinkItem const& r): std_string(r), Target(r.Target) {}
-  cmTarget const* Target;
+  cmGeneratorTarget const* Target;
 };
 
 class cmLinkImplItem: public cmLinkItem
@@ -34,7 +35,7 @@ class cmLinkImplItem: public cmLinkItem
 public:
   cmLinkImplItem(): cmLinkItem(), Backtrace(), FromGenex(false) {}
   cmLinkImplItem(std::string const& n,
-                 cmTarget const* t,
+                 cmGeneratorTarget const* t,
                  cmListFileBacktrace const& bt,
                  bool fromGenex):
     cmLinkItem(n, t), Backtrace(bt), FromGenex(fromGenex) {}
@@ -97,7 +98,7 @@ struct cmOptionalLinkInterface: public cmLinkInterface
 };
 
 struct cmHeadToLinkInterfaceMap:
-    public std::map<cmTarget const*, cmOptionalLinkInterface>
+    public std::map<cmGeneratorTarget const*, cmOptionalLinkInterface>
 {
 };
 
@@ -118,4 +119,27 @@ struct cmOptionalLinkImplementation: public cmLinkImplementation
   bool HadHeadSensitiveCondition;
 };
 
+/** Compute the link type to use for the given configuration.  */
+inline cmTargetLinkLibraryType
+CMP0003_ComputeLinkType(const std::string& config,
+                        std::vector<std::string> const& debugConfigs)
+{
+  // No configuration is always optimized.
+  if(config.empty())
+    {
+    return OPTIMIZED_LibraryType;
+    }
+
+  // Check if any entry in the list matches this configuration.
+  std::string configUpper = cmSystemTools::UpperCase(config);
+  if (std::find(debugConfigs.begin(), debugConfigs.end(), configUpper) !=
+      debugConfigs.end())
+    {
+    return DEBUG_LibraryType;
+    }
+  // The current configuration is not a debug configuration.
+  return OPTIMIZED_LibraryType;
+}
+
+
 #endif
diff --git a/Source/cmLinkLibrariesCommand.cxx b/Source/cmLinkLibrariesCommand.cxx
index 996b538..eb3bfce 100644
--- a/Source/cmLinkLibrariesCommand.cxx
+++ b/Source/cmLinkLibrariesCommand.cxx
@@ -34,7 +34,7 @@ bool cmLinkLibrariesCommand
         return false;
         }
       this->Makefile->AddLinkLibrary(*i,
-                                 cmTarget::DEBUG);
+                                 DEBUG_LibraryType);
       }
     else if (*i == "optimized")
       {
@@ -46,7 +46,7 @@ bool cmLinkLibrariesCommand
         return false;
         }
       this->Makefile->AddLinkLibrary(*i,
-                                 cmTarget::OPTIMIZED);
+                                 OPTIMIZED_LibraryType);
       }
     else
       {
diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx
index 1465f90..7ba61f3 100644
--- a/Source/cmListFileCache.cxx
+++ b/Source/cmListFileCache.cxx
@@ -12,7 +12,7 @@
 #include "cmListFileCache.h"
 
 #include "cmListFileLexer.h"
-#include "cmLocalGenerator.h"
+#include "cmOutputConverter.h"
 #include "cmSystemTools.h"
 #include "cmMakefile.h"
 #include "cmVersion.h"
diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h
index 17ee10f..03e0abe 100644
--- a/Source/cmListFileCache.h
+++ b/Source/cmListFileCache.h
@@ -109,13 +109,4 @@ struct cmListFile
   std::vector<cmListFileFunction> Functions;
 };
 
-struct cmValueWithOrigin {
-  cmValueWithOrigin(const std::string &value,
-                          const cmListFileBacktrace &bt)
-    : Value(value), Backtrace(bt)
-  {}
-  std::string Value;
-  cmListFileBacktrace Backtrace;
-};
-
 #endif
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 233e7fe..912be0c 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -51,6 +51,8 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg,
 
   this->Makefile = makefile;
 
+  this->AliasTargets = makefile->GetAliasTargets();
+
   this->EmitUniversalBinaryFlags = true;
   this->BackwardsCompatibility = 0;
   this->BackwardsCompatibilityFinal = false;
@@ -60,6 +62,8 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg,
 
 cmLocalGenerator::~cmLocalGenerator()
 {
+  cmDeleteAll(this->GeneratorTargets);
+  cmDeleteAll(this->OwnedImportedGeneratorTargets);
 }
 
 void cmLocalGenerator::IssueMessage(cmake::MessageType t,
@@ -132,16 +136,15 @@ void cmLocalGenerator::TraceDependencies()
     this->GlobalGenerator->CreateEvaluationSourceFiles(*ci);
     }
   // Generate the rule files for each target.
-  cmGeneratorTargetsType targets = this->Makefile->GetGeneratorTargets();
-  for(cmGeneratorTargetsType::iterator t = targets.begin();
+  std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
+  for(std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
       t != targets.end(); ++t)
     {
-    if (t->second->Target->IsImported()
-        || t->second->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
+    if ((*t)->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
-    t->second->TraceDependencies();
+    (*t)->TraceDependencies();
     }
 }
 
@@ -448,6 +451,65 @@ void cmLocalGenerator::GenerateInstallRules()
     }
 }
 
+
+void cmLocalGenerator::AddGeneratorTarget(cmGeneratorTarget* gt)
+{
+  this->GeneratorTargets.push_back(gt);
+  this->GlobalGenerator->IndexGeneratorTarget(gt);
+}
+
+void cmLocalGenerator::AddImportedGeneratorTarget(cmGeneratorTarget* gt)
+{
+  this->ImportedGeneratorTargets.push_back(gt);
+  this->GlobalGenerator->IndexGeneratorTarget(gt);
+}
+
+void cmLocalGenerator::AddOwnedImportedGeneratorTarget(cmGeneratorTarget* gt)
+{
+  this->OwnedImportedGeneratorTargets.push_back(gt);
+}
+
+struct NamedGeneratorTargetFinder
+{
+  NamedGeneratorTargetFinder(std::string const& name)
+    : Name(name)
+  {
+
+  }
+
+  bool operator()(cmGeneratorTarget* tgt)
+  {
+    return tgt->GetName() == this->Name;
+  }
+private:
+  std::string Name;
+};
+
+cmGeneratorTarget* cmLocalGenerator::FindGeneratorTarget(
+    const std::string& name) const
+{
+  std::map<std::string, std::string>::const_iterator i =
+      this->AliasTargets.find(name);
+  if (i != this->AliasTargets.end())
+    {
+    std::vector<cmGeneratorTarget*>::const_iterator ai =
+        std::find_if(this->GeneratorTargets.begin(),
+                     this->GeneratorTargets.end(),
+                     NamedGeneratorTargetFinder(i->second));
+    return *ai;
+    }
+  std::vector<cmGeneratorTarget*>::const_iterator ti =
+      std::find_if(this->GeneratorTargets.begin(),
+                   this->GeneratorTargets.end(),
+                   NamedGeneratorTargetFinder(name));
+  if ( ti != this->GeneratorTargets.end() )
+    {
+    return *ti;
+    }
+
+  return 0;
+}
+
 //----------------------------------------------------------------------------
 void cmLocalGenerator::ComputeTargetManifest()
 {
@@ -460,16 +522,12 @@ void cmLocalGenerator::ComputeTargetManifest()
     }
 
   // Add our targets to the manifest for each configuration.
-  cmGeneratorTargetsType targets = this->Makefile->GetGeneratorTargets();
-  for(cmGeneratorTargetsType::iterator t = targets.begin();
+  std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
+  for(std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
       t != targets.end(); ++t)
     {
-    cmGeneratorTarget& target = *t->second;
-    if (target.Target->GetType() == cmTarget::INTERFACE_LIBRARY)
-      {
-      continue;
-      }
-    if (target.Target->IsImported())
+    cmGeneratorTarget* target = *t;
+    if (target->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
@@ -477,11 +535,16 @@ void cmLocalGenerator::ComputeTargetManifest()
         ci != configNames.end(); ++ci)
       {
       const char* config = ci->c_str();
-      target.ComputeTargetManifest(config);
+      target->ComputeTargetManifest(config);
       }
     }
 }
 
+bool cmLocalGenerator::IsRootMakefile() const
+{
+  return !this->StateSnapshot.GetBuildsystemDirectoryParent().IsValid();
+}
+
 cmState* cmLocalGenerator::GetState() const
 {
   return this->GlobalGenerator->GetCMakeInstance()->GetState();
@@ -753,7 +816,7 @@ cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
       }
     if(variable == "TARGET_TYPE")
       {
-      return cmTarget::GetTargetTypeName(replaceValues.CMTarget->GetType());
+      return cmState::GetTargetTypeName(replaceValues.CMTarget->GetType());
       }
     }
   if(replaceValues.Output)
@@ -913,7 +976,7 @@ cmLocalGenerator::ExpandRuleVariables(std::string& s,
 }
 
 //----------------------------------------------------------------------------
-const char* cmLocalGenerator::GetRuleLauncher(cmTarget* target,
+const char* cmLocalGenerator::GetRuleLauncher(cmGeneratorTarget* target,
                                               const std::string& prop)
 {
   if(target)
@@ -927,7 +990,8 @@ const char* cmLocalGenerator::GetRuleLauncher(cmTarget* target,
 }
 
 //----------------------------------------------------------------------------
-void cmLocalGenerator::InsertRuleLauncher(std::string& s, cmTarget* target,
+void cmLocalGenerator::InsertRuleLauncher(std::string& s,
+                                          cmGeneratorTarget* target,
                                           const std::string& prop)
 {
   if(const char* val = this->GetRuleLauncher(target, prop))
@@ -1080,27 +1144,23 @@ std::string cmLocalGenerator::GetIncludeFlags(
 
 //----------------------------------------------------------------------------
 void cmLocalGenerator::AddCompileDefinitions(std::set<std::string>& defines,
-                                             cmTarget const* target,
+                                             cmGeneratorTarget const* target,
                                              const std::string& config,
                                              const std::string& lang)
 {
   std::vector<std::string> targetDefines;
-  cmGeneratorTarget* gtgt = this->GlobalGenerator->GetGeneratorTarget(target);
-  gtgt->GetCompileDefinitions(targetDefines, config, lang);
+  target->GetCompileDefinitions(targetDefines, config, lang);
   this->AppendDefines(defines, targetDefines);
 }
 
 //----------------------------------------------------------------------------
 void cmLocalGenerator::AddCompileOptions(
-  std::string& flags, cmTarget* target,
+  std::string& flags, cmGeneratorTarget* target,
   const std::string& lang, const std::string& config
   )
 {
   std::string langFlagRegexVar = std::string("CMAKE_")+lang+"_FLAG_REGEX";
 
-  cmGeneratorTarget* gtgt =
-      this->GlobalGenerator->GetGeneratorTarget(target);
-
   if(const char* langFlagRegexStr =
      this->Makefile->GetDefinition(langFlagRegexVar))
     {
@@ -1111,7 +1171,7 @@ void cmLocalGenerator::AddCompileOptions(
       {
       cmSystemTools::ParseWindowsCommandLine(targetFlags, opts);
       }
-    gtgt->GetCompileOptions(opts, config, lang);
+    target->GetCompileOptions(opts, config, lang);
     for(std::vector<std::string>::const_iterator i = opts.begin();
         i != opts.end(); ++i)
       {
@@ -1132,7 +1192,7 @@ void cmLocalGenerator::AddCompileOptions(
       this->AppendFlags(flags, targetFlags);
       }
     std::vector<std::string> opts;
-    gtgt->GetCompileOptions(opts, config, lang);
+    target->GetCompileOptions(opts, config, lang);
     for(std::vector<std::string>::const_iterator i = opts.begin();
         i != opts.end(); ++i)
       {
@@ -1141,11 +1201,11 @@ void cmLocalGenerator::AddCompileOptions(
       }
     }
   std::vector<std::string> features;
-  gtgt->GetCompileFeatures(features, config);
+  target->GetCompileFeatures(features, config);
   for(std::vector<std::string>::const_iterator it = features.begin();
       it != features.end(); ++it)
     {
-     if (!this->Makefile->AddRequiredTargetFeature(target, *it))
+     if (!this->Makefile->AddRequiredTargetFeature(target->Target, *it))
       {
       return;
       }
@@ -1180,7 +1240,7 @@ void cmLocalGenerator::AddCompileOptions(
 
 //----------------------------------------------------------------------------
 void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
-                                             cmGeneratorTarget* target,
+                                             cmGeneratorTarget const* target,
                                              const std::string& lang,
                                              const std::string& config,
                                              bool stripImplicitInclDirs
@@ -1307,7 +1367,7 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
 
 void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags,
                                              std::string const& config,
-                                             cmTarget* target)
+                                             cmGeneratorTarget* target)
 {
   this->AppendFlags(flags,
     this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS"));
@@ -1340,12 +1400,12 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
 
   switch(target->GetType())
     {
-    case cmTarget::STATIC_LIBRARY:
-      this->GetStaticLibraryFlags(linkFlags, buildType, target->Target);
+    case cmState::STATIC_LIBRARY:
+      this->GetStaticLibraryFlags(linkFlags, buildType, target);
       break;
-    case cmTarget::MODULE_LIBRARY:
+    case cmState::MODULE_LIBRARY:
       libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
-    case cmTarget::SHARED_LIBRARY:
+    case cmState::SHARED_LIBRARY:
       {
       linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
       linkFlags += " ";
@@ -1397,7 +1457,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
                                 *target, false, false, useWatcomQuote);
       }
       break;
-    case cmTarget::EXECUTABLE:
+    case cmState::EXECUTABLE:
       {
       linkFlags +=
         this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
@@ -1414,7 +1474,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
         {
         cmSystemTools::Error
           ("CMake can not determine linker language for target: ",
-           target->Target->GetName().c_str());
+           target->GetName().c_str());
         return;
         }
       this->AddLanguageFlags(flags, linkLanguage, buildType);
@@ -1440,7 +1500,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
           this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
         linkFlags += " ";
         }
-      if (target->Target->IsExecutableWithExports())
+      if (target->IsExecutableWithExports())
         {
         std::string exportFlagVar = "CMAKE_EXE_EXPORTS_";
         exportFlagVar += linkLanguage;
@@ -1542,12 +1602,12 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
     this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
 
   // Flags to link an executable to shared libraries.
-  if (tgt.GetType() == cmTarget::EXECUTABLE &&
+  if (tgt.GetType() == cmState::EXECUTABLE &&
       this->StateSnapshot.GetState()->
         GetGlobalPropertyAsBool("TARGET_SUPPORTS_SHARED_LIBS"))
     {
     bool add_shlib_flags = false;
-    switch(tgt.Target->GetPolicyStatusCMP0065())
+    switch(tgt.GetPolicyStatusCMP0065())
       {
       case cmPolicies::WARN:
         if(!tgt.GetPropertyAsBool("ENABLE_EXPORTS") &&
@@ -1624,7 +1684,7 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
   ItemVector const& items = cli.GetItems();
   for(ItemVector::const_iterator li = items.begin(); li != items.end(); ++li)
     {
-    if(li->Target && li->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
+    if(li->Target && li->Target->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
@@ -1767,6 +1827,27 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags,
 }
 
 //----------------------------------------------------------------------------
+cmGeneratorTarget*
+cmLocalGenerator::FindGeneratorTargetToUse(const std::string& name) const
+{
+  std::vector<cmGeneratorTarget*>::const_iterator
+    imported = std::find_if(this->ImportedGeneratorTargets.begin(),
+                            this->ImportedGeneratorTargets.end(),
+                            NamedGeneratorTargetFinder(name));
+  if(imported != this->ImportedGeneratorTargets.end())
+    {
+    return *imported;
+    }
+
+  if(cmGeneratorTarget* t = this->FindGeneratorTarget(name))
+    {
+    return t;
+    }
+
+  return this->GetGlobalGenerator()->FindGeneratorTarget(name);
+}
+
+//----------------------------------------------------------------------------
 bool cmLocalGenerator::GetRealDependency(const std::string& inName,
                                          const std::string& config,
                                          std::string& dep)
@@ -1792,15 +1873,15 @@ bool cmLocalGenerator::GetRealDependency(const std::string& inName,
 
   // Look for a CMake target with the given name.
   if(cmGeneratorTarget* target =
-     this->Makefile->FindGeneratorTargetToUse(name))
+     this->FindGeneratorTargetToUse(name))
     {
     // make sure it is not just a coincidence that the target name
     // found is part of the inName
     if(cmSystemTools::FileIsFullPath(inName.c_str()))
       {
       std::string tLocation;
-      if(target->GetType() >= cmTarget::EXECUTABLE &&
-         target->GetType() <= cmTarget::MODULE_LIBRARY)
+      if(target->GetType() >= cmState::EXECUTABLE &&
+         target->GetType() <= cmState::MODULE_LIBRARY)
         {
         tLocation = target->GetLocation(config);
         tLocation = cmSystemTools::GetFilenamePath(tLocation);
@@ -1820,23 +1901,23 @@ bool cmLocalGenerator::GetRealDependency(const std::string& inName,
       }
     switch (target->GetType())
       {
-      case cmTarget::EXECUTABLE:
-      case cmTarget::STATIC_LIBRARY:
-      case cmTarget::SHARED_LIBRARY:
-      case cmTarget::MODULE_LIBRARY:
-      case cmTarget::UNKNOWN_LIBRARY:
+      case cmState::EXECUTABLE:
+      case cmState::STATIC_LIBRARY:
+      case cmState::SHARED_LIBRARY:
+      case cmState::MODULE_LIBRARY:
+      case cmState::UNKNOWN_LIBRARY:
         dep = target->GetLocation(config);
         return true;
-      case cmTarget::OBJECT_LIBRARY:
+      case cmState::OBJECT_LIBRARY:
         // An object library has no single file on which to depend.
         // This was listed to get the target-level dependency.
         return false;
-      case cmTarget::INTERFACE_LIBRARY:
+      case cmState::INTERFACE_LIBRARY:
         // An interface library has no file on which to depend.
         // This was listed to get the target-level dependency.
         return false;
-      case cmTarget::UTILITY:
-      case cmTarget::GLOBAL_TARGET:
+      case cmState::UTILITY:
+      case cmState::GLOBAL_TARGET:
         // A utility target has no file on which to depend.  This was listed
         // only to get the target-level dependency.
         return false;
@@ -1886,7 +1967,8 @@ void cmLocalGenerator::AddSharedFlags(std::string& flags,
 
 //----------------------------------------------------------------------------
 void cmLocalGenerator::
-AddCompilerRequirementFlag(std::string &flags, cmTarget const* target,
+AddCompilerRequirementFlag(std::string &flags,
+                           cmGeneratorTarget const* target,
                            const std::string& lang)
 {
   if (lang.empty())
@@ -1924,7 +2006,8 @@ AddCompilerRequirementFlag(std::string &flags, cmTarget const* target,
               "CMAKE_" + lang + standardProp
                       + "_" + type + "_COMPILE_OPTION";
 
-    const char *opt = target->GetMakefile()->GetDefinition(option_flag);
+    const char *opt = target->Target->GetMakefile()
+        ->GetDefinition(option_flag);
     if (!opt)
       {
       std::ostringstream e;
@@ -1989,7 +2072,7 @@ AddCompilerRequirementFlag(std::string &flags, cmTarget const* target,
                       + "_" + type + "_COMPILE_OPTION";
 
     const char *opt =
-        target->GetMakefile()->GetRequiredDefinition(option_flag);
+        target->Target->GetMakefile()->GetRequiredDefinition(option_flag);
     this->AppendFlagEscape(flags, opt);
     return;
     }
@@ -2000,7 +2083,8 @@ AddCompilerRequirementFlag(std::string &flags, cmTarget const* target,
               "CMAKE_" + lang + *stdIt
                       + "_" + type + "_COMPILE_OPTION";
 
-    if (const char *opt = target->GetMakefile()->GetDefinition(option_flag))
+    if (const char *opt = target->Target
+        ->GetMakefile()->GetDefinition(option_flag))
       {
       this->AppendFlagEscape(flags, opt);
       return;
@@ -2009,7 +2093,7 @@ AddCompilerRequirementFlag(std::string &flags, cmTarget const* target,
 }
 
 static void AddVisibilityCompileOption(std::string &flags,
-                                       cmTarget const* target,
+                                       cmGeneratorTarget const* target,
                                        cmLocalGenerator *lg,
                                        const std::string& lang,
                                        std::string* warnCMP0063)
@@ -2049,7 +2133,7 @@ static void AddVisibilityCompileOption(std::string &flags,
 }
 
 static void AddInlineVisibilityCompileOption(std::string &flags,
-                                       cmTarget const* target,
+                                       cmGeneratorTarget const* target,
                                        cmLocalGenerator *lg,
                                        std::string* warnCMP0063)
 {
@@ -2076,7 +2160,7 @@ static void AddInlineVisibilityCompileOption(std::string &flags,
 
 //----------------------------------------------------------------------------
 void cmLocalGenerator
-::AddVisibilityPresetFlags(std::string &flags, cmTarget const* target,
+::AddVisibilityPresetFlags(std::string &flags, cmGeneratorTarget const* target,
                             const std::string& lang)
 {
   if (lang.empty())
@@ -2086,8 +2170,8 @@ void cmLocalGenerator
 
   std::string warnCMP0063;
   std::string *pWarnCMP0063 = 0;
-  if (target->GetType() != cmTarget::SHARED_LIBRARY &&
-      target->GetType() != cmTarget::MODULE_LIBRARY &&
+  if (target->GetType() != cmState::SHARED_LIBRARY &&
+      target->GetType() != cmState::MODULE_LIBRARY &&
       !target->IsExecutableWithExports())
     {
     switch (target->GetPolicyStatusCMP0063())
@@ -2116,25 +2200,26 @@ void cmLocalGenerator
     w <<
       cmPolicies::GetPolicyWarning(cmPolicies::CMP0063) << "\n"
       "Target \"" << target->GetName() << "\" of "
-      "type \"" << cmTarget::GetTargetTypeName(target->GetType()) << "\" "
+      "type \"" << cmState::GetTargetTypeName(target->GetType()) << "\" "
       "has the following visibility properties set for " << lang << ":\n" <<
       warnCMP0063 <<
       "For compatibility CMake is not honoring them for this target.";
-    target->GetMakefile()->GetCMakeInstance()
-      ->IssueMessage(cmake::AUTHOR_WARNING, w.str(), target->GetBacktrace());
+    target->GetLocalGenerator()->GetCMakeInstance()
+      ->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
+                     target->GetBacktrace());
     }
 }
 
 //----------------------------------------------------------------------------
 void cmLocalGenerator::AddCMP0018Flags(std::string &flags,
-                                       cmTarget const* target,
+                                       cmGeneratorTarget const* target,
                                        std::string const& lang,
                                        const std::string& config)
 {
   int targetType = target->GetType();
 
-  bool shared = ((targetType == cmTarget::SHARED_LIBRARY) ||
-                  (targetType == cmTarget::MODULE_LIBRARY));
+  bool shared = ((targetType == cmState::SHARED_LIBRARY) ||
+                  (targetType == cmState::MODULE_LIBRARY));
 
   if (this->GetShouldUseOldFlags(shared, lang))
     {
@@ -2142,7 +2227,7 @@ void cmLocalGenerator::AddCMP0018Flags(std::string &flags,
     }
   else
     {
-    if (target->GetType() == cmTarget::OBJECT_LIBRARY)
+    if (target->GetType() == cmState::OBJECT_LIBRARY)
       {
       if (target->GetPropertyAsBool("POSITION_INDEPENDENT_CODE"))
         {
@@ -2151,9 +2236,7 @@ void cmLocalGenerator::AddCMP0018Flags(std::string &flags,
       return;
       }
 
-    cmGeneratorTarget* gtgt =
-        this->GlobalGenerator->GetGeneratorTarget(target);
-    if (gtgt->GetLinkInterfaceDependentBoolProperty(
+    if (target->GetLinkInterfaceDependentBoolProperty(
                                                 "POSITION_INDEPENDENT_CODE",
                                                 config))
       {
@@ -2182,7 +2265,7 @@ bool cmLocalGenerator::GetShouldUseOldFlags(bool shared,
 
     if (flags && flags != originalFlags)
       {
-      switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0018))
+      switch (this->GetPolicyStatus(cmPolicies::CMP0018))
         {
         case cmPolicies::WARN:
         {
@@ -2216,7 +2299,7 @@ void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags,
 {
   const char* picFlags = 0;
 
-  if(targetType == cmTarget::EXECUTABLE)
+  if(targetType == cmState::EXECUTABLE)
     {
     std::string flagsVar = "CMAKE_";
     flagsVar += lang;
@@ -2431,6 +2514,11 @@ const char* cmLocalGenerator::GetFeature(const std::string& feature,
   return 0;
 }
 
+std::string cmLocalGenerator::GetProjectName() const
+{
+  return this->StateSnapshot.GetProjectName();
+}
+
 //----------------------------------------------------------------------------
 std::string
 cmLocalGenerator::ConstructComment(cmCustomCommandGenerator const& ccg,
@@ -2486,28 +2574,29 @@ cmLocalGenerator
 {
   // Convert the old-style install specification from each target to
   // an install generator and run it.
-  cmTargets& tgts = this->Makefile->GetTargets();
-  for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
+  std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
+  for(std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
+      l != tgts.end(); ++l)
     {
-    if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
+    if ((*l)->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
 
     // Include the user-specified pre-install script for this target.
-    if(const char* preinstall = l->second.GetProperty("PRE_INSTALL_SCRIPT"))
+    if(const char* preinstall = (*l)->GetProperty("PRE_INSTALL_SCRIPT"))
       {
       cmInstallScriptGenerator g(preinstall, false, 0);
       g.Generate(os, config, configurationTypes);
       }
 
     // Install this target if a destination is given.
-    if(l->second.GetInstallPath() != "")
+    if((*l)->Target->GetInstallPath() != "")
       {
       // Compute the full install destination.  Note that converting
       // to unix slashes also removes any trailing slash.
       // We also skip over the leading slash given by the user.
-      std::string destination = l->second.GetInstallPath().substr(1);
+      std::string destination = (*l)->Target->GetInstallPath().substr(1);
       cmSystemTools::ConvertToUnixSlashes(destination);
       if(destination.empty())
         {
@@ -2515,37 +2604,37 @@ cmLocalGenerator
         }
 
       // Generate the proper install generator for this target type.
-      switch(l->second.GetType())
+      switch((*l)->GetType())
         {
-        case cmTarget::EXECUTABLE:
-        case cmTarget::STATIC_LIBRARY:
-        case cmTarget::MODULE_LIBRARY:
+        case cmState::EXECUTABLE:
+        case cmState::STATIC_LIBRARY:
+        case cmState::MODULE_LIBRARY:
           {
           // Use a target install generator.
           cmInstallTargetGeneratorLocal
-            g(this, l->first, destination.c_str(), false);
+            g(this, (*l)->GetName(), destination.c_str(), false);
           g.Generate(os, config, configurationTypes);
           }
           break;
-        case cmTarget::SHARED_LIBRARY:
+        case cmState::SHARED_LIBRARY:
           {
 #if defined(_WIN32) || defined(__CYGWIN__)
           // Special code to handle DLL.  Install the import library
           // to the normal destination and the DLL to the runtime
           // destination.
           cmInstallTargetGeneratorLocal
-            g1(this, l->first, destination.c_str(), true);
+            g1(this, (*l)->GetName(), destination.c_str(), true);
           g1.Generate(os, config, configurationTypes);
           // We also skip over the leading slash given by the user.
-          destination = l->second.GetRuntimeInstallPath().substr(1);
+          destination = (*l)->Target->GetRuntimeInstallPath().substr(1);
           cmSystemTools::ConvertToUnixSlashes(destination);
           cmInstallTargetGeneratorLocal
-            g2(this, l->first, destination.c_str(), false);
+            g2(this, (*l)->GetName(), destination.c_str(), false);
           g2.Generate(os, config, configurationTypes);
 #else
           // Use a target install generator.
           cmInstallTargetGeneratorLocal
-            g(this, l->first, destination.c_str(), false);
+            g(this, (*l)->GetName(), destination.c_str(), false);
           g.Generate(os, config, configurationTypes);
 #endif
           }
@@ -2556,7 +2645,7 @@ cmLocalGenerator
       }
 
     // Include the user-specified post-install script for this target.
-    if(const char* postinstall = l->second.GetProperty("POST_INSTALL_SCRIPT"))
+    if(const char* postinstall = (*l)->GetProperty("POST_INSTALL_SCRIPT"))
       {
       cmInstallScriptGenerator g(postinstall, false, 0);
       g.Generate(os, config, configurationTypes);
@@ -2858,9 +2947,34 @@ cmLocalGenerator
   return source.GetLanguage();
 }
 
+cmake* cmLocalGenerator::GetCMakeInstance() const
+{
+  return this->GlobalGenerator->GetCMakeInstance();
+}
+
+const char* cmLocalGenerator::GetSourceDirectory() const
+{
+  return this->GetCMakeInstance()->GetHomeDirectory();
+}
+
+const char* cmLocalGenerator::GetBinaryDirectory() const
+{
+  return this->GetCMakeInstance()->GetHomeOutputDirectory();
+}
+
+const char* cmLocalGenerator::GetCurrentBinaryDirectory() const
+{
+  return this->StateSnapshot.GetDirectory().GetCurrentBinary();
+}
+
+const char* cmLocalGenerator::GetCurrentSourceDirectory() const
+{
+  return this->StateSnapshot.GetDirectory().GetCurrentSource();
+}
+
 //----------------------------------------------------------------------------
 std::string
-cmLocalGenerator::GetTargetDirectory(cmTarget const&) const
+cmLocalGenerator::GetTargetDirectory(const cmGeneratorTarget*) const
 {
   cmSystemTools::Error("GetTargetDirectory"
                        " called on cmLocalGenerator");
@@ -2868,7 +2982,7 @@ cmLocalGenerator::GetTargetDirectory(cmTarget const&) const
 }
 
 //----------------------------------------------------------------------------
-cmIML_INT_uint64_t cmLocalGenerator::GetBackwardsCompatibility()
+KWIML_INT_uint64_t cmLocalGenerator::GetBackwardsCompatibility()
 {
   // The computed version may change until the project is fully
   // configured.
@@ -2899,7 +3013,7 @@ bool cmLocalGenerator::NeedBackwardsCompatibility_2_4()
 {
   // Check the policy to decide whether to pay attention to this
   // variable.
-  switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0001))
+  switch(this->GetPolicyStatus(cmPolicies::CMP0001))
     {
     case cmPolicies::WARN:
       // WARN is just OLD without warning because user code does not
@@ -2921,11 +3035,17 @@ bool cmLocalGenerator::NeedBackwardsCompatibility_2_4()
 
   // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set
   // equal to or lower than the given version.
-  cmIML_INT_uint64_t actual_compat = this->GetBackwardsCompatibility();
+  KWIML_INT_uint64_t actual_compat = this->GetBackwardsCompatibility();
   return (actual_compat &&
           actual_compat <= CMake_VERSION_ENCODE(2, 4, 255));
 }
 
+cmPolicies::PolicyStatus
+cmLocalGenerator::GetPolicyStatus(cmPolicies::PolicyID id) const
+{
+  return this->Makefile->GetPolicyStatus(id);
+}
+
 //----------------------------------------------------------------------------
 bool cmLocalGenerator::CheckDefinition(std::string const& define) const
 {
@@ -2964,7 +3084,7 @@ bool cmLocalGenerator::CheckDefinition(std::string const& define) const
 }
 
 //----------------------------------------------------------------------------
-static void cmLGInfoProp(cmMakefile* mf, cmTarget* target,
+static void cmLGInfoProp(cmMakefile* mf, cmGeneratorTarget* target,
     const std::string& prop)
 {
   if(const char* val = target->GetProperty(prop))
@@ -2974,7 +3094,7 @@ static void cmLGInfoProp(cmMakefile* mf, cmTarget* target,
 }
 
 //----------------------------------------------------------------------------
-void cmLocalGenerator::GenerateAppleInfoPList(cmTarget* target,
+void cmLocalGenerator::GenerateAppleInfoPList(cmGeneratorTarget* target,
                                               const std::string& targetName,
                                               const char* fname)
 {
@@ -3017,7 +3137,7 @@ void cmLocalGenerator::GenerateAppleInfoPList(cmTarget* target,
 }
 
 //----------------------------------------------------------------------------
-void cmLocalGenerator::GenerateFrameworkInfoPList(cmTarget* target,
+void cmLocalGenerator::GenerateFrameworkInfoPList(cmGeneratorTarget* target,
                                                 const std::string& targetName,
                                                 const char* fname)
 {
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 6ea414a..68e7667 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -20,7 +20,6 @@
 class cmMakefile;
 class cmGlobalGenerator;
 class cmGeneratorTarget;
-class cmTarget;
 class cmTargetManifest;
 class cmSourceFile;
 class cmCustomCommand;
@@ -68,6 +67,8 @@ public:
    */
   void ComputeTargetManifest();
 
+  bool IsRootMakefile() const;
+
   ///! Get the makefile for this generator
   cmMakefile *GetMakefile() {
     return this->Makefile; }
@@ -91,13 +92,15 @@ public:
 
   void AddLanguageFlags(std::string& flags, const std::string& lang,
                         const std::string& config);
-  void AddCMP0018Flags(std::string &flags, cmTarget const* target,
+  void AddCMP0018Flags(std::string &flags, cmGeneratorTarget const* target,
                        std::string const& lang, const std::string& config);
-  void AddVisibilityPresetFlags(std::string &flags, cmTarget const* target,
+  void AddVisibilityPresetFlags(std::string &flags,
+                                cmGeneratorTarget const* target,
                                 const std::string& lang);
   void AddConfigVariableFlags(std::string& flags, const std::string& var,
                               const std::string& config);
-  void AddCompilerRequirementFlag(std::string &flags, cmTarget const* target,
+  void AddCompilerRequirementFlag(std::string &flags,
+                                  cmGeneratorTarget const* target,
                                   const std::string& lang);
   ///! Append flags to a string.
   virtual void AppendFlags(std::string& flags, const std::string& newFlags);
@@ -112,6 +115,23 @@ public:
                               bool forResponseFile = false,
                               const std::string& config = "");
 
+  const std::vector<cmGeneratorTarget*> &GetGeneratorTargets() const
+    {
+      return this->GeneratorTargets;
+    }
+
+  const std::vector<cmGeneratorTarget*> &GetImportedGeneratorTargets() const
+    {
+      return this->ImportedGeneratorTargets;
+    }
+
+  void AddGeneratorTarget(cmGeneratorTarget* gt);
+  void AddImportedGeneratorTarget(cmGeneratorTarget* gt);
+  void AddOwnedImportedGeneratorTarget(cmGeneratorTarget* gt);
+
+  cmGeneratorTarget* FindGeneratorTarget(const std::string& name) const;
+  cmGeneratorTarget* FindGeneratorTargetToUse(const std::string& name) const;
+
   /**
    * Encode a list of preprocessor definitions for the compiler
    * command line.
@@ -171,23 +191,25 @@ public:
 
   /** Get the include flags for the current makefile and language.  */
   void GetIncludeDirectories(std::vector<std::string>& dirs,
-                             cmGeneratorTarget* target,
+                             cmGeneratorTarget const* target,
                              const std::string& lang = "C",
                              const std::string& config = "",
                              bool stripImplicitInclDirs = true) const;
-  void AddCompileOptions(std::string& flags, cmTarget* target,
+  void AddCompileOptions(std::string& flags, cmGeneratorTarget* target,
                          const std::string& lang, const std::string& config);
   void AddCompileDefinitions(std::set<std::string>& defines,
-                             cmTarget const* target,
+                             cmGeneratorTarget const* target,
                              const std::string& config,
                              const std::string& lang);
 
+  std::string GetProjectName() const;
+
   /** Compute the language used to compile the given source file.  */
   std::string GetSourceFileLanguage(const cmSourceFile& source);
 
   // Fill the vector with the target names for the object files,
   // preprocessed files and assembly files.
-  virtual void GetIndividualFileTargets(std::vector<std::string>&) {}
+  void GetIndividualFileTargets(std::vector<std::string>&) {}
 
   // Create a struct to hold the varibles passed into
   // ExpandRuleVariables
@@ -197,7 +219,7 @@ public:
       {
         memset(this, 0,  sizeof(*this));
       }
-    cmTarget* CMTarget;
+    cmGeneratorTarget* CMTarget;
     const char* TargetPDB;
     const char* TargetCompilePDB;
     const char* TargetVersionMajor;
@@ -232,7 +254,8 @@ public:
    * Get the relative path from the generator output directory to a
    * per-target support directory.
    */
-  virtual std::string GetTargetDirectory(cmTarget const& target) const;
+  virtual std::string
+  GetTargetDirectory(cmGeneratorTarget const* target) const;
 
   /**
    * Get the level of backwards compatibility requested by the project
@@ -244,23 +267,34 @@ public:
    *
    * and is monotonically increasing with the CMake version.
    */
-  cmIML_INT_uint64_t GetBackwardsCompatibility();
+  KWIML_INT_uint64_t GetBackwardsCompatibility();
 
   /**
    * Test whether compatibility is set to a given version or lower.
    */
   bool NeedBackwardsCompatibility_2_4();
 
+  cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id) const;
+
+  cmake* GetCMakeInstance() const;
+
+  const char* GetSourceDirectory() const;
+  const char* GetBinaryDirectory() const;
+
+  const char* GetCurrentBinaryDirectory() const;
+  const char* GetCurrentSourceDirectory() const;
+
   /**
    * Generate a Mac OS X application bundle Info.plist file.
    */
-  void GenerateAppleInfoPList(cmTarget* target, const std::string& targetName,
+  void GenerateAppleInfoPList(cmGeneratorTarget* target,
+                              const std::string& targetName,
                               const char* fname);
 
   /**
    * Generate a Mac OS X framework Info.plist file.
    */
-  void GenerateFrameworkInfoPList(cmTarget* target,
+  void GenerateFrameworkInfoPList(cmGeneratorTarget* target,
                                   const std::string& targetName,
                                   const char* fname);
   /** Construct a comment for a custom command.  */
@@ -274,7 +308,7 @@ public:
   /** Fill out the static linker flags for the given target.  */
   void GetStaticLibraryFlags(std::string& flags,
                              std::string const& config,
-                             cmTarget* target);
+                             cmGeneratorTarget* target);
 
   /** Fill out these strings for the given target.  Libraries to link,
    *  flags, and linkflags. */
@@ -317,8 +351,9 @@ protected:
   std::string ExpandRuleVariable(std::string const& variable,
                                  const RuleVariables& replaceValues);
 
-  const char* GetRuleLauncher(cmTarget* target, const std::string& prop);
-  void InsertRuleLauncher(std::string& s, cmTarget* target,
+  const char* GetRuleLauncher(cmGeneratorTarget* target,
+                              const std::string& prop);
+  void InsertRuleLauncher(std::string& s, cmGeneratorTarget* target,
                           const std::string& prop);
 
   // Handle old-style install rules stored in the targets.
@@ -343,7 +378,11 @@ protected:
   std::string::size_type ObjectPathMax;
   std::set<std::string> ObjectMaxPathViolations;
 
-  std::set<cmTarget const*> WarnCMP0063;
+  std::set<cmGeneratorTarget const*> WarnCMP0063;
+  std::vector<cmGeneratorTarget*> GeneratorTargets;
+  std::vector<cmGeneratorTarget*> ImportedGeneratorTargets;
+  std::vector<cmGeneratorTarget*> OwnedImportedGeneratorTargets;
+  std::map<std::string, std::string> AliasTargets;
 
   bool EmitUniversalBinaryFlags;
 
@@ -351,7 +390,7 @@ protected:
   // committed.
   std::string TargetImplib;
 
-  cmIML_INT_uint64_t BackwardsCompatibility;
+  KWIML_INT_uint64_t BackwardsCompatibility;
   bool BackwardsCompatibilityFinal;
 private:
   void AddSharedFlags(std::string& flags, const std::string& lang,
diff --git a/Source/cmLocalGhsMultiGenerator.cxx b/Source/cmLocalGhsMultiGenerator.cxx
index bac989f..a77a75e 100644
--- a/Source/cmLocalGhsMultiGenerator.cxx
+++ b/Source/cmLocalGhsMultiGenerator.cxx
@@ -26,17 +26,16 @@ cmLocalGhsMultiGenerator::~cmLocalGhsMultiGenerator() {}
 
 void cmLocalGhsMultiGenerator::Generate()
 {
-  cmGeneratorTargetsType tgts = this->GetMakefile()->GetGeneratorTargets();
+  std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
 
-  for (cmGeneratorTargetsType::iterator l = tgts.begin(); l != tgts.end();
-       ++l)
+  for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
+       l != tgts.end(); ++l)
     {
-    if (l->second->Target->GetType() == cmTarget::INTERFACE_LIBRARY
-        || l->second->Target->IsImported())
+    if ((*l)->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
-    cmGhsMultiTargetGenerator tg(l->second);
+    cmGhsMultiTargetGenerator tg(*l);
     tg.Generate();
     }
 }
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx
index c46adc1..b2927a9 100644
--- a/Source/cmLocalNinjaGenerator.cxx
+++ b/Source/cmLocalNinjaGenerator.cxx
@@ -42,7 +42,7 @@ void cmLocalNinjaGenerator::Generate()
   // Compute the path to use when referencing the current output
   // directory from the top output directory.
   this->HomeRelativeOutputPath =
-    this->Convert(this->Makefile->GetCurrentBinaryDirectory(), HOME_OUTPUT);
+    this->Convert(this->GetCurrentBinaryDirectory(), HOME_OUTPUT);
   if(this->HomeRelativeOutputPath == ".")
     {
     this->HomeRelativeOutputPath = "";
@@ -56,7 +56,7 @@ void cmLocalNinjaGenerator::Generate()
 #endif
 
   // We do that only once for the top CMakeLists.txt file.
-  if(this->Makefile->IsRootMakefile())
+  if(this->IsRootMakefile())
     {
     this->WriteBuildFileTop();
 
@@ -73,24 +73,23 @@ void cmLocalNinjaGenerator::Generate()
       }
     }
 
-  cmGeneratorTargetsType targets = this->GetMakefile()->GetGeneratorTargets();
-  for(cmGeneratorTargetsType::iterator t = targets.begin();
+  std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
+  for(std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
       t != targets.end(); ++t)
     {
-    if (t->second->Target->GetType() == cmTarget::INTERFACE_LIBRARY
-        || t->second->Target->IsImported())
+    if ((*t)->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
-    cmNinjaTargetGenerator* tg = cmNinjaTargetGenerator::New(t->second);
+    cmNinjaTargetGenerator* tg = cmNinjaTargetGenerator::New(*t);
     if(tg)
       {
       tg->Generate();
       // Add the target to "all" if required.
       if (!this->GetGlobalNinjaGenerator()->IsExcluded(
             this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0],
-            t->second))
-        this->GetGlobalNinjaGenerator()->AddDependencyToAll(t->second->Target);
+            *t))
+        this->GetGlobalNinjaGenerator()->AddDependencyToAll(*t);
       delete tg;
       }
     }
@@ -100,10 +99,10 @@ void cmLocalNinjaGenerator::Generate()
 
 // TODO: Picked up from cmLocalUnixMakefileGenerator3.  Refactor it.
 std::string cmLocalNinjaGenerator
-::GetTargetDirectory(cmTarget const& target) const
+::GetTargetDirectory(cmGeneratorTarget const* target) const
 {
   std::string dir = cmake::GetCMakeFilesDirectoryPostSlash();
-  dir += target.GetName();
+  dir += target->GetName();
 #if defined(__VMS)
   dir += "_dir";
 #else
@@ -183,7 +182,7 @@ void cmLocalNinjaGenerator::WriteProjectHeader(std::ostream& os)
 {
   cmGlobalNinjaGenerator::WriteDivider(os);
   os
-    << "# Project: " << this->GetMakefile()->GetProjectName() << std::endl
+    << "# Project: " << this->GetProjectName() << std::endl
     << "# Configuration: " << this->ConfigName << std::endl
     ;
   cmGlobalNinjaGenerator::WriteDivider(os);
@@ -278,7 +277,7 @@ void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os)
     << "# Write statements declared in CMakeLists.txt:" << std::endl
     << "# "
     << this->Makefile->GetDefinition("CMAKE_CURRENT_LIST_FILE") << std::endl;
-  if(this->Makefile->IsRootMakefile())
+  if(this->IsRootMakefile())
     os << "# Which is the root file." << std::endl;
   cmGlobalNinjaGenerator::WriteDivider(os);
   os << std::endl;
@@ -286,14 +285,14 @@ void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os)
 
 void
 cmLocalNinjaGenerator
-::AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs)
+::AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs)
 {
   this->GetGlobalNinjaGenerator()->AppendTargetOutputs(target, outputs);
 }
 
 void
 cmLocalNinjaGenerator
-::AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs)
+::AppendTargetDepends(cmGeneratorTarget* target, cmNinjaDeps& outputs)
 {
   this->GetGlobalNinjaGenerator()->AppendTargetDepends(target, outputs);
 }
@@ -363,7 +362,7 @@ void cmLocalNinjaGenerator::AppendCustomCommandLines(
   if (ccg.GetNumberOfCommands() > 0) {
     std::string wd = ccg.GetWorkingDirectory();
     if (wd.empty())
-      wd = this->GetMakefile()->GetCurrentBinaryDirectory();
+      wd = this->GetCurrentBinaryDirectory();
 
     std::ostringstream cdCmd;
 #ifdef _WIN32
@@ -399,6 +398,16 @@ cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
   const std::vector<std::string> &byproducts = ccg.GetByproducts();
   cmNinjaDeps ninjaOutputs(outputs.size()+byproducts.size()), ninjaDeps;
 
+  bool symbolic = false;
+  for (std::vector<std::string>::const_iterator o = outputs.begin();
+       o != outputs.end(); ++o)
+    {
+    if (cmSourceFile* sf = this->Makefile->GetSource(*o))
+      {
+      symbolic = sf->GetPropertyAsBool("SYMBOLIC");
+      }
+    }
+
 #if 0
 #error TODO: Once CC in an ExternalProject target must provide the \
     file of each imported target that has an add_dependencies pointing \
@@ -435,6 +444,7 @@ cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
       this->ConstructComment(ccg),
       "Custom command for " + ninjaOutputs[0],
       cc->GetUsesTerminal(),
+      /*restat*/!symbolic,
       ninjaOutputs,
       ninjaDeps,
       orderOnlyDeps);
@@ -442,7 +452,7 @@ cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
 }
 
 void cmLocalNinjaGenerator::AddCustomCommandTarget(cmCustomCommand const* cc,
-                                                   cmTarget* target)
+                                                   cmGeneratorTarget* target)
 {
   this->CustomCommandTargets[cc].insert(target);
 }
@@ -460,7 +470,7 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements()
     //
     // FIXME: This won't work in certain obscure scenarios involving indirect
     // dependencies.
-    std::set<cmTarget*>::iterator j = i->second.begin();
+    std::set<cmGeneratorTarget*>::iterator j = i->second.begin();
     assert(j != i->second.end());
     std::vector<std::string> ccTargetDeps;
     this->AppendTargetDepends(*j, ccTargetDeps);
diff --git a/Source/cmLocalNinjaGenerator.h b/Source/cmLocalNinjaGenerator.h
index 1645a8d..b6987ef 100644
--- a/Source/cmLocalNinjaGenerator.h
+++ b/Source/cmLocalNinjaGenerator.h
@@ -37,7 +37,8 @@ public:
 
   virtual void Generate();
 
-  virtual std::string GetTargetDirectory(cmTarget const& target) const;
+  virtual
+  std::string GetTargetDirectory(cmGeneratorTarget const* target) const;
 
   const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const;
   cmGlobalNinjaGenerator* GetGlobalNinjaGenerator();
@@ -57,10 +58,11 @@ public:
 
   std::string BuildCommandLine(const std::vector<std::string> &cmdLines);
 
-  void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs);
-  void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs);
+  void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs);
+  void AppendTargetDepends(cmGeneratorTarget* target, cmNinjaDeps& outputs);
 
-  void AddCustomCommandTarget(cmCustomCommand const* cc, cmTarget* target);
+  void AddCustomCommandTarget(cmCustomCommand const* cc,
+                              cmGeneratorTarget* target);
   void AppendCustomCommandLines(cmCustomCommandGenerator const& ccg,
                                 std::vector<std::string> &cmdLines);
   void AppendCustomCommandDeps(cmCustomCommandGenerator const& ccg,
@@ -101,7 +103,7 @@ private:
 
   std::string HomeRelativeOutputPath;
 
-  typedef std::map<cmCustomCommand const*, std::set<cmTarget*> >
+  typedef std::map<cmCustomCommand const*, std::set<cmGeneratorTarget*> >
     CustomCommandTargetMap;
   CustomCommandTargetMap CustomCommandTargets;
 };
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
index b131a63..62fea3d 100644
--- a/Source/cmLocalUnixMakefileGenerator3.cxx
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -113,19 +113,18 @@ void cmLocalUnixMakefileGenerator3::Generate()
     this->Makefile->IsOn("CMAKE_SKIP_ASSEMBLY_SOURCE_RULES");
 
   // Generate the rule files for each target.
-  cmGeneratorTargetsType targets = this->Makefile->GetGeneratorTargets();
+  std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
   cmGlobalUnixMakefileGenerator3* gg =
     static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
-  for(cmGeneratorTargetsType::iterator t = targets.begin();
+  for(std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
       t != targets.end(); ++t)
     {
-    if (t->second->Target->GetType() == cmTarget::INTERFACE_LIBRARY
-        || t->second->Target->IsImported())
+    if ((*t)->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
     cmsys::auto_ptr<cmMakefileTargetGenerator> tg(
-      cmMakefileTargetGenerator::New(t->second));
+      cmMakefileTargetGenerator::New(*t));
     if (tg.get())
       {
       tg->WriteRuleFiles();
@@ -145,7 +144,7 @@ void cmLocalUnixMakefileGenerator3::ComputeHomeRelativeOutputPath()
   // Compute the path to use when referencing the current output
   // directory from the top output directory.
   this->HomeRelativeOutputPath =
-    this->Convert(this->Makefile->GetCurrentBinaryDirectory(), HOME_OUTPUT);
+    this->Convert(this->GetCurrentBinaryDirectory(), HOME_OUTPUT);
   if(this->HomeRelativeOutputPath == ".")
     {
     this->HomeRelativeOutputPath = "";
@@ -174,13 +173,12 @@ void cmLocalUnixMakefileGenerator3::ComputeObjectFilenames(
 void cmLocalUnixMakefileGenerator3::
 GetLocalObjectFiles(std::map<std::string, LocalObjectInfo> &localObjectFiles)
 {
-  std::set<std::string> emitted;
-  cmGeneratorTargetsType targets = this->Makefile->GetGeneratorTargets();
-  for(cmGeneratorTargetsType::iterator ti = targets.begin();
+  std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
+  for(std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
       ti != targets.end(); ++ti)
     {
-    cmGeneratorTarget* gt = ti->second;
-    if (gt->GetType() == cmTarget::INTERFACE_LIBRARY)
+    cmGeneratorTarget* gt = *ti;
+    if (gt->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
@@ -189,9 +187,9 @@ GetLocalObjectFiles(std::map<std::string, LocalObjectInfo> &localObjectFiles)
                                     ->GetSafeDefinition("CMAKE_BUILD_TYPE"));
     // Compute full path to object file directory for this target.
     std::string dir;
-    dir += gt->Makefile->GetCurrentBinaryDirectory();
+    dir += gt->LocalGenerator->GetCurrentBinaryDirectory();
     dir += "/";
-    dir += this->GetTargetDirectory(*gt->Target);
+    dir += this->GetTargetDirectory(gt);
     dir += "/";
     // Compute the name of each object file.
     for(std::vector<cmSourceFile const*>::iterator
@@ -209,7 +207,7 @@ GetLocalObjectFiles(std::map<std::string, LocalObjectInfo> &localObjectFiles)
         }
       LocalObjectInfo& info = localObjectFiles[objectName];
       info.HasSourceExtension = hasSourceExtension;
-      info.push_back(LocalObjectEntry(gt->Target, sf->GetLanguage()));
+      info.push_back(LocalObjectEntry(gt, sf->GetLanguage()));
       }
     }
 }
@@ -255,7 +253,7 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
     return;
     }
   // always write the top makefile
-  if (!this->GetMakefile()->IsRootMakefile())
+  if (!this->IsRootMakefile())
     {
     ruleFileStream.SetCopyIfDifferent(true);
     }
@@ -266,7 +264,7 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
   // only write local targets unless at the top Keep track of targets already
   // listed.
   std::set<std::string> emittedTargets;
-  if (!this->GetMakefile()->IsRootMakefile())
+  if (!this->IsRootMakefile())
     {
     // write our targets, and while doing it collect up the object
     // file rules
@@ -389,7 +387,7 @@ cmLocalUnixMakefileGenerator3
       t != info.end(); ++t)
     {
     std::string tgtMakefileName =
-      this->GetRelativeTargetDirectory(*(t->Target));
+      this->GetRelativeTargetDirectory(t->Target);
     std::string targetName = tgtMakefileName;
     tgtMakefileName += "/build.make";
     targetName += "/";
@@ -399,7 +397,7 @@ cmLocalUnixMakefileGenerator3
       );
     }
   this->CreateCDCommand(commands,
-                        this->Makefile->GetHomeOutputDirectory(),
+                        this->GetBinaryDirectory(),
                         cmLocalGenerator::START_OUTPUT);
 
   // Write the rule to the makefile.
@@ -418,27 +416,22 @@ void cmLocalUnixMakefileGenerator3
 
   // for each target we just provide a rule to cd up to the top and do a make
   // on the target
-  cmGeneratorTargetsType targets = this->Makefile->GetGeneratorTargets();
+  std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
   std::string localName;
-  for(cmGeneratorTargetsType::iterator t = targets.begin();
+  for(std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
       t != targets.end(); ++t)
     {
-    if((t->second->GetType() == cmTarget::EXECUTABLE) ||
-       (t->second->GetType() == cmTarget::STATIC_LIBRARY) ||
-       (t->second->GetType() == cmTarget::SHARED_LIBRARY) ||
-       (t->second->GetType() == cmTarget::MODULE_LIBRARY) ||
-       (t->second->GetType() == cmTarget::OBJECT_LIBRARY) ||
-       (t->second->GetType() == cmTarget::UTILITY))
+    if(((*t)->GetType() == cmState::EXECUTABLE) ||
+       ((*t)->GetType() == cmState::STATIC_LIBRARY) ||
+       ((*t)->GetType() == cmState::SHARED_LIBRARY) ||
+       ((*t)->GetType() == cmState::MODULE_LIBRARY) ||
+       ((*t)->GetType() == cmState::OBJECT_LIBRARY) ||
+       ((*t)->GetType() == cmState::UTILITY))
       {
-      if (t->second->Target->IsImported())
-        {
-        continue;
-        }
-
-      emitted.insert(t->second->GetName());
+      emitted.insert((*t)->GetName());
 
       // for subdirs add a rule to build this specific target by name.
-      localName = this->GetRelativeTargetDirectory(*t->second->Target);
+      localName = this->GetRelativeTargetDirectory(*t);
       localName += "/rule";
       commands.clear();
       depends.clear();
@@ -449,54 +442,54 @@ void cmLocalUnixMakefileGenerator3
       commands.push_back(this->GetRecursiveMakeCall
                          (makefile2.c_str(),localName));
       this->CreateCDCommand(commands,
-                            this->Makefile->GetHomeOutputDirectory(),
+                            this->GetBinaryDirectory(),
                             cmLocalGenerator::START_OUTPUT);
       this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
                           localName, depends, commands, true);
 
       // Add a target with the canonical name (no prefix, suffix or path).
-      if(localName != t->second->GetName())
+      if(localName != (*t)->GetName())
         {
         commands.clear();
         depends.push_back(localName);
         this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
-                            t->second->GetName(), depends, commands, true);
+                            (*t)->GetName(), depends, commands, true);
         }
 
       // Add a fast rule to build the target
       std::string makefileName =
-                         this->GetRelativeTargetDirectory(*t->second->Target);
+                         this->GetRelativeTargetDirectory(*t);
       makefileName += "/build.make";
       // make sure the makefile name is suitable for a makefile
       std::string makeTargetName =
-        this->GetRelativeTargetDirectory(*t->second->Target);
+        this->GetRelativeTargetDirectory(*t);
       makeTargetName += "/build";
-      localName = t->second->GetName();
+      localName = (*t)->GetName();
       localName += "/fast";
       depends.clear();
       commands.clear();
       commands.push_back(this->GetRecursiveMakeCall
                          (makefileName.c_str(), makeTargetName));
       this->CreateCDCommand(commands,
-                            this->Makefile->GetHomeOutputDirectory(),
+                            this->GetBinaryDirectory(),
                             cmLocalGenerator::START_OUTPUT);
       this->WriteMakeRule(ruleFileStream, "fast build rule for target.",
                           localName, depends, commands, true);
 
       // Add a local name for the rule to relink the target before
       // installation.
-      if(t->second->NeedRelinkBeforeInstall(this->ConfigName))
+      if((*t)->NeedRelinkBeforeInstall(this->ConfigName))
         {
-        makeTargetName = this->GetRelativeTargetDirectory(*t->second->Target);
+        makeTargetName = this->GetRelativeTargetDirectory(*t);
         makeTargetName += "/preinstall";
-        localName = t->second->GetName();
+        localName = (*t)->GetName();
         localName += "/preinstall";
         depends.clear();
         commands.clear();
         commands.push_back(this->GetRecursiveMakeCall
                            (makefile2.c_str(), makeTargetName));
         this->CreateCDCommand(commands,
-                              this->Makefile->GetHomeOutputDirectory(),
+                              this->GetBinaryDirectory(),
                               cmLocalGenerator::START_OUTPUT);
         this->WriteMakeRule(ruleFileStream,
                             "Manual pre-install relink rule for target.",
@@ -509,7 +502,7 @@ void cmLocalUnixMakefileGenerator3
 //----------------------------------------------------------------------------
 void cmLocalUnixMakefileGenerator3::WriteDirectoryInformationFile()
 {
-  std::string infoFileName = this->Makefile->GetCurrentBinaryDirectory();
+  std::string infoFileName = this->GetCurrentBinaryDirectory();
   infoFileName += cmake::GetCMakeFilesDirectory();
   infoFileName += "/CMakeDirectoryInformation.cmake";
 
@@ -573,7 +566,7 @@ std::string
 cmLocalUnixMakefileGenerator3
 ::ConvertToFullPath(const std::string& localPath)
 {
-  std::string dir = this->Makefile->GetCurrentBinaryDirectory();
+  std::string dir = this->GetCurrentBinaryDirectory();
   dir += "/";
   dir += localPath;
   return dir;
@@ -750,13 +743,13 @@ cmLocalUnixMakefileGenerator3
   makefileStream
     << "# The top-level source directory on which CMake was run.\n"
     << "CMAKE_SOURCE_DIR = "
-    << this->Convert(this->Makefile->GetHomeDirectory(), FULL, SHELL)
+    << this->Convert(this->GetSourceDirectory(), FULL, SHELL)
     << "\n"
     << "\n";
   makefileStream
     << "# The top-level build directory on which CMake was run.\n"
     << "CMAKE_BINARY_DIR = "
-    << this->Convert(this->Makefile->GetHomeOutputDirectory(), FULL, SHELL)
+    << this->Convert(this->GetBinaryDirectory(), FULL, SHELL)
     << "\n"
     << "\n";
 }
@@ -886,10 +879,10 @@ void cmLocalUnixMakefileGenerator3
   std::vector<std::string> no_depends;
   std::vector<std::string> commands;
   commands.push_back(runRule);
-  if(!this->GetMakefile()->IsRootMakefile())
+  if(!this->IsRootMakefile())
     {
     this->CreateCDCommand(commands,
-                          this->Makefile->GetHomeOutputDirectory(),
+                          this->GetBinaryDirectory(),
                           cmLocalGenerator::START_OUTPUT);
     }
   this->WriteMakeRule(makefileStream,
@@ -933,7 +926,7 @@ cmLocalUnixMakefileGenerator3
 //----------------------------------------------------------------------------
 std::string
 cmLocalUnixMakefileGenerator3
-::GetRelativeTargetDirectory(cmTarget const& target)
+::GetRelativeTargetDirectory(cmGeneratorTarget* target)
 {
   std::string dir = this->HomeRelativeOutputPath;
   dir += this->GetTargetDirectory(target);
@@ -1034,7 +1027,7 @@ void
 cmLocalUnixMakefileGenerator3
 ::AppendCustomCommands(std::vector<std::string>& commands,
                        const std::vector<cmCustomCommand>& ccs,
-                       cmTarget* target,
+                       cmGeneratorTarget* target,
                        cmLocalGenerator::RelativeRoot relative)
 {
   for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
@@ -1050,7 +1043,7 @@ void
 cmLocalUnixMakefileGenerator3
 ::AppendCustomCommand(std::vector<std::string>& commands,
                       cmCustomCommandGenerator const& ccg,
-                      cmTarget* target,
+                      cmGeneratorTarget* target,
                       bool echo_comment,
                       cmLocalGenerator::RelativeRoot relative,
                       std::ostream* content)
@@ -1070,7 +1063,7 @@ cmLocalUnixMakefileGenerator3
     }
 
   // if the command specified a working directory use it.
-  std::string dir  = this->Makefile->GetCurrentBinaryDirectory();
+  std::string dir  = this->GetCurrentBinaryDirectory();
   std::string workingDir = ccg.GetWorkingDirectory();
   if(!workingDir.empty())
     {
@@ -1181,7 +1174,7 @@ cmLocalUnixMakefileGenerator3
 std::string
 cmLocalUnixMakefileGenerator3::MakeLauncher(
   cmCustomCommandGenerator const& ccg,
-  cmTarget* target, RelativeRoot relative)
+  cmGeneratorTarget* target, RelativeRoot relative)
 {
   // Short-circuit if there is no launcher.
   const char* prop = "RULE_LAUNCH_CUSTOM";
@@ -1218,9 +1211,9 @@ void
 cmLocalUnixMakefileGenerator3
 ::AppendCleanCommand(std::vector<std::string>& commands,
                      const std::vector<std::string>& files,
-                     cmTarget& target, const char* filename)
+                     cmGeneratorTarget* target, const char* filename)
 {
-  std::string cleanfile = this->Makefile->GetCurrentBinaryDirectory();
+  std::string cleanfile = this->GetCurrentBinaryDirectory();
   cleanfile += "/";
   cleanfile += this->GetTargetDirectory(target);
   cleanfile += "/cmake_clean";
@@ -1256,9 +1249,7 @@ cmLocalUnixMakefileGenerator3
     {
     // Get the set of source languages in the target.
     std::set<std::string> languages;
-    cmGeneratorTarget *gtgt =
-        this->GlobalGenerator->GetGeneratorTarget(&target);
-    gtgt->GetLanguages(languages,
+    target->GetLanguages(languages,
                       this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
     fout << "\n"
          << "# Per-language clean rules from dependency scanning.\n"
@@ -1501,7 +1492,7 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
   // If the directory information is newer than depend.internal, include dirs
   // may have changed. In this case discard all old dependencies.
   bool needRescanDirInfo = false;
-  std::string dirInfoFile = this->Makefile->GetCurrentBinaryDirectory();
+  std::string dirInfoFile = this->GetCurrentBinaryDirectory();
   dirInfoFile += cmake::GetCMakeFilesDirectory();
   dirInfoFile += "/CMakeDirectoryInformation.cmake";
   {
@@ -1575,7 +1566,7 @@ cmLocalUnixMakefileGenerator3
   // Read the directory information file.
   cmMakefile* mf = this->Makefile;
   bool haveDirectoryInfo = false;
-  std::string dirInfoFile = this->Makefile->GetCurrentBinaryDirectory();
+  std::string dirInfoFile = this->GetCurrentBinaryDirectory();
   dirInfoFile += cmake::GetCMakeFilesDirectory();
   dirInfoFile += "/CMakeDirectoryInformation.cmake";
   if(mf->ReadListFile(dirInfoFile.c_str()) &&
@@ -1770,40 +1761,43 @@ void cmLocalUnixMakefileGenerator3
   ruleFileStream
     << "# Targets provided globally by CMake.\n"
     << "\n";
-  cmTargets* targets = &(this->Makefile->GetTargets());
-  cmTargets::iterator glIt;
-  for ( glIt = targets->begin(); glIt != targets->end(); ++ glIt )
+  std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
+  std::vector<cmGeneratorTarget*>::iterator glIt;
+  for ( glIt = targets.begin(); glIt != targets.end(); ++ glIt )
     {
-    if ( glIt->second.GetType() == cmTarget::GLOBAL_TARGET )
+    if ( (*glIt)->GetType() == cmState::GLOBAL_TARGET )
       {
-      std::string targetString = "Special rule for the target " + glIt->first;
+      std::string targetString = "Special rule for the target " +
+          (*glIt)->GetName();
       std::vector<std::string> commands;
       std::vector<std::string> depends;
 
-      const char* text = glIt->second.GetProperty("EchoString");
+      const char* text = (*glIt)->GetProperty("EchoString");
       if ( !text )
         {
         text = "Running external command ...";
         }
-      depends.insert(depends.end(), glIt->second.GetUtilities().begin(),
-                     glIt->second.GetUtilities().end());
+      depends.insert(depends.end(), (*glIt)->GetUtilities().begin(),
+                     (*glIt)->GetUtilities().end());
       this->AppendEcho(commands, text,
                        cmLocalUnixMakefileGenerator3::EchoGlobal);
 
+      cmGeneratorTarget* gt = *glIt;
+
       // Global targets store their rules in pre- and post-build commands.
       this->AppendCustomDepends(depends,
-                                glIt->second.GetPreBuildCommands());
+                                gt->GetPreBuildCommands());
       this->AppendCustomDepends(depends,
-                                glIt->second.GetPostBuildCommands());
+                                gt->GetPostBuildCommands());
       this->AppendCustomCommands(commands,
-                                 glIt->second.GetPreBuildCommands(),
-                                 &glIt->second,
+                                 gt->GetPreBuildCommands(),
+                                 gt,
                                  cmLocalGenerator::START_OUTPUT);
       this->AppendCustomCommands(commands,
-                                 glIt->second.GetPostBuildCommands(),
-                                 &glIt->second,
+                                 gt->GetPostBuildCommands(),
+                                 gt,
                                  cmLocalGenerator::START_OUTPUT);
-      std::string targetName = glIt->second.GetName();
+      std::string targetName = gt->GetName();
       this->WriteMakeRule(ruleFileStream, targetString.c_str(),
                           targetName, depends, commands, true);
 
@@ -1833,12 +1827,12 @@ void cmLocalUnixMakefileGenerator3
   std::vector<std::string> commands;
 
   // Write the all rule.
-  std::string recursiveTarget = this->Makefile->GetCurrentBinaryDirectory();
+  std::string recursiveTarget = this->GetCurrentBinaryDirectory();
   recursiveTarget += "/all";
 
   depends.push_back("cmake_check_build_system");
 
-  std::string progressDir = this->Makefile->GetHomeOutputDirectory();
+  std::string progressDir = this->GetBinaryDirectory();
   progressDir += cmake::GetCMakeFilesDirectory();
     {
     std::ostringstream progCmd;
@@ -1862,7 +1856,7 @@ void cmLocalUnixMakefileGenerator3
   commands.push_back(this->GetRecursiveMakeCall(mf2Dir.c_str(),
                                                 recursiveTarget));
   this->CreateCDCommand(commands,
-                        this->Makefile->GetHomeOutputDirectory(),
+                        this->GetBinaryDirectory(),
                         cmLocalGenerator::START_OUTPUT);
     {
     std::ostringstream progCmd;
@@ -1877,14 +1871,14 @@ void cmLocalUnixMakefileGenerator3
                       depends, commands, true);
 
   // Write the clean rule.
-  recursiveTarget = this->Makefile->GetCurrentBinaryDirectory();
+  recursiveTarget = this->GetCurrentBinaryDirectory();
   recursiveTarget += "/clean";
   commands.clear();
   depends.clear();
   commands.push_back(this->GetRecursiveMakeCall(mf2Dir.c_str(),
                                                 recursiveTarget));
   this->CreateCDCommand(commands,
-                                this->Makefile->GetHomeOutputDirectory(),
+                                this->GetBinaryDirectory(),
                                 cmLocalGenerator::START_OUTPUT);
   this->WriteMakeRule(ruleFileStream, "The main clean target", "clean",
                       depends, commands, true);
@@ -1895,7 +1889,7 @@ void cmLocalUnixMakefileGenerator3
                       depends, commands, true);
 
   // Write the preinstall rule.
-  recursiveTarget = this->Makefile->GetCurrentBinaryDirectory();
+  recursiveTarget = this->GetCurrentBinaryDirectory();
   recursiveTarget += "/preinstall";
   commands.clear();
   depends.clear();
@@ -1914,7 +1908,7 @@ void cmLocalUnixMakefileGenerator3
   commands.push_back
     (this->GetRecursiveMakeCall(mf2Dir.c_str(), recursiveTarget));
   this->CreateCDCommand(commands,
-                        this->Makefile->GetHomeOutputDirectory(),
+                        this->GetBinaryDirectory(),
                         cmLocalGenerator::START_OUTPUT);
   this->WriteMakeRule(ruleFileStream, "Prepare targets for installation.",
                       "preinstall", depends, commands, true);
@@ -1935,7 +1929,7 @@ void cmLocalUnixMakefileGenerator3
   runRule += " 1";
   commands.push_back(runRule);
   this->CreateCDCommand(commands,
-                        this->Makefile->GetHomeOutputDirectory(),
+                        this->GetBinaryDirectory(),
                         cmLocalGenerator::START_OUTPUT);
   this->WriteMakeRule(ruleFileStream, "clear depends",
                       "depend",
@@ -1978,7 +1972,8 @@ void cmLocalUnixMakefileGenerator3::ClearDependencies(cmMakefile* mf,
 
 
 void cmLocalUnixMakefileGenerator3
-::WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &target)
+::WriteDependLanguageInfo(std::ostream& cmakefileStream,
+                          cmGeneratorTarget* target)
 {
   ImplicitDependLanguageMap const& implicitLangs =
     this->GetImplicitDepends(target);
@@ -2032,7 +2027,7 @@ void cmLocalUnixMakefileGenerator3
 
     // Build a list of preprocessor definitions for the target.
     std::set<std::string> defines;
-    this->AddCompileDefinitions(defines, &target,
+    this->AddCompileDefinitions(defines, target,
                                 this->ConfigName, l->first);
     if(!defines.empty())
       {
@@ -2058,12 +2053,10 @@ void cmLocalUnixMakefileGenerator3
       << "set(CMAKE_" << l->first << "_TARGET_INCLUDE_PATH\n";
     std::vector<std::string> includes;
 
-    cmGeneratorTarget* gt = this->GetGlobalGenerator()
-                                ->GetGeneratorTarget(&target);
 
     const std::string& config =
       this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
-    this->GetIncludeDirectories(includes, gt,
+    this->GetIncludeDirectories(includes, target,
                                 l->first, config);
     for(std::vector<std::string>::iterator i = includes.begin();
         i != includes.end(); ++i)
@@ -2086,7 +2079,7 @@ void cmLocalUnixMakefileGenerator3
     cmSystemTools::ExpandListArgument(xform, transformRules);
     }
   if(const char* xform =
-     target.GetProperty("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM"))
+     target->GetProperty("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM"))
     {
     cmSystemTools::ExpandListArgument(xform, transformRules);
     }
@@ -2284,10 +2277,10 @@ cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p,
 //----------------------------------------------------------------------------
 std::string
 cmLocalUnixMakefileGenerator3
-::GetTargetDirectory(cmTarget const& target) const
+::GetTargetDirectory(cmGeneratorTarget const* target) const
 {
   std::string dir = cmake::GetCMakeFilesDirectoryPostSlash();
-  dir += target.GetName();
+  dir += target->GetName();
 #if defined(__VMS)
   dir += "_dir";
 #else
@@ -2298,19 +2291,20 @@ cmLocalUnixMakefileGenerator3
 
 //----------------------------------------------------------------------------
 cmLocalUnixMakefileGenerator3::ImplicitDependLanguageMap const&
-cmLocalUnixMakefileGenerator3::GetImplicitDepends(cmTarget const& tgt)
+cmLocalUnixMakefileGenerator3::GetImplicitDepends(
+    const cmGeneratorTarget* tgt)
 {
-  return this->ImplicitDepends[tgt.GetName()];
+  return this->ImplicitDepends[tgt->GetName()];
 }
 
 //----------------------------------------------------------------------------
 void
-cmLocalUnixMakefileGenerator3::AddImplicitDepends(cmTarget const& tgt,
+cmLocalUnixMakefileGenerator3::AddImplicitDepends(const cmGeneratorTarget* tgt,
                                                   const std::string& lang,
                                                   const char* obj,
                                                   const char* src)
 {
-  this->ImplicitDepends[tgt.GetName()][lang][obj].push_back(src);
+  this->ImplicitDepends[tgt->GetName()][lang][obj].push_back(src);
 }
 
 //----------------------------------------------------------------------------
diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h
index 98f15e6..8f69311 100644
--- a/Source/cmLocalUnixMakefileGenerator3.h
+++ b/Source/cmLocalUnixMakefileGenerator3.h
@@ -19,10 +19,8 @@
 
 class cmCustomCommand;
 class cmCustomCommandGenerator;
-class cmDependInformation;
 class cmDepends;
 class cmMakefileTargetGenerator;
-class cmTarget;
 class cmSourceFile;
 
 /** \class cmLocalUnixMakefileGenerator3
@@ -106,7 +104,8 @@ public:
   /** Get whether the makefile is to have color.  */
   bool GetColorMakefile() const { return this->ColorMakefile; }
 
-  virtual std::string GetTargetDirectory(cmTarget const& target) const;
+  virtual
+  std::string GetTargetDirectory(cmGeneratorTarget const* target) const;
 
     // create a command that cds to the start dir then runs the commands
   void CreateCDCommand(std::vector<std::string>& commands,
@@ -131,7 +130,7 @@ public:
   void WriteSpecialTargetsTop(std::ostream& makefileStream);
   void WriteSpecialTargetsBottom(std::ostream& makefileStream);
 
-  std::string GetRelativeTargetDirectory(cmTarget const& target);
+  std::string GetRelativeTargetDirectory(cmGeneratorTarget* target);
 
   // File pairs for implicit dependency scanning.  The key of the map
   // is the depender and the value is the explicit dependee.
@@ -141,9 +140,11 @@ public:
     public std::map<std::string, ImplicitDependFileMap> {};
   struct ImplicitDependTargetMap:
     public std::map<std::string, ImplicitDependLanguageMap> {};
-  ImplicitDependLanguageMap const& GetImplicitDepends(cmTarget const& tgt);
+  ImplicitDependLanguageMap const&
+  GetImplicitDepends(cmGeneratorTarget const* tgt);
 
-  void AddImplicitDepends(cmTarget const& tgt, const std::string& lang,
+  void AddImplicitDepends(cmGeneratorTarget const* tgt,
+                          const std::string& lang,
                           const char* obj, const char* src);
 
   // write the target rules for the local Makefile into the stream
@@ -181,7 +182,8 @@ protected:
 
 
   // write the depend info
-  void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
+  void WriteDependLanguageInfo(std::ostream& cmakefileStream,
+                               cmGeneratorTarget *tgt);
 
   // write the local help rule
   void WriteHelpRule(std::ostream& ruleFileStream);
@@ -196,12 +198,12 @@ protected:
                             const std::string& helpTarget);
 
   void WriteTargetDependRule(std::ostream& ruleFileStream,
-                             cmTarget& target);
+                             cmGeneratorTarget* target);
   void WriteTargetCleanRule(std::ostream& ruleFileStream,
-                            cmTarget& target,
+                            cmGeneratorTarget* target,
                             const std::vector<std::string>& files);
   void WriteTargetRequiresRule(std::ostream& ruleFileStream,
-                               cmTarget& target,
+                               cmGeneratorTarget* target,
                                const std::vector<std::string>& objects);
 
   void AppendRuleDepend(std::vector<std::string>& depends,
@@ -214,19 +216,19 @@ protected:
                           cmCustomCommandGenerator const& cc);
   void AppendCustomCommands(std::vector<std::string>& commands,
                             const std::vector<cmCustomCommand>& ccs,
-                            cmTarget* target,
+                            cmGeneratorTarget* target,
                             cmLocalGenerator::RelativeRoot relative =
                             cmLocalGenerator::HOME_OUTPUT);
   void AppendCustomCommand(std::vector<std::string>& commands,
                            cmCustomCommandGenerator const& ccg,
-                           cmTarget* target,
+                           cmGeneratorTarget* target,
                            bool echo_comment=false,
                            cmLocalGenerator::RelativeRoot relative =
                            cmLocalGenerator::HOME_OUTPUT,
                            std::ostream* content = 0);
   void AppendCleanCommand(std::vector<std::string>& commands,
                           const std::vector<std::string>& files,
-                          cmTarget& target, const char* filename =0);
+                          cmGeneratorTarget* target, const char* filename =0);
 
   // Helper methods for dependeny updates.
   bool ScanDependencies(const char* targetDir,
@@ -236,7 +238,7 @@ protected:
 private:
   std::string ConvertShellCommand(std::string const& cmd, RelativeRoot root);
   std::string MakeLauncher(cmCustomCommandGenerator const& ccg,
-                           cmTarget* target, RelativeRoot relative);
+                           cmGeneratorTarget* target, RelativeRoot relative);
 
   virtual void ComputeObjectFilenames(
                         std::map<cmSourceFile const*, std::string>& mapping,
@@ -254,10 +256,10 @@ private:
 
   struct LocalObjectEntry
   {
-    cmTarget* Target;
+    cmGeneratorTarget* Target;
     std::string Language;
     LocalObjectEntry(): Target(0), Language() {}
-    LocalObjectEntry(cmTarget* t, const std::string& lang):
+    LocalObjectEntry(cmGeneratorTarget* t, const std::string& lang):
       Target(t), Language(lang) {}
   };
   struct LocalObjectInfo: public std::vector<LocalObjectEntry>
diff --git a/Source/cmLocalVisualStudio10Generator.cxx b/Source/cmLocalVisualStudio10Generator.cxx
index b043b00..d0784ad 100644
--- a/Source/cmLocalVisualStudio10Generator.cxx
+++ b/Source/cmLocalVisualStudio10Generator.cxx
@@ -10,7 +10,6 @@
   See the License for more information.
 ============================================================================*/
 #include "cmLocalVisualStudio10Generator.h"
-#include "cmTarget.h"
 #include "cmMakefile.h"
 #include "cmVisualStudio10TargetGenerator.h"
 #include "cmGlobalVisualStudio10Generator.h"
@@ -74,22 +73,23 @@ cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator()
 void cmLocalVisualStudio10Generator::Generate()
 {
 
-  cmTargets &tgts = this->Makefile->GetTargets();
-  for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
+  std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
+  for(std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
+      l != tgts.end(); ++l)
     {
-    if(l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
+    if((*l)->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
     if(static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
-       ->TargetIsFortranOnly(l->second))
+       ->TargetIsFortranOnly(*l))
       {
-      this->CreateSingleVCProj(l->first.c_str(),l->second);
+      this->CreateSingleVCProj((*l)->GetName().c_str(), *l);
       }
     else
       {
       cmVisualStudio10TargetGenerator tg(
-        &l->second, static_cast<cmGlobalVisualStudio10Generator*>(
+        *l, static_cast<cmGlobalVisualStudio10Generator*>(
           this->GetGlobalGenerator()));
       tg.Generate();
       }
diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx
index cc94cd4..cdacb9e 100644
--- a/Source/cmLocalVisualStudio6Generator.cxx
+++ b/Source/cmLocalVisualStudio6Generator.cxx
@@ -82,12 +82,12 @@ private:
 
 void cmLocalVisualStudio6Generator::AddCMakeListsRules()
 {
-  cmTargets &tgts = this->Makefile->GetTargets();
-  for(cmTargets::iterator l = tgts.begin();
-      l != tgts.end(); l++)
+  std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
+  for(std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
+      l != tgts.end(); ++l)
     {
-    if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY
-        || l->second.GetType() == cmTarget::GLOBAL_TARGET)
+    if ((*l)->GetType() == cmState::INTERFACE_LIBRARY
+        || (*l)->GetType() == cmState::GLOBAL_TARGET)
       {
       continue;
       }
@@ -98,7 +98,7 @@ void cmLocalVisualStudio6Generator::AddCMakeListsRules()
       this->Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
     if (!cmSystemTools::IsOn(suppRegenRule))
       {
-      this->AddDSPBuildRule(l->second);
+      this->AddDSPBuildRule(*l);
       }
     }
 }
@@ -111,67 +111,69 @@ void cmLocalVisualStudio6Generator::Generate()
 void cmLocalVisualStudio6Generator::OutputDSPFile()
 {
   // If not an in source build, then create the output directory
-  if(strcmp(this->Makefile->GetCurrentBinaryDirectory(),
-            this->Makefile->GetHomeDirectory()) != 0)
+  if(strcmp(this->GetCurrentBinaryDirectory(),
+            this->GetSourceDirectory()) != 0)
     {
     if(!cmSystemTools::MakeDirectory
-       (this->Makefile->GetCurrentBinaryDirectory()))
+       (this->GetCurrentBinaryDirectory()))
       {
       cmSystemTools::Error("Error creating directory ",
-                           this->Makefile->GetCurrentBinaryDirectory());
+                           this->GetCurrentBinaryDirectory());
       }
     }
 
   // Create the DSP or set of DSP's for libraries and executables
 
-  cmTargets &tgts = this->Makefile->GetTargets();
-
-  // build any targets
-  for(cmTargets::iterator l = tgts.begin();
-      l != tgts.end(); l++)
+  std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
+  for(std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
+      l != tgts.end(); ++l)
     {
-    switch(l->second.GetType())
+    switch((*l)->GetType())
       {
-      case cmTarget::STATIC_LIBRARY:
-      case cmTarget::OBJECT_LIBRARY:
-        this->SetBuildType(STATIC_LIBRARY, l->first.c_str(), l->second);
+      case cmState::STATIC_LIBRARY:
+      case cmState::OBJECT_LIBRARY:
+        this->SetBuildType(STATIC_LIBRARY,
+                           (*l)->GetName().c_str(), *l);
         break;
-      case cmTarget::SHARED_LIBRARY:
-      case cmTarget::MODULE_LIBRARY:
-        this->SetBuildType(DLL, l->first.c_str(), l->second);
+      case cmState::SHARED_LIBRARY:
+      case cmState::MODULE_LIBRARY:
+        this->SetBuildType(DLL,
+                           (*l)->GetName().c_str(), *l);
         break;
-      case cmTarget::EXECUTABLE:
-        this->SetBuildType(EXECUTABLE,l->first.c_str(), l->second);
+      case cmState::EXECUTABLE:
+        this->SetBuildType(EXECUTABLE,
+                           (*l)->GetName().c_str(), *l);
         break;
-      case cmTarget::UTILITY:
-      case cmTarget::GLOBAL_TARGET:
-        this->SetBuildType(UTILITY, l->first.c_str(), l->second);
+      case cmState::UTILITY:
+      case cmState::GLOBAL_TARGET:
+        this->SetBuildType(UTILITY,
+                           (*l)->GetName().c_str(), *l);
         break;
-      case cmTarget::INTERFACE_LIBRARY:
+      case cmState::INTERFACE_LIBRARY:
         continue;
       default:
-        cmSystemTools::Error("Bad target type: ", l->first.c_str());
+        cmSystemTools::Error("Bad target type: ", (*l)->GetName().c_str());
         break;
       }
     // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
     // so don't build a projectfile for it
     const char* path =
-      l->second.GetProperty("EXTERNAL_MSPROJECT");
+      (*l)->GetProperty("EXTERNAL_MSPROJECT");
     if(!path)
       {
       // check to see if the dsp is going into a sub-directory
-      std::string::size_type pos = l->first.rfind('/');
+      std::string::size_type pos = (*l)->GetName().rfind('/');
       if(pos != std::string::npos)
         {
-        std::string dir = this->Makefile->GetCurrentBinaryDirectory();
+        std::string dir = this->GetCurrentBinaryDirectory();
         dir += "/";
-        dir += l->first.substr(0, pos);
+        dir += (*l)->GetName().substr(0, pos);
         if(!cmSystemTools::MakeDirectory(dir.c_str()))
           {
           cmSystemTools::Error("Error creating directory: ", dir.c_str());
           }
         }
-      this->CreateSingleDSP(l->first.c_str(),l->second);
+      this->CreateSingleDSP((*l)->GetName().c_str(), *l);
       }
     }
 }
@@ -182,14 +184,14 @@ void cmLocalVisualStudio6Generator::OutputDSPFile()
 extern std::string GetVS6TargetName(const std::string& targetName);
 
 void cmLocalVisualStudio6Generator::CreateSingleDSP(const std::string& lname,
-                                                    cmTarget &target)
+                                                    cmGeneratorTarget* target)
 {
   // add to the list of projects
   std::string pname = GetVS6TargetName(lname);
 
   // create the dsp.cmake file
   std::string fname;
-  fname = this->Makefile->GetCurrentBinaryDirectory();
+  fname = this->GetCurrentBinaryDirectory();
   fname += "/";
   fname += pname;
   fname += ".dsp";
@@ -209,13 +211,13 @@ void cmLocalVisualStudio6Generator::CreateSingleDSP(const std::string& lname,
 }
 
 
-void cmLocalVisualStudio6Generator::AddDSPBuildRule(cmTarget& tgt)
+void cmLocalVisualStudio6Generator::AddDSPBuildRule(cmGeneratorTarget *tgt)
 {
-  std::string dspname = GetVS6TargetName(tgt.GetName());
+  std::string dspname = GetVS6TargetName(tgt->GetName());
   dspname += ".dsp.cmake";
   cmCustomCommandLine commandLine;
   commandLine.push_back(cmSystemTools::GetCMakeCommand());
-  std::string makefileIn = this->Makefile->GetCurrentSourceDirectory();
+  std::string makefileIn = this->GetCurrentSourceDirectory();
   makefileIn += "/";
   makefileIn += "CMakeLists.txt";
   if(!cmSystemTools::FileExists(makefileIn.c_str()))
@@ -226,10 +228,10 @@ void cmLocalVisualStudio6Generator::AddDSPBuildRule(cmTarget& tgt)
   comment += makefileIn;
   std::string args;
   args = "-H";
-  args += this->Makefile->GetHomeDirectory();
+  args += this->GetSourceDirectory();
   commandLine.push_back(args);
   args = "-B";
-  args += this->Makefile->GetHomeOutputDirectory();
+  args += this->GetBinaryDirectory();
   commandLine.push_back(args);
 
   std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
@@ -243,7 +245,7 @@ void cmLocalVisualStudio6Generator::AddDSPBuildRule(cmTarget& tgt)
                                            no_working_directory, true);
   if(this->Makefile->GetSource(makefileIn.c_str()))
     {
-    tgt.AddSource(makefileIn);
+    tgt->AddSource(makefileIn);
     }
   else
     {
@@ -254,7 +256,7 @@ void cmLocalVisualStudio6Generator::AddDSPBuildRule(cmTarget& tgt)
 
 void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
                                                  const std::string& libName,
-                                                 cmTarget &target)
+                                                 cmGeneratorTarget *target)
 {
   // For utility targets need custom command since pre- and post-
   // build does not do anything in Visual Studio 6.  In order for the
@@ -262,23 +264,23 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
   // special care for dependencies.  The first rule must depend on all
   // the dependencies of all the rules.  The later rules must each
   // depend only on the previous rule.
-  if ((target.GetType() == cmTarget::UTILITY ||
-      target.GetType() == cmTarget::GLOBAL_TARGET) &&
-      (!target.GetPreBuildCommands().empty() ||
-       !target.GetPostBuildCommands().empty()))
+  if ((target->GetType() == cmState::UTILITY ||
+      target->GetType() == cmState::GLOBAL_TARGET) &&
+      (!target->GetPreBuildCommands().empty() ||
+       !target->GetPostBuildCommands().empty()))
     {
     // Accumulate the dependencies of all the commands.
     std::vector<std::string> depends;
     for (std::vector<cmCustomCommand>::const_iterator cr =
-           target.GetPreBuildCommands().begin();
-         cr != target.GetPreBuildCommands().end(); ++cr)
+           target->GetPreBuildCommands().begin();
+         cr != target->GetPreBuildCommands().end(); ++cr)
       {
       depends.insert(depends.end(),
                      cr->GetDepends().begin(), cr->GetDepends().end());
       }
     for (std::vector<cmCustomCommand>::const_iterator cr =
-           target.GetPostBuildCommands().begin();
-         cr != target.GetPostBuildCommands().end(); ++cr)
+           target->GetPostBuildCommands().begin();
+         cr != target->GetPostBuildCommands().end(); ++cr)
       {
       depends.insert(depends.end(),
                      cr->GetDepends().begin(), cr->GetDepends().end());
@@ -287,14 +289,14 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
     // Add the pre- and post-build commands in order.
     int count = 1;
     for (std::vector<cmCustomCommand>::const_iterator cr =
-           target.GetPreBuildCommands().begin();
-         cr != target.GetPreBuildCommands().end(); ++cr)
+           target->GetPreBuildCommands().begin();
+         cr != target->GetPreBuildCommands().end(); ++cr)
       {
       this->AddUtilityCommandHack(target, count++, depends, *cr);
       }
     for (std::vector<cmCustomCommand>::const_iterator cr =
-           target.GetPostBuildCommands().begin();
-         cr != target.GetPostBuildCommands().end(); ++cr)
+           target->GetPostBuildCommands().begin();
+         cr != target->GetPostBuildCommands().end(); ++cr)
       {
       this->AddUtilityCommandHack(target, count++, depends, *cr);
       }
@@ -303,12 +305,9 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
   // We may be modifying the source groups temporarily, so make a copy.
   std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
 
-  cmGeneratorTarget* gt =
-    this->GlobalGenerator->GetGeneratorTarget(&target);
-
   // get the classes from the source lists then add them to the groups
   std::vector<cmSourceFile*> classes;
-  if (!gt->GetConfigCommonSourceFiles(classes))
+  if (!target->GetConfigCommonSourceFiles(classes))
     {
     return;
     }
@@ -372,11 +371,9 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
 }
 
 void cmLocalVisualStudio6Generator
-::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
+::WriteGroup(const cmSourceGroup *sg, cmGeneratorTarget* target,
              std::ostream &fout, const std::string& libName)
 {
-  cmGeneratorTarget* gt =
-    this->GlobalGenerator->GetGeneratorTarget(&target);
   const std::vector<const cmSourceFile *> &sourceFiles =
     sg->GetSourceFiles();
   // If the group is empty, don't write it at all.
@@ -408,9 +405,10 @@ void cmLocalVisualStudio6Generator
     std::string compileFlags;
     std::vector<std::string> depends;
     std::string objectNameDir;
-    if(gt->HasExplicitObjectName(*sf))
+    if(target->HasExplicitObjectName(*sf))
       {
-      objectNameDir = cmSystemTools::GetFilenamePath(gt->GetObjectName(*sf));
+      objectNameDir =
+          cmSystemTools::GetFilenamePath(target->GetObjectName(*sf));
       }
 
     // Add per-source file flags.
@@ -481,8 +479,8 @@ void cmLocalVisualStudio6Generator
       cmSystemTools::ExpandListArgument(dependsValue, depends);
       }
     if (GetVS6TargetName(source) != libName ||
-      target.GetType() == cmTarget::UTILITY ||
-      target.GetType() == cmTarget::GLOBAL_TARGET)
+      target->GetType() == cmState::UTILITY ||
+      target->GetType() == cmState::GLOBAL_TARGET)
       {
       fout << "# Begin Source File\n\n";
 
@@ -572,15 +570,15 @@ void cmLocalVisualStudio6Generator
 
 void
 cmLocalVisualStudio6Generator
-::AddUtilityCommandHack(cmTarget& target, int count,
+::AddUtilityCommandHack(cmGeneratorTarget *target, int count,
                         std::vector<std::string>& depends,
                         const cmCustomCommand& origCommand)
 {
   // Create a fake output that forces the rule to run.
-  char* output = new char[(strlen(this->Makefile->GetCurrentBinaryDirectory())
-                           + target.GetName().size() + 30)];
-  sprintf(output,"%s/%s_force_%i", this->Makefile->GetCurrentBinaryDirectory(),
-          target.GetName().c_str(), count);
+  char* output = new char[(strlen(this->GetCurrentBinaryDirectory())
+                           + target->GetName().size() + 30)];
+  sprintf(output,"%s/%s_force_%i", this->GetCurrentBinaryDirectory(),
+          target->GetName().c_str(), count);
   const char* comment = origCommand.GetComment();
   if(!comment && origCommand.GetOutputs().empty())
     {
@@ -595,7 +593,7 @@ cmLocalVisualStudio6Generator
        origCommand.GetCommandLines(), comment,
        origCommand.GetWorkingDirectory().c_str()))
     {
-    target.AddSource(outsf->GetFullPath());
+    target->AddSource(outsf->GetFullPath());
     }
 
   // Replace the dependencies with the output of this rule so that the
@@ -711,7 +709,7 @@ void cmLocalVisualStudio6Generator::WriteDSPEndGroup(std::ostream& fout)
 
 void cmLocalVisualStudio6Generator::SetBuildType(BuildType b,
                                                  const std::string& libName,
-                                                 cmTarget& target)
+                                                 cmGeneratorTarget *target)
 {
   std::string root= this->Makefile->GetRequiredDefinition("CMAKE_ROOT");
   const char *def=
@@ -743,7 +741,7 @@ void cmLocalVisualStudio6Generator::SetBuildType(BuildType b,
       this->DSPFooterTemplate += "/DLLFooter.dsptemplate";
       break;
     case EXECUTABLE:
-      if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
+      if ( target->GetPropertyAsBool("WIN32_EXECUTABLE") )
         {
         this->DSPHeaderTemplate = root;
         this->DSPHeaderTemplate += "/EXEWinHeader.dsptemplate";
@@ -795,15 +793,16 @@ void cmLocalVisualStudio6Generator::SetBuildType(BuildType b,
 
 //----------------------------------------------------------------------------
 cmsys::auto_ptr<cmCustomCommand>
-cmLocalVisualStudio6Generator::MaybeCreateOutputDir(cmTarget& target,
+cmLocalVisualStudio6Generator::MaybeCreateOutputDir(cmGeneratorTarget* target,
                                                     const std::string& config)
 {
   cmsys::auto_ptr<cmCustomCommand> pcc;
 
   // VS6 forgets to create the output directory for archives if it
   // differs from the intermediate directory.
-  if(target.GetType() != cmTarget::STATIC_LIBRARY) { return pcc; }
-  std::string outDir = target.GetDirectory(config, false);
+  if(target->GetType() != cmState::STATIC_LIBRARY) { return pcc; }
+
+  std::string outDir = target->GetDirectory(config, false);
 
   // Add a pre-link event to create the directory.
   cmCustomCommandLine command;
@@ -825,11 +824,11 @@ cmLocalVisualStudio6Generator::MaybeCreateOutputDir(cmTarget& target,
 
 // look for custom rules on a target and collect them together
 std::string
-cmLocalVisualStudio6Generator::CreateTargetRules(cmTarget &target,
+cmLocalVisualStudio6Generator::CreateTargetRules(cmGeneratorTarget *target,
                                               const std::string& configName,
                                               const std::string& /* libName */)
 {
-  if (target.GetType() >= cmTarget::UTILITY )
+  if (target->GetType() >= cmState::UTILITY )
     {
     return "";
     }
@@ -839,8 +838,8 @@ cmLocalVisualStudio6Generator::CreateTargetRules(cmTarget &target,
 
   // Write the pre-build and pre-link together (VS6 does not support both).
   event.Start("PreLink");
-  event.Write(target.GetPreBuildCommands());
-  event.Write(target.GetPreLinkCommands());
+  event.Write(target->GetPreBuildCommands());
+  event.Write(target->GetPreLinkCommands());
   cmsys::auto_ptr<cmCustomCommand> pcc(
     this->MaybeCreateImplibDir(target, configName, false));
   if(pcc.get())
@@ -856,7 +855,7 @@ cmLocalVisualStudio6Generator::CreateTargetRules(cmTarget &target,
 
   // Write the post-build rules.
   event.Start("PostBuild");
-  event.Write(target.GetPostBuildCommands());
+  event.Write(target->GetPostBuildCommands());
   event.Finish();
 
   customRuleCode += "# End Special Build Tool\n";
@@ -875,7 +874,8 @@ inline std::string removeQuotes(const std::string& s)
 
 
 std::string
-cmLocalVisualStudio6Generator::GetTargetIncludeOptions(cmTarget &target,
+cmLocalVisualStudio6Generator::GetTargetIncludeOptions(
+        cmGeneratorTarget *target,
                                                   const std::string& config)
 {
   std::string includeOptions;
@@ -886,12 +886,10 @@ cmLocalVisualStudio6Generator::GetTargetIncludeOptions(cmTarget &target,
   unsigned int maxIncludeLength = 3000;
   bool useShortPath = false;
 
-  cmGeneratorTarget* gt =
-    this->GlobalGenerator->GetGeneratorTarget(&target);
   for(int j=0; j < 2; ++j)
     {
     std::vector<std::string> includes;
-    this->GetIncludeDirectories(includes, gt, "C", config);
+    this->GetIncludeDirectories(includes, target, "C", config);
 
     std::vector<std::string>::iterator i;
     for(i = includes.begin(); i != includes.end(); ++i)
@@ -939,11 +937,11 @@ cmLocalVisualStudio6Generator::GetTargetIncludeOptions(cmTarget &target,
 
 void cmLocalVisualStudio6Generator
 ::WriteDSPHeader(std::ostream& fout,
-                 const std::string& libName, cmTarget &target,
+                 const std::string& libName, cmGeneratorTarget* target,
                  std::vector<cmSourceGroup> &)
 {
-  bool targetBuilds = (target.GetType() >= cmTarget::EXECUTABLE &&
-                       target.GetType() <= cmTarget::MODULE_LIBRARY);
+  bool targetBuilds = (target->GetType() >= cmState::EXECUTABLE &&
+                       target->GetType() <= cmState::MODULE_LIBRARY);
 #ifdef CM_USE_OLD_VS6
   // Lookup the library and executable output directories.
   std::string libPath;
@@ -1053,7 +1051,8 @@ void cmLocalVisualStudio6Generator
       }
     }
   std::vector<std::string>::const_iterator i;
-  const std::vector<std::string>& libdirs = target.GetLinkDirectories();
+  const std::vector<std::string>& libdirs =
+      target->GetLinkDirectories();
   for(i = libdirs.begin(); i != libdirs.end(); ++i)
     {
     std::string path = *i;
@@ -1095,33 +1094,32 @@ void cmLocalVisualStudio6Generator
     }
   // find link libraries
   const cmTarget::LinkLibraryVectorType& libs =
-    target.GetLinkLibrariesForVS6();
+    target->Target->GetLinkLibrariesForVS6();
   cmTarget::LinkLibraryVectorType::const_iterator j;
   for(j = libs.begin(); j != libs.end(); ++j)
     {
     // add libraries to executables and dlls (but never include
     // a library in a library, bad recursion)
     // NEVER LINK STATIC LIBRARIES TO OTHER STATIC LIBRARIES
-    if ((target.GetType() != cmTarget::SHARED_LIBRARY
-         && target.GetType() != cmTarget::STATIC_LIBRARY
-         && target.GetType() != cmTarget::MODULE_LIBRARY) ||
-        (target.GetType()==cmTarget::SHARED_LIBRARY
+    if ((target->GetType() != cmState::SHARED_LIBRARY
+         && target->GetType() != cmState::STATIC_LIBRARY
+         && target->GetType() != cmState::MODULE_LIBRARY) ||
+        (target->GetType()==cmState::SHARED_LIBRARY
          && libName != GetVS6TargetName(j->first)) ||
-        (target.GetType()==cmTarget::MODULE_LIBRARY
+        (target->GetType()==cmState::MODULE_LIBRARY
          && libName != GetVS6TargetName(j->first)))
       {
       // Compute the proper name to use to link this library.
       std::string lib;
       std::string libDebug;
-      cmTarget* tgt = this->GlobalGenerator->FindTarget(j->first.c_str());
+      cmGeneratorTarget* tgt =
+          this->GlobalGenerator->FindGeneratorTarget(j->first.c_str());
       if(tgt)
         {
-        cmGeneratorTarget* gt =
-          this->GlobalGenerator->GetGeneratorTarget(tgt);
         lib = cmSystemTools::GetFilenameWithoutExtension
-          (gt->GetFullName().c_str());
+          (tgt->GetFullName().c_str());
         libDebug = cmSystemTools::GetFilenameWithoutExtension
-          (gt->GetFullName("Debug").c_str());
+          (tgt->GetFullName("Debug").c_str());
         lib += ".lib";
         libDebug += ".lib";
         }
@@ -1139,7 +1137,7 @@ void cmLocalVisualStudio6Generator
       libDebug =
         this->ConvertToOutputFormat(libDebug.c_str(), SHELL);
 
-      if (j->second == cmTarget::GENERAL)
+      if (j->second == GENERAL_LibraryType)
         {
         libOptions += " ";
         libOptions += lib;
@@ -1150,7 +1148,7 @@ void cmLocalVisualStudio6Generator
         libMultiLineOptionsForDebug +=  libDebug;
         libMultiLineOptionsForDebug += "\n";
         }
-      if (j->second == cmTarget::DEBUG)
+      if (j->second == DEBUG_LibraryType)
         {
         libDebugOptions += " ";
         libDebugOptions += lib;
@@ -1159,7 +1157,7 @@ void cmLocalVisualStudio6Generator
         libMultiLineDebugOptions += libDebug;
         libMultiLineDebugOptions += "\n";
         }
-      if (j->second == cmTarget::OPTIMIZED)
+      if (j->second == OPTIMIZED_LibraryType)
         {
         libOptimizedOptions += " ";
         libOptimizedOptions += lib;
@@ -1189,7 +1187,7 @@ void cmLocalVisualStudio6Generator
   std::string extraLinkOptionsRelease;
   std::string extraLinkOptionsMinSizeRel;
   std::string extraLinkOptionsRelWithDebInfo;
-  if(target.GetType() == cmTarget::EXECUTABLE)
+  if(target->GetType() == cmState::EXECUTABLE)
     {
     extraLinkOptions = this->Makefile->
       GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS");
@@ -1202,7 +1200,7 @@ void cmLocalVisualStudio6Generator
     extraLinkOptionsRelWithDebInfo = this->Makefile->
       GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO");
     }
-  if(target.GetType() == cmTarget::SHARED_LIBRARY)
+  if(target->GetType() == cmState::SHARED_LIBRARY)
     {
     extraLinkOptions = this->Makefile->
       GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS");
@@ -1215,7 +1213,7 @@ void cmLocalVisualStudio6Generator
     extraLinkOptionsRelWithDebInfo = this->Makefile->
       GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO");
     }
-  if(target.GetType() == cmTarget::MODULE_LIBRARY)
+  if(target->GetType() == cmState::MODULE_LIBRARY)
     {
     extraLinkOptions = this->Makefile->
       GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS");
@@ -1230,63 +1228,61 @@ void cmLocalVisualStudio6Generator
     }
 
   // Get extra linker options for this target.
-  if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS"))
+  if(const char* targetLinkFlags = target->GetProperty("LINK_FLAGS"))
     {
     extraLinkOptions += " ";
     extraLinkOptions += targetLinkFlags;
     }
 
-  if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_DEBUG"))
+  if(const char* targetLinkFlags = target->GetProperty("LINK_FLAGS_DEBUG"))
     {
     extraLinkOptionsDebug += " ";
     extraLinkOptionsDebug += targetLinkFlags;
     }
 
-  if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_RELEASE"))
+  if(const char* targetLinkFlags = target->GetProperty("LINK_FLAGS_RELEASE"))
     {
     extraLinkOptionsRelease += " ";
     extraLinkOptionsRelease += targetLinkFlags;
     }
 
-  if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_MINSIZEREL"))
+  if(const char* targetLinkFlags =
+     target->GetProperty("LINK_FLAGS_MINSIZEREL"))
     {
     extraLinkOptionsMinSizeRel += " ";
     extraLinkOptionsMinSizeRel += targetLinkFlags;
     }
 
   if(const char* targetLinkFlags =
-     target.GetProperty("LINK_FLAGS_RELWITHDEBINFO"))
+     target->GetProperty("LINK_FLAGS_RELWITHDEBINFO"))
     {
     extraLinkOptionsRelWithDebInfo += " ";
     extraLinkOptionsRelWithDebInfo += targetLinkFlags;
     }
 
-  cmGeneratorTarget* gt =
-    this->GlobalGenerator->GetGeneratorTarget(&target);
-
   // Get standard libraries for this language.
   if(targetBuilds)
     {
     // Get the language to use for linking.
     std::vector<std::string> configs;
-    target.GetMakefile()->GetConfigurations(configs);
+    target->Target->GetMakefile()->GetConfigurations(configs);
     std::vector<std::string>::const_iterator it = configs.begin();
-    const std::string& linkLanguage = gt->GetLinkerLanguage(*it);
+    const std::string& linkLanguage = target->GetLinkerLanguage(*it);
     for ( ; it != configs.end(); ++it)
       {
-      const std::string& configLinkLanguage = gt->GetLinkerLanguage(*it);
+      const std::string& configLinkLanguage = target->GetLinkerLanguage(*it);
       if (configLinkLanguage != linkLanguage)
         {
         cmSystemTools::Error
           ("Linker language must not vary by configuration for target: ",
-          target.GetName().c_str());
+          target->GetName().c_str());
         }
       }
     if(linkLanguage.empty())
       {
       cmSystemTools::Error
         ("CMake can not determine linker language for target: ",
-         target.GetName().c_str());
+         target->GetName().c_str());
       return;
       }
 
@@ -1307,13 +1303,13 @@ void cmLocalVisualStudio6Generator
 
   // Compute version number information.
   std::string targetVersionFlag;
-  if(target.GetType() == cmTarget::EXECUTABLE ||
-     target.GetType() == cmTarget::SHARED_LIBRARY ||
-     target.GetType() == cmTarget::MODULE_LIBRARY)
+  if(target->GetType() == cmState::EXECUTABLE ||
+     target->GetType() == cmState::SHARED_LIBRARY ||
+     target->GetType() == cmState::MODULE_LIBRARY)
     {
     int major;
     int minor;
-    target.GetTargetVersion(major, minor);
+    target->GetTargetVersion(major, minor);
     std::ostringstream targetVersionStream;
     targetVersionStream << "/version:" << major << "." << minor;
     targetVersionFlag = targetVersionStream.str();
@@ -1326,20 +1322,20 @@ void cmLocalVisualStudio6Generator
   std::string outputNameRelease = outputName;
   std::string outputNameMinSizeRel = outputName;
   std::string outputNameRelWithDebInfo = outputName;
-  if(target.GetType() == cmTarget::EXECUTABLE ||
-     target.GetType() == cmTarget::STATIC_LIBRARY ||
-     target.GetType() == cmTarget::SHARED_LIBRARY ||
-     target.GetType() == cmTarget::MODULE_LIBRARY)
+  if(target->GetType() == cmState::EXECUTABLE ||
+     target->GetType() == cmState::STATIC_LIBRARY ||
+     target->GetType() == cmState::SHARED_LIBRARY ||
+     target->GetType() == cmState::MODULE_LIBRARY)
     {
-    outputName = gt->GetFullName();
-    outputNameDebug = gt->GetFullName("Debug");
-    outputNameRelease = gt->GetFullName("Release");
-    outputNameMinSizeRel = gt->GetFullName("MinSizeRel");
-    outputNameRelWithDebInfo = gt->GetFullName("RelWithDebInfo");
+    outputName = target->GetFullName();
+    outputNameDebug = target->GetFullName("Debug");
+    outputNameRelease = target->GetFullName("Release");
+    outputNameMinSizeRel = target->GetFullName("MinSizeRel");
+    outputNameRelWithDebInfo = target->GetFullName("RelWithDebInfo");
     }
-  else if(target.GetType() == cmTarget::OBJECT_LIBRARY)
+  else if(target->GetType() == cmState::OBJECT_LIBRARY)
     {
-    outputName = target.GetName();
+    outputName = target->GetName();
     outputName += ".lib";
     outputNameDebug = outputName;
     outputNameRelease = outputName;
@@ -1353,30 +1349,30 @@ void cmLocalVisualStudio6Generator
   std::string outputDirRelease;
   std::string outputDirMinSizeRel;
   std::string outputDirRelWithDebInfo;
-  if(target.GetType() == cmTarget::EXECUTABLE ||
-     target.GetType() == cmTarget::STATIC_LIBRARY ||
-     target.GetType() == cmTarget::SHARED_LIBRARY ||
-     target.GetType() == cmTarget::MODULE_LIBRARY)
+  if(target->GetType() == cmState::EXECUTABLE ||
+     target->GetType() == cmState::STATIC_LIBRARY ||
+     target->GetType() == cmState::SHARED_LIBRARY ||
+     target->GetType() == cmState::MODULE_LIBRARY)
     {
 #ifdef CM_USE_OLD_VS6
     outputDirOld =
       removeQuotes(this->ConvertToOutputFormat
-                   (target.GetDirectory().c_str(), SHELL));
+                   (target->GetDirectory().c_str(), SHELL));
 #endif
     outputDirDebug =
         removeQuotes(this->ConvertToOutputFormat(
-                       target.GetDirectory("Debug").c_str(), SHELL));
+                       target->GetDirectory("Debug").c_str(), SHELL));
     outputDirRelease =
         removeQuotes(this->ConvertToOutputFormat(
-                 target.GetDirectory("Release").c_str(), SHELL));
+                 target->GetDirectory("Release").c_str(), SHELL));
     outputDirMinSizeRel =
         removeQuotes(this->ConvertToOutputFormat(
-                 target.GetDirectory("MinSizeRel").c_str(), SHELL));
+                 target->GetDirectory("MinSizeRel").c_str(), SHELL));
     outputDirRelWithDebInfo =
         removeQuotes(this->ConvertToOutputFormat(
-                 target.GetDirectory("RelWithDebInfo").c_str(), SHELL));
+                 target->GetDirectory("RelWithDebInfo").c_str(), SHELL));
     }
-  else if(target.GetType() == cmTarget::OBJECT_LIBRARY)
+  else if(target->GetType() == cmState::OBJECT_LIBRARY)
     {
     std::string outputDir = cmake::GetCMakeFilesDirectoryPostSlash();
     outputDirDebug = outputDir + "Debug";
@@ -1390,9 +1386,9 @@ void cmLocalVisualStudio6Generator
   std::string optionsRelease;
   std::string optionsMinSizeRel;
   std::string optionsRelWithDebInfo;
-  if(target.GetType() == cmTarget::EXECUTABLE ||
-     target.GetType() == cmTarget::SHARED_LIBRARY ||
-     target.GetType() == cmTarget::MODULE_LIBRARY)
+  if(target->GetType() == cmState::EXECUTABLE ||
+     target->GetType() == cmState::SHARED_LIBRARY ||
+     target->GetType() == cmState::MODULE_LIBRARY)
     {
     extraLinkOptionsDebug =
       extraLinkOptions + " " + extraLinkOptionsDebug;
@@ -1418,24 +1414,24 @@ void cmLocalVisualStudio6Generator
   std::string targetImplibFlagRelease;
   std::string targetImplibFlagMinSizeRel;
   std::string targetImplibFlagRelWithDebInfo;
-  if(target.GetType() == cmTarget::SHARED_LIBRARY ||
-     target.GetType() == cmTarget::MODULE_LIBRARY ||
-     target.GetType() == cmTarget::EXECUTABLE)
+  if(target->GetType() == cmState::SHARED_LIBRARY ||
+     target->GetType() == cmState::MODULE_LIBRARY ||
+     target->GetType() == cmState::EXECUTABLE)
     {
-    std::string fullPathImpDebug = target.GetDirectory("Debug", true);
-    std::string fullPathImpRelease = target.GetDirectory("Release", true);
+    std::string fullPathImpDebug = target->GetDirectory("Debug", true);
+    std::string fullPathImpRelease = target->GetDirectory("Release", true);
     std::string fullPathImpMinSizeRel =
-      target.GetDirectory("MinSizeRel", true);
+      target->GetDirectory("MinSizeRel", true);
     std::string fullPathImpRelWithDebInfo =
-      target.GetDirectory("RelWithDebInfo", true);
+      target->GetDirectory("RelWithDebInfo", true);
     fullPathImpDebug += "/";
     fullPathImpRelease += "/";
     fullPathImpMinSizeRel += "/";
     fullPathImpRelWithDebInfo += "/";
-    fullPathImpDebug += gt->GetFullName("Debug", true);
-    fullPathImpRelease += gt->GetFullName("Release", true);
-    fullPathImpMinSizeRel += gt->GetFullName("MinSizeRel", true);
-    fullPathImpRelWithDebInfo += gt->GetFullName("RelWithDebInfo", true);
+    fullPathImpDebug += target->GetFullName("Debug", true);
+    fullPathImpRelease += target->GetFullName("Release", true);
+    fullPathImpMinSizeRel += target->GetFullName("MinSizeRel", true);
+    fullPathImpRelWithDebInfo += target->GetFullName("RelWithDebInfo", true);
 
     targetImplibFlagDebug = "/implib:";
     targetImplibFlagRelease = "/implib:";
@@ -1488,7 +1484,7 @@ void cmLocalVisualStudio6Generator
   std::string staticLibOptionsRelease;
   std::string staticLibOptionsMinSizeRel;
   std::string staticLibOptionsRelWithDebInfo;
-  if(target.GetType() == cmTarget::STATIC_LIBRARY )
+  if(target->GetType() == cmState::STATIC_LIBRARY )
     {
     const char *libflagsGlobal =
       this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS");
@@ -1507,7 +1503,7 @@ void cmLocalVisualStudio6Generator
     this->AppendFlags(staticLibOptionsRelWithDebInfo, this->Makefile->
       GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO"));
 
-    const char *libflags = target.GetProperty("STATIC_LIBRARY_FLAGS");
+    const char *libflags = target->GetProperty("STATIC_LIBRARY_FLAGS");
     this->AppendFlags(staticLibOptions, libflags);
     this->AppendFlags(staticLibOptionsDebug, libflags);
     this->AppendFlags(staticLibOptionsRelease, libflags);
@@ -1515,13 +1511,13 @@ void cmLocalVisualStudio6Generator
     this->AppendFlags(staticLibOptionsRelWithDebInfo, libflags);
 
     this->AppendFlags(staticLibOptionsDebug,
-      target.GetProperty("STATIC_LIBRARY_FLAGS_DEBUG"));
+      target->GetProperty("STATIC_LIBRARY_FLAGS_DEBUG"));
     this->AppendFlags(staticLibOptionsRelease,
-      target.GetProperty("STATIC_LIBRARY_FLAGS_RELEASE"));
+      target->GetProperty("STATIC_LIBRARY_FLAGS_RELEASE"));
     this->AppendFlags(staticLibOptionsMinSizeRel,
-      target.GetProperty("STATIC_LIBRARY_FLAGS_MINSIZEREL"));
+      target->GetProperty("STATIC_LIBRARY_FLAGS_MINSIZEREL"));
     this->AppendFlags(staticLibOptionsRelWithDebInfo,
-      target.GetProperty("STATIC_LIBRARY_FLAGS_RELWITHDEBINFO"));
+      target->GetProperty("STATIC_LIBRARY_FLAGS_RELWITHDEBINFO"));
 
     std::string objects;
     this->OutputObjects(target, "LIB", objects);
@@ -1537,7 +1533,7 @@ void cmLocalVisualStudio6Generator
 
   // Add the export symbol definition for shared library objects.
   std::string exportSymbol;
-  if(const char* exportMacro = target.GetExportMacro())
+  if(const char* exportMacro = target->GetExportMacro())
     {
     exportSymbol = exportMacro;
     }
@@ -1561,8 +1557,8 @@ void cmLocalVisualStudio6Generator
                                  libnameExports.c_str());
     cmSystemTools::ReplaceString(line, "CMAKE_MFC_FLAG",
                                  mfcFlag);
-    if(target.GetType() == cmTarget::STATIC_LIBRARY ||
-       target.GetType() == cmTarget::OBJECT_LIBRARY)
+    if(target->GetType() == cmState::STATIC_LIBRARY ||
+       target->GetType() == cmState::OBJECT_LIBRARY)
       {
       cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS_DEBUG",
                                    staticLibOptionsDebug.c_str());
@@ -1668,7 +1664,7 @@ void cmLocalVisualStudio6Generator
                     (exePath.c_str(), SHELL)).c_str());
 #endif
 
-    if(targetBuilds || target.GetType() == cmTarget::OBJECT_LIBRARY)
+    if(targetBuilds || target->GetType() == cmState::OBJECT_LIBRARY)
       {
       cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY_DEBUG",
                                    outputDirDebug.c_str());
@@ -1692,8 +1688,8 @@ void cmLocalVisualStudio6Generator
       = this->Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
     cmSystemTools::ReplaceString(line, "DEBUG_POSTFIX",
                                  debugPostfix?debugPostfix:"");
-    if(target.GetType() >= cmTarget::EXECUTABLE &&
-       target.GetType() <= cmTarget::OBJECT_LIBRARY)
+    if(target->GetType() >= cmState::EXECUTABLE &&
+       target->GetType() <= cmState::OBJECT_LIBRARY)
       {
       // store flags for each configuration
       std::string flags = " ";
@@ -1702,24 +1698,24 @@ void cmLocalVisualStudio6Generator
       std::string flagsDebug = " ";
       std::string flagsRelWithDebInfo = " ";
       std::vector<std::string> configs;
-      target.GetMakefile()->GetConfigurations(configs);
+      target->Target->GetMakefile()->GetConfigurations(configs);
       std::vector<std::string>::const_iterator it = configs.begin();
-      const std::string& linkLanguage = gt->GetLinkerLanguage(*it);
+      const std::string& linkLanguage = target->GetLinkerLanguage(*it);
       for ( ; it != configs.end(); ++it)
         {
-        const std::string& configLinkLanguage = gt->GetLinkerLanguage(*it);
+        const std::string& configLinkLanguage = target->GetLinkerLanguage(*it);
         if (configLinkLanguage != linkLanguage)
           {
           cmSystemTools::Error
             ("Linker language must not vary by configuration for target: ",
-            target.GetName().c_str());
+            target->GetName().c_str());
           }
         }
       if(linkLanguage.empty())
         {
         cmSystemTools::Error
           ("CMake can not determine linker language for target: ",
-           target.GetName().c_str());
+           target->GetName().c_str());
         return;
         }
       // if CXX is on and the target contains cxx code then add the cxx flags
@@ -1744,12 +1740,12 @@ void cmLocalVisualStudio6Generator
       flagsRelWithDebInfo = this->Makefile->GetSafeDefinition(flagVar.c_str());
       flagsRelWithDebInfo += " -DCMAKE_INTDIR=\\\"RelWithDebInfo\\\" ";
 
-      this->AddCompileOptions(flags, &target, linkLanguage, "");
-      this->AddCompileOptions(flagsDebug, &target, linkLanguage, "Debug");
-      this->AddCompileOptions(flagsRelease, &target, linkLanguage, "Release");
-      this->AddCompileOptions(flagsMinSizeRel, &target, linkLanguage,
+      this->AddCompileOptions(flags, target, linkLanguage, "");
+      this->AddCompileOptions(flagsDebug, target, linkLanguage, "Debug");
+      this->AddCompileOptions(flagsRelease, target, linkLanguage, "Release");
+      this->AddCompileOptions(flagsMinSizeRel, target, linkLanguage,
                               "MinSizeRel");
-      this->AddCompileOptions(flagsRelWithDebInfo, &target, linkLanguage,
+      this->AddCompileOptions(flagsRelWithDebInfo, target, linkLanguage,
                               "RelWithDebInfo");
 
       // if _UNICODE and _SBCS are not found, then add -D_MBCS
@@ -1769,14 +1765,14 @@ void cmLocalVisualStudio6Generator
       std::set<std::string> minsizeDefinesSet;
       std::set<std::string> debugrelDefinesSet;
 
-      this->AddCompileDefinitions(definesSet, &target, "", linkLanguage);
-      this->AddCompileDefinitions(debugDefinesSet, &target,
+      this->AddCompileDefinitions(definesSet, target, "", linkLanguage);
+      this->AddCompileDefinitions(debugDefinesSet, target,
                                   "DEBUG", linkLanguage);
-      this->AddCompileDefinitions(releaseDefinesSet, &target,
+      this->AddCompileDefinitions(releaseDefinesSet, target,
                                   "RELEASE", linkLanguage);
-      this->AddCompileDefinitions(minsizeDefinesSet, &target,
+      this->AddCompileDefinitions(minsizeDefinesSet, target,
                                   "MINSIZEREL", linkLanguage);
-      this->AddCompileDefinitions(debugrelDefinesSet, &target,
+      this->AddCompileDefinitions(debugrelDefinesSet, target,
                                   "RELWITHDEBINFO", linkLanguage);
 
       std::string defines = " ";
@@ -1844,15 +1840,13 @@ void cmLocalVisualStudio6Generator::WriteDSPFooter(std::ostream& fout)
 
 //----------------------------------------------------------------------------
 void cmLocalVisualStudio6Generator
-::ComputeLinkOptions(cmTarget& target,
+::ComputeLinkOptions(cmGeneratorTarget *target,
                      const std::string& configName,
                      const std::string extraOptions,
                      std::string& options)
 {
-  cmGeneratorTarget* gt =
-    this->GlobalGenerator->GetGeneratorTarget(&target);
   // Compute the link information for this configuration.
-  cmComputeLinkInformation* pcli = gt->GetLinkInformation(configName);
+  cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
   if(!pcli)
     {
     return;
@@ -1893,7 +1887,7 @@ void cmLocalVisualStudio6Generator
         this->ConvertToOutputFormat(l->Value.c_str(), SHELL);
       }
     else if (!l->Target
-        || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
+        || l->Target->GetType() != cmState::INTERFACE_LIBRARY)
       {
       options += l->Value;
       }
@@ -1911,15 +1905,13 @@ void cmLocalVisualStudio6Generator
 
 //----------------------------------------------------------------------------
 void cmLocalVisualStudio6Generator
-::OutputObjects(cmTarget& target, const char* tool,
+::OutputObjects(cmGeneratorTarget* target, const char* tool,
                 std::string& options)
 {
   // VS 6 does not support per-config source locations so we
   // list object library content on the link line instead.
-  cmGeneratorTarget* gt =
-    this->GlobalGenerator->GetGeneratorTarget(&target);
   std::vector<std::string> objs;
-  gt->UseObjectLibraries(objs, "");
+  target->UseObjectLibraries(objs, "");
   for(std::vector<std::string>::const_iterator
         oi = objs.begin(); oi != objs.end(); ++oi)
     {
@@ -1933,7 +1925,7 @@ void cmLocalVisualStudio6Generator
 
 std::string
 cmLocalVisualStudio6Generator
-::GetTargetDirectory(cmTarget const&) const
+::GetTargetDirectory(cmGeneratorTarget const*) const
 {
   // No per-target directory for this generator (yet).
   return "";
@@ -1942,7 +1934,7 @@ cmLocalVisualStudio6Generator
 //----------------------------------------------------------------------------
 std::string
 cmLocalVisualStudio6Generator
-::ComputeLongestObjectDirectory(cmTarget&) const
+::ComputeLongestObjectDirectory(cmGeneratorTarget const*) const
 {
   // Compute the maximum length configuration name.
   std::string config_max;
@@ -1962,7 +1954,7 @@ cmLocalVisualStudio6Generator
   // files directory for any configuration.  This is used to construct
   // object file names that do not produce paths that are too long.
   std::string dir_max;
-  dir_max += this->Makefile->GetCurrentBinaryDirectory();
+  dir_max += this->GetCurrentBinaryDirectory();
   dir_max += "/";
   dir_max += config_max;
   dir_max += "/";
diff --git a/Source/cmLocalVisualStudio6Generator.h b/Source/cmLocalVisualStudio6Generator.h
index 828d252..dab32a5 100644
--- a/Source/cmLocalVisualStudio6Generator.h
+++ b/Source/cmLocalVisualStudio6Generator.h
@@ -14,7 +14,6 @@
 
 #include "cmLocalVisualStudioGenerator.h"
 
-class cmTarget;
 class cmSourceFile;
 class cmSourceGroup;
 class cmCustomCommand;
@@ -47,49 +46,52 @@ public:
   /**
    * Specify the type of the build: static, dll, or executable.
    */
-  void SetBuildType(BuildType, const std::string& libName, cmTarget&);
+  void SetBuildType(BuildType, const std::string& libName, cmGeneratorTarget*);
 
-  virtual std::string GetTargetDirectory(cmTarget const& target) const;
-  virtual std::string ComputeLongestObjectDirectory(cmTarget&) const;
+  virtual
+  std::string GetTargetDirectory(cmGeneratorTarget const* target) const;
+  virtual std::string
+  ComputeLongestObjectDirectory(cmGeneratorTarget const*) const;
 private:
   std::string DSPHeaderTemplate;
   std::string DSPFooterTemplate;
 
-  void CreateSingleDSP(const std::string& lname, cmTarget &tgt);
+  void CreateSingleDSP(const std::string& lname, cmGeneratorTarget* tgt);
   void WriteDSPFile(std::ostream& fout, const std::string& libName,
-                    cmTarget &tgt);
+                    cmGeneratorTarget* tgt);
   void WriteDSPBeginGroup(std::ostream& fout,
                           const char* group,
                           const char* filter);
   void WriteDSPEndGroup(std::ostream& fout);
 
   void WriteDSPHeader(std::ostream& fout, const std::string& libName,
-                      cmTarget &tgt, std::vector<cmSourceGroup> &sgs);
+                      cmGeneratorTarget* tgt, std::vector<cmSourceGroup> &sgs);
 
   void WriteDSPFooter(std::ostream& fout);
-  void AddDSPBuildRule(cmTarget& tgt);
+  void AddDSPBuildRule(cmGeneratorTarget* tgt);
   void WriteCustomRule(std::ostream& fout,
                        const char* source,
                        const cmCustomCommand& command,
                        const char* flags);
-  void AddUtilityCommandHack(cmTarget& target, int count,
+  void AddUtilityCommandHack(cmGeneratorTarget* target, int count,
                              std::vector<std::string>& depends,
                              const cmCustomCommand& origCommand);
-  void WriteGroup(const cmSourceGroup *sg, cmTarget& target,
+  void WriteGroup(const cmSourceGroup *sg, cmGeneratorTarget* target,
                   std::ostream &fout, const std::string& libName);
   class EventWriter;
   friend class EventWriter;
   cmsys::auto_ptr<cmCustomCommand>
-  MaybeCreateOutputDir(cmTarget& target, const std::string& config);
-  std::string CreateTargetRules(cmTarget &target,
+  MaybeCreateOutputDir(cmGeneratorTarget *target, const std::string& config);
+  std::string CreateTargetRules(cmGeneratorTarget* target,
                                 const std::string& configName,
                                 const std::string& libName);
-  void ComputeLinkOptions(cmTarget& target, const std::string& configName,
+  void ComputeLinkOptions(cmGeneratorTarget* target,
+                          const std::string& configName,
                           const std::string extraOptions,
                           std::string& options);
-  void OutputObjects(cmTarget& target, const char* tool,
+  void OutputObjects(cmGeneratorTarget* target, const char* tool,
                      std::string& options);
-  std::string GetTargetIncludeOptions(cmTarget &target,
+  std::string GetTargetIncludeOptions(cmGeneratorTarget* target,
                                       const std::string& config);
   std::vector<std::string> Configurations;
 
diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx
index a4bce8a..ae6a24e 100644
--- a/Source/cmLocalVisualStudio7Generator.cxx
+++ b/Source/cmLocalVisualStudio7Generator.cxx
@@ -34,7 +34,8 @@ public:
     LocalGenerator(e) {}
   typedef cmComputeLinkInformation::ItemVector ItemVector;
   void OutputLibraries(std::ostream& fout, ItemVector const& libs);
-  void OutputObjects(std::ostream& fout, cmTarget* t, const char* isep = 0);
+  void OutputObjects(std::ostream& fout, cmGeneratorTarget* t,
+                     const char* isep = 0);
 private:
   cmLocalVisualStudio7Generator* LocalGenerator;
 };
@@ -67,19 +68,19 @@ cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
 void cmLocalVisualStudio7Generator::AddHelperCommands()
 {
   // Now create GUIDs for targets
-  cmTargets &tgts = this->Makefile->GetTargets();
-
-  for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
+  std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
+  for(std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
+      l != tgts.end(); ++l)
     {
-    if(l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
+    if((*l)->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
-    const char* path = l->second.GetProperty("EXTERNAL_MSPROJECT");
+    const char* path = (*l)->GetProperty("EXTERNAL_MSPROJECT");
     if(path)
       {
       this->ReadAndStoreExternalGUID(
-        l->second.GetName().c_str(), path);
+        (*l)->GetName().c_str(), path);
       }
     }
 
@@ -95,7 +96,6 @@ void cmLocalVisualStudio7Generator::Generate()
 
 void cmLocalVisualStudio7Generator::AddCMakeListsRules()
 {
-  cmTargets &tgts = this->Makefile->GetTargets();
   // Create the regeneration custom rule.
   if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION"))
     {
@@ -104,15 +104,17 @@ void cmLocalVisualStudio7Generator::AddCMakeListsRules()
     if(cmSourceFile* sf = this->CreateVCProjBuildRule())
       {
       // Add the rule to targets that need it.
-      for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
+      std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
+      for(std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
+          l != tgts.end(); ++l)
         {
-        if (l->second.GetType() == cmTarget::GLOBAL_TARGET)
+        if ((*l)->GetType() == cmState::GLOBAL_TARGET)
           {
           continue;
           }
-        if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
+        if((*l)->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
           {
-          l->second.AddSource(sf->GetFullPath());
+          (*l)->AddSource(sf->GetFullPath());
           }
         }
       }
@@ -124,12 +126,11 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets()
   // Visual Studio .NET 2003 Service Pack 1 will not run post-build
   // commands for targets in which no sources are built.  Add dummy
   // rules to force these targets to build.
-  cmTargets &tgts = this->Makefile->GetTargets();
-  for(cmTargets::iterator l = tgts.begin();
+  std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
+  for(std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
       l != tgts.end(); l++)
     {
-    cmTarget& tgt = l->second;
-    if(tgt.GetType() == cmTarget::GLOBAL_TARGET)
+    if((*l)->GetType() == cmState::GLOBAL_TARGET)
       {
       std::vector<std::string> no_depends;
       cmCustomCommandLine force_command;
@@ -138,17 +139,17 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets()
       cmCustomCommandLines force_commands;
       force_commands.push_back(force_command);
       std::string no_main_dependency = "";
-      std::string force = this->Makefile->GetCurrentBinaryDirectory();
+      std::string force = this->GetCurrentBinaryDirectory();
       force += cmake::GetCMakeFilesDirectory();
       force += "/";
-      force += tgt.GetName();
+      force += (*l)->GetName();
       force += "_force";
       if(cmSourceFile* file =
          this->Makefile->AddCustomCommandToOutput(
            force.c_str(), no_depends, no_main_dependency,
            force_commands, " ", 0, true))
         {
-        tgt.AddSource(file->GetFullPath());
+        (*l)->AddSource(file->GetFullPath());
         }
       }
     }
@@ -160,33 +161,33 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets()
 void cmLocalVisualStudio7Generator::WriteProjectFiles()
 {
   // If not an in source build, then create the output directory
-  if(strcmp(this->Makefile->GetCurrentBinaryDirectory(),
-            this->Makefile->GetHomeDirectory()) != 0)
+  if(strcmp(this->GetCurrentBinaryDirectory(),
+            this->GetSourceDirectory()) != 0)
     {
     if(!cmSystemTools::MakeDirectory
-       (this->Makefile->GetCurrentBinaryDirectory()))
+       (this->GetCurrentBinaryDirectory()))
       {
       cmSystemTools::Error("Error creating directory ",
-                           this->Makefile->GetCurrentBinaryDirectory());
+                           this->GetCurrentBinaryDirectory());
       }
     }
 
   // Get the set of targets in this directory.
-  cmTargets &tgts = this->Makefile->GetTargets();
+  std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
 
   // Create the project file for each target.
-  for(cmTargets::iterator l = tgts.begin();
+  for(std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
       l != tgts.end(); l++)
     {
-    if(l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
+    if((*l)->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
     // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
     // so don't build a projectfile for it
-    if(!l->second.GetProperty("EXTERNAL_MSPROJECT"))
+    if(!(*l)->GetProperty("EXTERNAL_MSPROJECT"))
       {
-      this->CreateSingleVCProj(l->first.c_str(),l->second);
+      this->CreateSingleVCProj((*l)->GetName().c_str(), *l);
       }
     }
 }
@@ -196,7 +197,7 @@ void cmLocalVisualStudio7Generator::WriteStampFiles()
 {
   // Touch a timestamp file used to determine when the project file is
   // out of date.
-  std::string stampName = this->Makefile->GetCurrentBinaryDirectory();
+  std::string stampName = this->GetCurrentBinaryDirectory();
   stampName += cmake::GetCMakeFilesDirectory();
   cmSystemTools::MakeDirectory(stampName.c_str());
   stampName += "/";
@@ -224,7 +225,7 @@ void cmLocalVisualStudio7Generator::WriteStampFiles()
 
 //----------------------------------------------------------------------------
 void cmLocalVisualStudio7Generator
-::CreateSingleVCProj(const std::string& lname, cmTarget &target)
+::CreateSingleVCProj(const std::string& lname, cmGeneratorTarget *target)
 {
   cmGlobalVisualStudioGenerator* gg
       = static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
@@ -240,10 +241,10 @@ void cmLocalVisualStudio7Generator
     }
 
   // add to the list of projects
-  target.SetProperty("GENERATOR_FILE_NAME",lname.c_str());
+  target->Target->SetProperty("GENERATOR_FILE_NAME",lname.c_str());
   // create the dsp.cmake file
   std::string fname;
-  fname = this->Makefile->GetCurrentBinaryDirectory();
+  fname = this->GetCurrentBinaryDirectory();
   fname += "/";
   fname += lname;
   if(this->FortranProject)
@@ -272,13 +273,13 @@ void cmLocalVisualStudio7Generator
 //----------------------------------------------------------------------------
 cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
 {
-  std::string stampName = this->Makefile->GetCurrentBinaryDirectory();
+  std::string stampName = this->GetCurrentBinaryDirectory();
   stampName += "/";
   stampName += cmake::GetCMakeFilesDirectoryPostSlash();
   stampName += "generate.stamp";
   cmCustomCommandLine commandLine;
   commandLine.push_back(cmSystemTools::GetCMakeCommand());
-  std::string makefileIn = this->Makefile->GetCurrentSourceDirectory();
+  std::string makefileIn = this->GetCurrentSourceDirectory();
   makefileIn += "/";
   makefileIn += "CMakeLists.txt";
   makefileIn = cmSystemTools::CollapseFullPath(makefileIn.c_str());
@@ -290,10 +291,10 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
   comment += makefileIn;
   std::string args;
   args = "-H";
-  args += this->Makefile->GetHomeDirectory();
+  args += this->GetSourceDirectory();
   commandLine.push_back(args);
   args = "-B";
-  args += this->Makefile->GetHomeOutputDirectory();
+  args += this->GetBinaryDirectory();
   commandLine.push_back(args);
   commandLine.push_back("--check-stamp-file");
   std::string stampFilename = this->Convert(stampName.c_str(), FULL,
@@ -323,8 +324,9 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
 }
 
 void cmLocalVisualStudio7Generator::WriteConfigurations(
-  std::ostream& fout, std::vector<std::string> const& configs,
-  const std::string& libName, cmTarget &target
+    std::ostream& fout,
+    std::vector<std::string> const& configs,
+  const std::string& libName, cmGeneratorTarget *target
   )
 {
   fout << "\t<Configurations>\n";
@@ -642,7 +644,7 @@ private:
 void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
                                                 const std::string& configName,
                                                 const std::string& libName,
-                                                cmTarget &target)
+                                                cmGeneratorTarget *target)
 {
   const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
   if(!mfcFlag)
@@ -663,27 +665,24 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
   const char* projectType = 0;
   bool targetBuilds = true;
 
-  cmGeneratorTarget* gt =
-    this->GlobalGenerator->GetGeneratorTarget(&target);
-
-  switch(target.GetType())
+  switch(target->GetType())
     {
-    case cmTarget::OBJECT_LIBRARY:
+    case cmState::OBJECT_LIBRARY:
       targetBuilds = false; // no manifest tool for object library
-    case cmTarget::STATIC_LIBRARY:
+    case cmState::STATIC_LIBRARY:
       projectType = "typeStaticLibrary";
       configType = "4";
       break;
-    case cmTarget::SHARED_LIBRARY:
-    case cmTarget::MODULE_LIBRARY:
+    case cmState::SHARED_LIBRARY:
+    case cmState::MODULE_LIBRARY:
       projectType = "typeDynamicLibrary";
       configType = "2";
       break;
-    case cmTarget::EXECUTABLE:
+    case cmState::EXECUTABLE:
       configType = "1";
       break;
-    case cmTarget::UTILITY:
-    case cmTarget::GLOBAL_TARGET:
+    case cmState::UTILITY:
+    case cmState::GLOBAL_TARGET:
       configType = "10";
     default:
       targetBuilds = false;
@@ -698,12 +697,12 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
     {
     const std::string& linkLanguage = (this->FortranProject?
                                        std::string("Fortran"):
-                                gt->GetLinkerLanguage(configName));
+                                target->GetLinkerLanguage(configName));
     if(linkLanguage.empty())
       {
       cmSystemTools::Error
         ("CMake can not determine linker language for target: ",
-         target.GetName().c_str());
+         target->GetName().c_str());
       return;
       }
     if(linkLanguage == "C" || linkLanguage == "CXX"
@@ -729,12 +728,12 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
       }
 
     // Add the target-specific flags.
-    this->AddCompileOptions(flags, &target, linkLanguage, configName);
+    this->AddCompileOptions(flags, target, linkLanguage, configName);
     }
 
   if(this->FortranProject)
     {
-    switch(this->GetFortranFormat(target.GetProperty("Fortran_FORMAT")))
+    switch(this->GetFortranFormat(target->GetProperty("Fortran_FORMAT")))
       {
       case FortranFormatFixed: flags += " -fixed"; break;
       case FortranFormatFree: flags += " -free"; break;
@@ -761,7 +760,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
   targetOptions.Parse(defineFlags.c_str());
   targetOptions.ParseFinish();
   std::vector<std::string> targetDefines;
-  gt->GetCompileDefinitions(targetDefines, configName, "CXX");
+  target->GetCompileDefinitions(targetDefines, configName, "CXX");
   targetOptions.AddDefines(targetDefines);
   targetOptions.SetVerboseMakefile(
     this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
@@ -773,7 +772,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
   targetOptions.AddDefine(configDefine);
 
   // Add the export symbol definition for shared library objects.
-  if(const char* exportMacro = target.GetExportMacro())
+  if(const char* exportMacro = target->GetExportMacro())
     {
     targetOptions.AddDefine(exportMacro);
     }
@@ -784,11 +783,11 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
   intermediateDir += "/";
   intermediateDir += configName;
 
-  if (target.GetType() < cmTarget::UTILITY)
+  if (target->GetType() < cmState::UTILITY)
     {
     std::string const& outDir =
-      target.GetType() == cmTarget::OBJECT_LIBRARY?
-      intermediateDir : target.GetDirectory(configName);
+      target->GetType() == cmState::OBJECT_LIBRARY?
+      intermediateDir : target->GetDirectory(configName);
     fout << "\t\t\tOutputDirectory=\""
          << this->ConvertToXMLOutputPathSingle(outDir.c_str()) << "\"\n";
     }
@@ -803,7 +802,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
   if (this->FortranProject)
     {
     // Intel Fortran >= 15.0 uses TargetName property.
-    std::string targetNameFull = gt->GetFullName(configName);
+    std::string targetNameFull = target->GetFullName(configName);
     std::string targetName =
       cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
     std::string targetExt =
@@ -838,7 +837,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
   if(this->FortranProject)
     {
     const char* target_mod_dir =
-      target.GetProperty("Fortran_MODULE_DIRECTORY");
+      target->GetProperty("Fortran_MODULE_DIRECTORY");
     std::string modDir;
     if(target_mod_dir)
       {
@@ -857,7 +856,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
   targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
   fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
   std::vector<std::string> includes;
-  this->GetIncludeDirectories(includes, gt, "C", configName);
+  this->GetIncludeDirectories(includes, target, "C", configName);
   std::vector<std::string>::iterator i = includes.begin();
   for(;i != includes.end(); ++i)
     {
@@ -878,10 +877,10 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
   targetOptions.OutputFlagMap(fout, "\t\t\t\t");
   targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", "CXX");
   fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
-  if(target.GetType() <= cmTarget::OBJECT_LIBRARY)
+  if(target->GetType() <= cmState::OBJECT_LIBRARY)
     {
     // Specify the compiler program database file if configured.
-    std::string pdb = gt->GetCompilePDBPath(configName);
+    std::string pdb = target->GetCompilePDBPath(configName);
     if(!pdb.empty())
       {
       fout <<  "\t\t\t\tProgramDataBaseFileName=\""
@@ -985,7 +984,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
       "\t\t\t\tName=\"" << manifestTool << "\"";
 
     std::vector<cmSourceFile const*> manifest_srcs;
-    gt->GetManifests(manifest_srcs, configName);
+    target->GetManifests(manifest_srcs, configName);
     if (!manifest_srcs.empty())
       {
       fout << "\n\t\t\t\tAdditionalManifestFiles=\"";
@@ -1000,7 +999,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
 
     // Check if we need the FAT32 workaround.
     // Check the filesystem type where the target will be written.
-    if (cmLVS6G_IsFAT(target.GetDirectory(configName).c_str()))
+    if (cmLVS6G_IsFAT(target->GetDirectory(configName).c_str()))
       {
       // Add a flag telling the manifest tool to use a workaround
       // for FAT32 file systems, which can cause an empty manifest
@@ -1034,28 +1033,28 @@ cmLocalVisualStudio7Generator
 }
 
 void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
-  const std::string& configName, cmTarget &target,
+  const std::string& configName, cmGeneratorTarget* target,
   const Options& targetOptions)
 {
   cmGlobalVisualStudio7Generator* gg =
     static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
   std::string temp;
   std::string extraLinkOptions;
-  if(target.GetType() == cmTarget::EXECUTABLE)
+  if(target->GetType() == cmState::EXECUTABLE)
     {
     extraLinkOptions =
       this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
       + std::string(" ")
       + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
     }
-  if(target.GetType() == cmTarget::SHARED_LIBRARY)
+  if(target->GetType() == cmState::SHARED_LIBRARY)
     {
     extraLinkOptions =
       this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
       + std::string(" ")
       + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
     }
-  if(target.GetType() == cmTarget::MODULE_LIBRARY)
+  if(target->GetType() == cmState::MODULE_LIBRARY)
     {
     extraLinkOptions =
       this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
@@ -1063,7 +1062,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
       + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
     }
 
-  const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
+  const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
   if(targetLinkFlags)
     {
     extraLinkOptions += " ";
@@ -1072,7 +1071,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
   std::string configTypeUpper = cmSystemTools::UpperCase(configName);
   std::string linkFlagsConfig = "LINK_FLAGS_";
   linkFlagsConfig += configTypeUpper;
-  targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
+  targetLinkFlags = target->GetProperty(linkFlagsConfig.c_str());
   if(targetLinkFlags)
     {
     extraLinkOptions += " ";
@@ -1092,28 +1091,26 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
       this->ConvertToOutputFormat(this->ModuleDefinitionFile, SHELL);
     linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
     }
-  cmGeneratorTarget* gt =
-    this->GlobalGenerator->GetGeneratorTarget(&target);
 
-  if (target.GetType() == cmTarget::SHARED_LIBRARY &&
+  if (target->GetType() == cmState::SHARED_LIBRARY &&
       this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS"))
     {
-    if (target.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
+    if (target->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
       {
       linkOptions.AddFlag("ModuleDefinitionFile", "$(IntDir)/exportall.def");
       }
     }
-  switch(target.GetType())
+  switch(target->GetType())
     {
-    case cmTarget::UNKNOWN_LIBRARY:
+    case cmState::UNKNOWN_LIBRARY:
       break;
-    case cmTarget::OBJECT_LIBRARY:
+    case cmState::OBJECT_LIBRARY:
       {
       std::string libpath = this->GetTargetDirectory(target);
       libpath += "/";
       libpath += configName;
       libpath += "/";
-      libpath += target.GetName();
+      libpath += target->GetName();
       libpath += ".lib";
       const char* tool =
         this->FortranProject? "VFLibrarianTool":"VCLibrarianTool";
@@ -1123,10 +1120,10 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
            << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
       break;
       }
-    case cmTarget::STATIC_LIBRARY:
+    case cmState::STATIC_LIBRARY:
     {
-    std::string targetNameFull = gt->GetFullName(configName);
-    std::string libpath = target.GetDirectory(configName);
+    std::string targetNameFull = target->GetFullName(configName);
+    std::string libpath = target->GetDirectory(configName);
     libpath += "/";
     libpath += targetNameFull;
     const char* tool = "VCLibrarianTool";
@@ -1141,14 +1138,14 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
         || this->FortranProject)
       {
       std::ostringstream libdeps;
-      this->Internal->OutputObjects(libdeps, &target);
+      this->Internal->OutputObjects(libdeps, target);
       if(!libdeps.str().empty())
         {
         fout << "\t\t\t\tAdditionalDependencies=\"" << libdeps.str() << "\"\n";
         }
       }
     std::string libflags;
-    this->GetStaticLibraryFlags(libflags, configTypeUpper, &target);
+    this->GetStaticLibraryFlags(libflags, configTypeUpper, target);
     if(!libflags.empty())
       {
       fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
@@ -1157,19 +1154,19 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
          << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
     break;
     }
-    case cmTarget::SHARED_LIBRARY:
-    case cmTarget::MODULE_LIBRARY:
+    case cmState::SHARED_LIBRARY:
+    case cmState::MODULE_LIBRARY:
     {
     std::string targetName;
     std::string targetNameSO;
     std::string targetNameFull;
     std::string targetNameImport;
     std::string targetNamePDB;
-    gt->GetLibraryNames(targetName, targetNameSO, targetNameFull,
+    target->GetLibraryNames(targetName, targetNameSO, targetNameFull,
                            targetNameImport, targetNamePDB, configName);
 
     // Compute the link library and directory information.
-    cmComputeLinkInformation* pcli = gt->GetLinkInformation(configName);
+    cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
     if(!pcli)
       {
       return;
@@ -1201,12 +1198,12 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
     if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS8
         || this->FortranProject)
       {
-      this->Internal->OutputObjects(fout, &target, " ");
+      this->Internal->OutputObjects(fout, target, " ");
       }
     fout << " ";
     this->Internal->OutputLibraries(fout, cli.GetItems());
     fout << "\"\n";
-    temp = target.GetDirectory(configName);
+    temp = target->GetDirectory(configName);
     temp += "/";
     temp += targetNameFull;
     fout << "\t\t\t\tOutputFile=\""
@@ -1216,7 +1213,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
     fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
     this->OutputLibraryDirectories(fout, cli.GetDirectories());
     fout << "\"\n";
-    temp = target.GetPDBDirectory(configName);
+    temp = target->GetPDBDirectory(configName);
     temp += "/";
     temp += targetNamePDB;
     fout << "\t\t\t\tProgramDatabaseFile=\"" <<
@@ -1244,7 +1241,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
       {
       fout << "\t\t\t\tStackReserveSize=\"" << stackVal  << "\"\n";
       }
-    temp = target.GetDirectory(configName, true);
+    temp = target->GetDirectory(configName, true);
     temp += "/";
     temp += targetNameImport;
     fout << "\t\t\t\tImportLibrary=\""
@@ -1256,17 +1253,17 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
     fout << "/>\n";
     }
     break;
-    case cmTarget::EXECUTABLE:
+    case cmState::EXECUTABLE:
     {
     std::string targetName;
     std::string targetNameFull;
     std::string targetNameImport;
     std::string targetNamePDB;
-    gt->GetExecutableNames(targetName, targetNameFull,
+    target->GetExecutableNames(targetName, targetNameFull,
                               targetNameImport, targetNamePDB, configName);
 
     // Compute the link library and directory information.
-    cmComputeLinkInformation* pcli = gt->GetLinkInformation(configName);
+    cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
     if(!pcli)
       {
       return;
@@ -1274,7 +1271,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
     cmComputeLinkInformation& cli = *pcli;
     std::string linkLanguage = cli.GetLinkLanguage();
 
-    bool isWin32Executable = target.GetPropertyAsBool("WIN32_EXECUTABLE");
+    bool isWin32Executable = target->GetPropertyAsBool("WIN32_EXECUTABLE");
 
     // Compute the variable name to lookup standard libraries for this
     // language.
@@ -1300,12 +1297,12 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
     if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS8
         || this->FortranProject)
       {
-      this->Internal->OutputObjects(fout, &target, " ");
+      this->Internal->OutputObjects(fout, target, " ");
       }
     fout << " ";
     this->Internal->OutputLibraries(fout, cli.GetItems());
     fout << "\"\n";
-    temp = target.GetDirectory(configName);
+    temp = target->GetDirectory(configName);
     temp += "/";
     temp += targetNameFull;
     fout << "\t\t\t\tOutputFile=\""
@@ -1316,7 +1313,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
     this->OutputLibraryDirectories(fout, cli.GetDirectories());
     fout << "\"\n";
     std::string path = this->ConvertToXMLOutputPathSingle(
-      target.GetPDBDirectory(configName).c_str());
+      target->GetPDBDirectory(configName).c_str());
     fout << "\t\t\t\tProgramDatabaseFile=\""
          << path << "/" << targetNamePDB
          << "\"\n";
@@ -1363,16 +1360,16 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
       {
       fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
       }
-    temp = target.GetDirectory(configName, true);
+    temp = target->GetDirectory(configName, true);
     temp += "/";
     temp += targetNameImport;
     fout << "\t\t\t\tImportLibrary=\""
          << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
     break;
     }
-    case cmTarget::UTILITY:
-    case cmTarget::GLOBAL_TARGET:
-    case cmTarget::INTERFACE_LIBRARY:
+    case cmState::UTILITY:
+    case cmState::GLOBAL_TARGET:
+    case cmState::INTERFACE_LIBRARY:
       break;
     }
 }
@@ -1380,11 +1377,11 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
 //----------------------------------------------------------------------------
 void
 cmLocalVisualStudio7Generator
-::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
+::WriteTargetVersionAttribute(std::ostream& fout, cmGeneratorTarget* gt)
 {
   int major;
   int minor;
-  target.GetTargetVersion(major, minor);
+  gt->GetTargetVersion(major, minor);
   fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
 }
 
@@ -1404,7 +1401,7 @@ cmLocalVisualStudio7GeneratorInternals
       fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
       }
     else if (!l->Target
-        || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
+        || l->Target->GetType() != cmState::INTERFACE_LIBRARY)
       {
       fout << l->Value << " ";
       }
@@ -1414,13 +1411,11 @@ cmLocalVisualStudio7GeneratorInternals
 //----------------------------------------------------------------------------
 void
 cmLocalVisualStudio7GeneratorInternals
-::OutputObjects(std::ostream& fout, cmTarget* t, const char* isep)
+::OutputObjects(std::ostream& fout, cmGeneratorTarget* gt, const char* isep)
 {
   // VS < 8 does not support per-config source locations so we
   // list object library content on the link line instead.
   cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
-  cmGeneratorTarget* gt =
-    lg->GetGlobalGenerator()->GetGeneratorTarget(t);
   std::vector<std::string> objs;
   gt->UseObjectLibraries(objs, "");
   const char* sep = isep? isep : "";
@@ -1477,7 +1472,7 @@ cmLocalVisualStudio7Generator
 
 void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
                                                     const std::string& libName,
-                                                    cmTarget &target)
+                                                    cmGeneratorTarget* target)
 {
   std::vector<std::string> configs;
   this->Makefile->GetConfigurations(configs);
@@ -1485,13 +1480,10 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
   // We may be modifying the source groups temporarily, so make a copy.
   std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
 
-  cmGeneratorTarget* gt =
-    this->GlobalGenerator->GetGeneratorTarget(&target);
-
   // get the classes from the source lists then add them to the groups
   this->ModuleDefinitionFile = "";
   std::vector<cmSourceFile*> classes;
-  if (!gt->GetConfigCommonSourceFiles(classes))
+  if (!target->GetConfigCommonSourceFiles(classes))
     {
     return;
     }
@@ -1534,7 +1526,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
     // VS >= 8 support per-config source locations so we
     // list object library content as external objects.
     std::vector<std::string> objs;
-    gt->UseObjectLibraries(objs, "");
+    target->UseObjectLibraries(objs, "");
     if(!objs.empty())
       {
       // TODO: Separate sub-filter for each object library used?
@@ -1569,7 +1561,7 @@ class cmLocalVisualStudio7GeneratorFCInfo
 {
 public:
   cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
-                                      cmTarget& target,
+                                      cmGeneratorTarget* target,
                                       cmSourceFile const& sf,
                                       std::vector<std::string> const& configs);
   std::map<std::string, cmLVS7GFileConfig> FileConfigMap;
@@ -1577,12 +1569,10 @@ public:
 
 cmLocalVisualStudio7GeneratorFCInfo
 ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
-                                      cmTarget& target,
+                                      cmGeneratorTarget* gt,
                                       cmSourceFile const& sf,
                                       std::vector<std::string> const& configs)
 {
-  cmGeneratorTarget* gt =
-    lg->GetGlobalGenerator()->GetGeneratorTarget(&target);
   std::string objectName;
   if(gt->HasExplicitObjectName(&sf))
     {
@@ -1699,10 +1689,10 @@ cmLocalVisualStudio7GeneratorFCInfo
 //----------------------------------------------------------------------------
 std::string
 cmLocalVisualStudio7Generator
-::ComputeLongestObjectDirectory(cmTarget& target) const
+::ComputeLongestObjectDirectory(cmGeneratorTarget const* target) const
 {
   std::vector<std::string> configs;
-  target.GetMakefile()->GetConfigurations(configs);
+  target->Target->GetMakefile()->GetConfigurations(configs);
 
   // Compute the maximum length configuration name.
   std::string config_max;
@@ -1719,7 +1709,7 @@ cmLocalVisualStudio7Generator
   // files directory for any configuration.  This is used to construct
   // object file names that do not produce paths that are too long.
   std::string dir_max;
-  dir_max += this->Makefile->GetCurrentBinaryDirectory();
+  dir_max += this->GetCurrentBinaryDirectory();
   dir_max += "/";
   dir_max += this->GetTargetDirectory(target);
   dir_max += "/";
@@ -1729,7 +1719,7 @@ cmLocalVisualStudio7Generator
 }
 
 bool cmLocalVisualStudio7Generator
-::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
+::WriteGroup(const cmSourceGroup *sg, cmGeneratorTarget* target,
              std::ostream &fout, const std::string& libName,
              std::vector<std::string> const& configs)
 {
@@ -1764,15 +1754,14 @@ bool cmLocalVisualStudio7Generator
     }
 
   // Loop through each source in the source group.
-  std::string objectName;
   for(std::vector<const cmSourceFile *>::const_iterator sf =
         sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
     {
     std::string source = (*sf)->GetFullPath();
     FCInfo fcinfo(this, target, *(*sf), configs);
 
-    if (source != libName || target.GetType() == cmTarget::UTILITY ||
-      target.GetType() == cmTarget::GLOBAL_TARGET )
+    if (source != libName || target->GetType() == cmState::UTILITY ||
+      target->GetType() == cmState::GLOBAL_TARGET )
       {
       fout << "\t\t\t<File\n";
       std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
@@ -2019,10 +2008,10 @@ void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
 void cmLocalVisualStudio7Generator
 ::OutputTargetRules(std::ostream& fout,
                     const std::string& configName,
-                    cmTarget &target,
+                    cmGeneratorTarget *target,
                     const std::string& /*libName*/)
 {
-  if (target.GetType() > cmTarget::GLOBAL_TARGET)
+  if (target->GetType() > cmState::GLOBAL_TARGET)
     {
     return;
     }
@@ -2032,36 +2021,35 @@ void cmLocalVisualStudio7Generator
   const char* tool =
     this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool";
   event.Start(tool);
-  event.Write(target.GetPreBuildCommands());
+  event.Write(target->GetPreBuildCommands());
   event.Finish();
 
   // Add pre-link event.
   tool = this->FortranProject? "VFPreLinkEventTool":"VCPreLinkEventTool";
   event.Start(tool);
   bool addedPrelink = false;
-  if (target.GetType() == cmTarget::SHARED_LIBRARY &&
+  if (target->GetType() == cmState::SHARED_LIBRARY &&
       this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS"))
     {
-    if (target.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
+    if (target->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
       {
       addedPrelink = true;
       std::vector<cmCustomCommand> commands =
-        target.GetPreLinkCommands();
+        target->GetPreLinkCommands();
       cmGlobalVisualStudioGenerator* gg
         = static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
-      cmGeneratorTarget* gt =
-        this->GlobalGenerator->GetGeneratorTarget(&target);
       gg->AddSymbolExportCommand(
-        gt, commands, configName);
+        target, commands, configName);
       event.Write(commands);
       }
     }
   if (!addedPrelink)
     {
-    event.Write(target.GetPreLinkCommands());
+    event.Write(target->GetPreLinkCommands());
     }
   cmsys::auto_ptr<cmCustomCommand> pcc(
-    this->MaybeCreateImplibDir(target, configName, this->FortranProject));
+    this->MaybeCreateImplibDir(target,
+                               configName, this->FortranProject));
   if(pcc.get())
     {
     event.Write(*pcc);
@@ -2071,18 +2059,18 @@ void cmLocalVisualStudio7Generator
   // Add post-build event.
   tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool";
   event.Start(tool);
-  event.Write(target.GetPostBuildCommands());
+  event.Write(target->GetPostBuildCommands());
   event.Finish();
 }
 
 void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
-                                                    cmTarget& target)
+                                                    cmGeneratorTarget* target)
 {
   // if we have all the required Source code control tags
   // then add that to the project
-  const char* vsProjectname = target.GetProperty("VS_SCC_PROJECTNAME");
-  const char* vsLocalpath = target.GetProperty("VS_SCC_LOCALPATH");
-  const char* vsProvider = target.GetProperty("VS_SCC_PROVIDER");
+  const char* vsProjectname = target->GetProperty("VS_SCC_PROJECTNAME");
+  const char* vsLocalpath = target->GetProperty("VS_SCC_LOCALPATH");
+  const char* vsProvider = target->GetProperty("VS_SCC_PROVIDER");
 
   if(vsProvider && vsLocalpath && vsProjectname)
     {
@@ -2090,7 +2078,7 @@ void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
          << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
          << "\tSccProvider=\"" << vsProvider << "\"\n";
 
-    const char* vsAuxPath = target.GetProperty("VS_SCC_AUXPATH");
+    const char* vsAuxPath = target->GetProperty("VS_SCC_AUXPATH");
     if(vsAuxPath)
       {
       fout << "\tSccAuxPath=\"" << vsAuxPath << "\"\n";
@@ -2102,7 +2090,7 @@ void
 cmLocalVisualStudio7Generator
 ::WriteProjectStartFortran(std::ostream& fout,
                            const std::string& libName,
-                           cmTarget & target)
+                           cmGeneratorTarget *target)
 {
 
   cmGlobalVisualStudio7Generator* gg =
@@ -2112,38 +2100,38 @@ cmLocalVisualStudio7Generator
        << "<VisualStudioProject\n"
        << "\tProjectCreator=\"Intel Fortran\"\n"
        << "\tVersion=\"" << gg->GetIntelProjectVersion() << "\"\n";
-  const char* keyword = target.GetProperty("VS_KEYWORD");
+  const char* keyword = target->GetProperty("VS_KEYWORD");
   if(!keyword)
     {
     keyword = "Console Application";
     }
   const char* projectType = 0;
-  switch(target.GetType())
+  switch(target->GetType())
     {
-    case cmTarget::STATIC_LIBRARY:
+    case cmState::STATIC_LIBRARY:
       projectType = "typeStaticLibrary";
       if(keyword)
         {
         keyword = "Static Library";
         }
       break;
-    case cmTarget::SHARED_LIBRARY:
-    case cmTarget::MODULE_LIBRARY:
+    case cmState::SHARED_LIBRARY:
+    case cmState::MODULE_LIBRARY:
       projectType = "typeDynamicLibrary";
       if(!keyword)
         {
         keyword = "Dll";
         }
       break;
-    case cmTarget::EXECUTABLE:
+    case cmState::EXECUTABLE:
       if(!keyword)
         {
         keyword = "Console Application";
         }
       projectType = 0;
       break;
-    case cmTarget::UTILITY:
-    case cmTarget::GLOBAL_TARGET:
+    case cmState::UTILITY:
+    case cmState::GLOBAL_TARGET:
     default:
       break;
     }
@@ -2163,7 +2151,7 @@ cmLocalVisualStudio7Generator
 void
 cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
                                                  const std::string& libName,
-                                                 cmTarget & target,
+                                                 cmGeneratorTarget *target,
                                                  std::vector<cmSourceGroup> &)
 {
   if(this->FortranProject)
@@ -2187,12 +2175,12 @@ cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
     {
     fout <<  "\tVersion=\"" << (gg->GetVersion()/10) << ".00\"\n";
     }
-  const char* projLabel = target.GetProperty("PROJECT_LABEL");
+  const char* projLabel = target->GetProperty("PROJECT_LABEL");
   if(!projLabel)
     {
     projLabel = libName.c_str();
     }
-  const char* keyword = target.GetProperty("VS_KEYWORD");
+  const char* keyword = target->GetProperty("VS_KEYWORD");
   if(!keyword)
     {
     keyword = "Win32Proj";
@@ -2204,7 +2192,7 @@ cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
     }
   this->WriteProjectSCC(fout, target);
   if(const char* targetFrameworkVersion =
-     target.GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
+     target->GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
     {
     fout << "\tTargetFrameworkVersion=\"" << targetFrameworkVersion << "\"\n";
     }
@@ -2225,22 +2213,24 @@ cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
 }
 
 
-void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout,
-                                                      cmTarget &target)
+void cmLocalVisualStudio7Generator::WriteVCProjFooter(
+    std::ostream& fout,
+    cmGeneratorTarget *target)
 {
   fout << "\t<Globals>\n";
 
-  cmPropertyMap const& props = target.GetProperties();
-  for(cmPropertyMap::const_iterator i = props.begin(); i != props.end(); ++i)
+  std::vector<std::string> const& props = target->GetPropertyKeys();
+  for(std::vector<std::string>::const_iterator i = props.begin();
+      i != props.end(); ++i)
     {
-    if(i->first.find("VS_GLOBAL_") == 0)
+    if(i->find("VS_GLOBAL_") == 0)
       {
-      std::string name = i->first.substr(10);
+      std::string name = i->substr(10);
       if(name != "")
         {
         fout << "\t\t<Global\n"
              << "\t\t\tName=\"" << name << "\"\n"
-             << "\t\t\tValue=\"" << i->second.GetValue() << "\"\n"
+             << "\t\t\tValue=\"" << target->GetProperty(*i) << "\"\n"
              << "\t\t/>\n";
         }
       }
@@ -2365,10 +2355,10 @@ void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
 
 //----------------------------------------------------------------------------
 std::string cmLocalVisualStudio7Generator
-::GetTargetDirectory(cmTarget const& target) const
+::GetTargetDirectory(cmGeneratorTarget const* target) const
 {
   std::string dir;
-  dir += target.GetName();
+  dir += target->GetName();
   dir += ".dir";
   return dir;
 }
diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h
index bc05a06..7bb9cc6 100644
--- a/Source/cmLocalVisualStudio7Generator.h
+++ b/Source/cmLocalVisualStudio7Generator.h
@@ -15,7 +15,6 @@
 #include "cmLocalVisualStudioGenerator.h"
 #include "cmVisualStudioGeneratorOptions.h"
 
-class cmTarget;
 class cmSourceFile;
 class cmCustomCommand;
 class cmSourceGroup;
@@ -53,16 +52,19 @@ public:
    */
   void SetBuildType(BuildType,const std::string& name);
 
-  virtual std::string GetTargetDirectory(cmTarget const&) const;
+  virtual
+  std::string GetTargetDirectory(cmGeneratorTarget const* target) const;
   cmSourceFile* CreateVCProjBuildRule();
   void WriteStampFiles();
-  virtual std::string ComputeLongestObjectDirectory(cmTarget&) const;
+  virtual std::string
+  ComputeLongestObjectDirectory(cmGeneratorTarget const*) const;
 
   virtual void ReadAndStoreExternalGUID(const std::string& name,
                                         const char* path);
   virtual void AddCMakeListsRules();
 protected:
-  void CreateSingleVCProj(const std::string& lname, cmTarget &tgt);
+  void CreateSingleVCProj(const std::string& lname,
+                          cmGeneratorTarget *tgt);
 private:
   typedef cmVisualStudioGeneratorOptions Options;
   typedef cmLocalVisualStudio7GeneratorFCInfo FCInfo;
@@ -71,30 +73,33 @@ private:
   void FixGlobalTargets();
   void WriteProjectFiles();
   void WriteVCProjHeader(std::ostream& fout, const std::string& libName,
-                         cmTarget &tgt, std::vector<cmSourceGroup> &sgs);
-  void WriteVCProjFooter(std::ostream& fout, cmTarget &target);
+                         cmGeneratorTarget* tgt,
+                         std::vector<cmSourceGroup> &sgs);
+  void WriteVCProjFooter(std::ostream& fout, cmGeneratorTarget* target);
   void WriteVCProjFile(std::ostream& fout, const std::string& libName,
-                       cmTarget &tgt);
+                       cmGeneratorTarget* tgt);
   void WriteConfigurations(std::ostream& fout,
                            std::vector<std::string> const& configs,
-                           const std::string& libName, cmTarget &tgt);
+                           const std::string& libName, cmGeneratorTarget* tgt);
   void WriteConfiguration(std::ostream& fout,
                           const std::string& configName,
-                          const std::string& libName, cmTarget &tgt);
+                          const std::string& libName, cmGeneratorTarget* tgt);
   std::string EscapeForXML(const std::string& s);
   std::string ConvertToXMLOutputPath(const char* path);
   std::string ConvertToXMLOutputPathSingle(const char* path);
   void OutputTargetRules(std::ostream& fout, const std::string& configName,
-                         cmTarget &target, const std::string& libName);
+                         cmGeneratorTarget* target,
+                         const std::string& libName);
   void OutputBuildTool(std::ostream& fout, const std::string& configName,
-                       cmTarget& t, const Options& targetOptions);
+                       cmGeneratorTarget* t, const Options& targetOptions);
   void OutputLibraryDirectories(std::ostream& fout,
                                 std::vector<std::string> const& dirs);
-  void WriteProjectSCC(std::ostream& fout, cmTarget& target);
+  void WriteProjectSCC(std::ostream& fout, cmGeneratorTarget *target);
   void WriteProjectStart(std::ostream& fout, const std::string& libName,
-                         cmTarget &tgt, std::vector<cmSourceGroup> &sgs);
+                         cmGeneratorTarget* tgt,
+                         std::vector<cmSourceGroup> &sgs);
   void WriteProjectStartFortran(std::ostream& fout, const std::string& libName,
-                                cmTarget &tgt);
+                                cmGeneratorTarget* tgt);
   void WriteVCProjBeginGroup(std::ostream& fout,
                           const char* group,
                           const char* filter);
@@ -105,10 +110,11 @@ private:
                        const char* source,
                        const cmCustomCommand& command,
                        FCInfo& fcinfo);
-  void WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target);
+  void WriteTargetVersionAttribute(std::ostream& fout,
+                                   cmGeneratorTarget* gt);
 
   bool WriteGroup(const cmSourceGroup *sg,
-                  cmTarget& target, std::ostream &fout,
+                  cmGeneratorTarget* target, std::ostream &fout,
                   const std::string& libName,
                   std::vector<std::string> const& configs);
 
diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx
index c0072de..561f9a1 100644
--- a/Source/cmLocalVisualStudioGenerator.cxx
+++ b/Source/cmLocalVisualStudioGenerator.cxx
@@ -43,7 +43,7 @@ void cmLocalVisualStudioGenerator::ComputeObjectFilenames(
                         std::map<cmSourceFile const*, std::string>& mapping,
                         cmGeneratorTarget const* gt)
 {
-  std::string dir_max = this->ComputeLongestObjectDirectory(*gt->Target);
+  std::string dir_max = this->ComputeLongestObjectDirectory(gt);
 
   // Count the number of object files with each name.  Note that
   // windows file names are not case sensitive.
@@ -80,7 +80,7 @@ void cmLocalVisualStudioGenerator::ComputeObjectFilenames(
 
 //----------------------------------------------------------------------------
 cmsys::auto_ptr<cmCustomCommand>
-cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmTarget& target,
+cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmGeneratorTarget* target,
                                                    const std::string& config,
                                                    bool isFortran)
 {
@@ -89,11 +89,11 @@ cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmTarget& target,
   // If an executable exports symbols then VS wants to create an
   // import library but forgets to create the output directory.
   // The Intel Fortran plugin always forgets to the directory.
-  if(target.GetType() != cmTarget::EXECUTABLE &&
-     !(isFortran && target.GetType() == cmTarget::SHARED_LIBRARY))
+  if(target->GetType() != cmState::EXECUTABLE &&
+     !(isFortran && target->GetType() == cmState::SHARED_LIBRARY))
     { return pcc; }
-  std::string outDir = target.GetDirectory(config, false);
-  std::string impDir = target.GetDirectory(config, true);
+  std::string outDir = target->GetDirectory(config, false);
+  std::string impDir = target->GetDirectory(config, true);
   if(impDir == outDir) { return pcc; }
 
   // Add a pre-build event to create the directory.
diff --git a/Source/cmLocalVisualStudioGenerator.h b/Source/cmLocalVisualStudioGenerator.h
index 071bfb3..f95eefa 100644
--- a/Source/cmLocalVisualStudioGenerator.h
+++ b/Source/cmLocalVisualStudioGenerator.h
@@ -44,7 +44,8 @@ public:
 
   cmGlobalVisualStudioGenerator::VSVersion GetVersion() const;
 
-  virtual std::string ComputeLongestObjectDirectory(cmTarget&) const = 0;
+  virtual std::string
+  ComputeLongestObjectDirectory(cmGeneratorTarget const*) const = 0;
 
   virtual void AddCMakeListsRules() = 0;
 
@@ -58,7 +59,8 @@ protected:
 
   /** Construct a custom command to make exe import lib dir.  */
   cmsys::auto_ptr<cmCustomCommand>
-  MaybeCreateImplibDir(cmTarget& target, const std::string& config,
+  MaybeCreateImplibDir(cmGeneratorTarget *target,
+                       const std::string& config,
                        bool isFortran);
 };
 
diff --git a/Source/cmLocalXCodeGenerator.cxx b/Source/cmLocalXCodeGenerator.cxx
index b19112d..aec2603 100644
--- a/Source/cmLocalXCodeGenerator.cxx
+++ b/Source/cmLocalXCodeGenerator.cxx
@@ -31,7 +31,7 @@ cmLocalXCodeGenerator::~cmLocalXCodeGenerator()
 
 //----------------------------------------------------------------------------
 std::string
-cmLocalXCodeGenerator::GetTargetDirectory(cmTarget const&) const
+cmLocalXCodeGenerator::GetTargetDirectory(cmGeneratorTarget const*) const
 {
   // No per-target directory for this generator (yet).
   return "";
@@ -51,12 +51,11 @@ void cmLocalXCodeGenerator::Generate()
 {
   cmLocalGenerator::Generate();
 
-  cmTargets& targets = this->Makefile->GetTargets();
-  for(cmTargets::iterator iter = targets.begin();
+  std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
+  for(std::vector<cmGeneratorTarget*>::iterator iter = targets.begin();
       iter != targets.end(); ++iter)
     {
-    cmTarget* t = &iter->second;
-    t->HasMacOSXRpathInstallNameDir("");
+    (*iter)->HasMacOSXRpathInstallNameDir("");
     }
 }
 
@@ -65,12 +64,11 @@ void cmLocalXCodeGenerator::GenerateInstallRules()
 {
   cmLocalGenerator::GenerateInstallRules();
 
-  cmTargets& targets = this->Makefile->GetTargets();
-  for(cmTargets::iterator iter = targets.begin();
+  std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
+  for(std::vector<cmGeneratorTarget*>::iterator iter = targets.begin();
       iter != targets.end(); ++iter)
     {
-    cmTarget* t = &iter->second;
-    t->HasMacOSXRpathInstallNameDir("");
+    (*iter)->HasMacOSXRpathInstallNameDir("");
     }
 }
 
diff --git a/Source/cmLocalXCodeGenerator.h b/Source/cmLocalXCodeGenerator.h
index 6d0926f..4381a6d 100644
--- a/Source/cmLocalXCodeGenerator.h
+++ b/Source/cmLocalXCodeGenerator.h
@@ -28,7 +28,8 @@ public:
                         cmMakefile* mf);
 
   virtual ~cmLocalXCodeGenerator();
-  virtual std::string GetTargetDirectory(cmTarget const& target) const;
+  virtual
+  std::string GetTargetDirectory(cmGeneratorTarget const* target) const;
   virtual void AppendFlagEscape(std::string& flags,
                                 const std::string& rawFlag);
   virtual void Generate();
diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx
index e4026b0..71de7a7 100644
--- a/Source/cmMacroCommand.cxx
+++ b/Source/cmMacroCommand.cxx
@@ -146,16 +146,14 @@ bool cmMacroHelperCommand::InvokeInitialPass
         // replace formal arguments
         for (unsigned int j = 0; j < variables.size(); ++j)
           {
-          cmSystemTools::ReplaceString(arg.Value, variables[j].c_str(),
-                                       expandedArgs[j].c_str());
+          cmSystemTools::ReplaceString(arg.Value, variables[j],
+                                       expandedArgs[j]);
           }
         // replace argc
-        cmSystemTools::ReplaceString(arg.Value, "${ARGC}",argcDef.c_str());
+        cmSystemTools::ReplaceString(arg.Value, "${ARGC}", argcDef);
 
-        cmSystemTools::ReplaceString(arg.Value, "${ARGN}",
-                                     expandedArgn.c_str());
-        cmSystemTools::ReplaceString(arg.Value, "${ARGV}",
-                                     expandedArgv.c_str());
+        cmSystemTools::ReplaceString(arg.Value, "${ARGN}", expandedArgn);
+        cmSystemTools::ReplaceString(arg.Value, "${ARGV}", expandedArgv);
 
         // if the current argument of the current function has ${ARGV in it
         // then try replacing ARGV values
@@ -163,8 +161,8 @@ bool cmMacroHelperCommand::InvokeInitialPass
           {
           for (unsigned int t = 0; t < expandedArgs.size(); ++t)
             {
-            cmSystemTools::ReplaceString(arg.Value, argVs[t].c_str(),
-                                         expandedArgs[t].c_str());
+            cmSystemTools::ReplaceString(arg.Value, argVs[t],
+                                         expandedArgs[t]);
             }
           }
         }
diff --git a/Source/cmMakeDepend.cxx b/Source/cmMakeDepend.cxx
deleted file mode 100644
index cbc7e02..0000000
--- a/Source/cmMakeDepend.cxx
+++ /dev/null
@@ -1,361 +0,0 @@
-/*============================================================================
-  CMake - Cross Platform Makefile Generator
-  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
-
-  Distributed under the OSI-approved BSD License (the "License");
-  see accompanying file Copyright.txt for details.
-
-  This software is distributed WITHOUT ANY WARRANTY; without even the
-  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-  See the License for more information.
-============================================================================*/
-#include "cmMakeDepend.h"
-#include "cmSystemTools.h"
-#include "cmGeneratorExpression.h"
-#include "cmAlgorithms.h"
-
-#include <cmsys/RegularExpression.hxx>
-#include <cmsys/FStream.hxx>
-
-void cmDependInformation::AddDependencies(cmDependInformation* info)
-{
-  if(this != info)
-    {
-    this->DependencySet.insert(info);
-    }
-}
-
-cmMakeDepend::cmMakeDepend()
-{
-  this->Verbose = false;
-  this->IncludeFileRegularExpression.compile("^.*$");
-  this->ComplainFileRegularExpression.compile("^$");
-}
-
-
-cmMakeDepend::~cmMakeDepend()
-{
-  cmDeleteAll(this->DependInformationMap);
-}
-
-
-// Set the makefile that depends will be made from.
-// The pointer is kept so the cmSourceFile array can
-// be updated with the depend information in the cmMakefile.
-
-void cmMakeDepend::SetMakefile(cmMakefile* makefile)
-{
-  this->Makefile = makefile;
-
-  // Now extract the include file regular expression from the makefile.
-  this->IncludeFileRegularExpression.compile(
-    this->Makefile->GetIncludeRegularExpression());
-  this->ComplainFileRegularExpression.compile(
-    this->Makefile->ComplainFileRegularExpression.c_str());
-
-  // Now extract any include paths from the targets
-  std::set<std::string> uniqueIncludes;
-  std::vector<std::string> orderedAndUniqueIncludes;
-  cmTargets &targets = this->Makefile->GetTargets();
-  for (cmTargets::iterator l = targets.begin();
-       l != targets.end(); ++l)
-    {
-    const char *incDirProp = l->second.GetProperty("INCLUDE_DIRECTORIES");
-    if (!incDirProp)
-      {
-      continue;
-      }
-
-    std::string incDirs = cmGeneratorExpression::Preprocess(incDirProp,
-                      cmGeneratorExpression::StripAllGeneratorExpressions);
-
-    std::vector<std::string> includes;
-    cmSystemTools::ExpandListArgument(incDirs, includes);
-
-    for(std::vector<std::string>::const_iterator j = includes.begin();
-        j != includes.end(); ++j)
-      {
-      std::string path = *j;
-      this->Makefile->ExpandVariablesInString(path);
-      if(uniqueIncludes.insert(path).second)
-        {
-        orderedAndUniqueIncludes.push_back(path);
-        }
-      }
-    }
-
-  for(std::vector<std::string>::const_iterator
-    it = orderedAndUniqueIncludes.begin();
-    it != orderedAndUniqueIncludes.end();
-    ++it)
-    {
-    this->AddSearchPath(*it);
-    }
-}
-
-
-const cmDependInformation* cmMakeDepend::FindDependencies(const char* file)
-{
-  cmDependInformation* info = this->GetDependInformation(file,0);
-  this->GenerateDependInformation(info);
-  return info;
-}
-
-void cmMakeDepend::GenerateDependInformation(cmDependInformation* info)
-{
-  // If dependencies are already done, stop now.
-  if(info->DependDone)
-    {
-    return;
-    }
-  else
-    {
-    // Make sure we don't visit the same file more than once.
-    info->DependDone = true;
-    }
-  const char* path = info->FullPath.c_str();
-  if(!path)
-    {
-    cmSystemTools::Error(
-      "Attempt to find dependencies for file without path!");
-    return;
-    }
-
-  bool found = false;
-
-  // If the file exists, use it to find dependency information.
-  if(cmSystemTools::FileExists(path, true))
-    {
-    // Use the real file to find its dependencies.
-    this->DependWalk(info);
-    found = true;
-    }
-
-
-  // See if the cmSourceFile for it has any files specified as
-  // dependency hints.
-  if(info->SourceFile != 0)
-    {
-
-    // Get the cmSourceFile corresponding to this.
-    const cmSourceFile& cFile = *(info->SourceFile);
-    // See if there are any hints for finding dependencies for the missing
-    // file.
-    if(!cFile.GetDepends().empty())
-      {
-      // Dependency hints have been given.  Use them to begin the
-      // recursion.
-      for(std::vector<std::string>::const_iterator file =
-            cFile.GetDepends().begin(); file != cFile.GetDepends().end();
-          ++file)
-        {
-        this->AddDependency(info, file->c_str());
-        }
-
-      // Found dependency information.  We are done.
-      found = true;
-      }
-    }
-
-  if(!found)
-    {
-    // Try to find the file amongst the sources
-    cmSourceFile *srcFile = this->Makefile->GetSource
-      (cmSystemTools::GetFilenameWithoutExtension(path));
-    if (srcFile)
-      {
-      if (srcFile->GetFullPath() == path)
-        {
-        found=true;
-        }
-      else
-        {
-        //try to guess which include path to use
-        for(std::vector<std::string>::iterator t =
-              this->IncludeDirectories.begin();
-            t != this->IncludeDirectories.end(); ++t)
-          {
-          std::string incpath = *t;
-          if (!incpath.empty() && incpath[incpath.size() - 1] != '/')
-            {
-            incpath = incpath + "/";
-            }
-          incpath = incpath + path;
-          if (srcFile->GetFullPath() == incpath)
-            {
-            // set the path to the guessed path
-            info->FullPath = incpath;
-            found=true;
-            }
-          }
-        }
-      }
-    }
-
-  if(!found)
-    {
-    // Couldn't find any dependency information.
-    if(this->ComplainFileRegularExpression.find(info->IncludeName.c_str()))
-      {
-      cmSystemTools::Error("error cannot find dependencies for ", path);
-      }
-    else
-      {
-      // Destroy the name of the file so that it won't be output as a
-      // dependency.
-      info->FullPath = "";
-      }
-    }
-}
-
-// This function actually reads the file specified and scans it for
-// #include directives
-void cmMakeDepend::DependWalk(cmDependInformation* info)
-{
-  cmsys::RegularExpression includeLine
-    ("^[ \t]*#[ \t]*include[ \t]*[<\"]([^\">]+)[\">]");
-  cmsys::ifstream fin(info->FullPath.c_str());
-  if(!fin)
-    {
-    cmSystemTools::Error("Cannot open ", info->FullPath.c_str());
-    return;
-    }
-
-  // TODO: Write real read loop (see cmSystemTools::CopyFile).
-  std::string line;
-  while( cmSystemTools::GetLineFromStream(fin, line) )
-    {
-    if(includeLine.find(line.c_str()))
-      {
-      // extract the file being included
-      std::string includeFile = includeLine.match(1);
-      // see if the include matches the regular expression
-      if(!this->IncludeFileRegularExpression.find(includeFile))
-        {
-        if(this->Verbose)
-          {
-          std::string message = "Skipping ";
-          message += includeFile;
-          message += " for file ";
-          message += info->FullPath.c_str();
-          cmSystemTools::Error(message.c_str(), 0);
-          }
-        continue;
-        }
-
-      // Add this file and all its dependencies.
-      this->AddDependency(info, includeFile.c_str());
-      }
-    }
-}
-
-
-void cmMakeDepend::AddDependency(cmDependInformation* info, const char* file)
-{
-  cmDependInformation* dependInfo =
-    this->GetDependInformation(file, info->PathOnly.c_str());
-  this->GenerateDependInformation(dependInfo);
-  info->AddDependencies(dependInfo);
-}
-
-cmDependInformation* cmMakeDepend::GetDependInformation(const char* file,
-                                                        const char *extraPath)
-{
-  // Get the full path for the file so that lookup is unambiguous.
-  std::string fullPath = this->FullPath(file, extraPath);
-
-  // Try to find the file's instance of cmDependInformation.
-  DependInformationMapType::const_iterator result =
-    this->DependInformationMap.find(fullPath);
-  if(result != this->DependInformationMap.end())
-    {
-    // Found an instance, return it.
-    return result->second;
-    }
-  else
-    {
-    // Didn't find an instance.  Create a new one and save it.
-    cmDependInformation* info = new cmDependInformation;
-    info->FullPath = fullPath;
-    info->PathOnly = cmSystemTools::GetFilenamePath(fullPath);
-    info->IncludeName = file;
-    this->DependInformationMap[fullPath] = info;
-    return info;
-    }
-}
-
-
-// find the full path to fname by searching the this->IncludeDirectories array
-std::string cmMakeDepend::FullPath(const char* fname, const char *extraPath)
-{
-  DirectoryToFileToPathMapType::iterator m;
-  if(extraPath)
-    {
-    m = this->DirectoryToFileToPathMap.find(extraPath);
-    }
-  else
-    {
-    m = this->DirectoryToFileToPathMap.find("");
-    }
-
-  if(m != this->DirectoryToFileToPathMap.end())
-    {
-    FileToPathMapType& map = m->second;
-    FileToPathMapType::iterator p = map.find(fname);
-    if(p != map.end())
-      {
-      return p->second;
-      }
-    }
-
-  if(cmSystemTools::FileExists(fname, true))
-    {
-    std::string fp = cmSystemTools::CollapseFullPath(fname);
-    this->DirectoryToFileToPathMap[extraPath? extraPath: ""][fname] = fp;
-    return fp;
-    }
-
-  for(std::vector<std::string>::iterator i = this->IncludeDirectories.begin();
-      i != this->IncludeDirectories.end(); ++i)
-    {
-    std::string path = *i;
-    if (!path.empty() && path[path.size() - 1] != '/')
-      {
-      path = path + "/";
-      }
-    path = path + fname;
-    if(cmSystemTools::FileExists(path.c_str(), true)
-       && !cmSystemTools::FileIsDirectory(path))
-      {
-      std::string fp = cmSystemTools::CollapseFullPath(path);
-      this->DirectoryToFileToPathMap[extraPath? extraPath: ""][fname] = fp;
-      return fp;
-      }
-    }
-
-  if (extraPath)
-    {
-    std::string path = extraPath;
-    if (!path.empty() && path[path.size() - 1] != '/')
-      {
-      path = path + "/";
-      }
-    path = path + fname;
-    if(cmSystemTools::FileExists(path.c_str(), true)
-       && !cmSystemTools::FileIsDirectory(path))
-      {
-      std::string fp = cmSystemTools::CollapseFullPath(path);
-      this->DirectoryToFileToPathMap[extraPath][fname] = fp;
-      return fp;
-      }
-    }
-
-  // Couldn't find the file.
-  return std::string(fname);
-}
-
-// Add a directory to the search path
-void cmMakeDepend::AddSearchPath(const std::string& path)
-{
-  this->IncludeDirectories.push_back(path);
-}
diff --git a/Source/cmMakeDepend.h b/Source/cmMakeDepend.h
deleted file mode 100644
index 2c9d515..0000000
--- a/Source/cmMakeDepend.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/*============================================================================
-  CMake - Cross Platform Makefile Generator
-  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
-
-  Distributed under the OSI-approved BSD License (the "License");
-  see accompanying file Copyright.txt for details.
-
-  This software is distributed WITHOUT ANY WARRANTY; without even the
-  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-  See the License for more information.
-============================================================================*/
-#ifndef cmMakeDepend_h
-#define cmMakeDepend_h
-
-#include "cmMakefile.h"
-#include "cmSourceFile.h"
-
-#include <cmsys/RegularExpression.hxx>
-
-/** \class cmDependInformation
- * \brief Store dependency information for a single source file.
- *
- * This structure stores the depend information for a single source file.
- */
-class cmDependInformation
-{
-public:
-  /**
-   * Construct with dependency generation marked not done; instance
-   * not placed in cmMakefile's list.
-   */
-  cmDependInformation(): DependDone(false), SourceFile(0) {}
-
-  /**
-   * The set of files on which this one depends.
-   */
-  typedef std::set<cmDependInformation*> DependencySetType;
-  DependencySetType DependencySet;
-
-  /**
-   * This flag indicates whether dependency checking has been
-   * performed for this file.
-   */
-  bool DependDone;
-
-  /**
-   * If this object corresponds to a cmSourceFile instance, this points
-   * to it.
-   */
-  const cmSourceFile *SourceFile;
-
-  /**
-   * Full path to this file.
-   */
-  std::string FullPath;
-
-  /**
-   * Full path not including file name.
-   */
-  std::string PathOnly;
-
-  /**
-   * Name used to #include this file.
-   */
-  std::string IncludeName;
-
-  /**
-   * This method adds the dependencies of another file to this one.
-   */
-  void AddDependencies(cmDependInformation*);
-};
-
-
-// cmMakeDepend is used to generate dependancy information for
-// the classes in a makefile
-class cmMakeDepend
-{
-public:
-  /**
-   * Construct the object with verbose turned off.
-   */
-  cmMakeDepend();
-
-  /**
-   * Destructor.
-   */
-  virtual ~cmMakeDepend();
-
-  /**
-   * Set the makefile that is used as a source of classes.
-   */
-  virtual void SetMakefile(cmMakefile* makefile);
-
-  /**
-   * Add a directory to the search path for include files.
-   */
-  virtual void AddSearchPath(const std::string&);
-
-  /**
-   * Generate dependencies for the file given.  Returns a pointer to
-   * the cmDependInformation object for the file.
-   */
-  const cmDependInformation* FindDependencies(const char* file);
-
-protected:
-  /**
-   * Compute the depend information for this class.
-   */
-  virtual void DependWalk(cmDependInformation* info);
-
-  /**
-   * Add a dependency.  Possibly walk it for more dependencies.
-   */
-  virtual void AddDependency(cmDependInformation* info, const char* file);
-
-  /**
-   * Fill in the given object with dependency information.  If the
-   * information is already complete, nothing is done.
-   */
-  void GenerateDependInformation(cmDependInformation* info);
-
-  /**
-   * Get an instance of cmDependInformation corresponding to the given file
-   * name.
-   */
-  cmDependInformation* GetDependInformation(const char* file,
-                                            const char *extraPath);
-
-  /**
-   * Find the full path name for the given file name.
-   * This uses the include directories.
-   * TODO: Cache path conversions to reduce FileExists calls.
-   */
-  std::string FullPath(const char *filename, const char *extraPath);
-
-  cmMakefile* Makefile;
-  bool Verbose;
-  cmsys::RegularExpression IncludeFileRegularExpression;
-  cmsys::RegularExpression ComplainFileRegularExpression;
-  std::vector<std::string> IncludeDirectories;
-  typedef std::map<std::string, std::string> FileToPathMapType;
-  typedef std::map<std::string, FileToPathMapType>
-  DirectoryToFileToPathMapType;
-  typedef std::map<std::string, cmDependInformation*>
-  DependInformationMapType;
-  DependInformationMapType DependInformationMap;
-  DirectoryToFileToPathMapType DirectoryToFileToPathMap;
-};
-
-#endif
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 3c19f55..950b247 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -50,46 +50,16 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator,
 {
   this->IsSourceFileTryCompile = false;
 
-  // Initialize these first since AddDefaultDefinitions calls AddDefinition
   this->WarnUnused = this->GetCMakeInstance()->GetWarnUnused();
   this->CheckSystemVars = this->GetCMakeInstance()->GetCheckSystemVars();
 
   this->SuppressWatches = false;
 
-  // Setup the default include file regular expression (match everything).
-  this->SetProperty("INCLUDE_REGULAR_EXPRESSION", "^.*$");
   // Setup the default include complaint regular expression (match nothing).
   this->ComplainFileRegularExpression = "^$";
-  // Source and header file extensions that we can handle
-
-  // Set up a list of source and header extensions
-  // these are used to find files when the extension
-  // is not given
-  // The "c" extension MUST precede the "C" extension.
-  this->SourceFileExtensions.push_back( "c" );
-  this->SourceFileExtensions.push_back( "C" );
-
-  this->SourceFileExtensions.push_back( "c++" );
-  this->SourceFileExtensions.push_back( "cc" );
-  this->SourceFileExtensions.push_back( "cpp" );
-  this->SourceFileExtensions.push_back( "cxx" );
-  this->SourceFileExtensions.push_back( "m" );
-  this->SourceFileExtensions.push_back( "M" );
-  this->SourceFileExtensions.push_back( "mm" );
-
-  this->HeaderFileExtensions.push_back( "h" );
-  this->HeaderFileExtensions.push_back( "hh" );
-  this->HeaderFileExtensions.push_back( "h++" );
-  this->HeaderFileExtensions.push_back( "hm" );
-  this->HeaderFileExtensions.push_back( "hpp" );
-  this->HeaderFileExtensions.push_back( "hxx" );
-  this->HeaderFileExtensions.push_back( "in" );
-  this->HeaderFileExtensions.push_back( "txx" );
 
   this->DefineFlags = " ";
 
-  this->AddDefaultDefinitions();
-
   this->cmDefineRegex.compile("#cmakedefine[ \t]+([A-Za-z_0-9]*)");
   this->cmDefine01Regex.compile("#cmakedefine01[ \t]+([A-Za-z_0-9]*)");
   this->cmAtVarRegex.compile("(@[A-Za-z_0-9/.+-]+@)");
@@ -119,17 +89,6 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator,
   this->AddSourceGroup("Resources", "\\.plist$");
   this->AddSourceGroup("Object Files", "\\.(lo|o|obj)$");
 #endif
-
-  {
-  const char* dir = this->GetCMakeInstance()->GetHomeDirectory();
-  this->AddDefinition("CMAKE_SOURCE_DIR", dir);
-  this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR", dir);
-  }
-  {
-  const char* dir = this->GetCMakeInstance()->GetHomeOutputDirectory();
-  this->AddDefinition("CMAKE_BINARY_DIR", dir);
-  this->AddDefinition("CMAKE_CURRENT_BINARY_DIR", dir);
-  }
 }
 
 cmMakefile::~cmMakefile()
@@ -142,14 +101,12 @@ cmMakefile::~cmMakefile()
   cmDeleteAll(this->FinalPassCommands);
   cmDeleteAll(this->FunctionBlockers);
   cmDeleteAll(this->EvaluationFiles);
-  this->EvaluationFiles.clear();
-
-  this->FunctionBlockers.clear();
 }
 
 //----------------------------------------------------------------------------
 void cmMakefile::IssueMessage(cmake::MessageType t,
-                              std::string const& text) const
+                              std::string const& text,
+                              bool force) const
 {
   // Collect context information.
   if(!this->ExecutionStatusStack.empty())
@@ -158,7 +115,8 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
       {
       this->ExecutionStatusStack.back()->SetNestedError(true);
       }
-    this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace());
+    this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace(),
+                                           force);
     }
   else
     {
@@ -173,7 +131,7 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
       lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
       }
     lfc.Line = 0;
-    this->GetCMakeInstance()->IssueMessage(t, text, lfc);
+    this->GetCMakeInstance()->IssueMessage(t, text, lfc, force);
     }
 }
 
@@ -686,6 +644,29 @@ cmMakefile::GetEvaluationFiles() const
   return this->EvaluationFiles;
 }
 
+std::vector<cmExportBuildFileGenerator*>
+cmMakefile::GetExportBuildFileGenerators() const
+{
+  return this->ExportBuildFileGenerators;
+}
+
+void cmMakefile::RemoveExportBuildFileGeneratorCMP0024(
+    cmExportBuildFileGenerator* gen)
+{
+  std::vector<cmExportBuildFileGenerator*>::iterator it =
+      std::find(this->ExportBuildFileGenerators.begin(),
+                this->ExportBuildFileGenerators.end(), gen);
+  if(it != this->ExportBuildFileGenerators.end())
+    {
+    this->ExportBuildFileGenerators.erase(it);
+    }
+}
+
+void cmMakefile::AddExportBuildFileGenerator(cmExportBuildFileGenerator* gen)
+{
+  this->ExportBuildFileGenerators.push_back(gen);
+}
+
 namespace
 {
   struct file_not_persistent
@@ -752,15 +733,26 @@ void cmMakefile::ConfigureFinalPass()
       "with CMake 2.4 or later. For compatibility with older versions please "
       "use any CMake 2.8.x release or lower.");
     }
-  for (cmTargets::iterator l = this->Targets.begin();
-       l != this->Targets.end(); l++)
+#if defined(_WIN32) && !defined(__CYGWIN__)
+  // Do old-style link dependency analysis only for CM_USE_OLD_VS6.
+  if(this->GetGlobalGenerator()->IsForVS6())
     {
-    if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
+    for (cmTargets::iterator l = this->Targets.begin();
+         l != this->Targets.end(); l++)
       {
-      continue;
+      if (l->second.GetType() == cmState::INTERFACE_LIBRARY)
+        {
+        continue;
+        }
+      // Erase any cached link information that might have been comptued
+      // on-demand during the configuration.  This ensures that build
+      // system generation uses up-to-date information even if other cache
+      // invalidation code in this source file is buggy.
+
+      l->second.AnalyzeLibDependenciesForVS6(*this);
       }
-    l->second.FinishConfigure();
     }
+#endif
 }
 
 //----------------------------------------------------------------------------
@@ -799,14 +791,31 @@ cmMakefile::AddCustomCommandToTarget(const std::string& target,
 
     if(issueMessage)
       {
-      e << "The target name \"" << target << "\" is unknown in this context.";
+      if (cmTarget const* t = this->FindTargetToUse(target))
+        {
+        if (t->IsImported())
+          {
+          e << "TARGET '" << target
+            << "' is IMPORTED and does not build here.";
+          }
+        else
+          {
+          e << "TARGET '" << target
+            << "' was not created in this directory.";
+          }
+        }
+      else
+        {
+        e << "No TARGET '" << target
+          << "' has been created in this directory.";
+        }
       IssueMessage(messageType, e.str());
       }
 
       return;
     }
 
-  if(ti->second.GetType() == cmTarget::OBJECT_LIBRARY)
+  if(ti->second.GetType() == cmState::OBJECT_LIBRARY)
     {
     std::ostringstream e;
     e << "Target \"" << target << "\" is an OBJECT library "
@@ -814,7 +823,7 @@ cmMakefile::AddCustomCommandToTarget(const std::string& target,
     this->IssueMessage(cmake::FATAL_ERROR, e.str());
     return;
     }
-  if(ti->second.GetType() == cmTarget::INTERFACE_LIBRARY)
+  if(ti->second.GetType() == cmState::INTERFACE_LIBRARY)
     {
     std::ostringstream e;
     e << "Target \"" << target << "\" is an INTERFACE library "
@@ -1180,7 +1189,7 @@ cmMakefile::AddUtilityCommand(const std::string& utilityName,
                               bool uses_terminal)
 {
   // Create a target instance for this utility.
-  cmTarget* target = this->AddNewTarget(cmTarget::UTILITY, utilityName);
+  cmTarget* target = this->AddNewTarget(cmState::UTILITY, utilityName);
   if (excludeFromAll)
     {
     target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
@@ -1396,7 +1405,7 @@ bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove)
 }
 
 void cmMakefile::AddLinkLibrary(const std::string& lib,
-                                cmTarget::LinkLibraryType llt)
+                                cmTargetLinkLibraryType llt)
 {
   cmTarget::LibraryID tmp;
   tmp.first = lib;
@@ -1406,7 +1415,7 @@ void cmMakefile::AddLinkLibrary(const std::string& lib,
 
 void cmMakefile::AddLinkLibraryForTarget(const std::string& target,
                                          const std::string& lib,
-                                         cmTarget::LinkLibraryType llt)
+                                         cmTargetLinkLibraryType llt)
 {
   cmTargets::iterator i = this->Targets.find(target);
   if ( i != this->Targets.end())
@@ -1415,14 +1424,14 @@ void cmMakefile::AddLinkLibraryForTarget(const std::string& target,
     if(tgt)
       {
       // if it is not a static or shared library then you can not link to it
-      if(!((tgt->GetType() == cmTarget::STATIC_LIBRARY) ||
-           (tgt->GetType() == cmTarget::SHARED_LIBRARY) ||
-           (tgt->GetType() == cmTarget::INTERFACE_LIBRARY) ||
+      if(!((tgt->GetType() == cmState::STATIC_LIBRARY) ||
+           (tgt->GetType() == cmState::SHARED_LIBRARY) ||
+           (tgt->GetType() == cmState::INTERFACE_LIBRARY) ||
            tgt->IsExecutableWithExports()))
         {
         std::ostringstream e;
         e << "Target \"" << lib << "\" of type "
-          << cmTarget::GetTargetTypeName(tgt->GetType())
+          << cmState::GetTargetTypeName(tgt->GetType())
           << " may not be linked into another target.  "
           << "One may link only to STATIC or SHARED libraries, or "
           << "to executables with the ENABLE_EXPORTS property set.";
@@ -1467,18 +1476,11 @@ void cmMakefile::AddLinkDirectoryForTarget(const std::string& target,
 
 void cmMakefile::AddLinkLibrary(const std::string& lib)
 {
-  this->AddLinkLibrary(lib,cmTarget::GENERAL);
+  this->AddLinkLibrary(lib,GENERAL_LibraryType);
 }
 
 void cmMakefile::InitializeFromParent(cmMakefile* parent)
 {
-  this->StateSnapshot.InitializeFromParent();
-
-  this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
-                      this->GetCurrentSourceDirectory());
-  this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
-                      this->GetCurrentBinaryDirectory());
-
   this->SystemIncludeDirectories = parent->SystemIncludeDirectories;
 
   // define flags
@@ -1517,7 +1519,7 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent)
                     parent->GetProperty("LINK_DIRECTORIES"));
 
   // the initial project name
-  this->SetProjectName(parent->GetProjectName());
+  this->StateSnapshot.SetProjectName(parent->StateSnapshot.GetProjectName());
 
   // Copy include regular expressions.
   this->ComplainFileRegularExpression = parent->ComplainFileRegularExpression;
@@ -1673,6 +1675,7 @@ void cmMakefile::Configure()
   std::vector<cmMakefile*>::iterator sdi = subdirs.begin();
   for (; sdi != subdirs.end(); ++sdi)
     {
+    (*sdi)->StateSnapshot.InitializeFromParent_ForSubdirsCommand();
     this->ConfigureSubDirectory(*sdi);
     }
 
@@ -1749,12 +1752,14 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath,
                                            this->ContextStack.back()->Name,
                                            this->ContextStack.back()->Line);
 
+  newSnapshot.GetDirectory().SetCurrentSource(srcPath);
+  newSnapshot.GetDirectory().SetCurrentBinary(binPath);
+
+  cmSystemTools::MakeDirectory(binPath.c_str());
+
   cmMakefile* subMf = new cmMakefile(this->GlobalGenerator, newSnapshot);
   this->GetGlobalGenerator()->AddMakefile(subMf);
 
-  // set the subdirs start dirs
-  subMf->SetCurrentSourceDirectory(srcPath);
-  subMf->SetCurrentBinaryDirectory(binPath);
   if(excludeFromAll)
     {
     subMf->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
@@ -1770,35 +1775,26 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath,
     }
 }
 
-void cmMakefile::SetCurrentSourceDirectory(const std::string& dir)
-{
-  this->StateSnapshot.GetDirectory().SetCurrentSource(dir);
-  this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
-                      this->StateSnapshot.GetDirectory().GetCurrentSource());
-}
-
 const char* cmMakefile::GetCurrentSourceDirectory() const
 {
   return this->StateSnapshot.GetDirectory().GetCurrentSource();
 }
 
-void cmMakefile::SetCurrentBinaryDirectory(const std::string& dir)
-{
-  this->StateSnapshot.GetDirectory().SetCurrentBinary(dir);
-  const char* binDir = this->StateSnapshot.GetDirectory().GetCurrentBinary();
-  cmSystemTools::MakeDirectory(binDir);
-  this->AddDefinition("CMAKE_CURRENT_BINARY_DIR", binDir);
-}
-
 const char* cmMakefile::GetCurrentBinaryDirectory() const
 {
   return this->StateSnapshot.GetDirectory().GetCurrentBinary();
 }
 
-void cmMakefile::AddGeneratorTarget(cmTarget* t, cmGeneratorTarget* gt)
+std::vector<cmTarget*> cmMakefile::GetImportedTargets() const
 {
-  this->GeneratorTargets[t] = gt;
-  this->GetGlobalGenerator()->AddGeneratorTarget(t, gt);
+  std::vector<cmTarget*> tgts;
+  tgts.reserve(this->ImportedTargets.size());
+  for (TargetMap::const_iterator it = this->ImportedTargets.begin();
+       it != this->ImportedTargets.end(); ++it)
+    {
+    tgts.push_back(it->second);
+    }
+  return tgts;
 }
 
 //----------------------------------------------------------------------------
@@ -1911,13 +1907,13 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
         nvalue += files[cc];
         }
 
-      this->GetState()->AddCacheEntry(name, nvalue.c_str(), doc, type);
+      this->GetCMakeInstance()->AddCacheEntry(name, nvalue.c_str(), doc, type);
       val = this->GetState()->GetInitializedCacheValue(name);
       haveVal = true;
       }
 
     }
-  this->GetState()->AddCacheEntry(name, haveVal ? val.c_str() : 0,
+  this->GetCMakeInstance()->AddCacheEntry(name, haveVal ? val.c_str() : 0,
                                           doc, type);
   // if there was a definition then remove it
   this->StateSnapshot.RemoveDefinition(name);
@@ -2033,20 +2029,15 @@ void cmMakefile::SetProjectName(std::string const& p)
   this->StateSnapshot.SetProjectName(p);
 }
 
-std::string cmMakefile::GetProjectName() const
-{
-  return this->StateSnapshot.GetProjectName();
-}
-
 void cmMakefile::AddGlobalLinkInformation(const std::string& name,
                                           cmTarget& target)
 {
   // for these targets do not add anything
   switch(target.GetType())
     {
-    case cmTarget::UTILITY:
-    case cmTarget::GLOBAL_TARGET:
-    case cmTarget::INTERFACE_LIBRARY:
+    case cmState::UTILITY:
+    case cmState::GLOBAL_TARGET:
+    case cmState::INTERFACE_LIBRARY:
       return;
     default:;
     }
@@ -2076,27 +2067,28 @@ void cmMakefile::AddGlobalLinkInformation(const std::string& name,
 }
 
 
-void cmMakefile::AddAlias(const std::string& lname, cmTarget *tgt)
+void cmMakefile::AddAlias(const std::string& lname,
+                          std::string const& tgtName)
 {
-  this->AliasTargets[lname] = tgt;
-  this->GetGlobalGenerator()->AddAlias(lname, tgt);
+  this->AliasTargets[lname] = tgtName;
+  this->GetGlobalGenerator()->AddAlias(lname, tgtName);
 }
 
 cmTarget* cmMakefile::AddLibrary(const std::string& lname,
-                            cmTarget::TargetType type,
+                            cmState::TargetType type,
                             const std::vector<std::string> &srcs,
                             bool excludeFromAll)
 {
   // wrong type ? default to STATIC
-  if (    (type != cmTarget::STATIC_LIBRARY)
-       && (type != cmTarget::SHARED_LIBRARY)
-       && (type != cmTarget::MODULE_LIBRARY)
-       && (type != cmTarget::OBJECT_LIBRARY)
-       && (type != cmTarget::INTERFACE_LIBRARY))
+  if (    (type != cmState::STATIC_LIBRARY)
+       && (type != cmState::SHARED_LIBRARY)
+       && (type != cmState::MODULE_LIBRARY)
+       && (type != cmState::OBJECT_LIBRARY)
+       && (type != cmState::INTERFACE_LIBRARY))
     {
     this->IssueMessage(cmake::INTERNAL_ERROR,
                        "cmMakefile::AddLibrary given invalid target type.");
-    type = cmTarget::STATIC_LIBRARY;
+    type = cmState::STATIC_LIBRARY;
     }
 
   cmTarget* target = this->AddNewTarget(type, lname);
@@ -2117,7 +2109,7 @@ cmTarget* cmMakefile::AddExecutable(const char *exeName,
                                     const std::vector<std::string> &srcs,
                                     bool excludeFromAll)
 {
-  cmTarget* target = this->AddNewTarget(cmTarget::EXECUTABLE, exeName);
+  cmTarget* target = this->AddNewTarget(cmState::EXECUTABLE, exeName);
   if(excludeFromAll)
     {
     target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
@@ -2129,14 +2121,14 @@ cmTarget* cmMakefile::AddExecutable(const char *exeName,
 
 //----------------------------------------------------------------------------
 cmTarget*
-cmMakefile::AddNewTarget(cmTarget::TargetType type, const std::string& name)
+cmMakefile::AddNewTarget(cmState::TargetType type, const std::string& name)
 {
   cmTargets::iterator it =
     this->Targets.insert(cmTargets::value_type(name, cmTarget())).first;
   cmTarget& target = it->second;
   target.SetType(type, name);
   target.SetMakefile(this);
-  this->GetGlobalGenerator()->AddTarget(&it->second);
+  this->GetGlobalGenerator()->IndexTarget(&it->second);
   return &it->second;
 }
 
@@ -2200,7 +2192,7 @@ cmMakefile::GetSourceGroup(const std::vector<std::string>&name) const
 {
   cmSourceGroup* sg = 0;
 
-  // first look for source group starting with the same as the one we wants
+  // first look for source group starting with the same as the one we want
   for (std::vector<cmSourceGroup>::const_iterator
       sgIt = this->SourceGroups.begin();
       sgIt != this->SourceGroups.end(); ++sgIt)
@@ -2233,7 +2225,7 @@ void cmMakefile::AddSourceGroup(const std::string& name,
 {
   std::vector<std::string> nameVector;
   nameVector.push_back(name);
-  AddSourceGroup(nameVector, regex);
+  this->AddSourceGroup(nameVector, regex);
 }
 
 void cmMakefile::AddSourceGroup(const std::vector<std::string>& name,
@@ -2325,8 +2317,8 @@ void cmMakefile::ExpandVariablesCMP0019()
        l != this->Targets.end(); ++l)
     {
     cmTarget &t = l->second;
-    if (t.GetType() == cmTarget::INTERFACE_LIBRARY
-        || t.GetType() == cmTarget::GLOBAL_TARGET)
+    if (t.GetType() == cmState::INTERFACE_LIBRARY
+        || t.GetType() == cmState::GLOBAL_TARGET)
       {
       continue;
       }
@@ -2433,10 +2425,23 @@ bool cmMakefile::PlatformIsAppleIos() const
   sdkRoot = this->GetSafeDefinition("CMAKE_OSX_SYSROOT");
   sdkRoot = cmSystemTools::LowerCase(sdkRoot);
 
-  return sdkRoot.find("iphoneos") == 0 ||
-         sdkRoot.find("/iphoneos") != std::string::npos ||
-         sdkRoot.find("iphonesimulator") == 0 ||
-         sdkRoot.find("/iphonesimulator") != std::string::npos;
+  const std::string embedded[] =
+    {
+    "appletvos", "appletvsimulator",
+    "iphoneos", "iphonesimulator",
+    "watchos", "watchsimulator",
+    };
+
+  for(size_t i = 0; i < sizeof(embedded) / sizeof(embedded[0]); ++i)
+    {
+    if(sdkRoot.find(embedded[i]) == 0 ||
+       sdkRoot.find(std::string("/") + embedded[i]) != std::string::npos)
+      {
+      return true;
+      }
+    }
+
+   return false;
 }
 
 const char* cmMakefile::GetSONameFlag(const std::string& language) const
@@ -2845,10 +2850,9 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
   const char* last = in;
   std::string result;
   result.reserve(source.size());
-  std::stack<t_lookup> openstack;
+  std::vector<t_lookup> openstack;
   bool error = false;
   bool done = false;
-  openstack.push(t_lookup());
   cmake::MessageType mtype = cmake::LOG;
 
   cmState* state = this->GetCMakeInstance()->GetState();
@@ -2859,10 +2863,10 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
     switch(inc)
       {
       case '}':
-        if(openstack.size() > 1)
+        if(!openstack.empty())
           {
-          t_lookup var = openstack.top();
-          openstack.pop();
+          t_lookup var = openstack.back();
+          openstack.pop_back();
           result.append(last, in - last);
           std::string const& lookup = result.substr(var.loc);
           const char* value = NULL;
@@ -2983,7 +2987,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
             last = start;
             in = start - 1;
             lookup.loc = result.size();
-            openstack.push(lookup);
+            openstack.push_back(lookup);
             }
           break;
           }
@@ -3010,7 +3014,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
             result.append("\r");
             last = next + 1;
             }
-          else if(nextc == ';' && openstack.size() == 1)
+          else if(nextc == ';' && openstack.empty())
             {
             // Handled in ExpandListArgument; pass the backslash literally.
             }
@@ -3078,7 +3082,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
         /* FALLTHROUGH */
       default:
         {
-        if(openstack.size() > 1 &&
+        if(!openstack.empty() &&
            !(isalnum(inc) || inc == '_' ||
              inc == '/' || inc == '.' ||
              inc == '+' || inc == '-'))
@@ -3087,7 +3091,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
           errorstr += inc;
           result.append(last, in - last);
           errorstr += "\') in a variable name: "
-                      "'" + result.substr(openstack.top().loc) + "'";
+                      "'" + result.substr(openstack.back().loc) + "'";
           mtype = cmake::FATAL_ERROR;
           error = true;
           }
@@ -3098,7 +3102,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
     } while(!error && !done && *++in);
 
   // Check for open variable references yet.
-  if(!error && openstack.size() != 1)
+  if(!error && !openstack.empty())
     {
     // There's an open variable reference waiting.  Policy CMP0010 flags
     // whether this is an error or not.  The new parser now enforces
@@ -3163,58 +3167,6 @@ void cmMakefile::RemoveVariablesInString(std::string& source,
     }
 }
 
-/**
- * Add the default definitions to the makefile.  These values must not
- * be dependent on anything that isn't known when this cmMakefile instance
- * is constructed.
- */
-void cmMakefile::AddDefaultDefinitions()
-{
-/* Up to CMake 2.4 here only WIN32, UNIX and APPLE were set.
-  With CMake must separate between target and host platform. In most cases
-  the tests for WIN32, UNIX and APPLE will be for the target system, so an
-  additional set of variables for the host system is required ->
-  CMAKE_HOST_WIN32, CMAKE_HOST_UNIX, CMAKE_HOST_APPLE.
-  WIN32, UNIX and APPLE are now set in the platform files in
-  Modules/Platforms/.
-  To keep cmake scripts (-P) and custom language and compiler modules
-  working, these variables are still also set here in this place, but they
-  will be reset in CMakeSystemSpecificInformation.cmake before the platform
-  files are executed. */
-#if defined(_WIN32)
-  this->AddDefinition("WIN32", "1");
-  this->AddDefinition("CMAKE_HOST_WIN32", "1");
-#else
-  this->AddDefinition("UNIX", "1");
-  this->AddDefinition("CMAKE_HOST_UNIX", "1");
-#endif
-#if defined(__CYGWIN__)
-  if(cmSystemTools::IsOn(cmSystemTools::GetEnv("CMAKE_LEGACY_CYGWIN_WIN32")))
-    {
-    this->AddDefinition("WIN32", "1");
-    this->AddDefinition("CMAKE_HOST_WIN32", "1");
-    }
-#endif
-#if defined(__APPLE__)
-  this->AddDefinition("APPLE", "1");
-  this->AddDefinition("CMAKE_HOST_APPLE", "1");
-#endif
-
-  char temp[1024];
-  sprintf(temp, "%d", cmVersion::GetMinorVersion());
-  this->AddDefinition("CMAKE_MINOR_VERSION", temp);
-  sprintf(temp, "%d", cmVersion::GetMajorVersion());
-  this->AddDefinition("CMAKE_MAJOR_VERSION", temp);
-  sprintf(temp, "%d", cmVersion::GetPatchVersion());
-  this->AddDefinition("CMAKE_PATCH_VERSION", temp);
-  sprintf(temp, "%d", cmVersion::GetTweakVersion());
-  this->AddDefinition("CMAKE_TWEAK_VERSION", temp);
-  this->AddDefinition("CMAKE_VERSION", cmVersion::GetCMakeVersion());
-
-  this->AddDefinition("CMAKE_FILES_DIRECTORY",
-                      cmake::GetCMakeFilesDirectory());
-}
-
 //----------------------------------------------------------------------------
 std::string
 cmMakefile::GetConfigurations(std::vector<std::string>& configs,
@@ -4104,10 +4056,12 @@ cmTarget* cmMakefile::FindTarget(const std::string& name,
 {
   if (!excludeAliases)
     {
-    TargetMap::const_iterator i = this->AliasTargets.find(name);
+    std::map<std::string, std::string>::const_iterator i =
+        this->AliasTargets.find(name);
     if (i != this->AliasTargets.end())
       {
-      return i->second;
+      cmTargets::iterator ai = this->Targets.find(i->second);
+      return &ai->second;
       }
     }
   cmTargets::iterator i = this->Targets.find( name );
@@ -4254,21 +4208,18 @@ void cmMakefile::RaiseScope(const std::string& var, const char *varDef)
 //----------------------------------------------------------------------------
 cmTarget*
 cmMakefile::AddImportedTarget(const std::string& name,
-                              cmTarget::TargetType type,
+                              cmState::TargetType type,
                               bool global)
 {
   // Create the target.
   cmsys::auto_ptr<cmTarget> target(new cmTarget);
   target->SetType(type, name);
-  target->MarkAsImported();
+  target->MarkAsImported(global);
   target->SetMakefile(this);
 
   // Add to the set of available imported targets.
   this->ImportedTargets[name] = target.get();
-  if(global)
-    {
-    this->GetGlobalGenerator()->AddTarget(target.get());
-    }
+  this->GetGlobalGenerator()->IndexTarget(target.get());
 
   // Transfer ownership to this cmMakefile object.
   this->ImportedTargetsOwned.push_back(target.get());
@@ -4307,17 +4258,6 @@ bool cmMakefile::IsAlias(const std::string& name) const
 }
 
 //----------------------------------------------------------------------------
-cmGeneratorTarget*
-cmMakefile::FindGeneratorTargetToUse(const std::string& name) const
-{
-  if (cmTarget *t = this->FindTargetToUse(name))
-    {
-    return this->GetGlobalGenerator()->GetGeneratorTarget(t);
-    }
-  return 0;
-}
-
-//----------------------------------------------------------------------------
 bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg,
                                    bool isCustom) const
 {
@@ -4366,7 +4306,7 @@ bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg,
       // The conflict is with a non-imported target.
       // Allow this if the user has requested support.
       cmake* cm = this->GetCMakeInstance();
-      if(isCustom && existing->GetType() == cmTarget::UTILITY &&
+      if(isCustom && existing->GetType() == cmState::UTILITY &&
          this != existing->GetMakefile() &&
          cm->GetState()
            ->GetGlobalPropertyAsBool("ALLOW_DUPLICATE_CUSTOM_TARGETS"))
@@ -4382,22 +4322,22 @@ bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg,
         << "The existing target is ";
       switch(existing->GetType())
         {
-        case cmTarget::EXECUTABLE:
+        case cmState::EXECUTABLE:
           e << "an executable ";
           break;
-        case cmTarget::STATIC_LIBRARY:
+        case cmState::STATIC_LIBRARY:
           e << "a static library ";
           break;
-        case cmTarget::SHARED_LIBRARY:
+        case cmState::SHARED_LIBRARY:
           e << "a shared library ";
           break;
-        case cmTarget::MODULE_LIBRARY:
+        case cmState::MODULE_LIBRARY:
           e << "a module library ";
           break;
-        case cmTarget::UTILITY:
+        case cmState::UTILITY:
           e << "a custom target ";
           break;
-        case cmTarget::INTERFACE_LIBRARY:
+        case cmState::INTERFACE_LIBRARY:
           e << "an interface library ";
           break;
         default: break;
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 1edffdc..362ea75 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -17,7 +17,6 @@
 #include "cmSystemTools.h"
 #include "cmTarget.h"
 #include "cmNewLineStyle.h"
-#include "cmGeneratorTarget.h"
 #include "cmExpandedCommandArgument.h"
 #include "cmake.h"
 #include "cmState.h"
@@ -42,7 +41,6 @@
 class cmFunctionBlocker;
 class cmCommand;
 class cmInstallGenerator;
-class cmMakeDepend;
 class cmSourceFile;
 class cmTest;
 class cmTestGenerator;
@@ -51,6 +49,7 @@ class cmake;
 class cmMakefileCall;
 class cmCMakePolicyCommand;
 class cmGeneratorExpressionEvaluationFile;
+class cmExportBuildFileGenerator;
 
 /** \class cmMakefile
  * \brief Process the input CMakeLists.txt file.
@@ -172,10 +171,10 @@ public:
 
   /** Create a new imported target with the name and type given.  */
   cmTarget* AddImportedTarget(const std::string& name,
-                              cmTarget::TargetType type,
+                              cmState::TargetType type,
                               bool global);
 
-  cmTarget* AddNewTarget(cmTarget::TargetType type, const std::string& name);
+  cmTarget* AddNewTarget(cmState::TargetType type, const std::string& name);
 
   /**
    * Add an executable to the build.
@@ -219,9 +218,9 @@ public:
    * Add a link library to the build.
    */
   void AddLinkLibrary(const std::string&);
-  void AddLinkLibrary(const std::string&, cmTarget::LinkLibraryType type);
+  void AddLinkLibrary(const std::string&, cmTargetLinkLibraryType type);
   void AddLinkLibraryForTarget(const std::string& tgt, const std::string&,
-                               cmTarget::LinkLibraryType type);
+                               cmTargetLinkLibraryType type);
   void AddLinkDirectoryForTarget(const std::string& tgt, const std::string& d);
 
   /**
@@ -274,11 +273,6 @@ public:
    */
   void SetProjectName(std::string const& name);
 
-  /**
-   * Get the name of the project for this build.
-   */
-  std::string GetProjectName() const;
-
   /** Get the configurations to be generated.  */
   std::string GetConfigurations(std::vector<std::string>& configs,
                                 bool single = true) const;
@@ -286,10 +280,10 @@ public:
   /**
    * Set the name of the library.
    */
-  cmTarget* AddLibrary(const std::string& libname, cmTarget::TargetType type,
+  cmTarget* AddLibrary(const std::string& libname, cmState::TargetType type,
                   const std::vector<std::string> &srcs,
                   bool excludeFromAll = false);
-  void AddAlias(const std::string& libname, cmTarget *tgt);
+  void AddAlias(const std::string& libname, const std::string& tgt);
 
 #if defined(CMAKE_BUILD_WITH_CMAKE)
   /**
@@ -349,9 +343,7 @@ public:
    */
   void SetArgcArgv(const std::vector<std::string>& args);
 
-  void SetCurrentSourceDirectory(const std::string& dir);
   const char* GetCurrentSourceDirectory() const;
-  void SetCurrentBinaryDirectory(const std::string& dir);
   const char* GetCurrentBinaryDirectory() const;
 
   //@}
@@ -394,17 +386,7 @@ public:
     {
       return this->ImportedTargetsOwned;
     }
-
-  const cmGeneratorTargetsType &GetGeneratorTargets() const
-    {
-      return this->GeneratorTargets;
-    }
-
-  void SetGeneratorTargets(const cmGeneratorTargetsType &targets)
-    {
-      this->GeneratorTargets = targets;
-    }
-  void AddGeneratorTarget(cmTarget* t, cmGeneratorTarget* gt);
+  std::vector<cmTarget*> GetImportedTargets() const;
 
   cmTarget* FindTarget(const std::string& name,
                        bool excludeAliases = false) const;
@@ -414,7 +396,11 @@ public:
   cmTarget* FindTargetToUse(const std::string& name,
                             bool excludeAliases = false) const;
   bool IsAlias(const std::string& name) const;
-  cmGeneratorTarget* FindGeneratorTargetToUse(const std::string& name) const;
+
+  std::map<std::string, std::string> GetAliasTargets() const
+  {
+    return this->AliasTargets;
+  }
 
   /**
    * Mark include directories as system directories.
@@ -441,17 +427,6 @@ public:
   cmSourceFile* GetOrCreateSource(const std::string& sourceName,
                                   bool generated = false);
 
-  //@{
-  /**
-   * Return a list of extensions associated with source and header
-   * files
-   */
-  const std::vector<std::string>& GetSourceExtensions() const
-    {return this->SourceFileExtensions;}
-  const std::vector<std::string>& GetHeaderExtensions() const
-    {return this->HeaderFileExtensions;}
-  //@}
-
   /**
    * Given a variable name, return its value (as a string).
    * If the variable is not found in this makefile instance, the
@@ -734,7 +709,8 @@ public:
   };
 
   void IssueMessage(cmake::MessageType t,
-                    std::string const& text) const;
+                    std::string const& text,
+                    bool force = false) const;
 
   /** Set whether or not to report a CMP0000 violation.  */
   void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }
@@ -792,6 +768,11 @@ public:
                   bool inputIsContent);
   std::vector<cmGeneratorExpressionEvaluationFile*> GetEvaluationFiles() const;
 
+  std::vector<cmExportBuildFileGenerator*>
+  GetExportBuildFileGenerators() const;
+  void RemoveExportBuildFileGeneratorCMP0024(cmExportBuildFileGenerator* gen);
+  void AddExportBuildFileGenerator(cmExportBuildFileGenerator* gen);
+
 protected:
   // add link libraries and directories to the target
   void AddGlobalLinkInformation(const std::string& name, cmTarget& target);
@@ -812,8 +793,7 @@ protected:
 #else
   typedef std::map<std::string, cmTarget*> TargetMap;
 #endif
-  TargetMap AliasTargets;
-  cmGeneratorTargetsType GeneratorTargets;
+  std::map<std::string, std::string> AliasTargets;
   std::vector<cmSourceFile*> SourceFiles;
 
   // Tests
@@ -835,8 +815,6 @@ protected:
   std::vector<cmTestGenerator*> TestGenerators;
 
   std::string ComplainFileRegularExpression;
-  std::vector<std::string> SourceFileExtensions;
-  std::vector<std::string> HeaderFileExtensions;
   std::string DefineFlags;
 
   // Track the value of the computed DEFINITIONS property.
@@ -867,10 +845,6 @@ private:
   bool EnforceUniqueDir(const std::string& srcPath,
                         const std::string& binPath) const;
 
-  friend class cmMakeDepend;    // make depend needs direct access
-                                // to the Sources array
-
-  void AddDefaultDefinitions();
   typedef std::vector<cmFunctionBlocker*> FunctionBlockersType;
   FunctionBlockersType FunctionBlockers;
   std::vector<FunctionBlockersType::size_type> FunctionBlockerBarriers;
@@ -885,6 +859,7 @@ private:
   mutable cmsys::RegularExpression cmNamedCurly;
 
   std::vector<cmMakefile*> UnConfiguredDirectories;
+  std::vector<cmExportBuildFileGenerator*> ExportBuildFileGenerators;
 
   std::vector<cmGeneratorExpressionEvaluationFile*> EvaluationFiles;
 
diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx
index 90f679e..9e35e4c 100644
--- a/Source/cmMakefileExecutableTargetGenerator.cxx
+++ b/Source/cmMakefileExecutableTargetGenerator.cxx
@@ -16,7 +16,6 @@
 #include "cmLocalUnixMakefileGenerator3.h"
 #include "cmMakefile.h"
 #include "cmSourceFile.h"
-#include "cmTarget.h"
 #include "cmake.h"
 
 //----------------------------------------------------------------------------
@@ -99,8 +98,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
      this->ConfigName);
 
   // Construct the full path version of the names.
-  std::string outpath = this->Target->GetDirectory(this->ConfigName);
-  if(this->Target->IsAppBundleOnApple())
+  std::string outpath = this->GeneratorTarget->GetDirectory(this->ConfigName);
+  if(this->GeneratorTarget->IsAppBundleOnApple())
     {
     this->OSXBundleGenerator->CreateAppBundle(targetName, outpath);
     }
@@ -123,7 +122,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
     cmSystemTools::MakeDirectory(outpath.c_str());
     if(!targetNameImport.empty())
       {
-      outpathImp = this->Target->GetDirectory(this->ConfigName, true);
+      outpathImp = this->GeneratorTarget->GetDirectory(this->ConfigName, true);
       cmSystemTools::MakeDirectory(outpathImp.c_str());
       outpathImp += "/";
       }
@@ -133,7 +132,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
     this->GeneratorTarget->GetCompilePDBDirectory(this->ConfigName);
   cmSystemTools::MakeDirectory(compilePdbOutputPath.c_str());
 
-  std::string pdbOutputPath = this->Target->GetPDBDirectory(this->ConfigName);
+  std::string pdbOutputPath =
+      this->GeneratorTarget->GetPDBDirectory(this->ConfigName);
   cmSystemTools::MakeDirectory(pdbOutputPath.c_str());
   pdbOutputPath += "/";
 
@@ -167,7 +167,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
   if(linkLanguage.empty())
     {
     cmSystemTools::Error("Cannot determine link language for target \"",
-                         this->Target->GetName().c_str(), "\".");
+                         this->GeneratorTarget->GetName().c_str(), "\".");
     return;
     }
 
@@ -196,7 +196,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
                            this->ConfigName);
 
 
-  if(this->Target->GetPropertyAsBool("WIN32_EXECUTABLE"))
+  if(this->GeneratorTarget->GetPropertyAsBool("WIN32_EXECUTABLE"))
     {
     this->LocalGenerator->AppendFlags
       (linkFlags, this->Makefile->GetDefinition("CMAKE_CREATE_WIN32_EXE"));
@@ -208,7 +208,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
     }
 
   // Add symbol export flags if necessary.
-  if(this->Target->IsExecutableWithExports())
+  if(this->GeneratorTarget->IsExecutableWithExports())
     {
     std::string export_flag_var = "CMAKE_EXE_EXPORTS_";
     export_flag_var += linkLanguage;
@@ -225,11 +225,11 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
 
   // Add target-specific linker flags.
   this->LocalGenerator->AppendFlags
-    (linkFlags, this->Target->GetProperty("LINK_FLAGS"));
+    (linkFlags, this->GeneratorTarget->GetProperty("LINK_FLAGS"));
   std::string linkFlagsConfig = "LINK_FLAGS_";
   linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
   this->LocalGenerator->AppendFlags
-    (linkFlags, this->Target->GetProperty(linkFlagsConfig));
+    (linkFlags, this->GeneratorTarget->GetProperty(linkFlagsConfig));
 
   this->AddModuleDefinitionFlag(linkFlags);
 
@@ -258,7 +258,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
                                           cmLocalGenerator::START_OUTPUT,
                                           cmLocalGenerator::UNCHANGED));
     std::string implib;
-    if(this->Target->GetImplibGNUtoMS(targetFullPathImport, implib))
+    if(this->GeneratorTarget->GetImplibGNUtoMS(targetFullPathImport, implib))
       {
       exeCleanFiles.push_back(this->Convert(implib,
                                             cmLocalGenerator::START_OUTPUT,
@@ -278,11 +278,13 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
   if(!relink)
     {
     this->LocalGenerator
-      ->AppendCustomCommands(commands, this->Target->GetPreBuildCommands(),
-                             this->Target);
+      ->AppendCustomCommands(commands,
+                        this->GeneratorTarget->GetPreBuildCommands(),
+                        this->GeneratorTarget);
     this->LocalGenerator
-      ->AppendCustomCommands(commands, this->Target->GetPreLinkCommands(),
-                             this->Target);
+      ->AppendCustomCommands(commands,
+                        this->GeneratorTarget->GetPreLinkCommands(),
+                        this->GeneratorTarget);
     }
 
   // Determine whether a link script will be used.
@@ -296,7 +298,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
   std::string linkRule = this->GetLinkRule(linkRuleVar);
   std::vector<std::string> commands1;
   cmSystemTools::ExpandListArgument(linkRule, real_link_commands);
-  if(this->Target->IsExecutableWithExports())
+  if(this->GeneratorTarget->IsExecutableWithExports())
     {
     // If a separate rule for creating an import library is specified
     // add it now.
@@ -357,10 +359,10 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
 
   cmLocalGenerator::RuleVariables vars;
   vars.RuleLauncher = "RULE_LAUNCH_LINK";
-  vars.CMTarget = this->Target;
+  vars.CMTarget = this->GeneratorTarget;
   vars.Language = linkLanguage.c_str();
   vars.Objects = buildObjs.c_str();
-  std::string objectDir = this->Target->GetSupportDirectory();
+  std::string objectDir = this->GeneratorTarget->GetSupportDirectory();
   objectDir = this->Convert(objectDir,
                             cmLocalGenerator::START_OUTPUT,
                             cmLocalGenerator::SHELL);
@@ -381,7 +383,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
   std::ostringstream minorStream;
   int major;
   int minor;
-  this->Target->GetTargetVersion(major, minor);
+  this->GeneratorTarget->GetTargetVersion(major, minor);
   majorStream << major;
   minorStream << minor;
   targetVersionMajor = majorStream.str();
@@ -447,8 +449,9 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
   if(!relink)
     {
     this->LocalGenerator->
-      AppendCustomCommands(commands, this->Target->GetPostBuildCommands(),
-                           this->Target);
+      AppendCustomCommands(commands,
+                       this->GeneratorTarget->GetPostBuildCommands(),
+                       this->GeneratorTarget);
     }
 
   // Write the build rule.
diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx
index cd387a0..1923ea4 100644
--- a/Source/cmMakefileLibraryTargetGenerator.cxx
+++ b/Source/cmMakefileLibraryTargetGenerator.cxx
@@ -16,7 +16,6 @@
 #include "cmLocalUnixMakefileGenerator3.h"
 #include "cmMakefile.h"
 #include "cmSourceFile.h"
-#include "cmTarget.h"
 #include "cmake.h"
 #include "cmAlgorithms.h"
 
@@ -26,7 +25,7 @@ cmMakefileLibraryTargetGenerator
   cmMakefileTargetGenerator(target)
 {
   this->CustomCommandDriver = OnDepends;
-  if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
+  if (this->GeneratorTarget->GetType() != cmState::INTERFACE_LIBRARY)
     {
     this->GeneratorTarget->GetLibraryNames(
       this->TargetNameOut, this->TargetNameSO, this->TargetNameReal,
@@ -62,12 +61,12 @@ void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
 
   // write the link rules
   // Write the rule for this target type.
-  switch(this->Target->GetType())
+  switch(this->GeneratorTarget->GetType())
     {
-    case cmTarget::STATIC_LIBRARY:
+    case cmState::STATIC_LIBRARY:
       this->WriteStaticLibraryRules();
       break;
-    case cmTarget::SHARED_LIBRARY:
+    case cmState::SHARED_LIBRARY:
       this->WriteSharedLibraryRules(false);
       if(this->GeneratorTarget->NeedRelinkBeforeInstall(this->ConfigName))
         {
@@ -75,7 +74,7 @@ void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
         this->WriteSharedLibraryRules(true);
         }
       break;
-    case cmTarget::MODULE_LIBRARY:
+    case cmState::MODULE_LIBRARY:
       this->WriteModuleLibraryRules(false);
       if(this->GeneratorTarget->NeedRelinkBeforeInstall(this->ConfigName))
         {
@@ -83,7 +82,7 @@ void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
         this->WriteModuleLibraryRules(true);
         }
       break;
-    case cmTarget::OBJECT_LIBRARY:
+    case cmState::OBJECT_LIBRARY:
       this->WriteObjectLibraryRules();
       break;
     default:
@@ -114,19 +113,20 @@ void cmMakefileLibraryTargetGenerator::WriteObjectLibraryRules()
 
   // Add post-build rules.
   this->LocalGenerator->
-    AppendCustomCommands(commands, this->Target->GetPostBuildCommands(),
-                         this->Target);
+    AppendCustomCommands(commands,
+                         this->GeneratorTarget->GetPostBuildCommands(),
+                         this->GeneratorTarget);
 
   // Depend on the object files.
   this->AppendObjectDepends(depends);
 
   // Write the rule.
   this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
-                                      this->Target->GetName(),
+                                      this->GeneratorTarget->GetName(),
                                       depends, commands, true);
 
   // Write the main driver rule to build everything in this target.
-  this->WriteTargetDriverRule(this->Target->GetName(), false);
+  this->WriteTargetDriverRule(this->GeneratorTarget->GetName(), false);
 }
 
 //----------------------------------------------------------------------------
@@ -146,14 +146,14 @@ void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules()
 
   std::string extraFlags;
   this->LocalGenerator->GetStaticLibraryFlags(extraFlags,
-    cmSystemTools::UpperCase(this->ConfigName), this->Target);
+    cmSystemTools::UpperCase(this->ConfigName), this->GeneratorTarget);
   this->WriteLibraryRules(linkRuleVar, extraFlags, false);
 }
 
 //----------------------------------------------------------------------------
 void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
 {
-  if(this->Target->IsFrameworkOnApple())
+  if(this->GeneratorTarget->IsFrameworkOnApple())
     {
     this->WriteFrameworkRules(relink);
     return;
@@ -166,11 +166,11 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
 
   std::string extraFlags;
   this->LocalGenerator->AppendFlags
-    (extraFlags, this->Target->GetProperty("LINK_FLAGS"));
+    (extraFlags, this->GeneratorTarget->GetProperty("LINK_FLAGS"));
   std::string linkFlagsConfig = "LINK_FLAGS_";
   linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
   this->LocalGenerator->AppendFlags
-    (extraFlags, this->Target->GetProperty(linkFlagsConfig));
+    (extraFlags, this->GeneratorTarget->GetProperty(linkFlagsConfig));
 
   this->LocalGenerator->AddConfigVariableFlags
     (extraFlags, "CMAKE_SHARED_LINKER_FLAGS", this->ConfigName);
@@ -190,11 +190,11 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
 
   std::string extraFlags;
   this->LocalGenerator->AppendFlags(extraFlags,
-                                    this->Target->GetProperty("LINK_FLAGS"));
+                           this->GeneratorTarget->GetProperty("LINK_FLAGS"));
   std::string linkFlagsConfig = "LINK_FLAGS_";
   linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
   this->LocalGenerator->AppendFlags
-    (extraFlags, this->Target->GetProperty(linkFlagsConfig));
+    (extraFlags, this->GeneratorTarget->GetProperty(linkFlagsConfig));
   this->LocalGenerator->AddConfigVariableFlags
     (extraFlags, "CMAKE_MODULE_LINKER_FLAGS", this->ConfigName);
   this->AddModuleDefinitionFlag(extraFlags);
@@ -213,11 +213,11 @@ void cmMakefileLibraryTargetGenerator::WriteFrameworkRules(bool relink)
 
   std::string extraFlags;
   this->LocalGenerator->AppendFlags(extraFlags,
-                                    this->Target->GetProperty("LINK_FLAGS"));
+                             this->GeneratorTarget->GetProperty("LINK_FLAGS"));
   std::string linkFlagsConfig = "LINK_FLAGS_";
   linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
   this->LocalGenerator->AppendFlags
-    (extraFlags, this->Target->GetProperty(linkFlagsConfig));
+    (extraFlags, this->GeneratorTarget->GetProperty(linkFlagsConfig));
   this->LocalGenerator->AddConfigVariableFlags
     (extraFlags, "CMAKE_MACOSX_FRAMEWORK_LINKER_FLAGS", this->ConfigName);
 
@@ -244,7 +244,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
   if(linkLanguage.empty())
     {
     cmSystemTools::Error("Cannot determine link language for target \"",
-                         this->Target->GetName().c_str(), "\".");
+                         this->GeneratorTarget->GetName().c_str(), "\".");
     return;
     }
 
@@ -253,8 +253,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
   this->LocalGenerator->AppendFlags(linkFlags, extraFlags);
 
   // Add OSX version flags, if any.
-  if(this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
-     this->Target->GetType() == cmTarget::MODULE_LIBRARY)
+  if(this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
+     this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY)
     {
     this->AppendOSXVerFlag(linkFlags, linkLanguage, "COMPATIBILITY", true);
     this->AppendOSXVerFlag(linkFlags, linkLanguage, "CURRENT", false);
@@ -273,15 +273,15 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
   // Construct the full path version of the names.
   std::string outpath;
   std::string outpathImp;
-  if(this->Target->IsFrameworkOnApple())
+  if(this->GeneratorTarget->IsFrameworkOnApple())
     {
-    outpath = this->Target->GetDirectory(this->ConfigName);
+    outpath = this->GeneratorTarget->GetDirectory(this->ConfigName);
     this->OSXBundleGenerator->CreateFramework(targetName, outpath);
     outpath += "/";
     }
-  else if(this->Target->IsCFBundleOnApple())
+  else if(this->GeneratorTarget->IsCFBundleOnApple())
     {
-    outpath = this->Target->GetDirectory(this->ConfigName);
+    outpath = this->GeneratorTarget->GetDirectory(this->ConfigName);
     this->OSXBundleGenerator->CreateCFBundle(targetName, outpath);
     outpath += "/";
     }
@@ -299,12 +299,12 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
     }
   else
     {
-    outpath = this->Target->GetDirectory(this->ConfigName);
+    outpath = this->GeneratorTarget->GetDirectory(this->ConfigName);
     cmSystemTools::MakeDirectory(outpath.c_str());
     outpath += "/";
     if(!targetNameImport.empty())
       {
-      outpathImp = this->Target->GetDirectory(this->ConfigName, true);
+      outpathImp = this->GeneratorTarget->GetDirectory(this->ConfigName, true);
       cmSystemTools::MakeDirectory(outpathImp.c_str());
       outpathImp += "/";
       }
@@ -314,7 +314,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
     this->GeneratorTarget->GetCompilePDBDirectory(this->ConfigName);
   cmSystemTools::MakeDirectory(compilePdbOutputPath.c_str());
 
-  std::string pdbOutputPath = this->Target->GetPDBDirectory(this->ConfigName);
+  std::string pdbOutputPath =
+      this->GeneratorTarget->GetPDBDirectory(this->ConfigName);
   cmSystemTools::MakeDirectory(pdbOutputPath.c_str());
   pdbOutputPath += "/";
 
@@ -350,16 +351,16 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
     // Add the link message.
     std::string buildEcho = "Linking ";
     buildEcho += linkLanguage;
-    switch(this->Target->GetType())
+    switch(this->GeneratorTarget->GetType())
       {
-      case cmTarget::STATIC_LIBRARY:
+      case cmState::STATIC_LIBRARY:
         buildEcho += " static library ";
         break;
-      case cmTarget::SHARED_LIBRARY:
+      case cmState::SHARED_LIBRARY:
         buildEcho += " shared library ";
         break;
-      case cmTarget::MODULE_LIBRARY:
-        if (this->Target->IsCFBundleOnApple())
+      case cmState::MODULE_LIBRARY:
+        if (this->GeneratorTarget->IsCFBundleOnApple())
             buildEcho += " CFBundle";
         buildEcho += " shared module ";
         break;
@@ -374,12 +375,12 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
     }
 
   const char* forbiddenFlagVar = 0;
-  switch(this->Target->GetType())
+  switch(this->GeneratorTarget->GetType())
     {
-    case cmTarget::SHARED_LIBRARY:
+    case cmState::SHARED_LIBRARY:
       forbiddenFlagVar = "_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS";
       break;
-    case cmTarget::MODULE_LIBRARY:
+    case cmState::MODULE_LIBRARY:
       forbiddenFlagVar = "_CREATE_SHARED_MODULE_FORBIDDEN_FLAGS";
       break;
     default: break;
@@ -409,7 +410,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
         cmLocalGenerator::START_OUTPUT,
         cmLocalGenerator::UNCHANGED));
     std::string implib;
-    if(this->Target->GetImplibGNUtoMS(targetFullPathImport, implib))
+    if(this->GeneratorTarget->GetImplibGNUtoMS(targetFullPathImport, implib))
       {
       libCleanFiles.push_back(this->Convert(implib,
                                             cmLocalGenerator::START_OUTPUT,
@@ -428,7 +429,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
 #ifdef _WIN32
   // There may be a manifest file for this target.  Add it to the
   // clean set just in case.
-  if(this->Target->GetType() != cmTarget::STATIC_LIBRARY)
+  if(this->GeneratorTarget->GetType() != cmState::STATIC_LIBRARY)
     {
     libCleanFiles.push_back(
       this->Convert((targetFullPath+".manifest").c_str(),
@@ -440,10 +441,10 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
   std::vector<std::string> commands1;
   // Add a command to remove any existing files for this library.
   // for static libs only
-  if(this->Target->GetType() == cmTarget::STATIC_LIBRARY)
+  if(this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY)
     {
     this->LocalGenerator->AppendCleanCommand(commands1, libCleanFiles,
-                                             *this->Target, "target");
+                                             this->GeneratorTarget, "target");
     this->LocalGenerator->CreateCDCommand
       (commands1,
        this->Makefile->GetCurrentBinaryDirectory(),
@@ -456,11 +457,13 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
   if(!relink)
     {
     this->LocalGenerator
-      ->AppendCustomCommands(commands, this->Target->GetPreBuildCommands(),
-                             this->Target);
+      ->AppendCustomCommands(commands,
+                        this->GeneratorTarget->GetPreBuildCommands(),
+                        this->GeneratorTarget);
     this->LocalGenerator
-      ->AppendCustomCommands(commands, this->Target->GetPreLinkCommands(),
-                             this->Target);
+      ->AppendCustomCommands(commands,
+                        this->GeneratorTarget->GetPreLinkCommands(),
+                        this->GeneratorTarget);
     }
 
   // Determine whether a link script will be used.
@@ -496,7 +499,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
   std::vector<std::string> archiveAppendCommands;
   std::vector<std::string> archiveFinishCommands;
   std::string::size_type archiveCommandLimit = std::string::npos;
-  if(this->Target->GetType() == cmTarget::STATIC_LIBRARY)
+  if(this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY)
     {
     haveStaticLibraryRule =
       this->Makefile->GetDefinition(linkRuleVar)? true:false;
@@ -551,7 +554,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
 
   // Collect up flags to link in needed libraries.
   std::string linkLibs;
-  if(this->Target->GetType() != cmTarget::STATIC_LIBRARY)
+  if(this->GeneratorTarget->GetType() != cmState::STATIC_LIBRARY)
     {
     this->CreateLinkLibs(linkLibs, relink, useResponseFileForLibs, depends,
                          useWatcomQuote);
@@ -565,15 +568,15 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
                           useWatcomQuote);
 
   // maybe create .def file from list of objects
-  if (this->Target->GetType() == cmTarget::SHARED_LIBRARY &&
+  if (this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY &&
       this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS"))
     {
-    if(this->Target->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
+    if(this->GeneratorTarget->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
       {
       std::string name_of_def_file =
-        this->Target->GetSupportDirectory();
+        this->GeneratorTarget->GetSupportDirectory();
       name_of_def_file += std::string("/") +
-        this->Target->GetName();
+        this->GeneratorTarget->GetName();
       name_of_def_file += ".def";
       std::string cmd = cmSystemTools::GetCMakeCommand();
       cmd = this->Convert(cmd, cmLocalGenerator::NONE,
@@ -629,7 +632,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
   std::ostringstream minorStream;
   int major;
   int minor;
-  this->Target->GetTargetVersion(major, minor);
+  this->GeneratorTarget->GetTargetVersion(major, minor);
   majorStream << major;
   minorStream << minor;
   targetVersionMajor = majorStream.str();
@@ -639,10 +642,10 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
   vars.TargetVersionMinor = targetVersionMinor.c_str();
 
   vars.RuleLauncher = "RULE_LAUNCH_LINK";
-  vars.CMTarget = this->Target;
+  vars.CMTarget = this->GeneratorTarget;
   vars.Language = linkLanguage.c_str();
   vars.Objects = buildObjs.c_str();
-  std::string objectDir = this->Target->GetSupportDirectory();
+  std::string objectDir = this->GeneratorTarget->GetSupportDirectory();
   objectDir = this->Convert(objectDir,
                             cmLocalGenerator::START_OUTPUT,
                             cmLocalGenerator::SHELL);
@@ -666,7 +669,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
 
   // Compute the directory portion of the install_name setting.
   std::string install_name_dir;
-  if(this->Target->GetType() == cmTarget::SHARED_LIBRARY)
+  if(this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY)
     {
     // Get the install_name directory for the build tree.
     install_name_dir =
@@ -790,7 +793,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
 
   // Add a rule to create necessary symlinks for the library.
   // Frameworks are handled by cmOSXBundleGenerator.
-  if(targetOutPath != targetOutPathReal && !this->Target->IsFrameworkOnApple())
+  if(targetOutPath != targetOutPathReal
+     && !this->GeneratorTarget->IsFrameworkOnApple())
     {
     std::string symlink = "$(CMAKE_COMMAND) -E cmake_symlink_library ";
     symlink += targetOutPathReal;
@@ -809,8 +813,9 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
   if(!relink)
     {
     this->LocalGenerator->
-      AppendCustomCommands(commands, this->Target->GetPostBuildCommands(),
-                           this->Target);
+      AppendCustomCommands(commands,
+                       this->GeneratorTarget->GetPostBuildCommands(),
+                       this->GeneratorTarget);
     }
 
   // Compute the list of outputs.
@@ -861,7 +866,7 @@ cmMakefileLibraryTargetGenerator
   int major;
   int minor;
   int patch;
-  this->Target->GetTargetVersion(so, major, minor, patch);
+  this->GeneratorTarget->GetTargetVersion(so, major, minor, patch);
   if(major > 0 || minor > 0 || patch > 0)
     {
     // Append the flag since a non-zero version is specified.
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index b278087..eedc6ab 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -18,7 +18,6 @@
 #include "cmLocalUnixMakefileGenerator3.h"
 #include "cmMakefile.h"
 #include "cmSourceFile.h"
-#include "cmTarget.h"
 #include "cmake.h"
 #include "cmState.h"
 #include "cmComputeLinkInformation.h"
@@ -68,16 +67,16 @@ cmMakefileTargetGenerator::New(cmGeneratorTarget *tgt)
 
   switch (tgt->GetType())
     {
-    case cmTarget::EXECUTABLE:
+    case cmState::EXECUTABLE:
       result = new cmMakefileExecutableTargetGenerator(tgt);
       break;
-    case cmTarget::STATIC_LIBRARY:
-    case cmTarget::SHARED_LIBRARY:
-    case cmTarget::MODULE_LIBRARY:
-    case cmTarget::OBJECT_LIBRARY:
+    case cmState::STATIC_LIBRARY:
+    case cmState::SHARED_LIBRARY:
+    case cmState::MODULE_LIBRARY:
+    case cmState::OBJECT_LIBRARY:
       result = new cmMakefileLibraryTargetGenerator(tgt);
       break;
-    case cmTarget::UTILITY:
+    case cmState::UTILITY:
       result = new cmMakefileUtilityTargetGenerator(tgt);
       break;
     default:
@@ -92,7 +91,7 @@ void cmMakefileTargetGenerator::CreateRuleFile()
 {
   // Create a directory for this target.
   this->TargetBuildDirectory =
-    this->LocalGenerator->GetTargetDirectory(*this->Target);
+    this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
   this->TargetBuildDirectoryFull =
     this->LocalGenerator->ConvertToFullPath(this->TargetBuildDirectory);
   cmSystemTools::MakeDirectory(this->TargetBuildDirectoryFull.c_str());
@@ -147,8 +146,11 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
     cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
                                             ge.Parse(additional_clean_files);
 
-    cmSystemTools::ExpandListArgument(cge->Evaluate(this->Makefile, config,
-                                                  false, this->Target, 0, 0),
+    cmSystemTools::ExpandListArgument(cge->Evaluate(this->LocalGenerator,
+                                                    config,
+                                                    false,
+                                                    this->GeneratorTarget,
+                                                    0, 0),
                                       this->CleanFiles);
     }
 
@@ -245,7 +247,8 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules()
     // Write an empty dependency file.
     cmGeneratedFileStream depFileStream(dependFileNameFull.c_str());
     depFileStream
-      << "# Empty dependencies file for " << this->Target->GetName() << ".\n"
+      << "# Empty dependencies file for "
+      << this->GeneratorTarget->GetName() << ".\n"
       << "# This may be replaced when dependencies are built." << std::endl;
     }
 
@@ -375,7 +378,8 @@ void cmMakefileTargetGenerator
   // Get the full path name of the object file.
   std::string const& objectName = this->GeneratorTarget
                                       ->GetObjectName(&source);
-  std::string obj = this->LocalGenerator->GetTargetDirectory(*this->Target);
+  std::string obj =
+      this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
   obj += "/";
   obj += objectName;
 
@@ -390,7 +394,7 @@ void cmMakefileTargetGenerator
     err << "Warning: Source file \""
         << source.GetFullPath()
         << "\" is listed multiple times for target \""
-        << this->Target->GetName()
+        << this->GeneratorTarget->GetName()
         << "\".";
     cmSystemTools::Message(err.str().c_str(), "Warning");
     return;
@@ -419,7 +423,7 @@ void cmMakefileTargetGenerator
   this->WriteObjectBuildFile(obj, lang, source, depends);
 
   // The object file should be checked for dependency integrity.
-  std::string objFullPath = this->Makefile->GetCurrentBinaryDirectory();
+  std::string objFullPath = this->LocalGenerator->GetCurrentBinaryDirectory();
   objFullPath += "/";
   objFullPath += obj;
   objFullPath =
@@ -427,7 +431,7 @@ void cmMakefileTargetGenerator
   std::string srcFullPath =
     this->Convert(source.GetFullPath(), cmLocalGenerator::FULL);
   this->LocalGenerator->
-    AddImplicitDepends(*this->Target, lang,
+    AddImplicitDepends(this->GeneratorTarget, lang,
                        objFullPath.c_str(),
                        srcFullPath.c_str());
 }
@@ -539,24 +543,26 @@ cmMakefileTargetGenerator
   std::string targetFullPathReal;
   std::string targetFullPathPDB;
   std::string targetFullPathCompilePDB;
-  if(this->Target->GetType() == cmTarget::EXECUTABLE ||
-     this->Target->GetType() == cmTarget::STATIC_LIBRARY ||
-     this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
-     this->Target->GetType() == cmTarget::MODULE_LIBRARY)
+  if(this->GeneratorTarget->GetType() == cmState::EXECUTABLE ||
+     this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY ||
+     this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
+     this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY)
     {
     targetFullPathReal =
       this->GeneratorTarget->GetFullPath(this->ConfigName, false, true);
-    targetFullPathPDB = this->Target->GetPDBDirectory(this->ConfigName);
+    targetFullPathPDB =
+        this->GeneratorTarget->GetPDBDirectory(this->ConfigName);
     targetFullPathPDB += "/";
     targetFullPathPDB += this->GeneratorTarget->GetPDBName(this->ConfigName);
     }
-  if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
+  if(this->GeneratorTarget->GetType() <= cmState::OBJECT_LIBRARY)
     {
     targetFullPathCompilePDB =
       this->GeneratorTarget->GetCompilePDBPath(this->ConfigName);
     if(targetFullPathCompilePDB.empty())
       {
-      targetFullPathCompilePDB = this->Target->GetSupportDirectory() + "/";
+      targetFullPathCompilePDB =
+          this->GeneratorTarget->GetSupportDirectory() + "/";
       }
     }
 
@@ -582,7 +588,7 @@ cmMakefileTargetGenerator
   }
   cmLocalGenerator::RuleVariables vars;
   vars.RuleLauncher = "RULE_LAUNCH_COMPILE";
-  vars.CMTarget = this->Target;
+  vars.CMTarget = this->GeneratorTarget;
   vars.Language = lang.c_str();
   vars.Target = targetOutPathReal.c_str();
   vars.TargetPDB = targetOutPathPDB.c_str();
@@ -593,7 +599,7 @@ cmMakefileTargetGenerator
                   cmLocalGenerator::NONE,
                   cmLocalGenerator::SHELL);
   vars.Object = shellObj.c_str();
-  std::string objectDir = this->Target->GetSupportDirectory();
+  std::string objectDir = this->GeneratorTarget->GetSupportDirectory();
   objectDir = this->Convert(objectDir,
                             cmLocalGenerator::START_OUTPUT,
                             cmLocalGenerator::SHELL);
@@ -642,7 +648,8 @@ cmMakefileTargetGenerator
     this->LocalGenerator->ExpandRuleVariables(compileCommand, vars);
     std::string workingDirectory =
       this->LocalGenerator->Convert(
-        this->Makefile->GetCurrentBinaryDirectory(), cmLocalGenerator::FULL);
+        this->LocalGenerator->GetCurrentBinaryDirectory(),
+                                    cmLocalGenerator::FULL);
     compileCommand.replace(compileCommand.find(langFlags),
                            langFlags.size(), this->GetFlags(lang));
     std::string langDefines = std::string("$(") + lang + "_DEFINES)";
@@ -659,7 +666,7 @@ cmMakefileTargetGenerator
   if (!compileCommands.empty() && (lang == "C" || lang == "CXX"))
     {
     std::string const iwyu_prop = lang + "_INCLUDE_WHAT_YOU_USE";
-    const char *iwyu = this->Target->GetProperty(iwyu_prop);
+    const char *iwyu = this->GeneratorTarget->GetProperty(iwyu_prop);
     if (iwyu && *iwyu)
       {
       std::string run_iwyu = "$(CMAKE_COMMAND) -E __run_iwyu --iwyu=";
@@ -673,7 +680,7 @@ cmMakefileTargetGenerator
   if (!compileCommands.empty() && (lang == "C" || lang == "CXX"))
     {
     std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER";
-    const char *clauncher = this->Target->GetProperty(clauncher_prop);
+    const char *clauncher = this->GeneratorTarget->GetProperty(clauncher_prop);
     if (clauncher && *clauncher)
       {
       std::vector<std::string> launcher_cmd;
@@ -698,7 +705,7 @@ cmMakefileTargetGenerator
   // Change the command working directory to the local build tree.
   this->LocalGenerator->CreateCDCommand
     (compileCommands,
-     this->Makefile->GetCurrentBinaryDirectory(),
+     this->LocalGenerator->GetCurrentBinaryDirectory(),
      cmLocalGenerator::HOME_OUTPUT);
   commands.insert(commands.end(),
                   compileCommands.begin(), compileCommands.end());
@@ -771,7 +778,7 @@ cmMakefileTargetGenerator
 
         this->LocalGenerator->CreateCDCommand
           (preprocessCommands,
-           this->Makefile->GetCurrentBinaryDirectory(),
+           this->LocalGenerator->GetCurrentBinaryDirectory(),
            cmLocalGenerator::HOME_OUTPUT);
         commands.insert(commands.end(),
                         preprocessCommands.begin(),
@@ -828,7 +835,7 @@ cmMakefileTargetGenerator
 
         this->LocalGenerator->CreateCDCommand
           (assemblyCommands,
-           this->Makefile->GetCurrentBinaryDirectory(),
+           this->LocalGenerator->GetCurrentBinaryDirectory(),
            cmLocalGenerator::HOME_OUTPUT);
         commands.insert(commands.end(),
                         assemblyCommands.begin(),
@@ -864,7 +871,7 @@ cmMakefileTargetGenerator
   temp += ".provides.build";
   std::vector<std::string> r_commands;
   std::string tgtMakefileName =
-    this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
+    this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
   tgtMakefileName += "/build.make";
   r_commands.push_back
     (this->LocalGenerator->GetRecursiveMakeCall(tgtMakefileName.c_str(),
@@ -892,7 +899,7 @@ void cmMakefileTargetGenerator::WriteTargetRequiresRules()
 
   // Construct the name of the dependency generation target.
   std::string depTarget =
-    this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
+    this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
   depTarget += "/requires";
 
   // This target drives dependency generation for all object files.
@@ -921,15 +928,15 @@ void cmMakefileTargetGenerator::WriteTargetCleanRules()
 
   // Construct the clean target name.
   std::string cleanTarget =
-    this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
+    this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
   cleanTarget += "/clean";
 
   // Construct the clean command.
   this->LocalGenerator->AppendCleanCommand(commands, this->CleanFiles,
-                                           *this->Target);
+                                           this->GeneratorTarget);
   this->LocalGenerator->CreateCDCommand
     (commands,
-     this->Makefile->GetCurrentBinaryDirectory(),
+     this->LocalGenerator->GetCurrentBinaryDirectory(),
      cmLocalGenerator::HOME_OUTPUT);
 
   // Write the rule.
@@ -1018,7 +1025,8 @@ bool cmMakefileTargetGenerator::WriteMakeRule(
 void cmMakefileTargetGenerator::WriteTargetDependRules()
 {
   // must write the targets depend info file
-  std::string dir = this->LocalGenerator->GetTargetDirectory(*this->Target);
+  std::string dir =
+      this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
   this->InfoFileNameFull = dir;
   this->InfoFileNameFull += "/DependInfo.cmake";
   this->InfoFileNameFull =
@@ -1031,7 +1039,7 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
     return;
     }
   this->LocalGenerator->
-    WriteDependLanguageInfo(*this->InfoFileStream,*this->Target);
+    WriteDependLanguageInfo(*this->InfoFileStream, this->GeneratorTarget);
 
   // Store multiple output pairs in the depend info file.
   if(!this->MultipleOutputPairs.empty())
@@ -1080,7 +1088,7 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
 
   // Construct the name of the dependency generation target.
   std::string depTarget =
-    this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
+    this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
   depTarget += "/depend";
 
   // Add a command to call CMake to scan dependencies.  CMake will
@@ -1095,7 +1103,7 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
   // translation table for the dependency scanning process.
   depCmd << "cd "
          << (this->LocalGenerator->Convert(
-               this->Makefile->GetHomeOutputDirectory(),
+               this->LocalGenerator->GetBinaryDirectory(),
                cmLocalGenerator::FULL, cmLocalGenerator::SHELL))
          << " && ";
 #endif
@@ -1110,16 +1118,16 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
   // the state of our local generator sufficiently for its needs.
   depCmd << "$(CMAKE_COMMAND) -E cmake_depends \""
          << this->GlobalGenerator->GetName() << "\" "
-         << this->Convert(this->Makefile->GetHomeDirectory(),
+         << this->Convert(this->LocalGenerator->GetSourceDirectory(),
                           cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
          << " "
-         << this->Convert(this->Makefile->GetCurrentSourceDirectory(),
+         << this->Convert(this->LocalGenerator->GetCurrentSourceDirectory(),
                           cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
          << " "
-         << this->Convert(this->Makefile->GetHomeOutputDirectory(),
+         << this->Convert(this->LocalGenerator->GetBinaryDirectory(),
                           cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
          << " "
-         << this->Convert(this->Makefile->GetCurrentBinaryDirectory(),
+         << this->Convert(this->LocalGenerator->GetCurrentBinaryDirectory(),
                           cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
          << " "
          << this->Convert(this->InfoFileNameFull,
@@ -1149,7 +1157,7 @@ cmMakefileTargetGenerator
 {
   // Depend on all custom command outputs.
   std::vector<cmSourceFile*> sources;
-  this->Target->GetSourceFiles(sources,
+  this->GeneratorTarget->GetSourceFiles(sources,
                       this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
   for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
       source != sources.end(); ++source)
@@ -1202,7 +1210,8 @@ void cmMakefileTargetGenerator
 
   // Now append the actual user-specified commands.
   std::ostringstream content;
-  this->LocalGenerator->AppendCustomCommand(commands, ccg, this->Target, false,
+  this->LocalGenerator->AppendCustomCommand(commands, ccg,
+                                            this->GeneratorTarget, false,
                                             cmLocalGenerator::HOME_OUTPUT,
                                             &content);
 
@@ -1231,7 +1240,7 @@ void cmMakefileTargetGenerator
     std::string srcFullPath =
       this->Convert(idi->second, cmLocalGenerator::FULL);
     this->LocalGenerator->
-      AddImplicitDepends(*this->Target, idi->first,
+      AddImplicitDepends(this->GeneratorTarget, idi->first,
                          objFullPath.c_str(),
                          srcFullPath.c_str());
     }
@@ -1242,7 +1251,7 @@ void
 cmMakefileTargetGenerator
 ::MakeEchoProgress(cmLocalUnixMakefileGenerator3::EchoProgress& progress) const
 {
-  progress.Dir = this->Makefile->GetHomeOutputDirectory();
+  progress.Dir = this->LocalGenerator->GetBinaryDirectory();
   progress.Dir += cmake::GetCMakeFilesDirectory();
   std::ostringstream progressArg;
   progressArg << "$(CMAKE_PROGRESS_" << this->NumberOfProgressActions << ")";
@@ -1259,10 +1268,10 @@ cmMakefileTargetGenerator
   // Write a make variable assignment that lists all objects for the
   // target.
   variableName =
-    this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
+    this->LocalGenerator->CreateMakeVariable(this->GeneratorTarget->GetName(),
                                              "_OBJECTS");
   *this->BuildFileStream
-    << "# Object files for target " << this->Target->GetName() << "\n"
+    << "# Object files for target " << this->GeneratorTarget->GetName() << "\n"
     << variableName << " =";
   std::string object;
   const char* lineContinue =
@@ -1284,12 +1293,12 @@ cmMakefileTargetGenerator
   // Write a make variable assignment that lists all external objects
   // for the target.
   variableNameExternal =
-    this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
+    this->LocalGenerator->CreateMakeVariable(this->GeneratorTarget->GetName(),
                                              "_EXTERNAL_OBJECTS");
   *this->BuildFileStream
     << "\n"
     << "# External object files for target "
-    << this->Target->GetName() << "\n"
+    << this->GeneratorTarget->GetName() << "\n"
     << variableNameExternal << " =";
   for(std::vector<std::string>::const_iterator i =
         this->ExternalObjects.begin();
@@ -1394,7 +1403,7 @@ void cmMakefileTargetGenerator::WriteTargetDriverRule(
 {
   // Compute the name of the driver target.
   std::string dir =
-    this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
+    this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
   std::string buildTargetRuleName = dir;
   buildTargetRuleName += relink?"/preinstall":"/build";
   buildTargetRuleName = this->Convert(buildTargetRuleName,
@@ -1439,7 +1448,7 @@ void cmMakefileTargetGenerator
 ::AppendTargetDepends(std::vector<std::string>& depends)
 {
   // Static libraries never depend on anything for linking.
-  if(this->Target->GetType() == cmTarget::STATIC_LIBRARY)
+  if(this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY)
     {
     return;
     }
@@ -1488,9 +1497,9 @@ void cmMakefileTargetGenerator
   this->AppendTargetDepends(depends);
 
   // Add a dependency on the link definitions file, if any.
-  if(!this->ModuleDefinitionFile.empty())
+  if(this->ModuleDefinitionFile)
     {
-    depends.push_back(this->ModuleDefinitionFile);
+    depends.push_back(this->ModuleDefinitionFile->GetFullPath());
     }
 
   // Add a dependency on user-specified manifest files, if any.
@@ -1504,7 +1513,7 @@ void cmMakefileTargetGenerator
 
   // Add user-specified dependencies.
   if(const char* linkDepends =
-     this->Target->GetProperty("LINK_DEPENDS"))
+     this->GeneratorTarget->GetProperty("LINK_DEPENDS"))
     {
     cmSystemTools::ExpandListArgument(linkDepends, depends);
     }
@@ -1515,7 +1524,7 @@ std::string cmMakefileTargetGenerator::GetLinkRule(
                                               const std::string& linkRuleVar)
 {
   std::string linkRule = this->Makefile->GetRequiredDefinition(linkRuleVar);
-  if(this->Target->HasImplibGNUtoMS())
+  if(this->GeneratorTarget->HasImplibGNUtoMS())
     {
     std::string ruleVar = "CMAKE_";
     ruleVar += this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h
index fd4527b..38f40c0 100644
--- a/Source/cmMakefileTargetGenerator.h
+++ b/Source/cmMakefileTargetGenerator.h
@@ -18,14 +18,12 @@
 #include "cmOSXBundleGenerator.h"
 
 class cmCustomCommandGenerator;
-class cmDependInformation;
 class cmDepends;
 class cmGeneratorTarget;
 class cmGeneratedFileStream;
 class cmGlobalUnixMakefileGenerator3;
 class cmLocalUnixMakefileGenerator3;
 class cmMakefile;
-class cmTarget;
 class cmSourceFile;
 
 /** \class cmMakefileTargetGenerator
@@ -52,7 +50,6 @@ public:
   std::string GetProgressFileNameFull()
     { return this->ProgressFileNameFull; }
 
-  cmTarget* GetTarget() { return this->Target;}
   cmGeneratorTarget* GetGeneratorTarget() { return this->GeneratorTarget;}
 
 protected:
diff --git a/Source/cmMakefileUtilityTargetGenerator.cxx b/Source/cmMakefileUtilityTargetGenerator.cxx
index 303ca63..5b62cbf 100644
--- a/Source/cmMakefileUtilityTargetGenerator.cxx
+++ b/Source/cmMakefileUtilityTargetGenerator.cxx
@@ -16,7 +16,6 @@
 #include "cmLocalUnixMakefileGenerator3.h"
 #include "cmMakefile.h"
 #include "cmSourceFile.h"
-#include "cmTarget.h"
 
 //----------------------------------------------------------------------------
 cmMakefileUtilityTargetGenerator
@@ -42,7 +41,8 @@ void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
   this->CreateRuleFile();
 
   *this->BuildFileStream
-    << "# Utility rule file for " << this->Target->GetName() << ".\n\n";
+    << "# Utility rule file for "
+    << this->GeneratorTarget->GetName() << ".\n\n";
 
   if(!this->NoRuleMessages)
     {
@@ -67,19 +67,21 @@ void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
 
   // Utility targets store their rules in pre- and post-build commands.
   this->LocalGenerator->AppendCustomDepends
-    (depends, this->Target->GetPreBuildCommands());
+    (depends, this->GeneratorTarget->GetPreBuildCommands());
 
   this->LocalGenerator->AppendCustomDepends
-    (depends, this->Target->GetPostBuildCommands());
+    (depends, this->GeneratorTarget->GetPostBuildCommands());
 
   this->LocalGenerator->AppendCustomCommands
-    (commands, this->Target->GetPreBuildCommands(), this->Target);
+    (commands, this->GeneratorTarget->GetPreBuildCommands(),
+     this->GeneratorTarget);
 
   // Depend on all custom command outputs for sources
   this->DriveCustomCommands(depends);
 
   this->LocalGenerator->AppendCustomCommands
-    (commands, this->Target->GetPostBuildCommands(), this->Target);
+    (commands, this->GeneratorTarget->GetPostBuildCommands(),
+     this->GeneratorTarget);
 
   // Add dependencies on targets that must be built first.
   this->AppendTargetDepends(depends);
@@ -101,11 +103,11 @@ void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
 
   // Write the rule.
   this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
-                                      this->Target->GetName(),
+                                      this->GeneratorTarget->GetName(),
                                       depends, commands, true);
 
   // Write the main driver rule to build everything in this target.
-  this->WriteTargetDriverRule(this->Target->GetName(), false);
+  this->WriteTargetDriverRule(this->GeneratorTarget->GetName(), false);
 
   // Write clean target
   this->WriteTargetCleanRules();
diff --git a/Source/cmMarkAsAdvancedCommand.cxx b/Source/cmMarkAsAdvancedCommand.cxx
index 10d30f3..8d0e2b3 100644
--- a/Source/cmMarkAsAdvancedCommand.cxx
+++ b/Source/cmMarkAsAdvancedCommand.cxx
@@ -39,7 +39,8 @@ bool cmMarkAsAdvancedCommand
     cmState* state = this->Makefile->GetState();
     if (!state->GetCacheEntryValue(variable))
       {
-      state->AddCacheEntry(variable, 0, 0, cmState::UNINITIALIZED);
+      this->Makefile->GetCMakeInstance()->AddCacheEntry(
+              variable, 0, 0, cmState::UNINITIALIZED);
       overwrite = true;
       }
     if (!state->GetCacheEntryValue(variable))
diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx
index 2854a82..1c67cea 100644
--- a/Source/cmMessageCommand.cxx
+++ b/Source/cmMessageCommand.cxx
@@ -25,6 +25,7 @@ bool cmMessageCommand
   cmake::MessageType type = cmake::MESSAGE;
   bool status = false;
   bool fatal = false;
+  cmake* cm = this->Makefile->GetCMakeInstance();
   if (*i == "SEND_ERROR")
     {
     type = cmake::FATAL_ERROR;
@@ -43,7 +44,19 @@ bool cmMessageCommand
     }
   else if (*i == "AUTHOR_WARNING")
     {
-    type = cmake::AUTHOR_WARNING;
+    if (cm->GetDevWarningsAsErrors(this->Makefile))
+      {
+      fatal = true;
+      type = cmake::AUTHOR_ERROR;
+      }
+    else if (!cm->GetSuppressDevWarnings(this->Makefile))
+      {
+      type = cmake::AUTHOR_WARNING;
+      }
+    else
+      {
+      return true;
+      }
     ++i;
     }
   else if (*i == "STATUS")
@@ -53,12 +66,12 @@ bool cmMessageCommand
     }
   else if (*i == "DEPRECATION")
     {
-    if (this->Makefile->IsOn("CMAKE_ERROR_DEPRECATED"))
+    if (cm->GetDeprecatedWarningsAsErrors(this->Makefile))
       {
       fatal = true;
       type = cmake::DEPRECATION_ERROR;
       }
-    else if (this->Makefile->IsOn("CMAKE_WARN_DEPRECATED"))
+    else if (!cm->GetSuppressDeprecatedWarnings(this->Makefile))
       {
       type = cmake::DEPRECATION_WARNING;
       }
@@ -73,7 +86,8 @@ bool cmMessageCommand
 
   if (type != cmake::MESSAGE)
     {
-    this->Makefile->IssueMessage(type, message);
+    // we've overriden the message type, above, so force IssueMessage to use it
+    this->Makefile->IssueMessage(type, message, true);
     }
   else
     {
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 84c19a3..17561b5 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -41,7 +41,7 @@ cmNinjaNormalTargetGenerator(cmGeneratorTarget* target)
   , TargetLinkLanguage("")
 {
   this->TargetLinkLanguage = target->GetLinkerLanguage(this->GetConfigName());
-  if (target->GetType() == cmTarget::EXECUTABLE)
+  if (target->GetType() == cmState::EXECUTABLE)
     this->GetGeneratorTarget()->GetExecutableNames(this->TargetNameOut,
                                this->TargetNameReal,
                                this->TargetNameImport,
@@ -55,11 +55,11 @@ cmNinjaNormalTargetGenerator(cmGeneratorTarget* target)
                             this->TargetNamePDB,
                             GetLocalGenerator()->GetConfigName());
 
-  if(target->GetType() != cmTarget::OBJECT_LIBRARY)
+  if(target->GetType() != cmState::OBJECT_LIBRARY)
     {
     // on Windows the output dir is already needed at compile time
     // ensure the directory exists (OutDir test)
-    EnsureDirectoryExists(target->Target->GetDirectory(this->GetConfigName()));
+    EnsureDirectoryExists(target->GetDirectory(this->GetConfigName()));
     }
 
   this->OSXBundleGenerator = new cmOSXBundleGenerator(target,
@@ -77,7 +77,7 @@ void cmNinjaNormalTargetGenerator::Generate()
   if (this->TargetLinkLanguage.empty()) {
     cmSystemTools::Error("CMake can not determine linker language for "
                          "target: ",
-                         this->GetTarget()->GetName().c_str());
+                         this->GetGeneratorTarget()->GetName().c_str());
     return;
   }
 
@@ -87,7 +87,7 @@ void cmNinjaNormalTargetGenerator::Generate()
   // Write the build statements
   this->WriteObjectBuildStatements();
 
-  if(this->GetTarget()->GetType() == cmTarget::OBJECT_LIBRARY)
+  if(this->GetGeneratorTarget()->GetType() == cmState::OBJECT_LIBRARY)
     {
     this->WriteObjectLibStatement();
     }
@@ -103,7 +103,7 @@ void cmNinjaNormalTargetGenerator::WriteLanguagesRules()
   cmGlobalNinjaGenerator::WriteDivider(this->GetRulesFileStream());
   this->GetRulesFileStream()
     << "# Rules for each languages for "
-    << cmTarget::GetTargetTypeName(this->GetTarget()->GetType())
+    << cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType())
     << " target "
     << this->GetTargetName()
     << "\n\n";
@@ -112,7 +112,7 @@ void cmNinjaNormalTargetGenerator::WriteLanguagesRules()
   // Write rules for languages compiled in this target.
   std::set<std::string> languages;
   std::vector<cmSourceFile*> sourceFiles;
-  this->GetTarget()->GetSourceFiles(sourceFiles,
+  this->GetGeneratorTarget()->GetSourceFiles(sourceFiles,
     this->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE"));
   for(std::vector<cmSourceFile*>::const_iterator
         i = sourceFiles.begin(); i != sourceFiles.end(); ++i)
@@ -133,17 +133,17 @@ void cmNinjaNormalTargetGenerator::WriteLanguagesRules()
 
 const char *cmNinjaNormalTargetGenerator::GetVisibleTypeName() const
 {
-  switch (this->GetTarget()->GetType()) {
-    case cmTarget::STATIC_LIBRARY:
+  switch (this->GetGeneratorTarget()->GetType()) {
+    case cmState::STATIC_LIBRARY:
       return "static library";
-    case cmTarget::SHARED_LIBRARY:
+    case cmState::SHARED_LIBRARY:
       return "shared library";
-    case cmTarget::MODULE_LIBRARY:
-      if (this->GetTarget()->IsCFBundleOnApple())
+    case cmState::MODULE_LIBRARY:
+      if (this->GetGeneratorTarget()->IsCFBundleOnApple())
         return "CFBundle shared module";
       else
         return "shared module";
-    case cmTarget::EXECUTABLE:
+    case cmState::EXECUTABLE:
       return "executable";
     default:
       return 0;
@@ -156,9 +156,10 @@ cmNinjaNormalTargetGenerator
 {
   return this->TargetLinkLanguage
     + "_"
-    + cmTarget::GetTargetTypeName(this->GetTarget()->GetType())
+    + cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType())
     + "_LINKER__"
-    + cmGlobalNinjaGenerator::EncodeRuleName(this->GetTarget()->GetName())
+    + cmGlobalNinjaGenerator::EncodeRuleName(
+        this->GetGeneratorTarget()->GetName())
     ;
 }
 
@@ -166,7 +167,8 @@ void
 cmNinjaNormalTargetGenerator
 ::WriteLinkRule(bool useResponseFile)
 {
-  cmTarget::TargetType targetType = this->GetTarget()->GetType();
+  cmState::TargetType targetType =
+      this->GetGeneratorTarget()->GetType();
   std::string ruleName = this->LanguageLinkerRule();
 
   // Select whether to use a response file for objects.
@@ -176,7 +178,7 @@ cmNinjaNormalTargetGenerator
   if (!this->GetGlobalGenerator()->HasRule(ruleName)) {
     cmLocalGenerator::RuleVariables vars;
     vars.RuleLauncher = "RULE_LAUNCH_LINK";
-    vars.CMTarget = this->GetTarget();
+    vars.CMTarget = this->GetGeneratorTarget();
     vars.Language = this->TargetLinkLanguage.c_str();
 
     std::string responseFlag;
@@ -226,7 +228,7 @@ cmNinjaNormalTargetGenerator
     std::ostringstream minorStream;
     int major;
     int minor;
-    this->GetTarget()->GetTargetVersion(major, minor);
+    this->GetGeneratorTarget()->GetTargetVersion(major, minor);
     majorStream << major;
     minorStream << minor;
     targetVersionMajor = majorStream.str();
@@ -240,7 +242,7 @@ cmNinjaNormalTargetGenerator
     vars.Manifests = "$MANIFESTS";
 
     std::string langFlags;
-    if (targetType != cmTarget::EXECUTABLE)
+    if (targetType != cmState::EXECUTABLE)
       {
       langFlags += "$LANGUAGE_COMPILE_FLAGS $ARCH_FLAGS";
       vars.LanguageCompileFlags = langFlags.c_str();
@@ -279,11 +281,11 @@ cmNinjaNormalTargetGenerator
   }
 
   if (this->TargetNameOut != this->TargetNameReal &&
-    !this->GetTarget()->IsFrameworkOnApple()) {
+    !this->GetGeneratorTarget()->IsFrameworkOnApple()) {
     std::string cmakeCommand =
       this->GetLocalGenerator()->ConvertToOutputFormat(
         cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
-    if (targetType == cmTarget::EXECUTABLE)
+    if (targetType == cmState::EXECUTABLE)
       this->GetGlobalGenerator()->AddRule("CMAKE_SYMLINK_EXECUTABLE",
                                           cmakeCommand +
                                           " -E cmake_symlink_executable"
@@ -330,8 +332,8 @@ cmNinjaNormalTargetGenerator
     return linkCmds;
     }
   }
-  switch (this->GetTarget()->GetType()) {
-    case cmTarget::STATIC_LIBRARY: {
+  switch (this->GetGeneratorTarget()->GetType()) {
+    case cmState::STATIC_LIBRARY: {
       // We have archive link commands set. First, delete the existing archive.
       {
       std::string cmakeCommand =
@@ -356,9 +358,9 @@ cmNinjaNormalTargetGenerator
       }
       return linkCmds;
     }
-    case cmTarget::SHARED_LIBRARY:
-    case cmTarget::MODULE_LIBRARY:
-    case cmTarget::EXECUTABLE:
+    case cmState::SHARED_LIBRARY:
+    case cmState::MODULE_LIBRARY:
+    case cmState::EXECUTABLE:
       break;
     default:
       assert(0 && "Unexpected target type");
@@ -397,7 +399,6 @@ static int calculateCommandLineLengthLimit(int linkRuleLength)
 
 void cmNinjaNormalTargetGenerator::WriteLinkStatement()
 {
-  cmTarget& target = *this->GetTarget();
   cmGeneratorTarget& gt = *this->GetGeneratorTarget();
   const std::string cfgName = this->GetConfigName();
   std::string targetOutput = ConvertToNinjaPath(
@@ -410,10 +411,10 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
                                      gt.GetFullPath(cfgName,
                                        /*implib=*/true));
 
-  if (target.IsAppBundleOnApple())
+  if (gt.IsAppBundleOnApple())
     {
     // Create the app bundle
-    std::string outpath = target.GetDirectory(cfgName);
+    std::string outpath = gt.GetDirectory(cfgName);
     this->OSXBundleGenerator->CreateAppBundle(this->TargetNameOut, outpath);
 
     // Calculate the output path
@@ -426,25 +427,25 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
     targetOutputReal += this->TargetNameReal;
     targetOutputReal = this->ConvertToNinjaPath(targetOutputReal);
     }
-  else if (target.IsFrameworkOnApple())
+  else if (gt.IsFrameworkOnApple())
     {
     // Create the library framework.
     this->OSXBundleGenerator->CreateFramework(this->TargetNameOut,
-                                              target.GetDirectory(cfgName));
+                                              gt.GetDirectory(cfgName));
     }
-  else if(target.IsCFBundleOnApple())
+  else if(gt.IsCFBundleOnApple())
     {
     // Create the core foundation bundle.
     this->OSXBundleGenerator->CreateCFBundle(this->TargetNameOut,
-                                             target.GetDirectory(cfgName));
+                                             gt.GetDirectory(cfgName));
     }
 
   // Write comments.
   cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
-  const cmTarget::TargetType targetType = target.GetType();
+  const cmState::TargetType targetType = gt.GetType();
   this->GetBuildFileStream()
     << "# Link build statements for "
-    << cmTarget::GetTargetTypeName(targetType)
+    << cmState::GetTargetTypeName(targetType)
     << " target "
     << this->GetTargetName()
     << "\n\n";
@@ -488,14 +489,13 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
                           &genTarget,
                           useWatcomQuote);
   if(this->GetMakefile()->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")
-     && target.GetType() == cmTarget::SHARED_LIBRARY)
+     && gt.GetType() == cmState::SHARED_LIBRARY)
     {
-    if(target.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
+    if(gt.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
       {
-      std::string dllname = targetOutput;
       std::string name_of_def_file
-        = target.GetSupportDirectory();
-      name_of_def_file += "/" + target.GetName();
+        = gt.GetSupportDirectory();
+      name_of_def_file += "/" + gt.GetName();
       name_of_def_file += ".def ";
       vars["LINK_FLAGS"] += " /DEF:";
       vars["LINK_FLAGS"] += this->GetLocalGenerator()
@@ -504,7 +504,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
       }
     }
 
-  this->addPoolNinjaVariable("JOB_POOL_LINK", &target, vars);
+  this->addPoolNinjaVariable("JOB_POOL_LINK", &gt, vars);
 
   this->AddModuleDefinitionFlag(vars["LINK_FLAGS"]);
   vars["LINK_FLAGS"] = cmGlobalNinjaGenerator
@@ -517,7 +517,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
   // Compute architecture specific link flags.  Yes, these go into a different
   // variable for executables, probably due to a mistake made when duplicating
   // code between the Makefile executable and library generators.
-  if (targetType == cmTarget::EXECUTABLE)
+  if (targetType == cmState::EXECUTABLE)
     {
     std::string t = vars["FLAGS"];
     localGen.AddArchitectureFlags(t, &genTarget, TargetLinkLanguage, cfgName);
@@ -537,7 +537,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
     {
     vars["SONAME_FLAG"] = mf->GetSONameFlag(this->TargetLinkLanguage);
     vars["SONAME"] = this->TargetNameSO;
-    if (targetType == cmTarget::SHARED_LIBRARY)
+    if (targetType == cmState::SHARED_LIBRARY)
       {
       std::string install_dir =
           this->GetGeneratorTarget()->GetInstallNameDirForBuildTree(cfgName);
@@ -559,7 +559,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
                                               cmLocalGenerator::SHELL);
     vars["TARGET_IMPLIB"] = impLibPath;
     EnsureParentDirectoryExists(impLibPath);
-    if(target.HasImportLibrary())
+    if(genTarget.HasImportLibrary())
       {
       byproducts.push_back(targetOutputImplib);
       }
@@ -582,7 +582,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
     vars["TARGET_PDB"] = base + suffix + dbg_suffix;
     }
 
-  const std::string objPath = GetTarget()->GetSupportDirectory();
+  const std::string objPath = GetGeneratorTarget()->GetSupportDirectory();
   vars["OBJECT_DIR"] =
     this->GetLocalGenerator()->ConvertToOutputFormat(
       this->ConvertToNinjaPath(objPath), cmLocalGenerator::SHELL);
@@ -598,9 +598,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
     }
 
   const std::vector<cmCustomCommand> *cmdLists[3] = {
-    &target.GetPreBuildCommands(),
-    &target.GetPreLinkCommands(),
-    &target.GetPostBuildCommands()
+    &gt.GetPreBuildCommands(),
+    &gt.GetPreLinkCommands(),
+    &gt.GetPostBuildCommands()
   };
 
   std::vector<std::string> preLinkCmdLines, postBuildCmdLines;
@@ -625,17 +625,17 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
     }
 
   // maybe create .def file from list of objects
-  if (target.GetType() == cmTarget::SHARED_LIBRARY &&
+  if (gt.GetType() == cmState::SHARED_LIBRARY &&
       this->GetMakefile()->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS"))
     {
-    if(target.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
+    if(gt.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
       {
       std::string cmakeCommand =
       this->GetLocalGenerator()->ConvertToOutputFormat(
         cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
       std::string name_of_def_file
-        = target.GetSupportDirectory();
-      name_of_def_file += "/" + target.GetName();
+        = gt.GetSupportDirectory();
+      name_of_def_file += "/" + gt.GetName();
       name_of_def_file += ".def";
       std::string cmd = cmakeCommand;
       cmd += " -E __create_def ";
@@ -666,8 +666,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
   if (!preLinkCmdLines.empty())
     {
     const std::string homeOutDir = localGen.ConvertToOutputFormat(
-                                              mf->GetHomeOutputDirectory(),
-                                              cmLocalGenerator::SHELL);
+                                            localGen.GetBinaryDirectory(),
+                                            cmLocalGenerator::SHELL);
     preLinkCmdLines.push_back("cd " + homeOutDir);
     }
 
@@ -698,11 +698,11 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
 
   const std::string rspfile =
       std::string(cmake::GetCMakeFilesDirectoryPostSlash())
-      + target.GetName() + ".rsp";
+      + gt.GetName() + ".rsp";
 
   // Gather order-only dependencies.
   cmNinjaDeps orderOnlyDeps;
-  this->GetLocalGenerator()->AppendTargetDepends(this->GetTarget(),
+  this->GetLocalGenerator()->AppendTargetDepends(this->GetGeneratorTarget(),
     orderOnlyDeps);
 
   // Ninja should restat after linking if and only if there are byproducts.
@@ -731,9 +731,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
                         &usedResponseFile);
   this->WriteLinkRule(usedResponseFile);
 
-  if (targetOutput != targetOutputReal && !target.IsFrameworkOnApple())
+  if (targetOutput != targetOutputReal && !gt.IsFrameworkOnApple())
     {
-    if (targetType == cmTarget::EXECUTABLE)
+    if (targetType == cmState::EXECUTABLE)
       {
       globalGen.WriteBuild(this->GetBuildFileStream(),
                             "Create executable symlink " + targetOutput,
@@ -771,8 +771,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
     }
 
   // Add aliases for the file name and the target name.
-  globalGen.AddTargetAlias(this->TargetNameOut, &target);
-  globalGen.AddTargetAlias(this->GetTargetName(), &target);
+  globalGen.AddTargetAlias(this->TargetNameOut, &gt);
+  globalGen.AddTargetAlias(this->GetTargetName(), &gt);
 }
 
 //----------------------------------------------------------------------------
@@ -780,7 +780,8 @@ void cmNinjaNormalTargetGenerator::WriteObjectLibStatement()
 {
   // Write a phony output that depends on all object files.
   cmNinjaDeps outputs;
-  this->GetLocalGenerator()->AppendTargetOutputs(this->GetTarget(), outputs);
+  this->GetLocalGenerator()->AppendTargetOutputs(this->GetGeneratorTarget(),
+                                                 outputs);
   cmNinjaDeps depends = this->GetObjects();
   this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
                                               "Object library "
@@ -790,5 +791,5 @@ void cmNinjaNormalTargetGenerator::WriteObjectLibStatement()
 
   // Add aliases for the target name.
   this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
-                                             this->GetTarget());
+                                             this->GetGeneratorTarget());
 }
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 6e6dc60..5ff4fdb 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -31,23 +31,22 @@ cmNinjaTargetGenerator::New(cmGeneratorTarget* target)
 {
   switch (target->GetType())
     {
-      case cmTarget::EXECUTABLE:
-      case cmTarget::SHARED_LIBRARY:
-      case cmTarget::STATIC_LIBRARY:
-      case cmTarget::MODULE_LIBRARY:
-      case cmTarget::OBJECT_LIBRARY:
+      case cmState::EXECUTABLE:
+      case cmState::SHARED_LIBRARY:
+      case cmState::STATIC_LIBRARY:
+      case cmState::MODULE_LIBRARY:
+      case cmState::OBJECT_LIBRARY:
         return new cmNinjaNormalTargetGenerator(target);
 
-      case cmTarget::UTILITY:
+      case cmState::UTILITY:
         return new cmNinjaUtilityTargetGenerator(target);;
 
-      case cmTarget::GLOBAL_TARGET: {
+      case cmState::GLOBAL_TARGET: {
         // We only want to process global targets that live in the home
         // (i.e. top-level) directory.  CMake creates copies of these targets
         // in every directory, which we don't need.
-        cmMakefile *mf = target->Target->GetMakefile();
-        if (strcmp(mf->GetCurrentSourceDirectory(),
-                   mf->GetHomeDirectory()) == 0)
+        if (strcmp(target->GetLocalGenerator()->GetCurrentSourceDirectory(),
+                   target->GetLocalGenerator()->GetSourceDirectory()) == 0)
           return new cmNinjaUtilityTargetGenerator(target);
         // else fallthrough
       }
@@ -93,7 +92,7 @@ std::string cmNinjaTargetGenerator::LanguageCompilerRule(
   const std::string& lang) const
 {
   return lang + "_COMPILER__" +
-    cmGlobalNinjaGenerator::EncodeRuleName(this->Target->GetName());
+    cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName());
 }
 
 std::string
@@ -149,17 +148,9 @@ void cmNinjaTargetGenerator::AddIncludeFlags(std::string& languageFlags,
 
 bool cmNinjaTargetGenerator::NeedDepTypeMSVC(const std::string& lang) const
 {
-  if (lang == "C" || lang == "CXX")
-    {
-    cmMakefile* mf = this->GetMakefile();
-    return (
-      strcmp(mf->GetSafeDefinition("CMAKE_C_COMPILER_ID"), "MSVC") == 0 ||
-      strcmp(mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID"), "MSVC") == 0 ||
-      strcmp(mf->GetSafeDefinition("CMAKE_C_SIMULATE_ID"), "MSVC") == 0 ||
-      strcmp(mf->GetSafeDefinition("CMAKE_CXX_SIMULATE_ID"), "MSVC") == 0
-      );
-    }
-  return false;
+  return strcmp(
+    this->GetMakefile()->GetSafeDefinition("CMAKE_NINJA_DEPTYPE_" + lang),
+    "msvc") == 0;
 }
 
 // TODO: Refactor with
@@ -190,8 +181,8 @@ ComputeDefines(cmSourceFile const* source, const std::string& language)
 cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const
 {
   // Static libraries never depend on other targets for linking.
-  if (this->Target->GetType() == cmTarget::STATIC_LIBRARY ||
-      this->Target->GetType() == cmTarget::OBJECT_LIBRARY)
+  if (this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY ||
+      this->GeneratorTarget->GetType() == cmState::OBJECT_LIBRARY)
     return cmNinjaDeps();
 
   cmComputeLinkInformation* cli =
@@ -204,9 +195,10 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const
   std::transform(deps.begin(), deps.end(), result.begin(), MapToNinjaPath());
 
   // Add a dependency on the link definitions file, if any.
-  if(!this->ModuleDefinitionFile.empty())
+  if(this->ModuleDefinitionFile)
     {
-    result.push_back(this->ConvertToNinjaPath(this->ModuleDefinitionFile));
+    result.push_back(this->ConvertToNinjaPath(
+        this->ModuleDefinitionFile->GetFullPath()));
     }
 
   // Add a dependency on user-specified manifest files, if any.
@@ -219,7 +211,8 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const
     }
 
   // Add user-specified dependencies.
-  if (const char* linkDepends = this->Target->GetProperty("LINK_DEPENDS"))
+  if (const char* linkDepends =
+      this->GeneratorTarget->GetProperty("LINK_DEPENDS"))
     {
     std::vector<std::string> linkDeps;
     cmSystemTools::ExpandListArgument(linkDepends, linkDeps);
@@ -246,7 +239,7 @@ cmNinjaTargetGenerator
     path += "/";
   std::string const& objectName = this->GeneratorTarget
                                       ->GetObjectName(source);
-  path += this->LocalGenerator->GetTargetDirectory(*this->Target);
+  path += this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
   path += "/";
   path += objectName;
   return path;
@@ -254,7 +247,7 @@ cmNinjaTargetGenerator
 
 std::string cmNinjaTargetGenerator::GetTargetOutputDir() const
 {
-  std::string dir = this->Target->GetDirectory(this->GetConfigName());
+  std::string dir = this->GeneratorTarget->GetDirectory(this->GetConfigName());
   return ConvertToNinjaPath(dir);
 }
 
@@ -272,7 +265,7 @@ cmNinjaTargetGenerator
 
 std::string cmNinjaTargetGenerator::GetTargetName() const
 {
-  return this->Target->GetName();
+  return this->GeneratorTarget->GetName();
 }
 
 
@@ -284,22 +277,22 @@ bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable(cmNinjaVars& vars) const
     {
     std::string pdbPath;
     std::string compilePdbPath;
-    if(this->Target->GetType() == cmTarget::EXECUTABLE ||
-       this->Target->GetType() == cmTarget::STATIC_LIBRARY ||
-       this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
-       this->Target->GetType() == cmTarget::MODULE_LIBRARY)
+    if(this->GeneratorTarget->GetType() == cmState::EXECUTABLE ||
+       this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY ||
+       this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
+       this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY)
       {
-      pdbPath = this->Target->GetPDBDirectory(this->GetConfigName());
+      pdbPath = this->GeneratorTarget->GetPDBDirectory(this->GetConfigName());
       pdbPath += "/";
       pdbPath += this->GeneratorTarget->GetPDBName(this->GetConfigName());
       }
-    if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
+    if(this->GeneratorTarget->GetType() <= cmState::OBJECT_LIBRARY)
       {
       compilePdbPath =
               this->GeneratorTarget->GetCompilePDBPath(this->GetConfigName());
       if(compilePdbPath.empty())
         {
-        compilePdbPath = this->Target->GetSupportDirectory() + "/";
+        compilePdbPath = this->GeneratorTarget->GetSupportDirectory() + "/";
         }
       }
 
@@ -335,7 +328,7 @@ cmNinjaTargetGenerator
 {
   cmLocalGenerator::RuleVariables vars;
   vars.RuleLauncher = "RULE_LAUNCH_COMPILE";
-  vars.CMTarget = this->GetTarget();
+  vars.CMTarget = this->GetGeneratorTarget();
   vars.Language = lang.c_str();
   vars.Source = "$in";
   vars.Object = "$out";
@@ -359,7 +352,7 @@ cmNinjaTargetGenerator
     depfile = "";
     flags += " /showIncludes";
     }
-  else if (lang == "RC" && this->NeedDepTypeMSVC("C"))
+  else if (mf->IsOn("CMAKE_NINJA_CMCLDEPS_"+lang))
     {
     // For the MS resource compiler we need cmcldeps, but skip dependencies
     // for source-file try_compile cases because they are always fresh.
@@ -411,7 +404,7 @@ cmNinjaTargetGenerator
   if (!compileCmds.empty() && (lang == "C" || lang == "CXX"))
     {
     std::string const iwyu_prop = lang + "_INCLUDE_WHAT_YOU_USE";
-    const char *iwyu = this->Target->GetProperty(iwyu_prop);
+    const char *iwyu = this->GeneratorTarget->GetProperty(iwyu_prop);
     if (iwyu && *iwyu)
       {
       std::string run_iwyu =
@@ -428,7 +421,7 @@ cmNinjaTargetGenerator
   if (!compileCmds.empty() && (lang == "C" || lang == "CXX"))
     {
     std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER";
-    const char *clauncher = this->Target->GetProperty(clauncher_prop);
+    const char *clauncher = this->GeneratorTarget->GetProperty(clauncher_prop);
     if (clauncher && *clauncher)
       {
       std::vector<std::string> launcher_cmd;
@@ -481,7 +474,7 @@ cmNinjaTargetGenerator
   cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
   this->GetBuildFileStream()
     << "# Object build statements for "
-    << cmTarget::GetTargetTypeName(this->GetTarget()->GetType())
+    << cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType())
     << " target "
     << this->GetTargetName()
     << "\n\n";
@@ -494,7 +487,8 @@ cmNinjaTargetGenerator
       si != customCommands.end(); ++si)
      {
      cmCustomCommand const* cc = (*si)->GetCustomCommand();
-     this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget());
+     this->GetLocalGenerator()->AddCustomCommandTarget(cc,
+         this->GetGeneratorTarget());
      // Record the custom commands for this target. The container is used
      // in WriteObjectBuildStatement when called in a loop below.
      this->CustomCommands.push_back(cc);
@@ -519,7 +513,8 @@ cmNinjaTargetGenerator
     }
 
   cmNinjaDeps orderOnlyDeps;
-  this->GetLocalGenerator()->AppendTargetDepends(this->Target, orderOnlyDeps);
+  this->GetLocalGenerator()->AppendTargetDepends(this->GeneratorTarget,
+                                                 orderOnlyDeps);
 
   // Add order-only dependencies on custom command outputs.
   for(std::vector<cmCustomCommand const*>::const_iterator
@@ -568,7 +563,7 @@ cmNinjaTargetGenerator
   std::string const language = source->GetLanguage();
   std::string const sourceFileName =
     language=="RC" ? source->GetFullPath() : this->GetSourceFilePath(source);
-  std::string const objectDir = this->Target->GetSupportDirectory();
+  std::string const objectDir = this->GeneratorTarget->GetSupportDirectory();
   std::string const objectFileName = this->GetObjectFilePath(source);
   std::string const objectFileDir =
     cmSystemTools::GetFilenamePath(objectFileName);
@@ -641,7 +636,8 @@ cmNinjaTargetGenerator
                               ConvertToNinjaPath(objectFileDir),
                               cmLocalGenerator::SHELL);
 
-  this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetTarget(), vars);
+  this->addPoolNinjaVariable("JOB_POOL_COMPILE",
+                             this->GetGeneratorTarget(), vars);
 
   this->SetMsvcTargetPdbVariable(vars);
 
@@ -790,7 +786,7 @@ cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
 
 void cmNinjaTargetGenerator::addPoolNinjaVariable(
                                               const std::string& pool_property,
-                                              cmTarget* target,
+                                              cmGeneratorTarget* target,
                                               cmNinjaVars& vars)
 {
     const char* pool = target->GetProperty(pool_property);
diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h
index 0267f63..e3ec423 100644
--- a/Source/cmNinjaTargetGenerator.h
+++ b/Source/cmNinjaTargetGenerator.h
@@ -53,9 +53,6 @@ protected:
   cmGeneratedFileStream& GetBuildFileStream() const;
   cmGeneratedFileStream& GetRulesFileStream() const;
 
-  cmTarget* GetTarget() const
-  { return this->Target; }
-
   cmGeneratorTarget* GetGeneratorTarget() const
   { return this->GeneratorTarget; }
 
@@ -152,7 +149,7 @@ protected:
   std::set<std::string> MacContentFolders;
 
   void addPoolNinjaVariable(const std::string& pool_property,
-                            cmTarget* target,
+                            cmGeneratorTarget* target,
                             cmNinjaVars& vars);
 
 private:
diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx
index 58b901a..ac66fcd 100644
--- a/Source/cmNinjaUtilityTargetGenerator.cxx
+++ b/Source/cmNinjaUtilityTargetGenerator.cxx
@@ -16,7 +16,6 @@
 #include "cmGlobalNinjaGenerator.h"
 #include "cmMakefile.h"
 #include "cmSourceFile.h"
-#include "cmTarget.h"
 #include "cmCustomCommandGenerator.h"
 
 cmNinjaUtilityTargetGenerator::cmNinjaUtilityTargetGenerator(
@@ -34,8 +33,8 @@ void cmNinjaUtilityTargetGenerator::Generate()
   cmNinjaDeps deps, outputs, util_outputs(1, utilCommandName);
 
   const std::vector<cmCustomCommand> *cmdLists[2] = {
-    &this->GetTarget()->GetPreBuildCommands(),
-    &this->GetTarget()->GetPostBuildCommands()
+    &this->GetGeneratorTarget()->GetPreBuildCommands(),
+    &this->GetGeneratorTarget()->GetPostBuildCommands()
   };
 
   bool uses_terminal = false;
@@ -58,7 +57,7 @@ void cmNinjaUtilityTargetGenerator::Generate()
   std::vector<cmSourceFile*> sources;
   std::string config = this->GetMakefile()
                            ->GetSafeDefinition("CMAKE_BUILD_TYPE");
-  this->GetTarget()->GetSourceFiles(sources, config);
+  this->GetGeneratorTarget()->GetSourceFiles(sources, config);
   for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
       source != sources.end(); ++source)
     {
@@ -66,7 +65,8 @@ void cmNinjaUtilityTargetGenerator::Generate()
       {
       cmCustomCommandGenerator ccg(*cc, this->GetConfigName(),
                                    this->GetLocalGenerator());
-      this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget());
+      this->GetLocalGenerator()->AddCustomCommandTarget(cc,
+          this->GetGeneratorTarget());
 
       // Depend on all custom command outputs.
       const std::vector<std::string>& ccOutputs = ccg.GetOutputs();
@@ -78,8 +78,10 @@ void cmNinjaUtilityTargetGenerator::Generate()
       }
     }
 
-  this->GetLocalGenerator()->AppendTargetOutputs(this->GetTarget(), outputs);
-  this->GetLocalGenerator()->AppendTargetDepends(this->GetTarget(), deps);
+  this->GetLocalGenerator()->AppendTargetOutputs(this->GetGeneratorTarget(),
+                                                 outputs);
+  this->GetLocalGenerator()->AppendTargetDepends(this->GetGeneratorTarget(),
+                                                 deps);
 
   if (commands.empty()) {
     this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
@@ -90,7 +92,8 @@ void cmNinjaUtilityTargetGenerator::Generate()
   } else {
     std::string command =
       this->GetLocalGenerator()->BuildCommandLine(commands);
-    const char *echoStr = this->GetTarget()->GetProperty("EchoString");
+    const char *echoStr =
+        this->GetGeneratorTarget()->GetProperty("EchoString");
     std::string desc;
     if (echoStr)
       desc = echoStr;
@@ -103,13 +106,13 @@ void cmNinjaUtilityTargetGenerator::Generate()
       command,
       "$(CMAKE_SOURCE_DIR)",
       this->GetLocalGenerator()->ConvertToOutputFormat(
-        this->GetTarget()->GetMakefile()->GetHomeDirectory(),
+        this->GetLocalGenerator()->GetSourceDirectory(),
         cmLocalGenerator::SHELL).c_str());
     cmSystemTools::ReplaceString(
       command,
       "$(CMAKE_BINARY_DIR)",
       this->GetLocalGenerator()->ConvertToOutputFormat(
-        this->GetTarget()->GetMakefile()->GetHomeOutputDirectory(),
+        this->GetLocalGenerator()->GetBinaryDirectory(),
         cmLocalGenerator::SHELL).c_str());
     cmSystemTools::ReplaceString(command, "$(ARGS)", "");
 
@@ -128,6 +131,7 @@ void cmNinjaUtilityTargetGenerator::Generate()
       desc,
       "Utility command for " + this->GetTargetName(),
       uses_terminal,
+      /*restat*/true,
       util_outputs,
       deps);
 
@@ -139,5 +143,5 @@ void cmNinjaUtilityTargetGenerator::Generate()
   }
 
   this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
-                                             this->GetTarget());
+                                             this->GetGeneratorTarget());
 }
diff --git a/Source/cmOSXBundleGenerator.cxx b/Source/cmOSXBundleGenerator.cxx
index 4fe99e3..934e198 100644
--- a/Source/cmOSXBundleGenerator.cxx
+++ b/Source/cmOSXBundleGenerator.cxx
@@ -34,7 +34,7 @@ cmOSXBundleGenerator(cmGeneratorTarget* target,
 //----------------------------------------------------------------------------
 bool cmOSXBundleGenerator::MustSkip()
 {
-  return !this->GT->Target->HaveWellDefinedOutputFiles();
+  return !this->GT->HaveWellDefinedOutputFiles();
 }
 
 //----------------------------------------------------------------------------
@@ -59,7 +59,7 @@ void cmOSXBundleGenerator::CreateAppBundle(const std::string& targetName,
   plist += "/";
   plist += this->GT->GetAppBundleDirectory(this->ConfigName, true);
   plist += "/Info.plist";
-  this->LocalGenerator->GenerateAppleInfoPList(this->GT->Target,
+  this->LocalGenerator->GenerateAppleInfoPList(this->GT,
                                                targetName,
                                                plist.c_str());
   this->Makefile->AddCMakeOutputFile(plist);
@@ -83,17 +83,26 @@ void cmOSXBundleGenerator::CreateFramework(
   std::string newoutpath = outpath + "/" +
     this->GT->GetFrameworkDirectory(this->ConfigName, false);
 
-  std::string frameworkVersion = this->GT->Target->GetFrameworkVersion();
+  std::string frameworkVersion = this->GT->GetFrameworkVersion();
 
-  // Configure the Info.plist file into the Resources directory.
-  this->MacContentFolders->insert("Resources");
+  // Configure the Info.plist file
   std::string plist = newoutpath;
-  plist += "/Resources/Info.plist";
+  if (!this->Makefile->PlatformIsAppleIos())
+    {
+    // Put the Info.plist file into the Resources directory.
+    this->MacContentFolders->insert("Resources");
+    plist += "/Resources";
+    }
+  plist += "/Info.plist";
   std::string name = cmSystemTools::GetFilenameName(targetName);
-  this->LocalGenerator->GenerateFrameworkInfoPList(this->GT->Target,
+  this->LocalGenerator->GenerateFrameworkInfoPList(this->GT,
                                                    name,
                                                    plist.c_str());
 
+  // Generate Versions directory only for MacOSX frameworks
+  if (this->Makefile->PlatformIsAppleIos())
+    return;
+
   // TODO: Use the cmMakefileTargetGenerator::ExtraFiles vector to
   // drive rules to create these files at build time.
   std::string oldName;
@@ -182,7 +191,7 @@ void cmOSXBundleGenerator::CreateCFBundle(const std::string& targetName,
     this->GT->GetCFBundleDirectory(this->ConfigName, true);
   plist += "/Info.plist";
   std::string name = cmSystemTools::GetFilenameName(targetName);
-  this->LocalGenerator->GenerateAppleInfoPList(this->GT->Target,
+  this->LocalGenerator->GenerateAppleInfoPList(this->GT,
                                                name,
                                                plist.c_str());
   this->Makefile->AddCMakeOutputFile(plist);
diff --git a/Source/cmOrderDirectories.cxx b/Source/cmOrderDirectories.cxx
index e3406a8..61efd01 100644
--- a/Source/cmOrderDirectories.cxx
+++ b/Source/cmOrderDirectories.cxx
@@ -553,7 +553,7 @@ void cmOrderDirectories::FindImplicitConflicts()
     << "Some of these libraries may not be found correctly.";
   this->GlobalGenerator->GetCMakeInstance()
     ->IssueMessage(cmake::WARNING, w.str(),
-                   this->Target->Target->GetBacktrace());
+                   this->Target->GetBacktrace());
 }
 
 //----------------------------------------------------------------------------
@@ -635,7 +635,7 @@ void cmOrderDirectories::DiagnoseCycle()
   e << "Some of these libraries may not be found correctly.";
   this->GlobalGenerator->GetCMakeInstance()
     ->IssueMessage(cmake::WARNING, e.str(),
-                   this->Target->Target->GetBacktrace());
+                   this->Target->GetBacktrace());
 }
 
 bool cmOrderDirectories::IsSameDirectory(std::string const& l,
diff --git a/Source/cmOutputRequiredFilesCommand.cxx b/Source/cmOutputRequiredFilesCommand.cxx
index 2d57d3b..54208ac 100644
--- a/Source/cmOutputRequiredFilesCommand.cxx
+++ b/Source/cmOutputRequiredFilesCommand.cxx
@@ -10,108 +10,239 @@
   See the License for more information.
 ============================================================================*/
 #include "cmOutputRequiredFilesCommand.h"
-#include "cmMakeDepend.h"
 #include "cmAlgorithms.h"
 #include <cmsys/FStream.hxx>
 
-class cmLBDepend : public cmMakeDepend
+/** \class cmDependInformation
+ * \brief Store dependency information for a single source file.
+ *
+ * This structure stores the depend information for a single source file.
+ */
+class cmDependInformation
 {
+public:
   /**
-   * Compute the depend information for this class.
+   * Construct with dependency generation marked not done; instance
+   * not placed in cmMakefile's list.
    */
-  virtual void DependWalk(cmDependInformation* info);
-};
+  cmDependInformation(): DependDone(false), SourceFile(0) {}
 
-void cmLBDepend::DependWalk(cmDependInformation* info)
-{
-  cmsys::ifstream fin(info->FullPath.c_str());
-  if(!fin)
+  /**
+   * The set of files on which this one depends.
+   */
+  typedef std::set<cmDependInformation*> DependencySetType;
+  DependencySetType DependencySet;
+
+  /**
+   * This flag indicates whether dependency checking has been
+   * performed for this file.
+   */
+  bool DependDone;
+
+  /**
+   * If this object corresponds to a cmSourceFile instance, this points
+   * to it.
+   */
+  const cmSourceFile *SourceFile;
+
+  /**
+   * Full path to this file.
+   */
+  std::string FullPath;
+
+  /**
+   * Full path not including file name.
+   */
+  std::string PathOnly;
+
+  /**
+   * Name used to #include this file.
+   */
+  std::string IncludeName;
+
+  /**
+   * This method adds the dependencies of another file to this one.
+   */
+  void AddDependencies(cmDependInformation* info)
+  {
+  if(this != info)
     {
-    cmSystemTools::Error("error can not open ", info->FullPath.c_str());
-    return;
+    this->DependencySet.insert(info);
     }
+  }
+};
 
-  std::string line;
-  while(cmSystemTools::GetLineFromStream(fin, line))
-    {
-    if(cmHasLiteralPrefix(line.c_str(), "#include"))
-      {
-      // if it is an include line then create a string class
-      std::string currentline = line;
-      size_t qstart = currentline.find('\"', 8);
-      size_t qend;
-      // if a quote is not found look for a <
-      if(qstart == std::string::npos)
-        {
-        qstart = currentline.find('<', 8);
-        // if a < is not found then move on
-        if(qstart == std::string::npos)
-          {
-          cmSystemTools::Error("unknown include directive ",
-                               currentline.c_str() );
-          continue;
-          }
-        else
-          {
-          qend = currentline.find('>', qstart+1);
-          }
-        }
-      else
+class cmLBDepend
+{
+public:
+  /**
+   * Construct the object with verbose turned off.
+   */
+  cmLBDepend()
+  {
+    this->Verbose = false;
+    this->IncludeFileRegularExpression.compile("^.*$");
+    this->ComplainFileRegularExpression.compile("^$");
+  }
+
+  /**
+   * Destructor.
+   */
+  ~cmLBDepend()
+  {
+    cmDeleteAll(this->DependInformationMap);
+  }
+
+  /**
+   * Set the makefile that is used as a source of classes.
+   */
+  void SetMakefile(cmMakefile* makefile)
+  {
+    this->Makefile = makefile;
+
+    // Now extract the include file regular expression from the makefile.
+    this->IncludeFileRegularExpression.compile(
+          this->Makefile->GetIncludeRegularExpression());
+    this->ComplainFileRegularExpression.compile(
+          this->Makefile->GetComplainRegularExpression());
+
+    // Now extract any include paths from the targets
+    std::set<std::string> uniqueIncludes;
+    std::vector<std::string> orderedAndUniqueIncludes;
+    cmTargets &targets = this->Makefile->GetTargets();
+    for (cmTargets::iterator l = targets.begin();
+         l != targets.end(); ++l)
+      {
+      const char *incDirProp = l->second.GetProperty("INCLUDE_DIRECTORIES");
+      if (!incDirProp)
         {
-        qend = currentline.find('\"', qstart+1);
+        continue;
         }
-      // extract the file being included
-      std::string includeFile = currentline.substr(qstart+1, qend - qstart-1);
-      // see if the include matches the regular expression
-      if(!this->IncludeFileRegularExpression.find(includeFile))
+
+      std::string incDirs =
+          cmGeneratorExpression::Preprocess(incDirProp,
+              cmGeneratorExpression::StripAllGeneratorExpressions);
+
+      std::vector<std::string> includes;
+      cmSystemTools::ExpandListArgument(incDirs, includes);
+
+      for(std::vector<std::string>::const_iterator j = includes.begin();
+          j != includes.end(); ++j)
         {
-        if(this->Verbose)
+        std::string path = *j;
+        this->Makefile->ExpandVariablesInString(path);
+        if(uniqueIncludes.insert(path).second)
           {
-          std::string message = "Skipping ";
-          message += includeFile;
-          message += " for file ";
-          message += info->FullPath.c_str();
-          cmSystemTools::Error(message.c_str(), 0);
+          orderedAndUniqueIncludes.push_back(path);
           }
-        continue;
         }
+      }
 
-      // Add this file and all its dependencies.
-      this->AddDependency(info, includeFile.c_str());
-      /// add the cxx file if it exists
-      std::string cxxFile = includeFile;
-      std::string::size_type pos = cxxFile.rfind('.');
-      if(pos != std::string::npos)
+    for(std::vector<std::string>::const_iterator
+        it = orderedAndUniqueIncludes.begin();
+        it != orderedAndUniqueIncludes.end();
+        ++it)
+      {
+      this->AddSearchPath(*it);
+      }
+  }
+
+  /**
+   * Add a directory to the search path for include files.
+   */
+  void AddSearchPath(const std::string& path)
+  {
+    this->IncludeDirectories.push_back(path);
+  }
+
+  /**
+   * Generate dependencies for the file given.  Returns a pointer to
+   * the cmDependInformation object for the file.
+   */
+  const cmDependInformation* FindDependencies(const char* file)
+  {
+    cmDependInformation* info = this->GetDependInformation(file,0);
+    this->GenerateDependInformation(info);
+    return info;
+  }
+
+protected:
+  /**
+   * Compute the depend information for this class.
+   */
+
+  void DependWalk(cmDependInformation* info)
+  {
+    cmsys::ifstream fin(info->FullPath.c_str());
+    if(!fin)
+      {
+      cmSystemTools::Error("error can not open ", info->FullPath.c_str());
+      return;
+      }
+
+    std::string line;
+    while(cmSystemTools::GetLineFromStream(fin, line))
+      {
+      if(cmHasLiteralPrefix(line.c_str(), "#include"))
         {
-        std::string root = cxxFile.substr(0, pos);
-        cxxFile = root + ".cxx";
-        bool found = false;
-        // try jumping to .cxx .cpp and .c in order
-        if(cmSystemTools::FileExists(cxxFile.c_str()))
+        // if it is an include line then create a string class
+        std::string currentline = line;
+        size_t qstart = currentline.find('\"', 8);
+        size_t qend;
+        // if a quote is not found look for a <
+        if(qstart == std::string::npos)
           {
-          found = true;
+          qstart = currentline.find('<', 8);
+          // if a < is not found then move on
+          if(qstart == std::string::npos)
+            {
+            cmSystemTools::Error("unknown include directive ",
+                                 currentline.c_str() );
+            continue;
+            }
+          else
+            {
+            qend = currentline.find('>', qstart+1);
+            }
           }
-        for(std::vector<std::string>::iterator i =
-              this->IncludeDirectories.begin();
-            i != this->IncludeDirectories.end(); ++i)
+        else
+          {
+          qend = currentline.find('\"', qstart+1);
+          }
+        // extract the file being included
+        std::string includeFile =
+          currentline.substr(qstart+1, qend - qstart-1);
+        // see if the include matches the regular expression
+        if(!this->IncludeFileRegularExpression.find(includeFile))
           {
-          std::string path = *i;
-          path = path + "/";
-          path = path + cxxFile;
-          if(cmSystemTools::FileExists(path.c_str()))
+          if(this->Verbose)
             {
-            found = true;
+            std::string message = "Skipping ";
+            message += includeFile;
+            message += " for file ";
+            message += info->FullPath.c_str();
+            cmSystemTools::Error(message.c_str(), 0);
             }
+          continue;
           }
-        if (!found)
+
+        // Add this file and all its dependencies.
+        this->AddDependency(info, includeFile.c_str());
+        /// add the cxx file if it exists
+        std::string cxxFile = includeFile;
+        std::string::size_type pos = cxxFile.rfind('.');
+        if(pos != std::string::npos)
           {
-          cxxFile = root + ".cpp";
+          std::string root = cxxFile.substr(0, pos);
+          cxxFile = root + ".cxx";
+          bool found = false;
+          // try jumping to .cxx .cpp and .c in order
           if(cmSystemTools::FileExists(cxxFile.c_str()))
             {
             found = true;
             }
           for(std::vector<std::string>::iterator i =
-                this->IncludeDirectories.begin();
+              this->IncludeDirectories.begin();
               i != this->IncludeDirectories.end(); ++i)
             {
             std::string path = *i;
@@ -122,55 +253,314 @@ void cmLBDepend::DependWalk(cmDependInformation* info)
               found = true;
               }
             }
-          }
-        if (!found)
-          {
-          cxxFile = root + ".c";
-          if(cmSystemTools::FileExists(cxxFile.c_str()))
+          if (!found)
             {
-            found = true;
-            }
-          for(std::vector<std::string>::iterator i =
-                this->IncludeDirectories.begin();
-              i != this->IncludeDirectories.end(); ++i)
-            {
-            std::string path = *i;
-            path = path + "/";
-            path = path + cxxFile;
-            if(cmSystemTools::FileExists(path.c_str()))
+            cxxFile = root + ".cpp";
+            if(cmSystemTools::FileExists(cxxFile.c_str()))
               {
               found = true;
               }
+            for(std::vector<std::string>::iterator i =
+                this->IncludeDirectories.begin();
+                i != this->IncludeDirectories.end(); ++i)
+              {
+              std::string path = *i;
+              path = path + "/";
+              path = path + cxxFile;
+              if(cmSystemTools::FileExists(path.c_str()))
+                {
+                found = true;
+                }
+              }
             }
-          }
-        if (!found)
-          {
-          cxxFile = root + ".txx";
-          if(cmSystemTools::FileExists(cxxFile.c_str()))
+          if (!found)
             {
-            found = true;
-            }
-          for(std::vector<std::string>::iterator i =
+            cxxFile = root + ".c";
+            if(cmSystemTools::FileExists(cxxFile.c_str()))
+              {
+              found = true;
+              }
+            for(std::vector<std::string>::iterator i =
                 this->IncludeDirectories.begin();
-              i != this->IncludeDirectories.end(); ++i)
+                i != this->IncludeDirectories.end(); ++i)
+              {
+              std::string path = *i;
+              path = path + "/";
+              path = path + cxxFile;
+              if(cmSystemTools::FileExists(path.c_str()))
+                {
+                found = true;
+                }
+              }
+            }
+          if (!found)
             {
-            std::string path = *i;
-            path = path + "/";
-            path = path + cxxFile;
-            if(cmSystemTools::FileExists(path.c_str()))
+            cxxFile = root + ".txx";
+            if(cmSystemTools::FileExists(cxxFile.c_str()))
               {
               found = true;
               }
+            for(std::vector<std::string>::iterator i =
+                this->IncludeDirectories.begin();
+                i != this->IncludeDirectories.end(); ++i)
+              {
+              std::string path = *i;
+              path = path + "/";
+              path = path + cxxFile;
+              if(cmSystemTools::FileExists(path.c_str()))
+                {
+                found = true;
+                }
+              }
+            }
+          if (found)
+            {
+            this->AddDependency(info, cxxFile.c_str());
             }
           }
-        if (found)
+        }
+      }
+  }
+
+  /**
+   * Add a dependency.  Possibly walk it for more dependencies.
+   */
+  void AddDependency(cmDependInformation* info, const char* file)
+  {
+    cmDependInformation* dependInfo =
+        this->GetDependInformation(file, info->PathOnly.c_str());
+    this->GenerateDependInformation(dependInfo);
+    info->AddDependencies(dependInfo);
+  }
+
+  /**
+   * Fill in the given object with dependency information.  If the
+   * information is already complete, nothing is done.
+   */
+  void GenerateDependInformation(cmDependInformation* info)
+  {
+    // If dependencies are already done, stop now.
+    if(info->DependDone)
+      {
+      return;
+      }
+    else
+      {
+      // Make sure we don't visit the same file more than once.
+      info->DependDone = true;
+      }
+    const char* path = info->FullPath.c_str();
+    if(!path)
+      {
+      cmSystemTools::Error(
+            "Attempt to find dependencies for file without path!");
+      return;
+      }
+
+    bool found = false;
+
+    // If the file exists, use it to find dependency information.
+    if(cmSystemTools::FileExists(path, true))
+      {
+      // Use the real file to find its dependencies.
+      this->DependWalk(info);
+      found = true;
+      }
+
+
+    // See if the cmSourceFile for it has any files specified as
+    // dependency hints.
+    if(info->SourceFile != 0)
+      {
+
+      // Get the cmSourceFile corresponding to this.
+      const cmSourceFile& cFile = *(info->SourceFile);
+      // See if there are any hints for finding dependencies for the missing
+      // file.
+      if(!cFile.GetDepends().empty())
+        {
+        // Dependency hints have been given.  Use them to begin the
+        // recursion.
+        for(std::vector<std::string>::const_iterator file =
+            cFile.GetDepends().begin(); file != cFile.GetDepends().end();
+            ++file)
           {
-          this->AddDependency(info, cxxFile.c_str());
+          this->AddDependency(info, file->c_str());
           }
+
+        // Found dependency information.  We are done.
+        found = true;
         }
       }
-    }
-}
+
+    if(!found)
+      {
+      // Try to find the file amongst the sources
+      cmSourceFile *srcFile = this->Makefile->GetSource
+          (cmSystemTools::GetFilenameWithoutExtension(path));
+      if (srcFile)
+        {
+        if (srcFile->GetFullPath() == path)
+          {
+          found=true;
+          }
+        else
+          {
+          //try to guess which include path to use
+          for(std::vector<std::string>::iterator t =
+              this->IncludeDirectories.begin();
+              t != this->IncludeDirectories.end(); ++t)
+            {
+            std::string incpath = *t;
+            if (!incpath.empty() && incpath[incpath.size() - 1] != '/')
+              {
+              incpath = incpath + "/";
+              }
+            incpath = incpath + path;
+            if (srcFile->GetFullPath() == incpath)
+              {
+              // set the path to the guessed path
+              info->FullPath = incpath;
+              found=true;
+              }
+            }
+          }
+        }
+      }
+
+    if(!found)
+      {
+      // Couldn't find any dependency information.
+      if(this->ComplainFileRegularExpression.find(info->IncludeName.c_str()))
+        {
+        cmSystemTools::Error("error cannot find dependencies for ", path);
+        }
+      else
+        {
+        // Destroy the name of the file so that it won't be output as a
+        // dependency.
+        info->FullPath = "";
+        }
+      }
+  }
+
+  /**
+   * Get an instance of cmDependInformation corresponding to the given file
+   * name.
+   */
+  cmDependInformation* GetDependInformation(const char* file,
+                                            const char *extraPath)
+  {
+    // Get the full path for the file so that lookup is unambiguous.
+    std::string fullPath = this->FullPath(file, extraPath);
+
+    // Try to find the file's instance of cmDependInformation.
+    DependInformationMapType::const_iterator result =
+        this->DependInformationMap.find(fullPath);
+    if(result != this->DependInformationMap.end())
+      {
+      // Found an instance, return it.
+      return result->second;
+      }
+    else
+      {
+      // Didn't find an instance.  Create a new one and save it.
+      cmDependInformation* info = new cmDependInformation;
+      info->FullPath = fullPath;
+      info->PathOnly = cmSystemTools::GetFilenamePath(fullPath);
+      info->IncludeName = file;
+      this->DependInformationMap[fullPath] = info;
+      return info;
+      }
+  }
+
+  /**
+   * Find the full path name for the given file name.
+   * This uses the include directories.
+   * TODO: Cache path conversions to reduce FileExists calls.
+   */
+  std::string FullPath(const char *fname, const char *extraPath)
+  {
+    DirectoryToFileToPathMapType::iterator m;
+    if(extraPath)
+      {
+      m = this->DirectoryToFileToPathMap.find(extraPath);
+      }
+    else
+      {
+      m = this->DirectoryToFileToPathMap.find("");
+      }
+
+    if(m != this->DirectoryToFileToPathMap.end())
+      {
+      FileToPathMapType& map = m->second;
+      FileToPathMapType::iterator p = map.find(fname);
+      if(p != map.end())
+        {
+        return p->second;
+        }
+      }
+
+    if(cmSystemTools::FileExists(fname, true))
+      {
+      std::string fp = cmSystemTools::CollapseFullPath(fname);
+      this->DirectoryToFileToPathMap[extraPath? extraPath: ""][fname] = fp;
+      return fp;
+      }
+
+    for(std::vector<std::string>::iterator i =
+        this->IncludeDirectories.begin();
+        i != this->IncludeDirectories.end(); ++i)
+      {
+      std::string path = *i;
+      if (!path.empty() && path[path.size() - 1] != '/')
+        {
+        path = path + "/";
+        }
+      path = path + fname;
+      if(cmSystemTools::FileExists(path.c_str(), true)
+         && !cmSystemTools::FileIsDirectory(path))
+        {
+        std::string fp = cmSystemTools::CollapseFullPath(path);
+        this->DirectoryToFileToPathMap[extraPath? extraPath: ""][fname] = fp;
+        return fp;
+        }
+      }
+
+    if (extraPath)
+      {
+      std::string path = extraPath;
+      if (!path.empty() && path[path.size() - 1] != '/')
+        {
+        path = path + "/";
+        }
+      path = path + fname;
+      if(cmSystemTools::FileExists(path.c_str(), true)
+         && !cmSystemTools::FileIsDirectory(path))
+        {
+        std::string fp = cmSystemTools::CollapseFullPath(path);
+        this->DirectoryToFileToPathMap[extraPath][fname] = fp;
+        return fp;
+        }
+      }
+
+    // Couldn't find the file.
+    return std::string(fname);
+  }
+
+  cmMakefile* Makefile;
+  bool Verbose;
+  cmsys::RegularExpression IncludeFileRegularExpression;
+  cmsys::RegularExpression ComplainFileRegularExpression;
+  std::vector<std::string> IncludeDirectories;
+  typedef std::map<std::string, std::string> FileToPathMapType;
+  typedef std::map<std::string, FileToPathMapType>
+  DirectoryToFileToPathMapType;
+  typedef std::map<std::string, cmDependInformation*>
+  DependInformationMapType;
+  DependInformationMapType DependInformationMap;
+  DirectoryToFileToPathMapType DirectoryToFileToPathMap;
+};
 
 // cmOutputRequiredFilesCommand
 bool cmOutputRequiredFilesCommand
diff --git a/Source/cmOutputRequiredFilesCommand.h b/Source/cmOutputRequiredFilesCommand.h
index 6a09673..b5eb932 100644
--- a/Source/cmOutputRequiredFilesCommand.h
+++ b/Source/cmOutputRequiredFilesCommand.h
@@ -13,7 +13,8 @@
 #define cmOutputRequiredFilesCommand_h
 
 #include "cmCommand.h"
-#include "cmMakeDepend.h"
+
+class cmDependInformation;
 
 class cmOutputRequiredFilesCommand : public cmCommand
 {
diff --git a/Source/cmParseArgumentsCommand.cxx b/Source/cmParseArgumentsCommand.cxx
new file mode 100644
index 0000000..ca76c88
--- /dev/null
+++ b/Source/cmParseArgumentsCommand.cxx
@@ -0,0 +1,200 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2015 Matthias Maennich <matthias at maennich.net>
+  Copyright 2010 Alexander Neundorf <neundorf at kde.org>
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
+#include "cmParseArgumentsCommand.h"
+#include "cmAlgorithms.h"
+
+//----------------------------------------------------------------------------
+bool cmParseArgumentsCommand
+::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+{
+  // cmake_parse_arguments(prefix options single multi <ARGN>)
+  //                         1       2      3      4
+  if (args.size() < 4)
+    {
+    this->SetError("must be called with at least 4 arguments.");
+    return false;
+    }
+
+  std::vector<std::string>::const_iterator argIter = args.begin(),
+                                           argEnd  = args.end();
+  // the first argument is the prefix
+  const std::string prefix = (*argIter++) + "_";
+
+  // define the result maps holding key/value pairs for
+  // options, single values and multi values
+  typedef std::map<std::string, bool> options_map;
+  typedef std::map<std::string, std::string> single_map;
+  typedef std::map<std::string, std::vector<std::string> > multi_map;
+  options_map options;
+  single_map single;
+  multi_map multi;
+
+  // anything else is put into a vector of unparsed strings
+  std::vector<std::string> unparsed;
+
+  // remember already defined keywords
+  std::set<std::string> used_keywords;
+  const std::string dup_warning = "keyword defined more than once: ";
+
+  // the second argument is a (cmake) list of options without argument
+  std::vector<std::string> list;
+  cmSystemTools::ExpandListArgument(*argIter++, list);
+  for (std::vector<std::string>::const_iterator iter  = list.begin(),
+                                                end   = list.end();
+                                                iter != end; ++iter)
+    {
+    if (!used_keywords.insert(*iter).second)
+      {
+      this->GetMakefile()->IssueMessage(cmake::WARNING, dup_warning + *iter);
+      }
+    options[*iter]; // default initialize
+    }
+
+  // the third argument is a (cmake) list of single argument options
+  list.clear();
+  cmSystemTools::ExpandListArgument(*argIter++, list);
+  for (std::vector<std::string>::const_iterator iter  = list.begin(),
+                                                end   = list.end();
+                                                iter != end; ++iter)
+    {
+    if (!used_keywords.insert(*iter).second)
+      {
+      this->GetMakefile()->IssueMessage(cmake::WARNING, dup_warning + *iter);
+      }
+    single[*iter]; // default initialize
+    }
+
+  // the fourth argument is a (cmake) list of multi argument options
+  list.clear();
+  cmSystemTools::ExpandListArgument(*argIter++, list);
+  for (std::vector<std::string>::const_iterator iter  = list.begin(),
+                                                end   = list.end();
+                                                iter != end; ++iter)
+    {
+    if (!used_keywords.insert(*iter).second)
+      {
+      this->GetMakefile()->IssueMessage(cmake::WARNING, dup_warning + *iter);
+      }
+    multi[*iter]; // default initialize
+    }
+
+  enum insideValues
+  {
+    NONE,
+    SINGLE,
+    MULTI
+  } insideValues = NONE;
+  std::string currentArgName;
+
+  // Flatten ;-lists in the arguments into a single list as was done
+  // by the original function(CMAKE_PARSE_ARGUMENTS).
+  list.clear();
+  for(; argIter != argEnd; ++argIter)
+    {
+    cmSystemTools::ExpandListArgument(*argIter, list);
+    }
+
+  // iterate over the arguments list and fill in the values where applicable
+  for (argIter = list.begin(), argEnd = list.end();
+       argIter != argEnd; ++argIter)
+    {
+    const options_map::iterator optIter = options.find(*argIter);
+    if (optIter != options.end())
+      {
+      insideValues = NONE;
+      optIter->second = true;
+      continue;
+      }
+
+    const single_map::iterator singleIter = single.find(*argIter);
+    if (singleIter != single.end())
+      {
+      insideValues = SINGLE;
+      currentArgName = *argIter;
+      continue;
+      }
+
+    const multi_map::iterator multiIter = multi.find(*argIter);
+    if (multiIter != multi.end())
+      {
+      insideValues = MULTI;
+      currentArgName = *argIter;
+      continue;
+      }
+
+    switch(insideValues)
+      {
+      case SINGLE:
+        single[currentArgName] = *argIter;
+        insideValues = NONE;
+        break;
+      case MULTI:
+        multi[currentArgName].push_back(*argIter);
+        break;
+      default:
+        unparsed.push_back(*argIter);
+        break;
+      }
+    }
+
+  // now iterate over the collected values and update their definition
+  // within the current scope. undefine if necessary.
+
+  for (options_map::const_iterator iter = options.begin(), end = options.end();
+                                   iter != end; ++iter)
+    {
+    this->Makefile->AddDefinition(prefix + iter->first,
+                                  iter->second? "TRUE": "FALSE");
+    }
+  for (single_map::const_iterator iter = single.begin(), end = single.end();
+                                  iter != end; ++iter)
+    {
+    if (!iter->second.empty())
+      {
+      this->Makefile->AddDefinition(prefix + iter->first,
+                                    iter->second.c_str());
+      }
+    else
+      {
+      this->Makefile->RemoveDefinition(prefix + iter->first);
+      }
+    }
+
+  for (multi_map::const_iterator iter = multi.begin(), end = multi.end();
+                                  iter != end; ++iter)
+    {
+    if (!iter->second.empty())
+      {
+      this->Makefile->AddDefinition(prefix + iter->first,
+                                    cmJoin(cmMakeRange(iter->second), ";")
+                                      .c_str());
+      }
+    else
+      {
+      this->Makefile->RemoveDefinition(prefix + iter->first);
+      }
+    }
+
+  if (!unparsed.empty())
+    {
+    this->Makefile->AddDefinition(prefix + "UNPARSED_ARGUMENTS",
+                                  cmJoin(cmMakeRange(unparsed), ";").c_str());
+    }
+  else
+    {
+    this->Makefile->RemoveDefinition(prefix + "UNPARSED_ARGUMENTS");
+    }
+
+  return true;
+}
diff --git a/Source/cmParseArgumentsCommand.h b/Source/cmParseArgumentsCommand.h
new file mode 100644
index 0000000..7fbf642
--- /dev/null
+++ b/Source/cmParseArgumentsCommand.h
@@ -0,0 +1,54 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2015 Matthias Maennich <matthias at maennich.net>
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
+#ifndef cmParseArgumentsCommand_h
+#define cmParseArgumentsCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmParseArgumentsCommand
+ *
+ */
+class cmParseArgumentsCommand : public cmCommand
+{
+public:
+  /**
+   * This is a virtual constructor for the command.
+   */
+  virtual cmCommand* Clone()
+    {
+    return new cmParseArgumentsCommand;
+    }
+
+  /**
+   * This is called when the command is first encountered in
+   * the CMakeLists.txt file.
+   */
+  virtual bool InitialPass(std::vector<std::string> const& args,
+                           cmExecutionStatus &status);
+
+  /**
+   * This determines if the command is invoked when in script mode.
+   */
+  virtual bool IsScriptable() const { return true; }
+
+  /**
+   * The name of the command as specified in CMakeList.txt.
+   */
+  virtual std::string GetName() const { return "cmake_parse_arguments";}
+
+  cmTypeMacro(cmParseArgumentsCommand, cmCommand);
+
+};
+
+
+#endif
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index a549d18..5023055 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -230,6 +230,23 @@ class cmPolicy;
 #define CM_FOR_EACH_POLICY_ID(POLICY) \
   CM_FOR_EACH_POLICY_TABLE(POLICY, CM_SELECT_ID)
 
+#define CM_FOR_EACH_TARGET_POLICY(F) \
+  F(CMP0003) \
+  F(CMP0004) \
+  F(CMP0008) \
+  F(CMP0020) \
+  F(CMP0021) \
+  F(CMP0022) \
+  F(CMP0027) \
+  F(CMP0038) \
+  F(CMP0041) \
+  F(CMP0042) \
+  F(CMP0046) \
+  F(CMP0052) \
+  F(CMP0060) \
+  F(CMP0063) \
+  F(CMP0065)
+
 
 /** \class cmPolicies
  * \brief Handles changes in CMake behavior and policies
diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx
index d52ab78..08caea3 100644
--- a/Source/cmQtAutoGeneratorInitializer.cxx
+++ b/Source/cmQtAutoGeneratorInitializer.cxx
@@ -25,1050 +25,1048 @@
 # include "cmGlobalVisualStudioGenerator.h"
 #endif
 
-std::string cmQtAutoGeneratorInitializer::GetAutogenTargetName(
-    cmTarget const* target)
+static void SetupSourceFiles(cmGeneratorTarget const* target,
+                                   std::vector<std::string>& skipMoc,
+                                   std::vector<std::string>& mocSources,
+                                   std::vector<std::string>& mocHeaders,
+                                   std::vector<std::string>& skipUic)
 {
-  std::string autogenTargetName = target->GetName();
-  autogenTargetName += "_automoc";
-  return autogenTargetName;
-}
+  cmMakefile* makefile = target->Target->GetMakefile();
 
-std::string cmQtAutoGeneratorInitializer::GetAutogenTargetDir(
-    cmTarget const* target)
-{
-  cmMakefile* makefile = target->GetMakefile();
-  std::string targetDir = makefile->GetCurrentBinaryDirectory();
-  targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory();
-  targetDir += "/";
-  targetDir += cmQtAutoGeneratorInitializer::GetAutogenTargetName(target);
-  targetDir += ".dir/";
-  return targetDir;
-}
+  std::vector<cmSourceFile*> srcFiles;
+  target->GetConfigCommonSourceFiles(srcFiles);
 
-static void copyTargetProperty(cmTarget* destinationTarget,
-                               cmTarget* sourceTarget,
-                               const std::string& propertyName)
-{
-  const char* propertyValue = sourceTarget->GetProperty(propertyName);
-  if (propertyValue)
+  std::vector<std::string> newRccFiles;
+
+  for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
+      fileIt != srcFiles.end();
+      ++fileIt)
     {
-    destinationTarget->SetProperty(propertyName, propertyValue);
+    cmSourceFile* sf = *fileIt;
+    std::string absFile = cmsys::SystemTools::GetRealPath(
+                                                    sf->GetFullPath());
+    bool skipFileForMoc =
+        cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC"));
+    bool generated = cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"));
+
+    if(cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOUIC")))
+      {
+      skipUic.push_back(absFile);
+      }
+
+    std::string ext = sf->GetExtension();
+
+    if (target->GetPropertyAsBool("AUTORCC"))
+      {
+      if (ext == "qrc"
+          && !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC")))
+        {
+        std::string basename = cmsys::SystemTools::
+                                      GetFilenameWithoutLastExtension(absFile);
+
+        std::string rcc_output_dir = target->GetSupportDirectory();
+        cmSystemTools::MakeDirectory(rcc_output_dir.c_str());
+        std::string rcc_output_file = rcc_output_dir;
+        rcc_output_file += "/qrc_" + basename + ".cpp";
+        makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
+                                rcc_output_file.c_str(), false);
+        makefile->GetOrCreateSource(rcc_output_file, true);
+        newRccFiles.push_back(rcc_output_file);
+        }
+      }
+
+    if (!generated)
+      {
+      if (skipFileForMoc)
+        {
+        skipMoc.push_back(absFile);
+        }
+      else
+        {
+        cmSystemTools::FileFormat fileType = cmSystemTools::GetFileFormat(
+                                                                ext.c_str());
+        if (fileType == cmSystemTools::CXX_FILE_FORMAT)
+          {
+          mocSources.push_back(absFile);
+          }
+        else if (fileType == cmSystemTools::HEADER_FILE_FORMAT)
+          {
+          mocHeaders.push_back(absFile);
+          }
+        }
+      }
     }
-}
 
-static std::string cmQtAutoGeneratorsStripCR(std::string const& line)
-{
-  // Strip CR characters rcc may have printed (possibly more than one!).
-  std::string::size_type cr = line.find('\r');
-  if (cr != line.npos)
+  for(std::vector<std::string>::const_iterator fileIt = newRccFiles.begin();
+      fileIt != newRccFiles.end();
+      ++fileIt)
     {
-    return line.substr(0, cr);
+    const_cast<cmGeneratorTarget*>(target)->AddSource(*fileIt);
     }
-  return line;
 }
 
-static std::string ReadAll(const std::string& filename)
+static void GetCompileDefinitionsAndDirectories(
+  cmGeneratorTarget const* target,
+  const std::string& config,
+  std::string &incs,
+  std::string &defs)
 {
-  cmsys::ifstream file(filename.c_str());
-  std::stringstream stream;
-  stream << file.rdbuf();
-  file.close();
-  return stream.str();
+  std::vector<std::string> includeDirs;
+  cmLocalGenerator *localGen = target->GetLocalGenerator();
+  // Get the include dirs for this target, without stripping the implicit
+  // include dirs off, see http://public.kitware.com/Bug/view.php?id=13667
+  localGen->GetIncludeDirectories(includeDirs, target, "CXX", config, false);
+
+  incs = cmJoin(includeDirs, ";");
+
+  std::set<std::string> defines;
+  localGen->AddCompileDefinitions(defines, target, config, "CXX");
+
+  defs += cmJoin(defines, ";");
 }
 
-std::string cmQtAutoGeneratorInitializer::ListQt5RccInputs(cmSourceFile* sf,
-                                            cmTarget const* target,
-                                            std::vector<std::string>& depends)
+static void SetupAutoMocTarget(cmGeneratorTarget const* target,
+                          const std::string &autogenTargetName,
+                          std::vector<std::string> const& skipMoc,
+                          std::vector<std::string> const& mocHeaders,
+                          std::map<std::string, std::string> &configIncludes,
+                          std::map<std::string, std::string> &configDefines)
 {
-  std::string rccCommand
-      = cmQtAutoGeneratorInitializer::GetRccExecutable(target);
-  std::vector<std::string> qrcEntries;
+  cmLocalGenerator* lg = target->GetLocalGenerator();
+  cmMakefile* makefile = target->Target->GetMakefile();
 
-  std::vector<std::string> command;
-  command.push_back(rccCommand);
-  command.push_back("--list");
+  const char* tmp = target->GetProperty("AUTOMOC_MOC_OPTIONS");
+  std::string _moc_options = (tmp!=0 ? tmp : "");
+  makefile->AddDefinition("_moc_options",
+          cmOutputConverter::EscapeForCMake(_moc_options).c_str());
+  makefile->AddDefinition("_skip_moc",
+          cmOutputConverter::EscapeForCMake(cmJoin(skipMoc, ";")).c_str());
+  makefile->AddDefinition("_moc_headers",
+          cmOutputConverter::EscapeForCMake(cmJoin(mocHeaders, ";")).c_str());
+  bool relaxedMode = makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE");
+  makefile->AddDefinition("_moc_relaxed_mode", relaxedMode ? "TRUE" : "FALSE");
 
-  std::string absFile = cmsys::SystemTools::GetRealPath(
-                                              sf->GetFullPath());
+  std::string _moc_incs;
+  std::string _moc_compile_defs;
+  std::vector<std::string> configs;
+  const std::string& config = makefile->GetConfigurations(configs);
+  GetCompileDefinitionsAndDirectories(target, config,
+                                      _moc_incs, _moc_compile_defs);
 
-  command.push_back(absFile);
+  makefile->AddDefinition("_moc_incs",
+          cmOutputConverter::EscapeForCMake(_moc_incs).c_str());
+  makefile->AddDefinition("_moc_compile_defs",
+          cmOutputConverter::EscapeForCMake(_moc_compile_defs).c_str());
 
-  std::string rccStdOut;
-  std::string rccStdErr;
-  int retVal = 0;
-  bool result = cmSystemTools::RunSingleCommand(
-    command, &rccStdOut, &rccStdErr,
-    &retVal, 0, cmSystemTools::OUTPUT_NONE);
-  if (!result || retVal)
+  for (std::vector<std::string>::const_iterator li = configs.begin();
+       li != configs.end(); ++li)
     {
-    std::cerr << "AUTOGEN: error: Rcc list process for " << sf->GetFullPath()
-              << " failed:\n" << rccStdOut << "\n" << rccStdErr << std::endl;
-    return std::string();
+    std::string config_moc_incs;
+    std::string config_moc_compile_defs;
+    GetCompileDefinitionsAndDirectories(target, *li,
+                                        config_moc_incs,
+                                        config_moc_compile_defs);
+    if (config_moc_incs != _moc_incs)
+      {
+      configIncludes[*li] =
+                    cmOutputConverter::EscapeForCMake(config_moc_incs);
+      if(_moc_incs.empty())
+        {
+        _moc_incs = config_moc_incs;
+        }
+      }
+    if (config_moc_compile_defs != _moc_compile_defs)
+      {
+      configDefines[*li] =
+            cmOutputConverter::EscapeForCMake(config_moc_compile_defs);
+      if(_moc_compile_defs.empty())
+        {
+        _moc_compile_defs = config_moc_compile_defs;
+        }
+      }
     }
 
-  {
-  std::istringstream ostr(rccStdOut);
-  std::string oline;
-  while(std::getline(ostr, oline))
+  const char *qtVersion = makefile->GetDefinition("_target_qt_version");
+  if (strcmp(qtVersion, "5") == 0)
     {
-    oline = cmQtAutoGeneratorsStripCR(oline);
-    if(!oline.empty())
+    cmGeneratorTarget *qt5Moc =
+        lg->FindGeneratorTargetToUse("Qt5::moc");
+    if (!qt5Moc)
       {
-      qrcEntries.push_back(oline);
+      cmSystemTools::Error("Qt5::moc target not found ",
+                          autogenTargetName.c_str());
+      return;
       }
+    makefile->AddDefinition("_qt_moc_executable",
+                            qt5Moc->ImportedGetLocation(""));
     }
-  }
-
-  {
-  std::istringstream estr(rccStdErr);
-  std::string eline;
-  while(std::getline(estr, eline))
+  else if (strcmp(qtVersion, "4") == 0)
     {
-    eline = cmQtAutoGeneratorsStripCR(eline);
-    if (cmHasLiteralPrefix(eline, "RCC: Error in"))
+    cmGeneratorTarget *qt4Moc =
+        lg->FindGeneratorTargetToUse("Qt4::moc");
+    if (!qt4Moc)
       {
-      static std::string searchString = "Cannot find file '";
-
-      std::string::size_type pos = eline.find(searchString);
-      if (pos == std::string::npos)
-        {
-        std::cerr << "AUTOGEN: error: Rcc lists unparsable output "
-                  << eline << std::endl;
-        return std::string();
-        }
-      pos += searchString.length();
-      std::string::size_type sz = eline.size() - pos - 1;
-      qrcEntries.push_back(eline.substr(pos, sz));
+      cmSystemTools::Error("Qt4::moc target not found ",
+                          autogenTargetName.c_str());
+      return;
       }
+    makefile->AddDefinition("_qt_moc_executable",
+                            qt4Moc->ImportedGetLocation(""));
+    }
+  else
+    {
+    cmSystemTools::Error("The CMAKE_AUTOMOC feature supports only Qt 4 and "
+                        "Qt 5 ", autogenTargetName.c_str());
     }
-  }
-
-  depends.insert(depends.end(), qrcEntries.begin(), qrcEntries.end());
-  return cmJoin(qrcEntries, "@list_sep@");
 }
 
-std::string cmQtAutoGeneratorInitializer::ListQt4RccInputs(cmSourceFile* sf,
-                                            std::vector<std::string>& depends)
+static void GetUicOpts(cmGeneratorTarget const* target,
+                       const std::string& config,
+                       std::string &optString)
 {
-  const std::string qrcContents = ReadAll(sf->GetFullPath());
-
-  cmsys::RegularExpression fileMatchRegex("(<file[^<]+)");
+  std::vector<std::string> opts;
+  target->GetAutoUicOptions(opts, config);
+  optString = cmJoin(opts, ";");
+}
 
-  std::string entriesList;
-  const char* sep = "";
+static void SetupAutoUicTarget(cmGeneratorTarget const* target,
+                          std::vector<std::string> const& skipUic,
+                          std::map<std::string, std::string> &configUicOptions)
+{
+  cmLocalGenerator* lg = target->GetLocalGenerator();
+  cmMakefile *makefile = target->Target->GetMakefile();
 
-  size_t offset = 0;
-  while (fileMatchRegex.find(qrcContents.c_str() + offset))
-    {
-    std::string qrcEntry = fileMatchRegex.match(1);
+  std::set<std::string> skipped;
+  skipped.insert(skipUic.begin(), skipUic.end());
 
-    offset += qrcEntry.size();
+  makefile->AddDefinition("_skip_uic",
+          cmOutputConverter::EscapeForCMake(cmJoin(skipUic, ";")).c_str());
 
-    cmsys::RegularExpression fileReplaceRegex("(^<file[^>]*>)");
-    fileReplaceRegex.find(qrcEntry);
-    std::string tag = fileReplaceRegex.match(1);
+  std::vector<cmSourceFile*> uiFilesWithOptions
+                                        = makefile->GetQtUiFilesWithOptions();
 
-    qrcEntry = qrcEntry.substr(tag.size());
+  const char *qtVersion = makefile->GetDefinition("_target_qt_version");
 
-    if (!cmSystemTools::FileIsFullPath(qrcEntry.c_str()))
-      {
-      qrcEntry = sf->GetLocation().GetDirectory() + "/" + qrcEntry;
-      }
-
-    entriesList += sep;
-    entriesList += qrcEntry;
-    sep = "@list_sep@";
-    depends.push_back(qrcEntry);
-    }
-  return entriesList;
-}
-
-
-void cmQtAutoGeneratorInitializer::InitializeAutogenSources(cmTarget* target)
-{
-  cmMakefile* makefile = target->GetMakefile();
+  std::string _uic_opts;
+  std::vector<std::string> configs;
+  const std::string& config = makefile->GetConfigurations(configs);
+  GetUicOpts(target, config, _uic_opts);
 
-  if (target->GetPropertyAsBool("AUTOMOC"))
+  if (!_uic_opts.empty())
     {
-    std::string automocTargetName =
-        cmQtAutoGeneratorInitializer::GetAutogenTargetName(target);
-    std::string mocCppFile = makefile->GetCurrentBinaryDirectory();
-    mocCppFile += "/";
-    mocCppFile += automocTargetName;
-    mocCppFile += ".cpp";
-    makefile->GetOrCreateSource(mocCppFile, true);
-    makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
-                            mocCppFile.c_str(), false);
-
-    target->AddSource(mocCppFile);
+    _uic_opts = cmOutputConverter::EscapeForCMake(_uic_opts);
+    makefile->AddDefinition("_uic_target_options", _uic_opts.c_str());
     }
-}
-
-void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
-                                                 cmLocalGenerator* lg,
-                                                 cmTarget* target)
-{
-  cmMakefile* makefile = target->GetMakefile();
-
-  std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
-  if (qtMajorVersion == "")
+  for (std::vector<std::string>::const_iterator li = configs.begin();
+       li != configs.end(); ++li)
     {
-    qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR");
+    std::string config_uic_opts;
+    GetUicOpts(target, *li, config_uic_opts);
+    if (config_uic_opts != _uic_opts)
+      {
+      configUicOptions[*li] =
+                    cmOutputConverter::EscapeForCMake(config_uic_opts);
+      if(_uic_opts.empty())
+        {
+        _uic_opts = config_uic_opts;
+        }
+      }
     }
 
-  // create a custom target for running generators at buildtime:
-  std::string autogenTargetName =
-      cmQtAutoGeneratorInitializer::GetAutogenTargetName(target);
-
-  std::string targetDir =
-      cmQtAutoGeneratorInitializer::GetAutogenTargetDir(target);
+  std::string uiFileFiles;
+  std::string uiFileOptions;
+  const char* sep = "";
 
-  cmCustomCommandLine currentLine;
-  currentLine.push_back(cmSystemTools::GetCMakeCommand());
-  currentLine.push_back("-E");
-  currentLine.push_back("cmake_autogen");
-  currentLine.push_back(targetDir);
-  currentLine.push_back("$<CONFIGURATION>");
+  for(std::vector<cmSourceFile*>::const_iterator fileIt =
+      uiFilesWithOptions.begin();
+      fileIt != uiFilesWithOptions.end();
+      ++fileIt)
+    {
+    cmSourceFile* sf = *fileIt;
+    std::string absFile = cmsys::SystemTools::GetRealPath(
+                                                    sf->GetFullPath());
 
-  cmCustomCommandLines commandLines;
-  commandLines.push_back(currentLine);
+    if (!skipped.insert(absFile).second)
+      {
+      continue;
+      }
+    uiFileFiles += sep;
+    uiFileFiles += absFile;
+    uiFileOptions += sep;
+    std::string opts = sf->GetProperty("AUTOUIC_OPTIONS");
+    cmSystemTools::ReplaceString(opts, ";", "@list_sep@");
+    uiFileOptions += opts;
+    sep = ";";
+    }
 
-  std::string workingDirectory = cmSystemTools::CollapseFullPath(
-                                    "", makefile->GetCurrentBinaryDirectory());
+  makefile->AddDefinition("_qt_uic_options_files",
+              cmOutputConverter::EscapeForCMake(uiFileFiles).c_str());
+  makefile->AddDefinition("_qt_uic_options_options",
+            cmOutputConverter::EscapeForCMake(uiFileOptions).c_str());
 
-  std::vector<std::string> depends;
-  if (const char *autogenDepends =
-                                target->GetProperty("AUTOGEN_TARGET_DEPENDS"))
-    {
-    cmSystemTools::ExpandListArgument(autogenDepends, depends);
-    }
-  std::vector<std::string> toolNames;
-  if (target->GetPropertyAsBool("AUTOMOC"))
-    {
-    toolNames.push_back("moc");
-    }
-  if (target->GetPropertyAsBool("AUTOUIC"))
-    {
-    toolNames.push_back("uic");
-    }
-  if (target->GetPropertyAsBool("AUTORCC"))
+  std::string targetName = target->GetName();
+  if (strcmp(qtVersion, "5") == 0)
     {
-    toolNames.push_back("rcc");
+    cmGeneratorTarget *qt5Uic =
+        lg->FindGeneratorTargetToUse("Qt5::uic");
+    if (!qt5Uic)
+      {
+      // Project does not use Qt5Widgets, but has AUTOUIC ON anyway
+      }
+    else
+      {
+      makefile->AddDefinition("_qt_uic_executable",
+                              qt5Uic->ImportedGetLocation(""));
+      }
     }
-
-  std::string tools = toolNames[0];
-  toolNames.erase(toolNames.begin());
-  while (toolNames.size() > 1)
+  else if (strcmp(qtVersion, "4") == 0)
     {
-    tools += ", " + toolNames[0];
-    toolNames.erase(toolNames.begin());
+    cmGeneratorTarget *qt4Uic =
+        lg->FindGeneratorTargetToUse("Qt4::uic");
+    if (!qt4Uic)
+      {
+      cmSystemTools::Error("Qt4::uic target not found ",
+                          targetName.c_str());
+      return;
+      }
+    makefile->AddDefinition("_qt_uic_executable",
+                            qt4Uic->ImportedGetLocation(""));
     }
-  if (toolNames.size() == 1)
+  else
     {
-    tools += " and " + toolNames[0];
+    cmSystemTools::Error("The CMAKE_AUTOUIC feature supports only Qt 4 and "
+                        "Qt 5 ", targetName.c_str());
     }
-  std::string autogenComment = "Automatic " + tools + " for target ";
-  autogenComment += target->GetName();
+}
 
-#if defined(_WIN32) && !defined(__CYGWIN__)
-  bool usePRE_BUILD = false;
-  cmGlobalGenerator* gg = lg->GetGlobalGenerator();
-  if(gg->GetName().find("Visual Studio") != std::string::npos)
+static std::string GetRccExecutable(cmGeneratorTarget const* target)
+{
+  cmLocalGenerator* lg = target->GetLocalGenerator();
+  cmMakefile *makefile = target->Target->GetMakefile();
+  const char *qtVersion = makefile->GetDefinition("_target_qt_version");
+  if (!qtVersion)
     {
-    cmGlobalVisualStudioGenerator* vsgg =
-      static_cast<cmGlobalVisualStudioGenerator*>(gg);
-    // Under VS >= 7 use a PRE_BUILD event instead of a separate target to
-    // reduce the number of targets loaded into the IDE.
-    // This also works around a VS 11 bug that may skip updating the target:
-    //  https://connect.microsoft.com/VisualStudio/feedback/details/769495
-    usePRE_BUILD = vsgg->GetVersion() >= cmGlobalVisualStudioGenerator::VS7;
-    if(usePRE_BUILD)
+    qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR");
+    if (!qtVersion)
       {
-      for (std::vector<std::string>::iterator it = depends.begin();
-            it != depends.end(); ++it)
-        {
-        if(!makefile->FindTargetToUse(it->c_str()))
-          {
-          usePRE_BUILD = false;
-          break;
-          }
-        }
+      qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR");
+      }
+    if (const char *targetQtVersion =
+        target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION",
+                                                        ""))
+      {
+      qtVersion = targetQtVersion;
       }
     }
-#endif
 
-  std::vector<std::string> rcc_output;
-  bool const isNinja =
-    lg->GetGlobalGenerator()->GetName() == "Ninja";
-  if(isNinja
-#if defined(_WIN32) && !defined(__CYGWIN__)
-        || usePRE_BUILD
-#endif
-        )
+  std::string targetName = target->GetName();
+  if (strcmp(qtVersion, "5") == 0)
     {
-    std::vector<cmSourceFile*> srcFiles;
-    cmGeneratorTarget* gtgt =
-        lg->GetGlobalGenerator()->GetGeneratorTarget(target);
-    gtgt->GetConfigCommonSourceFiles(srcFiles);
-    for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
-        fileIt != srcFiles.end();
-        ++fileIt)
+    cmGeneratorTarget *qt5Rcc =
+        lg->FindGeneratorTargetToUse("Qt5::rcc");
+    if (!qt5Rcc)
       {
-      cmSourceFile* sf = *fileIt;
-      std::string absFile = cmsys::SystemTools::GetRealPath(
-                                                sf->GetFullPath());
-
-      std::string ext = sf->GetExtension();
-
-      if (target->GetPropertyAsBool("AUTORCC"))
-        {
-        if (ext == "qrc"
-            && !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC")))
-          {
-          std::string basename = cmsys::SystemTools::
-                                  GetFilenameWithoutLastExtension(absFile);
-
-          std::string rcc_output_dir = target->GetSupportDirectory();
-          cmSystemTools::MakeDirectory(rcc_output_dir.c_str());
-          std::string rcc_output_file = rcc_output_dir;
-          rcc_output_file += "/qrc_" + basename + ".cpp";
-          rcc_output.push_back(rcc_output_file);
-
-          if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED")))
-            {
-            if (qtMajorVersion == "5")
-              {
-              cmQtAutoGeneratorInitializer::ListQt5RccInputs(sf, target,
-                                                              depends);
-              }
-            else
-              {
-              cmQtAutoGeneratorInitializer::ListQt4RccInputs(sf, depends);
-              }
-#if defined(_WIN32) && !defined(__CYGWIN__)
-            // Cannot use PRE_BUILD because the resource files themselves
-            // may not be sources within the target so VS may not know the
-            // target needs to re-build at all.
-            usePRE_BUILD = false;
-#endif
-            }
-          }
-        }
+      cmSystemTools::Error("Qt5::rcc target not found ",
+                          targetName.c_str());
+      return std::string();
       }
+    return qt5Rcc->ImportedGetLocation("");
     }
-
-#if defined(_WIN32) && !defined(__CYGWIN__)
-  if(usePRE_BUILD)
+  else if (strcmp(qtVersion, "4") == 0)
     {
-    // Add the pre-build command directly to bypass the OBJECT_LIBRARY
-    // rejection in cmMakefile::AddCustomCommandToTarget because we know
-    // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case.
-    std::vector<std::string> no_output;
-    std::vector<std::string> no_byproducts;
-    cmCustomCommand cc(makefile, no_output, no_byproducts, depends,
-                       commandLines, autogenComment.c_str(),
-                       workingDirectory.c_str());
-    cc.SetEscapeOldStyle(false);
-    cc.SetEscapeAllowMakeVars(true);
-    target->AddPreBuildCommand(cc);
+    cmGeneratorTarget *qt4Rcc =
+        lg->FindGeneratorTargetToUse("Qt4::rcc");
+    if (!qt4Rcc)
+      {
+      cmSystemTools::Error("Qt4::rcc target not found ",
+                          targetName.c_str());
+      return std::string();
+      }
+    return qt4Rcc->ImportedGetLocation("");
     }
-  else
-#endif
-    {
-    cmTarget* autogenTarget = makefile->AddUtilityCommand(
-                                autogenTargetName, true,
-                                workingDirectory.c_str(),
-                                /*byproducts=*/rcc_output, depends,
-                                commandLines, false, autogenComment.c_str());
 
-    cmGeneratorTarget* gt = new cmGeneratorTarget(autogenTarget, lg);
-    makefile->AddGeneratorTarget(autogenTarget, gt);
+  cmSystemTools::Error("The CMAKE_AUTORCC feature supports only Qt 4 and "
+                      "Qt 5 ", targetName.c_str());
+  return std::string();
+}
 
-    // Set target folder
-    const char* autogenFolder = makefile->GetState()
-                                ->GetGlobalProperty("AUTOMOC_TARGETS_FOLDER");
-    if (!autogenFolder)
-      {
-      autogenFolder = makefile->GetState()
-                                ->GetGlobalProperty("AUTOGEN_TARGETS_FOLDER");
-      }
-    if (autogenFolder && *autogenFolder)
+static void MergeRccOptions(std::vector<std::string> &opts,
+                         const std::vector<std::string> &fileOpts,
+                         bool isQt5)
+{
+  static const char* valueOptions[] = {
+    "name",
+    "root",
+    "compress",
+    "threshold"
+  };
+  std::vector<std::string> extraOpts;
+  for(std::vector<std::string>::const_iterator it = fileOpts.begin();
+      it != fileOpts.end(); ++it)
+    {
+    std::vector<std::string>::iterator existingIt
+                                  = std::find(opts.begin(), opts.end(), *it);
+    if (existingIt != opts.end())
       {
-      autogenTarget->SetProperty("FOLDER", autogenFolder);
+      const char *o = it->c_str();
+      if (*o == '-')
+        {
+        ++o;
+        }
+      if (isQt5 && *o == '-')
+        {
+        ++o;
+        }
+      if (std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions),
+                  cmStrCmp(*it)) != cmArrayEnd(valueOptions))
+        {
+        assert(existingIt + 1 != opts.end());
+        *(existingIt + 1) = *(it + 1);
+        ++it;
+        }
       }
     else
       {
-      // inherit FOLDER property from target (#13688)
-      copyTargetProperty(autogenTarget, target, "FOLDER");
+      extraOpts.push_back(*it);
       }
-
-    target->AddUtility(autogenTargetName);
     }
+  opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
 }
 
-static void GetCompileDefinitionsAndDirectories(cmTarget const* target,
-                                                const std::string& config,
-                                                std::string &incs,
-                                                std::string &defs)
+std::string GetAutogenTargetName(
+    cmGeneratorTarget const* target)
 {
-  cmMakefile* makefile = target->GetMakefile();
-  cmGlobalGenerator* globalGen = makefile->GetGlobalGenerator();
-  std::vector<std::string> includeDirs;
-  cmGeneratorTarget *gtgt = globalGen->GetGeneratorTarget(target);
-  cmLocalGenerator *localGen = gtgt->GetLocalGenerator();
-  // Get the include dirs for this target, without stripping the implicit
-  // include dirs off, see http://public.kitware.com/Bug/view.php?id=13667
-  localGen->GetIncludeDirectories(includeDirs, gtgt, "CXX", config, false);
-
-  incs = cmJoin(includeDirs, ";");
-
-  std::set<std::string> defines;
-  localGen->AddCompileDefinitions(defines, target, config, "CXX");
-
-  defs += cmJoin(defines, ";");
+  std::string autogenTargetName = target->GetName();
+  autogenTargetName += "_automoc";
+  return autogenTargetName;
 }
 
-void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget(
-    cmTarget const* target)
+std::string GetAutogenTargetDir(
+    cmGeneratorTarget const* target)
 {
-  cmMakefile* makefile = target->GetMakefile();
-
-  // forget the variables added here afterwards again:
-  cmMakefile::ScopePushPop varScope(makefile);
-  static_cast<void>(varScope);
-
-  // create a custom target for running generators at buildtime:
-  std::string autogenTargetName =
-      cmQtAutoGeneratorInitializer::GetAutogenTargetName(target);
-
-  makefile->AddDefinition("_moc_target_name",
-          cmOutputConverter::EscapeForCMake(autogenTargetName).c_str());
-  makefile->AddDefinition("_origin_target_name",
-          cmOutputConverter::EscapeForCMake(target->GetName()).c_str());
-
-  std::string targetDir =
-      cmQtAutoGeneratorInitializer::GetAutogenTargetDir(target);
+  cmMakefile* makefile = target->Target->GetMakefile();
+  std::string targetDir = makefile->GetCurrentBinaryDirectory();
+  targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory();
+  targetDir += "/";
+  targetDir += GetAutogenTargetName(target);
+  targetDir += ".dir/";
+  return targetDir;
+}
 
-  const char *qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR");
-  if (!qtVersion)
-    {
-    qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR");
-    }
-  cmGeneratorTarget *gtgt = target->GetMakefile()
-                                  ->GetGlobalGenerator()
-                                  ->GetGeneratorTarget(target);
-  if (const char *targetQtVersion =
-      gtgt->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", ""))
+static void copyTargetProperty(cmTarget* destinationTarget,
+                               cmTarget* sourceTarget,
+                               const std::string& propertyName)
+{
+  const char* propertyValue = sourceTarget->GetProperty(propertyName);
+  if (propertyValue)
     {
-    qtVersion = targetQtVersion;
+    destinationTarget->SetProperty(propertyName, propertyValue);
     }
-  if (qtVersion)
+}
+
+static std::string cmQtAutoGeneratorsStripCR(std::string const& line)
+{
+  // Strip CR characters rcc may have printed (possibly more than one!).
+  std::string::size_type cr = line.find('\r');
+  if (cr != line.npos)
     {
-    makefile->AddDefinition("_target_qt_version", qtVersion);
+    return line.substr(0, cr);
     }
+  return line;
+}
 
-  std::vector<std::string> skipUic;
-  std::vector<std::string> skipMoc;
-  std::vector<std::string> mocSources;
-  std::vector<std::string> mocHeaders;
-  std::map<std::string, std::string> configIncludes;
-  std::map<std::string, std::string> configDefines;
-  std::map<std::string, std::string> configUicOptions;
+static std::string ReadAll(const std::string& filename)
+{
+  cmsys::ifstream file(filename.c_str());
+  std::stringstream stream;
+  stream << file.rdbuf();
+  file.close();
+  return stream.str();
+}
 
-  if (target->GetPropertyAsBool("AUTOMOC")
-      || target->GetPropertyAsBool("AUTOUIC")
-      || target->GetPropertyAsBool("AUTORCC"))
-    {
-    cmQtAutoGeneratorInitializer::SetupSourceFiles(target, skipMoc,
-                                         mocSources, mocHeaders, skipUic);
-    }
-  makefile->AddDefinition("_cpp_files",
-          cmOutputConverter::EscapeForCMake(cmJoin(mocSources, ";")).c_str());
-  if (target->GetPropertyAsBool("AUTOMOC"))
-    {
-    cmQtAutoGeneratorInitializer::SetupAutoMocTarget(target, autogenTargetName,
-                             skipMoc, mocHeaders,
-                             configIncludes, configDefines);
-    }
-  if (target->GetPropertyAsBool("AUTOUIC"))
-    {
-    cmQtAutoGeneratorInitializer::SetupAutoUicTarget(target, skipUic,
-                                                      configUicOptions);
-    }
-  if (target->GetPropertyAsBool("AUTORCC"))
+static std::string ListQt5RccInputs(cmSourceFile* sf,
+                                            cmGeneratorTarget const* target,
+                                            std::vector<std::string>& depends)
+{
+  std::string rccCommand
+      = GetRccExecutable(target);
+
+  bool hasDashDashList = false;
+  {
+  std::vector<std::string> command;
+  command.push_back(rccCommand);
+  command.push_back("--help");
+  std::string rccStdOut;
+  std::string rccStdErr;
+  int retVal = 0;
+  bool result = cmSystemTools::RunSingleCommand(
+    command, &rccStdOut, &rccStdErr,
+    &retVal, 0, cmSystemTools::OUTPUT_NONE);
+  if (result && retVal == 0 &&
+      rccStdOut.find("--list") != std::string::npos)
     {
-    cmQtAutoGeneratorInitializer::SetupAutoRccTarget(target);
+    hasDashDashList = true;
     }
+  }
 
-  const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT");
-  std::string inputFile = cmakeRoot;
-  inputFile += "/Modules/AutogenInfo.cmake.in";
-  std::string outputFile = targetDir;
-  outputFile += "/AutogenInfo.cmake";
-  makefile->AddDefinition("_qt_rcc_inputs",
-              makefile->GetDefinition("_qt_rcc_inputs_" + target->GetName()));
-  makefile->ConfigureFile(inputFile.c_str(), outputFile.c_str(),
-                          false, true, false);
+  std::vector<std::string> qrcEntries;
 
-  // Ensure we have write permission in case .in was read-only.
-  mode_t perm = 0;
-#if defined(_WIN32) && !defined(__CYGWIN__)
-  mode_t mode_write = S_IWRITE;
-#else
-  mode_t mode_write = S_IWUSR;
-#endif
-  cmSystemTools::GetPermissions(outputFile, perm);
-  if (!(perm & mode_write))
+  std::vector<std::string> command;
+  command.push_back(rccCommand);
+  command.push_back(hasDashDashList? "--list" : "-list");
+
+  std::string absFile = cmsys::SystemTools::GetRealPath(
+                                              sf->GetFullPath());
+
+  command.push_back(absFile);
+
+  std::string rccStdOut;
+  std::string rccStdErr;
+  int retVal = 0;
+  bool result = cmSystemTools::RunSingleCommand(
+    command, &rccStdOut, &rccStdErr,
+    &retVal, 0, cmSystemTools::OUTPUT_NONE);
+  if (!result || retVal)
     {
-    cmSystemTools::SetPermissions(outputFile, perm | mode_write);
+    std::cerr << "AUTOGEN: error: Rcc list process for " << sf->GetFullPath()
+              << " failed:\n" << rccStdOut << "\n" << rccStdErr << std::endl;
+    return std::string();
     }
-  if (!configDefines.empty()
-      || !configIncludes.empty()
-      || !configUicOptions.empty())
+
+  {
+  std::istringstream ostr(rccStdOut);
+  std::string oline;
+  while(std::getline(ostr, oline))
     {
-    cmsys::ofstream infoFile(outputFile.c_str(), std::ios::app);
-    if ( !infoFile )
-      {
-      std::string error = "Internal CMake error when trying to open file: ";
-      error += outputFile.c_str();
-      error += " for writing.";
-      cmSystemTools::Error(error.c_str());
-      return;
-      }
-    if (!configDefines.empty())
-      {
-      for (std::map<std::string, std::string>::iterator
-            it = configDefines.begin(), end = configDefines.end();
-            it != end; ++it)
-        {
-        infoFile << "set(AM_MOC_COMPILE_DEFINITIONS_" << it->first <<
-          " " << it->second << ")\n";
-        }
-      }
-    if (!configIncludes.empty())
-      {
-      for (std::map<std::string, std::string>::iterator
-            it = configIncludes.begin(), end = configIncludes.end();
-            it != end; ++it)
-        {
-        infoFile << "set(AM_MOC_INCLUDES_" << it->first <<
-          " " << it->second << ")\n";
-        }
+    oline = cmQtAutoGeneratorsStripCR(oline);
+    if(!oline.empty())
+      {
+      qrcEntries.push_back(oline);
       }
-    if (!configUicOptions.empty())
+    }
+  }
+
+  {
+  std::istringstream estr(rccStdErr);
+  std::string eline;
+  while(std::getline(estr, eline))
+    {
+    eline = cmQtAutoGeneratorsStripCR(eline);
+    if (cmHasLiteralPrefix(eline, "RCC: Error in"))
       {
-      for (std::map<std::string, std::string>::iterator
-            it = configUicOptions.begin(), end = configUicOptions.end();
-            it != end; ++it)
+      static std::string searchString = "Cannot find file '";
+
+      std::string::size_type pos = eline.find(searchString);
+      if (pos == std::string::npos)
         {
-        infoFile << "set(AM_UIC_TARGET_OPTIONS_" << it->first <<
-          " " << it->second << ")\n";
+        std::cerr << "AUTOGEN: error: Rcc lists unparsable output "
+                  << eline << std::endl;
+        return std::string();
         }
+      pos += searchString.length();
+      std::string::size_type sz = eline.size() - pos - 1;
+      qrcEntries.push_back(eline.substr(pos, sz));
       }
     }
+  }
+
+  depends.insert(depends.end(), qrcEntries.begin(), qrcEntries.end());
+  return cmJoin(qrcEntries, "@list_sep@");
 }
 
-void cmQtAutoGeneratorInitializer::SetupSourceFiles(cmTarget const* target,
-                                   std::vector<std::string>& skipMoc,
-                                   std::vector<std::string>& mocSources,
-                                   std::vector<std::string>& mocHeaders,
-                                   std::vector<std::string>& skipUic)
+static std::string ListQt4RccInputs(cmSourceFile* sf,
+                                            std::vector<std::string>& depends)
 {
-  cmMakefile* makefile = target->GetMakefile();
+  const std::string qrcContents = ReadAll(sf->GetFullPath());
 
-  std::vector<cmSourceFile*> srcFiles;
-  cmGeneratorTarget *gtgt = target->GetMakefile()
-                                  ->GetGlobalGenerator()
-                                  ->GetGeneratorTarget(target);
-  gtgt->GetConfigCommonSourceFiles(srcFiles);
+  cmsys::RegularExpression fileMatchRegex("(<file[^<]+)");
 
-  std::vector<std::string> newRccFiles;
+  std::string entriesList;
+  const char* sep = "";
 
-  for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
-      fileIt != srcFiles.end();
-      ++fileIt)
+  size_t offset = 0;
+  while (fileMatchRegex.find(qrcContents.c_str() + offset))
     {
-    cmSourceFile* sf = *fileIt;
-    std::string absFile = cmsys::SystemTools::GetRealPath(
-                                                    sf->GetFullPath());
-    bool skipFileForMoc =
-        cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC"));
-    bool generated = cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"));
-
-    if(cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOUIC")))
-      {
-      skipUic.push_back(absFile);
-      }
+    std::string qrcEntry = fileMatchRegex.match(1);
 
-    std::string ext = sf->GetExtension();
+    offset += qrcEntry.size();
 
-    if (target->GetPropertyAsBool("AUTORCC"))
-      {
-      if (ext == "qrc"
-          && !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC")))
-        {
-        std::string basename = cmsys::SystemTools::
-                                      GetFilenameWithoutLastExtension(absFile);
+    cmsys::RegularExpression fileReplaceRegex("(^<file[^>]*>)");
+    fileReplaceRegex.find(qrcEntry);
+    std::string tag = fileReplaceRegex.match(1);
 
-        std::string rcc_output_dir = target->GetSupportDirectory();
-        cmSystemTools::MakeDirectory(rcc_output_dir.c_str());
-        std::string rcc_output_file = rcc_output_dir;
-        rcc_output_file += "/qrc_" + basename + ".cpp";
-        makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
-                                rcc_output_file.c_str(), false);
-        makefile->GetOrCreateSource(rcc_output_file, true);
-        newRccFiles.push_back(rcc_output_file);
-        }
-      }
+    qrcEntry = qrcEntry.substr(tag.size());
 
-    if (!generated)
+    if (!cmSystemTools::FileIsFullPath(qrcEntry.c_str()))
       {
-      if (skipFileForMoc)
-        {
-        skipMoc.push_back(absFile);
-        }
-      else
-        {
-        cmSystemTools::FileFormat fileType = cmSystemTools::GetFileFormat(
-                                                                ext.c_str());
-        if (fileType == cmSystemTools::CXX_FILE_FORMAT)
-          {
-          mocSources.push_back(absFile);
-          }
-        else if (fileType == cmSystemTools::HEADER_FILE_FORMAT)
-          {
-          mocHeaders.push_back(absFile);
-          }
-        }
+      qrcEntry = sf->GetLocation().GetDirectory() + "/" + qrcEntry;
       }
-    }
 
-  for(std::vector<std::string>::const_iterator fileIt = newRccFiles.begin();
-      fileIt != newRccFiles.end();
-      ++fileIt)
-    {
-    const_cast<cmTarget*>(target)->AddSource(*fileIt);
+    entriesList += sep;
+    entriesList += qrcEntry;
+    sep = "@list_sep@";
+    depends.push_back(qrcEntry);
     }
+  return entriesList;
 }
 
-void cmQtAutoGeneratorInitializer::SetupAutoMocTarget(cmTarget const* target,
-                          const std::string &autogenTargetName,
-                          std::vector<std::string> const& skipMoc,
-                          std::vector<std::string> const& mocHeaders,
-                          std::map<std::string, std::string> &configIncludes,
-                          std::map<std::string, std::string> &configDefines)
+static void SetupAutoRccTarget(cmGeneratorTarget const* target)
 {
-  cmMakefile* makefile = target->GetMakefile();
+  std::string _rcc_files;
+  const char* sepRccFiles = "";
+  cmMakefile *makefile = target->Target->GetMakefile();
 
-  const char* tmp = target->GetProperty("AUTOMOC_MOC_OPTIONS");
-  std::string _moc_options = (tmp!=0 ? tmp : "");
-  makefile->AddDefinition("_moc_options",
-          cmOutputConverter::EscapeForCMake(_moc_options).c_str());
-  makefile->AddDefinition("_skip_moc",
-          cmOutputConverter::EscapeForCMake(cmJoin(skipMoc, ";")).c_str());
-  makefile->AddDefinition("_moc_headers",
-          cmOutputConverter::EscapeForCMake(cmJoin(mocHeaders, ";")).c_str());
-  bool relaxedMode = makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE");
-  makefile->AddDefinition("_moc_relaxed_mode", relaxedMode ? "TRUE" : "FALSE");
+  std::vector<cmSourceFile*> srcFiles;
+  target->GetConfigCommonSourceFiles(srcFiles);
 
-  std::string _moc_incs;
-  std::string _moc_compile_defs;
-  std::vector<std::string> configs;
-  const std::string& config = makefile->GetConfigurations(configs);
-  GetCompileDefinitionsAndDirectories(target, config,
-                                      _moc_incs, _moc_compile_defs);
+  std::string qrcInputs;
+  const char* qrcInputsSep = "";
 
-  makefile->AddDefinition("_moc_incs",
-          cmOutputConverter::EscapeForCMake(_moc_incs).c_str());
-  makefile->AddDefinition("_moc_compile_defs",
-          cmOutputConverter::EscapeForCMake(_moc_compile_defs).c_str());
+  std::string rccFileFiles;
+  std::string rccFileOptions;
+  const char *optionSep = "";
 
-  for (std::vector<std::string>::const_iterator li = configs.begin();
-       li != configs.end(); ++li)
+  const char *qtVersion = makefile->GetDefinition("_target_qt_version");
+
+  std::vector<std::string> rccOptions;
+  if (const char* opts = target->GetProperty("AUTORCC_OPTIONS"))
     {
-    std::string config_moc_incs;
-    std::string config_moc_compile_defs;
-    GetCompileDefinitionsAndDirectories(target, *li,
-                                        config_moc_incs,
-                                        config_moc_compile_defs);
-    if (config_moc_incs != _moc_incs)
-      {
-      configIncludes[*li] =
-                    cmOutputConverter::EscapeForCMake(config_moc_incs);
-      if(_moc_incs.empty())
-        {
-        _moc_incs = config_moc_incs;
-        }
-      }
-    if (config_moc_compile_defs != _moc_compile_defs)
-      {
-      configDefines[*li] =
-            cmOutputConverter::EscapeForCMake(config_moc_compile_defs);
-      if(_moc_compile_defs.empty())
-        {
-        _moc_compile_defs = config_moc_compile_defs;
-        }
-      }
+    cmSystemTools::ExpandListArgument(opts, rccOptions);
     }
-
-  const char *qtVersion = makefile->GetDefinition("_target_qt_version");
-  if (strcmp(qtVersion, "5") == 0)
+  std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
+  if (qtMajorVersion == "")
     {
-    cmTarget *qt5Moc = makefile->FindTargetToUse("Qt5::moc");
-    if (!qt5Moc)
-      {
-      cmSystemTools::Error("Qt5::moc target not found ",
-                          autogenTargetName.c_str());
-      return;
-      }
-    makefile->AddDefinition("_qt_moc_executable",
-                            qt5Moc->ImportedGetLocation(""));
+    qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR");
     }
-  else if (strcmp(qtVersion, "4") == 0)
+
+  for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
+      fileIt != srcFiles.end();
+      ++fileIt)
     {
-    cmTarget *qt4Moc = makefile->FindTargetToUse("Qt4::moc");
-    if (!qt4Moc)
+    cmSourceFile* sf = *fileIt;
+    std::string ext = sf->GetExtension();
+    if (ext == "qrc")
       {
-      cmSystemTools::Error("Qt4::moc target not found ",
-                          autogenTargetName.c_str());
-      return;
+      std::string absFile = cmsys::SystemTools::GetRealPath(
+                                                  sf->GetFullPath());
+      bool skip = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"));
+
+      if (!skip)
+        {
+        _rcc_files += sepRccFiles;
+        _rcc_files += absFile;
+        sepRccFiles = ";";
+
+        if (const char *prop = sf->GetProperty("AUTORCC_OPTIONS"))
+          {
+          std::vector<std::string> optsVec;
+          cmSystemTools::ExpandListArgument(prop, optsVec);
+          MergeRccOptions(rccOptions, optsVec,
+                                strcmp(qtVersion, "5") == 0);
+          }
+
+        if (!rccOptions.empty())
+          {
+          rccFileFiles += optionSep;
+          rccFileFiles += absFile;
+          rccFileOptions += optionSep;
+          }
+        const char *listSep = "";
+        for(std::vector<std::string>::const_iterator it = rccOptions.begin();
+            it != rccOptions.end();
+            ++it)
+          {
+          rccFileOptions += listSep;
+          rccFileOptions += *it;
+          listSep = "@list_sep@";
+          }
+        optionSep = ";";
+
+        std::vector<std::string> depends;
+
+        std::string entriesList;
+        if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED")))
+          {
+          if (qtMajorVersion == "5")
+            {
+            entriesList = ListQt5RccInputs(sf, target, depends);
+            }
+          else
+            {
+            entriesList = ListQt4RccInputs(sf, depends);
+            }
+          if (entriesList.empty())
+            {
+            return;
+            }
+          }
+        qrcInputs += qrcInputsSep;
+        qrcInputs += entriesList;
+        qrcInputsSep = ";";
+        }
       }
-    makefile->AddDefinition("_qt_moc_executable",
-                            qt4Moc->ImportedGetLocation(""));
-    }
-  else
-    {
-    cmSystemTools::Error("The CMAKE_AUTOMOC feature supports only Qt 4 and "
-                        "Qt 5 ", autogenTargetName.c_str());
     }
+  makefile->AddDefinition("_qt_rcc_inputs_" + target->GetName(),
+                      cmOutputConverter::EscapeForCMake(qrcInputs).c_str());
+
+  makefile->AddDefinition("_rcc_files",
+          cmOutputConverter::EscapeForCMake(_rcc_files).c_str());
+
+  makefile->AddDefinition("_qt_rcc_options_files",
+              cmOutputConverter::EscapeForCMake(rccFileFiles).c_str());
+  makefile->AddDefinition("_qt_rcc_options_options",
+            cmOutputConverter::EscapeForCMake(rccFileOptions).c_str());
+
+  makefile->AddDefinition("_qt_rcc_executable",
+              GetRccExecutable(target).c_str());
 }
 
-static void GetUicOpts(cmTarget const* target, const std::string& config,
-                       std::string &optString)
+void cmQtAutoGeneratorInitializer::InitializeAutogenSources(
+    cmGeneratorTarget* target)
 {
-  cmGeneratorTarget *gtgt = target->GetMakefile()
-                                  ->GetGlobalGenerator()
-                                  ->GetGeneratorTarget(target);
-  std::vector<std::string> opts;
-  gtgt->GetAutoUicOptions(opts, config);
-  optString = cmJoin(opts, ";");
+  cmMakefile* makefile = target->Target->GetMakefile();
+
+  if (target->GetPropertyAsBool("AUTOMOC"))
+    {
+    std::string automocTargetName = GetAutogenTargetName(target);
+    std::string mocCppFile = makefile->GetCurrentBinaryDirectory();
+    mocCppFile += "/";
+    mocCppFile += automocTargetName;
+    mocCppFile += ".cpp";
+    makefile->GetOrCreateSource(mocCppFile, true);
+    makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
+                            mocCppFile.c_str(), false);
+
+    target->AddSource(mocCppFile);
+    }
 }
 
-void cmQtAutoGeneratorInitializer::SetupAutoUicTarget(cmTarget const* target,
-                          std::vector<std::string> const& skipUic,
-                          std::map<std::string, std::string> &configUicOptions)
+void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
+                                                 cmLocalGenerator* lg,
+                                                 cmGeneratorTarget* target)
 {
-  cmMakefile *makefile = target->GetMakefile();
+  cmMakefile* makefile = target->Target->GetMakefile();
 
-  std::set<std::string> skipped;
-  skipped.insert(skipUic.begin(), skipUic.end());
+  std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
+  if (qtMajorVersion == "")
+    {
+    qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR");
+    }
 
-  makefile->AddDefinition("_skip_uic",
-          cmOutputConverter::EscapeForCMake(cmJoin(skipUic, ";")).c_str());
+  // create a custom target for running generators at buildtime:
+  std::string autogenTargetName = GetAutogenTargetName(target);
 
-  std::vector<cmSourceFile*> uiFilesWithOptions
-                                        = makefile->GetQtUiFilesWithOptions();
+  std::string targetDir = GetAutogenTargetDir(target);
 
-  const char *qtVersion = makefile->GetDefinition("_target_qt_version");
+  cmCustomCommandLine currentLine;
+  currentLine.push_back(cmSystemTools::GetCMakeCommand());
+  currentLine.push_back("-E");
+  currentLine.push_back("cmake_autogen");
+  currentLine.push_back(targetDir);
+  currentLine.push_back("$<CONFIGURATION>");
 
-  std::string _uic_opts;
-  std::vector<std::string> configs;
-  const std::string& config = makefile->GetConfigurations(configs);
-  GetUicOpts(target, config, _uic_opts);
+  cmCustomCommandLines commandLines;
+  commandLines.push_back(currentLine);
 
-  if (!_uic_opts.empty())
+  std::string workingDirectory = cmSystemTools::CollapseFullPath(
+                                    "", makefile->GetCurrentBinaryDirectory());
+
+  std::vector<std::string> depends;
+  if (const char *autogenDepends =
+                                target->GetProperty("AUTOGEN_TARGET_DEPENDS"))
     {
-    _uic_opts = cmOutputConverter::EscapeForCMake(_uic_opts);
-    makefile->AddDefinition("_uic_target_options", _uic_opts.c_str());
+    cmSystemTools::ExpandListArgument(autogenDepends, depends);
     }
-  for (std::vector<std::string>::const_iterator li = configs.begin();
-       li != configs.end(); ++li)
+  std::vector<std::string> toolNames;
+  if (target->GetPropertyAsBool("AUTOMOC"))
     {
-    std::string config_uic_opts;
-    GetUicOpts(target, *li, config_uic_opts);
-    if (config_uic_opts != _uic_opts)
-      {
-      configUicOptions[*li] =
-                    cmOutputConverter::EscapeForCMake(config_uic_opts);
-      if(_uic_opts.empty())
-        {
-        _uic_opts = config_uic_opts;
-        }
-      }
+    toolNames.push_back("moc");
     }
-
-  std::string uiFileFiles;
-  std::string uiFileOptions;
-  const char* sep = "";
-
-  for(std::vector<cmSourceFile*>::const_iterator fileIt =
-      uiFilesWithOptions.begin();
-      fileIt != uiFilesWithOptions.end();
-      ++fileIt)
+  if (target->GetPropertyAsBool("AUTOUIC"))
     {
-    cmSourceFile* sf = *fileIt;
-    std::string absFile = cmsys::SystemTools::GetRealPath(
-                                                    sf->GetFullPath());
-
-    if (!skipped.insert(absFile).second)
-      {
-      continue;
-      }
-    uiFileFiles += sep;
-    uiFileFiles += absFile;
-    uiFileOptions += sep;
-    std::string opts = sf->GetProperty("AUTOUIC_OPTIONS");
-    cmSystemTools::ReplaceString(opts, ";", "@list_sep@");
-    uiFileOptions += opts;
-    sep = ";";
+    toolNames.push_back("uic");
+    }
+  if (target->GetPropertyAsBool("AUTORCC"))
+    {
+    toolNames.push_back("rcc");
     }
 
-  makefile->AddDefinition("_qt_uic_options_files",
-              cmOutputConverter::EscapeForCMake(uiFileFiles).c_str());
-  makefile->AddDefinition("_qt_uic_options_options",
-            cmOutputConverter::EscapeForCMake(uiFileOptions).c_str());
+  std::string tools = toolNames[0];
+  toolNames.erase(toolNames.begin());
+  while (toolNames.size() > 1)
+    {
+    tools += ", " + toolNames[0];
+    toolNames.erase(toolNames.begin());
+    }
+  if (toolNames.size() == 1)
+    {
+    tools += " and " + toolNames[0];
+    }
+  std::string autogenComment = "Automatic " + tools + " for target ";
+  autogenComment += target->GetName();
 
-  std::string targetName = target->GetName();
-  if (strcmp(qtVersion, "5") == 0)
+#if defined(_WIN32) && !defined(__CYGWIN__)
+  bool usePRE_BUILD = false;
+  cmGlobalGenerator* gg = lg->GetGlobalGenerator();
+  if(gg->GetName().find("Visual Studio") != std::string::npos)
     {
-    cmTarget *qt5Uic = makefile->FindTargetToUse("Qt5::uic");
-    if (!qt5Uic)
-      {
-      // Project does not use Qt5Widgets, but has AUTOUIC ON anyway
-      }
-    else
+    cmGlobalVisualStudioGenerator* vsgg =
+      static_cast<cmGlobalVisualStudioGenerator*>(gg);
+    // Under VS >= 7 use a PRE_BUILD event instead of a separate target to
+    // reduce the number of targets loaded into the IDE.
+    // This also works around a VS 11 bug that may skip updating the target:
+    //  https://connect.microsoft.com/VisualStudio/feedback/details/769495
+    usePRE_BUILD = vsgg->GetVersion() >= cmGlobalVisualStudioGenerator::VS7;
+    if(usePRE_BUILD)
       {
-      makefile->AddDefinition("_qt_uic_executable",
-                              qt5Uic->ImportedGetLocation(""));
+      for (std::vector<std::string>::iterator it = depends.begin();
+            it != depends.end(); ++it)
+        {
+        if(!makefile->FindTargetToUse(it->c_str()))
+          {
+          usePRE_BUILD = false;
+          break;
+          }
+        }
       }
     }
-  else if (strcmp(qtVersion, "4") == 0)
+#endif
+
+  std::vector<std::string> rcc_output;
+  bool const isNinja =
+    lg->GetGlobalGenerator()->GetName() == "Ninja";
+  if(isNinja
+#if defined(_WIN32) && !defined(__CYGWIN__)
+        || usePRE_BUILD
+#endif
+        )
     {
-    cmTarget *qt4Uic = makefile->FindTargetToUse("Qt4::uic");
-    if (!qt4Uic)
+    std::vector<cmSourceFile*> srcFiles;
+    target->GetConfigCommonSourceFiles(srcFiles);
+    for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
+        fileIt != srcFiles.end();
+        ++fileIt)
       {
-      cmSystemTools::Error("Qt4::uic target not found ",
-                          targetName.c_str());
-      return;
+      cmSourceFile* sf = *fileIt;
+      std::string absFile = cmsys::SystemTools::GetRealPath(
+                                                sf->GetFullPath());
+
+      std::string ext = sf->GetExtension();
+
+      if (target->GetPropertyAsBool("AUTORCC"))
+        {
+        if (ext == "qrc"
+            && !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC")))
+          {
+          std::string basename = cmsys::SystemTools::
+                                  GetFilenameWithoutLastExtension(absFile);
+
+          std::string rcc_output_dir = target->GetSupportDirectory();
+          cmSystemTools::MakeDirectory(rcc_output_dir.c_str());
+          std::string rcc_output_file = rcc_output_dir;
+          rcc_output_file += "/qrc_" + basename + ".cpp";
+          rcc_output.push_back(rcc_output_file);
+
+          if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED")))
+            {
+            if (qtMajorVersion == "5")
+              {
+              ListQt5RccInputs(sf, target, depends);
+              }
+            else
+              {
+              ListQt4RccInputs(sf, depends);
+              }
+#if defined(_WIN32) && !defined(__CYGWIN__)
+            // Cannot use PRE_BUILD because the resource files themselves
+            // may not be sources within the target so VS may not know the
+            // target needs to re-build at all.
+            usePRE_BUILD = false;
+#endif
+            }
+          }
+        }
       }
-    makefile->AddDefinition("_qt_uic_executable",
-                            qt4Uic->ImportedGetLocation(""));
     }
-  else
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+  if(usePRE_BUILD)
     {
-    cmSystemTools::Error("The CMAKE_AUTOUIC feature supports only Qt 4 and "
-                        "Qt 5 ", targetName.c_str());
+    // Add the pre-build command directly to bypass the OBJECT_LIBRARY
+    // rejection in cmMakefile::AddCustomCommandToTarget because we know
+    // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case.
+    std::vector<std::string> no_output;
+    std::vector<std::string> no_byproducts;
+    cmCustomCommand cc(makefile, no_output, no_byproducts, depends,
+                       commandLines, autogenComment.c_str(),
+                       workingDirectory.c_str());
+    cc.SetEscapeOldStyle(false);
+    cc.SetEscapeAllowMakeVars(true);
+    target->Target->AddPreBuildCommand(cc);
     }
-}
-
-void cmQtAutoGeneratorInitializer::MergeRccOptions(
-                         std::vector<std::string> &opts,
-                         const std::vector<std::string> &fileOpts,
-                         bool isQt5)
-{
-  static const char* valueOptions[] = {
-    "name",
-    "root",
-    "compress",
-    "threshold"
-  };
-  std::vector<std::string> extraOpts;
-  for(std::vector<std::string>::const_iterator it = fileOpts.begin();
-      it != fileOpts.end(); ++it)
+  else
+#endif
     {
-    std::vector<std::string>::iterator existingIt
-                                  = std::find(opts.begin(), opts.end(), *it);
-    if (existingIt != opts.end())
+    cmTarget* autogenTarget = makefile->AddUtilityCommand(
+                                autogenTargetName, true,
+                                workingDirectory.c_str(),
+                                /*byproducts=*/rcc_output, depends,
+                                commandLines, false, autogenComment.c_str());
+
+    cmGeneratorTarget* gt = new cmGeneratorTarget(autogenTarget, lg);
+    lg->AddGeneratorTarget(gt);
+
+    // Set target folder
+    const char* autogenFolder = makefile->GetState()
+                                ->GetGlobalProperty("AUTOMOC_TARGETS_FOLDER");
+    if (!autogenFolder)
       {
-      const char *o = it->c_str();
-      if (*o == '-')
-        {
-        ++o;
-        }
-      if (isQt5 && *o == '-')
-        {
-        ++o;
-        }
-      if (std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions),
-                  cmStrCmp(*it)) != cmArrayEnd(valueOptions))
-        {
-        assert(existingIt + 1 != opts.end());
-        *(existingIt + 1) = *(it + 1);
-        ++it;
-        }
+      autogenFolder = makefile->GetState()
+                                ->GetGlobalProperty("AUTOGEN_TARGETS_FOLDER");
+      }
+    if (autogenFolder && *autogenFolder)
+      {
+      autogenTarget->SetProperty("FOLDER", autogenFolder);
       }
     else
       {
-      extraOpts.push_back(*it);
+      // inherit FOLDER property from target (#13688)
+      copyTargetProperty(gt->Target, target->Target, "FOLDER");
       }
+
+    target->Target->AddUtility(autogenTargetName);
     }
-  opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
 }
 
-void cmQtAutoGeneratorInitializer::SetupAutoRccTarget(cmTarget const* target)
+void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget(
+    cmGeneratorTarget const* target)
 {
-  std::string _rcc_files;
-  const char* sepRccFiles = "";
-  cmMakefile *makefile = target->GetMakefile();
+  cmMakefile* makefile = target->Target->GetMakefile();
 
-  std::vector<cmSourceFile*> srcFiles;
-  cmGeneratorTarget *gtgt = target->GetMakefile()
-                                  ->GetGlobalGenerator()
-                                  ->GetGeneratorTarget(target);
-  gtgt->GetConfigCommonSourceFiles(srcFiles);
+  // forget the variables added here afterwards again:
+  cmMakefile::ScopePushPop varScope(makefile);
+  static_cast<void>(varScope);
 
-  std::string qrcInputs;
-  const char* qrcInputsSep = "";
+  // create a custom target for running generators at buildtime:
+  std::string autogenTargetName = GetAutogenTargetName(target);
 
-  std::string rccFileFiles;
-  std::string rccFileOptions;
-  const char *optionSep = "";
+  makefile->AddDefinition("_moc_target_name",
+          cmOutputConverter::EscapeForCMake(autogenTargetName).c_str());
+  makefile->AddDefinition("_origin_target_name",
+          cmOutputConverter::EscapeForCMake(target->GetName()).c_str());
 
-  const char *qtVersion = makefile->GetDefinition("_target_qt_version");
+  std::string targetDir = GetAutogenTargetDir(target);
 
-  std::vector<std::string> rccOptions;
-  if (const char* opts = target->GetProperty("AUTORCC_OPTIONS"))
+  const char *qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR");
+  if (!qtVersion)
     {
-    cmSystemTools::ExpandListArgument(opts, rccOptions);
+    qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR");
     }
-  std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
-  if (qtMajorVersion == "")
+  if (const char *targetQtVersion =
+      target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", ""))
     {
-    qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR");
+    qtVersion = targetQtVersion;
     }
-
-  for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
-      fileIt != srcFiles.end();
-      ++fileIt)
+  if (qtVersion)
     {
-    cmSourceFile* sf = *fileIt;
-    std::string ext = sf->GetExtension();
-    if (ext == "qrc")
-      {
-      std::string absFile = cmsys::SystemTools::GetRealPath(
-                                                  sf->GetFullPath());
-      bool skip = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"));
-
-      if (!skip)
-        {
-        _rcc_files += sepRccFiles;
-        _rcc_files += absFile;
-        sepRccFiles = ";";
-
-        if (const char *prop = sf->GetProperty("AUTORCC_OPTIONS"))
-          {
-          std::vector<std::string> optsVec;
-          cmSystemTools::ExpandListArgument(prop, optsVec);
-          cmQtAutoGeneratorInitializer::MergeRccOptions(rccOptions, optsVec,
-                                strcmp(qtVersion, "5") == 0);
-          }
-
-        if (!rccOptions.empty())
-          {
-          rccFileFiles += optionSep;
-          rccFileFiles += absFile;
-          rccFileOptions += optionSep;
-          }
-        const char *listSep = "";
-        for(std::vector<std::string>::const_iterator it = rccOptions.begin();
-            it != rccOptions.end();
-            ++it)
-          {
-          rccFileOptions += listSep;
-          rccFileOptions += *it;
-          listSep = "@list_sep@";
-          }
-        optionSep = ";";
-
-        std::vector<std::string> depends;
-
-        std::string entriesList;
-        if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED")))
-          {
-          if (qtMajorVersion == "5")
-            {
-            entriesList = cmQtAutoGeneratorInitializer::ListQt5RccInputs(sf,
-                                                               target,
-                                                               depends);
-            }
-          else
-            {
-            entriesList =
-                cmQtAutoGeneratorInitializer::ListQt4RccInputs(sf, depends);
-            }
-          if (entriesList.empty())
-            {
-            return;
-            }
-          }
-        qrcInputs += qrcInputsSep;
-        qrcInputs += entriesList;
-        qrcInputsSep = ";";
-        }
-      }
+    makefile->AddDefinition("_target_qt_version", qtVersion);
     }
-  makefile->AddDefinition("_qt_rcc_inputs_" + target->GetName(),
-                      cmOutputConverter::EscapeForCMake(qrcInputs).c_str());
 
-  makefile->AddDefinition("_rcc_files",
-          cmOutputConverter::EscapeForCMake(_rcc_files).c_str());
+  std::vector<std::string> skipUic;
+  std::vector<std::string> skipMoc;
+  std::vector<std::string> mocSources;
+  std::vector<std::string> mocHeaders;
+  std::map<std::string, std::string> configIncludes;
+  std::map<std::string, std::string> configDefines;
+  std::map<std::string, std::string> configUicOptions;
 
-  makefile->AddDefinition("_qt_rcc_options_files",
-              cmOutputConverter::EscapeForCMake(rccFileFiles).c_str());
-  makefile->AddDefinition("_qt_rcc_options_options",
-            cmOutputConverter::EscapeForCMake(rccFileOptions).c_str());
+  if (target->GetPropertyAsBool("AUTOMOC")
+      || target->GetPropertyAsBool("AUTOUIC")
+      || target->GetPropertyAsBool("AUTORCC"))
+    {
+    SetupSourceFiles(target, skipMoc, mocSources, mocHeaders, skipUic);
+    }
+  makefile->AddDefinition("_cpp_files",
+          cmOutputConverter::EscapeForCMake(cmJoin(mocSources, ";")).c_str());
+  if (target->GetPropertyAsBool("AUTOMOC"))
+    {
+    SetupAutoMocTarget(target, autogenTargetName,
+                             skipMoc, mocHeaders,
+                             configIncludes, configDefines);
+    }
+  if (target->GetPropertyAsBool("AUTOUIC"))
+    {
+    SetupAutoUicTarget(target, skipUic, configUicOptions);
+    }
+  if (target->GetPropertyAsBool("AUTORCC"))
+    {
+    SetupAutoRccTarget(target);
+    }
 
-  makefile->AddDefinition("_qt_rcc_executable",
-              cmQtAutoGeneratorInitializer::GetRccExecutable(target).c_str());
-}
+  const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT");
+  std::string inputFile = cmakeRoot;
+  inputFile += "/Modules/AutogenInfo.cmake.in";
+  std::string outputFile = targetDir;
+  outputFile += "/AutogenInfo.cmake";
+  makefile->AddDefinition("_qt_rcc_inputs",
+              makefile->GetDefinition("_qt_rcc_inputs_" + target->GetName()));
+  makefile->ConfigureFile(inputFile.c_str(), outputFile.c_str(),
+                          false, true, false);
 
-std::string cmQtAutoGeneratorInitializer::GetRccExecutable(
-    cmTarget const* target)
-{
-  cmGeneratorTarget *gtgt = target->GetMakefile()
-                                  ->GetGlobalGenerator()
-                                  ->GetGeneratorTarget(target);
-  cmMakefile *makefile = target->GetMakefile();
-  const char *qtVersion = makefile->GetDefinition("_target_qt_version");
-  if (!qtVersion)
+  // Ensure we have write permission in case .in was read-only.
+  mode_t perm = 0;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+  mode_t mode_write = S_IWRITE;
+#else
+  mode_t mode_write = S_IWUSR;
+#endif
+  cmSystemTools::GetPermissions(outputFile, perm);
+  if (!(perm & mode_write))
     {
-    qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR");
-    if (!qtVersion)
+    cmSystemTools::SetPermissions(outputFile, perm | mode_write);
+    }
+  if (!configDefines.empty()
+      || !configIncludes.empty()
+      || !configUicOptions.empty())
+    {
+    cmsys::ofstream infoFile(outputFile.c_str(), std::ios::app);
+    if ( !infoFile )
       {
-      qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR");
+      std::string error = "Internal CMake error when trying to open file: ";
+      error += outputFile.c_str();
+      error += " for writing.";
+      cmSystemTools::Error(error.c_str());
+      return;
       }
-    if (const char *targetQtVersion =
-        gtgt->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", ""))
+    if (!configDefines.empty())
       {
-      qtVersion = targetQtVersion;
+      for (std::map<std::string, std::string>::iterator
+            it = configDefines.begin(), end = configDefines.end();
+            it != end; ++it)
+        {
+        infoFile << "set(AM_MOC_COMPILE_DEFINITIONS_" << it->first <<
+          " " << it->second << ")\n";
+        }
       }
-    }
-
-  std::string targetName = target->GetName();
-  if (strcmp(qtVersion, "5") == 0)
-    {
-    cmTarget *qt5Rcc = makefile->FindTargetToUse("Qt5::rcc");
-    if (!qt5Rcc)
+    if (!configIncludes.empty())
       {
-      cmSystemTools::Error("Qt5::rcc target not found ",
-                          targetName.c_str());
-      return std::string();
+      for (std::map<std::string, std::string>::iterator
+            it = configIncludes.begin(), end = configIncludes.end();
+            it != end; ++it)
+        {
+        infoFile << "set(AM_MOC_INCLUDES_" << it->first <<
+          " " << it->second << ")\n";
+        }
       }
-    return qt5Rcc->ImportedGetLocation("");
-    }
-  else if (strcmp(qtVersion, "4") == 0)
-    {
-    cmTarget *qt4Rcc = makefile->FindTargetToUse("Qt4::rcc");
-    if (!qt4Rcc)
+    if (!configUicOptions.empty())
       {
-      cmSystemTools::Error("Qt4::rcc target not found ",
-                          targetName.c_str());
-      return std::string();
+      for (std::map<std::string, std::string>::iterator
+            it = configUicOptions.begin(), end = configUicOptions.end();
+            it != end; ++it)
+        {
+        infoFile << "set(AM_UIC_TARGET_OPTIONS_" << it->first <<
+          " " << it->second << ")\n";
+        }
       }
-    return qt4Rcc->ImportedGetLocation("");
     }
-
-  cmSystemTools::Error("The CMAKE_AUTORCC feature supports only Qt 4 and "
-                      "Qt 5 ", targetName.c_str());
-  return std::string();
 }
diff --git a/Source/cmQtAutoGeneratorInitializer.h b/Source/cmQtAutoGeneratorInitializer.h
index c22f172..eaf140d 100644
--- a/Source/cmQtAutoGeneratorInitializer.h
+++ b/Source/cmQtAutoGeneratorInitializer.h
@@ -21,47 +21,16 @@
 #include <map>
 
 class cmSourceFile;
-class cmTarget;
+class cmGeneratorTarget;
 class cmLocalGenerator;
 
 class cmQtAutoGeneratorInitializer
 {
 public:
-  static void InitializeAutogenSources(cmTarget* target);
-  static void InitializeAutogenTarget(cmLocalGenerator* lg, cmTarget* target);
-  static void SetupAutoGenerateTarget(cmTarget const* target);
-
-  static std::string GetAutogenTargetName(cmTarget const* target);
-  static std::string GetAutogenTargetDir(cmTarget const* target);
-
-private:
-  static void SetupSourceFiles(cmTarget const* target,
-                        std::vector<std::string>& skipMoc,
-                        std::vector<std::string>& mocSources,
-                        std::vector<std::string>& mocHeaders,
-                        std::vector<std::string>& skipUic);
-
-  static void SetupAutoMocTarget(cmTarget const* target,
-                          const std::string &autogenTargetName,
-                          const std::vector<std::string>& skipMoc,
-                          const std::vector<std::string>& mocHeaders,
-                          std::map<std::string, std::string> &configIncludes,
-                          std::map<std::string, std::string> &configDefines);
-  static void SetupAutoUicTarget(cmTarget const* target,
-                        const std::vector<std::string>& skipUic,
-                        std::map<std::string, std::string> &configUicOptions);
-  static void SetupAutoRccTarget(cmTarget const* target);
-
-  static void MergeRccOptions(std::vector<std::string> &opts,
-                       const std::vector<std::string> &fileOpts, bool isQt5);
-
-  static std::string GetRccExecutable(cmTarget const* target);
-
-  static std::string ListQt5RccInputs(cmSourceFile* sf, cmTarget const* target,
-                               std::vector<std::string>& depends);
-
-  static std::string ListQt4RccInputs(cmSourceFile* sf,
-                               std::vector<std::string>& depends);
+  static void InitializeAutogenSources(cmGeneratorTarget* target);
+  static void InitializeAutogenTarget(cmLocalGenerator* lg,
+                                      cmGeneratorTarget* target);
+  static void SetupAutoGenerateTarget(cmGeneratorTarget const* target);
 };
 
 #endif
diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx
index bbeb3dc..b16eccd 100644
--- a/Source/cmQtAutoGenerators.cxx
+++ b/Source/cmQtAutoGenerators.cxx
@@ -175,12 +175,14 @@ bool cmQtAutoGenerators::Run(const std::string& targetDirectory,
   cmake cm;
   cm.SetHomeOutputDirectory(targetDirectory);
   cm.SetHomeDirectory(targetDirectory);
+  cm.GetCurrentSnapshot().SetDefaultDefinitions();
   cmGlobalGenerator gg(&cm);
 
   cmState::Snapshot snapshot = cm.GetCurrentSnapshot();
+  snapshot.GetDirectory().SetCurrentBinary(targetDirectory);
+  snapshot.GetDirectory().SetCurrentSource(targetDirectory);
+
   cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, snapshot));
-  mf->SetCurrentBinaryDirectory(targetDirectory);
-  mf->SetCurrentSourceDirectory(targetDirectory);
   gg.SetCurrentMakefile(mf.get());
 
   this->ReadAutogenInfoFile(mf.get(), targetDirectory, config);
@@ -526,7 +528,7 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile)
   cmSystemTools::ExpandListArgument(this->Sources, sourceFiles);
 
   const std::vector<std::string>& headerExtensions =
-                                               makefile->GetHeaderExtensions();
+      makefile->GetCMakeInstance()->GetHeaderExtensions();
 
   std::map<std::string, std::vector<std::string> > includedUis;
   std::map<std::string, std::vector<std::string> > skippedUis;
diff --git a/Source/cmSetTargetPropertiesCommand.cxx b/Source/cmSetTargetPropertiesCommand.cxx
index 06217bb..b1c13ac 100644
--- a/Source/cmSetTargetPropertiesCommand.cxx
+++ b/Source/cmSetTargetPropertiesCommand.cxx
@@ -10,7 +10,6 @@
   See the License for more information.
 ============================================================================*/
 #include "cmSetTargetPropertiesCommand.h"
-#include "cmLocalGenerator.h"
 #include "cmGlobalGenerator.h"
 
 // cmSetTargetPropertiesCommand
diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx
index 86f0a7a..a9ac549 100644
--- a/Source/cmSourceFile.cxx
+++ b/Source/cmSourceFile.cxx
@@ -12,7 +12,6 @@
 #include "cmSourceFile.h"
 
 #include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmMakefile.h"
 #include "cmSystemTools.h"
 #include "cmake.h"
@@ -168,8 +167,10 @@ bool cmSourceFile::FindFullPath(std::string* error)
     {
     tryDirs[0] = "";
     }
-  const std::vector<std::string>& srcExts = mf->GetSourceExtensions();
-  const std::vector<std::string>& hdrExts = mf->GetHeaderExtensions();
+  const std::vector<std::string>& srcExts =
+      mf->GetCMakeInstance()->GetSourceExtensions();
+  std::vector<std::string> hdrExts =
+      mf->GetCMakeInstance()->GetHeaderExtensions();
   for(const char* const* di = tryDirs; *di; ++di)
     {
     std::string tryPath = this->Location.GetDirectory();
diff --git a/Source/cmSourceFileLocation.cxx b/Source/cmSourceFileLocation.cxx
index 4a87cc2..00d5d6a 100644
--- a/Source/cmSourceFileLocation.cxx
+++ b/Source/cmSourceFileLocation.cxx
@@ -12,7 +12,6 @@
 #include "cmSourceFileLocation.h"
 
 #include "cmMakefile.h"
-#include "cmLocalGenerator.h"
 #include "cmGlobalGenerator.h"
 #include "cmSystemTools.h"
 #include "cmAlgorithms.h"
@@ -122,8 +121,10 @@ void cmSourceFileLocation::UpdateExtension(const std::string& name)
   // The global generator checks extensions of enabled languages.
   cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
   cmMakefile const* mf = this->Makefile;
-  const std::vector<std::string>& srcExts = mf->GetSourceExtensions();
-  const std::vector<std::string>& hdrExts = mf->GetHeaderExtensions();
+  const std::vector<std::string>& srcExts =
+      mf->GetCMakeInstance()->GetSourceExtensions();
+  const std::vector<std::string>& hdrExts =
+      mf->GetCMakeInstance()->GetHeaderExtensions();
   if(!gg->GetLanguageFromExtension(ext.c_str()).empty() ||
      std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end() ||
      std::find(hdrExts.begin(), hdrExts.end(), ext) != hdrExts.end())
@@ -194,12 +195,14 @@ cmSourceFileLocation
   // disk.  One of these must match if loc refers to this source file.
   std::string const& ext = this->Name.substr(loc.Name.size()+1);
   cmMakefile const* mf = this->Makefile;
-  const std::vector<std::string>& srcExts = mf->GetSourceExtensions();
+  const std::vector<std::string>& srcExts =
+      mf->GetCMakeInstance()->GetSourceExtensions();
   if(std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end())
     {
     return true;
     }
-  const std::vector<std::string>& hdrExts = mf->GetHeaderExtensions();
+  std::vector<std::string> hdrExts =
+      mf->GetCMakeInstance()->GetHeaderExtensions();
   if(std::find(hdrExts.begin(), hdrExts.end(), ext) != hdrExts.end())
     {
     return true;
diff --git a/Source/cmStandardIncludes.h b/Source/cmStandardIncludes.h
index e212616..272c136 100644
--- a/Source/cmStandardIncludes.h
+++ b/Source/cmStandardIncludes.h
@@ -31,7 +31,7 @@
 #endif
 
 // Provide fixed-size integer types.
-#include <cmIML/INT.h>
+#include <cm_kwiml.h>
 
 #include <fstream>
 #include <iostream>
@@ -125,4 +125,10 @@ static thisClass* SafeDownCast(cmObject *c) \
 } \
 class cmTypeMacro_UseTrailingSemicolon
 
+enum cmTargetLinkLibraryType {
+  GENERAL_LibraryType,
+  DEBUG_LibraryType,
+  OPTIMIZED_LibraryType
+};
+
 #endif
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index c1ead6c..b8e604b 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -12,6 +12,7 @@
 #include "cmState.h"
 
 #include "cmake.h"
+#include "cmVersion.h"
 #include "cmCacheManager.h"
 #include "cmCommand.h"
 #include "cmAlgorithms.h"
@@ -83,9 +84,8 @@ struct cmState::BuildsystemDirectoryStateType
   std::vector<cmState::Snapshot> Children;
 };
 
-cmState::cmState(cmake* cm)
-  : CMakeInstance(cm),
-    IsInTryCompile(false),
+cmState::cmState()
+  : IsInTryCompile(false),
     WindowsShell(false),
     WindowsVSIDE(false),
     WatcomWMake(false),
@@ -93,13 +93,42 @@ cmState::cmState(cmake* cm)
     NMake(false),
     MSYSShell(false)
 {
+  this->CacheManager = new cmCacheManager;
 }
 
 cmState::~cmState()
 {
+  delete this->CacheManager;
   cmDeleteAll(this->Commands);
 }
 
+const char* cmState::GetTargetTypeName(cmState::TargetType targetType)
+{
+  switch( targetType )
+    {
+      case cmState::STATIC_LIBRARY:
+        return "STATIC_LIBRARY";
+      case cmState::MODULE_LIBRARY:
+        return "MODULE_LIBRARY";
+      case cmState::SHARED_LIBRARY:
+        return "SHARED_LIBRARY";
+      case cmState::OBJECT_LIBRARY:
+        return "OBJECT_LIBRARY";
+      case cmState::EXECUTABLE:
+        return "EXECUTABLE";
+      case cmState::UTILITY:
+        return "UTILITY";
+      case cmState::GLOBAL_TARGET:
+        return "GLOBAL_TARGET";
+      case cmState::INTERFACE_LIBRARY:
+        return "INTERFACE_LIBRARY";
+      case cmState::UNKNOWN_LIBRARY:
+        return "UNKNOWN_LIBRARY";
+    }
+  assert(0 && "Unexpected target type");
+  return 0;
+}
+
 const char* cmCacheEntryTypes[] =
 { "BOOL",
   "PATH",
@@ -148,12 +177,30 @@ bool cmState::IsCacheEntryType(std::string const& key)
   return false;
 }
 
+bool cmState::LoadCache(const std::string& path, bool internal,
+                        std::set<std::string>& excludes,
+                        std::set<std::string>& includes)
+{
+  return this->CacheManager->LoadCache(path, internal,
+                                       excludes, includes);
+}
+
+bool cmState::SaveCache(const std::string& path)
+{
+  return this->CacheManager->SaveCache(path);
+}
+
+bool cmState::DeleteCache(const std::string& path)
+{
+  return this->CacheManager->DeleteCache(path);
+}
+
 std::vector<std::string> cmState::GetCacheEntryKeys() const
 {
   std::vector<std::string> definitions;
-  definitions.reserve(this->CMakeInstance->GetCacheManager()->GetSize());
+  definitions.reserve(this->CacheManager->GetSize());
   cmCacheManager::CacheIterator cit =
-    this->CMakeInstance->GetCacheManager()->GetCacheIterator();
+    this->CacheManager->GetCacheIterator();
   for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
     {
     definitions.push_back(cit.GetName());
@@ -163,7 +210,7 @@ std::vector<std::string> cmState::GetCacheEntryKeys() const
 
 const char* cmState::GetCacheEntryValue(std::string const& key) const
 {
-  cmCacheManager::CacheEntry* e = this->CMakeInstance->GetCacheManager()
+  cmCacheManager::CacheEntry* e = this->CacheManager
              ->GetCacheEntry(key);
   if (!e)
     {
@@ -175,21 +222,21 @@ const char* cmState::GetCacheEntryValue(std::string const& key) const
 const char*
 cmState::GetInitializedCacheValue(std::string const& key) const
 {
-  return this->CMakeInstance->GetCacheManager()->GetInitializedCacheValue(key);
+  return this->CacheManager->GetInitializedCacheValue(key);
 }
 
 cmState::CacheEntryType
 cmState::GetCacheEntryType(std::string const& key) const
 {
   cmCacheManager::CacheIterator it =
-      this->CMakeInstance->GetCacheManager()->GetCacheIterator(key.c_str());
+      this->CacheManager->GetCacheIterator(key.c_str());
   return it.GetType();
 }
 
 void cmState::SetCacheEntryValue(std::string const& key,
                                          std::string const& value)
 {
-  this->CMakeInstance->GetCacheManager()->SetCacheEntryValue(key, value);
+  this->CacheManager->SetCacheEntryValue(key, value);
 }
 
 void cmState::SetCacheEntryProperty(std::string const& key,
@@ -197,7 +244,7 @@ void cmState::SetCacheEntryProperty(std::string const& key,
                             std::string const& value)
 {
   cmCacheManager::CacheIterator it =
-      this->CMakeInstance->GetCacheManager()->GetCacheIterator(key.c_str());
+      this->CacheManager->GetCacheIterator(key.c_str());
   it.SetProperty(propertyName, value.c_str());
 }
 
@@ -206,14 +253,14 @@ void cmState::SetCacheEntryBoolProperty(std::string const& key,
                             bool value)
 {
   cmCacheManager::CacheIterator it =
-      this->CMakeInstance->GetCacheManager()->GetCacheIterator(key.c_str());
+      this->CacheManager->GetCacheIterator(key.c_str());
   it.SetProperty(propertyName, value);
 }
 
 const char* cmState::GetCacheEntryProperty(std::string const& key,
                                               std::string const& propertyName)
 {
-  cmCacheManager::CacheIterator it = this->CMakeInstance->GetCacheManager()
+  cmCacheManager::CacheIterator it = this->CacheManager
              ->GetCacheIterator(key.c_str());
   if (!it.PropertyExists(propertyName))
     {
@@ -225,7 +272,7 @@ const char* cmState::GetCacheEntryProperty(std::string const& key,
 bool cmState::GetCacheEntryPropertyAsBool(std::string const& key,
                                               std::string const& propertyName)
 {
-  return this->CMakeInstance->GetCacheManager()
+  return this->CacheManager
              ->GetCacheIterator(key.c_str()).GetPropertyAsBool(propertyName);
 }
 
@@ -233,13 +280,13 @@ void cmState::AddCacheEntry(const std::string& key, const char* value,
                                     const char* helpString,
                                     cmState::CacheEntryType type)
 {
-  this->CMakeInstance->GetCacheManager()->AddCacheEntry(key, value,
+  this->CacheManager->AddCacheEntry(key, value,
                                                         helpString, type);
 }
 
 void cmState::RemoveCacheEntry(std::string const& key)
 {
-  this->CMakeInstance->GetCacheManager()->RemoveCacheEntry(key);
+  this->CacheManager->RemoveCacheEntry(key);
 }
 
 void cmState::AppendCacheEntryProperty(const std::string& key,
@@ -247,7 +294,7 @@ void cmState::AppendCacheEntryProperty(const std::string& key,
                                                const std::string& value,
                                                bool asString)
 {
-  this->CMakeInstance->GetCacheManager()
+  this->CacheManager
        ->GetCacheIterator(key.c_str()).AppendProperty(property,
                                                        value.c_str(),
                                                        asString);
@@ -256,7 +303,7 @@ void cmState::AppendCacheEntryProperty(const std::string& key,
 void cmState::RemoveCacheEntryProperty(std::string const& key,
                                               std::string const& propertyName)
 {
-  this->CMakeInstance->GetCacheManager()
+  this->CacheManager
        ->GetCacheIterator(key.c_str()).SetProperty(propertyName, (void*)0);
 }
 
@@ -288,11 +335,21 @@ cmState::Snapshot cmState::Reset()
   pos->PolicyScope = this->PolicyStack.Root();
   assert(pos->Policies.IsValid());
   assert(pos->PolicyRoot.IsValid());
+
+  {
+  std::string srcDir =
+      cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root);
+  std::string binDir =
+      cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root);
   this->VarTree.Clear();
   pos->Vars = this->VarTree.Push(this->VarTree.Root());
   pos->Parent = this->VarTree.Root();
   pos->Root = this->VarTree.Root();
 
+  pos->Vars->Set("CMAKE_SOURCE_DIR", srcDir.c_str());
+  pos->Vars->Set("CMAKE_BINARY_DIR", binDir.c_str());
+  }
+
   this->DefineProperty
     ("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY,
      "", "", true);
@@ -660,6 +717,16 @@ bool cmState::UseMSYSShell() const
   return this->MSYSShell;
 }
 
+unsigned int cmState::GetCacheMajorVersion() const
+{
+  return this->CacheManager->GetCacheMajorVersion();
+}
+
+unsigned int cmState::GetCacheMinorVersion() const
+{
+  return this->CacheManager->GetCacheMinorVersion();
+}
+
 const char* cmState::GetBinaryDirectory() const
 {
   return this->BinaryDirectory.c_str();
@@ -808,8 +875,12 @@ cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
   pos->Parent = origin;
   pos->Root = origin;
   pos->Vars = this->VarTree.Push(origin);
+
   cmState::Snapshot snapshot = cmState::Snapshot(this, pos);
   originSnapshot.Position->BuildSystemDirectory->Children.push_back(snapshot);
+  snapshot.SetDefaultDefinitions();
+  snapshot.InitializeFromParent();
+  snapshot.SetDirectoryDefinitions();
   return snapshot;
 }
 
@@ -1003,6 +1074,8 @@ void cmState::Directory::SetCurrentSource(std::string const& dir)
       loc,
       this->DirectoryState->CurrentSourceDirectoryComponents);
   this->ComputeRelativePathTopSource();
+
+  this->Snapshot_.SetDefinition("CMAKE_CURRENT_SOURCE_DIR", loc.c_str());
 }
 
 const char* cmState::Directory::GetCurrentBinary() const
@@ -1021,6 +1094,8 @@ void cmState::Directory::SetCurrentBinary(std::string const& dir)
       loc,
       this->DirectoryState->CurrentBinaryDirectoryComponents);
   this->ComputeRelativePathTopBinary();
+
+  this->Snapshot_.SetDefinition("CMAKE_CURRENT_BINARY_DIR", loc.c_str());
 }
 
 void cmState::Snapshot::Keep()
@@ -1319,6 +1394,70 @@ void InitializeContentFromParent(T& parentContent,
   contentEndPosition = thisContent.size();
 }
 
+void cmState::Snapshot::SetDefaultDefinitions()
+{
+  /* Up to CMake 2.4 here only WIN32, UNIX and APPLE were set.
+    With CMake must separate between target and host platform. In most cases
+    the tests for WIN32, UNIX and APPLE will be for the target system, so an
+    additional set of variables for the host system is required ->
+    CMAKE_HOST_WIN32, CMAKE_HOST_UNIX, CMAKE_HOST_APPLE.
+    WIN32, UNIX and APPLE are now set in the platform files in
+    Modules/Platforms/.
+    To keep cmake scripts (-P) and custom language and compiler modules
+    working, these variables are still also set here in this place, but they
+    will be reset in CMakeSystemSpecificInformation.cmake before the platform
+    files are executed. */
+  #if defined(_WIN32)
+    this->SetDefinition("WIN32", "1");
+    this->SetDefinition("CMAKE_HOST_WIN32", "1");
+  #else
+    this->SetDefinition("UNIX", "1");
+    this->SetDefinition("CMAKE_HOST_UNIX", "1");
+  #endif
+  #if defined(__CYGWIN__)
+    if(cmSystemTools::IsOn(cmSystemTools::GetEnv("CMAKE_LEGACY_CYGWIN_WIN32")))
+      {
+      this->SetDefinition("WIN32", "1");
+      this->SetDefinition("CMAKE_HOST_WIN32", "1");
+      }
+  #endif
+  #if defined(__APPLE__)
+    this->SetDefinition("APPLE", "1");
+    this->SetDefinition("CMAKE_HOST_APPLE", "1");
+  #endif
+
+    char temp[1024];
+    sprintf(temp, "%d", cmVersion::GetMinorVersion());
+    this->SetDefinition("CMAKE_MINOR_VERSION", temp);
+    sprintf(temp, "%d", cmVersion::GetMajorVersion());
+    this->SetDefinition("CMAKE_MAJOR_VERSION", temp);
+    sprintf(temp, "%d", cmVersion::GetPatchVersion());
+    this->SetDefinition("CMAKE_PATCH_VERSION", temp);
+    sprintf(temp, "%d", cmVersion::GetTweakVersion());
+    this->SetDefinition("CMAKE_TWEAK_VERSION", temp);
+    this->SetDefinition("CMAKE_VERSION",
+                                      cmVersion::GetCMakeVersion());
+
+    this->SetDefinition("CMAKE_FILES_DIRECTORY",
+                        cmake::GetCMakeFilesDirectory());
+
+  // Setup the default include file regular expression (match everything).
+  this->Position->BuildSystemDirectory
+      ->Properties.SetProperty("INCLUDE_REGULAR_EXPRESSION", "^.*$");
+}
+
+void cmState::Snapshot::SetDirectoryDefinitions()
+{
+  this->SetDefinition("CMAKE_SOURCE_DIR",
+                      this->State->GetSourceDirectory());
+  this->SetDefinition("CMAKE_CURRENT_SOURCE_DIR",
+                      this->State->GetSourceDirectory());
+  this->SetDefinition("CMAKE_BINARY_DIR",
+                      this->State->GetBinaryDirectory());
+  this->SetDefinition("CMAKE_CURRENT_BINARY_DIR",
+                      this->State->GetBinaryDirectory());
+}
+
 void cmState::Snapshot::InitializeFromParent()
 {
   PositionType parent = this->Position->DirectoryParent;
@@ -1367,6 +1506,20 @@ std::string cmState::Snapshot::GetProjectName() const
   return this->Position->BuildSystemDirectory->ProjectName;
 }
 
+void cmState::Snapshot::InitializeFromParent_ForSubdirsCommand()
+{
+  std::string currentSrcDir = this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR");
+  std::string currentBinDir = this->GetDefinition("CMAKE_CURRENT_BINARY_DIR");
+  this->InitializeFromParent();
+  this->SetDefinition("CMAKE_SOURCE_DIR",
+                      this->State->GetSourceDirectory());
+  this->SetDefinition("CMAKE_BINARY_DIR",
+                      this->State->GetBinaryDirectory());
+
+  this->SetDefinition("CMAKE_CURRENT_SOURCE_DIR", currentSrcDir.c_str());
+  this->SetDefinition("CMAKE_CURRENT_BINARY_DIR", currentBinDir.c_str());
+}
+
 cmState::Directory::Directory(
     cmLinkedTree<BuildsystemDirectoryStateType>::iterator iter,
     const cmState::Snapshot& snapshot)
@@ -1771,3 +1924,87 @@ bool operator!=(const cmState::Snapshot& lhs, const cmState::Snapshot& rhs)
 {
   return lhs.Position != rhs.Position;
 }
+
+static bool ParseEntryWithoutType(const std::string& entry,
+                                  std::string& var,
+                                  std::string& value)
+{
+  // input line is:         key=value
+  static cmsys::RegularExpression reg(
+    "^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
+  // input line is:         "key"=value
+  static cmsys::RegularExpression regQuoted(
+    "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
+  bool flag = false;
+  if(regQuoted.find(entry))
+    {
+    var = regQuoted.match(1);
+    value = regQuoted.match(2);
+    flag = true;
+    }
+  else if (reg.find(entry))
+    {
+    var = reg.match(1);
+    value = reg.match(2);
+    flag = true;
+    }
+
+  // if value is enclosed in single quotes ('foo') then remove them
+  // it is used to enclose trailing space or tab
+  if (flag &&
+      value.size() >= 2 &&
+      value[0] == '\'' &&
+      value[value.size() - 1] == '\'')
+    {
+    value = value.substr(1,
+                         value.size() - 2);
+    }
+
+  return flag;
+}
+
+bool cmState::ParseCacheEntry(const std::string& entry,
+                                std::string& var,
+                                std::string& value,
+                                CacheEntryType& type)
+{
+  // input line is:         key:type=value
+  static cmsys::RegularExpression reg(
+    "^([^=:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
+  // input line is:         "key":type=value
+  static cmsys::RegularExpression regQuoted(
+    "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
+  bool flag = false;
+  if(regQuoted.find(entry))
+    {
+    var = regQuoted.match(1);
+    type = cmState::StringToCacheEntryType(regQuoted.match(2).c_str());
+    value = regQuoted.match(3);
+    flag = true;
+    }
+  else if (reg.find(entry))
+    {
+    var = reg.match(1);
+    type = cmState::StringToCacheEntryType(reg.match(2).c_str());
+    value = reg.match(3);
+    flag = true;
+    }
+
+  // if value is enclosed in single quotes ('foo') then remove them
+  // it is used to enclose trailing space or tab
+  if (flag &&
+      value.size() >= 2 &&
+      value[0] == '\'' &&
+      value[value.size() - 1] == '\'')
+    {
+    value = value.substr(1,
+                         value.size() - 2);
+    }
+
+  if (!flag)
+    {
+    return ParseEntryWithoutType(entry, var, value);
+    }
+
+  return flag;
+}
diff --git a/Source/cmState.h b/Source/cmState.h
index a66603f..6717481 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -23,6 +23,7 @@ class cmake;
 class cmCommand;
 class cmDefinitions;
 class cmListFileBacktrace;
+class cmCacheManager;
 
 class cmState
 {
@@ -32,7 +33,7 @@ class cmState
   typedef cmLinkedTree<SnapshotDataType>::iterator PositionType;
   friend class Snapshot;
 public:
-  cmState(cmake* cm);
+  cmState();
   ~cmState();
 
   enum SnapshotType
@@ -76,8 +77,6 @@ public:
     Snapshot GetCallStackParent() const;
     SnapshotType GetType() const;
 
-    void InitializeFromParent();
-
     void SetPolicy(cmPolicies::PolicyID id, cmPolicies::PolicyStatus status);
     cmPolicies::PolicyStatus GetPolicy(cmPolicies::PolicyID id) const;
     bool HasDefinedPolicyCMP0011();
@@ -92,12 +91,17 @@ public:
     void SetProjectName(std::string const& name);
     std::string GetProjectName() const;
 
+    void InitializeFromParent_ForSubdirsCommand();
+
     struct StrictWeakOrder
     {
       bool operator()(const cmState::Snapshot& lhs,
                       const cmState::Snapshot& rhs) const;
     };
 
+    void SetDirectoryDefinitions();
+    void SetDefaultDefinitions();
+
   private:
     friend bool operator==(const cmState::Snapshot& lhs,
                            const cmState::Snapshot& rhs);
@@ -106,6 +110,9 @@ public:
     friend class cmState;
     friend class Directory;
     friend struct StrictWeakOrder;
+
+    void InitializeFromParent();
+
     cmState* State;
     cmState::PositionType Position;
   };
@@ -175,6 +182,14 @@ public:
     friend class Snapshot;
   };
 
+  enum TargetType { EXECUTABLE, STATIC_LIBRARY,
+                    SHARED_LIBRARY, MODULE_LIBRARY,
+                    OBJECT_LIBRARY, UTILITY, GLOBAL_TARGET,
+                    INTERFACE_LIBRARY,
+                    UNKNOWN_LIBRARY};
+
+  static const char* GetTargetTypeName(cmState::TargetType targetType);
+
   Snapshot CreateBaseSnapshot();
   Snapshot
   CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
@@ -208,6 +223,14 @@ public:
   static const char* CacheEntryTypeToString(CacheEntryType);
   static bool IsCacheEntryType(std::string const& key);
 
+  bool LoadCache(const std::string& path, bool internal,
+                 std::set<std::string>& excludes,
+                 std::set<std::string>& includes);
+
+  bool SaveCache(const std::string& path) ;
+
+  bool DeleteCache(const std::string& path);
+
   std::vector<std::string> GetCacheEntryKeys() const;
   const char* GetCacheEntryValue(std::string const& key) const;
   const char* GetInitializedCacheValue(std::string const& key) const;
@@ -215,8 +238,6 @@ public:
   void SetCacheEntryValue(std::string const& key, std::string const& value);
   void SetCacheValue(std::string const& key, std::string const& value);
 
-  void AddCacheEntry(const std::string& key, const char* value,
-                     const char* helpString, CacheEntryType type);
   void RemoveCacheEntry(std::string const& key);
 
   void SetCacheEntryProperty(std::string const& key,
@@ -236,6 +257,12 @@ public:
   void RemoveCacheEntryProperty(std::string const& key,
                                 std::string const& propertyName);
 
+  ///! Break up a line like VAR:type="value" into var, type and value
+  static bool ParseCacheEntry(const std::string& entry,
+                              std::string& var,
+                              std::string& value,
+                              CacheEntryType& type);
+
   Snapshot Reset();
   // Define a property
   void DefineProperty(const std::string& name, cmProperty::ScopeType scope,
@@ -296,12 +323,19 @@ public:
   void SetMSYSShell(bool mSYSShell);
   bool UseMSYSShell() const;
 
+  unsigned int GetCacheMajorVersion() const;
+  unsigned int GetCacheMinorVersion() const;
+
 private:
+  friend class cmake;
+  void AddCacheEntry(const std::string& key, const char* value,
+                     const char* helpString, CacheEntryType type);
+
   std::map<cmProperty::ScopeType, cmPropertyDefinitionMap> PropertyDefinitions;
   std::vector<std::string> EnabledLanguages;
   std::map<std::string, cmCommand*> Commands;
   cmPropertyMap GlobalProperties;
-  cmake* CMakeInstance;
+  cmCacheManager* CacheManager;
 
   cmLinkedTree<BuildsystemDirectoryStateType> BuildsystemDirectory;
 
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 2c5aa8a..3ba7287 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -17,6 +17,7 @@
 #include <time.h>
 #include <string.h>
 #include <stdlib.h>
+#include <assert.h>
 #ifdef __QNX__
 # include <malloc.h> /* for malloc/free on QNX */
 #endif
@@ -29,6 +30,9 @@
 # include "cmArchiveWrite.h"
 # include "cmLocale.h"
 # include <cm_libarchive.h>
+# ifndef __LA_INT64_T
+#  define __LA_INT64_T la_int64_t
+# endif
 #endif
 #include <cmsys/FStream.hxx>
 #include <cmsys/Terminal.h>
@@ -657,14 +661,6 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
     argv.push_back(a->c_str());
     }
   argv.push_back(0);
-  if ( captureStdOut )
-    {
-    *captureStdOut = "";
-    }
-  if (captureStdErr && captureStdErr != captureStdOut)
-    {
-    *captureStdErr = "";
-    }
 
   cmsysProcess* cp = cmsysProcess_New();
   cmsysProcess_SetCommand(cp, &*argv.begin());
@@ -678,7 +674,16 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
     {
     cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1);
     cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1);
+    captureStdOut = 0;
+    captureStdErr = 0;
     }
+  else if (outputflag == OUTPUT_MERGE ||
+           (captureStdErr && captureStdErr == captureStdOut))
+    {
+    cmsysProcess_SetOption(cp, cmsysProcess_Option_MergeOutput, 1);
+    captureStdErr = 0;
+    }
+  assert(!captureStdErr || captureStdErr != captureStdOut);
 
   cmsysProcess_SetTimeout(cp, timeout);
   cmsysProcess_Execute(cp);
@@ -693,65 +698,50 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
     {
     while((pipe = cmsysProcess_WaitForData(cp, &data, &length, 0)) > 0)
       {
-      if(captureStdOut || captureStdErr || outputflag != OUTPUT_NONE)
+      // Translate NULL characters in the output into valid text.
+      // Visual Studio 7 puts these characters in the output of its
+      // build process.
+      for(int i=0; i < length; ++i)
         {
-        // Translate NULL characters in the output into valid text.
-        // Visual Studio 7 puts these characters in the output of its
-        // build process.
-        for(int i=0; i < length; ++i)
+        if(data[i] == '\0')
           {
-          if(data[i] == '\0')
-            {
-            data[i] = ' ';
-            }
+          data[i] = ' ';
           }
         }
-      if(pipe == cmsysProcess_Pipe_STDOUT ||
-         (pipe == cmsysProcess_Pipe_STDERR &&
-          captureStdOut == captureStdErr))
+
+      if (pipe == cmsysProcess_Pipe_STDOUT)
         {
-        if (captureStdOut)
+        if (outputflag != OUTPUT_NONE)
           {
-          tempStdOut.insert(tempStdOut.end(), data, data+length);
+          cmSystemTools::Stdout(data, length);
           }
-        }
-      else if(pipe == cmsysProcess_Pipe_STDERR)
-        {
-        if (captureStdErr)
+        if (captureStdOut)
           {
-          tempStdErr.insert(tempStdErr.end(), data, data+length);
+          tempStdOut.insert(tempStdOut.end(), data, data+length);
           }
         }
-      if(outputflag != OUTPUT_NONE)
+      else if (pipe == cmsysProcess_Pipe_STDERR)
         {
-        if(outputflag == OUTPUT_MERGE)
+        if (outputflag != OUTPUT_NONE)
           {
-          cmSystemTools::Stdout(data, length);
+          cmSystemTools::Stderr(data, length);
           }
-        else
+        if (captureStdErr)
           {
-          if(pipe == cmsysProcess_Pipe_STDERR)
-            {
-            cmSystemTools::Stderr(data, length);
-            }
-          else if(pipe == cmsysProcess_Pipe_STDOUT)
-            {
-            cmSystemTools::Stdout(data, length);
-            }
+          tempStdErr.insert(tempStdErr.end(), data, data+length);
           }
         }
       }
     }
 
   cmsysProcess_WaitForExit(cp, 0);
-  if ( captureStdOut && tempStdOut.begin() != tempStdOut.end())
+  if (captureStdOut)
     {
-    captureStdOut->append(&*tempStdOut.begin(), tempStdOut.size());
+    captureStdOut->assign(tempStdOut.begin(), tempStdOut.end());
     }
-  if ( captureStdErr && captureStdErr != captureStdOut &&
-       tempStdErr.begin() != tempStdErr.end())
+  if (captureStdErr)
     {
-    captureStdErr->append(&*tempStdErr.begin(), tempStdErr.size());
+    captureStdErr->assign(tempStdErr.begin(), tempStdErr.end());
     }
 
   bool result = true;
@@ -2562,6 +2552,7 @@ bool cmSystemTools::ChangeRPath(std::string const& file,
     *changed = false;
     }
   int rp_count = 0;
+  bool remove_rpath = true;
   cmSystemToolsRPathInfo rp[2];
   {
   // Parse the ELF binary.
@@ -2619,6 +2610,7 @@ bool cmSystemTools::ChangeRPath(std::string const& file,
       // If it contains the new rpath instead then it is okay.
       if(cmSystemToolsFindRPath(se[i]->Value, newRPath) != std::string::npos)
         {
+        remove_rpath = false;
         continue;
         }
       if(emsg)
@@ -2639,13 +2631,30 @@ bool cmSystemTools::ChangeRPath(std::string const& file,
     rp[rp_count].Size = se[i]->Size;
     rp[rp_count].Name = se_name[i];
 
+    std::string::size_type prefix_len = pos;
+
+    // If oldRPath was at the end of the file's RPath, and newRPath is empty,
+    // we should remove the unnecessary ':' at the end.
+    if (newRPath.empty() &&
+        pos > 0 &&
+        se[i]->Value[pos - 1] == ':' &&
+        pos + oldRPath.length() == se[i]->Value.length())
+      {
+      prefix_len--;
+      }
+
     // Construct the new value which preserves the part of the path
     // not being changed.
-    rp[rp_count].Value = se[i]->Value.substr(0, pos);
+    rp[rp_count].Value = se[i]->Value.substr(0, prefix_len);
     rp[rp_count].Value += newRPath;
     rp[rp_count].Value += se[i]->Value.substr(pos+oldRPath.length(),
                                               oldRPath.npos);
 
+    if (!rp[rp_count].Value.empty())
+      {
+      remove_rpath = false;
+      }
+
     // Make sure there is enough room to store the new rpath and at
     // least one null terminator.
     if(rp[rp_count].Size < rp[rp_count].Value.length()+1)
@@ -2670,6 +2679,12 @@ bool cmSystemTools::ChangeRPath(std::string const& file,
     return true;
     }
 
+  // If the resulting rpath is empty, just remove the entire entry instead.
+  if (remove_rpath)
+    {
+    return cmSystemTools::RemoveRPath(file, emsg, changed);
+    }
+
   {
   // Open the file for update.
   cmsys::ofstream f(file.c_str(),
@@ -2777,6 +2792,14 @@ bool cmSystemTools::VersionCompare(cmSystemTools::CompareOp op,
 }
 
 //----------------------------------------------------------------------------
+bool cmSystemTools::VersionCompareEqual(std::string const& lhs,
+                                        std::string const& rhs)
+{
+  return cmSystemTools::VersionCompare(
+    cmSystemTools::OP_EQUAL, lhs.c_str(), rhs.c_str());
+}
+
+//----------------------------------------------------------------------------
 bool cmSystemTools::VersionCompareGreater(std::string const& lhs,
                                           std::string const& rhs)
 {
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index b6b0978..f511ae4 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -203,7 +203,7 @@ public:
    * Output is controlled with outputflag. If outputflag is OUTPUT_NONE, no
    * user-viewable output from the program being run will be generated.
    * OUTPUT_MERGE is the legacy behaviour where stdout and stderr are merged
-   * into stdout.  OUTPUT_NORMAL passes through the output to stdout/stderr as
+   * into stdout.  OUTPUT_FORWARD copies the output to stdout/stderr as
    * it was received.  OUTPUT_PASSTHROUGH passes through the original handles.
    *
    * If timeout is specified, the command will be terminated after
@@ -223,7 +223,7 @@ public:
    {
      OUTPUT_NONE = 0,
      OUTPUT_MERGE,
-     OUTPUT_NORMAL,
+     OUTPUT_FORWARD,
      OUTPUT_PASSTHROUGH
    };
   static bool RunSingleCommand(const char* command,
@@ -294,6 +294,8 @@ public:
    * Compare versions
    */
   static bool VersionCompare(CompareOp op, const char* lhs, const char* rhs);
+  static bool VersionCompareEqual(std::string const& lhs,
+                                  std::string const& rhs);
   static bool VersionCompareGreater(std::string const& lhs,
                                     std::string const& rhs);
 
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index bb44956..1986e5f 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -33,91 +33,10 @@
 #define UNORDERED_SET std::set
 #endif
 
-const char* cmTarget::GetTargetTypeName(TargetType targetType)
-{
-  switch( targetType )
-    {
-      case cmTarget::STATIC_LIBRARY:
-        return "STATIC_LIBRARY";
-      case cmTarget::MODULE_LIBRARY:
-        return "MODULE_LIBRARY";
-      case cmTarget::SHARED_LIBRARY:
-        return "SHARED_LIBRARY";
-      case cmTarget::OBJECT_LIBRARY:
-        return "OBJECT_LIBRARY";
-      case cmTarget::EXECUTABLE:
-        return "EXECUTABLE";
-      case cmTarget::UTILITY:
-        return "UTILITY";
-      case cmTarget::GLOBAL_TARGET:
-        return "GLOBAL_TARGET";
-      case cmTarget::INTERFACE_LIBRARY:
-        return "INTERFACE_LIBRARY";
-      case cmTarget::UNKNOWN_LIBRARY:
-        return "UNKNOWN_LIBRARY";
-    }
-  assert(0 && "Unexpected target type");
-  return 0;
-}
-
-//----------------------------------------------------------------------------
-struct cmTarget::OutputInfo
-{
-  std::string OutDir;
-  std::string ImpDir;
-  std::string PdbDir;
-  bool empty() const
-    { return OutDir.empty() && ImpDir.empty() && PdbDir.empty(); }
-};
-
 //----------------------------------------------------------------------------
 class cmTargetInternals
 {
 public:
-  cmTargetInternals()
-    : Backtrace()
-    {
-    this->UtilityItemsDone = false;
-    }
-  cmTargetInternals(cmTargetInternals const&)
-    : Backtrace()
-    {
-    this->UtilityItemsDone = false;
-    }
-  ~cmTargetInternals();
-
-  // The backtrace when the target was created.
-  cmListFileBacktrace Backtrace;
-
-  typedef std::map<std::string, cmTarget::OutputInfo> OutputInfoMapType;
-  OutputInfoMapType OutputInfoMap;
-
-  typedef std::map<std::string, cmTarget::ImportInfo> ImportInfoMapType;
-  ImportInfoMapType ImportInfoMap;
-
-  struct HeadToLinkImplementationMap:
-    public std::map<cmTarget const*, cmOptionalLinkImplementation> {};
-  typedef std::map<std::string,
-                   HeadToLinkImplementationMap> LinkImplMapType;
-  LinkImplMapType LinkImplMap;
-
-  typedef std::map<std::string, std::vector<cmSourceFile*> >
-                                                       SourceFilesMapType;
-  SourceFilesMapType SourceFilesMap;
-
-  std::set<cmLinkItem> UtilityItems;
-  bool UtilityItemsDone;
-
-  class TargetPropertyEntry {
-    static cmLinkImplItem NoLinkImplItem;
-  public:
-    TargetPropertyEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
-                        cmLinkImplItem const& item = NoLinkImplItem)
-      : ge(cge), LinkImplItem(item)
-    {}
-    const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
-    cmLinkImplItem const& LinkImplItem;
-  };
   std::vector<std::string> IncludeDirectoriesEntries;
   std::vector<cmListFileBacktrace> IncludeDirectoriesBacktraces;
   std::vector<std::string> CompileOptionsEntries;
@@ -126,21 +45,12 @@ public:
   std::vector<cmListFileBacktrace> CompileFeaturesBacktraces;
   std::vector<std::string> CompileDefinitionsEntries;
   std::vector<cmListFileBacktrace> CompileDefinitionsBacktraces;
-  std::vector<TargetPropertyEntry*> SourceEntries;
-  std::vector<cmValueWithOrigin> LinkImplementationPropertyEntries;
-
-  void AddInterfaceEntries(
-    cmTarget const* thisTarget, std::string const& config,
-    std::string const& prop, std::vector<TargetPropertyEntry*>& entries);
+  std::vector<std::string> SourceEntries;
+  std::vector<cmListFileBacktrace> SourceBacktraces;
+  std::vector<std::string> LinkImplementationPropertyEntries;
+  std::vector<cmListFileBacktrace> LinkImplementationPropertyBacktraces;
 };
 
-cmLinkImplItem cmTargetInternals::TargetPropertyEntry::NoLinkImplItem;
-
-//----------------------------------------------------------------------------
-cmTargetInternals::~cmTargetInternals()
-{
-}
-
 //----------------------------------------------------------------------------
 cmTarget::cmTarget()
 {
@@ -151,20 +61,18 @@ cmTarget::cmTarget()
   this->HaveInstallRule = false;
   this->DLLPlatform = false;
   this->IsAndroid = false;
-  this->IsApple = false;
   this->IsImportedTarget = false;
+  this->ImportedGloballyVisible = false;
   this->BuildInterfaceIncludesAppended = false;
-  this->DebugSourcesDone = false;
-  this->LinkImplementationLanguageIsContextDependent = true;
 }
 
-void cmTarget::SetType(TargetType type, const std::string& name)
+void cmTarget::SetType(cmState::TargetType type, const std::string& name)
 {
   this->Name = name;
   // only add dependency information for library targets
   this->TargetTypeValue = type;
-  if(this->TargetTypeValue >= STATIC_LIBRARY
-     && this->TargetTypeValue <= MODULE_LIBRARY)
+  if(this->TargetTypeValue >= cmState::STATIC_LIBRARY
+     && this->TargetTypeValue <= cmState::MODULE_LIBRARY)
     {
     this->RecordDependencies = true;
     }
@@ -190,11 +98,9 @@ void cmTarget::SetMakefile(cmMakefile* mf)
     strcmp(this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME"),
            "Android") == 0;
 
-  // Check whether we are targeting an Apple platform.
-  this->IsApple = this->Makefile->IsOn("APPLE");
-
   // Setup default property values.
-  if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
+  if (this->GetType() != cmState::INTERFACE_LIBRARY
+      && this->GetType() != cmState::UTILITY)
     {
     this->SetPropertyDefault("ANDROID_API", 0);
     this->SetPropertyDefault("ANDROID_API_MIN", 0);
@@ -226,6 +132,7 @@ void cmTarget::SetMakefile(cmMakefile* mf)
     this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
     this->SetPropertyDefault("GNUtoMS", 0);
     this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
+    this->SetPropertyDefault("IOS_INSTALL_COMBINED", 0);
     this->SetPropertyDefault("AUTOMOC", 0);
     this->SetPropertyDefault("AUTOUIC", 0);
     this->SetPropertyDefault("AUTORCC", 0);
@@ -257,7 +164,7 @@ void cmTarget::SetMakefile(cmMakefile* mf)
   mf->GetConfigurations(configNames);
 
   // Setup per-configuration property default values.
-  if (this->GetType() != UTILITY)
+  if (this->GetType() != cmState::UTILITY)
     {
     const char* configProps[] = {
       "ARCHIVE_OUTPUT_DIRECTORY_",
@@ -273,7 +180,7 @@ void cmTarget::SetMakefile(cmMakefile* mf)
       std::string configUpper = cmSystemTools::UpperCase(*ci);
       for(const char** p = configProps; *p; ++p)
         {
-        if (this->TargetTypeValue == INTERFACE_LIBRARY
+        if (this->TargetTypeValue == cmState::INTERFACE_LIBRARY
             && strcmp(*p, "MAP_IMPORTED_CONFIG_") != 0)
           {
           continue;
@@ -288,8 +195,8 @@ void cmTarget::SetMakefile(cmMakefile* mf)
       // compatibility with previous CMake versions in which executables
       // did not support this variable.  Projects may still specify the
       // property directly.
-      if(this->TargetTypeValue != cmTarget::EXECUTABLE
-          && this->TargetTypeValue != cmTarget::INTERFACE_LIBRARY)
+      if(this->TargetTypeValue != cmState::EXECUTABLE
+          && this->TargetTypeValue != cmState::INTERFACE_LIBRARY)
         {
         std::string property = cmSystemTools::UpperCase(*ci);
         property += "_POSTFIX";
@@ -299,7 +206,7 @@ void cmTarget::SetMakefile(cmMakefile* mf)
     }
 
   // Save the backtrace of target construction.
-  this->Internal->Backtrace = this->Makefile->GetBacktrace();
+  this->Backtrace = this->Makefile->GetBacktrace();
 
   if (!this->IsImported())
     {
@@ -336,30 +243,32 @@ void cmTarget::SetMakefile(cmMakefile* mf)
           parentOptionsBts.begin(), parentOptionsBts.end());
     }
 
-  if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
+  if (this->GetType() != cmState::INTERFACE_LIBRARY
+      && this->GetType() != cmState::UTILITY)
     {
     this->SetPropertyDefault("C_VISIBILITY_PRESET", 0);
     this->SetPropertyDefault("CXX_VISIBILITY_PRESET", 0);
     this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", 0);
     }
 
-  if(this->TargetTypeValue == cmTarget::EXECUTABLE)
+  if(this->TargetTypeValue == cmState::EXECUTABLE)
     {
     this->SetPropertyDefault("ANDROID_GUI", 0);
     this->SetPropertyDefault("CROSSCOMPILING_EMULATOR", 0);
     this->SetPropertyDefault("ENABLE_EXPORTS", 0);
     }
-  if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
-      || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
+  if(this->TargetTypeValue == cmState::SHARED_LIBRARY
+      || this->TargetTypeValue == cmState::MODULE_LIBRARY)
     {
     this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
     }
-  if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY)
+  if(this->TargetTypeValue == cmState::SHARED_LIBRARY)
     {
     this->SetPropertyDefault("WINDOWS_EXPORT_ALL_SYMBOLS", 0);
     }
 
-  if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
+  if (this->GetType() != cmState::INTERFACE_LIBRARY
+      && this->GetType() != cmState::UTILITY)
     {
     this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
     }
@@ -367,42 +276,29 @@ void cmTarget::SetMakefile(cmMakefile* mf)
   // Record current policies for later use.
   this->Makefile->RecordPolicies(this->PolicyMap);
 
-  if (this->TargetTypeValue == INTERFACE_LIBRARY)
+  if (this->TargetTypeValue == cmState::INTERFACE_LIBRARY)
     {
     // This policy is checked in a few conditions. The properties relevant
-    // to the policy are always ignored for INTERFACE_LIBRARY targets,
+    // to the policy are always ignored for cmState::INTERFACE_LIBRARY targets,
     // so ensure that the conditions don't lead to nonsense.
     this->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW);
     }
 
-  if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
+  if (this->GetType() != cmState::INTERFACE_LIBRARY
+      && this->GetType() != cmState::UTILITY)
     {
     this->SetPropertyDefault("JOB_POOL_COMPILE", 0);
     this->SetPropertyDefault("JOB_POOL_LINK", 0);
     }
 }
 
-void CreatePropertyGeneratorExpressions(
-    std::vector<std::string> const& entries,
-    std::vector<cmListFileBacktrace> const& backtraces,
-    std::vector<cmTargetInternals::TargetPropertyEntry*>& items)
-{
-  std::vector<cmListFileBacktrace>::const_iterator btIt = backtraces.begin();
-  for (std::vector<std::string>::const_iterator it = entries.begin();
-       it != entries.end(); ++it, ++btIt)
-    {
-    cmGeneratorExpression ge(*btIt);
-    cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*it);
-    items.push_back(new cmTargetInternals::TargetPropertyEntry(cge));
-    }
-}
-
 //----------------------------------------------------------------------------
 void cmTarget::AddUtility(const std::string& u, cmMakefile *makefile)
 {
   if(this->Utilities.insert(u).second && makefile)
     {
-    UtilityBacktraces.insert(std::make_pair(u, makefile->GetBacktrace()));
+    this->UtilityBacktraces.insert(
+            std::make_pair(u, makefile->GetBacktrace()));
     }
 }
 
@@ -418,98 +314,30 @@ cmListFileBacktrace const* cmTarget::GetUtilityBacktrace(
 }
 
 //----------------------------------------------------------------------------
-std::set<cmLinkItem> const& cmTarget::GetUtilityItems() const
-{
-  if(!this->Internal->UtilityItemsDone)
-    {
-    this->Internal->UtilityItemsDone = true;
-    for(std::set<std::string>::const_iterator i = this->Utilities.begin();
-        i != this->Utilities.end(); ++i)
-      {
-      this->Internal->UtilityItems.insert(
-        cmLinkItem(*i, this->Makefile->FindTargetToUse(*i)));
-      }
-    }
-  return this->Internal->UtilityItems;
-}
-
-//----------------------------------------------------------------------------
-void cmTarget::FinishConfigure()
-{
-  // Erase any cached link information that might have been comptued
-  // on-demand during the configuration.  This ensures that build
-  // system generation uses up-to-date information even if other cache
-  // invalidation code in this source file is buggy.
-  this->ClearLinkMaps();
-
-#if defined(_WIN32) && !defined(__CYGWIN__)
-  // Do old-style link dependency analysis only for CM_USE_OLD_VS6.
-  if(this->Makefile->GetGlobalGenerator()->IsForVS6())
-    {
-    this->AnalyzeLibDependenciesForVS6(*this->Makefile);
-    }
-#endif
-}
-
-//----------------------------------------------------------------------------
-void cmTarget::ClearLinkMaps()
-{
-  this->LinkImplementationLanguageIsContextDependent = true;
-  this->Internal->LinkImplMap.clear();
-  this->Internal->SourceFilesMap.clear();
-}
-
-//----------------------------------------------------------------------------
 cmListFileBacktrace const& cmTarget::GetBacktrace() const
 {
-  return this->Internal->Backtrace;
-}
-
-//----------------------------------------------------------------------------
-std::string cmTarget::GetSupportDirectory() const
-{
-  std::string dir = this->Makefile->GetCurrentBinaryDirectory();
-  dir += cmake::GetCMakeFilesDirectory();
-  dir += "/";
-  dir += this->Name;
-#if defined(__VMS)
-  dir += "_dir";
-#else
-  dir += ".dir";
-#endif
-  return dir;
+  return this->Backtrace;
 }
 
 //----------------------------------------------------------------------------
 bool cmTarget::IsExecutableWithExports() const
 {
-  return (this->GetType() == cmTarget::EXECUTABLE &&
+  return (this->GetType() == cmState::EXECUTABLE &&
           this->GetPropertyAsBool("ENABLE_EXPORTS"));
 }
 
 //----------------------------------------------------------------------------
-bool cmTarget::IsLinkable() const
-{
-  return (this->GetType() == cmTarget::STATIC_LIBRARY ||
-          this->GetType() == cmTarget::SHARED_LIBRARY ||
-          this->GetType() == cmTarget::MODULE_LIBRARY ||
-          this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
-          this->GetType() == cmTarget::INTERFACE_LIBRARY ||
-          this->IsExecutableWithExports());
-}
-
-//----------------------------------------------------------------------------
 bool cmTarget::HasImportLibrary() const
 {
   return (this->DLLPlatform &&
-          (this->GetType() == cmTarget::SHARED_LIBRARY ||
+          (this->GetType() == cmState::SHARED_LIBRARY ||
            this->IsExecutableWithExports()));
 }
 
 //----------------------------------------------------------------------------
 bool cmTarget::IsFrameworkOnApple() const
 {
-  return (this->GetType() == cmTarget::SHARED_LIBRARY &&
+  return (this->GetType() == cmState::SHARED_LIBRARY &&
           this->Makefile->IsOn("APPLE") &&
           this->GetPropertyAsBool("FRAMEWORK"));
 }
@@ -517,268 +345,19 @@ bool cmTarget::IsFrameworkOnApple() const
 //----------------------------------------------------------------------------
 bool cmTarget::IsAppBundleOnApple() const
 {
-  return (this->GetType() == cmTarget::EXECUTABLE &&
+  return (this->GetType() == cmState::EXECUTABLE &&
           this->Makefile->IsOn("APPLE") &&
           this->GetPropertyAsBool("MACOSX_BUNDLE"));
 }
 
 //----------------------------------------------------------------------------
-bool cmTarget::IsCFBundleOnApple() const
-{
-  return (this->GetType() == cmTarget::MODULE_LIBRARY &&
-          this->Makefile->IsOn("APPLE") &&
-          this->GetPropertyAsBool("BUNDLE"));
-}
-
-//----------------------------------------------------------------------------
-bool cmTarget::IsXCTestOnApple() const
-{
-  return (this->IsCFBundleOnApple() &&
-          this->GetPropertyAsBool("XCTEST"));
-}
-
-//----------------------------------------------------------------------------
-static bool processSources(cmTarget const* tgt,
-      const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
-      std::vector<std::string> &srcs,
-      UNORDERED_SET<std::string> &uniqueSrcs,
-      cmGeneratorExpressionDAGChecker *dagChecker,
-      std::string const& config, bool debugSources)
-{
-  cmMakefile *mf = tgt->GetMakefile();
-
-  bool contextDependent = false;
-
-  for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
-      it = entries.begin(), end = entries.end(); it != end; ++it)
-    {
-    cmLinkImplItem const& item = (*it)->LinkImplItem;
-    std::string const& targetName = item;
-    std::vector<std::string> entrySources;
-    cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
-                                              config,
-                                              false,
-                                              tgt,
-                                              tgt,
-                                              dagChecker),
-                                    entrySources);
-
-    if ((*it)->ge->GetHadContextSensitiveCondition())
-      {
-      contextDependent = true;
-      }
-
-    for(std::vector<std::string>::iterator i = entrySources.begin();
-        i != entrySources.end(); ++i)
-      {
-      std::string& src = *i;
-      cmSourceFile* sf = mf->GetOrCreateSource(src);
-      std::string e;
-      std::string fullPath = sf->GetFullPath(&e);
-      if(fullPath.empty())
-        {
-        if(!e.empty())
-          {
-          cmake* cm = mf->GetCMakeInstance();
-          cm->IssueMessage(cmake::FATAL_ERROR, e,
-                          tgt->GetBacktrace());
-          }
-        return contextDependent;
-        }
-
-      if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src.c_str()))
-        {
-        std::ostringstream err;
-        if (!targetName.empty())
-          {
-          err << "Target \"" << targetName << "\" contains relative "
-            "path in its INTERFACE_SOURCES:\n"
-            "  \"" << src << "\"";
-          }
-        else
-          {
-          err << "Found relative path while evaluating sources of "
-          "\"" << tgt->GetName() << "\":\n  \"" << src << "\"\n";
-          }
-        tgt->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, err.str());
-        return contextDependent;
-        }
-      src = fullPath;
-      }
-    std::string usedSources;
-    for(std::vector<std::string>::iterator
-          li = entrySources.begin(); li != entrySources.end(); ++li)
-      {
-      std::string src = *li;
-
-      if(uniqueSrcs.insert(src).second)
-        {
-        srcs.push_back(src);
-        if (debugSources)
-          {
-          usedSources += " * " + src + "\n";
-          }
-        }
-      }
-    if (!usedSources.empty())
-      {
-      mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
-                            std::string("Used sources for target ")
-                            + tgt->GetName() + ":\n"
-                            + usedSources, (*it)->ge->GetBacktrace());
-      }
-    }
-  return contextDependent;
-}
-
-//----------------------------------------------------------------------------
-void cmTarget::GetSourceFiles(std::vector<std::string> &files,
-                              const std::string& config) const
-{
-  assert(this->GetType() != INTERFACE_LIBRARY);
-
-  if (!this->GetMakefile()->GetGlobalGenerator()->GetConfigureDoneCMP0026())
-    {
-    // At configure-time, this method can be called as part of getting the
-    // LOCATION property or to export() a file to be include()d.  However
-    // there is no cmGeneratorTarget at configure-time, so search the SOURCES
-    // for TARGET_OBJECTS instead for backwards compatibility with OLD
-    // behavior of CMP0024 and CMP0026 only.
-
-    typedef cmTargetInternals::TargetPropertyEntry
-                                TargetPropertyEntry;
-    for(std::vector<TargetPropertyEntry*>::const_iterator
-          i = this->Internal->SourceEntries.begin();
-        i != this->Internal->SourceEntries.end(); ++i)
-      {
-      std::string entry = (*i)->ge->GetInput();
-
-      std::vector<std::string> items;
-      cmSystemTools::ExpandListArgument(entry, items);
-      for (std::vector<std::string>::const_iterator
-          li = items.begin(); li != items.end(); ++li)
-        {
-        if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
-            (*li)[li->size() - 1] == '>')
-          {
-          continue;
-          }
-        files.push_back(*li);
-        }
-      }
-    return;
-    }
-
-  std::vector<std::string> debugProperties;
-  const char *debugProp =
-              this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
-  if (debugProp)
-    {
-    cmSystemTools::ExpandListArgument(debugProp, debugProperties);
-    }
-
-  bool debugSources = !this->DebugSourcesDone
-                    && std::find(debugProperties.begin(),
-                                 debugProperties.end(),
-                                 "SOURCES")
-                        != debugProperties.end();
-
-  if (this->GetMakefile()->GetGlobalGenerator()->GetConfigureDoneCMP0026())
-    {
-    this->DebugSourcesDone = true;
-    }
-
-  cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
-                                             "SOURCES", 0, 0);
-
-  UNORDERED_SET<std::string> uniqueSrcs;
-  bool contextDependentDirectSources = processSources(this,
-                 this->Internal->SourceEntries,
-                 files,
-                 uniqueSrcs,
-                 &dagChecker,
-                 config,
-                 debugSources);
-
-  std::vector<cmTargetInternals::TargetPropertyEntry*>
-    linkInterfaceSourcesEntries;
-
-  this->Internal->AddInterfaceEntries(
-    this, config, "INTERFACE_SOURCES",
-    linkInterfaceSourcesEntries);
-
-  std::vector<std::string>::size_type numFilesBefore = files.size();
-  bool contextDependentInterfaceSources = processSources(this,
-    linkInterfaceSourcesEntries,
-                            files,
-                            uniqueSrcs,
-                            &dagChecker,
-                            config,
-                            debugSources);
-
-  if (!contextDependentDirectSources
-      && !(contextDependentInterfaceSources && numFilesBefore < files.size()))
-    {
-    this->LinkImplementationLanguageIsContextDependent = false;
-    }
-
-  cmDeleteAll(linkInterfaceSourcesEntries);
-}
-
-//----------------------------------------------------------------------------
-void cmTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
-                              const std::string& config) const
-{
-
-  // Lookup any existing link implementation for this configuration.
-  std::string key = cmSystemTools::UpperCase(config);
-
-  if(!this->LinkImplementationLanguageIsContextDependent)
-    {
-    files = this->Internal->SourceFilesMap.begin()->second;
-    return;
-    }
-
-  cmTargetInternals::SourceFilesMapType::iterator
-    it = this->Internal->SourceFilesMap.find(key);
-  if(it != this->Internal->SourceFilesMap.end())
-    {
-    files = it->second;
-    }
-  else
-    {
-    std::vector<std::string> srcs;
-    this->GetSourceFiles(srcs, config);
-
-    std::set<cmSourceFile*> emitted;
-
-    for(std::vector<std::string>::const_iterator i = srcs.begin();
-        i != srcs.end(); ++i)
-      {
-      cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
-      if (emitted.insert(sf).second)
-        {
-        files.push_back(sf);
-        }
-      }
-    this->Internal->SourceFilesMap[key] = files;
-    }
-}
-
-//----------------------------------------------------------------------------
 void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
 {
-  std::string srcFiles = cmJoin(srcs, ";");
-  if (!srcFiles.empty())
+  if (!srcs.empty())
     {
-    this->Internal->SourceFilesMap.clear();
-    this->LinkImplementationLanguageIsContextDependent = true;
     cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
-    cmGeneratorExpression ge(lfbt);
-    cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(srcFiles);
-    cge->SetEvaluateForBuildsystem(true);
-    this->Internal->SourceEntries.push_back(
-                          new cmTargetInternals::TargetPropertyEntry(cge));
+    this->Internal->SourceEntries.push_back(cmJoin(srcs, ";"));
+    this->Internal->SourceBacktraces.push_back(lfbt);
     }
 }
 
@@ -811,14 +390,9 @@ void cmTarget::AddSources(std::vector<std::string> const& srcs)
     }
   if (!srcFiles.empty())
     {
-    this->Internal->SourceFilesMap.clear();
-    this->LinkImplementationLanguageIsContextDependent = true;
     cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
-    cmGeneratorExpression ge(lfbt);
-    cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(srcFiles);
-    cge->SetEvaluateForBuildsystem(true);
-    this->Internal->SourceEntries.push_back(
-                          new cmTargetInternals::TargetPropertyEntry(cge));
+    this->Internal->SourceEntries.push_back(srcFiles);
+    this->Internal->SourceBacktraces.push_back(lfbt);
     }
 }
 
@@ -922,10 +496,10 @@ public:
 
   }
 
-  bool operator()(cmTargetInternals::TargetPropertyEntry* entry)
+  bool operator()(std::string const& entry)
   {
     std::vector<std::string> files;
-    cmSystemTools::ExpandListArgument(entry->ge->GetInput(), files);
+    cmSystemTools::ExpandListArgument(entry, files);
     std::vector<cmSourceFileLocation> locations(files.size());
     std::transform(files.begin(), files.end(), locations.begin(),
                    CreateLocation(this->Needle.GetMakefile()));
@@ -944,14 +518,9 @@ cmSourceFile* cmTarget::AddSource(const std::string& src)
                    TargetPropertyEntryFinder(sfl))
                                       == this->Internal->SourceEntries.end())
     {
-    this->Internal->SourceFilesMap.clear();
-    this->LinkImplementationLanguageIsContextDependent = true;
     cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
-    cmGeneratorExpression ge(lfbt);
-    cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
-    cge->SetEvaluateForBuildsystem(true);
-    this->Internal->SourceEntries.push_back(
-                          new cmTargetInternals::TargetPropertyEntry(cge));
+    this->Internal->SourceEntries.push_back(src);
+    this->Internal->SourceBacktraces.push_back(lfbt);
     }
   if (cmGeneratorExpression::Find(src) != std::string::npos)
     {
@@ -996,31 +565,6 @@ const std::vector<std::string>& cmTarget::GetLinkDirectories() const
 }
 
 //----------------------------------------------------------------------------
-cmTarget::LinkLibraryType cmTarget::ComputeLinkType(
-                                      const std::string& config) const
-{
-  // No configuration is always optimized.
-  if(config.empty())
-    {
-    return cmTarget::OPTIMIZED;
-    }
-
-  // Get the list of configurations considered to be DEBUG.
-  std::vector<std::string> debugConfigs =
-    this->Makefile->GetCMakeInstance()->GetDebugConfigs();
-
-  // Check if any entry in the list matches this configuration.
-  std::string configUpper = cmSystemTools::UpperCase(config);
-  if (std::find(debugConfigs.begin(), debugConfigs.end(), configUpper) !=
-      debugConfigs.end())
-    {
-    return cmTarget::DEBUG;
-    }
-  // The current configuration is not a debug configuration.
-  return cmTarget::OPTIMIZED;
-}
-
-//----------------------------------------------------------------------------
 void cmTarget::ClearDependencyInformation( cmMakefile& mf,
                                            const std::string& target )
 {
@@ -1049,17 +593,10 @@ void cmTarget::ClearDependencyInformation( cmMakefile& mf,
 }
 
 //----------------------------------------------------------------------------
-bool cmTarget::NameResolvesToFramework(const std::string& libname) const
-{
-  return this->Makefile->GetGlobalGenerator()->
-    NameResolvesToFramework(libname);
-}
-
-//----------------------------------------------------------------------------
 std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
-                                  cmTarget::LinkLibraryType llt) const
+                                  cmTargetLinkLibraryType llt) const
 {
-  if (llt == GENERAL)
+  if (llt == GENERAL_LibraryType)
     {
     return value;
     }
@@ -1080,7 +617,7 @@ std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
     configString = "$<OR:" + configString + ">";
     }
 
-  if (llt == OPTIMIZED)
+  if (llt == OPTIMIZED_LibraryType)
     {
     configString = "$<NOT:" + configString + ">";
     }
@@ -1137,22 +674,23 @@ void cmTarget::GetTllSignatureTraces(std::ostringstream &s,
 void cmTarget::AddLinkLibrary(cmMakefile& mf,
                               const std::string& target,
                               const std::string& lib,
-                              LinkLibraryType llt)
+                              cmTargetLinkLibraryType llt)
 {
   cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
   {
   const bool isNonImportedTarget = tgt && !tgt->IsImported();
 
-  const std::string libName = (isNonImportedTarget && llt != GENERAL)
-                                                        ? targetNameGenex(lib)
-                                                        : lib;
+  const std::string libName =
+      (isNonImportedTarget && llt != GENERAL_LibraryType)
+      ? targetNameGenex(lib)
+      : lib;
   this->AppendProperty("LINK_LIBRARIES",
                        this->GetDebugGeneratorExpressions(libName,
                                                           llt).c_str());
   }
 
   if (cmGeneratorExpression::Find(lib) != std::string::npos
-      || (tgt && tgt->GetType() == INTERFACE_LIBRARY)
+      || (tgt && tgt->GetType() == cmState::INTERFACE_LIBRARY)
       || (target == lib ))
     {
     return;
@@ -1165,7 +703,6 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf,
   this->LinkLibrariesForVS6.push_back( tmp );
 #endif
   this->OriginalLinkLibraries.push_back(tmp);
-  this->ClearLinkMaps();
 
   // Add the explicit dependency information for this target. This is
   // simply a set of libraries separated by ";". There should always
@@ -1187,13 +724,13 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf,
       }
     switch (llt)
       {
-      case cmTarget::GENERAL:
+      case GENERAL_LibraryType:
         dependencies += "general";
         break;
-      case cmTarget::DEBUG:
+      case DEBUG_LibraryType:
         dependencies += "debug";
         break;
-      case cmTarget::OPTIMIZED:
+      case OPTIMIZED_LibraryType:
         dependencies += "optimized";
         break;
       }
@@ -1254,6 +791,26 @@ cmBacktraceRange cmTarget::GetCompileDefinitionsBacktraces() const
   return cmMakeRange(this->Internal->CompileDefinitionsBacktraces);
 }
 
+cmStringRange cmTarget::GetSourceEntries() const
+{
+  return cmMakeRange(this->Internal->SourceEntries);
+}
+
+cmBacktraceRange cmTarget::GetSourceBacktraces() const
+{
+  return cmMakeRange(this->Internal->SourceBacktraces);
+}
+
+cmStringRange cmTarget::GetLinkImplementationEntries() const
+{
+  return cmMakeRange(this->Internal->LinkImplementationPropertyEntries);
+}
+
+cmBacktraceRange cmTarget::GetLinkImplementationBacktraces() const
+{
+  return cmMakeRange(this->Internal->LinkImplementationPropertyBacktraces);
+}
+
 #if defined(_WIN32) && !defined(__CYGWIN__)
 //----------------------------------------------------------------------------
 void
@@ -1507,7 +1064,7 @@ void cmTarget::GatherDependenciesForVS6( const cmMakefile& mf,
 
     // Parse the dependency information, which is a set of
     // type, library pairs separated by ";". There is always a trailing ";".
-    cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
+    cmTargetLinkLibraryType llt = GENERAL_LibraryType;
     std::string depline = deps;
     std::string::size_type start = 0;
     std::string::size_type end;
@@ -1519,22 +1076,22 @@ void cmTarget::GatherDependenciesForVS6( const cmMakefile& mf,
         {
         if (l == "debug")
           {
-          llt = cmTarget::DEBUG;
+          llt = DEBUG_LibraryType;
           }
         else if (l == "optimized")
           {
-          llt = cmTarget::OPTIMIZED;
+          llt = OPTIMIZED_LibraryType;
           }
         else if (l == "general")
           {
-          llt = cmTarget::GENERAL;
+          llt = GENERAL_LibraryType;
           }
         else
           {
           LibraryID lib2(l,llt);
           this->InsertDependencyForVS6( dep_map, lib, lib2);
           this->GatherDependenciesForVS6( mf, lib2, dep_map);
-          llt = cmTarget::GENERAL;
+          llt = GENERAL_LibraryType;
           }
         }
       start = end+1; // skip the ;
@@ -1582,7 +1139,7 @@ static bool whiteListedInterfaceProperty(const std::string& prop)
 //----------------------------------------------------------------------------
 void cmTarget::SetProperty(const std::string& prop, const char* value)
 {
-  if (this->GetType() == INTERFACE_LIBRARY
+  if (this->GetType() == cmState::INTERFACE_LIBRARY
       && !whiteListedInterfaceProperty(prop))
     {
     std::ostringstream e;
@@ -1652,11 +1209,12 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
   else if (prop == "LINK_LIBRARIES")
     {
     this->Internal->LinkImplementationPropertyEntries.clear();
+    this->Internal->LinkImplementationPropertyBacktraces.clear();
     if (value)
       {
       cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
-      cmValueWithOrigin entry(value, lfbt);
-      this->Internal->LinkImplementationPropertyEntries.push_back(entry);
+      this->Internal->LinkImplementationPropertyEntries.push_back(value);
+      this->Internal->LinkImplementationPropertyBacktraces.push_back(lfbt);
       }
     }
   else if (prop == "SOURCES")
@@ -1669,19 +1227,19 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
       this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
       return;
       }
-    this->Internal->SourceFilesMap.clear();
-    cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
-    cmGeneratorExpression ge(lfbt);
-    cmDeleteAll(this->Internal->SourceEntries);
+
     this->Internal->SourceEntries.clear();
-    cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
-    this->Internal->SourceEntries.push_back(
-                          new cmTargetInternals::TargetPropertyEntry(cge));
+    this->Internal->SourceBacktraces.clear();
+    if (value)
+      {
+      cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
+      this->Internal->SourceEntries.push_back(value);
+      this->Internal->SourceBacktraces.push_back(lfbt);
+      }
     }
   else
     {
     this->Properties.SetProperty(prop, value);
-    this->MaybeInvalidatePropertyCache(prop);
     }
 }
 
@@ -1689,7 +1247,7 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
 void cmTarget::AppendProperty(const std::string& prop, const char* value,
                               bool asString)
 {
-  if (this->GetType() == INTERFACE_LIBRARY
+  if (this->GetType() == cmState::INTERFACE_LIBRARY
       && !whiteListedInterfaceProperty(prop))
     {
     std::ostringstream e;
@@ -1753,8 +1311,8 @@ void cmTarget::AppendProperty(const std::string& prop, const char* value,
     if (value && *value)
       {
       cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
-      cmValueWithOrigin entry(value, lfbt);
-      this->Internal->LinkImplementationPropertyEntries.push_back(entry);
+      this->Internal->LinkImplementationPropertyEntries.push_back(value);
+      this->Internal->LinkImplementationPropertyBacktraces.push_back(lfbt);
       }
     }
   else if (prop == "SOURCES")
@@ -1767,47 +1325,23 @@ void cmTarget::AppendProperty(const std::string& prop, const char* value,
       this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
       return;
       }
-    this->Internal->SourceFilesMap.clear();
     cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
-    cmGeneratorExpression ge(lfbt);
-    cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
-    this->Internal->SourceEntries.push_back(
-                          new cmTargetInternals::TargetPropertyEntry(cge));
+    this->Internal->SourceEntries.push_back(value);
+    this->Internal->SourceBacktraces.push_back(lfbt);
     }
   else
     {
     this->Properties.AppendProperty(prop, value, asString);
-    this->MaybeInvalidatePropertyCache(prop);
-    }
-}
-
-//----------------------------------------------------------------------------
-std::string cmTarget::GetExportName() const
-{
-  const char *exportName = this->GetProperty("EXPORT_NAME");
-
-  if (exportName && *exportName)
-    {
-    if (!cmGeneratorExpression::IsValidTargetName(exportName))
-      {
-      std::ostringstream e;
-      e << "EXPORT_NAME property \"" << exportName << "\" for \""
-        << this->GetName() << "\": is not valid.";
-      cmSystemTools::Error(e.str().c_str());
-      return "";
-      }
-    return exportName;
     }
-  return this->GetName();
 }
 
 //----------------------------------------------------------------------------
 void cmTarget::AppendBuildInterfaceIncludes()
 {
-  if(this->GetType() != cmTarget::SHARED_LIBRARY &&
-     this->GetType() != cmTarget::STATIC_LIBRARY &&
-     this->GetType() != cmTarget::MODULE_LIBRARY &&
-     this->GetType() != cmTarget::INTERFACE_LIBRARY &&
+  if(this->GetType() != cmState::SHARED_LIBRARY &&
+     this->GetType() != cmState::STATIC_LIBRARY &&
+     this->GetType() != cmState::MODULE_LIBRARY &&
+     this->GetType() != cmState::INTERFACE_LIBRARY &&
      !this->IsExecutableWithExports())
     {
     return;
@@ -1876,20 +1410,6 @@ void cmTarget::InsertCompileDefinition(std::string const& entry,
 }
 
 //----------------------------------------------------------------------------
-void cmTarget::MaybeInvalidatePropertyCache(const std::string& prop)
-{
-  // Wipe out maps caching information affected by this property.
-  if(this->IsImported() && cmHasLiteralPrefix(prop, "IMPORTED"))
-    {
-    this->Internal->ImportInfoMap.clear();
-    }
-  if(!this->IsImported() && cmHasLiteralPrefix(prop, "LINK_INTERFACE_"))
-    {
-    this->ClearLinkMaps();
-    }
-}
-
-//----------------------------------------------------------------------------
 static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
   const std::string& prop, const char* value, cmMakefile* context,
   bool imported)
@@ -1984,206 +1504,59 @@ void cmTarget::CheckProperty(const std::string& prop,
 }
 
 //----------------------------------------------------------------------------
-void cmTarget::MarkAsImported()
+void cmTarget::MarkAsImported(bool global)
 {
   this->IsImportedTarget = true;
+  this->ImportedGloballyVisible = global;
 }
 
 //----------------------------------------------------------------------------
-bool cmTarget::HaveWellDefinedOutputFiles() const
-{
-  return
-    this->GetType() == cmTarget::STATIC_LIBRARY ||
-    this->GetType() == cmTarget::SHARED_LIBRARY ||
-    this->GetType() == cmTarget::MODULE_LIBRARY ||
-    this->GetType() == cmTarget::EXECUTABLE;
-}
-
-//----------------------------------------------------------------------------
-cmTarget::OutputInfo const* cmTarget::GetOutputInfo(
-    const std::string& config) const
+bool cmTarget::HandleLocationPropertyPolicy(cmMakefile* context) const
 {
-  // There is no output information for imported targets.
-  if(this->IsImported())
+  if (this->IsImported())
     {
-    return 0;
+    return true;
     }
-
-  // Only libraries and executables have well-defined output files.
-  if(!this->HaveWellDefinedOutputFiles())
+  std::ostringstream e;
+  const char *modal = 0;
+  cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+  switch (context->GetPolicyStatus(cmPolicies::CMP0026))
     {
-    std::string msg = "cmTarget::GetOutputInfo called for ";
-    msg += this->GetName();
-    msg += " which has type ";
-    msg += cmTarget::GetTargetTypeName(this->GetType());
-    this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
-    return 0;
+    case cmPolicies::WARN:
+      e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0026) << "\n";
+      modal = "should";
+    case cmPolicies::OLD:
+      break;
+    case cmPolicies::REQUIRED_ALWAYS:
+    case cmPolicies::REQUIRED_IF_USED:
+    case cmPolicies::NEW:
+      modal = "may";
+      messageType = cmake::FATAL_ERROR;
     }
 
-  // Lookup/compute/cache the output information for this configuration.
-  std::string config_upper;
-  if(!config.empty())
+  if (modal)
     {
-    config_upper = cmSystemTools::UpperCase(config);
+    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>, "
+      "as appropriate.\n";
+    context->IssueMessage(messageType, e.str());
     }
-  typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
-  OutputInfoMapType::iterator i =
-    this->Internal->OutputInfoMap.find(config_upper);
-  if(i == this->Internal->OutputInfoMap.end())
-    {
-    // Add empty info in map to detect potential recursion.
-    OutputInfo info;
-    OutputInfoMapType::value_type entry(config_upper, info);
-    i = this->Internal->OutputInfoMap.insert(entry).first;
 
-    // Compute output directories.
-    this->ComputeOutputDir(config, false, info.OutDir);
-    this->ComputeOutputDir(config, true, info.ImpDir);
-    if(!this->ComputePDBOutputDir("PDB", config, info.PdbDir))
-      {
-      info.PdbDir = info.OutDir;
-      }
+  return messageType != cmake::FATAL_ERROR;
+}
 
-    // Now update the previously-prepared map entry.
-    i->second = info;
-    }
-  else if(i->second.empty())
-    {
-    // An empty map entry indicates we have been called recursively
-    // from the above block.
-    this->Makefile->GetCMakeInstance()->IssueMessage(
-      cmake::FATAL_ERROR,
-      "Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.",
-      this->GetBacktrace());
-    return 0;
-    }
-  return &i->second;
+//----------------------------------------------------------------------------
+const char *cmTarget::GetProperty(const std::string& prop) const
+{
+  return this->GetProperty(prop, this->Makefile);
 }
 
 //----------------------------------------------------------------------------
-std::string cmTarget::GetDirectory(const std::string& config,
-                                   bool implib) const
+const char *cmTarget::GetProperty(const std::string& prop,
+                                  cmMakefile* context) const
 {
-  if (this->IsImported())
-    {
-    // Return the directory from which the target is imported.
-    return
-      cmSystemTools::GetFilenamePath(
-      this->ImportedGetFullPath(config, implib));
-    }
-  else if(OutputInfo const* info = this->GetOutputInfo(config))
-    {
-    // Return the directory in which the target will be built.
-    return implib? info->ImpDir : info->OutDir;
-    }
-  return "";
-}
-
-//----------------------------------------------------------------------------
-std::string cmTarget::GetPDBDirectory(const std::string& config) const
-{
-  if(OutputInfo const* info = this->GetOutputInfo(config))
-    {
-    // Return the directory in which the target will be built.
-    return info->PdbDir;
-    }
-  return "";
-}
-
-//----------------------------------------------------------------------------
-const char* cmTarget::ImportedGetLocation(const std::string& config) const
-{
-  static std::string location;
-  assert(this->IsImported());
-  location = this->ImportedGetFullPath(config, false);
-  return location.c_str();
-}
-
-//----------------------------------------------------------------------------
-void cmTarget::GetTargetVersion(int& major, int& minor) const
-{
-  int patch;
-  this->GetTargetVersion(false, major, minor, patch);
-}
-
-//----------------------------------------------------------------------------
-void cmTarget::GetTargetVersion(bool soversion,
-                                int& major, int& minor, int& patch) const
-{
-  // Set the default values.
-  major = 0;
-  minor = 0;
-  patch = 0;
-
-  assert(this->GetType() != INTERFACE_LIBRARY);
-
-  // Look for a VERSION or SOVERSION property.
-  const char* prop = soversion? "SOVERSION" : "VERSION";
-  if(const char* version = this->GetProperty(prop))
-    {
-    // Try to parse the version number and store the results that were
-    // successfully parsed.
-    int parsed_major;
-    int parsed_minor;
-    int parsed_patch;
-    switch(sscanf(version, "%d.%d.%d",
-                  &parsed_major, &parsed_minor, &parsed_patch))
-      {
-      case 3: patch = parsed_patch; // no break!
-      case 2: minor = parsed_minor; // no break!
-      case 1: major = parsed_major; // no break!
-      default: break;
-      }
-    }
-}
-
-//----------------------------------------------------------------------------
-bool cmTarget::HandleLocationPropertyPolicy(cmMakefile* context) const
-{
-  if (this->IsImported())
-    {
-    return true;
-    }
-  std::ostringstream e;
-  const char *modal = 0;
-  cmake::MessageType messageType = cmake::AUTHOR_WARNING;
-  switch (context->GetPolicyStatus(cmPolicies::CMP0026))
-    {
-    case cmPolicies::WARN:
-      e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0026) << "\n";
-      modal = "should";
-    case cmPolicies::OLD:
-      break;
-    case cmPolicies::REQUIRED_ALWAYS:
-    case cmPolicies::REQUIRED_IF_USED:
-    case cmPolicies::NEW:
-      modal = "may";
-      messageType = cmake::FATAL_ERROR;
-    }
-
-  if (modal)
-    {
-    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>, "
-      "as appropriate.\n";
-    context->IssueMessage(messageType, e.str());
-    }
-
-  return messageType != cmake::FATAL_ERROR;
-}
-
-//----------------------------------------------------------------------------
-const char *cmTarget::GetProperty(const std::string& prop) const
-{
-  return this->GetProperty(prop, this->Makefile);
-}
-
-//----------------------------------------------------------------------------
-const char *cmTarget::GetProperty(const std::string& prop,
-                                  cmMakefile* context) const
-{
-  if (this->GetType() == INTERFACE_LIBRARY
+  if (this->GetType() == cmState::INTERFACE_LIBRARY
       && !whiteListedInterfaceProperty(prop))
     {
     std::ostringstream e;
@@ -2195,11 +1568,11 @@ const char *cmTarget::GetProperty(const std::string& prop,
 
   // Watch for special "computed" properties that are dependent on
   // other properties or variables.  Always recompute them.
-  if(this->GetType() == cmTarget::EXECUTABLE ||
-     this->GetType() == cmTarget::STATIC_LIBRARY ||
-     this->GetType() == cmTarget::SHARED_LIBRARY ||
-     this->GetType() == cmTarget::MODULE_LIBRARY ||
-     this->GetType() == cmTarget::UNKNOWN_LIBRARY)
+  if(this->GetType() == cmState::EXECUTABLE ||
+     this->GetType() == cmState::STATIC_LIBRARY ||
+     this->GetType() == cmState::SHARED_LIBRARY ||
+     this->GetType() == cmState::MODULE_LIBRARY ||
+     this->GetType() == cmState::UNKNOWN_LIBRARY)
     {
     static const std::string propLOCATION = "LOCATION";
     if(prop == propLOCATION)
@@ -2227,7 +1600,7 @@ const char *cmTarget::GetProperty(const std::string& prop,
         // CMake time.
         cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
         gg->CreateGenerationObjects();
-        cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
+        cmGeneratorTarget* gt = gg->FindGeneratorTarget(this->GetName());
         this->Properties.SetProperty(propLOCATION,
                                      gt->GetLocationForBuild());
         }
@@ -2252,7 +1625,7 @@ const char *cmTarget::GetProperty(const std::string& prop,
         {
         cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
         gg->CreateGenerationObjects();
-        cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
+        cmGeneratorTarget* gt = gg->FindGeneratorTarget(this->GetName());
         this->Properties.SetProperty(
                 prop, gt->GetFullPath(configName, false).c_str());
         }
@@ -2276,7 +1649,7 @@ const char *cmTarget::GetProperty(const std::string& prop,
           {
           cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
           gg->CreateGenerationObjects();
-          cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
+          cmGeneratorTarget* gt = gg->FindGeneratorTarget(this->GetName());
           this->Properties.SetProperty(
                   prop, gt->GetFullPath(configName, false).c_str());
           }
@@ -2322,23 +1695,13 @@ const char *cmTarget::GetProperty(const std::string& prop,
         }
 
       static std::string output;
-      output = "";
-      std::string sep;
-      for (std::vector<cmValueWithOrigin>::const_iterator
-          it = this->Internal->LinkImplementationPropertyEntries.begin(),
-          end = this->Internal->LinkImplementationPropertyEntries.end();
-          it != end; ++it)
-        {
-        output += sep;
-        output += it->Value;
-        sep = ";";
-        }
+      output = cmJoin(this->Internal->LinkImplementationPropertyEntries, ";");
       return output.c_str();
       }
     // the type property returns what type the target is
     else if (prop == propTYPE)
       {
-      return cmTarget::GetTargetTypeName(this->GetType());
+      return cmState::GetTargetTypeName(this->GetType());
       }
     else if(prop == propINCLUDE_DIRECTORIES)
       {
@@ -2409,13 +1772,11 @@ const char *cmTarget::GetProperty(const std::string& prop,
 
       std::ostringstream ss;
       const char* sep = "";
-      typedef cmTargetInternals::TargetPropertyEntry
-                                  TargetPropertyEntry;
-      for(std::vector<TargetPropertyEntry*>::const_iterator
+      for(std::vector<std::string>::const_iterator
             i = this->Internal->SourceEntries.begin();
           i != this->Internal->SourceEntries.end(); ++i)
         {
-        std::string entry = (*i)->ge->GetInput();
+        std::string const& entry = *i;
 
         std::vector<std::string> files;
         cmSystemTools::ExpandListArgument(entry, files);
@@ -2521,17 +1882,17 @@ const char* cmTarget::GetSuffixVariableInternal(bool implib) const
 {
   switch(this->GetType())
     {
-    case cmTarget::STATIC_LIBRARY:
+    case cmState::STATIC_LIBRARY:
       return "CMAKE_STATIC_LIBRARY_SUFFIX";
-    case cmTarget::SHARED_LIBRARY:
+    case cmState::SHARED_LIBRARY:
       return (implib
               ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
               : "CMAKE_SHARED_LIBRARY_SUFFIX");
-    case cmTarget::MODULE_LIBRARY:
+    case cmState::MODULE_LIBRARY:
       return (implib
               ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
               : "CMAKE_SHARED_MODULE_SUFFIX");
-    case cmTarget::EXECUTABLE:
+    case cmState::EXECUTABLE:
       return (implib
               ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
                 // Android GUI application packages store the native
@@ -2550,17 +1911,17 @@ const char* cmTarget::GetPrefixVariableInternal(bool implib) const
 {
   switch(this->GetType())
     {
-    case cmTarget::STATIC_LIBRARY:
+    case cmState::STATIC_LIBRARY:
       return "CMAKE_STATIC_LIBRARY_PREFIX";
-    case cmTarget::SHARED_LIBRARY:
+    case cmState::SHARED_LIBRARY:
       return (implib
               ? "CMAKE_IMPORT_LIBRARY_PREFIX"
               : "CMAKE_SHARED_LIBRARY_PREFIX");
-    case cmTarget::MODULE_LIBRARY:
+    case cmState::MODULE_LIBRARY:
       return (implib
               ? "CMAKE_IMPORT_LIBRARY_PREFIX"
               : "CMAKE_SHARED_MODULE_PREFIX");
-    case cmTarget::EXECUTABLE:
+    case cmState::EXECUTABLE:
       return (implib
               ? "CMAKE_IMPORT_LIBRARY_PREFIX"
                 // Android GUI application packages store the native
@@ -2574,148 +1935,76 @@ const char* cmTarget::GetPrefixVariableInternal(bool implib) const
 }
 
 //----------------------------------------------------------------------------
-bool cmTarget::HasMacOSXRpathInstallNameDir(const std::string& config) const
+std::string
+cmTarget::ImportedGetFullPath(const std::string& config, bool pimplib) const
 {
-  bool install_name_is_rpath = false;
-  bool macosx_rpath = false;
+  assert(this->IsImported());
 
-  if(!this->IsImportedTarget)
+  // Lookup/compute/cache the import information for this
+  // configuration.
+  std::string config_upper;
+  if(!config.empty())
     {
-    if(this->GetType() != cmTarget::SHARED_LIBRARY)
-      {
-      return false;
-      }
-    const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
-    bool use_install_name =
-      this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
-    if(install_name && use_install_name &&
-       std::string(install_name) == "@rpath")
-      {
-      install_name_is_rpath = true;
-      }
-    else if(install_name && use_install_name)
-      {
-      return false;
-      }
-    if(!install_name_is_rpath)
-      {
-      macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
-      }
+    config_upper = cmSystemTools::UpperCase(config);
     }
   else
     {
-    // Lookup the imported soname.
-    if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
+    config_upper = "NOCONFIG";
+    }
+
+  std::string result;
+
+  const char* loc = 0;
+  const char* imp = 0;
+  std::string suffix;
+
+  if(this->GetType() != cmState::INTERFACE_LIBRARY
+     && this->GetMappedConfig(config_upper, &loc, &imp, suffix))
+    {
+    if (!pimplib)
       {
-      if(!info->NoSOName && !info->SOName.empty())
+      if(loc)
         {
-        if(info->SOName.find("@rpath/") == 0)
-          {
-          install_name_is_rpath = true;
-          }
+        result = loc;
         }
       else
         {
-        std::string install_name;
-        cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
-        if(install_name.find("@rpath") != std::string::npos)
+        std::string impProp = "IMPORTED_LOCATION";
+        impProp += suffix;
+        if(const char* config_location = this->GetProperty(impProp))
+          {
+          result = config_location;
+          }
+        else if(const char* location =
+                this->GetProperty("IMPORTED_LOCATION"))
           {
-          install_name_is_rpath = true;
+          result = location;
           }
         }
       }
-    }
-
-  if(!install_name_is_rpath && !macosx_rpath)
-    {
-    return false;
-    }
-
-  if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
-    {
-    std::ostringstream w;
-    w << "Attempting to use";
-    if(macosx_rpath)
-      {
-      w << " MACOSX_RPATH";
-      }
     else
       {
-      w << " @rpath";
-      }
-    w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
-    w << "  This could be because you are using a Mac OS X version";
-    w << " less than 10.5 or because CMake's platform configuration is";
-    w << " corrupt.";
-    cmake* cm = this->Makefile->GetCMakeInstance();
-    cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
-    }
-
-  return true;
-}
-
-//----------------------------------------------------------------------------
-bool cmTarget::MacOSXRpathInstallNameDirDefault() const
-{
-  // we can't do rpaths when unsupported
-  if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
-    {
-    return false;
-    }
-
-  const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
-  if(macosx_rpath_str)
-    {
-    return this->GetPropertyAsBool("MACOSX_RPATH");
-    }
-
-  cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
-
-  if(cmp0042 == cmPolicies::WARN)
-    {
-    this->Makefile->GetGlobalGenerator()->
-      AddCMP0042WarnTarget(this->GetName());
-    }
-
-  if(cmp0042 == cmPolicies::NEW)
-    {
-    return true;
-    }
-
-  return false;
-}
-
-//----------------------------------------------------------------------------
-bool cmTarget::IsImportedSharedLibWithoutSOName(
-                                          const std::string& config) const
-{
-  if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
-    {
-    if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
-      {
-      return info->NoSOName;
+      if(imp)
+        {
+        result = imp;
+        }
+      else if(this->GetType() == cmState::SHARED_LIBRARY ||
+              this->IsExecutableWithExports())
+        {
+        std::string impProp = "IMPORTED_IMPLIB";
+        impProp += suffix;
+        if(const char* config_implib = this->GetProperty(impProp))
+          {
+          result = config_implib;
+          }
+        else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
+          {
+          result = implib;
+          }
+        }
       }
     }
-  return false;
-}
-
-//----------------------------------------------------------------------------
-std::string
-cmTarget::GetFullNameImported(const std::string& config, bool implib) const
-{
-  return cmSystemTools::GetFilenameName(
-    this->ImportedGetFullPath(config, implib));
-}
 
-//----------------------------------------------------------------------------
-std::string
-cmTarget::ImportedGetFullPath(const std::string& config, bool implib) const
-{
-  std::string result;
-  if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
-    {
-    result = implib? info->ImportLibrary : info->Location;
-    }
   if(result.empty())
     {
     result = this->GetName();
@@ -2725,43 +2014,6 @@ cmTarget::ImportedGetFullPath(const std::string& config, bool implib) const
 }
 
 //----------------------------------------------------------------------------
-void cmTarget::ComputeVersionedName(std::string& vName,
-                                    std::string const& prefix,
-                                    std::string const& base,
-                                    std::string const& suffix,
-                                    std::string const& name,
-                                    const char* version) const
-{
-  vName = this->IsApple? (prefix+base) : name;
-  if(version)
-    {
-    vName += ".";
-    vName += version;
-    }
-  vName += this->IsApple? suffix : std::string();
-}
-
-//----------------------------------------------------------------------------
-bool cmTarget::HasImplibGNUtoMS() const
-{
-  return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
-}
-
-//----------------------------------------------------------------------------
-bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
-                                std::string& out, const char* newExt) const
-{
-  if(this->HasImplibGNUtoMS() &&
-     gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
-    {
-    out = gnuName.substr(0, gnuName.size()-6);
-    out += newExt? newExt : ".lib";
-    return true;
-    }
-  return false;
-}
-
-//----------------------------------------------------------------------------
 void cmTarget::SetPropertyDefault(const std::string& property,
                                   const char* default_value)
 {
@@ -2779,417 +2031,49 @@ void cmTarget::SetPropertyDefault(const std::string& property,
     }
 }
 
-//----------------------------------------------------------------------------
-bool cmTarget::HaveInstallTreeRPATH() const
-{
-  const char* install_rpath = this->GetProperty("INSTALL_RPATH");
-  return (install_rpath && *install_rpath) &&
-          !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
-}
-
-//----------------------------------------------------------------------------
-const char* cmTarget::GetOutputTargetType(bool implib) const
+bool cmTarget::GetMappedConfig(std::string const& desired_config,
+                               const char** loc,
+                               const char** imp,
+                               std::string& suffix) const
 {
-  switch(this->GetType())
+  if (this->GetType() == cmState::INTERFACE_LIBRARY)
     {
-    case cmTarget::SHARED_LIBRARY:
-      if(this->DLLPlatform)
-        {
-        if(implib)
-          {
-          // A DLL import library is treated as an archive target.
-          return "ARCHIVE";
-          }
-        else
-          {
-          // A DLL shared library is treated as a runtime target.
-          return "RUNTIME";
-          }
-        }
-      else
-        {
-        // For non-DLL platforms shared libraries are treated as
-        // library targets.
-        return "LIBRARY";
-        }
-    case cmTarget::STATIC_LIBRARY:
-      // Static libraries are always treated as archive targets.
-      return "ARCHIVE";
-    case cmTarget::MODULE_LIBRARY:
-      if(implib)
-        {
-        // Module libraries are always treated as library targets.
-        return "ARCHIVE";
-        }
-      else
-        {
-        // Module import libraries are treated as archive targets.
-        return "LIBRARY";
-        }
-    case cmTarget::EXECUTABLE:
-      if(implib)
-        {
-        // Executable import libraries are treated as archive targets.
-        return "ARCHIVE";
-        }
-      else
-        {
-        // Executables are always treated as runtime targets.
-        return "RUNTIME";
-        }
-    default:
-      break;
+    // This method attempts to find a config-specific LOCATION for the
+    // IMPORTED library. In the case of cmState::INTERFACE_LIBRARY, there is no
+    // LOCATION at all, so leaving *loc and *imp unchanged is the appropriate
+    // and valid response.
+    return true;
     }
-  return "";
-}
-
-//----------------------------------------------------------------------------
-bool cmTarget::ComputeOutputDir(const std::string& config,
-                                bool implib, std::string& out) const
-{
-  bool usesDefaultOutputDir = false;
-  std::string conf = config;
 
-  // Look for a target property defining the target output directory
-  // based on the target type.
-  std::string targetTypeName = this->GetOutputTargetType(implib);
-  const char* propertyName = 0;
-  std::string propertyNameStr = targetTypeName;
-  if(!propertyNameStr.empty())
-    {
-    propertyNameStr += "_OUTPUT_DIRECTORY";
-    propertyName = propertyNameStr.c_str();
-    }
+  // Track the configuration-specific property suffix.
+  suffix = "_";
+  suffix += desired_config;
 
-  // Check for a per-configuration output directory target property.
-  std::string configUpper = cmSystemTools::UpperCase(conf);
-  const char* configProp = 0;
-  std::string configPropStr = targetTypeName;
-  if(!configPropStr.empty())
+  std::vector<std::string> mappedConfigs;
+  {
+  std::string mapProp = "MAP_IMPORTED_CONFIG_";
+  mapProp += desired_config;
+  if(const char* mapValue = this->GetProperty(mapProp))
     {
-    configPropStr += "_OUTPUT_DIRECTORY_";
-    configPropStr += configUpper;
-    configProp = configPropStr.c_str();
+    cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
     }
+  }
 
-  // Select an output directory.
-  if(const char* config_outdir = this->GetProperty(configProp))
-    {
-    // Use the user-specified per-configuration output directory.
-    cmGeneratorExpression ge;
-    cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
-      ge.Parse(config_outdir);
-    out = cge->Evaluate(this->Makefile, config);
+  // If we needed to find one of the mapped configurations but did not
+  // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
+  // library or an executable with exports.
+  bool allowImp = this->HasImportLibrary();
 
-    // Skip per-configuration subdirectory.
-    conf = "";
-    }
-  else if(const char* outdir = this->GetProperty(propertyName))
+  // If a mapping was found, check its configurations.
+  for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
+      !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
     {
-    // Use the user-specified output directory.
-    cmGeneratorExpression ge;
-    cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
-      ge.Parse(outdir);
-    out = cge->Evaluate(this->Makefile, config);
-
-    // Skip per-configuration subdirectory if the value contained a
-    // generator expression.
-    if (out != outdir)
-      {
-      conf = "";
-      }
-    }
-  else if(this->GetType() == cmTarget::EXECUTABLE)
-    {
-    // Lookup the output path for executables.
-    out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
-    }
-  else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
-          this->GetType() == cmTarget::SHARED_LIBRARY ||
-          this->GetType() == cmTarget::MODULE_LIBRARY)
-    {
-    // Lookup the output path for libraries.
-    out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
-    }
-  if(out.empty())
-    {
-    // Default to the current output directory.
-    usesDefaultOutputDir = true;
-    out = ".";
-    }
-
-  // Convert the output path to a full path in case it is
-  // specified as a relative path.  Treat a relative path as
-  // relative to the current output directory for this makefile.
-  out = (cmSystemTools::CollapseFullPath
-         (out, this->Makefile->GetCurrentBinaryDirectory()));
-
-  // The generator may add the configuration's subdirectory.
-  if(!conf.empty())
-    {
-    bool iosPlatform = this->Makefile->PlatformIsAppleIos();
-    std::string suffix =
-      usesDefaultOutputDir && iosPlatform ? "${EFFECTIVE_PLATFORM_NAME}" : "";
-    this->Makefile->GetGlobalGenerator()->
-      AppendDirectoryForConfig("/", conf, suffix, out);
-    }
-
-  return usesDefaultOutputDir;
-}
-
-//----------------------------------------------------------------------------
-bool cmTarget::ComputePDBOutputDir(const std::string& kind,
-                                   const std::string& config,
-                                   std::string& out) const
-{
-  // Look for a target property defining the target output directory
-  // based on the target type.
-  const char* propertyName = 0;
-  std::string propertyNameStr = kind;
-  if(!propertyNameStr.empty())
-    {
-    propertyNameStr += "_OUTPUT_DIRECTORY";
-    propertyName = propertyNameStr.c_str();
-    }
-  std::string conf = config;
-
-  // Check for a per-configuration output directory target property.
-  std::string configUpper = cmSystemTools::UpperCase(conf);
-  const char* configProp = 0;
-  std::string configPropStr = kind;
-  if(!configPropStr.empty())
-    {
-    configPropStr += "_OUTPUT_DIRECTORY_";
-    configPropStr += configUpper;
-    configProp = configPropStr.c_str();
-    }
-
-  // Select an output directory.
-  if(const char* config_outdir = this->GetProperty(configProp))
-    {
-    // Use the user-specified per-configuration output directory.
-    out = config_outdir;
-
-    // Skip per-configuration subdirectory.
-    conf = "";
-    }
-  else if(const char* outdir = this->GetProperty(propertyName))
-    {
-    // Use the user-specified output directory.
-    out = outdir;
-    }
-  if(out.empty())
-    {
-    return false;
-    }
-
-  // Convert the output path to a full path in case it is
-  // specified as a relative path.  Treat a relative path as
-  // relative to the current output directory for this makefile.
-  out = (cmSystemTools::CollapseFullPath
-         (out, this->Makefile->GetCurrentBinaryDirectory()));
-
-  // The generator may add the configuration's subdirectory.
-  if(!conf.empty())
-    {
-    this->Makefile->GetGlobalGenerator()->
-      AppendDirectoryForConfig("/", conf, "", out);
-    }
-  return true;
-}
-
-//----------------------------------------------------------------------------
-bool cmTarget::UsesDefaultOutputDir(const std::string& config,
-                                    bool implib) const
-{
-  std::string dir;
-  return this->ComputeOutputDir(config, implib, dir);
-}
-
-//----------------------------------------------------------------------------
-std::string cmTarget::GetFrameworkVersion() const
-{
-  assert(this->GetType() != INTERFACE_LIBRARY);
-
-  if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
-    {
-    return fversion;
-    }
-  else if(const char* tversion = this->GetProperty("VERSION"))
-    {
-    return tversion;
-    }
-  else
-    {
-    return "A";
-    }
-}
-
-//----------------------------------------------------------------------------
-const char* cmTarget::GetExportMacro() const
-{
-  // Define the symbol for targets that export symbols.
-  if(this->GetType() == cmTarget::SHARED_LIBRARY ||
-     this->GetType() == cmTarget::MODULE_LIBRARY ||
-     this->IsExecutableWithExports())
-    {
-    if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
-      {
-      this->ExportMacro = custom_export_name;
-      }
-    else
-      {
-      std::string in = this->GetName();
-      in += "_EXPORTS";
-      this->ExportMacro = cmSystemTools::MakeCindentifier(in);
-      }
-    return this->ExportMacro.c_str();
-    }
-  else
-    {
-    return 0;
-    }
-}
-
-//----------------------------------------------------------------------------
-bool cmTarget::IsNullImpliedByLinkLibraries(const std::string &p) const
-{
-  return this->LinkImplicitNullProperties.find(p)
-      != this->LinkImplicitNullProperties.end();
-}
-
-//----------------------------------------------------------------------------
-void
-cmTarget::GetObjectLibrariesCMP0026(std::vector<cmTarget*>& objlibs) const
-{
-  // At configure-time, this method can be called as part of getting the
-  // LOCATION property or to export() a file to be include()d.  However
-  // there is no cmGeneratorTarget at configure-time, so search the SOURCES
-  // for TARGET_OBJECTS instead for backwards compatibility with OLD
-  // behavior of CMP0024 and CMP0026 only.
-  typedef cmTargetInternals::TargetPropertyEntry
-                              TargetPropertyEntry;
-  for(std::vector<TargetPropertyEntry*>::const_iterator
-        i = this->Internal->SourceEntries.begin();
-      i != this->Internal->SourceEntries.end(); ++i)
-    {
-    std::string entry = (*i)->ge->GetInput();
-
-    std::vector<std::string> files;
-    cmSystemTools::ExpandListArgument(entry, files);
-    for (std::vector<std::string>::const_iterator
-        li = files.begin(); li != files.end(); ++li)
-      {
-      if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
-          (*li)[li->size() - 1] == '>')
-        {
-        std::string objLibName = li->substr(17, li->size()-18);
-
-        if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
-          {
-          continue;
-          }
-        cmTarget *objLib = this->Makefile->FindTargetToUse(objLibName);
-        if(objLib)
-          {
-          objlibs.push_back(objLib);
-          }
-        }
-      }
-    }
-}
-
-//----------------------------------------------------------------------------
-cmTarget::ImportInfo const*
-cmTarget::GetImportInfo(const std::string& config) const
-{
-  // There is no imported information for non-imported targets.
-  if(!this->IsImported())
-    {
-    return 0;
-    }
-
-  // Lookup/compute/cache the import information for this
-  // configuration.
-  std::string config_upper;
-  if(!config.empty())
-    {
-    config_upper = cmSystemTools::UpperCase(config);
-    }
-  else
-    {
-    config_upper = "NOCONFIG";
-    }
-  typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
-
-  ImportInfoMapType::const_iterator i =
-    this->Internal->ImportInfoMap.find(config_upper);
-  if(i == this->Internal->ImportInfoMap.end())
-    {
-    ImportInfo info;
-    this->ComputeImportInfo(config_upper, info);
-    ImportInfoMapType::value_type entry(config_upper, info);
-    i = this->Internal->ImportInfoMap.insert(entry).first;
-    }
-
-  if(this->GetType() == INTERFACE_LIBRARY)
-    {
-    return &i->second;
-    }
-  // If the location is empty then the target is not available for
-  // this configuration.
-  if(i->second.Location.empty() && i->second.ImportLibrary.empty())
-    {
-    return 0;
-    }
-
-  // Return the import information.
-  return &i->second;
-}
-
-bool cmTarget::GetMappedConfig(std::string const& desired_config,
-                               const char** loc,
-                               const char** imp,
-                               std::string& suffix) const
-{
-  if (this->GetType() == INTERFACE_LIBRARY)
-    {
-    // This method attempts to find a config-specific LOCATION for the
-    // IMPORTED library. In the case of INTERFACE_LIBRARY, there is no
-    // LOCATION at all, so leaving *loc and *imp unchanged is the appropriate
-    // and valid response.
-    return true;
-    }
-
-  // Track the configuration-specific property suffix.
-  suffix = "_";
-  suffix += desired_config;
-
-  std::vector<std::string> mappedConfigs;
-  {
-  std::string mapProp = "MAP_IMPORTED_CONFIG_";
-  mapProp += desired_config;
-  if(const char* mapValue = this->GetProperty(mapProp))
-    {
-    cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
-    }
-  }
-
-  // If we needed to find one of the mapped configurations but did not
-  // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
-  // library or an executable with exports.
-  bool allowImp = this->HasImportLibrary();
-
-  // If a mapping was found, check its configurations.
-  for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
-      !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
-    {
-    // Look for this configuration.
-    std::string mcUpper = cmSystemTools::UpperCase(*mci);
-    std::string locProp = "IMPORTED_LOCATION_";
-    locProp += mcUpper;
-    *loc = this->GetProperty(locProp);
-    if(allowImp)
+    // Look for this configuration.
+    std::string mcUpper = cmSystemTools::UpperCase(*mci);
+    std::string locProp = "IMPORTED_LOCATION_";
+    locProp += mcUpper;
+    *loc = this->GetProperty(locProp);
+    if(allowImp)
       {
       std::string impProp = "IMPORTED_IMPLIB_";
       impProp += mcUpper;
@@ -3279,445 +2163,6 @@ bool cmTarget::GetMappedConfig(std::string const& desired_config,
 }
 
 //----------------------------------------------------------------------------
-void cmTarget::ComputeImportInfo(std::string const& desired_config,
-                                 ImportInfo& info) const
-{
-  // This method finds information about an imported target from its
-  // properties.  The "IMPORTED_" namespace is reserved for properties
-  // defined by the project exporting the target.
-
-  // Initialize members.
-  info.NoSOName = false;
-
-  const char* loc = 0;
-  const char* imp = 0;
-  std::string suffix;
-  if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix))
-    {
-    return;
-    }
-
-  // Get the link interface.
-  {
-  std::string linkProp = "INTERFACE_LINK_LIBRARIES";
-  const char *propertyLibs = this->GetProperty(linkProp);
-
-  if (this->GetType() != INTERFACE_LIBRARY)
-    {
-    if(!propertyLibs)
-      {
-      linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
-      linkProp += suffix;
-      propertyLibs = this->GetProperty(linkProp);
-      }
-
-    if(!propertyLibs)
-      {
-      linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
-      propertyLibs = this->GetProperty(linkProp);
-      }
-    }
-  if(propertyLibs)
-    {
-    info.LibrariesProp = linkProp;
-    info.Libraries = propertyLibs;
-    }
-  }
-  if(this->GetType() == INTERFACE_LIBRARY)
-    {
-    return;
-    }
-
-  // A provided configuration has been chosen.  Load the
-  // configuration's properties.
-
-  // Get the location.
-  if(loc)
-    {
-    info.Location = loc;
-    }
-  else
-    {
-    std::string impProp = "IMPORTED_LOCATION";
-    impProp += suffix;
-    if(const char* config_location = this->GetProperty(impProp))
-      {
-      info.Location = config_location;
-      }
-    else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
-      {
-      info.Location = location;
-      }
-    }
-
-  // Get the soname.
-  if(this->GetType() == cmTarget::SHARED_LIBRARY)
-    {
-    std::string soProp = "IMPORTED_SONAME";
-    soProp += suffix;
-    if(const char* config_soname = this->GetProperty(soProp))
-      {
-      info.SOName = config_soname;
-      }
-    else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
-      {
-      info.SOName = soname;
-      }
-    }
-
-  // Get the "no-soname" mark.
-  if(this->GetType() == cmTarget::SHARED_LIBRARY)
-    {
-    std::string soProp = "IMPORTED_NO_SONAME";
-    soProp += suffix;
-    if(const char* config_no_soname = this->GetProperty(soProp))
-      {
-      info.NoSOName = cmSystemTools::IsOn(config_no_soname);
-      }
-    else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
-      {
-      info.NoSOName = cmSystemTools::IsOn(no_soname);
-      }
-    }
-
-  // Get the import library.
-  if(imp)
-    {
-    info.ImportLibrary = imp;
-    }
-  else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
-          this->IsExecutableWithExports())
-    {
-    std::string impProp = "IMPORTED_IMPLIB";
-    impProp += suffix;
-    if(const char* config_implib = this->GetProperty(impProp))
-      {
-      info.ImportLibrary = config_implib;
-      }
-    else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
-      {
-      info.ImportLibrary = implib;
-      }
-    }
-
-  // Get the link dependencies.
-  {
-  std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
-  linkProp += suffix;
-  if(const char* config_libs = this->GetProperty(linkProp))
-    {
-    info.SharedDeps = config_libs;
-    }
-  else if(const char* libs =
-          this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
-    {
-    info.SharedDeps = libs;
-    }
-  }
-
-  // Get the link languages.
-  if(this->LinkLanguagePropagatesToDependents())
-    {
-    std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
-    linkProp += suffix;
-    if(const char* config_libs = this->GetProperty(linkProp))
-      {
-      info.Languages = config_libs;
-      }
-    else if(const char* libs =
-            this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
-      {
-      info.Languages = libs;
-      }
-    }
-
-  // Get the cyclic repetition count.
-  if(this->GetType() == cmTarget::STATIC_LIBRARY)
-    {
-    std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
-    linkProp += suffix;
-    if(const char* config_reps = this->GetProperty(linkProp))
-      {
-      sscanf(config_reps, "%u", &info.Multiplicity);
-      }
-    else if(const char* reps =
-            this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
-      {
-      sscanf(reps, "%u", &info.Multiplicity);
-      }
-    }
-}
-
-//----------------------------------------------------------------------------
-void cmTargetInternals::AddInterfaceEntries(
-  cmTarget const* thisTarget, std::string const& config,
-  std::string const& prop, std::vector<TargetPropertyEntry*>& entries)
-{
-  if(cmLinkImplementationLibraries const* impl =
-     thisTarget->GetLinkImplementationLibraries(config))
-    {
-    for (std::vector<cmLinkImplItem>::const_iterator
-           it = impl->Libraries.begin(), end = impl->Libraries.end();
-         it != end; ++it)
-      {
-      if(it->Target)
-        {
-        std::string genex =
-          "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
-        cmGeneratorExpression ge(it->Backtrace);
-        cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
-        cge->SetEvaluateForBuildsystem(true);
-        entries.push_back(
-          new cmTargetInternals::TargetPropertyEntry(cge, *it));
-        }
-      }
-    }
-}
-
-cmOptionalLinkImplementation&
-cmTarget::GetLinkImplMap(std::string const& config) const
-{
-  // Populate the link implementation for this configuration.
-  std::string CONFIG = cmSystemTools::UpperCase(config);
-  return Internal->LinkImplMap[CONFIG][this];
-}
-
-//----------------------------------------------------------------------------
-cmLinkImplementationLibraries const*
-cmTarget::GetLinkImplementationLibraries(const std::string& config) const
-{
-  return this->GetLinkImplementationLibrariesInternal(config, this);
-}
-
-//----------------------------------------------------------------------------
-cmLinkImplementationLibraries const*
-cmTarget::GetLinkImplementationLibrariesInternal(const std::string& config,
-                                                 cmTarget const* head) const
-{
-  // There is no link implementation for imported targets.
-  if(this->IsImported())
-    {
-    return 0;
-    }
-
-  // Populate the link implementation libraries for this configuration.
-  std::string CONFIG = cmSystemTools::UpperCase(config);
-  cmTargetInternals::HeadToLinkImplementationMap& hm =
-    this->Internal->LinkImplMap[CONFIG];
-
-  // If the link implementation does not depend on the head target
-  // then return the one we computed first.
-  if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
-    {
-    return &hm.begin()->second;
-    }
-
-  cmOptionalLinkImplementation& impl = hm[head];
-  if(!impl.LibrariesDone)
-    {
-    impl.LibrariesDone = true;
-    this->ComputeLinkImplementationLibraries(config, impl, head);
-    }
-  return &impl;
-}
-
-//----------------------------------------------------------------------------
-void cmTarget::ComputeLinkImplementationLibraries(
-  const std::string& config,
-  cmOptionalLinkImplementation& impl,
-  cmTarget const* head) const
-{
-  // Collect libraries directly linked in this configuration.
-  for (std::vector<cmValueWithOrigin>::const_iterator
-      le = this->Internal->LinkImplementationPropertyEntries.begin(),
-      end = this->Internal->LinkImplementationPropertyEntries.end();
-      le != end; ++le)
-    {
-    std::vector<std::string> llibs;
-    cmGeneratorExpressionDAGChecker dagChecker(
-                                        this->GetName(),
-                                        "LINK_LIBRARIES", 0, 0);
-    cmGeneratorExpression ge(le->Backtrace);
-    cmsys::auto_ptr<cmCompiledGeneratorExpression> const cge =
-      ge.Parse(le->Value);
-    std::string const evaluated =
-      cge->Evaluate(this->Makefile, config, false, head, &dagChecker);
-    cmSystemTools::ExpandListArgument(evaluated, llibs);
-    if(cge->GetHadHeadSensitiveCondition())
-      {
-      impl.HadHeadSensitiveCondition = true;
-      }
-
-    for(std::vector<std::string>::const_iterator li = llibs.begin();
-        li != llibs.end(); ++li)
-      {
-      // Skip entries that resolve to the target itself or are empty.
-      std::string name = this->CheckCMP0004(*li);
-      if(name == this->GetName() || name.empty())
-        {
-        if(name == this->GetName())
-          {
-          bool noMessage = false;
-          cmake::MessageType messageType = cmake::FATAL_ERROR;
-          std::ostringstream e;
-          switch(this->GetPolicyStatusCMP0038())
-            {
-            case cmPolicies::WARN:
-              {
-              e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n";
-              messageType = cmake::AUTHOR_WARNING;
-              }
-              break;
-            case cmPolicies::OLD:
-              noMessage = true;
-            case cmPolicies::REQUIRED_IF_USED:
-            case cmPolicies::REQUIRED_ALWAYS:
-            case cmPolicies::NEW:
-              // Issue the fatal message.
-              break;
-            }
-
-          if(!noMessage)
-            {
-            e << "Target \"" << this->GetName() << "\" links to itself.";
-            this->Makefile->GetCMakeInstance()->IssueMessage(
-              messageType, e.str(), this->GetBacktrace());
-            if (messageType == cmake::FATAL_ERROR)
-              {
-              return;
-              }
-            }
-          }
-        continue;
-        }
-
-      // The entry is meant for this configuration.
-      impl.Libraries.push_back(
-        cmLinkImplItem(name, this->FindTargetToLink(name),
-                       le->Backtrace, evaluated != le->Value));
-      }
-
-    std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
-    for (std::set<std::string>::const_iterator it = seenProps.begin();
-        it != seenProps.end(); ++it)
-      {
-      if (!this->GetProperty(*it))
-        {
-        this->LinkImplicitNullProperties.insert(*it);
-        }
-      }
-    cge->GetMaxLanguageStandard(this, this->MaxLanguageStandards);
-    }
-
-  cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
-  cmTarget::LinkLibraryVectorType const& oldllibs =
-    this->GetOriginalLinkLibraries();
-  for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
-      li != oldllibs.end(); ++li)
-    {
-    if(li->second != cmTarget::GENERAL && li->second != linkType)
-      {
-      std::string name = this->CheckCMP0004(li->first);
-      if(name == this->GetName() || name.empty())
-        {
-        continue;
-        }
-      // Support OLD behavior for CMP0003.
-      impl.WrongConfigLibraries.push_back(
-        cmLinkItem(name, this->FindTargetToLink(name)));
-      }
-    }
-}
-
-//----------------------------------------------------------------------------
-cmTarget const* cmTarget::FindTargetToLink(std::string const& name) const
-{
-  cmTarget const* tgt = this->Makefile->FindTargetToUse(name);
-
-  // Skip targets that will not really be linked.  This is probably a
-  // name conflict between an external library and an executable
-  // within the project.
-  if(tgt && tgt->GetType() == cmTarget::EXECUTABLE &&
-     !tgt->IsExecutableWithExports())
-    {
-    tgt = 0;
-    }
-
-  if(tgt && tgt->GetType() == cmTarget::OBJECT_LIBRARY)
-    {
-    std::ostringstream e;
-    e << "Target \"" << this->GetName() << "\" links to "
-      "OBJECT library \"" << tgt->GetName() << "\" but this is not "
-      "allowed.  "
-      "One may link only to STATIC or SHARED libraries, or to executables "
-      "with the ENABLE_EXPORTS property set.";
-    cmake* cm = this->Makefile->GetCMakeInstance();
-    cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
-    tgt = 0;
-    }
-
-  // Return the target found, if any.
-  return tgt;
-}
-
-//----------------------------------------------------------------------------
-std::string cmTarget::CheckCMP0004(std::string const& item) const
-{
-  // Strip whitespace off the library names because we used to do this
-  // in case variables were expanded at generate time.  We no longer
-  // do the expansion but users link to libraries like " ${VAR} ".
-  std::string lib = item;
-  std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
-  if(pos != lib.npos)
-    {
-    lib = lib.substr(pos, lib.npos);
-    }
-  pos = lib.find_last_not_of(" \t\r\n");
-  if(pos != lib.npos)
-    {
-    lib = lib.substr(0, pos+1);
-    }
-  if(lib != item)
-    {
-    cmake* cm = this->Makefile->GetCMakeInstance();
-    switch(this->GetPolicyStatusCMP0004())
-      {
-      case cmPolicies::WARN:
-        {
-        std::ostringstream w;
-        w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
-          << "Target \"" << this->GetName() << "\" links to item \""
-          << item << "\" which has leading or trailing whitespace.";
-        cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
-                         this->GetBacktrace());
-        }
-      case cmPolicies::OLD:
-        break;
-      case cmPolicies::NEW:
-        {
-        std::ostringstream e;
-        e << "Target \"" << this->GetName() << "\" links to item \""
-          << item << "\" which has leading or trailing whitespace.  "
-          << "This is now an error according to policy CMP0004.";
-        cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
-        }
-        break;
-      case cmPolicies::REQUIRED_IF_USED:
-      case cmPolicies::REQUIRED_ALWAYS:
-        {
-        std::ostringstream e;
-        e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
-          << "Target \"" << this->GetName() << "\" links to item \""
-          << item << "\" which has leading or trailing whitespace.";
-        cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
-        }
-        break;
-      }
-    }
-  return lib;
-}
-
-//----------------------------------------------------------------------------
 cmTargetInternalPointer::cmTargetInternalPointer()
 {
   this->Pointer = new cmTargetInternals;
@@ -3736,7 +2181,6 @@ cmTargetInternalPointer
 //----------------------------------------------------------------------------
 cmTargetInternalPointer::~cmTargetInternalPointer()
 {
-  cmDeleteAll(this->Pointer->SourceEntries);
   delete this->Pointer;
 }
 
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index 3e71dbd..97b0871 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -16,7 +16,6 @@
 #include "cmPropertyMap.h"
 #include "cmPolicies.h"
 #include "cmListFileCache.h"
-#include "cmLinkItem.h"
 
 #include <cmsys/auto_ptr.hxx>
 #if defined(CMAKE_BUILD_WITH_CMAKE)
@@ -27,28 +26,10 @@
 # endif
 #endif
 
-#define CM_FOR_EACH_TARGET_POLICY(F) \
-  F(CMP0003) \
-  F(CMP0004) \
-  F(CMP0008) \
-  F(CMP0020) \
-  F(CMP0021) \
-  F(CMP0022) \
-  F(CMP0027) \
-  F(CMP0038) \
-  F(CMP0041) \
-  F(CMP0042) \
-  F(CMP0046) \
-  F(CMP0052) \
-  F(CMP0060) \
-  F(CMP0063) \
-  F(CMP0065)
-
 class cmake;
 class cmMakefile;
 class cmSourceFile;
 class cmGlobalGenerator;
-class cmComputeLinkInformation;
 class cmListFileBacktrace;
 class cmTarget;
 class cmGeneratorTarget;
@@ -78,18 +59,12 @@ class cmTarget
 {
 public:
   cmTarget();
-  enum TargetType { EXECUTABLE, STATIC_LIBRARY,
-                    SHARED_LIBRARY, MODULE_LIBRARY,
-                    OBJECT_LIBRARY, UTILITY, GLOBAL_TARGET,
-                    INTERFACE_LIBRARY,
-                    UNKNOWN_LIBRARY};
-  static const char* GetTargetTypeName(TargetType targetType);
   enum CustomCommandType { PRE_BUILD, PRE_LINK, POST_BUILD };
 
   /**
    * Return the type of target.
    */
-  TargetType GetType() const
+  cmState::TargetType GetType() const
     {
     return this->TargetTypeValue;
     }
@@ -97,13 +72,12 @@ public:
   /**
    * Set the target type
    */
-  void SetType(TargetType f, const std::string& name);
+  void SetType(cmState::TargetType f, const std::string& name);
 
-  void MarkAsImported();
+  void MarkAsImported(bool global = false);
 
   ///! Set/Get the name of the target
   const std::string& GetName() const {return this->Name;}
-  std::string GetExportName() const;
 
   ///! Set the cmMakefile that owns this target
   void SetMakefile(cmMakefile *mf);
@@ -134,11 +108,6 @@ public:
     {this->PostBuildCommands.push_back(cmd);}
 
   /**
-   * Get the list of the source files used by this target
-   */
-  void GetSourceFiles(std::vector<cmSourceFile*> &files,
-                      const std::string& config) const;
-  /**
    * Add sources to the target.
    */
   void AddSources(std::vector<std::string> const& srcs);
@@ -146,28 +115,21 @@ public:
   cmSourceFile* AddSourceCMP0049(const std::string& src);
   cmSourceFile* AddSource(const std::string& src);
 
-  enum LinkLibraryType {GENERAL, DEBUG, OPTIMIZED};
-
   //* how we identify a library, by name and type
-  typedef std::pair<std::string, LinkLibraryType> LibraryID;
+  typedef std::pair<std::string, cmTargetLinkLibraryType> LibraryID;
 
   typedef std::vector<LibraryID > LinkLibraryVectorType;
   const LinkLibraryVectorType &GetOriginalLinkLibraries() const
     {return this->OriginalLinkLibraries;}
 
-  /** Compute the link type to use for the given configuration.  */
-  LinkLibraryType ComputeLinkType(const std::string& config) const;
-
   /**
    * Clear the dependency information recorded for this target, if any.
    */
   void ClearDependencyInformation(cmMakefile& mf, const std::string& target);
 
-  // Check to see if a library is a framework and treat it different on Mac
-  bool NameResolvesToFramework(const std::string& libname) const;
   void AddLinkLibrary(cmMakefile& mf,
                       const std::string& target, const std::string& lib,
-                      LinkLibraryType llt);
+                      cmTargetLinkLibraryType llt);
   enum TLLSignature {
     KeywordTLLSignature,
     PlainTLLSignature
@@ -211,12 +173,8 @@ public:
   void AddUtility(const std::string& u, cmMakefile *makefile = 0);
   ///! Get the utilities used by this target
   std::set<std::string>const& GetUtilities() const { return this->Utilities; }
-  std::set<cmLinkItem>const& GetUtilityItems() const;
   cmListFileBacktrace const* GetUtilityBacktrace(const std::string& u) const;
 
-  /** Finalize the target at the end of the Configure step.  */
-  void FinishConfigure();
-
   ///! Set/Get a property of this target file
   void SetProperty(const std::string& prop, const char *value);
   void AppendProperty(const std::string&  prop, const char* value,
@@ -227,70 +185,8 @@ public:
   void CheckProperty(const std::string& prop, cmMakefile* context) const;
 
   bool IsImported() const {return this->IsImportedTarget;}
-
-  void GetObjectLibrariesCMP0026(std::vector<cmTarget*>& objlibs) const;
-
-  cmLinkImplementationLibraries const*
-    GetLinkImplementationLibraries(const std::string& config) const;
-
-  void ComputeLinkImplementationLibraries(const std::string& config,
-                                          cmOptionalLinkImplementation& impl,
-                                          cmTarget const* head) const;
-
-  cmOptionalLinkImplementation&
-  GetLinkImplMap(std::string const& config) const;
-
-  cmTarget const* FindTargetToLink(std::string const& name) const;
-
-  /** Strip off leading and trailing whitespace from an item named in
-      the link dependencies of this target.  */
-  std::string CheckCMP0004(std::string const& item) const;
-
-  /** Get the directory in which this target will be built.  If the
-      configuration name is given then the generator will add its
-      subdirectory for that configuration.  Otherwise just the canonical
-      output directory is given.  */
-  std::string GetDirectory(const std::string& config = "",
-                           bool implib = false) const;
-
-  /** Get the directory in which this targets .pdb files will be placed.
-      If the configuration name is given then the generator will add its
-      subdirectory for that configuration.  Otherwise just the canonical
-      pdb output directory is given.  */
-  std::string GetPDBDirectory(const std::string& config) const;
-
-  const char* ImportedGetLocation(const std::string& config) const;
-
-  /** Get the target major and minor version numbers interpreted from
-      the VERSION property.  Version 0 is returned if the property is
-      not set or cannot be parsed.  */
-  void GetTargetVersion(int& major, int& minor) const;
-
-  /** Get the target major, minor, and patch version numbers
-      interpreted from the VERSION or SOVERSION property.  Version 0
-      is returned if the property is not set or cannot be parsed.  */
-  void
-  GetTargetVersion(bool soversion, int& major, int& minor, int& patch) const;
-
-  /** Whether this library has \@rpath and platform supports it.  */
-  bool HasMacOSXRpathInstallNameDir(const std::string& config) const;
-
-  /** Whether this library defaults to \@rpath.  */
-  bool MacOSXRpathInstallNameDirDefault() const;
-
-  /** Test for special case of a third-party shared library that has
-      no soname at all.  */
-  bool IsImportedSharedLibWithoutSOName(const std::string& config) const;
-
-  /** Does this target have a GNU implib to convert to MS format?  */
-  bool HasImplibGNUtoMS() const;
-
-  /** Convert the given GNU import library name (.dll.a) to a name with a new
-      extension (.lib or ${CMAKE_IMPORT_LIBRARY_SUFFIX}).  */
-  bool GetImplibGNUtoMS(std::string const& gnuName, std::string& out,
-                        const char* newExt = 0) const;
-
-  bool HaveInstallTreeRPATH() const;
+  bool IsImportedGloballyVisible() const
+  { return this->ImportedGloballyVisible; }
 
   // Get the properties
   cmPropertyMap &GetProperties() const { return this->Properties; }
@@ -300,53 +196,20 @@ public:
                        const char** imp,
                        std::string& suffix) const;
 
-  /** Get the macro to define when building sources in this target.
-      If no macro should be defined null is returned.  */
-  const char* GetExportMacro() const;
-
   /** Return whether this target is an executable with symbol exports
       enabled.  */
   bool IsExecutableWithExports() const;
 
-  /** Return whether this target may be used to link another target.  */
-  bool IsLinkable() const;
-
-  /** Return whether or not the target is for a DLL platform.  */
-  bool IsDLLPlatform() const { return this->DLLPlatform; }
-
-  /** Return whether or not the target has a DLL import library.  */
-  bool HasImportLibrary() const;
-
   /** Return whether this target is a shared library Framework on
       Apple.  */
   bool IsFrameworkOnApple() const;
 
-  /** Return whether this target is a CFBundle (plugin) on Apple.  */
-  bool IsCFBundleOnApple() const;
-
-  /** Return whether this target is a XCTest on Apple.  */
-  bool IsXCTestOnApple() const;
-
   /** Return whether this target is an executable Bundle on Apple.  */
   bool IsAppBundleOnApple() const;
 
-  /** Return the framework version string.  Undefined if
-      IsFrameworkOnApple returns false.  */
-  std::string GetFrameworkVersion() const;
-
   /** Get a backtrace from the creation of the target.  */
   cmListFileBacktrace const& GetBacktrace() const;
 
-  /** Get a build-tree directory in which to place target support files.  */
-  std::string GetSupportDirectory() const;
-
-  /** Return whether this target uses the default value for its output
-      directory.  */
-  bool UsesDefaultOutputDir(const std::string& config, bool implib) const;
-
-  /** @return whether this target have a well defined output file name. */
-  bool HaveWellDefinedOutputFiles() const;
-
   void InsertInclude(std::string const& entry,
                      cmListFileBacktrace const& bt,
                      bool before = false);
@@ -358,24 +221,13 @@ public:
 
   void AppendBuildInterfaceIncludes();
 
-  bool IsNullImpliedByLinkLibraries(const std::string &p) const;
-
   std::string GetDebugGeneratorExpressions(const std::string &value,
-                                  cmTarget::LinkLibraryType llt) const;
+                                  cmTargetLinkLibraryType llt) const;
 
   void AddSystemIncludeDirectories(const std::set<std::string> &incs);
   std::set<std::string> const & GetSystemIncludeDirectories() const
     { return this->SystemIncludeDirectories; }
 
-  bool LinkLanguagePropagatesToDependents() const
-  { return this->TargetTypeValue == STATIC_LIBRARY; }
-
-  std::map<std::string, std::string> const&
-  GetMaxLanguageStandards() const
-  {
-    return this->MaxLanguageStandards;
-  }
-
   cmStringRange GetIncludeDirectoriesEntries() const;
   cmBacktraceRange GetIncludeDirectoriesBacktraces() const;
 
@@ -388,11 +240,22 @@ public:
   cmStringRange GetCompileDefinitionsEntries() const;
   cmBacktraceRange GetCompileDefinitionsBacktraces() const;
 
+  cmStringRange GetSourceEntries() const;
+  cmBacktraceRange GetSourceBacktraces() const;
+  cmStringRange GetLinkImplementationEntries() const;
+  cmBacktraceRange GetLinkImplementationBacktraces() const;
+
 #if defined(_WIN32) && !defined(__CYGWIN__)
   const LinkLibraryVectorType &GetLinkLibrariesForVS6() const {
   return this->LinkLibrariesForVS6;}
+
+  void AnalyzeLibDependenciesForVS6( const cmMakefile& mf );
 #endif
 
+  struct StrictTargetComparison {
+    bool operator()(cmTarget const* t1, cmTarget const* t2) const;
+  };
+
 private:
   bool HandleLocationPropertyPolicy(cmMakefile* context) const;
 
@@ -445,8 +308,6 @@ private:
   void GatherDependenciesForVS6( const cmMakefile& mf,
                                  const LibraryID& lib,
                                  DependencyMap& dep_map);
-
-  void AnalyzeLibDependenciesForVS6( const cmMakefile& mf );
 #endif
 
   const char* GetSuffixVariableInternal(bool implib) const;
@@ -457,31 +318,19 @@ private:
   void SetPropertyDefault(const std::string& property,
                           const char* default_value);
 
-  // Returns ARCHIVE, LIBRARY, or RUNTIME based on platform and type.
-  const char* GetOutputTargetType(bool implib) const;
-
-  std::string GetFullNameImported(const std::string& config,
-                                  bool implib) const;
-
   std::string ImportedGetFullPath(const std::string& config,
                                   bool implib) const;
 
-
-  void GetSourceFiles(std::vector<std::string> &files,
-                      const std::string& config) const;
 private:
   mutable cmPropertyMap Properties;
   std::set<std::string> SystemIncludeDirectories;
   std::set<std::string> LinkDirectoriesEmmitted;
   std::set<std::string> Utilities;
-  mutable std::set<std::string> LinkImplicitNullProperties;
   std::map<std::string, cmListFileBacktrace> UtilityBacktraces;
-  mutable std::map<std::string, std::string> MaxLanguageStandards;
   cmPolicies::PolicyMap PolicyMap;
   std::string Name;
   std::string InstallPath;
   std::string RuntimeInstallPath;
-  mutable std::string ExportMacro;
   std::vector<std::string> LinkDirectories;
   std::vector<cmCustomCommand> PreBuildCommands;
   std::vector<cmCustomCommand> PreLinkCommands;
@@ -494,69 +343,29 @@ private:
 #endif
   cmMakefile* Makefile;
   cmTargetInternalPointer Internal;
-  TargetType TargetTypeValue;
+  cmState::TargetType TargetTypeValue;
   bool HaveInstallRule;
   bool RecordDependencies;
   bool DLLPlatform;
   bool IsAndroid;
-  bool IsApple;
   bool IsImportedTarget;
+  bool ImportedGloballyVisible;
   bool BuildInterfaceIncludesAppended;
-  mutable bool DebugSourcesDone;
-  mutable bool LinkImplementationLanguageIsContextDependent;
 #if defined(_WIN32) && !defined(__CYGWIN__)
   bool LinkLibrariesForVS6Analyzed;
 #endif
 
-  // Cache target output paths for each configuration.
-  struct OutputInfo;
-  OutputInfo const* GetOutputInfo(const std::string& config) const;
-  bool
-  ComputeOutputDir(const std::string& config,
-                   bool implib, std::string& out) const;
-  bool ComputePDBOutputDir(const std::string& kind, const std::string& config,
-                           std::string& out) const;
-
-  // Cache import information from properties for each configuration.
-  struct ImportInfo
-  {
-    ImportInfo(): NoSOName(false), Multiplicity(0) {}
-    bool NoSOName;
-    int Multiplicity;
-    std::string Location;
-    std::string SOName;
-    std::string ImportLibrary;
-    std::string Languages;
-    std::string Libraries;
-    std::string LibrariesProp;
-    std::string SharedDeps;
-  };
-
-  ImportInfo const* GetImportInfo(const std::string& config) const;
-  void ComputeImportInfo(std::string const& desired_config,
-                         ImportInfo& info) const;
-
-  cmLinkImplementationLibraries const*
-    GetLinkImplementationLibrariesInternal(const std::string& config,
-                                           cmTarget const* head) const;
-
   std::string ProcessSourceItemCMP0049(const std::string& s);
 
-  void ClearLinkMaps();
-
-  void MaybeInvalidatePropertyCache(const std::string& prop);
+  /** Return whether or not the target has a DLL import library.  */
+  bool HasImportLibrary() const;
 
   // Internal representation details.
   friend class cmTargetInternals;
   friend class cmGeneratorTarget;
   friend class cmTargetTraceDependencies;
 
-  void ComputeVersionedName(std::string& vName,
-                            std::string const& prefix,
-                            std::string const& base,
-                            std::string const& suffix,
-                            std::string const& name,
-                            const char* version) const;
+  cmListFileBacktrace Backtrace;
 };
 
 #ifdef CMAKE_BUILD_WITH_CMAKE
diff --git a/Source/cmTargetExport.h b/Source/cmTargetExport.h
index 7665888..2781337 100644
--- a/Source/cmTargetExport.h
+++ b/Source/cmTargetExport.h
@@ -14,7 +14,7 @@
 
 #include "cmStandardIncludes.h"
 
-class cmTarget;
+class cmGeneratorTarget;
 class cmInstallTargetGenerator;
 class cmInstallFilesGenerator;
 
@@ -25,7 +25,8 @@ class cmInstallFilesGenerator;
 class cmTargetExport
 {
 public:
-  cmTarget* Target; ///< The target
+  std::string TargetName;
+  cmGeneratorTarget* Target;
 
   ///@name Generators
   ///@{
diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx
index b57b921..435346a 100644
--- a/Source/cmTargetLinkLibrariesCommand.cxx
+++ b/Source/cmTargetLinkLibrariesCommand.cxx
@@ -88,7 +88,7 @@ bool cmTargetLinkLibrariesCommand
     return true;
     }
 
-  if(this->Target->GetType() == cmTarget::OBJECT_LIBRARY)
+  if(this->Target->GetType() == cmState::OBJECT_LIBRARY)
     {
     std::ostringstream e;
     e << "Object library target \"" << args[0] << "\" "
@@ -98,7 +98,7 @@ bool cmTargetLinkLibrariesCommand
     return true;
     }
 
-  if (this->Target->GetType() == cmTarget::UTILITY)
+  if (this->Target->GetType() == cmState::UTILITY)
     {
     std::ostringstream e;
     const char *modal = 0;
@@ -136,7 +136,7 @@ bool cmTargetLinkLibrariesCommand
     }
 
   // Keep track of link configuration specifiers.
-  cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
+  cmTargetLinkLibraryType llt = GENERAL_LibraryType;
   bool haveLLT = false;
 
   // Start with primary linking and switch to link interface
@@ -242,27 +242,27 @@ bool cmTargetLinkLibrariesCommand
       {
       if(haveLLT)
         {
-        this->LinkLibraryTypeSpecifierWarning(llt, cmTarget::DEBUG);
+        this->LinkLibraryTypeSpecifierWarning(llt, DEBUG_LibraryType);
         }
-      llt = cmTarget::DEBUG;
+      llt = DEBUG_LibraryType;
       haveLLT = true;
       }
     else if(args[i] == "optimized")
       {
       if(haveLLT)
         {
-        this->LinkLibraryTypeSpecifierWarning(llt, cmTarget::OPTIMIZED);
+        this->LinkLibraryTypeSpecifierWarning(llt, OPTIMIZED_LibraryType);
         }
-      llt = cmTarget::OPTIMIZED;
+      llt = OPTIMIZED_LibraryType;
       haveLLT = true;
       }
     else if(args[i] == "general")
       {
       if(haveLLT)
         {
-        this->LinkLibraryTypeSpecifierWarning(llt, cmTarget::GENERAL);
+        this->LinkLibraryTypeSpecifierWarning(llt, GENERAL_LibraryType);
         }
-      llt = cmTarget::GENERAL;
+      llt = GENERAL_LibraryType;
       haveLLT = true;
       }
     else if(haveLLT)
@@ -282,7 +282,7 @@ bool cmTargetLinkLibrariesCommand
       // specifed that a library is both debug and optimized.  (this check is
       // only there for backwards compatibility when mixing projects built
       // with old versions of CMake and new)
-      llt = cmTarget::GENERAL;
+      llt = GENERAL_LibraryType;
       std::string linkType = args[0];
       linkType += "_LINK_TYPE";
       const char* linkTypeString =
@@ -291,11 +291,11 @@ bool cmTargetLinkLibrariesCommand
         {
         if(strcmp(linkTypeString, "debug") == 0)
           {
-          llt = cmTarget::DEBUG;
+          llt = DEBUG_LibraryType;
           }
         if(strcmp(linkTypeString, "optimized") == 0)
           {
-          llt = cmTarget::OPTIMIZED;
+          llt = OPTIMIZED_LibraryType;
           }
         }
       if (!this->HandleLibrary(args[i], llt))
@@ -350,9 +350,9 @@ cmTargetLinkLibrariesCommand
 //----------------------------------------------------------------------------
 bool
 cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
-                                            cmTarget::LinkLibraryType llt)
+                                            cmTargetLinkLibraryType llt)
 {
-  if(this->Target->GetType() == cmTarget::INTERFACE_LIBRARY
+  if(this->Target->GetType() == cmState::INTERFACE_LIBRARY
       && this->CurrentProcessingState != ProcessingKeywordLinkInterface)
     {
     this->Makefile->IssueMessage(cmake::FATAL_ERROR,
@@ -428,7 +428,7 @@ cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
     else if(this->CurrentProcessingState != ProcessingKeywordPublicInterface
             && this->CurrentProcessingState != ProcessingPlainPublicInterface)
       {
-      if (this->Target->GetType() == cmTarget::STATIC_LIBRARY)
+      if (this->Target->GetType() == cmState::STATIC_LIBRARY)
         {
         std::string configLib = this->Target
                                      ->GetDebugGeneratorExpressions(lib, llt);
@@ -458,7 +458,7 @@ cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
     return true;
     }
 
-  if (this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
+  if (this->Target->GetType() == cmState::INTERFACE_LIBRARY)
     {
     return true;
     }
@@ -469,7 +469,7 @@ cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
   std::string prop;
 
   // Include this library in the link interface for the target.
-  if(llt == cmTarget::DEBUG || llt == cmTarget::GENERAL)
+  if(llt == DEBUG_LibraryType || llt == GENERAL_LibraryType)
     {
     // Put in the DEBUG configuration interfaces.
     for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
@@ -480,7 +480,7 @@ cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
       this->Target->AppendProperty(prop, lib.c_str());
       }
     }
-  if(llt == cmTarget::OPTIMIZED || llt == cmTarget::GENERAL)
+  if(llt == OPTIMIZED_LibraryType || llt == GENERAL_LibraryType)
     {
     // Put in the non-DEBUG configuration interfaces.
     this->Target->AppendProperty("LINK_INTERFACE_LIBRARIES", lib.c_str());
diff --git a/Source/cmTargetLinkLibrariesCommand.h b/Source/cmTargetLinkLibrariesCommand.h
index 47dd8bd..f061e6d 100644
--- a/Source/cmTargetLinkLibrariesCommand.h
+++ b/Source/cmTargetLinkLibrariesCommand.h
@@ -62,7 +62,7 @@ private:
 
   ProcessingState CurrentProcessingState;
 
-  bool HandleLibrary(const std::string& lib, cmTarget::LinkLibraryType llt);
+  bool HandleLibrary(const std::string& lib, cmTargetLinkLibraryType llt);
 };
 
 
diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx
index 4696de4..bfc19a4 100644
--- a/Source/cmTargetPropCommandBase.cxx
+++ b/Source/cmTargetPropCommandBase.cxx
@@ -44,12 +44,12 @@ bool cmTargetPropCommandBase
     this->HandleMissingTarget(args[0]);
     return false;
     }
-  if ((this->Target->GetType() != cmTarget::SHARED_LIBRARY)
-    && (this->Target->GetType() != cmTarget::STATIC_LIBRARY)
-    && (this->Target->GetType() != cmTarget::OBJECT_LIBRARY)
-    && (this->Target->GetType() != cmTarget::MODULE_LIBRARY)
-    && (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
-    && (this->Target->GetType() != cmTarget::EXECUTABLE))
+  if ((this->Target->GetType() != cmState::SHARED_LIBRARY)
+    && (this->Target->GetType() != cmState::STATIC_LIBRARY)
+    && (this->Target->GetType() != cmState::OBJECT_LIBRARY)
+    && (this->Target->GetType() != cmState::MODULE_LIBRARY)
+    && (this->Target->GetType() != cmState::INTERFACE_LIBRARY)
+    && (this->Target->GetType() != cmState::EXECUTABLE))
     {
     this->SetError("called with non-compilable target type");
     return false;
@@ -114,7 +114,7 @@ bool cmTargetPropCommandBase
     return false;
     }
 
-  if (this->Target->GetType() == cmTarget::INTERFACE_LIBRARY
+  if (this->Target->GetType() == cmState::INTERFACE_LIBRARY
       && scope != "INTERFACE")
     {
     this->SetError("may only be set INTERFACE properties on INTERFACE "
diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx
index 9d85f5a..b411f15 100644
--- a/Source/cmTestGenerator.cxx
+++ b/Source/cmTestGenerator.cxx
@@ -13,10 +13,8 @@
 
 #include "cmGeneratorExpression.h"
 #include "cmOutputConverter.h"
-#include "cmMakefile.h"
 #include "cmLocalGenerator.h"
 #include "cmSystemTools.h"
-#include "cmTarget.h"
 #include "cmTest.h"
 
 //----------------------------------------------------------------------------
@@ -89,8 +87,8 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
   // be translated.
   std::string exe = command[0];
   cmGeneratorTarget* target =
-      this->LG->GetMakefile()->FindGeneratorTargetToUse(exe);
-  if(target && target->GetType() == cmTarget::EXECUTABLE)
+      this->LG->FindGeneratorTargetToUse(exe);
+  if(target && target->GetType() == cmState::EXECUTABLE)
     {
     // Use the target file on disk.
     exe = target->GetFullPath(config);
@@ -117,7 +115,7 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
   else
     {
     // Use the command name given.
-    exe = ge.Parse(exe.c_str())->Evaluate(this->LG->GetMakefile(), config);
+    exe = ge.Parse(exe.c_str())->Evaluate(this->LG, config);
     cmSystemTools::ConvertToUnixSlashes(exe);
     }
 
@@ -128,7 +126,7 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
     {
     os << " " << cmOutputConverter::EscapeForCMake(
                                          ge.Parse(*ci)->Evaluate(
-                                            this->LG->GetMakefile(), config));
+                                            this->LG, config));
     }
 
   // Finish the test command.
@@ -145,7 +143,7 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
       {
       os << " " << i->first
          << " " << cmOutputConverter::EscapeForCMake(
-           ge.Parse(i->second.GetValue())->Evaluate(this->LG->GetMakefile(),
+           ge.Parse(i->second.GetValue())->Evaluate(this->LG,
                                                     config));
       }
     os << ")" << std::endl;
diff --git a/Source/cmUtilitySourceCommand.cxx b/Source/cmUtilitySourceCommand.cxx
index 486328f..3f1e333 100644
--- a/Source/cmUtilitySourceCommand.cxx
+++ b/Source/cmUtilitySourceCommand.cxx
@@ -11,8 +11,6 @@
 ============================================================================*/
 #include "cmUtilitySourceCommand.h"
 
-#include "cmCacheManager.h"
-
 // cmUtilitySourceCommand
 bool cmUtilitySourceCommand
 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
@@ -54,13 +52,13 @@ bool cmUtilitySourceCommand
     }
   else
     {
-    cmCacheManager *manager =
-        this->Makefile->GetCMakeInstance()->GetCacheManager();
+    cmState *state =
+        this->Makefile->GetState();
     haveCacheValue = (cacheValue &&
      (strstr(cacheValue, "(IntDir)") == 0 ||
       (intDir && strcmp(intDir, "$(IntDir)") == 0)) &&
-     (manager->GetCacheMajorVersion() != 0 &&
-      manager->GetCacheMinorVersion() != 0 ));
+     (state->GetCacheMajorVersion() != 0 &&
+      state->GetCacheMinorVersion() != 0 ));
     }
 
   if(haveCacheValue)
diff --git a/Source/cmVS10LinkFlagTable.h b/Source/cmVS10LinkFlagTable.h
index f6b758d..dd92329 100644
--- a/Source/cmVS10LinkFlagTable.h
+++ b/Source/cmVS10LinkFlagTable.h
@@ -155,7 +155,8 @@ static cmVS7FlagTable cmVS10LinkFlagTable[] =
   {"AllowIsolation", "ALLOWISOLATION:NO", "", "false", 0},
   {"UACUIAccess", "uiAccess='false'", "", "false", 0},
   {"UACUIAccess", "uiAccess='true'", "", "true", 0},
-  {"GenerateDebugInformation", "DEBUG", "", "true", 0},
+  {"GenerateDebugInformation", "DEBUG", "", "true",
+   cmVS7FlagTable::CaseInsensitive},
   {"MapExports", "MAPINFO:EXPORTS", "", "true", 0},
   {"AssemblyDebug", "ASSEMBLYDEBUG:DISABLE", "", "false", 0},
   {"AssemblyDebug", "ASSEMBLYDEBUG", "", "true", 0},
diff --git a/Source/cmVS11LinkFlagTable.h b/Source/cmVS11LinkFlagTable.h
index 0f641e4..2d6f6c0 100644
--- a/Source/cmVS11LinkFlagTable.h
+++ b/Source/cmVS11LinkFlagTable.h
@@ -177,7 +177,8 @@ static cmVS7FlagTable cmVS11LinkFlagTable[] =
   {"UACUIAccess", "uiAccess='false'", "", "false", 0},
   {"UACUIAccess", "uiAccess='true'", "", "true", 0},
   {"ManifestEmbed", "manifest:embed", "", "true", 0},
-  {"GenerateDebugInformation", "DEBUG", "", "true", 0},
+  {"GenerateDebugInformation", "DEBUG", "", "true",
+   cmVS7FlagTable::CaseInsensitive},
   {"MapExports", "MAPINFO:EXPORTS", "", "true", 0},
   {"AssemblyDebug", "ASSEMBLYDEBUG:DISABLE", "", "false", 0},
   {"AssemblyDebug", "ASSEMBLYDEBUG", "", "true", 0},
diff --git a/Source/cmVS12LinkFlagTable.h b/Source/cmVS12LinkFlagTable.h
index e5a570e..0be5e34 100644
--- a/Source/cmVS12LinkFlagTable.h
+++ b/Source/cmVS12LinkFlagTable.h
@@ -177,7 +177,8 @@ static cmVS7FlagTable cmVS12LinkFlagTable[] =
   {"UACUIAccess", "uiAccess='false'", "", "false", 0},
   {"UACUIAccess", "uiAccess='true'", "", "true", 0},
   {"ManifestEmbed", "manifest:embed", "", "true", 0},
-  {"GenerateDebugInformation", "DEBUG", "", "true", 0},
+  {"GenerateDebugInformation", "DEBUG", "", "true",
+   cmVS7FlagTable::CaseInsensitive},
   {"MapExports", "MAPINFO:EXPORTS", "", "true", 0},
   {"AssemblyDebug", "ASSEMBLYDEBUG:DISABLE", "", "false", 0},
   {"AssemblyDebug", "ASSEMBLYDEBUG", "", "true", 0},
diff --git a/Source/cmVS14LinkFlagTable.h b/Source/cmVS14LinkFlagTable.h
index 6d81d12..29e3d86 100644
--- a/Source/cmVS14LinkFlagTable.h
+++ b/Source/cmVS14LinkFlagTable.h
@@ -177,7 +177,10 @@ static cmVS7FlagTable cmVS14LinkFlagTable[] =
   {"UACUIAccess", "uiAccess='false'", "", "false", 0},
   {"UACUIAccess", "uiAccess='true'", "", "true", 0},
   {"ManifestEmbed", "manifest:embed", "", "true", 0},
-  {"GenerateDebugInformation", "DEBUG", "", "true", 0},
+  {"GenerateDebugInformation", "DEBUG:FASTLINK", "", "DebugFastLink",
+   cmVS7FlagTable::CaseInsensitive},
+  {"GenerateDebugInformation", "DEBUG", "", "Debug",
+   cmVS7FlagTable::CaseInsensitive},
   {"MapExports", "MAPINFO:EXPORTS", "", "true", 0},
   {"AssemblyDebug", "ASSEMBLYDEBUG:DISABLE", "", "false", 0},
   {"AssemblyDebug", "ASSEMBLYDEBUG", "", "true", 0},
diff --git a/Source/cmVersion.h b/Source/cmVersion.h
index 0ab6390..84f750f 100644
--- a/Source/cmVersion.h
+++ b/Source/cmVersion.h
@@ -34,7 +34,7 @@ public:
 
 /* Encode with room for up to 1000 minor releases between major releases
    and to encode dates until the year 10000 in the patch level.  */
-#define CMake_VERSION_ENCODE__BASE cmIML_INT_UINT64_C(100000000)
+#define CMake_VERSION_ENCODE__BASE KWIML_INT_UINT64_C(100000000)
 #define CMake_VERSION_ENCODE(major, minor, patch) \
   ((((major) * 1000u) * CMake_VERSION_ENCODE__BASE) + \
    (((minor) % 1000u) * CMake_VERSION_ENCODE__BASE) + \
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 1de2847..da950be 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -13,7 +13,6 @@
 #include "cmVisualStudio10TargetGenerator.h"
 #include "cmGlobalVisualStudio10Generator.h"
 #include "cmGeneratorTarget.h"
-#include "cmTarget.h"
 #include "cmComputeLinkInformation.h"
 #include "cmGeneratedFileStream.h"
 #include "cmMakefile.h"
@@ -167,18 +166,17 @@ static std::string cmVS10EscapeComment(std::string comment)
 }
 
 cmVisualStudio10TargetGenerator::
-cmVisualStudio10TargetGenerator(cmTarget* target,
+cmVisualStudio10TargetGenerator(cmGeneratorTarget* target,
                                 cmGlobalVisualStudio10Generator* gg)
 {
   this->GlobalGenerator = gg;
-  this->Target = target;
-  this->GeneratorTarget = gg->GetGeneratorTarget(target);
-  this->Makefile = target->GetMakefile();
+  this->GeneratorTarget = target;
+  this->Makefile = target->Target->GetMakefile();
   this->Makefile->GetConfigurations(this->Configurations);
   this->LocalGenerator =
     (cmLocalVisualStudio7Generator*)
     this->GeneratorTarget->GetLocalGenerator();
-  this->Name = this->Target->GetName();
+  this->Name = this->GeneratorTarget->GetName();
   this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str());
   this->Platform = gg->GetPlatformName();
   this->NsightTegra = gg->IsNsightTegra();
@@ -195,8 +193,8 @@ cmVisualStudio10TargetGenerator(cmTarget* target,
   this->BuildFileStream = 0;
   this->IsMissingFiles = false;
   this->DefaultArtifactDir =
-    this->Makefile->GetCurrentBinaryDirectory() + std::string("/") +
-    this->LocalGenerator->GetTargetDirectory(*this->Target);
+    this->LocalGenerator->GetCurrentBinaryDirectory() + std::string("/") +
+    this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
 }
 
 cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
@@ -269,16 +267,17 @@ void cmVisualStudio10TargetGenerator::WriteString(const char* line,
 void cmVisualStudio10TargetGenerator::Generate()
 {
   // do not generate external ms projects
-  if(this->Target->GetType() == cmTarget::INTERFACE_LIBRARY
-      || this->Target->GetProperty("EXTERNAL_MSPROJECT"))
+  if(this->GeneratorTarget->GetType() == cmState::INTERFACE_LIBRARY
+      || this->GeneratorTarget->GetProperty("EXTERNAL_MSPROJECT"))
     {
     return;
     }
   // Tell the global generator the name of the project file
-  this->Target->SetProperty("GENERATOR_FILE_NAME",this->Name.c_str());
-  this->Target->SetProperty("GENERATOR_FILE_NAME_EXT",
+  this->GeneratorTarget->Target
+      ->SetProperty("GENERATOR_FILE_NAME",this->Name.c_str());
+  this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME_EXT",
                             ".vcxproj");
-  if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
+  if(this->GeneratorTarget->GetType() <= cmState::OBJECT_LIBRARY)
     {
     if(!this->ComputeClOptions())
       {
@@ -297,8 +296,7 @@ void cmVisualStudio10TargetGenerator::Generate()
       return;
       }
     }
-  cmMakefile* mf = this->Target->GetMakefile();
-  std::string path =  mf->GetCurrentBinaryDirectory();
+  std::string path =  this->LocalGenerator->GetCurrentBinaryDirectory();
   path += "/";
   path += this->Name;
   path += ".vcxproj";
@@ -361,14 +359,15 @@ void cmVisualStudio10TargetGenerator::Generate()
   this->WriteString("<ProjectGUID>", 2);
   (*this->BuildFileStream) <<  "{" << this->GUID << "}</ProjectGUID>\n";
 
-  if(this->MSTools && this->Target->GetType() <= cmTarget::GLOBAL_TARGET)
+  if(this->MSTools
+     && this->GeneratorTarget->GetType() <= cmState::GLOBAL_TARGET)
     {
     this->WriteApplicationTypeSettings();
     this->VerifyNecessaryFiles();
     }
 
   const char* vsProjectTypes =
-    this->Target->GetProperty("VS_GLOBAL_PROJECT_TYPES");
+    this->GeneratorTarget->GetProperty("VS_GLOBAL_PROJECT_TYPES");
   if(vsProjectTypes)
     {
     this->WriteString("<ProjectTypes>", 2);
@@ -376,9 +375,12 @@ void cmVisualStudio10TargetGenerator::Generate()
       "</ProjectTypes>\n";
     }
 
-  const char* vsProjectName = this->Target->GetProperty("VS_SCC_PROJECTNAME");
-  const char* vsLocalPath = this->Target->GetProperty("VS_SCC_LOCALPATH");
-  const char* vsProvider = this->Target->GetProperty("VS_SCC_PROVIDER");
+  const char* vsProjectName =
+      this->GeneratorTarget->GetProperty("VS_SCC_PROJECTNAME");
+  const char* vsLocalPath =
+      this->GeneratorTarget->GetProperty("VS_SCC_LOCALPATH");
+  const char* vsProvider =
+      this->GeneratorTarget->GetProperty("VS_SCC_PROVIDER");
 
   if( vsProjectName && vsLocalPath && vsProvider )
     {
@@ -392,7 +394,8 @@ void cmVisualStudio10TargetGenerator::Generate()
     (*this->BuildFileStream) << cmVS10EscapeXML(vsProvider) <<
       "</SccProvider>\n";
 
-    const char* vsAuxPath = this->Target->GetProperty("VS_SCC_AUXPATH");
+    const char* vsAuxPath =
+        this->GeneratorTarget->GetProperty("VS_SCC_AUXPATH");
     if( vsAuxPath )
       {
       this->WriteString("<SccAuxPath>", 2);
@@ -401,13 +404,13 @@ void cmVisualStudio10TargetGenerator::Generate()
       }
     }
 
-  if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
+  if(this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT"))
     {
     this->WriteString("<WinMDAssembly>true</WinMDAssembly>\n", 2);
     }
 
   const char* vsGlobalKeyword =
-    this->Target->GetProperty("VS_GLOBAL_KEYWORD");
+    this->GeneratorTarget->GetProperty("VS_GLOBAL_KEYWORD");
   if(!vsGlobalKeyword)
     {
     this->WriteString("<Keyword>Win32Proj</Keyword>\n", 2);
@@ -420,7 +423,7 @@ void cmVisualStudio10TargetGenerator::Generate()
     }
 
   const char* vsGlobalRootNamespace =
-    this->Target->GetProperty("VS_GLOBAL_ROOTNAMESPACE");
+    this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE");
   if(vsGlobalRootNamespace)
     {
     this->WriteString("<RootNamespace>", 2);
@@ -431,20 +434,46 @@ void cmVisualStudio10TargetGenerator::Generate()
   this->WriteString("<Platform>", 2);
   (*this->BuildFileStream) << cmVS10EscapeXML(this->Platform)
                            << "</Platform>\n";
-  const char* projLabel = this->Target->GetProperty("PROJECT_LABEL");
+  const char* projLabel = this->GeneratorTarget->GetProperty("PROJECT_LABEL");
   if(!projLabel)
     {
     projLabel = this->Name.c_str();
     }
   this->WriteString("<ProjectName>", 2);
   (*this->BuildFileStream) << cmVS10EscapeXML(projLabel) << "</ProjectName>\n";
-  if(const char* targetFrameworkVersion = this->Target->GetProperty(
+  if(const char* targetFrameworkVersion = this->GeneratorTarget->GetProperty(
        "VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
     {
     this->WriteString("<TargetFrameworkVersion>", 2);
     (*this->BuildFileStream) << cmVS10EscapeXML(targetFrameworkVersion)
                              << "</TargetFrameworkVersion>\n";
     }
+
+  std::vector<std::string> keys = this->GeneratorTarget->GetPropertyKeys();
+  for(std::vector<std::string>::const_iterator keyIt = keys.begin();
+      keyIt != keys.end(); ++keyIt)
+    {
+    static const char* prefix = "VS_GLOBAL_";
+    if(keyIt->find(prefix) != 0)
+      continue;
+    std::string globalKey = keyIt->substr(strlen(prefix));
+    // Skip invalid or separately-handled properties.
+    if(globalKey == "" ||
+       globalKey == "PROJECT_TYPES" ||
+       globalKey == "ROOTNAMESPACE" ||
+       globalKey == "KEYWORD")
+      {
+      continue;
+      }
+    const char* value = this->GeneratorTarget->GetProperty(keyIt->c_str());
+    if (!value)
+      continue;
+    this->WriteString("<", 2);
+    (*this->BuildFileStream) << globalKey << ">"
+                             << cmVS10EscapeXML(value)
+                             << "</" << globalKey << ">\n";
+    }
+
   this->WriteString("</PropertyGroup>\n", 1);
   this->WriteString("<Import Project="
                     "\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n",
@@ -497,7 +526,7 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
 {
   std::vector<std::string> references;
   if(const char* vsDotNetReferences =
-     this->Target->GetProperty("VS_DOTNET_REFERENCES"))
+     this->GeneratorTarget->GetProperty("VS_DOTNET_REFERENCES"))
     {
     cmSystemTools::ExpandListArgument(vsDotNetReferences, references);
     }
@@ -543,7 +572,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup()
           i != this->Configurations.end(); ++i)
         {
         this->WritePlatformConfigTag("LogicalName", i->c_str(), 3);
-        if(this->Target->GetProperty("VS_GLOBAL_ROOTNAMESPACE"))
+        if(this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE"))
           {
           (*this->BuildFileStream ) << "$(RootNamespace).";
           }
@@ -610,7 +639,7 @@ void cmVisualStudio10TargetGenerator::WriteWinRTReferences()
 {
   std::vector<std::string> references;
   if(const char* vsWinRTReferences =
-     this->Target->GetProperty("VS_WINRT_REFERENCES"))
+     this->GeneratorTarget->GetProperty("VS_WINRT_REFERENCES"))
     {
     cmSystemTools::ExpandListArgument(vsWinRTReferences, references);
     }
@@ -667,19 +696,19 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
                                  i->c_str(),
                                  1, " Label=\"Configuration\"", "\n");
     std::string configType = "<ConfigurationType>";
-    switch(this->Target->GetType())
+    switch(this->GeneratorTarget->GetType())
       {
-      case cmTarget::SHARED_LIBRARY:
-      case cmTarget::MODULE_LIBRARY:
+      case cmState::SHARED_LIBRARY:
+      case cmState::MODULE_LIBRARY:
         configType += "DynamicLibrary";
         break;
-      case cmTarget::OBJECT_LIBRARY:
-      case cmTarget::STATIC_LIBRARY:
+      case cmState::OBJECT_LIBRARY:
+      case cmState::STATIC_LIBRARY:
         configType += "StaticLibrary";
         break;
-      case cmTarget::EXECUTABLE:
+      case cmState::EXECUTABLE:
         if(this->NsightTegra &&
-           !this->Target->GetPropertyAsBool("ANDROID_GUI"))
+           !this->GeneratorTarget->GetPropertyAsBool("ANDROID_GUI"))
           {
           // Android executables are .so too.
           configType += "DynamicLibrary";
@@ -689,8 +718,8 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
           configType += "Application";
           }
         break;
-      case cmTarget::UTILITY:
-      case cmTarget::GLOBAL_TARGET:
+      case cmState::UTILITY:
+      case cmState::GLOBAL_TARGET:
         if(this->NsightTegra)
           {
           // Tegra-Android platform does not understand "Utility".
@@ -701,8 +730,8 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
           configType += "Utility";
           }
         break;
-      case cmTarget::UNKNOWN_LIBRARY:
-      case cmTarget::INTERFACE_LIBRARY:
+      case cmState::UNKNOWN_LIBRARY:
+      case cmState::INTERFACE_LIBRARY:
         break;
       }
     configType += "</ConfigurationType>\n";
@@ -728,32 +757,36 @@ void cmVisualStudio10TargetGenerator
   cmGlobalVisualStudio10Generator* gg =
     static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
   const char* mfcFlag =
-    this->Target->GetMakefile()->GetDefinition("CMAKE_MFC_FLAG");
+    this->GeneratorTarget->
+      Target->GetMakefile()->GetDefinition("CMAKE_MFC_FLAG");
   std::string mfcFlagValue = mfcFlag ? mfcFlag : "0";
 
   std::string useOfMfcValue = "false";
-  if(mfcFlagValue == "1")
-    {
-    useOfMfcValue = "Static";
-    }
-  else if(mfcFlagValue == "2")
+  if(this->GeneratorTarget->GetType() <= cmState::OBJECT_LIBRARY)
     {
-    useOfMfcValue = "Dynamic";
+    if(mfcFlagValue == "1")
+      {
+      useOfMfcValue = "Static";
+      }
+    else if(mfcFlagValue == "2")
+      {
+      useOfMfcValue = "Dynamic";
+      }
     }
   std::string mfcLine = "<UseOfMfc>";
   mfcLine += useOfMfcValue + "</UseOfMfc>\n";
   this->WriteString(mfcLine.c_str(), 2);
 
-  if((this->Target->GetType() <= cmTarget::OBJECT_LIBRARY &&
+  if((this->GeneratorTarget->GetType() <= cmState::OBJECT_LIBRARY &&
       this->ClOptions[config]->UsingUnicode()) ||
-     this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
+     this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
      this->GlobalGenerator->TargetsWindowsPhone() ||
      this->GlobalGenerator->TargetsWindowsStore() ||
-     this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
+     this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
     {
     this->WriteString("<CharacterSet>Unicode</CharacterSet>\n", 2);
     }
-  else if (this->Target->GetType() <= cmTarget::MODULE_LIBRARY &&
+  else if (this->GeneratorTarget->GetType() <= cmState::MODULE_LIBRARY &&
            this->ClOptions[config]->UsingSBCS())
     {
     this->WriteString("<CharacterSet>NotSet</CharacterSet>\n", 2);
@@ -769,8 +802,8 @@ void cmVisualStudio10TargetGenerator
     pts += "</PlatformToolset>\n";
     this->WriteString(pts.c_str(), 2);
     }
-  if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
-     this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
+  if(this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
+     this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
     {
     this->WriteString("<WindowsAppContainer>true"
                       "</WindowsAppContainer>\n", 2);
@@ -788,27 +821,29 @@ void cmVisualStudio10TargetGenerator
   ntv += toolset? toolset : "Default";
   ntv += "</NdkToolchainVersion>\n";
   this->WriteString(ntv.c_str(), 2);
-  if(const char* minApi = this->Target->GetProperty("ANDROID_API_MIN"))
+  if(const char* minApi =
+     this->GeneratorTarget->GetProperty("ANDROID_API_MIN"))
     {
     this->WriteString("<AndroidMinAPI>", 2);
     (*this->BuildFileStream ) <<
       "android-" << cmVS10EscapeXML(minApi) << "</AndroidMinAPI>\n";
     }
-  if(const char* api = this->Target->GetProperty("ANDROID_API"))
+  if(const char* api = this->GeneratorTarget->GetProperty("ANDROID_API"))
     {
     this->WriteString("<AndroidTargetAPI>", 2);
     (*this->BuildFileStream ) <<
       "android-" << cmVS10EscapeXML(api) << "</AndroidTargetAPI>\n";
     }
 
-  if(const char* cpuArch = this->Target->GetProperty("ANDROID_ARCH"))
+  if(const char* cpuArch = this->GeneratorTarget->GetProperty("ANDROID_ARCH"))
     {
     this->WriteString("<AndroidArch>", 2);
     (*this->BuildFileStream) << cmVS10EscapeXML(cpuArch) <<
       "</AndroidArch>\n";
     }
 
-  if(const char* stlType = this->Target->GetProperty("ANDROID_STL_TYPE"))
+  if(const char* stlType =
+     this->GeneratorTarget->GetProperty("ANDROID_STL_TYPE"))
     {
     this->WriteString("<AndroidStlType>", 2);
     (*this->BuildFileStream) << cmVS10EscapeXML(stlType) <<
@@ -951,7 +986,7 @@ cmVisualStudio10TargetGenerator::ConvertPath(std::string const& path,
 {
   return forceRelative
     ? cmSystemTools::RelativePath(
-      this->Makefile->GetCurrentBinaryDirectory(), path.c_str())
+      this->LocalGenerator->GetCurrentBinaryDirectory(), path.c_str())
     : path.c_str();
 }
 
@@ -990,7 +1025,7 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
   this->AddMissingSourceGroups(groupsUsed, sourceGroups);
 
   // Write out group file
-  std::string path =  this->Makefile->GetCurrentBinaryDirectory();
+  std::string path =  this->LocalGenerator->GetCurrentBinaryDirectory();
   path += "/";
   path += this->Name;
   path += ".vcxproj.filters";
@@ -1375,7 +1410,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
         }
       for(size_t i = 0; i != this->Configurations.size(); ++i)
         {
-        if(0 == strcmp(cge->Evaluate(this->Makefile,
+        if(0 == strcmp(cge->Evaluate(this->LocalGenerator,
                                      this->Configurations[i]), "1"))
           {
           this->WriteString("<DeploymentContent Condition=\""
@@ -1452,7 +1487,7 @@ void cmVisualStudio10TargetGenerator::WriteSource(
     std::string sourceRel = this->ConvertPath(sf->GetFullPath(), true);
     size_t const maxLen = 250;
     if(sf->GetCustomCommand() ||
-       ((strlen(this->Makefile->GetCurrentBinaryDirectory()) + 1 +
+       ((strlen(this->LocalGenerator->GetCurrentBinaryDirectory()) + 1 +
          sourceRel.length()) <= maxLen))
       {
       forceRelative = true;
@@ -1460,7 +1495,8 @@ void cmVisualStudio10TargetGenerator::WriteSource(
       }
     else
       {
-      this->GlobalGenerator->PathTooLong(this->Target, sf, sourceRel);
+      this->GlobalGenerator->PathTooLong(this->GeneratorTarget,
+                                         sf, sourceRel);
       }
     }
   this->ConvertToWindowsSlash(sourceFile);
@@ -1485,7 +1521,7 @@ void cmVisualStudio10TargetGenerator::WriteSources(
 
 void cmVisualStudio10TargetGenerator::WriteAllSources()
 {
-  if(this->Target->GetType() > cmTarget::UTILITY)
+  if(this->GeneratorTarget->GetType() > cmState::UTILITY)
     {
     return;
     }
@@ -1606,6 +1642,12 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
     (*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\" />\n";
     }
 
+  if (cmSourceFile const* defsrc =
+      this->GeneratorTarget->GetModuleDefinitionFile(""))
+    {
+    this->WriteSource("None", defsrc);
+    }
+
   if (this->IsMissingFiles)
     {
     this->WriteMissingFiles();
@@ -1747,8 +1789,8 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
 
 void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
 {
-  cmTarget::TargetType ttype = this->Target->GetType();
-  if(ttype > cmTarget::GLOBAL_TARGET)
+  cmState::TargetType ttype = this->GeneratorTarget->GetType();
+  if(ttype > cmState::GLOBAL_TARGET)
     {
     return;
     }
@@ -1760,7 +1802,7 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
         config = this->Configurations.begin();
       config != this->Configurations.end(); ++config)
     {
-    if(ttype >= cmTarget::UTILITY)
+    if(ttype >= cmState::UTILITY)
       {
       this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
       *this->BuildFileStream
@@ -1770,21 +1812,21 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
     else
       {
       std::string intermediateDir = this->LocalGenerator->
-        GetTargetDirectory(*this->Target);
+        GetTargetDirectory(this->GeneratorTarget);
       intermediateDir += "/";
       intermediateDir += *config;
       intermediateDir += "/";
       std::string outDir;
       std::string targetNameFull;
-      if(ttype == cmTarget::OBJECT_LIBRARY)
+      if(ttype == cmState::OBJECT_LIBRARY)
         {
         outDir = intermediateDir;
-        targetNameFull = this->Target->GetName();
+        targetNameFull = this->GeneratorTarget->GetName();
         targetNameFull += ".lib";
         }
       else
         {
-        outDir = this->Target->GetDirectory(config->c_str()) + "/";
+        outDir = this->GeneratorTarget->GetDirectory(config->c_str()) + "/";
         targetNameFull = this->GeneratorTarget->GetFullName(config->c_str());
         }
       this->ConvertToWindowsSlash(intermediateDir);
@@ -1832,8 +1874,8 @@ OutputLinkIncremental(std::string const& configName)
     }
   // static libraries and things greater than modules do not need
   // to set this option
-  if(this->Target->GetType() == cmTarget::STATIC_LIBRARY
-     || this->Target->GetType() > cmTarget::MODULE_LIBRARY)
+  if(this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY
+     || this->GeneratorTarget->GetType() > cmState::MODULE_LIBRARY)
     {
     return;
     }
@@ -1913,12 +1955,12 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
     std::string baseFlagVar = "CMAKE_";
     baseFlagVar += linkLanguage;
     baseFlagVar += "_FLAGS";
-    flags = this->
+    flags = this->GeneratorTarget->
       Target->GetMakefile()->GetRequiredDefinition(baseFlagVar.c_str());
     std::string flagVar = baseFlagVar + std::string("_") +
       cmSystemTools::UpperCase(configName);
     flags += " ";
-    flags += this->
+    flags += this->GeneratorTarget->
       Target->GetMakefile()->GetRequiredDefinition(flagVar.c_str());
     }
   // set the correct language
@@ -1930,11 +1972,12 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
     {
     clOptions.AddFlag("CompileAs", "CompileAsCpp");
     }
-  this->LocalGenerator->AddCompileOptions(flags, this->Target,
+  this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget,
                                           linkLanguage, configName.c_str());
 
   // Get preprocessor definitions for this directory.
-  std::string defineFlags = this->Target->GetMakefile()->GetDefineFlags();
+  std::string defineFlags =
+      this->GeneratorTarget->Target->GetMakefile()->GetDefineFlags();
   if(this->MSTools)
     {
     clOptions.FixExceptionHandlingDefault();
@@ -1959,7 +2002,8 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
   configDefine += configName;
   configDefine += "\"";
   clOptions.AddDefine(configDefine);
-  if(const char* exportMacro = this->Target->GetExportMacro())
+  if(const char* exportMacro =
+          this->GeneratorTarget->GetExportMacro())
     {
     clOptions.AddDefine(exportMacro);
     }
@@ -1967,12 +2011,12 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
   if (this->MSTools)
     {
     // If we have the VS_WINRT_COMPONENT set then force Compile as WinRT.
-    if (this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
+    if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT"))
       {
       clOptions.AddFlag("CompileAsWinRT", "true");
       // For WinRT components, add the _WINRT_DLL define to produce a lib
-      if (this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
-          this->Target->GetType() == cmTarget::MODULE_LIBRARY )
+      if (this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
+          this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY )
         {
         clOptions.AddDefine("_WINRT_DLL");
         }
@@ -2016,7 +2060,7 @@ void cmVisualStudio10TargetGenerator::WriteClOptions(
   if(this->NsightTegra)
     {
     if(const char* processMax =
-        this->Target->GetProperty("ANDROID_PROCESS_MAX"))
+        this->GeneratorTarget->GetProperty("ANDROID_PROCESS_MAX"))
       {
       this->WriteString("<ProcessMax>", 3);
       *this->BuildFileStream << cmVS10EscapeXML(processMax) <<
@@ -2180,14 +2224,14 @@ WriteMasmOptions(std::string const& configName,
 void
 cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
 {
-  if(this->Target->GetType() != cmTarget::STATIC_LIBRARY &&
-     this->Target->GetType() != cmTarget::OBJECT_LIBRARY)
+  if(this->GeneratorTarget->GetType() != cmState::STATIC_LIBRARY &&
+     this->GeneratorTarget->GetType() != cmState::OBJECT_LIBRARY)
     {
     return;
     }
   std::string libflags;
   this->LocalGenerator->GetStaticLibraryFlags(libflags,
-    cmSystemTools::UpperCase(config), this->Target);
+    cmSystemTools::UpperCase(config), this->GeneratorTarget);
   if(!libflags.empty())
     {
     this->WriteString("<Lib>\n", 2);
@@ -2217,9 +2261,9 @@ cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
 void cmVisualStudio10TargetGenerator::WriteManifestOptions(
   std::string const& config)
 {
-  if (this->Target->GetType() != cmTarget::EXECUTABLE &&
-      this->Target->GetType() != cmTarget::SHARED_LIBRARY &&
-      this->Target->GetType() != cmTarget::MODULE_LIBRARY)
+  if (this->GeneratorTarget->GetType() != cmState::EXECUTABLE &&
+      this->GeneratorTarget->GetType() != cmState::SHARED_LIBRARY &&
+      this->GeneratorTarget->GetType() != cmState::MODULE_LIBRARY)
     {
     return;
     }
@@ -2248,7 +2292,7 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
 {
   // Look through the sources for AndroidManifest.xml and use
   // its location as the root source directory.
-  std::string rootDir = this->Makefile->GetCurrentSourceDirectory();
+  std::string rootDir = this->LocalGenerator->GetCurrentSourceDirectory();
   {
   std::vector<cmSourceFile const*> extraSources;
   this->GeneratorTarget->GetExtraSources(extraSources, "");
@@ -2274,18 +2318,18 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
     cmVS10EscapeXML(antBuildPath) << "</AntBuildPath>\n";
   }
 
-  if (this->Target->GetPropertyAsBool("ANDROID_SKIP_ANT_STEP"))
+  if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_SKIP_ANT_STEP"))
     {
     this->WriteString("<SkipAntStep>true</SkipAntStep>\n", 3);
     }
 
-  if (this->Target->GetPropertyAsBool("ANDROID_PROGUARD"))
+  if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_PROGUARD"))
     {
     this->WriteString("<EnableProGuard>true</EnableProGuard>\n", 3);
     }
 
   if (const char* proGuardConfigLocation =
-      this->Target->GetProperty("ANDROID_PROGUARD_CONFIG_PATH"))
+      this->GeneratorTarget->GetProperty("ANDROID_PROGUARD_CONFIG_PATH"))
     {
     this->WriteString("<ProGuardConfigLocation>", 3);
     (*this->BuildFileStream) << cmVS10EscapeXML(proGuardConfigLocation) <<
@@ -2293,7 +2337,7 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
     }
 
   if (const char* securePropertiesLocation =
-      this->Target->GetProperty("ANDROID_SECURE_PROPS_PATH"))
+      this->GeneratorTarget->GetProperty("ANDROID_SECURE_PROPS_PATH"))
     {
     this->WriteString("<SecurePropertiesLocation>", 3);
     (*this->BuildFileStream) << cmVS10EscapeXML(securePropertiesLocation) <<
@@ -2301,31 +2345,33 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
     }
 
   if (const char* nativeLibDirectoriesExpression =
-      this->Target->GetProperty("ANDROID_NATIVE_LIB_DIRECTORIES"))
+      this->GeneratorTarget->GetProperty("ANDROID_NATIVE_LIB_DIRECTORIES"))
     {
     cmGeneratorExpression ge;
     cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
         ge.Parse(nativeLibDirectoriesExpression);
-    std::string nativeLibDirs = cge->Evaluate(this->Makefile, configName);
+    std::string nativeLibDirs = cge->Evaluate(this->LocalGenerator,
+                                              configName);
     this->WriteString("<NativeLibDirectories>", 3);
     (*this->BuildFileStream) << cmVS10EscapeXML(nativeLibDirs) <<
       "</NativeLibDirectories>\n";
     }
 
   if (const char* nativeLibDependenciesExpression =
-      this->Target->GetProperty("ANDROID_NATIVE_LIB_DEPENDENCIES"))
+      this->GeneratorTarget->GetProperty("ANDROID_NATIVE_LIB_DEPENDENCIES"))
     {
     cmGeneratorExpression ge;
     cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
         ge.Parse(nativeLibDependenciesExpression);
-    std::string nativeLibDeps = cge->Evaluate(this->Makefile, configName);
+    std::string nativeLibDeps = cge->Evaluate(this->LocalGenerator,
+                                              configName);
     this->WriteString("<NativeLibDependencies>", 3);
     (*this->BuildFileStream) << cmVS10EscapeXML(nativeLibDeps) <<
       "</NativeLibDependencies>\n";
     }
 
   if (const char* javaSourceDir =
-      this->Target->GetProperty("ANDROID_JAVA_SOURCE_DIR"))
+      this->GeneratorTarget->GetProperty("ANDROID_JAVA_SOURCE_DIR"))
     {
     this->WriteString("<JavaSourceDir>", 3);
     (*this->BuildFileStream) << cmVS10EscapeXML(javaSourceDir) <<
@@ -2333,19 +2379,20 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
     }
 
   if (const char* jarDirectoriesExpression =
-      this->Target->GetProperty("ANDROID_JAR_DIRECTORIES"))
+      this->GeneratorTarget->GetProperty("ANDROID_JAR_DIRECTORIES"))
     {
     cmGeneratorExpression ge;
     cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
       ge.Parse(jarDirectoriesExpression);
-    std::string jarDirectories = cge->Evaluate(this->Makefile, configName);
+    std::string jarDirectories = cge->Evaluate(this->LocalGenerator,
+                                               configName);
     this->WriteString("<JarDirectories>", 3);
     (*this->BuildFileStream) << cmVS10EscapeXML(jarDirectories) <<
       "</JarDirectories>\n";
     }
 
   if (const char* jarDeps =
-      this->Target->GetProperty("ANDROID_JAR_DEPENDENCIES"))
+      this->GeneratorTarget->GetProperty("ANDROID_JAR_DEPENDENCIES"))
     {
     this->WriteString("<JarDependencies>", 3);
     (*this->BuildFileStream) << cmVS10EscapeXML(jarDeps) <<
@@ -2353,7 +2400,7 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
     }
 
   if (const char* assetsDirectories =
-      this->Target->GetProperty("ANDROID_ASSETS_DIRECTORIES"))
+      this->GeneratorTarget->GetProperty("ANDROID_ASSETS_DIRECTORIES"))
     {
     this->WriteString("<AssetsDirectories>", 3);
     (*this->BuildFileStream) << cmVS10EscapeXML(assetsDirectories) <<
@@ -2369,7 +2416,7 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
   }
 
   if (const char* antAdditionalOptions =
-      this->Target->GetProperty("ANDROID_ANT_ADDITIONAL_OPTIONS"))
+      this->GeneratorTarget->GetProperty("ANDROID_ANT_ADDITIONAL_OPTIONS"))
     {
     this->WriteString("<AdditionalOptions>", 3);
     (*this->BuildFileStream) << cmVS10EscapeXML(antAdditionalOptions) <<
@@ -2382,9 +2429,9 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
 //----------------------------------------------------------------------------
 bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
 {
-  if(this->Target->GetType() == cmTarget::EXECUTABLE ||
-     this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
-     this->Target->GetType() == cmTarget::MODULE_LIBRARY)
+  if(this->GeneratorTarget->GetType() == cmState::EXECUTABLE ||
+     this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
+     this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY)
     {
     for(std::vector<std::string>::const_iterator
           i = this->Configurations.begin();
@@ -2421,11 +2468,11 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
   std::string CONFIG = cmSystemTools::UpperCase(config);
 
   const char* linkType = "SHARED";
-  if(this->Target->GetType() == cmTarget::MODULE_LIBRARY)
+  if(this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY)
     {
     linkType = "MODULE";
     }
-  if(this->Target->GetType() == cmTarget::EXECUTABLE)
+  if(this->GeneratorTarget->GetType() == cmState::EXECUTABLE)
     {
     linkType = "EXE";
     }
@@ -2434,13 +2481,14 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
   linkFlagVarBase += linkType;
   linkFlagVarBase += "_LINKER_FLAGS";
   flags += " ";
-  flags += this->
+  flags += this->GeneratorTarget->
     Target->GetMakefile()->GetRequiredDefinition(linkFlagVarBase.c_str());
   std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
   flags += " ";
-  flags += this->
+  flags += this->GeneratorTarget->
     Target->GetMakefile()->GetRequiredDefinition(linkFlagVar.c_str());
-  const char* targetLinkFlags = this->Target->GetProperty("LINK_FLAGS");
+  const char* targetLinkFlags =
+      this->GeneratorTarget->GetProperty("LINK_FLAGS");
   if(targetLinkFlags)
     {
     flags += " ";
@@ -2448,7 +2496,8 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
     }
   std::string flagsProp = "LINK_FLAGS_";
   flagsProp += CONFIG;
-  if(const char* flagsConfig = this->Target->GetProperty(flagsProp.c_str()))
+  if(const char* flagsConfig =
+     this->GeneratorTarget->GetProperty(flagsProp.c_str()))
     {
     flags += " ";
     flags += flagsConfig;
@@ -2508,7 +2557,7 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
   std::string targetNameFull;
   std::string targetNameImport;
   std::string targetNamePDB;
-  if(this->Target->GetType() == cmTarget::EXECUTABLE)
+  if(this->GeneratorTarget->GetType() == cmState::EXECUTABLE)
     {
     this->GeneratorTarget->GetExecutableNames(targetName, targetNameFull,
                                      targetNameImport, targetNamePDB,
@@ -2526,12 +2575,12 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
     {
     linkOptions.AddFlag("Version", "");
 
-    if ( this->Target->GetPropertyAsBool("WIN32_EXECUTABLE") )
+    if ( this->GeneratorTarget->GetPropertyAsBool("WIN32_EXECUTABLE") )
       {
       if (this->GlobalGenerator->TargetsWindowsCE())
         {
         linkOptions.AddFlag("SubSystem", "WindowsCE");
-        if (this->Target->GetType() == cmTarget::EXECUTABLE)
+        if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE)
           {
           if (this->ClOptions[config]->UsingUnicode())
             {
@@ -2553,7 +2602,7 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
       if (this->GlobalGenerator->TargetsWindowsCE())
         {
         linkOptions.AddFlag("SubSystem", "WindowsCE");
-        if (this->Target->GetType() == cmTarget::EXECUTABLE)
+        if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE)
           {
           if (this->ClOptions[config]->UsingUnicode())
             {
@@ -2577,18 +2626,21 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
       linkOptions.AddFlag("StackReserveSize", stackVal);
       }
 
-    if(linkOptions.IsDebug() || flags.find("/debug") != flags.npos)
+    if (this->LocalGenerator->GetVersion() >=
+        cmGlobalVisualStudioGenerator::VS14)
       {
-      linkOptions.AddFlag("GenerateDebugInformation", "true");
+      linkOptions.AddFlag("GenerateDebugInformation", "No");
       }
     else
       {
       linkOptions.AddFlag("GenerateDebugInformation", "false");
       }
-    std::string pdb = this->Target->GetPDBDirectory(config.c_str());
+
+    std::string pdb = this->GeneratorTarget->GetPDBDirectory(config.c_str());
     pdb += "/";
     pdb += targetNamePDB;
-    std::string imLib = this->Target->GetDirectory(config.c_str(), true);
+    std::string imLib =
+        this->GeneratorTarget->GetDirectory(config.c_str(), true);
     imLib += "/";
     imLib += targetNameImport;
 
@@ -2597,8 +2649,8 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
 
     // A Windows Runtime component uses internal .NET metadata,
     // so does not have an import library.
-    if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") &&
-       this->Target->GetType() != cmTarget::EXECUTABLE)
+    if(this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") &&
+       this->GeneratorTarget->GetType() != cmState::EXECUTABLE)
       {
       linkOptions.AddFlag("GenerateWindowsMetadata", "true");
       }
@@ -2627,24 +2679,53 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
 
   if(this->MSTools)
     {
-    std::string def = this->GeneratorTarget->GetModuleDefinitionFile("");
-    if(!def.empty())
+    if (cmSourceFile const* defsrc =
+        this->GeneratorTarget->GetModuleDefinitionFile(""))
       {
-      linkOptions.AddFlag("ModuleDefinitionFile", def.c_str());
+      linkOptions.AddFlag("ModuleDefinitionFile",
+                          defsrc->GetFullPath().c_str());
       }
     linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
                            "%(IgnoreSpecificDefaultLibraries)");
     }
 
-  if (this->Target->GetType() == cmTarget::SHARED_LIBRARY &&
+  if (this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY &&
       this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS"))
     {
-    if (this->Target->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
+    if (this->GeneratorTarget->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
       {
       linkOptions.AddFlag("ModuleDefinitionFile", "$(IntDir)exportall.def");
       }
     }
 
+  // Hack to fix flag version selection in a common use case.
+  // FIXME: Select flag table based on toolset instead of VS version.
+  if (this->LocalGenerator->GetVersion() >=
+      cmGlobalVisualStudioGenerator::VS14)
+    {
+    cmGlobalVisualStudio10Generator* gg =
+      static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
+    const char* toolset = gg->GetPlatformToolset();
+    if (toolset &&
+        (cmHasLiteralPrefix(toolset, "v100") ||
+         cmHasLiteralPrefix(toolset, "v110") ||
+         cmHasLiteralPrefix(toolset, "v120")))
+      {
+      if (const char* debug = linkOptions.GetFlag("GenerateDebugInformation"))
+        {
+        // Convert value from enumeration back to boolean for older toolsets.
+        if (strcmp(debug, "No") == 0)
+          {
+          linkOptions.AddFlag("GenerateDebugInformation", "false");
+          }
+        else if (strcmp(debug, "Debug") == 0)
+          {
+          linkOptions.AddFlag("GenerateDebugInformation", "true");
+          }
+        }
+      }
+    }
+
   this->LinkOptions[config] = pOptions.release();
   return true;
 }
@@ -2653,8 +2734,8 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
 void
 cmVisualStudio10TargetGenerator::WriteLinkOptions(std::string const& config)
 {
-  if(this->Target->GetType() == cmTarget::STATIC_LIBRARY
-     || this->Target->GetType() > cmTarget::MODULE_LIBRARY)
+  if(this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY
+     || this->GeneratorTarget->GetType() > cmState::MODULE_LIBRARY)
     {
     return;
     }
@@ -2665,7 +2746,8 @@ cmVisualStudio10TargetGenerator::WriteLinkOptions(std::string const& config)
   linkOptions.OutputFlagMap(*this->BuildFileStream, "      ");
 
   this->WriteString("</Link>\n", 2);
-  if(!this->GlobalGenerator->NeedLinkLibraryDependencies(*this->Target))
+  if(!this->GlobalGenerator->NeedLinkLibraryDependencies(
+              this->GeneratorTarget))
     {
     this->WriteString("<ProjectReference>\n", 2);
     this->WriteString(
@@ -2692,7 +2774,7 @@ void cmVisualStudio10TargetGenerator::AddLibraries(
       libVec.push_back(path);
       }
     else if (!l->Target
-        || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
+        || l->Target->GetType() != cmState::INTERFACE_LIBRARY)
       {
       libVec.push_back(l->Value);
       }
@@ -2764,7 +2846,7 @@ void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
     this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1);
     *this->BuildFileStream << "\n";
     //    output cl compile flags <ClCompile></ClCompile>
-    if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
+    if(this->GeneratorTarget->GetType() <= cmState::OBJECT_LIBRARY)
       {
       this->WriteClOptions(*i, includes);
       //    output rc compile flags <ResourceCompile></ResourceCompile>
@@ -2782,8 +2864,8 @@ void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
     //    output manifest flags  <Manifest></Manifest>
     this->WriteManifestOptions(*i);
     if(this->NsightTegra &&
-       this->Target->GetType() == cmTarget::EXECUTABLE &&
-       this->Target->GetPropertyAsBool("ANDROID_GUI"))
+       this->GeneratorTarget->GetType() == cmState::EXECUTABLE &&
+       this->GeneratorTarget->GetPropertyAsBool("ANDROID_GUI"))
       {
       this->WriteAntBuildOptions(*i);
       }
@@ -2795,14 +2877,14 @@ void
 cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
 {
   bool addedPrelink = false;
-  if (this->Target->GetType() == cmTarget::SHARED_LIBRARY &&
+  if (this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY &&
       this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS"))
     {
-    if (this->Target->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
+    if (this->GeneratorTarget->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
       {
       addedPrelink = true;
       std::vector<cmCustomCommand> commands =
-        this->Target->GetPreLinkCommands();
+        this->GeneratorTarget->GetPreLinkCommands();
       this->GlobalGenerator->AddSymbolExportCommand(
         this->GeneratorTarget, commands, configName);
       this->WriteEvent("PreLinkEvent", commands, configName);
@@ -2811,12 +2893,12 @@ cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
   if (!addedPrelink)
     {
     this->WriteEvent("PreLinkEvent",
-                     this->Target->GetPreLinkCommands(), configName);
+        this->GeneratorTarget->GetPreLinkCommands(), configName);
     }
   this->WriteEvent("PreBuildEvent",
-                   this->Target->GetPreBuildCommands(), configName);
+        this->GeneratorTarget->GetPreBuildCommands(), configName);
   this->WriteEvent("PostBuildEvent",
-                   this->Target->GetPostBuildCommands(), configName);
+        this->GeneratorTarget->GetPostBuildCommands(), configName);
 }
 
 void cmVisualStudio10TargetGenerator::WriteEvent(
@@ -2866,20 +2948,20 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences()
   for( OrderedTargetDependSet::const_iterator i = depends.begin();
        i != depends.end(); ++i)
     {
-    cmTarget const* dt = (*i)->Target;
-    if(dt->GetType() == cmTarget::INTERFACE_LIBRARY)
+    cmGeneratorTarget const* dt = *i;
+    if(dt->GetType() == cmState::INTERFACE_LIBRARY)
       {
       continue;
       }
     // skip fortran targets as they can not be processed by MSBuild
     // the only reference will be in the .sln file
     if(static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
-       ->TargetIsFortranOnly(*dt))
+       ->TargetIsFortranOnly(dt))
       {
       continue;
       }
     this->WriteString("<ProjectReference Include=\"", 2);
-    cmMakefile* mf = dt->GetMakefile();
+    cmLocalGenerator* lg = dt->GetLocalGenerator();
     std::string name = dt->GetName();
     std::string path;
     const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
@@ -2889,7 +2971,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences()
       }
     else
       {
-      path =  mf->GetCurrentBinaryDirectory();
+      path =  lg->GetCurrentBinaryDirectory();
       path += "/";
       path += dt->GetName();
       path += ".vcxproj";
@@ -2911,14 +2993,14 @@ void cmVisualStudio10TargetGenerator::WritePlatformExtensions()
       cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0"))
     {
     const char* desktopExtensionsVersion =
-      this->Target->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
+      this->GeneratorTarget->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
     if (desktopExtensionsVersion)
       {
       this->WriteSinglePlatformExtension("WindowsDesktop",
                                          desktopExtensionsVersion);
       }
     const char* mobileExtensionsVersion =
-      this->Target->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
+      this->GeneratorTarget->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
     if (mobileExtensionsVersion)
       {
       this->WriteSinglePlatformExtension("WindowsMobile",
@@ -2958,11 +3040,11 @@ void cmVisualStudio10TargetGenerator::WriteSDKReferences()
       cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0"))
     {
     const char* desktopExtensionsVersion =
-      this->Target->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
+      this->GeneratorTarget->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
     const char* mobileExtensionsVersion =
-      this->Target->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
+      this->GeneratorTarget->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
     const char* iotExtensionsVersion =
-      this->Target->GetProperty("VS_IOT_EXTENSIONS_VERSION");
+      this->GeneratorTarget->GetProperty("VS_IOT_EXTENSIONS_VERSION");
 
     if(desktopExtensionsVersion || mobileExtensionsVersion ||
        iotExtensionsVersion)
@@ -3003,7 +3085,7 @@ void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
 {
   if((this->GlobalGenerator->TargetsWindowsStore() ||
       this->GlobalGenerator->TargetsWindowsPhone())
-      && (cmTarget::EXECUTABLE == this->Target->GetType()))
+      && (cmState::EXECUTABLE == this->GeneratorTarget->GetType()))
     {
     std::string pfxFile;
     std::vector<cmSourceFile const*> certificates;
@@ -3022,7 +3104,7 @@ void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
       {
       // Move the manifest to a project directory to avoid clashes
       std::string artifactDir =
-        this->LocalGenerator->GetTargetDirectory(*this->Target);
+        this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
       this->ConvertToWindowsSlash(artifactDir);
       this->WriteString("<PropertyGroup>\n", 1);
       this->WriteString("<AppxPackageArtifactsDir>", 2);
@@ -3132,7 +3214,7 @@ void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
       this->WriteString("<MinimumVisualStudioVersion>14.0"
         "</MinimumVisualStudioVersion>\n", 2);
 
-      if(this->Target->GetType() < cmTarget::UTILITY)
+      if(this->GeneratorTarget->GetType() < cmState::UTILITY)
         {
         isAppContainer = true;
         }
@@ -3146,7 +3228,7 @@ void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
       this->WriteString("<MinimumVisualStudioVersion>12.0"
                         "</MinimumVisualStudioVersion>\n", 2);
 
-      if (this->Target->GetType() < cmTarget::UTILITY)
+      if (this->GeneratorTarget->GetType() < cmState::UTILITY)
         {
         isAppContainer = true;
         }
@@ -3160,12 +3242,13 @@ void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
       this->WriteString("<MinimumVisualStudioVersion>11.0"
                         "</MinimumVisualStudioVersion>\n", 2);
 
-      if (isWindowsStore && this->Target->GetType() < cmTarget::UTILITY)
+      if (isWindowsStore
+          && this->GeneratorTarget->GetType() < cmState::UTILITY)
         {
         isAppContainer = true;
         }
       else if (isWindowsPhone &&
-               this->Target->GetType() == cmTarget::EXECUTABLE)
+               this->GeneratorTarget->GetType() == cmState::EXECUTABLE)
         {
         this->WriteString("<XapOutputs>true</XapOutputs>\n", 2);
         this->WriteString("<XapFilename>", 2);
@@ -3193,7 +3276,8 @@ void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
       "</WindowsTargetPlatformVersion>\n";
     }
   const char* targetPlatformMinVersion =
-      this->Target->GetProperty("VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION");
+      this->GeneratorTarget
+      ->GetProperty("VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION");
   if(targetPlatformMinVersion)
     {
     this->WriteString("<WindowsTargetPlatformMinVersion>", 2);
@@ -3212,7 +3296,7 @@ void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
     }
 
   // Added IoT Startup Task support
-  if(this->Target->GetPropertyAsBool("VS_IOT_STARTUP_TASK"))
+  if(this->GeneratorTarget->GetPropertyAsBool("VS_IOT_STARTUP_TASK"))
     {
     this->WriteString("<ContainsStartupTask>true</ContainsStartupTask>\n", 2);
     }
@@ -3222,7 +3306,7 @@ void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles()
 {
   // For Windows and Windows Phone executables, we will assume that if a
   // manifest is not present that we need to add all the necessary files
-  if (this->Target->GetType() == cmTarget::EXECUTABLE)
+  if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE)
     {
     std::vector<cmSourceFile const*> manifestSources;
     this->GeneratorTarget->GetAppManifest(manifestSources, "");
@@ -3317,13 +3401,15 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80()
   // For WP80, the manifest needs to be in the same folder as the project
   // this can cause an overwrite problem if projects aren't organized in
   // folders
-  std::string manifestFile = this->Makefile->GetCurrentBinaryDirectory() +
+  std::string manifestFile =
+      this->LocalGenerator->GetCurrentBinaryDirectory() +
                              std::string("/WMAppManifest.xml");
   std::string artifactDir =
-    this->LocalGenerator->GetTargetDirectory(*this->Target);
+    this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
   this->ConvertToWindowsSlash(artifactDir);
   std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
-  std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
+  std::string targetNameXML =
+      cmVS10EscapeXML(this->GeneratorTarget->GetName());
 
   cmGeneratedFileStream fout(manifestFile.c_str());
   fout.SetCopyIfDifferent(true);
@@ -3403,10 +3489,11 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81()
   std::string manifestFile =
     this->DefaultArtifactDir + "/package.appxManifest";
   std::string artifactDir =
-    this->LocalGenerator->GetTargetDirectory(*this->Target);
+    this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
   this->ConvertToWindowsSlash(artifactDir);
   std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
-  std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
+  std::string targetNameXML =
+      cmVS10EscapeXML(this->GeneratorTarget->GetName());
 
   cmGeneratedFileStream fout(manifestFile.c_str());
   fout.SetCopyIfDifferent(true);
@@ -3463,10 +3550,11 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80()
   std::string manifestFile =
     this->DefaultArtifactDir + "/package.appxManifest";
   std::string artifactDir =
-    this->LocalGenerator->GetTargetDirectory(*this->Target);
+    this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
   this->ConvertToWindowsSlash(artifactDir);
   std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
-  std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
+  std::string targetNameXML =
+      cmVS10EscapeXML(this->GeneratorTarget->GetName());
 
   cmGeneratedFileStream fout(manifestFile.c_str());
   fout.SetCopyIfDifferent(true);
@@ -3515,10 +3603,11 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81()
   std::string manifestFile =
     this->DefaultArtifactDir + "/package.appxManifest";
   std::string artifactDir =
-    this->LocalGenerator->GetTargetDirectory(*this->Target);
+    this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
   this->ConvertToWindowsSlash(artifactDir);
   std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
-  std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
+  std::string targetNameXML =
+      cmVS10EscapeXML(this->GeneratorTarget->GetName());
 
   cmGeneratedFileStream fout(manifestFile.c_str());
   fout.SetCopyIfDifferent(true);
@@ -3572,10 +3661,11 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWS10_0()
   std::string manifestFile =
     this->DefaultArtifactDir + "/package.appxManifest";
   std::string artifactDir =
-    this->LocalGenerator->GetTargetDirectory(*this->Target);
+    this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
   this->ConvertToWindowsSlash(artifactDir);
   std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
-  std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
+  std::string targetNameXML =
+      cmVS10EscapeXML(this->GeneratorTarget->GetName());
 
   cmGeneratedFileStream fout(manifestFile.c_str());
   fout.SetCopyIfDifferent(true);
diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h
index 15ed9f2..044e0dd 100644
--- a/Source/cmVisualStudio10TargetGenerator.h
+++ b/Source/cmVisualStudio10TargetGenerator.h
@@ -13,7 +13,6 @@
 #define cmVisualStudioTargetGenerator_h
 #include "cmStandardIncludes.h"
 
-class cmTarget;
 class cmMakefile;
 class cmGeneratorTarget;
 class cmGeneratedFileStream;
@@ -29,7 +28,7 @@ struct cmIDEFlagTable;
 class cmVisualStudio10TargetGenerator
 {
 public:
-  cmVisualStudio10TargetGenerator(cmTarget* target,
+  cmVisualStudio10TargetGenerator(cmGeneratorTarget* target,
                                   cmGlobalVisualStudio10Generator* gg);
   ~cmVisualStudio10TargetGenerator();
   void Generate();
@@ -148,7 +147,6 @@ private:
   OptionsMap LinkOptions;
   std::string PathToVcxproj;
   std::vector<std::string> Configurations;
-  cmTarget* Target;
   cmGeneratorTarget* GeneratorTarget;
   cmMakefile* Makefile;
   std::string Platform;
diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx
index c59c360..5bc34c1 100644
--- a/Source/cmXCodeObject.cxx
+++ b/Source/cmXCodeObject.cxx
@@ -255,9 +255,9 @@ void cmXCodeObject::PrintString(std::ostream& os,std::string String)
   for(std::string::const_iterator i = String.begin();
       i != String.end(); ++i)
     {
-    if(*i == '"')
+    if(*i == '"' || *i == '\\')
       {
-      // Escape double-quotes.
+      // Escape double-quotes and backslashes.
       os << '\\';
       }
     os << *i;
diff --git a/Source/cmXCodeObject.h b/Source/cmXCodeObject.h
index ed2940a..bd0f43f 100644
--- a/Source/cmXCodeObject.h
+++ b/Source/cmXCodeObject.h
@@ -13,7 +13,7 @@
 #define cmXCodeObject_h
 
 #include "cmStandardIncludes.h"
-class cmTarget;
+class cmGeneratorTarget;
 
 class cmXCodeObject
 {
@@ -75,7 +75,7 @@ public:
   }
   static void Indent(int level, std::ostream& out);
   void Print(std::ostream& out);
-  virtual void PrintComment(std::ostream&) {};
+  virtual void PrintComment(std::ostream&) {}
 
   static void PrintList(std::vector<cmXCodeObject*> const&,
                         std::ostream& out);
@@ -87,11 +87,11 @@ public:
     {
       this->Id = id;
     }
-  cmTarget* GetTarget()
+  cmGeneratorTarget* GetTarget()
     {
       return this->Target;
     }
-  void SetTarget(cmTarget* t)
+  void SetTarget(cmGeneratorTarget* t)
     {
       this->Target = t;
     }
@@ -105,7 +105,7 @@ public:
         }
       return 0;
     }
-  // serach the attribute list for an object of the specified type
+  // search the attribute list for an object of the specified type
   cmXCodeObject* GetObject(cmXCodeObject::PBXType t)
     {
       for(std::vector<cmXCodeObject*>::iterator i = this->List.begin();
@@ -146,7 +146,7 @@ public:
 protected:
   void PrintString(std::ostream& os) const;
 
-  cmTarget* Target;
+  cmGeneratorTarget* Target;
   Type TypeValue;
   std::string Id;
   PBXType IsA;
diff --git a/Source/cm_sha2.c b/Source/cm_sha2.c
index b90e060..649c39a 100644
--- a/Source/cm_sha2.c
+++ b/Source/cm_sha2.c
@@ -87,22 +87,21 @@
  * made).
  */
 #if !defined(BYTE_ORDER) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN)
-/* CMake modification: use byte order from cmIML.  */
-# include "cmIML/ABI.h"
+/* CMake modification: use byte order from KWIML.  */
 # undef BYTE_ORDER
 # undef BIG_ENDIAN
 # undef LITTLE_ENDIAN
-# define BYTE_ORDER    cmIML_ABI_ENDIAN_ID
-# define BIG_ENDIAN    cmIML_ABI_ENDIAN_ID_BIG
-# define LITTLE_ENDIAN cmIML_ABI_ENDIAN_ID_LITTLE
+# define BYTE_ORDER    KWIML_ABI_ENDIAN_ID
+# define BIG_ENDIAN    KWIML_ABI_ENDIAN_ID_BIG
+# define LITTLE_ENDIAN KWIML_ABI_ENDIAN_ID_LITTLE
 #endif
 
 /* CMake modification: use types computed in header.  */
 typedef cm_sha2_uint8_t  sha_byte;	/* Exactly 1 byte */
 typedef cm_sha2_uint32_t sha_word32;	/* Exactly 4 bytes */
 typedef cm_sha2_uint64_t sha_word64;	/* Exactly 8 bytes */
-#define SHA_UINT32_C(x) cmIML_INT_UINT32_C(x)
-#define SHA_UINT64_C(x) cmIML_INT_UINT64_C(x)
+#define SHA_UINT32_C(x) KWIML_INT_UINT32_C(x)
+#define SHA_UINT64_C(x) KWIML_INT_UINT64_C(x)
 #if defined(__clang__)
 # pragma clang diagnostic ignored "-Wcast-align"
 #endif
diff --git a/Source/cm_sha2.h b/Source/cm_sha2.h
index 71395f0..f151031 100644
--- a/Source/cm_sha2.h
+++ b/Source/cm_sha2.h
@@ -38,11 +38,11 @@
 
 #include "cm_sha2_mangle.h"
 
-/* CMake modification: use integer types from cmIML.  */
-#include "cmIML/INT.h"
-typedef cmIML_INT_uint8_t cm_sha2_uint8_t;
-typedef cmIML_INT_uint32_t cm_sha2_uint32_t;
-typedef cmIML_INT_uint64_t cm_sha2_uint64_t;
+/* CMake modification: use integer types from KWIML.  */
+#include <cm_kwiml.h>
+typedef KWIML_INT_uint8_t cm_sha2_uint8_t;
+typedef KWIML_INT_uint32_t cm_sha2_uint32_t;
+typedef KWIML_INT_uint64_t cm_sha2_uint64_t;
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 386f6a5..8f6b952 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -10,7 +10,6 @@
   See the License for more information.
 ============================================================================*/
 #include "cmake.h"
-#include "cmCacheManager.h"
 #include "cmMakefile.h"
 #include "cmLocalGenerator.h"
 #include "cmExternalMakefileProjectGenerator.h"
@@ -128,14 +127,12 @@ cmake::cmake()
   this->WarnUnused = false;
   this->WarnUnusedCli = true;
   this->CheckSystemVars = false;
-  this->SuppressDevWarnings = false;
-  this->DoSuppressDevWarnings = false;
   this->DebugOutput = false;
   this->DebugTryCompile = false;
   this->ClearBuildSystem = false;
   this->FileComparison = new cmFileTimeComparison;
 
-  this->State = new cmState(this);
+  this->State = new cmState;
   this->CurrentSnapshot = this->State->CreateBaseSnapshot();
 
 #ifdef __APPLE__
@@ -151,7 +148,6 @@ cmake::cmake()
 #endif
 
   this->Verbose = false;
-  this->CacheManager = new cmCacheManager(this);
   this->GlobalGenerator = 0;
   this->ProgressCallback = 0;
   this->ProgressCallbackClientData = 0;
@@ -167,11 +163,34 @@ cmake::cmake()
 
   // Make sure we can capture the build tool output.
   cmSystemTools::EnableVSConsoleOutput();
+
+  // Set up a list of source and header extensions
+  // these are used to find files when the extension
+  // is not given
+  // The "c" extension MUST precede the "C" extension.
+  this->SourceFileExtensions.push_back( "c" );
+  this->SourceFileExtensions.push_back( "C" );
+
+  this->SourceFileExtensions.push_back( "c++" );
+  this->SourceFileExtensions.push_back( "cc" );
+  this->SourceFileExtensions.push_back( "cpp" );
+  this->SourceFileExtensions.push_back( "cxx" );
+  this->SourceFileExtensions.push_back( "m" );
+  this->SourceFileExtensions.push_back( "M" );
+  this->SourceFileExtensions.push_back( "mm" );
+
+  this->HeaderFileExtensions.push_back( "h" );
+  this->HeaderFileExtensions.push_back( "hh" );
+  this->HeaderFileExtensions.push_back( "h++" );
+  this->HeaderFileExtensions.push_back( "hm" );
+  this->HeaderFileExtensions.push_back( "hpp" );
+  this->HeaderFileExtensions.push_back( "hxx" );
+  this->HeaderFileExtensions.push_back( "in" );
+  this->HeaderFileExtensions.push_back( "txx" );
 }
 
 cmake::~cmake()
 {
-  delete this->CacheManager;
   delete this->State;
   if (this->GlobalGenerator)
     {
@@ -189,6 +208,7 @@ void cmake::CleanupCommandsAndMacros()
 {
   this->CurrentSnapshot = this->State->Reset();
   this->State->RemoveUserDefinedCommands();
+  this->CurrentSnapshot.SetDefaultDefinitions();
 }
 
 // Parse the args
@@ -216,7 +236,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
         }
       std::string var, value;
       cmState::CacheEntryType type = cmState::UNINITIALIZED;
-      if(cmCacheManager::ParseEntry(entry, var, value, type))
+      if(cmState::ParseCacheEntry(entry, var, value, type))
         {
         // The value is transformed if it is a filepath for example, so
         // we can't compare whether the value is already in the cache until
@@ -232,7 +252,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
             }
           }
 
-        this->State->AddCacheEntry(var, value.c_str(),
+        this->AddCacheEntry(var, value.c_str(),
           "No help, variable specified on the command line.", type);
 
         if(this->WarnUnusedCli)
@@ -252,15 +272,69 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
         return false;
         }
       }
-    else if(arg.find("-Wno-dev",0) == 0)
-      {
-      this->SuppressDevWarnings = true;
-      this->DoSuppressDevWarnings = true;
-      }
-    else if(arg.find("-Wdev",0) == 0)
+    else if(cmHasLiteralPrefix(arg, "-W"))
       {
-      this->SuppressDevWarnings = false;
-      this->DoSuppressDevWarnings = true;
+      std::string entry = arg.substr(2);
+      if (entry.empty())
+        {
+        ++i;
+        if (i < args.size())
+          {
+          entry = args[i];
+          }
+        else
+          {
+          cmSystemTools::Error("-W must be followed with [no-]<name>.");
+          return false;
+          }
+        }
+
+      std::string name;
+      bool foundNo = false;
+      bool foundError = false;
+      unsigned int nameStartPosition = 0;
+
+      if (entry.find("no-", nameStartPosition) == 0)
+        {
+        foundNo = true;
+        nameStartPosition += 3;
+        }
+
+      if (entry.find("error=", nameStartPosition) == 0)
+        {
+        foundError = true;
+        nameStartPosition += 6;
+        }
+
+      name = entry.substr(nameStartPosition);
+      if (name.empty())
+        {
+        cmSystemTools::Error("No warning name provided.");
+        return false;
+        }
+
+      if (!foundNo && !foundError)
+        {
+        // -W<name>
+        this->DiagLevels[name] = std::max(this->DiagLevels[name],
+                                          DIAG_WARN);
+        }
+      else if (foundNo && !foundError)
+        {
+         // -Wno<name>
+         this->DiagLevels[name] = DIAG_IGNORE;
+        }
+      else if (!foundNo && foundError)
+        {
+        // -Werror=<name>
+        this->DiagLevels[name] = DIAG_ERROR;
+        }
+      else
+        {
+        // -Wno-error=<name>
+        this->DiagLevels[name] = std::min(this->DiagLevels[name],
+                                          DIAG_WARN);
+        }
       }
     else if(arg.find("-U",0) == 0)
       {
@@ -377,21 +451,21 @@ void cmake::ReadListFile(const std::vector<std::string>& args,
     this->SetHomeDirectory(cmSystemTools::GetCurrentWorkingDirectory());
     this->SetHomeOutputDirectory(cmSystemTools::GetCurrentWorkingDirectory());
     cmState::Snapshot snapshot = this->GetCurrentSnapshot();
-    cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(gg, snapshot));
-    cmsys::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator(mf.get()));
-    lg->GetMakefile()->SetCurrentBinaryDirectory
+    snapshot.GetDirectory().SetCurrentBinary
       (cmSystemTools::GetCurrentWorkingDirectory());
-    lg->GetMakefile()->SetCurrentSourceDirectory
+    snapshot.GetDirectory().SetCurrentSource
       (cmSystemTools::GetCurrentWorkingDirectory());
+    snapshot.SetDefaultDefinitions();
+    cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(gg, snapshot));
     if (this->GetWorkingMode() != NORMAL_MODE)
       {
       std::string file(cmSystemTools::CollapseFullPath(path));
       cmSystemTools::ConvertToUnixSlashes(file);
-      lg->GetMakefile()->SetScriptModeFile(file.c_str());
+      mf->SetScriptModeFile(file.c_str());
 
-      lg->GetMakefile()->SetArgcArgv(args);
+      mf->SetArgcArgv(args);
       }
-    if (!lg->GetMakefile()->ReadListFile(path))
+    if (!mf->ReadListFile(path))
       {
       cmSystemTools::Error("Error processing file: ", path);
       }
@@ -419,13 +493,14 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
   this->SetGlobalGenerator(gg);
 
   cmState::Snapshot snapshot = this->GetCurrentSnapshot();
-  // read in the list file to fill the cache
-  cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(gg, snapshot));
-  cmsys::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator(mf.get()));
-  mf->SetCurrentBinaryDirectory
+  snapshot.GetDirectory().SetCurrentBinary
     (cmSystemTools::GetCurrentWorkingDirectory());
-  mf->SetCurrentSourceDirectory
+  snapshot.GetDirectory().SetCurrentSource
     (cmSystemTools::GetCurrentWorkingDirectory());
+  // read in the list file to fill the cache
+  snapshot.SetDefaultDefinitions();
+  cmMakefile* mf = new cmMakefile(gg, snapshot);
+  gg->AddMakefile(mf);
 
   mf->SetArgcArgv(args);
 
@@ -458,6 +533,8 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
     std::vector<std::string> includeDirs;
     cmSystemTools::ExpandListArgument(includes, includeDirs);
 
+    gg->CreateGenerationObjects();
+    cmLocalGenerator* lg = gg->LocalGenerators[0];
     std::string includeFlags = lg->GetIncludeFlags(includeDirs, 0, language);
 
     std::string definitions = mf->GetSafeDefinition("PACKAGE_DEFINITIONS");
@@ -478,7 +555,7 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
             ++libIt)
       {
       mf->AddLinkLibraryForTarget(targetName, *libIt,
-                                  cmTarget::GENERAL);
+                                  GENERAL_LibraryType);
       }
 
 
@@ -487,8 +564,9 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
     std::string linkPath;
     std::string flags;
     std::string linkFlags;
-    gg->CreateGeneratorTargets(cmGlobalGenerator::AllTargets, lg.get());
-    cmGeneratorTarget *gtgt = gg->GetGeneratorTarget(tgt);
+    gg->CreateGenerationObjects();
+    cmGeneratorTarget *gtgt = gg->FindGeneratorTarget(tgt->GetName());
+    cmLocalGenerator* lg = gtgt->GetLocalGenerator();
     lg->GetTargetFlags(linkLibs, frameworkPath, linkPath, flags, linkFlags,
                        gtgt, false);
     linkLibs = frameworkPath + linkPath + linkLibs;
@@ -592,11 +670,7 @@ void cmake::SetArgs(const std::vector<std::string>& args,
       // skip for now
       i++;
       }
-    else if(arg.find("-Wno-dev",0) == 0)
-      {
-      // skip for now
-      }
-    else if(arg.find("-Wdev",0) == 0)
+    else if(arg.find("-W",0) == 0)
       {
       // skip for now
       }
@@ -849,14 +923,14 @@ void cmake::SetDirectoriesFromFile(const char* arg)
 int cmake::AddCMakePaths()
 {
   // Save the value in the cache
-  this->CacheManager->AddCacheEntry
+  this->AddCacheEntry
     ("CMAKE_COMMAND", cmSystemTools::GetCMakeCommand().c_str(),
      "Path to CMake executable.", cmState::INTERNAL);
 #ifdef CMAKE_BUILD_WITH_CMAKE
-  this->CacheManager->AddCacheEntry
+  this->AddCacheEntry
     ("CMAKE_CTEST_COMMAND", cmSystemTools::GetCTestCommand().c_str(),
      "Path to ctest program executable.", cmState::INTERNAL);
-  this->CacheManager->AddCacheEntry
+  this->AddCacheEntry
     ("CMAKE_CPACK_COMMAND", cmSystemTools::GetCPackCommand().c_str(),
      "Path to cpack program executable.", cmState::INTERNAL);
 #endif
@@ -870,7 +944,7 @@ int cmake::AddCMakePaths()
       cmSystemTools::GetCMakeRoot().c_str());
     return 0;
     }
-  this->CacheManager->AddCacheEntry
+  this->AddCacheEntry
     ("CMAKE_ROOT", cmSystemTools::GetCMakeRoot().c_str(),
      "Path to CMake installation.", cmState::INTERNAL);
 
@@ -931,18 +1005,32 @@ void cmake::AddDefaultExtraGenerators()
 
 
 //----------------------------------------------------------------------------
-void cmake::GetRegisteredGenerators(std::vector<std::string>& names)
+void cmake::GetRegisteredGenerators(std::vector<GeneratorInfo>& generators)
 {
-  for(RegisteredGeneratorsVector::const_iterator i = this->Generators.begin();
-      i != this->Generators.end(); ++i)
+  for (RegisteredGeneratorsVector::const_iterator
+       i = this->Generators.begin(), e = this->Generators.end();
+       i != e; ++i)
     {
+    std::vector<std::string> names;
     (*i)->GetGenerators(names);
+
+    for (size_t j = 0; j < names.size(); ++j)
+      {
+      GeneratorInfo info;
+      info.supportsToolset = (*i)->SupportsToolset();
+      info.name = names[j];
+      generators.push_back(info);
+      }
     }
-  for(RegisteredExtraGeneratorsMap::const_iterator
-      i = this->ExtraGenerators.begin();
-      i != this->ExtraGenerators.end(); ++i)
+
+  for (RegisteredExtraGeneratorsMap::const_iterator
+       i = this->ExtraGenerators.begin(), e = this->ExtraGenerators.end();
+       i != e; ++i)
     {
-    names.push_back(i->first);
+    GeneratorInfo info;
+    info.name = i->first;
+    info.supportsToolset = false;
+    generators.push_back(info);
     }
 }
 
@@ -984,6 +1072,10 @@ cmGlobalGenerator* cmake::CreateGlobalGenerator(const std::string& gname)
 void cmake::SetHomeDirectory(const std::string& dir)
 {
   this->State->SetSourceDirectory(dir);
+  if (this->CurrentSnapshot.IsValid())
+    {
+    this->CurrentSnapshot.SetDefinition("CMAKE_SOURCE_DIR", dir);
+    }
 }
 
 const char* cmake::GetHomeDirectory() const
@@ -994,6 +1086,10 @@ const char* cmake::GetHomeDirectory() const
 void cmake::SetHomeOutputDirectory(const std::string& dir)
 {
   this->State->SetBinaryDirectory(dir);
+  if (this->CurrentSnapshot.IsValid())
+    {
+    this->CurrentSnapshot.SetDefinition("CMAKE_BINARY_DIR", dir);
+    }
 }
 
 const char* cmake::GetHomeOutputDirectory() const
@@ -1087,10 +1183,10 @@ int cmake::DoPreConfigureChecks()
     }
 
   // do a sanity check on some values
-  if(this->CacheManager->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY"))
+  if(this->State->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY"))
     {
     std::string cacheStart =
-      this->CacheManager->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY");
+      this->State->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY");
     cacheStart += "/CMakeLists.txt";
     std::string currentStart = this->GetHomeDirectory();
     currentStart += "/CMakeLists.txt";
@@ -1147,12 +1243,12 @@ int cmake::HandleDeleteCacheVariables(const std::string& var)
     save.value = *i;
     warning << *i << "\n";
     const char* existingValue =
-        this->CacheManager->GetCacheEntryValue(save.key);
+        this->State->GetCacheEntryValue(save.key);
     if(existingValue)
       {
-      save.type = this->CacheManager->GetCacheEntryType(save.key);
+      save.type = this->State->GetCacheEntryType(save.key);
       if(const char* help =
-            this->CacheManager->GetCacheEntryProperty(save.key, "HELPSTRING"))
+            this->State->GetCacheEntryProperty(save.key, "HELPSTRING"))
         {
         save.help = help;
         }
@@ -1161,7 +1257,7 @@ int cmake::HandleDeleteCacheVariables(const std::string& var)
     }
 
   // remove the cache
-  this->CacheManager->DeleteCache(this->GetHomeOutputDirectory());
+  this->DeleteCache(this->GetHomeOutputDirectory());
   // load the empty cache
   this->LoadCache();
   // restore the changed compilers
@@ -1183,25 +1279,80 @@ int cmake::HandleDeleteCacheVariables(const std::string& var)
 
 int cmake::Configure()
 {
-  if(this->DoSuppressDevWarnings)
+  DiagLevel diagLevel;
+
+  if (this->DiagLevels.count("deprecated") == 1)
     {
-    if(this->SuppressDevWarnings)
+
+    diagLevel = this->DiagLevels["deprecated"];
+    if (diagLevel == DIAG_IGNORE)
       {
-      this->CacheManager->
-        AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "TRUE",
-                      "Suppress Warnings that are meant for"
-                      " the author of the CMakeLists.txt files.",
-                      cmState::INTERNAL);
+      this->SetSuppressDeprecatedWarnings(true);
+      this->SetDeprecatedWarningsAsErrors(false);
       }
-    else
+    else if (diagLevel == DIAG_WARN)
       {
-      this->CacheManager->
-        AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "FALSE",
-                      "Suppress Warnings that are meant for"
-                      " the author of the CMakeLists.txt files.",
-                      cmState::INTERNAL);
+      this->SetSuppressDeprecatedWarnings(false);
+      this->SetDeprecatedWarningsAsErrors(false);
+      }
+    else if (diagLevel == DIAG_ERROR)
+      {
+      this->SetSuppressDeprecatedWarnings(false);
+      this->SetDeprecatedWarningsAsErrors(true);
       }
     }
+
+  if (this->DiagLevels.count("dev") == 1)
+    {
+    bool setDeprecatedVariables = false;
+
+    const char* cachedWarnDeprecated =
+           this->State->GetCacheEntryValue("CMAKE_WARN_DEPRECATED");
+    const char* cachedErrorDeprecated =
+           this->State->GetCacheEntryValue("CMAKE_ERROR_DEPRECATED");
+
+    // don't overwrite deprecated warning setting from a previous invocation
+    if (!cachedWarnDeprecated && !cachedErrorDeprecated)
+      {
+      setDeprecatedVariables = true;
+      }
+
+    diagLevel = this->DiagLevels["dev"];
+    if (diagLevel == DIAG_IGNORE)
+      {
+      this->SetSuppressDevWarnings(true);
+      this->SetDevWarningsAsErrors(false);
+
+      if (setDeprecatedVariables)
+        {
+        this->SetSuppressDeprecatedWarnings(true);
+        this->SetDeprecatedWarningsAsErrors(false);
+        }
+      }
+    else if (diagLevel == DIAG_WARN)
+      {
+      this->SetSuppressDevWarnings(false);
+      this->SetDevWarningsAsErrors(false);
+
+      if (setDeprecatedVariables)
+        {
+        this->SetSuppressDeprecatedWarnings(false);
+        this->SetDeprecatedWarningsAsErrors(false);
+        }
+      }
+    else if (diagLevel == DIAG_ERROR)
+      {
+      this->SetSuppressDevWarnings(false);
+      this->SetDevWarningsAsErrors(true);
+
+      if (setDeprecatedVariables)
+        {
+        this->SetSuppressDeprecatedWarnings(false);
+        this->SetDeprecatedWarningsAsErrors(true);
+        }
+      }
+    }
+
   int ret = this->ActualConfigure();
   const char* delCacheVars = this->State
                     ->GetGlobalProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_");
@@ -1230,7 +1381,7 @@ int cmake::ActualConfigure()
     }
   if ( !res )
     {
-    this->CacheManager->AddCacheEntry
+    this->AddCacheEntry
       ("CMAKE_HOME_DIRECTORY",
        this->GetHomeDirectory(),
        "Source directory with the top level CMakeLists.txt file for this "
@@ -1242,9 +1393,9 @@ int cmake::ActualConfigure()
   if(!this->GlobalGenerator)
     {
     const char* genName =
-      this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR");
+      this->State->GetInitializedCacheValue("CMAKE_GENERATOR");
     const char* extraGenName =
-      this->CacheManager->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
+      this->State->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
     if(genName)
       {
       std::string fullName = cmExternalMakefileProjectGenerator::
@@ -1322,7 +1473,7 @@ int cmake::ActualConfigure()
       }
     }
 
-  const char* genName = this->CacheManager
+  const char* genName = this->State
                             ->GetInitializedCacheValue("CMAKE_GENERATOR");
   if(genName)
     {
@@ -1339,20 +1490,20 @@ int cmake::ActualConfigure()
       return -2;
       }
     }
-  if(!this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR"))
+  if(!this->State->GetInitializedCacheValue("CMAKE_GENERATOR"))
     {
-    this->CacheManager->AddCacheEntry("CMAKE_GENERATOR",
+    this->AddCacheEntry("CMAKE_GENERATOR",
                                       this->GlobalGenerator->GetName().c_str(),
                                       "Name of generator.",
                                       cmState::INTERNAL);
-    this->CacheManager->AddCacheEntry("CMAKE_EXTRA_GENERATOR",
+    this->AddCacheEntry("CMAKE_EXTRA_GENERATOR",
                         this->GlobalGenerator->GetExtraGeneratorName().c_str(),
                         "Name of external makefile project generator.",
                         cmState::INTERNAL);
     }
 
   if(const char* platformName =
-     this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR_PLATFORM"))
+     this->State->GetInitializedCacheValue("CMAKE_GENERATOR_PLATFORM"))
     {
     if(this->GeneratorPlatform.empty())
       {
@@ -1373,14 +1524,14 @@ int cmake::ActualConfigure()
     }
   else
     {
-    this->CacheManager->AddCacheEntry("CMAKE_GENERATOR_PLATFORM",
+    this->AddCacheEntry("CMAKE_GENERATOR_PLATFORM",
                                       this->GeneratorPlatform.c_str(),
                                       "Name of generator platform.",
                                       cmState::INTERNAL);
     }
 
   if(const char* tsName =
-     this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR_TOOLSET"))
+     this->State->GetInitializedCacheValue("CMAKE_GENERATOR_TOOLSET"))
     {
     if(this->GeneratorToolset.empty())
       {
@@ -1401,7 +1552,7 @@ int cmake::ActualConfigure()
     }
   else
     {
-    this->CacheManager->AddCacheEntry("CMAKE_GENERATOR_TOOLSET",
+    this->AddCacheEntry("CMAKE_GENERATOR_TOOLSET",
                                       this->GeneratorToolset.c_str(),
                                       "Name of generator toolset.",
                                       cmState::INTERNAL);
@@ -1435,7 +1586,7 @@ int cmake::ActualConfigure()
     {
     if(!this->State->GetInitializedCacheValue("LIBRARY_OUTPUT_PATH"))
       {
-      this->State->AddCacheEntry
+      this->AddCacheEntry
         ("LIBRARY_OUTPUT_PATH", "",
          "Single output directory for building all libraries.",
          cmState::PATH);
@@ -1443,7 +1594,7 @@ int cmake::ActualConfigure()
     if(!this->State
             ->GetInitializedCacheValue("EXECUTABLE_OUTPUT_PATH"))
       {
-      this->State->AddCacheEntry
+      this->AddCacheEntry
         ("EXECUTABLE_OUTPUT_PATH", "",
          "Single output directory for building all executables.",
          cmState::PATH);
@@ -1463,7 +1614,7 @@ int cmake::ActualConfigure()
   // only save the cache if there were no fatal errors
   if ( this->GetWorkingMode() == NORMAL_MODE )
     {
-    this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
+    this->SaveCache(this->GetHomeOutputDirectory());
     }
   if(cmSystemTools::GetErrorOccuredFlag())
     {
@@ -1532,6 +1683,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
     {
     this->AddCMakePaths();
     }
+
   // Add any cache args
   if ( !this->SetCacheArgs(args) )
     {
@@ -1633,7 +1785,7 @@ int cmake::Generate()
   // for the Visual Studio and Xcode generators.)
   if ( this->GetWorkingMode() == NORMAL_MODE )
     {
-    this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
+    this->SaveCache(this->GetHomeOutputDirectory());
     }
   return 0;
 }
@@ -1642,14 +1794,15 @@ void cmake::AddCacheEntry(const std::string& key, const char* value,
                           const char* helpString,
                           int type)
 {
-  this->CacheManager->AddCacheEntry(key, value,
+  this->State->AddCacheEntry(key, value,
                                     helpString,
                                     cmState::CacheEntryType(type));
+  this->UnwatchUnusedCli(key);
 }
 
 const char* cmake::GetCacheDefinition(const std::string& name) const
 {
-  return this->CacheManager->GetInitializedCacheValue(name);
+  return this->State->GetInitializedCacheValue(name);
 }
 
 void cmake::AddDefaultCommands()
@@ -1722,7 +1875,7 @@ bool cmake::ParseCacheEntry(const std::string& entry,
                             std::string& value,
                             cmState::CacheEntryType& type)
 {
-  return cmCacheManager::ParseEntry(entry, var, value, type);
+  return cmState::ParseCacheEntry(entry, var, value, type);
 }
 
 int cmake::LoadCache()
@@ -1753,24 +1906,43 @@ int cmake::LoadCache()
 
 bool cmake::LoadCache(const std::string& path)
 {
-  return this->CacheManager->LoadCache(path);
+  std::set<std::string> emptySet;
+  return this->LoadCache(path, true, emptySet, emptySet);
 }
 
 bool cmake::LoadCache(const std::string& path, bool internal,
                 std::set<std::string>& excludes,
                 std::set<std::string>& includes)
 {
-  return this->CacheManager->LoadCache(path, internal, excludes, includes);
+  bool result = this->State->LoadCache(path, internal, excludes, includes);
+  static const char* entries[] = {"CMAKE_CACHE_MAJOR_VERSION",
+                                  "CMAKE_CACHE_MINOR_VERSION"};
+  for (const char* const* nameIt = cmArrayBegin(entries);
+       nameIt != cmArrayEnd(entries); ++nameIt)
+    {
+    this->UnwatchUnusedCli(*nameIt);
+    }
+  return result;
 }
 
 bool cmake::SaveCache(const std::string& path)
 {
-  return this->CacheManager->SaveCache(path);
+  bool result = this->State->SaveCache(path);
+  static const char* entries[] = {"CMAKE_CACHE_MAJOR_VERSION",
+                                  "CMAKE_CACHE_MINOR_VERSION",
+                                  "CMAKE_CACHE_PATCH_VERSION",
+                                  "CMAKE_CACHEFILE_DIR"};
+  for (const char* const* nameIt = cmArrayBegin(entries);
+       nameIt != cmArrayEnd(entries); ++nameIt)
+    {
+    this->UnwatchUnusedCli(*nameIt);
+    }
+  return result;
 }
 
 bool cmake::DeleteCache(const std::string& path)
 {
-  return this->CacheManager->DeleteCache(path);
+  return this->State->DeleteCache(path);
 }
 
 void cmake::SetProgressCallback(ProgressCallbackType f, void *cd)
@@ -1835,7 +2007,7 @@ void cmake::UpdateConversionPathTable()
 {
   // Update the path conversion table with any specified file:
   const char* tablepath =
-    this->CacheManager
+    this->State
         ->GetInitializedCacheValue("CMAKE_PATH_TRANSLATION_FILE");
 
   if(tablepath)
@@ -1904,9 +2076,9 @@ int cmake::CheckBuildSystem()
   cmake cm;
   cm.SetHomeDirectory("");
   cm.SetHomeOutputDirectory("");
+  cm.GetCurrentSnapshot().SetDefaultDefinitions();
   cmGlobalGenerator gg(&cm);
   cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
-  cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator(mf.get()));
   if(!mf->ReadListFile(this->CheckBuildSystemArgument.c_str()) ||
      cmSystemTools::GetErrorOccuredFlag())
     {
@@ -1935,6 +2107,7 @@ int cmake::CheckBuildSystem()
       ggd(this->CreateGlobalGenerator(genName));
     if(ggd.get())
       {
+      cm.GetCurrentSnapshot().SetDefaultDefinitions();
       cmsys::auto_ptr<cmMakefile> mfd(new cmMakefile(ggd.get(),
                                                     cm.GetCurrentSnapshot()));
       cmsys::auto_ptr<cmLocalGenerator> lgd(
@@ -2416,6 +2589,74 @@ static bool cmakeCheckStampList(const char* stampList)
   return true;
 }
 
+cmake::MessageType cmake::ConvertMessageType(cmake::MessageType t)
+{
+  bool warningsAsErrors;
+
+  if (t == cmake::AUTHOR_WARNING || t == cmake::AUTHOR_ERROR)
+    {
+    warningsAsErrors = this->GetDevWarningsAsErrors();
+    if (warningsAsErrors && t == cmake::AUTHOR_WARNING)
+      {
+      t = cmake::AUTHOR_ERROR;
+      }
+    else if (!warningsAsErrors && t == cmake::AUTHOR_ERROR)
+      {
+      t = cmake::AUTHOR_WARNING;
+      }
+    }
+  else if (t == cmake::DEPRECATION_WARNING || t == cmake::DEPRECATION_ERROR)
+    {
+    warningsAsErrors = this->GetDeprecatedWarningsAsErrors();
+    if (warningsAsErrors && t == cmake::DEPRECATION_WARNING)
+      {
+      t = cmake::DEPRECATION_ERROR;
+      }
+    else if (!warningsAsErrors && t == cmake::DEPRECATION_ERROR)
+      {
+      t = cmake::DEPRECATION_WARNING;
+      }
+    }
+
+  return t;
+}
+
+bool cmake::IsMessageTypeVisible(cmake::MessageType t)
+{
+  bool isVisible = true;
+
+  if(t == cmake::DEPRECATION_ERROR)
+    {
+    if(!this->GetDeprecatedWarningsAsErrors())
+      {
+      isVisible = false;
+      }
+    }
+  else if (t == cmake::DEPRECATION_WARNING)
+    {
+    if (this->GetSuppressDeprecatedWarnings())
+      {
+      isVisible = false;
+      }
+    }
+  else if (t == cmake::AUTHOR_ERROR)
+    {
+    if (!this->GetDevWarningsAsErrors())
+      {
+      isVisible = false;
+      }
+    }
+  else if (t == cmake::AUTHOR_WARNING)
+    {
+    if (this->GetSuppressDevWarnings())
+      {
+      isVisible = false;
+      }
+    }
+
+  return isVisible;
+}
+
 bool cmake::PrintMessagePreamble(cmake::MessageType t, std::ostream& msg)
 {
   // Construct the message header.
@@ -2439,20 +2680,17 @@ bool cmake::PrintMessagePreamble(cmake::MessageType t, std::ostream& msg)
     {
     msg << "CMake Deprecation Warning";
     }
+  else if (t == cmake::AUTHOR_WARNING)
+    {
+    msg << "CMake Warning (dev)";
+    }
+  else if (t == cmake::AUTHOR_ERROR)
+    {
+    msg << "CMake Error (dev)";
+    }
   else
     {
     msg << "CMake Warning";
-    if(t == cmake::AUTHOR_WARNING)
-      {
-      // Allow suppression of these warnings.
-      const char* suppress = this->State->GetCacheEntryValue(
-                                        "CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
-      if(suppress && cmSystemTools::IsOn(suppress))
-        {
-        return false;
-        }
-      msg << " (dev)";
-      }
     }
   return true;
 }
@@ -2474,6 +2712,12 @@ void displayMessage(cmake::MessageType t, std::ostringstream& msg)
     msg <<
       "This warning is for project developers.  Use -Wno-dev to suppress it.";
     }
+  else if (t == cmake::AUTHOR_ERROR)
+    {
+    msg <<
+      "This error is for project developers. Use -Wno-error=dev to suppress "
+      "it.";
+    }
 
   // Add a terminating blank line.
   msg << "\n";
@@ -2497,7 +2741,8 @@ void displayMessage(cmake::MessageType t, std::ostringstream& msg)
   // Output the message.
   if(t == cmake::FATAL_ERROR
      || t == cmake::INTERNAL_ERROR
-     || t == cmake::DEPRECATION_ERROR)
+     || t == cmake::DEPRECATION_ERROR
+     || t == cmake::AUTHOR_ERROR)
     {
     cmSystemTools::SetErrorOccured();
     cmSystemTools::Message(msg.str().c_str(), "Error");
@@ -2510,10 +2755,27 @@ void displayMessage(cmake::MessageType t, std::ostringstream& msg)
 
 //----------------------------------------------------------------------------
 void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
-                         cmListFileBacktrace const& bt)
+                         cmListFileBacktrace const& bt,
+                         bool force)
 {
   cmListFileBacktrace backtrace = bt;
 
+  if (!force)
+    {
+    // override the message type, if needed, for warnings and errors
+    cmake::MessageType override = this->ConvertMessageType(t);
+    if (override != t)
+      {
+      t = override;
+      force = true;
+      }
+    }
+
+  if (!force && !this->IsMessageTypeVisible(t))
+    {
+    return;
+    }
+
   std::ostringstream msg;
   if (!this->PrintMessagePreamble(t, msg))
     {
@@ -2533,8 +2795,25 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
 
 //----------------------------------------------------------------------------
 void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
-                         cmListFileContext const& lfc)
+                         cmListFileContext const& lfc,
+                         bool force)
 {
+  if (!force)
+    {
+    // override the message type, if needed, for warnings and errors
+    cmake::MessageType override = this->ConvertMessageType(t);
+    if (override != t)
+      {
+      t = override;
+      force = true;
+      }
+    }
+
+  if (!force && !this->IsMessageTypeVisible(t))
+    {
+    return;
+    }
+
   std::ostringstream msg;
   if (!this->PrintMessagePreamble(t, msg))
     {
@@ -2694,3 +2973,153 @@ void cmake::RunCheckForUnusedVariables()
     }
 #endif
 }
+
+bool cmake::GetSuppressDevWarnings(cmMakefile const* mf)
+{
+  /*
+   * The suppression CMake variable may be set in the CMake configuration file
+   * itself, so we have to check what its set to in the makefile if we can.
+   */
+  if (mf)
+    {
+    return mf->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
+    }
+  else
+    {
+    const char* cacheEntryValue = this->State->GetCacheEntryValue(
+      "CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
+    return cmSystemTools::IsOn(cacheEntryValue);
+    }
+}
+
+void cmake::SetSuppressDevWarnings(bool b)
+{
+  std::string value;
+
+  // equivalent to -Wno-dev
+  if (b)
+    {
+    value = "TRUE";
+    }
+  // equivalent to -Wdev
+  else
+    {
+    value = "FALSE";
+    }
+
+  this->AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", value.c_str(),
+                      "Suppress Warnings that are meant for"
+                      " the author of the CMakeLists.txt files.",
+                      cmState::INTERNAL);
+}
+
+bool cmake::GetSuppressDeprecatedWarnings(cmMakefile const* mf)
+{
+  /*
+   * The suppression CMake variable may be set in the CMake configuration file
+   * itself, so we have to check what its set to in the makefile if we can.
+   */
+  if (mf)
+    {
+    return (mf->IsSet("CMAKE_WARN_DEPRECATED") &&
+            !mf->IsOn("CMAKE_WARN_DEPRECATED"));
+    }
+  else
+    {
+    const char* cacheEntryValue = this->State->GetCacheEntryValue(
+      "CMAKE_WARN_DEPRECATED");
+    return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue);
+    }
+}
+
+void cmake::SetSuppressDeprecatedWarnings(bool b)
+{
+  std::string value;
+
+  // equivalent to -Wno-deprecated
+  if (b)
+    {
+    value = "FALSE";
+    }
+  // equivalent to -Wdeprecated
+  else
+    {
+    value = "TRUE";
+    }
+
+  this->AddCacheEntry("CMAKE_WARN_DEPRECATED", value.c_str(),
+                      "Whether to issue warnings for deprecated "
+                      "functionality.",
+                      cmState::INTERNAL);
+}
+
+bool cmake::GetDevWarningsAsErrors(cmMakefile const* mf)
+{
+  if (mf)
+    {
+    return (mf->IsSet("CMAKE_SUPPRESS_DEVELOPER_ERRORS") &&
+            !mf->IsOn("CMAKE_SUPPRESS_DEVELOPER_ERRORS"));
+    }
+  else
+    {
+    const char* cacheEntryValue = this->State->GetCacheEntryValue(
+      "CMAKE_SUPPRESS_DEVELOPER_ERRORS");
+    return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue);
+    }
+}
+
+void cmake::SetDevWarningsAsErrors(bool b)
+{
+  std::string value;
+
+  // equivalent to -Werror=dev
+  if (b)
+    {
+    value = "FALSE";
+    }
+  // equivalent to -Wno-error=dev
+  else
+    {
+    value = "TRUE";
+    }
+
+  this->AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_ERRORS", value.c_str(),
+                      "Suppress errors that are meant for"
+                      " the author of the CMakeLists.txt files.",
+                      cmState::INTERNAL);
+}
+
+bool cmake::GetDeprecatedWarningsAsErrors(cmMakefile const* mf)
+{
+  if (mf)
+    {
+    return mf->IsOn("CMAKE_ERROR_DEPRECATED");
+    }
+  else
+    {
+    const char* cacheEntryValue = this->State->GetCacheEntryValue(
+      "CMAKE_ERROR_DEPRECATED");
+    return cmSystemTools::IsOn(cacheEntryValue);
+    }
+}
+
+void cmake::SetDeprecatedWarningsAsErrors(bool b)
+{
+  std::string value;
+
+  // equivalent to -Werror=deprecated
+  if (b)
+    {
+    value = "TRUE";
+    }
+  // equivalent to -Wno-error=deprecated
+  else
+    {
+    value = "FALSE";
+    }
+
+  this->AddCacheEntry("CMAKE_ERROR_DEPRECATED", value.c_str(),
+                      "Whether to issue deprecation errors for macros"
+                      " and functions.",
+                      cmState::INTERNAL);
+}
diff --git a/Source/cmake.h b/Source/cmake.h
index 9d28cba..8496705 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -59,6 +59,7 @@ class cmake
  public:
   enum MessageType
   { AUTHOR_WARNING,
+    AUTHOR_ERROR,
     FATAL_ERROR,
     INTERNAL_ERROR,
     MESSAGE,
@@ -68,6 +69,12 @@ class cmake
     DEPRECATION_WARNING
   };
 
+  enum DiagLevel
+  {
+    DIAG_IGNORE,
+    DIAG_WARN,
+    DIAG_ERROR
+  };
 
   /** \brief Describes the working modes of cmake */
   enum WorkingMode
@@ -89,6 +96,13 @@ class cmake
      */
     FIND_PACKAGE_MODE
   };
+
+  struct GeneratorInfo
+    {
+    std::string name;
+    bool supportsToolset;
+    };
+
   typedef std::map<std::string, cmInstalledFile> InstalledFilesMap;
 
   /// Default constructor
@@ -161,7 +175,7 @@ class cmake
   void SetGlobalGenerator(cmGlobalGenerator *);
 
   ///! Get the names of the current registered generators
-  void GetRegisteredGenerators(std::vector<std::string>& names);
+  void GetRegisteredGenerators(std::vector<GeneratorInfo>& generators);
 
   ///! Set the name of the selected generator-specific platform.
   void SetGeneratorPlatform(std::string const& ts)
@@ -182,6 +196,11 @@ class cmake
   ///! get the cmCachemManager used by this invocation of cmake
   cmCacheManager *GetCacheManager() { return this->CacheManager; }
 
+  const std::vector<std::string>& GetSourceExtensions() const
+    {return this->SourceFileExtensions;}
+  const std::vector<std::string>& GetHeaderExtensions() const
+    {return this->HeaderFileExtensions;}
+
   /**
    * Given a variable name, return its value (as a string).
    */
@@ -291,17 +310,57 @@ class cmake
   std::string const& GetCMakeEditCommand() const
     { return this->CMakeEditCommand; }
 
-  void SetSuppressDevWarnings(bool v)
-    {
-      this->SuppressDevWarnings = v;
-      this->DoSuppressDevWarnings = true;
-    }
+  /*
+   * Get the state of the suppression of developer (author) warnings.
+   * Returns false, by default, if developer warnings should be shown, true
+   * otherwise.
+   */
+  bool GetSuppressDevWarnings(cmMakefile const* mf = NULL);
+  /*
+   * Set the state of the suppression of developer (author) warnings.
+   */
+  void SetSuppressDevWarnings(bool v);
+
+  /*
+   * Get the state of the suppression of deprecated warnings.
+   * Returns false, by default, if deprecated warnings should be shown, true
+   * otherwise.
+   */
+  bool GetSuppressDeprecatedWarnings(cmMakefile const* mf = NULL);
+  /*
+   * Set the state of the suppression of deprecated warnings.
+   */
+  void SetSuppressDeprecatedWarnings(bool v);
+
+  /*
+   * Get the state of treating developer (author) warnings as errors.
+   * Returns false, by default, if warnings should not be treated as errors,
+   * true otherwise.
+   */
+  bool GetDevWarningsAsErrors(cmMakefile const* mf = NULL);
+  /**
+   * Set the state of treating developer (author) warnings as errors.
+   */
+  void SetDevWarningsAsErrors(bool v);
+
+  /*
+   * Get the state of treating deprecated warnings as errors.
+   * Returns false, by default, if warnings should not be treated as errors,
+   * true otherwise.
+   */
+  bool GetDeprecatedWarningsAsErrors(cmMakefile const* mf = NULL);
+  /**
+   * Set the state of treating developer (author) warnings as errors.
+   */
+  void SetDeprecatedWarningsAsErrors(bool v);
 
   /** Display a message to the user.  */
   void IssueMessage(cmake::MessageType t, std::string const& text,
-        cmListFileBacktrace const& backtrace = cmListFileBacktrace());
+        cmListFileBacktrace const& backtrace = cmListFileBacktrace(),
+        bool force = false);
   void IssueMessage(cmake::MessageType t, std::string const& text,
-        cmListFileContext const& lfc);
+        cmListFileContext const& lfc,
+        bool force = false);
 
   ///! run the --build option
   int Build(const std::string& dir,
@@ -339,8 +398,7 @@ protected:
 
   cmGlobalGenerator *GlobalGenerator;
   cmCacheManager *CacheManager;
-  bool SuppressDevWarnings;
-  bool DoSuppressDevWarnings;
+  std::map<std::string, DiagLevel> DiagLevels;
   std::string GeneratorPlatform;
   std::string GeneratorToolset;
 
@@ -391,6 +449,8 @@ private:
   std::string CheckStampFile;
   std::string CheckStampList;
   std::string VSSolutionFile;
+  std::vector<std::string> SourceFileExtensions;
+  std::vector<std::string> HeaderFileExtensions;
   bool ClearBuildSystem;
   bool DebugTryCompile;
   cmFileTimeComparison* FileComparison;
@@ -405,6 +465,18 @@ private:
   // Print a list of valid generators to stderr.
   void PrintGeneratorList();
 
+  /**
+   * Convert a message type between a warning and an error, based on the state
+   * of the error output CMake variables, in the cache.
+   */
+  cmake::MessageType ConvertMessageType(cmake::MessageType t);
+
+  /*
+   * Check if messages of this type should be output, based on the state of the
+   * warning and error output CMake variables, in the cache.
+   */
+  bool IsMessageTypeVisible(cmake::MessageType t);
+
   bool PrintMessagePreamble(cmake::MessageType t, std::ostream& msg);
 };
 
@@ -415,8 +487,16 @@ private:
   {"-G <generator-name>", "Specify a build system generator."},\
   {"-T <toolset-name>", "Specify toolset name if supported by generator."}, \
   {"-A <platform-name>", "Specify platform name if supported by generator."}, \
+  {"-Wdev", "Enable developer warnings."},\
   {"-Wno-dev", "Suppress developer warnings."},\
-  {"-Wdev", "Enable developer warnings."}
+  {"-Werror=dev", "Make developer warnings errors."},\
+  {"-Wno-error=dev", "Make developer warnings not errors."},\
+  {"-Wdeprecated", "Enable deprecation warnings."},\
+  {"-Wno-deprecated", "Suppress deprecation warnings."},\
+  {"-Werror=deprecated", "Make deprecated macro and function warnings " \
+                         "errors."},\
+  {"-Wno-error=deprecated", "Make deprecated macro and function warnings " \
+                            "not errors."}
 
 #define FOR_EACH_C_FEATURE(F) \
   F(c_function_prototypes) \
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index a074444..e9d77b2 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -35,8 +35,7 @@
 
 #include <stdlib.h> // required for atoi
 #if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE)
-// defined in binexplib.cxx
-bool DumpFile(const char* filename, FILE *fout);
+#include "bindexplib.h"
 #endif
 
 void CMakeCommandUsage(const char* program)
@@ -53,25 +52,25 @@ void CMakeCommandUsage(const char* program)
   // If you add new commands, change here,
   // and in cmakemain.cxx in the options table
   errorStream
-    << "Usage: " << program << " -E [command] [arguments ...]\n"
+    << "Usage: " << program << " -E <command> [arguments...]\n"
     << "Available commands: \n"
-    << "  chdir dir cmd [args]...   - run command in a given directory\n"
+    << "  chdir dir cmd [args...]   - run command in a given directory\n"
     << "  compare_files file1 file2 - check if file1 is same as file2\n"
-    << "  copy file destination     - copy file to destination (either file "
-       "or directory)\n"
-    << "  copy_directory source destination   - copy directory 'source' "
-       "content to directory 'destination'\n"
-    << "  copy_if_different in-file out-file  - copy file if input has "
+    << "  copy <file>... destination  - copy files to destination "
+       "(either file or directory)\n"
+    << "  copy_directory <dir>... destination   - copy content of <dir>... "
+       "directories to 'destination' directory\n"
+    << "  copy_if_different <file>... destination  - copy files if it has "
        "changed\n"
-    << "  echo [string]...          - displays arguments as text\n"
-    << "  echo_append [string]...   - displays arguments as text but no new "
+    << "  echo [<string>...]        - displays arguments as text\n"
+    << "  echo_append [<string>...] - displays arguments as text but no new "
        "line\n"
     << "  env [--unset=NAME]... [NAME=VALUE]... COMMAND [ARG]...\n"
     << "                            - run command in a modified environment\n"
     << "  environment               - display the current environment\n"
-    << "  make_directory dir        - create a directory\n"
-    << "  md5sum file1 [...]        - compute md5sum of files\n"
-    << "  remove [-f] file1 file2 ... - remove the file(s), use -f to force "
+    << "  make_directory <dir>...   - create parent and <dir> directories\n"
+    << "  md5sum <file>...          - compute md5sum of files\n"
+    << "  remove [-f] <file>...     - remove the file(s), use -f to force "
        "it\n"
     << "  remove_directory dir      - remove a directory and its contents\n"
     << "  rename oldname newname    - rename a file or directory "
@@ -79,7 +78,7 @@ void CMakeCommandUsage(const char* program)
     << "  tar [cxt][vf][zjJ] file.tar [file/dir1 file/dir2 ...]\n"
     << "                            - create or extract a tar or zip archive\n"
     << "  sleep <number>...         - sleep for given number of seconds\n"
-    << "  time command [args] ...   - run command and return elapsed time\n"
+    << "  time command [args...]    - run command and return elapsed time\n"
     << "  touch file                - touch a file.\n"
     << "  touch_nocreate file       - touch a file but do not create it.\n"
 #if defined(_WIN32) && !defined(__CYGWIN__)
@@ -150,42 +149,79 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
   if (args.size() > 1)
     {
     // Copy file
-    if (args[1] == "copy" && args.size() == 4)
+    if (args[1] == "copy" && args.size() > 3)
       {
-      if(!cmSystemTools::cmCopyFile(args[2].c_str(), args[3].c_str()))
+      // If multiple source files specified,
+      // then destination must be directory
+      if ((args.size() > 4) &&
+          (!cmSystemTools::FileIsDirectory(args[args.size() - 1])))
         {
-        std::cerr << "Error copying file \"" << args[2]
-                  << "\" to \"" << args[3] << "\".\n";
+        std::cerr << "Error: Target (for copy command) \""
+                  << args[args.size() - 1]
+                  << "\" is not a directory.\n";
         return 1;
         }
-      return 0;
+      // If error occurs we want to continue copying next files.
+      bool return_value = 0;
+      for (std::string::size_type cc = 2; cc < args.size() - 1; cc ++)
+        {
+        if(!cmSystemTools::cmCopyFile(args[cc].c_str(),
+            args[args.size() - 1].c_str()))
+          {
+          std::cerr << "Error copying file \"" << args[cc]
+                    << "\" to \"" << args[args.size() - 1] << "\".\n";
+          return_value = 1;
+          }
+        }
+      return return_value;
       }
 
     // Copy file if different.
-    if (args[1] == "copy_if_different" && args.size() == 4)
+    if (args[1] == "copy_if_different" && args.size() > 3)
       {
-      if(!cmSystemTools::CopyFileIfDifferent(args[2].c_str(),
-          args[3].c_str()))
+      // If multiple source files specified,
+      // then destination must be directory
+      if ((args.size() > 4) &&
+          (!cmSystemTools::FileIsDirectory(args[args.size() - 1])))
         {
-        std::cerr << "Error copying file (if different) from \""
-                  << args[2] << "\" to \"" << args[3]
-                  << "\".\n";
+        std::cerr << "Error: Target (for copy_if_different command) \""
+                  << args[args.size() - 1]
+                  << "\" is not a directory.\n";
         return 1;
         }
-      return 0;
+      // If error occurs we want to continue copying next files.
+      bool return_value = 0;
+      for (std::string::size_type cc = 2; cc < args.size() - 1; cc ++)
+        {
+        if(!cmSystemTools::CopyFileIfDifferent(args[cc].c_str(),
+            args[args.size() - 1].c_str()))
+          {
+          std::cerr << "Error copying file (if different) from \""
+                    << args[cc] << "\" to \"" << args[args.size() - 1]
+                    << "\".\n";
+          return_value = 1;
+          }
+        }
+      return return_value;
       }
 
     // Copy directory content
-    if (args[1] == "copy_directory" && args.size() == 4)
+    if (args[1] == "copy_directory" && args.size() > 3)
       {
-      if(!cmSystemTools::CopyADirectory(args[2], args[3]))
+      // If error occurs we want to continue copying next files.
+      bool return_value = 0;
+      for (std::string::size_type cc = 2; cc < args.size() - 1; cc ++)
         {
-        std::cerr << "Error copying directory from \""
-                  << args[2] << "\" to \"" << args[3]
-                  << "\".\n";
-        return 1;
+        if(!cmSystemTools::CopyADirectory(args[cc].c_str(),
+            args[args.size() - 1].c_str()))
+          {
+          std::cerr << "Error copying directory from \""
+                    << args[cc] << "\" to \"" << args[args.size() - 1]
+                    << "\".\n";
+          return_value = 1;
+          }
         }
-      return 0;
+      return return_value;
       }
 
     // Rename a file or directory
@@ -240,13 +276,16 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
         return 1;
         }
       std::string objfile;
+      bindexplib deffile;
       while(cmSystemTools::GetLineFromStream(fin, objfile))
         {
-        if (!DumpFile(objfile.c_str(), fout))
+        if( !deffile.AddObjectFile(objfile.c_str()))
           {
           return 1;
           }
         }
+      deffile.WriteFile(fout);
+      fclose(fout);
       return 0;
       }
 #endif
@@ -322,11 +361,10 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
         }
 
       // Now run the real compiler command and return its result value.
-      if(!cmSystemTools::RunSingleCommand(orig_cmd, 0, &stdErr, &ret, 0,
+      if(!cmSystemTools::RunSingleCommand(orig_cmd, 0, 0, &ret, 0,
                                           cmSystemTools::OUTPUT_PASSTHROUGH))
         {
-        std::cerr << "Error running '" << orig_cmd[0] << "': "
-                  << stdErr << "\n";
+        std::cerr << "Error running '" << orig_cmd[0] << "'\n";
         return 1;
         }
       return ret;
@@ -408,15 +446,20 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
       }
 #endif
 
-    else if (args[1] == "make_directory" && args.size() == 3)
+    else if (args[1] == "make_directory" && args.size() > 2)
       {
-      if(!cmSystemTools::MakeDirectory(args[2].c_str()))
+      // If error occurs we want to continue copying next files.
+      bool return_value = 0;
+      for (std::string::size_type cc = 2; cc < args.size(); cc ++)
         {
-        std::cerr << "Error making directory \"" << args[2]
-                  << "\".\n";
-        return 1;
+        if(!cmSystemTools::MakeDirectory(args[cc].c_str()))
+          {
+          std::cerr << "Error creating directory \""
+                    << args[cc] << "\".\n";
+          return_value = 1;
+          }
         }
-      return 0;
+      return return_value;
       }
 
     else if (args[1] == "remove_directory" && args.size() == 3)
@@ -511,7 +554,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
     // Clock command
     else if (args[1] == "time" && args.size() > 2)
       {
-      std::string command = cmJoin(cmMakeRange(args).advance(2), " ");
+      std::vector<std::string> command(args.begin()+2, args.end());
 
       clock_t clock_start, clock_finish;
       time_t time_start, time_finish;
@@ -519,7 +562,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
       time(&time_start);
       clock_start = clock();
       int ret =0;
-      cmSystemTools::RunSingleCommand(command.c_str(), 0, 0, &ret);
+      cmSystemTools::RunSingleCommand(command, 0, 0, &ret);
 
       clock_finish = clock();
       time(&time_finish);
@@ -577,7 +620,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
       int retval = 0;
       int timeout = 0;
       if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, 0, &retval,
-             directory.c_str(), cmSystemTools::OUTPUT_NORMAL, timeout) )
+             directory.c_str(), cmSystemTools::OUTPUT_PASSTHROUGH, timeout) )
         {
         return retval;
         }
@@ -765,15 +808,16 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
       startOutDir = cmSystemTools::CollapseFullPath(startOutDir);
       cm.SetHomeDirectory(homeDir);
       cm.SetHomeOutputDirectory(homeOutDir);
+      cm.GetCurrentSnapshot().SetDefaultDefinitions();
       if(cmGlobalGenerator* ggd = cm.CreateGlobalGenerator(gen))
         {
         cm.SetGlobalGenerator(ggd);
         cmState::Snapshot snapshot = cm.GetCurrentSnapshot();
+        snapshot.GetDirectory().SetCurrentBinary(startOutDir);
+        snapshot.GetDirectory().SetCurrentSource(startDir);
         cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(ggd, snapshot));
         cmsys::auto_ptr<cmLocalGenerator> lgd(
               ggd->CreateLocalGenerator(mf.get()));
-        lgd->GetMakefile()->SetCurrentSourceDirectory(startDir);
-        lgd->GetMakefile()->SetCurrentBinaryDirectory(startOutDir);
 
         // Actually scan dependencies.
         return lgd->UpdateDependencies(depInfo.c_str(),
diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt
index 84010d8..8b15394 100644
--- a/Source/kwsys/CMakeLists.txt
+++ b/Source/kwsys/CMakeLists.txt
@@ -118,13 +118,11 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
   SET(KWSYS_USE_System 1)
   SET(KWSYS_USE_SystemTools 1)
   SET(KWSYS_USE_CommandLineArguments 1)
-  SET(KWSYS_USE_FundamentalType 1)
   SET(KWSYS_USE_Terminal 1)
   SET(KWSYS_USE_IOStream 1)
   SET(KWSYS_USE_FStream 1)
   SET(KWSYS_USE_String 1)
   SET(KWSYS_USE_SystemInformation 1)
-  SET(KWSYS_USE_CPU 1)
 ENDIF()
 
 # Enforce component dependencies.
@@ -342,11 +340,6 @@ ENDIF()
 # capabilities and parent project's request.  Enforce 0/1 as only
 # possible values for configuration into Configure.hxx.
 
-IF(UNIX)
-  KWSYS_PLATFORM_CXX_TEST(KWSYS_STAT_HAS_ST_MTIM
-    "Checking whether struct stat has st_mtim member" DIRECT)
-ENDIF()
-
 # Check existence and uniqueness of long long and __int64.
 KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_LONG_LONG
   "Checking whether C++ compiler has 'long long'" DIRECT)
@@ -380,68 +373,6 @@ IF(KWSYS_CXX_HAS___INT64)
   ENDIF()
 ENDIF()
 
-IF(KWSYS_USE_FundamentalType)
-  # Look for type size helper macros.
-  KWSYS_PLATFORM_INFO_TEST(C KWSYS_C_TYPE_MACROS
-    "Checking for C type size macros")
-  SET(macro_regex ".*INFO:macro\\[([^]]*)\\].*")
-  FOREACH(info ${KWSYS_C_TYPE_MACROS})
-    IF("${info}" MATCHES "${macro_regex}")
-      STRING(REGEX REPLACE "${macro_regex}" "\\1" macro "${info}")
-      SET(KWSYS_C_HAS_MACRO_${macro} 1)
-    ENDIF()
-  ENDFOREACH()
-
-  # Determine type sizes at preprocessing time if possible, and
-  # otherwise fall back to a try-compile.
-  SET(KWSYS_C_TYPE_NAME_CHAR      "char")
-  SET(KWSYS_C_TYPE_NAME_SHORT     "short")
-  SET(KWSYS_C_TYPE_NAME_INT       "int")
-  SET(KWSYS_C_TYPE_NAME_LONG      "long")
-  SET(KWSYS_C_TYPE_NAME_LONG_LONG "long long")
-  SET(KWSYS_C_TYPE_NAME___INT64   "__int64")
-  FOREACH(type CHAR SHORT INT LONG LONG_LONG __INT64)
-    IF(KWSYS_C_HAS_MACRO___SIZEOF_${type}__)
-      # Use __SIZEOF_${type}__ macro.
-      SET(KWSYS_SIZEOF_${type} TRUE)
-      SET(KWSYS_C_CODE_SIZEOF_${type} "#define ${KWSYS_NAMESPACE}_SIZEOF_${type} __SIZEOF_${type}__")
-    ELSEIF(KWSYS_C_HAS_MACRO___${type}_MAX__)
-      # Use __${type}_MAX__ macro.
-      SET(KWSYS_SIZEOF_${type} TRUE)
-      SET(KWSYS_C_CODE_SIZEOF_${type} "#if __${type}_MAX__ == 0x7f
-# define ${KWSYS_NAMESPACE}_SIZEOF_${type} 1
-#elif __${type}_MAX__ == 0x7fff
-# define ${KWSYS_NAMESPACE}_SIZEOF_${type} 2
-#elif __${type}_MAX__ == 0x7fffffff
-# define ${KWSYS_NAMESPACE}_SIZEOF_${type} 4
-#elif __${type}_MAX__>>32 == 0x7fffffff
-# define ${KWSYS_NAMESPACE}_SIZEOF_${type} 8
-#else
-# error \"Cannot determine sizeof(${KWSYS_C_TYPE_NAME_${type}}).\"
-#endif")
-    ELSE()
-      # Configure a hard-coded type size.
-      CHECK_TYPE_SIZE("${KWSYS_C_TYPE_NAME_${type}}" KWSYS_SIZEOF_${type})
-      IF(NOT KWSYS_SIZEOF_${type})
-        SET(KWSYS_SIZEOF_${type} 0)
-      ENDIF()
-      SET(KWSYS_C_CODE_SIZEOF_${type}
-        "#define ${KWSYS_NAMESPACE}_SIZEOF_${type} ${KWSYS_SIZEOF_${type}}")
-    ENDIF()
-  ENDFOREACH()
-
-  IF(KWSYS_USE___INT64)
-    KWSYS_PLATFORM_CXX_TEST(KWSYS_CAN_CONVERT_UI64_TO_DOUBLE
-      "Checking whether unsigned __int64 can convert to double" DIRECT)
-  ELSE()
-    SET(KWSYS_CAN_CONVERT_UI64_TO_DOUBLE 1)
-  ENDIF()
-
-  # Check signedness of "char" type.
-  KWSYS_PLATFORM_CXX_TEST_RUN(KWSYS_CHAR_IS_SIGNED
-    "Checking whether char is signed" DIRECT)
-ENDIF()
-
 IF(KWSYS_USE_Encoding)
   # Look for type size helper macros.
   KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_WSTRING
@@ -511,12 +442,18 @@ IF(KWSYS_USE_SystemTools)
     "Checking whether CXX compiler has utimes" DIRECT)
   KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_UTIMENSAT
     "Checking whether CXX compiler has utimensat" DIRECT)
+  KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_STAT_HAS_ST_MTIM
+    "Checking whether CXX compiler struct stat has st_mtim member" DIRECT)
+  KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_STAT_HAS_ST_MTIMESPEC
+    "Checking whether CXX compiler struct stat has st_mtimespec member" DIRECT)
   SET_PROPERTY(SOURCE SystemTools.cxx APPEND PROPERTY COMPILE_DEFINITIONS
     KWSYS_CXX_HAS_SETENV=${KWSYS_CXX_HAS_SETENV}
     KWSYS_CXX_HAS_UNSETENV=${KWSYS_CXX_HAS_UNSETENV}
     KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=${KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H}
     KWSYS_CXX_HAS_UTIMES=${KWSYS_CXX_HAS_UTIMES}
     KWSYS_CXX_HAS_UTIMENSAT=${KWSYS_CXX_HAS_UTIMENSAT}
+    KWSYS_CXX_STAT_HAS_ST_MTIM=${KWSYS_CXX_STAT_HAS_ST_MTIM}
+    KWSYS_CXX_STAT_HAS_ST_MTIMESPEC=${KWSYS_CXX_STAT_HAS_ST_MTIMESPEC}
     )
 ENDIF()
 
@@ -748,7 +685,7 @@ ENDFOREACH()
 
 # Add selected C components.
 FOREACH(c
-    Process Base64 Encoding FundamentalType MD5 Terminal System String CPU
+    Process Base64 Encoding MD5 Terminal System String
     )
   IF(KWSYS_USE_${c})
     # Use the corresponding header file.
diff --git a/Source/kwsys/CPU.h.in b/Source/kwsys/CPU.h.in
deleted file mode 100644
index 66ffbb1..0000000
--- a/Source/kwsys/CPU.h.in
+++ /dev/null
@@ -1,141 +0,0 @@
-/*============================================================================
-  KWSys - Kitware System Library
-  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
-
-  Distributed under the OSI-approved BSD License (the "License");
-  see accompanying file Copyright.txt for details.
-
-  This software is distributed WITHOUT ANY WARRANTY; without even the
-  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-  See the License for more information.
-============================================================================*/
-#ifndef @KWSYS_NAMESPACE at _CPU_h
-#define @KWSYS_NAMESPACE at _CPU_h
-
-#include <@KWSYS_NAMESPACE@/Configure.h>
-
-/* Identify possible endian cases.  The macro
-   @KWSYS_NAMESPACE at _CPU_ENDIAN_ID will be defined to one of these, or
-   0 if unknown.  */
-#define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG    4321
-#define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_LITTLE 1234
-
-/* Apple always defines one of these.  */
-#if defined(__LITTLE_ENDIAN__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_LITTLE
-#elif defined(__BIG_ENDIAN__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-
-/* Alpha */
-#elif defined(__alpha) || defined(__alpha__) || defined(_M_ALPHA)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_LITTLE
-
-/* Arm */
-#elif defined(__arm__)
-# if !defined(__ARMEB__)
-#  define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_LITTLE
-# else
-#  define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-# endif
-
-/* Intel x86 */
-#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_LITTLE
-#elif defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_LITTLE
-#elif defined(__MWERKS__) && defined(__INTEL__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_LITTLE
-
-/* Intel x86-64 */
-#elif defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_LITTLE
-#elif defined(__amd64) || defined(__amd64__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_LITTLE
-
-/* Intel Architecture-64 (Itanium) */
-#elif defined(__ia64) || defined(__ia64__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_LITTLE
-#elif defined(_IA64) || defined(__IA64__) || defined(_M_IA64)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_LITTLE
-
-/* PowerPC */
-#elif defined(__powerpc) || defined(__powerpc__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-#elif defined(__ppc) || defined(__ppc__) || defined(__POWERPC__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-
-/* SPARC */
-#elif defined(__sparc) || defined(__sparc__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-
-/* HP/PA RISC */
-#elif defined(__hppa) || defined(__hppa__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-
-/* Motorola 68k */
-#elif defined(__m68k__) || defined(M68000)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-
-/* MIPSel (MIPS little endian) */
-#elif defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_LITTLE
-
-/* MIPSeb (MIPS big endian) */
-#elif defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-
-/* MIPS (fallback, big endian) */
-#elif defined(__mips) || defined(__mips__) || defined(__MIPS__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-
-/* NIOS2 */
-#elif defined(__NIOS2__) || defined(__NIOS2) || defined(__nios2__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_LITTLE
-
-/* OpenRISC 1000 */
-#elif defined(__or1k__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-
-/* RS/6000 */
-#elif defined(__THW_RS600) || defined(_IBMR2) || defined(_POWER)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-#elif defined(_ARCH_PWR) || defined(_ARCH_PWR2)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-
-/* System/370 */
-#elif defined(__370__) || defined(__THW_370__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-
-/* System/390 */
-#elif defined(__s390__) || defined(__s390x__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-
-/* z/Architecture */
-#elif defined(__SYSC_ZARCH__)
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-
-/* Aarch64 */
-#elif defined(__aarch64__)
-# if !defined(__AARCH64EB__)
-#  define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_LITTLE
-# else
-#  define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-# endif
-
-/* Unknown CPU */
-#else
-# define @KWSYS_NAMESPACE at _CPU_ENDIAN_ID 0
-# if !defined(@KWSYS_NAMESPACE at _CPU_UNKNOWN_OKAY)
-#  error "The target CPU architecture is not known."
-# endif
-#endif
-
-/* If building a C or C++ file in kwsys itself, give the source file
-   access to the macros without a configured namespace.  */
-#if defined(KWSYS_NAMESPACE)
-# define KWSYS_CPU_ENDIAN_ID        @KWSYS_NAMESPACE at _CPU_ENDIAN_ID
-# define KWSYS_CPU_ENDIAN_ID_BIG    @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_BIG
-# define KWSYS_CPU_ENDIAN_ID_LITTLE @KWSYS_NAMESPACE at _CPU_ENDIAN_ID_LITTLE
-#endif
-
-#endif
diff --git a/Source/kwsys/Configure.h.in b/Source/kwsys/Configure.h.in
index 70cf844..cd2d965 100644
--- a/Source/kwsys/Configure.h.in
+++ b/Source/kwsys/Configure.h.in
@@ -115,6 +115,11 @@
 #  pragma warning (disable: 4710) /* function not inlined */
 #  pragma warning (disable: 4786) /* identifier truncated in debug info */
 # endif
+# if defined(__BORLANDC__) && !defined(__cplusplus)
+   /* Code has no effect; raised by winnt.h in C (not C++) when ignoring an
+      unused parameter using "(param)" syntax (i.e. no cast to void).  */
+#  pragma warn -8019
+# endif
 #endif
 
 /* MSVC 6.0 in release mode will warn about code it produces with its
diff --git a/Source/kwsys/Configure.hxx.in b/Source/kwsys/Configure.hxx.in
index 3faf862..ff8e49d 100644
--- a/Source/kwsys/Configure.hxx.in
+++ b/Source/kwsys/Configure.hxx.in
@@ -18,9 +18,6 @@
 /* Whether wstring is available.  */
 #define @KWSYS_NAMESPACE at _STL_HAS_WSTRING @KWSYS_STL_HAS_WSTRING@
 
-/* Whether struct stat has the st_mtim member for high resolution times.  */
-#define @KWSYS_NAMESPACE at _STAT_HAS_ST_MTIM @KWSYS_STAT_HAS_ST_MTIM@
-
 /* If building a C++ file in kwsys itself, give the source file
    access to the macros without a configured namespace.  */
 #if defined(KWSYS_NAMESPACE)
@@ -28,7 +25,6 @@
 #  define kwsys     @KWSYS_NAMESPACE@
 # endif
 # define KWSYS_NAME_IS_KWSYS            @KWSYS_NAMESPACE at _NAME_IS_KWSYS
-# define KWSYS_STAT_HAS_ST_MTIM         @KWSYS_NAMESPACE at _STAT_HAS_ST_MTIM
 # define KWSYS_STL_HAS_WSTRING          @KWSYS_NAMESPACE at _STL_HAS_WSTRING
 #endif
 
diff --git a/Source/kwsys/EncodingCXX.cxx b/Source/kwsys/EncodingCXX.cxx
index 7d9b3e4..597d4bd 100644
--- a/Source/kwsys/EncodingCXX.cxx
+++ b/Source/kwsys/EncodingCXX.cxx
@@ -38,6 +38,7 @@
 // Windows API.
 #if defined(_WIN32)
 # include <windows.h>
+# include <shellapi.h>
 #endif
 
 namespace KWSYS_NAMESPACE
diff --git a/Source/kwsys/FStream.cxx b/Source/kwsys/FStream.cxx
index 018652c..5a30997 100644
--- a/Source/kwsys/FStream.cxx
+++ b/Source/kwsys/FStream.cxx
@@ -34,6 +34,7 @@ BOM ReadBOM(std::istream& in)
   in.read(reinterpret_cast<char*>(bom), 2);
   if(!in.good())
     {
+    in.clear();
     in.seekg(orig);
     return BOM_None;
     }
@@ -68,6 +69,7 @@ BOM ReadBOM(std::istream& in)
     in.seekg(p);
     return BOM_UTF16LE;
     }
+  in.clear();
   in.seekg(orig);
   return BOM_None;
 }
diff --git a/Source/kwsys/FundamentalType.h.in b/Source/kwsys/FundamentalType.h.in
deleted file mode 100644
index ff20063..0000000
--- a/Source/kwsys/FundamentalType.h.in
+++ /dev/null
@@ -1,146 +0,0 @@
-/*============================================================================
-  KWSys - Kitware System Library
-  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
-
-  Distributed under the OSI-approved BSD License (the "License");
-  see accompanying file Copyright.txt for details.
-
-  This software is distributed WITHOUT ANY WARRANTY; without even the
-  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-  See the License for more information.
-============================================================================*/
-#ifndef @KWSYS_NAMESPACE at _FundamentalType_h
-#define @KWSYS_NAMESPACE at _FundamentalType_h
-
-#include <@KWSYS_NAMESPACE@/Configure.h>
-
-/* Redefine all public interface symbol names to be in the proper
-   namespace.  These macros are used internally to kwsys only, and are
-   not visible to user code.  Use kwsysHeaderDump.pl to reproduce
-   these macros after making changes to the interface.  */
-#if !defined(KWSYS_NAMESPACE)
-# define kwsys_ns(x) @KWSYS_NAMESPACE@##x
-# define kwsysEXPORT @KWSYS_NAMESPACE at _EXPORT
-#endif
-
-#if !@KWSYS_NAMESPACE at _NAME_IS_KWSYS
-# define kwsysFundamentalType        kwsys_ns(FundamentalType)
-# define kwsysFundamentalType_Int8   kwsys_ns(FundamentalType_Int8)
-# define kwsysFundamentalType_UInt8  kwsys_ns(FundamentalType_UInt8)
-# define kwsysFundamentalType_Int16  kwsys_ns(FundamentalType_Int16)
-# define kwsysFundamentalType_UInt16 kwsys_ns(FundamentalType_UInt16)
-# define kwsysFundamentalType_Int32  kwsys_ns(FundamentalType_Int32)
-# define kwsysFundamentalType_UInt32 kwsys_ns(FundamentalType_UInt32)
-# define kwsysFundamentalType_Int64  kwsys_ns(FundamentalType_Int64)
-# define kwsysFundamentalType_UInt64 kwsys_ns(FundamentalType_UInt64)
-#endif
-
-/* The size of fundamental types.  Types that do not exist have size 0.  */
- at KWSYS_C_CODE_SIZEOF_CHAR@
- at KWSYS_C_CODE_SIZEOF_SHORT@
- at KWSYS_C_CODE_SIZEOF_INT@
- at KWSYS_C_CODE_SIZEOF_LONG@
- at KWSYS_C_CODE_SIZEOF_LONG_LONG@
- at KWSYS_C_CODE_SIZEOF___INT64@
-
-/* Whether types "long long" and "__int64" are enabled.  If a type is
-   enabled then it is a unique fundamental type.  */
-#define @KWSYS_NAMESPACE at _USE_LONG_LONG @KWSYS_USE_LONG_LONG@
-#define @KWSYS_NAMESPACE at _USE___INT64 @KWSYS_USE___INT64@
-
-/* Whether type "char" is signed (it may be signed or unsigned).  */
-#define @KWSYS_NAMESPACE at _CHAR_IS_SIGNED @KWSYS_CHAR_IS_SIGNED@
-
-#if defined(__cplusplus)
-extern "C"
-{
-#endif
-
-/* Select an 8-bit integer type.  */
-#if @KWSYS_NAMESPACE at _SIZEOF_CHAR == 1
-typedef signed char kwsysFundamentalType_Int8;
-typedef unsigned char kwsysFundamentalType_UInt8;
-#else
-# error "No native data type can represent an 8-bit integer."
-#endif
-
-/* Select a 16-bit integer type.  */
-#if @KWSYS_NAMESPACE at _SIZEOF_SHORT == 2
-typedef short kwsysFundamentalType_Int16;
-typedef unsigned short kwsysFundamentalType_UInt16;
-#elif @KWSYS_NAMESPACE at _SIZEOF_INT == 2
-typedef int kwsysFundamentalType_Int16;
-typedef unsigned int kwsysFundamentalType_UInt16;
-#else
-# error "No native data type can represent a 16-bit integer."
-#endif
-
-/* Select a 32-bit integer type.  */
-#if @KWSYS_NAMESPACE at _SIZEOF_INT == 4
-typedef int kwsysFundamentalType_Int32;
-typedef unsigned int kwsysFundamentalType_UInt32;
-#elif @KWSYS_NAMESPACE at _SIZEOF_LONG == 4
-typedef long kwsysFundamentalType_Int32;
-typedef unsigned long kwsysFundamentalType_UInt32;
-#else
-# error "No native data type can represent a 32-bit integer."
-#endif
-
-/* Select a 64-bit integer type.  */
-#if @KWSYS_NAMESPACE at _SIZEOF_LONG == 8
-typedef signed long   kwsysFundamentalType_Int64;
-typedef unsigned long kwsysFundamentalType_UInt64;
-/* Whether UInt64 can be converted to double.  */
-# define @KWSYS_NAMESPACE at _CAN_CONVERT_UI64_TO_DOUBLE 1
-#elif @KWSYS_NAMESPACE at _USE_LONG_LONG && @KWSYS_NAMESPACE at _SIZEOF_LONG_LONG == 8
-typedef signed long long   kwsysFundamentalType_Int64;
-typedef unsigned long long kwsysFundamentalType_UInt64;
-/* Whether UInt64 can be converted to double.  */
-# define @KWSYS_NAMESPACE at _CAN_CONVERT_UI64_TO_DOUBLE 1
-#elif @KWSYS_NAMESPACE at _USE___INT64 && @KWSYS_NAMESPACE at _SIZEOF___INT64 == 8
-typedef signed __int64   kwsysFundamentalType_Int64;
-typedef unsigned __int64 kwsysFundamentalType_UInt64;
-/* Whether UInt64 can be converted to double.  */
-# define @KWSYS_NAMESPACE at _CAN_CONVERT_UI64_TO_DOUBLE @KWSYS_CAN_CONVERT_UI64_TO_DOUBLE@
-#else
-# error "No native data type can represent a 64-bit integer."
-#endif
-
-#if defined(__cplusplus)
-} /* extern "C" */
-#endif
-
-/* If we are building a kwsys .c or .cxx file, let it use these macros.
-   Otherwise, undefine them to keep the namespace clean.  */
-#if !defined(KWSYS_NAMESPACE)
-# undef kwsys_ns
-# undef kwsysEXPORT
-# if !defined(KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE at _NAME_IS_KWSYS
-#  undef kwsysFundamentalType
-#  undef kwsysFundamentalType_Int8
-#  undef kwsysFundamentalType_UInt8
-#  undef kwsysFundamentalType_Int16
-#  undef kwsysFundamentalType_UInt16
-#  undef kwsysFundamentalType_Int32
-#  undef kwsysFundamentalType_UInt32
-#  undef kwsysFundamentalType_Int64
-#  undef kwsysFundamentalType_UInt64
-# endif
-#endif
-
-/* If building a C or C++ file in kwsys itself, give the source file
-   access to the configured macros without a configured namespace.  */
-#if defined(KWSYS_NAMESPACE)
-# define KWSYS_SIZEOF_CHAR @KWSYS_NAMESPACE at _SIZEOF_CHAR
-# define KWSYS_SIZEOF_SHORT @KWSYS_NAMESPACE at _SIZEOF_SHORT
-# define KWSYS_SIZEOF_INT @KWSYS_NAMESPACE at _SIZEOF_INT
-# define KWSYS_SIZEOF_LONG @KWSYS_NAMESPACE at _SIZEOF_LONG
-# define KWSYS_SIZEOF_LONG_LONG @KWSYS_NAMESPACE at _SIZEOF_LONG_LONG
-# define KWSYS_SIZEOF___INT64 @KWSYS_NAMESPACE at _SIZEOF___INT64
-# define KWSYS_USE_LONG_LONG @KWSYS_NAMESPACE at _USE_LONG_LONG
-# define KWSYS_USE___INT64 @KWSYS_NAMESPACE at _USE___INT64
-# define KWSYS_CHAR_IS_SIGNED @KWSYS_NAMESPACE at _CHAR_IS_SIGNED
-# define KWSYS_CAN_CONVERT_UI64_TO_DOUBLE @KWSYS_NAMESPACE at _CAN_CONVERT_UI64_TO_DOUBLE
-#endif
-
-#endif
diff --git a/Source/kwsys/MD5.c b/Source/kwsys/MD5.c
index a147057..b9d25a8 100644
--- a/Source/kwsys/MD5.c
+++ b/Source/kwsys/MD5.c
@@ -29,7 +29,7 @@
    it in a single source file instead of a separate header and
    implementation file.  */
 
-#if defined(__clang__)
+#if defined(__clang__) && !defined(__INTEL_COMPILER)
 # pragma clang diagnostic push
 # pragma clang diagnostic ignored "-Wcast-align"
 #endif
@@ -433,7 +433,7 @@ static void md5_finish(md5_state_t *pms, md5_byte_t digest[16])
         digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
 }
 
-#if defined(__clang__)
+#if defined(__clang__) && !defined(__INTEL_COMPILER)
 # pragma clang diagnostic pop
 #endif
 
diff --git a/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c
index 6d9b109..07c644b 100644
--- a/Source/kwsys/ProcessUNIX.c
+++ b/Source/kwsys/ProcessUNIX.c
@@ -1595,12 +1595,12 @@ static void kwsysProcessVolatileFree(volatile void* p)
 {
   /* clang has made it impossible to free memory that points to volatile
      without first using special pragmas to disable a warning...  */
-#if defined(__clang__)
+#if defined(__clang__) && !defined(__INTEL_COMPILER)
 # pragma clang diagnostic push
 # pragma clang diagnostic ignored "-Wcast-qual"
 #endif
   free((void*)p); /* The cast will silence most compilers, but not clang.  */
-#if defined(__clang__)
+#if defined(__clang__) && !defined(__INTEL_COMPILER)
 # pragma clang diagnostic pop
 #endif
 }
@@ -2241,7 +2241,7 @@ static kwsysProcessTime kwsysProcessTimeAdd(kwsysProcessTime in1, kwsysProcessTi
   kwsysProcessTime out;
   out.tv_sec = in1.tv_sec + in2.tv_sec;
   out.tv_usec = in1.tv_usec + in2.tv_usec;
-  if(out.tv_usec > 1000000)
+  if(out.tv_usec >= 1000000)
     {
     out.tv_usec -= 1000000;
     out.tv_sec += 1;
diff --git a/Source/kwsys/SharedForward.h.in b/Source/kwsys/SharedForward.h.in
index f22fa58..f80ef84 100644
--- a/Source/kwsys/SharedForward.h.in
+++ b/Source/kwsys/SharedForward.h.in
@@ -74,6 +74,12 @@
 # endif
 #endif
 
+#if defined(__BORLANDC__) && !defined(__cplusplus)
+  /* Code has no effect; raised by winnt.h in C (not C++) when ignoring an
+     unused parameter using "(param)" syntax (i.e. no cast to void).  */
+# pragma warn -8019
+#endif
+
 /*--------------------------------------------------------------------------*/
 
 /* Full path to the directory in which this executable is built.  Do
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 262af27..e3428f8 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -1366,15 +1366,18 @@ bool SystemTools::Touch(const std::string& filename, bool create)
   struct timeval mtime;
   gettimeofday(&mtime, 0);
 # if KWSYS_CXX_HAS_UTIMES
-  struct timeval times[2] =
-    {
-#  if KWSYS_STAT_HAS_ST_MTIM
-      {st.st_atim.tv_sec, st.st_atim.tv_nsec/1000}, /* tv_sec, tv_usec */
+  struct timeval atime;
+#  if KWSYS_CXX_STAT_HAS_ST_MTIM
+  atime.tv_sec = st.st_atim.tv_sec;
+  atime.tv_usec = st.st_atim.tv_nsec/1000;
+#  elif KWSYS_CXX_STAT_HAS_ST_MTIMESPEC
+  atime.tv_sec = st.st_atimespec.tv_sec;
+  atime.tv_usec = st.st_atimespec.tv_nsec/1000;
 #  else
-      {st.st_atime, 0},
+  atime.tv_sec = st.st_atime;
+  atime.tv_usec = 0;
 #  endif
-      mtime
-    };
+  struct timeval times[2] = { atime, mtime };
   if(utimes(filename.c_str(), times) < 0)
     {
     return false;
@@ -1408,7 +1411,7 @@ bool SystemTools::FileTimeCompare(const std::string& f1,
     {
     return false;
     }
-# if KWSYS_STAT_HAS_ST_MTIM
+# if KWSYS_CXX_STAT_HAS_ST_MTIM
   // Compare using nanosecond resolution.
   if(s1.st_mtim.tv_sec < s2.st_mtim.tv_sec)
     {
@@ -1426,6 +1429,24 @@ bool SystemTools::FileTimeCompare(const std::string& f1,
     {
     *result = 1;
     }
+# elif KWSYS_CXX_STAT_HAS_ST_MTIMESPEC
+  // Compare using nanosecond resolution.
+  if(s1.st_mtimespec.tv_sec < s2.st_mtimespec.tv_sec)
+    {
+    *result = -1;
+    }
+  else if(s1.st_mtimespec.tv_sec > s2.st_mtimespec.tv_sec)
+    {
+    *result = 1;
+    }
+  else if(s1.st_mtimespec.tv_nsec < s2.st_mtimespec.tv_nsec)
+    {
+    *result = -1;
+    }
+  else if(s1.st_mtimespec.tv_nsec > s2.st_mtimespec.tv_nsec)
+    {
+    *result = 1;
+    }
 # else
   // Compare using 1 second resolution.
   if(s1.st_mtime < s2.st_mtime)
@@ -2381,8 +2402,7 @@ bool SystemTools::CopyFileAlways(const std::string& source, const std::string& d
     // name as the source in that directory.
 
     std::string destination_dir;
-    if(SystemTools::FileExists(destination) &&
-       SystemTools::FileIsDirectory(destination))
+    if(SystemTools::FileIsDirectory(destination))
       {
       destination_dir = real_destination;
       SystemTools::ConvertToUnixSlashes(real_destination);
@@ -2948,42 +2968,36 @@ std::string SystemTools::FindProgram(
   const std::vector<std::string>& userPaths,
   bool no_system_path)
 {
-  std::vector<std::string> extensions;
+  std::string tryPath;
+
 #if defined (_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
-  bool hasExtension = false;
+  std::vector<std::string> extensions;
   // check to see if the name already has a .xxx at
   // the end of it
-  if(name.size() > 3 && name[name.size()-4] == '.')
-    {
-    hasExtension = true;
-    }
   // on windows try .com then .exe
-  if(!hasExtension)
+  if(name.size() <= 3 || name[name.size()-4] != '.')
     {
     extensions.push_back(".com");
     extensions.push_back(".exe");
-    }
-#endif
-  std::string tryPath;
 
-  // first try with extensions if the os supports them
-  for(std::vector<std::string>::iterator i =
-        extensions.begin(); i != extensions.end(); ++i)
-    {
-    tryPath = name;
-    tryPath += *i;
-    if(SystemTools::FileExists(tryPath) &&
-        !SystemTools::FileIsDirectory(tryPath))
+    // first try with extensions if the os supports them
+    for(std::vector<std::string>::iterator i =
+          extensions.begin(); i != extensions.end(); ++i)
       {
-      return SystemTools::CollapseFullPath(tryPath);
+      tryPath = name;
+      tryPath += *i;
+      if(SystemTools::FileExists(tryPath, true))
+        {
+        return SystemTools::CollapseFullPath(tryPath);
+        }
       }
     }
+#endif
+
   // now try just the name
-  tryPath = name;
-  if(SystemTools::FileExists(tryPath) &&
-     !SystemTools::FileIsDirectory(tryPath))
+  if(SystemTools::FileExists(name, true))
     {
-    return SystemTools::CollapseFullPath(tryPath);
+    return SystemTools::CollapseFullPath(name);
     }
   // now construct the path
   std::vector<std::string> path;
@@ -3020,6 +3034,7 @@ std::string SystemTools::FindProgram(
     // Remove double quotes from the path on windows
     SystemTools::ReplaceString(*p, "\"", "");
 #endif
+#if defined (_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
     // first try with extensions
     for(std::vector<std::string>::iterator ext
           = extensions.begin(); ext != extensions.end(); ++ext)
@@ -3027,17 +3042,16 @@ std::string SystemTools::FindProgram(
       tryPath = *p;
       tryPath += name;
       tryPath += *ext;
-      if(SystemTools::FileExists(tryPath) &&
-          !SystemTools::FileIsDirectory(tryPath))
+      if(SystemTools::FileExists(tryPath, true))
         {
         return SystemTools::CollapseFullPath(tryPath);
         }
       }
+#endif
     // now try it without them
     tryPath = *p;
     tryPath += name;
-    if(SystemTools::FileExists(tryPath) &&
-       !SystemTools::FileIsDirectory(tryPath))
+    if(SystemTools::FileExists(tryPath, true))
       {
       return SystemTools::CollapseFullPath(tryPath);
       }
@@ -3076,8 +3090,7 @@ std::string SystemTools
               const std::vector<std::string>& userPaths)
 {
   // See if the executable exists as written.
-  if(SystemTools::FileExists(name) &&
-     !SystemTools::FileIsDirectory(name))
+  if(SystemTools::FileExists(name, true))
     {
     return SystemTools::CollapseFullPath(name);
     }
@@ -3113,8 +3126,7 @@ std::string SystemTools
     tryPath = *p;
     tryPath += name;
     tryPath += ".framework";
-    if(SystemTools::FileExists(tryPath)
-       && SystemTools::FileIsDirectory(tryPath))
+    if(SystemTools::FileIsDirectory(tryPath))
       {
       return SystemTools::CollapseFullPath(tryPath);
       }
@@ -3123,8 +3135,7 @@ std::string SystemTools
     tryPath = *p;
     tryPath += name;
     tryPath += ".lib";
-    if(SystemTools::FileExists(tryPath)
-       && !SystemTools::FileIsDirectory(tryPath))
+    if(SystemTools::FileExists(tryPath, true))
       {
       return SystemTools::CollapseFullPath(tryPath);
       }
@@ -3133,8 +3144,7 @@ std::string SystemTools
     tryPath += "lib";
     tryPath += name;
     tryPath += ".so";
-    if(SystemTools::FileExists(tryPath)
-       && !SystemTools::FileIsDirectory(tryPath))
+    if(SystemTools::FileExists(tryPath, true))
       {
       return SystemTools::CollapseFullPath(tryPath);
       }
@@ -3142,8 +3152,7 @@ std::string SystemTools
     tryPath += "lib";
     tryPath += name;
     tryPath += ".a";
-    if(SystemTools::FileExists(tryPath)
-       && !SystemTools::FileIsDirectory(tryPath))
+    if(SystemTools::FileExists(tryPath, true))
       {
       return SystemTools::CollapseFullPath(tryPath);
       }
@@ -3151,8 +3160,7 @@ std::string SystemTools
     tryPath += "lib";
     tryPath += name;
     tryPath += ".sl";
-    if(SystemTools::FileExists(tryPath)
-       && !SystemTools::FileIsDirectory(tryPath))
+    if(SystemTools::FileExists(tryPath, true))
       {
       return SystemTools::CollapseFullPath(tryPath);
       }
@@ -3160,8 +3168,7 @@ std::string SystemTools
     tryPath += "lib";
     tryPath += name;
     tryPath += ".dylib";
-    if(SystemTools::FileExists(tryPath)
-       && !SystemTools::FileIsDirectory(tryPath))
+    if(SystemTools::FileExists(tryPath, true))
       {
       return SystemTools::CollapseFullPath(tryPath);
       }
@@ -3169,8 +3176,7 @@ std::string SystemTools
     tryPath += "lib";
     tryPath += name;
     tryPath += ".dll";
-    if(SystemTools::FileExists(tryPath)
-       && !SystemTools::FileIsDirectory(tryPath))
+    if(SystemTools::FileExists(tryPath, true))
       {
       return SystemTools::CollapseFullPath(tryPath);
       }
@@ -4485,36 +4491,27 @@ bool SystemTools::FileIsFullPath(const char* in_name, size_t len)
 bool SystemTools::GetShortPath(const std::string& path, std::string& shortPath)
 {
 #if defined(_WIN32) && !defined(__CYGWIN__)
-  const int size = int(path.size()) +1; // size of return
-  char *tempPath = new char[size];  // create a buffer
-  DWORD ret;
+  std::string tempPath = path;  // create a buffer
 
   // if the path passed in has quotes around it, first remove the quotes
   if (!path.empty() && path[0] == '"' && *path.rbegin() == '"')
     {
-    strcpy(tempPath,path.c_str()+1);
-    tempPath[size-2] = '\0';
-    }
-  else
-    {
-    strcpy(tempPath,path.c_str());
+    tempPath = path.substr(1, path.length()-2);
     }
 
   std::wstring wtempPath = Encoding::ToWide(tempPath);
-  std::vector<wchar_t> buffer(wtempPath.size()+1);
-  buffer[0] = 0;
+  DWORD ret = GetShortPathNameW(wtempPath.c_str(), NULL, 0);
+  std::vector<wchar_t> buffer(ret);
   ret = GetShortPathNameW(wtempPath.c_str(),
-    &buffer[0], static_cast<DWORD>(wtempPath.size()));
+                          &buffer[0], static_cast<DWORD>(buffer.size()));
 
-  if(buffer[0] == 0 || ret > wtempPath.size())
+  if (ret == 0)
     {
-    delete [] tempPath;
     return false;
     }
   else
     {
     shortPath = Encoding::ToNarrow(&buffer[0]);
-    delete [] tempPath;
     return true;
     }
 #else
diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in
index d2d1d40..bba5a5c 100644
--- a/Source/kwsys/SystemTools.hxx.in
+++ b/Source/kwsys/SystemTools.hxx.in
@@ -703,13 +703,13 @@ public:
 
   /**
    * Create a symbolic link if the platform supports it.  Returns whether
-   * creation succeded.
+   * creation succeeded.
    */
   static bool CreateSymlink(const std::string& origName, const std::string& newName);
 
   /**
    * Read the contents of a symbolic link.  Returns whether reading
-   * succeded.
+   * succeeded.
    */
   static bool ReadSymlink(const std::string& newName, std::string& origName);
 
diff --git a/Source/kwsys/Terminal.c b/Source/kwsys/Terminal.c
index d13f79a..a8abb6c 100644
--- a/Source/kwsys/Terminal.c
+++ b/Source/kwsys/Terminal.c
@@ -184,14 +184,25 @@ static const char* kwsysTerminalVT100Names[] =
 static int kwsysTerminalStreamIsVT100(FILE* stream, int default_vt100,
                                       int default_tty)
 {
+  /* Force color according to http://bixense.com/clicolors/ convention.  */
+  {
+  const char* clicolor_force = getenv("CLICOLOR_FORCE");
+  if (clicolor_force && *clicolor_force && strcmp(clicolor_force, "0") != 0)
+    {
+    return 1;
+    }
+  }
+
   /* If running inside emacs the terminal is not VT100.  Some emacs
      seem to claim the TERM is xterm even though they do not support
      VT100 escapes.  */
+  {
   const char* emacs = getenv("EMACS");
   if(emacs && *emacs == 't')
     {
     return 0;
     }
+  }
 
   /* Check for a valid terminal.  */
   if(!default_vt100)
diff --git a/Source/kwsys/kwsysPlatformTestsCXX.cxx b/Source/kwsys/kwsysPlatformTestsCXX.cxx
index 94579b3..fc87f91 100644
--- a/Source/kwsys/kwsysPlatformTestsCXX.cxx
+++ b/Source/kwsys/kwsysPlatformTestsCXX.cxx
@@ -32,7 +32,7 @@ int main()
 }
 #endif
 
-#ifdef TEST_KWSYS_STAT_HAS_ST_MTIM
+#ifdef TEST_KWSYS_CXX_STAT_HAS_ST_MTIM
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -45,18 +45,21 @@ int main()
 }
 #endif
 
-#ifdef TEST_KWSYS_CXX_SAME_LONG_AND___INT64
-void function(long**) {}
+#ifdef TEST_KWSYS_CXX_STAT_HAS_ST_MTIMESPEC
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 int main()
 {
-  __int64** p = 0;
-  function(p);
+  struct stat stat1;
+  (void)stat1.st_mtimespec.tv_sec;
+  (void)stat1.st_mtimespec.tv_nsec;
   return 0;
 }
 #endif
 
-#ifdef TEST_KWSYS_CXX_SAME_LONG_LONG_AND___INT64
-void function(long long**) {}
+#ifdef TEST_KWSYS_CXX_SAME_LONG_AND___INT64
+void function(long**) {}
 int main()
 {
   __int64** p = 0;
@@ -65,17 +68,12 @@ int main()
 }
 #endif
 
-#ifdef TEST_KWSYS_CAN_CONVERT_UI64_TO_DOUBLE
-void function(double& l, unsigned __int64 const& r)
-{
-  l = static_cast<double>(r);
-}
-
+#ifdef TEST_KWSYS_CXX_SAME_LONG_LONG_AND___INT64
+void function(long long**) {}
 int main()
 {
-  double tTo = 0.0;
-  unsigned __int64 tFrom = 0;
-  function(tTo, tFrom);
+  __int64** p = 0;
+  function(p);
   return 0;
 }
 #endif
@@ -132,15 +130,6 @@ int main()
 }
 #endif
 
-#ifdef TEST_KWSYS_CHAR_IS_SIGNED
-/* Return 0 for char signed and 1 for char unsigned.  */
-int main()
-{
-  unsigned char uc = 255;
-  return (*reinterpret_cast<char*>(&uc) < 0)?0:1;
-}
-#endif
-
 #ifdef TEST_KWSYS_LFS_WORKS
 /* Return 0 when LFS is available and 1 otherwise.  */
 #define _LARGEFILE_SOURCE
@@ -328,93 +317,6 @@ int main()
 }
 #endif
 
-#ifdef TEST_KWSYS_CXX_TYPE_INFO
-/* Collect fundamental type information and save it to a CMake script.  */
-
-/* Include limits.h to get macros indicating long long and __int64.
-   Note that certain compilers need special macros to define these
-   macros in limits.h.  */
-#if defined(_MSC_VER) && !defined(_MSC_EXTENSIONS)
-# define _MSC_EXTENSIONS
-#endif
-#if defined(__GNUC__) && __GNUC__ < 3
-# define _GNU_SOURCE
-#endif
-#include <limits.h>
-
-#include <stdio.h>
-#include <string.h>
-
-/* Due to shell differences and limitations of ADD_DEFINITIONS the
-   KWSYS_CXX_TYPE_INFO_FILE macro will sometimes have double quotes
-   and sometimes not.  This macro will make sure the value is treated
-   as a double-quoted string.  */
-#define TO_STRING(x) TO_STRING0(x)
-#define TO_STRING0(x) TO_STRING1(x)
-#define TO_STRING1(x) #x
-
-void f() {}
-
-int main()
-{
-  /* Construct the output file name.  Some preprocessors will add an
-     extra level of double quotes, so strip them.  */
-  char fbuf[] = TO_STRING(KWSYS_CXX_TYPE_INFO_FILE);
-  char* fname = fbuf;
-  if(fname[0] == '"')
-    {
-    ++fname;
-    int len = static_cast<int>(strlen(fname));
-    if(len > 0 && fname[len-1] == '"')
-      {
-      fname[len-1] = 0;
-      }
-    }
-
-  /* Try to open the output file.  */
-  if(FILE* fout = fopen(fname, "w"))
-    {
-    /* Set the size of standard types.  */
-    fprintf(fout, "SET(KWSYS_SIZEOF_CHAR %d)\n", static_cast<int>(sizeof(char)));
-    fprintf(fout, "SET(KWSYS_SIZEOF_SHORT %d)\n", static_cast<int>(sizeof(short)));
-    fprintf(fout, "SET(KWSYS_SIZEOF_INT %d)\n", static_cast<int>(sizeof(int)));
-    fprintf(fout, "SET(KWSYS_SIZEOF_LONG %d)\n", static_cast<int>(sizeof(long)));
-
-    /* Set the size of some non-standard but common types.  */
-    /* Check for a limits.h macro for long long to see if the type exists.  */
-#if defined(LLONG_MAX) || defined(LONG_LONG_MAX) || defined(LONGLONG_MAX)
-    fprintf(fout, "SET(KWSYS_SIZEOF_LONG_LONG %d)\n", static_cast<int>(sizeof(long long)));
-#else
-    fprintf(fout, "SET(KWSYS_SIZEOF_LONG_LONG 0) # No long long available.\n");
-#endif
-    /* Check for a limits.h macro for __int64 to see if the type exists.  */
-#if defined(_I64_MIN)
-    fprintf(fout, "SET(KWSYS_SIZEOF___INT64 %d)\n", static_cast<int>(sizeof(__int64)));
-#else
-    fprintf(fout, "SET(KWSYS_SIZEOF___INT64 0) # No __int64 available.\n");
-#endif
-
-    /* Set the size of some pointer types.  */
-    fprintf(fout, "SET(KWSYS_SIZEOF_PDATA %d)\n", static_cast<int>(sizeof(void*)));
-    fprintf(fout, "SET(KWSYS_SIZEOF_PFUNC %d)\n", static_cast<int>(sizeof(&f)));
-
-    /* Set whether the native type "char" is signed or unsigned.  */
-    unsigned char uc = 255;
-    fprintf(fout, "SET(KWSYS_CHAR_IS_SIGNED %d)\n",
-            (*reinterpret_cast<char*>(&uc) < 0)?1:0);
-
-    fclose(fout);
-    return 0;
-    }
-  else
-    {
-    fprintf(stderr, "Failed to write fundamental type info to \"%s\".\n",
-            fname);
-    return 1;
-    }
-}
-#endif
-
 #ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM
 int main()
 {
diff --git a/Source/kwsys/testFStream.cxx b/Source/kwsys/testFStream.cxx
index ac5220a..5e53725 100644
--- a/Source/kwsys/testFStream.cxx
+++ b/Source/kwsys/testFStream.cxx
@@ -41,8 +41,13 @@ static int testNoFile()
   return 0;
 }
 
-static kwsys::FStream::BOM expected_bom[5] =
+static const int num_test_files = 7;
+static const int max_test_file_size = 45;
+
+static kwsys::FStream::BOM expected_bom[num_test_files] =
 {
+  kwsys::FStream::BOM_None,
+  kwsys::FStream::BOM_None,
   kwsys::FStream::BOM_UTF8,
   kwsys::FStream::BOM_UTF16LE,
   kwsys::FStream::BOM_UTF16BE,
@@ -50,8 +55,10 @@ static kwsys::FStream::BOM expected_bom[5] =
   kwsys::FStream::BOM_UTF32BE
 };
 
-static unsigned char expected_bom_data[5][5] =
+static unsigned char expected_bom_data[num_test_files][5] =
 {
+    {0},
+    {0},
     {3, 0xEF, 0xBB, 0xBF},
     {2, 0xFF, 0xFE},
     {2, 0xFE, 0xFF},
@@ -59,8 +66,10 @@ static unsigned char expected_bom_data[5][5] =
     {4, 0x00, 0x00, 0xFE, 0xFF},
 };
 
-static unsigned char file_data[5][45] =
+static unsigned char file_data[num_test_files][max_test_file_size] =
 {
+    {1, 'H'},
+    {11, 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'},
     {11, 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'},
     {22, 0x48, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x20, 0x00,
     0x57, 0x00, 0x6F, 0x00, 0x72, 0x00, 0x6C, 0x00, 0x64, 0x00},
@@ -80,7 +89,7 @@ static unsigned char file_data[5][45] =
 static int testBOM()
 {
   // test various encodings in binary mode
-  for(int i=0; i<5; i++)
+  for(int i=0; i<num_test_files; i++)
     {
       {
       kwsys::ofstream out("bom.txt", kwsys::ofstream::binary);
@@ -97,7 +106,7 @@ static int testBOM()
       std::cout << "Unexpected BOM " << i << std::endl;
       return 1;
       }
-    char data[45];
+    char data[max_test_file_size];
     in.read(data, file_data[i][0]);
     if(!in.good())
       {
@@ -113,66 +122,6 @@ static int testBOM()
 
     }
 
-  // test text file without bom
-  {
-    {
-    kwsys::ofstream out("bom.txt");
-    out << "Hello World";
-    }
-
-    kwsys::ifstream in("bom.txt");
-    kwsys::FStream::BOM bom = kwsys::FStream::ReadBOM(in);
-    if(bom != kwsys::FStream::BOM_None)
-      {
-      std::cout << "Unexpected BOM for none case" << std::endl;
-      return 1;
-      }
-    char data[45];
-    in.read(data, file_data[0][0]);
-    if(!in.good())
-      {
-      std::cout << "Unable to read data for none case" << std::endl;
-      return 1;
-      }
-
-    if(memcmp(data, file_data[0]+1, file_data[0][0]) != 0)
-      {
-      std::cout << "Incorrect read data for none case" << std::endl;
-      return 1;
-      }
-  }
-
-  // test text file with utf-8 bom
-  {
-    {
-    kwsys::ofstream out("bom.txt");
-    out.write(reinterpret_cast<const char*>(expected_bom_data[0]+1),
-              *expected_bom_data[0]);
-    out << "Hello World";
-    }
-
-    kwsys::ifstream in("bom.txt");
-    kwsys::FStream::BOM bom = kwsys::FStream::ReadBOM(in);
-    if(bom != kwsys::FStream::BOM_UTF8)
-      {
-      std::cout << "Unexpected BOM for utf-8 case" << std::endl;
-      return 1;
-      }
-    char data[45];
-    in.read(data, file_data[0][0]);
-    if(!in.good())
-      {
-      std::cout << "Unable to read data for utf-8 case" << std::endl;
-      return 1;
-      }
-
-    if(memcmp(data, file_data[0]+1, file_data[0][0]) != 0)
-      {
-      std::cout << "Incorrect read data for utf-8 case" << std::endl;
-      return 1;
-      }
-  }
-
   return 0;
 }
 
diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx
index a0f904f..4d97688 100644
--- a/Source/kwsys/testSystemTools.cxx
+++ b/Source/kwsys/testSystemTools.cxx
@@ -172,6 +172,63 @@ static bool CheckFileOperations()
       << testNewDir << std::endl;
     res = false;
     }
+  // calling it again should just return true
+  if (!kwsys::SystemTools::MakeDirectory(testNewDir))
+    {
+    std::cerr
+      << "Problem with second call to MakeDirectory for: "
+      << testNewDir << std::endl;
+    res = false;
+    }
+  // calling with 0 pointer should return false
+  if (kwsys::SystemTools::MakeDirectory(0))
+    {
+    std::cerr
+      << "Problem with MakeDirectory(0)"
+      << std::endl;
+    res = false;
+    }
+  // calling with an empty string should return false
+  if (kwsys::SystemTools::MakeDirectory(std::string()))
+    {
+    std::cerr
+      << "Problem with MakeDirectory(std::string())"
+      << std::endl;
+    res = false;
+    }
+  // check existence
+  if (!kwsys::SystemTools::FileExists(testNewDir.c_str(), false))
+    {
+    std::cerr
+      << "Problem with FileExists as C string and not file for: "
+      << testNewDir << std::endl;
+    res = false;
+    }
+  // remove it
+  if (!kwsys::SystemTools::RemoveADirectory(testNewDir))
+    {
+    std::cerr
+      << "Problem with RemoveADirectory for: "
+      << testNewDir << std::endl;
+    res = false;
+    }
+  // check existence
+  if (kwsys::SystemTools::FileExists(testNewDir.c_str(), false))
+    {
+    std::cerr
+      << "After RemoveADirectory: "
+      << "Problem with FileExists as C string and not file for: "
+      << testNewDir << std::endl;
+    res = false;
+    }
+  // create it using the char* version
+  if (!kwsys::SystemTools::MakeDirectory(testNewDir.c_str()))
+    {
+    std::cerr
+      << "Problem with second call to MakeDirectory as C string for: "
+      << testNewDir << std::endl;
+    res = false;
+    }
 
   if (!kwsys::SystemTools::Touch(testNewFile.c_str(), true))
     {
@@ -180,6 +237,97 @@ static bool CheckFileOperations()
       << testNewFile << std::endl;
     res = false;
     }
+  // calling MakeDirectory with something that is no file should fail
+  if (kwsys::SystemTools::MakeDirectory(testNewFile))
+    {
+    std::cerr
+      << "Problem with to MakeDirectory for: "
+      << testNewFile << std::endl;
+    res = false;
+    }
+
+  // calling with 0 pointer should return false
+  if (kwsys::SystemTools::FileExists(0))
+    {
+    std::cerr
+      << "Problem with FileExists(0)"
+      << std::endl;
+    res = false;
+    }
+  if (kwsys::SystemTools::FileExists(0, true))
+    {
+    std::cerr
+      << "Problem with FileExists(0) as file"
+      << std::endl;
+    res = false;
+    }
+  // calling with an empty string should return false
+  if (kwsys::SystemTools::FileExists(std::string()))
+    {
+    std::cerr
+      << "Problem with FileExists(std::string())"
+      << std::endl;
+    res = false;
+    }
+  // FileExists(x, true) should return false on a directory
+  if (kwsys::SystemTools::FileExists(testNewDir, true))
+    {
+    std::cerr
+      << "Problem with FileExists as file for: "
+      << testNewDir << std::endl;
+    res = false;
+    }
+  if (kwsys::SystemTools::FileExists(testNewDir.c_str(), true))
+    {
+    std::cerr
+      << "Problem with FileExists as C string and file for: "
+      << testNewDir << std::endl;
+    res = false;
+    }
+  // FileExists(x, false) should return true even on a directory
+  if (!kwsys::SystemTools::FileExists(testNewDir, false))
+    {
+    std::cerr
+      << "Problem with FileExists as not file for: "
+      << testNewDir << std::endl;
+    res = false;
+    }
+  if (!kwsys::SystemTools::FileExists(testNewDir.c_str(), false))
+    {
+    std::cerr
+      << "Problem with FileExists as C string and not file for: "
+      << testNewDir << std::endl;
+    res = false;
+    }
+  // should work, was created as new file before
+  if (!kwsys::SystemTools::FileExists(testNewFile))
+    {
+    std::cerr
+      << "Problem with FileExists for: "
+      << testNewDir << std::endl;
+    res = false;
+    }
+  if (!kwsys::SystemTools::FileExists(testNewFile.c_str()))
+    {
+    std::cerr
+      << "Problem with FileExists as C string for: "
+      << testNewDir << std::endl;
+    res = false;
+    }
+  if (!kwsys::SystemTools::FileExists(testNewFile, true))
+    {
+    std::cerr
+      << "Problem with FileExists as file for: "
+      << testNewDir << std::endl;
+    res = false;
+    }
+  if (!kwsys::SystemTools::FileExists(testNewFile.c_str(), true))
+    {
+    std::cerr
+      << "Problem with FileExists as C string and file for: "
+      << testNewDir << std::endl;
+    res = false;
+    }
 
   // Reset umask
 #if defined(_WIN32) && !defined(__CYGWIN__)
@@ -851,6 +999,44 @@ static bool CheckGetPath()
   return res;
 }
 
+static bool CheckFind()
+{
+  bool res = true;
+  const std::string testFindFileName("testFindFile.txt");
+  const std::string testFindFile(TEST_SYSTEMTOOLS_BINARY_DIR "/"
+                                 + testFindFileName);
+
+  if (!kwsys::SystemTools::Touch(testFindFile.c_str(), true))
+    {
+    std::cerr
+      << "Problem with Touch for: "
+      << testFindFile << std::endl;
+    // abort here as the existence of the file only makes the test meaningful
+    return false;
+    }
+
+  std::vector<std::string> searchPaths;
+  searchPaths.push_back(TEST_SYSTEMTOOLS_BINARY_DIR);
+  if (kwsys::SystemTools::FindFile(testFindFileName,
+                                    searchPaths, true).empty())
+    {
+    std::cerr
+      << "Problem with FindFile without system paths for: "
+      << testFindFileName << std::endl;
+    res = false;
+    }
+  if (kwsys::SystemTools::FindFile(testFindFileName,
+                                    searchPaths, false).empty())
+    {
+    std::cerr
+      << "Problem with FindFile with system paths for: "
+      << testFindFileName << std::endl;
+    res = false;
+    }
+
+  return res;
+}
+
 //----------------------------------------------------------------------------
 int testSystemTools(int, char*[])
 {
@@ -888,5 +1074,7 @@ int testSystemTools(int, char*[])
 
   res &= CheckGetPath();
 
+  res &= CheckFind();
+
   return res ? 0 : 1;
 }
diff --git a/Tests/AliasTarget/CMakeLists.txt b/Tests/AliasTarget/CMakeLists.txt
index c50b4e6..e1d8966 100644
--- a/Tests/AliasTarget/CMakeLists.txt
+++ b/Tests/AliasTarget/CMakeLists.txt
@@ -37,7 +37,9 @@ target_include_directories(bat PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
 add_executable(targetgenerator targetgenerator.cpp)
 add_executable(Generator::Target ALIAS targetgenerator)
 
-add_custom_target(usealias Generator::Target)
+add_subdirectory(subdir)
+
+add_custom_target(usealias Generator::Target $<TARGET_FILE:Sub::tgt>)
 add_dependencies(bat usealias)
 
 if (NOT TARGET Another::Alias)
diff --git a/Tests/AliasTarget/subdir/CMakeLists.txt b/Tests/AliasTarget/subdir/CMakeLists.txt
new file mode 100644
index 0000000..8c84aea
--- /dev/null
+++ b/Tests/AliasTarget/subdir/CMakeLists.txt
@@ -0,0 +1,3 @@
+
+add_library(tgt STATIC empty.cpp)
+add_library(Sub::tgt ALIAS tgt)
diff --git a/Tests/AliasTarget/subdir/empty.cpp b/Tests/AliasTarget/subdir/empty.cpp
new file mode 100644
index 0000000..b19427a
--- /dev/null
+++ b/Tests/AliasTarget/subdir/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int main(void)
+{
+  return 0;
+}
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index c82cb68..7bb0721 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -269,8 +269,7 @@ if(BUILD_TESTING)
     set(TEST_RESOURCES TRUE)
   endif()
   # for borland and watcom there is no resource support
-  if("${CMAKE_GENERATOR}" MATCHES "WMake" OR
-      "${CMAKE_GENERATOR}" MATCHES "Borland")
+  if(WATCOM OR BORLAND)
     set(TEST_RESOURCES FALSE)
   endif()
   if(TEST_RESOURCES)
@@ -686,13 +685,13 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
   endmacro()
   if(CMAKE_BUILD_NIGHTLY_RELEASES)
     ADD_NIGHTLY_BUILD_TEST(CMakeNightlyWindows
-      dash2win64_release.cmake)
-    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyMac
-      dashmacmini2_release.cmake)
-    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyMac64
+      dash3win7_release.cmake)
+    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyOSX
       dashmacmini5_release.cmake)
-    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyLinux
+    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyLinux32
       magrathea_release.cmake)
+    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyLinux64
+      linux64_release.cmake)
   endif()
 
   # add tests with more complex invocations
@@ -1033,9 +1032,11 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
       set(DEB_CONFIGURATIONS_TO_TEST "components-lintian-dpkgdeb-checks"
                                      "components-description1"
                                      "components-description2"
+                                     "components-source"
                                      "components-shlibdeps1"
                                      "components-depend1"
-                                     "components-depend2")
+                                     "components-depend2"
+                                     "compression")
       set(CPackGen "DEB")
       set(CPackRun_CPackGen "-DCPackGen=${CPackGen}")
 
@@ -1354,9 +1355,18 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
     endif()
   endif()
 
+  if(CMake_TEST_FindBoost)
+    add_subdirectory(FindBoost)
+  endif()
+
   if(CMake_TEST_FindGSL)
     add_subdirectory(FindGSL)
   endif()
+
+  if(CMake_TEST_FindGTest)
+    add_subdirectory(FindGTest)
+  endif()
+
   if(CMake_TEST_FindJsonCpp)
     add_subdirectory(FindJsonCpp)
   endif()
@@ -1365,6 +1375,22 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
     add_subdirectory(FindOpenSSL)
   endif()
 
+  if(CMake_TEST_FindPNG)
+    add_subdirectory(FindPNG)
+  endif()
+
+  if(CMake_TEST_FindTIFF)
+    add_subdirectory(FindTIFF)
+  endif()
+
+  if(CMake_TEST_FindXalanC)
+    add_subdirectory(FindXalanC)
+  endif()
+
+  if(CMake_TEST_FindXercesC)
+    add_subdirectory(FindXercesC)
+  endif()
+
   add_subdirectory(FindThreads)
 
   # Matlab module
@@ -2542,6 +2568,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
   set_tests_properties(CTestCoberturaCoverage PROPERTIES
       PASS_REGULAR_EXPRESSION
       "Process file.*CoverageTest.java.*Total LOC:.*18.*Percentage Coverage: 72.22.*"
+      ENVIRONMENT COBERTURADIR=${CMake_BINARY_DIR}/Testing/CoberturaCoverage
       ENVIRONMENT COVFILE=)
 
 
@@ -2587,8 +2614,9 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
      "${CMake_BINARY_DIR}/Testing/DelphiCoverage/DartConfiguration.tcl")
   file(COPY "${CMake_SOURCE_DIR}/Tests/DelphiCoverage/src"
     DESTINATION "${CMake_BINARY_DIR}/Testing/DelphiCoverage")
-  file(COPY "${CMake_SOURCE_DIR}/Tests/DelphiCoverage/UTCovTest(UTCovTest.pas).html"
-    DESTINATION "${CMake_BINARY_DIR}/Testing/DelphiCoverage")
+  configure_file(
+    "${CMake_SOURCE_DIR}/Tests/DelphiCoverage/UTCovTest(UTCovTest.pas).html.in"
+    "${CMake_BINARY_DIR}/Testing/DelphiCoverage/UTCovTest(UTCovTest.pas).html")
   add_test(NAME CTestDelphiCoverage
     COMMAND cmake -E chdir
     ${CMake_BINARY_DIR}/Testing/DelphiCoverage
diff --git a/Tests/CMakeOnly/CompilerIdC/CMakeLists.txt b/Tests/CMakeOnly/CompilerIdC/CMakeLists.txt
index 848ffdd..6fea73e 100644
--- a/Tests/CMakeOnly/CompilerIdC/CMakeLists.txt
+++ b/Tests/CMakeOnly/CompilerIdC/CMakeLists.txt
@@ -12,3 +12,10 @@ foreach(v
     message(SEND_ERROR "${v} not set!")
   endif()
 endforeach()
+
+# Version numbers may only contain numbers and periods.
+if(NOT CMAKE_C_COMPILER_VERSION MATCHES
+    "^([0-9]+)(\\.([0-9]+))?(\\.([0-9]+))?(\\.([0-9]+))?$"
+    )
+  message(SEND_ERROR "Compiler version is not numeric!")
+endif()
diff --git a/Tests/CMakeOnly/CompilerIdCXX/CMakeLists.txt b/Tests/CMakeOnly/CompilerIdCXX/CMakeLists.txt
index 94ac31e..05e6bb2 100644
--- a/Tests/CMakeOnly/CompilerIdCXX/CMakeLists.txt
+++ b/Tests/CMakeOnly/CompilerIdCXX/CMakeLists.txt
@@ -12,3 +12,10 @@ foreach(v
     message(SEND_ERROR "${v} not set!")
   endif()
 endforeach()
+
+# Version numbers may only contain numbers and periods.
+if(NOT CMAKE_CXX_COMPILER_VERSION MATCHES
+    "^([0-9]+)(\\.([0-9]+))?(\\.([0-9]+))?(\\.([0-9]+))?$"
+    )
+  message(SEND_ERROR "Compiler version is not numeric!")
+endif()
diff --git a/Tests/CMakeOnly/CompilerIdFortran/CMakeLists.txt b/Tests/CMakeOnly/CompilerIdFortran/CMakeLists.txt
index 02e4668..067fb8c 100644
--- a/Tests/CMakeOnly/CompilerIdFortran/CMakeLists.txt
+++ b/Tests/CMakeOnly/CompilerIdFortran/CMakeLists.txt
@@ -12,3 +12,10 @@ foreach(v
     message(SEND_ERROR "${v} not set!")
   endif()
 endforeach()
+
+# Version numbers may only contain numbers and periods.
+if(NOT CMAKE_Fortran_COMPILER_VERSION MATCHES
+    "^([0-9]+)(\\.([0-9]+))?(\\.([0-9]+))?(\\.([0-9]+))?$"
+    )
+  message(SEND_ERROR "Compiler version is not numeric!")
+endif()
diff --git a/Tests/CPackComponentsDEB/MyLibCPackConfig-components-source.cmake.in b/Tests/CPackComponentsDEB/MyLibCPackConfig-components-source.cmake.in
new file mode 100644
index 0000000..352f10b
--- /dev/null
+++ b/Tests/CPackComponentsDEB/MyLibCPackConfig-components-source.cmake.in
@@ -0,0 +1,33 @@
+#
+# Activate component packaging
+#
+
+if(CPACK_GENERATOR MATCHES "DEB")
+   set(CPACK_DEB_COMPONENT_INSTALL "ON")
+endif()
+
+#
+# Choose grouping way
+#
+set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
+
+# setting dependencies
+set(CPACK_DEBIAN_PACKAGE_DEPENDS                "depend-default")
+set(CPACK_DEBIAN_HEADERS_PACKAGE_DEPENDS        "depend-headers")
+
+# this time we set shlibdeps to on
+set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
+set(CPACK_DEBIAN_HEADERS_PACKAGE_SHLIBDEPS OFF)
+set(CPACK_DEBIAN_LIBRARIES_PACKAGE_SHLIBDEPS OFF)
+
+# we also set the dependencies of APPLICATION component to empty, and let
+# shlibdeps do the job for this component. Otherwise the default will
+# override
+set(CPACK_DEBIAN_APPLICATIONS_PACKAGE_DEPENDS        "")
+
+# this sets the generated packages source to the desired one, in case
+# several packages are generated from a unique source (the case with
+# multicomponents packaging).
+
+set(CPACK_DEBIAN_PACKAGE_SOURCE "test-source")
+set(CPACK_DEBIAN_APPLICATIONS_PACKAGE_SOURCE "test-other-source")
diff --git a/Tests/CPackComponentsDEB/MyLibCPackConfig-compression.cmake.in b/Tests/CPackComponentsDEB/MyLibCPackConfig-compression.cmake.in
new file mode 100644
index 0000000..ff18834
--- /dev/null
+++ b/Tests/CPackComponentsDEB/MyLibCPackConfig-compression.cmake.in
@@ -0,0 +1,11 @@
+#
+# Test that setting the compression produces valid
+# packages (compression does not leak to the DEBIAN/ files that use gzip)
+#
+
+if(CPACK_GENERATOR MATCHES "DEB")
+   set(CPACK_DEB_COMPONENT_INSTALL "OFF")
+endif()
+
+set(CPACK_COMPONENTS_ALL_GROUPS_IN_ONE_PACKAGE)
+set(CPACK_DEBIAN_COMPRESSION_TYPE xz)
diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-source.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-source.cmake
new file mode 100644
index 0000000..51fa3ad
--- /dev/null
+++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-source.cmake
@@ -0,0 +1,75 @@
+if(NOT CPackComponentsDEB_SOURCE_DIR)
+  message(FATAL_ERROR "CPackComponentsDEB_SOURCE_DIR not set")
+endif()
+
+include(${CPackComponentsDEB_SOURCE_DIR}/RunCPackVerifyResult.cmake)
+
+
+# expected results
+set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/MyLib-*.deb")
+set(expected_count 3)
+
+set(config_verbose -V)
+set(actual_output)
+run_cpack(actual_output
+          CPack_output
+          CPack_error
+          EXPECTED_FILE_MASK "${expected_file_mask}"
+          CONFIG_ARGS ${config_args}
+          CONFIG_VERBOSE ${config_verbose})
+
+
+if(NOT actual_output)
+  message(STATUS "expected_count='${expected_count}'")
+  message(STATUS "expected_file_mask='${expected_file_mask}'")
+  message(STATUS "actual_output_files='${actual_output}'")
+  message(FATAL_ERROR "error: expected_files do not exist: CPackComponentsDEB test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error}")
+endif()
+
+list(LENGTH actual_output actual_count)
+if(NOT actual_count EQUAL expected_count)
+  message(STATUS "actual_count='${actual_count}'")
+  message(FATAL_ERROR "error: expected_count=${expected_count} does not match actual_count=${actual_count}: CPackComponents test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error})")
+endif()
+
+
+# dpkg-deb checks for the summary of the packages
+find_program(DPKGDEB_EXECUTABLE dpkg-deb)
+if(DPKGDEB_EXECUTABLE)
+  set(dpkgdeb_output_errors_all "")
+  foreach(_f IN LISTS actual_output)
+
+    # extracts the metadata from the package
+    run_dpkgdeb(dpkg_output
+                FILENAME "${_f}"
+                )
+
+    dpkgdeb_return_specific_metaentry(dpkg_package_name
+                                      DPKGDEB_OUTPUT "${dpkg_output}"
+                                      METAENTRY "Package:")
+
+    dpkgdeb_return_specific_metaentry(dpkg_package_source
+                                      DPKGDEB_OUTPUT "${dpkg_output}"
+                                      METAENTRY "Source:")
+
+    message(STATUS "package='${_f}', source='${dpkg_package_source}'")
+
+    if(NOT ("${dpkg_package_name}" STREQUAL "mylib-applications"))
+      if(NOT ("${dpkg_package_source}" STREQUAL "test-source"))
+          set(dpkgdeb_output_errors_all "${dpkgdeb_output_errors_all}"
+                                        "dpkg-deb: ${_f}: Incorrect source for package '${dpkg_package_name}': '${dpkg_package_source}' instead of 'test-source'\n")
+      endif()
+    else()
+      if(NOT ("${dpkg_package_source}" STREQUAL "test-other-source"))
+          set(dpkgdeb_output_errors_all "${dpkgdeb_output_errors_all}"
+                                        "dpkg-deb: ${_f}: Incorrect source for package '${dpkg_package_name}': '${dpkg_package_source}' instead of 'test-other-source'\n")
+      endif()
+    endif()
+  endforeach()
+
+  if(NOT "${dpkgdeb_output_errors_all}" STREQUAL "")
+    message(FATAL_ERROR "dpkg-deb checks failed:\n${dpkgdeb_output_errors_all}")
+  endif()
+else()
+  message("dpkg-deb executable not found - skipping dpkg-deb test")
+endif()
diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult-compression.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult-compression.cmake
new file mode 100644
index 0000000..2175ada
--- /dev/null
+++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult-compression.cmake
@@ -0,0 +1,54 @@
+if(NOT CPackComponentsDEB_SOURCE_DIR)
+  message(FATAL_ERROR "CPackComponentsDEB_SOURCE_DIR not set")
+endif()
+
+include(${CPackComponentsDEB_SOURCE_DIR}/RunCPackVerifyResult.cmake)
+
+# TODO: currently debian doens't produce lower cased names
+set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/MyLib-*.deb")
+set(expected_count 1)
+
+set(actual_output)
+run_cpack(actual_output
+          CPack_output
+          CPack_error
+          EXPECTED_FILE_MASK "${expected_file_mask}"
+          CONFIG_ARGS "${config_args}"
+          CONFIG_VERBOSE "${config_verbose}")
+
+if(NOT actual_output)
+  message(STATUS "expected_count='${expected_count}'")
+  message(STATUS "expected_file_mask='${expected_file_mask}'")
+  message(STATUS "actual_output_files='${actual_output}'")
+  message(FATAL_ERROR "error: expected_files do not exist: CPackComponentsDEB test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error}")
+endif()
+
+list(LENGTH actual_output actual_count)
+if(NOT actual_count EQUAL expected_count)
+  message(STATUS "actual_count='${actual_count}'")
+  message(FATAL_ERROR "error: expected_count=${expected_count} does not match actual_count=${actual_count}: CPackComponents test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error})")
+endif()
+
+
+# dpkg-deb checks
+find_program(DPKGDEB_EXECUTABLE dpkg-deb)
+if(DPKGDEB_EXECUTABLE)
+  set(dpkgdeb_output_errors_all "")
+  foreach(_f IN LISTS actual_output)
+    run_dpkgdeb(dpkg_output
+                FILENAME "${_f}"
+                )
+
+    # message(FATAL_ERROR "output = '${dpkg_output}'")
+    if("${dpkg_output}" STREQUAL "")
+      set(dpkgdeb_output_errors_all "${dpkgdeb_output_errors_all}"
+                                    "dpkg-deb: ${_f}: empty content returned by dpkg-deb")
+    endif()
+  endforeach()
+
+  if(NOT "${dpkgdeb_output_errors_all}" STREQUAL "")
+    message(FATAL_ERROR "dpkg-deb checks failed:\n${dpkgdeb_output_errors_all}")
+  endif()
+else()
+  message("dpkg-deb executable not found - skipping dpkg-deb test")
+endif()
diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake
index bf9f81d..b4e567c 100644
--- a/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake
+++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake
@@ -86,7 +86,7 @@ function(run_lintian lintian_output)
       message(FATAL_ERROR "error: run_lintian needs FILENAME to be set")
     endif()
 
-    # run lintian
+    # run dpkg-deb
     execute_process(COMMAND ${LINTIAN_EXECUTABLE} ${run_lintian_deb_FILENAME}
       WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
       OUTPUT_VARIABLE LINTIAN_OUTPUT
@@ -167,6 +167,10 @@ function(run_dpkgdeb dpkg_deb_output)
       ERROR_VARIABLE DPKGDEB_ERROR
       OUTPUT_STRIP_TRAILING_WHITESPACE )
 
+    if(NOT ("${DPKGDEB_RESULT}" EQUAL "0"))
+      message(FATAL_ERROR "Error '${DPKGDEB_RESULT}' returned by dpkg-deb: '${DPKGDEB_ERROR}'")
+    endif()
+
     set(${dpkg_deb_output} "${DPKGDEB_OUTPUT}" PARENT_SCOPE)
   else()
     message(FATAL_ERROR "run_dpkgdeb called without dpkg-deb executable being present")
diff --git a/Tests/CTestUpdateGIT.cmake.in b/Tests/CTestUpdateGIT.cmake.in
index 6488a1f..46230cc 100644
--- a/Tests/CTestUpdateGIT.cmake.in
+++ b/Tests/CTestUpdateGIT.cmake.in
@@ -41,7 +41,6 @@ run_child(
   COMMAND ${GIT} --bare init
   )
 file(REMOVE_RECURSE ${TOP}/repo.git/hooks)
-set(REPO file://${TOP}/repo.git)
 
 # Create submodule repository.
 message("Creating submodule...")
@@ -51,17 +50,13 @@ run_child(
   COMMAND ${GIT} --bare init
   )
 file(REMOVE_RECURSE ${TOP}/module.git/hooks)
-set(MOD_REPO file://${TOP}/module.git)
-create_content(module)
-run_child(WORKING_DIRECTORY ${TOP}/module
-  COMMAND ${GIT} init
+run_child(WORKING_DIRECTORY ${TOP}
+  COMMAND ${GIT} clone module.git module
   )
 file(REMOVE_RECURSE ${TOP}/module/.git/hooks)
 file(APPEND ${TOP}/module/.git/config "
-[remote \"origin\"]
-\turl = ${MOD_REPO}
-\tfetch = +refs/heads/*:refs/remotes/origin/*
 ${AUTHOR_CONFIG}")
+create_content(module)
 run_child(WORKING_DIRECTORY ${TOP}/module
   COMMAND ${GIT} add .
   )
@@ -75,20 +70,17 @@ run_child(WORKING_DIRECTORY ${TOP}/module
 #-----------------------------------------------------------------------------
 # Import initial content into the repository.
 message("Importing content...")
-create_content(import)
-file(WRITE ${TOP}/import/HEAD "HEAD\n")
-file(WRITE ${TOP}/import/master "master\n")
 
 # Import the content into the repository.
-run_child(WORKING_DIRECTORY ${TOP}/import
-  COMMAND ${GIT} init
+run_child(WORKING_DIRECTORY ${TOP}
+  COMMAND ${GIT} clone repo.git import
   )
 file(REMOVE_RECURSE ${TOP}/import/.git/hooks)
 file(APPEND ${TOP}/import/.git/config "
-[remote \"origin\"]
-\turl = ${REPO}
-\tfetch = +refs/heads/*:refs/remotes/origin/*
 ${AUTHOR_CONFIG}")
+create_content(import)
+file(WRITE ${TOP}/import/HEAD "HEAD\n")
+file(WRITE ${TOP}/import/master "master\n")
 run_child(WORKING_DIRECTORY ${TOP}/import
   COMMAND ${GIT} add .
   )
@@ -96,7 +88,7 @@ run_child(WORKING_DIRECTORY ${TOP}/import
   COMMAND ${GIT} config core.safecrlf false
   )
 run_child(WORKING_DIRECTORY ${TOP}/import
-  COMMAND ${GIT} submodule add ${MOD_REPO} module
+  COMMAND ${GIT} submodule add ../module.git module
   )
 run_child(WORKING_DIRECTORY ${TOP}/import
   COMMAND ${GIT} commit -m "Initial content"
@@ -123,7 +115,7 @@ run_child(WORKING_DIRECTORY ${TOP}/module
 message("Checking out revision 1...")
 run_child(
   WORKING_DIRECTORY ${TOP}
-  COMMAND ${GIT} clone ${REPO} user-source
+  COMMAND ${GIT} clone repo.git user-source
   )
 file(REMOVE_RECURSE ${TOP}/user-source/.git/hooks)
 file(APPEND ${TOP}/user-source/.git/config "${AUTHOR_CONFIG}")
@@ -278,7 +270,7 @@ set(CTEST_GIT_COMMAND \"${GIT}\")
 set(CTEST_GIT_UPDATE_OPTIONS)
 execute_process(
   WORKING_DIRECTORY \"${TOP}\"
-  COMMAND \"${GIT}\" clone \"${REPO}\" dash-source
+  COMMAND \"${GIT}\" clone repo.git dash-source
   )
 
 # Test .git file.
diff --git a/Tests/CompileOptions/CMakeLists.txt b/Tests/CompileOptions/CMakeLists.txt
index 05a5f82..692e0de 100644
--- a/Tests/CompileOptions/CMakeLists.txt
+++ b/Tests/CompileOptions/CMakeLists.txt
@@ -22,7 +22,7 @@ set_property(TARGET CompileOptions PROPERTY COMPILE_OPTIONS
   ${cxx_tests}
   )
 
-if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|Borland")
+if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|Borland|Embarcadero")
   set_property(TARGET CompileOptions APPEND PROPERTY COMPILE_OPTIONS
     "-DTEST_OCTOTHORPE=\"#\""
     )
diff --git a/Tests/DelphiCoverage/UTCovTest(UTCovTest.pas).html b/Tests/DelphiCoverage/UTCovTest(UTCovTest.pas).html.in
similarity index 100%
rename from Tests/DelphiCoverage/UTCovTest(UTCovTest.pas).html
rename to Tests/DelphiCoverage/UTCovTest(UTCovTest.pas).html.in
diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt
index aedc89b..c2ecb0b 100644
--- a/Tests/ExportImport/Export/CMakeLists.txt
+++ b/Tests/ExportImport/Export/CMakeLists.txt
@@ -130,10 +130,15 @@ set_property(TARGET testLibCycleA PROPERTY LINK_INTERFACE_MULTIPLICITY 3)
 add_library(testLibNoSONAME SHARED testLibNoSONAME.c)
 set_property(TARGET testLibNoSONAME PROPERTY NO_SONAME 1)
 
+cmake_policy(PUSH)
+cmake_policy(SET CMP0022 NEW)
 # Test exporting dependent libraries into different exports
 add_library(testLibRequired testLibRequired.c)
 add_library(testLibDepends testLibDepends.c)
 target_link_libraries(testLibDepends LINK_PUBLIC testLibRequired)
+add_library(testStaticLibRequiredPrivate testStaticLibRequiredPrivate.c)
+target_link_libraries(testLibDepends PRIVATE testStaticLibRequiredPrivate)
+cmake_policy(POP)
 
 macro(add_include_lib _libName)
   file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_libName}.c" "/* no content */\n")
@@ -270,6 +275,7 @@ install(FILES
     DESTINATION include/testSharedLibRequiredUser
 )
 
+cmake_policy(PUSH)
 cmake_policy(SET CMP0022 NEW)
 add_library(testSharedLibRequiredUser2 SHARED testSharedLibRequiredUser2.cpp)
 generate_export_header(testSharedLibRequiredUser2)
@@ -283,7 +289,7 @@ install(FILES
   "${CMAKE_CURRENT_BINARY_DIR}/testsharedlibrequireduser2_export.h"
     DESTINATION include/testSharedLibRequiredUser2
 )
-cmake_policy(SET CMP0022 OLD)
+cmake_policy(POP)
 
 add_library(testSharedLibDepends SHARED testSharedLibDepends.cpp)
 set_property(TARGET testSharedLibDepends APPEND PROPERTY
@@ -311,6 +317,8 @@ target_link_libraries(testSharedLibDepends LINK_PUBLIC renamed_on_export)
 target_link_libraries(testSharedLibDepends LINK_INTERFACE_LIBRARIES
   $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:$<TARGET_NAME:testSharedLibRequired>>)
 
+cmake_policy(PUSH)
+cmake_policy(SET CMP0022 OLD)
 add_library(cmp0022OLD SHARED cmp0022_vs6_1.cpp)
 generate_export_header(cmp0022OLD BASE_NAME cmp0022)
 target_include_directories(cmp0022OLD PUBLIC
@@ -324,7 +332,7 @@ target_include_directories(cmp0022NEW PUBLIC
   "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}>"
   "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include/cmp0022>"
 )
-cmake_policy(SET CMP0022 OLD)
+cmake_policy(POP)
 install(FILES
   "${CMAKE_CURRENT_SOURCE_DIR}/cmp0022.h"
   "${CMAKE_CURRENT_BINARY_DIR}/cmp0022_export.h"
@@ -388,6 +396,10 @@ install(TARGETS
         INCLUDES DESTINATION
           $<INSTALL_PREFIX>/include/$<TARGET_PROPERTY:NAME>
 )
+install(TARGETS
+          testStaticLibRequiredPrivate
+        EXPORT RequiredExp DESTINATION lib
+)
 install(EXPORT RequiredExp NAMESPACE Req:: FILE testLibRequiredTargets.cmake DESTINATION lib/cmake/testLibRequired)
 
 file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest")
@@ -551,5 +563,5 @@ install(
   ARCHIVE DESTINATION lib
   INCLUDES DESTINATION include/abs
   )
-install(DIRECTORY include/abs DESTINATION $<1:include>$<0:/wrong>)
+install(DIRECTORY $<1:include/abs>$<0:/wrong> DESTINATION $<1:include>$<0:/wrong>)
 install(EXPORT expAbs NAMESPACE expAbs_ DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/expAbs)
diff --git a/Tests/ExportImport/Export/testLibDepends.c b/Tests/ExportImport/Export/testLibDepends.c
index fb5a002..3c7774e 100644
--- a/Tests/ExportImport/Export/testLibDepends.c
+++ b/Tests/ExportImport/Export/testLibDepends.c
@@ -16,5 +16,10 @@
 #endif
 
 extern int testLibRequired(void);
+extern int testStaticLibRequiredPrivate(void);
 
-int testLibDepends(void) { return testLibRequired(); }
+int testLibDepends(void) {
+  return testLibRequired()
+    + testStaticLibRequiredPrivate()
+    ;
+}
diff --git a/Tests/ExportImport/Export/testStaticLibRequiredPrivate.c b/Tests/ExportImport/Export/testStaticLibRequiredPrivate.c
new file mode 100644
index 0000000..28a2675
--- /dev/null
+++ b/Tests/ExportImport/Export/testStaticLibRequiredPrivate.c
@@ -0,0 +1 @@
+int testStaticLibRequiredPrivate(void) { return 0; }
diff --git a/Tests/FindBoost/CMakeLists.txt b/Tests/FindBoost/CMakeLists.txt
new file mode 100644
index 0000000..259ee26
--- /dev/null
+++ b/Tests/FindBoost/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_test(NAME FindBoost.Test COMMAND
+  ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+  --build-and-test
+  "${CMake_SOURCE_DIR}/Tests/FindBoost/Test"
+  "${CMake_BINARY_DIR}/Tests/FindBoost/Test"
+  ${build_generator_args}
+  --build-project TestFindBoost
+  --build-options ${build_options}
+  --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+  )
diff --git a/Tests/FindBoost/Test/CMakeLists.txt b/Tests/FindBoost/Test/CMakeLists.txt
new file mode 100644
index 0000000..ce50fc7
--- /dev/null
+++ b/Tests/FindBoost/Test/CMakeLists.txt
@@ -0,0 +1,18 @@
+cmake_minimum_required(VERSION 3.1)
+project(TestFindBoost CXX)
+include(CTest)
+
+find_package(Boost REQUIRED COMPONENTS filesystem thread)
+
+add_executable(test_boost_tgt main.cxx)
+target_link_libraries(test_boost_tgt
+                      Boost::dynamic_linking
+                      Boost::disable_autolinking
+                      Boost::filesystem
+                      Boost::thread)
+add_test(NAME test_boost_tgt COMMAND test_boost_tgt)
+
+add_executable(test_boost_var main.cxx)
+target_include_directories(test_boost_var PRIVATE ${Boost_INCLUDE_DIRS})
+target_link_libraries(test_boost_var PRIVATE ${Boost_FILESYSTEM_LIBRARIES} ${Boost_SYSTEM_LIBRARIES} ${Boost_THREAD_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
+add_test(NAME test_boost_var COMMAND test_boost_var)
diff --git a/Tests/FindBoost/Test/main.cxx b/Tests/FindBoost/Test/main.cxx
new file mode 100644
index 0000000..0f44f30
--- /dev/null
+++ b/Tests/FindBoost/Test/main.cxx
@@ -0,0 +1,26 @@
+#include <boost/filesystem.hpp>
+#include <boost/thread.hpp>
+
+namespace
+{
+
+  boost::mutex m1;
+  boost::recursive_mutex m2;
+
+  void
+  threadmain()
+  {
+    boost::lock_guard<boost::mutex> lock1(m1);
+    boost::lock_guard<boost::recursive_mutex> lock2(m2);
+
+    boost::filesystem::path p(boost::filesystem::current_path());
+  }
+
+}
+
+int main() {
+  boost::thread foo(threadmain);
+  foo.join();
+
+  return 0;
+}
diff --git a/Tests/FindGTest/CMakeLists.txt b/Tests/FindGTest/CMakeLists.txt
new file mode 100644
index 0000000..cbc92b1
--- /dev/null
+++ b/Tests/FindGTest/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_test(NAME FindGTest.Test COMMAND
+  ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+  --build-and-test
+  "${CMake_SOURCE_DIR}/Tests/FindGTest/Test"
+  "${CMake_BINARY_DIR}/Tests/FindGTest/Test"
+  ${build_generator_args}
+  --build-project TestFindGTest
+  --build-options ${build_options}
+  --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+  )
diff --git a/Tests/FindGTest/Test/CMakeLists.txt b/Tests/FindGTest/Test/CMakeLists.txt
new file mode 100644
index 0000000..99368ac
--- /dev/null
+++ b/Tests/FindGTest/Test/CMakeLists.txt
@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 3.1)
+project(TestFindGTest CXX)
+include(CTest)
+
+# CMake does not actually provide FindGTest publicly.
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../Source/Modules)
+
+find_package(GTest REQUIRED)
+
+add_executable(test_gtest_tgt main.cxx)
+target_link_libraries(test_gtest_tgt GTest::Main)
+add_test(NAME test_gtest_tgt COMMAND test_gtest_tgt)
+
+add_executable(test_gtest_var main.cxx)
+target_include_directories(test_gtest_var PRIVATE ${GTEST_INCLUDE_DIRS})
+target_link_libraries(test_gtest_var PRIVATE ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
+add_test(NAME test_gtest_var COMMAND test_gtest_var)
diff --git a/Tests/FindGTest/Test/main.cxx b/Tests/FindGTest/Test/main.cxx
new file mode 100644
index 0000000..0572a5d
--- /dev/null
+++ b/Tests/FindGTest/Test/main.cxx
@@ -0,0 +1,6 @@
+#include <gtest/gtest.h>
+
+TEST(FindCMake, LinksAndRuns)
+{
+  ASSERT_TRUE(true);
+}
diff --git a/Tests/FindPNG/CMakeLists.txt b/Tests/FindPNG/CMakeLists.txt
new file mode 100644
index 0000000..c665b67
--- /dev/null
+++ b/Tests/FindPNG/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_test(NAME FindPNG.Test COMMAND
+  ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+  --build-and-test
+  "${CMake_SOURCE_DIR}/Tests/FindPNG/Test"
+  "${CMake_BINARY_DIR}/Tests/FindPNG/Test"
+  ${build_generator_args}
+  --build-project TestFindPNG
+  --build-options ${build_options}
+  --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+  )
diff --git a/Tests/FindPNG/Test/CMakeLists.txt b/Tests/FindPNG/Test/CMakeLists.txt
new file mode 100644
index 0000000..ad50011
--- /dev/null
+++ b/Tests/FindPNG/Test/CMakeLists.txt
@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 3.4)
+project(TestFindPNG C)
+include(CTest)
+
+find_package(PNG REQUIRED)
+
+add_definitions(-DCMAKE_EXPECTED_PNG_VERSION="${PNG_VERSION_STRING}")
+
+add_executable(test_tgt main.c)
+target_link_libraries(test_tgt PNG::PNG)
+add_test(NAME test_tgt COMMAND test_tgt)
+
+add_executable(test_var main.c)
+target_include_directories(test_var PRIVATE ${PNG_INCLUDE_DIRS})
+target_link_libraries(test_var PRIVATE ${PNG_LIBRARIES})
+add_test(NAME test_var COMMAND test_var)
diff --git a/Tests/FindPNG/Test/main.c b/Tests/FindPNG/Test/main.c
new file mode 100644
index 0000000..27e1478
--- /dev/null
+++ b/Tests/FindPNG/Test/main.c
@@ -0,0 +1,20 @@
+#include <assert.h>
+#include <string.h>
+#include <png.h>
+
+int main()
+{
+  png_uint_32 png_version;
+  char png_version_string[16];
+
+  png_version = png_access_version_number ();
+
+  snprintf (png_version_string, 16, "%i.%i.%i",
+            png_version / 10000,
+            (png_version % 10000) / 100,
+            png_version % 100);
+
+  assert (strcmp(png_version_string, CMAKE_EXPECTED_PNG_VERSION) == 0);
+
+  return 0;
+}
diff --git a/Tests/FindTIFF/CMakeLists.txt b/Tests/FindTIFF/CMakeLists.txt
new file mode 100644
index 0000000..c4e0c6a
--- /dev/null
+++ b/Tests/FindTIFF/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_test(NAME FindTIFF.Test COMMAND
+  ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+  --build-and-test
+  "${CMake_SOURCE_DIR}/Tests/FindTIFF/Test"
+  "${CMake_BINARY_DIR}/Tests/FindTIFF/Test"
+  ${build_generator_args}
+  --build-project TestFindTIFF
+  --build-options ${build_options}
+  --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+  )
diff --git a/Tests/FindTIFF/Test/CMakeLists.txt b/Tests/FindTIFF/Test/CMakeLists.txt
new file mode 100644
index 0000000..f17cda7
--- /dev/null
+++ b/Tests/FindTIFF/Test/CMakeLists.txt
@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 3.1)
+project(TestFindTIFF C)
+include(CTest)
+
+# CMake does not actually provide FindTIFF publicly.
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../Source/Modules)
+
+find_package(TIFF REQUIRED)
+
+add_executable(test_xercesc_tgt main.c)
+target_link_libraries(test_xercesc_tgt TIFF::TIFF)
+add_test(NAME test_xercesc_tgt COMMAND test_xercesc_tgt)
+
+add_executable(test_xercesc_var main.c)
+target_include_directories(test_xercesc_var PRIVATE ${TIFF_INCLUDE_DIRS})
+target_link_libraries(test_xercesc_var PRIVATE ${TIFF_LIBRARIES})
+add_test(NAME test_xercesc_var COMMAND test_xercesc_var)
diff --git a/Tests/FindTIFF/Test/main.c b/Tests/FindTIFF/Test/main.c
new file mode 100644
index 0000000..fc4f337
--- /dev/null
+++ b/Tests/FindTIFF/Test/main.c
@@ -0,0 +1,12 @@
+#include <assert.h>
+#include <tiffio.h>
+
+int main()
+{
+  /* Without any TIFF file to open, test that the call fails as
+     expected.  This tests that linking worked. */
+  TIFF *tiff = TIFFOpen("invalid.tiff", "r");
+  assert(!tiff);
+
+  return 0;
+}
diff --git a/Tests/FindXalanC/CMakeLists.txt b/Tests/FindXalanC/CMakeLists.txt
new file mode 100644
index 0000000..7872929
--- /dev/null
+++ b/Tests/FindXalanC/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_test(NAME FindXalanC.Test COMMAND
+  ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+  --build-and-test
+  "${CMake_SOURCE_DIR}/Tests/FindXalanC/Test"
+  "${CMake_BINARY_DIR}/Tests/FindXalanC/Test"
+  ${build_generator_args}
+  --build-project TestFindXalanC
+  --build-options ${build_options}
+  --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+  )
diff --git a/Tests/FindXalanC/Test/CMakeLists.txt b/Tests/FindXalanC/Test/CMakeLists.txt
new file mode 100644
index 0000000..b445e0e
--- /dev/null
+++ b/Tests/FindXalanC/Test/CMakeLists.txt
@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 3.1)
+project(TestFindXalanC CXX)
+include(CTest)
+
+# CMake does not actually provide FindXalanC publicly.
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../Source/Modules)
+
+find_package(XalanC REQUIRED)
+
+add_executable(test_xalanc_tgt main.cxx)
+target_link_libraries(test_xalanc_tgt XalanC::XalanC)
+add_test(NAME test_xalanc_tgt COMMAND test_xalanc_tgt)
+
+add_executable(test_xalanc_var main.cxx)
+target_include_directories(test_xalanc_var PRIVATE ${XalanC_INCLUDE_DIRS})
+target_link_libraries(test_xalanc_var PRIVATE ${XalanC_LIBRARIES})
+add_test(NAME test_xalanc_var COMMAND test_xalanc_var)
diff --git a/Tests/FindXalanC/Test/main.cxx b/Tests/FindXalanC/Test/main.cxx
new file mode 100644
index 0000000..3b4a2df
--- /dev/null
+++ b/Tests/FindXalanC/Test/main.cxx
@@ -0,0 +1,10 @@
+#include <xercesc/util/PlatformUtils.hpp>
+#include <xalanc/XalanTransformer/XalanTransformer.hpp>
+
+int main()
+{
+  xercesc::XMLPlatformUtils::Initialize();
+  xalanc::XalanTransformer::initialize();
+  xalanc::XalanTransformer::terminate();
+  xercesc::XMLPlatformUtils::Terminate();
+}
diff --git a/Tests/FindXercesC/CMakeLists.txt b/Tests/FindXercesC/CMakeLists.txt
new file mode 100644
index 0000000..633f613
--- /dev/null
+++ b/Tests/FindXercesC/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_test(NAME FindXercesC.Test COMMAND
+  ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+  --build-and-test
+  "${CMake_SOURCE_DIR}/Tests/FindXercesC/Test"
+  "${CMake_BINARY_DIR}/Tests/FindXercesC/Test"
+  ${build_generator_args}
+  --build-project TestFindXercesC
+  --build-options ${build_options}
+  --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+  )
diff --git a/Tests/FindXercesC/Test/CMakeLists.txt b/Tests/FindXercesC/Test/CMakeLists.txt
new file mode 100644
index 0000000..8e7767c
--- /dev/null
+++ b/Tests/FindXercesC/Test/CMakeLists.txt
@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 3.1)
+project(TestFindXercesC CXX)
+include(CTest)
+
+# CMake does not actually provide FindXercesC publicly.
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../Source/Modules)
+
+find_package(XercesC REQUIRED)
+
+add_executable(test_xercesc_tgt main.cxx)
+target_link_libraries(test_xercesc_tgt XercesC::XercesC)
+add_test(NAME test_xercesc_tgt COMMAND test_xercesc_tgt)
+
+add_executable(test_xercesc_var main.cxx)
+target_include_directories(test_xercesc_var PRIVATE ${XercesC_INCLUDE_DIRS})
+target_link_libraries(test_xercesc_var PRIVATE ${XercesC_LIBRARIES})
+add_test(NAME test_xercesc_var COMMAND test_xercesc_var)
diff --git a/Tests/FindXercesC/Test/main.cxx b/Tests/FindXercesC/Test/main.cxx
new file mode 100644
index 0000000..1794fa6
--- /dev/null
+++ b/Tests/FindXercesC/Test/main.cxx
@@ -0,0 +1,7 @@
+#include <xercesc/util/PlatformUtils.hpp>
+
+int main()
+{
+  xercesc::XMLPlatformUtils::Initialize();
+  xercesc::XMLPlatformUtils::Terminate();
+}
diff --git a/Tests/Fortran/CMakeLists.txt b/Tests/Fortran/CMakeLists.txt
index 753ce27..ecf38a6 100644
--- a/Tests/Fortran/CMakeLists.txt
+++ b/Tests/Fortran/CMakeLists.txt
@@ -223,5 +223,6 @@ if(TEST_MODULE_DEPENDS)
   endif()
 
   add_subdirectory(Library)
+  add_subdirectory(Subdir)
   add_subdirectory(Executable)
 endif()
diff --git a/Tests/Fortran/Executable/CMakeLists.txt b/Tests/Fortran/Executable/CMakeLists.txt
index 55f21ad..de08d86 100644
--- a/Tests/Fortran/Executable/CMakeLists.txt
+++ b/Tests/Fortran/Executable/CMakeLists.txt
@@ -3,6 +3,6 @@ include_directories(${External_BINARY_DIR})
 link_directories(${External_BINARY_DIR})
 
 add_executable(subdir_exe2 main.f90)
-target_link_libraries(subdir_exe2 subdir_mods)
+target_link_libraries(subdir_exe2 subdir_mods subdir_mods2)
 add_dependencies(subdir_exe2 ExternalTarget)
 target_link_libraries(subdir_exe2 myext)
diff --git a/Tests/Fortran/Executable/main.f90 b/Tests/Fortran/Executable/main.f90
index f21156c..640259c 100644
--- a/Tests/Fortran/Executable/main.f90
+++ b/Tests/Fortran/Executable/main.f90
@@ -1,6 +1,7 @@
 PROGRAM MAINF90
   USE libraryModuleA
   USE libraryModuleB
+  USE subdirModuleA
   USE externalMod
   CALL printExtModGreeting
 END PROGRAM MAINF90
diff --git a/Tests/Fortran/Subdir/CMakeLists.txt b/Tests/Fortran/Subdir/CMakeLists.txt
new file mode 100644
index 0000000..52683e5
--- /dev/null
+++ b/Tests/Fortran/Subdir/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_library(subdir_mods2 subdir.f90)
+target_include_directories(subdir_mods2 INTERFACE ${CMAKE_CURRENT_BINARY_DIR})
diff --git a/Tests/Fortran/Subdir/subdir.f90 b/Tests/Fortran/Subdir/subdir.f90
new file mode 100644
index 0000000..68955f6
--- /dev/null
+++ b/Tests/Fortran/Subdir/subdir.f90
@@ -0,0 +1,2 @@
+MODULE subdirModuleA
+END MODULE
diff --git a/Tests/JavaJavah/C.cpp b/Tests/JavaJavah/C.cpp
new file mode 100644
index 0000000..ec75f42
--- /dev/null
+++ b/Tests/JavaJavah/C.cpp
@@ -0,0 +1,10 @@
+
+#include <jni.h>
+#include <stdio.h>
+
+#include "C.h"
+
+JNIEXPORT void JNICALL Java_C_printName(JNIEnv *, jobject)
+{
+  printf("C\n");
+}
diff --git a/Tests/JavaJavah/C.java b/Tests/JavaJavah/C.java
new file mode 100644
index 0000000..54b1be2
--- /dev/null
+++ b/Tests/JavaJavah/C.java
@@ -0,0 +1,19 @@
+class C
+{
+  public C()
+    {
+    }
+
+    public native void printName();
+
+    static {
+        try {
+
+            System.loadLibrary("B");
+
+        } catch (UnsatisfiedLinkError e) {
+            System.err.println("Native code library failed to load.\n" + e);
+            System.exit(1);
+        }
+    }
+}
diff --git a/Tests/JavaJavah/CMakeLists.txt b/Tests/JavaJavah/CMakeLists.txt
index 83b0ad0..071bf20 100644
--- a/Tests/JavaJavah/CMakeLists.txt
+++ b/Tests/JavaJavah/CMakeLists.txt
@@ -9,10 +9,13 @@ include (UseJava)
 # JNI support
 find_package(JNI)
 
-add_jar(hello3 B.java HelloWorld2.java)
-create_javah(TARGET B_javah CLASSES B CLASSPATH hello3)
+add_jar(B1 B.java)
+add_jar(C1 C.java)
+create_javah(TARGET B_javah CLASSES B C CLASSPATH B1 C1)
 
-add_library(B SHARED B.cpp)
+add_jar(hello3 HelloWorld2.java)
+
+add_library(B SHARED B.cpp C.cpp)
 add_dependencies(B B_javah)
 
 target_include_directories(B PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
diff --git a/Tests/JavaJavah/HelloWorld2.java b/Tests/JavaJavah/HelloWorld2.java
index faf7277..5ff710f 100644
--- a/Tests/JavaJavah/HelloWorld2.java
+++ b/Tests/JavaJavah/HelloWorld2.java
@@ -5,6 +5,11 @@ class HelloWorld2
         B b;
         b = new B();
         b.printName();
+
+        C c;
+        c = new C();
+        c.printName();
+
         System.out.println("Hello World!");
     }
 }
diff --git a/Tests/Module/GenerateExportHeader/exportheader_test.cpp b/Tests/Module/GenerateExportHeader/exportheader_test.cpp
index 146374a..4f45f37 100644
--- a/Tests/Module/GenerateExportHeader/exportheader_test.cpp
+++ b/Tests/Module/GenerateExportHeader/exportheader_test.cpp
@@ -39,6 +39,18 @@ void compare(const char* refName, const char* testName)
     std::string testLine;
     std::getline(ref, refLine);
     std::getline(test, testLine);
+    // Some very old Borland runtimes (C++ Builder 5 WITHOUT Update 1) add a
+    // trailing null to the string that we need to strip before testing for a
+    // trailing space.
+    if (refLine.size() && refLine[refLine.size()-1] == 0)
+      {
+      refLine = refLine.substr(0, refLine.size() - 1);
+      }
+    if (testLine.size() && testLine[testLine.size()-1] == 0)
+      {
+      testLine = testLine.substr(0, testLine.size() - 1);
+      }
+    // The reference files never have trailing spaces:
     if (testLine.size() && testLine[testLine.size()-1] == ' ')
       {
       testLine = testLine.substr(0, testLine.size() - 1);
diff --git a/Tests/RunCMake/BuildDepends/Custom-Always.cmake b/Tests/RunCMake/BuildDepends/Custom-Always.cmake
new file mode 100644
index 0000000..d412708
--- /dev/null
+++ b/Tests/RunCMake/BuildDepends/Custom-Always.cmake
@@ -0,0 +1,24 @@
+add_custom_command(
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/before-always
+  COMMAND ${CMAKE_COMMAND} -E touch before-always
+  )
+add_custom_command(
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/always
+  COMMAND ${CMAKE_COMMAND} -E touch always-updated
+  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/before-always
+  )
+set_property(SOURCE always PROPERTY SYMBOLIC 1)
+add_custom_command(
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/after-always
+  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/always
+  COMMAND ${CMAKE_COMMAND} -E touch after-always
+  )
+
+add_custom_target(drive ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/after-always)
+
+file(GENERATE OUTPUT check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
+set(check_pairs
+  \"${CMAKE_CURRENT_BINARY_DIR}/always-updated|${CMAKE_CURRENT_BINARY_DIR}/before-always\"
+  \"${CMAKE_CURRENT_BINARY_DIR}/after-always|${CMAKE_CURRENT_BINARY_DIR}/always-updated\"
+  )
+")
diff --git a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake
index a578408..31c72fb 100644
--- a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake
+++ b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake
@@ -38,3 +38,5 @@ if(NOT RunCMake_GENERATOR MATCHES "Visual Studio [67]|Xcode")
   run_BuildDepends(C-Exe-Manifest)
   unset(run_BuildDepends_skip_step_2)
 endif()
+
+run_BuildDepends(Custom-Always)
diff --git a/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt b/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt
index 3f82d8c..4a1077c 100644
--- a/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt
+++ b/Tests/RunCMake/CMP0040/CMP0040-NEW-missing-target-stderr.txt
@@ -1,4 +1,4 @@
 CMake Error at CMP0040-NEW-missing-target.cmake:3 \(add_custom_command\):
-  The target name "foobar" is unknown in this context.
+  No TARGET 'foobar' has been created in this directory.
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt b/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt
index e791f0a..e3e3ff4 100644
--- a/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt
+++ b/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt
@@ -4,7 +4,7 @@ CMake Warning \(dev\) at CMP0040-WARN-missing-target.cmake:2 \(add_custom_comman
   policy details.  Use the cmake_policy command to set the policy and
   suppress this warning.
 +
-  The target name "foobar" is unknown in this context.
+  No TARGET 'foobar' has been created in this directory.
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
 This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 1a0019f..0a388c5 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -177,6 +177,7 @@ add_RunCMake_test(build_command)
 add_RunCMake_test(execute_process)
 add_RunCMake_test(export)
 add_RunCMake_test(cmake_minimum_required)
+add_RunCMake_test(cmake_parse_arguments)
 add_RunCMake_test(continue)
 add_RunCMake_test(ctest_build)
 add_RunCMake_test(ctest_configure)
@@ -239,6 +240,12 @@ if(XCODE_VERSION AND NOT "${XCODE_VERSION}" VERSION_LESS 3)
   add_RunCMake_test(XcodeProject -DXCODE_VERSION=${XCODE_VERSION})
 endif()
 
+if(NOT XCODE
+    AND CMAKE_C_COMPILER_ID STREQUAL "AppleClang"
+    AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.0)
+  add_RunCMake_test(Framework)
+endif()
+
 add_RunCMake_test(File_Generate)
 add_RunCMake_test(ExportWithoutLanguage)
 add_RunCMake_test(target_link_libraries)
diff --git a/Tests/RunCMake/CPack/DEB/PER_COMPONENT_FIELDS-ExpectedFiles.cmake b/Tests/RunCMake/CPack/DEB/PER_COMPONENT_FIELDS-ExpectedFiles.cmake
new file mode 100644
index 0000000..1f6c11b
--- /dev/null
+++ b/Tests/RunCMake/CPack/DEB/PER_COMPONENT_FIELDS-ExpectedFiles.cmake
@@ -0,0 +1,9 @@
+set(whitespaces_ "[\t\n\r ]*")
+
+set(EXPECTED_FILES_COUNT "3")
+set(EXPECTED_FILE_1 "per_component*-pkg_1.deb")
+set(EXPECTED_FILE_CONTENT_1 "^.*/usr/foo${whitespaces_}.*/usr/foo/CMakeLists.txt$")
+set(EXPECTED_FILE_2 "per_component*-pkg_2.deb")
+set(EXPECTED_FILE_CONTENT_2 "^.*/usr/foo${whitespaces_}.*/usr/foo/CMakeLists.txt$")
+set(EXPECTED_FILE_3 "per_component*-pkg_3.deb")
+set(EXPECTED_FILE_CONTENT_3 "^.*/usr/foo${whitespaces_}.*/usr/foo/CMakeLists.txt$")
diff --git a/Tests/RunCMake/CPack/DEB/PER_COMPONENT_FIELDS-VerifyResult.cmake b/Tests/RunCMake/CPack/DEB/PER_COMPONENT_FIELDS-VerifyResult.cmake
new file mode 100644
index 0000000..55293be
--- /dev/null
+++ b/Tests/RunCMake/CPack/DEB/PER_COMPONENT_FIELDS-VerifyResult.cmake
@@ -0,0 +1,18 @@
+function(checkPackageInfo_ TYPE FILE REGEX)
+  set(whitespaces_ "[\t\n\r ]*")
+
+  getPackageInfo("${FILE}" "FILE_INFO_")
+  if(NOT FILE_INFO_ MATCHES "${REGEX}")
+    message(FATAL_ERROR "Unexpected ${TYPE} in '${FILE}'; file info: '${FILE_INFO_}'")
+  endif()
+endfunction()
+
+# check package name
+checkPackageInfo_("name" "${FOUND_FILE_1}" ".*Package${whitespaces_}:${whitespaces_}per_component-pkg_1")
+checkPackageInfo_("name" "${FOUND_FILE_2}" ".*Package${whitespaces_}:${whitespaces_}second")
+checkPackageInfo_("name" "${FOUND_FILE_3}" ".*Package${whitespaces_}:${whitespaces_}per_component-pkg_3")
+
+# check package group
+checkPackageInfo_("group" "${FOUND_FILE_1}" ".*Section${whitespaces_}:${whitespaces_}default")
+checkPackageInfo_("group" "${FOUND_FILE_2}" ".*Section${whitespaces_}:${whitespaces_}second_group")
+checkPackageInfo_("group" "${FOUND_FILE_3}" ".*Section${whitespaces_}:${whitespaces_}default")
diff --git a/Tests/RunCMake/CPack/DEB/PER_COMPONENT_FIELDS-specifics.cmake b/Tests/RunCMake/CPack/DEB/PER_COMPONENT_FIELDS-specifics.cmake
new file mode 100644
index 0000000..a1da1a3
--- /dev/null
+++ b/Tests/RunCMake/CPack/DEB/PER_COMPONENT_FIELDS-specifics.cmake
@@ -0,0 +1,6 @@
+set(CPACK_PACKAGE_CONTACT "someone")
+set(CPACK_DEB_COMPONENT_INSTALL "ON")
+
+set(CPACK_DEBIAN_PACKAGE_SECTION "default")
+set(CPACK_DEBIAN_PKG_2_PACKAGE_NAME "second")
+set(CPACK_DEBIAN_PKG_2_PACKAGE_SECTION "second_group")
diff --git a/Tests/RunCMake/CPack/PER_COMPONENT_FIELDS.cmake b/Tests/RunCMake/CPack/PER_COMPONENT_FIELDS.cmake
new file mode 100644
index 0000000..bb42cf4
--- /dev/null
+++ b/Tests/RunCMake/CPack/PER_COMPONENT_FIELDS.cmake
@@ -0,0 +1,5 @@
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT pkg_1)
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT pkg_2)
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT pkg_3)
+
+set(CPACK_PACKAGE_NAME "per_component")
diff --git a/Tests/RunCMake/CPack/RPM/Helpers.cmake b/Tests/RunCMake/CPack/RPM/Helpers.cmake
index 98cdad8..ba77a4a 100644
--- a/Tests/RunCMake/CPack/RPM/Helpers.cmake
+++ b/Tests/RunCMake/CPack/RPM/Helpers.cmake
@@ -8,3 +8,12 @@ function(getPackageContent FILE RESULT_VAR)
 
   set(${RESULT_VAR} "${package_content_}" PARENT_SCOPE)
 endfunction()
+
+function(getPackageInfo FILE RESULT_VAR)
+  execute_process(COMMAND ${RPM_EXECUTABLE} -pqi ${FILE}
+          OUTPUT_VARIABLE info_content
+          ERROR_QUIET
+          OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+  set(${RESULT_VAR} "${info_content}" PARENT_SCOPE)
+endfunction()
diff --git a/Tests/RunCMake/CPack/RPM/PER_COMPONENT_FIELDS-ExpectedFiles.cmake b/Tests/RunCMake/CPack/RPM/PER_COMPONENT_FIELDS-ExpectedFiles.cmake
new file mode 100644
index 0000000..3d28d41
--- /dev/null
+++ b/Tests/RunCMake/CPack/RPM/PER_COMPONENT_FIELDS-ExpectedFiles.cmake
@@ -0,0 +1,9 @@
+set(whitespaces_ "[\t\n\r ]*")
+
+set(EXPECTED_FILES_COUNT "3")
+set(EXPECTED_FILE_1 "per_component*-pkg_1.rpm")
+set(EXPECTED_FILE_CONTENT_1 "^/usr/foo${whitespaces_}/usr/foo/CMakeLists.txt$")
+set(EXPECTED_FILE_2 "per_component*-pkg_2.rpm")
+set(EXPECTED_FILE_CONTENT_2 "^/usr/foo${whitespaces_}/usr/foo/CMakeLists.txt$")
+set(EXPECTED_FILE_3 "per_component*-pkg_3.rpm")
+set(EXPECTED_FILE_CONTENT_3 "^/usr/foo${whitespaces_}/usr/foo/CMakeLists.txt$")
diff --git a/Tests/RunCMake/CPack/RPM/PER_COMPONENT_FIELDS-VerifyResult.cmake b/Tests/RunCMake/CPack/RPM/PER_COMPONENT_FIELDS-VerifyResult.cmake
new file mode 100644
index 0000000..d7d4f9d
--- /dev/null
+++ b/Tests/RunCMake/CPack/RPM/PER_COMPONENT_FIELDS-VerifyResult.cmake
@@ -0,0 +1,18 @@
+function(checkPackageInfo_ TYPE FILE REGEX)
+  set(whitespaces_ "[\t\n\r ]*")
+
+  getPackageInfo("${FILE}" "FILE_INFO_")
+  if(NOT FILE_INFO_ MATCHES "${REGEX}")
+    message(FATAL_ERROR "Unexpected ${TYPE} in '${FILE}'; file info: '${FILE_INFO_}'")
+  endif()
+endfunction()
+
+# check package name
+checkPackageInfo_("name" "${FOUND_FILE_1}" ".*Name${whitespaces_}:${whitespaces_}per_component-pkg_1")
+checkPackageInfo_("name" "${FOUND_FILE_2}" ".*Name${whitespaces_}:${whitespaces_}second")
+checkPackageInfo_("name" "${FOUND_FILE_3}" ".*Name${whitespaces_}:${whitespaces_}per_component-pkg_3")
+
+# check package group
+checkPackageInfo_("group" "${FOUND_FILE_1}" ".*Group${whitespaces_}:${whitespaces_}default")
+checkPackageInfo_("group" "${FOUND_FILE_2}" ".*Group${whitespaces_}:${whitespaces_}second_group")
+checkPackageInfo_("group" "${FOUND_FILE_3}" ".*Group${whitespaces_}:${whitespaces_}default")
diff --git a/Tests/RunCMake/CPack/RPM/PER_COMPONENT_FIELDS-specifics.cmake b/Tests/RunCMake/CPack/RPM/PER_COMPONENT_FIELDS-specifics.cmake
new file mode 100644
index 0000000..d398168
--- /dev/null
+++ b/Tests/RunCMake/CPack/RPM/PER_COMPONENT_FIELDS-specifics.cmake
@@ -0,0 +1,5 @@
+set(CPACK_RPM_COMPONENT_INSTALL "ON")
+
+set(CPACK_RPM_PACKAGE_GROUP "default")
+set(CPACK_RPM_pkg_2_PACKAGE_NAME "second")
+set(CPACK_RPM_pkg_2_PACKAGE_GROUP "second_group")
diff --git a/Tests/RunCMake/CPack/RunCMakeTest.cmake b/Tests/RunCMake/CPack/RunCMakeTest.cmake
index b7295f4..fe2b48b 100644
--- a/Tests/RunCMake/CPack/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CPack/RunCMakeTest.cmake
@@ -10,3 +10,4 @@ run_cpack_test(DEB_EXTRA "DEB" false)
 run_cpack_test(DEPENDENCIES "RPM;DEB" true)
 run_cpack_test(EMPTY_DIR "RPM;DEB;TGZ" true)
 run_cpack_test(COMPONENTS_EMPTY_DIR "RPM;DEB;TGZ" true)
+run_cpack_test(PER_COMPONENT_FIELDS "RPM;DEB" false)
diff --git a/Tests/RunCMake/CommandLine/E-no-arg-stderr.txt b/Tests/RunCMake/CommandLine/E-no-arg-stderr.txt
index 056ce05..50d9b03 100644
--- a/Tests/RunCMake/CommandLine/E-no-arg-stderr.txt
+++ b/Tests/RunCMake/CommandLine/E-no-arg-stderr.txt
@@ -1,3 +1,3 @@
 ^CMake Error: cmake version .*
-Usage: .* -E \[command\] \[arguments ...\]
+Usage: .* -E <command> \[arguments\.\.\.\]
 Available commands:
diff --git a/Tests/RunCMake/CommandLine/E_copy-one-source-directory-target-is-directory-result.txt b/Tests/RunCMake/CommandLine/E_copy-one-source-directory-target-is-directory-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_copy-one-source-directory-target-is-directory-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CommandLine/E_copy-one-source-directory-target-is-directory-stderr.txt b/Tests/RunCMake/CommandLine/E_copy-one-source-directory-target-is-directory-stderr.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/CommandLine/E_copy-one-source-file-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/CommandLine/E_copy-one-source-file-result.txt
diff --git a/Tests/RunCMake/CommandLine/E_copy-one-source-file-stderr.txt b/Tests/RunCMake/CommandLine/E_copy-one-source-file-stderr.txt
new file mode 100644
index 0000000..9a9301d
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_copy-one-source-file-stderr.txt
@@ -0,0 +1 @@
+^CMake Error: .*
diff --git a/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-directory-result.txt b/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-directory-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-directory-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-directory-stderr.txt b/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-directory-stderr.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-file-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-file-result.txt
diff --git a/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-file-stderr.txt b/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-file-stderr.txt
new file mode 100644
index 0000000..9504216
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-file-stderr.txt
@@ -0,0 +1 @@
+^Error: Target \(for copy command\).* is not a directory.$
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/CommandLine/E_copy-two-good-and-one-bad-source-files-target-is-directory-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/CommandLine/E_copy-two-good-and-one-bad-source-files-target-is-directory-result.txt
diff --git a/Tests/RunCMake/CommandLine/E_copy-two-good-and-one-bad-source-files-target-is-directory-stderr.txt b/Tests/RunCMake/CommandLine/E_copy-two-good-and-one-bad-source-files-target-is-directory-stderr.txt
new file mode 100644
index 0000000..2d0d986
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_copy-two-good-and-one-bad-source-files-target-is-directory-stderr.txt
@@ -0,0 +1 @@
+^Error copying file .*not_existing_file.bad\" to .*
diff --git a/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-directory-result.txt b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-directory-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-directory-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-directory-stderr.txt b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-directory-stderr.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-file-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-file-result.txt
diff --git a/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-file-stderr.txt b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-file-stderr.txt
new file mode 100644
index 0000000..6ca3677
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-file-stderr.txt
@@ -0,0 +1,3 @@
+^Error copying directory from .* to .*file_for_test.txt\".*
+Error copying directory from .* to .*file_for_test.txt\".*
+Error copying directory from .* to .*file_for_test.txt\".$
diff --git a/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-not-exist-result.txt b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-not-exist-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-not-exist-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-not-exist-stderr.txt b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-not-exist-stderr.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/CommandLine/E_copy_if_different-one-source-directory-target-is-directory-result.txt b/Tests/RunCMake/CommandLine/E_copy_if_different-one-source-directory-target-is-directory-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_copy_if_different-one-source-directory-target-is-directory-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CommandLine/E_copy_if_different-one-source-directory-target-is-directory-stderr.txt b/Tests/RunCMake/CommandLine/E_copy_if_different-one-source-directory-target-is-directory-stderr.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-directory-result.txt b/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-directory-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-directory-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-directory-stderr.txt b/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-directory-stderr.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-file-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-file-result.txt
diff --git a/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-file-stderr.txt b/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-file-stderr.txt
new file mode 100644
index 0000000..64b7b1b
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-file-stderr.txt
@@ -0,0 +1 @@
+^Error: Target \(for copy_if_different command\).* is not a directory.$
diff --git a/Tests/RunCMake/CommandLine/E_create_symlink-no-arg-stderr.txt b/Tests/RunCMake/CommandLine/E_create_symlink-no-arg-stderr.txt
index 056ce05..50d9b03 100644
--- a/Tests/RunCMake/CommandLine/E_create_symlink-no-arg-stderr.txt
+++ b/Tests/RunCMake/CommandLine/E_create_symlink-no-arg-stderr.txt
@@ -1,3 +1,3 @@
 ^CMake Error: cmake version .*
-Usage: .* -E \[command\] \[arguments ...\]
+Usage: .* -E <command> \[arguments\.\.\.\]
 Available commands:
diff --git a/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-result.txt b/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-stderr.txt b/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-stderr.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-result.txt
diff --git a/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-stderr.txt b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-stderr.txt
new file mode 100644
index 0000000..08a9428
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-stderr.txt
@@ -0,0 +1 @@
+^Error creating directory .*file_for_test.txt\".$
diff --git a/Tests/RunCMake/CommandLine/E_make_directory-three-directories-result.txt b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CommandLine/E_make_directory-three-directories-stderr.txt b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-stderr.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/CommandLine/E_rename-no-arg-stderr.txt b/Tests/RunCMake/CommandLine/E_rename-no-arg-stderr.txt
index 056ce05..50d9b03 100644
--- a/Tests/RunCMake/CommandLine/E_rename-no-arg-stderr.txt
+++ b/Tests/RunCMake/CommandLine/E_rename-no-arg-stderr.txt
@@ -1,3 +1,3 @@
 ^CMake Error: cmake version .*
-Usage: .* -E \[command\] \[arguments ...\]
+Usage: .* -E <command> \[arguments\.\.\.\]
 Available commands:
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/CommandLine/E_time-no-arg-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/CommandLine/E_time-no-arg-result.txt
diff --git a/Tests/RunCMake/CommandLine/E-no-arg-stderr.txt b/Tests/RunCMake/CommandLine/E_time-no-arg-stderr.txt
similarity index 54%
copy from Tests/RunCMake/CommandLine/E-no-arg-stderr.txt
copy to Tests/RunCMake/CommandLine/E_time-no-arg-stderr.txt
index 056ce05..50d9b03 100644
--- a/Tests/RunCMake/CommandLine/E-no-arg-stderr.txt
+++ b/Tests/RunCMake/CommandLine/E_time-no-arg-stderr.txt
@@ -1,3 +1,3 @@
 ^CMake Error: cmake version .*
-Usage: .* -E \[command\] \[arguments ...\]
+Usage: .* -E <command> \[arguments\.\.\.\]
 Available commands:
diff --git a/Tests/RunCMake/CommandLine/E_time-stdout.txt b/Tests/RunCMake/CommandLine/E_time-stdout.txt
new file mode 100644
index 0000000..a51446a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_time-stdout.txt
@@ -0,0 +1,3 @@
+^hello  world
+Elapsed time: [^
+]*$
diff --git a/Tests/RunCMake/CommandLine/E_touch_nocreate-no-arg-stderr.txt b/Tests/RunCMake/CommandLine/E_touch_nocreate-no-arg-stderr.txt
index 056ce05..50d9b03 100644
--- a/Tests/RunCMake/CommandLine/E_touch_nocreate-no-arg-stderr.txt
+++ b/Tests/RunCMake/CommandLine/E_touch_nocreate-no-arg-stderr.txt
@@ -1,3 +1,3 @@
 ^CMake Error: cmake version .*
-Usage: .* -E \[command\] \[arguments ...\]
+Usage: .* -E <command> \[arguments\.\.\.\]
 Available commands:
diff --git a/Tests/RunCMake/CommandLine/P_working-dir.cmake b/Tests/RunCMake/CommandLine/P_working-dir.cmake
new file mode 100644
index 0000000..4ea0293
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/P_working-dir.cmake
@@ -0,0 +1,14 @@
+if(NOT IS_DIRECTORY "${EXPECTED_WORKING_DIR}")
+  message(FATAL_ERROR "EXPECTED_WORKING_DIR is not a directory: ${EXPECTED_WORKING_DIR}")
+endif()
+
+foreach(d CMAKE_BINARY_DIR CMAKE_CURRENT_BINARY_DIR CMAKE_SOURCE_DIR CMAKE_CURRENT_SOURCE_DIR)
+  if(NOT DEFINED ${d})
+    message(FATAL_ERROR "${d} is not defined")
+  endif()
+  if(EXPECTED_WORKING_DIR STREQUAL "${${d}}")
+    message(STATUS "${d} is the expected working directory (${EXPECTED_WORKING_DIR})")
+  else()
+    message(FATAL_ERROR "${d} = \"${${d}}\" is not the expected working directory (${EXPECTED_WORKING_DIR})")
+  endif()
+endforeach()
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index cef6368..e3b73ff 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -12,6 +12,9 @@ run_cmake_command(E_echo_append ${CMAKE_COMMAND} -E echo_append)
 run_cmake_command(E_rename-no-arg ${CMAKE_COMMAND} -E rename)
 run_cmake_command(E_touch_nocreate-no-arg ${CMAKE_COMMAND} -E touch_nocreate)
 
+run_cmake_command(E_time ${CMAKE_COMMAND} -E time ${CMAKE_COMMAND} -E echo "hello  world")
+run_cmake_command(E_time-no-arg ${CMAKE_COMMAND} -E time)
+
 run_cmake_command(E___run_iwyu-no-iwyu ${CMAKE_COMMAND} -E __run_iwyu -- command-does-not-exist)
 run_cmake_command(E___run_iwyu-bad-iwyu ${CMAKE_COMMAND} -E __run_iwyu --iwyu=iwyu-does-not-exist -- command-does-not-exist)
 run_cmake_command(E___run_iwyu-no--- ${CMAKE_COMMAND} -E __run_iwyu --iwyu=iwyu-does-not-exist command-does-not-exist)
@@ -33,6 +36,11 @@ run_cmake_command(build-bad-dir
 run_cmake_command(build-bad-generator
   ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-bad-generator)
 
+run_cmake_command(cache-bad-entry
+  ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-bad-entry/)
+run_cmake_command(cache-empty-entry
+  ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-empty-entry/)
+
 function(run_BuildDir)
   # Use a single build tree for a few tests without cleaning.
   set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/BuildDir-build)
@@ -101,6 +109,60 @@ if(UNIX)
     )
 endif()
 
+set(in ${RunCMake_SOURCE_DIR}/copy_input)
+set(out ${RunCMake_BINARY_DIR}/copy_output)
+file(REMOVE_RECURSE "${out}")
+file(MAKE_DIRECTORY ${out})
+run_cmake_command(E_copy-one-source-file
+  ${CMAKE_COMMAND} -E copy ${out}/f1.txt)
+run_cmake_command(E_copy-one-source-directory-target-is-directory
+  ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${out})
+run_cmake_command(E_copy-three-source-files-target-is-directory
+  ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out})
+run_cmake_command(E_copy-three-source-files-target-is-file
+  ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out}/f1.txt)
+run_cmake_command(E_copy-two-good-and-one-bad-source-files-target-is-directory
+  ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${in}/not_existing_file.bad ${in}/f3.txt ${out})
+run_cmake_command(E_copy_if_different-one-source-directory-target-is-directory
+  ${CMAKE_COMMAND} -E copy_if_different ${in}/f1.txt ${out})
+run_cmake_command(E_copy_if_different-three-source-files-target-is-directory
+  ${CMAKE_COMMAND} -E copy_if_different ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out})
+run_cmake_command(E_copy_if_different-three-source-files-target-is-file
+  ${CMAKE_COMMAND} -E copy_if_different ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out}/f1.txt)
+unset(in)
+unset(out)
+
+set(in ${RunCMake_SOURCE_DIR}/copy_input)
+set(out ${RunCMake_BINARY_DIR}/copy_directory_output)
+set(outfile ${out}/file_for_test.txt)
+file(REMOVE_RECURSE "${out}")
+file(MAKE_DIRECTORY ${out})
+file(WRITE ${outfile} "")
+run_cmake_command(E_copy_directory-three-source-files-target-is-directory
+  ${CMAKE_COMMAND} -E copy_directory ${in}/d1 ${in}/d2 ${in}/d3 ${out})
+run_cmake_command(E_copy_directory-three-source-files-target-is-file
+  ${CMAKE_COMMAND} -E copy_directory ${in}/d1 ${in}/d2 ${in}/d3 ${outfile})
+run_cmake_command(E_copy_directory-three-source-files-target-is-not-exist
+  ${CMAKE_COMMAND} -E copy_directory ${in}/d1 ${in}/d2 ${in}/d3 ${out}/not_existing_directory)
+unset(in)
+unset(out)
+unset(outfile)
+
+set(out ${RunCMake_BINARY_DIR}/make_directory_output)
+set(outfile ${out}/file_for_test.txt)
+file(REMOVE_RECURSE "${out}")
+file(MAKE_DIRECTORY ${out})
+file(WRITE ${outfile} "")
+run_cmake_command(E_make_directory-three-directories
+  ${CMAKE_COMMAND} -E make_directory ${out}/d1 ${out}/d2 ${out}/d2)
+run_cmake_command(E_make_directory-directory-with-parent
+  ${CMAKE_COMMAND} -E make_directory ${out}/parent/child)
+run_cmake_command(E_make_directory-three-directories-and-file
+  ${CMAKE_COMMAND} -E make_directory ${out}/d1 ${out}/d2 ${outfile})
+unset(out)
+unset(outfile)
+
+
 run_cmake_command(E_env-no-command0 ${CMAKE_COMMAND} -E env)
 run_cmake_command(E_env-no-command1 ${CMAKE_COMMAND} -E env TEST_ENV=1)
 run_cmake_command(E_env-bad-arg1 ${CMAKE_COMMAND} -E env -bad-arg1)
@@ -115,6 +177,7 @@ run_cmake_command(E_sleep-bad-arg2 ${CMAKE_COMMAND} -E sleep 1 -1)
 run_cmake_command(E_sleep-one-tenth ${CMAKE_COMMAND} -E sleep 0.1)
 
 run_cmake_command(P_directory ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR})
+run_cmake_command(P_working-dir ${CMAKE_COMMAND} -DEXPECTED_WORKING_DIR=${RunCMake_BINARY_DIR}/P_working-dir-build -P ${RunCMake_SOURCE_DIR}/P_working-dir.cmake)
 
 set(RunCMake_TEST_OPTIONS
   "-DFOO=-DBAR:BOOL=BAZ")
@@ -128,9 +191,69 @@ set(RunCMake_TEST_OPTIONS -Wno-dev)
 run_cmake(Wno-dev)
 unset(RunCMake_TEST_OPTIONS)
 
+set(RunCMake_TEST_OPTIONS -Wdev)
+run_cmake(Wdev)
+unset(RunCMake_TEST_OPTIONS)
+
+set(RunCMake_TEST_OPTIONS -Werror=dev)
+run_cmake(Werror_dev)
+unset(RunCMake_TEST_OPTIONS)
+
+set(RunCMake_TEST_OPTIONS -Wno-error=dev)
+run_cmake(Wno-error_deprecated)
+unset(RunCMake_TEST_OPTIONS)
+
+# -Wdev should not override deprecated options if specified
+set(RunCMake_TEST_OPTIONS -Wdev -Wno-deprecated)
+run_cmake(Wno-deprecated)
+unset(RunCMake_TEST_OPTIONS)
+set(RunCMake_TEST_OPTIONS -Wno-deprecated -Wdev)
+run_cmake(Wno-deprecated)
+unset(RunCMake_TEST_OPTIONS)
+
+# -Wdev should enable deprecated warnings as well
+set(RunCMake_TEST_OPTIONS -Wdev)
+run_cmake(Wdeprecated)
+unset(RunCMake_TEST_OPTIONS)
+
+# -Werror=dev should enable deprecated errors as well
+set(RunCMake_TEST_OPTIONS -Werror=dev)
+run_cmake(Werror_deprecated)
+unset(RunCMake_TEST_OPTIONS)
+
+set(RunCMake_TEST_OPTIONS -Wdeprecated)
+run_cmake(Wdeprecated)
+unset(RunCMake_TEST_OPTIONS)
+
+set(RunCMake_TEST_OPTIONS -Wno-deprecated)
+run_cmake(Wno-deprecated)
+unset(RunCMake_TEST_OPTIONS)
+
+set(RunCMake_TEST_OPTIONS -Werror=deprecated)
+run_cmake(Werror_deprecated)
+unset(RunCMake_TEST_OPTIONS)
+
+set(RunCMake_TEST_OPTIONS -Wno-error=deprecated)
+run_cmake(Wno-error_deprecated)
+unset(RunCMake_TEST_OPTIONS)
+
+# Dev warnings should be on by default
+run_cmake(Wdev)
+
+# Deprecated warnings should be on by default
+run_cmake(Wdeprecated)
+
+# Conflicting -W options should honor the last value
 set(RunCMake_TEST_OPTIONS -Wno-dev -Wdev)
 run_cmake(Wdev)
 unset(RunCMake_TEST_OPTIONS)
+set(RunCMake_TEST_OPTIONS -Wdev -Wno-dev)
+run_cmake(Wno-dev)
+unset(RunCMake_TEST_OPTIONS)
+
+run_cmake_command(W_bad-arg1 ${CMAKE_COMMAND} -W)
+run_cmake_command(W_bad-arg2 ${CMAKE_COMMAND} -Wno-)
+run_cmake_command(W_bad-arg3 ${CMAKE_COMMAND} -Werror=)
 
 set(RunCMake_TEST_OPTIONS --debug-output)
 run_cmake(debug-output)
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/CommandLine/W_bad-arg1-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/CommandLine/W_bad-arg1-result.txt
diff --git a/Tests/RunCMake/CommandLine/W_bad-arg1-stderr.txt b/Tests/RunCMake/CommandLine/W_bad-arg1-stderr.txt
new file mode 100644
index 0000000..0c0f613
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/W_bad-arg1-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error: -W must be followed with \[no-\]<name>.
+CMake Error: Problem processing arguments. Aborting.
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/CommandLine/W_bad-arg2-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/CommandLine/W_bad-arg2-result.txt
diff --git a/Tests/RunCMake/CommandLine/W_bad-arg2-stderr.txt b/Tests/RunCMake/CommandLine/W_bad-arg2-stderr.txt
new file mode 100644
index 0000000..cc643df
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/W_bad-arg2-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error: No warning name provided.
+CMake Error: Problem processing arguments. Aborting.
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/CommandLine/W_bad-arg3-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/CommandLine/W_bad-arg3-result.txt
diff --git a/Tests/RunCMake/CommandLine/W_bad-arg3-stderr.txt b/Tests/RunCMake/CommandLine/W_bad-arg3-stderr.txt
new file mode 100644
index 0000000..cc643df
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/W_bad-arg3-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error: No warning name provided.
+CMake Error: Problem processing arguments. Aborting.
diff --git a/Tests/RunCMake/CommandLine/Wdeprecated-stderr.txt b/Tests/RunCMake/CommandLine/Wdeprecated-stderr.txt
new file mode 100644
index 0000000..e9be1dc
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Wdeprecated-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Deprecation Warning at Wdeprecated.cmake:1 \(message\):
+  Some deprecated warning
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CommandLine/Wdeprecated.cmake b/Tests/RunCMake/CommandLine/Wdeprecated.cmake
new file mode 100644
index 0000000..3142b42
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Wdeprecated.cmake
@@ -0,0 +1 @@
+message(DEPRECATION "Some deprecated warning")
diff --git a/Tests/RunCMake/CommandLine/Wdev-stderr.txt b/Tests/RunCMake/CommandLine/Wdev-stderr.txt
index 92c1d23..88cfb3a 100644
--- a/Tests/RunCMake/CommandLine/Wdev-stderr.txt
+++ b/Tests/RunCMake/CommandLine/Wdev-stderr.txt
@@ -1,5 +1,5 @@
 ^CMake Warning \(dev\) at Wdev.cmake:1 \(message\):
-  Some Author Warning
+  Some author warning
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
 This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CommandLine/Wdev.cmake b/Tests/RunCMake/CommandLine/Wdev.cmake
index e5026ef..756f31e 100644
--- a/Tests/RunCMake/CommandLine/Wdev.cmake
+++ b/Tests/RunCMake/CommandLine/Wdev.cmake
@@ -1,4 +1,4 @@
-message(AUTHOR_WARNING "Some Author Warning")
+message(AUTHOR_WARNING "Some author warning")
 
 # with -Wdev this will also cause an AUTHOR_WARNING message, checks that
 # messages issued outside of the message command, by other CMake commands, also
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/CommandLine/Werror_deprecated-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/CommandLine/Werror_deprecated-result.txt
diff --git a/Tests/RunCMake/CommandLine/Werror_deprecated-stderr.txt b/Tests/RunCMake/CommandLine/Werror_deprecated-stderr.txt
new file mode 100644
index 0000000..6acdc73
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Werror_deprecated-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Deprecation Error at Werror_deprecated.cmake:1 \(message\):
+  Some deprecated warning
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CommandLine/Werror_deprecated.cmake b/Tests/RunCMake/CommandLine/Werror_deprecated.cmake
new file mode 100644
index 0000000..3142b42
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Werror_deprecated.cmake
@@ -0,0 +1 @@
+message(DEPRECATION "Some deprecated warning")
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/CommandLine/Werror_dev-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/CommandLine/Werror_dev-result.txt
diff --git a/Tests/RunCMake/CommandLine/Werror_dev-stderr.txt b/Tests/RunCMake/CommandLine/Werror_dev-stderr.txt
new file mode 100644
index 0000000..590ec96
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Werror_dev-stderr.txt
@@ -0,0 +1,11 @@
+^CMake Error \(dev\) at Werror_dev.cmake:4 \(include\):
+  include\(\) given empty file name \(ignored\).
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+This error is for project developers. Use -Wno-error=dev to suppress it.
+
+CMake Error \(dev\) at Werror_dev.cmake:7 \(message\):
+  Some author warning
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+This error is for project developers. Use -Wno-error=dev to suppress it.$
diff --git a/Tests/RunCMake/CommandLine/Werror_dev.cmake b/Tests/RunCMake/CommandLine/Werror_dev.cmake
new file mode 100644
index 0000000..05f333a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Werror_dev.cmake
@@ -0,0 +1,7 @@
+# with -Werror=dev this will also cause an (upgraded) AUTHOR_ERROR message,
+# checks that messages issued outside of the message command, by other CMake
+# commands, also are affected by -Werror=dev
+include("")
+
+# message command sets fatal occurred flag, so run it last
+message(AUTHOR_WARNING "Some author warning")
diff --git a/Tests/RunCMake/CommandLine/Wno-deprecated.cmake b/Tests/RunCMake/CommandLine/Wno-deprecated.cmake
new file mode 100644
index 0000000..3142b42
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Wno-deprecated.cmake
@@ -0,0 +1 @@
+message(DEPRECATION "Some deprecated warning")
diff --git a/Tests/RunCMake/CommandLine/Wno-dev.cmake b/Tests/RunCMake/CommandLine/Wno-dev.cmake
index d81b858..802b435 100644
--- a/Tests/RunCMake/CommandLine/Wno-dev.cmake
+++ b/Tests/RunCMake/CommandLine/Wno-dev.cmake
@@ -1,4 +1,4 @@
-message(AUTHOR_WARNING "Some Author Warning")
+message(AUTHOR_WARNING "Some author warning")
 
 # without -Wno-dev this will also cause an AUTHOR_WARNING message, checks that
 # messages issued outside of the message command, by other CMake commands, also
diff --git a/Tests/RunCMake/CommandLine/Wno-error_deprecated-stderr.txt b/Tests/RunCMake/CommandLine/Wno-error_deprecated-stderr.txt
new file mode 100644
index 0000000..0ed1698
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Wno-error_deprecated-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Deprecation Warning at Wno-error_deprecated.cmake:2 \(message\):
+  Some deprecated warning
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CommandLine/Wno-error_deprecated.cmake b/Tests/RunCMake/CommandLine/Wno-error_deprecated.cmake
new file mode 100644
index 0000000..676792a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Wno-error_deprecated.cmake
@@ -0,0 +1,2 @@
+# This should still produce a warning when -Wno-error=deprecated is specified
+message(DEPRECATION "Some deprecated warning")
diff --git a/Tests/RunCMake/CommandLine/Wdev-stderr.txt b/Tests/RunCMake/CommandLine/Wno-error_dev-stderr.txt
similarity index 69%
copy from Tests/RunCMake/CommandLine/Wdev-stderr.txt
copy to Tests/RunCMake/CommandLine/Wno-error_dev-stderr.txt
index 92c1d23..dd22d55 100644
--- a/Tests/RunCMake/CommandLine/Wdev-stderr.txt
+++ b/Tests/RunCMake/CommandLine/Wno-error_dev-stderr.txt
@@ -1,10 +1,10 @@
-^CMake Warning \(dev\) at Wdev.cmake:1 \(message\):
-  Some Author Warning
+^CMake Warning \(dev\) at Wno-error_dev.cmake:2 \(message\):
+  Some author warning
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
 This warning is for project developers.  Use -Wno-dev to suppress it.
 
-CMake Warning \(dev\) at Wdev.cmake:6 \(include\):
+CMake Warning \(dev\) at Wno-error_dev.cmake:6 \(include\):
   include\(\) given empty file name \(ignored\).
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CommandLine/Wno-error_dev.cmake b/Tests/RunCMake/CommandLine/Wno-error_dev.cmake
new file mode 100644
index 0000000..b700c19
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Wno-error_dev.cmake
@@ -0,0 +1,7 @@
+# This should still produce a warning when -Wno-error=dev is specified
+message(AUTHOR_WARNING "Some author warning")
+
+# with -Wno-error=dev this will also cause an AUTHOR_WARNING message, checks
+# that messages issued outside of the message command, by other CMake commands,
+# also are affected by -Wno-error=dev
+include("")
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/CommandLine/cache-bad-entry-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/CommandLine/cache-bad-entry-result.txt
diff --git a/Tests/RunCMake/CommandLine/cache-bad-entry-stderr.txt b/Tests/RunCMake/CommandLine/cache-bad-entry-stderr.txt
new file mode 100644
index 0000000..150d2ca
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/cache-bad-entry-stderr.txt
@@ -0,0 +1 @@
+^CMake Error: Parse error in cache file .*/Tests/RunCMake/CommandLine/cache-bad-entry/CMakeCache.txt on line 7. Offending entry: BAD ENTRY.*
diff --git a/Tests/RunCMake/CommandLine/cache-bad-entry/CMakeCache.txt b/Tests/RunCMake/CommandLine/cache-bad-entry/CMakeCache.txt
new file mode 100644
index 0000000..75cd7c2
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/cache-bad-entry/CMakeCache.txt
@@ -0,0 +1,10 @@
+# This is a comment
+
+// That was an empty line. This isn't.
+EMPTY_LINE:BOOL=FALSE
+
+// Uhoh! Here it comes
+BAD ENTRY
+
+// This is fine
+GOOD_ENTRY:BOOL=TRUE
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/CommandLine/cache-empty-entry-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/CommandLine/cache-empty-entry-result.txt
diff --git a/Tests/RunCMake/CommandLine/cache-empty-entry-stderr.txt b/Tests/RunCMake/CommandLine/cache-empty-entry-stderr.txt
new file mode 100644
index 0000000..54f4452
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/cache-empty-entry-stderr.txt
@@ -0,0 +1 @@
+^CMake Error: Parse error in cache file .*/Tests/RunCMake/CommandLine/cache-empty-entry/CMakeCache.txt on line 5. Offending entry:.*
diff --git a/Tests/RunCMake/CommandLine/cache-empty-entry/CMakeCache.txt b/Tests/RunCMake/CommandLine/cache-empty-entry/CMakeCache.txt
new file mode 100644
index 0000000..44da1c9
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/cache-empty-entry/CMakeCache.txt
@@ -0,0 +1,7 @@
+// This is valid
+VALID:BOOL=TRUE
+
+// This isn't
+
+// One final entry
+FINAL:BOOL=TRUE
diff --git a/Tests/RunCMake/CommandLine/copy_input/d1/d1.txt b/Tests/RunCMake/CommandLine/copy_input/d1/d1.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/CommandLine/copy_input/d2/d2.txt b/Tests/RunCMake/CommandLine/copy_input/d2/d2.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/CommandLine/copy_input/d3/d3.txt b/Tests/RunCMake/CommandLine/copy_input/d3/d3.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/CommandLine/copy_input/f1.txt b/Tests/RunCMake/CommandLine/copy_input/f1.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/CommandLine/copy_input/f2.txt b/Tests/RunCMake/CommandLine/copy_input/f2.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/CommandLine/copy_input/f3.txt b/Tests/RunCMake/CommandLine/copy_input/f3.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_cache_variables.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_cache_variables.cmake
new file mode 100644
index 0000000..8d8d000
--- /dev/null
+++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_cache_variables.cmake
@@ -0,0 +1,16 @@
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(NCURSES QUIET ncurses)
+
+if (NCURSES_FOUND)
+  foreach (variable IN ITEMS PREFIX INCLUDEDIR LIBDIR)
+    get_property("${variable}"
+      CACHE     "NCURSES_${variable}"
+      PROPERTY  TYPE
+      SET)
+    if (NOT ${variable})
+      message(FATAL_ERROR "Failed to set cache entry for NCURSES_${variable}")
+    endif ()
+  endforeach ()
+else ()
+  message(STATUS "skipping test; ncurses not found")
+endif ()
diff --git a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake
index bb04aa2..24089e0 100644
--- a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake
+++ b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake
@@ -14,4 +14,5 @@ endif()
 find_package(PkgConfig)
 if (PKG_CONFIG_FOUND)
   run_cmake(FindPkgConfig_GET_VARIABLE)
+  run_cmake(FindPkgConfig_cache_variables)
 endif ()
diff --git a/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh
index 852e841..abe14bf 100755
--- a/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh
+++ b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh
@@ -10,9 +10,10 @@ case $1 in
     ;;
   --exists)
     shift
-    echo "Expected: $@"
+    eval last=\${$#}
+    echo "Expected: ${last}"
     echo "Found:    ${PKG_CONFIG_PATH}"
-    [ "$@" = "${PKG_CONFIG_PATH}" ] || exit 1
+    [ "${last}" = "${PKG_CONFIG_PATH}" ] || exit 1
     ;;
   *)
     exit 255
diff --git a/Tests/RunCMake/install/CMakeLists.txt b/Tests/RunCMake/Framework/CMakeLists.txt
similarity index 61%
copy from Tests/RunCMake/install/CMakeLists.txt
copy to Tests/RunCMake/Framework/CMakeLists.txt
index 4b3de84..6dd8cdf 100644
--- a/Tests/RunCMake/install/CMakeLists.txt
+++ b/Tests/RunCMake/Framework/CMakeLists.txt
@@ -1,3 +1,3 @@
-cmake_minimum_required(VERSION 2.8.12)
+cmake_minimum_required(VERSION 3.4)
 project(${RunCMake_TEST} NONE)
 include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/Framework/FrameworkLayout.cmake b/Tests/RunCMake/Framework/FrameworkLayout.cmake
new file mode 100644
index 0000000..5184755
--- /dev/null
+++ b/Tests/RunCMake/Framework/FrameworkLayout.cmake
@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 3.4)
+enable_language(C)
+
+add_library(Framework SHARED
+            foo.c
+            foo.h
+            res.txt)
+set_target_properties(Framework PROPERTIES
+                      FRAMEWORK TRUE
+                      PUBLIC_HEADER foo.h
+                      RESOURCE "res.txt")
diff --git a/Tests/RunCMake/Framework/OSXFrameworkLayout-build-check.cmake b/Tests/RunCMake/Framework/OSXFrameworkLayout-build-check.cmake
new file mode 100644
index 0000000..da1ccb4
--- /dev/null
+++ b/Tests/RunCMake/Framework/OSXFrameworkLayout-build-check.cmake
@@ -0,0 +1,35 @@
+set(framework-dir "${RunCMake_TEST_BINARY_DIR}/Framework.framework")
+set(framework-resources "${framework-dir}/Resources")
+set(framework-resource-file "${framework-resources}/res.txt")
+set(framework-library "${framework-dir}/Framework")
+set(framework-versions "${framework-dir}/Versions")
+set(plist-file "${framework-resources}/Info.plist")
+set(framework-header "${framework-dir}/Headers/foo.h")
+
+if(NOT IS_DIRECTORY ${framework-dir})
+  message(SEND_ERROR "Framework not found at ${framework-dir}")
+endif()
+
+if(NOT EXISTS ${plist-file})
+  message(SEND_ERROR "plist file not found at ${plist-file}")
+endif()
+
+if(NOT EXISTS ${framework-library})
+  message(SEND_ERROR "Framework library not found at ${framework-library}")
+endif()
+
+if(NOT EXISTS ${framework-resource-file})
+  message(SEND_ERROR "Framework resource file not found at ${framework-resource-file}")
+endif()
+
+if(NOT EXISTS ${framework-versions})
+  message(SEND_ERROR "Framework versions not found at ${framework-versions}")
+endif()
+
+if(NOT EXISTS ${framework-resources})
+  message(SEND_ERROR "Framework Resources not found at ${framework-resources}")
+endif()
+
+if(NOT EXISTS ${framework-header})
+  message(SEND_ERROR "Framework header file not found at ${framework-header}")
+endif()
diff --git a/Tests/RunCMake/Framework/RunCMakeTest.cmake b/Tests/RunCMake/Framework/RunCMakeTest.cmake
new file mode 100644
index 0000000..d810283
--- /dev/null
+++ b/Tests/RunCMake/Framework/RunCMakeTest.cmake
@@ -0,0 +1,33 @@
+include(RunCMake)
+
+# iOS
+
+set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/iOSFrameworkLayout-build)
+set(RunCMake_TEST_NO_CLEAN 1)
+set(RunCMake_TEST_OPTIONS "-DCMAKE_TOOLCHAIN_FILE=${RunCMake_SOURCE_DIR}/ios.cmake")
+
+file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+
+run_cmake(FrameworkLayout)
+run_cmake_command(iOSFrameworkLayout-build ${CMAKE_COMMAND} --build .)
+
+unset(RunCMake_TEST_BINARY_DIR)
+unset(RunCMake_TEST_NO_CLEAN)
+unset(RunCMake_TEST_OPTIONS)
+
+# OSX
+
+set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/OSXFrameworkLayout-build)
+set(RunCMake_TEST_NO_CLEAN 1)
+set(RunCMake_TEST_OPTIONS "-DCMAKE_TOOLCHAIN_FILE=${RunCMake_SOURCE_DIR}/OSX.cmake")
+
+file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+
+run_cmake(FrameworkLayout)
+run_cmake_command(OSXFrameworkLayout-build ${CMAKE_COMMAND} --build .)
+
+unset(RunCMake_TEST_BINARY_DIR)
+unset(RunCMake_TEST_NO_CLEAN)
+unset(RunCMake_TEST_OPTIONS)
diff --git a/Tests/RunCMake/Framework/foo.c b/Tests/RunCMake/Framework/foo.c
new file mode 100644
index 0000000..bf7759e
--- /dev/null
+++ b/Tests/RunCMake/Framework/foo.c
@@ -0,0 +1 @@
+int foo() { return 42; }
diff --git a/Tests/RunCMake/Framework/foo.h b/Tests/RunCMake/Framework/foo.h
new file mode 100644
index 0000000..5d5f8f0
--- /dev/null
+++ b/Tests/RunCMake/Framework/foo.h
@@ -0,0 +1 @@
+int foo();
diff --git a/Tests/RunCMake/Framework/iOSFrameworkLayout-build-check.cmake b/Tests/RunCMake/Framework/iOSFrameworkLayout-build-check.cmake
new file mode 100644
index 0000000..b81a5f7
--- /dev/null
+++ b/Tests/RunCMake/Framework/iOSFrameworkLayout-build-check.cmake
@@ -0,0 +1,35 @@
+set(framework-dir "${RunCMake_TEST_BINARY_DIR}/Framework.framework")
+set(framework-resources "${framework-dir}/Resources")
+set(framework-resource-file "${framework-dir}/res.txt")
+set(framework-library "${framework-dir}/Framework")
+set(framework-versions "${framework-dir}/Versions")
+set(plist-file "${framework-dir}/Info.plist")
+set(framework-header "${framework-dir}/Headers/foo.h")
+
+if(NOT IS_DIRECTORY ${framework-dir})
+  message(SEND_ERROR "Framework not found at ${framework-dir}")
+endif()
+
+if(NOT EXISTS ${plist-file})
+  message(SEND_ERROR "plist file not found at ${plist-file}")
+endif()
+
+if(NOT EXISTS ${framework-library})
+  message(SEND_ERROR "Framework library not found at ${framework-library}")
+endif()
+
+if(NOT EXISTS ${framework-resource-file})
+  message(SEND_ERROR "Framework resource file not found at ${framework-resource-file}")
+endif()
+
+if(EXISTS ${framework-versions})
+  message(SEND_ERROR "Framework versions found at ${framework-versions}")
+endif()
+
+if(EXISTS ${framework-resources})
+  message(SEND_ERROR "Framework Resources found at ${framework-resources}")
+endif()
+
+if(NOT EXISTS ${framework-header})
+  message(SEND_ERROR "Framework headers not found at ${framework-header}")
+endif()
diff --git a/Tests/RunCMake/Framework/ios.cmake b/Tests/RunCMake/Framework/ios.cmake
new file mode 100644
index 0000000..209a50d
--- /dev/null
+++ b/Tests/RunCMake/Framework/ios.cmake
@@ -0,0 +1,25 @@
+set(CMAKE_SYSTEM_NAME Darwin)
+set(CMAKE_SYSTEM_VERSION 1)
+set(UNIX True)
+set(APPLE True)
+
+set(CMAKE_MACOSX_BUNDLE TRUE)
+set(CMAKE_CXX_COMPILER_WORKS TRUE)
+set(CMAKE_C_COMPILER_WORKS TRUE)
+set(CMAKE_CROSSCOMPILING TRUE)
+set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
+set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO")
+
+find_program(XCRUN_EXECUTABLE xcrun)
+if(NOT XCRUN_EXECUTABLE)
+  message(FATAL_ERROR "xcrun not found")
+endif()
+
+execute_process(
+  COMMAND ${XCRUN_EXECUTABLE} --sdk iphoneos --show-sdk-path
+  OUTPUT_VARIABLE IOS_SDK_PATH
+  OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+set(CMAKE_OSX_SYSROOT ${IOS_SDK_PATH} CACHE PATH "Sysroot used for iOS support")
+set(CMAKE_OSX_ARCHITECTURES "armv7" CACHE STRING "Architectures to build for")
+set(CMAKE_FIND_ROOT_PATH ${IOS_SDK_PATH} CACHE PATH "Find search path root")
diff --git a/Tests/RunCMake/Framework/osx.cmake b/Tests/RunCMake/Framework/osx.cmake
new file mode 100644
index 0000000..e021fcd
--- /dev/null
+++ b/Tests/RunCMake/Framework/osx.cmake
@@ -0,0 +1,18 @@
+set(CMAKE_SYSTEM_NAME Darwin)
+set(CMAKE_SYSTEM_VERSION 1)
+set(UNIX True)
+set(APPLE True)
+
+find_program(XCRUN_EXECUTABLE xcrun)
+if(NOT XCRUN_EXECUTABLE)
+  message(FATAL_ERROR "xcrun not found")
+endif()
+
+execute_process(
+  COMMAND ${XCRUN_EXECUTABLE} --sdk macosx --show-sdk-path
+  OUTPUT_VARIABLE OSX_SDK_PATH
+  OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+set(CMAKE_OSX_SYSROOT ${OSX_SDK_PATH} CACHE PATH "Sysroot used for OSX support")
+
+set(CMAKE_FIND_ROOT_PATH ${OSX_SDK_PATH} CACHE PATH "Find search path root")
diff --git a/Tests/RunCMake/Framework/res.txt b/Tests/RunCMake/Framework/res.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-exe-stderr.txt b/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-exe-stderr.txt
new file mode 100644
index 0000000..b8d726f
--- /dev/null
+++ b/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-exe-stderr.txt
@@ -0,0 +1,15 @@
+CMake Warning \(dev\) at CMP0063-WARN-exe.cmake:[0-9]+ \(add_executable\):
+  Policy CMP0063 is not set: Honor visibility properties for all target
+  types.  Run "cmake --help-policy CMP0063" for policy details.  Use the
+  cmake_policy command to set the policy and suppress this warning.
+
+  Target "myexe" of type "EXECUTABLE" has the following visibility properties
+  set for CXX:
+
+    CXX_VISIBILITY_PRESET
+    VISIBILITY_INLINES_HIDDEN
+
+  For compatibility CMake is not honoring them for this target.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:[0-9]+ \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-yes.cmake b/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-exe.cmake
similarity index 68%
copy from Tests/RunCMake/VisibilityPreset/CMP0063-WARN-yes.cmake
copy to Tests/RunCMake/VisibilityPreset/CMP0063-WARN-exe.cmake
index 3388e4d..cef1d75 100644
--- a/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-yes.cmake
+++ b/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-exe.cmake
@@ -5,4 +5,7 @@ enable_language(CXX)
 set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
 set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
 
-include(CMP0063-Common.cmake)
+set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
+set(CMAKE_CXX_VISIBILITY_PRESET hidden)
+
+add_executable(myexe lib.cpp)
diff --git a/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-obj-stderr.txt b/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-obj-stderr.txt
new file mode 100644
index 0000000..3a7732a
--- /dev/null
+++ b/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-obj-stderr.txt
@@ -0,0 +1,15 @@
+CMake Warning \(dev\) at CMP0063-WARN-obj.cmake:[0-9]+ \(add_library\):
+  Policy CMP0063 is not set: Honor visibility properties for all target
+  types.  Run "cmake --help-policy CMP0063" for policy details.  Use the
+  cmake_policy command to set the policy and suppress this warning.
+
+  Target "myobject" of type "OBJECT_LIBRARY" has the following visibility
+  properties set for CXX:
+
+    CXX_VISIBILITY_PRESET
+    VISIBILITY_INLINES_HIDDEN
+
+  For compatibility CMake is not honoring them for this target.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:[0-9]+ \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-yes.cmake b/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-obj.cmake
similarity index 67%
copy from Tests/RunCMake/VisibilityPreset/CMP0063-WARN-yes.cmake
copy to Tests/RunCMake/VisibilityPreset/CMP0063-WARN-obj.cmake
index 3388e4d..81d1c33 100644
--- a/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-yes.cmake
+++ b/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-obj.cmake
@@ -5,4 +5,7 @@ enable_language(CXX)
 set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
 set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
 
-include(CMP0063-Common.cmake)
+set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
+set(CMAKE_CXX_VISIBILITY_PRESET hidden)
+
+add_library(myobject OBJECT lib.cpp)
diff --git a/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-sta-stderr.txt b/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-sta-stderr.txt
new file mode 100644
index 0000000..1efa1b5
--- /dev/null
+++ b/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-sta-stderr.txt
@@ -0,0 +1,15 @@
+CMake Warning \(dev\) at CMP0063-WARN-sta.cmake:[0-9]+ \(add_library\):
+  Policy CMP0063 is not set: Honor visibility properties for all target
+  types.  Run "cmake --help-policy CMP0063" for policy details.  Use the
+  cmake_policy command to set the policy and suppress this warning.
+
+  Target "mystatic" of type "STATIC_LIBRARY" has the following visibility
+  properties set for CXX:
+
+    CXX_VISIBILITY_PRESET
+    VISIBILITY_INLINES_HIDDEN
+
+  For compatibility CMake is not honoring them for this target.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:[0-9]+ \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-yes.cmake b/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-sta.cmake
similarity index 67%
rename from Tests/RunCMake/VisibilityPreset/CMP0063-WARN-yes.cmake
rename to Tests/RunCMake/VisibilityPreset/CMP0063-WARN-sta.cmake
index 3388e4d..132e076 100644
--- a/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-yes.cmake
+++ b/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-sta.cmake
@@ -5,4 +5,7 @@ enable_language(CXX)
 set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
 set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
 
-include(CMP0063-Common.cmake)
+set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
+set(CMAKE_CXX_VISIBILITY_PRESET hidden)
+
+add_library(mystatic STATIC lib.cpp)
diff --git a/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-yes-stderr.txt b/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-yes-stderr.txt
deleted file mode 100644
index 59a4b8f..0000000
--- a/Tests/RunCMake/VisibilityPreset/CMP0063-WARN-yes-stderr.txt
+++ /dev/null
@@ -1,50 +0,0 @@
-^CMake Warning \(dev\) at CMP0063-Common.cmake:[0-9]+ \(add_executable\):
-  Policy CMP0063 is not set: Honor visibility properties for all target
-  types.  Run "cmake --help-policy CMP0063" for policy details.  Use the
-  cmake_policy command to set the policy and suppress this warning.
-
-  Target "myexe" of type "EXECUTABLE" has the following visibility properties
-  set for CXX:
-
-    CXX_VISIBILITY_PRESET
-    VISIBILITY_INLINES_HIDDEN
-
-  For compatibility CMake is not honoring them for this target.
-Call Stack \(most recent call first\):
-  CMP0063-WARN-yes.cmake:[0-9]+ \(include\)
-  CMakeLists.txt:[0-9]+ \(include\)
-This warning is for project developers.  Use -Wno-dev to suppress it.
-+
-CMake Warning \(dev\) at CMP0063-Common.cmake:[0-9]+ \(add_library\):
-  Policy CMP0063 is not set: Honor visibility properties for all target
-  types.  Run "cmake --help-policy CMP0063" for policy details.  Use the
-  cmake_policy command to set the policy and suppress this warning.
-
-  Target "myobject" of type "OBJECT_LIBRARY" has the following visibility
-  properties set for CXX:
-
-    CXX_VISIBILITY_PRESET
-    VISIBILITY_INLINES_HIDDEN
-
-  For compatibility CMake is not honoring them for this target.
-Call Stack \(most recent call first\):
-  CMP0063-WARN-yes.cmake:[0-9]+ \(include\)
-  CMakeLists.txt:[0-9]+ \(include\)
-This warning is for project developers.  Use -Wno-dev to suppress it.
-+
-CMake Warning \(dev\) at CMP0063-Common.cmake:[0-9]+ \(add_library\):
-  Policy CMP0063 is not set: Honor visibility properties for all target
-  types.  Run "cmake --help-policy CMP0063" for policy details.  Use the
-  cmake_policy command to set the policy and suppress this warning.
-
-  Target "mystatic" of type "STATIC_LIBRARY" has the following visibility
-  properties set for CXX:
-
-    CXX_VISIBILITY_PRESET
-    VISIBILITY_INLINES_HIDDEN
-
-  For compatibility CMake is not honoring them for this target.
-Call Stack \(most recent call first\):
-  CMP0063-WARN-yes.cmake:[0-9]+ \(include\)
-  CMakeLists.txt:[0-9]+ \(include\)
-This warning is for project developers.  Use -Wno-dev to suppress it.$
diff --git a/Tests/RunCMake/VisibilityPreset/RunCMakeTest.cmake b/Tests/RunCMake/VisibilityPreset/RunCMakeTest.cmake
index c7eb808..7a000ee 100644
--- a/Tests/RunCMake/VisibilityPreset/RunCMakeTest.cmake
+++ b/Tests/RunCMake/VisibilityPreset/RunCMakeTest.cmake
@@ -2,6 +2,8 @@ include(RunCMake)
 
 run_cmake(PropertyTypo)
 run_cmake(CMP0063-OLD)
-run_cmake(CMP0063-WARN-yes)
+run_cmake(CMP0063-WARN-exe)
+run_cmake(CMP0063-WARN-obj)
+run_cmake(CMP0063-WARN-sta)
 run_cmake(CMP0063-WARN-no)
 run_cmake(CMP0063-NEW)
diff --git a/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake b/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake
index 8ab618b..395c74b 100644
--- a/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake
+++ b/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake
@@ -3,7 +3,11 @@ include(RunCMake)
 run_cmake(XcodeFileType)
 run_cmake(XcodeAttributeGenex)
 run_cmake(XcodeAttributeGenexError)
+run_cmake(XcodeObjectNeedsEscape)
 run_cmake(XcodeObjectNeedsQuote)
+run_cmake(XcodeOptimizationFlags)
+run_cmake(XcodePreserveNonOptimizationFlags)
+run_cmake(XcodePreserveObjcFlag)
 if (NOT XCODE_VERSION VERSION_LESS 6)
   run_cmake(XcodePlatformFrameworks)
 endif()
@@ -55,7 +59,75 @@ if(NOT XCODE_VERSION VERSION_LESS 5)
 endif()
 
 if(NOT XCODE_VERSION VERSION_LESS 7)
+  set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeBundlesWatchOS-build)
+  set(RunCMake_TEST_NO_CLEAN 1)
+  set(RunCMake_TEST_OPTIONS "-DTEST_WATCHOS=ON")
+
+  file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+  file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+
+  run_cmake(XcodeBundles)
+  run_cmake_command(XcodeBundles-build ${CMAKE_COMMAND} --build .)
+
+  unset(RunCMake_TEST_BINARY_DIR)
+  unset(RunCMake_TEST_NO_CLEAN)
+  unset(RunCMake_TEST_OPTIONS)
+endif()
+
+if(NOT XCODE_VERSION VERSION_LESS 7.1)
+  set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeBundlesTvOS-build)
+  set(RunCMake_TEST_NO_CLEAN 1)
+  set(RunCMake_TEST_OPTIONS "-DTEST_TVOS=ON")
+
+  file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+  file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+
+  run_cmake(XcodeBundles)
+  run_cmake_command(XcodeBundles-build ${CMAKE_COMMAND} --build .)
+
+  unset(RunCMake_TEST_BINARY_DIR)
+  unset(RunCMake_TEST_NO_CLEAN)
+  unset(RunCMake_TEST_OPTIONS)
+endif()
+
+if(NOT XCODE_VERSION VERSION_LESS 7)
   set(RunCMake_TEST_OPTIONS "-DCMAKE_TOOLCHAIN_FILE=${RunCMake_SOURCE_DIR}/osx.cmake")
   run_cmake(XcodeTbdStub)
   unset(RunCMake_TEST_OPTIONS)
 endif()
+
+if(NOT XCODE_VERSION VERSION_LESS 6)
+  set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeIOSInstallCombined-build)
+  set(RunCMake_TEST_NO_CLEAN 1)
+  set(RunCMake_TEST_OPTIONS
+    "-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/_install"
+    "-DCMAKE_IOS_INSTALL_COMBINED=YES")
+
+  file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+  file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+
+  run_cmake(XcodeIOSInstallCombined)
+  run_cmake_command(XcodeIOSInstallCombined-build ${CMAKE_COMMAND} --build .)
+  run_cmake_command(XcodeIOSInstallCombined-install ${CMAKE_COMMAND} --build . --target install)
+
+  unset(RunCMake_TEST_BINARY_DIR)
+  unset(RunCMake_TEST_NO_CLEAN)
+  unset(RunCMake_TEST_OPTIONS)
+
+  set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeIOSInstallCombinedPrune-build)
+  set(RunCMake_TEST_NO_CLEAN 1)
+  set(RunCMake_TEST_OPTIONS
+    "-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/_install"
+    "-DCMAKE_IOS_INSTALL_COMBINED=YES")
+
+  file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+  file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+
+  run_cmake(XcodeIOSInstallCombinedPrune)
+  run_cmake_command(XcodeIOSInstallCombinedPrune-build ${CMAKE_COMMAND} --build .)
+  run_cmake_command(XcodeIOSInstallCombinedPrune-install ${CMAKE_COMMAND} --build . --target install)
+
+  unset(RunCMake_TEST_BINARY_DIR)
+  unset(RunCMake_TEST_NO_CLEAN)
+  unset(RunCMake_TEST_OPTIONS)
+endif()
diff --git a/Tests/RunCMake/XcodeProject/XcodeAttributeGenex-check.cmake b/Tests/RunCMake/XcodeProject/XcodeAttributeGenex-check.cmake
index 637df0f..8a39506 100644
--- a/Tests/RunCMake/XcodeProject/XcodeAttributeGenex-check.cmake
+++ b/Tests/RunCMake/XcodeProject/XcodeAttributeGenex-check.cmake
@@ -1,3 +1,5 @@
+# per target attribute with genex
+
 set(expect "TEST_HOST = \"[^;\"]*Tests/RunCMake/XcodeProject/XcodeAttributeGenex-build/[^;\"/]*/some\"")
 file(STRINGS ${RunCMake_TEST_BINARY_DIR}/XcodeAttributeGenex.xcodeproj/project.pbxproj actual
      REGEX "TEST_HOST = .*;" LIMIT_COUNT 1)
@@ -5,3 +7,49 @@ if(NOT "${actual}" MATCHES "${expect}")
   message(SEND_ERROR "The actual project contains the line:\n ${actual}\n"
     "which does not match expected regex:\n ${expect}\n")
 endif()
+
+# per target attribute with variant
+
+file(STRINGS ${RunCMake_TEST_BINARY_DIR}/XcodeAttributeGenex.xcodeproj/project.pbxproj actual
+     REGEX "CONFIG_SPECIFIC = .*;")
+list(REMOVE_DUPLICATES actual)
+
+set(expect "CONFIG_SPECIFIC = general")
+if(NOT "${actual}" MATCHES "${expect}")
+  message(SEND_ERROR "The actual project contains the line:\n ${actual}\n"
+    "which does not match expected regex:\n ${expect}\n")
+endif()
+
+set(expect "CONFIG_SPECIFIC = release")
+if(NOT "${actual}" MATCHES "${expect}")
+  message(SEND_ERROR "The actual project contains the line:\n ${actual}\n"
+    "which does not match expected regex:\n ${expect}\n")
+endif()
+
+# global attribute with genex
+
+set(expect "ANOTHER_GLOBAL = \"[^;\"]*Tests/RunCMake/XcodeProject/XcodeAttributeGenex-build/[^;\"/]*/another\"")
+file(STRINGS ${RunCMake_TEST_BINARY_DIR}/XcodeAttributeGenex.xcodeproj/project.pbxproj actual
+     REGEX "ANOTHER_GLOBAL = .*;" LIMIT_COUNT 1)
+if(NOT "${actual}" MATCHES "${expect}")
+  message(SEND_ERROR "The actual project contains the line:\n ${actual}\n"
+    "which does not match expected regex:\n ${expect}\n")
+endif()
+
+# global attribute with variant
+
+file(STRINGS ${RunCMake_TEST_BINARY_DIR}/XcodeAttributeGenex.xcodeproj/project.pbxproj actual
+     REGEX "ANOTHER_CONFIG = .*;" LIMIT_COUNT 4)
+list(REMOVE_DUPLICATES actual)
+
+set(expect "ANOTHER_CONFIG = general")
+if(NOT "${actual}" MATCHES "${expect}")
+  message(SEND_ERROR "The actual project contains the line:\n ${actual}\n"
+    "which does not match expected regex:\n ${expect}\n")
+endif()
+
+set(expect "ANOTHER_CONFIG = debug")
+if(NOT "${actual}" MATCHES "${expect}")
+  message(SEND_ERROR "The actual project contains the line:\n ${actual}\n"
+    "which does not match expected regex:\n ${expect}\n")
+endif()
diff --git a/Tests/RunCMake/XcodeProject/XcodeAttributeGenex.cmake b/Tests/RunCMake/XcodeProject/XcodeAttributeGenex.cmake
index 760b882..d8cb3bd 100644
--- a/Tests/RunCMake/XcodeProject/XcodeAttributeGenex.cmake
+++ b/Tests/RunCMake/XcodeProject/XcodeAttributeGenex.cmake
@@ -1,4 +1,16 @@
 enable_language(C)
 add_executable(some main.c)
 add_executable(another main.c)
-set_property(TARGET another PROPERTY XCODE_ATTRIBUTE_TEST_HOST "$<TARGET_FILE:some>")
+set_target_properties(another PROPERTIES
+  # per target attribute with genex
+  XCODE_ATTRIBUTE_TEST_HOST "$<TARGET_FILE:some>"
+  # per target attribute with variant
+  XCODE_ATTRIBUTE_CONFIG_SPECIFIC[variant=Release] "release"
+  XCODE_ATTRIBUTE_CONFIG_SPECIFIC "general")
+
+# global attribute with genex
+set(CMAKE_XCODE_ATTRIBUTE_ANOTHER_GLOBAL "$<TARGET_FILE:another>")
+
+# global attribute with variant
+set(CMAKE_XCODE_ATTRIBUTE_ANOTHER_CONFIG "general")
+set(CMAKE_XCODE_ATTRIBUTE_ANOTHER_CONFIG[variant=Debug] "debug")
diff --git a/Tests/RunCMake/XcodeProject/XcodeBundles.cmake b/Tests/RunCMake/XcodeProject/XcodeBundles.cmake
index 2cbccfa..0fdc6af 100644
--- a/Tests/RunCMake/XcodeProject/XcodeBundles.cmake
+++ b/Tests/RunCMake/XcodeProject/XcodeBundles.cmake
@@ -10,6 +10,22 @@ if(TEST_IOS)
   set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO")
 endif(TEST_IOS)
 
+if(TEST_WATCHOS)
+  set(CMAKE_OSX_SYSROOT watchos)
+  set(CMAKE_OSX_ARCHITECTURES "armv7k")
+  set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
+  set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")
+  set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
+endif()
+
+if(TEST_TVOS)
+  set(CMAKE_OSX_SYSROOT appletvos)
+  set(CMAKE_OSX_ARCHITECTURES "arm64")
+  set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
+  set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")
+  set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
+endif()
+
 # App Bundle
 
 add_executable(AppBundle MACOSX_BUNDLE main.m)
@@ -35,11 +51,13 @@ endif()
 
 # Bundle
 
-add_library(Bundle MODULE main.c)
-set_target_properties(Bundle PROPERTIES BUNDLE TRUE)
+if(NOT CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE)
+  add_library(Bundle MODULE main.c)
+  set_target_properties(Bundle PROPERTIES BUNDLE TRUE)
 
-add_custom_target(BundleTest ALL
-  COMMAND ${CMAKE_COMMAND} -E copy
-    "$<TARGET_FILE:Bundle>" "$<TARGET_FILE:Bundle>.old")
+  add_custom_target(BundleTest ALL
+    COMMAND ${CMAKE_COMMAND} -E copy
+      "$<TARGET_FILE:Bundle>" "$<TARGET_FILE:Bundle>.old")
 
-add_dependencies(BundleTest Bundle)
+  add_dependencies(BundleTest Bundle)
+endif()
diff --git a/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombined-install-check.cmake b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombined-install-check.cmake
new file mode 100644
index 0000000..a1c0671
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombined-install-check.cmake
@@ -0,0 +1,30 @@
+function(verify_architectures file)
+  execute_process(
+    COMMAND xcrun otool -vf ${RunCMake_TEST_BINARY_DIR}/_install/${file}
+    OUTPUT_VARIABLE otool_out
+    ERROR_VARIABLE otool_err
+    RESULT_VARIABLE otool_result)
+  if(NOT otool_result EQUAL "0")
+    message(SEND_ERROR "Could not retrieve fat headers: ${otool_err}")
+    return()
+  endif()
+
+  string(REGEX MATCHALL "architecture [^ \n\t]+" architectures ${otool_out})
+  string(REPLACE "architecture " "" actual "${architectures}")
+  list(SORT actual)
+
+  set(expected arm64 armv7 i386 x86_64)
+
+  if(NOT actual STREQUAL expected)
+    message(SEND_ERROR
+      "The actual library contains the architectures:\n ${actual} \n"
+      "which do not match expected ones:\n ${expected} \n"
+      "otool output:\n${otool_out}")
+  endif()
+endfunction()
+
+verify_architectures(bin/foo_app.app/foo_app)
+verify_architectures(lib/libfoo_static.a)
+verify_architectures(lib/libfoo_shared.dylib)
+verify_architectures(lib/foo_bundle.bundle/foo_bundle)
+verify_architectures(lib/foo_framework.framework/foo_framework)
diff --git a/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombined.cmake b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombined.cmake
new file mode 100644
index 0000000..fc830b1
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombined.cmake
@@ -0,0 +1,27 @@
+cmake_minimum_required(VERSION 3.3)
+
+project(IOSInstallCombined CXX)
+
+set(CMAKE_OSX_SYSROOT iphoneos)
+set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
+set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf")
+set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO")
+
+set(CMAKE_OSX_ARCHITECTURES "armv7;arm64;i386;x86_64")
+
+add_executable(foo_app MACOSX_BUNDLE main.cpp)
+install(TARGETS foo_app BUNDLE DESTINATION bin)
+
+add_library(foo_static STATIC foo.cpp)
+install(TARGETS foo_static ARCHIVE DESTINATION lib)
+
+add_library(foo_shared SHARED foo.cpp)
+install(TARGETS foo_shared LIBRARY DESTINATION lib)
+
+add_library(foo_bundle MODULE foo.cpp)
+set_target_properties(foo_bundle PROPERTIES BUNDLE TRUE)
+install(TARGETS foo_bundle LIBRARY DESTINATION lib)
+
+add_library(foo_framework SHARED foo.cpp)
+set_target_properties(foo_framework PROPERTIES FRAMEWORK TRUE)
+install(TARGETS foo_framework FRAMEWORK DESTINATION lib)
diff --git a/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedPrune-install-check.cmake b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedPrune-install-check.cmake
new file mode 100644
index 0000000..83da17d
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedPrune-install-check.cmake
@@ -0,0 +1,26 @@
+function(verify_architectures file)
+  execute_process(
+    COMMAND xcrun otool -vf ${RunCMake_TEST_BINARY_DIR}/_install/${file}
+    OUTPUT_VARIABLE otool_out
+    ERROR_VARIABLE otool_err
+    RESULT_VARIABLE otool_result)
+  if(NOT otool_result EQUAL "0")
+    message(SEND_ERROR "Could not retrieve fat headers: ${otool_err}")
+    return()
+  endif()
+
+  string(REGEX MATCHALL "architecture [^ \n\t]+" architectures ${otool_out})
+  string(REPLACE "architecture " "" actual "${architectures}")
+  list(SORT actual)
+
+  set(expected armv7 x86_64)
+
+  if(NOT actual STREQUAL expected)
+    message(SEND_ERROR
+      "The actual library contains the architectures:\n ${actual} \n"
+      "which do not match expected ones:\n ${expected} \n"
+      "otool output:\n${otool_out}")
+  endif()
+endfunction()
+
+verify_architectures(lib/libfoo.dylib)
diff --git a/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedPrune-install-stdout.txt b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedPrune-install-stdout.txt
new file mode 100644
index 0000000..28edadc
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedPrune-install-stdout.txt
@@ -0,0 +1,2 @@
+.*Unexpected architecture `i386` detected.*
+.*Unexpected architecture `arm64` detected.*
\ No newline at end of file
diff --git a/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedPrune.cmake b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedPrune.cmake
new file mode 100644
index 0000000..b47d3a5
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedPrune.cmake
@@ -0,0 +1,36 @@
+cmake_minimum_required(VERSION 3.3)
+
+project(XcodeIOSInstallCombinedPrune CXX)
+
+set(CMAKE_OSX_SYSROOT iphoneos)
+set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
+set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf")
+
+add_library(foo SHARED foo.cpp)
+install(TARGETS foo DESTINATION lib)
+
+add_library(baz SHARED foo.cpp)
+set_target_properties(
+  foo baz
+  PROPERTIES
+  XCODE_ATTRIBUTE_ARCHS[sdk=iphoneos*] armv7
+  XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphoneos*] armv7
+  XCODE_ATTRIBUTE_ARCHS[sdk=iphonesimulator*] x86_64
+  XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphonesimulator*] x86_64
+)
+
+add_library(boo SHARED foo.cpp)
+set_target_properties(
+  boo
+  PROPERTIES
+  XCODE_ATTRIBUTE_ARCHS[sdk=iphoneos*] arm64
+  XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphoneos*] arm64
+  XCODE_ATTRIBUTE_ARCHS[sdk=iphonesimulator*] i386
+  XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphonesimulator*] i386
+)
+
+add_custom_command(
+  TARGET foo
+  POST_BUILD
+  COMMAND lipo -create $<TARGET_FILE:baz> $<TARGET_FILE:boo> -output $<TARGET_FILE:foo>
+)
diff --git a/Tests/RunCMake/XcodeProject/XcodeObjectNeedsEscape-check.cmake b/Tests/RunCMake/XcodeProject/XcodeObjectNeedsEscape-check.cmake
new file mode 100644
index 0000000..c34e3fe
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodeObjectNeedsEscape-check.cmake
@@ -0,0 +1,7 @@
+set(expect "-DKDESRCDIR=\\\\\\\\\\\\\"foo\\\\\\\\\\\\\"")
+file(STRINGS ${RunCMake_TEST_BINARY_DIR}/XcodeObjectNeedsEscape.xcodeproj/project.pbxproj actual
+     REGEX "OTHER_CPLUSPLUSFLAGS = [^;]*;" LIMIT_COUNT 1)
+if(NOT "${actual}" MATCHES "${expect}")
+  message(SEND_ERROR "The actual project contains the line:\n ${actual}\n"
+    "which does not match expected regex:\n ${expect}\n")
+endif()
diff --git a/Tests/RunCMake/XcodeProject/XcodeObjectNeedsEscape.cmake b/Tests/RunCMake/XcodeProject/XcodeObjectNeedsEscape.cmake
new file mode 100644
index 0000000..7606a19
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodeObjectNeedsEscape.cmake
@@ -0,0 +1,3 @@
+enable_language(CXX)
+string(APPEND CMAKE_CXX_FLAGS " -DKDESRCDIR=\\\"foo\\\"")
+add_library(foo STATIC foo.cpp)
diff --git a/Tests/RunCMake/XcodeProject/XcodeOptimizationFlags-check.cmake b/Tests/RunCMake/XcodeProject/XcodeOptimizationFlags-check.cmake
new file mode 100644
index 0000000..f5595b3
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodeOptimizationFlags-check.cmake
@@ -0,0 +1,7 @@
+foreach(level 1 2 3 s fast)
+  file(STRINGS ${RunCMake_TEST_BINARY_DIR}/XcodeOptimizationFlags.xcodeproj/project.pbxproj actual-${level}
+       REGEX "GCC_OPTIMIZATION_LEVEL = ${level};" LIMIT_COUNT 1)
+  if(NOT actual-${level})
+    message(SEND_ERROR "Optimization level '${level}' not found in Xcode project.")
+  endif()
+endforeach()
diff --git a/Tests/RunCMake/XcodeProject/XcodeOptimizationFlags.cmake b/Tests/RunCMake/XcodeProject/XcodeOptimizationFlags.cmake
new file mode 100644
index 0000000..e14bf80
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodeOptimizationFlags.cmake
@@ -0,0 +1,20 @@
+set(CMAKE_CONFIGURATION_TYPES "Release" CACHE INTERNAL "Supported configuration types")
+
+set(CMAKE_CXX_FLAGS_RELEASE "")
+
+project(XcodeOptimizationFlags CXX)
+
+add_library(fooO1 STATIC foo.cpp)
+set_target_properties(fooO1 PROPERTIES COMPILE_OPTIONS -O1)
+
+add_library(fooO2 STATIC foo.cpp)
+set_target_properties(fooO2 PROPERTIES COMPILE_OPTIONS -O2)
+
+add_library(fooO3 STATIC foo.cpp)
+set_target_properties(fooO3 PROPERTIES COMPILE_OPTIONS -O3)
+
+add_library(fooOs STATIC foo.cpp)
+set_target_properties(fooOs PROPERTIES COMPILE_OPTIONS -Os)
+
+add_library(fooOfast STATIC foo.cpp)
+set_target_properties(fooOfast PROPERTIES COMPILE_OPTIONS -Ofast)
diff --git a/Tests/RunCMake/XcodeProject/XcodePreserveNonOptimizationFlags-check.cmake b/Tests/RunCMake/XcodeProject/XcodePreserveNonOptimizationFlags-check.cmake
new file mode 100644
index 0000000..2f6c03d
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodePreserveNonOptimizationFlags-check.cmake
@@ -0,0 +1,8 @@
+file(STRINGS ${RunCMake_TEST_BINARY_DIR}/XcodePreserveNonOptimizationFlags.xcodeproj/project.pbxproj actual
+     REGEX "OTHER_CPLUSPLUSFLAGS = [^;]*;")
+foreach(expect "-DA" "-DB +-DC" "-DD")
+  if(NOT "${actual}" MATCHES "${expect}")
+    message(SEND_ERROR "The actual project contains the lines:\n ${actual}\n"
+      "which do not match expected regex:\n ${expect}\n")
+  endif()
+endforeach()
diff --git a/Tests/RunCMake/XcodeProject/XcodePreserveNonOptimizationFlags.cmake b/Tests/RunCMake/XcodeProject/XcodePreserveNonOptimizationFlags.cmake
new file mode 100644
index 0000000..16f0381
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodePreserveNonOptimizationFlags.cmake
@@ -0,0 +1,12 @@
+set(CMAKE_CONFIGURATION_TYPES "Release" CACHE INTERNAL "Supported configuration types")
+
+project(XcodePreserveNonOptimizationFlags CXX)
+
+add_library(preserveStart STATIC foo.cpp)
+set_property(TARGET preserveStart PROPERTY COMPILE_OPTIONS -DA -O1)
+
+add_library(preserveBoth STATIC foo.cpp)
+set_property(TARGET preserveBoth PROPERTY COMPILE_OPTIONS -DB -O1 -DC)
+
+add_library(preserveEnd STATIC foo.cpp)
+set_property(TARGET preserveEnd PROPERTY COMPILE_OPTIONS -O1 -DD)
diff --git a/Tests/RunCMake/XcodeProject/XcodePreserveObjcFlag-check.cmake b/Tests/RunCMake/XcodeProject/XcodePreserveObjcFlag-check.cmake
new file mode 100644
index 0000000..332906f
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodePreserveObjcFlag-check.cmake
@@ -0,0 +1,7 @@
+set(expect "-ObjC")
+file(STRINGS ${RunCMake_TEST_BINARY_DIR}/XcodePreserveObjcFlag.xcodeproj/project.pbxproj actual
+     REGEX "OTHER_CPLUSPLUSFLAGS = [^;]*;" LIMIT_COUNT 1)
+if(NOT "${actual}" MATCHES "${expect}")
+  message(SEND_ERROR "The actual project contains the line:\n ${actual}\n"
+    "which does not match expected regex:\n ${expect}\n")
+endif()
diff --git a/Tests/RunCMake/XcodeProject/XcodePreserveObjcFlag.cmake b/Tests/RunCMake/XcodeProject/XcodePreserveObjcFlag.cmake
new file mode 100644
index 0000000..64db633
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodePreserveObjcFlag.cmake
@@ -0,0 +1,6 @@
+set(CMAKE_CONFIGURATION_TYPES "Release" CACHE INTERNAL "Supported configuration types")
+
+project(XcodePreserveObjcFlag CXX)
+
+add_library(foo STATIC foo.cpp)
+set_target_properties(foo PROPERTIES COMPILE_OPTIONS -ObjC)
diff --git a/Tests/RunCMake/XcodeProject/main.cpp b/Tests/RunCMake/XcodeProject/main.cpp
new file mode 100644
index 0000000..1695921
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/main.cpp
@@ -0,0 +1,3 @@
+int main(int argc, const char * argv[]) {
+    return 0;
+}
diff --git a/Tests/RunCMake/add_custom_command/RunCMakeTest.cmake b/Tests/RunCMake/add_custom_command/RunCMakeTest.cmake
index 2f5c938..397c63d 100644
--- a/Tests/RunCMake/add_custom_command/RunCMakeTest.cmake
+++ b/Tests/RunCMake/add_custom_command/RunCMakeTest.cmake
@@ -8,3 +8,5 @@ run_cmake(NoOutputOrTarget)
 run_cmake(OutputAndTarget)
 run_cmake(SourceByproducts)
 run_cmake(SourceUsesTerminal)
+run_cmake(TargetImported)
+run_cmake(TargetNotInDir)
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/add_custom_command/TargetImported-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/add_custom_command/TargetImported-result.txt
diff --git a/Tests/RunCMake/add_custom_command/TargetImported-stderr.txt b/Tests/RunCMake/add_custom_command/TargetImported-stderr.txt
new file mode 100644
index 0000000..44c4ad8
--- /dev/null
+++ b/Tests/RunCMake/add_custom_command/TargetImported-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at TargetImported.cmake:2 \(add_custom_command\):
+  TARGET 'TargetImported' is IMPORTED and does not build here.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/add_custom_command/TargetImported.cmake b/Tests/RunCMake/add_custom_command/TargetImported.cmake
new file mode 100644
index 0000000..c0f2d66
--- /dev/null
+++ b/Tests/RunCMake/add_custom_command/TargetImported.cmake
@@ -0,0 +1,2 @@
+add_library(TargetImported UNKNOWN IMPORTED)
+add_custom_command(TARGET TargetImported COMMAND ${CMAKE_COMMAND} -E echo tada)
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/add_custom_command/TargetNotInDir-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/add_custom_command/TargetNotInDir-result.txt
diff --git a/Tests/RunCMake/add_custom_command/TargetNotInDir-stderr.txt b/Tests/RunCMake/add_custom_command/TargetNotInDir-stderr.txt
new file mode 100644
index 0000000..91876a0
--- /dev/null
+++ b/Tests/RunCMake/add_custom_command/TargetNotInDir-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at TargetNotInDir.cmake:2 \(add_custom_command\):
+  TARGET 'TargetNotInDir' was not created in this directory.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/add_custom_command/TargetNotInDir.cmake b/Tests/RunCMake/add_custom_command/TargetNotInDir.cmake
new file mode 100644
index 0000000..a551026
--- /dev/null
+++ b/Tests/RunCMake/add_custom_command/TargetNotInDir.cmake
@@ -0,0 +1,2 @@
+add_subdirectory(TargetNotInDir)
+add_custom_command(TARGET TargetNotInDir COMMAND ${CMAKE_COMMAND} -E echo tada)
diff --git a/Tests/RunCMake/add_custom_command/TargetNotInDir/CMakeLists.txt b/Tests/RunCMake/add_custom_command/TargetNotInDir/CMakeLists.txt
new file mode 100644
index 0000000..3d51d27
--- /dev/null
+++ b/Tests/RunCMake/add_custom_command/TargetNotInDir/CMakeLists.txt
@@ -0,0 +1 @@
+add_custom_target(TargetNotInDir)
diff --git a/Tests/RunCMake/install/CMakeLists.txt b/Tests/RunCMake/cmake_parse_arguments/CMakeLists.txt
similarity index 61%
copy from Tests/RunCMake/install/CMakeLists.txt
copy to Tests/RunCMake/cmake_parse_arguments/CMakeLists.txt
index 4b3de84..6dd8cdf 100644
--- a/Tests/RunCMake/install/CMakeLists.txt
+++ b/Tests/RunCMake/cmake_parse_arguments/CMakeLists.txt
@@ -1,3 +1,3 @@
-cmake_minimum_required(VERSION 2.8.12)
+cmake_minimum_required(VERSION 3.4)
 project(${RunCMake_TEST} NONE)
 include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/cmake_parse_arguments/CornerCases.cmake b/Tests/RunCMake/cmake_parse_arguments/CornerCases.cmake
new file mode 100644
index 0000000..72c82ab
--- /dev/null
+++ b/Tests/RunCMake/cmake_parse_arguments/CornerCases.cmake
@@ -0,0 +1,34 @@
+include(${CMAKE_CURRENT_LIST_DIR}/test_utils.cmake)
+
+# example from the documentation
+# OPTIONAL is a keyword and therefore terminates the definition of
+# the multi-value DEFINITION before even a single value has been added
+
+set(options OPTIONAL FAST)
+set(oneValueArgs DESTINATION RENAME)
+set(multiValueArgs TARGETS CONFIGURATIONS)
+cmake_parse_arguments(MY_INSTALL "${options}" "${oneValueArgs}"
+                      "${multiValueArgs}"
+                      TARGETS foo DESTINATION OPTIONAL)
+
+TEST(MY_INSTALL_DESTINATION UNDEFINED)
+TEST(MY_INSTALL_OPTIONAL TRUE)
+
+macro(foo)
+  set(_options )
+  set(_oneValueArgs FOO)
+  set(_multiValueArgs )
+  cmake_parse_arguments(_FOO2 "${_options}"
+                              "${_oneValueArgs}"
+                              "${_multiValueArgs}"
+                              "${ARGN}")
+  cmake_parse_arguments(_FOO1 "${_options}"
+                              "${_oneValueArgs}"
+                              "${_multiValueArgs}"
+                              ${ARGN})
+endmacro()
+
+foo(FOO foo)
+
+TEST(_FOO1_FOO foo)
+TEST(_FOO2_FOO foo)
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/cmake_parse_arguments/Errors-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/cmake_parse_arguments/Errors-result.txt
diff --git a/Tests/RunCMake/cmake_parse_arguments/Errors-stderr.txt b/Tests/RunCMake/cmake_parse_arguments/Errors-stderr.txt
new file mode 100644
index 0000000..f2ba9b8
--- /dev/null
+++ b/Tests/RunCMake/cmake_parse_arguments/Errors-stderr.txt
@@ -0,0 +1,44 @@
+CMake Error at Errors\.cmake:2 \(cmake_parse_arguments\):
+  cmake_parse_arguments must be called with at least 4 arguments\.
+Call Stack \(most recent call first\):
+  CMakeLists\.txt:3 \(include\)
++
+CMake Error at Errors\.cmake:3 \(cmake_parse_arguments\):
+  cmake_parse_arguments must be called with at least 4 arguments\.
+Call Stack \(most recent call first\):
+  CMakeLists\.txt:3 \(include\)
++
+CMake Error at Errors\.cmake:4 \(cmake_parse_arguments\):
+  cmake_parse_arguments must be called with at least 4 arguments\.
+Call Stack \(most recent call first\):
+  CMakeLists\.txt:3 \(include\)
++
+CMake Warning at Errors\.cmake:8 \(cmake_parse_arguments\):
+  keyword defined more than once: OPT
+Call Stack \(most recent call first\):
+  CMakeLists\.txt:3 \(include\)
++
+CMake Warning at Errors\.cmake:9 \(cmake_parse_arguments\):
+  keyword defined more than once: OPT
+Call Stack \(most recent call first\):
+  CMakeLists\.txt:3 \(include\)
++
+CMake Warning at Errors\.cmake:10 \(cmake_parse_arguments\):
+  keyword defined more than once: OPT
+Call Stack \(most recent call first\):
+  CMakeLists\.txt:3 \(include\)
++
+CMake Warning at Errors\.cmake:12 \(cmake_parse_arguments\):
+  keyword defined more than once: OPT
+Call Stack \(most recent call first\):
+  CMakeLists\.txt:3 \(include\)
++
+CMake Warning at Errors\.cmake:13 \(cmake_parse_arguments\):
+  keyword defined more than once: OPT
+Call Stack \(most recent call first\):
+  CMakeLists\.txt:3 \(include\)
++
+CMake Warning at Errors\.cmake:14 \(cmake_parse_arguments\):
+  keyword defined more than once: OPT
+Call Stack \(most recent call first\):
+  CMakeLists\.txt:3 \(include\)
diff --git a/Tests/RunCMake/cmake_parse_arguments/Errors.cmake b/Tests/RunCMake/cmake_parse_arguments/Errors.cmake
new file mode 100644
index 0000000..6a38081
--- /dev/null
+++ b/Tests/RunCMake/cmake_parse_arguments/Errors.cmake
@@ -0,0 +1,14 @@
+# wrong argument count
+cmake_parse_arguments()
+cmake_parse_arguments(prefix OPT)
+cmake_parse_arguments(prefix OPT SINGLE)
+cmake_parse_arguments(prefix OPT SINGLE MULTI) # not an error
+
+# duplicate keywords
+cmake_parse_arguments(prefix "OPT;OPT" "" "")
+cmake_parse_arguments(prefix "" "OPT;OPT" "")
+cmake_parse_arguments(prefix "" "" "OPT;OPT")
+
+cmake_parse_arguments(prefix "OPT" "OPT" "")
+cmake_parse_arguments(prefix "" "OPT" "OPT")
+cmake_parse_arguments(prefix "OPT" "" "OPT")
diff --git a/Tests/RunCMake/cmake_parse_arguments/Initialization.cmake b/Tests/RunCMake/cmake_parse_arguments/Initialization.cmake
new file mode 100644
index 0000000..462f923
--- /dev/null
+++ b/Tests/RunCMake/cmake_parse_arguments/Initialization.cmake
@@ -0,0 +1,68 @@
+include(${CMAKE_CURRENT_LIST_DIR}/test_utils.cmake)
+
+# unparsed arguments
+cmake_parse_arguments(pref "" "" "")
+TEST(pref_UNPARSED_ARGUMENTS UNDEFINED)
+
+cmake_parse_arguments(pref "" "" "" FOO)
+TEST(pref_UNPARSED_ARGUMENTS "FOO")
+cmake_parse_arguments(pref "" "" "" FOO BAR)
+TEST(pref_UNPARSED_ARGUMENTS "FOO;BAR")
+cmake_parse_arguments(pref "" "" "")
+TEST(pref_UNPARSED_ARGUMENTS UNDEFINED)
+
+
+# options
+cmake_parse_arguments(pref "OPT1" "" "")
+TEST(pref_OPT1 FALSE)
+
+cmake_parse_arguments(pref "OPT1;OPT2" "" "")
+TEST(pref_OPT1 FALSE)
+TEST(pref_OPT2 FALSE)
+
+cmake_parse_arguments(pref "OPT1" "" "" OPT1)
+TEST(pref_OPT1 TRUE)
+cmake_parse_arguments(pref "OPT1;OPT2" "" "" OPT1 OPT2)
+TEST(pref_OPT1 TRUE)
+TEST(pref_OPT2 TRUE)
+cmake_parse_arguments(pref "OPT1;OPT2" "" "")
+TEST(pref_OPT1 FALSE)
+TEST(pref_OPT2 FALSE)
+
+
+# single arguments
+cmake_parse_arguments(pref "" "SINGLE1" "")
+TEST(pref_SINGLE1 UNDEFINED)
+
+cmake_parse_arguments(pref "" "SINGLE1;SINGLE2" "")
+TEST(pref_SINGLE1 UNDEFINED)
+TEST(pref_SINGLE2 UNDEFINED)
+
+
+cmake_parse_arguments(pref "" "SINGLE1" "" SINGLE1 foo)
+TEST(pref_SINGLE1 foo)
+cmake_parse_arguments(pref "" "SINGLE1;SINGLE2" "" SINGLE1 foo SINGLE2 bar)
+TEST(pref_SINGLE1 foo)
+TEST(pref_SINGLE2 bar)
+cmake_parse_arguments(pref "" "SINGLE1;SINGLE2" "")
+TEST(pref_SINGLE1 UNDEFINED)
+TEST(pref_SINGLE2 UNDEFINED)
+
+
+# multi arguments
+
+cmake_parse_arguments(pref "" "" "MULTI1")
+TEST(pref_MULTI1 UNDEFINED)
+
+cmake_parse_arguments(pref "" "" "MULTI1;MULTI2")
+TEST(pref_MULTI1 UNDEFINED)
+TEST(pref_MULTI2 UNDEFINED)
+
+cmake_parse_arguments(pref "" "" "MULTI1" MULTI1 foo)
+TEST(pref_MULTI1 foo)
+cmake_parse_arguments(pref "" "" "MULTI1;MULTI2" MULTI1 foo bar MULTI2 bar foo)
+TEST(pref_MULTI1 foo bar)
+TEST(pref_MULTI2 bar foo)
+cmake_parse_arguments(pref "" "" "MULTI1;MULTI2")
+TEST(pref_MULTI1 UNDEFINED)
+TEST(pref_MULTI2 UNDEFINED)
diff --git a/Tests/RunCMake/cmake_parse_arguments/Mix.cmake b/Tests/RunCMake/cmake_parse_arguments/Mix.cmake
new file mode 100644
index 0000000..b3eff39
--- /dev/null
+++ b/Tests/RunCMake/cmake_parse_arguments/Mix.cmake
@@ -0,0 +1,24 @@
+include(${CMAKE_CURRENT_LIST_DIR}/test_utils.cmake)
+
+# specify two keywords for each category and set the first keyword of each
+# within ARGN
+cmake_parse_arguments(pref "OPT1;OPT2" "SINGLE1;SINGLE2" "MULTI1;MULTI2"
+                        OPT1 SINGLE1 foo MULTI1 bar foo bar)
+TEST(pref_OPT1 TRUE)
+TEST(pref_OPT2 FALSE)
+TEST(pref_SINGLE1 foo)
+TEST(pref_SINGLE2 UNDEFINED)
+TEST(pref_MULTI1 bar foo bar)
+TEST(pref_MULTI2 UNDEFINED)
+TEST(pref_UNPARSED_ARGUMENTS UNDEFINED)
+
+# same as above but reversed ARGN
+cmake_parse_arguments(pref "OPT1;OPT2" "SINGLE1;SINGLE2" "MULTI1;MULTI2"
+                        MULTI1 bar foo bar SINGLE1 foo OPT1)
+TEST(pref_OPT1 TRUE)
+TEST(pref_OPT2 FALSE)
+TEST(pref_SINGLE1 foo)
+TEST(pref_SINGLE2 UNDEFINED)
+TEST(pref_MULTI1 bar foo bar)
+TEST(pref_MULTI2 UNDEFINED)
+TEST(pref_UNPARSED_ARGUMENTS UNDEFINED)
diff --git a/Tests/RunCMake/cmake_parse_arguments/RunCMakeTest.cmake b/Tests/RunCMake/cmake_parse_arguments/RunCMakeTest.cmake
new file mode 100644
index 0000000..b89f1a5
--- /dev/null
+++ b/Tests/RunCMake/cmake_parse_arguments/RunCMakeTest.cmake
@@ -0,0 +1,7 @@
+include(RunCMake)
+
+run_cmake(Utils)
+run_cmake(Initialization)
+run_cmake(Mix)
+run_cmake(CornerCases)
+run_cmake(Errors)
diff --git a/Tests/RunCMake/cmake_parse_arguments/Utils.cmake b/Tests/RunCMake/cmake_parse_arguments/Utils.cmake
new file mode 100644
index 0000000..3bbf115
--- /dev/null
+++ b/Tests/RunCMake/cmake_parse_arguments/Utils.cmake
@@ -0,0 +1,20 @@
+include(${CMAKE_CURRENT_LIST_DIR}/test_utils.cmake)
+
+# test the TEST macro itself
+
+TEST(asdf UNDEFINED)
+
+SET (asdf FALSE)
+TEST(asdf FALSE)
+
+SET (asdf TRUE)
+TEST(asdf TRUE)
+
+SET (asdf TRUE)
+TEST(asdf TRUE)
+
+SET (asdf "some value")
+TEST(asdf "some value")
+
+SET (asdf some list)
+TEST(asdf "some;list")
diff --git a/Tests/RunCMake/cmake_parse_arguments/test_utils.cmake b/Tests/RunCMake/cmake_parse_arguments/test_utils.cmake
new file mode 100644
index 0000000..f5425c2
--- /dev/null
+++ b/Tests/RunCMake/cmake_parse_arguments/test_utils.cmake
@@ -0,0 +1,20 @@
+macro(TEST variable)
+  SET(expected "${ARGN}")
+  if ( "${expected}" STREQUAL "UNDEFINED" )
+    if (DEFINED ${variable})
+      message(FATAL_ERROR "'${variable}' shall be undefined but has value '${${variable}}'")
+    endif()
+  elseif( "${expected}" STREQUAL "FALSE" )
+    if (NOT ${variable} STREQUAL "FALSE")
+      message(FATAL_ERROR "'${variable}' shall be FALSE")
+    endif()
+  elseif( "${expected}" STREQUAL "TRUE" )
+    if (NOT ${variable} STREQUAL "TRUE")
+      message(FATAL_ERROR "'${variable}' shall be TRUE")
+    endif()
+  else()
+    if (NOT ${variable} STREQUAL "${expected}")
+      message(FATAL_ERROR "'${variable}' shall be '${expected}'")
+    endif()
+  endif()
+endmacro()
diff --git a/Tests/RunCMake/ctest_submit/CDashSubmitQuiet-stderr.txt b/Tests/RunCMake/ctest_submit/CDashSubmitQuiet-stderr.txt
index adf334b..4825d7a 100644
--- a/Tests/RunCMake/ctest_submit/CDashSubmitQuiet-stderr.txt
+++ b/Tests/RunCMake/ctest_submit/CDashSubmitQuiet-stderr.txt
@@ -1,3 +1,3 @@
  *Error when uploading file: .*/Configure.xml
- *Error message was: ([Cc]ould *n.t resolve host:? '?-no-site-'?|The requested URL returned error:.*)
+ *Error message was: ([Cc]ould *n.t resolve host:? '?-no-site-'?.*|The requested URL returned error:.*)
  *Problems when submitting via HTTP
diff --git a/Tests/RunCMake/ctest_submit/FailDrop-ftp-stderr.txt b/Tests/RunCMake/ctest_submit/FailDrop-ftp-stderr.txt
index 64c3011..b9d9394 100644
--- a/Tests/RunCMake/ctest_submit/FailDrop-ftp-stderr.txt
+++ b/Tests/RunCMake/ctest_submit/FailDrop-ftp-stderr.txt
@@ -1,2 +1,2 @@
-Error message was: ([Cc]ould *n.t resolve host:? '?-no-site-'?|The requested URL returned error:.*)
+Error message was: ([Cc]ould *n.t resolve host:? '?-no-site-'?.*|The requested URL returned error:.*)
    Problems when submitting via FTP
diff --git a/Tests/RunCMake/ctest_submit/FailDrop-http-stderr.txt b/Tests/RunCMake/ctest_submit/FailDrop-http-stderr.txt
index 73f0138..f52d2d8 100644
--- a/Tests/RunCMake/ctest_submit/FailDrop-http-stderr.txt
+++ b/Tests/RunCMake/ctest_submit/FailDrop-http-stderr.txt
@@ -1,2 +1,2 @@
-Error message was: ([Cc]ould *n.t resolve host:? '?-no-site-'?|The requested URL returned error:.*)
+Error message was: ([Cc]ould *n.t resolve host:? '?-no-site-'?.*|The requested URL returned error:.*)
    Problems when submitting via HTTP
diff --git a/Tests/RunCMake/ctest_submit/FailDrop-https-stderr.txt b/Tests/RunCMake/ctest_submit/FailDrop-https-stderr.txt
index a1ba4f6..24083f2 100644
--- a/Tests/RunCMake/ctest_submit/FailDrop-https-stderr.txt
+++ b/Tests/RunCMake/ctest_submit/FailDrop-https-stderr.txt
@@ -1,2 +1,2 @@
-Error message was: ([Cc]ould *n.t resolve host:? '?-no-site-'?|The requested URL returned error:.*|Protocol "https" not supported or disabled in .*|.* was built with SSL disabled.*)
+Error message was: ([Cc]ould *n.t resolve host:? '?-no-site-'?.*|The requested URL returned error:.*|Protocol "https" not supported or disabled in .*|.* was built with SSL disabled.*)
    Problems when submitting via HTTP
diff --git a/Tests/RunCMake/ctest_test/RunCMakeTest.cmake b/Tests/RunCMake/ctest_test/RunCMakeTest.cmake
index e2f380c..1b31726 100644
--- a/Tests/RunCMake/ctest_test/RunCMakeTest.cmake
+++ b/Tests/RunCMake/ctest_test/RunCMakeTest.cmake
@@ -71,6 +71,7 @@ add_test(NAME PassingTest COMMAND ${CMAKE_COMMAND} -E echo PassingTestOutput)
 add_test(NAME FailingTest COMMAND ${CMAKE_COMMAND} -E no_such_command)
   ]])
 
+  unset(ENV{CTEST_PARALLEL_LEVEL})
   run_ctest(TestOutputSize)
 endfunction()
 run_TestOutputSize()
diff --git a/Tests/RunCMake/ctest_test/TestOutputSize-check.cmake b/Tests/RunCMake/ctest_test/TestOutputSize-check.cmake
index 918d242..74ad669 100644
--- a/Tests/RunCMake/ctest_test/TestOutputSize-check.cmake
+++ b/Tests/RunCMake/ctest_test/TestOutputSize-check.cmake
@@ -4,14 +4,14 @@ if(test_xml_file)
   if("${test_xml}" MATCHES [[(<Test Status="passed">.*</Test>).*(<Test Status="failed">.*</Test>)]])
     set(test_passed "${CMAKE_MATCH_1}")
     set(test_failed "${CMAKE_MATCH_2}")
+    if(NOT "${test_passed}" MATCHES [[<Value>PassingTes\.\.\..*10 bytes]])
+      set(RunCMake_TEST_FAILED "Test.xml passed test output not truncated at 10 bytes:\n ${test_passed}")
+    elseif(NOT "${test_failed}" MATCHES [[<Value>CMake Error:\.\.\..*12 bytes]])
+      set(RunCMake_TEST_FAILED "Test.xml failed test output not truncated at 12 bytes:\n ${test_failed}")
+    endif()
   else()
     set(RunCMake_TEST_FAILED "Test.xml does not contain a passed then failed test:\n ${test_xml}")
   endif()
-  if(NOT "${test_passed}" MATCHES [[<Value>PassingTes\.\.\..*10 bytes]])
-    set(RunCMake_TEST_FAILED "Test.xml passed test output not truncated at 10 bytes:\n ${test_passed}")
-  elseif(NOT "${test_failed}" MATCHES [[<Value>CMake Error:\.\.\..*12 bytes]])
-    set(RunCMake_TEST_FAILED "Test.xml failed test output not truncated at 12 bytes:\n ${test_failed}")
-  endif()
 else()
   set(RunCMake_TEST_FAILED "Test.xml not found")
 endif()
diff --git a/Tests/RunCMake/if/MatchesSelf.cmake b/Tests/RunCMake/if/MatchesSelf.cmake
new file mode 100644
index 0000000..3131ac4
--- /dev/null
+++ b/Tests/RunCMake/if/MatchesSelf.cmake
@@ -0,0 +1,4 @@
+foreach(n 0 1 2 3 4 5 6 7 8 9 COUNT)
+  if(CMAKE_MATCH_${n} MATCHES "x")
+  endif()
+endforeach()
diff --git a/Tests/RunCMake/if/RunCMakeTest.cmake b/Tests/RunCMake/if/RunCMakeTest.cmake
index 3f4d2a2..077d00a 100644
--- a/Tests/RunCMake/if/RunCMakeTest.cmake
+++ b/Tests/RunCMake/if/RunCMakeTest.cmake
@@ -5,5 +5,7 @@ run_cmake(IsDirectory)
 run_cmake(IsDirectoryLong)
 run_cmake(elseif-message)
 
+run_cmake(MatchesSelf)
+
 run_cmake(TestNameThatExists)
 run_cmake(TestNameThatDoesNotExist)
diff --git a/Tests/RunCMake/install/CMP0062-NEW.cmake b/Tests/RunCMake/install/CMP0062-NEW.cmake
index a696f56..9e7a5fb 100644
--- a/Tests/RunCMake/install/CMP0062-NEW.cmake
+++ b/Tests/RunCMake/install/CMP0062-NEW.cmake
@@ -1,4 +1,4 @@
-
+cmake_policy(VERSION 3.2)
 cmake_policy(SET CMP0062 NEW)
 
 add_library(iface INTERFACE)
diff --git a/Tests/RunCMake/install/CMP0062-OLD.cmake b/Tests/RunCMake/install/CMP0062-OLD.cmake
index 94b809a..8874923 100644
--- a/Tests/RunCMake/install/CMP0062-OLD.cmake
+++ b/Tests/RunCMake/install/CMP0062-OLD.cmake
@@ -1,4 +1,4 @@
-
+cmake_policy(VERSION 3.2)
 cmake_policy(SET CMP0062 OLD)
 
 add_library(iface INTERFACE)
diff --git a/Tests/RunCMake/install/CMP0062-WARN.cmake b/Tests/RunCMake/install/CMP0062-WARN.cmake
index 0435a64..018f822 100644
--- a/Tests/RunCMake/install/CMP0062-WARN.cmake
+++ b/Tests/RunCMake/install/CMP0062-WARN.cmake
@@ -1,3 +1,4 @@
+cmake_policy(VERSION 3.2)
 
 add_library(iface INTERFACE)
 export(TARGETS iface FILE "${CMAKE_CURRENT_BINARY_DIR}/exported.cmake")
diff --git a/Tests/RunCMake/install/CMakeLists.txt b/Tests/RunCMake/install/CMakeLists.txt
index 4b3de84..6dd8cdf 100644
--- a/Tests/RunCMake/install/CMakeLists.txt
+++ b/Tests/RunCMake/install/CMakeLists.txt
@@ -1,3 +1,3 @@
-cmake_minimum_required(VERSION 2.8.12)
+cmake_minimum_required(VERSION 3.4)
 project(${RunCMake_TEST} NONE)
 include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/install/DIRECTORY-DIRECTORY-bad-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/install/DIRECTORY-DIRECTORY-bad-result.txt
diff --git a/Tests/RunCMake/install/DIRECTORY-DIRECTORY-bad-stderr.txt b/Tests/RunCMake/install/DIRECTORY-DIRECTORY-bad-stderr.txt
new file mode 100644
index 0000000..9844158
--- /dev/null
+++ b/Tests/RunCMake/install/DIRECTORY-DIRECTORY-bad-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error:
+  Error evaluating generator expression:
+
+    \$<NOTAGENEX>
+
+  Expression did not evaluate to a known generator expression
diff --git a/Tests/RunCMake/install/DIRECTORY-DIRECTORY-bad.cmake b/Tests/RunCMake/install/DIRECTORY-DIRECTORY-bad.cmake
new file mode 100644
index 0000000..ec0436d
--- /dev/null
+++ b/Tests/RunCMake/install/DIRECTORY-DIRECTORY-bad.cmake
@@ -0,0 +1 @@
+install(DIRECTORY $<NOTAGENEX> DESTINATION .)
diff --git a/Tests/RunCMake/install/EXPORT-OldIFace.cmake b/Tests/RunCMake/install/EXPORT-OldIFace.cmake
new file mode 100644
index 0000000..033f684
--- /dev/null
+++ b/Tests/RunCMake/install/EXPORT-OldIFace.cmake
@@ -0,0 +1,7 @@
+enable_language(C)
+set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
+add_subdirectory(EXPORT-OldIFace)
+add_library(foo SHARED empty.c)
+target_link_libraries(foo bar)
+install(TARGETS foo DESTINATION lib EXPORT fooExport)
+install(EXPORT fooExport DESTINATION lib/cmake/foo EXPORT_LINK_INTERFACE_LIBRARIES)
diff --git a/Tests/RunCMake/install/EXPORT-OldIFace/CMakeLists.txt b/Tests/RunCMake/install/EXPORT-OldIFace/CMakeLists.txt
new file mode 100644
index 0000000..32292e2
--- /dev/null
+++ b/Tests/RunCMake/install/EXPORT-OldIFace/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_library(bar SHARED ../empty.c)
+install(TARGETS bar DESTINATION lib EXPORT fooExport)
diff --git a/Tests/RunCMake/install/RunCMakeTest.cmake b/Tests/RunCMake/install/RunCMakeTest.cmake
index 043bd1f..c2347d8 100644
--- a/Tests/RunCMake/install/RunCMakeTest.cmake
+++ b/Tests/RunCMake/install/RunCMakeTest.cmake
@@ -6,9 +6,11 @@ run_cmake(DIRECTORY-message-lazy)
 run_cmake(SkipInstallRulesWarning)
 run_cmake(SkipInstallRulesNoWarning1)
 run_cmake(SkipInstallRulesNoWarning2)
+run_cmake(DIRECTORY-DIRECTORY-bad)
 run_cmake(DIRECTORY-DESTINATION-bad)
 run_cmake(FILES-DESTINATION-bad)
 run_cmake(TARGETS-DESTINATION-bad)
+run_cmake(EXPORT-OldIFace)
 run_cmake(CMP0062-OLD)
 run_cmake(CMP0062-NEW)
 run_cmake(CMP0062-WARN)
diff --git a/Tests/RunCMake/message/RunCMakeTest.cmake b/Tests/RunCMake/message/RunCMakeTest.cmake
index d2bc0c3..9489693 100644
--- a/Tests/RunCMake/message/RunCMakeTest.cmake
+++ b/Tests/RunCMake/message/RunCMakeTest.cmake
@@ -1,5 +1,10 @@
 include(RunCMake)
 
+run_cmake(defaultmessage)
 run_cmake(nomessage)
 run_cmake(warnmessage)
-run_cmake(errormessage)
+# message command sets fatal occurred flag, so check each type of error
+
+# seperately
+run_cmake(errormessage_deprecated)
+run_cmake(errormessage_dev)
diff --git a/Tests/RunCMake/message/defaultmessage-result.txt b/Tests/RunCMake/message/defaultmessage-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/message/defaultmessage-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/message/defaultmessage-stderr.txt b/Tests/RunCMake/message/defaultmessage-stderr.txt
new file mode 100644
index 0000000..dd1b28f
--- /dev/null
+++ b/Tests/RunCMake/message/defaultmessage-stderr.txt
@@ -0,0 +1,11 @@
+^CMake Deprecation Warning at defaultmessage.cmake:2 \(message\):
+  This is a deprecation warning
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+
+
+CMake Warning \(dev\) at defaultmessage.cmake:4 \(message\):
+  This is a author warning
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.$
diff --git a/Tests/RunCMake/message/defaultmessage.cmake b/Tests/RunCMake/message/defaultmessage.cmake
new file mode 100644
index 0000000..427014d
--- /dev/null
+++ b/Tests/RunCMake/message/defaultmessage.cmake
@@ -0,0 +1,4 @@
+
+message(DEPRECATION "This is a deprecation warning")
+
+message(AUTHOR_WARNING "This is a author warning")
diff --git a/Tests/RunCMake/message/errormessage-stderr.txt b/Tests/RunCMake/message/errormessage-stderr.txt
deleted file mode 100644
index 49e7ca9..0000000
--- a/Tests/RunCMake/message/errormessage-stderr.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-CMake Deprecation Error at errormessage.cmake:4 \(message\):
-  This is an error
-Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/message/errormessage.cmake b/Tests/RunCMake/message/errormessage.cmake
deleted file mode 100644
index 7d3b779..0000000
--- a/Tests/RunCMake/message/errormessage.cmake
+++ /dev/null
@@ -1,4 +0,0 @@
-
-set(CMAKE_ERROR_DEPRECATED ON)
-
-message(DEPRECATION "This is an error")
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/message/errormessage_deprecated-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/message/errormessage_deprecated-result.txt
diff --git a/Tests/RunCMake/message/errormessage_deprecated-stderr.txt b/Tests/RunCMake/message/errormessage_deprecated-stderr.txt
new file mode 100644
index 0000000..dd21c3b
--- /dev/null
+++ b/Tests/RunCMake/message/errormessage_deprecated-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Deprecation Error at errormessage_deprecated.cmake:3 \(message\):
+  This is a deprecation error
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/message/errormessage_deprecated.cmake b/Tests/RunCMake/message/errormessage_deprecated.cmake
new file mode 100644
index 0000000..579275e
--- /dev/null
+++ b/Tests/RunCMake/message/errormessage_deprecated.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_ERROR_DEPRECATED ON)
+
+message(DEPRECATION "This is a deprecation error")
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/message/errormessage_dev-result.txt
similarity index 100%
copy from Tests/RunCMake/message/errormessage-result.txt
copy to Tests/RunCMake/message/errormessage_dev-result.txt
diff --git a/Tests/RunCMake/message/errormessage_dev-stderr.txt b/Tests/RunCMake/message/errormessage_dev-stderr.txt
new file mode 100644
index 0000000..086b55c
--- /dev/null
+++ b/Tests/RunCMake/message/errormessage_dev-stderr.txt
@@ -0,0 +1,5 @@
+^CMake Error \(dev\) at errormessage_dev.cmake:3 \(message\):
+  This is a author error
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+This error is for project developers. Use -Wno-error=dev to suppress it.$
diff --git a/Tests/RunCMake/message/errormessage_dev.cmake b/Tests/RunCMake/message/errormessage_dev.cmake
new file mode 100644
index 0000000..6ba1165
--- /dev/null
+++ b/Tests/RunCMake/message/errormessage_dev.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_SUPPRESS_DEVELOPER_ERRORS OFF)
+
+message(AUTHOR_WARNING "This is a author error")
diff --git a/Tests/RunCMake/message/nomessage.cmake b/Tests/RunCMake/message/nomessage.cmake
index bcc97be..78f4769 100644
--- a/Tests/RunCMake/message/nomessage.cmake
+++ b/Tests/RunCMake/message/nomessage.cmake
@@ -1,2 +1,8 @@
 
+set(CMAKE_WARN_DEPRECATED OFF)
+
 message(DEPRECATION "This is not issued")
+
+set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS ON)
+
+message(AUTHOR_WARNING "This is not issued")
diff --git a/Tests/RunCMake/message/warnmessage-stderr.txt b/Tests/RunCMake/message/warnmessage-stderr.txt
index 5c44566..e60af6e 100644
--- a/Tests/RunCMake/message/warnmessage-stderr.txt
+++ b/Tests/RunCMake/message/warnmessage-stderr.txt
@@ -1,4 +1,11 @@
-CMake Deprecation Warning at warnmessage.cmake:4 \(message\):
-  This is a warning
+^CMake Deprecation Warning at warnmessage.cmake:4 \(message\):
+  This is a deprecation warning
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
+
+
+CMake Warning \(dev\) at warnmessage.cmake:8 \(message\):
+  This is a author warning
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.$
diff --git a/Tests/RunCMake/message/warnmessage.cmake b/Tests/RunCMake/message/warnmessage.cmake
index 4c421a1..53f2a43 100644
--- a/Tests/RunCMake/message/warnmessage.cmake
+++ b/Tests/RunCMake/message/warnmessage.cmake
@@ -1,4 +1,8 @@
 
 set(CMAKE_WARN_DEPRECATED ON)
 
-message(DEPRECATION "This is a warning")
+message(DEPRECATION "This is a deprecation warning")
+
+set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS OFF)
+
+message(AUTHOR_WARNING "This is a author warning")
diff --git a/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake
index 8307607..1466fbf 100644
--- a/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake
+++ b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake
@@ -8,3 +8,5 @@ run_cmake(MixedSignature)
 run_cmake(Separate-PRIVATE-LINK_PRIVATE-uses)
 run_cmake(SubDirTarget)
 run_cmake(SharedDepNotTarget)
+run_cmake(StaticPrivateDepNotExported)
+run_cmake(StaticPrivateDepNotTarget)
diff --git a/Tests/RunCMake/message/errormessage-result.txt b/Tests/RunCMake/target_link_libraries/StaticPrivateDepNotExported-result.txt
similarity index 100%
rename from Tests/RunCMake/message/errormessage-result.txt
rename to Tests/RunCMake/target_link_libraries/StaticPrivateDepNotExported-result.txt
diff --git a/Tests/RunCMake/target_link_libraries/StaticPrivateDepNotExported-stderr.txt b/Tests/RunCMake/target_link_libraries/StaticPrivateDepNotExported-stderr.txt
new file mode 100644
index 0000000..6bb44ab
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/StaticPrivateDepNotExported-stderr.txt
@@ -0,0 +1 @@
+CMake Error: install\(EXPORT "Exp" ...\) includes target "foo" which requires target "not_exported" that is not in the export set.
diff --git a/Tests/RunCMake/target_link_libraries/StaticPrivateDepNotExported.cmake b/Tests/RunCMake/target_link_libraries/StaticPrivateDepNotExported.cmake
new file mode 100644
index 0000000..9b97918
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/StaticPrivateDepNotExported.cmake
@@ -0,0 +1,7 @@
+cmake_policy(SET CMP0022 NEW)
+enable_language(C)
+add_library(foo STATIC empty.c)
+add_library(not_exported STATIC empty.c)
+target_link_libraries(foo PRIVATE not_exported)
+install(TARGETS foo EXPORT Exp DESTINATION lib)
+install(EXPORT Exp DESTINATION lib/cmake/Exp)
diff --git a/Tests/RunCMake/target_link_libraries/StaticPrivateDepNotTarget.cmake b/Tests/RunCMake/target_link_libraries/StaticPrivateDepNotTarget.cmake
new file mode 100644
index 0000000..7122ae9
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/StaticPrivateDepNotTarget.cmake
@@ -0,0 +1,6 @@
+cmake_policy(SET CMP0022 NEW)
+enable_language(C)
+add_library(foo STATIC empty.c)
+target_link_libraries(foo PRIVATE not_a_target)
+install(TARGETS foo EXPORT Exp DESTINATION lib)
+install(EXPORT Exp DESTINATION lib/cmake/Exp)
diff --git a/Tests/SimpleInstall/CMakeLists.txt b/Tests/SimpleInstall/CMakeLists.txt
index e365076..2737f18 100644
--- a/Tests/SimpleInstall/CMakeLists.txt
+++ b/Tests/SimpleInstall/CMakeLists.txt
@@ -252,7 +252,7 @@ else()
   file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
   file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
   install(
-    DIRECTORY TestSubDir scripts/ DESTINATION $<1:MyTest/share>$<0:/wrong>
+    DIRECTORY TestSubDir $<1:scripts/>$<0:/wrong> DESTINATION $<1:MyTest/share>$<0:/wrong>
     FILE_PERMISSIONS OWNER_READ OWNER_WRITE
     DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
                           GROUP_READ GROUP_EXECUTE
@@ -263,7 +263,7 @@ else()
 
   # Alternate directory installation for coverage.
   install(
-    DIRECTORY scripts/ DESTINATION $<1:MyTest/share/alt>$<0:/wrong>
+    DIRECTORY $<1:scripts/>$<0:/wrong> DESTINATION $<1:MyTest/share/alt>$<0:/wrong>
     COMPONENT Development
     USE_SOURCE_PERMISSIONS
     PATTERN "CVS" EXCLUDE
diff --git a/Tests/SimpleInstallS2/CMakeLists.txt b/Tests/SimpleInstallS2/CMakeLists.txt
index e365076..2737f18 100644
--- a/Tests/SimpleInstallS2/CMakeLists.txt
+++ b/Tests/SimpleInstallS2/CMakeLists.txt
@@ -252,7 +252,7 @@ else()
   file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
   file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
   install(
-    DIRECTORY TestSubDir scripts/ DESTINATION $<1:MyTest/share>$<0:/wrong>
+    DIRECTORY TestSubDir $<1:scripts/>$<0:/wrong> DESTINATION $<1:MyTest/share>$<0:/wrong>
     FILE_PERMISSIONS OWNER_READ OWNER_WRITE
     DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
                           GROUP_READ GROUP_EXECUTE
@@ -263,7 +263,7 @@ else()
 
   # Alternate directory installation for coverage.
   install(
-    DIRECTORY scripts/ DESTINATION $<1:MyTest/share/alt>$<0:/wrong>
+    DIRECTORY $<1:scripts/>$<0:/wrong> DESTINATION $<1:MyTest/share/alt>$<0:/wrong>
     COMPONENT Development
     USE_SOURCE_PERMISSIONS
     PATTERN "CVS" EXCLUDE
diff --git a/Tests/SubDir/CMakeLists.txt b/Tests/SubDir/CMakeLists.txt
index 6822e6b..32aa93f 100644
--- a/Tests/SubDir/CMakeLists.txt
+++ b/Tests/SubDir/CMakeLists.txt
@@ -1,6 +1,10 @@
 cmake_minimum_required (VERSION 2.6)
 project(SUBDIR)
+
 subdirs(Executable EXCLUDE_FROM_ALL Examples)
+
+set(DEFINED_AFTER_SUBDIRS_COMMAND 42)
+
 write_file(${SUBDIR_BINARY_DIR}/ShouldBeHere "This file should exist.")
 #WATCOM WMAKE does not support + in the name of a file!
 if(WATCOM)
diff --git a/Tests/SubDir/Executable/CMakeLists.txt b/Tests/SubDir/Executable/CMakeLists.txt
index 77e6751..fbe338e 100644
--- a/Tests/SubDir/Executable/CMakeLists.txt
+++ b/Tests/SubDir/Executable/CMakeLists.txt
@@ -1 +1,13 @@
 add_executable(test test.cxx)
+
+if (NOT DEFINED_AFTER_SUBDIRS_COMMAND)
+  message(FATAL_ERROR "DEFINED_AFTER_SUBDIRS_COMMAND should be defined.")
+endif()
+
+string(FIND "${CMAKE_CURRENT_BINARY_DIR}" "SubDir/Executable" location)
+string(LENGTH "${CMAKE_CURRENT_BINARY_DIR}" dirLength)
+math(EXPR suffixLength "${dirLength} - ${location}")
+
+if (NOT suffixLength EQUAL 17)
+  message(FATAL_ERROR "CMAKE_CURRENT_BINARY_DIR does not end with \"SubDir/Executable\"")
+endif()
diff --git a/Tests/Wrapping/CMakeLists.txt b/Tests/Wrapping/CMakeLists.txt
index cbb28a1..aca36bc 100644
--- a/Tests/Wrapping/CMakeLists.txt
+++ b/Tests/Wrapping/CMakeLists.txt
@@ -85,16 +85,18 @@ endif ()
 # Since FLTK_FLUID_EXE is supposed to create a .cxx/.h from a .fl/.fld,
 # create an empty one so that the dependencies can be met.
 #
-set (FLTK_SRCS
-  fltk1.fl
-  )
 add_executable(fakefluid fakefluid.cxx)
 set (FLTK_WRAP_UI "On")
 set (FLTK_FLUID_EXECUTABLE fakefluid)
-fltk_wrap_ui (wraplibFLTK ${FLTK_SRCS})
+fltk_wrap_ui (wraplibFLTK fltk1.fl)
 add_library(wraplibFLTK ${wraplibFLTK_FLTK_UI_SRCS})
 add_dependencies(wraplibFLTK fakefluid)
 add_dependencies(fakefluid Wrap)
+fltk_wrap_ui (wrapFLTK fltk2.fl)
+add_executable(wrapFLTK wrapFLTK.c ${wrapFLTK_FLTK_UI_SRCS})
+target_link_libraries(wrapFLTK wraplibFLTK)
+add_dependencies(wrapFLTK fakefluid)
+
 #
 # Mangled Mesa
 #
diff --git a/Tests/Wrapping/fltk2.fl b/Tests/Wrapping/fltk2.fl
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/Wrapping/wrapFLTK.c b/Tests/Wrapping/wrapFLTK.c
new file mode 100644
index 0000000..78f2de1
--- /dev/null
+++ b/Tests/Wrapping/wrapFLTK.c
@@ -0,0 +1 @@
+int main(void) { return 0; }
diff --git a/Utilities/CMakeLists.txt b/Utilities/CMakeLists.txt
index 8b3e325..cf6bb72 100644
--- a/Utilities/CMakeLists.txt
+++ b/Utilities/CMakeLists.txt
@@ -33,3 +33,7 @@ else()
   # Normal documentation build.
   add_subdirectory(Sphinx)
 endif()
+
+if(WIX_CUSTOM_ACTION_ENABLED)
+  add_subdirectory(Release/WiX)
+endif()
diff --git a/Utilities/KWIML/.gitattributes b/Utilities/KWIML/.gitattributes
new file mode 100644
index 0000000..ecbf219
--- /dev/null
+++ b/Utilities/KWIML/.gitattributes
@@ -0,0 +1 @@
+*.md             conflict-marker-size=78
diff --git a/Utilities/KWIML/ABI.h.in b/Utilities/KWIML/ABI.h.in
deleted file mode 100644
index 87b6e96..0000000
--- a/Utilities/KWIML/ABI.h.in
+++ /dev/null
@@ -1,506 +0,0 @@
-/*============================================================================
-  Kitware Information Macro Library
-  Copyright 2010-2011 Kitware, Inc.
-  All rights reserved.
-
-  Redistribution and use in source and binary forms, with or without
-  modification, are permitted provided that the following conditions
-  are met:
-
-  * Redistributions of source code must retain the above copyright
-    notice, this list of conditions and the following disclaimer.
-
-  * Redistributions in binary form must reproduce the above copyright
-    notice, this list of conditions and the following disclaimer in the
-    documentation and/or other materials provided with the distribution.
-
-  * Neither the name of Kitware, Inc. nor the names of its contributors
-    may be used to endorse or promote products derived from this
-    software without specific prior written permission.
-
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-============================================================================*/
-#ifndef @KWIML at _ABI_H
-#define @KWIML at _ABI_H
-/*
-This header defines macros with information about the C ABI.
-Only information that can be determined using the preprocessor at
-compilation time is available.  No try-compile results may be added
-here.  Instead we memorize results on platforms of interest.
-
-An includer may optionally define the following macros to suppress errors:
-
-  @KWIML at _ABI_NO_VERIFY          = skip verification declarations
-  @KWIML at _ABI_NO_ERROR_CHAR_SIGN = signedness of 'char' may be unknown
-  @KWIML at _ABI_NO_ERROR_LONG_LONG = existence of 'long long' may be unknown
-  @KWIML at _ABI_NO_ERROR_ENDIAN    = byte order of CPU may be unknown
-
-An includer may test the following macros after inclusion:
-
-  @KWIML at _ABI_SIZEOF_DATA_PTR   = sizeof(void*)
-  @KWIML at _ABI_SIZEOF_CODE_PTR   = sizeof(void(*)(void))
-  @KWIML at _ABI_SIZEOF_FLOAT      = sizeof(float)
-  @KWIML at _ABI_SIZEOF_DOUBLE     = sizeof(double)
-  @KWIML at _ABI_SIZEOF_CHAR       = sizeof(char)
-  @KWIML at _ABI_SIZEOF_SHORT      = sizeof(short)
-  @KWIML at _ABI_SIZEOF_INT        = sizeof(int)
-  @KWIML at _ABI_SIZEOF_LONG       = sizeof(long)
-
-  @KWIML at _ABI_SIZEOF_LONG_LONG  = sizeof(long long) or 0 if not a type
-    Undefined if existence is unknown and error suppression macro
-    @KWIML at _ABI_NO_ERROR_LONG_LONG was defined.
-
-  @KWIML at _ABI_SIZEOF___INT64    = 8 if '__int64' exists or 0 if not
-    Undefined if existence is unknown.
-
-  @KWIML at _ABI___INT64_IS_LONG   = 1 if '__int64' is 'long' (same type)
-    Undefined otherwise.
-  @KWIML at _ABI___INT64_IS_LONG_LONG = 1 if '__int64' is 'long long' (same type)
-    Undefined otherwise.
-  @KWIML at _ABI___INT64_IS_UNIQUE = 1 if '__int64' is a distinct type
-    Undefined otherwise.
-
-  @KWIML at _ABI_CHAR_IS_UNSIGNED  = 1 if 'char' is unsigned, else undefined
-  @KWIML at _ABI_CHAR_IS_SIGNED    = 1 if 'char' is signed, else undefined
-    One of these is defined unless signedness of 'char' is unknown and
-    error suppression macro @KWIML at _ABI_NO_ERROR_CHAR_SIGN was defined.
-
-  @KWIML at _ABI_ENDIAN_ID_BIG    = id for big-endian (always defined)
-  @KWIML at _ABI_ENDIAN_ID_LITTLE = id for little-endian (always defined)
-  @KWIML at _ABI_ENDIAN_ID        = id of byte order of target CPU
-    Defined to @KWIML at _ABI_ENDIAN_ID_BIG or @KWIML at _ABI_ENDIAN_ID_LITTLE
-    unless byte order is unknown and error suppression macro
-    @KWIML at _ABI_NO_ERROR_ENDIAN was defined.
-
-We verify most results using dummy "extern" declarations that are
-invalid if the macros are wrong.  Verification is disabled if
-suppression macro @KWIML at _ABI_NO_VERIFY was defined.
-*/
-
-/*--------------------------------------------------------------------------*/
-#if !defined(@KWIML at _ABI_SIZEOF_DATA_PTR)
-# if defined(__SIZEOF_POINTER__)
-#  define @KWIML at _ABI_SIZEOF_DATA_PTR __SIZEOF_POINTER__
-# elif defined(_SIZE_PTR)
-#  define @KWIML at _ABI_SIZEOF_DATA_PTR (_SIZE_PTR >> 3)
-# elif defined(_LP64) || defined(__LP64__)
-#  define @KWIML at _ABI_SIZEOF_DATA_PTR 8
-# elif defined(_ILP32)
-#  define @KWIML at _ABI_SIZEOF_DATA_PTR 4
-# elif defined(__64BIT__) /* IBM XL */
-#  define @KWIML at _ABI_SIZEOF_DATA_PTR 8
-# elif defined(_M_X64)
-#  define @KWIML at _ABI_SIZEOF_DATA_PTR 8
-# elif defined(__ia64)
-#  define @KWIML at _ABI_SIZEOF_DATA_PTR 8
-# elif defined(__sparcv9)
-#  define @KWIML at _ABI_SIZEOF_DATA_PTR 8
-# elif defined(__x86_64) || defined(__x86_64__)
-#  define @KWIML at _ABI_SIZEOF_DATA_PTR 8
-# elif defined(__amd64) || defined(__amd64__)
-#  define @KWIML at _ABI_SIZEOF_DATA_PTR 8
-# elif defined(__i386) || defined(__i386__)
-#  define @KWIML at _ABI_SIZEOF_DATA_PTR 4
-# endif
-#endif
-#if !defined(@KWIML at _ABI_SIZEOF_DATA_PTR)
-# define @KWIML at _ABI_SIZEOF_DATA_PTR 4
-#endif
-#if !defined(@KWIML at _ABI_SIZEOF_CODE_PTR)
-# define @KWIML at _ABI_SIZEOF_CODE_PTR @KWIML at _ABI_SIZEOF_DATA_PTR
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if !defined(@KWIML at _ABI_SIZEOF_CHAR)
-# define @KWIML at _ABI_SIZEOF_CHAR 1
-#endif
-
-#if !defined(@KWIML at _ABI_CHAR_IS_UNSIGNED) && !defined(@KWIML at _ABI_CHAR_IS_SIGNED)
-# if defined(__CHAR_UNSIGNED__) /* GNU, some IBM XL, others?  */
-#  define @KWIML at _ABI_CHAR_IS_UNSIGNED 1
-# elif defined(_CHAR_UNSIGNED) /* Intel, IBM XL, MSVC, Borland, others?  */
-#  define @KWIML at _ABI_CHAR_IS_UNSIGNED 1
-# elif defined(_CHAR_SIGNED) /* IBM XL, others? */
-#  define @KWIML at _ABI_CHAR_IS_SIGNED 1
-# elif defined(__CHAR_SIGNED__) /* IBM XL, Watcom, others? */
-#  define @KWIML at _ABI_CHAR_IS_SIGNED 1
-# elif defined(__SIGNED_CHARS__) /* EDG, Intel, SGI MIPSpro */
-#  define @KWIML at _ABI_CHAR_IS_SIGNED 1
-# elif defined(_CHAR_IS_SIGNED) /* Some SunPro, others? */
-#  define @KWIML at _ABI_CHAR_IS_SIGNED 1
-# elif defined(_CHAR_IS_UNSIGNED) /* SunPro, others? */
-#  define @KWIML at _ABI_CHAR_IS_UNSIGNED 1
-# elif defined(__GNUC__) /* GNU default */
-#  define @KWIML at _ABI_CHAR_IS_SIGNED 1
-# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* SunPro default */
-#  define @KWIML at _ABI_CHAR_IS_SIGNED 1
-# elif defined(__HP_cc) || defined(__HP_aCC) /* HP default (unless +uc) */
-#  define @KWIML at _ABI_CHAR_IS_SIGNED 1
-# elif defined(_SGI_COMPILER_VERSION) /* SGI MIPSpro default */
-#  define @KWIML at _ABI_CHAR_IS_UNSIGNED 1
-# elif defined(__PGIC__) /* PGI default */
-#  define @KWIML at _ABI_CHAR_IS_SIGNED 1
-# elif defined(_MSC_VER) /* MSVC default */
-#  define @KWIML at _ABI_CHAR_IS_SIGNED 1
-# elif defined(__WATCOMC__) /* Watcom default */
-#  define @KWIML at _ABI_CHAR_IS_UNSIGNED 1
-# elif defined(__BORLANDC__) /* Borland default */
-#  define @KWIML at _ABI_CHAR_IS_SIGNED 1
-# elif defined(__hpux) /* Old HP: no __HP_cc/__HP_aCC/__GNUC__ above */
-#  define @KWIML at _ABI_CHAR_IS_SIGNED 1 /* (unless +uc) */
-# endif
-#endif
-#if !defined(@KWIML at _ABI_CHAR_IS_UNSIGNED) && !defined(@KWIML at _ABI_CHAR_IS_SIGNED) \
- && !defined(@KWIML at _ABI_NO_ERROR_CHAR_SIGN)
-# error "Signedness of 'char' unknown."
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if !defined(@KWIML at _ABI_SIZEOF_SHORT)
-# if defined(__SIZEOF_SHORT__)
-#  define @KWIML at _ABI_SIZEOF_SHORT __SIZEOF_SHORT__
-# endif
-#endif
-#if !defined(@KWIML at _ABI_SIZEOF_SHORT)
-# define @KWIML at _ABI_SIZEOF_SHORT 2
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if !defined(@KWIML at _ABI_SIZEOF_INT)
-# if defined(__SIZEOF_INT__)
-#  define @KWIML at _ABI_SIZEOF_INT __SIZEOF_INT__
-# elif defined(_SIZE_INT)
-#  define @KWIML at _ABI_SIZEOF_INT (_SIZE_INT >> 3)
-# endif
-#endif
-#if !defined(@KWIML at _ABI_SIZEOF_INT)
-# define @KWIML at _ABI_SIZEOF_INT 4
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if !defined(@KWIML at _ABI_SIZEOF_LONG)
-# if defined(__SIZEOF_LONG__)
-#  define @KWIML at _ABI_SIZEOF_LONG __SIZEOF_LONG__
-# elif defined(_SIZE_LONG)
-#  define @KWIML at _ABI_SIZEOF_LONG (_SIZE_LONG >> 3)
-# elif defined(__LONG_MAX__)
-#  if __LONG_MAX__ == 0x7fffffff
-#   define @KWIML at _ABI_SIZEOF_LONG 4
-#  elif __LONG_MAX__>>32 == 0x7fffffff
-#   define @KWIML at _ABI_SIZEOF_LONG 8
-#  endif
-# elif defined(_MSC_VER) /* MSVC and Intel on Windows */
-#  define @KWIML at _ABI_SIZEOF_LONG 4
-# endif
-#endif
-#if !defined(@KWIML at _ABI_SIZEOF_LONG)
-# define @KWIML at _ABI_SIZEOF_LONG @KWIML at _ABI_SIZEOF_DATA_PTR
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if !defined(@KWIML at _ABI_SIZEOF_LONG_LONG)
-# if defined(__SIZEOF_LONG_LONG__)
-#  define @KWIML at _ABI_SIZEOF_LONG_LONG __SIZEOF_LONG_LONG__
-# elif defined(__LONG_LONG_MAX__)
-#  if __LONG_LONG_MAX__ == 0x7fffffff
-#   define @KWIML at _ABI_SIZEOF_LONG_LONG 4
-#  elif __LONG_LONG_MAX__>>32 == 0x7fffffff
-#   define @KWIML at _ABI_SIZEOF_LONG_LONG 8
-#  endif
-# endif
-#endif
-#if !defined(@KWIML at _ABI_SIZEOF_LONG_LONG)
-# if defined(_LONGLONG) /* SGI, some GNU, perhaps others.  */ \
-  && !defined(_MSC_VER)
-#  define @KWIML at _ABI_SIZEOF_LONG_LONG 8
-# elif defined(_LONG_LONG) /* IBM XL, perhaps others.  */
-#  define @KWIML at _ABI_SIZEOF_LONG_LONG 8
-# elif defined(__NO_LONG_LONG) /* EDG */
-#  define @KWIML at _ABI_SIZEOF_LONG_LONG 0
-# elif defined(__cplusplus) && __cplusplus > 199711L /* C++0x */
-#  define @KWIML at _ABI_SIZEOF_LONG_LONG 8
-# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
-#  define @KWIML at _ABI_SIZEOF_LONG_LONG 8
-# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* SunPro */
-#  define @KWIML at _ABI_SIZEOF_LONG_LONG 8
-# elif defined(__HP_cc) || defined(__HP_aCC) /* HP */
-#  define @KWIML at _ABI_SIZEOF_LONG_LONG 8
-# elif defined(__PGIC__) /* PGI */
-#  define @KWIML at _ABI_SIZEOF_LONG_LONG 8
-# elif defined(__WATCOMC__) /* Watcom */
-#  define @KWIML at _ABI_SIZEOF_LONG_LONG 8
-# elif defined(__INTEL_COMPILER) /* Intel */
-#  define @KWIML at _ABI_SIZEOF_LONG_LONG 8
-# elif defined(__BORLANDC__) /* Borland */
-#  if __BORLANDC__ >= 0x0560
-#   define @KWIML at _ABI_SIZEOF_LONG_LONG 8
-#  else
-#   define @KWIML at _ABI_SIZEOF_LONG_LONG 0
-#  endif
-# elif defined(_MSC_VER) /* Microsoft */
-#  if _MSC_VER >= 1310
-#   define @KWIML at _ABI_SIZEOF_LONG_LONG 8
-#  else
-#   define @KWIML at _ABI_SIZEOF_LONG_LONG 0
-#  endif
-# elif defined(__GNUC__) /* GNU */
-#  define @KWIML at _ABI_SIZEOF_LONG_LONG 8
-# elif defined(__hpux) /* Old HP: no __HP_cc/__HP_aCC/__GNUC__ above */
-#  define @KWIML at _ABI_SIZEOF_LONG_LONG 8
-# endif
-#endif
-#if !defined(@KWIML at _ABI_SIZEOF_LONG_LONG) && !defined(@KWIML at _ABI_NO_ERROR_LONG_LONG)
-# error "Existence of 'long long' unknown."
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if !defined(@KWIML at _ABI_SIZEOF___INT64)
-# if defined(__INTEL_COMPILER)
-#  define @KWIML at _ABI_SIZEOF___INT64 8
-# elif defined(_MSC_VER)
-#  define @KWIML at _ABI_SIZEOF___INT64 8
-# elif defined(__BORLANDC__)
-#  define @KWIML at _ABI_SIZEOF___INT64 8
-# else
-#  define @KWIML at _ABI_SIZEOF___INT64 0
-# endif
-#endif
-
-#if defined(@KWIML at _ABI_SIZEOF___INT64) && @KWIML at _ABI_SIZEOF___INT64 > 0
-# if @KWIML at _ABI_SIZEOF_LONG == 8
-#  define @KWIML at _ABI___INT64_IS_LONG 1
-# elif defined(@KWIML at _ABI_SIZEOF_LONG_LONG) && @KWIML at _ABI_SIZEOF_LONG_LONG == 8
-#  define @KWIML at _ABI___INT64_IS_LONG_LONG 1
-# else
-#  define @KWIML at _ABI___INT64_IS_UNIQUE 1
-# endif
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if !defined(@KWIML at _ABI_SIZEOF_FLOAT)
-# if defined(__SIZEOF_FLOAT__)
-#  define @KWIML at _ABI_SIZEOF_FLOAT __SIZEOF_FLOAT__
-# endif
-#endif
-#if !defined(@KWIML at _ABI_SIZEOF_FLOAT)
-# define @KWIML at _ABI_SIZEOF_FLOAT 4
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if !defined(@KWIML at _ABI_SIZEOF_DOUBLE)
-# if defined(__SIZEOF_DOUBLE__)
-#  define @KWIML at _ABI_SIZEOF_DOUBLE __SIZEOF_DOUBLE__
-# endif
-#endif
-#if !defined(@KWIML at _ABI_SIZEOF_DOUBLE)
-# define @KWIML at _ABI_SIZEOF_DOUBLE 8
-#endif
-
-/*--------------------------------------------------------------------------*/
-/* Identify possible endian cases.  The macro @KWIML at _ABI_ENDIAN_ID will be
-   defined to one of these, or undefined if unknown.  */
-#if !defined(@KWIML at _ABI_ENDIAN_ID_BIG)
-# define @KWIML at _ABI_ENDIAN_ID_BIG    4321
-#endif
-#if !defined(@KWIML at _ABI_ENDIAN_ID_LITTLE)
-# define @KWIML at _ABI_ENDIAN_ID_LITTLE 1234
-#endif
-#if @KWIML at _ABI_ENDIAN_ID_BIG == @KWIML at _ABI_ENDIAN_ID_LITTLE
-# error "@KWIML at _ABI_ENDIAN_ID_BIG == @KWIML at _ABI_ENDIAN_ID_LITTLE"
-#endif
-
-#if defined(@KWIML at _ABI_ENDIAN_ID) /* Skip #elif cases if already defined.  */
-
-/* Use dedicated symbols if the compiler defines them.  Do this first
-   because some architectures allow runtime byte order selection by
-   the operating system (values for such architectures below are
-   guesses for compilers that do not define a dedicated symbol).
-   Ensure that only one is defined in case the platform or a header
-   defines both as possible values for some third symbol.  */
-#elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-#elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_LITTLE
-#elif defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-#elif defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_LITTLE
-
-/* Alpha */
-#elif defined(__alpha) || defined(__alpha__) || defined(_M_ALPHA)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_LITTLE
-
-/* Arm */
-#elif defined(__arm__)
-# if !defined(__ARMEB__)
-#  define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_LITTLE
-# else
-#  define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-# endif
-
-/* Intel x86 */
-#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_LITTLE
-#elif defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_LITTLE
-#elif defined(__MWERKS__) && defined(__INTEL__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_LITTLE
-
-/* Intel x86-64 */
-#elif defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_LITTLE
-#elif defined(__amd64) || defined(__amd64__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_LITTLE
-
-/* Intel Architecture-64 (Itanium) */
-#elif defined(__ia64) || defined(__ia64__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_LITTLE
-#elif defined(_IA64) || defined(__IA64__) || defined(_M_IA64)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_LITTLE
-
-/* PowerPC */
-#elif defined(__powerpc) || defined(__powerpc__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-#elif defined(__ppc) || defined(__ppc__) || defined(__POWERPC__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-
-/* SPARC */
-#elif defined(__sparc) || defined(__sparc__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-
-/* HP/PA RISC */
-#elif defined(__hppa) || defined(__hppa__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-
-/* Motorola 68k */
-#elif defined(__m68k__) || defined(M68000)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-
-/* MIPSel (MIPS little endian) */
-#elif defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_LITTLE
-
-/* MIPSeb (MIPS big endian) */
-#elif defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-
-/* MIPS (fallback, big endian) */
-#elif defined(__mips) || defined(__mips__) || defined(__MIPS__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-
-/* NIOS2 */
-#elif defined(__NIOS2__) || defined(__NIOS2) || defined(__nios2__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_LITTLE
-
-/* OpenRISC 1000 */
-#elif defined(__or1k__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-
-/* RS/6000 */
-#elif defined(__THW_RS600) || defined(_IBMR2) || defined(_POWER)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-#elif defined(_ARCH_PWR) || defined(_ARCH_PWR2)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-
-/* System/370 */
-#elif defined(__370__) || defined(__THW_370__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-
-/* System/390 */
-#elif defined(__s390__) || defined(__s390x__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-
-/* z/Architecture */
-#elif defined(__SYSC_ZARCH__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-
-/* VAX */
-#elif defined(__vax__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-
-/* Aarch64 */
-#elif defined(__aarch64__)
-# if !defined(__AARCH64EB__)
-#  define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_LITTLE
-# else
-#  define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-# endif
-
-/* Xtensa */
-#elif defined(__XTENSA_EB__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_BIG
-#elif defined(__XTENSA_EL__)
-# define @KWIML at _ABI_ENDIAN_ID @KWIML at _ABI_ENDIAN_ID_LITTLE
-
-/* Unknown CPU */
-#elif !defined(@KWIML at _ABI_NO_ERROR_ENDIAN)
-# error "Byte order of target CPU unknown."
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if !defined(@KWIML at _ABI_NO_VERIFY)
-#define @KWIML at _ABI__VERIFY(n, x, y) extern int (*n)[x]; extern int (*n)[y]
-#define @KWIML at _ABI__VERIFY2(n, x, y) extern int (*n)(x*); extern int (*n)(y*)
-#if defined(__cplusplus)
-# define @KWIML at _ABI__VERIFY3(n, x, y) extern int* n(x*); extern char* n(y*)
-#else
-# define @KWIML at _ABI__VERIFY3(n, x, y) extern int* n(x*) /* TODO: possible? */
-#endif
-#define @KWIML at _ABI__VERIFY_BOOL(m, b) @KWIML at _ABI__VERIFY(m##__VERIFY__, 2, (b)?2:3)
-#define @KWIML at _ABI__VERIFY_SIZE(m, t) @KWIML at _ABI__VERIFY(m##__VERIFY__, m, sizeof(t))
-#define @KWIML at _ABI__VERIFY_SAME(m, x, y) @KWIML at _ABI__VERIFY2(m##__VERIFY__, x, y)
-#define @KWIML at _ABI__VERIFY_DIFF(m, x, y) @KWIML at _ABI__VERIFY3(m##__VERIFY__, x, y)
-
- at KWIML@_ABI__VERIFY_SIZE(@KWIML at _ABI_SIZEOF_DATA_PTR, int*);
- at KWIML@_ABI__VERIFY_SIZE(@KWIML at _ABI_SIZEOF_CODE_PTR, int(*)(int));
- at KWIML@_ABI__VERIFY_SIZE(@KWIML at _ABI_SIZEOF_CHAR, char);
- at KWIML@_ABI__VERIFY_SIZE(@KWIML at _ABI_SIZEOF_SHORT, short);
- at KWIML@_ABI__VERIFY_SIZE(@KWIML at _ABI_SIZEOF_INT, int);
- at KWIML@_ABI__VERIFY_SIZE(@KWIML at _ABI_SIZEOF_LONG, long);
-#if defined(@KWIML at _ABI_SIZEOF_LONG_LONG) && @KWIML at _ABI_SIZEOF_LONG_LONG > 0
- at KWIML@_ABI__VERIFY_SIZE(@KWIML at _ABI_SIZEOF_LONG_LONG, long long);
-#endif
-#if defined(@KWIML at _ABI_SIZEOF___INT64) && @KWIML at _ABI_SIZEOF___INT64 > 0
- at KWIML@_ABI__VERIFY_SIZE(@KWIML at _ABI_SIZEOF___INT64, __int64);
-#endif
- at KWIML@_ABI__VERIFY_SIZE(@KWIML at _ABI_SIZEOF_FLOAT, float);
- at KWIML@_ABI__VERIFY_SIZE(@KWIML at _ABI_SIZEOF_DOUBLE, double);
-
-#if defined(@KWIML at _ABI___INT64_IS_LONG)
- at KWIML@_ABI__VERIFY_SAME(@KWIML at _ABI___INT64_IS_LONG, __int64, long);
-#elif defined(@KWIML at _ABI___INT64_IS_LONG_LONG)
- at KWIML@_ABI__VERIFY_SAME(@KWIML at _ABI___INT64_IS_LONG_LONG, __int64, long long);
-#elif defined(@KWIML at _ABI_SIZEOF___INT64) && @KWIML at _ABI_SIZEOF___INT64 > 0
- at KWIML@_ABI__VERIFY_DIFF(@KWIML at _ABI___INT64_NOT_LONG, __int64, long);
-# if defined(@KWIML at _ABI_SIZEOF_LONG_LONG) && @KWIML at _ABI_SIZEOF_LONG_LONG > 0
- at KWIML@_ABI__VERIFY_DIFF(@KWIML at _ABI___INT64_NOT_LONG_LONG, __int64, long long);
-# endif
-#endif
-
-#if defined(@KWIML at _ABI_CHAR_IS_UNSIGNED)
- at KWIML@_ABI__VERIFY_BOOL(@KWIML at _ABI_CHAR_IS_UNSIGNED, (char)0x80 > 0);
-#elif defined(@KWIML at _ABI_CHAR_IS_SIGNED)
- at KWIML@_ABI__VERIFY_BOOL(@KWIML at _ABI_CHAR_IS_SIGNED,   (char)0x80 < 0);
-#endif
-
-#undef @KWIML at _ABI__VERIFY_DIFF
-#undef @KWIML at _ABI__VERIFY_SAME
-#undef @KWIML at _ABI__VERIFY_SIZE
-#undef @KWIML at _ABI__VERIFY_BOOL
-#undef @KWIML at _ABI__VERIFY3
-#undef @KWIML at _ABI__VERIFY2
-#undef @KWIML at _ABI__VERIFY
-
-#endif
-
-#endif
diff --git a/Utilities/KWIML/CMakeLists.txt b/Utilities/KWIML/CMakeLists.txt
index 62b6fff..15e65e5 100644
--- a/Utilities/KWIML/CMakeLists.txt
+++ b/Utilities/KWIML/CMakeLists.txt
@@ -1,52 +1,29 @@
-#=============================================================================
-# Kitware Information Macro Library
-# Copyright 2010-2011 Kitware, Inc.
 #
-# Distributed under the OSI-approved BSD License (the "License");
-# see accompanying file Copyright.txt for details.
+# Copyright Kitware, Inc.
+# Distributed under the OSI-approved BSD 3-Clause License.
+# See accompanying file Copyright.txt for details.
 #
-# This software is distributed WITHOUT ANY WARRANTY; without even the
-# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the License for more information.
-#=============================================================================
-
-# Import the KWIML directory tree into a subdirectory under a parent
-# project and configure the library as follows:
-#
-#  set(KWIML myIML)
-#  subdirs(KWIML)
-#
-# Optional settings are as follows:
-#
-#  KWIML_HEADER_ROOT = build tree directory to hold KWIML headers.
-#    Headers will go in a directory called "${KWIML}" under this root.
-#    For example:
-#
-#      set(KWIML_HEADER_ROOT ${PROJECT_BINARY_DIR})
-#      include_directories(${PROJECT_BINARY_DIR})
-#
-#  KWIML_INSTALL_INCLUDE_DIR = install KWIML with "make install"
-#    Specify a value relative to the install prefix and do NOT start with '/'.
-#  KWIML_INSTALL_INCLUDE_OPTIONS = extra header installation options
-#    Specify options for the install(FILES) command.
-#
-#  KWIML_LABELS_TEST = list of labels for KWIML tests
-
-cmake_minimum_required(VERSION 2.6.3 FATAL_ERROR)
-
-#-----------------------------------------------------------------------------
-if(NOT DEFINED KWIML)
-  if(NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
-    message(FATAL_ERROR "Set KWIML namespace in parent directory!")
-  endif()
-  set(KWIML KWIML)
-  set(KWIML_STANDALONE 1)
+if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
+  cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
+  set(kwiml_standalone 1)
   project(KWIML)
   include(CTest)
   mark_as_advanced(BUILD_TESTING)
+  if(BUILD_TESTING)
+    set(KWIML_TEST_ENABLE 1)
+  endif()
+  if(NOT DEFINED KWIML_INSTALL_INCLUDE_DIR)
+    set(KWIML_INSTALL_INCLUDE_DIR include)
+  endif()
+  set(KWIML_INCLUDE_PREFIX kwiml)
+else()
+  cmake_minimum_required(VERSION 2.8.2 FATAL_ERROR)
+  set(kwiml_standalone 0)
+  if(KWIML_INSTALL_INCLUDE_DIR AND NOT DEFINED KWIML_INCLUDE_PREFIX)
+    message(FATAL_ERROR "Host project must set KWIML_INCLUDE_PREFIX")
+  endif()
 endif()
 
-#-----------------------------------------------------------------------------
 get_property(KWIML_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
 foreach(lang ${KWIML_LANGUAGES})
   set(KWIML_LANGUAGE_${lang} 1)
@@ -55,25 +32,73 @@ if(NOT KWIML_LANGUAGE_C AND NOT KWIML_LANGUAGE_CXX)
   set(BUILD_TESTING OFF)
 endif()
 
-#-----------------------------------------------------------------------------
-if(NOT KWIML_HEADER_ROOT)
-  set(KWIML_HEADER_ROOT "${PROJECT_BINARY_DIR}")
+if(KWIML_INSTALL_INCLUDE_DIR)
+  install(FILES
+    include/kwiml/abi.h
+    include/kwiml/int.h
+    DESTINATION ${KWIML_INSTALL_INCLUDE_DIR}/${KWIML_INCLUDE_PREFIX}
+    ${KWIML_INSTALL_INCLUDE_OPTIONS}
+    )
 endif()
-set(KWIML_HEADER_DIR "${KWIML_HEADER_ROOT}/${KWIML}")
-include_directories(${KWIML_HEADER_ROOT})
 
-#-----------------------------------------------------------------------------
-foreach(h ABI INT)
-  set(header ${KWIML_HEADER_DIR}/${h}.h)
-  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${h}.h.in ${header} @ONLY)
-  if(KWIML_INSTALL_INCLUDE_DIR)
-    install(FILES ${header}
-      DESTINATION ${KWIML_INSTALL_INCLUDE_DIR}/${KWIML}
-      ${KWIML_INSTALL_INCLUDE_OPTIONS})
-  endif()
-endforeach()
-
-#-----------------------------------------------------------------------------
-if(BUILD_TESTING)
+if(KWIML_TEST_ENABLE)
   add_subdirectory(test)
 endif()
+
+if(NOT kwiml_standalone)
+  return()
+endif()
+
+#----------------------------------------------------------------------------
+set(KWIML_VERSION 1.0.0)
+if(KWIML_VERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)")
+  set(KWIML_VERSION_MAJOR "${CMAKE_MATCH_1}")
+  set(KWIML_VERSION_MINOR "${CMAKE_MATCH_2}")
+  set(KWIML_VERSION_PATCH "${CMAKE_MATCH_3}")
+  math(EXPR KWIML_VERSION_DECIMAL
+    "${KWIML_VERSION_MAJOR}*1000000 + ${KWIML_VERSION_MINOR}*1000 + ${KWIML_VERSION_PATCH}")
+else()
+  message(FATAL_ERROR "Failed to parse KWIML_VERSION='${KWIML_VERSION}'")
+endif()
+
+configure_file(src/version.h.in include/kwiml/version.h @ONLY)
+install(FILES
+  ${CMAKE_CURRENT_BINARY_DIR}/include/kwiml/version.h
+  DESTINATION ${KWIML_INSTALL_INCLUDE_DIR}/kwiml
+  )
+
+if(NOT KWIML_INSTALL_PACKAGE_DIR)
+  set(KWIML_INSTALL_PACKAGE_DIR share/cmake/kwiml-${KWIML_VERSION_MAJOR}.${KWIML_VERSION_MINOR})
+endif()
+
+add_library(kwiml INTERFACE)
+target_include_directories(kwiml INTERFACE
+  $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${KWIML_INSTALL_INCLUDE_DIR}>
+  $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
+  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
+  )
+export(TARGETS kwiml
+  NAMESPACE kwiml::
+  FILE kwiml-targets.cmake
+  )
+install(TARGETS kwiml
+  DESTINATION lib
+  EXPORT kwiml-targets
+  )
+install(EXPORT kwiml-targets
+  NAMESPACE kwiml::
+  DESTINATION ${KWIML_INSTALL_PACKAGE_DIR}
+  )
+
+configure_file(src/kwiml-config.cmake.in kwiml-config.cmake @ONLY)
+include(CMakePackageConfigHelpers)
+write_basic_package_version_file(
+  "${CMAKE_CURRENT_BINARY_DIR}/kwiml-config-version.cmake"
+  VERSION ${KWIML_VERSION}
+  COMPATIBILITY AnyNewerVersion
+  )
+install(FILES
+  ${CMAKE_CURRENT_BINARY_DIR}/kwiml-config.cmake
+  ${CMAKE_CURRENT_BINARY_DIR}/kwiml-config-version.cmake
+  DESTINATION ${KWIML_INSTALL_PACKAGE_DIR}
+  )
diff --git a/Utilities/KWIML/Copyright.txt b/Utilities/KWIML/Copyright.txt
index c1e5ebc..a6204b0 100644
--- a/Utilities/KWIML/Copyright.txt
+++ b/Utilities/KWIML/Copyright.txt
@@ -1,5 +1,5 @@
 Kitware Information Macro Library
-Copyright 2010-2011 Kitware, Inc.
+Copyright 2010-2015 Kitware, Inc.
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
diff --git a/Utilities/KWIML/INT.h.in b/Utilities/KWIML/INT.h.in
deleted file mode 100644
index d2eda63..0000000
--- a/Utilities/KWIML/INT.h.in
+++ /dev/null
@@ -1,861 +0,0 @@
-/*============================================================================
-  Kitware Information Macro Library
-  Copyright 2010-2011 Kitware, Inc.
-  All rights reserved.
-
-  Redistribution and use in source and binary forms, with or without
-  modification, are permitted provided that the following conditions
-  are met:
-
-  * Redistributions of source code must retain the above copyright
-    notice, this list of conditions and the following disclaimer.
-
-  * Redistributions in binary form must reproduce the above copyright
-    notice, this list of conditions and the following disclaimer in the
-    documentation and/or other materials provided with the distribution.
-
-  * Neither the name of Kitware, Inc. nor the names of its contributors
-    may be used to endorse or promote products derived from this
-    software without specific prior written permission.
-
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-============================================================================*/
-#ifndef @KWIML at _INT_H
-#define @KWIML at _INT_H
-/*
-This header defines macros with information about sized integer types.
-Only information that can be determined using the preprocessor at
-compilation time is available.  No try-compile results may be added
-here.  Instead we memorize results on platforms of interest.
-
-An includer may optionally define the following macros to suppress errors:
-
-Input:
-  @KWIML at _INT_NO_VERIFY          = skip verification declarations
-  @KWIML at _INT_NO_ERROR_INT64_T   = type '@KWIML at _INT_int64_t' is optional (*)
-  @KWIML at _INT_NO_ERROR_UINT64_T  = type '@KWIML at _INT_uint64_t' is optional (*)
-  @KWIML at _INT_NO_ERROR_INTPTR_T  = type '@KWIML at _INT_intptr_t' is optional (*)
-  @KWIML at _INT_NO_ERROR_UINTPTR_T = type '@KWIML at _INT_uintptr_t' is optional (*)
-
-An includer may optionally define the following macros to override defaults.
-Either way, an includer may test these macros after inclusion:
-
-  @KWIML at _INT_HAVE_STDINT_H   = include <stdint.h>
-  @KWIML at _INT_NO_STDINT_H     = do not include <stdint.h>
-  @KWIML at _INT_HAVE_INTTYPES_H = include <inttypes.h>
-  @KWIML at _INT_NO_INTTYPES_H   = do not include <inttypes.h>
-
-An includer may test the following macros after inclusion:
-
-  @KWIML at _INT_HAVE_INT#_T     = type 'int#_t' is available
-  @KWIML at _INT_HAVE_UINT#_T    = type 'uint#_t' is available
-                                # = 8, 16, 32, 64, PTR
-
-  @KWIML at _INT_int#_t          = signed integer type exactly # bits wide
-  @KWIML at _INT_uint#_t         = unsigned integer type exactly # bits wide
-                                # = 8, 16, 32, 64 (*), ptr (*)
-
-  @KWIML at _INT_NO_INT64_T      = type '@KWIML at _INT_int64_t' not available
-  @KWIML at _INT_NO_UINT64_T     = type '@KWIML at _INT_uint64_t' not available
-  @KWIML at _INT_NO_INTPTR_T     = type '@KWIML at _INT_intptr_t' not available
-  @KWIML at _INT_NO_UINTPTR_T    = type '@KWIML at _INT_uintptr_t' not available
-
-  @KWIML at _INT_INT#_C(c)       = signed integer constant at least # bits wide
-  @KWIML at _INT_UINT#_C(c)      = unsigned integer constant at least # bits wide
-                                # = 8, 16, 32, 64 (*)
-
-  @KWIML at _INT_<fmt>#          = print or scan format, <fmt> in table below
-                                # = 8, 16, 32, 64, PTR (*)
-
-             signed                unsigned
-           ----------- ------------------------------
-          |  decimal  | decimal  octal   hexadecimal |
-    print | PRId PRIi |  PRIu    PRIo    PRIx  PRIX  |
-     scan | SCNd SCNi |  SCNu    SCNo    SCNx        |
-           ----------- ------------------------------
-
-    The SCN*8 and SCN*64 format macros will not be defined on systems
-    with scanf implementations known not to support them.
-
-  @KWIML at _INT_BROKEN_<fmt># = macro <fmt># is incorrect if defined
-    Some compilers define integer format macros incorrectly for their
-    own formatted print/scan implementations.
-
-  @KWIML at _INT_BROKEN_INT#_C  = macro INT#_C is incorrect if defined
-  @KWIML at _INT_BROKEN_UINT#_C = macro UINT#_C is incorrect if defined
-    Some compilers define integer constant macros incorrectly and
-    cannot handle literals as large as the integer type or even
-    produce bad preprocessor syntax.
-
-  @KWIML at _INT_BROKEN_INT8_T   = type 'int8_t' is available but incorrect
-    Some compilers have a flag to make 'char' (un)signed but do not account
-    for it while defining int8_t in the non-default case.
-
-  The broken cases do not affect correctness of the macros documented above.
-*/
-
-#include "ABI.h"
-
-/*--------------------------------------------------------------------------*/
-#if defined(@KWIML at _INT_HAVE_STDINT_H) /* Already defined. */
-#elif defined(@KWIML at _INT_NO_STDINT_H) /* Already defined. */
-#elif defined(HAVE_STDINT_H) /* Optionally provided by includer.  */
-# define @KWIML at _INT_HAVE_STDINT_H 1
-#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
-# define @KWIML at _INT_HAVE_STDINT_H 1
-#elif defined(_MSC_VER) /* MSVC */
-# if _MSC_VER >= 1600
-#  define @KWIML at _INT_HAVE_STDINT_H 1
-# else
-#  define @KWIML at _INT_NO_STDINT_H 1
-# endif
-#elif defined(__BORLANDC__) /* Borland */
-# if __BORLANDC__ >= 0x560
-#  define @KWIML at _INT_HAVE_STDINT_H 1
-# else
-#  define @KWIML at _INT_NO_STDINT_H 1
-# endif
-#elif defined(__WATCOMC__) /* Watcom */
-# define @KWIML at _INT_NO_STDINT_H 1
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if defined(@KWIML at _INT_HAVE_INTTYPES_H) /* Already defined. */
-#elif defined(@KWIML at _INT_NO_INTTYPES_H) /* Already defined. */
-#elif defined(HAVE_INTTYPES_H) /* Optionally provided by includer.  */
-# define @KWIML at _INT_HAVE_INTTYPES_H 1
-#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
-# define @KWIML at _INT_HAVE_INTTYPES_H 1
-#elif defined(_MSC_VER) /* MSVC */
-# define @KWIML at _INT_NO_INTTYPES_H 1
-#elif defined(__BORLANDC__) /* Borland */
-# define @KWIML at _INT_NO_INTTYPES_H 1
-#elif defined(__WATCOMC__) /* Watcom */
-# define @KWIML at _INT_NO_INTTYPES_H 1
-#else /* Assume it exists.  */
-# define @KWIML at _INT_HAVE_INTTYPES_H 1
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if defined(@KWIML at _INT_HAVE_STDINT_H) && defined(@KWIML at _INT_NO_STDINT_H)
-# error "Both @KWIML at _INT_HAVE_STDINT_H and @KWIML at _INT_NO_STDINT_H defined!"
-#endif
-#if defined(@KWIML at _INT_HAVE_INTTYPES_H) && defined(@KWIML at _INT_NO_INTTYPES_H)
-# error "Both @KWIML at _INT_HAVE_INTTYPES_H and @KWIML at _INT_NO_INTTYPES_H defined!"
-#endif
-
-#if defined(@KWIML at _INT_HAVE_STDINT_H)
-# include <stdint.h>
-#endif
-#if defined(@KWIML at _INT_HAVE_INTTYPES_H)
-# if defined(__cplusplus) && !defined(__STDC_FORMAT_MACROS)
-#  define __STDC_FORMAT_MACROS
-# endif
-# include <inttypes.h>
-#endif
-
-#if defined(@KWIML at _INT_HAVE_STDINT_H) || defined(@KWIML at _INT_HAVE_INTTYPES_H)
-#define @KWIML at _INT_HAVE_INT8_T 1
-#define @KWIML at _INT_HAVE_UINT8_T 1
-#define @KWIML at _INT_HAVE_INT16_T 1
-#define @KWIML at _INT_HAVE_UINT16_T 1
-#define @KWIML at _INT_HAVE_INT32_T 1
-#define @KWIML at _INT_HAVE_UINT32_T 1
-#define @KWIML at _INT_HAVE_INT64_T 1
-#define @KWIML at _INT_HAVE_UINT64_T 1
-#define @KWIML at _INT_HAVE_INTPTR_T 1
-#define @KWIML at _INT_HAVE_UINTPTR_T 1
-#endif
-
-#if defined(_AIX43) && !defined(_AIX50) && !defined(_AIX51)
-  /* AIX 4.3 defines these incorrectly with % and no quotes. */
-# define @KWIML at _INT_BROKEN_PRId8
-# define @KWIML at _INT_BROKEN_SCNd8
-# define @KWIML at _INT_BROKEN_PRIi8
-# define @KWIML at _INT_BROKEN_SCNi8
-# define @KWIML at _INT_BROKEN_PRIo8
-# define @KWIML at _INT_BROKEN_SCNo8
-# define @KWIML at _INT_BROKEN_PRIu8
-# define @KWIML at _INT_BROKEN_SCNu8
-# define @KWIML at _INT_BROKEN_PRIx8
-# define @KWIML at _INT_BROKEN_SCNx8
-# define @KWIML at _INT_BROKEN_PRIX8
-# define @KWIML at _INT_BROKEN_PRId16
-# define @KWIML at _INT_BROKEN_SCNd16
-# define @KWIML at _INT_BROKEN_PRIi16
-# define @KWIML at _INT_BROKEN_SCNi16
-# define @KWIML at _INT_BROKEN_PRIo16
-# define @KWIML at _INT_BROKEN_SCNo16
-# define @KWIML at _INT_BROKEN_PRIu16
-# define @KWIML at _INT_BROKEN_SCNu16
-# define @KWIML at _INT_BROKEN_PRIx16
-# define @KWIML at _INT_BROKEN_SCNx16
-# define @KWIML at _INT_BROKEN_PRIX16
-# define @KWIML at _INT_BROKEN_PRId32
-# define @KWIML at _INT_BROKEN_SCNd32
-# define @KWIML at _INT_BROKEN_PRIi32
-# define @KWIML at _INT_BROKEN_SCNi32
-# define @KWIML at _INT_BROKEN_PRIo32
-# define @KWIML at _INT_BROKEN_SCNo32
-# define @KWIML at _INT_BROKEN_PRIu32
-# define @KWIML at _INT_BROKEN_SCNu32
-# define @KWIML at _INT_BROKEN_PRIx32
-# define @KWIML at _INT_BROKEN_SCNx32
-# define @KWIML at _INT_BROKEN_PRIX32
-# define @KWIML at _INT_BROKEN_PRId64
-# define @KWIML at _INT_BROKEN_SCNd64
-# define @KWIML at _INT_BROKEN_PRIi64
-# define @KWIML at _INT_BROKEN_SCNi64
-# define @KWIML at _INT_BROKEN_PRIo64
-# define @KWIML at _INT_BROKEN_SCNo64
-# define @KWIML at _INT_BROKEN_PRIu64
-# define @KWIML at _INT_BROKEN_SCNu64
-# define @KWIML at _INT_BROKEN_PRIx64
-# define @KWIML at _INT_BROKEN_SCNx64
-# define @KWIML at _INT_BROKEN_PRIX64
-# define @KWIML at _INT_BROKEN_PRIdPTR
-# define @KWIML at _INT_BROKEN_SCNdPTR
-# define @KWIML at _INT_BROKEN_PRIiPTR
-# define @KWIML at _INT_BROKEN_SCNiPTR
-# define @KWIML at _INT_BROKEN_PRIoPTR
-# define @KWIML at _INT_BROKEN_SCNoPTR
-# define @KWIML at _INT_BROKEN_PRIuPTR
-# define @KWIML at _INT_BROKEN_SCNuPTR
-# define @KWIML at _INT_BROKEN_PRIxPTR
-# define @KWIML at _INT_BROKEN_SCNxPTR
-# define @KWIML at _INT_BROKEN_PRIXPTR
-#endif
-
-#if (defined(__SUNPRO_C)||defined(__SUNPRO_CC)) && defined(_CHAR_IS_UNSIGNED)
-# define @KWIML at _INT_BROKEN_INT8_T /* system type defined incorrectly */
-#elif defined(__BORLANDC__) && defined(_CHAR_UNSIGNED)
-# define @KWIML at _INT_BROKEN_INT8_T /* system type defined incorrectly */
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if defined(@KWIML at _INT_HAVE_INT8_T) && !defined(@KWIML at _INT_BROKEN_INT8_T)
-# define @KWIML at _INT_int8_t int8_t
-#else
-# define @KWIML at _INT_int8_t signed char
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT8_T)
-# define @KWIML at _INT_uint8_t uint8_t
-#else
-# define @KWIML at _INT_uint8_t unsigned char
-#endif
-
-#if defined(__INTEL_COMPILER)
-# if defined(_WIN32)
-#  define @KWIML at _INT__NO_SCN8
-# endif
-#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
-# define @KWIML at _INT__NO_SCN8
-#elif defined(__BORLANDC__)
-# define @KWIML at _INT__NO_SCN8
-# define @KWIML at _INT__NO_SCN64
-#elif defined(_MSC_VER)
-# define @KWIML at _INT__NO_SCN8
-#elif defined(__WATCOMC__)
-# define @KWIML at _INT__NO_SCN8
-# elif defined(__hpux) /* HP runtime lacks support (any compiler) */
-# define @KWIML at _INT__NO_SCN8
-#endif
-
-/* 8-bit d, i */
-#if defined(@KWIML at _INT_HAVE_INT8_T) && defined(PRId8) \
-  && !defined(@KWIML at _INT_BROKEN_PRId8)
-# define @KWIML at _INT_PRId8 PRId8
-#else
-# define @KWIML at _INT_PRId8   "d"
-#endif
-#if defined(@KWIML at _INT_HAVE_INT8_T) && defined(SCNd8) \
-  && !defined(@KWIML at _INT_BROKEN_SCNd8)
-# define @KWIML at _INT_SCNd8 SCNd8
-#elif !defined(@KWIML at _INT__NO_SCN8)
-# define @KWIML at _INT_SCNd8 "hhd"
-#endif
-#if defined(@KWIML at _INT_HAVE_INT8_T) && defined(PRIi8) \
-  && !defined(@KWIML at _INT_BROKEN_PRIi8)
-# define @KWIML at _INT_PRIi8 PRIi8
-#else
-# define @KWIML at _INT_PRIi8   "i"
-#endif
-#if defined(@KWIML at _INT_HAVE_INT8_T) && defined(SCNi8) \
-  && !defined(@KWIML at _INT_BROKEN_SCNi8)
-# define @KWIML at _INT_SCNi8 SCNi8
-#elif !defined(@KWIML at _INT__NO_SCN8)
-# define @KWIML at _INT_SCNi8 "hhi"
-#endif
-
-/* 8-bit o, u, x, X */
-#if defined(@KWIML at _INT_HAVE_UINT8_T) && defined(PRIo8) \
-  && !defined(@KWIML at _INT_BROKEN_PRIo8)
-# define @KWIML at _INT_PRIo8 PRIo8
-#else
-# define @KWIML at _INT_PRIo8   "o"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT8_T) && defined(SCNo8) \
-  && !defined(@KWIML at _INT_BROKEN_SCNo8)
-# define @KWIML at _INT_SCNo8 SCNo8
-#elif !defined(@KWIML at _INT__NO_SCN8)
-# define @KWIML at _INT_SCNo8 "hho"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT8_T) && defined(PRIu8) \
-  && !defined(@KWIML at _INT_BROKEN_PRIu8)
-# define @KWIML at _INT_PRIu8 PRIu8
-#else
-# define @KWIML at _INT_PRIu8   "u"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT8_T) && defined(SCNu8) \
-  && !defined(@KWIML at _INT_BROKEN_SCNu8)
-# define @KWIML at _INT_SCNu8 SCNu8
-#elif !defined(@KWIML at _INT__NO_SCN8)
-# define @KWIML at _INT_SCNu8 "hhu"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT8_T) && defined(PRIx8) \
-  && !defined(@KWIML at _INT_BROKEN_PRIx8)
-# define @KWIML at _INT_PRIx8 PRIx8
-#else
-# define @KWIML at _INT_PRIx8   "x"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT8_T) && defined(SCNx8) \
-  && !defined(@KWIML at _INT_BROKEN_SCNx8)
-# define @KWIML at _INT_SCNx8 SCNx8
-#elif !defined(@KWIML at _INT__NO_SCN8)
-# define @KWIML at _INT_SCNx8 "hhx"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT8_T) && defined(PRIX8) \
-  && !defined(@KWIML at _INT_BROKEN_PRIX8)
-# define @KWIML at _INT_PRIX8 PRIX8
-#else
-# define @KWIML at _INT_PRIX8   "X"
-#endif
-
-/* 8-bit constants */
-#if defined(INT8_C) && !defined(@KWIML at _INT_BROKEN_INT8_C)
-# define @KWIML at _INT_INT8_C(c) INT8_C(c)
-#else
-# define @KWIML at _INT_INT8_C(c) c
-#endif
-#if defined(UINT8_C) && !defined(@KWIML at _INT_BROKEN_UINT8_C)
-# define @KWIML at _INT_UINT8_C(c) UINT8_C(c)
-#else
-# define @KWIML at _INT_UINT8_C(c) c ## u
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if defined(@KWIML at _INT_HAVE_INT16_T)
-# define @KWIML at _INT_int16_t int16_t
-#else
-# define @KWIML at _INT_int16_t signed short
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT16_T)
-# define @KWIML at _INT_uint16_t uint16_t
-#else
-# define @KWIML at _INT_uint16_t unsigned short
-#endif
-
-/* 16-bit d, i */
-#if defined(@KWIML at _INT_HAVE_INT16_T) && defined(PRId16) \
-  && !defined(@KWIML at _INT_BROKEN_PRId16)
-# define @KWIML at _INT_PRId16 PRId16
-#else
-# define @KWIML at _INT_PRId16  "d"
-#endif
-#if defined(@KWIML at _INT_HAVE_INT16_T) && defined(SCNd16) \
-  && !defined(@KWIML at _INT_BROKEN_SCNd16)
-# define @KWIML at _INT_SCNd16 SCNd16
-#else
-# define @KWIML at _INT_SCNd16 "hd"
-#endif
-#if defined(@KWIML at _INT_HAVE_INT16_T) && defined(PRIi16) \
-  && !defined(@KWIML at _INT_BROKEN_PRIi16)
-# define @KWIML at _INT_PRIi16 PRIi16
-#else
-# define @KWIML at _INT_PRIi16  "i"
-#endif
-#if defined(@KWIML at _INT_HAVE_INT16_T) && defined(SCNi16) \
-  && !defined(@KWIML at _INT_BROKEN_SCNi16)
-# define @KWIML at _INT_SCNi16 SCNi16
-#else
-# define @KWIML at _INT_SCNi16 "hi"
-#endif
-
-/* 16-bit o, u, x, X */
-#if defined(@KWIML at _INT_HAVE_UINT16_T) && defined(PRIo16) \
-  && !defined(@KWIML at _INT_BROKEN_PRIo16)
-# define @KWIML at _INT_PRIo16 PRIo16
-#else
-# define @KWIML at _INT_PRIo16  "o"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT16_T) && defined(SCNo16) \
-  && !defined(@KWIML at _INT_BROKEN_SCNo16)
-# define @KWIML at _INT_SCNo16 SCNo16
-#else
-# define @KWIML at _INT_SCNo16 "ho"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT16_T) && defined(PRIu16) \
-  && !defined(@KWIML at _INT_BROKEN_PRIu16)
-# define @KWIML at _INT_PRIu16 PRIu16
-#else
-# define @KWIML at _INT_PRIu16  "u"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT16_T) && defined(SCNu16) \
-  && !defined(@KWIML at _INT_BROKEN_SCNu16)
-# define @KWIML at _INT_SCNu16 SCNu16
-#else
-# define @KWIML at _INT_SCNu16 "hu"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT16_T) && defined(PRIx16) \
-  && !defined(@KWIML at _INT_BROKEN_PRIx16)
-# define @KWIML at _INT_PRIx16 PRIx16
-#else
-# define @KWIML at _INT_PRIx16  "x"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT16_T) && defined(SCNx16) \
-  && !defined(@KWIML at _INT_BROKEN_SCNx16)
-# define @KWIML at _INT_SCNx16 SCNx16
-#else
-# define @KWIML at _INT_SCNx16 "hx"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT16_T) && defined(PRIX16) \
-  && !defined(@KWIML at _INT_BROKEN_PRIX16)
-# define @KWIML at _INT_PRIX16 PRIX16
-#else
-# define @KWIML at _INT_PRIX16  "X"
-#endif
-
-/* 16-bit constants */
-#if defined(INT16_C) && !defined(@KWIML at _INT_BROKEN_INT16_C)
-# define @KWIML at _INT_INT16_C(c) INT16_C(c)
-#else
-# define @KWIML at _INT_INT16_C(c) c
-#endif
-#if defined(UINT16_C) && !defined(@KWIML at _INT_BROKEN_UINT16_C)
-# define @KWIML at _INT_UINT16_C(c) UINT16_C(c)
-#else
-# define @KWIML at _INT_UINT16_C(c) c ## u
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if defined(@KWIML at _INT_HAVE_INT32_T)
-# define @KWIML at _INT_int32_t int32_t
-#else
-# define @KWIML at _INT_int32_t signed int
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT32_T)
-# define @KWIML at _INT_uint32_t uint32_t
-#else
-# define @KWIML at _INT_uint32_t unsigned int
-#endif
-
-/* 32-bit d, i */
-#if defined(@KWIML at _INT_HAVE_INT32_T) && defined(PRId32) \
-  && !defined(@KWIML at _INT_BROKEN_PRId32)
-# define @KWIML at _INT_PRId32 PRId32
-#else
-# define @KWIML at _INT_PRId32 "d"
-#endif
-#if defined(@KWIML at _INT_HAVE_INT32_T) && defined(SCNd32) \
-  && !defined(@KWIML at _INT_BROKEN_SCNd32)
-# define @KWIML at _INT_SCNd32 SCNd32
-#else
-# define @KWIML at _INT_SCNd32 "d"
-#endif
-#if defined(@KWIML at _INT_HAVE_INT32_T) && defined(PRIi32) \
-  && !defined(@KWIML at _INT_BROKEN_PRIi32)
-# define @KWIML at _INT_PRIi32 PRIi32
-#else
-# define @KWIML at _INT_PRIi32 "i"
-#endif
-#if defined(@KWIML at _INT_HAVE_INT32_T) && defined(SCNi32) \
-  && !defined(@KWIML at _INT_BROKEN_SCNi32)
-# define @KWIML at _INT_SCNi32 SCNi32
-#else
-# define @KWIML at _INT_SCNi32 "i"
-#endif
-
-/* 32-bit o, u, x, X */
-#if defined(@KWIML at _INT_HAVE_UINT32_T) && defined(PRIo32) \
-  && !defined(@KWIML at _INT_BROKEN_PRIo32)
-# define @KWIML at _INT_PRIo32 PRIo32
-#else
-# define @KWIML at _INT_PRIo32 "o"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT32_T) && defined(SCNo32) \
-  && !defined(@KWIML at _INT_BROKEN_SCNo32)
-# define @KWIML at _INT_SCNo32 SCNo32
-#else
-# define @KWIML at _INT_SCNo32 "o"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT32_T) && defined(PRIu32) \
-  && !defined(@KWIML at _INT_BROKEN_PRIu32)
-# define @KWIML at _INT_PRIu32 PRIu32
-#else
-# define @KWIML at _INT_PRIu32 "u"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT32_T) && defined(SCNu32) \
-  && !defined(@KWIML at _INT_BROKEN_SCNu32)
-# define @KWIML at _INT_SCNu32 SCNu32
-#else
-# define @KWIML at _INT_SCNu32 "u"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT32_T) && defined(PRIx32) \
-  && !defined(@KWIML at _INT_BROKEN_PRIx32)
-# define @KWIML at _INT_PRIx32 PRIx32
-#else
-# define @KWIML at _INT_PRIx32 "x"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT32_T) && defined(SCNx32) \
-  && !defined(@KWIML at _INT_BROKEN_SCNx32)
-# define @KWIML at _INT_SCNx32 SCNx32
-#else
-# define @KWIML at _INT_SCNx32 "x"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT32_T) && defined(PRIX32) \
-  && !defined(@KWIML at _INT_BROKEN_PRIX32)
-# define @KWIML at _INT_PRIX32 PRIX32
-#else
-# define @KWIML at _INT_PRIX32 "X"
-#endif
-
-#if defined(__hpux) && defined(__GNUC__) && !defined(__LP64__) \
- && defined(__CONCAT__) && defined(__CONCAT_U__)
-  /* Some HPs define UINT32_C incorrectly and break GNU.  */
-# define @KWIML at _INT_BROKEN_UINT32_C
-#endif
-
-/* 32-bit constants */
-#if defined(INT32_C) && !defined(@KWIML at _INT_BROKEN_INT32_C)
-# define @KWIML at _INT_INT32_C(c) INT32_C(c)
-#else
-# define @KWIML at _INT_INT32_C(c) c
-#endif
-#if defined(UINT32_C) && !defined(@KWIML at _INT_BROKEN_UINT32_C)
-# define @KWIML at _INT_UINT32_C(c) UINT32_C(c)
-#else
-# define @KWIML at _INT_UINT32_C(c) c ## u
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if defined(@KWIML at _INT_HAVE_INT64_T)
-# define @KWIML at _INT_int64_t int64_t
-#elif @KWIML at _ABI_SIZEOF_LONG == 8
-# define @KWIML at _INT_int64_t signed long
-#elif defined(@KWIML at _ABI_SIZEOF_LONG_LONG) && @KWIML at _ABI_SIZEOF_LONG_LONG == 8
-# define @KWIML at _INT_int64_t signed long long
-#elif defined(@KWIML at _ABI_SIZEOF___INT64)
-# define @KWIML at _INT_int64_t signed __int64
-#elif defined(@KWIML at _INT_NO_ERROR_INT64_T)
-# define @KWIML at _INT_NO_INT64_T
-#else
-# error "No type known for 'int64_t'."
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT64_T)
-# define @KWIML at _INT_uint64_t uint64_t
-#elif @KWIML at _ABI_SIZEOF_LONG == 8
-# define @KWIML at _INT_uint64_t unsigned long
-#elif defined(@KWIML at _ABI_SIZEOF_LONG_LONG) && @KWIML at _ABI_SIZEOF_LONG_LONG == 8
-# define @KWIML at _INT_uint64_t unsigned long long
-#elif defined(@KWIML at _ABI_SIZEOF___INT64)
-# define @KWIML at _INT_uint64_t unsigned __int64
-#elif defined(@KWIML at _INT_NO_ERROR_UINT64_T)
-# define @KWIML at _INT_NO_UINT64_T
-#else
-# error "No type known for 'uint64_t'."
-#endif
-
-#if defined(__INTEL_COMPILER)
-#elif defined(__BORLANDC__)
-# define @KWIML at _INT__NO_FMTLL /* type 'long long' but not 'll' format */
-# define @KWIML at _INT_BROKEN_INT64_C   /* system macro defined incorrectly */
-# define @KWIML at _INT_BROKEN_UINT64_C  /* system macro defined incorrectly */
-#elif defined(_MSC_VER) && _MSC_VER < 1400
-# define @KWIML at _INT__NO_FMTLL /* type 'long long' but not 'll' format */
-#endif
-
-#if @KWIML at _ABI_SIZEOF_LONG == 8
-# define @KWIML at _INT__FMT64 "l"
-#elif defined(@KWIML at _ABI_SIZEOF_LONG_LONG) && @KWIML at _ABI_SIZEOF_LONG_LONG == 8
-# if !defined(@KWIML at _INT__NO_FMTLL)
-#  define @KWIML at _INT__FMT64 "ll"
-# else
-#  define @KWIML at _INT__FMT64 "I64"
-# endif
-#elif defined(@KWIML at _ABI_SIZEOF___INT64)
-# if defined(__BORLANDC__)
-#  define @KWIML at _INT__FMT64 "L"
-# else
-#  define @KWIML at _INT__FMT64 "I64"
-# endif
-#endif
-
-/* 64-bit d, i */
-#if defined(@KWIML at _INT_HAVE_INT64_T) && defined(PRId64) \
-  && !defined(@KWIML at _INT_BROKEN_PRId64)
-# define @KWIML at _INT_PRId64 PRId64
-#elif defined(@KWIML at _INT__FMT64)
-# define @KWIML at _INT_PRId64 @KWIML at _INT__FMT64 "d"
-#endif
-#if defined(@KWIML at _INT_HAVE_INT64_T) && defined(SCNd64) \
-  && !defined(@KWIML at _INT_BROKEN_SCNd64)
-# define @KWIML at _INT_SCNd64 SCNd64
-#elif defined(@KWIML at _INT__FMT64) && !defined(@KWIML at _INT__NO_SCN64)
-# define @KWIML at _INT_SCNd64 @KWIML at _INT__FMT64 "d"
-#endif
-#if defined(@KWIML at _INT_HAVE_INT64_T) && defined(PRIi64) \
-  && !defined(@KWIML at _INT_BROKEN_PRIi64)
-# define @KWIML at _INT_PRIi64 PRIi64
-#elif defined(@KWIML at _INT__FMT64)
-# define @KWIML at _INT_PRIi64 @KWIML at _INT__FMT64 "d"
-#endif
-#if defined(@KWIML at _INT_HAVE_INT64_T) && defined(SCNi64) \
-  && !defined(@KWIML at _INT_BROKEN_SCNi64)
-# define @KWIML at _INT_SCNi64 SCNi64
-#elif defined(@KWIML at _INT__FMT64) && !defined(@KWIML at _INT__NO_SCN64)
-# define @KWIML at _INT_SCNi64 @KWIML at _INT__FMT64 "d"
-#endif
-
-/* 64-bit o, u, x, X */
-#if defined(@KWIML at _INT_HAVE_UINT64_T) && defined(PRIo64) \
-  && !defined(@KWIML at _INT_BROKEN_PRIo64)
-# define @KWIML at _INT_PRIo64 PRIo64
-#elif defined(@KWIML at _INT__FMT64)
-# define @KWIML at _INT_PRIo64 @KWIML at _INT__FMT64 "o"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT64_T) && defined(SCNo64) \
-  && !defined(@KWIML at _INT_BROKEN_SCNo64)
-# define @KWIML at _INT_SCNo64 SCNo64
-#elif defined(@KWIML at _INT__FMT64) && !defined(@KWIML at _INT__NO_SCN64)
-# define @KWIML at _INT_SCNo64 @KWIML at _INT__FMT64 "o"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT64_T) && defined(PRIu64) \
-  && !defined(@KWIML at _INT_BROKEN_PRIu64)
-# define @KWIML at _INT_PRIu64 PRIu64
-#elif defined(@KWIML at _INT__FMT64)
-# define @KWIML at _INT_PRIu64 @KWIML at _INT__FMT64 "u"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT64_T) && defined(SCNu64) \
-  && !defined(@KWIML at _INT_BROKEN_SCNu64)
-# define @KWIML at _INT_SCNu64 SCNu64
-#elif defined(@KWIML at _INT__FMT64) && !defined(@KWIML at _INT__NO_SCN64)
-# define @KWIML at _INT_SCNu64 @KWIML at _INT__FMT64 "u"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT64_T) && defined(PRIx64) \
-  && !defined(@KWIML at _INT_BROKEN_PRIx64)
-# define @KWIML at _INT_PRIx64 PRIx64
-#elif defined(@KWIML at _INT__FMT64)
-# define @KWIML at _INT_PRIx64 @KWIML at _INT__FMT64 "x"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT64_T) && defined(SCNx64) \
-  && !defined(@KWIML at _INT_BROKEN_SCNx64)
-# define @KWIML at _INT_SCNx64 SCNx64
-#elif defined(@KWIML at _INT__FMT64) && !defined(@KWIML at _INT__NO_SCN64)
-# define @KWIML at _INT_SCNx64 @KWIML at _INT__FMT64 "x"
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT64_T) && defined(PRIX64) \
-  && !defined(@KWIML at _INT_BROKEN_PRIX64)
-# define @KWIML at _INT_PRIX64 PRIX64
-#elif defined(@KWIML at _INT__FMT64)
-# define @KWIML at _INT_PRIX64 @KWIML at _INT__FMT64 "X"
-#endif
-
-/* 64-bit constants */
-#if defined(@KWIML at _INT_HAVE_INT64_T) && defined(INT64_C) \
-  && !defined(@KWIML at _INT_BROKEN_INT64_C)
-# define @KWIML at _INT_INT64_C(c) INT64_C(c)
-#elif @KWIML at _ABI_SIZEOF_LONG == 8
-# define @KWIML at _INT_INT64_C(c) c ## l
-#elif defined(@KWIML at _ABI_SIZEOF_LONG_LONG) && @KWIML at _ABI_SIZEOF_LONG_LONG == 8
-# define @KWIML at _INT_INT64_C(c) c ## ll
-#elif defined(@KWIML at _ABI_SIZEOF___INT64)
-# define @KWIML at _INT_INT64_C(c) c ## i64
-#endif
-#if defined(@KWIML at _INT_HAVE_UINT64_T) && defined(UINT64_C) \
-  && !defined(@KWIML at _INT_BROKEN_UINT64_C)
-# define @KWIML at _INT_UINT64_C(c) UINT64_C(c)
-#elif @KWIML at _ABI_SIZEOF_LONG == 8
-# define @KWIML at _INT_UINT64_C(c) c ## ul
-#elif defined(@KWIML at _ABI_SIZEOF_LONG_LONG) && @KWIML at _ABI_SIZEOF_LONG_LONG == 8
-# define @KWIML at _INT_UINT64_C(c) c ## ull
-#elif defined(@KWIML at _ABI_SIZEOF___INT64)
-# define @KWIML at _INT_UINT64_C(c) c ## ui64
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if defined(@KWIML at _INT_HAVE_INTPTR_T)
-# define @KWIML at _INT_intptr_t intptr_t
-#elif @KWIML at _ABI_SIZEOF_DATA_PTR == 4
-# define @KWIML at _INT_intptr_t @KWIML at _INT_int32_t
-#elif !defined(@KWIML at _INT_NO_INT64_T)
-# define @KWIML at _INT_intptr_t @KWIML at _INT_int64_t
-#elif defined(@KWIML at _INT_NO_ERROR_INTPTR_T)
-# define @KWIML at _INT_NO_INTPTR_T
-#else
-# error "No type known for 'intptr_t'."
-#endif
-#if defined(@KWIML at _INT_HAVE_UINTPTR_T)
-# define @KWIML at _INT_uintptr_t uintptr_t
-#elif @KWIML at _ABI_SIZEOF_DATA_PTR == 4
-# define @KWIML at _INT_uintptr_t @KWIML at _INT_uint32_t
-#elif !defined(@KWIML at _INT_NO_UINT64_T)
-# define @KWIML at _INT_uintptr_t @KWIML at _INT_uint64_t
-#elif defined(@KWIML at _INT_NO_ERROR_UINTPTR_T)
-# define @KWIML at _INT_NO_UINTPTR_T
-#else
-# error "No type known for 'uintptr_t'."
-#endif
-
-#if defined(@KWIML at _INT_HAVE_INTPTR_T) && defined(PRIdPTR) \
-  && !defined(@KWIML at _INT_BROKEN_PRIdPTR)
-# define @KWIML at _INT_PRIdPTR PRIdPTR
-#elif @KWIML at _ABI_SIZEOF_DATA_PTR == 4
-# define @KWIML at _INT_PRIdPTR @KWIML at _INT_PRId32
-#elif !defined(@KWIML at _INT_NO_UINT64_T)
-# define @KWIML at _INT_PRIdPTR @KWIML at _INT_PRId64
-#endif
-#if defined(@KWIML at _INT_HAVE_INTPTR_T) && defined(SCNdPTR) \
-  && !defined(@KWIML at _INT_BROKEN_SCNdPTR)
-# define @KWIML at _INT_SCNdPTR SCNdPTR
-#elif @KWIML at _ABI_SIZEOF_DATA_PTR == 4
-# define @KWIML at _INT_SCNdPTR @KWIML at _INT_SCNd32
-#elif !defined(@KWIML at _INT_NO_UINT64_T)
-# define @KWIML at _INT_SCNdPTR @KWIML at _INT_SCNd64
-#endif
-#if defined(@KWIML at _INT_HAVE_INTPTR_T) && defined(PRIiPTR) \
-  && !defined(@KWIML at _INT_BROKEN_PRIiPTR)
-# define @KWIML at _INT_PRIiPTR PRIiPTR
-#elif @KWIML at _ABI_SIZEOF_DATA_PTR == 4
-# define @KWIML at _INT_PRIiPTR @KWIML at _INT_PRIi32
-#elif !defined(@KWIML at _INT_NO_UINT64_T)
-# define @KWIML at _INT_PRIiPTR @KWIML at _INT_PRIi64
-#endif
-#if defined(@KWIML at _INT_HAVE_INTPTR_T) && defined(SCNiPTR) \
-  && !defined(@KWIML at _INT_BROKEN_SCNiPTR)
-# define @KWIML at _INT_SCNiPTR SCNiPTR
-#elif @KWIML at _ABI_SIZEOF_DATA_PTR == 4
-# define @KWIML at _INT_SCNiPTR @KWIML at _INT_SCNi32
-#elif !defined(@KWIML at _INT_NO_UINT64_T)
-# define @KWIML at _INT_SCNiPTR @KWIML at _INT_SCNi64
-#endif
-
-#if defined(@KWIML at _INT_HAVE_UINTPTR_T) && defined(PRIoPTR) \
-  && !defined(@KWIML at _INT_BROKEN_PRIoPTR)
-# define @KWIML at _INT_PRIoPTR PRIoPTR
-#elif @KWIML at _ABI_SIZEOF_DATA_PTR == 4
-# define @KWIML at _INT_PRIoPTR @KWIML at _INT_PRIo32
-#elif !defined(@KWIML at _INT_NO_UINT64_T)
-# define @KWIML at _INT_PRIoPTR @KWIML at _INT_PRIo64
-#endif
-#if defined(@KWIML at _INT_HAVE_UINTPTR_T) && defined(SCNoPTR) \
-  && !defined(@KWIML at _INT_BROKEN_SCNoPTR)
-# define @KWIML at _INT_SCNoPTR SCNoPTR
-#elif @KWIML at _ABI_SIZEOF_DATA_PTR == 4
-# define @KWIML at _INT_SCNoPTR @KWIML at _INT_SCNo32
-#elif !defined(@KWIML at _INT_NO_UINT64_T)
-# define @KWIML at _INT_SCNoPTR @KWIML at _INT_SCNo64
-#endif
-#if defined(@KWIML at _INT_HAVE_UINTPTR_T) && defined(PRIuPTR) \
-  && !defined(@KWIML at _INT_BROKEN_PRIuPTR)
-# define @KWIML at _INT_PRIuPTR PRIuPTR
-#elif @KWIML at _ABI_SIZEOF_DATA_PTR == 4
-# define @KWIML at _INT_PRIuPTR @KWIML at _INT_PRIu32
-#elif !defined(@KWIML at _INT_NO_UINT64_T)
-# define @KWIML at _INT_PRIuPTR @KWIML at _INT_PRIu64
-#endif
-#if defined(@KWIML at _INT_HAVE_UINTPTR_T) && defined(SCNuPTR) \
-  && !defined(@KWIML at _INT_BROKEN_SCNuPTR)
-# define @KWIML at _INT_SCNuPTR SCNuPTR
-#elif @KWIML at _ABI_SIZEOF_DATA_PTR == 4
-# define @KWIML at _INT_SCNuPTR @KWIML at _INT_SCNu32
-#elif !defined(@KWIML at _INT_NO_UINT64_T)
-# define @KWIML at _INT_SCNuPTR @KWIML at _INT_SCNu64
-#endif
-#if defined(@KWIML at _INT_HAVE_UINTPTR_T) && defined(PRIxPTR) \
-  && !defined(@KWIML at _INT_BROKEN_PRIxPTR)
-# define @KWIML at _INT_PRIxPTR PRIxPTR
-#elif @KWIML at _ABI_SIZEOF_DATA_PTR == 4
-# define @KWIML at _INT_PRIxPTR @KWIML at _INT_PRIx32
-#elif !defined(@KWIML at _INT_NO_UINT64_T)
-# define @KWIML at _INT_PRIxPTR @KWIML at _INT_PRIx64
-#endif
-#if defined(@KWIML at _INT_HAVE_UINTPTR_T) && defined(SCNxPTR) \
-  && !defined(@KWIML at _INT_BROKEN_SCNxPTR)
-# define @KWIML at _INT_SCNxPTR SCNxPTR
-#elif @KWIML at _ABI_SIZEOF_DATA_PTR == 4
-# define @KWIML at _INT_SCNxPTR @KWIML at _INT_SCNx32
-#elif !defined(@KWIML at _INT_NO_UINT64_T)
-# define @KWIML at _INT_SCNxPTR @KWIML at _INT_SCNx64
-#endif
-#if defined(@KWIML at _INT_HAVE_UINTPTR_T) && defined(PRIXPTR) \
-  && !defined(@KWIML at _INT_BROKEN_PRIXPTR)
-# define @KWIML at _INT_PRIXPTR PRIXPTR
-#elif @KWIML at _ABI_SIZEOF_DATA_PTR == 4
-# define @KWIML at _INT_PRIXPTR @KWIML at _INT_PRIX32
-#elif !defined(@KWIML at _INT_NO_UINT64_T)
-# define @KWIML at _INT_PRIXPTR @KWIML at _INT_PRIX64
-#endif
-
-/*--------------------------------------------------------------------------*/
-#if !defined(@KWIML at _INT_NO_VERIFY)
-#define @KWIML at _INT__VERIFY(n, x, y) extern int (*n)[x]; extern int (*n)[y]
-#define @KWIML at _INT__VERIFY_BOOL(m, b) @KWIML at _INT__VERIFY(m##__VERIFY__, 2, (b)?2:3)
-#define @KWIML at _INT__VERIFY_TYPE(t, s) @KWIML at _INT__VERIFY(t##__VERIFY__, s, sizeof(t))
-#define @KWIML at _INT__VERIFY_SIGN(t, u, o) @KWIML at _INT__VERIFY_BOOL(t##__SIGN, (t)((u)1 << ((sizeof(t)<<3)-1)) o 0)
-
- at KWIML@_INT__VERIFY_TYPE(@KWIML at _INT_int8_t,    1);
- at KWIML@_INT__VERIFY_TYPE(@KWIML at _INT_uint8_t,   1);
- at KWIML@_INT__VERIFY_TYPE(@KWIML at _INT_int16_t,   2);
- at KWIML@_INT__VERIFY_TYPE(@KWIML at _INT_uint16_t,  2);
- at KWIML@_INT__VERIFY_TYPE(@KWIML at _INT_int32_t,   4);
- at KWIML@_INT__VERIFY_TYPE(@KWIML at _INT_uint32_t,  4);
-#if !defined(@KWIML at _INT_NO_INT64_T)
- at KWIML@_INT__VERIFY_TYPE(@KWIML at _INT_int64_t,   8);
-#endif
-#if !defined(@KWIML at _INT_NO_UINT64_T)
- at KWIML@_INT__VERIFY_TYPE(@KWIML at _INT_uint64_t,  8);
-#endif
-#if !defined(@KWIML at _INT_NO_INTPTR_T)
- at KWIML@_INT__VERIFY_TYPE(@KWIML at _INT_intptr_t,  sizeof(void*));
-#endif
-#if !defined(@KWIML at _INT_NO_UINTPTR_T)
- at KWIML@_INT__VERIFY_TYPE(@KWIML at _INT_uintptr_t, sizeof(void*));
-#endif
-
- at KWIML@_INT__VERIFY_SIGN(@KWIML at _INT_int8_t,    @KWIML at _INT_uint8_t,   <);
- at KWIML@_INT__VERIFY_SIGN(@KWIML at _INT_uint8_t,   @KWIML at _INT_uint8_t,   >);
- at KWIML@_INT__VERIFY_SIGN(@KWIML at _INT_int16_t,   @KWIML at _INT_uint16_t,  <);
- at KWIML@_INT__VERIFY_SIGN(@KWIML at _INT_uint16_t,  @KWIML at _INT_uint16_t,  >);
- at KWIML@_INT__VERIFY_SIGN(@KWIML at _INT_int32_t,   @KWIML at _INT_uint32_t,  <);
- at KWIML@_INT__VERIFY_SIGN(@KWIML at _INT_uint32_t,  @KWIML at _INT_uint32_t,  >);
-#if !defined(@KWIML at _INT_NO_INT64_T)
- at KWIML@_INT__VERIFY_SIGN(@KWIML at _INT_int64_t,   @KWIML at _INT_uint64_t,  <);
-#endif
-#if !defined(@KWIML at _INT_NO_UINT64_T)
- at KWIML@_INT__VERIFY_SIGN(@KWIML at _INT_uint64_t,  @KWIML at _INT_uint64_t,  >);
-#endif
-#if !defined(@KWIML at _INT_NO_INTPTR_T)
- at KWIML@_INT__VERIFY_SIGN(@KWIML at _INT_intptr_t,  @KWIML at _INT_uintptr_t, <);
-#endif
-#if !defined(@KWIML at _INT_NO_UINTPTR_T)
- at KWIML@_INT__VERIFY_SIGN(@KWIML at _INT_uintptr_t, @KWIML at _INT_uintptr_t, >);
-#endif
-
-#undef @KWIML at _INT__VERIFY_SIGN
-#undef @KWIML at _INT__VERIFY_TYPE
-#undef @KWIML at _INT__VERIFY_BOOL
-#undef @KWIML at _INT__VERIFY
-
-#endif
-
-#endif
diff --git a/Utilities/KWIML/README.md b/Utilities/KWIML/README.md
new file mode 100644
index 0000000..37d72d1
--- /dev/null
+++ b/Utilities/KWIML/README.md
@@ -0,0 +1,36 @@
+Kitware Information Macro Library (KWIML)
+=========================================
+
+KWIML provides header files that use preprocessor tests to detect and
+provide information about the compiler and its target architecture.
+The headers contain no configuration-time test results and thus may
+be installed into an architecture-independent include directory.
+This makes them suitable for use in the public interface of any package.
+
+The following headers are provided.  See header comments for details:
+
+* [kwiml/abi.h][]: Fundamental type size and representation.
+
+* [kwiml/int.h][]: Fixed-size integer types and format specifiers.
+
+* [kwiml/version.h][]: Information about this version of KWIML.
+
+The [test][] subdirectory builds tests that verify correctness of the
+information provided by each header.
+
+License
+=======
+
+KWIML is distributed under the OSI-approved 3-clause BSD License.
+
+Files used only for build and test purposes contain a copyright notice and
+reference [Copyright.txt][] for details.  Headers meant for installation and
+distribution outside the source tree come with full inlined copies of the
+copyright notice and license text.  This makes them suitable for distribution
+with any package under compatible license terms.
+
+[Copyright.txt]: Copyright.txt
+[kwiml/abi.h]: include/kwiml/abi.h
+[kwiml/int.h]: include/kwiml/int.h
+[kwiml/version.h]: src/version.h.in
+[test]: test/
diff --git a/Utilities/KWIML/README.txt b/Utilities/KWIML/README.txt
deleted file mode 100644
index 6bdf859..0000000
--- a/Utilities/KWIML/README.txt
+++ /dev/null
@@ -1,29 +0,0 @@
-KWIML - The Kitware Information Macro Library
-
-KWIML provides header files that use preprocessor tests to detect and
-provide information about the compiler and its target architecture.  The
-headers contain no configuration-time test results and thus may be
-installed into an architecture-independent include directory.  This
-makes them suitable for use in the public interface of any package.
-
-This source tree is intended for distribution inside the source trees of
-other packages.  In order to avoid name collisions among multiple
-packages the KWIML headers are configured with a per-package prefix on
-both the header locations and the macros they define.  See comments in
-CMakeLists.txt for instructions to include KWIML inside another project.
-
-The entire KWIML source tree is distributed under the OSI-approved
-3-clause BSD License.  Files used only for build and test purposes
-contain a copyright notice and reference Copyright.txt for details.
-Headers meant for installation and distribution outside the source tree
-come with full inlined copies of the copyright notice and license text.
-This makes them suitable for distribution with any package under
-compatible license terms.
-
-The following components are provided.  See header comments for details:
-
-  ABI.h = Fundamental type size and representation
-  INT.h = Fixed-size integer types and format specifiers
-
-The "test" subdirectory builds tests that verify correctness of the
-information provided by each header.
diff --git a/Utilities/KWIML/include/kwiml/abi.h b/Utilities/KWIML/include/kwiml/abi.h
new file mode 100644
index 0000000..3626361
--- /dev/null
+++ b/Utilities/KWIML/include/kwiml/abi.h
@@ -0,0 +1,562 @@
+/*============================================================================
+  Kitware Information Macro Library
+  Copyright 2010-2015 Kitware, Inc.
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  * Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+
+  * Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+
+  * Neither the name of Kitware, Inc. nor the names of its contributors
+    may be used to endorse or promote products derived from this
+    software without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+============================================================================*/
+/*
+This header defines macros with information about the C ABI.
+Only information that can be determined using the preprocessor at
+compilation time is available.  No try-compile results may be added
+here.  Instead we memorize results on platforms of interest.
+
+An includer may optionally define the following macros to suppress errors:
+
+  KWIML_ABI_NO_VERIFY          = skip verification declarations
+  KWIML_ABI_NO_ERROR_CHAR_SIGN = signedness of 'char' may be unknown
+  KWIML_ABI_NO_ERROR_LONG_LONG = existence of 'long long' may be unknown
+  KWIML_ABI_NO_ERROR_ENDIAN    = byte order of CPU may be unknown
+
+An includer may test the following macros after inclusion:
+
+  KWIML_ABI_VERSION           = interface version number # of this header
+
+  KWIML_ABI_SIZEOF_DATA_PTR   = sizeof(void*)
+  KWIML_ABI_SIZEOF_CODE_PTR   = sizeof(void(*)(void))
+  KWIML_ABI_SIZEOF_FLOAT      = sizeof(float)
+  KWIML_ABI_SIZEOF_DOUBLE     = sizeof(double)
+  KWIML_ABI_SIZEOF_CHAR       = sizeof(char)
+  KWIML_ABI_SIZEOF_SHORT      = sizeof(short)
+  KWIML_ABI_SIZEOF_INT        = sizeof(int)
+  KWIML_ABI_SIZEOF_LONG       = sizeof(long)
+
+  KWIML_ABI_SIZEOF_LONG_LONG  = sizeof(long long) or 0 if not a type
+    Undefined if existence is unknown and error suppression macro
+    KWIML_ABI_NO_ERROR_LONG_LONG was defined.
+
+  KWIML_ABI_SIZEOF___INT64    = 8 if '__int64' exists or 0 if not
+    Undefined if existence is unknown.
+
+  KWIML_ABI___INT64_IS_LONG   = 1 if '__int64' is 'long' (same type)
+    Undefined otherwise.
+  KWIML_ABI___INT64_IS_LONG_LONG = 1 if '__int64' is 'long long' (same type)
+    Undefined otherwise.
+  KWIML_ABI___INT64_IS_UNIQUE = 1 if '__int64' is a distinct type
+    Undefined otherwise.
+
+  KWIML_ABI_CHAR_IS_UNSIGNED  = 1 if 'char' is unsigned, else undefined
+  KWIML_ABI_CHAR_IS_SIGNED    = 1 if 'char' is signed, else undefined
+    One of these is defined unless signedness of 'char' is unknown and
+    error suppression macro KWIML_ABI_NO_ERROR_CHAR_SIGN was defined.
+
+  KWIML_ABI_ENDIAN_ID_BIG    = id for big-endian (always defined)
+  KWIML_ABI_ENDIAN_ID_LITTLE = id for little-endian (always defined)
+  KWIML_ABI_ENDIAN_ID        = id of byte order of target CPU
+    Defined to KWIML_ABI_ENDIAN_ID_BIG or KWIML_ABI_ENDIAN_ID_LITTLE
+    unless byte order is unknown and error suppression macro
+    KWIML_ABI_NO_ERROR_ENDIAN was defined.
+
+We verify most results using dummy "extern" declarations that are
+invalid if the macros are wrong.  Verification is disabled if
+suppression macro KWIML_ABI_NO_VERIFY was defined.
+*/
+
+#define KWIML_ABI_private_VERSION 1
+
+/* Guard definition of this version.  */
+#ifndef KWIML_ABI_detail_DEFINED_VERSION_1
+# define KWIML_ABI_detail_DEFINED_VERSION_1 1
+# define KWIML_ABI_private_DO_DEFINE
+#endif
+
+/* Guard verification of this version.  */
+#if !defined(KWIML_ABI_NO_VERIFY)
+# ifndef KWIML_ABI_detail_VERIFIED_VERSION_1
+#  define KWIML_ABI_detail_VERIFIED_VERSION_1
+#  define KWIML_ABI_private_DO_VERIFY
+# endif
+#endif
+
+#ifdef KWIML_ABI_private_DO_DEFINE
+#undef KWIML_ABI_private_DO_DEFINE
+
+/* Define version as most recent of those included.  */
+#if !defined(KWIML_ABI_VERSION) || KWIML_ABI_VERSION < KWIML_ABI_private_VERSION
+# undef KWIML_ABI_VERSION
+# define KWIML_ABI_VERSION 1
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if !defined(KWIML_ABI_SIZEOF_DATA_PTR)
+# if defined(__SIZEOF_POINTER__)
+#  define KWIML_ABI_SIZEOF_DATA_PTR __SIZEOF_POINTER__
+# elif defined(_SIZE_PTR)
+#  define KWIML_ABI_SIZEOF_DATA_PTR (_SIZE_PTR >> 3)
+# elif defined(_LP64) || defined(__LP64__)
+#  define KWIML_ABI_SIZEOF_DATA_PTR 8
+# elif defined(_ILP32)
+#  define KWIML_ABI_SIZEOF_DATA_PTR 4
+# elif defined(__64BIT__) /* IBM XL */
+#  define KWIML_ABI_SIZEOF_DATA_PTR 8
+# elif defined(_M_X64)
+#  define KWIML_ABI_SIZEOF_DATA_PTR 8
+# elif defined(__ia64)
+#  define KWIML_ABI_SIZEOF_DATA_PTR 8
+# elif defined(__sparcv9)
+#  define KWIML_ABI_SIZEOF_DATA_PTR 8
+# elif defined(__x86_64) || defined(__x86_64__)
+#  define KWIML_ABI_SIZEOF_DATA_PTR 8
+# elif defined(__amd64) || defined(__amd64__)
+#  define KWIML_ABI_SIZEOF_DATA_PTR 8
+# elif defined(__i386) || defined(__i386__)
+#  define KWIML_ABI_SIZEOF_DATA_PTR 4
+# endif
+#endif
+#if !defined(KWIML_ABI_SIZEOF_DATA_PTR)
+# define KWIML_ABI_SIZEOF_DATA_PTR 4
+#endif
+#if !defined(KWIML_ABI_SIZEOF_CODE_PTR)
+# define KWIML_ABI_SIZEOF_CODE_PTR KWIML_ABI_SIZEOF_DATA_PTR
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if !defined(KWIML_ABI_SIZEOF_CHAR)
+# define KWIML_ABI_SIZEOF_CHAR 1
+#endif
+
+#if !defined(KWIML_ABI_CHAR_IS_UNSIGNED) && !defined(KWIML_ABI_CHAR_IS_SIGNED)
+# if defined(__CHAR_UNSIGNED__) /* GNU, some IBM XL, others?  */
+#  define KWIML_ABI_CHAR_IS_UNSIGNED 1
+# elif defined(_CHAR_UNSIGNED) /* Intel, IBM XL, MSVC, Borland, others?  */
+#  define KWIML_ABI_CHAR_IS_UNSIGNED 1
+# elif defined(_CHAR_SIGNED) /* IBM XL, others? */
+#  define KWIML_ABI_CHAR_IS_SIGNED 1
+# elif defined(__CHAR_SIGNED__) /* IBM XL, Watcom, others? */
+#  define KWIML_ABI_CHAR_IS_SIGNED 1
+# elif defined(__SIGNED_CHARS__) /* EDG, Intel, SGI MIPSpro */
+#  define KWIML_ABI_CHAR_IS_SIGNED 1
+# elif defined(_CHAR_IS_SIGNED) /* Some SunPro, others? */
+#  define KWIML_ABI_CHAR_IS_SIGNED 1
+# elif defined(_CHAR_IS_UNSIGNED) /* SunPro, others? */
+#  define KWIML_ABI_CHAR_IS_UNSIGNED 1
+# elif defined(__GNUC__) /* GNU default */
+#  define KWIML_ABI_CHAR_IS_SIGNED 1
+# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* SunPro default */
+#  define KWIML_ABI_CHAR_IS_SIGNED 1
+# elif defined(__HP_cc) || defined(__HP_aCC) /* HP default (unless +uc) */
+#  define KWIML_ABI_CHAR_IS_SIGNED 1
+# elif defined(_SGI_COMPILER_VERSION) /* SGI MIPSpro default */
+#  define KWIML_ABI_CHAR_IS_UNSIGNED 1
+# elif defined(__PGIC__) /* PGI default */
+#  define KWIML_ABI_CHAR_IS_SIGNED 1
+# elif defined(_MSC_VER) /* MSVC default */
+#  define KWIML_ABI_CHAR_IS_SIGNED 1
+# elif defined(__WATCOMC__) /* Watcom default */
+#  define KWIML_ABI_CHAR_IS_UNSIGNED 1
+# elif defined(__BORLANDC__) /* Borland default */
+#  define KWIML_ABI_CHAR_IS_SIGNED 1
+# elif defined(__hpux) /* Old HP: no __HP_cc/__HP_aCC/__GNUC__ above */
+#  define KWIML_ABI_CHAR_IS_SIGNED 1 /* (unless +uc) */
+# endif
+#endif
+#if !defined(KWIML_ABI_CHAR_IS_UNSIGNED) && !defined(KWIML_ABI_CHAR_IS_SIGNED) \
+ && !defined(KWIML_ABI_NO_ERROR_CHAR_SIGN)
+# error "Signedness of 'char' unknown."
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if !defined(KWIML_ABI_SIZEOF_SHORT)
+# if defined(__SIZEOF_SHORT__)
+#  define KWIML_ABI_SIZEOF_SHORT __SIZEOF_SHORT__
+# endif
+#endif
+#if !defined(KWIML_ABI_SIZEOF_SHORT)
+# define KWIML_ABI_SIZEOF_SHORT 2
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if !defined(KWIML_ABI_SIZEOF_INT)
+# if defined(__SIZEOF_INT__)
+#  define KWIML_ABI_SIZEOF_INT __SIZEOF_INT__
+# elif defined(_SIZE_INT)
+#  define KWIML_ABI_SIZEOF_INT (_SIZE_INT >> 3)
+# endif
+#endif
+#if !defined(KWIML_ABI_SIZEOF_INT)
+# define KWIML_ABI_SIZEOF_INT 4
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if !defined(KWIML_ABI_SIZEOF_LONG)
+# if defined(__SIZEOF_LONG__)
+#  define KWIML_ABI_SIZEOF_LONG __SIZEOF_LONG__
+# elif defined(_SIZE_LONG)
+#  define KWIML_ABI_SIZEOF_LONG (_SIZE_LONG >> 3)
+# elif defined(__LONG_MAX__)
+#  if __LONG_MAX__ == 0x7fffffff
+#   define KWIML_ABI_SIZEOF_LONG 4
+#  elif __LONG_MAX__>>32 == 0x7fffffff
+#   define KWIML_ABI_SIZEOF_LONG 8
+#  endif
+# elif defined(_MSC_VER) /* MSVC and Intel on Windows */
+#  define KWIML_ABI_SIZEOF_LONG 4
+# endif
+#endif
+#if !defined(KWIML_ABI_SIZEOF_LONG)
+# define KWIML_ABI_SIZEOF_LONG KWIML_ABI_SIZEOF_DATA_PTR
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if !defined(KWIML_ABI_SIZEOF_LONG_LONG)
+# if defined(__SIZEOF_LONG_LONG__)
+#  define KWIML_ABI_SIZEOF_LONG_LONG __SIZEOF_LONG_LONG__
+# elif defined(__LONG_LONG_MAX__)
+#  if __LONG_LONG_MAX__ == 0x7fffffff
+#   define KWIML_ABI_SIZEOF_LONG_LONG 4
+#  elif __LONG_LONG_MAX__>>32 == 0x7fffffff
+#   define KWIML_ABI_SIZEOF_LONG_LONG 8
+#  endif
+# endif
+#endif
+#if !defined(KWIML_ABI_SIZEOF_LONG_LONG)
+# if defined(_LONGLONG) /* SGI, some GNU, perhaps others.  */ \
+  && !defined(_MSC_VER)
+#  define KWIML_ABI_SIZEOF_LONG_LONG 8
+# elif defined(_LONG_LONG) /* IBM XL, perhaps others.  */
+#  define KWIML_ABI_SIZEOF_LONG_LONG 8
+# elif defined(__NO_LONG_LONG) /* EDG */
+#  define KWIML_ABI_SIZEOF_LONG_LONG 0
+# elif defined(__cplusplus) && __cplusplus > 199711L /* C++0x */
+#  define KWIML_ABI_SIZEOF_LONG_LONG 8
+# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
+#  define KWIML_ABI_SIZEOF_LONG_LONG 8
+# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* SunPro */
+#  define KWIML_ABI_SIZEOF_LONG_LONG 8
+# elif defined(__HP_cc) || defined(__HP_aCC) /* HP */
+#  define KWIML_ABI_SIZEOF_LONG_LONG 8
+# elif defined(__PGIC__) /* PGI */
+#  define KWIML_ABI_SIZEOF_LONG_LONG 8
+# elif defined(__WATCOMC__) /* Watcom */
+#  define KWIML_ABI_SIZEOF_LONG_LONG 8
+# elif defined(__INTEL_COMPILER) /* Intel */
+#  define KWIML_ABI_SIZEOF_LONG_LONG 8
+# elif defined(__BORLANDC__) /* Borland */
+#  if __BORLANDC__ >= 0x0560
+#   define KWIML_ABI_SIZEOF_LONG_LONG 8
+#  else
+#   define KWIML_ABI_SIZEOF_LONG_LONG 0
+#  endif
+# elif defined(_MSC_VER) /* Microsoft */
+#  if _MSC_VER >= 1310
+#   define KWIML_ABI_SIZEOF_LONG_LONG 8
+#  else
+#   define KWIML_ABI_SIZEOF_LONG_LONG 0
+#  endif
+# elif defined(__GNUC__) /* GNU */
+#  define KWIML_ABI_SIZEOF_LONG_LONG 8
+# elif defined(__hpux) /* Old HP: no __HP_cc/__HP_aCC/__GNUC__ above */
+#  define KWIML_ABI_SIZEOF_LONG_LONG 8
+# endif
+#endif
+#if !defined(KWIML_ABI_SIZEOF_LONG_LONG) && !defined(KWIML_ABI_NO_ERROR_LONG_LONG)
+# error "Existence of 'long long' unknown."
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if !defined(KWIML_ABI_SIZEOF___INT64)
+# if defined(__INTEL_COMPILER)
+#  define KWIML_ABI_SIZEOF___INT64 8
+# elif defined(_MSC_VER)
+#  define KWIML_ABI_SIZEOF___INT64 8
+# elif defined(__BORLANDC__)
+#  define KWIML_ABI_SIZEOF___INT64 8
+# else
+#  define KWIML_ABI_SIZEOF___INT64 0
+# endif
+#endif
+
+#if defined(KWIML_ABI_SIZEOF___INT64) && KWIML_ABI_SIZEOF___INT64 > 0
+# if KWIML_ABI_SIZEOF_LONG == 8
+#  define KWIML_ABI___INT64_IS_LONG 1
+# elif defined(KWIML_ABI_SIZEOF_LONG_LONG) && KWIML_ABI_SIZEOF_LONG_LONG == 8
+#  define KWIML_ABI___INT64_IS_LONG_LONG 1
+# else
+#  define KWIML_ABI___INT64_IS_UNIQUE 1
+# endif
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if !defined(KWIML_ABI_SIZEOF_FLOAT)
+# if defined(__SIZEOF_FLOAT__)
+#  define KWIML_ABI_SIZEOF_FLOAT __SIZEOF_FLOAT__
+# endif
+#endif
+#if !defined(KWIML_ABI_SIZEOF_FLOAT)
+# define KWIML_ABI_SIZEOF_FLOAT 4
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if !defined(KWIML_ABI_SIZEOF_DOUBLE)
+# if defined(__SIZEOF_DOUBLE__)
+#  define KWIML_ABI_SIZEOF_DOUBLE __SIZEOF_DOUBLE__
+# endif
+#endif
+#if !defined(KWIML_ABI_SIZEOF_DOUBLE)
+# define KWIML_ABI_SIZEOF_DOUBLE 8
+#endif
+
+/*--------------------------------------------------------------------------*/
+/* Identify possible endian cases.  The macro KWIML_ABI_ENDIAN_ID will be
+   defined to one of these, or undefined if unknown.  */
+#if !defined(KWIML_ABI_ENDIAN_ID_BIG)
+# define KWIML_ABI_ENDIAN_ID_BIG    4321
+#endif
+#if !defined(KWIML_ABI_ENDIAN_ID_LITTLE)
+# define KWIML_ABI_ENDIAN_ID_LITTLE 1234
+#endif
+#if KWIML_ABI_ENDIAN_ID_BIG == KWIML_ABI_ENDIAN_ID_LITTLE
+# error "KWIML_ABI_ENDIAN_ID_BIG == KWIML_ABI_ENDIAN_ID_LITTLE"
+#endif
+
+#if defined(KWIML_ABI_ENDIAN_ID) /* Skip #elif cases if already defined.  */
+
+/* Use dedicated symbols if the compiler defines them.  Do this first
+   because some architectures allow runtime byte order selection by
+   the operating system (values for such architectures below are
+   guesses for compilers that do not define a dedicated symbol).
+   Ensure that only one is defined in case the platform or a header
+   defines both as possible values for some third symbol.  */
+#elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+#elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
+#elif defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+#elif defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
+
+/* Alpha */
+#elif defined(__alpha) || defined(__alpha__) || defined(_M_ALPHA)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
+
+/* Arm */
+#elif defined(__arm__)
+# if !defined(__ARMEB__)
+#  define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
+# else
+#  define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+# endif
+
+/* Intel x86 */
+#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
+#elif defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
+#elif defined(__MWERKS__) && defined(__INTEL__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
+
+/* Intel x86-64 */
+#elif defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
+#elif defined(__amd64) || defined(__amd64__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
+
+/* Intel Architecture-64 (Itanium) */
+#elif defined(__ia64) || defined(__ia64__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
+#elif defined(_IA64) || defined(__IA64__) || defined(_M_IA64)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
+
+/* PowerPC */
+#elif defined(__powerpc) || defined(__powerpc__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+#elif defined(__ppc) || defined(__ppc__) || defined(__POWERPC__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+
+/* SPARC */
+#elif defined(__sparc) || defined(__sparc__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+
+/* HP/PA RISC */
+#elif defined(__hppa) || defined(__hppa__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+
+/* Motorola 68k */
+#elif defined(__m68k__) || defined(M68000)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+
+/* MIPSel (MIPS little endian) */
+#elif defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
+
+/* MIPSeb (MIPS big endian) */
+#elif defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+
+/* MIPS (fallback, big endian) */
+#elif defined(__mips) || defined(__mips__) || defined(__MIPS__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+
+/* NIOS2 */
+#elif defined(__NIOS2__) || defined(__NIOS2) || defined(__nios2__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
+
+/* OpenRISC 1000 */
+#elif defined(__or1k__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+
+/* RS/6000 */
+#elif defined(__THW_RS600) || defined(_IBMR2) || defined(_POWER)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+#elif defined(_ARCH_PWR) || defined(_ARCH_PWR2)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+
+/* System/370 */
+#elif defined(__370__) || defined(__THW_370__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+
+/* System/390 */
+#elif defined(__s390__) || defined(__s390x__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+
+/* z/Architecture */
+#elif defined(__SYSC_ZARCH__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+
+/* VAX */
+#elif defined(__vax__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+
+/* Aarch64 */
+#elif defined(__aarch64__)
+# if !defined(__AARCH64EB__)
+#  define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
+# else
+#  define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+# endif
+
+/* Xtensa */
+#elif defined(__XTENSA_EB__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
+#elif defined(__XTENSA_EL__)
+# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
+
+/* Unknown CPU */
+#elif !defined(KWIML_ABI_NO_ERROR_ENDIAN)
+# error "Byte order of target CPU unknown."
+#endif
+
+#endif /* KWIML_ABI_private_DO_DEFINE */
+
+/*--------------------------------------------------------------------------*/
+#ifdef KWIML_ABI_private_DO_VERIFY
+#undef KWIML_ABI_private_DO_VERIFY
+
+#if defined(_MSC_VER)
+# pragma warning (push)
+# pragma warning (disable:4310) /* cast truncates constant value */
+#endif
+
+#define KWIML_ABI_private_VERIFY(n, x, y) KWIML_ABI_private_VERIFY_0(KWIML_ABI_private_VERSION, n, x, y)
+#define KWIML_ABI_private_VERIFY_0(V, n, x, y) KWIML_ABI_private_VERIFY_1(V, n, x, y)
+#define KWIML_ABI_private_VERIFY_1(V, n, x, y) extern int (*n##_v##V)[x]; extern int (*n##_v##V)[y]
+
+#define KWIML_ABI_private_VERIFY_SAME_IMPL(n, x, y) KWIML_ABI_private_VERIFY_SAME_IMPL_0(KWIML_ABI_private_VERSION, n, x, y)
+#define KWIML_ABI_private_VERIFY_SAME_IMPL_0(V, n, x, y) KWIML_ABI_private_VERIFY_SAME_IMPL_1(V, n, x, y)
+#define KWIML_ABI_private_VERIFY_SAME_IMPL_1(V, n, x, y) extern int (*n##_v##V)(x*); extern int (*n##_v##V)(y*)
+
+#define KWIML_ABI_private_VERIFY_DIFF_IMPL(n, x, y) KWIML_ABI_private_VERIFY_DIFF_IMPL_0(KWIML_ABI_private_VERSION, n, x, y)
+#define KWIML_ABI_private_VERIFY_DIFF_IMPL_0(V, n, x, y) KWIML_ABI_private_VERIFY_DIFF_IMPL_1(V, n, x, y)
+#if defined(__cplusplus)
+# define KWIML_ABI_private_VERIFY_DIFF_IMPL_1(V, n, x, y) extern int* n##_v##V(x*); extern char* n##_v##V(y*)
+#else
+# define KWIML_ABI_private_VERIFY_DIFF_IMPL_1(V, n, x, y) extern int* n##_v##V(x*) /* TODO: possible? */
+#endif
+
+#define KWIML_ABI_private_VERIFY_BOOL(m, b) KWIML_ABI_private_VERIFY(KWIML_ABI_detail_VERIFY_##m, 2, (b)?2:3)
+#define KWIML_ABI_private_VERIFY_SIZE(m, t) KWIML_ABI_private_VERIFY(KWIML_ABI_detail_VERIFY_##m, m, sizeof(t))
+#define KWIML_ABI_private_VERIFY_SAME(m, x, y) KWIML_ABI_private_VERIFY_SAME_IMPL(KWIML_ABI_detail_VERIFY_##m, x, y)
+#define KWIML_ABI_private_VERIFY_DIFF(m, x, y) KWIML_ABI_private_VERIFY_DIFF_IMPL(KWIML_ABI_detail_VERIFY_##m, x, y)
+
+KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_DATA_PTR, int*);
+KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_CODE_PTR, int(*)(int));
+KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_CHAR, char);
+KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_SHORT, short);
+KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_INT, int);
+KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_LONG, long);
+#if defined(KWIML_ABI_SIZEOF_LONG_LONG) && KWIML_ABI_SIZEOF_LONG_LONG > 0
+KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_LONG_LONG, long long);
+#endif
+#if defined(KWIML_ABI_SIZEOF___INT64) && KWIML_ABI_SIZEOF___INT64 > 0
+KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF___INT64, __int64);
+#endif
+KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_FLOAT, float);
+KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_DOUBLE, double);
+
+#if defined(KWIML_ABI___INT64_IS_LONG)
+KWIML_ABI_private_VERIFY_SAME(KWIML_ABI___INT64_IS_LONG, __int64, long);
+#elif defined(KWIML_ABI___INT64_IS_LONG_LONG)
+KWIML_ABI_private_VERIFY_SAME(KWIML_ABI___INT64_IS_LONG_LONG, __int64, long long);
+#elif defined(KWIML_ABI_SIZEOF___INT64) && KWIML_ABI_SIZEOF___INT64 > 0
+KWIML_ABI_private_VERIFY_DIFF(KWIML_ABI___INT64_NOT_LONG, __int64, long);
+# if defined(KWIML_ABI_SIZEOF_LONG_LONG) && KWIML_ABI_SIZEOF_LONG_LONG > 0
+KWIML_ABI_private_VERIFY_DIFF(KWIML_ABI___INT64_NOT_LONG_LONG, __int64, long long);
+# endif
+#endif
+
+#if defined(KWIML_ABI_CHAR_IS_UNSIGNED)
+KWIML_ABI_private_VERIFY_BOOL(KWIML_ABI_CHAR_IS_UNSIGNED, (char)0x80 > 0);
+#elif defined(KWIML_ABI_CHAR_IS_SIGNED)
+KWIML_ABI_private_VERIFY_BOOL(KWIML_ABI_CHAR_IS_SIGNED,   (char)0x80 < 0);
+#endif
+
+#undef KWIML_ABI_private_VERIFY_DIFF
+#undef KWIML_ABI_private_VERIFY_SAME
+#undef KWIML_ABI_private_VERIFY_SIZE
+#undef KWIML_ABI_private_VERIFY_BOOL
+
+#undef KWIML_ABI_private_VERIFY_DIFF_IMPL_1
+#undef KWIML_ABI_private_VERIFY_DIFF_IMPL_0
+#undef KWIML_ABI_private_VERIFY_DIFF_IMPL
+
+#undef KWIML_ABI_private_VERIFY_SAME_IMPL_1
+#undef KWIML_ABI_private_VERIFY_SAME_IMPL_0
+#undef KWIML_ABI_private_VERIFY_SAME_IMPL
+
+#undef KWIML_ABI_private_VERIFY_1
+#undef KWIML_ABI_private_VERIFY_0
+#undef KWIML_ABI_private_VERIFY
+
+#if defined(_MSC_VER)
+# pragma warning (pop)
+#endif
+
+#endif /* KWIML_ABI_private_DO_VERIFY */
+
+#undef KWIML_ABI_private_VERSION
diff --git a/Utilities/KWIML/include/kwiml/int.h b/Utilities/KWIML/include/kwiml/int.h
new file mode 100644
index 0000000..b297ace
--- /dev/null
+++ b/Utilities/KWIML/include/kwiml/int.h
@@ -0,0 +1,1069 @@
+/*============================================================================
+  Kitware Information Macro Library
+  Copyright 2010-2015 Kitware, Inc.
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  * Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+
+  * Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+
+  * Neither the name of Kitware, Inc. nor the names of its contributors
+    may be used to endorse or promote products derived from this
+    software without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+============================================================================*/
+/*
+This header defines macros with information about sized integer types.
+Only information that can be determined using the preprocessor at
+compilation time is available.  No try-compile results may be added
+here.  Instead we memorize results on platforms of interest.
+
+An includer may optionally define the following macros to suppress errors:
+
+Input:
+  KWIML_INT_NO_VERIFY          = skip verification declarations
+  KWIML_INT_NO_ERROR_INT64_T   = type 'KWIML_INT_int64_t' is optional (*)
+  KWIML_INT_NO_ERROR_UINT64_T  = type 'KWIML_INT_uint64_t' is optional (*)
+  KWIML_INT_NO_ERROR_INTPTR_T  = type 'KWIML_INT_intptr_t' is optional (*)
+  KWIML_INT_NO_ERROR_UINTPTR_T = type 'KWIML_INT_uintptr_t' is optional (*)
+
+An includer may optionally define the following macros to override defaults.
+Either way, an includer may test these macros after inclusion:
+
+  KWIML_INT_HAVE_STDINT_H   = include <stdint.h>
+  KWIML_INT_NO_STDINT_H     = do not include <stdint.h>
+  KWIML_INT_HAVE_INTTYPES_H = include <inttypes.h>
+  KWIML_INT_NO_INTTYPES_H   = do not include <inttypes.h>
+
+An includer may test the following macros after inclusion:
+
+  KWIML_INT_VERSION         = interface version number # of this header
+
+  KWIML_INT_HAVE_INT#_T     = type 'int#_t' is available
+  KWIML_INT_HAVE_UINT#_T    = type 'uint#_t' is available
+                                # = 8, 16, 32, 64, PTR
+
+  KWIML_INT_int#_t          = signed integer type exactly # bits wide
+  KWIML_INT_uint#_t         = unsigned integer type exactly # bits wide
+                                # = 8, 16, 32, 64 (*), ptr (*)
+
+  KWIML_INT_NO_INT64_T      = type 'KWIML_INT_int64_t' not available
+  KWIML_INT_NO_UINT64_T     = type 'KWIML_INT_uint64_t' not available
+  KWIML_INT_NO_INTPTR_T     = type 'KWIML_INT_intptr_t' not available
+  KWIML_INT_NO_UINTPTR_T    = type 'KWIML_INT_uintptr_t' not available
+
+  KWIML_INT_INT#_C(c)       = signed integer constant at least # bits wide
+  KWIML_INT_UINT#_C(c)      = unsigned integer constant at least # bits wide
+                                # = 8, 16, 32, 64 (*)
+
+  KWIML_INT_<fmt>#          = print or scan format, <fmt> in table below
+                                # = 8, 16, 32, 64, PTR (*)
+
+             signed                unsigned
+           ----------- ------------------------------
+          |  decimal  | decimal  octal   hexadecimal |
+    print | PRId PRIi |  PRIu    PRIo    PRIx  PRIX  |
+     scan | SCNd SCNi |  SCNu    SCNo    SCNx        |
+           ----------- ------------------------------
+
+    The SCN*8 and SCN*64 format macros will not be defined on systems
+    with scanf implementations known not to support them.
+
+  KWIML_INT_BROKEN_<fmt># = macro <fmt># is incorrect if defined
+    Some compilers define integer format macros incorrectly for their
+    own formatted print/scan implementations.
+
+  KWIML_INT_BROKEN_INT#_C  = macro INT#_C is incorrect if defined
+  KWIML_INT_BROKEN_UINT#_C = macro UINT#_C is incorrect if defined
+    Some compilers define integer constant macros incorrectly and
+    cannot handle literals as large as the integer type or even
+    produce bad preprocessor syntax.
+
+  KWIML_INT_BROKEN_INT8_T   = type 'int8_t' is available but incorrect
+    Some compilers have a flag to make 'char' (un)signed but do not account
+    for it while defining int8_t in the non-default case.
+
+  The broken cases do not affect correctness of the macros documented above.
+*/
+
+#include "abi.h"
+
+#define KWIML_INT_private_VERSION 1
+
+/* Guard definition of this version.  */
+#ifndef KWIML_INT_detail_DEFINED_VERSION_1
+# define KWIML_INT_detail_DEFINED_VERSION_1 1
+# define KWIML_INT_private_DO_DEFINE
+#endif
+
+/* Guard verification of this version.  */
+#if !defined(KWIML_INT_NO_VERIFY)
+# ifndef KWIML_INT_detail_VERIFIED_VERSION_1
+#  define KWIML_INT_detail_VERIFIED_VERSION_1
+#  define KWIML_INT_private_DO_VERIFY
+# endif
+#endif
+
+#ifdef KWIML_INT_private_DO_DEFINE
+#undef KWIML_INT_private_DO_DEFINE
+
+/* Define version as most recent of those included.  */
+#if !defined(KWIML_INT_VERSION) || KWIML_INT_VERSION < KWIML_INT_private_VERSION
+# undef KWIML_INT_VERSION
+# define KWIML_INT_VERSION 1
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if defined(KWIML_INT_HAVE_STDINT_H) /* Already defined. */
+#elif defined(KWIML_INT_NO_STDINT_H) /* Already defined. */
+#elif defined(HAVE_STDINT_H) /* Optionally provided by includer.  */
+# define KWIML_INT_HAVE_STDINT_H 1
+#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
+# define KWIML_INT_HAVE_STDINT_H 1
+#elif defined(_MSC_VER) /* MSVC */
+# if _MSC_VER >= 1600
+#  define KWIML_INT_HAVE_STDINT_H 1
+# else
+#  define KWIML_INT_NO_STDINT_H 1
+# endif
+#elif defined(__BORLANDC__) /* Borland */
+# if __BORLANDC__ >= 0x560
+#  define KWIML_INT_HAVE_STDINT_H 1
+# else
+#  define KWIML_INT_NO_STDINT_H 1
+# endif
+#elif defined(__WATCOMC__) /* Watcom */
+# define KWIML_INT_NO_STDINT_H 1
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if defined(KWIML_INT_HAVE_INTTYPES_H) /* Already defined. */
+#elif defined(KWIML_INT_NO_INTTYPES_H) /* Already defined. */
+#elif defined(HAVE_INTTYPES_H) /* Optionally provided by includer.  */
+# define KWIML_INT_HAVE_INTTYPES_H 1
+#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
+# define KWIML_INT_HAVE_INTTYPES_H 1
+#elif defined(_MSC_VER) /* MSVC */
+# define KWIML_INT_NO_INTTYPES_H 1
+#elif defined(__BORLANDC__) /* Borland */
+# define KWIML_INT_NO_INTTYPES_H 1
+#elif defined(__WATCOMC__) /* Watcom */
+# define KWIML_INT_NO_INTTYPES_H 1
+#else /* Assume it exists.  */
+# define KWIML_INT_HAVE_INTTYPES_H 1
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if defined(KWIML_INT_HAVE_STDINT_H) && defined(KWIML_INT_NO_STDINT_H)
+# error "Both KWIML_INT_HAVE_STDINT_H and KWIML_INT_NO_STDINT_H defined!"
+#endif
+#if defined(KWIML_INT_HAVE_INTTYPES_H) && defined(KWIML_INT_NO_INTTYPES_H)
+# error "Both KWIML_INT_HAVE_INTTYPES_H and KWIML_INT_NO_INTTYPES_H defined!"
+#endif
+
+#if defined(KWIML_INT_HAVE_STDINT_H)
+# ifndef KWIML_INT_detail_INCLUDED_STDINT_H
+#  define KWIML_INT_detail_INCLUDED_STDINT_H
+#  include <stdint.h>
+# endif
+#endif
+#if defined(KWIML_INT_HAVE_INTTYPES_H)
+# ifndef KWIML_INT_detail_INCLUDED_INTTYPES_H
+#  define KWIML_INT_detail_INCLUDED_INTTYPES_H
+#  if defined(__cplusplus) && !defined(__STDC_FORMAT_MACROS)
+#   define __STDC_FORMAT_MACROS
+#  endif
+#  include <inttypes.h>
+# endif
+#endif
+
+#if defined(KWIML_INT_HAVE_STDINT_H) || defined(KWIML_INT_HAVE_INTTYPES_H)
+#define KWIML_INT_HAVE_INT8_T 1
+#define KWIML_INT_HAVE_UINT8_T 1
+#define KWIML_INT_HAVE_INT16_T 1
+#define KWIML_INT_HAVE_UINT16_T 1
+#define KWIML_INT_HAVE_INT32_T 1
+#define KWIML_INT_HAVE_UINT32_T 1
+#define KWIML_INT_HAVE_INT64_T 1
+#define KWIML_INT_HAVE_UINT64_T 1
+#define KWIML_INT_HAVE_INTPTR_T 1
+#define KWIML_INT_HAVE_UINTPTR_T 1
+# if defined(__cplusplus)
+#  define KWIML_INT_detail_GLOBAL_NS(T) ::T
+# else
+#  define KWIML_INT_detail_GLOBAL_NS(T) T
+# endif
+#endif
+
+#if defined(_AIX43) && !defined(_AIX50) && !defined(_AIX51)
+  /* AIX 4.3 defines these incorrectly with % and no quotes. */
+# define KWIML_INT_BROKEN_PRId8 1
+# define KWIML_INT_BROKEN_SCNd8 1
+# define KWIML_INT_BROKEN_PRIi8 1
+# define KWIML_INT_BROKEN_SCNi8 1
+# define KWIML_INT_BROKEN_PRIo8 1
+# define KWIML_INT_BROKEN_SCNo8 1
+# define KWIML_INT_BROKEN_PRIu8 1
+# define KWIML_INT_BROKEN_SCNu8 1
+# define KWIML_INT_BROKEN_PRIx8 1
+# define KWIML_INT_BROKEN_SCNx8 1
+# define KWIML_INT_BROKEN_PRIX8 1
+# define KWIML_INT_BROKEN_PRId16 1
+# define KWIML_INT_BROKEN_SCNd16 1
+# define KWIML_INT_BROKEN_PRIi16 1
+# define KWIML_INT_BROKEN_SCNi16 1
+# define KWIML_INT_BROKEN_PRIo16 1
+# define KWIML_INT_BROKEN_SCNo16 1
+# define KWIML_INT_BROKEN_PRIu16 1
+# define KWIML_INT_BROKEN_SCNu16 1
+# define KWIML_INT_BROKEN_PRIx16 1
+# define KWIML_INT_BROKEN_SCNx16 1
+# define KWIML_INT_BROKEN_PRIX16 1
+# define KWIML_INT_BROKEN_PRId32 1
+# define KWIML_INT_BROKEN_SCNd32 1
+# define KWIML_INT_BROKEN_PRIi32 1
+# define KWIML_INT_BROKEN_SCNi32 1
+# define KWIML_INT_BROKEN_PRIo32 1
+# define KWIML_INT_BROKEN_SCNo32 1
+# define KWIML_INT_BROKEN_PRIu32 1
+# define KWIML_INT_BROKEN_SCNu32 1
+# define KWIML_INT_BROKEN_PRIx32 1
+# define KWIML_INT_BROKEN_SCNx32 1
+# define KWIML_INT_BROKEN_PRIX32 1
+# define KWIML_INT_BROKEN_PRId64 1
+# define KWIML_INT_BROKEN_SCNd64 1
+# define KWIML_INT_BROKEN_PRIi64 1
+# define KWIML_INT_BROKEN_SCNi64 1
+# define KWIML_INT_BROKEN_PRIo64 1
+# define KWIML_INT_BROKEN_SCNo64 1
+# define KWIML_INT_BROKEN_PRIu64 1
+# define KWIML_INT_BROKEN_SCNu64 1
+# define KWIML_INT_BROKEN_PRIx64 1
+# define KWIML_INT_BROKEN_SCNx64 1
+# define KWIML_INT_BROKEN_PRIX64 1
+# define KWIML_INT_BROKEN_PRIdPTR 1
+# define KWIML_INT_BROKEN_SCNdPTR 1
+# define KWIML_INT_BROKEN_PRIiPTR 1
+# define KWIML_INT_BROKEN_SCNiPTR 1
+# define KWIML_INT_BROKEN_PRIoPTR 1
+# define KWIML_INT_BROKEN_SCNoPTR 1
+# define KWIML_INT_BROKEN_PRIuPTR 1
+# define KWIML_INT_BROKEN_SCNuPTR 1
+# define KWIML_INT_BROKEN_PRIxPTR 1
+# define KWIML_INT_BROKEN_SCNxPTR 1
+# define KWIML_INT_BROKEN_PRIXPTR 1
+#endif
+
+#if (defined(__SUNPRO_C)||defined(__SUNPRO_CC)) && defined(_CHAR_IS_UNSIGNED)
+# define KWIML_INT_BROKEN_INT8_T 1 /* system type defined incorrectly */
+#elif defined(__BORLANDC__) && defined(_CHAR_UNSIGNED)
+# define KWIML_INT_BROKEN_INT8_T 1 /* system type defined incorrectly */
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if !defined(KWIML_INT_int8_t)
+# if defined(KWIML_INT_HAVE_INT8_T) && !defined(KWIML_INT_BROKEN_INT8_T)
+#  define KWIML_INT_int8_t KWIML_INT_detail_GLOBAL_NS(int8_t)
+# else
+#  define KWIML_INT_int8_t signed char
+# endif
+#endif
+#if !defined(KWIML_INT_uint8_t)
+# if defined(KWIML_INT_HAVE_UINT8_T)
+#  define KWIML_INT_uint8_t KWIML_INT_detail_GLOBAL_NS(uint8_t)
+# else
+#  define KWIML_INT_uint8_t unsigned char
+# endif
+#endif
+
+#if defined(__INTEL_COMPILER)
+# if defined(_WIN32)
+#  define KWIML_INT_private_NO_SCN8
+# endif
+#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+# define KWIML_INT_private_NO_SCN8
+#elif defined(__BORLANDC__)
+# define KWIML_INT_private_NO_SCN8
+# define KWIML_INT_private_NO_SCN64
+#elif defined(_MSC_VER)
+# define KWIML_INT_private_NO_SCN8
+#elif defined(__WATCOMC__)
+# define KWIML_INT_private_NO_SCN8
+# elif defined(__hpux) /* HP runtime lacks support (any compiler) */
+# define KWIML_INT_private_NO_SCN8
+#endif
+
+/* 8-bit d, i */
+#if !defined(KWIML_INT_PRId8)
+# if defined(KWIML_INT_HAVE_INT8_T) && defined(PRId8) \
+   && !defined(KWIML_INT_BROKEN_PRId8)
+#  define KWIML_INT_PRId8 PRId8
+# else
+#  define KWIML_INT_PRId8   "d"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNd8)
+# if defined(KWIML_INT_HAVE_INT8_T) && defined(SCNd8) \
+   && !defined(KWIML_INT_BROKEN_SCNd8)
+#  define KWIML_INT_SCNd8 SCNd8
+# elif !defined(KWIML_INT_private_NO_SCN8)
+#  define KWIML_INT_SCNd8 "hhd"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIi8)
+# if defined(KWIML_INT_HAVE_INT8_T) && defined(PRIi8) \
+   && !defined(KWIML_INT_BROKEN_PRIi8)
+#  define KWIML_INT_PRIi8 PRIi8
+# else
+#  define KWIML_INT_PRIi8   "i"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNi8)
+# if defined(KWIML_INT_HAVE_INT8_T) && defined(SCNi8) \
+   && !defined(KWIML_INT_BROKEN_SCNi8)
+#  define KWIML_INT_SCNi8 SCNi8
+# elif !defined(KWIML_INT_private_NO_SCN8)
+#  define KWIML_INT_SCNi8 "hhi"
+# endif
+#endif
+
+/* 8-bit o, u, x, X */
+#if !defined(KWIML_INT_PRIo8)
+# if defined(KWIML_INT_HAVE_UINT8_T) && defined(PRIo8) \
+   && !defined(KWIML_INT_BROKEN_PRIo8)
+#  define KWIML_INT_PRIo8 PRIo8
+# else
+#  define KWIML_INT_PRIo8   "o"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNo8)
+# if defined(KWIML_INT_HAVE_UINT8_T) && defined(SCNo8) \
+   && !defined(KWIML_INT_BROKEN_SCNo8)
+#  define KWIML_INT_SCNo8 SCNo8
+# elif !defined(KWIML_INT_private_NO_SCN8)
+#  define KWIML_INT_SCNo8 "hho"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIu8)
+# if defined(KWIML_INT_HAVE_UINT8_T) && defined(PRIu8) \
+   && !defined(KWIML_INT_BROKEN_PRIu8)
+#  define KWIML_INT_PRIu8 PRIu8
+# else
+#  define KWIML_INT_PRIu8   "u"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNu8)
+# if defined(KWIML_INT_HAVE_UINT8_T) && defined(SCNu8) \
+   && !defined(KWIML_INT_BROKEN_SCNu8)
+#  define KWIML_INT_SCNu8 SCNu8
+# elif !defined(KWIML_INT_private_NO_SCN8)
+#  define KWIML_INT_SCNu8 "hhu"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIx8)
+# if defined(KWIML_INT_HAVE_UINT8_T) && defined(PRIx8) \
+   && !defined(KWIML_INT_BROKEN_PRIx8)
+#  define KWIML_INT_PRIx8 PRIx8
+# else
+#  define KWIML_INT_PRIx8   "x"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNx8)
+# if defined(KWIML_INT_HAVE_UINT8_T) && defined(SCNx8) \
+   && !defined(KWIML_INT_BROKEN_SCNx8)
+#  define KWIML_INT_SCNx8 SCNx8
+# elif !defined(KWIML_INT_private_NO_SCN8)
+#  define KWIML_INT_SCNx8 "hhx"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIX8)
+# if defined(KWIML_INT_HAVE_UINT8_T) && defined(PRIX8) \
+   && !defined(KWIML_INT_BROKEN_PRIX8)
+#  define KWIML_INT_PRIX8 PRIX8
+# else
+#  define KWIML_INT_PRIX8   "X"
+# endif
+#endif
+
+/* 8-bit constants */
+#if !defined(KWIML_INT_INT8_C)
+# if defined(INT8_C) && !defined(KWIML_INT_BROKEN_INT8_C)
+#  define KWIML_INT_INT8_C(c) INT8_C(c)
+# else
+#  define KWIML_INT_INT8_C(c) c
+# endif
+#endif
+#if !defined(KWIML_INT_UINT8_C)
+# if defined(UINT8_C) && !defined(KWIML_INT_BROKEN_UINT8_C)
+#  define KWIML_INT_UINT8_C(c) UINT8_C(c)
+# else
+#  define KWIML_INT_UINT8_C(c) c ## u
+# endif
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if !defined(KWIML_INT_int16_t)
+# if defined(KWIML_INT_HAVE_INT16_T)
+#  define KWIML_INT_int16_t KWIML_INT_detail_GLOBAL_NS(int16_t)
+# else
+#  define KWIML_INT_int16_t signed short
+# endif
+#endif
+#if !defined(KWIML_INT_uint16_t)
+# if defined(KWIML_INT_HAVE_UINT16_T)
+#  define KWIML_INT_uint16_t KWIML_INT_detail_GLOBAL_NS(uint16_t)
+# else
+#  define KWIML_INT_uint16_t unsigned short
+# endif
+#endif
+
+/* 16-bit d, i */
+#if !defined(KWIML_INT_PRId16)
+# if defined(KWIML_INT_HAVE_INT16_T) && defined(PRId16) \
+   && !defined(KWIML_INT_BROKEN_PRId16)
+#  define KWIML_INT_PRId16 PRId16
+# else
+#  define KWIML_INT_PRId16  "d"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNd16)
+# if defined(KWIML_INT_HAVE_INT16_T) && defined(SCNd16) \
+   && !defined(KWIML_INT_BROKEN_SCNd16)
+#  define KWIML_INT_SCNd16 SCNd16
+# else
+#  define KWIML_INT_SCNd16 "hd"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIi16)
+# if defined(KWIML_INT_HAVE_INT16_T) && defined(PRIi16) \
+   && !defined(KWIML_INT_BROKEN_PRIi16)
+#  define KWIML_INT_PRIi16 PRIi16
+# else
+#  define KWIML_INT_PRIi16  "i"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNi16)
+# if defined(KWIML_INT_HAVE_INT16_T) && defined(SCNi16) \
+   && !defined(KWIML_INT_BROKEN_SCNi16)
+#  define KWIML_INT_SCNi16 SCNi16
+# else
+#  define KWIML_INT_SCNi16 "hi"
+# endif
+#endif
+
+/* 16-bit o, u, x, X */
+#if !defined(KWIML_INT_PRIo16)
+# if defined(KWIML_INT_HAVE_UINT16_T) && defined(PRIo16) \
+   && !defined(KWIML_INT_BROKEN_PRIo16)
+#  define KWIML_INT_PRIo16 PRIo16
+# else
+#  define KWIML_INT_PRIo16  "o"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNo16)
+# if defined(KWIML_INT_HAVE_UINT16_T) && defined(SCNo16) \
+   && !defined(KWIML_INT_BROKEN_SCNo16)
+#  define KWIML_INT_SCNo16 SCNo16
+# else
+#  define KWIML_INT_SCNo16 "ho"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIu16)
+# if defined(KWIML_INT_HAVE_UINT16_T) && defined(PRIu16) \
+   && !defined(KWIML_INT_BROKEN_PRIu16)
+#  define KWIML_INT_PRIu16 PRIu16
+# else
+#  define KWIML_INT_PRIu16  "u"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNu16)
+# if defined(KWIML_INT_HAVE_UINT16_T) && defined(SCNu16) \
+   && !defined(KWIML_INT_BROKEN_SCNu16)
+#  define KWIML_INT_SCNu16 SCNu16
+# else
+#  define KWIML_INT_SCNu16 "hu"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIx16)
+# if defined(KWIML_INT_HAVE_UINT16_T) && defined(PRIx16) \
+   && !defined(KWIML_INT_BROKEN_PRIx16)
+#  define KWIML_INT_PRIx16 PRIx16
+# else
+#  define KWIML_INT_PRIx16  "x"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNx16)
+# if defined(KWIML_INT_HAVE_UINT16_T) && defined(SCNx16) \
+   && !defined(KWIML_INT_BROKEN_SCNx16)
+#  define KWIML_INT_SCNx16 SCNx16
+# else
+#  define KWIML_INT_SCNx16 "hx"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIX16)
+# if defined(KWIML_INT_HAVE_UINT16_T) && defined(PRIX16) \
+   && !defined(KWIML_INT_BROKEN_PRIX16)
+#  define KWIML_INT_PRIX16 PRIX16
+# else
+#  define KWIML_INT_PRIX16  "X"
+# endif
+#endif
+
+/* 16-bit constants */
+#if !defined(KWIML_INT_INT16_C)
+# if defined(INT16_C) && !defined(KWIML_INT_BROKEN_INT16_C)
+#  define KWIML_INT_INT16_C(c) INT16_C(c)
+# else
+#  define KWIML_INT_INT16_C(c) c
+# endif
+#endif
+#if !defined(KWIML_INT_UINT16_C)
+# if defined(UINT16_C) && !defined(KWIML_INT_BROKEN_UINT16_C)
+#  define KWIML_INT_UINT16_C(c) UINT16_C(c)
+# else
+#  define KWIML_INT_UINT16_C(c) c ## u
+# endif
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if !defined(KWIML_INT_int32_t)
+# if defined(KWIML_INT_HAVE_INT32_T)
+#  define KWIML_INT_int32_t KWIML_INT_detail_GLOBAL_NS(int32_t)
+# else
+#  define KWIML_INT_int32_t signed int
+# endif
+#endif
+#if !defined(KWIML_INT_uint32_t)
+# if defined(KWIML_INT_HAVE_UINT32_T)
+#  define KWIML_INT_uint32_t KWIML_INT_detail_GLOBAL_NS(uint32_t)
+# else
+#  define KWIML_INT_uint32_t unsigned int
+# endif
+#endif
+
+/* 32-bit d, i */
+#if !defined(KWIML_INT_PRId32)
+# if defined(KWIML_INT_HAVE_INT32_T) && defined(PRId32) \
+   && !defined(KWIML_INT_BROKEN_PRId32)
+#  define KWIML_INT_PRId32 PRId32
+# else
+#  define KWIML_INT_PRId32 "d"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNd32)
+# if defined(KWIML_INT_HAVE_INT32_T) && defined(SCNd32) \
+   && !defined(KWIML_INT_BROKEN_SCNd32)
+#  define KWIML_INT_SCNd32 SCNd32
+# else
+#  define KWIML_INT_SCNd32 "d"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIi32)
+# if defined(KWIML_INT_HAVE_INT32_T) && defined(PRIi32) \
+   && !defined(KWIML_INT_BROKEN_PRIi32)
+#  define KWIML_INT_PRIi32 PRIi32
+# else
+#  define KWIML_INT_PRIi32 "i"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNi32)
+# if defined(KWIML_INT_HAVE_INT32_T) && defined(SCNi32) \
+   && !defined(KWIML_INT_BROKEN_SCNi32)
+#  define KWIML_INT_SCNi32 SCNi32
+# else
+#  define KWIML_INT_SCNi32 "i"
+# endif
+#endif
+
+/* 32-bit o, u, x, X */
+#if !defined(KWIML_INT_PRIo32)
+# if defined(KWIML_INT_HAVE_UINT32_T) && defined(PRIo32) \
+   && !defined(KWIML_INT_BROKEN_PRIo32)
+#  define KWIML_INT_PRIo32 PRIo32
+# else
+#  define KWIML_INT_PRIo32 "o"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNo32)
+# if defined(KWIML_INT_HAVE_UINT32_T) && defined(SCNo32) \
+   && !defined(KWIML_INT_BROKEN_SCNo32)
+#  define KWIML_INT_SCNo32 SCNo32
+# else
+#  define KWIML_INT_SCNo32 "o"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIu32)
+# if defined(KWIML_INT_HAVE_UINT32_T) && defined(PRIu32) \
+   && !defined(KWIML_INT_BROKEN_PRIu32)
+#  define KWIML_INT_PRIu32 PRIu32
+# else
+#  define KWIML_INT_PRIu32 "u"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNu32)
+# if defined(KWIML_INT_HAVE_UINT32_T) && defined(SCNu32) \
+   && !defined(KWIML_INT_BROKEN_SCNu32)
+#  define KWIML_INT_SCNu32 SCNu32
+# else
+#  define KWIML_INT_SCNu32 "u"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIx32)
+# if defined(KWIML_INT_HAVE_UINT32_T) && defined(PRIx32) \
+   && !defined(KWIML_INT_BROKEN_PRIx32)
+#  define KWIML_INT_PRIx32 PRIx32
+# else
+#  define KWIML_INT_PRIx32 "x"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNx32)
+# if defined(KWIML_INT_HAVE_UINT32_T) && defined(SCNx32) \
+   && !defined(KWIML_INT_BROKEN_SCNx32)
+#  define KWIML_INT_SCNx32 SCNx32
+# else
+#  define KWIML_INT_SCNx32 "x"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIX32)
+# if defined(KWIML_INT_HAVE_UINT32_T) && defined(PRIX32) \
+   && !defined(KWIML_INT_BROKEN_PRIX32)
+#  define KWIML_INT_PRIX32 PRIX32
+# else
+#  define KWIML_INT_PRIX32 "X"
+# endif
+#endif
+
+#if defined(__hpux) && defined(__GNUC__) && !defined(__LP64__) \
+ && defined(__CONCAT__) && defined(__CONCAT_U__)
+  /* Some HPs define UINT32_C incorrectly and break GNU.  */
+# define KWIML_INT_BROKEN_UINT32_C 1
+#endif
+
+/* 32-bit constants */
+#if !defined(KWIML_INT_INT32_C)
+# if defined(INT32_C) && !defined(KWIML_INT_BROKEN_INT32_C)
+#  define KWIML_INT_INT32_C(c) INT32_C(c)
+# else
+#  define KWIML_INT_INT32_C(c) c
+# endif
+#endif
+#if !defined(KWIML_INT_UINT32_C)
+# if defined(UINT32_C) && !defined(KWIML_INT_BROKEN_UINT32_C)
+#  define KWIML_INT_UINT32_C(c) UINT32_C(c)
+# else
+#  define KWIML_INT_UINT32_C(c) c ## u
+# endif
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if !defined(KWIML_INT_int64_t) && !defined(KWIML_INT_NO_INT64_T)
+# if defined(KWIML_INT_HAVE_INT64_T)
+#  define KWIML_INT_int64_t KWIML_INT_detail_GLOBAL_NS(int64_t)
+# elif KWIML_ABI_SIZEOF_LONG == 8
+#  define KWIML_INT_int64_t signed long
+# elif defined(KWIML_ABI_SIZEOF_LONG_LONG) && KWIML_ABI_SIZEOF_LONG_LONG == 8
+#  define KWIML_INT_int64_t signed long long
+# elif defined(KWIML_ABI_SIZEOF___INT64)
+#  define KWIML_INT_int64_t signed __int64
+# elif defined(KWIML_INT_NO_ERROR_INT64_T)
+#  define KWIML_INT_NO_INT64_T
+# else
+#  error "No type known for 'int64_t'."
+# endif
+#endif
+#if !defined(KWIML_INT_uint64_t) && !defined(KWIML_INT_NO_UINT64_T)
+# if defined(KWIML_INT_HAVE_UINT64_T)
+#  define KWIML_INT_uint64_t KWIML_INT_detail_GLOBAL_NS(uint64_t)
+# elif KWIML_ABI_SIZEOF_LONG == 8
+#  define KWIML_INT_uint64_t unsigned long
+# elif defined(KWIML_ABI_SIZEOF_LONG_LONG) && KWIML_ABI_SIZEOF_LONG_LONG == 8
+#  define KWIML_INT_uint64_t unsigned long long
+# elif defined(KWIML_ABI_SIZEOF___INT64)
+#  define KWIML_INT_uint64_t unsigned __int64
+# elif defined(KWIML_INT_NO_ERROR_UINT64_T)
+#  define KWIML_INT_NO_UINT64_T
+# else
+#  error "No type known for 'uint64_t'."
+# endif
+#endif
+
+#if defined(__INTEL_COMPILER)
+#elif defined(__BORLANDC__)
+# define KWIML_INT_private_NO_FMTLL /* type 'long long' but not 'll' format */
+# define KWIML_INT_BROKEN_INT64_C 1  /* system macro defined incorrectly */
+# define KWIML_INT_BROKEN_UINT64_C 1 /* system macro defined incorrectly */
+#elif defined(_MSC_VER) && _MSC_VER < 1400
+# define KWIML_INT_private_NO_FMTLL /* type 'long long' but not 'll' format */
+#endif
+
+#if !defined(KWIML_INT_detail_FMT64)
+# if KWIML_ABI_SIZEOF_LONG == 8
+#  define KWIML_INT_detail_FMT64 "l"
+# elif defined(KWIML_ABI_SIZEOF_LONG_LONG) && KWIML_ABI_SIZEOF_LONG_LONG == 8
+#  if !defined(KWIML_INT_private_NO_FMTLL)
+#   define KWIML_INT_detail_FMT64 "ll"
+#  else
+#   define KWIML_INT_detail_FMT64 "I64"
+#  endif
+# elif defined(KWIML_ABI_SIZEOF___INT64)
+#  if defined(__BORLANDC__)
+#   define KWIML_INT_detail_FMT64 "L"
+#  else
+#   define KWIML_INT_detail_FMT64 "I64"
+#  endif
+# endif
+#endif
+
+#undef KWIML_INT_private_NO_FMTLL
+
+/* 64-bit d, i */
+#if !defined(KWIML_INT_PRId64)
+# if defined(KWIML_INT_HAVE_INT64_T) && defined(PRId64) \
+   && !defined(KWIML_INT_BROKEN_PRId64)
+#  define KWIML_INT_PRId64 PRId64
+# elif defined(KWIML_INT_detail_FMT64)
+#  define KWIML_INT_PRId64 KWIML_INT_detail_FMT64 "d"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNd64)
+# if defined(KWIML_INT_HAVE_INT64_T) && defined(SCNd64) \
+   && !defined(KWIML_INT_BROKEN_SCNd64)
+#  define KWIML_INT_SCNd64 SCNd64
+# elif defined(KWIML_INT_detail_FMT64) && !defined(KWIML_INT_private_NO_SCN64)
+#  define KWIML_INT_SCNd64 KWIML_INT_detail_FMT64 "d"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIi64)
+# if defined(KWIML_INT_HAVE_INT64_T) && defined(PRIi64) \
+   && !defined(KWIML_INT_BROKEN_PRIi64)
+#  define KWIML_INT_PRIi64 PRIi64
+# elif defined(KWIML_INT_detail_FMT64)
+#  define KWIML_INT_PRIi64 KWIML_INT_detail_FMT64 "d"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNi64)
+# if defined(KWIML_INT_HAVE_INT64_T) && defined(SCNi64) \
+   && !defined(KWIML_INT_BROKEN_SCNi64)
+#  define KWIML_INT_SCNi64 SCNi64
+# elif defined(KWIML_INT_detail_FMT64) && !defined(KWIML_INT_private_NO_SCN64)
+#  define KWIML_INT_SCNi64 KWIML_INT_detail_FMT64 "d"
+# endif
+#endif
+
+/* 64-bit o, u, x, X */
+#if !defined(KWIML_INT_PRIo64)
+# if defined(KWIML_INT_HAVE_UINT64_T) && defined(PRIo64) \
+   && !defined(KWIML_INT_BROKEN_PRIo64)
+#  define KWIML_INT_PRIo64 PRIo64
+# elif defined(KWIML_INT_detail_FMT64)
+#  define KWIML_INT_PRIo64 KWIML_INT_detail_FMT64 "o"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNo64)
+# if defined(KWIML_INT_HAVE_UINT64_T) && defined(SCNo64) \
+   && !defined(KWIML_INT_BROKEN_SCNo64)
+#  define KWIML_INT_SCNo64 SCNo64
+# elif defined(KWIML_INT_detail_FMT64) && !defined(KWIML_INT_private_NO_SCN64)
+#  define KWIML_INT_SCNo64 KWIML_INT_detail_FMT64 "o"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIu64)
+# if defined(KWIML_INT_HAVE_UINT64_T) && defined(PRIu64) \
+   && !defined(KWIML_INT_BROKEN_PRIu64)
+#  define KWIML_INT_PRIu64 PRIu64
+# elif defined(KWIML_INT_detail_FMT64)
+#  define KWIML_INT_PRIu64 KWIML_INT_detail_FMT64 "u"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNu64)
+# if defined(KWIML_INT_HAVE_UINT64_T) && defined(SCNu64) \
+   && !defined(KWIML_INT_BROKEN_SCNu64)
+#  define KWIML_INT_SCNu64 SCNu64
+# elif defined(KWIML_INT_detail_FMT64) && !defined(KWIML_INT_private_NO_SCN64)
+#  define KWIML_INT_SCNu64 KWIML_INT_detail_FMT64 "u"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIx64)
+# if defined(KWIML_INT_HAVE_UINT64_T) && defined(PRIx64) \
+   && !defined(KWIML_INT_BROKEN_PRIx64)
+#  define KWIML_INT_PRIx64 PRIx64
+# elif defined(KWIML_INT_detail_FMT64)
+#  define KWIML_INT_PRIx64 KWIML_INT_detail_FMT64 "x"
+# endif
+#endif
+#if !defined(KWIML_INT_SCNx64)
+# if defined(KWIML_INT_HAVE_UINT64_T) && defined(SCNx64) \
+   && !defined(KWIML_INT_BROKEN_SCNx64)
+#  define KWIML_INT_SCNx64 SCNx64
+# elif defined(KWIML_INT_detail_FMT64) && !defined(KWIML_INT_private_NO_SCN64)
+#  define KWIML_INT_SCNx64 KWIML_INT_detail_FMT64 "x"
+# endif
+#endif
+#if !defined(KWIML_INT_PRIX64)
+# if defined(KWIML_INT_HAVE_UINT64_T) && defined(PRIX64) \
+   && !defined(KWIML_INT_BROKEN_PRIX64)
+#  define KWIML_INT_PRIX64 PRIX64
+# elif defined(KWIML_INT_detail_FMT64)
+#  define KWIML_INT_PRIX64 KWIML_INT_detail_FMT64 "X"
+# endif
+#endif
+
+/* 64-bit constants */
+#if !defined(KWIML_INT_INT64_C)
+# if defined(KWIML_INT_HAVE_INT64_T) && defined(INT64_C) \
+   && !defined(KWIML_INT_BROKEN_INT64_C)
+#  define KWIML_INT_INT64_C(c) INT64_C(c)
+# elif KWIML_ABI_SIZEOF_LONG == 8
+#  define KWIML_INT_INT64_C(c) c ## l
+# elif defined(KWIML_ABI_SIZEOF_LONG_LONG) && KWIML_ABI_SIZEOF_LONG_LONG == 8
+#  define KWIML_INT_INT64_C(c) c ## ll
+# elif defined(KWIML_ABI_SIZEOF___INT64)
+#  define KWIML_INT_INT64_C(c) c ## i64
+# endif
+#endif
+#if !defined(KWIML_INT_UINT64_C)
+# if defined(KWIML_INT_HAVE_UINT64_T) && defined(UINT64_C) \
+   && !defined(KWIML_INT_BROKEN_UINT64_C)
+#  define KWIML_INT_UINT64_C(c) UINT64_C(c)
+# elif KWIML_ABI_SIZEOF_LONG == 8
+#  define KWIML_INT_UINT64_C(c) c ## ul
+# elif defined(KWIML_ABI_SIZEOF_LONG_LONG) && KWIML_ABI_SIZEOF_LONG_LONG == 8
+#  define KWIML_INT_UINT64_C(c) c ## ull
+# elif defined(KWIML_ABI_SIZEOF___INT64)
+#  define KWIML_INT_UINT64_C(c) c ## ui64
+# endif
+#endif
+
+/*--------------------------------------------------------------------------*/
+#if !defined(KWIML_INT_intptr_t) && !defined(KWIML_INT_NO_INTPTR_T)
+# if defined(KWIML_INT_HAVE_INTPTR_T)
+#  define KWIML_INT_intptr_t KWIML_INT_detail_GLOBAL_NS(intptr_t)
+# elif KWIML_ABI_SIZEOF_DATA_PTR == 4
+#  define KWIML_INT_intptr_t KWIML_INT_int32_t
+# elif !defined(KWIML_INT_NO_INT64_T)
+#  define KWIML_INT_intptr_t KWIML_INT_int64_t
+# elif defined(KWIML_INT_NO_ERROR_INTPTR_T)
+#  define KWIML_INT_NO_INTPTR_T
+# else
+#  error "No type known for 'intptr_t'."
+# endif
+#endif
+#if !defined(KWIML_INT_uintptr_t) && !defined(KWIML_INT_NO_UINTPTR_T)
+# if defined(KWIML_INT_HAVE_UINTPTR_T)
+#  define KWIML_INT_uintptr_t KWIML_INT_detail_GLOBAL_NS(uintptr_t)
+# elif KWIML_ABI_SIZEOF_DATA_PTR == 4
+#  define KWIML_INT_uintptr_t KWIML_INT_uint32_t
+# elif !defined(KWIML_INT_NO_UINT64_T)
+#  define KWIML_INT_uintptr_t KWIML_INT_uint64_t
+# elif defined(KWIML_INT_NO_ERROR_UINTPTR_T)
+#  define KWIML_INT_NO_UINTPTR_T
+# else
+#  error "No type known for 'uintptr_t'."
+# endif
+#endif
+
+#if !defined(KWIML_INT_PRIdPTR)
+# if defined(KWIML_INT_HAVE_INTPTR_T) && defined(PRIdPTR) \
+   && !defined(KWIML_INT_BROKEN_PRIdPTR)
+#  define KWIML_INT_PRIdPTR PRIdPTR
+# elif KWIML_ABI_SIZEOF_DATA_PTR == 4
+#  define KWIML_INT_PRIdPTR KWIML_INT_PRId32
+# elif !defined(KWIML_INT_NO_UINT64_T)
+#  define KWIML_INT_PRIdPTR KWIML_INT_PRId64
+# endif
+#endif
+#if !defined(KWIML_INT_SCNdPTR)
+# if defined(KWIML_INT_HAVE_INTPTR_T) && defined(SCNdPTR) \
+   && !defined(KWIML_INT_BROKEN_SCNdPTR)
+#  define KWIML_INT_SCNdPTR SCNdPTR
+# elif KWIML_ABI_SIZEOF_DATA_PTR == 4
+#  define KWIML_INT_SCNdPTR KWIML_INT_SCNd32
+# elif !defined(KWIML_INT_NO_UINT64_T)
+#  define KWIML_INT_SCNdPTR KWIML_INT_SCNd64
+# endif
+#endif
+#if !defined(KWIML_INT_PRIiPTR)
+# if defined(KWIML_INT_HAVE_INTPTR_T) && defined(PRIiPTR) \
+   && !defined(KWIML_INT_BROKEN_PRIiPTR)
+#  define KWIML_INT_PRIiPTR PRIiPTR
+# elif KWIML_ABI_SIZEOF_DATA_PTR == 4
+#  define KWIML_INT_PRIiPTR KWIML_INT_PRIi32
+# elif !defined(KWIML_INT_NO_UINT64_T)
+#  define KWIML_INT_PRIiPTR KWIML_INT_PRIi64
+# endif
+#endif
+#if !defined(KWIML_INT_SCNiPTR)
+# if defined(KWIML_INT_HAVE_INTPTR_T) && defined(SCNiPTR) \
+   && !defined(KWIML_INT_BROKEN_SCNiPTR)
+#  define KWIML_INT_SCNiPTR SCNiPTR
+# elif KWIML_ABI_SIZEOF_DATA_PTR == 4
+#  define KWIML_INT_SCNiPTR KWIML_INT_SCNi32
+# elif !defined(KWIML_INT_NO_UINT64_T)
+#  define KWIML_INT_SCNiPTR KWIML_INT_SCNi64
+# endif
+#endif
+
+#if !defined(KWIML_INT_PRIoPTR)
+# if defined(KWIML_INT_HAVE_UINTPTR_T) && defined(PRIoPTR) \
+   && !defined(KWIML_INT_BROKEN_PRIoPTR)
+#  define KWIML_INT_PRIoPTR PRIoPTR
+# elif KWIML_ABI_SIZEOF_DATA_PTR == 4
+#  define KWIML_INT_PRIoPTR KWIML_INT_PRIo32
+# elif !defined(KWIML_INT_NO_UINT64_T)
+#  define KWIML_INT_PRIoPTR KWIML_INT_PRIo64
+# endif
+#endif
+#if !defined(KWIML_INT_SCNoPTR)
+# if defined(KWIML_INT_HAVE_UINTPTR_T) && defined(SCNoPTR) \
+   && !defined(KWIML_INT_BROKEN_SCNoPTR)
+#  define KWIML_INT_SCNoPTR SCNoPTR
+# elif KWIML_ABI_SIZEOF_DATA_PTR == 4
+#  define KWIML_INT_SCNoPTR KWIML_INT_SCNo32
+# elif !defined(KWIML_INT_NO_UINT64_T)
+#  define KWIML_INT_SCNoPTR KWIML_INT_SCNo64
+# endif
+#endif
+#if !defined(KWIML_INT_PRIuPTR)
+# if defined(KWIML_INT_HAVE_UINTPTR_T) && defined(PRIuPTR) \
+   && !defined(KWIML_INT_BROKEN_PRIuPTR)
+#  define KWIML_INT_PRIuPTR PRIuPTR
+# elif KWIML_ABI_SIZEOF_DATA_PTR == 4
+#  define KWIML_INT_PRIuPTR KWIML_INT_PRIu32
+# elif !defined(KWIML_INT_NO_UINT64_T)
+#  define KWIML_INT_PRIuPTR KWIML_INT_PRIu64
+# endif
+#endif
+#if !defined(KWIML_INT_SCNuPTR)
+# if defined(KWIML_INT_HAVE_UINTPTR_T) && defined(SCNuPTR) \
+   && !defined(KWIML_INT_BROKEN_SCNuPTR)
+#  define KWIML_INT_SCNuPTR SCNuPTR
+# elif KWIML_ABI_SIZEOF_DATA_PTR == 4
+#  define KWIML_INT_SCNuPTR KWIML_INT_SCNu32
+# elif !defined(KWIML_INT_NO_UINT64_T)
+#  define KWIML_INT_SCNuPTR KWIML_INT_SCNu64
+# endif
+#endif
+#if !defined(KWIML_INT_PRIxPTR)
+# if defined(KWIML_INT_HAVE_UINTPTR_T) && defined(PRIxPTR) \
+   && !defined(KWIML_INT_BROKEN_PRIxPTR)
+#  define KWIML_INT_PRIxPTR PRIxPTR
+# elif KWIML_ABI_SIZEOF_DATA_PTR == 4
+#  define KWIML_INT_PRIxPTR KWIML_INT_PRIx32
+# elif !defined(KWIML_INT_NO_UINT64_T)
+#  define KWIML_INT_PRIxPTR KWIML_INT_PRIx64
+# endif
+#endif
+#if !defined(KWIML_INT_SCNxPTR)
+# if defined(KWIML_INT_HAVE_UINTPTR_T) && defined(SCNxPTR) \
+   && !defined(KWIML_INT_BROKEN_SCNxPTR)
+#  define KWIML_INT_SCNxPTR SCNxPTR
+# elif KWIML_ABI_SIZEOF_DATA_PTR == 4
+#  define KWIML_INT_SCNxPTR KWIML_INT_SCNx32
+# elif !defined(KWIML_INT_NO_UINT64_T)
+#  define KWIML_INT_SCNxPTR KWIML_INT_SCNx64
+# endif
+#endif
+#if !defined(KWIML_INT_PRIXPTR)
+# if defined(KWIML_INT_HAVE_UINTPTR_T) && defined(PRIXPTR) \
+   && !defined(KWIML_INT_BROKEN_PRIXPTR)
+#  define KWIML_INT_PRIXPTR PRIXPTR
+# elif KWIML_ABI_SIZEOF_DATA_PTR == 4
+#  define KWIML_INT_PRIXPTR KWIML_INT_PRIX32
+# elif !defined(KWIML_INT_NO_UINT64_T)
+#  define KWIML_INT_PRIXPTR KWIML_INT_PRIX64
+# endif
+#endif
+
+#undef KWIML_INT_private_NO_SCN64
+#undef KWIML_INT_private_NO_SCN8
+
+#endif /* KWIML_INT_private_DO_DEFINE */
+
+/*--------------------------------------------------------------------------*/
+#ifdef KWIML_INT_private_DO_VERIFY
+#undef KWIML_INT_private_DO_VERIFY
+
+#if defined(_MSC_VER)
+# pragma warning (push)
+# pragma warning (disable:4310) /* cast truncates constant value */
+#endif
+
+#define KWIML_INT_private_VERIFY(n, x, y) KWIML_INT_private_VERIFY_0(KWIML_INT_private_VERSION, n, x, y)
+#define KWIML_INT_private_VERIFY_0(V, n, x, y) KWIML_INT_private_VERIFY_1(V, n, x, y)
+#define KWIML_INT_private_VERIFY_1(V, n, x, y) extern int (*n##_v##V)[x]; extern int (*n##_v##V)[y]
+
+#define KWIML_INT_private_VERIFY_BOOL(m, b) KWIML_INT_private_VERIFY(KWIML_INT_detail_VERIFY_##m, 2, (b)?2:3)
+#define KWIML_INT_private_VERIFY_TYPE(t, s) KWIML_INT_private_VERIFY(KWIML_INT_detail_VERIFY_##t, s, sizeof(t))
+#define KWIML_INT_private_VERIFY_SIGN(t, u, o) KWIML_INT_private_VERIFY_BOOL(SIGN_##t, (t)((u)1 << ((sizeof(t)<<3)-1)) o 0)
+
+KWIML_INT_private_VERIFY_TYPE(KWIML_INT_int8_t,    1);
+KWIML_INT_private_VERIFY_TYPE(KWIML_INT_uint8_t,   1);
+KWIML_INT_private_VERIFY_TYPE(KWIML_INT_int16_t,   2);
+KWIML_INT_private_VERIFY_TYPE(KWIML_INT_uint16_t,  2);
+KWIML_INT_private_VERIFY_TYPE(KWIML_INT_int32_t,   4);
+KWIML_INT_private_VERIFY_TYPE(KWIML_INT_uint32_t,  4);
+#if !defined(KWIML_INT_NO_INT64_T)
+KWIML_INT_private_VERIFY_TYPE(KWIML_INT_int64_t,   8);
+#endif
+#if !defined(KWIML_INT_NO_UINT64_T)
+KWIML_INT_private_VERIFY_TYPE(KWIML_INT_uint64_t,  8);
+#endif
+#if !defined(KWIML_INT_NO_INTPTR_T)
+KWIML_INT_private_VERIFY_TYPE(KWIML_INT_intptr_t,  sizeof(void*));
+#endif
+#if !defined(KWIML_INT_NO_UINTPTR_T)
+KWIML_INT_private_VERIFY_TYPE(KWIML_INT_uintptr_t, sizeof(void*));
+#endif
+
+KWIML_INT_private_VERIFY_SIGN(KWIML_INT_int8_t,    KWIML_INT_uint8_t,   <);
+KWIML_INT_private_VERIFY_SIGN(KWIML_INT_uint8_t,   KWIML_INT_uint8_t,   >);
+KWIML_INT_private_VERIFY_SIGN(KWIML_INT_int16_t,   KWIML_INT_uint16_t,  <);
+KWIML_INT_private_VERIFY_SIGN(KWIML_INT_uint16_t,  KWIML_INT_uint16_t,  >);
+KWIML_INT_private_VERIFY_SIGN(KWIML_INT_int32_t,   KWIML_INT_uint32_t,  <);
+KWIML_INT_private_VERIFY_SIGN(KWIML_INT_uint32_t,  KWIML_INT_uint32_t,  >);
+#if !defined(KWIML_INT_NO_INT64_T)
+KWIML_INT_private_VERIFY_SIGN(KWIML_INT_int64_t,   KWIML_INT_uint64_t,  <);
+#endif
+#if !defined(KWIML_INT_NO_UINT64_T)
+KWIML_INT_private_VERIFY_SIGN(KWIML_INT_uint64_t,  KWIML_INT_uint64_t,  >);
+#endif
+#if !defined(KWIML_INT_NO_INTPTR_T)
+KWIML_INT_private_VERIFY_SIGN(KWIML_INT_intptr_t,  KWIML_INT_uintptr_t, <);
+#endif
+#if !defined(KWIML_INT_NO_UINTPTR_T)
+KWIML_INT_private_VERIFY_SIGN(KWIML_INT_uintptr_t, KWIML_INT_uintptr_t, >);
+#endif
+
+#undef KWIML_INT_private_VERIFY_SIGN
+#undef KWIML_INT_private_VERIFY_TYPE
+#undef KWIML_INT_private_VERIFY_BOOL
+
+#undef KWIML_INT_private_VERIFY_1
+#undef KWIML_INT_private_VERIFY_0
+#undef KWIML_INT_private_VERIFY
+
+#if defined(_MSC_VER)
+# pragma warning (pop)
+#endif
+
+#endif /* KWIML_INT_private_DO_VERIFY  */
+
+#undef KWIML_INT_private_VERSION
diff --git a/Utilities/KWIML/src/kwiml-config.cmake.in b/Utilities/KWIML/src/kwiml-config.cmake.in
new file mode 100644
index 0000000..124f0fc
--- /dev/null
+++ b/Utilities/KWIML/src/kwiml-config.cmake.in
@@ -0,0 +1 @@
+include(${CMAKE_CURRENT_LIST_DIR}/kwiml-targets.cmake)
diff --git a/Utilities/KWIML/src/version.h.in b/Utilities/KWIML/src/version.h.in
new file mode 100644
index 0000000..e58e0dc
--- /dev/null
+++ b/Utilities/KWIML/src/version.h.in
@@ -0,0 +1,59 @@
+/*============================================================================
+  Kitware Information Macro Library
+  Copyright 2010-2015 Kitware, Inc.
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  * Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+
+  * Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+
+  * Neither the name of Kitware, Inc. nor the names of its contributors
+    may be used to endorse or promote products derived from this
+    software without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+============================================================================*/
+#ifndef KWIML_VERSION_H
+#define KWIML_VERSION_H
+/*
+This header defines macros with information about this version of KWIML.
+
+An includer may test the following macros after inclusion:
+
+  KWIML_VERSION = KWIML version number encoded in an integer as
+                  `printf("%d%03d%03d", MAJOR, MINOR, PATCH)`.
+                  MAJOR is incremented on incompatible changes.
+                  MINOR is incremented on interface additions.
+                  PATCH is incremented on implementation updates.
+
+  KWIML_VERSION_STRING = KWIML version number in string formatted as
+                         `printf("%d.%d.%d", MAJOR, MINOR PATCH)`.
+
+  KWIML_VERSION_HAS_ABI_H = header 'kwiml/abi.h' is available
+  KWIML_VERSION_HAS_INT_H = header 'kwiml/int.h' is available
+*/
+
+#define KWIML_VERSION @KWIML_VERSION_DECIMAL@
+#define KWIML_VERSION_STRING "@KWIML_VERSION@"
+
+#define KWIML_VERSION_HAS_ABI_H 1
+#define KWIML_VERSION_HAS_INT_H 1
+
+#endif
diff --git a/Utilities/KWIML/test/CMakeLists.txt b/Utilities/KWIML/test/CMakeLists.txt
index a16b5cd..4f6f37b 100644
--- a/Utilities/KWIML/test/CMakeLists.txt
+++ b/Utilities/KWIML/test/CMakeLists.txt
@@ -1,22 +1,11 @@
-#=============================================================================
-# Kitware Information Macro Library
-# Copyright 2010-2011 Kitware, Inc.
 #
-# Distributed under the OSI-approved BSD License (the "License");
-# see accompanying file Copyright.txt for details.
+# Copyright Kitware, Inc.
+# Distributed under the OSI-approved BSD 3-Clause License.
+# See accompanying file Copyright.txt for details.
 #
-# This software is distributed WITHOUT ANY WARRANTY; without even the
-# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the License for more information.
-#=============================================================================
-
-set(test_defs KWIML_NAMESPACE=${KWIML})
-
-# Tell CMake how to follow dependencies of sources in this directory.
-set_property(DIRECTORY
-  PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM
-  "KWIML_HEADER(%)=<${KWIML}/%>"
-  )
+if(NOT KWIML_TEST_PREFIX)
+  set(KWIML_TEST_PREFIX kwiml)
+endif()
 
 # Suppress printf/scanf format warnings; we test if the sizes match.
 foreach(lang C CXX)
@@ -33,38 +22,33 @@ endif()
 if(KWIML_LANGUAGE_C)
   list(APPEND test_defs KWIML_LANGUAGE_C)
   list(APPEND test_srcs
-    test_ABI_C.c
-    test_INT_C.c
+    test_abi_C.c
+    test_int_C.c
     test_include_C.c
     )
 endif()
 if(KWIML_LANGUAGE_CXX)
   list(APPEND test_defs KWIML_LANGUAGE_CXX)
   list(APPEND test_srcs
-    test_ABI_CXX.cxx
-    test_INT_CXX.cxx
+    test_abi_CXX.cxx
+    test_int_CXX.cxx
     test_include_CXX.cxx
     )
 endif()
 
-foreach(th test_ABI_endian test_INT_format)
-  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${th}.h.in
-                 ${CMAKE_CURRENT_BINARY_DIR}/${th}.h @ONLY)
-endforeach()
-include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
-add_executable(${KWIML}_test ${test_srcs})
-set_property(TARGET ${KWIML}_test PROPERTY COMPILE_DEFINITIONS ${test_defs})
-set_property(TARGET ${KWIML}_test PROPERTY
+add_executable(kwiml_test ${test_srcs})
+set_property(TARGET kwiml_test PROPERTY COMPILE_DEFINITIONS ${test_defs})
+set_property(TARGET kwiml_test PROPERTY
   RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
-add_test(${KWIML}.test ${CMAKE_CURRENT_BINARY_DIR}/${KWIML}_test)
-set_property(TEST ${KWIML}.test PROPERTY LABELS ${KWIML_LABELS_TEST})
+add_test(NAME ${KWIML_TEST_PREFIX}.test COMMAND kwiml_test)
+set_property(TEST ${KWIML_TEST_PREFIX}.test PROPERTY LABELS ${KWIML_TEST_LABELS})
 
 # Xcode 2.x forgets to create the output directory before linking
 # the individual architectures.
 if(CMAKE_OSX_ARCHITECTURES AND XCODE
     AND NOT "${XCODE_VERSION}" MATCHES "^[^12]")
   add_custom_command(
-    TARGET ${KWIML}_test
+    TARGET kwiml_test
     PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CFG_INTDIR}"
     )
 endif()
diff --git a/Utilities/KWIML/test/test.c b/Utilities/KWIML/test/test.c
index 131c81f..5f5b5d7 100644
--- a/Utilities/KWIML/test/test.c
+++ b/Utilities/KWIML/test/test.c
@@ -1,21 +1,15 @@
-/*============================================================================
-  Kitware Information Macro Library
-  Copyright 2010-2011 Kitware, Inc.
-
-  Distributed under the OSI-approved BSD License (the "License");
-  see accompanying file Copyright.txt for details.
-
-  This software is distributed WITHOUT ANY WARRANTY; without even the
-  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-  See the License for more information.
-============================================================================*/
+/*
+  Copyright Kitware, Inc.
+  Distributed under the OSI-approved BSD 3-Clause License.
+  See accompanying file Copyright.txt for details.
+*/
 #ifdef __cplusplus
 extern "C" {
 #endif
-extern int test_ABI_C(void);
-extern int test_INT_C(void);
-extern int test_ABI_CXX(void);
-extern int test_INT_CXX(void);
+extern int test_abi_C(void);
+extern int test_int_C(void);
+extern int test_abi_CXX(void);
+extern int test_int_CXX(void);
 extern int test_include_C(void);
 extern int test_include_CXX(void);
 #ifdef __cplusplus
@@ -26,13 +20,13 @@ int main(void)
 {
   int result = 1;
 #ifdef KWIML_LANGUAGE_C
-  result = test_ABI_C() && result;
-  result = test_INT_C() && result;
+  result = test_abi_C() && result;
+  result = test_int_C() && result;
   result = test_include_C() && result;
 #endif
 #ifdef KWIML_LANGUAGE_CXX
-  result = test_ABI_CXX() && result;
-  result = test_INT_CXX() && result;
+  result = test_abi_CXX() && result;
+  result = test_int_CXX() && result;
   result = test_include_CXX() && result;
 #endif
   return result? 0 : 1;
diff --git a/Utilities/KWIML/test/test.cxx b/Utilities/KWIML/test/test.cxx
index bf61421..464325b 100644
--- a/Utilities/KWIML/test/test.cxx
+++ b/Utilities/KWIML/test/test.cxx
@@ -1,12 +1,6 @@
-/*============================================================================
-  Kitware Information Macro Library
-  Copyright 2010-2011 Kitware, Inc.
-
-  Distributed under the OSI-approved BSD License (the "License");
-  see accompanying file Copyright.txt for details.
-
-  This software is distributed WITHOUT ANY WARRANTY; without even the
-  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-  See the License for more information.
-============================================================================*/
+/*
+  Copyright Kitware, Inc.
+  Distributed under the OSI-approved BSD 3-Clause License.
+  See accompanying file Copyright.txt for details.
+*/
 #include "test.c"
diff --git a/Utilities/KWIML/test/test.h b/Utilities/KWIML/test/test.h
index b87a0e7..44add3f 100644
--- a/Utilities/KWIML/test/test.h
+++ b/Utilities/KWIML/test/test.h
@@ -1,31 +1,10 @@
-/*============================================================================
-  Kitware Information Macro Library
-  Copyright 2010-2011 Kitware, Inc.
-
-  Distributed under the OSI-approved BSD License (the "License");
-  see accompanying file Copyright.txt for details.
-
-  This software is distributed WITHOUT ANY WARRANTY; without even the
-  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-  See the License for more information.
-============================================================================*/
-#ifndef KWIML_NAMESPACE
-# error "Do not include test.h outside of KWIML test files."
-#endif
-
-#ifndef KWIML_TEST_H
-#define KWIML_TEST_H
-
 /*
-  Define KWIML_HEADER macro to help the test files include kwiml
-  headers from the configured namespace directory.  The macro can be
-  used like this:
-
-  #include KWIML_HEADER(ABI.h)
+  Copyright Kitware, Inc.
+  Distributed under the OSI-approved BSD 3-Clause License.
+  See accompanying file Copyright.txt for details.
 */
-#define KWIML_HEADER(x) KWIML_HEADER0(KWIML_NAMESPACE/x)
-#define KWIML_HEADER0(x) KWIML_HEADER1(x)
-#define KWIML_HEADER1(x) <x>
+#ifndef KWIML_TEST_H
+#define KWIML_TEST_H
 
 /* Quiet MS standard library deprecation warnings.  */
 #ifndef _CRT_SECURE_NO_DEPRECATE
diff --git a/Utilities/KWIML/test/test_ABI_C.c b/Utilities/KWIML/test/test_ABI_C.c
deleted file mode 100644
index 3ca4ad3..0000000
--- a/Utilities/KWIML/test/test_ABI_C.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/*============================================================================
-  Kitware Information Macro Library
-  Copyright 2010-2011 Kitware, Inc.
-
-  Distributed under the OSI-approved BSD License (the "License");
-  see accompanying file Copyright.txt for details.
-
-  This software is distributed WITHOUT ANY WARRANTY; without even the
-  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-  See the License for more information.
-============================================================================*/
-#include "test.h"
-#include KWIML_HEADER(ABI.h)
-#include "test_ABI_endian.h"
-int test_ABI_C(void)
-{
-  if(!test_ABI_endian())
-    {
-    return 0;
-    }
-  return 1;
-}
diff --git a/Utilities/KWIML/test/test_ABI_CXX.cxx b/Utilities/KWIML/test/test_ABI_CXX.cxx
deleted file mode 100644
index 7ede20e..0000000
--- a/Utilities/KWIML/test/test_ABI_CXX.cxx
+++ /dev/null
@@ -1,22 +0,0 @@
-/*============================================================================
-  Kitware Information Macro Library
-  Copyright 2010-2011 Kitware, Inc.
-
-  Distributed under the OSI-approved BSD License (the "License");
-  see accompanying file Copyright.txt for details.
-
-  This software is distributed WITHOUT ANY WARRANTY; without even the
-  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-  See the License for more information.
-============================================================================*/
-#include "test.h"
-#include KWIML_HEADER(ABI.h)
-#include "test_ABI_endian.h"
-extern "C" int test_ABI_CXX(void)
-{
-  if(!test_ABI_endian())
-    {
-    return 0;
-    }
-  return 1;
-}
diff --git a/Utilities/KWIML/test/test_ABI_endian.h.in b/Utilities/KWIML/test/test_ABI_endian.h.in
deleted file mode 100644
index 992baea..0000000
--- a/Utilities/KWIML/test/test_ABI_endian.h.in
+++ /dev/null
@@ -1,47 +0,0 @@
-/*============================================================================
-  Kitware Information Macro Library
-  Copyright 2010-2011 Kitware, Inc.
-
-  Distributed under the OSI-approved BSD License (the "License");
-  see accompanying file Copyright.txt for details.
-
-  This software is distributed WITHOUT ANY WARRANTY; without even the
-  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-  See the License for more information.
-============================================================================*/
-#include <stdio.h>
-
-#ifdef __cplusplus
-# define LANG "C++ "
-#else
-# define LANG "C "
-#endif
-
-static int test_ABI_endian(void)
-{
-  int result = 1;
-  {
-#if defined(@KWIML at _ABI_ENDIAN_ID)
-  int expect;
-  union { short s; unsigned char c[sizeof(short)]; } x;
-  x.s = 1;
-  expect = (x.c[0] == 1 ?
-            @KWIML at _ABI_ENDIAN_ID_LITTLE : @KWIML at _ABI_ENDIAN_ID_BIG);
-  printf(LANG "@KWIML at _ABI_ENDIAN_ID: expected [%d], got [%d]",
-         expect, @KWIML at _ABI_ENDIAN_ID);
-  if(@KWIML at _ABI_ENDIAN_ID == expect)
-    {
-    printf(", PASSED\n");
-    }
-  else
-    {
-    printf(", FAILED\n");
-    result = 0;
-    }
-#else
-  printf(LANG "@KWIML at _ABI_ENDIAN_ID: unknown, FAILED\n");
-  result = 0;
-#endif
-  }
-  return result;
-}
diff --git a/Utilities/KWIML/test/test_INT_CXX.cxx b/Utilities/KWIML/test/test_INT_CXX.cxx
deleted file mode 100644
index 9f74e96..0000000
--- a/Utilities/KWIML/test/test_INT_CXX.cxx
+++ /dev/null
@@ -1,22 +0,0 @@
-/*============================================================================
-  Kitware Information Macro Library
-  Copyright 2010-2011 Kitware, Inc.
-
-  Distributed under the OSI-approved BSD License (the "License");
-  see accompanying file Copyright.txt for details.
-
-  This software is distributed WITHOUT ANY WARRANTY; without even the
-  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-  See the License for more information.
-============================================================================*/
-#include "test.h"
-#include KWIML_HEADER(INT.h)
-#include "test_INT_format.h"
-extern "C" int test_INT_CXX(void)
-{
-  if(!test_INT_format())
-    {
-    return 0;
-    }
-  return 1;
-}
diff --git a/Utilities/KWIML/test/test_abi_C.c b/Utilities/KWIML/test/test_abi_C.c
new file mode 100644
index 0000000..18b639f
--- /dev/null
+++ b/Utilities/KWIML/test/test_abi_C.c
@@ -0,0 +1,19 @@
+/*
+  Copyright Kitware, Inc.
+  Distributed under the OSI-approved BSD 3-Clause License.
+  See accompanying file Copyright.txt for details.
+*/
+#include "test.h"
+#include "../include/kwiml/abi.h"
+#include "test_abi_endian.h"
+#ifndef KWIML_ABI_VERSION
+# error "KWIML_ABI_VERSION not defined!"
+#endif
+int test_abi_C(void)
+{
+  if(!test_abi_endian())
+    {
+    return 0;
+    }
+  return 1;
+}
diff --git a/Utilities/KWIML/test/test_abi_CXX.cxx b/Utilities/KWIML/test/test_abi_CXX.cxx
new file mode 100644
index 0000000..e8feb44
--- /dev/null
+++ b/Utilities/KWIML/test/test_abi_CXX.cxx
@@ -0,0 +1,19 @@
+/*
+  Copyright Kitware, Inc.
+  Distributed under the OSI-approved BSD 3-Clause License.
+  See accompanying file Copyright.txt for details.
+*/
+#include "test.h"
+#include "../include/kwiml/abi.h"
+#include "test_abi_endian.h"
+#ifndef KWIML_ABI_VERSION
+# error "KWIML_ABI_VERSION not defined!"
+#endif
+extern "C" int test_abi_CXX(void)
+{
+  if(!test_abi_endian())
+    {
+    return 0;
+    }
+  return 1;
+}
diff --git a/Utilities/KWIML/test/test_abi_endian.h b/Utilities/KWIML/test/test_abi_endian.h
new file mode 100644
index 0000000..334b018
--- /dev/null
+++ b/Utilities/KWIML/test/test_abi_endian.h
@@ -0,0 +1,41 @@
+/*
+  Copyright Kitware, Inc.
+  Distributed under the OSI-approved BSD 3-Clause License.
+  See accompanying file Copyright.txt for details.
+*/
+#include <stdio.h>
+
+#ifdef __cplusplus
+# define LANG "C++ "
+#else
+# define LANG "C "
+#endif
+
+static int test_abi_endian(void)
+{
+  int result = 1;
+  {
+#if defined(KWIML_ABI_ENDIAN_ID)
+  int expect;
+  union { short s; unsigned char c[sizeof(short)]; } x;
+  x.s = 1;
+  expect = (x.c[0] == 1 ?
+            KWIML_ABI_ENDIAN_ID_LITTLE : KWIML_ABI_ENDIAN_ID_BIG);
+  printf(LANG "KWIML_ABI_ENDIAN_ID: expected [%d], got [%d]",
+         expect, KWIML_ABI_ENDIAN_ID);
+  if(KWIML_ABI_ENDIAN_ID == expect)
+    {
+    printf(", PASSED\n");
+    }
+  else
+    {
+    printf(", FAILED\n");
+    result = 0;
+    }
+#else
+  printf(LANG "KWIML_ABI_ENDIAN_ID: unknown, FAILED\n");
+  result = 0;
+#endif
+  }
+  return result;
+}
diff --git a/Utilities/KWIML/test/test_include_C.c b/Utilities/KWIML/test/test_include_C.c
index fb3e4cf..518544d 100644
--- a/Utilities/KWIML/test/test_include_C.c
+++ b/Utilities/KWIML/test/test_include_C.c
@@ -1,20 +1,14 @@
-/*============================================================================
-  Kitware Information Macro Library
-  Copyright 2010-2011 Kitware, Inc.
-
-  Distributed under the OSI-approved BSD License (the "License");
-  see accompanying file Copyright.txt for details.
-
-  This software is distributed WITHOUT ANY WARRANTY; without even the
-  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-  See the License for more information.
-============================================================================*/
+/*
+  Copyright Kitware, Inc.
+  Distributed under the OSI-approved BSD 3-Clause License.
+  See accompanying file Copyright.txt for details.
+*/
 #include <stdio.h>
 
 /* Test KWIML header inclusion after above system headers.  */
 #include "test.h"
-#include KWIML_HEADER(ABI.h)
-#include KWIML_HEADER(INT.h)
+#include "../include/kwiml/abi.h"
+#include "../include/kwiml/int.h"
 
 int test_include_C(void)
 {
diff --git a/Utilities/KWIML/test/test_include_CXX.cxx b/Utilities/KWIML/test/test_include_CXX.cxx
index 111311a..82aa546 100644
--- a/Utilities/KWIML/test/test_include_CXX.cxx
+++ b/Utilities/KWIML/test/test_include_CXX.cxx
@@ -1,14 +1,8 @@
-/*============================================================================
-  Kitware Information Macro Library
-  Copyright 2010-2011 Kitware, Inc.
-
-  Distributed under the OSI-approved BSD License (the "License");
-  see accompanying file Copyright.txt for details.
-
-  This software is distributed WITHOUT ANY WARRANTY; without even the
-  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-  See the License for more information.
-============================================================================*/
+/*
+  Copyright Kitware, Inc.
+  Distributed under the OSI-approved BSD 3-Clause License.
+  See accompanying file Copyright.txt for details.
+*/
 #include <string>
 
 #if defined(_MSC_VER) && defined(NDEBUG)
@@ -19,8 +13,8 @@ std::string test_include_CXX_use_stl_string;
 
 /* Test KWIML header inclusion after above system headers.  */
 #include "test.h"
-#include KWIML_HEADER(ABI.h)
-#include KWIML_HEADER(INT.h)
+#include "../include/kwiml/abi.h"
+#include "../include/kwiml/int.h"
 
 extern "C" int test_include_CXX(void)
 {
diff --git a/Utilities/KWIML/test/test_int_C.c b/Utilities/KWIML/test/test_int_C.c
new file mode 100644
index 0000000..fe8ee8e
--- /dev/null
+++ b/Utilities/KWIML/test/test_int_C.c
@@ -0,0 +1,19 @@
+/*
+  Copyright Kitware, Inc.
+  Distributed under the OSI-approved BSD 3-Clause License.
+  See accompanying file Copyright.txt for details.
+*/
+#include "test.h"
+#include "../include/kwiml/int.h"
+#include "test_int_format.h"
+#ifndef KWIML_INT_VERSION
+# error "KWIML_INT_VERSION not defined!"
+#endif
+int test_int_C(void)
+{
+  if(!test_int_format())
+    {
+    return 0;
+    }
+  return 1;
+}
diff --git a/Utilities/KWIML/test/test_int_CXX.cxx b/Utilities/KWIML/test/test_int_CXX.cxx
new file mode 100644
index 0000000..ffa4c9b
--- /dev/null
+++ b/Utilities/KWIML/test/test_int_CXX.cxx
@@ -0,0 +1,19 @@
+/*
+  Copyright Kitware, Inc.
+  Distributed under the OSI-approved BSD 3-Clause License.
+  See accompanying file Copyright.txt for details.
+*/
+#include "test.h"
+#include "../include/kwiml/int.h"
+#include "test_int_format.h"
+#ifndef KWIML_INT_VERSION
+# error "KWIML_INT_VERSION not defined!"
+#endif
+extern "C" int test_int_CXX(void)
+{
+  if(!test_int_format())
+    {
+    return 0;
+    }
+  return 1;
+}
diff --git a/Utilities/KWIML/test/test_INT_format.h.in b/Utilities/KWIML/test/test_int_format.h
similarity index 78%
rename from Utilities/KWIML/test/test_INT_format.h.in
rename to Utilities/KWIML/test/test_int_format.h
index 71b443d..24dcdfb 100644
--- a/Utilities/KWIML/test/test_INT_format.h.in
+++ b/Utilities/KWIML/test/test_int_format.h
@@ -1,17 +1,16 @@
-/*============================================================================
-  Kitware Information Macro Library
-  Copyright 2010-2011 Kitware, Inc.
-
-  Distributed under the OSI-approved BSD License (the "License");
-  see accompanying file Copyright.txt for details.
-
-  This software is distributed WITHOUT ANY WARRANTY; without even the
-  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-  See the License for more information.
-============================================================================*/
+/*
+  Copyright Kitware, Inc.
+  Distributed under the OSI-approved BSD 3-Clause License.
+  See accompanying file Copyright.txt for details.
+*/
 #include <stdio.h>
 #include <string.h>
 
+#if defined(_MSC_VER)
+# pragma warning (push)
+# pragma warning (disable:4310) /* cast truncates constant value */
+#endif
+
 #ifdef __cplusplus
 # define LANG "C++ "
 #else
@@ -25,8 +24,8 @@
   T const x = VALUE(T, U);                                              \
   T y = C(V);                                                           \
   printf(LANG #C ":"                                                    \
-         " expression [%" @KWIML at _INT_PRI##PRI "],"                     \
-         " literal [%" @KWIML at _INT_PRI##PRI "]", x, y);                 \
+         " expression [%" KWIML_INT_PRI##PRI "],"                       \
+         " literal [%" KWIML_INT_PRI##PRI "]", x, y);                   \
   if(x == y)                                                            \
     {                                                                   \
     printf(", PASSED\n");                                               \
@@ -42,8 +41,8 @@
   {                                                                     \
   T const x = VALUE(T, U);                                              \
   char const* str = STR;                                                \
-  sprintf(buf, "%" @KWIML at _INT_PRI##PRI, x);                            \
-  printf(LANG "@KWIML at _INT_PRI" #PRI ":"                                \
+  sprintf(buf, "%" KWIML_INT_PRI##PRI, x);                              \
+  printf(LANG "KWIML_INT_PRI" #PRI ":"                                  \
          " expected [%s], got [%s]", str, buf);                         \
   if(strcmp(str, buf) == 0)                                             \
     {                                                                   \
@@ -62,13 +61,13 @@
   T const x = VALUE(T, U);                                              \
   T y;                                                                  \
   char const* str = STR;                                                \
-  if(sscanf(str, "%" @KWIML at _INT_SCN##SCN, &y) != 1)                    \
+  if(sscanf(str, "%" KWIML_INT_SCN##SCN, &y) != 1)                      \
     {                                                                   \
     y = 0;                                                              \
     }                                                                   \
-  printf(LANG "@KWIML at _INT_SCN" #SCN ":"                                \
-         " expected [%" @KWIML at _INT_PRI##PRI "],"                       \
-         " got [%" @KWIML at _INT_PRI##PRI "]", x, y);                     \
+  printf(LANG "KWIML_INT_SCN" #SCN ":"                                  \
+         " expected [%" KWIML_INT_PRI##PRI "],"                         \
+         " got [%" KWIML_INT_PRI##PRI "]", x, y);                       \
   if(x == y)                                                            \
     {                                                                   \
     printf(", PASSED\n");                                               \
@@ -87,41 +86,41 @@
 
 /* Concatenate T and U now to avoid expanding them.  */
 #define TEST(FMT, T, U, STR) \
-        TEST_(FMT, @KWIML at _INT_##T, @KWIML at _INT_##U, STR)
+        TEST_(FMT, KWIML_INT_##T, KWIML_INT_##U, STR)
 #define TEST2(PRI, SCN, T, U, STR) \
-        TEST2_(PRI, SCN, @KWIML at _INT_##T, @KWIML at _INT_##U, STR)
+        TEST2_(PRI, SCN, KWIML_INT_##T, KWIML_INT_##U, STR)
 #define TEST_C(C, V, PRI, T, U) \
-        TEST_C_(@KWIML at _INT_##C, V, PRI, @KWIML at _INT_##T, @KWIML at _INT_##U)
+        TEST_C_(KWIML_INT_##C, V, PRI, KWIML_INT_##T, KWIML_INT_##U)
 #define TEST_PRI(PRI, T, U, STR) \
-        TEST_PRI_(PRI, @KWIML at _INT_##T, @KWIML at _INT_##U, STR)
+        TEST_PRI_(PRI, KWIML_INT_##T, KWIML_INT_##U, STR)
 #define TEST_SCN(SCN, T, U, STR) \
-        TEST_SCN_(SCN, @KWIML at _INT_##T, @KWIML at _INT_##U, STR)
+        TEST_SCN_(SCN, KWIML_INT_##T, KWIML_INT_##U, STR)
 #define TEST_SCN2(PRI, SCN, T, U, STR) \
-        TEST_SCN2_(PRI, SCN, @KWIML at _INT_##T, @KWIML at _INT_##U, STR)
+        TEST_SCN2_(PRI, SCN, KWIML_INT_##T, KWIML_INT_##U, STR)
 
-static int test_INT_format(void)
+static int test_int_format(void)
 {
   int result = 1;
   char buf[256];
   TEST_PRI(i8, int8_t, uint8_t, "-85")
-#if defined(@KWIML at _INT_SCNi8)
+#if defined(KWIML_INT_SCNi8)
   TEST_SCN(i8, int8_t, uint8_t, "-85")
 #endif
   TEST_PRI(d8, int8_t, uint8_t, "-85")
-#if defined(@KWIML at _INT_SCNd8)
+#if defined(KWIML_INT_SCNd8)
   TEST_SCN(d8, int8_t, uint8_t, "-85")
 #endif
   TEST_PRI(o8, uint8_t, uint8_t, "253")
-#if defined(@KWIML at _INT_SCNo8)
+#if defined(KWIML_INT_SCNo8)
   TEST_SCN(o8, uint8_t, uint8_t, "253")
 #endif
   TEST_PRI(u8, uint8_t, uint8_t, "171")
-#if defined(@KWIML at _INT_SCNu8)
+#if defined(KWIML_INT_SCNu8)
   TEST_SCN(u8, uint8_t, uint8_t, "171")
 #endif
   TEST_PRI(x8, uint8_t, uint8_t, "ab")
   TEST_PRI(X8, uint8_t, uint8_t, "AB")
-#if defined(@KWIML at _INT_SCNx8)
+#if defined(KWIML_INT_SCNx8)
   TEST_SCN(x8, uint8_t, uint8_t, "ab")
   TEST_SCN2(X8, x8, uint8_t, uint8_t, "AB")
 #endif
@@ -141,30 +140,30 @@ static int test_INT_format(void)
   TEST2(X32, x32, uint32_t, uint32_t, "AB000000")
 
   TEST_PRI(i64, int64_t, uint64_t, "-6124895493223874560")
-#if defined(@KWIML at _INT_SCNi64)
+#if defined(KWIML_INT_SCNi64)
   TEST_SCN(i64, int64_t, uint64_t, "-6124895493223874560")
 #endif
   TEST_PRI(d64, int64_t, uint64_t, "-6124895493223874560")
-#if defined(@KWIML at _INT_SCNd64)
+#if defined(KWIML_INT_SCNd64)
   TEST_SCN(d64, int64_t, uint64_t, "-6124895493223874560")
 #endif
   TEST_PRI(o64, uint64_t, uint64_t, "1254000000000000000000")
-#if defined(@KWIML at _INT_SCNo64)
+#if defined(KWIML_INT_SCNo64)
   TEST_SCN(o64, uint64_t, uint64_t, "1254000000000000000000")
 #endif
   TEST_PRI(u64, uint64_t, uint64_t, "12321848580485677056")
-#if defined(@KWIML at _INT_SCNu64)
+#if defined(KWIML_INT_SCNu64)
   TEST_SCN(u64, uint64_t, uint64_t, "12321848580485677056")
 #endif
   TEST_PRI(x64, uint64_t, uint64_t, "ab00000000000000")
   TEST_PRI(X64, uint64_t, uint64_t, "AB00000000000000")
-#if defined(@KWIML at _INT_SCNx64)
+#if defined(KWIML_INT_SCNx64)
   TEST_SCN(x64, uint64_t, uint64_t, "ab00000000000000")
   TEST_SCN2(X64, x64, uint64_t, uint64_t, "AB00000000000000")
 #endif
 
-#if !defined(@KWIML at _INT_NO_INTPTR_T)
-# if @KWIML at _ABI_SIZEOF_DATA_PTR == 4
+#if !defined(KWIML_INT_NO_INTPTR_T)
+# if KWIML_ABI_SIZEOF_DATA_PTR == 4
   TEST(iPTR, intptr_t, uint32_t, "-1426063360")
   TEST(dPTR, intptr_t, uint32_t, "-1426063360")
 # else
@@ -173,8 +172,8 @@ static int test_INT_format(void)
 # endif
 #endif
 
-#if !defined(@KWIML at _INT_NO_UINTPTR_T)
-# if @KWIML at _ABI_SIZEOF_DATA_PTR == 4
+#if !defined(KWIML_INT_NO_UINTPTR_T)
+# if KWIML_ABI_SIZEOF_DATA_PTR == 4
   TEST(oPTR, uintptr_t, uintptr_t, "25300000000")
   TEST(uPTR, uintptr_t, uintptr_t, "2868903936")
   TEST(xPTR, uintptr_t, uintptr_t, "ab000000")
@@ -198,3 +197,7 @@ static int test_INT_format(void)
 
   return result;
 }
+
+#if defined(_MSC_VER)
+# pragma warning (pop)
+#endif
diff --git a/Utilities/Release/WiX/CMakeLists.txt b/Utilities/Release/WiX/CMakeLists.txt
new file mode 100644
index 0000000..cc0dbe1
--- /dev/null
+++ b/Utilities/Release/WiX/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_subdirectory(CustomAction)
+
+if(CMAKE_CONFIGURATION_TYPES)
+  set(CUSTOM_ACTION_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/custom_action_dll-$<CONFIG>.wxs")
+else()
+  set(CUSTOM_ACTION_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/custom_action_dll.wxs")
+endif()
+
+file(GENERATE
+  OUTPUT "${CUSTOM_ACTION_OUTPUT}"
+  INPUT "${CMAKE_CURRENT_SOURCE_DIR}/custom_action_dll.wxs.in"
+  )
diff --git a/Utilities/Release/WiX/CustomAction/CMakeLists.txt b/Utilities/Release/WiX/CustomAction/CMakeLists.txt
new file mode 100644
index 0000000..7efd01e
--- /dev/null
+++ b/Utilities/Release/WiX/CustomAction/CMakeLists.txt
@@ -0,0 +1,13 @@
+foreach(CONFIG DEBUG MINSIZEREL RELEASE RELWITHDEBINFO)
+  string(REPLACE "/MD" "/MT"
+    "CMAKE_CXX_FLAGS_${CONFIG}"
+    "${CMAKE_CXX_FLAGS_${CONFIG}}"
+  )
+endforeach()
+
+add_library(CMakeWiXCustomActions MODULE
+  detect_nsis_overwrite.cpp
+  exports.def
+)
+
+target_link_libraries(CMakeWiXCustomActions PRIVATE msi)
diff --git a/Utilities/Release/WiX/CustomAction/detect_nsis_overwrite.cpp b/Utilities/Release/WiX/CustomAction/detect_nsis_overwrite.cpp
new file mode 100644
index 0000000..dad1ae5
--- /dev/null
+++ b/Utilities/Release/WiX/CustomAction/detect_nsis_overwrite.cpp
@@ -0,0 +1,45 @@
+#include <windows.h>
+#include <msi.h>
+#include <msiquery.h>
+
+#include <string>
+#include <vector>
+
+std::wstring get_property(MSIHANDLE msi_handle, std::wstring const& name)
+{
+  DWORD size = 0;
+
+  UINT status = MsiGetPropertyW(msi_handle, name.c_str(), L"", &size);
+
+  if(status == ERROR_MORE_DATA)
+    {
+    std::vector<wchar_t> buffer(size + 1);
+    MsiGetPropertyW(msi_handle, name.c_str(), &buffer[0], &size);
+    return std::wstring(&buffer[0]);
+    }
+  else
+    {
+    return std::wstring();
+    }
+}
+
+void set_property(MSIHANDLE msi_handle,
+  std::wstring const& name, std::wstring const& value)
+{
+  MsiSetPropertyW(msi_handle, name.c_str(), value.c_str());
+}
+
+extern "C" UINT __stdcall DetectNsisOverwrite(MSIHANDLE msi_handle)
+{
+  std::wstring install_root = get_property(msi_handle, L"INSTALL_ROOT");
+
+  std::wstring uninstall_exe = install_root + L"\\uninstall.exe";
+
+  bool uninstall_exe_exists =
+      GetFileAttributesW(uninstall_exe.c_str()) != INVALID_FILE_ATTRIBUTES;
+
+  set_property(msi_handle, L"CMAKE_NSIS_OVERWRITE_DETECTED",
+    uninstall_exe_exists ? L"1" : L"0");
+
+  return ERROR_SUCCESS;
+}
diff --git a/Utilities/Release/WiX/CustomAction/exports.def b/Utilities/Release/WiX/CustomAction/exports.def
new file mode 100644
index 0000000..0e448b2
--- /dev/null
+++ b/Utilities/Release/WiX/CustomAction/exports.def
@@ -0,0 +1,2 @@
+EXPORTS
+	DetectNsisOverwrite=DetectNsisOverwrite
diff --git a/Utilities/Release/WiX/WIX.template.in b/Utilities/Release/WiX/WIX.template.in
new file mode 100644
index 0000000..094999f
--- /dev/null
+++ b/Utilities/Release/WiX/WIX.template.in
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?include "cpack_variables.wxi"?>
+
+<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
+    RequiredVersion="3.6.3303.0">
+
+    <Product Id="$(var.CPACK_WIX_PRODUCT_GUID)"
+        Name="$(var.CPACK_PACKAGE_NAME)"
+        Language="1033"
+        Version="$(var.CPACK_PACKAGE_VERSION)"
+        Manufacturer="$(var.CPACK_PACKAGE_VENDOR)"
+        UpgradeCode="$(var.CPACK_WIX_UPGRADE_GUID)">
+
+        <Package InstallerVersion="301" Compressed="yes" InstallScope="perMachine"/>
+
+        <Media Id="1" Cabinet="media1.cab" EmbedCab="yes"/>
+
+        <MajorUpgrade
+            Schedule="afterInstallInitialize"
+            AllowDowngrades="yes"/>
+
+        <WixVariable Id="WixUILicenseRtf" Value="$(var.CPACK_WIX_LICENSE_RTF)"/>
+        <Property Id="WIXUI_INSTALLDIR" Value="INSTALL_ROOT"/>
+
+        <?ifdef CPACK_WIX_PRODUCT_ICON?>
+        <Property Id="ARPPRODUCTICON">ProductIcon.ico</Property>
+        <Icon Id="ProductIcon.ico" SourceFile="$(var.CPACK_WIX_PRODUCT_ICON)"/>
+        <?endif?>
+
+        <?ifdef CPACK_WIX_UI_BANNER?>
+        <WixVariable Id="WixUIBannerBmp" Value="$(var.CPACK_WIX_UI_BANNER)"/>
+        <?endif?>
+
+        <?ifdef CPACK_WIX_UI_DIALOG?>
+        <WixVariable Id="WixUIDialogBmp" Value="$(var.CPACK_WIX_UI_DIALOG)"/>
+        <?endif?>
+
+        <FeatureRef Id="ProductFeature"/>
+
+        <UIRef Id="$(var.CPACK_WIX_UI_REF)" />
+
+        <?include "properties.wxi"?>
+        <?include "product_fragment.wxi"?>
+    </Product>
+</Wix>
diff --git a/Utilities/Release/WiX/cmake_extra_dialog.wxs b/Utilities/Release/WiX/cmake_extra_dialog.wxs
new file mode 100644
index 0000000..0ee3d99
--- /dev/null
+++ b/Utilities/Release/WiX/cmake_extra_dialog.wxs
@@ -0,0 +1,36 @@
+<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
+	<Fragment>
+		<UI>
+			<Property Id="ADD_CMAKE_TO_PATH" Value="None"/>
+			<Dialog Id="CMakeExtraDialog" Width="370" Height="270" Title="Install Options">
+
+				<Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="!(loc.WixUINext)"/>
+				<Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)"/>
+
+				<Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="!(loc.WixUICancel)">
+					<Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
+				</Control>
+
+				<Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes" Text="Choose options for installing CMake [ProductVersion]"/>
+				<Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes" Text="Install Options"/>
+				<Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="!(loc.InstallDirDlgBannerBitmap)"/>
+				<Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0"/>
+				<Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0"/>
+
+				<Control Id="Hint" Type="Text" X="26" Y="60" Width="250" Height="16" Transparent="yes" Text="By default CMake does not add its directory to the system PATH."/>
+
+				<Control Id="ADD_CMAKE_TO_PATHOption" Type="RadioButtonGroup" X="26" Y="100" Width="305" Height="65" Property="ADD_CMAKE_TO_PATH">
+					<RadioButtonGroup Property="ADD_CMAKE_TO_PATH">
+						<RadioButton Value="None" X="0" Y="0" Width="295" Height="16" Text="Do not add CMake to the system PATH"/>
+						<RadioButton Value="System" X="0" Y="20" Width="295" Height="16" Text="Add CMake to the system PATH for all users"/>
+						<RadioButton Value="User" X="0" Y="40" Width="295" Height="16" Text="Add CMake to the system PATH for the current user"/>
+					</RadioButtonGroup>
+				</Control>
+
+				<?ifdef BUILD_QtDialog ?>
+					<Control Id="DesktopShortcutCheckBox" Type="CheckBox" X="20" Y="170" Width="330" Height="18" CheckBoxValue="1" Property="DESKTOP_SHORTCUT_REQUESTED" Text="Create CMake Desktop Icon"/>
+				<?endif ?>
+			</Dialog>
+		</UI>
+	</Fragment>
+</Wix>
diff --git a/Utilities/Release/WiX/cmake_nsis_overwrite_dialog.wxs b/Utilities/Release/WiX/cmake_nsis_overwrite_dialog.wxs
new file mode 100644
index 0000000..8fe60f2
--- /dev/null
+++ b/Utilities/Release/WiX/cmake_nsis_overwrite_dialog.wxs
@@ -0,0 +1,21 @@
+<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
+	<Fragment>
+		<UI>
+	            <Dialog Id="CMakeNsisOverwriteDialog" Width="310" Height="120" Title="NSIS Installation Conflict">
+			<Control Id="OK" Type="PushButton" X="122" Y="90" Width="56" Height="17" Default="yes" Cancel="yes" Text="!(loc.WixUIOK)">
+	                    <Publish Event="EndDialog" Value="Return">1</Publish>
+	                </Control>
+	                <Control Id="Text" Type="Text" X="48" Y="22" Width="260" Height="60">
+				<Text>
+					Uninstall.exe was detected in your chosen installation prefix.
+					This indicates a conflicting NSIS based installation of CMake.
+
+					Please uninstall your old CMake installation or choose a different
+					installation directory.
+				</Text>
+			</Control>
+	                <Control Id="Icon" Type="Icon" X="15" Y="15" Width="24" Height="24" ToolTip="!(loc.InvalidDirDlgIconTooltip)" FixedSize="yes" IconSize="32" Text="!(loc.InvalidDirDlgIcon)" />
+	            </Dialog>
+		</UI>
+	</Fragment>
+</Wix>
diff --git a/Utilities/Release/WiX/custom_action_dll.wxs.in b/Utilities/Release/WiX/custom_action_dll.wxs.in
new file mode 100644
index 0000000..021e63c
--- /dev/null
+++ b/Utilities/Release/WiX/custom_action_dll.wxs.in
@@ -0,0 +1,6 @@
+<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
+	<Fragment>
+		<Binary Id="CMakeCustomActionsDll"
+			SourceFile="$<TARGET_FILE:CMakeWiXCustomActions>"/>
+	</Fragment>
+</Wix>
diff --git a/Utilities/Release/WiX/install_dir.wxs b/Utilities/Release/WiX/install_dir.wxs
new file mode 100644
index 0000000..49b74e3
--- /dev/null
+++ b/Utilities/Release/WiX/install_dir.wxs
@@ -0,0 +1,72 @@
+<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
+	<Fragment>
+		<UI Id="CMakeUI_InstallDir">
+			<TextStyle Id="WixUI_Font_Normal" FaceName="Tahoma" Size="8" />
+			<TextStyle Id="WixUI_Font_Bigger" FaceName="Tahoma" Size="12" />
+			<TextStyle Id="WixUI_Font_Title" FaceName="Tahoma" Size="9" Bold="yes" />
+
+			<Property Id="DefaultUIFont" Value="WixUI_Font_Normal" />
+			<Property Id="WixUI_Mode" Value="InstallDir" />
+
+			<DialogRef Id="CMakeExtraDialog" />
+			<?ifdef CHECK_NSIS ?>
+				<DialogRef Id="CMakeNsisOverwriteDialog" />
+			<?endif ?>
+
+			<DialogRef Id="BrowseDlg" />
+			<DialogRef Id="DiskCostDlg" />
+			<DialogRef Id="ErrorDlg" />
+			<DialogRef Id="FatalError" />
+			<DialogRef Id="FilesInUse" />
+			<DialogRef Id="MsiRMFilesInUse" />
+			<DialogRef Id="PrepareDlg" />
+			<DialogRef Id="ProgressDlg" />
+			<DialogRef Id="ResumeDlg" />
+			<DialogRef Id="UserExit" />
+
+			<Publish Dialog="BrowseDlg" Control="OK" Event="DoAction" Value="WixUIValidatePath" Order="3">1</Publish>
+			<Publish Dialog="BrowseDlg" Control="OK" Event="SpawnDialog" Value="InvalidDirDlg" Order="4"><![CDATA[WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
+
+			<Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>
+
+			<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="LicenseAgreementDlg">NOT Installed</Publish>
+			<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">Installed AND PATCH</Publish>
+
+			<Publish Dialog="LicenseAgreementDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg">1</Publish>
+			<Publish Dialog="LicenseAgreementDlg" Control="Next" Event="NewDialog" Value="CMakeExtraDialog">LicenseAccepted = "1"</Publish>
+
+			<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="CMakeExtraDialog">1</Publish>
+			<Publish Dialog="InstallDirDlg" Control="Next" Event="SetTargetPath" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
+			<Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="WixUIValidatePath" Order="2">NOT WIXUI_DONTVALIDATEPATH</Publish>
+			<Publish Dialog="InstallDirDlg" Control="Next" Event="SpawnDialog" Value="InvalidDirDlg" Order="3"><![CDATA[NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
+			<?ifdef CHECK_NSIS ?>
+				<Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="CMakeDetectNsisOverwrite" Order="4">1</Publish>
+				<Publish Dialog="InstallDirDlg" Control="Next" Event="SpawnDialog" Value="CMakeNsisOverwriteDialog" Order="5">CMAKE_NSIS_OVERWRITE_DETECTED="1"</Publish>
+			<?endif ?>
+			<Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="6"><![CDATA[(WIXUI_DONTVALIDATEPATH OR WIXUI_INSTALLDIR_VALID="1") AND CMAKE_NSIS_OVERWRITE_DETECTED<>1]]></Publish>
+			<Publish Dialog="InstallDirDlg" Control="ChangeFolder" Property="_BrowseProperty" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
+			<Publish Dialog="InstallDirDlg" Control="ChangeFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2">1</Publish>
+
+			<Publish Dialog="CMakeExtraDialog" Control="Back" Event="NewDialog" Value="LicenseAgreementDlg">1</Publish>
+			<Publish Dialog="CMakeExtraDialog" Control="Next" Event="NewDialog" Value="InstallDirDlg">1</Publish>
+
+			<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="InstallDirDlg" Order="1">NOT Installed</Publish>
+			<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg" Order="2">Installed AND NOT PATCH</Publish>
+			<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2">Installed AND PATCH</Publish>
+
+			<Publish Dialog="MaintenanceWelcomeDlg" Control="Next" Event="NewDialog" Value="MaintenanceTypeDlg">1</Publish>
+
+			<Publish Dialog="MaintenanceTypeDlg" Control="RepairButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
+			<Publish Dialog="MaintenanceTypeDlg" Control="RemoveButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
+			<Publish Dialog="MaintenanceTypeDlg" Control="Back" Event="NewDialog" Value="MaintenanceWelcomeDlg">1</Publish>
+
+			<Property Id="ARPNOMODIFY" Value="1" />
+		</UI>
+
+		<UIRef Id="WixUI_Common" />
+
+		<?ifdef CHECK_NSIS ?>
+			<CustomAction Id="CMakeDetectNsisOverwrite" BinaryKey="CMakeCustomActionsDll" DllEntry="DetectNsisOverwrite"/>
+		<?endif ?>
+	</Fragment>
+</Wix>
diff --git a/Utilities/Release/WiX/patch_desktop_shortcut.xml b/Utilities/Release/WiX/patch_desktop_shortcut.xml
new file mode 100644
index 0000000..d30705d
--- /dev/null
+++ b/Utilities/Release/WiX/patch_desktop_shortcut.xml
@@ -0,0 +1,5 @@
+<CPackWiXPatch>
+  <CPackWiXFragment Id="CM_SHORTCUT_DESKTOP">
+    <Condition>DESKTOP_SHORTCUT_REQUESTED = 1</Condition>
+  </CPackWiXFragment>
+</CPackWiXPatch>
diff --git a/Utilities/Release/WiX/patch_path_env.xml b/Utilities/Release/WiX/patch_path_env.xml
new file mode 100644
index 0000000..0e335c4
--- /dev/null
+++ b/Utilities/Release/WiX/patch_path_env.xml
@@ -0,0 +1,26 @@
+<CPackWiXPatch>
+  <CPackWiXFragment Id="CM_DP_bin">
+    <Component Id="CMakeSystemPathEntryCMP" KeyPath="yes" Guid="0E782367-5D68-4539-81D1-B9757AE496A1">
+
+      <Condition>ADD_CMAKE_TO_PATH = "System"</Condition>
+
+      <Environment Id="CMakeSystemPathEntryENV" Action="set" Part="last"
+        Name="PATH" Value="[INSTALL_ROOT]bin"
+        System="yes"/>
+    </Component>
+
+    <Component Id="CMakeUserPathEntryCMP" KeyPath="yes" Guid="392E524D-D5BF-4F16-A7AF-A82B07482CB9">
+
+      <Condition>ADD_CMAKE_TO_PATH = "User"</Condition>
+
+      <Environment Id="CMakeUserPathEntryENV" Action="set" Part="last"
+        Name="PATH" Value="[INSTALL_ROOT]bin"
+        System="no"/>
+    </Component>
+  </CPackWiXFragment>
+
+  <CPackWiXFragment Id="#PRODUCTFEATURE">
+    <ComponentRef Id="CMakeSystemPathEntryCMP"/>
+    <ComponentRef Id="CMakeUserPathEntryCMP"/>
+  </CPackWiXFragment>
+</CPackWiXPatch>
diff --git a/Utilities/Release/cpack_wix_ui_banner.jpg b/Utilities/Release/WiX/ui_banner.jpg
similarity index 100%
rename from Utilities/Release/cpack_wix_ui_banner.jpg
rename to Utilities/Release/WiX/ui_banner.jpg
diff --git a/Utilities/Release/cpack_wix_ui_dialog.jpg b/Utilities/Release/WiX/ui_dialog.jpg
similarity index 100%
rename from Utilities/Release/cpack_wix_ui_dialog.jpg
rename to Utilities/Release/WiX/ui_dialog.jpg
diff --git a/Utilities/Release/create-cmake-release.cmake b/Utilities/Release/create-cmake-release.cmake
index 4cfa2ed..d41c4ec 100644
--- a/Utilities/Release/create-cmake-release.cmake
+++ b/Utilities/Release/create-cmake-release.cmake
@@ -6,9 +6,8 @@ endif()
 file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/logs)
 
 set(RELEASE_SCRIPTS_BATCH_1
-  dash2win64_release.cmake    # Windows
-  dashmacmini2_release.cmake  # Mac Darwin universal ppc;i386
-  dashmacmini5_release.cmake  # Mac Darwin64 universal x86_64;i386
+  dash3win7_release.cmake     # Windows
+  dashmacmini5_release.cmake  # OS X x86_64
   magrathea_release.cmake     # Linux
   linux64_release.cmake       # Linux x86_64
 )
diff --git a/Utilities/Release/dash2win64_cygwin.cmake b/Utilities/Release/dash2win64_cygwin.cmake
index c0cd761..ca590ed 100644
--- a/Utilities/Release/dash2win64_cygwin.cmake
+++ b/Utilities/Release/dash2win64_cygwin.cmake
@@ -28,4 +28,6 @@ get_filename_component(path "${CMAKE_CURRENT_LIST_FILE}" PATH)
 # allows us to produce cygwin builds in the short term.
 set(EXTRA_CTEST_ARGS "-E ExternalProject")
 
+set(LOCAL_DIR cygwin)
+
 include(${path}/release_cmake.cmake)
diff --git a/Utilities/Release/dash2win64_release.cmake b/Utilities/Release/dash3win7_release.cmake
similarity index 61%
rename from Utilities/Release/dash2win64_release.cmake
rename to Utilities/Release/dash3win7_release.cmake
index ecfd7c5..f25d638 100644
--- a/Utilities/Release/dash2win64_release.cmake
+++ b/Utilities/Release/dash3win7_release.cmake
@@ -1,23 +1,28 @@
-set(CMAKE_RELEASE_DIRECTORY "c:/cygwin/home/dashboard/CMakeReleaseDirectory")
+set(CMAKE_RELEASE_DIRECTORY "c:/msys64/home/dashboard/CMakeReleaseDirectory")
 set(CONFIGURE_WITH_CMAKE TRUE)
 set(CMAKE_CONFIGURE_PATH "c:/Program\\ Files\\ \\(x86\\)/CMake/bin/cmake.exe")
 set(PROCESSORS 8)
-set(HOST dash2win64)
-set(CPACK_BINARY_GENERATORS "NSIS ZIP")
+set(HOST dash3win7)
+set(RUN_LAUNCHER ~/rel/run)
+set(CPACK_BINARY_GENERATORS "WIX ZIP")
 set(CPACK_SOURCE_GENERATORS "ZIP")
-set(MAKE_PROGRAM "make")
+set(MAKE_PROGRAM "ninja")
 set(MAKE "${MAKE_PROGRAM} -j8")
 set(INITIAL_CACHE "CMAKE_BUILD_TYPE:STRING=Release
 CMAKE_DOC_DIR:STRING=doc/cmake
 CMAKE_USE_OPENSSL:BOOL=OFF
 CMAKE_SKIP_BOOTSTRAP_TEST:STRING=TRUE
 CMAKE_Fortran_COMPILER:FILEPATH=FALSE
-CMAKE_GENERATOR:INTERNAL=Unix Makefiles
+CMAKE_GENERATOR:INTERNAL=Ninja
 BUILD_QtDialog:BOOL:=TRUE
 CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL:BOOL=TRUE
 CMake_INSTALL_DEPENDENCIES:BOOL=ON
-QT_QMAKE_EXECUTABLE:FILEPATH=c:/Dashboards/Support/qt-build/Qt/bin/qmake.exe
+CMAKE_EXE_LINKER_FLAGS:STRING=-machine:x86 -subsystem:console,5.01
 ")
+set(ppflags "-D_WIN32_WINNT=0x501 -D_USING_V110_SDK71_")
+set(CFLAGS "${ppflags}")
+set(CXXFLAGS "${ppflags}")
+set(ENV ". ~/rel/env")
 get_filename_component(path "${CMAKE_CURRENT_LIST_FILE}" PATH)
 set(GIT_EXTRA "git config core.autocrlf true")
 include(${path}/release_cmake.cmake)
diff --git a/Utilities/Release/dashmacmini2_release.cmake b/Utilities/Release/dashmacmini2_release.cmake
deleted file mode 100644
index cd4c5a1..0000000
--- a/Utilities/Release/dashmacmini2_release.cmake
+++ /dev/null
@@ -1,25 +0,0 @@
-set(PROCESSORS 2)
-set(CMAKE_RELEASE_DIRECTORY /Users/kitware/CMakeReleaseDirectory)
-set(USER_OVERRIDE "set(CMAKE_CXX_LINK_EXECUTABLE \\\"gcc  <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>  -shared-libgcc -lstdc++-static\\\")")
-set(BOOTSTRAP_ARGS "--prefix=/ --docdir=doc/cmake")
-set(HOST dashmacmini2)
-set(MAKE_PROGRAM "make")
-set(MAKE "${MAKE_PROGRAM} -j2")
-set(CPACK_BINARY_GENERATORS "DragNDrop TGZ TZ")
-set(CPACK_DMG_FORMAT "UDBZ") #build using bzip2 for smaller package size
-set(INITIAL_CACHE "
-CMAKE_BUILD_TYPE:STRING=Release
-CMAKE_OSX_ARCHITECTURES:STRING=ppc;i386
-CMAKE_USE_OPENSSL:BOOL=ON
-OPENSSL_CRYPTO_LIBRARY:FILEPATH=/Users/kitware/openssl-1.0.1g-install/lib/libcrypto.a
-OPENSSL_INCLUDE_DIR:PATH=/Users/kitware/openssl-1.0.1g-install/include
-OPENSSL_SSL_LIBRARY:FILEPATH=/Users/kitware/openssl-1.0.1g-install/lib/libssl.a
-CMAKE_SKIP_BOOTSTRAP_TEST:STRING=TRUE
-CPACK_SYSTEM_NAME:STRING=Darwin-universal
-BUILD_QtDialog:BOOL=TRUE
-CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL:BOOL=TRUE
-CMake_INSTALL_DEPENDENCIES:BOOL=ON
-QT_QMAKE_EXECUTABLE:FILEPATH=/Users/kitware/Support/qt-4.8.0/install/bin/qmake
-")
-get_filename_component(path "${CMAKE_CURRENT_LIST_FILE}" PATH)
-include(${path}/release_cmake.cmake)
diff --git a/Utilities/Release/release_cmake.cmake b/Utilities/Release/release_cmake.cmake
index 4c4dd8a..0d9c784 100644
--- a/Utilities/Release/release_cmake.cmake
+++ b/Utilities/Release/release_cmake.cmake
@@ -19,6 +19,9 @@ endif()
 if(NOT DEFINED RUN_SHELL)
   set(RUN_SHELL "/bin/sh")
 endif()
+if(NOT DEFINED RUN_LAUNCHER)
+  set(RUN_LAUNCHER "")
+endif()
 if(NOT DEFINED PROCESSORS)
   set(PROCESSORS 1)
 endif()
@@ -52,11 +55,11 @@ message("Creating CMake release ${CMAKE_CREATE_VERSION} on ${HOST} with parallel
 macro(remote_command comment command)
   message("${comment}")
   if(${ARGC} GREATER 2)
-    message("ssh ${HOST} ${command}")
-    execute_process(COMMAND ssh ${HOST} ${command} RESULT_VARIABLE result INPUT_FILE ${ARGV2})
+    message("ssh ${HOST} ${RUN_LAUNCHER} ${command}")
+    execute_process(COMMAND ssh ${HOST} ${RUN_LAUNCHER} ${command} RESULT_VARIABLE result INPUT_FILE ${ARGV2})
   else()
-    message("ssh ${HOST} ${command}")
-    execute_process(COMMAND ssh ${HOST} ${command} RESULT_VARIABLE result)
+    message("ssh ${HOST} ${RUN_LAUNCHER} ${command}")
+    execute_process(COMMAND ssh ${HOST} ${RUN_LAUNCHER} ${command} RESULT_VARIABLE result)
   endif()
   if(${result} GREATER 0)
     message(FATAL_ERROR "Error running command: ${command}, return value = ${result}")
@@ -112,6 +115,9 @@ foreach(gen ${generators})
   if("${gen}" STREQUAL "TZ")
     set(SUFFIXES ${SUFFIXES} "*.tar.Z")
   endif()
+  if("${gen}" STREQUAL "WIX")
+    set(SUFFIXES ${SUFFIXES} "*.msi")
+  endif()
   if("${gen}" STREQUAL "ZIP")
     set(SUFFIXES ${SUFFIXES} "*.zip")
   endif()
@@ -119,27 +125,38 @@ foreach(gen ${generators})
     set(SUFFIXES ${SUFFIXES} "*.exe")
   endif()
 endforeach()
+
+if(SUFFIXES)
+  list(REMOVE_DUPLICATES SUFFIXES)
+endif()
+
+if(LOCAL_DIR)
+  file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${LOCAL_DIR}")
+else()
+  set(LOCAL_DIR .)
+endif()
+
 # copy all the files over from the remote machine
 set(PROJECT_PREFIX cmake-)
 foreach(suffix ${SUFFIXES})
-  message("scp ${HOST}:${FINAL_PATH}/${PROJECT_PREFIX}${suffix} .")
+  message("scp ${HOST}:${FINAL_PATH}/${PROJECT_PREFIX}${suffix} ${LOCAL_DIR}")
   execute_process(COMMAND
-    scp ${HOST}:${FINAL_PATH}/${PROJECT_PREFIX}${suffix} .
+    scp ${HOST}:${FINAL_PATH}/${PROJECT_PREFIX}${suffix} ${LOCAL_DIR}
     RESULT_VARIABLE result)
   if(${result} GREATER 0)
-    message("error getting file back scp ${HOST}:${FINAL_PATH}/${PROJECT_PREFIX}${suffix} .")
+    message("error getting file back scp ${HOST}:${FINAL_PATH}/${PROJECT_PREFIX}${suffix} ${LOCAL_DIR}")
   endif()
 endforeach()
 
 # if there are extra files to copy get them as well
 if(extra_files)
   foreach(f ${extra_files})
-    message("scp ${HOST}:${FINAL_PATH}/${f} .")
+    message("scp ${HOST}:${FINAL_PATH}/${f} ${LOCAL_DIR}")
     execute_process(COMMAND
-      scp ${HOST}:${FINAL_PATH}/${f} .
+      scp ${HOST}:${FINAL_PATH}/${f} ${LOCAL_DIR}
       RESULT_VARIABLE result)
     if(${result} GREATER 0)
-      message("error getting file back scp ${HOST}:${FINAL_PATH}/${f} .")
+      message("error getting file back scp ${HOST}:${FINAL_PATH}/${f} ${LOCAL_DIR}")
     endif()
   endforeach()
 endif()
diff --git a/Utilities/Release/release_cmake.sh.in b/Utilities/Release/release_cmake.sh.in
index 06e720f..1465129 100755
--- a/Utilities/Release/release_cmake.sh.in
+++ b/Utilities/Release/release_cmake.sh.in
@@ -5,6 +5,7 @@ echo ""
 echo  "remove and create working directory @CMAKE_RELEASE_DIRECTORY@"
 rm -rf @CMAKE_RELEASE_DIRECTORY@
 mkdir @CMAKE_RELEASE_DIRECTORY@
+ at ENV@
 
 check_exit_value()
 {
diff --git a/Utilities/Release/upload_release.cmake b/Utilities/Release/upload_release.cmake
index 171811a..f5e325e 100644
--- a/Utilities/Release/upload_release.cmake
+++ b/Utilities/Release/upload_release.cmake
@@ -1,6 +1,6 @@
 set(CTEST_RUN_CURRENT_SCRIPT 0)
 if(NOT VERSION)
- set(VERSION 3.4)
+ set(VERSION 3.5)
 endif()
 if(NOT DEFINED PROJECT_PREFIX)
   set(PROJECT_PREFIX cmake-${VERSION})
diff --git a/Utilities/Scripts/BoostScanDeps.cmake b/Utilities/Scripts/BoostScanDeps.cmake
new file mode 100644
index 0000000..1fbea4b
--- /dev/null
+++ b/Utilities/Scripts/BoostScanDeps.cmake
@@ -0,0 +1,217 @@
+# Scan the Boost headers and determine the library dependencies.  Note
+# that this script only scans one Boost version at once; invoke once
+# for each Boost release.  Note that this does require the headers for
+# a given component to match the library name, since this computes
+# inter-library dependencies.  Library components for which this
+# assumption does not hold true and which have dependencies on other
+# Boost libraries will require special-casing.  It also doesn't handle
+# private dependencies not described in the headers, for static
+# library dependencies--this is also a limitation of auto-linking, and
+# I'm unaware of any specific instances where this would be
+# problematic.
+#
+# Invoke in script mode, defining these variables:
+# BOOST_DIR - the root of the boost includes
+#
+# The script will process each directory under the root as a
+# "component".  For each component, all the headers will be scanned to
+# determine the components it depends upon by following all the
+# possible includes from this component.  This is to match the
+# behaviour of autolinking.
+
+# Written by Roger Leigh <rleigh at codelibre.net>
+
+#=============================================================================
+# Copyright 2014-2015 University of Dundee
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+# Determine header dependencies on libraries using the embedded dependency information.
+#
+# component - the component to check (uses all headers from boost/${component})
+# includedir - the path to the Boost headers
+# _ret_libs - list of library dependencies
+#
+function(_Boost_FIND_COMPONENT_DEPENDENCIES component includedir _ret_libs)
+  # _boost_unprocessed_headers - list of headers requiring parsing
+  # _boost_processed_headers - headers already parsed (or currently being parsed)
+  # _boost_new_headers - new headers discovered for future processing
+
+  set(library_component FALSE)
+
+  # Start by finding all headers for the component; header
+  # dependencies via #include will be solved by future passes
+
+  # Special-case since it is part of mpi; look only in boost/mpi/python*
+  if(component STREQUAL "mpi_python")
+    set(_boost_DEPS "python")
+    set(library_component TRUE)
+    file(GLOB_RECURSE _boost_unprocessed_headers
+         RELATIVE "${includedir}"
+         "${includedir}/boost/mpi/python/*")
+    list(INSERT _boost_unprocessed_headers 0 "${includedir}/boost/mpi/python.hpp")
+  # Special-case since it is a serialization variant; look in boost/serialization
+  elseif(component STREQUAL "wserialization")
+    set(library_component TRUE)
+    file(GLOB_RECURSE _boost_unprocessed_headers
+         RELATIVE "${includedir}"
+         "${includedir}/boost/serialization/*")
+    list(INSERT _boost_unprocessed_headers 0 "${includedir}/boost/serialization.hpp")
+  # Not really a library in its own right, but treat it as one
+  elseif(component STREQUAL "math")
+    set(library_component TRUE)
+    file(GLOB_RECURSE _boost_unprocessed_headers
+         RELATIVE "${includedir}"
+         "${includedir}/boost/math/*")
+    list(INSERT _boost_unprocessed_headers 0 "${includedir}/boost/math.hpp")
+  # Single test header
+  elseif(component STREQUAL "unit_test_framework")
+    set(library_component TRUE)
+    set(_boost_unprocessed_headers "${BOOST_DIR}/test/unit_test.hpp")
+  # Single test header
+  elseif(component STREQUAL "prg_exec_monitor")
+    set(library_component TRUE)
+    set(_boost_unprocessed_headers "${BOOST_DIR}/test/prg_exec_monitor.hpp")
+  # Single test header
+  elseif(component STREQUAL "test_exec_monitor")
+    set(library_component TRUE)
+    set(_boost_unprocessed_headers "${BOOST_DIR}/test/test_exec_monitor.hpp")
+  else()
+    # Default behaviour where header directory is the same as the library name.
+    file(GLOB_RECURSE _boost_unprocessed_headers
+         RELATIVE "${includedir}"
+         "${includedir}/boost/${component}/*")
+    list(INSERT _boost_unprocessed_headers 0 "${includedir}/boost/${component}.hpp")
+  endif()
+
+  while(_boost_unprocessed_headers)
+    list(APPEND _boost_processed_headers ${_boost_unprocessed_headers})
+    foreach(header ${_boost_unprocessed_headers})
+      if(EXISTS "${includedir}/${header}")
+        file(STRINGS "${includedir}/${header}" _boost_header_includes REGEX "^#[ \t]*include[ \t]*<boost/[^>][^>]*>")
+        # The optional whitespace before "#" is intentional
+        # (boost/serialization/config.hpp bug).
+        file(STRINGS "${includedir}/${header}" _boost_header_deps REGEX "^[ \t]*#[ \t]*define[ \t][ \t]*BOOST_LIB_NAME[ \t][ \t]*boost_")
+
+        foreach(line ${_boost_header_includes})
+          string(REGEX REPLACE "^#[ \t]*include[ \t]*<(boost/[^>][^>]*)>.*" "\\1" _boost_header_match "${line}")
+          list(FIND _boost_processed_headers "${_boost_header_match}" _boost_header_processed)
+          list(FIND _boost_new_headers "${_boost_header_match}" _boost_header_new)
+          if (_boost_header_processed EQUAL -1 AND _boost_header_new EQUAL -1)
+            list(APPEND _boost_new_headers ${_boost_header_match})
+          endif()
+        endforeach()
+
+        foreach(line ${_boost_header_deps})
+          string(REGEX REPLACE "^[ \t]*#[ \t]*define[ \t][ \t]*BOOST_LIB_NAME[ \t][ \t]*boost_([^ \t][^ \t]*).*" "\\1" _boost_component_match "${line}")
+          list(FIND _boost_DEPS "${_boost_component_match}" _boost_dep_found)
+          if(_boost_component_match STREQUAL "bzip2" OR
+             _boost_component_match STREQUAL "zlib")
+            # These components may or may not be required; not
+            # possible to tell without knowing where and when
+            # BOOST_BZIP2_BINARY and BOOST_ZLIB_BINARY are defined.
+            # If building against an external zlib or bzip2, this is
+            # undesirable.
+            continue()
+          endif()
+          if(component STREQUAL "mpi" AND
+             (_boost_component_match STREQUAL "mpi_python" OR
+              _boost_component_match STREQUAL "python"))
+            # Optional python dependency; skip to avoid making it a
+            # hard dependency (handle as special-case for mpi_python).
+            continue()
+          endif()
+          if (_boost_dep_found EQUAL -1 AND
+              NOT "${_boost_component_match}" STREQUAL "${component}")
+            list(APPEND _boost_DEPS "${_boost_component_match}")
+          endif()
+          if("${_boost_component_match}" STREQUAL "${component}")
+            set(library_component TRUE)
+          endif()
+        endforeach()
+      endif()
+    endforeach()
+    set(_boost_unprocessed_headers ${_boost_new_headers})
+    unset(_boost_new_headers)
+  endwhile()
+
+  # message(STATUS "Unfiltered dependencies for Boost::${component}: ${_boost_DEPS}")
+
+  if(NOT library_component)
+    unset(_boost_DEPS)
+  endif()
+  set(${_ret_libs} ${_boost_DEPS} PARENT_SCOPE)
+
+  #string(REGEX REPLACE ";" " " _boost_DEPS_STRING "${_boost_DEPS}")
+  #if (NOT _boost_DEPS_STRING)
+  #  set(_boost_DEPS_STRING "(none)")
+  #endif()
+  #message(STATUS "Dependencies for Boost::${component}: ${_boost_DEPS_STRING}")
+endfunction()
+
+
+message(STATUS "Scanning ${BOOST_DIR}")
+
+# List of all directories and files
+file(GLOB boost_contents RELATIVE "${BOOST_DIR}/boost" "${BOOST_DIR}/boost/*")
+
+# Components as directories
+foreach(component ${boost_contents})
+  if(IS_DIRECTORY "${BOOST_DIR}/boost/${component}")
+    list(APPEND boost_components "${component}")
+  endif()
+endforeach()
+
+# The following components are not top-level directories, so require
+# special-casing:
+
+# Special-case mpi_python, since it's a part of mpi
+if(IS_DIRECTORY "${BOOST_DIR}/boost/mpi" AND
+   IS_DIRECTORY "${BOOST_DIR}/boost/python")
+ list(APPEND boost_components "mpi_python")
+endif()
+# Special-case wserialization, which is a variant of serialization
+if(IS_DIRECTORY "${BOOST_DIR}/boost/serialization")
+ list(APPEND boost_components "wserialization")
+endif()
+# Special-case math* since there are six libraries, but no actual math
+# library component.  Handle specially when scanning above.
+#
+# Special-case separate test libraries, which are all part of test
+if(EXISTS "${BOOST_DIR}/test/unit_test.hpp")
+ list(APPEND boost_components "unit_test_framework")
+endif()
+if(EXISTS "${BOOST_DIR}/test/prg_exec_monitor.hpp")
+ list(APPEND boost_components "prg_exec_monitor")
+endif()
+if(EXISTS "${BOOST_DIR}/test/test_exec_monitor.hpp")
+ list(APPEND boost_components "test_exec_monitor")
+endif()
+
+if(boost_components)
+  list(SORT boost_components)
+endif()
+
+# Process each component defined above
+foreach(component ${boost_components})
+  string(TOUPPER ${component} UPPERCOMPONENT)
+  _Boost_FIND_COMPONENT_DEPENDENCIES("${component}" "${BOOST_DIR}"
+                                     _Boost_${UPPERCOMPONENT}_LIBRARY_DEPENDENCIES)
+endforeach()
+
+# Output results
+foreach(component ${boost_components})
+  string(TOUPPER ${component} UPPERCOMPONENT)
+  if(_Boost_${UPPERCOMPONENT}_LIBRARY_DEPENDENCIES)
+    string(REGEX REPLACE ";" " " _boost_DEPS_STRING "${_Boost_${UPPERCOMPONENT}_LIBRARY_DEPENDENCIES}")
+    message(STATUS "set(_Boost_${UPPERCOMPONENT}_DEPENDENCIES ${_boost_DEPS_STRING})")
+  endif()
+endforeach()
diff --git a/Utilities/Scripts/update-kwiml.bash b/Utilities/Scripts/update-kwiml.bash
new file mode 100755
index 0000000..5c0d192
--- /dev/null
+++ b/Utilities/Scripts/update-kwiml.bash
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+
+set -e
+set -x
+shopt -s dotglob
+
+readonly name="KWIML"
+readonly ownership="KWIML Upstream <kwrobot at kitware.com>"
+readonly subtree="Utilities/KWIML"
+readonly repo="https://github.com/Kitware/KWIML.git"
+readonly tag="master"
+readonly shortlog=true
+readonly paths="
+"
+
+extract_source () {
+    git_archive
+}
+
+. "${BASH_SOURCE%/*}/update-third-party.bash"
diff --git a/Utilities/Scripts/update-kwsys.bash b/Utilities/Scripts/update-kwsys.bash
new file mode 100755
index 0000000..650841f
--- /dev/null
+++ b/Utilities/Scripts/update-kwsys.bash
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+set -e
+set -x
+shopt -s dotglob
+
+readonly name="KWSys"
+readonly ownership="KWSys Upstream <kwrobot at kitware.com>"
+readonly subtree="Source/kwsys"
+readonly repo="http://public.kitware.com/KWSys.git"
+readonly tag="master"
+readonly shortlog=true
+readonly paths="
+"
+
+extract_source () {
+    git_archive
+}
+
+export HOOKS_ALLOW_KWSYS=1
+
+. "${BASH_SOURCE%/*}/update-third-party.bash"
diff --git a/Utilities/Scripts/update-third-party.bash b/Utilities/Scripts/update-third-party.bash
new file mode 100644
index 0000000..8925296
--- /dev/null
+++ b/Utilities/Scripts/update-third-party.bash
@@ -0,0 +1,146 @@
+########################################################################
+# Script for updating third party packages.
+#
+# This script should be sourced in a project-specific script which sets
+# the following variables:
+#
+#   name
+#       The name of the project.
+#   ownership
+#       A git author name/email for the commits.
+#   subtree
+#       The location of the thirdparty package within the main source
+#       tree.
+#   repo
+#       The git repository to use as upstream.
+#   tag
+#       The tag, branch or commit hash to use for upstream.
+#   shortlog
+#       Optional.  Set to 'true' to get a shortlog in the commit message.
+#
+# Additionally, an "extract_source" function must be defined. It will be
+# run within the checkout of the project on the requested tag. It should
+# should place the desired tree into $extractdir/$name-reduced. This
+# directory will be used as the newest commit for the project.
+#
+# For convenience, the function may use the "git_archive" function which
+# does a standard "git archive" extraction using the (optional) "paths"
+# variable to only extract a subset of the source tree.
+########################################################################
+
+########################################################################
+# Utility functions
+########################################################################
+git_archive () {
+    git archive --prefix="$name-reduced/" HEAD -- $paths | \
+        tar -C "$extractdir" -x
+}
+
+die () {
+    echo >&2 "$@"
+    exit 1
+}
+
+warn () {
+    echo >&2 "warning: $@"
+}
+
+readonly regex_date='20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]'
+readonly basehash_regex="$name $regex_date ([0-9a-f]*)"
+readonly basehash="$( git rev-list --author="$ownership" --grep="$basehash_regex" -n 1 HEAD )"
+readonly upstream_old_short="$( git cat-file commit "$basehash" | sed -n '/'"$basehash_regex"'/ {s/.*(//;s/)//;p}' | egrep '^[0-9a-f]+$' )"
+
+########################################################################
+# Sanity checking
+########################################################################
+[ -n "$name" ] || \
+    die "'name' is empty"
+[ -n "$ownership" ] || \
+    die "'ownership' is empty"
+[ -n "$subtree" ] || \
+    die "'subtree' is empty"
+[ -n "$repo" ] || \
+    die "'repo' is empty"
+[ -n "$tag" ] || \
+    die "'tag' is empty"
+[ -n "$basehash" ] || \
+    warn "'basehash' is empty; performing initial import"
+readonly do_shortlog="${shortlog-false}"
+
+readonly workdir="$PWD/work"
+readonly upstreamdir="$workdir/upstream"
+readonly extractdir="$workdir/extract"
+
+[ -d "$workdir" ] && \
+    die "error: workdir '$workdir' already exists"
+
+trap "rm -rf '$workdir'" EXIT
+
+# Get upstream
+git clone "$repo" "$upstreamdir"
+
+if [ -n "$basehash" ]; then
+    # Use the existing package's history
+    git worktree add "$extractdir" "$basehash"
+    # Clear out the working tree
+    pushd "$extractdir"
+    git ls-files | xargs rm -v
+    popd
+else
+    # Create a repo to hold this package's history
+    mkdir -p "$extractdir"
+    git -C "$extractdir" init
+fi
+
+# Extract the subset of upstream we care about
+pushd "$upstreamdir"
+git checkout "$tag"
+readonly upstream_hash="$( git rev-parse HEAD )"
+readonly upstream_hash_short="$( git rev-parse --short=8 "$upstream_hash" )"
+readonly upstream_datetime="$( git rev-list "$upstream_hash" --format='%ci' -n 1 | grep -e "^$regex_date" )"
+readonly upstream_date="$( echo "$upstream_datetime" | grep -o -e "$regex_date" )"
+if $do_shortlog && [ -n "$basehash" ]; then
+    readonly commit_shortlog="
+
+Upstream Shortlog
+-----------------
+
+$( git shortlog --no-merges --abbrev=8 --format='%h %s' "$upstream_old_short".."$upstream_hash" )"
+else
+    readonly commit_shortlog=""
+fi
+extract_source || \
+    die "failed to extract source"
+popd
+
+[ -d "$extractdir/$name-reduced" ] || \
+    die "expected directory to extract does not exist"
+readonly commit_summary="$name $upstream_date ($upstream_hash_short)"
+
+# Commit the subset
+pushd "$extractdir"
+mv -v "$name-reduced/"* .
+rmdir "$name-reduced/"
+git add -A .
+git commit -n --author="$ownership" --date="$upstream_datetime" -F - <<-EOF
+$commit_summary
+
+Code extracted from:
+
+    $repo
+
+at commit $upstream_hash ($tag).$commit_shortlog
+EOF
+git branch -f "upstream-$name"
+popd
+
+# Merge the subset into this repository
+if [ -n "$basehash" ]; then
+    git merge --log -s recursive "-Xsubtree=$subtree/" --no-commit "upstream-$name"
+else
+    git fetch "$extractdir" "upstream-$name:upstream-$name"
+    git merge --log -s ours --no-commit "upstream-$name"
+    git read-tree -u --prefix="$subtree/" "upstream-$name"
+fi
+git commit --no-edit
+git branch -d "upstream-$name"
diff --git a/Utilities/Sphinx/CMakeLists.txt b/Utilities/Sphinx/CMakeLists.txt
index 1baca35..257ba62 100644
--- a/Utilities/Sphinx/CMakeLists.txt
+++ b/Utilities/Sphinx/CMakeLists.txt
@@ -156,6 +156,14 @@ if(SPHINX_MAN)
     if("x${m}" MATCHES "^x(.+)\\.([1-9])\\.rst$")
       set(name "${CMAKE_MATCH_1}")
       set(sec "${CMAKE_MATCH_2}")
+      if(NOT CMakeHelp_STANDALONE)
+        if(name STREQUAL "ccmake" AND NOT BUILD_CursesDialog)
+          continue()
+        endif()
+        if(name STREQUAL "cmake-gui" AND NOT BUILD_QtDialog)
+          continue()
+        endif()
+      endif()
       CMake_OPTIONAL_COMPONENT(sphinx-man)
       install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/${name}.${sec}
               DESTINATION ${CMAKE_MAN_DIR}/man${sec}
diff --git a/Utilities/cmThirdParty.h.in b/Utilities/cmThirdParty.h.in
index 0cb6809..4c1177c 100644
--- a/Utilities/cmThirdParty.h.in
+++ b/Utilities/cmThirdParty.h.in
@@ -15,6 +15,7 @@
 /* Whether CMake is using its own utility libraries.  */
 #cmakedefine CMAKE_USE_SYSTEM_CURL
 #cmakedefine CMAKE_USE_SYSTEM_EXPAT
+#cmakedefine CMAKE_USE_SYSTEM_KWIML
 #cmakedefine CMAKE_USE_SYSTEM_ZLIB
 #cmakedefine CMAKE_USE_SYSTEM_BZIP2
 #cmakedefine CMAKE_USE_SYSTEM_LIBARCHIVE
diff --git a/Source/cmEnableTestingCommand.cxx b/Utilities/cm_kwiml.h
similarity index 54%
copy from Source/cmEnableTestingCommand.cxx
copy to Utilities/cm_kwiml.h
index aa41ef7..ab2b80b 100644
--- a/Source/cmEnableTestingCommand.cxx
+++ b/Utilities/cm_kwiml.h
@@ -1,6 +1,6 @@
 /*============================================================================
   CMake - Cross Platform Makefile Generator
-  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
+  Copyright 2000-2015 Kitware, Inc., Insight Software Consortium
 
   Distributed under the OSI-approved BSD License (the "License");
   see accompanying file Copyright.txt for details.
@@ -9,14 +9,17 @@
   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   See the License for more information.
 ============================================================================*/
-#include "cmEnableTestingCommand.h"
-#include "cmLocalGenerator.h"
+#ifndef cm_kwiml_h
+#define cm_kwiml_h
 
-// we do this in the final pass so that we now the subdirs have all
-// been defined
-bool cmEnableTestingCommand::InitialPass(std::vector<std::string> const&,
-                                         cmExecutionStatus &)
-{
-  this->Makefile->AddDefinition("CMAKE_TESTING_ENABLED","1");
-  return true;
-}
+/* Use the KWIML library configured for CMake.  */
+#include "cmThirdParty.h"
+#ifdef CMAKE_USE_SYSTEM_KWIML
+# include <kwiml/abi.h>
+# include <kwiml/int.h>
+#else
+# include "KWIML/include/kwiml/abi.h"
+# include "KWIML/include/kwiml/int.h"
+#endif
+
+#endif
diff --git a/Utilities/cmjsoncpp/CMakeLists.txt b/Utilities/cmjsoncpp/CMakeLists.txt
index 1c863f8..d0114e7 100644
--- a/Utilities/cmjsoncpp/CMakeLists.txt
+++ b/Utilities/cmjsoncpp/CMakeLists.txt
@@ -23,3 +23,4 @@ include_directories(
   )
 
 add_library(cmjsoncpp ${JSONCPP_SOURCES})
+target_link_libraries(cmjsoncpp ${CMake_KWIML_LIBRARIES})
diff --git a/Utilities/cmlibarchive/CMakeLists.txt b/Utilities/cmlibarchive/CMakeLists.txt
index b150408..00550e2 100644
--- a/Utilities/cmlibarchive/CMakeLists.txt
+++ b/Utilities/cmlibarchive/CMakeLists.txt
@@ -8,6 +8,9 @@ endif()
 # On MacOS, prefer MacPorts libraries to system libraries.
 # I haven't come up with a compelling argument for this to be conditional.
 list(APPEND CMAKE_PREFIX_PATH /opt/local)
+# Enable @rpath in the install name.
+# detail in "cmake  --help-policy CMP0042"
+SET(CMAKE_MACOSX_RPATH ON)
 
 #
 # Version - read from 'version' file.
@@ -71,9 +74,12 @@ OPTION(ENABLE_OPENSSL "Enable use of OpenSSL" ON)
 OPTION(ENABLE_LZMA "Enable the use of the system found LZMA library if found" ON)
 OPTION(ENABLE_ZLIB "Enable the use of the system found ZLIB library if found" ON)
 OPTION(ENABLE_BZip2 "Enable the use of the system found BZip2 library if found" ON)
+OPTION(ENABLE_LIBXML2 "Enable the use of the system found libxml2 library if found" ON)
 OPTION(ENABLE_EXPAT "Enable the use of the system found EXPAT library if found" ON)
 OPTION(ENABLE_PCREPOSIX "Enable the use of the system found PCREPOSIX library if found" ON)
 OPTION(ENABLE_LibGCC "Enable the use of the system found LibGCC library if found" ON)
+# CNG is used for encrypt/decrypt Zip archives on Windows.
+OPTION(ENABLE_CNG "Enable the use of CNG(Crypto Next Generation)" ON)
 
 OPTION(ENABLE_XATTR "Enable extended attribute support" ON)
 OPTION(ENABLE_ACL "Enable ACL support" ON)
@@ -88,6 +94,8 @@ IF(WIN32)
   SET(_WIN32_WINNT ${WINVER})
 ENDIF(WIN32)
 
+set(HAVE_PTHREAD_H 0) # no threads in CMake
+
 IF("${CMAKE_C_PLATFORM_ID}" MATCHES "^(HP-UX)$")
   ADD_DEFINITIONS(-D_XOPEN_SOURCE=500) # Ask wchar.h for mbstate_t
 ENDIF()
@@ -273,6 +281,8 @@ IF(BZIP2_FOUND)
 ENDIF(BZIP2_FOUND)
 MARK_AS_ADVANCED(CLEAR BZIP2_INCLUDE_DIR)
 MARK_AS_ADVANCED(CLEAR BZIP2_LIBRARIES)
+
+
 #
 # Find LZMA
 #
@@ -335,6 +345,35 @@ ENDIF(LZO2_FOUND)
 MARK_AS_ADVANCED(CLEAR LZO2_INCLUDE_DIR)
 MARK_AS_ADVANCED(CLEAR LZO2_LIBRARY)
 ENDIF()
+IF(0) # CMake does not need LZ4 support in libarchive
+#
+# Find LZ4
+#
+IF (LZ4_INCLUDE_DIR)
+  # Already in cache, be silent
+  SET(LZ4_FIND_QUIETLY TRUE)
+ENDIF (LZ4_INCLUDE_DIR)
+
+FIND_PATH(LZ4_INCLUDE_DIR lz4.h)
+FIND_LIBRARY(LZ4_LIBRARY NAMES lz4 liblz4)
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZ4 DEFAULT_MSG LZ4_LIBRARY LZ4_INCLUDE_DIR)
+IF(LZ4_FOUND)
+  SET(HAVE_LIBLZ4 1)
+  SET(HAVE_LZ4_H 1)
+  CMAKE_PUSH_CHECK_STATE()	# Save the state of the variables
+  SET(CMAKE_REQUIRED_INCLUDES ${LZ4_INCLUDE_DIR})
+  CHECK_INCLUDE_FILES("lz4hc.h" HAVE_LZ4HC_H)
+  CMAKE_POP_CHECK_STATE()	# Restore the state of the variables
+  INCLUDE_DIRECTORIES(${LZ4_INCLUDE_DIR})
+  LIST(APPEND ADDITIONAL_LIBS ${LZ4_LIBRARY})
+  #
+  # TODO: test for static library.
+  #
+ENDIF(LZ4_FOUND)
+MARK_AS_ADVANCED(CLEAR LZ4_INCLUDE_DIR)
+MARK_AS_ADVANCED(CLEAR LZ4_LIBRARY)
+ENDIF()
 
 #
 # Check headers
@@ -384,7 +423,9 @@ LA_CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H)
 LA_CHECK_INCLUDE_FILE("paths.h" HAVE_PATHS_H)
 LA_CHECK_INCLUDE_FILE("poll.h" HAVE_POLL_H)
 LA_CHECK_INCLUDE_FILE("process.h" HAVE_PROCESS_H)
+LA_CHECK_INCLUDE_FILE("pthread.h" HAVE_PTHREAD_H)
 LA_CHECK_INCLUDE_FILE("pwd.h" HAVE_PWD_H)
+LA_CHECK_INCLUDE_FILE("readpassphrase.h" HAVE_READPASSPHRASE_H)
 LA_CHECK_INCLUDE_FILE("regex.h" HAVE_REGEX_H)
 LA_CHECK_INCLUDE_FILE("signal.h" HAVE_SIGNAL_H)
 LA_CHECK_INCLUDE_FILE("spawn.h" HAVE_SPAWN_H)
@@ -415,6 +456,11 @@ LA_CHECK_INCLUDE_FILE("utime.h" HAVE_UTIME_H)
 LA_CHECK_INCLUDE_FILE("wchar.h" HAVE_WCHAR_H)
 LA_CHECK_INCLUDE_FILE("wctype.h" HAVE_WCTYPE_H)
 LA_CHECK_INCLUDE_FILE("windows.h" HAVE_WINDOWS_H)
+IF(ENABLE_CNG)
+  LA_CHECK_INCLUDE_FILE("Bcrypt.h" HAVE_BCRYPT_H)
+ELSE(ENABLE_CNG)
+  UNSET(HAVE_BCRYPT_H CACHE)
+ENDIF(ENABLE_CNG)
 # Following files need windwos.h, so we should test it after windows.h test.
 LA_CHECK_INCLUDE_FILE("wincrypt.h" HAVE_WINCRYPT_H)
 LA_CHECK_INCLUDE_FILE("winioctl.h" HAVE_WINIOCTL_H)
@@ -446,6 +492,7 @@ IF(ENABLE_NETTLE)
     SET(HAVE_NETTLE_SHA_H 1)
     INCLUDE_DIRECTORIES(${NETTLE_INCLUDE_DIR})
     LIST(APPEND ADDITIONAL_LIBS ${NETTLE_LIBRARIES})
+    LA_CHECK_INCLUDE_FILE("nettle/pbkdf2.h" HAVE_NETTLE_PBKDF2_H)
   ENDIF(NETTLE_FOUND)
   MARK_AS_ADVANCED(CLEAR NETTLE_INCLUDE_DIR)
   MARK_AS_ADVANCED(CLEAR NETTLE_LIBRARIES)
@@ -457,6 +504,9 @@ ENDIF(ENABLE_NETTLE)
 #
 IF(ENABLE_OPENSSL AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
   FIND_PACKAGE(OpenSSL)
+  IF(OPENSSL_FOUND)
+    SET(HAVE_LIBCRYPTO 1)
+  ENDIF(OPENSSL_FOUND)
 ELSE()
   SET(OPENSSL_FOUND FALSE) # Override cached value
 ENDIF()
@@ -475,7 +525,7 @@ ENDIF(NOT OPENSSL_FOUND)
 
 #
 # How to prove that CRYPTO functions, which have several names on various
-# platforms, just see if archive_crypto.c can compile and link against
+# platforms, just see if archive_digest.c can compile and link against
 # required libraries.
 #
 MACRO(CHECK_CRYPTO ALGORITHMS IMPLEMENTATION)
@@ -514,7 +564,7 @@ MACRO(CHECK_CRYPTO ALGORITHMS IMPLEMENTATION)
       ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/confdefs.h)
 	FILE(READ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/confdefs.h"
 	     CONFDEFS_H)
-	FILE(READ "${CMAKE_CURRENT_SOURCE_DIR}/libarchive/archive_crypto.c"
+	FILE(READ "${CMAKE_CURRENT_SOURCE_DIR}/libarchive/archive_digest.c"
 	     ARCHIVE_CRYPTO_C)
 
 	SET(SOURCE "${CONFDEFS_H}
@@ -664,14 +714,15 @@ ENDMACRO(CHECK_CRYPTO_WIN CRYPTO_LIST)
 MACRO(CHECK_ICONV LIB TRY_ICONV_CONST)
   IF(NOT HAVE_ICONV)
     CMAKE_PUSH_CHECK_STATE()	# Save the state of the variables
-    IF (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+    IF (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
+        CMAKE_C_COMPILER_ID STREQUAL "Clang")
       #
       # During checking iconv proto type, we should use -Werror to avoid the
       # success of iconv detection with a warnig which success is a miss
       # detection. So this needs for all build mode(even it's a release mode).
       #
       SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror")
-    ENDIF (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+    ENDIF ()
     IF (MSVC)
       # NOTE: /WX option is the same as gcc's -Werror option.
       SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} /WX")
@@ -795,7 +846,11 @@ IF(0) # CMake does not need XML support in libarchive
 #
 # Find Libxml2
 #
-FIND_PACKAGE(LibXml2)
+IF(ENABLE_LIBXML2)
+  FIND_PACKAGE(LibXml2)
+ELSE()
+  SET(LIBXML2_FOUND FALSE)
+ENDIF()
 IF(LIBXML2_FOUND)
   CMAKE_PUSH_CHECK_STATE()	# Save the state of the variables
   INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
@@ -820,7 +875,11 @@ ELSE(LIBXML2_FOUND)
   #
   # Find Expat
   #
-  FIND_PACKAGE(EXPAT)
+  IF(ENABLE_EXPAT)
+    FIND_PACKAGE(EXPAT)
+  ELSE()
+    SET(EXPAT_FOUND FALSE)
+  ENDIF()
   IF(EXPAT_FOUND)
     CMAKE_PUSH_CHECK_STATE()	# Save the state of the variables
     INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR})
@@ -838,7 +897,8 @@ ENDIF()
 # Check functions
 #
 CMAKE_PUSH_CHECK_STATE()	# Save the state of the variables
-IF (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+IF (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
+    CMAKE_C_COMPILER_ID STREQUAL "Clang")
   #
   # During checking functions, we should use -fno-builtin to avoid the
   # failure of function detection which failure is an error "conflicting
@@ -847,6 +907,7 @@ IF (CMAKE_C_COMPILER_ID STREQUAL "GNU")
   SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-builtin")
 ENDIF ()
 CHECK_SYMBOL_EXISTS(_CrtSetReportMode "crtdbg.h" HAVE__CrtSetReportMode)
+CHECK_FUNCTION_EXISTS_GLIBC(arc4random_buf HAVE_ARC4RANDOM_BUF)
 CHECK_FUNCTION_EXISTS_GLIBC(chflags HAVE_CHFLAGS)
 CHECK_FUNCTION_EXISTS_GLIBC(chown HAVE_CHOWN)
 CHECK_FUNCTION_EXISTS_GLIBC(chroot HAVE_CHROOT)
@@ -894,6 +955,7 @@ CHECK_FUNCTION_EXISTS_GLIBC(pipe HAVE_PIPE)
 CHECK_FUNCTION_EXISTS_GLIBC(poll HAVE_POLL)
 CHECK_FUNCTION_EXISTS_GLIBC(posix_spawnp HAVE_POSIX_SPAWNP)
 CHECK_FUNCTION_EXISTS_GLIBC(readlink HAVE_READLINK)
+CHECK_FUNCTION_EXISTS_GLIBC(readpassphrase HAVE_READPASSPHRASE)
 CHECK_FUNCTION_EXISTS_GLIBC(select HAVE_SELECT)
 CHECK_FUNCTION_EXISTS_GLIBC(setenv HAVE_SETENV)
 CHECK_FUNCTION_EXISTS_GLIBC(setlocale HAVE_SETLOCALE)
@@ -932,6 +994,7 @@ CHECK_FUNCTION_EXISTS(strftime HAVE_STRFTIME)
 CHECK_FUNCTION_EXISTS(vprintf HAVE_VPRINTF)
 CHECK_FUNCTION_EXISTS(wmemcmp HAVE_WMEMCMP)
 CHECK_FUNCTION_EXISTS(wmemcpy HAVE_WMEMCPY)
+CHECK_FUNCTION_EXISTS(wmemmove HAVE_WMEMMOVE)
 
 CMAKE_POP_CHECK_STATE()	# Restore the state of the variables
 
diff --git a/Utilities/cmlibarchive/COPYING b/Utilities/cmlibarchive/COPYING
index b258806..93952b7 100644
--- a/Utilities/cmlibarchive/COPYING
+++ b/Utilities/cmlibarchive/COPYING
@@ -17,12 +17,11 @@ the actual statements in the files are controlling.
   files for details:
    libarchive/archive_entry.c
    libarchive/archive_read_support_filter_compress.c
-   libarchive/archive_write_set_filter_compress.c
+   libarchive/archive_write_add_filter_compress.c
    libarchive/mtree.5
-   tar/matching.c
 
 * The following source files are in the public domain:
-   tar/getdate.c
+   libarchive/archive_getdate.c
 
 * The build files---including Makefiles, configure scripts,
   and auxiliary scripts used as part of the compile process---have
diff --git a/Utilities/cmlibarchive/README-CMake.txt b/Utilities/cmlibarchive/README-CMake.txt
index 8f3b29b..0a3e34a 100644
--- a/Utilities/cmlibarchive/README-CMake.txt
+++ b/Utilities/cmlibarchive/README-CMake.txt
@@ -11,7 +11,7 @@ branch, but it is merged into our history.
 Update libarchive from upstream as follows.  Create a local branch to
 explicitly reference the upstream snapshot branch head:
 
- git branch libarchive-upstream 37f225b7
+ git branch libarchive-upstream 1a8c7bc2
 
 Use a temporary directory to checkout the branch:
 
@@ -24,7 +24,7 @@ Use a temporary directory to checkout the branch:
 Now place the (reduced) libarchive content in this directory.  See
 instructions shown by
 
- git log 37f225b7
+ git log 1a8c7bc2
 
 for help extracting the content from the upstream svn repo.  Then run
 the following commands to commit the new version.  Substitute the
@@ -34,8 +34,8 @@ appropriate date and version number:
 
  GIT_AUTHOR_NAME='LibArchive Upstream' \
  GIT_AUTHOR_EMAIL='libarchive-discuss at googlegroups.com' \
- GIT_AUTHOR_DATE='Mon Apr 14 19:19:05 2014 -0700' \
- git commit -m 'libarchive 3.1.2-246-ga5a5d28b (reduced)' &&
+ GIT_AUTHOR_DATE='Wed Oct 21 01:47:34 2015 -0700' \
+ git commit -m 'libarchive 3.1.2-601-g3bfe5f1 (reduced)' &&
  git commit --amend
 
 Edit the commit message to describe the procedure used to obtain the
diff --git a/Utilities/cmlibarchive/build/cmake/CreatePkgConfigFile.cmake b/Utilities/cmlibarchive/build/cmake/CreatePkgConfigFile.cmake
index f96bbef..fc8529a 100644
--- a/Utilities/cmlibarchive/build/cmake/CreatePkgConfigFile.cmake
+++ b/Utilities/cmlibarchive/build/cmake/CreatePkgConfigFile.cmake
@@ -27,5 +27,7 @@ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build/pkgconfig/libarchive.pc.in
 		${CMAKE_CURRENT_SOURCE_DIR}/build/pkgconfig/libarchive.pc
 		@ONLY)
 # And install it, of course ;).
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/build/pkgconfig/libarchive.pc
-	DESTINATION "lib/pkgconfig")
+IF(ENABLE_INSTALL)
+  INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/build/pkgconfig/libarchive.pc
+          DESTINATION "lib/pkgconfig")
+ENDIF()
diff --git a/Utilities/cmlibarchive/build/cmake/config.h.in b/Utilities/cmlibarchive/build/cmake/config.h.in
index 32a29d0..1abeaaa 100644
--- a/Utilities/cmlibarchive/build/cmake/config.h.in
+++ b/Utilities/cmlibarchive/build/cmake/config.h.in
@@ -66,7 +66,7 @@ typedef long long int64_t;
  * Similarly for int32_t
  */
 #if !defined(HAVE_INT32_T) && SIZE_OF_INT == 4
-typedef long int32_t;
+typedef int int32_t;
 #define HAVE_INT32_T
 #endif
 
@@ -331,9 +331,15 @@ typedef uint64_t uintmax_t;
 /* True for systems with POSIX ACL support */
 #cmakedefine HAVE_ACL_USER 1
 
+/* Define to 1 if you have the `arc4random_buf' function. */
+#cmakedefine HAVE_ARC4RANDOM_BUF 1
+
 /* Define to 1 if you have the <attr/xattr.h> header file. */
 #cmakedefine HAVE_ATTR_XATTR_H 1
 
+/* Define to 1 if you have the <Bcrypt.h> header file. */
+#cmakedefine HAVE_BCRYPT_H 1
+
 /* Define to 1 if you have the <bsdxml.h> header file. */
 #cmakedefine HAVE_BSDXML_H 1
 
@@ -582,12 +588,21 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the `bz2' library (-lbz2). */
 #cmakedefine HAVE_LIBBZ2 1
 
+/* Define to 1 if you have the `charset' library (-lcharset). */
+#cmakedefine HAVE_LIBCHARSET 1
+
+/* Define to 1 if you have the `crypto' library (-lcrypto). */
+#cmakedefine HAVE_LIBCRYPTO 1
+
 /* Define to 1 if you have the `expat' library (-lexpat). */
 #cmakedefine HAVE_LIBEXPAT 1
 
 /* Define to 1 if you have the `gcc' library (-lgcc). */
 #cmakedefine HAVE_LIBGCC 1
 
+/* Define to 1 if you have the `lz4' library (-llz4). */
+#cmakedefine HAVE_LIBLZ4 1
+
 /* Define to 1 if you have the `lzma' library (-llzma). */
 #cmakedefine HAVE_LIBLZMA 1
 
@@ -682,6 +697,12 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the `lutimes' function. */
 #cmakedefine HAVE_LUTIMES 1
 
+/* Define to 1 if you have the <lz4hc.h> header file. */
+#cmakedefine HAVE_LZ4HC_H 1
+
+/* Define to 1 if you have the <lz4.h> header file. */
+#cmakedefine HAVE_LZ4_H 1
+
 /* Define to 1 if you have the <lzmadec.h> header file. */
 #cmakedefine HAVE_LZMADEC_H 1
 
@@ -721,6 +742,9 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the <nettle/md5.h> header file. */
 #cmakedefine HAVE_NETTLE_MD5_H 1
 
+/* Define to 1 if you have the <nettle/pbkdf2.h> header file. */
+#cmakedefine HAVE_NETTLE_PBKDF2_H 1
+
 /* Define to 1 if you have the <nettle/ripemd160.h> header file. */
 #cmakedefine HAVE_NETTLE_RIPEMD160_H 1
 
@@ -742,6 +766,9 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the `pipe' function. */
 #cmakedefine HAVE_PIPE 1
 
+/* Define to 1 if you have the `PKCS5_PBKDF2_HMAC_SHA1' function. */
+#cmakedefine HAVE_PKCS5_PBKDF2_HMAC_SHA1 1
+
 /* Define to 1 if you have the `poll' function. */
 #cmakedefine HAVE_POLL 1
 
@@ -754,6 +781,9 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the <process.h> header file. */
 #cmakedefine HAVE_PROCESS_H 1
 
+/* Define to 1 if you have the <pthread.h> header file. */
+#cmakedefine HAVE_PTHREAD_H 1
+
 /* Define to 1 if you have the <pwd.h> header file. */
 #cmakedefine HAVE_PWD_H 1
 
@@ -766,6 +796,12 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the `readlinkat' function. */
 #cmakedefine HAVE_READLINKAT 1
 
+/* Define to 1 if you have the `readpassphrase' function. */
+#cmakedefine HAVE_READPASSPHRASE 1
+
+/* Define to 1 if you have the <readpassphrase.h> header file. */
+#cmakedefine HAVE_READPASSPHRASE_H 1
+
 /* Define to 1 if you have the <regex.h> header file. */
 #cmakedefine HAVE_REGEX_H 1
 
@@ -1021,6 +1057,9 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the `wmemcpy' function. */
 #cmakedefine HAVE_WMEMCPY 1
 
+/* Define to 1 if you have the `wmemmove' function. */
+#cmakedefine HAVE_WMEMMOVE 1
+
 /* Define to 1 if you have a working EXT2_IOC_GETFLAGS */
 #cmakedefine HAVE_WORKING_EXT2_IOC_GETFLAGS 1
 
diff --git a/Utilities/cmlibarchive/libarchive/CMakeLists.txt b/Utilities/cmlibarchive/libarchive/CMakeLists.txt
index 8908a62..891c728 100644
--- a/Utilities/cmlibarchive/libarchive/CMakeLists.txt
+++ b/Utilities/cmlibarchive/libarchive/CMakeLists.txt
@@ -18,8 +18,10 @@ SET(libarchive_SOURCES
   archive_cmdline.c
   archive_cmdline_private.h
   archive_crc32.h
-  archive_crypto.c
-  archive_crypto_private.h
+  archive_cryptor.c
+  archive_cryptor_private.h
+  archive_digest.c
+  archive_digest_private.h
   archive_endian.h
   archive_entry.c
   archive_entry.h
@@ -32,6 +34,8 @@ SET(libarchive_SOURCES
   archive_entry_strmode.c
   archive_entry_xattr.c
   archive_getdate.c
+  archive_hmac.c
+  archive_hmac_private.h
   archive_match.c
   archive_options.c
   archive_options_private.h
@@ -44,9 +48,12 @@ SET(libarchive_SOURCES
   archive_ppmd7.c
   archive_ppmd7_private.h
   archive_private.h
+  archive_random.c
+  archive_random_private.h
   archive_rb.c
   archive_rb.h
   archive_read.c
+  archive_read_add_passphrase.c
   archive_read_append_filter.c
   archive_read_data_into_fd.c
   archive_read_disk_entry_from_file.c
@@ -68,6 +75,7 @@ SET(libarchive_SOURCES
   archive_read_support_filter_gzip.c
   archive_read_support_filter_grzip.c
   archive_read_support_filter_lrzip.c
+  archive_read_support_filter_lz4.c
   archive_read_support_filter_lzop.c
   archive_read_support_filter_none.c
   archive_read_support_filter_program.c
@@ -87,6 +95,7 @@ SET(libarchive_SOURCES
   archive_read_support_format_rar.c
   archive_read_support_format_raw.c
   archive_read_support_format_tar.c
+  archive_read_support_format_warc.c
   archive_read_support_format_xar.c
   archive_read_support_format_zip.c
   archive_string.c
@@ -113,6 +122,7 @@ SET(libarchive_SOURCES
   archive_write_add_filter_grzip.c
   archive_write_add_filter_gzip.c
   archive_write_add_filter_lrzip.c
+  archive_write_add_filter_lz4.c
   archive_write_add_filter_lzop.c
   archive_write_add_filter_none.c
   archive_write_add_filter_program.c
@@ -124,6 +134,7 @@ SET(libarchive_SOURCES
   archive_write_set_format_by_name.c
   archive_write_set_format_cpio.c
   archive_write_set_format_cpio_newc.c
+  archive_write_set_format_filter_by_ext.c
   archive_write_set_format_gnutar.c
   archive_write_set_format_iso9660.c
   archive_write_set_format_mtree.c
@@ -132,11 +143,15 @@ SET(libarchive_SOURCES
   archive_write_set_format_shar.c
   archive_write_set_format_ustar.c
   archive_write_set_format_v7tar.c
+  archive_write_set_format_warc.c
   archive_write_set_format_xar.c
   archive_write_set_format_zip.c
   archive_write_set_options.c
+  archive_write_set_passphrase.c
+  archive_xxhash.h
   filter_fork_posix.c
   filter_fork.h
+  xxhash.c
 )
 
 # Man pages
@@ -149,12 +164,14 @@ SET(libarchive_MANS
   archive_entry_stat.3
   archive_entry_time.3
   archive_read.3
+  archive_read_add_passphrase.3
   archive_read_disk.3
   archive_read_set_options.3
   archive_util.3
   archive_write.3
   archive_write_disk.3
   archive_write_set_options.3
+  archive_write_set_passphrase.3
   cpio.5
   libarchive.3
   libarchive_internals.3
diff --git a/Utilities/cmlibarchive/libarchive/archive.h b/Utilities/cmlibarchive/libarchive/archive.h
index 9cf762d..a8d4c6c 100644
--- a/Utilities/cmlibarchive/libarchive/archive.h
+++ b/Utilities/cmlibarchive/libarchive/archive.h
@@ -28,6 +28,16 @@
 #ifndef ARCHIVE_H_INCLUDED
 #define	ARCHIVE_H_INCLUDED
 
+/*
+ * The version number is expressed as a single integer that makes it
+ * easy to compare versions at build time: for version a.b.c, the
+ * version number is printf("%d%03d%03d",a,b,c).  For example, if you
+ * know your application requires version 2.12.108 or later, you can
+ * assert that ARCHIVE_VERSION_NUMBER >= 2012108.
+ */
+/* Note: Compiler will complain if this does not match archive_entry.h! */
+#define	ARCHIVE_VERSION_NUMBER 3001002
+
 #include <sys/stat.h>
 #include <stddef.h>  /* for wchar_t */
 #include <stdio.h> /* For FILE * */
@@ -45,32 +55,44 @@
 # include <inttypes.h>
 #endif
 
-/* Borland symbols are case-insensitive.  This workaround only works
-   within CMake because we do not mix compilers.  */
-#if defined(__BORLANDC__)
-# define archive_read_open_FILE archive_read_open_FILE_
-# define archive_write_open_FILE archive_write_open_FILE_
+/* Get appropriate definitions of 64-bit integer */
+#if !defined(__LA_INT64_T_DEFINED)
+/* Older code relied on the __LA_INT64_T macro; after 4.0 we'll switch to the typedef exclusively. */
+# if ARCHIVE_VERSION_NUMBER < 4000000
+#define __LA_INT64_T la_int64_t
+# endif
+#define __LA_INT64_T_DEFINED
+# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
+typedef __int64 la_int64_t;
+# else
+# include <unistd.h>  /* ssize_t */
+#  if defined(_SCO_DS) || defined(__osf__)
+typedef long long la_int64_t;
+#  else
+typedef int64_t la_int64_t;
+#  endif
+# endif
 #endif
 
-/* Get appropriate definitions of standard POSIX-style types. */
-/* These should match the types used in 'struct stat' */
-#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
-# define	__LA_INT64_T	__int64
-# if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_)
-#  define	__LA_SSIZE_T	ssize_t
-# elif defined(_WIN64)
-#  define	__LA_SSIZE_T	__int64
-# else
-#  define	__LA_SSIZE_T	long
+/* The la_ssize_t should match the type used in 'struct stat' */
+#if !defined(__LA_SSIZE_T_DEFINED)
+/* Older code relied on the __LA_SSIZE_T macro; after 4.0 we'll switch to the typedef exclusively. */
+# if ARCHIVE_VERSION_NUMBER < 4000000
+#define __LA_SSIZE_T la_ssize_t
 # endif
-#else
-# include <unistd.h>  /* ssize_t, uid_t, and gid_t */
-# if defined(_SCO_DS) || defined(__osf__)
-#  define	__LA_INT64_T	long long
+#define __LA_SSIZE_T_DEFINED
+# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
+#  if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_)
+typedef ssize_t la_ssize_t;
+#  elif defined(_WIN64)
+typedef __int64 la_ssize_t;
+#  else
+typedef long la_ssize_t;
+#  endif
 # else
-#  define	__LA_INT64_T	int64_t
+# include <unistd.h>  /* ssize_t */
+typedef ssize_t la_ssize_t;
 # endif
-# define	__LA_SSIZE_T	ssize_t
 #endif
 
 /*
@@ -119,26 +141,21 @@ extern "C" {
  * header and library are very different, you should expect some
  * strangeness.  Don't do that.
  */
-
-/*
- * The version number is expressed as a single integer that makes it
- * easy to compare versions at build time: for version a.b.c, the
- * version number is printf("%d%03d%03d",a,b,c).  For example, if you
- * know your application requires version 2.12.108 or later, you can
- * assert that ARCHIVE_VERSION_NUMBER >= 2012108.
- */
-/* Note: Compiler will complain if this does not match archive_entry.h! */
-#define	ARCHIVE_VERSION_NUMBER 3001002
 __LA_DECL int		archive_version_number(void);
 
 /*
  * Textual name/version of the library, useful for version displays.
  */
-#define	ARCHIVE_VERSION_STRING "libarchive 3.1.2"
+#define	ARCHIVE_VERSION_ONLY_STRING "3.1.2"
+#define	ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING
 __LA_DECL const char *	archive_version_string(void);
 
 /*
  * Detailed textual name/version of the library and its dependencies.
+ * This has the form:
+ *    "libarchive x.y.z zlib/a.b.c liblzma/d.e.f ... etc ..."
+ * the list of libraries described here will vary depending on how
+ * libarchive was compiled.
  */
 __LA_DECL const char *	archive_version_details(void);
 
@@ -182,7 +199,7 @@ struct archive_entry;
  */
 
 /* Returns pointer and size of next block of data from archive. */
-typedef __LA_SSIZE_T	archive_read_callback(struct archive *,
+typedef la_ssize_t	archive_read_callback(struct archive *,
 			    void *_client_data, const void **_buffer);
 
 /* Skips at most request bytes from archive and returns the skipped amount.
@@ -190,18 +207,18 @@ typedef __LA_SSIZE_T	archive_read_callback(struct archive *,
  * If you do skip fewer bytes than requested, libarchive will invoke your
  * read callback and discard data as necessary to make up the full skip.
  */
-typedef __LA_INT64_T	archive_skip_callback(struct archive *,
-			    void *_client_data, __LA_INT64_T request);
+typedef la_int64_t	archive_skip_callback(struct archive *,
+			    void *_client_data, la_int64_t request);
 
 /* Seeks to specified location in the file and returns the position.
  * Whence values are SEEK_SET, SEEK_CUR, SEEK_END from stdio.h.
  * Return ARCHIVE_FATAL if the seek fails for any reason.
  */
-typedef __LA_INT64_T	archive_seek_callback(struct archive *,
-    void *_client_data, __LA_INT64_T offset, int whence);
+typedef la_int64_t	archive_seek_callback(struct archive *,
+    void *_client_data, la_int64_t offset, int whence);
 
 /* Returns size actually written, zero on EOF, -1 on error. */
-typedef __LA_SSIZE_T	archive_write_callback(struct archive *,
+typedef la_ssize_t	archive_write_callback(struct archive *,
 			    void *_client_data,
 			    const void *_buffer, size_t _length);
 
@@ -217,6 +234,13 @@ typedef int archive_switch_callback(struct archive *, void *_client_data1,
 			    void *_client_data2);
 
 /*
+ * Returns a passphrase used for encryption or decryption, NULL on nothing
+ * to do and give it up.
+ */
+typedef const char *archive_passphrase_callback(struct archive *,
+			    void *_client_data);
+
+/*
  * Codes to identify various stream filters.
  */
 #define	ARCHIVE_FILTER_NONE	0
@@ -232,6 +256,7 @@ typedef int archive_switch_callback(struct archive *, void *_client_data1,
 #define	ARCHIVE_FILTER_LRZIP	10
 #define	ARCHIVE_FILTER_LZOP	11
 #define	ARCHIVE_FILTER_GRZIP	12
+#define	ARCHIVE_FILTER_LZ4	13
 
 #if ARCHIVE_VERSION_NUMBER < 4000000
 #define	ARCHIVE_COMPRESSION_NONE	ARCHIVE_FILTER_NONE
@@ -293,6 +318,7 @@ typedef int archive_switch_callback(struct archive *, void *_client_data1,
 #define	ARCHIVE_FORMAT_CAB			0xC0000
 #define	ARCHIVE_FORMAT_RAR			0xD0000
 #define	ARCHIVE_FORMAT_7ZIP			0xE0000
+#define	ARCHIVE_FORMAT_WARC			0xF0000
 
 /*
  * Codes returned by archive_read_format_capabilities().
@@ -375,6 +401,7 @@ __LA_DECL int archive_read_support_filter_compress(struct archive *);
 __LA_DECL int archive_read_support_filter_gzip(struct archive *);
 __LA_DECL int archive_read_support_filter_grzip(struct archive *);
 __LA_DECL int archive_read_support_filter_lrzip(struct archive *);
+__LA_DECL int archive_read_support_filter_lz4(struct archive *);
 __LA_DECL int archive_read_support_filter_lzip(struct archive *);
 __LA_DECL int archive_read_support_filter_lzma(struct archive *);
 __LA_DECL int archive_read_support_filter_lzop(struct archive *);
@@ -402,6 +429,7 @@ __LA_DECL int archive_read_support_format_mtree(struct archive *);
 __LA_DECL int archive_read_support_format_rar(struct archive *);
 __LA_DECL int archive_read_support_format_raw(struct archive *);
 __LA_DECL int archive_read_support_format_tar(struct archive *);
+__LA_DECL int archive_read_support_format_warc(struct archive *);
 __LA_DECL int archive_read_support_format_xar(struct archive *);
 /* archive_read_support_format_zip() enables both streamable and seekable
  * zip readers. */
@@ -482,9 +510,9 @@ __LA_DECL int archive_read_open_file(struct archive *,
 		     const char *_filename, size_t _block_size) __LA_DEPRECATED;
 /* Read an archive that's stored in memory. */
 __LA_DECL int archive_read_open_memory(struct archive *,
-		     void * buff, size_t size);
+		     const void * buff, size_t size);
 /* A more involved version that is only used for internal testing. */
-__LA_DECL int archive_read_open_memory2(struct archive *a, void *buff,
+__LA_DECL int archive_read_open_memory2(struct archive *a, const void *buff,
 		     size_t size, size_t read_size);
 /* Read an archive that's already open, using the file descriptor. */
 __LA_DECL int archive_read_open_fd(struct archive *, int _fd,
@@ -505,7 +533,7 @@ __LA_DECL int archive_read_next_header2(struct archive *,
  * Retrieve the byte offset in UNCOMPRESSED data where last-read
  * header started.
  */
-__LA_DECL __LA_INT64_T		 archive_read_header_position(struct archive *);
+__LA_DECL la_int64_t		 archive_read_header_position(struct archive *);
 
 /*
  * Returns 1 if the archive contains at least one encrypted entry.
@@ -534,11 +562,11 @@ __LA_DECL int	archive_read_has_encrypted_entries(struct archive *);
 __LA_DECL int		 archive_read_format_capabilities(struct archive *);
 
 /* Read data from the body of an entry.  Similar to read(2). */
-__LA_DECL __LA_SSIZE_T		 archive_read_data(struct archive *,
+__LA_DECL la_ssize_t		 archive_read_data(struct archive *,
 				    void *, size_t);
 
 /* Seek within the body of an entry.  Similar to lseek(2). */
-__LA_DECL __LA_INT64_T archive_seek_data(struct archive *, __LA_INT64_T, int);
+__LA_DECL la_int64_t archive_seek_data(struct archive *, la_int64_t, int);
 
 /*
  * A zero-copy version of archive_read_data that also exposes the file offset
@@ -547,7 +575,7 @@ __LA_DECL __LA_INT64_T archive_seek_data(struct archive *, __LA_INT64_T, int);
  * be strictly increasing and that returned blocks will not overlap.
  */
 __LA_DECL int archive_read_data_block(struct archive *a,
-		    const void **buff, size_t *size, __LA_INT64_T *offset);
+		    const void **buff, size_t *size, la_int64_t *offset);
 
 /*-
  * Some convenience functions that are built on archive_read_data:
@@ -577,6 +605,14 @@ __LA_DECL int archive_read_set_option(struct archive *_a,
 __LA_DECL int archive_read_set_options(struct archive *_a,
 			    const char *opts);
 
+/*
+ * Add a decryption passphrase.
+ */
+__LA_DECL int archive_read_add_passphrase(struct archive *, const char *);
+__LA_DECL int archive_read_set_passphrase_callback(struct archive *,
+			    void *client_data, archive_passphrase_callback *);
+
+
 /*-
  * Convenience function to recreate the current entry (whose header
  * has just been read) on disk.
@@ -629,6 +665,10 @@ __LA_DECL int archive_read_set_options(struct archive *_a,
 /* Default: Do not use HFS+ compression if it was not compressed. */
 /* This has no effect except on Mac OS v10.6 or later. */
 #define	ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED	(0x8000)
+/* Default: Do not reject entries with absolute paths */
+#define ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS (0x10000)
+/* Default: Do not clear no-change flags when unlinking object */
+#define	ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS	(0x20000)
 
 __LA_DECL int archive_read_extract(struct archive *, struct archive_entry *,
 		     int flags);
@@ -640,7 +680,7 @@ __LA_DECL void	 archive_read_extract_set_progress_callback(struct archive *,
 /* Record the dev/ino of a file that will not be written.  This is
  * generally set to the dev/ino of the archive being read. */
 __LA_DECL void		archive_read_extract_set_skip_file(struct archive *,
-		     __LA_INT64_T, __LA_INT64_T);
+		     la_int64_t, la_int64_t);
 
 /* Close the file and release most resources. */
 __LA_DECL int		 archive_read_close(struct archive *);
@@ -679,7 +719,7 @@ __LA_DECL int archive_write_get_bytes_in_last_block(struct archive *);
 /* The dev/ino of a file that won't be archived.  This is used
  * to avoid recursively adding an archive to itself. */
 __LA_DECL int archive_write_set_skip_file(struct archive *,
-    __LA_INT64_T, __LA_INT64_T);
+    la_int64_t, la_int64_t);
 
 #if ARCHIVE_VERSION_NUMBER < 4000000
 __LA_DECL int archive_write_set_compression_bzip2(struct archive *)
@@ -710,6 +750,7 @@ __LA_DECL int archive_write_add_filter_compress(struct archive *);
 __LA_DECL int archive_write_add_filter_grzip(struct archive *);
 __LA_DECL int archive_write_add_filter_gzip(struct archive *);
 __LA_DECL int archive_write_add_filter_lrzip(struct archive *);
+__LA_DECL int archive_write_add_filter_lz4(struct archive *);
 __LA_DECL int archive_write_add_filter_lzip(struct archive *);
 __LA_DECL int archive_write_add_filter_lzma(struct archive *);
 __LA_DECL int archive_write_add_filter_lzop(struct archive *);
@@ -742,8 +783,11 @@ __LA_DECL int archive_write_set_format_shar(struct archive *);
 __LA_DECL int archive_write_set_format_shar_dump(struct archive *);
 __LA_DECL int archive_write_set_format_ustar(struct archive *);
 __LA_DECL int archive_write_set_format_v7tar(struct archive *);
+__LA_DECL int archive_write_set_format_warc(struct archive *);
 __LA_DECL int archive_write_set_format_xar(struct archive *);
 __LA_DECL int archive_write_set_format_zip(struct archive *);
+__LA_DECL int archive_write_set_format_filter_by_ext(struct archive *a, const char *filename);
+__LA_DECL int archive_write_set_format_filter_by_ext_def(struct archive *a, const char *filename, const char * def_ext);
 __LA_DECL int archive_write_zip_set_compression_deflate(struct archive *);
 __LA_DECL int archive_write_zip_set_compression_store(struct archive *);
 __LA_DECL int archive_write_open(struct archive *, void *,
@@ -768,12 +812,12 @@ __LA_DECL int archive_write_open_memory(struct archive *,
  */
 __LA_DECL int archive_write_header(struct archive *,
 		     struct archive_entry *);
-__LA_DECL __LA_SSIZE_T	archive_write_data(struct archive *,
+__LA_DECL la_ssize_t	archive_write_data(struct archive *,
 			    const void *, size_t);
 
 /* This interface is currently only available for archive_write_disk handles.  */
-__LA_DECL __LA_SSIZE_T	 archive_write_data_block(struct archive *,
-				    const void *, size_t, __LA_INT64_T);
+__LA_DECL la_ssize_t	 archive_write_data_block(struct archive *,
+				    const void *, size_t, la_int64_t);
 
 __LA_DECL int		 archive_write_finish_entry(struct archive *);
 __LA_DECL int		 archive_write_close(struct archive *);
@@ -808,6 +852,13 @@ __LA_DECL int archive_write_set_option(struct archive *_a,
 __LA_DECL int archive_write_set_options(struct archive *_a,
 			    const char *opts);
 
+/*
+ * Set a encryption passphrase.
+ */
+__LA_DECL int archive_write_set_passphrase(struct archive *_a, const char *p);
+__LA_DECL int archive_write_set_passphrase_callback(struct archive *,
+			    void *client_data, archive_passphrase_callback *);
+
 /*-
  * ARCHIVE_WRITE_DISK API
  *
@@ -827,7 +878,7 @@ __LA_DECL int archive_write_set_options(struct archive *_a,
 __LA_DECL struct archive	*archive_write_disk_new(void);
 /* This file will not be overwritten. */
 __LA_DECL int archive_write_disk_set_skip_file(struct archive *,
-    __LA_INT64_T, __LA_INT64_T);
+    la_int64_t, la_int64_t);
 /* Set flags to control how the next item gets created.
  * This accepts a bitmask of ARCHIVE_EXTRACT_XXX flags defined above. */
 __LA_DECL int		 archive_write_disk_set_options(struct archive *,
@@ -857,14 +908,14 @@ __LA_DECL int	 archive_write_disk_set_standard_lookup(struct archive *);
  */
 __LA_DECL int archive_write_disk_set_group_lookup(struct archive *,
     void * /* private_data */,
-    __LA_INT64_T (*)(void *, const char *, __LA_INT64_T),
+    la_int64_t (*)(void *, const char *, la_int64_t),
     void (* /* cleanup */)(void *));
 __LA_DECL int archive_write_disk_set_user_lookup(struct archive *,
     void * /* private_data */,
-    __LA_INT64_T (*)(void *, const char *, __LA_INT64_T),
+    la_int64_t (*)(void *, const char *, la_int64_t),
     void (* /* cleanup */)(void *));
-__LA_DECL __LA_INT64_T archive_write_disk_gid(struct archive *, const char *, __LA_INT64_T);
-__LA_DECL __LA_INT64_T archive_write_disk_uid(struct archive *, const char *, __LA_INT64_T);
+__LA_DECL la_int64_t archive_write_disk_gid(struct archive *, const char *, la_int64_t);
+__LA_DECL la_int64_t archive_write_disk_uid(struct archive *, const char *, la_int64_t);
 
 /*
  * ARCHIVE_READ_DISK API
@@ -885,19 +936,19 @@ __LA_DECL int archive_read_disk_entry_from_file(struct archive *,
     struct archive_entry *, int /* fd */, const struct stat *);
 /* Look up gname for gid or uname for uid. */
 /* Default implementations are very, very stupid. */
-__LA_DECL const char *archive_read_disk_gname(struct archive *, __LA_INT64_T);
-__LA_DECL const char *archive_read_disk_uname(struct archive *, __LA_INT64_T);
+__LA_DECL const char *archive_read_disk_gname(struct archive *, la_int64_t);
+__LA_DECL const char *archive_read_disk_uname(struct archive *, la_int64_t);
 /* "Standard" implementation uses getpwuid_r, getgrgid_r and caches the
  * results for performance. */
 __LA_DECL int	archive_read_disk_set_standard_lookup(struct archive *);
 /* You can install your own lookups if you like. */
 __LA_DECL int	archive_read_disk_set_gname_lookup(struct archive *,
     void * /* private_data */,
-    const char *(* /* lookup_fn */)(void *, __LA_INT64_T),
+    const char *(* /* lookup_fn */)(void *, la_int64_t),
     void (* /* cleanup_fn */)(void *));
 __LA_DECL int	archive_read_disk_set_uname_lookup(struct archive *,
     void * /* private_data */,
-    const char *(* /* lookup_fn */)(void *, __LA_INT64_T),
+    const char *(* /* lookup_fn */)(void *, la_int64_t),
     void (* /* cleanup_fn */)(void *));
 /* Start traversal. */
 __LA_DECL int	archive_read_disk_open(struct archive *, const char *);
@@ -927,8 +978,10 @@ __LA_DECL int  archive_read_disk_set_atime_restored(struct archive *);
 /* Default: Skip a mac resource fork file whose prefix is "._" because of
  * using copyfile. */
 #define	ARCHIVE_READDISK_MAC_COPYFILE		(0x0004)
-/* Default: Do not traverse mount points. */
+/* Default: Traverse mount points. */
 #define	ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS	(0x0008)
+/* Default: Xattrs are read from disk. */
+#define	ARCHIVE_READDISK_NO_XATTR		(0x0010)
 
 __LA_DECL int  archive_read_disk_set_behavior(struct archive *,
 		    int flags);
@@ -961,7 +1014,7 @@ __LA_DECL int	archive_free(struct archive *);
  * last filter, which is always the pseudo-filter that wraps the
  * client callbacks. */
 __LA_DECL int		 archive_filter_count(struct archive *);
-__LA_DECL __LA_INT64_T	 archive_filter_bytes(struct archive *, int);
+__LA_DECL la_int64_t	 archive_filter_bytes(struct archive *, int);
 __LA_DECL int		 archive_filter_code(struct archive *, int);
 __LA_DECL const char *	 archive_filter_name(struct archive *, int);
 
@@ -969,10 +1022,10 @@ __LA_DECL const char *	 archive_filter_name(struct archive *, int);
 /* These don't properly handle multiple filters, so are deprecated and
  * will eventually be removed. */
 /* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, -1); */
-__LA_DECL __LA_INT64_T	 archive_position_compressed(struct archive *)
+__LA_DECL la_int64_t	 archive_position_compressed(struct archive *)
 				__LA_DEPRECATED;
 /* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, 0); */
-__LA_DECL __LA_INT64_T	 archive_position_uncompressed(struct archive *)
+__LA_DECL la_int64_t	 archive_position_uncompressed(struct archive *)
 				__LA_DEPRECATED;
 /* As of libarchive 3.0, this is an alias for archive_filter_name(a, 0); */
 __LA_DECL const char	*archive_compression_name(struct archive *)
@@ -1088,8 +1141,8 @@ __LA_DECL int	archive_match_exclude_entry(struct archive *,
 __LA_DECL int	archive_match_owner_excluded(struct archive *,
 		    struct archive_entry *);
 /* Add inclusion uid, gid, uname and gname. */
-__LA_DECL int	archive_match_include_uid(struct archive *, __LA_INT64_T);
-__LA_DECL int	archive_match_include_gid(struct archive *, __LA_INT64_T);
+__LA_DECL int	archive_match_include_uid(struct archive *, la_int64_t);
+__LA_DECL int	archive_match_include_gid(struct archive *, la_int64_t);
 __LA_DECL int	archive_match_include_uname(struct archive *, const char *);
 __LA_DECL int	archive_match_include_uname_w(struct archive *,
 		    const wchar_t *);
@@ -1108,9 +1161,4 @@ __LA_DECL int archive_utility_string_sort(char **);
 /* These are meaningless outside of this header. */
 #undef __LA_DECL
 
-/* These need to remain defined because they're used in the
- * callback type definitions.  XXX Fix this.  This is ugly. XXX */
-/* #undef __LA_INT64_T */
-/* #undef __LA_SSIZE_T */
-
 #endif /* !ARCHIVE_H_INCLUDED */
diff --git a/Utilities/cmlibarchive/libarchive/archive_cryptor.c b/Utilities/cmlibarchive/libarchive/archive_cryptor.c
new file mode 100644
index 0000000..efd350d
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_cryptor.c
@@ -0,0 +1,435 @@
+/*-
+* Copyright (c) 2014 Michihiro NAKAJIMA
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "archive_platform.h"
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#include "archive.h"
+#include "archive_cryptor_private.h"
+
+#ifdef ARCHIVE_CRYPTOR_USE_Apple_CommonCrypto
+
+static int
+pbkdf2_sha1(const char *pw, size_t pw_len, const uint8_t *salt,
+    size_t salt_len, unsigned rounds, uint8_t *derived_key,
+    size_t derived_key_len)
+{
+	CCKeyDerivationPBKDF(kCCPBKDF2, (const char *)pw,
+	    pw_len, salt, salt_len, kCCPRFHmacAlgSHA1, rounds,
+	    derived_key, derived_key_len);
+	return 0;
+}
+
+#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H)
+#ifdef _MSC_VER
+#pragma comment(lib, "Bcrypt.lib")
+#endif
+
+static int
+pbkdf2_sha1(const char *pw, size_t pw_len, const uint8_t *salt,
+	size_t salt_len, unsigned rounds, uint8_t *derived_key,
+	size_t derived_key_len)
+{
+	NTSTATUS status;
+	BCRYPT_ALG_HANDLE hAlg;
+
+	status = BCryptOpenAlgorithmProvider(&hAlg, BCRYPT_SHA1_ALGORITHM,
+		MS_PRIMITIVE_PROVIDER, BCRYPT_ALG_HANDLE_HMAC_FLAG);
+	if (!BCRYPT_SUCCESS(status))
+		return -1;
+
+	status = BCryptDeriveKeyPBKDF2(hAlg,
+		(PUCHAR)(uintptr_t)pw, (ULONG)pw_len,
+		(PUCHAR)(uintptr_t)salt, (ULONG)salt_len, rounds,
+		(PUCHAR)derived_key, (ULONG)derived_key_len, 0);
+
+	BCryptCloseAlgorithmProvider(hAlg, 0);
+
+	return (BCRYPT_SUCCESS(status)) ? 0: -1;
+}
+
+#elif defined(HAVE_LIBNETTLE) && defined(HAVE_NETTLE_PBKDF2_H)
+
+static int
+pbkdf2_sha1(const char *pw, size_t pw_len, const uint8_t *salt,
+    size_t salt_len, unsigned rounds, uint8_t *derived_key,
+    size_t derived_key_len) {
+	pbkdf2_hmac_sha1((unsigned)pw_len, (const uint8_t *)pw, rounds,
+	    salt_len, salt, derived_key_len, derived_key);
+	return 0;
+}
+
+#elif defined(HAVE_LIBCRYPTO) && defined(HAVE_PKCS5_PBKDF2_HMAC_SHA1)
+
+static int
+pbkdf2_sha1(const char *pw, size_t pw_len, const uint8_t *salt,
+    size_t salt_len, unsigned rounds, uint8_t *derived_key,
+    size_t derived_key_len) {
+
+	PKCS5_PBKDF2_HMAC_SHA1(pw, pw_len, salt, salt_len, rounds,
+	    derived_key_len, derived_key);
+	return 0;
+}
+
+#else
+
+/* Stub */
+static int
+pbkdf2_sha1(const char *pw, size_t pw_len, const uint8_t *salt,
+    size_t salt_len, unsigned rounds, uint8_t *derived_key,
+    size_t derived_key_len) {
+	(void)pw; /* UNUSED */
+	(void)pw_len; /* UNUSED */
+	(void)salt; /* UNUSED */
+	(void)salt_len; /* UNUSED */
+	(void)rounds; /* UNUSED */
+	(void)derived_key; /* UNUSED */
+	(void)derived_key_len; /* UNUSED */
+	return -1; /* UNSUPPORTED */
+}
+
+#endif
+
+#ifdef ARCHIVE_CRYPTOR_USE_Apple_CommonCrypto
+# if MAC_OS_X_VERSION_MAX_ALLOWED < 1090
+#  define kCCAlgorithmAES kCCAlgorithmAES128
+# endif
+
+static int
+aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
+{
+	CCCryptorStatus r;
+
+	ctx->key_len = key_len;
+	memcpy(ctx->key, key, key_len);
+	memset(ctx->nonce, 0, sizeof(ctx->nonce));
+	ctx->encr_pos = AES_BLOCK_SIZE;
+	r = CCCryptorCreateWithMode(kCCEncrypt, kCCModeECB, kCCAlgorithmAES,
+	    ccNoPadding, NULL, key, key_len, NULL, 0, 0, 0, &ctx->ctx);
+	return (r == kCCSuccess)? 0: -1;
+}
+
+static int
+aes_ctr_encrypt_counter(archive_crypto_ctx *ctx)
+{
+	CCCryptorRef ref = ctx->ctx;
+	CCCryptorStatus r;
+
+	r = CCCryptorReset(ref, NULL);
+	if (r != kCCSuccess)
+		return -1;
+	r = CCCryptorUpdate(ref, ctx->nonce, AES_BLOCK_SIZE, ctx->encr_buf,
+	    AES_BLOCK_SIZE, NULL);
+	return (r == kCCSuccess)? 0: -1;
+}
+
+static int
+aes_ctr_release(archive_crypto_ctx *ctx)
+{
+	memset(ctx->key, 0, ctx->key_len);
+	memset(ctx->nonce, 0, sizeof(ctx->nonce));
+	return 0;
+}
+
+#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H)
+
+static int
+aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
+{
+	BCRYPT_ALG_HANDLE hAlg;
+	BCRYPT_KEY_HANDLE hKey;
+	DWORD keyObj_len, aes_key_len;
+	PBYTE keyObj;
+	ULONG result;
+	NTSTATUS status;
+	BCRYPT_KEY_LENGTHS_STRUCT key_lengths;
+
+	ctx->hAlg = NULL;
+	ctx->hKey = NULL;
+	ctx->keyObj = NULL;
+	switch (key_len) {
+	case 16: aes_key_len = 128; break;
+	case 24: aes_key_len = 192; break;
+	case 32: aes_key_len = 256; break;
+	default: return -1;
+	}
+	status = BCryptOpenAlgorithmProvider(&hAlg, BCRYPT_AES_ALGORITHM,
+		MS_PRIMITIVE_PROVIDER, 0);
+	if (!BCRYPT_SUCCESS(status))
+		return -1;
+	status = BCryptGetProperty(hAlg, BCRYPT_KEY_LENGTHS, (PUCHAR)&key_lengths,
+		sizeof(key_lengths), &result, 0);
+	if (!BCRYPT_SUCCESS(status)) {
+		BCryptCloseAlgorithmProvider(hAlg, 0);
+		return -1;
+	}
+	if (key_lengths.dwMinLength > aes_key_len
+		|| key_lengths.dwMaxLength < aes_key_len) {
+		BCryptCloseAlgorithmProvider(hAlg, 0);
+		return -1;
+	}
+	status = BCryptGetProperty(hAlg, BCRYPT_OBJECT_LENGTH, (PUCHAR)&keyObj_len,
+		sizeof(keyObj_len), &result, 0);
+	if (!BCRYPT_SUCCESS(status)) {
+		BCryptCloseAlgorithmProvider(hAlg, 0);
+		return -1;
+	}
+	keyObj = (PBYTE)HeapAlloc(GetProcessHeap(), 0, keyObj_len);
+	if (keyObj == NULL) {
+		BCryptCloseAlgorithmProvider(hAlg, 0);
+		return -1;
+	}
+	status = BCryptSetProperty(hAlg, BCRYPT_CHAINING_MODE,
+		(PUCHAR)BCRYPT_CHAIN_MODE_ECB, sizeof(BCRYPT_CHAIN_MODE_ECB), 0);
+	if (!BCRYPT_SUCCESS(status)) {
+		BCryptCloseAlgorithmProvider(hAlg, 0);
+		HeapFree(GetProcessHeap(), 0, keyObj);
+		return -1;
+	}
+	status = BCryptGenerateSymmetricKey(hAlg, &hKey,
+		keyObj, keyObj_len,
+		(PUCHAR)(uintptr_t)key, (ULONG)key_len, 0);
+	if (!BCRYPT_SUCCESS(status)) {
+		BCryptCloseAlgorithmProvider(hAlg, 0);
+		HeapFree(GetProcessHeap(), 0, keyObj);
+		return -1;
+	}
+
+	ctx->hAlg = hAlg;
+	ctx->hKey = hKey;
+	ctx->keyObj = keyObj;
+	ctx->keyObj_len = keyObj_len;
+	ctx->encr_pos = AES_BLOCK_SIZE;
+
+	return 0;
+}
+
+static int
+aes_ctr_encrypt_counter(archive_crypto_ctx *ctx)
+{
+	NTSTATUS status;
+	ULONG result;
+
+	status = BCryptEncrypt(ctx->hKey, (PUCHAR)ctx->nonce, AES_BLOCK_SIZE,
+		NULL, NULL, 0, (PUCHAR)ctx->encr_buf, AES_BLOCK_SIZE,
+		&result, 0);
+	return BCRYPT_SUCCESS(status) ? 0 : -1;
+}
+
+static int
+aes_ctr_release(archive_crypto_ctx *ctx)
+{
+
+	if (ctx->hAlg != NULL) {
+		BCryptCloseAlgorithmProvider(ctx->hAlg, 0);
+		ctx->hAlg = NULL;
+		BCryptDestroyKey(ctx->hKey);
+		ctx->hKey = NULL;
+		HeapFree(GetProcessHeap(), 0, ctx->keyObj);
+		ctx->keyObj = NULL;
+	}
+	memset(ctx, 0, sizeof(*ctx));
+	return 0;
+}
+
+#elif defined(HAVE_LIBNETTLE)
+
+static int
+aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
+{
+	ctx->key_len = key_len;
+	memcpy(ctx->key, key, key_len);
+	memset(ctx->nonce, 0, sizeof(ctx->nonce));
+	ctx->encr_pos = AES_BLOCK_SIZE;
+	memset(&ctx->ctx, 0, sizeof(ctx->ctx));
+	return 0;
+}
+
+static int
+aes_ctr_encrypt_counter(archive_crypto_ctx *ctx)
+{
+	aes_set_encrypt_key(&ctx->ctx, ctx->key_len, ctx->key);
+	aes_encrypt(&ctx->ctx, AES_BLOCK_SIZE, ctx->encr_buf, ctx->nonce);
+	return 0;
+}
+
+static int
+aes_ctr_release(archive_crypto_ctx *ctx)
+{
+	memset(ctx, 0, sizeof(*ctx));
+	return 0;
+}
+
+#elif defined(HAVE_LIBCRYPTO)
+
+static int
+aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
+{
+
+	switch (key_len) {
+	case 16: ctx->type = EVP_aes_128_ecb(); break;
+	case 24: ctx->type = EVP_aes_192_ecb(); break;
+	case 32: ctx->type = EVP_aes_256_ecb(); break;
+	default: ctx->type = NULL; return -1;
+	}
+
+	ctx->key_len = key_len;
+	memcpy(ctx->key, key, key_len);
+	memset(ctx->nonce, 0, sizeof(ctx->nonce));
+	ctx->encr_pos = AES_BLOCK_SIZE;
+	EVP_CIPHER_CTX_init(&ctx->ctx);
+	return 0;
+}
+
+static int
+aes_ctr_encrypt_counter(archive_crypto_ctx *ctx)
+{
+	int outl = 0;
+	int r;
+
+	r = EVP_EncryptInit_ex(&ctx->ctx, ctx->type, NULL, ctx->key, NULL);
+	if (r == 0)
+		return -1;
+	r = EVP_EncryptUpdate(&ctx->ctx, ctx->encr_buf, &outl, ctx->nonce,
+	    AES_BLOCK_SIZE);
+	if (r == 0 || outl != AES_BLOCK_SIZE)
+		return -1;
+	return 0;
+}
+
+static int
+aes_ctr_release(archive_crypto_ctx *ctx)
+{
+	EVP_CIPHER_CTX_cleanup(&ctx->ctx);
+	memset(ctx->key, 0, ctx->key_len);
+	memset(ctx->nonce, 0, sizeof(ctx->nonce));
+	return 0;
+}
+
+#else
+
+#define ARCHIVE_CRYPTOR_STUB
+/* Stub */
+static int
+aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
+{
+	(void)ctx; /* UNUSED */
+	(void)key; /* UNUSED */
+	(void)key_len; /* UNUSED */
+	return -1;
+}
+
+static int
+aes_ctr_encrypt_counter(archive_crypto_ctx *ctx)
+{
+	(void)ctx; /* UNUSED */
+	return -1;
+}
+
+static int
+aes_ctr_release(archive_crypto_ctx *ctx)
+{
+	(void)ctx; /* UNUSED */
+	return 0;
+}
+
+#endif
+
+#ifdef ARCHIVE_CRYPTOR_STUB
+static int
+aes_ctr_update(archive_crypto_ctx *ctx, const uint8_t * const in,
+    size_t in_len, uint8_t * const out, size_t *out_len)
+{
+	(void)ctx; /* UNUSED */
+	(void)in; /* UNUSED */
+	(void)in_len; /* UNUSED */
+	(void)out; /* UNUSED */
+	(void)out_len; /* UNUSED */
+	aes_ctr_encrypt_counter(ctx); /* UNUSED */ /* Fix unused function warning */
+	return -1;
+}
+
+#else
+static void
+aes_ctr_increase_counter(archive_crypto_ctx *ctx)
+{
+	uint8_t *const nonce = ctx->nonce;
+	int j;
+
+	for (j = 0; j < 8; j++) {
+		if (++nonce[j])
+			break;
+	}
+}
+
+static int
+aes_ctr_update(archive_crypto_ctx *ctx, const uint8_t * const in,
+    size_t in_len, uint8_t * const out, size_t *out_len)
+{
+	uint8_t *const ebuf = ctx->encr_buf;
+	unsigned pos = ctx->encr_pos;
+	unsigned max = (unsigned)((in_len < *out_len)? in_len: *out_len);
+	unsigned i;
+
+	for (i = 0; i < max; ) {
+		if (pos == AES_BLOCK_SIZE) {
+			aes_ctr_increase_counter(ctx);
+			if (aes_ctr_encrypt_counter(ctx) != 0)
+				return -1;
+			while (max -i >= AES_BLOCK_SIZE) {
+				for (pos = 0; pos < AES_BLOCK_SIZE; pos++)
+					out[i+pos] = in[i+pos] ^ ebuf[pos];
+				i += AES_BLOCK_SIZE;
+				aes_ctr_increase_counter(ctx);
+				if (aes_ctr_encrypt_counter(ctx) != 0)
+					return -1;
+			}
+			pos = 0;
+			if (i >= max)
+				break;
+		}
+		out[i] = in[i] ^ ebuf[pos++];
+		i++;
+	}
+	ctx->encr_pos = pos;
+	*out_len = i;
+
+	return 0;
+}
+#endif /* ARCHIVE_CRYPTOR_STUB */
+
+
+const struct archive_cryptor __archive_cryptor =
+{
+  &pbkdf2_sha1,
+  &aes_ctr_init,
+  &aes_ctr_update,
+  &aes_ctr_release,
+  &aes_ctr_init,
+  &aes_ctr_update,
+  &aes_ctr_release,
+};
diff --git a/Utilities/cmlibarchive/libarchive/archive_cryptor_private.h b/Utilities/cmlibarchive/libarchive/archive_cryptor_private.h
new file mode 100644
index 0000000..9a96aee
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_cryptor_private.h
@@ -0,0 +1,152 @@
+/*-
+* Copyright (c) 2014 Michihiro NAKAJIMA
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+#ifndef ARCHIVE_CRYPTOR_PRIVATE_H_INCLUDED
+#define ARCHIVE_CRYPTOR_PRIVATE_H_INCLUDED
+
+#ifdef __APPLE__
+# include <AvailabilityMacros.h>
+# if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
+#  define ARCHIVE_CRYPTOR_USE_Apple_CommonCrypto
+# endif
+#endif
+
+#ifdef ARCHIVE_CRYPTOR_USE_Apple_CommonCrypto
+#include <CommonCrypto/CommonCryptor.h>
+#include <CommonCrypto/CommonKeyDerivation.h>
+#define AES_BLOCK_SIZE	16
+#define AES_MAX_KEY_SIZE kCCKeySizeAES256
+
+typedef struct {
+	CCCryptorRef	ctx;
+	uint8_t		key[AES_MAX_KEY_SIZE];
+	unsigned	key_len;
+	uint8_t		nonce[AES_BLOCK_SIZE];
+	uint8_t		encr_buf[AES_BLOCK_SIZE];
+	unsigned	encr_pos;
+} archive_crypto_ctx;
+
+#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H)
+#include <Bcrypt.h>
+
+/* Common in other bcrypt implementations, but missing from VS2008. */
+#ifndef BCRYPT_SUCCESS
+#define BCRYPT_SUCCESS(r) ((NTSTATUS)(r) == STATUS_SUCCESS)
+#endif
+
+#define AES_MAX_KEY_SIZE 32
+#define AES_BLOCK_SIZE 16
+typedef struct {
+	BCRYPT_ALG_HANDLE hAlg;
+	BCRYPT_KEY_HANDLE hKey;
+	PBYTE		keyObj;
+	DWORD		keyObj_len;
+	uint8_t		nonce[AES_BLOCK_SIZE];
+	uint8_t		encr_buf[AES_BLOCK_SIZE];
+	unsigned	encr_pos;
+} archive_crypto_ctx;
+
+#elif defined(HAVE_LIBNETTLE)
+#if defined(HAVE_NETTLE_PBKDF2_H)
+#include <nettle/pbkdf2.h>
+#endif
+#include <nettle/aes.h>
+
+typedef struct {
+	struct aes_ctx	ctx;
+	uint8_t		key[AES_MAX_KEY_SIZE];
+	unsigned	key_len;
+	uint8_t		nonce[AES_BLOCK_SIZE];
+	uint8_t		encr_buf[AES_BLOCK_SIZE];
+	unsigned	encr_pos;
+} archive_crypto_ctx;
+
+#elif defined(HAVE_LIBCRYPTO)
+#include <openssl/evp.h>
+#define AES_BLOCK_SIZE	16
+#define AES_MAX_KEY_SIZE 32
+
+typedef struct {
+	EVP_CIPHER_CTX	ctx;
+	const EVP_CIPHER *type;
+	uint8_t		key[AES_MAX_KEY_SIZE];
+	unsigned	key_len;
+	uint8_t		nonce[AES_BLOCK_SIZE];
+	uint8_t		encr_buf[AES_BLOCK_SIZE];
+	unsigned	encr_pos;
+} archive_crypto_ctx;
+
+#else
+
+#define AES_BLOCK_SIZE	16
+#define AES_MAX_KEY_SIZE 32
+typedef int archive_crypto_ctx;
+
+#endif
+
+/* defines */
+#define archive_pbkdf2_sha1(pw, pw_len, salt, salt_len, rounds, dk, dk_len)\
+  __archive_cryptor.pbkdf2sha1(pw, pw_len, salt, salt_len, rounds, dk, dk_len)
+
+#define archive_decrypto_aes_ctr_init(ctx, key, key_len) \
+  __archive_cryptor.decrypto_aes_ctr_init(ctx, key, key_len)
+#define archive_decrypto_aes_ctr_update(ctx, in, in_len, out, out_len) \
+  __archive_cryptor.decrypto_aes_ctr_update(ctx, in, in_len, out, out_len)
+#define archive_decrypto_aes_ctr_release(ctx) \
+  __archive_cryptor.decrypto_aes_ctr_release(ctx)
+
+#define archive_encrypto_aes_ctr_init(ctx, key, key_len) \
+  __archive_cryptor.encrypto_aes_ctr_init(ctx, key, key_len)
+#define archive_encrypto_aes_ctr_update(ctx, in, in_len, out, out_len) \
+  __archive_cryptor.encrypto_aes_ctr_update(ctx, in, in_len, out, out_len)
+#define archive_encrypto_aes_ctr_release(ctx) \
+  __archive_cryptor.encrypto_aes_ctr_release(ctx)
+
+/* Minimal interface to cryptographic functionality for internal use in
+ * libarchive */
+struct archive_cryptor
+{
+  /* PKCS5 PBKDF2 HMAC-SHA1 */
+  int (*pbkdf2sha1)(const char *pw, size_t pw_len, const uint8_t *salt,
+    size_t salt_len, unsigned rounds, uint8_t *derived_key,
+    size_t derived_key_len);
+  /* AES CTR mode(little endian version) */
+  int (*decrypto_aes_ctr_init)(archive_crypto_ctx *, const uint8_t *, size_t);
+  int (*decrypto_aes_ctr_update)(archive_crypto_ctx *, const uint8_t *,
+    size_t, uint8_t *, size_t *);
+  int (*decrypto_aes_ctr_release)(archive_crypto_ctx *);
+  int (*encrypto_aes_ctr_init)(archive_crypto_ctx *, const uint8_t *, size_t);
+  int (*encrypto_aes_ctr_update)(archive_crypto_ctx *, const uint8_t *,
+    size_t, uint8_t *, size_t *);
+  int (*encrypto_aes_ctr_release)(archive_crypto_ctx *);
+};
+
+extern const struct archive_cryptor __archive_cryptor;
+
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_crypto.c b/Utilities/cmlibarchive/libarchive/archive_digest.c
similarity index 99%
rename from Utilities/cmlibarchive/libarchive/archive_crypto.c
rename to Utilities/cmlibarchive/libarchive/archive_digest.c
index 85aba3a..f009d31 100644
--- a/Utilities/cmlibarchive/libarchive/archive_crypto.c
+++ b/Utilities/cmlibarchive/libarchive/archive_digest.c
@@ -28,7 +28,7 @@
 #include "archive_platform.h"
 
 #include "archive.h"
-#include "archive_crypto_private.h"
+#include "archive_digest_private.h"
 
 /* In particular, force the configure probe to break if it tries
  * to test a combination of OpenSSL and libmd. */
@@ -1216,8 +1216,8 @@ __archive_stub_sha512final(archive_sha512_ctx *ctx, void *md)
 
 #endif
 
-/* NOTE: Crypto functions are set based on availability and by the following
- * order of preference.
+/* NOTE: Message Digest functions are set based on availability and by the
+ * following order of preference.
  * 1. libc
  * 2. libc2
  * 3. libc3
@@ -1227,7 +1227,7 @@ __archive_stub_sha512final(archive_sha512_ctx *ctx, void *md)
  * 7. libmd
  * 8. Windows API
  */
-const struct archive_crypto __archive_crypto =
+const struct archive_digest __archive_digest =
 {
 /* MD5 */
 #if defined(ARCHIVE_CRYPTO_MD5_LIBC)
@@ -1412,7 +1412,7 @@ const struct archive_crypto __archive_crypto =
 #elif defined(ARCHIVE_CRYPTO_SHA512_NETTLE)
   &__archive_nettle_sha512init,
   &__archive_nettle_sha512update,
-  &__archive_nettle_sha512final,
+  &__archive_nettle_sha512final
 #elif defined(ARCHIVE_CRYPTO_SHA512_OPENSSL)
   &__archive_openssl_sha512init,
   &__archive_openssl_sha512update,
diff --git a/Utilities/cmlibarchive/libarchive/archive_crypto_private.h b/Utilities/cmlibarchive/libarchive/archive_digest_private.h
similarity index 93%
rename from Utilities/cmlibarchive/libarchive/archive_crypto_private.h
rename to Utilities/cmlibarchive/libarchive/archive_digest_private.h
index f8b1fb3..77fad58 100644
--- a/Utilities/cmlibarchive/libarchive/archive_crypto_private.h
+++ b/Utilities/cmlibarchive/libarchive/archive_digest_private.h
@@ -264,11 +264,11 @@ typedef unsigned char archive_sha512_ctx;
 #define ARCHIVE_HAS_MD5
 #endif
 #define archive_md5_init(ctx)\
-  __archive_crypto.md5init(ctx)
+  __archive_digest.md5init(ctx)
 #define archive_md5_final(ctx, md)\
-  __archive_crypto.md5final(ctx, md)
+  __archive_digest.md5final(ctx, md)
 #define archive_md5_update(ctx, buf, n)\
-  __archive_crypto.md5update(ctx, buf, n)
+  __archive_digest.md5update(ctx, buf, n)
 
 #if defined(ARCHIVE_CRYPTO_RMD160_LIBC) ||\
   defined(ARCHIVE_CRYPTO_RMD160_NETTLE) ||\
@@ -276,11 +276,11 @@ typedef unsigned char archive_sha512_ctx;
 #define ARCHIVE_HAS_RMD160
 #endif
 #define archive_rmd160_init(ctx)\
-  __archive_crypto.rmd160init(ctx)
+  __archive_digest.rmd160init(ctx)
 #define archive_rmd160_final(ctx, md)\
-  __archive_crypto.rmd160final(ctx, md)
+  __archive_digest.rmd160final(ctx, md)
 #define archive_rmd160_update(ctx, buf, n)\
-  __archive_crypto.rmd160update(ctx, buf, n)
+  __archive_digest.rmd160update(ctx, buf, n)
 
 #if defined(ARCHIVE_CRYPTO_SHA1_LIBC) ||\
   defined(ARCHIVE_CRYPTO_SHA1_LIBMD) ||	\
@@ -291,11 +291,11 @@ typedef unsigned char archive_sha512_ctx;
 #define ARCHIVE_HAS_SHA1
 #endif
 #define archive_sha1_init(ctx)\
-  __archive_crypto.sha1init(ctx)
+  __archive_digest.sha1init(ctx)
 #define archive_sha1_final(ctx, md)\
-  __archive_crypto.sha1final(ctx, md)
+  __archive_digest.sha1final(ctx, md)
 #define archive_sha1_update(ctx, buf, n)\
-  __archive_crypto.sha1update(ctx, buf, n)
+  __archive_digest.sha1update(ctx, buf, n)
 
 #if defined(ARCHIVE_CRYPTO_SHA256_LIBC) ||\
   defined(ARCHIVE_CRYPTO_SHA256_LIBC2) ||\
@@ -308,11 +308,11 @@ typedef unsigned char archive_sha512_ctx;
 #define ARCHIVE_HAS_SHA256
 #endif
 #define archive_sha256_init(ctx)\
-  __archive_crypto.sha256init(ctx)
+  __archive_digest.sha256init(ctx)
 #define archive_sha256_final(ctx, md)\
-  __archive_crypto.sha256final(ctx, md)
+  __archive_digest.sha256final(ctx, md)
 #define archive_sha256_update(ctx, buf, n)\
-  __archive_crypto.sha256update(ctx, buf, n)
+  __archive_digest.sha256update(ctx, buf, n)
 
 #if defined(ARCHIVE_CRYPTO_SHA384_LIBC) ||\
   defined(ARCHIVE_CRYPTO_SHA384_LIBC2) ||\
@@ -324,11 +324,11 @@ typedef unsigned char archive_sha512_ctx;
 #define ARCHIVE_HAS_SHA384
 #endif
 #define archive_sha384_init(ctx)\
-  __archive_crypto.sha384init(ctx)
+  __archive_digest.sha384init(ctx)
 #define archive_sha384_final(ctx, md)\
-  __archive_crypto.sha384final(ctx, md)
+  __archive_digest.sha384final(ctx, md)
 #define archive_sha384_update(ctx, buf, n)\
-  __archive_crypto.sha384update(ctx, buf, n)
+  __archive_digest.sha384update(ctx, buf, n)
 
 #if defined(ARCHIVE_CRYPTO_SHA512_LIBC) ||\
   defined(ARCHIVE_CRYPTO_SHA512_LIBC2) ||\
@@ -341,14 +341,14 @@ typedef unsigned char archive_sha512_ctx;
 #define ARCHIVE_HAS_SHA512
 #endif
 #define archive_sha512_init(ctx)\
-  __archive_crypto.sha512init(ctx)
+  __archive_digest.sha512init(ctx)
 #define archive_sha512_final(ctx, md)\
-  __archive_crypto.sha512final(ctx, md)
+  __archive_digest.sha512final(ctx, md)
 #define archive_sha512_update(ctx, buf, n)\
-  __archive_crypto.sha512update(ctx, buf, n)
+  __archive_digest.sha512update(ctx, buf, n)
 
-/* Minimal interface to crypto functionality for internal use in libarchive */
-struct archive_crypto
+/* Minimal interface to digest functionality for internal use in libarchive */
+struct archive_digest
 {
   /* Message Digest */
   int (*md5init)(archive_md5_ctx *ctx);
@@ -371,6 +371,6 @@ struct archive_crypto
   int (*sha512final)(archive_sha512_ctx *, void *);
 };
 
-extern const struct archive_crypto __archive_crypto;
+extern const struct archive_digest __archive_digest;
 
 #endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.3 b/Utilities/cmlibarchive/libarchive/archive_entry.3
index f77f385..f5e22af 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry.3
+++ b/Utilities/cmlibarchive/libarchive/archive_entry.3
@@ -131,11 +131,11 @@ be discarded in favor of the new data.
 .\" .Sh RETURN VALUES
 .\" .Sh ERRORS
 .Sh SEE ALSO
-.Xr archive 3 ,
 .Xr archive_entry_acl 3 ,
 .Xr archive_entry_paths 3 ,
 .Xr archive_entry_perms 3 ,
 .Xr archive_entry_time 3
+.Xr libarchive 3 ,
 .Sh HISTORY
 The
 .Nm libarchive
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.c b/Utilities/cmlibarchive/libarchive/archive_entry.c
index 293c701..4ac1966 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry.c
+++ b/Utilities/cmlibarchive/libarchive/archive_entry.c
@@ -418,6 +418,18 @@ archive_entry_gname(struct archive_entry *entry)
 	return (NULL);
 }
 
+const char *
+archive_entry_gname_utf8(struct archive_entry *entry)
+{
+	const char *p;
+	if (archive_mstring_get_utf8(entry->archive, &entry->ae_gname, &p) == 0)
+		return (p);
+	if (errno == ENOMEM)
+		__archive_errx(1, "No memory");
+	return (NULL);
+}
+
+
 const wchar_t *
 archive_entry_gname_w(struct archive_entry *entry)
 {
@@ -450,6 +462,20 @@ archive_entry_hardlink(struct archive_entry *entry)
 	return (NULL);
 }
 
+const char *
+archive_entry_hardlink_utf8(struct archive_entry *entry)
+{
+	const char *p;
+	if ((entry->ae_set & AE_SET_HARDLINK) == 0)
+		return (NULL);
+	if (archive_mstring_get_utf8(
+	    entry->archive, &entry->ae_hardlink, &p) == 0)
+		return (p);
+	if (errno == ENOMEM)
+		__archive_errx(1, "No memory");
+	return (NULL);
+}
+
 const wchar_t *
 archive_entry_hardlink_w(struct archive_entry *entry)
 {
@@ -536,6 +562,18 @@ archive_entry_pathname(struct archive_entry *entry)
 	return (NULL);
 }
 
+const char *
+archive_entry_pathname_utf8(struct archive_entry *entry)
+{
+	const char *p;
+	if (archive_mstring_get_utf8(
+	    entry->archive, &entry->ae_pathname, &p) == 0)
+		return (p);
+	if (errno == ENOMEM)
+		__archive_errx(1, "No memory");
+	return (NULL);
+}
+
 const wchar_t *
 archive_entry_pathname_w(struct archive_entry *entry)
 {
@@ -637,6 +675,20 @@ archive_entry_symlink(struct archive_entry *entry)
 	return (NULL);
 }
 
+const char *
+archive_entry_symlink_utf8(struct archive_entry *entry)
+{
+	const char *p;
+	if ((entry->ae_set & AE_SET_SYMLINK) == 0)
+		return (NULL);
+	if (archive_mstring_get_utf8(
+	    entry->archive, &entry->ae_symlink, &p) == 0)
+		return (p);
+	if (errno == ENOMEM)
+		__archive_errx(1, "No memory");
+	return (NULL);
+}
+
 const wchar_t *
 archive_entry_symlink_w(struct archive_entry *entry)
 {
@@ -680,6 +732,17 @@ archive_entry_uname(struct archive_entry *entry)
 	return (NULL);
 }
 
+const char *
+archive_entry_uname_utf8(struct archive_entry *entry)
+{
+	const char *p;
+	if (archive_mstring_get_utf8(entry->archive, &entry->ae_uname, &p) == 0)
+		return (p);
+	if (errno == ENOMEM)
+		__archive_errx(1, "No memory");
+	return (NULL);
+}
+
 const wchar_t *
 archive_entry_uname_w(struct archive_entry *entry)
 {
@@ -769,6 +832,12 @@ archive_entry_set_gname(struct archive_entry *entry, const char *name)
 }
 
 void
+archive_entry_set_gname_utf8(struct archive_entry *entry, const char *name)
+{
+	archive_mstring_copy_utf8(&entry->ae_gname, name);
+}
+
+void
 archive_entry_copy_gname(struct archive_entry *entry, const char *name)
 {
 	archive_mstring_copy_mbs(&entry->ae_gname, name);
@@ -825,6 +894,16 @@ archive_entry_set_hardlink(struct archive_entry *entry, const char *target)
 }
 
 void
+archive_entry_set_hardlink_utf8(struct archive_entry *entry, const char *target)
+{
+	archive_mstring_copy_utf8(&entry->ae_hardlink, target);
+	if (target != NULL)
+		entry->ae_set |= AE_SET_HARDLINK;
+	else
+		entry->ae_set &= ~AE_SET_HARDLINK;
+}
+
+void
 archive_entry_copy_hardlink(struct archive_entry *entry, const char *target)
 {
 	archive_mstring_copy_mbs(&entry->ae_hardlink, target);
@@ -962,6 +1041,15 @@ archive_entry_set_link(struct archive_entry *entry, const char *target)
 		archive_mstring_copy_mbs(&entry->ae_hardlink, target);
 }
 
+void
+archive_entry_set_link_utf8(struct archive_entry *entry, const char *target)
+{
+	if (entry->ae_set & AE_SET_SYMLINK)
+		archive_mstring_copy_utf8(&entry->ae_symlink, target);
+	else
+		archive_mstring_copy_utf8(&entry->ae_hardlink, target);
+}
+
 /* Set symlink if symlink is already set, else set hardlink. */
 void
 archive_entry_copy_link(struct archive_entry *entry, const char *target)
@@ -1052,6 +1140,12 @@ archive_entry_set_pathname(struct archive_entry *entry, const char *name)
 }
 
 void
+archive_entry_set_pathname_utf8(struct archive_entry *entry, const char *name)
+{
+	archive_mstring_copy_utf8(&entry->ae_pathname, name);
+}
+
+void
 archive_entry_copy_pathname(struct archive_entry *entry, const char *name)
 {
 	archive_mstring_copy_mbs(&entry->ae_pathname, name);
@@ -1152,6 +1246,16 @@ archive_entry_set_symlink(struct archive_entry *entry, const char *linkname)
 }
 
 void
+archive_entry_set_symlink_utf8(struct archive_entry *entry, const char *linkname)
+{
+	archive_mstring_copy_utf8(&entry->ae_symlink, linkname);
+	if (linkname != NULL)
+		entry->ae_set |= AE_SET_SYMLINK;
+	else
+		entry->ae_set &= ~AE_SET_SYMLINK;
+}
+
+void
 archive_entry_copy_symlink(struct archive_entry *entry, const char *linkname)
 {
 	archive_mstring_copy_mbs(&entry->ae_symlink, linkname);
@@ -1215,6 +1319,12 @@ archive_entry_set_uname(struct archive_entry *entry, const char *name)
 }
 
 void
+archive_entry_set_uname_utf8(struct archive_entry *entry, const char *name)
+{
+	archive_mstring_copy_utf8(&entry->ae_uname, name);
+}
+
+void
 archive_entry_copy_uname(struct archive_entry *entry, const char *name)
 {
 	archive_mstring_copy_mbs(&entry->ae_uname, name);
@@ -1629,19 +1739,23 @@ ae_strtofflags(const char *s, unsigned long *setp, unsigned long *clrp)
 	while (*start == '\t'  ||  *start == ' '  ||  *start == ',')
 		start++;
 	while (*start != '\0') {
+		size_t length;
 		/* Locate end of token. */
 		end = start;
 		while (*end != '\0'  &&  *end != '\t'  &&
 		    *end != ' '  &&  *end != ',')
 			end++;
+		length = end - start;
 		for (flag = flags; flag->name != NULL; flag++) {
-			if (memcmp(start, flag->name, end - start) == 0) {
+			size_t flag_length = strlen(flag->name);
+			if (length == flag_length
+			    && memcmp(start, flag->name, length) == 0) {
 				/* Matched "noXXXX", so reverse the sense. */
 				clear |= flag->set;
 				set |= flag->clear;
 				break;
-			} else if (memcmp(start, flag->name + 2, end - start)
-			    == 0) {
+			} else if (length == flag_length - 2
+			    && memcmp(start, flag->name + 2, length) == 0) {
 				/* Matched "XXXX", so don't reverse. */
 				set |= flag->set;
 				clear |= flag->clear;
@@ -1693,19 +1807,23 @@ ae_wcstofflags(const wchar_t *s, unsigned long *setp, unsigned long *clrp)
 	while (*start == L'\t'  ||  *start == L' '  ||  *start == L',')
 		start++;
 	while (*start != L'\0') {
+		size_t length;
 		/* Locate end of token. */
 		end = start;
 		while (*end != L'\0'  &&  *end != L'\t'  &&
 		    *end != L' '  &&  *end != L',')
 			end++;
+		length = end - start;
 		for (flag = flags; flag->wname != NULL; flag++) {
-			if (wmemcmp(start, flag->wname, end - start) == 0) {
+			size_t flag_length = wcslen(flag->wname);
+			if (length == flag_length
+			    && wmemcmp(start, flag->wname, length) == 0) {
 				/* Matched "noXXXX", so reverse the sense. */
 				clear |= flag->set;
 				set |= flag->clear;
 				break;
-			} else if (wmemcmp(start, flag->wname + 2, end - start)
-			    == 0) {
+			} else if (length == flag_length - 2
+			    && wmemcmp(start, flag->wname + 2, length) == 0) {
 				/* Matched "XXXX", so don't reverse. */
 				set |= flag->set;
 				clear |= flag->clear;
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.h b/Utilities/cmlibarchive/libarchive/archive_entry.h
index efc4d73..68d8ab9 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry.h
+++ b/Utilities/cmlibarchive/libarchive/archive_entry.h
@@ -43,15 +43,25 @@
 #include <stddef.h>  /* for wchar_t */
 #include <time.h>
 
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include <windows.h>
+#endif
+
 /* Get a suitable 64-bit integer type. */
-#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
-# define	__LA_INT64_T	__int64
-#else
-#include <unistd.h>
-# if defined(_SCO_DS) || defined(__osf__)
-#  define	__LA_INT64_T	long long
+#if !defined(__LA_INT64_T_DEFINED)
+# if ARCHIVE_VERSION_NUMBER < 4000000
+#define __LA_INT64_T la_int64_t
+# endif
+#define __LA_INT64_T_DEFINED
+# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
+typedef __int64 la_int64_t;
 # else
-#  define	__LA_INT64_T	int64_t
+#include <unistd.h>
+#  if defined(_SCO_DS) || defined(__osf__)
+typedef long long la_int64_t;
+#  else
+typedef int64_t la_int64_t;
+#  endif
 # endif
 #endif
 
@@ -202,13 +212,15 @@ __LA_DECL void		 archive_entry_fflags(struct archive_entry *,
 			    unsigned long * /* set */,
 			    unsigned long * /* clear */);
 __LA_DECL const char	*archive_entry_fflags_text(struct archive_entry *);
-__LA_DECL __LA_INT64_T	 archive_entry_gid(struct archive_entry *);
+__LA_DECL la_int64_t	 archive_entry_gid(struct archive_entry *);
 __LA_DECL const char	*archive_entry_gname(struct archive_entry *);
+__LA_DECL const char	*archive_entry_gname_utf8(struct archive_entry *);
 __LA_DECL const wchar_t	*archive_entry_gname_w(struct archive_entry *);
 __LA_DECL const char	*archive_entry_hardlink(struct archive_entry *);
+__LA_DECL const char	*archive_entry_hardlink_utf8(struct archive_entry *);
 __LA_DECL const wchar_t	*archive_entry_hardlink_w(struct archive_entry *);
-__LA_DECL __LA_INT64_T	 archive_entry_ino(struct archive_entry *);
-__LA_DECL __LA_INT64_T	 archive_entry_ino64(struct archive_entry *);
+__LA_DECL la_int64_t	 archive_entry_ino(struct archive_entry *);
+__LA_DECL la_int64_t	 archive_entry_ino64(struct archive_entry *);
 __LA_DECL int		 archive_entry_ino_is_set(struct archive_entry *);
 __LA_DECL __LA_MODE_T	 archive_entry_mode(struct archive_entry *);
 __LA_DECL time_t	 archive_entry_mtime(struct archive_entry *);
@@ -216,6 +228,7 @@ __LA_DECL long		 archive_entry_mtime_nsec(struct archive_entry *);
 __LA_DECL int		 archive_entry_mtime_is_set(struct archive_entry *);
 __LA_DECL unsigned int	 archive_entry_nlink(struct archive_entry *);
 __LA_DECL const char	*archive_entry_pathname(struct archive_entry *);
+__LA_DECL const char	*archive_entry_pathname_utf8(struct archive_entry *);
 __LA_DECL const wchar_t	*archive_entry_pathname_w(struct archive_entry *);
 __LA_DECL __LA_MODE_T	 archive_entry_perm(struct archive_entry *);
 __LA_DECL dev_t		 archive_entry_rdev(struct archive_entry *);
@@ -223,13 +236,15 @@ __LA_DECL dev_t		 archive_entry_rdevmajor(struct archive_entry *);
 __LA_DECL dev_t		 archive_entry_rdevminor(struct archive_entry *);
 __LA_DECL const char	*archive_entry_sourcepath(struct archive_entry *);
 __LA_DECL const wchar_t	*archive_entry_sourcepath_w(struct archive_entry *);
-__LA_DECL __LA_INT64_T	 archive_entry_size(struct archive_entry *);
+__LA_DECL la_int64_t	 archive_entry_size(struct archive_entry *);
 __LA_DECL int		 archive_entry_size_is_set(struct archive_entry *);
 __LA_DECL const char	*archive_entry_strmode(struct archive_entry *);
 __LA_DECL const char	*archive_entry_symlink(struct archive_entry *);
+__LA_DECL const char	*archive_entry_symlink_utf8(struct archive_entry *);
 __LA_DECL const wchar_t	*archive_entry_symlink_w(struct archive_entry *);
-__LA_DECL __LA_INT64_T	 archive_entry_uid(struct archive_entry *);
+__LA_DECL la_int64_t	 archive_entry_uid(struct archive_entry *);
 __LA_DECL const char	*archive_entry_uname(struct archive_entry *);
+__LA_DECL const char	*archive_entry_uname_utf8(struct archive_entry *);
 __LA_DECL const wchar_t	*archive_entry_uname_w(struct archive_entry *);
 __LA_DECL int archive_entry_is_data_encrypted(struct archive_entry *);
 __LA_DECL int archive_entry_is_metadata_encrypted(struct archive_entry *);
@@ -265,18 +280,21 @@ __LA_DECL const char *archive_entry_copy_fflags_text(struct archive_entry *,
 	    const char *);
 __LA_DECL const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry *,
 	    const wchar_t *);
-__LA_DECL void	archive_entry_set_gid(struct archive_entry *, __LA_INT64_T);
+__LA_DECL void	archive_entry_set_gid(struct archive_entry *, la_int64_t);
 __LA_DECL void	archive_entry_set_gname(struct archive_entry *, const char *);
+__LA_DECL void	archive_entry_set_gname_utf8(struct archive_entry *, const char *);
 __LA_DECL void	archive_entry_copy_gname(struct archive_entry *, const char *);
 __LA_DECL void	archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *);
 __LA_DECL int	archive_entry_update_gname_utf8(struct archive_entry *, const char *);
 __LA_DECL void	archive_entry_set_hardlink(struct archive_entry *, const char *);
+__LA_DECL void	archive_entry_set_hardlink_utf8(struct archive_entry *, const char *);
 __LA_DECL void	archive_entry_copy_hardlink(struct archive_entry *, const char *);
 __LA_DECL void	archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *);
 __LA_DECL int	archive_entry_update_hardlink_utf8(struct archive_entry *, const char *);
-__LA_DECL void	archive_entry_set_ino(struct archive_entry *, __LA_INT64_T);
-__LA_DECL void	archive_entry_set_ino64(struct archive_entry *, __LA_INT64_T);
+__LA_DECL void	archive_entry_set_ino(struct archive_entry *, la_int64_t);
+__LA_DECL void	archive_entry_set_ino64(struct archive_entry *, la_int64_t);
 __LA_DECL void	archive_entry_set_link(struct archive_entry *, const char *);
+__LA_DECL void	archive_entry_set_link_utf8(struct archive_entry *, const char *);
 __LA_DECL void	archive_entry_copy_link(struct archive_entry *, const char *);
 __LA_DECL void	archive_entry_copy_link_w(struct archive_entry *, const wchar_t *);
 __LA_DECL int	archive_entry_update_link_utf8(struct archive_entry *, const char *);
@@ -285,6 +303,7 @@ __LA_DECL void	archive_entry_set_mtime(struct archive_entry *, time_t, long);
 __LA_DECL void  archive_entry_unset_mtime(struct archive_entry *);
 __LA_DECL void	archive_entry_set_nlink(struct archive_entry *, unsigned int);
 __LA_DECL void	archive_entry_set_pathname(struct archive_entry *, const char *);
+__LA_DECL void	archive_entry_set_pathname_utf8(struct archive_entry *, const char *);
 __LA_DECL void	archive_entry_copy_pathname(struct archive_entry *, const char *);
 __LA_DECL void	archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *);
 __LA_DECL int	archive_entry_update_pathname_utf8(struct archive_entry *, const char *);
@@ -292,16 +311,18 @@ __LA_DECL void	archive_entry_set_perm(struct archive_entry *, __LA_MODE_T);
 __LA_DECL void	archive_entry_set_rdev(struct archive_entry *, dev_t);
 __LA_DECL void	archive_entry_set_rdevmajor(struct archive_entry *, dev_t);
 __LA_DECL void	archive_entry_set_rdevminor(struct archive_entry *, dev_t);
-__LA_DECL void	archive_entry_set_size(struct archive_entry *, __LA_INT64_T);
+__LA_DECL void	archive_entry_set_size(struct archive_entry *, la_int64_t);
 __LA_DECL void	archive_entry_unset_size(struct archive_entry *);
 __LA_DECL void	archive_entry_copy_sourcepath(struct archive_entry *, const char *);
 __LA_DECL void	archive_entry_copy_sourcepath_w(struct archive_entry *, const wchar_t *);
 __LA_DECL void	archive_entry_set_symlink(struct archive_entry *, const char *);
+__LA_DECL void	archive_entry_set_symlink_utf8(struct archive_entry *, const char *);
 __LA_DECL void	archive_entry_copy_symlink(struct archive_entry *, const char *);
 __LA_DECL void	archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *);
 __LA_DECL int	archive_entry_update_symlink_utf8(struct archive_entry *, const char *);
-__LA_DECL void	archive_entry_set_uid(struct archive_entry *, __LA_INT64_T);
+__LA_DECL void	archive_entry_set_uid(struct archive_entry *, la_int64_t);
 __LA_DECL void	archive_entry_set_uname(struct archive_entry *, const char *);
+__LA_DECL void	archive_entry_set_uname_utf8(struct archive_entry *, const char *);
 __LA_DECL void	archive_entry_copy_uname(struct archive_entry *, const char *);
 __LA_DECL void	archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *);
 __LA_DECL int	archive_entry_update_uname_utf8(struct archive_entry *, const char *);
@@ -515,7 +536,7 @@ __LA_DECL int	archive_entry_xattr_next(struct archive_entry *,
 
 __LA_DECL void	 archive_entry_sparse_clear(struct archive_entry *);
 __LA_DECL void	 archive_entry_sparse_add_entry(struct archive_entry *,
-	    __LA_INT64_T /* offset */, __LA_INT64_T /* length */);
+	    la_int64_t /* offset */, la_int64_t /* length */);
 
 /*
  * To retrieve the xattr list, first "reset", then repeatedly ask for the
@@ -525,7 +546,7 @@ __LA_DECL void	 archive_entry_sparse_add_entry(struct archive_entry *,
 __LA_DECL int	archive_entry_sparse_count(struct archive_entry *);
 __LA_DECL int	archive_entry_sparse_reset(struct archive_entry *);
 __LA_DECL int	archive_entry_sparse_next(struct archive_entry *,
-	    __LA_INT64_T * /* offset */, __LA_INT64_T * /* length */);
+	    la_int64_t * /* offset */, la_int64_t * /* length */);
 
 /*
  * Utility to match up hardlinks.
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_acl.3 b/Utilities/cmlibarchive/libarchive/archive_entry_acl.3
index f5c3377..5aff996 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry_acl.3
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_acl.3
@@ -226,8 +226,8 @@ The returned long string is valid until the next call to
 or
 .Fn archive_entry_acl_text_w .
 .Sh SEE ALSO
-.Xr archive 3 ,
 .Xr archive_entry 3
+.Xr libarchive 3 ,
 .Sh BUGS
 .Dv ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID
 and
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_paths.3 b/Utilities/cmlibarchive/libarchive/archive_entry_paths.3
index 51c8b8c..fd22cf7 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry_paths.3
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_paths.3
@@ -149,5 +149,5 @@ It doesn't have a corresponding get accessor function.
 is an alias for 
 .Fn archive_entry_copy_XXX .
 .Sh SEE ALSO
-.Xr archive 3 ,
 .Xr archive_entry 3
+.Xr libarchive 3 ,
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_perms.3 b/Utilities/cmlibarchive/libarchive/archive_entry_perms.3
index 5b7b5d9..340c5ea 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry_perms.3
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_perms.3
@@ -194,11 +194,11 @@ every name that is recognized.
 .Xr strtofflags 3 ,
 which stops parsing at the first unrecognized name.)
 .Sh SEE ALSO
-.Xr archive 3 ,
 .Xr archive_entry 3 ,
 .Xr archive_entry_acl 3 ,
 .Xr archive_read_disk 3 ,
 .Xr archive_write_disk 3
+.Xr libarchive 3 ,
 .Sh BUGS
 The platform types
 .Vt uid_t
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_stat.3 b/Utilities/cmlibarchive/libarchive/archive_entry_stat.3
index 84a4ea1..26611e4 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry_stat.3
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_stat.3
@@ -226,7 +226,7 @@ and
 are used by
 .Xr archive_entry_linkify 3
 to find hardlinks.
-The pair of device and inode is suppossed to identify hardlinked files.
+The pair of device and inode is supposed to identify hardlinked files.
 .Pp
 The device major and minor number can be obtained independently using
 .Fn archive_entry_devmajor
@@ -267,8 +267,8 @@ platforms.
 Some archive formats use the combined form, while other formats use
 the split form.
 .Sh SEE ALSO
-.Xr archive 3 ,
 .Xr archive_entry_acl 3 ,
 .Xr archive_entry_perms 3 ,
 .Xr archive_entry_time 3 ,
+.Xr libarchive 3 ,
 .Xr stat 2
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_time.3 b/Utilities/cmlibarchive/libarchive/archive_entry_time.3
index 17c658a..1864521 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry_time.3
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_time.3
@@ -113,8 +113,8 @@ The current state can be queried using
 .Fn XXX_is_set .
 Unset time fields have a second and nanosecond field of 0.
 .Sh SEE ALSO
-.Xr archive 3 ,
 .Xr archive_entry 3
+.Xr libarchive 3 ,
 .Sh HISTORY
 The
 .Nm libarchive
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_xattr.c b/Utilities/cmlibarchive/libarchive/archive_entry_xattr.c
index a3efe7c..05eb90f 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry_xattr.c
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_xattr.c
@@ -98,7 +98,10 @@ archive_entry_xattr_add_entry(struct archive_entry *entry,
 		/* XXX Error XXX */
 		return;
 
-	xp->name = strdup(name);
+	if ((xp->name = strdup(name)) == NULL)
+		/* XXX Error XXX */
+		return;
+
 	if ((xp->value = malloc(size)) != NULL) {
 		memcpy(xp->value, value, size);
 		xp->size = size;
diff --git a/Utilities/cmlibarchive/libarchive/archive_hmac.c b/Utilities/cmlibarchive/libarchive/archive_hmac.c
new file mode 100644
index 0000000..36e3e1c
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_hmac.c
@@ -0,0 +1,234 @@
+/*-
+* Copyright (c) 2014 Michihiro NAKAJIMA
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "archive_platform.h"
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#include "archive.h"
+#include "archive_hmac_private.h"
+
+#ifdef ARCHIVE_HMAC_USE_Apple_CommonCrypto
+
+static int
+__hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len)
+{
+	CCHmacInit(ctx, kCCHmacAlgSHA1, key, key_len);
+	return 0;
+}
+
+static void
+__hmac_sha1_update(archive_hmac_sha1_ctx *ctx, const uint8_t *data,
+    size_t data_len)
+{
+	CCHmacUpdate(ctx, data, data_len);
+}
+
+static void
+__hmac_sha1_final(archive_hmac_sha1_ctx *ctx, uint8_t *out, size_t *out_len)
+{
+	CCHmacFinal(ctx, out);
+	*out_len = 20;
+}
+
+static void
+__hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx)
+{
+	memset(ctx, 0, sizeof(*ctx));
+}
+
+#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H)
+
+static int
+__hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len)
+{
+	BCRYPT_ALG_HANDLE hAlg;
+	BCRYPT_HASH_HANDLE hHash;
+	DWORD hash_len;
+	PBYTE hash;
+	ULONG result;
+	NTSTATUS status;
+
+	ctx->hAlg = NULL;
+	status = BCryptOpenAlgorithmProvider(&hAlg, BCRYPT_SHA1_ALGORITHM,
+		MS_PRIMITIVE_PROVIDER, BCRYPT_ALG_HANDLE_HMAC_FLAG);
+	if (!BCRYPT_SUCCESS(status))
+		return -1;
+	status = BCryptGetProperty(hAlg, BCRYPT_HASH_LENGTH, (PUCHAR)&hash_len,
+		sizeof(hash_len), &result, 0);
+	if (!BCRYPT_SUCCESS(status)) {
+		BCryptCloseAlgorithmProvider(hAlg, 0);
+		return -1;
+	}
+	hash = (PBYTE)HeapAlloc(GetProcessHeap(), 0, hash_len);
+	if (hash == NULL) {
+		BCryptCloseAlgorithmProvider(hAlg, 0);
+		return -1;
+	}
+	status = BCryptCreateHash(hAlg, &hHash, NULL, 0,
+		(PUCHAR)key, (ULONG)key_len, BCRYPT_HASH_REUSABLE_FLAG);
+	if (!BCRYPT_SUCCESS(status)) {
+		BCryptCloseAlgorithmProvider(hAlg, 0);
+		HeapFree(GetProcessHeap(), 0, hash);
+		return -1;
+	}
+
+	ctx->hAlg = hAlg;
+	ctx->hHash = hHash;
+	ctx->hash_len = hash_len;
+	ctx->hash = hash;
+
+	return 0;
+}
+
+static void
+__hmac_sha1_update(archive_hmac_sha1_ctx *ctx, const uint8_t *data,
+	size_t data_len)
+{
+	BCryptHashData(ctx->hHash, (PUCHAR)(uintptr_t)data, (ULONG)data_len, 0);
+}
+
+static void
+__hmac_sha1_final(archive_hmac_sha1_ctx *ctx, uint8_t *out, size_t *out_len)
+{
+	BCryptFinishHash(ctx->hHash, ctx->hash, ctx->hash_len, 0);
+	if (ctx->hash_len == *out_len)
+		memcpy(out, ctx->hash, *out_len);
+}
+
+static void
+__hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx)
+{
+	if (ctx->hAlg != NULL) {
+		BCryptCloseAlgorithmProvider(ctx->hAlg, 0);
+		HeapFree(GetProcessHeap(), 0, ctx->hash);
+		ctx->hAlg = NULL;
+	}
+}
+
+#elif defined(HAVE_LIBNETTLE)
+
+static int
+__hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len)
+{
+	hmac_sha1_set_key(ctx, key_len, key);
+	return 0;
+}
+
+static void
+__hmac_sha1_update(archive_hmac_sha1_ctx *ctx, const uint8_t *data,
+    size_t data_len)
+{
+	hmac_sha1_update(ctx, data_len, data);
+}
+
+static void
+__hmac_sha1_final(archive_hmac_sha1_ctx *ctx, uint8_t *out, size_t *out_len)
+{
+	hmac_sha1_digest(ctx, (unsigned)*out_len, out);
+}
+
+static void
+__hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx)
+{
+	memset(ctx, 0, sizeof(*ctx));
+}
+
+#elif defined(HAVE_LIBCRYPTO)
+
+static int
+__hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len)
+{
+	HMAC_CTX_init(ctx);
+	HMAC_Init(ctx, key, key_len, EVP_sha1());
+	return 0;
+}
+
+static void
+__hmac_sha1_update(archive_hmac_sha1_ctx *ctx, const uint8_t *data,
+    size_t data_len)
+{
+	HMAC_Update(ctx, data, data_len);
+}
+
+static void
+__hmac_sha1_final(archive_hmac_sha1_ctx *ctx, uint8_t *out, size_t *out_len)
+{
+	unsigned int len = (unsigned int)*out_len;
+	HMAC_Final(ctx, out, &len);
+	*out_len = len;
+}
+
+static void
+__hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx)
+{
+	HMAC_CTX_cleanup(ctx);
+	memset(ctx, 0, sizeof(*ctx));
+}
+
+#else
+
+/* Stub */
+static int
+__hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len)
+{
+	(void)ctx;/* UNUSED */
+	(void)key;/* UNUSED */
+	(void)key_len;/* UNUSED */
+	return -1;
+}
+
+static void
+__hmac_sha1_update(archive_hmac_sha1_ctx *ctx, const uint8_t *data,
+    size_t data_len)
+{
+	(void)ctx;/* UNUSED */
+	(void)data;/* UNUSED */
+	(void)data_len;/* UNUSED */
+}
+
+static void
+__hmac_sha1_final(archive_hmac_sha1_ctx *ctx, uint8_t *out, size_t *out_len)
+{
+	(void)ctx;/* UNUSED */
+	(void)out;/* UNUSED */
+	(void)out_len;/* UNUSED */
+}
+
+static void
+__hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx)
+{
+	(void)ctx;/* UNUSED */
+}
+
+#endif
+
+const struct archive_hmac __archive_hmac = {
+	&__hmac_sha1_init,
+	&__hmac_sha1_update,
+	&__hmac_sha1_final,
+	&__hmac_sha1_cleanup,
+};
diff --git a/Utilities/cmlibarchive/libarchive/archive_hmac_private.h b/Utilities/cmlibarchive/libarchive/archive_hmac_private.h
new file mode 100644
index 0000000..a9fb8ec
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_hmac_private.h
@@ -0,0 +1,95 @@
+/*-
+* Copyright (c) 2014 Michihiro NAKAJIMA
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
+#endif
+
+#ifndef ARCHIVE_HMAC_PRIVATE_H_INCLUDED
+#define ARCHIVE_HMAC_PRIVATE_H_INCLUDED
+
+#ifdef __APPLE__
+# include <AvailabilityMacros.h>
+# if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
+#  define ARCHIVE_HMAC_USE_Apple_CommonCrypto
+# endif
+#endif
+
+#ifdef ARCHIVE_HMAC_USE_Apple_CommonCrypto
+#include <CommonCrypto/CommonHMAC.h>
+
+typedef	CCHmacContext archive_hmac_sha1_ctx;
+
+#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H)
+#include <bcrypt.h>
+
+typedef struct {
+	BCRYPT_ALG_HANDLE	hAlg;
+	BCRYPT_HASH_HANDLE	hHash;
+	DWORD				hash_len;
+	PBYTE				hash;
+
+} archive_hmac_sha1_ctx;
+
+#elif defined(HAVE_LIBNETTLE)
+#include <nettle/hmac.h>
+
+typedef	struct hmac_sha1_ctx archive_hmac_sha1_ctx;
+
+#elif defined(HAVE_LIBCRYPTO)
+#include <openssl/hmac.h>
+
+typedef	HMAC_CTX archive_hmac_sha1_ctx;
+
+#else
+
+typedef int archive_hmac_sha1_ctx;
+
+#endif
+
+
+/* HMAC */
+#define archive_hmac_sha1_init(ctx, key, key_len)\
+	__archive_hmac.__hmac_sha1_init(ctx, key, key_len)
+#define archive_hmac_sha1_update(ctx, data, data_len)\
+	__archive_hmac.__hmac_sha1_update(ctx, data, data_len)
+#define archive_hmac_sha1_final(ctx, out, out_len)\
+  	__archive_hmac.__hmac_sha1_final(ctx, out, out_len)
+#define archive_hmac_sha1_cleanup(ctx)\
+	__archive_hmac.__hmac_sha1_cleanup(ctx)
+
+
+struct archive_hmac {
+	/* HMAC */
+	int (*__hmac_sha1_init)(archive_hmac_sha1_ctx *, const uint8_t *,
+		size_t);
+	void (*__hmac_sha1_update)(archive_hmac_sha1_ctx *, const uint8_t *,
+		size_t);
+	void (*__hmac_sha1_final)(archive_hmac_sha1_ctx *, uint8_t *, size_t *);
+	void (*__hmac_sha1_cleanup)(archive_hmac_sha1_ctx *);
+};
+
+extern const struct archive_hmac __archive_hmac;
+#endif /* ARCHIVE_HMAC_PRIVATE_H_INCLUDED */
diff --git a/Utilities/cmlibarchive/libarchive/archive_match.c b/Utilities/cmlibarchive/libarchive/archive_match.c
index 6fb8644..74aaacb 100644
--- a/Utilities/cmlibarchive/libarchive/archive_match.c
+++ b/Utilities/cmlibarchive/libarchive/archive_match.c
@@ -580,6 +580,7 @@ add_pattern_from_file(struct archive_match *a, struct match_list *mlist,
 		return (ARCHIVE_FATAL);
 	}
 	r = archive_read_support_format_raw(ar);
+	r = archive_read_support_format_empty(ar);
 	if (r != ARCHIVE_OK) {
 		archive_copy_error(&(a->archive), ar);
 		archive_read_free(ar);
@@ -596,9 +597,13 @@ add_pattern_from_file(struct archive_match *a, struct match_list *mlist,
 	}
 	r = archive_read_next_header(ar, &ae);
 	if (r != ARCHIVE_OK) {
-		archive_copy_error(&(a->archive), ar);
 		archive_read_free(ar);
-		return (r);
+		if (r == ARCHIVE_EOF) {
+			return (ARCHIVE_OK);
+		} else {
+			archive_copy_error(&(a->archive), ar);
+			return (r);
+		}
 	}
 
 	archive_string_init(&as);
diff --git a/Utilities/cmlibarchive/libarchive/archive_pathmatch.c b/Utilities/cmlibarchive/libarchive/archive_pathmatch.c
index 505252a..619e2b6 100644
--- a/Utilities/cmlibarchive/libarchive/archive_pathmatch.c
+++ b/Utilities/cmlibarchive/libarchive/archive_pathmatch.c
@@ -394,8 +394,8 @@ __archive_pathmatch(const char *p, const char *s, int flags)
 	if (*p == '/' && *s != '/')
 		return (0);
 
-	/* Certain patterns and file names anchor implicitly. */
-	if (*p == '*' || *p == '/' || *p == '/') {
+	/* Certain patterns anchor implicitly. */
+	if (*p == '*' || *p == '/') {
 		while (*p == '/')
 			++p;
 		while (*s == '/')
@@ -434,8 +434,8 @@ __archive_pathmatch_w(const wchar_t *p, const wchar_t *s, int flags)
 	if (*p == L'/' && *s != L'/')
 		return (0);
 
-	/* Certain patterns and file names anchor implicitly. */
-	if (*p == L'*' || *p == L'/' || *p == L'/') {
+	/* Certain patterns anchor implicitly. */
+	if (*p == L'*' || *p == L'/') {
 		while (*p == L'/')
 			++p;
 		while (*s == L'/')
diff --git a/Utilities/cmlibarchive/libarchive/archive_private.h b/Utilities/cmlibarchive/libarchive/archive_private.h
index 30d472f..4b4be97 100644
--- a/Utilities/cmlibarchive/libarchive/archive_private.h
+++ b/Utilities/cmlibarchive/libarchive/archive_private.h
@@ -119,6 +119,23 @@ struct archive {
 	unsigned current_codepage; /* Current ACP(ANSI CodePage). */
 	unsigned current_oemcp; /* Current OEMCP(OEM CodePage). */
 	struct archive_string_conv *sconv;
+
+	/*
+	 * Used by archive_read_data() to track blocks and copy
+	 * data to client buffers, filling gaps with zero bytes.
+	 */
+	const char	 *read_data_block;
+	int64_t		  read_data_offset;
+	int64_t		  read_data_output_offset;
+	size_t		  read_data_remaining;
+
+	/*
+	 * Used by formats/filters to determine the amount of data
+	 * requested from a call to archive_read_data(). This is only
+	 * useful when the format/filter has seek support.
+	 */
+	char		  read_data_is_posix_read;
+	size_t		  read_data_requested;
 };
 
 /* Check magic value and state; return(ARCHIVE_FATAL) if it isn't valid. */
@@ -139,6 +156,8 @@ int	__archive_mktemp(const char *tmpdir);
 
 int	__archive_clean(struct archive *);
 
+void __archive_reset_read_data(struct archive *);
+
 #define	err_combine(a,b)	((a) < (b) ? (a) : (b))
 
 #if defined(__BORLANDC__) || (defined(_MSC_VER) &&  _MSC_VER <= 1300)
diff --git a/Utilities/cmlibarchive/libarchive/archive_random.c b/Utilities/cmlibarchive/libarchive/archive_random.c
new file mode 100644
index 0000000..a20b9b1
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_random.c
@@ -0,0 +1,269 @@
+/*-
+ * Copyright (c) 2014 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "archive_platform.h"
+__FBSDID("$FreeBSD$");
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#if !defined(HAVE_ARC4RANDOM_BUF) && (!defined(_WIN32) || defined(__CYGWIN__))
+
+#ifdef HAVE_FCNTL
+#include <fcntl.h>
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_PTHREAD_H
+#include <pthread.h>
+#endif
+
+static void arc4random_buf(void *, size_t);
+
+#endif /* HAVE_ARC4RANDOM_BUF */
+
+#include "archive.h"
+#include "archive_random_private.h"
+
+#if defined(HAVE_WINCRYPT_H) && !defined(__CYGWIN__)
+#include <wincrypt.h>
+#endif
+
+#ifndef O_CLOEXEC
+#define O_CLOEXEC	0
+#endif
+
+/*
+ * Random number generator function.
+ * This simply calls arc4random_buf function if the platform provides it.
+ */
+
+int
+archive_random(void *buf, size_t nbytes)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+	HCRYPTPROV hProv;
+	BOOL success;
+
+	success = CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL,
+	    CRYPT_VERIFYCONTEXT);
+	if (!success && GetLastError() == NTE_BAD_KEYSET) {
+		success = CryptAcquireContext(&hProv, NULL, NULL,
+		    PROV_RSA_FULL, CRYPT_NEWKEYSET);
+	}
+	if (success) {
+		success = CryptGenRandom(hProv, (DWORD)nbytes, (BYTE*)buf);
+		CryptReleaseContext(hProv, 0);
+		if (success)
+			return ARCHIVE_OK;
+	}
+	/* TODO: Does this case really happen? */
+	return ARCHIVE_FAILED;
+#else
+	arc4random_buf(buf, nbytes);
+	return ARCHIVE_OK;
+#endif
+}
+
+#if !defined(HAVE_ARC4RANDOM_BUF) && (!defined(_WIN32) || defined(__CYGWIN__))
+
+/*	$OpenBSD: arc4random.c,v 1.24 2013/06/11 16:59:50 deraadt Exp $	*/
+/*
+ * Copyright (c) 1996, David Mazieres <dm at uun.org>
+ * Copyright (c) 2008, Damien Miller <djm at openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Arc4 random number generator for OpenBSD.
+ *
+ * This code is derived from section 17.1 of Applied Cryptography,
+ * second edition, which describes a stream cipher allegedly
+ * compatible with RSA Labs "RC4" cipher (the actual description of
+ * which is a trade secret).  The same algorithm is used as a stream
+ * cipher called "arcfour" in Tatu Ylonen's ssh package.
+ *
+ * RC4 is a registered trademark of RSA Laboratories.
+ */
+
+#ifdef __GNUC__
+#define inline __inline
+#else				/* !__GNUC__ */
+#define inline
+#endif				/* !__GNUC__ */
+
+struct arc4_stream {
+	uint8_t i;
+	uint8_t j;
+	uint8_t s[256];
+};
+
+#define	RANDOMDEV	"/dev/urandom"
+#define	KEYSIZE		128
+#ifdef HAVE_PTHREAD_H
+static pthread_mutex_t	arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
+#define	_ARC4_LOCK()	pthread_mutex_lock(&arc4random_mtx);
+#define	_ARC4_UNLOCK()  pthread_mutex_unlock(&arc4random_mtx);
+#else
+#define	_ARC4_LOCK()
+#define	_ARC4_UNLOCK()
+#endif
+
+static int rs_initialized;
+static struct arc4_stream rs;
+static pid_t arc4_stir_pid;
+static int arc4_count;
+
+static inline uint8_t arc4_getbyte(void);
+static void arc4_stir(void);
+
+static inline void
+arc4_init(void)
+{
+	int     n;
+
+	for (n = 0; n < 256; n++)
+		rs.s[n] = n;
+	rs.i = 0;
+	rs.j = 0;
+}
+
+static inline void
+arc4_addrandom(u_char *dat, int datlen)
+{
+	int     n;
+	uint8_t si;
+
+	rs.i--;
+	for (n = 0; n < 256; n++) {
+		rs.i = (rs.i + 1);
+		si = rs.s[rs.i];
+		rs.j = (rs.j + si + dat[n % datlen]);
+		rs.s[rs.i] = rs.s[rs.j];
+		rs.s[rs.j] = si;
+	}
+	rs.j = rs.i;
+}
+
+static void
+arc4_stir(void)
+{
+	int done, fd, i;
+	struct {
+		struct timeval	tv;
+		pid_t		pid;
+		u_char	 	rnd[KEYSIZE];
+	} rdat;
+
+	if (!rs_initialized) {
+		arc4_init();
+		rs_initialized = 1;
+	}
+	done = 0;
+	fd = open(RANDOMDEV, O_RDONLY | O_CLOEXEC, 0);
+	if (fd >= 0) {
+		if (read(fd, &rdat, KEYSIZE) == KEYSIZE)
+			done = 1;
+		(void)close(fd);
+	}
+	if (!done) {
+		(void)gettimeofday(&rdat.tv, NULL);
+		rdat.pid = getpid();
+		/* We'll just take whatever was on the stack too... */
+	}
+
+	arc4_addrandom((u_char *)&rdat, KEYSIZE);
+
+	/*
+	 * Discard early keystream, as per recommendations in:
+	 * "(Not So) Random Shuffles of RC4" by Ilya Mironov.
+	 */
+	for (i = 0; i < 1024; i++)
+		(void)arc4_getbyte();
+	arc4_count = 1600000;
+}
+
+static void
+arc4_stir_if_needed(void)
+{
+	pid_t pid = getpid();
+
+	if (arc4_count <= 0 || !rs_initialized || arc4_stir_pid != pid) {
+		arc4_stir_pid = pid;
+		arc4_stir();
+	}
+}
+
+static inline uint8_t
+arc4_getbyte(void)
+{
+	uint8_t si, sj;
+
+	rs.i = (rs.i + 1);
+	si = rs.s[rs.i];
+	rs.j = (rs.j + si);
+	sj = rs.s[rs.j];
+	rs.s[rs.i] = sj;
+	rs.s[rs.j] = si;
+	return (rs.s[(si + sj) & 0xff]);
+}
+
+static void
+arc4random_buf(void *_buf, size_t n)
+{
+	u_char *buf = (u_char *)_buf;
+	_ARC4_LOCK();
+	arc4_stir_if_needed();
+	while (n--) {
+		if (--arc4_count <= 0)
+			arc4_stir();
+		buf[n] = arc4_getbyte();
+	}
+	_ARC4_UNLOCK();
+}
+
+#endif /* !HAVE_ARC4RANDOM_BUF */
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c b/Utilities/cmlibarchive/libarchive/archive_random_private.h
similarity index 50%
copy from Utilities/cmlibarchive/libarchive/archive_write_add_filter.c
copy to Utilities/cmlibarchive/libarchive/archive_random_private.h
index 81dd683..c414779 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c
+++ b/Utilities/cmlibarchive/libarchive/archive_random_private.h
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2012 Ondrej Holy
+ * Copyright (c) 2014 Michihiro NAKAJIMA
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -23,48 +23,14 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "archive_platform.h"
-__FBSDID("$FreeBSD$");
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
 #endif
 
-#include "archive.h"
-#include "archive_private.h"
-
-/* A table that maps filter codes to functions. */
-static
-struct { int code; int (*setter)(struct archive *); } codes[] =
-{
-	{ ARCHIVE_FILTER_NONE,		archive_write_add_filter_none },
-	{ ARCHIVE_FILTER_GZIP,		archive_write_add_filter_gzip },
-	{ ARCHIVE_FILTER_BZIP2,		archive_write_add_filter_bzip2 },
-	{ ARCHIVE_FILTER_COMPRESS,	archive_write_add_filter_compress },
-	{ ARCHIVE_FILTER_GRZIP,		archive_write_add_filter_grzip },
-	{ ARCHIVE_FILTER_LRZIP,		archive_write_add_filter_lrzip },
-	{ ARCHIVE_FILTER_LZIP,		archive_write_add_filter_lzip },
-	{ ARCHIVE_FILTER_LZMA,		archive_write_add_filter_lzma },
-	{ ARCHIVE_FILTER_LZOP,		archive_write_add_filter_lzip },
-	{ ARCHIVE_FILTER_UU,		archive_write_add_filter_uuencode },
-	{ ARCHIVE_FILTER_XZ,		archive_write_add_filter_xz },
-	{ -1,			NULL }
-};
-
-int
-archive_write_add_filter(struct archive *a, int code)
-{
-	int i;
+#ifndef ARCHIVE_RANDOM_PRIVATE_H_INCLUDED
+#define ARCHIVE_RANDOM_PRIVATE_H_INCLUDED
 
-	for (i = 0; codes[i].code != -1; i++) {
-		if (code == codes[i].code)
-			return ((codes[i].setter)(a));
-	}
+/* Random number generator. */
+int archive_random(void *buf, size_t nbytes);
 
-	archive_set_error(a, EINVAL, "No such filter");
-	return (ARCHIVE_FATAL);
-}
+#endif /* ARCHIVE_RANDOM_PRIVATE_H_INCLUDED */
diff --git a/Utilities/cmlibarchive/libarchive/archive_read.3 b/Utilities/cmlibarchive/libarchive/archive_read.3
index a29cc1e..d37e732 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read.3
+++ b/Utilities/cmlibarchive/libarchive/archive_read.3
@@ -130,7 +130,7 @@ which provides a slightly more efficient interface.
 You may prefer to use the higher-level
 .Fn archive_read_data_skip ,
 which reads and discards the data for this entry,
-.Fn archive_read_data_to_file ,
+.Fn archive_read_data_into_fd ,
 which copies the data to the provided file descriptor, or
 .Fn archive_read_extract ,
 which recreates the specified entry on disk and copies data
@@ -186,7 +186,7 @@ list_archive(const char *name)
   free(mydata);
 }
 
-ssize_t
+la_ssize_t
 myread(struct archive *a, void *client_data, const void **buff)
 {
   struct mydata *mydata = client_data;
diff --git a/Utilities/cmlibarchive/libarchive/archive_read.c b/Utilities/cmlibarchive/libarchive/archive_read.c
index a65b94d..033ed8b 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read.c
@@ -101,16 +101,17 @@ archive_read_new(void)
 {
 	struct archive_read *a;
 
-	a = (struct archive_read *)malloc(sizeof(*a));
+	a = (struct archive_read *)calloc(1, sizeof(*a));
 	if (a == NULL)
 		return (NULL);
-	memset(a, 0, sizeof(*a));
 	a->archive.magic = ARCHIVE_READ_MAGIC;
 
 	a->archive.state = ARCHIVE_STATE_NEW;
 	a->entry = archive_entry_new2(&a->archive);
 	a->archive.vtable = archive_read_vtable();
 
+	a->passphrases.last = &a->passphrases.first;
+
 	return (&a->archive);
 }
 
@@ -194,10 +195,12 @@ client_skip_proxy(struct archive_read_filter *self, int64_t request)
 				ask = skip_limit;
 			get = (self->archive->client.skipper)
 				(&self->archive->archive, self->data, ask);
-			if (get == 0)
+			total += get;
+			if (get == 0 || get == request)
 				return (total);
+			if (get > request)
+				return ARCHIVE_FATAL;
 			request -= get;
-			total += get;
 		}
 	} else if (self->archive->client.seeker != NULL
 		&& request > 64 * 1024) {
@@ -230,8 +233,11 @@ client_seek_proxy(struct archive_read_filter *self, int64_t offset, int whence)
 	 * other libarchive code that assumes a successful forward
 	 * seek means it can also seek backwards.
 	 */
-	if (self->archive->client.seeker == NULL)
+	if (self->archive->client.seeker == NULL) {
+		archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
+		    "Current client reader does not support seeking a device");
 		return (ARCHIVE_FAILED);
+	}
 	return (self->archive->client.seeker)(&self->archive->archive,
 	    self->data, offset, whence);
 }
@@ -454,7 +460,7 @@ archive_read_open1(struct archive *_a)
 {
 	struct archive_read *a = (struct archive_read *)_a;
 	struct archive_read_filter *filter, *tmp;
-	int slot, e;
+	int slot, e = ARCHIVE_OK;
 	unsigned int i;
 
 	archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
@@ -544,13 +550,13 @@ archive_read_open1(struct archive *_a)
 static int
 choose_filters(struct archive_read *a)
 {
-	int number_bidders, i, bid, best_bid;
+	int number_bidders, i, bid, best_bid, n;
 	struct archive_read_filter_bidder *bidder, *best_bidder;
 	struct archive_read_filter *filter;
 	ssize_t avail;
 	int r;
 
-	for (;;) {
+	for (n = 0; n < 25; ++n) {
 		number_bidders = sizeof(a->bidders) / sizeof(a->bidders[0]);
 
 		best_bid = 0;
@@ -596,6 +602,9 @@ choose_filters(struct archive_read *a)
 			return (ARCHIVE_FATAL);
 		}
 	}
+	archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+	    "Input requires too many filters for decoding");
+	return (ARCHIVE_FATAL);
 }
 
 /*
@@ -658,16 +667,14 @@ _archive_read_next_header2(struct archive *_a, struct archive_entry *entry)
 		break;
 	}
 
-	a->read_data_output_offset = 0;
-	a->read_data_remaining = 0;
-	a->read_data_is_posix_read = 0;
-	a->read_data_requested = 0;
+	__archive_reset_read_data(&a->archive);
+
 	a->data_start_node = a->client.cursor;
 	/* EOF always wins; otherwise return the worst error. */
 	return (r2 < r1 || r2 == ARCHIVE_EOF) ? r2 : r1;
 }
 
-int
+static int
 _archive_read_next_header(struct archive *_a, struct archive_entry **entryp)
 {
 	int ret;
@@ -813,7 +820,7 @@ archive_read_format_capabilities(struct archive *_a)
 ssize_t
 archive_read_data(struct archive *_a, void *buff, size_t s)
 {
-	struct archive_read *a = (struct archive_read *)_a;
+	struct archive *a = (struct archive *)_a;
 	char	*dest;
 	const void *read_buf;
 	size_t	 bytes_read;
@@ -828,7 +835,7 @@ archive_read_data(struct archive *_a, void *buff, size_t s)
 			read_buf = a->read_data_block;
 			a->read_data_is_posix_read = 1;
 			a->read_data_requested = s;
-			r = _archive_read_data_block(&a->archive, &read_buf,
+			r = archive_read_data_block(a, &read_buf,
 			    &a->read_data_remaining, &a->read_data_offset);
 			a->read_data_block = read_buf;
 			if (r == ARCHIVE_EOF)
@@ -843,7 +850,7 @@ archive_read_data(struct archive *_a, void *buff, size_t s)
 		}
 
 		if (a->read_data_offset < a->read_data_output_offset) {
-			archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+			archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,
 			    "Encountered out-of-order sparse blocks");
 			return (ARCHIVE_RETRY);
 		}
@@ -887,6 +894,21 @@ archive_read_data(struct archive *_a, void *buff, size_t s)
 }
 
 /*
+ * Reset the read_data_* variables, used for starting a new entry.
+ */
+void __archive_reset_read_data(struct archive * a)
+{
+	a->read_data_output_offset = 0;
+	a->read_data_remaining = 0;
+	a->read_data_is_posix_read = 0;
+	a->read_data_requested = 0;
+
+   /* extra resets, from rar.c */
+   a->read_data_block = NULL;
+   a->read_data_offset = 0;
+}
+
+/*
  * Skip over all remaining data in this entry.
  */
 int
@@ -953,7 +975,7 @@ _archive_read_data_block(struct archive *_a,
 	if (a->format->read_data == NULL) {
 		archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
 		    "Internal error: "
-		    "No format_read_data_block function registered");
+		    "No format->read_data function registered");
 		return (ARCHIVE_FATAL);
 	}
 
@@ -1040,6 +1062,7 @@ static int
 _archive_read_free(struct archive *_a)
 {
 	struct archive_read *a = (struct archive_read *)_a;
+	struct archive_read_passphrase *p;
 	int i, n;
 	int slots;
 	int r = ARCHIVE_OK;
@@ -1077,9 +1100,20 @@ _archive_read_free(struct archive *_a)
 		}
 	}
 
+	/* Release passphrase list. */
+	p = a->passphrases.first;
+	while (p != NULL) {
+		struct archive_read_passphrase *np = p->next;
+
+		/* A passphrase should be cleaned. */
+		memset(p->passphrase, 0, strlen(p->passphrase));
+		free(p->passphrase);
+		free(p);
+		p = np;
+	}
+
 	archive_string_free(&a->archive.error_string);
-	if (a->entry)
-		archive_entry_free(a->entry);
+	archive_entry_free(a->entry);
 	a->archive.magic = 0;
 	__archive_clean(&a->archive);
 	free(a->client.dataset);
@@ -1451,6 +1485,8 @@ __archive_read_filter_consume(struct archive_read_filter * filter,
 {
 	int64_t skipped;
 
+	if (request < 0)
+		return ARCHIVE_FATAL;
 	if (request == 0)
 		return 0;
 
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_data.3 b/Utilities/cmlibarchive/libarchive/archive_read_add_passphrase.3
similarity index 59%
copy from Utilities/cmlibarchive/libarchive/archive_write_data.3
copy to Utilities/cmlibarchive/libarchive/archive_read_add_passphrase.3
index cfd5cd5..8b242ea 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_data.3
+++ b/Utilities/cmlibarchive/libarchive/archive_read_add_passphrase.3
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" Copyright (c) 2014 Michihiro NAKAJIMA
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -24,39 +24,51 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd February 2, 2012
-.Dt ARCHIVE_WRITE_DATA 3
+.Dd September 14, 2014
+.Dt ARCHIVE_READ_ADD_PASSPHRASE 3
 .Os
 .Sh NAME
-.Nm archive_write_data
-.Nd functions for creating archives
+.Nm archive_read_add_passphrase ,
+.Nm archive_read_set_passphrase_callback
+.Nd functions for reading encrypted archives
 .Sh LIBRARY
 Streaming Archive Library (libarchive, -larchive)
 .Sh SYNOPSIS
 .In archive.h
-.Ft ssize_t
-.Fn archive_write_data "struct archive *" "const void *" "size_t"
+.Ft int
+.Fo archive_read_add_passphrase
+.Fa "struct archive *"
+.Fa "const char *passphrase"
+.Fc
+.Ft int
+.Fo archive_read_set_passphrase_callback
+.Fa "struct archive *"
+.Fa "void *client_data"
+.Fa "archive_passphrase_callback *"
+.Fc
 .Sh DESCRIPTION
-Write data corresponding to the header just written.
-.\" .Sh EXAMPLE
-.\"
-.Sh RETURN VALUES
-This function returns the number of bytes actually written, or
-.Li -1
-on error.
-.\"
-.Sh ERRORS
-Detailed error codes and textual descriptions are available from the
-.Fn archive_errno
-and
-.Fn archive_error_string
-functions.
-.\"
+.Bl -tag -width indent
+.It Fn archive_read_add_passphrase
+Register passphrases for reading an encryption archive.
+If
+.Ar passphrase
+is
+.Dv NULL
+or empty, this function will do nothing and
+.Cm ARCHIVE_FAILED
+will be returned.
+Otherwise,
+.Cm ARCHIVE_OK
+will be returned. 
+.It Fn archive_read_set_passphrase_callback
+Register callback function that will be invoked to get a passphrase 
+for decrption after trying all passphrases registered by the
+.Fn archive_read_add_passphrase
+function failed.
+.El
+.\" .Sh ERRORS
 .Sh SEE ALSO
 .Xr tar 1 ,
 .Xr libarchive 3 ,
-.Xr archive_write_finish_entry 3 ,
-.Xr archive_write_set_options 3 ,
-.Xr cpio 5 ,
-.Xr mtree 5 ,
-.Xr tar 5
+.Xr archive_read 3 ,
+.Xr archive_read_set_options 3
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_add_passphrase.c b/Utilities/cmlibarchive/libarchive/archive_read_add_passphrase.c
new file mode 100644
index 0000000..f67f1eb
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_add_passphrase.c
@@ -0,0 +1,186 @@
+/*-
+ * Copyright (c) 2014 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "archive_platform.h"
+__FBSDID("$FreeBSD$");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include "archive_read_private.h"
+
+static void
+add_passphrase_to_tail(struct archive_read *a,
+    struct archive_read_passphrase *p)
+{
+	*a->passphrases.last = p;
+	a->passphrases.last = &p->next;
+	p->next = NULL;
+}
+
+static struct archive_read_passphrase *
+remove_passphrases_from_head(struct archive_read *a)
+{
+	struct archive_read_passphrase *p;
+
+	p = a->passphrases.first;
+	if (p != NULL)
+		a->passphrases.first = p->next;
+	return (p);
+}
+
+static void
+insert_passphrase_to_head(struct archive_read *a,
+    struct archive_read_passphrase *p)
+{
+	p->next = a->passphrases.first;
+	a->passphrases.first = p;
+}
+
+static struct archive_read_passphrase *
+new_read_passphrase(struct archive_read *a, const char *passphrase)
+{
+	struct archive_read_passphrase *p;
+
+	p = malloc(sizeof(*p));
+	if (p == NULL) {
+		archive_set_error(&a->archive, ENOMEM,
+		    "Can't allocate memory");
+		return (NULL);
+	}
+	p->passphrase = strdup(passphrase);
+	if (p->passphrase == NULL) {
+		free(p);
+		archive_set_error(&a->archive, ENOMEM,
+		    "Can't allocate memory");
+		return (NULL);
+	}
+	return (p);
+}
+
+int
+archive_read_add_passphrase(struct archive *_a, const char *passphrase)
+{
+	struct archive_read *a = (struct archive_read *)_a;
+	struct archive_read_passphrase *p;
+
+	archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
+		"archive_read_add_passphrase");
+
+	if (passphrase == NULL || passphrase[0] == '\0') {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Empty passphrase is unacceptable");
+		return (ARCHIVE_FAILED);
+	}
+
+	p = new_read_passphrase(a, passphrase);
+	if (p == NULL)
+		return (ARCHIVE_FATAL);
+	add_passphrase_to_tail(a, p);
+
+	return (ARCHIVE_OK);
+}
+
+int
+archive_read_set_passphrase_callback(struct archive *_a, void *client_data,
+    archive_passphrase_callback *cb)
+{
+	struct archive_read *a = (struct archive_read *)_a;
+
+	archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
+		"archive_read_set_passphrase_callback");
+
+	a->passphrases.callback = cb;
+	a->passphrases.client_data = client_data;
+	return (ARCHIVE_OK);
+}
+
+/*
+ * Call this in advance when you start to get a passphrase for decryption
+ * for a entry.
+ */
+void
+__archive_read_reset_passphrase(struct archive_read *a)
+{
+
+	a->passphrases.candiate = -1;
+}
+
+/*
+ * Get a passphrase for decryption.
+ */
+const char *
+__archive_read_next_passphrase(struct archive_read *a)
+{
+	struct archive_read_passphrase *p;
+	const char *passphrase;
+
+	if (a->passphrases.candiate < 0) {
+		/* Count out how many passphrases we have. */
+		int cnt = 0;
+
+		for (p = a->passphrases.first; p != NULL; p = p->next)
+			cnt++;
+		a->passphrases.candiate = cnt;
+		p = a->passphrases.first;
+	} else if (a->passphrases.candiate > 1) {
+		/* Rotate a passphrase list. */
+		a->passphrases.candiate--;
+		p = remove_passphrases_from_head(a);
+		add_passphrase_to_tail(a, p);
+		/* Pick a new passphrase candiate up. */
+		p = a->passphrases.first;
+	} else if (a->passphrases.candiate == 1) {
+		/* This case is that all cadiates failed to decryption. */
+		a->passphrases.candiate = 0;
+		if (a->passphrases.first->next != NULL) {
+			/* Rotate a passphrase list. */
+			p = remove_passphrases_from_head(a);
+			add_passphrase_to_tail(a, p);
+		}
+		p = NULL;
+	} else  /* There is no passphrase candaite. */
+		p = NULL;
+
+	if (p != NULL)
+		passphrase = p->passphrase;
+	else if (a->passphrases.callback != NULL) {
+		/* Get a passphrase through a call-back function
+		 * since we tried all passphrases out or we don't
+		 * have it. */
+		passphrase = a->passphrases.callback(&a->archive,
+		    a->passphrases.client_data);
+		if (passphrase != NULL) {
+			p = new_read_passphrase(a, passphrase);
+			if (p == NULL)
+				return (NULL);
+			insert_passphrase_to_head(a, p);
+			a->passphrases.candiate = 1;
+		}
+	} else
+		passphrase = NULL;
+
+	return (passphrase);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_append_filter.c b/Utilities/cmlibarchive/libarchive/archive_read_append_filter.c
index 017d7c6..3a0d4d6 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_append_filter.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_append_filter.c
@@ -43,7 +43,7 @@ archive_read_append_filter(struct archive *_a, int code)
   struct archive_read_filter *filter;
   struct archive_read *a = (struct archive_read *)_a;
 
-  r1 = r2 = (ARCHIVE_OK);
+  r2 = (ARCHIVE_OK);
   switch (code)
   {
     case ARCHIVE_FILTER_NONE:
@@ -85,6 +85,10 @@ archive_read_append_filter(struct archive *_a, int code)
       strcpy(str, "rpm");
       r1 = archive_read_support_filter_rpm(_a);
       break;
+    case ARCHIVE_FILTER_LZ4:
+      strcpy(str, "lz4");
+      r1 = archive_read_support_filter_lz4(_a);
+      break;
     case ARCHIVE_FILTER_LZIP:
       strcpy(str, "lzip");
       r1 = archive_read_support_filter_lzip(_a);
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_data.3 b/Utilities/cmlibarchive/libarchive/archive_read_data.3
index bf0578c..c1bc15d 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_data.3
+++ b/Utilities/cmlibarchive/libarchive/archive_read_data.3
@@ -37,7 +37,7 @@
 Streaming Archive Library (libarchive, -larchive)
 .Sh SYNOPSIS
 .In archive.h
-.Ft ssize_t
+.Ft la_ssize_t
 .Fn archive_read_data "struct archive *" "void *buff" "size_t len"
 .Ft int
 .Fo archive_read_data_block
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c
index e81cbec..38303aa 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c
@@ -251,9 +251,11 @@ archive_read_disk_entry_from_file(struct archive *_a,
 #endif /* HAVE_READLINK || HAVE_READLINKAT */
 
 	r = setup_acls(a, entry, &fd);
-	r1 = setup_xattrs(a, entry, &fd);
-	if (r1 < r)
-		r = r1;
+	if (!a->suppress_xattr) {
+		r1 = setup_xattrs(a, entry, &fd);
+		if (r1 < r)
+			r = r1;
+	}
 	if (a->enable_copyfile) {
 		r1 = setup_mac_metadata(a, entry, &fd);
 		if (r1 < r)
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c
index 94eb5e7..f480539 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c
@@ -356,6 +356,8 @@ static int	_archive_read_free(struct archive *);
 static int	_archive_read_close(struct archive *);
 static int	_archive_read_data_block(struct archive *,
 		    const void **, size_t *, int64_t *);
+static int	_archive_read_next_header(struct archive *,
+		    struct archive_entry **);
 static int	_archive_read_next_header2(struct archive *,
 		    struct archive_entry *);
 static const char *trivial_lookup_gname(void *, int64_t gid);
@@ -377,6 +379,7 @@ archive_read_disk_vtable(void)
 		av.archive_free = _archive_read_free;
 		av.archive_close = _archive_read_close;
 		av.archive_read_data_block = _archive_read_data_block;
+		av.archive_read_next_header = _archive_read_next_header;
 		av.archive_read_next_header2 = _archive_read_next_header2;
 		inited = 1;
 	}
@@ -459,6 +462,7 @@ archive_read_disk_new(void)
 	a->archive.magic = ARCHIVE_READ_DISK_MAGIC;
 	a->archive.state = ARCHIVE_STATE_NEW;
 	a->archive.vtable = archive_read_disk_vtable();
+	a->entry = archive_entry_new2(&a->archive);
 	a->lookup_uname = trivial_lookup_uname;
 	a->lookup_gname = trivial_lookup_gname;
 	a->enable_copyfile = 1;
@@ -491,6 +495,7 @@ _archive_read_free(struct archive *_a)
 	if (a->cleanup_uname != NULL && a->lookup_uname_data != NULL)
 		(a->cleanup_uname)(a->lookup_uname_data);
 	archive_string_free(&a->archive.error_string);
+	archive_entry_free(a->entry);
 	a->archive.magic = 0;
 	__archive_clean(&a->archive);
 	free(a);
@@ -609,6 +614,10 @@ archive_read_disk_set_behavior(struct archive *_a, int flags)
 		a->traverse_mount_points = 0;
 	else
 		a->traverse_mount_points = 1;
+	if (flags & ARCHIVE_READDISK_NO_XATTR)
+		a->suppress_xattr = 1;
+	else
+		a->suppress_xattr = 0;
 	return (r);
 }
 
@@ -974,7 +983,7 @@ next_entry(struct archive_read_disk *a, struct tree *t,
 		t->initial_filesystem_id = t->current_filesystem_id;
 	if (!a->traverse_mount_points) {
 		if (t->initial_filesystem_id != t->current_filesystem_id)
-			return (ARCHIVE_RETRY);
+			descend = 0;
 	}
 	t->descend = descend;
 
@@ -1081,6 +1090,17 @@ next_entry(struct archive_read_disk *a, struct tree *t,
 }
 
 static int
+_archive_read_next_header(struct archive *_a, struct archive_entry **entryp)
+{
+	int ret;
+	struct archive_read_disk *a = (struct archive_read_disk *)_a;
+	*entryp = NULL;
+	ret = _archive_read_next_header2(_a, a->entry);
+	*entryp = a->entry;
+	return ret;
+}
+
+static int
 _archive_read_next_header2(struct archive *_a, struct archive_entry *entry)
 {
 	struct archive_read_disk *a = (struct archive_read_disk *)_a;
@@ -1148,6 +1168,7 @@ _archive_read_next_header2(struct archive *_a, struct archive_entry *entry)
 		break;
 	}
 
+	__archive_reset_read_data(&a->archive);
 	return (r);
 }
 
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h b/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h
index e5af16b..2569321 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h
@@ -39,6 +39,9 @@ struct archive_entry;
 struct archive_read_disk {
 	struct archive	archive;
 
+	/* Reused by archive_read_next_header() */
+	struct archive_entry *entry;
+
 	/*
 	 * Symlink mode is one of 'L'ogical, 'P'hysical, or 'H'ybrid,
 	 * following an old BSD convention.  'L' follows all symlinks,
@@ -68,6 +71,8 @@ struct archive_read_disk {
 	int		 enable_copyfile;
 	/* Set 1 if users request to traverse mount points. */
 	int		 traverse_mount_points;
+	/* Set 1 if users want to suppress xattr information. */
+	int		 suppress_xattr;
 
 	const char * (*lookup_gname)(void *private, int64_t gid);
 	void	(*cleanup_gname)(void *private);
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_set_standard_lookup.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_set_standard_lookup.c
index 3bc52c7..d6b2d55 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_disk_set_standard_lookup.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_set_standard_lookup.c
@@ -83,7 +83,7 @@ static const char *	lookup_uname_helper(struct name_cache *, id_t uid);
  * a simple cache to accelerate such lookups---into the archive_read_disk
  * object.  This is in a separate file because getpwuid()/getgrgid()
  * can pull in a LOT of library code (including NIS/LDAP functions, which
- * pull in DNS resolveers, etc).  This can easily top 500kB, which makes
+ * pull in DNS resolvers, etc).  This can easily top 500kB, which makes
  * it inappropriate for some space-constrained applications.
  *
  * Applications that are size-sensitive may want to just use the
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c
index 5c0f366..53bd4b8 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c
@@ -288,6 +288,8 @@ static int	_archive_read_free(struct archive *);
 static int	_archive_read_close(struct archive *);
 static int	_archive_read_data_block(struct archive *,
 		    const void **, size_t *, int64_t *);
+static int	_archive_read_next_header(struct archive *,
+		    struct archive_entry **);
 static int	_archive_read_next_header2(struct archive *,
 		    struct archive_entry *);
 static const char *trivial_lookup_gname(void *, int64_t gid);
@@ -310,6 +312,7 @@ archive_read_disk_vtable(void)
 		av.archive_free = _archive_read_free;
 		av.archive_close = _archive_read_close;
 		av.archive_read_data_block = _archive_read_data_block;
+		av.archive_read_next_header = _archive_read_next_header;
 		av.archive_read_next_header2 = _archive_read_next_header2;
 		inited = 1;
 	}
@@ -393,6 +396,7 @@ archive_read_disk_new(void)
 	a->archive.magic = ARCHIVE_READ_DISK_MAGIC;
 	a->archive.state = ARCHIVE_STATE_NEW;
 	a->archive.vtable = archive_read_disk_vtable();
+	a->entry = archive_entry_new2(&a->archive);
 	a->lookup_uname = trivial_lookup_uname;
 	a->lookup_gname = trivial_lookup_gname;
 	a->enable_copyfile = 1;
@@ -422,6 +426,7 @@ _archive_read_free(struct archive *_a)
 	if (a->cleanup_uname != NULL && a->lookup_uname_data != NULL)
 		(a->cleanup_uname)(a->lookup_uname_data);
 	archive_string_free(&a->archive.error_string);
+	archive_entry_free(a->entry);
 	a->archive.magic = 0;
 	free(a);
 	return (r);
@@ -945,6 +950,17 @@ next_entry(struct archive_read_disk *a, struct tree *t,
 }
 
 static int
+_archive_read_next_header(struct archive *_a, struct archive_entry **entryp)
+{
+       int ret;
+       struct archive_read_disk *a = (struct archive_read_disk *)_a;
+       *entryp = NULL;
+       ret = _archive_read_next_header2(_a, a->entry);
+       *entryp = a->entry;
+       return ret;
+}
+
+static int
 _archive_read_next_header2(struct archive *_a, struct archive_entry *entry)
 {
 	struct archive_read_disk *a = (struct archive_read_disk *)_a;
@@ -1000,6 +1016,7 @@ _archive_read_next_header2(struct archive *_a, struct archive_entry *entry)
 		break;
 	}
 
+	__archive_reset_read_data(&a->archive);
 	return (r);
 }
 
@@ -1851,8 +1868,6 @@ entry_copy_bhfi(struct archive_entry *entry, const wchar_t *path,
 				break;
 			case L'C': case L'c':
 				if (((p[2] == L'M' || p[2] == L'm' ) &&
-				    (p[3] == L'D' || p[3] == L'd' )) ||
-				    ((p[2] == L'M' || p[2] == L'm' ) &&
 				    (p[3] == L'D' || p[3] == L'd' )))
 					mode |= S_IXUSR | S_IXGRP | S_IXOTH;
 				break;
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_extract.c b/Utilities/cmlibarchive/libarchive/archive_read_extract.c
index ce76a6c..b7973fa 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_extract.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_extract.c
@@ -35,8 +35,6 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_extract.c,v 1.61 2008/05/26
 #include "archive_private.h"
 #include "archive_read_private.h"
 
-static int	archive_read_extract_cleanup(struct archive_read *);
-
 int
 archive_read_extract(struct archive *_a, struct archive_entry *entry, int flags)
 {
@@ -55,23 +53,8 @@ archive_read_extract(struct archive *_a, struct archive_entry *entry, int flags)
 			return (ARCHIVE_FATAL);
 		}
 		archive_write_disk_set_standard_lookup(extract->ad);
-		a->cleanup_archive_extract = archive_read_extract_cleanup;
 	}
 
 	archive_write_disk_set_options(extract->ad, flags);
 	return (archive_read_extract2(&a->archive, entry, extract->ad));
 }
-
-/*
- * Cleanup function for archive_extract.
- */
-static int
-archive_read_extract_cleanup(struct archive_read *a)
-{
-	int ret = ARCHIVE_OK;
-
-	ret = archive_write_free(a->extract->ad);
-	free(a->extract);
-	a->extract = NULL;
-	return (ret);
-}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_extract2.c b/Utilities/cmlibarchive/libarchive/archive_read_extract2.c
index 3c65e80..7b2c126 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_extract2.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_extract2.c
@@ -42,6 +42,8 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_extract.c,v 1.61 2008/05/26
 #include "archive_read_private.h"
 
 static int	copy_data(struct archive *ar, struct archive *aw);
+static int	archive_read_extract_cleanup(struct archive_read *);
+
 
 /* Retrieve an extract object without initialising the associated
  * archive_write_disk object.
@@ -56,10 +58,27 @@ __archive_read_get_extract(struct archive_read *a)
 			return (NULL);
 		}
 		memset(a->extract, 0, sizeof(*a->extract));
+		a->cleanup_archive_extract = archive_read_extract_cleanup;
 	}
 	return (a->extract);
 }
 
+/*
+ * Cleanup function for archive_extract.
+ */
+static int
+archive_read_extract_cleanup(struct archive_read *a)
+{
+	int ret = ARCHIVE_OK;
+
+	if (a->extract->ad != NULL) {
+		ret = archive_write_free(a->extract->ad);
+	}
+	free(a->extract);
+	a->extract = NULL;
+	return (ret);
+}
+
 int
 archive_read_extract2(struct archive *_a, struct archive_entry *entry,
     struct archive *ad)
@@ -125,7 +144,7 @@ copy_data(struct archive *ar, struct archive *aw)
 		r = (int)archive_write_data_block(aw, buff, size, offset);
 		if (r < ARCHIVE_WARN)
 			r = ARCHIVE_WARN;
-		if (r != ARCHIVE_OK) {
+		if (r < ARCHIVE_OK) {
 			archive_set_error(ar, archive_errno(aw),
 			    "%s", archive_error_string(aw));
 			return (r);
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_filter.3 b/Utilities/cmlibarchive/libarchive/archive_read_filter.3
index 8761127..47effac 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_filter.3
+++ b/Utilities/cmlibarchive/libarchive/archive_read_filter.3
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd February 2, 2012
+.Dd August 14, 2014
 .Dt ARCHIVE_READ_FILTER 3
 .Os
 .Sh NAME
@@ -32,8 +32,11 @@
 .Nm archive_read_support_filter_bzip2 ,
 .Nm archive_read_support_filter_compress ,
 .Nm archive_read_support_filter_gzip ,
+.Nm archive_read_support_filter_lz4 ,
 .Nm archive_read_support_filter_lzma ,
 .Nm archive_read_support_filter_none ,
+.Nm archive_read_support_filter_rpm ,
+.Nm archive_read_support_filter_uu ,
 .Nm archive_read_support_filter_xz ,
 .Nm archive_read_support_filter_program ,
 .Nm archive_read_support_filter_program_signature
@@ -52,10 +55,18 @@ Streaming Archive Library (libarchive, -larchive)
 .Ft int
 .Fn archive_read_support_filter_gzip "struct archive *"
 .Ft int
+.Fn archive_read_support_filter_lz4 "struct archive *"
+.Ft int
 .Fn archive_read_support_filter_lzma "struct archive *"
 .Ft int
+.Fn archive_read_support_filter_lzop "struct archive *"
+.Ft int
 .Fn archive_read_support_filter_none "struct archive *"
 .Ft int
+.Fn archive_read_support_filter_rpm "struct archive *"
+.Ft int
+.Fn archive_read_support_filter_uu "struct archive *"
+.Ft int
 .Fn archive_read_support_filter_xz "struct archive *"
 .Ft int
 .Fo archive_read_support_filter_program
@@ -76,8 +87,12 @@ Streaming Archive Library (libarchive, -larchive)
 .Fn archive_read_support_filter_bzip2 ,
 .Fn archive_read_support_filter_compress ,
 .Fn archive_read_support_filter_gzip ,
+.Fn archive_read_support_filter_lz4 ,
 .Fn archive_read_support_filter_lzma ,
+.Fn archive_read_support_filter_lzop ,
 .Fn archive_read_support_filter_none ,
+.Fn archive_read_support_filter_rpm ,
+.Fn archive_read_support_filter_uu ,
 .Fn archive_read_support_filter_xz
 .Xc
 Enables auto-detection code and decompression support for the
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open.3 b/Utilities/cmlibarchive/libarchive/archive_read_open.3
index 30a740b..4d8272c 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_open.3
+++ b/Utilities/cmlibarchive/libarchive/archive_read_open.3
@@ -130,14 +130,14 @@ objects can be found in the overview manual page for
 The callback functions must match the following prototypes:
 .Bl -item -offset indent
 .It
-.Ft typedef ssize_t
+.Ft typedef la_ssize_t
 .Fo archive_read_callback
 .Fa "struct archive *"
 .Fa "void *client_data"
 .Fa "const void **buffer"
 .Fc
 .It
-.Ft typedef off_t
+.Ft typedef la_int64_t
 .Fo archive_skip_callback
 .Fa "struct archive *"
 .Fa "void *client_data"
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open_fd.c b/Utilities/cmlibarchive/libarchive/archive_read_open_fd.c
index e0f95bf..f59cd07 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_open_fd.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_open_fd.c
@@ -59,6 +59,7 @@ struct read_fd_data {
 
 static int	file_close(struct archive *, void *);
 static ssize_t	file_read(struct archive *, void *, const void **buff);
+static int64_t	file_seek(struct archive *, void *, int64_t request, int);
 static int64_t	file_skip(struct archive *, void *, int64_t request);
 
 int
@@ -102,6 +103,7 @@ archive_read_open_fd(struct archive *a, int fd, size_t block_size)
 
 	archive_read_set_read_callback(a, file_read);
 	archive_read_set_skip_callback(a, file_skip);
+	archive_read_set_seek_callback(a, file_seek);
 	archive_read_set_close_callback(a, file_close);
 	archive_read_set_callback_data(a, mine);
 	return (archive_read_open1(a));
@@ -170,6 +172,33 @@ file_skip(struct archive *a, void *client_data, int64_t request)
 	return (-1);
 }
 
+/*
+ * TODO: Store the offset and use it in the read callback.
+ */
+static int64_t
+file_seek(struct archive *a, void *client_data, int64_t request, int whence)
+{
+	struct read_fd_data *mine = (struct read_fd_data *)client_data;
+	int64_t r;
+
+	/* We use off_t here because lseek() is declared that way. */
+	/* See above for notes about when off_t is less than 64 bits. */
+	r = lseek(mine->fd, request, whence);
+	if (r >= 0)
+		return r;
+
+	if (errno == ESPIPE) {
+		archive_set_error(a, errno,
+		    "A file descriptor(%d) is not seekable(PIPE)", mine->fd);
+		return (ARCHIVE_FAILED);
+	} else {
+		/* If the input is corrupted or truncated, fail. */
+		archive_set_error(a, errno,
+		    "Error seeking in a file descriptor(%d)", mine->fd);
+		return (ARCHIVE_FATAL);
+	}
+}
+
 static int
 file_close(struct archive *a, void *client_data)
 {
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open_memory.c b/Utilities/cmlibarchive/libarchive/archive_read_open_memory.c
index bcc7d6f..ff935a7 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_open_memory.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_open_memory.c
@@ -41,9 +41,9 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_open_memory.c,v 1.6 2007/07/
  */
 
 struct read_memory_data {
-	unsigned char	*start;
-	unsigned char	*p;
-	unsigned char	*end;
+	const unsigned char	*start;
+	const unsigned char	*p;
+	const unsigned char	*end;
 	ssize_t	 read_size;
 };
 
@@ -54,7 +54,7 @@ static int64_t	memory_read_skip(struct archive *, void *, int64_t request);
 static ssize_t	memory_read(struct archive *, void *, const void **buff);
 
 int
-archive_read_open_memory(struct archive *a, void *buff, size_t size)
+archive_read_open_memory(struct archive *a, const void *buff, size_t size)
 {
 	return archive_read_open_memory2(a, buff, size, size);
 }
@@ -65,7 +65,7 @@ archive_read_open_memory(struct archive *a, void *buff, size_t size)
  * test harnesses can exercise block operations inside the library.
  */
 int
-archive_read_open_memory2(struct archive *a, void *buff,
+archive_read_open_memory2(struct archive *a, const void *buff,
     size_t size, size_t read_size)
 {
 	struct read_memory_data *mine;
@@ -76,7 +76,7 @@ archive_read_open_memory2(struct archive *a, void *buff,
 		return (ARCHIVE_FATAL);
 	}
 	memset(mine, 0, sizeof(*mine));
-	mine->start = mine->p = (unsigned char *)buff;
+	mine->start = mine->p = (const unsigned char *)buff;
 	mine->end = mine->start + size;
 	mine->read_size = read_size;
 	archive_read_set_open_callback(a, memory_read_open);
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_private.h b/Utilities/cmlibarchive/libarchive/archive_read_private.h
index 27e203b..9b61a53 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_private.h
+++ b/Utilities/cmlibarchive/libarchive/archive_read_private.h
@@ -26,8 +26,10 @@
  */
 
 #ifndef __LIBARCHIVE_BUILD
+#ifndef __LIBARCHIVE_TEST
 #error This header is only to be used internally to libarchive.
 #endif
+#endif
 
 #ifndef ARCHIVE_READ_PRIVATE_H_INCLUDED
 #define	ARCHIVE_READ_PRIVATE_H_INCLUDED
@@ -141,6 +143,10 @@ struct archive_read_client {
 	int64_t position;
 	struct archive_read_data_node *dataset;
 };
+struct archive_read_passphrase {
+	char	*passphrase;
+	struct archive_read_passphrase *next;
+};
 
 struct archive_read_extract {
 	struct archive *ad; /* archive_write_disk object */
@@ -160,28 +166,11 @@ struct archive_read {
 	int64_t		  skip_file_dev;
 	int64_t		  skip_file_ino;
 
-	/*
-	 * Used by archive_read_data() to track blocks and copy
-	 * data to client buffers, filling gaps with zero bytes.
-	 */
-	const char	 *read_data_block;
-	int64_t		  read_data_offset;
-	int64_t		  read_data_output_offset;
-	size_t		  read_data_remaining;
-
-	/*
-	 * Used by formats/filters to determine the amount of data
-	 * requested from a call to archive_read_data(). This is only
-	 * useful when the format/filter has seek support.
-	 */
-	char		  read_data_is_posix_read;
-	size_t		  read_data_requested;
-
 	/* Callbacks to open/read/write/close client archive streams. */
 	struct archive_read_client client;
 
 	/* Registered filter bidders. */
-	struct archive_read_filter_bidder bidders[14];
+	struct archive_read_filter_bidder bidders[16];
 
 	/* Last filter in chain */
 	struct archive_read_filter *filter;
@@ -225,6 +214,17 @@ struct archive_read {
 	 */
 	struct archive_read_extract		*extract;
 	int			(*cleanup_archive_extract)(struct archive_read *);
+
+	/*
+	 * Decryption passphrase.
+	 */
+	struct {
+		struct archive_read_passphrase *first;
+		struct archive_read_passphrase **last;
+		int candiate;
+		archive_passphrase_callback *callback;
+		void *client_data;
+	}		passphrases;
 };
 
 int	__archive_read_register_format(struct archive_read *a,
@@ -254,4 +254,11 @@ int __archive_read_program(struct archive_read_filter *, const char *);
 void __archive_read_free_filters(struct archive_read *);
 int  __archive_read_close_filters(struct archive_read *);
 struct archive_read_extract *__archive_read_get_extract(struct archive_read *);
+
+
+/*
+ * Get a decryption passphrase.
+ */
+void __archive_read_reset_passphrase(struct archive_read *a);
+const char * __archive_read_next_passphrase(struct archive_read *a);
 #endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_set_options.c b/Utilities/cmlibarchive/libarchive/archive_read_set_options.c
index 46678b1..2e2eea6 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_set_options.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_set_options.c
@@ -76,14 +76,13 @@ archive_set_format_option(struct archive *_a, const char *m, const char *o,
     const char *v)
 {
 	struct archive_read *a = (struct archive_read *)_a;
-	struct archive_format_descriptor *format;
 	size_t i;
 	int r, rv = ARCHIVE_WARN, matched_modules = 0;
 
 	for (i = 0; i < sizeof(a->formats)/sizeof(a->formats[0]); i++) {
-		format = &a->formats[i];
-		if (format == NULL || format->options == NULL ||
-		    format->name == NULL)
+		struct archive_format_descriptor *format = &a->formats[i];
+
+		if (format->options == NULL || format->name == NULL)
 			/* This format does not support option. */
 			continue;
 		if (m != NULL) {
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c
index b778cfb..68c53de 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c
@@ -69,6 +69,8 @@ archive_read_support_filter_all(struct archive *a)
 	archive_read_support_filter_lzop(a);
 	/* The decode code always uses "grzip -d" command-line. */
 	archive_read_support_filter_grzip(a);
+	/* Lz4 falls back to "lz4 -d" command-line program. */
+	archive_read_support_filter_lz4(a);
 
 	/* Note: We always return ARCHIVE_OK here, even if some of the
 	 * above return ARCHIVE_WARN.  The intent here is to enable
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_compress.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_compress.c
index 3f5d1f3..e05132d 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_compress.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_compress.c
@@ -185,19 +185,22 @@ compress_bidder_bid(struct archive_read_filter_bidder *self,
 
 	(void)self; /* UNUSED */
 
-	buffer = __archive_read_filter_ahead(filter, 2, &avail);
+	/* Shortest valid compress file is 3 bytes. */
+	buffer = __archive_read_filter_ahead(filter, 3, &avail);
 
 	if (buffer == NULL)
 		return (0);
 
 	bits_checked = 0;
+	/* First two bytes are the magic value */
 	if (buffer[0] != 0x1F || buffer[1] != 0x9D)
 		return (0);
-	bits_checked += 16;
-
-	/*
-	 * TODO: Verify more.
-	 */
+	/* Third byte holds compression parameters. */
+	if (buffer[2] & 0x20) /* Reserved bit, must be zero. */
+		return (0);
+	if (buffer[2] & 0x40) /* Reserved bit, must be zero. */
+		return (0);
+	bits_checked += 18;
 
 	return (bits_checked);
 }
@@ -239,7 +242,13 @@ compress_bidder_init(struct archive_read_filter *self)
 	(void)getbits(self, 8); /* Skip first signature byte. */
 	(void)getbits(self, 8); /* Skip second signature byte. */
 
+	/* Get compression parameters. */
 	code = getbits(self, 8);
+	if ((code & 0x1f) > 16) {
+		archive_set_error(&self->archive->archive, -1,
+		    "Invalid compressed data");
+		return (ARCHIVE_FATAL);
+	}
 	state->maxcode_bits = code & 0x1f;
 	state->maxcode = (1 << state->maxcode_bits);
 	state->use_reset_code = code & 0x80;
@@ -368,7 +377,8 @@ next_code(struct archive_read_filter *self)
 		return (next_code(self));
 	}
 
-	if (code > state->free_ent) {
+	if (code > state->free_ent
+	    || (code == state->free_ent && state->oldcode < 0)) {
 		/* An invalid code is a fatal error. */
 		archive_set_error(&(self->archive->archive), -1,
 		    "Invalid compressed data");
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c
new file mode 100644
index 0000000..db62cb3
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c
@@ -0,0 +1,728 @@
+/*-
+ * Copyright (c) 2014 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "archive_platform.h"
+
+__FBSDID("$FreeBSD$");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_LZ4_H
+#include <lz4.h>
+#endif
+
+#include "archive.h"
+#include "archive_endian.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+#include "archive_xxhash.h"
+
+#define LZ4_MAGICNUMBER		0x184d2204
+#define LZ4_SKIPPABLED		0x184d2a50
+#define LZ4_LEGACY		0x184c2102
+
+#if defined(HAVE_LIBLZ4)
+struct private_data {
+	enum {  SELECT_STREAM,
+		READ_DEFAULT_STREAM,
+		READ_DEFAULT_BLOCK,
+		READ_LEGACY_STREAM,
+		READ_LEGACY_BLOCK,
+	}		stage;
+	struct {
+		unsigned block_independence:1;
+		unsigned block_checksum:3;
+		unsigned stream_size:1;
+		unsigned stream_checksum:1;
+		unsigned preset_dictionary:1;
+		int	 block_maximum_size;
+	} flags;
+	int64_t		 stream_size;
+	uint32_t	 dict_id;
+	char		*out_block;
+	size_t		 out_block_size;
+
+	/* Bytes read but not yet consumed via __archive_read_consume() */
+	size_t		 unconsumed;
+	size_t		 decoded_size;
+	void		*xxh32_state;
+
+	char		 valid; /* True = decompressor is initialized */
+	char		 eof; /* True = found end of compressed data. */
+};
+
+#define LEGACY_BLOCK_SIZE	(8 * 1024 * 1024)
+
+/* Lz4 filter */
+static ssize_t	lz4_filter_read(struct archive_read_filter *, const void **);
+static int	lz4_filter_close(struct archive_read_filter *);
+#endif
+
+/*
+ * Note that we can detect lz4 archives even if we can't decompress
+ * them.  (In fact, we like detecting them because we can give better
+ * error messages.)  So the bid framework here gets compiled even
+ * if liblz4 is unavailable.
+ */
+static int	lz4_reader_bid(struct archive_read_filter_bidder *, struct archive_read_filter *);
+static int	lz4_reader_init(struct archive_read_filter *);
+static int	lz4_reader_free(struct archive_read_filter_bidder *);
+#if defined(HAVE_LIBLZ4)
+static ssize_t  lz4_filter_read_default_stream(struct archive_read_filter *,
+		    const void **);
+static ssize_t  lz4_filter_read_legacy_stream(struct archive_read_filter *,
+		    const void **);
+#endif
+
+int
+archive_read_support_filter_lz4(struct archive *_a)
+{
+	struct archive_read *a = (struct archive_read *)_a;
+	struct archive_read_filter_bidder *reader;
+
+	archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+	    ARCHIVE_STATE_NEW, "archive_read_support_filter_lz4");
+
+	if (__archive_read_get_bidder(a, &reader) != ARCHIVE_OK)
+		return (ARCHIVE_FATAL);
+
+	reader->data = NULL;
+	reader->name = "lz4";
+	reader->bid = lz4_reader_bid;
+	reader->init = lz4_reader_init;
+	reader->options = NULL;
+	reader->free = lz4_reader_free;
+#if defined(HAVE_LIBLZ4)
+	return (ARCHIVE_OK);
+#else
+	archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+	    "Using external lz4 program");
+	return (ARCHIVE_WARN);
+#endif
+}
+
+static int
+lz4_reader_free(struct archive_read_filter_bidder *self){
+	(void)self; /* UNUSED */
+	return (ARCHIVE_OK);
+}
+
+/*
+ * Test whether we can handle this data.
+ *
+ * This logic returns zero if any part of the signature fails.  It
+ * also tries to Do The Right Thing if a very short buffer prevents us
+ * from verifying as much as we would like.
+ */
+static int
+lz4_reader_bid(struct archive_read_filter_bidder *self,
+    struct archive_read_filter *filter)
+{
+	const unsigned char *buffer;
+	ssize_t avail;
+	int bits_checked;
+	uint32_t number;
+
+	(void)self; /* UNUSED */
+
+	/* Minimal lz4 archive is 11 bytes. */
+	buffer = __archive_read_filter_ahead(filter, 11, &avail);
+	if (buffer == NULL)
+		return (0);
+
+	/* First four bytes must be LZ4 magic numbers. */
+	bits_checked = 0;
+	if ((number = archive_le32dec(buffer)) == LZ4_MAGICNUMBER) {
+		unsigned char flag, BD;
+
+		bits_checked += 32;
+		/* Next follows a stream descriptor. */
+		/* Descriptor Flags. */
+		flag = buffer[4];
+		/* A version number must be "01". */
+		if (((flag & 0xc0) >> 6) != 1)
+			return (0);
+		/* A reserved bit must be "0". */
+		if (flag & 2)
+			return (0);
+		bits_checked += 8;
+		BD = buffer[5];
+		/* A block maximum size shuld be more than 3. */
+		if (((BD & 0x70) >> 4) < 4)
+			return (0);
+		/* Reserved bits must be "0". */
+		if (BD & ~0x70)
+			return (0);
+		bits_checked += 8;
+	} else if (number == LZ4_LEGACY) {
+		bits_checked += 32;
+	}
+	
+	return (bits_checked);
+}
+
+#if !defined(HAVE_LIBLZ4)
+
+/*
+ * If we don't have the library on this system, we can't actually do the
+ * decompression.  We can, however, still detect compressed archives
+ * and emit a useful message.
+ */
+static int
+lz4_reader_init(struct archive_read_filter *self)
+{
+	int r;
+
+	r = __archive_read_program(self, "lz4 -d -q");
+	/* Note: We set the format here even if __archive_read_program()
+	 * above fails.  We do, after all, know what the format is
+	 * even if we weren't able to read it. */
+	self->code = ARCHIVE_FILTER_LZ4;
+	self->name = "lz4";
+	return (r);
+}
+
+
+#else
+
+/*
+ * Setup the callbacks.
+ */
+static int
+lz4_reader_init(struct archive_read_filter *self)
+{
+	struct private_data *state;
+
+	self->code = ARCHIVE_FILTER_LZ4;
+	self->name = "lz4";
+
+	state = (struct private_data *)calloc(sizeof(*state), 1);
+	if (state == NULL) {
+		archive_set_error(&self->archive->archive, ENOMEM,
+		    "Can't allocate data for lz4 decompression");
+		return (ARCHIVE_FATAL);
+	}
+
+	self->data = state;
+	state->stage = SELECT_STREAM;
+	self->read = lz4_filter_read;
+	self->skip = NULL; /* not supported */
+	self->close = lz4_filter_close;
+
+	return (ARCHIVE_OK);
+}
+
+static int
+lz4_allocate_out_block(struct archive_read_filter *self)
+{
+	struct private_data *state = (struct private_data *)self->data;
+	size_t out_block_size = state->flags.block_maximum_size;
+	void *out_block;
+
+	if (!state->flags.block_independence)
+		out_block_size += 64 * 1024;
+	if (state->out_block_size < out_block_size) {
+		free(state->out_block);
+		out_block = (unsigned char *)malloc(out_block_size);
+		state->out_block_size = out_block_size;
+		if (out_block == NULL) {
+			archive_set_error(&self->archive->archive, ENOMEM,
+			    "Can't allocate data for lz4 decompression");
+			return (ARCHIVE_FATAL);
+		}
+		state->out_block = out_block;
+	}
+	if (!state->flags.block_independence)
+		memset(state->out_block, 0, 64 * 1024);
+	return (ARCHIVE_OK);
+}
+
+static int
+lz4_allocate_out_block_for_legacy(struct archive_read_filter *self)
+{
+	struct private_data *state = (struct private_data *)self->data;
+	size_t out_block_size = LEGACY_BLOCK_SIZE;
+	void *out_block;
+
+	if (state->out_block_size < out_block_size) {
+		free(state->out_block);
+		out_block = (unsigned char *)malloc(out_block_size);
+		state->out_block_size = out_block_size;
+		if (out_block == NULL) {
+			archive_set_error(&self->archive->archive, ENOMEM,
+			    "Can't allocate data for lz4 decompression");
+			return (ARCHIVE_FATAL);
+		}
+		state->out_block = out_block;
+	}
+	return (ARCHIVE_OK);
+}
+
+/*
+ * Return the next block of decompressed data.
+ */
+static ssize_t
+lz4_filter_read(struct archive_read_filter *self, const void **p)
+{
+	struct private_data *state = (struct private_data *)self->data;
+	ssize_t ret;
+
+	if (state->eof) {
+		*p = NULL;
+		return (0);
+	}
+
+	__archive_read_filter_consume(self->upstream, state->unconsumed);
+	state->unconsumed = 0;
+
+	switch (state->stage) {
+	case SELECT_STREAM:
+		break;
+	case READ_DEFAULT_STREAM:
+	case READ_LEGACY_STREAM:
+		/* Reading a lz4 stream already failed. */
+		archive_set_error(&self->archive->archive,
+		    ARCHIVE_ERRNO_MISC, "Invalid sequence.");
+		return (ARCHIVE_FATAL);
+	case READ_DEFAULT_BLOCK:
+		ret = lz4_filter_read_default_stream(self, p);
+		if (ret != 0 || state->stage != SELECT_STREAM)
+			return ret;
+		break;
+	case READ_LEGACY_BLOCK:
+		ret = lz4_filter_read_legacy_stream(self, p);
+		if (ret != 0 || state->stage != SELECT_STREAM)
+			return ret;
+		break;
+	default:
+		archive_set_error(&self->archive->archive,
+		    ARCHIVE_ERRNO_MISC, "Program error.");
+		return (ARCHIVE_FATAL);
+		break;
+	}
+
+	while (state->stage == SELECT_STREAM) {
+		const char *read_buf;
+
+		/* Read a magic number. */
+		read_buf = __archive_read_filter_ahead(self->upstream, 4,
+				NULL);
+		if (read_buf == NULL) {
+			state->eof = 1;
+			*p = NULL;
+			return (0);
+		}
+		uint32_t number = archive_le32dec(read_buf);
+		__archive_read_filter_consume(self->upstream, 4);
+		if (number == LZ4_MAGICNUMBER)
+			return lz4_filter_read_default_stream(self, p);
+		else if (number == LZ4_LEGACY)
+			return lz4_filter_read_legacy_stream(self, p);
+		else if ((number & ~0xF) == LZ4_SKIPPABLED) {
+			read_buf = __archive_read_filter_ahead(
+				self->upstream, 4, NULL);
+			if (read_buf == NULL) {
+				archive_set_error(
+				    &self->archive->archive,
+		    		    ARCHIVE_ERRNO_MISC,
+				    "Malformed lz4 data");
+				return (ARCHIVE_FATAL);
+			}
+			uint32_t skip_bytes = archive_le32dec(read_buf);
+			__archive_read_filter_consume(self->upstream,
+				4 + skip_bytes);
+		} else {
+			/* Ignore following unrecognized data. */
+			state->eof = 1;
+			*p = NULL;
+			return (0);
+		}
+	}
+	state->eof = 1;
+	*p = NULL;
+	return (0);
+}
+
+static int
+lz4_filter_read_descriptor(struct archive_read_filter *self)
+{
+	struct private_data *state = (struct private_data *)self->data;
+	const char *read_buf;
+	ssize_t bytes_remaining;
+	ssize_t descriptor_bytes;
+	unsigned char flag, bd;
+	unsigned int chsum, chsum_verifier;
+
+	/* Make sure we have 2 bytes for flags. */
+	read_buf = __archive_read_filter_ahead(self->upstream, 2,
+	    &bytes_remaining);
+	if (read_buf == NULL) {
+		archive_set_error(&self->archive->archive,
+		    ARCHIVE_ERRNO_MISC,
+		    "truncated lz4 input");
+		return (ARCHIVE_FATAL);
+	}
+
+	/*
+	   Parse flags.
+	 */
+	flag = (unsigned char)read_buf[0];
+	/* Verify version number. */
+	if ((flag & 0xc0) != 1<<6)
+		goto malformed_error;
+	/* A reserved bit must be zero. */
+	if (flag & 0x02)
+		goto malformed_error;
+	state->flags.block_independence = (flag & 0x20) != 0;
+	state->flags.block_checksum = (flag & 0x10)?4:0;
+	state->flags.stream_size = (flag & 0x08) != 0;
+	state->flags.stream_checksum = (flag & 0x04) != 0;
+	state->flags.preset_dictionary = (flag & 0x01) != 0;
+
+	/* BD */
+	bd = (unsigned char)read_buf[1];
+	/* Reserved bits must be zero. */
+	if (bd & 0x8f)
+		goto malformed_error;
+	/* Get a maxinum block size. */
+	switch (read_buf[1] >> 4) {
+	case 4: /* 64 KB */
+		state->flags.block_maximum_size = 64 * 1024;
+		break;
+	case 5: /* 256 KB */
+		state->flags.block_maximum_size = 256 * 1024;
+		break;
+	case 6: /* 1 MB */
+		state->flags.block_maximum_size = 1024 * 1024;
+		break;
+	case 7: /* 4 MB */
+		state->flags.block_maximum_size = 4 * 1024 * 1024;
+		break;
+	default:
+		goto malformed_error;
+	}
+
+	/* Read the whole descriptor in a stream block. */
+	descriptor_bytes = 3;
+	if (state->flags.stream_size)
+		descriptor_bytes += 8;
+	if (state->flags.preset_dictionary)
+		descriptor_bytes += 4;
+	if (bytes_remaining < descriptor_bytes) {
+		read_buf = __archive_read_filter_ahead(self->upstream,
+		    descriptor_bytes, &bytes_remaining);
+		if (read_buf == NULL) {
+			archive_set_error(&self->archive->archive,
+			    ARCHIVE_ERRNO_MISC,
+			    "truncated lz4 input");
+			return (ARCHIVE_FATAL);
+		}
+	}
+	/* Check if a descriptor is corrupted */
+	chsum = __archive_xxhash.XXH32(read_buf, (int)descriptor_bytes -1, 0);
+	chsum = (chsum >> 8) & 0xff;
+	chsum_verifier = read_buf[descriptor_bytes-1] & 0xff;
+	if (chsum != chsum_verifier)
+		goto malformed_error;
+
+	__archive_read_filter_consume(self->upstream, descriptor_bytes);
+
+	/* Make sure we have an enough buffer for uncompressed data. */
+	if (lz4_allocate_out_block(self) != ARCHIVE_OK)
+		return (ARCHIVE_FATAL);
+	if (state->flags.stream_checksum)
+		state->xxh32_state = __archive_xxhash.XXH32_init(0);
+
+	state->decoded_size = 0;
+	/* Success */
+	return (ARCHIVE_OK);
+malformed_error:
+	archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
+	    "malformed lz4 data");
+	return (ARCHIVE_FATAL);
+}
+
+static ssize_t
+lz4_filter_read_data_block(struct archive_read_filter *self, const void **p)
+{
+	struct private_data *state = (struct private_data *)self->data;
+	ssize_t compressed_size;
+	const char *read_buf;
+	ssize_t bytes_remaining;
+	int checksum_size;
+	ssize_t uncompressed_size;
+	size_t prefix64k;
+
+	*p = NULL;
+
+	/* Make sure we have 4 bytes for a block size. */
+	read_buf = __archive_read_filter_ahead(self->upstream, 4,
+	    &bytes_remaining);
+	if (read_buf == NULL)
+		goto truncated_error;
+	compressed_size = archive_le32dec(read_buf);
+	if ((compressed_size & ~(1 << 31)) > state->flags.block_maximum_size)
+		goto malformed_error;
+	/* A compressed size == 0 means the end of stream blocks. */
+	if (compressed_size == 0) {
+		__archive_read_filter_consume(self->upstream, 4);
+		return 0;
+	}
+
+	checksum_size = state->flags.block_checksum;
+	/* Check if the block is uncompressed. */
+	if (compressed_size & (1 << 31)) {
+		compressed_size &= ~(1 << 31);
+		uncompressed_size = compressed_size;
+	} else
+		uncompressed_size = 0;/* Unknown yet. */
+
+	/*
+	  Unfortunately, lz4 decompression API requires a whole block
+	  for its decompression speed, so we read a whole block and allocate
+	  a huge buffer used for decoded data.
+	*/
+	read_buf = __archive_read_filter_ahead(self->upstream,
+	    4 + compressed_size + checksum_size, &bytes_remaining);
+	if (read_buf == NULL)
+		goto truncated_error;
+
+	/* Optional process, checking a block sum. */
+	if (checksum_size) {
+		unsigned int chsum = __archive_xxhash.XXH32(
+			read_buf + 4, (int)compressed_size, 0);
+		unsigned int chsum_block =
+		    archive_le32dec(read_buf + 4 + compressed_size);
+		if (chsum != chsum_block)
+			goto malformed_error;
+	}
+
+
+	/* If the block is uncompressed, there is nothing to do. */
+	if (uncompressed_size) {
+		/* Prepare a prefix 64k block for next block. */
+		if (!state->flags.block_independence) {
+			prefix64k = 64 * 1024;
+			if (uncompressed_size < (ssize_t)prefix64k) {
+				memcpy(state->out_block
+					+ prefix64k - uncompressed_size,
+				    read_buf + 4,
+				    uncompressed_size);
+				memset(state->out_block, 0,
+				    prefix64k - uncompressed_size);
+			} else {
+				memcpy(state->out_block,
+				    read_buf + 4
+					+ uncompressed_size - prefix64k,
+				    prefix64k);
+			}
+			state->decoded_size = 0;
+		}
+		state->unconsumed = 4 + uncompressed_size + checksum_size;
+		*p = read_buf + 4;
+		return uncompressed_size;
+	}
+
+	/*
+	   Decompress a block data.
+	 */
+	if (state->flags.block_independence) {
+		prefix64k = 0;
+		uncompressed_size = LZ4_decompress_safe(read_buf + 4,
+		    state->out_block, (int)compressed_size,
+		    state->flags.block_maximum_size);
+	} else {
+		prefix64k = 64 * 1024;
+		if (state->decoded_size) {
+			if (state->decoded_size < prefix64k) {
+				memmove(state->out_block
+					+ prefix64k - state->decoded_size,
+				    state->out_block + prefix64k,
+				    state->decoded_size);
+				memset(state->out_block, 0,
+				    prefix64k - state->decoded_size);
+			} else {
+				memmove(state->out_block,
+				    state->out_block + state->decoded_size,
+				    prefix64k);
+			}
+		}
+		uncompressed_size = LZ4_decompress_safe_withPrefix64k(
+		    read_buf + 4,
+		    state->out_block + prefix64k, (int)compressed_size,
+		    state->flags.block_maximum_size);
+	}
+
+	/* Check if an error happend in decompression process. */
+	if (uncompressed_size < 0) {
+		archive_set_error(&(self->archive->archive),
+		    ARCHIVE_ERRNO_MISC, "lz4 decompression failed");
+		return (ARCHIVE_FATAL);
+	}
+
+	state->unconsumed = 4 + compressed_size + checksum_size;
+	*p = state->out_block + prefix64k;
+	state->decoded_size = uncompressed_size;
+	return uncompressed_size;
+
+malformed_error:
+	archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
+	    "malformed lz4 data");
+	return (ARCHIVE_FATAL);
+truncated_error:
+	archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
+	    "truncated lz4 input");
+	return (ARCHIVE_FATAL);
+}
+
+static ssize_t
+lz4_filter_read_default_stream(struct archive_read_filter *self, const void **p)
+{
+	struct private_data *state = (struct private_data *)self->data;
+	const char *read_buf;
+	ssize_t bytes_remaining;
+	ssize_t ret;
+
+	if (state->stage == SELECT_STREAM) {
+		state->stage = READ_DEFAULT_STREAM;
+		/* First, read a desciprtor. */
+		if((ret = lz4_filter_read_descriptor(self)) != ARCHIVE_OK)
+			return (ret);
+		state->stage = READ_DEFAULT_BLOCK;
+	}
+	/* Decompress a block. */
+	ret = lz4_filter_read_data_block(self, p);
+
+	/* If the end of block is detected, change the filter status
+	   to read next stream. */
+	if (ret == 0 && *p == NULL)
+		state->stage = SELECT_STREAM;
+
+	/* Optional process, checking a stream sum. */
+	if (state->flags.stream_checksum) {
+		if (state->stage == SELECT_STREAM) {
+			unsigned int checksum;
+			unsigned int checksum_stream;
+			read_buf = __archive_read_filter_ahead(self->upstream,
+			    4, &bytes_remaining);
+			if (read_buf == NULL) {
+				archive_set_error(&self->archive->archive,
+				    ARCHIVE_ERRNO_MISC, "truncated lz4 input");
+				return (ARCHIVE_FATAL);
+			}
+			checksum = archive_le32dec(read_buf);
+			__archive_read_filter_consume(self->upstream, 4);
+			checksum_stream = __archive_xxhash.XXH32_digest(
+			    state->xxh32_state);
+			state->xxh32_state = NULL;
+			if (checksum != checksum_stream) {
+				archive_set_error(&self->archive->archive,
+				    ARCHIVE_ERRNO_MISC,
+				    "lz4 stream cheksum error");
+				return (ARCHIVE_FATAL);
+			}
+		} else if (ret > 0)
+			__archive_xxhash.XXH32_update(state->xxh32_state,
+			    *p, (int)ret);
+	}
+	return (ret);
+}
+
+static ssize_t
+lz4_filter_read_legacy_stream(struct archive_read_filter *self, const void **p)
+{
+	struct private_data *state = (struct private_data *)self->data;
+	int compressed;
+	const char *read_buf;
+	ssize_t ret;
+
+	*p = NULL;
+	ret = lz4_allocate_out_block_for_legacy(self);
+	if (ret != ARCHIVE_OK)
+		return ret;
+
+	/* Make sure we have 4 bytes for a block size. */
+	read_buf = __archive_read_filter_ahead(self->upstream, 4, NULL);
+	if (read_buf == NULL) {
+		if (state->stage == SELECT_STREAM) {
+			state->stage = READ_LEGACY_STREAM;
+			archive_set_error(&self->archive->archive,
+			    ARCHIVE_ERRNO_MISC,
+			    "truncated lz4 input");
+			return (ARCHIVE_FATAL);
+		}
+		state->stage = SELECT_STREAM;
+		return 0;
+	}
+	state->stage = READ_LEGACY_BLOCK;
+	compressed = archive_le32dec(read_buf);
+	if (compressed > LZ4_COMPRESSBOUND(LEGACY_BLOCK_SIZE)) {
+		state->stage = SELECT_STREAM;
+		return 0;
+	}
+
+	/* Make sure we have a whole block. */
+	read_buf = __archive_read_filter_ahead(self->upstream,
+	    4 + compressed, NULL);
+	ret = LZ4_decompress_safe(read_buf + 4, state->out_block,
+	    compressed, (int)state->out_block_size);
+	if (ret < 0) {
+		archive_set_error(&(self->archive->archive),
+		    ARCHIVE_ERRNO_MISC, "lz4 decompression failed");
+		return (ARCHIVE_FATAL);
+	}
+	*p = state->out_block;
+	state->unconsumed = 4 + compressed;
+	return ret;
+}
+
+/*
+ * Clean up the decompressor.
+ */
+static int
+lz4_filter_close(struct archive_read_filter *self)
+{
+	struct private_data *state;
+	int ret = ARCHIVE_OK;
+
+	state = (struct private_data *)self->data;
+	free(state->xxh32_state);
+	free(state->out_block);
+	free(state);
+	return (ret);
+}
+
+#endif /* HAVE_LIBLZ4 */
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lzop.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lzop.c
index 9ef2054..23c18c7 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lzop.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lzop.c
@@ -242,10 +242,17 @@ consume_header(struct archive_read_filter *self)
 
 	if (version >= 0x940) {
 		unsigned level = *p++;
+#if 0
 		unsigned default_level[] = {0, 3, 1, 9};
+#endif
 		if (level == 0)
 			/* Method is 1..3 here due to check above. */
+#if 0	/* Avoid an error Clang Static Analyzer claims
+	  "Value stored to 'level' is never read". */
 			level = default_level[method];
+#else
+			;/* NOP */
+#endif
 		else if (level > 9) {
 			archive_set_error(&self->archive->archive,
 			    ARCHIVE_ERRNO_MISC, "Invalid level");
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_uu.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_uu.c
index 471771b..787a619 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_uu.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_uu.c
@@ -509,7 +509,7 @@ read_more:
 			return (ARCHIVE_FATAL);
 		}
 		llen = len;
-		if (nl == 0) {
+		if ((nl == 0) && (uudecode->state != ST_UUEND)) {
 			/*
 			 * Save remaining data which does not contain
 			 * NL('\n','\r').
@@ -527,6 +527,7 @@ read_more:
 				    self->upstream, ravail);
 				goto read_more;
 			}
+			used += len;
 			break;
 		}
 		switch (uudecode->state) {
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_xz.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_xz.c
index a3ad67a..8f48273 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_xz.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_xz.c
@@ -627,7 +627,7 @@ lzip_tail(struct archive_read_filter *self)
 	f = __archive_read_filter_ahead(self->upstream, tail, &avail_in);
 	if (f == NULL && avail_in < 0)
 		return (ARCHIVE_FATAL);
-	if (avail_in < tail) {
+	if (f == NULL || avail_in < tail) {
 		archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
 		    "Lzip: Remaining data is less bytes");
 		return (ARCHIVE_FAILED);
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c
index 47e0752..f045b8f 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c
@@ -108,6 +108,7 @@ __FBSDID("$FreeBSD$");
 #define kMTime			0x14
 #define kAttributes		0x15
 #define kEncodedHeader		0x17
+#define kDummy			0x19
 
 struct _7z_digests {
 	unsigned char	*defineds;
@@ -331,6 +332,11 @@ struct _7zip {
 	int			 has_encrypted_entries;
 };
 
+/* Maximum entry size. This limitation prevents reading intentional
+ * corrupted 7-zip files on assuming there are not so many entries in
+ * the files. */
+#define UMAX_ENTRY	ARCHIVE_LITERAL_ULL(100000000)
+
 static int	archive_read_format_7zip_has_encrypted_entries(struct archive_read *);
 static int	archive_read_support_format_7zip_capabilities(struct archive_read *a);
 static int	archive_read_format_7zip_bid(struct archive_read *, int);
@@ -640,7 +646,7 @@ archive_read_format_7zip_read_header(struct archive_read *a,
 	}
 	zip_entry = zip->entry;
 
-	if (zip->entries_remaining <= 0)
+	if (zip->entries_remaining <= 0 || zip_entry == NULL)
 		return ARCHIVE_EOF;
 	--zip->entries_remaining;
 
@@ -1663,7 +1669,7 @@ parse_7zip_uint64(struct archive_read *a, uint64_t *val)
 			mask >>= 1;
 			continue;
 		}
-		*val += (avail & (mask -1)) << (8 * i);
+		*val += ((uint64_t)(avail & (mask -1))) << (8 * i);
 		break;
 	}
 	return (0);
@@ -1763,7 +1769,7 @@ read_PackInfo(struct archive_read *a, struct _7z_pack_info *pi)
 		return (-1);
 	if (pi->numPackStreams == 0)
 		return (-1);
-	if (1000000 < pi->numPackStreams)
+	if (UMAX_ENTRY < pi->numPackStreams)
 		return (-1);
 
 	/*
@@ -1892,12 +1898,12 @@ read_Folder(struct archive_read *a, struct _7z_folder *f)
 			if (parse_7zip_uint64(
 			    a, &(f->coders[i].numInStreams)) < 0)
 				return (-1);
-			if (1000000 < f->coders[i].numInStreams)
+			if (UMAX_ENTRY < f->coders[i].numInStreams)
 				return (-1);
 			if (parse_7zip_uint64(
 			    a, &(f->coders[i].numOutStreams)) < 0)
 				return (-1);
-			if (1000000 < f->coders[i].numOutStreams)
+			if (UMAX_ENTRY < f->coders[i].numOutStreams)
 				return (-1);
 		}
 
@@ -1937,11 +1943,11 @@ read_Folder(struct archive_read *a, struct _7z_folder *f)
 	for (i = 0; i < f->numBindPairs; i++) {
 		if (parse_7zip_uint64(a, &(f->bindPairs[i].inIndex)) < 0)
 			return (-1);
-		if (1000000 < f->bindPairs[i].inIndex)
+		if (UMAX_ENTRY < f->bindPairs[i].inIndex)
 			return (-1);
 		if (parse_7zip_uint64(a, &(f->bindPairs[i].outIndex)) < 0)
 			return (-1);
-		if (1000000 < f->bindPairs[i].outIndex)
+		if (UMAX_ENTRY < f->bindPairs[i].outIndex)
 			return (-1);
 	}
 
@@ -1967,7 +1973,7 @@ read_Folder(struct archive_read *a, struct _7z_folder *f)
 		for (i = 0; i < f->numPackedStreams; i++) {
 			if (parse_7zip_uint64(a, &(f->packedStreams[i])) < 0)
 				return (-1);
-			if (1000000 < f->packedStreams[i])
+			if (UMAX_ENTRY < f->packedStreams[i])
 				return (-1);
 		}
 	}
@@ -2009,8 +2015,8 @@ read_CodersInfo(struct archive_read *a, struct _7z_coders_info *ci)
 	 */
 	if (parse_7zip_uint64(a, &(ci->numFolders)) < 0)
 		goto failed;
-	if (1000000 < ci->numFolders)
-			return (-1);
+	if (UMAX_ENTRY < ci->numFolders)
+		return (-1);
 
 	/*
 	 * Read External.
@@ -2031,9 +2037,18 @@ read_CodersInfo(struct archive_read *a, struct _7z_coders_info *ci)
 	case 1:
 		if (parse_7zip_uint64(a, &(ci->dataStreamIndex)) < 0)
 			return (-1);
-		if (1000000 < ci->dataStreamIndex)
+		if (UMAX_ENTRY < ci->dataStreamIndex)
 			return (-1);
+		if (ci->numFolders > 0) {
+			archive_set_error(&a->archive, -1,
+			    "Malformed 7-Zip archive");
+			goto failed;
+		}
 		break;
+	default:
+		archive_set_error(&a->archive, -1,
+		    "Malformed 7-Zip archive");
+		goto failed;
 	}
 
 	if ((p = header_bytes(a, 1)) == NULL)
@@ -2136,7 +2151,7 @@ read_SubStreamsInfo(struct archive_read *a, struct _7z_substream_info *ss,
 		for (i = 0; i < numFolders; i++) {
 			if (parse_7zip_uint64(a, &(f[i].numUnpackStreams)) < 0)
 				return (-1);
-			if (1000000 < f[i].numUnpackStreams)
+			if (UMAX_ENTRY < f[i].numUnpackStreams)
 				return (-1);
 			unpack_streams += (size_t)f[i].numUnpackStreams;
 		}
@@ -2385,8 +2400,8 @@ read_Header(struct archive_read *a, struct _7z_header_info *h,
 
 	if (parse_7zip_uint64(a, &(zip->numFiles)) < 0)
 		return (-1);
-	if (1000000 < zip->numFiles)
-			return (-1);
+	if (UMAX_ENTRY < zip->numFiles)
+		return (-1);
 
 	zip->entries = calloc((size_t)zip->numFiles, sizeof(*zip->entries));
 	if (zip->entries == NULL)
@@ -2545,6 +2560,9 @@ read_Header(struct archive_read *a, struct _7z_header_info *h,
 			}
 			break;
 		}
+		case kDummy:
+			if (ll == 0)
+				break;
 		default:
 			if (header_bytes(a, ll) == NULL)
 				return (-1);
@@ -2684,7 +2702,7 @@ read_Times(struct archive_read *a, struct _7z_header_info *h, int type)
 	if (*p) {
 		if (parse_7zip_uint64(a, &(h->dataIndex)) < 0)
 			goto failed;
-		if (1000000 < h->dataIndex)
+		if (UMAX_ENTRY < h->dataIndex)
 			goto failed;
 	}
 
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_all.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_all.c
index 53fe6fa..2127ebd3 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_all.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_all.c
@@ -61,6 +61,7 @@ archive_read_support_format_all(struct archive *a)
 	archive_read_support_format_mtree(a);
 	archive_read_support_format_tar(a);
 	archive_read_support_format_xar(a);
+	archive_read_support_format_warc(a);
 
 	/*
 	 * Install expensive bidders last.  By doing them last, we
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_ar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_ar.c
index 82756c9..4b5b66b 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_ar.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_ar.c
@@ -180,7 +180,7 @@ _ar_read_header(struct archive_read *a, struct archive_entry *entry,
 	if (strncmp(h + AR_fmag_offset, "`\n", 2) != 0) {
 		archive_set_error(&a->archive, EINVAL,
 		    "Incorrect file header signature");
-		return (ARCHIVE_WARN);
+		return (ARCHIVE_FATAL);
 	}
 
 	/* Copy filename into work buffer. */
@@ -239,8 +239,15 @@ _ar_read_header(struct archive_read *a, struct archive_entry *entry,
 	 * and are not terminated in '/', so we don't trim anything
 	 * that starts with '/'.)
 	 */
-	if (filename[0] != '/' && *p == '/')
+	if (filename[0] != '/' && p > filename && *p == '/') {
 		*p = '\0';
+	}
+
+	if (p < filename) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Found entry with empty filename");
+		return (ARCHIVE_FATAL);
+	}
 
 	/*
 	 * '//' is the GNU filename table.
@@ -262,12 +269,12 @@ _ar_read_header(struct archive_read *a, struct archive_entry *entry,
 		if (entry_size == 0) {
 			archive_set_error(&a->archive, EINVAL,
 			    "Invalid string table");
-			return (ARCHIVE_WARN);
+			return (ARCHIVE_FATAL);
 		}
 		if (ar->strtab != NULL) {
 			archive_set_error(&a->archive, EINVAL,
 			    "More than one string tables exist");
-			return (ARCHIVE_WARN);
+			return (ARCHIVE_FATAL);
 		}
 
 		/* Read the filename table into memory. */
@@ -311,11 +318,11 @@ _ar_read_header(struct archive_read *a, struct archive_entry *entry,
 		 */
 		if (ar->strtab == NULL || number > ar->strtab_size) {
 			archive_set_error(&a->archive, EINVAL,
-			    "Can't find long filename for entry");
+			    "Can't find long filename for GNU/SVR4 archive entry");
 			archive_entry_copy_pathname(entry, filename);
 			/* Parse the time, owner, mode, size fields. */
 			ar_parse_common_header(ar, entry, h);
-			return (ARCHIVE_WARN);
+			return (ARCHIVE_FATAL);
 		}
 
 		archive_entry_copy_pathname(entry, &ar->strtab[(size_t)number]);
@@ -573,7 +580,7 @@ bad_string_table:
 	    "Invalid string table");
 	free(ar->strtab);
 	ar->strtab = NULL;
-	return (ARCHIVE_WARN);
+	return (ARCHIVE_FATAL);
 }
 
 static uint64_t
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c
index 0b69689..c2ca85b 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c
@@ -198,7 +198,7 @@ static int	archive_read_format_cpio_read_data(struct archive_read *,
 static int	archive_read_format_cpio_read_header(struct archive_read *,
 		    struct archive_entry *);
 static int	archive_read_format_cpio_skip(struct archive_read *);
-static int	be4(const unsigned char *);
+static int64_t	be4(const unsigned char *);
 static int	find_odc_header(struct archive_read *);
 static int	find_newc_header(struct archive_read *);
 static int	header_bin_be(struct archive_read *, struct cpio *,
@@ -213,7 +213,7 @@ static int	header_afiol(struct archive_read *, struct cpio *,
 		    struct archive_entry *, size_t *, size_t *);
 static int	is_octal(const char *, size_t);
 static int	is_hex(const char *, size_t);
-static int	le4(const unsigned char *);
+static int64_t	le4(const unsigned char *);
 static int	record_hardlink(struct archive_read *a,
 		    struct cpio *cpio, struct archive_entry *entry);
 
@@ -866,8 +866,11 @@ header_bin_le(struct archive_read *a, struct cpio *cpio,
 
 	/* Read fixed-size portion of header. */
 	h = __archive_read_ahead(a, bin_header_size, NULL);
-	if (h == NULL)
+	if (h == NULL) {
+	    archive_set_error(&a->archive, 0,
+		"End of file trying to read next cpio header");
 	    return (ARCHIVE_FATAL);
+	}
 
 	/* Parse out binary fields. */
 	header = (const unsigned char *)h;
@@ -902,8 +905,11 @@ header_bin_be(struct archive_read *a, struct cpio *cpio,
 
 	/* Read fixed-size portion of header. */
 	h = __archive_read_ahead(a, bin_header_size, NULL);
-	if (h == NULL)
+	if (h == NULL) {
+	    archive_set_error(&a->archive, 0,
+		"End of file trying to read next cpio header");
 	    return (ARCHIVE_FATAL);
+	}
 
 	/* Parse out binary fields. */
 	header = (const unsigned char *)h;
@@ -946,17 +952,17 @@ archive_read_format_cpio_cleanup(struct archive_read *a)
 	return (ARCHIVE_OK);
 }
 
-static int
+static int64_t
 le4(const unsigned char *p)
 {
-	return ((p[0]<<16) + (p[1]<<24) + (p[2]<<0) + (p[3]<<8));
+	return ((p[0] << 16) + (((int64_t)p[1]) << 24) + (p[2] << 0) + (p[3] << 8));
 }
 
 
-static int
+static int64_t
 be4(const unsigned char *p)
 {
-	return ((p[0]<<24) + (p[1]<<16) + (p[2]<<8) + (p[3]));
+	return ((((int64_t)p[0]) << 24) + (p[1] << 16) + (p[2] << 8) + (p[3]));
 }
 
 /*
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c
index 2219e61..3628025 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c
@@ -387,7 +387,7 @@ static int	archive_read_format_iso9660_read_data(struct archive_read *,
 static int	archive_read_format_iso9660_read_data_skip(struct archive_read *);
 static int	archive_read_format_iso9660_read_header(struct archive_read *,
 		    struct archive_entry *);
-static const char *build_pathname(struct archive_string *, struct file_info *);
+static const char *build_pathname(struct archive_string *, struct file_info *, int);
 static int	build_pathname_utf16be(unsigned char *, size_t, size_t *,
 		    struct file_info *);
 #if DEBUG
@@ -1225,6 +1225,7 @@ archive_read_format_iso9660_read_header(struct archive_read *a,
 			archive_set_error(&a->archive,
 			    ARCHIVE_ERRNO_FILE_FORMAT,
 			    "Pathname is too long");
+			return (ARCHIVE_FATAL);
 		}
 
 		r = archive_entry_copy_pathname_l(entry,
@@ -1247,9 +1248,16 @@ archive_read_format_iso9660_read_header(struct archive_read *a,
 			rd_r = ARCHIVE_WARN;
 		}
 	} else {
-		archive_string_empty(&iso9660->pathname);
-		archive_entry_set_pathname(entry,
-		    build_pathname(&iso9660->pathname, file));
+		const char *path = build_pathname(&iso9660->pathname, file, 0);
+		if (path == NULL) {
+			archive_set_error(&a->archive,
+			    ARCHIVE_ERRNO_FILE_FORMAT,
+			    "Pathname is too long");
+			return (ARCHIVE_FATAL);
+		} else {
+			archive_string_empty(&iso9660->pathname);
+			archive_entry_set_pathname(entry, path);
+		}
 	}
 
 	iso9660->entry_bytes_remaining = file->size;
@@ -1744,12 +1752,12 @@ parse_file_info(struct archive_read *a, struct file_info *parent,
     const unsigned char *isodirrec)
 {
 	struct iso9660 *iso9660;
-	struct file_info *file;
+	struct file_info *file, *filep;
 	size_t name_len;
 	const unsigned char *rr_start, *rr_end;
 	const unsigned char *p;
 	size_t dr_len;
-	uint64_t fsize;
+	uint64_t fsize, offset;
 	int32_t location;
 	int flags;
 
@@ -1793,6 +1801,16 @@ parse_file_info(struct archive_read *a, struct file_info *parent,
 		return (NULL);
 	}
 
+	/* Sanity check that this entry does not create a cycle. */
+	offset = iso9660->logical_block_size * (uint64_t)location;
+	for (filep = parent; filep != NULL; filep = filep->parent) {
+		if (filep->offset == offset) {
+			archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+			    "Directory structure contains loop");
+			return (NULL);
+		}
+	}
+
 	/* Create a new file entry and copy data from the ISO dir record. */
 	file = (struct file_info *)calloc(1, sizeof(*file));
 	if (file == NULL) {
@@ -1801,7 +1819,7 @@ parse_file_info(struct archive_read *a, struct file_info *parent,
 		return (NULL);
 	}
 	file->parent = parent;
-	file->offset = iso9660->logical_block_size * (uint64_t)location;
+	file->offset = offset;
 	file->size = fsize;
 	file->mtime = isodate7(isodirrec + DR_date_offset);
 	file->ctime = file->atime = file->mtime;
@@ -3147,29 +3165,39 @@ static time_t
 time_from_tm(struct tm *t)
 {
 #if HAVE_TIMEGM
-	/* Use platform timegm() if available. */
-	return (timegm(t));
+        /* Use platform timegm() if available. */
+        return (timegm(t));
 #elif HAVE__MKGMTIME64
-	return (_mkgmtime64(t));
+        return (_mkgmtime64(t));
 #else
-	/* Else use direct calculation using POSIX assumptions. */
-	/* First, fix up tm_yday based on the year/month/day. */
-	if (mktime(t) == (time_t)-1)
-		return ((time_t)-1);
-	/* Then we can compute timegm() from first principles. */
-	return (t->tm_sec + t->tm_min * 60 + t->tm_hour * 3600
-	    + t->tm_yday * 86400 + (t->tm_year - 70) * 31536000
-	    + ((t->tm_year - 69) / 4) * 86400 -
-	    ((t->tm_year - 1) / 100) * 86400
-	    + ((t->tm_year + 299) / 400) * 86400);
+        /* Else use direct calculation using POSIX assumptions. */
+        /* First, fix up tm_yday based on the year/month/day. */
+        if (mktime(t) == (time_t)-1)
+                return ((time_t)-1);
+        /* Then we can compute timegm() from first principles. */
+        return (t->tm_sec
+            + t->tm_min * 60
+            + t->tm_hour * 3600
+            + t->tm_yday * 86400
+            + (t->tm_year - 70) * 31536000
+            + ((t->tm_year - 69) / 4) * 86400
+            - ((t->tm_year - 1) / 100) * 86400
+            + ((t->tm_year + 299) / 400) * 86400);
 #endif
 }
 
 static const char *
-build_pathname(struct archive_string *as, struct file_info *file)
+build_pathname(struct archive_string *as, struct file_info *file, int depth)
 {
+	// Plain ISO9660 only allows 8 dir levels; if we get
+	// to 1000, then something is very, very wrong.
+	if (depth > 1000) {
+		return NULL;
+	}
 	if (file->parent != NULL && archive_strlen(&file->parent->name) > 0) {
-		build_pathname(as, file->parent);
+		if (build_pathname(as, file->parent, depth + 1) == NULL) {
+			return NULL;
+		}
 		archive_strcat(as, "/");
 	}
 	if (archive_strlen(&file->name) == 0)
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c
index b88731a..eff02d8 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2008-2012 Michihiro NAKAJIMA
+ * Copyright (c) 2008-2014 Michihiro NAKAJIMA
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -82,9 +82,6 @@ struct lzh_dec {
 	/* The length how many bytes we can copy decoded code from
 	 * the window. */
 	int     		 copy_len;
-	/* The remaining bytes that we have not copied decoded data from
-	 * the window to an output buffer. */
-	int			 w_remaining;
 
 	/*
 	 * Bit stream reader.
@@ -140,10 +137,10 @@ struct lzh_dec {
 
 struct lzh_stream {
 	const unsigned char	*next_in;
-	int64_t			 avail_in;
+	int			 avail_in;
 	int64_t			 total_in;
-	unsigned char		*next_out;
-	int64_t			 avail_out;
+	const unsigned char	*ref_ptr;
+	int			 avail_out;
 	int64_t			 total_out;
 	struct lzh_dec		*ds;
 };
@@ -198,9 +195,6 @@ struct lha {
 	char			 end_of_entry_cleanup;
 	char			 entry_is_compressed;
 
-	unsigned char		*uncompressed_buffer;
-	size_t			 uncompressed_buffer_size;
-
 	char			 format_name[64];
 
 	struct lzh_stream	 strm;
@@ -214,41 +208,6 @@ struct lha {
 #define H_LEVEL_OFFSET	20	/* Header Level.  */
 #define H_SIZE		22	/* Minimum header size. */
 
-static const uint16_t crc16tbl[256] = {
-	0x0000,0xC0C1,0xC181,0x0140,0xC301,0x03C0,0x0280,0xC241,
-	0xC601,0x06C0,0x0780,0xC741,0x0500,0xC5C1,0xC481,0x0440,
-	0xCC01,0x0CC0,0x0D80,0xCD41,0x0F00,0xCFC1,0xCE81,0x0E40,
-	0x0A00,0xCAC1,0xCB81,0x0B40,0xC901,0x09C0,0x0880,0xC841,
-	0xD801,0x18C0,0x1980,0xD941,0x1B00,0xDBC1,0xDA81,0x1A40,
-	0x1E00,0xDEC1,0xDF81,0x1F40,0xDD01,0x1DC0,0x1C80,0xDC41,
-	0x1400,0xD4C1,0xD581,0x1540,0xD701,0x17C0,0x1680,0xD641,
-	0xD201,0x12C0,0x1380,0xD341,0x1100,0xD1C1,0xD081,0x1040,
-	0xF001,0x30C0,0x3180,0xF141,0x3300,0xF3C1,0xF281,0x3240,
-	0x3600,0xF6C1,0xF781,0x3740,0xF501,0x35C0,0x3480,0xF441,
-	0x3C00,0xFCC1,0xFD81,0x3D40,0xFF01,0x3FC0,0x3E80,0xFE41,
-	0xFA01,0x3AC0,0x3B80,0xFB41,0x3900,0xF9C1,0xF881,0x3840,
-	0x2800,0xE8C1,0xE981,0x2940,0xEB01,0x2BC0,0x2A80,0xEA41,
-	0xEE01,0x2EC0,0x2F80,0xEF41,0x2D00,0xEDC1,0xEC81,0x2C40,
-	0xE401,0x24C0,0x2580,0xE541,0x2700,0xE7C1,0xE681,0x2640,
-	0x2200,0xE2C1,0xE381,0x2340,0xE101,0x21C0,0x2080,0xE041,
-	0xA001,0x60C0,0x6180,0xA141,0x6300,0xA3C1,0xA281,0x6240,
-	0x6600,0xA6C1,0xA781,0x6740,0xA501,0x65C0,0x6480,0xA441,
-	0x6C00,0xACC1,0xAD81,0x6D40,0xAF01,0x6FC0,0x6E80,0xAE41,
-	0xAA01,0x6AC0,0x6B80,0xAB41,0x6900,0xA9C1,0xA881,0x6840,
-	0x7800,0xB8C1,0xB981,0x7940,0xBB01,0x7BC0,0x7A80,0xBA41,
-	0xBE01,0x7EC0,0x7F80,0xBF41,0x7D00,0xBDC1,0xBC81,0x7C40,
-	0xB401,0x74C0,0x7580,0xB541,0x7700,0xB7C1,0xB681,0x7640,
-	0x7200,0xB2C1,0xB381,0x7340,0xB101,0x71C0,0x7080,0xB041,
-	0x5000,0x90C1,0x9181,0x5140,0x9301,0x53C0,0x5280,0x9241,
-	0x9601,0x56C0,0x5780,0x9741,0x5500,0x95C1,0x9481,0x5440,
-	0x9C01,0x5CC0,0x5D80,0x9D41,0x5F00,0x9FC1,0x9E81,0x5E40,
-	0x5A00,0x9AC1,0x9B81,0x5B40,0x9901,0x59C0,0x5880,0x9841,
-	0x8801,0x48C0,0x4980,0x8941,0x4B00,0x8BC1,0x8A81,0x4A40,
-	0x4E00,0x8EC1,0x8F81,0x4F40,0x8D01,0x4DC0,0x4C80,0x8C41,
-	0x4400,0x84C1,0x8581,0x4540,0x8701,0x47C0,0x4680,0x8641,
-	0x8201,0x42C0,0x4380,0x8341,0x4100,0x81C1,0x8081,0x4040
-};
-
 static int      archive_read_format_lha_bid(struct archive_read *, int);
 static int      archive_read_format_lha_options(struct archive_read *,
 		    const char *, const char *);
@@ -279,6 +238,7 @@ static int	lha_read_data_none(struct archive_read *, const void **,
 		    size_t *, int64_t *);
 static int	lha_read_data_lzh(struct archive_read *, const void **,
 		    size_t *, int64_t *);
+static void	lha_crc16_init(void);
 static uint16_t lha_crc16(uint16_t, const void *, size_t);
 static int	lzh_decode_init(struct lzh_stream *, const char *);
 static void	lzh_decode_free(struct lzh_stream *);
@@ -520,6 +480,8 @@ archive_read_format_lha_read_header(struct archive_read *a,
 	const char *signature;
 	int err;
 	
+	lha_crc16_init();
+
 	a->archive.archive_format = ARCHIVE_FORMAT_LHA;
 	if (a->archive.archive_format_name == NULL)
 		a->archive.archive_format_name = "lha";
@@ -1232,13 +1194,15 @@ lha_read_file_extended_header(struct archive_read *a, struct lha *lha,
 				archive_string_empty(&lha->filename);
 				break;
 			}
+			if (extdheader[0] == '\0')
+				goto invalid;
 			archive_strncpy(&lha->filename,
 			    (const char *)extdheader, datasize);
 			break;
 		case EXT_DIRECTORY:
-			if (datasize == 0)
+			if (datasize == 0 || extdheader[0] == '\0')
 				/* no directory name data. exit this case. */
-				break;
+				goto invalid;
 
 			archive_strncpy(&lha->dirname,
 		  	    (const char *)extdheader, datasize);
@@ -1378,6 +1342,26 @@ invalid:
 }
 
 static int
+lha_end_of_entry(struct archive_read *a)
+{
+	struct lha *lha = (struct lha *)(a->format->data);
+	int r = ARCHIVE_EOF;
+
+	if (!lha->end_of_entry_cleanup) {
+		if ((lha->setflag & CRC_IS_SET) &&
+		    lha->crc != lha->entry_crc_calculated) {
+			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+			    "LHa data CRC error");
+			r = ARCHIVE_WARN;
+		}
+
+		/* End-of-entry cleanup done. */
+		lha->end_of_entry_cleanup = 1;
+	}
+	return (r);
+}
+
+static int
 archive_read_format_lha_read_data(struct archive_read *a,
     const void **buff, size_t *size, int64_t *offset)
 {
@@ -1390,22 +1374,10 @@ archive_read_format_lha_read_data(struct archive_read *a,
 		lha->entry_unconsumed = 0;
 	}
 	if (lha->end_of_entry) {
-		if (!lha->end_of_entry_cleanup) {
-			if ((lha->setflag & CRC_IS_SET) &&
-			    lha->crc != lha->entry_crc_calculated) {
-				archive_set_error(&a->archive,
-				    ARCHIVE_ERRNO_MISC,
-				    "LHa data CRC error");
-				return (ARCHIVE_WARN);
-			}
-
-			/* End-of-entry cleanup done. */
-			lha->end_of_entry_cleanup = 1;
-		}
 		*offset = lha->entry_offset;
 		*size = 0;
 		*buff = NULL;
-		return (ARCHIVE_EOF);
+		return (lha_end_of_entry(a));
 	}
 
 	if (lha->entry_is_compressed)
@@ -1477,18 +1449,6 @@ lha_read_data_lzh(struct archive_read *a, const void **buff,
 	ssize_t bytes_avail;
 	int r;
 
-	/* If the buffer hasn't been allocated, allocate it now. */
-	if (lha->uncompressed_buffer == NULL) {
-		lha->uncompressed_buffer_size = 64 * 1024;
-		lha->uncompressed_buffer
-		    = (unsigned char *)malloc(lha->uncompressed_buffer_size);
-		if (lha->uncompressed_buffer == NULL) {
-			archive_set_error(&a->archive, ENOMEM,
-			    "No memory for lzh decompression");
-			return (ARCHIVE_FATAL);
-		}
-	}
-
 	/* If we haven't yet read any data, initialize the decompressor. */
 	if (!lha->decompress_init) {
 		r = lzh_decode_init(&(lha->strm), lha->method);
@@ -1534,12 +1494,9 @@ lha_read_data_lzh(struct archive_read *a, const void **buff,
 	if (bytes_avail > lha->entry_bytes_remaining)
 		bytes_avail = (ssize_t)lha->entry_bytes_remaining;
 
-	lha->strm.avail_in = bytes_avail;
+	lha->strm.avail_in = (int)bytes_avail;
 	lha->strm.total_in = 0;
-	if (lha->strm.avail_out == 0) {
-		lha->strm.next_out = lha->uncompressed_buffer;
-		lha->strm.avail_out = lha->uncompressed_buffer_size;
-	}
+	lha->strm.avail_out = 0;
 
 	r = lzh_decode(&(lha->strm), bytes_avail == lha->entry_bytes_remaining);
 	switch (r) {
@@ -1556,10 +1513,10 @@ lha_read_data_lzh(struct archive_read *a, const void **buff,
 	lha->entry_unconsumed = lha->strm.total_in;
 	lha->entry_bytes_remaining -= lha->strm.total_in;
 
-	if (lha->strm.avail_out == 0 || lha->end_of_entry) {
+	if (lha->strm.avail_out) {
 		*offset = lha->entry_offset;
-		*size = lha->strm.next_out - lha->uncompressed_buffer;
-		*buff = lha->uncompressed_buffer;
+		*size = lha->strm.avail_out;
+		*buff = lha->strm.ref_ptr;
 		lha->entry_crc_calculated =
 		    lha_crc16(lha->entry_crc_calculated, *buff, *size);
 		lha->entry_offset += *size;
@@ -1567,6 +1524,8 @@ lha_read_data_lzh(struct archive_read *a, const void **buff,
 		*offset = lha->entry_offset;
 		*size = 0;
 		*buff = NULL;
+		if (lha->end_of_entry)
+			return (lha_end_of_entry(a));
 	}
 	return (ARCHIVE_OK);
 }
@@ -1611,7 +1570,6 @@ archive_read_format_lha_cleanup(struct archive_read *a)
 	struct lha *lha = (struct lha *)(a->format->data);
 
 	lzh_decode_free(&(lha->strm));
-	free(lha->uncompressed_buffer);
 	archive_string_free(&(lha->dirname));
 	archive_string_free(&(lha->filename));
 	archive_string_free(&(lha->uname));
@@ -1702,50 +1660,90 @@ lha_calcsum(unsigned char sum, const void *pp, int offset, size_t size)
 	return (sum);
 }
 
-#define CRC16(crc, v)	do {	\
-	(crc) = crc16tbl[((crc) ^ v) & 0xFF] ^ ((crc) >> 8);	\
-} while (0)
+static uint16_t crc16tbl[2][256];
+static void
+lha_crc16_init(void)
+{
+	unsigned int i;
+	static int crc16init = 0;
+
+	if (crc16init)
+		return;
+	crc16init = 1;
+
+	for (i = 0; i < 256; i++) {
+		unsigned int j;
+		uint16_t crc = (uint16_t)i;
+		for (j = 8; j; j--)
+			crc = (crc >> 1) ^ ((crc & 1) * 0xA001);
+		crc16tbl[0][i] = crc;
+	}
+
+	for (i = 0; i < 256; i++) {
+		crc16tbl[1][i] = (crc16tbl[0][i] >> 8)
+			^ crc16tbl[0][crc16tbl[0][i] & 0xff];
+	}
+}
 
 static uint16_t
 lha_crc16(uint16_t crc, const void *pp, size_t len)
 {
-	const unsigned char *buff = (const unsigned char *)pp;
-
-	while (len >= 8) {
-		CRC16(crc, *buff++); CRC16(crc, *buff++);
-		CRC16(crc, *buff++); CRC16(crc, *buff++);
-		CRC16(crc, *buff++); CRC16(crc, *buff++);
-		CRC16(crc, *buff++); CRC16(crc, *buff++);
-		len -= 8;
+	const unsigned char *p = (const unsigned char *)pp;
+	const uint16_t *buff;
+	const union {
+		uint32_t i;
+		char c[4];
+	} u = { 0x01020304 };
+
+	if (len == 0)
+		return crc;
+
+	/* Process unaligned address. */
+	if (((uintptr_t)p) & (uintptr_t)0x1) {
+		crc = (crc >> 8) ^ crc16tbl[0][(crc ^ *p++) & 0xff];
+		len--;
 	}
-	switch (len) {
-	case 7:
-		CRC16(crc, *buff++);
-		/* FALL THROUGH */
-	case 6:
-		CRC16(crc, *buff++);
-		/* FALL THROUGH */
-	case 5:
-		CRC16(crc, *buff++);
-		/* FALL THROUGH */
-	case 4:
-		CRC16(crc, *buff++);
-		/* FALL THROUGH */
-	case 3:
-		CRC16(crc, *buff++);
-		/* FALL THROUGH */
-	case 2:
-		CRC16(crc, *buff++);
-		/* FALL THROUGH */
-	case 1:
-		CRC16(crc, *buff);
-		/* FALL THROUGH */
-	case 0:
-		break;
+	buff = (const uint16_t *)p;
+	/*
+	 * Modern C compiler such as GCC does not unroll automatically yet
+	 * without unrolling pragma, and Clang is so. So we should
+	 * unroll this loop for its performance.
+	 */
+	for (;len >= 8; len -= 8) {
+		/* This if statement expects compiler optimization will
+		 * remove the stament which will not be executed. */
+#ifndef __has_builtin
+#  define __has_builtin(x) 0
+#endif
+#if defined(_MSC_VER) && _MSC_VER >= 1400  /* Visual Studio */
+#  define bswap16(x) _byteswap_ushort(x)
+#elif (defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 8) \
+      || (defined(__clang__) && __has_builtin(__builtin_bswap16))
+#  define bswap16(x) __builtin_bswap16(x)
+#else
+#  define bswap16(x) ((((x) >> 8) & 0xff) | ((x) << 8))
+#endif
+#define CRC16W	do { 	\
+		if(u.c[0] == 1) { /* Big endian */		\
+			crc ^= bswap16(*buff); buff++;		\
+		} else						\
+			crc ^= *buff++;				\
+		crc = crc16tbl[1][crc & 0xff] ^ crc16tbl[0][crc >> 8];\
+} while (0)
+		CRC16W;
+		CRC16W;
+		CRC16W;
+		CRC16W;
+#undef CRC16W
+#undef bswap16
 	}
-	return (crc);
-}
 
+	p = (const unsigned char *)buff;
+	for (;len; len--) {
+		crc = (crc >> 8) ^ crc16tbl[0][(crc ^ *p++) & 0xff];
+	}
+	return crc;
+}
 
 /*
  * Initialize LZHUF decoder.
@@ -1784,18 +1782,18 @@ lzh_decode_init(struct lzh_stream *strm, const char *method)
 		return (ARCHIVE_FAILED);/* Not supported. */
 	}
 	ds->error = ARCHIVE_FATAL;
-	w_size = ds->w_size;
-	ds->w_size = 1U << w_bits;
+	/* Expand a window size up to 128 KiB for decompressing process
+	 * performance whatever its original window size is. */
+	ds->w_size = 1U << 17;
 	ds->w_mask = ds->w_size -1;
-	if (ds->w_buff == NULL || w_size != ds->w_size) {
-		free(ds->w_buff);
+	if (ds->w_buff == NULL) {
 		ds->w_buff = malloc(ds->w_size);
 		if (ds->w_buff == NULL)
 			return (ARCHIVE_FATAL);
 	}
-	memset(ds->w_buff, 0x20, ds->w_size);
+	w_size = 1U << w_bits;
+	memset(ds->w_buff + ds->w_size - w_size, 0x20, w_size);
 	ds->w_pos = 0;
-	ds->w_remaining = 0;
 	ds->state = 0;
 	ds->pos_pt_len_size = w_bits + 1;
 	ds->pos_pt_len_bits = (w_bits == 15 || w_bits == 16)? 5: 4;
@@ -1882,9 +1880,10 @@ lzh_br_fillup(struct lzh_stream *strm, struct lzh_br *br)
 	int n = CACHE_BITS - br->cache_avail;
 
 	for (;;) {
-		switch (n >> 3) {
-		case 8:
-			if (strm->avail_in >= 8) {
+		const int x = n >> 3;
+		if (strm->avail_in >= x) {
+			switch (x) {
+			case 8:
 				br->cache_buffer =
 				    ((uint64_t)strm->next_in[0]) << 56 |
 				    ((uint64_t)strm->next_in[1]) << 48 |
@@ -1898,10 +1897,7 @@ lzh_br_fillup(struct lzh_stream *strm, struct lzh_br *br)
 				strm->avail_in -= 8;
 				br->cache_avail += 8 * 8;
 				return (1);
-			}
-			break;
-		case 7:
-			if (strm->avail_in >= 7) {
+			case 7:
 				br->cache_buffer =
 		 		   (br->cache_buffer << 56) |
 				    ((uint64_t)strm->next_in[0]) << 48 |
@@ -1915,10 +1911,7 @@ lzh_br_fillup(struct lzh_stream *strm, struct lzh_br *br)
 				strm->avail_in -= 7;
 				br->cache_avail += 7 * 8;
 				return (1);
-			}
-			break;
-		case 6:
-			if (strm->avail_in >= 6) {
+			case 6:
 				br->cache_buffer =
 		 		   (br->cache_buffer << 48) |
 				    ((uint64_t)strm->next_in[0]) << 40 |
@@ -1931,14 +1924,13 @@ lzh_br_fillup(struct lzh_stream *strm, struct lzh_br *br)
 				strm->avail_in -= 6;
 				br->cache_avail += 6 * 8;
 				return (1);
+			case 0:
+				/* We have enough compressed data in
+				 * the cache buffer.*/
+				return (1);
+			default:
+				break;
 			}
-			break;
-		case 0:
-			/* We have enough compressed data in
-			 * the cache buffer.*/ 
-			return (1);
-		default:
-			break;
 		}
 		if (strm->avail_in == 0) {
 			/* There is not enough compressed data to fill up the
@@ -1993,7 +1985,7 @@ static int
 lzh_decode(struct lzh_stream *strm, int last)
 {
 	struct lzh_dec *ds = strm->ds;
-	int64_t avail_in;
+	int avail_in;
 	int r;
 
 	if (ds->error)
@@ -2010,35 +2002,12 @@ lzh_decode(struct lzh_stream *strm, int last)
 	return (r);
 }
 
-static int
-lzh_copy_from_window(struct lzh_stream *strm, struct lzh_dec *ds)
+static void
+lzh_emit_window(struct lzh_stream *strm, size_t s)
 {
-	size_t copy_bytes;
-
-	if (ds->w_remaining == 0 && ds->w_pos > 0) {
-		if (ds->w_pos - ds->copy_pos <= strm->avail_out)
-			copy_bytes = ds->w_pos - ds->copy_pos;
-		else
-			copy_bytes = (size_t)strm->avail_out;
-		memcpy(strm->next_out,
-		    ds->w_buff + ds->copy_pos, copy_bytes);
-		ds->copy_pos += (int)copy_bytes;
-	} else {
-		if (ds->w_remaining <= strm->avail_out)
-			copy_bytes = ds->w_remaining;
-		else
-			copy_bytes = (size_t)strm->avail_out;
-		memcpy(strm->next_out,
-		    ds->w_buff + ds->w_size - ds->w_remaining, copy_bytes);
-		ds->w_remaining -= (int)copy_bytes;
-	}
-	strm->next_out += copy_bytes;
-	strm->avail_out -= copy_bytes;
-	strm->total_out += copy_bytes;
-	if (strm->avail_out == 0)
-		return (0);
-	else
-		return (1);
+	strm->ref_ptr = strm->ds->w_buff;
+	strm->avail_out = (int)s;
+	strm->total_out += s;
 }
 
 static int
@@ -2073,8 +2042,9 @@ lzh_read_blocks(struct lzh_stream *strm, int last)
 					goto failed;
 				}
 				if (ds->w_pos > 0) {
-					if (!lzh_copy_from_window(strm, ds))
-						return (ARCHIVE_OK);
+					lzh_emit_window(strm, ds->w_pos);
+					ds->w_pos = 0;
+					return (ARCHIVE_OK);
 				}
 				/* End of compressed data; we have completely
 				 * handled all compressed data. */
@@ -2291,10 +2261,6 @@ lzh_decode_blocks(struct lzh_stream *strm, int last)
 	int lt_max_bits = lt->max_bits, pt_max_bits = pt->max_bits;
 	int state = ds->state;
 
-	if (ds->w_remaining > 0) {
-		if (!lzh_copy_from_window(strm, ds))
-			goto next_data;
-	}
 	for (;;) {
 		switch (state) {
 		case ST_GET_LITERAL:
@@ -2349,9 +2315,8 @@ lzh_decode_blocks(struct lzh_stream *strm, int last)
 				w_buff[w_pos] = c;
 				if (++w_pos >= w_size) {
 					w_pos = 0;
-					ds->w_remaining = w_size;
-					if (!lzh_copy_from_window(strm, ds))
-						goto next_data;
+					lzh_emit_window(strm, w_size);
+					goto next_data;
 				}
 			}
 			/* 'c' is the length of a match pattern we have
@@ -2429,25 +2394,26 @@ lzh_decode_blocks(struct lzh_stream *strm, int last)
 
 					d = w_buff + w_pos;
 					s = w_buff + copy_pos;
-					for (li = 0; li < l; li++)
+					for (li = 0; li < l-1;) {
+						d[li] = s[li];li++;
+						d[li] = s[li];li++;
+					}
+					if (li < l)
 						d[li] = s[li];
 				}
-				w_pos = (w_pos + l) & w_mask;
-				if (w_pos == 0) {
-					ds->w_remaining = w_size;
-					if (!lzh_copy_from_window(strm, ds)) {
-						if (copy_len <= l)
-							state = ST_GET_LITERAL;
-						else {
-							state = ST_COPY_DATA;
-							ds->copy_len =
-							    copy_len - l;
-							ds->copy_pos =
-							    (copy_pos + l)
-							    & w_mask;
-						}
-						goto next_data;
+				w_pos += l;
+				if (w_pos == w_size) {
+					w_pos = 0;
+					lzh_emit_window(strm, w_size);
+					if (copy_len <= l)
+						state = ST_GET_LITERAL;
+					else {
+						state = ST_COPY_DATA;
+						ds->copy_len = copy_len - l;
+						ds->copy_pos =
+						    (copy_pos + l) & w_mask;
 					}
+					goto next_data;
 				}
 				if (copy_len <= l)
 					/* A copy of current pattern ended. */
@@ -2507,14 +2473,80 @@ lzh_huffman_free(struct huffman *hf)
 	free(hf->tree);
 }
 
+static char bitlen_tbl[0x400] = {
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	 9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
+	 9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
+	 9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
+	 9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
+	 9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
+	 9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
+	 9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
+	 9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
+	10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+	10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+	10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+	10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+	11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+	11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+	12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+	13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 16,  0
+};
 static int
 lzh_read_pt_bitlen(struct lzh_stream *strm, int start, int end)
 {
 	struct lzh_dec *ds = strm->ds;
-	struct lzh_br * br = &(ds->br);
+	struct lzh_br *br = &(ds->br);
 	int c, i;
 
-	for (i = start; i < end;) {
+	for (i = start; i < end; ) {
 		/*
 		 *  bit pattern     the number we need
 		 *     000           ->  0
@@ -2530,17 +2562,13 @@ lzh_read_pt_bitlen(struct lzh_stream *strm, int start, int end)
 		if (!lzh_br_read_ahead(strm, br, 3))
 			return (i);
 		if ((c = lzh_br_bits(br, 3)) == 7) {
-			int d;
 			if (!lzh_br_read_ahead(strm, br, 13))
 				return (i);
-			d = lzh_br_bits(br, 13);
-			while (d & 0x200) {
-				c++;
-				d <<= 1;
-			}
-			if (c > 16)
+			c = bitlen_tbl[lzh_br_bits(br, 13) & 0x3FF];
+			if (c)
+				lzh_br_consume(br, c - 3);
+			else
 				return (-1);/* Invalid data. */
-			lzh_br_consume(br, c - 3);
 		} else
 			lzh_br_consume(br, 3);
 		ds->pt.bitlen[i++] = c;
@@ -2603,7 +2631,7 @@ lzh_make_huffman_table(struct huffman *hf)
 		}
 	}
 	if (maxbits > HTBL_BITS) {
-		int htbl_max;
+		unsigned htbl_max;
 		uint16_t *p;
 
 		diffbits = maxbits - HTBL_BITS;
@@ -2647,8 +2675,40 @@ lzh_make_huffman_table(struct huffman *hf)
 				return (0);/* Invalid */
 			/* Update the table */
 			p = &(tbl[ptn]);
-			while (--cnt >= 0)
-				p[cnt] = (uint16_t)i;
+			if (cnt > 7) {
+				uint16_t *pc;
+
+				cnt -= 8;
+				pc = &p[cnt];
+				pc[0] = (uint16_t)i;
+				pc[1] = (uint16_t)i;
+				pc[2] = (uint16_t)i;
+				pc[3] = (uint16_t)i;
+				pc[4] = (uint16_t)i;
+				pc[5] = (uint16_t)i;
+				pc[6] = (uint16_t)i;
+				pc[7] = (uint16_t)i;
+				if (cnt > 7) {
+					cnt -= 8;
+					memcpy(&p[cnt], pc,
+						8 * sizeof(uint16_t));
+					pc = &p[cnt];
+					while (cnt > 15) {
+						cnt -= 16;
+						memcpy(&p[cnt], pc,
+							16 * sizeof(uint16_t));
+					}
+				}
+				if (cnt)
+					memcpy(p, pc, cnt * sizeof(uint16_t));
+			} else {
+				while (cnt > 1) {
+					p[--cnt] = (uint16_t)i;
+					p[--cnt] = (uint16_t)i;
+				}
+				if (cnt)
+					p[--cnt] = (uint16_t)i;
+			}
 			continue;
 		}
 
@@ -2742,7 +2802,7 @@ lzh_decode_huffman(struct huffman *hf, unsigned rbits)
 	 * If it fails, search a huffman tree for.
 	 */
 	c = hf->tbl[rbits >> hf->shift_bits];
-	if (c < hf->len_avail)
+	if (c < hf->len_avail || hf->len_avail == 0)
 		return (c);
 	/* This bit pattern needs to be found out at a huffman tree. */
 	return (lzh_decode_huffman_tree(hf, rbits, c));
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c
index d82d4c1..b5f8e30 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c
@@ -139,16 +139,19 @@ get_time_t_max(void)
 #if defined(TIME_T_MAX)
 	return TIME_T_MAX;
 #else
-	static time_t t;
-	time_t a;
-	if (t == 0) {
-		a = 1;
-		while (a > t) {
-			t = a;
-			a = a * 2 + 1;
-		}
+	/* ISO C allows time_t to be a floating-point type,
+	   but POSIX requires an integer type.  The following
+	   should work on any system that follows the POSIX
+	   conventions. */
+	if (((time_t)0) < ((time_t)-1)) {
+		/* Time_t is unsigned */
+		return (~(time_t)0);
+	} else {
+		/* Time_t is signed. */
+		const uintmax_t max_unsigned_time_t = (uintmax_t)(~(time_t)0);
+		const uintmax_t max_signed_time_t = max_unsigned_time_t >> 1;
+		return (time_t)max_signed_time_t;
 	}
-	return t;
 #endif
 }
 
@@ -158,20 +161,16 @@ get_time_t_min(void)
 #if defined(TIME_T_MIN)
 	return TIME_T_MIN;
 #else
-	/* 't' will hold the minimum value, which will be zero (if
-	 * time_t is unsigned) or -2^n (if time_t is signed). */
-	static int computed;
-	static time_t t;
-	time_t a;
-	if (computed == 0) {
-		a = (time_t)-1;
-		while (a < t) {
-			t = a;
-			a = a * 2;
-		}			
-		computed = 1;
+	if (((time_t)0) < ((time_t)-1)) {
+		/* Time_t is unsigned */
+		return (time_t)0;
+	} else {
+		/* Time_t is signed. */
+		const uintmax_t max_unsigned_time_t = (uintmax_t)(~(time_t)0);
+		const uintmax_t max_signed_time_t = max_unsigned_time_t >> 1;
+		const intmax_t min_signed_time_t = (intmax_t)~max_signed_time_t;
+		return (time_t)min_signed_time_t;
 	}
-	return t;
 #endif
 }
 
@@ -532,32 +531,34 @@ bid_entry(const char *p, ssize_t len, ssize_t nl, int *last_is_path)
 		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* E0 - EF */
 		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F0 - FF */
 	};
-	ssize_t ll = len;
+	ssize_t ll;
 	const char *pp = p;
+	const char * const pp_end = pp + len;
 
 	*last_is_path = 0;
 	/*
 	 * Skip the path-name which is quoted.
 	 */
-	while (ll > 0 && *pp != ' ' &&*pp != '\t' && *pp != '\r' &&
-	    *pp != '\n') {
+	for (;pp < pp_end; ++pp) {
 		if (!safe_char[*(const unsigned char *)pp]) {
-			f = 0;
+			if (*pp != ' ' && *pp != '\t' && *pp != '\r'
+			    && *pp != '\n')
+				f = 0;
 			break;
 		}
-		++pp;
-		--ll;
-		++f;
+		f = 1;
 	}
+	ll = pp_end - pp;
+
 	/* If a path-name was not found at the first, try to check
-	 * a mtree format ``NetBSD's mtree -D'' creates, which
-	 * places the path-name at the last. */
+	 * a mtree format(a.k.a form D) ``NetBSD's mtree -D'' creates,
+	 * which places the path-name at the last. */
 	if (f == 0) {
 		const char *pb = p + len - nl;
 		int name_len = 0;
 		int slash;
 
-		/* Do not accept multi lines for form D. */
+		/* The form D accepts only a single line for an entry. */
 		if (pb-2 >= p &&
 		    pb[-1] == '\\' && (pb[-2] == ' ' || pb[-2] == '\t'))
 			return (-1);
@@ -1056,7 +1057,8 @@ read_header(struct archive_read *a, struct archive_entry *entry)
 		}
 		if (!mtree->this_entry->used) {
 			use_next = 0;
-			r = parse_file(a, entry, mtree, mtree->this_entry, &use_next);
+			r = parse_file(a, entry, mtree, mtree->this_entry,
+				&use_next);
 			if (use_next == 0)
 				return (r);
 		}
@@ -1151,8 +1153,8 @@ parse_file(struct archive_read *a, struct archive_entry *entry,
 			mtree->fd = open(path, O_RDONLY | O_BINARY | O_CLOEXEC);
 			__archive_ensure_cloexec_flag(mtree->fd);
 			if (mtree->fd == -1 &&
-					(errno != ENOENT ||
-					 archive_strlen(&mtree->contents_name) > 0)) {
+				(errno != ENOENT ||
+				 archive_strlen(&mtree->contents_name) > 0)) {
 				archive_set_error(&a->archive, errno,
 						"Can't open %s", path);
 				r = ARCHIVE_WARN;
@@ -1175,76 +1177,79 @@ parse_file(struct archive_read *a, struct archive_entry *entry,
 		}
 
 		/*
-		 * Check for a mismatch between the type in the specification and
-		 * the type of the contents object on disk.
+		 * Check for a mismatch between the type in the specification
+		 * and the type of the contents object on disk.
 		 */
 		if (st != NULL) {
-			if (
-					((st->st_mode & S_IFMT) == S_IFREG &&
-					 archive_entry_filetype(entry) == AE_IFREG)
+			if (((st->st_mode & S_IFMT) == S_IFREG &&
+			      archive_entry_filetype(entry) == AE_IFREG)
 #ifdef S_IFLNK
-					|| ((st->st_mode & S_IFMT) == S_IFLNK &&
-						archive_entry_filetype(entry) == AE_IFLNK)
+			  ||((st->st_mode & S_IFMT) == S_IFLNK &&
+			      archive_entry_filetype(entry) == AE_IFLNK)
 #endif
 #ifdef S_IFSOCK
-					|| ((st->st_mode & S_IFSOCK) == S_IFSOCK &&
-						archive_entry_filetype(entry) == AE_IFSOCK)
+			  ||((st->st_mode & S_IFSOCK) == S_IFSOCK &&
+			      archive_entry_filetype(entry) == AE_IFSOCK)
 #endif
 #ifdef S_IFCHR
-					|| ((st->st_mode & S_IFMT) == S_IFCHR &&
-						archive_entry_filetype(entry) == AE_IFCHR)
+			  ||((st->st_mode & S_IFMT) == S_IFCHR &&
+			      archive_entry_filetype(entry) == AE_IFCHR)
 #endif
 #ifdef S_IFBLK
-					|| ((st->st_mode & S_IFMT) == S_IFBLK &&
-						archive_entry_filetype(entry) == AE_IFBLK)
+			  ||((st->st_mode & S_IFMT) == S_IFBLK &&
+			      archive_entry_filetype(entry) == AE_IFBLK)
 #endif
-					|| ((st->st_mode & S_IFMT) == S_IFDIR &&
-						archive_entry_filetype(entry) == AE_IFDIR)
+			  ||((st->st_mode & S_IFMT) == S_IFDIR &&
+			      archive_entry_filetype(entry) == AE_IFDIR)
 #ifdef S_IFIFO
-					|| ((st->st_mode & S_IFMT) == S_IFIFO &&
-							archive_entry_filetype(entry) == AE_IFIFO)
+			  ||((st->st_mode & S_IFMT) == S_IFIFO &&
+			      archive_entry_filetype(entry) == AE_IFIFO)
 #endif
-					) {
-						/* Types match. */
-					} else {
-						/* Types don't match; bail out gracefully. */
-						if (mtree->fd >= 0)
-							close(mtree->fd);
-						mtree->fd = -1;
-						if (parsed_kws & MTREE_HAS_OPTIONAL) {
-							/* It's not an error for an optional entry
-							   to not match disk. */
-							*use_next = 1;
-						} else if (r == ARCHIVE_OK) {
-							archive_set_error(&a->archive,
-									ARCHIVE_ERRNO_MISC,
-									"mtree specification has different type for %s",
-									archive_entry_pathname(entry));
-							r = ARCHIVE_WARN;
-						}
-						return r;
-					}
+			) {
+				/* Types match. */
+			} else {
+				/* Types don't match; bail out gracefully. */
+				if (mtree->fd >= 0)
+					close(mtree->fd);
+				mtree->fd = -1;
+				if (parsed_kws & MTREE_HAS_OPTIONAL) {
+					/* It's not an error for an optional
+					 * entry to not match disk. */
+					*use_next = 1;
+				} else if (r == ARCHIVE_OK) {
+					archive_set_error(&a->archive,
+					    ARCHIVE_ERRNO_MISC,
+					    "mtree specification has different"
+					    " type for %s",
+					    archive_entry_pathname(entry));
+					r = ARCHIVE_WARN;
+				}
+				return (r);
+			}
 		}
 
 		/*
-		 * If there is a contents file on disk, pick some of the metadata
-		 * from that file.  For most of these, we only set it from the contents
-		 * if it wasn't already parsed from the specification.
+		 * If there is a contents file on disk, pick some of the
+		 * metadata from that file.  For most of these, we only
+		 * set it from the contents if it wasn't already parsed
+		 * from the specification.
 		 */
 		if (st != NULL) {
 			if (((parsed_kws & MTREE_HAS_DEVICE) == 0 ||
-						(parsed_kws & MTREE_HAS_NOCHANGE) != 0) &&
-					(archive_entry_filetype(entry) == AE_IFCHR ||
-					 archive_entry_filetype(entry) == AE_IFBLK))
+				(parsed_kws & MTREE_HAS_NOCHANGE) != 0) &&
+				(archive_entry_filetype(entry) == AE_IFCHR ||
+				 archive_entry_filetype(entry) == AE_IFBLK))
 				archive_entry_set_rdev(entry, st->st_rdev);
-			if ((parsed_kws & (MTREE_HAS_GID | MTREE_HAS_GNAME)) == 0 ||
-					(parsed_kws & MTREE_HAS_NOCHANGE) != 0)
+			if ((parsed_kws & (MTREE_HAS_GID | MTREE_HAS_GNAME))
+				== 0 ||
+			    (parsed_kws & MTREE_HAS_NOCHANGE) != 0)
 				archive_entry_set_gid(entry, st->st_gid);
-			if ((parsed_kws & (MTREE_HAS_UID | MTREE_HAS_UNAME)) == 0 ||
-					(parsed_kws & MTREE_HAS_NOCHANGE) != 0)
+			if ((parsed_kws & (MTREE_HAS_UID | MTREE_HAS_UNAME))
+				== 0 ||
+			    (parsed_kws & MTREE_HAS_NOCHANGE) != 0)
 				archive_entry_set_uid(entry, st->st_uid);
 			if ((parsed_kws & MTREE_HAS_MTIME) == 0 ||
-					(parsed_kws & MTREE_HAS_NOCHANGE) != 0) {
+			    (parsed_kws & MTREE_HAS_NOCHANGE) != 0) {
 #if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
 				archive_entry_set_mtime(entry, st->st_mtime,
 						st->st_mtimespec.tv_nsec);
@@ -1265,23 +1270,24 @@ parse_file(struct archive_read *a, struct archive_entry *entry,
 #endif
 			}
 			if ((parsed_kws & MTREE_HAS_NLINK) == 0 ||
-					(parsed_kws & MTREE_HAS_NOCHANGE) != 0)
+			    (parsed_kws & MTREE_HAS_NOCHANGE) != 0)
 				archive_entry_set_nlink(entry, st->st_nlink);
 			if ((parsed_kws & MTREE_HAS_PERM) == 0 ||
-					(parsed_kws & MTREE_HAS_NOCHANGE) != 0)
+			    (parsed_kws & MTREE_HAS_NOCHANGE) != 0)
 				archive_entry_set_perm(entry, st->st_mode);
 			if ((parsed_kws & MTREE_HAS_SIZE) == 0 ||
-					(parsed_kws & MTREE_HAS_NOCHANGE) != 0)
+			    (parsed_kws & MTREE_HAS_NOCHANGE) != 0)
 				archive_entry_set_size(entry, st->st_size);
 			archive_entry_set_ino(entry, st->st_ino);
 			archive_entry_set_dev(entry, st->st_dev);
 
-			archive_entry_linkify(mtree->resolver, &entry, &sparse_entry);
+			archive_entry_linkify(mtree->resolver, &entry,
+				&sparse_entry);
 		} else if (parsed_kws & MTREE_HAS_OPTIONAL) {
 			/*
 			 * Couldn't open the entry, stat it or the on-disk type
-			 * didn't match.  If this entry is optional, just ignore it
-			 * and read the next header entry.
+			 * didn't match.  If this entry is optional, just
+			 * ignore it and read the next header entry.
 			 */
 			*use_next = 1;
 			return ARCHIVE_OK;
@@ -1370,7 +1376,7 @@ parse_device(dev_t *pdev, struct archive *a, char *val)
 				    "Missing number");
 				return ARCHIVE_WARN;
 			}
-			numbers[argc++] = mtree_atol(&p);
+			numbers[argc++] = (unsigned long)mtree_atol(&p);
 			if (argc > MAX_PACK_ARGS) {
 				archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,
 				    "Too many arguments");
@@ -1583,32 +1589,38 @@ parse_keyword(struct archive_read *a, struct mtree *mtree,
 				}
 			case 'c':
 				if (strcmp(val, "char") == 0) {
-					archive_entry_set_filetype(entry, AE_IFCHR);
+					archive_entry_set_filetype(entry,
+						AE_IFCHR);
 					break;
 				}
 			case 'd':
 				if (strcmp(val, "dir") == 0) {
-					archive_entry_set_filetype(entry, AE_IFDIR);
+					archive_entry_set_filetype(entry,
+						AE_IFDIR);
 					break;
 				}
 			case 'f':
 				if (strcmp(val, "fifo") == 0) {
-					archive_entry_set_filetype(entry, AE_IFIFO);
+					archive_entry_set_filetype(entry,
+						AE_IFIFO);
 					break;
 				}
 				if (strcmp(val, "file") == 0) {
-					archive_entry_set_filetype(entry, AE_IFREG);
+					archive_entry_set_filetype(entry,
+						AE_IFREG);
 					break;
 				}
 			case 'l':
 				if (strcmp(val, "link") == 0) {
-					archive_entry_set_filetype(entry, AE_IFLNK);
+					archive_entry_set_filetype(entry,
+						AE_IFLNK);
 					break;
 				}
 			default:
 				archive_set_error(&a->archive,
 				    ARCHIVE_ERRNO_FILE_FORMAT,
-				    "Unrecognized file type \"%s\"; assuming \"file\"", val);
+				    "Unrecognized file type \"%s\"; "
+				    "assuming \"file\"", val);
 				archive_entry_set_filetype(entry, AE_IFREG);
 				return (ARCHIVE_WARN);
 			}
@@ -1635,7 +1647,8 @@ parse_keyword(struct archive_read *a, struct mtree *mtree,
 }
 
 static int
-read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset)
+read_data(struct archive_read *a, const void **buff, size_t *size,
+    int64_t *offset)
 {
 	size_t bytes_to_read;
 	ssize_t bytes_read;
@@ -1761,6 +1774,10 @@ parse_escapes(char *src, struct mtree_entry *mentry)
 				c = '\v';
 				++src;
 				break;
+			case '\\':
+				c = '\\';
+				++src;
+				break;
 			}
 		}
 		*dest++ = c;
@@ -1898,14 +1915,14 @@ mtree_atol(char **p)
  * point to first character of line.
  */
 static ssize_t
-readline(struct archive_read *a, struct mtree *mtree, char **start, ssize_t limit)
+readline(struct archive_read *a, struct mtree *mtree, char **start,
+    ssize_t limit)
 {
 	ssize_t bytes_read;
 	ssize_t total_size = 0;
 	ssize_t find_off = 0;
 	const void *t;
-	const char *s;
-	void *p;
+	void *nl;
 	char *u;
 
 	/* Accumulate line in a line buffer. */
@@ -1916,11 +1933,10 @@ readline(struct archive_read *a, struct mtree *mtree, char **start, ssize_t limi
 			return (0);
 		if (bytes_read < 0)
 			return (ARCHIVE_FATAL);
-		s = t;  /* Start of line? */
-		p = memchr(t, '\n', bytes_read);
-		/* If we found '\n', trim the read. */
-		if (p != NULL) {
-			bytes_read = 1 + ((const char *)p) - s;
+		nl = memchr(t, '\n', bytes_read);
+		/* If we found '\n', trim the read to end exactly there. */
+		if (nl != NULL) {
+			bytes_read = ((const char *)nl) - ((const char *)t) + 1;
 		}
 		if (total_size + bytes_read + 1 > limit) {
 			archive_set_error(&a->archive,
@@ -1934,38 +1950,34 @@ readline(struct archive_read *a, struct mtree *mtree, char **start, ssize_t limi
 			    "Can't allocate working buffer");
 			return (ARCHIVE_FATAL);
 		}
+		/* Append new bytes to string. */
 		memcpy(mtree->line.s + total_size, t, bytes_read);
 		__archive_read_consume(a, bytes_read);
 		total_size += bytes_read;
-		/* Null terminate. */
 		mtree->line.s[total_size] = '\0';
-		/* If we found an unescaped '\n', clean up and return. */
+
 		for (u = mtree->line.s + find_off; *u; ++u) {
 			if (u[0] == '\n') {
+				/* Ends with unescaped newline. */
 				*start = mtree->line.s;
 				return total_size;
-			}
-			if (u[0] == '#') {
-				if (p == NULL)
+			} else if (u[0] == '#') {
+				/* Ends with comment sequence #...\n */
+				if (nl == NULL) {
+					/* But we've not found the \n yet */
 					break;
-				*start = mtree->line.s;
-				return total_size;
-			}
-			if (u[0] != '\\')
-				continue;
-			if (u[1] == '\\') {
-				++u;
-				continue;
-			}
-			if (u[1] == '\n') {
-				memmove(u, u + 1,
-				    total_size - (u - mtree->line.s) + 1);
-				--total_size;
-				++u;
-				break;
+				}
+			} else if (u[0] == '\\') {
+				if (u[1] == '\n') {
+					/* Trim escaped newline. */
+					total_size -= 2;
+					mtree->line.s[total_size] = '\0';
+					break;
+				} else if (u[1] != '\0') {
+					/* Skip the two-char escape sequence */
+					++u;
+				}
 			}
-			if (u[1] == '\0')
-				break;
 		}
 		find_off = u - mtree->line.s;
 	}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c
index 4c56834..35ac7cf 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c
@@ -186,6 +186,7 @@ struct huffman_code
 {
   struct huffman_tree_node *tree;
   int numentries;
+  int numallocatedentries;
   int minlength;
   int maxlength;
   int tablesize;
@@ -225,6 +226,7 @@ struct rar
   mode_t mode;
   char *filename;
   char *filename_save;
+  size_t filename_save_size;
   size_t filename_allocated;
 
   /* File header optional entries */
@@ -1000,8 +1002,8 @@ archive_read_format_rar_read_data(struct archive_read *a, const void **buff,
       rar->bytes_unconsumed = 0;
   }
 
+  *buff = NULL;
   if (rar->entry_eof || rar->offset_seek >= rar->unp_size) {
-    *buff = NULL;
     *size = 0;
     *offset = rar->offset;
     if (*offset < rar->unp_size)
@@ -1201,10 +1203,8 @@ archive_read_format_rar_seek_data(struct archive_read *a, int64_t offset,
     ret -= rar->dbo[0].start_offset;
 
     /* Always restart reading the file after a seek */
-    a->read_data_block = NULL;
-    a->read_data_offset = 0;
-    a->read_data_output_offset = 0;
-    a->read_data_remaining = 0;
+    __archive_reset_read_data(&a->archive);
+
     rar->bytes_unconsumed = 0;
     rar->offset = 0;
 
@@ -1530,6 +1530,7 @@ read_header(struct archive_read *a, struct archive_entry *entry,
 
   /* Split file in multivolume RAR. No more need to process header. */
   if (rar->filename_save &&
+    filename_size == rar->filename_save_size &&
     !memcmp(rar->filename, rar->filename_save, filename_size + 1))
   {
     __archive_read_consume(a, header_size - 7);
@@ -1559,6 +1560,7 @@ read_header(struct archive_read *a, struct archive_entry *entry,
   rar->filename_save = (char*)realloc(rar->filename_save,
                                       filename_size + 1);
   memcpy(rar->filename_save, rar->filename, filename_size + 1);
+  rar->filename_save_size = filename_size;
 
   /* Set info for seeking */
   free(rar->dbo);
@@ -2406,6 +2408,8 @@ create_code(struct archive_read *a, struct huffman_code *code,
 {
   int i, j, codebits = 0, symbolsleft = numsymbols;
 
+  code->numentries = 0;
+  code->numallocatedentries = 0;
   if (new_node(code) < 0) {
     archive_set_error(&a->archive, ENOMEM,
                       "Unable to allocate memory for node data.");
@@ -2534,11 +2538,17 @@ static int
 new_node(struct huffman_code *code)
 {
   void *new_tree;
-
-  new_tree = realloc(code->tree, (code->numentries + 1) * sizeof(*code->tree));
-  if (new_tree == NULL)
-    return (-1);
-  code->tree = (struct huffman_tree_node *)new_tree;
+  if (code->numallocatedentries == code->numentries) {
+    int new_num_entries = 256;
+    if (code->numentries > 0) {
+        new_num_entries = code->numentries * 2;
+    }
+    new_tree = realloc(code->tree, new_num_entries * sizeof(*code->tree));
+    if (new_tree == NULL)
+        return (-1);
+    code->tree = (struct huffman_tree_node *)new_tree;
+    code->numallocatedentries = new_num_entries;
+  }
   code->tree[code->numentries].branches[0] = -1;
   code->tree[code->numentries].branches[1] = -2;
   return 1;
@@ -2895,8 +2905,8 @@ rar_read_ahead(struct archive_read *a, size_t min, ssize_t *avail)
   int ret;
   if (avail)
   {
-    if (a->read_data_is_posix_read && *avail > (ssize_t)a->read_data_requested)
-      *avail = a->read_data_requested;
+    if (a->archive.read_data_is_posix_read && *avail > (ssize_t)a->archive.read_data_requested)
+      *avail = a->archive.read_data_requested;
     if (*avail > rar->bytes_remaining)
       *avail = (ssize_t)rar->bytes_remaining;
     if (*avail < 0)
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c
index 734424d..01d85cf 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c
@@ -456,6 +456,7 @@ archive_read_format_tar_read_header(struct archive_read *a,
 	static int default_dev;
 	struct tar *tar;
 	const char *p;
+	const wchar_t *wp;
 	int r;
 	size_t l, unconsumed = 0;
 
@@ -506,27 +507,22 @@ archive_read_format_tar_read_header(struct archive_read *a,
 		}
 	}
 
-	if (r == ARCHIVE_OK) {
+	if (r == ARCHIVE_OK && archive_entry_filetype(entry) == AE_IFREG) {
 		/*
 		 * "Regular" entry with trailing '/' is really
 		 * directory: This is needed for certain old tar
 		 * variants and even for some broken newer ones.
 		 */
-		const wchar_t *wp;
-		wp = archive_entry_pathname_w(entry);
-		if (wp != NULL) {
+		if ((wp = archive_entry_pathname_w(entry)) != NULL) {
 			l = wcslen(wp);
-			if (archive_entry_filetype(entry) == AE_IFREG
-			    && wp[l-1] == L'/')
+			if (l > 0 && wp[l - 1] == L'/') {
 				archive_entry_set_filetype(entry, AE_IFDIR);
-		} else {
-			p = archive_entry_pathname(entry);
-			if (p == NULL)
-				return (ARCHIVE_FAILED);
+			}
+		} else if ((p = archive_entry_pathname(entry)) != NULL) {
 			l = strlen(p);
-			if (archive_entry_filetype(entry) == AE_IFREG
-			    && p[l-1] == '/')
+			if (l > 0 && p[l - 1] == '/') {
 				archive_entry_set_filetype(entry, AE_IFDIR);
+			}
 		}
 	}
 	return (r);
@@ -599,13 +595,27 @@ static int
 archive_read_format_tar_skip(struct archive_read *a)
 {
 	int64_t bytes_skipped;
+	int64_t request;
+	struct sparse_block *p;
 	struct tar* tar;
 
 	tar = (struct tar *)(a->format->data);
 
-	bytes_skipped = __archive_read_consume(a,
-	    tar->entry_bytes_remaining + tar->entry_padding +
-	    tar->entry_bytes_unconsumed);
+	/* Do not consume the hole of a sparse file. */
+	request = 0;
+	for (p = tar->sparse_list; p != NULL; p = p->next) {
+		if (!p->hole) {
+			if (p->remaining >= INT64_MAX - request) {
+				return ARCHIVE_FATAL;
+			}
+			request += p->remaining;
+		}
+	}
+	if (request > tar->entry_bytes_remaining)
+		request = tar->entry_bytes_remaining;
+	request += tar->entry_padding + tar->entry_bytes_unconsumed;
+
+	bytes_skipped = __archive_read_consume(a, request);
 	if (bytes_skipped < 0)
 		return (ARCHIVE_FATAL);
 
@@ -2117,6 +2127,10 @@ gnu_add_sparse_entry(struct archive_read *a, struct tar *tar,
 	else
 		tar->sparse_list = p;
 	tar->sparse_last = p;
+	if (remaining < 0 || offset < 0) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Malformed sparse map data");
+		return (ARCHIVE_FATAL);
+	}
 	p->offset = offset;
 	p->remaining = remaining;
 	return (ARCHIVE_OK);
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c
new file mode 100644
index 0000000..57534f3
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c
@@ -0,0 +1,794 @@
+/*-
+ * Copyright (c) 2014 Sebastian Freundt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "archive_platform.h"
+__FBSDID("$FreeBSD$");
+
+/**
+ * WARC is standardised by ISO TC46/SC4/WG12 and currently available as
+ * ISO 28500:2009.
+ * For the purposes of this file we used the final draft from:
+ * http://bibnum.bnf.fr/warc/WARC_ISO_28500_version1_latestdraft.pdf
+ *
+ * Todo:
+ * [ ] real-world warcs can contain resources at endpoints ending in /
+ *     e.g. http://bibnum.bnf.fr/warc/
+ *     if you're lucky their response contains a Content-Location: header
+ *     pointing to a unix-compliant filename, in the example above it's
+ *     Content-Location: http://bibnum.bnf.fr/warc/index.html
+ *     however, that's not mandated and github for example doesn't follow
+ *     this convention.
+ *     We need a set of archive options to control what to do with
+ *     entries like these, at the moment care is taken to skip them.
+ *
+ **/
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#ifdef HAVE_CTYPE_H
+#include <ctype.h>
+#endif
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+typedef enum {
+	WT_NONE,
+	/* warcinfo */
+	WT_INFO,
+	/* metadata */
+	WT_META,
+	/* resource */
+	WT_RSRC,
+	/* request, unsupported */
+	WT_REQ,
+	/* response, unsupported */
+	WT_RSP,
+	/* revisit, unsupported */
+	WT_RVIS,
+	/* conversion, unsupported */
+	WT_CONV,
+	/* continutation, unsupported at the moment */
+	WT_CONT,
+	/* invalid type */
+	LAST_WT
+} warc_type_t;
+
+typedef struct {
+	size_t len;
+	const char *str;
+} warc_string_t;
+
+typedef struct {
+	size_t len;
+	char *str;
+} warc_strbuf_t;
+
+struct warc_s {
+	/* content length ahead */
+	size_t cntlen;
+	/* and how much we've processed so far */
+	size_t cntoff;
+	/* and how much we need to consume between calls */
+	size_t unconsumed;
+
+	/* string pool */
+	warc_strbuf_t pool;
+	/* previous version */
+	unsigned int pver;
+	/* stringified format name */
+	struct archive_string sver;
+};
+
+static int _warc_bid(struct archive_read *a, int);
+static int _warc_cleanup(struct archive_read *a);
+static int _warc_read(struct archive_read*, const void**, size_t*, int64_t*);
+static int _warc_skip(struct archive_read *a);
+static int _warc_rdhdr(struct archive_read *a, struct archive_entry *e);
+
+/* private routines */
+static unsigned int _warc_rdver(const char buf[10], size_t bsz);
+static unsigned int _warc_rdtyp(const char *buf, size_t bsz);
+static warc_string_t _warc_rduri(const char *buf, size_t bsz);
+static ssize_t _warc_rdlen(const char *buf, size_t bsz);
+static time_t _warc_rdrtm(const char *buf, size_t bsz);
+static time_t _warc_rdmtm(const char *buf, size_t bsz);
+static const char *_warc_find_eoh(const char *buf, size_t bsz);
+
+

+int
+archive_read_support_format_warc(struct archive *_a)
+{
+	struct archive_read *a = (struct archive_read *)_a;
+	struct warc_s *w;
+	int r;
+
+	archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+	    ARCHIVE_STATE_NEW, "archive_read_support_format_warc");
+
+	if ((w = malloc(sizeof(*w))) == NULL) {
+		archive_set_error(&a->archive, ENOMEM,
+		    "Can't allocate warc data");
+		return (ARCHIVE_FATAL);
+	}
+	memset(w, 0, sizeof(*w));
+
+	r = __archive_read_register_format(
+		a, w, "warc",
+		_warc_bid, NULL, _warc_rdhdr, _warc_read,
+		_warc_skip, NULL, _warc_cleanup, NULL, NULL);
+
+	if (r != ARCHIVE_OK) {
+		free(w);
+		return (r);
+	}
+	return (ARCHIVE_OK);
+}
+
+static int
+_warc_cleanup(struct archive_read *a)
+{
+	struct warc_s *w = a->format->data;
+
+	if (w->pool.len > 0U) {
+		free(w->pool.str);
+	}
+	archive_string_free(&w->sver);
+	free(w);
+	a->format->data = NULL;
+	return (ARCHIVE_OK);
+}
+
+static int
+_warc_bid(struct archive_read *a, int best_bid)
+{
+	const char *hdr;
+	ssize_t nrd;
+	unsigned int ver;
+
+	(void)best_bid; /* UNUSED */
+
+	/* check first line of file, it should be a record already */
+	if ((hdr = __archive_read_ahead(a, 12U, &nrd)) == NULL) {
+		/* no idea what to do */
+		return -1;
+	} else if (nrd < 12) {
+		/* nah, not for us, our magic cookie is at least 12 bytes */
+		return -1;
+	}
+
+	/* otherwise snarf the record's version number */
+	ver = _warc_rdver(hdr, nrd);
+	if (ver == 0U || ver > 10000U) {
+		/* oh oh oh, best not to wager ... */
+		return -1;
+	}
+
+	/* otherwise be confident */
+	return (64);
+}
+
+static int
+_warc_rdhdr(struct archive_read *a, struct archive_entry *entry)
+{
+#define HDR_PROBE_LEN		(12U)
+	struct warc_s *w = a->format->data;
+	unsigned int ver;
+	const char *buf;
+	ssize_t nrd;
+	const char *eoh;
+	/* for the file name, saves some strndup()'ing */
+	warc_string_t fnam;
+	/* warc record type, not that we really use it a lot */
+	warc_type_t ftyp;
+	/* content-length+error monad */
+	ssize_t cntlen;
+	/* record time is the WARC-Date time we reinterpret it as ctime */
+	time_t rtime;
+	/* mtime is the Last-Modified time which will be the entry's mtime */
+	time_t mtime;
+
+start_over:
+	/* just use read_ahead() they keep track of unconsumed
+	 * bits and bobs for us; no need to put an extra shift in
+	 * and reproduce that functionality here */
+	buf = __archive_read_ahead(a, HDR_PROBE_LEN, &nrd);
+
+	if (nrd < 0) {
+		/* no good */
+		archive_set_error(
+			&a->archive, ARCHIVE_ERRNO_MISC,
+			"Bad record header");
+		return (ARCHIVE_FATAL);
+	} else if (buf == NULL) {
+		/* there should be room for at least WARC/bla\r\n
+		 * must be EOF therefore */
+		return (ARCHIVE_EOF);
+	}
+ 	/* looks good so far, try and find the end of the header now */
+	eoh = _warc_find_eoh(buf, nrd);
+	if (eoh == NULL) {
+		/* still no good, the header end might be beyond the
+		 * probe we've requested, but then again who'd cram
+		 * so much stuff into the header *and* be 28500-compliant */
+		archive_set_error(
+			&a->archive, ARCHIVE_ERRNO_MISC,
+			"Bad record header");
+		return (ARCHIVE_FATAL);
+	} else if ((ver = _warc_rdver(buf, eoh - buf)) > 10000U) {
+		/* nawww, I wish they promised backward compatibility
+		 * anyhoo, in their infinite wisdom the 28500 guys might
+		 * come up with something we can't possibly handle so
+		 * best end things here */
+		archive_set_error(
+			&a->archive, ARCHIVE_ERRNO_MISC,
+			"Unsupported record version");
+		return (ARCHIVE_FATAL);
+	} else if ((cntlen = _warc_rdlen(buf, eoh - buf)) < 0) {
+		/* nightmare!  the specs say content-length is mandatory
+		 * so I don't feel overly bad stopping the reader here */
+		archive_set_error(
+			&a->archive, EINVAL,
+			"Bad content length");
+		return (ARCHIVE_FATAL);
+	} else if ((rtime = _warc_rdrtm(buf, eoh - buf)) == (time_t)-1) {
+		/* record time is mandatory as per WARC/1.0,
+		 * so just barf here, fast and loud */
+		archive_set_error(
+			&a->archive, EINVAL,
+			"Bad record time");
+		return (ARCHIVE_FATAL);
+	}
+
+	/* let the world know we're a WARC archive */
+	a->archive.archive_format = ARCHIVE_FORMAT_WARC;
+	if (ver != w->pver) {
+		/* stringify this entry's version */
+		archive_string_sprintf(&w->sver,
+			"WARC/%u.%u", ver / 10000, ver % 10000);
+		/* remember the version */
+		w->pver = ver;
+	}
+	/* start off with the type */
+	ftyp = _warc_rdtyp(buf, eoh - buf);
+	/* and let future calls know about the content */
+	w->cntlen = cntlen;
+	w->cntoff = 0U;
+	mtime = 0;/* Avoid compiling error on some platform. */
+
+	switch (ftyp) {
+	case WT_RSRC:
+	case WT_RSP:
+		/* only try and read the filename in the cases that are
+		 * guaranteed to have one */
+		fnam = _warc_rduri(buf, eoh - buf);
+		/* check the last character in the URI to avoid creating
+		 * directory endpoints as files, see Todo above */
+		if (fnam.len == 0 || fnam.str[fnam.len - 1] == '/') {
+			/* break here for now */
+			fnam.len = 0U;
+			fnam.str = NULL;
+			break;
+		}
+		/* bang to our string pool, so we save a
+		 * malloc()+free() roundtrip */
+		if (fnam.len + 1U > w->pool.len) {
+			w->pool.len = ((fnam.len + 64U) / 64U) * 64U;
+			w->pool.str = realloc(w->pool.str, w->pool.len);
+		}
+		memcpy(w->pool.str, fnam.str, fnam.len);
+		w->pool.str[fnam.len] = '\0';
+		/* let noone else know about the pool, it's a secret, shhh */
+		fnam.str = w->pool.str;
+
+		/* snarf mtime or deduce from rtime
+		 * this is a custom header added by our writer, it's quite
+		 * hard to believe anyone else would go through with it
+		 * (apart from being part of some http responses of course) */
+		if ((mtime = _warc_rdmtm(buf, eoh - buf)) == (time_t)-1) {
+			mtime = rtime;
+		}
+		break;
+	default:
+		fnam.len = 0U;
+		fnam.str = NULL;
+		break;
+	}
+
+	/* now eat some of those delicious buffer bits */
+	__archive_read_consume(a, eoh - buf);
+
+	switch (ftyp) {
+	case WT_RSRC:
+	case WT_RSP:
+		if (fnam.len > 0U) {
+			/* populate entry object */
+			archive_entry_set_filetype(entry, AE_IFREG);
+			archive_entry_copy_pathname(entry, fnam.str);
+			archive_entry_set_size(entry, cntlen);
+			archive_entry_set_perm(entry, 0644);
+			/* rtime is the new ctime, mtime stays mtime */
+			archive_entry_set_ctime(entry, rtime, 0L);
+			archive_entry_set_mtime(entry, mtime, 0L);
+			break;
+		}
+		/* FALLTHROUGH */
+	default:
+		/* consume the content and start over */
+		_warc_skip(a);
+		goto start_over;
+	}
+	return (ARCHIVE_OK);
+}
+
+static int
+_warc_read(struct archive_read *a, const void **buf, size_t *bsz, int64_t *off)
+{
+	struct warc_s *w = a->format->data;
+	const char *rab;
+	ssize_t nrd;
+
+	if (w->cntoff >= w->cntlen) {
+	eof:
+		/* it's our lucky day, no work, we can leave early */
+		*buf = NULL;
+		*bsz = 0U;
+		*off = w->cntoff + 4U/*for \r\n\r\n separator*/;
+		w->unconsumed = 0U;
+		return (ARCHIVE_EOF);
+	}
+
+	rab = __archive_read_ahead(a, 1U, &nrd);
+	if (nrd < 0) {
+		*bsz = 0U;
+		/* big catastrophe */
+		return (int)nrd;
+	} else if (nrd == 0) {
+		goto eof;
+	} else if ((size_t)nrd > w->cntlen - w->cntoff) {
+		/* clamp to content-length */
+		nrd = w->cntlen - w->cntoff;
+	}
+	*off = w->cntoff;
+	*bsz = nrd;
+	*buf = rab;
+
+	w->cntoff += nrd;
+	w->unconsumed = (size_t)nrd;
+	return (ARCHIVE_OK);
+}
+
+static int
+_warc_skip(struct archive_read *a)
+{
+	struct warc_s *w = a->format->data;
+
+	__archive_read_consume(a, w->cntlen + 4U/*\r\n\r\n separator*/);
+	w->cntlen = 0U;
+	w->cntoff = 0U;
+	return (ARCHIVE_OK);
+}
+
+

+/* private routines */
+static void*
+deconst(const void *c)
+{
+	return (char *)0x1 + (((const char *)c) - (const char *)0x1);
+}
+
+static char*
+xmemmem(const char *hay, const size_t hz_, const char *ndl, const size_t nz)
+{
+	const char *const eoh = hay + hz_;
+	const char *const eon = ndl + nz;
+	const char *hp;
+	const char *np;
+	const char *cand;
+	unsigned int hsum;
+	unsigned int nsum;
+	unsigned int eqp;
+
+	/* trivial checks first
+         * a 0-sized needle is defined to be found anywhere in haystack
+         * then run strchr() to find a candidate in HAYSTACK (i.e. a portion
+         * that happens to begin with *NEEDLE) */
+	if (nz == 0UL) {
+		return deconst(hay);
+	} else if ((hay = memchr(hay, *ndl, hz_)) == NULL) {
+		/* trivial */
+		return NULL;
+	}
+
+	/* First characters of haystack and needle are the same now. Both are
+	 * guaranteed to be at least one character long.  Now computes the sum
+	 * of characters values of needle together with the sum of the first
+	 * needle_len characters of haystack. */
+	for (hp = hay + 1U, np = ndl + 1U, hsum = *hay, nsum = *hay, eqp = 1U;
+	     hp < eoh && np < eon;
+	     hsum ^= *hp, nsum ^= *np, eqp &= *hp == *np, hp++, np++);
+
+	/* HP now references the (NZ + 1)-th character. */
+	if (np < eon) {
+		/* haystack is smaller than needle, :O */
+		return NULL;
+	} else if (eqp) {
+		/* found a match */
+		return deconst(hay);
+	}
+
+	/* now loop through the rest of haystack,
+	 * updating the sum iteratively */
+	for (cand = hay; hp < eoh; hp++) {
+		hsum ^= *cand++;
+		hsum ^= *hp;
+
+		/* Since the sum of the characters is already known to be
+		 * equal at that point, it is enough to check just NZ - 1
+		 * characters for equality,
+		 * also CAND is by design < HP, so no need for range checks */
+		if (hsum == nsum && memcmp(cand, ndl, nz - 1U) == 0) {
+			return deconst(cand);
+		}
+	}
+	return NULL;
+}
+
+static int
+strtoi_lim(const char *str, const char **ep, int llim, int ulim)
+{
+	int res = 0;
+	const char *sp;
+	/* we keep track of the number of digits via rulim */
+	int rulim;
+
+	for (sp = str, rulim = ulim > 10 ? ulim : 10;
+	     res * 10 <= ulim && rulim && *sp >= '0' && *sp <= '9';
+	     sp++, rulim /= 10) {
+		res *= 10;
+		res += *sp - '0';
+	}
+	if (sp == str) {
+		res = -1;
+	} else if (res < llim || res > ulim) {
+		res = -2;
+	}
+	*ep = (const char*)sp;
+	return res;
+}
+
+static time_t
+time_from_tm(struct tm *t)
+{
+#if HAVE_TIMEGM
+        /* Use platform timegm() if available. */
+        return (timegm(t));
+#elif HAVE__MKGMTIME64
+        return (_mkgmtime64(t));
+#else
+        /* Else use direct calculation using POSIX assumptions. */
+        /* First, fix up tm_yday based on the year/month/day. */
+        if (mktime(t) == (time_t)-1)
+                return ((time_t)-1);
+        /* Then we can compute timegm() from first principles. */
+        return (t->tm_sec
+            + t->tm_min * 60
+            + t->tm_hour * 3600
+            + t->tm_yday * 86400
+            + (t->tm_year - 70) * 31536000
+            + ((t->tm_year - 69) / 4) * 86400
+            - ((t->tm_year - 1) / 100) * 86400
+            + ((t->tm_year + 299) / 400) * 86400);
+#endif
+}
+
+static time_t
+xstrpisotime(const char *s, char **endptr)
+{
+/** like strptime() but strictly for ISO 8601 Zulu strings */
+	struct tm tm;
+	time_t res = (time_t)-1;
+
+	/* make sure tm is clean */
+	memset(&tm, 0, sizeof(tm));
+
+	/* as a courtesy to our callers, and since this is a non-standard
+	 * routine, we skip leading whitespace */
+	for (; isspace(*s); s++);
+
+	/* read year */
+	if ((tm.tm_year = strtoi_lim(s, &s, 1583, 4095)) < 0 || *s++ != '-') {
+		goto out;
+	}
+	/* read month */
+	if ((tm.tm_mon = strtoi_lim(s, &s, 1, 12)) < 0 || *s++ != '-') {
+		goto out;
+	}
+	/* read day-of-month */
+	if ((tm.tm_mday = strtoi_lim(s, &s, 1, 31)) < 0 || *s++ != 'T') {
+		goto out;
+	}
+	/* read hour */
+	if ((tm.tm_hour = strtoi_lim(s, &s, 0, 23)) < 0 || *s++ != ':') {
+		goto out;
+	}
+	/* read minute */
+	if ((tm.tm_min = strtoi_lim(s, &s, 0, 59)) < 0 || *s++ != ':') {
+		goto out;
+	}
+	/* read second */
+	if ((tm.tm_sec = strtoi_lim(s, &s, 0, 60)) < 0 || *s++ != 'Z') {
+		goto out;
+	}
+
+	/* massage TM to fulfill some of POSIX' contraints */
+	tm.tm_year -= 1900;
+	tm.tm_mon--;
+
+	/* now convert our custom tm struct to a unix stamp using UTC */
+	res = time_from_tm(&tm);
+
+out:
+	if (endptr != NULL) {
+		*endptr = deconst(s);
+	}
+	return res;
+}
+
+static unsigned int
+_warc_rdver(const char buf[10], size_t bsz)
+{
+	static const char magic[] = "WARC/";
+	unsigned int ver;
+
+	(void)bsz; /* UNUSED */
+
+	if (memcmp(buf, magic, sizeof(magic) - 1U) != 0) {
+		/* nope */
+		return 99999U;
+	}
+	/* looks good so far, read the version number for a laugh */
+	buf += sizeof(magic) - 1U;
+	/* most common case gets a quick-check here */
+	if (memcmp(buf, "1.0\r\n", 5U) == 0) {
+		ver = 10000U;
+	} else {
+		switch (*buf) {
+		case '0':
+		case '1':
+		case '2':
+		case '3':
+		case '4':
+		case '5':
+		case '6':
+		case '7':
+		case '8':
+			if (buf[1U] == '.') {
+				char *on;
+
+				/* set up major version */
+				ver = (buf[0U] - '0') * 10000U;
+				/* minor version, anyone? */
+				ver += (strtol(buf + 2U, &on, 10)) * 100U;
+				/* don't parse anything else */
+				if (on > buf + 2U) {
+					break;
+				}
+			}
+			/* FALLTHROUGH */
+		case '9':
+		default:
+			/* just make the version ridiculously high */
+			ver = 999999U;
+			break;
+		}
+	}
+	return ver;
+}
+
+static unsigned int
+_warc_rdtyp(const char *buf, size_t bsz)
+{
+	static const char _key[] = "\r\nWARC-Type:";
+	const char *const eob = buf + bsz;
+	const char *val;
+
+	if ((val = xmemmem(buf, bsz, _key, sizeof(_key) - 1U)) == NULL) {
+		/* no bother */
+		return WT_NONE;
+	}
+	/* overread whitespace */
+	for (val += sizeof(_key) - 1U; val < eob && isspace(*val); val++);
+
+	if (val + 8U > eob) {
+		;
+	} else if (memcmp(val, "resource", 8U) == 0) {
+		return WT_RSRC;
+	} else if (memcmp(val, "warcinfo", 8U) == 0) {
+		return WT_INFO;
+	} else if (memcmp(val, "metadata", 8U) == 0) {
+		return WT_META;
+	} else if (memcmp(val, "request", 7U) == 0) {
+		return WT_REQ;
+	} else if (memcmp(val, "response", 8U) == 0) {
+		return WT_RSP;
+	} else if (memcmp(val, "conversi", 8U) == 0) {
+		return WT_CONV;
+	} else if (memcmp(val, "continua", 8U) == 0) {
+		return WT_CONT;
+	}
+	return WT_NONE;
+}
+
+static warc_string_t
+_warc_rduri(const char *buf, size_t bsz)
+{
+	static const char _key[] = "\r\nWARC-Target-URI:";
+	const char *const eob = buf + bsz;
+	const char *val;
+	const char *uri;
+	const char *eol;
+	warc_string_t res = {0U, NULL};
+
+	if ((val = xmemmem(buf, bsz, _key, sizeof(_key) - 1U)) == NULL) {
+		/* no bother */
+		return res;
+	}
+	/* overread whitespace */
+	for (val += sizeof(_key) - 1U; val < eob && isspace(*val); val++);
+
+	/* overread URL designators */
+	if ((uri = xmemmem(val, eob - val, "://", 3U)) == NULL) {
+		/* not touching that! */
+		return res;
+	} else if ((eol = memchr(uri, '\n', eob - uri)) == NULL) {
+		/* no end of line? :O */
+		return res;
+	}
+
+	/* massage uri to point to after :// */
+	uri += 3U;
+	/* also massage eol to point to the first whitespace
+	 * after the last non-whitespace character before
+	 * the end of the line */
+	for (; eol > uri && isspace(eol[-1]); eol--);
+
+	/* now then, inspect the URI */
+	if (memcmp(val, "file", 4U) == 0) {
+		/* perfect, nothing left to do here */
+
+	} else if (memcmp(val, "http", 4U) == 0 ||
+		   memcmp(val, "ftp", 3U) == 0) {
+		/* overread domain, and the first / */
+		while (uri < eol && *uri++ != '/');
+	} else {
+		/* not sure what to do? best to bugger off */
+		return res;
+	}
+	res.str = uri;
+	res.len = eol - uri;
+	return res;
+}
+
+static ssize_t
+_warc_rdlen(const char *buf, size_t bsz)
+{
+	static const char _key[] = "\r\nContent-Length:";
+	const char *val;
+	char *on = NULL;
+	long int len;
+
+	if ((val = xmemmem(buf, bsz, _key, sizeof(_key) - 1U)) == NULL) {
+		/* no bother */
+		return -1;
+	}
+
+	/* strtol kindly overreads whitespace for us, so use that */
+	val += sizeof(_key) - 1U;
+	len = strtol(val, &on, 10);
+	if (on == NULL || !isspace(*on)) {
+		/* hm, can we trust that number?  Best not. */
+		return -1;
+	}
+	return (size_t)len;
+}
+
+static time_t
+_warc_rdrtm(const char *buf, size_t bsz)
+{
+	static const char _key[] = "\r\nWARC-Date:";
+	const char *val;
+	char *on = NULL;
+	time_t res;
+
+	if ((val = xmemmem(buf, bsz, _key, sizeof(_key) - 1U)) == NULL) {
+		/* no bother */
+		return (time_t)-1;
+	}
+
+	/* xstrpisotime() kindly overreads whitespace for us, so use that */
+	val += sizeof(_key) - 1U;
+	res = xstrpisotime(val, &on);
+	if (on == NULL || !isspace(*on)) {
+		/* hm, can we trust that number?  Best not. */
+		return (time_t)-1;
+	}
+	return res;
+}
+
+static time_t
+_warc_rdmtm(const char *buf, size_t bsz)
+{
+	static const char _key[] = "\r\nLast-Modified:";
+	const char *val;
+	char *on = NULL;
+	time_t res;
+
+	if ((val = xmemmem(buf, bsz, _key, sizeof(_key) - 1U)) == NULL) {
+		/* no bother */
+		return (time_t)-1;
+	}
+
+	/* xstrpisotime() kindly overreads whitespace for us, so use that */
+	val += sizeof(_key) - 1U;
+	res = xstrpisotime(val, &on);
+	if (on == NULL || !isspace(*on)) {
+		/* hm, can we trust that number?  Best not. */
+		return (time_t)-1;
+	}
+	return res;
+}
+
+static const char*
+_warc_find_eoh(const char *buf, size_t bsz)
+{
+	static const char _marker[] = "\r\n\r\n";
+	const char *hit = xmemmem(buf, bsz, _marker, sizeof(_marker) - 1U);
+
+	if (hit != NULL) {
+		hit += sizeof(_marker) - 1U;
+	}
+	return hit;
+}
+
+/* archive_read_support_format_warc.c ends here */
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c
index 68485d1..bbef99f 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c
@@ -51,7 +51,7 @@ __FBSDID("$FreeBSD$");
 #endif
 
 #include "archive.h"
-#include "archive_crypto_private.h"
+#include "archive_digest_private.h"
 #include "archive_endian.h"
 #include "archive_entry.h"
 #include "archive_entry_locale.h"
@@ -1107,20 +1107,23 @@ static time_t
 time_from_tm(struct tm *t)
 {
 #if HAVE_TIMEGM
-	/* Use platform timegm() if available. */
-	return (timegm(t));
+        /* Use platform timegm() if available. */
+        return (timegm(t));
 #elif HAVE__MKGMTIME64
-	return (_mkgmtime64(t));
+        return (_mkgmtime64(t));
 #else
-	/* Else use direct calculation using POSIX assumptions. */
-	/* First, fix up tm_yday based on the year/month/day. */
-	mktime(t);
-	/* Then we can compute timegm() from first principles. */
-	return (t->tm_sec + t->tm_min * 60 + t->tm_hour * 3600
-	    + t->tm_yday * 86400 + (t->tm_year - 70) * 31536000
-	    + ((t->tm_year - 69) / 4) * 86400 -
-	    ((t->tm_year - 1) / 100) * 86400
-	    + ((t->tm_year + 299) / 400) * 86400);
+        /* Else use direct calculation using POSIX assumptions. */
+        /* First, fix up tm_yday based on the year/month/day. */
+        mktime(t);
+        /* Then we can compute timegm() from first principles. */
+        return (t->tm_sec
+            + t->tm_min * 60
+            + t->tm_hour * 3600
+            + t->tm_yday * 86400
+            + (t->tm_year - 70) * 31536000
+            + ((t->tm_year - 69) / 4) * 86400
+            - ((t->tm_year - 1) / 100) * 86400
+            + ((t->tm_year + 299) / 400) * 86400);
 #endif
 }
 
@@ -3189,9 +3192,8 @@ xml2_read_toc(struct archive_read *a)
 		case XML_READER_TYPE_ELEMENT:
 			empty = xmlTextReaderIsEmptyElement(reader);
 			r = xml2_xmlattr_setup(a, &list, reader);
-			if (r != ARCHIVE_OK)
-				return (r);
-			r = xml_start(a, name, &list);
+			if (r == ARCHIVE_OK)
+				r = xml_start(a, name, &list);
 			xmlattr_cleanup(&list);
 			if (r != ARCHIVE_OK)
 				return (r);
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c
index 5ef2952..62bf5e3 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c
@@ -1,6 +1,6 @@
 /*-
  * Copyright (c) 2004-2013 Tim Kientzle
- * Copyright (c) 2011-2012 Michihiro NAKAJIMA
+ * Copyright (c) 2011-2012,2014 Michihiro NAKAJIMA
  * Copyright (c) 2013 Konrad Kleine
  * All rights reserved.
  *
@@ -53,9 +53,12 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_zip.c 201102
 #endif
 
 #include "archive.h"
+#include "archive_digest_private.h"
+#include "archive_cryptor_private.h"
 #include "archive_endian.h"
 #include "archive_entry.h"
 #include "archive_entry_locale.h"
+#include "archive_hmac_private.h"
 #include "archive_private.h"
 #include "archive_rb.h"
 #include "archive_read_private.h"
@@ -64,10 +67,6 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_zip.c 201102
 #include "archive_crc32.h"
 #endif
 
-#if defined(_WIN32) && !defined(__CYGWIN__)
-# define snprintf _snprintf
-#endif
-
 struct zip_entry {
 	struct archive_rb_node	node;
 	struct zip_entry	*next;
@@ -86,6 +85,25 @@ struct zip_entry {
 	unsigned char		compression;
 	unsigned char		system; /* From "version written by" */
 	unsigned char		flags; /* Our extra markers. */
+	unsigned char		decdat;/* Used for Decryption check */
+
+	/* WinZip AES encryption extra field should be available
+	 * when compression is 99. */
+	struct {
+		/* Vendor version: AE-1 - 0x0001, AE-2 - 0x0002 */
+		unsigned	vendor;
+#define AES_VENDOR_AE_1	0x0001
+#define AES_VENDOR_AE_2	0x0002
+		/* AES encryption strength:
+		 * 1 - 128 bits, 2 - 192 bits, 2 - 256 bits. */
+		unsigned	strength;
+		/* Actual compression method. */
+		unsigned char	compression;
+	}			aes_extra;
+};
+
+struct trad_enc_ctx {
+	uint32_t	keys[3];
 };
 
 /* Bits used in zip_flags. */
@@ -101,9 +119,20 @@ struct zip_entry {
 #define LA_USED_ZIP64	(1 << 0)
 #define LA_FROM_CENTRAL_DIRECTORY (1 << 1)
 
+/*
+ * See "WinZip - AES Encryption Information"
+ *     http://www.winzip.com/aes_info.htm
+ */
+/* Value used in compression method. */
+#define WINZIP_AES_ENCRYPTION	99
+/* Authentication code size. */
+#define AUTH_CODE_SIZE	10
+/**/
+#define MAX_DERIVED_KEY_BUF_SIZE	(AES_MAX_KEY_SIZE * 2 + 2)
+
 struct zip {
 	/* Structural information about the archive. */
-	char			format_name[64];
+	struct archive_string	format_name;
 	int64_t			central_directory_offset;
 	size_t			central_directory_entries_total;
 	size_t			central_directory_entries_on_this_disk;
@@ -127,7 +156,8 @@ struct zip {
 
 	/* Running CRC32 of the decompressed data */
 	unsigned long		entry_crc32;
-	unsigned long		(*crc32func)(unsigned long, const void *, size_t);
+	unsigned long		(*crc32func)(unsigned long, const void *,
+				    size_t);
 	char			ignore_crc32;
 
 	/* Flags to mark progress of decompression. */
@@ -146,6 +176,38 @@ struct zip {
 	struct archive_string_conv *sconv_utf8;
 	int			init_default_conversion;
 	int			process_mac_extensions;
+
+	char			init_decryption;
+
+	/* Decryption buffer. */
+	unsigned char 		*decrypted_buffer;
+	unsigned char 		*decrypted_ptr;
+	size_t 			decrypted_buffer_size;
+	size_t 			decrypted_bytes_remaining;
+	size_t 			decrypted_unconsumed_bytes;
+
+	/* Traditional PKWARE decryption. */
+	struct trad_enc_ctx	tctx;
+	char			tctx_valid;
+
+	/* WinZip AES decyption. */
+	/* Contexts used for AES decryption. */
+	archive_crypto_ctx	cctx;
+	char			cctx_valid;
+	archive_hmac_sha1_ctx	hctx;
+	char			hctx_valid;
+
+	/* Strong encryption's decryption header information. */
+	unsigned		iv_size;
+	unsigned		alg_id;
+	unsigned		bit_len;
+	unsigned		flags;
+	unsigned		erd_size;
+	unsigned		v_size;
+	unsigned		v_crc32;
+	uint8_t			*iv;
+	uint8_t			*erd;
+	uint8_t			*v_data;
 };
 
 /* Many systems define min or MIN, but not all. */
@@ -154,6 +216,106 @@ struct zip {
 /* ------------------------------------------------------------------------ */
 
 /*
+  Traditional PKWARE Decryption functions.
+ */
+
+static void
+trad_enc_update_keys(struct trad_enc_ctx *ctx, uint8_t c)
+{
+	uint8_t t;
+#define CRC32(c, b) (crc32(c ^ 0xffffffffUL, &b, 1) ^ 0xffffffffUL)
+
+	ctx->keys[0] = CRC32(ctx->keys[0], c);
+	ctx->keys[1] = (ctx->keys[1] + (ctx->keys[0] & 0xff)) * 134775813L + 1;
+	t = (ctx->keys[1] >> 24) & 0xff;
+	ctx->keys[2] = CRC32(ctx->keys[2], t);
+#undef CRC32
+}
+
+static uint8_t
+trad_enc_decypt_byte(struct trad_enc_ctx *ctx)
+{
+	unsigned temp = ctx->keys[2] | 2;
+	return (uint8_t)((temp * (temp ^ 1)) >> 8) & 0xff;
+}
+
+static void
+trad_enc_decrypt_update(struct trad_enc_ctx *ctx, const uint8_t *in,
+    size_t in_len, uint8_t *out, size_t out_len)
+{
+	unsigned i, max;
+
+	max = (unsigned)((in_len < out_len)? in_len: out_len);
+
+	for (i = 0; i < max; i++) {
+		uint8_t t = in[i] ^ trad_enc_decypt_byte(ctx);
+		out[i] = t;
+		trad_enc_update_keys(ctx, t);
+	}
+}
+
+static int
+trad_enc_init(struct trad_enc_ctx *ctx, const char *pw, size_t pw_len,
+    const uint8_t *key, size_t key_len, uint8_t *crcchk)
+{
+	uint8_t header[12];
+
+	if (key_len < 12) {
+		*crcchk = 0xff;
+		return -1;
+	}
+
+	ctx->keys[0] = 305419896L;
+	ctx->keys[1] = 591751049L;
+	ctx->keys[2] = 878082192L;
+
+	for (;pw_len; --pw_len)
+		trad_enc_update_keys(ctx, *pw++);
+
+	trad_enc_decrypt_update(ctx, key, 12, header, 12);
+	/* Return the last byte for CRC check. */
+	*crcchk = header[11];
+	return 0;
+}
+
+#if 0
+static void
+crypt_derive_key_sha1(const void *p, int size, unsigned char *key,
+    int key_size)
+{
+#define MD_SIZE 20
+	archive_sha1_ctx ctx;
+	unsigned char md1[MD_SIZE];
+	unsigned char md2[MD_SIZE * 2];
+	unsigned char mkb[64];
+	int i;
+
+	archive_sha1_init(&ctx);
+	archive_sha1_update(&ctx, p, size);
+	archive_sha1_final(&ctx, md1);
+
+	memset(mkb, 0x36, sizeof(mkb));
+	for (i = 0; i < MD_SIZE; i++)
+		mkb[i] ^= md1[i];
+	archive_sha1_init(&ctx);
+	archive_sha1_update(&ctx, mkb, sizeof(mkb));
+	archive_sha1_final(&ctx, md2);
+
+	memset(mkb, 0x5C, sizeof(mkb));
+	for (i = 0; i < MD_SIZE; i++)
+		mkb[i] ^= md1[i];
+	archive_sha1_init(&ctx);
+	archive_sha1_update(&ctx, mkb, sizeof(mkb));
+	archive_sha1_final(&ctx, md2 + MD_SIZE);
+
+	if (key_size > 32)
+		key_size = 32;
+	memcpy(key, md2, key_size);
+#undef MD_SIZE
+}
+#endif
+
+/*
  * Common code for streaming or seeking modes.
  *
  * Includes code to read local file headers, decompress data
@@ -163,9 +325,10 @@ struct zip {
 static unsigned long
 real_crc32(unsigned long crc, const void *buff, size_t len)
 {
-	return crc32(crc, buff, len);
+	return crc32(crc, buff, (unsigned int)len);
 }
 
+/* Used by "ignorecrc32" option to speed up tests. */
 static unsigned long
 fake_crc32(unsigned long crc, const void *buff, size_t len)
 {
@@ -185,33 +348,36 @@ static struct {
 	{3, "reduced-2"}, /* The file is Reduced with compression factor 2 */
 	{4, "reduced-3"}, /* The file is Reduced with compression factor 3 */
 	{5, "reduced-4"}, /* The file is Reduced with compression factor 4 */
-	{6, "imploded"}, /* The file is Imploded */
-	{7, "reserved"}, /* Reserved for Tokenizing compression algorithm */
+	{6, "imploded"},  /* The file is Imploded */
+	{7, "reserved"},  /* Reserved for Tokenizing compression algorithm */
 	{8, "deflation"}, /* The file is Deflated */
 	{9, "deflation-64-bit"}, /* Enhanced Deflating using Deflate64(tm) */
-	{10, "ibm-terse"}, /* PKWARE Data Compression Library Imploding (old IBM TERSE) */
+	{10, "ibm-terse"},/* PKWARE Data Compression Library Imploding
+			   * (old IBM TERSE) */
 	{11, "reserved"}, /* Reserved by PKWARE */
-	{12, "bzip"}, /* File is compressed using BZIP2 algorithm */
+	{12, "bzip"},     /* File is compressed using BZIP2 algorithm */
 	{13, "reserved"}, /* Reserved by PKWARE */
-	{14, "lzma"}, /* LZMA (EFS) */
+	{14, "lzma"},     /* LZMA (EFS) */
 	{15, "reserved"}, /* Reserved by PKWARE */
 	{16, "reserved"}, /* Reserved by PKWARE */
 	{17, "reserved"}, /* Reserved by PKWARE */
 	{18, "ibm-terse-new"}, /* File is compressed using IBM TERSE (new) */
-	{19, "ibm-lz777"}, /* IBM LZ77 z Architecture (PFS) */
+	{19, "ibm-lz777"},/* IBM LZ77 z Architecture (PFS) */
 	{97, "wav-pack"}, /* WavPack compressed data */
-	{98, "ppmd-1"} /* PPMd version I, Rev 1 */
+	{98, "ppmd-1"},   /* PPMd version I, Rev 1 */
+	{99, "aes"}       /* WinZip AES encryption  */
 };
 
 static const char *
 compression_name(const int compression)
 {
-	static const int num_compression_methods = sizeof(compression_methods)/sizeof(compression_methods[0]);
+	static const int num_compression_methods =
+		sizeof(compression_methods)/sizeof(compression_methods[0]);
 	int i=0;
+
 	while(compression >= 0 && i < num_compression_methods) {
-		if (compression_methods[i].id == compression) {
+		if (compression_methods[i].id == compression)
 			return compression_methods[i].name;
-		}
 		i++;
 	}
 	return "??";
@@ -248,15 +414,15 @@ process_extra(const char *p, size_t extra_length, struct zip_entry* zip_entry)
 {
 	unsigned offset = 0;
 
-	while (offset < extra_length - 4)
-	{
+	while (offset < extra_length - 4) {
 		unsigned short headerid = archive_le16dec(p + offset);
 		unsigned short datasize = archive_le16dec(p + offset + 2);
+
 		offset += 4;
 		if (offset + datasize > extra_length)
 			break;
 #ifdef DEBUG
-		fprintf(stderr, "Header id 0x%x, length %d\n",
+		fprintf(stderr, "Header id 0x%04x, length %d\n",
 		    headerid, datasize);
 #endif
 		switch (headerid) {
@@ -291,6 +457,23 @@ process_extra(const char *p, size_t extra_length, struct zip_entry* zip_entry)
 			 * on which file starts, but we don't handle
 			 * multi-volume Zip files. */
 			break;
+#ifdef DEBUG
+		case 0x0017:
+		{
+			/* Strong encryption field. */
+			if (archive_le16dec(p + offset) == 2) {
+				unsigned algId =
+					archive_le16dec(p + offset + 2);
+				unsigned bitLen =
+					archive_le16dec(p + offset + 4);
+				int	 flags =
+					archive_le16dec(p + offset + 6);
+				fprintf(stderr, "algId=0x%04x, bitLen=%u, "
+				    "flgas=%d\n", algId, bitLen,flags);
+			}
+			break;
+		}
+#endif
 		case 0x5455:
 		{
 			/* Extended time field "UT". */
@@ -345,16 +528,34 @@ process_extra(const char *p, size_t extra_length, struct zip_entry* zip_entry)
 			}
 			break;
 		}
-		case 0x6c65:
+		case 0x6c78:
 		{
-			/* Experimental 'el' field */
+			/* Experimental 'xl' field */
 			/*
 			 * Introduced Dec 2013 to provide a way to
-			 * include external file attributes in local file
-			 * header.  This provides file type and permission
-			 * information necessary to support full streaming
-			 * extraction.  Currently being discussed with
-			 * other Zip developers... subject to change.
+			 * include external file attributes (and other
+			 * fields that ordinarily appear only in
+			 * central directory) in local file header.
+			 * This provides file type and permission
+			 * information necessary to support full
+			 * streaming extraction.  Currently being
+			 * discussed with other Zip developers
+			 * ... subject to change.
+			 *
+			 * Format:
+			 *  The field starts with a bitmap that specifies
+			 *  which additional fields are included.  The
+			 *  bitmap is variable length and can be extended in
+			 *  the future.
+			 *
+			 *  n bytes - feature bitmap: first byte has low-order
+			 *    7 bits.  If high-order bit is set, a subsequent
+			 *    byte holds the next 7 bits, etc.
+			 *
+			 *  if bitmap & 1, 2 byte "version made by"
+			 *  if bitmap & 2, 2 byte "internal file attributes"
+			 *  if bitmap & 4, 4 byte "external file attributes"
+			 *  if bitmap * 7, 2 byte comment length + n byte comment
 			 */
 			int bitmap, bitmap_last;
 
@@ -373,7 +574,7 @@ process_extra(const char *p, size_t extra_length, struct zip_entry* zip_entry)
 			}
 
 			if (bitmap & 1) {
-				// 2 byte "version made by"
+				/* 2 byte "version made by" */
 				if (datasize < 2)
 					break;
 				zip_entry->system
@@ -382,19 +583,19 @@ process_extra(const char *p, size_t extra_length, struct zip_entry* zip_entry)
 				datasize -= 2;
 			}
 			if (bitmap & 2) {
-				// 2 byte "internal file attributes"
+				/* 2 byte "internal file attributes" */
 				uint32_t internal_attributes;
 				if (datasize < 2)
 					break;
 				internal_attributes
 				    = archive_le16dec(p + offset);
-				// Not used by libarchive at present.
+				/* Not used by libarchive at present. */
 				(void)internal_attributes; /* UNUSED */
 				offset += 2;
 				datasize -= 2;
 			}
 			if (bitmap & 4) {
-				// 4 byte "external file attributes"
+				/* 4 byte "external file attributes" */
 				uint32_t external_attributes;
 				if (datasize < 4)
 					break;
@@ -408,7 +609,7 @@ process_extra(const char *p, size_t extra_length, struct zip_entry* zip_entry)
 				datasize -= 4;
 			}
 			if (bitmap & 8) {
-				// 2 byte comment length + comment
+				/* 2 byte comment length + comment */
 				uint32_t comment_length;
 				if (datasize < 2)
 					break;
@@ -419,7 +620,7 @@ process_extra(const char *p, size_t extra_length, struct zip_entry* zip_entry)
 
 				if (datasize < comment_length)
 					break;
-				// Comment is not supported by libarchive
+				/* Comment is not supported by libarchive */
 				offset += comment_length;
 				datasize -= comment_length;
 			}
@@ -447,7 +648,7 @@ process_extra(const char *p, size_t extra_length, struct zip_entry* zip_entry)
 			if (datasize >= 1 && p[offset] == 1) {/* version=1 */
 				if (datasize >= 4) {
 					/* get a uid size. */
-					uidsize = p[offset+1];
+					uidsize = 0xff & (int)p[offset+1];
 					if (uidsize == 2)
 						zip_entry->uid =
 						    archive_le16dec(
@@ -459,7 +660,7 @@ process_extra(const char *p, size_t extra_length, struct zip_entry* zip_entry)
 				}
 				if (datasize >= (2 + uidsize + 3)) {
 					/* get a gid size. */
-					gidsize = p[offset+2+uidsize];
+					gidsize = 0xff & (int)p[offset+2+uidsize];
 					if (gidsize == 2)
 						zip_entry->gid =
 						    archive_le16dec(
@@ -473,6 +674,19 @@ process_extra(const char *p, size_t extra_length, struct zip_entry* zip_entry)
 			}
 			break;
 		}
+		case 0x9901:
+			/* WinZIp AES extra data field. */
+			if (p[offset + 2] == 'A' && p[offset + 3] == 'E') {
+				/* Vendor version. */
+				zip_entry->aes_extra.vendor =
+				    archive_le16dec(p + offset);
+				/* AES encryption strength. */
+				zip_entry->aes_extra.strength = p[offset + 4];
+				/* Actual compression method. */
+				zip_entry->aes_extra.compression =
+				    p[offset + 5];
+			}
+			break;
 		default:
 			break;
 		}
@@ -544,9 +758,14 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry,
 			return ARCHIVE_FATAL;
 		}
 	}
+	zip->init_decryption = (zip_entry->zip_flags & ZIP_ENCRYPTED);
 	zip_entry->compression = (char)archive_le16dec(p + 8);
 	zip_entry->mtime = zip_time(p + 10);
 	zip_entry->crc32 = archive_le32dec(p + 14);
+	if (zip_entry->zip_flags & ZIP_LENGTH_AT_END)
+		zip_entry->decdat = p[11];
+	else
+		zip_entry->decdat = p[17];
 	zip_entry->compressed_size = archive_le32dec(p + 18);
 	zip_entry->uncompressed_size = archive_le32dec(p + 22);
 	filename_length = archive_le16dec(p + 26);
@@ -687,7 +906,15 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry,
 	archive_entry_set_atime(entry, zip_entry->atime, 0);
 
 	if ((zip->entry->mode & AE_IFMT) == AE_IFLNK) {
-		size_t linkname_length = zip_entry->compressed_size;
+		size_t linkname_length;
+
+		if (zip_entry->compressed_size > 64 * 1024) {
+			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+			    "Zip file with oversized link entry");
+			return ARCHIVE_FATAL;
+		}
+
+		linkname_length = (size_t)zip_entry->compressed_size;
 
 		archive_entry_set_size(entry, 0);
 		p = __archive_read_ahead(a, linkname_length, NULL);
@@ -696,11 +923,6 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry,
 			    "Truncated Zip file");
 			return ARCHIVE_FATAL;
 		}
-		if (__archive_read_consume(a, linkname_length) < 0) {
-			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
-			    "Read error skipping symlink target name");
-			return ARCHIVE_FATAL;
-		}
 
 		sconv = zip->sconv;
 		if (sconv == NULL && (zip->entry->zip_flags & ZIP_UTF8_NAME))
@@ -735,6 +957,12 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry,
 			}
 		}
 		zip_entry->uncompressed_size = zip_entry->compressed_size = 0;
+
+		if (__archive_read_consume(a, linkname_length) < 0) {
+			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+			    "Read error skipping symlink target name");
+			return ARCHIVE_FATAL;
+		}
 	} else if (0 == (zip_entry->zip_flags & ZIP_LENGTH_AT_END)
 	    || zip_entry->uncompressed_size > 0) {
 		/* Set the size only if it's meaningful. */
@@ -748,14 +976,51 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry,
 		zip->end_of_entry = 1;
 
 	/* Set up a more descriptive format name. */
-	snprintf(zip->format_name, sizeof(zip->format_name), "ZIP %d.%d (%s)",
+	archive_string_sprintf(&zip->format_name, "ZIP %d.%d (%s)",
 	    version / 10, version % 10,
 	    compression_name(zip->entry->compression));
-	a->archive.archive_format_name = zip->format_name;
+	a->archive.archive_format_name = zip->format_name.s;
 
 	return (ret);
 }
 
+static int
+check_authentication_code(struct archive_read *a, const void *_p)
+{
+	struct zip *zip = (struct zip *)(a->format->data);
+
+	/* Check authentication code. */
+	if (zip->hctx_valid) {
+		const void *p;
+		uint8_t hmac[20];
+		size_t hmac_len = 20;
+		int cmp;
+
+		archive_hmac_sha1_final(&zip->hctx, hmac, &hmac_len);
+		if (_p == NULL) {
+			/* Read authentication code. */
+			p = __archive_read_ahead(a, AUTH_CODE_SIZE, NULL);
+			if (p == NULL) {
+				archive_set_error(&a->archive,
+				    ARCHIVE_ERRNO_FILE_FORMAT,
+				    "Truncated ZIP file data");
+				return (ARCHIVE_FATAL);
+			}
+		} else {
+			p = _p;
+		}
+		cmp = memcmp(hmac, p, AUTH_CODE_SIZE);
+		__archive_read_consume(a, AUTH_CODE_SIZE);
+		if (cmp != 0) {
+			archive_set_error(&a->archive,
+			    ARCHIVE_ERRNO_MISC,
+			    "ZIP bad Authentication code");
+			return (ARCHIVE_WARN);
+		}
+	}
+	return (ARCHIVE_OK);
+}
+
 /*
  * Read "uncompressed" data.  There are three cases:
  *  1) We know the size of the data.  This is always true for the
@@ -787,6 +1052,7 @@ zip_read_data_none(struct archive_read *a, const void **_buff,
 	struct zip *zip;
 	const char *buff;
 	ssize_t bytes_avail;
+	int r;
 
 	(void)offset; /* UNUSED */
 
@@ -794,10 +1060,13 @@ zip_read_data_none(struct archive_read *a, const void **_buff,
 
 	if (zip->entry->zip_flags & ZIP_LENGTH_AT_END) {
 		const char *p;
+		ssize_t grabbing_bytes = 24;
 
+		if (zip->hctx_valid)
+			grabbing_bytes += AUTH_CODE_SIZE;
 		/* Grab at least 24 bytes. */
-		buff = __archive_read_ahead(a, 24, &bytes_avail);
-		if (bytes_avail < 24) {
+		buff = __archive_read_ahead(a, grabbing_bytes, &bytes_avail);
+		if (bytes_avail < grabbing_bytes) {
 			/* Zip archives have end-of-archive markers
 			   that are longer than this, so a failure to get at
 			   least 24 bytes really does indicate a truncated
@@ -810,21 +1079,34 @@ zip_read_data_none(struct archive_read *a, const void **_buff,
 		/* Check for a complete PK\007\010 signature, followed
 		 * by the correct 4-byte CRC. */
 		p = buff;
+		if (zip->hctx_valid)
+			p += AUTH_CODE_SIZE;
 		if (p[0] == 'P' && p[1] == 'K'
 		    && p[2] == '\007' && p[3] == '\010'
 		    && (archive_le32dec(p + 4) == zip->entry_crc32
-			|| zip->ignore_crc32)) {
+			|| zip->ignore_crc32
+			|| (zip->hctx_valid
+			 && zip->entry->aes_extra.vendor == AES_VENDOR_AE_2))) {
 			if (zip->entry->flags & LA_USED_ZIP64) {
 				zip->entry->crc32 = archive_le32dec(p + 4);
-				zip->entry->compressed_size = archive_le64dec(p + 8);
-				zip->entry->uncompressed_size = archive_le64dec(p + 16);
+				zip->entry->compressed_size =
+					archive_le64dec(p + 8);
+				zip->entry->uncompressed_size =
+					archive_le64dec(p + 16);
 				zip->unconsumed = 24;
 			} else {
 				zip->entry->crc32 = archive_le32dec(p + 4);
-				zip->entry->compressed_size = archive_le32dec(p + 8);
-				zip->entry->uncompressed_size = archive_le32dec(p + 12);
+				zip->entry->compressed_size =
+					archive_le32dec(p + 8);
+				zip->entry->uncompressed_size =
+					archive_le32dec(p + 12);
 				zip->unconsumed = 16;
 			}
+			if (zip->hctx_valid) {
+				r = check_authentication_code(a, buff);
+				if (r != ARCHIVE_OK)
+					return (r);
+			}
 			zip->end_of_entry = 1;
 			return (ARCHIVE_OK);
 		}
@@ -841,6 +1123,8 @@ zip_read_data_none(struct archive_read *a, const void **_buff,
 			else if (p[3] == '\007') { p += 1; }
 			else if (p[3] == '\010' && p[2] == '\007'
 			    && p[1] == 'K' && p[0] == 'P') {
+				if (zip->hctx_valid)
+					p -= AUTH_CODE_SIZE;
 				break;
 			} else { p += 4; }
 		}
@@ -848,6 +1132,11 @@ zip_read_data_none(struct archive_read *a, const void **_buff,
 	} else {
 		if (zip->entry_bytes_remaining == 0) {
 			zip->end_of_entry = 1;
+			if (zip->hctx_valid) {
+				r = check_authentication_code(a, NULL);
+				if (r != ARCHIVE_OK)
+					return (r);
+			}
 			return (ARCHIVE_OK);
 		}
 		/* Grab a bunch of bytes. */
@@ -861,6 +1150,26 @@ zip_read_data_none(struct archive_read *a, const void **_buff,
 		if (bytes_avail > zip->entry_bytes_remaining)
 			bytes_avail = (ssize_t)zip->entry_bytes_remaining;
 	}
+	if (zip->tctx_valid || zip->cctx_valid) {
+		size_t dec_size = bytes_avail;
+
+		if (dec_size > zip->decrypted_buffer_size)
+			dec_size = zip->decrypted_buffer_size;
+		if (zip->tctx_valid) {
+			trad_enc_decrypt_update(&zip->tctx,
+			    (const uint8_t *)buff, dec_size,
+			    zip->decrypted_buffer, dec_size);
+		} else {
+			size_t dsize = dec_size;
+			archive_hmac_sha1_update(&zip->hctx,
+			    (const uint8_t *)buff, dec_size);
+			archive_decrypto_aes_ctr_update(&zip->cctx,
+			    (const uint8_t *)buff, dec_size,
+			    zip->decrypted_buffer, &dsize);
+		}
+		bytes_avail = dec_size;
+		buff = (const char *)zip->decrypted_buffer;
+	}
 	*size = bytes_avail;
 	zip->entry_bytes_remaining -= bytes_avail;
 	zip->entry_uncompressed_bytes_read += bytes_avail;
@@ -902,7 +1211,7 @@ zip_read_data_deflate(struct archive_read *a, const void **buff,
 {
 	struct zip *zip;
 	ssize_t bytes_avail;
-	const void *compressed_buff;
+	const void *compressed_buff, *sp;
 	int r;
 
 	(void)offset; /* UNUSED */
@@ -931,7 +1240,7 @@ zip_read_data_deflate(struct archive_read *a, const void **buff,
 	 * available bytes; asking for more than that forces the
 	 * decompressor to combine reads by copying data.
 	 */
-	compressed_buff = __archive_read_ahead(a, 1, &bytes_avail);
+	compressed_buff = sp = __archive_read_ahead(a, 1, &bytes_avail);
 	if (0 == (zip->entry->zip_flags & ZIP_LENGTH_AT_END)
 	    && bytes_avail > zip->entry_bytes_remaining) {
 		bytes_avail = (ssize_t)zip->entry_bytes_remaining;
@@ -942,6 +1251,51 @@ zip_read_data_deflate(struct archive_read *a, const void **buff,
 		return (ARCHIVE_FATAL);
 	}
 
+	if (zip->tctx_valid || zip->cctx_valid) {
+		if (zip->decrypted_bytes_remaining < (size_t)bytes_avail) {
+			size_t buff_remaining = zip->decrypted_buffer_size
+			    - (zip->decrypted_ptr - zip->decrypted_buffer);
+
+			if (buff_remaining > (size_t)bytes_avail)
+				buff_remaining = (size_t)bytes_avail;
+
+			if (0 == (zip->entry->zip_flags & ZIP_LENGTH_AT_END) &&
+			      zip->entry_bytes_remaining > 0) {
+				if ((int64_t)(zip->decrypted_bytes_remaining
+				    + buff_remaining)
+				      > zip->entry_bytes_remaining) {
+					if (zip->entry_bytes_remaining <
+					      (int64_t)zip->decrypted_bytes_remaining)
+						buff_remaining = 0;
+					else
+						buff_remaining =
+						    (size_t)zip->entry_bytes_remaining
+						      - zip->decrypted_bytes_remaining;
+				}
+			}
+			if (buff_remaining > 0) {
+				if (zip->tctx_valid) {
+					trad_enc_decrypt_update(&zip->tctx,
+					    compressed_buff, buff_remaining,
+					    zip->decrypted_ptr
+					      + zip->decrypted_bytes_remaining,
+					    buff_remaining);
+				} else {
+					size_t dsize = buff_remaining;
+					archive_decrypto_aes_ctr_update(
+					    &zip->cctx,
+					    compressed_buff, buff_remaining,
+					    zip->decrypted_ptr
+					      + zip->decrypted_bytes_remaining,
+					    &dsize);
+				}
+				zip->decrypted_bytes_remaining += buff_remaining;
+			}
+		}
+		bytes_avail = zip->decrypted_bytes_remaining;
+		compressed_buff = (const char *)zip->decrypted_ptr;
+	}
+
 	/*
 	 * A bug in zlib.h: stream.next_in should be marked 'const'
 	 * but isn't (the library never alters data through the
@@ -974,6 +1328,16 @@ zip_read_data_deflate(struct archive_read *a, const void **buff,
 
 	/* Consume as much as the compressor actually used. */
 	bytes_avail = zip->stream.total_in;
+	if (zip->tctx_valid || zip->cctx_valid) {
+		zip->decrypted_bytes_remaining -= bytes_avail;
+		if (zip->decrypted_bytes_remaining == 0)
+			zip->decrypted_ptr = zip->decrypted_buffer;
+		else
+			zip->decrypted_ptr += bytes_avail;
+	}
+	/* Calculate compressed data as much as we used.*/
+	if (zip->hctx_valid)
+		archive_hmac_sha1_update(&zip->hctx, sp, bytes_avail);
 	__archive_read_consume(a, bytes_avail);
 	zip->entry_bytes_remaining -= bytes_avail;
 	zip->entry_compressed_bytes_read += bytes_avail;
@@ -982,6 +1346,12 @@ zip_read_data_deflate(struct archive_read *a, const void **buff,
 	zip->entry_uncompressed_bytes_read += zip->stream.total_out;
 	*buff = zip->uncompressed_buffer;
 
+	if (zip->end_of_entry && zip->hctx_valid) {
+		r = check_authentication_code(a, NULL);
+		if (r != ARCHIVE_OK)
+			return (r);
+	}
+
 	if (zip->end_of_entry && (zip->entry->zip_flags & ZIP_LENGTH_AT_END)) {
 		const char *p;
 
@@ -1015,13 +1385,392 @@ zip_read_data_deflate(struct archive_read *a, const void **buff,
 #endif
 
 static int
+read_decryption_header(struct archive_read *a)
+{
+	struct zip *zip = (struct zip *)(a->format->data);
+	const char *p;
+	unsigned int remaining_size;
+	unsigned int ts;
+
+	/*
+	 * Read an initialization vector data field.
+	 */
+	p = __archive_read_ahead(a, 2, NULL);
+	if (p == NULL)
+		goto truncated;
+	ts = zip->iv_size;
+	zip->iv_size = archive_le16dec(p);
+	__archive_read_consume(a, 2);
+	if (ts < zip->iv_size) {
+		free(zip->iv);
+		zip->iv = NULL;
+	}
+	p = __archive_read_ahead(a, zip->iv_size, NULL);
+	if (p == NULL)
+		goto truncated;
+	if (zip->iv == NULL) {
+		zip->iv = malloc(zip->iv_size);
+		if (zip->iv == NULL)
+			goto nomem;
+	}
+	memcpy(zip->iv, p, zip->iv_size);
+	__archive_read_consume(a, zip->iv_size);
+
+	/*
+	 * Read a size of remaining decryption header field.
+	 */
+	p = __archive_read_ahead(a, 14, NULL);
+	if (p == NULL)
+		goto truncated;
+	remaining_size = archive_le32dec(p);
+	if (remaining_size < 16 || remaining_size > (1 << 18))
+		goto corrupted;
+
+	/* Check if format version is supported. */
+	if (archive_le16dec(p+4) != 3) {
+		archive_set_error(&a->archive,
+		    ARCHIVE_ERRNO_FILE_FORMAT,
+		    "Unsupported encryption format version: %u",
+		    archive_le16dec(p+4));
+		return (ARCHIVE_FAILED);
+	}
+
+	/*
+	 * Read an encryption algorithm field.
+	 */
+	zip->alg_id = archive_le16dec(p+6);
+	switch (zip->alg_id) {
+	case 0x6601:/* DES */
+	case 0x6602:/* RC2 */
+	case 0x6603:/* 3DES 168 */
+	case 0x6609:/* 3DES 112 */
+	case 0x660E:/* AES 128 */
+	case 0x660F:/* AES 192 */
+	case 0x6610:/* AES 256 */
+	case 0x6702:/* RC2 (version >= 5.2) */
+	case 0x6720:/* Blowfish */
+	case 0x6721:/* Twofish */
+	case 0x6801:/* RC4 */
+		/* Suuported encryption algorithm. */
+		break;
+	default:
+		archive_set_error(&a->archive,
+		    ARCHIVE_ERRNO_FILE_FORMAT,
+		    "Unknown encryption algorithm: %u", zip->alg_id);
+		return (ARCHIVE_FAILED);
+	}
+
+	/*
+	 * Read a bit length field.
+	 */
+	zip->bit_len = archive_le16dec(p+8);
+
+	/*
+	 * Read a flags field.
+	 */
+	zip->flags = archive_le16dec(p+10);
+	switch (zip->flags & 0xf000) {
+	case 0x0001: /* Password is required to decrypt. */
+	case 0x0002: /* Certificates only. */
+	case 0x0003: /* Password or certificate required to decrypt. */
+		break;
+	default:
+		archive_set_error(&a->archive,
+		    ARCHIVE_ERRNO_FILE_FORMAT,
+		    "Unknown encryption flag: %u", zip->flags);
+		return (ARCHIVE_FAILED);
+	}
+	if ((zip->flags & 0xf000) == 0 ||
+	    (zip->flags & 0xf000) == 0x4000) {
+		archive_set_error(&a->archive,
+		    ARCHIVE_ERRNO_FILE_FORMAT,
+		    "Unknown encryption flag: %u", zip->flags);
+		return (ARCHIVE_FAILED);
+	}
+
+	/*
+	 * Read an encrypted random data field.
+	 */
+	ts = zip->erd_size;
+	zip->erd_size = archive_le16dec(p+12);
+	__archive_read_consume(a, 14);
+	if ((zip->erd_size & 0xf) != 0 ||
+	    (zip->erd_size + 16) > remaining_size ||
+	    (zip->erd_size + 16) < zip->erd_size)
+		goto corrupted;
+
+	if (ts < zip->erd_size) {
+		free(zip->erd);
+		zip->erd = NULL;
+	}
+	p = __archive_read_ahead(a, zip->erd_size, NULL);
+	if (p == NULL)
+		goto truncated;
+	if (zip->erd == NULL) {
+		zip->erd = malloc(zip->erd_size);
+		if (zip->erd == NULL)
+			goto nomem;
+	}
+	memcpy(zip->erd, p, zip->erd_size);
+	__archive_read_consume(a, zip->erd_size);
+
+	/*
+	 * Read a reserved data field.
+	 */
+	p = __archive_read_ahead(a, 4, NULL);
+	if (p == NULL)
+		goto truncated;
+	/* Reserved data size should be zero. */
+	if (archive_le32dec(p) != 0)
+		goto corrupted;
+	__archive_read_consume(a, 4);
+
+	/*
+	 * Read a password validation data field.
+	 */
+	p = __archive_read_ahead(a, 2, NULL);
+	if (p == NULL)
+		goto truncated;
+	ts = zip->v_size;
+	zip->v_size = archive_le16dec(p);
+	__archive_read_consume(a, 2);
+	if ((zip->v_size & 0x0f) != 0 ||
+	    (zip->erd_size + zip->v_size + 16) > remaining_size ||
+	    (zip->erd_size + zip->v_size + 16) < (zip->erd_size + zip->v_size))
+		goto corrupted;
+	if (ts < zip->v_size) {
+		free(zip->v_data);
+		zip->v_data = NULL;
+	}
+	p = __archive_read_ahead(a, zip->v_size, NULL);
+	if (p == NULL)
+		goto truncated;
+	if (zip->v_data == NULL) {
+		zip->v_data = malloc(zip->v_size);
+		if (zip->v_data == NULL)
+			goto nomem;
+	}
+	memcpy(zip->v_data, p, zip->v_size);
+	__archive_read_consume(a, zip->v_size);
+
+	p = __archive_read_ahead(a, 4, NULL);
+	if (p == NULL)
+		goto truncated;
+	zip->v_crc32 = archive_le32dec(p);
+	__archive_read_consume(a, 4);
+
+	/*return (ARCHIVE_OK);
+	 * This is not fully implemnted yet.*/
+	archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+	    "Encrypted file is unsupported");
+	return (ARCHIVE_FAILED);
+truncated:
+	archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+	    "Truncated ZIP file data");
+	return (ARCHIVE_FATAL);
+corrupted:
+	archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+	    "Corrupted ZIP file data");
+	return (ARCHIVE_FATAL);
+nomem:
+	archive_set_error(&a->archive, ENOMEM,
+	    "No memory for ZIP decryption");
+	return (ARCHIVE_FATAL);
+}
+
+static int
+zip_alloc_decryption_buffer(struct archive_read *a)
+{
+	struct zip *zip = (struct zip *)(a->format->data);
+	size_t bs = 256 * 1024;
+
+	if (zip->decrypted_buffer == NULL) {
+		zip->decrypted_buffer_size = bs;
+		zip->decrypted_buffer = malloc(bs);
+		if (zip->decrypted_buffer == NULL) {
+			archive_set_error(&a->archive, ENOMEM,
+			    "No memory for ZIP decryption");
+			return (ARCHIVE_FATAL);
+		}
+	}
+	zip->decrypted_ptr = zip->decrypted_buffer;
+	return (ARCHIVE_OK);
+}
+
+static int
+init_traditional_PKWARE_decryption(struct archive_read *a)
+{
+	struct zip *zip = (struct zip *)(a->format->data);
+	const void *p;
+	int retry;
+	int r;
+
+	if (zip->tctx_valid)
+		return (ARCHIVE_OK);
+
+	/*
+	   Read the 12 bytes encryption header stored at
+	   the start of the data area.
+	 */
+#define ENC_HEADER_SIZE	12
+	if (0 == (zip->entry->zip_flags & ZIP_LENGTH_AT_END)
+	    && zip->entry_bytes_remaining < ENC_HEADER_SIZE) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+		    "Truncated Zip encrypted body: only %jd bytes available",
+		    (intmax_t)zip->entry_bytes_remaining);
+		return (ARCHIVE_FATAL);
+	}
+
+	p = __archive_read_ahead(a, ENC_HEADER_SIZE, NULL);
+	if (p == NULL) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+		    "Truncated ZIP file data");
+		return (ARCHIVE_FATAL);
+	}
+
+	for (retry = 0;; retry++) {
+		const char *passphrase;
+		uint8_t crcchk;
+
+		passphrase = __archive_read_next_passphrase(a);
+		if (passphrase == NULL) {
+			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+			    (retry > 0)?
+				"Incorrect passphrase":
+				"Passphrase required for this entry");
+			return (ARCHIVE_FAILED);
+		}
+
+		/*
+		 * Initialize ctx for Traditional PKWARE Decyption.
+		 */
+		r = trad_enc_init(&zip->tctx, passphrase, strlen(passphrase),
+			p, ENC_HEADER_SIZE, &crcchk);
+		if (r == 0 && crcchk == zip->entry->decdat)
+			break;/* The passphrase is OK. */
+		if (retry > 10000) {
+			/* Avoid infinity loop. */
+			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+			    "Too many incorrect passphrases");
+			return (ARCHIVE_FAILED);
+		}
+	}
+
+	__archive_read_consume(a, ENC_HEADER_SIZE);
+	zip->tctx_valid = 1;
+	if (0 == (zip->entry->zip_flags & ZIP_LENGTH_AT_END)) {
+	    zip->entry_bytes_remaining -= ENC_HEADER_SIZE;
+	}
+	/*zip->entry_uncompressed_bytes_read += ENC_HEADER_SIZE;*/
+	zip->entry_compressed_bytes_read += ENC_HEADER_SIZE;
+	zip->decrypted_bytes_remaining = 0;
+
+	return (zip_alloc_decryption_buffer(a));
+#undef ENC_HEADER_SIZE
+}
+
+static int
+init_WinZip_AES_decryption(struct archive_read *a)
+{
+	struct zip *zip = (struct zip *)(a->format->data);
+	const void *p;
+	const uint8_t *pv;
+	size_t key_len, salt_len;
+	uint8_t derived_key[MAX_DERIVED_KEY_BUF_SIZE];
+	int retry;
+	int r;
+
+	if (zip->cctx_valid || zip->hctx_valid)
+		return (ARCHIVE_OK);
+
+	switch (zip->entry->aes_extra.strength) {
+	case 1: salt_len = 8;  key_len = 16; break;
+	case 2: salt_len = 12; key_len = 24; break;
+	case 3: salt_len = 16; key_len = 32; break;
+	default: goto corrupted;
+	}
+	p = __archive_read_ahead(a, salt_len + 2, NULL);
+	if (p == NULL)
+		goto truncated;
+
+	for (retry = 0;; retry++) {
+		const char *passphrase;
+
+		passphrase = __archive_read_next_passphrase(a);
+		if (passphrase == NULL) {
+			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+			    (retry > 0)?
+				"Incorrect passphrase":
+				"Passphrase required for this entry");
+			return (ARCHIVE_FAILED);
+		}
+		memset(derived_key, 0, sizeof(derived_key));
+		r = archive_pbkdf2_sha1(passphrase, strlen(passphrase),
+		    p, salt_len, 1000, derived_key, key_len * 2 + 2);
+		if (r != 0) {
+			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+			    "Decryption is unsupported due to lack of "
+			    "crypto library");
+			return (ARCHIVE_FAILED);
+		}
+
+		/* Check password verification value. */
+		pv = ((const uint8_t *)p) + salt_len;
+		if (derived_key[key_len * 2] == pv[0] &&
+		    derived_key[key_len * 2 + 1] == pv[1])
+			break;/* The passphrase is OK. */
+		if (retry > 10000) {
+			/* Avoid infinity loop. */
+			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+			    "Too many incorrect passphrases");
+			return (ARCHIVE_FAILED);
+		}
+	}
+
+	r = archive_decrypto_aes_ctr_init(&zip->cctx, derived_key, key_len);
+	if (r != 0) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Decryption is unsupported due to lack of crypto library");
+		return (ARCHIVE_FAILED);
+	}
+	r = archive_hmac_sha1_init(&zip->hctx, derived_key + key_len, key_len);
+	if (r != 0) {
+		archive_decrypto_aes_ctr_release(&zip->cctx);
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Failed to initialize HMAC-SHA1");
+		return (ARCHIVE_FAILED);
+	}
+	zip->cctx_valid = zip->hctx_valid = 1;
+	__archive_read_consume(a, salt_len + 2);
+	zip->entry_bytes_remaining -= salt_len + 2 + AUTH_CODE_SIZE;
+	if (0 == (zip->entry->zip_flags & ZIP_LENGTH_AT_END)
+	    && zip->entry_bytes_remaining < 0)
+		goto corrupted;
+	zip->entry_compressed_bytes_read += salt_len + 2 + AUTH_CODE_SIZE;
+	zip->decrypted_bytes_remaining = 0;
+
+	zip->entry->compression = zip->entry->aes_extra.compression;
+	return (zip_alloc_decryption_buffer(a));
+
+truncated:
+	archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+	    "Truncated ZIP file data");
+	return (ARCHIVE_FATAL);
+corrupted:
+	archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+	    "Corrupted ZIP file data");
+	return (ARCHIVE_FATAL);
+}
+
+static int
 archive_read_format_zip_read_data(struct archive_read *a,
     const void **buff, size_t *size, int64_t *offset)
 {
 	int r;
 	struct zip *zip = (struct zip *)(a->format->data);
 
-	if (zip->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) {
+	if (zip->has_encrypted_entries ==
+			ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) {
 		zip->has_encrypted_entries = 0;
 	}
 
@@ -1037,16 +1786,22 @@ archive_read_format_zip_read_data(struct archive_read *a,
 	if (AE_IFREG != (zip->entry->mode & AE_IFMT))
 		return (ARCHIVE_EOF);
 
-	if (zip->entry->zip_flags & (ZIP_ENCRYPTED | ZIP_STRONG_ENCRYPTED)) {
-		zip->has_encrypted_entries = 1;
-		archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
-		    "Encrypted file is unsupported");
-		return (ARCHIVE_FAILED);
-	}
-
 	__archive_read_consume(a, zip->unconsumed);
 	zip->unconsumed = 0;
 
+	if (zip->init_decryption) {
+		zip->has_encrypted_entries = 1;
+		if (zip->entry->zip_flags & ZIP_STRONG_ENCRYPTED)
+			r = read_decryption_header(a);
+		else if (zip->entry->compression == WINZIP_AES_ENCRYPTION)
+			r = init_WinZip_AES_decryption(a);
+		else
+			r = init_traditional_PKWARE_decryption(a);
+		if (r != ARCHIVE_OK)
+			return (r);
+		zip->init_decryption = 0;
+	}
+
 	switch(zip->entry->compression) {
 	case 0:  /* No compression. */
 		r =  zip_read_data_none(a, buff, size, offset);
@@ -1096,7 +1851,9 @@ archive_read_format_zip_read_data(struct archive_read *a,
 			return (ARCHIVE_WARN);
 		}
 		/* Check computed CRC against header */
-		if (zip->entry->crc32 != zip->entry_crc32
+		if ((!zip->hctx_valid ||
+		      zip->entry->aes_extra.vendor != AES_VENDOR_AE_2) &&
+		   zip->entry->crc32 != zip->entry_crc32
 		    && !zip->ignore_crc32) {
 			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
 			    "ZIP bad CRC: 0x%lx should be 0x%lx",
@@ -1130,6 +1887,15 @@ archive_read_format_zip_cleanup(struct archive_read *a)
 			zip_entry = next_zip_entry;
 		}
 	}
+	free(zip->decrypted_buffer);
+	if (zip->cctx_valid)
+		archive_decrypto_aes_ctr_release(&zip->cctx);
+	if (zip->hctx_valid)
+		archive_hmac_sha1_cleanup(&zip->hctx);
+	free(zip->iv);
+	free(zip->erd);
+	free(zip->v_data);
+	archive_string_free(&zip->format_name);
 	free(zip);
 	(a->format->data) = NULL;
 	return (ARCHIVE_OK);
@@ -1217,7 +1983,8 @@ static int
 archive_read_support_format_zip_capabilities_streamable(struct archive_read * a)
 {
 	(void)a; /* UNUSED */
-	return (ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA | ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA);
+	return (ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA |
+		ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA);
 }
 
 static int
@@ -1275,9 +2042,9 @@ archive_read_format_zip_streamable_read_header(struct archive_read *a,
 	 * archive_read_data(), so be it. We'll do the same check there
 	 * as well.
 	 */
-	if (zip->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) {
+	if (zip->has_encrypted_entries ==
+			ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW)
 		zip->has_encrypted_entries = 0;
-	}
 
 	/* Make sure we have a zip_entry structure to use. */
 	if (zip->zip_entries == NULL) {
@@ -1291,6 +2058,13 @@ archive_read_format_zip_streamable_read_header(struct archive_read *a,
 	zip->entry = zip->zip_entries;
 	memset(zip->entry, 0, sizeof(struct zip_entry));
 
+	if (zip->cctx_valid)
+		archive_decrypto_aes_ctr_release(&zip->cctx);
+	if (zip->hctx_valid)
+		archive_hmac_sha1_cleanup(&zip->hctx);
+	zip->tctx_valid = zip->cctx_valid = zip->hctx_valid = 0;
+	__archive_read_reset_passphrase(a);
+
 	/* Search ahead for the next local file header. */
 	__archive_read_consume(a, zip->unconsumed);
 	zip->unconsumed = 0;
@@ -1363,12 +2137,28 @@ archive_read_format_zip_read_data_skip_streamable(struct archive_read *a)
 	if (0 == (zip->entry->zip_flags & ZIP_LENGTH_AT_END)
 	    || zip->entry->compressed_size > 0) {
 		/* We know the compressed length, so we can just skip. */
-		bytes_skipped = __archive_read_consume(a, zip->entry_bytes_remaining);
+		bytes_skipped = __archive_read_consume(a,
+					zip->entry_bytes_remaining);
 		if (bytes_skipped < 0)
 			return (ARCHIVE_FATAL);
 		return (ARCHIVE_OK);
 	}
 
+	if (zip->init_decryption) {
+		int r;
+
+		zip->has_encrypted_entries = 1;
+		if (zip->entry->zip_flags & ZIP_STRONG_ENCRYPTED)
+			r = read_decryption_header(a);
+		else if (zip->entry->compression == WINZIP_AES_ENCRYPTION)
+			r = init_WinZip_AES_decryption(a);
+		else
+			r = init_traditional_PKWARE_decryption(a);
+		if (r != ARCHIVE_OK)
+			return (r);
+		zip->init_decryption = 0;
+	}
+
 	/* We're streaming and we don't know the length. */
 	/* If the body is compressed and we know the format, we can
 	 * find an exact end-of-entry by decompressing it. */
@@ -1406,9 +2196,11 @@ archive_read_format_zip_read_data_skip_streamable(struct archive_read *a)
 				else if (p[3] == '\010' && p[2] == '\007'
 				    && p[1] == 'K' && p[0] == 'P') {
 					if (zip->entry->flags & LA_USED_ZIP64)
-						__archive_read_consume(a, p - buff + 24);
+						__archive_read_consume(a,
+						    p - buff + 24);
 					else
-						__archive_read_consume(a, p - buff + 16);
+						__archive_read_consume(a,
+						    p - buff + 16);
 					return ARCHIVE_OK;
 				} else { p += 4; }
 			}
@@ -1427,13 +2219,12 @@ archive_read_support_format_zip_streamable(struct archive *_a)
 	archive_check_magic(_a, ARCHIVE_READ_MAGIC,
 	    ARCHIVE_STATE_NEW, "archive_read_support_format_zip");
 
-	zip = (struct zip *)malloc(sizeof(*zip));
+	zip = (struct zip *)calloc(1, sizeof(*zip));
 	if (zip == NULL) {
 		archive_set_error(&a->archive, ENOMEM,
 		    "Can't allocate zip data");
 		return (ARCHIVE_FATAL);
 	}
-	memset(zip, 0, sizeof(*zip));
 
 	/* Streamable reader doesn't support mac extensions. */
 	zip->process_mac_extensions = 0;
@@ -1473,7 +2264,8 @@ static int
 archive_read_support_format_zip_capabilities_seekable(struct archive_read * a)
 {
 	(void)a; /* UNUSED */
-	return (ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA | ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA);
+	return (ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA |
+		ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA);
 }
 
 /*
@@ -1514,7 +2306,11 @@ read_eocd(struct zip *zip, const char *p, int64_t current_offset)
 	return 32;
 }
 
-static int
+/*
+ * Examine Zip64 EOCD locator:  If it's valid, store the information
+ * from it.
+ */
+static void
 read_zip64_eocd(struct archive_read *a, struct zip *zip, const char *p)
 {
 	int64_t eocd64_offset;
@@ -1524,37 +2320,35 @@ read_zip64_eocd(struct archive_read *a, struct zip *zip, const char *p)
 
 	/* Central dir must be on first volume. */
 	if (archive_le32dec(p + 4) != 0)
-		return 0;
+		return;
 	/* Must be only a single volume. */
 	if (archive_le32dec(p + 16) != 1)
-		return 0;
+		return;
 
 	/* Find the Zip64 EOCD record. */
 	eocd64_offset = archive_le64dec(p + 8);
 	if (__archive_read_seek(a, eocd64_offset, SEEK_SET) < 0)
-		return 0;
+		return;
 	if ((p = __archive_read_ahead(a, 56, NULL)) == NULL)
-		return 0;
+		return;
 	/* Make sure we can read all of it. */
 	eocd64_size = archive_le64dec(p + 4) + 12;
 	if (eocd64_size < 56 || eocd64_size > 16384)
-		return 0;
-	if ((p = __archive_read_ahead(a, eocd64_size, NULL)) == NULL)
-		return 0;
+		return;
+	if ((p = __archive_read_ahead(a, (size_t)eocd64_size, NULL)) == NULL)
+		return;
 
 	/* Sanity-check the EOCD64 */
 	if (archive_le32dec(p + 16) != 0) /* Must be disk #0 */
-		return 0;
+		return;
 	if (archive_le32dec(p + 20) != 0) /* CD must be on disk #0 */
-		return 0;
+		return;
 	/* CD can't be split. */
 	if (archive_le64dec(p + 24) != archive_le64dec(p + 32))
-		return 0;
+		return;
 
 	/* Save the central directory offset for later use. */
 	zip->central_directory_offset = archive_le64dec(p + 48);
-
-	return 32;
 }
 
 static int
@@ -1575,40 +2369,39 @@ archive_read_format_zip_seekable_bid(struct archive_read *a, int best_bid)
 		return 0;
 
 	/* Search last 16k of file for end-of-central-directory
-	 * record (which starts with PK\005\006) or Zip64 locator
-	 * record (which begins with PK\006\007) */
-	tail = zipmin(1024 * 16, file_size);
+	 * record (which starts with PK\005\006) */
+	tail = (int)zipmin(1024 * 16, file_size);
 	current_offset = __archive_read_seek(a, -tail, SEEK_END);
 	if (current_offset < 0)
 		return 0;
 	if ((p = __archive_read_ahead(a, (size_t)tail, NULL)) == NULL)
 		return 0;
-	/* TODO: Rework this to search backwards from the end.  We
-	 * normally expect the EOCD record to be at the very end, so
-	 * that should be significantly faster.  Tricky part: Make
-	 * sure we still prefer the Zip64 locator if it's present. */
-	for (i = 0; i <= tail - 22;) {
-		switch (p[i + 3]) {
-		case 'P': i += 3; break;
-		case 'K': i += 2; break;
-		case 005: i += 1; break;
-		case 006:
+	/* Boyer-Moore search backwards from the end, since we want
+	 * to match the last EOCD in the file (there can be more than
+	 * one if there is an uncompressed Zip archive as a member
+	 * within this Zip archive). */
+	for (i = tail - 22; i > 0;) {
+		switch (p[i]) {
+		case 'P':
 			if (memcmp(p + i, "PK\005\006", 4) == 0) {
-				int ret = read_eocd(zip, p + i, current_offset + i);
-				if (ret > 0)
-					return (ret);
-			}
-			i += 1; /* Look for PK\006\007 next */
-			break;
-		case 007:
-			if (memcmp(p + i, "PK\006\007", 4) == 0) {
-				int ret = read_zip64_eocd(a, zip, p + i);
-				if (ret > 0)
+				int ret = read_eocd(zip, p + i,
+				    current_offset + i);
+				if (ret > 0) {
+					/* Zip64 EOCD locator precedes
+					 * regular EOCD if present. */
+					if (i >= 20
+					    && memcmp(p + i - 20, "PK\006\007", 4) == 0) {
+						read_zip64_eocd(a, zip, p + i - 20);
+					}
 					return (ret);
+				}
 			}
-			i += 4;
+			i -= 4;
 			break;
-		default: i += 4; break;
+		case 'K': i -= 1; break;
+		case 005: i -= 2; break;
+		case 006: i -= 3; break;
+		default: i -= 4; break;
 		}
 	}
 	return 0;
@@ -1760,7 +2553,8 @@ slurp_central_directory(struct archive_read *a, struct zip *zip)
 		}
 		__archive_read_consume(a, i);
 	}
-	correction = archive_filter_bytes(&a->archive, 0) - zip->central_directory_offset;
+	correction = archive_filter_bytes(&a->archive, 0)
+			- zip->central_directory_offset;
 
 	__archive_rb_tree_init(&zip->tree, &rb_ops);
 	__archive_rb_tree_init(&zip->tree_rsrc, &rb_rsrc_ops);
@@ -1795,12 +2589,17 @@ slurp_central_directory(struct archive_read *a, struct zip *zip)
 		zip_entry->system = p[5];
 		/* version_required = archive_le16dec(p + 6); */
 		zip_entry->zip_flags = archive_le16dec(p + 8);
-		if (zip_entry->zip_flags & (ZIP_ENCRYPTED | ZIP_STRONG_ENCRYPTED)){
+		if (zip_entry->zip_flags
+		      & (ZIP_ENCRYPTED | ZIP_STRONG_ENCRYPTED)){
 			zip->has_encrypted_entries = 1;
 		}
 		zip_entry->compression = (char)archive_le16dec(p + 10);
 		zip_entry->mtime = zip_time(p + 12);
 		zip_entry->crc32 = archive_le32dec(p + 16);
+		if (zip_entry->zip_flags & ZIP_LENGTH_AT_END)
+			zip_entry->decdat = p[13];
+		else
+			zip_entry->decdat = p[19];
 		zip_entry->compressed_size = archive_le32dec(p + 20);
 		zip_entry->uncompressed_size = archive_le32dec(p + 24);
 		filename_length = archive_le16dec(p + 28);
@@ -1823,9 +2622,11 @@ slurp_central_directory(struct archive_read *a, struct zip *zip)
 		/* We're done with the regular data; get the filename and
 		 * extra data. */
 		__archive_read_consume(a, 46);
-		if ((p = __archive_read_ahead(a, filename_length + extra_length, NULL))
-		    == NULL) {
-			archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+		p = __archive_read_ahead(a, filename_length + extra_length,
+			NULL);
+		if (p == NULL) {
+			archive_set_error(&a->archive,
+			    ARCHIVE_ERRNO_FILE_FORMAT,
 			    "Truncated ZIP file header");
 			return ARCHIVE_FATAL;
 		}
@@ -1850,26 +2651,30 @@ slurp_central_directory(struct archive_read *a, struct zip *zip)
 				 * resource fork file to expose it. */
 				if (name[filename_length-1] != '/' &&
 				    (r - name < 3 || r[0] != '.' || r[1] != '_')) {
-					__archive_rb_tree_insert_node(&zip->tree,
-					    &zip_entry->node);
+					__archive_rb_tree_insert_node(
+					    &zip->tree, &zip_entry->node);
 					/* Expose its parent directories. */
-					expose_parent_dirs(zip, name, filename_length);
+					expose_parent_dirs(zip, name,
+					    filename_length);
 				} else {
 					/* This file is a resource fork file or
 					 * a directory. */
-					archive_strncpy(&(zip_entry->rsrcname), name,
-					    filename_length);
-					__archive_rb_tree_insert_node(&zip->tree_rsrc,
-					    &zip_entry->node);
+					archive_strncpy(&(zip_entry->rsrcname),
+					     name, filename_length);
+					__archive_rb_tree_insert_node(
+					    &zip->tree_rsrc, &zip_entry->node);
 				}
 			} else {
-				/* Generate resource fork name to find its resource
-				 * file at zip->tree_rsrc. */
-				archive_strcpy(&(zip_entry->rsrcname), "__MACOSX/");
-				archive_strncat(&(zip_entry->rsrcname), name, r - name);
+				/* Generate resource fork name to find its
+				 * resource file at zip->tree_rsrc. */
+				archive_strcpy(&(zip_entry->rsrcname),
+				    "__MACOSX/");
+				archive_strncat(&(zip_entry->rsrcname),
+				    name, r - name);
 				archive_strcat(&(zip_entry->rsrcname), "._");
 				archive_strncat(&(zip_entry->rsrcname),
-				    name + (r - name), filename_length - (r - name));
+				    name + (r - name),
+				    filename_length - (r - name));
 				/* Register an entry to RB tree to sort it by
 				 * file offset. */
 				__archive_rb_tree_insert_node(&zip->tree,
@@ -2060,9 +2865,9 @@ archive_read_format_zip_seekable_read_header(struct archive_read *a,
 	 * archive_read_data(), so be it. We'll do the same check there
 	 * as well.
 	 */
-	if (zip->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) {
+	if (zip->has_encrypted_entries ==
+			ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW)
 		zip->has_encrypted_entries = 0;
-	}
 
 	a->archive.archive_format = ARCHIVE_FORMAT_ZIP;
 	if (a->archive.archive_format_name == NULL)
@@ -2091,6 +2896,13 @@ archive_read_format_zip_seekable_read_header(struct archive_read *a,
 	else
 		rsrc = NULL;
 
+	if (zip->cctx_valid)
+		archive_decrypto_aes_ctr_release(&zip->cctx);
+	if (zip->hctx_valid)
+		archive_hmac_sha1_cleanup(&zip->hctx);
+	zip->tctx_valid = zip->cctx_valid = zip->hctx_valid = 0;
+	__archive_read_reset_passphrase(a);
+
 	/* File entries are sorted by the header offset, we should mostly
 	 * use __archive_read_consume to advance a read point to avoid redundant
 	 * data reading.  */
@@ -2099,7 +2911,8 @@ archive_read_format_zip_seekable_read_header(struct archive_read *a,
 		__archive_read_consume(a,
 		    zip->entry->local_header_offset - offset);
 	else if (offset != zip->entry->local_header_offset) {
-		__archive_read_seek(a, zip->entry->local_header_offset, SEEK_SET);
+		__archive_read_seek(a, zip->entry->local_header_offset,
+		    SEEK_SET);
 	}
 	zip->unconsumed = 0;
 	r = zip_read_local_file_header(a, entry, zip);
@@ -2137,13 +2950,12 @@ archive_read_support_format_zip_seekable(struct archive *_a)
 	archive_check_magic(_a, ARCHIVE_READ_MAGIC,
 	    ARCHIVE_STATE_NEW, "archive_read_support_format_zip_seekable");
 
-	zip = (struct zip *)malloc(sizeof(*zip));
+	zip = (struct zip *)calloc(1, sizeof(*zip));
 	if (zip == NULL) {
 		archive_set_error(&a->archive, ENOMEM,
 		    "Can't allocate zip data");
 		return (ARCHIVE_FATAL);
 	}
-	memset(zip, 0, sizeof(*zip));
 
 #ifdef HAVE_COPYFILE_H
 	/* Set this by default on Mac OS. */
diff --git a/Utilities/cmlibarchive/libarchive/archive_string.c b/Utilities/cmlibarchive/libarchive/archive_string.c
index 87f9288..3d4be82 100644
--- a/Utilities/cmlibarchive/libarchive/archive_string.c
+++ b/Utilities/cmlibarchive/libarchive/archive_string.c
@@ -71,6 +71,10 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_string.c 201095 2009-12-28 02:33
 #define wmemcpy(a,b,i)  (wchar_t *)memcpy((a), (b), (i) * sizeof(wchar_t))
 #endif
 
+#if !defined(HAVE_WMEMMOVE) && !defined(wmemmove)
+#define wmemmove(a,b,i)  (wchar_t *)memmove((a), (b), (i) * sizeof(wchar_t))
+#endif
+
 struct archive_string_conv {
 	struct archive_string_conv	*next;
 	char				*from_charset;
@@ -127,12 +131,7 @@ struct archive_string_conv {
 #define UNICODE_MAX		0x10FFFF
 #define UNICODE_R_CHAR		0xFFFD	/* Replacement character. */
 /* Set U+FFFD(Replacement character) in UTF-8. */
-#define UTF8_SET_R_CHAR(outp) do {		\
-			(outp)[0] = 0xef;	\
-			(outp)[1] = 0xbf;	\
-			(outp)[2] = 0xbd;	\
-} while (0)
-#define UTF8_R_CHAR_SIZE	3
+static const char utf8_replacement_char[] = {0xef, 0xbf, 0xbd};
 
 static struct archive_string_conv *find_sconv_object(struct archive *,
 	const char *, const char *);
@@ -203,7 +202,7 @@ archive_string_append(struct archive_string *as, const char *p, size_t s)
 {
 	if (archive_string_ensure(as, as->length + s + 1) == NULL)
 		return (NULL);
-	memcpy(as->s + as->length, p, s);
+	memmove(as->s + as->length, p, s);
 	as->length += s;
 	as->s[as->length] = 0;
 	return (as);
@@ -214,7 +213,7 @@ archive_wstring_append(struct archive_wstring *as, const wchar_t *p, size_t s)
 {
 	if (archive_wstring_ensure(as, as->length + s + 1) == NULL)
 		return (NULL);
-	wmemcpy(as->s + as->length, p, s);
+	wmemmove(as->s + as->length, p, s);
 	as->length += s;
 	as->s[as->length] = 0;
 	return (as);
@@ -2037,7 +2036,7 @@ iconv_strncat_in_locale(struct archive_string *as, const void *_p,
 			if (sc->flag & (SCONV_TO_UTF8 | SCONV_TO_UTF16)) {
 				size_t rbytes;
 				if (sc->flag & SCONV_TO_UTF8)
-					rbytes = UTF8_R_CHAR_SIZE;
+					rbytes = sizeof(utf8_replacement_char);
 				else
 					rbytes = 2;
 
@@ -2053,7 +2052,7 @@ iconv_strncat_in_locale(struct archive_string *as, const void *_p,
 					    - as->length - to_size;
 				}
 				if (sc->flag & SCONV_TO_UTF8)
-					UTF8_SET_R_CHAR(outp);
+					memcpy(outp, utf8_replacement_char, sizeof(utf8_replacement_char));
 				else if (sc->flag & SCONV_TO_UTF16BE)
 					archive_be16enc(outp, UNICODE_R_CHAR);
 				else
@@ -2202,9 +2201,7 @@ best_effort_strncat_in_locale(struct archive_string *as, const void *_p,
     size_t length, struct archive_string_conv *sc)
 {
 	size_t remaining;
-	char *otp;
 	const uint8_t *itp;
-	size_t avail;
 	int return_value = 0; /* success */
 
 	/*
@@ -2223,46 +2220,25 @@ best_effort_strncat_in_locale(struct archive_string *as, const void *_p,
 	 * byte sequence 0xEF 0xBD 0xBD, which are code point U+FFFD,
 	 * a Replacement Character in Unicode.
 	 */
-	if (archive_string_ensure(as, as->length + length + 1) == NULL)
-		return (-1);
 
 	remaining = length;
 	itp = (const uint8_t *)_p;
-	otp = as->s + as->length;
-	avail = as->buffer_length - as->length -1;
 	while (*itp && remaining > 0) {
-		if (*itp > 127 && (sc->flag & SCONV_TO_UTF8)) {
-			if (avail < UTF8_R_CHAR_SIZE) {
-				as->length = otp - as->s;
-				if (NULL == archive_string_ensure(as,
-				    as->buffer_length + remaining +
-				    UTF8_R_CHAR_SIZE))
-					return (-1);
-				otp = as->s + as->length;
-				avail = as->buffer_length - as->length -1;
+		if (*itp > 127) {
+			// Non-ASCII: Substitute with suitable replacement
+			if (sc->flag & SCONV_TO_UTF8) {
+				if (archive_string_append(as, utf8_replacement_char, sizeof(utf8_replacement_char)) == NULL) {
+					__archive_errx(1, "Out of memory");
+				}
+			} else {
+				archive_strappend_char(as, '?');
 			}
-			/*
-		 	 * When coping a string in UTF-8, unknown character
-			 * should be U+FFFD (replacement character).
-			 */
-			UTF8_SET_R_CHAR(otp);
-			otp += UTF8_R_CHAR_SIZE;
-			avail -= UTF8_R_CHAR_SIZE;
-			itp++;
-			remaining--;
-			return_value = -1;
-		} else if (*itp > 127) {
-			*otp++ = '?';
-			itp++;
-			remaining--;
 			return_value = -1;
 		} else {
-			*otp++ = (char)*itp++;
-			remaining--;
+			archive_strappend_char(as, *itp);
 		}
+		++itp;
 	}
-	as->length = otp - as->s;
-	as->s[as->length] = '\0';
 	return (return_value);
 }
 
@@ -2488,6 +2464,9 @@ unicode_to_utf8(char *p, size_t remaining, uint32_t uc)
 {
 	char *_p = p;
 
+	/* Invalid Unicode char maps to Replacement character */
+	if (uc > UNICODE_MAX)
+		uc = UNICODE_R_CHAR;
 	/* Translate code point to UTF8 */
 	if (uc <= 0x7f) {
 		if (remaining == 0)
@@ -2504,22 +2483,13 @@ unicode_to_utf8(char *p, size_t remaining, uint32_t uc)
 		*p++ = 0xe0 | ((uc >> 12) & 0x0f);
 		*p++ = 0x80 | ((uc >> 6) & 0x3f);
 		*p++ = 0x80 | (uc & 0x3f);
-	} else if (uc <= UNICODE_MAX) {
+	} else {
 		if (remaining < 4)
 			return (0);
 		*p++ = 0xf0 | ((uc >> 18) & 0x07);
 		*p++ = 0x80 | ((uc >> 12) & 0x3f);
 		*p++ = 0x80 | ((uc >> 6) & 0x3f);
 		*p++ = 0x80 | (uc & 0x3f);
-	} else {
-		/*
-		 * Undescribed code point should be U+FFFD
-		 * (replacement character).
-		 */
-		if (remaining < UTF8_R_CHAR_SIZE)
-			return (0);
-		UTF8_SET_R_CHAR(p);
-		p += UTF8_R_CHAR_SIZE;
 	}
 	return (p - _p);
 }
@@ -3887,7 +3857,7 @@ archive_mstring_get_utf8(struct archive *a, struct archive_mstring *aes,
 		sc = archive_string_conversion_to_charset(a, "UTF-8", 1);
 		if (sc == NULL)
 			return (-1);/* Couldn't allocate memory for sc. */
-		r = archive_strncpy_l(&(aes->aes_mbs), aes->aes_mbs.s,
+		r = archive_strncpy_l(&(aes->aes_utf8), aes->aes_mbs.s,
 		    aes->aes_mbs.length, sc);
 		if (a == NULL)
 			free_sconv_object(sc);
@@ -4062,6 +4032,19 @@ archive_mstring_copy_wcs(struct archive_mstring *aes, const wchar_t *wcs)
 }
 
 int
+archive_mstring_copy_utf8(struct archive_mstring *aes, const char *utf8)
+{
+  if (utf8 == NULL) {
+    aes->aes_set = 0;
+  }
+  aes->aes_set = AES_SET_UTF8;
+  archive_string_empty(&(aes->aes_mbs));
+  archive_string_empty(&(aes->aes_wcs));
+  archive_strncpy(&(aes->aes_utf8), utf8, strlen(utf8));
+  return (int)strlen(utf8);
+}
+
+int
 archive_mstring_copy_wcs_len(struct archive_mstring *aes, const wchar_t *wcs,
     size_t len)
 {
diff --git a/Utilities/cmlibarchive/libarchive/archive_util.c b/Utilities/cmlibarchive/libarchive/archive_util.c
index d136498..5f31edf 100644
--- a/Utilities/cmlibarchive/libarchive/archive_util.c
+++ b/Utilities/cmlibarchive/libarchive/archive_util.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2009-2012 Michihiro NAKAJIMA
+ * Copyright (c) 2009-2012,2014 Michihiro NAKAJIMA
  * Copyright (c) 2003-2007 Tim Kientzle
  * All rights reserved.
  *
@@ -54,9 +54,13 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_util.c 201098 2009-12-28 02:58:1
 #ifdef HAVE_BZLIB_H
 #include <cm_bzlib.h>
 #endif
+#ifdef HAVE_LZ4_H
+#include <lz4.h>
+#endif
 
 #include "archive.h"
 #include "archive_private.h"
+#include "archive_random_private.h"
 #include "archive_string.h"
 
 #ifndef O_CLOEXEC
@@ -113,7 +117,11 @@ archive_version_details(void)
 			archive_strncat(&str, p, sep - p);
 		}
 #endif
-	    }
+#if defined(HAVE_LZ4_H) && defined(HAVE_LIBLZ4)
+		archive_string_sprintf(&str, " liblz4/%d.%d.%d",
+		    LZ4_VERSION_MAJOR, LZ4_VERSION_MINOR, LZ4_VERSION_RELEASE);
+#endif
+	}
 	return str.s;
 }
 
@@ -465,7 +473,6 @@ __archive_mktemp(const char *tmpdir)
 	struct stat st;
 	int fd;
 	char *tp, *ep;
-	unsigned seed;
 
 	fd = -1;
 	archive_string_init(&temp_name);
@@ -489,21 +496,15 @@ __archive_mktemp(const char *tmpdir)
 	archive_strcat(&temp_name, "XXXXXXXXXX");
 	ep = temp_name.s + archive_strlen(&temp_name);
 
-	fd = open("/dev/random", O_RDONLY | O_CLOEXEC);
-	__archive_ensure_cloexec_flag(fd);
-	if (fd < 0)
-		seed = time(NULL);
-	else {
-		if (read(fd, &seed, sizeof(seed)) < 0)
-			seed = time(NULL);
-		close(fd);
-	}
 	do {
 		char *p;
 
 		p = tp;
-		while (p < ep)
-			*p++ = num[((unsigned)rand_r(&seed)) % sizeof(num)];
+		archive_random(p, ep - p);
+		while (p < ep) {
+			int d = *((unsigned char *)p) % sizeof(num);
+			*p++ = num[d];
+		}
 		fd = open(temp_name.s, O_CREAT | O_EXCL | O_RDWR | O_CLOEXEC,
 			  0600);
 	} while (fd < 0 && errno == EEXIST);
@@ -551,62 +552,70 @@ __archive_ensure_cloexec_flag(int fd)
 static int
 archive_utility_string_sort_helper(char **strings, unsigned int n)
 {
-  unsigned int i, lesser_count, greater_count;
-  char **lesser, **greater, **tmp, *pivot;
-  int retval1, retval2;
-
-  /* A list of 0 or 1 elements is already sorted */
-  if (n <= 1)
-    return (ARCHIVE_OK);
-
-  lesser_count = greater_count = 0;
-  lesser = greater = NULL;
-  pivot = strings[0];
-  for (i = 1; i < n; i++)
-  {
-    if (strcmp(strings[i], pivot) < 0)
-    {
-      lesser_count++;
-      tmp = (char **)realloc(lesser, lesser_count * sizeof(char *));
-      if (!tmp)
-        return (ARCHIVE_FATAL);
-      lesser = tmp;
-      lesser[lesser_count - 1] = strings[i];
-    }
-    else
-    {
-      greater_count++;
-      tmp = (char **)realloc(greater, greater_count * sizeof(char *));
-      if (!tmp)
-        return (ARCHIVE_FATAL);
-      greater = tmp;
-      greater[greater_count - 1] = strings[i];
-    }
-  }
-
-  /* quicksort(lesser) */
-  retval1 = archive_utility_string_sort_helper(lesser, lesser_count);
-  for (i = 0; i < lesser_count; i++)
-    strings[i] = lesser[i];
-  free(lesser);
-
-  /* pivot */
-  strings[lesser_count] = pivot;
-
-  /* quicksort(greater) */
-  retval2 = archive_utility_string_sort_helper(greater, greater_count);
-  for (i = 0; i < greater_count; i++)
-    strings[lesser_count + 1 + i] = greater[i];
-  free(greater);
-
-  return (retval1 < retval2) ? retval1 : retval2;
+	unsigned int i, lesser_count, greater_count;
+	char **lesser, **greater, **tmp, *pivot;
+	int retval1, retval2;
+
+	/* A list of 0 or 1 elements is already sorted */
+	if (n <= 1)
+		return (ARCHIVE_OK);
+
+	lesser_count = greater_count = 0;
+	lesser = greater = NULL;
+	pivot = strings[0];
+	for (i = 1; i < n; i++)
+	{
+		if (strcmp(strings[i], pivot) < 0)
+		{
+			lesser_count++;
+			tmp = (char **)realloc(lesser,
+				lesser_count * sizeof(char *));
+			if (!tmp) {
+				free(greater);
+				free(lesser);
+				return (ARCHIVE_FATAL);
+			}
+			lesser = tmp;
+			lesser[lesser_count - 1] = strings[i];
+		}
+		else
+		{
+			greater_count++;
+			tmp = (char **)realloc(greater,
+				greater_count * sizeof(char *));
+			if (!tmp) {
+				free(greater);
+				free(lesser);
+				return (ARCHIVE_FATAL);
+			}
+			greater = tmp;
+			greater[greater_count - 1] = strings[i];
+		}
+	}
+
+	/* quicksort(lesser) */
+	retval1 = archive_utility_string_sort_helper(lesser, lesser_count);
+	for (i = 0; i < lesser_count; i++)
+		strings[i] = lesser[i];
+	free(lesser);
+
+	/* pivot */
+	strings[lesser_count] = pivot;
+
+	/* quicksort(greater) */
+	retval2 = archive_utility_string_sort_helper(greater, greater_count);
+	for (i = 0; i < greater_count; i++)
+		strings[lesser_count + 1 + i] = greater[i];
+	free(greater);
+
+	return (retval1 < retval2) ? retval1 : retval2;
 }
 
 int
 archive_utility_string_sort(char **strings)
 {
-  unsigned int size = 0;
-  while (strings[size] != NULL)
-    size++;
-  return archive_utility_string_sort_helper(strings, size);
+	  unsigned int size = 0;
+	  while (strings[size] != NULL)
+		size++;
+	  return archive_utility_string_sort_helper(strings, size);
 }
diff --git a/Utilities/cmlibarchive/libarchive/archive_windows.h b/Utilities/cmlibarchive/libarchive/archive_windows.h
index dc2f241..7c31a16 100644
--- a/Utilities/cmlibarchive/libarchive/archive_windows.h
+++ b/Utilities/cmlibarchive/libarchive/archive_windows.h
@@ -227,7 +227,9 @@
 #define	S_IRWXG        _S_IRWXG
 #define	S_IXGRP        _S_IXGRP
 #define	S_IWGRP        _S_IWGRP
+#ifndef S_IRGRP
 #define	S_IRGRP        _S_IRGRP
+#endif
 #define	S_IRWXO        _S_IRWXO
 #define	S_IXOTH        _S_IXOTH
 #define	S_IWOTH        _S_IWOTH
diff --git a/Utilities/cmlibarchive/libarchive/archive_write.3 b/Utilities/cmlibarchive/libarchive/archive_write.3
index 228bc2c..376d71d 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write.3
+++ b/Utilities/cmlibarchive/libarchive/archive_write.3
@@ -155,7 +155,7 @@ myopen(struct archive *a, void *client_data)
     return (ARCHIVE_FATAL);
 }
 
-ssize_t
+la_ssize_t
 mywrite(struct archive *a, void *client_data, const void *buff, size_t n)
 {
   struct mydata *mydata = client_data;
@@ -186,8 +186,13 @@ write_archive(const char *outname, const char **filename)
 
   a = archive_write_new();
   mydata->name = outname;
-  archive_write_add_filter_gzip(a);
-  archive_write_set_format_ustar(a);
+  /* Set archive format and filter according to output file extension.
+   * If it fails, set default format. Platform depended function.
+   * See supported formats in archive_write_set_format_filter_by_ext.c */
+  if (archive_write_set_format_filter_by_ext(a, outname) != ARCHIVE_OK)  {
+    archive_write_add_filter_gzip(a);
+    archive_write_set_format_ustar(a);
+  }  
   archive_write_open(a, mydata, myopen, mywrite, myclose);
   while (*filename) {
     stat(*filename, &st);
@@ -197,7 +202,7 @@ write_archive(const char *outname, const char **filename)
     archive_write_header(a, entry);
     if ((fd = open(*filename, O_RDONLY)) != -1) {
       len = read(fd, buff, sizeof(buff));
-      while ( len > 0 ) {
+      while (len > 0) {
         archive_write_data(a, buff, len);
         len = read(fd, buff, sizeof(buff));
       }
@@ -213,7 +218,7 @@ int main(int argc, const char **argv)
 {
   const char *outname;
   argv++;
-  outname = argv++;
+  outname = *argv++;
   write_archive(outname, argv);
   return 0;
 }
diff --git a/Utilities/cmlibarchive/libarchive/archive_write.c b/Utilities/cmlibarchive/libarchive/archive_write.c
index 8997193..e3fa335 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write.c
@@ -444,6 +444,12 @@ archive_write_client_close(struct archive_write_filter *f)
 	/* Clear the close handler myself not to be called again. */
 	f->close = NULL;
 	a->client_data = NULL;
+	/* Clear passphrase. */
+	if (a->passphrase != NULL) {
+		memset(a->passphrase, 0, strlen(a->passphrase));
+		free(a->passphrase);
+		a->passphrase = NULL;
+	}
 	return (ret);
 }
 
@@ -592,6 +598,11 @@ _archive_write_free(struct archive *_a)
 	/* Release various dynamic buffers. */
 	free((void *)(uintptr_t)(const void *)a->nulls);
 	archive_string_free(&a->archive.error_string);
+	if (a->passphrase != NULL) {
+		/* A passphrase should be cleaned. */
+		memset(a->passphrase, 0, strlen(a->passphrase));
+		free(a->passphrase);
+	}
 	a->archive.magic = 0;
 	__archive_clean(&a->archive);
 	free(a);
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c
index 81dd683..ad5dc83 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c
@@ -47,6 +47,7 @@ struct { int code; int (*setter)(struct archive *); } codes[] =
 	{ ARCHIVE_FILTER_COMPRESS,	archive_write_add_filter_compress },
 	{ ARCHIVE_FILTER_GRZIP,		archive_write_add_filter_grzip },
 	{ ARCHIVE_FILTER_LRZIP,		archive_write_add_filter_lrzip },
+	{ ARCHIVE_FILTER_LZ4,		archive_write_add_filter_lz4 },
 	{ ARCHIVE_FILTER_LZIP,		archive_write_add_filter_lzip },
 	{ ARCHIVE_FILTER_LZMA,		archive_write_add_filter_lzma },
 	{ ARCHIVE_FILTER_LZOP,		archive_write_add_filter_lzip },
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c
index e4cba4a..eac4011 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c
@@ -51,6 +51,7 @@ struct { const char *name; int (*setter)(struct archive *); } names[] =
 	{ "grzip",		archive_write_add_filter_grzip },
 	{ "gzip",		archive_write_add_filter_gzip },
 	{ "lrzip",		archive_write_add_filter_lrzip },
+	{ "lz4",		archive_write_add_filter_lz4 },
 	{ "lzip",		archive_write_add_filter_lzip },
 	{ "lzma",		archive_write_add_filter_lzma },
 	{ "lzop",		archive_write_add_filter_lzop },
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lz4.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lz4.c
new file mode 100644
index 0000000..e23e5e9
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lz4.c
@@ -0,0 +1,646 @@
+/*-
+ * Copyright (c) 2014 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "archive_platform.h"
+
+__FBSDID("$FreeBSD$");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_LZ4_H
+#include <lz4.h>
+#endif
+#ifdef HAVE_LZ4HC_H
+#include <lz4hc.h>
+#endif
+
+#include "archive.h"
+#include "archive_endian.h"
+#include "archive_private.h"
+#include "archive_write_private.h"
+#include "archive_xxhash.h"
+
+#define LZ4_MAGICNUMBER	0x184d2204
+
+struct private_data {
+	int		 compression_level;
+	unsigned	 header_written:1;
+	unsigned	 version_number:1;
+	unsigned	 block_independence:1;
+	unsigned	 block_checksum:1;
+	unsigned	 stream_size:1;
+	unsigned	 stream_checksum:1;
+	unsigned	 preset_dictionary:1;
+	unsigned	 block_maximum_size:3;
+#if defined(HAVE_LIBLZ4) && LZ4_VERSION_MAJOR >= 1 && LZ4_VERSION_MINOR >= 2
+	int64_t		 total_in;
+	char		*out;
+	char		*out_buffer;
+	size_t		 out_buffer_size;
+	size_t		 out_block_size;
+	char		*in;
+	char		*in_buffer_allocated;
+	char		*in_buffer;
+	size_t		 in_buffer_size;
+	size_t		 block_size;
+
+	void		*xxh32_state;
+	void		*lz4_stream;
+#else
+	struct archive_write_program_data *pdata;
+#endif
+};
+
+static int archive_filter_lz4_close(struct archive_write_filter *);
+static int archive_filter_lz4_free(struct archive_write_filter *);
+static int archive_filter_lz4_open(struct archive_write_filter *);
+static int archive_filter_lz4_options(struct archive_write_filter *,
+		    const char *, const char *);
+static int archive_filter_lz4_write(struct archive_write_filter *,
+		    const void *, size_t);
+
+/*
+ * Add a lz4 compression filter to this write handle.
+ */
+int
+archive_write_add_filter_lz4(struct archive *_a)
+{
+	struct archive_write *a = (struct archive_write *)_a;
+	struct archive_write_filter *f = __archive_write_allocate_filter(_a);
+	struct private_data *data;
+
+	archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+	    ARCHIVE_STATE_NEW, "archive_write_add_filter_lz4");
+
+	data = calloc(1, sizeof(*data));
+	if (data == NULL) {
+		archive_set_error(&a->archive, ENOMEM, "Out of memory");
+		return (ARCHIVE_FATAL);
+	}
+
+	/*
+	 * Setup default settings.
+	 */
+	data->compression_level = 1;
+	data->version_number = 0x01;
+	data->block_independence = 1;
+	data->block_checksum = 0;
+	data->stream_size = 0;
+	data->stream_checksum = 1;
+	data->preset_dictionary = 0;
+	data->block_maximum_size = 7;
+
+	/*
+	 * Setup a filter setting.
+	 */
+	f->data = data;
+	f->options = &archive_filter_lz4_options;
+	f->close = &archive_filter_lz4_close;
+	f->free = &archive_filter_lz4_free;
+	f->open = &archive_filter_lz4_open;
+	f->code = ARCHIVE_FILTER_LZ4;
+	f->name = "lz4";
+#if defined(HAVE_LIBLZ4) && LZ4_VERSION_MAJOR >= 1 && LZ4_VERSION_MINOR >= 2
+	return (ARCHIVE_OK);
+#else
+	/*
+	 * We don't have lz4 library, and execute external lz4 program
+	 * instead.
+	 */
+	data->pdata = __archive_write_program_allocate();
+	if (data->pdata == NULL) {
+		free(data);
+		archive_set_error(&a->archive, ENOMEM, "Out of memory");
+		return (ARCHIVE_FATAL);
+	}
+	data->compression_level = 0;
+	archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+	    "Using external lz4 program");
+	return (ARCHIVE_WARN);
+#endif
+}
+
+/*
+ * Set write options.
+ */
+static int
+archive_filter_lz4_options(struct archive_write_filter *f,
+    const char *key, const char *value)
+{
+	struct private_data *data = (struct private_data *)f->data;
+
+	if (strcmp(key, "compression-level") == 0) {
+		if (value == NULL || !(value[0] >= '1' && value[0] <= '9') ||
+		    value[1] != '\0')
+			return (ARCHIVE_WARN);
+		data->compression_level = value[0] - '0';
+		return (ARCHIVE_OK);
+	}
+	if (strcmp(key, "stream-checksum") == 0) {
+		data->stream_checksum = value != NULL;
+		return (ARCHIVE_OK);
+	}
+	if (strcmp(key, "block-checksum") == 0) {
+		data->block_checksum = value != NULL;
+		return (ARCHIVE_OK);
+	}
+	if (strcmp(key, "block-size") == 0) {
+		if (value == NULL || !(value[0] >= '4' && value[0] <= '7') ||
+		    value[1] != '\0')
+			return (ARCHIVE_WARN);
+		data->block_maximum_size = value[0] - '0';
+		return (ARCHIVE_OK);
+	}
+	if (strcmp(key, "block-dependence") == 0) {
+		data->block_independence = value == NULL;
+		return (ARCHIVE_OK);
+	}
+
+	/* Note: The "warn" return is just to inform the options
+	 * supervisor that we didn't handle it.  It will generate
+	 * a suitable error if no one used this option. */
+	return (ARCHIVE_WARN);
+}
+
+#if defined(HAVE_LIBLZ4) && LZ4_VERSION_MAJOR >= 1 && LZ4_VERSION_MINOR >= 2
+/* Don't compile this if we don't have liblz4. */
+
+static int drive_compressor(struct archive_write_filter *, const char *,
+    size_t);
+static int drive_compressor_independence(struct archive_write_filter *,
+    const char *, size_t);
+static int drive_compressor_dependence(struct archive_write_filter *,
+    const char *, size_t);
+static int lz4_write_stream_descriptor(struct archive_write_filter *);
+static ssize_t lz4_write_one_block(struct archive_write_filter *, const char *,
+    size_t);
+
+
+/*
+ * Setup callback.
+ */
+static int
+archive_filter_lz4_open(struct archive_write_filter *f)
+{
+	struct private_data *data = (struct private_data *)f->data;
+	int ret;
+	size_t required_size;
+	static size_t bkmap[] = { 64 * 1024, 256 * 1024, 1 * 1024 * 1024,
+			   4 * 1024 * 1024 };
+	size_t pre_block_size;
+
+	ret = __archive_write_open_filter(f->next_filter);
+	if (ret != 0)
+		return (ret);
+
+	if (data->block_maximum_size < 4)
+		data->block_size = bkmap[0];
+	else
+		data->block_size = bkmap[data->block_maximum_size - 4];
+
+	required_size = 4 + 15 + 4 + data->block_size + 4 + 4;
+	if (data->out_buffer_size < required_size) {
+		size_t bs = required_size, bpb;
+		free(data->out_buffer);
+		if (f->archive->magic == ARCHIVE_WRITE_MAGIC) {
+			/* Buffer size should be a multiple number of
+			 * the of bytes per block for performance. */
+			bpb = archive_write_get_bytes_per_block(f->archive);
+			if (bpb > bs)
+				bs = bpb;
+			else if (bpb != 0) {
+				bs += bpb;
+				bs -= bs % bpb;
+			}
+		}
+		data->out_block_size = bs;
+		bs += required_size;
+		data->out_buffer = malloc(bs);
+		data->out = data->out_buffer;
+		data->out_buffer_size = bs;
+	}
+
+	pre_block_size = (data->block_independence)? 0: 64 * 1024;
+	if (data->in_buffer_size < data->block_size + pre_block_size) {
+		free(data->in_buffer_allocated);
+		data->in_buffer_size = data->block_size;
+		data->in_buffer_allocated =
+		    malloc(data->in_buffer_size + pre_block_size);
+		data->in_buffer = data->in_buffer_allocated + pre_block_size;
+		if (!data->block_independence && data->compression_level >= 3)
+		    data->in_buffer = data->in_buffer_allocated;
+		data->in = data->in_buffer;
+		data->in_buffer_size = data->block_size;
+	}
+
+	if (data->out_buffer == NULL || data->in_buffer_allocated == NULL) {
+		archive_set_error(f->archive, ENOMEM,
+		    "Can't allocate data for compression buffer");
+		return (ARCHIVE_FATAL);
+	}
+
+	f->write = archive_filter_lz4_write;
+
+	return (ARCHIVE_OK);
+}
+
+/*
+ * Write data to the out stream.
+ *
+ * Returns ARCHIVE_OK if all data written, error otherwise.
+ */
+static int
+archive_filter_lz4_write(struct archive_write_filter *f,
+    const void *buff, size_t length)
+{
+	struct private_data *data = (struct private_data *)f->data;
+	int ret = ARCHIVE_OK;
+	const char *p;
+	size_t remaining;
+	ssize_t size;
+
+	/* If we haven't written a stream descriptor, we have to do it first. */
+	if (!data->header_written) {
+		ret = lz4_write_stream_descriptor(f);
+		if (ret != ARCHIVE_OK)
+			return (ret);
+		data->header_written = 1;
+	}
+
+	/* Update statistics */
+	data->total_in += length;
+
+	p = (const char *)buff;
+	remaining = length;
+	while (remaining) {
+		size_t l;
+		/* Compress input data to output buffer */
+		size = lz4_write_one_block(f, p, remaining);
+		if (size < ARCHIVE_OK)
+			return (ARCHIVE_FATAL);
+		l = data->out - data->out_buffer;
+		if (l >= data->out_block_size) {
+			ret = __archive_write_filter(f->next_filter,
+			    data->out_buffer, data->out_block_size);
+			l -= data->out_block_size;
+			memcpy(data->out_buffer,
+			    data->out_buffer + data->out_block_size, l);
+			data->out = data->out_buffer + l;
+			if (ret < ARCHIVE_WARN)
+				break;
+		}
+		p += size;
+		remaining -= size;
+	}
+
+	return (ret);
+}
+
+/*
+ * Finish the compression.
+ */
+static int
+archive_filter_lz4_close(struct archive_write_filter *f)
+{
+	struct private_data *data = (struct private_data *)f->data;
+	int ret, r1;
+
+	/* Finish compression cycle. */
+	ret = (int)lz4_write_one_block(f, NULL, 0);
+	if (ret >= 0) {
+		/*
+		 * Write the last block and the end of the stream data.
+		 */
+
+		/* Write End Of Stream. */
+		memset(data->out, 0, 4); data->out += 4;
+		/* Write Stream checksum if needed. */
+		if (data->stream_checksum) {
+			unsigned int checksum;
+			checksum = __archive_xxhash.XXH32_digest(
+					data->xxh32_state);
+			data->xxh32_state = NULL;
+			archive_le32enc(data->out, checksum);
+			data->out += 4;
+		}
+		ret = __archive_write_filter(f->next_filter,
+			    data->out_buffer, data->out - data->out_buffer);
+	}
+
+	r1 = __archive_write_close_filter(f->next_filter);
+	return (r1 < ret ? r1 : ret);
+}
+
+static int
+archive_filter_lz4_free(struct archive_write_filter *f)
+{
+	struct private_data *data = (struct private_data *)f->data;
+
+	if (data->lz4_stream != NULL) {
+		if (data->compression_level < 3)
+#if LZ4_VERSION_MINOR >= 3
+			LZ4_freeStream(data->lz4_stream);
+#else
+			LZ4_free(data->lz4_stream);
+#endif
+		else
+			LZ4_freeHC(data->lz4_stream);
+	}
+	free(data->out_buffer);
+	free(data->in_buffer_allocated);
+	free(data->xxh32_state);
+	free(data);
+	f->data = NULL;
+	return (ARCHIVE_OK);
+}
+
+static int
+lz4_write_stream_descriptor(struct archive_write_filter *f)
+{
+	struct private_data *data = (struct private_data *)f->data;
+	uint8_t *sd;
+
+	sd = (uint8_t *)data->out;
+	/* Write Magic Number. */
+	archive_le32enc(&sd[0], LZ4_MAGICNUMBER);
+	/* FLG */
+	sd[4] = (data->version_number << 6)
+	      | (data->block_independence << 5)
+	      | (data->block_checksum << 4)
+	      | (data->stream_size << 3)
+	      | (data->stream_checksum << 2)
+	      | (data->preset_dictionary << 0);
+	/* BD */
+	sd[5] = (data->block_maximum_size << 4);
+	sd[6] = (__archive_xxhash.XXH32(&sd[4], 2, 0) >> 8) & 0xff;
+	data->out += 7;
+	if (data->stream_checksum)
+		data->xxh32_state = __archive_xxhash.XXH32_init(0);
+	else
+		data->xxh32_state = NULL;
+	return (ARCHIVE_OK);
+}
+
+static ssize_t
+lz4_write_one_block(struct archive_write_filter *f, const char *p,
+    size_t length)
+{
+	struct private_data *data = (struct private_data *)f->data;
+	ssize_t r;
+
+	if (p == NULL) {
+		/* Compress remaining uncompressed data. */
+		if (data->in_buffer == data->in)
+			return 0;
+		else {
+			size_t l = data->in - data->in_buffer;
+			r = drive_compressor(f, data->in_buffer, l);
+			if (r == ARCHIVE_OK)
+				r = (ssize_t)l;
+		}
+	} else if ((data->block_independence || data->compression_level < 3) &&
+	    data->in_buffer == data->in && length >= data->block_size) {
+		r = drive_compressor(f, p, data->block_size);
+		if (r == ARCHIVE_OK)
+			r = (ssize_t)data->block_size;
+	} else {
+		size_t remaining_size = data->in_buffer_size -
+			(data->in - data->in_buffer);
+		size_t l = (remaining_size > length)? length: remaining_size;
+		memcpy(data->in, p, l);
+		data->in += l;
+		if (l == remaining_size) {
+			r = drive_compressor(f, data->in_buffer,
+			    data->block_size);
+			if (r == ARCHIVE_OK)
+				r = (ssize_t)l;
+			data->in = data->in_buffer;
+		} else
+			r = (ssize_t)l;
+	}
+
+	return (r);
+}
+
+
+/*
+ * Utility function to push input data through compressor, writing
+ * full output blocks as necessary.
+ *
+ * Note that this handles both the regular write case (finishing ==
+ * false) and the end-of-archive case (finishing == true).
+ */
+static int
+drive_compressor(struct archive_write_filter *f, const char *p, size_t length)
+{
+	struct private_data *data = (struct private_data *)f->data;
+
+	if (data->stream_checksum)
+		__archive_xxhash.XXH32_update(data->xxh32_state,
+			p, (int)length);
+	if (data->block_independence)
+		return drive_compressor_independence(f, p, length);
+	else
+		return drive_compressor_dependence(f, p, length);
+}
+
+static int
+drive_compressor_independence(struct archive_write_filter *f, const char *p,
+    size_t length)
+{
+	struct private_data *data = (struct private_data *)f->data;
+	unsigned int outsize;
+
+	if (data->compression_level < 4)
+		outsize = LZ4_compress_limitedOutput(p, data->out + 4,
+		    (int)length, (int)data->block_size);
+	else
+		outsize = LZ4_compressHC2_limitedOutput(p, data->out + 4,
+		    (int)length, (int)data->block_size,
+		    data->compression_level);
+
+	if (outsize) {
+		/* The buffer is compressed. */
+		archive_le32enc(data->out, outsize);
+		data->out += 4;
+	} else {
+		/* The buffer is not compressed. The commpressed size was
+		 * bigger than its uncompressed size. */
+		archive_le32enc(data->out, length | 0x80000000);
+		data->out += 4;
+		memcpy(data->out, p, length);
+		outsize = length;
+	}
+	data->out += outsize;
+	if (data->block_checksum) {
+		unsigned int checksum =
+		    __archive_xxhash.XXH32(data->out - outsize, outsize, 0);
+		archive_le32enc(data->out, checksum);
+		data->out += 4;
+	}
+	return (ARCHIVE_OK);
+}
+
+static int
+drive_compressor_dependence(struct archive_write_filter *f, const char *p,
+    size_t length)
+{
+	struct private_data *data = (struct private_data *)f->data;
+	int outsize;
+
+	if (data->compression_level < 3) {
+		if (data->lz4_stream == NULL) {
+			data->lz4_stream = LZ4_createStream();
+			if (data->lz4_stream == NULL) {
+				archive_set_error(f->archive, ENOMEM,
+				    "Can't allocate data for compression"
+				    " buffer");
+				return (ARCHIVE_FATAL);
+			}
+		}
+		outsize = LZ4_compress_limitedOutput_continue(
+		    data->lz4_stream, p, data->out + 4, (int)length,
+		    (int)data->block_size);
+	} else {
+		if (data->lz4_stream == NULL) {
+			data->lz4_stream =
+			    LZ4_createHC(data->in_buffer_allocated);
+			if (data->lz4_stream == NULL) {
+				archive_set_error(f->archive, ENOMEM,
+				    "Can't allocate data for compression"
+				    " buffer");
+				return (ARCHIVE_FATAL);
+			}
+		}
+		outsize = LZ4_compressHC2_limitedOutput_continue(
+		    data->lz4_stream, p, data->out + 4, (int)length,
+		    (int)data->block_size, data->compression_level);
+	}
+
+	if (outsize) {
+		/* The buffer is compressed. */
+		archive_le32enc(data->out, outsize);
+		data->out += 4;
+	} else {
+		/* The buffer is not compressed. The commpressed size was
+		 * bigger than its uncompressed size. */
+		archive_le32enc(data->out, length | 0x80000000);
+		data->out += 4;
+		memcpy(data->out, p, length);
+		outsize = length;
+	}
+	data->out += outsize;
+	if (data->block_checksum) {
+		unsigned int checksum =
+		    __archive_xxhash.XXH32(data->out - outsize, outsize, 0);
+		archive_le32enc(data->out, checksum);
+		data->out += 4;
+	}
+
+	if (length == data->block_size) {
+#define DICT_SIZE	(64 * 1024)
+		if (data->compression_level < 3)
+			LZ4_saveDict(data->lz4_stream,
+			    data->in_buffer_allocated, DICT_SIZE);
+		else {
+			LZ4_slideInputBufferHC(data->lz4_stream);
+			data->in_buffer = data->in_buffer_allocated + DICT_SIZE;
+		}
+#undef DICT_SIZE
+	}
+	return (ARCHIVE_OK);
+}
+
+#else /* HAVE_LIBLZ4 */
+
+static int
+archive_filter_lz4_open(struct archive_write_filter *f)
+{
+	struct private_data *data = (struct private_data *)f->data;
+	struct archive_string as;
+	int r;
+
+	archive_string_init(&as);
+	archive_strcpy(&as, "lz4 -z -q -q");
+
+	/* Specify a compression level. */
+	if (data->compression_level > 0) {
+		archive_strcat(&as, " -");
+		archive_strappend_char(&as, '0' + data->compression_level);
+	}
+	/* Specify a block size. */
+	archive_strcat(&as, " -B");
+	archive_strappend_char(&as, '0' + data->block_maximum_size);
+
+	if (data->block_checksum)
+		archive_strcat(&as, " -BX");
+	if (data->stream_checksum == 0)
+		archive_strcat(&as, " -Sx");
+	if (data->block_independence == 0)
+		archive_strcat(&as, " -BD");
+
+	f->write = archive_filter_lz4_write;
+
+	r = __archive_write_program_open(f, data->pdata, as.s);
+	archive_string_free(&as);
+	return (r);
+}
+
+static int
+archive_filter_lz4_write(struct archive_write_filter *f, const void *buff,
+    size_t length)
+{
+	struct private_data *data = (struct private_data *)f->data;
+
+	return __archive_write_program_write(f, data->pdata, buff, length);
+}
+
+static int
+archive_filter_lz4_close(struct archive_write_filter *f)
+{
+	struct private_data *data = (struct private_data *)f->data;
+
+	return __archive_write_program_close(f, data->pdata);
+}
+
+static int
+archive_filter_lz4_free(struct archive_write_filter *f)
+{
+	struct private_data *data = (struct private_data *)f->data;
+
+	__archive_write_program_free(data->pdata);
+	free(data);
+	return (ARCHIVE_OK);
+}
+
+#endif /* HAVE_LIBLZ4 */
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_xz.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_xz.c
index a566732..4f849ce 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_xz.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_xz.c
@@ -100,6 +100,7 @@ archive_write_add_filter_lzip(struct archive *a)
 
 struct private_data {
 	int		 compression_level;
+	uint32_t	 threads;
 	lzma_stream	 stream;
 	lzma_filter	 lzmafilters[2];
 	lzma_options_lzma lzma_opt;
@@ -151,6 +152,7 @@ common_setup(struct archive_write_filter *f)
 	}
 	f->data = data;
 	data->compression_level = LZMA_PRESET_DEFAULT;
+	data->threads = 1;
 	f->open = &archive_compressor_xz_open;
 	f->close = archive_compressor_xz_close;
 	f->free = archive_compressor_xz_free;
@@ -221,23 +223,37 @@ archive_compressor_xz_init_stream(struct archive_write_filter *f,
 {
 	static const lzma_stream lzma_stream_init_data = LZMA_STREAM_INIT;
 	int ret;
+#ifdef HAVE_LZMA_STREAM_ENCODER_MT
+	lzma_mt mt_options;
+#endif
 
 	data->stream = lzma_stream_init_data;
 	data->stream.next_out = data->compressed;
 	data->stream.avail_out = data->compressed_buffer_size;
-	if (f->code == ARCHIVE_FILTER_XZ)
-		ret = lzma_stream_encoder(&(data->stream),
-		    data->lzmafilters, LZMA_CHECK_CRC64);
-	else if (f->code == ARCHIVE_FILTER_LZMA)
+	if (f->code == ARCHIVE_FILTER_XZ) {
+#ifdef HAVE_LZMA_STREAM_ENCODER_MT
+		if (data->threads != 1) {
+			bzero(&mt_options, sizeof(mt_options));
+			mt_options.threads = data->threads;
+			mt_options.timeout = 300;
+			mt_options.filters = data->lzmafilters;
+			mt_options.check = LZMA_CHECK_CRC64;
+			ret = lzma_stream_encoder_mt(&(data->stream),
+			    &mt_options);
+		} else
+#endif
+			ret = lzma_stream_encoder(&(data->stream),
+			    data->lzmafilters, LZMA_CHECK_CRC64);
+	} else if (f->code == ARCHIVE_FILTER_LZMA) {
 		ret = lzma_alone_encoder(&(data->stream), &data->lzma_opt);
-	else {	/* ARCHIVE_FILTER_LZIP */
+	} else {	/* ARCHIVE_FILTER_LZIP */
 		int dict_size = data->lzma_opt.dict_size;
 		int ds, log2dic, wedges;
 
 		/* Calculate a coded dictionary size */
 		if (dict_size < (1 << 12) || dict_size > (1 << 27)) {
 			archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
-			    "Unacceptable dictionary dize for lzip: %d",
+			    "Unacceptable dictionary size for lzip: %d",
 			    dict_size);
 			return (ARCHIVE_FATAL);
 		}
@@ -373,6 +389,22 @@ archive_compressor_xz_options(struct archive_write_filter *f,
 		if (data->compression_level > 6)
 			data->compression_level = 6;
 		return (ARCHIVE_OK);
+	} else if (strcmp(key, "threads") == 0) {
+		if (value == NULL)
+			return (ARCHIVE_WARN);
+		data->threads = (int)strtoul(value, NULL, 10);
+		if (data->threads == 0 && errno != 0) {
+			data->threads = 1;
+			return (ARCHIVE_WARN);
+		}
+		if (data->threads == 0) {
+#ifdef HAVE_LZMA_STREAM_ENCODER_MT
+			data->threads = lzma_cputhreads();
+#else
+			data->threads = 1;
+#endif
+		}
+		return (ARCHIVE_OK);
 	}
 
 	/* Note: The "warn" return is just to inform the options
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_data.3 b/Utilities/cmlibarchive/libarchive/archive_write_data.3
index cfd5cd5..0cdd25f 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_data.3
+++ b/Utilities/cmlibarchive/libarchive/archive_write_data.3
@@ -34,7 +34,7 @@
 Streaming Archive Library (libarchive, -larchive)
 .Sh SYNOPSIS
 .In archive.h
-.Ft ssize_t
+.Ft la_ssize_t
 .Fn archive_write_data "struct archive *" "const void *" "size_t"
 .Sh DESCRIPTION
 Write data corresponding to the header just written.
@@ -42,8 +42,7 @@ Write data corresponding to the header just written.
 .\"
 .Sh RETURN VALUES
 This function returns the number of bytes actually written, or
-.Li -1
-on error.
+a negative error code on error.
 .\"
 .Sh ERRORS
 Detailed error codes and textual descriptions are available from the
@@ -52,6 +51,15 @@ and
 .Fn archive_error_string
 functions.
 .\"
+.Sh BUGS
+In libarchive 3.x, this function sometimes returns
+zero on success instead of returning the number of bytes written.
+Specifically, this occurs when writing to an
+.Vt archive_write_disk
+handle.
+Clients should treat any value less than zero as an error
+and consider any non-negative value as success.
+.\"
 .Sh SEE ALSO
 .Xr tar 1 ,
 .Xr libarchive 3 ,
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk.3 b/Utilities/cmlibarchive/libarchive/archive_write_disk.3
index fa925cc..ba6c970 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_disk.3
+++ b/Utilities/cmlibarchive/libarchive/archive_write_disk.3
@@ -70,9 +70,9 @@ Streaming Archive Library (libarchive, -larchive)
 .Fc
 .Ft int
 .Fn archive_write_header "struct archive *" "struct archive_entry *"
-.Ft ssize_t
+.Ft la_ssize_t
 .Fn archive_write_data "struct archive *" "const void *" "size_t"
-.Ft ssize_t
+.Ft la_ssize_t
 .Fn archive_write_data_block "struct archive *" "const void *" "size_t size" "int64_t offset"
 .Ft int
 .Fn archive_write_finish_entry "struct archive *"
@@ -177,10 +177,16 @@ The default is to not refuse such paths.
 Note that paths ending in
 .Pa ..
 always cause an error, regardless of this flag.
+.It Cm ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS
+Refuse to extract an absolute path.
+The default is to not refuse such paths.
 .It Cm ARCHIVE_EXTRACT_SPARSE
 Scan data for blocks of NUL bytes and try to recreate them with holes.
 This results in sparse files, independent of whether the archive format
 supports or uses them.
+.It Cm ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS
+Before removing a file system object prior to replacing it, clear
+platform-specific file flags which might prevent its removal.
 .El
 .It Xo
 .Fn archive_write_disk_set_group_lookup ,
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c
index a3d350b..450ac75 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c
@@ -343,6 +343,7 @@ static int	restore_entry(struct archive_write_disk *);
 static int	set_mac_metadata(struct archive_write_disk *, const char *,
 				 const void *, size_t);
 static int	set_xattrs(struct archive_write_disk *);
+static int	clear_nochange_fflags(struct archive_write_disk *);
 static int	set_fflags(struct archive_write_disk *);
 static int	set_fflags_platform(struct archive_write_disk *, int fd,
 		    const char *name, mode_t mode,
@@ -1467,10 +1468,14 @@ _archive_write_disk_data_block(struct archive *_a,
 		return (r);
 	if ((size_t)r < size) {
 		archive_set_error(&a->archive, 0,
-		    "Write request too large");
+		    "Too much data: Truncating file at %ju bytes", (uintmax_t)a->filesize);
 		return (ARCHIVE_WARN);
 	}
+#if ARCHIVE_VERSION_NUMBER < 3999000
 	return (ARCHIVE_OK);
+#else
+	return (size);
+#endif
 }
 
 static ssize_t
@@ -1842,6 +1847,8 @@ restore_entry(struct archive_write_disk *a)
 		 * object is a dir, but that doesn't mean the old
 		 * object isn't a dir.
 		 */
+		if (a->flags & ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS)
+			(void)clear_nochange_fflags(a);
 		if (unlink(a->name) == 0) {
 			/* We removed it, reset cached stat. */
 			a->pst = NULL;
@@ -1869,6 +1876,13 @@ restore_entry(struct archive_write_disk *a)
 		en = create_filesystem_object(a);
 	}
 
+	if ((en == ENOENT) && (archive_entry_hardlink(a->entry) != NULL)) {
+		archive_set_error(&a->archive, en,
+		    "Hard-link target '%s' does not exist.",
+		    archive_entry_hardlink(a->entry));
+		return (ARCHIVE_FAILED);
+	}
+
 	if ((en == EISDIR || en == EEXIST)
 	    && (a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) {
 		/* If we're not overwriting, we're done. */
@@ -1940,6 +1954,8 @@ restore_entry(struct archive_write_disk *a)
 
 		if (!S_ISDIR(a->st.st_mode)) {
 			/* A non-dir is in the way, unlink it. */
+			if (a->flags & ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS)
+				(void)clear_nochange_fflags(a);
 			if (unlink(a->name) != 0) {
 				archive_set_error(&a->archive, errno,
 				    "Can't unlink already-existing object");
@@ -1950,6 +1966,8 @@ restore_entry(struct archive_write_disk *a)
 			en = create_filesystem_object(a);
 		} else if (!S_ISDIR(a->mode)) {
 			/* A dir is in the way of a non-dir, rmdir it. */
+			if (a->flags & ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS)
+				(void)clear_nochange_fflags(a);
 			if (rmdir(a->name) != 0) {
 				archive_set_error(&a->archive, errno,
 				    "Can't replace existing directory with non-directory");
@@ -2505,8 +2523,9 @@ cleanup_pathname_win(struct archive_write_disk *a)
 /*
  * Canonicalize the pathname.  In particular, this strips duplicate
  * '/' characters, '.' elements, and trailing '/'.  It also raises an
- * error for an empty path, a trailing '..' or (if _SECURE_NODOTDOT is
- * set) any '..' in the path.
+ * error for an empty path, a trailing '..', (if _SECURE_NODOTDOT is
+ * set) any '..' in the path or (if ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS
+ * is set) if the path is absolute.
  */
 static int
 cleanup_pathname(struct archive_write_disk *a)
@@ -2525,8 +2544,15 @@ cleanup_pathname(struct archive_write_disk *a)
 	cleanup_pathname_win(a);
 #endif
 	/* Skip leading '/'. */
-	if (*src == '/')
+	if (*src == '/') {
+		if (a->flags & ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS) {
+			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+			                  "Path is absolute");
+			return (ARCHIVE_FAILED);
+		}
+
 		separator = *src++;
+	}
 
 	/* Scan the pathname one element at a time. */
 	for (;;) {
@@ -3056,9 +3082,23 @@ set_mode(struct archive_write_disk *a, int mode)
 		 * impact.
 		 */
 		if (lchmod(a->name, mode) != 0) {
-			archive_set_error(&a->archive, errno,
-			    "Can't set permissions to 0%o", (int)mode);
-			r = ARCHIVE_WARN;
+			switch (errno) {
+			case ENOTSUP:
+			case ENOSYS:
+#if ENOTSUP != EOPNOTSUPP
+			case EOPNOTSUPP:
+#endif
+				/*
+				 * if lchmod is defined but the platform
+				 * doesn't support it, silently ignore
+				 * error
+				 */
+				break;
+			default:
+				archive_set_error(&a->archive, errno,
+				    "Can't set permissions to 0%o", (int)mode);
+				r = ARCHIVE_WARN;
+			}
 		}
 #endif
 	} else if (!S_ISDIR(a->mode)) {
@@ -3159,6 +3199,36 @@ set_fflags(struct archive_write_disk *a)
 	return (ARCHIVE_OK);
 }
 
+static int
+clear_nochange_fflags(struct archive_write_disk *a)
+{
+	int		nochange_flags;
+	mode_t		mode = archive_entry_mode(a->entry);
+
+	/* Hopefully, the compiler will optimize this mess into a constant. */
+	nochange_flags = 0;
+#ifdef SF_IMMUTABLE
+	nochange_flags |= SF_IMMUTABLE;
+#endif
+#ifdef UF_IMMUTABLE
+	nochange_flags |= UF_IMMUTABLE;
+#endif
+#ifdef SF_APPEND
+	nochange_flags |= SF_APPEND;
+#endif
+#ifdef UF_APPEND
+	nochange_flags |= UF_APPEND;
+#endif
+#ifdef EXT2_APPEND_FL
+	nochange_flags |= EXT2_APPEND_FL;
+#endif
+#ifdef EXT2_IMMUTABLE_FL
+	nochange_flags |= EXT2_IMMUTABLE_FL;
+#endif
+
+	return (set_fflags_platform(a, a->fd, a->name, mode, 0, nochange_flags));
+}
+
 
 #if ( defined(HAVE_LCHFLAGS) || defined(HAVE_CHFLAGS) || defined(HAVE_FCHFLAGS) ) && defined(HAVE_STRUCT_STAT_ST_FLAGS)
 /*
@@ -3366,6 +3436,7 @@ copy_xattrs(struct archive_write_disk *a, int tmpfd, int dffd)
 	}
 	for (xattr_i = 0; xattr_i < xattr_size;
 	    xattr_i += strlen(xattr_names + xattr_i) + 1) {
+		char *xattr_val_saved;
 		ssize_t s;
 		int f;
 
@@ -3376,11 +3447,13 @@ copy_xattrs(struct archive_write_disk *a, int tmpfd, int dffd)
 			ret = ARCHIVE_WARN;
 			goto exit_xattr;
 		}
+		xattr_val_saved = xattr_val;
 		xattr_val = realloc(xattr_val, s);
 		if (xattr_val == NULL) {
 			archive_set_error(&a->archive, ENOMEM,
 			    "Failed to get metadata(xattr)");
 			ret = ARCHIVE_WARN;
+			free(xattr_val_saved);
 			goto exit_xattr;
 		}
 		s = fgetxattr(tmpfd, xattr_names + xattr_i, xattr_val, s, 0, 0);
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_set_standard_lookup.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_set_standard_lookup.c
index e79008e..3b868fb 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_disk_set_standard_lookup.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_set_standard_lookup.c
@@ -67,7 +67,7 @@ static void	cleanup(void *);
  * a simple cache to accelerate such lookups---into the archive_write_disk
  * object.  This is in a separate file because getpwnam()/getgrnam()
  * can pull in a LOT of library code (including NIS/LDAP functions, which
- * pull in DNS resolveers, etc).  This can easily top 500kB, which makes
+ * pull in DNS resolvers, etc).  This can easily top 500kB, which makes
  * it inappropriate for some space-constrained applications.
  *
  * Applications that are size-sensitive may want to just use the
@@ -86,6 +86,11 @@ archive_write_disk_set_standard_lookup(struct archive *a)
 {
 	struct bucket *ucache = malloc(cache_size * sizeof(struct bucket));
 	struct bucket *gcache = malloc(cache_size * sizeof(struct bucket));
+	if (ucache == NULL || gcache == NULL) {
+		free(ucache);
+		free(gcache);
+		return (ARCHIVE_FATAL);
+	}
 	memset(ucache, 0, cache_size * sizeof(struct bucket));
 	memset(gcache, 0, cache_size * sizeof(struct bucket));
 	archive_write_disk_set_group_lookup(a, gcache, lookup_gid, cleanup);
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c
index ed62009..800aa89 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c
@@ -330,8 +330,6 @@ file_information(struct archive_write_disk *a, wchar_t *path,
 				break;
 			case L'C': case L'c':
 				if (((p[2] == L'M' || p[2] == L'm' ) &&
-				    (p[3] == L'D' || p[3] == L'd' )) ||
-				    ((p[2] == L'M' || p[2] == L'm' ) &&
 				    (p[3] == L'D' || p[3] == L'd' )))
 					*mode |= S_IXUSR | S_IXGRP | S_IXOTH;
 				break;
@@ -1011,7 +1009,11 @@ _archive_write_disk_data_block(struct archive *_a,
 		    "Write request too large");
 		return (ARCHIVE_WARN);
 	}
+#if ARCHIVE_VERSION_NUMBER < 3999000
 	return (ARCHIVE_OK);
+#else
+	return (size);
+#endif
 }
 
 static ssize_t
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_filter.3 b/Utilities/cmlibarchive/libarchive/archive_write_filter.3
index 3ca248b..83bd2c6 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_filter.3
+++ b/Utilities/cmlibarchive/libarchive/archive_write_filter.3
@@ -24,46 +24,62 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd February 2, 2012
+.Dd August 14, 2014
 .Dt ARCHIVE_WRITE_FILTER 3
 .Os
 .Sh NAME
+.Nm archive_write_add_filter_b64encode ,
 .Nm archive_write_add_filter_bzip2 ,
 .Nm archive_write_add_filter_compress ,
 .Nm archive_write_add_filter_gzip ,
+.Nm archive_write_add_filter_lz4 ,
 .Nm archive_write_add_filter_lzip ,
 .Nm archive_write_add_filter_lzma ,
+.Nm archive_write_add_filter_lzop ,
 .Nm archive_write_add_filter_none ,
 .Nm archive_write_add_filter_program ,
+.Nm archive_write_add_filter_uuencode ,
 .Nm archive_write_add_filter_xz
 .Sh LIBRARY
 Streaming Archive Library (libarchive, -larchive)
 .Sh SYNOPSIS
 .In archive.h
 .Ft int
+.Fn archive_write_add_filter_b64encode "struct archive *"
+.Ft int
 .Fn archive_write_add_filter_bzip2 "struct archive *"
 .Ft int
 .Fn archive_write_add_filter_compress "struct archive *"
 .Ft int
 .Fn archive_write_add_filter_gzip "struct archive *"
 .Ft int
+.Fn archive_write_add_filter_lz4 "struct archive *"
+.Ft int
 .Fn archive_write_add_filter_lzip "struct archive *"
 .Ft int
 .Fn archive_write_add_filter_lzma "struct archive *"
 .Ft int
+.Fn archive_write_add_filter_lzop "struct archive *"
+.Ft int
 .Fn archive_write_add_filter_none "struct archive *"
 .Ft int
 .Fn archive_write_add_filter_program "struct archive *" "const char * cmd"
 .Ft int
+.Fn archive_write_add_filter_uuencode "struct archive *"
+.Ft int
 .Fn archive_write_add_filter_xz "struct archive *"
 .Sh DESCRIPTION
 .Bl -tag -width indent
 .It Xo
+.Fn archive_write_add_filter_b64encode ,
 .Fn archive_write_add_filter_bzip2 ,
 .Fn archive_write_add_filter_compress ,
 .Fn archive_write_add_filter_gzip ,
+.Fn archive_write_add_filter_lz4 ,
 .Fn archive_write_add_filter_lzip ,
 .Fn archive_write_add_filter_lzma ,
+.Fn archive_write_add_filter_lzop ,
+.Fn archive_write_add_filter_uuencode ,
 .Fn archive_write_add_filter_xz ,
 .Xc
 The resulting archive will be compressed as specified.
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3 b/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3
index d881c80..c5ef69e 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3
+++ b/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3
@@ -41,7 +41,7 @@ Close out the entry just written.
 In particular, this writes out the final padding required by some formats.
 Ordinarily, clients never need to call this, as it
 is called automatically by
-.Fn archive_write_next_header
+.Fn archive_write_header
 and
 .Fn archive_write_close
 as needed.
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_format.3 b/Utilities/cmlibarchive/libarchive/archive_write_format.3
index 39d3006..4bd1163 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_format.3
+++ b/Utilities/cmlibarchive/libarchive/archive_write_format.3
@@ -34,7 +34,9 @@
 .Nm archive_write_set_format_raw ,
 .Nm archive_write_set_format_shar ,
 .Nm archive_write_set_format_shar_dump ,
-.Nm archive_write_set_format_ustar
+.Nm archive_write_set_format_ustar ,
+.Nm archive_write_set_format_filter_by_ext ,
+.Nm archive_write_set_format_filter_by_ext_def
 .Nd functions for creating archives
 .Sh LIBRARY
 Streaming Archive Library (libarchive, -larchive)
@@ -54,6 +56,10 @@ Streaming Archive Library (libarchive, -larchive)
 .Fn archive_write_set_format_shar_dump "struct archive *"
 .Ft int
 .Fn archive_write_set_format_ustar "struct archive *"
+.Ft int
+.Fn archive_write_set_format_filter_by_ext "struct archive *" "const char *"
+.Ft int
+.Fn archive_write_set_format_filter_by_ext_def "struct archive *" "const char *" "const char *"
 .Sh DESCRIPTION
 These functions set the format that will be used for the archive.
 .Pp
@@ -79,6 +85,14 @@ filenames, linknames, uids, sizes, etc.
 is the library default; this is the same as pax format, but suppresses
 the pax extended header for most normal files.
 In most cases, this will result in ordinary ustar archives.
+.Bl -tag -width indent
+.It Xo
+.Fn archive_write_set_format_filter_by_ext ,
+.Fn archive_write_set_format_filter_by_ext_def
+.Xc
+Format and filter for archive can be set automatically, based on output file name extension.
+The functions are platform dependent.
+Supported extensions: .7z, .zip, .jar, .cpio, .iso, .a, .ar, .tar, .tgz, .tar.gz, .tar.bz2, .tar.xz
 .\"
 .Sh RETURN VALUES
 These functions return
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_open.3 b/Utilities/cmlibarchive/libarchive/archive_write_open.3
index 4037248..a52959b 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_open.3
+++ b/Utilities/cmlibarchive/libarchive/archive_write_open.3
@@ -154,7 +154,7 @@ to register an error code and message and return
 .Cm ARCHIVE_FATAL .
 .Bl -item -offset indent
 .It
-.Ft typedef ssize_t
+.Ft typedef la_ssize_t
 .Fo archive_write_callback
 .Fa "struct archive *"
 .Fa "void *client_data"
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_open_filename.c b/Utilities/cmlibarchive/libarchive/archive_write_open_filename.c
index 196b770..66e0dfe 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_open_filename.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_open_filename.c
@@ -243,7 +243,10 @@ file_close(struct archive *a, void *client_data)
 	struct write_file_data	*mine = (struct write_file_data *)client_data;
 
 	(void)a; /* UNUSED */
-	close(mine->fd);
+
+	if (mine->fd >= 0)
+		close(mine->fd);
+
 	archive_mstring_clean(&mine->filename);
 	free(mine);
 	return (ARCHIVE_OK);
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_private.h b/Utilities/cmlibarchive/libarchive/archive_write_private.h
index e600d54..0c3cc0c 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_private.h
+++ b/Utilities/cmlibarchive/libarchive/archive_write_private.h
@@ -26,8 +26,10 @@
  */
 
 #ifndef __LIBARCHIVE_BUILD
+#ifndef __LIBARCHIVE_TEST
 #error This header is only to be used internally to libarchive.
 #endif
+#endif
 
 #ifndef ARCHIVE_WRITE_PRIVATE_H_INCLUDED
 #define	ARCHIVE_WRITE_PRIVATE_H_INCLUDED
@@ -116,6 +118,14 @@ struct archive_write {
 		    const void *buff, size_t);
 	int	(*format_close)(struct archive_write *);
 	int	(*format_free)(struct archive_write *);
+
+
+	/*
+	 * Encryption passphrase.
+	 */
+	char		*passphrase;
+	archive_passphrase_callback *passphrase_callback;
+	void		*passphrase_client_data;
 };
 
 /*
@@ -142,4 +152,9 @@ int	__archive_write_program_close(struct archive_write_filter *,
 	    struct archive_write_program_data *);
 int	__archive_write_program_write(struct archive_write_filter *,
 	    struct archive_write_program_data *, const void *, size_t);
+
+/*
+ * Get a encryption passphrase.
+ */
+const char * __archive_write_get_passphrase(struct archive_write *a);
 #endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format.c
index 9055753..744302d 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_set_format.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format.c
@@ -57,6 +57,7 @@ struct { int code; int (*setter)(struct archive *); } codes[] =
 	{ ARCHIVE_FORMAT_TAR_PAX_RESTRICTED,
 				archive_write_set_format_pax_restricted },
 	{ ARCHIVE_FORMAT_TAR_USTAR,	archive_write_set_format_ustar },
+	{ ARCHIVE_FORMAT_WARC,		archive_write_set_format_warc },
 	{ ARCHIVE_FORMAT_XAR,		archive_write_set_format_xar },
 	{ ARCHIVE_FORMAT_ZIP,		archive_write_set_format_zip },
 	{ 0,		NULL }
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c
index 4f3ce7d..a2ce7c6 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c
@@ -70,6 +70,7 @@ struct { const char *name; int (*setter)(struct archive *); } names[] =
 	{ "ustar",	archive_write_set_format_ustar },
 	{ "v7tar",	archive_write_set_format_v7tar },
 	{ "v7",		archive_write_set_format_v7tar },
+	{ "warc",	archive_write_set_format_warc },
 	{ "xar",	archive_write_set_format_xar },
 	{ "zip",	archive_write_set_format_zip },
 	{ NULL,		NULL }
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_filter_by_ext.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_filter_by_ext.c
new file mode 100644
index 0000000..adec9b2
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_filter_by_ext.c
@@ -0,0 +1,142 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2015 Okhotnikov Kirill
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "archive_platform.h"
+__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_by_name.c 201168 2009-12-29 06:15:32Z kientzle $");
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_private.h"
+
+/* A table that maps names to functions. */
+static
+struct { const char *name; int (*format)(struct archive *); int (*filter)(struct archive *);  } names[] =
+{
+	{ ".7z",	archive_write_set_format_7zip,            archive_write_add_filter_none},
+	{ ".zip",	archive_write_set_format_zip,             archive_write_add_filter_none},
+	{ ".jar",	archive_write_set_format_zip,             archive_write_add_filter_none},
+	{ ".cpio",	archive_write_set_format_cpio,            archive_write_add_filter_none},
+	{ ".iso",	archive_write_set_format_iso9660,         archive_write_add_filter_none},
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
+	{ ".a",	        archive_write_set_format_ar_bsd,          archive_write_add_filter_none},
+	{ ".ar",	archive_write_set_format_ar_bsd,          archive_write_add_filter_none},
+#else         
+	{ ".a",	        archive_write_set_format_ar_svr4,         archive_write_add_filter_none},
+	{ ".ar",	archive_write_set_format_ar_svr4,         archive_write_add_filter_none},
+#endif        
+	{ ".tar",	archive_write_set_format_pax_restricted,  archive_write_add_filter_none},
+	{ ".tgz",	archive_write_set_format_pax_restricted,  archive_write_add_filter_gzip},
+	{ ".tar.gz",	archive_write_set_format_pax_restricted,  archive_write_add_filter_gzip},
+	{ ".tar.bz2",	archive_write_set_format_pax_restricted,  archive_write_add_filter_bzip2},
+	{ ".tar.xz",	archive_write_set_format_pax_restricted,  archive_write_add_filter_xz},
+	{ NULL,		NULL,                             NULL }
+};
+
+static 
+int cmpsuff(const char *str, const char *suffix)
+{
+  size_t length_str, length_suffix;
+
+  if ((str == NULL) || (suffix == NULL))
+    return -1;
+
+  length_str = strlen(str);
+  length_suffix = strlen(suffix);
+
+  if (length_str >= length_suffix) {
+    return strcmp(str + (length_str - length_suffix), suffix);
+  } else {
+    return -1;
+  }
+}
+
+static int get_array_index(const char *name)
+{
+  int i;
+
+  for (i = 0; names[i].name != NULL; i++) 
+  {
+    if (cmpsuff(name, names[i].name) == 0)
+      return i;
+  }    
+  return -1;
+  
+}
+
+int
+archive_write_set_format_filter_by_ext(struct archive *a, const char *filename)
+{
+  int names_index = get_array_index(filename);
+  
+  if (names_index >= 0)
+  {  
+    int format_state = (names[names_index].format)(a);
+    if (format_state == ARCHIVE_OK)
+      return ((names[names_index].filter)(a));
+    else
+      return format_state;
+  }    
+
+  archive_set_error(a, EINVAL, "No such format '%s'", filename);
+  a->state = ARCHIVE_STATE_FATAL;
+  return (ARCHIVE_FATAL);
+}
+
+int
+archive_write_set_format_filter_by_ext_def(struct archive *a, const char *filename, const char * def_ext)
+{
+  int names_index = get_array_index(filename);
+  
+  if (names_index < 0)
+    names_index = get_array_index(def_ext);
+  
+  if (names_index >= 0)
+  {  
+    int format_state = (names[names_index].format)(a);
+    if (format_state == ARCHIVE_OK)
+      return ((names[names_index].filter)(a));
+    else
+      return format_state;
+  }    
+
+  archive_set_error(a, EINVAL, "No such format '%s'", filename);
+  a->state = ARCHIVE_STATE_FATAL;
+  return (ARCHIVE_FATAL);
+}
+
+
+
+
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_iso9660.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_iso9660.c
index e722625..576f4c2 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_iso9660.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_iso9660.c
@@ -2719,6 +2719,16 @@ extra_get_record(struct isoent *isoent, int *space, int *off, int *loc)
 			rec->offset = 0;
 			/* Insert `rec` into the tail of isoent->extr_rec_list */
 			rec->next = NULL;
+			/*
+			 * Note: testing isoent->extr_rec_list.last == NULL
+			 * here is really unneeded since it has been already
+			 * initialized at isoent_new function but Clang Static
+			 * Analyzer claims that it is dereference of null
+			 * pointer.
+			 */
+			if (isoent->extr_rec_list.last == NULL)
+				isoent->extr_rec_list.last =
+					&(isoent->extr_rec_list.first);
 			*isoent->extr_rec_list.last = rec;
 			isoent->extr_rec_list.last = &(rec->next);
 		}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c
index b0c8018..b686303 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c
@@ -35,7 +35,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_mtree.c 201171
 #include <string.h>
 
 #include "archive.h"
-#include "archive_crypto_private.h"
+#include "archive_digest_private.h"
 #include "archive_entry.h"
 #include "archive_private.h"
 #include "archive_rb.h"
@@ -639,7 +639,7 @@ attr_counter_inc(struct attr_counter **top, struct attr_counter *ac,
 			*top = ac;
 			ac->next->prev = ac;
 		}
-	} else {
+	} else if (last != NULL) {
 		ac = attr_counter_new(me, last);
 		if (ac == NULL)
 			return (-1);
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_warc.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_warc.c
new file mode 100644
index 0000000..80abc6f
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_warc.c
@@ -0,0 +1,439 @@
+/*-
+ * Copyright (c) 2014 Sebastian Freundt
+ * Author: Sebastian Freundt  <devel at fresse.org>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "archive_platform.h"
+__FBSDID("$FreeBSD$");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_entry_locale.h"
+#include "archive_private.h"
+#include "archive_random_private.h"
+#include "archive_write_private.h"
+
+struct warc_s {
+	unsigned int omit_warcinfo:1;
+
+	time_t now;
+	mode_t typ;
+	unsigned int rng;
+	/* populated size */
+	uint64_t populz;
+};
+
+static const char warcinfo[] =
+    "software: libarchive/" ARCHIVE_VERSION_ONLY_STRING "\r\n"
+    "format: WARC file version 1.0\r\n";
+
+typedef enum {
+	WT_NONE,
+	/* warcinfo */
+	WT_INFO,
+	/* metadata */
+	WT_META,
+	/* resource */
+	WT_RSRC,
+	/* request, unsupported */
+	WT_REQ,
+	/* response, unsupported */
+	WT_RSP,
+	/* revisit, unsupported */
+	WT_RVIS,
+	/* conversion, unsupported */
+	WT_CONV,
+	/* continutation, unsupported at the moment */
+	WT_CONT,
+	/* invalid type */
+	LAST_WT
+} warc_type_t;
+
+typedef struct {
+	warc_type_t type;
+	const char *tgturi;
+	const char *recid;
+	time_t rtime;
+	time_t mtime;
+	const char *cnttyp;
+	uint64_t cntlen;
+} warc_essential_hdr_t;
+
+typedef struct {
+	unsigned int u[4U];
+} warc_uuid_t;
+
+static int _warc_options(struct archive_write*, const char *key, const char *v);
+static int _warc_header(struct archive_write *a, struct archive_entry *entry);
+static ssize_t _warc_data(struct archive_write *a, const void *buf, size_t sz);
+static int _warc_finish_entry(struct archive_write *a);
+static int _warc_close(struct archive_write *a);
+static int _warc_free(struct archive_write *a);
+
+/* private routines */
+static ssize_t _popul_ehdr(struct archive_string *t, size_t z, warc_essential_hdr_t);
+static int _gen_uuid(warc_uuid_t *tgt);
+
+

+/*
+ * Set output format to ISO 28500 (aka WARC) format.
+ */
+int
+archive_write_set_format_warc(struct archive *_a)
+{
+	struct archive_write *a = (struct archive_write *)_a;
+	struct warc_s *w;
+
+	archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
+	    ARCHIVE_STATE_NEW, "archive_write_set_format_warc");
+
+	/* If another format was already registered, unregister it. */
+	if (a->format_free != NULL) {
+		(a->format_free)(a);
+	}
+
+	w = malloc(sizeof(*w));
+	if (w == NULL) {
+		archive_set_error(&a->archive, ENOMEM,
+		    "Can't allocate warc data");
+		return (ARCHIVE_FATAL);
+	}
+	/* by default we're emitting a file wide header */
+	w->omit_warcinfo = 0U;
+	/* obtain current time for date fields */
+	w->now = time(NULL);
+	/* reset file type info */
+	w->typ = 0;
+	/* also initialise our rng */
+	w->rng = (unsigned int)w->now;
+
+	a->format_data = w;
+	a->format_name = "WARC/1.0";
+	a->format_options = _warc_options;
+	a->format_write_header = _warc_header;
+	a->format_write_data = _warc_data;
+	a->format_close = _warc_close;
+	a->format_free = _warc_free;
+	a->format_finish_entry = _warc_finish_entry;
+	a->archive.archive_format = ARCHIVE_FORMAT_WARC;
+	a->archive.archive_format_name = "WARC/1.0";
+	return (ARCHIVE_OK);
+}
+
+

+/* archive methods */
+static int
+_warc_options(struct archive_write *a, const char *key, const char *val)
+{
+	struct warc_s *w = a->format_data;
+
+	if (strcmp(key, "omit-warcinfo") == 0) {
+		if (val == NULL || strcmp(val, "true") == 0) {
+			/* great */
+			w->omit_warcinfo = 1U;
+			return (ARCHIVE_OK);
+		}
+	}
+
+	/* Note: The "warn" return is just to inform the options
+	 * supervisor that we didn't handle it.  It will generate
+	 * a suitable error if no one used this option. */
+	return (ARCHIVE_WARN);
+}
+
+static int
+_warc_header(struct archive_write *a, struct archive_entry *entry)
+{
+	struct warc_s *w = a->format_data;
+	struct archive_string hdr;
+#define MAX_HDR_SIZE 512
+
+	/* check whether warcinfo record needs outputting */
+	if (!w->omit_warcinfo) {
+		warc_essential_hdr_t wi = {
+			WT_INFO,
+			/*uri*/NULL,
+			/*urn*/NULL,
+			/*rtm*/w->now,
+			/*mtm*/w->now,
+			/*cty*/"application/warc-fields",
+			/*len*/sizeof(warcinfo) - 1U,
+		};
+		ssize_t r;
+
+		archive_string_init(&hdr);
+		r = _popul_ehdr(&hdr, MAX_HDR_SIZE, wi);
+		if (r >= 0) {
+			/* jackpot! */
+			/* now also use HDR buffer for the actual warcinfo */
+			archive_strncat(&hdr, warcinfo, sizeof(warcinfo) -1);
+
+			/* append end-of-record indicator */
+			archive_strncat(&hdr, "\r\n\r\n", 4);
+
+			/* write to output stream */
+			__archive_write_output(a, hdr.s, archive_strlen(&hdr));
+		}
+		/* indicate we're done with file header writing */
+		w->omit_warcinfo = 1U;
+		archive_string_free(&hdr);
+	}
+
+	if (archive_entry_pathname(entry) == NULL) {
+		archive_set_error(&a->archive, EINVAL,
+		    "Invalid filename");
+		return (ARCHIVE_WARN);
+	}
+
+	w->typ = archive_entry_filetype(entry);
+	w->populz = 0U;
+	if (w->typ == AE_IFREG) {
+		warc_essential_hdr_t rh = {
+			WT_RSRC,
+			/*uri*/archive_entry_pathname(entry),
+			/*urn*/NULL,
+			/*rtm*/w->now,
+			/*mtm*/archive_entry_mtime(entry),
+			/*cty*/NULL,
+			/*len*/(size_t)archive_entry_size(entry),
+		};
+		ssize_t r;
+
+		archive_string_init(&hdr);
+		r = _popul_ehdr(&hdr, MAX_HDR_SIZE, rh);
+		if (r < 0) {
+			/* don't bother */
+			archive_set_error(
+				&a->archive,
+				ARCHIVE_ERRNO_FILE_FORMAT,
+				"cannot archive file");
+			return (ARCHIVE_WARN);
+		}
+		/* otherwise append to output stream */
+		__archive_write_output(a, hdr.s, r);
+		/* and let subsequent calls to _data() know about the size */
+		w->populz = rh.cntlen;
+		archive_string_free(&hdr);
+		return (ARCHIVE_OK);
+	}
+	/* just resort to erroring as per Tim's advice */
+	archive_set_error(
+		&a->archive,
+		ARCHIVE_ERRNO_FILE_FORMAT,
+		"WARC can only process regular files");
+	return (ARCHIVE_FAILED);
+}
+
+static ssize_t
+_warc_data(struct archive_write *a, const void *buf, size_t len)
+{
+	struct warc_s *w = a->format_data;
+
+	if (w->typ == AE_IFREG) {
+		int rc;
+
+		/* never write more bytes than announced */
+		if (len > w->populz) {
+			len = (size_t)w->populz;
+		}
+
+		/* now then, out we put the whole shebang */
+		rc = __archive_write_output(a, buf, len);
+		if (rc != ARCHIVE_OK) {
+			return rc;
+		}
+	}
+	return len;
+}
+
+static int
+_warc_finish_entry(struct archive_write *a)
+{
+	static const char _eor[] = "\r\n\r\n";
+	struct warc_s *w = a->format_data;
+
+	if (w->typ == AE_IFREG) {
+		int rc = __archive_write_output(a, _eor, sizeof(_eor) - 1U);
+
+		if (rc != ARCHIVE_OK) {
+			return rc;
+		}
+	}
+	/* reset type info */
+	w->typ = 0;
+	return (ARCHIVE_OK);
+}
+
+static int
+_warc_close(struct archive_write *a)
+{
+	(void)a; /* UNUSED */
+	return (ARCHIVE_OK);
+}
+
+static int
+_warc_free(struct archive_write *a)
+{
+	struct warc_s *w = a->format_data;
+
+	free(w);
+	a->format_data = NULL;
+	return (ARCHIVE_OK);
+}
+
+

+/* private routines */
+static void
+xstrftime(struct archive_string *as, const char *fmt, time_t t)
+{
+/** like strftime(3) but for time_t objects */
+	struct tm *rt;
+#if defined(HAVE_GMTIME_R) || defined(HAVE__GMTIME64_S)
+	struct tm time;
+#endif
+	char strtime[100];
+	size_t len;
+
+#ifdef HAVE_GMTIME_R
+	if ((rt = gmtime_r(&t, &time)) == NULL)
+		return;
+#elif defined(HAVE__GMTIME64_S)
+	_gmtime64_s(&time, &t);
+#else
+	if ((rt = gmtime(&t)) == NULL)
+		return;
+#endif
+	/* leave the hard yacker to our role model strftime() */
+	len = strftime(strtime, sizeof(strtime)-1, fmt, rt);
+	archive_strncat(as, strtime, len);
+}
+
+static ssize_t
+_popul_ehdr(struct archive_string *tgt, size_t tsz, warc_essential_hdr_t hdr)
+{
+	static const char _ver[] = "WARC/1.0\r\n";
+	static const char *_typ[LAST_WT] = {
+		NULL, "warcinfo", "metadata", "resource", NULL
+	};
+	char std_uuid[48U];
+
+	if (hdr.type == WT_NONE || hdr.type > WT_RSRC) {
+		/* brilliant, how exactly did we get here? */
+		return -1;
+	}
+
+	archive_strcpy(tgt, _ver);
+
+	archive_string_sprintf(tgt, "WARC-Type: %s\r\n", _typ[hdr.type]);
+
+	if (hdr.tgturi != NULL) {
+		/* check if there's a xyz:// */
+		static const char _uri[] = "";
+		static const char _fil[] = "file://";
+		const char *u;
+		char *chk = strchr(hdr.tgturi, ':');
+
+		if (chk != NULL && chk[1U] == '/' && chk[2U] == '/') {
+			/* yep, it's definitely a URI */
+			u = _uri;
+		} else {
+			/* hm, best to prepend file:// then */
+			u = _fil;
+		}
+		archive_string_sprintf(tgt,
+			"WARC-Target-URI: %s%s\r\n", u, hdr.tgturi);
+	}
+
+	/* record time is usually when the http is sent off,
+	 * just treat the archive writing as such for a moment */
+	xstrftime(tgt, "WARC-Date: %Y-%m-%dT%H:%M:%SZ\r\n", hdr.rtime);
+
+	/* while we're at it, record the mtime */
+	xstrftime(tgt, "Last-Modified: %Y-%m-%dT%H:%M:%SZ\r\n", hdr.mtime);
+
+	if (hdr.recid == NULL) {
+		/* generate one, grrrr */
+		warc_uuid_t u;
+
+		_gen_uuid(&u);
+		/* Unfortunately, archive_string_sprintf does not
+		 * handle the minimum number following '%'.
+		 * So we have to use snprintf function here instead
+		 * of archive_string_snprintf function. */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define snprintf _snprintf
+#endif
+		snprintf(
+			std_uuid, sizeof(std_uuid),
+			"<urn:uuid:%08x-%04x-%04x-%04x-%04x%08x>",
+			u.u[0U],
+			u.u[1U] >> 16U, u.u[1U] & 0xffffU,
+			u.u[2U] >> 16U, u.u[2U] & 0xffffU,
+			u.u[3U]);
+		hdr.recid = std_uuid;
+	}
+
+	/* record-id is mandatory, fingers crossed we won't fail */
+	archive_string_sprintf(tgt, "WARC-Record-ID: %s\r\n", hdr.recid);
+
+	if (hdr.cnttyp != NULL) {
+		archive_string_sprintf(tgt, "Content-Type: %s\r\n", hdr.cnttyp);
+	}
+
+	/* next one is mandatory */
+	archive_string_sprintf(tgt, "Content-Length: %ju\r\n", (uintmax_t)hdr.cntlen);
+	/**/
+	archive_strncat(tgt, "\r\n", 2);
+
+	return (archive_strlen(tgt) >= tsz)? -1: (ssize_t)archive_strlen(tgt);
+}
+
+static int
+_gen_uuid(warc_uuid_t *tgt)
+{
+	archive_random(tgt->u, sizeof(tgt->u));
+	/* obey uuid version 4 rules */
+	tgt->u[1U] &= 0xffff0fffU;
+	tgt->u[1U] |= 0x4000U;
+	tgt->u[2U] &= 0x3fffffffU;
+	tgt->u[2U] |= 0x80000000U;
+	return 0;
+}
+
+/* archive_write_set_format_warc.c ends here */
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_xar.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_xar.c
index 4cd2b9d..a47c53c 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_xar.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_xar.c
@@ -47,7 +47,7 @@ __FBSDID("$FreeBSD$");
 #endif
 
 #include "archive.h"
-#include "archive_crypto_private.h"
+#include "archive_digest_private.h"
 #include "archive_endian.h"
 #include "archive_entry.h"
 #include "archive_entry_locale.h"
@@ -114,7 +114,7 @@ enum sumalg {
 #define MAX_SUM_SIZE	20
 #define MD5_NAME	"md5"
 #define SHA1_NAME	"sha1"
- 
+
 enum enctype {
 	NONE,
 	GZIP,
@@ -242,6 +242,7 @@ struct xar {
 	enum sumalg		 opt_sumalg;
 	enum enctype		 opt_compression;
 	int			 opt_compression_level;
+	uint32_t		 opt_threads;
 
 	struct chksumwork	 a_sumwrk;	/* archived checksum.	*/
 	struct chksumwork	 e_sumwrk;	/* extracted checksum.	*/
@@ -317,7 +318,7 @@ static int	compression_end_bzip2(struct archive *, struct la_zstream *);
 static int	compression_init_encoder_lzma(struct archive *,
 		    struct la_zstream *, int);
 static int	compression_init_encoder_xz(struct archive *,
-		    struct la_zstream *, int);
+		    struct la_zstream *, int, int);
 #if defined(HAVE_LZMA_H)
 static int	compression_code_lzma(struct archive *,
 		    struct la_zstream *, enum la_zaction);
@@ -380,9 +381,10 @@ archive_write_set_format_xar(struct archive *_a)
 	/* Set default checksum type. */
 	xar->opt_toc_sumalg = CKSUM_SHA1;
 	xar->opt_sumalg = CKSUM_SHA1;
-	/* Set default compression type and level. */
+	/* Set default compression type, level, and number of threads. */
 	xar->opt_compression = GZIP;
 	xar->opt_compression_level = 6;
+	xar->opt_threads = 1;
 
 	a->format_data = xar;
 
@@ -493,6 +495,26 @@ xar_options(struct archive_write *a, const char *key, const char *value)
 		}
 		return (ARCHIVE_OK);
 	}
+	if (strcmp(key, "threads") == 0) {
+		if (value == NULL)
+			return (ARCHIVE_FAILED);
+		xar->opt_threads = (int)strtoul(value, NULL, 10);
+		if (xar->opt_threads == 0 && errno != 0) {
+			xar->opt_threads = 1;
+			archive_set_error(&(a->archive),
+			    ARCHIVE_ERRNO_MISC,
+			    "Illegal value `%s'",
+			    value);
+			return (ARCHIVE_FAILED);
+		}
+		if (xar->opt_threads == 0) {
+#ifdef HAVE_LZMA_STREAM_ENCODER_MT
+			xar->opt_threads = lzma_cputhreads();
+#else
+			xar->opt_threads = 1;
+#endif
+		}
+	}
 
 	/* Note: The "warn" return is just to inform the options
 	 * supervisor that we didn't handle it.  It will generate
@@ -805,7 +827,7 @@ xmlwrite_string(struct archive_write *a, xmlTextWriterPtr writer,
 
 	if (value == NULL)
 		return (ARCHIVE_OK);
-	
+
 	r = xmlTextWriterStartElement(writer, BAD_CAST_CONST(key));
 	if (r < 0) {
 		archive_set_error(&a->archive,
@@ -1875,7 +1897,7 @@ file_cmp_node(const struct archive_rb_node *n1,
 
 	return (strcmp(f1->basename.s, f2->basename.s));
 }
-        
+
 static int
 file_cmp_key(const struct archive_rb_node *n, const void *key)
 {
@@ -2154,7 +2176,7 @@ file_gen_utility_names(struct archive_write *a, struct file *file)
 		file->parentdir.length = len;
 		archive_string_copy(&(file->basename), &(file->parentdir));
 		archive_string_empty(&(file->parentdir));
-		file->parentdir.s = '\0';
+		*file->parentdir.s = '\0';
 		return (r);
 	}
 
@@ -2494,7 +2516,7 @@ file_init_hardlinks(struct xar *xar)
 	static const struct archive_rb_tree_ops rb_ops = {
 		file_hd_cmp_node, file_hd_cmp_key,
 	};
- 
+
 	__archive_rb_tree_init(&(xar->hardlink_rbtree), &rb_ops);
 }
 
@@ -2848,13 +2870,18 @@ compression_init_encoder_lzma(struct archive *a,
 
 static int
 compression_init_encoder_xz(struct archive *a,
-    struct la_zstream *lastrm, int level)
+    struct la_zstream *lastrm, int level, int threads)
 {
 	static const lzma_stream lzma_init_data = LZMA_STREAM_INIT;
 	lzma_stream *strm;
 	lzma_filter *lzmafilters;
 	lzma_options_lzma lzma_opt;
 	int r;
+#ifdef HAVE_LZMA_STREAM_ENCODER_MT
+	lzma_mt mt_options;
+#endif
+
+	(void)threads; /* UNUSED (if multi-threaded LZMA library not avail) */
 
 	if (lastrm->valid)
 		compression_end(a, lastrm);
@@ -2879,7 +2906,17 @@ compression_init_encoder_xz(struct archive *a,
 	lzmafilters[1].id = LZMA_VLI_UNKNOWN;/* Terminate */
 
 	*strm = lzma_init_data;
-	r = lzma_stream_encoder(strm, lzmafilters, LZMA_CHECK_CRC64);
+#ifdef HAVE_LZMA_STREAM_ENCODER_MT
+	if (threads > 1) {
+		bzero(&mt_options, sizeof(mt_options));
+		mt_options.threads = threads;
+		mt_options.timeout = 300;
+		mt_options.filters = lzmafilters;
+		mt_options.check = LZMA_CHECK_CRC64;
+		r = lzma_stream_encoder_mt(strm, &mt_options);
+	} else
+#endif
+		r = lzma_stream_encoder(strm, lzmafilters, LZMA_CHECK_CRC64);
 	switch (r) {
 	case LZMA_OK:
 		lastrm->real_stream = strm;
@@ -2979,10 +3016,11 @@ compression_init_encoder_lzma(struct archive *a,
 }
 static int
 compression_init_encoder_xz(struct archive *a,
-    struct la_zstream *lastrm, int level)
+    struct la_zstream *lastrm, int level, int threads)
 {
 
 	(void) level; /* UNUSED */
+	(void) threads; /* UNUSED */
 	if (lastrm->valid)
 		compression_end(a, lastrm);
 	return (compression_unsupported_encoder(a, lastrm, "xz"));
@@ -3015,7 +3053,7 @@ xar_compression_init_encoder(struct archive_write *a)
 	case XZ:
 		r = compression_init_encoder_xz(
 		    &(a->archive), &(xar->stream),
-		    xar->opt_compression_level);
+		    xar->opt_compression_level, xar->opt_threads);
 		break;
 	default:
 		r = ARCHIVE_OK;
@@ -3178,4 +3216,3 @@ getalgname(enum sumalg sumalg)
 }
 
 #endif /* Support xar format */
-
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_zip.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_zip.c
index 3b07e35..0636f46 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_zip.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_zip.c
@@ -1,7 +1,7 @@
 /*-
  * Copyright (c) 2008 Anselm Strauss
  * Copyright (c) 2009 Joerg Sonnenberger
- * Copyright (c) 2011-2012 Michihiro NAKAJIMA
+ * Copyright (c) 2011-2012,2014 Michihiro NAKAJIMA
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -49,20 +49,23 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_zip.c 201168 20
 #endif
 
 #include "archive.h"
+#include "archive_cryptor_private.h"
 #include "archive_endian.h"
 #include "archive_entry.h"
 #include "archive_entry_locale.h"
+#include "archive_hmac_private.h"
 #include "archive_private.h"
+#include "archive_random_private.h"
 #include "archive_write_private.h"
 
 #ifndef HAVE_ZLIB_H
 #include "archive_crc32.h"
 #endif
 
+#define ZIP_ENTRY_FLAG_ENCRYPTED	(1<<0)
 #define ZIP_ENTRY_FLAG_LENGTH_AT_END	(1<<3)
 #define ZIP_ENTRY_FLAG_UTF8_NAME	(1 << 11)
 
-
 enum compression {
 	COMPRESSION_UNSPECIFIED = -1,
 	COMPRESSION_STORE = 0,
@@ -75,6 +78,32 @@ enum compression {
 #define COMPRESSION_DEFAULT	COMPRESSION_STORE
 #endif
 
+enum encryption {
+	ENCRYPTION_NONE	= 0,
+	ENCRYPTION_TRADITIONAL, /* Traditional PKWARE encryption. */
+	ENCRYPTION_WINZIP_AES128, /* WinZIP AES-128 encryption. */
+	ENCRYPTION_WINZIP_AES256, /* WinZIP AES-256 encryption. */
+};
+
+#define TRAD_HEADER_SIZE	12
+/*
+ * See "WinZip - AES Encryption Information"
+ *     http://www.winzip.com/aes_info.htm
+ */
+/* Value used in compression method. */
+#define WINZIP_AES_ENCRYPTION	99
+/* A WinZip AES header size which is stored at the beginning of
+ * file contents. */
+#define WINZIP_AES128_HEADER_SIZE	(8 + 2)
+#define WINZIP_AES256_HEADER_SIZE	(16 + 2)
+/* AES vendor version. */
+#define AES_VENDOR_AE_1 0x0001
+#define AES_VENDOR_AE_2 0x0002
+/* Authentication code size. */
+#define AUTH_CODE_SIZE		10
+/**/
+#define MAX_DERIVED_KEY_BUF_SIZE (AES_MAX_KEY_SIZE * 2 + 2)
+
 struct cd_segment {
 	struct cd_segment *next;
 	size_t buff_size;
@@ -82,9 +111,9 @@ struct cd_segment {
 	unsigned char *p;
 };
 
-/* Bits used to enable/disable certain experimental features. */
-#define	EXPERIMENT_LA 1
-#define	EXPERIMENTS_ALL 0xffff
+struct trad_enc_ctx {
+	uint32_t keys[3];
+};
 
 struct zip {
 
@@ -97,9 +126,18 @@ struct zip {
 	struct archive_entry *entry;
 	uint32_t entry_crc32;
 	enum compression entry_compression;
+	enum encryption  entry_encryption;
 	int entry_flags;
 	int entry_uses_zip64;
 	int experiments;
+	struct trad_enc_ctx tctx;
+	char tctx_valid;
+	unsigned char trad_chkdat;
+	unsigned aes_vendor;
+	archive_crypto_ctx cctx;
+	char cctx_valid;
+	archive_hmac_sha1_ctx hctx;
+	char hctx_valid;
 
 	unsigned char *file_header;
 	size_t file_header_extra_offset;
@@ -115,18 +153,20 @@ struct zip {
 	struct archive_string_conv *opt_sconv;
 	struct archive_string_conv *sconv_default;
 	enum compression requested_compression;
+	int deflate_compression_level;
 	int init_default_conversion;
+	enum encryption  encryption_type;
 
 #define ZIP_FLAG_AVOID_ZIP64 1
 #define ZIP_FLAG_FORCE_ZIP64 2
-#define ZIP_FLAG_EXPERIMENT_EL 4
+#define ZIP_FLAG_EXPERIMENT_xl 4
 	int flags;
 
 #ifdef HAVE_ZLIB_H
 	z_stream stream;
+#endif
 	size_t len_buf;
 	unsigned char *buf;
-#endif
 };
 
 /* Don't call this min or MIN, since those are already defined
@@ -147,6 +187,13 @@ static size_t path_length(struct archive_entry *);
 static int write_path(struct archive_entry *, struct archive_write *);
 static void copy_path(struct archive_entry *, unsigned char *);
 static struct archive_string_conv *get_sconv(struct archive_write *, struct zip *);
+static int trad_enc_init(struct trad_enc_ctx *, const char *, size_t);
+static unsigned trad_enc_encrypt_update(struct trad_enc_ctx *, const uint8_t *,
+    size_t, uint8_t *, size_t);
+static int init_traditional_pkware_encryption(struct archive_write *);
+static int is_traditional_pkware_encryption_supported(void);
+static int init_winzip_aes_encryption(struct archive_write *);
+static int is_winzip_aes_encryption_supported(int encryption);
 
 static unsigned char *
 cd_alloc(struct zip *zip, size_t length)
@@ -186,7 +233,7 @@ cd_alloc(struct zip *zip, size_t length)
 static unsigned long
 real_crc32(unsigned long crc, const void *buff, size_t len)
 {
-	return crc32(crc, buff, len);
+	return crc32(crc, buff, (unsigned int)len);
 }
 
 static unsigned long
@@ -227,11 +274,70 @@ archive_write_zip_options(struct archive_write *a, const char *key,
 			ret = ARCHIVE_OK;
 		}
 		return (ret);
+	} else if (strcmp(key, "compression-level") == 0) {
+		if (val == NULL || !(val[0] >= '0' && val[0] <= '9') || val[1] != '\0') {
+			return ARCHIVE_WARN;
+		}
+
+		if (val[0] == '0') {
+			zip->requested_compression = COMPRESSION_STORE;
+			return ARCHIVE_OK;
+		} else {
+#ifdef HAVE_ZLIB_H
+			zip->requested_compression = COMPRESSION_DEFLATE;
+			zip->deflate_compression_level = val[0] - '0';
+			return ARCHIVE_OK;
+#else
+			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+			    "deflate compression not supported");
+#endif
+		}
+	} else if (strcmp(key, "encryption") == 0) {
+		if (val == NULL) {
+			zip->encryption_type = ENCRYPTION_NONE;
+			ret = ARCHIVE_OK;
+		} else if (val[0] == '1' || strcmp(val, "traditional") == 0
+		    || strcmp(val, "zipcrypt") == 0
+		    || strcmp(val, "ZipCrypt") == 0) {
+			if (is_traditional_pkware_encryption_supported()) {
+				zip->encryption_type = ENCRYPTION_TRADITIONAL;
+				ret = ARCHIVE_OK;
+			} else {
+				archive_set_error(&a->archive,
+				    ARCHIVE_ERRNO_MISC,
+				    "encryption not supported");
+			}
+		} else if (strcmp(val, "aes128") == 0) {
+			if (is_winzip_aes_encryption_supported(
+			    ENCRYPTION_WINZIP_AES128)) {
+				zip->encryption_type = ENCRYPTION_WINZIP_AES128;
+				ret = ARCHIVE_OK;
+			} else {
+				archive_set_error(&a->archive,
+				    ARCHIVE_ERRNO_MISC,
+				    "encryption not supported");
+			}
+		} else if (strcmp(val, "aes256") == 0) {
+			if (is_winzip_aes_encryption_supported(
+			    ENCRYPTION_WINZIP_AES256)) {
+				zip->encryption_type = ENCRYPTION_WINZIP_AES256;
+				ret = ARCHIVE_OK;
+			} else {
+				archive_set_error(&a->archive,
+				    ARCHIVE_ERRNO_MISC,
+				    "encryption not supported");
+			}
+		} else {
+			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+			    "%s: unknown encryption '%s'",
+			    a->format_name, val);
+		}
+		return (ret);
 	} else if (strcmp(key, "experimental") == 0) {
 		if (val == NULL || val[0] == 0) {
-			zip->flags &= ~ ZIP_FLAG_EXPERIMENT_EL;
+			zip->flags &= ~ ZIP_FLAG_EXPERIMENT_xl;
 		} else {
-			zip->flags |= ZIP_FLAG_EXPERIMENT_EL;
+			zip->flags |= ZIP_FLAG_EXPERIMENT_xl;
 		}
 		return (ARCHIVE_OK);
 	} else if (strcmp(key, "fakecrc32") == 0) {
@@ -357,9 +463,12 @@ archive_write_set_format_zip(struct archive *_a)
 
 	/* "Unspecified" lets us choose the appropriate compression. */
 	zip->requested_compression = COMPRESSION_UNSPECIFIED;
+#ifdef HAVE_ZLIB_H
+	zip->deflate_compression_level = Z_DEFAULT_COMPRESSION;
+#endif
 	zip->crc32func = real_crc32;
 
-#ifdef HAVE_ZLIB_H
+	/* A buffer used for both compression and encryption. */
 	zip->len_buf = 65536;
 	zip->buf = malloc(zip->len_buf);
 	if (zip->buf == NULL) {
@@ -368,7 +477,6 @@ archive_write_set_format_zip(struct archive *_a)
 		    "Can't allocate compression buffer");
 		return (ARCHIVE_FATAL);
 	}
-#endif
 
 	a->format_data = zip;
 	a->format_name = "zip";
@@ -400,7 +508,7 @@ static int
 archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 {
 	unsigned char local_header[32];
-	unsigned char local_extra[128];
+	unsigned char local_extra[144];
 	struct zip *zip = a->format_data;
 	unsigned char *e;
 	unsigned char *cd_extra;
@@ -409,7 +517,6 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 	size_t slink_size = 0;
 	struct archive_string_conv *sconv = get_sconv(a, zip);
 	int ret, ret2 = ARCHIVE_OK;
-	int64_t size;
 	mode_t type;
 	int version_needed = 10;
 
@@ -425,13 +532,14 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 	if (zip->flags & ZIP_FLAG_AVOID_ZIP64) {
 		/* Reject entries over 4GB. */
 		if (archive_entry_size_is_set(entry)
-		    && (archive_entry_size(entry) > 0xffffffff)) {
+		    && (archive_entry_size(entry) >
+			ARCHIVE_LITERAL_LL(0xffffffff))) {
 			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
 			    "Files > 4GB require Zip64 extensions");
 			return ARCHIVE_FAILED;
 		}
 		/* Reject entries if archive is > 4GB. */
-		if (zip->written_bytes > 0xffffffff) {
+		if (zip->written_bytes > ARCHIVE_LITERAL_LL(0xffffffff)) {
 			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
 			    "Archives > 4GB require Zip64 extensions");
 			return ARCHIVE_FAILED;
@@ -453,11 +561,34 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 	zip->entry_flags = 0;
 	zip->entry_uses_zip64 = 0;
 	zip->entry_crc32 = zip->crc32func(0, NULL, 0);
+	zip->entry_encryption = 0;
 	if (zip->entry != NULL) {
 		archive_entry_free(zip->entry);
 		zip->entry = NULL;
 	}
 
+	if (zip->cctx_valid)
+		archive_encrypto_aes_ctr_release(&zip->cctx);
+	if (zip->hctx_valid)
+		archive_hmac_sha1_cleanup(&zip->hctx);
+	zip->tctx_valid = zip->cctx_valid = zip->hctx_valid = 0;
+
+	if (type == AE_IFREG
+		    &&(!archive_entry_size_is_set(entry)
+			|| archive_entry_size(entry) > 0)) {
+		switch (zip->encryption_type) {
+		case ENCRYPTION_TRADITIONAL:
+		case ENCRYPTION_WINZIP_AES128:
+		case ENCRYPTION_WINZIP_AES256:
+			zip->entry_flags |= ZIP_ENTRY_FLAG_ENCRYPTED;
+			zip->entry_encryption = zip->encryption_type;
+			break;
+		default:
+			break;
+		}
+	}
+
+
 #if defined(_WIN32) && !defined(__CYGWIN__)
 	/* Make sure the path separators in pahtname, hardlink and symlink
 	 * are all slash '/', not the Windows path separator '\'. */
@@ -543,10 +674,11 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 	} else if (type != AE_IFREG) {
 		zip->entry_compression = COMPRESSION_STORE;
 		zip->entry_uncompressed_limit = 0;
-		size = 0;
 		version_needed = 20;
 	} else if (archive_entry_size_is_set(zip->entry)) {
-		size = archive_entry_size(zip->entry);
+		int64_t size = archive_entry_size(zip->entry);
+		int64_t additional_size = 0;
+
 		zip->entry_uncompressed_limit = size;
 		zip->entry_compression = zip->requested_compression;
 		if (zip->entry_compression == COMPRESSION_UNSPECIFIED) {
@@ -560,8 +692,46 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 			zip->entry_uncompressed_size = size;
 			version_needed = 20;
 		}
-		if ((zip->flags & ZIP_FLAG_FORCE_ZIP64) /* User asked. */
-		    || (zip->entry_uncompressed_size > ARCHIVE_LITERAL_LL(0xffffffff))) { /* Large entry. */
+
+		if (zip->entry_flags & ZIP_ENTRY_FLAG_ENCRYPTED) {
+			switch (zip->entry_encryption) {
+			case ENCRYPTION_TRADITIONAL:
+				additional_size = TRAD_HEADER_SIZE;
+				version_needed = 20;
+				break;
+			case ENCRYPTION_WINZIP_AES128:
+				additional_size = WINZIP_AES128_HEADER_SIZE
+				    + AUTH_CODE_SIZE;
+				version_needed = 20;
+				break;
+			case ENCRYPTION_WINZIP_AES256:
+				additional_size = WINZIP_AES256_HEADER_SIZE
+				    + AUTH_CODE_SIZE;
+				version_needed = 20;
+				break;
+			default:
+				break;
+			}
+			if (zip->entry_compression == COMPRESSION_STORE)
+				zip->entry_compressed_size += additional_size;
+		}
+
+		/*
+		 * Set Zip64 extension in any of the following cases
+		 * (this was suggested by discussion on info-zip-dev
+		 * mailing list):
+		 *  = Zip64 is being forced by user
+		 *  = File is over 4GiB uncompressed
+		 *    (including encryption header, if any)
+		 *  = File is close to 4GiB and is being compressed
+		 *    (compression might make file larger)
+		 */
+		if ((zip->flags & ZIP_FLAG_FORCE_ZIP64)
+		    || (zip->entry_uncompressed_size + additional_size >
+			ARCHIVE_LITERAL_LL(0xffffffff))
+		    || (zip->entry_uncompressed_size >
+			ARCHIVE_LITERAL_LL(0xff000000)
+			&& zip->entry_compression != COMPRESSION_STORE)) {
 			zip->entry_uses_zip64 = 1;
 			version_needed = 45;
 		}
@@ -569,9 +739,11 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 		/* We may know the size, but never the CRC. */
 		zip->entry_flags |= ZIP_ENTRY_FLAG_LENGTH_AT_END;
 	} else {
-		/* Prefer deflate if it's available, because deflate
-		 * has a clear end-of-data marker that makes
-		 * length-at-end more reliable. */
+		/* We don't know the size.  In this case, we prefer
+		 * deflate (it has a clear end-of-data marker which
+		 * makes length-at-end more reliable) and will
+		 * enable Zip64 extensions unless we're told not to.
+		 */
 		zip->entry_compression = COMPRESSION_DEFAULT;
 		zip->entry_flags |= ZIP_ENTRY_FLAG_LENGTH_AT_END;
 		if ((zip->flags & ZIP_FLAG_AVOID_ZIP64) == 0) {
@@ -582,6 +754,19 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 		} else {
 			version_needed = 20;
 		}
+
+		if (zip->entry_flags & ZIP_ENTRY_FLAG_ENCRYPTED) {
+			switch (zip->entry_encryption) {
+			case ENCRYPTION_TRADITIONAL:
+			case ENCRYPTION_WINZIP_AES128:
+			case ENCRYPTION_WINZIP_AES256:
+				if (version_needed < 20)
+					version_needed = 20;
+				break;
+			default:
+				break;
+			}
+		}
 	}
 
 	/* Format the local header. */
@@ -589,8 +774,13 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 	memcpy(local_header, "PK\003\004", 4);
 	archive_le16enc(local_header + 4, version_needed);
 	archive_le16enc(local_header + 6, zip->entry_flags);
-	archive_le16enc(local_header + 8, zip->entry_compression);
-	archive_le32enc(local_header + 10, dos_time(archive_entry_mtime(zip->entry)));
+	if (zip->entry_encryption == ENCRYPTION_WINZIP_AES128
+	    || zip->entry_encryption == ENCRYPTION_WINZIP_AES256)
+		archive_le16enc(local_header + 8, WINZIP_AES_ENCRYPTION);
+	else
+		archive_le16enc(local_header + 8, zip->entry_compression);
+	archive_le32enc(local_header + 10,
+		dos_time(archive_entry_mtime(zip->entry)));
 	archive_le32enc(local_header + 14, zip->entry_crc32);
 	if (zip->entry_uses_zip64) {
 		/* Zip64 data in the local header "must" include both
@@ -601,10 +791,17 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 		archive_le32enc(local_header + 18, ARCHIVE_LITERAL_LL(0xffffffff));
 		archive_le32enc(local_header + 22, ARCHIVE_LITERAL_LL(0xffffffff));
 	} else {
-		archive_le32enc(local_header + 18, zip->entry_compressed_size);
-		archive_le32enc(local_header + 22, zip->entry_uncompressed_size);
+		archive_le32enc(local_header + 18, (uint32_t)zip->entry_compressed_size);
+		archive_le32enc(local_header + 22, (uint32_t)zip->entry_uncompressed_size);
+	}
+	archive_le16enc(local_header + 26, (uint16_t)filename_length);
+
+	if (zip->entry_encryption == ENCRYPTION_TRADITIONAL) {
+		if (zip->entry_flags & ZIP_ENTRY_FLAG_LENGTH_AT_END)
+			zip->trad_chkdat = local_header[11];
+		else
+			zip->trad_chkdat = local_header[17];
 	}
-	archive_le16enc(local_header + 26, filename_length);
 
 	/* Format as much of central directory file header as we can: */
 	zip->file_header = cd_alloc(zip, 46);
@@ -616,9 +813,14 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 	archive_le16enc(zip->file_header + 4, 3 * 256 + version_needed);
 	archive_le16enc(zip->file_header + 6, version_needed);
 	archive_le16enc(zip->file_header + 8, zip->entry_flags);
-	archive_le16enc(zip->file_header + 10, zip->entry_compression);
-	archive_le32enc(zip->file_header + 12, dos_time(archive_entry_mtime(zip->entry)));
-	archive_le16enc(zip->file_header + 28, filename_length);
+	if (zip->entry_encryption == ENCRYPTION_WINZIP_AES128
+	    || zip->entry_encryption == ENCRYPTION_WINZIP_AES256)
+		archive_le16enc(zip->file_header + 10, WINZIP_AES_ENCRYPTION);
+	else
+		archive_le16enc(zip->file_header + 10, zip->entry_compression);
+	archive_le32enc(zip->file_header + 12,
+		dos_time(archive_entry_mtime(zip->entry)));
+	archive_le16enc(zip->file_header + 28, (uint16_t)filename_length);
 	/* Following Info-Zip, store mode in the "external attributes" field. */
 	archive_le32enc(zip->file_header + 38,
 	    ((uint32_t)archive_entry_mode(zip->entry)) << 16);
@@ -670,7 +872,33 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 	archive_le32enc(e, (uint32_t)archive_entry_gid(entry));
 	e += 4;
 
-	/* Copy UT and ux into central directory as well. */
+	/* AES extra data field: WinZIP AES information, ID=0x9901 */
+	if ((zip->entry_flags & ZIP_ENTRY_FLAG_ENCRYPTED)
+	    && (zip->entry_encryption == ENCRYPTION_WINZIP_AES128
+	        || zip->entry_encryption == ENCRYPTION_WINZIP_AES256)) {
+
+		memcpy(e, "\001\231\007\000\001\000AE", 8);
+		/* AES vendoer version AE-2 does not store a CRC.
+		 * WinZip 11 uses AE-1, which does store the CRC,
+		 * but it does not store the CRC when the file size
+		 * is less than 20 bytes. So we simulate what
+		 * WinZip 11 does.
+		 * NOTE: WinZip 9.0 and 10.0 uses AE-2 by default. */
+		if (archive_entry_size_is_set(zip->entry)
+		    && archive_entry_size(zip->entry) < 20) {
+			archive_le16enc(e+4, AES_VENDOR_AE_2);
+			zip->aes_vendor = AES_VENDOR_AE_2;/* no CRC. */
+		} else
+			zip->aes_vendor = AES_VENDOR_AE_1;
+		e += 8;
+		/* AES encryption strength. */
+		*e++ = (zip->entry_encryption == ENCRYPTION_WINZIP_AES128)?1:3;
+		/* Actual compression method. */
+		archive_le16enc(e, zip->entry_compression);
+		e += 2;
+	}
+
+	/* Copy UT ,ux, and AES-extra into central directory as well. */
 	zip->file_header_extra_offset = zip->central_directory_bytes;
 	cd_extra = cd_alloc(zip, e - local_extra);
 	memcpy(cd_extra, local_extra, e - local_extra);
@@ -692,14 +920,14 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 		e += 8;
 		archive_le64enc(e, zip->entry_compressed_size);
 		e += 8;
-		archive_le16enc(zip64_start + 2, e - (zip64_start + 4));
+		archive_le16enc(zip64_start + 2, (uint16_t)(e - (zip64_start + 4)));
 	}
 
-	if (zip->flags & ZIP_FLAG_EXPERIMENT_EL) {
-		/* Experimental 'el' extension to improve streaming. */
+	if (zip->flags & ZIP_FLAG_EXPERIMENT_xl) {
+		/* Experimental 'xl' extension to improve streaming. */
 		unsigned char *external_info = e;
 		int included = 7;
-		memcpy(e, "el\000\000", 4); // 0x6c65 + 2-byte length
+		memcpy(e, "xl\000\000", 4); // 0x6c65 + 2-byte length
 		e += 4;
 		e[0] = included; /* bitmap of included fields */
 		e += 1;
@@ -720,11 +948,11 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 		if (included & 8) {
 			// Libarchive does not currently support file comments.
 		}
-		archive_le16enc(external_info + 2, e - (external_info + 4));
+		archive_le16enc(external_info + 2, (uint16_t)(e - (external_info + 4)));
 	}
 
 	/* Update local header with size of extra data and write it all out: */
-	archive_le16enc(local_header + 28, e - local_extra);
+	archive_le16enc(local_header + 28, (uint16_t)(e - local_extra));
 
 	ret = __archive_write_output(a, local_header, 30);
 	if (ret != ARCHIVE_OK)
@@ -758,7 +986,7 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 		zip->stream.opaque = Z_NULL;
 		zip->stream.next_out = zip->buf;
 		zip->stream.avail_out = (uInt)zip->len_buf;
-		if (deflateInit2(&zip->stream, Z_DEFAULT_COMPRESSION,
+		if (deflateInit2(&zip->stream, zip->deflate_compression_level,
 		    Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY) != Z_OK) {
 			archive_set_error(&a->archive, ENOMEM,
 			    "Can't init deflate compressor");
@@ -782,13 +1010,72 @@ archive_write_zip_data(struct archive_write *a, const void *buff, size_t s)
 
 	if (s == 0) return 0;
 
+	if (zip->entry_flags & ZIP_ENTRY_FLAG_ENCRYPTED) {
+		switch (zip->entry_encryption) {
+		case ENCRYPTION_TRADITIONAL:
+			/* Initialize traditoinal PKWARE encryption context. */
+			if (!zip->tctx_valid) {
+				ret = init_traditional_pkware_encryption(a);
+				if (ret != ARCHIVE_OK)
+					return (ret);
+				zip->tctx_valid = 1;
+			}
+			break;
+		case ENCRYPTION_WINZIP_AES128:
+		case ENCRYPTION_WINZIP_AES256:
+			if (!zip->cctx_valid) {
+				ret = init_winzip_aes_encryption(a);
+				if (ret != ARCHIVE_OK)
+					return (ret);
+				zip->cctx_valid = zip->hctx_valid = 1;
+			}
+			break;
+		default:
+			break;
+		}
+	}
+
 	switch (zip->entry_compression) {
 	case COMPRESSION_STORE:
-		ret = __archive_write_output(a, buff, s);
-		if (ret != ARCHIVE_OK)
-			return (ret);
-		zip->written_bytes += s;
-		zip->entry_compressed_written += s;
+		if (zip->tctx_valid || zip->cctx_valid) {
+			const uint8_t *rb = (const uint8_t *)buff;
+			const uint8_t * const re = rb + s;
+
+			while (rb < re) {
+				size_t l;
+
+				if (zip->tctx_valid) {
+					l = trad_enc_encrypt_update(&zip->tctx,
+					    rb, re - rb,
+					    zip->buf, zip->len_buf);
+				} else {
+					l = zip->len_buf;
+					ret = archive_encrypto_aes_ctr_update(
+					    &zip->cctx,
+					    rb, re - rb, zip->buf, &l);
+					if (ret < 0) {
+						archive_set_error(&a->archive,
+						    ARCHIVE_ERRNO_MISC,
+						    "Failed to encrypt file");
+						return (ARCHIVE_FAILED);
+					}
+					archive_hmac_sha1_update(&zip->hctx,
+					    zip->buf, l);
+				}
+				ret = __archive_write_output(a, zip->buf, l);
+				if (ret != ARCHIVE_OK)
+					return (ret);
+				zip->entry_compressed_written += l;
+				zip->written_bytes += l;
+				rb += l;
+			}
+		} else {
+			ret = __archive_write_output(a, buff, s);
+			if (ret != ARCHIVE_OK)
+				return (ret);
+			zip->written_bytes += s;
+			zip->entry_compressed_written += s;
+		}
 		break;
 #if HAVE_ZLIB_H
 	case COMPRESSION_DEFLATE:
@@ -799,6 +1086,25 @@ archive_write_zip_data(struct archive_write *a, const void *buff, size_t s)
 			if (ret == Z_STREAM_ERROR)
 				return (ARCHIVE_FATAL);
 			if (zip->stream.avail_out == 0) {
+				if (zip->tctx_valid) {
+					trad_enc_encrypt_update(&zip->tctx,
+					    zip->buf, zip->len_buf,
+					    zip->buf, zip->len_buf);
+				} else if (zip->cctx_valid) {
+					size_t outl = zip->len_buf;
+					ret = archive_encrypto_aes_ctr_update(
+					    &zip->cctx,
+					    zip->buf, zip->len_buf,
+					    zip->buf, &outl);
+					if (ret < 0) {
+						archive_set_error(&a->archive,
+						    ARCHIVE_ERRNO_MISC,
+						    "Failed to encrypt file");
+						return (ARCHIVE_FAILED);
+					}
+					archive_hmac_sha1_update(&zip->hctx,
+					    zip->buf, zip->len_buf);
+				}
 				ret = __archive_write_output(a, zip->buf,
 					zip->len_buf);
 				if (ret != ARCHIVE_OK)
@@ -819,7 +1125,9 @@ archive_write_zip_data(struct archive_write *a, const void *buff, size_t s)
 	}
 
 	zip->entry_uncompressed_limit -= s;
-	zip->entry_crc32 = zip->crc32func(zip->entry_crc32, buff, (unsigned)s);
+	if (!zip->cctx_valid || zip->aes_vendor != AES_VENDOR_AE_2)
+		zip->entry_crc32 =
+		    zip->crc32func(zip->entry_crc32, buff, (unsigned)s);
 	return (s);
 
 }
@@ -834,10 +1142,28 @@ archive_write_zip_finish_entry(struct archive_write *a)
 	if (zip->entry_compression == COMPRESSION_DEFLATE) {
 		for (;;) {
 			size_t remainder;
+
 			ret = deflate(&zip->stream, Z_FINISH);
 			if (ret == Z_STREAM_ERROR)
 				return (ARCHIVE_FATAL);
 			remainder = zip->len_buf - zip->stream.avail_out;
+			if (zip->tctx_valid) {
+				trad_enc_encrypt_update(&zip->tctx,
+				    zip->buf, remainder, zip->buf, remainder);
+			} else if (zip->cctx_valid) {
+				size_t outl = remainder;
+				ret = archive_encrypto_aes_ctr_update(
+				    &zip->cctx, zip->buf, remainder,
+				    zip->buf, &outl);
+				if (ret < 0) {
+					archive_set_error(&a->archive,
+					    ARCHIVE_ERRNO_MISC,
+					    "Failed to encrypt file");
+					return (ARCHIVE_FAILED);
+				}
+				archive_hmac_sha1_update(&zip->hctx,
+				    zip->buf, remainder);
+			}
 			ret = __archive_write_output(a, zip->buf, remainder);
 			if (ret != ARCHIVE_OK)
 				return (ret);
@@ -851,20 +1177,38 @@ archive_write_zip_finish_entry(struct archive_write *a)
 		deflateEnd(&zip->stream);
 	}
 #endif
+	if (zip->hctx_valid) {
+		uint8_t hmac[20];
+		size_t hmac_len = 20;
+
+		archive_hmac_sha1_final(&zip->hctx, hmac, &hmac_len);
+		ret = __archive_write_output(a, hmac, AUTH_CODE_SIZE);
+		if (ret != ARCHIVE_OK)
+			return (ret);
+		zip->entry_compressed_written += AUTH_CODE_SIZE;
+		zip->written_bytes += AUTH_CODE_SIZE;
+	}
 
 	/* Write trailing data descriptor. */
 	if ((zip->entry_flags & ZIP_ENTRY_FLAG_LENGTH_AT_END) != 0) {
 		char d[24];
 		memcpy(d, "PK\007\010", 4);
-		archive_le32enc(d + 4, zip->entry_crc32);
+		if (zip->cctx_valid && zip->aes_vendor == AES_VENDOR_AE_2)
+			archive_le32enc(d + 4, 0);/* no CRC.*/
+		else
+			archive_le32enc(d + 4, zip->entry_crc32);
 		if (zip->entry_uses_zip64) {
-			archive_le64enc(d + 8, (uint64_t)zip->entry_compressed_written);
-			archive_le64enc(d + 16, (uint64_t)zip->entry_uncompressed_written);
+			archive_le64enc(d + 8,
+				(uint64_t)zip->entry_compressed_written);
+			archive_le64enc(d + 16,
+				(uint64_t)zip->entry_uncompressed_written);
 			ret = __archive_write_output(a, d, 24);
 			zip->written_bytes += 24;
 		} else {
-			archive_le32enc(d + 8, (uint32_t)zip->entry_compressed_written);
-			archive_le32enc(d + 12, (uint32_t)zip->entry_uncompressed_written);
+			archive_le32enc(d + 8,
+				(uint32_t)zip->entry_compressed_written);
+			archive_le32enc(d + 12,
+				(uint32_t)zip->entry_uncompressed_written);
 			ret = __archive_write_output(a, d, 16);
 			zip->written_bytes += 16;
 		}
@@ -892,7 +1236,7 @@ archive_write_zip_finish_entry(struct archive_write *a)
 			archive_le64enc(z, zip->entry_offset);
 			z += 8;
 		}
-		archive_le16enc(zip64 + 2, z - (zip64 + 4));
+		archive_le16enc(zip64 + 2, (uint16_t)(z - (zip64 + 4)));
 		zd = cd_alloc(zip, z - zip64);
 		if (zd == NULL) {
 			archive_set_error(&a->archive, ENOMEM,
@@ -906,15 +1250,21 @@ archive_write_zip_finish_entry(struct archive_write *a)
 	}
 
 	/* Fix up central directory file header. */
-	archive_le32enc(zip->file_header + 16, zip->entry_crc32);
+	if (zip->cctx_valid && zip->aes_vendor == AES_VENDOR_AE_2)
+		archive_le32enc(zip->file_header + 16, 0);/* no CRC.*/
+	else
+		archive_le32enc(zip->file_header + 16, zip->entry_crc32);
 	archive_le32enc(zip->file_header + 20,
-	    zipmin(zip->entry_compressed_written, ARCHIVE_LITERAL_LL(0xffffffff)));
+		(uint32_t)zipmin(zip->entry_compressed_written,
+				 ARCHIVE_LITERAL_LL(0xffffffff)));
 	archive_le32enc(zip->file_header + 24,
-	    zipmin(zip->entry_uncompressed_written, ARCHIVE_LITERAL_LL(0xffffffff)));
+		(uint32_t)zipmin(zip->entry_uncompressed_written,
+				 ARCHIVE_LITERAL_LL(0xffffffff)));
 	archive_le16enc(zip->file_header + 30,
-	    zip->central_directory_bytes - zip->file_header_extra_offset);
+	    (uint16_t)(zip->central_directory_bytes - zip->file_header_extra_offset));
 	archive_le32enc(zip->file_header + 42,
-	    zipmin(zip->entry_offset, ARCHIVE_LITERAL_LL(0xffffffff)));
+		(uint32_t)zipmin(zip->entry_offset,
+				 ARCHIVE_LITERAL_LL(0xffffffff)));
 
 	return (ARCHIVE_OK);
 }
@@ -977,10 +1327,16 @@ archive_write_zip_close(struct archive_write *a)
 	/* Format and write end of central directory. */
 	memset(buff, 0, sizeof(buff));
 	memcpy(buff, "PK\005\006", 4);
-	archive_le16enc(buff + 8, zipmin(0xffffU, zip->central_directory_entries));
-	archive_le16enc(buff + 10, zipmin(0xffffU, zip->central_directory_entries));
-	archive_le32enc(buff + 12, (uint32_t)zipmin(ARCHIVE_LITERAL_LL(0xffffffff), (offset_end - offset_start)));
-	archive_le32enc(buff + 16, (uint32_t)zipmin(ARCHIVE_LITERAL_LL(0xffffffff), offset_start));
+	archive_le16enc(buff + 8, (uint16_t)zipmin(0xffffU,
+		zip->central_directory_entries));
+	archive_le16enc(buff + 10, (uint16_t)zipmin(0xffffU,
+		zip->central_directory_entries));
+	archive_le32enc(buff + 12,
+		(uint32_t)zipmin(ARCHIVE_LITERAL_LL(0xffffffff),
+				 (offset_end - offset_start)));
+	archive_le32enc(buff + 16,
+		(uint32_t)zipmin(ARCHIVE_LITERAL_LL(0xffffffff),
+				 offset_start));
 	ret = __archive_write_output(a, buff, 22);
 	if (ret != ARCHIVE_OK)
 		return (ARCHIVE_FATAL);
@@ -1001,10 +1357,12 @@ archive_write_zip_free(struct archive_write *a)
 		free(segment->buff);
 		free(segment);
 	}
-#ifdef HAVE_ZLIB_H
 	free(zip->buf);
-#endif
 	archive_entry_free(zip->entry);
+	if (zip->cctx_valid)
+		archive_encrypto_aes_ctr_release(&zip->cctx);
+	if (zip->hctx_valid)
+		archive_hmac_sha1_cleanup(&zip->hctx);
 	/* TODO: Free opt_sconv, sconv_default */
 
 	free(zip);
@@ -1124,3 +1482,199 @@ get_sconv(struct archive_write *a, struct zip *zip)
 	}
 	return (zip->sconv_default);
 }
+
+/*
+  Traditional PKWARE Decryption functions.
+ */
+
+static void
+trad_enc_update_keys(struct trad_enc_ctx *ctx, uint8_t c)
+{
+	uint8_t t;
+#define CRC32(c, b) (crc32(c ^ 0xffffffffUL, &b, 1) ^ 0xffffffffUL)
+
+	ctx->keys[0] = CRC32(ctx->keys[0], c);
+	ctx->keys[1] = (ctx->keys[1] + (ctx->keys[0] & 0xff)) * 134775813L + 1;
+	t = (ctx->keys[1] >> 24) & 0xff;
+	ctx->keys[2] = CRC32(ctx->keys[2], t);
+#undef CRC32
+}
+
+static uint8_t
+trad_enc_decypt_byte(struct trad_enc_ctx *ctx)
+{
+	unsigned temp = ctx->keys[2] | 2;
+	return (uint8_t)((temp * (temp ^ 1)) >> 8) & 0xff;
+}
+
+static unsigned
+trad_enc_encrypt_update(struct trad_enc_ctx *ctx, const uint8_t *in,
+    size_t in_len, uint8_t *out, size_t out_len)
+{
+	unsigned i, max;
+
+	max = (unsigned)((in_len < out_len)? in_len: out_len);
+
+	for (i = 0; i < max; i++) {
+		uint8_t t = in[i];
+		out[i] = t ^ trad_enc_decypt_byte(ctx);
+		trad_enc_update_keys(ctx, t);
+	}
+	return i;
+}
+
+static int
+trad_enc_init(struct trad_enc_ctx *ctx, const char *pw, size_t pw_len)
+{
+
+	ctx->keys[0] = 305419896L;
+	ctx->keys[1] = 591751049L;
+	ctx->keys[2] = 878082192L;
+
+	for (;pw_len; --pw_len)
+		trad_enc_update_keys(ctx, *pw++);
+	return 0;
+}
+
+static int
+is_traditional_pkware_encryption_supported(void)
+{
+	uint8_t key[TRAD_HEADER_SIZE];
+
+	if (archive_random(key, sizeof(key)-1) != ARCHIVE_OK)
+		return (0);
+	return (1);
+}
+
+static int
+init_traditional_pkware_encryption(struct archive_write *a)
+{
+	struct zip *zip = a->format_data;
+	const char *passphrase;
+	uint8_t key[TRAD_HEADER_SIZE];
+	uint8_t key_encrypted[TRAD_HEADER_SIZE];
+	int ret;
+
+	passphrase = __archive_write_get_passphrase(a);
+	if (passphrase == NULL) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Encryption needs passphrase");
+		return ARCHIVE_FAILED;
+	}
+	if (archive_random(key, sizeof(key)-1) != ARCHIVE_OK) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Can't generate random number for encryption");
+		return ARCHIVE_FATAL;
+	}
+	trad_enc_init(&zip->tctx, passphrase, strlen(passphrase));
+	/* Set the last key code which will be used as a check code
+	 * for verifying passphrase in decryption. */
+	key[TRAD_HEADER_SIZE-1] = zip->trad_chkdat;
+	trad_enc_encrypt_update(&zip->tctx, key, TRAD_HEADER_SIZE,
+	    key_encrypted, TRAD_HEADER_SIZE);
+	/* Write encrypted keys in the top of the file content. */
+	ret = __archive_write_output(a, key_encrypted, TRAD_HEADER_SIZE);
+	if (ret != ARCHIVE_OK)
+		return (ret);
+	zip->written_bytes += TRAD_HEADER_SIZE;
+	zip->entry_compressed_written += TRAD_HEADER_SIZE;
+	return (ret);
+}
+
+static int
+init_winzip_aes_encryption(struct archive_write *a)
+{
+	struct zip *zip = a->format_data;
+	const char *passphrase;
+	size_t key_len, salt_len;
+	uint8_t salt[16 + 2];
+	uint8_t derived_key[MAX_DERIVED_KEY_BUF_SIZE];
+	int ret;
+
+	passphrase = __archive_write_get_passphrase(a);
+	if (passphrase == NULL) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Encryption needs passphrase");
+		return (ARCHIVE_FAILED);
+	}
+	if (zip->entry_encryption == ENCRYPTION_WINZIP_AES128) {
+		salt_len = 8;
+		key_len = 16;
+	} else {
+		/* AES 256 */
+		salt_len = 16;
+		key_len = 32;
+	}
+	if (archive_random(salt, salt_len) != ARCHIVE_OK) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Can't generate random number for encryption");
+		return (ARCHIVE_FATAL);
+	}
+	archive_pbkdf2_sha1(passphrase, strlen(passphrase),
+	    salt, salt_len, 1000, derived_key, key_len * 2 + 2);
+
+	ret = archive_encrypto_aes_ctr_init(&zip->cctx, derived_key, key_len);
+	if (ret != 0) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Decryption is unsupported due to lack of crypto library");
+		return (ARCHIVE_FAILED);
+	}
+	ret = archive_hmac_sha1_init(&zip->hctx, derived_key + key_len,
+	    key_len);
+	if (ret != 0) {
+		archive_encrypto_aes_ctr_release(&zip->cctx);
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Failed to initialize HMAC-SHA1");
+		return (ARCHIVE_FAILED);
+        }
+
+	/* Set a passowrd verification value after the 'salt'. */
+	salt[salt_len] = derived_key[key_len * 2];
+	salt[salt_len + 1] = derived_key[key_len * 2 + 1];
+
+	/* Write encrypted keys in the top of the file content. */
+	ret = __archive_write_output(a, salt, salt_len + 2);
+	if (ret != ARCHIVE_OK)
+		return (ret);
+	zip->written_bytes += salt_len + 2;
+	zip->entry_compressed_written += salt_len + 2;
+
+	return (ARCHIVE_OK);
+}
+
+static int
+is_winzip_aes_encryption_supported(int encryption)
+{
+	size_t key_len, salt_len;
+	uint8_t salt[16 + 2];
+	uint8_t derived_key[MAX_DERIVED_KEY_BUF_SIZE];
+	archive_crypto_ctx cctx;
+	archive_hmac_sha1_ctx hctx;
+	int ret;
+
+	if (encryption == ENCRYPTION_WINZIP_AES128) {
+		salt_len = 8;
+		key_len = 16;
+	} else {
+		/* AES 256 */
+		salt_len = 16;
+		key_len = 32;
+	}
+	if (archive_random(salt, salt_len) != ARCHIVE_OK)
+		return (0);
+	ret = archive_pbkdf2_sha1("p", 1, salt, salt_len, 1000,
+	    derived_key, key_len * 2 + 2);
+	if (ret != 0)
+		return (0);
+
+	ret = archive_encrypto_aes_ctr_init(&cctx, derived_key, key_len);
+	if (ret != 0)
+		return (0);
+	ret = archive_hmac_sha1_init(&hctx, derived_key + key_len,
+	    key_len);
+	archive_encrypto_aes_ctr_release(&cctx);
+	if (ret != 0)
+		return (0);
+	archive_hmac_sha1_cleanup(&hctx);
+	return (1);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_options.3 b/Utilities/cmlibarchive/libarchive/archive_write_set_options.3
index f8fb039..a2f4b57 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_set_options.3
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_options.3
@@ -397,6 +397,48 @@ Specifies a filename that should not be compressed when using
 This option can be provided multiple times to suppress compression
 on many files.
 .El
+.It Format zip
+.Bl -tag -compact -width indent
+.It Cm compression
+The value is either
+.Dq store
+or
+.Dq deflate
+to indicate how the following entries should be compressed.
+Note that this setting is ignored for directories, symbolic links,
+and other special entries.
+.It Cm experimental
+This boolean option enables or disables experimental Zip features
+that may not be compatible with other Zip implementations.
+.It Cm fakecrc32
+This boolean option disables CRC calculations.
+All CRC fields are set to zero.
+It should not be used except for testing purposes.
+.It Cm hdrcharset
+This sets the character set used for filenames.
+.It Cm zip64
+Zip64 extensions provide additional file size information
+for entries larger than 4 GiB.
+They also provide extended file offset and archive size information
+when archives exceed 4 GiB.
+By default, the Zip writer selectively enables these extensions only as needed.
+In particular, if the file size is unknown, the Zip writer will
+include Zip64 extensions to guard against the possibility that the
+file might be larger than 4 GiB.
+.Pp
+Setting this boolean option will force the writer to use Zip64 extensions
+even for small files that would not otherwise require them.
+This is primarily useful for testing.
+.Pp
+Disabling this option with
+.Cm !zip64
+will force the Zip writer to avoid Zip64 extensions:
+It will reject files with size greater than 4 GiB,
+it will reject any new entries once the total archive size reaches 4 GiB,
+and it will not use Zip64 extensions for files with unknown size.
+In particular, this can improve compatibility when generating archives
+where the entry sizes are not known in advance.
+.El
 .El
 .Sh EXAMPLES
 The following example creates an archive write handle to
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_data.3 b/Utilities/cmlibarchive/libarchive/archive_write_set_passphrase.3
similarity index 60%
copy from Utilities/cmlibarchive/libarchive/archive_write_data.3
copy to Utilities/cmlibarchive/libarchive/archive_write_set_passphrase.3
index cfd5cd5..2585595 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_data.3
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_passphrase.3
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2003-2011 Tim Kientzle
+.\" Copyright (c) 2014 Michihiro NAKAJIMA
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -24,39 +24,51 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd February 2, 2012
-.Dt ARCHIVE_WRITE_DATA 3
+.Dd September 21, 2014
+.Dt ARCHIVE_WRITE_SET_PASSPHRASE 3
 .Os
 .Sh NAME
-.Nm archive_write_data
-.Nd functions for creating archives
+.Nm archive_write_set_passphrase ,
+.Nm archive_write_set_passphrase_callback
+.Nd functions for writing encrypted archives
 .Sh LIBRARY
 Streaming Archive Library (libarchive, -larchive)
 .Sh SYNOPSIS
 .In archive.h
-.Ft ssize_t
-.Fn archive_write_data "struct archive *" "const void *" "size_t"
+.Ft int
+.Fo archive_write_set_passphrase
+.Fa "struct archive *"
+.Fa "const char *passphrase"
+.Fc
+.Ft int
+.Fo archive_write_set_passphrase_callback
+.Fa "struct archive *"
+.Fa "void *client_data"
+.Fa "archive_passphrase_callback *"
+.Fc
 .Sh DESCRIPTION
-Write data corresponding to the header just written.
-.\" .Sh EXAMPLE
-.\"
-.Sh RETURN VALUES
-This function returns the number of bytes actually written, or
-.Li -1
-on error.
-.\"
-.Sh ERRORS
-Detailed error codes and textual descriptions are available from the
-.Fn archive_errno
-and
-.Fn archive_error_string
-functions.
-.\"
+.Bl -tag -width indent
+.It Fn archive_write_set_passphrase
+Set a passphrase for writing an encryption archive.
+If
+.Ar passphrase
+is
+.Dv NULL
+or empty, this function will do nothing and
+.Cm ARCHIVE_FAILED
+will be returned.
+Otherwise,
+.Cm ARCHIVE_OK
+will be returned. 
+.It Fn archive_write_set_passphrase_callback
+Register callback function that will be invoked to get a passphrase
+for encrption if the passphrase was not set by the
+.Fn archive_write_set_passphrase
+function.
+.El
+.\" .Sh ERRORS
 .Sh SEE ALSO
 .Xr tar 1 ,
 .Xr libarchive 3 ,
-.Xr archive_write_finish_entry 3 ,
-.Xr archive_write_set_options 3 ,
-.Xr cpio 5 ,
-.Xr mtree 5 ,
-.Xr tar 5
+.Xr archive_write 3 ,
+.Xr archive_write_set_options 3
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_passphrase.c b/Utilities/cmlibarchive/libarchive/archive_write_set_passphrase.c
new file mode 100644
index 0000000..710ecba
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_passphrase.c
@@ -0,0 +1,95 @@
+/*-
+ * Copyright (c) 2014 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "archive_platform.h"
+__FBSDID("$FreeBSD$");
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include "archive_write_private.h"
+
+int
+archive_write_set_passphrase(struct archive *_a, const char *p)
+{
+	struct archive_write *a = (struct archive_write *)_a;
+
+	archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW,
+		"archive_write_set_passphrase");
+
+	if (p == NULL || p[0] == '\0') {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Empty passphrase is unacceptable");
+		return (ARCHIVE_FAILED);
+	}
+	free(a->passphrase);
+	a->passphrase = strdup(p);
+	if (a->passphrase == NULL) {
+		archive_set_error(&a->archive, ENOMEM,
+		    "Can't allocate data for passphrase");
+		return (ARCHIVE_FATAL);
+	}
+	return (ARCHIVE_OK);
+}
+
+
+int
+archive_write_set_passphrase_callback(struct archive *_a, void *client_data,
+    archive_passphrase_callback *cb)
+{
+	struct archive_write *a = (struct archive_write *)_a;
+
+	archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW,
+		"archive_write_set_passphrase_callback");
+
+	a->passphrase_callback = cb;
+	a->passphrase_client_data = client_data;
+	return (ARCHIVE_OK);
+}
+
+
+const char *
+__archive_write_get_passphrase(struct archive_write *a)
+{
+
+	if (a->passphrase != NULL)
+		return (a->passphrase);
+
+	if (a->passphrase_callback != NULL) {
+		const char *p;
+		p = a->passphrase_callback(&a->archive,
+		    a->passphrase_client_data);
+		if (p != NULL) {
+			a->passphrase = strdup(p);
+			if (a->passphrase == NULL) {
+				archive_set_error(&a->archive, ENOMEM,
+				    "Can't allocate data for passphrase");
+				return (NULL);
+			}
+			return (a->passphrase);
+		}
+	}
+	return (NULL);
+}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c b/Utilities/cmlibarchive/libarchive/archive_xxhash.h
similarity index 50%
copy from Utilities/cmlibarchive/libarchive/archive_write_add_filter.c
copy to Utilities/cmlibarchive/libarchive/archive_xxhash.h
index 81dd683..4272416 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c
+++ b/Utilities/cmlibarchive/libarchive/archive_xxhash.h
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2012 Ondrej Holy
+ * Copyright (c) 2014 Michihiro NAKAJIMA
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -21,50 +21,27 @@
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
  */
 
-#include "archive_platform.h"
-__FBSDID("$FreeBSD$");
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
+#ifndef __LIBARCHIVE_BUILD
+#error This header is only to be used internally to libarchive.
 #endif
 
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
+#ifndef ARCHIVE_XXHASH_H
+#define ARCHIVE_XXHASH_H
 
-#include "archive.h"
-#include "archive_private.h"
+typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
 
-/* A table that maps filter codes to functions. */
-static
-struct { int code; int (*setter)(struct archive *); } codes[] =
-{
-	{ ARCHIVE_FILTER_NONE,		archive_write_add_filter_none },
-	{ ARCHIVE_FILTER_GZIP,		archive_write_add_filter_gzip },
-	{ ARCHIVE_FILTER_BZIP2,		archive_write_add_filter_bzip2 },
-	{ ARCHIVE_FILTER_COMPRESS,	archive_write_add_filter_compress },
-	{ ARCHIVE_FILTER_GRZIP,		archive_write_add_filter_grzip },
-	{ ARCHIVE_FILTER_LRZIP,		archive_write_add_filter_lrzip },
-	{ ARCHIVE_FILTER_LZIP,		archive_write_add_filter_lzip },
-	{ ARCHIVE_FILTER_LZMA,		archive_write_add_filter_lzma },
-	{ ARCHIVE_FILTER_LZOP,		archive_write_add_filter_lzip },
-	{ ARCHIVE_FILTER_UU,		archive_write_add_filter_uuencode },
-	{ ARCHIVE_FILTER_XZ,		archive_write_add_filter_xz },
-	{ -1,			NULL }
+struct archive_xxhash {
+	unsigned int  (*XXH32)(const void* input, unsigned int len,
+			unsigned int seed);
+	void*         (*XXH32_init)(unsigned int seed);
+	XXH_errorcode (*XXH32_update)(void* state, const void* input,
+			unsigned int len);
+	unsigned int  (*XXH32_digest)(void* state);
 };
 
-int
-archive_write_add_filter(struct archive *a, int code)
-{
-	int i;
+extern const struct archive_xxhash __archive_xxhash;
 
-	for (i = 0; codes[i].code != -1; i++) {
-		if (code == codes[i].code)
-			return ((codes[i].setter)(a));
-	}
-
-	archive_set_error(a, EINVAL, "No such filter");
-	return (ARCHIVE_FATAL);
-}
+#endif
diff --git a/Utilities/cmlibarchive/libarchive/libarchive.3 b/Utilities/cmlibarchive/libarchive/libarchive.3
index 3a9a841..c6894d2 100644
--- a/Utilities/cmlibarchive/libarchive/libarchive.3
+++ b/Utilities/cmlibarchive/libarchive/libarchive.3
@@ -146,11 +146,11 @@ pages for each API or utility function.
 .\"
 .Sh READING AN ARCHIVE
 See
-.Xr libarchive_read 3 .
+.Xr archive_read 3 .
 .\"
 .Sh WRITING AN ARCHIVE
 See
-.Xr libarchive_write 3 .
+.Xr archive_write 3 .
 .\"
 .Sh WRITING ENTRIES TO DISK
 The
diff --git a/Utilities/cmlibarchive/libarchive/libarchive_internals.3 b/Utilities/cmlibarchive/libarchive/libarchive_internals.3
index 4aa09f9..8275d66 100644
--- a/Utilities/cmlibarchive/libarchive/libarchive_internals.3
+++ b/Utilities/cmlibarchive/libarchive/libarchive_internals.3
@@ -347,11 +347,11 @@ Fortunately, such archives are very rare, and libarchive can read
 most ZIP archives, though it cannot always extract as much information
 as a dedicated ZIP program.
 .Sh SEE ALSO
-.Xr archive 3 ,
 .Xr archive_entry 3 ,
 .Xr archive_read 3 ,
 .Xr archive_write 3 ,
 .Xr archive_write_disk 3
+.Xr libarchive 3 ,
 .Sh HISTORY
 The
 .Nm libarchive
diff --git a/Utilities/cmlibarchive/libarchive/mtree.5 b/Utilities/cmlibarchive/libarchive/mtree.5
index 8c45a7d..16c8abe 100644
--- a/Utilities/cmlibarchive/libarchive/mtree.5
+++ b/Utilities/cmlibarchive/libarchive/mtree.5
@@ -56,14 +56,6 @@ corresponding character.
 .Pp
 Each line is interpreted independently as one of the following types:
 .Bl -tag -width Cm
-.It Signature
-The first line of any mtree file must begin with
-.Dq #mtree .
-If a file contains any full path entries, the first line should
-begin with
-.Dq #mtree v2.0 ,
-otherwise, the first line should begin with
-.Dq #mtree v1.0 .
 .It Blank
 Blank lines are ignored.
 .It Comment
@@ -302,16 +294,6 @@ The file owner as a symbolic name.
 .Xr find 1 ,
 .Xr mtree 8
 .Sh BUGS
-The
-.Fx
-implementation of mtree does not currently support
-the
-.Nm
-2.0
-format.
-The requirement for a
-.Dq #mtree
-signature line is new and not yet widely implemented.
 .Sh HISTORY
 The
 .Nm
diff --git a/Utilities/cmlibarchive/libarchive/tar.5 b/Utilities/cmlibarchive/libarchive/tar.5
index 688bb92..6e6f0c0 100644
--- a/Utilities/cmlibarchive/libarchive/tar.5
+++ b/Utilities/cmlibarchive/libarchive/tar.5
@@ -935,7 +935,7 @@ and formed the basis of
 (circa 1988).
 Joerg Shilling's
 .Nm star
-archiver is another open-source (GPL) archiver (originally developed
+archiver is another open-source (CDDL) archiver (originally developed
 circa 1985) which features complete support for pax interchange
 format.
 .Pp
diff --git a/Utilities/cmlibarchive/libarchive/xxhash.c b/Utilities/cmlibarchive/libarchive/xxhash.c
new file mode 100644
index 0000000..f7647a5
--- /dev/null
+++ b/Utilities/cmlibarchive/libarchive/xxhash.c
@@ -0,0 +1,500 @@
+/*
+xxHash - Fast Hash algorithm
+Copyright (C) 2012-2014, Yann Collet.
+BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+* Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+You can contact the author at :
+- xxHash source repository : http://code.google.com/p/xxhash/
+*/
+
+#include "archive_platform.h"
+#ifdef HAVE_LIBLZ4
+
+/***************************************
+** Tuning parameters
+****************************************/
+/* Unaligned memory access is automatically enabled for "common" CPU, such as x86.
+** For others CPU, the compiler will be more cautious, and insert extra code to ensure aligned access is respected.
+** If you know your target CPU supports unaligned memory access, you want to force this option manually to improve performance.
+** You can also enable this parameter if you know your input data will always be aligned (boundaries of 4, for U32).
+*/
+#if defined(__ARM_FEATURE_UNALIGNED) || defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)
+#  define XXH_USE_UNALIGNED_ACCESS 1
+#endif
+
+/* XXH_ACCEPT_NULL_INPUT_POINTER :
+** If the input pointer is a null pointer, xxHash default behavior is to trigger a memory access error, since it is a bad pointer.
+** When this option is enabled, xxHash output for null input pointers will be the same as a null-length input.
+** This option has a very small performance cost (only measurable on small inputs).
+** By default, this option is disabled. To enable it, uncomment below define :
+** #define XXH_ACCEPT_NULL_INPUT_POINTER 1
+
+** XXH_FORCE_NATIVE_FORMAT :
+** By default, xxHash library provides endian-independant Hash values, based on little-endian convention.
+** Results are therefore identical for little-endian and big-endian CPU.
+** This comes at a performance cost for big-endian CPU, since some swapping is required to emulate little-endian format.
+** Should endian-independance be of no importance for your application, you may set the #define below to 1.
+** It will improve speed for Big-endian CPU.
+** This option has no impact on Little_Endian CPU.
+*/
+#define XXH_FORCE_NATIVE_FORMAT 0
+
+/***************************************
+** Compiler Specific Options
+****************************************/
+/* Disable some Visual warning messages */
+#ifdef _MSC_VER  /* Visual Studio */
+#  pragma warning(disable : 4127)      /* disable: C4127: conditional expression is constant */
+#endif
+
+#ifdef _MSC_VER    /* Visual Studio */
+#  define FORCE_INLINE __forceinline
+#else
+#  ifdef __GNUC__
+#    define FORCE_INLINE inline __attribute__((always_inline))
+#  else
+#    define FORCE_INLINE inline
+#  endif
+#endif
+
+/***************************************
+** Includes & Memory related functions
+****************************************/
+#include "archive_xxhash.h"
+#include <stdlib.h>
+#define XXH_malloc malloc
+#define XXH_free free
+#include <string.h>
+#define XXH_memcpy memcpy
+
+
+static unsigned int	  XXH32 (const void*, unsigned int, unsigned int);
+static void*		  XXH32_init   (unsigned int);
+static XXH_errorcode	  XXH32_update (void*, const void*, unsigned int);
+static unsigned int	  XXH32_digest (void*);
+/*static int		  XXH32_sizeofState(void);*/
+static XXH_errorcode	  XXH32_resetState(void*, unsigned int);
+#define       XXH32_SIZEOFSTATE 48
+typedef struct { long long ll[(XXH32_SIZEOFSTATE+(sizeof(long long)-1))/sizeof(long long)]; } XXH32_stateSpace_t;
+static unsigned int	  XXH32_intermediateDigest (void*);
+
+/***************************************
+** Basic Types
+****************************************/
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L   /* C99 */
+# include <stdint.h>
+  typedef uint8_t  BYTE;
+  typedef uint16_t U16;
+  typedef uint32_t U32;
+  typedef  int32_t S32;
+  typedef uint64_t U64;
+#else
+  typedef unsigned char      BYTE;
+  typedef unsigned short     U16;
+  typedef unsigned int       U32;
+  typedef   signed int       S32;
+  typedef unsigned long long U64;
+#endif
+
+#if defined(__GNUC__)  && !defined(XXH_USE_UNALIGNED_ACCESS)
+#  define _PACKED __attribute__ ((packed))
+#else
+#  define _PACKED
+#endif
+
+#if !defined(XXH_USE_UNALIGNED_ACCESS) && !defined(__GNUC__)
+#  ifdef __IBMC__
+#    pragma pack(1)
+#  else
+#    pragma pack(push, 1)
+#  endif
+#endif
+
+typedef struct _U32_S { U32 v; } _PACKED U32_S;
+
+#if !defined(XXH_USE_UNALIGNED_ACCESS) && !defined(__GNUC__)
+#  pragma pack(pop)
+#endif
+
+#define A32(x) (((const U32_S *)(x))->v)
+
+
+/****************************************
+** Compiler-specific Functions and Macros
+*****************************************/
+#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
+
+/* Note : although _rotl exists for minGW (GCC under windows), performance seems poor */
+#if defined(_MSC_VER)
+#  define XXH_rotl32(x,r) _rotl(x,r)
+#else
+#  define XXH_rotl32(x,r) ((x << r) | (x >> (32 - r)))
+#endif
+
+#if defined(_MSC_VER)     /* Visual Studio */
+#  define XXH_swap32 _byteswap_ulong
+#elif GCC_VERSION >= 403
+#  define XXH_swap32 __builtin_bswap32
+#else
+static inline U32 XXH_swap32 (U32 x) {
+    return  ((x << 24) & 0xff000000 ) |
+			((x <<  8) & 0x00ff0000 ) |
+			((x >>  8) & 0x0000ff00 ) |
+			((x >> 24) & 0x000000ff );}
+#endif
+
+
+/***************************************
+** Constants
+****************************************/
+#define PRIME32_1   2654435761U
+#define PRIME32_2   2246822519U
+#define PRIME32_3   3266489917U
+#define PRIME32_4    668265263U
+#define PRIME32_5    374761393U
+
+
+/***************************************
+** Architecture Macros
+****************************************/
+typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess;
+#ifndef XXH_CPU_LITTLE_ENDIAN   /* It is possible to define XXH_CPU_LITTLE_ENDIAN externally, for example using a compiler switch */
+    static const int one = 1;
+#   define XXH_CPU_LITTLE_ENDIAN   (*(const char*)(&one))
+#endif
+
+
+/***************************************
+** Macros
+****************************************/
+#define XXH_STATIC_ASSERT(c)   { enum { XXH_static_assert = 1/(!!(c)) }; }    /* use only *after* variable declarations */
+
+
+/*****************************
+** Memory reads
+******************************/
+typedef enum { XXH_aligned, XXH_unaligned } XXH_alignment;
+
+static
+FORCE_INLINE U32 XXH_readLE32_align(const U32* ptr, XXH_endianess endian, XXH_alignment align)
+{
+    if (align==XXH_unaligned)
+        return endian==XXH_littleEndian ? A32(ptr) : XXH_swap32(A32(ptr));
+    else
+        return endian==XXH_littleEndian ? *ptr : XXH_swap32(*ptr);
+}
+
+static
+FORCE_INLINE U32 XXH_readLE32(const U32* ptr, XXH_endianess endian) { return XXH_readLE32_align(ptr, endian, XXH_unaligned); }
+
+
+/*****************************
+** Simple Hash Functions
+******************************/
+static
+FORCE_INLINE U32 XXH32_endian_align(const void* input, unsigned int len, U32 seed, XXH_endianess endian, XXH_alignment align)
+{
+    const BYTE* p = (const BYTE*)input;
+    const BYTE* bEnd = p + len;
+    U32 h32;
+#define XXH_get32bits(p) XXH_readLE32_align((const U32*)p, endian, align)
+
+#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
+    if (p==NULL) { len=0; bEnd=p=(const BYTE*)(size_t)16; }
+#endif
+
+    if (len>=16)
+    {
+        const BYTE* const limit = bEnd - 16;
+        U32 v1 = seed + PRIME32_1 + PRIME32_2;
+        U32 v2 = seed + PRIME32_2;
+        U32 v3 = seed + 0;
+        U32 v4 = seed - PRIME32_1;
+
+        do
+        {
+            v1 += XXH_get32bits(p) * PRIME32_2; v1 = XXH_rotl32(v1, 13); v1 *= PRIME32_1; p+=4;
+            v2 += XXH_get32bits(p) * PRIME32_2; v2 = XXH_rotl32(v2, 13); v2 *= PRIME32_1; p+=4;
+            v3 += XXH_get32bits(p) * PRIME32_2; v3 = XXH_rotl32(v3, 13); v3 *= PRIME32_1; p+=4;
+            v4 += XXH_get32bits(p) * PRIME32_2; v4 = XXH_rotl32(v4, 13); v4 *= PRIME32_1; p+=4;
+        } while (p<=limit);
+
+        h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7) + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18);
+    }
+    else
+    {
+        h32  = seed + PRIME32_5;
+    }
+
+    h32 += (U32) len;
+
+    while (p<=bEnd-4)
+    {
+        h32 += XXH_get32bits(p) * PRIME32_3;
+        h32  = XXH_rotl32(h32, 17) * PRIME32_4 ;
+        p+=4;
+    }
+
+    while (p<bEnd)
+    {
+        h32 += (*p) * PRIME32_5;
+        h32 = XXH_rotl32(h32, 11) * PRIME32_1 ;
+        p++;
+    }
+
+    h32 ^= h32 >> 15;
+    h32 *= PRIME32_2;
+    h32 ^= h32 >> 13;
+    h32 *= PRIME32_3;
+    h32 ^= h32 >> 16;
+
+    return h32;
+}
+
+
+U32 XXH32(const void* input, unsigned int len, U32 seed)
+{
+#if 0
+    // Simple version, good for code maintenance, but unfortunately slow for small inputs
+    void* state = XXH32_init(seed);
+    XXH32_update(state, input, len);
+    return XXH32_digest(state);
+#else
+    XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
+
+#  if !defined(XXH_USE_UNALIGNED_ACCESS)
+    if ((((size_t)input) & 3) == 0)   /* Input is aligned, let's leverage the speed advantage */
+    {
+        if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
+            return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned);
+        else
+            return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned);
+    }
+#  endif
+
+    if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
+        return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned);
+    else
+        return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned);
+#endif
+}
+
+/*****************************
+** Advanced Hash Functions
+******************************/
+
+struct XXH_state32_t
+{
+    U64 total_len;
+    U32 seed;
+    U32 v1;
+    U32 v2;
+    U32 v3;
+    U32 v4;
+    int memsize;
+    char memory[16];
+};
+
+#if 0
+static
+int XXH32_sizeofState(void)
+{
+    XXH_STATIC_ASSERT(XXH32_SIZEOFSTATE >= sizeof(struct XXH_state32_t));   /* A compilation error here means XXH32_SIZEOFSTATE is not large enough */
+    return sizeof(struct XXH_state32_t);
+}
+#endif
+
+static
+XXH_errorcode XXH32_resetState(void* state_in, U32 seed)
+{
+    struct XXH_state32_t * state = (struct XXH_state32_t *) state_in;
+    state->seed = seed;
+    state->v1 = seed + PRIME32_1 + PRIME32_2;
+    state->v2 = seed + PRIME32_2;
+    state->v3 = seed + 0;
+    state->v4 = seed - PRIME32_1;
+    state->total_len = 0;
+    state->memsize = 0;
+    return XXH_OK;
+}
+
+static
+void* XXH32_init (U32 seed)
+{
+    void* state = XXH_malloc (sizeof(struct XXH_state32_t));
+    XXH32_resetState(state, seed);
+    return state;
+}
+
+static
+FORCE_INLINE XXH_errorcode XXH32_update_endian (void* state_in, const void* input, int len, XXH_endianess endian)
+{
+    struct XXH_state32_t * state = (struct XXH_state32_t *) state_in;
+    const BYTE* p = (const BYTE*)input;
+    const BYTE* const bEnd = p + len;
+
+#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
+    if (input==NULL) return XXH_ERROR;
+#endif
+
+    state->total_len += len;
+
+    if (state->memsize + len < 16)   /* fill in tmp buffer */
+    {
+        XXH_memcpy(state->memory + state->memsize, input, len);
+        state->memsize +=  len;
+        return XXH_OK;
+    }
+
+    if (state->memsize)   /* some data left from previous update */
+    {
+        XXH_memcpy(state->memory + state->memsize, input, 16-state->memsize);
+        {
+            const U32* p32 = (const U32*)state->memory;
+            state->v1 += XXH_readLE32(p32, endian) * PRIME32_2; state->v1 = XXH_rotl32(state->v1, 13); state->v1 *= PRIME32_1; p32++;
+            state->v2 += XXH_readLE32(p32, endian) * PRIME32_2; state->v2 = XXH_rotl32(state->v2, 13); state->v2 *= PRIME32_1; p32++;
+            state->v3 += XXH_readLE32(p32, endian) * PRIME32_2; state->v3 = XXH_rotl32(state->v3, 13); state->v3 *= PRIME32_1; p32++;
+            state->v4 += XXH_readLE32(p32, endian) * PRIME32_2; state->v4 = XXH_rotl32(state->v4, 13); state->v4 *= PRIME32_1; p32++;
+        }
+        p += 16-state->memsize;
+        state->memsize = 0;
+    }
+
+    if (p <= bEnd-16)
+    {
+        const BYTE* const limit = bEnd - 16;
+        U32 v1 = state->v1;
+        U32 v2 = state->v2;
+        U32 v3 = state->v3;
+        U32 v4 = state->v4;
+
+        do
+        {
+            v1 += XXH_readLE32((const U32*)p, endian) * PRIME32_2; v1 = XXH_rotl32(v1, 13); v1 *= PRIME32_1; p+=4;
+            v2 += XXH_readLE32((const U32*)p, endian) * PRIME32_2; v2 = XXH_rotl32(v2, 13); v2 *= PRIME32_1; p+=4;
+            v3 += XXH_readLE32((const U32*)p, endian) * PRIME32_2; v3 = XXH_rotl32(v3, 13); v3 *= PRIME32_1; p+=4;
+            v4 += XXH_readLE32((const U32*)p, endian) * PRIME32_2; v4 = XXH_rotl32(v4, 13); v4 *= PRIME32_1; p+=4;
+        } while (p<=limit);
+
+        state->v1 = v1;
+        state->v2 = v2;
+        state->v3 = v3;
+        state->v4 = v4;
+    }
+
+    if (p < bEnd)
+    {
+        XXH_memcpy(state->memory, p, bEnd-p);
+        state->memsize = (int)(bEnd-p);
+    }
+
+    return XXH_OK;
+}
+
+static
+XXH_errorcode XXH32_update (void* state_in, const void* input, unsigned int len)
+{
+    XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
+
+    if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
+        return XXH32_update_endian(state_in, input, len, XXH_littleEndian);
+    else
+        return XXH32_update_endian(state_in, input, len, XXH_bigEndian);
+}
+
+
+
+static
+FORCE_INLINE U32 XXH32_intermediateDigest_endian (void* state_in, XXH_endianess endian)
+{
+    struct XXH_state32_t * state = (struct XXH_state32_t *) state_in;
+    const BYTE * p = (const BYTE*)state->memory;
+    BYTE* bEnd = (BYTE*)state->memory + state->memsize;
+    U32 h32;
+
+    if (state->total_len >= 16)
+    {
+        h32 = XXH_rotl32(state->v1, 1) + XXH_rotl32(state->v2, 7) + XXH_rotl32(state->v3, 12) + XXH_rotl32(state->v4, 18);
+    }
+    else
+    {
+        h32  = state->seed + PRIME32_5;
+    }
+
+    h32 += (U32) state->total_len;
+
+    while (p<=bEnd-4)
+    {
+        h32 += XXH_readLE32((const U32*)p, endian) * PRIME32_3;
+        h32  = XXH_rotl32(h32, 17) * PRIME32_4;
+        p+=4;
+    }
+
+    while (p<bEnd)
+    {
+        h32 += (*p) * PRIME32_5;
+        h32 = XXH_rotl32(h32, 11) * PRIME32_1;
+        p++;
+    }
+
+    h32 ^= h32 >> 15;
+    h32 *= PRIME32_2;
+    h32 ^= h32 >> 13;
+    h32 *= PRIME32_3;
+    h32 ^= h32 >> 16;
+
+    return h32;
+}
+
+static
+U32 XXH32_intermediateDigest (void* state_in)
+{
+    XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
+
+    if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
+        return XXH32_intermediateDigest_endian(state_in, XXH_littleEndian);
+    else
+        return XXH32_intermediateDigest_endian(state_in, XXH_bigEndian);
+}
+
+static
+U32 XXH32_digest (void* state_in)
+{
+    U32 h32 = XXH32_intermediateDigest(state_in);
+
+    XXH_free(state_in);
+
+    return h32;
+}
+
+const
+struct archive_xxhash __archive_xxhash = {
+	XXH32,
+	XXH32_init,
+	XXH32_update,
+	XXH32_digest
+};
+#endif /* HAVE_LIBLZ4 */
diff --git a/bootstrap b/bootstrap
index 31e9b89..b3f06a1 100755
--- a/bootstrap
+++ b/bootstrap
@@ -63,9 +63,11 @@ cmake_copyright="`grep '^Copyright .* Kitware' "${cmake_source_dir}/Copyright.tx
 cmake_data_dir_keyword="OTHER"
 cmake_doc_dir_keyword="OTHER"
 cmake_man_dir_keyword="OTHER"
+cmake_xdgdata_dir_keyword="OTHER"
 cmake_data_dir=""
 cmake_doc_dir=""
 cmake_man_dir=""
+cmake_xdgdata_dir=""
 cmake_init_file=""
 cmake_bootstrap_system_libs=""
 cmake_bootstrap_qt_gui=""
@@ -214,6 +216,7 @@ fi
 cmake_data_dir_default="`cmake_install_dest_default DATA ${cmake_data_dir_keyword}`"
 cmake_doc_dir_default="`cmake_install_dest_default DOC ${cmake_doc_dir_keyword}`"
 cmake_man_dir_default="`cmake_install_dest_default MAN ${cmake_man_dir_keyword}`"
+cmake_xdgdata_dir_default="`cmake_install_dest_default XDGDATA ${cmake_xdgdata_dir_keyword}`"
 
 CMAKE_KNOWN_C_COMPILERS="cc gcc xlc icc tcc"
 CMAKE_KNOWN_CXX_COMPILERS="aCC xlC CC g++ c++ icc como "
@@ -259,8 +262,8 @@ CMAKE_CXX_SOURCES="\
   cmPropertyMap \
   cmPropertyDefinition \
   cmPropertyDefinitionMap \
-  cmMakeDepend \
   cmMakefile \
+  cmExportBuildFileGenerator \
   cmExportFileGenerator \
   cmExportInstallFileGenerator \
   cmExportTryCompileFileGenerator \
@@ -373,11 +376,6 @@ KWSYS_FILES="\
   SystemTools.hxx \
   Terminal.h"
 
-KWIML_FILES='
-  ABI.h
-  INT.h
-'
-
 # Display CMake bootstrap usage
 cmake_usage()
 {
@@ -406,6 +404,8 @@ Configuration:
   --no-system-zlib        use cmake-provided zlib library (default)
   --system-bzip2          use system-installed bzip2 library
   --no-system-bzip2       use cmake-provided bzip2 library (default)
+  --system-liblzma        use system-installed liblzma library
+  --no-system-liblzma     use cmake-provided liblzma library (default)
   --system-libarchive     use system-installed libarchive library
   --no-system-libarchive  use cmake-provided libarchive library (default)
 
@@ -428,6 +428,8 @@ Directory and file names:
                           ['"${cmake_doc_dir_default}"']
   --mandir=DIR            install man pages files in PREFIX/DIR/manN
                           ['"${cmake_man_dir_default}"']
+  --xdgdatadir=DIR        install XDG specific files in PREFIX/DIR
+                          ['"${cmake_xdgdata_dir_default}"']
 '
   exit 10
 }
@@ -455,6 +457,18 @@ cmake_error()
   exit ${res}
 }
 
+cmake_generate_file ()
+{
+  OUTFILE="$1"
+  CONTENT="$2"
+  echo "$CONTENT" > "$OUTFILE.tmp"
+  if "${_diff}" "$OUTFILE.tmp" "$OUTFILE" > /dev/null 2> /dev/null ; then
+    rm -f "$OUTFILE.tmp"
+  else
+    mv -f "$OUTFILE.tmp" "$OUTFILE"
+  fi
+}
+
 # Replace KWSYS_NAMESPACE with cmsys
 cmake_replace_string ()
 {
@@ -493,7 +507,7 @@ cmake_kwsys_config_replace_string ()
                 s/@KWSYS_LFS_REQUESTED@/${KWSYS_LFS_REQUESTED}/g;
                 s/@KWSYS_NAME_IS_KWSYS@/${KWSYS_NAME_IS_KWSYS}/g;
                 s/@KWSYS_STL_HAS_WSTRING@/${KWSYS_STL_HAS_WSTRING}/g;
-                s/@KWSYS_STAT_HAS_ST_MTIM@/${KWSYS_STAT_HAS_ST_MTIM}/g;}" >> "${OUTFILE}${_tmp}"
+               }" >> "${OUTFILE}${_tmp}"
     if [ -f "${OUTFILE}${_tmp}" ]; then
       if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then
         #echo "Files are the same"
@@ -572,7 +586,7 @@ cmake_try_run ()
     echo "Test produced non-zero return code"
     return 3
   fi
-  echo "Test succeded"
+  echo "Test succeeded"
   return 0
 }
 
@@ -616,13 +630,14 @@ while test $# != 0; do
   --datadir=*) cmake_data_dir=`cmake_arg "$1"` ;;
   --docdir=*) cmake_doc_dir=`cmake_arg "$1"` ;;
   --mandir=*) cmake_man_dir=`cmake_arg "$1"` ;;
+  --xdgdatadir=*) cmake_xdgdata_dir=`cmake_arg "$1"` ;;
   --init=*) cmake_init_file=`cmake_arg "$1"` ;;
   --system-libs) cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=1" ;;
   --no-system-libs) cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=0" ;;
-  --system-bzip2|--system-curl|--system-expat|--system-jsoncpp|--system-libarchive|--system-zlib)
+  --system-bzip2|--system-curl|--system-expat|--system-jsoncpp|--system-libarchive|--system-zlib|--system-liblzma)
     lib=`cmake_arg "$1" "--system-"`
     cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper $lib`=1" ;;
-  --no-system-bzip2|--no-system-curl|--no-system-expat|--no-system-jsoncpp|--no-system-libarchive|--no-system-zlib)
+  --no-system-bzip2|--no-system-curl|--no-system-expat|--no-system-jsoncpp|--no-system-libarchive|--no-system-zlib|--no-system-liblzma)
     lib=`cmake_arg "$1" "--no-system-"`
     cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper $lib`=0" ;;
   --qt-gui) cmake_bootstrap_qt_gui="1" ;;
@@ -702,18 +717,6 @@ if [ ! -d "cmsys" ]; then
   cmake_error 4 "Cannot create directory ${cmake_bootstrap_dir}/cmsys"
 fi
 
-for a in stl ios; do
-  [ -d "cmsys/${a}" ] || mkdir "cmsys/${a}"
-  if [ ! -d "cmsys/${a}" ]; then
-    cmake_error 5 "Cannot create directory ${cmake_bootstrap_dir}/cmsys/${a}"
-  fi
-done
-
-[ -d "cmIML" ] || mkdir "cmIML"
-if [ ! -d "cmIML" ]; then
-  cmake_error 12 "Cannot create directory ${cmake_bootstrap_dir}/cmIML"
-fi
-
 # Delete all the bootstrap files
 rm -f "${cmake_bootstrap_dir}/cmake_bootstrap.log"
 rm -f "${cmake_bootstrap_dir}/cmConfigure.h${_tmp}"
@@ -1173,7 +1176,6 @@ KWSYS_NAME_IS_KWSYS=0
 KWSYS_BUILD_SHARED=0
 KWSYS_LFS_AVAILABLE=0
 KWSYS_LFS_REQUESTED=0
-KWSYS_STAT_HAS_ST_MTIM=0
 KWSYS_STL_HAS_WSTRING=0
 KWSYS_CXX_HAS_SETENV=0
 KWSYS_CXX_HAS_UNSETENV=0
@@ -1217,15 +1219,6 @@ else
   echo "${cmake_cxx_compiler} does not have stl wstring"
 fi
 
-if cmake_try_run "${cmake_cxx_compiler}" \
-  "${cmake_cxx_flags} -DTEST_KWSYS_STAT_HAS_ST_MTIM" \
-  "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
-  KWSYS_STAT_HAS_ST_MTIM=1
-  echo "${cmake_cxx_compiler} has struct stat with st_mtim member"
-else
-  echo "${cmake_cxx_compiler} does not have struct stat with st_mtim member"
-fi
-
 # Just to be safe, let us store compiler and flags to the header file
 
 cmake_bootstrap_version='$Revision$'
@@ -1297,10 +1290,7 @@ for a in ${KWSYS_FILES}; do
      "${cmake_bootstrap_dir}/cmsys/${a}" KWSYS_NAMESPACE cmsys
 done
 
-for a in ${KWIML_FILES}; do
-  cmake_replace_string "${cmake_source_dir}/Utilities/KWIML/${a}.in" \
-     "${cmake_bootstrap_dir}/cmIML/${a}" KWIML cmIML
-done
+cmake_generate_file "${cmake_bootstrap_dir}/cmThirdParty.h" ""
 
 # Generate Makefile
 dep="cmConfigure.h cmsys/*.hxx cmsys/*.h `cmake_escape \"${cmake_source_dir}\"`/Source/*.h"
@@ -1343,9 +1333,9 @@ cmake_cxx_flags_SystemTools="
   -DKWSYS_CXX_HAS_UTIMES=${KWSYS_CXX_HAS_UTIMES}
 "
 cmake_c_flags="${cmake_c_flags}-I`cmake_escape \"${cmake_bootstrap_dir}\"` -I`cmake_escape \"${cmake_source_dir}/Source\"` \
-  -I`cmake_escape \"${cmake_bootstrap_dir}\"`"
+  -I`cmake_escape \"${cmake_source_dir}/Utilities\"`"
 cmake_cxx_flags="${cmake_cxx_flags} -I`cmake_escape \"${cmake_bootstrap_dir}\"` -I`cmake_escape \"${cmake_source_dir}/Source\"` \
-  -I`cmake_escape \"${cmake_bootstrap_dir}\"`"
+  -I`cmake_escape \"${cmake_source_dir}/Utilities\"`"
 echo "cmake: ${objs}" > "${cmake_bootstrap_dir}/Makefile"
 echo "	${cmake_cxx_compiler} ${cmake_ld_flags} ${cmake_cxx_flags} ${objs} -o cmake" >> "${cmake_bootstrap_dir}/Makefile"
 for a in ${CMAKE_CXX_SOURCES}; do
@@ -1385,6 +1375,7 @@ set (CMAKE_INSTALL_PREFIX "'"${cmake_prefix_dir}"'" CACHE PATH "Install path pre
 set (CMAKE_DOC_DIR "'"${cmake_doc_dir}"'" CACHE PATH "Install location for documentation (relative to prefix)." FORCE)
 set (CMAKE_MAN_DIR "'"${cmake_man_dir}"'" CACHE PATH "Install location for man pages (relative to prefix)." FORCE)
 set (CMAKE_DATA_DIR "'"${cmake_data_dir}"'" CACHE PATH "Install location for data (relative to prefix)." FORCE)
+set (CMAKE_XDGDATA_DIR "'"${cmake_xdgdata_dir}"'" CACHE PATH "Install location for XDG specific files (relative to prefix)." FORCE)
 ' > "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
 
 # Add configuration settings given as command-line options.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-cmake/cmake.git



More information about the Pkg-cmake-commits mailing list